1
0
Fork 0
mirror of https://github.com/graphhopper/jsprit.git synced 2020-01-24 07:45:05 +01:00

add and test core.algorithm.VehicleRoutingAlgorithm.setMaxIterations(...) and .getMaxIterations()

deprecate .setNuOfIterations(...) and .getNuOfIterations()
This commit is contained in:
oblonski 2014-08-08 08:50:49 +02:00
parent ae83eadad7
commit 632a889c4b
2 changed files with 65 additions and 16 deletions

View file

@ -18,21 +18,20 @@
******************************************************************************/
package jsprit.core.algorithm;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.util.Arrays;
import java.util.Collection;
import jsprit.core.algorithm.SearchStrategy.DiscoveredSolution;
import jsprit.core.algorithm.listener.IterationStartsListener;
import jsprit.core.algorithm.termination.PrematureAlgorithmTermination;
import jsprit.core.problem.VehicleRoutingProblem;
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
import org.junit.Test;
import java.util.Arrays;
import java.util.Collection;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public class VehicleRoutingAlgorithmTest {
@Test
@ -42,6 +41,14 @@ public class VehicleRoutingAlgorithmTest {
algorithm.setNuOfIterations(50);
assertEquals(50,algorithm.getNuOfIterations());
}
@Test
public void whenSettingIterationsWithMaxIterations_itIsSetCorrectly(){
VehicleRoutingAlgorithm algorithm = new VehicleRoutingAlgorithm(mock(VehicleRoutingProblem.class),
mock(SearchStrategyManager.class));
algorithm.setMaxIterations(50);
assertEquals(50,algorithm.getMaxIterations());
}
private static class CountIterations implements IterationStartsListener {
@ -57,7 +64,21 @@ public class VehicleRoutingAlgorithmTest {
}
}
@Test
public void whenSettingIterationsWithMaxIterations_iterAreExecutedCorrectly(){
SearchStrategyManager stratManager = mock(SearchStrategyManager.class);
VehicleRoutingAlgorithm algorithm = new VehicleRoutingAlgorithm(mock(VehicleRoutingProblem.class),
stratManager);
when(stratManager.getRandomStrategy()).thenReturn(mock(SearchStrategy.class));
when(stratManager.getProbabilities()).thenReturn(Arrays.asList(1.0));
algorithm.setMaxIterations(1000);
CountIterations counter = new CountIterations();
algorithm.addListener(counter);
algorithm.searchSolutions();
assertEquals(1000,counter.getCountIterations());
}
@Test
public void whenSettingIterations_iterAreExecutedCorrectly(){
SearchStrategyManager stratManager = mock(SearchStrategyManager.class);