Generated on Fri Jul 13 2018 06:08:28 for Gecode by doxygen 1.8.14
int-bin.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, 2003
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 { namespace Linear {
39 
40  /*
41  * Binary linear propagators
42  *
43  */
44  template<class Val, class A, class B, PropCond pc>
46  LinBin<Val,A,B,pc>::LinBin(Home home, A y0, B y1, Val c0)
47  : Propagator(home), x0(y0), x1(y1), c(c0) {
48  x0.subscribe(home,*this,pc);
49  x1.subscribe(home,*this,pc);
50  }
51 
52  template<class Val, class A, class B, PropCond pc>
55  : Propagator(home,share,p), c(p.c) {
56  x0.update(home,share,p.x0);
57  x1.update(home,share,p.x1);
58  }
59 
60  template<class Val, class A, class B, PropCond pc>
63  A y0, B y1, Val c0)
64  : Propagator(home,share,p), c(c0) {
65  x0.update(home,share,y0);
66  x1.update(home,share,y1);
67  }
68 
69  template<class Val, class A, class B, PropCond pc>
70  PropCost
72  return PropCost::binary(PropCost::LO);
73  }
74 
75  template<class Val, class A, class B, PropCond pc>
76  void
78  x0.reschedule(home,*this,pc);
79  x1.reschedule(home,*this,pc);
80  }
81 
82  template<class Val, class A, class B, PropCond pc>
83  forceinline size_t
85  x0.cancel(home,*this,pc);
86  x1.cancel(home,*this,pc);
87  (void) Propagator::dispose(home);
88  return sizeof(*this);
89  }
90 
91 
92  /*
93  * Binary reified linear propagators
94  *
95  */
96  template<class Val, class A, class B, PropCond pc, class Ctrl>
98  ReLinBin<Val,A,B,pc,Ctrl>::ReLinBin(Home home, A y0, B y1, Val c0, Ctrl b0)
99  : Propagator(home), x0(y0), x1(y1), c(c0), b(b0) {
100  x0.subscribe(home,*this,pc);
101  x1.subscribe(home,*this,pc);
102  b.subscribe(home,*this,PC_INT_VAL);
103  }
104 
105  template<class Val, class A, class B, PropCond pc, class Ctrl>
109  : Propagator(home,share,p), c(p.c) {
110  x0.update(home,share,p.x0);
111  x1.update(home,share,p.x1);
112  b.update(home,share,p.b);
113  }
114 
115  template<class Val, class A, class B, PropCond pc, class Ctrl>
116  PropCost
118  return PropCost::binary(PropCost::LO);
119  }
120 
121  template<class Val, class A, class B, PropCond pc, class Ctrl>
122  void
124  x0.reschedule(home,*this,pc);
125  x1.reschedule(home,*this,pc);
126  b.reschedule(home,*this,PC_INT_VAL);
127  }
128 
129  template<class Val, class A, class B, PropCond pc, class Ctrl>
130  forceinline size_t
132  x0.cancel(home,*this,pc);
133  x1.cancel(home,*this,pc);
134  b.cancel(home,*this,PC_BOOL_VAL);
135  (void) Propagator::dispose(home);
136  return sizeof(*this);
137  }
138 
139  /*
140  * Binary bounds consistent linear equality
141  *
142  */
143 
144  template<class Val, class A, class B>
146  EqBin<Val,A,B>::EqBin(Home home, A x0, B x1, Val c)
147  : LinBin<Val,A,B,PC_INT_BND>(home,x0,x1,c) {}
148 
149  template<class Val, class A, class B>
150  ExecStatus
151  EqBin<Val,A,B>::post(Home home, A x0, B x1, Val c) {
152  (void) new (home) EqBin<Val,A,B>(home,x0,x1,c);
153  return ES_OK;
154  }
155 
156 
157  template<class Val, class A, class B>
160  : LinBin<Val,A,B,PC_INT_BND>(home,share,p) {}
161 
162  template<class Val, class A, class B>
165  A x0, B x1, Val c)
166  : LinBin<Val,A,B,PC_INT_BND>(home,share,p,x0,x1,c) {}
167 
168  template<class Val, class A, class B>
169  Actor*
170  EqBin<Val,A,B>::copy(Space& home, bool share) {
171  return new (home) EqBin<Val,A,B>(home,share,*this);
172  }
173 
175  enum BinMod {
176  BM_X0_MIN = 1<<0,
177  BM_X0_MAX = 1<<1,
178  BM_X1_MIN = 1<<2,
179  BM_X1_MAX = 1<<3,
181  };
182 
183 #define GECODE_INT_PV(CASE,TELL,UPDATE) \
184  if (bm & (CASE)) { \
185  bm -= (CASE); ModEvent me = (TELL); \
186  if (me_failed(me)) return ES_FAILED; \
187  if (me_modified(me)) bm |= (UPDATE); \
188  }
189 
190  template<class Val, class A, class B>
191  ExecStatus
193  int bm = BM_ALL;
194  do {
195  GECODE_INT_PV(BM_X0_MIN, x0.gq(home,c-x1.max()), BM_X1_MAX);
196  GECODE_INT_PV(BM_X1_MIN, x1.gq(home,c-x0.max()), BM_X0_MAX);
197  GECODE_INT_PV(BM_X0_MAX, x0.lq(home,c-x1.min()), BM_X1_MIN);
198  GECODE_INT_PV(BM_X1_MAX, x1.lq(home,c-x0.min()), BM_X0_MIN);
199  } while (bm);
200  return x0.assigned() ? home.ES_SUBSUMED(*this) : ES_FIX;
201  }
202 
203 #undef GECODE_INT_PV
204 
205 
206 
207 
208 
209  /*
210  * Reified binary bounds consistent linear equality
211  *
212  */
213 
214  template<class Val, class A, class B, class Ctrl, ReifyMode rm>
216  ReEqBin<Val,A,B,Ctrl,rm>::ReEqBin(Home home, A x0, B x1, Val c, Ctrl b)
217  : ReLinBin<Val,A,B,PC_INT_BND,Ctrl>(home,x0,x1,c,b) {}
218 
219  template<class Val, class A, class B, class Ctrl, ReifyMode rm>
220  ExecStatus
221  ReEqBin<Val,A,B,Ctrl,rm>::post(Home home, A x0, B x1, Val c, Ctrl b) {
222  (void) new (home) ReEqBin<Val,A,B,Ctrl,rm>(home,x0,x1,c,b);
223  return ES_OK;
224  }
225 
226 
227  template<class Val, class A, class B, class Ctrl, ReifyMode rm>
231  : ReLinBin<Val,A,B,PC_INT_BND,Ctrl>(home,share,p) {}
232 
233  template<class Val, class A, class B, class Ctrl, ReifyMode rm>
234  Actor*
236  return new (home) ReEqBin<Val,A,B,Ctrl,rm>(home,share,*this);
237  }
238 
239  template<class Val, class A, class B, class Ctrl, ReifyMode rm>
240  ExecStatus
242  if (b.zero()) {
243  if (rm == RM_IMP)
244  return home.ES_SUBSUMED(*this);
245  GECODE_REWRITE(*this,(NqBin<Val,A,B>::post(home(*this),x0,x1,c)));
246  }
247  if (b.one()) {
248  if (rm == RM_PMI)
249  return home.ES_SUBSUMED(*this);
250  GECODE_REWRITE(*this,(EqBin<Val,A,B>::post(home(*this),x0,x1,c)));
251  }
252  if ((x0.min() + x1.min() > c) || (x0.max() + x1.max() < c)) {
253  if (rm != RM_PMI)
254  GECODE_ME_CHECK(b.zero_none(home));
255  return home.ES_SUBSUMED(*this);
256  }
257  if (x0.assigned() && x1.assigned()) {
258  assert(x0.val() + x1.val() == c);
259  if (rm != RM_IMP)
260  GECODE_ME_CHECK(b.one_none(home));
261  return home.ES_SUBSUMED(*this);
262  }
263  return ES_FIX;
264  }
265 
266 
267 
268 
269  /*
270  * Binary domain consistent linear disequality
271  *
272  */
273  template<class Val, class A, class B>
275  NqBin<Val,A,B>::NqBin(Home home, A x0, B x1, Val c)
276  : LinBin<Val,A,B,PC_INT_VAL>(home,x0,x1,c) {}
277 
278  template<class Val, class A, class B>
279  ExecStatus
280  NqBin<Val,A,B>::post(Home home, A x0, B x1, Val c) {
281  (void) new (home) NqBin<Val,A,B>(home,x0,x1,c);
282  return ES_OK;
283  }
284 
285 
286  template<class Val, class A, class B>
289  : LinBin<Val,A,B,PC_INT_VAL>(home,share,p) {}
290 
291  template<class Val, class A, class B>
292  Actor*
293  NqBin<Val,A,B>::copy(Space& home, bool share) {
294  return new (home) NqBin<Val,A,B>(home,share,*this);
295  }
296 
297  template<class Val, class A, class B>
300  A x0, B x1, Val c)
301  : LinBin<Val,A,B,PC_INT_VAL>(home,share,p,x0,x1,c) {}
302 
303 
304 
305  template<class Val, class A, class B>
306  PropCost
307  NqBin<Val,A,B>::cost(const Space&, const ModEventDelta&) const {
309  }
310 
311  template<class Val, class A, class B>
312  ExecStatus
314  if (x0.assigned()) {
315  GECODE_ME_CHECK(x1.nq(home,c-x0.val()));
316  } else {
317  assert(x1.assigned());
318  GECODE_ME_CHECK(x0.nq(home,c-x1.val()));
319  }
320  return home.ES_SUBSUMED(*this);
321  }
322 
323 
324  /*
325  * Binary domain consistent less equal
326  *
327  */
328 
329  template<class Val, class A, class B>
331  LqBin<Val,A,B>::LqBin(Home home, A x0, B x1, Val c)
332  : LinBin<Val,A,B,PC_INT_BND>(home,x0,x1,c) {}
333 
334  template<class Val, class A, class B>
335  ExecStatus
336  LqBin<Val,A,B>::post(Home home, A x0, B x1, Val c) {
337  (void) new (home) LqBin<Val,A,B>(home,x0,x1,c);
338  return ES_OK;
339  }
340 
341 
342  template<class Val, class A, class B>
345  : LinBin<Val,A,B,PC_INT_BND>(home,share,p) {}
346 
347  template<class Val, class A, class B>
348  Actor*
349  LqBin<Val,A,B>::copy(Space& home, bool share) {
350  return new (home) LqBin<Val,A,B>(home,share,*this);
351  }
352 
353  template<class Val, class A, class B>
356  A x0, B x1, Val c)
357  : LinBin<Val,A,B,PC_INT_BND>(home,share,p,x0,x1,c) {}
358 
359  template<class Val, class A, class B>
360  ExecStatus
362  GECODE_ME_CHECK(x0.lq(home,c-x1.min()));
363  GECODE_ME_CHECK(x1.lq(home,c-x0.min()));
364  return (x0.max()+x1.max() <= c) ? home.ES_SUBSUMED(*this) : ES_FIX;
365  }
366 
367 
368 
369 
370  /*
371  * Binary domain consistent greater equal
372  *
373  */
374 
375  template<class Val, class A, class B>
377  GqBin<Val,A,B>::GqBin(Home home, A x0, B x1, Val c)
378  : LinBin<Val,A,B,PC_INT_BND>(home,x0,x1,c) {}
379 
380  template<class Val, class A, class B>
381  ExecStatus
382  GqBin<Val,A,B>::post(Home home, A x0, B x1, Val c) {
383  (void) new (home) GqBin<Val,A,B>(home,x0,x1,c);
384  return ES_OK;
385  }
386 
387 
388  template<class Val, class A, class B>
391  : LinBin<Val,A,B,PC_INT_BND>(home,share,p) {}
392 
393  template<class Val, class A, class B>
394  Actor*
395  GqBin<Val,A,B>::copy(Space& home, bool share) {
396  return new (home) GqBin<Val,A,B>(home,share,*this);
397  }
398 
399  template<class Val, class A, class B>
402  A x0, B x1, Val c)
403  : LinBin<Val,A,B,PC_INT_BND>(home,share,p,x0,x1,c) {}
404 
405  template<class Val, class A, class B>
406  ExecStatus
408  GECODE_ME_CHECK(x0.gq(home,c-x1.max()));
409  GECODE_ME_CHECK(x1.gq(home,c-x0.max()));
410  return (x0.min()+x1.min() >= c) ? home.ES_SUBSUMED(*this) : ES_FIX;
411  }
412 
413 
414 
415 
416  /*
417  * Reified binary domain consistent less equal
418  *
419  */
420 
421  template<class Val, class A, class B, ReifyMode rm>
423  ReLqBin<Val,A,B,rm>::ReLqBin(Home home, A x0, B x1, Val c, BoolView b)
424  : ReLinBin<Val,A,B,PC_INT_BND,BoolView>(home,x0,x1,c,b) {}
425 
426  template<class Val, class A, class B, ReifyMode rm>
427  ExecStatus
428  ReLqBin<Val,A,B,rm>::post(Home home, A x0, B x1, Val c, BoolView b) {
429  (void) new (home) ReLqBin<Val,A,B,rm>(home,x0,x1,c,b);
430  return ES_OK;
431  }
432 
433 
434  template<class Val, class A, class B, ReifyMode rm>
437  : ReLinBin<Val,A,B,PC_INT_BND,BoolView>(home,share,p) {}
438 
439  template<class Val, class A, class B, ReifyMode rm>
440  Actor*
441  ReLqBin<Val,A,B,rm>::copy(Space& home, bool share) {
442  return new (home) ReLqBin<Val,A,B,rm>(home,share,*this);
443  }
444 
445  template<class Val, class A, class B, ReifyMode rm>
446  ExecStatus
448  if (b.one()) {
449  if (rm == RM_PMI)
450  return home.ES_SUBSUMED(*this);
451  GECODE_REWRITE(*this,(LqBin<Val,A,B>::post(home(*this),x0,x1,c)));
452  }
453  if (b.zero()) {
454  if (rm == RM_IMP)
455  return home.ES_SUBSUMED(*this);
456  GECODE_REWRITE(*this,(GqBin<Val,A,B>::post(home(*this),x0,x1,c+1)));
457  }
458  if (x0.max() + x1.max() <= c) {
459  if (rm != RM_IMP)
460  GECODE_ME_CHECK(b.one_none(home));
461  return home.ES_SUBSUMED(*this);
462  }
463  if (x0.min() + x1.min() > c) {
464  if (rm != RM_PMI)
465  GECODE_ME_CHECK(b.zero_none(home));
466  return home.ES_SUBSUMED(*this);
467  }
468  return ES_FIX;
469  }
470 
471 }}}
472 
473 // STATISTICS: int-prop
474 
virtual Actor * copy(Space &home, bool share)
Create copy during cloning.
Definition: int-bin.hpp:293
Propagator for bounds consistent binary linear disequality
Definition: linear.hh:205
#define GECODE_REWRITE(prop, post)
Rewrite propagator by executing post function.
Definition: macros.hpp:120
BinMod
Describe which view has been modified how.
Definition: int-bin.hpp:175
Inverse implication for reification.
Definition: int.hh:850
ExecStatus ES_SUBSUMED(Propagator &p)
Definition: core.hpp:3614
Propagator for bounds consistent binary linear greater or equal
Definition: linear.hh:275
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: int-bin.hpp:407
static ExecStatus post(Home home, A x0, B x1, Val c, BoolView b)
Post propagator for .
Definition: int-bin.hpp:428
LqBin(Space &home, bool share, LqBin &p)
Constructor for cloning p.
Definition: int-bin.hpp:344
GqBin(Space &home, bool share, GqBin &p)
Constructor for cloning p.
Definition: int-bin.hpp:390
Base-class for propagators.
Definition: core.hpp:1092
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: int-bin.hpp:447
#define GECODE_INT_PV(CASE, TELL, UPDATE)
Definition: int-bin.hpp:183
Propagation has computed fixpoint.
Definition: core.hpp:545
static PropCost unary(PropCost::Mod m)
Single variable for modifier pcm.
Definition: core.hpp:4858
Propagator for bounds consistent binary linear equality
Definition: linear.hh:138
Computation spaces.
Definition: core.hpp:1748
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: int-bin.hpp:361
Base-class for binary linear propagators.
Definition: linear.hh:69
Base-class for both propagators and branchers.
Definition: core.hpp:696
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function (defined as low unary)
Definition: int-bin.hpp:307
Gecode::FloatVal c(-8, 8)
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:236
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: int-bin.hpp:241
IntSet * A
Position of a piece in a square board.
const Gecode::PropCond PC_INT_BND
Propagate when minimum or maximum of a view changes.
Definition: var-type.hpp:91
virtual Actor * copy(Space &home, bool share)
Create copy during cloning.
Definition: int-bin.hpp:235
Propagator for bounds consistent binary linear less or equal
Definition: linear.hh:241
struct Gecode::@579::NNF::@61::@62 b
For binary nodes (and, or, eqv)
static ExecStatus post(Home home, A x0, B x1, Val c, Ctrl b)
Post propagator for .
Definition: int-bin.hpp:221
#define GECODE_ME_CHECK(me)
Check whether modification event me is failed, and forward failure.
Definition: macros.hpp:56
Propagator for reified bounds consistent binary linear less or equal
Definition: linear.hh:309
virtual Actor * copy(Space &home, bool share)
Create copy during cloning.
Definition: int-bin.hpp:441
static ExecStatus post(Home home, A x0, B x1, Val c)
Post propagator for .
Definition: int-bin.hpp:151
Propagation cost.
Definition: core.hpp:554
Base-class for reified binary linear propagators.
Definition: linear.hh:102
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: int-bin.hpp:192
ExecStatus
Definition: core.hpp:540
static ExecStatus post(Home home, A x0, B x1, Val c)
Post propagator for .
Definition: int-bin.hpp:280
virtual Actor * copy(Space &home, bool share)
Create copy during cloning.
Definition: int-bin.hpp:170
#define forceinline
Definition: config.hpp:173
Propagator for reified bounds consistent binary linear equality
Definition: linear.hh:172
virtual Actor * copy(Space &home, bool share)
Create copy during cloning.
Definition: int-bin.hpp:349
Execution is okay.
Definition: core.hpp:544
virtual Actor * copy(Space &home, bool share)
Create copy during cloning.
Definition: int-bin.hpp:395
LinBin(Space &home, bool share, LinBin &p)
Constructor for cloning p.
Definition: int-bin.hpp:54
Gecode toplevel namespace
NqBin(Space &home, bool share, NqBin &p)
Constructor for cloning p.
Definition: int-bin.hpp:288
Implication for reification.
Definition: int.hh:843
static ExecStatus post(Home home, A x0, B x1, Val c)
Post propagator for .
Definition: int-bin.hpp:336
void reschedule(Space &home, Propagator &p, IntSet &y)
Definition: rel.hpp:96
friend FloatVal max(const FloatVal &x, const FloatVal &y)
Definition: val.hpp:390
int ModEventDelta
Modification event deltas.
Definition: core.hpp:169
friend FloatVal min(const FloatVal &x, const FloatVal &y)
Definition: val.hpp:402
static ExecStatus post(Home home, A x0, B x1, Val c)
Post propagator for .
Definition: int-bin.hpp:382
ReLqBin(Space &home, bool share, ReLqBin &p)
Constructor for cloning p.
Definition: int-bin.hpp:436
Home class for posting propagators
Definition: core.hpp:922
ReEqBin(Space &home, bool share, ReEqBin &p)
Constructor for cloning p.
Definition: int-bin.hpp:229
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: int-bin.hpp:313
EqBin(Space &home, bool share, EqBin &p)
Constructor for cloning p.
Definition: int-bin.hpp:159
const Gecode::PropCond PC_INT_VAL
Propagate when a view becomes assigned (single value)
Definition: var-type.hpp:82
const Gecode::PropCond PC_BOOL_VAL
Propagate when a view becomes assigned (single value)
Definition: var-type.hpp:126
Boolean view for Boolean variables.
Definition: view.hpp:1315