From f7ff7aeecab95575a3a45a4ad968c5059149929c Mon Sep 17 00:00:00 2001 From: Stefan Schroeder <4sschroeder@gmail.com> Date: Thu, 22 Aug 2013 17:34:19 +0200 Subject: [PATCH] internale experiments with insertionCalc --- .../java/algorithms/CalculatorBuilder.java | 2 +- ... MarginalsCalculusTriangleInequality.java} | 4 +- .../algorithms/RuinAndRecreateModule.java | 59 ++ .../main/java/algorithms/RuinListeners.java | 5 + .../src/main/java/algorithms/RuinRadial.java | 10 + .../src/main/java/algorithms/RuinRandom.java | 10 + .../main/java/algorithms/RuinStrategy.java | 4 + .../algorithms/UdateCostsAtRouteLevel.java | 2 +- .../algorithms/BuildFastCVRPAlgoTest.java | 97 +++ .../java/algorithms/GendreauPostOptTest.java | 2 +- .../java/algorithms/TestAlgorithmReader.java | 12 + .../TestCalculatesServiceInsertion.java | 2 +- .../src/test/resources/vrpnc1-jsprit.xml | 635 ++++++++++++++++++ jsprit-examples/input/vrpnc1-jsprit.xml | 635 ++++++++++++++++++ jsprit-examples/input/vrpnc1.txt | 52 ++ .../src/main/java/examples/CVRPExample.java | 16 + 16 files changed, 1541 insertions(+), 6 deletions(-) rename jsprit-core/src/main/java/algorithms/{MarginalsCalculusDefault.java => MarginalsCalculusTriangleInequality.java} (92%) create mode 100644 jsprit-core/src/main/java/algorithms/RuinAndRecreateModule.java create mode 100644 jsprit-core/src/test/java/algorithms/BuildFastCVRPAlgoTest.java create mode 100644 jsprit-core/src/test/resources/vrpnc1-jsprit.xml create mode 100644 jsprit-examples/input/vrpnc1-jsprit.xml create mode 100644 jsprit-examples/input/vrpnc1.txt create mode 100644 jsprit-examples/src/main/java/examples/CVRPExample.java diff --git a/jsprit-core/src/main/java/algorithms/CalculatorBuilder.java b/jsprit-core/src/main/java/algorithms/CalculatorBuilder.java index c8c745cb..1caee42d 100644 --- a/jsprit-core/src/main/java/algorithms/CalculatorBuilder.java +++ b/jsprit-core/src/main/java/algorithms/CalculatorBuilder.java @@ -214,7 +214,7 @@ class CalculatorBuilder { } private CalculatorPlusListeners createStandardLocal(VehicleRoutingProblem vrp, StateManager activityStates2){ - MarginalsCalculus defaultCalc = new MarginalsCalculusDefault(vrp.getTransportCosts(), vrp.getActivityCosts(), new HardConstraints.HardTimeWindowConstraint(activityStates2) ); + MarginalsCalculus defaultCalc = new MarginalsCalculusTriangleInequality(vrp.getTransportCosts(), vrp.getActivityCosts(), new HardConstraints.HardTimeWindowConstraint(activityStates2) ); JobInsertionCalculator standardServiceInsertion = new CalculatesServiceInsertion(defaultCalc, new HardConstraints.HardLoadConstraint(activityStates2)); ((CalculatesServiceInsertion) standardServiceInsertion).setNeighborhood(vrp.getNeighborhood()); diff --git a/jsprit-core/src/main/java/algorithms/MarginalsCalculusDefault.java b/jsprit-core/src/main/java/algorithms/MarginalsCalculusTriangleInequality.java similarity index 92% rename from jsprit-core/src/main/java/algorithms/MarginalsCalculusDefault.java rename to jsprit-core/src/main/java/algorithms/MarginalsCalculusTriangleInequality.java index 699779ed..6332bd6e 100644 --- a/jsprit-core/src/main/java/algorithms/MarginalsCalculusDefault.java +++ b/jsprit-core/src/main/java/algorithms/MarginalsCalculusTriangleInequality.java @@ -5,14 +5,14 @@ import basics.costs.VehicleRoutingActivityCosts; import basics.costs.VehicleRoutingTransportCosts; import basics.route.TourActivity; -class MarginalsCalculusDefault implements MarginalsCalculus{ +class MarginalsCalculusTriangleInequality implements MarginalsCalculus{ private HardActivityLevelConstraint hardConstraint; private VehicleRoutingTransportCosts routingCosts; private VehicleRoutingActivityCosts activityCosts; - public MarginalsCalculusDefault(VehicleRoutingTransportCosts routingCosts, VehicleRoutingActivityCosts actCosts, HardActivityLevelConstraint hardActivityLevelConstraint) { + public MarginalsCalculusTriangleInequality(VehicleRoutingTransportCosts routingCosts, VehicleRoutingActivityCosts actCosts, HardActivityLevelConstraint hardActivityLevelConstraint) { super(); this.routingCosts = routingCosts; this.activityCosts = actCosts; diff --git a/jsprit-core/src/main/java/algorithms/RuinAndRecreateModule.java b/jsprit-core/src/main/java/algorithms/RuinAndRecreateModule.java new file mode 100644 index 00000000..f6d12397 --- /dev/null +++ b/jsprit-core/src/main/java/algorithms/RuinAndRecreateModule.java @@ -0,0 +1,59 @@ +package algorithms; + +import java.util.Collection; + +import util.RouteUtils; +import algorithms.RuinStrategy.RuinListener; +import basics.Job; +import basics.VehicleRoutingProblemSolution; +import basics.algo.InsertionListener; +import basics.algo.SearchStrategyModule; +import basics.algo.SearchStrategyModuleListener; + +class RuinAndRecreateModule implements SearchStrategyModule{ + + private InsertionStrategy insertion; + + private RuinStrategy ruin; + + private String moduleName; + + public RuinAndRecreateModule(String moduleName, InsertionStrategy insertion, RuinStrategy ruin) { + super(); + this.insertion = insertion; + this.ruin = ruin; + this.moduleName = moduleName; + } + + @Override + public VehicleRoutingProblemSolution runAndGetSolution(VehicleRoutingProblemSolution vrpSolution) { + Collection ruinedJobs = ruin.ruin(vrpSolution.getRoutes()); + insertion.insertJobs(vrpSolution.getRoutes(), ruinedJobs); + double totalCost = RouteUtils.getTotalCost(vrpSolution.getRoutes()); + vrpSolution.setCost(totalCost); + return vrpSolution; + } + + @Override + public String getName() { + return moduleName; + } + + @Override + public void addModuleListener(SearchStrategyModuleListener moduleListener) { + if(moduleListener instanceof InsertionListener){ + InsertionListener iListener = (InsertionListener) moduleListener; + if(!insertion.getListeners().contains(iListener)){ + insertion.addListener(iListener); + } + } + if(moduleListener instanceof RuinListener){ + RuinListener rListener = (RuinListener) moduleListener; + if(!ruin.getListeners().contains(rListener)){ + ruin.addListener(rListener); + } + } + + } + +} diff --git a/jsprit-core/src/main/java/algorithms/RuinListeners.java b/jsprit-core/src/main/java/algorithms/RuinListeners.java index f48df19d..08b91488 100644 --- a/jsprit-core/src/main/java/algorithms/RuinListeners.java +++ b/jsprit-core/src/main/java/algorithms/RuinListeners.java @@ -2,6 +2,7 @@ package algorithms; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import algorithms.RuinStrategy.RuinListener; import basics.Job; @@ -30,4 +31,8 @@ class RuinListeners { void removeListener(RuinListener ruinListener){ ruinListeners.remove(ruinListener); } + + Collection getListeners(){ + return Collections.unmodifiableCollection(ruinListeners); + } } diff --git a/jsprit-core/src/main/java/algorithms/RuinRadial.java b/jsprit-core/src/main/java/algorithms/RuinRadial.java index f40cf375..2e293468 100644 --- a/jsprit-core/src/main/java/algorithms/RuinRadial.java +++ b/jsprit-core/src/main/java/algorithms/RuinRadial.java @@ -177,5 +177,15 @@ final class RuinRadial implements RuinStrategy { ruinListeners.addListener(ruinListener); } + @Override + public void removeListener(RuinListener ruinListener) { + ruinListeners.removeListener(ruinListener); + } + + @Override + public Collection getListeners() { + return ruinListeners.getListeners(); + } + } diff --git a/jsprit-core/src/main/java/algorithms/RuinRandom.java b/jsprit-core/src/main/java/algorithms/RuinRandom.java index 8079c7fa..3695a2dd 100644 --- a/jsprit-core/src/main/java/algorithms/RuinRandom.java +++ b/jsprit-core/src/main/java/algorithms/RuinRandom.java @@ -145,4 +145,14 @@ final class RuinRandom implements RuinStrategy { ruinListeners.addListener(ruinListener); } + @Override + public void removeListener(RuinListener ruinListener) { + ruinListeners.removeListener(ruinListener); + } + + @Override + public Collection getListeners() { + return ruinListeners.getListeners(); + } + } diff --git a/jsprit-core/src/main/java/algorithms/RuinStrategy.java b/jsprit-core/src/main/java/algorithms/RuinStrategy.java index 18c893cb..603050d7 100644 --- a/jsprit-core/src/main/java/algorithms/RuinStrategy.java +++ b/jsprit-core/src/main/java/algorithms/RuinStrategy.java @@ -81,5 +81,9 @@ interface RuinStrategy { * @param {@link RuinListener} */ public void addListener(RuinListener ruinListener); + + public void removeListener(RuinListener ruinListener); + + public Collection getListeners(); } diff --git a/jsprit-core/src/main/java/algorithms/UdateCostsAtRouteLevel.java b/jsprit-core/src/main/java/algorithms/UdateCostsAtRouteLevel.java index 7ad93067..444de69c 100644 --- a/jsprit-core/src/main/java/algorithms/UdateCostsAtRouteLevel.java +++ b/jsprit-core/src/main/java/algorithms/UdateCostsAtRouteLevel.java @@ -27,7 +27,7 @@ class UdateCostsAtRouteLevel implements JobInsertedListener, InsertionStartsList @Override public void informJobInserted(Job job2insert, VehicleRoute inRoute, double additionalCosts, double additionalTime) { - inRoute.getVehicleRouteCostCalculator().addTransportCost(additionalCosts); +// inRoute.getVehicleRouteCostCalculator().addTransportCost(additionalCosts); } @Override diff --git a/jsprit-core/src/test/java/algorithms/BuildFastCVRPAlgoTest.java b/jsprit-core/src/test/java/algorithms/BuildFastCVRPAlgoTest.java new file mode 100644 index 00000000..a245bf64 --- /dev/null +++ b/jsprit-core/src/test/java/algorithms/BuildFastCVRPAlgoTest.java @@ -0,0 +1,97 @@ +package algorithms; + +import java.util.Collection; + +import org.junit.Before; +import org.junit.Test; + +import util.Solutions; + +import algorithms.HardConstraints.HardActivityLevelConstraint; +import algorithms.acceptors.AcceptNewIfBetterThanWorst; +import algorithms.selectors.SelectBest; +import basics.VehicleRoutingAlgorithm; +import basics.VehicleRoutingProblem; +import basics.VehicleRoutingProblemSolution; +import basics.algo.IterationStartsListener; +import basics.algo.SearchStrategy; +import basics.algo.SearchStrategyManager; +import basics.io.VrpXMLReader; +import basics.route.TourActivity; + +public class BuildFastCVRPAlgoTest { + + VehicleRoutingProblem vrp; + + VehicleRoutingAlgorithm vra; + + @Before + public void setup(){ + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(builder).read("src/test/resources/vrpnc1-jsprit.xml"); + vrp = builder.build(); + + final StateManagerImpl stateManager = new StateManagerImpl(); + HardActivityLevelConstraint hardActLevelConstraint = new HardActivityLevelConstraint() { + + @Override + public boolean fulfilled(InsertionFacts iFacts, TourActivity act, double arrTime) { + return true; + } + }; + MarginalsCalculus marginalCalculus = new MarginalsCalculusTriangleInequality(vrp.getTransportCosts(), vrp.getActivityCosts(), hardActLevelConstraint); + CalculatesServiceInsertion serviceInsertion = new CalculatesServiceInsertion(marginalCalculus, new HardConstraints.HardLoadConstraint(stateManager)); + + VehicleFleetManager fleetManager = new InfiniteVehicles(vrp.getVehicles()); + JobInsertionCalculator finalServiceInsertion = new CalculatesVehTypeDepServiceInsertion(fleetManager, serviceInsertion); + +// UpdateStates stateUpdater = new UpdateStates(stateManager, vrp.getTransportCosts(), vrp.getActivityCosts()); + + BestInsertion bestInsertion = new BestInsertion(finalServiceInsertion); + + RuinRadial radial = new RuinRadial(vrp, 0.3, new JobDistanceAvgCosts(vrp.getTransportCosts())); + RuinRandom random = new RuinRandom(vrp, 0.5); + + SearchStrategy randomStrategy = new SearchStrategy(new SelectBest(), new AcceptNewIfBetterThanWorst(1)); + RuinAndRecreateModule randomModule = new RuinAndRecreateModule("randomRuin_bestInsertion", bestInsertion, random); + randomStrategy.addModule(randomModule); + + SearchStrategy radialStrategy = new SearchStrategy(new SelectBest(), new AcceptNewIfBetterThanWorst(1)); + 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); + + //listeners + IterationStartsListener clearStateManager = new IterationStartsListener() { + + @Override + public void informIterationStarts(int i, VehicleRoutingProblem problem, Collection solutions) { + stateManager.clear(); + } + }; + vra.getAlgorithmListeners().addListener(clearStateManager); + vra.getSearchStrategyManager().addSearchStrategyModuleListener(new RemoveEmptyVehicles(fleetManager)); + + vra.getSearchStrategyManager().addSearchStrategyModuleListener(new UdateCostsAtRouteLevel(stateManager, vrp.getTransportCosts(), vrp.getActivityCosts())); + vra.getSearchStrategyManager().addSearchStrategyModuleListener(new UpdateLoadAtRouteLevel(stateManager)); + + VehicleRoutingProblemSolution iniSolution = new CreateInitialSolution(bestInsertion).createInitialSolution(vrp); + System.out.println("ini: costs="+iniSolution.getCost()+";#routes="+iniSolution.getRoutes().size()); + vra.addInitialSolution(iniSolution); + + vra.setNuOfIterations(1000); + vra.setPrematureBreak(200); + } + + @Test + public void testVRA(){ + Collection solutions = vra.searchSolutions(); + System.out.println("costs="+Solutions.getBest(solutions).getCost()+";#routes="+Solutions.getBest(solutions).getRoutes().size()); + } + +} diff --git a/jsprit-core/src/test/java/algorithms/GendreauPostOptTest.java b/jsprit-core/src/test/java/algorithms/GendreauPostOptTest.java index ee80235e..305451e8 100644 --- a/jsprit-core/src/test/java/algorithms/GendreauPostOptTest.java +++ b/jsprit-core/src/test/java/algorithms/GendreauPostOptTest.java @@ -151,7 +151,7 @@ public class GendreauPostOptTest { activityCosts = new ExampleActivityCostFunction(); - CalculatesServiceInsertion standardServiceInsertion = new CalculatesServiceInsertion(new MarginalsCalculusDefault(cost, activityCosts, new HardConstraints.HardTimeWindowConstraint(states)), new HardConstraints.HardLoadConstraint(states)); + CalculatesServiceInsertion standardServiceInsertion = new CalculatesServiceInsertion(new MarginalsCalculusTriangleInequality(cost, activityCosts, new HardConstraints.HardTimeWindowConstraint(states)), new HardConstraints.HardLoadConstraint(states)); CalculatesServiceInsertionConsideringFixCost withFixCost = new CalculatesServiceInsertionConsideringFixCost(standardServiceInsertion, states); withFixCost.setWeightOfFixCost(1.2); diff --git a/jsprit-core/src/test/java/algorithms/TestAlgorithmReader.java b/jsprit-core/src/test/java/algorithms/TestAlgorithmReader.java index 1698fac9..949cdfa3 100644 --- a/jsprit-core/src/test/java/algorithms/TestAlgorithmReader.java +++ b/jsprit-core/src/test/java/algorithms/TestAlgorithmReader.java @@ -175,6 +175,18 @@ public class TestAlgorithmReader { // TODO Auto-generated method stub } + + @Override + public void removeListener(RuinListener ruinListener) { + // TODO Auto-generated method stub + + } + + @Override + public Collection getListeners() { + // TODO Auto-generated method stub + return null; + } }; diff --git a/jsprit-core/src/test/java/algorithms/TestCalculatesServiceInsertion.java b/jsprit-core/src/test/java/algorithms/TestCalculatesServiceInsertion.java index de649284..69d92379 100644 --- a/jsprit-core/src/test/java/algorithms/TestCalculatesServiceInsertion.java +++ b/jsprit-core/src/test/java/algorithms/TestCalculatesServiceInsertion.java @@ -156,7 +156,7 @@ public class TestCalculatesServiceInsertion { ExampleActivityCostFunction activityCosts = new ExampleActivityCostFunction(); - serviceInsertion = new CalculatesServiceInsertion(new MarginalsCalculusDefault(costs, activityCosts, new HardConstraints.HardTimeWindowConstraint(states)), new HardConstraints.HardLoadConstraint(states)); + serviceInsertion = new CalculatesServiceInsertion(new MarginalsCalculusTriangleInequality(costs, activityCosts, new HardConstraints.HardTimeWindowConstraint(states)), new HardConstraints.HardLoadConstraint(states)); stateUpdater = new UpdateStates(states, costs, activityCosts); diff --git a/jsprit-core/src/test/resources/vrpnc1-jsprit.xml b/jsprit-core/src/test/resources/vrpnc1-jsprit.xml new file mode 100644 index 00000000..5d3ff044 --- /dev/null +++ b/jsprit-core/src/test/resources/vrpnc1-jsprit.xml @@ -0,0 +1,635 @@ + + + + INFINITE + HOMOGENEOUS + + + + christophidesVehicle + christophidesType + + [x=30.0][y=40.0] + + + + 0.0 + 999999.0 + + + + + + christophidesType + 160 + + 0.0 + 1.0 + + + + + + + [x=62.0][y=63.0] + + 17 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=63.0][y=69.0] + + 6 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=46.0][y=10.0] + + 23 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=61.0][y=33.0] + + 26 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=59.0][y=15.0] + + 14 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=32.0][y=22.0] + + 9 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=45.0][y=35.0] + + 15 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=5.0][y=64.0] + + 11 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=21.0][y=10.0] + + 13 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=10.0][y=17.0] + + 27 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=5.0][y=6.0] + + 7 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=42.0][y=57.0] + + 8 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=16.0][y=57.0] + + 16 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=8.0][y=52.0] + + 10 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=7.0][y=38.0] + + 28 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=27.0][y=68.0] + + 7 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=30.0][y=48.0] + + 15 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=43.0][y=67.0] + + 14 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=58.0][y=48.0] + + 6 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=52.0][y=64.0] + + 16 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=49.0][y=49.0] + + 30 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=37.0][y=52.0] + + 7 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=17.0][y=63.0] + + 19 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=58.0][y=27.0] + + 19 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=21.0][y=47.0] + + 15 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=40.0][y=30.0] + + 21 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=38.0][y=46.0] + + 12 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=20.0][y=26.0] + + 9 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=37.0][y=69.0] + + 11 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=52.0][y=33.0] + + 11 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=31.0][y=62.0] + + 23 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=13.0][y=13.0] + + 9 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=27.0][y=23.0] + + 3 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=17.0][y=33.0] + + 41 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=36.0][y=16.0] + + 10 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=52.0][y=41.0] + + 15 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=5.0][y=25.0] + + 23 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=12.0][y=42.0] + + 21 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=42.0][y=41.0] + + 19 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=31.0][y=32.0] + + 29 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=62.0][y=42.0] + + 8 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=57.0][y=58.0] + + 28 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=48.0][y=28.0] + + 18 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=25.0][y=55.0] + + 17 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=39.0][y=10.0] + + 10 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=30.0][y=15.0] + + 16 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=25.0][y=32.0] + + 25 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=32.0][y=39.0] + + 5 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=51.0][y=21.0] + + 5 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=56.0][y=37.0] + + 10 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + diff --git a/jsprit-examples/input/vrpnc1-jsprit.xml b/jsprit-examples/input/vrpnc1-jsprit.xml new file mode 100644 index 00000000..5d3ff044 --- /dev/null +++ b/jsprit-examples/input/vrpnc1-jsprit.xml @@ -0,0 +1,635 @@ + + + + INFINITE + HOMOGENEOUS + + + + christophidesVehicle + christophidesType + + [x=30.0][y=40.0] + + + + 0.0 + 999999.0 + + + + + + christophidesType + 160 + + 0.0 + 1.0 + + + + + + + [x=62.0][y=63.0] + + 17 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=63.0][y=69.0] + + 6 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=46.0][y=10.0] + + 23 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=61.0][y=33.0] + + 26 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=59.0][y=15.0] + + 14 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=32.0][y=22.0] + + 9 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=45.0][y=35.0] + + 15 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=5.0][y=64.0] + + 11 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=21.0][y=10.0] + + 13 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=10.0][y=17.0] + + 27 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=5.0][y=6.0] + + 7 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=42.0][y=57.0] + + 8 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=16.0][y=57.0] + + 16 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=8.0][y=52.0] + + 10 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=7.0][y=38.0] + + 28 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=27.0][y=68.0] + + 7 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=30.0][y=48.0] + + 15 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=43.0][y=67.0] + + 14 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=58.0][y=48.0] + + 6 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=52.0][y=64.0] + + 16 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=49.0][y=49.0] + + 30 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=37.0][y=52.0] + + 7 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=17.0][y=63.0] + + 19 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=58.0][y=27.0] + + 19 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=21.0][y=47.0] + + 15 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=40.0][y=30.0] + + 21 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=38.0][y=46.0] + + 12 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=20.0][y=26.0] + + 9 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=37.0][y=69.0] + + 11 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=52.0][y=33.0] + + 11 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=31.0][y=62.0] + + 23 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=13.0][y=13.0] + + 9 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=27.0][y=23.0] + + 3 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=17.0][y=33.0] + + 41 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=36.0][y=16.0] + + 10 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=52.0][y=41.0] + + 15 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=5.0][y=25.0] + + 23 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=12.0][y=42.0] + + 21 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=42.0][y=41.0] + + 19 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=31.0][y=32.0] + + 29 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=62.0][y=42.0] + + 8 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=57.0][y=58.0] + + 28 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=48.0][y=28.0] + + 18 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=25.0][y=55.0] + + 17 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=39.0][y=10.0] + + 10 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=30.0][y=15.0] + + 16 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=25.0][y=32.0] + + 25 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=32.0][y=39.0] + + 5 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=51.0][y=21.0] + + 5 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=56.0][y=37.0] + + 10 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + diff --git a/jsprit-examples/input/vrpnc1.txt b/jsprit-examples/input/vrpnc1.txt new file mode 100644 index 00000000..7296a49f --- /dev/null +++ b/jsprit-examples/input/vrpnc1.txt @@ -0,0 +1,52 @@ + 50 160 999999 0 + 30 40 + 37 52 7 + 49 49 30 + 52 64 16 + 20 26 9 + 40 30 21 + 21 47 15 + 17 63 19 + 31 62 23 + 52 33 11 + 51 21 5 + 42 41 19 + 31 32 29 + 5 25 23 + 12 42 21 + 36 16 10 + 52 41 15 + 27 23 3 + 17 33 41 + 13 13 9 + 57 58 28 + 62 42 8 + 42 57 8 + 16 57 16 + 8 52 10 + 7 38 28 + 27 68 7 + 30 48 15 + 43 67 14 + 58 48 6 + 58 27 19 + 37 69 11 + 38 46 12 + 46 10 23 + 61 33 26 + 62 63 17 + 63 69 6 + 32 22 9 + 45 35 15 + 59 15 14 + 5 6 7 + 10 17 27 + 21 10 13 + 5 64 11 + 30 15 16 + 39 10 10 + 32 39 5 + 25 32 25 + 25 55 17 + 48 28 18 + 56 37 10 diff --git a/jsprit-examples/src/main/java/examples/CVRPExample.java b/jsprit-examples/src/main/java/examples/CVRPExample.java new file mode 100644 index 00000000..3196a732 --- /dev/null +++ b/jsprit-examples/src/main/java/examples/CVRPExample.java @@ -0,0 +1,16 @@ +package examples; + +import readers.ChristofidesReader; +import basics.VehicleRoutingProblem; +import basics.io.VrpXMLWriter; + +public class CVRPExample { + + public static void main(String[] args) { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + new ChristofidesReader(builder).read("input/vrpnc1.txt"); + VehicleRoutingProblem vrp = builder.build(); + new VrpXMLWriter(vrp).write("input/vrpnc1-jsprit.xml"); + } + +}