Originally posted by: davidoff
In the following sample, I have three activities in a non-overlapping sequence.
These 3 activities are optional but I would like to enforce the total ordering
Unfortunately, I'm afraid this can't be done using only prev , as shown in the following sample
using CP; dvar interval A[i in 1..3] optional size 1; dvar sequence s in A; constraints
{ noOverlap(s); prev(s,A[1],A[2]); prev(s,A[2],A[3]);
//before(s, A[1],A[3]);//mandatory otherwise the next constraint is valid ! prev(s,A[3],A[1]);
//valid !
//endBeforeStart(A[1],A[2]);
//endBeforeStart(A[2],A[3]);
}
}
Generally speaking, it seems that if I want to order totally n optional intervals A1,...,An in a non overlapping sequence, I must add a quadratic number of constraints
forall(i in 1..3, j in 1..3 : i<j) before(s,A[i],A[j]);
Is there a better way to enforce a total ordering ? I think using artificial transition times is a good workaround :
using CP; tuple Transition
{
int i1;
int i2;
int d;
}
int M = 100;
//
{Transition
} Dist =
{ <1,1,0> , <1,2,0>,<1,3,0>,<2,1,M>,<2,2,0>,<2,3,0>,<3,1,M>,<3,2,M>,<3,3,0>
}; dvar interval A[i in 1..3] optional(i ==2) in 0..10 size 1 ; dvar sequence s in A types all(i in 1..3) i; constraints
{ noOverlap(s , Dist, 1); prev(s,A[1],A[2]); prev(s,A[2],A[3]);
//before(s, A[1],A[3]); prev(s,A[3],A[1]);
//endBeforeStart(A[1],A[2]);
//endBeforeStart(A[2],A[3]);
//forall(i in 1..3, j in 1..3 : i<j)
//before(s,A[i],A[j]);
}
Is there any other (better) way ?
Thanks
David
#DecisionOptimization#OPLusingCPOptimizer