public final class HardSoftBigDecimalScore extends AbstractScore<HardSoftBigDecimalScore> implements FeasibilityScore<HardSoftBigDecimalScore>
Score
is based on 2 levels of BigDecimal
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 HardSoftBigDecimalScore |
ZERO |
INIT_LABEL, initScore
Modifier and Type | Method and Description |
---|---|
HardSoftBigDecimalScore |
add(HardSoftBigDecimalScore augment)
Returns a Score whose value is (this + augment).
|
int |
compareTo(HardSoftBigDecimalScore other) |
HardSoftBigDecimalScore |
divide(double divisor)
Returns a Score whose value is (this / divisor).
|
boolean |
equals(Object o) |
BigDecimal |
getHardScore()
The total of the broken negative hard constraints and fulfilled positive hard constraints.
|
BigDecimal |
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. |
HardSoftBigDecimalScore |
multiply(double multiplicand)
Returns a Score whose value is (this * multiplicand).
|
HardSoftBigDecimalScore |
negate()
Returns a Score whose value is (- this).
|
static HardSoftBigDecimalScore |
parseScore(String scoreString) |
HardSoftBigDecimalScore |
power(double exponent)
Returns a Score whose value is (this ^ exponent).
|
HardSoftBigDecimalScore |
subtract(HardSoftBigDecimalScore subtrahend)
Returns a Score whose value is (this - subtrahend).
|
HardSoftBigDecimalScore |
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 HardSoftBigDecimalScore |
valueOf(BigDecimal hardScore,
BigDecimal softScore) |
static HardSoftBigDecimalScore |
valueOfUninitialized(int initScore,
BigDecimal hardScore,
BigDecimal softScore) |
HardSoftBigDecimalScore |
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 HardSoftBigDecimalScore ZERO
public static HardSoftBigDecimalScore parseScore(String scoreString)
public static HardSoftBigDecimalScore valueOfUninitialized(int initScore, BigDecimal hardScore, BigDecimal softScore)
public static HardSoftBigDecimalScore valueOf(BigDecimal hardScore, BigDecimal softScore)
public BigDecimal getHardScore()
public BigDecimal getSoftScore()
In a normal score comparison, the soft score is irrelevant if the 2 scores don't have the same hard score.
public HardSoftBigDecimalScore toInitializedScore()
Score
-7init/0hard/-8soft
returns 0hard/-8soft
.toInitializedScore
in interface Score<HardSoftBigDecimalScore>
Score.getInitScore()
is 0
.public HardSoftBigDecimalScore withInitScore(int newInitScore)
Score
0hard/-8soft
with -7
returns -7init/0hard/-8soft
.withInitScore
in interface Score<HardSoftBigDecimalScore>
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<HardSoftBigDecimalScore>
Score.getInitScore()
is 0.public HardSoftBigDecimalScore add(HardSoftBigDecimalScore augment)
Score
add
in interface Score<HardSoftBigDecimalScore>
augment
- value to be added to this Scorepublic HardSoftBigDecimalScore subtract(HardSoftBigDecimalScore subtrahend)
Score
subtract
in interface Score<HardSoftBigDecimalScore>
subtrahend
- value to be subtracted from this Scorepublic HardSoftBigDecimalScore 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<HardSoftBigDecimalScore>
multiplicand
- value to be multiplied by this Score.public HardSoftBigDecimalScore 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<HardSoftBigDecimalScore>
divisor
- value by which this Score is to be dividedpublic HardSoftBigDecimalScore 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<HardSoftBigDecimalScore>
exponent
- value by which this Score is to be poweredpublic HardSoftBigDecimalScore negate()
Score
negate
in interface Score<HardSoftBigDecimalScore>
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<HardSoftBigDecimalScore>
ScoreDefinition.fromLevelNumbers(int, Number[])
public int compareTo(HardSoftBigDecimalScore other)
compareTo
in interface Comparable<HardSoftBigDecimalScore>
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<HardSoftBigDecimalScore>
public boolean isCompatibleArithmeticArgument(Score otherScore)
isCompatibleArithmeticArgument
in interface Score<HardSoftBigDecimalScore>
otherScore
- never nullScore.add(Score)
, Score.subtract(Score)
and Comparable.compareTo(Object)
.Copyright © 2006–2017 JBoss by Red Hat. All rights reserved.