简体   繁体   English

我们可以只打印第一个解决方案策略而不打印 Google OR 工具中的本地搜索解决方案吗?

[英]Can we only print the first solution strategy and not the local search solution in Google OR Tools?

I am currently learning how to use Google OR-Tools, specifically on the CVRP Problem.我目前正在学习如何使用 Google OR-Tools,特别是在 CVRP 问题上。 The code is divided into two stages.代码分为两个阶段。 The first one is finding the initial/first solution using path-cheapest-arc, savings algorithm, etc. the second stage is finding the solution using local search.第一个是使用最便宜的路径、节省算法等找到初始/第一个解决方案。第二阶段是使用本地搜索找到解决方案。 ` `

# Setting first solution heuristic.
    search_parameters = pywrapcp.DefaultRoutingSearchParameters()
    search_parameters.first_solution_strategy = (
        routing_enums_pb2.FirstSolutionStrategy.PATH_CHEAPEST_ARC)
    search_parameters.local_search_metaheuristic = (
        routing_enums_pb2.LocalSearchMetaheuristic.GUIDED_LOCAL_SEARCH)
    search_parameters.time_limit.FromSeconds(1)

The code above contains two searching parameters, the first solution strategy (path cheapest arc) and the local search metaheuristic.上面的代码包含两个搜索参数,第一个解决方案策略(路径最便宜的弧)和局部搜索元启发式。 My question is, can we only use the first solution strategy and not use the local search metaheuristic?我的问题是,我们是否可以只使用第一种解决策略而不使用本地搜索元启发式?

Thanks!谢谢!

I'm trying to compare the solution that I obtain from only using the first solution and the metaheuristic one.我正在尝试比较仅使用第一个解决方案和元启发式解决方案获得的解决方案。

YES you can, simply don't set it, aka remove the line.是的,您可以,只是不要设置它,也就是删除该行。

search_parameters.local_search_metaheuristic = (
        routing_enums_pb2.LocalSearchMetaheuristic.GUIDED_LOCAL_SEARCH)

Just to add to Mizux's answer, since you said you are new to OR-Tools and want to compare the solution.只是添加到 Mizux 的答案中,因为你说你是 OR-Tools 的新手并且想比较解决方案。

You can add the following line to display the log in the terminal:您可以添加以下行以在终端中显示日志:

search_parameters.log_search = True

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM