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

bool-expr.icc

Go to the documentation of this file.
00001 /*
00002  *  Main authors:
00003  *     Guido Tack <tack@gecode.org>
00004  *
00005  *  Copyright:
00006  *     Guido Tack, 2004
00007  *
00008  *  Last modified:
00009  *     $Date: 2006-08-04 16:05:26 +0200 (Fri, 04 Aug 2006) $ by $Author: schulte $
00010  *     $Revision: 3513 $
00011  *
00012  *  This file is part of Gecode, the generic constraint
00013  *  development environment:
00014  *     http://www.gecode.org
00015  *
00016  *  See the file "LICENSE" for information on usage and
00017  *  redistribution of this file, and for a
00018  *     DISCLAIMER OF ALL WARRANTIES.
00019  *
00020  */
00021 
00022 namespace Gecode { namespace MiniModel {
00023 
00024   /*
00025    * Operations for nodes
00026    *
00027    */
00028   forceinline void*
00029   BoolExpr::Node::operator new(size_t size) {
00030     return Memory::malloc(size);
00031   }
00032 
00033   forceinline void
00034   BoolExpr::Node::operator delete(void* p, size_t) {
00035     Memory::free(p);
00036   }
00037 
00038   forceinline
00039   BoolExpr::Node::Node(void) : use(1) {};
00040 
00041   /*
00042    * Operations for expressions
00043    *
00044    */
00045 
00046   forceinline
00047   BoolExpr::BoolExpr(const BoolExpr& e) : n(e.n) {
00048     n->use++;
00049   }
00050 
00051   inline
00052   BoolExpr::BoolExpr(const BoolVar& x) : n(new Node) {
00053     n->same = 1;
00054     n->t    = BT_VAR;
00055     n->l    = NULL;
00056     n->r    = NULL;
00057     n->x    = x;
00058   }
00059 
00060   inline
00061   BoolExpr::BoolExpr(const BoolExpr& l, NodeType t, const BoolExpr& r)
00062     : n(new Node) {
00063     unsigned int ls = ((l.n->t == t) || l.n->t == BT_VAR) ? l.n->same : 0;
00064     unsigned int rs = ((r.n->t == t) || r.n->t == BT_VAR) ? r.n->same : 0;
00065     n->same = ls+rs;
00066     n->t    = t;
00067     n->l    = l.n;
00068     n->l->use++;
00069     n->r    = r.n;
00070     n->r->use++;
00071   }
00072 
00073   inline
00074   BoolExpr::BoolExpr(const BoolExpr& l, NodeType t)
00075     : n(new Node) {
00076     assert(t == BT_NOT);
00077     n->same = 1;
00078     n->t    = BT_NOT;
00079     n->l    = l.n;
00080     n->l->use++;
00081     n->r    = NULL;
00082   }
00083 
00084   inline
00085   BoolExpr::BoolExpr(const LinRel& rl)
00086     : n(new Node) {
00087     n->same = 1;
00088     n->t    = BT_RLIN;
00089     n->l    = NULL;
00090     n->r    = NULL;
00091     n->rl   = rl;
00092   }
00093 
00094 
00095   inline const BoolExpr&
00096   BoolExpr::operator=(const BoolExpr& e) {
00097     if (this != &e) {
00098       if (n->decrement())
00099         delete n;
00100       n = e.n;
00101       n->use++;
00102     }
00103     return *this;
00104   }
00105 
00106   forceinline
00107   BoolExpr::~BoolExpr(void) {
00108     if (n->decrement())
00109       delete n;
00110   }
00111 
00112   forceinline BoolVar
00113   BoolExpr::post(Space* home) const {
00114     return n->post(home);
00115   }
00116 
00117   forceinline void
00118   BoolExpr::post(Space* home, bool t) const {
00119     n->post(home,t);
00120   }
00121 
00122 }}
00123 
00124 inline Gecode::MiniModel::BoolExpr
00125 operator&&(const Gecode::MiniModel::BoolExpr& l,
00126            const Gecode::MiniModel::BoolExpr& r) {
00127   return Gecode::MiniModel::BoolExpr(l,
00128                                      Gecode::MiniModel::BoolExpr::BT_AND,
00129                                      r);
00130 }
00131 
00132 inline Gecode::MiniModel::BoolExpr
00133 operator||(const Gecode::MiniModel::BoolExpr& l,
00134            const Gecode::MiniModel::BoolExpr& r) {
00135   return Gecode::MiniModel::BoolExpr(l,
00136                                      Gecode::MiniModel::BoolExpr::BT_OR,
00137                                      r);
00138 }
00139 
00140 inline Gecode::MiniModel::BoolExpr
00141 operator^(const Gecode::MiniModel::BoolExpr& l,
00142           const Gecode::MiniModel::BoolExpr& r) {
00143   return Gecode::MiniModel::BoolExpr(l,
00144                                      Gecode::MiniModel::BoolExpr::BT_XOR,
00145                                      r);
00146 }
00147 
00148 inline Gecode::MiniModel::BoolExpr
00149 operator~(const Gecode::MiniModel::LinRel& rl) {
00150   return Gecode::MiniModel::BoolExpr(rl);
00151 }
00152 
00153 inline Gecode::MiniModel::BoolExpr
00154 operator!(const Gecode::MiniModel::BoolExpr& e) {
00155   return Gecode::MiniModel::BoolExpr(e,
00156                                      Gecode::MiniModel::BoolExpr::BT_NOT);
00157 }
00158 
00159 namespace Gecode {
00160 
00161   inline MiniModel::BoolExpr
00162   eqv(const MiniModel::BoolExpr& l,
00163       const MiniModel::BoolExpr& r) {
00164     return MiniModel::BoolExpr(l,
00165                                MiniModel::BoolExpr::BT_EQV,
00166                                r);
00167   }
00168 
00169   inline MiniModel::BoolExpr
00170   imp(const MiniModel::BoolExpr& l,
00171       const MiniModel::BoolExpr& r) {
00172     return MiniModel::BoolExpr(l,
00173                                MiniModel::BoolExpr::BT_IMP,
00174                                r);
00175   }
00176 
00177 
00178   inline BoolVar
00179   post(Space* home, const MiniModel::BoolExpr& e, IntConLevel) {
00180     return e.post(home);
00181   }
00182 
00183   inline BoolVar
00184   post(Space* home, const BoolVar& b, IntConLevel) {
00185     return b;
00186   }
00187 
00188 
00189 }
00190 
00191 // STATISTICS: minimodel-any