44 namespace Gecode {
namespace Int {
namespace Linear {
50 if (t[
i].x.assigned()) {
51 d -= t[
i].
a *
static_cast<double>(t[
i].
x.val());
72 std::swap(n_p,n_n); std::swap(t_p,t_n); d = -
d;
87 for (
int i = n_p;
i--; ) {
88 sl += t_p[
i].
a *
static_cast<double>(t_p[
i].
x.min());
89 su += t_p[
i].
a *
static_cast<double>(t_p[
i].
x.max());
93 for (
int i = n_n;
i--; ) {
94 sl -= t_n[
i].
a *
static_cast<double>(t_n[
i].
x.max());
95 su -= t_n[
i].
a *
static_cast<double>(t_n[
i].
x.min());
109 for (
int i = n_p;
i--; ) {
110 if (sl - t_p[
i].
a * static_cast<double>(t_p[
i].x.min())
113 if (sl - t_p[
i].
a * static_cast<double>(t_p[
i].x.min()) <
Limits::min)
115 if (su - t_p[
i].
a * static_cast<double>(t_p[
i].x.max())
118 if (su - t_p[
i].
a * static_cast<double>(t_p[
i].x.max()) >
Limits::max)
121 for (
int i = n_n;
i--; ) {
122 if (sl + t_n[
i].
a * static_cast<double>(t_n[
i].x.min())
125 if (sl + t_n[
i].
a * static_cast<double>(t_n[
i].x.min()) <
Limits::min)
127 if (su + t_n[
i].
a * static_cast<double>(t_n[
i].x.max())
130 if (su + t_n[
i].
a * static_cast<double>(t_n[
i].x.max()) >
Limits::max)
140 template<
class Val,
class View>
160 #define GECODE_INT_PL_BIN(CLASS) \
163 GECODE_ES_FAIL((CLASS<int,IntView,IntView>::post \
164 (home,t_p[0].x,t_p[1].x,c))); \
167 GECODE_ES_FAIL((CLASS<int,IntView,MinusView>::post \
168 (home,t_p[0].x,MinusView(t_n[0].x),c))); \
171 GECODE_ES_FAIL((CLASS<int,MinusView,MinusView>::post \
172 (home,MinusView(t_n[0].x),MinusView(t_n[1].x),c))); \
174 default: GECODE_NEVER; \
178 #define GECODE_INT_PL_TER(CLASS) \
181 GECODE_ES_FAIL((CLASS<int,IntView,IntView,IntView>::post \
182 (home,t_p[0].x,t_p[1].x,t_p[2].x,c))); \
185 GECODE_ES_FAIL((CLASS<int,IntView,IntView,MinusView>::post \
186 (home,t_p[0].x,t_p[1].x, \
187 MinusView(t_n[0].x),c))); \
190 GECODE_ES_FAIL((CLASS<int,IntView,MinusView,MinusView>::post \
192 MinusView(t_n[0].x),MinusView(t_n[1].x),c))); \
195 GECODE_ES_FAIL((CLASS<int,MinusView,MinusView,MinusView>::post \
196 (home,MinusView(t_n[0].x), \
197 MinusView(t_n[1].x),MinusView(t_n[2].x),c))); \
199 default: GECODE_NEVER; \
214 bool is_unit = normalize<IntView>(t,n,t_p,n_p,t_n,n_n);
220 case IRT_EQ:
if (d != 0.0) home.
fail();
break;
221 case IRT_NQ:
if (d == 0.0) home.
fail();
break;
249 bool is_ip =
precision(t_p,n_p,t_n,n_n,d);
251 if (is_unit && is_ip && (icl !=
ICL_DOM)) {
253 c =
static_cast<int>(
d);
270 for (
int i = n_p;
i--; )
273 for (
int i = n_n;
i--; )
275 post_nary<int,IntView>(home,x,y,
r,
c);
280 c =
static_cast<int>(
d);
336 c =
static_cast<int>(
d);
338 for (
int i = n_p;
i--; )
341 for (
int i = n_n;
i--; )
346 post_nary<int,IntScaleView>(home,x,y,
r,
c);
352 for (
int i = n_p;
i--; )
355 for (
int i = n_n;
i--; )
360 post_nary<double,DoubleScaleView>(home,x,y,
r,
d);
365 #undef GECODE_INT_PL_BIN
366 #undef GECODE_INT_PL_TER
373 template<
class Val,
class View>
409 bool is_unit = normalize<IntView>(t,n,t_p,n_p,t_n,n_n);
416 case IRT_EQ: fail = (d != 0.0);
break;
417 case IRT_NQ: fail = (d == 0.0);
break;
418 case IRT_LQ: fail = (0.0 >
d);
break;
426 bool is_ip =
precision(t_p,n_p,t_n,n_n,d);
428 if (is_unit && is_ip) {
429 c =
static_cast<int>(
d);
435 (home,t_p[0].x,c,b)));
438 (home,t_n[0].x,-c,b)));
446 (home,t_p[0].x,c,nb)));
449 (home,t_n[0].x,-c,nb)));
456 (home,t_p[0].x,c,b)));
460 (home,t_n[0].x,-c-1,nb)));
471 (home,t_p[0].x,t_p[1].x,c,b)));
475 (home,t_p[0].x,
MinusView(t_n[0].x),c,b)));
479 (home,t_n[0].x,t_n[1].x,-c,b)));
491 (home,t_p[0].x,t_p[1].x,c,nb)));
512 (home,t_p[0].x,t_p[1].x,c,b)));
516 (home,t_p[0].x,
MinusView(t_n[0].x),c,b)));
530 for (
int i = n_p;
i--; )
533 for (
int i = n_n;
i--; )
535 post_nary<int,IntView>(home,x,y,
r,
c,
b);
539 c =
static_cast<int>(
d);
541 for (
int i = n_p;
i--; )
544 for (
int i = n_n;
i--; )
546 post_nary<int,IntScaleView>(home,x,y,
r,
c,
b);
550 for (
int i = n_p;
i--; )
553 for (
int i = n_n;
i--; )
555 post_nary<double,DoubleScaleView>(home,x,y,
r,
d,
b);