[gecode-users] Implementing scene allocation symmetry break in gecode-python

Michael Rand begbie00 at gmail.com
Sat Jun 29 14:05:38 CEST 2013


Hi,

Here's some c++ code implementing the symmetry break in the scene allocation 
problem:

//Symmetry breaking
    //Assign shot day for scene imposing an order
    post(*this, shoot[0] == 1);
    for(sceneCount=1; sceneCount<numScenes; sceneCount++){
      IntVar currentMax(*this,1,maxDays);      
      IntVarArray shot_slice(*this,sceneCount,1,maxDays);
      //Get Shot days from 0 to sceneCount
      int parcialShoot;
      for(parcialShoot=0; parcialShoot< sceneCount; parcialShoot++){
	shot_slice[parcialShoot] = shoot[parcialShoot];
      }
      //Each scene must be assigned to an already assigned scene day
      //or to the successor of the max assigned day
      max(*this,shot_slice, currentMax);
      post(*this, shoot[sceneCount] <= 1+currentMax);
    }

I would think the same constraint would be constructed in gecode-python as 
follows (with s = the space object):

    s.rel(shoot[0],cp.IRT_EQ,1)
    for scene_count in xrange(1,num_scenes):
        current_max = s.intvar(1, max_days)
        shot_slice = s.intvars(scene_count, 1, max_days)
        for partial_shoot in xrange(0, scene_count):
            shot_slice[partial_shoot] = shoot[partial_shoot]
        s.max(shot_slice, current_max)
        s.rel(shoot[scene_count], cp.IRT_LQ, current_max + 1)

But this raises the following exception:

Traceback (most recent call last):
  ...
  File "solver.py", line 61, in solveIt
    s.rel(shoot[scene_count], cp.IRT_LQ, current_max + 1)
TypeError: unsupported operand type(s) for +: '_gecode.IntVar' and 'int'


How do I implement the "+1" portion of the constraint if I can't add an int 
and an IntVar? Do I need to use some kind of linear equation constraint with 
a "plus_one" intvar?




More information about the users mailing list