Originally posted by: AndyHam
Dear IBM,
I am struggling with heightAtEnd in conjunction with cumulFunction.
In particular, the following two constraints do not correctly calculate the cumul function (it returns all zero).
//c1: heightAtEnd(itvJ2T[j,t],cumBattery[t])==sizeOf(itvJ2T[j,t]);
//c3: heightAtEnd(itvJ2T[j,t],cumBattery[t])==DistMatrixById[j.id][typeOfNext(seqTrk[t], itvJ2T[j][t], j.id, j.id)];
However, this
constraint works. c2: heightAtEnd(itvJ2T[j,t],cumBattery[t])==1;
Two weeks ago, I was testing the cumulative travel distance (c3) and it worked well.
// DistMatrixById[j.id][typeOfNext(seqTrk[t], itvJ2T[j][t], j.id, j.id)];
Now, it does not work anymore after I upgraded OPL into 12.8 (or I made some mistake ^^).
If IBM can take a look into the following code, it will be appreciated.
//================================================
Jobs = {
< 0 d 40 50 0 0 1236 0 >
< 1 d 40 50 0 0 1236 0 >
< 2 d 40 50 0 0 1236 0 >
< 3 d 40 50 0 0 1236 0 >
< 7 c 20 55 10 355 407 90 >
< 8 c 25 85 20 176 228 90 >
< 9 c 55 85 20 744 798 90 >
< 10 c 68 60 30 737 809 90 >
< 11 c 48 30 10 263 325 90 >
};
using CP;
int m =1; // Number of Trucks
range Trucks = 1..m;
tuple t_Job {
key int id;
string ctype;
int x;
int y;
int q;
int r;
int d;
int s;
};
{t_Job} Jobs = ...;
{int} Customers = { j.id | j in Jobs };
tuple triplet { int c1; int c2; int d; };
{triplet} Dist = {
<j1.id, j2.id, ftoi(round(sqrt(pow(j2.x-j1.x,2)+pow(j2.y-j1.y,2)))) >
| j1, j2 in Jobs : j1.id != j2.id };
int DistMatrix[p1 in Jobs][p2 in Jobs] = ftoi(round(sqrt(pow(p2.x-p1.x,2)+pow(p2.y-p1.y,2))));
int DistMatrixById[c1 in Customers][c2 in Customers] = DistMatrix[<c1>][<c2>];
dvar interval itvJob[j in Jobs] size j.s ;
dvar interval itvJ2T[j in Jobs][Trucks] optional;
dvar sequence seqTrk[t in Trucks]
in all(j in Jobs) itvJ2T[j][t]
types all(j in Jobs) j.id;
cumulFunction cumBattery[t in Trucks]=
sum(j in Jobs) stepAtEnd (itvJ2T[j,t], 0,9999999);
dexpr float totDistance =
sum(j in Jobs, t in Trucks) DistMatrixById[j.id][typeOfNext(seqTrk[t], itvJ2T[j][t], j.id, j.id)];
execute {
cp.param.TimeMode = "ElapsedTime";
cp.param.TimeLimit = 2;
}
minimize totDistance;
constraints {
forall(j in Jobs,t in Trucks)
//c1: heightAtEnd(itvJ2T[j,t],cumBattery[t])==sizeOf(itvJ2T[j,t]);
c2: heightAtEnd(itvJ2T[j,t],cumBattery[t])==1; //DistMatrixById[j.id][typeOfNext(seqTrk[t], itvJ2T[j][t], j.id, j.id)];
//c3: heightAtEnd(itvJ2T[j,t],cumBattery[t])==DistMatrixById[j.id][typeOfNext(seqTrk[t], itvJ2T[j][t], j.id, j.id)];
forall(t in Trucks)
cumBattery[t] <= 9999999999999;
forall(t in Trucks)
noOverlap(seqTrk[t], Dist);
forall(t in Trucks,j in Jobs: t-1==j.id && j.id<=1) //j0 ==> t1, j1==t2
{
presenceOf(itvJ2T[j][t])==1;
first(seqTrk[t],itvJ2T[j][t]); // Truck t starts at depot
}
forall(t in Trucks,j in Jobs: t+1==j.id && j.id>=2 && j.id<=3)//j2 ==> t1, j3==t2
{
presenceOf(itvJ2T[j][t])==1;
last (seqTrk[t],itvJ2T[j][t]); // Truck t ends at depot
}
forall(j in Jobs)
alternative(itvJob[j], all(t in Trucks) itvJ2T[j][t]); // Truck selection
}
#DecisionOptimization#OPLusingCPOptimizer