Search code examples
optaplanner

How to implement Constraint Match Total in VehicleRouting example


I'm trying to explain the score of the VehicleRouting example with GUI, but i don't understand this: "Do not attempt to parse this string or use it in your UI or exposed services. Instead use the ConstraintMatch API below and do it properly." What is the ConstraintMatch API, and how can I implement it with the GUI example?

I only try to print solver.explainBestScore(), but it says to "Do not attempt to parse this string or use it in your UI or exposed services".


Solution

  • Take a look at the rest of that javadoc:

     * Do not parse this string.
     * Instead, to provide this information in a UI or a service, use {@link #getScoreDirectorFactory()}
     * to retrieve {@link ScoreDirector#getConstraintMatchTotals()} and {@link ScoreDirector#getIndictmentMap()}
     * and convert those into a domain specific API.
    

    In the documentation, do ctrl-f "getConstraintMatchTotals()" and you'll end up at the section "Explaining the score" which documents how to do that.