我正在使用 Google 的 OR-Tools 来解决 VRPtw 问题,并努力思考日志。
我向解算器提供一定数量的访问点和车辆。我不知道这需要多少时间,也就是说,甚至时间的尺度。
我们有什么办法可以获取进度信息吗?
我知道有一个 SearchLog 类(https://developers.google.com/optimization/reference/constraint_solver/constraint_solveri/SearchLog)。但我不明白这能给我我想要的信息。
首先,您必须了解求解器的工作分两个步骤,首先它将尝试找到第一个解决方案,然后如果启用,它将尝试使用本地搜索来改进它。
要在每次找到解决方案时获取日志,可以使用搜索参数 proto。
search_parameters.local_search_metaheuristic = (
routing_enums_pb2.LocalSearchMetaheuristic.GUIDED_LOCAL_SEARCH)
search_parameters.log_search = True
solution = routing.SolveWithParameters(search_parameters)
Run Code Online (Sandbox Code Playgroud)
然后,如果您想要非常细粒度的跟踪,您可以使用路由参数 proto 启用跟踪日志
routing_parameters = pywrapcp.DefaultRoutingModelParameters()
routing_parameters.solver_parameters.trace_propagation = True
routing_parameters.solver_parameters.trace_search = True
routing = pywrapcp.RoutingModel(manager, routing_parameters)
Run Code Online (Sandbox Code Playgroud)
参考:https://github.com/google/or-tools/blob/a0a56698ba8fd07b7f84aee4fc45d891a8cd9828/ortools/constraint_solver/routing_parameters.proto#L431-L433和
https://github.com/google/or-tools/blob/a0a56698ba8fd07b7f84a ee4fc45d891a8cd9828 /或工具/constraint_solver/solver_parameters.proto#L77-L81
另外不要忘记 VRP 是 NP 难的......