0

Is there a workaround in order to express this model correctly:

using CP;

int fooSize[0..3]=[2,2,3,2];
dvar interval foo[t in 0..3] size fooSize[t];
dvar int bar[0..3] in 0..1;

dexpr int stop = max(t in 0..3) endOf(foo[t]);

minimize stop;
subject to{
    all(ordered u,v in 0..3: bar[u]==bar[v])
        startOf(foo[u])>=endOf(foo[v]) || startOf(foo[v])>=endOf(foo[u]);
}

OPLIDE tells me that the decision variable bar is not authorized. I also tried:

forall(ordered u,v in 0..3)
    (bar[u]==bar[v]) => (startOf(foo[u])>=endOf(foo[v]) || startOf(foo[v])>=endOf(foo[u]));

But it does not seem to work, the solver just hangs for hours. By the way how am I supposed to debug an OPL model? Please tell me if you need specific information.

Generally speaking, is there a way to condition a constraint based on the value of a decision variable?

Emilien
  • 2,385
  • 16
  • 24

1 Answers1

1

You cannot slice with a decision variable.

You could write:

    using CP;

int fooSize[0..3]=[2,2,3,2];
dvar interval foo[t in 0..3] in 0..10000 size fooSize[t];
dvar int bar[0..3] in 0..1;

dexpr int stop = max(t in 0..3) endOf(foo[t]);

minimize stop;
subject to{
    forall(ordered u,v in 0..3)
        (bar[u]==bar[v]) =>  (startOf(foo[u])>=endOf(foo[v]) || startOf(foo[v])>=endOf(foo[u]));
}

Inside the CPLEX OPL IDE you have a debugger. This is described in documentation IDE and OPL > Starting Kit > From Operations Research to CPLEX Studio and ODM Enterprise

regards

Alex Fleischer
  • 9,276
  • 2
  • 12
  • 15