[gecode-users] questions in integer n-ary linear with advisor

Mikael Zayenz Lagerkvist zayenz at gmail.com
Mon Nov 26 09:31:37 CET 2007


On Nov 26, 2007 1:07 AM, Pengyu Zhao <zpengyu at gmail.com> wrote:
> I have a question about "advisor".
>
> I am writing an advisor for n-ary linear equation.
>
> In n-ary Eq(trunk/gecode/int/linear.hh), the template class definition
> is:
>        template<class Val, class P, class N>
>        class Eq : public Lin<Val,P,N,PC_INT_BND> {......}
> "P" represented for position view array.
> "N" represented for negative view array or NoView.
> Then, I added a council to this propagator, like,
>        Council<LinearAdvisor<V>> council;
> I added a "LinearAdvisor" class which derived from "ViewAdvisor<V>",like
>        template<class V>
>        class LinearAdvisor : public ViewAdvisor<V> {......}
> when constructing, the council and Advisors of variables only accept ONE
> template parameter like P or N. But, the type of views in a propagator
> may different, is there another way to set an advisor to a view
> dynamically? How can I make a council accept different kinds of
> advisors?
> I have tried to set V to DoubleView, it's ok but coefficient can only
> accept 1 or -1.
> Also, the propagator only accept one Council.

Since most propagators only need one type of advisor, we simplified
the system by only allowing a single type of advisor for a propagator.
When more than one type is needed, one has to program this explicitly.
Essentially, you need to distinguish the type of the advisor in the
advise-function. This can be done with either sub-types or tagging.

For sub-typing, you would have a class hierarchy something like:
    class PorNAdvisor : public Advisor { ... }
    class PAdvisor : public PorNAdvisor { ... }
    class NAdvisor : public PorNAdvisor { ... }
In the advise-function you could then use RTTI or polymorphism to find
the right function.

For tagging, you can just add a field in your advisor as follows
    class PorNAdvisor : public Advisor {
        ...
        bool isP; ///< Advisor for positive views
        ....
    }
In the advise-function you can then check this field to determine what
needs to be done.


Cheers,
Mikael

-- 
Mikael Zayenz Lagerkvist, http://www.ict.kth.se/~zayenz/




More information about the gecode-users mailing list