Originally posted by: GGR
Hi
Basically the piece of model I gave is standard for Integer Programming (whatever you use a MIP or CP techniques to solve it). If you need to limit yourself to a <<linear>> number of constraints (because N to big): I am not sure you can do better.
Anyway one could add a cubic redundant term in the model:
forall(i in 1..N, j in 1..N, k in 1 ..N: i < j && i < k && k < j) (isIn[i]*isIn[j] == 1) <= (isIn[k] == 1);
Actually, CPO allows to declare a model using temporal (scheduling) concepts that will do the job. That is, use the analogy between the line of integer and a temporal axis, and the continuity of Non Zero values with an interval variable.
int N = ...;
int ub = ... dvar
int line[1..N] in 0..ub; dvar interval isIn[p in 1..N] optional in p..p+1 size 1; dvar interval beforeNonZero in 1..N+1; dvar interval nonZero in 1..N+1; dvar interval afterNonZero in 1..N+1;
// the line as a cumulative function dexpr cumulFunction presence = sum (i in 1..N) pulse(isIn, 1); subject to
{
// the line shape endAtStart(beforeNonZero, nonZero); endAtStart(nonZero, afterNonZero); alwaysIn(presence, nonZero, 1, 1); alwaysIn(presence, beforeNonZero, 0, 0); alwaysIn(presence, afterNonZero, 0, 0);
// the connection between the cumulative function and the variables forall(i in 1..N) presenceOf(isIn[i]) == (line[i] > 0); span(nonZero, isIn);
// continuity constraint
}
Anyway, the last model requires a search phase that excludes the interval variables from the search.
#DecisionOptimization#OPLusingCPOptimizer