Generated on Thu Apr 5 2018 19:44:19 for Gecode by doxygen 1.8.13
int-nary.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$ by $Author$
11  * $Revision$
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 
39 
40 namespace Gecode { namespace Int { namespace Linear {
41 
46  template<class P, class N>
47  forceinline bool
48  isunit(ViewArray<P>&, ViewArray<N>&) { return false; }
49  template<>
50  forceinline bool
52  template<>
53  forceinline bool
55  template<>
56  forceinline bool
58 
59  /*
60  * Linear propagators
61  *
62  */
63  template<class Val, class P, class N, PropCond pc>
66  : Propagator(home), x(x0), y(y0), c(c0) {
67  x.subscribe(home,*this,pc);
68  y.subscribe(home,*this,pc);
69  }
70 
71  template<class Val, class P, class N, PropCond pc>
74  : Propagator(home,p), c(p.c) {
75  x.update(home,p.x);
76  y.update(home,p.y);
77  }
78 
79  template<class Val, class P, class N, PropCond pc>
80  PropCost
81  Lin<Val,P,N,pc>::cost(const Space&, const ModEventDelta&) const {
82  return PropCost::linear(PropCost::LO, x.size()+y.size());
83  }
84 
85  template<class Val, class P, class N, PropCond pc>
86  void
88  x.reschedule(home,*this,pc);
89  y.reschedule(home,*this,pc);
90  }
91 
92  template<class Val, class P, class N, PropCond pc>
93  forceinline size_t
95  x.cancel(home,*this,pc);
96  y.cancel(home,*this,pc);
97  (void) Propagator::dispose(home);
98  return sizeof(*this);
99  }
100 
101  /*
102  * Reified linear propagators
103  *
104  */
105  template<class Val, class P, class N, PropCond pc, class Ctrl>
108  (Home home, ViewArray<P>& x, ViewArray<N>& y, Val c, Ctrl b0)
109  : Lin<Val,P,N,pc>(home,x,y,c), b(b0) {
110  b.subscribe(home,*this,PC_INT_VAL);
111  }
112 
113  template<class Val, class P, class N, PropCond pc, class Ctrl>
117  : Lin<Val,P,N,pc>(home,p) {
118  b.update(home,p.b);
119  }
120 
121  template<class Val, class P, class N, PropCond pc, class Ctrl>
122  void
124  x.reschedule(home,*this,pc);
125  y.reschedule(home,*this,pc);
126  b.reschedule(home,*this,PC_INT_VAL);
127  }
128 
129  template<class Val, class P, class N, PropCond pc, class Ctrl>
130  forceinline size_t
132  b.cancel(home,*this,PC_BOOL_VAL);
133  (void) Lin<Val,P,N,pc>::dispose(home);
134  return sizeof(*this);
135  }
136 
137  /*
138  * Computing bounds
139  *
140  */
141 
142  template<class Val, class View>
143  void
144  bounds_p(ModEventDelta med, ViewArray<View>& x, Val& c, Val& sl, Val& su) {
145  int n = x.size();
146  if (IntView::me(med) == ME_INT_VAL) {
147  for (int i = n; i--; ) {
148  Val m = x[i].min();
149  if (x[i].assigned()) {
150  c -= m; x[i] = x[--n];
151  } else {
152  sl -= m; su -= x[i].max();
153  }
154  }
155  x.size(n);
156  } else {
157  for (int i = n; i--; ) {
158  sl -= x[i].min(); su -= x[i].max();
159  }
160  }
161  }
162 
163  template<class Val, class View>
164  void
165  bounds_n(ModEventDelta med, ViewArray<View>& y, Val& c, Val& sl, Val& su) {
166  int n = y.size();
167  if (IntView::me(med) == ME_INT_VAL) {
168  for (int i = n; i--; ) {
169  Val m = y[i].max();
170  if (y[i].assigned()) {
171  c += m; y[i] = y[--n];
172  } else {
173  sl += m; su += y[i].min();
174  }
175  }
176  y.size(n);
177  } else {
178  for (int i = n; i--; ) {
179  sl += y[i].max(); su += y[i].min();
180  }
181  }
182  }
183 
184 
185  template<class Val, class P, class N>
186  ExecStatus
188  ViewArray<P>& x, ViewArray<N>& y, Val& c) {
189  // Eliminate singletons
190  Val sl = 0;
191  Val su = 0;
192 
193  bounds_p<Val,P>(med, x, c, sl, su);
194  bounds_n<Val,N>(med, y, c, sl, su);
195 
196  if ((IntView::me(med) == ME_INT_VAL) && ((x.size() + y.size()) <= 1)) {
197  if (x.size() == 1) {
198  GECODE_ME_CHECK(x[0].eq(home,c));
199  return home.ES_SUBSUMED(p);
200  }
201  if (y.size() == 1) {
202  GECODE_ME_CHECK(y[0].eq(home,-c));
203  return home.ES_SUBSUMED(p);
204  }
205  return (c == static_cast<Val>(0)) ?
206  home.ES_SUBSUMED(p) : ES_FAILED;
207  }
208 
209  sl += c; su += c;
210 
211  const int mod_sl = 1;
212  const int mod_su = 2;
213 
214  int mod = mod_sl | mod_su;
215 
216  do {
217  if (mod & mod_sl) {
218  mod -= mod_sl;
219  // Propagate upper bound for positive variables
220  for (int i = x.size(); i--; ) {
221  const Val xi_max = x[i].max();
222  ModEvent me = x[i].lq(home,sl + x[i].min());
223  if (me_failed(me))
224  return ES_FAILED;
225  if (me_modified(me)) {
226  su += xi_max - x[i].max();
227  mod |= mod_su;
228  }
229  }
230  // Propagate lower bound for negative variables
231  for (int i = y.size(); i--; ) {
232  const Val yi_min = y[i].min();
233  ModEvent me = y[i].gq(home,y[i].max() - sl);
234  if (me_failed(me))
235  return ES_FAILED;
236  if (me_modified(me)) {
237  su += y[i].min() - yi_min;
238  mod |= mod_su;
239  }
240  }
241  }
242  if (mod & mod_su) {
243  mod -= mod_su;
244  // Propagate lower bound for positive variables
245  for (int i = x.size(); i--; ) {
246  const Val xi_min = x[i].min();
247  ModEvent me = x[i].gq(home,su + x[i].max());
248  if (me_failed(me))
249  return ES_FAILED;
250  if (me_modified(me)) {
251  sl += xi_min - x[i].min();
252  mod |= mod_sl;
253  }
254  }
255  // Propagate upper bound for negative variables
256  for (int i = y.size(); i--; ) {
257  const Val yi_max = y[i].max();
258  ModEvent me = y[i].lq(home,y[i].min() - su);
259  if (me_failed(me))
260  return ES_FAILED;
261  if (me_modified(me)) {
262  sl += y[i].max() - yi_max;
263  mod |= mod_sl;
264  }
265  }
266  }
267  } while (mod);
268 
269  return (sl == su) ? home.ES_SUBSUMED(p) : ES_FIX;
270  }
271 
272  /*
273  * Bound consistent linear equation
274  *
275  */
276 
277  template<class Val, class P, class N>
280  : Lin<Val,P,N,PC_INT_BND>(home,x,y,c) {}
281 
282  template<class Val, class P, class N>
283  ExecStatus
285  ViewArray<NoView> nva;
286  if (y.size() == 0) {
287  (void) new (home) Eq<Val,P,NoView>(home,x,nva,c);
288  } else if (x.size() == 0) {
289  (void) new (home) Eq<Val,N,NoView>(home,y,nva,-c);
290  } else {
291  (void) new (home) Eq<Val,P,N>(home,x,y,c);
292  }
293  return ES_OK;
294  }
295 
296 
297  template<class Val, class P, class N>
300  : Lin<Val,P,N,PC_INT_BND>(home,p) {}
301 
306  template<class Val, class P, class N>
309  return NULL;
310  }
311  template<class Val>
315  assert(x.size() == 2);
316  return new (home) EqBin<Val,IntView,IntView>
317  (home,p,x[0],x[1],c);
318  }
319  template<class Val>
323  assert(y.size() == 2);
324  return new (home) EqBin<Val,IntView,IntView>
325  (home,p,y[0],y[1],-c);
326  }
327  template<class Val>
330  ViewArray<IntView>& x, ViewArray<IntView>& y, Val c) {
331  if (x.size() == 2)
332  return new (home) EqBin<Val,IntView,IntView>
333  (home,p,x[0],x[1],c);
334  if (x.size() == 1)
335  return new (home) EqBin<Val,IntView,MinusView>
336  (home,p,x[0],MinusView(y[0]),c);
337  return new (home) EqBin<Val,IntView,IntView>
338  (home,p,y[0],y[1],-c);
339  }
340 
345  template<class Val, class P, class N>
348  return NULL;
349  }
350  template<class Val>
354  assert(x.size() == 3);
355  return new (home) EqTer<Val,IntView,IntView,IntView>
356  (home,p,x[0],x[1],x[2],c);
357  }
358  template<class Val>
362  assert(y.size() == 3);
363  return new (home) EqTer<Val,IntView,IntView,IntView>
364  (home,p,y[0],y[1],y[2],-c);
365  }
366  template<class Val>
369  ViewArray<IntView>& x, ViewArray<IntView>& y, Val c) {
370  if (x.size() == 3)
371  return new (home) EqTer<Val,IntView,IntView,IntView>
372  (home,p,x[0],x[1],x[2],c);
373  if (x.size() == 2)
374  return new (home) EqTer<Val,IntView,IntView,MinusView>
375  (home,p,x[0],x[1],MinusView(y[0]),c);
376  if (x.size() == 1)
377  return new (home) EqTer<Val,IntView,IntView,MinusView>
378  (home,p,y[0],y[1],MinusView(x[0]),-c);
379  return new (home) EqTer<Val,IntView,IntView,IntView>
380  (home,p,y[0],y[1],y[2],-c);
381  }
382 
383  template<class Val, class P, class N>
384  Actor*
386  if (isunit(x,y)) {
387  // Check whether rewriting is possible
388  if (x.size() + y.size() == 2)
389  return eqtobin(home,*this,x,y,c);
390  if (x.size() + y.size() == 3)
391  return eqtoter(home,*this,x,y,c);
392  }
393  return new (home) Eq<Val,P,N>(home,*this);
394  }
395 
396  template<class Val, class P, class N>
397  ExecStatus
399  return prop_bnd<Val,P,N>(home,med,*this,x,y,c);
400  }
401 
402  /*
403  * Reified bound consistent linear equation
404  *
405  */
406 
407  template<class Val, class P, class N, class Ctrl, ReifyMode rm>
410  ViewArray<P>& x, ViewArray<N>& y, Val c, Ctrl b)
411  : ReLin<Val,P,N,PC_INT_BND,Ctrl>(home,x,y,c,b) {}
412 
413  template<class Val, class P, class N, class Ctrl, ReifyMode rm>
414  ExecStatus
416  ViewArray<P>& x, ViewArray<N>& y, Val c, Ctrl b) {
417  ViewArray<NoView> nva;
418  if (y.size() == 0) {
419  (void) new (home) ReEq<Val,P,NoView,Ctrl,rm>(home,x,nva,c,b);
420  } else if (x.size() == 0) {
421  (void) new (home) ReEq<Val,N,NoView,Ctrl,rm>(home,y,nva,-c,b);
422  } else {
423  (void) new (home) ReEq<Val,P,N,Ctrl,rm>(home,x,y,c,b);
424  }
425  return ES_OK;
426  }
427 
428 
429  template<class Val, class P, class N, class Ctrl, ReifyMode rm>
432  : ReLin<Val,P,N,PC_INT_BND,Ctrl>(home,p) {}
433 
434  template<class Val, class P, class N, class Ctrl, ReifyMode rm>
435  Actor*
437  return new (home) ReEq<Val,P,N,Ctrl,rm>(home,*this);
438  }
439 
440  template<class Val, class P, class N, class Ctrl, ReifyMode rm>
441  ExecStatus
443  if (b.zero()) {
444  if (rm == RM_IMP)
445  return home.ES_SUBSUMED(*this);
446  GECODE_REWRITE(*this,(Nq<Val,P,N>::post(home(*this),x,y,c)));
447  }
448  if (b.one()) {
449  if (rm == RM_PMI)
450  return home.ES_SUBSUMED(*this);
451  GECODE_REWRITE(*this,(Eq<Val,P,N>::post(home(*this),x,y,c)));
452  }
453 
454  Val sl = 0;
455  Val su = 0;
456 
457  bounds_p<Val,P>(med, x, c, sl, su);
458  bounds_n<Val,N>(med, y, c, sl, su);
459 
460  if ((-sl == c) && (-su == c)) {
461  if (rm != RM_IMP)
462  GECODE_ME_CHECK(b.one_none(home));
463  return home.ES_SUBSUMED(*this);
464  }
465  if ((-sl > c) || (-su < c)) {
466  if (rm != RM_PMI)
467  GECODE_ME_CHECK(b.zero_none(home));
468  return home.ES_SUBSUMED(*this);
469  }
470  return ES_FIX;
471  }
472 
473 
474  /*
475  * Domain consistent linear disequation
476  *
477  */
478 
479  template<class Val, class P, class N>
482  : Lin<Val,P,N,PC_INT_VAL>(home,x,y,c) {}
483 
484  template<class Val, class P, class N>
485  ExecStatus
487  ViewArray<NoView> nva;
488  if (y.size() == 0) {
489  (void) new (home) Nq<Val,P,NoView>(home,x,nva,c);
490  } else if (x.size() == 0) {
491  (void) new (home) Nq<Val,N,NoView>(home,y,nva,-c);
492  } else {
493  (void) new (home) Nq<Val,P,N>(home,x,y,c);
494  }
495  return ES_OK;
496  }
497 
498 
499  template<class Val, class P, class N>
502  : Lin<Val,P,N,PC_INT_VAL>(home,p) {}
503 
508  template<class Val, class P, class N>
511  return NULL;
512  }
513  template<class Val>
517  assert(x.size() == 2);
518  return new (home) NqBin<Val,IntView,IntView>
519  (home,p,x[0],x[1],c);
520  }
521  template<class Val>
525  assert(y.size() == 2);
526  return new (home) NqBin<Val,IntView,IntView>
527  (home,p,y[0],y[1],-c);
528  }
529  template<class Val>
532  ViewArray<IntView>& x, ViewArray<IntView>& y, Val c) {
533  if (x.size() == 2)
534  return new (home) NqBin<Val,IntView,IntView>
535  (home,p,x[0],x[1],c);
536  if (x.size() == 1)
537  return new (home) NqBin<Val,IntView,MinusView>
538  (home,p,x[0],MinusView(y[0]),c);
539  return new (home) NqBin<Val,IntView,IntView>
540  (home,p,y[0],y[1],-c);
541  }
542 
547  template<class Val, class P, class N>
550  return NULL;
551  }
552  template<class Val>
556  assert(x.size() == 3);
557  return new (home) NqTer<Val,IntView,IntView,IntView>
558  (home,p,x[0],x[1],x[2],c);
559  }
560  template<class Val>
564  assert(y.size() == 3);
565  return new (home) NqTer<Val,IntView,IntView,IntView>
566  (home,p,y[0],y[1],y[2],-c);
567  }
568  template<class Val>
571  ViewArray<IntView>& x, ViewArray<IntView>& y, Val c) {
572  if (x.size() == 3)
573  return new (home) NqTer<Val,IntView,IntView,IntView>
574  (home,p,x[0],x[1],x[2],c);
575  if (x.size() == 2)
576  return new (home) NqTer<Val,IntView,IntView,MinusView>
577  (home,p,x[0],x[1],MinusView(y[0]),c);
578  if (x.size() == 1)
579  return new (home) NqTer<Val,IntView,IntView,MinusView>
580  (home,p,y[0],y[1],MinusView(x[0]),-c);
581  return new (home) NqTer<Val,IntView,IntView,IntView>
582  (home,p,y[0],y[1],y[2],-c);
583  }
584 
585  template<class Val, class P, class N>
586  Actor*
588  if (isunit(x,y)) {
589  // Check whether rewriting is possible
590  if (x.size() + y.size() == 2)
591  return nqtobin(home,*this,x,y,c);
592  if (x.size() + y.size() == 3)
593  return nqtoter(home,*this,x,y,c);
594  }
595  return new (home) Nq<Val,P,N>(home,*this);
596  }
597 
598  template<class Val, class P, class N>
599  ExecStatus
601  for (int i = x.size(); i--; )
602  if (x[i].assigned()) {
603  c -= x[i].val(); x.move_lst(i);
604  }
605  for (int i = y.size(); i--; )
606  if (y[i].assigned()) {
607  c += y[i].val(); y.move_lst(i);
608  }
609  if (x.size() + y.size() <= 1) {
610  if (x.size() == 1) {
611  GECODE_ME_CHECK(x[0].nq(home,c)); return home.ES_SUBSUMED(*this);
612  }
613  if (y.size() == 1) {
614  GECODE_ME_CHECK(y[0].nq(home,-c)); return home.ES_SUBSUMED(*this);
615  }
616  return (c == static_cast<Val>(0)) ?
617  ES_FAILED : home.ES_SUBSUMED(*this);
618  }
619  return ES_FIX;
620  }
621 
622 
623  /*
624  * Bound consistent linear inequation
625  *
626  */
627 
628  template<class Val, class P, class N>
631  : Lin<Val,P,N,PC_INT_BND>(home,x,y,c) {}
632 
633  template<class Val, class P, class N>
634  ExecStatus
636  ViewArray<NoView> nva;
637  if (y.size() == 0) {
638  (void) new (home) Lq<Val,P,NoView>(home,x,nva,c);
639  } else if (x.size() == 0) {
640  (void) new (home) Lq<Val,NoView,N>(home,nva,y,c);
641  } else {
642  (void) new (home) Lq<Val,P,N>(home,x,y,c);
643  }
644  return ES_OK;
645  }
646 
647 
648  template<class Val, class P, class N>
651  : Lin<Val,P,N,PC_INT_BND>(home,p) {}
652 
657  template<class Val, class P, class N>
660  return NULL;
661  }
662  template<class Val>
666  assert(x.size() == 2);
667  return new (home) LqBin<Val,IntView,IntView>
668  (home,p,x[0],x[1],c);
669  }
670  template<class Val>
674  assert(y.size() == 2);
675  return new (home) LqBin<Val,MinusView,MinusView>
676  (home,p,MinusView(y[0]),MinusView(y[1]),c);
677  }
678  template<class Val>
681  ViewArray<IntView>& x, ViewArray<IntView>& y, Val c) {
682  if (x.size() == 2)
683  return new (home) LqBin<Val,IntView,IntView>
684  (home,p,x[0],x[1],c);
685  if (x.size() == 1)
686  return new (home) LqBin<Val,IntView,MinusView>
687  (home,p,x[0],MinusView(y[0]),c);
688  return new (home) LqBin<Val,MinusView,MinusView>
689  (home,p,MinusView(y[0]),MinusView(y[1]),c);
690  }
691 
696  template<class Val, class P, class N>
699  return NULL;
700  }
701  template<class Val>
705  assert(x.size() == 3);
706  return new (home) LqTer<Val,IntView,IntView,IntView>
707  (home,p,x[0],x[1],x[2],c);
708  }
709  template<class Val>
713  assert(y.size() == 3);
715  (home,p,MinusView(y[0]),MinusView(y[1]),MinusView(y[2]),c);
716  }
717  template<class Val>
720  ViewArray<IntView>& x, ViewArray<IntView>& y, Val c) {
721  if (x.size() == 3)
722  return new (home) LqTer<Val,IntView,IntView,IntView>
723  (home,p,x[0],x[1],x[2],c);
724  if (x.size() == 2)
725  return new (home) LqTer<Val,IntView,IntView,MinusView>
726  (home,p,x[0],x[1],MinusView(y[0]),c);
727  if (x.size() == 1)
729  (home,p,x[0],MinusView(y[0]),MinusView(y[1]),c);
731  (home,p,MinusView(y[0]),MinusView(y[1]),MinusView(y[2]),c);
732  }
733 
734  template<class Val, class P, class N>
735  Actor*
737  if (isunit(x,y)) {
738  // Check whether rewriting is possible
739  if (x.size() + y.size() == 2)
740  return lqtobin(home,*this,x,y,c);
741  if (x.size() + y.size() == 3)
742  return lqtoter(home,*this,x,y,c);
743  }
744  return new (home) Lq<Val,P,N>(home,*this);
745  }
746 
747  template<class Val, class P, class N>
748  ExecStatus
750  // Eliminate singletons
751  Val sl = 0;
752 
753  if (IntView::me(med) == ME_INT_VAL) {
754  for (int i = x.size(); i--; ) {
755  Val m = x[i].min();
756  if (x[i].assigned()) {
757  c -= m; x.move_lst(i);
758  } else {
759  sl -= m;
760  }
761  }
762  for (int i = y.size(); i--; ) {
763  Val m = y[i].max();
764  if (y[i].assigned()) {
765  c += m; y.move_lst(i);
766  } else {
767  sl += m;
768  }
769  }
770  if ((x.size() + y.size()) <= 1) {
771  if (x.size() == 1) {
772  GECODE_ME_CHECK(x[0].lq(home,c));
773  return home.ES_SUBSUMED(*this);
774  }
775  if (y.size() == 1) {
776  GECODE_ME_CHECK(y[0].gq(home,-c));
777  return home.ES_SUBSUMED(*this);
778  }
779  return (c >= static_cast<Val>(0)) ?
780  home.ES_SUBSUMED(*this) : ES_FAILED;
781  }
782  } else {
783  for (int i = x.size(); i--; )
784  sl -= x[i].min();
785  for (int i = y.size(); i--; )
786  sl += y[i].max();
787  }
788 
789  sl += c;
790 
791  ExecStatus es = ES_FIX;
792  bool assigned = true;
793  for (int i = x.size(); i--; ) {
794  assert(!x[i].assigned());
795  Val slx = sl + x[i].min();
796  ModEvent me = x[i].lq(home,slx);
797  if (me == ME_INT_FAILED)
798  return ES_FAILED;
799  if (me != ME_INT_VAL)
800  assigned = false;
801  if (me_modified(me) && (slx != x[i].max()))
802  es = ES_NOFIX;
803  }
804 
805  for (int i = y.size(); i--; ) {
806  assert(!y[i].assigned());
807  Val sly = y[i].max() - sl;
808  ModEvent me = y[i].gq(home,sly);
809  if (me == ME_INT_FAILED)
810  return ES_FAILED;
811  if (me != ME_INT_VAL)
812  assigned = false;
813  if (me_modified(me) && (sly != y[i].min()))
814  es = ES_NOFIX;
815  }
816  return assigned ? home.ES_SUBSUMED(*this) : es;
817  }
818 
819  /*
820  * Reified bound consistent linear inequation
821  *
822  */
823 
824  template<class Val, class P, class N, ReifyMode rm>
827  ViewArray<P>& x, ViewArray<N>& y, Val c, BoolView b)
828  : ReLin<Val,P,N,PC_INT_BND,BoolView>(home,x,y,c,b) {}
829 
830  template<class Val, class P, class N, ReifyMode rm>
831  ExecStatus
833  ViewArray<P>& x, ViewArray<N>& y, Val c, BoolView b) {
834  ViewArray<NoView> nva;
835  if (y.size() == 0) {
836  (void) new (home) ReLq<Val,P,NoView,rm>(home,x,nva,c,b);
837  } else if (x.size() == 0) {
838  (void) new (home) ReLq<Val,NoView,N,rm>(home,nva,y,c,b);
839  } else {
840  (void) new (home) ReLq<Val,P,N,rm>(home,x,y,c,b);
841  }
842  return ES_OK;
843  }
844 
845 
846  template<class Val, class P, class N, ReifyMode rm>
849  : ReLin<Val,P,N,PC_INT_BND,BoolView>(home,p) {}
850 
851  template<class Val, class P, class N, ReifyMode rm>
852  Actor*
854  return new (home) ReLq<Val,P,N,rm>(home,*this);
855  }
856 
857  template<class Val, class P, class N, ReifyMode rm>
858  ExecStatus
860  if (b.zero()) {
861  if (rm == RM_IMP)
862  return home.ES_SUBSUMED(*this);
863  GECODE_REWRITE(*this,(Lq<Val,N,P>::post(home(*this),y,x,-c-1)));
864  }
865  if (b.one()) {
866  if (rm == RM_PMI)
867  return home.ES_SUBSUMED(*this);
868  GECODE_REWRITE(*this,(Lq<Val,P,N>::post(home(*this),x,y,c)));
869  }
870 
871  // Eliminate singletons
872  Val sl = 0;
873  Val su = 0;
874 
875  bounds_p<Val,P>(med,x,c,sl,su);
876  bounds_n<Val,N>(med,y,c,sl,su);
877 
878  if (-sl > c) {
879  if (rm != RM_PMI)
880  GECODE_ME_CHECK(b.zero_none(home));
881  return home.ES_SUBSUMED(*this);
882  }
883  if (-su <= c) {
884  if (rm != RM_IMP)
885  GECODE_ME_CHECK(b.one_none(home));
886  return home.ES_SUBSUMED(*this);
887  }
888 
889  return ES_FIX;
890  }
891 
892 }}}
893 
894 // STATISTICS: int-prop
895 
Propagator for bounds consistent binary linear disequality
Definition: linear.hh:205
void mod(Home home, IntVar x0, IntVar x1, IntVar x2, IntPropLevel ipl)
Post propagator for .
Definition: arithmetic.cpp:267
#define GECODE_REWRITE(prop, post)
Rewrite propagator by executing post function.
Definition: macros.hpp:120
bool isunit(ViewArray< P > &, ViewArray< N > &)
Test if only unit-coefficient arrays used.
Definition: int-nary.hpp:48
static ExecStatus post(Home home, ViewArray< P > &x, ViewArray< N > &y, Val c)
Post propagator for .
Definition: int-nary.hpp:486
Propagator for bounds consistent n-ary linear equality
Definition: linear.hh:581
bool zero(void) const
Test whether view is assigned to be zero.
Definition: bool.hpp:214
Actor * nqtobin(Space &, Propagator &, ViewArray< P > &, ViewArray< N > &, Val)
Rewriting of disequality to binary propagators.
Definition: int-nary.hpp:510
Inverse implication for reification.
Definition: int.hh:848
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:1657
Actor * eqtobin(Space &, Propagator &, ViewArray< P > &, ViewArray< N > &, Val)
Rewriting of equality to binary propagators.
Definition: int-nary.hpp:308
ViewArray< N > y
Array of negative views.
Definition: linear.hh:506
Propagator for reified bounds consistent n-ary linear less or equal
Definition: linear.hh:753
ExecStatus ES_SUBSUMED(Propagator &p)
Definition: core.hpp:3433
const FloatNum max
Largest allowed float value.
Definition: float.hh:848
Actor * lqtoter(Space &, Propagator &, ViewArray< P > &, ViewArray< N > &, Val)
Rewriting of inequality to ternary propagators.
Definition: int-nary.hpp:698
static ExecStatus post(Home home, ViewArray< P > &x, ViewArray< N > &y, Val c)
Post propagator for .
Definition: int-nary.hpp:284
Propagator for bounds consistent n-ary linear disequality
Definition: linear.hh:687
bool one(void) const
Test whether view is assigned to be one.
Definition: bool.hpp:218
void max(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition: arithmetic.cpp:53
Actor * lqtobin(Space &, Propagator &, ViewArray< P > &, ViewArray< N > &, Val)
Rewriting of inequality to binary propagators.
Definition: int-nary.hpp:659
Propagator for bounds consistent ternary linear equality
Definition: linear.hh:388
ExecStatus prop_bnd(Space &home, ModEventDelta med, Propagator &p, ViewArray< P > &x, ViewArray< N > &y, Val &c)
Definition: int-nary.hpp:187
int ModEvent
Type for modification events.
Definition: core.hpp:64
void linear(Home home, const FloatVarArgs &x, FloatRelType frt, FloatVal c)
Post propagator for .
Definition: linear.cpp:45
Base-class for reified n-ary linear propagators.
Definition: linear.hh:533
Base-class for propagators.
Definition: core.hpp:1016
Base-class for n-ary linear propagators.
Definition: linear.hh:501
virtual Actor * copy(Space &home)
Create copy during cloning.
Definition: int-nary.hpp:587
#define forceinline
Definition: config.hpp:182
Propagation has computed fixpoint.
Definition: core.hpp:469
virtual Actor * copy(Space &home)
Create copy during cloning.
Definition: int-nary.hpp:853
Propagator for bounds consistent binary linear equality
Definition: linear.hh:138
Computation spaces.
Definition: core.hpp:1668
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: int-nary.hpp:600
ReEq(Space &home, ReEq &p)
Constructor for cloning p.
Definition: int-nary.hpp:431
Base-class for both propagators and branchers.
Definition: core.hpp:620
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: int-nary.hpp:442
ViewArray< P > x
Array of positive views.
Definition: linear.hh:504
const Gecode::ModEvent ME_INT_FAILED
Domain operation has resulted in failure.
Definition: var-type.hpp:52
Propagator for bounds consistent ternary linear less or equal
Definition: linear.hh:458
Gecode::FloatVal c(-8, 8)
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: int-nary.hpp:398
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:236
const FloatNum min
Smallest allowed float value.
Definition: float.hh:850
Gecode::IntArgs i(4, 1, 2, 3, 4)
static ExecStatus post(Home home, ViewArray< P > &x, ViewArray< N > &y, Val c, BoolView b)
Post propagator for .
Definition: int-nary.hpp:832
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
Execution has resulted in failure.
Definition: core.hpp:466
ModEvent zero_none(Space &home)
Assign not yet assigned view to zero.
Definition: bool.hpp:232
void bounds_n(ModEventDelta med, ViewArray< View > &y, Val &c, Val &sl, Val &su)
Definition: int-nary.hpp:165
const Gecode::PropCond PC_INT_BND
Propagate when minimum or maximum of a view changes.
Definition: var-type.hpp:91
const Gecode::ModEvent ME_INT_VAL
Domain operation has resulted in a value (assigned variable)
Definition: var-type.hpp:56
virtual Actor * copy(Space &home)
Create copy during cloning.
Definition: int-nary.hpp:385
ModEventDelta med
A set of modification events (used during propagation)
Definition: core.hpp:1027
Propagator for bounds consistent binary linear less or equal
Definition: linear.hh:241
virtual Actor * copy(Space &home)
Create copy during cloning.
Definition: int-nary.hpp:736
Actor * nqtoter(Space &, Propagator &, ViewArray< P > &, ViewArray< N > &, Val)
Rewriting of disequality to ternary propagators.
Definition: int-nary.hpp:549
void update(Space &home, VarImpVar< VarImp > &y)
Update this variable to be a clone of variable y.
Definition: var.hpp:128
size_t size
The size of the propagator (used during subsumption)
Definition: core.hpp:1029
ReLq(Space &home, ReLq &p)
Constructor for cloning p.
Definition: int-nary.hpp:848
Propagator for reified bounds consistent n-ary linear equality
Definition: linear.hh:653
void bounds_p(ModEventDelta med, ViewArray< View > &x, Val &c, Val &sl, Val &su)
Definition: int-nary.hpp:144
#define GECODE_ME_CHECK(me)
Check whether modification event me is failed, and forward failure.
Definition: macros.hpp:56
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: int-nary.hpp:749
Lq(Space &home, Lq &p)
Constructor for cloning p.
Definition: int-nary.hpp:650
Actor * eqtoter(Space &, Propagator &, ViewArray< P > &, ViewArray< N > &, Val)
Rewriting of equality to ternary propagators.
Definition: int-nary.hpp:347
void min(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition: arithmetic.cpp:71
struct Gecode::@585::NNF::@62::@63 b
For binary nodes (and, or, eqv)
Post propagator for SetVar SetOpType SetVar y
Definition: set.hh:769
static ExecStatus post(Home home, ViewArray< P > &x, ViewArray< N > &y, Val c, Ctrl b)
Post propagator for .
Definition: int-nary.hpp:415
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
virtual Actor * copy(Space &home)
Create copy during cloning.
Definition: int-nary.hpp:436
static ExecStatus post(Home home, ViewArray< P > &x, ViewArray< N > &y, Val c)
Post propagator for .
Definition: int-nary.hpp:635
Propagation cost.
Definition: core.hpp:478
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: int-nary.hpp:859
ExecStatus
Definition: core.hpp:464
Minus integer view.
Definition: view.hpp:278
bool assigned(View x, int v)
Whether x is assigned to value v.
Definition: single.hpp:47
static ModEvent me(const ModEventDelta &med)
Return modification event for view type in med.
Definition: view.hpp:514
bool me_modified(ModEvent me)
Check whether modification event me describes variable modification.
Definition: modevent.hpp:63
Eq(Space &home, Eq &p)
Constructor for cloning p.
Definition: int-nary.hpp:299
Post propagator for SetVar x
Definition: set.hh:769
Execution is okay.
Definition: core.hpp:468
Propagation has not computed fixpoint.
Definition: core.hpp:467
Nq(Space &home, Nq &p)
Constructor for cloning p.
Definition: int-nary.hpp:501
Ctrl b
Control view for reification.
Definition: linear.hh:538
Gecode toplevel namespace
Propagator for bounds consistent n-ary linear less or equal
Definition: linear.hh:720
Implication for reification.
Definition: int.hh:841
Lin(Space &home, Lin< Val, P, N, pc > &p)
Constructor for cloning p.
Definition: int-nary.hpp:73
virtual void reschedule(Space &home)
Schedule function.
Definition: int-nary.hpp:87
ModEvent one_none(Space &home)
Assign not yet assigned view to one.
Definition: bool.hpp:236
void reschedule(Space &home, Propagator &p, IntSet &y)
Definition: rel.hpp:96
Propagator for bounds consistent ternary linear disquality
Definition: linear.hh:423
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:1203
int ModEventDelta
Modification event deltas.
Definition: core.hpp:91
Home class for posting propagators
Definition: core.hpp:846
bool me_failed(ModEvent me)
Check whether modification event me is failed.
Definition: modevent.hpp:58
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:1329