Originally posted by: JodokusQuak
Great, it's working this way. Thanks a lot, Daniel.
I've got to other issues. Maybe you can help me out. .
1) Now, I have to realise for the "max" constraint that I add to the objective function the max values of the first b = (2*n)+1
and the secound b = (2*n)+2. It is possible that they don't have their highest values in the same period. So I tried it the way to duplicate the constraint. It seems that I get the right values but the calculation time is now 1000 sec higher. Is there another way to save calculation time?
IloNumExprArray sums(env); // sums[t] is sum(v,b,j)q[v][b][j][t]
for (int t = 1; t < u+1; t++) {
// Create the sum of q[*][*][*][t]
IloExpr sum(env);
for (int v = 1; v < s+1; v++)
for (int j = 1; j < (2*n)+m+1; j++)
sum += q[v][(2*n)+1][j][t];
sums.add(sum);
}
OF1 += c_tech * IloMax(sums); // IloMax() yields the maximum of all elements
// in sums
sums.end();
IloNumExprArray sums2(env); // sums2[t] is sum(v,b,j)q[v][b][j][t]
for (int t = 1; t < u+1; t++) {
// Create the sum of q[*][*][*][t]
IloExpr sum2(env);
for (int v = 1; v < s+1; v++)
for (int j = 1; j < (2*n)+m+1; j++)
sum2 += q[v][(2*n)+2][j][t];
sums2.add(sum2);
}
OF1 += c_tech * IloMax(sums2); // IloMax() yields the maximum of all elements
// in sums2
sums2.end();
2) My second issue is the important one: I have another problem with the constraint which one we discussed earlier:
for (int v = 1; v < s+1; v++){
for (int i = 1; i < c+1; i++){
for (int t = 1; t < u+1; t++){
IloExpr x_sum(env);
for (int j = 1; j < (2*n)+m+1; j++)
x_sum += x[v][i][j][t];
OF1 += c_down[i][t] * (((z[v][i+n][t] + t_transfer[i]) * x_sum) + (24 * (1 - x_sum)));
x_sum.end();
}
}
}
The problem is that this formulation is adding the (24 * ... section) for every vessel [v] to the objective function. I want that it's adding this section one time to OF1 if no vessel [v] startet from [i] in [t]. So I tried it this way:
Now, I've got the problem that it's still adding the (24 * ... section) to the obj function even when any vessel [v] startet already from [i] in any period [t] before. So an example: If vessel [v] traveled from [i] to [j] in t=3 of 4 periods then I want that the programming is adding 2 times (for t=1 and t=2) the (24 * ... section) to the obj function but not for the last period t=4 or any period after. Do you understand my problem?
for (int i = 1; i < c+1; i++){
for (int t = 1; t < u+1; t++){
IloExpr x_sum(env);
for (int v = 1; v < s+1; v++)
for (int j = 1; j < (2*n)+m+1; j++)
x_sum += x[v][i][j][t];
OF1 += c_down[i][t] * (24 * (1 - x_sum));
x_sum.end();
}
}
#CPLEXOptimizers#DecisionOptimization