Nikola Atanasov
Nikola Atanasov

Reputation: 573

Debugging Optaplanner Rules in Drools

After the implementation of some of the rules for my project, i did a "ScoreConsistencyCheck" to ensure myself that the rules were implemented correctly.

"ScoreConsistencyCheck" meaning implementing my own Java method that would be called after i either terminate the solving early, or it terminated via configuration, that would output the expected score. The parameter of this method is a Solution instance, based on what the state of the solution is the expected score is calculated, and then it is compared to the score that comes from the "score" variable from the Solution instance.

When i use FULL_ASSERT, it doesn't throw a ScoreCorruption exception, but when i try it this way, i sometimes get a score difference at a particular step either in the construction heuristic or local search. My guess is because OptaPlanner does not know what the expected score based on the solution is all it cares about in FULL_ASSERT is the step score to be the same as the score that is recalculated after the undo move is done.

So because the "ScoreConsistencyCheck" is only called after the solving has ended, i can't really deduce what case is causing a problem(if it is causing any) , because the move and step in which this occurred is unknown.

Because of this i'm looking for a way that will show me my expected score(from the "ScoreConsistencyCheck") after each move, so i can compare it with the OptaPlanner one, and find the cases that are missed in the calculations. To do this, i need a way to get the working solution after each move.

After some searching i wasn't able to find much. I did however, find that in Optaplanner 7.0.0 Beta there is a ScoreVerifier (using Optaplanner 6.4.0) but the case with that is:

My questions here are:

  1. How to get the workingSolution after each move, and use it for the check?
  2. Is there a feature in Optaplanner 6.4.0 that will allow me to do this?
  3. If there isn't a feature, is there a possible workaround?
  4. Is there a better way to check the score consistency of the Rules?

Upvotes: 1

Views: 390

Answers (1)

Geoffrey De Smet
Geoffrey De Smet

Reputation: 27312

  1. Yes, <assertionScoreDirectorFactory> (see docs). Use that in combination with FULL_ASSERT and you'll have a more isolated view on where score corruption first started.

Upvotes: 1

Related Questions