How to model the VRP flow constraint

288 views Asked by At

I'm having some trouble modeling this constraint in Julia

enter image description here

right now I have

for k=1:v
 for j = 2:nodes
  @constraint(model,sum(x[i,j,k] for i=1:nodes) == sum(x[j,i,k] for i=1:n))
 end
end

where nodes is the customer set, n includes the depot and the depot clone. K is the number of vehicles, i is the start node and j is the end node.

1

There are 1 answers

0
Mathilde Garrigues On

I am not sure that you asked a real question but here is how I would model this constraint in julia :

@constraints(model, begin
[i in 2:nodes, k in 1:K], sum(x[j, i, k] for j in 1:nodes if j != i) == sum(x[i, j, k] for j in 1:nodes if j != i) 
end)

If you are not in a complete graph, be sure that you have well defined your variable x[i, j, k] so that it is equal to 0 when there is no arc between i and j.