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

bool-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     bool
00031     BoolExpr::Node::decrement(void) {
00032       if (--use == 0) {
00033         if ((l != NULL) && l->decrement())
00034           delete l;
00035         if ((r != NULL) && r->decrement())
00036           delete r;
00037         return true;
00038       }
00039       return false;
00040     }
00041 
00042     BoolVar
00043     BoolExpr::Node::post(Space* home) const {
00044       if (t == BT_VAR)
00045         return x;
00046       BoolVar b(home,0,1);
00047       post(home,b);
00048       return b;
00049     }
00050 
00051     int
00052     BoolExpr::Node::post(Space* home, NodeType t,
00053                          BoolVarArgs& b, int i) const {
00054       if (this->t != t) {
00055         b[i] = post(home);
00056         return i+1;
00057       } else {
00058         return l->post(home,t,b,r->post(home,t,b,i));
00059       }
00060     }
00061 
00062     void
00063     BoolExpr::Node::post(Space* home, BoolVar b) const {
00064       assert(t != BT_VAR);
00065       switch (t) {
00066       case BT_NOT:
00067         bool_not(home, l->post(home), b);
00068         break;
00069       case BT_AND:
00070         if (same > 2) {
00071           BoolVarArgs ba(same);
00072           (void) post(home,BT_AND,ba,0);
00073           bool_and(home, ba, b);
00074         } else {
00075           bool_and(home, l->post(home), r->post(home), b);
00076         }
00077         break;
00078       case BT_OR:
00079         if (same > 2) {
00080           BoolVarArgs ba(same);
00081           (void) post(home,BT_OR,ba,0);
00082           bool_or(home, ba, b);
00083         } else {
00084           bool_or(home, l->post(home), r->post(home), b);
00085         }
00086         break;
00087       case BT_IMP:
00088         bool_imp(home, l->post(home), r->post(home), b);
00089         break;
00090       case BT_XOR:
00091         bool_xor(home, l->post(home), r->post(home), b);
00092         break;
00093       case BT_EQV:
00094         bool_eqv(home, l->post(home), r->post(home), b);
00095         break;
00096       default:
00097         GECODE_NEVER;
00098       case BT_RLIN:
00099         rl.post(home,b);
00100         break;
00101       }
00102     }
00103 
00104     void
00105     BoolExpr::Node::post(Space* home, bool b) const {
00106       if (b) {
00107         switch (t) {
00108         case BT_VAR:
00109           rel(home, x, IRT_EQ, 1);
00110           break;
00111         case BT_NOT:
00112           l->post(home,false);
00113           break;
00114         case BT_OR:
00115           if (same > 2) {
00116             BoolVarArgs ba(same);
00117             (void) post(home,BT_OR,ba,0);
00118             bool_or(home, ba, true);
00119           } else {
00120             bool_or(home, l->post(home), r->post(home), true);
00121           }
00122           break;
00123         case BT_AND:
00124           l->post(home,true);
00125           r->post(home,true);
00126           break;
00127         case BT_EQV:
00128           if ((l->t == BT_VAR) && (r->t != BT_VAR)) {
00129             r->post(home,l->x);
00130           } else if ((l->t != BT_VAR) && (r->t == BT_VAR)) {
00131             l->post(home,r->x);
00132           } else if ((l->t != BT_VAR) && (r->t != BT_VAR)) {
00133             BoolVar b(home,0,1);
00134             l->post(home,b);
00135             r->post(home,b);
00136           } else {
00137             BoolVar b(home,1,1);
00138             post(home,b);
00139           }
00140           break;
00141         case BT_RLIN:
00142           rl.post(home,true,ICL_DEF);
00143           break;
00144         default:
00145           {
00146             BoolVar b(home,1,1);
00147             post(home,b);
00148           }
00149           break;
00150         }
00151       } else {
00152         switch (t) {
00153         case BT_VAR:
00154           rel(home, x, IRT_EQ, 0);
00155           break;
00156         case BT_NOT:
00157           l->post(home,true);
00158           break;
00159         case BT_OR:
00160           l->post(home,false);
00161           r->post(home,false);
00162           break;
00163         case BT_AND:
00164           if (same > 2) {
00165             BoolVarArgs ba(same);
00166             (void) post(home,BT_AND,ba,0);
00167             bool_and(home, ba, false);
00168           } else {
00169             bool_and(home, l->post(home), r->post(home), false);
00170           }
00171           break;
00172         case BT_IMP:
00173           l->post(home,true);
00174           r->post(home,false);
00175           break;
00176         case BT_XOR:
00177           if ((l->t == BT_VAR) && (r->t != BT_VAR)) {
00178             r->post(home,l->x);
00179           } else if ((l->t != BT_VAR) && (r->t == BT_VAR)) {
00180             l->post(home,r->x);
00181           } else if ((l->t != BT_VAR) && (r->t != BT_VAR)) {
00182             BoolVar b(home,0,1);
00183             l->post(home,b);
00184             r->post(home,b);
00185           } else {
00186             BoolVar b(home,0,0);
00187             post(home,b);
00188           }
00189           break;
00190         case BT_RLIN:
00191           rl.post(home,false,ICL_DEF);
00192           break;
00193         default:
00194           {
00195             BoolVar b(home,0,0);
00196             post(home,b);
00197           }
00198           break;
00199         }
00200       }
00201     }
00202 
00203   }
00204 
00205 }
00206 
00207 // STATISTICS: minimodel-any