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.'