Originally posted by: SystemAdmin
Hello,
You can use the first/next functions on the sequence as follows.
using CP;
int n=10; dvar interval x[i in 1..n] size i; dvar sequence s in x; constraints
{ noOverlap(s);
} execute
{
for (var a = s.first(); a !=
null; a = s.next(a)) writeln(a);
}
Using this type of iteration, you can access the interval variables themselves.
But if you need to access some data associated with the interval variables, you may have to sort the sequence yourself. In the piece of code below, I assume you want to get an information info[i] associated with interval x[i] in chronological order:
using CP;
int n=10; dvar interval x [i in 1..n] size i;
int info [i in 1..n] = (i % 5); dvar sequence s in x; constraints
{ noOverlap(s);
}
// Sorted interval start times tuple Start
{
int s;
int i;
} sorted
{Start
} sol =
{ <startOf(x[i]),i> | i in 1..n
}; execute
{
for (var pos = 0; pos <n; pos++)
{ var i = Opl.item(sol,pos).i; writeln(
"At position ", pos,
" info=", info[i]);
}
}
Philippe
#DecisionOptimization#OPLusingCPOptimizer