1
0
Fork 0
mirror of https://github.com/graphhopper/jsprit.git synced 2020-01-24 07:45:05 +01:00
This commit is contained in:
oblonski 2015-10-06 12:44:16 +02:00
parent 5051b6960b
commit 966dc6e901
63 changed files with 1447 additions and 1466 deletions

View file

@ -38,71 +38,70 @@ import java.util.Collection;
public class BreakExample {
public static void main(String[] args) {
public static void main(String[] args) {
/*
* get a vehicle type-builder and build a type with the typeId "vehicleType" and one capacity dimension, i.e. weight, and capacity dimension value of 2
* get a vehicle type-builder and build a type with the typeId "vehicleType" and one capacity dimension, i.e. weight, and capacity dimension value of 2
*/
final int WEIGHT_INDEX = 0;
VehicleTypeImpl.Builder vehicleTypeBuilder = VehicleTypeImpl.Builder.newInstance("vehicleType")
.addCapacityDimension(WEIGHT_INDEX, 2).setCostPerWaitingTime(1.0);
VehicleType vehicleType = vehicleTypeBuilder.build();
final int WEIGHT_INDEX = 0;
VehicleTypeImpl.Builder vehicleTypeBuilder = VehicleTypeImpl.Builder.newInstance("vehicleType")
.addCapacityDimension(WEIGHT_INDEX, 2).setCostPerWaitingTime(1.0);
VehicleType vehicleType = vehicleTypeBuilder.build();
/*
* get a vehicle-builder and build a vehicle located at (10,10) with type "vehicleType"
*/
Builder vehicleBuilder = Builder.newInstance("v1");
vehicleBuilder.setStartLocation(Location.newInstance(10, 10));
Break myFirstBreak = Break.Builder.newInstance("myFirstBreak")
Builder vehicleBuilder = Builder.newInstance("v1");
vehicleBuilder.setStartLocation(Location.newInstance(10, 10));
Break myFirstBreak = Break.Builder.newInstance("myFirstBreak")
.setTimeWindow(TimeWindow.newInstance(10, 15)).setServiceTime(100).build();
vehicleBuilder.setBreak(myFirstBreak);
vehicleBuilder.setType(vehicleType);
VehicleImpl vehicle = vehicleBuilder.build();
vehicleBuilder.setBreak(myFirstBreak);
vehicleBuilder.setType(vehicleType);
VehicleImpl vehicle = vehicleBuilder.build();
VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(Location.newInstance(0, 10)).setType(vehicleType)
.setBreak((Break) Break.Builder.newInstance("mySecondBreak").setTimeWindow(TimeWindow.newInstance(5,10)).setServiceTime(10).build()).build();
VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(Location.newInstance(0, 10)).setType(vehicleType)
.setBreak((Break) Break.Builder.newInstance("mySecondBreak").setTimeWindow(TimeWindow.newInstance(5, 10)).setServiceTime(10).build()).build();
/*
* build services at the required locations, each with a capacity-demand of 1.
*/
Service service1 = Service.Builder.newInstance("1").addSizeDimension(WEIGHT_INDEX, 1).setLocation(Location.newInstance(5, 7)).build();
Service service2 = Service.Builder.newInstance("2").addSizeDimension(WEIGHT_INDEX, 1).setLocation(Location.newInstance(5, 13)).build();
Service service1 = Service.Builder.newInstance("1").addSizeDimension(WEIGHT_INDEX, 1).setLocation(Location.newInstance(5, 7)).build();
Service service2 = Service.Builder.newInstance("2").addSizeDimension(WEIGHT_INDEX, 1).setLocation(Location.newInstance(5, 13)).build();
Service service3 = Service.Builder.newInstance("3").addSizeDimension(WEIGHT_INDEX, 1).setLocation(Location.newInstance(15, 7)).build();
Service service4 = Service.Builder.newInstance("4").addSizeDimension(WEIGHT_INDEX, 1).setLocation(Location.newInstance(15, 13)).build();
Service service3 = Service.Builder.newInstance("3").addSizeDimension(WEIGHT_INDEX, 1).setLocation(Location.newInstance(15, 7)).build();
Service service4 = Service.Builder.newInstance("4").addSizeDimension(WEIGHT_INDEX, 1).setLocation(Location.newInstance(15, 13)).build();
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
vrpBuilder.addVehicle(vehicle);
vrpBuilder.addJob(service1).addJob(service2).addJob(service3).addJob(service4).addVehicle(v2);
vrpBuilder.setFleetSize(VehicleRoutingProblem.FleetSize.FINITE);
VehicleRoutingProblem problem = vrpBuilder.build();
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
vrpBuilder.addVehicle(vehicle);
vrpBuilder.addJob(service1).addJob(service2).addJob(service3).addJob(service4).addVehicle(v2);
vrpBuilder.setFleetSize(VehicleRoutingProblem.FleetSize.FINITE);
VehicleRoutingProblem problem = vrpBuilder.build();
/*
* get the algorithm out-of-the-box.
*/
VehicleRoutingAlgorithm algorithm = Jsprit.Builder.newInstance(problem)
.setProperty(Jsprit.Strategy.CLUSTER_REGRET,"0.")
.setProperty(Jsprit.Strategy.CLUSTER_BEST,"0.").buildAlgorithm();
VehicleRoutingAlgorithm algorithm = Jsprit.Builder.newInstance(problem)
.setProperty(Jsprit.Strategy.CLUSTER_REGRET, "0.")
.setProperty(Jsprit.Strategy.CLUSTER_BEST, "0.").buildAlgorithm();
/*
* and search a solution
*/
Collection<VehicleRoutingProblemSolution> solutions = algorithm.searchSolutions();
Collection<VehicleRoutingProblemSolution> solutions = algorithm.searchSolutions();
/*
* get the best
*/
VehicleRoutingProblemSolution bestSolution = Solutions.bestOf(solutions);
VehicleRoutingProblemSolution bestSolution = Solutions.bestOf(solutions);
SolutionPrinter.print(problem, bestSolution, SolutionPrinter.Print.VERBOSE);
SolutionPrinter.print(problem, bestSolution, SolutionPrinter.Print.VERBOSE);
/*
* plot
*/
new Plotter(problem,bestSolution).plot("output/plot","breaks");
new Plotter(problem, bestSolution).plot("output/plot", "breaks");
}
}
}

View file

@ -96,7 +96,7 @@ public class ConfigureAlgorithmInCodeInsteadOfPerXml {
SolutionPrinter.print(bestSolution);
/*
* plot
* plot
*/
new Plotter(problem, bestSolution).plot("output/solution.png", "solution");
}

View file

@ -131,7 +131,7 @@ public class EnRoutePickupAndDeliveryWithMultipleDepotsAndOpenRoutesExample {
Collection<VehicleRoutingProblemSolution> solutions = algorithm.searchSolutions();
/*
* get the best
* get the best
*/
VehicleRoutingProblemSolution bestSolution = Solutions.bestOf(solutions);

View file

@ -96,7 +96,7 @@ public class MultipleDepotExample {
// SolutionPlotter.plotVrpAsPNG(vrp, "output/problem01.png", "p01");
/*
* solve the problem
* solve the problem
*/
VehicleRoutingAlgorithm vra = Jsprit.Builder.newInstance(vrp).setProperty(Jsprit.Parameter.THREADS, "5").buildAlgorithm();
vra.getAlgorithmListeners().addListener(new StopWatch(), Priority.HIGH);

View file

@ -102,7 +102,7 @@ public class MultipleDepotExample2 {
// SolutionPlotter.plotVrpAsPNG(vrp, "output/problem08.png", "p08");
/*
* solve the problem
* solve the problem
*/
VehicleRoutingAlgorithm vra = Jsprit.Builder.newInstance(vrp).setProperty(Jsprit.Parameter.THREADS, "5").buildAlgorithm();
vra.setMaxIterations(2000);

View file

@ -69,7 +69,7 @@ public class MultipleDepotWithInitialRoutesExample {
assert !vrp.getJobs().containsKey("44") : "strange. service 44 should not be part of the problem";
/*
* plot to see how the problem looks like
* plot to see how the problem looks like
*/
new Plotter(vrp).setLabel(Label.ID).plot("output/cordeau01_problem_withInitialRoute.png", "c");

View file

@ -79,7 +79,7 @@ public class PickupAndDeliveryExample {
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
/*
* Retrieve best solution.
* Retrieve best solution.
*/
VehicleRoutingProblemSolution solution = new SelectBest().selectSolution(solutions);

View file

@ -83,7 +83,7 @@ public class PickupAndDeliveryExample2 {
VehicleRoutingProblemSolution solution = new SelectBest().selectSolution(solutions);
/*
* print solution
* print solution
*/
SolutionPrinter.print(solution);

View file

@ -76,7 +76,7 @@ public class PickupAndDeliveryOpenExample {
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
/*
* Retrieve best solution.
* Retrieve best solution.
*/
VehicleRoutingProblemSolution solution = new SelectBest().selectSolution(solutions);

View file

@ -113,7 +113,7 @@ public class RefuseCollectionExample {
* build service
*/
Service service = Service.Builder.newInstance(lineTokens[0]).addSizeDimension(0, Integer.parseInt(lineTokens[1])).setLocation(Location.newInstance(lineTokens[0])).build();
/*
/*
* and add it to problem
*/
vrpBuilder.addJob(service);

View file

@ -115,7 +115,7 @@ public class RefuseCollectionWithFastMatrixExample {
.addSizeDimension(0, Integer.parseInt(lineTokens[1]))
.setLocation(Location.Builder.newInstance().setIndex(Integer.parseInt(lineTokens[0])).build())
.build();
/*
/*
* and add it to problem
*/
vrpBuilder.addJob(service);

View file

@ -114,7 +114,7 @@ public class ServicePickupsWithMultipleDepotsExample {
VehicleRoutingProblemSolution bestSolution = Solutions.bestOf(solutions);
/*
* write out problem and solution to xml-file
* write out problem and solution to xml-file
*/
new VrpXMLWriter(problem, solutions).write("output/shipment-problem-with-solution.xml");

View file

@ -97,7 +97,7 @@ public class SimpleDepotBoundedPickupAndDeliveryExample {
SolutionPrinter.print(bestSolution);
/*
* plot
* plot
*/
Plotter plotter = new Plotter(problem, bestSolution);
plotter.setLabel(Label.SIZE);

View file

@ -98,7 +98,7 @@ public class SimpleEnRoutePickupAndDeliveryExample {
VehicleRoutingProblemSolution bestSolution = Solutions.bestOf(solutions);
/*
* write out problem and solution to xml-file
* write out problem and solution to xml-file
*/
new VrpXMLWriter(problem, solutions).write("output/shipment-problem-with-solution.xml");

View file

@ -98,7 +98,7 @@ public class SimpleEnRoutePickupAndDeliveryOpenRoutesExample {
VehicleRoutingProblemSolution bestSolution = Solutions.bestOf(solutions);
/*
* write out problem and solution to xml-file
* write out problem and solution to xml-file
*/
new VrpXMLWriter(problem, solutions).write("output/shipment-problem-with-solution.xml");

View file

@ -109,7 +109,7 @@ public class SimpleEnRoutePickupAndDeliveryWithDepotBoundedDeliveriesExample {
VehicleRoutingAlgorithm algorithm = vraBuilder.build();
/*
* and search a solution
* and search a solution
*/
Collection<VehicleRoutingProblemSolution> solutions = algorithm.searchSolutions();

View file

@ -102,7 +102,7 @@ public class SimpleExample {
SolutionPrinter.print(problem, bestSolution, SolutionPrinter.Print.VERBOSE);
/*
* plot
* plot
*/
// SolutionPlotter.plotSolutionAsPNG(problem, bestSolution, "output/solution.png", "solution");

View file

@ -96,7 +96,7 @@ public class SimpleExampleOpenRoutes {
SolutionPrinter.print(bestSolution);
/*
* plot
* plot
*/
new Plotter(problem, bestSolution).plot("output/solution.png", "solution");

View file

@ -124,7 +124,7 @@ public class SimpleExampleWithSkills {
SolutionPrinter.print(problem, bestSolution, SolutionPrinter.Print.VERBOSE);
/*
* plot
* plot
*/
// SolutionPlotter.plotSolutionAsPNG(problem, bestSolution, "output/solution.png", "solution");

View file

@ -80,7 +80,7 @@ public class SolomonExample {
/*
* print solution
* print solution
*/
SolutionPrinter.print(vrp, solution, SolutionPrinter.Print.VERBOSE);

View file

@ -84,7 +84,7 @@ public class SolomonExampleWithSpecifiedVehicleEndLocations {
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
/*
* Retrieve best solution.
* Retrieve best solution.
*/
VehicleRoutingProblemSolution solution = new SelectBest().selectSolution(solutions);

View file

@ -84,7 +84,7 @@ public class SolomonExampleWithSpecifiedVehicleEndLocationsWithoutTWs {
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
/*
* Retrieve best solution.
* Retrieve best solution.
*/
VehicleRoutingProblemSolution solution = new SelectBest().selectSolution(solutions);

View file

@ -76,7 +76,7 @@ public class SolomonOpenExample {
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
/*
* Retrieve best solution.
* Retrieve best solution.
*/
VehicleRoutingProblemSolution solution = new SelectBest().selectSolution(solutions);

View file

@ -69,7 +69,7 @@ public class SolomonR101Example {
// vra.setPrematureBreak(100);
vra.getAlgorithmListeners().addListener(new AlgorithmSearchProgressChartListener("output/sol_progress.png"));
/*
* Solve the problem.
* Solve the problem.
*
*
*/

View file

@ -87,7 +87,7 @@ public class SolomonWithRegretInsertionExample {
/*
* print solution
* print solution
*/
SolutionPrinter.print(vrp, solution, SolutionPrinter.Print.VERBOSE);

View file

@ -191,7 +191,7 @@ public class TransportOfDisabledPeople {
Collection<VehicleRoutingProblemSolution> solutions = algorithm.searchSolutions();
/*
* get the best
* get the best
*/
VehicleRoutingProblemSolution bestSolution = Solutions.bestOf(solutions);

View file

@ -84,7 +84,7 @@ public class VRPWithBackhaulsExample {
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
/*
* Retrieve best solution.
* Retrieve best solution.
*/
VehicleRoutingProblemSolution solution = new SelectBest().selectSolution(solutions);

View file

@ -110,7 +110,7 @@ public class VRPWithBackhaulsExample2 {
VehicleRoutingProblemSolution solution = new SelectBest().selectSolution(solutions);
/*
* print solution
* print solution
*/
SolutionPrinter.print(solution);