首页 > 解决方案 > 如何在使用 optaplanner-spring-boot-starter 时实现 questionFactChange?

问题描述

我将 Optaplanner 8.3.0.Final 与 optaplanner-spring-boot-starter 一起使用,一切都按预期工作,只是我不知道如何实现 issueFactChange。

这个问题:当使用带有 Optaplanner 的 autowired SolverManager 时,如何访问 scoreDirector?提到自动装配solverfactory,然后使用Solverfactory .getScoreDirectorFactory()。但是我看不到如何使用它来访问有线求解器管理器正在使用的求解器,我相信这就是我所需要的“addProblemFactChange”,当求解器可以这样做时,它应该会改变问题事实。

标签: spring-bootoptaplanner

解决方案


存在SolverManager缺少addProblemFactChange()方法的 API 差距。

投票给它。

解决方法

如果没有高级SolverManagerAPI,解决方法是改用低级SolverAPI:

@Autowired
SolverFactory<MySolution> solverFactory

public void runSolver() { // don't call this directly in an HTTP servlet/rest thread
    Solver<MySolution> solver = solverFactory().buildSolver();
    solver.solve(myProblem); // hogs the current thread
}

public void doChange() {
    solver.addProblemFactChange( ... /* do change */);
}

推荐阅读