Originally posted by: SystemAdmin
[dgravot@noos.fr said:]
The "all" keyword allows you to collect the relevant pairs i,j
In the following sample, I also use the keyword "append" to append two collections (actually two singleton)
/*********************************************
* OPL 6.1.1 Model
* Author: dgravot
* Creation Date: 19 Mar 2009 at 17:51:53
http://forums.ilog.com/optimization/index.php?action=post;topic=1014.0 *********************************************/
using CP;
int nbtasks = 5;
range rtasks = 1..nbtasks;
int noSimultaneously[i in rtasks][j in rtasks] = ((i+j) % 3==0) ? 1 : 0;
tuple Clique
{
{int} nodes;
}
{Clique} cliques;
execute FIND_CLIQUES
{
//TODO !!
}
dvar interval task[r in rtasks] size r;
constraints
{
//1. post one constraint for each "no-simultaneous" pair
forall(i in rtasks,j in i+1..nbtasks : noSimultaneously[i][j]==1)//j>i avoids posting twice the constraint
noOverlap( append( all(k in i..i) task[k] , all(q in j..j) task[q]) );
//2. less and more efficient constraints using cliques
forall(c in cliques)
noOverlap( all(i in c.nodes) task[i] );
}
Instead of posting only pairwise constraints, it is more efficient to collect the maximum cliques , that is if 1 and 2 are incompatible, 2 and 3 are incompatible, and 1 and 3 are also incompatible, we have a no-overlap of intervals 1,2,3 together.
#DecisionOptimization#OPLusingCPOptimizer