微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

or-tools 如何在搜索过程中强制停止 vrp 求解器

如何解决or-tools 如何在搜索过程中强制停止 vrp 求解器

有没有办法在搜索解决方案期间停止 or-tools 求解器?我为搜索设置了限制

 RoutingSearchParameters searchParameters =
                main.defaultRoutingSearchParameters()
                        .toBuilder()
                        .setLogSearch(true)
                        .setSolutionLimit(solutionLimit)
                        .setFirstSolutionStrategy(FirstSolutionStrategy.Value.AUTOMATIC)
                        .setLocalSearchMetaheuristic(LocalSearchMetaheuristic.Value.GUIDED_LOCAL_SEARCH)
                        .setTimeLimit(com.google.protobuf.Duration.newBuilder().setSeconds(60 * 60 * 12).build())
                        .build();

但在某些情况下,我想强制停止搜索。例如,当我发现输入数据错误时。我尝试了 endSearch 方法,但在调用过程中异常停止后。

routing.addAtSolutionCallback(() -> {
            foundSolutionsCount.getAndIncrement();
            listener.onProgress((float)foundSolutionsCount.get() / finalSolutionLimit);
            if (foundSolutionsCount.get() >= 3) {
                routing.solver().endSearch();
            }
        });

异常日志:

I0125 17:27:39.820322 203316 search.cc:254] Solution #1 (12890,objective maximum = 12920,time = 2785 ms,branches = 383,failures = 103,depth = 33,PairRelocateOperator,neighbors = 16323,filtered neighbors = 3,accepted neighbors = 1,memory used = 1858.74 MB,limit = 20%)
I0125 17:27:39.949419 203316 search.cc:254] End search (time = 2914 ms,branches = 481,failures = 112,speed = 165 branches/s)
F0125 17:27:39.949463 203316 expressions.cc:1340] Check Failed: min_.Value() == max_.Value() (0 vs. 9223372036854775807)  variable Cost(0..9223372036854775807) is not bound.
*** Check failure stack trace: ***

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。