oy321
oy321

Reputation: 397

How to get the selected move when the best solution has been updated for OptaPlanner?

We know that OptaPlanner does multiple steps' calculations before selecting one step which generating the highest score to update the best solution, as the debug log shows e.g. [main] DEBUG o.o.c.i.c.DefaultConstructionHeuristicSolverPhase - Step index (1147), time spend (4381), score (0hard/80504soft), selected move count (15) for constructing step...

I am trying to get the move which was selected (or at least to get a notification) so that I can capture some intermediate calculation results. Apparently printing out all calculation results for each single step is not feasible as many of them were not selected.

I was looking at the BestSolutionChangedEvent method but seems it might not fit my purpose as per this thread: How to know Optaplanner solving has ended?

Is there any idea of how to achieve that? Thanks in advance.

Upvotes: 0

Views: 471

Answers (1)

Geoffrey De Smet
Geoffrey De Smet

Reputation: 27312

Before answering the actual question, is this really useful? Suppose the follow scenario:

  • step 0, new best score after doing move 0
  • step 1, new best score after doing move 1
  • step 2, same best score after doing move 2
  • step 3, same best score after doing move 3
  • step 4, new best score after doing move 4

Now, what do you get if you just take the move that leads to the new best solution?

  • new best solution event A after step 0, giving move 0
  • new best solution event B after step 1, giving move 1
  • new best solution event C after step 4, giving move 4 // BUT without doing move 2 and move 3 we wouldn't have been in this solution in the first place.

So that isn't useful, unless of course you just want to understand which moves are good. But in that case, take a look at the Benchmarker's Picked move type best score diff over time statistic, new in 6.2.

enter image description here

Now to answer your question :) There's no public API to do it, but you can use the internal (non-backward compatible) implementation classes, as done in this class.

Upvotes: 1

Related Questions