36 namespace Gecode {
namespace Int {
namespace Linear {
42 template<
class P,
class N>
59 template<
class Val,
class P,
class N, PropCond pc>
63 x.subscribe(home,*
this,pc);
64 y.subscribe(home,*
this,pc);
67 template<
class Val,
class P,
class N, PropCond pc>
75 template<
class Val,
class P,
class N, PropCond pc>
81 template<
class Val,
class P,
class N, PropCond pc>
84 x.reschedule(home,*
this,pc);
85 y.reschedule(home,*
this,pc);
88 template<
class Val,
class P,
class N, PropCond pc>
91 x.cancel(home,*
this,pc);
92 y.cancel(home,*
this,pc);
93 (void) Propagator::dispose(home);
101 template<
class Val,
class P,
class N, PropCond pc,
class Ctrl>
109 template<
class Val,
class P,
class N, PropCond pc,
class Ctrl>
117 template<
class Val,
class P,
class N, PropCond pc,
class Ctrl>
125 template<
class Val,
class P,
class N, PropCond pc,
class Ctrl>
130 return sizeof(*this);
138 template<
class Val,
class View>
143 for (
int i=n;
i--; ) {
146 c -= m; x[
i] = x[--
n];
148 sl -= m; su -= x[
i].max();
153 for (
int i=0;
i<
n;
i++) {
154 sl -= x[
i].min(); su -= x[
i].max();
159 template<
class Val,
class View>
164 for (
int i=n;
i--; ) {
167 c += m; y[
i] = y[--
n];
169 sl += m; su += y[
i].min();
174 for (
int i=0;
i<
n;
i++) {
175 sl += y[
i].max(); su += y[
i].min();
181 template<
class Val,
class P,
class N>
189 bounds_p<Val,P>(med,
x,
c, sl, su);
190 bounds_n<Val,N>(med,
y,
c, sl, su);
192 if ((IntView::me(med) ==
ME_INT_VAL) && ((x.size() + y.size()) <= 1)) {
201 return (c == static_cast<Val>(0)) ?
207 const int mod_sl = 1;
208 const int mod_su = 2;
210 int mod = mod_sl | mod_su;
216 for (
int i=0;
i<x.
size();
i++) {
217 const Val xi_max = x[
i].max();
222 su += xi_max - x[
i].max();
227 for (
int i=0;
i<y.
size();
i++) {
228 const Val yi_min = y[
i].min();
233 su += y[
i].min() - yi_min;
241 for (
int i=0;
i<x.
size();
i++) {
242 const Val xi_min = x[
i].min();
247 sl += xi_min - x[
i].min();
252 for (
int i=0;
i<y.
size();
i++) {
253 const Val yi_max = y[
i].max();
258 sl += y[
i].max() - yi_max;
273 template<
class Val,
class P,
class N>
278 template<
class Val,
class P,
class N>
284 }
else if (x.
size() == 0) {
293 template<
class Val,
class P,
class N>
302 template<
class Val,
class P,
class N>
311 assert(x.
size() == 2);
313 (home,p,x[0],x[1],c);
319 assert(y.
size() == 2);
321 (home,p,y[0],y[1],-c);
329 (home,
p,x[0],x[1],
c);
334 (home,p,y[0],y[1],-c);
341 template<
class Val,
class P,
class N>
350 assert(x.
size() == 3);
352 (home,p,x[0],x[1],x[2],c);
358 assert(y.
size() == 3);
360 (home,p,y[0],y[1],y[2],-c);
368 (home,
p,x[0],x[1],x[2],
c);
376 (home,p,y[0],y[1],y[2],-c);
379 template<
class Val,
class P,
class N>
385 return eqtobin(home,*
this,x,y,c);
387 return eqtoter(home,*
this,x,y,c);
392 template<
class Val,
class P,
class N>
395 return prop_bnd<Val,P,N>(home,
med,*
this,
x,
y,
c);
403 template<
class Val,
class P,
class N,
class Ctrl, ReifyMode rm>
409 template<
class Val,
class P,
class N,
class Ctrl, ReifyMode rm>
416 }
else if (x.
size() == 0) {
425 template<
class Val,
class P,
class N,
class Ctrl, ReifyMode rm>
430 template<
class Val,
class P,
class N,
class Ctrl, ReifyMode rm>
436 template<
class Val,
class P,
class N,
class Ctrl, ReifyMode rm>
453 bounds_p<Val,P>(
med,
x,
c, sl, su);
454 bounds_n<Val,N>(
med,
y,
c, sl, su);
456 if ((-sl == c) && (-su ==
c)) {
461 if ((-sl > c) || (-su < c)) {
475 template<
class Val,
class P,
class N>
480 template<
class Val,
class P,
class N>
486 }
else if (x.
size() == 0) {
495 template<
class Val,
class P,
class N>
504 template<
class Val,
class P,
class N>
513 assert(x.
size() == 2);
515 (home,p,x[0],x[1],c);
521 assert(y.
size() == 2);
523 (home,p,y[0],y[1],-c);
531 (home,
p,x[0],x[1],
c);
536 (home,p,y[0],y[1],-c);
543 template<
class Val,
class P,
class N>
552 assert(x.
size() == 3);
554 (home,p,x[0],x[1],x[2],c);
560 assert(y.
size() == 3);
562 (home,p,y[0],y[1],y[2],-c);
570 (home,
p,x[0],x[1],x[2],
c);
578 (home,p,y[0],y[1],y[2],-c);
581 template<
class Val,
class P,
class N>
587 return nqtobin(home,*
this,x,y,c);
589 return nqtoter(home,*
this,x,y,c);
594 template<
class Val,
class P,
class N>
597 for (
int i=x.
size();
i--; )
599 c -= x[
i].val(); x.move_lst(
i);
601 for (
int i=y.
size();
i--; )
603 c += y[
i].val(); y.move_lst(
i);
612 return (c == static_cast<Val>(0)) ?
624 template<
class Val,
class P,
class N>
629 template<
class Val,
class P,
class N>
635 }
else if (x.
size() == 0) {
644 template<
class Val,
class P,
class N>
653 template<
class Val,
class P,
class N>
662 assert(x.
size() == 2);
664 (home,p,x[0],x[1],c);
670 assert(y.
size() == 2);
680 (home,
p,x[0],x[1],
c);
692 template<
class Val,
class P,
class N>
701 assert(x.
size() == 3);
703 (home,p,x[0],x[1],x[2],c);
709 assert(y.
size() == 3);
719 (home,
p,x[0],x[1],x[2],
c);
730 template<
class Val,
class P,
class N>
736 return lqtobin(home,*
this,x,y,c);
738 return lqtoter(home,*
this,x,y,c);
743 template<
class Val,
class P,
class N>
750 for (
int i=x.
size();
i--; ) {
753 c -= m; x.move_lst(
i);
758 for (
int i=y.
size();
i--; ) {
761 c += m; y.move_lst(
i);
775 return (c >= static_cast<Val>(0)) ?
789 for (
int i=0;
i<x.
size();
i++) {
791 Val slx = sl + x[
i].min();
801 for (
int i=0;
i<y.
size();
i++) {
803 Val sly = y[
i].max() - sl;
820 template<
class Val,
class P,
class N, ReifyMode rm>
826 template<
class Val,
class P,
class N, ReifyMode rm>
833 }
else if (x.
size() == 0) {
842 template<
class Val,
class P,
class N, ReifyMode rm>
847 template<
class Val,
class P,
class N, ReifyMode rm>
853 template<
class Val,
class P,
class N, ReifyMode rm>
871 bounds_p<Val,P>(
med,
x,
c,sl,su);
872 bounds_n<Val,N>(
med,
y,
c,sl,su);
Propagator for bounds consistent binary linear disequality
void mod(Home home, IntVar x0, IntVar x1, IntVar x2, IntPropLevel ipl)
Post propagator for .
#define GECODE_REWRITE(prop, post)
Rewrite propagator by executing post function.
bool isunit(ViewArray< P > &, ViewArray< N > &)
Test if only unit-coefficient arrays used.
static ExecStatus post(Home home, ViewArray< P > &x, ViewArray< N > &y, Val c)
Post propagator for .
Propagator for bounds consistent n-ary linear equality
bool zero(void) const
Test whether view is assigned to be zero.
Actor * nqtobin(Space &, Propagator &, ViewArray< P > &, ViewArray< N > &, Val)
Rewriting of disequality to binary propagators.
Inverse implication for reification.
int size(void) const
Return size of array (number of elements)
Actor * eqtobin(Space &, Propagator &, ViewArray< P > &, ViewArray< N > &, Val)
Rewriting of equality to binary propagators.
ViewArray< N > y
Array of negative views.
Propagator for reified bounds consistent n-ary linear less or equal
ExecStatus ES_SUBSUMED(Propagator &p)
const FloatNum max
Largest allowed float value.
Actor * lqtoter(Space &, Propagator &, ViewArray< P > &, ViewArray< N > &, Val)
Rewriting of inequality to ternary propagators.
static ExecStatus post(Home home, ViewArray< P > &x, ViewArray< N > &y, Val c)
Post propagator for .
Propagator for bounds consistent n-ary linear disequality
bool one(void) const
Test whether view is assigned to be one.
void max(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Actor * lqtobin(Space &, Propagator &, ViewArray< P > &, ViewArray< N > &, Val)
Rewriting of inequality to binary propagators.
Propagator for bounds consistent ternary linear equality
ExecStatus prop_bnd(Space &home, ModEventDelta med, Propagator &p, ViewArray< P > &x, ViewArray< N > &y, Val &c)
int ModEvent
Type for modification events.
void linear(Home home, const FloatVarArgs &x, FloatRelType frt, FloatVal c)
Post propagator for .
Base-class for reified n-ary linear propagators.
Base-class for propagators.
Base-class for n-ary linear propagators.
virtual Actor * copy(Space &home)
Create copy during cloning.
Propagation has computed fixpoint.
virtual Actor * copy(Space &home)
Create copy during cloning.
Propagator for bounds consistent binary linear equality
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
ReEq(Space &home, ReEq &p)
Constructor for cloning p.
Base-class for both propagators and branchers.
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
ViewArray< P > x
Array of positive views.
const Gecode::ModEvent ME_INT_FAILED
Domain operation has resulted in failure.
Propagator for bounds consistent ternary linear less or equal
Gecode::FloatVal c(-8, 8)
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
int p
Number of positive literals for node type.
const FloatNum min
Smallest allowed float value.
static ExecStatus post(Home home, ViewArray< P > &x, ViewArray< N > &y, Val c, BoolView b)
Post propagator for .
int n
Number of negative literals for node type.
Gecode::IntArgs i({1, 2, 3, 4})
Execution has resulted in failure.
ModEvent zero_none(Space &home)
Assign not yet assigned view to zero.
void bounds_n(ModEventDelta med, ViewArray< View > &y, Val &c, Val &sl, Val &su)
const Gecode::PropCond PC_INT_BND
Propagate when minimum or maximum of a view changes.
const Gecode::ModEvent ME_INT_VAL
Domain operation has resulted in a value (assigned variable)
virtual Actor * copy(Space &home)
Create copy during cloning.
ModEventDelta med
A set of modification events (used during propagation)
Propagator for bounds consistent binary linear less or equal
struct Gecode::@593::NNF::@62::@63 b
For binary nodes (and, or, eqv)
virtual Actor * copy(Space &home)
Create copy during cloning.
Actor * nqtoter(Space &, Propagator &, ViewArray< P > &, ViewArray< N > &, Val)
Rewriting of disequality to ternary propagators.
void update(Space &home, VarImpVar< VarImp > &y)
Update this variable to be a clone of variable y.
size_t size
The size of the propagator (used during subsumption)
ReLq(Space &home, ReLq &p)
Constructor for cloning p.
Propagator for reified bounds consistent n-ary linear equality
void bounds_p(ModEventDelta med, ViewArray< View > &x, Val &c, Val &sl, Val &su)
#define GECODE_ME_CHECK(me)
Check whether modification event me is failed, and forward failure.
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Lq(Space &home, Lq &p)
Constructor for cloning p.
Actor * eqtoter(Space &, Propagator &, ViewArray< P > &, ViewArray< N > &, Val)
Rewriting of equality to ternary propagators.
void min(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Post propagator for SetVar SetOpType SetVar y
static ExecStatus post(Home home, ViewArray< P > &x, ViewArray< N > &y, Val c, Ctrl b)
Post propagator for .
Node * x
Pointer to corresponding Boolean expression node.
virtual Actor * copy(Space &home)
Create copy during cloning.
static ExecStatus post(Home home, ViewArray< P > &x, ViewArray< N > &y, Val c)
Post propagator for .
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
bool assigned(View x, int v)
Whether x is assigned to value v.
static ModEvent me(const ModEventDelta &med)
Return modification event for view type in med.
bool me_modified(ModEvent me)
Check whether modification event me describes variable modification.
Eq(Space &home, Eq &p)
Constructor for cloning p.
Post propagator for SetVar x
Propagation has not computed fixpoint.
Nq(Space &home, Nq &p)
Constructor for cloning p.
Ctrl b
Control view for reification.
Gecode toplevel namespace
Propagator for bounds consistent n-ary linear less or equal
Implication for reification.
Lin(Space &home, Lin< Val, P, N, pc > &p)
Constructor for cloning p.
virtual void reschedule(Space &home)
Schedule function.
ModEvent one_none(Space &home)
Assign not yet assigned view to one.
void reschedule(Space &home, Propagator &p, IntSet &y)
Propagator for bounds consistent ternary linear disquality
int size(void) const
Return size of array (number of elements)
int ModEventDelta
Modification event deltas.
Home class for posting propagators
bool me_failed(ModEvent me)
Check whether modification event me is failed.
const Gecode::PropCond PC_INT_VAL
Propagate when a view becomes assigned (single value)
const Gecode::PropCond PC_BOOL_VAL
Propagate when a view becomes assigned (single value)
Boolean view for Boolean variables.