禁用constraintMatchEnabled(false)时,不应调用此方法

时间:2014-09-23 10:29:55

标签: optaplanner

我正在尝试在optaplnner中使用得分导演,如:

 Solver solver = solverFactory.buildSolver();
 ScoreDirectorFactory scoreDirectorFactory = solver.getScoreDirectorFactory();
 ScoreDirector guiScoreDirector = scoreDirectorFactory.buildScoreDirector();

 for (ConstraintMatchTotal constraintMatchTotal :guiScoreDirector.getConstraintMatchTotals()) {

 }

但是当我调用getConstraintMatchTotals方法时,我得到以下异常:

 When constraintMatchEnabled (false) is disabled, this method should not be called.. Stacktrace follows:
    Message: When constraintMatchEnabled (false) is disabled, this method should not be called.
        Line | Method
    ->>  140 | getConstraintMatchTotals in org.optaplanner.core.impl.score.director.AbstractScoreDirector
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
    |     57 | solve                    in com.volcare.optaplanner.TaskPlanningController
    |     97 | index . . . . . . . . .  in     ''
    |    200 | doFilter                 in grails.plugin.cache.web.filter.PageFragmentCachingFilter
    |     63 | doFilter . . . . . . . . in grails.plugin.cache.web.filter.AbstractFilter
    |   1145 | runWorker                in java.util.concurrent.ThreadPoolExecutor
    |    615 | run . . . . . . . . . .  in java.util.concurrent.ThreadPoolExecutor$Worker
    ^    744 | run                      in java.lang.Thread

solverconfig.xml

  <!-- Score configuration -->
  <scoreDirectorFactory>
    <scoreDefinitionType>HARD_SOFT_BIG_DECIMAL</scoreDefinitionType>
    <simpleScoreCalculatorClass>com.volcare.optaplanner.TaskPlanScoreCalculator</simpleScoreCalculatorClass>
    <!-- <scoreDrl>/taskPlanningScoreRules.drl</scoreDrl> -->
  </scoreDirectorFactory>

1 个答案:

答案 0 :(得分:0)

SimpleScoreCalculator(现在称为EasyScoreCalculator)不支持约束匹配。解决方案:

  1. 使用Drools得分计算(使用<scoreDrl>代替) 您的配置中为<simpleScoreCalculatorClass>。 Drools规则 引擎很聪明,不仅可以计算得分,还可以 通过告诉你约束匹配来解释它。

  2. 对于IncrementalScoreCalculator,我们最近添加了界面 ConstraintMatchAwareIncrementalScoreCalculator,因此用户可以公开它们(但与Drools不同,它不仅仅是神奇地工作 - 还有工作要做)。我认为我们也应该支持类似的interfacef或简易分数计算(ConstraintMatchAwareEasyScoreCalculator)。

  3. 注意:您收到的错误消息不清楚,但我在6.2.0.Beta2中改进了该错误消息。一旦发布,请检查错误消息是否更清晰。