I want to have x vehicle which goes on a graph going from vertex 1 and ending in the same all vertices as to be seen one time by one and only one vehicle (for those who know, i'm interesting in a PDPTW problem, but i'm stuck at this point)
using JuMP
using Cbc
nbVertex = 5
nbTransp = 2
model = Model(optimizer_with_attributes(Cbc.Optimizer, "seconds" => limiteExec))
set_optimizer_attribute(model, "PrimalTolerance", 1e-9)
print(model)
#les variables de decisions
@variable(model, route[1:nbVertex,1:nbVertex,1:nbTransp],Bin) #if road between 2 vertex is taken by vehic v
@variable(model, object>=0)
@constraint(model, [v in 1:nbTransp],sum(route[1,i,v] for i in 1:nbVertex)==1)#starting at one
@constraint(model, [v in 1:nbTransp],sum(route[i,1,v] for i in 1:nbVertex)==1)#ending at one
@constraint(model, [j=2: nbVertex],sum(route[i,j,v] for i in 1:nbVertex , v in 1 : nbTransp if i != j )==1)
# all vertices as to be seen by one and only one vehicule
@constraint(model, [j=1:nbVertex, v= 1: nbTransp],sum(route[i,j,v] for i in 1:nbVertex if i != j)-sum(route[j,k,v] for k in 1:nbVertex if k != j)==0)
# here is the constraint
@objective(model, Min,object)
@show model
optimize!(model)
for k in 1:nbTransp
dataTmp=Matrix(undef,2,0)
for i in 1:nbVertex
for j in 1:nbVertex
if value.(route[i,j,k])==1
dataTmp=hcat(dataTmp,[i,j])
println("vehicule ", k, " from ", i, " to ", j, ": $(route[i,j,k]) " )
end
end
end
end
vehicule 1 from 1 to 2: route[1,2,1]
vehicule 1 from 2 to 1: route[2,1,1]
vehicule 2 from 1 to 3: route[1,3,2]
vehicule 2 from 3 to 1: route[3,1,2]
vehicule 2 from 4 to 5: route[4,5,2]
vehicule 2 from 5 to 4: route[5,4,2]
why is vehicle 2 looping in 4->5->4->5->4 ...?