Generated on Fri Oct 19 11:25:02 2018 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  *  This file is part of Gecode, the generic constraint
00010  *  development environment:
00011  *     http://www.gecode.org
00012  *
00013  *  Permission is hereby granted, free of charge, to any person obtaining
00014  *  a copy of this software and associated documentation files (the
00015  *  "Software"), to deal in the Software without restriction, including
00016  *  without limitation the rights to use, copy, modify, merge, publish,
00017  *  distribute, sublicense, and/or sell copies of the Software, and to
00018  *  permit persons to whom the Software is furnished to do so, subject to
00019  *  the following conditions:
00020  *
00021  *  The above copyright notice and this permission notice shall be
00022  *  included in all copies or substantial portions of the Software.
00023  *
00024  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00025  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00026  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00027  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00028  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00029  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00030  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00031  *
00032  */
00033 
00034 #include <climits>
00035 
00036 namespace Gecode { namespace Int { namespace Distinct {
00037 
00038   template<class View>
00039   forceinline
00040   Dom<View>::Dom(Home home, ViewArray<View>& x)
00041     : NaryPropagator<View,PC_INT_DOM>(home,x) {}
00042 
00043   template<class View>
00044   ExecStatus
00045   Dom<View>::post(Home home, ViewArray<View>& x) {
00046     if (x.size() == 2)
00047       return Rel::Nq<View,View>::post(home,x[0],x[1]);
00048     if (x.size() == 3)
00049       return TerDom<View>::post(home,x[0],x[1],x[2]);
00050     if (x.size() > 3) {
00051       // Do bounds propagation to make view-value graph smaller
00052       GECODE_ES_CHECK(prop_bnd<View>(home,x));
00053       (void) new (home) Dom<View>(home,x);
00054     }
00055     return ES_OK;
00056   }
00057 
00058   template<class View>
00059   forceinline
00060   Dom<View>::Dom(Space& home, Dom<View>& p)
00061     : NaryPropagator<View,PC_INT_DOM>(home,p) {}
00062 
00063   template<class View>
00064   PropCost
00065   Dom<View>::cost(const Space&, const ModEventDelta& med) const {
00066     if (View::me(med) == ME_INT_VAL)
00067       return PropCost::linear(PropCost::LO, x.size());
00068     else
00069       return PropCost::quadratic(PropCost::HI, x.size());
00070   }
00071 
00072   template<class View>
00073   Actor*
00074   Dom<View>::copy(Space& home) {
00075     return new (home) Dom<View>(home,*this);
00076   }
00077 
00078 #ifdef GECODE_HAS_CBS
00079   template<class View>
00080   void
00081   Dom<View>::solndistrib(Space& home, Propagator::SendMarginal send) const {
00082     cbsdistinct(home,this->id(),x,send);
00083   }
00084 
00085   template<class View>
00086   void
00087   Dom<View>::domainsizesum(Propagator::InDecision in, unsigned int& size,
00088                            unsigned int& size_b) const {
00089     cbssize(x,in,size,size_b);
00090   }
00091 #endif
00092 
00093 
00094   template<class View>
00095   ExecStatus
00096   Dom<View>::propagate(Space& home, const ModEventDelta& med) {
00097     if (View::me(med) == ME_INT_VAL) {
00098       ExecStatus es = prop_val<View,false>(home,x);
00099       GECODE_ES_CHECK(es);
00100       if (x.size() < 2)
00101         return home.ES_SUBSUMED(*this);
00102       if (es == ES_FIX)
00103         return home.ES_FIX_PARTIAL(*this,View::med(ME_INT_DOM));
00104       es = prop_bnd<View>(home,x);
00105       GECODE_ES_CHECK(es);
00106       if (x.size() < 2)
00107         return home.ES_SUBSUMED(*this);
00108       es = prop_val<View,true>(home,x);
00109       GECODE_ES_CHECK(es);
00110       if (x.size() < 2)
00111         return home.ES_SUBSUMED(*this);
00112       return home.ES_FIX_PARTIAL(*this,View::med(ME_INT_DOM));
00113     }
00114 
00115     if (x.size() == 2)
00116       GECODE_REWRITE(*this,(Rel::Nq<View,View>::post(home(*this),x[0],x[1])));
00117     if (x.size() == 3)
00118       GECODE_REWRITE(*this,TerDom<View>::post(home(*this),x[0],x[1],x[2]));
00119 
00120     if (dc.available()) {
00121       GECODE_ES_CHECK(dc.sync());
00122     } else {
00123       GECODE_ES_CHECK(dc.init(home,x));
00124     }
00125 
00126     bool assigned;
00127     GECODE_ES_CHECK(dc.propagate(home,assigned));
00128 
00129     return ES_FIX;
00130   }
00131 
00132 }}}
00133 
00134 // STATISTICS: int-prop
00135