mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
replace .setNuOfIterations with .setMaxIterations
This commit is contained in:
parent
527ca56d04
commit
8d20fe12aa
19 changed files with 320 additions and 77 deletions
|
|
@ -120,7 +120,7 @@ public class ExperimentalSchrimpfAcceptance implements SolutionAcceptor, Iterati
|
|||
AlgorithmConfig algorithmConfig = new AlgorithmConfig();
|
||||
new AlgorithmConfigXmlReader(algorithmConfig).read(resource);
|
||||
VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.createAlgorithm(problem, algorithmConfig);
|
||||
vra.setNuOfIterations(nOfRandomWalks);
|
||||
vra.setMaxIterations(nOfRandomWalks);
|
||||
vra.getAlgorithmListeners().addListener(new IterationEndsListener() {
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -58,16 +58,8 @@ public class BuildCVRPAlgoFromScratch_IT {
|
|||
vrp = builder.build();
|
||||
|
||||
final StateManager stateManager = new StateManager(vrp);
|
||||
stateManager.updateLoadStates();
|
||||
stateManager.updateTimeWindowStates();
|
||||
stateManager.addStateUpdater(new UpdateVariableCosts(vrp.getActivityCosts(), vrp.getTransportCosts(), stateManager));
|
||||
|
||||
|
||||
ConstraintManager cManager = new ConstraintManager(vrp, stateManager);
|
||||
cManager.addLoadConstraint();
|
||||
cManager.addTimeWindowConstraint();
|
||||
|
||||
|
||||
|
||||
VehicleFleetManager fleetManager = new InfiniteFleetManagerFactory(vrp.getVehicles()).createFleetManager();
|
||||
|
||||
InsertionStrategy bestInsertion = new BestInsertionBuilder(vrp, fleetManager, stateManager, cManager).build();
|
||||
|
|
@ -94,19 +86,11 @@ public class BuildCVRPAlgoFromScratch_IT {
|
|||
SearchStrategy radialStrategy = new SearchStrategy("radial", new SelectBest(), new GreedyAcceptance(1), solutionCostCalculator);
|
||||
RuinAndRecreateModule radialModule = new RuinAndRecreateModule("radialRuin_bestInsertion", bestInsertion, radial);
|
||||
radialStrategy.addModule(radialModule);
|
||||
|
||||
SearchStrategyManager strategyManager = new SearchStrategyManager();
|
||||
strategyManager.addStrategy(radialStrategy, 0.5);
|
||||
strategyManager.addStrategy(randomStrategy, 0.5);
|
||||
|
||||
vra = new VehicleRoutingAlgorithm(vrp, strategyManager);
|
||||
vra.addListener(stateManager);
|
||||
vra.addListener(new RemoveEmptyVehicles(fleetManager));
|
||||
|
||||
VehicleRoutingProblemSolution iniSolution = new InsertionInitialSolutionFactory(bestInsertion, solutionCostCalculator).createSolution(vrp);
|
||||
|
||||
vra.addInitialSolution(iniSolution);
|
||||
|
||||
vra = new PrettyAlgorithmBuilder(vrp,fleetManager,stateManager,cManager)
|
||||
.withStrategy(randomStrategy,0.5).withStrategy(radialStrategy,0.5)
|
||||
.addCoreStateAndConstraintStuff()
|
||||
.constructInitialSolutionWith(bestInsertion,solutionCostCalculator).build();
|
||||
vra.setMaxIterations(2000);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ import jsprit.core.problem.solution.route.VehicleRoute;
|
|||
import jsprit.core.problem.vehicle.InfiniteFleetManagerFactory;
|
||||
import jsprit.core.problem.vehicle.VehicleFleetManager;
|
||||
import jsprit.core.util.Solutions;
|
||||
import junit.framework.Assert;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.junit.Before;
|
||||
|
|
@ -63,15 +64,11 @@ public class BuildPDVRPAlgoFromScratch_IT {
|
|||
final StateManager stateManager = new StateManager(vrp);
|
||||
|
||||
ConstraintManager constraintManager = new ConstraintManager(vrp,stateManager);
|
||||
constraintManager.addTimeWindowConstraint();
|
||||
constraintManager.addLoadConstraint();
|
||||
|
||||
|
||||
VehicleFleetManager fleetManager = new InfiniteFleetManagerFactory(vrp.getVehicles()).createFleetManager();
|
||||
|
||||
BestInsertionBuilder iBuilder = new BestInsertionBuilder(vrp, fleetManager, stateManager, constraintManager);
|
||||
// iBuilder.setConstraintManager(constraintManger);
|
||||
InsertionStrategy bestInsertion = iBuilder.build();
|
||||
|
||||
|
||||
InsertionStrategy bestInsertion = new BestInsertionBuilder(vrp, fleetManager, stateManager, constraintManager).build();
|
||||
|
||||
RuinStrategy radial = new RadialRuinStrategyFactory( 0.15, new AvgServiceDistance(vrp.getTransportCosts())).createStrategy(vrp);
|
||||
RuinStrategy random = new RandomRuinStrategyFactory(0.25).createStrategy(vrp);
|
||||
|
||||
|
|
@ -96,27 +93,26 @@ public class BuildPDVRPAlgoFromScratch_IT {
|
|||
SearchStrategy radialStrategy = new SearchStrategy("radial", new SelectBest(), new GreedyAcceptance(1), solutionCostCalculator);
|
||||
RuinAndRecreateModule radialModule = new RuinAndRecreateModule("radialRuin_bestInsertion", bestInsertion, radial);
|
||||
radialStrategy.addModule(radialModule);
|
||||
|
||||
SearchStrategyManager strategyManager = new SearchStrategyManager();
|
||||
strategyManager.addStrategy(radialStrategy, 0.5);
|
||||
strategyManager.addStrategy(randomStrategy, 0.5);
|
||||
|
||||
vra = new VehicleRoutingAlgorithm(vrp, strategyManager);
|
||||
vra.addListener(stateManager);
|
||||
vra.addListener(new RemoveEmptyVehicles(fleetManager));
|
||||
|
||||
VehicleRoutingProblemSolution iniSolution = new InsertionInitialSolutionFactory(bestInsertion, solutionCostCalculator).createSolution(vrp);
|
||||
|
||||
vra.addInitialSolution(iniSolution);
|
||||
vra.setNuOfIterations(1000);
|
||||
vra = new PrettyAlgorithmBuilder(vrp,fleetManager,stateManager,constraintManager)
|
||||
.addCoreStateAndConstraintStuff().constructInitialSolutionWith(bestInsertion,solutionCostCalculator)
|
||||
.withStrategy(radialStrategy,0.5).withStrategy(randomStrategy,0.5).build();
|
||||
|
||||
vra.setMaxIterations(1000);
|
||||
vra.setPrematureAlgorithmTermination(new IterationWithoutImprovementTermination(100));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test(){
|
||||
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
|
||||
System.out.println(Solutions.bestOf(solutions).getCost());
|
||||
try {
|
||||
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
|
||||
System.out.println(Solutions.bestOf(solutions).getCost());
|
||||
Assert.assertTrue(true);
|
||||
}
|
||||
catch (Exception e){
|
||||
Assert.assertTrue(false);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ public class BuildPDVRPWithShipmentsAlgoFromScratch_IT {
|
|||
VehicleRoutingProblemSolution iniSolution = new InsertionInitialSolutionFactory(bestInsertion, solutionCostCalculator).createSolution(vrp);
|
||||
vra.addInitialSolution(iniSolution);
|
||||
|
||||
vra.setNuOfIterations(3);
|
||||
vra.setMaxIterations(3);
|
||||
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
|
||||
assertTrue(!solutions.isEmpty());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ public class FiniteVehicleFleetManagerIdentifiesDistinctVehicle_IT {
|
|||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
|
||||
VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp);
|
||||
vra.setNuOfIterations(10);
|
||||
vra.setMaxIterations(10);
|
||||
try{
|
||||
@SuppressWarnings("unused")
|
||||
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
|
||||
|
|
|
|||
|
|
@ -291,7 +291,7 @@ public class InitialRoutesTest {
|
|||
.setFleetSize(VehicleRoutingProblem.FleetSize.FINITE).addInitialVehicleRoute(iniRoute).build();
|
||||
|
||||
VehicleRoutingAlgorithm vra = new GreedySchrimpfFactory().createAlgorithm(vrp);
|
||||
vra.setNuOfIterations(10);
|
||||
vra.setMaxIterations(10);
|
||||
|
||||
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
|
||||
|
||||
|
|
@ -304,7 +304,7 @@ public class InitialRoutesTest {
|
|||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem_iniRoutes_2.xml");
|
||||
VehicleRoutingAlgorithm vra = new GreedySchrimpfFactory().createAlgorithm(vrpBuilder.build());
|
||||
vra.setNuOfIterations(10);
|
||||
vra.setMaxIterations(10);
|
||||
|
||||
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
|
||||
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ public class MeetTimeWindowConstraint_IT {
|
|||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
|
||||
VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp);
|
||||
vra.setNuOfIterations(100);
|
||||
vra.setMaxIterations(100);
|
||||
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
|
||||
|
||||
assertEquals(2,Solutions.bestOf(solutions).getRoutes().size());
|
||||
|
|
@ -61,7 +61,7 @@ public class MeetTimeWindowConstraint_IT {
|
|||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
|
||||
VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp);
|
||||
vra.setNuOfIterations(100);
|
||||
vra.setMaxIterations(100);
|
||||
final List<Boolean> testFailed = new ArrayList<Boolean>();
|
||||
vra.addListener(new JobInsertedListener() {
|
||||
|
||||
|
|
@ -93,7 +93,7 @@ public class MeetTimeWindowConstraint_IT {
|
|||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
|
||||
VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp);
|
||||
vra.setNuOfIterations(100);
|
||||
vra.setMaxIterations(100);
|
||||
final List<Boolean> testFailed = new ArrayList<Boolean>();
|
||||
vra.addListener(new VehicleSwitchedListener() {
|
||||
|
||||
|
|
@ -132,7 +132,7 @@ public class MeetTimeWindowConstraint_IT {
|
|||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
|
||||
VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp);
|
||||
vra.setNuOfIterations(100);
|
||||
vra.setMaxIterations(100);
|
||||
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
|
||||
|
||||
assertEquals(2,Solutions.bestOf(solutions).getRoutes().size());
|
||||
|
|
@ -145,7 +145,7 @@ public class MeetTimeWindowConstraint_IT {
|
|||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
|
||||
VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp);
|
||||
vra.setNuOfIterations(100);
|
||||
vra.setMaxIterations(100);
|
||||
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
|
||||
|
||||
// assertEquals(2,Solutions.bestOf(solutions).getRoutes().size());
|
||||
|
|
@ -159,7 +159,7 @@ public class MeetTimeWindowConstraint_IT {
|
|||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
|
||||
VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp);
|
||||
vra.setNuOfIterations(100);
|
||||
vra.setMaxIterations(100);
|
||||
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
|
||||
|
||||
// assertEquals(2,Solutions.bestOf(solutions).getRoutes().size());
|
||||
|
|
@ -176,7 +176,7 @@ public class MeetTimeWindowConstraint_IT {
|
|||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
|
||||
VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/schrimpf_vehicleSwitchNotAllowed.xml");
|
||||
vra.setNuOfIterations(100);
|
||||
vra.setMaxIterations(100);
|
||||
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
|
||||
|
||||
assertEquals(2,Solutions.bestOf(solutions).getRoutes().size());
|
||||
|
|
@ -189,7 +189,7 @@ public class MeetTimeWindowConstraint_IT {
|
|||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
|
||||
VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/schrimpf_vehicleSwitchNotAllowed.xml");
|
||||
vra.setNuOfIterations(100);
|
||||
vra.setMaxIterations(100);
|
||||
final List<Boolean> testFailed = new ArrayList<Boolean>();
|
||||
vra.addListener(new JobInsertedListener() {
|
||||
|
||||
|
|
@ -221,7 +221,7 @@ public class MeetTimeWindowConstraint_IT {
|
|||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
|
||||
VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/schrimpf_vehicleSwitchNotAllowed.xml");
|
||||
vra.setNuOfIterations(100);
|
||||
vra.setMaxIterations(100);
|
||||
final List<Boolean> testFailed = new ArrayList<Boolean>();
|
||||
vra.addListener(new VehicleSwitchedListener() {
|
||||
|
||||
|
|
@ -260,7 +260,7 @@ public class MeetTimeWindowConstraint_IT {
|
|||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
|
||||
VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/schrimpf_vehicleSwitchNotAllowed.xml");
|
||||
vra.setNuOfIterations(100);
|
||||
vra.setMaxIterations(100);
|
||||
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
|
||||
|
||||
assertEquals(2,Solutions.bestOf(solutions).getRoutes().size());
|
||||
|
|
@ -273,7 +273,7 @@ public class MeetTimeWindowConstraint_IT {
|
|||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
|
||||
VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/schrimpf_vehicleSwitchNotAllowed.xml");
|
||||
vra.setNuOfIterations(100);
|
||||
vra.setMaxIterations(100);
|
||||
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
|
||||
|
||||
assertEquals(2,Solutions.bestOf(solutions).getRoutes().size());
|
||||
|
|
@ -287,7 +287,7 @@ public class MeetTimeWindowConstraint_IT {
|
|||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
|
||||
VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/schrimpf_vehicleSwitchNotAllowed.xml");
|
||||
vra.setNuOfIterations(100);
|
||||
vra.setMaxIterations(100);
|
||||
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
|
||||
|
||||
assertEquals(2,Solutions.bestOf(solutions).getRoutes().size());
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ public class SolomonSkills_IT {
|
|||
constraintManager.addSkillsConstraint();
|
||||
|
||||
VehicleRoutingAlgorithm vra = vraBuilder.build();
|
||||
vra.setNuOfIterations(500);
|
||||
vra.setMaxIterations(500);
|
||||
|
||||
try {
|
||||
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ public class Solomon_IT {
|
|||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
|
||||
VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp,"src/test/resources/algorithmConfig.xml");
|
||||
vra.setNuOfIterations(500);
|
||||
vra.setMaxIterations(500);
|
||||
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
|
||||
assertEquals(828.94, Solutions.bestOf(solutions).getCost(),0.01);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue