public final class HardSoftScore extends AbstractScore<HardSoftScore> implements FeasibilityScore<HardSoftScore>
Score
is based on 2 levels of int constraints: hard and soft.
Hard constraints have priority over soft constraints.
Hard constraints determine feasibility.
This class is immutable.
Score
,
Serialized FormModifier and Type | Field and Description |
---|---|
static HardSoftScore |
ONE_HARD |
static HardSoftScore |
ONE_SOFT |
static HardSoftScore |
ZERO |
INIT_LABEL, initScore
Modifier and Type | Method and Description |
---|---|
HardSoftScore |
add(HardSoftScore addend)
Returns a Score whose value is (this + addend).
|
int |
compareTo(HardSoftScore other) |
HardSoftScore |
divide(double divisor)
Returns a Score whose value is (this / divisor).
|
boolean |
equals(Object o) |
int |
getHardScore()
The total of the broken negative hard constraints and fulfilled positive hard constraints.
|
int |
getSoftScore()
The total of the broken negative soft constraints and fulfilled positive soft constraints.
|
int |
hashCode() |
boolean |
isCompatibleArithmeticArgument(Score otherScore) |
boolean |
isFeasible()
A
PlanningSolution is feasible if it has no broken hard constraints
and Score.isSolutionInitialized() is true. |
HardSoftScore |
multiply(double multiplicand)
Returns a Score whose value is (this * multiplicand).
|
HardSoftScore |
negate()
Returns a Score whose value is (- this).
|
static HardSoftScore |
of(int hardScore,
int softScore) |
static HardSoftScore |
ofHard(int hardScore) |
static HardSoftScore |
ofSoft(int softScore) |
static HardSoftScore |
ofUninitialized(int initScore,
int hardScore,
int softScore) |
static HardSoftScore |
parseScore(String scoreString) |
HardSoftScore |
power(double exponent)
Returns a Score whose value is (this ^ exponent).
|
HardSoftScore |
subtract(HardSoftScore subtrahend)
Returns a Score whose value is (this - subtrahend).
|
HardSoftScore |
toInitializedScore()
For example
-7init/0hard/-8soft returns 0hard/-8soft . |
Number[] |
toLevelNumbers()
Returns an array of numbers representing the Score.
|
String |
toShortString()
Like
Object.toString() , but trims score levels which have a zero weight. |
String |
toString() |
static HardSoftScore |
valueOf(int hardScore,
int softScore)
Deprecated.
in favor of
of(int, int) |
static HardSoftScore |
valueOfUninitialized(int initScore,
int hardScore,
int softScore)
Deprecated.
in favor of
ofUninitialized(int, int, int) |
HardSoftScore |
withInitScore(int newInitScore)
For example
0hard/-8soft with -7 returns -7init/0hard/-8soft . |
assertNoInitScore, buildScorePattern, buildShortString, getInitPrefix, getInitScore, isSolutionInitialized, parseInitScore, parseLevelAsBigDecimal, parseLevelAsDouble, parseLevelAsInt, parseLevelAsLong, parseScoreTokens
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
getInitScore, isSolutionInitialized
public static final HardSoftScore ZERO
public static final HardSoftScore ONE_HARD
public static final HardSoftScore ONE_SOFT
public static HardSoftScore parseScore(String scoreString)
public static HardSoftScore ofUninitialized(int initScore, int hardScore, int softScore)
@Deprecated public static HardSoftScore valueOfUninitialized(int initScore, int hardScore, int softScore)
ofUninitialized(int, int, int)
public static HardSoftScore of(int hardScore, int softScore)
@Deprecated public static HardSoftScore valueOf(int hardScore, int softScore)
of(int, int)
public static HardSoftScore ofHard(int hardScore)
public static HardSoftScore ofSoft(int softScore)
public int getHardScore()
public int getSoftScore()
In a normal score comparison, the soft score is irrelevant if the 2 scores don't have the same hard score.
public HardSoftScore toInitializedScore()
Score
-7init/0hard/-8soft
returns 0hard/-8soft
.toInitializedScore
in interface Score<HardSoftScore>
Score.getInitScore()
is 0
.public HardSoftScore withInitScore(int newInitScore)
Score
0hard/-8soft
with -7
returns -7init/0hard/-8soft
.withInitScore
in interface Score<HardSoftScore>
newInitScore
- always negative (except in statistical calculations), 0 if all planning variables are initializedScore.getInitScore()
is set to newInitScore
public boolean isFeasible()
FeasibilityScore
PlanningSolution
is feasible if it has no broken hard constraints
and Score.isSolutionInitialized()
is true.isFeasible
in interface FeasibilityScore<HardSoftScore>
Score.getInitScore()
is 0.public HardSoftScore add(HardSoftScore addend)
Score
add
in interface Score<HardSoftScore>
addend
- value to be added to this Scorepublic HardSoftScore subtract(HardSoftScore subtrahend)
Score
subtract
in interface Score<HardSoftScore>
subtrahend
- value to be subtracted from this Scorepublic HardSoftScore multiply(double multiplicand)
Score
Math.floor(double)
).
If the implementation has a scale/precision, then the unspecified scale/precision of the double multiplicand should have no impact on the returned scale/precision.
multiply
in interface Score<HardSoftScore>
multiplicand
- value to be multiplied by this Score.public HardSoftScore divide(double divisor)
Score
Math.floor(double)
).
If the implementation has a scale/precision, then the unspecified scale/precision of the double divisor should have no impact on the returned scale/precision.
divide
in interface Score<HardSoftScore>
divisor
- value by which this Score is to be dividedpublic HardSoftScore power(double exponent)
Score
Math.floor(double)
).
If the implementation has a scale/precision, then the unspecified scale/precision of the double exponent should have no impact on the returned scale/precision.
power
in interface Score<HardSoftScore>
exponent
- value by which this Score is to be poweredpublic HardSoftScore negate()
Score
negate
in interface Score<HardSoftScore>
public Number[] toLevelNumbers()
Score
When rounding is needed, each rounding should be floored (as defined by Math.floor(double)
).
The length of the returned array must be stable for a specific Score
implementation.
For example: -0hard/-7soft
returns new int{-0, -7}
The level numbers do not contain the Score.getInitScore()
.
For example: -3init/-0hard/-7soft
also returns new int{-0, -7}
toLevelNumbers
in interface Score<HardSoftScore>
ScoreDefinition.fromLevelNumbers(int, Number[])
public int compareTo(HardSoftScore other)
compareTo
in interface Comparable<HardSoftScore>
public String toShortString()
Score
Object.toString()
, but trims score levels which have a zero weight.
For example 0hard/-258soft returns -258soft.
Do not use this format to persist information as text, use Object.toString()
instead,
so it can be parsed reliably.
toShortString
in interface Score<HardSoftScore>
public boolean isCompatibleArithmeticArgument(Score otherScore)
isCompatibleArithmeticArgument
in interface Score<HardSoftScore>
otherScore
- never nullScore.add(Score)
, Score.subtract(Score)
and Comparable.compareTo(Object)
.Copyright © 2006–2020 JBoss by Red Hat. All rights reserved.