Optaplanner评分腐败和基于时间的规则

时间:2015-03-17 10:13:36

标签: optaplanner

我的解决方案面临得分损坏的问题。 当我在FULL_ASSERT模式下以drools计算我的实体的软分数时,会发生这种情况。在“生产”模式中,分数损坏并未发生。

我试图计算涉及当前日期的比率。基本上像(现在 - start_date_of_my_entity)* priority_of_my_entity。结果是该实体的得分。

我尝试了一些方法来解决这个问题:在drools文件中,我有一个名为&#34的全局变量;现在"由名为" init"的规则初始化。该规则具有1000的显着性,以确保规则是第一个执行的规则。 但这也不起作用。 当我运行我的解决方案时,一切正常,直到变量" now"达到像XX的时间:YY:ZZ + 1。此时会出现分数损坏。

有堆栈跟踪:

10:19:00,007  INFO XXXXXXXXXXXXXXXXXX:153 - Score corruption: the workingScore (0hard/0medium/-188soft) is not the uncorruptedScore (0hard/0medium/-198soft) after completedAction (Entity(Customer1-19531312-50min)-Agent(19463312-TEST) => Agent(19463312-TEST)):
  The corrupted scoreDirector has 3 ConstraintMatch(s) which are in excess (and should not be there):
    com.package.solver/agentRatio/level2/[[Ljava.lang.Object;@105d99aa, Agent(19463312-TEST)]=-63
    com.package.solver/decalageEtPriorite/level2/[Entity(Customer2-19531332-23min)-Agent(19463312-TEST)]=-50
    com.package.solver/decalageEtPriorite/level2/[Entity(Customer1-19531312-50min)-Agent(19463312-TEST)]=-75
  The corrupted scoreDirector has 3 ConstraintMatch(s) which are missing:
    com.package.solver/agentRatio/level2/[[Ljava.lang.Object;@23739ca6, Agent(19463312-TEST)]=-63
    com.package.solver/decalageEtPriorite/level2/[Entity(Customer2-19531332-23min)-Agent(19463312-TEST)]=-55
    com.package.solver/decalageEtPriorite/level2/[Entity(Customer1-19531312-50min)-Agent(19463312-TEST)]=-80
  Check your score constraints.
10:19:00,007  INFO BasicPlumbingTermination:59 - Terminating solver early.
java.lang.IllegalStateException: Score corruption: the workingScore (0hard/0medium/-188soft) is not the uncorruptedScore (0hard/0medium/-198soft) after completedAction (Entity(Customer1-19531312-50min)-Agent(19463312-TEST) => Agent(19463312-TEST)):
  The corrupted scoreDirector has 3 ConstraintMatch(s) which are in excess (and should not be there):
    com.package.solver/agentRatio/level2/[[Ljava.lang.Object;@105d99aa, Agent(19463312-TEST)]=-63
    com.package.solver/decalageEtPriorite/level2/[Entity(Customer2-19531332-23min)-Agent(19463312-TEST)]=-50
    com.package.solver/decalageEtPriorite/level2/[Entity(Customer1-19531312-50min)-Agent(19463312-TEST)]=-75
  The corrupted scoreDirector has 3 ConstraintMatch(s) which are missing:
    com.package.solver/agentRatio/level2/[[Ljava.lang.Object;@23739ca6, Agent(19463312-TEST)]=-63
    com.package.solver/decalageEtPriorite/level2/[Entity(Customer2-19531332-23min)-Agent(19463312-TEST)]=-55
    com.package.solver/decalageEtPriorite/level2/[Entity(Customer1-19531312-50min)-Agent(19463312-TEST)]=-80
  Check your score constraints.
    at org.optaplanner.core.impl.score.director.AbstractScoreDirector.assertWorkingScoreFromScratch(AbstractScoreDirector.java:308)
    at org.optaplanner.core.impl.solver.scope.DefaultSolverScope.assertWorkingScoreFromScratch(DefaultSolverScope.java:118)
    at org.optaplanner.core.impl.phase.scope.AbstractPhaseScope.assertWorkingScoreFromScratch(AbstractPhaseScope.java:131)
    at org.optaplanner.core.impl.localsearch.decider.LocalSearchDecider.processMove(LocalSearchDecider.java:164)
    at org.optaplanner.core.impl.localsearch.decider.LocalSearchDecider.doMove(LocalSearchDecider.java:149)
    at org.optaplanner.core.impl.localsearch.decider.LocalSearchDecider.decideNextStep(LocalSearchDecider.java:121)
    at org.optaplanner.core.impl.localsearch.DefaultLocalSearchPhase.solve(DefaultLocalSearchPhase.java:66)
    at org.optaplanner.core.impl.solver.DefaultSolver.runPhases(DefaultSolver.java:193)
    at org.optaplanner.core.impl.solver.DefaultSolver.solve(DefaultSolver.java:157)

我认为问题来自于当我从一分钟跳到另一分钟时,得分不一样。 例如,从08:10:00开始的实体和优先级5:

  • 在08:00:59,得分为10 * 5 => 50
  • 在08:01:00,得分为9 * 5 => 45

该分数似乎是在08:00:59和08:01:00计算得分验证

此外,我发现移动是从当前代理到当前代理。这可以吗?

此外,堆栈跟踪涉及另一个规则" agentRatio"。我认为这是因为这个规则是基于当前计算分数的时间。这个规则同样存在问题。

你能帮我解决这个问题吗?

编辑:在尝试了几个潜在的解决方案之后,我仍然坚持这个问题。 我可以尝试的是添加一个表示时间的问题事实,并使用它来进行基于时间的计算。但是这个解决方案并没有让我满意。

1 个答案:

答案 0 :(得分:0)

我面临同样的问题,在我的情况下,当我将得分计算逻辑从Drools文件移动到我的java代码时,它就开始发生了,例如:

scoreHolder.addSoftConstraintMatch(kcontext,<complex expression>);

scoreHolder.addSoftConstraintMatch(kcontext,$myVariable.calculate());

根据this link,我无法做到。