Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OptaPlanner's mythical score corruption

I use incremental score calculator for my model. After several hours/days of optimization in "full assert" mode Score corruption exception thrown out:

java.lang.IllegalStateException: Score corruption: the workingScore (-86591/-2765/-422/-591) is not the uncorruptedScore (-86591/-2873/-422/-591) after completedAction [...]:
Uncorrupted: Score calculator 3718238 [schedule=Schedule6422-2015-04-16T09:47:36.932[-86591/-2873/-422/-591], prioritiesScore=-422, timelineGapsScore=-2873, requirementGapsScore=-86591, timelineVersionsScore=-591]
Corrupted: Score calculator 3717237 [schedule=Schedule6422-2015-04-16T09:47:36.932[-86591/-2873/-422/-591], prioritiesScore=-422, timelineGapsScore=-2873, requirementGapsScore=-86591, timelineVersionsScore=-591]

That's scores differs in parameter timelineGapsScore. Score instance is created from score calculator object fields prioritiesScore, timelineGapsScore, requirementGapsScore and timelineVersionsScore. Going by log, instances of both scores are equivalent in these fields, but optaplanner engine find differences (-86591/-2765/-422/-591) vs (-86591/-2873/-422/-591). How it's possible?

I suspect references leaks on solution cloning (it's specific implementation and do deep copying), but careful code check doesn't show such errors.

UPD: I forgot to mention: optaplanner runs in daemon mode, model is capable to change facts in real-time. So I have suspicion on race conditions in model. But I don't know how changes injection realized under hood of optaplanner (it isn't enough info in docs).

like image 754
injecto Avatar asked Nov 01 '22 06:11

injecto


1 Answers

"When a Solution changes, incremental score calculation (AKA delta based score calculation), will calculate the delta with the previous state to find the new Score, instead of recalculating the entire score on every solution evaluation.

For example, if a single queen A moves from row 1 to 2, it won't bother to check if queen B and C can attack each other, since neither of them changed."

enter image description here

Score corruption happens when the incremental score and the real score (= uncorrupted score) get out of sync.

There can be several causes. It could even be a bug in Drools if you're using Drools score calculation. If you can isolate it and file a jira with a reproducer, then we give usually look at it quickly.

Isolation means (in this order!):

  1. remove all score rules that aren't needed to reproduce it
  2. remove all planning entities that aren't needed to reproduce it
  3. remove all steps that aren't needed to reproduce it. See Termination.stepCountLimit to save the solution just before it goes wrong and then solve starting from that solution
  4. (optional) remove all moves that aren't needed to reproduce it. Turn on Trace log. Thats hard to do without hacking optaplanner, so we usually do this step.
like image 110
Geoffrey De Smet Avatar answered Nov 04 '22 08:11

Geoffrey De Smet