mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
added tests
This commit is contained in:
parent
2a94626710
commit
1645641ab6
2 changed files with 37 additions and 8 deletions
|
|
@ -94,9 +94,6 @@ import org.apache.commons.configuration.HierarchicalConfiguration;
|
|||
import org.apache.commons.configuration.XMLConfiguration;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
|
||||
|
||||
|
||||
public class VehicleRoutingAlgorithms {
|
||||
|
||||
static class TypedMap {
|
||||
|
|
@ -583,7 +580,6 @@ public class VehicleRoutingAlgorithms {
|
|||
if(config.containsKey("iterations")){
|
||||
int iter = config.getInt("iterations");
|
||||
metaAlgorithm.setNuOfIterations(iter);
|
||||
log.info("set nuOfIterations to " + iter);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,15 @@
|
|||
package jsprit.core.algorithm;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
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;
|
||||
|
||||
|
|
@ -38,13 +42,42 @@ public class VehicleRoutingAlgorithmTest {
|
|||
|
||||
@Test
|
||||
public void whenSettingIterations_iterAreExecutedCorrectly(){
|
||||
SearchStrategyManager stratManager = mock(SearchStrategyManager.class);
|
||||
VehicleRoutingAlgorithm algorithm = new VehicleRoutingAlgorithm(mock(VehicleRoutingProblem.class),
|
||||
mock(SearchStrategyManager.class));
|
||||
algorithm.setNuOfIterations(100);
|
||||
stratManager);
|
||||
when(stratManager.getRandomStrategy()).thenReturn(mock(SearchStrategy.class));
|
||||
when(stratManager.getProbabilities()).thenReturn(Arrays.asList(1.0));
|
||||
algorithm.setNuOfIterations(1000);
|
||||
CountIterations counter = new CountIterations();
|
||||
algorithm.addListener(counter);
|
||||
algorithm.searchSolutions();
|
||||
assertEquals(100,counter.getCountIterations());
|
||||
assertEquals(1000,counter.getCountIterations());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingPrematureTermination_itIsExecutedCorrectly(){
|
||||
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.setNuOfIterations(1000);
|
||||
PrematureAlgorithmTermination termination = new PrematureAlgorithmTermination() {
|
||||
|
||||
private int nuOfIterations = 1;
|
||||
|
||||
@Override
|
||||
public boolean isPrematureBreak(DiscoveredSolution discoveredSolution) {
|
||||
if(nuOfIterations == 50) return true;
|
||||
nuOfIterations++;
|
||||
return false;
|
||||
}
|
||||
};
|
||||
CountIterations counter = new CountIterations();
|
||||
algorithm.addListener(counter);
|
||||
algorithm.setPrematureAlgorithmTermination(termination);
|
||||
algorithm.searchSolutions();
|
||||
assertEquals(50,counter.getCountIterations());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue