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, 2007
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 namespace Gecode { namespace Int { namespace Circuit {
00035 
00036   /*
00037    * The actual propagator
00038    *
00039    */
00040   template<class View, class Offset>
00041   forceinline
00042   Dom<View,Offset>::Dom(Home home, ViewArray<View>& x, Offset& o)
00043     : Base<View,Offset>(home,x,o) {}
00044 
00045   template<class View, class Offset>
00046   forceinline
00047   Dom<View,Offset>::Dom(Space& home, Dom<View,Offset>& p)
00048     : Base<View,Offset>(home,p) {}
00049 
00050   template<class View, class Offset>
00051   Actor*
00052   Dom<View,Offset>::copy(Space& home) {
00053     return new (home) Dom<View,Offset>(home,*this);
00054   }
00055 
00056   template<class View, class Offset>
00057   PropCost
00058   Dom<View,Offset>::cost(const Space&, const ModEventDelta& med) const {
00059     if (View::me(med) == Int::ME_INT_VAL)
00060       return PropCost::linear(PropCost::LO, x.size());
00061     else
00062       return PropCost::quadratic(PropCost::HI, x.size());
00063   }
00064 
00065   template<class View, class Offset>
00066   void
00067   Dom<View,Offset>::reschedule(Space& home) {
00068     for (int i=0; i<y.size(); i++)
00069       if (y[i].assigned()) {
00070         View::schedule(home, *this, ME_INT_VAL);
00071         return;
00072       }
00073     View::schedule(home, *this, ME_INT_DOM);
00074   }
00075 
00076   template<class View, class Offset>
00077   ExecStatus
00078   Dom<View,Offset>::propagate(Space& home, const ModEventDelta& med) {
00079     if (View::me(med) == Int::ME_INT_VAL) {
00080       GECODE_ES_CHECK((Int::Distinct::prop_val<View,true>(home,y)));
00081       ExecStatus escv = connected(home);
00082       if (escv != ES_FIX)
00083         return escv;
00084       if (y.size() < 2)
00085         return home.ES_SUBSUMED(*this);
00086       return home.ES_FIX_PARTIAL(*this,View::med(Int::ME_INT_DOM));
00087     }
00088 
00089     if (dc.available()) {
00090       GECODE_ES_CHECK(dc.sync());
00091     } else {
00092       GECODE_ES_CHECK(dc.init(home,y));
00093     }
00094     bool assigned;
00095     GECODE_ES_CHECK(dc.propagate(home,assigned));
00096 
00097     ExecStatus esc = connected(home);
00098     if (esc != ES_FIX)
00099       return esc;
00100 
00101     // Elminiate assigned views from y, as they have been assigned
00102     // and propagated by domain consistent propagation. This is required
00103     // as we need to know how many assigned views actually exist.
00104     if (assigned)
00105       for (int i=y.size(); i--; )
00106         if (y[i].assigned())
00107           y.move_lst(i);
00108 
00109     return path(home);
00110   }
00111 
00112   template<class View, class Offset>
00113   ExecStatus
00114   Dom<View,Offset>::post(Home home, ViewArray<View>& x, Offset& o) {
00115     int n = x.size();
00116     if (n == 1) {
00117       GECODE_ME_CHECK(o(x[0]).eq(home,0));
00118     } else if (n == 2) {
00119       GECODE_ME_CHECK(o(x[0]).eq(home,1));
00120       GECODE_ME_CHECK(o(x[1]).eq(home,0));
00121     } else {
00122       for (int i=0; i<n; i++) {
00123         GECODE_ME_CHECK(o(x[i]).gq(home,0));
00124         GECODE_ME_CHECK(o(x[i]).le(home,n));
00125         GECODE_ME_CHECK(o(x[i]).nq(home,i));
00126       }
00127       (void) new (home) Dom<View,Offset>(home,x,o);
00128     }
00129     return ES_OK;
00130   }
00131 
00132 }}}
00133 
00134 // STATISTICS: int-prop
00135