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:
parent
b2d34b1c65
commit
9f49b96fa4
1 changed files with 72 additions and 72 deletions
|
|
@ -51,78 +51,78 @@ public class JspritTest {
|
|||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultStrategyProbabilitiesShouldWork_(){
|
||||
Service s = Service.Builder.newInstance("s1").setLocation(Location.newInstance(1,1)).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();
|
||||
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addVehicle(v).addJob(s2).addJob(s).build();
|
||||
VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp);
|
||||
vra.setMaxIterations(5000);
|
||||
final Map<String,Integer> counts = new HashMap<String,Integer>();
|
||||
vra.addListener(new StrategySelectedListener() {
|
||||
|
||||
@Override
|
||||
public void informSelectedStrategy(SearchStrategy.DiscoveredSolution discoveredSolution, VehicleRoutingProblem vehicleRoutingProblem, Collection<VehicleRoutingProblemSolution> vehicleRoutingProblemSolutions) {
|
||||
count(discoveredSolution.getStrategyId());
|
||||
}
|
||||
|
||||
private void count(String strategyId) {
|
||||
if(!counts.containsKey(strategyId)) counts.put(strategyId,1);
|
||||
Integer integer = counts.get(strategyId);
|
||||
counts.put(strategyId, integer +1);
|
||||
}
|
||||
|
||||
});
|
||||
vra.searchSolutions();
|
||||
Assert.assertTrue(!counts.containsKey(Jsprit.Strategy.RADIAL_BEST.toString()));
|
||||
Assert.assertTrue(!counts.containsKey(Jsprit.Strategy.WORST_BEST.toString()));
|
||||
Assert.assertTrue(!counts.containsKey(Jsprit.Strategy.CLUSTER_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) 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.*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);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenChangingStratProb_itShouldBeReflected(){
|
||||
Service s = Service.Builder.newInstance("s1").setLocation(Location.newInstance(1,1)).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();
|
||||
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addVehicle(v).addJob(s2).addJob(s).build();
|
||||
VehicleRoutingAlgorithm vra = Jsprit.Builder.newInstance(vrp)
|
||||
.setProperty(Jsprit.Strategy.RANDOM_BEST,"100.").buildAlgorithm();
|
||||
vra.setMaxIterations(5000);
|
||||
final Map<String,Integer> counts = new HashMap<String,Integer>();
|
||||
vra.addListener(new StrategySelectedListener() {
|
||||
|
||||
@Override
|
||||
public void informSelectedStrategy(SearchStrategy.DiscoveredSolution discoveredSolution, VehicleRoutingProblem vehicleRoutingProblem, Collection<VehicleRoutingProblemSolution> vehicleRoutingProblemSolutions) {
|
||||
count(discoveredSolution.getStrategyId());
|
||||
}
|
||||
|
||||
private void count(String strategyId) {
|
||||
if(!counts.containsKey(strategyId)) counts.put(strategyId,1);
|
||||
Integer integer = counts.get(strategyId);
|
||||
counts.put(strategyId, integer +1);
|
||||
}
|
||||
|
||||
});
|
||||
vra.searchSolutions();
|
||||
Assert.assertTrue(!counts.containsKey(Jsprit.Strategy.RADIAL_BEST.toString()));
|
||||
Assert.assertTrue(!counts.containsKey(Jsprit.Strategy.WORST_BEST.toString()));
|
||||
Assert.assertTrue(!counts.containsKey(Jsprit.Strategy.CLUSTER_BEST.toString()));
|
||||
Integer randomBestCounts = counts.get(Jsprit.Strategy.RANDOM_BEST.toString());
|
||||
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.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.CLUSTER_REGRET.toString()),100);
|
||||
|
||||
}
|
||||
// @Test
|
||||
// public void defaultStrategyProbabilitiesShouldWork_(){
|
||||
// Service s = Service.Builder.newInstance("s1").setLocation(Location.newInstance(1,1)).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();
|
||||
// VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addVehicle(v).addJob(s2).addJob(s).build();
|
||||
// VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp);
|
||||
// vra.setMaxIterations(5000);
|
||||
// final Map<String,Integer> counts = new HashMap<String,Integer>();
|
||||
// vra.addListener(new StrategySelectedListener() {
|
||||
//
|
||||
// @Override
|
||||
// public void informSelectedStrategy(SearchStrategy.DiscoveredSolution discoveredSolution, VehicleRoutingProblem vehicleRoutingProblem, Collection<VehicleRoutingProblemSolution> vehicleRoutingProblemSolutions) {
|
||||
// count(discoveredSolution.getStrategyId());
|
||||
// }
|
||||
//
|
||||
// private void count(String strategyId) {
|
||||
// if(!counts.containsKey(strategyId)) counts.put(strategyId,1);
|
||||
// Integer integer = counts.get(strategyId);
|
||||
// counts.put(strategyId, integer +1);
|
||||
// }
|
||||
//
|
||||
// });
|
||||
// vra.searchSolutions();
|
||||
// Assert.assertTrue(!counts.containsKey(Jsprit.Strategy.RADIAL_BEST.toString()));
|
||||
// Assert.assertTrue(!counts.containsKey(Jsprit.Strategy.WORST_BEST.toString()));
|
||||
// Assert.assertTrue(!counts.containsKey(Jsprit.Strategy.CLUSTER_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) 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.*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);
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void whenChangingStratProb_itShouldBeReflected(){
|
||||
// Service s = Service.Builder.newInstance("s1").setLocation(Location.newInstance(1,1)).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();
|
||||
// VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addVehicle(v).addJob(s2).addJob(s).build();
|
||||
// VehicleRoutingAlgorithm vra = Jsprit.Builder.newInstance(vrp)
|
||||
// .setProperty(Jsprit.Strategy.RANDOM_BEST,"100.").buildAlgorithm();
|
||||
// vra.setMaxIterations(5000);
|
||||
// final Map<String,Integer> counts = new HashMap<String,Integer>();
|
||||
// vra.addListener(new StrategySelectedListener() {
|
||||
//
|
||||
// @Override
|
||||
// public void informSelectedStrategy(SearchStrategy.DiscoveredSolution discoveredSolution, VehicleRoutingProblem vehicleRoutingProblem, Collection<VehicleRoutingProblemSolution> vehicleRoutingProblemSolutions) {
|
||||
// count(discoveredSolution.getStrategyId());
|
||||
// }
|
||||
//
|
||||
// private void count(String strategyId) {
|
||||
// if(!counts.containsKey(strategyId)) counts.put(strategyId,1);
|
||||
// Integer integer = counts.get(strategyId);
|
||||
// counts.put(strategyId, integer +1);
|
||||
// }
|
||||
//
|
||||
// });
|
||||
// vra.searchSolutions();
|
||||
// Assert.assertTrue(!counts.containsKey(Jsprit.Strategy.RADIAL_BEST.toString()));
|
||||
// Assert.assertTrue(!counts.containsKey(Jsprit.Strategy.WORST_BEST.toString()));
|
||||
// Assert.assertTrue(!counts.containsKey(Jsprit.Strategy.CLUSTER_BEST.toString()));
|
||||
// Integer randomBestCounts = counts.get(Jsprit.Strategy.RANDOM_BEST.toString());
|
||||
// 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.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.CLUSTER_REGRET.toString()),100);
|
||||
//
|
||||
// }
|
||||
|
||||
@Test
|
||||
public void whenActivatingStrat_itShouldBeReflected(){
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue