Hi Louis,
The diffn column constraints can be implemented in CP Optimizer by combining resource constraints and state functions.
Assume you have n task modelled by n interval variables. The resource constraint is expressed with a cumul expression (sum of pulse expressions over the interval variables) that must be less or equal to the capacity of the resource. To ensure that interval variables that overlaps have the same start and end, one use a single state function (see here) and an "AlwaysEqual" constraint (see here) for each interval variable.
Here is an example in C++ to see the details. Note the 2 IloTrue arguments passed to the IloAlwaysEqual(env, f, iv[i], 0, IloTrue, IloTrue) function to ensure that start and end must be equal. The state function is arbitrarily set to 0. You can have different values if need to specify that some types of interval variables cannot overlap other types of interval variable. This is quite powerful.
Regards,
Philippe
#include <ilcp/cp.h>
ILOSTLBEGIN
int main() {
IloEnv env;
IloModel model(env);
IloIntervalVarArray iv(env);
IloIntArray cons(env);
iv.add(IloIntervalVar(env, 5, "x")); cons.add(2);
iv.add(IloIntervalVar(env, 5, "y")); cons.add(2);
iv.add(IloIntervalVar(env, 3, "z")); cons.add(1);
iv.add(IloIntervalVar(env, 1, "u")); cons.add(1);
IloStateFunction f(env);
// Resource constraint
IloCumulFunctionExpr r(env);
for (IlcInt i = 0; i < iv.getSize(); i++) {
r += IloPulse(iv[i], cons[i]);
}
model.add(r <= 4);
IloIntExprArray ends(env);
for (IloInt i = 0; i < iv.getSize(); i++) {
ends.add(IloEndOf(iv[i]));
model.add(IloAlwaysEqual(env, f, iv[i], 0, IloTrue, IloTrue));
}
// Minimize makespan
model.add(IloMinimize(env, IloMax(ends)));
IloCP cp(model);
cp.solve();
for (IloInt i = 0; i < iv.getSize(); i++) {
cout << cp.domain(iv[i]) << endl;
}
return 0;
}
------------------------------
Philippe Refalo
IBM ILOG CP Optimizer
------------------------------