java - OptaPlanner:如何在没有 .xml 配置文件的情况下构建求解器?
问题描述
默认情况下,我是 OptaPlanner 的初学者,我发现所有求解器都是由 OptaPlanner 中的 xml 配置文件构建的。所以我想知道如何仅使用纯 java 代码构建我的求解器,就像
SolverFactory.setScoreCalculator(new NQueensEasyScoreCalculator()).setSearch(new ***()).build();
也就是说,我们不需要其他的xml文件,就可以使用上面的solver来解决问题。所以任何人都可以告诉我我该如何处理它?
非常感谢。
解决方案
SolverConfig
是的,您可以使用fluent API构建配置。例如:
SolverConfig solverConfig = new SolverConfig()
.withEnvironmentMode(EnvironmentMode.REPRODUCIBLE)
.withSolutionClass(VehicleRoutingSolution.class)
.withEntityClasses(Standstill.class, PlanningVisit.class)
.withScoreDirectorFactory(new ScoreDirectorFactoryConfig().withScoreDrls("org/optaweb/vehiclerouting/solver/vehicleRoutingScoreRules.drl"))
.withTerminationConfig(new TerminationConfig().withSecondsSpentLimit(60L))
.withPhases(
new ConstructionHeuristicPhaseConfig().withConstructionHeuristicType(ConstructionHeuristicType.FIRST_FIT_DECREASING),
new LocalSearchPhaseConfig().withLocalSearchType(LocalSearchType.TABU_SEARCH)
);
然后你可以使用配置来构建一个求解器SolverFactory
:
SolverFactory<VehicleRoutingSolution> solverFactory = SolverFactory.create(solverConfig);
Solver<VehicleRoutingSolution> solver = solverFactory.buildSolver();
在您的情况下,配置可能更简单。我包括了更多选项来说明可能性。
推荐阅读
- python - 用于线性回归的具有多个系列的 pandas 数据帧的 Y 截距
- python - Mac 上的 Python // 更改工作目录
- python - 如何按字母顺序将项目放在桌子上的循环中?
- python - 如何使用 python 代码创建表格,然后在浏览器中查看?
- node.js - 为什么在 macOS 上使用 mocha 运行 Node.js 脚本时未定义 LD_LIBRARY_PATH?
- ms-office - Onlyoffice或WOPI协议
- orientdb - 为什么本地 OrientDB 控制台中的列表类挂起?
- html - 为什么 display: flex 可以工作但不能标记?
- ruby-on-rails - 运行上限生产部署和 bitbucket
- python - 尝试人脸识别时出现可见的弃用警告和值错误