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

modify SolomonExamply to comply with corresponding wiki-example

This commit is contained in:
Stefan Schroeder 2013-06-10 17:26:23 +02:00
parent 8f5ebf18e3
commit a113a6cf18

View file

@ -23,7 +23,8 @@ package examples;
import java.util.Collection; import java.util.Collection;
import readers.SolomonReader; import readers.SolomonReader;
import algorithms.VehicleRoutingAlgorithms; import algorithms.GreedySchrimpfFactory;
import algorithms.SchrimpfFactory;
import algorithms.selectors.SelectBest; import algorithms.selectors.SelectBest;
import analysis.AlgorithmSearchProgressChartListener; import analysis.AlgorithmSearchProgressChartListener;
import analysis.SolutionPlotter; import analysis.SolutionPlotter;
@ -34,13 +35,12 @@ import basics.VehicleRoutingAlgorithm;
import basics.VehicleRoutingProblem; import basics.VehicleRoutingProblem;
import basics.VehicleRoutingProblemSolution; import basics.VehicleRoutingProblemSolution;
import basics.algo.VehicleRoutingAlgorithmListeners.Priority; import basics.algo.VehicleRoutingAlgorithmListeners.Priority;
import basics.io.AlgorithmConfig;
import basics.io.AlgorithmConfigXmlReader;
public class SolomonExample { public class SolomonExample {
public static void main(String[] args) { public static void main(String[] args) {
/* /*
* Build the problem. * Build the problem.
* *
@ -58,29 +58,15 @@ public class SolomonExample {
*/ */
VehicleRoutingProblem vrp = vrpBuilder.build(); VehicleRoutingProblem vrp = vrpBuilder.build();
SolutionPlotter.plotVrpAsPNG(vrp, "output/solomon_C101.png", "C101");
/* /*
* Define the required vehicle-routing algorithms to solve the above problem. * Define the required vehicle-routing algorithms to solve the above problem.
* *
* The algorithm can be defined and configured in an xml-file. * The algorithm can be defined and configured in an xml-file.
*/ */
AlgorithmConfig algorithmConfig = new AlgorithmConfig(); VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp);
new AlgorithmConfigXmlReader(algorithmConfig).read("input/algorithmConfig_solomon.xml");
VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.createAlgorithm(vrp, algorithmConfig);
vra.setPrematureBreak(500);
/*
* Listen to the search-progress.
*/
vra.getAlgorithmListeners().addListener(new AlgorithmSearchProgressChartListener("output/searchProgress.png"));
/*
* StopWatch to measure computation time.
*/
StopWatch stopWatch = new StopWatch();
vra.getAlgorithmListeners().addListener(stopWatch,Priority.HIGH);
// vra.setPrematureBreak(200);
/* /*
* Solve the problem. * Solve the problem.
* *
@ -93,21 +79,13 @@ public class SolomonExample {
*/ */
VehicleRoutingProblemSolution solution = new SelectBest().selectSolution(solutions); VehicleRoutingProblemSolution solution = new SelectBest().selectSolution(solutions);
/*
* Print computation time.
*/
System.out.println(stopWatch);
/*
* Print solution.
*/
SolutionPrinter.print(solution, Print.VERBOSE);
/* /*
* Plot solution. * Plot solution.
*/ */
SolutionPlotter.plotSolutionAsPNG(vrp, solution, "output/solomonSolution.png","C101"); SolutionPlotter.plotSolutionAsPNG(vrp, solution, "output/solomon_C101_solution.png","C101");
} }