Generated on Wed Jan 4 17:49:13 2006 for Gecode by doxygen 1.4.6

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: 2005-08-03 17:17:11 +0200 (Wed, 03 Aug 2005) $ by $Author: schulte $
00012  *     $Revision: 2126 $
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 "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         assert(false);
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_AND:
00115           l->post(home,true);
00116           r->post(home,true);
00117           break;
00118         case BT_EQV:
00119           if ((l->t == BT_VAR) && (r->t != BT_VAR)) {
00120             r->post(home,l->x);
00121           } else if ((l->t != BT_VAR) && (r->t == BT_VAR)) {
00122             l->post(home,r->x);
00123           } else if ((l->t != BT_VAR) && (r->t != BT_VAR)) {
00124             BoolVar b(home,0,1);
00125             l->post(home,b);
00126             r->post(home,b);
00127           } else {
00128             BoolVar b(home,1,1);
00129             post(home,b);
00130           }
00131           break;
00132         case BT_RLIN:
00133           rl.post(home,true);
00134           break;
00135         default:
00136           {
00137             BoolVar b(home,1,1);
00138             post(home,b);
00139           }
00140           break;
00141         }
00142       } else {
00143         switch (t) {
00144         case BT_VAR:
00145           rel(home, x, IRT_EQ, 0);
00146           break;
00147         case BT_NOT:
00148           l->post(home,true);
00149           break;
00150         case BT_OR:
00151           l->post(home,false);
00152           r->post(home,false);
00153           break;
00154         case BT_IMP:
00155           l->post(home,true);
00156           r->post(home,false);
00157           break;
00158         case BT_XOR:
00159           if ((l->t == BT_VAR) && (r->t != BT_VAR)) {
00160             r->post(home,l->x);
00161           } else if ((l->t != BT_VAR) && (r->t == BT_VAR)) {
00162             l->post(home,r->x);
00163           } else if ((l->t != BT_VAR) && (r->t != BT_VAR)) {
00164             BoolVar b(home,0,1);
00165             l->post(home,b);
00166             r->post(home,b);
00167           } else {
00168             BoolVar b(home,0,0);
00169             post(home,b);
00170           }
00171           break;
00172         case BT_RLIN:
00173           rl.post(home,false);
00174           break;
00175         default: 
00176           {
00177             BoolVar b(home,0,0);
00178             post(home,b);
00179           }
00180           break;
00181         }
00182       }
00183     }
00184 
00185   }
00186 
00187 }
00188 
00189 // STATISTICS: minimodel-any