@Override public HardSoftScore fromLevelNumbers(int initScore, Number[] levelNumbers) { if (levelNumbers.length != getLevelsSize()) { throw new IllegalStateException("The levelNumbers (" + Arrays.toString(levelNumbers) + ")'s length (" + levelNumbers.length + ") must equal the levelSize (" + getLevelsSize() + ")."); } return HardSoftScore.ofUninitialized(initScore, (Integer) levelNumbers[0], (Integer) levelNumbers[1]); }
@Override public HardSoftScore buildOptimisticBound(InitializingScoreTrend initializingScoreTrend, HardSoftScore score) { InitializingScoreTrendLevel[] trendLevels = initializingScoreTrend.getTrendLevels(); return HardSoftScore.ofUninitialized(0, trendLevels[0] == InitializingScoreTrendLevel.ONLY_DOWN ? score.getHardScore() : Integer.MAX_VALUE, trendLevels[1] == InitializingScoreTrendLevel.ONLY_DOWN ? score.getSoftScore() : Integer.MAX_VALUE); }
@Override public HardSoftScore buildPessimisticBound(InitializingScoreTrend initializingScoreTrend, HardSoftScore score) { InitializingScoreTrendLevel[] trendLevels = initializingScoreTrend.getTrendLevels(); return HardSoftScore.ofUninitialized(0, trendLevels[0] == InitializingScoreTrendLevel.ONLY_UP ? score.getHardScore() : Integer.MIN_VALUE, trendLevels[1] == InitializingScoreTrendLevel.ONLY_UP ? score.getSoftScore() : Integer.MIN_VALUE); }
public static HardSoftScore parseScore(String scoreString) { String[] scoreTokens = parseScoreTokens(HardSoftScore.class, scoreString, HARD_LABEL, SOFT_LABEL); int initScore = parseInitScore(HardSoftScore.class, scoreString, scoreTokens[0]); int hardScore = parseLevelAsInt(HardSoftScore.class, scoreString, scoreTokens[1]); int softScore = parseLevelAsInt(HardSoftScore.class, scoreString, scoreTokens[2]); return ofUninitialized(initScore, hardScore, softScore); }
@Test public void subtract() { assertEquals(HardSoftScore.of(21, 280), HardSoftScore.of(20, -20).subtract( HardSoftScore.of(-1, -300))); assertEquals(HardSoftScore.ofUninitialized(-63, 21, 280), HardSoftScore.ofUninitialized(-70, 20, -20).subtract( HardSoftScore.ofUninitialized(-7, -1, -300))); }
@Test public void add() { assertEquals(HardSoftScore.of(19, -320), HardSoftScore.of(20, -20).add( HardSoftScore.of(-1, -300))); assertEquals(HardSoftScore.ofUninitialized(-77, 19, -320), HardSoftScore.ofUninitialized(-70, 20, -20).add( HardSoftScore.ofUninitialized(-7, -1, -300))); }
@Test public void checkPickEarlyFirstFeasibleScoreOrNonDeterioratingHard() { DefaultConstructionHeuristicForager forager = new DefaultConstructionHeuristicForager( ConstructionHeuristicPickEarlyType.FIRST_FEASIBLE_SCORE_OR_NON_DETERIORATING_HARD); ConstructionHeuristicStepScope<Solution_> stepScope = buildStepScope(HardSoftScore.ofUninitialized(-8, -10, -100)); forager.checkPickEarly(buildMoveScope(stepScope, HardSoftScore.ofUninitialized(-7, -11, -110))); assertEquals(false, forager.isQuitEarly()); forager.checkPickEarly(buildMoveScope(stepScope, HardSoftScore.ofUninitialized(-7, -11, -90))); assertEquals(false, forager.isQuitEarly()); forager.checkPickEarly(buildMoveScope(stepScope, HardSoftScore.ofUninitialized(-7, -10, -110))); assertEquals(true, forager.isQuitEarly()); }
@Test public void checkPickEarlyFirstFeasibleScore() { DefaultConstructionHeuristicForager forager = new DefaultConstructionHeuristicForager( ConstructionHeuristicPickEarlyType.FIRST_FEASIBLE_SCORE); ConstructionHeuristicStepScope<Solution_> stepScope = buildStepScope(HardSoftScore.ofUninitialized(-8, 0, -100)); forager.checkPickEarly(buildMoveScope(stepScope, HardSoftScore.ofUninitialized(-7, -1, -110))); assertEquals(false, forager.isQuitEarly()); forager.checkPickEarly(buildMoveScope(stepScope, HardSoftScore.ofUninitialized(-7, -1, -90))); assertEquals(false, forager.isQuitEarly()); forager.checkPickEarly(buildMoveScope(stepScope, HardSoftScore.ofUninitialized(-7, 0, -110))); assertEquals(true, forager.isQuitEarly()); }
@Test public void persistAndMerge() { persistAndMerge(new TestJpaEntity(null), HardSoftScore.of(-10, -2), HardSoftScore.ofUninitialized(-7, -10, -2)); }
@Test public void withInitScore() { assertEquals(HardSoftScore.ofUninitialized(-7, -147, -258), HardSoftScore.of(-147, -258).withInitScore(-7)); }
@Test public void power() { assertEquals(HardSoftScore.of(16, 25), HardSoftScore.of(-4, 5).power(2.0)); assertEquals(HardSoftScore.of(4, 5), HardSoftScore.of(16, 25).power(0.5)); assertEquals(HardSoftScore.ofUninitialized(-343, 64, 125), HardSoftScore.ofUninitialized(-7, 4, 5).power(3.0)); }
@Test public void toShortString() { assertEquals("0", HardSoftScore.of(0, 0).toShortString()); assertEquals("-258soft", HardSoftScore.of(0, -258).toShortString()); assertEquals("-147hard", HardSoftScore.of(-147, 0).toShortString()); assertEquals("-147hard/-258soft", HardSoftScore.of(-147, -258).toShortString()); assertEquals("-7init", HardSoftScore.ofUninitialized(-7, 0, 0).toShortString()); assertEquals("-7init/-258soft", HardSoftScore.ofUninitialized(-7, 0, -258).toShortString()); assertEquals("-7init/-147hard/-258soft", HardSoftScore.ofUninitialized(-7, -147, -258).toShortString()); }
@Test public void divide() { assertEquals(HardSoftScore.of(5, -5), HardSoftScore.of(25, -25).divide(5.0)); assertEquals(HardSoftScore.of(4, -5), HardSoftScore.of(21, -21).divide(5.0)); assertEquals(HardSoftScore.of(4, -5), HardSoftScore.of(24, -24).divide(5.0)); assertEquals(HardSoftScore.ofUninitialized(-7, 4, -5), HardSoftScore.ofUninitialized(-14, 8, -10).divide(2.0)); }
@Test public void multiply() { assertEquals(HardSoftScore.of(6, -6), HardSoftScore.of(5, -5).multiply(1.2)); assertEquals(HardSoftScore.of(1, -2), HardSoftScore.of(1, -1).multiply(1.2)); assertEquals(HardSoftScore.of(4, -5), HardSoftScore.of(4, -4).multiply(1.2)); assertEquals(HardSoftScore.ofUninitialized(-14, 8, -10), HardSoftScore.ofUninitialized(-7, 4, -5).multiply(2.0)); }
@Test public void serializeAndDeserialize() { assertSerializeAndDeserialize(null, new TestHardSoftScoreWrapper(null)); HardSoftScore score = HardSoftScore.of(1200, 34); assertSerializeAndDeserialize(score, new TestHardSoftScoreWrapper(score)); score = HardSoftScore.ofUninitialized(-7, 1200, 34); assertSerializeAndDeserialize(score, new TestHardSoftScoreWrapper(score)); }
@Test public void serializeAndDeserialize() { assertSerializeAndDeserialize(null, new TestHardSoftScoreWrapper(null)); HardSoftScore score = HardSoftScore.of(1200, 34); assertSerializeAndDeserialize(score, new TestHardSoftScoreWrapper(score)); score = HardSoftScore.ofUninitialized(-7, 1200, 34); assertSerializeAndDeserialize(score, new TestHardSoftScoreWrapper(score)); }
@Test public void toInitializedScore() { assertEquals(HardSoftScore.of(-147, -258), HardSoftScore.of(-147, -258).toInitializedScore()); assertEquals(HardSoftScore.of(-147, -258), HardSoftScore.ofUninitialized(-7, -147, -258).toInitializedScore()); }
@Test public void serializeAndDeserialize() { assertSerializeAndDeserialize(null, new TestHardSoftScoreWrapper(null)); HardSoftScore score = HardSoftScore.of(1200, 34); assertSerializeAndDeserialize(score, new TestHardSoftScoreWrapper(score)); score = HardSoftScore.ofUninitialized(-7, 1200, 34); assertSerializeAndDeserialize(score, new TestHardSoftScoreWrapper(score)); }
@Test public void parseScore() { assertEquals(HardSoftScore.of(-147, -258), HardSoftScore.parseScore("-147hard/-258soft")); assertEquals(HardSoftScore.ofUninitialized(-7, -147, -258), HardSoftScore.parseScore("-7init/-147hard/-258soft")); assertEquals(HardSoftScore.of(-147, Integer.MIN_VALUE), HardSoftScore.parseScore("-147hard/*soft")); }
@Test public void testToString() { assertEquals("0hard/-258soft", HardSoftScore.of(0, -258).toString()); assertEquals("-147hard/-258soft", HardSoftScore.of(-147, -258).toString()); assertEquals("-7init/-147hard/-258soft", HardSoftScore.ofUninitialized(-7, -147, -258).toString()); }