[gecode-users] Position of IntVar in IntVarArray within a propagate function

Mikael Zayenz Lagerkvist zayenz at gmail.com
Tue Apr 13 18:50:01 CEST 2010


When you define your propagator, just add two int-fields pos0 and pos1  
and instantiate the propagators with the appropriate info. Remember to  
update the fields when the propagator is copied.

/Mikael

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

On 13 apr 2010, at 18.03, Peter Vanhee <peter.vanhee at gmail.com> wrote:

> Hey all,
>
> I am working on a binary propagator which needs to know the position  
> of the two variables
> it receives within the domain of the problem (coded with an  
> IntVarArray).
>
> I am not sure whether this is possible (and if it should be  
> possible!) to access this information, as I believe
> a binary propagator should be able to propagate without knowing the  
> context.
>
> Still, in my particular problem I don't see any other solution.
>
> Here a code snippet:
>
>        // in the model
>        IntVarArray        domains;
>
>        // in the propagator
>        ExecStatus
>        BinaryPropagator::propagate(Space& home, const ModEventDelta&  
> med) {
>
>            if (x0.assigned()) {
>                int val = x0.val();
>
>                // need to know index of x0 within "domains" to  
> access info that depends on position in domain + value on that  
> position
>                // does x0 has some reference to this? or home?
>                int idx = ?
>            }
>            else {
>                // same here but with x1
>            }
>        }
>
> A simple but rather dumb solution would be to encode the position  
> within the values using
> some mathematical trick, but this will create unnecessary holes  
> within the domain.
>
> Thanks for any help on this!
>
> Peter
>
>
> _______________________________________________
> Gecode users mailing list
> users at gecode.org
> https://www.gecode.org/mailman/listinfo/gecode-users



More information about the users mailing list