0

I've got a problem with a gurobi program which is supposed to find a certain number of distinct shortest paths in a graph with a length not exceeding maxLength by using an LP. For making sure that the different paths are distinct I tried to sum up the number of arcs where one path is different from another. y[a,i,j] should be one if paths i and j are different in arc a and zero otherwise.

I tried to achieve that by taking the difference between x[a,i] and x[a,j] at every arc and then expect the sum over all arcs for every combination of i and j to be greater one. Everything above that are just constraints for a regular min cost flow. Somehow my problem is infeasible for any of the test instances if I want more than 1 path. Any ideas? Thanks in advance.

def findXShortestPaths(V, A, pred, succ, start, end, cost, amount, maxLength, origin, destination): 
model = Model("Shortest Path")
I = range(amount) 

x = model.addVars(A, I, vtype = GRB.BINARY, name = "x")

y = model.addVars(A, I, I, vtype = GRB.INTEGER, name = "y")  

z = model.addVars(A,I,I,vtype=GRB.BINARY,name="z")

model.setObjective(quicksum(cost[a] * x[a, i] for a in A for i in I), GRB.MINIMIZE)

model.addConstrs(quicksum(x[a,i] for a in pred[v]) - quicksum(x[a,i] for a in succ[v]) == 0 for i in I for v in V if v != origin and v != destination)

model.addConstrs(quicksum(x[a,i] for a in succ[origin]) == 1 for i in I)

model.addConstrs(quicksum(x[a,i] for a in pred[destination]) == 1 for i in I)

model.addConstrs(x[a,i] + x[b,i] <= 1 for i in I for a in A for b in A if end[a] == start[b] and end[b] == start[a])


model.addConstrs(y[a,i,j]==x[a,i]-x[a,j] for a in A for i in I for j in I)
model.addConstrs(z[a,i,j]== abs_(y[a,i,j]) for a in A for i in I for j in I)

model.addConstrs(quicksum(z[a,i,j] for a in A) >= 1  for i in I for j in I if i != j) 

model.addConstrs(quicksum(x[a,i]*cost[a] for a in A) <= maxLength for i in I)

model.optimize()
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
nickk
  • 1

0 Answers0