Search code examples
optaplanner

How is the scoreDirector accessed when using the autowired SolverManager with Optaplanner?


I'm using the autowired SolverManager with the optaplanner-spring-boot-starter jar

@Autowired
    private SolverManager<BatchSolution, UUID> solverManager;

And would like to report on the constraints using:

Map<Object, Indictment> indictmentMap = guiScoreDirector.getIndictmentMap();

In previous versions I used:

ScoreDirectorFactory<Solution_> scoreDirectorFactory = solver.getScoreDirectorFactory();
guiScoreDirector = scoreDirectorFactory.buildScoreDirector();

And can't see how to access the scoreDirector through the solverManager in the examples.


Solution

  • We're planning to expose this functionality in the ScoreManager:

    @Autowired
    ScoreManager<MySolution> scoreManager;
    

    But that API doesn't support getIndictmentMap(Solution_) yet. This is an API gap.

    Meanwhile, just workaround it, by autowiring the SolverFactory too and use ScolverFactory.getScoreDirectorFactory() until we deprecate that once the ScoreManager API replaces that functionality.