Show Table of Contents
5.2. Choose a Score Definition
Each
Score implementation also has a ScoreDefinition implementation. For example: SimpleScore is defined by SimpleScoreDefinition.
Note
To properly write a
Score to database (with JPA/Hibernate) or to XML/JSON (with XStream/JAXB), see the integration chapter.
5.2.1. SimpleScore
A
SimpleScore has a single int value, for example -123. It has a single score level.
<scoreDirectorFactory>
<scoreDefinitionType>SIMPLE</scoreDefinitionType>
...
</scoreDirectorFactory>
Variants of this
scoreDefinitionType:
SIMPLE_LONG: UsesSimpleLongScorewhich has alongvalue instead of anintvalue.SIMPLE_DOUBLE: UsesSimpleDoubleScorewhich has adoublevalue instead of anintvalue. Not recommended to use.SIMPLE_BIG_DECIMAL: UsesSimpleBigDecimalScorewhich has aBigDecimalvalue instead of anintvalue.
5.2.2. HardSoftScore (Recommended)
A
HardSoftScore has a hard int value and a soft int value, for example -123hard/-456soft. It has 2 score levels (hard and soft).
<scoreDirectorFactory>
<scoreDefinitionType>HARD_SOFT</scoreDefinitionType>
...
</scoreDirectorFactory>
Variants of this
scoreDefinitionType:
HARD_SOFT_LONG: UsesHardSoftLongScorewhich haslongvalues instead ofintvalues.HARD_SOFT_DOUBLE: UsesHardSoftDoubleScorewhich hasdoublevalues instead ofintvalues. Not recommended to use.HARD_SOFT_BIG_DECIMAL: UsesHardSoftBigDecimalScorewhich hasBigDecimalvalues instead ofintvalues.
5.2.3. HardMediumSoftScore
A
HardMediumSoftScore which has a hard int value, a medium int value and a soft int value, for example -123hard/-456medium/-789soft. It has 3 score levels (hard, medium and soft).
<scoreDirectorFactory>
<scoreDefinitionType>HARD_MEDIUM_SOFT</scoreDefinitionType>
...
</scoreDirectorFactory>
Variants of this
scoreDefinitionType:
HARD_MEDIUM_SOFT_LONG: UsesHardMediumSoftLongScorewhich haslongvalues instead ofintvalues.
5.2.4. BendableScore
A
BendableScore has a configurable number of score levels. It has an array of hard int values and an array of soft int value, for example with 2 hard levels and 3 soft levels, the score can be -123/-456/-789/-012/-345.
<scoreDirectorFactory>
<scoreDefinitionType>BENDABLE</scoreDefinitionType>
<bendableHardLevelsSize>2</bendableHardLevelsSize>
<bendableSoftLevelsSize>3</bendableSoftLevelsSize>
...
</scoreDirectorFactory>
The number of hard and soft score levels needs to be set at configuration time: it's not flexible to change during solving.
Variants of this
scoreDefinitionType:
BENDABLE_Long: UsesBendableLongScorewhich haslongvalues instead ofintvalues.BENDABLE_BIG_DECIMAL: UsesBendableBigDecimalScorewhich hasBigDecimalvalues instead ofintvalues.
5.2.5. Implementing a Custom Score
The
ScoreDefinition interface defines the score representation.
To implement a custom
Score, you'll also need to implement a custom ScoreDefinition. Extend AbstractScoreDefinition (preferably by copy pasting HardSoftScoreDefinition) and start from there.
Then hook your custom
ScoreDefinition in your SolverConfig.xml:
<scoreDirectorFactory>
<scoreDefinitionClass>...MyScoreDefinition</scoreDefinitionClass>
...
</scoreDirectorFactory>
Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.