1

I have set-up a fine solver for *what is the best route to visit 1000 nodes" in my graph.

But I would like to solve the question "what is the shortest route to visit any 500 of 1000 given nodes in my graph".

I think, I have to add disjunctive constraints somehow to my python RoutingModel, but how?

This is a rough sketch of my current solver:

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.'
Karussell
  • 17,085
  • 16
  • 97
  • 197
towi
  • 21,587
  • 28
  • 106
  • 187
  • possibly related: http://stackoverflow.com/questions/26927960/a-variation-of-tsp-limit-time-visit-as-many-nodes-as-possible – Drunix Sep 07 '15 at 11:36

0 Answers0