Generated on Thu Jul 25 2019 00:00:00 for Gecode by doxygen 1.8.15
propagator.hpp
Go to the documentation of this file.
1 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2 /*
3  * Main authors:
4  * Christian Schulte <schulte@gecode.org>
5  *
6  * Copyright:
7  * Christian Schulte, 2002
8  *
9  * Last modified:
10  * $Date: 2016-06-29 17:28:17 +0200 (Wed, 29 Jun 2016) $ by $Author: schulte $
11  * $Revision: 15137 $
12  *
13  * This file is part of Gecode, the generic constraint
14  * development environment:
15  * http://www.gecode.org
16  *
17  * Permission is hereby granted, free of charge, to any person obtaining
18  * a copy of this software and associated documentation files (the
19  * "Software"), to deal in the Software without restriction, including
20  * without limitation the rights to use, copy, modify, merge, publish,
21  * distribute, sublicense, and/or sell copies of the Software, and to
22  * permit persons to whom the Software is furnished to do so, subject to
23  * the following conditions:
24  *
25  * The above copyright notice and this permission notice shall be
26  * included in all copies or substantial portions of the Software.
27  *
28  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35  *
36  */
37 
38 namespace Gecode { namespace Int {
39 
57  template<class View, PropCond pc, class CtrlView>
58  class ReUnaryPropagator : public Propagator {
59  protected:
61  View x0;
63  CtrlView b;
65  ReUnaryPropagator(Space& home, bool share, ReUnaryPropagator& p);
67  ReUnaryPropagator(Space& home, bool share, Propagator& p,
68  View x0, CtrlView b);
70  ReUnaryPropagator(Home home, View x0, CtrlView b);
71  public:
73  virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
75  virtual void reschedule(Space& home);
77  virtual size_t dispose(Space& home);
78  };
79 
90  template<class View, PropCond pc, class CtrlView>
91  class ReBinaryPropagator : public Propagator {
92  protected:
94  View x0, x1;
96  CtrlView b;
98  ReBinaryPropagator(Space& home, bool share, ReBinaryPropagator& p);
100  ReBinaryPropagator(Space& home, bool share, Propagator& p,
101  View x0, View x1, CtrlView b);
103  ReBinaryPropagator(Home home, View x0, View x1, CtrlView b);
104  public:
106  virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
108  virtual void reschedule(Space& home);
110  virtual size_t dispose(Space& home);
111  };
113 
114 
126  template<class View0, PropCond pc0, class View1, PropCond pc1,
127  class CtrlView>
129  protected:
131  View0 x0;
133  View1 x1;
135  CtrlView b;
137  ReMixBinaryPropagator(Space& home, bool share, ReMixBinaryPropagator& p);
139  ReMixBinaryPropagator(Home home, View0 x0, View1 x1, CtrlView b);
141  ReMixBinaryPropagator(Space& home, bool share, Propagator& p,
142  View0 x0, View1 x1, CtrlView b);
143  public:
145  virtual PropCost cost(const Space& home, const ModEventDelta& med) const;
147  virtual void reschedule(Space& home);
149  virtual size_t dispose(Space& home);
150  };
151 
152 
153  /*
154  * Reified unary propagators
155  *
156  */
157  template<class View, PropCond pc, class CtrlView>
159  (Home home, View y0, CtrlView b0)
160  : Propagator(home), x0(y0), b(b0) {
161  if (pc != PC_GEN_NONE)
162  x0.subscribe(home,*this,pc);
163  b.subscribe(home,*this,Int::PC_INT_VAL);
164  }
165 
166  template<class View, PropCond pc, class CtrlView>
170  : Propagator(home,share,p) {
171  x0.update(home,share,p.x0);
172  b.update(home,share,p.b);
173  }
174 
175  template<class View, PropCond pc, class CtrlView>
178  (Space& home, bool share, Propagator& p, View y0, CtrlView b0)
179  : Propagator(home,share,p) {
180  x0.update(home,share,y0);
181  b.update(home,share,b0);
182  }
183 
184  template<class View, PropCond pc, class CtrlView>
185  PropCost
188  }
189 
190  template<class View, PropCond pc, class CtrlView>
191  void
193  if (pc != PC_GEN_NONE)
194  x0.reschedule(home,*this,pc);
195  b.reschedule(home,*this,Int::PC_INT_VAL);
196  }
197 
198  template<class View, PropCond pc, class CtrlView>
199  forceinline size_t
201  if (pc != PC_GEN_NONE)
202  x0.cancel(home,*this,pc);
203  b.cancel(home,*this,Int::PC_INT_VAL);
204  (void) Propagator::dispose(home);
205  return sizeof(*this);
206  }
207 
208  /*
209  * Reified binary propagators
210  *
211  */
212  template<class View, PropCond pc, class CtrlView>
214  (Home home, View y0, View y1, CtrlView b1)
215  : Propagator(home), x0(y0), x1(y1), b(b1) {
216  if (pc != PC_GEN_NONE) {
217  x0.subscribe(home,*this,pc);
218  x1.subscribe(home,*this,pc);
219  }
220  b.subscribe(home,*this,Int::PC_INT_VAL);
221  }
222 
223  template<class View, PropCond pc, class CtrlView>
227  : Propagator(home,share,p) {
228  x0.update(home,share,p.x0);
229  x1.update(home,share,p.x1);
230  b.update(home,share,p.b);
231  }
232 
233  template<class View, PropCond pc, class CtrlView>
236  (Space& home, bool share, Propagator& p, View y0, View y1, CtrlView b0)
237  : Propagator(home,share,p) {
238  x0.update(home,share,y0);
239  x1.update(home,share,y1);
240  b.update(home,share,b0);
241  }
242 
243  template<class View, PropCond pc, class CtrlView>
244  PropCost
247  }
248 
249  template<class View, PropCond pc, class CtrlView>
250  void
252  if (pc != PC_GEN_NONE) {
253  x0.reschedule(home,*this,pc);
254  x1.reschedule(home,*this,pc);
255  }
256  b.reschedule(home,*this,Int::PC_INT_VAL);
257  }
258 
259  template<class View, PropCond pc, class CtrlView>
260  forceinline size_t
262  if (pc != PC_GEN_NONE) {
263  x0.cancel(home,*this,pc);
264  x1.cancel(home,*this,pc);
265  }
266  b.cancel(home,*this,Int::PC_INT_VAL);
267  (void) Propagator::dispose(home);
268  return sizeof(*this);
269  }
270 
271  /*
272  * Reified mixed binary propagator
273  *
274  */
275  template<class View0, PropCond pc0, class View1, PropCond pc1,
276  class CtrlView>
278  ::ReMixBinaryPropagator(Home home, View0 y0, View1 y1, CtrlView b1)
279  : Propagator(home), x0(y0), x1(y1), b(b1) {
280  if (pc0 != PC_GEN_NONE)
281  x0.subscribe(home,*this,pc0);
282  if (pc1 != PC_GEN_NONE)
283  x1.subscribe(home,*this,pc1);
284  b.subscribe(home,*this,Int::PC_INT_VAL);
285  }
286 
287  template<class View0, PropCond pc0, class View1, PropCond pc1,
288  class CtrlView>
291  (Space& home, bool share,
293  : Propagator(home,share,p) {
294  x0.update(home,share,p.x0);
295  x1.update(home,share,p.x1);
296  b.update(home,share,p.b);
297  }
298 
299  template<class View0, PropCond pc0, class View1, PropCond pc1,
300  class CtrlView>
304  (Space& home, bool share, Propagator& p, View0 y0, View1 y1, CtrlView b0)
305  : Propagator(home,share,p) {
306  x0.update(home,share,y0);
307  x1.update(home,share,y1);
308  b.update(home,share,b0);
309  }
310 
311  template<class View0, PropCond pc0, class View1, PropCond pc1,
312  class CtrlView>
313  PropCost
315  ::cost(const Space&, const ModEventDelta&) const {
317  }
318 
319  template<class View0, PropCond pc0, class View1, PropCond pc1,
320  class CtrlView>
321  void
323  if (pc0 != PC_GEN_NONE)
324  x0.reschedule(home,*this,pc0);
325  if (pc1 != PC_GEN_NONE)
326  x1.reschedule(home,*this,pc1);
327  b.reschedule(home,*this,Int::PC_INT_VAL);
328  }
329 
330  template<class View0, PropCond pc0, class View1, PropCond pc1,
331  class CtrlView>
332  forceinline size_t
334  if (pc0 != PC_GEN_NONE)
335  x0.cancel(home,*this,pc0);
336  if (pc1 != PC_GEN_NONE)
337  x1.cancel(home,*this,pc1);
338  b.cancel(home,*this,Int::PC_INT_VAL);
339  (void) Propagator::dispose(home);
340  return sizeof(*this);
341  }
342 
343 }}
344 
345 // STATISTICS: int-prop
346 
virtual void reschedule(Space &home)
Schedule function.
Definition: propagator.hpp:251
const PropCond PC_GEN_NONE
Propagation condition to be ignored (convenience)
Definition: core.hpp:154
ReBinaryPropagator(Space &home, bool share, ReBinaryPropagator &p)
Constructor for cloning p.
Definition: propagator.hpp:226
Reified unary propagator.
Definition: propagator.hpp:58
Reified binary propagator.
Definition: propagator.hpp:91
Reified mixed binary propagator.
Definition: propagator.hpp:128
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function (defined as low unary)
Definition: propagator.hpp:186
Base-class for propagators.
Definition: core.hpp:1092
ReUnaryPropagator(Space &home, bool share, ReUnaryPropagator &p)
Constructor for cloning p.
Definition: propagator.hpp:169
static PropCost unary(PropCost::Mod m)
Single variable for modifier pcm.
Definition: core.hpp:4858
Computation spaces.
Definition: core.hpp:1748
CtrlView b
Boolean control view.
Definition: propagator.hpp:63
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function (defined as low binary)
Definition: propagator.hpp:245
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:236
int PropCond
Type for propagation conditions.
Definition: core.hpp:152
ModEventDelta med
A set of modification events (used during propagation)
Definition: core.hpp:1103
View0 x0
View of type View0.
Definition: propagator.hpp:131
struct Gecode::@579::NNF::@61::@62 b
For binary nodes (and, or, eqv)
virtual size_t dispose(Space &home)
Delete actor and return its size.
Definition: core.hpp:3354
Propagation cost.
Definition: core.hpp:554
virtual void reschedule(Space &home)
Schedule function.
Definition: propagator.hpp:322
CtrlView b
Boolean control view.
Definition: propagator.hpp:135
#define forceinline
Definition: config.hpp:173
virtual size_t dispose(Space &home)
Delete propagator and return its size.
Definition: propagator.hpp:333
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function (defined as low binary)
Definition: propagator.hpp:315
ReMixBinaryPropagator(Space &home, bool share, ReMixBinaryPropagator &p)
Constructor for cloning p.
Definition: propagator.hpp:291
Gecode toplevel namespace
virtual size_t dispose(Space &home)
Delete propagator and return its size.
Definition: propagator.hpp:200
virtual void reschedule(Space &home)
Schedule function.
Definition: propagator.hpp:192
CtrlView b
Boolean control view.
Definition: propagator.hpp:96
View1 x1
View of type View1.
Definition: propagator.hpp:133
int ModEventDelta
Modification event deltas.
Definition: core.hpp:169
Home class for posting propagators
Definition: core.hpp:922
static PropCost binary(PropCost::Mod m)
Two variables for modifier pcm.
Definition: core.hpp:4854
virtual size_t dispose(Space &home)
Delete propagator and return its size.
Definition: propagator.hpp:261
const Gecode::PropCond PC_INT_VAL
Propagate when a view becomes assigned (single value)
Definition: var-type.hpp:82