Hi,
as a workaround you can scale the matrix to get integer values for the noOverlap.
Small TSPTW examples
.mod
using CP;
int scale=100;
int n=...;
range nodes = 1..n;
//float d[0..n][1..n]=...;
float t[1..n][1..n]= ...;
int a[1..n]=...;
int b[1..n]=...;
range Cities = 1..n;
int realCity[i in 1..n+1]=(i<=n)?i:1;
// Edges -- sparse set
tuple edge {int i; int j;}
setof(edge) Edges = {<i,j> | ordered i,j in 1..n};
setof(edge) Edges2 = {<i,j> | i,j in 1..n+1}; // node n+1 is node 1
int dist[<i,j> in Edges] = ftoi(ceil(scale*t[i][j]));
int dist2[<i,j> in Edges2]=(realCity[i]==realCity[j])?0:
((realCity[i]<realCity[j])?dist[<realCity[i],realCity[j]>]:dist[<realCity[j],realCity[i]>]);
dvar interval itvs[1..n+1] size 1;
dvar sequence seq in all(i in 1..n+1) itvs[i];
execute
{
cp.param.TimeLimit=60;
var f = cp.factory;
cp.setSearchPhases(f.searchPhase(seq));
}
tuple triplet { int c1; int c2; int d; };
{triplet} Dist = {
<i-1,j-1,dist2[<i ,j >]>
| i,j in 1..n+1};
minimize 1/scale*(endOf(itvs[n+1]) - (n+1));
subject to
{
startOf(itvs[1])==0; // break sym
noOverlap(seq,Dist,true); // nooverlap with a distance matrix
last(seq, itvs[n+1]); // last node
// Visits
forall(i in Cities) ctVisits:startOf(itvs[i]) in scale*a[i]..scale*b[i];
}
int x[<i,j> in Edges]=prev(seq,itvs[i],itvs[j])+prev(seq,itvs[j],itvs[i]);
int isPrevFromNPlus1[i in 1..n]=prev(seq,itvs[i],itvs[n+1]);
int l=first({i | i in 1..n : isPrevFromNPlus1[i]==1});
edge el=<1,l>;
execute
{
isPrevFromNPlus1;
x;
x[el]=1;
}
// Let us check here that the constraints of the IP model are ok
assert forall (j in Cities)
as:sum (<i,j> in Edges) x[<i,j>] + sum (<j,k> in Edges) x[<j,k>] == 2;
// Let us compute here the objective the IP way
int cost=sum (<i,j> in Edges) dist[<i,j>]*x[<i,j>];
execute
{
writeln(cost);
}
.dat
n=20;
t=[
[1000000.0 79.4 78.6 70.0 48.4 77.5 102.4 43.5 71.2 7.3 69.3 80.1 55.5 56.2 82.0 10.0 80.8 54.8 44.1 78.1],
[79.4 1000000.0 65.2 51.4 60.3 66.6 44.0 39.0 8.2 86.6 71.3 14.1 99.4 32.1 37.7 79.1 57.7 28.6 81.1 102.4],
[78.6 65.2 1000000.0 14.6 30.1 2.2 45.2 48.9 62.7 82.8 13.9 52.5 55.0 40.6 30.5 70.7 9.3 47.0 44.3 43.5],
[70.0 51.4 14.6 1000000.0 23.7 15.5 39.7 35.5 48.3 75.1 20.8 39.3 58.0 26.1 20.5 63.3 11.3 32.5 43.4 53.0],
[48.4 60.3 30.1 23.7 1000000.0 29.0 62.1 27.6 54.3 52.7 22.2 52.3 39.4 28.1 41.5 40.6 33.2 32.9 21.9 44.9],
[77.5 66.6 2.2 15.5 29.0 1000000.0 47.5 49.0 63.8 81.5 11.7 54.0 52.8 41.2 32.4 69.4 11.5 47.6 42.4 41.3],
[102.4 44.0 45.2 39.7 62.1 47.5 1000000.0 59.9 47.7 108.7 58.0 31.2 97.6 46.6 20.9 97.9 36.0 49.8 83.0 88.8],
[43.5 39.0 48.9 35.5 27.6 49.0 59.9 1000000.0 31.4 50.3 47.0 36.9 63.2 13.2 40.5 41.1 46.7 11.4 44.7 72.5],
[71.2 8.2 62.7 48.3 54.3 63.8 47.7 31.4 1000000.0 78.5 67.3 16.4 93.0 26.2 37.8 71.1 56.0 21.8 74.6 97.6],
[7.3 86.6 82.8 75.1 52.7 81.5 108.7 50.3 78.5 1000000.0 72.7 87.0 54.5 62.8 88.1 12.1 85.6 61.7 45.4 78.6],
[69.3 71.3 13.9 20.8 22.2 11.7 58.0 47.0 67.3 72.7 1000000.0 60.0 41.1 42.3 40.8 60.6 22.2 48.4 31.2 32.1],
[80.1 14.1 52.5 39.3 52.3 54.0 31.2 36.9 16.4 87.0 60.0 1000000.0 91.7 26.1 23.8 78.0 44.4 25.4 74.1 91.8],
[55.5 99.4 55.0 58.0 39.4 52.8 97.6 63.2 93.0 54.5 41.1 91.7 1000000.0 67.2 78.3 45.5 62.9 71.2 18.5 26.5],
[56.2 32.1 40.6 26.1 28.1 41.2 46.6 13.2 26.2 62.8 42.3 26.1 67.2 1000000.0 27.4 52.8 36.4 6.3 49.0 71.5],
[82.0 37.7 30.5 20.5 41.5 32.4 20.9 40.5 37.8 88.1 40.8 23.8 78.3 27.4 1000000.0 77.2 21.6 31.8 62.8 72.9],
[10.0 79.1 70.7 63.3 40.6 69.4 97.9 41.1 71.1 12.1 60.6 78.0 45.5 52.8 77.2 1000000.0 73.7 52.6 34.2 68.1],
[80.8 57.7 9.3 11.3 33.2 11.5 36.0 46.7 56.0 85.6 22.2 44.4 62.9 36.4 21.6 73.7 1000000.0 42.6 50.5 52.8],
[54.8 28.6 47.0 32.5 32.9 47.6 49.8 11.4 21.8 61.7 48.4 25.4 71.2 6.3 31.8 52.6 42.6 1000000.0 52.8 77.0],
[44.1 81.1 44.3 43.4 21.9 42.4 83.0 44.7 74.6 45.4 31.2 74.1 18.5 49.0 62.8 34.2 50.5 52.8 1000000.0 34.3],
[78.1 102.4 43.5 53.0 44.9 41.3 88.8 72.5 97.6 78.6 32.1 91.8 26.5 71.5 72.9 68.1 52.8 77.0 34.3 1000000.0]
];
a=[0,222,90,64,38,337,264,207,168,422,505,132,536,368,110,0,108,187,14,579];
b=[667,261,109,113,85,354,307,234,180,459,537,173,564,384,143,22,131,214,62,588];
------------------------------
[Alex] [Fleischer]
[Data and AI Technical Sales]
[IBM]
------------------------------
Original Message:
Sent: Fri February 23, 2024 02:11 PM
From: Fam Saeed
Subject: Add float Transitiontime Matrix and use No overlap function
Hello Thierry,
Thanks for your response.
Is there any other function I can use to replace the NoOverLap, which allows me to input the transition times as a matrix with non-negative float values?
Regards,
Fam Saeed
------------------------------
Fam Saeed
Original Message:
Sent: Fri February 23, 2024 04:52 AM
From: Thierry Sola
Subject: Add float Transitiontime Matrix and use No overlap function
Hello,
You must use a non-negative integer tuple set to input your transition times. The transition times must be integer.
Here is a link to the documentation:
https://www.ibm.com/docs/en/icos/22.1.1?topic=functions-nooverlap
Thierry Sola
------------------------------
Thierry Sola
Original Message:
Sent: Wed February 21, 2024 01:59 PM
From: Fam Saeed
Subject: Add float Transitiontime Matrix and use No overlap function
Hi,
I am writing a code to optimize the construction schedule of multiple buildings, using N number of workers. Each worker can only perform one (Specific) task and can only perform one task at a time.
I want to consider the transition time of the workers across the units. I want to input the transition time as a matrix, not a tuple (for more convenience with the large number of buildings).
Here is a snippet of my code:
using CP;
int NbHouses = ...;
range Houses = 1..NbHouses;
{string} WorkerNames = ...;
{string} TaskNames = ...;
int Duration [h in Houses][t in TaskNames] = ...;
string Worker [t in TaskNames] = ...;
// transitiontime across the units
float transitionTimes [Houses][Houses]=...;
//Add the no overlap constraints
forall(w in WorkerNames)
noOverlap(workers[w], transitionTimes);
The transitiontime matrix is input in the .dat file as follows:
// transitionTimes to be entered as a fraction of day (e.g., 2 hrs = 0.25 day)
transitionTimes = [[0.00, 0.51, 0.26, 0.42, 0.15],
[0.51, 0.00, 0.34, 0.12, 0.45],
[0.26, 0.34, 0.00, 0.55, 0.19],
[0.42, 0.12, 0.55, 0.00, 0.28],
[0.15, 0.45, 0.19, 0.28, 0.00]
];
I keep getting an error.
Any kind of help would be appreciated,
Fam
------------------------------
Fam Saeed
------------------------------