Generated on Mon Aug 25 11:35:37 2008 for Gecode by doxygen 1.5.6

basic.icc

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Mikael Lagerkvist <lagerkvist@gecode.org>
00005  *
00006  *  Copyright:
00007  *     Mikael Lagerkvist, 2007
00008  *
00009  *  Last modified:
00010  *     $Date: 2008-01-31 18:29:16 +0100 (Thu, 31 Jan 2008) $ by $Author: tack $
00011  *     $Revision: 6017 $
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 namespace Gecode { namespace Int { namespace Extensional {
00039   /*
00040    * The propagator proper
00041    *
00042    */
00043 
00044   template <class View>
00045   forceinline
00046   Basic<View>::Basic(Space* home, ViewArray<View>& x, const TupleSet& t)
00047     : Base<View>(home,x,t) {
00048   }
00049 
00050   template <class View>
00051   ExecStatus
00052   Basic<View>::post(Space* home, ViewArray<View>& x, const TupleSet& t) {
00053     (void) new (home) Basic<View>(home,x,t);
00054     return ES_OK;
00055   }
00056 
00057   template <class View>
00058   forceinline
00059   Basic<View>::Basic(Space* home, bool share, Basic<View>& p)
00060     : Base<View>(home,share,p) {
00061   }
00062 
00063   template <class View>
00064   PropCost
00065   Basic<View>::cost(ModEventDelta med) const {
00066     return (View::me(med) == ME_INT_VAL)
00067       ? PC_QUADRATIC_HI : PC_CUBIC_HI;
00068   }
00069 
00070   template <class View>
00071   Actor*
00072   Basic<View>::copy(Space* home, bool share) {
00073     return new (home) Basic<View>(home,share,*this);
00074   }
00075 
00076   template <class View>
00077   Gecode::Support::Symbol
00078   Basic<View>::ati(void) {
00079     return Reflection::mangle<View>("Gecode::Int::Extensional::Basic");
00080   }
00081 
00082   template <class View>
00083   Reflection::ActorSpec
00084   Basic<View>::spec(const Space* home, Reflection::VarMap& m) const {
00085     Reflection::ActorSpec s(ati());
00086     return s << x.spec(home, m)
00087              << tupleSet.spec(m);
00088   }
00089 
00090   template <class View>
00091   void
00092   Basic<View>::post(Space* home, Reflection::VarMap& vars,
00093                     const Reflection::ActorSpec& spec) {
00094     spec.checkArity(2);
00095     ViewArray<View> x(home, vars, spec[0]);
00096     TupleSet tupleSet(vars, spec[1]);
00097     (void) new (home) Basic<View>(home,x,tupleSet);    
00098   }
00099 
00100 
00101   template <class View>
00102   ExecStatus
00103   Basic<View>::propagate(Space* home, ModEventDelta) {
00107     GECODE_AUTOARRAY(BitSet, dom, x.size());
00108     init_dom(home, dom);
00109 
00111     GECODE_AUTOARRAY(BitSet, has_support, x.size());
00112     for (int i = x.size(); i--; ) 
00113       has_support[i].init(home, ts()->domsize);
00114  
00115 
00117     GECODE_AUTOARRAY(int,nq, ts()->domsize*x.size());
00118     int n_nq = 0;
00119 
00120     
00121     ExecStatus es = ES_FIX;
00122 
00125     for (int var = x.size(); var--; ) {
00126       for (ViewValues<View> vv(x[var]); vv(); ++vv) {
00127         // Value offset for indexing
00128         int val = vv.val() - ts()->min;
00129         if (!has_support[var].get(val)) {
00130           // Find support for value vv.val() in variable var
00131           Tuple l = find_support(dom, var, val);
00132           if (l == NULL) {
00133             // No possible supports left
00134             nq[n_nq] = vv.val();
00135             n_nq++;
00136           } else {
00137             // Mark values as supported 
00138             // Only forward direction marking is needed since all
00139             // previous values have been checked
00140             for (int i = var; i--; ) {
00141               has_support[i].set(l[i]- ts()->min);
00142               assert(has_support[i].get(l[i]- ts()->min));
00143             }
00144           }
00145         }
00146       }
00147 
00148       // Prune values for var which do not have support anymore
00149       while (n_nq-- > 0) {
00150         ModEvent me = x[var].nq(home,nq[n_nq]);
00151         if (me_failed(me))
00152           return ES_FAILED;
00153         if (me_modified(me))
00154           es = ES_NOFIX;
00155       }
00156       n_nq = 0;
00157     }
00158 
00159     for (int i = x.size(); i--; )
00160       if (!x[i].assigned())
00161         return es;
00162     return ES_SUBSUMED(this, home);
00163   }
00164 }}}
00165 // STATISTICS: int-prop
00166