Solver.solve() returns seeming random solution and score, not best

OptaPlanner was (of course) working correctly. I had a conceptual misunderstanding.

I was focusing on the Scores I was calculating, and not focusing on the scores that OptaPlanner was actually using. OptaPlanner can augment the Scores that are returned from the scoring function by adding an “init” value representing the number of uninitialized @PlanningVariables. Scores that had 0 Hard and Medium scores may have looked reasonable, but may still be uninitialized, which takes precedence over Hard/Medium/Soft values.

Once the duration of the simulation was set sufficiently high, all @PlanningVariables were being set. No scores with init of 0 were created after that, and completed optimized solutions (whether infeasible or feasible) were computed.

See the steps Geoffrey outlined for debugging. If you are using JDK logging, you may have to add slf4j-api and slf4j-jdk14 jars to your path.

See the documentation, section 2.3.6 “Gather the domain objects in a planning solution”, where it describes the difference between an “uninitialized”, “infeasible”, and “feasible” solution.

Note: It appears that the solver does not notify SolverEventListeners when the best solution so far is uninitialized.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top