Generated on Tue May 22 09:39:55 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   template<class View>
00079   ExecStatus
00080   Dom<View>::propagate(Space& home, const ModEventDelta& med) {
00081     if (View::me(med) == ME_INT_VAL) {
00082       ExecStatus es = prop_val<View,false>(home,x);
00083       GECODE_ES_CHECK(es);
00084       if (x.size() < 2)
00085         return home.ES_SUBSUMED(*this);
00086       if (es == ES_FIX)
00087         return home.ES_FIX_PARTIAL(*this,View::med(ME_INT_DOM));
00088       es = prop_bnd<View>(home,x);
00089       GECODE_ES_CHECK(es);
00090       if (x.size() < 2)
00091         return home.ES_SUBSUMED(*this);
00092       es = prop_val<View,true>(home,x);
00093       GECODE_ES_CHECK(es);
00094       if (x.size() < 2)
00095         return home.ES_SUBSUMED(*this);
00096       return home.ES_FIX_PARTIAL(*this,View::med(ME_INT_DOM));
00097     }
00098 
00099     if (x.size() == 2)
00100       GECODE_REWRITE(*this,(Rel::Nq<View,View>::post(home(*this),x[0],x[1])));
00101     if (x.size() == 3)
00102       GECODE_REWRITE(*this,TerDom<View>::post(home(*this),x[0],x[1],x[2]));
00103 
00104     if (dc.available()) {
00105       GECODE_ES_CHECK(dc.sync());
00106     } else {
00107       GECODE_ES_CHECK(dc.init(home,x));
00108     }
00109 
00110     bool assigned;
00111     GECODE_ES_CHECK(dc.propagate(home,assigned));
00112 
00113     return ES_FIX;
00114   }
00115 
00116 }}}
00117 
00118 // STATISTICS: int-prop
00119