Generated on Wed Nov 1 15:04:43 2006 for Gecode by doxygen 1.4.5

lin-expr.cc

Go to the documentation of this file.
00001 /*
00002  *  Main authors:
00003  *     Guido Tack <tack@gecode.org>
00004  *     Christian Schulte <schulte@gecode.org>
00005  *
00006  *  Copyright:
00007  *     Guido Tack, 2004
00008  *     Christian Schulte, 2004
00009  *
00010  *  Last modified:
00011  *     $Date: 2006-08-04 16:05:26 +0200 (Fri, 04 Aug 2006) $ by $Author: schulte $
00012  *     $Revision: 3513 $
00013  *
00014  *  This file is part of Gecode, the generic constraint
00015  *  development environment:
00016  *     http://www.gecode.org
00017  *
00018  *  See the file "LICENSE" for information on usage and
00019  *  redistribution of this file, and for a
00020  *     DISCLAIMER OF ALL WARRANTIES.
00021  *
00022  */
00023 
00024 #include "gecode/minimodel.hh"
00025 
00026 namespace Gecode {
00027 
00028   namespace MiniModel {
00029 
00030     /*
00031      * Operations for linear expressions
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 // STATISTICS: minimodel-any