Please read the examples in MPG again. It is not the old domain. It is the delta (as the name suggests).
Christian -- Christian Schulte, KTH, web.it.kth.se/~cschulte/ From: [email protected] [mailto:[email protected]] On Behalf Of Max Ostrowski Sent: Tuesday, August 21, 2012 10:12 AM To: [email protected] Subject: [gecode-users] Writing Advisors Hi, i want to write an advisor for my propagator that gets notified when the watched variable changes it bounds. In the attached code, the advise method now prints the view min and max. According to the Gecode Documentation min(d)/max(d) return the old value of the variable, while min()/max() return the new value, is this correct? In my current test setting, i have only one variable "a=[0..10]" Then i add the constraint a>5. The advisor is called properly. The first line prints: 0 5 6 10 This would mean that the domain of "a" before the progagation was [0..5] and now is [6..10]. This of course can't be true (as they do not overlap). So how do I use the Delta Information correctly. I found no example actually using this information. 2nd Question: With my two if statements in the advisor method, will i catch all changes of the bounds? Or is it possible to catch more. Best, Max PS: Thanks for the possibility to remove all propagators. class Waiter : public Propagator { ... class Watcher : public Advisor { public: Int::IntView b_; unsigned int lowerVar_; Watcher(Space& home, Propagator& p, Council<Watcher>& c, Int::IntView b, Clasp::Var lower) : Advisor(home,p,c), b_(b), lowerVar_(lower) { b_.subscribe(home,*this); } Watcher(Space& home, bool share, Watcher& w) : Advisor(home,share,w), lowerVar_(w.lowerVar_) { b_.update(home,share,w.b_); } void dispose(Space& home, Council<Watcher>& c) { b_.cancel(home,*this); Advisor::dispose(home,c); } }; Council<Watcher> c_; public: Waiter(Space& home) : Propagator(home), c_(home) { home.notice(*this,AP_DISPOSE); } Waiter(Space& home, bool shared, Waiter& p) : Propagator(home,shared,p) { c_.update(home,shared,p.c_); } void init(Space& home, GecodeSolver* csps, Int::IntView b, unsigned int varNumber) { solver = csps; ... (void) new (home) Watcher(home,*this,c_,b,varNumber); } /// Perform copying during cloning virtual Actor* copy(Space& home, bool share) { return new (home) Waiter(home,share,*this); } /// Const function (defined as low unary) PropCost cost(const Space&, const ModEventDelta&) const { return PropCost::unary(PropCost::LO); } virtual size_t dispose(Space &home) { home.ignore(*this,AP_DISPOSE); c_.dispose(home); (void) Propagator::dispose(home); return sizeof(*this); } virtual ExecStatus advise(Space &home, Advisor &a, const Delta &d) { std::cout << static_cast<Watcher&>(a).b_.min(d) << " " << static_cast<Watcher&>(a).b_.max(d) << "\t" << static_cast<Watcher&>(a).b_.min() << " " << static_cast<Watcher&>(a).b_.max() << std::endl; Gecode::ModEvent e = static_cast<Watcher&>(a).b_.modevent(d); //use this modevent if (e == Gecode::Int::ME_INT_BND) { if (!static_cast<Watcher&>(a).b_.any(d)) { if (static_cast<Watcher&>(a).b_.min(d) != static_cast<Watcher&>(a).b_.min()) // minimum has changed { ... } if (static_cast<Watcher&>(a).b_.max(d) != static_cast<Watcher&>(a).b_.max()) // maximum has changed { ... } } } if (static_cast<Watcher&>(a).b_.assigned()) return home.ES_FIX_DISPOSE(c_,static_cast<Watcher&>(a)); else return ES_FIX; } virtual ExecStatus propagate(Space &home, const ModEventDelta &med) { return ES_FIX; } };
_______________________________________________ Gecode users mailing list [email protected] https://www.gecode.org/mailman/listinfo/gecode-users
