Generated on Thu Mar 22 10:39:35 2012 for Gecode by doxygen 1.6.3

dom.hpp

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Christian Schulte <schulte@gecode.org>
00005  *
00006  *  Copyright:
00007  *     Christian Schulte, 2003
00008  *
00009  *  Last modified:
00010  *     $Date: 2011-09-06 14:19:49 +0200 (Tue, 06 Sep 2011) $ by $Author: schulte $
00011  *     $Revision: 12393 $
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 #include <climits>
00039 
00040 namespace Gecode { namespace Int { namespace Distinct {
00041 
00042   template<class View>
00043   forceinline
00044   Dom<View>::Dom(Home home, ViewArray<View>& x)
00045     : NaryPropagator<View,PC_INT_DOM>(home,x) {}
00046 
00047   template<class View>
00048   ExecStatus
00049   Dom<View>::post(Home home, ViewArray<View>& x) {
00050     if (x.size() == 2)
00051       return Rel::Nq<View>::post(home,x[0],x[1]);
00052     if (x.size() == 3)
00053       return TerDom<View>::post(home,x[0],x[1],x[2]);
00054     if (x.size() > 3) {
00055       // Do bounds propagation to make view-value graph smaller
00056       GECODE_ES_CHECK(prop_bnd<View>(home,x));
00057       (void) new (home) Dom<View>(home,x);
00058     }
00059     return ES_OK;
00060   }
00061 
00062   template<class View>
00063   forceinline
00064   Dom<View>::Dom(Space& home, bool share, Dom<View>& p)
00065     : NaryPropagator<View,PC_INT_DOM>(home,share,p) {}
00066 
00067   template<class View>
00068   PropCost
00069   Dom<View>::cost(const Space&, const ModEventDelta& med) const {
00070     if (View::me(med) == ME_INT_VAL)
00071       return PropCost::linear(PropCost::LO, x.size());
00072     else
00073       return PropCost::quadratic(PropCost::HI, x.size());
00074   }
00075 
00076   template<class View>
00077   Actor*
00078   Dom<View>::copy(Space& home, bool share) {
00079     return new (home) Dom<View>(home,share,*this);
00080   }
00081 
00082   template<class View>
00083   ExecStatus
00084   Dom<View>::propagate(Space& home, const ModEventDelta& med) {
00085     if (View::me(med) == ME_INT_VAL) {
00086       ExecStatus es = prop_val<View,false>(home,x);
00087       GECODE_ES_CHECK(es);
00088       if (x.size() < 2)
00089         return home.ES_SUBSUMED(*this);
00090       if (es == ES_FIX)
00091         return home.ES_FIX_PARTIAL(*this,View::med(ME_INT_DOM));
00092       es = prop_bnd<View>(home,x);
00093       GECODE_ES_CHECK(es);
00094       if (x.size() < 2)
00095         return home.ES_SUBSUMED(*this);
00096       es = prop_val<View,true>(home,x);
00097       GECODE_ES_CHECK(es);
00098       if (x.size() < 2)
00099         return home.ES_SUBSUMED(*this);
00100       return home.ES_FIX_PARTIAL(*this,View::med(ME_INT_DOM));
00101     }
00102 
00103     if (x.size() == 2)
00104       GECODE_REWRITE(*this,Rel::Nq<View>::post(home(*this),x[0],x[1]));
00105     if (x.size() == 3)
00106       GECODE_REWRITE(*this,TerDom<View>::post(home(*this),x[0],x[1],x[2]));
00107 
00108     if (dc.available()) {
00109       GECODE_ES_CHECK(dc.sync(home));
00110     } else {
00111       GECODE_ES_CHECK(dc.init(home,x));
00112     }
00113 
00114     bool assigned;
00115     GECODE_ES_CHECK(dc.propagate(home,assigned));
00116 
00117     return ES_FIX;
00118   }
00119 
00120 }}}
00121 
00122 // STATISTICS: int-prop
00123