[gecode-users] Writing Advisors

Christian Schulte cschulte at kth.se
Tue Aug 21 11:10:45 CEST 2012


Oh damn, I have to fix the doc. It is really the delta: what has been
removed. So in your example, 0..5 has been removed, that is what the delta
tells you.

 

Christian

 

--

Christian Schulte, KTH, web.it.kth.se/~cschulte/

 

From: Max Ostrowski [mailto:ostrowsk at cs.uni-potsdam.de] 
Sent: Tuesday, August 21, 2012 11:05 AM
To: cschulte at kth.se
Cc: users at gecode.org
Subject: Re: [gecode-users] Writing Advisors

 

I'm very sorry that I misinterpreted the manual.
But on page 288 you state
"Only if x.any(d) is false, x.min(d) returns the previously (that is, the
value before the domain modification) smallest value of x and x.max(d)
returns the previously largest value of x."
Isn't this the bounds of the old domain?


Unfortunately in the only example of the advise() function that uses the
Delta in the MPG (page 287) you use 
Int::BoolView::zero(d)
to determine that the variable has been assigned to zero.

Could you just state me what the min(d)==0 and max(d)==5 means when the
domain is restricted from [0..10] to [6..10].

Thanks again for your patience.
Max


On 08/21/2012 10:27 AM, Christian Schulte wrote: 

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: users-bounces at gecode.org [mailto:users-bounces at gecode.org] On Behalf
Of Max Ostrowski
Sent: Tuesday, August 21, 2012 10:12 AM
To: users at gecode.org
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;
        }

    }; 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.gecode.org/pipermail/users/attachments/20120821/33e7e94e/attachment-0001.html>


More information about the users mailing list