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

Peter Vanhee peter.vanhee at gmail.com
Tue Apr 13 18:03:37 CEST 2010


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




More information about the users mailing list