lin-expr.cc
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "gecode/minimodel.hh"
00025
00026 namespace Gecode {
00027
00028 namespace MiniModel {
00029
00030
00031
00032
00033
00034
00035 bool
00036 LinExpr::Node::decrement(void) {
00037 if (--use == 0) {
00038 if (left != NULL) {
00039 if (left->decrement())
00040 delete left;
00041 if (right->decrement())
00042 delete right;
00043 }
00044 return true;
00045 }
00046 return false;
00047 }
00048
00049 int
00050 LinExpr::Node::fill(Int::Linear::Term t[], int i, int m) const {
00051 if (left != NULL) {
00052 return right->fill(t, left->fill(t, i, signLeft*m), signRight*m);
00053 } else {
00054 t[i].a=m*a; t[i].x=x;
00055 return i+1;
00056 }
00057 }
00058
00059 void
00060 LinExpr::post(Space* home, IntRelType irt, IntConLevel icl) const {
00061 GECODE_AUTOARRAY(Int::Linear::Term, ts, n);
00062 (void) ax->fill(ts,0,sign);
00063 Int::Linear::post(home, ts, n, irt, sign*-c, icl);
00064 }
00065
00066 void
00067 LinExpr::post(Space* home, IntRelType irt, const BoolVar& b) const {
00068 GECODE_AUTOARRAY(Int::Linear::Term, ts, n);
00069 (void) ax->fill(ts,0,sign);
00070 Int::Linear::post(home, ts, n, irt, sign*-c, b);
00071 }
00072
00073 IntVar
00074 LinExpr::post(Space* home, IntConLevel icl) const {
00075 GECODE_AUTOARRAY(Int::Linear::Term, ts, n+1);
00076 (void) ax->fill(ts,0,sign);
00077 double min = sign*-c;
00078 double max = sign*-c;
00079 for (int i=n; i--; )
00080 if (ts[i].a > 0) {
00081 min += ts[i].a*ts[i].x.min();
00082 max += ts[i].a*ts[i].x.max();
00083 } else {
00084 max += ts[i].a*ts[i].x.min();
00085 min += ts[i].a*ts[i].x.max();
00086 }
00087 if (min < Limits::Int::int_min)
00088 min = Limits::Int::int_min;
00089 if (max > Limits::Int::int_max)
00090 max = Limits::Int::int_max;
00091 IntVar x(home, static_cast<int>(min), static_cast<int>(max));
00092 ts[n].x = x;
00093 ts[n].a = -1;
00094 Int::Linear::post(home, ts, n+1, IRT_EQ, sign*-c, icl);
00095 return x;
00096 }
00097
00098
00099 }
00100
00101 }
00102
00103