@Test
public void lateSimulatedAnnealingSize2() {
LateSimulatedAnnealingAcceptor acceptor = new LateSimulatedAnnealingAcceptor();
acceptor.setLateSimulatedAnnealingSize(2);
DefaultSolverScope solverScope = new DefaultSolverScope();
solverScope.setBestScore(SimpleScore.valueOf(-1000));
Random workingRandom = mock(Random.class);
when(workingRandom.nextDouble()).thenReturn(0.3);
solverScope.setWorkingRandom(workingRandom);
LocalSearchPhaseScope phaseScope = new LocalSearchPhaseScope(solverScope);
LocalSearchStepScope lastCompletedStepScope = new LocalSearchStepScope(phaseScope, -1);
lastCompletedStepScope.setScore(SimpleScore.valueOf(Integer.MIN_VALUE));
phaseScope.setLastCompletedStepScope(lastCompletedStepScope);
acceptor.phaseStarted(phaseScope);
// lateScore = -1000, bestScore = -1000
LocalSearchStepScope stepScope0 = new LocalSearchStepScope(phaseScope);
LocalSearchMoveScope moveScope0 = buildMoveScope(stepScope0, -500);
assertEquals(true, acceptor.isAccepted(buildMoveScope(stepScope0, -900)));
assertEquals(true, acceptor.isAccepted(moveScope0));
assertEquals(true, acceptor.isAccepted(buildMoveScope(stepScope0, -800)));
assertEquals(true, acceptor.isAccepted(buildMoveScope(stepScope0, -2000)));
assertEquals(true, acceptor.isAccepted(buildMoveScope(stepScope0, -1000)));
assertEquals(true, acceptor.isAccepted(buildMoveScope(stepScope0, -900))); // Repeated call
stepScope0.setStep(moveScope0.getMove());
stepScope0.setScore(moveScope0.getScore());
solverScope.setBestScore(moveScope0.getScore());
acceptor.stepEnded(stepScope0);
phaseScope.setLastCompletedStepScope(stepScope0);
// lateScore = -1000, bestScore = -500
LocalSearchStepScope stepScope1 = new LocalSearchStepScope(phaseScope);
LocalSearchMoveScope moveScope1 = buildMoveScope(stepScope1, -700);
assertEquals(true, acceptor.isAccepted(buildMoveScope(stepScope1, -900)));
assertEquals(false, acceptor.isAccepted(buildMoveScope(stepScope1, -2000)));
assertEquals(true, acceptor.isAccepted(moveScope1));
assertEquals(true, acceptor.isAccepted(buildMoveScope(stepScope1, -1000)));
assertEquals(true, acceptor.isAccepted(buildMoveScope(stepScope1, -1100)));
assertEquals(false, acceptor.isAccepted(buildMoveScope(stepScope1, -1200)));
assertEquals(true, acceptor.isAccepted(buildMoveScope(stepScope0, -900))); // Repeated call
stepScope1.setStep(moveScope1.getMove());
stepScope1.setScore(moveScope1.getScore());
// bestScore unchanged
acceptor.stepEnded(stepScope1);
phaseScope.setLastCompletedStepScope(stepScope1);
// lateScore = -500, bestScore = -500
LocalSearchStepScope stepScope2 = new LocalSearchStepScope(phaseScope);
LocalSearchMoveScope moveScope2 = buildMoveScope(stepScope1, -400);
assertEquals(true, acceptor.isAccepted(buildMoveScope(stepScope2, -700)));
assertEquals(false, acceptor.isAccepted(buildMoveScope(stepScope2, -2000)));
assertEquals(false, acceptor.isAccepted(buildMoveScope(stepScope2, -701)));
assertEquals(true, acceptor.isAccepted(buildMoveScope(stepScope2, -600)));
assertEquals(true, acceptor.isAccepted(moveScope2));
assertEquals(true, acceptor.isAccepted(buildMoveScope(stepScope0, -700))); // Repeated call
stepScope2.setStep(moveScope2.getMove());
stepScope2.setScore(moveScope2.getScore());
solverScope.setBestScore(moveScope2.getScore());
acceptor.stepEnded(stepScope2);
phaseScope.setLastCompletedStepScope(stepScope2);
// lateScore = -700, bestScore = -400
LocalSearchStepScope stepScope3 = new LocalSearchStepScope(phaseScope);
LocalSearchMoveScope moveScope3 = buildMoveScope(stepScope1, -200);
assertEquals(false, acceptor.isAccepted(buildMoveScope(stepScope3, -900)));
assertEquals(true, acceptor.isAccepted(buildMoveScope(stepScope3, -700)));
assertEquals(true, acceptor.isAccepted(buildMoveScope(stepScope3, -750)));
assertEquals(true, acceptor.isAccepted(moveScope3));
assertEquals(false, acceptor.isAccepted(buildMoveScope(stepScope3, -2000)));
assertEquals(false, acceptor.isAccepted(buildMoveScope(stepScope0, -900))); // Repeated call
stepScope3.setStep(moveScope3.getMove());
stepScope3.setScore(moveScope3.getScore());
solverScope.setBestScore(moveScope3.getScore());
acceptor.stepEnded(stepScope3);
phaseScope.setLastCompletedStepScope(stepScope3);
acceptor.phaseEnded(phaseScope);
}