如何使标准的旅行商解算器成为or-tools的收集价格解算器?

时间:2015-09-02 08:02:47

标签: python algorithm traveling-salesman or-tools vehicle-routing

我已经设置了一个精确的求解器* *访问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.'

0 个答案:

没有答案