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

remove tests based on probabilities

This commit is contained in:
oblonski 2015-04-22 11:21:43 +02:00
parent b2d34b1c65
commit 9f49b96fa4

View file

@ -51,78 +51,78 @@ public class JspritTest {
} }
@Test // @Test
public void defaultStrategyProbabilitiesShouldWork_(){ // public void defaultStrategyProbabilitiesShouldWork_(){
Service s = Service.Builder.newInstance("s1").setLocation(Location.newInstance(1,1)).build(); // Service s = Service.Builder.newInstance("s1").setLocation(Location.newInstance(1,1)).build();
Service s2 = Service.Builder.newInstance("s2").setLocation(Location.newInstance(1,2)).build(); // Service s2 = Service.Builder.newInstance("s2").setLocation(Location.newInstance(1,2)).build();
VehicleImpl v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0,0)).build(); // VehicleImpl v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0,0)).build();
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addVehicle(v).addJob(s2).addJob(s).build(); // VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addVehicle(v).addJob(s2).addJob(s).build();
VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp); // VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp);
vra.setMaxIterations(5000); // vra.setMaxIterations(5000);
final Map<String,Integer> counts = new HashMap<String,Integer>(); // final Map<String,Integer> counts = new HashMap<String,Integer>();
vra.addListener(new StrategySelectedListener() { // vra.addListener(new StrategySelectedListener() {
//
@Override // @Override
public void informSelectedStrategy(SearchStrategy.DiscoveredSolution discoveredSolution, VehicleRoutingProblem vehicleRoutingProblem, Collection<VehicleRoutingProblemSolution> vehicleRoutingProblemSolutions) { // public void informSelectedStrategy(SearchStrategy.DiscoveredSolution discoveredSolution, VehicleRoutingProblem vehicleRoutingProblem, Collection<VehicleRoutingProblemSolution> vehicleRoutingProblemSolutions) {
count(discoveredSolution.getStrategyId()); // count(discoveredSolution.getStrategyId());
} // }
//
private void count(String strategyId) { // private void count(String strategyId) {
if(!counts.containsKey(strategyId)) counts.put(strategyId,1); // if(!counts.containsKey(strategyId)) counts.put(strategyId,1);
Integer integer = counts.get(strategyId); // Integer integer = counts.get(strategyId);
counts.put(strategyId, integer +1); // counts.put(strategyId, integer +1);
} // }
//
}); // });
vra.searchSolutions(); // vra.searchSolutions();
Assert.assertTrue(!counts.containsKey(Jsprit.Strategy.RADIAL_BEST.toString())); // Assert.assertTrue(!counts.containsKey(Jsprit.Strategy.RADIAL_BEST.toString()));
Assert.assertTrue(!counts.containsKey(Jsprit.Strategy.WORST_BEST.toString())); // Assert.assertTrue(!counts.containsKey(Jsprit.Strategy.WORST_BEST.toString()));
Assert.assertTrue(!counts.containsKey(Jsprit.Strategy.CLUSTER_BEST.toString())); // Assert.assertTrue(!counts.containsKey(Jsprit.Strategy.CLUSTER_BEST.toString()));
Integer randomBestCounts = counts.get(Jsprit.Strategy.RANDOM_BEST.toString()); // Integer randomBestCounts = counts.get(Jsprit.Strategy.RANDOM_BEST.toString());
Assert.assertEquals(5000.*0.5/3.5,(double) randomBestCounts,100); // Assert.assertEquals(5000.*0.5/3.5,(double) randomBestCounts,100);
Assert.assertEquals(5000.*0.5/3.5,(double) counts.get(Jsprit.Strategy.RANDOM_REGRET.toString()),100); // Assert.assertEquals(5000.*0.5/3.5,(double) counts.get(Jsprit.Strategy.RANDOM_REGRET.toString()),100);
Assert.assertEquals(5000.*0.5/3.5,(double) counts.get(Jsprit.Strategy.RADIAL_REGRET.toString()),100); // Assert.assertEquals(5000.*0.5/3.5,(double) counts.get(Jsprit.Strategy.RADIAL_REGRET.toString()),100);
Assert.assertEquals(5000.*1./3.5,(double) counts.get(Jsprit.Strategy.WORST_REGRET.toString()),100); // Assert.assertEquals(5000.*1./3.5,(double) counts.get(Jsprit.Strategy.WORST_REGRET.toString()),100);
Assert.assertEquals(5000.*1./3.5,(double) counts.get(Jsprit.Strategy.CLUSTER_REGRET.toString()),100); // Assert.assertEquals(5000.*1./3.5,(double) counts.get(Jsprit.Strategy.CLUSTER_REGRET.toString()),100);
//
} // }
//
@Test // @Test
public void whenChangingStratProb_itShouldBeReflected(){ // public void whenChangingStratProb_itShouldBeReflected(){
Service s = Service.Builder.newInstance("s1").setLocation(Location.newInstance(1,1)).build(); // Service s = Service.Builder.newInstance("s1").setLocation(Location.newInstance(1,1)).build();
Service s2 = Service.Builder.newInstance("s2").setLocation(Location.newInstance(1,2)).build(); // Service s2 = Service.Builder.newInstance("s2").setLocation(Location.newInstance(1,2)).build();
VehicleImpl v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0,0)).build(); // VehicleImpl v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0,0)).build();
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addVehicle(v).addJob(s2).addJob(s).build(); // VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addVehicle(v).addJob(s2).addJob(s).build();
VehicleRoutingAlgorithm vra = Jsprit.Builder.newInstance(vrp) // VehicleRoutingAlgorithm vra = Jsprit.Builder.newInstance(vrp)
.setProperty(Jsprit.Strategy.RANDOM_BEST,"100.").buildAlgorithm(); // .setProperty(Jsprit.Strategy.RANDOM_BEST,"100.").buildAlgorithm();
vra.setMaxIterations(5000); // vra.setMaxIterations(5000);
final Map<String,Integer> counts = new HashMap<String,Integer>(); // final Map<String,Integer> counts = new HashMap<String,Integer>();
vra.addListener(new StrategySelectedListener() { // vra.addListener(new StrategySelectedListener() {
//
@Override // @Override
public void informSelectedStrategy(SearchStrategy.DiscoveredSolution discoveredSolution, VehicleRoutingProblem vehicleRoutingProblem, Collection<VehicleRoutingProblemSolution> vehicleRoutingProblemSolutions) { // public void informSelectedStrategy(SearchStrategy.DiscoveredSolution discoveredSolution, VehicleRoutingProblem vehicleRoutingProblem, Collection<VehicleRoutingProblemSolution> vehicleRoutingProblemSolutions) {
count(discoveredSolution.getStrategyId()); // count(discoveredSolution.getStrategyId());
} // }
//
private void count(String strategyId) { // private void count(String strategyId) {
if(!counts.containsKey(strategyId)) counts.put(strategyId,1); // if(!counts.containsKey(strategyId)) counts.put(strategyId,1);
Integer integer = counts.get(strategyId); // Integer integer = counts.get(strategyId);
counts.put(strategyId, integer +1); // counts.put(strategyId, integer +1);
} // }
//
}); // });
vra.searchSolutions(); // vra.searchSolutions();
Assert.assertTrue(!counts.containsKey(Jsprit.Strategy.RADIAL_BEST.toString())); // Assert.assertTrue(!counts.containsKey(Jsprit.Strategy.RADIAL_BEST.toString()));
Assert.assertTrue(!counts.containsKey(Jsprit.Strategy.WORST_BEST.toString())); // Assert.assertTrue(!counts.containsKey(Jsprit.Strategy.WORST_BEST.toString()));
Assert.assertTrue(!counts.containsKey(Jsprit.Strategy.CLUSTER_BEST.toString())); // Assert.assertTrue(!counts.containsKey(Jsprit.Strategy.CLUSTER_BEST.toString()));
Integer randomBestCounts = counts.get(Jsprit.Strategy.RANDOM_BEST.toString()); // Integer randomBestCounts = counts.get(Jsprit.Strategy.RANDOM_BEST.toString());
Assert.assertEquals(5000.*100./103.,(double) randomBestCounts,100); // Assert.assertEquals(5000.*100./103.,(double) randomBestCounts,100);
Assert.assertEquals(5000.*0.5/103.,(double) counts.get(Jsprit.Strategy.RANDOM_REGRET.toString()),100); // Assert.assertEquals(5000.*0.5/103.,(double) counts.get(Jsprit.Strategy.RANDOM_REGRET.toString()),100);
Assert.assertEquals(5000.*0.5/103.,(double) counts.get(Jsprit.Strategy.RADIAL_REGRET.toString()),100); // Assert.assertEquals(5000.*0.5/103.,(double) counts.get(Jsprit.Strategy.RADIAL_REGRET.toString()),100);
Assert.assertEquals(5000.*1./103.,(double) counts.get(Jsprit.Strategy.WORST_REGRET.toString()),100); // Assert.assertEquals(5000.*1./103.,(double) counts.get(Jsprit.Strategy.WORST_REGRET.toString()),100);
Assert.assertEquals(5000.*1./103.,(double) counts.get(Jsprit.Strategy.CLUSTER_REGRET.toString()),100); // Assert.assertEquals(5000.*1./103.,(double) counts.get(Jsprit.Strategy.CLUSTER_REGRET.toString()),100);
//
} // }
@Test @Test
public void whenActivatingStrat_itShouldBeReflected(){ public void whenActivatingStrat_itShouldBeReflected(){