TimefoldAI / timefold-solver

The open source Solver AI for Java, Python and Kotlin to optimize scheduling and routing. Solve the vehicle routing problem, employee rostering, task assignment, maintenance scheduling and other planning problems.
https://timefold.ai
Apache License 2.0
939 stars 80 forks source link

ScoreAnalysis should not fail fast if the solver is unintialized #903

Closed ge0ffrey closed 3 months ago

ge0ffrey commented 3 months ago

It's a pain as a user to have to work around this in practice:

java.lang.java.lang.IllegalArgumentException: java.lang.IllegalArgumentException: Cannot analyze solution (EmployeeSchedule@1198532872) as it is not initialized (-2828init/0hard/0soft).
Maybe run the solver first?

The only way to work around it is to update the solution first, calculate the score, check if its initialized and only then run the score analysis. All that code is boilerplate code. But if allowsUnassigned=false (default), then this boilerplate code is needed, just in case a CH doesn't finish on one particular dataset. Let's make that boilerplate code unneeded.

ge0ffrey commented 3 months ago

Proposal A put it into a constraintAnalysis

return new ScoreAnalysis {
   new ConstraintAnalysis { "Init score", HardSoftScore.ofInit(7) }
   ...
}

Con: the "init score" might be a valid constraint id already

Propsoal B add a field