我已经设置了一个精确的求解器* *访问1000个节点的最佳路径是什么"在我的图表中。
但我想解决问题"访问图表中任意500个给定节点的最短路径是什么"
我想,我必须以某种方式将disjunctive constraints添加到我的python RoutingModel
中,但是如何?
这是我当前解决者的粗略草图:
from ortools.constraint_solver import pywrapcp
nodes = readNodes() # graph nodes
matrix = readMatrix() # costs between edges, distances
assert len(nodes) == len(matrix)
# Create routing model
routing = pywrapcp.RoutingModel(len(nodes), 1)
parameters = ...
# Setting the cost function.
distance = lambda p,q: matrix[p][q]
routing.SetArcCostEvaluatorOfAllVehicles(distance)
# --> here is probably more setup needed <--
# Solve, returns a solution if any.
assignment = routing.SolveWithParameters(parameters, None)
if assignment:
# Solution cost.
print assignment.ObjectiveValue()
# Inspect solution
path = ...
printSolution(nodes, table, path)
else:
print 'No solution found.'