public final class BendableBigDecimalScore extends AbstractBendableScore<BendableBigDecimalScore> implements FeasibilityScore<BendableBigDecimalScore>
Score
is based on n levels of BigDecimal
constraints.
The number of levels is bendable at configuration time.
This class is immutable.
The getHardLevelsSize()
and getSoftLevelsSize()
must be the same as in the
BendableScoreDefinition
used.
Score
,
Serialized FormHARD_LABEL, LEVEL_SUFFIXES, SOFT_LABEL
INIT_LABEL, initScore
Modifier | Constructor and Description |
---|---|
protected |
BendableBigDecimalScore(int initScore,
BigDecimal[] hardScores,
BigDecimal[] softScores) |
Modifier and Type | Method and Description |
---|---|
BendableBigDecimalScore |
add(BendableBigDecimalScore addend)
Returns a Score whose value is (this + addend).
|
int |
compareTo(BendableBigDecimalScore other) |
BendableBigDecimalScore |
divide(double divisor)
Returns a Score whose value is (this / divisor).
|
boolean |
equals(Object o) |
int |
getHardLevelsSize()
The sum of this and
AbstractBendableScore.getSoftLevelsSize() equals AbstractBendableScore.getLevelsSize() . |
BigDecimal |
getHardOrSoftScore(int index) |
BigDecimal |
getHardScore(int index) |
BigDecimal[] |
getHardScores() |
int |
getLevelsSize() |
int |
getSoftLevelsSize()
The sum of
AbstractBendableScore.getHardLevelsSize() and this equals AbstractBendableScore.getLevelsSize() . |
BigDecimal |
getSoftScore(int index) |
BigDecimal[] |
getSoftScores() |
int |
hashCode() |
boolean |
isCompatibleArithmeticArgument(Score otherScore) |
boolean |
isFeasible()
A
PlanningSolution is feasible if it has no broken hard constraints
and Score.isSolutionInitialized() is true. |
BendableBigDecimalScore |
multiply(double multiplicand)
Returns a Score whose value is (this * multiplicand).
|
BendableBigDecimalScore |
negate()
Returns a Score whose value is (- this).
|
static BendableBigDecimalScore |
of(BigDecimal[] hardScores,
BigDecimal[] softScores)
Creates a new
BendableBigDecimalScore . |
static BendableBigDecimalScore |
ofHard(int hardLevelsSize,
int softLevelsSize,
int hardLevel,
BigDecimal hardScore)
Creates a new
BendableBigDecimalScore . |
static BendableBigDecimalScore |
ofSoft(int hardLevelsSize,
int softLevelsSize,
int softLevel,
BigDecimal softScore)
Creates a new
BendableBigDecimalScore . |
static BendableBigDecimalScore |
ofUninitialized(int initScore,
BigDecimal[] hardScores,
BigDecimal[] softScores)
Creates a new
BendableBigDecimalScore . |
static BendableBigDecimalScore |
parseScore(String scoreString) |
BendableBigDecimalScore |
power(double exponent)
Returns a Score whose value is (this ^ exponent).
|
BendableBigDecimalScore |
subtract(BendableBigDecimalScore subtrahend)
Returns a Score whose value is (this - subtrahend).
|
BendableBigDecimalScore |
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() |
void |
validateCompatible(BendableBigDecimalScore other) |
static BendableBigDecimalScore |
valueOf(BigDecimal[] hardScores,
BigDecimal[] softScores)
Deprecated.
in favor of
of(BigDecimal[], BigDecimal[]) |
static BendableBigDecimalScore |
valueOfUninitialized(int initScore,
BigDecimal[] hardScores,
BigDecimal[] softScores)
Deprecated.
in favor of
ofUninitialized(int, BigDecimal[], BigDecimal[]) |
BendableBigDecimalScore |
withInitScore(int newInitScore)
For example
0hard/-8soft with -7 returns -7init/0hard/-8soft . |
static BendableBigDecimalScore |
zero(int hardLevelsSize,
int softLevelsSize)
Creates a new
BendableBigDecimalScore . |
buildBendableShortString, parseBendableScoreTokens
assertNoInitScore, buildScorePattern, buildShortString, getInitPrefix, getInitScore, isSolutionInitialized, parseInitScore, parseLevelAsBigDecimal, parseLevelAsDouble, parseLevelAsInt, parseLevelAsLong, parseScoreTokens
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
getInitScore, isSolutionInitialized
protected BendableBigDecimalScore(int initScore, BigDecimal[] hardScores, BigDecimal[] softScores)
initScore
- see Score.getInitScore()
hardScores
- never nullsoftScores
- never nullpublic static BendableBigDecimalScore parseScore(String scoreString)
scoreString
- never nullpublic static BendableBigDecimalScore ofUninitialized(int initScore, BigDecimal[] hardScores, BigDecimal[] softScores)
BendableBigDecimalScore
.initScore
- see Score.getInitScore()
hardScores
- never null, never change that array afterwards: it must be immutablesoftScores
- never null, never change that array afterwards: it must be immutable@Deprecated public static BendableBigDecimalScore valueOfUninitialized(int initScore, BigDecimal[] hardScores, BigDecimal[] softScores)
ofUninitialized(int, BigDecimal[], BigDecimal[])
public static BendableBigDecimalScore of(BigDecimal[] hardScores, BigDecimal[] softScores)
BendableBigDecimalScore
.hardScores
- never null, never change that array afterwards: it must be immutablesoftScores
- never null, never change that array afterwards: it must be immutable@Deprecated public static BendableBigDecimalScore valueOf(BigDecimal[] hardScores, BigDecimal[] softScores)
of(BigDecimal[], BigDecimal[])
public static BendableBigDecimalScore zero(int hardLevelsSize, int softLevelsSize)
BendableBigDecimalScore
.hardLevelsSize
- at least 0softLevelsSize
- at least 0public static BendableBigDecimalScore ofHard(int hardLevelsSize, int softLevelsSize, int hardLevel, BigDecimal hardScore)
BendableBigDecimalScore
.hardLevelsSize
- at least 0softLevelsSize
- at least 0hardLevel
- at least 0, less than hardLevelsSizehardScore
- never nullpublic static BendableBigDecimalScore ofSoft(int hardLevelsSize, int softLevelsSize, int softLevel, BigDecimal softScore)
BendableBigDecimalScore
.hardLevelsSize
- at least 0softLevelsSize
- at least 0softLevel
- at least 0, less than softLevelsSizesoftScore
- never nullpublic BigDecimal[] getHardScores()
public BigDecimal[] getSoftScores()
public int getHardLevelsSize()
AbstractBendableScore
AbstractBendableScore.getSoftLevelsSize()
equals AbstractBendableScore.getLevelsSize()
.getHardLevelsSize
in class AbstractBendableScore<BendableBigDecimalScore>
>= 0
and <
AbstractBendableScore.getLevelsSize()
public BigDecimal getHardScore(int index)
index
- 0 <= index <
getHardLevelsSize()
public int getSoftLevelsSize()
AbstractBendableScore
AbstractBendableScore.getHardLevelsSize()
and this equals AbstractBendableScore.getLevelsSize()
.getSoftLevelsSize
in class AbstractBendableScore<BendableBigDecimalScore>
>= 0
and <
AbstractBendableScore.getLevelsSize()
public BigDecimal getSoftScore(int index)
index
- 0 <= index <
getSoftLevelsSize()
public BendableBigDecimalScore toInitializedScore()
Score
-7init/0hard/-8soft
returns 0hard/-8soft
.toInitializedScore
in interface Score<BendableBigDecimalScore>
Score.getInitScore()
is 0
.public BendableBigDecimalScore withInitScore(int newInitScore)
Score
0hard/-8soft
with -7
returns -7init/0hard/-8soft
.withInitScore
in interface Score<BendableBigDecimalScore>
newInitScore
- always negative (except in statistical calculations), 0 if all planning variables are initializedScore.getInitScore()
is set to newInitScore
public int getLevelsSize()
getLevelsSize
in class AbstractBendableScore<BendableBigDecimalScore>
AbstractBendableScore.getHardLevelsSize()
+ AbstractBendableScore.getSoftLevelsSize()
public BigDecimal getHardOrSoftScore(int index)
index
- 0 <= index <
getLevelsSize()
public boolean isFeasible()
FeasibilityScore
PlanningSolution
is feasible if it has no broken hard constraints
and Score.isSolutionInitialized()
is true.isFeasible
in interface FeasibilityScore<BendableBigDecimalScore>
Score.getInitScore()
is 0.public BendableBigDecimalScore add(BendableBigDecimalScore addend)
Score
add
in interface Score<BendableBigDecimalScore>
addend
- value to be added to this Scorepublic BendableBigDecimalScore subtract(BendableBigDecimalScore subtrahend)
Score
subtract
in interface Score<BendableBigDecimalScore>
subtrahend
- value to be subtracted from this Scorepublic BendableBigDecimalScore 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<BendableBigDecimalScore>
multiplicand
- value to be multiplied by this Score.public BendableBigDecimalScore 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<BendableBigDecimalScore>
divisor
- value by which this Score is to be dividedpublic BendableBigDecimalScore 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<BendableBigDecimalScore>
exponent
- value by which this Score is to be poweredpublic BendableBigDecimalScore negate()
Score
negate
in interface Score<BendableBigDecimalScore>
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<BendableBigDecimalScore>
ScoreDefinition.fromLevelNumbers(int, Number[])
public int compareTo(BendableBigDecimalScore other)
compareTo
in interface Comparable<BendableBigDecimalScore>
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<BendableBigDecimalScore>
public void validateCompatible(BendableBigDecimalScore other)
public boolean isCompatibleArithmeticArgument(Score otherScore)
isCompatibleArithmeticArgument
in interface Score<BendableBigDecimalScore>
otherScore
- never nullScore.add(Score)
, Score.subtract(Score)
and Comparable.compareTo(Object)
.Copyright © 2006–2020 JBoss by Red Hat. All rights reserved.