uninitializedEntityFilter的详细示例

时间:2013-10-21 08:46:45

标签: drools optaplanner

我已将计划变量设置为可为空。但是使用这个构造启发式将变量初始化为空值,我认为这是计算最优解的浪费时间。从文档中,您可以使用uninitializedEntityFilter覆盖它。但它没有显示实际的UninitializedTaskFilter.class。这堂课的内容是什么?谢谢!

1 个答案:

答案 0 :(得分:0)

如果nullable=true,您可能希望得分会对此造成惩罚,因此OptaPlanner会避免将变量设置为null

nullable=false的唯一区别在于它不是内置硬约束,因为在某些情况下 - 例如过度约束规划 - 最好将其保留为空,而不是将其初始化到与另一个分配冲突的地方

将变量置于null的另一个用例是,如果您有多个变量,并且某些变量在某些情况下不适用。但一般来说,子类化是一种更好的方法(现在支持6)

回答你的问题:SelectionFilter。 注意:uninitializedEntityFilter已在6.0.0.Alpha7中重命名为reinitializeVariableEntityFilter,以更好地反映其使用情况(文档也已明确说明)。我强烈建议更新到最新和最好的版本6.0.0.CR5(只需按照升级配方),因为它有许多与nullable等相关的改进/错误修正。

来自它的javadoc:

/**
 * Construction heuristics only change reinitializable planning variables.
 * Non reinitializable planning variable is ignored by construction heuristics.
 * This is especially useful in repeated planning use cases,
 * in which starting from scratch would waste previous results and time.
 * <p/>
 * If no {@link #reinitializeVariableEntityFilter} is specified,
 * the default considers an entity uninitialized for a variable if its value is null
 * (even if {@link #nullable()} is true).
 * <p/>
 * The method {@link SelectionFilter#accept(ScoreDirector, Object)}
 * returns false if the selection entity should be reinitialized for this variable
 * and it returns true if the selection entity should not be reinitialized for this variable
 * @return {@link NullReinitializeVariableEntityFilter} when it is null (workaround for annotation limitation)
 */
Class<? extends SelectionFilter> reinitializeVariableEntityFilter()
        default NullReinitializeVariableEntityFilter.class;