Skip to main content
added 1431 characters in body
Source Link
MAYA
  • 129
  • 5

I'm trying to solve the CVRP based on flow-formulation. In such a model, we have a decision variable with two-index, $x_{ij}$, where I'm using the MTZ formula to eliminate sub-tours. We have then a continuous variable that represents the flow of the vehicle after visiting a customer. Let's say $y_i$. In the case of delivery, the constraints that I formulate is:

$y_j \le y_i - d_j*x_{ij}+ Q*(1-x_{ij})$ , where $(0 \le y_i \le Q - d_i$).

For this example with $5$ customers : $\{1:19;2:30;3:16;4:23;5:11\}$ and $Q=35$, the solution I got is:

$x : \{(0,3);(3,1);(1,0);(0,2);(2,0);(0,4);(4,5);(5,0)\}$
For the other variables, $x$ is null.

$y: \{1:0;2:0;3:16;4:11;5:0\}$.
I expected 12 for $y_4 = 35 - 23 = 12$ and $y_5 = 12 - 11 = 1$

enter image description here

But something is wrong that I can not identify.

mdl = Model('CVRP2')
arc_k = {(i, j) for i in nodes for j in nodes if i != j}
var = {(i) for i in customers}
xt = mdl.addVars(arc_k, vtype=GRB.BINARY, name='xt')
y =  mdl.addVars(var, vtype=GRB.CONTINUOUS, name='y')
mdl.modelSense = GRB.MINIMIZE
mdl.setObjective(grb.quicksum(time_truck[i][j] * xt[i, j] if i!=j else 0 
for i in nodes for j in nodes)) 
#Constraint 1- Exactly the total number of vehicles leaves and return to 
 the depot 
mdl.addConstr(grb.quicksum(xt[0, j] for j in customers) <= nT)
mdl.addConstr(grb.quicksum(xt[i, 0] for i in customers) <= nT)
# Constraint 2- Customer is only served once by only one vehicle
for j in customers:
    mdl.addConstr(grb.quicksum(xt[i, j] for i in nodes if i != j) == 1)
# Constraint 3- Only one vehicle enters and leaves each customer 
for j in customers:
    mdl.addConstr(grb.quicksum(xt[i, j] if i != j else 0 for i in nodes) - grb.quicksum(xt[j, i] if i != j else 0 for i in nodes) == 0)
# Constraint 4: Subtour Elimination 
for i in customers:
    for j in customers:
        if i != j:
            mdl.addConstr(y[j]<=y[i]-df.demand[j] + (truck_capacity) * 
           (1- xt[i, j]))
#Constraint 5: Capacity Bounding Constraint
for i in customers:
    mdl.addConstr(y[i] >=0)
    mdl.addConstr(y[i] <= truck_capacity - df.demand[i])

I'm trying to solve the CVRP based on flow-formulation. In such a model, we have a decision variable with two-index, $x_{ij}$, where I'm using the MTZ formula to eliminate sub-tours. We have then a continuous variable that represents the flow of the vehicle after visiting a customer. Let's say $y_i$. In the case of delivery, the constraints that I formulate is:

$y_j \le y_i - d_j*x_{ij}+ Q*(1-x_{ij})$ , where $(0 \le y_i \le Q - d_i$).

For this example with $5$ customers : $\{1:19;2:30;3:16;4:23;5:11\}$ and $Q=35$, the solution I got is:

$x : \{(0,3);(3,1);(1,0);(0,2);(2,0);(0,4);(4,5);(5,0)\}$
For the other variables, $x$ is null.

$y: \{1:0;2:0;3:16;4:11;5:0\}$.
I expected 12 for $y_4 = 35 - 23 = 12$ and $y_5 = 12 - 11 = 1$

enter image description here

But something is wrong that I can not identify.

I'm trying to solve the CVRP based on flow-formulation. In such a model, we have a decision variable with two-index, $x_{ij}$, where I'm using the MTZ formula to eliminate sub-tours. We have then a continuous variable that represents the flow of the vehicle after visiting a customer. Let's say $y_i$. In the case of delivery, the constraints that I formulate is:

$y_j \le y_i - d_j*x_{ij}+ Q*(1-x_{ij})$ , where $(0 \le y_i \le Q - d_i$).

For this example with $5$ customers : $\{1:19;2:30;3:16;4:23;5:11\}$ and $Q=35$, the solution I got is:

$x : \{(0,3);(3,1);(1,0);(0,2);(2,0);(0,4);(4,5);(5,0)\}$
For the other variables, $x$ is null.

$y: \{1:0;2:0;3:16;4:11;5:0\}$.
I expected 12 for $y_4 = 35 - 23 = 12$ and $y_5 = 12 - 11 = 1$

enter image description here

But something is wrong that I can not identify.

mdl = Model('CVRP2')
arc_k = {(i, j) for i in nodes for j in nodes if i != j}
var = {(i) for i in customers}
xt = mdl.addVars(arc_k, vtype=GRB.BINARY, name='xt')
y =  mdl.addVars(var, vtype=GRB.CONTINUOUS, name='y')
mdl.modelSense = GRB.MINIMIZE
mdl.setObjective(grb.quicksum(time_truck[i][j] * xt[i, j] if i!=j else 0 
for i in nodes for j in nodes)) 
#Constraint 1- Exactly the total number of vehicles leaves and return to 
 the depot 
mdl.addConstr(grb.quicksum(xt[0, j] for j in customers) <= nT)
mdl.addConstr(grb.quicksum(xt[i, 0] for i in customers) <= nT)
# Constraint 2- Customer is only served once by only one vehicle
for j in customers:
    mdl.addConstr(grb.quicksum(xt[i, j] for i in nodes if i != j) == 1)
# Constraint 3- Only one vehicle enters and leaves each customer 
for j in customers:
    mdl.addConstr(grb.quicksum(xt[i, j] if i != j else 0 for i in nodes) - grb.quicksum(xt[j, i] if i != j else 0 for i in nodes) == 0)
# Constraint 4: Subtour Elimination 
for i in customers:
    for j in customers:
        if i != j:
            mdl.addConstr(y[j]<=y[i]-df.demand[j] + (truck_capacity) * 
           (1- xt[i, j]))
#Constraint 5: Capacity Bounding Constraint
for i in customers:
    mdl.addConstr(y[i] >=0)
    mdl.addConstr(y[i] <= truck_capacity - df.demand[i])
added 6 characters in body
Source Link
MAYA
  • 129
  • 5

I'm trying to solve the CVRP based on flow-formulation. In such a model, we have a decision variable with two-index, $x_{ij}$, where I'm using the MTZ formula to eliminate sub-tours. We have then a continuous variable that represents the flow of the vehicle after visiting a customer. Let's say $y_i$. In the case of delivery, the constraints that I formulate is:

$y_j \le y_i - d_i + Q*(1-x_{ij})$$y_j \le y_i - d_j*x_{ij}+ Q*(1-x_{ij})$ , where $(0 \le y_i \le Q - d_i$).

For this example with $5$ customers : $\{1:19;2:30;3:16;4:23;5:11\}$ and $Q=35$, the solution I got is:

$x : \{(0,3);(3,1);(1,0);(0,2);(2,0);(0,4);(4,5);(5,0)\}$
For the other variables, $x$ is null.

$y: \{1:0;2:0;3:16;4:11;5:0\}$.
I expected 12 for $y_4 = 35 - 23 = 12$ and $y_5 = 12 - 11 = 1$

enter image description here

But something is wrong that I can not identify.

I'm trying to solve the CVRP based on flow-formulation. In such a model, we have a decision variable with two-index, $x_{ij}$, where I'm using the MTZ formula to eliminate sub-tours. We have then a continuous variable that represents the flow of the vehicle after visiting a customer. Let's say $y_i$. In the case of delivery, the constraints that I formulate is:

$y_j \le y_i - d_i + Q*(1-x_{ij})$ , where $(0 \le y_i \le Q - d_i$).

For this example with $5$ customers : $\{1:19;2:30;3:16;4:23;5:11\}$ and $Q=35$, the solution I got is:

$x : \{(0,3);(3,1);(1,0);(0,2);(2,0);(0,4);(4,5);(5,0)\}$
For the other variables, $x$ is null.

$y: \{1:0;2:0;3:16;4:11;5:0\}$.
I expected 12 for $y_4 = 35 - 23 = 12$ and $y_5 = 12 - 11 = 1$

enter image description here

But something is wrong that I can not identify.

I'm trying to solve the CVRP based on flow-formulation. In such a model, we have a decision variable with two-index, $x_{ij}$, where I'm using the MTZ formula to eliminate sub-tours. We have then a continuous variable that represents the flow of the vehicle after visiting a customer. Let's say $y_i$. In the case of delivery, the constraints that I formulate is:

$y_j \le y_i - d_j*x_{ij}+ Q*(1-x_{ij})$ , where $(0 \le y_i \le Q - d_i$).

For this example with $5$ customers : $\{1:19;2:30;3:16;4:23;5:11\}$ and $Q=35$, the solution I got is:

$x : \{(0,3);(3,1);(1,0);(0,2);(2,0);(0,4);(4,5);(5,0)\}$
For the other variables, $x$ is null.

$y: \{1:0;2:0;3:16;4:11;5:0\}$.
I expected 12 for $y_4 = 35 - 23 = 12$ and $y_5 = 12 - 11 = 1$

enter image description here

But something is wrong that I can not identify.

added 10 characters in body
Source Link
A.Omidi
  • 9.5k
  • 2
  • 15
  • 50

I'm trying to solve the CVRP based on flow-formulation. In such a model, we have a decision variable with two-index, $x_{ij}$, where I'm using the MTZ formula to eliminate sub-tours. We have then a continuous variable that represents the flow of the vehicle after visiting a customer. Let's say $y_i$. In the case of delivery, the constraints that I formulate is:

$y_j \le y_i - d_i + Q*(1-x_{ij})$
where $ 0\le y_i \le Q - d_i$ , where $(0 \le y_i \le Q - d_i$).

For this example with 5$5$ customers : $\{1:19;2:30;3:16;4:23;5:11\}$ and $Q=35$
The, the solution I got is:

$x : \{(0,3);(3,1);(1,0);(0,2);(2,0);(0,4);(4,5);(5,0)\}$
For the other variables, $x$ is null.
  

$y: \{1:0;2:0;3:16;4:11;5:0\}$.
I expected 12 for $y_4 = 35 - 23 = 12$ and $y_5 = 12 - 11 = 1$   

enter image description here But

But something is wrong that I can not identify.

I'm trying to solve the CVRP based on flow-formulation. In such a model, we have a decision variable with two-index, $x_{ij}$, where I'm using the MTZ formula to eliminate sub-tours. We have then a continuous variable that represents the flow of the vehicle after visiting a customer. Let's say $y_i$. In the case of delivery, the constraints that I formulate is:

$y_j \le y_i - d_i + Q*(1-x_{ij})$
where $ 0\le y_i \le Q - d_i$

For this example with 5 customers : $\{1:19;2:30;3:16;4:23;5:11\}$ and $Q=35$
The solution I got is:

$x : \{(0,3);(3,1);(1,0);(0,2);(2,0);(0,4);(4,5);(5,0)\}$
For the other variables, $x$ is null.
 $y: \{1:0;2:0;3:16;4:11;5:0\}$.
I expected 12 for $y_4 = 35 - 23 = 12$ and $y_5 = 12 - 11 = 1$  enter image description here But something is wrong that I can not identify.

I'm trying to solve the CVRP based on flow-formulation. In such a model, we have a decision variable with two-index, $x_{ij}$, where I'm using the MTZ formula to eliminate sub-tours. We have then a continuous variable that represents the flow of the vehicle after visiting a customer. Let's say $y_i$. In the case of delivery, the constraints that I formulate is:

$y_j \le y_i - d_i + Q*(1-x_{ij})$ , where $(0 \le y_i \le Q - d_i$).

For this example with $5$ customers : $\{1:19;2:30;3:16;4:23;5:11\}$ and $Q=35$, the solution I got is:

$x : \{(0,3);(3,1);(1,0);(0,2);(2,0);(0,4);(4,5);(5,0)\}$
For the other variables, $x$ is null. 

$y: \{1:0;2:0;3:16;4:11;5:0\}$.
I expected 12 for $y_4 = 35 - 23 = 12$ and $y_5 = 12 - 11 = 1$ 

enter image description here

But something is wrong that I can not identify.

added 85 characters in body
Source Link
MAYA
  • 129
  • 5
Loading
added 3 characters in body
Source Link
EhsanK
  • 5.9k
  • 3
  • 19
  • 54
Loading
Source Link
MAYA
  • 129
  • 5
Loading