I have some problem with my code. VC must add X(i)(j)(k) but when multiplying and running the result, there is a problem of splitting the route and not starting from the depot. Can "execute" be used for additional calculation for "objective function"? If not, how should I fix the code? I am working on the multi-depot VRP problem including 2 depots, 7 customers, and 1 type of vehicle.
//Parameters
int numOfN = ...;
int numOfM = ...;
int numOfK = ...;
int numOfL = ...;
int Mdist = ...;
int numOfP = numOfN + numOfM;
range P = 1..numOfP;
range I = 1..numOfM;
range J = numOfM+1..numOfM+numOfN;
range K = 1..numOfK;
range L = 1..numOfL;
float dist_ij[P, P] = ...;
float veh_k_Cap[1..numOfK] = ...;
float veh_k_FC[1..numOfK] = ...;
float veh_k_VC[1..numOfK] = ...;
float veh_k_DC[1..numOfK] = ...;
float item_l_W[1..numOfL] = ...;
float demand_il[P, L] = ...;
// Decision variable
dvar boolean X[P][P][K];
dvar int+ D[P][K][L];
dvar int+ S[P][P][K][L];
//Objective function
minimize
sum(i in P, j in P, k in K: i!=j) veh_k_FC[k]*X[i][j][k]
+ sum(i in P, j in P: i!=j) dist_ij[i][j] * sum(k in K) veh_k_VC[k]
+ sum(i in J, j in J, k in K: i!=j) veh_k_DC[k]*X[i][j][k];
// ---------------------------------------------
subject to {
// (2) Each order can be divided into multiple trips.
forall(j in P)
sum(i in P, k in K: i!=j) X[i][j][k] >= 1;
// (3) The number of vehicles arriving at a destination is equal to the number of vehicles leaving
forall(k in K, p in P)
sum(i in P) X[i][p][k] - sum(j in P) X[p][j][k] == 0;
// (4) Each vehicle can only visit a delivery point once.
forall(k in K, i in J: i>1)
sum(j in P) X[i][j][k] <= 1;
// (5) Each vehicle can only travel from the construction material store once.
forall(k in K, i in I: i>1)
sum(j in P) X[i][j][k] <= 1;
// (6) Each vehicle can only travel to the depot once
forall(k in K, i in I)
sum(j in P) X[j][i][k] <= 1;
// (7) The delivery route of each vehicle cannot exceed the maximum distance required.
forall(k in K)
sum(i in P, j in P: i!=j) dist_ij[i][j] * X[i][j][k] <= Mdist;
// (8) That the quantity of items delivered to consumers by all vehicles is equal to the demand off products required for every order placed by a client
forall(i in P)
sum(k in K) D[i][k][1] == demand_il[i][1];
// (9) Each vehicle's maximum capacity is not exceeded by the product weight of the orders on it.
forall(k in K)
sum(i in P) D[i][k][1] * item_l_W[1] <= veh_k_Cap[k];
// (10) The total weight of all orders in a vehicle's route must not exceed the vehicle's capacity forall(k in K) sum(i in P, j in P: i!=j) demand_il[i][1] * X[i][j][k] * item_l_W[1] <= veh_k_Cap[k];
// (11) Each vehicle leaves the construction material store the total weight of all goods from all orders must not exceed the vehicle's loading capacity.
forall(j in J, k in K, i in I: j>1)
item_l_W[1] * S[i][j][k][1] <= veh_k_Cap[k];
// (12) The total weight of the products on each vehicle to ensure that it does not exceed the vehicle's load capacity
forall(i in P, j in P, k in K: i!=j)
item_l_W[1] * S[i][j][k][1] <= X[i][j][k] * veh_k_Cap[k];
// (13) All vehicles must be empty while returning to the building material store
forall(k in K)
sum(i in P, j in I) item_l_W[1] * S[i][j][k][1] <= 0;
// (14) Depots cannot exchange goods with each other
forall(i in I, j in I, k in K)
X[i][j][k] == 0;
// (15) Each center has at least one vehicle.
forall(k in K)
(sum(i in P, j in P: i!=j) X[i][j][k] >= 1) => (sum(i in I, j in P: i!=j) X[i][j][k] == 1);
}
execute {
var totalCost = 0;
for(var i in P)
for(var j in P)
if(i != j)
for(var k in K)
totalCost += veh_k_FC[k] * X[i][j][k] + dist_ij[i][j] * veh_k_VC[k] * X[i][j][k];
for(var i in J)
for(var j in J)
if(i != j)
for(var k in K)
totalCost += veh_k_DC[k] * X[i][j][k];
}