如何在 Optaplanner 中实现自定义终止

How to implement a custom termination in Optaplanner

我正在尝试实现自定义终止 class 但我无法注入 TerminationConfig class 的扩展以加载然后读取新终止所需的自定义字段(包含在求解器中 config.xml)。

我已经实现了:通过扩展 AbstractTermination 的自定义终止以及 TerminationConfig.

的扩展

缺少的部分是我如何告诉 Optaplanner 使用我的自定义配置 class.

提前致谢。

使用TerminationConfig.setTerminationClass(myClass).

<termination>
  <terminationClass>org.foo.Bar</terminationClass>
</termination>

或者如果这还不够,试试

<termination class="org.foo.BarTerminationConfig">
  <barField>7</barField>
</termination>
  • 1) 你的自定义终止是做什么的? 我想了解用例以评估我们是否可以在未来的版本中开箱即用地支持它。
  • 2) 我们可以很容易地添加 customProperties 支持。看起来像这样:

    <termination>
      <terminationClass>org.foo.Bar</terminationClass>
      <customProperties>
        <barField>7</barField>
      </customerProperties>
    </termination>
    

    注意不需要 BarConfig class。 Create a jira for it and link it here.