Apologies. It seems there was a misunderstanding. In the CP Optimizer, there is no direct `noOverlap` constraint that takes two interval variables as input. Instead, you should use the state function approach as I previously described. Here's a modified version of the model that avoids overlaps between tasks with specific IDs:
using CP;
int NbTasks = ...;
int NbRsrcs = ...;
range RsrcIds = 0..NbRsrcs-1;
int Capacity[r in RsrcIds] = ...;
tuple Task {
key int id;
int pt;
int dmds[RsrcIds];
{int} succs;
}
{Task} Tasks = ...;
dvar interval itvs[t in Tasks] size t.pt;
cumulFunction rsrcUsage[r in RsrcIds] =
sum (t in Tasks: t.dmds[r]>0) pulse(itvs[t], t.dmds[r]);
minimize max(t in Tasks) endOf(itvs[t]);
// Add a state function
stateFunction typeExclusionFn;
// Define tags for tasks you want to avoid overlapping
int Tag1 = 1;
int Tag2 = 2;
subject to {
forall (r in RsrcIds)
rsrcUsage[r] <= Capacity[r];
forall (t1 in Tasks, t2id in t1.succs)
endBeforeStart(itvs[t1], itvs[<t2id>]);
// Add alwaysEqual constraints to prevent overlaps between tasks with specific IDs
forall (t in Tasks)
if (t.id == 1)
alwaysEqual(typeExclusionFn, itvs[t], Tag1);
else if (t.id == 2)
alwaysEqual(typeExclusionFn, itvs[t], Tag2);
}
By using the state function `typeExclusionFn` and the `alwaysEqual` constraints, this model will ensure that tasks with ID 1 and tasks with ID 2 do not overlap.
------------------------------
Scott Dunn
------------------------------
Original Message:
Sent: Fri April 28, 2023 09:55 AM
From: Francisco Yuraszeck
Subject: noOverlap constraint for Tuple key int id
Thank you Scott for taking the time to answer my question.
I followed your advice but now I have a warning at the noOverlap constraint.
The warning (translated from Spanish to English) says: "The function noOverlap(dvar interval, dvar interval) does not exist"
------------------------------
Francisco Yuraszeck
Yuraszeck
Original Message:
Sent: Thu April 27, 2023 09:11 PM
From: Scott Dunn
Subject: noOverlap constraint for Tuple key int id
Yes, you can impose a noOverlap constraint between specific tasks in the CP Optimizer. You can add an additional constraint to your existing model, which ensures that certain pairs of tasks do not overlap. In your example, you want to avoid an overlap between tasks with id 1 and tasks with id 2.
You can achieve this by adding the following constraint to the `subject to` block in your model:
```cplex
forall (t1 in Tasks, t2 in Tasks: t1.id == 1 && t2.id == 2)
noOverlap(itvs[t1], itvs[t2]);
```
This constraint iterates through all the tasks and ensures that if a task has an id of 1, it will not overlap with any tasks having an id of 2.
Here's the updated model with the added constraint:
```cplex
using CP;
int NbTasks = ...;
int NbRsrcs = ...;
range RsrcIds = 0..NbRsrcs-1;
int Capacity[r in RsrcIds] = ...;
tuple Task {
key int id;
int pt;
int dmds[RsrcIds];
{int} succs;
}
{Task} Tasks = ...;
dvar interval itvs[t in Tasks] size t.pt;
cumulFunction rsrcUsage[r in RsrcIds] =
sum (t in Tasks: t.dmds[r]>0) pulse(itvs[t], t.dmds[r]);
minimize max(t in Tasks) endOf(itvs[t]);
subject to {
forall (r in RsrcIds)
rsrcUsage[r] <= Capacity[r];
forall (t1 in Tasks, t2id in t1.succs)
endBeforeStart(itvs[t1], itvs[<t2id>]);
// Add noOverlap constraint for specific task ids
forall (t1 in Tasks, t2 in Tasks: t1.id == 1 && t2.id == 2)
noOverlap(itvs[t1], itvs[t2]);
}
```
Now, the model will ensure that tasks with id 1 do not overlap with tasks with id 2. You can extend this constraint to include other task pairs as needed.
------------------------------
Scott Dunn
Original Message:
Sent: Wed April 26, 2023 11:39 PM
From: Francisco Yuraszeck
Subject: noOverlap constraint for Tuple key int id
I'm using CP Optimizer for an RCPSP. I was wondering if there exists a simple way to impose a noOverlap constraint for determined tuples id. For example, avoid an overlap between Tasks with id 1 and Tasks with id 2. Is that possible?
using CP;int NbTasks = ...;int NbRsrcs = ...;range RsrcIds = 0..NbRsrcs-1; int Capacity[r in RsrcIds] = ...;tuple Task { key int id; int pt; int dmds[RsrcIds]; {int} succs; }{Task} Tasks = ...;dvar interval itvs[t in Tasks] size t.pt;cumulFunction rsrcUsage[r in RsrcIds] = sum (t in Tasks: t.dmds[r]>0) pulse(itvs[t], t.dmds[r]);minimize max(t in Tasks) endOf(itvs[t]);subject to { forall (r in RsrcIds) rsrcUsage[r] <= Capacity[r]; forall (t1 in Tasks, t2id in t1.succs) endBeforeStart(itvs[t1], itvs[<t2id>]); }
------------------------------
Francisco Yuraszeck
Yuraszeck
------------------------------