Optaplanner和Quarkus求解器配置更新

huangapple go评论72阅读模式
英文:

Optaplanner and Quarkus solver config update

问题

我正在使用 Quarkus 和 OptaPlanner 进行一个项目,我正在尝试访问和修改求解器的配置,以添加启发式算法、更改搜索算法等等。

我正在使用 solverJob 和 solverManager,但是 Quarkus 似乎将求解器的配置隐藏起来了。我基本上在按照 Quarkus 教程的步骤进行操作(https://quarkus.io/guides/optaplanner)。

public PlannerSolution solve() {
    UUID problemId = UUID.randomUUID();
    SolverJob<PlannerSolution, UUID> solverJob;
    
    solverJob = solverManager.solve(problemId, problem);

    PlannerSolution solution;
    try {
      // 等待求解结束
      System.out.println("等待中................");
      solution = solverJob.getFinalBestSolution();
      System.out.println("完成");
    } catch (InterruptedException | ExecutionException e) {
      throw new IllegalStateException("求解失败。", e);
    }
    return solution;
  }

我还在使用 constraintProvider API。

是否有办法让我访问并修改 Quarkus 自动创建的这个配置?我尝试过使用 solverFactory 和 XML 配置文件的基本方式,但是 Quarkus 对此似乐见其成。

提前谢谢!

英文:

I'm working on a project with quarkus and optaplanner, and I'm trying to access and modify the configuration of the solver, to add heuristics, change search algorithm etc.

I'm using a solverJob and a solverManager, and quarkus seems to be hiding from me the configuration of the solver. I'm basically following the steps of the Quarkus tutorial (https://quarkus.io/guides/optaplanner).

public PlannerSolution solve() {
    UUID problemId = UUID.randomUUID();
    SolverJob&lt;PlannerSolution, UUID&gt; solverJob;
    
    solverJob = solverManager.solve(problemId, problem);

    PlannerSolution solution;
    try {
      // Wait until the solving ends
      System.out.println(&quot;Waiting................&quot;);
      solution = solverJob.getFinalBestSolution();
      System.out.println(&quot;Done&quot;);
    } catch (InterruptedException | ExecutionException e) {
      throw new IllegalStateException(&quot;Solving failed.&quot;, e);
    }
    return solution;
  }

I'm also using the constraintProvider API.
Is there a way for me to access and modify this config made automatically by quarkus ? I've tried the basic way with a solverFactory and xml conf file, but quarkus isn't happy about that at all.

Thank you in advance !

答案1

得分: 4

更改默认的求解器配置,请在项目的类路径上创建XML配置文件。optaplanner-quarkus扩展默认尝试读取solverConfig.xml。在项目中,它应该位于:

.../src/main/resources/solverConfig.xml

配置文件的默认位置可以通过application.properties中的属性quarkus.optaplanner.solver-config-xml进行覆盖。

英文:

To change the default solver configuration, create the XML configuration file on the project's classpath. The optaplanner-quarkus extension tries to read the solverConfig.xml by default. In the project, it should be located in:

.../src/main/resources/solverConfig.xml

The default location of the configuration file can be overridden by the property quarkus.optaplanner.solver-config-xml in the application.properties.

huangapple
  • 本文由 发表于 2020年7月28日 23:15:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/63137461.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定