Search code examples
optaplanner

Exception when using a HardMediumSoftScore in a constraint in OptaPlanner


I am trying to use a HardMediumSoftScore in a constraint but I get the following exception:

java.lang.IllegalArgumentException: The constraintWeight (1hard/0medium/0soft) of class (class org.optaplanner.core.api.score.buildin.hardmediumsoft.HardMediumSoftScore) for constraintPackage (xxx) and constraintName (xxx) must be of the scoreClass (class org.optaplanner.core.api.score.buildin.hardsoft.HardSoftScore).

I cannot see anything in the documentation as to why I cannot use a medium score, or that I need to do anything different over using a hard or soft score.

I have the same problem using v8.9.1-FINAL and v8.10.0-FINAL.

Any ideas? Thanks in advance.


Solution

  • Some part of your planning domain will contain a reference to HardSoftScore. From this exception message, which is coming from constraints, I'm guessing that your planning solution is using HardSoftScore and not HardMediumSoftScore.

    You are free to use either, but you need to consistently use one or the other.