Generated on Tue Jul 27 2010 21:59:17 for Gecode by doxygen 1.7.1

set-expr.hpp

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Guido Tack <tack@gecode.org>
00005  *
00006  *  Copyright:
00007  *     Guido Tack, 2010
00008  *
00009  *  Last modified:
00010  *     $Date: 2010-07-14 20:32:01 +0200 (Wed, 14 Jul 2010) $ by $Author: schulte $
00011  *     $Revision: 11195 $
00012  *
00013  *  This file is part of Gecode, the generic constraint
00014  *  development environment:
00015  *     http://www.gecode.org
00016  *
00017  *  Permission is hereby granted, free of charge, to any person obtaining
00018  *  a copy of this software and associated documentation files (the
00019  *  "Software"), to deal in the Software without restriction, including
00020  *  without limitation the rights to use, copy, modify, merge, publish,
00021  *  distribute, sublicense, and/or sell copies of the Software, and to
00022  *  permit persons to whom the Software is furnished to do so, subject to
00023  *  the following conditions:
00024  *
00025  *  The above copyright notice and this permission notice shall be
00026  *  included in all copies or substantial portions of the Software.
00027  *
00028  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00029  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00030  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00031  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00032  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00033  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00034  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00035  *
00036  */
00037 
00038 #ifdef GECODE_HAS_SET_VARS
00039 
00040 namespace Gecode {
00041 
00042   /*
00043    * Operations for expressions
00044    *
00045    */
00046   forceinline
00047   SetExpr::Node::Node(void) : use(1) {}
00048 
00049   forceinline void*
00050   SetExpr::Node::operator new(size_t size) {
00051     return heap.ralloc(size);
00052   }
00053   forceinline void
00054   SetExpr::Node::operator delete(void* p, size_t) {
00055     heap.rfree(p);
00056   }
00057 
00058   forceinline
00059   SetExpr::SetExpr(void) : n(NULL) {}
00060 
00061   forceinline
00062   SetExpr::SetExpr(const SetExpr& e) : n(e.n) {
00063     n->use++;
00064   }
00065 
00066   forceinline
00067   SetExpr::SetExpr(const SetVar& x) : n(new Node) {
00068     n->same = 1;
00069     n->t    = NT_VAR;
00070     n->l    = NULL;
00071     n->r    = NULL;
00072     n->x    = x;
00073   }
00074 
00075   forceinline
00076   SetExpr::SetExpr(const IntSet& s) : n(new Node) {
00077     n->same = 1;
00078     n->t    = NT_CONST;
00079     n->l    = NULL;
00080     n->r    = NULL;
00081     n->s    = s;
00082   }
00083 
00084   forceinline
00085   SetExpr::SetExpr(const LinExpr& e) : n(new Node) {
00086     n->same = 1;
00087     n->t    = NT_LEXP;
00088     n->l    = NULL;
00089     n->r    = NULL;
00090     n->e    = e;
00091   }
00092   
00093   forceinline bool
00094   SetExpr::same(NodeType t0, NodeType t1) {
00095     return (t0==t1) || (t1==NT_VAR) || (t1==NT_CONST) || (t1==NT_LEXP);
00096   }
00097 
00098   forceinline
00099   SetExpr::SetExpr(const SetExpr& l, NodeType t, const SetExpr& r)
00100     : n(new Node) {
00101     int ls = same(t,l.n->t) ? l.n->same : 1;
00102     int rs = same(t,r.n->t) ? r.n->same : 1;
00103     n->same = ls+rs;
00104     n->t    = t;
00105     n->l    = l.n;
00106     n->l->use++;
00107     n->r    = r.n;
00108     n->r->use++;
00109   }
00110 
00111   forceinline
00112   SetExpr::SetExpr(const SetExpr& l, NodeType t) {
00113     (void) t;
00114     assert(t == NT_CMPL);
00115     if (l.n->t == NT_CMPL) {
00116       n = l.n->l;
00117       n->use++;
00118     } else {
00119       n = new Node;
00120       n->same = 1;
00121       n->t    = NT_CMPL;
00122       n->l    = l.n;
00123       n->l->use++;
00124       n->r    = NULL;
00125     }
00126   }
00127 
00128   inline SetVar
00129   SetExpr::post(Home home) const {
00130     Region r(home);
00131     SetVar s(home,IntSet::empty,
00132              IntSet(Set::Limits::min,Set::Limits::max));
00133     NNF::nnf(r,n,false)->post(home,SRT_EQ,s);
00134     return s;
00135   }
00136 
00137   inline void
00138   SetExpr::post(Home home, SetRelType srt, const SetExpr& e) const {
00139     Region r(home);
00140     return NNF::nnf(r,n,false)->post(home,srt,NNF::nnf(r,e.n,false));
00141   }
00142   inline void
00143   SetExpr::post(Home home, BoolVar b, bool t,
00144                 SetRelType srt, const SetExpr& e) const {
00145     Region r(home);
00146     return NNF::nnf(r,n,false)->post(home,b,t,srt,NNF::nnf(r,e.n,false));                  
00147   }
00148 
00149 }
00150 
00151 #endif
00152 
00153 // STATISTICS: minimodel-any