class SolutionCallback(object): def __init__(self, model): self.model = model
def __call__(self): print("Solution", self.model.CostVar().Max())
solution_callback = SolutionCallback(routing)routing.AddAtSolutionCallback(solution_callback)
def print_solution(manager, routing, assignment): """Prints assignment on console.""" print('Objective: {} miles'.format(assignment.ObjectiveValue())) index = routing.Start(0) plan_output = 'Route for vehicle 0:\n' route_distance = 0 while not routing.IsEnd(index): plan_output += ' {} ->'.format(manager.IndexToNode(index)) previous_index = index index = assignment.Value(routing.NextVar(index)) route_distance += routing.GetArcCostForVehicle(previous_index, index, 0) plan_output += ' {}\n'.format(manager.IndexToNode(index)) print(plan_output) plan_output += 'Route distance: {}miles\n'.format(route_distance)--
You received this message because you are subscribed to the Google Groups "or-tools-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to or-tools-discu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/or-tools-discuss/935ffb69-16dd-428d-afad-65007d016147%40googlegroups.com.
You actually don't need the assignment, you can directly look at the variable values when the callback is called. For instance, instead of index = assignment.Value(routing.NextVar(index)), just do index = routing.NextVar(index).Value().
To unsubscribe from this group and stop receiving emails from it, send an email to or-tools...@googlegroups.com.
class SolutionCallback(object): def __init__(self, model): self.model = model self.time = model.GetDimensionOrDie("Time")
def __call__(self): index = self.model.NextVar(0) time_var = self.time.CumulVar(index) print(time_var.Value())
You actually don't need the assignment, you can directly look at the variable values when the callback is called. For instance, instead of index = assignment.Value(routing.NextVar(index)), just do index = routing.NextVar(index).Value().
To unsubscribe from this group and stop receiving emails from it, send an email to or-tools...@googlegroups.com.