No, you can't delete. The idea is: the i-th view (that is, x[i]) is assigned the last view in the array (x[n-1]) and the size of the array is shrunk by one (--n). Unfortunately, the propagator Tias sent is non-sensical in that it does not implement a constraint: its semantics is random!
The reason why you can't delete it here is that it is also used for detecting subsumption: any propagator must at very latest report subsumption if it is not failed and all of its views are assigned! Christian -- Christian Schulte, www.ict.kth.se/~cschulte/ From: users-boun...@gecode.org [mailto:users-boun...@gecode.org] On Behalf Of amina kemmar Sent: Sunday, September 06, 2009 2:14 PM To: us...@gecode.org Subject: [gecode-users] A simple propagator Hi everyone, thank you Tias for the propagator's example that you make available in the mailing list, it is very interesting, but i don't understand why you add the following statement, in the propagate method : x[i]=x[--n]; can we delete it? if anyone have an idea could he give me an answer, thank you. greetings, Amina. //////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// //////// #include <gecode/kernel.hh> #include <gecode/int.hh> namespace myprop { using namespace ::Gecode; using namespace ::Gecode::Int; /** * \brief Base-class for simple cleaner */ template <class V> class CleanerBool : public Propagator { protected: /// Boolean views ViewArray<V> x; /// Constructor for creation CleanerBool(Space& home, ViewArray<V>& x); /// Constructor for cloning \a p CleanerBool(Space& home, bool share, CleanerBool& p); public: /// Cost function (defined as low linear) virtual PropCost cost(const Space& home, const ModEventDelta& med) const; /// Delete propagator and return its size // virtual size_t dispose(Space& home); /// Create copy during cloning virtual Actor* copy(Space& home, bool share); /// Perform propagation virtual ExecStatus propagate(Space& home, const ModEventDelta& med); /// Post propagator static ExecStatus post(Space& home, ViewArray<V>& x); }; /* * propagator implementation */ template <class V> CleanerBool<V>::CleanerBool(Space& home, ViewArray<V>& x0) : Propagator(home), x(x0) { x.subscribe(home,*this,PC_INT_VAL); } template <class V> forceinline size_t CleanerBool<V>::dispose(Space& home) { assert(!home->failed()); x.cancel(home,*this,PC_INT_VAL); (void) Propagator::dispose(home); return sizeof(*this); } template <class V> forceinline CleanerBool<V>::CleanerBool(Space& home, bool share, CleanerBool& p) : Propagator(home,share,p) { x.update(home,share,p.x); } template <class V> PropCost CleanerBool<V>::cost(const Space&, const ModEventDelta&) const { // make sure this propagator is run as last before the fixpoint return PropCost::crazy(PropCost::HI, 100000); // in a real propagator, this would be something more sensible, // for example: PropCost::linear(PropCost::LO, x.size()); } template <class V> ExecStatus CleanerBool<V>::post(Space& home, ViewArray<V>& x) { (void) new (home) CleanerBool<V>(home,x); return ES_OK; } template <class V> Actor* CleanerBool<V>::copy(Space& home, bool share) { return new (home) CleanerBool<V>(home,share,*this); } template <class V> ExecStatus CleanerBool<V>::propagate(Space& home, const ModEventDelta&) { int n = x.size(); for (int i = n; i--; ) { if (x[i].zero()) { x[i]=x[--n]; } else if (x[i].one()) { x[i]=x[--n]; } else { GECODE_ME_CHECK( x[i].one(home) ); x[i]=x[--n]; } // all cases covered, so every var assigned and removed } x.size(n); if (n == 0) { return ES_SUBSUMED(*this,home); } return ES_FIX; } /** \brief Post propagator for cleanup of unassigned variables * Is run as last propagator (crazy_hi), sets unassigned variables to 1 */ void cleaner(Space& home, const BoolVarArgs& x) { if (home.failed()) return; ViewArray<BoolView> Vx(home, x); GECODE_ES_FAIL(home,(CleanerBool<BoolView>::post(home, Vx))); } } //////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////// _____ Achetez un nouveau PC et bénéficiez de Windows 7 dès sa sortie ! En savoir plus <http://www.portable-windows.com/>
_______________________________________________ Gecode users mailing list us...@gecode.org https://www.gecode.org/mailman/listinfo/gecode-users