Generated on Thu Apr 11 13:58:58 2019 for Gecode by doxygen 1.6.3

val.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   Val<View,Offset>::Val(Home home, ViewArray<View>& x, Offset& o)
00043     : Base<View,Offset>(home,x,o) {}
00044 
00045   template<class View, class Offset>
00046   forceinline
00047   Val<View,Offset>::Val(Space& home, Val<View,Offset>& p)
00048     : Base<View,Offset>(home,p) {}
00049 
00050   template<class View, class Offset>
00051   Actor*
00052   Val<View,Offset>::copy(Space& home) {
00053     return new (home) Val<View,Offset>(home,*this);
00054   }
00055 
00056   template<class View, class Offset>
00057   PropCost
00058   Val<View,Offset>::cost(const Space&, const ModEventDelta&) const {
00059     return PropCost::linear(PropCost::HI, x.size());
00060   }
00061 
00062   template<class View, class Offset>
00063   ExecStatus
00064   Val<View,Offset>::propagate(Space& home, const ModEventDelta&) {
00065     GECODE_ES_CHECK((Int::Distinct::prop_val<View,true>(home,y)));
00066     ExecStatus esc = connected(home);
00067     if (esc != ES_FIX)
00068       return esc;
00069     /*
00070      * One cannot have a single unassigned view as the views constitute
00071      * a permutation.
00072      */
00073     if (y.size() < 2)
00074       return home.ES_SUBSUMED(*this);
00075     return path(home);
00076   }
00077 
00078   template<class View, class Offset>
00079   ExecStatus
00080   Val<View,Offset>::post(Home home, ViewArray<View>& x, Offset& o) {
00081     int n = x.size();
00082     if (n == 1) {
00083       GECODE_ME_CHECK(o(x[0]).eq(home,0));
00084     } else if (n == 2) {
00085       GECODE_ME_CHECK(o(x[0]).eq(home,1));
00086       GECODE_ME_CHECK(o(x[1]).eq(home,0));
00087     } else {
00088       for (int i=0; i<n; i++) {
00089         GECODE_ME_CHECK(o(x[i]).gq(home,0));
00090         GECODE_ME_CHECK(o(x[i]).le(home,n));
00091         GECODE_ME_CHECK(o(x[i]).nq(home,i));
00092       }
00093       (void) new (home) Val<View,Offset>(home,x,o);
00094     }
00095     return ES_OK;
00096   }
00097 
00098 }}}
00099 
00100 // STATISTICS: int-prop
00101