From 02c3c96e9c4a4d18bb43ad6eb8e50ddc19336154 Mon Sep 17 00:00:00 2001 From: oblonski Date: Fri, 11 Dec 2015 17:40:41 +0100 Subject: [PATCH] merged master into multiple tw branch --- .editorconfig | 13 + CHANGELOG.md | 12 + README.md | 2 +- WHATS_NEW.md | 5 + jsprit-analysis/pom.xml | 147 +- .../toolbox/AlgorithmEventsRecorder.java | 197 +- .../toolbox/AlgorithmEventsViewer.java | 22 +- .../AlgorithmSearchProgressChartListener.java | 93 +- .../toolbox/ComputationalLaboratory.java | 839 +- .../toolbox/ConcurrentBenchmarker.java | 342 +- .../analysis/toolbox/GraphStreamViewer.java | 792 +- .../toolbox/NoLocationFoundException.java | 24 +- .../java/jsprit/analysis/toolbox/Plotter.java | 1089 ++- .../jsprit/analysis/toolbox/StopWatch.java | 100 +- .../analysis/toolbox/XYLineChartBuilder.java | 158 +- .../jsprit/analysis/util/BenchmarkWriter.java | 16 +- .../util/HtmlBenchmarkTableWriter.java | 449 +- jsprit-core/pom.xml | 171 +- .../InsertionInitialSolutionFactory.java | 59 +- .../algorithm/PrettyAlgorithmBuilder.java | 56 +- .../core/algorithm/RemoveEmptyVehicles.java | 52 +- .../algorithm/ResetAndIniFleetManager.java | 48 +- .../jsprit/core/algorithm/SearchStrategy.java | 198 +- .../core/algorithm/SearchStrategyManager.java | 143 +- .../core/algorithm/SearchStrategyModule.java | 20 +- ...lusFixedSolutionCostCalculatorFactory.java | 59 +- .../algorithm/VehicleRoutingAlgorithm.java | 326 +- .../VehicleRoutingAlgorithmBuilder.java | 256 +- .../VehicleRoutingAlgorithmFactory.java | 14 +- .../acceptor/AcceptNewRemoveFirst.java | 54 +- .../ExperimentalSchrimpfAcceptance.java | 222 +- .../algorithm/acceptor/GreedyAcceptance.java | 80 +- .../GreedyAcceptance_minVehFirst.java | 87 +- .../acceptor/SchrimpfAcceptance.java | 183 +- .../SchrimpfInitialThresholdGenerator.java | 92 +- .../algorithm/acceptor/SolutionAcceptor.java | 27 +- .../box/ConcurrentInsertionNoiseMaker.java | 61 + .../algorithm/box/GreedySchrimpfFactory.java | 59 +- .../algorithm/box/InsertionNoiseMaker.java | 68 +- .../jsprit/core/algorithm/box/Jsprit.java | 410 +- .../core/algorithm/box/SchrimpfFactory.java | 59 +- .../core/algorithm/io/AlgorithmConfig.java | 30 +- .../io/AlgorithmConfigXmlReader.java | 123 +- .../core/algorithm/io/InsertionFactory.java | 149 +- .../io/VehicleRoutingAlgorithms.java | 1462 ++-- .../listener/AlgorithmEndsListener.java | 16 +- .../listener/AlgorithmStartsListener.java | 16 +- .../listener/IterationEndsListener.java | 19 +- .../listener/IterationStartsListener.java | 18 +- .../listener/SearchStrategyListener.java | 12 +- .../SearchStrategyModuleListener.java | 12 +- .../listener/StrategySelectedListener.java | 16 +- .../VehicleRoutingAlgorithmListener.java | 10 +- .../VehicleRoutingAlgorithmListeners.java | 259 +- .../module/RuinAndRecreateModule.java | 100 +- .../recreate/AbstractInsertionStrategy.java | 14 +- .../ActivityInsertionCostsCalculator.java | 57 +- .../AdditionalAccessEgressCalculator.java | 86 +- .../recreate/AuxilliaryCostCalculator.java | 82 +- .../algorithm/recreate/BestInsertion.java | 83 +- .../recreate/BestInsertionBuilder.java | 260 +- .../recreate/BestInsertionConcurrent.java | 300 +- .../recreate/BreakInsertionCalculator.java | 179 + ...tesServiceInsertionWithTimeScheduling.java | 23 +- ...ceInsertionWithTimeSchedulingInSlices.java | 107 +- .../recreate/ConfigureFixCostCalculator.java | 66 +- ...igureLocalActivityInsertionCalculator.java | 40 + .../algorithm/recreate/DefaultScorer.java | 83 + .../recreate/DellAmicoFixCostCalculator.java | 72 +- .../algorithm/recreate/EventListeners.java | 5 +- .../recreate/InsertActivityListener.java | 8 +- .../core/algorithm/recreate/InsertBreak.java | 42 + .../recreate/InsertBreakListener.java | 37 + .../core/algorithm/recreate/Inserter.java | 187 +- .../algorithm/recreate/InsertionBuilder.java | 281 +- .../algorithm/recreate/InsertionData.java | 250 +- .../recreate/InsertionDataUpdater.java | 157 + .../algorithm/recreate/InsertionStrategy.java | 31 +- .../recreate/InsertionStrategyFactory.java | 14 +- .../recreate/JobCalculatorSwitcher.java | 38 +- ...nsertionConsideringFixCostsCalculator.java | 190 +- .../recreate/JobInsertionCostsCalculator.java | 16 +- .../JobInsertionCostsCalculatorBuilder.java | 501 +- .../JobInsertionCostsCalculatorLight.java | 4 +- ...bInsertionCostsCalculatorLightFactory.java | 12 +- ...LocalActivityInsertionCostsCalculator.java | 125 +- .../recreate/NoSolutionFoundException.java | 28 +- .../algorithm/recreate/RegretInsertion.java | 287 +- .../recreate/RegretInsertionConcurrent.java | 146 +- .../RegretInsertionConcurrentFast.java | 196 + .../recreate/RegretInsertionFast.java | 173 + ...eLevelActivityInsertionCostsEstimator.java | 102 +- .../core/algorithm/recreate/ScoredJob.java | 57 + .../algorithm/recreate/ScoringFunction.java | 12 + .../recreate/ServiceInsertionCalculator.java | 204 +- ...erviceInsertionOnRouteLevelCalculator.java | 464 +- .../recreate/ShipmentInsertionCalculator.java | 275 +- .../recreate/SwitchVehicleListener.java | 24 +- .../VariableTransportCostCalculator.java | 71 +- .../algorithm/recreate/VehicleSwitched.java | 34 +- ...leTypeDependentJobInsertionCalculator.java | 183 +- .../recreate/VersionedInsertionData.java | 33 + .../listener/BeforeJobInsertionListener.java | 14 +- .../listener/InsertionEndsListener.java | 13 +- .../recreate/listener/InsertionListener.java | 16 +- .../recreate/listener/InsertionListeners.java | 116 +- .../listener/InsertionStartsListener.java | 15 +- .../listener/JobInsertedListener.java | 18 +- .../listener/VehicleSwitchedListener.java | 16 +- .../algorithm/ruin/AbstractRuinStrategy.java | 26 +- .../core/algorithm/ruin/DBSCANClusterer.java | 114 +- .../core/algorithm/ruin/JobNeighborhoods.java | 6 +- .../ruin/JobNeighborhoodsFactory.java | 8 +- .../algorithm/ruin/JobNeighborhoodsImpl.java | 44 +- ...obNeighborhoodsImplWithCapRestriction.java | 57 +- .../ruin/NearestNeighborhoodIterator.java | 9 +- .../ruin/RadialRuinStrategyFactory.java | 40 +- .../ruin/RandomRuinStrategyFactory.java | 34 +- .../core/algorithm/ruin/ReferencedJob.java | 4 +- .../core/algorithm/ruin/RuinBreaks.java | 38 + .../core/algorithm/ruin/RuinClusters.java | 251 +- .../core/algorithm/ruin/RuinRadial.java | 195 +- .../ruin/RuinRadialMultipleCenters.java | 176 +- .../core/algorithm/ruin/RuinRandom.java | 119 +- .../core/algorithm/ruin/RuinStrategy.java | 55 +- .../algorithm/ruin/RuinStrategyFactory.java | 14 +- .../jsprit/core/algorithm/ruin/RuinWorst.java | 215 +- .../AvgServiceAndShipmentDistance.java | 115 +- .../ruin/distance/AvgServiceDistance.java | 87 +- .../distance/EuclideanServiceDistance.java | 45 +- .../algorithm/ruin/distance/JobDistance.java | 13 +- .../algorithm/ruin/listener/RuinListener.java | 65 +- .../ruin/listener/RuinListeners.java | 51 +- .../core/algorithm/selector/SelectBest.java | 70 +- .../algorithm/selector/SelectRandomly.java | 54 +- .../algorithm/selector/SolutionSelector.java | 15 +- .../core/algorithm/state/InternalStates.java | 47 +- .../core/algorithm/state/StateFactory.java | 24 +- .../jsprit/core/algorithm/state/StateId.java | 4 +- .../core/algorithm/state/StateManager.java | 652 +- .../core/algorithm/state/StateUpdater.java | 12 +- .../algorithm/state/UpdateActivityTimes.java | 80 +- .../state/UpdateEndLocationIfRouteIsOpen.java | 33 +- .../state/UpdateFutureWaitingTimes.java | 62 + .../core/algorithm/state/UpdateLoads.java | 137 +- ...nAtActivitiesByLookingBackwardInRoute.java | 50 +- ...onAtActivitiesByLookingForwardInRoute.java | 59 +- .../UpdateMaxCapacityUtilisationAtRoute.java | 81 +- .../state/UpdatePracticalTimeWindows.java | 104 +- .../core/algorithm/state/UpdateSkills.java | 4 +- .../algorithm/state/UpdateVariableCosts.java | 136 +- ...eVehicleDependentPracticalTimeWindows.java | 36 +- ...terationWithoutImprovementTermination.java | 61 +- .../PrematureAlgorithmTermination.java | 13 +- .../termination/TimeTermination.java | 67 +- .../VariationCoefficientTermination.java | 153 +- .../core/analysis/SolutionAnalyser.java | 598 +- .../jsprit/core/problem/AbstractActivity.java | 8 +- .../java/jsprit/core/problem/AbstractJob.java | 8 +- .../jsprit/core/problem/AbstractVehicle.java | 20 +- .../java/jsprit/core/problem/Capacity.java | 521 +- .../java/jsprit/core/problem/Location.java | 36 +- .../main/java/jsprit/core/problem/Skills.java | 27 +- .../core/problem/VehicleRoutingProblem.java | 856 +- .../AdditionalTransportationCosts.java | 106 +- .../core/problem/constraint/Constraint.java | 12 +- .../problem/constraint/ConstraintManager.java | 245 +- .../constraint/HardActivityConstraint.java | 38 +- .../HardActivityLevelConstraintManager.java | 144 +- .../problem/constraint/HardConstraint.java | 14 +- .../constraint/HardRouteConstraint.java | 6 +- .../HardRouteLevelConstraintManager.java | 36 +- .../constraint/HardSkillConstraint.java | 11 +- ...erShipmentLoadActivityLevelConstraint.java | 96 +- .../ServiceDeliveriesFirstConstraint.java | 46 +- .../ServiceLoadActivityLevelConstraint.java | 81 +- .../ServiceLoadRouteLevelConstraint.java | 68 +- .../ShipmentPickupsFirstConstraint.java | 18 +- .../constraint/SoftActivityConstraint.java | 18 +- .../SoftActivityConstraintManager.java | 48 +- .../problem/constraint/SoftConstraint.java | 14 +- .../constraint/SoftRouteConstraint.java | 18 +- .../SoftRouteConstraintManager.java | 48 +- .../problem/constraint/SwitchNotFeasible.java | 26 + .../constraint/TimeWindowConstraint.java | 170 +- ...VehicleDependentTimeWindowConstraints.java | 62 +- ...ctForwardVehicleRoutingTransportCosts.java | 28 +- .../problem/cost/BackwardTransportCost.java | 4 +- .../problem/cost/BackwardTransportTime.java | 4 +- .../problem/cost/ForwardTransportCost.java | 4 +- .../problem/cost/ForwardTransportTime.java | 4 +- .../core/problem/cost/TransportCost.java | 12 +- .../core/problem/cost/TransportTime.java | 12 +- .../cost/VehicleRoutingActivityCosts.java | 77 +- .../cost/VehicleRoutingTransportCosts.java | 15 +- .../core/problem/cost/WaitingTimeCosts.java | 22 + .../jsprit/core/problem/driver/Driver.java | 12 +- .../core/problem/driver/DriverImpl.java | 90 +- .../java/jsprit/core/problem/io/Schema.java | 96 +- .../jsprit/core/problem/io/VrpXMLReader.java | 1051 ++- .../jsprit/core/problem/io/VrpXMLWriter.java | 557 +- .../java/jsprit/core/problem/job/Break.java | 79 + .../jsprit/core/problem/job/Delivery.java | 73 +- .../java/jsprit/core/problem/job/Job.java | 29 +- .../java/jsprit/core/problem/job/Pickup.java | 75 +- .../java/jsprit/core/problem/job/Service.java | 442 +- .../jsprit/core/problem/job/Shipment.java | 439 +- .../core/problem/misc/ActivityContext.java | 6 +- .../problem/misc/JobInsertionContext.java | 101 +- .../solution/InitialSolutionFactory.java | 27 +- .../solution/SolutionCostCalculator.java | 31 +- .../VehicleRoutingProblemSolution.java | 142 +- .../route/ReverseRouteActivityVisitor.java | 84 +- .../solution/route/RouteActivityVisitor.java | 72 +- .../problem/solution/route/RouteVisitor.java | 14 +- .../problem/solution/route/VehicleRoute.java | 724 +- .../solution/route/activity/Activities.java | 26 +- .../route/activity/ActivityVisitor.java | 22 +- .../route/activity/BreakActivity.java | 198 + .../DefaultShipmentActivityFactory.java | 30 +- .../activity/DefaultTourActivityFactory.java | 38 +- .../route/activity/DeliverService.java | 192 +- .../route/activity/DeliverShipment.java | 168 +- .../route/activity/DeliveryActivity.java | 14 +- .../problem/solution/route/activity/End.java | 203 +- .../route/activity/PickupActivity.java | 16 +- .../route/activity/PickupService.java | 194 +- .../route/activity/PickupShipment.java | 157 +- .../activity/ReverseActivityVisitor.java | 22 +- .../route/activity/ServiceActivity.java | 284 +- .../solution/route/activity/Start.java | 203 +- .../solution/route/activity/TimeWindow.java | 175 +- .../route/activity/TourActivities.java | 333 +- .../solution/route/activity/TourActivity.java | 209 +- .../route/activity/TourActivityFactory.java | 14 +- .../activity/TourShipmentActivityFactory.java | 20 +- .../state/RouteAndActivityStateGetter.java | 16 +- .../vehicle/FiniteFleetManagerFactory.java | 69 +- .../vehicle/InfiniteFleetManagerFactory.java | 48 +- .../problem/vehicle/InfiniteVehicles.java | 125 +- .../jsprit/core/problem/vehicle/Vehicle.java | 77 +- .../problem/vehicle/VehicleFleetManager.java | 92 +- .../vehicle/VehicleFleetManagerFactory.java | 16 +- .../vehicle/VehicleFleetManagerImpl.java | 360 +- .../core/problem/vehicle/VehicleImpl.java | 462 +- .../core/problem/vehicle/VehicleType.java | 65 +- .../core/problem/vehicle/VehicleTypeImpl.java | 572 +- .../core/problem/vehicle/VehicleTypeKey.java | 70 +- .../core/reporting/SolutionPrinter.java | 294 +- .../jsprit/core/util/ActivityTimeTracker.java | 122 +- .../java/jsprit/core/util/ArrayUtils.java | 40 +- .../jsprit/core/util/BenchmarkInstance.java | 33 +- .../jsprit/core/util/BenchmarkResult.java | 107 +- .../jsprit/core/util/CalculationUtils.java | 22 +- .../java/jsprit/core/util/Coordinate.java | 104 +- .../java/jsprit/core/util/CrowFlyCosts.java | 125 +- .../java/jsprit/core/util/DistanceUnit.java | 6 +- .../java/jsprit/core/util/EuclideanCosts.java | 107 +- .../util/EuclideanDistanceCalculator.java | 21 +- ...astVehicleRoutingTransportCostsMatrix.java | 205 +- .../jsprit/core/util/GreatCircleCosts.java | 50 +- .../util/GreatCircleDistanceCalculator.java | 6 +- .../main/java/jsprit/core/util/Locations.java | 14 +- .../java/jsprit/core/util/ManhattanCosts.java | 84 +- .../util/ManhattanDistanceCalculator.java | 11 +- .../core/util/RandomNumberGeneration.java | 44 +- .../java/jsprit/core/util/RandomUtils.java | 20 +- .../main/java/jsprit/core/util/Resource.java | 92 +- .../java/jsprit/core/util/RouteUtils.java | 156 +- .../jsprit/core/util/SolutionVerifier.java | 42 +- .../main/java/jsprit/core/util/Solutions.java | 28 +- .../main/java/jsprit/core/util/StopWatch.java | 68 +- .../src/main/java/jsprit/core/util/Time.java | 135 +- .../VehicleRoutingTransportCostsMatrix.java | 425 +- .../src/main/resources/algorithm_schema.xsd | 479 +- jsprit-core/src/main/resources/config.xml | 124 +- .../src/main/resources/greedySchrimpf.xml | 87 +- jsprit-core/src/main/resources/randomWalk.xml | 83 +- jsprit-core/src/main/resources/schrimpf.xml | 93 +- .../src/main/resources/vrp_xml_schema.xsd | 667 +- .../java/jsprit/core/IntegrationTest.java | 7 + .../BuildCVRPAlgoFromScratch_IT.java | 111 +- .../BuildPDVRPAlgoFromScratch_IT.java | 126 +- ...dPDVRPWithShipmentsAlgoFromScratch_IT.java | 28 +- ...iesAndDifferentInsertionStrategies_IT.java | 40 +- .../core/algorithm/CVRPwithDeliveries_IT.java | 46 +- .../core/algorithm/CVRPwithMatrix_IT.java | 169 +- .../core/algorithm/CVRPwithPickups_IT.java | 48 +- .../algorithm/DeactivateTimeWindowsTest.java | 32 +- .../ExampleActivityCostFunction.java | 67 +- .../ExternalInitialSolutionIsInValidTest.java | 8 +- ...etManagerIdentifiesDistinctVehicle_IT.java | 95 +- .../core/algorithm/InitialRoutesTest.java | 197 +- .../MeetTimeWindowConstraint_IT.java | 1055 +-- .../jsprit/core/algorithm/OpenRoutesTest.java | 252 +- .../java/jsprit/core/algorithm/PDTW_IT.java | 187 - .../algorithm/PickupsAndDeliveries_IT.java | 60 +- ...CostsHigherThanTimesAndFiniteFleet_IT.java | 305 +- ...niteFleet_withTimeAndDistanceCosts_IT.java | 305 +- .../core/algorithm/RefuseCollection_IT.java | 250 +- .../algorithm/SearchStrategyManagerTest.java | 221 +- .../core/algorithm/SearchStrategyTest.java | 362 +- .../core/algorithm/SelectRandomlyTest.java | 24 +- .../{state => }/SolomonSkills_IT.java | 51 +- .../algorithm/{state => }/Solomon_IT.java | 20 +- .../core/algorithm/UnassignedJobListTest.java | 6 +- .../VariableDepartureAndWaitingTime_IT.java | 111 + .../VehicleRoutingAlgorithmTest.java | 154 +- .../acceptor/AcceptNewRemoveWorstTest.java | 52 +- .../acceptor/SchrimpfAcceptanceTest.java | 211 +- .../jsprit/core/algorithm/box/JspritTest.java | 622 +- .../algorithm/io/TestAlgorithmReader.java | 385 +- ...icleTypeDependentServiceInsertionTest.java | 134 +- .../recreate/CalcWithTimeSchedulingTest.java | 102 +- ...tionConsideringFixCostsCalculatorTest.java | 478 +- .../recreate/RegretInsertionTest.java | 84 +- ...erviceInsertionAndLoadConstraintsTest.java | 148 +- .../ShipmentInsertionCalculatorTest.java | 322 +- .../TestAuxilliaryCostCalculator.java | 164 +- .../TestCalculatesServiceInsertion.java | 374 +- ...alculatesServiceInsertionOnRouteLevel.java | 202 +- .../recreate/TestDepartureTimeOpt.java | 348 +- .../core/algorithm/recreate/TestInserter.java | 319 +- ...LocalActivityInsertionCostsCalculator.java | 558 +- ...erviceAndShipmentsProblemOnRouteLevel.java | 196 +- ...teLevelActivityInsertionCostEstimator.java | 96 +- ...uteLevelServiceInsertionCostEstimator.java | 105 +- .../algorithm/ruin/DBSCANClustererTest.java | 50 +- .../ruin/JobNeighborhoodsImplTest.java | 188 +- ...ighborhoodsWithCapRestrictionImplTest.java | 188 +- .../core/algorithm/ruin/RuinBreakTest.java | 39 + .../core/algorithm/ruin/RuinClustersTest.java | 34 +- .../core/algorithm/ruin/RuinWorstTest.java | 119 +- .../ruin/distance/AverageJobDistanceTest.java | 89 +- .../distance/TestJobDistanceAvgCosts.java | 136 +- .../algorithm/selector/SelectBestTest.java | 54 +- .../selector/SelectRandomlyTest.java | 97 +- ...eliveryShipmentActivityConstraintTest.java | 79 +- .../core/algorithm/state/LoadStateTest.java | 132 +- .../algorithm/state/StateManagerTest.java | 269 +- .../state/UpdatePracticalTimeWindowTest.java | 107 +- .../state/UpdateRequiredSkillsTest.java | 10 +- .../state/UpdateVariableCostsTest.java | 12 +- .../UpdateVehicleDependentTimeWindowTest.java | 74 +- .../IterationsWithoutImprovementTest.java | 26 +- .../termination/TimeTerminationTest.java | 4 +- .../core/analysis/SolutionAnalyserTest.java | 1457 ++-- .../jsprit/core/problem/CapacityTest.java | 697 +- .../jsprit/core/problem/LocationTest.java | 36 +- .../java/jsprit/core/problem/SkillsTest.java | 59 +- .../problem/VehicleRoutingProblemTest.java | 722 +- .../constraint/LoadConstraintTest.java | 346 +- .../ServiceLoadRouteLevelConstraintTest.java | 587 +- .../constraint/SkillConstraintTest.java | 26 +- .../SoftActivityConstraintManagerTest.java | 84 +- .../SoftRouteConstraintManagerTest.java | 78 +- .../constraint/TestConstraintManager.java | 114 +- .../VehicleDependentTimeWindowTest.java | 112 +- ...wWithStartTimeAndMaxOperationTimeTest.java | 112 +- .../core/problem/io/VrpXMLReaderTest.java | 922 +-- .../core/problem/io/VrpXMLWriterTest.java | 1408 ++-- .../jsprit/core/problem/job/DeliveryTest.java | 106 +- .../jsprit/core/problem/job/PickupTest.java | 110 +- .../jsprit/core/problem/job/ServiceTest.java | 290 +- .../jsprit/core/problem/job/ShipmentTest.java | 530 +- .../problem/misc/JobInsertionContextTest.java | 30 +- .../VehicleRoutingProblemSolutionTest.java | 66 +- .../solution/route/TestVehicleRoute.java | 524 +- .../route/VehicleRouteBuilderTest.java | 268 +- .../route/activity/BreakActivityTest.java | 106 + .../DefaultShipmentActivityFactoryTest.java | 40 +- .../DefaultTourActivityFactoryTest.java | 66 +- .../route/activity/DeliverServiceTest.java | 114 +- .../route/activity/DeliverShipmentTest.java | 132 +- .../solution/route/activity/EndTest.java | 114 +- .../route/activity/PickupServiceTest.java | 116 +- .../route/activity/PickupShipmentTest.java | 132 +- .../route/activity/ServiceActivityTest.java | 156 +- .../solution/route/activity/StartTest.java | 120 +- .../solution/route/activity/TestRefs.java | 42 +- .../route/activity/TestTourActivities.java | 230 +- .../route/activity/TimeWindowTest.java | 12 +- .../FiniteVehicleFleetManagerFactoryTest.java | 22 +- .../vehicle/TestVehicleFleetManagerImpl.java | 375 +- .../core/problem/vehicle/VehicleImplTest.java | 415 +- .../problem/vehicle/VehicleTypeImplTest.java | 268 +- .../problem/vehicle/VehicleTypeKeyTest.java | 12 +- .../java/jsprit/core/util/CostFactory.java | 68 +- ...ehicleRoutingTransportCostsMatrixTest.java | 114 +- .../GreatCircleDistanceCalculatorTest.java | 20 +- .../jsprit/core/util/RandomUtilsTest.java | 10 +- .../test/java/jsprit/core/util/TestUtils.java | 6 +- .../test/java/jsprit/core/util/TimeTest.java | 290 +- ...ehicleRoutingTransportCostsMatrixTest.java | 445 +- .../src/test/resources/C101_solomon_pd.xml | 5065 ++++++------ .../src/test/resources/algorithmConfig.xml | 85 +- .../algorithmConfigForReaderTest.xml | 85 +- .../algorithmConfigForReaderTest2.xml | 85 +- ...algorithmConfigWithDepartureTimeChoice.xml | 119 +- .../algorithmConfig_greedyWithRegret.xml | 85 +- .../algorithmConfig_greedyWithRegret_v2.xml | 85 +- .../algorithmConfig_selectRandomly.xml | 50 +- .../algorithmConfig_withoutIterations.xml | 85 +- .../algorithm_without_construction.xml | 77 +- .../src/test/resources/biggerProblem.xml | 1279 +-- .../resources/configWithRegretInsertion.xml | 133 +- jsprit-core/src/test/resources/finiteVrp.xml | 163 +- .../test/resources/finiteVrpForReaderTest.xml | 424 +- ...iteVrpWithInitialSolutionForReaderTest.xml | 412 +- .../finiteVrpWithShipmentsAndSolution.xml | 304 +- .../finiteVrpWithSolutionForReaderTest.xml | 382 +- .../test/resources/lilim_algorithmConfig.xml | 85 +- .../src/test/resources/lilim_lr101.xml | 2941 +++---- .../src/test/resources/lui-shen-solution.xml | 3823 ++++----- jsprit-core/src/test/resources/matrix.txt | 121 + .../test/resources/pdVRP_vrpnc1_jsprit.xml | 1263 +-- .../test/resources/pd_solomon_c101_sol.xml | 7217 +++++++++-------- .../src/test/resources/pd_solomon_r101.xml | 2463 +++--- jsprit-core/src/test/resources/pdp.xml | 1017 +-- .../schrimpf_vehicleSwitchNotAllowed.xml | 87 +- .../src/test/resources/simpleProblem.xml | 189 +- .../simpleProblem_inclShipments_iniRoutes.xml | 145 +- .../resources/simpleProblem_iniRoutes.xml | 145 +- .../resources/simpleProblem_iniRoutes_2.xml | 75 +- .../resources/simpleProblem_iniRoutes_3.xml | 129 +- .../src/test/resources/solomon_c101.xml | 2877 +++---- jsprit-core/src/test/resources/testConfig.xml | 126 +- .../src/test/resources/testConfig2.xml | 120 +- jsprit-core/src/test/resources/twbug.xml | 407 + .../src/test/resources/vrp-solution.json | 50 +- jsprit-core/src/test/resources/vrp.json | 189 +- .../vrpnc1-jsprit-with-deliveries.xml | 1263 +-- .../resources/vrpnc1-jsprit-with-pickups.xml | 1263 +-- .../src/test/resources/vrpnc1-jsprit.xml | 1263 +-- jsprit-examples/input/algorithmConfig.xml | 129 +- .../algorithmConfigWithSchrimpfAcceptance.xml | 97 +- .../algorithmConfig_considerFixedCosts.xml | 101 +- ...hmConfig_considerFixedCosts_routeLevel.xml | 103 +- jsprit-examples/input/algorithmConfig_fix.xml | 85 +- .../input/algorithmConfig_fix_schrimpf.xml | 91 +- .../algorithmConfig_greedyWithRegret.xml | 85 +- .../input/algorithmConfig_noVehicleSwitch.xml | 125 +- .../input/algorithmConfig_open.xml | 95 +- .../input/algorithmConfig_solomon.xml | 85 +- jsprit-examples/input/cordeau01.xml | 1991 ++--- jsprit-examples/input/cordeau_p01.xml | 1647 ++-- jsprit-examples/input/cordeau_p08.xml | 6651 +++++++-------- .../input/deliveries_solomon_c101.xml | 2465 +++--- .../input/deliveries_solomon_open_c101.xml | 2467 +++--- ...omon_specifiedVehicleEndLocations_c101.xml | 2475 +++--- jsprit-examples/input/fastAlgo.xml | 99 +- .../input/pd_christophides_vrpnc1_vcap50.xml | 1263 +-- .../pickups_and_deliveries_solomon_c101.xml | 2465 +++--- ...and_deliveries_solomon_c101_withoutTWs.xml | 2463 +++--- ...utTWs_and_specifiedVehicleEndLocations.xml | 2471 +++--- .../pickups_and_deliveries_solomon_r101.xml | 2465 +++--- ...ckups_and_deliveries_solomon_r101_open.xml | 2467 +++--- ...and_deliveries_solomon_r101_withoutTWs.xml | 2463 +++--- ...eliveries_solomon_r101_withoutTWs_open.xml | 2465 +++--- .../input/pickups_solomon_c101.xml | 2465 +++--- jsprit-examples/input/vrp_cordeau_01.xml | 1209 +-- jsprit-examples/input/vrp_cordeau_08.xml | 5985 +++++++------- jsprit-examples/input/vrpnc1-jsprit.xml | 1263 +-- jsprit-examples/pom.xml | 118 +- .../AdditionalDistanceConstraintExample.java | 47 +- .../jsprit/examples/BicycleMessenger.java | 477 +- .../java/jsprit/examples/BreakExample.java | 107 + .../examples/BuildAlgorithmFromScratch.java | 57 +- .../java/jsprit/examples/CircleExample.java | 30 +- ...nfigureAlgorithmInCodeInsteadOfPerXml.java | 180 +- .../jsprit/examples/CostMatrixExample.java | 99 +- ...ithMultipleDepotsAndOpenRoutesExample.java | 196 +- .../java/jsprit/examples/HVRPExample.java | 167 +- .../JobAndActivityDependenciesExample.java | 142 +- .../jsprit/examples/MultipleDepotExample.java | 100 +- .../examples/MultipleDepotExample2.java | 108 +- ...MultipleDepotWithInitialRoutesExample.java | 96 +- ...ipleProductsWithLoadConstraintExample.java | 80 +- .../examples/PickupAndDeliveryExample.java | 82 +- .../examples/PickupAndDeliveryExample2.java | 88 +- .../PickupAndDeliveryOpenExample.java | 81 +- .../examples/RefuseCollectionExample.java | 168 +- ...RefuseCollectionWithFastMatrixExample.java | 147 +- ...rvicePickupsWithMultipleDepotsExample.java | 144 +- ...eDepotBoundedPickupAndDeliveryExample.java | 131 +- ...SimpleEnRoutePickupAndDeliveryExample.java | 120 +- ...utePickupAndDeliveryOpenRoutesExample.java | 120 +- ...veryWithDepotBoundedDeliveriesExample.java | 130 +- .../java/jsprit/examples/SimpleExample.java | 127 +- .../examples/SimpleExampleOpenRoutes.java | 104 +- .../examples/SimpleExampleWithSkills.java | 115 +- .../SimpleVRPWithBackhaulsExample.java | 118 +- .../java/jsprit/examples/SolomonExample.java | 70 +- ...ampleWithSpecifiedVehicleEndLocations.java | 100 +- ...pecifiedVehicleEndLocationsWithoutTWs.java | 98 +- .../jsprit/examples/SolomonOpenExample.java | 78 +- .../jsprit/examples/SolomonR101Example.java | 46 +- .../SolomonWithRegretInsertionExample.java | 74 +- .../examples/SolomonWithSkillsExample.java | 51 +- .../examples/TransportOfDisabledPeople.java | 286 +- .../examples/VRPWithBackhaulsExample.java | 76 +- .../examples/VRPWithBackhaulsExample2.java | 118 +- .../src/main/java/jsprit/util/Examples.java | 32 +- jsprit-instances/pom.xml | 104 +- .../instance/reader/ChristofidesReader.java | 196 +- .../jsprit/instance/reader/CordeauReader.java | 235 +- .../jsprit/instance/reader/Figliozzi.java | 224 +- .../jsprit/instance/reader/LiLimReader.java | 308 +- .../reader/LopezIbanezBlumReader.java | 56 +- .../jsprit/instance/reader/LuiShenReader.java | 279 +- .../jsprit/instance/reader/SolomonReader.java | 227 +- .../reader/TSPLIB95CostMatrixReader.java | 16 +- .../instance/reader/TSPLIB95Reader.java | 153 +- .../java/jsprit/instance/reader/Taillard.java | 148 +- .../instance/reader/VrphGoldenReader.java | 274 +- .../java/jsprit/instance/util/Instances.java | 423 +- .../reader/ChristophidesReaderTest.java | 152 +- .../instance/reader/CordeauReaderTest.java | 246 +- .../jsprit/instance/reader/FigliozziTest.java | 352 +- .../instance/reader/GoldenReaderTest.java | 577 +- .../instance/reader/LuiShenReaderTest.java | 74 +- .../instance/reader/SolomonReaderTest.java | 158 +- pom.xml | 591 +- 523 files changed, 77426 insertions(+), 74576 deletions(-) create mode 100644 .editorconfig create mode 100644 jsprit-core/src/main/java/jsprit/core/algorithm/box/ConcurrentInsertionNoiseMaker.java create mode 100644 jsprit-core/src/main/java/jsprit/core/algorithm/recreate/BreakInsertionCalculator.java create mode 100644 jsprit-core/src/main/java/jsprit/core/algorithm/recreate/ConfigureLocalActivityInsertionCalculator.java create mode 100644 jsprit-core/src/main/java/jsprit/core/algorithm/recreate/DefaultScorer.java create mode 100644 jsprit-core/src/main/java/jsprit/core/algorithm/recreate/InsertBreak.java create mode 100644 jsprit-core/src/main/java/jsprit/core/algorithm/recreate/InsertBreakListener.java create mode 100644 jsprit-core/src/main/java/jsprit/core/algorithm/recreate/InsertionDataUpdater.java create mode 100644 jsprit-core/src/main/java/jsprit/core/algorithm/recreate/RegretInsertionConcurrentFast.java create mode 100644 jsprit-core/src/main/java/jsprit/core/algorithm/recreate/RegretInsertionFast.java create mode 100644 jsprit-core/src/main/java/jsprit/core/algorithm/recreate/ScoredJob.java create mode 100644 jsprit-core/src/main/java/jsprit/core/algorithm/recreate/ScoringFunction.java create mode 100644 jsprit-core/src/main/java/jsprit/core/algorithm/recreate/VersionedInsertionData.java create mode 100644 jsprit-core/src/main/java/jsprit/core/algorithm/ruin/RuinBreaks.java create mode 100644 jsprit-core/src/main/java/jsprit/core/algorithm/state/UpdateFutureWaitingTimes.java create mode 100644 jsprit-core/src/main/java/jsprit/core/problem/constraint/SwitchNotFeasible.java create mode 100644 jsprit-core/src/main/java/jsprit/core/problem/cost/WaitingTimeCosts.java create mode 100644 jsprit-core/src/main/java/jsprit/core/problem/job/Break.java create mode 100644 jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/BreakActivity.java create mode 100644 jsprit-core/src/test/java/jsprit/core/IntegrationTest.java delete mode 100644 jsprit-core/src/test/java/jsprit/core/algorithm/PDTW_IT.java rename jsprit-core/src/test/java/jsprit/core/algorithm/{state => }/SolomonSkills_IT.java (70%) rename jsprit-core/src/test/java/jsprit/core/algorithm/{state => }/Solomon_IT.java (55%) create mode 100644 jsprit-core/src/test/java/jsprit/core/algorithm/VariableDepartureAndWaitingTime_IT.java create mode 100644 jsprit-core/src/test/java/jsprit/core/algorithm/ruin/RuinBreakTest.java create mode 100644 jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/BreakActivityTest.java create mode 100644 jsprit-core/src/test/resources/matrix.txt create mode 100644 jsprit-core/src/test/resources/twbug.xml create mode 100644 jsprit-examples/src/main/java/jsprit/examples/BreakExample.java diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..7852a87c --- /dev/null +++ b/.editorconfig @@ -0,0 +1,13 @@ +root = true + +[*] +indent_style = space +indent_size = 4 +insert_final_newline = true +charset = utf-8 +end_of_line = lf +trim_trailing_whitespace = true +max_line_length = 120 + +[.travis.yml] +indent_size = 2 diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f8a790f..d394bd00 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,18 @@ Change-log ========== +**v1.6.1** @ 2015-08-10 +- feature [#165](https://github.com/jsprit/jsprit/issues/156) +- feature [#169](https://github.com/jsprit/jsprit/issues/159) +- bugfix [#154](https://github.com/jsprit/jsprit/issues/154) +- bugfix [#155](https://github.com/jsprit/jsprit/issues/155) +- bugfix [#158](https://github.com/jsprit/jsprit/issues/158) +- bugfix [#164](https://github.com/jsprit/jsprit/issues/164) +- bugfix [#165](https://github.com/jsprit/jsprit/issues/165) + +- [detailed changelog ](https://rawgit.com/jsprit/misc-rep/master/changelog_1.6_to_1.6.1.html) + + **v1.6** @ 2015-03-12 ! Break change ! diff --git a/README.md b/README.md index c347f9c5..d1cbf5f3 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ This software is released under [LGPL](http://opensource.org/licenses/LGPL-3.0). ##Contact ####Mailing List: -In the [mailing list](https://groups.google.com/group/jsprit-mailing-list) you can discuss jsprit related issues and you will probably get answers to your questions. +In the [mailing list](https://discuss.graphhopper.com/) ([old mailing list](https://groups.google.com/group/jsprit-mailing-list)) you can discuss jsprit related issues and you will probably get answers to your questions. ####Stackoverflow: You can also use [stackoverflow](http://stackoverflow.com/questions/tagged/jsprit) to discuss your issues. Tag it with jsprit then it is easier to keep track of your topic. diff --git a/WHATS_NEW.md b/WHATS_NEW.md index ae0da788..35b03b24 100644 --- a/WHATS_NEW.md +++ b/WHATS_NEW.md @@ -1,6 +1,11 @@ WHATS NEW ========== ------------------------------ +2015-08-10 new release **v1.6.1** + +Jsprit results are now reproducible since every time the algorithm runs, a unique random number generator (always starting with a + predefined seed) is invoked. If one does not want this behaviour, one can always specify custom random number generators. + 2015-03-12 new release **v1.6** When reviewing the feedback from our users, we realized that jsprit cannot solve certain kinds of problems adequately. diff --git a/jsprit-analysis/pom.xml b/jsprit-analysis/pom.xml index 5253489b..1622276b 100644 --- a/jsprit-analysis/pom.xml +++ b/jsprit-analysis/pom.xml @@ -1,74 +1,75 @@ - - - jsprit - jsprit - 1.6.1-SNAPSHOT - - 4.0.0 - jsprit-analysis - jar - - - - - - org.eclipse.m2e - lifecycle-mapping - 1.0.0 - - - - - - org.apache.maven.plugins - maven-enforcer-plugin - [1.0.0,) - - enforce - - - - - - - - - - - - - - - - - org.jfree - jfreechart - 1.0.14 - compile - - - - ${project.groupId} - jsprit-core - ${project.version} - jar - provided - - - - gs-core - org.graphstream - 1.3 - false - - - - gs-ui - org.graphstream - 1.3 - false - - - - + + + jsprit + jsprit + 1.6.2-SNAPSHOT + + 4.0.0 + jsprit-analysis + jar + + + + + + org.eclipse.m2e + lifecycle-mapping + 1.0.0 + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + [1.0.0,) + + enforce + + + + + + + + + + + + + + + + + org.jfree + jfreechart + 1.0.19 + compile + + + + ${project.groupId} + jsprit-core + ${project.version} + jar + provided + + + + gs-core + org.graphstream + 1.3 + false + + + + gs-ui + org.graphstream + 1.3 + false + + + + diff --git a/jsprit-analysis/src/main/java/jsprit/analysis/toolbox/AlgorithmEventsRecorder.java b/jsprit-analysis/src/main/java/jsprit/analysis/toolbox/AlgorithmEventsRecorder.java index c772ea7e..6759de6a 100644 --- a/jsprit-analysis/src/main/java/jsprit/analysis/toolbox/AlgorithmEventsRecorder.java +++ b/jsprit-analysis/src/main/java/jsprit/analysis/toolbox/AlgorithmEventsRecorder.java @@ -89,11 +89,10 @@ public class AlgorithmEventsRecorder implements RuinListener, IterationStartsLis File dgsFile = new File(dgsFileLocation); fos = new FileOutputStream(dgsFile); fileSink = new FileSinkDGS(); - if(dgsFile.getName().endsWith("gz")){ + if (dgsFile.getName().endsWith("gz")) { gzipOs = new GZIPOutputStream(fos); fileSink.begin(gzipOs); - } - else{ + } else { fileSink.begin(fos); } graph.addSink(fileSink); @@ -109,37 +108,37 @@ public class AlgorithmEventsRecorder implements RuinListener, IterationStartsLis new AlgorithmEventsRecorder(vrp, dgsFileLocation); } - public void setRecordingRange(int startIteration, int endIteration){ + public void setRecordingRange(int startIteration, int endIteration) { this.start_recording_at = startIteration; this.end_recording_at = endIteration; } @Override public void ruinStarts(Collection routes) { - if(!record()) return; - fileSink.stepBegins(graph.getId(),0,BEFORE_RUIN_RENDER_SOLUTION); + if (!record()) return; + fileSink.stepBegins(graph.getId(), 0, BEFORE_RUIN_RENDER_SOLUTION); markAllNodesAsInserted(); addRoutes(routes); - fileSink.stepBegins(graph.getId(),0,RUIN); + fileSink.stepBegins(graph.getId(), 0, RUIN); } private void markAllNodesAsInserted() { - for(Job j : vrp.getJobs().values()){ + for (Job j : vrp.getJobs().values()) { markInserted(j); } } private void addRoutes(Collection routes) { - for(VehicleRoute route : routes){ + for (VehicleRoute route : routes) { String prevNode = makeStartId(route.getVehicle()); - for(TourActivity act : route.getActivities()){ + for (TourActivity act : route.getActivities()) { String actNodeId = getNodeId(act); - addEdge(prevNode+"_"+actNodeId,prevNode,actNodeId); + addEdge(prevNode + "_" + actNodeId, prevNode, actNodeId); prevNode = actNodeId; } - if(route.getVehicle().isReturnToDepot()) { + if (route.getVehicle().isReturnToDepot()) { String lastNode = makeEndId(route.getVehicle()); - addEdge(prevNode+"_"+lastNode,prevNode,lastNode); + addEdge(prevNode + "_" + lastNode, prevNode, lastNode); } } @@ -147,13 +146,12 @@ public class AlgorithmEventsRecorder implements RuinListener, IterationStartsLis private String getNodeId(TourActivity act) { String nodeId = null; - if(act instanceof TourActivity.JobActivity){ + if (act instanceof TourActivity.JobActivity) { Job job = ((TourActivity.JobActivity) act).getJob(); - if(job instanceof Service){ + if (job instanceof Service) { nodeId = job.getId(); - } - else if(job instanceof Shipment){ - if(act.getName().equals("pickupShipment")) nodeId = getFromNodeId((Shipment) job); + } else if (job instanceof Shipment) { + if (act.getName().equals("pickupShipment")) nodeId = getFromNodeId((Shipment) job); else nodeId = getToNodeId((Shipment) job); } } @@ -171,28 +169,29 @@ public class AlgorithmEventsRecorder implements RuinListener, IterationStartsLis @Override public void removed(Job job, VehicleRoute fromRoute) { - if(!record()) return; - if(job instanceof Service) removeService(job, fromRoute); - else if(job instanceof Shipment) removeShipment(job,fromRoute); + if (!record()) return; + if (job instanceof Service) removeService(job, fromRoute); + else if (job instanceof Shipment) removeShipment(job, fromRoute); } private void removeShipment(Job job, VehicleRoute fromRoute) { - Shipment shipment = (Shipment)job; + Shipment shipment = (Shipment) job; String fromNodeId = getFromNodeId(shipment); String toNodeId = getToNodeId(shipment); // removeNodeAndBelongingEdges(fromNodeId,fromRoute); // removeNodeAndBelongingEdges(toNodeId,fromRoute); Edge enteringToNode = getEnteringEdge(toNodeId); - if(enteringToNode.getNode0().getId().equals(fromNodeId)){ + if (enteringToNode.getNode0().getId().equals(fromNodeId)) { markRemoved(graph.getNode(fromNodeId)); markRemoved(graph.getNode(toNodeId)); // i -> from -> to -> j: rem(i,from), rem(from,to), rem(to,j), add(i,j) Edge enteringFromNode = getEnteringEdge(fromNodeId); removeEdge(enteringFromNode.getId()); removeEdge(enteringToNode.getId()); - if(graph.getNode(toNodeId).getLeavingEdgeSet().isEmpty()){ - if(fromRoute.getVehicle().isReturnToDepot()) throw new IllegalStateException("leaving edge is missing"); + if (graph.getNode(toNodeId).getLeavingEdgeSet().isEmpty()) { + if (fromRoute.getVehicle().isReturnToDepot()) + throw new IllegalStateException("leaving edge is missing"); return; } @@ -200,22 +199,23 @@ public class AlgorithmEventsRecorder implements RuinListener, IterationStartsLis removeEdge(leavingToNode.getId()); Node from = enteringFromNode.getNode0(); Node to = leavingToNode.getNode1(); - if(!fromRoute.getActivities().isEmpty()){ - addEdge(makeEdgeId(from,to),from.getId(),to.getId()); + if (!fromRoute.getActivities().isEmpty()) { + addEdge(makeEdgeId(from, to), from.getId(), to.getId()); } - } - else{ - removeNodeAndBelongingEdges(fromNodeId,fromRoute); - removeNodeAndBelongingEdges(toNodeId,fromRoute); + } else { + removeNodeAndBelongingEdges(fromNodeId, fromRoute); + removeNodeAndBelongingEdges(toNodeId, fromRoute); } } private Edge getLeavingEdge(String toNodeId) { Collection edges = graph.getNode(toNodeId).getLeavingEdgeSet(); - if(edges.size()==1) return edges.iterator().next(); - else{ - for(Edge e : edges){ - if(e.getId().startsWith("shipment")){ continue; } + if (edges.size() == 1) return edges.iterator().next(); + else { + for (Edge e : edges) { + if (e.getId().startsWith("shipment")) { + continue; + } return e; } } @@ -224,10 +224,12 @@ public class AlgorithmEventsRecorder implements RuinListener, IterationStartsLis private Edge getEnteringEdge(String toNodeId) { Collection enteringEdges = graph.getNode(toNodeId).getEnteringEdgeSet(); - if(enteringEdges.size()==1) return enteringEdges.iterator().next(); - else{ - for(Edge e : enteringEdges){ - if(e.getId().startsWith("shipment")){ continue; } + if (enteringEdges.size() == 1) return enteringEdges.iterator().next(); + else { + for (Edge e : enteringEdges) { + if (e.getId().startsWith("shipment")) { + continue; + } return e; } } @@ -253,8 +255,8 @@ public class AlgorithmEventsRecorder implements RuinListener, IterationStartsLis Edge entering = getEnteringEdge(nodeId); removeEdge(entering.getId()); - if(node.getLeavingEdgeSet().isEmpty()){ - if(fromRoute.getVehicle().isReturnToDepot()) throw new IllegalStateException("leaving edge is missing"); + if (node.getLeavingEdgeSet().isEmpty()) { + if (fromRoute.getVehicle().isReturnToDepot()) throw new IllegalStateException("leaving edge is missing"); return; } @@ -262,13 +264,13 @@ public class AlgorithmEventsRecorder implements RuinListener, IterationStartsLis removeEdge((leaving.getId())); Node from = entering.getNode0(); Node to = leaving.getNode1(); - if(!fromRoute.getActivities().isEmpty()){ - addEdge(makeEdgeId(from,to),from.getId(),to.getId()); + if (!fromRoute.getActivities().isEmpty()) { + addEdge(makeEdgeId(from, to), from.getId(), to.getId()); } } private void markRemoved(Node node) { - node.setAttribute("ui.class","removed"); + node.setAttribute("ui.class", "removed"); } private String makeEdgeId(Node from, Node to) { @@ -278,7 +280,7 @@ public class AlgorithmEventsRecorder implements RuinListener, IterationStartsLis @Override public void informAlgorithmEnds(VehicleRoutingProblem problem, Collection solutions) { VehicleRoutingProblemSolution solution = Solutions.bestOf(solutions); - fileSink.stepBegins(graph.getId(),0,BEFORE_RUIN_RENDER_SOLUTION); + fileSink.stepBegins(graph.getId(), 0, BEFORE_RUIN_RENDER_SOLUTION); addRoutes(solution.getRoutes()); finish(); } @@ -287,7 +289,7 @@ public class AlgorithmEventsRecorder implements RuinListener, IterationStartsLis try { fileSink.end(); fos.close(); - if(gzipOs != null) gzipOs.close(); + if (gzipOs != null) gzipOs.close(); } catch (IOException e) { e.printStackTrace(); } @@ -299,28 +301,27 @@ public class AlgorithmEventsRecorder implements RuinListener, IterationStartsLis } private void initialiseGraph(VehicleRoutingProblem problem) { - for(Vehicle vehicle : problem.getVehicles()){ + for (Vehicle vehicle : problem.getVehicles()) { addVehicle(vehicle); } - for(Job job : problem.getJobs().values()){ + for (Job job : problem.getJobs().values()) { addJob(job); } } private void addJob(Job job) { - if(job instanceof Service){ - Service service = (Service)job; + if (job instanceof Service) { + Service service = (Service) job; addNode(service.getId(), service.getLocation().getCoordinate()); markService(service); - } - else if(job instanceof Shipment){ - Shipment shipment = (Shipment)job; + } else if (job instanceof Shipment) { + Shipment shipment = (Shipment) job; String fromNodeId = getFromNodeId(shipment); addNode(fromNodeId, shipment.getPickupLocation().getCoordinate()); String toNodeId = getToNodeId(shipment); - addNode(toNodeId,shipment.getDeliveryLocation().getCoordinate()); + addNode(toNodeId, shipment.getDeliveryLocation().getCoordinate()); markShipment(shipment); - if(renderShipments) { + if (renderShipments) { Edge e = graph.addEdge("shipment_" + fromNodeId + "_" + toNodeId, fromNodeId, toNodeId, true); e.addAttribute("ui.class", "shipment"); } @@ -333,35 +334,34 @@ public class AlgorithmEventsRecorder implements RuinListener, IterationStartsLis } private void markService(Service service) { - if(service instanceof Delivery){ + if (service instanceof Delivery) { markDelivery(service.getId()); - } - else { + } else { markPickup(service.getId()); } } private void markPickup(String id) { - graph.getNode(id).addAttribute("ui.class","pickup"); + graph.getNode(id).addAttribute("ui.class", "pickup"); } private void markDelivery(String id) { - graph.getNode(id).addAttribute("ui.class","delivery"); + graph.getNode(id).addAttribute("ui.class", "delivery"); } private void addVehicle(Vehicle vehicle) { String startId = makeStartId(vehicle); Node node = graph.addNode(startId); - node.addAttribute("x",vehicle.getStartLocation().getCoordinate().getX()); + node.addAttribute("x", vehicle.getStartLocation().getCoordinate().getX()); node.addAttribute("y", vehicle.getStartLocation().getCoordinate().getY()); - node.addAttribute("ui.class","depot"); + node.addAttribute("ui.class", "depot"); String endId = makeEndId(vehicle); - if(!startId.equals(endId)){ + if (!startId.equals(endId)) { Node endNode = graph.addNode(endId); endNode.addAttribute("x", vehicle.getEndLocation().getCoordinate().getX()); endNode.addAttribute("y", vehicle.getEndLocation().getCoordinate().getY()); - endNode.addAttribute("ui.class","depot"); + endNode.addAttribute("ui.class", "depot"); } } @@ -370,7 +370,7 @@ public class AlgorithmEventsRecorder implements RuinListener, IterationStartsLis } private String makeEndId(Vehicle vehicle) { - if(vehicle.getStartLocation().getId().equals(vehicle.getEndLocation().getId())) return makeStartId(vehicle); + if (vehicle.getStartLocation().getId().equals(vehicle.getEndLocation().getId())) return makeStartId(vehicle); return vehicle.getId() + "_end"; } @@ -382,20 +382,20 @@ public class AlgorithmEventsRecorder implements RuinListener, IterationStartsLis @Override public void informInsertionEnds(Collection vehicleRoutes) { - if(!record()) return; - fileSink.stepBegins(graph.getId(),0,CLEAR_SOLUTION); + if (!record()) return; + fileSink.stepBegins(graph.getId(), 0, CLEAR_SOLUTION); removeRoutes(vehicleRoutes); } private void removeRoutes(Collection vehicleRoutes) { - for(VehicleRoute route : vehicleRoutes){ + for (VehicleRoute route : vehicleRoutes) { String prevNode = makeStartId(route.getVehicle()); - for(TourActivity act : route.getActivities()){ + for (TourActivity act : route.getActivities()) { String actNode = getNodeId(act); removeEdge(prevNode + "_" + actNode); prevNode = actNode; } - if(route.getVehicle().isReturnToDepot()) { + if (route.getVehicle().isReturnToDepot()) { String lastNode = makeEndId(route.getVehicle()); removeEdge(prevNode + "_" + lastNode); } @@ -404,25 +404,25 @@ public class AlgorithmEventsRecorder implements RuinListener, IterationStartsLis @Override public void informBeforeJobInsertion(Job job, InsertionData data, VehicleRoute route) { - if(!record()) return; + if (!record()) return; markInserted(job); handleVehicleSwitch(data, route); insertJob(job, data, route); } private void insertJob(Job job, InsertionData data, VehicleRoute route) { - if(job instanceof Service) insertService(job,data,route); - else if(job instanceof Shipment) insertShipment(job,data,route); + if (job instanceof Service) insertService(job, data, route); + else if (job instanceof Shipment) insertShipment(job, data, route); } private void insertShipment(Job job, InsertionData data, VehicleRoute route) { String fromNodeId = getFromNodeId((Shipment) job); String toNodeId = getToNodeId((Shipment) job); - insertNode(toNodeId,data.getDeliveryInsertionIndex(),data,route); + insertNode(toNodeId, data.getDeliveryInsertionIndex(), data, route); List del = vrp.getActivities(job); VehicleRoute copied = VehicleRoute.copyOf(route); - copied.getTourActivities().addActivity(data.getDeliveryInsertionIndex(),del.get(1)); + copied.getTourActivities().addActivity(data.getDeliveryInsertionIndex(), del.get(1)); insertNode(fromNodeId, data.getPickupInsertionIndex(), data, copied); } @@ -436,19 +436,17 @@ public class AlgorithmEventsRecorder implements RuinListener, IterationStartsLis String node_i; - if(isFirst(insertionIndex)) { + if (isFirst(insertionIndex)) { node_i = makeStartId(data.getSelectedVehicle()); - } - else { + } else { TourActivity.JobActivity jobActivity = (TourActivity.JobActivity) route.getActivities().get(insertionIndex - 1); node_i = getNodeId(jobActivity); } - String edgeId_1 = node_i + "_" + nodeId; + String edgeId_1 = node_i + "_" + nodeId; String node_j; - if(isLast(insertionIndex,route)) { + if (isLast(insertionIndex, route)) { node_j = makeEndId(data.getSelectedVehicle()); - } - else { + } else { TourActivity.JobActivity jobActivity = (TourActivity.JobActivity) route.getActivities().get(insertionIndex); node_j = getNodeId(jobActivity); } @@ -456,7 +454,7 @@ public class AlgorithmEventsRecorder implements RuinListener, IterationStartsLis addEdge(edgeId_1, node_i, nodeId); - if(!(isLast(insertionIndex,route) && !data.getSelectedVehicle().isReturnToDepot())) { + if (!(isLast(insertionIndex, route) && !data.getSelectedVehicle().isReturnToDepot())) { addEdge(edgeId_2, nodeId, node_j); if (!route.getActivities().isEmpty()) { removeEdge(node_i + "_" + node_j); @@ -466,38 +464,37 @@ public class AlgorithmEventsRecorder implements RuinListener, IterationStartsLis private void handleVehicleSwitch(InsertionData data, VehicleRoute route) { boolean vehicleSwitch = false; - if(!(route.getVehicle() instanceof VehicleImpl.NoVehicle)) { + if (!(route.getVehicle() instanceof VehicleImpl.NoVehicle)) { if (!route.getVehicle().getId().equals(data.getSelectedVehicle().getId())) { vehicleSwitch = true; } } - if(vehicleSwitch && !route.getActivities().isEmpty()){ + if (vehicleSwitch && !route.getActivities().isEmpty()) { String oldStart = makeStartId(route.getVehicle()); - String firstAct = ((TourActivity.JobActivity)route.getActivities().get(0)).getJob().getId(); + String firstAct = ((TourActivity.JobActivity) route.getActivities().get(0)).getJob().getId(); String oldEnd = makeEndId(route.getVehicle()); - String lastAct = ((TourActivity.JobActivity)route.getActivities().get(route.getActivities().size()-1)).getJob().getId(); + String lastAct = ((TourActivity.JobActivity) route.getActivities().get(route.getActivities().size() - 1)).getJob().getId(); removeEdge(oldStart + "_" + firstAct); - if(route.getVehicle().isReturnToDepot()) { + if (route.getVehicle().isReturnToDepot()) { removeEdge(lastAct + "_" + oldEnd); } String newStart = makeStartId(data.getSelectedVehicle()); String newEnd = makeEndId(data.getSelectedVehicle()); - addEdge(newStart + "_" + firstAct,newStart,firstAct); + addEdge(newStart + "_" + firstAct, newStart, firstAct); - if(data.getSelectedVehicle().isReturnToDepot()) { + if (data.getSelectedVehicle().isReturnToDepot()) { addEdge(lastAct + "_" + newEnd, lastAct, newEnd); } } } private void markInserted(Job job) { - if(job instanceof Service){ + if (job instanceof Service) { markService((Service) job); - } - else{ - markShipment((Shipment)job); + } else { + markShipment((Shipment) job); } } @@ -507,7 +504,7 @@ public class AlgorithmEventsRecorder implements RuinListener, IterationStartsLis } private void markEdgeRemoved(String edgeId) { - graph.getEdge(edgeId).addAttribute("ui.class","removed"); + graph.getEdge(edgeId).addAttribute("ui.class", "removed"); } private boolean isFirst(int index) { @@ -518,19 +515,19 @@ public class AlgorithmEventsRecorder implements RuinListener, IterationStartsLis return index == route.getActivities().size(); } - private void addEdge(String edgeId, String fromNode, String toNode) { - graph.addEdge(edgeId,fromNode,toNode,true); + private void addEdge(String edgeId, String fromNode, String toNode) { + graph.addEdge(edgeId, fromNode, toNode, true); markEdgeInserted(edgeId); } private void markEdgeInserted(String edgeId) { - graph.getEdge(edgeId).addAttribute("ui.class","inserted"); + graph.getEdge(edgeId).addAttribute("ui.class", "inserted"); graph.getEdge(edgeId).removeAttribute("ui.class"); } @Override public void informInsertionStarts(Collection vehicleRoutes, Collection unassignedJobs) { - if(!record()) return; - fileSink.stepBegins(graph.getId(),0,RECREATE); + if (!record()) return; + fileSink.stepBegins(graph.getId(), 0, RECREATE); } } diff --git a/jsprit-analysis/src/main/java/jsprit/analysis/toolbox/AlgorithmEventsViewer.java b/jsprit-analysis/src/main/java/jsprit/analysis/toolbox/AlgorithmEventsViewer.java index 3efae707..dea49371 100644 --- a/jsprit-analysis/src/main/java/jsprit/analysis/toolbox/AlgorithmEventsViewer.java +++ b/jsprit-analysis/src/main/java/jsprit/analysis/toolbox/AlgorithmEventsViewer.java @@ -47,7 +47,7 @@ public class AlgorithmEventsViewer { this.delayContainer = delayContainer; } - public void setRuinDelay(long ruinDelay){ + public void setRuinDelay(long ruinDelay) { this.ruinDelay = ruinDelay; } @@ -131,16 +131,14 @@ public class AlgorithmEventsViewer { @Override public void stepBegins(String sourceId, long timeId, double step) { - if(step == AlgorithmEventsRecorder.RECREATE) { + if (step == AlgorithmEventsRecorder.RECREATE) { delayContainer.delay = recreateDelay; } - if(step == AlgorithmEventsRecorder.RUIN){ + if (step == AlgorithmEventsRecorder.RUIN) { delayContainer.delay = ruinDelay; - } - else if(step == AlgorithmEventsRecorder.CLEAR_SOLUTION){ + } else if (step == AlgorithmEventsRecorder.CLEAR_SOLUTION) { delayContainer.delay = delay; - } - else if(step == AlgorithmEventsRecorder.BEFORE_RUIN_RENDER_SOLUTION){ + } else if (step == AlgorithmEventsRecorder.BEFORE_RUIN_RENDER_SOLUTION) { delayContainer.delay = delay; } } @@ -156,15 +154,15 @@ public class AlgorithmEventsViewer { private long delay = 2; - public void setRecreationDelay(long delay_in_ms){ + public void setRecreationDelay(long delay_in_ms) { this.delayRecreation = delay_in_ms; } - public void setRuinDelay(long delay_in_ms){ + public void setRuinDelay(long delay_in_ms) { this.delayRuin = delay_in_ms; } - public void display(String dgsFile){ + public void display(String dgsFile) { System.setProperty("org.graphstream.ui.renderer", "org.graphstream.ui.j2dviewer.J2DGraphRenderer"); Graph graph = GraphStreamViewer.createMultiGraph("g", GraphStreamViewer.StyleSheets.BLUE_FOREST); Viewer viewer = graph.display(); @@ -185,13 +183,13 @@ public class AlgorithmEventsViewer { while (fs.nextEvents()) { sleep(delayContainer.delay); } - } catch( IOException e) { + } catch (IOException e) { e.printStackTrace(); } try { fs.end(); - } catch( IOException e) { + } catch (IOException e) { e.printStackTrace(); } finally { fs.removeSink(graph); diff --git a/jsprit-analysis/src/main/java/jsprit/analysis/toolbox/AlgorithmSearchProgressChartListener.java b/jsprit-analysis/src/main/java/jsprit/analysis/toolbox/AlgorithmSearchProgressChartListener.java index 4136ff8c..5dcca9b3 100644 --- a/jsprit-analysis/src/main/java/jsprit/analysis/toolbox/AlgorithmSearchProgressChartListener.java +++ b/jsprit-analysis/src/main/java/jsprit/analysis/toolbox/AlgorithmSearchProgressChartListener.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.analysis.toolbox; @@ -30,59 +30,58 @@ import java.util.Collection; /** * VehicleRoutingAlgorithm-Listener to record the solution-search-progress. - * + *

*

Register this listener in VehicleRoutingAlgorithm. - * + * * @author stefan schroeder - * */ public class AlgorithmSearchProgressChartListener implements IterationEndsListener, AlgorithmEndsListener, AlgorithmStartsListener { - private static Logger log = LogManager.getLogger(AlgorithmSearchProgressChartListener.class); + private static Logger log = LogManager.getLogger(AlgorithmSearchProgressChartListener.class); - private String filename; - - private XYLineChartBuilder chartBuilder; + private String filename; - /** - * Constructs chart listener with target png-file (filename plus path). - * - * @param pngFileName - */ - public AlgorithmSearchProgressChartListener(String pngFileName) { - super(); - this.filename = pngFileName; - if(!this.filename.endsWith("png")){ - this.filename += ".png"; - } - } + private XYLineChartBuilder chartBuilder; - @Override - public void informAlgorithmEnds(VehicleRoutingProblem problem, Collection solutions) { - log.info("create chart " + filename); - XYLineChartBuilder.saveChartAsPNG(chartBuilder.build(), filename); - } + /** + * Constructs chart listener with target png-file (filename plus path). + * + * @param pngFileName + */ + public AlgorithmSearchProgressChartListener(String pngFileName) { + super(); + this.filename = pngFileName; + if (!this.filename.endsWith("png")) { + this.filename += ".png"; + } + } - @Override - public void informIterationEnds(int i, VehicleRoutingProblem problem, Collection solutions) { - double worst = 0.0; - double best = Double.MAX_VALUE; - double sum = 0.0; - for(VehicleRoutingProblemSolution sol : solutions){ - if(sol.getCost() > worst) worst = Math.min(sol.getCost(),Double.MAX_VALUE); - if(sol.getCost() < best) best = sol.getCost(); - sum += Math.min(sol.getCost(),Double.MAX_VALUE); - } - chartBuilder.addData("best", i, best); - chartBuilder.addData("worst", i, worst); - chartBuilder.addData("avg", i, sum/(double)solutions.size()); - } + @Override + public void informAlgorithmEnds(VehicleRoutingProblem problem, Collection solutions) { + log.info("create chart {}", filename); + XYLineChartBuilder.saveChartAsPNG(chartBuilder.build(), filename); + } + + @Override + public void informIterationEnds(int i, VehicleRoutingProblem problem, Collection solutions) { + double worst = 0.0; + double best = Double.MAX_VALUE; + double sum = 0.0; + for (VehicleRoutingProblemSolution sol : solutions) { + if (sol.getCost() > worst) worst = Math.min(sol.getCost(), Double.MAX_VALUE); + if (sol.getCost() < best) best = sol.getCost(); + sum += Math.min(sol.getCost(), Double.MAX_VALUE); + } + chartBuilder.addData("best", i, best); + chartBuilder.addData("worst", i, worst); + chartBuilder.addData("avg", i, sum / (double) solutions.size()); + } - @Override - public void informAlgorithmStarts(VehicleRoutingProblem problem,VehicleRoutingAlgorithm algorithm,Collection solutions) { - chartBuilder = XYLineChartBuilder.newInstance("search-progress", "iterations", "results"); - } + @Override + public void informAlgorithmStarts(VehicleRoutingProblem problem, VehicleRoutingAlgorithm algorithm, Collection solutions) { + chartBuilder = XYLineChartBuilder.newInstance("search-progress", "iterations", "results"); + } } diff --git a/jsprit-analysis/src/main/java/jsprit/analysis/toolbox/ComputationalLaboratory.java b/jsprit-analysis/src/main/java/jsprit/analysis/toolbox/ComputationalLaboratory.java index 7ebf4b3f..8abf7657 100644 --- a/jsprit-analysis/src/main/java/jsprit/analysis/toolbox/ComputationalLaboratory.java +++ b/jsprit-analysis/src/main/java/jsprit/analysis/toolbox/ComputationalLaboratory.java @@ -1,18 +1,18 @@ /******************************************************************************* * Copyright (c) 2014 Stefan Schroeder. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . - * + * * Contributors: * Stefan Schroeder - initial API and implementation ******************************************************************************/ @@ -33,433 +33,444 @@ import java.util.concurrent.TimeUnit; public class ComputationalLaboratory { - public static interface LabListener { + public static interface LabListener { - } + } - /** - * Listener-interface to listen to calculation. - * - *

Note that calculations are run concurrently, i.e. a unique task that is distributed to an available thread is - * {algorithm, instance, run}. - * - * @author schroeder - * - */ - public static interface CalculationListener extends LabListener{ - - public void calculationStarts(final BenchmarkInstance p, final String algorithmName, final VehicleRoutingAlgorithm algorithm, final int run); - - public void calculationEnds(final BenchmarkInstance p, final String algorithmName, final VehicleRoutingAlgorithm algorithm, final int run, final Collection solutions); - - } + /** + * Listener-interface to listen to calculation. + *

+ *

Note that calculations are run concurrently, i.e. a unique task that is distributed to an available thread is + * {algorithm, instance, run}. + * + * @author schroeder + */ + public static interface CalculationListener extends LabListener { - public static interface LabStartsAndEndsListener extends LabListener { + public void calculationStarts(final BenchmarkInstance p, final String algorithmName, final VehicleRoutingAlgorithm algorithm, final int run); - public void labStarts(List instances, int noAlgorithms, int runs); + public void calculationEnds(final BenchmarkInstance p, final String algorithmName, final VehicleRoutingAlgorithm algorithm, final int run, final Collection solutions); - public void labEnds(); - } - - /** - * Collects whatever indicators you require by algorithmName, instanceName, run and indicator. - * - * @author schroeder - * - */ - public static class DataCollector { - - public static class Key { - private String instanceName; - private String algorithmName; - private int run; - private String indicatorName; - - public Key(String instanceName, String algorithmName, int run,String indicatorName) { - super(); - this.instanceName = instanceName; - this.algorithmName = algorithmName; - this.run = run; - this.indicatorName = indicatorName; - } - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime - * result - + ((algorithmName == null) ? 0 : algorithmName - .hashCode()); - result = prime - * result - + ((indicatorName == null) ? 0 : indicatorName - .hashCode()); - result = prime - * result - + ((instanceName == null) ? 0 : instanceName.hashCode()); - result = prime * result + run; - return result; - } - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - Key other = (Key) obj; - if (algorithmName == null) { - if (other.algorithmName != null) - return false; - } else if (!algorithmName.equals(other.algorithmName)) - return false; - if (indicatorName == null) { - if (other.indicatorName != null) - return false; - } else if (!indicatorName.equals(other.indicatorName)) - return false; - if (instanceName == null) { - if (other.instanceName != null) - return false; - } else if (!instanceName.equals(other.instanceName)) - return false; - if (run != other.run) - return false; - return true; - } - public String getInstanceName() { - return instanceName; - } - public String getAlgorithmName() { - return algorithmName; - } - public int getRun() { - return run; - } - public String getIndicatorName() { - return indicatorName; - } - - @Override - public String toString() { - return "[algorithm="+algorithmName+"][instance="+instanceName+"][run="+run+"][indicator="+indicatorName+"]"; - } - - } - - private final static String SOLUTION_INDICATOR_NAME = "vehicle-routing-problem-solution"; - - private ConcurrentHashMap data = new ConcurrentHashMap(); - - private ConcurrentHashMap solutions = new ConcurrentHashMap(); - /** - * Adds a single date by instanceName, algorithmName, run and indicatorName. - *

If there is already an entry for this instance, algorithm, run and indicatorName, it is overwritten. - * - * @param instanceName - * @param algorithmName - * @param run - * @param indicatorName - * @param value - */ - public void addDate(String instanceName, String algorithmName, int run, String indicatorName, double value){ - if(indicatorName.equals(SOLUTION_INDICATOR_NAME)) throw new IllegalArgumentException(indicatorName + " is already used internally. please choose another indicator-name."); - Key key = new Key(instanceName,algorithmName,run,indicatorName); - data.put(key, value); - } - - public void addSolution(String instanceName, String algorithmName, int run, VehicleRoutingProblemSolution solution){ - Key key = new Key(instanceName,algorithmName,run,SOLUTION_INDICATOR_NAME); - solutions.put(key, solution); - } - - /** - * Returns a collections of indicator values representing the calculated values of individual runs. - * - * @param instanceName - * @param algorithmName - * @param indicator - * @return - */ - public Collection getData(String instanceName, String algorithmName, String indicator){ - List values = new ArrayList(); - for(Key key : data.keySet()){ - if(key.getAlgorithmName().equals(algorithmName) && key.getInstanceName().equals(instanceName) && key.getIndicatorName().equals(indicator)){ - values.add(data.get(key)); - } - } - return values; - } - - /** - * Returns indicator value. - * - * @param instanceName - * @param algorithmName - * @param run - * @param indicator - * @return - */ - public Double getDate(String instanceName, String algorithmName, int run, String indicator){ - return data.get(new Key(instanceName,algorithmName,run,indicator)); - } - - public VehicleRoutingProblemSolution getSolution(String instanceName, String algorithmName, int run){ - return solutions.get(new Key(instanceName,algorithmName,run,"solution")); - } + } - /** - * Returns all keys that have been created. A key is a unique combination of algorithmName, instanceName, run and indicator. - * - * @return - */ - public Set getDataKeySet(){ - return data.keySet(); - } - - public Set getSolutionKeySet(){ - return solutions.keySet(); - } - - public VehicleRoutingProblemSolution getSolution(Key solutionKey){ - return solutions.get(solutionKey); - } - - public Collection getSolutions(){ - return solutions.values(); - } - - /** - * Returns date associated to specified key. - * - * @param key - * @return - */ - public Double getData(Key key){ - return data.get(key); - } - - } - - - private static class Algorithm { - - private String name; - - private VehicleRoutingAlgorithmFactory factory; + public static interface LabStartsAndEndsListener extends LabListener { - public Algorithm(String name, VehicleRoutingAlgorithmFactory factory) { - super(); - this.name = name; - this.factory = factory; - } - - } - - private List benchmarkInstances = new ArrayList(); + public void labStarts(List instances, int noAlgorithms, int runs); - private int runs = 1; - - private Collection listeners = new ArrayList(); + public void labEnds(); + } - private Collection startsAndEndslisteners = new ArrayList(); - - private List algorithms = new ArrayList(); - - private Set algorithmNames = new HashSet(); - - private Set instanceNames = new HashSet(); - - private int threads = 1; - - public ComputationalLaboratory() { + /** + * Collects whatever indicators you require by algorithmName, instanceName, run and indicator. + * + * @author schroeder + */ + public static class DataCollector { - } - - /** - * Adds algorithmFactory by name. - * - * @param name - * @param factory - * @throws IllegalStateException if there is already an algorithmFactory with the same name - */ - public void addAlgorithmFactory(String name, VehicleRoutingAlgorithmFactory factory){ - if(algorithmNames.contains(name)) throw new IllegalStateException("there is already a algorithmFactory with the same name (algorithmName="+name+"). unique names are required."); - algorithms.add(new Algorithm(name,factory)); - algorithmNames.add(name); - } - - public Collection getAlgorithmNames() { - return algorithmNames; - } - - public Collection getInstanceNames(){ - return instanceNames; - } + public static class Key { + private String instanceName; + private String algorithmName; + private int run; + private String indicatorName; - /** - * Adds instance by name. - * - * @param name - * @param problem - * @throws IllegalStateException if there is already an instance with the same name. - */ - public void addInstance(String name, VehicleRoutingProblem problem){ - if(benchmarkInstances.contains(name)) throw new IllegalStateException("there is already an instance with the same name (instanceName="+name+"). unique names are required."); - benchmarkInstances.add(new BenchmarkInstance(name,problem,null,null)); - instanceNames.add(name); - } - - /** - * Adds instance. - * - * @param instance the instance to be added - * @throws IllegalStateException if there is already an instance with the same name. - */ - public void addInstance(BenchmarkInstance instance){ - if(benchmarkInstances.contains(instance.name)) throw new IllegalStateException("there is already an instance with the same name (instanceName="+instance.name+"). unique names are required."); - benchmarkInstances.add(instance); - instanceNames.add(instance.name); - } - - /** - * Adds collection of instances. - * - * @param instances collection of instances to be added - * @throws IllegalStateException if there is already an instance with the same name. - */ - public void addAllInstances(Collection instances){ - for(BenchmarkInstance i : instances){ - addInstance(i); - } - } - - /** - * Adds instance by name, and with best known results. - * - * @param name - * @param problem - * @throws IllegalStateException if there is already an instance with the same name. - */ - public void addInstance(String name, VehicleRoutingProblem problem, Double bestKnownResult, Double bestKnownVehicles){ - addInstance(new BenchmarkInstance(name,problem,bestKnownResult,bestKnownVehicles)); - } - - /** - * Adds listener to listen computational experiments. - * - * @param listener - */ - public void addListener(LabListener listener){ - if(listener instanceof CalculationListener) { - listeners.add((CalculationListener) listener); - } - if(listener instanceof LabStartsAndEndsListener){ - startsAndEndslisteners.add((LabStartsAndEndsListener) listener); - } - } - - /** - * Sets nuOfRuns with same algorithm on same instance. - *

Default is 1 - * - * @param runs - */ - public void setNuOfRuns(int runs){ - this.runs = runs; - } - - /** - * Runs experiments. - * - *

If nuThreads > 1 it runs them concurrently, i.e. individual runs are distributed to available threads. Therefore - * a unique task is defined by its algorithmName, instanceName and its runNumber. - *

If you have one algorithm called "myAlgorithm" and one instance called "myInstance", and you need to run "myAlgorithm" on "myInstance" three times - * with three threads then "myAlgorithm","myInstance",run1 runs on the first thread, "myAlgorithm", "myInstance", run2 on the second etc. - *

You can register whatever analysisTool you require by implementing and registering CalculationListener. Then your tool is informed just - * before a calculation starts as well as just after a calculation has been finished. - * - * @see CalculationListener - * @throws IllegalStateException if either no algorithm or no instance has been specified - */ - public void run(){ - if(algorithms.isEmpty()){ - throw new IllegalStateException("no algorithm specified. at least one algorithm needs to be specified."); - } - if(benchmarkInstances.isEmpty()){ - throw new IllegalStateException("no instance specified. at least one instance needs to be specified."); - } - informStart(); - System.out.println("start benchmarking [nuAlgorithms="+algorithms.size()+"][nuInstances=" + benchmarkInstances.size() + "][runsPerInstance=" + runs + "]"); - double startTime = System.currentTimeMillis(); - ExecutorService executor = Executors.newFixedThreadPool(threads); - for(final Algorithm algorithm : algorithms){ - for(final BenchmarkInstance p : benchmarkInstances){ - for(int run=0;runBy default: nuThreads = Runtime.getRuntime().availableProcessors()+1 - * - * @param threads - */ - public void setThreads(int threads) { - this.threads = threads; - } + public String getIndicatorName() { + return indicatorName; + } - private void runAlgorithm(BenchmarkInstance p, Algorithm algorithm, int run) { - System.out.println("[algorithm=" + algorithm.name + "][instance="+p.name+"][run="+run+"][status=start]"); - VehicleRoutingAlgorithm vra = algorithm.factory.createAlgorithm(p.vrp); - informCalculationStarts(p, algorithm.name, vra, run); - Collection solutions = vra.searchSolutions(); - System.out.println("[algorithm=" + algorithm.name + "][instance="+p.name+"][run="+run+"][status=finished]"); - informCalculationsEnds(p, algorithm.name, vra, run, solutions); - } + @Override + public String toString() { + return "[algorithm=" + algorithmName + "][instance=" + instanceName + "][run=" + run + "][indicator=" + indicatorName + "]"; + } - private void informCalculationStarts(BenchmarkInstance p, String name, VehicleRoutingAlgorithm vra, int run) { - for(CalculationListener l : listeners) l.calculationStarts(p, name, vra, run); - } + } - private void informCalculationsEnds(BenchmarkInstance p, String name, VehicleRoutingAlgorithm vra, int run, - Collection solutions) { - for(CalculationListener l : listeners) l.calculationEnds(p, name, vra, run, solutions); - } + private final static String SOLUTION_INDICATOR_NAME = "vehicle-routing-problem-solution"; + + private ConcurrentHashMap data = new ConcurrentHashMap(); + + private ConcurrentHashMap solutions = new ConcurrentHashMap(); + + /** + * Adds a single date by instanceName, algorithmName, run and indicatorName. + *

If there is already an entry for this instance, algorithm, run and indicatorName, it is overwritten. + * + * @param instanceName + * @param algorithmName + * @param run + * @param indicatorName + * @param value + */ + public void addDate(String instanceName, String algorithmName, int run, String indicatorName, double value) { + if (indicatorName.equals(SOLUTION_INDICATOR_NAME)) + throw new IllegalArgumentException(indicatorName + " is already used internally. please choose another indicator-name."); + Key key = new Key(instanceName, algorithmName, run, indicatorName); + data.put(key, value); + } + + public void addSolution(String instanceName, String algorithmName, int run, VehicleRoutingProblemSolution solution) { + Key key = new Key(instanceName, algorithmName, run, SOLUTION_INDICATOR_NAME); + solutions.put(key, solution); + } + + /** + * Returns a collections of indicator values representing the calculated values of individual runs. + * + * @param instanceName + * @param algorithmName + * @param indicator + * @return + */ + public Collection getData(String instanceName, String algorithmName, String indicator) { + List values = new ArrayList(); + for (Key key : data.keySet()) { + if (key.getAlgorithmName().equals(algorithmName) && key.getInstanceName().equals(instanceName) && key.getIndicatorName().equals(indicator)) { + values.add(data.get(key)); + } + } + return values; + } + + /** + * Returns indicator value. + * + * @param instanceName + * @param algorithmName + * @param run + * @param indicator + * @return + */ + public Double getDate(String instanceName, String algorithmName, int run, String indicator) { + return data.get(new Key(instanceName, algorithmName, run, indicator)); + } + + public VehicleRoutingProblemSolution getSolution(String instanceName, String algorithmName, int run) { + return solutions.get(new Key(instanceName, algorithmName, run, "solution")); + } + + /** + * Returns all keys that have been created. A key is a unique combination of algorithmName, instanceName, run and indicator. + * + * @return + */ + public Set getDataKeySet() { + return data.keySet(); + } + + public Set getSolutionKeySet() { + return solutions.keySet(); + } + + public VehicleRoutingProblemSolution getSolution(Key solutionKey) { + return solutions.get(solutionKey); + } + + public Collection getSolutions() { + return solutions.values(); + } + + /** + * Returns date associated to specified key. + * + * @param key + * @return + */ + public Double getData(Key key) { + return data.get(key); + } + + } + + + private static class Algorithm { + + private String name; + + private VehicleRoutingAlgorithmFactory factory; + + public Algorithm(String name, VehicleRoutingAlgorithmFactory factory) { + super(); + this.name = name; + this.factory = factory; + } + + } + + private List benchmarkInstances = new ArrayList(); + + private int runs = 1; + + private Collection listeners = new ArrayList(); + + private Collection startsAndEndslisteners = new ArrayList(); + + private List algorithms = new ArrayList(); + + private Set algorithmNames = new HashSet(); + + private Set instanceNames = new HashSet(); + + private int threads = 1; + + public ComputationalLaboratory() { + + } + + /** + * Adds algorithmFactory by name. + * + * @param name + * @param factory + * @throws IllegalStateException if there is already an algorithmFactory with the same name + */ + public void addAlgorithmFactory(String name, VehicleRoutingAlgorithmFactory factory) { + if (algorithmNames.contains(name)) + throw new IllegalStateException("there is already a algorithmFactory with the same name (algorithmName=" + name + "). unique names are required."); + algorithms.add(new Algorithm(name, factory)); + algorithmNames.add(name); + } + + public Collection getAlgorithmNames() { + return algorithmNames; + } + + public Collection getInstanceNames() { + return instanceNames; + } + + /** + * Adds instance by name. + * + * @param name + * @param problem + * @throws IllegalStateException if there is already an instance with the same name. + */ + public void addInstance(String name, VehicleRoutingProblem problem) { + if (benchmarkInstances.contains(name)) + throw new IllegalStateException("there is already an instance with the same name (instanceName=" + name + "). unique names are required."); + benchmarkInstances.add(new BenchmarkInstance(name, problem, null, null)); + instanceNames.add(name); + } + + /** + * Adds instance. + * + * @param instance the instance to be added + * @throws IllegalStateException if there is already an instance with the same name. + */ + public void addInstance(BenchmarkInstance instance) { + if (benchmarkInstances.contains(instance.name)) + throw new IllegalStateException("there is already an instance with the same name (instanceName=" + instance.name + "). unique names are required."); + benchmarkInstances.add(instance); + instanceNames.add(instance.name); + } + + /** + * Adds collection of instances. + * + * @param instances collection of instances to be added + * @throws IllegalStateException if there is already an instance with the same name. + */ + public void addAllInstances(Collection instances) { + for (BenchmarkInstance i : instances) { + addInstance(i); + } + } + + /** + * Adds instance by name, and with best known results. + * + * @param name + * @param problem + * @throws IllegalStateException if there is already an instance with the same name. + */ + public void addInstance(String name, VehicleRoutingProblem problem, Double bestKnownResult, Double bestKnownVehicles) { + addInstance(new BenchmarkInstance(name, problem, bestKnownResult, bestKnownVehicles)); + } + + /** + * Adds listener to listen computational experiments. + * + * @param listener + */ + public void addListener(LabListener listener) { + if (listener instanceof CalculationListener) { + listeners.add((CalculationListener) listener); + } + if (listener instanceof LabStartsAndEndsListener) { + startsAndEndslisteners.add((LabStartsAndEndsListener) listener); + } + } + + /** + * Sets nuOfRuns with same algorithm on same instance. + *

Default is 1 + * + * @param runs + */ + public void setNuOfRuns(int runs) { + this.runs = runs; + } + + /** + * Runs experiments. + *

+ *

If nuThreads > 1 it runs them concurrently, i.e. individual runs are distributed to available threads. Therefore + * a unique task is defined by its algorithmName, instanceName and its runNumber. + *

If you have one algorithm called "myAlgorithm" and one instance called "myInstance", and you need to run "myAlgorithm" on "myInstance" three times + * with three threads then "myAlgorithm","myInstance",run1 runs on the first thread, "myAlgorithm", "myInstance", run2 on the second etc. + *

You can register whatever analysisTool you require by implementing and registering CalculationListener. Then your tool is informed just + * before a calculation starts as well as just after a calculation has been finished. + * + * @throws IllegalStateException if either no algorithm or no instance has been specified + * @see CalculationListener + */ + public void run() { + if (algorithms.isEmpty()) { + throw new IllegalStateException("no algorithm specified. at least one algorithm needs to be specified."); + } + if (benchmarkInstances.isEmpty()) { + throw new IllegalStateException("no instance specified. at least one instance needs to be specified."); + } + informStart(); + System.out.println("start benchmarking [nuAlgorithms=" + algorithms.size() + "][nuInstances=" + benchmarkInstances.size() + "][runsPerInstance=" + runs + "]"); + double startTime = System.currentTimeMillis(); + ExecutorService executor = Executors.newFixedThreadPool(threads); + for (final Algorithm algorithm : algorithms) { + for (final BenchmarkInstance p : benchmarkInstances) { + for (int run = 0; run < runs; run++) { + final int r = run; + try { + executor.submit(new Runnable() { + + @Override + public void run() { + runAlgorithm(p, algorithm, r + 1); + } + + }); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + } + } + try { + executor.shutdown(); + executor.awaitTermination(Long.MAX_VALUE, TimeUnit.MINUTES); + + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + System.out.println("benchmarking done [time=" + (System.currentTimeMillis() - startTime) / 1000 + "sec]"); + informEnd(); + } + + private void informEnd() { + for (LabStartsAndEndsListener l : startsAndEndslisteners) { + l.labEnds(); + } + } + + private void informStart() { + for (LabStartsAndEndsListener l : startsAndEndslisteners) { + l.labStarts(benchmarkInstances, algorithms.size(), runs); + } + } + + /** + * Sets number of threads. + *

By default: nuThreads = Runtime.getRuntime().availableProcessors()+1 + * + * @param threads + */ + public void setThreads(int threads) { + this.threads = threads; + } + + private void runAlgorithm(BenchmarkInstance p, Algorithm algorithm, int run) { + System.out.println("[algorithm=" + algorithm.name + "][instance=" + p.name + "][run=" + run + "][status=start]"); + VehicleRoutingAlgorithm vra = algorithm.factory.createAlgorithm(p.vrp); + informCalculationStarts(p, algorithm.name, vra, run); + Collection solutions = vra.searchSolutions(); + System.out.println("[algorithm=" + algorithm.name + "][instance=" + p.name + "][run=" + run + "][status=finished]"); + informCalculationsEnds(p, algorithm.name, vra, run, solutions); + } + + private void informCalculationStarts(BenchmarkInstance p, String name, VehicleRoutingAlgorithm vra, int run) { + for (CalculationListener l : listeners) l.calculationStarts(p, name, vra, run); + } + + private void informCalculationsEnds(BenchmarkInstance p, String name, VehicleRoutingAlgorithm vra, int run, + Collection solutions) { + for (CalculationListener l : listeners) l.calculationEnds(p, name, vra, run, solutions); + } } diff --git a/jsprit-analysis/src/main/java/jsprit/analysis/toolbox/ConcurrentBenchmarker.java b/jsprit-analysis/src/main/java/jsprit/analysis/toolbox/ConcurrentBenchmarker.java index 7b7a8e0b..67586c60 100644 --- a/jsprit-analysis/src/main/java/jsprit/analysis/toolbox/ConcurrentBenchmarker.java +++ b/jsprit-analysis/src/main/java/jsprit/analysis/toolbox/ConcurrentBenchmarker.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.analysis.toolbox; @@ -35,185 +35,185 @@ import java.util.concurrent.*; public class ConcurrentBenchmarker { - - public static interface Cost { - public double getCost(VehicleRoutingProblemSolution sol); - } - - - - private String algorithmConfig = null; - - private List benchmarkInstances = new ArrayList(); - private int runs = 1; - - private Collection writers = new ArrayList(); - - private Collection results = new ArrayList(); - - private Cost cost = new Cost(){ + public static interface Cost { + public double getCost(VehicleRoutingProblemSolution sol); + } - @Override - public double getCost(VehicleRoutingProblemSolution sol) { - return sol.getCost(); - } - - }; - private VehicleRoutingAlgorithmFactory algorithmFactory; - - public void setCost(Cost cost){ this.cost = cost; } - - public ConcurrentBenchmarker(String algorithmConfig) { - super(); - this.algorithmConfig = algorithmConfig; + private String algorithmConfig = null; + + private List benchmarkInstances = new ArrayList(); + + private int runs = 1; + + private Collection writers = new ArrayList(); + + private Collection results = new ArrayList(); + + private Cost cost = new Cost() { + + @Override + public double getCost(VehicleRoutingProblemSolution sol) { + return sol.getCost(); + } + + }; + + private VehicleRoutingAlgorithmFactory algorithmFactory; + + public void setCost(Cost cost) { + this.cost = cost; + } + + public ConcurrentBenchmarker(String algorithmConfig) { + super(); + this.algorithmConfig = algorithmConfig; // LogManager.getRootLogger().setLevel(Level.ERROR); - } - - public ConcurrentBenchmarker(VehicleRoutingAlgorithmFactory algorithmFactory){ - this.algorithmFactory = algorithmFactory; - } - - public void addBenchmarkWriter(BenchmarkWriter writer){ - writers.add(writer); - } + } - public void addInstance(String name, VehicleRoutingProblem problem){ - benchmarkInstances.add(new BenchmarkInstance(name,problem,null,null)); - } - - public void addInstane(BenchmarkInstance instance){ - benchmarkInstances.add(instance); - } - - public void addAllInstances(Collection instances){ - benchmarkInstances.addAll(instances); - } - - public void addInstance(String name, VehicleRoutingProblem problem, Double bestKnownResult, Double bestKnownVehicles){ - benchmarkInstances.add(new BenchmarkInstance(name,problem,bestKnownResult,bestKnownVehicles)); - } - - /** - * Sets nuOfRuns with same algorithm on same instance. - *

Default is 1 - * - * @param runs - */ - public void setNuOfRuns(int runs){ - this.runs = runs; - } - - public void run(){ - System.out.println("start benchmarking [nuOfInstances=" + benchmarkInstances.size() + "][runsPerInstance=" + runs + "]"); - double startTime = System.currentTimeMillis(); - ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()+1); - List> futures = new ArrayList>(); - for(final BenchmarkInstance p : benchmarkInstances){ - - Future futureResult = executor.submit(new Callable(){ + public ConcurrentBenchmarker(VehicleRoutingAlgorithmFactory algorithmFactory) { + this.algorithmFactory = algorithmFactory; + } - @Override - public BenchmarkResult call() throws Exception { - return runAlgoAndGetResult(p); - } + public void addBenchmarkWriter(BenchmarkWriter writer) { + writers.add(writer); + } - }); - futures.add(futureResult); - - } - try { - int count = 1; - for(Future f : futures){ - BenchmarkResult r = f.get(); - print(r,count); - results.add(f.get()); - count++; - } - } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (ExecutionException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - executor.shutdown(); - print(results); - System.out.println("done [time="+(System.currentTimeMillis()-startTime)/1000 + "sec]"); - } + public void addInstance(String name, VehicleRoutingProblem problem) { + benchmarkInstances.add(new BenchmarkInstance(name, problem, null, null)); + } - private BenchmarkResult runAlgoAndGetResult(BenchmarkInstance p) { - double[] vehicles = new double[runs]; - double[] results = new double[runs]; - double[] times = new double[runs]; - - for(int run=0;run solutions = vra.searchSolutions(); - VehicleRoutingProblemSolution best = Solutions.bestOf(solutions); - vehicles[run] = best.getRoutes().size(); - results[run] = cost.getCost(best); - times[run] = stopwatch.getCompTimeInSeconds(); - } - - return new BenchmarkResult(p, runs, results, times, vehicles); - } + public void addInstane(BenchmarkInstance instance) { + benchmarkInstances.add(instance); + } - private VehicleRoutingAlgorithm createAlgorithm(BenchmarkInstance p) { - if(algorithmConfig != null){ - return VehicleRoutingAlgorithms.readAndCreateAlgorithm(p.vrp, algorithmConfig); - } - else{ - return algorithmFactory.createAlgorithm(p.vrp); - } - - } + public void addAllInstances(Collection instances) { + benchmarkInstances.addAll(instances); + } - private void print(Collection results) { - double sumTime=0.0; - double sumResult=0.0; - for(BenchmarkResult r : results){ - sumTime+=r.getTimesStats().getMean(); - sumResult+=r.getResultStats().getMean(); + public void addInstance(String name, VehicleRoutingProblem problem, Double bestKnownResult, Double bestKnownVehicles) { + benchmarkInstances.add(new BenchmarkInstance(name, problem, bestKnownResult, bestKnownVehicles)); + } + + /** + * Sets nuOfRuns with same algorithm on same instance. + *

Default is 1 + * + * @param runs + */ + public void setNuOfRuns(int runs) { + this.runs = runs; + } + + public void run() { + System.out.println("start benchmarking [nuOfInstances=" + benchmarkInstances.size() + "][runsPerInstance=" + runs + "]"); + double startTime = System.currentTimeMillis(); + ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() + 1); + List> futures = new ArrayList>(); + for (final BenchmarkInstance p : benchmarkInstances) { + + Future futureResult = executor.submit(new Callable() { + + @Override + public BenchmarkResult call() throws Exception { + return runAlgoAndGetResult(p); + } + + }); + futures.add(futureResult); + + } + try { + int count = 1; + for (Future f : futures) { + BenchmarkResult r = f.get(); + print(r, count); + results.add(f.get()); + count++; + } + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (ExecutionException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + executor.shutdown(); + print(results); + System.out.println("done [time=" + (System.currentTimeMillis() - startTime) / 1000 + "sec]"); + } + + private BenchmarkResult runAlgoAndGetResult(BenchmarkInstance p) { + double[] vehicles = new double[runs]; + double[] results = new double[runs]; + double[] times = new double[runs]; + + for (int run = 0; run < runs; run++) { + VehicleRoutingAlgorithm vra = createAlgorithm(p); + StopWatch stopwatch = new StopWatch(); + vra.getAlgorithmListeners().addListener(stopwatch, Priority.HIGH); + Collection solutions = vra.searchSolutions(); + VehicleRoutingProblemSolution best = Solutions.bestOf(solutions); + vehicles[run] = best.getRoutes().size(); + results[run] = cost.getCost(best); + times[run] = stopwatch.getCompTimeInSeconds(); + } + + return new BenchmarkResult(p, runs, results, times, vehicles); + } + + private VehicleRoutingAlgorithm createAlgorithm(BenchmarkInstance p) { + if (algorithmConfig != null) { + return VehicleRoutingAlgorithms.readAndCreateAlgorithm(p.vrp, algorithmConfig); + } else { + return algorithmFactory.createAlgorithm(p.vrp); + } + + } + + private void print(Collection results) { + double sumTime = 0.0; + double sumResult = 0.0; + for (BenchmarkResult r : results) { + sumTime += r.getTimesStats().getMean(); + sumResult += r.getResultStats().getMean(); // print(r); - } - System.out.println("[avgTime="+round(sumTime/(double)results.size(),2)+"][avgResult="+round(sumResult/(double)results.size(),2)+"]"); - for(BenchmarkWriter writer : writers){ - writer.write(results); - } - } + } + System.out.println("[avgTime=" + round(sumTime / (double) results.size(), 2) + "][avgResult=" + round(sumResult / (double) results.size(), 2) + "]"); + for (BenchmarkWriter writer : writers) { + writer.write(results); + } + } - private void print(BenchmarkResult r, int count) { - Double avgDelta = null; - Double bestDelta = null; - Double worstDelta = null; - if(r.instance.bestKnownResult != null){ - avgDelta = (r.getResultStats().getMean() / r.instance.bestKnownResult - 1) * 100; - bestDelta = (r.getResultStats().getMin() / r.instance.bestKnownResult - 1) * 100; - worstDelta = (r.getResultStats().getMax() / r.instance.bestKnownResult - 1) * 100; - } - System.out.println("("+count+"/"+benchmarkInstances.size() +")"+ "\t[instance="+r.instance.name+ - "][avgTime="+round(r.getTimesStats().getMean(),2)+"]" + - "[Result=" + getString(r.getResultStats()) + "]" + - "[Vehicles=" + getString(r.getVehicleStats()) + "]" + - "[Delta[%]=" + getString(bestDelta,avgDelta,worstDelta) + "]"); - } - - private String getString(Double bestDelta, Double avgDelta,Double worstDelta) { - return "[best="+round(bestDelta,2)+"][avg="+round(avgDelta,2)+"][worst="+round(worstDelta,2)+"]"; - } + private void print(BenchmarkResult r, int count) { + Double avgDelta = null; + Double bestDelta = null; + Double worstDelta = null; + if (r.instance.bestKnownResult != null) { + avgDelta = (r.getResultStats().getMean() / r.instance.bestKnownResult - 1) * 100; + bestDelta = (r.getResultStats().getMin() / r.instance.bestKnownResult - 1) * 100; + worstDelta = (r.getResultStats().getMax() / r.instance.bestKnownResult - 1) * 100; + } + System.out.println("(" + count + "/" + benchmarkInstances.size() + ")" + "\t[instance=" + r.instance.name + + "][avgTime=" + round(r.getTimesStats().getMean(), 2) + "]" + + "[Result=" + getString(r.getResultStats()) + "]" + + "[Vehicles=" + getString(r.getVehicleStats()) + "]" + + "[Delta[%]=" + getString(bestDelta, avgDelta, worstDelta) + "]"); + } - private String getString(DescriptiveStatistics stats){ - return "[best="+round(stats.getMin(),2)+"][avg="+round(stats.getMean(),2)+"][worst="+round(stats.getMax(),2)+"][stdDev=" + round(stats.getStandardDeviation(),2)+"]"; - } + private String getString(Double bestDelta, Double avgDelta, Double worstDelta) { + return "[best=" + round(bestDelta, 2) + "][avg=" + round(avgDelta, 2) + "][worst=" + round(worstDelta, 2) + "]"; + } - private Double round(Double value, int i) { - if(value==null) return null; - long roundedVal = Math.round(value*Math.pow(10, i)); - return (double)roundedVal/(double)(Math.pow(10, i)); - } + private String getString(DescriptiveStatistics stats) { + return "[best=" + round(stats.getMin(), 2) + "][avg=" + round(stats.getMean(), 2) + "][worst=" + round(stats.getMax(), 2) + "][stdDev=" + round(stats.getStandardDeviation(), 2) + "]"; + } + + private Double round(Double value, int i) { + if (value == null) return null; + long roundedVal = Math.round(value * Math.pow(10, i)); + return (double) roundedVal / (double) (Math.pow(10, i)); + } } diff --git a/jsprit-analysis/src/main/java/jsprit/analysis/toolbox/GraphStreamViewer.java b/jsprit-analysis/src/main/java/jsprit/analysis/toolbox/GraphStreamViewer.java index 673f7a1b..6e8e2a26 100644 --- a/jsprit-analysis/src/main/java/jsprit/analysis/toolbox/GraphStreamViewer.java +++ b/jsprit-analysis/src/main/java/jsprit/analysis/toolbox/GraphStreamViewer.java @@ -46,55 +46,55 @@ public class GraphStreamViewer { public static class StyleSheets { public static String BLUE_FOREST = - "graph { fill-color: #141F2E; }" + - "node {" + - " size: 7px, 7px;" + - " fill-color: #A0FFA0;" + - " text-alignment: at-right;" + - " stroke-mode: plain;" + - " stroke-color: #999;" + - " stroke-width: 1.0;" + - " text-font: couriernew;" + - " text-offset: 2,-5;" + - " text-size: 8;" + - "}" + - "node.pickup {" + - " fill-color: #6CC644;" + - "}" + - "node.delivery {" + - " fill-color: #f93;" + - "}" + - "node.pickupInRoute {" + - " fill-color: #6CC644;" + - " stroke-mode: plain;" + - " stroke-color: #333;" + - " stroke-width: 2.0;" + - "}" + - "node.deliveryInRoute {" + - " fill-color: #f93;" + - " stroke-mode: plain;" + - " stroke-color: #333;" + - " stroke-width: 2.0;" + - "}" + - "node.depot {" + - " fill-color: #BD2C00;" + - " size: 10px, 10px;" + - " shape: box;" + - "}" + - "node.removed {" + - " fill-color: #FF8080;" + - " size: 10px, 10px;" + - " stroke-mode: plain;" + - " stroke-color: #CCF;" + - " stroke-width: 2.0;" + - " shadow-mode: gradient-radial;" + - " shadow-width: 10px; shadow-color: #EEF, #000; shadow-offset: 0px;" + - "}" + + "graph { fill-color: #141F2E; }" + + "node {" + + " size: 7px, 7px;" + + " fill-color: #A0FFA0;" + + " text-alignment: at-right;" + + " stroke-mode: plain;" + + " stroke-color: #999;" + + " stroke-width: 1.0;" + + " text-font: couriernew;" + + " text-offset: 2,-5;" + + " text-size: 8;" + + "}" + + "node.pickup {" + + " fill-color: #6CC644;" + + "}" + + "node.delivery {" + + " fill-color: #f93;" + + "}" + + "node.pickupInRoute {" + + " fill-color: #6CC644;" + + " stroke-mode: plain;" + + " stroke-color: #333;" + + " stroke-width: 2.0;" + + "}" + + "node.deliveryInRoute {" + + " fill-color: #f93;" + + " stroke-mode: plain;" + + " stroke-color: #333;" + + " stroke-width: 2.0;" + + "}" + + "node.depot {" + + " fill-color: #BD2C00;" + + " size: 10px, 10px;" + + " shape: box;" + + "}" + + "node.removed {" + + " fill-color: #FF8080;" + + " size: 10px, 10px;" + + " stroke-mode: plain;" + + " stroke-color: #CCF;" + + " stroke-width: 2.0;" + + " shadow-mode: gradient-radial;" + + " shadow-width: 10px; shadow-color: #EEF, #000; shadow-offset: 0px;" + + "}" + - "edge {" + - " fill-color: #D3D3D3;" + - " arrow-size: 6px,3px;" + - "}" + + "edge {" + + " fill-color: #D3D3D3;" + + " arrow-size: 6px,3px;" + + "}" + // "edge.inserted {" + // " fill-color: #A0FFA0;" + // " arrow-size: 6px,3px;" + @@ -107,69 +107,68 @@ public class GraphStreamViewer { // " shadow-mode: gradient-radial;" + // " shadow-width: 10px; shadow-color: #EEF, #000; shadow-offset: 0px;" + // "}" + - "edge.shipment {" + - " fill-color: #999;" + - " arrow-size: 6px,3px;" + - "}" ; - + "edge.shipment {" + + " fill-color: #999;" + + " arrow-size: 6px,3px;" + + "}"; @SuppressWarnings("UnusedDeclaration") public static String SIMPLE_WHITE = - "node {" + - " size: 10px, 10px;" + - " fill-color: #6CC644;" + - " text-alignment: at-right;" + - " stroke-mode: plain;" + - " stroke-color: #999;" + - " stroke-width: 1.0;" + - " text-font: couriernew;" + - " text-offset: 2,-5;" + - " text-size: 8;" + - "}" + - "node.pickup {" + - " fill-color: #6CC644;" + - "}" + - "node.delivery {" + - " fill-color: #f93;" + - "}" + - "node.pickupInRoute {" + - " fill-color: #6CC644;" + - " stroke-mode: plain;" + - " stroke-color: #333;" + - " stroke-width: 2.0;" + - "}" + - "node.deliveryInRoute {" + - " fill-color: #f93;" + - " stroke-mode: plain;" + - " stroke-color: #333;" + - " stroke-width: 2.0;" + - "}" + - "node.depot {" + - " fill-color: #BD2C00;" + - " size: 10px, 10px;" + - " shape: box;" + - "}" + - "node.removed {" + - " fill-color: #BD2C00;" + - " size: 10px, 10px;" + - " stroke-mode: plain;" + - " stroke-color: #333;" + - " stroke-width: 2.0;" + - "}" + + "node {" + + " size: 10px, 10px;" + + " fill-color: #6CC644;" + + " text-alignment: at-right;" + + " stroke-mode: plain;" + + " stroke-color: #999;" + + " stroke-width: 1.0;" + + " text-font: couriernew;" + + " text-offset: 2,-5;" + + " text-size: 8;" + + "}" + + "node.pickup {" + + " fill-color: #6CC644;" + + "}" + + "node.delivery {" + + " fill-color: #f93;" + + "}" + + "node.pickupInRoute {" + + " fill-color: #6CC644;" + + " stroke-mode: plain;" + + " stroke-color: #333;" + + " stroke-width: 2.0;" + + "}" + + "node.deliveryInRoute {" + + " fill-color: #f93;" + + " stroke-mode: plain;" + + " stroke-color: #333;" + + " stroke-width: 2.0;" + + "}" + + "node.depot {" + + " fill-color: #BD2C00;" + + " size: 10px, 10px;" + + " shape: box;" + + "}" + + "node.removed {" + + " fill-color: #BD2C00;" + + " size: 10px, 10px;" + + " stroke-mode: plain;" + + " stroke-color: #333;" + + " stroke-width: 2.0;" + + "}" + - "edge {" + - " fill-color: #333;" + - " arrow-size: 6px,3px;" + - "}" + - "edge.shipment {" + - " fill-color: #999;" + - " arrow-size: 6px,3px;" + - "}" ; + "edge {" + + " fill-color: #333;" + + " arrow-size: 6px,3px;" + + "}" + + "edge.shipment {" + + " fill-color: #999;" + + " arrow-size: 6px,3px;" + + "}"; } - public static Graph createMultiGraph(String name, String style){ + public static Graph createMultiGraph(String name, String style) { Graph g = new MultiGraph(name); g.addAttribute("ui.quality"); g.addAttribute("ui.antialias"); @@ -177,162 +176,162 @@ public class GraphStreamViewer { return g; } - public static ViewPanel createEmbeddedView(Graph graph, double scaling){ - Viewer viewer = new Viewer(graph,Viewer.ThreadingModel.GRAPH_IN_ANOTHER_THREAD); + public static ViewPanel createEmbeddedView(Graph graph, double scaling) { + Viewer viewer = new Viewer(graph, Viewer.ThreadingModel.GRAPH_IN_ANOTHER_THREAD); ViewPanel view = viewer.addDefaultView(false); view.setPreferredSize(new Dimension((int) (698 * scaling), (int) (440 * scaling))); return view; } - public static String STYLESHEET = - "node {" + - " size: 10px, 10px;" + - " fill-color: #6CC644;" + - " text-alignment: at-right;" + - " stroke-mode: plain;" + - " stroke-color: #999;" + - " stroke-width: 1.0;" + - " text-font: couriernew;" + - " text-offset: 2,-5;" + - " text-size: 8;" + - "}" + - "node.pickup {" + - " fill-color: #6CC644;" + - "}" + - "node.delivery {" + - " fill-color: #f93;" + - "}" + - "node.pickupInRoute {" + - " fill-color: #6CC644;" + - " stroke-mode: plain;" + - " stroke-color: #333;" + - " stroke-width: 2.0;" + - "}" + - "node.deliveryInRoute {" + - " fill-color: #f93;" + - " stroke-mode: plain;" + - " stroke-color: #333;" + - " stroke-width: 2.0;" + - "}" + - "node.depot {" + - " fill-color: #BD2C00;" + - " size: 10px, 10px;" + - " shape: box;" + - "}" + - "node.removed {" + - " fill-color: #BD2C00;" + - " size: 10px, 10px;" + - " stroke-mode: plain;" + - " stroke-color: #333;" + - " stroke-width: 2.0;" + - "}" + - - "edge {" + - " fill-color: #333;" + - " arrow-size: 6px,3px;" + - "}" + - "edge.shipment {" + - " fill-color: #999;" + - " arrow-size: 6px,3px;" + - "}" ; + public static String STYLESHEET = + "node {" + + " size: 10px, 10px;" + + " fill-color: #6CC644;" + + " text-alignment: at-right;" + + " stroke-mode: plain;" + + " stroke-color: #999;" + + " stroke-width: 1.0;" + + " text-font: couriernew;" + + " text-offset: 2,-5;" + + " text-size: 8;" + + "}" + + "node.pickup {" + + " fill-color: #6CC644;" + + "}" + + "node.delivery {" + + " fill-color: #f93;" + + "}" + + "node.pickupInRoute {" + + " fill-color: #6CC644;" + + " stroke-mode: plain;" + + " stroke-color: #333;" + + " stroke-width: 2.0;" + + "}" + + "node.deliveryInRoute {" + + " fill-color: #f93;" + + " stroke-mode: plain;" + + " stroke-color: #333;" + + " stroke-width: 2.0;" + + "}" + + "node.depot {" + + " fill-color: #BD2C00;" + + " size: 10px, 10px;" + + " shape: box;" + + "}" + + "node.removed {" + + " fill-color: #BD2C00;" + + " size: 10px, 10px;" + + " stroke-mode: plain;" + + " stroke-color: #333;" + + " stroke-width: 2.0;" + + "}" + - public static enum Label { - NO_LABEL, ID, JOB_NAME, ARRIVAL_TIME, DEPARTURE_TIME, ACTIVITY - } - - private static class Center { - final double x; - final double y; - - public Center(double x, double y) { - super(); - this.x = x; - this.y = y; - } - - } + "edge {" + + " fill-color: #333;" + + " arrow-size: 6px,3px;" + + "}" + + "edge.shipment {" + + " fill-color: #999;" + + " arrow-size: 6px,3px;" + + "}"; - private Label label = Label.NO_LABEL; + public static enum Label { + NO_LABEL, ID, JOB_NAME, ARRIVAL_TIME, DEPARTURE_TIME, ACTIVITY + } - private long renderDelay_in_ms = 0; + private static class Center { + final double x; + final double y; - private boolean renderShipments = false; - - private Center center; + public Center(double x, double y) { + super(); + this.x = x; + this.y = y; + } - private VehicleRoutingProblem vrp; + } - private VehicleRoutingProblemSolution solution; + private Label label = Label.NO_LABEL; - private double zoomFactor; - - private double scaling = 1.0; + private long renderDelay_in_ms = 0; + + private boolean renderShipments = false; + + private Center center; + + private VehicleRoutingProblem vrp; + + private VehicleRoutingProblemSolution solution; + + private double zoomFactor; + + private double scaling = 1.0; - public GraphStreamViewer(VehicleRoutingProblem vrp) { - super(); - this.vrp = vrp; - } + public GraphStreamViewer(VehicleRoutingProblem vrp) { + super(); + this.vrp = vrp; + } - public GraphStreamViewer(VehicleRoutingProblem vrp, VehicleRoutingProblemSolution solution) { - super(); - this.vrp = vrp; - this.solution = solution; - } + public GraphStreamViewer(VehicleRoutingProblem vrp, VehicleRoutingProblemSolution solution) { + super(); + this.vrp = vrp; + this.solution = solution; + } - public GraphStreamViewer labelWith(Label label){ - this.label=label; - return this; - } + public GraphStreamViewer labelWith(Label label) { + this.label = label; + return this; + } - public GraphStreamViewer setRenderDelay(long ms){ - this.renderDelay_in_ms=ms; - return this; - } + public GraphStreamViewer setRenderDelay(long ms) { + this.renderDelay_in_ms = ms; + return this; + } @Deprecated - public GraphStreamViewer setEnableAutoLayout(boolean enableAutoLayout) { - return this; - } + public GraphStreamViewer setEnableAutoLayout(boolean enableAutoLayout) { + return this; + } - public GraphStreamViewer setRenderShipments(boolean renderShipments){ - this.renderShipments = renderShipments; - return this; - } - - public GraphStreamViewer setGraphStreamFrameScalingFactor(double factor){ - this.scaling=factor; - return this; - } + public GraphStreamViewer setRenderShipments(boolean renderShipments) { + this.renderShipments = renderShipments; + return this; + } - /** - * Sets the camera-view. Center describes the center-focus of the camera and zoomFactor its - * zoomFactor. - * - *

a zoomFactor < 1 zooms in and > 1 out. - * - * @param centerX x coordinate of center - * @param centerY y coordinate of center - * @param zoomFactor zoom factor - * @return the viewer - */ - public GraphStreamViewer setCameraView(double centerX, double centerY, double zoomFactor){ - center = new Center(centerX,centerY); - this.zoomFactor = zoomFactor; - return this; - } - - public void display(){ - System.setProperty("org.graphstream.ui.renderer", "org.graphstream.ui.j2dviewer.J2DGraphRenderer"); + public GraphStreamViewer setGraphStreamFrameScalingFactor(double factor) { + this.scaling = factor; + return this; + } + + /** + * Sets the camera-view. Center describes the center-focus of the camera and zoomFactor its + * zoomFactor. + *

+ *

a zoomFactor < 1 zooms in and > 1 out. + * + * @param centerX x coordinate of center + * @param centerY y coordinate of center + * @param zoomFactor zoom factor + * @return the viewer + */ + public GraphStreamViewer setCameraView(double centerX, double centerY, double zoomFactor) { + center = new Center(centerX, centerY); + this.zoomFactor = zoomFactor; + return this; + } + + public void display() { + System.setProperty("org.graphstream.ui.renderer", "org.graphstream.ui.j2dviewer.J2DGraphRenderer"); Graph g = createMultiGraph("g"); - ViewPanel view = createEmbeddedView(g,scaling); + ViewPanel view = createEmbeddedView(g, scaling); - createJFrame(view,scaling); + createJFrame(view, scaling); render(g, view); - } + } private JFrame createJFrame(ViewPanel view, double scaling) { JFrame jframe = new JFrame(); @@ -345,11 +344,11 @@ public class GraphStreamViewer { JPanel graphStreamPanel = new JPanel(); - graphStreamPanel.setPreferredSize(new Dimension((int)(800*scaling),(int)(460*scaling))); + graphStreamPanel.setPreferredSize(new Dimension((int) (800 * scaling), (int) (460 * scaling))); graphStreamPanel.setBackground(Color.WHITE); JPanel graphStreamBackPanel = new JPanel(); - graphStreamBackPanel.setPreferredSize(new Dimension((int)(700*scaling),(int)(450*scaling))); + graphStreamBackPanel.setPreferredSize(new Dimension((int) (700 * scaling), (int) (450 * scaling))); graphStreamBackPanel.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY, 1)); graphStreamBackPanel.setBackground(Color.WHITE); @@ -365,7 +364,7 @@ public class GraphStreamViewer { jframe.add(basicPanel); //conf jframe - jframe.setSize((int)(800*scaling),(int)(580*scaling)); + jframe.setSize((int) (800 * scaling), (int) (580 * scaling)); jframe.setLocationRelativeTo(null); jframe.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); jframe.setVisible(true); @@ -375,40 +374,39 @@ public class GraphStreamViewer { } private Graph createMultiGraph(String name) { - return GraphStreamViewer.createMultiGraph(name,STYLESHEET); + return GraphStreamViewer.createMultiGraph(name, STYLESHEET); } private void render(Graph g, ViewPanel view) { - if(center != null){ - view.resizeFrame(view.getWidth(), view.getHeight()); + if (center != null) { + view.resizeFrame(view.getWidth(), view.getHeight()); alignCamera(view); - } + } - for(Vehicle vehicle : vrp.getVehicles()){ - renderVehicle(g,vehicle,label); - sleep(renderDelay_in_ms); - } + for (Vehicle vehicle : vrp.getVehicles()) { + renderVehicle(g, vehicle, label); + sleep(renderDelay_in_ms); + } - for(Job j : vrp.getJobs().values()){ - if(j instanceof Service){ - renderService(g,(Service)j,label); - } - else if(j instanceof Shipment){ - renderShipment(g,(Shipment)j,label,renderShipments); - } - sleep(renderDelay_in_ms); - } + for (Job j : vrp.getJobs().values()) { + if (j instanceof Service) { + renderService(g, (Service) j, label); + } else if (j instanceof Shipment) { + renderShipment(g, (Shipment) j, label, renderShipments); + } + sleep(renderDelay_in_ms); + } - if(solution != null){ - int routeId = 1; - for(VehicleRoute route : solution.getRoutes()){ - renderRoute(g,route,routeId,renderDelay_in_ms,label); - sleep(renderDelay_in_ms); - routeId++; - } - } - - } + if (solution != null) { + int routeId = 1; + for (VehicleRoute route : solution.getRoutes()) { + renderRoute(g, route, routeId, renderDelay_in_ms, label); + sleep(renderDelay_in_ms); + routeId++; + } + } + + } private void alignCamera(View view) { view.getCamera().setViewCenter(center.x, center.y, 0); @@ -416,204 +414,202 @@ public class GraphStreamViewer { } private JLabel createEmptyLabel() { - JLabel emptyLabel1 = new JLabel(); - emptyLabel1.setPreferredSize(new Dimension((int)(40*scaling),(int)(25*scaling))); - return emptyLabel1; - } + JLabel emptyLabel1 = new JLabel(); + emptyLabel1.setPreferredSize(new Dimension((int) (40 * scaling), (int) (25 * scaling))); + return emptyLabel1; + } - private JPanel createResultPanel() { - int width = 800; - int height = 50; - - JPanel panel = new JPanel(); - panel.setPreferredSize(new Dimension((int)(width*scaling),(int)(height*scaling))); + private JPanel createResultPanel() { + int width = 800; + int height = 50; + + JPanel panel = new JPanel(); + panel.setPreferredSize(new Dimension((int) (width * scaling), (int) (height * scaling))); panel.setBackground(Color.WHITE); - + JPanel subpanel = new JPanel(); subpanel.setLayout(new FlowLayout()); - subpanel.setPreferredSize(new Dimension((int)(700*scaling),(int)(40*scaling))); + subpanel.setPreferredSize(new Dimension((int) (700 * scaling), (int) (40 * scaling))); subpanel.setBackground(Color.WHITE); - subpanel.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY,1)); - + subpanel.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY, 1)); + Font font = Font.decode("couriernew"); JLabel jobs = new JLabel("jobs"); jobs.setFont(font); - jobs.setPreferredSize(new Dimension((int)(40*scaling),(int)(25*scaling))); + jobs.setPreferredSize(new Dimension((int) (40 * scaling), (int) (25 * scaling))); int noJobs = 0; - if(this.vrp != null) noJobs = this.vrp.getJobs().values().size(); + if (this.vrp != null) noJobs = this.vrp.getJobs().values().size(); JFormattedTextField nJobs = new JFormattedTextField(noJobs); nJobs.setFont(font); nJobs.setEditable(false); nJobs.setBorder(BorderFactory.createEmptyBorder()); - nJobs.setBackground(new Color(230,230,230)); - + nJobs.setBackground(new Color(230, 230, 230)); + JLabel costs = new JLabel("costs"); costs.setFont(font); - costs.setPreferredSize(new Dimension((int)(40*scaling),(int)(25*scaling))); + costs.setPreferredSize(new Dimension((int) (40 * scaling), (int) (25 * scaling))); JFormattedTextField costsVal = new JFormattedTextField(getSolutionCosts()); costsVal.setFont(font); costsVal.setEditable(false); costsVal.setBorder(BorderFactory.createEmptyBorder()); - costsVal.setBackground(new Color(230,230,230)); - + costsVal.setBackground(new Color(230, 230, 230)); + JLabel vehicles = new JLabel("routes"); vehicles.setFont(font); - vehicles.setPreferredSize(new Dimension((int)(40*scaling),(int)(25*scaling))); + vehicles.setPreferredSize(new Dimension((int) (40 * scaling), (int) (25 * scaling))); // vehicles.setForeground(Color.DARK_GRAY); - + JFormattedTextField vehVal = new JFormattedTextField(getNoRoutes()); vehVal.setFont(font); vehVal.setEditable(false); vehVal.setBorder(BorderFactory.createEmptyBorder()); // vehVal.setForeground(Color.DARK_GRAY); - vehVal.setBackground(new Color(230,230,230)); - + vehVal.setBackground(new Color(230, 230, 230)); + //platzhalter JLabel placeholder1 = new JLabel(); - placeholder1.setPreferredSize(new Dimension((int)(60*scaling),(int)(25*scaling))); - + placeholder1.setPreferredSize(new Dimension((int) (60 * scaling), (int) (25 * scaling))); + JLabel emptyLabel1 = createEmptyLabel(); - + subpanel.add(jobs); subpanel.add(nJobs); - + subpanel.add(emptyLabel1); - + subpanel.add(costs); subpanel.add(costsVal); JLabel emptyLabel2 = createEmptyLabel(); subpanel.add(emptyLabel2); - + subpanel.add(vehicles); subpanel.add(vehVal); panel.add(subpanel); - - return panel; - } - private Integer getNoRoutes() { - if(solution!=null) return solution.getRoutes().size(); - return 0; - } - - private Double getSolutionCosts() { - if(solution!=null) return solution.getCost(); - return 0.0; - } - - private void renderShipment(Graph g, Shipment shipment, Label label, boolean renderShipments) { - - Node n1 = g.addNode(makeId(shipment.getId(),shipment.getPickupLocation().getId())); - if(label.equals(Label.ID)) n1.addAttribute("ui.label", shipment.getId()); - n1.addAttribute("x", shipment.getPickupLocation().getCoordinate().getX()); - n1.addAttribute("y", shipment.getPickupLocation().getCoordinate().getY()); - n1.setAttribute("ui.class", "pickup"); - - Node n2 = g.addNode(makeId(shipment.getId(),shipment.getDeliveryLocation().getId())); - if(label.equals(Label.ID)) n2.addAttribute("ui.label", shipment.getId()); - n2.addAttribute("x", shipment.getDeliveryLocation().getCoordinate().getX()); - n2.addAttribute("y", shipment.getDeliveryLocation().getCoordinate().getY()); - n2.setAttribute("ui.class", "delivery"); - - if(renderShipments){ - Edge s = g.addEdge(shipment.getId(), makeId(shipment.getId(),shipment.getPickupLocation().getId()), - makeId(shipment.getId(),shipment.getDeliveryLocation().getId()), true); - s.addAttribute("ui.class", "shipment"); - } - - } - - private void sleep(long renderDelay_in_ms2) { - try { - Thread.sleep(renderDelay_in_ms2); - } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + return panel; } - private void renderService(Graph g, Service service, Label label) { - Node n = g.addNode(makeId(service.getId(),service.getLocation().getId())); - if(label.equals(Label.ID)) n.addAttribute("ui.label", service.getId()); - n.addAttribute("x", service.getLocation().getCoordinate().getX()); - n.addAttribute("y", service.getLocation().getCoordinate().getY()); - if(service.getType().equals("pickup")) n.setAttribute("ui.class", "pickup"); - if(service.getType().equals("delivery")) n.setAttribute("ui.class", "delivery"); - } + private Integer getNoRoutes() { + if (solution != null) return solution.getRoutes().size(); + return 0; + } - private String makeId(String id, String locationId) { - return id + "_" + locationId; - } + private Double getSolutionCosts() { + if (solution != null) return solution.getCost(); + return 0.0; + } - private void renderVehicle(Graph g, Vehicle vehicle, Label label) { - String nodeId = makeId(vehicle.getId(),vehicle.getStartLocation().getId()); + private void renderShipment(Graph g, Shipment shipment, Label label, boolean renderShipments) { + + Node n1 = g.addNode(makeId(shipment.getId(), shipment.getPickupLocation().getId())); + if (label.equals(Label.ID)) n1.addAttribute("ui.label", shipment.getId()); + n1.addAttribute("x", shipment.getPickupLocation().getCoordinate().getX()); + n1.addAttribute("y", shipment.getPickupLocation().getCoordinate().getY()); + n1.setAttribute("ui.class", "pickup"); + + Node n2 = g.addNode(makeId(shipment.getId(), shipment.getDeliveryLocation().getId())); + if (label.equals(Label.ID)) n2.addAttribute("ui.label", shipment.getId()); + n2.addAttribute("x", shipment.getDeliveryLocation().getCoordinate().getX()); + n2.addAttribute("y", shipment.getDeliveryLocation().getCoordinate().getY()); + n2.setAttribute("ui.class", "delivery"); + + if (renderShipments) { + Edge s = g.addEdge(shipment.getId(), makeId(shipment.getId(), shipment.getPickupLocation().getId()), + makeId(shipment.getId(), shipment.getDeliveryLocation().getId()), true); + s.addAttribute("ui.class", "shipment"); + } + + } + + private void sleep(long renderDelay_in_ms2) { + try { + Thread.sleep(renderDelay_in_ms2); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + private void renderService(Graph g, Service service, Label label) { + Node n = g.addNode(makeId(service.getId(), service.getLocation().getId())); + if (label.equals(Label.ID)) n.addAttribute("ui.label", service.getId()); + n.addAttribute("x", service.getLocation().getCoordinate().getX()); + n.addAttribute("y", service.getLocation().getCoordinate().getY()); + if (service.getType().equals("pickup")) n.setAttribute("ui.class", "pickup"); + if (service.getType().equals("delivery")) n.setAttribute("ui.class", "delivery"); + } + + private String makeId(String id, String locationId) { + return id + "_" + locationId; + } + + private void renderVehicle(Graph g, Vehicle vehicle, Label label) { + String nodeId = makeId(vehicle.getId(), vehicle.getStartLocation().getId()); Node vehicleStart = g.addNode(nodeId); - if(label.equals(Label.ID)) vehicleStart.addAttribute("ui.label", "depot"); + if (label.equals(Label.ID)) vehicleStart.addAttribute("ui.label", "depot"); // if(label.equals(Label.ACTIVITY)) n.addAttribute("ui.label", "start"); - vehicleStart.addAttribute("x", vehicle.getStartLocation().getCoordinate().getX()); - vehicleStart.addAttribute("y", vehicle.getStartLocation().getCoordinate().getY()); - vehicleStart.setAttribute("ui.class", "depot"); - - if(!vehicle.getStartLocation().getId().equals(vehicle.getEndLocation().getId())){ - Node vehicleEnd = g.addNode(makeId(vehicle.getId(),vehicle.getEndLocation().getId())); - if(label.equals(Label.ID)) vehicleEnd.addAttribute("ui.label", "depot"); - vehicleEnd.addAttribute("x", vehicle.getEndLocation().getCoordinate().getX()); - vehicleEnd.addAttribute("y", vehicle.getEndLocation().getCoordinate().getY()); - vehicleEnd.setAttribute("ui.class", "depot"); - - } - } + vehicleStart.addAttribute("x", vehicle.getStartLocation().getCoordinate().getX()); + vehicleStart.addAttribute("y", vehicle.getStartLocation().getCoordinate().getY()); + vehicleStart.setAttribute("ui.class", "depot"); - private void renderRoute(Graph g, VehicleRoute route, int routeId, long renderDelay_in_ms, Label label) { - int vehicle_edgeId = 1; - String prevIdentifier = makeId(route.getVehicle().getId(),route.getVehicle().getStartLocation().getId()); - if(label.equals(Label.ACTIVITY) || label.equals(Label.JOB_NAME)){ - Node n = g.getNode(prevIdentifier); - n.addAttribute("ui.label", "start"); - } - for(TourActivity act : route.getActivities()){ + if (!vehicle.getStartLocation().getId().equals(vehicle.getEndLocation().getId())) { + Node vehicleEnd = g.addNode(makeId(vehicle.getId(), vehicle.getEndLocation().getId())); + if (label.equals(Label.ID)) vehicleEnd.addAttribute("ui.label", "depot"); + vehicleEnd.addAttribute("x", vehicle.getEndLocation().getCoordinate().getX()); + vehicleEnd.addAttribute("y", vehicle.getEndLocation().getCoordinate().getY()); + vehicleEnd.setAttribute("ui.class", "depot"); + + } + } + + private void renderRoute(Graph g, VehicleRoute route, int routeId, long renderDelay_in_ms, Label label) { + int vehicle_edgeId = 1; + String prevIdentifier = makeId(route.getVehicle().getId(), route.getVehicle().getStartLocation().getId()); + if (label.equals(Label.ACTIVITY) || label.equals(Label.JOB_NAME)) { + Node n = g.getNode(prevIdentifier); + n.addAttribute("ui.label", "start"); + } + for (TourActivity act : route.getActivities()) { Job job = ((JobActivity) act).getJob(); - String currIdentifier = makeId(job.getId(),act.getLocation().getId()); - if(label.equals(Label.ACTIVITY)){ - Node actNode = g.getNode(currIdentifier); - actNode.addAttribute("ui.label", act.getName()); - } - else if(label.equals(Label.JOB_NAME)){ + String currIdentifier = makeId(job.getId(), act.getLocation().getId()); + if (label.equals(Label.ACTIVITY)) { + Node actNode = g.getNode(currIdentifier); + actNode.addAttribute("ui.label", act.getName()); + } else if (label.equals(Label.JOB_NAME)) { Node actNode = g.getNode(currIdentifier); actNode.addAttribute("ui.label", job.getName()); - } - else if(label.equals(Label.ARRIVAL_TIME)){ + } else if (label.equals(Label.ARRIVAL_TIME)) { Node actNode = g.getNode(currIdentifier); actNode.addAttribute("ui.label", Time.parseSecondsToTime(act.getArrTime())); - } - else if(label.equals(Label.DEPARTURE_TIME)){ + } else if (label.equals(Label.DEPARTURE_TIME)) { Node actNode = g.getNode(currIdentifier); actNode.addAttribute("ui.label", Time.parseSecondsToTime(act.getEndTime())); } - g.addEdge(makeEdgeId(routeId,vehicle_edgeId), prevIdentifier, currIdentifier, true); - if(act instanceof PickupActivity) g.getNode(currIdentifier).addAttribute("ui.class", "pickupInRoute"); - else if (act instanceof DeliveryActivity) g.getNode(currIdentifier).addAttribute("ui.class", "deliveryInRoute"); - prevIdentifier = currIdentifier; - vehicle_edgeId++; - sleep(renderDelay_in_ms); - } - if(route.getVehicle().isReturnToDepot()){ - String lastIdentifier = makeId(route.getVehicle().getId(),route.getVehicle().getEndLocation().getId()); - g.addEdge(makeEdgeId(routeId,vehicle_edgeId), prevIdentifier, lastIdentifier, true); - } - } + g.addEdge(makeEdgeId(routeId, vehicle_edgeId), prevIdentifier, currIdentifier, true); + if (act instanceof PickupActivity) g.getNode(currIdentifier).addAttribute("ui.class", "pickupInRoute"); + else if (act instanceof DeliveryActivity) + g.getNode(currIdentifier).addAttribute("ui.class", "deliveryInRoute"); + prevIdentifier = currIdentifier; + vehicle_edgeId++; + sleep(renderDelay_in_ms); + } + if (route.getVehicle().isReturnToDepot()) { + String lastIdentifier = makeId(route.getVehicle().getId(), route.getVehicle().getEndLocation().getId()); + g.addEdge(makeEdgeId(routeId, vehicle_edgeId), prevIdentifier, lastIdentifier, true); + } + } - private String makeEdgeId(int routeId, int vehicle_edgeId) { - return Integer.valueOf(routeId).toString() + "." + Integer.valueOf(vehicle_edgeId).toString(); - } + private String makeEdgeId(int routeId, int vehicle_edgeId) { + return Integer.valueOf(routeId).toString() + "." + Integer.valueOf(vehicle_edgeId).toString(); + } - // public void saveAsPNG(String filename){ - // - // } + // public void saveAsPNG(String filename){ + // + // } } diff --git a/jsprit-analysis/src/main/java/jsprit/analysis/toolbox/NoLocationFoundException.java b/jsprit-analysis/src/main/java/jsprit/analysis/toolbox/NoLocationFoundException.java index 77df2b6e..4c0a2ecc 100644 --- a/jsprit-analysis/src/main/java/jsprit/analysis/toolbox/NoLocationFoundException.java +++ b/jsprit-analysis/src/main/java/jsprit/analysis/toolbox/NoLocationFoundException.java @@ -1,28 +1,28 @@ /******************************************************************************* * Copyright (c) 2014 Stefan Schroeder. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . - * + * * Contributors: * Stefan Schroeder - initial API and implementation ******************************************************************************/ package jsprit.analysis.toolbox; -class NoLocationFoundException extends Exception{ +class NoLocationFoundException extends Exception { + + /** + * + */ + private static final long serialVersionUID = 1L; - /** - * - */ - private static final long serialVersionUID = 1L; - } diff --git a/jsprit-analysis/src/main/java/jsprit/analysis/toolbox/Plotter.java b/jsprit-analysis/src/main/java/jsprit/analysis/toolbox/Plotter.java index 383dc732..7b7c7b87 100644 --- a/jsprit-analysis/src/main/java/jsprit/analysis/toolbox/Plotter.java +++ b/jsprit-analysis/src/main/java/jsprit/analysis/toolbox/Plotter.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.analysis.toolbox; @@ -51,585 +51,576 @@ import java.util.*; /** * Visualizes problem and solution. *

Note that every item to be rendered need to have coordinates. - * - * @author schroeder * + * @author schroeder */ public class Plotter { - - private final static Color START_COLOR = Color.RED; - private final static Color END_COLOR = Color.RED; - private final static Color PICKUP_COLOR = Color.GREEN; - private final static Color DELIVERY_COLOR = Color.BLUE; - private final static Color SERVICE_COLOR = Color.BLUE; - - private final static Shape ELLIPSE = new Ellipse2D.Double(-3, -3, 6, 6); - - private static class MyActivityRenderer extends XYLineAndShapeRenderer { - /** - * - */ - private static final long serialVersionUID = 1L; - - private XYSeriesCollection seriesCollection; - - private Map activities; - - private Set firstActivities; - - public MyActivityRenderer(XYSeriesCollection seriesCollection,Map activities,Set firstActivities) { - super(false,true); - this.seriesCollection = seriesCollection; - this.activities = activities; - this.firstActivities = firstActivities; - super.setSeriesOutlinePaint(0, Color.DARK_GRAY); - super.setUseOutlinePaint(true); - } + private final static Color START_COLOR = Color.RED; + private final static Color END_COLOR = Color.RED; + private final static Color PICKUP_COLOR = Color.GREEN; + private final static Color DELIVERY_COLOR = Color.BLUE; + private final static Color SERVICE_COLOR = Color.BLUE; - @Override - public Shape getItemShape(int seriesIndex, int itemIndex) { - XYDataItem dataItem = seriesCollection.getSeries(seriesIndex).getDataItem(itemIndex); - if(firstActivities.contains(dataItem)){ - return ShapeUtilities.createUpTriangle(4.0f); - } - return ELLIPSE; - } - - @Override - public Paint getItemOutlinePaint(int seriesIndex, int itemIndex) { - XYDataItem dataItem = seriesCollection.getSeries(seriesIndex).getDataItem(itemIndex); - if(firstActivities.contains(dataItem)){ - return Color.BLACK; - } - return super.getItemOutlinePaint(seriesIndex, itemIndex); - } - - @Override - public Paint getItemPaint(int seriesIndex, int itemIndex) { - XYDataItem dataItem = seriesCollection.getSeries(seriesIndex).getDataItem(itemIndex); - Activity activity = activities.get(dataItem); - if(activity.equals(Activity.PICKUP)) return PICKUP_COLOR; - if(activity.equals(Activity.DELIVERY)) return DELIVERY_COLOR; - if(activity.equals(Activity.SERVICE)) return SERVICE_COLOR; - if(activity.equals(Activity.START)) return START_COLOR; - if(activity.equals(Activity.END)) return END_COLOR; - throw new IllegalStateException("activity at "+dataItem.toString()+" cannot be assigned to a color"); - } - - } - - private static class BoundingBox { - double minX; - double minY; - double maxX; - double maxY; - public BoundingBox(double minX, double minY, double maxX, double maxY) { - super(); - this.minX = minX; - this.minY = minY; - this.maxX = maxX; - this.maxY = maxY; - } - - } - - private enum Activity { - START, END, PICKUP, DELIVERY, SERVICE - } - - - private static Logger log = LogManager.getLogger(Plotter.class); - - /** - * Label to label ID (=jobId), SIZE (=jobSize=jobCapacityDimensions) - * @author schroeder - * - */ - public static enum Label { - ID, SIZE, @SuppressWarnings("UnusedDeclaration")NO_LABEL - } - - private Label label = Label.SIZE; - - private VehicleRoutingProblem vrp; - - private boolean plotSolutionAsWell = false; + private final static Shape ELLIPSE = new Ellipse2D.Double(-3, -3, 6, 6); - private boolean plotShipments = true; + private static class MyActivityRenderer extends XYLineAndShapeRenderer { - private Collection routes; - - private BoundingBox boundingBox = null; - - private Map activitiesByDataItem = new HashMap(); - - private Map labelsByDataItem = new HashMap(); - - private XYSeries activities; - - private Set firstActivities = new HashSet(); - - private boolean containsPickupAct = false; - - private boolean containsDeliveryAct = false; - - private boolean containsServiceAct = false; - - private double scalingFactor = 1.; + /** + * + */ + private static final long serialVersionUID = 1L; - private boolean invert = false; - - /** - * Constructs Plotter with problem. Thus only the problem can be rendered. - * - * @param vrp the routing problem - */ - public Plotter(VehicleRoutingProblem vrp) { - super(); - this.vrp = vrp; - } + private XYSeriesCollection seriesCollection; - /** - * Constructs Plotter with problem and solution to render them both. - * - * @param vrp the routing problem - * @param solution the solution - */ - public Plotter(VehicleRoutingProblem vrp, VehicleRoutingProblemSolution solution) { - super(); - this.vrp = vrp; - this.routes = solution.getRoutes(); - plotSolutionAsWell = true; - } + private Map activities; - /** - * Constructs Plotter with problem and routes to render individual routes. - * - * @param vrp the routing problem - * @param routes routes - */ - public Plotter(VehicleRoutingProblem vrp, Collection routes) { - super(); - this.vrp = vrp; - this.routes = routes; - plotSolutionAsWell = true; - } + private Set firstActivities; - @SuppressWarnings("UnusedDeclaration") - public Plotter setScalingFactor(double scalingFactor){ - this.scalingFactor=scalingFactor; - return this; - } - - /** - * Sets a label. - * @param label of jobs - * @return plotter - */ - public Plotter setLabel(Label label){ - this.label = label; - return this; - } + public MyActivityRenderer(XYSeriesCollection seriesCollection, Map activities, Set firstActivities) { + super(false, true); + this.seriesCollection = seriesCollection; + this.activities = activities; + this.firstActivities = firstActivities; + super.setSeriesOutlinePaint(0, Color.DARK_GRAY); + super.setUseOutlinePaint(true); + } - public Plotter invertCoordinates(boolean invert){ - this.invert = invert; - return this; - } - - /** - * Sets a bounding box to zoom in to certain areas. - * - * @param minX lower left x - * @param minY lower left y - * @param maxX upper right x - * @param maxY upper right y - * @return - */ - @SuppressWarnings("UnusedDeclaration") - public Plotter setBoundingBox(double minX, double minY, double maxX, double maxY){ - boundingBox = new BoundingBox(minX,minY,maxX,maxY); - return this; - } + @Override + public Shape getItemShape(int seriesIndex, int itemIndex) { + XYDataItem dataItem = seriesCollection.getSeries(seriesIndex).getDataItem(itemIndex); + if (firstActivities.contains(dataItem)) { + return ShapeUtilities.createUpTriangle(4.0f); + } + return ELLIPSE; + } - /** - * Flag that indicates whether shipments should be rendered as well. - * - * @param plotShipments flag to plot shipment - * @return the plotter - */ - public Plotter plotShipments(boolean plotShipments) { - this.plotShipments = plotShipments; - return this; - } + @Override + public Paint getItemOutlinePaint(int seriesIndex, int itemIndex) { + XYDataItem dataItem = seriesCollection.getSeries(seriesIndex).getDataItem(itemIndex); + if (firstActivities.contains(dataItem)) { + return Color.BLACK; + } + return super.getItemOutlinePaint(seriesIndex, itemIndex); + } - /** - * Plots problem and/or solution/routes. - * - * @param pngFileName - path and filename - * @param plotTitle - title that appears on top of image - */ - public void plot(String pngFileName, String plotTitle){ - String filename = pngFileName; - if(!pngFileName.endsWith(".png")) filename += ".png"; - if(plotSolutionAsWell){ - plot(vrp, routes, filename, plotTitle); - } - else if(!(vrp.getInitialVehicleRoutes().isEmpty())){ - plot(vrp, vrp.getInitialVehicleRoutes(), filename, plotTitle); - } - else{ - plot(vrp, null, filename, plotTitle); - } - } - - private void plot(VehicleRoutingProblem vrp, final Collection routes, String pngFile, String title){ - log.info("plot to " + pngFile); - XYSeriesCollection problem; - XYSeriesCollection solution = null; - final XYSeriesCollection shipments; - try { - retrieveActivities(vrp); - problem = new XYSeriesCollection(activities); - shipments = makeShipmentSeries(vrp.getJobs().values()); - if(routes!=null) solution = makeSolutionSeries(vrp, routes); - } catch (NoLocationFoundException e) { - log.warn("cannot plot vrp, since coord is missing"); - return; - } - final XYPlot plot = createPlot(problem, shipments, solution); - JFreeChart chart = new JFreeChart(title, plot); - - LegendTitle legend = createLegend(routes, shipments, plot); - chart.removeLegend(); - chart.addLegend(legend); - - save(chart,pngFile); - - } + @Override + public Paint getItemPaint(int seriesIndex, int itemIndex) { + XYDataItem dataItem = seriesCollection.getSeries(seriesIndex).getDataItem(itemIndex); + Activity activity = activities.get(dataItem); + if (activity.equals(Activity.PICKUP)) return PICKUP_COLOR; + if (activity.equals(Activity.DELIVERY)) return DELIVERY_COLOR; + if (activity.equals(Activity.SERVICE)) return SERVICE_COLOR; + if (activity.equals(Activity.START)) return START_COLOR; + if (activity.equals(Activity.END)) return END_COLOR; + throw new IllegalStateException("activity at " + dataItem.toString() + " cannot be assigned to a color"); + } - private LegendTitle createLegend(final Collection routes,final XYSeriesCollection shipments, final XYPlot plot) { - LegendItemSource lis = new LegendItemSource() { + } - @Override - public LegendItemCollection getLegendItems() { - LegendItemCollection lic = new LegendItemCollection(); - LegendItem vehLoc = new LegendItem("vehLoc", Color.RED); - vehLoc.setShape(ELLIPSE); - vehLoc.setShapeVisible(true); - lic.add(vehLoc); - if(containsServiceAct){ - LegendItem item = new LegendItem("service", Color.BLUE); - item.setShape(ELLIPSE); - item.setShapeVisible(true); - lic.add(item); - } - if(containsPickupAct){ - LegendItem item = new LegendItem("pickup", Color.GREEN); - item.setShape(ELLIPSE); - item.setShapeVisible(true); - lic.add(item); - } - if(containsDeliveryAct){ - LegendItem item = new LegendItem("delivery", Color.BLUE); - item.setShape(ELLIPSE); - item.setShapeVisible(true); - lic.add(item); - } - if(routes!=null){ - LegendItem item = new LegendItem("firstActivity",Color.BLACK); - Shape upTriangle = ShapeUtilities.createUpTriangle(3.0f); - item.setShape(upTriangle); - item.setOutlinePaint(Color.BLACK); - - item.setLine(upTriangle); - item.setLinePaint(Color.BLACK); - item.setShapeVisible(true); - - lic.add(item); - } - if(!shipments.getSeries().isEmpty()){ - lic.add(plot.getRenderer(1).getLegendItem(1, 0)); - } - if(routes!=null){ - lic.addAll(plot.getRenderer(2).getLegendItems()); - } - return lic; - } - }; - - LegendTitle legend = new LegendTitle(lis); - legend.setPosition(RectangleEdge.BOTTOM); - return legend; - } + private static class BoundingBox { + double minX; + double minY; + double maxX; + double maxY; - private XYItemRenderer getShipmentRenderer(XYSeriesCollection shipments) { - XYItemRenderer shipmentsRenderer = new XYLineAndShapeRenderer(true, false); // Shapes only - for(int i=0;i routes) throws NoLocationFoundException{ - Locations locations = retrieveLocations(vrp); - XYSeriesCollection coll = new XYSeriesCollection(); - int counter = 1; - for(VehicleRoute route : routes){ - if(route.isEmpty()) continue; - XYSeries series = new XYSeries(counter, false, true); - - Coordinate startCoord = getCoordinate(locations.getCoord(route.getStart().getLocation().getId())); - series.add(startCoord.getX()*scalingFactor, startCoord.getY()*scalingFactor); - - for(TourActivity act : route.getTourActivities().getActivities()){ - Coordinate coord = getCoordinate(locations.getCoord(act.getLocation().getId())); - series.add(coord.getX()*scalingFactor, coord.getY()*scalingFactor); - } - - Coordinate endCoord = getCoordinate(locations.getCoord(route.getEnd().getLocation().getId())); - series.add(endCoord.getX()*scalingFactor, endCoord.getY()*scalingFactor); - - coll.addSeries(series); - counter++; - } - return coll; - } - - private XYSeriesCollection makeShipmentSeries(Collection jobs) throws NoLocationFoundException{ - XYSeriesCollection coll = new XYSeriesCollection(); - if(!plotShipments) return coll; - int sCounter = 1; - String ship = "shipment"; - boolean first = true; - for(Job job : jobs){ - if(!(job instanceof Shipment)){ - continue; - } - Shipment shipment = (Shipment)job; - XYSeries shipmentSeries; - if(first){ - first = false; - shipmentSeries = new XYSeries(ship, false, true); - } - else{ - shipmentSeries = new XYSeries(sCounter, false, true); - sCounter++; - } - Coordinate pickupCoordinate = getCoordinate(shipment.getPickupLocation().getCoordinate()); - Coordinate delCoordinate = getCoordinate(shipment.getDeliveryLocation().getCoordinate()); - shipmentSeries.add(pickupCoordinate.getX()*scalingFactor, pickupCoordinate.getY()*scalingFactor); - shipmentSeries.add(delCoordinate.getX()*scalingFactor, delCoordinate.getY()*scalingFactor); - coll.addSeries(shipmentSeries); - } - return coll; - } + private boolean plotSolutionAsWell = false; - private void addJob(XYSeries activities, Job job) { - if(job instanceof Shipment){ - Shipment s = (Shipment)job; - Coordinate pickupCoordinate = getCoordinate(s.getPickupLocation().getCoordinate()); - XYDataItem dataItem = new XYDataItem(pickupCoordinate.getX()*scalingFactor, pickupCoordinate.getY()*scalingFactor); - activities.add(dataItem); - addLabel(s, dataItem); - markItem(dataItem,Activity.PICKUP); - containsPickupAct = true; + private boolean plotShipments = true; - Coordinate deliveryCoordinate = getCoordinate(s.getDeliveryLocation().getCoordinate()); - XYDataItem dataItem2 = new XYDataItem(deliveryCoordinate.getX()*scalingFactor, deliveryCoordinate.getY()*scalingFactor); - activities.add(dataItem2); - addLabel(s, dataItem2); - markItem(dataItem2,Activity.DELIVERY); - containsDeliveryAct = true; - } - else if(job instanceof Pickup){ - Pickup service = (Pickup)job; - Coordinate coord = getCoordinate(service.getLocation().getCoordinate()); - XYDataItem dataItem = new XYDataItem(coord.getX()*scalingFactor, coord.getY()*scalingFactor); - activities.add(dataItem); - addLabel(service, dataItem); - markItem(dataItem, Activity.PICKUP); - containsPickupAct = true; - } - else if(job instanceof Delivery){ - Delivery service = (Delivery)job; - Coordinate coord = getCoordinate(service.getLocation().getCoordinate()); - XYDataItem dataItem = new XYDataItem(coord.getX()*scalingFactor, coord.getY()*scalingFactor); - activities.add(dataItem); - addLabel(service, dataItem); - markItem(dataItem, Activity.DELIVERY); - containsDeliveryAct = true; - } - else if(job instanceof Service){ - Service service = (Service)job; - Coordinate coord = getCoordinate(service.getLocation().getCoordinate()); - XYDataItem dataItem = new XYDataItem(coord.getX()*scalingFactor, coord.getY()*scalingFactor); - activities.add(dataItem); - addLabel(service, dataItem); - markItem(dataItem, Activity.SERVICE); - containsServiceAct = true; - } - else{ - throw new IllegalStateException("job instanceof " + job.getClass().toString() + ". this is not supported."); - } - } + private Collection routes; - private void addLabel(Job job, XYDataItem dataItem) { - if(this.label.equals(Label.SIZE)){ - labelsByDataItem.put(dataItem, getSizeString(job)); - } - else if(this.label.equals(Label.ID)){ - labelsByDataItem.put(dataItem, String.valueOf(job.getId())); - } - } - - private String getSizeString(Job job) { - StringBuilder builder = new StringBuilder(); - builder.append("("); - boolean firstDim = true; - for(int i=0;i activitiesByDataItem = new HashMap(); - private void retrieveActivities(VehicleRoutingProblem vrp) throws NoLocationFoundException{ - activities = new XYSeries("activities", false, true); - for(Vehicle v : vrp.getVehicles()){ - Coordinate start_coordinate = getCoordinate(v.getStartLocation().getCoordinate()); - if(start_coordinate == null) throw new NoLocationFoundException(); - XYDataItem item = new XYDataItem(start_coordinate.getX()*scalingFactor, start_coordinate.getY()*scalingFactor); - markItem(item,Activity.START); - activities.add(item); - - if(!v.getStartLocation().getId().equals(v.getEndLocation().getId())){ - Coordinate end_coordinate = getCoordinate(v.getEndLocation().getCoordinate()); - if(end_coordinate == null) throw new NoLocationFoundException(); - XYDataItem end_item = new XYDataItem(end_coordinate.getX()*scalingFactor,end_coordinate.getY()*scalingFactor); - markItem(end_item,Activity.END); + private Map labelsByDataItem = new HashMap(); + + private XYSeries activities; + + private Set firstActivities = new HashSet(); + + private boolean containsPickupAct = false; + + private boolean containsDeliveryAct = false; + + private boolean containsServiceAct = false; + + private double scalingFactor = 1.; + + private boolean invert = false; + + /** + * Constructs Plotter with problem. Thus only the problem can be rendered. + * + * @param vrp the routing problem + */ + public Plotter(VehicleRoutingProblem vrp) { + super(); + this.vrp = vrp; + } + + /** + * Constructs Plotter with problem and solution to render them both. + * + * @param vrp the routing problem + * @param solution the solution + */ + public Plotter(VehicleRoutingProblem vrp, VehicleRoutingProblemSolution solution) { + super(); + this.vrp = vrp; + this.routes = solution.getRoutes(); + plotSolutionAsWell = true; + } + + /** + * Constructs Plotter with problem and routes to render individual routes. + * + * @param vrp the routing problem + * @param routes routes + */ + public Plotter(VehicleRoutingProblem vrp, Collection routes) { + super(); + this.vrp = vrp; + this.routes = routes; + plotSolutionAsWell = true; + } + + @SuppressWarnings("UnusedDeclaration") + public Plotter setScalingFactor(double scalingFactor) { + this.scalingFactor = scalingFactor; + return this; + } + + /** + * Sets a label. + * + * @param label of jobs + * @return plotter + */ + public Plotter setLabel(Label label) { + this.label = label; + return this; + } + + public Plotter invertCoordinates(boolean invert) { + this.invert = invert; + return this; + } + + /** + * Sets a bounding box to zoom in to certain areas. + * + * @param minX lower left x + * @param minY lower left y + * @param maxX upper right x + * @param maxY upper right y + * @return + */ + @SuppressWarnings("UnusedDeclaration") + public Plotter setBoundingBox(double minX, double minY, double maxX, double maxY) { + boundingBox = new BoundingBox(minX, minY, maxX, maxY); + return this; + } + + /** + * Flag that indicates whether shipments should be rendered as well. + * + * @param plotShipments flag to plot shipment + * @return the plotter + */ + public Plotter plotShipments(boolean plotShipments) { + this.plotShipments = plotShipments; + return this; + } + + /** + * Plots problem and/or solution/routes. + * + * @param pngFileName - path and filename + * @param plotTitle - title that appears on top of image + */ + public void plot(String pngFileName, String plotTitle) { + String filename = pngFileName; + if (!pngFileName.endsWith(".png")) filename += ".png"; + if (plotSolutionAsWell) { + plot(vrp, routes, filename, plotTitle); + } else if (!(vrp.getInitialVehicleRoutes().isEmpty())) { + plot(vrp, vrp.getInitialVehicleRoutes(), filename, plotTitle); + } else { + plot(vrp, null, filename, plotTitle); + } + } + + private void plot(VehicleRoutingProblem vrp, final Collection routes, String pngFile, String title) { + log.info("plot to {}", pngFile); + XYSeriesCollection problem; + XYSeriesCollection solution = null; + final XYSeriesCollection shipments; + try { + retrieveActivities(vrp); + problem = new XYSeriesCollection(activities); + shipments = makeShipmentSeries(vrp.getJobs().values()); + if (routes != null) solution = makeSolutionSeries(vrp, routes); + } catch (NoLocationFoundException e) { + log.warn("cannot plot vrp, since coord is missing"); + return; + } + final XYPlot plot = createPlot(problem, shipments, solution); + JFreeChart chart = new JFreeChart(title, plot); + + LegendTitle legend = createLegend(routes, shipments, plot); + chart.removeLegend(); + chart.addLegend(legend); + + save(chart, pngFile); + + } + + private LegendTitle createLegend(final Collection routes, final XYSeriesCollection shipments, final XYPlot plot) { + LegendItemSource lis = new LegendItemSource() { + + @Override + public LegendItemCollection getLegendItems() { + LegendItemCollection lic = new LegendItemCollection(); + LegendItem vehLoc = new LegendItem("vehLoc", Color.RED); + vehLoc.setShape(ELLIPSE); + vehLoc.setShapeVisible(true); + lic.add(vehLoc); + if (containsServiceAct) { + LegendItem item = new LegendItem("service", Color.BLUE); + item.setShape(ELLIPSE); + item.setShapeVisible(true); + lic.add(item); + } + if (containsPickupAct) { + LegendItem item = new LegendItem("pickup", Color.GREEN); + item.setShape(ELLIPSE); + item.setShapeVisible(true); + lic.add(item); + } + if (containsDeliveryAct) { + LegendItem item = new LegendItem("delivery", Color.BLUE); + item.setShape(ELLIPSE); + item.setShapeVisible(true); + lic.add(item); + } + if (routes != null) { + LegendItem item = new LegendItem("firstActivity", Color.BLACK); + Shape upTriangle = ShapeUtilities.createUpTriangle(3.0f); + item.setShape(upTriangle); + item.setOutlinePaint(Color.BLACK); + + item.setLine(upTriangle); + item.setLinePaint(Color.BLACK); + item.setShapeVisible(true); + + lic.add(item); + } + if (!shipments.getSeries().isEmpty()) { + lic.add(plot.getRenderer(1).getLegendItem(1, 0)); + } + if (routes != null) { + lic.addAll(plot.getRenderer(2).getLegendItems()); + } + return lic; + } + }; + + LegendTitle legend = new LegendTitle(lis); + legend.setPosition(RectangleEdge.BOTTOM); + return legend; + } + + private XYItemRenderer getShipmentRenderer(XYSeriesCollection shipments) { + XYItemRenderer shipmentsRenderer = new XYLineAndShapeRenderer(true, false); // Shapes only + for (int i = 0; i < shipments.getSeriesCount(); i++) { + shipmentsRenderer.setSeriesPaint(i, Color.DARK_GRAY); + shipmentsRenderer.setSeriesStroke(i, new BasicStroke( + 1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, + 1.f, new float[]{4.0f, 4.0f}, 0.0f + )); + } + return shipmentsRenderer; + } + + private MyActivityRenderer getProblemRenderer(final XYSeriesCollection problem) { + MyActivityRenderer problemRenderer = new MyActivityRenderer(problem, activitiesByDataItem, firstActivities); + problemRenderer.setBaseItemLabelGenerator(new XYItemLabelGenerator() { + + @Override + public String generateLabel(XYDataset arg0, int arg1, int arg2) { + XYDataItem item = problem.getSeries(arg1).getDataItem(arg2); + return labelsByDataItem.get(item); + } + + }); + problemRenderer.setBaseItemLabelsVisible(true); + problemRenderer.setBaseItemLabelPaint(Color.BLACK); + + return problemRenderer; + } + + private Range getRange(final XYSeriesCollection seriesCol) { + if (this.boundingBox == null) return seriesCol.getRangeBounds(false); + else return new Range(boundingBox.minY, boundingBox.maxY); + } + + private Range getDomainRange(final XYSeriesCollection seriesCol) { + if (this.boundingBox == null) return seriesCol.getDomainBounds(true); + else return new Range(boundingBox.minX, boundingBox.maxX); + } + + private XYPlot createPlot(final XYSeriesCollection problem, XYSeriesCollection shipments, XYSeriesCollection solution) { + XYPlot plot = new XYPlot(); + plot.setBackgroundPaint(Color.LIGHT_GRAY); + plot.setRangeGridlinePaint(Color.LIGHT_GRAY); + plot.setDomainGridlinePaint(Color.LIGHT_GRAY); + + XYLineAndShapeRenderer problemRenderer = getProblemRenderer(problem); + plot.setDataset(0, problem); + plot.setRenderer(0, problemRenderer); + + XYItemRenderer shipmentsRenderer = getShipmentRenderer(shipments); + plot.setDataset(1, shipments); + plot.setRenderer(1, shipmentsRenderer); + + if (solution != null) { + XYItemRenderer solutionRenderer = getRouteRenderer(solution); + plot.setDataset(2, solution); + plot.setRenderer(2, solutionRenderer); + } + + NumberAxis xAxis = new NumberAxis(); + NumberAxis yAxis = new NumberAxis(); + + if (boundingBox == null) { + xAxis.setRangeWithMargins(getDomainRange(problem)); + yAxis.setRangeWithMargins(getRange(problem)); + } else { + xAxis.setRangeWithMargins(new Range(boundingBox.minX, boundingBox.maxX)); + yAxis.setRangeWithMargins(new Range(boundingBox.minY, boundingBox.maxY)); + } + + plot.setDomainAxis(xAxis); + plot.setRangeAxis(yAxis); + + return plot; + } + + private XYItemRenderer getRouteRenderer(XYSeriesCollection solutionColl) { + XYItemRenderer solutionRenderer = new XYLineAndShapeRenderer(true, false); // Lines only + for (int i = 0; i < solutionColl.getSeriesCount(); i++) { + XYSeries s = solutionColl.getSeries(i); + XYDataItem firstCustomer = s.getDataItem(1); + firstActivities.add(firstCustomer); + } + return solutionRenderer; + } + + private void save(JFreeChart chart, String pngFile) { + try { + ChartUtilities.saveChartAsPNG(new File(pngFile), chart, 1000, 600); + } catch (IOException e) { + log.error("cannot plot"); + log.error(e); + e.printStackTrace(); + } + } + + private XYSeriesCollection makeSolutionSeries(VehicleRoutingProblem vrp, Collection routes) throws NoLocationFoundException { + Locations locations = retrieveLocations(vrp); + XYSeriesCollection coll = new XYSeriesCollection(); + int counter = 1; + for (VehicleRoute route : routes) { + if (route.isEmpty()) continue; + XYSeries series = new XYSeries(counter, false, true); + + Coordinate startCoord = getCoordinate(locations.getCoord(route.getStart().getLocation().getId())); + series.add(startCoord.getX() * scalingFactor, startCoord.getY() * scalingFactor); + + for (TourActivity act : route.getTourActivities().getActivities()) { + Coordinate coord = getCoordinate(locations.getCoord(act.getLocation().getId())); + series.add(coord.getX() * scalingFactor, coord.getY() * scalingFactor); + } + + Coordinate endCoord = getCoordinate(locations.getCoord(route.getEnd().getLocation().getId())); + series.add(endCoord.getX() * scalingFactor, endCoord.getY() * scalingFactor); + + coll.addSeries(series); + counter++; + } + return coll; + } + + private XYSeriesCollection makeShipmentSeries(Collection jobs) throws NoLocationFoundException { + XYSeriesCollection coll = new XYSeriesCollection(); + if (!plotShipments) return coll; + int sCounter = 1; + String ship = "shipment"; + boolean first = true; + for (Job job : jobs) { + if (!(job instanceof Shipment)) { + continue; + } + Shipment shipment = (Shipment) job; + XYSeries shipmentSeries; + if (first) { + first = false; + shipmentSeries = new XYSeries(ship, false, true); + } else { + shipmentSeries = new XYSeries(sCounter, false, true); + sCounter++; + } + Coordinate pickupCoordinate = getCoordinate(shipment.getPickupLocation().getCoordinate()); + Coordinate delCoordinate = getCoordinate(shipment.getDeliveryLocation().getCoordinate()); + shipmentSeries.add(pickupCoordinate.getX() * scalingFactor, pickupCoordinate.getY() * scalingFactor); + shipmentSeries.add(delCoordinate.getX() * scalingFactor, delCoordinate.getY() * scalingFactor); + coll.addSeries(shipmentSeries); + } + return coll; + } + + private void addJob(XYSeries activities, Job job) { + if (job instanceof Shipment) { + Shipment s = (Shipment) job; + Coordinate pickupCoordinate = getCoordinate(s.getPickupLocation().getCoordinate()); + XYDataItem dataItem = new XYDataItem(pickupCoordinate.getX() * scalingFactor, pickupCoordinate.getY() * scalingFactor); + activities.add(dataItem); + addLabel(s, dataItem); + markItem(dataItem, Activity.PICKUP); + containsPickupAct = true; + + Coordinate deliveryCoordinate = getCoordinate(s.getDeliveryLocation().getCoordinate()); + XYDataItem dataItem2 = new XYDataItem(deliveryCoordinate.getX() * scalingFactor, deliveryCoordinate.getY() * scalingFactor); + activities.add(dataItem2); + addLabel(s, dataItem2); + markItem(dataItem2, Activity.DELIVERY); + containsDeliveryAct = true; + } else if (job instanceof Pickup) { + Pickup service = (Pickup) job; + Coordinate coord = getCoordinate(service.getLocation().getCoordinate()); + XYDataItem dataItem = new XYDataItem(coord.getX() * scalingFactor, coord.getY() * scalingFactor); + activities.add(dataItem); + addLabel(service, dataItem); + markItem(dataItem, Activity.PICKUP); + containsPickupAct = true; + } else if (job instanceof Delivery) { + Delivery service = (Delivery) job; + Coordinate coord = getCoordinate(service.getLocation().getCoordinate()); + XYDataItem dataItem = new XYDataItem(coord.getX() * scalingFactor, coord.getY() * scalingFactor); + activities.add(dataItem); + addLabel(service, dataItem); + markItem(dataItem, Activity.DELIVERY); + containsDeliveryAct = true; + } else if (job instanceof Service) { + Service service = (Service) job; + Coordinate coord = getCoordinate(service.getLocation().getCoordinate()); + XYDataItem dataItem = new XYDataItem(coord.getX() * scalingFactor, coord.getY() * scalingFactor); + activities.add(dataItem); + addLabel(service, dataItem); + markItem(dataItem, Activity.SERVICE); + containsServiceAct = true; + } else { + throw new IllegalStateException("job instanceof " + job.getClass().toString() + ". this is not supported."); + } + } + + private void addLabel(Job job, XYDataItem dataItem) { + if (this.label.equals(Label.SIZE)) { + labelsByDataItem.put(dataItem, getSizeString(job)); + } else if (this.label.equals(Label.ID)) { + labelsByDataItem.put(dataItem, String.valueOf(job.getId())); + } + } + + private String getSizeString(Job job) { + StringBuilder builder = new StringBuilder(); + builder.append("("); + boolean firstDim = true; + for (int i = 0; i < job.getSize().getNuOfDimensions(); i++) { + if (firstDim) { + builder.append(String.valueOf(job.getSize().get(i))); + firstDim = false; + } else { + builder.append(","); + builder.append(String.valueOf(job.getSize().get(i))); + } + } + builder.append(")"); + return builder.toString(); + } + + private Coordinate getCoordinate(Coordinate coordinate) { + if (invert) { + return Coordinate.newInstance(coordinate.getY(), coordinate.getX()); + } + return coordinate; + } + + private void retrieveActivities(VehicleRoutingProblem vrp) throws NoLocationFoundException { + activities = new XYSeries("activities", false, true); + for (Vehicle v : vrp.getVehicles()) { + Coordinate start_coordinate = getCoordinate(v.getStartLocation().getCoordinate()); + if (start_coordinate == null) throw new NoLocationFoundException(); + XYDataItem item = new XYDataItem(start_coordinate.getX() * scalingFactor, start_coordinate.getY() * scalingFactor); + markItem(item, Activity.START); + activities.add(item); + + if (!v.getStartLocation().getId().equals(v.getEndLocation().getId())) { + Coordinate end_coordinate = getCoordinate(v.getEndLocation().getCoordinate()); + if (end_coordinate == null) throw new NoLocationFoundException(); + XYDataItem end_item = new XYDataItem(end_coordinate.getX() * scalingFactor, end_coordinate.getY() * scalingFactor); + markItem(end_item, Activity.END); activities.add(end_item); - } - } - for(Job job : vrp.getJobs().values()){ - addJob(activities, job); - } - for(VehicleRoute r : vrp.getInitialVehicleRoutes()){ - for(Job job : r.getTourActivities().getJobs()){ - addJob(activities, job); - } - } - } - - private void markItem(XYDataItem item, Activity activity) { - activitiesByDataItem.put(item,activity); - } + } + } + for (Job job : vrp.getJobs().values()) { + addJob(activities, job); + } + for (VehicleRoute r : vrp.getInitialVehicleRoutes()) { + for (Job job : r.getTourActivities().getJobs()) { + addJob(activities, job); + } + } + } - private Locations retrieveLocations(VehicleRoutingProblem vrp) throws NoLocationFoundException { - return vrp.getLocations(); - } + private void markItem(XYDataItem item, Activity activity) { + activitiesByDataItem.put(item, activity); + } + + private Locations retrieveLocations(VehicleRoutingProblem vrp) throws NoLocationFoundException { + return vrp.getLocations(); + } } diff --git a/jsprit-analysis/src/main/java/jsprit/analysis/toolbox/StopWatch.java b/jsprit-analysis/src/main/java/jsprit/analysis/toolbox/StopWatch.java index 2ccac67d..b7f61ff7 100644 --- a/jsprit-analysis/src/main/java/jsprit/analysis/toolbox/StopWatch.java +++ b/jsprit-analysis/src/main/java/jsprit/analysis/toolbox/StopWatch.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.analysis.toolbox; @@ -27,51 +27,51 @@ import org.apache.logging.log4j.Logger; import java.util.Collection; -public class StopWatch implements AlgorithmStartsListener, AlgorithmEndsListener{ - - private static Logger log = LogManager.getLogger(StopWatch.class); - - private double ran; - - private double startTime; - - - @Override - public void informAlgorithmStarts(VehicleRoutingProblem problem, VehicleRoutingAlgorithm algorithm, Collection solutions) { - reset(); - start(); - } - - public double getCompTimeInSeconds(){ - return (ran)/1000.0; - } +public class StopWatch implements AlgorithmStartsListener, AlgorithmEndsListener { - @Override - public void informAlgorithmEnds(VehicleRoutingProblem problem, Collection solutions) { - stop(); - log.info("computation time [in sec]: " + getCompTimeInSeconds()); - } - - public void stop(){ - ran += System.currentTimeMillis() - startTime; - } - - public void start(){ - startTime = System.currentTimeMillis(); - } - - public void reset(){ - startTime = 0; - ran = 0; - } - - @Override - public String toString() { - return "stopWatch: " + getCompTimeInSeconds() + " sec"; - } + private static Logger log = LogManager.getLogger(StopWatch.class); + + private double ran; + + private double startTime; + + + @Override + public void informAlgorithmStarts(VehicleRoutingProblem problem, VehicleRoutingAlgorithm algorithm, Collection solutions) { + reset(); + start(); + } + + public double getCompTimeInSeconds() { + return (ran) / 1000.0; + } + + @Override + public void informAlgorithmEnds(VehicleRoutingProblem problem, Collection solutions) { + stop(); + log.info("computation time [in sec]: {}", getCompTimeInSeconds()); + } + + public void stop() { + ran += System.currentTimeMillis() - startTime; + } + + public void start() { + startTime = System.currentTimeMillis(); + } + + public void reset() { + startTime = 0; + ran = 0; + } + + @Override + public String toString() { + return "stopWatch: " + getCompTimeInSeconds() + " sec"; + } + + public double getCurrTimeInSeconds() { + return (System.currentTimeMillis() - startTime) / 1000.0; + } - public double getCurrTimeInSeconds() { - return (System.currentTimeMillis()-startTime)/1000.0; - } - } diff --git a/jsprit-analysis/src/main/java/jsprit/analysis/toolbox/XYLineChartBuilder.java b/jsprit-analysis/src/main/java/jsprit/analysis/toolbox/XYLineChartBuilder.java index b1a5145d..923ac4ff 100644 --- a/jsprit-analysis/src/main/java/jsprit/analysis/toolbox/XYLineChartBuilder.java +++ b/jsprit-analysis/src/main/java/jsprit/analysis/toolbox/XYLineChartBuilder.java @@ -1,18 +1,18 @@ /******************************************************************************* * Copyright (c) 2014 Stefan Schroeder. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . - * + * * Contributors: * Stefan Schroeder - initial API and implementation ******************************************************************************/ @@ -32,82 +32,80 @@ import java.io.IOException; import java.util.concurrent.ConcurrentHashMap; /** - * * @author schroeder - * */ public class XYLineChartBuilder { - - /** - * Helper that just saves the chart as specified png-file. The width of the image is 1000 and height 600. - * - * @param chart - * @param pngFilename - */ - public static void saveChartAsPNG(JFreeChart chart, String pngFilename){ - try { - ChartUtilities.saveChartAsPNG(new File(pngFilename), chart, 1000, 600); - } catch (IOException e) { - e.printStackTrace(); - } - } - - /** - * Returns a new instance of the builder. - * - * @param chartTitle appears on top of the XYLineChart - * @param xDomainName appears below the xAxis - * @param yDomainName appears beside the yAxis - * - * @return the builder - */ - public static XYLineChartBuilder newInstance(String chartTitle, String xDomainName, String yDomainName){ - return new XYLineChartBuilder(chartTitle, xDomainName, yDomainName); - } - - private ConcurrentHashMap seriesMap = new ConcurrentHashMap(); - - private final String xDomain; - - private final String yDomain; - - private final String chartName; - - private XYLineChartBuilder(String chartName, String xDomainName, String yDomainName) { - this.xDomain=xDomainName; - this.yDomain=yDomainName; - this.chartName=chartName; - } - - /** - * Adds data to the according series (i.e. XYLine). - * - * @param seriesName - * @param xVal - * @param yVal - */ - public void addData(String seriesName, double xVal, double yVal){ - if(!seriesMap.containsKey(seriesName)){ - seriesMap.put(seriesName, new XYSeries(seriesName,true,true)); - } - seriesMap.get(seriesName).add(xVal, yVal); - } - - /** - * Builds and returns JFreeChart. - * @return - */ - public JFreeChart build(){ - XYSeriesCollection collection = new XYSeriesCollection(); - for(XYSeries s : seriesMap.values()){ - collection.addSeries(s); - } - JFreeChart chart = ChartFactory.createXYLineChart(chartName, xDomain, yDomain, collection, PlotOrientation.VERTICAL, true, true, false); - XYPlot plot = chart.getXYPlot(); - plot.setBackgroundPaint(Color.WHITE); - plot.setDomainGridlinePaint(Color.LIGHT_GRAY); - plot.setRangeGridlinePaint(Color.LIGHT_GRAY); - return chart; - } + + /** + * Helper that just saves the chart as specified png-file. The width of the image is 1000 and height 600. + * + * @param chart + * @param pngFilename + */ + public static void saveChartAsPNG(JFreeChart chart, String pngFilename) { + try { + ChartUtilities.saveChartAsPNG(new File(pngFilename), chart, 1000, 600); + } catch (IOException e) { + e.printStackTrace(); + } + } + + /** + * Returns a new instance of the builder. + * + * @param chartTitle appears on top of the XYLineChart + * @param xDomainName appears below the xAxis + * @param yDomainName appears beside the yAxis + * @return the builder + */ + public static XYLineChartBuilder newInstance(String chartTitle, String xDomainName, String yDomainName) { + return new XYLineChartBuilder(chartTitle, xDomainName, yDomainName); + } + + private ConcurrentHashMap seriesMap = new ConcurrentHashMap(); + + private final String xDomain; + + private final String yDomain; + + private final String chartName; + + private XYLineChartBuilder(String chartName, String xDomainName, String yDomainName) { + this.xDomain = xDomainName; + this.yDomain = yDomainName; + this.chartName = chartName; + } + + /** + * Adds data to the according series (i.e. XYLine). + * + * @param seriesName + * @param xVal + * @param yVal + */ + public void addData(String seriesName, double xVal, double yVal) { + if (!seriesMap.containsKey(seriesName)) { + seriesMap.put(seriesName, new XYSeries(seriesName, true, true)); + } + seriesMap.get(seriesName).add(xVal, yVal); + } + + /** + * Builds and returns JFreeChart. + * + * @return + */ + public JFreeChart build() { + XYSeriesCollection collection = new XYSeriesCollection(); + for (XYSeries s : seriesMap.values()) { + collection.addSeries(s); + } + JFreeChart chart = ChartFactory.createXYLineChart(chartName, xDomain, yDomain, collection, PlotOrientation.VERTICAL, true, true, false); + XYPlot plot = chart.getXYPlot(); + plot.setBackgroundPaint(Color.WHITE); + plot.setDomainGridlinePaint(Color.LIGHT_GRAY); + plot.setRangeGridlinePaint(Color.LIGHT_GRAY); + return chart; + } } diff --git a/jsprit-analysis/src/main/java/jsprit/analysis/util/BenchmarkWriter.java b/jsprit-analysis/src/main/java/jsprit/analysis/util/BenchmarkWriter.java index a4b2be2b..7529fc79 100644 --- a/jsprit-analysis/src/main/java/jsprit/analysis/util/BenchmarkWriter.java +++ b/jsprit-analysis/src/main/java/jsprit/analysis/util/BenchmarkWriter.java @@ -1,25 +1,25 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.analysis.util; -import java.util.Collection; - import jsprit.core.util.BenchmarkResult; +import java.util.Collection; + public interface BenchmarkWriter { - public void write(Collection results); + public void write(Collection results); } diff --git a/jsprit-analysis/src/main/java/jsprit/analysis/util/HtmlBenchmarkTableWriter.java b/jsprit-analysis/src/main/java/jsprit/analysis/util/HtmlBenchmarkTableWriter.java index 5cc3d8b3..c4159dcd 100644 --- a/jsprit-analysis/src/main/java/jsprit/analysis/util/HtmlBenchmarkTableWriter.java +++ b/jsprit-analysis/src/main/java/jsprit/analysis/util/HtmlBenchmarkTableWriter.java @@ -1,259 +1,256 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.analysis.util; +import jsprit.core.util.BenchmarkResult; + import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.util.Collection; -import jsprit.core.util.BenchmarkResult; +public class HtmlBenchmarkTableWriter implements BenchmarkWriter { -public class HtmlBenchmarkTableWriter implements BenchmarkWriter{ + private String filename; - private String filename; - - public HtmlBenchmarkTableWriter(String filename) { - this.filename = filename; - } + public HtmlBenchmarkTableWriter(String filename) { + this.filename = filename; + } - @Override - public void write(Collection results) { - - try { - BufferedWriter writer = new BufferedWriter(new FileWriter(new File(filename))); - writer.write(openTable() + newline()); - //table head - writer.write(openRow() + newline()); - writer.write(head("inst") + newline()); - writer.write(head("runs") + newline()); - writer.write(head("Ø time [sec]") + newline()); - writer.write(head("results",4)); - writer.write(head("vehicles",4)); - writer.write(head("res*") + newline()); - writer.write(head("veh*") + newline()); - writer.write(closeRow() + newline()); - - writer.write(openRow() + newline()); - writer.write(head("") + newline()); - writer.write(head("") + newline()); - writer.write(head("") + newline()); - writer.write(head("best") + newline()); - writer.write(head("avg") + newline()); - writer.write(head("worst") + newline()); - writer.write(head("stdev") + newline()); - writer.write(head("best") + newline()); - writer.write(head("avg") + newline()); - writer.write(head("worst") + newline()); - writer.write(head("stdev") + newline()); - writer.write(head("") + newline()); - writer.write(head("") + newline()); - writer.write(closeRow() + newline()); - - //data - double sum_avg_time = 0.0; - double sum_best_result = 0.0; - double sum_avg_result = 0.0; - double sum_worst_result = 0.0; - double sum_dev_result = 0.0; - - double sum_best_veh = 0.0; - double sum_avg_veh = 0.0; - double sum_worst_veh = 0.0; - double sum_dev_veh = 0.0; - - Integer runs = null; - Double sum_res_star=null; - Double sum_veh_star=null; - - for(BenchmarkResult result : results){ - if(runs==null) runs=result.runs; - writer.write(openRow() + newline()); - writer.write(date(result.instance.name) + newline()); - writer.write(date(Integer.valueOf(result.runs).toString()) + newline()); - - Double avg_time = round(result.getTimesStats().getMean(),2); - writer.write(date(Double.valueOf(avg_time).toString()) + newline()); - //bestRes - Double best_result = round(result.getResultStats().getMin(),2); - writer.write(date(Double.valueOf(best_result).toString()) + newline()); - //avgRes - Double avg_result = round(result.getResultStats().getMean(),2); - writer.write(date(Double.valueOf(avg_result).toString()) + newline()); - //worstRes - Double worst_result = round(result.getResultStats().getMax(),2); - writer.write(date(Double.valueOf(worst_result).toString()) + newline()); - //stdevRes - Double std_result = round(result.getResultStats().getStandardDeviation(),2); - writer.write(date(Double.valueOf(std_result).toString()) + newline()); - //bestVeh - Double best_vehicle = round(result.getVehicleStats().getMin(),2); - writer.write(date(Double.valueOf(best_vehicle).toString()) + newline()); - //avgVeh - Double avg_vehicle = round(result.getVehicleStats().getMean(),2); - writer.write(date(Double.valueOf(avg_vehicle).toString()) + newline()); - //worstVeh - Double worst_vehicle = round(result.getVehicleStats().getMax(),2); - writer.write(date(Double.valueOf(worst_vehicle).toString()) + newline()); - //stdevVeh - Double std_vehicle = round(result.getVehicleStats().getStandardDeviation(),2); - writer.write(date(Double.valueOf(std_vehicle).toString()) + newline()); - //bestKnownRes - writer.write(date("" + result.instance.bestKnownResult + newline())); - //bestKnownVeh - writer.write(date("" + result.instance.bestKnownVehicles + newline())); - writer.write(closeRow() + newline()); - - sum_avg_time+=avg_time; - sum_best_result+=best_result; - sum_avg_result+=avg_result; - sum_worst_result+=worst_result; - sum_dev_result+=std_result; - - sum_best_veh+=best_vehicle; - sum_avg_veh+=avg_vehicle; - sum_worst_veh+=worst_vehicle; - sum_dev_veh+=std_vehicle; - - if(result.instance.bestKnownResult != null){ - if(sum_res_star==null) sum_res_star=result.instance.bestKnownResult; - else sum_res_star+=result.instance.bestKnownResult; - } - if(result.instance.bestKnownVehicles != null){ - if(sum_veh_star==null) sum_veh_star=result.instance.bestKnownVehicles; - else sum_veh_star+=result.instance.bestKnownVehicles; - } - - } - writer.write(openRow() + newline()); - writer.write(date("Ø") + newline()); - writer.write(date(""+runs) + newline()); - - Double average_time = round(sum_avg_time/(double)results.size(),2); - writer.write(date(Double.valueOf(average_time).toString()) + newline()); - //bestRes - writer.write(date(Double.valueOf(round(sum_best_result/(double)results.size(),2)).toString()) + newline()); - //avgRes - Double average_result = round(sum_avg_result/(double)results.size(),2); - writer.write(date(Double.valueOf(average_result).toString()) + newline()); - //worstRes - writer.write(date(Double.valueOf(round(sum_worst_result/(double)results.size(),2)).toString()) + newline()); - //stdevRes - writer.write(date(Double.valueOf(round(sum_dev_result/(double)results.size(),2)).toString()) + newline()); - //bestVeh - writer.write(date(Double.valueOf(round(sum_best_veh/(double)results.size(),2)).toString()) + newline()); - //avgVeh - Double average_vehicles = round(sum_avg_veh/(double)results.size(),2); - writer.write(date(Double.valueOf(average_vehicles).toString()) + newline()); - //worstVeh - writer.write(date(Double.valueOf(round(sum_worst_veh/(double)results.size(),2)).toString()) + newline()); - //stdevVeh - writer.write(date(Double.valueOf(round(sum_dev_veh/(double)results.size(),2)).toString()) + newline()); - //bestKnownRes - Double delta_res = null; - if(sum_res_star != null){ - writer.write(date(Double.valueOf(round(sum_res_star.doubleValue()/(double)results.size(),2)).toString()) + newline()); - delta_res = (sum_avg_result/sum_res_star - 1)*100; - } - else writer.write(date("null") + newline()); - //bestKnownVeh - Double delta_veh = null; - if(sum_veh_star != null){ - writer.write(date(Double.valueOf(round(sum_veh_star.doubleValue()/(double)results.size(),2)).toString()) + newline()); - delta_veh = (sum_avg_veh - sum_veh_star)/(double)results.size(); - } - else writer.write(date("null") + newline()); - writer.write(closeRow() + newline()); - - writer.write(closeTable() + newline()); - - writer.write("avg. percentage deviation to best-known result: " + round(delta_res,2) + newline() + newline()); - writer.write("avg. absolute deviation to best-known vehicles: " + round(delta_veh,2) + newline()); - - writer.write(openTable() + newline()); - writer.write(openRow() + newline()); - writer.write(date("") + newline()); - writer.write(date("") + newline()); - writer.write(date("") + newline()); - writer.write(date("") + newline()); - writer.write(date(Double.valueOf(average_time).toString(),"align=\"right\"") + newline()); - writer.write(date(Double.valueOf(average_result).toString(),"align=\"right\"") + newline()); - writer.write(date(Double.valueOf(average_vehicles).toString(),"align=\"right\"") + newline()); - if(delta_res != null){ - writer.write(date(Double.valueOf(round(delta_res,2)).toString(),"align=\"right\"") + newline()); - }else writer.write(date("n.a.") + newline()); - if(delta_veh != null){ - writer.write(date(Double.valueOf(round(delta_veh,2)).toString(),"align=\"right\"") + newline()); - }else writer.write(date("n.a.") + newline()); - writer.write(closeRow() + newline()); - writer.write(closeTable() + newline()); - - - writer.close(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - } - - private String head(String string, int i) { - return ""+string+""; - } + @Override + public void write(Collection results) { - private Double round(Double value, int i) { - if(value==null) return null; - long roundedVal = Math.round(value*Math.pow(10, i)); - return (double)roundedVal/(double)(Math.pow(10, i)); - } + try { + BufferedWriter writer = new BufferedWriter(new FileWriter(new File(filename))); + writer.write(openTable() + newline()); + //table head + writer.write(openRow() + newline()); + writer.write(head("inst") + newline()); + writer.write(head("runs") + newline()); + writer.write(head("Ø time [sec]") + newline()); + writer.write(head("results", 4)); + writer.write(head("vehicles", 4)); + writer.write(head("res*") + newline()); + writer.write(head("veh*") + newline()); + writer.write(closeRow() + newline()); - private String head(String head) { - return ""+head+""; - } + writer.write(openRow() + newline()); + writer.write(head("") + newline()); + writer.write(head("") + newline()); + writer.write(head("") + newline()); + writer.write(head("best") + newline()); + writer.write(head("avg") + newline()); + writer.write(head("worst") + newline()); + writer.write(head("stdev") + newline()); + writer.write(head("best") + newline()); + writer.write(head("avg") + newline()); + writer.write(head("worst") + newline()); + writer.write(head("stdev") + newline()); + writer.write(head("") + newline()); + writer.write(head("") + newline()); + writer.write(closeRow() + newline()); - private String closeTable() { - return ""; - } + //data + double sum_avg_time = 0.0; + double sum_best_result = 0.0; + double sum_avg_result = 0.0; + double sum_worst_result = 0.0; + double sum_dev_result = 0.0; - private String openTable() { - return ""; - } + double sum_best_veh = 0.0; + double sum_avg_veh = 0.0; + double sum_worst_veh = 0.0; + double sum_dev_veh = 0.0; - private String closeRow() { - return ""; - } + Integer runs = null; + Double sum_res_star = null; + Double sum_veh_star = null; - private String date(String date) { - return ""; - } - - private String date(String date, String metaData) { - return ""; - } + for (BenchmarkResult result : results) { + if (runs == null) runs = result.runs; + writer.write(openRow() + newline()); + writer.write(date(result.instance.name) + newline()); + writer.write(date(Integer.valueOf(result.runs).toString()) + newline()); - private String newline() { - return "\n"; - } + Double avg_time = round(result.getTimesStats().getMean(), 2); + writer.write(date(Double.valueOf(avg_time).toString()) + newline()); + //bestRes + Double best_result = round(result.getResultStats().getMin(), 2); + writer.write(date(Double.valueOf(best_result).toString()) + newline()); + //avgRes + Double avg_result = round(result.getResultStats().getMean(), 2); + writer.write(date(Double.valueOf(avg_result).toString()) + newline()); + //worstRes + Double worst_result = round(result.getResultStats().getMax(), 2); + writer.write(date(Double.valueOf(worst_result).toString()) + newline()); + //stdevRes + Double std_result = round(result.getResultStats().getStandardDeviation(), 2); + writer.write(date(Double.valueOf(std_result).toString()) + newline()); + //bestVeh + Double best_vehicle = round(result.getVehicleStats().getMin(), 2); + writer.write(date(Double.valueOf(best_vehicle).toString()) + newline()); + //avgVeh + Double avg_vehicle = round(result.getVehicleStats().getMean(), 2); + writer.write(date(Double.valueOf(avg_vehicle).toString()) + newline()); + //worstVeh + Double worst_vehicle = round(result.getVehicleStats().getMax(), 2); + writer.write(date(Double.valueOf(worst_vehicle).toString()) + newline()); + //stdevVeh + Double std_vehicle = round(result.getVehicleStats().getStandardDeviation(), 2); + writer.write(date(Double.valueOf(std_vehicle).toString()) + newline()); + //bestKnownRes + writer.write(date("" + result.instance.bestKnownResult + newline())); + //bestKnownVeh + writer.write(date("" + result.instance.bestKnownVehicles + newline())); + writer.write(closeRow() + newline()); - private String openRow() { - return ""; - } + sum_avg_time += avg_time; + sum_best_result += best_result; + sum_avg_result += avg_result; + sum_worst_result += worst_result; + sum_dev_result += std_result; + + sum_best_veh += best_vehicle; + sum_avg_veh += avg_vehicle; + sum_worst_veh += worst_vehicle; + sum_dev_veh += std_vehicle; + + if (result.instance.bestKnownResult != null) { + if (sum_res_star == null) sum_res_star = result.instance.bestKnownResult; + else sum_res_star += result.instance.bestKnownResult; + } + if (result.instance.bestKnownVehicles != null) { + if (sum_veh_star == null) sum_veh_star = result.instance.bestKnownVehicles; + else sum_veh_star += result.instance.bestKnownVehicles; + } + + } + writer.write(openRow() + newline()); + writer.write(date("Ø") + newline()); + writer.write(date("" + runs) + newline()); + + Double average_time = round(sum_avg_time / (double) results.size(), 2); + writer.write(date(Double.valueOf(average_time).toString()) + newline()); + //bestRes + writer.write(date(Double.valueOf(round(sum_best_result / (double) results.size(), 2)).toString()) + newline()); + //avgRes + Double average_result = round(sum_avg_result / (double) results.size(), 2); + writer.write(date(Double.valueOf(average_result).toString()) + newline()); + //worstRes + writer.write(date(Double.valueOf(round(sum_worst_result / (double) results.size(), 2)).toString()) + newline()); + //stdevRes + writer.write(date(Double.valueOf(round(sum_dev_result / (double) results.size(), 2)).toString()) + newline()); + //bestVeh + writer.write(date(Double.valueOf(round(sum_best_veh / (double) results.size(), 2)).toString()) + newline()); + //avgVeh + Double average_vehicles = round(sum_avg_veh / (double) results.size(), 2); + writer.write(date(Double.valueOf(average_vehicles).toString()) + newline()); + //worstVeh + writer.write(date(Double.valueOf(round(sum_worst_veh / (double) results.size(), 2)).toString()) + newline()); + //stdevVeh + writer.write(date(Double.valueOf(round(sum_dev_veh / (double) results.size(), 2)).toString()) + newline()); + //bestKnownRes + Double delta_res = null; + if (sum_res_star != null) { + writer.write(date(Double.valueOf(round(sum_res_star.doubleValue() / (double) results.size(), 2)).toString()) + newline()); + delta_res = (sum_avg_result / sum_res_star - 1) * 100; + } else writer.write(date("null") + newline()); + //bestKnownVeh + Double delta_veh = null; + if (sum_veh_star != null) { + writer.write(date(Double.valueOf(round(sum_veh_star.doubleValue() / (double) results.size(), 2)).toString()) + newline()); + delta_veh = (sum_avg_veh - sum_veh_star) / (double) results.size(); + } else writer.write(date("null") + newline()); + writer.write(closeRow() + newline()); + + writer.write(closeTable() + newline()); + + writer.write("avg. percentage deviation to best-known result: " + round(delta_res, 2) + newline() + newline()); + writer.write("avg. absolute deviation to best-known vehicles: " + round(delta_veh, 2) + newline()); + + writer.write(openTable() + newline()); + writer.write(openRow() + newline()); + writer.write(date("") + newline()); + writer.write(date("") + newline()); + writer.write(date("") + newline()); + writer.write(date("") + newline()); + writer.write(date(Double.valueOf(average_time).toString(), "align=\"right\"") + newline()); + writer.write(date(Double.valueOf(average_result).toString(), "align=\"right\"") + newline()); + writer.write(date(Double.valueOf(average_vehicles).toString(), "align=\"right\"") + newline()); + if (delta_res != null) { + writer.write(date(Double.valueOf(round(delta_res, 2)).toString(), "align=\"right\"") + newline()); + } else writer.write(date("n.a.") + newline()); + if (delta_veh != null) { + writer.write(date(Double.valueOf(round(delta_veh, 2)).toString(), "align=\"right\"") + newline()); + } else writer.write(date("n.a.") + newline()); + writer.write(closeRow() + newline()); + writer.write(closeTable() + newline()); + + + writer.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + + private String head(String string, int i) { + return ""; + } + + private Double round(Double value, int i) { + if (value == null) return null; + long roundedVal = Math.round(value * Math.pow(10, i)); + return (double) roundedVal / (double) (Math.pow(10, i)); + } + + private String head(String head) { + return ""; + } + + private String closeTable() { + return "
"+date+""+date+"
" + string + "" + head + "
"; + } + + private String openTable() { + return ""; + } + + private String closeRow() { + return ""; + } + + private String date(String date) { + return ""; + } + + private String date(String date, String metaData) { + return ""; + } + + private String newline() { + return "\n"; + } + + private String openRow() { + return ""; + } - } diff --git a/jsprit-core/pom.xml b/jsprit-core/pom.xml index 66a21c57..a9f13f25 100644 --- a/jsprit-core/pom.xml +++ b/jsprit-core/pom.xml @@ -1,4 +1,3 @@ - - - - jsprit - jsprit - 1.6.1-SNAPSHOT - - 4.0.0 - jsprit-core - jsprit-core + + + jsprit + jsprit + 1.6.2-SNAPSHOT + + 4.0.0 + jsprit-core + jsprit-core - - - - - org.eclipse.m2e - lifecycle-mapping - 1.0.0 - - - - - - org.apache.maven.plugins - maven-enforcer-plugin - [1.0.0,) - - enforce - - - - - - - - - - - - - + + + + + org.eclipse.m2e + lifecycle-mapping + 1.0.0 + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + [1.0.0,) + + enforce + + + + + + + + + + + + + + + maven-surefire-plugin + 2.18.1 + + jsprit.core.IntegrationTest + + + + maven-failsafe-plugin + 2.18.1 + + + **/*.java + + jsprit.core.IntegrationTest + + + + + integration-test + verify + + + + + + - - - - org.apache.commons - commons-math - 2.2 - jar - compile - - - - commons-configuration - commons-configuration - 1.9 - jar - compile - - - xerces - xerces - 2.4.0 - compile - - - org.apache.commons - commons-math3 - 3.4 - + + + + org.apache.commons + commons-math + 2.2 + jar + compile + + + + commons-configuration + commons-configuration + 1.9 + jar + compile + + + + xerces + xercesImpl + 2.11.0 + compile + + + + org.apache.commons + commons-math3 + 3.4 + + + + - - - diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/InsertionInitialSolutionFactory.java b/jsprit-core/src/main/java/jsprit/core/algorithm/InsertionInitialSolutionFactory.java index 2e94d01e..9955fcd2 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/InsertionInitialSolutionFactory.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/InsertionInitialSolutionFactory.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ @@ -25,6 +25,7 @@ import jsprit.core.problem.solution.InitialSolutionFactory; import jsprit.core.problem.solution.SolutionCostCalculator; import jsprit.core.problem.solution.VehicleRoutingProblemSolution; import jsprit.core.problem.solution.route.VehicleRoute; +import jsprit.core.problem.vehicle.Vehicle; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -35,32 +36,36 @@ import java.util.List; public final class InsertionInitialSolutionFactory implements InitialSolutionFactory { - private static final Logger logger = LogManager.getLogger(InsertionInitialSolutionFactory.class); + private static final Logger logger = LogManager.getLogger(InsertionInitialSolutionFactory.class); - private final InsertionStrategy insertion; + private final InsertionStrategy insertion; - private SolutionCostCalculator solutionCostsCalculator; + private SolutionCostCalculator solutionCostsCalculator; - public InsertionInitialSolutionFactory(InsertionStrategy insertionStrategy, SolutionCostCalculator solutionCostCalculator) { - super(); - this.insertion = insertionStrategy; - this.solutionCostsCalculator = solutionCostCalculator; - } + public InsertionInitialSolutionFactory(InsertionStrategy insertionStrategy, SolutionCostCalculator solutionCostCalculator) { + super(); + this.insertion = insertionStrategy; + this.solutionCostsCalculator = solutionCostCalculator; + } - @Override - public VehicleRoutingProblemSolution createSolution(final VehicleRoutingProblem vrp) { - logger.info("create initial solution"); - List vehicleRoutes = new ArrayList(); - vehicleRoutes.addAll(vrp.getInitialVehicleRoutes()); - Collection badJobs = insertion.insertJobs(vehicleRoutes, getUnassignedJobs(vrp)); - VehicleRoutingProblemSolution solution = new VehicleRoutingProblemSolution(vehicleRoutes, badJobs, Double.MAX_VALUE); - double costs = solutionCostsCalculator.getCosts(solution); - solution.setCost(costs); - return solution; - } + @Override + public VehicleRoutingProblemSolution createSolution(final VehicleRoutingProblem vrp) { + logger.info("create initial solution"); + List vehicleRoutes = new ArrayList(); + vehicleRoutes.addAll(vrp.getInitialVehicleRoutes()); + Collection badJobs = insertion.insertJobs(vehicleRoutes, getUnassignedJobs(vrp)); + VehicleRoutingProblemSolution solution = new VehicleRoutingProblemSolution(vehicleRoutes, badJobs, Double.MAX_VALUE); + double costs = solutionCostsCalculator.getCosts(solution); + solution.setCost(costs); + return solution; + } - private List getUnassignedJobs(VehicleRoutingProblem vrp) { - return new ArrayList(vrp.getJobs().values()); - } + private List getUnassignedJobs(VehicleRoutingProblem vrp) { + ArrayList jobs = new ArrayList(vrp.getJobs().values()); + for (Vehicle v : vrp.getVehicles()) { + if (v.getBreak() != null) jobs.add(v.getBreak()); + } + return jobs; + } } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/PrettyAlgorithmBuilder.java b/jsprit-core/src/main/java/jsprit/core/algorithm/PrettyAlgorithmBuilder.java index 41b33089..733bb05c 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/PrettyAlgorithmBuilder.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/PrettyAlgorithmBuilder.java @@ -25,6 +25,7 @@ import jsprit.core.algorithm.recreate.VehicleSwitched; import jsprit.core.algorithm.state.*; import jsprit.core.problem.VehicleRoutingProblem; import jsprit.core.problem.constraint.ConstraintManager; +import jsprit.core.problem.constraint.SwitchNotFeasible; import jsprit.core.problem.solution.SolutionCostCalculator; import jsprit.core.problem.solution.VehicleRoutingProblemSolution; import jsprit.core.problem.solution.route.VehicleRoute; @@ -36,8 +37,8 @@ import jsprit.core.util.ActivityTimeTracker; import java.util.*; /** -* Created by schroeder on 10.12.14. -*/ + * Created by schroeder on 10.12.14. + */ public class PrettyAlgorithmBuilder { private final VehicleRoutingProblem vrp; @@ -56,11 +57,11 @@ public class PrettyAlgorithmBuilder { private boolean coreStuff = false; - public static PrettyAlgorithmBuilder newInstance(VehicleRoutingProblem vrp, VehicleFleetManager fleetManager, StateManager stateManager, ConstraintManager constraintManager){ - return new PrettyAlgorithmBuilder(vrp,fleetManager,stateManager,constraintManager); + public static PrettyAlgorithmBuilder newInstance(VehicleRoutingProblem vrp, VehicleFleetManager fleetManager, StateManager stateManager, ConstraintManager constraintManager) { + return new PrettyAlgorithmBuilder(vrp, fleetManager, stateManager, constraintManager); } - PrettyAlgorithmBuilder(VehicleRoutingProblem vrp, VehicleFleetManager fleetManager, StateManager stateManager, ConstraintManager constraintManager){ + PrettyAlgorithmBuilder(VehicleRoutingProblem vrp, VehicleFleetManager fleetManager, StateManager stateManager, ConstraintManager constraintManager) { this.vrp = vrp; this.fleetManager = fleetManager; this.stateManager = stateManager; @@ -68,40 +69,41 @@ public class PrettyAlgorithmBuilder { this.searchStrategyManager = new SearchStrategyManager(); } - public PrettyAlgorithmBuilder setRandom(Random random){ + public PrettyAlgorithmBuilder setRandom(Random random) { searchStrategyManager.setRandom(random); return this; } - public PrettyAlgorithmBuilder withStrategy(SearchStrategy strategy, double weight){ - searchStrategyManager.addStrategy(strategy,weight); + public PrettyAlgorithmBuilder withStrategy(SearchStrategy strategy, double weight) { + searchStrategyManager.addStrategy(strategy, weight); return this; } - public PrettyAlgorithmBuilder constructInitialSolutionWith(InsertionStrategy insertionStrategy, SolutionCostCalculator objFunction){ + public PrettyAlgorithmBuilder constructInitialSolutionWith(InsertionStrategy insertionStrategy, SolutionCostCalculator objFunction) { this.iniInsertionStrategy = insertionStrategy; this.iniObjFunction = objFunction; return this; } - public VehicleRoutingAlgorithm build(){ - if(coreStuff){ + public VehicleRoutingAlgorithm build() { + if (coreStuff) { constraintManager.addTimeWindowConstraint(); constraintManager.addLoadConstraint(); constraintManager.addSkillsConstraint(); + constraintManager.addConstraint(new SwitchNotFeasible(stateManager)); stateManager.updateLoadStates(); stateManager.updateTimeWindowStates(); - UpdateVehicleDependentPracticalTimeWindows tw_updater = new UpdateVehicleDependentPracticalTimeWindows(stateManager, vrp.getTransportCosts()); - tw_updater.setVehiclesToUpdate(new UpdateVehicleDependentPracticalTimeWindows.VehiclesToUpdate() { + UpdateVehicleDependentPracticalTimeWindows twUpdater = new UpdateVehicleDependentPracticalTimeWindows(stateManager, vrp.getTransportCosts()); + twUpdater.setVehiclesToUpdate(new UpdateVehicleDependentPracticalTimeWindows.VehiclesToUpdate() { - Map uniqueTypes = new HashMap(); + Map uniqueTypes = new HashMap(); @Override public Collection get(VehicleRoute vehicleRoute) { - if(uniqueTypes.isEmpty()){ - for( Vehicle v : vrp.getVehicles()){ - if(!uniqueTypes.containsKey(v.getVehicleTypeIdentifier())){ - uniqueTypes.put(v.getVehicleTypeIdentifier(),v); + if (uniqueTypes.isEmpty()) { + for (Vehicle v : vrp.getVehicles()) { + if (!uniqueTypes.containsKey(v.getVehicleTypeIdentifier())) { + uniqueTypes.put(v.getVehicleTypeIdentifier(), v); } } } @@ -109,14 +111,16 @@ public class PrettyAlgorithmBuilder { vehicles.addAll(uniqueTypes.values()); return vehicles; } + }); - stateManager.addStateUpdater(tw_updater); + stateManager.addStateUpdater(twUpdater); stateManager.updateSkillStates(); stateManager.addStateUpdater(new UpdateEndLocationIfRouteIsOpen()); stateManager.addStateUpdater(new UpdateActivityTimes(vrp.getTransportCosts(), ActivityTimeTracker.ActivityPolicy.AS_SOON_AS_TIME_WINDOW_OPENS)); stateManager.addStateUpdater(new UpdateVariableCosts(vrp.getActivityCosts(), vrp.getTransportCosts(), stateManager)); + stateManager.addStateUpdater(new UpdateFutureWaitingTimes(stateManager, vrp.getTransportCosts())); } - VehicleRoutingAlgorithm vra = new VehicleRoutingAlgorithm(vrp,searchStrategyManager); + VehicleRoutingAlgorithm vra = new VehicleRoutingAlgorithm(vrp, searchStrategyManager); vra.addListener(stateManager); RemoveEmptyVehicles removeEmptyVehicles = new RemoveEmptyVehicles(fleetManager); ResetAndIniFleetManager resetAndIniFleetManager = new ResetAndIniFleetManager(fleetManager); @@ -124,7 +128,7 @@ public class PrettyAlgorithmBuilder { vra.addListener(removeEmptyVehicles); vra.addListener(resetAndIniFleetManager); vra.addListener(vehicleSwitched); - if(iniInsertionStrategy != null) { + if (iniInsertionStrategy != null) { if (!iniInsertionStrategy.getListeners().contains(removeEmptyVehicles)) iniInsertionStrategy.addListener(removeEmptyVehicles); if (!iniInsertionStrategy.getListeners().contains(resetAndIniFleetManager)) @@ -136,7 +140,9 @@ public class PrettyAlgorithmBuilder { vra.addListener(new AlgorithmStartsListener() { @Override public void informAlgorithmStarts(VehicleRoutingProblem problem, VehicleRoutingAlgorithm algorithm, Collection solutions) { - solutions.add(new InsertionInitialSolutionFactory(iniInsertionStrategy, iniObjFunction).createSolution(vrp)); + if (solutions.isEmpty()) { + solutions.add(new InsertionInitialSolutionFactory(iniInsertionStrategy, iniObjFunction).createSolution(vrp)); + } } }); } @@ -150,10 +156,10 @@ public class PrettyAlgorithmBuilder { private void searchSchrimpfAndRegister(VehicleRoutingAlgorithm vra) { boolean schrimpfAdded = false; - for(SearchStrategy strategy : vra.getSearchStrategyManager().getStrategies()){ + for (SearchStrategy strategy : vra.getSearchStrategyManager().getStrategies()) { SolutionAcceptor acceptor = strategy.getSolutionAcceptor(); - if(acceptor instanceof SchrimpfAcceptance){ - if(!schrimpfAdded) { + if (acceptor instanceof SchrimpfAcceptance) { + if (!schrimpfAdded) { vra.addListener((SchrimpfAcceptance) acceptor); schrimpfAdded = true; } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/RemoveEmptyVehicles.java b/jsprit-core/src/main/java/jsprit/core/algorithm/RemoveEmptyVehicles.java index e4438455..4f5255a4 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/RemoveEmptyVehicles.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/RemoveEmptyVehicles.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm; @@ -25,28 +25,28 @@ import java.util.Collection; import java.util.List; -public class RemoveEmptyVehicles implements InsertionEndsListener{ +public class RemoveEmptyVehicles implements InsertionEndsListener { - private VehicleFleetManager fleetManager; - - public RemoveEmptyVehicles(VehicleFleetManager fleetManager) { - super(); - this.fleetManager = fleetManager; - } + private VehicleFleetManager fleetManager; - @Override - public String toString() { - return "[name=removeEmptyVehicles]"; - } + public RemoveEmptyVehicles(VehicleFleetManager fleetManager) { + super(); + this.fleetManager = fleetManager; + } - @Override - public void informInsertionEnds(Collection vehicleRoutes) { - List routes = new ArrayList(vehicleRoutes); - for(VehicleRoute route : routes){ - if(route.isEmpty()) { - fleetManager.unlock(route.getVehicle()); - vehicleRoutes.remove(route); - } - } - } + @Override + public String toString() { + return "[name=removeEmptyVehicles]"; + } + + @Override + public void informInsertionEnds(Collection vehicleRoutes) { + List routes = new ArrayList(vehicleRoutes); + for (VehicleRoute route : routes) { + if (route.isEmpty()) { + fleetManager.unlock(route.getVehicle()); + vehicleRoutes.remove(route); + } + } + } } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/ResetAndIniFleetManager.java b/jsprit-core/src/main/java/jsprit/core/algorithm/ResetAndIniFleetManager.java index 4ef1bafa..4ff712a7 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/ResetAndIniFleetManager.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/ResetAndIniFleetManager.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm; @@ -25,26 +25,26 @@ import java.util.ArrayList; import java.util.Collection; -public class ResetAndIniFleetManager implements InsertionStartsListener{ +public class ResetAndIniFleetManager implements InsertionStartsListener { - private VehicleFleetManager vehicleFleetManager; - - public ResetAndIniFleetManager(VehicleFleetManager vehicleFleetManager) { - super(); - this.vehicleFleetManager = vehicleFleetManager; - } + private VehicleFleetManager vehicleFleetManager; - @Override - public void informInsertionStarts(Collection vehicleRoutes, Collection unassignedJobs) { - vehicleFleetManager.unlockAll(); - Collection routes = new ArrayList(vehicleRoutes); - for(VehicleRoute route : routes){ - vehicleFleetManager.lock(route.getVehicle()); - } - } + public ResetAndIniFleetManager(VehicleFleetManager vehicleFleetManager) { + super(); + this.vehicleFleetManager = vehicleFleetManager; + } - @Override - public String toString() { - return "[name=resetAndIniFleetManager]"; - } + @Override + public void informInsertionStarts(Collection vehicleRoutes, Collection unassignedJobs) { + vehicleFleetManager.unlockAll(); + Collection routes = new ArrayList(vehicleRoutes); + for (VehicleRoute route : routes) { + vehicleFleetManager.lock(route.getVehicle()); + } + } + + @Override + public String toString() { + return "[name=resetAndIniFleetManager]"; + } } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/SearchStrategy.java b/jsprit-core/src/main/java/jsprit/core/algorithm/SearchStrategy.java index 711d3724..5f07727f 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/SearchStrategy.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/SearchStrategy.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm; @@ -31,64 +31,66 @@ import java.util.Collections; public class SearchStrategy { - - public static class DiscoveredSolution { - private VehicleRoutingProblemSolution solution; + public static class DiscoveredSolution { - private boolean accepted; + private VehicleRoutingProblemSolution solution; - private String strategyId; - - public DiscoveredSolution(VehicleRoutingProblemSolution solution, boolean accepted, String strategyId) { - super(); - this.solution = solution; - this.accepted = accepted; - this.strategyId = strategyId; - } + private boolean accepted; - public VehicleRoutingProblemSolution getSolution() { - return solution; - } + private String strategyId; - public boolean isAccepted() { - return accepted; - } + public DiscoveredSolution(VehicleRoutingProblemSolution solution, boolean accepted, String strategyId) { + super(); + this.solution = solution; + this.accepted = accepted; + this.strategyId = strategyId; + } - @Deprecated + public VehicleRoutingProblemSolution getSolution() { + return solution; + } + + public boolean isAccepted() { + return accepted; + } + + @Deprecated public String getStrategyName() { - return strategyId; - } + return strategyId; + } - public String getStrategyId() { return strategyId; } + public String getStrategyId() { + return strategyId; + } - @Override - public String toString() { - return "[strategyId="+strategyId+"][solution="+solution+"][accepted="+accepted+"]"; - } - } - - private static Logger logger = LogManager.getLogger(SearchStrategy.class); - - private final Collection searchStrategyModules = new ArrayList(); - - private final SolutionSelector solutionSelector; - - private final SolutionCostCalculator solutionCostCalculator; + @Override + public String toString() { + return "[strategyId=" + strategyId + "][solution=" + solution + "][accepted=" + accepted + "]"; + } + } - private final SolutionAcceptor solutionAcceptor; + private static Logger logger = LogManager.getLogger(SearchStrategy.class); + + private final Collection searchStrategyModules = new ArrayList(); + + private final SolutionSelector solutionSelector; + + private final SolutionCostCalculator solutionCostCalculator; + + private final SolutionAcceptor solutionAcceptor; private final String id; - - private String name; + + private String name; public SearchStrategy(String id, SolutionSelector solutionSelector, SolutionAcceptor solutionAcceptor, SolutionCostCalculator solutionCostCalculator) { - if(id == null) throw new IllegalStateException("strategy id cannot be null"); + if (id == null) throw new IllegalStateException("strategy id cannot be null"); this.solutionSelector = solutionSelector; this.solutionAcceptor = solutionAcceptor; this.solutionCostCalculator = solutionCostCalculator; this.id = id; - logger.debug("initialise " + this); + logger.debug("initialise {}", this); } public String getId() { @@ -96,77 +98,77 @@ public class SearchStrategy { } public String getName() { - return name; - } + return name; + } - public void setName(String name) { - this.name = name; - } + public void setName(String name) { + this.name = name; + } - public Collection getSearchStrategyModules() { - return Collections.unmodifiableCollection(searchStrategyModules); - } - - @SuppressWarnings("UnusedDeclaration") - public SolutionSelector getSolutionSelector() { - return solutionSelector; - } + public Collection getSearchStrategyModules() { + return Collections.unmodifiableCollection(searchStrategyModules); + } @SuppressWarnings("UnusedDeclaration") - public SolutionAcceptor getSolutionAcceptor() { - return solutionAcceptor; - } + public SolutionSelector getSolutionSelector() { + return solutionSelector; + } - @Override - public String toString() { - return "searchStrategy [#modules="+searchStrategyModules.size()+"][selector="+solutionSelector+"][acceptor="+solutionAcceptor+"]"; - } - - /** - * Runs the search-strategy and its according modules, and returns DiscoveredSolution. - * - *

This involves three basic steps: 1) Selecting a solution from solutions (input parameter) according to {@link jsprit.core.algorithm.selector.SolutionSelector}, 2) running the modules - * ({@link jsprit.core.algorithm.SearchStrategyModule}) on the selectedSolution and 3) accepting the new solution according to {@link jsprit.core.algorithm.acceptor.SolutionAcceptor}. - *

Note that after 1) the selected solution is copied, thus the original solution is not modified. - *

Note also that 3) modifies the input parameter solutions by adding, removing, replacing the existing solutions or whatever is defined in the solutionAcceptor. - * - * @param vrp the underlying vehicle routing problem - * @param solutions which will be modified - * @return discoveredSolution + @SuppressWarnings("UnusedDeclaration") + public SolutionAcceptor getSolutionAcceptor() { + return solutionAcceptor; + } + + @Override + public String toString() { + return "searchStrategy [#modules=" + searchStrategyModules.size() + "][selector=" + solutionSelector + "][acceptor=" + solutionAcceptor + "]"; + } + + /** + * Runs the search-strategy and its according modules, and returns DiscoveredSolution. + *

+ *

This involves three basic steps: 1) Selecting a solution from solutions (input parameter) according to {@link jsprit.core.algorithm.selector.SolutionSelector}, 2) running the modules + * ({@link jsprit.core.algorithm.SearchStrategyModule}) on the selectedSolution and 3) accepting the new solution according to {@link jsprit.core.algorithm.acceptor.SolutionAcceptor}. + *

Note that after 1) the selected solution is copied, thus the original solution is not modified. + *

Note also that 3) modifies the input parameter solutions by adding, removing, replacing the existing solutions or whatever is defined in the solutionAcceptor. + * + * @param vrp the underlying vehicle routing problem + * @param solutions which will be modified + * @return discoveredSolution * @throws java.lang.IllegalStateException if selector cannot select any solution */ - @SuppressWarnings("UnusedParameters") - public DiscoveredSolution run(VehicleRoutingProblem vrp, Collection solutions){ - VehicleRoutingProblemSolution solution = solutionSelector.selectSolution(solutions); - if(solution == null) throw new IllegalStateException(getErrMsg()); - VehicleRoutingProblemSolution lastSolution = VehicleRoutingProblemSolution.copyOf(solution); - for(SearchStrategyModule module : searchStrategyModules){ + @SuppressWarnings("UnusedParameters") + public DiscoveredSolution run(VehicleRoutingProblem vrp, Collection solutions) { + VehicleRoutingProblemSolution solution = solutionSelector.selectSolution(solutions); + if (solution == null) throw new IllegalStateException(getErrMsg()); + VehicleRoutingProblemSolution lastSolution = VehicleRoutingProblemSolution.copyOf(solution); + for (SearchStrategyModule module : searchStrategyModules) { lastSolution = module.runAndGetSolution(lastSolution); - } - double costs = solutionCostCalculator.getCosts(lastSolution); - lastSolution.setCost(costs); - boolean solutionAccepted = solutionAcceptor.acceptSolution(solutions, lastSolution); - return new DiscoveredSolution(lastSolution, solutionAccepted, getId()); - } + } + double costs = solutionCostCalculator.getCosts(lastSolution); + lastSolution.setCost(costs); + boolean solutionAccepted = solutionAcceptor.acceptSolution(solutions, lastSolution); + return new DiscoveredSolution(lastSolution, solutionAccepted, getId()); + } private String getErrMsg() { return "solution is null. check solutionSelector to return an appropriate solution. " + - "\nfigure out whether you start with an initial solution. either you set it manually by algorithm.addInitialSolution(...)" - + " or let the algorithm create an initial solution for you. then add the ... xml-snippet to your algorithm's config file."; + "\nfigure out whether you start with an initial solution. either you set it manually by algorithm.addInitialSolution(...)" + + " or let the algorithm create an initial solution for you. then add the ... xml-snippet to your algorithm's config file."; } - public void addModule(SearchStrategyModule module){ - if(module == null) throw new IllegalStateException("module to be added is null."); - searchStrategyModules.add(module); - logger.debug("module added [module=" + module + "][#modules=" + searchStrategyModules.size() + "]"); - } + public void addModule(SearchStrategyModule module) { + if (module == null) throw new IllegalStateException("module to be added is null."); + searchStrategyModules.add(module); + logger.debug("module added [module={}][#modules={}]", module, searchStrategyModules.size()); + } - public void addModuleListener(SearchStrategyModuleListener moduleListener) { - for(SearchStrategyModule module : searchStrategyModules){ - module.addModuleListener(moduleListener); - } - - } + public void addModuleListener(SearchStrategyModuleListener moduleListener) { + for (SearchStrategyModule module : searchStrategyModules) { + module.addModuleListener(moduleListener); + } + + } } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/SearchStrategyManager.java b/jsprit-core/src/main/java/jsprit/core/algorithm/SearchStrategyManager.java index b5ce9935..3feaa696 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/SearchStrategyManager.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/SearchStrategyManager.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm; @@ -27,71 +27,75 @@ import java.util.*; public class SearchStrategyManager { - private final static Logger logger = LogManager.getLogger(); - - private List searchStrategyListeners = new ArrayList(); - - private List strategies = new ArrayList(); - - private List weights = new ArrayList(); + private final static Logger logger = LogManager.getLogger(); - private Map id2index = new HashMap(); - - private Random random = RandomNumberGeneration.getRandom(); - - private double sumWeights = 0; + private List searchStrategyListeners = new ArrayList(); + + private List strategies = new ArrayList(); + + private List weights = new ArrayList(); + + private Map id2index = new HashMap(); + + private Random random = RandomNumberGeneration.getRandom(); + + private double sumWeights = 0; private int strategyIndex = 0; - - public void setRandom(Random random) { - this.random = random; - } - - public List getStrategies() { - return Collections.unmodifiableList(strategies); - } + + public void setRandom(Random random) { + this.random = random; + } + + public List getStrategies() { + return Collections.unmodifiableList(strategies); + } /** * Returns the probabilities. * [schroeder (2014.11.21): Now they are actually no propabilities anymore but weights. The resulting probabilities * are calculated here with the sum of weights] + * * @return list of probabilities */ - @Deprecated - public List getProbabilities() { - return Collections.unmodifiableList(weights); - } + @Deprecated + public List getProbabilities() { + return Collections.unmodifiableList(weights); + } - public List getWeights(){ return Collections.unmodifiableList(weights); } + public List getWeights() { + return Collections.unmodifiableList(weights); + } - public double getWeight(String strategyId){ - return weights.get(id2index.get(strategyId)); - } + public double getWeight(String strategyId) { + return weights.get(id2index.get(strategyId)); + } - /** - * adds a new search strategy with a certain weight. - * @param strategy strategy to be added - * @param weight of corresponding strategy to be added + /** + * adds a new search strategy with a certain weight. + * + * @param strategy strategy to be added + * @param weight of corresponding strategy to be added * @throws java.lang.IllegalStateException if strategy is null OR weight < 0 - */ - public void addStrategy(SearchStrategy strategy, double weight){ - if(strategy == null){ + */ + public void addStrategy(SearchStrategy strategy, double weight) { + if (strategy == null) { throw new IllegalStateException("strategy is null. make sure adding a valid strategy."); } - if(id2index.keySet().contains(strategy.getId())){ + if (id2index.keySet().contains(strategy.getId())) { throw new IllegalStateException("strategyId " + strategy.getId() + " already in use. replace strateId in your config file or code with a unique strategy id"); } - if(weight < 0.0){ - throw new IllegalStateException("weight is lower than zero."); - } - id2index.put(strategy.getId(),strategyIndex); + if (weight < 0.0) { + throw new IllegalStateException("weight is lower than zero."); + } + id2index.put(strategy.getId(), strategyIndex); strategyIndex++; - strategies.add(strategy); - weights.add(weight); - sumWeights += weight; - } + strategies.add(strategy); + weights.add(weight); + sumWeights += weight; + } - public void informStrategyWeightChanged(String strategyId, double weight){ + public void informStrategyWeightChanged(String strategyId, double weight) { int strategyIndex = id2index.get(strategyId); weights.set(strategyIndex, weight); updateSumWeights(); @@ -99,7 +103,7 @@ public class SearchStrategyManager { private void updateSumWeights() { double sum = 0.; - for(double w : weights){ + for (double w : weights) { sum += w; } sumWeights = sum; @@ -111,26 +115,27 @@ public class SearchStrategyManager { * @return selected search strategy * @throws java.lang.IllegalStateException if randomNumberGenerator is null OR no search strategy can be found */ - public SearchStrategy getRandomStrategy() { - if(random == null) throw new IllegalStateException("randomizer is null. make sure you set random object correctly"); - double randomFig = random.nextDouble(); - double sumProbabilities = 0.0; - for (int i = 0; i < weights.size(); i++) { - sumProbabilities += weights.get(i) / sumWeights; - if (randomFig < sumProbabilities) { - return strategies.get(i); - } - } - throw new IllegalStateException("no search-strategy found"); - } - - public void addSearchStrategyListener(SearchStrategyListener strategyListener){ - searchStrategyListeners.add(strategyListener); - } - - public void addSearchStrategyModuleListener(SearchStrategyModuleListener moduleListener){ - for(SearchStrategy s : strategies){ - s.addModuleListener(moduleListener); - } - } + public SearchStrategy getRandomStrategy() { + if (random == null) + throw new IllegalStateException("randomizer is null. make sure you set random object correctly"); + double randomFig = random.nextDouble(); + double sumProbabilities = 0.0; + for (int i = 0; i < weights.size(); i++) { + sumProbabilities += weights.get(i) / sumWeights; + if (randomFig < sumProbabilities) { + return strategies.get(i); + } + } + throw new IllegalStateException("no search-strategy found"); + } + + public void addSearchStrategyListener(SearchStrategyListener strategyListener) { + searchStrategyListeners.add(strategyListener); + } + + public void addSearchStrategyModuleListener(SearchStrategyModuleListener moduleListener) { + for (SearchStrategy s : strategies) { + s.addModuleListener(moduleListener); + } + } } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/SearchStrategyModule.java b/jsprit-core/src/main/java/jsprit/core/algorithm/SearchStrategyModule.java index 6551b11b..c847a31d 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/SearchStrategyModule.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/SearchStrategyModule.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm; @@ -21,11 +21,11 @@ import jsprit.core.problem.solution.VehicleRoutingProblemSolution; public interface SearchStrategyModule { - - public VehicleRoutingProblemSolution runAndGetSolution(VehicleRoutingProblemSolution vrpSolution); - - public String getName(); - public void addModuleListener(SearchStrategyModuleListener moduleListener); + public VehicleRoutingProblemSolution runAndGetSolution(VehicleRoutingProblemSolution vrpSolution); + + public String getName(); + + public void addModuleListener(SearchStrategyModuleListener moduleListener); } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/VariablePlusFixedSolutionCostCalculatorFactory.java b/jsprit-core/src/main/java/jsprit/core/algorithm/VariablePlusFixedSolutionCostCalculatorFactory.java index 5e02b6f0..d4b6d979 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/VariablePlusFixedSolutionCostCalculatorFactory.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/VariablePlusFixedSolutionCostCalculatorFactory.java @@ -1,18 +1,18 @@ /******************************************************************************* * Copyright (c) 2014 Stefan Schroeder. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . - * + * * Contributors: * Stefan Schroeder - initial API and implementation ******************************************************************************/ @@ -29,39 +29,38 @@ import jsprit.core.problem.vehicle.Vehicle; * Default objective function which is the sum of all fixed vehicle and variable * transportation costs, i.e. each is generated solution is evaluated according * this objective function. - * - * @author schroeder * + * @author schroeder */ public class VariablePlusFixedSolutionCostCalculatorFactory { - - private RouteAndActivityStateGetter stateManager; - - public VariablePlusFixedSolutionCostCalculatorFactory(RouteAndActivityStateGetter stateManager) { - super(); - this.stateManager = stateManager; - } - public SolutionCostCalculator createCalculator(){ - return new SolutionCostCalculator() { + private RouteAndActivityStateGetter stateManager; - @Override - public double getCosts(VehicleRoutingProblemSolution solution) { - double c = 0.0; - for(VehicleRoute r : solution.getRoutes()){ - c += stateManager.getRouteState(r, InternalStates.COSTS, Double.class); - c += getFixedCosts(r.getVehicle()); - } + public VariablePlusFixedSolutionCostCalculatorFactory(RouteAndActivityStateGetter stateManager) { + super(); + this.stateManager = stateManager; + } + + public SolutionCostCalculator createCalculator() { + return new SolutionCostCalculator() { + + @Override + public double getCosts(VehicleRoutingProblemSolution solution) { + double c = 0.0; + for (VehicleRoute r : solution.getRoutes()) { + c += stateManager.getRouteState(r, InternalStates.COSTS, Double.class); + c += getFixedCosts(r.getVehicle()); + } c += solution.getUnassignedJobs().size() * c * .1; - return c; - } + return c; + } private double getFixedCosts(Vehicle vehicle) { - if(vehicle == null) return 0.0; - if(vehicle.getType() == null) return 0.0; + if (vehicle == null) return 0.0; + if (vehicle.getType() == null) return 0.0; return vehicle.getType().getVehicleCostParams().fix; } - }; - } + }; + } } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/VehicleRoutingAlgorithm.java b/jsprit-core/src/main/java/jsprit/core/algorithm/VehicleRoutingAlgorithm.java index df46b466..466ff4e6 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/VehicleRoutingAlgorithm.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/VehicleRoutingAlgorithm.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm; @@ -20,6 +20,7 @@ import jsprit.core.algorithm.SearchStrategy.DiscoveredSolution; import jsprit.core.algorithm.listener.*; import jsprit.core.algorithm.termination.PrematureAlgorithmTermination; import jsprit.core.problem.VehicleRoutingProblem; +import jsprit.core.problem.job.Job; import jsprit.core.problem.solution.VehicleRoutingProblemSolution; import jsprit.core.problem.solution.route.VehicleRoute; import jsprit.core.problem.solution.route.activity.TourActivity; @@ -33,9 +34,8 @@ import java.util.Collection; /** * Algorithm that solves a {@link VehicleRoutingProblem}. - * - * @author stefan schroeder * + * @author stefan schroeder */ public class VehicleRoutingAlgorithm { @@ -43,14 +43,14 @@ public class VehicleRoutingAlgorithm { private Collection terminationCriteria = new ArrayList(); - void addTermination(PrematureAlgorithmTermination termination){ + void addTermination(PrematureAlgorithmTermination termination) { terminationCriteria.add(termination); } @Override public boolean isPrematureBreak(DiscoveredSolution discoveredSolution) { - for(PrematureAlgorithmTermination termination : terminationCriteria){ - if(termination.isPrematureBreak(discoveredSolution)){ + for (PrematureAlgorithmTermination termination : terminationCriteria) { + if (termination.isPrematureBreak(discoveredSolution)) { return true; } } @@ -59,31 +59,31 @@ public class VehicleRoutingAlgorithm { } private static class Counter { - private final String name; - private long counter = 0; - private long nextCounter = 1; - private static final Logger log = LogManager.getLogger(Counter.class); + private final String name; + private long counter = 0; + private long nextCounter = 1; + private static final Logger log = LogManager.getLogger(Counter.class); - public Counter(final String name) { - this.name = name; - } + public Counter(final String name) { + this.name = name; + } - public void incCounter() { - long i = counter++; - long n = nextCounter; - if (i >= n) { - nextCounter=n*2; + public void incCounter() { + long i = counter++; + long n = nextCounter; + if (i >= n) { + nextCounter = n * 2; log.info(this.name + n); - } - } + } + } - public void reset() { - counter=0; - nextCounter=1; - } - } + public void reset() { + counter = 0; + nextCounter = 1; + } + } - private final static Logger logger = LogManager.getLogger(); + private final static Logger logger = LogManager.getLogger(); private final Counter counter = new Counter("iterations "); @@ -100,63 +100,63 @@ public class VehicleRoutingAlgorithm { private TerminationManager terminationManager = new TerminationManager(); private VehicleRoutingProblemSolution bestEver = null; - - public VehicleRoutingAlgorithm(VehicleRoutingProblem problem, SearchStrategyManager searchStrategyManager) { - super(); - this.problem = problem; - this.searchStrategyManager = searchStrategyManager; - initialSolutions = new ArrayList(); - } - public VehicleRoutingAlgorithm(VehicleRoutingProblem problem, Collection initialSolutions, SearchStrategyManager searchStrategyManager) { - super(); - this.problem = problem; - this.searchStrategyManager = searchStrategyManager; - this.initialSolutions = initialSolutions; - } + public VehicleRoutingAlgorithm(VehicleRoutingProblem problem, SearchStrategyManager searchStrategyManager) { + super(); + this.problem = problem; + this.searchStrategyManager = searchStrategyManager; + initialSolutions = new ArrayList(); + } - /** - * Adds solution to the collection of initial solutions. - * - * @param solution the solution to be added - */ - public void addInitialSolution(VehicleRoutingProblemSolution solution){ + public VehicleRoutingAlgorithm(VehicleRoutingProblem problem, Collection initialSolutions, SearchStrategyManager searchStrategyManager) { + super(); + this.problem = problem; + this.searchStrategyManager = searchStrategyManager; + this.initialSolutions = initialSolutions; + } + + /** + * Adds solution to the collection of initial solutions. + * + * @param solution the solution to be added + */ + public void addInitialSolution(VehicleRoutingProblemSolution solution) { verify(solution); initialSolutions.add(solution); - } + } - private void verify(VehicleRoutingProblemSolution solution) { + private void verify(VehicleRoutingProblemSolution solution) { int nuJobs = 0; - for(VehicleRoute route : solution.getRoutes()){ + for (VehicleRoute route : solution.getRoutes()) { nuJobs += route.getTourActivities().getJobs().size(); - if(route.getVehicle().getIndex() == 0) + if (route.getVehicle().getIndex() == 0) throw new IllegalStateException("vehicle used in initial solution has no index. probably a vehicle is used that has not been added to the " + - " the VehicleRoutingProblem. only use vehicles that have already been added to the problem."); - for(TourActivity act : route.getActivities()) { + " the VehicleRoutingProblem. only use vehicles that have already been added to the problem."); + for (TourActivity act : route.getActivities()) { if (act.getIndex() == 0) { throw new IllegalStateException("act in initial solution has no index. activities are created and associated to their job in VehicleRoutingProblem\n." + - " thus if you build vehicle-routes use the jobActivityFactory from vehicle routing problem like that \n" + - " VehicleRoute.Builder.newInstance(knownVehicle).setJobActivityFactory(vrp.getJobActivityFactory).addService(..)....build() \n" + - " then the activities that are created to build the route are identical to the ones used in VehicleRoutingProblem"); + " thus if you build vehicle-routes use the jobActivityFactory from vehicle routing problem like that \n" + + " VehicleRoute.Builder.newInstance(knownVehicle).setJobActivityFactory(vrp.getJobActivityFactory).addService(..)....build() \n" + + " then the activities that are created to build the route are identical to the ones used in VehicleRoutingProblem"); } } } - if(nuJobs != problem.getJobs().values().size()){ - logger.warn("number of jobs in initial solution (" + nuJobs + ") is not equal nuJobs in vehicle routing problem (" + problem.getJobs().values().size() + ")" + - "\n this might yield unintended effects, e.g. initial solution cannot be improved anymore."); + if (nuJobs != problem.getJobs().values().size()) { + logger.warn("number of jobs in initial solution ({}) is not equal nuJobs in vehicle routing problem ({})" + + "\n this might yield unintended effects, e.g. initial solution cannot be improved anymore.", nuJobs, problem.getJobs().values().size()); } } /** - * Sets premature termination and overrides existing termination criteria. If existing ones should not be + * Sets premature termination and overrides existing termination criteria. If existing ones should not be * overridden use .addTerminationCriterion(...). - * - * @param prematureAlgorithmTermination the termination criterion - */ - public void setPrematureAlgorithmTermination(PrematureAlgorithmTermination prematureAlgorithmTermination){ - terminationManager = new TerminationManager(); + * + * @param prematureAlgorithmTermination the termination criterion + */ + public void setPrematureAlgorithmTermination(PrematureAlgorithmTermination prematureAlgorithmTermination) { + terminationManager = new TerminationManager(); terminationManager.addTermination(prematureAlgorithmTermination); - } + } /** * Adds a termination criterion to the collection of already specified termination criteria. If one @@ -164,101 +164,137 @@ public class VehicleRoutingAlgorithm { * * @param terminationCriterion the termination criterion */ - public void addTerminationCriterion(PrematureAlgorithmTermination terminationCriterion){ + public void addTerminationCriterion(PrematureAlgorithmTermination terminationCriterion) { terminationManager.addTermination(terminationCriterion); } - /** - * Gets the {@link SearchStrategyManager}. - * - * @return SearchStrategyManager - */ - public SearchStrategyManager getSearchStrategyManager() { - return searchStrategyManager; - } - - /** - * Runs the vehicle routing algorithm and returns a number of generated solutions. - * - *

The algorithm runs as long as it is specified in nuOfIterations and prematureBreak. In each iteration it selects a searchStrategy according - * to searchStrategyManager and runs the strategy to improve solutions. - *

Note that clients are allowed to observe/listen the algorithm. See {@link VehicleRoutingAlgorithmListener} and its according listeners. - * - * @return Collection the solutions - * @see {@link SearchStrategyManager}, {@link VehicleRoutingAlgorithmListener}, {@link AlgorithmStartsListener}, {@link AlgorithmEndsListener}, {@link IterationStartsListener}, {@link IterationEndsListener} - */ - public Collection searchSolutions(){ - logger.info("algorithm starts: " + "[maxIterations=" + maxIterations + "]"); - double now = System.currentTimeMillis(); - int noIterationsThisAlgoIsRunning = maxIterations; - counter.reset(); - Collection solutions = new ArrayList(initialSolutions); - algorithmStarts(problem,solutions); - bestEver = Solutions.bestOf(solutions); - logger.info("iterations start"); - for(int i=0;i< maxIterations;i++){ - iterationStarts(i+1,problem,solutions); - logger.debug("start iteration: " + i); - counter.incCounter(); - SearchStrategy strategy = searchStrategyManager.getRandomStrategy(); - DiscoveredSolution discoveredSolution = strategy.run(problem, solutions); - logger.trace("discovered solution: " + discoveredSolution); - memorizeIfBestEver(discoveredSolution); - selectedStrategy(discoveredSolution,problem,solutions); - if(terminationManager.isPrematureBreak(discoveredSolution)){ - logger.info("premature algorithm termination at iteration "+ (i+1)); - noIterationsThisAlgoIsRunning = (i+1); - break; - } - iterationEnds(i+1,problem,solutions); - } - logger.info("iterations end at " + noIterationsThisAlgoIsRunning + " iterations"); - addBestEver(solutions); - algorithmEnds(problem, solutions); - logger.info("took " + ((System.currentTimeMillis()-now)/1000.0) + " seconds"); - return solutions; - } - - private void addBestEver(Collection solutions) { - if(bestEver != null) solutions.add(bestEver); + /** + * Gets the {@link SearchStrategyManager}. + * + * @return SearchStrategyManager + */ + public SearchStrategyManager getSearchStrategyManager() { + return searchStrategyManager; } + /** + * Runs the vehicle routing algorithm and returns a number of generated solutions. + *

+ *

The algorithm runs as long as it is specified in nuOfIterations and prematureBreak. In each iteration it selects a searchStrategy according + * to searchStrategyManager and runs the strategy to improve solutions. + *

Note that clients are allowed to observe/listen the algorithm. See {@link VehicleRoutingAlgorithmListener} and its according listeners. + * + * @return Collection the solutions + * @see {@link SearchStrategyManager}, {@link VehicleRoutingAlgorithmListener}, {@link AlgorithmStartsListener}, {@link AlgorithmEndsListener}, {@link IterationStartsListener}, {@link IterationEndsListener} + */ + public Collection searchSolutions() { + logger.info("algorithm starts: [maxIterations={}]", maxIterations); + double now = System.currentTimeMillis(); + int noIterationsThisAlgoIsRunning = maxIterations; + counter.reset(); + Collection solutions = new ArrayList(initialSolutions); + algorithmStarts(problem, solutions); + bestEver = Solutions.bestOf(solutions); + if (logger.isTraceEnabled()) log(solutions); + logger.info("iterations start"); + for (int i = 0; i < maxIterations; i++) { + iterationStarts(i + 1, problem, solutions); + logger.debug("start iteration: {}", i); + counter.incCounter(); + SearchStrategy strategy = searchStrategyManager.getRandomStrategy(); + DiscoveredSolution discoveredSolution = strategy.run(problem, solutions); + if (logger.isTraceEnabled()) log(discoveredSolution); + memorizeIfBestEver(discoveredSolution); + selectedStrategy(discoveredSolution, problem, solutions); + if (terminationManager.isPrematureBreak(discoveredSolution)) { + logger.info("premature algorithm termination at iteration {}", (i + 1)); + noIterationsThisAlgoIsRunning = (i + 1); + break; + } + iterationEnds(i + 1, problem, solutions); + } + logger.info("iterations end at {} iterations", noIterationsThisAlgoIsRunning); + addBestEver(solutions); + algorithmEnds(problem, solutions); + logger.info("took {} seconds", ((System.currentTimeMillis() - now) / 1000.0)); + return solutions; + } + + private void addBestEver(Collection solutions) { + if (bestEver != null) solutions.add(bestEver); + } + + private void log(Collection solutions) { + for (VehicleRoutingProblemSolution sol : solutions) log(sol); + } + + private void log(VehicleRoutingProblemSolution solution) { + logger.trace("solution costs: {}", solution.getCost()); + for (VehicleRoute r : solution.getRoutes()) { + StringBuilder b = new StringBuilder(); + b.append(r.getVehicle().getId()).append(" : ").append("[ "); + for (TourActivity act : r.getActivities()) { + if (act instanceof TourActivity.JobActivity) { + b.append(((TourActivity.JobActivity) act).getJob().getId()).append(" "); + } + } + b.append("]"); + logger.trace(b.toString()); + } + StringBuilder b = new StringBuilder(); + b.append("unassigned : [ "); + for (Job j : solution.getUnassignedJobs()) { + b.append(j.getId()).append(" "); + } + b.append("]"); + logger.trace(b.toString()); + } + + private void log(DiscoveredSolution discoveredSolution) { + logger.trace("discovered solution: {}", discoveredSolution); + log(discoveredSolution.getSolution()); + } + + private void memorizeIfBestEver(DiscoveredSolution discoveredSolution) { - if(discoveredSolution == null) return; - if(bestEver == null) bestEver = discoveredSolution.getSolution(); - else if(discoveredSolution.getSolution().getCost() < bestEver.getCost()) bestEver = discoveredSolution.getSolution(); + if (discoveredSolution == null) return; + if (bestEver == null) bestEver = discoveredSolution.getSolution(); + else if (discoveredSolution.getSolution().getCost() < bestEver.getCost()) + bestEver = discoveredSolution.getSolution(); } private void selectedStrategy(DiscoveredSolution discoveredSolution, VehicleRoutingProblem problem, Collection solutions) { - algoListeners.selectedStrategy(discoveredSolution,problem,solutions); - } + algoListeners.selectedStrategy(discoveredSolution, problem, solutions); + } - private void algorithmEnds(VehicleRoutingProblem problem, Collection solutions) { - algoListeners.algorithmEnds(problem, solutions); - } + private void algorithmEnds(VehicleRoutingProblem problem, Collection solutions) { + algoListeners.algorithmEnds(problem, solutions); + } - public VehicleRoutingAlgorithmListeners getAlgorithmListeners() { - return algoListeners; - } - - public void addListener(VehicleRoutingAlgorithmListener l){ - algoListeners.addListener(l); - if(l instanceof SearchStrategyListener) searchStrategyManager.addSearchStrategyListener((SearchStrategyListener) l); - if(l instanceof SearchStrategyModuleListener) searchStrategyManager.addSearchStrategyModuleListener((SearchStrategyModuleListener) l); - } + public VehicleRoutingAlgorithmListeners getAlgorithmListeners() { + return algoListeners; + } - private void iterationEnds(int i, VehicleRoutingProblem problem, Collection solutions) { - algoListeners.iterationEnds(i,problem, solutions); - } + public void addListener(VehicleRoutingAlgorithmListener l) { + algoListeners.addListener(l); + if (l instanceof SearchStrategyListener) + searchStrategyManager.addSearchStrategyListener((SearchStrategyListener) l); + if (l instanceof SearchStrategyModuleListener) + searchStrategyManager.addSearchStrategyModuleListener((SearchStrategyModuleListener) l); + } - private void iterationStarts(int i, VehicleRoutingProblem problem, Collection solutions) { - algoListeners.iterationStarts(i, problem, solutions); - } + private void iterationEnds(int i, VehicleRoutingProblem problem, Collection solutions) { + algoListeners.iterationEnds(i, problem, solutions); + } - private void algorithmStarts(VehicleRoutingProblem problem, Collection solutions) { - algoListeners.algorithmStarts(problem, this, solutions); - } + private void iterationStarts(int i, VehicleRoutingProblem problem, Collection solutions) { + algoListeners.iterationStarts(i, problem, solutions); + } + + private void algorithmStarts(VehicleRoutingProblem problem, Collection solutions) { + algoListeners.algorithmStarts(problem, this, solutions); + } /** * Sets max number of iterations. @@ -267,7 +303,7 @@ public class VehicleRoutingAlgorithm { */ public void setMaxIterations(int maxIterations) { this.maxIterations = maxIterations; - logger.debug("set maxIterations to " + this.maxIterations); + logger.debug("set maxIterations to {}", this.maxIterations); } /** diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/VehicleRoutingAlgorithmBuilder.java b/jsprit-core/src/main/java/jsprit/core/algorithm/VehicleRoutingAlgorithmBuilder.java index 9b60d5ec..75c54357 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/VehicleRoutingAlgorithmBuilder.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/VehicleRoutingAlgorithmBuilder.java @@ -27,153 +27,151 @@ import jsprit.core.problem.solution.SolutionCostCalculator; /** * Builder that builds a {@link VehicleRoutingAlgorithm}. - * - * @author schroeder * + * @author schroeder */ public class VehicleRoutingAlgorithmBuilder { - private String algorithmConfigFile; - - private AlgorithmConfig algorithmConfig; - - private final VehicleRoutingProblem vrp; + private String algorithmConfigFile; - private SolutionCostCalculator solutionCostCalculator; + private AlgorithmConfig algorithmConfig; - private StateManager stateManager; - - private boolean addCoreConstraints = false; - - private boolean addDefaultCostCalculators = false; + private final VehicleRoutingProblem vrp; - private ConstraintManager constraintManager; + private SolutionCostCalculator solutionCostCalculator; - private int nuOfThreads=0; - - /** - * Constructs the builder with the problem and an algorithmConfigFile. Latter is to configure and specify the ruin-and-recreate meta-heuristic. - * - * @param problem to solve - * @param algorithmConfig config file of VehicleRoutingAlgorithm - */ - public VehicleRoutingAlgorithmBuilder(VehicleRoutingProblem problem, String algorithmConfig) { - this.vrp=problem; - this.algorithmConfigFile=algorithmConfig; - this.algorithmConfig=null; - } - - /** - * Constructs the builder with the problem and an algorithmConfig. Latter is to configure and specify the ruin-and-recreate meta-heuristic. - * - * @param problem to solve + private StateManager stateManager; + + private boolean addCoreConstraints = false; + + private boolean addDefaultCostCalculators = false; + + private ConstraintManager constraintManager; + + private int nuOfThreads = 0; + + /** + * Constructs the builder with the problem and an algorithmConfigFile. Latter is to configure and specify the ruin-and-recreate meta-heuristic. + * + * @param problem to solve * @param algorithmConfig config file of VehicleRoutingAlgorithm - */ - public VehicleRoutingAlgorithmBuilder(VehicleRoutingProblem problem, AlgorithmConfig algorithmConfig) { - this.vrp=problem; - this.algorithmConfigFile=null; - this.algorithmConfig=algorithmConfig; - } + */ + public VehicleRoutingAlgorithmBuilder(VehicleRoutingProblem problem, String algorithmConfig) { + this.vrp = problem; + this.algorithmConfigFile = algorithmConfig; + this.algorithmConfig = null; + } - /** - * Sets custom objective function. - * - *

If objective function is not set, a default function is applied (which basically minimizes - * fixed and variable transportation costs ({@link VariablePlusFixedSolutionCostCalculatorFactory}). - * - * @param objectiveFunction to be minimized - * @see VariablePlusFixedSolutionCostCalculatorFactory - */ - public void setObjectiveFunction(SolutionCostCalculator objectiveFunction) { - this.solutionCostCalculator = objectiveFunction; - } + /** + * Constructs the builder with the problem and an algorithmConfig. Latter is to configure and specify the ruin-and-recreate meta-heuristic. + * + * @param problem to solve + * @param algorithmConfig config file of VehicleRoutingAlgorithm + */ + public VehicleRoutingAlgorithmBuilder(VehicleRoutingProblem problem, AlgorithmConfig algorithmConfig) { + this.vrp = problem; + this.algorithmConfigFile = null; + this.algorithmConfig = algorithmConfig; + } - /** - * Sets stateManager to memorize states. - * - * @param stateManager that memorizes your states - * @see StateManager - */ - public void setStateManager(StateManager stateManager) { - this.stateManager=stateManager; - } + /** + * Sets custom objective function. + *

+ *

If objective function is not set, a default function is applied (which basically minimizes + * fixed and variable transportation costs ({@link VariablePlusFixedSolutionCostCalculatorFactory}). + * + * @param objectiveFunction to be minimized + * @see VariablePlusFixedSolutionCostCalculatorFactory + */ + public void setObjectiveFunction(SolutionCostCalculator objectiveFunction) { + this.solutionCostCalculator = objectiveFunction; + } - /** - * Adds core constraints. - * - *

Thus, it adds vehicle-capacity, time-window and skills constraints and their - * required stateUpdater. - * - */ - public void addCoreConstraints() { - addCoreConstraints=true; - } + /** + * Sets stateManager to memorize states. + * + * @param stateManager that memorizes your states + * @see StateManager + */ + public void setStateManager(StateManager stateManager) { + this.stateManager = stateManager; + } - /** - * Adds default cost calculators used by the insertion heuristic, - * to calculate activity insertion costs. - * By default, marginal transportation costs are calculated. Thus when inserting - * act_k between act_i and act_j, marginal (additional) transportation costs - * are basically c(act_i,act_k)+c(act_k,act_j)-c(act_i,act_j). - * - *

Do not use this method, if you plan to control the insertion heuristic - * entirely via hard- and soft-constraints. - */ - public void addDefaultCostCalculators() { - addDefaultCostCalculators=true; - } + /** + * Adds core constraints. + *

+ *

Thus, it adds vehicle-capacity, time-window and skills constraints and their + * required stateUpdater. + */ + public void addCoreConstraints() { + addCoreConstraints = true; + } - /** - * Sets state- and constraintManager. - * - * @param stateManager that memorizes your states - * @param constraintManager that manages your constraints - * @see StateManager - * @see ConstraintManager - */ - public void setStateAndConstraintManager(StateManager stateManager, ConstraintManager constraintManager) { - this.stateManager=stateManager; - this.constraintManager=constraintManager; - } - - /** - * Sets nuOfThreads. - * - * @param nuOfThreads to be operated - */ - public void setNuOfThreads(int nuOfThreads){ - this.nuOfThreads=nuOfThreads; - } + /** + * Adds default cost calculators used by the insertion heuristic, + * to calculate activity insertion costs. + * By default, marginal transportation costs are calculated. Thus when inserting + * act_k between act_i and act_j, marginal (additional) transportation costs + * are basically c(act_i,act_k)+c(act_k,act_j)-c(act_i,act_j). + *

+ *

Do not use this method, if you plan to control the insertion heuristic + * entirely via hard- and soft-constraints. + */ + public void addDefaultCostCalculators() { + addDefaultCostCalculators = true; + } - /** - * Builds and returns the algorithm. - * - *

If algorithmConfigFile is set, it reads the configuration. - * - * @return the algorithm - */ - public VehicleRoutingAlgorithm build() { - if(stateManager == null) stateManager = new StateManager(vrp); - if(constraintManager == null) constraintManager = new ConstraintManager(vrp,stateManager); - //add core updater - stateManager.addStateUpdater(new UpdateEndLocationIfRouteIsOpen()); + /** + * Sets state- and constraintManager. + * + * @param stateManager that memorizes your states + * @param constraintManager that manages your constraints + * @see StateManager + * @see ConstraintManager + */ + public void setStateAndConstraintManager(StateManager stateManager, ConstraintManager constraintManager) { + this.stateManager = stateManager; + this.constraintManager = constraintManager; + } + + /** + * Sets nuOfThreads. + * + * @param nuOfThreads to be operated + */ + public void setNuOfThreads(int nuOfThreads) { + this.nuOfThreads = nuOfThreads; + } + + /** + * Builds and returns the algorithm. + *

+ *

If algorithmConfigFile is set, it reads the configuration. + * + * @return the algorithm + */ + public VehicleRoutingAlgorithm build() { + if (stateManager == null) stateManager = new StateManager(vrp); + if (constraintManager == null) constraintManager = new ConstraintManager(vrp, stateManager); + //add core updater + stateManager.addStateUpdater(new UpdateEndLocationIfRouteIsOpen()); // stateManager.addStateUpdater(new OpenRouteStateVerifier()); - if(addCoreConstraints){ - constraintManager.addLoadConstraint(); - constraintManager.addTimeWindowConstraint(); - constraintManager.addSkillsConstraint(); + if (addCoreConstraints) { + constraintManager.addLoadConstraint(); + constraintManager.addTimeWindowConstraint(); + constraintManager.addSkillsConstraint(); stateManager.updateLoadStates(); - stateManager.updateTimeWindowStates(); + stateManager.updateTimeWindowStates(); stateManager.updateSkillStates(); - } - if(algorithmConfig==null){ - algorithmConfig = new AlgorithmConfig(); - AlgorithmConfigXmlReader xmlReader = new AlgorithmConfigXmlReader(algorithmConfig); - xmlReader.read(algorithmConfigFile); - } - return VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, algorithmConfig, nuOfThreads, solutionCostCalculator, stateManager, constraintManager, addDefaultCostCalculators); - } + } + if (algorithmConfig == null) { + algorithmConfig = new AlgorithmConfig(); + AlgorithmConfigXmlReader xmlReader = new AlgorithmConfigXmlReader(algorithmConfig); + xmlReader.read(algorithmConfigFile); + } + return VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, algorithmConfig, nuOfThreads, solutionCostCalculator, stateManager, constraintManager, addDefaultCostCalculators); + } + - } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/VehicleRoutingAlgorithmFactory.java b/jsprit-core/src/main/java/jsprit/core/algorithm/VehicleRoutingAlgorithmFactory.java index 40749bdb..286bf0e2 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/VehicleRoutingAlgorithmFactory.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/VehicleRoutingAlgorithmFactory.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm; @@ -20,7 +20,7 @@ import jsprit.core.problem.VehicleRoutingProblem; public interface VehicleRoutingAlgorithmFactory { - - public VehicleRoutingAlgorithm createAlgorithm(VehicleRoutingProblem vrp); + + public VehicleRoutingAlgorithm createAlgorithm(VehicleRoutingProblem vrp); } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/acceptor/AcceptNewRemoveFirst.java b/jsprit-core/src/main/java/jsprit/core/algorithm/acceptor/AcceptNewRemoveFirst.java index c14762e3..41421e3a 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/acceptor/AcceptNewRemoveFirst.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/acceptor/AcceptNewRemoveFirst.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.acceptor; @@ -24,35 +24,33 @@ import java.util.Collection; * @deprecated use GreedyAcceptance instead */ @Deprecated -public class AcceptNewRemoveFirst implements SolutionAcceptor{ +public class AcceptNewRemoveFirst implements SolutionAcceptor { - private final int solutionMemory; - - public AcceptNewRemoveFirst(int solutionMemory){ - this.solutionMemory = solutionMemory; - } - - /** - * Accepts every solution if solution memory allows. If memory occupied, than accepts new solution only if better than the worst in memory. - * Consequently, the worst solution is removed from solutions, and the new solution added. - * - *

Note that this modifies Collection solutions. - */ - @Override - public boolean acceptSolution(Collection solutions, VehicleRoutingProblemSolution newSolution) { - if (solutions.size() >= solutionMemory) { - solutions.remove(solutions.iterator().next()); - } - solutions.add(newSolution); - return true; - } - - @Override - public String toString() { - return "[name=acceptNewRemoveFirst]"; - } - + private final int solutionMemory; + public AcceptNewRemoveFirst(int solutionMemory) { + this.solutionMemory = solutionMemory; + } + + /** + * Accepts every solution if solution memory allows. If memory occupied, than accepts new solution only if better than the worst in memory. + * Consequently, the worst solution is removed from solutions, and the new solution added. + *

+ *

Note that this modifies Collection solutions. + */ + @Override + public boolean acceptSolution(Collection solutions, VehicleRoutingProblemSolution newSolution) { + if (solutions.size() >= solutionMemory) { + solutions.remove(solutions.iterator().next()); + } + solutions.add(newSolution); + return true; + } + + @Override + public String toString() { + return "[name=acceptNewRemoveFirst]"; + } } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/acceptor/ExperimentalSchrimpfAcceptance.java b/jsprit-core/src/main/java/jsprit/core/algorithm/acceptor/ExperimentalSchrimpfAcceptance.java index 64c5818a..de49605e 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/acceptor/ExperimentalSchrimpfAcceptance.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/acceptor/ExperimentalSchrimpfAcceptance.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.acceptor; @@ -35,122 +35,120 @@ import java.net.URL; import java.util.Collection; -public class ExperimentalSchrimpfAcceptance implements SolutionAcceptor, IterationStartsListener, AlgorithmStartsListener{ +public class ExperimentalSchrimpfAcceptance implements SolutionAcceptor, IterationStartsListener, AlgorithmStartsListener { - final static Logger logger = LogManager.getLogger(ExperimentalSchrimpfAcceptance.class.getName()); - - private final double alpha; - - private int nOfTotalIterations = 1000; - - private int currentIteration = 0; - - private double initialThreshold = 0.0; + final static Logger logger = LogManager.getLogger(ExperimentalSchrimpfAcceptance.class.getName()); - private final int nOfRandomWalks; - - private final int solutionMemory; - - - public ExperimentalSchrimpfAcceptance(int solutionMemory, double alpha, int nOfWarmupIterations) { - super(); - this.alpha = alpha; - this.nOfRandomWalks = nOfWarmupIterations; - this.solutionMemory = solutionMemory; - logger.info("initialise " + this); - } - + private final double alpha; + + private int nOfTotalIterations = 1000; + + private int currentIteration = 0; + + private double initialThreshold = 0.0; + + private final int nOfRandomWalks; + + private final int solutionMemory; - @Override - public boolean acceptSolution(Collection solutions, VehicleRoutingProblemSolution newSolution) { - boolean solutionAccepted = false; - if (solutions.size() < solutionMemory) { - solutions.add(newSolution); - solutionAccepted = true; - } else { - VehicleRoutingProblemSolution worst = null; - double threshold = getThreshold(currentIteration); - for(VehicleRoutingProblemSolution solutionInMemory : solutions){ - if(worst == null) worst = solutionInMemory; - else if(solutionInMemory.getCost() > worst.getCost()) worst = solutionInMemory; - } - if(newSolution.getRoutes().size() < worst.getRoutes().size()){ - solutions.remove(worst); - solutions.add(newSolution); - solutionAccepted = true; - } - else if(newSolution.getRoutes().size() == worst.getRoutes().size() && newSolution.getCost() < worst.getCost() + threshold){ - solutions.remove(worst); - solutions.add(newSolution); - solutionAccepted = true; - } - } - return solutionAccepted; - } - - @Override - public String toString() { - return "[name=schrimpfAcceptanceFunction][alpha="+alpha+"][warmup=" + nOfRandomWalks + "]"; - } - - private double getThreshold(int iteration) { - double scheduleVariable = (double) iteration / (double) nOfTotalIterations; -// logger.debug("iter="+iteration+" totalIter="+nOfTotalIterations+" scheduling="+scheduleVariable); - double currentThreshold = initialThreshold * Math.exp(-Math.log(2) * scheduleVariable / alpha); - return currentThreshold; - } + public ExperimentalSchrimpfAcceptance(int solutionMemory, double alpha, int nOfWarmupIterations) { + super(); + this.alpha = alpha; + this.nOfRandomWalks = nOfWarmupIterations; + this.solutionMemory = solutionMemory; + logger.info("initialise {}", this); + } - @Override - public void informAlgorithmStarts(VehicleRoutingProblem problem, VehicleRoutingAlgorithm algorithm, Collection solutions) { - reset(); - logger.info("---------------------------------------------------------------------"); - logger.info("prepare schrimpfAcceptanceFunction, i.e. determine initial threshold"); - logger.info("start random-walk (see randomWalk.xml)"); - double now = System.currentTimeMillis(); - this.nOfTotalIterations = algorithm.getMaxIterations(); - + @Override + public boolean acceptSolution(Collection solutions, VehicleRoutingProblemSolution newSolution) { + boolean solutionAccepted = false; + if (solutions.size() < solutionMemory) { + solutions.add(newSolution); + solutionAccepted = true; + } else { + VehicleRoutingProblemSolution worst = null; + double threshold = getThreshold(currentIteration); + for (VehicleRoutingProblemSolution solutionInMemory : solutions) { + if (worst == null) worst = solutionInMemory; + else if (solutionInMemory.getCost() > worst.getCost()) worst = solutionInMemory; + } + if (newSolution.getRoutes().size() < worst.getRoutes().size()) { + solutions.remove(worst); + solutions.add(newSolution); + solutionAccepted = true; + } else if (newSolution.getRoutes().size() == worst.getRoutes().size() && newSolution.getCost() < worst.getCost() + threshold) { + solutions.remove(worst); + solutions.add(newSolution); + solutionAccepted = true; + } + } + return solutionAccepted; + } + + @Override + public String toString() { + return "[name=schrimpfAcceptanceFunction][alpha=" + alpha + "][warmup=" + nOfRandomWalks + "]"; + } + + private double getThreshold(int iteration) { + double scheduleVariable = (double) iteration / (double) nOfTotalIterations; +// logger.debug("iter={} totalIter={} scheduling={}", iteration, nOfTotalIterations, scheduleVariable); + double currentThreshold = initialThreshold * Math.exp(-Math.log(2) * scheduleVariable / alpha); + return currentThreshold; + } + + + @Override + public void informAlgorithmStarts(VehicleRoutingProblem problem, VehicleRoutingAlgorithm algorithm, Collection solutions) { + reset(); + logger.info("---------------------------------------------------------------------"); + logger.info("prepare schrimpfAcceptanceFunction, i.e. determine initial threshold"); + logger.info("start random-walk (see randomWalk.xml)"); + double now = System.currentTimeMillis(); + this.nOfTotalIterations = algorithm.getMaxIterations(); + /* - * randomWalk to determine standardDev + * randomWalk to determine standardDev */ - final double[] results = new double[nOfRandomWalks]; - - URL resource = Resource.getAsURL("randomWalk.xml"); - AlgorithmConfig algorithmConfig = new AlgorithmConfig(); - new AlgorithmConfigXmlReader(algorithmConfig).read(resource); - VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.createAlgorithm(problem, algorithmConfig); - vra.setMaxIterations(nOfRandomWalks); - vra.getAlgorithmListeners().addListener(new IterationEndsListener() { - - @Override - public void informIterationEnds(int iteration, VehicleRoutingProblem problem, Collection solutions) { - double result = Solutions.bestOf(solutions).getCost(); -// logger.info("result="+result); - results[iteration-1] = result; - } - - }); - vra.searchSolutions(); - - StandardDeviation dev = new StandardDeviation(); - double standardDeviation = dev.evaluate(results); - initialThreshold = standardDeviation / 2; - - logger.info("warmup done"); - logger.info("total time: " + ((System.currentTimeMillis()-now)/1000.0) + "s"); - logger.info("initial threshold: " + initialThreshold); - logger.info("---------------------------------------------------------------------"); - - } + final double[] results = new double[nOfRandomWalks]; - private void reset() { - currentIteration = 0; - } + URL resource = Resource.getAsURL("randomWalk.xml"); + AlgorithmConfig algorithmConfig = new AlgorithmConfig(); + new AlgorithmConfigXmlReader(algorithmConfig).read(resource); + VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.createAlgorithm(problem, algorithmConfig); + vra.setMaxIterations(nOfRandomWalks); + vra.getAlgorithmListeners().addListener(new IterationEndsListener() { - @Override - public void informIterationStarts(int i, VehicleRoutingProblem problem, Collection solutions) { - currentIteration = i; - } + @Override + public void informIterationEnds(int iteration, VehicleRoutingProblem problem, Collection solutions) { + double result = Solutions.bestOf(solutions).getCost(); +// logger.info("result={}", result); + results[iteration - 1] = result; + } + + }); + vra.searchSolutions(); + + StandardDeviation dev = new StandardDeviation(); + double standardDeviation = dev.evaluate(results); + initialThreshold = standardDeviation / 2; + + logger.info("warmup done"); + logger.info("total time: {}s", ((System.currentTimeMillis() - now) / 1000.0)); + logger.info("initial threshold: {}", initialThreshold); + logger.info("---------------------------------------------------------------------"); + + } + + private void reset() { + currentIteration = 0; + } + + @Override + public void informIterationStarts(int i, VehicleRoutingProblem problem, Collection solutions) { + currentIteration = i; + } } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/acceptor/GreedyAcceptance.java b/jsprit-core/src/main/java/jsprit/core/algorithm/acceptor/GreedyAcceptance.java index b54be03a..71a77a94 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/acceptor/GreedyAcceptance.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/acceptor/GreedyAcceptance.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.acceptor; @@ -23,51 +23,49 @@ import java.util.Collection; /** * Acceptor that accepts solutions to be memorized only better solutions. - * + *

*

If there is enough memory, every solution will be accepted. If there is no memory anymore and the solution * to be evaluated is better than the worst, the worst will be replaced by the new solution.

*/ -public class GreedyAcceptance implements SolutionAcceptor{ +public class GreedyAcceptance implements SolutionAcceptor { - private final int solutionMemory; - - public GreedyAcceptance(int solutionMemory){ - this.solutionMemory = solutionMemory; - } - - /** - * Accepts every solution if solution memory allows. If memory occupied, than accepts new solution only if better than the worst in memory. - * Consequently, the worst solution is removed from solutions, and the new solution added. - * - *

Note that this modifies Collection solutions. - */ - @Override - public boolean acceptSolution(Collection solutions, VehicleRoutingProblemSolution newSolution) { - boolean solutionAccepted = false; - if (solutions.size() < solutionMemory) { - solutions.add(newSolution); - solutionAccepted = true; - } else { - VehicleRoutingProblemSolution worstSolution = null; - for (VehicleRoutingProblemSolution s : solutions) { - if (worstSolution == null) worstSolution = s; - else if (s.getCost() > worstSolution.getCost()) worstSolution = s; - } - if(newSolution.getCost() < worstSolution.getCost()){ - solutions.remove(worstSolution); - solutions.add(newSolution); - solutionAccepted = true; - } - } - return solutionAccepted; - } - - @Override - public String toString() { - return "[name=GreedyAcceptance]"; - } - + private final int solutionMemory; + public GreedyAcceptance(int solutionMemory) { + this.solutionMemory = solutionMemory; + } + + /** + * Accepts every solution if solution memory allows. If memory occupied, than accepts new solution only if better than the worst in memory. + * Consequently, the worst solution is removed from solutions, and the new solution added. + *

+ *

Note that this modifies Collection solutions. + */ + @Override + public boolean acceptSolution(Collection solutions, VehicleRoutingProblemSolution newSolution) { + boolean solutionAccepted = false; + if (solutions.size() < solutionMemory) { + solutions.add(newSolution); + solutionAccepted = true; + } else { + VehicleRoutingProblemSolution worstSolution = null; + for (VehicleRoutingProblemSolution s : solutions) { + if (worstSolution == null) worstSolution = s; + else if (s.getCost() > worstSolution.getCost()) worstSolution = s; + } + if (newSolution.getCost() < worstSolution.getCost()) { + solutions.remove(worstSolution); + solutions.add(newSolution); + solutionAccepted = true; + } + } + return solutionAccepted; + } + + @Override + public String toString() { + return "[name=GreedyAcceptance]"; + } } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/acceptor/GreedyAcceptance_minVehFirst.java b/jsprit-core/src/main/java/jsprit/core/algorithm/acceptor/GreedyAcceptance_minVehFirst.java index 0fda452b..57876c94 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/acceptor/GreedyAcceptance_minVehFirst.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/acceptor/GreedyAcceptance_minVehFirst.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.acceptor; @@ -22,52 +22,49 @@ import java.util.Collection; @Deprecated -public class GreedyAcceptance_minVehFirst implements SolutionAcceptor{ +public class GreedyAcceptance_minVehFirst implements SolutionAcceptor { - private final int solutionMemory; - - public GreedyAcceptance_minVehFirst(int solutionMemory){ - this.solutionMemory = solutionMemory; - } - - /** - * Accepts every solution if solution memory allows. If memory occupied, than accepts new solution only if better than the worst in memory. - * Consequently, the worst solution is removed from solutions, and the new solution added. - * - *

Note that this modifies Collection solutions. - */ - @Override - public boolean acceptSolution(Collection solutions, VehicleRoutingProblemSolution newSolution) { - boolean solutionAccepted = false; - if (solutions.size() < solutionMemory) { - solutions.add(newSolution); - solutionAccepted = true; - } else { - VehicleRoutingProblemSolution worstSolution = null; - for (VehicleRoutingProblemSolution s : solutions) { - if (worstSolution == null) worstSolution = s; - else if (s.getRoutes().size() > worstSolution.getRoutes().size()) worstSolution = s; - } - if(newSolution.getRoutes().size() < worstSolution.getRoutes().size()){ - solutions.remove(worstSolution); - solutions.add(newSolution); - solutionAccepted = true; - } - else if(newSolution.getRoutes().size() == worstSolution.getRoutes().size() && newSolution.getCost() < worstSolution.getCost()){ - solutions.remove(worstSolution); - solutions.add(newSolution); - solutionAccepted = true; - } - } - return solutionAccepted; - } - - @Override - public String toString() { - return "[name=greedyAcceptance_minVehFirst]"; - } - + private final int solutionMemory; + public GreedyAcceptance_minVehFirst(int solutionMemory) { + this.solutionMemory = solutionMemory; + } + + /** + * Accepts every solution if solution memory allows. If memory occupied, than accepts new solution only if better than the worst in memory. + * Consequently, the worst solution is removed from solutions, and the new solution added. + *

+ *

Note that this modifies Collection solutions. + */ + @Override + public boolean acceptSolution(Collection solutions, VehicleRoutingProblemSolution newSolution) { + boolean solutionAccepted = false; + if (solutions.size() < solutionMemory) { + solutions.add(newSolution); + solutionAccepted = true; + } else { + VehicleRoutingProblemSolution worstSolution = null; + for (VehicleRoutingProblemSolution s : solutions) { + if (worstSolution == null) worstSolution = s; + else if (s.getRoutes().size() > worstSolution.getRoutes().size()) worstSolution = s; + } + if (newSolution.getRoutes().size() < worstSolution.getRoutes().size()) { + solutions.remove(worstSolution); + solutions.add(newSolution); + solutionAccepted = true; + } else if (newSolution.getRoutes().size() == worstSolution.getRoutes().size() && newSolution.getCost() < worstSolution.getCost()) { + solutions.remove(worstSolution); + solutions.add(newSolution); + solutionAccepted = true; + } + } + return solutionAccepted; + } + + @Override + public String toString() { + return "[name=greedyAcceptance_minVehFirst]"; + } } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/acceptor/SchrimpfAcceptance.java b/jsprit-core/src/main/java/jsprit/core/algorithm/acceptor/SchrimpfAcceptance.java index 5b182b04..5cc00af4 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/acceptor/SchrimpfAcceptance.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/acceptor/SchrimpfAcceptance.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.acceptor; @@ -29,24 +29,24 @@ import java.util.Collection; /** * ThresholdAcceptance-Function defined by Schrimpf et al. (2000). - * - *

The idea can be described as follows: Most problems do not only have one unique minimum (maximum) but + *

+ *

The idea can be described as follows: Most problems do not only have one unique minimum (maximum) but * a number of local minima (maxima). To avoid to get stuck in a local minimum at the beginning of a search * this threshold-acceptance function accepts also worse solution at the beginning (in contrary to a greedy * approach which only accepts better solutions), and converges to a greedy approach at the end.
* The difficulty is to define (i) an appropriate initial threshold and (ii) a corresponding function describing * how the threshold converges to zero, i.e. the greedy threshold. - * - *

ad i) The initial threshold is determined by a random walk through the search space. - * The random walk currently runs with the following algorithm: src/main/resources/randomWalk.xml. It runs - * as long as it is specified in nuOfWarmupIterations. In the first iteration or walk respectively the algorithm generates a solution. - * This solution in turn is the basis of the next walk yielding to another solution value ... and so on. - * Each solution value is memorized since the initial threshold is essentially a function of the standard deviation of these solution values. - * To be more precise: initial threshold = stddev(solution values) / 2. - * - *

ad ii) The threshold of iteration i is determined as follows: + *

+ *

ad i) The initial threshold is determined by a random walk through the search space. + * The random walk currently runs with the following algorithm: src/main/resources/randomWalk.xml. It runs + * as long as it is specified in nuOfWarmupIterations. In the first iteration or walk respectively the algorithm generates a solution. + * This solution in turn is the basis of the next walk yielding to another solution value ... and so on. + * Each solution value is memorized since the initial threshold is essentially a function of the standard deviation of these solution values. + * To be more precise: initial threshold = stddev(solution values) / 2. + *

+ *

ad ii) The threshold of iteration i is determined as follows: * threshold(i) = initialThreshold * Math.exp(-Math.log(2) * (i / nuOfTotalIterations) / alpha) - * To get a better understanding of the threshold-function go to Wolfram Alpha and plot the following line + * To get a better understanding of the threshold-function go to Wolfram Alpha and plot the following line * (just copy and paste it into Wolfram's console: www.wolframalpha.com): *

100. * exp(-log(2)* (x/1000) / 0.1) (x from 0 to 1000) (y from 0 to 100) *

with
@@ -55,102 +55,99 @@ import java.util.Collection; * alpha = 0.1
* x corresponds to i iterations and
* y to the threshold(i) - * - *

Gerhard Schrimpf, Johannes Schneider, Hermann Stamm- Wilbrandt, and Gunter Dueck (2000). - * Record breaking optimization results using the ruin and recreate principle. - * Journal of Computational Physics, 159(2):139 – 171, 2000. ISSN 0021-9991. doi: 10.1006/jcph.1999. 6413. + *

+ *

Gerhard Schrimpf, Johannes Schneider, Hermann Stamm- Wilbrandt, and Gunter Dueck (2000). + * Record breaking optimization results using the ruin and recreate principle. + * Journal of Computational Physics, 159(2):139 – 171, 2000. ISSN 0021-9991. doi: 10.1006/jcph.1999. 6413. * URL http://www.sciencedirect.com/science/article/ pii/S0021999199964136 - * * * @author schroeder - * */ -public class SchrimpfAcceptance implements SolutionAcceptor, IterationStartsListener, AlgorithmStartsListener{ +public class SchrimpfAcceptance implements SolutionAcceptor, IterationStartsListener, AlgorithmStartsListener { - private static Logger logger = LogManager.getLogger(SchrimpfAcceptance.class.getName()); - - private final double alpha; - - private int maxIterations = 1000; - - private int currentIteration = 0; - - private double initialThreshold = 0.0; - - private final int solutionMemory; + private static Logger logger = LogManager.getLogger(SchrimpfAcceptance.class.getName()); - - public SchrimpfAcceptance(int solutionMemory, double alpha){ - this.alpha = alpha; - this.solutionMemory = solutionMemory; - logger.debug("initialise " + this); - } + private final double alpha; - @Override - public boolean acceptSolution(Collection solutions, VehicleRoutingProblemSolution newSolution) { - boolean solutionAccepted = false; - if (solutions.size() < solutionMemory) { - solutions.add(newSolution); - solutionAccepted = true; - } else { - VehicleRoutingProblemSolution worst = null; - double threshold = getThreshold(currentIteration); - for(VehicleRoutingProblemSolution solutionInMemory : solutions){ - if(worst == null) worst = solutionInMemory; - else if(solutionInMemory.getCost() > worst.getCost()) worst = solutionInMemory; - } - if(worst == null){ + private int maxIterations = 1000; + + private int currentIteration = 0; + + private double initialThreshold = 0.0; + + private final int solutionMemory; + + + public SchrimpfAcceptance(int solutionMemory, double alpha) { + this.alpha = alpha; + this.solutionMemory = solutionMemory; + logger.debug("initialise {}", this); + } + + @Override + public boolean acceptSolution(Collection solutions, VehicleRoutingProblemSolution newSolution) { + boolean solutionAccepted = false; + if (solutions.size() < solutionMemory) { + solutions.add(newSolution); + solutionAccepted = true; + } else { + VehicleRoutingProblemSolution worst = null; + double threshold = getThreshold(currentIteration); + for (VehicleRoutingProblemSolution solutionInMemory : solutions) { + if (worst == null) worst = solutionInMemory; + else if (solutionInMemory.getCost() > worst.getCost()) worst = solutionInMemory; + } + if (worst == null) { + solutions.add(newSolution); + solutionAccepted = true; + } else if (newSolution.getCost() < worst.getCost() + threshold) { + solutions.remove(worst); solutions.add(newSolution); solutionAccepted = true; } - else if(newSolution.getCost() < worst.getCost() + threshold){ - solutions.remove(worst); - solutions.add(newSolution); - solutionAccepted = true; - } - } - return solutionAccepted; - } - - @Override - public String toString() { - return "[name=SchrimpfAcceptance][alpha="+alpha+"]"; - } - - private double getThreshold(int iteration) { - double scheduleVariable = (double) iteration / (double) maxIterations; - return initialThreshold * Math.exp(-1. * Math.log(2) * scheduleVariable / alpha); - } + } + return solutionAccepted; + } + + @Override + public String toString() { + return "[name=SchrimpfAcceptance][alpha=" + alpha + "]"; + } + + private double getThreshold(int iteration) { + double scheduleVariable = (double) iteration / (double) maxIterations; + return initialThreshold * Math.exp(-1. * Math.log(2) * scheduleVariable / alpha); + } - @SuppressWarnings("UnusedDeclaration") - public double getInitialThreshold(){ - return initialThreshold; - } - - /** - * Sets initial threshold. - *

Note that if initial threshold has been set, automatic generation of initial threshold is disabled. - * - * @param initialThreshold the initialThreshold to set - */ - public void setInitialThreshold(double initialThreshold) { - this.initialThreshold = initialThreshold; - } + @SuppressWarnings("UnusedDeclaration") + public double getInitialThreshold() { + return initialThreshold; + } - @Override - public void informAlgorithmStarts(VehicleRoutingProblem problem, VehicleRoutingAlgorithm algorithm, Collection solutions) { + /** + * Sets initial threshold. + *

Note that if initial threshold has been set, automatic generation of initial threshold is disabled. + * + * @param initialThreshold the initialThreshold to set + */ + public void setInitialThreshold(double initialThreshold) { + this.initialThreshold = initialThreshold; + } + + @Override + public void informAlgorithmStarts(VehicleRoutingProblem problem, VehicleRoutingAlgorithm algorithm, Collection solutions) { reset(); this.maxIterations = algorithm.getMaxIterations(); - } + } - private void reset() { - currentIteration = 0; - } + private void reset() { + currentIteration = 0; + } - @Override - public void informIterationStarts(int i, VehicleRoutingProblem problem, Collection solutions) { - currentIteration = i; - } + @Override + public void informIterationStarts(int i, VehicleRoutingProblem problem, Collection solutions) { + currentIteration = i; + } } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/acceptor/SchrimpfInitialThresholdGenerator.java b/jsprit-core/src/main/java/jsprit/core/algorithm/acceptor/SchrimpfInitialThresholdGenerator.java index 1a2753a2..b0549b37 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/acceptor/SchrimpfInitialThresholdGenerator.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/acceptor/SchrimpfInitialThresholdGenerator.java @@ -34,55 +34,55 @@ import java.net.URL; import java.util.Collection; public class SchrimpfInitialThresholdGenerator implements AlgorithmStartsListener { - - private static Logger logger = LogManager.getLogger(SchrimpfInitialThresholdGenerator.class.getName()); - - private SchrimpfAcceptance schrimpfAcceptance; - - private int nOfRandomWalks; - - public SchrimpfInitialThresholdGenerator(SchrimpfAcceptance schrimpfAcceptance, int nOfRandomWalks) { - super(); - this.schrimpfAcceptance = schrimpfAcceptance; - this.nOfRandomWalks = nOfRandomWalks; - } - @Override - public void informAlgorithmStarts(VehicleRoutingProblem problem,VehicleRoutingAlgorithm algorithm,Collection solutions) { - logger.info("prepare schrimpfAcceptanceFunction, i.e. determine initial threshold"); - double now = System.currentTimeMillis(); - + private static Logger logger = LogManager.getLogger(SchrimpfInitialThresholdGenerator.class.getName()); + + private SchrimpfAcceptance schrimpfAcceptance; + + private int nOfRandomWalks; + + public SchrimpfInitialThresholdGenerator(SchrimpfAcceptance schrimpfAcceptance, int nOfRandomWalks) { + super(); + this.schrimpfAcceptance = schrimpfAcceptance; + this.nOfRandomWalks = nOfRandomWalks; + } + + @Override + public void informAlgorithmStarts(VehicleRoutingProblem problem, VehicleRoutingAlgorithm algorithm, Collection solutions) { + logger.info("prepare schrimpfAcceptanceFunction, i.e. determine initial threshold"); + double now = System.currentTimeMillis(); + /* - * randomWalk to determine standardDev + * randomWalk to determine standardDev */ - final double[] results = new double[nOfRandomWalks]; - - URL resource = Resource.getAsURL("randomWalk.xml"); - AlgorithmConfig algorithmConfig = new AlgorithmConfig(); - new AlgorithmConfigXmlReader(algorithmConfig).read(resource); - VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.createAlgorithm(problem, algorithmConfig); - vra.setMaxIterations(nOfRandomWalks); - vra.getAlgorithmListeners().addListener(new IterationEndsListener() { - - @Override - public void informIterationEnds(int iteration, VehicleRoutingProblem problem, Collection solutions) { - double result = Solutions.bestOf(solutions).getCost(); -// logger.info("result="+result); - results[iteration-1] = result; - } - - }); - vra.searchSolutions(); - - StandardDeviation dev = new StandardDeviation(); - double standardDeviation = dev.evaluate(results); - double initialThreshold = standardDeviation / 2; - - schrimpfAcceptance.setInitialThreshold(initialThreshold); + final double[] results = new double[nOfRandomWalks]; - logger.info("took " + ((System.currentTimeMillis()-now)/1000.0) + " seconds"); - logger.debug("initial threshold: " + initialThreshold); - logger.info("---------------------------------------------------------------------"); - } + URL resource = Resource.getAsURL("randomWalk.xml"); + AlgorithmConfig algorithmConfig = new AlgorithmConfig(); + new AlgorithmConfigXmlReader(algorithmConfig).read(resource); + VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.createAlgorithm(problem, algorithmConfig); + vra.setMaxIterations(nOfRandomWalks); + vra.getAlgorithmListeners().addListener(new IterationEndsListener() { + + @Override + public void informIterationEnds(int iteration, VehicleRoutingProblem problem, Collection solutions) { + double result = Solutions.bestOf(solutions).getCost(); +// logger.info("result={}", result); + results[iteration - 1] = result; + } + + }); + vra.searchSolutions(); + + StandardDeviation dev = new StandardDeviation(); + double standardDeviation = dev.evaluate(results); + double initialThreshold = standardDeviation / 2; + + schrimpfAcceptance.setInitialThreshold(initialThreshold); + + logger.info("took {} seconds", ((System.currentTimeMillis() - now) / 1000.0)); + logger.debug("initial threshold: {}", initialThreshold); + logger.info("---------------------------------------------------------------------"); + } } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/acceptor/SolutionAcceptor.java b/jsprit-core/src/main/java/jsprit/core/algorithm/acceptor/SolutionAcceptor.java index b47d913e..c6377bf1 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/acceptor/SolutionAcceptor.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/acceptor/SolutionAcceptor.java @@ -1,4 +1,3 @@ - /******************************************************************************* * Copyright (C) 2014 Stefan Schroeder * @@ -25,22 +24,20 @@ import java.util.Collection; /** * Acceptor that decides whether the newSolution is accepted or not. - * - * - * @author stefan * + * @author stefan */ public interface SolutionAcceptor { - - /** - * Accepts solution or not, and returns true if a new solution has been accepted. - * - *

If the solution is accepted, it is added to solutions, i.e. the solutions-collections is modified. - * - * @param solutions collection of existing solutions - * @param newSolution new solution to be evaluated - * @return true if solution accepted - */ - public boolean acceptSolution(Collection solutions, VehicleRoutingProblemSolution newSolution); + + /** + * Accepts solution or not, and returns true if a new solution has been accepted. + *

+ *

If the solution is accepted, it is added to solutions, i.e. the solutions-collections is modified. + * + * @param solutions collection of existing solutions + * @param newSolution new solution to be evaluated + * @return true if solution accepted + */ + public boolean acceptSolution(Collection solutions, VehicleRoutingProblemSolution newSolution); } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/box/ConcurrentInsertionNoiseMaker.java b/jsprit-core/src/main/java/jsprit/core/algorithm/box/ConcurrentInsertionNoiseMaker.java new file mode 100644 index 00000000..1c681224 --- /dev/null +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/box/ConcurrentInsertionNoiseMaker.java @@ -0,0 +1,61 @@ +package jsprit.core.algorithm.box; + +import jsprit.core.algorithm.listener.IterationStartsListener; +import jsprit.core.problem.VehicleRoutingProblem; +import jsprit.core.problem.constraint.SoftActivityConstraint; +import jsprit.core.problem.misc.JobInsertionContext; +import jsprit.core.problem.solution.VehicleRoutingProblemSolution; +import jsprit.core.problem.solution.route.activity.TourActivity; +import jsprit.core.util.RandomNumberGeneration; + +import java.util.Collection; +import java.util.Random; + +/** + * Created by schroeder on 16/01/15. + */ +class ConcurrentInsertionNoiseMaker implements SoftActivityConstraint, IterationStartsListener { + + private final double noiseProbability; + + private boolean makeNoise = false; + + private double noiseLevel = 0.1; + + private Random random = RandomNumberGeneration.newInstance(); + + private Random[] randomArray; + + private double maxCosts; + + ConcurrentInsertionNoiseMaker(VehicleRoutingProblem vrp, double maxCosts, double noiseLevel, double noiseProbability) { + this.noiseLevel = noiseLevel; + this.noiseProbability = noiseProbability; + this.maxCosts = maxCosts; + randomArray = new Random[vrp.getNuActivities() + 2]; + for (int i = 0; i < randomArray.length; i++) { + Random r = new Random(); + r.setSeed(random.nextLong()); + randomArray[i] = r; + } + } + + @Override + public void informIterationStarts(int i, VehicleRoutingProblem problem, Collection solutions) { + if (random.nextDouble() < noiseProbability) { + makeNoise = true; + } else makeNoise = false; + } + + @Override + public double getCosts(JobInsertionContext iFacts, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double prevActDepTime) { + if (makeNoise) { + return noiseLevel * maxCosts * randomArray[newAct.getIndex()].nextDouble(); + } + return 0; + } + + public void setRandom(Random random) { + this.random = random; + } +} diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/box/GreedySchrimpfFactory.java b/jsprit-core/src/main/java/jsprit/core/algorithm/box/GreedySchrimpfFactory.java index 9c195880..7c82fba9 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/box/GreedySchrimpfFactory.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/box/GreedySchrimpfFactory.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.box; @@ -26,41 +26,38 @@ import jsprit.core.util.Resource; import java.net.URL; - /** * Factory that creates the {@link VehicleRoutingAlgorithm} as proposed by Schrimpf et al., 2000 with the following parameters: - * - *

+ *

+ *

* R&R_random (prob=0.5, F=0.5); * R&R_radial (prob=0.5, F=0.3); * threshold-accepting with exponentialDecayFunction (alpha=0.1, warmup-iterations=100); * nuOfIterations=2000 - * - *

Gerhard Schrimpf, Johannes Schneider, Hermann Stamm- Wilbrandt, and Gunter Dueck. - * Record breaking optimization results using the ruin and recreate principle. - * Journal of Computational Physics, 159(2):139 – 171, 2000. ISSN 0021-9991. doi: 10.1006/jcph.1999. 6413. + *

+ *

Gerhard Schrimpf, Johannes Schneider, Hermann Stamm- Wilbrandt, and Gunter Dueck. + * Record breaking optimization results using the ruin and recreate principle. + * Journal of Computational Physics, 159(2):139 – 171, 2000. ISSN 0021-9991. doi: 10.1006/jcph.1999. 6413. * URL http://www.sciencedirect.com/science/article/ pii/S0021999199964136 - * - *

algorithm-xml-config is available at src/main/resources/schrimpf.xml. - * - * @author stefan schroeder + *

+ *

algorithm-xml-config is available at src/main/resources/schrimpf.xml. * + * @author stefan schroeder */ public class GreedySchrimpfFactory { - - /** - * Creates the {@link VehicleRoutingAlgorithm}. - * - * @param vrp - * @return algorithm - */ - public VehicleRoutingAlgorithm createAlgorithm(VehicleRoutingProblem vrp){ - AlgorithmConfig algorithmConfig = new AlgorithmConfig(); - URL resource = Resource.getAsURL("greedySchrimpf.xml"); - new AlgorithmConfigXmlReader(algorithmConfig).read(resource); - return VehicleRoutingAlgorithms.createAlgorithm(vrp, algorithmConfig); - } - - + + /** + * Creates the {@link VehicleRoutingAlgorithm}. + * + * @param vrp + * @return algorithm + */ + public VehicleRoutingAlgorithm createAlgorithm(VehicleRoutingProblem vrp) { + AlgorithmConfig algorithmConfig = new AlgorithmConfig(); + URL resource = Resource.getAsURL("greedySchrimpf.xml"); + new AlgorithmConfigXmlReader(algorithmConfig).read(resource); + return VehicleRoutingAlgorithms.createAlgorithm(vrp, algorithmConfig); + } + } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/box/InsertionNoiseMaker.java b/jsprit-core/src/main/java/jsprit/core/algorithm/box/InsertionNoiseMaker.java index 8aed19a2..4228bfa0 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/box/InsertionNoiseMaker.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/box/InsertionNoiseMaker.java @@ -1,92 +1,60 @@ package jsprit.core.algorithm.box; import jsprit.core.algorithm.listener.IterationStartsListener; -import jsprit.core.problem.Location; import jsprit.core.problem.VehicleRoutingProblem; import jsprit.core.problem.constraint.SoftActivityConstraint; -import jsprit.core.problem.job.Job; -import jsprit.core.problem.job.Service; -import jsprit.core.problem.job.Shipment; import jsprit.core.problem.misc.JobInsertionContext; import jsprit.core.problem.solution.VehicleRoutingProblemSolution; import jsprit.core.problem.solution.route.activity.TourActivity; import jsprit.core.util.RandomNumberGeneration; -import java.util.ArrayList; import java.util.Collection; -import java.util.List; import java.util.Random; /** -* Created by schroeder on 16/01/15. -*/ + * Created by schroeder on 16/01/15. + */ class InsertionNoiseMaker implements SoftActivityConstraint, IterationStartsListener { private final double noiseProbability; private boolean makeNoise = false; - private VehicleRoutingProblem vrp; - - double maxCosts = 0.; - private double noiseLevel = 0.1; - private Random random = RandomNumberGeneration.getRandom(); + private Random random = RandomNumberGeneration.newInstance(); - public InsertionNoiseMaker(VehicleRoutingProblem vrp, double noiseLevel, double noiseProbability) { - this.vrp = vrp; +// private Random[] randomArray; + + private double maxCosts; + + InsertionNoiseMaker(VehicleRoutingProblem vrp, double maxCosts, double noiseLevel, double noiseProbability) { this.noiseLevel = noiseLevel; this.noiseProbability = noiseProbability; - determineMaxCosts(vrp); - } - - //@ToDo refactor determining max costs to allow skipping this - private void determineMaxCosts(VehicleRoutingProblem vrp) { - double max = 0.; - for(Job i : vrp.getJobs().values()){ - List fromLocations = getLocations(i); - for(Job j : vrp.getJobs().values()){ - List toLocations = getLocations(j); - for(Location iLoc : fromLocations){ - for(Location jLoc : toLocations) { - max = Math.max(max, vrp.getTransportCosts().getTransportCost(iLoc, jLoc, 0, null, vrp.getVehicles().iterator().next())); - } - } - } - } - maxCosts = max; - } - - private List getLocations(Job j) { - List locs = new ArrayList(); - if(j instanceof Service) { - locs.add(((Service) j).getLocation()); - } - else if(j instanceof Shipment){ - locs.add(((Shipment) j).getPickupLocation()); - locs.add(((Shipment) j).getDeliveryLocation()); - } - return locs; + this.maxCosts = maxCosts; +// randomArray = new Random[vrp.getNuActivities() + 2]; +// for (int i = 0; i < randomArray.length; i++) { +// Random r = new Random(); +// r.setSeed(random.nextLong()); +// randomArray[i] = r; +// } } @Override public void informIterationStarts(int i, VehicleRoutingProblem problem, Collection solutions) { - if(random.nextDouble() < noiseProbability){ + if (random.nextDouble() < noiseProbability) { makeNoise = true; - } - else makeNoise = false; + } else makeNoise = false; } @Override public double getCosts(JobInsertionContext iFacts, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double prevActDepTime) { - if(makeNoise) { + if (makeNoise) { return noiseLevel * maxCosts * random.nextDouble(); } return 0; } - public void setRandom(Random random) { this.random = random; } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/box/Jsprit.java b/jsprit-core/src/main/java/jsprit/core/algorithm/box/Jsprit.java index af75626a..c410e43b 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/box/Jsprit.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/box/Jsprit.java @@ -17,6 +17,7 @@ import jsprit.core.problem.constraint.ConstraintManager; import jsprit.core.problem.solution.SolutionCostCalculator; import jsprit.core.problem.solution.VehicleRoutingProblemSolution; import jsprit.core.problem.solution.route.VehicleRoute; +import jsprit.core.problem.solution.route.activity.BreakActivity; import jsprit.core.problem.solution.route.activity.TourActivity; import jsprit.core.problem.vehicle.FiniteFleetManagerFactory; import jsprit.core.problem.vehicle.InfiniteFleetManagerFactory; @@ -34,17 +35,19 @@ import java.util.concurrent.Executors; public class Jsprit { + private final ActivityInsertionCostsCalculator activityInsertion; + public enum Construction { BEST_INSERTION("best_insertion"), REGRET_INSERTION("regret_insertion"); String name; - Construction(String name){ + Construction(String name) { this.name = name; } - public String toString(){ + public String toString() { return name; } @@ -63,11 +66,11 @@ public class Jsprit { String strategyName; - Strategy(String strategyName){ + Strategy(String strategyName) { this.strategyName = strategyName; } - public String toString(){ + public String toString() { return strategyName; } } @@ -75,7 +78,7 @@ public class Jsprit { public enum Parameter { FIXED_COST_PARAM("fixed_cost_param"), VEHICLE_SWITCH("vehicle_switch"), REGRET_TIME_WINDOW_SCORER("regret.tw_scorer"), - REGRET_DISTANCE_SCORER("regret.distance_scorer"), INITIAL_THRESHOLD("initial_threshold"), ITERATIONS("iterations"), + REGRET_DISTANCE_SCORER("regret.distance_scorer"), INITIAL_THRESHOLD("initial_threshold"), ITERATIONS("iterations"), THREADS("threads"), RANDOM_REGRET_MIN_SHARE("random_regret.min_share"), RANDOM_REGRET_MAX_SHARE("random_regret.max_share"), @@ -93,21 +96,23 @@ public class Jsprit { INSERTION_NOISE_PROB("insertion.noise_prob"), RUIN_WORST_NOISE_LEVEL("worst.noise_level"), RUIN_WORST_NOISE_PROB("worst.noise_prob"), + FAST_REGRET("regret.fast"), + MAX_TRANSPORT_COSTS("max_transport_costs"), CONSTRUCTION("construction"); String paraName; - Parameter(String name){ + Parameter(String name) { this.paraName = name; } - public String toString(){ + public String toString() { return paraName; } } - public static VehicleRoutingAlgorithm createAlgorithm(VehicleRoutingProblem vehicleRoutingProblem){ + public static VehicleRoutingAlgorithm createAlgorithm(VehicleRoutingProblem vehicleRoutingProblem) { return Jsprit.Builder.newInstance(vehicleRoutingProblem).buildAlgorithm(); } @@ -131,53 +136,56 @@ public class Jsprit { private Random random = RandomNumberGeneration.newInstance(); - public static Builder newInstance(VehicleRoutingProblem vrp){ + private ActivityInsertionCostsCalculator activityInsertionCalculator; + + public static Builder newInstance(VehicleRoutingProblem vrp) { return new Builder(vrp); } - private Builder(VehicleRoutingProblem vrp){ + private Builder(VehicleRoutingProblem vrp) { this.vrp = vrp; properties = new Properties(createDefaultProperties()); } private Properties createDefaultProperties() { Properties defaults = new Properties(); - defaults.put(Strategy.RADIAL_BEST.toString(),"0."); - defaults.put(Strategy.RADIAL_REGRET.toString(),".5"); - defaults.put(Strategy.RANDOM_BEST.toString(),".5"); - defaults.put(Strategy.RANDOM_REGRET.toString(),".5"); - defaults.put(Strategy.WORST_BEST.toString(),"0."); - defaults.put(Strategy.WORST_REGRET.toString(),"1."); - defaults.put(Strategy.CLUSTER_BEST.toString(),"0."); - defaults.put(Strategy.CLUSTER_REGRET.toString(),"1."); - defaults.put(Parameter.FIXED_COST_PARAM.toString(),"0."); - defaults.put(Parameter.VEHICLE_SWITCH.toString(),"true"); - defaults.put(Parameter.ITERATIONS.toString(),"2000"); - defaults.put(Parameter.REGRET_DISTANCE_SCORER.toString(),".05"); - defaults.put(Parameter.REGRET_TIME_WINDOW_SCORER.toString(),"-.1"); - defaults.put(Parameter.THREADS.toString(),"1"); - int minShare = (int)Math.min(20, Math.max(3,vrp.getJobs().size() * 0.05)); - int maxShare = (int)Math.min(50, Math.max(5,vrp.getJobs().size() * 0.3)); - defaults.put(Parameter.RADIAL_MIN_SHARE.toString(),String.valueOf(minShare)); - defaults.put(Parameter.RADIAL_MAX_SHARE.toString(),String.valueOf(maxShare)); - defaults.put(Parameter.WORST_MIN_SHARE.toString(),String.valueOf(minShare)); - defaults.put(Parameter.WORST_MAX_SHARE.toString(),String.valueOf(maxShare)); - defaults.put(Parameter.CLUSTER_MIN_SHARE.toString(),String.valueOf(minShare)); - defaults.put(Parameter.CLUSTER_MAX_SHARE.toString(),String.valueOf(maxShare)); - int minShare_ = (int)Math.min(70, Math.max(5,vrp.getJobs().size() * 0.5)); - int maxShare_ = (int)Math.min(70, Math.max(5,vrp.getJobs().size() * 0.5)); - defaults.put(Parameter.RANDOM_REGRET_MIN_SHARE.toString(),String.valueOf(minShare_)); - defaults.put(Parameter.RANDOM_REGRET_MAX_SHARE.toString(),String.valueOf(maxShare_)); - defaults.put(Parameter.RANDOM_BEST_MIN_SHARE.toString(),String.valueOf(minShare_)); - defaults.put(Parameter.RANDOM_BEST_MAX_SHARE.toString(),String.valueOf(maxShare_)); - defaults.put(Parameter.THRESHOLD_ALPHA.toString(),String.valueOf(0.15)); - defaults.put(Parameter.THRESHOLD_INI.toString(),String.valueOf(0.03)); - defaults.put(Parameter.INSERTION_NOISE_LEVEL.toString(),String.valueOf(0.15)); - defaults.put(Parameter.INSERTION_NOISE_PROB.toString(),String.valueOf(0.2)); - defaults.put(Parameter.RUIN_WORST_NOISE_LEVEL.toString(),String.valueOf(0.15)); - defaults.put(Parameter.RUIN_WORST_NOISE_PROB.toString(),String.valueOf(0.2)); - defaults.put(Parameter.VEHICLE_SWITCH.toString(),String.valueOf(true)); - defaults.put(Parameter.CONSTRUCTION.toString(),Construction.REGRET_INSERTION.toString()); + defaults.put(Strategy.RADIAL_BEST.toString(), "0."); + defaults.put(Strategy.RADIAL_REGRET.toString(), ".5"); + defaults.put(Strategy.RANDOM_BEST.toString(), ".5"); + defaults.put(Strategy.RANDOM_REGRET.toString(), ".5"); + defaults.put(Strategy.WORST_BEST.toString(), "0."); + defaults.put(Strategy.WORST_REGRET.toString(), "1."); + defaults.put(Strategy.CLUSTER_BEST.toString(), "0."); + defaults.put(Strategy.CLUSTER_REGRET.toString(), "1."); + defaults.put(Parameter.FIXED_COST_PARAM.toString(), "0."); + defaults.put(Parameter.VEHICLE_SWITCH.toString(), "true"); + defaults.put(Parameter.ITERATIONS.toString(), "2000"); + defaults.put(Parameter.REGRET_DISTANCE_SCORER.toString(), ".05"); + defaults.put(Parameter.REGRET_TIME_WINDOW_SCORER.toString(), "-.1"); + defaults.put(Parameter.THREADS.toString(), "1"); + int minShare = (int) Math.min(20, Math.max(3, vrp.getJobs().size() * 0.05)); + int maxShare = (int) Math.min(50, Math.max(5, vrp.getJobs().size() * 0.3)); + defaults.put(Parameter.RADIAL_MIN_SHARE.toString(), String.valueOf(minShare)); + defaults.put(Parameter.RADIAL_MAX_SHARE.toString(), String.valueOf(maxShare)); + defaults.put(Parameter.WORST_MIN_SHARE.toString(), String.valueOf(minShare)); + defaults.put(Parameter.WORST_MAX_SHARE.toString(), String.valueOf(maxShare)); + defaults.put(Parameter.CLUSTER_MIN_SHARE.toString(), String.valueOf(minShare)); + defaults.put(Parameter.CLUSTER_MAX_SHARE.toString(), String.valueOf(maxShare)); + int minShare_ = (int) Math.min(70, Math.max(5, vrp.getJobs().size() * 0.5)); + int maxShare_ = (int) Math.min(70, Math.max(5, vrp.getJobs().size() * 0.5)); + defaults.put(Parameter.RANDOM_REGRET_MIN_SHARE.toString(), String.valueOf(minShare_)); + defaults.put(Parameter.RANDOM_REGRET_MAX_SHARE.toString(), String.valueOf(maxShare_)); + defaults.put(Parameter.RANDOM_BEST_MIN_SHARE.toString(), String.valueOf(minShare_)); + defaults.put(Parameter.RANDOM_BEST_MAX_SHARE.toString(), String.valueOf(maxShare_)); + defaults.put(Parameter.THRESHOLD_ALPHA.toString(), String.valueOf(0.15)); + defaults.put(Parameter.THRESHOLD_INI.toString(), String.valueOf(0.03)); + defaults.put(Parameter.INSERTION_NOISE_LEVEL.toString(), String.valueOf(0.15)); + defaults.put(Parameter.INSERTION_NOISE_PROB.toString(), String.valueOf(0.2)); + defaults.put(Parameter.RUIN_WORST_NOISE_LEVEL.toString(), String.valueOf(0.15)); + defaults.put(Parameter.RUIN_WORST_NOISE_PROB.toString(), String.valueOf(0.2)); + defaults.put(Parameter.VEHICLE_SWITCH.toString(), String.valueOf(true)); + defaults.put(Parameter.FAST_REGRET, String.valueOf(false)); + defaults.put(Parameter.CONSTRUCTION.toString(), Construction.REGRET_INSERTION.toString()); return defaults; } @@ -188,23 +196,23 @@ public class Jsprit { return this; } - public Builder setRandom(Random random){ + public Builder setRandom(Random random) { this.random = random; return this; } - public Builder setProperty(String key, String value){ - properties.put(key,value); + public Builder setProperty(String key, String value) { + properties.put(key, value); return this; } - public Builder setProperty(Parameter parameter, String value){ - setProperty(parameter.toString(),value); + public Builder setProperty(Parameter parameter, String value) { + setProperty(parameter.toString(), value); return this; } - public Builder setProperty(Strategy strategy, String value){ - setProperty(strategy.toString(),value); + public Builder setProperty(Strategy strategy, String value) { + setProperty(strategy.toString(), value); return this; } @@ -224,7 +232,12 @@ public class Jsprit { return this; } - public VehicleRoutingAlgorithm buildAlgorithm(){ + public Builder setActivityInsertionCalculator(ActivityInsertionCostsCalculator activityInsertionCalculator) { + this.activityInsertionCalculator = activityInsertionCalculator; + return this; + } + + public VehicleRoutingAlgorithm buildAlgorithm() { return new Jsprit(this).create(vrp); } @@ -245,13 +258,15 @@ public class Jsprit { } public RuinShareFactoryImpl(int minShare, int maxShare) { - if(maxShare < minShare) throw new IllegalArgumentException("maxShare must be equal or greater than minShare"); + if (maxShare < minShare) + throw new IllegalArgumentException("maxShare must be equal or greater than minShare"); this.minShare = minShare; this.maxShare = maxShare; } public RuinShareFactoryImpl(int minShare, int maxShare, Random random) { - if(maxShare < minShare) throw new IllegalArgumentException("maxShare must be equal or greater than minShare"); + if (maxShare < minShare) + throw new IllegalArgumentException("maxShare must be equal or greater than minShare"); this.minShare = minShare; this.maxShare = maxShare; this.random = random; @@ -291,61 +306,93 @@ public class Jsprit { this.properties = builder.properties; this.objectiveFunction = builder.objectiveFunction; this.random = builder.random; + this.activityInsertion = builder.activityInsertionCalculator; } - private VehicleRoutingAlgorithm create(final VehicleRoutingProblem vrp){ + private VehicleRoutingAlgorithm create(final VehicleRoutingProblem vrp) { VehicleFleetManager fm; - if(vrp.getFleetSize().equals(VehicleRoutingProblem.FleetSize.INFINITE)){ + if (vrp.getFleetSize().equals(VehicleRoutingProblem.FleetSize.INFINITE)) { fm = new InfiniteFleetManagerFactory(vrp.getVehicles()).createFleetManager(); + } else { + FiniteFleetManagerFactory finiteFleetManagerFactory = new FiniteFleetManagerFactory(vrp.getVehicles()); + finiteFleetManagerFactory.setRandom(random); + fm = finiteFleetManagerFactory.createFleetManager(); } - else fm = new FiniteFleetManagerFactory(vrp.getVehicles()).createFleetManager(); - if(stateManager == null){ + if (stateManager == null) { stateManager = new StateManager(vrp); } - if(constraintManager == null){ - constraintManager = new ConstraintManager(vrp,stateManager); + if (constraintManager == null) { + constraintManager = new ConstraintManager(vrp, stateManager); + } + + if (noThreads == null) { + noThreads = toInteger(getProperty(Parameter.THREADS.toString())); + } + if (noThreads > 1) { + if (es == null) { + setupExecutorInternally = true; + es = Executors.newFixedThreadPool(noThreads); + } } double noiseLevel = toDouble(getProperty(Parameter.INSERTION_NOISE_LEVEL.toString())); double noiseProbability = toDouble(getProperty(Parameter.INSERTION_NOISE_PROB.toString())); - final InsertionNoiseMaker noiseMaker = new InsertionNoiseMaker(vrp, noiseLevel, noiseProbability); - noiseMaker.setRandom(random); - constraintManager.addConstraint(noiseMaker); JobNeighborhoods jobNeighborhoods = new JobNeighborhoodsFactory().createNeighborhoods(vrp, new AvgServiceAndShipmentDistance(vrp.getTransportCosts()), (int) (vrp.getJobs().values().size() * 0.5)); jobNeighborhoods.initialise(); - RuinRadial radial = new RuinRadial(vrp,vrp.getJobs().size(),jobNeighborhoods); + final double maxCosts; + if(properties.containsKey(Parameter.MAX_TRANSPORT_COSTS.toString())){ + maxCosts = Double.parseDouble(getProperty(Parameter.MAX_TRANSPORT_COSTS.toString())); + } + else{ + maxCosts = jobNeighborhoods.getMaxDistance(); + } + + IterationStartsListener noiseConfigurator; + if (noThreads > 1) { + ConcurrentInsertionNoiseMaker noiseMaker = new ConcurrentInsertionNoiseMaker(vrp, maxCosts, noiseLevel, noiseProbability); + noiseMaker.setRandom(random); + constraintManager.addConstraint(noiseMaker); + noiseConfigurator = noiseMaker; + } else { + InsertionNoiseMaker noiseMaker = new InsertionNoiseMaker(vrp, maxCosts, noiseLevel, noiseProbability); + noiseMaker.setRandom(random); + constraintManager.addConstraint(noiseMaker); + noiseConfigurator = noiseMaker; + } + + RuinRadial radial = new RuinRadial(vrp, vrp.getJobs().size(), jobNeighborhoods); radial.setRandom(random); radial.setRuinShareFactory(new RuinShareFactoryImpl( toInteger(properties.getProperty(Parameter.RADIAL_MIN_SHARE.toString())), toInteger(properties.getProperty(Parameter.RADIAL_MAX_SHARE.toString())), - random) + random) ); - final RuinRandom random_for_regret = new RuinRandom(vrp,0.5); + final RuinRandom random_for_regret = new RuinRandom(vrp, 0.5); random_for_regret.setRandom(random); random_for_regret.setRuinShareFactory(new RuinShareFactoryImpl( - toInteger(properties.getProperty(Parameter.RANDOM_REGRET_MIN_SHARE.toString())), - toInteger(properties.getProperty(Parameter.RANDOM_REGRET_MAX_SHARE.toString())), - random) + toInteger(properties.getProperty(Parameter.RANDOM_REGRET_MIN_SHARE.toString())), + toInteger(properties.getProperty(Parameter.RANDOM_REGRET_MAX_SHARE.toString())), + random) ); - final RuinRandom random_for_best = new RuinRandom(vrp,0.5); + final RuinRandom random_for_best = new RuinRandom(vrp, 0.5); random_for_best.setRandom(random); random_for_best.setRuinShareFactory(new RuinShareFactoryImpl( - toInteger(properties.getProperty(Parameter.RANDOM_BEST_MIN_SHARE.toString())), - toInteger(properties.getProperty(Parameter.RANDOM_BEST_MAX_SHARE.toString())), - random) + toInteger(properties.getProperty(Parameter.RANDOM_BEST_MIN_SHARE.toString())), + toInteger(properties.getProperty(Parameter.RANDOM_BEST_MAX_SHARE.toString())), + random) ); - final RuinWorst worst = new RuinWorst(vrp, (int) (vrp.getJobs().values().size()*0.5)); + final RuinWorst worst = new RuinWorst(vrp, (int) (vrp.getJobs().values().size() * 0.5)); worst.setRandom(random); worst.setRuinShareFactory(new RuinShareFactoryImpl( - toInteger(properties.getProperty(Parameter.WORST_MIN_SHARE.toString())), - toInteger(properties.getProperty(Parameter.WORST_MAX_SHARE.toString())), - random) + toInteger(properties.getProperty(Parameter.WORST_MIN_SHARE.toString())), + toInteger(properties.getProperty(Parameter.WORST_MAX_SHARE.toString())), + random) ); IterationStartsListener noise = new IterationStartsListener() { @Override @@ -353,158 +400,182 @@ public class Jsprit { worst.setNoiseMaker(new NoiseMaker() { public double makeNoise() { - if(random.nextDouble() < toDouble(getProperty(Parameter.RUIN_WORST_NOISE_PROB.toString()))) { + if (random.nextDouble() < toDouble(getProperty(Parameter.RUIN_WORST_NOISE_PROB.toString()))) { return toDouble(getProperty(Parameter.RUIN_WORST_NOISE_LEVEL.toString())) - * noiseMaker.maxCosts * random.nextDouble(); - } - else return 0.; + * maxCosts * random.nextDouble(); + } else return 0.; } }); } }; - final RuinClusters clusters = new RuinClusters(vrp,(int) (vrp.getJobs().values().size()*0.5),jobNeighborhoods); + final RuinClusters clusters = new RuinClusters(vrp, (int) (vrp.getJobs().values().size() * 0.5), jobNeighborhoods); clusters.setRandom(random); clusters.setRuinShareFactory(new RuinShareFactoryImpl( - toInteger(properties.getProperty(Parameter.WORST_MIN_SHARE.toString())), - toInteger(properties.getProperty(Parameter.WORST_MAX_SHARE.toString())), - random) + toInteger(properties.getProperty(Parameter.WORST_MIN_SHARE.toString())), + toInteger(properties.getProperty(Parameter.WORST_MAX_SHARE.toString())), + random) ); AbstractInsertionStrategy regret; - final RegretInsertion.DefaultScorer scorer; - if(noThreads == null){ - noThreads = toInteger(getProperty(Parameter.THREADS.toString())); - } - if(noThreads > 1){ - if(es == null){ - setupExecutorInternally = true; - es = Executors.newFixedThreadPool(noThreads); + final DefaultScorer scorer; + + boolean fastRegret = Boolean.parseBoolean(getProperty(Parameter.FAST_REGRET.toString())); + if (es != null) { + if(fastRegret){ + RegretInsertionConcurrentFast regretInsertion = (RegretInsertionConcurrentFast) new InsertionBuilder(vrp, fm, stateManager, constraintManager) + .setInsertionStrategy(InsertionBuilder.Strategy.REGRET) + .setConcurrentMode(es, noThreads) + .setFastRegret(true) + .considerFixedCosts(toDouble(getProperty(Parameter.FIXED_COST_PARAM.toString()))) + .setAllowVehicleSwitch(toBoolean(getProperty(Parameter.VEHICLE_SWITCH.toString()))) + .setActivityInsertionCostCalculator(activityInsertion) + .build(); + scorer = getRegretScorer(vrp); + regretInsertion.setScoringFunction(scorer); + regret = regretInsertion; } - } - if(es != null) { - RegretInsertionConcurrent regretInsertion = (RegretInsertionConcurrent) new InsertionBuilder(vrp, fm, stateManager, constraintManager) + else { + RegretInsertionConcurrent regretInsertion = (RegretInsertionConcurrent) new InsertionBuilder(vrp, fm, stateManager, constraintManager) .setInsertionStrategy(InsertionBuilder.Strategy.REGRET) .setConcurrentMode(es, noThreads) .considerFixedCosts(toDouble(getProperty(Parameter.FIXED_COST_PARAM.toString()))) .setAllowVehicleSwitch(toBoolean(getProperty(Parameter.VEHICLE_SWITCH.toString()))) + .setActivityInsertionCostCalculator(activityInsertion) .build(); - scorer = getRegretScorer(vrp); - regretInsertion.setScoringFunction(scorer); - regret = regretInsertion; - } - else { - RegretInsertion regretInsertion = (RegretInsertion) new InsertionBuilder(vrp, fm, stateManager, constraintManager) + scorer = getRegretScorer(vrp); + regretInsertion.setScoringFunction(scorer); + regret = regretInsertion; + } + } else { + if(fastRegret) { + RegretInsertionFast regretInsertion = (RegretInsertionFast) new InsertionBuilder(vrp, fm, stateManager, constraintManager) + .setInsertionStrategy(InsertionBuilder.Strategy.REGRET) + .setFastRegret(true) + .setAllowVehicleSwitch(toBoolean(getProperty(Parameter.VEHICLE_SWITCH.toString()))) + .considerFixedCosts(toDouble(getProperty(Parameter.FIXED_COST_PARAM.toString()))) + .setActivityInsertionCostCalculator(activityInsertion) + .build(); + scorer = getRegretScorer(vrp); + regretInsertion.setScoringFunction(scorer); + regret = regretInsertion; + } + else{ + RegretInsertion regretInsertion = (RegretInsertion) new InsertionBuilder(vrp, fm, stateManager, constraintManager) .setInsertionStrategy(InsertionBuilder.Strategy.REGRET) .setAllowVehicleSwitch(toBoolean(getProperty(Parameter.VEHICLE_SWITCH.toString()))) .considerFixedCosts(toDouble(getProperty(Parameter.FIXED_COST_PARAM.toString()))) + .setActivityInsertionCostCalculator(activityInsertion) .build(); - scorer = getRegretScorer(vrp); - regretInsertion.setScoringFunction(scorer); - regret = regretInsertion; + scorer = getRegretScorer(vrp); + regretInsertion.setScoringFunction(scorer); + regret = regretInsertion; + } } regret.setRandom(random); AbstractInsertionStrategy best; - if(vrp.getJobs().size() < 250 || es == null) { + if (vrp.getJobs().size() < 250 || es == null) { BestInsertion bestInsertion = (BestInsertion) new InsertionBuilder(vrp, fm, stateManager, constraintManager) - .setInsertionStrategy(InsertionBuilder.Strategy.BEST) - .considerFixedCosts(Double.valueOf(properties.getProperty(Parameter.FIXED_COST_PARAM.toString()))) - .setAllowVehicleSwitch(toBoolean(getProperty(Parameter.VEHICLE_SWITCH.toString()))) - .build(); + .setInsertionStrategy(InsertionBuilder.Strategy.BEST) + .considerFixedCosts(Double.valueOf(properties.getProperty(Parameter.FIXED_COST_PARAM.toString()))) + .setAllowVehicleSwitch(toBoolean(getProperty(Parameter.VEHICLE_SWITCH.toString()))) + .setActivityInsertionCostCalculator(activityInsertion) + .build(); best = bestInsertion; - } - else{ + } else { BestInsertionConcurrent bestInsertion = (BestInsertionConcurrent) new InsertionBuilder(vrp, fm, stateManager, constraintManager) - .setInsertionStrategy(InsertionBuilder.Strategy.BEST) - .considerFixedCosts(Double.valueOf(properties.getProperty(Parameter.FIXED_COST_PARAM.toString()))) - .setAllowVehicleSwitch(toBoolean(getProperty(Parameter.VEHICLE_SWITCH.toString()))) - .setConcurrentMode(es, noThreads) - .build(); + .setInsertionStrategy(InsertionBuilder.Strategy.BEST) + .considerFixedCosts(Double.valueOf(properties.getProperty(Parameter.FIXED_COST_PARAM.toString()))) + .setAllowVehicleSwitch(toBoolean(getProperty(Parameter.VEHICLE_SWITCH.toString()))) + .setConcurrentMode(es, noThreads) + .setActivityInsertionCostCalculator(activityInsertion) + .build(); best = bestInsertion; } best.setRandom(random); - final SchrimpfAcceptance schrimpfAcceptance = new SchrimpfAcceptance(1,toDouble(getProperty(Parameter.THRESHOLD_ALPHA.toString()))); + final SchrimpfAcceptance schrimpfAcceptance = new SchrimpfAcceptance(1, toDouble(getProperty(Parameter.THRESHOLD_ALPHA.toString()))); IterationStartsListener schrimpfThreshold = new IterationStartsListener() { @Override public void informIterationStarts(int i, VehicleRoutingProblem problem, Collection solutions) { - if(i == 1){ + if (i == 1) { double initialThreshold = Solutions.bestOf(solutions).getCost() * toDouble(getProperty(Parameter.THRESHOLD_INI.toString())); schrimpfAcceptance.setInitialThreshold(initialThreshold); } } }; - SolutionCostCalculator objectiveFunction = getObjectiveFunction(vrp, noiseMaker.maxCosts); - SearchStrategy radial_regret = new SearchStrategy(Strategy.RADIAL_REGRET.toString(),new SelectBest(),schrimpfAcceptance, objectiveFunction); + SolutionCostCalculator objectiveFunction = getObjectiveFunction(vrp, maxCosts); + SearchStrategy radial_regret = new SearchStrategy(Strategy.RADIAL_REGRET.toString(), new SelectBest(), schrimpfAcceptance, objectiveFunction); radial_regret.addModule(new RuinAndRecreateModule(Strategy.RADIAL_REGRET.toString(), regret, radial)); - SearchStrategy radial_best = new SearchStrategy(Strategy.RADIAL_BEST.toString(),new SelectBest(),schrimpfAcceptance,objectiveFunction); - radial_best.addModule(new RuinAndRecreateModule(Strategy.RADIAL_BEST.toString(),best,radial)); + SearchStrategy radial_best = new SearchStrategy(Strategy.RADIAL_BEST.toString(), new SelectBest(), schrimpfAcceptance, objectiveFunction); + radial_best.addModule(new RuinAndRecreateModule(Strategy.RADIAL_BEST.toString(), best, radial)); - SearchStrategy random_best = new SearchStrategy(Strategy.RANDOM_BEST.toString(),new SelectBest(),schrimpfAcceptance,objectiveFunction); - random_best.addModule(new RuinAndRecreateModule(Strategy.RANDOM_BEST.toString(),best,random_for_best)); + SearchStrategy random_best = new SearchStrategy(Strategy.RANDOM_BEST.toString(), new SelectBest(), schrimpfAcceptance, objectiveFunction); + random_best.addModule(new RuinAndRecreateModule(Strategy.RANDOM_BEST.toString(), best, random_for_best)); - SearchStrategy random_regret = new SearchStrategy(Strategy.RANDOM_REGRET.toString(),new SelectBest(),schrimpfAcceptance,objectiveFunction); - random_regret.addModule(new RuinAndRecreateModule(Strategy.RANDOM_REGRET.toString(),regret,random_for_regret)); + SearchStrategy random_regret = new SearchStrategy(Strategy.RANDOM_REGRET.toString(), new SelectBest(), schrimpfAcceptance, objectiveFunction); + random_regret.addModule(new RuinAndRecreateModule(Strategy.RANDOM_REGRET.toString(), regret, random_for_regret)); - SearchStrategy worst_regret = new SearchStrategy(Strategy.WORST_REGRET.toString(),new SelectBest(),schrimpfAcceptance,objectiveFunction); - worst_regret.addModule(new RuinAndRecreateModule(Strategy.WORST_REGRET.toString(),regret,worst)); + SearchStrategy worst_regret = new SearchStrategy(Strategy.WORST_REGRET.toString(), new SelectBest(), schrimpfAcceptance, objectiveFunction); + worst_regret.addModule(new RuinAndRecreateModule(Strategy.WORST_REGRET.toString(), regret, worst)); - SearchStrategy worst_best = new SearchStrategy(Strategy.WORST_BEST.toString(),new SelectBest(),schrimpfAcceptance,objectiveFunction); - worst_best.addModule(new RuinAndRecreateModule(Strategy.WORST_BEST.toString(),best,worst)); + SearchStrategy worst_best = new SearchStrategy(Strategy.WORST_BEST.toString(), new SelectBest(), schrimpfAcceptance, objectiveFunction); + worst_best.addModule(new RuinAndRecreateModule(Strategy.WORST_BEST.toString(), best, worst)); - final SearchStrategy clusters_regret = new SearchStrategy(Strategy.CLUSTER_REGRET.toString(),new SelectBest(),schrimpfAcceptance,objectiveFunction); - clusters_regret.addModule(new RuinAndRecreateModule(Strategy.CLUSTER_REGRET.toString(),regret,clusters)); + final SearchStrategy clusters_regret = new SearchStrategy(Strategy.CLUSTER_REGRET.toString(), new SelectBest(), schrimpfAcceptance, objectiveFunction); + clusters_regret.addModule(new RuinAndRecreateModule(Strategy.CLUSTER_REGRET.toString(), regret, clusters)); - final SearchStrategy clusters_best = new SearchStrategy(Strategy.CLUSTER_BEST.toString(),new SelectBest(),schrimpfAcceptance,objectiveFunction); - clusters_best.addModule(new RuinAndRecreateModule(Strategy.CLUSTER_BEST.toString(),best,clusters)); + final SearchStrategy clusters_best = new SearchStrategy(Strategy.CLUSTER_BEST.toString(), new SelectBest(), schrimpfAcceptance, objectiveFunction); + clusters_best.addModule(new RuinAndRecreateModule(Strategy.CLUSTER_BEST.toString(), best, clusters)); - PrettyAlgorithmBuilder prettyBuilder = PrettyAlgorithmBuilder.newInstance(vrp, fm, stateManager, constraintManager); + PrettyAlgorithmBuilder prettyBuilder = PrettyAlgorithmBuilder.newInstance(vrp, fm, stateManager, constraintManager); prettyBuilder.setRandom(random); - if(addCoreConstraints){ + if (addCoreConstraints) { prettyBuilder.addCoreStateAndConstraintStuff(); } prettyBuilder.withStrategy(radial_regret, toDouble(getProperty(Strategy.RADIAL_REGRET.toString()))) - .withStrategy(radial_best, toDouble(getProperty(Strategy.RADIAL_BEST.toString()))) - .withStrategy(random_best, toDouble(getProperty(Strategy.RANDOM_BEST.toString()))) - .withStrategy(random_regret, toDouble(getProperty(Strategy.RANDOM_REGRET.toString()))) - .withStrategy(worst_best, toDouble(getProperty(Strategy.WORST_BEST.toString()))) - .withStrategy(worst_regret, toDouble(getProperty(Strategy.WORST_REGRET.toString()))) - .withStrategy(clusters_regret,toDouble(getProperty(Strategy.CLUSTER_REGRET.toString()))) - .withStrategy(clusters_best,toDouble(getProperty(Strategy.CLUSTER_BEST.toString()))); - if (getProperty(Parameter.CONSTRUCTION.toString()).equals(Construction.BEST_INSERTION.toString())){ + .withStrategy(radial_best, toDouble(getProperty(Strategy.RADIAL_BEST.toString()))) + .withStrategy(random_best, toDouble(getProperty(Strategy.RANDOM_BEST.toString()))) + .withStrategy(random_regret, toDouble(getProperty(Strategy.RANDOM_REGRET.toString()))) + .withStrategy(worst_best, toDouble(getProperty(Strategy.WORST_BEST.toString()))) + .withStrategy(worst_regret, toDouble(getProperty(Strategy.WORST_REGRET.toString()))) + .withStrategy(clusters_regret, toDouble(getProperty(Strategy.CLUSTER_REGRET.toString()))) + .withStrategy(clusters_best, toDouble(getProperty(Strategy.CLUSTER_BEST.toString()))); + if (getProperty(Parameter.CONSTRUCTION.toString()).equals(Construction.BEST_INSERTION.toString())) { prettyBuilder.constructInitialSolutionWith(best, objectiveFunction); - } - else{ + } else { prettyBuilder.constructInitialSolutionWith(regret, objectiveFunction); } VehicleRoutingAlgorithm vra = prettyBuilder.build(); vra.addListener(schrimpfThreshold); - vra.addListener(noiseMaker); + vra.addListener(noiseConfigurator); vra.addListener(noise); vra.addListener(clusters); + vra.addListener(new RuinBreaks()); handleExecutorShutdown(vra); vra.setMaxIterations(Integer.valueOf(properties.getProperty(Parameter.ITERATIONS.toString()))); + return vra; } - private RegretInsertion.DefaultScorer getRegretScorer(VehicleRoutingProblem vrp) { - RegretInsertion.DefaultScorer scorer; - scorer = new RegretInsertion.DefaultScorer(vrp); + private DefaultScorer getRegretScorer(VehicleRoutingProblem vrp) { + DefaultScorer scorer; + scorer = new DefaultScorer(vrp); scorer.setTimeWindowParam(Double.valueOf(properties.getProperty(Parameter.REGRET_TIME_WINDOW_SCORER.toString()))); - scorer.setDepotDistanceParam(Double.valueOf(properties.getProperty(Parameter.REGRET_TIME_WINDOW_SCORER.toString()))); + scorer.setDepotDistanceParam(Double.valueOf(properties.getProperty(Parameter.REGRET_DISTANCE_SCORER.toString()))); return scorer; } private void handleExecutorShutdown(VehicleRoutingAlgorithm vra) { - if(setupExecutorInternally){ + if (setupExecutorInternally) { vra.addListener(new AlgorithmEndsListener() { @Override @@ -514,7 +585,7 @@ public class Jsprit { }); } - if(es != null) { + if (es != null) { Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { if (!es.isShutdown()) { @@ -526,7 +597,7 @@ public class Jsprit { } } - String getProperty(String key){ + String getProperty(String key) { return properties.getProperty(key); } @@ -543,20 +614,34 @@ public class Jsprit { } private SolutionCostCalculator getObjectiveFunction(final VehicleRoutingProblem vrp, final double maxCosts) { - if(objectiveFunction != null) return objectiveFunction; + if (objectiveFunction != null) return objectiveFunction; SolutionCostCalculator solutionCostCalculator = new SolutionCostCalculator() { @Override public double getCosts(VehicleRoutingProblemSolution solution) { double costs = 0.; - for(VehicleRoute route : solution.getRoutes()){ + + for (VehicleRoute route : solution.getRoutes()) { costs += route.getVehicle().getType().getVehicleCostParams().fix; + boolean hasBreak = false; TourActivity prevAct = route.getStart(); - for(TourActivity act : route.getActivities()){ - costs += vrp.getTransportCosts().getTransportCost(prevAct.getLocation(),act.getLocation(),prevAct.getEndTime(),route.getDriver(),route.getVehicle()); + for (TourActivity act : route.getActivities()) { + if (act instanceof BreakActivity) hasBreak = true; + costs += vrp.getTransportCosts().getTransportCost(prevAct.getLocation(), act.getLocation(), prevAct.getEndTime(), route.getDriver(), route.getVehicle()); + costs += vrp.getActivityCosts().getActivityCost(act, act.getArrTime(), route.getDriver(), route.getVehicle()); prevAct = act; } - costs += vrp.getTransportCosts().getTransportCost(prevAct.getLocation(),route.getEnd().getLocation(),prevAct.getEndTime(),route.getDriver(),route.getVehicle()); + costs += vrp.getTransportCosts().getTransportCost(prevAct.getLocation(), route.getEnd().getLocation(), prevAct.getEndTime(), route.getDriver(), route.getVehicle()); + if (route.getVehicle().getBreak() != null) { + if (!hasBreak) { + //break defined and required but not assigned penalty + if (route.getEnd().getArrTime() > route.getVehicle().getBreak().getTimeWindow().getEnd()) { + costs += maxCosts * 2 + route.getVehicle().getBreak().getServiceDuration() * route.getVehicle().getType().getVehicleCostParams().perServiceTimeUnit; + } else { + costs -= maxCosts * 2; + } + } + } } costs += solution.getUnassignedJobs().size() * maxCosts * 2; return costs; @@ -565,4 +650,5 @@ public class Jsprit { return solutionCostCalculator; } + } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/box/SchrimpfFactory.java b/jsprit-core/src/main/java/jsprit/core/algorithm/box/SchrimpfFactory.java index 7d0c3aa1..e02d1dc1 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/box/SchrimpfFactory.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/box/SchrimpfFactory.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.box; @@ -26,41 +26,38 @@ import jsprit.core.util.Resource; import java.net.URL; - /** * Factory that creates the {@link VehicleRoutingAlgorithm} as proposed by Schrimpf et al., 2000 with the following parameters: - * - *

+ *

+ *

* R&R_random (prob=0.5, F=0.5); * R&R_radial (prob=0.5, F=0.3); * threshold-accepting with exponentialDecayFunction (alpha=0.1, warmup-iterations=100); * nuOfIterations=2000 - * - *

Gerhard Schrimpf, Johannes Schneider, Hermann Stamm- Wilbrandt, and Gunter Dueck. - * Record breaking optimization results using the ruin and recreate principle. - * Journal of Computational Physics, 159(2):139 – 171, 2000. ISSN 0021-9991. doi: 10.1006/jcph.1999. 6413. + *

+ *

Gerhard Schrimpf, Johannes Schneider, Hermann Stamm- Wilbrandt, and Gunter Dueck. + * Record breaking optimization results using the ruin and recreate principle. + * Journal of Computational Physics, 159(2):139 – 171, 2000. ISSN 0021-9991. doi: 10.1006/jcph.1999. 6413. * URL http://www.sciencedirect.com/science/article/ pii/S0021999199964136 - * - *

algorithm-xml-config is available at src/main/resources/schrimpf.xml. - * - * @author stefan schroeder + *

+ *

algorithm-xml-config is available at src/main/resources/schrimpf.xml. * + * @author stefan schroeder */ public class SchrimpfFactory { - - /** - * Creates the {@link VehicleRoutingAlgorithm}. - * - * @param vrp the underlying vehicle routing problem - * @return algorithm - */ - public VehicleRoutingAlgorithm createAlgorithm(VehicleRoutingProblem vrp){ - AlgorithmConfig algorithmConfig = new AlgorithmConfig(); - URL resource = Resource.getAsURL("schrimpf.xml"); - new AlgorithmConfigXmlReader(algorithmConfig).read(resource); - return VehicleRoutingAlgorithms.createAlgorithm(vrp, algorithmConfig); - } - - + + /** + * Creates the {@link VehicleRoutingAlgorithm}. + * + * @param vrp the underlying vehicle routing problem + * @return algorithm + */ + public VehicleRoutingAlgorithm createAlgorithm(VehicleRoutingProblem vrp) { + AlgorithmConfig algorithmConfig = new AlgorithmConfig(); + URL resource = Resource.getAsURL("schrimpf.xml"); + new AlgorithmConfigXmlReader(algorithmConfig).read(resource); + return VehicleRoutingAlgorithms.createAlgorithm(vrp, algorithmConfig); + } + } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/io/AlgorithmConfig.java b/jsprit-core/src/main/java/jsprit/core/algorithm/io/AlgorithmConfig.java index 1fa3f1c1..086d6751 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/io/AlgorithmConfig.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/io/AlgorithmConfig.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.io; @@ -19,15 +19,15 @@ package jsprit.core.algorithm.io; import org.apache.commons.configuration.XMLConfiguration; public class AlgorithmConfig { - - private XMLConfiguration xmlConfig; - - public AlgorithmConfig(){ - xmlConfig = new XMLConfiguration(); - - } - public XMLConfiguration getXMLConfiguration(){ - return xmlConfig; - } + private XMLConfiguration xmlConfig; + + public AlgorithmConfig() { + xmlConfig = new XMLConfiguration(); + + } + + public XMLConfiguration getXMLConfiguration() { + return xmlConfig; + } } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/io/AlgorithmConfigXmlReader.java b/jsprit-core/src/main/java/jsprit/core/algorithm/io/AlgorithmConfigXmlReader.java index 3c6098db..47c536df 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/io/AlgorithmConfigXmlReader.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/io/AlgorithmConfigXmlReader.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.io; @@ -30,65 +30,62 @@ import java.net.URL; public class AlgorithmConfigXmlReader { - - private static Logger log = LogManager.getLogger(AlgorithmConfigXmlReader.class.getName()); - - private AlgorithmConfig algorithmConfig; - - private boolean schemaValidation = true; - - /** - * @param schemaValidation the schemaValidation to set - */ - public AlgorithmConfigXmlReader setSchemaValidation(boolean schemaValidation) { - this.schemaValidation = schemaValidation; - return this; - } - public AlgorithmConfigXmlReader(AlgorithmConfig algorithmConfig){ - this.algorithmConfig = algorithmConfig; - } - - public void read(URL url){ - log.debug("read algorithm: " + url); - algorithmConfig.getXMLConfiguration().setURL(url); - algorithmConfig.getXMLConfiguration().setAttributeSplittingDisabled(true); - algorithmConfig.getXMLConfiguration().setDelimiterParsingDisabled(true); - - if(schemaValidation){ - final InputStream resource = Resource.getAsInputStream("algorithm_schema.xsd"); - if(resource != null) { - EntityResolver resolver = new EntityResolver() { + private static Logger log = LogManager.getLogger(AlgorithmConfigXmlReader.class.getName()); - @Override - public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { - { - InputSource is = new InputSource(resource); - return is; - } - } - }; - algorithmConfig.getXMLConfiguration().setEntityResolver(resolver); - algorithmConfig.getXMLConfiguration().setSchemaValidation(true); - } - else{ - log.warn("cannot find schema-xsd file (algorithm_xml_schema.xsd). try to read xml without xml-file-validation."); - } - } - try { - algorithmConfig.getXMLConfiguration().load(); - } catch (ConfigurationException e) { - log.error(e); - e.printStackTrace(); - System.exit(1); - } - } - - - public void read(String filename){ - log.debug("read algorithm-config from file " + filename); - URL url = Resource.getAsURL(filename); - read(url); - } + private AlgorithmConfig algorithmConfig; + + private boolean schemaValidation = true; + + /** + * @param schemaValidation the schemaValidation to set + */ + public AlgorithmConfigXmlReader setSchemaValidation(boolean schemaValidation) { + this.schemaValidation = schemaValidation; + return this; + } + + public AlgorithmConfigXmlReader(AlgorithmConfig algorithmConfig) { + this.algorithmConfig = algorithmConfig; + } + + public void read(URL url) { + log.debug("read algorithm: " + url); + algorithmConfig.getXMLConfiguration().setURL(url); + algorithmConfig.getXMLConfiguration().setAttributeSplittingDisabled(true); + algorithmConfig.getXMLConfiguration().setDelimiterParsingDisabled(true); + + if (schemaValidation) { + final InputStream resource = Resource.getAsInputStream("algorithm_schema.xsd"); + if (resource != null) { + EntityResolver resolver = new EntityResolver() { + + @Override + public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { + { + InputSource is = new InputSource(resource); + return is; + } + } + }; + algorithmConfig.getXMLConfiguration().setEntityResolver(resolver); + algorithmConfig.getXMLConfiguration().setSchemaValidation(true); + } else { + log.warn("cannot find schema-xsd file (algorithm_xml_schema.xsd). try to read xml without xml-file-validation."); + } + } + try { + algorithmConfig.getXMLConfiguration().load(); + } catch (ConfigurationException e) { + throw new RuntimeException(e); + } + } + + + public void read(String filename) { + log.debug("read algorithm-config from file " + filename); + URL url = Resource.getAsURL(filename); + read(url); + } } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/io/InsertionFactory.java b/jsprit-core/src/main/java/jsprit/core/algorithm/io/InsertionFactory.java index 8b44bcb2..3802c803 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/io/InsertionFactory.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/io/InsertionFactory.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.io; @@ -32,85 +32,88 @@ import java.util.concurrent.ExecutorService; class InsertionFactory { - - private static Logger log = LogManager.getLogger(InsertionFactory.class.getName()); - - @SuppressWarnings("deprecation") - public static InsertionStrategy createInsertion(VehicleRoutingProblem vrp, HierarchicalConfiguration config, - VehicleFleetManager vehicleFleetManager, StateManager stateManager, List algorithmListeners, ExecutorService executorService, int nuOfThreads, ConstraintManager constraintManager, boolean addDefaultCostCalculators){ - if(config.containsKey("[@name]")){ - String insertionName = config.getString("[@name]"); - if(!insertionName.equals("bestInsertion") && !insertionName.equals("regretInsertion")){ - throw new IllegalStateException(insertionName + " is not supported. use either \"bestInsertion\" or \"regretInsertion\""); - } + private static Logger log = LogManager.getLogger(InsertionFactory.class.getName()); + + @SuppressWarnings("deprecation") + public static InsertionStrategy createInsertion(VehicleRoutingProblem vrp, HierarchicalConfiguration config, + VehicleFleetManager vehicleFleetManager, StateManager stateManager, List algorithmListeners, ExecutorService executorService, int nuOfThreads, ConstraintManager constraintManager, boolean addDefaultCostCalculators) { + + if (config.containsKey("[@name]")) { + String insertionName = config.getString("[@name]"); + if (!insertionName.equals("bestInsertion") && !insertionName.equals("regretInsertion")) { + throw new IllegalStateException(insertionName + " is not supported. use either \"bestInsertion\" or \"regretInsertion\""); + } InsertionBuilder iBuilder = new InsertionBuilder(vrp, vehicleFleetManager, stateManager, constraintManager); - if(executorService != null){ - iBuilder.setConcurrentMode(executorService, nuOfThreads); - } - - if(config.containsKey("level")){ - String level = config.getString("level"); - if(level.equals("local")){ - iBuilder.setLocalLevel(addDefaultCostCalculators); - } - else if(level.equals("route")){ - int forwardLooking = 0; - int memory = 1; - String forward = config.getString("level[@forwardLooking]"); - String mem = config.getString("level[@memory]"); - if(forward != null) forwardLooking = Integer.parseInt(forward); - else log.warn("parameter route[@forwardLooking] is missing. by default it is 0 which equals to local level"); - if(mem != null) memory = Integer.parseInt(mem); - else log.warn("parameter route[@memory] is missing. by default it is 1"); - iBuilder.setRouteLevel(forwardLooking, memory, addDefaultCostCalculators); - } - else throw new IllegalStateException("level " + level + " is not known. currently it only knows \"local\" or \"route\""); - } - else iBuilder.setLocalLevel(addDefaultCostCalculators); - - if(config.containsKey("considerFixedCosts") || config.containsKey("considerFixedCost")){ - if(addDefaultCostCalculators){ - String val = config.getString("considerFixedCosts"); - if(val == null) val = config.getString("considerFixedCost"); - if(val.equals("true")){ - double fixedCostWeight = 0.5; - String weight = config.getString("considerFixedCosts[@weight]"); - if(weight == null) weight = config.getString("considerFixedCost[@weight]"); - if(weight != null) fixedCostWeight = Double.parseDouble(weight); - else throw new IllegalStateException("fixedCostsParameter 'weight' must be set, e.g. true.\n" + - "this has to be changed in algorithm-config-xml-file."); - iBuilder.considerFixedCosts(fixedCostWeight); - } - else if(val.equals("false")){ - - } - else throw new IllegalStateException("considerFixedCosts must either be true or false, i.e. true or \nfalse. " + - "if latter, you can also omit the tag. this has to be changed in algorithm-config-xml-file"); - } - } - String timeSliceString = config.getString("experimental[@timeSlice]"); - String neighbors = config.getString("experimental[@neighboringSlices]"); - if(timeSliceString != null && neighbors != null){ - iBuilder.experimentalTimeScheduler(Double.parseDouble(timeSliceString),Integer.parseInt(neighbors)); - } - String allowVehicleSwitch = config.getString("allowVehicleSwitch"); - if(allowVehicleSwitch != null){ - iBuilder.setAllowVehicleSwitch(Boolean.parseBoolean(allowVehicleSwitch)); - } - - if(insertionName.equals("regretInsertion")){ - iBuilder.setInsertionStrategy(InsertionBuilder.Strategy.REGRET); + if (executorService != null) { + iBuilder.setConcurrentMode(executorService, nuOfThreads); } - return iBuilder.build(); - } - else throw new IllegalStateException("cannot create insertionStrategy, since it has no name."); - } - + if (config.containsKey("level")) { + String level = config.getString("level"); + if (level.equals("local")) { + iBuilder.setLocalLevel(addDefaultCostCalculators); + } else if (level.equals("route")) { + int forwardLooking = 0; + int memory = 1; + String forward = config.getString("level[@forwardLooking]"); + String mem = config.getString("level[@memory]"); + if (forward != null) forwardLooking = Integer.parseInt(forward); + else + log.warn("parameter route[@forwardLooking] is missing. by default it is 0 which equals to local level"); + if (mem != null) memory = Integer.parseInt(mem); + else log.warn("parameter route[@memory] is missing. by default it is 1"); + iBuilder.setRouteLevel(forwardLooking, memory, addDefaultCostCalculators); + } else + throw new IllegalStateException("level " + level + " is not known. currently it only knows \"local\" or \"route\""); + } else iBuilder.setLocalLevel(addDefaultCostCalculators); + + if (config.containsKey("considerFixedCosts") || config.containsKey("considerFixedCost")) { + if (addDefaultCostCalculators) { + String val = config.getString("considerFixedCosts"); + if (val == null) val = config.getString("considerFixedCost"); + if (val.equals("true")) { + double fixedCostWeight = 0.5; + String weight = config.getString("considerFixedCosts[@weight]"); + if (weight == null) weight = config.getString("considerFixedCost[@weight]"); + if (weight != null) fixedCostWeight = Double.parseDouble(weight); + else + throw new IllegalStateException("fixedCostsParameter 'weight' must be set, e.g. true.\n" + + "this has to be changed in algorithm-config-xml-file."); + iBuilder.considerFixedCosts(fixedCostWeight); + } else if (val.equals("false")) { + + } else + throw new IllegalStateException("considerFixedCosts must either be true or false, i.e. true or \nfalse. " + + "if latter, you can also omit the tag. this has to be changed in algorithm-config-xml-file"); + } + } + String timeSliceString = config.getString("experimental[@timeSlice]"); + String neighbors = config.getString("experimental[@neighboringSlices]"); + if (timeSliceString != null && neighbors != null) { + iBuilder.experimentalTimeScheduler(Double.parseDouble(timeSliceString), Integer.parseInt(neighbors)); + } + String allowVehicleSwitch = config.getString("allowVehicleSwitch"); + if (allowVehicleSwitch != null) { + iBuilder.setAllowVehicleSwitch(Boolean.parseBoolean(allowVehicleSwitch)); + } + + if (insertionName.equals("regretInsertion")) { + iBuilder.setInsertionStrategy(InsertionBuilder.Strategy.REGRET); + + String fastRegret = config.getString("fastRegret"); + if (fastRegret != null) { + iBuilder.setFastRegret(Boolean.parseBoolean(fastRegret)); + } + } + return iBuilder.build(); + } else throw new IllegalStateException("cannot create insertionStrategy, since it has no name."); + } + + } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/io/VehicleRoutingAlgorithms.java b/jsprit-core/src/main/java/jsprit/core/algorithm/io/VehicleRoutingAlgorithms.java index 52a9aa9c..f0ea52a3 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/io/VehicleRoutingAlgorithms.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/io/VehicleRoutingAlgorithms.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.io; @@ -42,6 +42,7 @@ import jsprit.core.algorithm.termination.VariationCoefficientTermination; import jsprit.core.problem.VehicleRoutingProblem; import jsprit.core.problem.VehicleRoutingProblem.FleetSize; import jsprit.core.problem.constraint.ConstraintManager; +import jsprit.core.problem.constraint.SwitchNotFeasible; import jsprit.core.problem.solution.SolutionCostCalculator; import jsprit.core.problem.solution.VehicleRoutingProblemSolution; import jsprit.core.problem.solution.route.VehicleRoute; @@ -62,614 +63,611 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; public class VehicleRoutingAlgorithms { - - static class TypedMap { - - static interface AbstractKey { - - Class getType(); - } - - static class AcceptorKey implements AbstractKey{ - private ModKey modKey; - - public AcceptorKey(ModKey modKey) { - super(); - this.modKey = modKey; - } + static class TypedMap { - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result - + ((modKey == null) ? 0 : modKey.hashCode()); - return result; - } + static interface AbstractKey { + + Class getType(); + } + + static class AcceptorKey implements AbstractKey { + + private ModKey modKey; + + public AcceptorKey(ModKey modKey) { + super(); + this.modKey = modKey; + } - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (!(obj instanceof AcceptorKey)) - return false; - AcceptorKey other = (AcceptorKey) obj; - if (modKey == null) { - if (other.modKey != null) - return false; - } else if (!modKey.equals(other.modKey)) - return false; - return true; - } + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + + ((modKey == null) ? 0 : modKey.hashCode()); + return result; + } - @Override - public Class getType() { - return SolutionAcceptor.class; - } - - } - - static class SelectorKey implements AbstractKey{ - - private ModKey modKey; - - public SelectorKey(ModKey modKey) { - super(); - this.modKey = modKey; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result - + ((modKey == null) ? 0 : modKey.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - SelectorKey other = (SelectorKey) obj; - if (modKey == null) { - if (other.modKey != null) - return false; - } else if (!modKey.equals(other.modKey)) - return false; - return true; - } + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (!(obj instanceof AcceptorKey)) + return false; + AcceptorKey other = (AcceptorKey) obj; + if (modKey == null) { + if (other.modKey != null) + return false; + } else if (!modKey.equals(other.modKey)) + return false; + return true; + } + @Override + public Class getType() { + return SolutionAcceptor.class; + } - @Override - public Class getType() { - return SolutionSelector.class; - } - - } - - static class StrategyModuleKey implements AbstractKey{ + } - private ModKey modKey; - - public StrategyModuleKey(ModKey modKey) { - super(); - this.modKey = modKey; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result - + ((modKey == null) ? 0 : modKey.hashCode()); - return result; - } + static class SelectorKey implements AbstractKey { - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - StrategyModuleKey other = (StrategyModuleKey) obj; - if (modKey == null) { - if (other.modKey != null) - return false; - } else if (!modKey.equals(other.modKey)) - return false; - return true; - } + private ModKey modKey; + + public SelectorKey(ModKey modKey) { + super(); + this.modKey = modKey; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + + ((modKey == null) ? 0 : modKey.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + SelectorKey other = (SelectorKey) obj; + if (modKey == null) { + if (other.modKey != null) + return false; + } else if (!modKey.equals(other.modKey)) + return false; + return true; + } + @Override + public Class getType() { + return SolutionSelector.class; + } - @Override - public Class getType() { - return SearchStrategyModule.class; - } - - } - - static class RuinStrategyKey implements AbstractKey{ + } - private ModKey modKey; - - public RuinStrategyKey(ModKey modKey) { - super(); - this.modKey = modKey; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result - + ((modKey == null) ? 0 : modKey.hashCode()); - return result; - } + static class StrategyModuleKey implements AbstractKey { - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - RuinStrategyKey other = (RuinStrategyKey) obj; - if (modKey == null) { - if (other.modKey != null) - return false; - } else if (!modKey.equals(other.modKey)) - return false; - return true; - } + private ModKey modKey; + + public StrategyModuleKey(ModKey modKey) { + super(); + this.modKey = modKey; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + + ((modKey == null) ? 0 : modKey.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + StrategyModuleKey other = (StrategyModuleKey) obj; + if (modKey == null) { + if (other.modKey != null) + return false; + } else if (!modKey.equals(other.modKey)) + return false; + return true; + } + @Override + public Class getType() { + return SearchStrategyModule.class; + } - @Override - public Class getType() { - return RuinStrategy.class; - } - - } + } - static class InsertionStrategyKey implements AbstractKey{ + static class RuinStrategyKey implements AbstractKey { - private ModKey modKey; - - public InsertionStrategyKey(ModKey modKey) { - super(); - this.modKey = modKey; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result - + ((modKey == null) ? 0 : modKey.hashCode()); - return result; - } + private ModKey modKey; - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - InsertionStrategyKey other = (InsertionStrategyKey) obj; - if (modKey == null) { - if (other.modKey != null) - return false; - } else if (!modKey.equals(other.modKey)) - return false; - return true; - } + public RuinStrategyKey(ModKey modKey) { + super(); + this.modKey = modKey; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + + ((modKey == null) ? 0 : modKey.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + RuinStrategyKey other = (RuinStrategyKey) obj; + if (modKey == null) { + if (other.modKey != null) + return false; + } else if (!modKey.equals(other.modKey)) + return false; + return true; + } + @Override + public Class getType() { + return RuinStrategy.class; + } - @Override - public Class getType() { - return InsertionStrategy.class; - } - - } - - private Map, Object> map = new HashMap, Object>(); + } - public T get(AbstractKey key) { - if(map.get(key) == null) return null; - return key.getType().cast(map.get(key)); - } + static class InsertionStrategyKey implements AbstractKey { - public T put(AbstractKey key, T value) { - return key.getType().cast(map.put(key, key.getType().cast(value))); - } - - public Set> keySet(){ - return map.keySet(); - } - } - - static class ModKey { - private String name; - private String id; - - public ModKey(String name, String id) { - super(); - this.name = name; - this.id = id; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((id == null) ? 0 : id.hashCode()); - result = prime * result + ((name == null) ? 0 : name.hashCode()); - return result; - } - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - ModKey other = (ModKey) obj; - if (id == null) { - if (other.id != null) - return false; - } else if (!id.equals(other.id)) - return false; - if (name == null) { - if (other.name != null) - return false; - } else if (!name.equals(other.name)) - return false; - return true; - } - - } - - private static Logger log = LogManager.getLogger(VehicleRoutingAlgorithms.class.getName()); - - private VehicleRoutingAlgorithms(){} - - /** - * Creates a {@link jsprit.core.algorithm.VehicleRoutingAlgorithm} from a AlgorithConfig based on the input vrp. - * - * @param vrp the routing problem - * @param algorithmConfig the algorithm config - * @return {@link jsprit.core.algorithm.VehicleRoutingAlgorithm} - */ - public static VehicleRoutingAlgorithm createAlgorithm(final VehicleRoutingProblem vrp, final AlgorithmConfig algorithmConfig){ - return createAlgo(vrp,algorithmConfig.getXMLConfiguration(),0, null); - } - public static VehicleRoutingAlgorithm createAlgorithm(final VehicleRoutingProblem vrp, int nThreads, final AlgorithmConfig algorithmConfig){ - return createAlgo(vrp,algorithmConfig.getXMLConfiguration(),nThreads, null); - } - - /** - * Read and creates a {@link VehicleRoutingAlgorithm} from an url. - * - * @param vrp the routing problem - * @param configURL config url - * @return {@link jsprit.core.algorithm.VehicleRoutingAlgorithm} - */ - public static VehicleRoutingAlgorithm readAndCreateAlgorithm(final VehicleRoutingProblem vrp, final URL configURL){ - AlgorithmConfig algorithmConfig = new AlgorithmConfig(); - AlgorithmConfigXmlReader xmlReader = new AlgorithmConfigXmlReader(algorithmConfig); - xmlReader.read(configURL); - return createAlgo(vrp,algorithmConfig.getXMLConfiguration(),0, null); - } - public static VehicleRoutingAlgorithm readAndCreateAlgorithm(final VehicleRoutingProblem vrp, int nThreads, final URL configURL){ - AlgorithmConfig algorithmConfig = new AlgorithmConfig(); - AlgorithmConfigXmlReader xmlReader = new AlgorithmConfigXmlReader(algorithmConfig); - xmlReader.read(configURL); - return createAlgo(vrp,algorithmConfig.getXMLConfiguration(),nThreads, null); - } - - /** - * Read and creates {@link jsprit.core.problem.VehicleRoutingProblem} from config-file. - * - * @param vrp the routing problem - * @param configFileName the config filename (and location) - * @return {@link jsprit.core.algorithm.VehicleRoutingAlgorithm} - */ - public static VehicleRoutingAlgorithm readAndCreateAlgorithm(final VehicleRoutingProblem vrp, final String configFileName){ - AlgorithmConfig algorithmConfig = new AlgorithmConfig(); - AlgorithmConfigXmlReader xmlReader = new AlgorithmConfigXmlReader(algorithmConfig); - xmlReader.read(configFileName); - return createAlgo(vrp,algorithmConfig.getXMLConfiguration(),0, null); - } + private ModKey modKey; - public static VehicleRoutingAlgorithm readAndCreateAlgorithm(final VehicleRoutingProblem vrp, final String configFileName, StateManager stateManager){ - AlgorithmConfig algorithmConfig = new AlgorithmConfig(); - AlgorithmConfigXmlReader xmlReader = new AlgorithmConfigXmlReader(algorithmConfig); - xmlReader.read(configFileName); - return createAlgo(vrp,algorithmConfig.getXMLConfiguration(),0, stateManager); - } - - public static VehicleRoutingAlgorithm readAndCreateAlgorithm(final VehicleRoutingProblem vrp, int nThreads, final String configFileName, StateManager stateManager){ - AlgorithmConfig algorithmConfig = new AlgorithmConfig(); - AlgorithmConfigXmlReader xmlReader = new AlgorithmConfigXmlReader(algorithmConfig); - xmlReader.read(configFileName); - return createAlgo(vrp,algorithmConfig.getXMLConfiguration(), nThreads, stateManager); - } - - public static VehicleRoutingAlgorithm readAndCreateAlgorithm(VehicleRoutingProblem vrp, int nThreads, String configFileName) { - AlgorithmConfig algorithmConfig = new AlgorithmConfig(); - AlgorithmConfigXmlReader xmlReader = new AlgorithmConfigXmlReader(algorithmConfig); - xmlReader.read(configFileName); - return createAlgo(vrp,algorithmConfig.getXMLConfiguration(),nThreads, null); - } - - private static class OpenRouteStateVerifier implements StateUpdater, ReverseActivityVisitor{ + public InsertionStrategyKey(ModKey modKey) { + super(); + this.modKey = modKey; + } - private End end; - - private boolean firstAct = true; - - private Vehicle vehicle; - - @Override - public void begin(VehicleRoute route) { - end = route.getEnd(); - vehicle = route.getVehicle(); - } + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + + ((modKey == null) ? 0 : modKey.hashCode()); + return result; + } - @Override - public void visit(TourActivity activity) { - if(firstAct){ - firstAct=false; - if(!vehicle.isReturnToDepot()){ - assert activity.getLocation().getId().equals(end.getLocation().getId()) : "route end and last activity are not equal even route is open. this should not be."; - } - } - - } + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + InsertionStrategyKey other = (InsertionStrategyKey) obj; + if (modKey == null) { + if (other.modKey != null) + return false; + } else if (!modKey.equals(other.modKey)) + return false; + return true; + } - @Override - public void finish() { - firstAct = true; - } - - } - private static VehicleRoutingAlgorithm createAlgo(final VehicleRoutingProblem vrp, XMLConfiguration config, int nuOfThreads, StateManager stateMan){ - //create state-manager - final StateManager stateManager; - if(stateMan!=null) { - stateManager = stateMan; - } - else{ - stateManager = new StateManager(vrp); - } - stateManager.updateLoadStates(); - stateManager.updateTimeWindowStates(); + @Override + public Class getType() { + return InsertionStrategy.class; + } + + } + + private Map, Object> map = new HashMap, Object>(); + + public T get(AbstractKey key) { + if (map.get(key) == null) return null; + return key.getType().cast(map.get(key)); + } + + public T put(AbstractKey key, T value) { + return key.getType().cast(map.put(key, key.getType().cast(value))); + } + + public Set> keySet() { + return map.keySet(); + } + } + + static class ModKey { + private String name; + private String id; + + public ModKey(String name, String id) { + super(); + this.name = name; + this.id = id; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((id == null) ? 0 : id.hashCode()); + result = prime * result + ((name == null) ? 0 : name.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ModKey other = (ModKey) obj; + if (id == null) { + if (other.id != null) + return false; + } else if (!id.equals(other.id)) + return false; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + return true; + } + + } + + private static Logger log = LogManager.getLogger(VehicleRoutingAlgorithms.class.getName()); + + private VehicleRoutingAlgorithms() { + } + + /** + * Creates a {@link jsprit.core.algorithm.VehicleRoutingAlgorithm} from a AlgorithConfig based on the input vrp. + * + * @param vrp the routing problem + * @param algorithmConfig the algorithm config + * @return {@link jsprit.core.algorithm.VehicleRoutingAlgorithm} + */ + public static VehicleRoutingAlgorithm createAlgorithm(final VehicleRoutingProblem vrp, final AlgorithmConfig algorithmConfig) { + return createAlgo(vrp, algorithmConfig.getXMLConfiguration(), 0, null); + } + + public static VehicleRoutingAlgorithm createAlgorithm(final VehicleRoutingProblem vrp, int nThreads, final AlgorithmConfig algorithmConfig) { + return createAlgo(vrp, algorithmConfig.getXMLConfiguration(), nThreads, null); + } + + /** + * Read and creates a {@link VehicleRoutingAlgorithm} from an url. + * + * @param vrp the routing problem + * @param configURL config url + * @return {@link jsprit.core.algorithm.VehicleRoutingAlgorithm} + */ + public static VehicleRoutingAlgorithm readAndCreateAlgorithm(final VehicleRoutingProblem vrp, final URL configURL) { + AlgorithmConfig algorithmConfig = new AlgorithmConfig(); + AlgorithmConfigXmlReader xmlReader = new AlgorithmConfigXmlReader(algorithmConfig); + xmlReader.read(configURL); + return createAlgo(vrp, algorithmConfig.getXMLConfiguration(), 0, null); + } + + public static VehicleRoutingAlgorithm readAndCreateAlgorithm(final VehicleRoutingProblem vrp, int nThreads, final URL configURL) { + AlgorithmConfig algorithmConfig = new AlgorithmConfig(); + AlgorithmConfigXmlReader xmlReader = new AlgorithmConfigXmlReader(algorithmConfig); + xmlReader.read(configURL); + return createAlgo(vrp, algorithmConfig.getXMLConfiguration(), nThreads, null); + } + + /** + * Read and creates {@link jsprit.core.problem.VehicleRoutingProblem} from config-file. + * + * @param vrp the routing problem + * @param configFileName the config filename (and location) + * @return {@link jsprit.core.algorithm.VehicleRoutingAlgorithm} + */ + public static VehicleRoutingAlgorithm readAndCreateAlgorithm(final VehicleRoutingProblem vrp, final String configFileName) { + AlgorithmConfig algorithmConfig = new AlgorithmConfig(); + AlgorithmConfigXmlReader xmlReader = new AlgorithmConfigXmlReader(algorithmConfig); + xmlReader.read(configFileName); + return createAlgo(vrp, algorithmConfig.getXMLConfiguration(), 0, null); + } + + public static VehicleRoutingAlgorithm readAndCreateAlgorithm(final VehicleRoutingProblem vrp, final String configFileName, StateManager stateManager) { + AlgorithmConfig algorithmConfig = new AlgorithmConfig(); + AlgorithmConfigXmlReader xmlReader = new AlgorithmConfigXmlReader(algorithmConfig); + xmlReader.read(configFileName); + return createAlgo(vrp, algorithmConfig.getXMLConfiguration(), 0, stateManager); + } + + public static VehicleRoutingAlgorithm readAndCreateAlgorithm(final VehicleRoutingProblem vrp, int nThreads, final String configFileName, StateManager stateManager) { + AlgorithmConfig algorithmConfig = new AlgorithmConfig(); + AlgorithmConfigXmlReader xmlReader = new AlgorithmConfigXmlReader(algorithmConfig); + xmlReader.read(configFileName); + return createAlgo(vrp, algorithmConfig.getXMLConfiguration(), nThreads, stateManager); + } + + public static VehicleRoutingAlgorithm readAndCreateAlgorithm(VehicleRoutingProblem vrp, int nThreads, String configFileName) { + AlgorithmConfig algorithmConfig = new AlgorithmConfig(); + AlgorithmConfigXmlReader xmlReader = new AlgorithmConfigXmlReader(algorithmConfig); + xmlReader.read(configFileName); + return createAlgo(vrp, algorithmConfig.getXMLConfiguration(), nThreads, null); + } + + private static class OpenRouteStateVerifier implements StateUpdater, ReverseActivityVisitor { + + private End end; + + private boolean firstAct = true; + + private Vehicle vehicle; + + @Override + public void begin(VehicleRoute route) { + end = route.getEnd(); + vehicle = route.getVehicle(); + } + + @Override + public void visit(TourActivity activity) { + if (firstAct) { + firstAct = false; + if (!vehicle.isReturnToDepot()) { + assert activity.getLocation().getId().equals(end.getLocation().getId()) : "route end and last activity are not equal even route is open. this should not be."; + } + } + + } + + @Override + public void finish() { + firstAct = true; + } + + } + + private static VehicleRoutingAlgorithm createAlgo(final VehicleRoutingProblem vrp, XMLConfiguration config, int nuOfThreads, StateManager stateMan) { + //create state-manager + final StateManager stateManager; + if (stateMan != null) { + stateManager = stateMan; + } else { + stateManager = new StateManager(vrp); + } + stateManager.updateLoadStates(); + stateManager.updateTimeWindowStates(); stateManager.updateSkillStates(); - stateManager.addStateUpdater(new UpdateEndLocationIfRouteIsOpen()); - stateManager.addStateUpdater(new OpenRouteStateVerifier()); + stateManager.addStateUpdater(new UpdateEndLocationIfRouteIsOpen()); + stateManager.addStateUpdater(new OpenRouteStateVerifier()); // stateManager.addStateUpdater(new UpdateActivityTimes(vrp.getTransportCosts())); // stateManager.addStateUpdater(new UpdateVariableCosts(vrp.getActivityCosts(), vrp.getTransportCosts(), stateManager)); /* - * define constraints + * define constraints */ - //constraint manager - ConstraintManager constraintManager = new ConstraintManager(vrp,stateManager); - constraintManager.addTimeWindowConstraint(); - constraintManager.addLoadConstraint(); + //constraint manager + ConstraintManager constraintManager = new ConstraintManager(vrp, stateManager); + constraintManager.addTimeWindowConstraint(); + constraintManager.addLoadConstraint(); constraintManager.addSkillsConstraint(); - - return readAndCreateAlgorithm(vrp, config, nuOfThreads, null, stateManager, constraintManager, true); - } + constraintManager.addConstraint(new SwitchNotFeasible(stateManager)); - public static VehicleRoutingAlgorithm readAndCreateAlgorithm(final VehicleRoutingProblem vrp, AlgorithmConfig config, - int nuOfThreads, SolutionCostCalculator solutionCostCalculator, final StateManager stateManager, ConstraintManager constraintManager, boolean addDefaultCostCalculators) { - return readAndCreateAlgorithm(vrp, config.getXMLConfiguration(),nuOfThreads, solutionCostCalculator, stateManager, constraintManager, addDefaultCostCalculators); - } - - private static VehicleRoutingAlgorithm readAndCreateAlgorithm(final VehicleRoutingProblem vrp, XMLConfiguration config, - int nuOfThreads, final SolutionCostCalculator solutionCostCalculator, final StateManager stateManager, ConstraintManager constraintManager, boolean addDefaultCostCalculators) { - // map to store constructed modules - TypedMap definedClasses = new TypedMap(); - - // algorithm listeners - Set algorithmListeners = new HashSet(); - - // insertion listeners - List insertionListeners = new ArrayList(); + return readAndCreateAlgorithm(vrp, config, nuOfThreads, null, stateManager, constraintManager, true); + } + + public static VehicleRoutingAlgorithm readAndCreateAlgorithm(final VehicleRoutingProblem vrp, AlgorithmConfig config, + int nuOfThreads, SolutionCostCalculator solutionCostCalculator, final StateManager stateManager, ConstraintManager constraintManager, boolean addDefaultCostCalculators) { + return readAndCreateAlgorithm(vrp, config.getXMLConfiguration(), nuOfThreads, solutionCostCalculator, stateManager, constraintManager, addDefaultCostCalculators); + } + + private static VehicleRoutingAlgorithm readAndCreateAlgorithm(final VehicleRoutingProblem vrp, XMLConfiguration config, + int nuOfThreads, final SolutionCostCalculator solutionCostCalculator, final StateManager stateManager, ConstraintManager constraintManager, boolean addDefaultCostCalculators) { + // map to store constructed modules + TypedMap definedClasses = new TypedMap(); + + // algorithm listeners + Set algorithmListeners = new HashSet(); + + // insertion listeners + List insertionListeners = new ArrayList(); - //threading - final ExecutorService executorService; - if(nuOfThreads > 0){ - log.debug("setup executor-service with " + nuOfThreads + " threads"); - executorService = Executors.newFixedThreadPool(nuOfThreads); - algorithmListeners.add(new PrioritizedVRAListener(Priority.LOW, new AlgorithmEndsListener() { + //threading + final ExecutorService executorService; + if (nuOfThreads > 0) { + log.debug("setup executor-service with " + nuOfThreads + " threads"); + executorService = Executors.newFixedThreadPool(nuOfThreads); + algorithmListeners.add(new PrioritizedVRAListener(Priority.LOW, new AlgorithmEndsListener() { - @Override - public void informAlgorithmEnds(VehicleRoutingProblem problem,Collection solutions) { - log.debug("shutdown executor-service"); - executorService.shutdown(); - } - })); - Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() { + @Override + public void informAlgorithmEnds(VehicleRoutingProblem problem, Collection solutions) { + log.debug("shutdown executor-service"); + executorService.shutdown(); + } + })); + Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() { - @Override - public void uncaughtException(Thread arg0, Throwable arg1) { - System.err.println(arg1.toString()); - System.exit(0); - } - }); - Runtime.getRuntime().addShutdownHook(new Thread(){ - public void run(){ - if(!executorService.isShutdown()){ - System.err.println("shutdowHook shuts down executorService"); - executorService.shutdown(); - } - } - }); - } - else executorService = null; + @Override + public void uncaughtException(Thread arg0, Throwable arg1) { + System.err.println(arg1.toString()); + } + }); + Runtime.getRuntime().addShutdownHook(new Thread() { + public void run() { + if (!executorService.isShutdown()) { + System.err.println("shutdowHook shuts down executorService"); + executorService.shutdown(); + } + } + }); + } else executorService = null; - //create fleetmanager - final VehicleFleetManager vehicleFleetManager = createFleetManager(vrp); + //create fleetmanager + final VehicleFleetManager vehicleFleetManager = createFleetManager(vrp); String switchString = config.getString("construction.insertion.allowVehicleSwitch"); final boolean switchAllowed; - if(switchString != null){ + if (switchString != null) { switchAllowed = Boolean.parseBoolean(switchString); - } - else switchAllowed = true; + } else switchAllowed = true; ActivityTimeTracker.ActivityPolicy activityPolicy; - if(stateManager.timeWindowUpdateIsActivated()){ - UpdateVehicleDependentPracticalTimeWindows timeWindowUpdater = new UpdateVehicleDependentPracticalTimeWindows(stateManager,vrp.getTransportCosts()); + if (stateManager.timeWindowUpdateIsActivated()) { + UpdateVehicleDependentPracticalTimeWindows timeWindowUpdater = new UpdateVehicleDependentPracticalTimeWindows(stateManager, vrp.getTransportCosts()); timeWindowUpdater.setVehiclesToUpdate(new UpdateVehicleDependentPracticalTimeWindows.VehiclesToUpdate() { - Map uniqueTypes = new HashMap(); + Map uniqueTypes = new HashMap(); - @Override - public Collection get(VehicleRoute vehicleRoute) { - if(uniqueTypes.isEmpty()){ - for( Vehicle v : vrp.getVehicles()){ - if(!uniqueTypes.containsKey(v.getVehicleTypeIdentifier())){ - uniqueTypes.put(v.getVehicleTypeIdentifier(),v); - } - } - } - Collection vehicles = new ArrayList(); - vehicles.addAll(uniqueTypes.values()); - return vehicles; - } + @Override + public Collection get(VehicleRoute vehicleRoute) { + if (uniqueTypes.isEmpty()) { + for (Vehicle v : vrp.getVehicles()) { + if (!uniqueTypes.containsKey(v.getVehicleTypeIdentifier())) { + uniqueTypes.put(v.getVehicleTypeIdentifier(), v); + } + } + } + Collection vehicles = new ArrayList(); + vehicles.addAll(uniqueTypes.values()); + return vehicles; + } }); stateManager.addStateUpdater(timeWindowUpdater); activityPolicy = ActivityTimeTracker.ActivityPolicy.AS_SOON_AS_TIME_WINDOW_OPENS; - } - else{ + } else { activityPolicy = ActivityTimeTracker.ActivityPolicy.AS_SOON_AS_ARRIVED; } - stateManager.addStateUpdater(new UpdateActivityTimes(vrp.getTransportCosts(),activityPolicy)); + stateManager.addStateUpdater(new UpdateActivityTimes(vrp.getTransportCosts(), activityPolicy)); stateManager.addStateUpdater(new UpdateVariableCosts(vrp.getActivityCosts(), vrp.getTransportCosts(), stateManager, activityPolicy)); - final SolutionCostCalculator costCalculator; - if(solutionCostCalculator==null) costCalculator = getDefaultCostCalculator(stateManager); - else costCalculator = solutionCostCalculator; + final SolutionCostCalculator costCalculator; + if (solutionCostCalculator == null) costCalculator = getDefaultCostCalculator(stateManager); + else costCalculator = solutionCostCalculator; - PrettyAlgorithmBuilder prettyAlgorithmBuilder = PrettyAlgorithmBuilder.newInstance(vrp,vehicleFleetManager,stateManager,constraintManager); - //construct initial solution creator - final InsertionStrategy initialInsertionStrategy = createInitialSolution(config,vrp,vehicleFleetManager,stateManager,algorithmListeners,definedClasses,executorService,nuOfThreads,costCalculator, constraintManager, addDefaultCostCalculators); - if(initialInsertionStrategy != null) prettyAlgorithmBuilder.constructInitialSolutionWith(initialInsertionStrategy,costCalculator); + PrettyAlgorithmBuilder prettyAlgorithmBuilder = PrettyAlgorithmBuilder.newInstance(vrp, vehicleFleetManager, stateManager, constraintManager); + //construct initial solution creator + final InsertionStrategy initialInsertionStrategy = createInitialSolution(config, vrp, vehicleFleetManager, stateManager, algorithmListeners, definedClasses, executorService, nuOfThreads, costCalculator, constraintManager, addDefaultCostCalculators); + if (initialInsertionStrategy != null) + prettyAlgorithmBuilder.constructInitialSolutionWith(initialInsertionStrategy, costCalculator); - //construct algorithm, i.e. search-strategies and its modules - int solutionMemory = config.getInt("strategy.memory"); + //construct algorithm, i.e. search-strategies and its modules + int solutionMemory = config.getInt("strategy.memory"); List strategyConfigs = config.configurationsAt("strategy.searchStrategies.searchStrategy"); - for(HierarchicalConfiguration strategyConfig : strategyConfigs){ - String name = getName(strategyConfig); - SolutionAcceptor acceptor = getAcceptor(strategyConfig,vrp,algorithmListeners,definedClasses,solutionMemory); - SolutionSelector selector = getSelector(strategyConfig,vrp,algorithmListeners,definedClasses); - - SearchStrategy strategy = new SearchStrategy(name, selector, acceptor, costCalculator); - strategy.setName(name); - List modulesConfig = strategyConfig.configurationsAt("modules.module"); - for(HierarchicalConfiguration moduleConfig : modulesConfig){ - SearchStrategyModule module = buildModule(moduleConfig,vrp,vehicleFleetManager,stateManager,algorithmListeners,definedClasses,executorService,nuOfThreads, constraintManager, addDefaultCostCalculators); - strategy.addModule(module); - } - prettyAlgorithmBuilder.withStrategy(strategy,strategyConfig.getDouble("probability")); + for (HierarchicalConfiguration strategyConfig : strategyConfigs) { + String name = getName(strategyConfig); + SolutionAcceptor acceptor = getAcceptor(strategyConfig, vrp, algorithmListeners, definedClasses, solutionMemory); + SolutionSelector selector = getSelector(strategyConfig, vrp, algorithmListeners, definedClasses); + + SearchStrategy strategy = new SearchStrategy(name, selector, acceptor, costCalculator); + strategy.setName(name); + List modulesConfig = strategyConfig.configurationsAt("modules.module"); + for (HierarchicalConfiguration moduleConfig : modulesConfig) { + SearchStrategyModule module = buildModule(moduleConfig, vrp, vehicleFleetManager, stateManager, algorithmListeners, definedClasses, executorService, nuOfThreads, constraintManager, addDefaultCostCalculators); + strategy.addModule(module); + } + prettyAlgorithmBuilder.withStrategy(strategy, strategyConfig.getDouble("probability")); } - //construct algorithm - VehicleRoutingAlgorithm metaAlgorithm = prettyAlgorithmBuilder.build(); + //construct algorithm + VehicleRoutingAlgorithm metaAlgorithm = prettyAlgorithmBuilder.build(); int maxIterations = getMaxIterations(config); - if(maxIterations > -1) metaAlgorithm.setMaxIterations(maxIterations); + if (maxIterations > -1) metaAlgorithm.setMaxIterations(maxIterations); - //define prematureBreak - PrematureAlgorithmTermination prematureAlgorithmTermination = getPrematureTermination(config, algorithmListeners); - if(prematureAlgorithmTermination != null) metaAlgorithm.setPrematureAlgorithmTermination(prematureAlgorithmTermination); - else{ + //define prematureBreak + PrematureAlgorithmTermination prematureAlgorithmTermination = getPrematureTermination(config, algorithmListeners); + if (prematureAlgorithmTermination != null) + metaAlgorithm.setPrematureAlgorithmTermination(prematureAlgorithmTermination); + else { List terminationCriteria = config.configurationsAt("terminationCriteria.termination"); - for(HierarchicalConfiguration terminationConfig : terminationCriteria){ + for (HierarchicalConfiguration terminationConfig : terminationCriteria) { PrematureAlgorithmTermination termination = getTerminationCriterion(terminationConfig, algorithmListeners); - if(termination != null) metaAlgorithm.addTerminationCriterion(termination); + if (termination != null) metaAlgorithm.addTerminationCriterion(termination); } } - for(PrioritizedVRAListener l : algorithmListeners){ + for (PrioritizedVRAListener l : algorithmListeners) { metaAlgorithm.getAlgorithmListeners().add(l); } return metaAlgorithm; - } + } private static int getMaxIterations(XMLConfiguration config) { String maxIterationsString = config.getString("iterations"); - if(maxIterationsString == null) maxIterationsString = config.getString("maxIterations"); - if(maxIterationsString != null) return (Integer.parseInt(maxIterationsString)); + if (maxIterationsString == null) maxIterationsString = config.getString("maxIterations"); + if (maxIterationsString != null) return (Integer.parseInt(maxIterationsString)); return -1; } private static SolutionCostCalculator getDefaultCostCalculator(final StateManager stateManager) { - return new VariablePlusFixedSolutionCostCalculatorFactory(stateManager).createCalculator(); + return new VariablePlusFixedSolutionCostCalculatorFactory(stateManager).createCalculator(); } - private static VehicleFleetManager createFleetManager(final VehicleRoutingProblem vrp) { - if(vrp.getFleetSize().equals(FleetSize.INFINITE)){ - return new InfiniteFleetManagerFactory(vrp.getVehicles()).createFleetManager(); + private static VehicleFleetManager createFleetManager(final VehicleRoutingProblem vrp) { + if (vrp.getFleetSize().equals(FleetSize.INFINITE)) { + return new InfiniteFleetManagerFactory(vrp.getVehicles()).createFleetManager(); - } - else if(vrp.getFleetSize().equals(FleetSize.FINITE)){ - return new FiniteFleetManagerFactory(vrp.getVehicles()).createFleetManager(); - } - throw new IllegalStateException("fleet size can only be infinite or finite. " + - "makes sure your config file contains one of these options"); - } + } else if (vrp.getFleetSize().equals(FleetSize.FINITE)) { + return new FiniteFleetManagerFactory(vrp.getVehicles()).createFleetManager(); + } + throw new IllegalStateException("fleet size can only be infinite or finite. " + + "makes sure your config file contains one of these options"); + } private static PrematureAlgorithmTermination getTerminationCriterion(HierarchicalConfiguration config, Set algorithmListeners) { String basedOn = config.getString("[@basedOn]"); - if(basedOn == null){ + if (basedOn == null) { log.debug("set default prematureBreak, i.e. no premature break at all."); return null; } - if(basedOn.equals("iterations")){ + if (basedOn.equals("iterations")) { log.debug("set prematureBreak based on iterations"); String iter = config.getString("iterations"); - if(iter == null) throw new IllegalStateException("iterations is missing"); + if (iter == null) throw new IllegalStateException("iterations is missing"); int iterations = Integer.valueOf(iter); return new IterationWithoutImprovementTermination(iterations); } - if(basedOn.equals("time")){ + if (basedOn.equals("time")) { log.debug("set prematureBreak based on time"); String timeString = config.getString("time"); - if(timeString == null) throw new IllegalStateException("time is missing"); + if (timeString == null) throw new IllegalStateException("time is missing"); long time = Long.parseLong(timeString); TimeTermination timeBreaker = new TimeTermination(time); algorithmListeners.add(new PrioritizedVRAListener(Priority.LOW, timeBreaker)); return timeBreaker; } - if(basedOn.equals("variationCoefficient")){ + if (basedOn.equals("variationCoefficient")) { log.debug("set prematureBreak based on variation coefficient"); String thresholdString = config.getString("threshold"); String iterationsString = config.getString("iterations"); - if(thresholdString == null) throw new IllegalStateException("threshold is missing"); - if(iterationsString == null) throw new IllegalStateException("iterations is missing"); + if (thresholdString == null) throw new IllegalStateException("threshold is missing"); + if (iterationsString == null) throw new IllegalStateException("iterations is missing"); double threshold = Double.valueOf(thresholdString); int iterations = Integer.valueOf(iterationsString); VariationCoefficientTermination variationCoefficientBreaker = new VariationCoefficientTermination(iterations, threshold); @@ -679,238 +677,236 @@ public class VehicleRoutingAlgorithms { throw new IllegalStateException("prematureBreak basedOn " + basedOn + " is not defined"); } - private static PrematureAlgorithmTermination getPrematureTermination(XMLConfiguration config, Set algorithmListeners) { - String basedOn = config.getString("prematureBreak[@basedOn]"); - if(basedOn == null){ - log.debug("set default prematureBreak, i.e. no premature break at all."); - return null; - } - if(basedOn.equals("iterations")){ - log.debug("set prematureBreak based on iterations"); - String iter = config.getString("prematureBreak.iterations"); - if(iter == null) throw new IllegalStateException("prematureBreak.iterations is missing"); - int iterations = Integer.valueOf(iter); - return new IterationWithoutImprovementTermination(iterations); - } - if(basedOn.equals("time")){ - log.debug("set prematureBreak based on time"); - String timeString = config.getString("prematureBreak.time"); - if(timeString == null) throw new IllegalStateException("prematureBreak.time is missing"); - long time = Long.parseLong(timeString); - TimeTermination timeBreaker = new TimeTermination(time); - algorithmListeners.add(new PrioritizedVRAListener(Priority.LOW, timeBreaker)); - return timeBreaker; - } - if(basedOn.equals("variationCoefficient")){ - log.debug("set prematureBreak based on variation coefficient"); - String thresholdString = config.getString("prematureBreak.threshold"); - String iterationsString = config.getString("prematureBreak.iterations"); - if(thresholdString == null) throw new IllegalStateException("prematureBreak.threshold is missing"); - if(iterationsString == null) throw new IllegalStateException("prematureBreak.iterations is missing"); - double threshold = Double.valueOf(thresholdString); - int iterations = Integer.valueOf(iterationsString); - VariationCoefficientTermination variationCoefficientBreaker = new VariationCoefficientTermination(iterations, threshold); - algorithmListeners.add(new PrioritizedVRAListener(Priority.LOW, variationCoefficientBreaker)); - return variationCoefficientBreaker; - } - throw new IllegalStateException("prematureBreak basedOn " + basedOn + " is not defined"); - } - - private static String getName(HierarchicalConfiguration strategyConfig) { if(strategyConfig.containsKey("[@name]")){ - return strategyConfig.getString("[@name]"); - } - return ""; - } - - private static InsertionStrategy createInitialSolution(XMLConfiguration config, final VehicleRoutingProblem vrp, VehicleFleetManager vehicleFleetManager, final StateManager routeStates, Set algorithmListeners, TypedMap definedClasses, ExecutorService executorService, int nuOfThreads, final SolutionCostCalculator solutionCostCalculator, ConstraintManager constraintManager, boolean addDefaultCostCalculators) { - List modConfigs = config.configurationsAt("construction.insertion"); - if(modConfigs == null) return null; - if(modConfigs.isEmpty()) return null; - if(modConfigs.size() != 1) throw new IllegalStateException("#construction.modules != 1. 1 expected"); - HierarchicalConfiguration modConfig = modConfigs.get(0); - String insertionName = modConfig.getString("[@name]"); - if(insertionName == null) throw new IllegalStateException("insertion[@name] is missing."); - String insertionId = modConfig.getString("[@id]"); - if(insertionId == null) insertionId = "noId"; - ModKey modKey = makeKey(insertionName,insertionId); - InsertionStrategyKey insertionStrategyKey = new InsertionStrategyKey(modKey); - InsertionStrategy insertionStrategy = definedClasses.get(insertionStrategyKey); - if(insertionStrategy == null){ - List prioListeners = new ArrayList(); - insertionStrategy = createInsertionStrategy(modConfig, vrp, vehicleFleetManager, routeStates, prioListeners, executorService, nuOfThreads, constraintManager, addDefaultCostCalculators); - algorithmListeners.addAll(prioListeners); - definedClasses.put(insertionStrategyKey,insertionStrategy); - } - return insertionStrategy; + private static PrematureAlgorithmTermination getPrematureTermination(XMLConfiguration config, Set algorithmListeners) { + String basedOn = config.getString("prematureBreak[@basedOn]"); + if (basedOn == null) { + log.debug("set default prematureBreak, i.e. no premature break at all."); + return null; + } + if (basedOn.equals("iterations")) { + log.debug("set prematureBreak based on iterations"); + String iter = config.getString("prematureBreak.iterations"); + if (iter == null) throw new IllegalStateException("prematureBreak.iterations is missing"); + int iterations = Integer.valueOf(iter); + return new IterationWithoutImprovementTermination(iterations); + } + if (basedOn.equals("time")) { + log.debug("set prematureBreak based on time"); + String timeString = config.getString("prematureBreak.time"); + if (timeString == null) throw new IllegalStateException("prematureBreak.time is missing"); + long time = Long.parseLong(timeString); + TimeTermination timeBreaker = new TimeTermination(time); + algorithmListeners.add(new PrioritizedVRAListener(Priority.LOW, timeBreaker)); + return timeBreaker; + } + if (basedOn.equals("variationCoefficient")) { + log.debug("set prematureBreak based on variation coefficient"); + String thresholdString = config.getString("prematureBreak.threshold"); + String iterationsString = config.getString("prematureBreak.iterations"); + if (thresholdString == null) throw new IllegalStateException("prematureBreak.threshold is missing"); + if (iterationsString == null) throw new IllegalStateException("prematureBreak.iterations is missing"); + double threshold = Double.valueOf(thresholdString); + int iterations = Integer.valueOf(iterationsString); + VariationCoefficientTermination variationCoefficientBreaker = new VariationCoefficientTermination(iterations, threshold); + algorithmListeners.add(new PrioritizedVRAListener(Priority.LOW, variationCoefficientBreaker)); + return variationCoefficientBreaker; + } + throw new IllegalStateException("prematureBreak basedOn " + basedOn + " is not defined"); } - - private static SolutionSelector getSelector(HierarchicalConfiguration strategyConfig, VehicleRoutingProblem vrp, Set algorithmListeners, TypedMap definedSelectors) { - String selectorName = strategyConfig.getString("selector[@name]"); - if(selectorName == null) throw new IllegalStateException("no solutionSelector defined. define either \"selectRandomly\" or \"selectBest\""); - String selectorId = strategyConfig.getString("selector[@id]"); - if(selectorId == null) selectorId="noId"; - ModKey modKey = makeKey(selectorName,selectorId); - SelectorKey selectorKey = new SelectorKey(modKey); - SolutionSelector definedSelector = definedSelectors.get(selectorKey); - if(definedSelector != null) { - return definedSelector; - } - if(selectorName.equals("selectRandomly")){ - SelectRandomly selector = SelectRandomly.getInstance(); - definedSelectors.put(selectorKey, selector); - return selector; - } - if(selectorName.equals("selectBest")){ - SelectBest selector = SelectBest.getInstance(); - definedSelectors.put(selectorKey, selector); - return selector; - } - throw new IllegalStateException("solutionSelector is not know. Currently, it only knows \"selectRandomly\" and \"selectBest\""); - } - - private static ModKey makeKey(String name, String id){ - return new ModKey(name, id); - } - - private static SolutionAcceptor getAcceptor(HierarchicalConfiguration strategyConfig, VehicleRoutingProblem vrp, Set algorithmListeners, TypedMap typedMap, int solutionMemory) { - String acceptorName = strategyConfig.getString("acceptor[@name]"); - if(acceptorName == null) throw new IllegalStateException("no solution acceptor is defined"); - String acceptorId = strategyConfig.getString("acceptor[@id]"); - if(acceptorId == null) acceptorId = "noId"; - AcceptorKey acceptorKey = new AcceptorKey(makeKey(acceptorName,acceptorId)); - SolutionAcceptor definedAcceptor = typedMap.get(acceptorKey); - if(definedAcceptor != null) return definedAcceptor; - if(acceptorName.equals("acceptNewRemoveWorst")){ - GreedyAcceptance acceptor = new GreedyAcceptance(solutionMemory); - typedMap.put(acceptorKey, acceptor); - return acceptor; - } - if(acceptorName.equals("acceptNewRemoveFirst")){ - AcceptNewRemoveFirst acceptor = new AcceptNewRemoveFirst(solutionMemory); - typedMap.put(acceptorKey, acceptor); - return acceptor; - } - if(acceptorName.equals("greedyAcceptance")){ - GreedyAcceptance acceptor = new GreedyAcceptance(solutionMemory); - typedMap.put(acceptorKey, acceptor); - return acceptor; - } - if(acceptorName.equals("greedyAcceptance_minVehFirst")){ - GreedyAcceptance_minVehFirst acceptor = new GreedyAcceptance_minVehFirst(solutionMemory); - typedMap.put(acceptorKey, acceptor); - return acceptor; - } - if(acceptorName.equals("schrimpfAcceptance")){ - String nuWarmupIterations = strategyConfig.getString("acceptor.warmup"); - double alpha = strategyConfig.getDouble("acceptor.alpha"); - SchrimpfAcceptance schrimpf = new SchrimpfAcceptance(solutionMemory, alpha); - if(nuWarmupIterations!=null){ - SchrimpfInitialThresholdGenerator iniThresholdGenerator = new SchrimpfInitialThresholdGenerator(schrimpf, Integer.parseInt(nuWarmupIterations)); - algorithmListeners.add(new PrioritizedVRAListener(Priority.LOW, iniThresholdGenerator)); - } - else{ - double threshold = strategyConfig.getDouble("acceptor.initialThreshold"); - schrimpf.setInitialThreshold(threshold); - } - algorithmListeners.add(new PrioritizedVRAListener(Priority.LOW, schrimpf)); - typedMap.put(acceptorKey, schrimpf); - return schrimpf; - } - if(acceptorName.equals("experimentalSchrimpfAcceptance")){ - int iterOfSchrimpf = strategyConfig.getInt("acceptor.warmup"); - double alpha = strategyConfig.getDouble("acceptor.alpha"); - ExperimentalSchrimpfAcceptance schrimpf = new ExperimentalSchrimpfAcceptance(solutionMemory, alpha, iterOfSchrimpf); - algorithmListeners.add(new PrioritizedVRAListener(Priority.LOW, schrimpf)); - typedMap.put(acceptorKey, schrimpf); - return schrimpf; - } - else{ - throw new IllegalStateException("solution acceptor " + acceptorName + " is not known"); - } - } - - private static SearchStrategyModule buildModule(HierarchicalConfiguration moduleConfig, final VehicleRoutingProblem vrp, VehicleFleetManager vehicleFleetManager, - final StateManager routeStates, Set algorithmListeners, TypedMap definedClasses, ExecutorService executorService, int nuOfThreads, ConstraintManager constraintManager, boolean addDefaultCostCalculators) { - String moduleName = moduleConfig.getString("[@name]"); - if(moduleName == null) throw new IllegalStateException("module(-name) is missing."); - String moduleId = moduleConfig.getString("[@id]"); - if(moduleId == null) moduleId = "noId"; - ModKey modKey = makeKey(moduleName,moduleId); - StrategyModuleKey strategyModuleKey = new StrategyModuleKey(modKey); - SearchStrategyModule definedModule = definedClasses.get(strategyModuleKey); - if(definedModule != null) return definedModule; - - if(moduleName.equals("ruin_and_recreate")){ - String ruin_name = moduleConfig.getString("ruin[@name]"); - if(ruin_name == null) throw new IllegalStateException("module.ruin[@name] is missing."); - String ruin_id = moduleConfig.getString("ruin[@id]"); - if(ruin_id == null) ruin_id = "noId"; - String shareToRuinString = moduleConfig.getString("ruin.share"); - if(shareToRuinString == null) throw new IllegalStateException("module.ruin.share is missing."); - double shareToRuin = Double.valueOf(shareToRuinString); - final RuinStrategy ruin; - ModKey ruinKey = makeKey(ruin_name,ruin_id); - if(ruin_name.equals("randomRuin")){ - ruin = getRandomRuin(vrp, routeStates, definedClasses, ruinKey, shareToRuin); - } - else if(ruin_name.equals("radialRuin")){ - JobDistance jobDistance = new AvgServiceAndShipmentDistance(vrp.getTransportCosts()); - ruin = getRadialRuin(vrp, routeStates, definedClasses, ruinKey, shareToRuin, jobDistance); - } - else throw new IllegalStateException("ruin[@name] " + ruin_name + " is not known. Use either randomRuin or radialRuin."); - - String insertionName = moduleConfig.getString("insertion[@name]"); - if(insertionName == null) throw new IllegalStateException("module.insertion[@name] is missing. set it to \"regretInsertion\" or \"bestInsertion\""); - String insertionId = moduleConfig.getString("insertion[@id]"); - if(insertionId == null) insertionId = "noId"; - ModKey insertionKey = makeKey(insertionName,insertionId); - InsertionStrategyKey insertionStrategyKey = new InsertionStrategyKey(insertionKey); - InsertionStrategy insertion = definedClasses.get(insertionStrategyKey); - if(insertion == null){ - List insertionConfigs = moduleConfig.configurationsAt("insertion"); - if(insertionConfigs.size() != 1) throw new IllegalStateException("this should be 1"); - List prioListeners = new ArrayList(); - insertion = createInsertionStrategy(insertionConfigs.get(0), vrp, vehicleFleetManager, routeStates, prioListeners, executorService, nuOfThreads, constraintManager, addDefaultCostCalculators); - algorithmListeners.addAll(prioListeners); - } - final InsertionStrategy final_insertion = insertion; - - RuinAndRecreateModule rrModule = new RuinAndRecreateModule("ruin_and_recreate", final_insertion, ruin); - return rrModule; - } - throw new NullPointerException("no module found with moduleName=" + moduleName + - "\n\tcheck config whether the correct names are used" + - "\n\tcurrently there are following modules available: " + - "\n\tbestInsertion" + - "\n\trandomRuin" + - "\n\tradialRuin"); - } - private static RuinStrategy getRadialRuin(final VehicleRoutingProblem vrp, final StateManager routeStates, TypedMap definedClasses, ModKey modKey, double shareToRuin, JobDistance jobDistance) { - RuinStrategyKey stratKey = new RuinStrategyKey(modKey); - RuinStrategy ruin = definedClasses.get(stratKey); - if(ruin == null){ - ruin = new RadialRuinStrategyFactory(shareToRuin, jobDistance).createStrategy(vrp); - definedClasses.put(stratKey, ruin); - } - return ruin; - } + private static String getName(HierarchicalConfiguration strategyConfig) { + if (strategyConfig.containsKey("[@name]")) { + return strategyConfig.getString("[@name]"); + } + return ""; + } - private static RuinStrategy getRandomRuin(final VehicleRoutingProblem vrp, final StateManager routeStates, TypedMap definedClasses, ModKey modKey, double shareToRuin) { - RuinStrategyKey stratKey = new RuinStrategyKey(modKey); - RuinStrategy ruin = definedClasses.get(stratKey); - if(ruin == null){ - ruin = new RandomRuinStrategyFactory(shareToRuin).createStrategy(vrp); - definedClasses.put(stratKey, ruin); - } - return ruin; - } - - private static InsertionStrategy createInsertionStrategy(HierarchicalConfiguration moduleConfig, VehicleRoutingProblem vrp,VehicleFleetManager vehicleFleetManager, StateManager routeStates, List algorithmListeners, ExecutorService executorService, int nuOfThreads, ConstraintManager constraintManager, boolean addDefaultCostCalculators) { - return InsertionFactory.createInsertion(vrp, moduleConfig, vehicleFleetManager, routeStates, algorithmListeners, executorService, nuOfThreads, constraintManager, addDefaultCostCalculators); - } + private static InsertionStrategy createInitialSolution(XMLConfiguration config, final VehicleRoutingProblem vrp, VehicleFleetManager vehicleFleetManager, final StateManager routeStates, Set algorithmListeners, TypedMap definedClasses, ExecutorService executorService, int nuOfThreads, final SolutionCostCalculator solutionCostCalculator, ConstraintManager constraintManager, boolean addDefaultCostCalculators) { + List modConfigs = config.configurationsAt("construction.insertion"); + if (modConfigs == null) return null; + if (modConfigs.isEmpty()) return null; + if (modConfigs.size() != 1) throw new IllegalStateException("#construction.modules != 1. 1 expected"); + HierarchicalConfiguration modConfig = modConfigs.get(0); + String insertionName = modConfig.getString("[@name]"); + if (insertionName == null) throw new IllegalStateException("insertion[@name] is missing."); + String insertionId = modConfig.getString("[@id]"); + if (insertionId == null) insertionId = "noId"; + ModKey modKey = makeKey(insertionName, insertionId); + InsertionStrategyKey insertionStrategyKey = new InsertionStrategyKey(modKey); + InsertionStrategy insertionStrategy = definedClasses.get(insertionStrategyKey); + if (insertionStrategy == null) { + List prioListeners = new ArrayList(); + insertionStrategy = createInsertionStrategy(modConfig, vrp, vehicleFleetManager, routeStates, prioListeners, executorService, nuOfThreads, constraintManager, addDefaultCostCalculators); + algorithmListeners.addAll(prioListeners); + definedClasses.put(insertionStrategyKey, insertionStrategy); + } + return insertionStrategy; + } + + private static SolutionSelector getSelector(HierarchicalConfiguration strategyConfig, VehicleRoutingProblem vrp, Set algorithmListeners, TypedMap definedSelectors) { + String selectorName = strategyConfig.getString("selector[@name]"); + if (selectorName == null) + throw new IllegalStateException("no solutionSelector defined. define either \"selectRandomly\" or \"selectBest\""); + String selectorId = strategyConfig.getString("selector[@id]"); + if (selectorId == null) selectorId = "noId"; + ModKey modKey = makeKey(selectorName, selectorId); + SelectorKey selectorKey = new SelectorKey(modKey); + SolutionSelector definedSelector = definedSelectors.get(selectorKey); + if (definedSelector != null) { + return definedSelector; + } + if (selectorName.equals("selectRandomly")) { + SelectRandomly selector = SelectRandomly.getInstance(); + definedSelectors.put(selectorKey, selector); + return selector; + } + if (selectorName.equals("selectBest")) { + SelectBest selector = SelectBest.getInstance(); + definedSelectors.put(selectorKey, selector); + return selector; + } + throw new IllegalStateException("solutionSelector is not know. Currently, it only knows \"selectRandomly\" and \"selectBest\""); + } + + private static ModKey makeKey(String name, String id) { + return new ModKey(name, id); + } + + private static SolutionAcceptor getAcceptor(HierarchicalConfiguration strategyConfig, VehicleRoutingProblem vrp, Set algorithmListeners, TypedMap typedMap, int solutionMemory) { + String acceptorName = strategyConfig.getString("acceptor[@name]"); + if (acceptorName == null) throw new IllegalStateException("no solution acceptor is defined"); + String acceptorId = strategyConfig.getString("acceptor[@id]"); + if (acceptorId == null) acceptorId = "noId"; + AcceptorKey acceptorKey = new AcceptorKey(makeKey(acceptorName, acceptorId)); + SolutionAcceptor definedAcceptor = typedMap.get(acceptorKey); + if (definedAcceptor != null) return definedAcceptor; + if (acceptorName.equals("acceptNewRemoveWorst")) { + GreedyAcceptance acceptor = new GreedyAcceptance(solutionMemory); + typedMap.put(acceptorKey, acceptor); + return acceptor; + } + if (acceptorName.equals("acceptNewRemoveFirst")) { + AcceptNewRemoveFirst acceptor = new AcceptNewRemoveFirst(solutionMemory); + typedMap.put(acceptorKey, acceptor); + return acceptor; + } + if (acceptorName.equals("greedyAcceptance")) { + GreedyAcceptance acceptor = new GreedyAcceptance(solutionMemory); + typedMap.put(acceptorKey, acceptor); + return acceptor; + } + if (acceptorName.equals("greedyAcceptance_minVehFirst")) { + GreedyAcceptance_minVehFirst acceptor = new GreedyAcceptance_minVehFirst(solutionMemory); + typedMap.put(acceptorKey, acceptor); + return acceptor; + } + if (acceptorName.equals("schrimpfAcceptance")) { + String nuWarmupIterations = strategyConfig.getString("acceptor.warmup"); + double alpha = strategyConfig.getDouble("acceptor.alpha"); + SchrimpfAcceptance schrimpf = new SchrimpfAcceptance(solutionMemory, alpha); + if (nuWarmupIterations != null) { + SchrimpfInitialThresholdGenerator iniThresholdGenerator = new SchrimpfInitialThresholdGenerator(schrimpf, Integer.parseInt(nuWarmupIterations)); + algorithmListeners.add(new PrioritizedVRAListener(Priority.LOW, iniThresholdGenerator)); + } else { + double threshold = strategyConfig.getDouble("acceptor.initialThreshold"); + schrimpf.setInitialThreshold(threshold); + } + algorithmListeners.add(new PrioritizedVRAListener(Priority.LOW, schrimpf)); + typedMap.put(acceptorKey, schrimpf); + return schrimpf; + } + if (acceptorName.equals("experimentalSchrimpfAcceptance")) { + int iterOfSchrimpf = strategyConfig.getInt("acceptor.warmup"); + double alpha = strategyConfig.getDouble("acceptor.alpha"); + ExperimentalSchrimpfAcceptance schrimpf = new ExperimentalSchrimpfAcceptance(solutionMemory, alpha, iterOfSchrimpf); + algorithmListeners.add(new PrioritizedVRAListener(Priority.LOW, schrimpf)); + typedMap.put(acceptorKey, schrimpf); + return schrimpf; + } else { + throw new IllegalStateException("solution acceptor " + acceptorName + " is not known"); + } + } + + private static SearchStrategyModule buildModule(HierarchicalConfiguration moduleConfig, final VehicleRoutingProblem vrp, VehicleFleetManager vehicleFleetManager, + final StateManager routeStates, Set algorithmListeners, TypedMap definedClasses, ExecutorService executorService, int nuOfThreads, ConstraintManager constraintManager, boolean addDefaultCostCalculators) { + String moduleName = moduleConfig.getString("[@name]"); + if (moduleName == null) throw new IllegalStateException("module(-name) is missing."); + String moduleId = moduleConfig.getString("[@id]"); + if (moduleId == null) moduleId = "noId"; + ModKey modKey = makeKey(moduleName, moduleId); + StrategyModuleKey strategyModuleKey = new StrategyModuleKey(modKey); + SearchStrategyModule definedModule = definedClasses.get(strategyModuleKey); + if (definedModule != null) return definedModule; + + if (moduleName.equals("ruin_and_recreate")) { + String ruin_name = moduleConfig.getString("ruin[@name]"); + if (ruin_name == null) throw new IllegalStateException("module.ruin[@name] is missing."); + String ruin_id = moduleConfig.getString("ruin[@id]"); + if (ruin_id == null) ruin_id = "noId"; + String shareToRuinString = moduleConfig.getString("ruin.share"); + if (shareToRuinString == null) throw new IllegalStateException("module.ruin.share is missing."); + double shareToRuin = Double.valueOf(shareToRuinString); + final RuinStrategy ruin; + ModKey ruinKey = makeKey(ruin_name, ruin_id); + if (ruin_name.equals("randomRuin")) { + ruin = getRandomRuin(vrp, routeStates, definedClasses, ruinKey, shareToRuin); + } else if (ruin_name.equals("radialRuin")) { + JobDistance jobDistance = new AvgServiceAndShipmentDistance(vrp.getTransportCosts()); + ruin = getRadialRuin(vrp, routeStates, definedClasses, ruinKey, shareToRuin, jobDistance); + } else + throw new IllegalStateException("ruin[@name] " + ruin_name + " is not known. Use either randomRuin or radialRuin."); + + String insertionName = moduleConfig.getString("insertion[@name]"); + if (insertionName == null) + throw new IllegalStateException("module.insertion[@name] is missing. set it to \"regretInsertion\" or \"bestInsertion\""); + String insertionId = moduleConfig.getString("insertion[@id]"); + if (insertionId == null) insertionId = "noId"; + ModKey insertionKey = makeKey(insertionName, insertionId); + InsertionStrategyKey insertionStrategyKey = new InsertionStrategyKey(insertionKey); + InsertionStrategy insertion = definedClasses.get(insertionStrategyKey); + if (insertion == null) { + List insertionConfigs = moduleConfig.configurationsAt("insertion"); + if (insertionConfigs.size() != 1) throw new IllegalStateException("this should be 1"); + List prioListeners = new ArrayList(); + insertion = createInsertionStrategy(insertionConfigs.get(0), vrp, vehicleFleetManager, routeStates, prioListeners, executorService, nuOfThreads, constraintManager, addDefaultCostCalculators); + algorithmListeners.addAll(prioListeners); + } + final InsertionStrategy final_insertion = insertion; + + RuinAndRecreateModule rrModule = new RuinAndRecreateModule("ruin_and_recreate", final_insertion, ruin); + return rrModule; + } + throw new NullPointerException("no module found with moduleName=" + moduleName + + "\n\tcheck config whether the correct names are used" + + "\n\tcurrently there are following modules available: " + + "\n\tbestInsertion" + + "\n\trandomRuin" + + "\n\tradialRuin"); + } + + private static RuinStrategy getRadialRuin(final VehicleRoutingProblem vrp, final StateManager routeStates, TypedMap definedClasses, ModKey modKey, double shareToRuin, JobDistance jobDistance) { + RuinStrategyKey stratKey = new RuinStrategyKey(modKey); + RuinStrategy ruin = definedClasses.get(stratKey); + if (ruin == null) { + ruin = new RadialRuinStrategyFactory(shareToRuin, jobDistance).createStrategy(vrp); + definedClasses.put(stratKey, ruin); + } + return ruin; + } + + private static RuinStrategy getRandomRuin(final VehicleRoutingProblem vrp, final StateManager routeStates, TypedMap definedClasses, ModKey modKey, double shareToRuin) { + RuinStrategyKey stratKey = new RuinStrategyKey(modKey); + RuinStrategy ruin = definedClasses.get(stratKey); + if (ruin == null) { + ruin = new RandomRuinStrategyFactory(shareToRuin).createStrategy(vrp); + definedClasses.put(stratKey, ruin); + } + return ruin; + } + + private static InsertionStrategy createInsertionStrategy(HierarchicalConfiguration moduleConfig, VehicleRoutingProblem vrp, VehicleFleetManager vehicleFleetManager, StateManager routeStates, List algorithmListeners, ExecutorService executorService, int nuOfThreads, ConstraintManager constraintManager, boolean addDefaultCostCalculators) { + return InsertionFactory.createInsertion(vrp, moduleConfig, vehicleFleetManager, routeStates, algorithmListeners, executorService, nuOfThreads, constraintManager, addDefaultCostCalculators); + } - - } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/listener/AlgorithmEndsListener.java b/jsprit-core/src/main/java/jsprit/core/algorithm/listener/AlgorithmEndsListener.java index b1dd2d9c..d0784ceb 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/listener/AlgorithmEndsListener.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/listener/AlgorithmEndsListener.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.listener; @@ -22,10 +22,8 @@ import jsprit.core.problem.solution.VehicleRoutingProblemSolution; import java.util.Collection; +public interface AlgorithmEndsListener extends VehicleRoutingAlgorithmListener { + void informAlgorithmEnds(VehicleRoutingProblem problem, Collection solutions); -public interface AlgorithmEndsListener extends VehicleRoutingAlgorithmListener{ - - void informAlgorithmEnds(VehicleRoutingProblem problem, Collection solutions); - } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/listener/AlgorithmStartsListener.java b/jsprit-core/src/main/java/jsprit/core/algorithm/listener/AlgorithmStartsListener.java index d442b751..9115f990 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/listener/AlgorithmStartsListener.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/listener/AlgorithmStartsListener.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.listener; @@ -23,10 +23,8 @@ import jsprit.core.problem.solution.VehicleRoutingProblemSolution; import java.util.Collection; +public interface AlgorithmStartsListener extends VehicleRoutingAlgorithmListener { + void informAlgorithmStarts(VehicleRoutingProblem problem, VehicleRoutingAlgorithm algorithm, Collection solutions); -public interface AlgorithmStartsListener extends VehicleRoutingAlgorithmListener{ - - void informAlgorithmStarts(VehicleRoutingProblem problem, VehicleRoutingAlgorithm algorithm, Collection solutions); - } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/listener/IterationEndsListener.java b/jsprit-core/src/main/java/jsprit/core/algorithm/listener/IterationEndsListener.java index da102244..308ece2d 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/listener/IterationEndsListener.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/listener/IterationEndsListener.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.listener; @@ -22,12 +22,9 @@ import jsprit.core.problem.solution.VehicleRoutingProblemSolution; import java.util.Collection; +public interface IterationEndsListener extends VehicleRoutingAlgorithmListener { + + public void informIterationEnds(int i, VehicleRoutingProblem problem, Collection solutions); - -public interface IterationEndsListener extends VehicleRoutingAlgorithmListener{ - - public void informIterationEnds(int i, VehicleRoutingProblem problem, Collection solutions); - - } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/listener/IterationStartsListener.java b/jsprit-core/src/main/java/jsprit/core/algorithm/listener/IterationStartsListener.java index afee00a6..2f2fe6f8 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/listener/IterationStartsListener.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/listener/IterationStartsListener.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.listener; @@ -22,11 +22,9 @@ import jsprit.core.problem.solution.VehicleRoutingProblemSolution; import java.util.Collection; +public interface IterationStartsListener extends VehicleRoutingAlgorithmListener { + + public void informIterationStarts(int i, VehicleRoutingProblem problem, Collection solutions); -public interface IterationStartsListener extends VehicleRoutingAlgorithmListener{ - - public void informIterationStarts(int i, VehicleRoutingProblem problem, Collection solutions); - - } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/listener/SearchStrategyListener.java b/jsprit-core/src/main/java/jsprit/core/algorithm/listener/SearchStrategyListener.java index d4983bb9..67720df5 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/listener/SearchStrategyListener.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/listener/SearchStrategyListener.java @@ -1,21 +1,21 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.listener; -public interface SearchStrategyListener extends VehicleRoutingAlgorithmListener{ +public interface SearchStrategyListener extends VehicleRoutingAlgorithmListener { } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/listener/SearchStrategyModuleListener.java b/jsprit-core/src/main/java/jsprit/core/algorithm/listener/SearchStrategyModuleListener.java index 58f7e737..2167e333 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/listener/SearchStrategyModuleListener.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/listener/SearchStrategyModuleListener.java @@ -1,21 +1,21 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.listener; -public interface SearchStrategyModuleListener extends VehicleRoutingAlgorithmListener{ +public interface SearchStrategyModuleListener extends VehicleRoutingAlgorithmListener { } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/listener/StrategySelectedListener.java b/jsprit-core/src/main/java/jsprit/core/algorithm/listener/StrategySelectedListener.java index 9f190c2a..ab6c2cea 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/listener/StrategySelectedListener.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/listener/StrategySelectedListener.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.listener; @@ -23,10 +23,8 @@ import jsprit.core.problem.solution.VehicleRoutingProblemSolution; import java.util.Collection; +public interface StrategySelectedListener extends VehicleRoutingAlgorithmListener { + void informSelectedStrategy(SearchStrategy.DiscoveredSolution discoveredSolution, VehicleRoutingProblem vehicleRoutingProblem, Collection vehicleRoutingProblemSolutions); -public interface StrategySelectedListener extends VehicleRoutingAlgorithmListener{ - - void informSelectedStrategy(SearchStrategy.DiscoveredSolution discoveredSolution, VehicleRoutingProblem vehicleRoutingProblem, Collection vehicleRoutingProblemSolutions); - } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/listener/VehicleRoutingAlgorithmListener.java b/jsprit-core/src/main/java/jsprit/core/algorithm/listener/VehicleRoutingAlgorithmListener.java index c2eaef7f..e53c1977 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/listener/VehicleRoutingAlgorithmListener.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/listener/VehicleRoutingAlgorithmListener.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.listener; diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/listener/VehicleRoutingAlgorithmListeners.java b/jsprit-core/src/main/java/jsprit/core/algorithm/listener/VehicleRoutingAlgorithmListeners.java index 2620038f..c9d0d355 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/listener/VehicleRoutingAlgorithmListeners.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/listener/VehicleRoutingAlgorithmListeners.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.listener; @@ -24,159 +24,126 @@ import jsprit.core.problem.solution.VehicleRoutingProblemSolution; import java.util.*; - - public class VehicleRoutingAlgorithmListeners { - public static class PrioritizedVRAListener { - - Priority priority; - VehicleRoutingAlgorithmListener l; - public PrioritizedVRAListener(Priority priority, VehicleRoutingAlgorithmListener l) { - super(); - this.priority = priority; - this.l = l; - } - public Priority getPriority() { - return priority; - } - public VehicleRoutingAlgorithmListener getListener() { - return l; - } - -// @Override -// public int hashCode() { -// final int prime = 31; -// int result = 1; -// result = prime * result + ((l == null) ? 0 : l.hashCode()); -// result = prime * result -// + ((priority == null) ? 0 : priority.hashCode()); -// return result; -// } -// @Override -// public boolean equals(Object obj) { -// if (this == obj) -// return true; -// if (obj == null) -// return false; -// if (getClass() != obj.getClass()) -// return false; -// PrioritizedVRAListener other = (PrioritizedVRAListener) obj; -// if (l == null) { -// if (other.l != null) -// return false; -// } else if (!l.equals(other.l)) -// return false; -// if (priority == null) { -// if (other.priority != null) -// return false; -// } else if (!priority.equals(other.priority)) -// return false; -// return true; -// } - - } - - public enum Priority { - HIGH, MEDIUM, LOW - } - - - private TreeSet algorithmListeners = new TreeSet(new Comparator() { + public static class PrioritizedVRAListener { - @Override - public int compare(PrioritizedVRAListener o1, PrioritizedVRAListener o2) { - if(o1 == o2) return 0; - if(o1.getPriority() == Priority.HIGH && o2.getPriority() != Priority.HIGH){ - return -1; - } - else if(o2.getPriority() == Priority.HIGH && o1.getPriority() != Priority.HIGH){ - return 1; - } - else if(o1.getPriority() == Priority.MEDIUM && o2.getPriority() != Priority.MEDIUM){ - return -1; - } - else if(o2.getPriority() == Priority.MEDIUM && o1.getPriority() != Priority.MEDIUM){ - return 1; - } - return 1; - } - }); - - - public Collection getAlgorithmListeners() { - List list = new ArrayList(); - for(PrioritizedVRAListener l : algorithmListeners){ - list.add(l.getListener()); - } - return Collections.unmodifiableCollection(list); - } - - public void remove(PrioritizedVRAListener listener){ - boolean removed = algorithmListeners.remove(listener); - if(!removed){ throw new IllegalStateException("cannot remove listener"); } - } + Priority priority; + VehicleRoutingAlgorithmListener l; - public void addListener(VehicleRoutingAlgorithmListener listener, Priority priority){ - algorithmListeners.add(new PrioritizedVRAListener(priority, listener)); - } + public PrioritizedVRAListener(Priority priority, VehicleRoutingAlgorithmListener l) { + super(); + this.priority = priority; + this.l = l; + } - public void addListener(VehicleRoutingAlgorithmListener listener){ - addListener(listener, Priority.LOW); - } + public Priority getPriority() { + return priority; + } - public void algorithmEnds(VehicleRoutingProblem problem, Collection solutions) { - for(PrioritizedVRAListener l : algorithmListeners){ - if(l.getListener() instanceof AlgorithmEndsListener){ - ((AlgorithmEndsListener)l.getListener()).informAlgorithmEnds(problem, solutions); - } - } - - } + public VehicleRoutingAlgorithmListener getListener() { + return l; + } - public void iterationEnds(int i, VehicleRoutingProblem problem, Collection solutions) { - for(PrioritizedVRAListener l : algorithmListeners){ - if(l.getListener() instanceof IterationEndsListener){ - ((IterationEndsListener)l.getListener()).informIterationEnds(i,problem, solutions); - } - } - } + } + + public enum Priority { + HIGH, MEDIUM, LOW + } + private TreeSet algorithmListeners = new TreeSet(new Comparator() { - public void iterationStarts(int i, VehicleRoutingProblem problem, Collection solutions) { - for(PrioritizedVRAListener l : algorithmListeners){ - if(l.getListener() instanceof IterationStartsListener){ - ((IterationStartsListener)l.getListener()).informIterationStarts(i,problem, solutions); - } - } - } + @Override + public int compare(PrioritizedVRAListener o1, PrioritizedVRAListener o2) { + if (o1 == o2) return 0; + if (o1.getPriority() == Priority.HIGH && o2.getPriority() != Priority.HIGH) { + return -1; + } else if (o2.getPriority() == Priority.HIGH && o1.getPriority() != Priority.HIGH) { + return 1; + } else if (o1.getPriority() == Priority.MEDIUM && o2.getPriority() != Priority.MEDIUM) { + return -1; + } else if (o2.getPriority() == Priority.MEDIUM && o1.getPriority() != Priority.MEDIUM) { + return 1; + } + return 1; + } + }); - - public void algorithmStarts(VehicleRoutingProblem problem, VehicleRoutingAlgorithm algorithm, Collection solutions) { - for(PrioritizedVRAListener l : algorithmListeners){ - if(l.getListener() instanceof AlgorithmStartsListener){ - ((AlgorithmStartsListener)l.getListener()).informAlgorithmStarts(problem, algorithm, solutions); - } - } - } + public Collection getAlgorithmListeners() { + List list = new ArrayList(); + for (PrioritizedVRAListener l : algorithmListeners) { + list.add(l.getListener()); + } + return Collections.unmodifiableCollection(list); + } - public void add(PrioritizedVRAListener l){ - algorithmListeners.add(l); - } - - public void addAll(Collection algorithmListeners) { - for(PrioritizedVRAListener l : algorithmListeners){ - this.algorithmListeners.add(l); - } - } + public void remove(PrioritizedVRAListener listener) { + boolean removed = algorithmListeners.remove(listener); + if (!removed) { + throw new IllegalStateException("cannot remove listener"); + } + } - public void selectedStrategy(SearchStrategy.DiscoveredSolution discoveredSolution, VehicleRoutingProblem problem, Collection solutions) { - for(PrioritizedVRAListener l : algorithmListeners){ - if(l.getListener() instanceof StrategySelectedListener){ - ((StrategySelectedListener)l.getListener()).informSelectedStrategy(discoveredSolution, problem, solutions); - } - } - } + public void addListener(VehicleRoutingAlgorithmListener listener, Priority priority) { + algorithmListeners.add(new PrioritizedVRAListener(priority, listener)); + } + + public void addListener(VehicleRoutingAlgorithmListener listener) { + addListener(listener, Priority.LOW); + } + + public void algorithmEnds(VehicleRoutingProblem problem, Collection solutions) { + for (PrioritizedVRAListener l : algorithmListeners) { + if (l.getListener() instanceof AlgorithmEndsListener) { + ((AlgorithmEndsListener) l.getListener()).informAlgorithmEnds(problem, solutions); + } + } + + } + + public void iterationEnds(int i, VehicleRoutingProblem problem, Collection solutions) { + for (PrioritizedVRAListener l : algorithmListeners) { + if (l.getListener() instanceof IterationEndsListener) { + ((IterationEndsListener) l.getListener()).informIterationEnds(i, problem, solutions); + } + } + } + + + public void iterationStarts(int i, VehicleRoutingProblem problem, Collection solutions) { + for (PrioritizedVRAListener l : algorithmListeners) { + if (l.getListener() instanceof IterationStartsListener) { + ((IterationStartsListener) l.getListener()).informIterationStarts(i, problem, solutions); + } + } + } + + + public void algorithmStarts(VehicleRoutingProblem problem, VehicleRoutingAlgorithm algorithm, Collection solutions) { + for (PrioritizedVRAListener l : algorithmListeners) { + if (l.getListener() instanceof AlgorithmStartsListener) { + ((AlgorithmStartsListener) l.getListener()).informAlgorithmStarts(problem, algorithm, solutions); + } + } + } + + public void add(PrioritizedVRAListener l) { + algorithmListeners.add(l); + } + + public void addAll(Collection algorithmListeners) { + for (PrioritizedVRAListener l : algorithmListeners) { + this.algorithmListeners.add(l); + } + } + + public void selectedStrategy(SearchStrategy.DiscoveredSolution discoveredSolution, VehicleRoutingProblem problem, Collection solutions) { + for (PrioritizedVRAListener l : algorithmListeners) { + if (l.getListener() instanceof StrategySelectedListener) { + ((StrategySelectedListener) l.getListener()).informSelectedStrategy(discoveredSolution, problem, solutions); + } + } + } } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/module/RuinAndRecreateModule.java b/jsprit-core/src/main/java/jsprit/core/algorithm/module/RuinAndRecreateModule.java index 7645cae7..e3d176cb 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/module/RuinAndRecreateModule.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/module/RuinAndRecreateModule.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.module; @@ -30,61 +30,61 @@ import java.util.HashSet; import java.util.Set; -public class RuinAndRecreateModule implements SearchStrategyModule{ +public 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; - } + private InsertionStrategy insertion; - @Override - public VehicleRoutingProblemSolution runAndGetSolution(VehicleRoutingProblemSolution vrpSolution) { - Collection ruinedJobs = ruin.ruin(vrpSolution.getRoutes()); + 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()); Set ruinedJobSet = new HashSet(); ruinedJobSet.addAll(ruinedJobs); ruinedJobSet.addAll(vrpSolution.getUnassignedJobs()); - Collection unassignedJobs = insertion.insertJobs(vrpSolution.getRoutes(), ruinedJobSet); + Collection unassignedJobs = insertion.insertJobs(vrpSolution.getRoutes(), ruinedJobSet); vrpSolution.getUnassignedJobs().clear(); vrpSolution.getUnassignedJobs().addAll(unassignedJobs); - return vrpSolution; + return vrpSolution; - } + } - @Override - public String getName() { - return moduleName; - } + @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); - } - } - - } + @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); + } + } - public InsertionStrategy getInsertion() { - return insertion; - } + } - public RuinStrategy getRuin() { - return ruin; - } + public InsertionStrategy getInsertion() { + return insertion; + } + + public RuinStrategy getRuin() { + return ruin; + } } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/AbstractInsertionStrategy.java b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/AbstractInsertionStrategy.java index 0c61da0a..b3d9b906 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/AbstractInsertionStrategy.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/AbstractInsertionStrategy.java @@ -33,7 +33,7 @@ import java.util.Collection; import java.util.Collections; import java.util.Random; -public abstract class AbstractInsertionStrategy implements InsertionStrategy{ +public abstract class AbstractInsertionStrategy implements InsertionStrategy { protected class Insertion { @@ -84,9 +84,9 @@ public abstract class AbstractInsertionStrategy implements InsertionStrategy{ } @Override - public Collection insertJobs(Collection vehicleRoutes, Collection unassignedJobs){ + public Collection insertJobs(Collection vehicleRoutes, Collection unassignedJobs) { insertionsListeners.informInsertionStarts(vehicleRoutes, unassignedJobs); - Collection badJobs = insertUnassignedJobs(vehicleRoutes,unassignedJobs); + Collection badJobs = insertUnassignedJobs(vehicleRoutes, unassignedJobs); insertionsListeners.informInsertionEndsListeners(vehicleRoutes); return badJobs; } @@ -109,13 +109,13 @@ public abstract class AbstractInsertionStrategy implements InsertionStrategy{ } - protected void insertJob(Job unassignedJob, InsertionData iData, VehicleRoute inRoute){ - logger.trace("insert: [jobId=" + unassignedJob.getId() + "]" + iData ); + protected void insertJob(Job unassignedJob, InsertionData iData, VehicleRoute inRoute) { + logger.trace("insert: [jobId={}]{}", unassignedJob.getId(), iData); insertionsListeners.informBeforeJobInsertion(unassignedJob, iData, inRoute); - if(!(inRoute.getVehicle().getId().equals(iData.getSelectedVehicle().getId()))){ + if (!(inRoute.getVehicle().getId().equals(iData.getSelectedVehicle().getId()))) { insertionsListeners.informVehicleSwitched(inRoute, inRoute.getVehicle(), iData.getSelectedVehicle()); } - for(Event e : iData.getEvents()){ + for (Event e : iData.getEvents()) { eventListeners.inform(e); } insertionsListeners.informJobInserted(unassignedJob, inRoute, iData.getInsertionCost(), iData.getAdditionalTime()); diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/ActivityInsertionCostsCalculator.java b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/ActivityInsertionCostsCalculator.java index 56aa153e..884656c0 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/ActivityInsertionCostsCalculator.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/ActivityInsertionCostsCalculator.java @@ -1,4 +1,3 @@ - /******************************************************************************* * Copyright (C) 2014 Stefan Schroeder * @@ -22,33 +21,35 @@ import jsprit.core.problem.misc.JobInsertionContext; import jsprit.core.problem.solution.route.activity.TourActivity; public interface ActivityInsertionCostsCalculator { - - public class ActivityInsertionCosts { - - private double additionalCosts; - private double additionalTime; - public ActivityInsertionCosts(double additionalCosts, double additionalTime) { - super(); - this.additionalCosts = additionalCosts; - this.additionalTime = additionalTime; - } - /** - * @return the additionalCosts - */ - public double getAdditionalCosts() { - return additionalCosts; - } - /** - * @return the additionalTime - */ - public double getAdditionalTime() { - return additionalTime; - } - - - } - - public double getCosts(JobInsertionContext iContext, TourActivity prevAct, TourActivity nextAct, TourActivity newAct, double depTimeAtPrevAct); + public class ActivityInsertionCosts { + + private double additionalCosts; + private double additionalTime; + + public ActivityInsertionCosts(double additionalCosts, double additionalTime) { + super(); + this.additionalCosts = additionalCosts; + this.additionalTime = additionalTime; + } + + /** + * @return the additionalCosts + */ + public double getAdditionalCosts() { + return additionalCosts; + } + + /** + * @return the additionalTime + */ + public double getAdditionalTime() { + return additionalTime; + } + + + } + + public double getCosts(JobInsertionContext iContext, TourActivity prevAct, TourActivity nextAct, TourActivity newAct, double depTimeAtPrevAct); } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/AdditionalAccessEgressCalculator.java b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/AdditionalAccessEgressCalculator.java index 8422a859..42b5327f 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/AdditionalAccessEgressCalculator.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/AdditionalAccessEgressCalculator.java @@ -25,52 +25,50 @@ import jsprit.core.problem.vehicle.Vehicle; /** * Estimates additional access/egress costs when operating route with a new vehicle that has different start/end-location. - * + *

*

If two vehicles have the same start/end-location and departure-time .getCosts(...) must return zero. - * - * @author schroeder * + * @author schroeder */ class AdditionalAccessEgressCalculator { - - private VehicleRoutingTransportCosts routingCosts; - - /** - * Constructs the estimator that estimates additional access/egress costs when operating route with a new vehicle that has different start/end-location. - * - *

If two vehicles have the same start/end-location and departure-time .getCosts(...) must return zero. - * - * @author schroeder - * - */ - public AdditionalAccessEgressCalculator(VehicleRoutingTransportCosts routingCosts) { - this.routingCosts = routingCosts; - } - - public double getCosts(JobInsertionContext insertionContext){ - double delta_access = 0.0; - double delta_egress = 0.0; - VehicleRoute currentRoute = insertionContext.getRoute(); - Vehicle newVehicle = insertionContext.getNewVehicle(); - Driver newDriver = insertionContext.getNewDriver(); - double newVehicleDepartureTime = insertionContext.getNewDepTime(); - if(!currentRoute.isEmpty()){ - double accessTransportCostNew = routingCosts.getTransportCost(newVehicle.getStartLocation(), currentRoute.getActivities().get(0).getLocation(), newVehicleDepartureTime, newDriver, newVehicle); - double accessTransportCostOld = routingCosts.getTransportCost(currentRoute.getStart().getLocation(), currentRoute.getActivities().get(0).getLocation(), currentRoute.getDepartureTime(), currentRoute.getDriver(), currentRoute.getVehicle()); - - delta_access = accessTransportCostNew - accessTransportCostOld; - - if(newVehicle.isReturnToDepot()){ - TourActivity lastActivityBeforeEndOfRoute = currentRoute.getActivities().get(currentRoute.getActivities().size()-1); - double lastActivityEndTimeWithOldVehicleAndDepartureTime = lastActivityBeforeEndOfRoute.getEndTime(); - double lastActivityEndTimeEstimationWithNewVehicleAndNewDepartureTime = Math.max(0.0, lastActivityEndTimeWithOldVehicleAndDepartureTime + (newVehicleDepartureTime - currentRoute.getDepartureTime())); - double egressTransportCostNew = routingCosts.getTransportCost(lastActivityBeforeEndOfRoute.getLocation(), newVehicle.getEndLocation() , lastActivityEndTimeEstimationWithNewVehicleAndNewDepartureTime, newDriver, newVehicle); - double egressTransportCostOld = routingCosts.getTransportCost(lastActivityBeforeEndOfRoute.getLocation(), currentRoute.getEnd().getLocation(), lastActivityEndTimeWithOldVehicleAndDepartureTime, currentRoute.getDriver(), currentRoute.getVehicle()); - - delta_egress = egressTransportCostNew - egressTransportCostOld; - } - } - return delta_access + delta_egress; - } - + + private VehicleRoutingTransportCosts routingCosts; + + /** + * Constructs the estimator that estimates additional access/egress costs when operating route with a new vehicle that has different start/end-location. + *

+ *

If two vehicles have the same start/end-location and departure-time .getCosts(...) must return zero. + * + * @author schroeder + */ + public AdditionalAccessEgressCalculator(VehicleRoutingTransportCosts routingCosts) { + this.routingCosts = routingCosts; + } + + public double getCosts(JobInsertionContext insertionContext) { + double delta_access = 0.0; + double delta_egress = 0.0; + VehicleRoute currentRoute = insertionContext.getRoute(); + Vehicle newVehicle = insertionContext.getNewVehicle(); + Driver newDriver = insertionContext.getNewDriver(); + double newVehicleDepartureTime = insertionContext.getNewDepTime(); + if (!currentRoute.isEmpty()) { + double accessTransportCostNew = routingCosts.getTransportCost(newVehicle.getStartLocation(), currentRoute.getActivities().get(0).getLocation(), newVehicleDepartureTime, newDriver, newVehicle); + double accessTransportCostOld = routingCosts.getTransportCost(currentRoute.getStart().getLocation(), currentRoute.getActivities().get(0).getLocation(), currentRoute.getDepartureTime(), currentRoute.getDriver(), currentRoute.getVehicle()); + + delta_access = accessTransportCostNew - accessTransportCostOld; + + if (newVehicle.isReturnToDepot()) { + TourActivity lastActivityBeforeEndOfRoute = currentRoute.getActivities().get(currentRoute.getActivities().size() - 1); + double lastActivityEndTimeWithOldVehicleAndDepartureTime = lastActivityBeforeEndOfRoute.getEndTime(); + double lastActivityEndTimeEstimationWithNewVehicleAndNewDepartureTime = Math.max(0.0, lastActivityEndTimeWithOldVehicleAndDepartureTime + (newVehicleDepartureTime - currentRoute.getDepartureTime())); + double egressTransportCostNew = routingCosts.getTransportCost(lastActivityBeforeEndOfRoute.getLocation(), newVehicle.getEndLocation(), lastActivityEndTimeEstimationWithNewVehicleAndNewDepartureTime, newDriver, newVehicle); + double egressTransportCostOld = routingCosts.getTransportCost(lastActivityBeforeEndOfRoute.getLocation(), currentRoute.getEnd().getLocation(), lastActivityEndTimeWithOldVehicleAndDepartureTime, currentRoute.getDriver(), currentRoute.getVehicle()); + + delta_egress = egressTransportCostNew - egressTransportCostOld; + } + } + return delta_access + delta_egress; + } + } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/AuxilliaryCostCalculator.java b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/AuxilliaryCostCalculator.java index b604e626..c8ab1b1d 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/AuxilliaryCostCalculator.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/AuxilliaryCostCalculator.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.recreate; @@ -27,54 +27,52 @@ import java.util.Iterator; import java.util.List; - final class AuxilliaryCostCalculator { - - private final VehicleRoutingTransportCosts routingCosts; - - private final VehicleRoutingActivityCosts activityCosts; - public AuxilliaryCostCalculator(final VehicleRoutingTransportCosts routingCosts, final VehicleRoutingActivityCosts actCosts) { - super(); - this.routingCosts = routingCosts; - this.activityCosts = actCosts; - } + private final VehicleRoutingTransportCosts routingCosts; + + private final VehicleRoutingActivityCosts activityCosts; + + public AuxilliaryCostCalculator(final VehicleRoutingTransportCosts routingCosts, final VehicleRoutingActivityCosts actCosts) { + super(); + this.routingCosts = routingCosts; + this.activityCosts = actCosts; + } /** - * - * @param path activity path to get the costs for + * @param path activity path to get the costs for * @param depTime departure time at first activity in path - * @param driver driver of vehicle + * @param driver driver of vehicle * @param vehicle vehicle running the path * @return cost of path */ - public double costOfPath(final List path, final double depTime, final Driver driver, final Vehicle vehicle){ - if(path.isEmpty()){ - return 0.0; - } - double cost = 0.0; - Iterator actIter = path.iterator(); - TourActivity prevAct = actIter.next(); - double startCost = 0.0; - cost += startCost; - double departureTimePrevAct = depTime; - while(actIter.hasNext()){ - TourActivity act = actIter.next(); - if(act instanceof End){ - if(!vehicle.isReturnToDepot()){ - return cost; - } - } - double transportCost = routingCosts.getTransportCost(prevAct.getLocation(), act.getLocation(), departureTimePrevAct, driver, vehicle); - double transportTime = routingCosts.getTransportTime(prevAct.getLocation(), act.getLocation(), departureTimePrevAct, driver, vehicle); - cost += transportCost; - double actStartTime = departureTimePrevAct + transportTime; + public double costOfPath(final List path, final double depTime, final Driver driver, final Vehicle vehicle) { + if (path.isEmpty()) { + return 0.0; + } + double cost = 0.0; + Iterator actIter = path.iterator(); + TourActivity prevAct = actIter.next(); + double startCost = 0.0; + cost += startCost; + double departureTimePrevAct = depTime; + while (actIter.hasNext()) { + TourActivity act = actIter.next(); + if (act instanceof End) { + if (!vehicle.isReturnToDepot()) { + return cost; + } + } + double transportCost = routingCosts.getTransportCost(prevAct.getLocation(), act.getLocation(), departureTimePrevAct, driver, vehicle); + double transportTime = routingCosts.getTransportTime(prevAct.getLocation(), act.getLocation(), departureTimePrevAct, driver, vehicle); + cost += transportCost; + double actStartTime = departureTimePrevAct + transportTime; departureTimePrevAct = Math.max(actStartTime, act.getTheoreticalEarliestOperationStartTime()) + act.getOperationTime(); - cost += activityCosts.getActivityCost(act, actStartTime, driver, vehicle); - prevAct = act; - } - return cost; - } - - + cost += activityCosts.getActivityCost(act, actStartTime, driver, vehicle); + prevAct = act; + } + return cost; + } + + } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/BestInsertion.java b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/BestInsertion.java index e79e9632..c48a041e 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/BestInsertion.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/BestInsertion.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.recreate; @@ -30,70 +30,67 @@ import java.util.Collections; import java.util.List; - - /** * Best insertion that insert the job where additional costs are minimal. * * @author stefan schroeder - * */ -public final class BestInsertion extends AbstractInsertionStrategy{ +public final class BestInsertion extends AbstractInsertionStrategy { - private static Logger logger = LogManager.getLogger(BestInsertion.class); + private static Logger logger = LogManager.getLogger(BestInsertion.class); - private JobInsertionCostsCalculator bestInsertionCostCalculator; + private JobInsertionCostsCalculator bestInsertionCostCalculator; - private NoiseMaker noiseMaker = new NoiseMaker() { + private NoiseMaker noiseMaker = new NoiseMaker() { - @Override - public double makeNoise() { - return 0; - } + @Override + public double makeNoise() { + return 0; + } - }; + }; - public BestInsertion(JobInsertionCostsCalculator jobInsertionCalculator, VehicleRoutingProblem vehicleRoutingProblem) { - super(vehicleRoutingProblem); - bestInsertionCostCalculator = jobInsertionCalculator; - logger.debug("initialise " + this); - } + public BestInsertion(JobInsertionCostsCalculator jobInsertionCalculator, VehicleRoutingProblem vehicleRoutingProblem) { + super(vehicleRoutingProblem); + bestInsertionCostCalculator = jobInsertionCalculator; + logger.debug("initialise {}", this); + } - @Override - public String toString() { - return "[name=bestInsertion]"; - } + @Override + public String toString() { + return "[name=bestInsertion]"; + } - @Override - public Collection insertUnassignedJobs(Collection vehicleRoutes, Collection unassignedJobs) { + @Override + public Collection insertUnassignedJobs(Collection vehicleRoutes, Collection unassignedJobs) { List badJobs = new ArrayList(unassignedJobs.size()); List unassignedJobList = new ArrayList(unassignedJobs); - Collections.shuffle(unassignedJobList, random); - for(Job unassignedJob : unassignedJobList){ - Insertion bestInsertion = null; - double bestInsertionCost = Double.MAX_VALUE; - for(VehicleRoute vehicleRoute : vehicleRoutes){ - InsertionData iData = bestInsertionCostCalculator.getInsertionData(vehicleRoute, unassignedJob, NO_NEW_VEHICLE_YET, NO_NEW_DEPARTURE_TIME_YET, NO_NEW_DRIVER_YET, bestInsertionCost); - if(iData instanceof NoInsertionFound) { - continue; - } - if(iData.getInsertionCost() < bestInsertionCost + noiseMaker.makeNoise()){ - bestInsertion = new Insertion(vehicleRoute,iData); - bestInsertionCost = iData.getInsertionCost(); - } - } + Collections.shuffle(unassignedJobList, random); + for (Job unassignedJob : unassignedJobList) { + Insertion bestInsertion = null; + double bestInsertionCost = Double.MAX_VALUE; + for (VehicleRoute vehicleRoute : vehicleRoutes) { + InsertionData iData = bestInsertionCostCalculator.getInsertionData(vehicleRoute, unassignedJob, NO_NEW_VEHICLE_YET, NO_NEW_DEPARTURE_TIME_YET, NO_NEW_DRIVER_YET, bestInsertionCost); + if (iData instanceof NoInsertionFound) { + continue; + } + if (iData.getInsertionCost() < bestInsertionCost + noiseMaker.makeNoise()) { + bestInsertion = new Insertion(vehicleRoute, iData); + bestInsertionCost = iData.getInsertionCost(); + } + } VehicleRoute newRoute = VehicleRoute.emptyRoute(); InsertionData newIData = bestInsertionCostCalculator.getInsertionData(newRoute, unassignedJob, NO_NEW_VEHICLE_YET, NO_NEW_DEPARTURE_TIME_YET, NO_NEW_DRIVER_YET, bestInsertionCost); - if(!(newIData instanceof NoInsertionFound)){ - if(newIData.getInsertionCost() < bestInsertionCost + noiseMaker.makeNoise()){ - bestInsertion = new Insertion(newRoute,newIData); + if (!(newIData instanceof NoInsertionFound)) { + if (newIData.getInsertionCost() < bestInsertionCost + noiseMaker.makeNoise()) { + bestInsertion = new Insertion(newRoute, newIData); vehicleRoutes.add(newRoute); } } - if(bestInsertion == null) badJobs.add(unassignedJob); + if (bestInsertion == null) badJobs.add(unassignedJob); else insertJob(unassignedJob, bestInsertion.getInsertionData(), bestInsertion.getRoute()); } return badJobs; - } + } } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/BestInsertionBuilder.java b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/BestInsertionBuilder.java index ac4eb1a5..badbadce 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/BestInsertionBuilder.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/BestInsertionBuilder.java @@ -30,150 +30,154 @@ import java.util.concurrent.ExecutorService; public class BestInsertionBuilder { - private VehicleRoutingProblem vrp; - - private StateManager stateManager; - - private boolean local = true; - - private ConstraintManager constraintManager; + private VehicleRoutingProblem vrp; - private VehicleFleetManager fleetManager; + private StateManager stateManager; - private double weightOfFixedCosts; + private boolean local = true; - private boolean considerFixedCosts = false; + private ConstraintManager constraintManager; - private ActivityInsertionCostsCalculator actInsertionCostsCalculator = null; + private VehicleFleetManager fleetManager; - private int forwaredLooking; + private double weightOfFixedCosts; - private int memory; + private boolean considerFixedCosts = false; - private ExecutorService executor; + private ActivityInsertionCostsCalculator actInsertionCostsCalculator = null; - private int nuOfThreads; + private int forwaredLooking; - private double timeSlice; + private int memory; - private int nNeighbors; + private ExecutorService executor; - private boolean timeScheduling=false; + private int nuOfThreads; - private boolean allowVehicleSwitch=true; + private double timeSlice; - private boolean addDefaultCostCalc=true; - - public BestInsertionBuilder(VehicleRoutingProblem vrp, VehicleFleetManager vehicleFleetManager, StateManager stateManager, ConstraintManager constraintManager) { - super(); - this.vrp = vrp; - this.stateManager = stateManager; - this.constraintManager = constraintManager; - this.fleetManager = vehicleFleetManager; - } - - public BestInsertionBuilder setRouteLevel(int forwardLooking, int memory){ - local = false; - this.forwaredLooking = forwardLooking; - this.memory = memory; - return this; - }; - - public BestInsertionBuilder setRouteLevel(int forwardLooking, int memory, boolean addDefaultMarginalCostCalculation){ - local = false; - this.forwaredLooking = forwardLooking; - this.memory = memory; - this.addDefaultCostCalc = addDefaultMarginalCostCalculation; - return this; - }; - - public BestInsertionBuilder setLocalLevel(){ - local = true; - return this; - }; - - /** - * If addDefaulMarginalCostCalculation is false, no calculator is set which implicitly assumes that marginal cost calculation - * is controlled by your custom soft constraints. - * - * @param addDefaultMarginalCostCalculation - * @return - */ - public BestInsertionBuilder setLocalLevel(boolean addDefaultMarginalCostCalculation){ - local = true; - addDefaultCostCalc = addDefaultMarginalCostCalculation; - return this; - } - - public BestInsertionBuilder considerFixedCosts(double weightOfFixedCosts){ - this.weightOfFixedCosts = weightOfFixedCosts; - this.considerFixedCosts = true; - return this; - } - - public BestInsertionBuilder setActivityInsertionCostCalculator(ActivityInsertionCostsCalculator activityInsertionCostsCalculator){ - this.actInsertionCostsCalculator = activityInsertionCostsCalculator; - return this; - }; - - public BestInsertionBuilder setConcurrentMode(ExecutorService executor, int nuOfThreads){ - this.executor = executor; - this.nuOfThreads = nuOfThreads; - return this; - } - - - public InsertionStrategy build() { - List iListeners = new ArrayList(); - List algorithmListeners = new ArrayList(); - JobInsertionCostsCalculatorBuilder calcBuilder = new JobInsertionCostsCalculatorBuilder(iListeners, algorithmListeners); - if(local){ - calcBuilder.setLocalLevel(addDefaultCostCalc); - } - else { - calcBuilder.setRouteLevel(forwaredLooking, memory, addDefaultCostCalc); - } - calcBuilder.setConstraintManager(constraintManager); - calcBuilder.setStateManager(stateManager); - calcBuilder.setVehicleRoutingProblem(vrp); - calcBuilder.setVehicleFleetManager(fleetManager); - calcBuilder.setActivityInsertionCostsCalculator(actInsertionCostsCalculator); - if(considerFixedCosts) { - calcBuilder.considerFixedCosts(weightOfFixedCosts); - } - if(timeScheduling){ - calcBuilder.experimentalTimeScheduler(timeSlice, nNeighbors); - } - calcBuilder.setAllowVehicleSwitch(allowVehicleSwitch); - JobInsertionCostsCalculator jobInsertions = calcBuilder.build(); - InsertionStrategy bestInsertion; - if(executor == null){ - bestInsertion = new BestInsertion(jobInsertions,vrp); - } - else{ - bestInsertion = new BestInsertionConcurrent(jobInsertions,executor,nuOfThreads,vrp); + private int nNeighbors; + + private boolean timeScheduling = false; + + private boolean allowVehicleSwitch = true; + + private boolean addDefaultCostCalc = true; + + public BestInsertionBuilder(VehicleRoutingProblem vrp, VehicleFleetManager vehicleFleetManager, StateManager stateManager, ConstraintManager constraintManager) { + super(); + this.vrp = vrp; + this.stateManager = stateManager; + this.constraintManager = constraintManager; + this.fleetManager = vehicleFleetManager; + } + + public BestInsertionBuilder setRouteLevel(int forwardLooking, int memory) { + local = false; + this.forwaredLooking = forwardLooking; + this.memory = memory; + return this; + } + + ; + + public BestInsertionBuilder setRouteLevel(int forwardLooking, int memory, boolean addDefaultMarginalCostCalculation) { + local = false; + this.forwaredLooking = forwardLooking; + this.memory = memory; + this.addDefaultCostCalc = addDefaultMarginalCostCalculation; + return this; + } + + ; + + public BestInsertionBuilder setLocalLevel() { + local = true; + return this; + } + + ; + + /** + * If addDefaulMarginalCostCalculation is false, no calculator is set which implicitly assumes that marginal cost calculation + * is controlled by your custom soft constraints. + * + * @param addDefaultMarginalCostCalculation + * @return + */ + public BestInsertionBuilder setLocalLevel(boolean addDefaultMarginalCostCalculation) { + local = true; + addDefaultCostCalc = addDefaultMarginalCostCalculation; + return this; + } + + public BestInsertionBuilder considerFixedCosts(double weightOfFixedCosts) { + this.weightOfFixedCosts = weightOfFixedCosts; + this.considerFixedCosts = true; + return this; + } + + public BestInsertionBuilder setActivityInsertionCostCalculator(ActivityInsertionCostsCalculator activityInsertionCostsCalculator) { + this.actInsertionCostsCalculator = activityInsertionCostsCalculator; + return this; + } + + ; + + public BestInsertionBuilder setConcurrentMode(ExecutorService executor, int nuOfThreads) { + this.executor = executor; + this.nuOfThreads = nuOfThreads; + return this; + } + + + public InsertionStrategy build() { + List iListeners = new ArrayList(); + List algorithmListeners = new ArrayList(); + JobInsertionCostsCalculatorBuilder calcBuilder = new JobInsertionCostsCalculatorBuilder(iListeners, algorithmListeners); + if (local) { + calcBuilder.setLocalLevel(addDefaultCostCalc); + } else { + calcBuilder.setRouteLevel(forwaredLooking, memory, addDefaultCostCalc); } - for(InsertionListener l : iListeners) bestInsertion.addListener(l); - return bestInsertion; - } + calcBuilder.setConstraintManager(constraintManager); + calcBuilder.setStateManager(stateManager); + calcBuilder.setVehicleRoutingProblem(vrp); + calcBuilder.setVehicleFleetManager(fleetManager); + calcBuilder.setActivityInsertionCostsCalculator(actInsertionCostsCalculator); + if (considerFixedCosts) { + calcBuilder.considerFixedCosts(weightOfFixedCosts); + } + if (timeScheduling) { + calcBuilder.experimentalTimeScheduler(timeSlice, nNeighbors); + } + calcBuilder.setAllowVehicleSwitch(allowVehicleSwitch); + JobInsertionCostsCalculator jobInsertions = calcBuilder.build(); + InsertionStrategy bestInsertion; + if (executor == null) { + bestInsertion = new BestInsertion(jobInsertions, vrp); + } else { + bestInsertion = new BestInsertionConcurrent(jobInsertions, executor, nuOfThreads, vrp); + } + for (InsertionListener l : iListeners) bestInsertion.addListener(l); + return bestInsertion; + } - /** - * @deprecated this is experimental and can disappear. - * @param timeSlice the time slice - * @param nNeighbors number of neighbors - */ - @Deprecated - public void experimentalTimeScheduler(double timeSlice, int nNeighbors) { - this.timeSlice=timeSlice; - this.nNeighbors=nNeighbors; - timeScheduling=true; - } + /** + * @param timeSlice the time slice + * @param nNeighbors number of neighbors + * @deprecated this is experimental and can disappear. + */ + @Deprecated + public void experimentalTimeScheduler(double timeSlice, int nNeighbors) { + this.timeSlice = timeSlice; + this.nNeighbors = nNeighbors; + timeScheduling = true; + } - public void setAllowVehicleSwitch(boolean allowVehicleSwitch) { - this.allowVehicleSwitch = allowVehicleSwitch; - } - - + public void setAllowVehicleSwitch(boolean allowVehicleSwitch) { + this.allowVehicleSwitch = allowVehicleSwitch; + } } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/BestInsertionConcurrent.java b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/BestInsertionConcurrent.java index 8ff2824e..de43da1b 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/BestInsertionConcurrent.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/BestInsertionConcurrent.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.recreate; @@ -30,171 +30,163 @@ import java.util.*; import java.util.concurrent.*; - - /** - * * @author stefan schroeder - * */ -public final class BestInsertionConcurrent extends AbstractInsertionStrategy{ - - static class Batch { - List routes = new ArrayList(); - - } - - class Insertion { - - private final VehicleRoute route; - - private final InsertionData insertionData; +public final class BestInsertionConcurrent extends AbstractInsertionStrategy { - public Insertion(VehicleRoute vehicleRoute, InsertionData insertionData) { - super(); - this.route = vehicleRoute; - this.insertionData = insertionData; - } + static class Batch { + List routes = new ArrayList(); - public VehicleRoute getRoute() { - return route; - } - - public InsertionData getInsertionData() { - return insertionData; - } - - } - - private static Logger logger = LogManager.getLogger(BestInsertionConcurrent.class); - - private final static double NO_NEW_DEPARTURE_TIME_YET = -12345.12345; - - private final static Vehicle NO_NEW_VEHICLE_YET = null; - - private final static Driver NO_NEW_DRIVER_YET = null; - - private InsertionListeners insertionsListeners; - - private JobInsertionCostsCalculator bestInsertionCostCalculator; + } - private int nuOfBatches; + class Insertion { - private ExecutorCompletionService completionService; + private final VehicleRoute route; - @Deprecated - public void setRandom(Random random) { - super.random = random; - } - - public BestInsertionConcurrent(JobInsertionCostsCalculator jobInsertionCalculator, ExecutorService executorService, int nuOfBatches, VehicleRoutingProblem vehicleRoutingProblem) { - super(vehicleRoutingProblem); - this.insertionsListeners = new InsertionListeners(); - this.nuOfBatches = nuOfBatches; - bestInsertionCostCalculator = jobInsertionCalculator; - completionService = new ExecutorCompletionService(executorService); - logger.debug("initialise " + this); - } + private final InsertionData insertionData; - @Override - public String toString() { - return "[name=bestInsertion]"; - } + public Insertion(VehicleRoute vehicleRoute, InsertionData insertionData) { + super(); + this.route = vehicleRoute; + this.insertionData = insertionData; + } - @Override - public Collection insertUnassignedJobs(Collection vehicleRoutes, Collection unassignedJobs) { - List badJobs = new ArrayList(unassignedJobs.size()); - List unassignedJobList = new ArrayList(unassignedJobs); - Collections.shuffle(unassignedJobList, random); - List batches = distributeRoutes(vehicleRoutes,nuOfBatches); - for(final Job unassignedJob : unassignedJobList){ - Insertion bestInsertion = null; - double bestInsertionCost = Double.MAX_VALUE; - for(final Batch batch : batches){ - completionService.submit(new Callable() { + public VehicleRoute getRoute() { + return route; + } - @Override - public Insertion call() throws Exception { - return getBestInsertion(batch,unassignedJob); - } + public InsertionData getInsertionData() { + return insertionData; + } - }); - } - try { - for (int i = 0; i < batches.size(); i++) { - Future futureIData = completionService.take(); - Insertion insertion = futureIData.get(); - if (insertion == null) continue; - if (insertion.getInsertionData().getInsertionCost() < bestInsertionCost) { - bestInsertion = insertion; - bestInsertionCost = insertion.getInsertionData().getInsertionCost(); - } - } - } catch(InterruptedException e){ - Thread.currentThread().interrupt(); - } - catch (ExecutionException e) { - e.printStackTrace(); - logger.error(e.getCause().toString()); - System.exit(1); - } - VehicleRoute newRoute = VehicleRoute.emptyRoute(); - InsertionData newIData = bestInsertionCostCalculator.getInsertionData(newRoute, unassignedJob, NO_NEW_VEHICLE_YET, NO_NEW_DEPARTURE_TIME_YET, NO_NEW_DRIVER_YET, bestInsertionCost); - if(newIData.getInsertionCost() < bestInsertionCost){ - bestInsertion = new Insertion(newRoute,newIData); - vehicleRoutes.add(newRoute); - batches.get(random.nextInt(batches.size())).routes.add(newRoute); - } - if(bestInsertion == null) badJobs.add(unassignedJob); - else insertJob(unassignedJob, bestInsertion.getInsertionData(), bestInsertion.getRoute()); - } - return badJobs; - } - - private Insertion getBestInsertion(Batch batch, Job unassignedJob) { - Insertion bestInsertion = null; - double bestInsertionCost = Double.MAX_VALUE; - for(VehicleRoute vehicleRoute : batch.routes){ - InsertionData iData = bestInsertionCostCalculator.getInsertionData(vehicleRoute, unassignedJob, NO_NEW_VEHICLE_YET, NO_NEW_DEPARTURE_TIME_YET, NO_NEW_DRIVER_YET, bestInsertionCost); - if(iData instanceof NoInsertionFound) { - continue; - } - if(iData.getInsertionCost() < bestInsertionCost){ - bestInsertion = new Insertion(vehicleRoute,iData); - bestInsertionCost = iData.getInsertionCost(); - } - } - return bestInsertion; - } - - private List distributeRoutes(Collection vehicleRoutes, int nuOfBatches) { - List batches = new ArrayList(); - for(int i=0;i completionService; + + @Deprecated + public void setRandom(Random random) { + super.random = random; + } + + public BestInsertionConcurrent(JobInsertionCostsCalculator jobInsertionCalculator, ExecutorService executorService, int nuOfBatches, VehicleRoutingProblem vehicleRoutingProblem) { + super(vehicleRoutingProblem); + this.insertionsListeners = new InsertionListeners(); + this.nuOfBatches = nuOfBatches; + bestInsertionCostCalculator = jobInsertionCalculator; + completionService = new ExecutorCompletionService(executorService); + logger.debug("initialise {}", this); + } + + @Override + public String toString() { + return "[name=bestInsertion]"; + } + + @Override + public Collection insertUnassignedJobs(Collection vehicleRoutes, Collection unassignedJobs) { + List badJobs = new ArrayList(unassignedJobs.size()); + List unassignedJobList = new ArrayList(unassignedJobs); + Collections.shuffle(unassignedJobList, random); + List batches = distributeRoutes(vehicleRoutes, nuOfBatches); + for (final Job unassignedJob : unassignedJobList) { + Insertion bestInsertion = null; + double bestInsertionCost = Double.MAX_VALUE; + for (final Batch batch : batches) { + completionService.submit(new Callable() { + + @Override + public Insertion call() throws Exception { + return getBestInsertion(batch, unassignedJob); + } + + }); + } + try { + for (int i = 0; i < batches.size(); i++) { + Future futureIData = completionService.take(); + Insertion insertion = futureIData.get(); + if (insertion == null) continue; + if (insertion.getInsertionData().getInsertionCost() < bestInsertionCost) { + bestInsertion = insertion; + bestInsertionCost = insertion.getInsertionData().getInsertionCost(); + } + } + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } catch (ExecutionException e) { + throw new RuntimeException(e); + } + VehicleRoute newRoute = VehicleRoute.emptyRoute(); + InsertionData newIData = bestInsertionCostCalculator.getInsertionData(newRoute, unassignedJob, NO_NEW_VEHICLE_YET, NO_NEW_DEPARTURE_TIME_YET, NO_NEW_DRIVER_YET, bestInsertionCost); + if (newIData.getInsertionCost() < bestInsertionCost) { + bestInsertion = new Insertion(newRoute, newIData); + vehicleRoutes.add(newRoute); + batches.get(random.nextInt(batches.size())).routes.add(newRoute); + } + if (bestInsertion == null) badJobs.add(unassignedJob); + else insertJob(unassignedJob, bestInsertion.getInsertionData(), bestInsertion.getRoute()); + } + return badJobs; + } + + private Insertion getBestInsertion(Batch batch, Job unassignedJob) { + Insertion bestInsertion = null; + double bestInsertionCost = Double.MAX_VALUE; + for (VehicleRoute vehicleRoute : batch.routes) { + InsertionData iData = bestInsertionCostCalculator.getInsertionData(vehicleRoute, unassignedJob, NO_NEW_VEHICLE_YET, NO_NEW_DEPARTURE_TIME_YET, NO_NEW_DRIVER_YET, bestInsertionCost); + if (iData instanceof NoInsertionFound) { + continue; + } + if (iData.getInsertionCost() < bestInsertionCost) { + bestInsertion = new Insertion(vehicleRoute, iData); + bestInsertionCost = iData.getInsertionCost(); + } + } + return bestInsertion; + } + + private List distributeRoutes(Collection vehicleRoutes, int nuOfBatches) { + List batches = new ArrayList(); + for (int i = 0; i < nuOfBatches; i++) batches.add(new Batch()); + /* + * if route.size < nuOfBatches add as much routes as empty batches are available * else add one empty route anyway */ - if(vehicleRoutes.size(). + ******************************************************************************/ +package jsprit.core.algorithm.recreate; + +import jsprit.core.problem.JobActivityFactory; +import jsprit.core.problem.Location; +import jsprit.core.problem.constraint.*; +import jsprit.core.problem.constraint.HardActivityConstraint.ConstraintsStatus; +import jsprit.core.problem.cost.VehicleRoutingTransportCosts; +import jsprit.core.problem.driver.Driver; +import jsprit.core.problem.job.Break; +import jsprit.core.problem.job.Job; +import jsprit.core.problem.misc.JobInsertionContext; +import jsprit.core.problem.solution.route.VehicleRoute; +import jsprit.core.problem.solution.route.activity.BreakActivity; +import jsprit.core.problem.solution.route.activity.End; +import jsprit.core.problem.solution.route.activity.Start; +import jsprit.core.problem.solution.route.activity.TourActivity; +import jsprit.core.problem.vehicle.Vehicle; +import jsprit.core.util.CalculationUtils; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; + +/** + * Calculator that calculates the best insertion position for a {@link jsprit.core.problem.job.Service}. + * + * @author schroeder + */ +final class BreakInsertionCalculator implements JobInsertionCostsCalculator { + + private static final Logger logger = LogManager.getLogger(BreakInsertionCalculator.class); + + private HardRouteConstraint hardRouteLevelConstraint; + + private HardActivityConstraint hardActivityLevelConstraint; + + private SoftRouteConstraint softRouteConstraint; + + private SoftActivityConstraint softActivityConstraint; + + private VehicleRoutingTransportCosts transportCosts; + + private ActivityInsertionCostsCalculator additionalTransportCostsCalculator; + + private JobActivityFactory activityFactory; + + private AdditionalAccessEgressCalculator additionalAccessEgressCalculator; + + public BreakInsertionCalculator(VehicleRoutingTransportCosts routingCosts, ActivityInsertionCostsCalculator additionalTransportCostsCalculator, ConstraintManager constraintManager) { + super(); + this.transportCosts = routingCosts; + hardRouteLevelConstraint = constraintManager; + hardActivityLevelConstraint = constraintManager; + softActivityConstraint = constraintManager; + softRouteConstraint = constraintManager; + this.additionalTransportCostsCalculator = additionalTransportCostsCalculator; + additionalAccessEgressCalculator = new AdditionalAccessEgressCalculator(routingCosts); + logger.debug("initialise " + this); + } + + public void setJobActivityFactory(JobActivityFactory jobActivityFactory) { + this.activityFactory = jobActivityFactory; + } + + @Override + public String toString() { + return "[name=calculatesServiceInsertion]"; + } + + /** + * Calculates the marginal cost of inserting job i locally. This is based on the + * assumption that cost changes can entirely covered by only looking at the predecessor i-1 and its successor i+1. + */ + @Override + public InsertionData getInsertionData(final VehicleRoute currentRoute, final Job jobToInsert, final Vehicle newVehicle, double newVehicleDepartureTime, final Driver newDriver, final double bestKnownCosts) { + Break breakToInsert = (Break) jobToInsert; + if (newVehicle.getBreak() == null || newVehicle.getBreak() != breakToInsert) { + return InsertionData.createEmptyInsertionData(); + } + if (currentRoute.isEmpty()) return InsertionData.createEmptyInsertionData(); + + JobInsertionContext insertionContext = new JobInsertionContext(currentRoute, jobToInsert, newVehicle, newDriver, newVehicleDepartureTime); + int insertionIndex = InsertionData.NO_INDEX; + + BreakActivity breakAct2Insert = (BreakActivity) activityFactory.createActivities(breakToInsert).get(0); + insertionContext.getAssociatedActivities().add(breakAct2Insert); + + /* + check hard constraints at route level + */ + if (!hardRouteLevelConstraint.fulfilled(insertionContext)) { + return InsertionData.createEmptyInsertionData(); + } + + /* + check soft constraints at route level + */ + double additionalICostsAtRouteLevel = softRouteConstraint.getCosts(insertionContext); + + double bestCost = bestKnownCosts; + additionalICostsAtRouteLevel += additionalAccessEgressCalculator.getCosts(insertionContext); + + /* + generate new start and end for new vehicle + */ + Start start = new Start(newVehicle.getStartLocation(), newVehicle.getEarliestDeparture(), Double.MAX_VALUE); + start.setEndTime(newVehicleDepartureTime); + End end = new End(newVehicle.getEndLocation(), 0.0, newVehicle.getLatestArrival()); + + Location bestLocation = null; + + TourActivity prevAct = start; + double prevActStartTime = newVehicleDepartureTime; + int actIndex = 0; + Iterator activityIterator = currentRoute.getActivities().iterator(); + boolean tourEnd = false; + while (!tourEnd) { + TourActivity nextAct; + if (activityIterator.hasNext()) nextAct = activityIterator.next(); + else { + nextAct = end; + tourEnd = true; + } + boolean breakThis = true; + List locations = Arrays.asList(prevAct.getLocation(), nextAct.getLocation()); + for (Location location : locations) { + breakAct2Insert.setLocation(location); + ConstraintsStatus status = hardActivityLevelConstraint.fulfilled(insertionContext, prevAct, breakAct2Insert, nextAct, prevActStartTime); + if (status.equals(ConstraintsStatus.FULFILLED)) { + //from job2insert induced costs at activity level + double additionalICostsAtActLevel = softActivityConstraint.getCosts(insertionContext, prevAct, breakAct2Insert, nextAct, prevActStartTime); + double additionalTransportationCosts = additionalTransportCostsCalculator.getCosts(insertionContext, prevAct, nextAct, breakAct2Insert, prevActStartTime); + if (additionalICostsAtRouteLevel + additionalICostsAtActLevel + additionalTransportationCosts < bestCost) { + bestCost = additionalICostsAtRouteLevel + additionalICostsAtActLevel + additionalTransportationCosts; + insertionIndex = actIndex; + bestLocation = location; + } + breakThis = false; + } else if (status.equals(ConstraintsStatus.NOT_FULFILLED)) { + breakThis = false; + } + } + double nextActArrTime = prevActStartTime + transportCosts.getTransportTime(prevAct.getLocation(), nextAct.getLocation(), prevActStartTime, newDriver, newVehicle); + prevActStartTime = CalculationUtils.getActivityEndTime(nextActArrTime, nextAct); + prevAct = nextAct; + actIndex++; + if (breakThis) break; + } + if (insertionIndex == InsertionData.NO_INDEX) { + return InsertionData.createEmptyInsertionData(); + } + InsertionData insertionData = new InsertionData(bestCost, InsertionData.NO_INDEX, insertionIndex, newVehicle, newDriver); + breakAct2Insert.setLocation(bestLocation); + insertionData.getEvents().add(new InsertBreak(currentRoute, newVehicle, breakAct2Insert, insertionIndex)); + insertionData.getEvents().add(new SwitchVehicle(currentRoute, newVehicle, newVehicleDepartureTime)); + insertionData.setVehicleDepartureTime(newVehicleDepartureTime); + return insertionData; + } + + +} diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/CalculatesServiceInsertionWithTimeScheduling.java b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/CalculatesServiceInsertionWithTimeScheduling.java index eacf36a5..06be01a6 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/CalculatesServiceInsertionWithTimeScheduling.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/CalculatesServiceInsertionWithTimeScheduling.java @@ -15,22 +15,24 @@ import java.util.List; import java.util.Random; -class CalculatesServiceInsertionWithTimeScheduling implements JobInsertionCostsCalculator{ +class CalculatesServiceInsertionWithTimeScheduling implements JobInsertionCostsCalculator { public static class KnowledgeInjection implements InsertionStartsListener { private CalculatesServiceInsertionWithTimeScheduling c; + public KnowledgeInjection(CalculatesServiceInsertionWithTimeScheduling c) { super(); this.c = c; } + @Override - public void informInsertionStarts(Collection vehicleRoutes,Collection unassignedJobs) { + public void informInsertionStarts(Collection vehicleRoutes, Collection unassignedJobs) { List knowledge = new ArrayList(); - if(vehicleRoutes.isEmpty()){ + if (vehicleRoutes.isEmpty()) { // System.out.println("hmm"); } - for(VehicleRoute route : vehicleRoutes){ + for (VehicleRoute route : vehicleRoutes) { // if(route.getDepartureTime() == 21600.){ // System.out.println("hu"); // } @@ -60,18 +62,17 @@ class CalculatesServiceInsertionWithTimeScheduling implements JobInsertionCostsC @Override public String toString() { - return "[name="+this.getClass().toString()+"]"; + return "[name=" + this.getClass().toString() + "]"; } @Override public InsertionData getInsertionData(VehicleRoute currentRoute, Job jobToInsert, Vehicle newVehicle, double newVehicleDepartureTime, Driver newDriver, double bestKnownScore) { double departureTime = newVehicleDepartureTime; - if(currentRoute.isEmpty()){ - if(!departureTimeKnowledge.isEmpty()){ + if (currentRoute.isEmpty()) { + if (!departureTimeKnowledge.isEmpty()) { departureTime = departureTimeKnowledge.get(random.nextInt(departureTimeKnowledge.size())); } - } - else if(!currentRoute.getVehicle().getId().equals(newVehicle.getId())){ + } else if (!currentRoute.getVehicle().getId().equals(newVehicle.getId())) { departureTime = currentRoute.getDepartureTime(); } @@ -82,7 +83,7 @@ class CalculatesServiceInsertionWithTimeScheduling implements JobInsertionCostsC return insertionData; } - public void setDepartureTimeKnowledge(List departureTimes){ - departureTimeKnowledge=departureTimes; + public void setDepartureTimeKnowledge(List departureTimes) { + departureTimeKnowledge = departureTimes; } } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/CalculatesServiceInsertionWithTimeSchedulingInSlices.java b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/CalculatesServiceInsertionWithTimeSchedulingInSlices.java index 3f6b84aa..d7273c68 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/CalculatesServiceInsertionWithTimeSchedulingInSlices.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/CalculatesServiceInsertionWithTimeSchedulingInSlices.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.recreate; @@ -27,65 +27,64 @@ import java.util.ArrayList; import java.util.List; -class CalculatesServiceInsertionWithTimeSchedulingInSlices implements JobInsertionCostsCalculator{ +class CalculatesServiceInsertionWithTimeSchedulingInSlices implements JobInsertionCostsCalculator { - private static Logger log = LogManager.getLogger(CalculatesServiceInsertionWithTimeSchedulingInSlices.class); - - private JobInsertionCostsCalculator jic; + private static Logger log = LogManager.getLogger(CalculatesServiceInsertionWithTimeSchedulingInSlices.class); - private int nOfDepartureTimes = 3; - - private double timeSlice = 900.0; - - public CalculatesServiceInsertionWithTimeSchedulingInSlices(JobInsertionCostsCalculator jic, double timeSlice, int neighbors) { - super(); - this.jic = jic; - this.timeSlice = timeSlice; - this.nOfDepartureTimes = neighbors; - log.debug("initialise " + this); - } - - @Override - public String toString() { - return "[name="+this.getClass().toString()+"][timeSlice="+timeSlice+"][#timeSlice="+nOfDepartureTimes+"]"; - } + private JobInsertionCostsCalculator jic; - @Override - public InsertionData getInsertionData(VehicleRoute currentRoute, Job jobToInsert, Vehicle newVehicle, double newVehicleDepartureTime, Driver newDriver, double bestKnownScore) { - List vehicleDepartureTimes = new ArrayList(); - double currentStart; - if(currentRoute.getStart() == null){ - currentStart = newVehicleDepartureTime; - } - else currentStart = currentRoute.getStart().getEndTime(); - - vehicleDepartureTimes.add(currentStart); + private int nOfDepartureTimes = 3; + + private double timeSlice = 900.0; + + public CalculatesServiceInsertionWithTimeSchedulingInSlices(JobInsertionCostsCalculator jic, double timeSlice, int neighbors) { + super(); + this.jic = jic; + this.timeSlice = timeSlice; + this.nOfDepartureTimes = neighbors; + log.debug("initialise " + this); + } + + @Override + public String toString() { + return "[name=" + this.getClass().toString() + "][timeSlice=" + timeSlice + "][#timeSlice=" + nOfDepartureTimes + "]"; + } + + @Override + public InsertionData getInsertionData(VehicleRoute currentRoute, Job jobToInsert, Vehicle newVehicle, double newVehicleDepartureTime, Driver newDriver, double bestKnownScore) { + List vehicleDepartureTimes = new ArrayList(); + double currentStart; + if (currentRoute.getStart() == null) { + currentStart = newVehicleDepartureTime; + } else currentStart = currentRoute.getStart().getEndTime(); + + vehicleDepartureTimes.add(currentStart); // double earliestDeparture = newVehicle.getEarliestDeparture(); // double latestEnd = newVehicle.getLatestArrival(); - - for(int i=0;i earliestDeparture) { - vehicleDepartureTimes.add(neighborStartTime_earlier); + vehicleDepartureTimes.add(neighborStartTime_earlier); // } - double neighborStartTime_later = currentStart + (i+1)*timeSlice; + double neighborStartTime_later = currentStart + (i + 1) * timeSlice; // if(neighborStartTime_later < latestEnd) { - vehicleDepartureTimes.add(neighborStartTime_later); + vehicleDepartureTimes.add(neighborStartTime_later); // } - } - - InsertionData bestIData = null; - for(Double departureTime : vehicleDepartureTimes){ - InsertionData iData = jic.getInsertionData(currentRoute, jobToInsert, newVehicle, departureTime, newDriver, bestKnownScore); - if(bestIData == null) bestIData = iData; - else if(iData.getInsertionCost() < bestIData.getInsertionCost()){ - iData.setVehicleDepartureTime(departureTime); - bestIData = iData; - } - } + } + + InsertionData bestIData = null; + for (Double departureTime : vehicleDepartureTimes) { + InsertionData iData = jic.getInsertionData(currentRoute, jobToInsert, newVehicle, departureTime, newDriver, bestKnownScore); + if (bestIData == null) bestIData = iData; + else if (iData.getInsertionCost() < bestIData.getInsertionCost()) { + iData.setVehicleDepartureTime(departureTime); + bestIData = iData; + } + } // log.info(bestIData); - return bestIData; - } + return bestIData; + } } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/ConfigureFixCostCalculator.java b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/ConfigureFixCostCalculator.java index c4f2e2b8..6618da8d 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/ConfigureFixCostCalculator.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/ConfigureFixCostCalculator.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.recreate; @@ -26,38 +26,38 @@ import jsprit.core.problem.solution.route.VehicleRoute; import java.util.Collection; -final class ConfigureFixCostCalculator implements InsertionStartsListener, JobInsertedListener{ +final class ConfigureFixCostCalculator implements InsertionStartsListener, JobInsertedListener { - VehicleRoutingProblem vrp; - - JobInsertionConsideringFixCostsCalculator calcConsideringFix; - - private int nuOfJobsToRecreate; + VehicleRoutingProblem vrp; - public ConfigureFixCostCalculator(VehicleRoutingProblem vrp, JobInsertionConsideringFixCostsCalculator calcConsideringFix) { - super(); - this.vrp = vrp; - this.calcConsideringFix = calcConsideringFix; - } - - @Override - public String toString() { - return "[name=configureFixCostCalculator]"; - } + JobInsertionConsideringFixCostsCalculator calcConsideringFix; - @Override - public void informInsertionStarts(Collection routes, Collection unassignedJobs) { - this.nuOfJobsToRecreate = unassignedJobs.size(); - double completenessRatio = (1-((double)nuOfJobsToRecreate/(double)vrp.getJobs().values().size())); - calcConsideringFix.setSolutionCompletenessRatio(completenessRatio); + private int nuOfJobsToRecreate; + + public ConfigureFixCostCalculator(VehicleRoutingProblem vrp, JobInsertionConsideringFixCostsCalculator calcConsideringFix) { + super(); + this.vrp = vrp; + this.calcConsideringFix = calcConsideringFix; + } + + @Override + public String toString() { + return "[name=configureFixCostCalculator]"; + } + + @Override + public void informInsertionStarts(Collection routes, Collection unassignedJobs) { + this.nuOfJobsToRecreate = unassignedJobs.size(); + double completenessRatio = (1 - ((double) nuOfJobsToRecreate / (double) vrp.getJobs().values().size())); + calcConsideringFix.setSolutionCompletenessRatio(completenessRatio); // log.debug("initialise completenessRatio to " + completenessRatio); - } + } - @Override - public void informJobInserted(Job job2insert, VehicleRoute inRoute, double additionalCosts, double additionalTime) { - nuOfJobsToRecreate--; - double completenessRatio = (1-((double)nuOfJobsToRecreate/(double)vrp.getJobs().values().size())); - calcConsideringFix.setSolutionCompletenessRatio(completenessRatio); + @Override + public void informJobInserted(Job job2insert, VehicleRoute inRoute, double additionalCosts, double additionalTime) { + nuOfJobsToRecreate--; + double completenessRatio = (1 - ((double) nuOfJobsToRecreate / (double) vrp.getJobs().values().size())); + calcConsideringFix.setSolutionCompletenessRatio(completenessRatio); // log.debug("set completenessRatio to " + completenessRatio); - } + } } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/ConfigureLocalActivityInsertionCalculator.java b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/ConfigureLocalActivityInsertionCalculator.java new file mode 100644 index 00000000..fd55558a --- /dev/null +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/ConfigureLocalActivityInsertionCalculator.java @@ -0,0 +1,40 @@ +package jsprit.core.algorithm.recreate; + +import jsprit.core.algorithm.recreate.listener.InsertionStartsListener; +import jsprit.core.algorithm.recreate.listener.JobInsertedListener; +import jsprit.core.problem.VehicleRoutingProblem; +import jsprit.core.problem.job.Job; +import jsprit.core.problem.solution.route.VehicleRoute; + +import java.util.Collection; + +/** + * Created by schroeder on 22/07/15. + */ +public class ConfigureLocalActivityInsertionCalculator implements InsertionStartsListener, JobInsertedListener { + + private VehicleRoutingProblem vrp; + + private LocalActivityInsertionCostsCalculator localActivityInsertionCostsCalculator; + + private int nuOfJobsToRecreate; + + public ConfigureLocalActivityInsertionCalculator(VehicleRoutingProblem vrp, LocalActivityInsertionCostsCalculator localActivityInsertionCostsCalculator) { + this.vrp = vrp; + this.localActivityInsertionCostsCalculator = localActivityInsertionCostsCalculator; + } + + @Override + public void informInsertionStarts(Collection vehicleRoutes, Collection unassignedJobs) { + this.nuOfJobsToRecreate = unassignedJobs.size(); + double completenessRatio = (1 - ((double) nuOfJobsToRecreate / (double) vrp.getJobs().values().size())); + localActivityInsertionCostsCalculator.setSolutionCompletenessRatio(Math.max(0.5, completenessRatio)); + } + + @Override + public void informJobInserted(Job job2insert, VehicleRoute inRoute, double additionalCosts, double additionalTime) { + nuOfJobsToRecreate--; + double completenessRatio = (1 - ((double) nuOfJobsToRecreate / (double) vrp.getJobs().values().size())); + localActivityInsertionCostsCalculator.setSolutionCompletenessRatio(Math.max(0.5, completenessRatio)); + } +} diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/DefaultScorer.java b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/DefaultScorer.java new file mode 100644 index 00000000..44c4f1c7 --- /dev/null +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/DefaultScorer.java @@ -0,0 +1,83 @@ +package jsprit.core.algorithm.recreate; + +import jsprit.core.problem.Location; +import jsprit.core.problem.VehicleRoutingProblem; +import jsprit.core.problem.job.Job; +import jsprit.core.problem.job.Service; +import jsprit.core.problem.job.Shipment; + +/** + * Created by schroeder on 15/10/15. + */ +public class DefaultScorer implements ScoringFunction { + + private VehicleRoutingProblem vrp; + + private double tw_param = -0.5; + + private double depotDistance_param = +0.1; + + private double minTimeWindowScore = -100000; + + public DefaultScorer(VehicleRoutingProblem vrp) { + this.vrp = vrp; + } + + public void setTimeWindowParam(double tw_param) { + this.tw_param = tw_param; + } + + public void setDepotDistanceParam(double depotDistance_param) { + this.depotDistance_param = depotDistance_param; + } + + @Override + public double score(InsertionData best, Job job) { + double score; + if (job instanceof Service) { + score = scoreService(best, job); + } else if (job instanceof Shipment) { + score = scoreShipment(best, job); + } else throw new IllegalStateException("not supported"); + return score; + } + + private double scoreShipment(InsertionData best, Job job) { + Shipment shipment = (Shipment) job; + double maxDepotDistance_1 = Math.max( + getDistance(best.getSelectedVehicle().getStartLocation(), shipment.getPickupLocation()), + getDistance(best.getSelectedVehicle().getStartLocation(), shipment.getDeliveryLocation()) + ); + double maxDepotDistance_2 = Math.max( + getDistance(best.getSelectedVehicle().getEndLocation(), shipment.getPickupLocation()), + getDistance(best.getSelectedVehicle().getEndLocation(), shipment.getDeliveryLocation()) + ); + double maxDepotDistance = Math.max(maxDepotDistance_1, maxDepotDistance_2); + double minTimeToOperate = Math.min(shipment.getPickupTimeWindow().getEnd() - shipment.getPickupTimeWindow().getStart(), + shipment.getDeliveryTimeWindow().getEnd() - shipment.getDeliveryTimeWindow().getStart()); + return Math.max(tw_param * minTimeToOperate, minTimeWindowScore) + depotDistance_param * maxDepotDistance; + } + + private double scoreService(InsertionData best, Job job) { + Location location = ((Service) job).getLocation(); + double maxDepotDistance = 0; + if (location != null) { + maxDepotDistance = Math.max( + getDistance(best.getSelectedVehicle().getStartLocation(), location), + getDistance(best.getSelectedVehicle().getEndLocation(), location) + ); + } + return Math.max(tw_param * (((Service) job).getTimeWindow().getEnd() - ((Service) job).getTimeWindow().getStart()), minTimeWindowScore) + + depotDistance_param * maxDepotDistance; + } + + + private double getDistance(Location loc1, Location loc2) { + return vrp.getTransportCosts().getTransportCost(loc1, loc2, 0., null, null); + } + + @Override + public String toString() { + return "[name=defaultScorer][twParam=" + tw_param + "][depotDistanceParam=" + depotDistance_param + "]"; + } +} diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/DellAmicoFixCostCalculator.java b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/DellAmicoFixCostCalculator.java index 95526692..22f0b5f0 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/DellAmicoFixCostCalculator.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/DellAmicoFixCostCalculator.java @@ -1,18 +1,18 @@ /******************************************************************************* * Copyright (c) 2014 Stefan Schroeder. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . - * + * * Contributors: * Stefan Schroeder - initial API and implementation ******************************************************************************/ @@ -28,38 +28,38 @@ import jsprit.core.problem.solution.route.state.RouteAndActivityStateGetter; import java.util.Collection; -public class DellAmicoFixCostCalculator implements SoftRouteConstraint, InsertionStartsListener, JobInsertedListener{ +public class DellAmicoFixCostCalculator implements SoftRouteConstraint, InsertionStartsListener, JobInsertedListener { - private int nuOfJobsToRecreate; - - private final JobInsertionConsideringFixCostsCalculator calculator; - - private final int nuOfJobs; - - public DellAmicoFixCostCalculator(final int nuOfJobs, final RouteAndActivityStateGetter stateGetter) { - super(); - this.nuOfJobs=nuOfJobs; - calculator = new JobInsertionConsideringFixCostsCalculator(null, stateGetter); - } + private int nuOfJobsToRecreate; - @Override - public double getCosts(JobInsertionContext insertionContext) { - return calculator.getCosts(insertionContext); - } - - @Override - public void informInsertionStarts(Collection routes, Collection unassignedJobs) { - this.nuOfJobsToRecreate = unassignedJobs.size(); - double completenessRatio = (1-((double)nuOfJobsToRecreate/(double)nuOfJobs)); - calculator.setSolutionCompletenessRatio(completenessRatio); - } + private final JobInsertionConsideringFixCostsCalculator calculator; - @Override - public void informJobInserted(Job job2insert, VehicleRoute inRoute, double additionalCosts, double additionalTime) { - nuOfJobsToRecreate--; - double completenessRatio = (1-((double)nuOfJobsToRecreate/(double)nuOfJobs)); - calculator.setSolutionCompletenessRatio(completenessRatio); - System.out.println(completenessRatio); - } + private final int nuOfJobs; + + public DellAmicoFixCostCalculator(final int nuOfJobs, final RouteAndActivityStateGetter stateGetter) { + super(); + this.nuOfJobs = nuOfJobs; + calculator = new JobInsertionConsideringFixCostsCalculator(null, stateGetter); + } + + @Override + public double getCosts(JobInsertionContext insertionContext) { + return calculator.getCosts(insertionContext); + } + + @Override + public void informInsertionStarts(Collection routes, Collection unassignedJobs) { + this.nuOfJobsToRecreate = unassignedJobs.size(); + double completenessRatio = (1 - ((double) nuOfJobsToRecreate / (double) nuOfJobs)); + calculator.setSolutionCompletenessRatio(completenessRatio); + } + + @Override + public void informJobInserted(Job job2insert, VehicleRoute inRoute, double additionalCosts, double additionalTime) { + nuOfJobsToRecreate--; + double completenessRatio = (1 - ((double) nuOfJobsToRecreate / (double) nuOfJobs)); + calculator.setSolutionCompletenessRatio(completenessRatio); + System.out.println(completenessRatio); + } } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/EventListeners.java b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/EventListeners.java index 069bb1b3..2ee92981 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/EventListeners.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/EventListeners.java @@ -13,10 +13,11 @@ class EventListeners { public EventListeners() { listeners.add(new InsertActivityListener()); listeners.add(new SwitchVehicleListener()); + listeners.add(new InsertBreakListener()); } - public void inform(Event event){ - for(EventListener l : listeners){ + public void inform(Event event) { + for (EventListener l : listeners) { l.inform(event); } } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/InsertActivityListener.java b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/InsertActivityListener.java index a9720348..58cc4ce1 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/InsertActivityListener.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/InsertActivityListener.java @@ -7,14 +7,14 @@ class InsertActivityListener implements EventListener { @Override public void inform(Event event) { - if(event instanceof InsertActivity){ + if (event instanceof InsertActivity) { InsertActivity insertActivity = (InsertActivity) event; - if(!insertActivity.getNewVehicle().isReturnToDepot()){ - if(insertActivity.getIndex()>=insertActivity.getVehicleRoute().getActivities().size()){ + if (!insertActivity.getNewVehicle().isReturnToDepot()) { + if (insertActivity.getIndex() >= insertActivity.getVehicleRoute().getActivities().size()) { insertActivity.getVehicleRoute().getEnd().setLocation(insertActivity.getActivity().getLocation()); } } - insertActivity.getVehicleRoute().getTourActivities().addActivity(insertActivity.getIndex(),((InsertActivity) event).getActivity()); + insertActivity.getVehicleRoute().getTourActivities().addActivity(insertActivity.getIndex(), ((InsertActivity) event).getActivity()); } } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/InsertBreak.java b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/InsertBreak.java new file mode 100644 index 00000000..8c5e33d9 --- /dev/null +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/InsertBreak.java @@ -0,0 +1,42 @@ +package jsprit.core.algorithm.recreate; + +import jsprit.core.problem.solution.route.VehicleRoute; +import jsprit.core.problem.solution.route.activity.TourActivity; +import jsprit.core.problem.vehicle.Vehicle; + +/** + * Created by schroeder on 19/05/15. + */ +class InsertBreak implements Event { + + private VehicleRoute vehicleRoute; + + private Vehicle newVehicle; + + private TourActivity activity; + + private int index; + + public InsertBreak(VehicleRoute vehicleRoute, Vehicle newVehicle, TourActivity activity, int index) { + this.vehicleRoute = vehicleRoute; + this.newVehicle = newVehicle; + this.activity = activity; + this.index = index; + } + + public Vehicle getNewVehicle() { + return newVehicle; + } + + public VehicleRoute getVehicleRoute() { + return vehicleRoute; + } + + public TourActivity getActivity() { + return activity; + } + + public int getIndex() { + return index; + } +} diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/InsertBreakListener.java b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/InsertBreakListener.java new file mode 100644 index 00000000..20b8bdca --- /dev/null +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/InsertBreakListener.java @@ -0,0 +1,37 @@ +package jsprit.core.algorithm.recreate; + +import jsprit.core.problem.solution.route.VehicleRoute; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +/** + * Created by schroeder on 19/05/15. + */ +class InsertBreakListener implements EventListener { + + private static final Logger logger = LogManager.getLogger(); + + @Override + public void inform(Event event) { + if (event instanceof InsertBreak) { + InsertBreak insertActivity = (InsertBreak) event; + if (!insertActivity.getNewVehicle().isReturnToDepot()) { + if (insertActivity.getIndex() >= insertActivity.getVehicleRoute().getActivities().size()) { + insertActivity.getVehicleRoute().getEnd().setLocation(insertActivity.getActivity().getLocation()); + } + } + VehicleRoute vehicleRoute = ((InsertBreak) event).getVehicleRoute(); + if (!vehicleRoute.isEmpty()) { + if (vehicleRoute.getVehicle() != ((InsertBreak) event).getNewVehicle()) { + if (vehicleRoute.getVehicle().getBreak() != null) { + boolean removed = vehicleRoute.getTourActivities().removeJob(vehicleRoute.getVehicle().getBreak()); + if (removed) + logger.trace("remove old break " + vehicleRoute.getVehicle().getBreak()); + } + } + } + insertActivity.getVehicleRoute().getTourActivities().addActivity(insertActivity.getIndex(), ((InsertBreak) event).getActivity()); + } + } + +} diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/Inserter.java b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/Inserter.java index 2fd482e9..f2e2a5d7 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/Inserter.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/Inserter.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.recreate; @@ -29,34 +29,34 @@ import jsprit.core.problem.solution.route.activity.*; import java.util.List; class Inserter { - - interface JobInsertionHandler { - void handleJobInsertion(Job job, InsertionData iData, VehicleRoute route); - - void setNextHandler(JobInsertionHandler handler); + interface JobInsertionHandler { - } - - class JobExceptionHandler implements JobInsertionHandler{ + void handleJobInsertion(Job job, InsertionData iData, VehicleRoute route); - @Override - public void handleJobInsertion(Job job, InsertionData iData,VehicleRoute route) { - throw new IllegalStateException("job insertion is not supported. Do not know job type."); - } + void setNextHandler(JobInsertionHandler handler); - @Override - public void setNextHandler(JobInsertionHandler handler) { + } - } - - } - - class ServiceInsertionHandler implements JobInsertionHandler{ + class JobExceptionHandler implements JobInsertionHandler { - private TourActivityFactory activityFactory = new DefaultTourActivityFactory(); - - private JobInsertionHandler delegator = new JobExceptionHandler(); + @Override + public void handleJobInsertion(Job job, InsertionData iData, VehicleRoute route) { + throw new IllegalStateException("job insertion is not supported. Do not know job type."); + } + + @Override + public void setNextHandler(JobInsertionHandler handler) { + + } + + } + + class ServiceInsertionHandler implements JobInsertionHandler { + + private TourActivityFactory activityFactory = new DefaultTourActivityFactory(); + + private JobInsertionHandler delegator = new JobExceptionHandler(); private VehicleRoutingProblem vehicleRoutingProblem; @@ -65,94 +65,93 @@ class Inserter { } @Override - public void handleJobInsertion(Job job, InsertionData iData, VehicleRoute route) { - if(job instanceof Service){ - route.setVehicleAndDepartureTime(iData.getSelectedVehicle(),iData.getVehicleDepartureTime()); - if(!iData.getSelectedVehicle().isReturnToDepot()){ - if(iData.getDeliveryInsertionIndex()>=route.getTourActivities().getActivities().size()){ - setEndLocation(route,(Service)job); - } - } + public void handleJobInsertion(Job job, InsertionData iData, VehicleRoute route) { + if (job instanceof Service) { + route.setVehicleAndDepartureTime(iData.getSelectedVehicle(), iData.getVehicleDepartureTime()); + if (!iData.getSelectedVehicle().isReturnToDepot()) { + if (iData.getDeliveryInsertionIndex() >= route.getTourActivities().getActivities().size()) { + setEndLocation(route, (Service) job); + } + } TourActivity activity = vehicleRoutingProblem.copyAndGetActivities(job).get(0); route.getTourActivities().addActivity(iData.getDeliveryInsertionIndex(), activity); - } - else delegator.handleJobInsertion(job, iData, route); - } - - private void setEndLocation(VehicleRoute route, Service service) { - route.getEnd().setLocation(service.getLocation()); - } - - public void setNextHandler(JobInsertionHandler jobInsertionHandler){ - this.delegator = jobInsertionHandler; - } - - } - - class ShipmentInsertionHandler implements JobInsertionHandler { + } else delegator.handleJobInsertion(job, iData, route); + } + + private void setEndLocation(VehicleRoute route, Service service) { + route.getEnd().setLocation(service.getLocation()); + } + + public void setNextHandler(JobInsertionHandler jobInsertionHandler) { + this.delegator = jobInsertionHandler; + } + + } + + class ShipmentInsertionHandler implements JobInsertionHandler { private final VehicleRoutingProblem vehicleRoutingProblem; private TourShipmentActivityFactory activityFactory = new DefaultShipmentActivityFactory(); - - private JobInsertionHandler delegator = new JobExceptionHandler(); + + private JobInsertionHandler delegator = new JobExceptionHandler(); public ShipmentInsertionHandler(VehicleRoutingProblem vehicleRoutingProblem) { this.vehicleRoutingProblem = vehicleRoutingProblem; } @Override - public void handleJobInsertion(Job job, InsertionData iData, VehicleRoute route) { - if(job instanceof Shipment){ + public void handleJobInsertion(Job job, InsertionData iData, VehicleRoute route) { + if (job instanceof Shipment) { List acts = vehicleRoutingProblem.copyAndGetActivities(job); - TourActivity pickupShipment = acts.get(0); - TourActivity deliverShipment = acts.get(1); - route.setVehicleAndDepartureTime(iData.getSelectedVehicle(),iData.getVehicleDepartureTime()); - if(!iData.getSelectedVehicle().isReturnToDepot()){ - if(iData.getDeliveryInsertionIndex()>=route.getActivities().size()){ - setEndLocation(route,(Shipment)job); - } - } - route.getTourActivities().addActivity(iData.getDeliveryInsertionIndex(), deliverShipment); - route.getTourActivities().addActivity(iData.getPickupInsertionIndex(), pickupShipment); - } - else delegator.handleJobInsertion(job, iData, route); - } - - private void setEndLocation(VehicleRoute route, Shipment shipment) { - route.getEnd().setLocation(shipment.getDeliveryLocation()); - } + TourActivity pickupShipment = acts.get(0); + TourActivity deliverShipment = acts.get(1); + route.setVehicleAndDepartureTime(iData.getSelectedVehicle(), iData.getVehicleDepartureTime()); + if (!iData.getSelectedVehicle().isReturnToDepot()) { + if (iData.getDeliveryInsertionIndex() >= route.getActivities().size()) { + setEndLocation(route, (Shipment) job); + } + } + route.getTourActivities().addActivity(iData.getDeliveryInsertionIndex(), deliverShipment); + route.getTourActivities().addActivity(iData.getPickupInsertionIndex(), pickupShipment); + } else delegator.handleJobInsertion(job, iData, route); + } - public void setNextHandler(JobInsertionHandler jobInsertionHandler){ - this.delegator = jobInsertionHandler; - } - - } + private void setEndLocation(VehicleRoute route, Shipment shipment) { + route.getEnd().setLocation(shipment.getDeliveryLocation()); + } - private InsertionListeners insertionListeners; - - private JobInsertionHandler jobInsertionHandler; + public void setNextHandler(JobInsertionHandler jobInsertionHandler) { + this.delegator = jobInsertionHandler; + } + + } + + private InsertionListeners insertionListeners; + + private JobInsertionHandler jobInsertionHandler; private VehicleRoutingProblem vehicleRoutingProblem; - - public Inserter(InsertionListeners insertionListeners, VehicleRoutingProblem vehicleRoutingProblem) { - this.insertionListeners = insertionListeners; - new DefaultTourActivityFactory(); - jobInsertionHandler = new ServiceInsertionHandler(vehicleRoutingProblem); - jobInsertionHandler.setNextHandler(new ShipmentInsertionHandler(vehicleRoutingProblem)); - } - public void insertJob(Job job, InsertionData insertionData, VehicleRoute vehicleRoute){ - insertionListeners.informBeforeJobInsertion(job, insertionData, vehicleRoute); - - if(insertionData == null || (insertionData instanceof NoInsertionFound)) throw new IllegalStateException("insertionData null. cannot insert job."); - if(job == null) throw new IllegalStateException("cannot insert null-job"); - if(!(vehicleRoute.getVehicle().getId().equals(insertionData.getSelectedVehicle().getId()))){ - insertionListeners.informVehicleSwitched(vehicleRoute, vehicleRoute.getVehicle(), insertionData.getSelectedVehicle()); - vehicleRoute.setVehicleAndDepartureTime(insertionData.getSelectedVehicle(), insertionData.getVehicleDepartureTime()); - } - jobInsertionHandler.handleJobInsertion(job, insertionData, vehicleRoute); + public Inserter(InsertionListeners insertionListeners, VehicleRoutingProblem vehicleRoutingProblem) { + this.insertionListeners = insertionListeners; + new DefaultTourActivityFactory(); + jobInsertionHandler = new ServiceInsertionHandler(vehicleRoutingProblem); + jobInsertionHandler.setNextHandler(new ShipmentInsertionHandler(vehicleRoutingProblem)); + } - insertionListeners.informJobInserted(job, vehicleRoute, insertionData.getInsertionCost(), insertionData.getAdditionalTime()); - } + public void insertJob(Job job, InsertionData insertionData, VehicleRoute vehicleRoute) { + insertionListeners.informBeforeJobInsertion(job, insertionData, vehicleRoute); + + if (insertionData == null || (insertionData instanceof NoInsertionFound)) + throw new IllegalStateException("insertionData null. cannot insert job."); + if (job == null) throw new IllegalStateException("cannot insert null-job"); + if (!(vehicleRoute.getVehicle().getId().equals(insertionData.getSelectedVehicle().getId()))) { + insertionListeners.informVehicleSwitched(vehicleRoute, vehicleRoute.getVehicle(), insertionData.getSelectedVehicle()); + vehicleRoute.setVehicleAndDepartureTime(insertionData.getSelectedVehicle(), insertionData.getVehicleDepartureTime()); + } + jobInsertionHandler.handleJobInsertion(job, insertionData, vehicleRoute); + + insertionListeners.informJobInserted(job, vehicleRoute, insertionData.getInsertionCost(), insertionData.getAdditionalTime()); + } } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/InsertionBuilder.java b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/InsertionBuilder.java index 68381178..e3ada608 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/InsertionBuilder.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/InsertionBuilder.java @@ -30,173 +30,196 @@ import java.util.concurrent.ExecutorService; public class InsertionBuilder { + private boolean fastRegret; + + public enum Strategy { REGRET, BEST } - private VehicleRoutingProblem vrp; + private VehicleRoutingProblem vrp; - private StateManager stateManager; + private StateManager stateManager; - private boolean local = true; + private boolean local = true; - private ConstraintManager constraintManager; + private ConstraintManager constraintManager; - private VehicleFleetManager fleetManager; + private VehicleFleetManager fleetManager; - private double weightOfFixedCosts; + private double weightOfFixedCosts; - private boolean considerFixedCosts = false; + private boolean considerFixedCosts = false; - private ActivityInsertionCostsCalculator actInsertionCostsCalculator = null; + private ActivityInsertionCostsCalculator actInsertionCostsCalculator = null; - private int forwaredLooking; + private int forwaredLooking; - private int memory; + private int memory; - private ExecutorService executor; + private ExecutorService executor; - private int nuOfThreads; + private int nuOfThreads; - private double timeSlice; + private double timeSlice; - private int nNeighbors; + private int nNeighbors; - private boolean timeScheduling=false; + private boolean timeScheduling = false; - private boolean allowVehicleSwitch=true; + private boolean allowVehicleSwitch = true; - private boolean addDefaultCostCalc=true; + private boolean addDefaultCostCalc = true; private Strategy strategy = Strategy.BEST; - public InsertionBuilder(VehicleRoutingProblem vrp, VehicleFleetManager vehicleFleetManager, StateManager stateManager, ConstraintManager constraintManager) { - super(); - this.vrp = vrp; - this.stateManager = stateManager; - this.constraintManager = constraintManager; - this.fleetManager = vehicleFleetManager; - } + private boolean isFastRegret = false; - public InsertionBuilder setInsertionStrategy(Strategy strategy){ + public InsertionBuilder(VehicleRoutingProblem vrp, VehicleFleetManager vehicleFleetManager, StateManager stateManager, ConstraintManager constraintManager) { + super(); + this.vrp = vrp; + this.stateManager = stateManager; + this.constraintManager = constraintManager; + this.fleetManager = vehicleFleetManager; + } + + public InsertionBuilder setInsertionStrategy(Strategy strategy) { this.strategy = strategy; return this; } - - public InsertionBuilder setRouteLevel(int forwardLooking, int memory){ - local = false; - this.forwaredLooking = forwardLooking; - this.memory = memory; - return this; - } - - public InsertionBuilder setRouteLevel(int forwardLooking, int memory, boolean addDefaultMarginalCostCalculation){ - local = false; - this.forwaredLooking = forwardLooking; - this.memory = memory; - this.addDefaultCostCalc = addDefaultMarginalCostCalculation; - return this; - } - - public InsertionBuilder setLocalLevel(){ - local = true; - return this; - } - - /** - * If addDefaulMarginalCostCalculation is false, no calculator is set which implicitly assumes that marginal cost calculation - * is controlled by your custom soft constraints. - * - * @param addDefaultMarginalCostCalculation - * @return - */ - public InsertionBuilder setLocalLevel(boolean addDefaultMarginalCostCalculation){ - local = true; - addDefaultCostCalc = addDefaultMarginalCostCalculation; - return this; - } - - public InsertionBuilder considerFixedCosts(double weightOfFixedCosts){ - this.weightOfFixedCosts = weightOfFixedCosts; - this.considerFixedCosts = true; - return this; - } - - public InsertionBuilder setActivityInsertionCostCalculator(ActivityInsertionCostsCalculator activityInsertionCostsCalculator){ - this.actInsertionCostsCalculator = activityInsertionCostsCalculator; - return this; - } - - public InsertionBuilder setConcurrentMode(ExecutorService executor, int nuOfThreads){ - this.executor = executor; - this.nuOfThreads = nuOfThreads; - return this; - } - - - public InsertionStrategy build() { - List iListeners = new ArrayList(); - List algorithmListeners = new ArrayList(); - JobInsertionCostsCalculatorBuilder calcBuilder = new JobInsertionCostsCalculatorBuilder(iListeners, algorithmListeners); - if(local){ - calcBuilder.setLocalLevel(addDefaultCostCalc); - } - else { - calcBuilder.setRouteLevel(forwaredLooking, memory, addDefaultCostCalc); - } - calcBuilder.setConstraintManager(constraintManager); - calcBuilder.setStateManager(stateManager); - calcBuilder.setVehicleRoutingProblem(vrp); - calcBuilder.setVehicleFleetManager(fleetManager); - calcBuilder.setActivityInsertionCostsCalculator(actInsertionCostsCalculator); - if(considerFixedCosts) { - calcBuilder.considerFixedCosts(weightOfFixedCosts); - } - if(timeScheduling){ - calcBuilder.experimentalTimeScheduler(timeSlice, nNeighbors); - } - calcBuilder.setAllowVehicleSwitch(allowVehicleSwitch); - JobInsertionCostsCalculator costCalculator = calcBuilder.build(); + + public InsertionBuilder setRouteLevel(int forwardLooking, int memory) { + local = false; + this.forwaredLooking = forwardLooking; + this.memory = memory; + return this; + } + + public InsertionBuilder setRouteLevel(int forwardLooking, int memory, boolean addDefaultMarginalCostCalculation) { + local = false; + this.forwaredLooking = forwardLooking; + this.memory = memory; + this.addDefaultCostCalc = addDefaultMarginalCostCalculation; + return this; + } + + public InsertionBuilder setFastRegret(boolean fastRegret) { + this.isFastRegret = fastRegret; + return this; + } + + + public InsertionBuilder setLocalLevel() { + local = true; + return this; + } + + /** + * If addDefaulMarginalCostCalculation is false, no calculator is set which implicitly assumes that marginal cost calculation + * is controlled by your custom soft constraints. + * + * @param addDefaultMarginalCostCalculation + * @return + */ + public InsertionBuilder setLocalLevel(boolean addDefaultMarginalCostCalculation) { + local = true; + addDefaultCostCalc = addDefaultMarginalCostCalculation; + return this; + } + + public InsertionBuilder considerFixedCosts(double weightOfFixedCosts) { + this.weightOfFixedCosts = weightOfFixedCosts; + this.considerFixedCosts = true; + return this; + } + + public InsertionBuilder setActivityInsertionCostCalculator(ActivityInsertionCostsCalculator activityInsertionCostsCalculator) { + this.actInsertionCostsCalculator = activityInsertionCostsCalculator; + return this; + } + + public InsertionBuilder setConcurrentMode(ExecutorService executor, int nuOfThreads) { + this.executor = executor; + this.nuOfThreads = nuOfThreads; + return this; + } + + + public InsertionStrategy build() { + List iListeners = new ArrayList(); + List algorithmListeners = new ArrayList(); + JobInsertionCostsCalculatorBuilder calcBuilder = new JobInsertionCostsCalculatorBuilder(iListeners, algorithmListeners); + if (local) { + calcBuilder.setLocalLevel(addDefaultCostCalc); + } else { + calcBuilder.setRouteLevel(forwaredLooking, memory, addDefaultCostCalc); + } + calcBuilder.setConstraintManager(constraintManager); + calcBuilder.setStateManager(stateManager); + calcBuilder.setVehicleRoutingProblem(vrp); + calcBuilder.setVehicleFleetManager(fleetManager); + calcBuilder.setActivityInsertionCostsCalculator(actInsertionCostsCalculator); + if (considerFixedCosts) { + calcBuilder.considerFixedCosts(weightOfFixedCosts); + } + if (timeScheduling) { + calcBuilder.experimentalTimeScheduler(timeSlice, nNeighbors); + } + calcBuilder.setAllowVehicleSwitch(allowVehicleSwitch); + JobInsertionCostsCalculator costCalculator = calcBuilder.build(); InsertionStrategy insertion; - if(strategy.equals(Strategy.BEST)) { + if (strategy.equals(Strategy.BEST)) { if (executor == null) { insertion = new BestInsertion(costCalculator, vrp); } else { insertion = new BestInsertionConcurrent(costCalculator, executor, nuOfThreads, vrp); } - } - else if(strategy.equals(Strategy.REGRET)){ + } else if (strategy.equals(Strategy.REGRET)) { if (executor == null) { - insertion = new RegretInsertion(costCalculator, vrp); + if(isFastRegret){ + RegretInsertionFast regret = new RegretInsertionFast(costCalculator, vrp, fleetManager); + regret.setSwitchAllowed(allowVehicleSwitch); + insertion = regret; + } + else { + RegretInsertion regret = new RegretInsertion(costCalculator, vrp); + insertion = regret; + } + + } else { + if(isFastRegret){ + RegretInsertionConcurrentFast regret = new RegretInsertionConcurrentFast(costCalculator, vrp, executor, fleetManager); + regret.setSwitchAllowed(allowVehicleSwitch); + insertion = regret; + } + else{ + RegretInsertionConcurrent regret = new RegretInsertionConcurrent(costCalculator, vrp, executor); + insertion = regret; + } + } - else { - insertion = new RegretInsertionConcurrent(costCalculator,vrp,executor); - } - } - else throw new IllegalStateException("you should never get here"); - for(InsertionListener l : iListeners) insertion.addListener(l); - return insertion; - } + } else throw new IllegalStateException("you should never get here"); + for (InsertionListener l : iListeners) insertion.addListener(l); + return insertion; + } - /** - * @deprecated this is experimental and can disappear. - * @param timeSlice the time slice - * @param nNeighbors number of neighbors - */ - @Deprecated - public void experimentalTimeScheduler(double timeSlice, int nNeighbors) { - this.timeSlice=timeSlice; - this.nNeighbors=nNeighbors; - timeScheduling=true; - } + /** + * @param timeSlice the time slice + * @param nNeighbors number of neighbors + * @deprecated this is experimental and can disappear. + */ + @Deprecated + public void experimentalTimeScheduler(double timeSlice, int nNeighbors) { + this.timeSlice = timeSlice; + this.nNeighbors = nNeighbors; + timeScheduling = true; + } - public InsertionBuilder setAllowVehicleSwitch(boolean allowVehicleSwitch) { - this.allowVehicleSwitch = allowVehicleSwitch; - return this; - } - - + public InsertionBuilder setAllowVehicleSwitch(boolean allowVehicleSwitch) { + this.allowVehicleSwitch = allowVehicleSwitch; + return this; + } } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/InsertionData.java b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/InsertionData.java index 2c72aebe..b6cc36b6 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/InsertionData.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/InsertionData.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.recreate; @@ -25,142 +25,140 @@ import java.util.List; /** * Data object that collects insertion information. It collects insertionCosts, insertionIndeces, vehicle and driver to be employed * and departureTime of vehicle at vehicle's start location (e.g. depot). - * - * @author stefan * + * @author stefan */ public class InsertionData { - - public static class NoInsertionFound extends InsertionData{ - - public NoInsertionFound() { - super(Double.MAX_VALUE, NO_INDEX, NO_INDEX, null, null); - } - } - - private static InsertionData noInsertion = new NoInsertionFound(); - - /** - * Returns an instance of InsertionData that represents an EmptyInsertionData (which might indicate - * that no insertion has been found). It is internally instantiated as follows:
- * new InsertionData(Double.MAX_VALUE, NO_INDEX, NO_INDEX, null, null);
- * where NO_INDEX=-1. - * - * @return - */ - public static InsertionData createEmptyInsertionData(){ - return noInsertion; - } - - static int NO_INDEX = -1; + public static class NoInsertionFound extends InsertionData { - private final double insertionCost; - - private final int pickupInsertionIndex; - - private final int deliveryInsertionIndex; - - private final Vehicle selectedVehicle; - - private final Driver selectedDriver; - - private double departureTime; - - private double additionalTime; + public NoInsertionFound() { + super(Double.MAX_VALUE, NO_INDEX, NO_INDEX, null, null); + } - private List events = new ArrayList(); + } - List getEvents(){ - return events; - } + private static InsertionData noInsertion = new NoInsertionFound(); - /** - * @return the additionalTime - */ - public double getAdditionalTime() { - return additionalTime; - } + /** + * Returns an instance of InsertionData that represents an EmptyInsertionData (which might indicate + * that no insertion has been found). It is internally instantiated as follows:
+ * new InsertionData(Double.MAX_VALUE, NO_INDEX, NO_INDEX, null, null);
+ * where NO_INDEX=-1. + * + * @return + */ + public static InsertionData createEmptyInsertionData() { + return noInsertion; + } - /** - * @param additionalTime the additionalTime to set - */ - public void setAdditionalTime(double additionalTime) { - this.additionalTime = additionalTime; - } + static int NO_INDEX = -1; - public InsertionData(double insertionCost, int pickupInsertionIndex, int deliveryInsertionIndex, Vehicle vehicle, Driver driver){ - this.insertionCost = insertionCost; - this.pickupInsertionIndex = pickupInsertionIndex; - this.deliveryInsertionIndex = deliveryInsertionIndex; - this.selectedVehicle = vehicle; - this.selectedDriver = driver; - } - - @Override - public String toString() { - return "[iCost="+insertionCost+"][pickupIndex="+pickupInsertionIndex+"][deliveryIndex="+deliveryInsertionIndex+"][depTime="+departureTime+"][vehicle="+selectedVehicle+"][driver="+selectedDriver+"]"; - } - - /** - * Returns insertionIndex of deliveryActivity. If no insertionPosition is found, it returns NO_INDEX (=-1). - * - * @return - */ - public int getDeliveryInsertionIndex(){ - return deliveryInsertionIndex; - } - - /** - * Returns insertionIndex of pickkupActivity. If no insertionPosition is found, it returns NO_INDEX (=-1). - * - * @return - */ - public int getPickupInsertionIndex(){ - return pickupInsertionIndex; - } - - /** - * Returns insertion costs (which might be the additional costs of inserting the corresponding job). - * - * @return - */ - public double getInsertionCost() { - return insertionCost; - } + private final double insertionCost; - /** - * Returns the vehicle to be employed. - * - * @return - */ - public Vehicle getSelectedVehicle() { - return selectedVehicle; - } - - /** - * Returns the vehicle to be employed. - * - * @return - */ - public Driver getSelectedDriver(){ - return selectedDriver; - } + private final int pickupInsertionIndex; + + private final int deliveryInsertionIndex; + + private final Vehicle selectedVehicle; + + private final Driver selectedDriver; + + private double departureTime; + + private double additionalTime; + + private List events = new ArrayList(); + + List getEvents() { + return events; + } + + /** + * @return the additionalTime + */ + public double getAdditionalTime() { + return additionalTime; + } + + /** + * @param additionalTime the additionalTime to set + */ + public void setAdditionalTime(double additionalTime) { + this.additionalTime = additionalTime; + } + + public InsertionData(double insertionCost, int pickupInsertionIndex, int deliveryInsertionIndex, Vehicle vehicle, Driver driver) { + this.insertionCost = insertionCost; + this.pickupInsertionIndex = pickupInsertionIndex; + this.deliveryInsertionIndex = deliveryInsertionIndex; + this.selectedVehicle = vehicle; + this.selectedDriver = driver; + } + + @Override + public String toString() { + return "[iCost=" + insertionCost + "][pickupIndex=" + pickupInsertionIndex + "][deliveryIndex=" + deliveryInsertionIndex + "][depTime=" + departureTime + "][vehicle=" + selectedVehicle + "][driver=" + selectedDriver + "]"; + } + + /** + * Returns insertionIndex of deliveryActivity. If no insertionPosition is found, it returns NO_INDEX (=-1). + * + * @return + */ + public int getDeliveryInsertionIndex() { + return deliveryInsertionIndex; + } + + /** + * Returns insertionIndex of pickkupActivity. If no insertionPosition is found, it returns NO_INDEX (=-1). + * + * @return + */ + public int getPickupInsertionIndex() { + return pickupInsertionIndex; + } + + /** + * Returns insertion costs (which might be the additional costs of inserting the corresponding job). + * + * @return + */ + public double getInsertionCost() { + return insertionCost; + } + + /** + * Returns the vehicle to be employed. + * + * @return + */ + public Vehicle getSelectedVehicle() { + return selectedVehicle; + } + + /** + * Returns the vehicle to be employed. + * + * @return + */ + public Driver getSelectedDriver() { + return selectedDriver; + } + + /** + * @return the departureTime + */ + public double getVehicleDepartureTime() { + return departureTime; + } + + /** + * @param departureTime the departureTime to set + */ + public void setVehicleDepartureTime(double departureTime) { + this.departureTime = departureTime; + } - /** - * @return the departureTime - */ - public double getVehicleDepartureTime() { - return departureTime; - } - /** - * @param departureTime the departureTime to set - */ - public void setVehicleDepartureTime(double departureTime) { - this.departureTime = departureTime; - } - - - } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/InsertionDataUpdater.java b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/InsertionDataUpdater.java new file mode 100644 index 00000000..9460d799 --- /dev/null +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/InsertionDataUpdater.java @@ -0,0 +1,157 @@ +package jsprit.core.algorithm.recreate; + +import jsprit.core.problem.job.Job; +import jsprit.core.problem.solution.route.VehicleRoute; +import jsprit.core.problem.vehicle.Vehicle; +import jsprit.core.problem.vehicle.VehicleFleetManager; +import jsprit.core.problem.vehicle.VehicleImpl; + +import java.util.*; + +/** + * Created by schroeder on 15/10/15. + */ +class InsertionDataUpdater { + + static boolean update(boolean addAllAvailable, Set initialVehicleIds, VehicleFleetManager fleetManager, JobInsertionCostsCalculator insertionCostsCalculator, TreeSet insertionDataSet, int updateRound, Job unassignedJob, Collection routes) { + for(VehicleRoute route : routes) { + Collection relevantVehicles = new ArrayList(); + if (!(route.getVehicle() instanceof VehicleImpl.NoVehicle)) { + relevantVehicles.add(route.getVehicle()); + if(addAllAvailable && !initialVehicleIds.contains(route.getVehicle().getId())){ + relevantVehicles.addAll(fleetManager.getAvailableVehicles(route.getVehicle())); + } + } else relevantVehicles.addAll(fleetManager.getAvailableVehicles()); + for (Vehicle v : relevantVehicles) { + double depTime = v.getEarliestDeparture(); + InsertionData iData = insertionCostsCalculator.getInsertionData(route, unassignedJob, v, depTime, route.getDriver(), Double.MAX_VALUE); + if (iData instanceof InsertionData.NoInsertionFound) { + continue; + } + insertionDataSet.add(new VersionedInsertionData(iData, updateRound, route)); + } + } + return true; + } + + + + static VehicleRoute findRoute(Collection routes, Job job) { + for(VehicleRoute r : routes){ + if(r.getVehicle().getBreak() == job) return r; + } + return null; + } + + static Comparator getComparator(){ + return new Comparator() { + @Override + public int compare(VersionedInsertionData o1, VersionedInsertionData o2) { + if(o1.getiData().getInsertionCost() < o2.getiData().getInsertionCost()) return -1; + return 1; + } + }; + } + + static ScoredJob getBest(boolean switchAllowed, Set initialVehicleIds, VehicleFleetManager fleetManager, JobInsertionCostsCalculator insertionCostsCalculator, ScoringFunction scoringFunction, TreeSet[] priorityQueues, Map updates, List unassignedJobList, List badJobs) { + ScoredJob bestScoredJob = null; + for(Job j : unassignedJobList){ + VehicleRoute bestRoute = null; + InsertionData best = null; + InsertionData secondBest = null; + TreeSet priorityQueue = priorityQueues[j.getIndex()]; + Iterator iterator = priorityQueue.iterator(); + while(iterator.hasNext()){ + VersionedInsertionData versionedIData = iterator.next(); + if(bestRoute != null){ + if(versionedIData.getRoute() == bestRoute){ + continue; + } + } + if(versionedIData.getiData() instanceof InsertionData.NoInsertionFound) continue; + if(!(versionedIData.getRoute().getVehicle() instanceof VehicleImpl.NoVehicle)) { + if (versionedIData.getiData().getSelectedVehicle() != versionedIData.getRoute().getVehicle()) { + if (!switchAllowed) continue; + if (initialVehicleIds.contains(versionedIData.getRoute().getVehicle().getId())) continue; + } + } + if(versionedIData.getiData().getSelectedVehicle() != versionedIData.getRoute().getVehicle()) { + if (fleetManager.isLocked(versionedIData.getiData().getSelectedVehicle())) { + Vehicle available = fleetManager.getAvailableVehicle(versionedIData.getiData().getSelectedVehicle().getVehicleTypeIdentifier()); + if (available != null) { + InsertionData oldData = versionedIData.getiData(); + InsertionData newData = new InsertionData(oldData.getInsertionCost(), oldData.getPickupInsertionIndex(), + oldData.getDeliveryInsertionIndex(), available, oldData.getSelectedDriver()); + newData.setVehicleDepartureTime(oldData.getVehicleDepartureTime()); + for(Event e : oldData.getEvents()){ + if(e instanceof SwitchVehicle){ + newData.getEvents().add(new SwitchVehicle(versionedIData.getRoute(),available,oldData.getVehicleDepartureTime())); + } + else newData.getEvents().add(e); + } + versionedIData = new VersionedInsertionData(newData, versionedIData.getVersion(), versionedIData.getRoute()); + } else continue; + } + } + int currentDataVersion = updates.get(versionedIData.getRoute()); + if(versionedIData.getVersion() == currentDataVersion){ + if(best == null) { + best = versionedIData.getiData(); + bestRoute = versionedIData.getRoute(); + } + else { + secondBest = versionedIData.getiData(); + break; + } + } + } + VehicleRoute emptyRoute = VehicleRoute.emptyRoute(); + InsertionData iData = insertionCostsCalculator.getInsertionData(emptyRoute, j, null, -1, null, Double.MAX_VALUE); + if(!(iData instanceof InsertionData.NoInsertionFound)){ + if (best == null) { + best = iData; + bestRoute = emptyRoute; + } else if (iData.getInsertionCost() < best.getInsertionCost()) { + secondBest = best; + best = iData; + bestRoute = emptyRoute; + } else if (secondBest == null || (iData.getInsertionCost() < secondBest.getInsertionCost())) { + secondBest = iData; + } + } + if (best == null) { + badJobs.add(j); + continue; + } + double score = score(j, best, secondBest, scoringFunction); + ScoredJob scoredJob; + if (bestRoute == emptyRoute) { + scoredJob = new ScoredJob(j, score, best, bestRoute, true); + } else scoredJob = new ScoredJob(j, score, best, bestRoute, false); + + if(bestScoredJob == null){ + bestScoredJob = scoredJob; + } + else if(scoredJob.getScore() > bestScoredJob.getScore()){ + bestScoredJob = scoredJob; + } + } + return bestScoredJob; + } + + static double score(Job unassignedJob, InsertionData best, InsertionData secondBest, ScoringFunction scoringFunction) { + if (best == null) { + throw new IllegalStateException("cannot insert job " + unassignedJob.getId()); + } + double score; + if (secondBest == null) { //either there is only one vehicle or there are more vehicles, but they cannot load unassignedJob + //if only one vehicle, I want the job to be inserted with min iCosts + //if there are more vehicles, I want this job to be prioritized since there are no alternatives + score = Integer.MAX_VALUE - best.getInsertionCost() + scoringFunction.score(best, unassignedJob); + } else { + score = (secondBest.getInsertionCost() - best.getInsertionCost()) + scoringFunction.score(best, unassignedJob); + } + return score; + } + +} diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/InsertionStrategy.java b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/InsertionStrategy.java index 8d0bc264..9638ba0c 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/InsertionStrategy.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/InsertionStrategy.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.recreate; @@ -23,27 +23,26 @@ import jsprit.core.problem.solution.route.VehicleRoute; import java.util.Collection; - /** * Basic interface for insertion strategies * * @author stefan schroeder - * */ public interface InsertionStrategy { - /** - * Inserts unassigned jobs into vehicle routes. - * @param vehicleRoutes existing vehicle routes - * @param unassignedJobs jobs to be inserted + /** + * Inserts unassigned jobs into vehicle routes. + * + * @param vehicleRoutes existing vehicle routes + * @param unassignedJobs jobs to be inserted */ - public Collection insertJobs(Collection vehicleRoutes, Collection unassignedJobs); + public Collection insertJobs(Collection vehicleRoutes, Collection unassignedJobs); public void addListener(InsertionListener insertionListener); - - public void removeListener(InsertionListener insertionListener); - - public Collection getListeners(); + + public void removeListener(InsertionListener insertionListener); + + public Collection getListeners(); } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/InsertionStrategyFactory.java b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/InsertionStrategyFactory.java index 8c36e9a0..94bfdcc2 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/InsertionStrategyFactory.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/InsertionStrategyFactory.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.recreate; @@ -20,6 +20,6 @@ import jsprit.core.problem.VehicleRoutingProblem; public interface InsertionStrategyFactory { - public InsertionStrategy createStrategy(VehicleRoutingProblem vrp); - + public InsertionStrategy createStrategy(VehicleRoutingProblem vrp); + } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/JobCalculatorSwitcher.java b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/JobCalculatorSwitcher.java index ed346ca8..15bf4e04 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/JobCalculatorSwitcher.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/JobCalculatorSwitcher.java @@ -1,18 +1,18 @@ /******************************************************************************* * Copyright (c) 2014 Stefan Schroeder. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . - * + * * Contributors: * Stefan Schroeder - initial API and implementation ******************************************************************************/ @@ -27,18 +27,18 @@ import java.util.HashMap; import java.util.Map; -class JobCalculatorSwitcher implements JobInsertionCostsCalculator{ +class JobCalculatorSwitcher implements JobInsertionCostsCalculator { + + private Map, JobInsertionCostsCalculator> calcMap = new HashMap, JobInsertionCostsCalculator>(); + + void put(Class jobClass, JobInsertionCostsCalculator jic) { + calcMap.put(jobClass, jic); + } + + public InsertionData getInsertionData(VehicleRoute currentRoute, Job jobToInsert, Vehicle newVehicle, double newVehicleDepartureTime, Driver newDriver, double bestKnownScore) { + JobInsertionCostsCalculator jic = calcMap.get(jobToInsert.getClass()); + if (jic == null) throw new IllegalStateException("cannot find calculator for " + jobToInsert.getClass()); + return jic.getInsertionData(currentRoute, jobToInsert, newVehicle, newVehicleDepartureTime, newDriver, bestKnownScore); + } - private Map,JobInsertionCostsCalculator> calcMap = new HashMap, JobInsertionCostsCalculator>(); - - void put(Class jobClass, JobInsertionCostsCalculator jic){ - calcMap.put(jobClass, jic); - } - - public InsertionData getInsertionData(VehicleRoute currentRoute, Job jobToInsert, Vehicle newVehicle, double newVehicleDepartureTime, Driver newDriver, double bestKnownScore){ - JobInsertionCostsCalculator jic = calcMap.get(jobToInsert.getClass()); - if(jic==null) throw new IllegalStateException("cannot find calculator for " + jobToInsert.getClass()); - return jic.getInsertionData(currentRoute, jobToInsert, newVehicle, newVehicleDepartureTime, newDriver, bestKnownScore); - } - } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/JobInsertionConsideringFixCostsCalculator.java b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/JobInsertionConsideringFixCostsCalculator.java index 431e1b4d..6540f0da 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/JobInsertionConsideringFixCostsCalculator.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/JobInsertionConsideringFixCostsCalculator.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.recreate; @@ -30,107 +30,103 @@ import jsprit.core.problem.vehicle.VehicleImpl.NoVehicle; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -final class JobInsertionConsideringFixCostsCalculator implements JobInsertionCostsCalculator, SoftRouteConstraint{ +final class JobInsertionConsideringFixCostsCalculator implements JobInsertionCostsCalculator, SoftRouteConstraint { - private static final Logger logger = LogManager.getLogger(JobInsertionConsideringFixCostsCalculator.class); - - private final JobInsertionCostsCalculator standardServiceInsertion; - - private double weight_deltaFixCost = 0.5; - - private double solution_completeness_ratio = 0.5; - - private RouteAndActivityStateGetter stateGetter; + private static final Logger logger = LogManager.getLogger(JobInsertionConsideringFixCostsCalculator.class); - public JobInsertionConsideringFixCostsCalculator(final JobInsertionCostsCalculator standardInsertionCalculator, RouteAndActivityStateGetter stateGetter) { - super(); - this.standardServiceInsertion = standardInsertionCalculator; - this.stateGetter = stateGetter; - logger.debug("inialise " + this); - } + private final JobInsertionCostsCalculator standardServiceInsertion; - @Override - public InsertionData getInsertionData(final VehicleRoute currentRoute, final Job jobToInsert, final Vehicle newVehicle, double newVehicleDepartureTime, final Driver newDriver, final double bestKnownPrice) { - double fixcost_contribution = getFixCostContribution(currentRoute,jobToInsert, newVehicle); - if(fixcost_contribution > bestKnownPrice){ - return InsertionData.createEmptyInsertionData(); - } - InsertionData iData = standardServiceInsertion.getInsertionData(currentRoute, jobToInsert, newVehicle, newVehicleDepartureTime, newDriver, bestKnownPrice); - if(iData instanceof NoInsertionFound){ - return iData; - } - double totalInsertionCost = iData.getInsertionCost() + fixcost_contribution; - InsertionData insertionData = new InsertionData(totalInsertionCost, iData.getPickupInsertionIndex(), iData.getDeliveryInsertionIndex(), newVehicle, newDriver); - insertionData.setVehicleDepartureTime(newVehicleDepartureTime); - insertionData.getEvents().addAll(iData.getEvents()); - return insertionData; - } + private double weight_deltaFixCost = 0.5; - private double getFixCostContribution(final VehicleRoute currentRoute, - final Job jobToInsert, final Vehicle newVehicle) { - double relFixCost = getDeltaRelativeFixCost(currentRoute, newVehicle, jobToInsert); - double absFixCost = getDeltaAbsoluteFixCost(currentRoute, newVehicle, jobToInsert); - double deltaFixCost = (1-solution_completeness_ratio)*relFixCost + solution_completeness_ratio*absFixCost; - double fixcost_contribution = weight_deltaFixCost*solution_completeness_ratio*deltaFixCost; - return fixcost_contribution; - } - - public void setWeightOfFixCost(double weight){ - weight_deltaFixCost = weight; - logger.debug("set weightOfFixCostSaving to " + weight); - } - - @Override - public String toString() { - return "[name=calculatesServiceInsertionConsideringFixCost][weightOfFixedCostSavings="+weight_deltaFixCost+"]"; - } + private double solution_completeness_ratio = 0.5; - public void setSolutionCompletenessRatio(double ratio){ - solution_completeness_ratio = ratio; - } + private RouteAndActivityStateGetter stateGetter; - private double getDeltaAbsoluteFixCost(VehicleRoute route, Vehicle newVehicle, Job job) { - Capacity load = Capacity.addup(getCurrentMaxLoadInRoute(route), job.getSize()); -// double load = getCurrentMaxLoadInRoute(route) + job.getCapacityDemand(); - double currentFix = 0.0; - if(route.getVehicle() != null){ - if(!(route.getVehicle() instanceof NoVehicle)){ - currentFix += route.getVehicle().getType().getVehicleCostParams().fix; - } - } - if(!newVehicle.getType().getCapacityDimensions().isGreaterOrEqual(load)){ - return Double.MAX_VALUE; - } - return newVehicle.getType().getVehicleCostParams().fix - currentFix; - } + public JobInsertionConsideringFixCostsCalculator(final JobInsertionCostsCalculator standardInsertionCalculator, RouteAndActivityStateGetter stateGetter) { + super(); + this.standardServiceInsertion = standardInsertionCalculator; + this.stateGetter = stateGetter; + logger.debug("inialise {}", this); + } - private double getDeltaRelativeFixCost(VehicleRoute route, Vehicle newVehicle, Job job) { - Capacity currentLoad = getCurrentMaxLoadInRoute(route); -// int currentLoad = getCurrentMaxLoadInRoute(route); - Capacity load = Capacity.addup(currentLoad, job.getSize()); -// double load = currentLoad + job.getCapacityDemand(); - double currentRelFix = 0.0; - if(route.getVehicle() != null){ - if(!(route.getVehicle() instanceof NoVehicle)){ - currentRelFix += route.getVehicle().getType().getVehicleCostParams().fix * Capacity.divide(currentLoad, route.getVehicle().getType().getCapacityDimensions()); - } - } - if(!newVehicle.getType().getCapacityDimensions().isGreaterOrEqual(load)){ - return Double.MAX_VALUE; - } - double relativeFixCost = newVehicle.getType().getVehicleCostParams().fix* (Capacity.divide(load, newVehicle.getType().getCapacityDimensions())) - currentRelFix; - return relativeFixCost; - } + @Override + public InsertionData getInsertionData(final VehicleRoute currentRoute, final Job jobToInsert, final Vehicle newVehicle, double newVehicleDepartureTime, final Driver newDriver, final double bestKnownPrice) { + double fixcost_contribution = getFixCostContribution(currentRoute, jobToInsert, newVehicle); + if (fixcost_contribution > bestKnownPrice) { + return InsertionData.createEmptyInsertionData(); + } + InsertionData iData = standardServiceInsertion.getInsertionData(currentRoute, jobToInsert, newVehicle, newVehicleDepartureTime, newDriver, bestKnownPrice); + if (iData instanceof NoInsertionFound) { + return iData; + } + double totalInsertionCost = iData.getInsertionCost() + fixcost_contribution; + InsertionData insertionData = new InsertionData(totalInsertionCost, iData.getPickupInsertionIndex(), iData.getDeliveryInsertionIndex(), newVehicle, newDriver); + insertionData.setVehicleDepartureTime(newVehicleDepartureTime); + insertionData.getEvents().addAll(iData.getEvents()); + return insertionData; + } - private Capacity getCurrentMaxLoadInRoute(VehicleRoute route) { + private double getFixCostContribution(final VehicleRoute currentRoute, final Job jobToInsert, final Vehicle newVehicle) { + Capacity currentMaxLoadInRoute = getCurrentMaxLoadInRoute(currentRoute); + double relFixCost = getDeltaRelativeFixCost(currentRoute, newVehicle, jobToInsert,currentMaxLoadInRoute); + double absFixCost = getDeltaAbsoluteFixCost(currentRoute, newVehicle, jobToInsert,currentMaxLoadInRoute); + double deltaFixCost = (1 - solution_completeness_ratio) * relFixCost + solution_completeness_ratio * absFixCost; + double fixcost_contribution = weight_deltaFixCost * solution_completeness_ratio * deltaFixCost; + return fixcost_contribution; + } + + public void setWeightOfFixCost(double weight) { + weight_deltaFixCost = weight; + logger.debug("set weightOfFixCostSaving to {}", weight); + } + + @Override + public String toString() { + return "[name=calculatesServiceInsertionConsideringFixCost][weightOfFixedCostSavings=" + weight_deltaFixCost + "]"; + } + + public void setSolutionCompletenessRatio(double ratio) { + solution_completeness_ratio = ratio; + } + + private double getDeltaAbsoluteFixCost(VehicleRoute route, Vehicle newVehicle, Job job, Capacity currentMaxLoadInRoute) { + Capacity load = Capacity.addup(currentMaxLoadInRoute, job.getSize()); + double currentFix = 0.0; + if (route.getVehicle() != null) { + if (!(route.getVehicle() instanceof NoVehicle)) { + currentFix += route.getVehicle().getType().getVehicleCostParams().fix; + } + } + if (!newVehicle.getType().getCapacityDimensions().isGreaterOrEqual(load)) { + return Double.MAX_VALUE; + } + return newVehicle.getType().getVehicleCostParams().fix - currentFix; + } + + private double getDeltaRelativeFixCost(VehicleRoute route, Vehicle newVehicle, Job job, Capacity currentLoad) { + Capacity load = Capacity.addup(currentLoad, job.getSize()); + double currentRelFix = 0.0; + if (route.getVehicle() != null) { + if (!(route.getVehicle() instanceof NoVehicle)) { + currentRelFix += route.getVehicle().getType().getVehicleCostParams().fix * Capacity.divide(currentLoad, route.getVehicle().getType().getCapacityDimensions()); + } + } + if (!newVehicle.getType().getCapacityDimensions().isGreaterOrEqual(load)) { + return Double.MAX_VALUE; + } + double relativeFixCost = newVehicle.getType().getVehicleCostParams().fix * (Capacity.divide(load, newVehicle.getType().getCapacityDimensions())) - currentRelFix; + return relativeFixCost; + } + + private Capacity getCurrentMaxLoadInRoute(VehicleRoute route) { Capacity maxLoad = stateGetter.getRouteState(route, InternalStates.MAXLOAD, Capacity.class); - if(maxLoad == null) maxLoad = Capacity.Builder.newInstance().build(); - return maxLoad; - } + if (maxLoad == null) maxLoad = Capacity.Builder.newInstance().build(); + return maxLoad; + } - @Override - public double getCosts(JobInsertionContext insertionContext) { - return getFixCostContribution(insertionContext.getRoute(), insertionContext.getJob(), insertionContext.getNewVehicle()); - } + @Override + public double getCosts(JobInsertionContext insertionContext) { + return getFixCostContribution(insertionContext.getRoute(), insertionContext.getJob(), insertionContext.getNewVehicle()); + } } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/JobInsertionCostsCalculator.java b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/JobInsertionCostsCalculator.java index 3d5599ac..0434f36a 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/JobInsertionCostsCalculator.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/JobInsertionCostsCalculator.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.recreate; @@ -22,8 +22,8 @@ import jsprit.core.problem.solution.route.VehicleRoute; import jsprit.core.problem.vehicle.Vehicle; - public interface JobInsertionCostsCalculator { - - public InsertionData getInsertionData(VehicleRoute currentRoute, Job newJob, Vehicle newVehicle, double newVehicleDepartureTime, Driver newDriver, double bestKnownCosts); +public interface JobInsertionCostsCalculator { + + public InsertionData getInsertionData(VehicleRoute currentRoute, Job newJob, Vehicle newVehicle, double newVehicleDepartureTime, Driver newDriver, double bestKnownCosts); } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/JobInsertionCostsCalculatorBuilder.java b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/JobInsertionCostsCalculatorBuilder.java index 32ba952b..1a056438 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/JobInsertionCostsCalculatorBuilder.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/JobInsertionCostsCalculatorBuilder.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.recreate; @@ -32,250 +32,251 @@ import java.util.ArrayList; import java.util.List; - - public class JobInsertionCostsCalculatorBuilder { - private static class CalculatorPlusListeners { + private static class CalculatorPlusListeners { - private JobInsertionCostsCalculator calculator; + private JobInsertionCostsCalculator calculator; - public JobInsertionCostsCalculator getCalculator() { - return calculator; - } + public JobInsertionCostsCalculator getCalculator() { + return calculator; + } - private List algorithmListener = new ArrayList(); - private List insertionListener = new ArrayList(); + private List algorithmListener = new ArrayList(); + private List insertionListener = new ArrayList(); - public CalculatorPlusListeners(JobInsertionCostsCalculator calculator) { - super(); - this.calculator = calculator; - } + public CalculatorPlusListeners(JobInsertionCostsCalculator calculator) { + super(); + this.calculator = calculator; + } - public List getAlgorithmListener() { - return algorithmListener; - } + public List getAlgorithmListener() { + return algorithmListener; + } - public List getInsertionListener() { - return insertionListener; - } - } + public List getInsertionListener() { + return insertionListener; + } + } - private List insertionListeners; + private List insertionListeners; - private List algorithmListeners; + private List algorithmListeners; - private VehicleRoutingProblem vrp; + private VehicleRoutingProblem vrp; - private RouteAndActivityStateGetter states; + private RouteAndActivityStateGetter states; - private boolean local = true; + private boolean local = true; - private int forwardLooking = 0; + private int forwardLooking = 0; - private int memory = 1; + private int memory = 1; - private boolean considerFixedCost = false; + private boolean considerFixedCost = false; - private double weightOfFixedCost = 0; + private double weightOfFixedCost = 0; - private VehicleFleetManager fleetManager; + private VehicleFleetManager fleetManager; - private boolean timeScheduling = false; + private boolean timeScheduling = false; - private double timeSlice; + private double timeSlice; - private int neighbors; - - private ConstraintManager constraintManager; - - private ActivityInsertionCostsCalculator activityInsertionCostCalculator = null; + private int neighbors; - private boolean allowVehicleSwitch = true; + private ConstraintManager constraintManager; - private boolean addDefaultCostCalc = true; + private ActivityInsertionCostsCalculator activityInsertionCostCalculator = null; - /** - * Constructs the builder. - * - *

Some calculators require information from the overall algorithm or the higher-level insertion procedure. Thus listeners inform them. - * These listeners are cached in the according list and can thus be added when its time to add them. - * - * @param insertionListeners - * @param algorithmListeners - */ - public JobInsertionCostsCalculatorBuilder(List insertionListeners, List algorithmListeners) { - super(); - this.insertionListeners = insertionListeners; - this.algorithmListeners = algorithmListeners; - } + private boolean allowVehicleSwitch = true; - /** - * Sets activityStates. MUST be set. - * @param stateManager - * - * @return - */ - public JobInsertionCostsCalculatorBuilder setStateManager(RouteAndActivityStateGetter stateManager){ - this.states = stateManager; - return this; - } + private boolean addDefaultCostCalc = true; - /** - * Sets routingProblem. MUST be set. - * - * @param vehicleRoutingProblem - * @return - */ - public JobInsertionCostsCalculatorBuilder setVehicleRoutingProblem(VehicleRoutingProblem vehicleRoutingProblem){ - this.vrp = vehicleRoutingProblem; - return this; - } + /** + * Constructs the builder. + *

+ *

Some calculators require information from the overall algorithm or the higher-level insertion procedure. Thus listeners inform them. + * These listeners are cached in the according list and can thus be added when its time to add them. + * + * @param insertionListeners + * @param algorithmListeners + */ + public JobInsertionCostsCalculatorBuilder(List insertionListeners, List algorithmListeners) { + super(); + this.insertionListeners = insertionListeners; + this.algorithmListeners = algorithmListeners; + } - /** - * Sets fleetManager. MUST be set. - * - * @param fleetManager - * @return - */ - public JobInsertionCostsCalculatorBuilder setVehicleFleetManager(VehicleFleetManager fleetManager){ - this.fleetManager = fleetManager; - return this; - } - - /** - * Sets a flag to build a calculator based on local calculations. - * - *

Insertion of a job and job-activity is evaluated based on the previous and next activity. - * @param addDefaultCostCalc - */ - public JobInsertionCostsCalculatorBuilder setLocalLevel(boolean addDefaultCostCalc){ - local = true; - this.addDefaultCostCalc = addDefaultCostCalc; + /** + * Sets activityStates. MUST be set. + * + * @param stateManager + * @return + */ + public JobInsertionCostsCalculatorBuilder setStateManager(RouteAndActivityStateGetter stateManager) { + this.states = stateManager; return this; - } - - public JobInsertionCostsCalculatorBuilder setActivityInsertionCostsCalculator(ActivityInsertionCostsCalculator activityInsertionCostsCalculator){ - this.activityInsertionCostCalculator = activityInsertionCostsCalculator; - return this; - } + } - /** - * Sets a flag to build a calculator that evaluates job insertion on route-level. - * - * @param forwardLooking - * @param memory - * @param addDefaultMarginalCostCalc - */ - public JobInsertionCostsCalculatorBuilder setRouteLevel(int forwardLooking, int memory, boolean addDefaultMarginalCostCalc){ - local = false; - this.forwardLooking = forwardLooking; - this.memory = memory; + /** + * Sets routingProblem. MUST be set. + * + * @param vehicleRoutingProblem + * @return + */ + public JobInsertionCostsCalculatorBuilder setVehicleRoutingProblem(VehicleRoutingProblem vehicleRoutingProblem) { + this.vrp = vehicleRoutingProblem; return this; - } + } - /** - * Sets a flag to consider also fixed-cost when evaluating the insertion of a job. The weight of the fixed-cost can be determined by setting - * weightofFixedCosts. - * - * @param weightOfFixedCosts - */ - public JobInsertionCostsCalculatorBuilder considerFixedCosts(double weightOfFixedCosts){ - considerFixedCost = true; - this.weightOfFixedCost = weightOfFixedCosts; + /** + * Sets fleetManager. MUST be set. + * + * @param fleetManager + * @return + */ + public JobInsertionCostsCalculatorBuilder setVehicleFleetManager(VehicleFleetManager fleetManager) { + this.fleetManager = fleetManager; return this; - } - - public JobInsertionCostsCalculatorBuilder experimentalTimeScheduler(double timeSlice, int neighbors){ - timeScheduling = true; - this.timeSlice = timeSlice; - this.neighbors = neighbors; - return this; - } + } - /** - * Builds the jobInsertionCalculator. - * - * @return jobInsertionCalculator. - * @throws IllegalStateException if vrp == null or activityStates == null or fleetManager == null. - */ - public JobInsertionCostsCalculator build(){ - if(vrp == null) throw new IllegalStateException("vehicle-routing-problem is null, but it must be set (this.setVehicleRoutingProblem(vrp))"); - if(states == null) throw new IllegalStateException("states is null, but is must be set (this.setStateManager(states))"); - if(fleetManager == null) throw new IllegalStateException("fleetManager is null, but it must be set (this.setVehicleFleetManager(fleetManager))"); - JobInsertionCostsCalculator baseCalculator = null; - CalculatorPlusListeners standardLocal = null; - if(local){ - standardLocal = createStandardLocal(vrp, states); - } - else{ - checkServicesOnly(); - standardLocal = createStandardRoute(vrp, states,forwardLooking,memory); - } - baseCalculator = standardLocal.getCalculator(); - addAlgorithmListeners(standardLocal.getAlgorithmListener()); - addInsertionListeners(standardLocal.getInsertionListener()); - if(considerFixedCost){ - CalculatorPlusListeners withFixed = createCalculatorConsideringFixedCosts(vrp, baseCalculator, states, weightOfFixedCost); - baseCalculator = withFixed.getCalculator(); - addAlgorithmListeners(withFixed.getAlgorithmListener()); - addInsertionListeners(withFixed.getInsertionListener()); - } - if(timeScheduling){ + /** + * Sets a flag to build a calculator based on local calculations. + *

+ *

Insertion of a job and job-activity is evaluated based on the previous and next activity. + * + * @param addDefaultCostCalc + */ + public JobInsertionCostsCalculatorBuilder setLocalLevel(boolean addDefaultCostCalc) { + local = true; + this.addDefaultCostCalc = addDefaultCostCalc; + return this; + } + + public JobInsertionCostsCalculatorBuilder setActivityInsertionCostsCalculator(ActivityInsertionCostsCalculator activityInsertionCostsCalculator) { + this.activityInsertionCostCalculator = activityInsertionCostsCalculator; + return this; + } + + /** + * Sets a flag to build a calculator that evaluates job insertion on route-level. + * + * @param forwardLooking + * @param memory + * @param addDefaultMarginalCostCalc + */ + public JobInsertionCostsCalculatorBuilder setRouteLevel(int forwardLooking, int memory, boolean addDefaultMarginalCostCalc) { + local = false; + this.forwardLooking = forwardLooking; + this.memory = memory; + return this; + } + + /** + * Sets a flag to consider also fixed-cost when evaluating the insertion of a job. The weight of the fixed-cost can be determined by setting + * weightofFixedCosts. + * + * @param weightOfFixedCosts + */ + public JobInsertionCostsCalculatorBuilder considerFixedCosts(double weightOfFixedCosts) { + considerFixedCost = true; + this.weightOfFixedCost = weightOfFixedCosts; + return this; + } + + public JobInsertionCostsCalculatorBuilder experimentalTimeScheduler(double timeSlice, int neighbors) { + timeScheduling = true; + this.timeSlice = timeSlice; + this.neighbors = neighbors; + return this; + } + + /** + * Builds the jobInsertionCalculator. + * + * @return jobInsertionCalculator. + * @throws IllegalStateException if vrp == null or activityStates == null or fleetManager == null. + */ + public JobInsertionCostsCalculator build() { + if (vrp == null) + throw new IllegalStateException("vehicle-routing-problem is null, but it must be set (this.setVehicleRoutingProblem(vrp))"); + if (states == null) + throw new IllegalStateException("states is null, but is must be set (this.setStateManager(states))"); + if (fleetManager == null) + throw new IllegalStateException("fleetManager is null, but it must be set (this.setVehicleFleetManager(fleetManager))"); + JobInsertionCostsCalculator baseCalculator = null; + CalculatorPlusListeners standardLocal = null; + if (local) { + standardLocal = createStandardLocal(vrp, states); + } else { + checkServicesOnly(); + standardLocal = createStandardRoute(vrp, states, forwardLooking, memory); + } + baseCalculator = standardLocal.getCalculator(); + addAlgorithmListeners(standardLocal.getAlgorithmListener()); + addInsertionListeners(standardLocal.getInsertionListener()); + if (considerFixedCost) { + CalculatorPlusListeners withFixed = createCalculatorConsideringFixedCosts(vrp, baseCalculator, states, weightOfFixedCost); + baseCalculator = withFixed.getCalculator(); + addAlgorithmListeners(withFixed.getAlgorithmListener()); + addInsertionListeners(withFixed.getInsertionListener()); + } + if (timeScheduling) { // baseCalculator = new CalculatesServiceInsertionWithTimeSchedulingInSlices(baseCalculator,timeSlice,neighbors); - CalculatesServiceInsertionWithTimeScheduling wts = new CalculatesServiceInsertionWithTimeScheduling(baseCalculator,timeSlice,neighbors); + CalculatesServiceInsertionWithTimeScheduling wts = new CalculatesServiceInsertionWithTimeScheduling(baseCalculator, timeSlice, neighbors); CalculatorPlusListeners calcPlusListeners = new CalculatorPlusListeners(wts); calcPlusListeners.getInsertionListener().add(new CalculatesServiceInsertionWithTimeScheduling.KnowledgeInjection(wts)); addInsertionListeners(calcPlusListeners.getInsertionListener()); baseCalculator = calcPlusListeners.getCalculator(); - } - return createFinalInsertion(fleetManager, baseCalculator, states); - } + } + return createFinalInsertion(fleetManager, baseCalculator, states); + } - private void checkServicesOnly() { - for(Job j : vrp.getJobs().values()){ - if(j instanceof Shipment){ - throw new UnsupportedOperationException("currently the 'insert-on-route-level' option is only available for services (i.e. service, pickup, delivery), \n" + - "if you want to deal with shipments switch to option 'local-level' by either setting bestInsertionBuilder.setLocalLevel() or \n" - + "by omitting the xml-tag 'route' when defining your insertionStrategy in algo-config.xml file"); - } - } - - } + private void checkServicesOnly() { + for (Job j : vrp.getJobs().values()) { + if (j instanceof Shipment) { + throw new UnsupportedOperationException("currently the 'insert-on-route-level' option is only available for services (i.e. service, pickup, delivery), \n" + + "if you want to deal with shipments switch to option 'local-level' by either setting bestInsertionBuilder.setLocalLevel() or \n" + + "by omitting the xml-tag 'route' when defining your insertionStrategy in algo-config.xml file"); + } + } - private void addInsertionListeners(List list) { - for(InsertionListener iL : list){ - insertionListeners.add(iL); - } - } + } - private void addAlgorithmListeners(List list) { - for(PrioritizedVRAListener aL : list){ - algorithmListeners.add(aL); - } - } + private void addInsertionListeners(List list) { + for (InsertionListener iL : list) { + insertionListeners.add(iL); + } + } - private CalculatorPlusListeners createStandardLocal(final VehicleRoutingProblem vrp, RouteAndActivityStateGetter statesManager){ - if(constraintManager == null) throw new IllegalStateException("constraint-manager is null"); + private void addAlgorithmListeners(List list) { + for (PrioritizedVRAListener aL : list) { + algorithmListeners.add(aL); + } + } - ActivityInsertionCostsCalculator actInsertionCalc; - if(activityInsertionCostCalculator == null && addDefaultCostCalc){ - actInsertionCalc = new LocalActivityInsertionCostsCalculator(vrp.getTransportCosts(), vrp.getActivityCosts()); - } - else if(activityInsertionCostCalculator == null && !addDefaultCostCalc){ - actInsertionCalc = new ActivityInsertionCostsCalculator(){ + private CalculatorPlusListeners createStandardLocal(final VehicleRoutingProblem vrp, RouteAndActivityStateGetter statesManager) { + if (constraintManager == null) throw new IllegalStateException("constraint-manager is null"); - @Override - public double getCosts(JobInsertionContext iContext, TourActivity prevAct, TourActivity nextAct, TourActivity newAct, + ActivityInsertionCostsCalculator actInsertionCalc; + ConfigureLocalActivityInsertionCalculator configLocal = null; + if (activityInsertionCostCalculator == null && addDefaultCostCalc) { + actInsertionCalc = new LocalActivityInsertionCostsCalculator(vrp.getTransportCosts(), vrp.getActivityCosts(), statesManager); + configLocal = new ConfigureLocalActivityInsertionCalculator(vrp, (LocalActivityInsertionCostsCalculator) actInsertionCalc); + } else if (activityInsertionCostCalculator == null && !addDefaultCostCalc) { + actInsertionCalc = new ActivityInsertionCostsCalculator() { + + @Override + public double getCosts(JobInsertionContext iContext, TourActivity prevAct, TourActivity nextAct, TourActivity newAct, double depTimeAtPrevAct) { - return 0.; - } - - }; - } - else{ - actInsertionCalc = activityInsertionCostCalculator; - } + return 0.; + } + + }; + } else { + actInsertionCalc = activityInsertionCostCalculator; + } JobActivityFactory activityFactory = new JobActivityFactory() { @@ -285,55 +286,61 @@ public class JobInsertionCostsCalculatorBuilder { } }; - ShipmentInsertionCalculator shipmentInsertion = new ShipmentInsertionCalculator(vrp.getTransportCosts(), actInsertionCalc, constraintManager); + ShipmentInsertionCalculator shipmentInsertion = new ShipmentInsertionCalculator(vrp.getTransportCosts(), actInsertionCalc, constraintManager); shipmentInsertion.setJobActivityFactory(activityFactory); - ServiceInsertionCalculator serviceInsertion = new ServiceInsertionCalculator(vrp.getTransportCosts(), actInsertionCalc, constraintManager); + ServiceInsertionCalculator serviceInsertion = new ServiceInsertionCalculator(vrp.getTransportCosts(), actInsertionCalc, constraintManager); serviceInsertion.setJobActivityFactory(activityFactory); + BreakInsertionCalculator breakInsertionCalculator = new BreakInsertionCalculator(vrp.getTransportCosts(), actInsertionCalc, constraintManager); + breakInsertionCalculator.setJobActivityFactory(activityFactory); + JobCalculatorSwitcher switcher = new JobCalculatorSwitcher(); - switcher.put(Shipment.class, shipmentInsertion); - switcher.put(Service.class, serviceInsertion); - switcher.put(Pickup.class, serviceInsertion); - switcher.put(Delivery.class, serviceInsertion); + switcher.put(Shipment.class, shipmentInsertion); + switcher.put(Service.class, serviceInsertion); + switcher.put(Pickup.class, serviceInsertion); + switcher.put(Delivery.class, serviceInsertion); + switcher.put(Break.class, breakInsertionCalculator); - return new CalculatorPlusListeners(switcher); - } + CalculatorPlusListeners calculatorPlusListeners = new CalculatorPlusListeners(switcher); + if (configLocal != null) { + calculatorPlusListeners.insertionListener.add(configLocal); + } + return calculatorPlusListeners; + } - private CalculatorPlusListeners createCalculatorConsideringFixedCosts(VehicleRoutingProblem vrp, JobInsertionCostsCalculator baseCalculator, RouteAndActivityStateGetter activityStates2, double weightOfFixedCosts){ - final JobInsertionConsideringFixCostsCalculator withFixCost = new JobInsertionConsideringFixCostsCalculator(baseCalculator, activityStates2); - withFixCost.setWeightOfFixCost(weightOfFixedCosts); - CalculatorPlusListeners calcPlusListeners = new CalculatorPlusListeners(withFixCost); - calcPlusListeners.getInsertionListener().add(new ConfigureFixCostCalculator(vrp, withFixCost)); - return calcPlusListeners; - } + private CalculatorPlusListeners createCalculatorConsideringFixedCosts(VehicleRoutingProblem vrp, JobInsertionCostsCalculator baseCalculator, RouteAndActivityStateGetter activityStates2, double weightOfFixedCosts) { + final JobInsertionConsideringFixCostsCalculator withFixCost = new JobInsertionConsideringFixCostsCalculator(baseCalculator, activityStates2); + withFixCost.setWeightOfFixCost(weightOfFixedCosts); + CalculatorPlusListeners calcPlusListeners = new CalculatorPlusListeners(withFixCost); + calcPlusListeners.getInsertionListener().add(new ConfigureFixCostCalculator(vrp, withFixCost)); + return calcPlusListeners; + } - private CalculatorPlusListeners createStandardRoute(final VehicleRoutingProblem vrp, RouteAndActivityStateGetter activityStates2, int forwardLooking, int solutionMemory){ - ActivityInsertionCostsCalculator routeLevelCostEstimator; - if(activityInsertionCostCalculator == null && addDefaultCostCalc){ + private CalculatorPlusListeners createStandardRoute(final VehicleRoutingProblem vrp, RouteAndActivityStateGetter activityStates2, int forwardLooking, int solutionMemory) { + ActivityInsertionCostsCalculator routeLevelCostEstimator; + if (activityInsertionCostCalculator == null && addDefaultCostCalc) { RouteLevelActivityInsertionCostsEstimator routeLevelActivityInsertionCostsEstimator = new RouteLevelActivityInsertionCostsEstimator(vrp.getTransportCosts(), vrp.getActivityCosts(), activityStates2); routeLevelActivityInsertionCostsEstimator.setForwardLooking(forwardLooking); routeLevelCostEstimator = routeLevelActivityInsertionCostsEstimator; - } - else if(activityInsertionCostCalculator == null && !addDefaultCostCalc){ - routeLevelCostEstimator = new ActivityInsertionCostsCalculator(){ + } else if (activityInsertionCostCalculator == null && !addDefaultCostCalc) { + routeLevelCostEstimator = new ActivityInsertionCostsCalculator() { - final ActivityInsertionCosts noInsertionCosts = new ActivityInsertionCosts(0.,0.); - - @Override - public double getCosts(JobInsertionContext iContext, TourActivity prevAct, TourActivity nextAct, TourActivity newAct, + final ActivityInsertionCosts noInsertionCosts = new ActivityInsertionCosts(0., 0.); + + @Override + public double getCosts(JobInsertionContext iContext, TourActivity prevAct, TourActivity nextAct, TourActivity newAct, double depTimeAtPrevAct) { - return 0.; - } - - }; - } - else{ - routeLevelCostEstimator = activityInsertionCostCalculator; - } + return 0.; + } + + }; + } else { + routeLevelCostEstimator = activityInsertionCostCalculator; + } ServiceInsertionOnRouteLevelCalculator jobInsertionCalculator = new ServiceInsertionOnRouteLevelCalculator(vrp.getTransportCosts(), vrp.getActivityCosts(), routeLevelCostEstimator, constraintManager, constraintManager); - jobInsertionCalculator.setNuOfActsForwardLooking(forwardLooking); - jobInsertionCalculator.setMemorySize(solutionMemory); - jobInsertionCalculator.setStates(activityStates2); + jobInsertionCalculator.setNuOfActsForwardLooking(forwardLooking); + jobInsertionCalculator.setMemorySize(solutionMemory); + jobInsertionCalculator.setStates(activityStates2); jobInsertionCalculator.setJobActivityFactory(new JobActivityFactory() { @Override public List createActivities(Job job) { @@ -341,23 +348,23 @@ public class JobInsertionCostsCalculatorBuilder { } }); return new CalculatorPlusListeners(jobInsertionCalculator); - } + } - private JobInsertionCostsCalculator createFinalInsertion(VehicleFleetManager fleetManager, JobInsertionCostsCalculator baseCalc, RouteAndActivityStateGetter activityStates2){ - VehicleTypeDependentJobInsertionCalculator vehicleTypeDependentJobInsertionCalculator = new VehicleTypeDependentJobInsertionCalculator(vrp, fleetManager, baseCalc); - vehicleTypeDependentJobInsertionCalculator.setVehicleSwitchAllowed(allowVehicleSwitch); - return vehicleTypeDependentJobInsertionCalculator; - } + private JobInsertionCostsCalculator createFinalInsertion(VehicleFleetManager fleetManager, JobInsertionCostsCalculator baseCalc, RouteAndActivityStateGetter activityStates2) { + VehicleTypeDependentJobInsertionCalculator vehicleTypeDependentJobInsertionCalculator = new VehicleTypeDependentJobInsertionCalculator(vrp, fleetManager, baseCalc); + vehicleTypeDependentJobInsertionCalculator.setVehicleSwitchAllowed(allowVehicleSwitch); + return vehicleTypeDependentJobInsertionCalculator; + } - public JobInsertionCostsCalculatorBuilder setConstraintManager(ConstraintManager constraintManager) { - this.constraintManager = constraintManager; + public JobInsertionCostsCalculatorBuilder setConstraintManager(ConstraintManager constraintManager) { + this.constraintManager = constraintManager; return this; - } + } - public JobInsertionCostsCalculatorBuilder setAllowVehicleSwitch(boolean allowVehicleSwitch) { + public JobInsertionCostsCalculatorBuilder setAllowVehicleSwitch(boolean allowVehicleSwitch) { this.allowVehicleSwitch = allowVehicleSwitch; return this; - } + } } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/JobInsertionCostsCalculatorLight.java b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/JobInsertionCostsCalculatorLight.java index 65353e1a..9414e351 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/JobInsertionCostsCalculatorLight.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/JobInsertionCostsCalculatorLight.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.recreate; @@ -22,6 +22,6 @@ import jsprit.core.problem.solution.route.VehicleRoute; public interface JobInsertionCostsCalculatorLight { - public InsertionData getInsertionData(Job unassignedJob, VehicleRoute route, double bestKnownCosts); + public InsertionData getInsertionData(Job unassignedJob, VehicleRoute route, double bestKnownCosts); } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/JobInsertionCostsCalculatorLightFactory.java b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/JobInsertionCostsCalculatorLightFactory.java index 6884dad0..1079d644 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/JobInsertionCostsCalculatorLightFactory.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/JobInsertionCostsCalculatorLightFactory.java @@ -38,23 +38,23 @@ public class JobInsertionCostsCalculatorLightFactory { * Returns standard insertion calculator, i.e. the calculator that identifies best insertion positions for the * jobs to be inserted. The position basically consists of the route and the according indices. * - * @param vrp vehicle routing problem - * @param fleetManager fleet manager - * @param stateManager state manager + * @param vrp vehicle routing problem + * @param fleetManager fleet manager + * @param stateManager state manager * @param constraintManager constraint manager * @return insertion calculator */ - public static JobInsertionCostsCalculatorLight createStandardCalculator(VehicleRoutingProblem vrp, VehicleFleetManager fleetManager, StateManager stateManager, ConstraintManager constraintManager){ + public static JobInsertionCostsCalculatorLight createStandardCalculator(VehicleRoutingProblem vrp, VehicleFleetManager fleetManager, StateManager stateManager, ConstraintManager constraintManager) { List al = new ArrayList(); List il = new ArrayList(); - JobInsertionCostsCalculatorBuilder builder = new JobInsertionCostsCalculatorBuilder(il,al); + JobInsertionCostsCalculatorBuilder builder = new JobInsertionCostsCalculatorBuilder(il, al); builder.setVehicleRoutingProblem(vrp).setConstraintManager(constraintManager).setStateManager(stateManager).setVehicleFleetManager(fleetManager); final JobInsertionCostsCalculator calculator = builder.build(); return new JobInsertionCostsCalculatorLight() { @Override public InsertionData getInsertionData(Job unassignedJob, VehicleRoute route, double bestKnownCosts) { - return calculator.getInsertionData(route,unassignedJob,AbstractInsertionStrategy.NO_NEW_VEHICLE_YET,AbstractInsertionStrategy.NO_NEW_DEPARTURE_TIME_YET,AbstractInsertionStrategy.NO_NEW_DRIVER_YET,bestKnownCosts); + return calculator.getInsertionData(route, unassignedJob, AbstractInsertionStrategy.NO_NEW_VEHICLE_YET, AbstractInsertionStrategy.NO_NEW_DEPARTURE_TIME_YET, AbstractInsertionStrategy.NO_NEW_DRIVER_YET, bestKnownCosts); } }; diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/LocalActivityInsertionCostsCalculator.java b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/LocalActivityInsertionCostsCalculator.java index 0a8e61c0..11b42742 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/LocalActivityInsertionCostsCalculator.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/LocalActivityInsertionCostsCalculator.java @@ -1,4 +1,3 @@ - /******************************************************************************* * Copyright (C) 2014 Stefan Schroeder * @@ -18,72 +17,94 @@ package jsprit.core.algorithm.recreate; +import jsprit.core.algorithm.state.InternalStates; import jsprit.core.problem.cost.VehicleRoutingActivityCosts; import jsprit.core.problem.cost.VehicleRoutingTransportCosts; import jsprit.core.problem.misc.JobInsertionContext; import jsprit.core.problem.solution.route.activity.End; import jsprit.core.problem.solution.route.activity.TourActivity; +import jsprit.core.problem.solution.route.state.RouteAndActivityStateGetter; +import jsprit.core.problem.vehicle.Vehicle; import jsprit.core.util.CalculationUtils; /** * Calculates activity insertion costs locally, i.e. by comparing the additional costs of insertion the new activity k between * activity i (prevAct) and j (nextAct). * Additional costs are then basically calculated as delta c = c_ik + c_kj - c_ij. - * + *

*

Note once time has an effect on costs this class requires activity endTimes. - * - * @author stefan * + * @author stefan */ -class LocalActivityInsertionCostsCalculator implements ActivityInsertionCostsCalculator{ +class LocalActivityInsertionCostsCalculator implements ActivityInsertionCostsCalculator { - private VehicleRoutingTransportCosts routingCosts; - - private VehicleRoutingActivityCosts activityCosts; - - - public LocalActivityInsertionCostsCalculator(VehicleRoutingTransportCosts routingCosts, VehicleRoutingActivityCosts actCosts) { - super(); - this.routingCosts = routingCosts; - this.activityCosts = actCosts; - } + private VehicleRoutingTransportCosts routingCosts; - @Override - public double getCosts(JobInsertionContext iFacts, TourActivity prevAct, TourActivity nextAct, TourActivity newAct, double depTimeAtPrevAct) { - - double tp_costs_prevAct_newAct = routingCosts.getTransportCost(prevAct.getLocation(), newAct.getLocation(), depTimeAtPrevAct, iFacts.getNewDriver(), iFacts.getNewVehicle()); - double tp_time_prevAct_newAct = routingCosts.getTransportTime(prevAct.getLocation(), newAct.getLocation(), depTimeAtPrevAct, iFacts.getNewDriver(), iFacts.getNewVehicle()); - double newAct_arrTime = depTimeAtPrevAct + tp_time_prevAct_newAct; - double newAct_endTime = CalculationUtils.getActivityEndTime(newAct_arrTime, newAct); - double act_costs_newAct = activityCosts.getActivityCost(newAct, newAct_arrTime, iFacts.getNewDriver(), iFacts.getNewVehicle()); - - //open routes - if(nextAct instanceof End){ - if(!iFacts.getNewVehicle().isReturnToDepot()){ - return tp_costs_prevAct_newAct; - } - } - - double tp_costs_newAct_nextAct = routingCosts.getTransportCost(newAct.getLocation(), nextAct.getLocation(), newAct_endTime, iFacts.getNewDriver(), iFacts.getNewVehicle()); - double tp_time_newAct_nextAct = routingCosts.getTransportTime(newAct.getLocation(), nextAct.getLocation(), newAct_endTime, iFacts.getNewDriver(), iFacts.getNewVehicle()); - double nextAct_arrTime = newAct_endTime + tp_time_newAct_nextAct; - double act_costs_nextAct = activityCosts.getActivityCost(nextAct, nextAct_arrTime, iFacts.getNewDriver(), iFacts.getNewVehicle()); - double totalCosts = tp_costs_prevAct_newAct + tp_costs_newAct_nextAct + act_costs_newAct + act_costs_nextAct; - - double oldCosts; - if(iFacts.getRoute().isEmpty()){ - double tp_costs_prevAct_nextAct = routingCosts.getTransportCost(prevAct.getLocation(), nextAct.getLocation(), depTimeAtPrevAct, iFacts.getNewDriver(), iFacts.getNewVehicle()); - double arrTime_nextAct = routingCosts.getTransportTime(prevAct.getLocation(), nextAct.getLocation(), depTimeAtPrevAct, iFacts.getNewDriver(), iFacts.getNewVehicle()); - double actCost_nextAct = activityCosts.getActivityCost(nextAct, arrTime_nextAct, iFacts.getNewDriver(), iFacts.getNewVehicle()); - oldCosts = tp_costs_prevAct_nextAct + actCost_nextAct; - } - else{ - double tp_costs_prevAct_nextAct = routingCosts.getTransportCost(prevAct.getLocation(), nextAct.getLocation(), prevAct.getEndTime(), iFacts.getRoute().getDriver(), iFacts.getRoute().getVehicle()); - double arrTime_nextAct = routingCosts.getTransportTime(prevAct.getLocation(), nextAct.getLocation(), prevAct.getEndTime(), iFacts.getRoute().getDriver(), iFacts.getRoute().getVehicle()); - double actCost_nextAct = activityCosts.getActivityCost(nextAct, arrTime_nextAct, iFacts.getRoute().getDriver(), iFacts.getRoute().getVehicle()); - oldCosts = tp_costs_prevAct_nextAct + actCost_nextAct; - } - return totalCosts - oldCosts; - } + private VehicleRoutingActivityCosts activityCosts; + private double activityCostsWeight = 1.; + + private double solutionCompletenessRatio = 1.; + + private RouteAndActivityStateGetter stateManager; + + public LocalActivityInsertionCostsCalculator(VehicleRoutingTransportCosts routingCosts, VehicleRoutingActivityCosts actCosts, RouteAndActivityStateGetter stateManager) { + super(); + this.routingCosts = routingCosts; + this.activityCosts = actCosts; + this.stateManager = stateManager; + } + + @Override + public double getCosts(JobInsertionContext iFacts, TourActivity prevAct, TourActivity nextAct, TourActivity newAct, double depTimeAtPrevAct) { + + double tp_costs_prevAct_newAct = routingCosts.getTransportCost(prevAct.getLocation(), newAct.getLocation(), depTimeAtPrevAct, iFacts.getNewDriver(), iFacts.getNewVehicle()); + double tp_time_prevAct_newAct = routingCosts.getTransportTime(prevAct.getLocation(), newAct.getLocation(), depTimeAtPrevAct, iFacts.getNewDriver(), iFacts.getNewVehicle()); + double newAct_arrTime = depTimeAtPrevAct + tp_time_prevAct_newAct; + double newAct_endTime = CalculationUtils.getActivityEndTime(newAct_arrTime, newAct); + + double act_costs_newAct = activityCosts.getActivityCost(newAct, newAct_arrTime, iFacts.getNewDriver(), iFacts.getNewVehicle()); + + if (isEnd(nextAct) && !toDepot(iFacts.getNewVehicle())) return tp_costs_prevAct_newAct; + + double tp_costs_newAct_nextAct = routingCosts.getTransportCost(newAct.getLocation(), nextAct.getLocation(), newAct_endTime, iFacts.getNewDriver(), iFacts.getNewVehicle()); + double tp_time_newAct_nextAct = routingCosts.getTransportTime(newAct.getLocation(), nextAct.getLocation(), newAct_endTime, iFacts.getNewDriver(), iFacts.getNewVehicle()); + double nextAct_arrTime = newAct_endTime + tp_time_newAct_nextAct; + double endTime_nextAct_new = CalculationUtils.getActivityEndTime(nextAct_arrTime, nextAct); + double act_costs_nextAct = activityCosts.getActivityCost(nextAct, nextAct_arrTime, iFacts.getNewDriver(), iFacts.getNewVehicle()); + + double totalCosts = tp_costs_prevAct_newAct + tp_costs_newAct_nextAct + solutionCompletenessRatio * activityCostsWeight * (act_costs_newAct + act_costs_nextAct); + + double oldCosts = 0.; + if (iFacts.getRoute().isEmpty()) { + double tp_costs_prevAct_nextAct = routingCosts.getTransportCost(prevAct.getLocation(), nextAct.getLocation(), depTimeAtPrevAct, iFacts.getNewDriver(), iFacts.getNewVehicle()); + oldCosts += tp_costs_prevAct_nextAct; + } else { + double tp_costs_prevAct_nextAct = routingCosts.getTransportCost(prevAct.getLocation(), nextAct.getLocation(), prevAct.getEndTime(), iFacts.getRoute().getDriver(), iFacts.getRoute().getVehicle()); + double arrTime_nextAct = depTimeAtPrevAct + routingCosts.getTransportTime(prevAct.getLocation(), nextAct.getLocation(), prevAct.getEndTime(), iFacts.getRoute().getDriver(), iFacts.getRoute().getVehicle()); + double endTime_nextAct_old = CalculationUtils.getActivityEndTime(arrTime_nextAct, nextAct); + double actCost_nextAct = activityCosts.getActivityCost(nextAct, arrTime_nextAct, iFacts.getRoute().getDriver(), iFacts.getRoute().getVehicle()); + + double endTimeDelay_nextAct = Math.max(0, endTime_nextAct_new - endTime_nextAct_old); + Double futureWaiting = stateManager.getActivityState(nextAct, iFacts.getRoute().getVehicle(), InternalStates.FUTURE_WAITING, Double.class); + if (futureWaiting == null) futureWaiting = 0.; + double waitingTime_savings_timeUnit = Math.min(futureWaiting, endTimeDelay_nextAct); + double waitingTime_savings = waitingTime_savings_timeUnit * iFacts.getRoute().getVehicle().getType().getVehicleCostParams().perWaitingTimeUnit; + oldCosts += solutionCompletenessRatio * activityCostsWeight * waitingTime_savings; + oldCosts += tp_costs_prevAct_nextAct + solutionCompletenessRatio * activityCostsWeight * actCost_nextAct; + } + return totalCosts - oldCosts; + } + + private boolean toDepot(Vehicle newVehicle) { + return newVehicle.isReturnToDepot(); + } + + private boolean isEnd(TourActivity nextAct) { + return nextAct instanceof End; + } + + public void setSolutionCompletenessRatio(double solutionCompletenessRatio) { + this.solutionCompletenessRatio = solutionCompletenessRatio; + } } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/NoSolutionFoundException.java b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/NoSolutionFoundException.java index 985759a8..28cb3367 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/NoSolutionFoundException.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/NoSolutionFoundException.java @@ -1,32 +1,32 @@ /******************************************************************************* * Copyright (c) 2014 Stefan Schroeder. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . - * + * * Contributors: * Stefan Schroeder - initial API and implementation ******************************************************************************/ package jsprit.core.algorithm.recreate; -public class NoSolutionFoundException extends IllegalStateException{ +public class NoSolutionFoundException extends IllegalStateException { - public NoSolutionFoundException(String errorMsg) { - super(errorMsg); - } + public NoSolutionFoundException(String errorMsg) { + super(errorMsg); + } - /** - * - */ - private static final long serialVersionUID = 1L; + /** + * + */ + private static final long serialVersionUID = 1L; } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/RegretInsertion.java b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/RegretInsertion.java index f6931f75..199b65ab 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/RegretInsertion.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/RegretInsertion.java @@ -17,224 +17,106 @@ package jsprit.core.algorithm.recreate; -import jsprit.core.problem.Location; import jsprit.core.problem.VehicleRoutingProblem; +import jsprit.core.problem.job.Break; import jsprit.core.problem.job.Job; -import jsprit.core.problem.job.Service; -import jsprit.core.problem.job.Shipment; import jsprit.core.problem.solution.route.VehicleRoute; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import java.util.ArrayList; import java.util.Collection; +import java.util.Iterator; import java.util.List; /** -* Insertion based on regret approach. -* -*

Basically calculates the insertion cost of the firstBest and the secondBest alternative. The score is then calculated as difference -* between secondBest and firstBest, plus additional scoring variables that can defined in this.ScoringFunction. -* The idea is that if the cost of the secondBest alternative is way higher than the first best, it seems to be important to insert this -* customer immediatedly. If difference is not that high, it might not impact solution if this customer is inserted later. -* -* @author stefan schroeder -* -*/ + * Insertion based on regret approach. + *

+ *

Basically calculates the insertion cost of the firstBest and the secondBest alternative. The score is then calculated as difference + * between secondBest and firstBest, plus additional scoring variables that can defined in this.ScoringFunction. + * The idea is that if the cost of the secondBest alternative is way higher than the first best, it seems to be important to insert this + * customer immediatedly. If difference is not that high, it might not impact solution if this customer is inserted later. + * + * @author stefan schroeder + */ public class RegretInsertion extends AbstractInsertionStrategy { - static class ScoredJob { - - private Job job; - - private double score; - - private InsertionData insertionData; - - private VehicleRoute route; - - private boolean newRoute; - ScoredJob(Job job, double score, InsertionData insertionData, VehicleRoute route, boolean isNewRoute) { - this.job = job; - this.score = score; - this.insertionData = insertionData; - this.route = route; - this.newRoute = isNewRoute; - } + private static Logger logger = LogManager.getLogger(RegretInsertionFast.class); - public boolean isNewRoute() { - return newRoute; - } - - public Job getJob() { - return job; - } - - public double getScore() { - return score; - } - - public InsertionData getInsertionData() { - return insertionData; - } - - public VehicleRoute getRoute() { - return route; - } - } - - static class BadJob extends ScoredJob { - - BadJob(Job job) { - super(job, 0., null, null, false); - } - } - - /** - * Scorer to include other impacts on score such as time-window length or distance to depot. - * - * @author schroeder - * - */ - static interface ScoringFunction { - - public double score(InsertionData best, Job job); - - } - - /** - * Scorer that includes the length of the time-window when scoring a job. The wider the time-window, the lower the score. - * - *

This is the default scorer, i.e.: score = (secondBest - firstBest) + this.TimeWindowScorer.score(job) - * - * @author schroeder - * - */ - public static class DefaultScorer implements ScoringFunction { - - private VehicleRoutingProblem vrp; - - private double tw_param = - 0.5; - - private double depotDistance_param = + 0.1; - - private double minTimeWindowScore = - 100000; - - public DefaultScorer(VehicleRoutingProblem vrp) { - this.vrp = vrp; - } - - public void setTimeWindowParam(double tw_param){ this.tw_param = tw_param; } - - public void setDepotDistanceParam(double depotDistance_param){ this.depotDistance_param = depotDistance_param; } - - @Override - public double score(InsertionData best, Job job) { - double score; - if(job instanceof Service){ - score = scoreService(best, job); - } - else if(job instanceof Shipment){ - score = scoreShipment(best,job); - } - else throw new IllegalStateException("not supported"); - return score; - } - - private double scoreShipment(InsertionData best, Job job) { - Shipment shipment = (Shipment)job; - double maxDepotDistance_1 = Math.max( - getDistance(best.getSelectedVehicle().getStartLocation(),shipment.getPickupLocation()), - getDistance(best.getSelectedVehicle().getStartLocation(),shipment.getDeliveryLocation()) - ); - double maxDepotDistance_2 = Math.max( - getDistance(best.getSelectedVehicle().getEndLocation(),shipment.getPickupLocation()), - getDistance(best.getSelectedVehicle().getEndLocation(),shipment.getDeliveryLocation()) - ); - double maxDepotDistance = Math.max(maxDepotDistance_1,maxDepotDistance_2); - double minTimeToOperate = Math.min(shipment.getPickupTimeWindow().getEnd()-shipment.getPickupTimeWindow().getStart(), - shipment.getDeliveryTimeWindow().getEnd()-shipment.getDeliveryTimeWindow().getStart()); - return Math.max(tw_param * minTimeToOperate,minTimeWindowScore) + depotDistance_param * maxDepotDistance; - } - - private double scoreService(InsertionData best, Job job) { - double maxDepotDistance = Math.max( - getDistance(best.getSelectedVehicle().getStartLocation(), ((Service) job).getLocation()), - getDistance(best.getSelectedVehicle().getEndLocation(), ((Service) job).getLocation()) - ); - return Math.max(tw_param * (((Service)job).getTimeWindow().getEnd() - ((Service)job).getTimeWindow().getStart()),minTimeWindowScore) + - depotDistance_param * maxDepotDistance; - } - - - private double getDistance(Location loc1, Location loc2) { - return vrp.getTransportCosts().getTransportCost(loc1,loc2,0.,null,null); - } - - @Override - public String toString() { - return "[name=defaultScorer][twParam="+tw_param+"][depotDistanceParam=" + depotDistance_param + "]"; - } - - } - - private static Logger logger = LogManager.getLogger(RegretInsertion.class); - - private ScoringFunction scoringFunction; + private ScoringFunction scoringFunction; private JobInsertionCostsCalculator insertionCostsCalculator; /** - * Sets the scoring function. - * - *

By default, the this.TimeWindowScorer is used. - * - * @param scoringFunction to score - */ - public void setScoringFunction(ScoringFunction scoringFunction) { - this.scoringFunction = scoringFunction; - } + * Sets the scoring function. + *

+ *

By default, the this.TimeWindowScorer is used. + * + * @param scoringFunction to score + */ + public void setScoringFunction(ScoringFunction scoringFunction) { + this.scoringFunction = scoringFunction; + } - public RegretInsertion(JobInsertionCostsCalculator jobInsertionCalculator, VehicleRoutingProblem vehicleRoutingProblem) { - super(vehicleRoutingProblem); + public RegretInsertion(JobInsertionCostsCalculator jobInsertionCalculator, VehicleRoutingProblem vehicleRoutingProblem) { + super(vehicleRoutingProblem); this.scoringFunction = new DefaultScorer(vehicleRoutingProblem); - this.insertionCostsCalculator = jobInsertionCalculator; + this.insertionCostsCalculator = jobInsertionCalculator; this.vrp = vehicleRoutingProblem; - logger.debug("initialise " + this); - } + logger.debug("initialise {}", this); + } - @Override - public String toString() { - return "[name=regretInsertion][additionalScorer="+scoringFunction+"]"; - } + @Override + public String toString() { + return "[name=regretInsertion][additionalScorer=" + scoringFunction + "]"; + } - /** - * Runs insertion. - * - *

Before inserting a job, all unassigned jobs are scored according to its best- and secondBest-insertion plus additional scoring variables. - * - */ - @Override - public Collection insertUnassignedJobs(Collection routes, Collection unassignedJobs) { + /** + * Runs insertion. + *

+ *

Before inserting a job, all unassigned jobs are scored according to its best- and secondBest-insertion plus additional scoring variables. + */ + @Override + public Collection insertUnassignedJobs(Collection routes, Collection unassignedJobs) { List badJobs = new ArrayList(unassignedJobs.size()); - List jobs = new ArrayList(unassignedJobs); + Iterator jobIterator = unassignedJobs.iterator(); + while (jobIterator.hasNext()){ + Job job = jobIterator.next(); + if(job instanceof Break){ + VehicleRoute route = findRoute(routes,job); + if(route == null){ + badJobs.add(job); + } + else { + InsertionData iData = insertionCostsCalculator.getInsertionData(route, job, NO_NEW_VEHICLE_YET, NO_NEW_DEPARTURE_TIME_YET, NO_NEW_DRIVER_YET, Double.MAX_VALUE); + if (iData instanceof InsertionData.NoInsertionFound) { + badJobs.add(job); + } else { + insertJob(job, iData, route); + } + } + jobIterator.remove(); + } + } + + List jobs = new ArrayList(unassignedJobs); while (!jobs.isEmpty()) { List unassignedJobList = new ArrayList(jobs); List badJobList = new ArrayList(); ScoredJob bestScoredJob = nextJob(routes, unassignedJobList, badJobList); - if(bestScoredJob != null){ - if(bestScoredJob.isNewRoute()){ + if (bestScoredJob != null) { + if (bestScoredJob.isNewRoute()) { routes.add(bestScoredJob.getRoute()); } - insertJob(bestScoredJob.getJob(),bestScoredJob.getInsertionData(),bestScoredJob.getRoute()); + insertJob(bestScoredJob.getJob(), bestScoredJob.getInsertionData(), bestScoredJob.getRoute()); jobs.remove(bestScoredJob.getJob()); } - for(Job bad : badJobList) { + for (Job bad : badJobList) { jobs.remove(bad); badJobs.add(bad); } @@ -242,18 +124,29 @@ public class RegretInsertion extends AbstractInsertionStrategy { return badJobs; } - private ScoredJob nextJob(Collection routes, List unassignedJobList, List badJobs) { + private VehicleRoute findRoute(Collection routes, Job job) { + for(VehicleRoute r : routes){ + if(r.getVehicle().getBreak() == job) return r; + } + return null; + } + + private ScoredJob nextJob(Collection routes, Collection unassignedJobList, List badJobs) { ScoredJob bestScoredJob = null; for (Job unassignedJob : unassignedJobList) { - ScoredJob scoredJob = getScoredJob(routes,unassignedJob,insertionCostsCalculator,scoringFunction); - if(scoredJob instanceof BadJob){ + ScoredJob scoredJob = getScoredJob(routes, unassignedJob, insertionCostsCalculator, scoringFunction); + if (scoredJob instanceof ScoredJob.BadJob) { badJobs.add(unassignedJob); continue; } - if(bestScoredJob == null) bestScoredJob = scoredJob; - else{ - if(scoredJob.getScore() > bestScoredJob.getScore()){ + if (bestScoredJob == null) bestScoredJob = scoredJob; + else { + if (scoredJob.getScore() > bestScoredJob.getScore()) { bestScoredJob = scoredJob; + } else if (scoredJob.getScore() == bestScoredJob.getScore()) { + if (scoredJob.getJob().getId().compareTo(bestScoredJob.getJob().getId()) <= 0) { + bestScoredJob = scoredJob; + } } } } @@ -298,31 +191,29 @@ public class RegretInsertion extends AbstractInsertionStrategy { secondBest = iData; } } - if(best == null){ - return new RegretInsertion.BadJob(unassignedJob); + if (best == null) { + return new ScoredJob.BadJob(unassignedJob); } double score = score(unassignedJob, best, secondBest, scoringFunction); ScoredJob scoredJob; - if(bestRoute == emptyRoute){ + if (bestRoute == emptyRoute) { scoredJob = new ScoredJob(unassignedJob, score, best, bestRoute, true); - } - else scoredJob = new ScoredJob(unassignedJob, score, best, bestRoute, false); + } else scoredJob = new ScoredJob(unassignedJob, score, best, bestRoute, false); return scoredJob; } static double score(Job unassignedJob, InsertionData best, InsertionData secondBest, ScoringFunction scoringFunction) { - if(best == null){ - throw new IllegalStateException("cannot insert job " + unassignedJob.getId()); + if (best == null) { + throw new IllegalStateException("cannot insert job " + unassignedJob.getId()); } double score; - if(secondBest == null){ //either there is only one vehicle or there are more vehicles, but they cannot load unassignedJob + if (secondBest == null) { //either there is only one vehicle or there are more vehicles, but they cannot load unassignedJob //if only one vehicle, I want the job to be inserted with min iCosts //if there are more vehicles, I want this job to be prioritized since there are no alternatives score = Integer.MAX_VALUE - best.getInsertionCost() + scoringFunction.score(best, unassignedJob); - } - else{ - score = (secondBest.getInsertionCost()-best.getInsertionCost()) + scoringFunction.score(best, unassignedJob); + } else { + score = (secondBest.getInsertionCost() - best.getInsertionCost()) + scoringFunction.score(best, unassignedJob); } return score; } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/RegretInsertionConcurrent.java b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/RegretInsertionConcurrent.java index d685989e..3bc622a9 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/RegretInsertionConcurrent.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/RegretInsertionConcurrent.java @@ -17,10 +17,8 @@ package jsprit.core.algorithm.recreate; -import jsprit.core.algorithm.recreate.RegretInsertion.DefaultScorer; -import jsprit.core.algorithm.recreate.RegretInsertion.ScoredJob; -import jsprit.core.algorithm.recreate.RegretInsertion.ScoringFunction; import jsprit.core.problem.VehicleRoutingProblem; +import jsprit.core.problem.job.Break; import jsprit.core.problem.job.Job; import jsprit.core.problem.solution.route.VehicleRoute; import org.apache.logging.log4j.LogManager; @@ -28,80 +26,101 @@ import org.apache.logging.log4j.Logger; import java.util.ArrayList; import java.util.Collection; +import java.util.Iterator; import java.util.List; import java.util.concurrent.*; /** -* Insertion based on regret approach. -* -*

Basically calculates the insertion cost of the firstBest and the secondBest alternative. The score is then calculated as difference -* between secondBest and firstBest, plus additional scoring variables that can defined in this.ScoringFunction. -* The idea is that if the cost of the secondBest alternative is way higher than the first best, it seems to be important to insert this -* customer immediatedly. If difference is not that high, it might not impact solution if this customer is inserted later. -* -* @author stefan schroeder -* -*/ + * Insertion based on regret approach. + *

+ *

Basically calculates the insertion cost of the firstBest and the secondBest alternative. The score is then calculated as difference + * between secondBest and firstBest, plus additional scoring variables that can defined in this.ScoringFunction. + * The idea is that if the cost of the secondBest alternative is way higher than the first best, it seems to be important to insert this + * customer immediatedly. If difference is not that high, it might not impact solution if this customer is inserted later. + * + * @author stefan schroeder + */ public class RegretInsertionConcurrent extends AbstractInsertionStrategy { - private static Logger logger = LogManager.getLogger(RegretInsertionConcurrent.class); + private static Logger logger = LogManager.getLogger(RegretInsertionConcurrentFast.class); - private ScoringFunction scoringFunction; + private ScoringFunction scoringFunction; private final JobInsertionCostsCalculator insertionCostsCalculator; private final ExecutorCompletionService completionService; /** - * Sets the scoring function. - * - *

By default, the this.TimeWindowScorer is used. - * - * @param scoringFunction to score - */ - public void setScoringFunction(ScoringFunction scoringFunction) { - this.scoringFunction = scoringFunction; - } + * Sets the scoring function. + *

+ *

By default, the this.TimeWindowScorer is used. + * + * @param scoringFunction to score + */ + public void setScoringFunction(ScoringFunction scoringFunction) { + this.scoringFunction = scoringFunction; + } - public RegretInsertionConcurrent(JobInsertionCostsCalculator jobInsertionCalculator, VehicleRoutingProblem vehicleRoutingProblem, ExecutorService executorService) { - super(vehicleRoutingProblem); + public RegretInsertionConcurrent(JobInsertionCostsCalculator jobInsertionCalculator, VehicleRoutingProblem vehicleRoutingProblem, ExecutorService executorService) { + super(vehicleRoutingProblem); this.scoringFunction = new DefaultScorer(vehicleRoutingProblem); - this.insertionCostsCalculator = jobInsertionCalculator; + this.insertionCostsCalculator = jobInsertionCalculator; this.vrp = vehicleRoutingProblem; completionService = new ExecutorCompletionService(executorService); - logger.debug("initialise " + this); - } + logger.debug("initialise " + this); + } - @Override - public String toString() { - return "[name=regretInsertion][additionalScorer="+scoringFunction+"]"; - } + @Override + public String toString() { + return "[name=regretInsertion][additionalScorer=" + scoringFunction + "]"; + } - /** - * Runs insertion. - * - *

Before inserting a job, all unassigned jobs are scored according to its best- and secondBest-insertion plus additional scoring variables. - * - */ - @Override - public Collection insertUnassignedJobs(Collection routes, Collection unassignedJobs) { + /** + * Runs insertion. + *

+ *

Before inserting a job, all unassigned jobs are scored according to its best- and secondBest-insertion plus additional scoring variables. + * + * @throws java.lang.RuntimeException if smth went wrong with thread execution + */ + @Override + public Collection insertUnassignedJobs(Collection routes, Collection unassignedJobs) { List badJobs = new ArrayList(unassignedJobs.size()); - List jobs = new ArrayList(unassignedJobs); + Iterator jobIterator = unassignedJobs.iterator(); + while (jobIterator.hasNext()){ + Job job = jobIterator.next(); + if(job instanceof Break){ + VehicleRoute route = findRoute(routes,job); + if(route == null){ + badJobs.add(job); + } + else { + InsertionData iData = insertionCostsCalculator.getInsertionData(route, job, NO_NEW_VEHICLE_YET, NO_NEW_DEPARTURE_TIME_YET, NO_NEW_DRIVER_YET, Double.MAX_VALUE); + if (iData instanceof InsertionData.NoInsertionFound) { + badJobs.add(job); + } else { + insertJob(job, iData, route); + } + } + jobIterator.remove(); + } + } + + List jobs = new ArrayList(unassignedJobs); while (!jobs.isEmpty()) { List unassignedJobList = new ArrayList(jobs); List badJobList = new ArrayList(); ScoredJob bestScoredJob = nextJob(routes, unassignedJobList, badJobList); - if(bestScoredJob != null){ - if(bestScoredJob.isNewRoute()){ + if (bestScoredJob != null) { + if (bestScoredJob.isNewRoute()) { routes.add(bestScoredJob.getRoute()); } - insertJob(bestScoredJob.getJob(),bestScoredJob.getInsertionData(),bestScoredJob.getRoute()); + insertJob(bestScoredJob.getJob(), bestScoredJob.getInsertionData(), bestScoredJob.getRoute()); jobs.remove(bestScoredJob.getJob()); } - for(Job j : badJobList) { + for (Job j : badJobList) { jobs.remove(j); badJobs.add(j); } @@ -123,38 +142,39 @@ public class RegretInsertionConcurrent extends AbstractInsertionStrategy { }); } - try{ - for(int i=0; i < unassignedJobList.size(); i++){ + try { + for (int i = 0; i < unassignedJobList.size(); i++) { Future fsj = completionService.take(); ScoredJob sJob = fsj.get(); - if(sJob instanceof RegretInsertion.BadJob){ + if (sJob instanceof ScoredJob.BadJob) { badJobList.add(sJob.getJob()); continue; } - if(bestScoredJob == null){ + if (bestScoredJob == null) { bestScoredJob = sJob; - } - else if(sJob.getScore() > bestScoredJob.getScore()){ + } else if (sJob.getScore() > bestScoredJob.getScore()) { bestScoredJob = sJob; + } else if (sJob.getScore() == bestScoredJob.getScore()) { + if (sJob.getJob().getId().compareTo(bestScoredJob.getJob().getId()) <= 0) { + bestScoredJob = sJob; + } } } - } - catch(InterruptedException e){ + } catch (InterruptedException e) { Thread.currentThread().interrupt(); - } - catch (ExecutionException e) { - e.printStackTrace(); - logger.error(e.getCause().toString()); - System.exit(1); + } catch (ExecutionException e) { + throw new RuntimeException(e); } return bestScoredJob; } - - - - + private VehicleRoute findRoute(Collection routes, Job job) { + for(VehicleRoute r : routes){ + if(r.getVehicle().getBreak() == job) return r; + } + return null; + } } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/RegretInsertionConcurrentFast.java b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/RegretInsertionConcurrentFast.java new file mode 100644 index 00000000..38f3d213 --- /dev/null +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/RegretInsertionConcurrentFast.java @@ -0,0 +1,196 @@ +/******************************************************************************* + * Copyright (C) 2014 Stefan Schroeder + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3.0 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + ******************************************************************************/ + +package jsprit.core.algorithm.recreate; + +import jsprit.core.problem.VehicleRoutingProblem; +import jsprit.core.problem.job.Break; +import jsprit.core.problem.job.Job; +import jsprit.core.problem.solution.route.VehicleRoute; +import jsprit.core.problem.vehicle.VehicleFleetManager; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.util.*; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Future; + +/** + * Insertion based on regret approach. + *

+ *

Basically calculates the insertion cost of the firstBest and the secondBest alternative. The score is then calculated as difference + * between secondBest and firstBest, plus additional scoring variables that can defined in this.ScoringFunction. + * The idea is that if the cost of the secondBest alternative is way higher than the first best, it seems to be important to insert this + * customer immediatedly. If difference is not that high, it might not impact solution if this customer is inserted later. + * + * @author stefan schroeder + */ +public class RegretInsertionConcurrentFast extends AbstractInsertionStrategy { + + + private static Logger logger = LogManager.getLogger(RegretInsertionConcurrentFast.class); + + private ScoringFunction scoringFunction; + + private final JobInsertionCostsCalculator insertionCostsCalculator; + + private final ExecutorService executor; + + private VehicleFleetManager fleetManager; + + private Set initialVehicleIds; + + private boolean switchAllowed = true; + + + /** + * Sets the scoring function. + *

+ *

By default, the this.TimeWindowScorer is used. + * + * @param scoringFunction to score + */ + public void setScoringFunction(ScoringFunction scoringFunction) { + this.scoringFunction = scoringFunction; + } + + public RegretInsertionConcurrentFast(JobInsertionCostsCalculator jobInsertionCalculator, VehicleRoutingProblem vehicleRoutingProblem, ExecutorService executorService, VehicleFleetManager fleetManager) { + super(vehicleRoutingProblem); + this.scoringFunction = new DefaultScorer(vehicleRoutingProblem); + this.insertionCostsCalculator = jobInsertionCalculator; + this.vrp = vehicleRoutingProblem; + this.executor = executorService; + this.fleetManager = fleetManager; + this.initialVehicleIds = getInitialVehicleIds(vehicleRoutingProblem); + logger.debug("initialise " + this); + } + + @Override + public String toString() { + return "[name=regretInsertion][additionalScorer=" + scoringFunction + "]"; + } + + public void setSwitchAllowed(boolean switchAllowed) { + this.switchAllowed = switchAllowed; + } + + private Set getInitialVehicleIds(VehicleRoutingProblem vehicleRoutingProblem) { + Set ids = new HashSet(); + for(VehicleRoute r : vehicleRoutingProblem.getInitialVehicleRoutes()){ + ids.add(r.getVehicle().getId()); + } + return ids; + } + + + /** + * Runs insertion. + *

+ *

Before inserting a job, all unassigned jobs are scored according to its best- and secondBest-insertion plus additional scoring variables. + * + * @throws java.lang.RuntimeException if smth went wrong with thread execution + */ + @Override + public Collection insertUnassignedJobs(Collection routes, Collection unassignedJobs) { + List badJobs = new ArrayList(unassignedJobs.size()); + + Iterator jobIterator = unassignedJobs.iterator(); + while (jobIterator.hasNext()){ + Job job = jobIterator.next(); + if(job instanceof Break){ + VehicleRoute route = InsertionDataUpdater.findRoute(routes, job); + if(route == null){ + badJobs.add(job); + } + else { + InsertionData iData = insertionCostsCalculator.getInsertionData(route, job, NO_NEW_VEHICLE_YET, NO_NEW_DEPARTURE_TIME_YET, NO_NEW_DRIVER_YET, Double.MAX_VALUE); + if (iData instanceof InsertionData.NoInsertionFound) { + badJobs.add(job); + } else { + insertJob(job, iData, route); + } + } + jobIterator.remove(); + } + } + + List jobs = new ArrayList(unassignedJobs); + TreeSet[] priorityQueues = new TreeSet[vrp.getJobs().values().size() + 2]; + VehicleRoute lastModified = null; + boolean firstRun = true; + int updateRound = 0; + Map updates = new HashMap(); + while (!jobs.isEmpty()) { + List unassignedJobList = new ArrayList(jobs); + List badJobList = new ArrayList(); + if(!firstRun && lastModified == null) throw new IllegalStateException("ho. this must not be."); + if(firstRun){ + firstRun = false; + updateInsertionData(priorityQueues, routes, unassignedJobList, updateRound); + for(VehicleRoute r : routes) updates.put(r,updateRound); + } + else{ + updateInsertionData(priorityQueues, Arrays.asList(lastModified), unassignedJobList, updateRound); + updates.put(lastModified,updateRound); + } + updateRound++; + ScoredJob bestScoredJob = InsertionDataUpdater.getBest(switchAllowed,initialVehicleIds,fleetManager, insertionCostsCalculator, scoringFunction, priorityQueues, updates, unassignedJobList, badJobList); + if (bestScoredJob != null) { + if (bestScoredJob.isNewRoute()) { + routes.add(bestScoredJob.getRoute()); + } + insertJob(bestScoredJob.getJob(), bestScoredJob.getInsertionData(), bestScoredJob.getRoute()); + jobs.remove(bestScoredJob.getJob()); + lastModified = bestScoredJob.getRoute(); + } + else lastModified = null; + for (Job bad : badJobList) { + jobs.remove(bad); + badJobs.add(bad); + } + } + return badJobs; + } + + private void updateInsertionData(final TreeSet[] priorityQueues, final Collection routes, List unassignedJobList, final int updateRound) { + List> tasks = new ArrayList>(); + for (final Job unassignedJob : unassignedJobList) { + if(priorityQueues[unassignedJob.getIndex()] == null){ + priorityQueues[unassignedJob.getIndex()] = new TreeSet(InsertionDataUpdater.getComparator()); + } + final TreeSet priorityQueue = priorityQueues[unassignedJob.getIndex()]; + tasks.add(new Callable() { + @Override + public Boolean call() throws Exception { + return InsertionDataUpdater.update(switchAllowed,initialVehicleIds,fleetManager, insertionCostsCalculator, priorityQueue, updateRound, unassignedJob, routes); + } + }); + } + try { + List> futures = executor.invokeAll(tasks); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + throw new RuntimeException(e); + } + } + + + + + +} diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/RegretInsertionFast.java b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/RegretInsertionFast.java new file mode 100644 index 00000000..da0ea0dd --- /dev/null +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/RegretInsertionFast.java @@ -0,0 +1,173 @@ +/******************************************************************************* + * Copyright (C) 2014 Stefan Schroeder + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3.0 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + ******************************************************************************/ + +package jsprit.core.algorithm.recreate; + +import jsprit.core.problem.VehicleRoutingProblem; +import jsprit.core.problem.job.Break; +import jsprit.core.problem.job.Job; +import jsprit.core.problem.solution.route.VehicleRoute; +import jsprit.core.problem.vehicle.VehicleFleetManager; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.util.*; + +/** + * Insertion based on regret approach. + *

+ *

Basically calculates the insertion cost of the firstBest and the secondBest alternative. The score is then calculated as difference + * between secondBest and firstBest, plus additional scoring variables that can defined in this.ScoringFunction. + * The idea is that if the cost of the secondBest alternative is way higher than the first best, it seems to be important to insert this + * customer immediatedly. If difference is not that high, it might not impact solution if this customer is inserted later. + * + * @author stefan schroeder + */ +public class RegretInsertionFast extends AbstractInsertionStrategy { + + private static Logger logger = LogManager.getLogger(RegretInsertionFast.class); + + private ScoringFunction scoringFunction; + + private JobInsertionCostsCalculator insertionCostsCalculator; + + private VehicleFleetManager fleetManager; + + private Set initialVehicleIds; + + private boolean switchAllowed = true; + + + + public RegretInsertionFast(JobInsertionCostsCalculator jobInsertionCalculator, VehicleRoutingProblem vehicleRoutingProblem, VehicleFleetManager fleetManager) { + super(vehicleRoutingProblem); + this.scoringFunction = new DefaultScorer(vehicleRoutingProblem); + this.insertionCostsCalculator = jobInsertionCalculator; + this.fleetManager = fleetManager; + this.vrp = vehicleRoutingProblem; + this.initialVehicleIds = getInitialVehicleIds(vehicleRoutingProblem); + logger.debug("initialise {}", this); + } + + /** + * Sets the scoring function. + *

+ *

By default, the this.TimeWindowScorer is used. + * + * @param scoringFunction to score + */ + public void setScoringFunction(ScoringFunction scoringFunction) { + this.scoringFunction = scoringFunction; + } + + public void setSwitchAllowed(boolean switchAllowed) { + this.switchAllowed = switchAllowed; + } + + private Set getInitialVehicleIds(VehicleRoutingProblem vehicleRoutingProblem) { + Set ids = new HashSet(); + for(VehicleRoute r : vehicleRoutingProblem.getInitialVehicleRoutes()){ + ids.add(r.getVehicle().getId()); + } + return ids; + } + + @Override + public String toString() { + return "[name=regretInsertion][additionalScorer=" + scoringFunction + "]"; + } + + + /** + * Runs insertion. + *

+ *

Before inserting a job, all unassigned jobs are scored according to its best- and secondBest-insertion plus additional scoring variables. + */ + @Override + public Collection insertUnassignedJobs(Collection routes, Collection unassignedJobs) { + List badJobs = new ArrayList(unassignedJobs.size()); + + Iterator jobIterator = unassignedJobs.iterator(); + while (jobIterator.hasNext()){ + Job job = jobIterator.next(); + if(job instanceof Break){ + VehicleRoute route = InsertionDataUpdater.findRoute(routes, job); + if(route == null){ + badJobs.add(job); + } + else { + InsertionData iData = insertionCostsCalculator.getInsertionData(route, job, NO_NEW_VEHICLE_YET, NO_NEW_DEPARTURE_TIME_YET, NO_NEW_DRIVER_YET, Double.MAX_VALUE); + if (iData instanceof InsertionData.NoInsertionFound) { + badJobs.add(job); + } else { + insertJob(job, iData, route); + } + } + jobIterator.remove(); + } + } + + List jobs = new ArrayList(unassignedJobs); + TreeSet[] priorityQueues = new TreeSet[vrp.getJobs().values().size() + 2]; + VehicleRoute lastModified = null; + boolean firstRun = true; + int updateRound = 0; + Map updates = new HashMap(); + while (!jobs.isEmpty()) { + List unassignedJobList = new ArrayList(jobs); + List badJobList = new ArrayList(); + if(!firstRun && lastModified == null) throw new IllegalStateException("fooo"); + if(firstRun){ + firstRun = false; + updateInsertionData(priorityQueues, routes, unassignedJobList, updateRound); + for(VehicleRoute r : routes) updates.put(r,updateRound); + } + else{ + updateInsertionData(priorityQueues, Arrays.asList(lastModified), unassignedJobList, updateRound); + updates.put(lastModified,updateRound); + } + updateRound++; + ScoredJob bestScoredJob = InsertionDataUpdater.getBest(switchAllowed,initialVehicleIds,fleetManager,insertionCostsCalculator,scoringFunction,priorityQueues,updates,unassignedJobList,badJobList); + if (bestScoredJob != null) { + if (bestScoredJob.isNewRoute()) { + routes.add(bestScoredJob.getRoute()); + } + insertJob(bestScoredJob.getJob(), bestScoredJob.getInsertionData(), bestScoredJob.getRoute()); + jobs.remove(bestScoredJob.getJob()); + lastModified = bestScoredJob.getRoute(); + } + else lastModified = null; + for (Job bad : badJobList) { + jobs.remove(bad); + badJobs.add(bad); + } + } + return badJobs; + } + + private void updateInsertionData(TreeSet[] priorityQueues, Collection routes, List unassignedJobList, int updateRound) { + for (Job unassignedJob : unassignedJobList) { + if(priorityQueues[unassignedJob.getIndex()] == null){ + priorityQueues[unassignedJob.getIndex()] = new TreeSet(InsertionDataUpdater.getComparator()); + } + InsertionDataUpdater.update(switchAllowed, initialVehicleIds,fleetManager,insertionCostsCalculator, priorityQueues[unassignedJob.getIndex()], updateRound, unassignedJob, routes); + } + } + + + +} diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/RouteLevelActivityInsertionCostsEstimator.java b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/RouteLevelActivityInsertionCostsEstimator.java index ee2e48d3..fc7b3429 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/RouteLevelActivityInsertionCostsEstimator.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/RouteLevelActivityInsertionCostsEstimator.java @@ -1,4 +1,3 @@ - /******************************************************************************* * Copyright (C) 2014 Stefan Schroeder * @@ -32,65 +31,68 @@ import java.util.ArrayList; import java.util.List; -class RouteLevelActivityInsertionCostsEstimator implements ActivityInsertionCostsCalculator{ +class RouteLevelActivityInsertionCostsEstimator implements ActivityInsertionCostsCalculator { - private VehicleRoutingActivityCosts activityCosts; - - private AuxilliaryCostCalculator auxilliaryPathCostCalculator; - - private RouteAndActivityStateGetter stateManager; - - private int nuOfActivities2LookForward = 0; - - public RouteLevelActivityInsertionCostsEstimator(VehicleRoutingTransportCosts routingCosts, VehicleRoutingActivityCosts actCosts, RouteAndActivityStateGetter stateManager) { - super(); - this.activityCosts = actCosts; - this.stateManager = stateManager; - auxilliaryPathCostCalculator = new AuxilliaryCostCalculator(routingCosts, activityCosts); - } + private VehicleRoutingActivityCosts activityCosts; - @Override - public double getCosts(JobInsertionContext iFacts, TourActivity prevAct, TourActivity nextAct, TourActivity newAct, double depTimeAtPrevAct) { - List path = new ArrayList(); - path.add(prevAct); path.add(newAct); path.add(nextAct); - int actIndex; - if(prevAct instanceof Start) actIndex = 0; - else actIndex = iFacts.getRoute().getTourActivities().getActivities().indexOf(nextAct); - if(nuOfActivities2LookForward > 0 && !(nextAct instanceof End)){ path.addAll(getForwardLookingPath(iFacts.getRoute(),actIndex)); } + private AuxilliaryCostCalculator auxilliaryPathCostCalculator; + + private RouteAndActivityStateGetter stateManager; + + private int nuOfActivities2LookForward = 0; + + public RouteLevelActivityInsertionCostsEstimator(VehicleRoutingTransportCosts routingCosts, VehicleRoutingActivityCosts actCosts, RouteAndActivityStateGetter stateManager) { + super(); + this.activityCosts = actCosts; + this.stateManager = stateManager; + auxilliaryPathCostCalculator = new AuxilliaryCostCalculator(routingCosts, activityCosts); + } + + @Override + public double getCosts(JobInsertionContext iFacts, TourActivity prevAct, TourActivity nextAct, TourActivity newAct, double depTimeAtPrevAct) { + List path = new ArrayList(); + path.add(prevAct); + path.add(newAct); + path.add(nextAct); + int actIndex; + if (prevAct instanceof Start) actIndex = 0; + else actIndex = iFacts.getRoute().getTourActivities().getActivities().indexOf(nextAct); + if (nuOfActivities2LookForward > 0 && !(nextAct instanceof End)) { + path.addAll(getForwardLookingPath(iFacts.getRoute(), actIndex)); + } /* - * calculates the path costs with new vehicle, c(forwardPath,newVehicle). + * calculates the path costs with new vehicle, c(forwardPath,newVehicle). */ - double forwardPathCost_newVehicle = auxilliaryPathCostCalculator.costOfPath(path, depTimeAtPrevAct, iFacts.getNewDriver(), iFacts.getNewVehicle()); - return forwardPathCost_newVehicle - (actCostsOld(iFacts.getRoute(), path.get(path.size()-1)) - actCostsOld(iFacts.getRoute(), prevAct)); - } - - private double actCostsOld(VehicleRoute vehicleRoute, TourActivity act) { + double forwardPathCost_newVehicle = auxilliaryPathCostCalculator.costOfPath(path, depTimeAtPrevAct, iFacts.getNewDriver(), iFacts.getNewVehicle()); + return forwardPathCost_newVehicle - (actCostsOld(iFacts.getRoute(), path.get(path.size() - 1)) - actCostsOld(iFacts.getRoute(), prevAct)); + } + + private double actCostsOld(VehicleRoute vehicleRoute, TourActivity act) { Double cost_at_act; - if(act instanceof End){ + if (act instanceof End) { cost_at_act = stateManager.getRouteState(vehicleRoute, InternalStates.COSTS, Double.class); - } - else{ + } else { cost_at_act = stateManager.getActivityState(act, InternalStates.COSTS, Double.class); } - if(cost_at_act == null) cost_at_act = 0.; + if (cost_at_act == null) cost_at_act = 0.; return cost_at_act; - } - - private List getForwardLookingPath(VehicleRoute route, int actIndex) { - List forwardLookingPath = new ArrayList(); - int nuOfActsInPath = 0; - int index = actIndex + 1; - while(index < route.getTourActivities().getActivities().size() && nuOfActsInPath < nuOfActivities2LookForward){ - forwardLookingPath.add(route.getTourActivities().getActivities().get(index)); - index++; - nuOfActsInPath++; - } - if(nuOfActsInPath < nuOfActivities2LookForward){ - forwardLookingPath.add(route.getEnd()); - } - return forwardLookingPath; - } + } + + private List getForwardLookingPath(VehicleRoute route, int actIndex) { + List forwardLookingPath = new ArrayList(); + int nuOfActsInPath = 0; + int index = actIndex + 1; + while (index < route.getTourActivities().getActivities().size() && nuOfActsInPath < nuOfActivities2LookForward) { + forwardLookingPath.add(route.getTourActivities().getActivities().get(index)); + index++; + nuOfActsInPath++; + } + if (nuOfActsInPath < nuOfActivities2LookForward) { + forwardLookingPath.add(route.getEnd()); + } + return forwardLookingPath; + } public void setForwardLooking(int nActivities) { this.nuOfActivities2LookForward = nActivities; diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/ScoredJob.java b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/ScoredJob.java new file mode 100644 index 00000000..32d952e2 --- /dev/null +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/ScoredJob.java @@ -0,0 +1,57 @@ +package jsprit.core.algorithm.recreate; + +import jsprit.core.problem.job.Job; +import jsprit.core.problem.solution.route.VehicleRoute; + +/** + * Created by schroeder on 15/10/15. + */ +class ScoredJob { + + static class BadJob extends ScoredJob { + + BadJob(Job job) { + super(job, 0., null, null, false); + } + } + + private Job job; + + private double score; + + private InsertionData insertionData; + + private VehicleRoute route; + + private boolean newRoute; + + + ScoredJob(Job job, double score, InsertionData insertionData, VehicleRoute route, boolean isNewRoute) { + this.job = job; + this.score = score; + this.insertionData = insertionData; + this.route = route; + this.newRoute = isNewRoute; + } + + public boolean isNewRoute() { + return newRoute; + } + + public Job getJob() { + return job; + } + + public double getScore() { + return score; + } + + public InsertionData getInsertionData() { + return insertionData; + } + + public VehicleRoute getRoute() { + return route; + } + +} diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/ScoringFunction.java b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/ScoringFunction.java new file mode 100644 index 00000000..434de325 --- /dev/null +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/ScoringFunction.java @@ -0,0 +1,12 @@ +package jsprit.core.algorithm.recreate; + +import jsprit.core.problem.job.Job; + +/** + * Created by schroeder on 15/10/15. + */ +public interface ScoringFunction { + + public double score(InsertionData best, Job job); + +} diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/ServiceInsertionCalculator.java b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/ServiceInsertionCalculator.java index ce29371e..7190136c 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/ServiceInsertionCalculator.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/ServiceInsertionCalculator.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.recreate; @@ -41,76 +41,74 @@ import java.util.Iterator; * Calculator that calculates the best insertion position for a {@link Service}. * * @author schroeder - * */ -final class ServiceInsertionCalculator implements JobInsertionCostsCalculator{ +final class ServiceInsertionCalculator implements JobInsertionCostsCalculator { - private static final Logger logger = LogManager.getLogger(ServiceInsertionCalculator.class); + private static final Logger logger = LogManager.getLogger(ServiceInsertionCalculator.class); - private HardRouteConstraint hardRouteLevelConstraint; + private HardRouteConstraint hardRouteLevelConstraint; - private HardActivityConstraint hardActivityLevelConstraint; + private HardActivityConstraint hardActivityLevelConstraint; - private SoftRouteConstraint softRouteConstraint; + private SoftRouteConstraint softRouteConstraint; - private SoftActivityConstraint softActivityConstraint; + private SoftActivityConstraint softActivityConstraint; - private VehicleRoutingTransportCosts transportCosts; + private VehicleRoutingTransportCosts transportCosts; - private ActivityInsertionCostsCalculator additionalTransportCostsCalculator; + private ActivityInsertionCostsCalculator additionalTransportCostsCalculator; - private JobActivityFactory activityFactory; + private JobActivityFactory activityFactory; - private AdditionalAccessEgressCalculator additionalAccessEgressCalculator; + private AdditionalAccessEgressCalculator additionalAccessEgressCalculator; - public ServiceInsertionCalculator(VehicleRoutingTransportCosts routingCosts, ActivityInsertionCostsCalculator additionalTransportCostsCalculator, ConstraintManager constraintManager) { - super(); - this.transportCosts = routingCosts; - hardRouteLevelConstraint = constraintManager; - hardActivityLevelConstraint = constraintManager; - softActivityConstraint = constraintManager; - softRouteConstraint = constraintManager; - this.additionalTransportCostsCalculator = additionalTransportCostsCalculator; - additionalAccessEgressCalculator = new AdditionalAccessEgressCalculator(routingCosts); - logger.debug("initialise " + this); - } + public ServiceInsertionCalculator(VehicleRoutingTransportCosts routingCosts, ActivityInsertionCostsCalculator additionalTransportCostsCalculator, ConstraintManager constraintManager) { + super(); + this.transportCosts = routingCosts; + hardRouteLevelConstraint = constraintManager; + hardActivityLevelConstraint = constraintManager; + softActivityConstraint = constraintManager; + softRouteConstraint = constraintManager; + this.additionalTransportCostsCalculator = additionalTransportCostsCalculator; + additionalAccessEgressCalculator = new AdditionalAccessEgressCalculator(routingCosts); + logger.debug("initialise {}", this); + } - public void setJobActivityFactory(JobActivityFactory jobActivityFactory){ + public void setJobActivityFactory(JobActivityFactory jobActivityFactory) { this.activityFactory = jobActivityFactory; } - @Override - public String toString() { - return "[name=calculatesServiceInsertion]"; - } + @Override + public String toString() { + return "[name=calculatesServiceInsertion]"; + } - /** - * Calculates the marginal cost of inserting job i locally. This is based on the - * assumption that cost changes can entirely covered by only looking at the predecessor i-1 and its successor i+1. - * - */ - @Override - public InsertionData getInsertionData(final VehicleRoute currentRoute, final Job jobToInsert, final Vehicle newVehicle, double newVehicleDepartureTime, final Driver newDriver, final double bestKnownCosts) { - JobInsertionContext insertionContext = new JobInsertionContext(currentRoute, jobToInsert, newVehicle, newDriver, newVehicleDepartureTime); - Service service = (Service)jobToInsert; + /** + * Calculates the marginal cost of inserting job i locally. This is based on the + * assumption that cost changes can entirely covered by only looking at the predecessor i-1 and its successor i+1. + */ + @Override + public InsertionData getInsertionData(final VehicleRoute currentRoute, final Job jobToInsert, final Vehicle newVehicle, double newVehicleDepartureTime, final Driver newDriver, final double bestKnownCosts) { + JobInsertionContext insertionContext = new JobInsertionContext(currentRoute, jobToInsert, newVehicle, newDriver, newVehicleDepartureTime); + Service service = (Service) jobToInsert; int insertionIndex = InsertionData.NO_INDEX; - TourActivity deliveryAct2Insert = activityFactory.createActivities(service).get(0); + TourActivity deliveryAct2Insert = activityFactory.createActivities(service).get(0); insertionContext.getAssociatedActivities().add(deliveryAct2Insert); /* check hard constraints at route level */ - if(!hardRouteLevelConstraint.fulfilled(insertionContext)){ - return InsertionData.createEmptyInsertionData(); - } + if (!hardRouteLevelConstraint.fulfilled(insertionContext)) { + return InsertionData.createEmptyInsertionData(); + } /* check soft constraints at route level */ double additionalICostsAtRouteLevel = softRouteConstraint.getCosts(insertionContext); - double bestCost = bestKnownCosts; + double bestCost = bestKnownCosts; additionalICostsAtRouteLevel += additionalAccessEgressCalculator.getCosts(insertionContext); TimeWindow bestTimeWindow = null; @@ -118,70 +116,70 @@ final class ServiceInsertionCalculator implements JobInsertionCostsCalculator{ generate new start and end for new vehicle */ Start start = new Start(newVehicle.getStartLocation(), newVehicle.getEarliestDeparture(), Double.MAX_VALUE); - start.setEndTime(newVehicleDepartureTime); - End end = new End(newVehicle.getEndLocation(), 0.0, newVehicle.getLatestArrival()); + start.setEndTime(newVehicleDepartureTime); + End end = new End(newVehicle.getEndLocation(), 0.0, newVehicle.getLatestArrival()); - TourActivity prevAct = start; - double prevActStartTime = newVehicleDepartureTime; - int actIndex = 0; - Iterator activityIterator = currentRoute.getActivities().iterator(); - boolean tourEnd = false; - while(!tourEnd){ - TourActivity nextAct; - if(activityIterator.hasNext()) nextAct = activityIterator.next(); - else{ - nextAct = end; - tourEnd = true; - } - double actArrTime = prevActStartTime + transportCosts.getTransportTime(prevAct.getLocation(),deliveryAct2Insert.getLocation(),prevActStartTime,newDriver,newVehicle); - Collection timeWindows = service.getTimeWindows(actArrTime); - TimeWindow timeWindow = getNextTimeWindow(actArrTime,timeWindows); - if(timeWindow == null) break; - boolean not_fulfilled_break = true; + TourActivity prevAct = start; + double prevActStartTime = newVehicleDepartureTime; + int actIndex = 0; + Iterator activityIterator = currentRoute.getActivities().iterator(); + boolean tourEnd = false; + while(!tourEnd){ + TourActivity nextAct; + if(activityIterator.hasNext()) nextAct = activityIterator.next(); + else{ + nextAct = end; + tourEnd = true; + } + double actArrTime = prevActStartTime + transportCosts.getTransportTime(prevAct.getLocation(),deliveryAct2Insert.getLocation(),prevActStartTime,newDriver,newVehicle); + Collection timeWindows = service.getTimeWindows(actArrTime); + TimeWindow timeWindow = getNextTimeWindow(actArrTime,timeWindows); + if(timeWindow == null) break; + boolean not_fulfilled_break = true; // for(TimeWindow timeWindow : timeWindows) { - deliveryAct2Insert.setTheoreticalEarliestOperationStartTime(timeWindow.getStart()); - deliveryAct2Insert.setTheoreticalLatestOperationStartTime(timeWindow.getEnd()); - ConstraintsStatus status = hardActivityLevelConstraint.fulfilled(insertionContext, prevAct, deliveryAct2Insert, nextAct, prevActStartTime); - if (status.equals(ConstraintsStatus.FULFILLED)) { - //from job2insert induced costs at activity level - double additionalICostsAtActLevel = softActivityConstraint.getCosts(insertionContext, prevAct, deliveryAct2Insert, nextAct, prevActStartTime); - double additionalTransportationCosts = additionalTransportCostsCalculator.getCosts(insertionContext, prevAct, nextAct, deliveryAct2Insert, prevActStartTime); - if (additionalICostsAtRouteLevel + additionalICostsAtActLevel + additionalTransportationCosts < bestCost) { - bestCost = additionalICostsAtRouteLevel + additionalICostsAtActLevel + additionalTransportationCosts; - insertionIndex = actIndex; - bestTimeWindow = timeWindow; - } - not_fulfilled_break = false; - } else if (status.equals(ConstraintsStatus.NOT_FULFILLED)) { - not_fulfilled_break = false; - } + deliveryAct2Insert.setTheoreticalEarliestOperationStartTime(timeWindow.getStart()); + deliveryAct2Insert.setTheoreticalLatestOperationStartTime(timeWindow.getEnd()); + ConstraintsStatus status = hardActivityLevelConstraint.fulfilled(insertionContext, prevAct, deliveryAct2Insert, nextAct, prevActStartTime); + if (status.equals(ConstraintsStatus.FULFILLED)) { + //from job2insert induced costs at activity level + double additionalICostsAtActLevel = softActivityConstraint.getCosts(insertionContext, prevAct, deliveryAct2Insert, nextAct, prevActStartTime); + double additionalTransportationCosts = additionalTransportCostsCalculator.getCosts(insertionContext, prevAct, nextAct, deliveryAct2Insert, prevActStartTime); + if (additionalICostsAtRouteLevel + additionalICostsAtActLevel + additionalTransportationCosts < bestCost) { + bestCost = additionalICostsAtRouteLevel + additionalICostsAtActLevel + additionalTransportationCosts; + insertionIndex = actIndex; + bestTimeWindow = timeWindow; + } + not_fulfilled_break = false; + } else if (status.equals(ConstraintsStatus.NOT_FULFILLED)) { + not_fulfilled_break = false; + } // } - if(not_fulfilled_break) break; - double nextActArrTime = prevActStartTime + transportCosts.getTransportTime(prevAct.getLocation(), nextAct.getLocation(), prevActStartTime, newDriver, newVehicle); - prevActStartTime = CalculationUtils.getActivityEndTime(nextActArrTime, nextAct); - prevAct = nextAct; - actIndex++; - } - if(insertionIndex == InsertionData.NO_INDEX) { - return InsertionData.createEmptyInsertionData(); - } - InsertionData insertionData = new InsertionData(bestCost, InsertionData.NO_INDEX, insertionIndex, newVehicle, newDriver); - deliveryAct2Insert.setTheoreticalEarliestOperationStartTime(bestTimeWindow.getStart()); - deliveryAct2Insert.setTheoreticalLatestOperationStartTime(bestTimeWindow.getEnd()); - insertionData.getEvents().add(new InsertActivity(currentRoute,newVehicle,deliveryAct2Insert,insertionIndex)); - insertionData.getEvents().add(new SwitchVehicle(currentRoute,newVehicle,newVehicleDepartureTime)); - insertionData.setVehicleDepartureTime(newVehicleDepartureTime); - return insertionData; - } + if(not_fulfilled_break) break; + double nextActArrTime = prevActStartTime + transportCosts.getTransportTime(prevAct.getLocation(), nextAct.getLocation(), prevActStartTime, newDriver, newVehicle); + prevActStartTime = CalculationUtils.getActivityEndTime(nextActArrTime, nextAct); + prevAct = nextAct; + actIndex++; + } + if(insertionIndex == InsertionData.NO_INDEX) { + return InsertionData.createEmptyInsertionData(); + } + InsertionData insertionData = new InsertionData(bestCost, InsertionData.NO_INDEX, insertionIndex, newVehicle, newDriver); + deliveryAct2Insert.setTheoreticalEarliestOperationStartTime(bestTimeWindow.getStart()); + deliveryAct2Insert.setTheoreticalLatestOperationStartTime(bestTimeWindow.getEnd()); + insertionData.getEvents().add(new InsertActivity(currentRoute, newVehicle, deliveryAct2Insert, insertionIndex)); + insertionData.getEvents().add(new SwitchVehicle(currentRoute,newVehicle,newVehicleDepartureTime)); + insertionData.setVehicleDepartureTime(newVehicleDepartureTime); + return insertionData; + } - private TimeWindow getNextTimeWindow(double actArrTime, Collection timeWindows) { - for(TimeWindow tw : timeWindows){ - if(actArrTime >= tw.getStart() && actArrTime <= tw.getEnd()) return tw; - else if(actArrTime < tw.getStart()){ - return tw; - } - } - return null; - } + private TimeWindow getNextTimeWindow(double actArrTime, Collection timeWindows) { + for(TimeWindow tw : timeWindows){ + if(actArrTime >= tw.getStart() && actArrTime <= tw.getEnd()) return tw; + else if(actArrTime < tw.getStart()){ + return tw; + } + } + return null; + } } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/ServiceInsertionOnRouteLevelCalculator.java b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/ServiceInsertionOnRouteLevelCalculator.java index 2f68f943..0f189d16 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/ServiceInsertionOnRouteLevelCalculator.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/ServiceInsertionOnRouteLevelCalculator.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.recreate; @@ -45,127 +45,125 @@ import java.util.List; import java.util.PriorityQueue; +final class ServiceInsertionOnRouteLevelCalculator implements JobInsertionCostsCalculator { + + private static final Logger logger = LogManager.getLogger(ServiceInsertionOnRouteLevelCalculator.class); + + private final VehicleRoutingTransportCosts transportCosts; + + private final VehicleRoutingActivityCosts activityCosts; + + private AuxilliaryCostCalculator auxilliaryPathCostCalculator; + + private JobActivityFactory activityFactory; + + private RouteAndActivityStateGetter stateManager; + + private HardRouteConstraint hardRouteLevelConstraint; + + private HardActivityConstraint hardActivityLevelConstraint; + + private ActivityInsertionCostsCalculator activityInsertionCostsCalculator; + + private int nuOfActsForwardLooking = 0; + // + private int memorySize = 2; + + private Start start; + + private End end; + + public void setJobActivityFactory(JobActivityFactory jobActivityFactory) { + this.activityFactory = jobActivityFactory; + } + + public void setMemorySize(int memorySize) { + this.memorySize = memorySize; + logger.debug("set [solutionMemory={}]", memorySize); + } + + public ServiceInsertionOnRouteLevelCalculator(VehicleRoutingTransportCosts vehicleRoutingCosts, VehicleRoutingActivityCosts costFunc, ActivityInsertionCostsCalculator activityInsertionCostsCalculator, HardRouteConstraint hardRouteLevelConstraint, HardActivityConstraint hardActivityLevelConstraint) { + super(); + this.transportCosts = vehicleRoutingCosts; + this.activityCosts = costFunc; + this.activityInsertionCostsCalculator = activityInsertionCostsCalculator; + this.hardRouteLevelConstraint = hardRouteLevelConstraint; + this.hardActivityLevelConstraint = hardActivityLevelConstraint; + auxilliaryPathCostCalculator = new AuxilliaryCostCalculator(transportCosts, activityCosts); + logger.debug("initialise {}", this); + } -final class ServiceInsertionOnRouteLevelCalculator implements JobInsertionCostsCalculator{ - - private static final Logger logger = LogManager.getLogger(ServiceInsertionOnRouteLevelCalculator.class); - - private final VehicleRoutingTransportCosts transportCosts; - - private final VehicleRoutingActivityCosts activityCosts; + public void setStates(RouteAndActivityStateGetter stateManager) { + this.stateManager = stateManager; + } - private AuxilliaryCostCalculator auxilliaryPathCostCalculator; - - private JobActivityFactory activityFactory; - - private RouteAndActivityStateGetter stateManager; - - private HardRouteConstraint hardRouteLevelConstraint; - - private HardActivityConstraint hardActivityLevelConstraint; - - private ActivityInsertionCostsCalculator activityInsertionCostsCalculator; - - private int nuOfActsForwardLooking = 0; -// - private int memorySize = 2; - - private Start start; - - private End end; + void setNuOfActsForwardLooking(int nOfActsForwardLooking) { + this.nuOfActsForwardLooking = nOfActsForwardLooking; + logger.debug("set [forwardLooking={}]", nOfActsForwardLooking); + } - public void setJobActivityFactory(JobActivityFactory jobActivityFactory){ - this.activityFactory=jobActivityFactory; - } + @Override + public String toString() { + return "[name=calculatesServiceInsertionOnRouteLevel][solutionMemory=" + memorySize + "][forwardLooking=" + nuOfActsForwardLooking + "]"; + } - public void setMemorySize(int memorySize) { - this.memorySize = memorySize; - logger.debug("set [solutionMemory="+memorySize+"]"); - } + /** + * Calculates the insertion costs of job i on route level (which is based on the assumption that inserting job i does not only + * have local effects but affects the entire route). + * Calculation is conducted by two steps. In the first step, promising insertion positions are identified by appromiximating their + * marginal insertion cost. In the second step, marginal cost of the best M positions are calculated exactly. + */ + @Override + public InsertionData getInsertionData(final VehicleRoute currentRoute, final Job jobToInsert, final Vehicle newVehicle, double newVehicleDepartureTime, final Driver newDriver, final double best_known_insertion_costs) { + if (jobToInsert == null) + throw new IllegalStateException("job is null. cannot calculate the insertion of a null-job."); + if (newVehicle == null || newVehicle instanceof NoVehicle) + throw new IllegalStateException("no vehicle given. set para vehicle!"); - public ServiceInsertionOnRouteLevelCalculator(VehicleRoutingTransportCosts vehicleRoutingCosts, VehicleRoutingActivityCosts costFunc, ActivityInsertionCostsCalculator activityInsertionCostsCalculator, HardRouteConstraint hardRouteLevelConstraint, HardActivityConstraint hardActivityLevelConstraint) { - super(); - this.transportCosts = vehicleRoutingCosts; - this.activityCosts = costFunc; - this.activityInsertionCostsCalculator = activityInsertionCostsCalculator; - this.hardRouteLevelConstraint = hardRouteLevelConstraint; - this.hardActivityLevelConstraint = hardActivityLevelConstraint; - auxilliaryPathCostCalculator = new AuxilliaryCostCalculator(transportCosts, activityCosts); - logger.debug("initialise " + this); - } + JobInsertionContext insertionContext = new JobInsertionContext(currentRoute, jobToInsert, newVehicle, newDriver, newVehicleDepartureTime); + if (!hardRouteLevelConstraint.fulfilled(insertionContext)) { + return InsertionData.createEmptyInsertionData(); + } - - public void setStates(RouteAndActivityStateGetter stateManager){ - this.stateManager = stateManager; - } - - void setNuOfActsForwardLooking(int nOfActsForwardLooking) { - this.nuOfActsForwardLooking = nOfActsForwardLooking; - logger.debug("set [forwardLooking="+nOfActsForwardLooking+"]"); - } - - @Override - public String toString() { - return "[name=calculatesServiceInsertionOnRouteLevel][solutionMemory="+memorySize+"][forwardLooking="+nuOfActsForwardLooking+"]"; - } - - /** - * Calculates the insertion costs of job i on route level (which is based on the assumption that inserting job i does not only - * have local effects but affects the entire route). - * Calculation is conducted by two steps. In the first step, promising insertion positions are identified by appromiximating their - * marginal insertion cost. In the second step, marginal cost of the best M positions are calculated exactly. - * - * - */ - @Override - public InsertionData getInsertionData(final VehicleRoute currentRoute, final Job jobToInsert, final Vehicle newVehicle, double newVehicleDepartureTime, final Driver newDriver, final double best_known_insertion_costs) { - if(jobToInsert == null) throw new IllegalStateException("job is null. cannot calculate the insertion of a null-job."); - if(newVehicle == null || newVehicle instanceof NoVehicle) throw new IllegalStateException("no vehicle given. set para vehicle!"); - - JobInsertionContext insertionContext = new JobInsertionContext(currentRoute, jobToInsert, newVehicle, newDriver, newVehicleDepartureTime); - if(!hardRouteLevelConstraint.fulfilled(insertionContext)){ - return InsertionData.createEmptyInsertionData(); - } - - /** - * map that memorizes the costs with newVehicle, which is a cost-snapshot at tour-activities. - */ + /** + * map that memorizes the costs with newVehicle, which is a cost-snapshot at tour-activities. + */ // Map activity2costWithNewVehicle = new HashMap(); - - /** - * priority queue that stores insertion-data by insertion-costs in ascending order. - */ - PriorityQueue bestInsertionsQueue = new PriorityQueue(Math.max(2, currentRoute.getTourActivities().getActivities().size()), getComparator()); - - TourActivities tour = currentRoute.getTourActivities(); - double best_insertion_costs = best_known_insertion_costs; - Service service = (Service)jobToInsert; - - /** - * some inis - */ - TourActivity serviceAct2Insert = activityFactory.createActivities(service).get(0); - int best_insertion_index = InsertionData.NO_INDEX; - - initialiseStartAndEnd(newVehicle, newVehicleDepartureTime); - - TourActivity prevAct = start; - int actIndex = 0; - double sumOf_prevCosts_newVehicle = 0.0; - double prevActDepTime_newVehicle = start.getEndTime(); + /** + * priority queue that stores insertion-data by insertion-costs in ascending order. + */ + PriorityQueue bestInsertionsQueue = new PriorityQueue(Math.max(2, currentRoute.getTourActivities().getActivities().size()), getComparator()); + + TourActivities tour = currentRoute.getTourActivities(); + double best_insertion_costs = best_known_insertion_costs; + Service service = (Service) jobToInsert; + + + /** + * some inis + */ + TourActivity serviceAct2Insert = activityFactory.createActivities(service).get(0); + int best_insertion_index = InsertionData.NO_INDEX; + + initialiseStartAndEnd(newVehicle, newVehicleDepartureTime); + + TourActivity prevAct = start; + int actIndex = 0; + double sumOf_prevCosts_newVehicle = 0.0; + double prevActDepTime_newVehicle = start.getEndTime(); boolean loopBroken = false; - /** - * inserting serviceAct2Insert in route r={0,1,...,i-1,i,j,j+1,...,n(r),n(r)+1} - * i=prevAct - * j=nextAct - * k=serviceAct2Insert - */ - for(TourActivity nextAct : tour.getActivities()){ + /** + * inserting serviceAct2Insert in route r={0,1,...,i-1,i,j,j+1,...,n(r),n(r)+1} + * i=prevAct + * j=nextAct + * k=serviceAct2Insert + */ + for (TourActivity nextAct : tour.getActivities()) { ConstraintsStatus hardActivityConstraintsStatus = hardActivityLevelConstraint.fulfilled(insertionContext, prevAct, serviceAct2Insert, nextAct, prevActDepTime_newVehicle); - if(hardActivityConstraintsStatus.equals(ConstraintsStatus.FULFILLED)){ + if (hardActivityConstraintsStatus.equals(ConstraintsStatus.FULFILLED)) { /** * builds a path on this route forwardPath={i,k,j,j+1,j+2,...,j+nuOfActsForwardLooking} */ @@ -174,16 +172,15 @@ final class ServiceInsertionOnRouteLevelCalculator implements JobInsertionCostsC /** * insertion_cost_approximation = c({0,1,...,i},newVehicle) + c({i,k,j,j+1,j+2,...,j+nuOfActsForwardLooking},newVehicle) - c({0,1,...,i,j,j+1,...,j+nuOfActsForwardLooking},oldVehicle) */ - double insertion_cost_approximation = sumOf_prevCosts_newVehicle - sumOf_prevCosts_oldVehicle(currentRoute,prevAct) + actInsertionCosts; + double insertion_cost_approximation = sumOf_prevCosts_newVehicle - sumOf_prevCosts_oldVehicle(currentRoute, prevAct) + actInsertionCosts; /** * memorize it in insertion-queue */ - if(insertion_cost_approximation < best_known_insertion_costs){ + if (insertion_cost_approximation < best_known_insertion_costs) { bestInsertionsQueue.add(new InsertionData(insertion_cost_approximation, InsertionData.NO_INDEX, actIndex, newVehicle, newDriver)); } - } - else if(hardActivityConstraintsStatus.equals(ConstraintsStatus.NOT_FULFILLED_BREAK)){ + } else if (hardActivityConstraintsStatus.equals(ConstraintsStatus.NOT_FULFILLED_BREAK)) { loopBroken = true; break; } @@ -192,148 +189,143 @@ final class ServiceInsertionOnRouteLevelCalculator implements JobInsertionCostsC /** * calculate transport and activity costs with new vehicle (without inserting k) */ - double transportCost_prevAct_nextAct_newVehicle = transportCosts.getTransportCost(prevAct.getLocation(), nextAct.getLocation(), prevActDepTime_newVehicle, newDriver, newVehicle); - double transportTime_prevAct_nextAct_newVehicle = transportCosts.getTransportTime(prevAct.getLocation(), nextAct.getLocation(), prevActDepTime_newVehicle, newDriver, newVehicle); - double arrTime_nextAct_newVehicle = prevActDepTime_newVehicle + transportTime_prevAct_nextAct_newVehicle; - double activityCost_nextAct = activityCosts.getActivityCost(nextAct, arrTime_nextAct_newVehicle, newDriver, newVehicle); + double transportCost_prevAct_nextAct_newVehicle = transportCosts.getTransportCost(prevAct.getLocation(), nextAct.getLocation(), prevActDepTime_newVehicle, newDriver, newVehicle); + double transportTime_prevAct_nextAct_newVehicle = transportCosts.getTransportTime(prevAct.getLocation(), nextAct.getLocation(), prevActDepTime_newVehicle, newDriver, newVehicle); + double arrTime_nextAct_newVehicle = prevActDepTime_newVehicle + transportTime_prevAct_nextAct_newVehicle; + double activityCost_nextAct = activityCosts.getActivityCost(nextAct, arrTime_nextAct_newVehicle, newDriver, newVehicle); - /** - * memorize transport and activity costs with new vehicle without inserting k - */ - sumOf_prevCosts_newVehicle += transportCost_prevAct_nextAct_newVehicle + activityCost_nextAct; + /** + * memorize transport and activity costs with new vehicle without inserting k + */ + sumOf_prevCosts_newVehicle += transportCost_prevAct_nextAct_newVehicle + activityCost_nextAct; // activity2costWithNewVehicle.put(nextAct, sumOf_prevCosts_newVehicle); - /** - * departure time at nextAct with new vehicle - */ - double depTime_nextAct_newVehicle = Math.max(arrTime_nextAct_newVehicle, nextAct.getTheoreticalEarliestOperationStartTime()) + nextAct.getOperationTime(); + /** + * departure time at nextAct with new vehicle + */ + double depTime_nextAct_newVehicle = Math.max(arrTime_nextAct_newVehicle, nextAct.getTheoreticalEarliestOperationStartTime()) + nextAct.getOperationTime(); - /** - * set previous to next - */ - prevAct = nextAct; - prevActDepTime_newVehicle = depTime_nextAct_newVehicle; + /** + * set previous to next + */ + prevAct = nextAct; + prevActDepTime_newVehicle = depTime_nextAct_newVehicle; - actIndex++; - } - if(!loopBroken){ - End nextAct = end; + actIndex++; + } + if (!loopBroken) { + End nextAct = end; ConstraintsStatus hardActivityConstraintsStatus = hardActivityLevelConstraint.fulfilled(insertionContext, prevAct, serviceAct2Insert, nextAct, prevActDepTime_newVehicle); - if(hardActivityConstraintsStatus.equals(ConstraintsStatus.FULFILLED)){ + if (hardActivityConstraintsStatus.equals(ConstraintsStatus.FULFILLED)) { double actInsertionCosts = activityInsertionCostsCalculator.getCosts(insertionContext, prevAct, nextAct, serviceAct2Insert, prevActDepTime_newVehicle); - /** - * insertion_cost_approximation = c({0,1,...,i},newVehicle) + c({i,k,j,j+1,j+2,...,j+nuOfActsForwardLooking},newVehicle) - c({0,1,...,i,j,j+1,...,j+nuOfActsForwardLooking},oldVehicle) - */ - double insertion_cost_approximation = sumOf_prevCosts_newVehicle - sumOf_prevCosts_oldVehicle(currentRoute,prevAct) + actInsertionCosts; + /** + * insertion_cost_approximation = c({0,1,...,i},newVehicle) + c({i,k,j,j+1,j+2,...,j+nuOfActsForwardLooking},newVehicle) - c({0,1,...,i,j,j+1,...,j+nuOfActsForwardLooking},oldVehicle) + */ + double insertion_cost_approximation = sumOf_prevCosts_newVehicle - sumOf_prevCosts_oldVehicle(currentRoute, prevAct) + actInsertionCosts; - /** - * memorize it in insertion-queue - */ - if(insertion_cost_approximation < best_known_insertion_costs){ - bestInsertionsQueue.add(new InsertionData(insertion_cost_approximation, InsertionData.NO_INDEX, actIndex, newVehicle, newDriver)); - } + /** + * memorize it in insertion-queue + */ + if (insertion_cost_approximation < best_known_insertion_costs) { + bestInsertionsQueue.add(new InsertionData(insertion_cost_approximation, InsertionData.NO_INDEX, actIndex, newVehicle, newDriver)); + } } } - - /** - * the above calculations approximate insertion costs. now calculate the exact insertion costs for the most promising (according to the approximation) - * insertion positions. - * - */ - - if(memorySize==0){ // return bestInsertion - InsertionData insertion = bestInsertionsQueue.poll(); - if(insertion != null){ - best_insertion_index = insertion.getDeliveryInsertionIndex(); - best_insertion_costs = insertion.getInsertionCost(); - } - } - else{ - - for(int i=0;i wholeTour = new ArrayList(); - wholeTour.add(start); - wholeTour.addAll(currentRoute.getTourActivities().getActivities()); - wholeTour.add(end); - wholeTour.add(data.getDeliveryInsertionIndex()+1, serviceAct2Insert); - /** - * compute cost-diff of tour with and without new activity --> insertion_costs - */ + /** + * the above calculations approximate insertion costs. now calculate the exact insertion costs for the most promising (according to the approximation) + * insertion positions. + * + */ + + if (memorySize == 0) { // return bestInsertion + InsertionData insertion = bestInsertionsQueue.poll(); + if (insertion != null) { + best_insertion_index = insertion.getDeliveryInsertionIndex(); + best_insertion_costs = insertion.getInsertionCost(); + } + } else { + + for (int i = 0; i < memorySize; i++) { + InsertionData data = bestInsertionsQueue.poll(); + if (data == null) { + continue; + } + /** + * build tour with new activity. + */ + List wholeTour = new ArrayList(); + wholeTour.add(start); + wholeTour.addAll(currentRoute.getTourActivities().getActivities()); + wholeTour.add(end); + wholeTour.add(data.getDeliveryInsertionIndex() + 1, serviceAct2Insert); + + /** + * compute cost-diff of tour with and without new activity --> insertion_costs + */ Double currentRouteCosts = stateManager.getRouteState(currentRoute, InternalStates.COSTS, Double.class); - if(currentRouteCosts == null) currentRouteCosts = 0.; + if (currentRouteCosts == null) currentRouteCosts = 0.; double insertion_costs = auxilliaryPathCostCalculator.costOfPath(wholeTour, start.getEndTime(), newDriver, newVehicle) - currentRouteCosts; - /** - * if better than best known, make it the best known - */ - if(insertion_costs < best_insertion_costs){ - best_insertion_index = data.getDeliveryInsertionIndex(); - best_insertion_costs = insertion_costs; - } - } - } - if(best_insertion_index == InsertionData.NO_INDEX) return InsertionData.createEmptyInsertionData(); - InsertionData insertionData = new InsertionData(best_insertion_costs, InsertionData.NO_INDEX, best_insertion_index, newVehicle, newDriver); - insertionData.setVehicleDepartureTime(start.getEndTime()); - return insertionData; - } + /** + * if better than best known, make it the best known + */ + if (insertion_costs < best_insertion_costs) { + best_insertion_index = data.getDeliveryInsertionIndex(); + best_insertion_costs = insertion_costs; + } + } + } + if (best_insertion_index == InsertionData.NO_INDEX) return InsertionData.createEmptyInsertionData(); + InsertionData insertionData = new InsertionData(best_insertion_costs, InsertionData.NO_INDEX, best_insertion_index, newVehicle, newDriver); + insertionData.setVehicleDepartureTime(start.getEndTime()); + return insertionData; + } - private void initialiseStartAndEnd(final Vehicle newVehicle, double newVehicleDepartureTime) { - if(start == null){ - start = new Start(newVehicle.getStartLocation(), newVehicle.getEarliestDeparture(), Double.MAX_VALUE); - start.setEndTime(newVehicleDepartureTime); - } - else{ - start.setLocation(Location.newInstance(newVehicle.getStartLocation().getId())); - start.setTheoreticalEarliestOperationStartTime(newVehicle.getEarliestDeparture()); - start.setTheoreticalLatestOperationStartTime(Double.MAX_VALUE); - start.setEndTime(newVehicleDepartureTime); - } - - if(end == null){ - end = new End(newVehicle.getEndLocation(), 0.0, newVehicle.getLatestArrival()); - } - else{ - end.setLocation(Location.newInstance(newVehicle.getEndLocation().getId())); - end.setTheoreticalEarliestOperationStartTime(0.0); - end.setTheoreticalLatestOperationStartTime(newVehicle.getLatestArrival()); - } - } + private void initialiseStartAndEnd(final Vehicle newVehicle, double newVehicleDepartureTime) { + if (start == null) { + start = new Start(newVehicle.getStartLocation(), newVehicle.getEarliestDeparture(), Double.MAX_VALUE); + start.setEndTime(newVehicleDepartureTime); + } else { + start.setLocation(Location.newInstance(newVehicle.getStartLocation().getId())); + start.setTheoreticalEarliestOperationStartTime(newVehicle.getEarliestDeparture()); + start.setTheoreticalLatestOperationStartTime(Double.MAX_VALUE); + start.setEndTime(newVehicleDepartureTime); + } - private double sumOf_prevCosts_oldVehicle(VehicleRoute vehicleRoute, TourActivity act) { - Double prevCost; - if(act instanceof End){ - prevCost = stateManager.getRouteState(vehicleRoute, InternalStates.COSTS,Double.class); - } - else prevCost = stateManager.getActivityState(act, InternalStates.COSTS,Double.class); - if(prevCost == null) prevCost = 0.; - return prevCost; - } + if (end == null) { + end = new End(newVehicle.getEndLocation(), 0.0, newVehicle.getLatestArrival()); + } else { + end.setLocation(Location.newInstance(newVehicle.getEndLocation().getId())); + end.setTheoreticalEarliestOperationStartTime(0.0); + end.setTheoreticalLatestOperationStartTime(newVehicle.getLatestArrival()); + } + } - private Comparator getComparator() { - return new Comparator() { + private double sumOf_prevCosts_oldVehicle(VehicleRoute vehicleRoute, TourActivity act) { + Double prevCost; + if (act instanceof End) { + prevCost = stateManager.getRouteState(vehicleRoute, InternalStates.COSTS, Double.class); + } else prevCost = stateManager.getActivityState(act, InternalStates.COSTS, Double.class); + if (prevCost == null) prevCost = 0.; + return prevCost; + } - @Override - public int compare(InsertionData o1, InsertionData o2) { - if(o1.getInsertionCost() < o2.getInsertionCost()){ - return -1; - } - else { - return 1; - } + private Comparator getComparator() { + return new Comparator() { - } - }; - } + @Override + public int compare(InsertionData o1, InsertionData o2) { + if (o1.getInsertionCost() < o2.getInsertionCost()) { + return -1; + } else { + return 1; + } + + } + }; + } } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/ShipmentInsertionCalculator.java b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/ShipmentInsertionCalculator.java index 59d38472..f47fa385 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/ShipmentInsertionCalculator.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/ShipmentInsertionCalculator.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.recreate; @@ -37,58 +37,55 @@ import org.apache.logging.log4j.Logger; import java.util.List; +final class ShipmentInsertionCalculator implements JobInsertionCostsCalculator { + private static final Logger logger = LogManager.getLogger(ShipmentInsertionCalculator.class); -final class ShipmentInsertionCalculator implements JobInsertionCostsCalculator{ + private HardRouteConstraint hardRouteLevelConstraint; - private static final Logger logger = LogManager.getLogger(ShipmentInsertionCalculator.class); + private HardActivityConstraint hardActivityLevelConstraint; - private HardRouteConstraint hardRouteLevelConstraint; - - private HardActivityConstraint hardActivityLevelConstraint; - - private SoftRouteConstraint softRouteConstraint; - - private SoftActivityConstraint softActivityConstraint; - - private ActivityInsertionCostsCalculator activityInsertionCostsCalculator; - - private VehicleRoutingTransportCosts transportCosts; - - private JobActivityFactory activityFactory; - - private AdditionalAccessEgressCalculator additionalAccessEgressCalculator; - - public ShipmentInsertionCalculator(VehicleRoutingTransportCosts routingCosts, ActivityInsertionCostsCalculator activityInsertionCostsCalculator, ConstraintManager constraintManager) { - super(); - this.activityInsertionCostsCalculator = activityInsertionCostsCalculator; - this.hardRouteLevelConstraint = constraintManager; - this.hardActivityLevelConstraint = constraintManager; - this.softActivityConstraint = constraintManager; - this.softRouteConstraint = constraintManager; - this.transportCosts = routingCosts; - additionalAccessEgressCalculator = new AdditionalAccessEgressCalculator(routingCosts); - logger.debug("initialise " + this); - } + private SoftRouteConstraint softRouteConstraint; - public void setJobActivityFactory(JobActivityFactory activityFactory){ + private SoftActivityConstraint softActivityConstraint; + + private ActivityInsertionCostsCalculator activityInsertionCostsCalculator; + + private VehicleRoutingTransportCosts transportCosts; + + private JobActivityFactory activityFactory; + + private AdditionalAccessEgressCalculator additionalAccessEgressCalculator; + + public ShipmentInsertionCalculator(VehicleRoutingTransportCosts routingCosts, ActivityInsertionCostsCalculator activityInsertionCostsCalculator, ConstraintManager constraintManager) { + super(); + this.activityInsertionCostsCalculator = activityInsertionCostsCalculator; + this.hardRouteLevelConstraint = constraintManager; + this.hardActivityLevelConstraint = constraintManager; + this.softActivityConstraint = constraintManager; + this.softRouteConstraint = constraintManager; + this.transportCosts = routingCosts; + additionalAccessEgressCalculator = new AdditionalAccessEgressCalculator(routingCosts); + logger.debug("initialise {}", this); + } + + public void setJobActivityFactory(JobActivityFactory activityFactory) { this.activityFactory = activityFactory; } - - @Override - public String toString() { - return "[name=calculatesServiceInsertion]"; - } - - /** - * Calculates the marginal cost of inserting job i locally. This is based on the - * assumption that cost changes can entirely covered by only looking at the predecessor i-1 and its successor i+1. - * - */ - @Override - public InsertionData getInsertionData(final VehicleRoute currentRoute, final Job jobToInsert, final Vehicle newVehicle, double newVehicleDepartureTime, final Driver newDriver, final double bestKnownCosts) { + + @Override + public String toString() { + return "[name=calculatesServiceInsertion]"; + } + + /** + * Calculates the marginal cost of inserting job i locally. This is based on the + * assumption that cost changes can entirely covered by only looking at the predecessor i-1 and its successor i+1. + */ + @Override + public InsertionData getInsertionData(final VehicleRoute currentRoute, final Job jobToInsert, final Vehicle newVehicle, double newVehicleDepartureTime, final Driver newDriver, final double bestKnownCosts) { JobInsertionContext insertionContext = new JobInsertionContext(currentRoute, jobToInsert, newVehicle, newDriver, newVehicleDepartureTime); - Shipment shipment = (Shipment)jobToInsert; + Shipment shipment = (Shipment) jobToInsert; TourActivity pickupShipment = activityFactory.createActivities(shipment).get(0); TourActivity deliverShipment = activityFactory.createActivities(shipment).get(1); insertionContext.getAssociatedActivities().add(pickupShipment); @@ -97,9 +94,9 @@ final class ShipmentInsertionCalculator implements JobInsertionCostsCalculator{ /* check hard route constraints */ - if(!hardRouteLevelConstraint.fulfilled(insertionContext)){ - return InsertionData.createEmptyInsertionData(); - } + if (!hardRouteLevelConstraint.fulfilled(insertionContext)) { + return InsertionData.createEmptyInsertionData(); + } /* check soft route constraints */ @@ -109,51 +106,49 @@ final class ShipmentInsertionCalculator implements JobInsertionCostsCalculator{ additionalICostsAtRouteLevel += additionalAccessEgressCalculator.getCosts(insertionContext); int pickupInsertionIndex = InsertionData.NO_INDEX; - int deliveryInsertionIndex = InsertionData.NO_INDEX; - - Start start = new Start(newVehicle.getStartLocation(), newVehicle.getEarliestDeparture(), newVehicle.getLatestArrival()); - start.setEndTime(newVehicleDepartureTime); - - End end = new End(newVehicle.getEndLocation(), 0.0, newVehicle.getLatestArrival()); + int deliveryInsertionIndex = InsertionData.NO_INDEX; + + Start start = new Start(newVehicle.getStartLocation(), newVehicle.getEarliestDeparture(), newVehicle.getLatestArrival()); + start.setEndTime(newVehicleDepartureTime); + + End end = new End(newVehicle.getEndLocation(), 0.0, newVehicle.getLatestArrival()); ActivityContext pickupContext = new ActivityContext(); - TourActivity prevAct = start; - double prevActEndTime = newVehicleDepartureTime; + TourActivity prevAct = start; + double prevActEndTime = newVehicleDepartureTime; - //loops - int i = 0; - boolean tourEnd = false; - //pickupShipmentLoop - List activities = currentRoute.getTourActivities().getActivities(); + //loops + int i = 0; + boolean tourEnd = false; + //pickupShipmentLoop + List activities = currentRoute.getTourActivities().getActivities(); - while(!tourEnd){ - TourActivity nextAct; - if(i < activities.size()){ - nextAct = activities.get(i); - } - else{ - nextAct = end; - tourEnd = true; - } -// logger.info("activity: " + i + ", act-size: " + activities.size()); - ConstraintsStatus pickupShipmentConstraintStatus = hardActivityLevelConstraint.fulfilled(insertionContext, prevAct, pickupShipment, nextAct, prevActEndTime); - if(pickupShipmentConstraintStatus.equals(ConstraintsStatus.NOT_FULFILLED)){ - double nextActArrTime = prevActEndTime + transportCosts.getTransportTime(prevAct.getLocation(), nextAct.getLocation(), prevActEndTime, newDriver, newVehicle); - prevActEndTime = CalculationUtils.getActivityEndTime(nextActArrTime, nextAct); - prevAct = nextAct; - i++; - continue; - } - else if(pickupShipmentConstraintStatus.equals(ConstraintsStatus.NOT_FULFILLED_BREAK)){ - break; - } - double additionalPickupICosts = softActivityConstraint.getCosts(insertionContext, prevAct, pickupShipment, nextAct, prevActEndTime); - double pickupAIC = calculate(insertionContext,prevAct,pickupShipment, nextAct,prevActEndTime); + while (!tourEnd) { + TourActivity nextAct; + if (i < activities.size()) { + nextAct = activities.get(i); + } else { + nextAct = end; + tourEnd = true; + } +// logger.info("activity: {}, act-size: {}", i, activities.size()); + ConstraintsStatus pickupShipmentConstraintStatus = hardActivityLevelConstraint.fulfilled(insertionContext, prevAct, pickupShipment, nextAct, prevActEndTime); + if (pickupShipmentConstraintStatus.equals(ConstraintsStatus.NOT_FULFILLED)) { + double nextActArrTime = prevActEndTime + transportCosts.getTransportTime(prevAct.getLocation(), nextAct.getLocation(), prevActEndTime, newDriver, newVehicle); + prevActEndTime = CalculationUtils.getActivityEndTime(nextActArrTime, nextAct); + prevAct = nextAct; + i++; + continue; + } else if (pickupShipmentConstraintStatus.equals(ConstraintsStatus.NOT_FULFILLED_BREAK)) { + break; + } + double additionalPickupICosts = softActivityConstraint.getCosts(insertionContext, prevAct, pickupShipment, nextAct, prevActEndTime); + double pickupAIC = calculate(insertionContext, prevAct, pickupShipment, nextAct, prevActEndTime); - TourActivity prevAct_deliveryLoop = pickupShipment; - double shipmentPickupArrTime = prevActEndTime + transportCosts.getTransportTime(prevAct.getLocation(), pickupShipment.getLocation(), prevActEndTime, newDriver, newVehicle); - double shipmentPickupEndTime = CalculationUtils.getActivityEndTime(shipmentPickupArrTime, pickupShipment); + TourActivity prevAct_deliveryLoop = pickupShipment; + double shipmentPickupArrTime = prevActEndTime + transportCosts.getTransportTime(prevAct.getLocation(), pickupShipment.getLocation(), prevActEndTime, newDriver, newVehicle); + double shipmentPickupEndTime = CalculationUtils.getActivityEndTime(shipmentPickupArrTime, pickupShipment); pickupContext.setArrivalTime(shipmentPickupArrTime); pickupContext.setEndTime(shipmentPickupEndTime); @@ -163,63 +158,61 @@ final class ShipmentInsertionCalculator implements JobInsertionCostsCalculator{ double prevActEndTime_deliveryLoop = shipmentPickupEndTime; /* - -------------------------------- + -------------------------------- */ - //deliverShipmentLoop - int j = i; - boolean tourEnd_deliveryLoop = false; - while(!tourEnd_deliveryLoop){ + //deliverShipmentLoop + int j = i; + boolean tourEnd_deliveryLoop = false; + while (!tourEnd_deliveryLoop) { // for(int j=i;j. ******************************************************************************/ package jsprit.core.algorithm.recreate; @@ -22,18 +22,18 @@ import jsprit.core.problem.vehicle.Vehicle; import jsprit.core.problem.vehicle.VehicleFleetManager; -public class VehicleSwitched implements VehicleSwitchedListener{ +public class VehicleSwitched implements VehicleSwitchedListener { - private VehicleFleetManager fleetManager; - - public VehicleSwitched(VehicleFleetManager fleetManager){ - this.fleetManager = fleetManager; - } - - @Override - public void vehicleSwitched(VehicleRoute vehicleRoute, Vehicle oldVehicle, Vehicle newVehicle) { - fleetManager.unlock(oldVehicle); - fleetManager.lock(newVehicle); - } + private VehicleFleetManager fleetManager; + + public VehicleSwitched(VehicleFleetManager fleetManager) { + this.fleetManager = fleetManager; + } + + @Override + public void vehicleSwitched(VehicleRoute vehicleRoute, Vehicle oldVehicle, Vehicle newVehicle) { + fleetManager.unlock(oldVehicle); + fleetManager.lock(newVehicle); + } } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/VehicleTypeDependentJobInsertionCalculator.java b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/VehicleTypeDependentJobInsertionCalculator.java index 4b630eea..6dc17a48 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/VehicleTypeDependentJobInsertionCalculator.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/VehicleTypeDependentJobInsertionCalculator.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.recreate; @@ -33,99 +33,104 @@ import java.util.HashSet; import java.util.Set; -final class VehicleTypeDependentJobInsertionCalculator implements JobInsertionCostsCalculator{ +final class VehicleTypeDependentJobInsertionCalculator implements JobInsertionCostsCalculator { - private Logger logger = LogManager.getLogger(VehicleTypeDependentJobInsertionCalculator.class); - - private final VehicleFleetManager fleetManager; - - private final JobInsertionCostsCalculator insertionCalculator; - - private final VehicleRoutingProblem vrp; - - private Set initialVehicleIds = new HashSet(); - - /** - * true if a vehicle(-type) is allowed to take over the whole route that was previously served by another vehicle - * - *

vehicleSwitch allowed makes sense if fleet consists of vehicles with different capacities such that one - * can start with a small vehicle, but as the number of customers grows bigger vehicles can be operated, i.e. - * bigger vehicles can take over the route that was previously served by a small vehicle. - * - */ - private boolean vehicleSwitchAllowed = false; + private Logger logger = LogManager.getLogger(VehicleTypeDependentJobInsertionCalculator.class); - public VehicleTypeDependentJobInsertionCalculator(final VehicleRoutingProblem vrp, final VehicleFleetManager fleetManager, final JobInsertionCostsCalculator jobInsertionCalc) { - this.fleetManager = fleetManager; - this.insertionCalculator = jobInsertionCalc; - this.vrp = vrp; - getInitialVehicleIds(); - logger.debug("initialise " + this); - } + private final VehicleFleetManager fleetManager; - private void getInitialVehicleIds() { + private final JobInsertionCostsCalculator insertionCalculator; + + private final VehicleRoutingProblem vrp; + + private Set initialVehicleIds = new HashSet(); + + /** + * true if a vehicle(-type) is allowed to take over the whole route that was previously served by another vehicle + *

+ *

vehicleSwitch allowed makes sense if fleet consists of vehicles with different capacities such that one + * can start with a small vehicle, but as the number of customers grows bigger vehicles can be operated, i.e. + * bigger vehicles can take over the route that was previously served by a small vehicle. + */ + private boolean vehicleSwitchAllowed = false; + + public VehicleTypeDependentJobInsertionCalculator(final VehicleRoutingProblem vrp, final VehicleFleetManager fleetManager, final JobInsertionCostsCalculator jobInsertionCalc) { + this.fleetManager = fleetManager; + this.insertionCalculator = jobInsertionCalc; + this.vrp = vrp; + getInitialVehicleIds(); + logger.debug("initialise " + this); + } + + private void getInitialVehicleIds() { Collection initialVehicleRoutes = vrp.getInitialVehicleRoutes(); - for(VehicleRoute initialRoute : initialVehicleRoutes){ - initialVehicleIds.add(initialRoute.getVehicle().getId()); - } - } + for (VehicleRoute initialRoute : initialVehicleRoutes) { + initialVehicleIds.add(initialRoute.getVehicle().getId()); + } + } - @Override - public String toString() { - return "[name=vehicleTypeDependentServiceInsertion]"; - } - - /** - * @return the vehicleSwitchAllowed - */ - @SuppressWarnings("UnusedDeclaration") + @Override + public String toString() { + return "[name=vehicleTypeDependentServiceInsertion]"; + } + + /** + * @return the vehicleSwitchAllowed + */ + @SuppressWarnings("UnusedDeclaration") public boolean isVehicleSwitchAllowed() { - return vehicleSwitchAllowed; - } + return vehicleSwitchAllowed; + } - /** - * default is true - * - * @param vehicleSwitchAllowed the vehicleSwitchAllowed to set - */ - public void setVehicleSwitchAllowed(boolean vehicleSwitchAllowed) { - logger.debug("set vehicleSwitchAllowed to " + vehicleSwitchAllowed); - this.vehicleSwitchAllowed = vehicleSwitchAllowed; - } + /** + * default is true + * + * @param vehicleSwitchAllowed the vehicleSwitchAllowed to set + */ + public void setVehicleSwitchAllowed(boolean vehicleSwitchAllowed) { + logger.debug("set vehicleSwitchAllowed to " + vehicleSwitchAllowed); + this.vehicleSwitchAllowed = vehicleSwitchAllowed; + } - public InsertionData getInsertionData(final VehicleRoute currentRoute, final Job jobToInsert, final Vehicle vehicle, double newVehicleDepartureTime, final Driver driver, final double bestKnownCost) { - Vehicle selectedVehicle = currentRoute.getVehicle(); - Driver selectedDriver = currentRoute.getDriver(); - InsertionData bestIData = InsertionData.createEmptyInsertionData(); - double bestKnownCost_ = bestKnownCost; - Collection relevantVehicles = new ArrayList(); - if(!(selectedVehicle instanceof NoVehicle)) { - relevantVehicles.add(selectedVehicle); - if(vehicleSwitchAllowed && !isVehicleWithInitialRoute(selectedVehicle)){ - relevantVehicles.addAll(fleetManager.getAvailableVehicles(selectedVehicle)); - } - } - else{ //if no vehicle has been assigned, i.e. it is an empty route - relevantVehicles.addAll(fleetManager.getAvailableVehicles()); - } - for(Vehicle v : relevantVehicles){ - double depTime; - if(v == selectedVehicle) depTime = currentRoute.getDepartureTime(); - else depTime = v.getEarliestDeparture(); - InsertionData iData = insertionCalculator.getInsertionData(currentRoute, jobToInsert, v, depTime, selectedDriver, bestKnownCost_); - if(iData instanceof NoInsertionFound) { + public InsertionData getInsertionData(final VehicleRoute currentRoute, final Job jobToInsert, final Vehicle vehicle, double newVehicleDepartureTime, final Driver driver, final double bestKnownCost) { + if(vehicle != null){ + return insertionCalculator.getInsertionData(currentRoute, jobToInsert, vehicle, newVehicleDepartureTime, driver, bestKnownCost); + } + Vehicle selectedVehicle = currentRoute.getVehicle(); + Driver selectedDriver = currentRoute.getDriver(); + InsertionData bestIData = InsertionData.createEmptyInsertionData(); + double bestKnownCost_ = bestKnownCost; + Collection relevantVehicles = new ArrayList(); + if (!(selectedVehicle instanceof NoVehicle)) { + relevantVehicles.add(selectedVehicle); + if (vehicleSwitchAllowed && !isVehicleWithInitialRoute(selectedVehicle)) { + relevantVehicles.addAll(fleetManager.getAvailableVehicles(selectedVehicle)); + } + } else { //if no vehicle has been assigned, i.e. it is an empty route + relevantVehicles.addAll(fleetManager.getAvailableVehicles()); + } + for (Vehicle v : relevantVehicles) { + double depTime; + if (v == selectedVehicle) depTime = currentRoute.getDepartureTime(); + else depTime = v.getEarliestDeparture(); + InsertionData iData = insertionCalculator.getInsertionData(currentRoute, jobToInsert, v, depTime, selectedDriver, bestKnownCost_); + if (iData instanceof NoInsertionFound) { continue; - } - if(iData.getInsertionCost() < bestKnownCost_){ - bestIData = iData; - bestKnownCost_ = iData.getInsertionCost(); - } - } - return bestIData; - } + } + if (iData.getInsertionCost() < bestKnownCost_) { + bestIData = iData; + bestKnownCost_ = iData.getInsertionCost(); + } + } + return bestIData; + } - private boolean isVehicleWithInitialRoute(Vehicle selectedVehicle) { - return initialVehicleIds.contains(selectedVehicle.getId()); - } + VehicleFleetManager getFleetManager(){ + return fleetManager; + } + + private boolean isVehicleWithInitialRoute(Vehicle selectedVehicle) { + return initialVehicleIds.contains(selectedVehicle.getId()); + } } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/VersionedInsertionData.java b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/VersionedInsertionData.java new file mode 100644 index 00000000..fcc4aa3c --- /dev/null +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/VersionedInsertionData.java @@ -0,0 +1,33 @@ +package jsprit.core.algorithm.recreate; + +import jsprit.core.problem.solution.route.VehicleRoute; + +/** + * Created by schroeder on 15/10/15. + */ +class VersionedInsertionData { + + private InsertionData iData; + + private VehicleRoute route; + + private int version; + + public VersionedInsertionData(InsertionData iData, int version, VehicleRoute route) { + this.iData = iData; + this.version = version; + this.route = route; + } + + public InsertionData getiData() { + return iData; + } + + public int getVersion() { + return version; + } + + public VehicleRoute getRoute() { + return route; + } +} diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/listener/BeforeJobInsertionListener.java b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/listener/BeforeJobInsertionListener.java index 7bc92d88..db1ee05b 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/listener/BeforeJobInsertionListener.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/listener/BeforeJobInsertionListener.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.recreate.listener; @@ -20,8 +20,8 @@ import jsprit.core.algorithm.recreate.InsertionData; import jsprit.core.problem.job.Job; import jsprit.core.problem.solution.route.VehicleRoute; -public interface BeforeJobInsertionListener extends InsertionListener{ +public interface BeforeJobInsertionListener extends InsertionListener { - public void informBeforeJobInsertion(Job job, InsertionData data, VehicleRoute route); + public void informBeforeJobInsertion(Job job, InsertionData data, VehicleRoute route); } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/listener/InsertionEndsListener.java b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/listener/InsertionEndsListener.java index 819e7ef5..e6be0d0b 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/listener/InsertionEndsListener.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/listener/InsertionEndsListener.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.recreate.listener; @@ -21,8 +21,7 @@ import jsprit.core.problem.solution.route.VehicleRoute; import java.util.Collection; - public interface InsertionEndsListener extends InsertionListener { - public void informInsertionEnds(Collection vehicleRoutes); + public void informInsertionEnds(Collection vehicleRoutes); } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/listener/InsertionListener.java b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/listener/InsertionListener.java index eb32b31c..a03751d6 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/listener/InsertionListener.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/listener/InsertionListener.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.recreate.listener; @@ -19,11 +19,7 @@ package jsprit.core.algorithm.recreate.listener; import jsprit.core.algorithm.listener.SearchStrategyModuleListener; +public interface InsertionListener extends SearchStrategyModuleListener { - -public interface InsertionListener extends SearchStrategyModuleListener{ - - - } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/listener/InsertionListeners.java b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/listener/InsertionListeners.java index 795f9d4c..c669a1f8 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/listener/InsertionListeners.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/listener/InsertionListeners.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.recreate.listener; @@ -26,63 +26,63 @@ import java.util.Collection; public class InsertionListeners { - - private Collection listeners = new ArrayList(); - - public Collection getListeners(){ - return listeners; - } - - public void informJobInserted(Job insertedJob, VehicleRoute inRoute, double additionalCosts, double additionalTime){ - for(InsertionListener l : listeners){ - if(l instanceof JobInsertedListener){ - ((JobInsertedListener)l).informJobInserted(insertedJob, inRoute, additionalCosts, additionalTime); - } - } - } - - public void informVehicleSwitched(VehicleRoute route, Vehicle oldVehicle, Vehicle newVehicle){ - for(InsertionListener l : listeners){ - if(l instanceof VehicleSwitchedListener){ - ((VehicleSwitchedListener) l).vehicleSwitched(route, oldVehicle, newVehicle); - } - } - } - - public void informBeforeJobInsertion(Job job, InsertionData data, VehicleRoute route){ - for(InsertionListener l : listeners){ - if(l instanceof BeforeJobInsertionListener){ - ((BeforeJobInsertionListener)l).informBeforeJobInsertion(job, data, route); - } - } - } - - public void informInsertionStarts(Collection vehicleRoutes, Collection unassignedJobs){ - for(InsertionListener l : listeners){ - if(l instanceof InsertionStartsListener){ - ((InsertionStartsListener)l).informInsertionStarts(vehicleRoutes, unassignedJobs); - } - } - } - - public void informInsertionEndsListeners(Collection vehicleRoutes) { - for(InsertionListener l : listeners){ - if(l instanceof InsertionEndsListener){ - ((InsertionEndsListener)l).informInsertionEnds(vehicleRoutes); - } - } - } - - public void addListener(InsertionListener insertionListener){ - listeners.add(insertionListener); - } - - public void removeListener(InsertionListener insertionListener){ - listeners.remove(insertionListener); - } - public void addAllListeners(Collection listeners) { - for(InsertionListener l : listeners) addListener(l); - } + private Collection listeners = new ArrayList(); + + public Collection getListeners() { + return listeners; + } + + public void informJobInserted(Job insertedJob, VehicleRoute inRoute, double additionalCosts, double additionalTime) { + for (InsertionListener l : listeners) { + if (l instanceof JobInsertedListener) { + ((JobInsertedListener) l).informJobInserted(insertedJob, inRoute, additionalCosts, additionalTime); + } + } + } + + public void informVehicleSwitched(VehicleRoute route, Vehicle oldVehicle, Vehicle newVehicle) { + for (InsertionListener l : listeners) { + if (l instanceof VehicleSwitchedListener) { + ((VehicleSwitchedListener) l).vehicleSwitched(route, oldVehicle, newVehicle); + } + } + } + + public void informBeforeJobInsertion(Job job, InsertionData data, VehicleRoute route) { + for (InsertionListener l : listeners) { + if (l instanceof BeforeJobInsertionListener) { + ((BeforeJobInsertionListener) l).informBeforeJobInsertion(job, data, route); + } + } + } + + public void informInsertionStarts(Collection vehicleRoutes, Collection unassignedJobs) { + for (InsertionListener l : listeners) { + if (l instanceof InsertionStartsListener) { + ((InsertionStartsListener) l).informInsertionStarts(vehicleRoutes, unassignedJobs); + } + } + } + + public void informInsertionEndsListeners(Collection vehicleRoutes) { + for (InsertionListener l : listeners) { + if (l instanceof InsertionEndsListener) { + ((InsertionEndsListener) l).informInsertionEnds(vehicleRoutes); + } + } + } + + public void addListener(InsertionListener insertionListener) { + listeners.add(insertionListener); + } + + public void removeListener(InsertionListener insertionListener) { + listeners.remove(insertionListener); + } + + public void addAllListeners(Collection listeners) { + for (InsertionListener l : listeners) addListener(l); + } } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/listener/InsertionStartsListener.java b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/listener/InsertionStartsListener.java index 3ebeae72..bcfd1d0e 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/listener/InsertionStartsListener.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/listener/InsertionStartsListener.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.recreate.listener; @@ -22,9 +22,8 @@ import jsprit.core.problem.solution.route.VehicleRoute; import java.util.Collection; - public interface InsertionStartsListener extends InsertionListener { - public void informInsertionStarts(Collection vehicleRoutes, Collection unassignedJobs); - + public void informInsertionStarts(Collection vehicleRoutes, Collection unassignedJobs); + } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/listener/JobInsertedListener.java b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/listener/JobInsertedListener.java index dd2663d9..9e48347f 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/listener/JobInsertedListener.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/listener/JobInsertedListener.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.recreate.listener; @@ -20,11 +20,7 @@ import jsprit.core.problem.job.Job; import jsprit.core.problem.solution.route.VehicleRoute; +public interface JobInsertedListener extends InsertionListener { - - - -public interface JobInsertedListener extends InsertionListener{ - - public void informJobInserted(Job job2insert, VehicleRoute inRoute, double additionalCosts, double additionalTime); + public void informJobInserted(Job job2insert, VehicleRoute inRoute, double additionalCosts, double additionalTime); } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/listener/VehicleSwitchedListener.java b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/listener/VehicleSwitchedListener.java index d57fa11e..483a3763 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/listener/VehicleSwitchedListener.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/listener/VehicleSwitchedListener.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.recreate.listener; @@ -19,8 +19,8 @@ package jsprit.core.algorithm.recreate.listener; import jsprit.core.problem.solution.route.VehicleRoute; import jsprit.core.problem.vehicle.Vehicle; -public interface VehicleSwitchedListener extends InsertionListener{ - - public void vehicleSwitched(VehicleRoute vehicleRoute, Vehicle oldVehicle, Vehicle newVehicle); +public interface VehicleSwitchedListener extends InsertionListener { + + public void vehicleSwitched(VehicleRoute vehicleRoute, Vehicle oldVehicle, Vehicle newVehicle); } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/AbstractRuinStrategy.java b/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/AbstractRuinStrategy.java index fb07df63..f25269b7 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/AbstractRuinStrategy.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/AbstractRuinStrategy.java @@ -30,7 +30,7 @@ import org.apache.logging.log4j.Logger; import java.util.Collection; import java.util.Random; -public abstract class AbstractRuinStrategy implements RuinStrategy{ +public abstract class AbstractRuinStrategy implements RuinStrategy { private final static Logger logger = LogManager.getLogger(); @@ -46,11 +46,11 @@ public abstract class AbstractRuinStrategy implements RuinStrategy{ protected RuinShareFactory ruinShareFactory; - public void setRuinShareFactory(RuinShareFactory ruinShareFactory){ + public void setRuinShareFactory(RuinShareFactory ruinShareFactory) { this.ruinShareFactory = ruinShareFactory; } - public RuinShareFactory getRuinShareFactory(){ + public RuinShareFactory getRuinShareFactory() { return ruinShareFactory; } @@ -60,11 +60,11 @@ public abstract class AbstractRuinStrategy implements RuinStrategy{ } @Override - public Collection ruin(Collection vehicleRoutes){ + public Collection ruin(Collection vehicleRoutes) { ruinListeners.ruinStarts(vehicleRoutes); Collection unassigned = ruinRoutes(vehicleRoutes); - logger.trace("ruin: " + "[ruined=" + unassigned.size() + "]"); - ruinListeners.ruinEnds(vehicleRoutes,unassigned); + logger.trace("ruin: [ruined={}]", unassigned.size()); + ruinListeners.ruinEnds(vehicleRoutes, unassigned); return unassigned; } @@ -73,10 +73,10 @@ public abstract class AbstractRuinStrategy implements RuinStrategy{ @Override @Deprecated - public Collection ruin(Collection vehicleRoutes, Job targetJob, int nOfJobs2BeRemoved){ + public Collection ruin(Collection vehicleRoutes, Job targetJob, int nOfJobs2BeRemoved) { ruinListeners.ruinStarts(vehicleRoutes); Collection unassigned = ruinRoutes(vehicleRoutes, targetJob, nOfJobs2BeRemoved); - ruinListeners.ruinEnds(vehicleRoutes,unassigned); + ruinListeners.ruinEnds(vehicleRoutes, unassigned); return unassigned; } @@ -99,7 +99,7 @@ public abstract class AbstractRuinStrategy implements RuinStrategy{ } protected boolean removeJob(Job job, Collection vehicleRoutes) { - if(jobIsInitial(job)) return false; + if (jobIsInitial(job)) return false; for (VehicleRoute route : vehicleRoutes) { if (removeJob(job, route)) { return true; @@ -108,16 +108,16 @@ public abstract class AbstractRuinStrategy implements RuinStrategy{ return false; } - private boolean jobIsInitial(Job job){ + private boolean jobIsInitial(Job job) { return !vrp.getJobs().containsKey(job.getId()); //for initial jobs (being not contained in problem } protected boolean removeJob(Job job, VehicleRoute route) { - if(jobIsInitial(job)) return false; + if (jobIsInitial(job)) return false; boolean removed = route.getTourActivities().removeJob(job); if (removed) { - logger.trace("ruin: " + job.getId()); - ruinListeners.removed(job,route); + logger.trace("ruin: {}", job.getId()); + ruinListeners.removed(job, route); return true; } return false; diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/DBSCANClusterer.java b/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/DBSCANClusterer.java index a0ad4b9f..fa34c58c 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/DBSCANClusterer.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/DBSCANClusterer.java @@ -3,8 +3,6 @@ package jsprit.core.algorithm.ruin; import jsprit.core.problem.Location; import jsprit.core.problem.cost.VehicleRoutingTransportCosts; import jsprit.core.problem.job.Job; -import jsprit.core.problem.job.Service; -import jsprit.core.problem.job.Shipment; import jsprit.core.problem.solution.route.VehicleRoute; import jsprit.core.problem.solution.route.activity.TourActivity; import jsprit.core.util.RandomNumberGeneration; @@ -16,8 +14,8 @@ import org.apache.commons.math3.ml.distance.DistanceMeasure; import java.util.*; /** -* Created by schroeder on 04/02/15. -*/ + * Created by schroeder on 04/02/15. + */ public class DBSCANClusterer { private static class LocationWrapper implements Clusterable { @@ -30,24 +28,24 @@ public class DBSCANClusterer { private int id; - public LocationWrapper(Job job) { - this.locations = getLocations(job); + public LocationWrapper(Job job, List locations) { + this.locations = locations; objCounter++; this.job = job; this.id = objCounter; } - private List getLocations(Job job){ - List locs = new ArrayList(); - if(job instanceof Service) { - locs.add(((Service) job).getLocation()); - } - else if(job instanceof Shipment){ - locs.add(((Shipment) job).getPickupLocation()); - locs.add(((Shipment) job).getDeliveryLocation()); - } - return locs; - } +// private List getLocations(Job job){ +// List locs = new ArrayList(); +// if(job instanceof Service) { +// locs.add(((Service) job).getLocation()); +// } +// else if(job instanceof Shipment){ +// locs.add(((Shipment) job).getPickupLocation()); +// locs.add(((Shipment) job).getDeliveryLocation()); +// } +// return locs; +// } public List getLocations() { return locations; @@ -55,7 +53,7 @@ public class DBSCANClusterer { @Override public double[] getPoint() { - return new double[]{ id }; + return new double[]{id}; } public Job getJob() { @@ -65,31 +63,31 @@ public class DBSCANClusterer { private static class MyDistance implements DistanceMeasure { - private Map locations; + private Map locations; private VehicleRoutingTransportCosts costs; public MyDistance(List locations, VehicleRoutingTransportCosts costs) { this.locations = new HashMap(); - for(LocationWrapper lw : locations){ - this.locations.put((int)lw.getPoint()[0],lw); + for (LocationWrapper lw : locations) { + this.locations.put((int) lw.getPoint()[0], lw); } this.costs = costs; } @Override public double compute(double[] doubles, double[] doubles1) { - LocationWrapper l1 = locations.get((int)doubles[0]); - LocationWrapper l2 = locations.get((int)doubles1[0]); + LocationWrapper l1 = locations.get((int) doubles[0]); + LocationWrapper l2 = locations.get((int) doubles1[0]); int count = 0; double sum = 0; - for(Location loc_1 : l1.getLocations()){ - for(Location loc_2 : l2.getLocations()){ - sum += costs.getTransportCost(loc_1,loc_2,0,null,null); + for (Location loc_1 : l1.getLocations()) { + for (Location loc_2 : l2.getLocations()) { + sum += costs.getTransportCost(loc_1, loc_2, 0, null, null); count++; } } - return sum / (double)count; + return sum / (double) count; } } @@ -113,38 +111,53 @@ public class DBSCANClusterer { this.costs = costs; } - public void setMinPts(int pts){ + public void setMinPts(int pts) { this.minNoOfJobsInCluster = pts; } - public void setEpsFactor(double epsFactor){ + public void setEpsFactor(double epsFactor) { this.epsFactor = epsFactor; } - public void setEpsDistance(double epsDistance){ + public void setEpsDistance(double epsDistance) { this.epsDistance = epsDistance; } - public List> getClusters(VehicleRoute route){ - List locations = new ArrayList(route.getTourActivities().getJobs().size()); - for(Job j : route.getTourActivities().getJobs()){ - locations.add(new LocationWrapper(j)); - } + public List> getClusters(VehicleRoute route) { + List locations = getLocationWrappers(route); List> clusterResults = getClusters(route, locations); return makeList(clusterResults); } + private List getLocationWrappers(VehicleRoute route) { + List locations = new ArrayList(route.getTourActivities().getJobs().size()); + Map> jobs2locations = new HashMap>(); + for (TourActivity act : route.getActivities()) { + if (act instanceof TourActivity.JobActivity) { + Job job = ((TourActivity.JobActivity) act).getJob(); + if (!jobs2locations.containsKey(job)) { + jobs2locations.put(job, new ArrayList()); + } + jobs2locations.get(job).add(act.getLocation()); + } + } + for (Job j : jobs2locations.keySet()) { + locations.add(new LocationWrapper(j, jobs2locations.get(j))); + } + return locations; + } + private List> getClusters(VehicleRoute route, List locations) { double sampledDistance; - if(epsDistance != null) sampledDistance = epsDistance; + if (epsDistance != null) sampledDistance = epsDistance; else sampledDistance = Math.max(0, sample(costs, route)); - org.apache.commons.math3.ml.clustering.DBSCANClusterer clusterer = new org.apache.commons.math3.ml.clustering.DBSCANClusterer(sampledDistance, minNoOfJobsInCluster, new MyDistance(locations,costs)); + org.apache.commons.math3.ml.clustering.DBSCANClusterer clusterer = new org.apache.commons.math3.ml.clustering.DBSCANClusterer(sampledDistance, minNoOfJobsInCluster, new MyDistance(locations, costs)); return clusterer.cluster(locations); } private List> makeList(List> clusterResults) { List> l = new ArrayList>(); - for(Cluster c : clusterResults){ + for (Cluster c : clusterResults) { List l_ = getJobList(c); l.add(l_); } @@ -153,21 +166,18 @@ public class DBSCANClusterer { private List getJobList(Cluster c) { List l_ = new ArrayList(); - if(c == null) return l_; - for(LocationWrapper lw : c.getPoints()){ + if (c == null) return l_; + for (LocationWrapper lw : c.getPoints()) { l_.add(lw.getJob()); } return l_; } - public List getRandomCluster(VehicleRoute route){ - if(route.isEmpty()) return Collections.emptyList(); - List locations = new ArrayList(route.getTourActivities().getJobs().size()); - for(Job j : route.getTourActivities().getJobs()){ - locations.add(new LocationWrapper(j)); - } - List> clusterResults = getClusters(route,locations); - if(clusterResults.isEmpty()) return Collections.emptyList(); + public List getRandomCluster(VehicleRoute route) { + if (route.isEmpty()) return Collections.emptyList(); + List locations = getLocationWrappers(route); + List> clusterResults = getClusters(route, locations); + if (clusterResults.isEmpty()) return Collections.emptyList(); Cluster randomCluster = RandomUtils.nextItem(clusterResults, random); return getJobList(randomCluster); } @@ -175,15 +185,15 @@ public class DBSCANClusterer { private double sample(VehicleRoutingTransportCosts costs, VehicleRoute r) { double min = Double.MAX_VALUE; double sum = 0; - for(int i=0;i getNearestNeighborsIterator(int nNeighbors, Job neighborTo); public void initialise(); + public double getMaxDistance(); + } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/JobNeighborhoodsFactory.java b/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/JobNeighborhoodsFactory.java index aa0cc4aa..691ede9e 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/JobNeighborhoodsFactory.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/JobNeighborhoodsFactory.java @@ -8,12 +8,12 @@ import jsprit.core.problem.VehicleRoutingProblem; */ public class JobNeighborhoodsFactory { - public JobNeighborhoods createNeighborhoods(VehicleRoutingProblem vrp, JobDistance jobDistance){ - return new JobNeighborhoodsImpl(vrp,jobDistance); + public JobNeighborhoods createNeighborhoods(VehicleRoutingProblem vrp, JobDistance jobDistance) { + return new JobNeighborhoodsImpl(vrp, jobDistance); } - public JobNeighborhoods createNeighborhoods(VehicleRoutingProblem vrp, JobDistance jobDistance, int capacity){ - return new JobNeighborhoodsImplWithCapRestriction(vrp,jobDistance,capacity); + public JobNeighborhoods createNeighborhoods(VehicleRoutingProblem vrp, JobDistance jobDistance, int capacity) { + return new JobNeighborhoodsImplWithCapRestriction(vrp, jobDistance, capacity); } } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/JobNeighborhoodsImpl.java b/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/JobNeighborhoodsImpl.java index b9ad9d5a..4bb0b043 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/JobNeighborhoodsImpl.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/JobNeighborhoodsImpl.java @@ -10,8 +10,8 @@ import org.apache.logging.log4j.Logger; import java.util.*; /** -* Created by schroeder on 07/01/15. -*/ + * Created by schroeder on 07/01/15. + */ class JobNeighborhoodsImpl implements JobNeighborhoods { private static Logger logger = LogManager.getLogger(JobNeighborhoodsImpl.class); @@ -22,17 +22,19 @@ class JobNeighborhoodsImpl implements JobNeighborhoods { private JobDistance jobDistance; + private double maxDistance = 0.; + public JobNeighborhoodsImpl(VehicleRoutingProblem vrp, JobDistance jobDistance) { super(); this.vrp = vrp; this.jobDistance = jobDistance; - logger.debug("intialise " + this); + logger.debug("intialise {}", this); } @Override - public Iterator getNearestNeighborsIterator(int nNeighbors, Job neighborTo){ + public Iterator getNearestNeighborsIterator(int nNeighbors, Job neighborTo) { TreeSet tree = distanceNodeTree.get(neighborTo.getId()); - if(tree == null) return new Iterator() { + if (tree == null) return new Iterator() { @Override public boolean hasNext() { return false; @@ -53,11 +55,16 @@ class JobNeighborhoodsImpl implements JobNeighborhoods { } @Override - public void initialise(){ + public void initialise() { logger.debug("calculates and memorizes distances from EACH job to EACH job --> n^2 calculations"); calculateDistancesFromJob2Job(); } + @Override + public double getMaxDistance() { + return 0; + } + private void calculateDistancesFromJob2Job() { logger.debug("preprocess distances between locations ..."); StopWatch stopWatch = new StopWatch(); @@ -65,20 +72,21 @@ class JobNeighborhoodsImpl implements JobNeighborhoods { int nuOfDistancesStored = 0; for (Job i : vrp.getJobs().values()) { TreeSet treeSet = new TreeSet( - new Comparator() { - @Override - public int compare(ReferencedJob o1, ReferencedJob o2) { - if (o1.getDistance() <= o2.getDistance()) { - return -1; - } else { - return 1; - } + new Comparator() { + @Override + public int compare(ReferencedJob o1, ReferencedJob o2) { + if (o1.getDistance() <= o2.getDistance()) { + return -1; + } else { + return 1; } - }); + } + }); distanceNodeTree.put(i.getId(), treeSet); for (Job j : vrp.getJobs().values()) { - if(i==j) continue; + if (i == j) continue; double distance = jobDistance.getDistance(i, j); + if (distance > maxDistance) maxDistance = distance; ReferencedJob refNode = new ReferencedJob(j, distance); treeSet.add(refNode); nuOfDistancesStored++; @@ -86,8 +94,8 @@ class JobNeighborhoodsImpl implements JobNeighborhoods { } stopWatch.stop(); - logger.debug("preprocessing comp-time: " + stopWatch + "; nuOfDistances stored: " + nuOfDistancesStored + "; estimated memory: " + - (distanceNodeTree.keySet().size()*64+nuOfDistancesStored*92) + " bytes"); + logger.debug("preprocessing comp-time: {}; nuOfDistances stored: {}; estimated memory: {}" + + " bytes", stopWatch, nuOfDistancesStored, (distanceNodeTree.keySet().size() * 64 + nuOfDistancesStored * 92)); } } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/JobNeighborhoodsImplWithCapRestriction.java b/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/JobNeighborhoodsImplWithCapRestriction.java index 1e8cf243..8288bc8e 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/JobNeighborhoodsImplWithCapRestriction.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/JobNeighborhoodsImplWithCapRestriction.java @@ -10,8 +10,8 @@ import org.apache.logging.log4j.Logger; import java.util.*; /** -* Created by schroeder on 07/01/15. -*/ + * Created by schroeder on 07/01/15. + */ class JobNeighborhoodsImplWithCapRestriction implements JobNeighborhoods { private static Logger logger = LogManager.getLogger(JobNeighborhoodsImpl.class); @@ -24,18 +24,20 @@ class JobNeighborhoodsImplWithCapRestriction implements JobNeighborhoods { private int capacity; + private double maxDistance = 0.; + public JobNeighborhoodsImplWithCapRestriction(VehicleRoutingProblem vrp, JobDistance jobDistance, int capacity) { super(); this.vrp = vrp; this.jobDistance = jobDistance; this.capacity = capacity; - logger.debug("intialise " + this); + logger.debug("initialize {}", this); } @Override - public Iterator getNearestNeighborsIterator(int nNeighbors, Job neighborTo){ + public Iterator getNearestNeighborsIterator(int nNeighbors, Job neighborTo) { TreeSet tree = distanceNodeTree.get(neighborTo.getId()); - if(tree == null) return new Iterator() { + if (tree == null) return new Iterator() { @Override public boolean hasNext() { @@ -58,12 +60,17 @@ class JobNeighborhoodsImplWithCapRestriction implements JobNeighborhoods { } @Override - public void initialise(){ - logger.debug("calculates distances from EACH job to EACH job --> n^2="+Math.pow(vrp.getJobs().values().size(), 2) + " calculations, but 'only' "+(vrp.getJobs().values().size()*capacity)+ " are cached."); - if(capacity==0) return; + public void initialise() { + logger.debug("calculates distances from EACH job to EACH job --> n^2={} calculations, but 'only' {} are cached.", Math.pow(vrp.getJobs().values().size(), 2), (vrp.getJobs().values().size() * capacity)); + if (capacity == 0) return; calculateDistancesFromJob2Job(); } + @Override + public double getMaxDistance() { + return maxDistance; + } + private void calculateDistancesFromJob2Job() { logger.debug("preprocess distances between locations ..."); StopWatch stopWatch = new StopWatch(); @@ -71,27 +78,27 @@ class JobNeighborhoodsImplWithCapRestriction implements JobNeighborhoods { int nuOfDistancesStored = 0; for (Job i : vrp.getJobs().values()) { TreeSet treeSet = new TreeSet( - new Comparator() { - @Override - public int compare(ReferencedJob o1, ReferencedJob o2) { - if (o1.getDistance() <= o2.getDistance()) { - return -1; - } else { - return 1; - } + new Comparator() { + @Override + public int compare(ReferencedJob o1, ReferencedJob o2) { + if (o1.getDistance() <= o2.getDistance()) { + return -1; + } else { + return 1; } - }); + } + }); distanceNodeTree.put(i.getId(), treeSet); for (Job j : vrp.getJobs().values()) { - if(i==j) continue; + if (i == j) continue; double distance = jobDistance.getDistance(i, j); + if (distance > maxDistance) maxDistance = distance; ReferencedJob refNode = new ReferencedJob(j, distance); - if(treeSet.size() < capacity){ + if (treeSet.size() < capacity) { treeSet.add(refNode); nuOfDistancesStored++; - } - else{ - if(treeSet.last().getDistance() > distance){ + } else { + if (treeSet.last().getDistance() > distance) { treeSet.pollLast(); treeSet.add(refNode); } @@ -101,13 +108,13 @@ class JobNeighborhoodsImplWithCapRestriction implements JobNeighborhoods { } stopWatch.stop(); - logger.debug("preprocessing comp-time: " + stopWatch + "; nuOfDistances stored: " + nuOfDistancesStored + "; estimated memory: " + - (distanceNodeTree.keySet().size()*64+nuOfDistancesStored*92) + " bytes"); + logger.debug("preprocessing comp-time: {}; nuOfDistances stored: {}; estimated memory: {}" + + " bytes", stopWatch, nuOfDistancesStored, (distanceNodeTree.keySet().size() * 64 + nuOfDistancesStored * 92)); } @Override public String toString() { - return "[name=neighborhoodWithCapRestriction][capacity="+capacity+"]"; + return "[name=neighborhoodWithCapRestriction][capacity=" + capacity + "]"; } } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/NearestNeighborhoodIterator.java b/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/NearestNeighborhoodIterator.java index 1542007a..1bc5515b 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/NearestNeighborhoodIterator.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/NearestNeighborhoodIterator.java @@ -7,8 +7,8 @@ import org.apache.logging.log4j.Logger; import java.util.Iterator; /** -* Created by schroeder on 07/01/15. -*/ + * Created by schroeder on 07/01/15. + */ class NearestNeighborhoodIterator implements Iterator { private static Logger log = LogManager.getLogger(NearestNeighborhoodIterator.class); @@ -27,9 +27,10 @@ class NearestNeighborhoodIterator implements Iterator { @Override public boolean hasNext() { - if(jobCount < nJobs){ + if (jobCount < nJobs) { boolean hasNext = jobIter.hasNext(); - if(!hasNext) log.warn("more jobs are requested then iterator can iterate over. probably the number of neighbors memorized in JobNeighborhoods is too small"); + if (!hasNext) + log.warn("more jobs are requested then iterator can iterate over. probably the number of neighbors memorized in JobNeighborhoods is too small"); return hasNext; } return false; diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/RadialRuinStrategyFactory.java b/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/RadialRuinStrategyFactory.java index f9702429..c6c6a7b0 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/RadialRuinStrategyFactory.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/RadialRuinStrategyFactory.java @@ -1,18 +1,18 @@ /******************************************************************************* * Copyright (c) 2014 Stefan Schroeder. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . - * + * * Contributors: * Stefan Schroeder - initial API and implementation ******************************************************************************/ @@ -21,21 +21,21 @@ package jsprit.core.algorithm.ruin; import jsprit.core.algorithm.ruin.distance.JobDistance; import jsprit.core.problem.VehicleRoutingProblem; -public class RadialRuinStrategyFactory implements RuinStrategyFactory{ +public class RadialRuinStrategyFactory implements RuinStrategyFactory { - private double fraction; - - private JobDistance jobDistance; - - public RadialRuinStrategyFactory(double fraction, JobDistance jobDistance) { - super(); - this.fraction = fraction; - this.jobDistance = jobDistance; - } + private double fraction; - @Override - public RuinStrategy createStrategy(VehicleRoutingProblem vrp) { - return new RuinRadial(vrp,fraction,jobDistance); - } + private JobDistance jobDistance; + + public RadialRuinStrategyFactory(double fraction, JobDistance jobDistance) { + super(); + this.fraction = fraction; + this.jobDistance = jobDistance; + } + + @Override + public RuinStrategy createStrategy(VehicleRoutingProblem vrp) { + return new RuinRadial(vrp, fraction, jobDistance); + } } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/RandomRuinStrategyFactory.java b/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/RandomRuinStrategyFactory.java index 32901aa9..44d64889 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/RandomRuinStrategyFactory.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/RandomRuinStrategyFactory.java @@ -1,18 +1,18 @@ /******************************************************************************* * Copyright (c) 2014 Stefan Schroeder. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . - * + * * Contributors: * Stefan Schroeder - initial API and implementation ******************************************************************************/ @@ -20,18 +20,18 @@ package jsprit.core.algorithm.ruin; import jsprit.core.problem.VehicleRoutingProblem; -public class RandomRuinStrategyFactory implements RuinStrategyFactory{ +public class RandomRuinStrategyFactory implements RuinStrategyFactory { - private double fraction; - - public RandomRuinStrategyFactory(double fraction) { - super(); - this.fraction = fraction; - } + private double fraction; - @Override - public RuinStrategy createStrategy(VehicleRoutingProblem vrp) { - return new RuinRandom(vrp, fraction); - } + public RandomRuinStrategyFactory(double fraction) { + super(); + this.fraction = fraction; + } + + @Override + public RuinStrategy createStrategy(VehicleRoutingProblem vrp) { + return new RuinRandom(vrp, fraction); + } } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/ReferencedJob.java b/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/ReferencedJob.java index 23a90973..7dc610fd 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/ReferencedJob.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/ReferencedJob.java @@ -3,8 +3,8 @@ package jsprit.core.algorithm.ruin; import jsprit.core.problem.job.Job; /** -* Created by schroeder on 07/01/15. -*/ + * Created by schroeder on 07/01/15. + */ class ReferencedJob { private Job job; private double distance; diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/RuinBreaks.java b/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/RuinBreaks.java new file mode 100644 index 00000000..912982d0 --- /dev/null +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/RuinBreaks.java @@ -0,0 +1,38 @@ +package jsprit.core.algorithm.ruin; + +import jsprit.core.algorithm.ruin.listener.RuinListener; +import jsprit.core.problem.job.Break; +import jsprit.core.problem.job.Job; +import jsprit.core.problem.solution.route.VehicleRoute; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.util.Collection; + +/** + * Created by schroeder on 04/08/15. + */ +public class RuinBreaks implements RuinListener { + + private final static Logger logger = LogManager.getLogger(); + + @Override + public void ruinStarts(Collection routes) { + } + + @Override + public void ruinEnds(Collection routes, Collection unassignedJobs) { + for (VehicleRoute r : routes) { + Break aBreak = r.getVehicle().getBreak(); + if (aBreak != null) { + r.getTourActivities().removeJob(aBreak); + logger.trace("ruin: {}", aBreak.getId()); + unassignedJobs.add(aBreak); + } + } + } + + @Override + public void removed(Job job, VehicleRoute fromRoute) { + } +} diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/RuinClusters.java b/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/RuinClusters.java index c12054ea..cdc7e349 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/RuinClusters.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/RuinClusters.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.ruin; @@ -33,159 +33,158 @@ import java.util.*; /** * Ruin strategy that ruins current solution randomly. I.e. * customer are removed randomly from current solution. - * + * * @author stefan schroeder - * */ public final class RuinClusters extends AbstractRuinStrategy implements IterationStartsListener { - @Override - public void informIterationStarts(int i, VehicleRoutingProblem problem, Collection solutions) { - minPts = 1 + random.nextInt(2); - epsFactor = 0.5 + random.nextDouble(); - } + @Override + public void informIterationStarts(int i, VehicleRoutingProblem problem, Collection solutions) { + minPts = 1 + random.nextInt(2); + epsFactor = 0.5 + random.nextDouble(); + } - public static class JobActivityWrapper implements Clusterable { + public static class JobActivityWrapper implements Clusterable { - private TourActivity.JobActivity jobActivity; + private TourActivity.JobActivity jobActivity; - public JobActivityWrapper(TourActivity.JobActivity jobActivity) { - this.jobActivity = jobActivity; - } + public JobActivityWrapper(TourActivity.JobActivity jobActivity) { + this.jobActivity = jobActivity; + } - @Override - public double[] getPoint() { - return new double[]{ jobActivity.getLocation().getCoordinate().getX(), jobActivity.getLocation().getCoordinate().getY() }; - } + @Override + public double[] getPoint() { + return new double[]{jobActivity.getLocation().getCoordinate().getX(), jobActivity.getLocation().getCoordinate().getY()}; + } - public TourActivity.JobActivity getActivity(){ - return jobActivity; - } - } + public TourActivity.JobActivity getActivity() { + return jobActivity; + } + } - private Logger logger = LogManager.getLogger(RuinClusters.class); + private Logger logger = LogManager.getLogger(RuinClusters.class); - private VehicleRoutingProblem vrp; + private VehicleRoutingProblem vrp; - private JobNeighborhoods jobNeighborhoods; + private JobNeighborhoods jobNeighborhoods; - private int noClusters = 2; + private int noClusters = 2; - private int minPts = 1; + private int minPts = 1; - private double epsFactor = 0.8; + private double epsFactor = 0.8; - public RuinClusters(VehicleRoutingProblem vrp, final int initialNumberJobsToRemove, JobNeighborhoods jobNeighborhoods) { - super(vrp); - this.vrp = vrp; - setRuinShareFactory(new RuinShareFactory() { - @Override - public int createNumberToBeRemoved() { - return initialNumberJobsToRemove; - } - }); - this.jobNeighborhoods = jobNeighborhoods; - logger.debug("initialise " + this); - } + public RuinClusters(VehicleRoutingProblem vrp, final int initialNumberJobsToRemove, JobNeighborhoods jobNeighborhoods) { + super(vrp); + this.vrp = vrp; + setRuinShareFactory(new RuinShareFactory() { + @Override + public int createNumberToBeRemoved() { + return initialNumberJobsToRemove; + } + }); + this.jobNeighborhoods = jobNeighborhoods; + logger.debug("initialise {}", this); + } - public void setNoClusters(int noClusters) { - this.noClusters = noClusters; - } + public void setNoClusters(int noClusters) { + this.noClusters = noClusters; + } - /** - * Removes a fraction of jobs from vehicleRoutes. - * - *

The number of jobs is calculated as follows: Math.ceil(vrp.getJobs().values().size() * fractionOfAllNodes2beRuined). - */ - @Override - public Collection ruinRoutes(Collection vehicleRoutes) { + /** + * Removes a fraction of jobs from vehicleRoutes. + *

+ *

The number of jobs is calculated as follows: Math.ceil(vrp.getJobs().values().size() * fractionOfAllNodes2beRuined). + */ + @Override + public Collection ruinRoutes(Collection vehicleRoutes) { List unassignedJobs = new ArrayList(); - int nOfJobs2BeRemoved = getRuinShareFactory().createNumberToBeRemoved(); - ruin(vehicleRoutes, nOfJobs2BeRemoved, unassignedJobs); + int nOfJobs2BeRemoved = getRuinShareFactory().createNumberToBeRemoved(); + ruin(vehicleRoutes, nOfJobs2BeRemoved, unassignedJobs); return unassignedJobs; - } + } - /** - * Removes nOfJobs2BeRemoved from vehicleRoutes, including targetJob. - */ - @Override - public Collection ruinRoutes(Collection vehicleRoutes, Job targetJob, int nOfJobs2BeRemoved) { + /** + * Removes nOfJobs2BeRemoved from vehicleRoutes, including targetJob. + */ + @Override + public Collection ruinRoutes(Collection vehicleRoutes, Job targetJob, int nOfJobs2BeRemoved) { throw new IllegalStateException("not supported"); - } + } - private void ruin(Collection vehicleRoutes, int nOfJobs2BeRemoved, List unassignedJobs) { - Map mappedRoutes = map(vehicleRoutes); - int toRemove = nOfJobs2BeRemoved; + private void ruin(Collection vehicleRoutes, int nOfJobs2BeRemoved, List unassignedJobs) { + if (vrp.getJobs().values().size() == 0) return; + Map mappedRoutes = map(vehicleRoutes); + int toRemove = nOfJobs2BeRemoved; - Collection lastRemoved = new ArrayList(); - Set ruined = new HashSet(); - Set removed = new HashSet(); - Set cycleCandidates = new HashSet(); - while(toRemove > 0) { - Job target; - VehicleRoute targetRoute = null; - if(lastRemoved.isEmpty()){ - target = RandomUtils.nextJob(vrp.getJobs().values(), random); - targetRoute = mappedRoutes.get(target); - } - else{ - target = RandomUtils.nextJob(lastRemoved, random); - Iterator neighborIterator = jobNeighborhoods.getNearestNeighborsIterator(nOfJobs2BeRemoved,target); - while(neighborIterator.hasNext()){ - Job j = neighborIterator.next(); - if(!removed.contains(j) && !ruined.contains(mappedRoutes.get(j))){ - targetRoute = mappedRoutes.get(j); - break; - } - } - lastRemoved.clear(); - } - if(targetRoute == null) break; - if(cycleCandidates.contains(targetRoute)) break; - if(ruined.contains(targetRoute)) { - cycleCandidates.add(targetRoute); - break; - } - DBSCANClusterer dbscan = new DBSCANClusterer(vrp.getTransportCosts()); - dbscan.setRandom(random); - dbscan.setMinPts(minPts); - dbscan.setEpsFactor(epsFactor); - List cluster = dbscan.getRandomCluster(targetRoute); - for(Job j : cluster){ - if(toRemove == 0) break; - if(removeJob(j, vehicleRoutes)) { - lastRemoved.add(j); - unassignedJobs.add(j); - } - toRemove--; - } - ruined.add(targetRoute); - } - } + Collection lastRemoved = new ArrayList(); + Set ruined = new HashSet(); + Set removed = new HashSet(); + Set cycleCandidates = new HashSet(); + while (toRemove > 0) { + Job target; + VehicleRoute targetRoute = null; + if (lastRemoved.isEmpty()) { + target = RandomUtils.nextJob(vrp.getJobs().values(), random); + targetRoute = mappedRoutes.get(target); + } else { + target = RandomUtils.nextJob(lastRemoved, random); + Iterator neighborIterator = jobNeighborhoods.getNearestNeighborsIterator(nOfJobs2BeRemoved, target); + while (neighborIterator.hasNext()) { + Job j = neighborIterator.next(); + if (!removed.contains(j) && !ruined.contains(mappedRoutes.get(j))) { + targetRoute = mappedRoutes.get(j); + break; + } + } + lastRemoved.clear(); + } + if (targetRoute == null) break; + if (cycleCandidates.contains(targetRoute)) break; + if (ruined.contains(targetRoute)) { + cycleCandidates.add(targetRoute); + break; + } + DBSCANClusterer dbscan = new DBSCANClusterer(vrp.getTransportCosts()); + dbscan.setRandom(random); + dbscan.setMinPts(minPts); + dbscan.setEpsFactor(epsFactor); + List cluster = dbscan.getRandomCluster(targetRoute); + for (Job j : cluster) { + if (toRemove == 0) break; + if (removeJob(j, vehicleRoutes)) { + lastRemoved.add(j); + unassignedJobs.add(j); + } + toRemove--; + } + ruined.add(targetRoute); + } + } - private List wrap(List activities) { - List wl = new ArrayList(); - for(TourActivity act : activities){ - wl.add(new JobActivityWrapper((TourActivity.JobActivity) act)); - } - return wl; - } + private List wrap(List activities) { + List wl = new ArrayList(); + for (TourActivity act : activities) { + wl.add(new JobActivityWrapper((TourActivity.JobActivity) act)); + } + return wl; + } - private Map map(Collection vehicleRoutes) { - Map map = new HashMap(vrp.getJobs().size()); - for(VehicleRoute r : vehicleRoutes){ - for(Job j : r.getTourActivities().getJobs()){ - map.put(j,r); - } - } - return map; - } + private Map map(Collection vehicleRoutes) { + Map map = new HashMap(vrp.getJobs().size()); + for (VehicleRoute r : vehicleRoutes) { + for (Job j : r.getTourActivities().getJobs()) { + map.put(j, r); + } + } + return map; + } - @Override - public String toString() { - return "[name=clusterRuin]"; - } + @Override + public String toString() { + return "[name=clusterRuin]"; + } } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/RuinRadial.java b/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/RuinRadial.java index de4ed294..792dcba6 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/RuinRadial.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/RuinRadial.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.ruin; @@ -28,124 +28,123 @@ import java.util.*; /** - * - * RuinStrategy that ruins the neighborhood of a randomly selected job. The size and the structure of the neighborhood is defined by - * the share of jobs to be removed and the distance between jobs (where distance not necessarily mean Euclidean distance but an arbitrary + * RuinStrategy that ruins the neighborhood of a randomly selected job. The size and the structure of the neighborhood is defined by + * the share of jobs to be removed and the distance between jobs (where distance not necessarily mean Euclidean distance but an arbitrary * measure). - * - * @author stefan * + * @author stefan */ public final class RuinRadial extends AbstractRuinStrategy { - - private Logger logger = LogManager.getLogger(RuinRadial.class); - private VehicleRoutingProblem vrp; + private Logger logger = LogManager.getLogger(RuinRadial.class); - private JobNeighborhoods jobNeighborhoods; + private VehicleRoutingProblem vrp; - private final int noJobsToMemorize; + private JobNeighborhoods jobNeighborhoods; - /** - * Constructs RuinRadial. - * - * @param vrp - * @param fraction2beRemoved i.e. the share of jobs to be removed (relative to the total number of jobs in vrp) - * @param jobDistance i.e. a measure to define the distance between two jobs and whether they are located close or distant to eachother - */ - public RuinRadial(VehicleRoutingProblem vrp, double fraction2beRemoved, JobDistance jobDistance) { - super(vrp); - this.vrp = vrp; - noJobsToMemorize = (int) Math.ceil(vrp.getJobs().values().size()*fraction2beRemoved); - ruinShareFactory = new RuinShareFactory() { + private final int noJobsToMemorize; - @Override - public int createNumberToBeRemoved() { - return noJobsToMemorize; - } + /** + * Constructs RuinRadial. + * + * @param vrp + * @param fraction2beRemoved i.e. the share of jobs to be removed (relative to the total number of jobs in vrp) + * @param jobDistance i.e. a measure to define the distance between two jobs and whether they are located close or distant to eachother + */ + public RuinRadial(VehicleRoutingProblem vrp, double fraction2beRemoved, JobDistance jobDistance) { + super(vrp); + this.vrp = vrp; + noJobsToMemorize = (int) Math.ceil(vrp.getJobs().values().size() * fraction2beRemoved); + ruinShareFactory = new RuinShareFactory() { - }; - JobNeighborhoodsImplWithCapRestriction jobNeighborhoodsImpl = new JobNeighborhoodsImplWithCapRestriction(vrp, jobDistance, noJobsToMemorize); - jobNeighborhoodsImpl.initialise(); - jobNeighborhoods = jobNeighborhoodsImpl; - logger.debug("initialise " + this); - } + @Override + public int createNumberToBeRemoved() { + return noJobsToMemorize; + } - public RuinRadial(VehicleRoutingProblem vrp, int noJobs2beRemoved, JobDistance jobDistance) { - super(vrp); - this.vrp = vrp; + }; + JobNeighborhoodsImplWithCapRestriction jobNeighborhoodsImpl = new JobNeighborhoodsImplWithCapRestriction(vrp, jobDistance, noJobsToMemorize); + jobNeighborhoodsImpl.initialise(); + jobNeighborhoods = jobNeighborhoodsImpl; + logger.debug("initialise {}", this); + } + + public RuinRadial(VehicleRoutingProblem vrp, int noJobs2beRemoved, JobDistance jobDistance) { + super(vrp); + this.vrp = vrp; // this.fractionOfAllNodes2beRuined = fraction2beRemoved; - noJobsToMemorize = noJobs2beRemoved; - ruinShareFactory = new RuinShareFactory() { + noJobsToMemorize = noJobs2beRemoved; + ruinShareFactory = new RuinShareFactory() { - @Override - public int createNumberToBeRemoved() { - return noJobsToMemorize; - } + @Override + public int createNumberToBeRemoved() { + return noJobsToMemorize; + } - }; - JobNeighborhoodsImplWithCapRestriction jobNeighborhoodsImpl = new JobNeighborhoodsImplWithCapRestriction(vrp, jobDistance, noJobsToMemorize); - jobNeighborhoodsImpl.initialise(); - jobNeighborhoods = jobNeighborhoodsImpl; - logger.debug("initialise " + this); - } + }; + JobNeighborhoodsImplWithCapRestriction jobNeighborhoodsImpl = new JobNeighborhoodsImplWithCapRestriction(vrp, jobDistance, noJobsToMemorize); + jobNeighborhoodsImpl.initialise(); + jobNeighborhoods = jobNeighborhoodsImpl; + logger.debug("initialise {}", this); + } - public RuinRadial(VehicleRoutingProblem vrp, int noJobs2beRemoved, JobNeighborhoods neighborhoods) { - super(vrp); - this.vrp = vrp; - noJobsToMemorize = noJobs2beRemoved; - ruinShareFactory = new RuinShareFactory() { + public RuinRadial(VehicleRoutingProblem vrp, int noJobs2beRemoved, JobNeighborhoods neighborhoods) { + super(vrp); + this.vrp = vrp; + noJobsToMemorize = noJobs2beRemoved; + ruinShareFactory = new RuinShareFactory() { - @Override - public int createNumberToBeRemoved() { - return noJobsToMemorize; - } + @Override + public int createNumberToBeRemoved() { + return noJobsToMemorize; + } - }; - jobNeighborhoods = neighborhoods; - logger.debug("initialise " + this); - } - - @Override - public String toString() { - return "[name=radialRuin][noJobsToBeRemoved="+noJobsToMemorize+"]"; - } + }; + jobNeighborhoods = neighborhoods; + logger.debug("initialise {}", this); + } - /** - * Ruins the collection of vehicleRoutes, i.e. removes a share of jobs. First, it selects a job randomly. Second, it identifies its neighborhood. And finally, it removes - * the neighborhood plus the randomly selected job from the number of vehicleRoutes. All removed jobs are then returned as a collection. - */ - @Override - public Collection ruinRoutes(Collection vehicleRoutes) { - if(vehicleRoutes.isEmpty()){ - return Collections.emptyList(); - } - int nOfJobs2BeRemoved = Math.min(ruinShareFactory.createNumberToBeRemoved(), noJobsToMemorize); - if (nOfJobs2BeRemoved == 0) { - return Collections.emptyList(); - } - Job randomJob = RandomUtils.nextJob(vrp.getJobs().values(),random); - return ruinRoutes(vehicleRoutes, randomJob, nOfJobs2BeRemoved); - } - - /** - * Removes targetJob and its neighborhood and returns the removed jobs. + @Override + public String toString() { + return "[name=radialRuin][noJobsToBeRemoved=" + noJobsToMemorize + "]"; + } + + /** + * Ruins the collection of vehicleRoutes, i.e. removes a share of jobs. First, it selects a job randomly. Second, it identifies its neighborhood. And finally, it removes + * the neighborhood plus the randomly selected job from the number of vehicleRoutes. All removed jobs are then returned as a collection. + */ + @Override + public Collection ruinRoutes(Collection vehicleRoutes) { + if (vehicleRoutes.isEmpty()) { + return Collections.emptyList(); + } + int nOfJobs2BeRemoved = Math.min(ruinShareFactory.createNumberToBeRemoved(), noJobsToMemorize); + if (nOfJobs2BeRemoved == 0) { + return Collections.emptyList(); + } + Job randomJob = RandomUtils.nextJob(vrp.getJobs().values(), random); + return ruinRoutes(vehicleRoutes, randomJob, nOfJobs2BeRemoved); + } + + /** + * Removes targetJob and its neighborhood and returns the removed jobs. + * * @deprecated will be private - */ + */ @Deprecated - public Collection ruinRoutes(Collection vehicleRoutes, Job targetJob, int nOfJobs2BeRemoved){ + public Collection ruinRoutes(Collection vehicleRoutes, Job targetJob, int nOfJobs2BeRemoved) { List unassignedJobs = new ArrayList(); - int nNeighbors = nOfJobs2BeRemoved - 1; - removeJob(targetJob,vehicleRoutes); - unassignedJobs.add(targetJob); - Iterator neighborhoodIterator = jobNeighborhoods.getNearestNeighborsIterator(nNeighbors, targetJob); - while(neighborhoodIterator.hasNext()){ - Job job = neighborhoodIterator.next(); - if(removeJob(job,vehicleRoutes)){ - unassignedJobs.add(job); - } - } + int nNeighbors = nOfJobs2BeRemoved - 1; + removeJob(targetJob, vehicleRoutes); + unassignedJobs.add(targetJob); + Iterator neighborhoodIterator = jobNeighborhoods.getNearestNeighborsIterator(nNeighbors, targetJob); + while (neighborhoodIterator.hasNext()) { + Job job = neighborhoodIterator.next(); + if (removeJob(job, vehicleRoutes)) { + unassignedJobs.add(job); + } + } return unassignedJobs; - } + } } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/RuinRadialMultipleCenters.java b/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/RuinRadialMultipleCenters.java index 8f10576d..26ce3e44 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/RuinRadialMultipleCenters.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/RuinRadialMultipleCenters.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.ruin; @@ -27,112 +27,110 @@ import java.util.*; /** - * - * RuinStrategy that ruins the neighborhood of a randomly selected job. The size and the structure of the neighborhood is defined by - * the share of jobs to be removed and the distance between jobs (where distance not necessarily mean Euclidean distance but an arbitrary + * RuinStrategy that ruins the neighborhood of a randomly selected job. The size and the structure of the neighborhood is defined by + * the share of jobs to be removed and the distance between jobs (where distance not necessarily mean Euclidean distance but an arbitrary * measure). - * - * @author stefan * + * @author stefan */ public final class RuinRadialMultipleCenters extends AbstractRuinStrategy { - private Logger logger = LogManager.getLogger(RuinRadialMultipleCenters.class); + private Logger logger = LogManager.getLogger(RuinRadialMultipleCenters.class); - private VehicleRoutingProblem vrp; + private VehicleRoutingProblem vrp; - private JobNeighborhoods jobNeighborhoods; + private JobNeighborhoods jobNeighborhoods; - private final int noJobsToMemorize; + private final int noJobsToMemorize; - private int noCenters = 1; + private int noCenters = 1; - public RuinRadialMultipleCenters(VehicleRoutingProblem vrp, int neighborhoodSize, JobDistance jobDistance) { - super(vrp); - this.vrp = vrp; - noJobsToMemorize = neighborhoodSize; - ruinShareFactory = new RuinShareFactory() { + public RuinRadialMultipleCenters(VehicleRoutingProblem vrp, int neighborhoodSize, JobDistance jobDistance) { + super(vrp); + this.vrp = vrp; + noJobsToMemorize = neighborhoodSize; + ruinShareFactory = new RuinShareFactory() { - @Override - public int createNumberToBeRemoved() { - return noJobsToMemorize; - } + @Override + public int createNumberToBeRemoved() { + return noJobsToMemorize; + } - }; - JobNeighborhoodsImplWithCapRestriction jobNeighborhoodsImpl = new JobNeighborhoodsImplWithCapRestriction(vrp, jobDistance, noJobsToMemorize); - jobNeighborhoodsImpl.initialise(); - jobNeighborhoods = jobNeighborhoodsImpl; - logger.debug("initialise " + this); - } + }; + JobNeighborhoodsImplWithCapRestriction jobNeighborhoodsImpl = new JobNeighborhoodsImplWithCapRestriction(vrp, jobDistance, noJobsToMemorize); + jobNeighborhoodsImpl.initialise(); + jobNeighborhoods = jobNeighborhoodsImpl; + logger.debug("initialise {}", this); + } - public void setNumberOfRuinCenters(int noCenters){ - this.noCenters = noCenters; - } - - @Override - public String toString() { - return "[name=radialRuin][noJobsToBeRemoved="+noJobsToMemorize+"]"; - } + public void setNumberOfRuinCenters(int noCenters) { + this.noCenters = noCenters; + } - /** - * Ruins the collection of vehicleRoutes, i.e. removes a share of jobs. First, it selects a job randomly. Second, it identifies its neighborhood. And finally, it removes - * the neighborhood plus the randomly selected job from the number of vehicleRoutes. All removed jobs are then returned as a collection. - */ - @Override - public Collection ruinRoutes(Collection vehicleRoutes) { - if(vehicleRoutes.isEmpty()){ - return Collections.emptyList(); - } - Set available = new HashSet(vrp.getJobs().values()); - Collection ruined = new ArrayList(); - for(int center=0;center ruinRoutes(Collection vehicleRoutes) { + if (vehicleRoutes.isEmpty()) { + return Collections.emptyList(); + } + Set available = new HashSet(vrp.getJobs().values()); + Collection ruined = new ArrayList(); + for (int center = 0; center < noCenters; center++) { + int nOfJobs2BeRemoved = ruinShareFactory.createNumberToBeRemoved(); + if (nOfJobs2BeRemoved == 0) { + return Collections.emptyList(); + } + Job randomJob = pickRandomJob(available); + if (randomJob != null) { + ruined.addAll(ruinRoutes_(vehicleRoutes, randomJob, nOfJobs2BeRemoved, available)); + } + } + return ruined; + } + + /** + * Removes targetJob and its neighborhood and returns the removed jobs. + * * @deprecated will be private - */ + */ @Deprecated - public Collection ruinRoutes(Collection vehicleRoutes, Job targetJob, int nOfJobs2BeRemoved){ - return ruinRoutes_(vehicleRoutes,targetJob,nOfJobs2BeRemoved,null); - } + public Collection ruinRoutes(Collection vehicleRoutes, Job targetJob, int nOfJobs2BeRemoved) { + return ruinRoutes_(vehicleRoutes, targetJob, nOfJobs2BeRemoved, null); + } - private Collection ruinRoutes_(Collection vehicleRoutes, Job targetJob, int nOfJobs2BeRemoved, Set available){ - List unassignedJobs = new ArrayList(); - int nNeighbors = nOfJobs2BeRemoved - 1; - removeJob(targetJob,vehicleRoutes); - unassignedJobs.add(targetJob); - Iterator neighborhoodIterator = jobNeighborhoods.getNearestNeighborsIterator(nNeighbors, targetJob); - while(neighborhoodIterator.hasNext()){ - Job job = neighborhoodIterator.next(); - if(available!=null) available.remove(job); - if(removeJob(job,vehicleRoutes)) { - unassignedJobs.add(job); - } - } - return unassignedJobs; - } + private Collection ruinRoutes_(Collection vehicleRoutes, Job targetJob, int nOfJobs2BeRemoved, Set available) { + List unassignedJobs = new ArrayList(); + int nNeighbors = nOfJobs2BeRemoved - 1; + removeJob(targetJob, vehicleRoutes); + unassignedJobs.add(targetJob); + Iterator neighborhoodIterator = jobNeighborhoods.getNearestNeighborsIterator(nNeighbors, targetJob); + while (neighborhoodIterator.hasNext()) { + Job job = neighborhoodIterator.next(); + if (available != null) available.remove(job); + if (removeJob(job, vehicleRoutes)) { + unassignedJobs.add(job); + } + } + return unassignedJobs; + } - private Job pickRandomJob(Set available) { - int randomIndex = random.nextInt(available.size()); - int i=0; - for(Job j : available){ - if(i>=randomIndex) { - return j; - } - else i++; - } - return null; + private Job pickRandomJob(Set available) { + int randomIndex = random.nextInt(available.size()); + int i = 0; + for (Job j : available) { + if (i >= randomIndex) { + return j; + } else i++; + } + return null; } } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/RuinRandom.java b/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/RuinRandom.java index acd0ee20..05de6fdb 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/RuinRandom.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/RuinRandom.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.ruin; @@ -31,80 +31,79 @@ import java.util.List; /** * Ruin strategy that ruins current solution randomly. I.e. * customer are removed randomly from current solution. - * + * * @author stefan schroeder - * */ public final class RuinRandom extends AbstractRuinStrategy { - - private Logger logger = LogManager.getLogger(RuinRandom.class); - private VehicleRoutingProblem vrp; + private Logger logger = LogManager.getLogger(RuinRandom.class); - private double fractionOfAllNodes2beRuined; + private VehicleRoutingProblem vrp; - /** - * Constructs ruinRandom. - * - * @param vrp - * @param fraction which is the fraction of total c - */ - public RuinRandom(VehicleRoutingProblem vrp, double fraction) { - super(vrp); - this.vrp = vrp; - this.fractionOfAllNodes2beRuined = fraction; - setRuinShareFactory(new RuinShareFactory() { - @Override - public int createNumberToBeRemoved() { - return selectNuOfJobs2BeRemoved(); - } - }); - logger.debug("initialise " + this); - } + private double fractionOfAllNodes2beRuined; - /** - * Removes a fraction of jobs from vehicleRoutes. - * - *

The number of jobs is calculated as follows: Math.ceil(vrp.getJobs().values().size() * fractionOfAllNodes2beRuined). - */ - @Override - public Collection ruinRoutes(Collection vehicleRoutes) { + /** + * Constructs ruinRandom. + * + * @param vrp + * @param fraction which is the fraction of total c + */ + public RuinRandom(VehicleRoutingProblem vrp, double fraction) { + super(vrp); + this.vrp = vrp; + this.fractionOfAllNodes2beRuined = fraction; + setRuinShareFactory(new RuinShareFactory() { + @Override + public int createNumberToBeRemoved() { + return selectNuOfJobs2BeRemoved(); + } + }); + logger.debug("initialise {}", this); + } + + /** + * Removes a fraction of jobs from vehicleRoutes. + *

+ *

The number of jobs is calculated as follows: Math.ceil(vrp.getJobs().values().size() * fractionOfAllNodes2beRuined). + */ + @Override + public Collection ruinRoutes(Collection vehicleRoutes) { List unassignedJobs = new ArrayList(); - int nOfJobs2BeRemoved = getRuinShareFactory().createNumberToBeRemoved(); - ruin(vehicleRoutes, nOfJobs2BeRemoved, unassignedJobs); + int nOfJobs2BeRemoved = getRuinShareFactory().createNumberToBeRemoved(); + ruin(vehicleRoutes, nOfJobs2BeRemoved, unassignedJobs); return unassignedJobs; - } + } - /** - * Removes nOfJobs2BeRemoved from vehicleRoutes, including targetJob. - */ - @Override - public Collection ruinRoutes(Collection vehicleRoutes, Job targetJob, int nOfJobs2BeRemoved) { + /** + * Removes nOfJobs2BeRemoved from vehicleRoutes, including targetJob. + */ + @Override + public Collection ruinRoutes(Collection vehicleRoutes, Job targetJob, int nOfJobs2BeRemoved) { throw new IllegalStateException("not supported"); - } + } - private void ruin(Collection vehicleRoutes, int nOfJobs2BeRemoved, List unassignedJobs) { - ArrayList availableJobs = new ArrayList(vrp.getJobs().values()); - Collections.shuffle(availableJobs,random); - int removed = 0; - for (Job job : availableJobs) { - if(removed == nOfJobs2BeRemoved) break; - if(removeJob(job,vehicleRoutes)) { - unassignedJobs.add(job); - } - removed++; - } - } + private void ruin(Collection vehicleRoutes, int nOfJobs2BeRemoved, List unassignedJobs) { + ArrayList availableJobs = new ArrayList(vrp.getJobs().values()); + Collections.shuffle(availableJobs, random); + int removed = 0; + for (Job job : availableJobs) { + if (removed == nOfJobs2BeRemoved) break; + if (removeJob(job, vehicleRoutes)) { + unassignedJobs.add(job); + } + removed++; + } + } - @Override - public String toString() { - return "[name=randomRuin][noJobsToBeRemoved="+selectNuOfJobs2BeRemoved()+"]"; - } + @Override + public String toString() { + return "[name=randomRuin][noJobsToBeRemoved=" + selectNuOfJobs2BeRemoved() + "]"; + } - private int selectNuOfJobs2BeRemoved() { - return (int) Math.ceil(vrp.getJobs().values().size() * fractionOfAllNodes2beRuined); - } + private int selectNuOfJobs2BeRemoved() { + return (int) Math.ceil(vrp.getJobs().values().size() * fractionOfAllNodes2beRuined); + } } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/RuinStrategy.java b/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/RuinStrategy.java index 88c35a74..e1435b00 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/RuinStrategy.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/RuinStrategy.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.ruin; @@ -23,41 +23,36 @@ import jsprit.core.problem.solution.route.VehicleRoute; import java.util.Collection; - - - /** - * * @author stefan schroeder - * */ public interface RuinStrategy { - - /** - * Ruins a current solution, i.e. a collection of vehicle-routes and - * returns a collection of removed and thus unassigned jobs. - * - * @param {@link VehicleRoute} - * @return Collection of {@link Job} - */ - public Collection ruin(Collection vehicleRoutes); - /** - * Removes targetJob as well as its neighbors with a size of (nOfJobs2BeRemoved-1). - */ + /** + * Ruins a current solution, i.e. a collection of vehicle-routes and + * returns a collection of removed and thus unassigned jobs. + * + * @param {@link VehicleRoute} + * @return Collection of {@link Job} + */ + public Collection ruin(Collection vehicleRoutes); + + /** + * Removes targetJob as well as its neighbors with a size of (nOfJobs2BeRemoved-1). + */ @Deprecated - public Collection ruin(Collection vehicleRoutes, Job targetJob, int nOfJobs2BeRemoved); - - /** - * Adds a ruin-listener. - * - * @param {@link RuinListener} - */ - public void addListener(RuinListener ruinListener); - - public void removeListener(RuinListener ruinListener); - - public Collection getListeners(); + public Collection ruin(Collection vehicleRoutes, Job targetJob, int nOfJobs2BeRemoved); + + /** + * Adds a ruin-listener. + * + * @param {@link RuinListener} + */ + public void addListener(RuinListener ruinListener); + + public void removeListener(RuinListener ruinListener); + + public Collection getListeners(); } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/RuinStrategyFactory.java b/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/RuinStrategyFactory.java index 21c1f1cf..d236213e 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/RuinStrategyFactory.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/RuinStrategyFactory.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.ruin; @@ -19,7 +19,7 @@ package jsprit.core.algorithm.ruin; import jsprit.core.problem.VehicleRoutingProblem; public interface RuinStrategyFactory { - - public RuinStrategy createStrategy(VehicleRoutingProblem vrp); + + public RuinStrategy createStrategy(VehicleRoutingProblem vrp); } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/RuinWorst.java b/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/RuinWorst.java index 971eb0d4..9bdae023 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/RuinWorst.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/RuinWorst.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.ruin; @@ -32,134 +32,131 @@ import java.util.*; /** * Ruin strategy that ruins current solution randomly. I.e. * customer are removed randomly from current solution. - * + * * @author stefan schroeder - * */ public final class RuinWorst extends AbstractRuinStrategy { - private Logger logger = LogManager.getLogger(RuinWorst.class); + private Logger logger = LogManager.getLogger(RuinWorst.class); - private VehicleRoutingProblem vrp; + private VehicleRoutingProblem vrp; - private NoiseMaker noiseMaker = new NoiseMaker(){ + private NoiseMaker noiseMaker = new NoiseMaker() { - @Override - public double makeNoise() { - return 0; - } - }; + @Override + public double makeNoise() { + return 0; + } + }; - public void setNoiseMaker(NoiseMaker noiseMaker) { - this.noiseMaker = noiseMaker; - } + public void setNoiseMaker(NoiseMaker noiseMaker) { + this.noiseMaker = noiseMaker; + } - public RuinWorst(VehicleRoutingProblem vrp, final int initialNumberJobsToRemove) { - super(vrp); - this.vrp = vrp; - setRuinShareFactory(new RuinShareFactory() { - @Override - public int createNumberToBeRemoved() { - return initialNumberJobsToRemove; - } - }); - logger.debug("initialise " + this); - } + public RuinWorst(VehicleRoutingProblem vrp, final int initialNumberJobsToRemove) { + super(vrp); + this.vrp = vrp; + setRuinShareFactory(new RuinShareFactory() { + @Override + public int createNumberToBeRemoved() { + return initialNumberJobsToRemove; + } + }); + logger.debug("initialise {}", this); + } - /** - * Removes a fraction of jobs from vehicleRoutes. - * - *

The number of jobs is calculated as follows: Math.ceil(vrp.getJobs().values().size() * fractionOfAllNodes2beRuined). - */ - @Override - public Collection ruinRoutes(Collection vehicleRoutes) { + /** + * Removes a fraction of jobs from vehicleRoutes. + *

+ *

The number of jobs is calculated as follows: Math.ceil(vrp.getJobs().values().size() * fractionOfAllNodes2beRuined). + */ + @Override + public Collection ruinRoutes(Collection vehicleRoutes) { List unassignedJobs = new ArrayList(); - int nOfJobs2BeRemoved = getRuinShareFactory().createNumberToBeRemoved(); - ruin(vehicleRoutes, nOfJobs2BeRemoved, unassignedJobs); + int nOfJobs2BeRemoved = getRuinShareFactory().createNumberToBeRemoved(); + ruin(vehicleRoutes, nOfJobs2BeRemoved, unassignedJobs); return unassignedJobs; - } + } - /** - * Removes nOfJobs2BeRemoved from vehicleRoutes, including targetJob. - */ - @Override - public Collection ruinRoutes(Collection vehicleRoutes, Job targetJob, int nOfJobs2BeRemoved) { + /** + * Removes nOfJobs2BeRemoved from vehicleRoutes, including targetJob. + */ + @Override + public Collection ruinRoutes(Collection vehicleRoutes, Job targetJob, int nOfJobs2BeRemoved) { throw new UnsupportedOperationException("ruinRoutes not supported"); - } + } - private void ruin(Collection vehicleRoutes, int nOfJobs2BeRemoved, List unassignedJobs) { - LinkedList availableJobs = new LinkedList(vrp.getJobs().values()); - int toRemove = nOfJobs2BeRemoved; - while(toRemove > 0){ - Job worst = getWorst(vehicleRoutes); - if(worst == null) break; - if(removeJob(worst,vehicleRoutes)) { - availableJobs.remove(worst); - unassignedJobs.add(worst); - } - toRemove--; - } - } + private void ruin(Collection vehicleRoutes, int nOfJobs2BeRemoved, List unassignedJobs) { + LinkedList availableJobs = new LinkedList(vrp.getJobs().values()); + int toRemove = nOfJobs2BeRemoved; + while (toRemove > 0) { + Job worst = getWorst(vehicleRoutes); + if (worst == null) break; + if (removeJob(worst, vehicleRoutes)) { + availableJobs.remove(worst); + unassignedJobs.add(worst); + } + toRemove--; + } + } - private Job getWorst(Collection copied) { - Job worst = null; - double bestSavings = Double.MIN_VALUE; + private Job getWorst(Collection copied) { + Job worst = null; + double bestSavings = Double.MIN_VALUE; - for(VehicleRoute route : copied) { - if(route.isEmpty()) continue; - Map savingsMap = new HashMap(); - TourActivity actBefore = route.getStart(); - TourActivity actToEval = null; - for (TourActivity act : route.getActivities()) { - if (actToEval == null) { - actToEval = act; - continue; - } - double savings = savings(route, actBefore, actToEval, act); - Job job = ((TourActivity.JobActivity) actToEval).getJob(); - if(!savingsMap.containsKey(job)){ - savingsMap.put(job,savings); - } - else { - double s = savingsMap.get(job); - savingsMap.put(job,s+savings); - } - actBefore = actToEval; - actToEval = act; - } - double savings = savings(route, actBefore, actToEval, route.getEnd()); - Job job = ((TourActivity.JobActivity) actToEval).getJob(); - if(!savingsMap.containsKey(job)){ - savingsMap.put(job,savings); - } - else { - double s = savingsMap.get(job); - savingsMap.put(job,s+savings); - } - //getCounts best - for(Job j : savingsMap.keySet()){ - if(savingsMap.get(j) > bestSavings){ - bestSavings = savingsMap.get(j); - worst = j; - } - } - } - return worst; - } + for (VehicleRoute route : copied) { + if (route.isEmpty()) continue; + Map savingsMap = new HashMap(); + TourActivity actBefore = route.getStart(); + TourActivity actToEval = null; + for (TourActivity act : route.getActivities()) { + if (actToEval == null) { + actToEval = act; + continue; + } + double savings = savings(route, actBefore, actToEval, act); + Job job = ((TourActivity.JobActivity) actToEval).getJob(); + if (!savingsMap.containsKey(job)) { + savingsMap.put(job, savings); + } else { + double s = savingsMap.get(job); + savingsMap.put(job, s + savings); + } + actBefore = actToEval; + actToEval = act; + } + double savings = savings(route, actBefore, actToEval, route.getEnd()); + Job job = ((TourActivity.JobActivity) actToEval).getJob(); + if (!savingsMap.containsKey(job)) { + savingsMap.put(job, savings); + } else { + double s = savingsMap.get(job); + savingsMap.put(job, s + savings); + } + //getCounts best + for (Job j : savingsMap.keySet()) { + if (savingsMap.get(j) > bestSavings) { + bestSavings = savingsMap.get(j); + worst = j; + } + } + } + return worst; + } - private double savings(VehicleRoute route, TourActivity actBefore, TourActivity actToEval, TourActivity act) { - double savings = c(actBefore, actToEval, route.getVehicle()) + c(actToEval, act, route.getVehicle()) - c(actBefore, act, route.getVehicle()); - return Math.max(0,savings + noiseMaker.makeNoise()); - } + private double savings(VehicleRoute route, TourActivity actBefore, TourActivity actToEval, TourActivity act) { + double savings = c(actBefore, actToEval, route.getVehicle()) + c(actToEval, act, route.getVehicle()) - c(actBefore, act, route.getVehicle()); + return Math.max(0, savings + noiseMaker.makeNoise()); + } - private double c(TourActivity from, TourActivity to, Vehicle vehicle) { - return vrp.getTransportCosts().getTransportCost(from.getLocation(),to.getLocation(),from.getEndTime(), DriverImpl.noDriver(), vehicle); - } + private double c(TourActivity from, TourActivity to, Vehicle vehicle) { + return vrp.getTransportCosts().getTransportCost(from.getLocation(), to.getLocation(), from.getEndTime(), DriverImpl.noDriver(), vehicle); + } - @Override - public String toString() { - return "[name=worstRuin]"; - } + @Override + public String toString() { + return "[name=worstRuin]"; + } } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/distance/AvgServiceAndShipmentDistance.java b/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/distance/AvgServiceAndShipmentDistance.java index d0da5512..908eb4e3 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/distance/AvgServiceAndShipmentDistance.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/distance/AvgServiceAndShipmentDistance.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.ruin.distance; @@ -24,76 +24,69 @@ import jsprit.core.problem.job.Shipment; import jsprit.core.util.EuclideanDistanceCalculator; - /** * Calculator that calculates average distance between two jobs based on the input-transport costs. - * + *

*

If the distance between two jobs cannot be calculated with input-transport costs, it tries the euclidean distance between these jobs. - * - * @author stefan schroeder * + * @author stefan schroeder */ public class AvgServiceAndShipmentDistance implements JobDistance { - private VehicleRoutingTransportCosts costs; + private VehicleRoutingTransportCosts costs; - public AvgServiceAndShipmentDistance(VehicleRoutingTransportCosts costs) { - super(); - this.costs = costs; + public AvgServiceAndShipmentDistance(VehicleRoutingTransportCosts costs) { + super(); + this.costs = costs; - } + } - /** - * Calculates and returns the average distance between two jobs based on the input-transport costs. - * - *

If the distance between two jobs cannot be calculated with input-transport costs, it tries the euclidean distance between these jobs. - */ - @Override - public double getDistance(Job i, Job j) { - if (i.equals(j)) return 0.0; + /** + * Calculates and returns the average distance between two jobs based on the input-transport costs. + *

+ *

If the distance between two jobs cannot be calculated with input-transport costs, it tries the euclidean distance between these jobs. + */ + @Override + public double getDistance(Job i, Job j) { + if (i.equals(j)) return 0.0; - if (i instanceof Service && j instanceof Service) { - return calcDist((Service)i, (Service)j); - } - else if(i instanceof Service && j instanceof Shipment){ - return calcDist((Service)i,(Shipment)j); - } - else if(i instanceof Shipment && j instanceof Service){ - return calcDist((Service)j,(Shipment)i); - } - else if(i instanceof Shipment && j instanceof Shipment){ - return calcDist((Shipment)i,(Shipment)j); - } - else{ - throw new IllegalStateException("this supports only shipments or services"); - } - } - - private double calcDist(Service i, Service j) { - return calcDist(i.getLocation(),j.getLocation()); - } - - private double calcDist(Service i, Shipment j) { - double c_ij1 = calcDist(i.getLocation(),j.getPickupLocation()); - double c_ij2 = calcDist(i.getLocation(),j.getDeliveryLocation()); - return (c_ij1 + c_ij2)/2.0; - } - - private double calcDist(Shipment i, Shipment j) { - double c_i1j1 = calcDist(i.getPickupLocation(),j.getPickupLocation()); - double c_i1j2 = calcDist(i.getPickupLocation(),j.getDeliveryLocation()); - double c_i2j1 = calcDist(i.getDeliveryLocation(),j.getPickupLocation()); - double c_i2j2 = calcDist(i.getDeliveryLocation(),j.getDeliveryLocation()); - return (c_i1j1 + c_i1j2 + c_i2j1 + c_i2j2)/4.0; - } - - private double calcDist(Location location_i, Location location_j){ - try{ - return costs.getTransportCost(location_i, location_j, 0.0, null, null); + if (i instanceof Service && j instanceof Service) { + return calcDist((Service) i, (Service) j); + } else if (i instanceof Service && j instanceof Shipment) { + return calcDist((Service) i, (Shipment) j); + } else if (i instanceof Shipment && j instanceof Service) { + return calcDist((Service) j, (Shipment) i); + } else if (i instanceof Shipment && j instanceof Shipment) { + return calcDist((Shipment) i, (Shipment) j); + } else { + throw new IllegalStateException("this supports only shipments or services"); } - catch(IllegalStateException e){ - // now try the euclidean distance between these two services - } - return EuclideanDistanceCalculator.calculateDistance(location_i.getCoordinate(), location_j.getCoordinate()); - } + } + + private double calcDist(Service i, Service j) { + return calcDist(i.getLocation(), j.getLocation()); + } + + private double calcDist(Service i, Shipment j) { + double c_ij1 = calcDist(i.getLocation(), j.getPickupLocation()); + double c_ij2 = calcDist(i.getLocation(), j.getDeliveryLocation()); + return (c_ij1 + c_ij2) / 2.0; + } + + private double calcDist(Shipment i, Shipment j) { + double c_i1j1 = calcDist(i.getPickupLocation(), j.getPickupLocation()); + double c_i1j2 = calcDist(i.getPickupLocation(), j.getDeliveryLocation()); + double c_i2j1 = calcDist(i.getDeliveryLocation(), j.getPickupLocation()); + double c_i2j2 = calcDist(i.getDeliveryLocation(), j.getDeliveryLocation()); + return (c_i1j1 + c_i1j2 + c_i2j1 + c_i2j2) / 4.0; + } + + private double calcDist(Location location_i, Location location_j) { + try { + return costs.getTransportCost(location_i, location_j, 0.0, null, null); + } catch (IllegalStateException e) { + // now try the euclidean distance between these two services + } + return EuclideanDistanceCalculator.calculateDistance(location_i.getCoordinate(), location_j.getCoordinate()); + } } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/distance/AvgServiceDistance.java b/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/distance/AvgServiceDistance.java index f9aa529d..f05c4712 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/distance/AvgServiceDistance.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/distance/AvgServiceDistance.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.ruin.distance; @@ -21,60 +21,57 @@ import jsprit.core.problem.job.Job; import jsprit.core.problem.job.Service; - /** * Calculator that calculates average distance between two jobs based on the input-transport costs. - * + *

*

If the distance between two jobs cannot be calculated with input-transport costs, it tries the euclidean distance between these jobs. - * - * @author stefan schroeder * + * @author stefan schroeder */ public class AvgServiceDistance implements JobDistance { - private VehicleRoutingTransportCosts costs; + private VehicleRoutingTransportCosts costs; - public AvgServiceDistance(VehicleRoutingTransportCosts costs) { - super(); - this.costs = costs; + public AvgServiceDistance(VehicleRoutingTransportCosts costs) { + super(); + this.costs = costs; - } + } - /** - * Calculates and returns the average distance between two jobs based on the input-transport costs. - * - *

If the distance between two jobs cannot be calculated with input-transport costs, it tries the euclidean distance between these jobs. - */ - @Override - public double getDistance(Job i, Job j) { - double avgCost = 0.0; - if (i instanceof Service && j instanceof Service) { - if (i.equals(j)) { - avgCost = 0.0; - } else { - Service s_i = (Service) i; - Service s_j = (Service) j; - avgCost = calcDist(s_i, s_j); - } - } else { - throw new UnsupportedOperationException( - "currently, this class just works services."); - } - return avgCost; - } + /** + * Calculates and returns the average distance between two jobs based on the input-transport costs. + *

+ *

If the distance between two jobs cannot be calculated with input-transport costs, it tries the euclidean distance between these jobs. + */ + @Override + public double getDistance(Job i, Job j) { + double avgCost = 0.0; + if (i instanceof Service && j instanceof Service) { + if (i.equals(j)) { + avgCost = 0.0; + } else { + Service s_i = (Service) i; + Service s_j = (Service) j; + avgCost = calcDist(s_i, s_j); + } + } else { + throw new UnsupportedOperationException( + "currently, this class just works services."); + } + return avgCost; + } - private double calcDist(Service s_i, Service s_j) { - double distance; - try{ - distance = costs.getTransportCost(s_i.getLocation(), s_j.getLocation(), 0.0, null, null); - return distance; - } - catch(IllegalStateException e){ - // now try the euclidean distance between these two services - } - EuclideanServiceDistance euclidean = new EuclideanServiceDistance(); - distance = euclidean.getDistance(s_i, s_j); - return distance; - } + private double calcDist(Service s_i, Service s_j) { + double distance; + try { + distance = costs.getTransportCost(s_i.getLocation(), s_j.getLocation(), 0.0, null, null); + return distance; + } catch (IllegalStateException e) { + // now try the euclidean distance between these two services + } + EuclideanServiceDistance euclidean = new EuclideanServiceDistance(); + distance = euclidean.getDistance(s_i, s_j); + return distance; + } } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/distance/EuclideanServiceDistance.java b/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/distance/EuclideanServiceDistance.java index 659b8d10..29cff947 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/distance/EuclideanServiceDistance.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/distance/EuclideanServiceDistance.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.ruin.distance; @@ -22,27 +22,28 @@ import jsprit.core.util.EuclideanDistanceCalculator; public class EuclideanServiceDistance implements JobDistance { - public EuclideanServiceDistance() { - super(); - } + public EuclideanServiceDistance() { + super(); + } - @Override - public double getDistance(Job i, Job j) { - double avgCost = 0.0; - if (i instanceof Service && j instanceof Service) { - if (i.equals(j)) { - avgCost = 0.0; - } else { - Service s_i = (Service) i; - Service s_j = (Service) j; - if(s_i.getLocation().getCoordinate() == null || s_j.getLocation().getCoordinate() == null) throw new IllegalStateException("cannot calculate euclidean distance. since service coords are missing"); - avgCost = EuclideanDistanceCalculator.calculateDistance(s_i.getLocation().getCoordinate(), s_j.getLocation().getCoordinate()); - } - } else { - throw new UnsupportedOperationException( - "currently, this class just works with shipments and services."); - } - return avgCost; - } + @Override + public double getDistance(Job i, Job j) { + double avgCost = 0.0; + if (i instanceof Service && j instanceof Service) { + if (i.equals(j)) { + avgCost = 0.0; + } else { + Service s_i = (Service) i; + Service s_j = (Service) j; + if (s_i.getLocation().getCoordinate() == null || s_j.getLocation().getCoordinate() == null) + throw new IllegalStateException("cannot calculate euclidean distance. since service coords are missing"); + avgCost = EuclideanDistanceCalculator.calculateDistance(s_i.getLocation().getCoordinate(), s_j.getLocation().getCoordinate()); + } + } else { + throw new UnsupportedOperationException( + "currently, this class just works with shipments and services."); + } + return avgCost; + } } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/distance/JobDistance.java b/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/distance/JobDistance.java index 45b4428b..c8364bf5 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/distance/JobDistance.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/distance/JobDistance.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.ruin.distance; @@ -19,9 +19,8 @@ package jsprit.core.algorithm.ruin.distance; import jsprit.core.problem.job.Job; - public interface JobDistance { - public double getDistance(Job i, Job j); + public double getDistance(Job i, Job j); } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/listener/RuinListener.java b/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/listener/RuinListener.java index bbb150d4..c01834c7 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/listener/RuinListener.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/listener/RuinListener.java @@ -1,18 +1,18 @@ /******************************************************************************* * Copyright (c) 2014 Stefan Schroeder. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . - * + * * Contributors: * Stefan Schroeder - initial API and implementation ******************************************************************************/ @@ -27,33 +27,32 @@ import java.util.Collection; /** * Listener that listens to the ruin-process. It informs whoever is interested about start, end and about a removal of a job. - * - * @author schroeder * + * @author schroeder */ -public interface RuinListener extends SearchStrategyModuleListener{ - - /** - * informs about ruin-start. - * - * @param routes - */ - public void ruinStarts(Collection routes); - - /** - * informs about ruin-end. - * - * @param routes - * @param unassignedJobs - */ - public void ruinEnds(Collection routes, Collection unassignedJobs); - - /** - * informs if a {@link Job} has been removed from a {@link VehicleRoute}. - * - * @param job - * @param fromRoute - */ - public void removed(Job job, VehicleRoute fromRoute); - +public interface RuinListener extends SearchStrategyModuleListener { + + /** + * informs about ruin-start. + * + * @param routes + */ + public void ruinStarts(Collection routes); + + /** + * informs about ruin-end. + * + * @param routes + * @param unassignedJobs + */ + public void ruinEnds(Collection routes, Collection unassignedJobs); + + /** + * informs if a {@link Job} has been removed from a {@link VehicleRoute}. + * + * @param job + * @param fromRoute + */ + public void removed(Job job, VehicleRoute fromRoute); + } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/listener/RuinListeners.java b/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/listener/RuinListeners.java index e028da64..56e5d65a 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/listener/RuinListeners.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/ruin/listener/RuinListeners.java @@ -1,4 +1,3 @@ - /******************************************************************************* * Copyright (C) 2014 Stefan Schroeder * @@ -27,30 +26,30 @@ import java.util.Collections; public class RuinListeners { - - private Collection ruinListeners = new ArrayList(); - public void ruinStarts(Collection routes){ - for(RuinListener l : ruinListeners) l.ruinStarts(routes); - } - - public void ruinEnds(Collection routes, Collection unassignedJobs){ - for(RuinListener l : ruinListeners) l.ruinEnds(routes, unassignedJobs); - } - - public void removed(Job job, VehicleRoute fromRoute){ - for(RuinListener l : ruinListeners) l.removed(job, fromRoute); - } - - public void addListener(RuinListener ruinListener){ - ruinListeners.add(ruinListener); - } - - public void removeListener(RuinListener ruinListener){ - ruinListeners.remove(ruinListener); - } - - public Collection getListeners(){ - return Collections.unmodifiableCollection(ruinListeners); - } + private Collection ruinListeners = new ArrayList(); + + public void ruinStarts(Collection routes) { + for (RuinListener l : ruinListeners) l.ruinStarts(routes); + } + + public void ruinEnds(Collection routes, Collection unassignedJobs) { + for (RuinListener l : ruinListeners) l.ruinEnds(routes, unassignedJobs); + } + + public void removed(Job job, VehicleRoute fromRoute) { + for (RuinListener l : ruinListeners) l.removed(job, fromRoute); + } + + public void addListener(RuinListener ruinListener) { + ruinListeners.add(ruinListener); + } + + public void removeListener(RuinListener ruinListener) { + ruinListeners.remove(ruinListener); + } + + public Collection getListeners() { + return Collections.unmodifiableCollection(ruinListeners); + } } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/selector/SelectBest.java b/jsprit-core/src/main/java/jsprit/core/algorithm/selector/SelectBest.java index 506b3e01..da77d346 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/selector/SelectBest.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/selector/SelectBest.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.selector; @@ -21,41 +21,37 @@ import jsprit.core.problem.solution.VehicleRoutingProblemSolution; import java.util.Collection; +public class SelectBest implements SolutionSelector { + private static SelectBest selector = null; + public static SelectBest getInstance() { + if (selector == null) { + selector = new SelectBest(); + return selector; + } + return selector; + } -public class SelectBest implements SolutionSelector{ + @Override + public VehicleRoutingProblemSolution selectSolution(Collection solutions) { + double minCost = Double.MAX_VALUE; + VehicleRoutingProblemSolution bestSolution = null; + for (VehicleRoutingProblemSolution sol : solutions) { + if (bestSolution == null) { + bestSolution = sol; + minCost = sol.getCost(); + } else if (sol.getCost() < minCost) { + bestSolution = sol; + minCost = sol.getCost(); + } + } + return bestSolution; + } - private static SelectBest selector = null; - - public static SelectBest getInstance(){ - if(selector == null){ - selector = new SelectBest(); - return selector; - } - return selector; - } - - @Override - public VehicleRoutingProblemSolution selectSolution(Collection solutions) { - double minCost = Double.MAX_VALUE; - VehicleRoutingProblemSolution bestSolution = null; - for(VehicleRoutingProblemSolution sol : solutions){ - if(bestSolution == null){ - bestSolution = sol; - minCost = sol.getCost(); - } - else if(sol.getCost() < minCost){ - bestSolution = sol; - minCost = sol.getCost(); - } - } - return bestSolution; - } - - @Override - public String toString() { - return "[name=selectBest]"; - } + @Override + public String toString() { + return "[name=selectBest]"; + } } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/selector/SelectRandomly.java b/jsprit-core/src/main/java/jsprit/core/algorithm/selector/SelectRandomly.java index d32dbc26..b61277c2 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/selector/SelectRandomly.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/selector/SelectRandomly.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.selector; @@ -25,32 +25,30 @@ import java.util.List; import java.util.Random; +public class SelectRandomly implements SolutionSelector { + private static SelectRandomly selector = null; -public class SelectRandomly implements SolutionSelector{ + public static SelectRandomly getInstance() { + if (selector == null) { + selector = new SelectRandomly(); + return selector; + } + return selector; + } - private static SelectRandomly selector = null; - - public static SelectRandomly getInstance(){ - if(selector == null){ - selector = new SelectRandomly(); - return selector; - } - return selector; - } - - private Random random = RandomNumberGeneration.getRandom(); - - @Override - public VehicleRoutingProblemSolution selectSolution(Collection solutions) { - if(solutions.isEmpty()) return null; - List solList = new ArrayList(solutions); - int randomIndex = random.nextInt(solutions.size()); - return solList.get(randomIndex); - } + private Random random = RandomNumberGeneration.getRandom(); - public void setRandom(Random random) { - this.random = random; - } + @Override + public VehicleRoutingProblemSolution selectSolution(Collection solutions) { + if (solutions.isEmpty()) return null; + List solList = new ArrayList(solutions); + int randomIndex = random.nextInt(solutions.size()); + return solList.get(randomIndex); + } + + public void setRandom(Random random) { + this.random = random; + } } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/selector/SolutionSelector.java b/jsprit-core/src/main/java/jsprit/core/algorithm/selector/SolutionSelector.java index 5a912921..cfc95110 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/selector/SolutionSelector.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/selector/SolutionSelector.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.selector; @@ -21,9 +21,8 @@ import jsprit.core.problem.solution.VehicleRoutingProblemSolution; import java.util.Collection; - public interface SolutionSelector { - - public VehicleRoutingProblemSolution selectSolution(Collection solutions); + + public VehicleRoutingProblemSolution selectSolution(Collection solutions); } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/state/InternalStates.java b/jsprit-core/src/main/java/jsprit/core/algorithm/state/InternalStates.java index ae8336d0..45d5efc1 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/state/InternalStates.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/state/InternalStates.java @@ -1,4 +1,3 @@ - /******************************************************************************* * Copyright (C) 2014 Stefan Schroeder * @@ -22,24 +21,34 @@ public class InternalStates { public final static StateId MAXLOAD = new StateFactory.StateIdImpl("max_load", 0); - - public final static StateId LOAD = new StateFactory.StateIdImpl("load", 1); - - public final static StateId COSTS = new StateFactory.StateIdImpl("costs", 2); - - public final static StateId LOAD_AT_BEGINNING = new StateFactory.StateIdImpl("load_at_beginning", 3); - - public final static StateId LOAD_AT_END = new StateFactory.StateIdImpl("load_at_end", 4); - - public final static StateId DURATION = new StateFactory.StateIdImpl("duration", 5); - - public final static StateId LATEST_OPERATION_START_TIME = new StateFactory.StateIdImpl("latest_operation_start_time", 6); - - public final static StateId EARLIEST_OPERATION_START_TIME = new StateFactory.StateIdImpl("earliest_operation_start_time", 7); - - public final static StateId FUTURE_MAXLOAD = new StateFactory.StateIdImpl("future_max_load", 8); - - public final static StateId PAST_MAXLOAD = new StateFactory.StateIdImpl("past_max_load", 9); + + public final static StateId LOAD = new StateFactory.StateIdImpl("load", 1); + + public final static StateId COSTS = new StateFactory.StateIdImpl("costs", 2); + + public final static StateId LOAD_AT_BEGINNING = new StateFactory.StateIdImpl("load_at_beginning", 3); + + public final static StateId LOAD_AT_END = new StateFactory.StateIdImpl("load_at_end", 4); + + public final static StateId DURATION = new StateFactory.StateIdImpl("duration", 5); + + public final static StateId LATEST_OPERATION_START_TIME = new StateFactory.StateIdImpl("latest_operation_start_time", 6); + + public final static StateId EARLIEST_OPERATION_START_TIME = new StateFactory.StateIdImpl("earliest_operation_start_time", 7); + + public final static StateId FUTURE_MAXLOAD = new StateFactory.StateIdImpl("future_max_load", 8); + + public final static StateId PAST_MAXLOAD = new StateFactory.StateIdImpl("past_max_load", 9); public static final StateId SKILLS = new StateFactory.StateIdImpl("skills", 10); + + public static final StateId WAITING = new StateFactory.StateIdImpl("waiting", 11); + + public static final StateId TIME_SLACK = new StateFactory.StateIdImpl("time_slack", 12); + + public static final StateId FUTURE_WAITING = new StateFactory.StateIdImpl("future_waiting", 13); + + public static final StateId EARLIEST_WITHOUT_WAITING = new StateFactory.StateIdImpl("earliest_without_waiting", 14); + + public static final StateId SWITCH_NOT_FEASIBLE = new StateFactory.StateIdImpl("switch_not_feasible", 15); } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/state/StateFactory.java b/jsprit-core/src/main/java/jsprit/core/algorithm/state/StateFactory.java index 0f17777f..cf7e0172 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/state/StateFactory.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/state/StateFactory.java @@ -9,26 +9,28 @@ import java.util.List; class StateFactory { final static List reservedIds = Arrays.asList("max_load", "load", "costs", "load_at_beginning", "load_at_end", "duration", "latest_operation_start_time", "earliest_operation_start_time" - , "future_max_load", "past_max_load", "skills"); + , "future_max_load", "past_max_load", "skills"); - static StateId createId(String name){ - if(reservedIds.contains(name)){ throwReservedIdException(name); } + static StateId createId(String name) { + if (reservedIds.contains(name)) { + throwReservedIdException(name); + } return new StateIdImpl(name, -1); } - static StateId createId(String name, int index){ - if(reservedIds.contains(name)) throwReservedIdException(name); - if(index < 10) throwReservedIdException(name); + static StateId createId(String name, int index) { + if (reservedIds.contains(name)) throwReservedIdException(name); + if (index < 10) throwReservedIdException(name); return new StateIdImpl(name, index); } - static boolean isReservedId(String stateId){ + static boolean isReservedId(String stateId) { return reservedIds.contains(stateId); } - static boolean isReservedId(StateId stateId){ + static boolean isReservedId(StateId stateId) { return reservedIds.contains(stateId.toString()); } @@ -41,7 +43,9 @@ class StateFactory { private int index; - public int getIndex(){ return index; } + public int getIndex() { + return index; + } /* (non-Javadoc) * @see java.lang.Object#hashCode() @@ -82,7 +86,7 @@ class StateFactory { this.index = index; } - public String toString(){ + public String toString() { return name; } } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/state/StateId.java b/jsprit-core/src/main/java/jsprit/core/algorithm/state/StateId.java index 3676b2d8..a1c23ff2 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/state/StateId.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/state/StateId.java @@ -3,8 +3,8 @@ package jsprit.core.algorithm.state; import jsprit.core.problem.HasIndex; /** -* Created by schroeder on 28.07.14. -*/ + * Created by schroeder on 28.07.14. + */ public interface StateId extends HasIndex { } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/state/StateManager.java b/jsprit-core/src/main/java/jsprit/core/algorithm/state/StateManager.java index daf1e99c..be09f491 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/state/StateManager.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/state/StateManager.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.state; @@ -37,96 +37,80 @@ import java.util.*; /** * Manages states. - * + *

*

Some condition, rules or constraints are stateful. This StateManager manages these states, i.e. it offers * methods to add, store and retrieve states based on the problem, vehicle-routes and tour-activities. - * - * @author schroeder * + * @author schroeder */ public class StateManager implements RouteAndActivityStateGetter, IterationStartsListener, RuinListener, InsertionStartsListener, JobInsertedListener, InsertionEndsListener { - static class States_ { - - private Map states = new HashMap(); - - public void putState(StateId id, Class type, T state){ - states.put(id, type.cast(state)); - } - - public T getState(StateId id, Class type){ - if(states.containsKey(id)){ - return type.cast(states.get(id)); - } - return null; - } - - public boolean containsKey(StateId stateId){ - return states.containsKey(stateId); - } - - public void clear(){ - states.clear(); - } - - } - - private States_ problemStates_ = new States_(); - - private RouteActivityVisitor routeActivityVisitor = new RouteActivityVisitor(); - - private ReverseRouteActivityVisitor revRouteActivityVisitor = new ReverseRouteActivityVisitor(); - - private Collection routeVisitors = new ArrayList(); - - private RuinListeners ruinListeners = new RuinListeners(); - - private InsertionListeners insertionListeners = new InsertionListeners(); - - private Collection updaters = new ArrayList(); + private RouteActivityVisitor routeActivityVisitor = new RouteActivityVisitor(); - private boolean updateLoad = false; - - private boolean updateTWs = false; + private ReverseRouteActivityVisitor revRouteActivityVisitor = new ReverseRouteActivityVisitor(); + + private Collection routeVisitors = new ArrayList(); + + private RuinListeners ruinListeners = new RuinListeners(); + + private InsertionListeners insertionListeners = new InsertionListeners(); + + private Collection updaters = new ArrayList(); + + private boolean updateLoad = false; + + private boolean updateTWs = false; private final int initialNoStates = 21; private int stateIndexCounter; - private Map createdStateIds = new HashMap(); + private Map createdStateIds = new HashMap(); private int nuActivities; private int nuVehicleTypeKeys; - private Object[][] activity_states; + private Object[] problemStates; - private Object[][][] vehicle_dependent_activity_states; + private Object[][] activityStates; - private Map route_state_map; + private Object[][][] vehicleDependentActivityStates; - private Map vehicle_dependent_route_state_map; + private Map routeStateMap; + + private Map vehicleDependentRouteStateMap; + + private Object[][] routeStatesArr; + + private Object[][][] vehicleDependentRouteStatesArr; private VehicleRoutingProblem vrp; - int getMaxIndexOfVehicleTypeIdentifiers(){ return nuVehicleTypeKeys; } + private final boolean isIndexedBased; + + int getMaxIndexOfVehicleTypeIdentifiers() { + return nuVehicleTypeKeys; + } /** * Create and returns a stateId with the specified state-name. - * + *

*

If a stateId with the specified name has already been created, it returns the created stateId.

*

If the specified is equal to a name that is already used internally, it throws an IllegalStateException

+ * * @param name the specified name of the state * @return the stateId with which a state can be identified, no matter if it is a problem, route or activity state. * @throws java.lang.IllegalStateException if name of state is already used internally */ - public StateId createStateId(String name){ - if(createdStateIds.containsKey(name)) return createdStateIds.get(name); - if(stateIndexCounter>=activity_states[0].length){ - activity_states = new Object[vrp.getNuActivities()+1][stateIndexCounter+1]; -// route_states = new Object[vrp.getNuActivities()+1][stateIndexCounter+1]; - vehicle_dependent_activity_states = new Object[nuActivities][nuVehicleTypeKeys][stateIndexCounter+1]; -// vehicle_dependent_route_states = new Object[nuActivities][nuVehicleTypeKeys][stateIndexCounter+1]; + public StateId createStateId(String name) { + if (createdStateIds.containsKey(name)) return createdStateIds.get(name); + if (stateIndexCounter >= activityStates[0].length) { + activityStates = new Object[vrp.getNuActivities() + 1][stateIndexCounter + 1]; + vehicleDependentActivityStates = new Object[nuActivities][nuVehicleTypeKeys][stateIndexCounter + 1]; + routeStatesArr = new Object[vrp.getNuActivities()+1][stateIndexCounter+1]; + vehicleDependentRouteStatesArr = new Object[nuActivities][nuVehicleTypeKeys][stateIndexCounter+1]; + problemStates = new Object[stateIndexCounter+1]; } StateId id = StateFactory.createId(name, stateIndexCounter); incStateIndexCounter(); @@ -144,24 +128,31 @@ public class StateManager implements RouteAndActivityStateGetter, IterationStart * * @param vehicleRoutingProblem the corresponding VehicleRoutingProblem */ - public StateManager(VehicleRoutingProblem vehicleRoutingProblem){ + public StateManager(VehicleRoutingProblem vehicleRoutingProblem) { stateIndexCounter = initialNoStates; int initialStateArrayLength = 30; this.vrp = vehicleRoutingProblem; nuActivities = Math.max(10, vrp.getNuActivities() + 1); nuVehicleTypeKeys = Math.max(3, getNuVehicleTypes(vrp) + 2); - activity_states = new Object[nuActivities][initialStateArrayLength]; -// route_states = new Object[nuActivities][initialStateArrayLength]; - vehicle_dependent_activity_states = new Object[nuActivities][nuVehicleTypeKeys][initialStateArrayLength]; -// vehicle_dependent_route_states = new Object[nuActivities][nuVehicleTypeKeys][initialStateArrayLength]; - route_state_map = new HashMap(); - vehicle_dependent_route_state_map = new HashMap(); + activityStates = new Object[nuActivities][initialStateArrayLength]; + vehicleDependentActivityStates = new Object[nuActivities][nuVehicleTypeKeys][initialStateArrayLength]; + if(vehicleRoutingProblem.getFleetSize().equals(VehicleRoutingProblem.FleetSize.FINITE)){ + isIndexedBased = true; + routeStatesArr = new Object[vrp.getVehicles().size() + 2][initialStateArrayLength]; + vehicleDependentRouteStatesArr = new Object[vrp.getVehicles().size() + 2][nuVehicleTypeKeys][initialStateArrayLength]; + } + else { + isIndexedBased = false; + routeStateMap = new HashMap(); + vehicleDependentRouteStateMap = new HashMap(); + } + problemStates = new Object[initialStateArrayLength]; } private int getNuVehicleTypes(VehicleRoutingProblem vrp) { int maxIndex = 0; - for(Vehicle v : vrp.getVehicles()){ - maxIndex = Math.max(maxIndex,v.getVehicleTypeIdentifier().getIndex()); + for (Vehicle v : vrp.getVehicles()) { + maxIndex = Math.max(maxIndex, v.getVehicleTypeIdentifier().getIndex()); } return maxIndex; } @@ -171,124 +162,127 @@ public class StateManager implements RouteAndActivityStateGetter, IterationStart * value is replaced by the new value. * * @param stateId the stateId which is the associated key to the problem state - * @param type the type of the problem state - * @param state the actual state value - * @param the type of the state value + * @param type the type of the problem state + * @param state the actual state value + * @param the type of the state value */ - public void putProblemState(StateId stateId, Class type, T state){ - problemStates_.putState(stateId, type, state); - } + public void putProblemState(StateId stateId, Class type, T state) { + problemStates[stateId.getIndex()] = state; +// problemStates.putState(stateId, type, state); + } /** * Returns mapped state value that is associated to the specified stateId, or null if no value is associated to * the specified stateId. * * @param stateId the stateId which is the associated key to the problem state - * @param type the type class of the state value - * @param the type + * @param type the type class of the state value + * @param the type * @return the state value that is associated to the specified stateId or null if no value is associated */ - public T getProblemState(StateId stateId, Class type){ - return problemStates_.getState(stateId, type); - } + public T getProblemState(StateId stateId, Class type) { + return type.cast(problemStates[stateId.getIndex()]); + } - /** - * Clears all states, i.e. set all value to null. - * - */ - public void clear(){ - fill_twoDimArr(activity_states, null); -// fill_twoDimArr(route_states, null); - fill_threeDimArr(vehicle_dependent_activity_states, null); -// fill_threeDimArr(vehicle_dependent_route_states, null); - problemStates_.clear(); - route_state_map.clear(); - vehicle_dependent_route_state_map.clear(); - } + /** + * Clears all states, i.e. set all value to null. + */ + public void clear() { + fill_twoDimArr(activityStates, null); + fill_threeDimArr(vehicleDependentActivityStates, null); + if(isIndexedBased) { + fill_twoDimArr(routeStatesArr, null); + fill_threeDimArr(vehicleDependentRouteStatesArr, null); + } + else{ + routeStateMap.clear(); + vehicleDependentRouteStateMap.clear(); + } + Arrays.fill(problemStates,null); + } private void fill_threeDimArr(Object[][][] states, Object o) { - for(Object[][] twoDimArr : states){ - for(Object[] oneDimArr : twoDimArr){ - Arrays.fill(oneDimArr,o); + for (Object[][] twoDimArr : states) { + for (Object[] oneDimArr : twoDimArr) { + Arrays.fill(oneDimArr, o); } } } private void fill_twoDimArr(Object[][] states, Object o) { - for(Object[] rows : states){ - Arrays.fill(rows,o); + for (Object[] rows : states) { + Arrays.fill(rows, o); } } /** - * Returns associated state for the specified activity and stateId, or it returns null if no value is associated. + * Returns associated state for the specified activity and stateId, or it returns null if no value is associated. *

If type class is not equal to the associated type class of the requested state value, it throws a ClassCastException.

- * - * @param act the activity for which a state value is associated to + * + * @param act the activity for which a state value is associated to * @param stateId the stateId for which a state value is associated to - * @param type the type of class of the associated state value - * @param the type + * @param type the type of class of the associated state value + * @param the type * @return the state value that is associated to the specified activity and stateId, or null if no value is associated. - * @throws java.lang.ClassCastException if type class is not equal to the associated type class of the requested state value + * @throws java.lang.ClassCastException if type class is not equal to the associated type class of the requested state value * @throws java.lang.IllegalStateException if act.getIndex()==0 since this suggests that act has no index at all - */ - @Override - public T getActivityState(TourActivity act, StateId stateId, Class type) { - if(act.getIndex() == 0) throw new IllegalStateException("activity index is 0. this should not be."); - if(act.getIndex()<0) return null; + */ + @Override + public T getActivityState(TourActivity act, StateId stateId, Class type) { + if (act.getIndex() == 0) throw new IllegalStateException("activity index is 0. this should not be."); + if (act.getIndex() < 0) return null; T state; - try{ - state = type.cast(activity_states[act.getIndex()][stateId.getIndex()]); - } - catch (ClassCastException e){ - throw getClassCastException(e,stateId,type.toString(),activity_states[act.getIndex()][stateId.getIndex()].getClass().toString()); + try { + state = type.cast(activityStates[act.getIndex()][stateId.getIndex()]); + } catch (ClassCastException e) { + throw getClassCastException(e, stateId, type.toString(), activityStates[act.getIndex()][stateId.getIndex()].getClass().toString()); } return state; - } + } /** * Returns true if a state value is associated to the specified activity, vehicle and stateId. * - * @param act the activity for which a state value is associated to + * @param act the activity for which a state value is associated to * @param vehicle the vehicle for which a state value is associated to * @param stateId the stateId which is the associated key to the problem state * @return true if a state value is associated otherwise false * @throws java.lang.IllegalStateException if act.getIndex()==0 since this suggests that act has no index at all */ - public boolean hasActivityState(TourActivity act, Vehicle vehicle, StateId stateId){ - if(act.getIndex() == 0) throw new IllegalStateException("activity index is 0. this should not be."); - return vehicle_dependent_activity_states[act.getIndex()][vehicle.getVehicleTypeIdentifier().getIndex()][stateId.getIndex()] != null; + public boolean hasActivityState(TourActivity act, Vehicle vehicle, StateId stateId) { + if (act.getIndex() == 0) throw new IllegalStateException("activity index is 0. this should not be."); + return vehicleDependentActivityStates[act.getIndex()][vehicle.getVehicleTypeIdentifier().getIndex()][stateId.getIndex()] != null; } /** * Returns the associated state value to the specified activity, vehicle and stateId, or null if no state value is * associated. *

If type class is not equal to the associated type class of the requested state value, it throws a ClassCastException.

- * @param act the activity for which a state value is associated to + * + * @param act the activity for which a state value is associated to * @param vehicle the vehicle for which a state value is associated to * @param stateId the stateId which is the associated key to the problem state - * @param type the class of the associated state value - * @param the type of the class + * @param type the class of the associated state value + * @param the type of the class * @return the associated state value to the specified activity, vehicle and stateId, or null if no state value is * associated. - * @throws java.lang.ClassCastException if type class is not equal to the associated type class of the requested state value + * @throws java.lang.ClassCastException if type class is not equal to the associated type class of the requested state value * @throws java.lang.IllegalStateException if act.getIndex()==0 since this suggests that act has no index at all */ public T getActivityState(TourActivity act, Vehicle vehicle, StateId stateId, Class type) { - if(act.getIndex() == 0) throw new IllegalStateException("activity index is 0. this should not be."); - if(act.getIndex() < 0) return null; //act.getIndex() < 0 indicates that act is either Start (-1) or End (-2) + if (act.getIndex() == 0) throw new IllegalStateException("activity index is 0. this should not be."); + if (act.getIndex() < 0) return null; //act.getIndex() < 0 indicates that act is either Start (-1) or End (-2) T state; try { - state = type.cast(vehicle_dependent_activity_states[act.getIndex()][vehicle.getVehicleTypeIdentifier().getIndex()][stateId.getIndex()]); - } - catch(ClassCastException e){ - Object state_class = vehicle_dependent_activity_states[act.getIndex()][vehicle.getVehicleTypeIdentifier().getIndex()][stateId.getIndex()]; - throw getClassCastException(e,stateId,type.toString(),state_class.getClass().toString()); + state = type.cast(vehicleDependentActivityStates[act.getIndex()][vehicle.getVehicleTypeIdentifier().getIndex()][stateId.getIndex()]); + } catch (ClassCastException e) { + Object state_class = vehicleDependentActivityStates[act.getIndex()][vehicle.getVehicleTypeIdentifier().getIndex()][stateId.getIndex()]; + throw getClassCastException(e, stateId, type.toString(), state_class.getClass().toString()); } return state; } - private ClassCastException getClassCastException(ClassCastException e, StateId stateId, String requestedTypeClass, String memorizedTypeClass){ + private ClassCastException getClassCastException(ClassCastException e, StateId stateId, String requestedTypeClass, String memorizedTypeClass) { return new ClassCastException(e + "\n" + "state with stateId '" + stateId.toString() + "' is of " + memorizedTypeClass + ". cannot cast it to " + requestedTypeClass + "."); } @@ -296,74 +290,83 @@ public class StateManager implements RouteAndActivityStateGetter, IterationStart * Returns the route state that is associated to the route and stateId, or null if no state is associated. *

If type class is not equal to the associated type class of the requested state value, it throws a ClassCastException.

* - * @param route the route which the associated route key to the route state + * @param route the route which the associated route key to the route state * @param stateId the stateId which is the associated key to the route state - * @param type the class of the associated state value - * @param the type of the class + * @param type the class of the associated state value + * @param the type of the class * @return the route state that is associated to the route and stateId, or null if no state is associated. - * @throws java.lang.ClassCastException if type class is not equal to the associated type class of the requested state value + * @throws java.lang.ClassCastException if type class is not equal to the associated type class of the requested state value * @throws java.lang.IllegalStateException if !route.isEmpty() and act(0).getIndex()==0 since this suggests that act has no index at all */ - @Override - public T getRouteState(VehicleRoute route, StateId stateId, Class type) { - if(route.isEmpty()) return null; + @Override + public T getRouteState(VehicleRoute route, StateId stateId, Class type) { + if (route.isEmpty()) return null; T state = null; - -// int index_of_first_act = route.getActivities().get(0).getIndex(); -// if(index_of_first_act == 0) throw new IllegalStateException("first activity in route has no index. this should not be."); - try{ - if(route_state_map.containsKey(route)) { - state = type.cast(route_state_map.get(route)[stateId.getIndex()]); + if(isIndexedBased){ + try { + state = type.cast(routeStatesArr[route.getVehicle().getIndex()][stateId.getIndex()]); + } catch (ClassCastException e) { + throw getClassCastException(e,stateId,type.toString(),routeStatesArr[route.getVehicle().getIndex()][stateId.getIndex()].getClass().toString()); } -// state = type.cast(route_states[index_of_first_act][stateId.getIndex()]); } - catch (ClassCastException e){ - throw getClassCastException(e,stateId,type.toString(),route_state_map.get(route)[stateId.getIndex()].getClass().toString()); -// throw getClassCastException(e,stateId,type.toString(),route_states[index_of_first_act][stateId.getIndex()].getClass().toString()); + else { + try { + if (routeStateMap.containsKey(route)) { + state = type.cast(routeStateMap.get(route)[stateId.getIndex()]); + } + } catch (ClassCastException e) { + throw getClassCastException(e, stateId, type.toString(), routeStateMap.get(route)[stateId.getIndex()].getClass().toString()); + } } return state; - } + } /** * Returns true if a state is assigned to the specified route, vehicle and stateId. Otherwise it returns false. * - * @param route the route for which the state is requested + * @param route the route for which the state is requested * @param vehicle the vehicle for which the state is requested * @param stateId the stateId(entifier) for the state that is requested * @return true if state exists and false otherwise */ @SuppressWarnings("UnusedDeclaration") public boolean hasRouteState(VehicleRoute route, Vehicle vehicle, StateId stateId) { - if(!vehicle_dependent_route_state_map.containsKey(route)) return false; - return vehicle_dependent_route_state_map.get(route)[vehicle.getVehicleTypeIdentifier().getIndex()][stateId.getIndex()] != null; + if (!vehicleDependentRouteStateMap.containsKey(route)) return false; + return vehicleDependentRouteStateMap.get(route)[vehicle.getVehicleTypeIdentifier().getIndex()][stateId.getIndex()] != null; // return vehicle_dependent_route_states[route.getActivities().get(0).getIndex()][vehicle.getVehicleTypeIdentifier().getIndex()][stateId.getIndex()] != null; } /** * Returns the route state that is assigned to the specified route, vehicle and stateId. *

Returns null if no state can be found

- * @param route the route for which the state is requested + * + * @param route the route for which the state is requested * @param vehicle the vehicle for which the state is requested * @param stateId the stateId(entifier) for the state that is requested - * @param type the type class of the requested state - * @param the type of the class + * @param type the type class of the requested state + * @param the type of the class * @return the actual route state that is assigned to the route, vehicle and stateId - * @throws java.lang.ClassCastException if specified type is not equal to the memorized type + * @throws java.lang.ClassCastException if specified type is not equal to the memorized type * @throws java.lang.IllegalStateException if !route.isEmpty() and act(0).getIndex()==0 since this suggests that act has no index at all */ public T getRouteState(VehicleRoute route, Vehicle vehicle, StateId stateId, Class type) { - if(route.isEmpty()) return null; -// int index_of_first_act = route.getActivities().get(0).getIndex(); -// if(index_of_first_act == 0) throw new IllegalStateException("first activity in route has no index. this should not be."); + if (route.isEmpty()) return null; T state = null; - try{ - if(vehicle_dependent_route_state_map.containsKey(route)){ - state = type.cast(vehicle_dependent_route_state_map.get(route)[vehicle.getVehicleTypeIdentifier().getIndex()][stateId.getIndex()]); + if(isIndexedBased){ + try { + state = type.cast(vehicleDependentRouteStatesArr[route.getVehicle().getIndex()][vehicle.getVehicleTypeIdentifier().getIndex()][stateId.getIndex()]); + } catch (ClassCastException e) { + throw getClassCastException(e, stateId, type.toString(), vehicleDependentRouteStatesArr[route.getVehicle().getIndex()][vehicle.getVehicleTypeIdentifier().getIndex()][stateId.getIndex()].getClass().toString()); } -// state = type.cast(vehicle_dependent_route_states[index_of_first_act][vehicle.getVehicleTypeIdentifier().getIndex()][stateId.getIndex()]); } - catch( ClassCastException e){ - throw getClassCastException(e, stateId, type.toString(), vehicle_dependent_route_state_map.get(route)[vehicle.getVehicleTypeIdentifier().getIndex()][stateId.getIndex()].getClass().toString()); + else { + try { + if (vehicleDependentRouteStateMap.containsKey(route)) { + state = type.cast(vehicleDependentRouteStateMap.get(route)[vehicle.getVehicleTypeIdentifier().getIndex()][stateId.getIndex()]); + } + } catch (ClassCastException e) { + throw getClassCastException(e, stateId, type.toString(), vehicleDependentRouteStateMap.get(route)[vehicle.getVehicleTypeIdentifier().getIndex()][stateId.getIndex()].getClass().toString()); + } } return state; } @@ -372,17 +375,17 @@ public class StateManager implements RouteAndActivityStateGetter, IterationStart * Associates the specified activity and stateId to the state value. If a state value is already associated to the * specified activity and stateId, it is replaced by the new state value. * - * @param act the activity for which a state value is associated to + * @param act the activity for which a state value is associated to * @param stateId the stateId which is the associated key to the activity state - * @param state the state that is associated to the activity and stateId - * @param the type of the state + * @param state the state that is associated to the activity and stateId + * @param the type of the state * @throws java.lang.IllegalStateException if act.getIndex() == 0 - * || stateId.getIndex < noInternalStates - * + * || stateId.getIndex < noInternalStates */ - public void putActivityState(TourActivity act, StateId stateId, T state){ - if(act.getIndex() == 0) throw new IllegalStateException("activity index is 0. this should not be."); - if(stateId.getIndex() < initialNoStates) throw new IllegalStateException("either you use a reserved stateId that is applied\n" + + public void putActivityState(TourActivity act, StateId stateId, T state) { + if (act.getIndex() == 0) throw new IllegalStateException("activity index is 0. this should not be."); + if (stateId.getIndex() < initialNoStates) + throw new IllegalStateException("either you use a reserved stateId that is applied\n" + "internally or your stateId has been created without index, e.g. StateFactory.createId(stateName)\n" + " does not assign indeces thus do not use it anymore, but use\n " + "stateManager.createStateId(name)\n" + @@ -394,17 +397,18 @@ public class StateManager implements RouteAndActivityStateGetter, IterationStart * Associates the specified activity, vehicle and stateId to the state value. If a state value is already associated to the * specified activity and stateId, it is replaced by the new state value. * - * @param act the activity for which a state value is associated to + * @param act the activity for which a state value is associated to * @param vehicle the vehicle for which a state value is associated to * @param stateId the stateId which is the associated key to the activity state - * @param state the state that is associated to the activity and stateId - * @param the type of the state + * @param state the state that is associated to the activity and stateId + * @param the type of the state * @throws java.lang.IllegalStateException if act.getIndex() == 0 - * || stateId.getIndex < noInternalStates + * || stateId.getIndex < noInternalStates */ - public void putActivityState(TourActivity act, Vehicle vehicle, StateId stateId, T state){ - if(act.getIndex() == 0) throw new IllegalStateException("activity index is 0. this should not be."); - if(stateId.getIndex() < initialNoStates) throw new IllegalStateException("either you use a reserved stateId that is applied\n" + + public void putActivityState(TourActivity act, Vehicle vehicle, StateId stateId, T state) { + if (act.getIndex() == 0) throw new IllegalStateException("activity index is 0. this should not be."); + if (stateId.getIndex() < initialNoStates) + throw new IllegalStateException("either you use a reserved stateId that is applied\n" + "internally or your stateId has been created without index, e.g. StateFactory.createId(stateName)\n" + " does not assign indeces thus do not use it anymore, but use\n " + "stateManager.createStateId(name)\n" + @@ -412,26 +416,26 @@ public class StateManager implements RouteAndActivityStateGetter, IterationStart putInternalTypedActivityState(act, vehicle, stateId, state); } - void putInternalTypedActivityState(TourActivity act, StateId stateId, T state){ - activity_states[act.getIndex()][stateId.getIndex()]=state; - } - - void putInternalTypedActivityState(TourActivity act, Vehicle vehicle, StateId stateId, T state){ - vehicle_dependent_activity_states[act.getIndex()][vehicle.getVehicleTypeIdentifier().getIndex()][stateId.getIndex()]=state; + void putInternalTypedActivityState(TourActivity act, StateId stateId, T state) { + activityStates[act.getIndex()][stateId.getIndex()] = state; } - /** + void putInternalTypedActivityState(TourActivity act, Vehicle vehicle, StateId stateId, T state) { + vehicleDependentActivityStates[act.getIndex()][vehicle.getVehicleTypeIdentifier().getIndex()][stateId.getIndex()] = state; + } + + /** * Associates the specified route, vehicle and stateId to the state value. If a state value is already associated to the * specified activity and stateId, it is replaced by the new state value. * - * @param route the route for which a state value is associated to + * @param route the route for which a state value is associated to * @param stateId the stateId which is the associated key to the activity state - * @param state the state that is associated to the activity and stateId - * @param the type of the state + * @param state the state that is associated to the activity and stateId + * @param the type of the state * @throws java.lang.IllegalStateException if stateId is equal to a stateId that is already used internally. */ - public void putRouteState(VehicleRoute route, StateId stateId, T state){ - if(stateId.getIndex() < initialNoStates) StateFactory.throwReservedIdException(stateId.toString()); + public void putRouteState(VehicleRoute route, StateId stateId, T state) { + if (stateId.getIndex() < initialNoStates) StateFactory.throwReservedIdException(stateId.toString()); putTypedInternalRouteState(route, stateId, state); } @@ -439,60 +443,69 @@ public class StateManager implements RouteAndActivityStateGetter, IterationStart * Associates the specified route, vehicle and stateId to the state value. If a state value is already associated to the * specified activity and stateId, it is replaced by the new state value. * - * @param route the route for which a state value is associated to + * @param route the route for which a state value is associated to * @param vehicle the vehicle for which a state value is associated to * @param stateId the stateId which is the associated key to the activity state - * @param state the state that is associated to the activity and stateId - * @param the type of the state + * @param state the state that is associated to the activity and stateId + * @param the type of the state * @throws java.lang.IllegalStateException if vehicle.getIndex() == 0 || stateId.getIndex() < noInternalStates */ - public void putRouteState(VehicleRoute route, Vehicle vehicle, StateId stateId, T state){ - if(vehicle.getIndex() == 0) throw new IllegalStateException("vehicle index is 0. this should not be."); - if(stateId.getIndex() < initialNoStates) StateFactory.throwReservedIdException(stateId.toString()); + public void putRouteState(VehicleRoute route, Vehicle vehicle, StateId stateId, T state) { + if (vehicle.getIndex() == 0) throw new IllegalStateException("vehicle index is 0. this should not be."); + if (stateId.getIndex() < initialNoStates) StateFactory.throwReservedIdException(stateId.toString()); putTypedInternalRouteState(route, vehicle, stateId, state); } - void putTypedInternalRouteState(VehicleRoute route, StateId stateId, T state){ - if(route.isEmpty()) return; - if(!route_state_map.containsKey(route)){ - route_state_map.put(route,new Object[stateIndexCounter]); + void putTypedInternalRouteState(VehicleRoute route, StateId stateId, T state) { + if (route.isEmpty()) return; + if(isIndexedBased){ + routeStatesArr[route.getVehicle().getIndex()][stateId.getIndex()] = state; + } + else { + if (!routeStateMap.containsKey(route)) { + routeStateMap.put(route, new Object[stateIndexCounter]); + } + routeStateMap.get(route)[stateId.getIndex()] = state; } - route_state_map.get(route)[stateId.getIndex()] = state; -// route_states[route.getActivities().get(0).getIndex()][stateId.getIndex()] = state; } - void putTypedInternalRouteState(VehicleRoute route, Vehicle vehicle, StateId stateId, T state){ - if(route.isEmpty()) return; - if(!vehicle_dependent_route_state_map.containsKey(route)){ - vehicle_dependent_route_state_map.put(route,new Object[nuVehicleTypeKeys][stateIndexCounter]); + void putTypedInternalRouteState(VehicleRoute route, Vehicle vehicle, StateId stateId, T state) { + if (route.isEmpty()) return; + if(isIndexedBased){ + vehicleDependentRouteStatesArr[route.getVehicle().getIndex()][vehicle.getVehicleTypeIdentifier().getIndex()][stateId.getIndex()] = state; } - vehicle_dependent_route_state_map.get(route)[vehicle.getVehicleTypeIdentifier().getIndex()][stateId.getIndex()] = state; -// vehicle_dependent_route_states[route.getActivities().get(0).getIndex()][vehicle.getVehicleTypeIdentifier().getIndex()][stateId.getIndex()] = state; + else { + if (!vehicleDependentRouteStateMap.containsKey(route)) { + vehicleDependentRouteStateMap.put(route, new Object[nuVehicleTypeKeys][stateIndexCounter]); + } + vehicleDependentRouteStateMap.get(route)[vehicle.getVehicleTypeIdentifier().getIndex()][stateId.getIndex()] = state; + } + } - /** - * Adds state updater. - * - *

Note that a state update occurs if route and/or activity states have changed, i.e. if jobs are removed - * or inserted into a route. Thus here, it is assumed that a state updater is either of type InsertionListener, - * RuinListener, ActivityVisitor, ReverseActivityVisitor, RouteVisitor, ReverseRouteVisitor. - * - *

The following rule pertain for activity/route visitors:These visitors visits all activities/route in a route subsequently in two cases. First, if insertionStart (after ruinStrategies have removed activities from routes) - * and, second, if a job has been inserted and thus if a route has changed. - * - * @param updater the update to be added - */ - public void addStateUpdater(StateUpdater updater){ - if(updater instanceof ActivityVisitor) addActivityVisitor((ActivityVisitor) updater); - if(updater instanceof ReverseActivityVisitor) addActivityVisitor((ReverseActivityVisitor)updater); - if(updater instanceof RouteVisitor) addRouteVisitor((RouteVisitor) updater); - if(updater instanceof InsertionListener) addListener((InsertionListener) updater); - if(updater instanceof RuinListener) addListener((RuinListener) updater); - updaters.add(updater); - } + /** + * Adds state updater. + *

+ *

Note that a state update occurs if route and/or activity states have changed, i.e. if jobs are removed + * or inserted into a route. Thus here, it is assumed that a state updater is either of type InsertionListener, + * RuinListener, ActivityVisitor, ReverseActivityVisitor, RouteVisitor, ReverseRouteVisitor. + *

+ *

The following rule pertain for activity/route visitors:These visitors visits all activities/route in a route subsequently in two cases. First, if insertionStart (after ruinStrategies have removed activities from routes) + * and, second, if a job has been inserted and thus if a route has changed. + * + * @param updater the update to be added + */ + public void addStateUpdater(StateUpdater updater) { + if (updater instanceof ActivityVisitor) addActivityVisitor((ActivityVisitor) updater); + if (updater instanceof ReverseActivityVisitor) addActivityVisitor((ReverseActivityVisitor) updater); + if (updater instanceof RouteVisitor) addRouteVisitor((RouteVisitor) updater); + if (updater instanceof InsertionListener) addListener((InsertionListener) updater); + if (updater instanceof RuinListener) addListener((RuinListener) updater); + updaters.add(updater); + } - public void addAllStateUpdater(Collection updaters){ - for(StateUpdater u : updaters) addStateUpdater(u); + public void addAllStateUpdater(Collection updaters) { + for (StateUpdater u : updaters) addStateUpdater(u); } /** @@ -501,112 +514,116 @@ public class StateManager implements RouteAndActivityStateGetter, IterationStart * @return an unmodifiable collections of stateUpdaters that have been added to this stateManager. */ @SuppressWarnings("UnusedDeclaration") - Collection getStateUpdaters(){ - return Collections.unmodifiableCollection(updaters); - } - - /** - * Adds an activityVisitor. - *

This visitor visits all activities in a route subsequently in two cases. First, if insertionStart (after ruinStrategies have removed activities from routes) - * and, second, if a job has been inserted and thus if a route has changed. - * - * @param activityVistor the activity-visitor to be added - */ - void addActivityVisitor(ActivityVisitor activityVistor){ - routeActivityVisitor.addActivityVisitor(activityVistor); - } + Collection getStateUpdaters() { + return Collections.unmodifiableCollection(updaters); + } - /** - * Adds an reverseActivityVisitor. - *

This reverseVisitor visits all activities in a route subsequently (starting from the end of the route) in two cases. First, if insertionStart (after ruinStrategies have removed activities from routes) - * and, second, if a job has been inserted and thus if a route has changed. - * - * @param activityVistor activityVisitor to add - */ - void addActivityVisitor(ReverseActivityVisitor activityVistor){ - revRouteActivityVisitor.addActivityVisitor(activityVistor); - } + /** + * Adds an activityVisitor. + *

This visitor visits all activities in a route subsequently in two cases. First, if insertionStart (after ruinStrategies have removed activities from routes) + * and, second, if a job has been inserted and thus if a route has changed. + * + * @param activityVistor the activity-visitor to be added + */ + void addActivityVisitor(ActivityVisitor activityVistor) { + routeActivityVisitor.addActivityVisitor(activityVistor); + } - void addRouteVisitor(RouteVisitor routeVisitor){ - routeVisitors.add(routeVisitor); - } + /** + * Adds an reverseActivityVisitor. + *

This reverseVisitor visits all activities in a route subsequently (starting from the end of the route) in two cases. First, if insertionStart (after ruinStrategies have removed activities from routes) + * and, second, if a job has been inserted and thus if a route has changed. + * + * @param activityVistor activityVisitor to add + */ + void addActivityVisitor(ReverseActivityVisitor activityVistor) { + revRouteActivityVisitor.addActivityVisitor(activityVistor); + } - void addListener(RuinListener ruinListener){ - ruinListeners.addListener(ruinListener); - } + void addRouteVisitor(RouteVisitor routeVisitor) { + routeVisitors.add(routeVisitor); + } - void addListener(InsertionListener insertionListener){ - insertionListeners.addListener(insertionListener); - } + void addListener(RuinListener ruinListener) { + ruinListeners.addListener(ruinListener); + } - @Override - public void informJobInserted(Job job2insert, VehicleRoute inRoute, double additionalCosts, double additionalTime) { + void addListener(InsertionListener insertionListener) { + insertionListeners.addListener(insertionListener); + } + + @Override + public void informJobInserted(Job job2insert, VehicleRoute inRoute, double additionalCosts, double additionalTime) { // log.debug("insert " + job2insert + " in " + inRoute); - insertionListeners.informJobInserted(job2insert, inRoute, additionalCosts, additionalTime); - for(RouteVisitor v : routeVisitors){ v.visit(inRoute); } - routeActivityVisitor.visit(inRoute); - revRouteActivityVisitor.visit(inRoute); - } + insertionListeners.informJobInserted(job2insert, inRoute, additionalCosts, additionalTime); + for (RouteVisitor v : routeVisitors) { + v.visit(inRoute); + } + routeActivityVisitor.visit(inRoute); + revRouteActivityVisitor.visit(inRoute); + } - @Override - public void informInsertionStarts(Collection vehicleRoutes,Collection unassignedJobs) { - insertionListeners.informInsertionStarts(vehicleRoutes, unassignedJobs); - for(VehicleRoute route : vehicleRoutes){ - for(RouteVisitor v : routeVisitors){ v.visit(route); } - routeActivityVisitor.visit(route); - revRouteActivityVisitor.visit(route); - } - } - - @Override - public void informIterationStarts(int i, VehicleRoutingProblem problem, Collection solutions) { - clear(); - } + @Override + public void informInsertionStarts(Collection vehicleRoutes, Collection unassignedJobs) { + insertionListeners.informInsertionStarts(vehicleRoutes, unassignedJobs); + for (VehicleRoute route : vehicleRoutes) { + for (RouteVisitor v : routeVisitors) { + v.visit(route); + } + routeActivityVisitor.visit(route); + revRouteActivityVisitor.visit(route); + } + } - @Override - public void ruinStarts(Collection routes) { - ruinListeners.ruinStarts(routes); - } + @Override + public void informIterationStarts(int i, VehicleRoutingProblem problem, Collection solutions) { + clear(); + } - @Override - public void ruinEnds(Collection routes, Collection unassignedJobs) { + @Override + public void ruinStarts(Collection routes) { + ruinListeners.ruinStarts(routes); + } + + @Override + public void ruinEnds(Collection routes, Collection unassignedJobs) { // log.debug("ruin ends"); - ruinListeners.ruinEnds(routes, unassignedJobs); - } + ruinListeners.ruinEnds(routes, unassignedJobs); + } - @Override - public void removed(Job job, VehicleRoute fromRoute) { - ruinListeners.removed(job, fromRoute); - } + @Override + public void removed(Job job, VehicleRoute fromRoute) { + ruinListeners.removed(job, fromRoute); + } - @Override - public void informInsertionEnds(Collection vehicleRoutes) { - insertionListeners.informInsertionEndsListeners(vehicleRoutes); - } + @Override + public void informInsertionEnds(Collection vehicleRoutes) { + insertionListeners.informInsertionEndsListeners(vehicleRoutes); + } /** * Updates load states. */ - public void updateLoadStates() { - if(!updateLoad){ - updateLoad=true; - UpdateLoads updateLoads = new UpdateLoads(this); - addActivityVisitor(updateLoads); - addListener(updateLoads); - addActivityVisitor(new UpdateMaxCapacityUtilisationAtActivitiesByLookingBackwardInRoute(this)); - addActivityVisitor(new UpdateMaxCapacityUtilisationAtActivitiesByLookingForwardInRoute(this)); - addActivityVisitor(new UpdateMaxCapacityUtilisationAtRoute(this)); - } - } + public void updateLoadStates() { + if (!updateLoad) { + updateLoad = true; + UpdateLoads updateLoads = new UpdateLoads(this); + addActivityVisitor(updateLoads); + addListener(updateLoads); + addActivityVisitor(new UpdateMaxCapacityUtilisationAtActivitiesByLookingBackwardInRoute(this)); + addActivityVisitor(new UpdateMaxCapacityUtilisationAtActivitiesByLookingForwardInRoute(this)); + addActivityVisitor(new UpdateMaxCapacityUtilisationAtRoute(this)); + } + } /** * Updates time-window states. */ - public void updateTimeWindowStates() { - updateTWs=true; - } + public void updateTimeWindowStates() { + updateTWs = true; + } - public boolean timeWindowUpdateIsActivated(){ + public boolean timeWindowUpdateIsActivated() { return updateTWs; } @@ -617,7 +634,8 @@ public class StateManager implements RouteAndActivityStateGetter, IterationStart addActivityVisitor(new UpdateSkills(this)); } - public void addCoreUpdater(){ + @Deprecated + public void addCoreUpdater() { } } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/state/StateUpdater.java b/jsprit-core/src/main/java/jsprit/core/algorithm/state/StateUpdater.java index 4f3c9793..26237bd8 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/state/StateUpdater.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/state/StateUpdater.java @@ -1,18 +1,18 @@ /******************************************************************************* * Copyright (c) 2014 Stefan Schroeder. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . - * + * * Contributors: * Stefan Schroeder - initial API and implementation ******************************************************************************/ diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/state/UpdateActivityTimes.java b/jsprit-core/src/main/java/jsprit/core/algorithm/state/UpdateActivityTimes.java index 868532f8..175c8701 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/state/UpdateActivityTimes.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/state/UpdateActivityTimes.java @@ -24,58 +24,54 @@ import jsprit.core.util.ActivityTimeTracker; /** - * Updates arrival and end times of activities. - * + * Updates arrival and end times of activities. + *

*

Note that this modifies arrTime and endTime of each activity in a route. - * - * @author stefan * + * @author stefan */ -public class UpdateActivityTimes implements ActivityVisitor, StateUpdater{ +public class UpdateActivityTimes implements ActivityVisitor, StateUpdater { private ActivityTimeTracker timeTracker; - - private VehicleRoute route; - /** - * Updates arrival and end times of activities. - * - *

Note that this modifies arrTime and endTime of each activity in a route. - * - *

ArrTimes and EndTimes can be retrieved by
- * activity.getArrTime() and - * activity.getEndTime() - * - * - * - */ - public UpdateActivityTimes(ForwardTransportTime transportTime) { - super(); - timeTracker = new ActivityTimeTracker(transportTime); - } + private VehicleRoute route; - public UpdateActivityTimes(ForwardTransportTime transportTime, ActivityTimeTracker.ActivityPolicy activityPolicy){ - timeTracker = new ActivityTimeTracker(transportTime,activityPolicy); + /** + * Updates arrival and end times of activities. + *

+ *

Note that this modifies arrTime and endTime of each activity in a route. + *

+ *

ArrTimes and EndTimes can be retrieved by
+ * activity.getArrTime() and + * activity.getEndTime() + */ + public UpdateActivityTimes(ForwardTransportTime transportTime) { + super(); + timeTracker = new ActivityTimeTracker(transportTime); } - @Override - public void begin(VehicleRoute route) { - timeTracker.begin(route); - this.route = route; - route.getStart().setEndTime(timeTracker.getActEndTime()); - } + public UpdateActivityTimes(ForwardTransportTime transportTime, ActivityTimeTracker.ActivityPolicy activityPolicy) { + timeTracker = new ActivityTimeTracker(transportTime, activityPolicy); + } - @Override - public void visit(TourActivity activity) { - timeTracker.visit(activity); - activity.setArrTime(timeTracker.getActArrTime()); - activity.setEndTime(timeTracker.getActEndTime()); - } + @Override + public void begin(VehicleRoute route) { + timeTracker.begin(route); + this.route = route; + route.getStart().setEndTime(timeTracker.getActEndTime()); + } - @Override - public void finish() { - timeTracker.finish(); - route.getEnd().setArrTime(timeTracker.getActArrTime()); - } + @Override + public void visit(TourActivity activity) { + timeTracker.visit(activity); + activity.setArrTime(timeTracker.getActArrTime()); + activity.setEndTime(timeTracker.getActEndTime()); + } + + @Override + public void finish() { + timeTracker.finish(); + route.getEnd().setArrTime(timeTracker.getActArrTime()); + } } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/state/UpdateEndLocationIfRouteIsOpen.java b/jsprit-core/src/main/java/jsprit/core/algorithm/state/UpdateEndLocationIfRouteIsOpen.java index 948fced8..1fbc5002 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/state/UpdateEndLocationIfRouteIsOpen.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/state/UpdateEndLocationIfRouteIsOpen.java @@ -20,26 +20,23 @@ import jsprit.core.problem.solution.route.RouteVisitor; import jsprit.core.problem.solution.route.VehicleRoute; import jsprit.core.problem.solution.route.activity.TourActivity; -public class UpdateEndLocationIfRouteIsOpen implements StateUpdater, RouteVisitor{ +public class UpdateEndLocationIfRouteIsOpen implements StateUpdater, RouteVisitor { - @Override - public void visit(VehicleRoute route) { - if(route.getVehicle() != null){ - if(!route.getVehicle().isReturnToDepot()){ - setRouteEndToLastActivity(route); - } - } - } + @Override + public void visit(VehicleRoute route) { + if (route.getVehicle() != null) { + if (!route.getVehicle().isReturnToDepot()) { + setRouteEndToLastActivity(route); + } + } + } - private void setRouteEndToLastActivity(VehicleRoute route) { - if(!route.getActivities().isEmpty()){ - TourActivity lastAct = route.getActivities().get(route.getActivities().size()-1); - route.getEnd().setLocation(lastAct.getLocation()); - } - } + private void setRouteEndToLastActivity(VehicleRoute route) { + if (!route.getActivities().isEmpty()) { + TourActivity lastAct = route.getActivities().get(route.getActivities().size() - 1); + route.getEnd().setLocation(lastAct.getLocation()); + } + } - - - } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/state/UpdateFutureWaitingTimes.java b/jsprit-core/src/main/java/jsprit/core/algorithm/state/UpdateFutureWaitingTimes.java new file mode 100644 index 00000000..07770758 --- /dev/null +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/state/UpdateFutureWaitingTimes.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (C) 2014 Stefan Schroeder + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3.0 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + ******************************************************************************/ +package jsprit.core.algorithm.state; + +import jsprit.core.problem.cost.VehicleRoutingTransportCosts; +import jsprit.core.problem.solution.route.VehicleRoute; +import jsprit.core.problem.solution.route.activity.ReverseActivityVisitor; +import jsprit.core.problem.solution.route.activity.TourActivity; + +/** + * Updates and memorizes latest operation start times at activities. + * + * @author schroeder + */ +public class UpdateFutureWaitingTimes implements ReverseActivityVisitor, StateUpdater { + + private StateManager states; + + private VehicleRoute route; + + private VehicleRoutingTransportCosts transportCosts; + + private double futureWaiting; + + public UpdateFutureWaitingTimes(StateManager states, VehicleRoutingTransportCosts tpCosts) { + super(); + this.states = states; + this.transportCosts = tpCosts; + } + + @Override + public void begin(VehicleRoute route) { + this.route = route; + this.futureWaiting = 0.; + } + + @Override + public void visit(TourActivity activity) { + states.putInternalTypedActivityState(activity, route.getVehicle(), InternalStates.FUTURE_WAITING, futureWaiting); +// if(!(activity instanceof BreakActivity)) { + futureWaiting += Math.max(activity.getTheoreticalEarliestOperationStartTime() - activity.getArrTime(), 0); +// } + } + + @Override + public void finish() { + } +} diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/state/UpdateLoads.java b/jsprit-core/src/main/java/jsprit/core/algorithm/state/UpdateLoads.java index 7ad3afe7..ee8f3355 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/state/UpdateLoads.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/state/UpdateLoads.java @@ -31,88 +31,87 @@ import java.util.Collection; /** - * Updates load at start and end of route as well as at each activity. And update is triggered when either - * activityVisitor has been started, the insertion process has been started or a job has been inserted. - * + * Updates load at start and end of route as well as at each activity. And update is triggered when either + * activityVisitor has been started, the insertion process has been started or a job has been inserted. + *

*

Note that this only works properly if you register this class as ActivityVisitor AND InsertionStartsListener AND JobInsertedListener. - * The reason behind is that activity states are dependent on route-level states and vice versa. If this is properly registered, + * The reason behind is that activity states are dependent on route-level states and vice versa. If this is properly registered, * this dependency is solved automatically. - * - * @author stefan * + * @author stefan */ class UpdateLoads implements ActivityVisitor, StateUpdater, InsertionStartsListener, JobInsertedListener { - - private StateManager stateManager; - - /* - * default has one dimension with a value of zero - */ - private Capacity currentLoad; + + private StateManager stateManager; + + /* + * default has one dimension with a value of zero + */ + private Capacity currentLoad; private Capacity defaultValue; - - private VehicleRoute route; - - public UpdateLoads(StateManager stateManager) { - super(); - this.stateManager = stateManager; - defaultValue = Capacity.Builder.newInstance().build(); - } - - @Override - public void begin(VehicleRoute route) { - currentLoad = stateManager.getRouteState(route, InternalStates.LOAD_AT_BEGINNING, Capacity.class); - if(currentLoad == null) currentLoad = defaultValue; - this.route = route; - } - @Override - public void visit(TourActivity act) { - currentLoad = Capacity.addup(currentLoad, act.getSize()); - stateManager.putInternalTypedActivityState(act, InternalStates.LOAD, currentLoad); + private VehicleRoute route; + + public UpdateLoads(StateManager stateManager) { + super(); + this.stateManager = stateManager; + defaultValue = Capacity.Builder.newInstance().build(); + } + + @Override + public void begin(VehicleRoute route) { + currentLoad = stateManager.getRouteState(route, InternalStates.LOAD_AT_BEGINNING, Capacity.class); + if (currentLoad == null) currentLoad = defaultValue; + this.route = route; + } + + @Override + public void visit(TourActivity act) { + currentLoad = Capacity.addup(currentLoad, act.getSize()); + stateManager.putInternalTypedActivityState(act, InternalStates.LOAD, currentLoad); // assert currentLoad.isLessOrEqual(route.getVehicle().getType().getCapacityDimensions()) : "currentLoad at activity must not be > vehicleCapacity"; // assert currentLoad.isGreaterOrEqual(Capacity.Builder.newInstance().build()) : "currentLoad at act must not be < 0 in one of the applied dimensions"; - } + } - @Override - public void finish() { + @Override + public void finish() { currentLoad = Capacity.Builder.newInstance().build(); - } - - void insertionStarts(VehicleRoute route) { - Capacity loadAtDepot = Capacity.Builder.newInstance().build(); - Capacity loadAtEnd = Capacity.Builder.newInstance().build(); - for(Job j : route.getTourActivities().getJobs()){ - if(j instanceof Delivery){ - loadAtDepot = Capacity.addup(loadAtDepot, j.getSize()); - } - else if(j instanceof Pickup || j instanceof Service){ - loadAtEnd = Capacity.addup(loadAtEnd, j.getSize()); - } - } - stateManager.putTypedInternalRouteState(route, InternalStates.LOAD_AT_BEGINNING, loadAtDepot); - stateManager.putTypedInternalRouteState(route, InternalStates.LOAD_AT_END, loadAtEnd); - } + } - @Override - public void informInsertionStarts(Collection vehicleRoutes, Collection unassignedJobs) { - for(VehicleRoute route : vehicleRoutes){ insertionStarts(route); } - } - - @Override - public void informJobInserted(Job job2insert, VehicleRoute inRoute, double additionalCosts, double additionalTime) { - if(job2insert instanceof Delivery){ - Capacity loadAtDepot = stateManager.getRouteState(inRoute, InternalStates.LOAD_AT_BEGINNING, Capacity.class); - if(loadAtDepot == null) loadAtDepot = defaultValue; - stateManager.putTypedInternalRouteState(inRoute, InternalStates.LOAD_AT_BEGINNING, Capacity.addup(loadAtDepot, job2insert.getSize())); - } - else if(job2insert instanceof Pickup || job2insert instanceof Service){ - Capacity loadAtEnd = stateManager.getRouteState(inRoute, InternalStates.LOAD_AT_END, Capacity.class); - if(loadAtEnd == null) loadAtEnd = defaultValue; - stateManager.putTypedInternalRouteState(inRoute, InternalStates.LOAD_AT_END, Capacity.addup(loadAtEnd, job2insert.getSize())); - } - } + void insertionStarts(VehicleRoute route) { + Capacity loadAtDepot = Capacity.Builder.newInstance().build(); + Capacity loadAtEnd = Capacity.Builder.newInstance().build(); + for (Job j : route.getTourActivities().getJobs()) { + if (j instanceof Delivery) { + loadAtDepot = Capacity.addup(loadAtDepot, j.getSize()); + } else if (j instanceof Pickup || j instanceof Service) { + loadAtEnd = Capacity.addup(loadAtEnd, j.getSize()); + } + } + stateManager.putTypedInternalRouteState(route, InternalStates.LOAD_AT_BEGINNING, loadAtDepot); + stateManager.putTypedInternalRouteState(route, InternalStates.LOAD_AT_END, loadAtEnd); + } + + @Override + public void informInsertionStarts(Collection vehicleRoutes, Collection unassignedJobs) { + for (VehicleRoute route : vehicleRoutes) { + insertionStarts(route); + } + } + + @Override + public void informJobInserted(Job job2insert, VehicleRoute inRoute, double additionalCosts, double additionalTime) { + if (job2insert instanceof Delivery) { + Capacity loadAtDepot = stateManager.getRouteState(inRoute, InternalStates.LOAD_AT_BEGINNING, Capacity.class); + if (loadAtDepot == null) loadAtDepot = defaultValue; + stateManager.putTypedInternalRouteState(inRoute, InternalStates.LOAD_AT_BEGINNING, Capacity.addup(loadAtDepot, job2insert.getSize())); + } else if (job2insert instanceof Pickup || job2insert instanceof Service) { + Capacity loadAtEnd = stateManager.getRouteState(inRoute, InternalStates.LOAD_AT_END, Capacity.class); + if (loadAtEnd == null) loadAtEnd = defaultValue; + stateManager.putTypedInternalRouteState(inRoute, InternalStates.LOAD_AT_END, Capacity.addup(loadAtEnd, job2insert.getSize())); + } + } } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/state/UpdateMaxCapacityUtilisationAtActivitiesByLookingBackwardInRoute.java b/jsprit-core/src/main/java/jsprit/core/algorithm/state/UpdateMaxCapacityUtilisationAtActivitiesByLookingBackwardInRoute.java index 4355d6cd..b186d926 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/state/UpdateMaxCapacityUtilisationAtActivitiesByLookingBackwardInRoute.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/state/UpdateMaxCapacityUtilisationAtActivitiesByLookingBackwardInRoute.java @@ -24,40 +24,40 @@ import jsprit.core.problem.solution.route.activity.TourActivity; /** * Determines and memorizes the maximum capacity utilization at each activity by looking backward in route, * i.e. the maximum capacity utilization at previous activities. - * - * @author schroeder * + * @author schroeder */ class UpdateMaxCapacityUtilisationAtActivitiesByLookingBackwardInRoute implements ActivityVisitor, StateUpdater { - - private StateManager stateManager; - - private VehicleRoute route; - - private Capacity maxLoad; + + private StateManager stateManager; + + private VehicleRoute route; + + private Capacity maxLoad; private Capacity defaultValue; - - public UpdateMaxCapacityUtilisationAtActivitiesByLookingBackwardInRoute(StateManager stateManager) { - this.stateManager = stateManager; + + public UpdateMaxCapacityUtilisationAtActivitiesByLookingBackwardInRoute(StateManager stateManager) { + this.stateManager = stateManager; defaultValue = Capacity.Builder.newInstance().build(); - } + } - @Override - public void begin(VehicleRoute route) { - this.route = route; - maxLoad = stateManager.getRouteState(route, InternalStates.LOAD_AT_BEGINNING, Capacity.class); - if(maxLoad == null) maxLoad = defaultValue; - } + @Override + public void begin(VehicleRoute route) { + this.route = route; + maxLoad = stateManager.getRouteState(route, InternalStates.LOAD_AT_BEGINNING, Capacity.class); + if (maxLoad == null) maxLoad = defaultValue; + } - @Override - public void visit(TourActivity act) { - maxLoad = Capacity.max(maxLoad, stateManager.getActivityState(act, InternalStates.LOAD, Capacity.class)); - stateManager.putInternalTypedActivityState(act, InternalStates.PAST_MAXLOAD, maxLoad); + @Override + public void visit(TourActivity act) { + maxLoad = Capacity.max(maxLoad, stateManager.getActivityState(act, InternalStates.LOAD, Capacity.class)); + stateManager.putInternalTypedActivityState(act, InternalStates.PAST_MAXLOAD, maxLoad); // assert maxLoad.isGreaterOrEqual(Capacity.Builder.newInstance().build()) : "maxLoad can never be smaller than 0"; // assert maxLoad.isLessOrEqual(route.getVehicle().getType().getCapacityDimensions()) : "maxLoad can never be bigger than vehicleCap"; - } + } - @Override - public void finish() {} + @Override + public void finish() { + } } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/state/UpdateMaxCapacityUtilisationAtActivitiesByLookingForwardInRoute.java b/jsprit-core/src/main/java/jsprit/core/algorithm/state/UpdateMaxCapacityUtilisationAtActivitiesByLookingForwardInRoute.java index d66e7267..15b606a7 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/state/UpdateMaxCapacityUtilisationAtActivitiesByLookingForwardInRoute.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/state/UpdateMaxCapacityUtilisationAtActivitiesByLookingForwardInRoute.java @@ -23,10 +23,10 @@ import jsprit.core.problem.solution.route.activity.TourActivity; /** * A {@link ReverseActivityVisitor} that looks forward in the vehicle route and determines - * the maximum capacity utilization (in terms of loads) at subsequent activities. - * + * the maximum capacity utilization (in terms of loads) at subsequent activities. + *

*

Assume a vehicle route with the following activity sequence {start,pickup(1,4),delivery(2,3),pickup(3,2),end} where - * pickup(1,2) = pickup(id,cap-demand).
+ * pickup(1,2) = pickup(id,cap-demand).
* Future maxLoad for each activity are calculated as follows:
* loadAt(end)=6 (since two pickups need to be delivered to depot)
* pickup(3)=max(loadAt(pickup(3)), futureMaxLoad(end))=max(6,6)=6 @@ -35,42 +35,41 @@ import jsprit.core.problem.solution.route.activity.TourActivity; * start=max(7,7)=7 * activity (apart from start and end), the maximum capacity is determined when forward looking into the route. * That is at each activity we know how much capacity is available whithout breaking future capacity constraints. - * - * - * @author schroeder * + * @author schroeder */ class UpdateMaxCapacityUtilisationAtActivitiesByLookingForwardInRoute implements ReverseActivityVisitor, StateUpdater { - - private StateManager stateManager; - - private VehicleRoute route; - - private Capacity maxLoad; + + private StateManager stateManager; + + private VehicleRoute route; + + private Capacity maxLoad; private Capacity defaultValue; - - public UpdateMaxCapacityUtilisationAtActivitiesByLookingForwardInRoute(StateManager stateManager) { - super(); - this.stateManager = stateManager; + + public UpdateMaxCapacityUtilisationAtActivitiesByLookingForwardInRoute(StateManager stateManager) { + super(); + this.stateManager = stateManager; defaultValue = Capacity.Builder.newInstance().build(); - } + } - @Override - public void begin(VehicleRoute route) { - this.route = route; - maxLoad = stateManager.getRouteState(route, InternalStates.LOAD_AT_END, Capacity.class); - if(maxLoad == null) maxLoad = defaultValue; - } + @Override + public void begin(VehicleRoute route) { + this.route = route; + maxLoad = stateManager.getRouteState(route, InternalStates.LOAD_AT_END, Capacity.class); + if (maxLoad == null) maxLoad = defaultValue; + } - @Override - public void visit(TourActivity act) { - maxLoad = Capacity.max(maxLoad, stateManager.getActivityState(act, InternalStates.LOAD, Capacity.class)); - stateManager.putInternalTypedActivityState(act, InternalStates.FUTURE_MAXLOAD, maxLoad); + @Override + public void visit(TourActivity act) { + maxLoad = Capacity.max(maxLoad, stateManager.getActivityState(act, InternalStates.LOAD, Capacity.class)); + stateManager.putInternalTypedActivityState(act, InternalStates.FUTURE_MAXLOAD, maxLoad); // assert maxLoad.isLessOrEqual(route.getVehicle().getType().getCapacityDimensions()) : "maxLoad can in every capacity dimension never be bigger than vehicleCap"; // assert maxLoad.isGreaterOrEqual(Capacity.Builder.newInstance().build()) : "maxLoad can never be smaller than 0"; - } + } - @Override - public void finish() {} + @Override + public void finish() { + } } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/state/UpdateMaxCapacityUtilisationAtRoute.java b/jsprit-core/src/main/java/jsprit/core/algorithm/state/UpdateMaxCapacityUtilisationAtRoute.java index f903db84..8ebad292 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/state/UpdateMaxCapacityUtilisationAtRoute.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/state/UpdateMaxCapacityUtilisationAtRoute.java @@ -1,18 +1,18 @@ /******************************************************************************* * Copyright (c) 2014 Stefan Schroeder. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . - * + * * Contributors: * Stefan Schroeder - initial API and implementation ******************************************************************************/ @@ -24,50 +24,49 @@ import jsprit.core.problem.solution.route.activity.ActivityVisitor; import jsprit.core.problem.solution.route.activity.TourActivity; /** - * Updates load at activity level. - * + * Updates load at activity level. + *

*

Note that this assumes that StateTypes.LOAD_AT_DEPOT is already updated, i.e. it starts by setting loadAtDepot to StateTypes.LOAD_AT_DEPOT. * If StateTypes.LOAD_AT_DEPOT is not set, it starts with 0 load at depot. - * + *

*

Thus it DEPENDS on StateTypes.LOAD_AT_DEPOT - * - * @author stefan * + * @author stefan */ class UpdateMaxCapacityUtilisationAtRoute implements ActivityVisitor, StateUpdater { - - private StateManager stateManager; - - private Capacity currentLoad = Capacity.Builder.newInstance().build(); - - private VehicleRoute route; - - private Capacity maxLoad; + + private StateManager stateManager; + + private Capacity currentLoad = Capacity.Builder.newInstance().build(); + + private VehicleRoute route; + + private Capacity maxLoad; private Capacity defaultValue; - - public UpdateMaxCapacityUtilisationAtRoute(StateManager stateManager) { - super(); - this.stateManager = stateManager; + + public UpdateMaxCapacityUtilisationAtRoute(StateManager stateManager) { + super(); + this.stateManager = stateManager; defaultValue = Capacity.Builder.newInstance().build(); - } - - @Override - public void begin(VehicleRoute route) { - currentLoad = stateManager.getRouteState(route, InternalStates.LOAD_AT_BEGINNING, Capacity.class); - if(currentLoad == null) currentLoad = defaultValue; - maxLoad = currentLoad; - this.route = route; - } + } - @Override - public void visit(TourActivity act) { - currentLoad = Capacity.addup(currentLoad, act.getSize()); - maxLoad = Capacity.max(maxLoad, currentLoad); - } + @Override + public void begin(VehicleRoute route) { + currentLoad = stateManager.getRouteState(route, InternalStates.LOAD_AT_BEGINNING, Capacity.class); + if (currentLoad == null) currentLoad = defaultValue; + maxLoad = currentLoad; + this.route = route; + } - @Override - public void finish() { - stateManager.putTypedInternalRouteState(route, InternalStates.MAXLOAD, maxLoad); - } + @Override + public void visit(TourActivity act) { + currentLoad = Capacity.addup(currentLoad, act.getSize()); + maxLoad = Capacity.max(maxLoad, currentLoad); + } + + @Override + public void finish() { + stateManager.putTypedInternalRouteState(route, InternalStates.MAXLOAD, maxLoad); + } } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/state/UpdatePracticalTimeWindows.java b/jsprit-core/src/main/java/jsprit/core/algorithm/state/UpdatePracticalTimeWindows.java index 5a3a2d73..3c48c114 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/state/UpdatePracticalTimeWindows.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/state/UpdatePracticalTimeWindows.java @@ -26,63 +26,63 @@ import java.util.Collection; /** * Updates and memorizes latest operation start times at activities. - * - * @author schroeder * + * @author schroeder */ -class UpdatePracticalTimeWindows implements ReverseActivityVisitor, StateUpdater{ +class UpdatePracticalTimeWindows implements ReverseActivityVisitor, StateUpdater { - private StateManager states; - - private VehicleRoute route; - - private VehicleRoutingTransportCosts transportCosts; - - private double latestArrTimeAtPrevAct; - - private TourActivity prevAct; - - public UpdatePracticalTimeWindows(StateManager states, VehicleRoutingTransportCosts tpCosts) { - super(); - this.states = states; - this.transportCosts = tpCosts; - } + private StateManager states; - @Override - public void begin(VehicleRoute route) { - this.route = route; - latestArrTimeAtPrevAct = route.getEnd().getTheoreticalLatestOperationStartTime(); - prevAct = route.getEnd(); - } + private VehicleRoute route; - @Override - public void visit(TourActivity activity) { - double potentialLatestArrivalTimeAtCurrAct = latestArrTimeAtPrevAct - transportCosts.getBackwardTransportTime(activity.getLocation(), prevAct.getLocation(), latestArrTimeAtPrevAct, route.getDriver(),route.getVehicle()) - activity.getOperationTime(); - Collection timeWindows = activity.getTimeWindows(); - double latestArrivalTime = getLatestArrivalTime(timeWindows,potentialLatestArrivalTimeAtCurrAct); - states.putInternalTypedActivityState(activity, InternalStates.LATEST_OPERATION_START_TIME, latestArrivalTime); - - latestArrTimeAtPrevAct = latestArrivalTime; - prevAct = activity; - } + private VehicleRoutingTransportCosts transportCosts; - private double getLatestArrivalTime(Collection timeWindows, double potentialLatestArrivalTimeAtCurrAct) { - TimeWindow last = null; - for(TimeWindow tw : timeWindows){ - if(tw.getStart() <= potentialLatestArrivalTimeAtCurrAct && tw.getEnd() >= potentialLatestArrivalTimeAtCurrAct){ - return potentialLatestArrivalTimeAtCurrAct; - } - else if(tw.getStart() > potentialLatestArrivalTimeAtCurrAct){ - if(last == null){ - return potentialLatestArrivalTimeAtCurrAct; - } - else return last.getEnd(); - } - last = tw; - } - return last.getEnd(); - } + private double latestArrTimeAtPrevAct; - @Override - public void finish() {} + private TourActivity prevAct; + + public UpdatePracticalTimeWindows(StateManager states, VehicleRoutingTransportCosts tpCosts) { + super(); + this.states = states; + this.transportCosts = tpCosts; + } + + @Override + public void begin(VehicleRoute route) { + this.route = route; + latestArrTimeAtPrevAct = route.getEnd().getTheoreticalLatestOperationStartTime(); + prevAct = route.getEnd(); + } + + @Override + public void visit(TourActivity activity) { + double potentialLatestArrivalTimeAtCurrAct = latestArrTimeAtPrevAct - transportCosts.getBackwardTransportTime(activity.getLocation(), prevAct.getLocation(), latestArrTimeAtPrevAct, route.getDriver(),route.getVehicle()) - activity.getOperationTime(); + Collection timeWindows = activity.getTimeWindows(); + double latestArrivalTime = getLatestArrivalTime(timeWindows,potentialLatestArrivalTimeAtCurrAct); + states.putInternalTypedActivityState(activity, InternalStates.LATEST_OPERATION_START_TIME, latestArrivalTime); + + latestArrTimeAtPrevAct = latestArrivalTime; + prevAct = activity; + } + + private double getLatestArrivalTime(Collection timeWindows, double potentialLatestArrivalTimeAtCurrAct) { + TimeWindow last = null; + for(TimeWindow tw : timeWindows){ + if(tw.getStart() <= potentialLatestArrivalTimeAtCurrAct && tw.getEnd() >= potentialLatestArrivalTimeAtCurrAct){ + return potentialLatestArrivalTimeAtCurrAct; + } + else if(tw.getStart() > potentialLatestArrivalTimeAtCurrAct){ + if(last == null){ + return potentialLatestArrivalTimeAtCurrAct; + } + else return last.getEnd(); + } + last = tw; + } + return last.getEnd(); + } + + @Override + public void finish() { + } } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/state/UpdateSkills.java b/jsprit-core/src/main/java/jsprit/core/algorithm/state/UpdateSkills.java index 940ebd05..bafa2484 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/state/UpdateSkills.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/state/UpdateSkills.java @@ -8,7 +8,7 @@ import jsprit.core.problem.solution.route.activity.TourActivity; /** * Update to update required skills on route */ -public class UpdateSkills implements StateUpdater, ActivityVisitor{ +public class UpdateSkills implements StateUpdater, ActivityVisitor { private Skills.Builder skillBuilder; @@ -28,7 +28,7 @@ public class UpdateSkills implements StateUpdater, ActivityVisitor{ @Override public void visit(TourActivity activity) { - if(activity instanceof TourActivity.JobActivity){ + if (activity instanceof TourActivity.JobActivity) { Skills skills = ((TourActivity.JobActivity) activity).getJob().getRequiredSkills(); skillBuilder.addAllSkills(skills.values()); } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/state/UpdateVariableCosts.java b/jsprit-core/src/main/java/jsprit/core/algorithm/state/UpdateVariableCosts.java index 95b2c51e..8dddca4b 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/state/UpdateVariableCosts.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/state/UpdateVariableCosts.java @@ -27,47 +27,45 @@ import jsprit.core.util.ActivityTimeTracker; /** * Updates total costs (i.e. transport and activity costs) at route and activity level. - * + *

*

Thus it modifies stateManager.getRouteState(route, StateTypes.COSTS) and
* stateManager.getActivityState(activity, StateTypes.COSTS) - * */ -public class UpdateVariableCosts implements ActivityVisitor,StateUpdater{ +public class UpdateVariableCosts implements ActivityVisitor, StateUpdater { - private VehicleRoutingActivityCosts activityCost; + private VehicleRoutingActivityCosts activityCost; - private ForwardTransportCost transportCost; - - private StateManager states; - - private double totalOperationCost = 0.0; - - private VehicleRoute vehicleRoute = null; - - private TourActivity prevAct = null; - - private double startTimeAtPrevAct = 0.0; - - private ActivityTimeTracker timeTracker; - - /** - * Updates total costs (i.e. transport and activity costs) at route and activity level. - * - *

Thus it modifies stateManager.getRouteState(route, StateTypes.COSTS) and
- * stateManager.getActivityState(activity, StateTypes.COSTS) - * - * - * @param activityCost - * @param transportCost - * @param states - */ - public UpdateVariableCosts(VehicleRoutingActivityCosts activityCost, VehicleRoutingTransportCosts transportCost, StateManager states) { - super(); - this.activityCost = activityCost; - this.transportCost = transportCost; - this.states = states; - timeTracker = new ActivityTimeTracker(transportCost); - } + private ForwardTransportCost transportCost; + + private StateManager states; + + private double totalOperationCost = 0.0; + + private VehicleRoute vehicleRoute = null; + + private TourActivity prevAct = null; + + private double startTimeAtPrevAct = 0.0; + + private ActivityTimeTracker timeTracker; + + /** + * Updates total costs (i.e. transport and activity costs) at route and activity level. + *

+ *

Thus it modifies stateManager.getRouteState(route, StateTypes.COSTS) and
+ * stateManager.getActivityState(activity, StateTypes.COSTS) + * + * @param activityCost + * @param transportCost + * @param states + */ + public UpdateVariableCosts(VehicleRoutingActivityCosts activityCost, VehicleRoutingTransportCosts transportCost, StateManager states) { + super(); + this.activityCost = activityCost; + this.transportCost = transportCost; + this.states = states; + timeTracker = new ActivityTimeTracker(transportCost); + } public UpdateVariableCosts(VehicleRoutingActivityCosts activityCosts, VehicleRoutingTransportCosts transportCosts, StateManager stateManager, ActivityTimeTracker.ActivityPolicy activityPolicy) { this.activityCost = activityCosts; @@ -77,44 +75,44 @@ public class UpdateVariableCosts implements ActivityVisitor,StateUpdater{ } @Override - public void begin(VehicleRoute route) { - vehicleRoute = route; - timeTracker.begin(route); - prevAct = route.getStart(); - startTimeAtPrevAct = timeTracker.getActEndTime(); - } + public void begin(VehicleRoute route) { + vehicleRoute = route; + timeTracker.begin(route); + prevAct = route.getStart(); + startTimeAtPrevAct = timeTracker.getActEndTime(); + } - @Override - public void visit(TourActivity act) { - timeTracker.visit(act); - - double transportCost = this.transportCost.getTransportCost(prevAct.getLocation(), act.getLocation(), startTimeAtPrevAct, vehicleRoute.getDriver(), vehicleRoute.getVehicle()); - double actCost = activityCost.getActivityCost(act, timeTracker.getActArrTime(), vehicleRoute.getDriver(), vehicleRoute.getVehicle()); + @Override + public void visit(TourActivity act) { + timeTracker.visit(act); - totalOperationCost += transportCost; - totalOperationCost += actCost; + double transportCost = this.transportCost.getTransportCost(prevAct.getLocation(), act.getLocation(), startTimeAtPrevAct, vehicleRoute.getDriver(), vehicleRoute.getVehicle()); + double actCost = activityCost.getActivityCost(act, timeTracker.getActArrTime(), vehicleRoute.getDriver(), vehicleRoute.getVehicle()); - states.putInternalTypedActivityState(act, InternalStates.COSTS, totalOperationCost); + totalOperationCost += transportCost; + totalOperationCost += actCost; - prevAct = act; - startTimeAtPrevAct = timeTracker.getActEndTime(); - } + states.putInternalTypedActivityState(act, InternalStates.COSTS, totalOperationCost); - @Override - public void finish() { - timeTracker.finish(); - double transportCost = this.transportCost.getTransportCost(prevAct.getLocation(), vehicleRoute.getEnd().getLocation(), startTimeAtPrevAct, vehicleRoute.getDriver(), vehicleRoute.getVehicle()); - double actCost = activityCost.getActivityCost(vehicleRoute.getEnd(), timeTracker.getActEndTime(), vehicleRoute.getDriver(), vehicleRoute.getVehicle()); + prevAct = act; + startTimeAtPrevAct = timeTracker.getActEndTime(); + } - totalOperationCost += transportCost; - totalOperationCost += actCost; - - states.putTypedInternalRouteState(vehicleRoute, InternalStates.COSTS, totalOperationCost); - - startTimeAtPrevAct = 0.0; - prevAct = null; - vehicleRoute = null; - totalOperationCost = 0.0; - } + @Override + public void finish() { + timeTracker.finish(); + double transportCost = this.transportCost.getTransportCost(prevAct.getLocation(), vehicleRoute.getEnd().getLocation(), startTimeAtPrevAct, vehicleRoute.getDriver(), vehicleRoute.getVehicle()); + double actCost = activityCost.getActivityCost(vehicleRoute.getEnd(), timeTracker.getActEndTime(), vehicleRoute.getDriver(), vehicleRoute.getVehicle()); + + totalOperationCost += transportCost; + totalOperationCost += actCost; + + states.putTypedInternalRouteState(vehicleRoute, InternalStates.COSTS, totalOperationCost); + + startTimeAtPrevAct = 0.0; + prevAct = null; + vehicleRoute = null; + totalOperationCost = 0.0; + } } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/state/UpdateVehicleDependentPracticalTimeWindows.java b/jsprit-core/src/main/java/jsprit/core/algorithm/state/UpdateVehicleDependentPracticalTimeWindows.java index 0ea69524..f10e1be2 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/state/UpdateVehicleDependentPracticalTimeWindows.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/state/UpdateVehicleDependentPracticalTimeWindows.java @@ -19,16 +19,27 @@ package jsprit.core.algorithm.state; import jsprit.core.problem.Location; import jsprit.core.problem.cost.VehicleRoutingTransportCosts; +import jsprit.core.problem.solution.route.RouteVisitor; import jsprit.core.problem.solution.route.VehicleRoute; -import jsprit.core.problem.solution.route.activity.ReverseActivityVisitor; import jsprit.core.problem.solution.route.activity.TimeWindow; import jsprit.core.problem.solution.route.activity.TourActivity; import jsprit.core.problem.vehicle.Vehicle; import java.util.Arrays; import java.util.Collection; +import java.util.Iterator; -public class UpdateVehicleDependentPracticalTimeWindows implements ReverseActivityVisitor, StateUpdater{ +public class UpdateVehicleDependentPracticalTimeWindows implements RouteVisitor, StateUpdater { + + @Override + public void visit(VehicleRoute route) { + begin(route); + Iterator revIterator = route.getTourActivities().reverseActivityIterator(); + while (revIterator.hasNext()) { + visit(revIterator.next()); + } + finish(); + } public static interface VehiclesToUpdate { @@ -65,37 +76,38 @@ public class UpdateVehicleDependentPracticalTimeWindows implements ReverseActivi location_of_prevAct = new Location[stateManager.getMaxIndexOfVehicleTypeIdentifiers() + 1]; } - public void setVehiclesToUpdate(VehiclesToUpdate vehiclesToUpdate){ + public void setVehiclesToUpdate(VehiclesToUpdate vehiclesToUpdate) { this.vehiclesToUpdate = vehiclesToUpdate; } - @Override + public void begin(VehicleRoute route) { this.route = route; vehicles = vehiclesToUpdate.get(route); - for(Vehicle vehicle : vehicles){ + for (Vehicle vehicle : vehicles) { latest_arrTimes_at_prevAct[vehicle.getVehicleTypeIdentifier().getIndex()] = vehicle.getLatestArrival(); -// System.out.println("vehicle latest arr time: " + latest_arrTimes_at_prevAct); location_of_prevAct[vehicle.getVehicleTypeIdentifier().getIndex()] = vehicle.getEndLocation(); } } - @Override + public void visit(TourActivity activity) { - for(Vehicle vehicle : vehicles){ + for (Vehicle vehicle : vehicles) { double latestArrTimeAtPrevAct = latest_arrTimes_at_prevAct[vehicle.getVehicleTypeIdentifier().getIndex()]; Location prevLocation = location_of_prevAct[vehicle.getVehicleTypeIdentifier().getIndex()]; double potentialLatestArrivalTimeAtCurrAct = latestArrTimeAtPrevAct - transportCosts.getBackwardTransportTime(activity.getLocation(), prevLocation, - latestArrTimeAtPrevAct, route.getDriver(), vehicle) - activity.getOperationTime(); - double latestArrivalTime = getLatestArrivalTime(activity.getTimeWindows(),potentialLatestArrivalTimeAtCurrAct); -// System.out.println("update latest: " + latestArrivalTime + " activity: " + activity); + latestArrTimeAtPrevAct, route.getDriver(), vehicle) - activity.getOperationTime(); + double latestArrivalTime = getLatestArrivalTime(activity.getTimeWindows(), potentialLatestArrivalTimeAtCurrAct); + if (latestArrivalTime < activity.getTheoreticalEarliestOperationStartTime()) { + stateManager.putTypedInternalRouteState(route, vehicle, InternalStates.SWITCH_NOT_FEASIBLE, true); + } stateManager.putInternalTypedActivityState(activity, vehicle, InternalStates.LATEST_OPERATION_START_TIME, latestArrivalTime); latest_arrTimes_at_prevAct[vehicle.getVehicleTypeIdentifier().getIndex()] = latestArrivalTime; location_of_prevAct[vehicle.getVehicleTypeIdentifier().getIndex()] = activity.getLocation(); } } - @Override + public void finish() {} private double getLatestArrivalTime(Collection timeWindows, double potentialLatestArrivalTimeAtCurrAct) { diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/termination/IterationWithoutImprovementTermination.java b/jsprit-core/src/main/java/jsprit/core/algorithm/termination/IterationWithoutImprovementTermination.java index 404c5251..b424c569 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/termination/IterationWithoutImprovementTermination.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/termination/IterationWithoutImprovementTermination.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.termination; @@ -22,43 +22,42 @@ import org.apache.logging.log4j.Logger; /** * Terminates algorithm prematurely based on iterations without any improvement (i.e. new solution acceptance). - * + *

*

Termination will be activated by:
- * + *

* algorithm.setPrematureAlgorithmTermination(this);
* * @author stefan schroeder - * */ -public class IterationWithoutImprovementTermination implements PrematureAlgorithmTermination{ +public class IterationWithoutImprovementTermination implements PrematureAlgorithmTermination { - private static Logger log = LogManager.getLogger(IterationWithoutImprovementTermination.class); - - private int noIterationWithoutImprovement; - - private int iterationsWithoutImprovement = 0; + private static Logger log = LogManager.getLogger(IterationWithoutImprovementTermination.class); + + private int noIterationWithoutImprovement; + + private int iterationsWithoutImprovement = 0; /** * Constructs termination. * * @param noIterationsWithoutImprovement previous iterations without any improvement */ - public IterationWithoutImprovementTermination(int noIterationsWithoutImprovement){ - this.noIterationWithoutImprovement =noIterationsWithoutImprovement; - log.debug("initialise " + this); - } - - @Override - public String toString() { - return "[name=IterationWithoutImprovementBreaker][iterationsWithoutImprovement="+ noIterationWithoutImprovement +"]"; - } - - @Override - public boolean isPrematureBreak(DiscoveredSolution discoveredSolution) { - if(discoveredSolution.isAccepted()) iterationsWithoutImprovement = 0; - else iterationsWithoutImprovement++; - return (iterationsWithoutImprovement > noIterationWithoutImprovement); - } + public IterationWithoutImprovementTermination(int noIterationsWithoutImprovement) { + this.noIterationWithoutImprovement = noIterationsWithoutImprovement; + log.debug("initialise " + this); + } + + @Override + public String toString() { + return "[name=IterationWithoutImprovementBreaker][iterationsWithoutImprovement=" + noIterationWithoutImprovement + "]"; + } + + @Override + public boolean isPrematureBreak(DiscoveredSolution discoveredSolution) { + if (discoveredSolution.isAccepted()) iterationsWithoutImprovement = 0; + else iterationsWithoutImprovement++; + return (iterationsWithoutImprovement > noIterationWithoutImprovement); + } + - } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/termination/PrematureAlgorithmTermination.java b/jsprit-core/src/main/java/jsprit/core/algorithm/termination/PrematureAlgorithmTermination.java index 92c42d1d..858f0459 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/termination/PrematureAlgorithmTermination.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/termination/PrematureAlgorithmTermination.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.termination; @@ -20,7 +20,6 @@ import jsprit.core.algorithm.SearchStrategy.DiscoveredSolution; /** * Basic interface for prematureTermination. - * */ public interface PrematureAlgorithmTermination { @@ -30,6 +29,6 @@ public interface PrematureAlgorithmTermination { * @param discoveredSolution the discovered solution * @return true if algorithm should terminate, false otherwise */ - public boolean isPrematureBreak(DiscoveredSolution discoveredSolution); + public boolean isPrematureBreak(DiscoveredSolution discoveredSolution); } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/termination/TimeTermination.java b/jsprit-core/src/main/java/jsprit/core/algorithm/termination/TimeTermination.java index 4b3b872f..2081548a 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/termination/TimeTermination.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/termination/TimeTermination.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.termination; @@ -29,27 +29,26 @@ import java.util.Collection; /** * Terminates algorithm prematurely based on specified time. - * + *

*

Note, TimeTermination must be registered as AlgorithmListener
* TimeTermination will be activated by:
- * + *

* algorithm.setPrematureAlgorithmTermination(this);
* algorithm.addListener(this); - * - * @author stefan schroeder * + * @author stefan schroeder */ -public class TimeTermination implements PrematureAlgorithmTermination, AlgorithmStartsListener{ +public class TimeTermination implements PrematureAlgorithmTermination, AlgorithmStartsListener { - public static interface TimeGetter { + public static interface TimeGetter { public long getCurrentTime(); } private static Logger logger = LogManager.getLogger(TimeTermination.class); - - private final long timeThreshold; + + private final long timeThreshold; private TimeGetter timeGetter = new TimeGetter() { @@ -59,45 +58,45 @@ public class TimeTermination implements PrematureAlgorithmTermination, Algorithm } }; - - private long startTime; - - /** - * Constructs TimeTermination that terminates algorithm prematurely based on specified time. - * + + private long startTime; + + /** + * Constructs TimeTermination that terminates algorithm prematurely based on specified time. + * * @param timeThreshold_in_milliseconds the computation time [in ms] after which the algorithm terminates */ - public TimeTermination(long timeThreshold_in_milliseconds) { - super(); - this.timeThreshold = timeThreshold_in_milliseconds; - logger.debug("initialise " + this); - } + public TimeTermination(long timeThreshold_in_milliseconds) { + super(); + this.timeThreshold = timeThreshold_in_milliseconds; + logger.debug("initialise {}", this); + } public void setTimeGetter(TimeGetter timeGetter) { this.timeGetter = timeGetter; } @Override - public String toString() { - return "[name=TimeTermination][timeThreshold="+timeThreshold+" ms]"; - } + public String toString() { + return "[name=TimeTermination][timeThreshold=" + timeThreshold + " ms]"; + } - @Override - public boolean isPrematureBreak(DiscoveredSolution discoveredSolution) { - return ( now() - startTime ) > timeThreshold ; - } + @Override + public boolean isPrematureBreak(DiscoveredSolution discoveredSolution) { + return (now() - startTime) > timeThreshold; + } - void start(long startTime){ + void start(long startTime) { this.startTime = startTime; } - private long now(){ + private long now() { return timeGetter.getCurrentTime(); } - - @Override - public void informAlgorithmStarts(VehicleRoutingProblem problem,VehicleRoutingAlgorithm algorithm, Collection solutions) { - start(timeGetter.getCurrentTime()); - } + + @Override + public void informAlgorithmStarts(VehicleRoutingProblem problem, VehicleRoutingAlgorithm algorithm, Collection solutions) { + start(timeGetter.getCurrentTime()); + } } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/termination/VariationCoefficientTermination.java b/jsprit-core/src/main/java/jsprit/core/algorithm/termination/VariationCoefficientTermination.java index 40507f61..df47369e 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/termination/VariationCoefficientTermination.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/termination/VariationCoefficientTermination.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.termination; @@ -34,98 +34,93 @@ import java.util.Collection; /** * Terminates algorithm prematurely based on variationCoefficient (http://en.wikipedia.org/wiki/Coefficient_of_variation). - * + *

*

Note, that this must be registered as AlgorithmListener
* It will be activated by:
- * + *

* algorithm.setPrematureAlgorithmTermination(this);
* algorithm.addListener(this); * - * * @author stefan schroeder - * */ -public class VariationCoefficientTermination implements PrematureAlgorithmTermination, IterationStartsListener, AlgorithmStartsListener, IterationEndsListener{ +public class VariationCoefficientTermination implements PrematureAlgorithmTermination, IterationStartsListener, AlgorithmStartsListener, IterationEndsListener { - private final static Logger logger = LogManager.getLogger(VariationCoefficientTermination.class); - - private final int noIterations; - - private final double variationCoefficientThreshold; - - private int currentIteration; - - private double[] solutionValues; - - private VehicleRoutingProblemSolution lastAccepted = null; + private final static Logger logger = LogManager.getLogger(VariationCoefficientTermination.class); + + private final int noIterations; + + private final double variationCoefficientThreshold; + + private int currentIteration; + + private double[] solutionValues; + + private VehicleRoutingProblemSolution lastAccepted = null; /** * Constructs termination. * - * @param noIterations size of the sample, i.e. number previous solutions values to take into account. If for example - * noIterations = 10 then every 10th iteration the variationCoefficient will be calculated with the - * last 10 solution values. + * @param noIterations size of the sample, i.e. number previous solutions values to take into account. If for example + * noIterations = 10 then every 10th iteration the variationCoefficient will be calculated with the + * last 10 solution values. * @param variationCoefficientThreshold the threshold used to terminate the algorithm. If the calculated variationCoefficient * is smaller than the specified threshold, the algorithm terminates. */ - public VariationCoefficientTermination(int noIterations, double variationCoefficientThreshold) { - super(); - this.noIterations = noIterations; - this.variationCoefficientThreshold = variationCoefficientThreshold; - solutionValues = new double[noIterations]; - logger.debug("initialise " + this); - } - - @Override - public String toString() { - return "[name=VariationCoefficientBreaker][variationCoefficientThreshold="+variationCoefficientThreshold+"][iterations="+ noIterations +"]"; - } + public VariationCoefficientTermination(int noIterations, double variationCoefficientThreshold) { + super(); + this.noIterations = noIterations; + this.variationCoefficientThreshold = variationCoefficientThreshold; + solutionValues = new double[noIterations]; + logger.debug("initialise {}", this); + } - @Override - public boolean isPrematureBreak(DiscoveredSolution discoveredSolution) { - if(discoveredSolution.isAccepted()){ - lastAccepted = discoveredSolution.getSolution(); - solutionValues[currentIteration] = discoveredSolution.getSolution().getCost(); - } - else{ - if(lastAccepted != null){ - solutionValues[currentIteration] = lastAccepted.getCost(); - } - else solutionValues[currentIteration] = Integer.MAX_VALUE; - } - if(currentIteration == (noIterations - 1)){ - double mean = StatUtils.mean(solutionValues); - double stdDev = new StandardDeviation(true).evaluate(solutionValues, mean); - double variationCoefficient = stdDev / mean; - if(variationCoefficient < variationCoefficientThreshold){ - return true; - } - } - return false; - } - - private void reset(){ - currentIteration = 0; - } + @Override + public String toString() { + return "[name=VariationCoefficientBreaker][variationCoefficientThreshold=" + variationCoefficientThreshold + "][iterations=" + noIterations + "]"; + } - @Override - public void informAlgorithmStarts(VehicleRoutingProblem problem,VehicleRoutingAlgorithm algorithm,Collection solutions) { - reset(); - } + @Override + public boolean isPrematureBreak(DiscoveredSolution discoveredSolution) { + if (discoveredSolution.isAccepted()) { + lastAccepted = discoveredSolution.getSolution(); + solutionValues[currentIteration] = discoveredSolution.getSolution().getCost(); + } else { + if (lastAccepted != null) { + solutionValues[currentIteration] = lastAccepted.getCost(); + } else solutionValues[currentIteration] = Integer.MAX_VALUE; + } + if (currentIteration == (noIterations - 1)) { + double mean = StatUtils.mean(solutionValues); + double stdDev = new StandardDeviation(true).evaluate(solutionValues, mean); + double variationCoefficient = stdDev / mean; + if (variationCoefficient < variationCoefficientThreshold) { + return true; + } + } + return false; + } - @Override - public void informIterationEnds(int i, VehicleRoutingProblem problem, Collection solutions) { - if(currentIteration == (noIterations - 1)){ - reset(); - } - else{ - currentIteration++; - } - } + private void reset() { + currentIteration = 0; + } - @Override - public void informIterationStarts(int i, VehicleRoutingProblem problem, Collection solutions) { - if(lastAccepted == null) lastAccepted = Solutions.bestOf(solutions); - } + @Override + public void informAlgorithmStarts(VehicleRoutingProblem problem, VehicleRoutingAlgorithm algorithm, Collection solutions) { + reset(); + } + + @Override + public void informIterationEnds(int i, VehicleRoutingProblem problem, Collection solutions) { + if (currentIteration == (noIterations - 1)) { + reset(); + } else { + currentIteration++; + } + } + + @Override + public void informIterationStarts(int i, VehicleRoutingProblem problem, Collection solutions) { + if (lastAccepted == null) lastAccepted = Solutions.bestOf(solutions); + } } diff --git a/jsprit-core/src/main/java/jsprit/core/analysis/SolutionAnalyser.java b/jsprit-core/src/main/java/jsprit/core/analysis/SolutionAnalyser.java index 7fe18e59..655e9d5b 100644 --- a/jsprit-core/src/main/java/jsprit/core/analysis/SolutionAnalyser.java +++ b/jsprit-core/src/main/java/jsprit/core/analysis/SolutionAnalyser.java @@ -116,17 +116,16 @@ public class SolutionAnalyser { @Override public void visit(TourActivity activity) { - if(activity instanceof PickupActivity){ + if (activity instanceof PickupActivity) { pickupCounter++; pickedUp = Capacity.addup(pickedUp, ((PickupActivity) activity).getJob().getSize()); - if(activity instanceof PickupService){ + if (activity instanceof PickupService) { deliverAtEndCounter++; } - } - else if(activity instanceof DeliveryActivity){ + } else if (activity instanceof DeliveryActivity) { deliveryCounter++; delivered = Capacity.addup(delivered, ((DeliveryActivity) activity).getJob().getSize()); - if(activity instanceof DeliverService){ + if (activity instanceof DeliverService) { pickupAtBeginningCounter++; } } @@ -134,12 +133,12 @@ public class SolutionAnalyser { @Override public void finish() { - stateManager.putRouteState(route,pickup_count_id,pickupCounter); - stateManager.putRouteState(route,delivery_count_id,deliveryCounter); - stateManager.putRouteState(route,load_picked_id,pickedUp); - stateManager.putRouteState(route,load_delivered_id,delivered); - stateManager.putRouteState(route,pickup_at_beginning_count_id,pickupAtBeginningCounter); - stateManager.putRouteState(route,delivery_at_end_count_id,deliverAtEndCounter); + stateManager.putRouteState(route, pickup_count_id, pickupCounter); + stateManager.putRouteState(route, delivery_count_id, deliveryCounter); + stateManager.putRouteState(route, load_picked_id, pickedUp); + stateManager.putRouteState(route, load_delivered_id, delivered); + stateManager.putRouteState(route, pickup_at_beginning_count_id, pickupAtBeginningCounter); + stateManager.putRouteState(route, delivery_at_end_count_id, deliverAtEndCounter); } } @@ -151,7 +150,7 @@ public class SolutionAnalyser { private final StateManager stateManager; - private Map openShipments; + private Map openShipments; private VehicleRoute route; @@ -179,35 +178,30 @@ public class SolutionAnalyser { @Override public void visit(TourActivity activity) { //shipment - if(activity instanceof PickupShipment){ - openShipments.put(((PickupShipment) activity).getJob().getId(),(PickupShipment)activity); - } - else if(activity instanceof DeliverShipment){ + if (activity instanceof PickupShipment) { + openShipments.put(((PickupShipment) activity).getJob().getId(), (PickupShipment) activity); + } else if (activity instanceof DeliverShipment) { String jobId = ((DeliverShipment) activity).getJob().getId(); - if(!openShipments.containsKey(jobId)){ + if (!openShipments.containsKey(jobId)) { //deliverShipment without pickupShipment - stateManager.putActivityState(activity,shipment_id,true); + stateManager.putActivityState(activity, shipment_id, true); shipmentConstraintOnRouteViolated = true; - } - else { + } else { PickupShipment removed = openShipments.remove(jobId); - stateManager.putActivityState(removed,shipment_id,false); - stateManager.putActivityState(activity,shipment_id,false); + stateManager.putActivityState(removed, shipment_id, false); + stateManager.putActivityState(activity, shipment_id, false); } - } - else stateManager.putActivityState(activity,shipment_id,false); + } else stateManager.putActivityState(activity, shipment_id, false); //backhaul - if(activity instanceof DeliverService && pickupOccured){ - stateManager.putActivityState(activity,backhaul_id,true); + if (activity instanceof DeliverService && pickupOccured) { + stateManager.putActivityState(activity, backhaul_id, true); backhaulConstraintOnRouteViolated = true; - } - else{ - if(activity instanceof PickupService || activity instanceof ServiceActivity || activity instanceof PickupShipment){ + } else { + if (activity instanceof PickupService || activity instanceof ServiceActivity || activity instanceof PickupShipment) { pickupOccured = true; - stateManager.putActivityState(activity,backhaul_id,false); - } - else stateManager.putActivityState(activity,backhaul_id,false); + stateManager.putActivityState(activity, backhaul_id, false); + } else stateManager.putActivityState(activity, backhaul_id, false); } } @@ -215,13 +209,13 @@ public class SolutionAnalyser { public void finish() { //shipment //pickups without deliveries - for(TourActivity act : openShipments.values()){ - stateManager.putActivityState(act,shipment_id,true); + for (TourActivity act : openShipments.values()) { + stateManager.putActivityState(act, shipment_id, true); shipmentConstraintOnRouteViolated = true; } - stateManager.putRouteState(route,shipment_id,shipmentConstraintOnRouteViolated); + stateManager.putRouteState(route, shipment_id, shipmentConstraintOnRouteViolated); //backhaul - stateManager.putRouteState(route,backhaul_id,backhaulConstraintOnRouteViolated); + stateManager.putRouteState(route, backhaul_id, backhaulConstraintOnRouteViolated); } } @@ -275,9 +269,9 @@ public class SolutionAnalyser { //waiting time & toolate double waitAtAct = 0.; double tooLate = 0.; - if(activityPolicy.equals(ActivityTimeTracker.ActivityPolicy.AS_SOON_AS_TIME_WINDOW_OPENS)){ - waitAtAct = Math.max(0,activity.getTheoreticalEarliestOperationStartTime() - activity.getArrTime()); - tooLate = Math.max(0,activity.getArrTime() - activity.getTheoreticalLatestOperationStartTime()); + if (activityPolicy.equals(ActivityTimeTracker.ActivityPolicy.AS_SOON_AS_TIME_WINDOW_OPENS)) { + waitAtAct = Math.max(0, activity.getTheoreticalEarliestOperationStartTime() - activity.getArrTime()); + tooLate = Math.max(0, activity.getArrTime() - activity.getTheoreticalLatestOperationStartTime()); } sum_waiting_time += waitAtAct; sum_too_late += tooLate; @@ -287,7 +281,7 @@ public class SolutionAnalyser { prevActDeparture = activity.getEndTime(); //service time sum_service_time += activity.getOperationTime(); - + stateManager.putActivityState(activity, transport_time_id, sum_transport_time); } @@ -296,14 +290,14 @@ public class SolutionAnalyser { public void finish() { sum_transport_time += route.getEnd().getArrTime() - prevActDeparture; sum_too_late += Math.max(0, route.getEnd().getArrTime() - route.getEnd().getTheoreticalLatestOperationStartTime()); - stateManager.putRouteState(route,transport_time_id,sum_transport_time); - stateManager.putRouteState(route,waiting_time_id,sum_waiting_time); - stateManager.putRouteState(route,service_time_id,sum_service_time); - stateManager.putRouteState(route,too_late_id,sum_too_late); + stateManager.putRouteState(route, transport_time_id, sum_transport_time); + stateManager.putRouteState(route, waiting_time_id, sum_waiting_time); + stateManager.putRouteState(route, service_time_id, sum_service_time); + stateManager.putRouteState(route, too_late_id, sum_too_late); } } - - private static class LastTransportUpdater implements StateUpdater, ActivityVisitor{ + + private static class LastTransportUpdater implements StateUpdater, ActivityVisitor { private final StateManager stateManager; private final VehicleRoutingTransportCosts transportCost; private final DistanceCalculator distanceCalculator; @@ -314,52 +308,52 @@ public class SolutionAnalyser { private double prevActDeparture; private VehicleRoute route; - - private LastTransportUpdater(StateManager stateManager,VehicleRoutingTransportCosts transportCost, DistanceCalculator distanceCalculator, StateId last_distance_id, StateId last_time_id, StateId last_cost_id) { - this.stateManager = stateManager; - this.transportCost = transportCost; - this.distanceCalculator = distanceCalculator; - this.last_transport_distance_id = last_distance_id; - this.last_transport_time_id = last_time_id; - this.last_transport_cost_id = last_cost_id; - } - @Override - public void begin(VehicleRoute route) { - this.route = route; - this.prevAct = route.getStart(); - this.prevActDeparture = route.getDepartureTime(); - } + private LastTransportUpdater(StateManager stateManager, VehicleRoutingTransportCosts transportCost, DistanceCalculator distanceCalculator, StateId last_distance_id, StateId last_time_id, StateId last_cost_id) { + this.stateManager = stateManager; + this.transportCost = transportCost; + this.distanceCalculator = distanceCalculator; + this.last_transport_distance_id = last_distance_id; + this.last_transport_time_id = last_time_id; + this.last_transport_cost_id = last_cost_id; + } + + @Override + public void begin(VehicleRoute route) { + this.route = route; + this.prevAct = route.getStart(); + this.prevActDeparture = route.getDepartureTime(); + } + + @Override + public void visit(TourActivity activity) { + stateManager.putActivityState(activity, last_transport_distance_id, distance(activity)); + stateManager.putActivityState(activity, last_transport_time_id, transportTime(activity)); + stateManager.putActivityState(activity, last_transport_cost_id, transportCost(activity)); - @Override - public void visit(TourActivity activity) { - stateManager.putActivityState(activity,last_transport_distance_id,distance(activity)); - stateManager.putActivityState(activity,last_transport_time_id,transportTime(activity)); - stateManager.putActivityState(activity, last_transport_cost_id, transportCost(activity)); - prevAct = activity; - prevActDeparture = activity.getEndTime(); - } + prevActDeparture = activity.getEndTime(); + } - private double transportCost(TourActivity activity) { - return transportCost.getTransportCost(prevAct.getLocation(), activity.getLocation(), prevActDeparture, route.getDriver(), route.getVehicle()); - } + private double transportCost(TourActivity activity) { + return transportCost.getTransportCost(prevAct.getLocation(), activity.getLocation(), prevActDeparture, route.getDriver(), route.getVehicle()); + } - private double transportTime(TourActivity activity) { - return activity.getArrTime() - prevActDeparture; - } + private double transportTime(TourActivity activity) { + return activity.getArrTime() - prevActDeparture; + } - private double distance(TourActivity activity) { - return distanceCalculator.getDistance(prevAct.getLocation(),activity.getLocation()); - } + private double distance(TourActivity activity) { + return distanceCalculator.getDistance(prevAct.getLocation(), activity.getLocation()); + } + + @Override + public void finish() { + stateManager.putRouteState(route, last_transport_distance_id, distance(route.getEnd())); + stateManager.putRouteState(route, last_transport_time_id, transportTime(route.getEnd())); + stateManager.putRouteState(route, last_transport_cost_id, transportCost(route.getEnd())); + } - @Override - public void finish() { - stateManager.putRouteState(route,last_transport_distance_id,distance(route.getEnd())); - stateManager.putRouteState(route,last_transport_time_id,transportTime(route.getEnd())); - stateManager.putRouteState(route, last_transport_cost_id, transportCost(route.getEnd())); - } - } private static class DistanceUpdater implements StateUpdater, ActivityVisitor { @@ -391,9 +385,9 @@ public class SolutionAnalyser { @Override public void visit(TourActivity activity) { - double distance = distanceCalculator.getDistance(prevAct.getLocation(),activity.getLocation()); + double distance = distanceCalculator.getDistance(prevAct.getLocation(), activity.getLocation()); sum_distance += distance; - stateManager.putActivityState(activity,distance_id,sum_distance); + stateManager.putActivityState(activity, distance_id, sum_distance); prevAct = activity; } @@ -401,7 +395,7 @@ public class SolutionAnalyser { public void finish() { double distance = distanceCalculator.getDistance(prevAct.getLocation(), route.getEnd().getLocation()); sum_distance += distance; - stateManager.putRouteState(route,distance_id,sum_distance); + stateManager.putRouteState(route, distance_id, sum_distance); } } @@ -429,21 +423,21 @@ public class SolutionAnalyser { @Override public void visit(TourActivity activity) { boolean violatedAtActivity = false; - if(activity instanceof TourActivity.JobActivity){ + if (activity instanceof TourActivity.JobActivity) { Set requiredForActivity = ((TourActivity.JobActivity) activity).getJob().getRequiredSkills().values(); - for(String skill : requiredForActivity){ - if(!route.getVehicle().getSkills().containsSkill(skill)){ + for (String skill : requiredForActivity) { + if (!route.getVehicle().getSkills().containsSkill(skill)) { violatedAtActivity = true; skillConstraintViolatedOnRoute = true; } } } - stateManager.putActivityState(activity,skill_id,violatedAtActivity); + stateManager.putActivityState(activity, skill_id, violatedAtActivity); } @Override public void finish() { - stateManager.putRouteState(route,skill_id, skillConstraintViolatedOnRoute); + stateManager.putRouteState(route, skill_id, skillConstraintViolatedOnRoute); } } @@ -470,13 +464,13 @@ public class SolutionAnalyser { private StateId backhaul_id; private StateId skill_id; - + private StateId last_transport_distance_id; - + private StateId last_transport_time_id; - - private StateId last_transport_cost_id; - + + private StateId last_transport_cost_id; + private ActivityTimeTracker.ActivityPolicy activityPolicy; @@ -509,7 +503,6 @@ public class SolutionAnalyser { private VehicleRoutingProblemSolution solution; /** - * * @param vrp * @param solution * @param distanceCalculator @@ -531,7 +524,7 @@ public class SolutionAnalyser { this.distanceCalculator = new DistanceCalculator() { @Override public double getDistance(Location from, Location to) { - return distanceCalculator.getDistance(from,to); + return distanceCalculator.getDistance(from, to); } }; initialise(); @@ -554,8 +547,8 @@ public class SolutionAnalyser { this.stateManager.updateLoadStates(); this.stateManager.updateSkillStates(); activityPolicy = ActivityTimeTracker.ActivityPolicy.AS_SOON_AS_TIME_WINDOW_OPENS; - this.stateManager.addStateUpdater(new UpdateActivityTimes(vrp.getTransportCosts(),activityPolicy)); - this.stateManager.addStateUpdater(new UpdateVariableCosts(vrp.getActivityCosts(),vrp.getTransportCosts(),stateManager)); + this.stateManager.addStateUpdater(new UpdateActivityTimes(vrp.getTransportCosts(), activityPolicy)); + this.stateManager.addStateUpdater(new UpdateVariableCosts(vrp.getActivityCosts(), vrp.getTransportCosts(), stateManager)); waiting_time_id = stateManager.createStateId("waiting-time"); transport_time_id = stateManager.createStateId("transport-time"); service_time_id = stateManager.createStateId("service-time"); @@ -567,45 +560,45 @@ public class SolutionAnalyser { last_transport_cost_id = stateManager.createStateId("last-transport-cost"); last_transport_distance_id = stateManager.createStateId("last-transport-distance"); last_transport_time_id = stateManager.createStateId("last-transport-time"); - - stateManager.addStateUpdater(new SumUpActivityTimes(waiting_time_id, transport_time_id, service_time_id,too_late_id , stateManager, activityPolicy)); - stateManager.addStateUpdater(new DistanceUpdater(distance_id,stateManager,distanceCalculator)); - stateManager.addStateUpdater(new BackhaulAndShipmentUpdater(backhaul_id,shipment_id,stateManager)); - stateManager.addStateUpdater(new SkillUpdater(stateManager,skill_id)); + + stateManager.addStateUpdater(new SumUpActivityTimes(waiting_time_id, transport_time_id, service_time_id, too_late_id, stateManager, activityPolicy)); + stateManager.addStateUpdater(new DistanceUpdater(distance_id, stateManager, distanceCalculator)); + stateManager.addStateUpdater(new BackhaulAndShipmentUpdater(backhaul_id, shipment_id, stateManager)); + stateManager.addStateUpdater(new SkillUpdater(stateManager, skill_id)); stateManager.addStateUpdater(new LoadAndActivityCounter(stateManager)); - stateManager.addStateUpdater(new LastTransportUpdater(stateManager,vrp.getTransportCosts(), distanceCalculator, last_transport_distance_id, last_transport_time_id, last_transport_cost_id)); + stateManager.addStateUpdater(new LastTransportUpdater(stateManager, vrp.getTransportCosts(), distanceCalculator, last_transport_distance_id, last_transport_time_id, last_transport_cost_id)); } - private void refreshStates(){ + private void refreshStates() { stateManager.clear(); - stateManager.informInsertionStarts(solution.getRoutes(),null); + stateManager.informInsertionStarts(solution.getRoutes(), null); clearSolutionIndicators(); recalculateSolutionIndicators(); } private void recalculateSolutionIndicators() { - for(VehicleRoute route : solution.getRoutes()){ + for (VehicleRoute route : solution.getRoutes()) { tp_distance += getDistance(route); tp_time += getTransportTime(route); waiting_time += getWaitingTime(route); service_time += getServiceTime(route); operation_time += getOperationTime(route); tw_violation += getTimeWindowViolation(route); - cap_violation = Capacity.addup(cap_violation,getCapacityViolation(route)); + cap_violation = Capacity.addup(cap_violation, getCapacityViolation(route)); fixed_costs += getFixedCosts(route); variable_transport_costs += getVariableTransportCosts(route); - if(hasSkillConstraintViolation(route)) hasSkillConstraintViolation = true; - if(hasShipmentConstraintViolation(route)) hasShipmentConstraintViolation = true; - if(hasBackhaulConstraintViolation(route)) hasBackhaulConstraintViolation = true; + if (hasSkillConstraintViolation(route)) hasSkillConstraintViolation = true; + if (hasShipmentConstraintViolation(route)) hasShipmentConstraintViolation = true; + if (hasBackhaulConstraintViolation(route)) hasBackhaulConstraintViolation = true; noPickups += getNumberOfPickups(route); noPickupsAtBeginning += getNumberOfPickupsAtBeginning(route); noDeliveries += getNumberOfDeliveries(route); noDeliveriesAtEnd += getNumberOfDeliveriesAtEnd(route); - pickupLoad = Capacity.addup(pickupLoad,getLoadPickedUp(route)); - pickupLoadAtBeginning = Capacity.addup(pickupLoadAtBeginning,getLoadAtBeginning(route)); - deliveryLoad = Capacity.addup(deliveryLoad,getLoadDelivered(route)); - deliveryLoadAtEnd = Capacity.addup(deliveryLoadAtEnd,getLoadAtEnd(route)); + pickupLoad = Capacity.addup(pickupLoad, getLoadPickedUp(route)); + pickupLoadAtBeginning = Capacity.addup(pickupLoadAtBeginning, getLoadAtBeginning(route)); + deliveryLoad = Capacity.addup(deliveryLoad, getLoadDelivered(route)); + deliveryLoadAtEnd = Capacity.addup(deliveryLoadAtEnd, getLoadAtEnd(route)); } total_costs = solutionCostCalculator.getCosts(this.solution); } @@ -639,7 +632,7 @@ public class SolutionAnalyser { * * @param newSolution to be analysed */ - public void informSolutionChanged(VehicleRoutingProblemSolution newSolution){ + public void informSolutionChanged(VehicleRoutingProblemSolution newSolution) { this.solution = newSolution; refreshStates(); } @@ -648,47 +641,46 @@ public class SolutionAnalyser { * @param route to get the load at beginning from * @return load at start location of specified route */ - public Capacity getLoadAtBeginning(VehicleRoute route){ - if(route == null) throw new IllegalArgumentException("route is missing."); - return stateManager.getRouteState(route, InternalStates.LOAD_AT_BEGINNING,Capacity.class); + public Capacity getLoadAtBeginning(VehicleRoute route) { + if (route == null) throw new IllegalArgumentException("route is missing."); + return stateManager.getRouteState(route, InternalStates.LOAD_AT_BEGINNING, Capacity.class); } /** * @param route to get the load at the end from * @return load at end location of specified route */ - public Capacity getLoadAtEnd(VehicleRoute route){ - if(route == null) throw new IllegalArgumentException("route is missing."); - return stateManager.getRouteState(route, InternalStates.LOAD_AT_END,Capacity.class); + public Capacity getLoadAtEnd(VehicleRoute route) { + if (route == null) throw new IllegalArgumentException("route is missing."); + return stateManager.getRouteState(route, InternalStates.LOAD_AT_END, Capacity.class); } /** * @param route to get max load from * @return max load of specified route, i.e. for each capacity dimension the max value. */ - public Capacity getMaxLoad(VehicleRoute route){ - if(route == null) throw new IllegalArgumentException("route is missing."); - return stateManager.getRouteState(route, InternalStates.MAXLOAD,Capacity.class); + public Capacity getMaxLoad(VehicleRoute route) { + if (route == null) throw new IllegalArgumentException("route is missing."); + return stateManager.getRouteState(route, InternalStates.MAXLOAD, Capacity.class); } /** - * * @param activity to get the load from (after activity) * @return load right after the specified activity. If act is Start, it returns the load atBeginning of the specified * route. If act is End, it returns the load atEnd of specified route. * Returns null if no load can be found. */ - public Capacity getLoadRightAfterActivity(TourActivity activity, VehicleRoute route){ - if(route == null) throw new IllegalArgumentException("route is missing."); - if(activity == null) throw new IllegalArgumentException("activity is missing."); - if(activity instanceof Start) return getLoadAtBeginning(route); - if(activity instanceof End) return getLoadAtEnd(route); + public Capacity getLoadRightAfterActivity(TourActivity activity, VehicleRoute route) { + if (route == null) throw new IllegalArgumentException("route is missing."); + if (activity == null) throw new IllegalArgumentException("activity is missing."); + if (activity instanceof Start) return getLoadAtBeginning(route); + if (activity instanceof End) return getLoadAtEnd(route); verifyThatRouteContainsAct(activity, route); return stateManager.getActivityState(activity, InternalStates.LOAD, Capacity.class); } private void verifyThatRouteContainsAct(TourActivity activity, VehicleRoute route) { - if(!route.getTourActivities().hasActivity(activity)){ + if (!route.getTourActivities().hasActivity(activity)) { throw new IllegalArgumentException("specified route does not contain specified activity " + activity); } } @@ -698,17 +690,16 @@ public class SolutionAnalyser { * @return load just before the specified activity. If act is Start, it returns the load atBeginning of the specified * route. If act is End, it returns the load atEnd of specified route. */ - public Capacity getLoadJustBeforeActivity(TourActivity activity, VehicleRoute route){ - if(route == null) throw new IllegalArgumentException("route is missing."); - if(activity == null) throw new IllegalArgumentException("activity is missing."); - if(activity instanceof Start) return getLoadAtBeginning(route); - if(activity instanceof End) return getLoadAtEnd(route); + public Capacity getLoadJustBeforeActivity(TourActivity activity, VehicleRoute route) { + if (route == null) throw new IllegalArgumentException("route is missing."); + if (activity == null) throw new IllegalArgumentException("activity is missing."); + if (activity instanceof Start) return getLoadAtBeginning(route); + if (activity instanceof End) return getLoadAtEnd(route); verifyThatRouteContainsAct(activity, route); - Capacity afterAct = stateManager.getActivityState(activity, InternalStates.LOAD,Capacity.class); - if(afterAct != null && activity.getSize() != null){ + Capacity afterAct = stateManager.getActivityState(activity, InternalStates.LOAD, Capacity.class); + if (afterAct != null && activity.getSize() != null) { return Capacity.subtract(afterAct, activity.getSize()); - } - else if(afterAct != null) return afterAct; + } else if (afterAct != null) return afterAct; else return null; } @@ -716,46 +707,46 @@ public class SolutionAnalyser { * @param route to get number of pickups from * @return number of pickups picked up on specified route (without load at beginning) */ - public Integer getNumberOfPickups(VehicleRoute route){ - if(route == null) throw new IllegalArgumentException("route is missing."); - return stateManager.getRouteState(route,stateManager.createStateId(PICKUP_COUNT),Integer.class); + public Integer getNumberOfPickups(VehicleRoute route) { + if (route == null) throw new IllegalArgumentException("route is missing."); + return stateManager.getRouteState(route, stateManager.createStateId(PICKUP_COUNT), Integer.class); } /** * @param route to get number of deliveries from * @return number of deliveries delivered on specified route (without load at end) */ - public Integer getNumberOfDeliveries(VehicleRoute route){ - if(route == null) throw new IllegalArgumentException("route is missing."); - return stateManager.getRouteState(route,stateManager.createStateId(DELIVERY_COUNT),Integer.class); + public Integer getNumberOfDeliveries(VehicleRoute route) { + if (route == null) throw new IllegalArgumentException("route is missing."); + return stateManager.getRouteState(route, stateManager.createStateId(DELIVERY_COUNT), Integer.class); } /** * @param route to get the picked load from * @return picked load (without load at beginning) */ - public Capacity getLoadPickedUp(VehicleRoute route){ - if(route == null) throw new IllegalArgumentException("route is missing."); - return stateManager.getRouteState(route,stateManager.createStateId(LOAD_PICKED),Capacity.class); + public Capacity getLoadPickedUp(VehicleRoute route) { + if (route == null) throw new IllegalArgumentException("route is missing."); + return stateManager.getRouteState(route, stateManager.createStateId(LOAD_PICKED), Capacity.class); } /** * @param route to get delivered load from * @return delivered laod (without load at end) */ - public Capacity getLoadDelivered(VehicleRoute route){ - if(route == null) throw new IllegalArgumentException("route is missing."); - return stateManager.getRouteState(route,stateManager.createStateId(LOAD_DELIVERED),Capacity.class); + public Capacity getLoadDelivered(VehicleRoute route) { + if (route == null) throw new IllegalArgumentException("route is missing."); + return stateManager.getRouteState(route, stateManager.createStateId(LOAD_DELIVERED), Capacity.class); } /** * @param route to get the capacity violation from * @return the capacity violation on this route, i.e. maxLoad - vehicleCapacity */ - public Capacity getCapacityViolation(VehicleRoute route){ - if(route == null) throw new IllegalArgumentException("route is missing."); + public Capacity getCapacityViolation(VehicleRoute route) { + if (route == null) throw new IllegalArgumentException("route is missing."); Capacity maxLoad = getMaxLoad(route); - return Capacity.max(Capacity.Builder.newInstance().build(),Capacity.subtract(maxLoad,route.getVehicle().getType().getCapacityDimensions())); + return Capacity.max(Capacity.Builder.newInstance().build(), Capacity.subtract(maxLoad, route.getVehicle().getType().getCapacityDimensions())); } /** @@ -764,10 +755,10 @@ public class SolutionAnalyser { * dimension with dimIndex=0 and dimIndex=1 and dimIndex=1 is violated by 4 units then this method returns * [[dimIndex=0][dimValue=0][dimIndex=1][dimValue=4]] */ - public Capacity getCapacityViolationAtBeginning(VehicleRoute route){ - if(route == null) throw new IllegalArgumentException("route is missing."); + public Capacity getCapacityViolationAtBeginning(VehicleRoute route) { + if (route == null) throw new IllegalArgumentException("route is missing."); Capacity atBeginning = getLoadAtBeginning(route); - return Capacity.max(Capacity.Builder.newInstance().build(),Capacity.subtract(atBeginning,route.getVehicle().getType().getCapacityDimensions())); + return Capacity.max(Capacity.Builder.newInstance().build(), Capacity.subtract(atBeginning, route.getVehicle().getType().getCapacityDimensions())); } /** @@ -776,10 +767,10 @@ public class SolutionAnalyser { * dimension with dimIndex=0 and dimIndex=1 and dimIndex=1 is violated by 4 units then this method returns * [[dimIndex=0][dimValue=0][dimIndex=1][dimValue=4]] */ - public Capacity getCapacityViolationAtEnd(VehicleRoute route){ - if(route == null) throw new IllegalArgumentException("route is missing."); + public Capacity getCapacityViolationAtEnd(VehicleRoute route) { + if (route == null) throw new IllegalArgumentException("route is missing."); Capacity atEnd = getLoadAtEnd(route); - return Capacity.max(Capacity.Builder.newInstance().build(),Capacity.subtract(atEnd,route.getVehicle().getType().getCapacityDimensions())); + return Capacity.max(Capacity.Builder.newInstance().build(), Capacity.subtract(atEnd, route.getVehicle().getType().getCapacityDimensions())); } @@ -789,30 +780,30 @@ public class SolutionAnalyser { * dimension with dimIndex=0 and dimIndex=1 and dimIndex=1 is violated by 4 units then this method returns * [[dimIndex=0][dimValue=0][dimIndex=1][dimValue=4]] */ - public Capacity getCapacityViolationAfterActivity(TourActivity activity, VehicleRoute route){ - if(route == null) throw new IllegalArgumentException("route is missing."); - if(activity == null) throw new IllegalArgumentException("activity is missing."); - Capacity afterAct = getLoadRightAfterActivity(activity,route); - return Capacity.max(Capacity.Builder.newInstance().build(),Capacity.subtract(afterAct,route.getVehicle().getType().getCapacityDimensions())); + public Capacity getCapacityViolationAfterActivity(TourActivity activity, VehicleRoute route) { + if (route == null) throw new IllegalArgumentException("route is missing."); + if (activity == null) throw new IllegalArgumentException("activity is missing."); + Capacity afterAct = getLoadRightAfterActivity(activity, route); + return Capacity.max(Capacity.Builder.newInstance().build(), Capacity.subtract(afterAct, route.getVehicle().getType().getCapacityDimensions())); } /** * @param route to get the time window violation from * @return time violation of route, i.e. sum of individual activity time window violations. */ - public Double getTimeWindowViolation(VehicleRoute route){ - if(route == null) throw new IllegalArgumentException("route is missing."); + public Double getTimeWindowViolation(VehicleRoute route) { + if (route == null) throw new IllegalArgumentException("route is missing."); return stateManager.getRouteState(route, too_late_id, Double.class); } /** * @param activity to get the time window violation from - * @param route where activity needs to be part of + * @param route where activity needs to be part of * @return time violation of activity */ - public Double getTimeWindowViolationAtActivity(TourActivity activity, VehicleRoute route){ - if(route == null) throw new IllegalArgumentException("route is missing."); - if(activity == null) throw new IllegalArgumentException("activity is missing."); + public Double getTimeWindowViolationAtActivity(TourActivity activity, VehicleRoute route) { + if (route == null) throw new IllegalArgumentException("route is missing."); + if (activity == null) throw new IllegalArgumentException("activity is missing."); return Math.max(0, activity.getArrTime() - activity.getTheoreticalLatestOperationStartTime()); } @@ -821,23 +812,23 @@ public class SolutionAnalyser { * @return true if skill constraint is violated, i.e. if vehicle does not have the required skills to conduct all * activities on the specified route. Returns null if route is null or skill state cannot be found. */ - public Boolean hasSkillConstraintViolation(VehicleRoute route){ - if(route == null) throw new IllegalArgumentException("route is missing."); + public Boolean hasSkillConstraintViolation(VehicleRoute route) { + if (route == null) throw new IllegalArgumentException("route is missing."); return stateManager.getRouteState(route, skill_id, Boolean.class); } /** * @param activity to check skill constraint - * @param route that must contain specified activity + * @param route that must contain specified activity * @return true if vehicle does not have the skills to conduct specified activity, false otherwise. Returns null * if specified route or activity is null or if route does not contain specified activity or if skill state connot be * found. If specified activity is Start or End, it returns false. */ - public Boolean hasSkillConstraintViolationAtActivity(TourActivity activity, VehicleRoute route){ - if(route == null) throw new IllegalArgumentException("route is missing."); - if(activity == null) throw new IllegalArgumentException("activity is missing."); - if(activity instanceof Start) return false; - if(activity instanceof End) return false; + public Boolean hasSkillConstraintViolationAtActivity(TourActivity activity, VehicleRoute route) { + if (route == null) throw new IllegalArgumentException("route is missing."); + if (activity == null) throw new IllegalArgumentException("activity is missing."); + if (activity instanceof Start) return false; + if (activity instanceof End) return false; verifyThatRouteContainsAct(activity, route); return stateManager.getActivityState(activity, skill_id, Boolean.class); } @@ -852,24 +843,24 @@ public class SolutionAnalyser { * @return true if backhaul constraint for specified route is violated. returns null if route is null or no backhaul * state can be found. In latter case try routeChanged(route). */ - public Boolean hasBackhaulConstraintViolation(VehicleRoute route){ - if(route == null) throw new IllegalArgumentException("route is missing."); - return stateManager.getRouteState(route,backhaul_id,Boolean.class); + public Boolean hasBackhaulConstraintViolation(VehicleRoute route) { + if (route == null) throw new IllegalArgumentException("route is missing."); + return stateManager.getRouteState(route, backhaul_id, Boolean.class); } /** * @param activity to check backhaul violation - * @param route that must contain the specified activity + * @param route that must contain the specified activity * @return true if backhaul constraint is violated, false otherwise. Null if either specified route or activity is null. * Null if specified route does not contain specified activity. */ - public Boolean hasBackhaulConstraintViolationAtActivity(TourActivity activity, VehicleRoute route){ - if(route == null) throw new IllegalArgumentException("route is missing."); - if(activity == null) throw new IllegalArgumentException("activity is missing."); - if(activity instanceof Start) return false; - if(activity instanceof End) return false; + public Boolean hasBackhaulConstraintViolationAtActivity(TourActivity activity, VehicleRoute route) { + if (route == null) throw new IllegalArgumentException("route is missing."); + if (activity == null) throw new IllegalArgumentException("activity is missing."); + if (activity instanceof Start) return false; + if (activity instanceof End) return false; verifyThatRouteContainsAct(activity, route); - return stateManager.getActivityState(activity,backhaul_id,Boolean.class); + return stateManager.getActivityState(activity, backhaul_id, Boolean.class); } /** @@ -880,9 +871,9 @@ public class SolutionAnalyser { * @param route to check the shipment constraint. * @return true if violated, false otherwise. Null if no state can be found or specified route is null. */ - public Boolean hasShipmentConstraintViolation(VehicleRoute route){ - if(route == null) throw new IllegalArgumentException("route is missing."); - return stateManager.getRouteState(route,shipment_id,Boolean.class); + public Boolean hasShipmentConstraintViolation(VehicleRoute route) { + if (route == null) throw new IllegalArgumentException("route is missing."); + return stateManager.getRouteState(route, shipment_id, Boolean.class); } /** @@ -890,27 +881,26 @@ public class SolutionAnalyser { * found before OR activity is pickupShipment and no deliverShipment can be found afterwards. * * @param activity to check the shipment constraint - * @param route that must contain specified activity + * @param route that must contain specified activity * @return true if shipment constraint is violated, false otherwise. If activity is either Start or End, it returns * false. Returns null if either specified activity or route is null or route does not containt activity. */ - public Boolean hasShipmentConstraintViolationAtActivity(TourActivity activity, VehicleRoute route){ - if(route == null) throw new IllegalArgumentException("route is missing."); - if(activity == null) throw new IllegalArgumentException("activity is missing."); - if(activity instanceof Start) return false; - if(activity instanceof End) return false; + public Boolean hasShipmentConstraintViolationAtActivity(TourActivity activity, VehicleRoute route) { + if (route == null) throw new IllegalArgumentException("route is missing."); + if (activity == null) throw new IllegalArgumentException("activity is missing."); + if (activity instanceof Start) return false; + if (activity instanceof End) return false; verifyThatRouteContainsAct(activity, route); - return stateManager.getActivityState(activity,shipment_id,Boolean.class); + return stateManager.getActivityState(activity, shipment_id, Boolean.class); } - /** * @param route to get the total operation time from * @return operation time of this route, i.e. endTime - startTime of specified route */ - public Double getOperationTime(VehicleRoute route){ - if(route == null) throw new IllegalArgumentException("route is missing."); + public Double getOperationTime(VehicleRoute route) { + if (route == null) throw new IllegalArgumentException("route is missing."); return route.getEnd().getArrTime() - route.getStart().getEndTime(); } @@ -919,8 +909,8 @@ public class SolutionAnalyser { * @return total waiting time of this route, i.e. sum of waiting times at activities. * Returns null if no waiting time value exists for the specified route */ - public Double getWaitingTime(VehicleRoute route){ - if(route == null) throw new IllegalArgumentException("route is missing."); + public Double getWaitingTime(VehicleRoute route) { + if (route == null) throw new IllegalArgumentException("route is missing."); return stateManager.getRouteState(route, waiting_time_id, Double.class); } @@ -928,8 +918,8 @@ public class SolutionAnalyser { * @param route to get the total transport time from * @return total transport time of specified route. Returns null if no time value exists for the specified route. */ - public Double getTransportTime(VehicleRoute route){ - if(route == null) throw new IllegalArgumentException("route is missing."); + public Double getTransportTime(VehicleRoute route) { + if (route == null) throw new IllegalArgumentException("route is missing."); return stateManager.getRouteState(route, transport_time_id, Double.class); } @@ -937,8 +927,8 @@ public class SolutionAnalyser { * @param route to get the total service time from * @return total service time of specified route. Returns null if no time value exists for specified route. */ - public Double getServiceTime(VehicleRoute route){ - if(route == null) throw new IllegalArgumentException("route is missing."); + public Double getServiceTime(VehicleRoute route) { + if (route == null) throw new IllegalArgumentException("route is missing."); return stateManager.getRouteState(route, service_time_id, Double.class); } @@ -947,103 +937,99 @@ public class SolutionAnalyser { * @return total variable transport costs of route, i.e. sum of transport costs specified by * vrp.getTransportCosts().getTransportCost(fromId,toId,...) */ - public Double getVariableTransportCosts(VehicleRoute route){ - if(route == null) throw new IllegalArgumentException("route is missing."); + public Double getVariableTransportCosts(VehicleRoute route) { + if (route == null) throw new IllegalArgumentException("route is missing."); - return stateManager.getRouteState(route,InternalStates.COSTS,Double.class); + return stateManager.getRouteState(route, InternalStates.COSTS, Double.class); } /** * @param route to get the fixed costs from * @return fixed costs of route, i.e. fixed costs of employed vehicle on this route. */ - public Double getFixedCosts(VehicleRoute route){ - if(route == null) throw new IllegalArgumentException("route is missing."); + public Double getFixedCosts(VehicleRoute route) { + if (route == null) throw new IllegalArgumentException("route is missing."); return route.getVehicle().getType().getVehicleCostParams().fix; } /** * @param activity to get the variable transport costs from - * @param route where the activity should be part of + * @param route where the activity should be part of * @return variable transport costs at activity, i.e. sum of transport costs from start of route to the specified activity * If activity is start, it returns 0.. If it is end, it returns .getVariableTransportCosts(route). */ - public Double getVariableTransportCostsAtActivity(TourActivity activity, VehicleRoute route){ - if(route == null) throw new IllegalArgumentException("route is missing."); - if(activity == null) throw new IllegalArgumentException("activity is missing."); - if(activity instanceof Start) return 0.; - if(activity instanceof End) return getVariableTransportCosts(route); + public Double getVariableTransportCostsAtActivity(TourActivity activity, VehicleRoute route) { + if (route == null) throw new IllegalArgumentException("route is missing."); + if (activity == null) throw new IllegalArgumentException("activity is missing."); + if (activity instanceof Start) return 0.; + if (activity instanceof End) return getVariableTransportCosts(route); verifyThatRouteContainsAct(activity, route); - return stateManager.getActivityState(activity,InternalStates.COSTS,Double.class); + return stateManager.getActivityState(activity, InternalStates.COSTS, Double.class); } /** - * * @param activity to get the transport time from - * @param route where the activity should be part of + * @param route where the activity should be part of * @return transport time at the activity, i.e. the total time spent driving since the start of the route to the specified activity. */ - public Double getTransportTimeAtActivity(TourActivity activity, VehicleRoute route){ - if(route == null) throw new IllegalArgumentException("route is missing."); - if(activity == null) throw new IllegalArgumentException("activity is missing."); - if(activity instanceof Start) return 0.; - if(activity instanceof End) return getTransportTime(route); + public Double getTransportTimeAtActivity(TourActivity activity, VehicleRoute route) { + if (route == null) throw new IllegalArgumentException("route is missing."); + if (activity == null) throw new IllegalArgumentException("activity is missing."); + if (activity instanceof Start) return 0.; + if (activity instanceof End) return getTransportTime(route); verifyThatRouteContainsAct(activity, route); - return stateManager.getActivityState(activity,transport_time_id,Double.class); - } - - /** - * - * @param activity to get the last transport time from - * @param route where the activity should be part of - * @return The transport time from the previous activity to this one. - */ - public Double getLastTransportTimeAtActivity(TourActivity activity, VehicleRoute route){ - return getLastTransport(activity, route, last_transport_time_id); + return stateManager.getActivityState(activity, transport_time_id, Double.class); + } + + /** + * @param activity to get the last transport time from + * @param route where the activity should be part of + * @return The transport time from the previous activity to this one. + */ + public Double getLastTransportTimeAtActivity(TourActivity activity, VehicleRoute route) { + return getLastTransport(activity, route, last_transport_time_id); } /** - * * @param activity to get the last transport distance from - * @param route where the activity should be part of + * @param route where the activity should be part of * @return The transport distance from the previous activity to this one. */ - public Double getLastTransportDistanceAtActivity(TourActivity activity, VehicleRoute route){ - return getLastTransport(activity, route, last_transport_distance_id); + public Double getLastTransportDistanceAtActivity(TourActivity activity, VehicleRoute route) { + return getLastTransport(activity, route, last_transport_distance_id); } - + /** - * * @param activity to get the last transport cost from - * @param route where the activity should be part of + * @param route where the activity should be part of * @return The transport cost from the previous activity to this one. */ - public Double getLastTransportCostAtActivity(TourActivity activity, VehicleRoute route){ - return getLastTransport(activity, route, last_transport_cost_id); + public Double getLastTransportCostAtActivity(TourActivity activity, VehicleRoute route) { + return getLastTransport(activity, route, last_transport_cost_id); } - - - private Double getLastTransport(TourActivity activity, VehicleRoute route, StateId id){ - if(route == null) throw new IllegalArgumentException("route is missing."); - if(activity == null) throw new IllegalArgumentException("activity is missing."); - if(activity instanceof Start) return 0.; - if(activity instanceof End) return stateManager.getRouteState(route, id, Double.class); + + + private Double getLastTransport(TourActivity activity, VehicleRoute route, StateId id) { + if (route == null) throw new IllegalArgumentException("route is missing."); + if (activity == null) throw new IllegalArgumentException("activity is missing."); + if (activity instanceof Start) return 0.; + if (activity instanceof End) return stateManager.getRouteState(route, id, Double.class); verifyThatRouteContainsAct(activity, route); - return stateManager.getActivityState(activity,id,Double.class); + return stateManager.getActivityState(activity, id, Double.class); } - + /** * @param activity to get the waiting from - * @param route where activity should be part of + * @param route where activity should be part of * @return waiting time at activity */ - public Double getWaitingTimeAtActivity(TourActivity activity, VehicleRoute route){ - if(route == null) throw new IllegalArgumentException("route is missing."); - if(activity == null) throw new IllegalArgumentException("activity is missing."); + public Double getWaitingTimeAtActivity(TourActivity activity, VehicleRoute route) { + if (route == null) throw new IllegalArgumentException("route is missing."); + if (activity == null) throw new IllegalArgumentException("activity is missing."); double waitingTime = 0.; - if(activityPolicy.equals(ActivityTimeTracker.ActivityPolicy.AS_SOON_AS_TIME_WINDOW_OPENS)){ - waitingTime = Math.max(0,activity.getTheoreticalEarliestOperationStartTime()-activity.getArrTime()); + if (activityPolicy.equals(ActivityTimeTracker.ActivityPolicy.AS_SOON_AS_TIME_WINDOW_OPENS)) { + waitingTime = Math.max(0, activity.getTheoreticalEarliestOperationStartTime() - activity.getArrTime()); } return waitingTime; } @@ -1052,8 +1038,8 @@ public class SolutionAnalyser { * @param route to get the distance from * @return total distance of route */ - public Double getDistance(VehicleRoute route){ - if(route == null) throw new IllegalArgumentException("route is missing."); + public Double getDistance(VehicleRoute route) { + if (route == null) throw new IllegalArgumentException("route is missing."); return stateManager.getRouteState(route, distance_id, Double.class); } @@ -1061,11 +1047,11 @@ public class SolutionAnalyser { * @param activity at which is distance of the current route is measured * @return distance at activity */ - public Double getDistanceAtActivity(TourActivity activity, VehicleRoute route){ - if(route == null) throw new IllegalArgumentException("route is missing."); - if(activity == null) throw new IllegalArgumentException("activity is missing."); - if(activity instanceof Start) return 0.; - if(activity instanceof End) return getDistance(route); + public Double getDistanceAtActivity(TourActivity activity, VehicleRoute route) { + if (route == null) throw new IllegalArgumentException("route is missing."); + if (activity == null) throw new IllegalArgumentException("activity is missing."); + if (activity instanceof Start) return 0.; + if (activity instanceof End) return getDistance(route); verifyThatRouteContainsAct(activity, route); return stateManager.getActivityState(activity, distance_id, Double.class); } @@ -1073,7 +1059,7 @@ public class SolutionAnalyser { /** * @return number of pickups in specified solution (without load at beginning of each route) */ - public Integer getNumberOfPickups(){ + public Integer getNumberOfPickups() { return noPickups; } @@ -1081,29 +1067,29 @@ public class SolutionAnalyser { * @param route to get the number of pickups at beginning from * @return number of pickups at beginning */ - public Integer getNumberOfPickupsAtBeginning(VehicleRoute route){ - if(route == null) throw new IllegalArgumentException("route is missing."); - return stateManager.getRouteState(route,stateManager.createStateId(PICKUP_COUNT_AT_BEGINNING),Integer.class); + public Integer getNumberOfPickupsAtBeginning(VehicleRoute route) { + if (route == null) throw new IllegalArgumentException("route is missing."); + return stateManager.getRouteState(route, stateManager.createStateId(PICKUP_COUNT_AT_BEGINNING), Integer.class); } /** * @return number of pickups in specified solution at beginning of each route */ - public Integer getNumberOfPickupsAtBeginning(){ + public Integer getNumberOfPickupsAtBeginning() { return noPickupsAtBeginning; } /** * @return number of deliveries in specified solution (without load at end of each route) */ - public Integer getNumberOfDeliveries(){ + public Integer getNumberOfDeliveries() { return noDeliveries; } /** * @return number of deliveries in specified solution at end of each route */ - public Integer getNumberOfDeliveriesAtEnd(){ + public Integer getNumberOfDeliveriesAtEnd() { return noDeliveriesAtEnd; } @@ -1111,137 +1097,131 @@ public class SolutionAnalyser { * @param route to get the number of deliveries at end from * @return number of deliveries at end of specified route */ - public Integer getNumberOfDeliveriesAtEnd(VehicleRoute route){ - if(route == null) throw new IllegalArgumentException("route is missing."); - return stateManager.getRouteState(route,stateManager.createStateId(DELIVERY_COUNT_AT_END),Integer.class); + public Integer getNumberOfDeliveriesAtEnd(VehicleRoute route) { + if (route == null) throw new IllegalArgumentException("route is missing."); + return stateManager.getRouteState(route, stateManager.createStateId(DELIVERY_COUNT_AT_END), Integer.class); } /** * @return load picked up in solution (without load at beginning of each route) */ - public Capacity getLoadPickedUp(){ + public Capacity getLoadPickedUp() { return pickupLoad; } /** * @return load picked up in solution at beginning of each route */ - public Capacity getLoadAtBeginning(){ + public Capacity getLoadAtBeginning() { return pickupLoadAtBeginning; } /** * @return load delivered in solution (without load at end of each route) */ - public Capacity getLoadDelivered(){ + public Capacity getLoadDelivered() { return deliveryLoad; } /** * @return load delivered in solution at end of each route */ - public Capacity getLoadAtEnd(){ + public Capacity getLoadAtEnd() { return deliveryLoadAtEnd; } - /** * @return total distance for specified solution */ - public Double getDistance(){ + public Double getDistance() { return tp_distance; } /** * @return total operation time for specified solution */ - public Double getOperationTime(){ - return operation_time; + public Double getOperationTime() { + return operation_time; } /** * @return total waiting time for specified solution */ - public Double getWaitingTime(){ + public Double getWaitingTime() { return waiting_time; } /** * @return total transportation time */ - public Double getTransportTime(){ + public Double getTransportTime() { return tp_time; } /** * @return total time window violation for specified solution */ - public Double getTimeWindowViolation(){ + public Double getTimeWindowViolation() { return tw_violation; } /** * @return total capacity violation for specified solution */ - public Capacity getCapacityViolation(){ + public Capacity getCapacityViolation() { return cap_violation; } /** * @return total service time for specified solution */ - public Double getServiceTime(){ + public Double getServiceTime() { return service_time; } /** * @return total fixed costs for specified solution */ - public Double getFixedCosts(){ + public Double getFixedCosts() { return fixed_costs; } /** * @return total variable transport costs for specified solution */ - public Double getVariableTransportCosts(){ + public Double getVariableTransportCosts() { return variable_transport_costs; } /** * @return total costs defined by solutionCostCalculator */ - public Double getTotalCosts(){ + public Double getTotalCosts() { return total_costs; } /** * @return true if at least one route in specified solution has shipment constraint violation */ - public Boolean hasShipmentConstraintViolation(){ + public Boolean hasShipmentConstraintViolation() { return hasShipmentConstraintViolation; } /** * @return true if at least one route in specified solution has backhaul constraint violation */ - public Boolean hasBackhaulConstraintViolation(){ + public Boolean hasBackhaulConstraintViolation() { return hasBackhaulConstraintViolation; } /** * @return true if at least one route in specified solution has skill constraint violation */ - public Boolean hasSkillConstraintViolation(){ + public Boolean hasSkillConstraintViolation() { return hasSkillConstraintViolation; } - - - - - } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/AbstractActivity.java b/jsprit-core/src/main/java/jsprit/core/problem/AbstractActivity.java index 634255a7..736ae2a5 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/AbstractActivity.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/AbstractActivity.java @@ -9,7 +9,11 @@ public abstract class AbstractActivity implements TourActivity { private int index; - public int getIndex(){ return index; } + public int getIndex() { + return index; + } - protected void setIndex(int index){ this.index = index; } + protected void setIndex(int index) { + this.index = index; + } } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/AbstractJob.java b/jsprit-core/src/main/java/jsprit/core/problem/AbstractJob.java index 4e48e444..558bdb05 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/AbstractJob.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/AbstractJob.java @@ -9,8 +9,12 @@ public abstract class AbstractJob implements Job { private int index; - public int getIndex(){ return index; } + public int getIndex() { + return index; + } - protected void setIndex(int index){ this.index = index; } + protected void setIndex(int index) { + this.index = index; + } } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/AbstractVehicle.java b/jsprit-core/src/main/java/jsprit/core/problem/AbstractVehicle.java index 87c7896f..d8414362 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/AbstractVehicle.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/AbstractVehicle.java @@ -12,9 +12,13 @@ public abstract class AbstractVehicle implements Vehicle { private int index; - public int getIndex(){ return index; } + public int getIndex() { + return index; + } - public void setIndex(int index) { this.index = index; } + public void setIndex(int index) { + this.index = index; + } } @@ -22,15 +26,19 @@ public abstract class AbstractVehicle implements Vehicle { private VehicleTypeKey vehicleIdentifier; - public int getIndex(){ return index; } + public int getIndex() { + return index; + } - protected void setIndex(int index){ this.index = index; } + protected void setIndex(int index) { + this.index = index; + } - public VehicleTypeKey getVehicleTypeIdentifier(){ + public VehicleTypeKey getVehicleTypeIdentifier() { return vehicleIdentifier; } - protected void setVehicleIdentifier(VehicleTypeKey vehicleTypeIdentifier){ + protected void setVehicleIdentifier(VehicleTypeKey vehicleTypeIdentifier) { this.vehicleIdentifier = vehicleTypeIdentifier; } } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/Capacity.java b/jsprit-core/src/main/java/jsprit/core/problem/Capacity.java index 172d4579..dc7c7e30 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/Capacity.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/Capacity.java @@ -18,284 +18,277 @@ package jsprit.core.problem; /** * Capacity with an arbitrary number of capacity-dimension. - * + *

*

Note that this assumes the the values of each capacity dimension can be added up and subtracted - * - * @author schroeder * + * @author schroeder */ public class Capacity { - /** - * Adds up two capacities, i.e. sums up each and every capacity dimension, and returns the resulting Capacity. - * - *

Note that this assumes that capacity dimension can be added up. - * - * @param cap1 capacity to be added up - * @param cap2 capacity to be added up - * @return new capacity - * @throws NullPointerException if one of the args is null + /** + * Adds up two capacities, i.e. sums up each and every capacity dimension, and returns the resulting Capacity. + *

+ *

Note that this assumes that capacity dimension can be added up. + * + * @param cap1 capacity to be added up + * @param cap2 capacity to be added up + * @return new capacity + * @throws NullPointerException if one of the args is null + */ + public static Capacity addup(Capacity cap1, Capacity cap2) { + if (cap1 == null || cap2 == null) throw new NullPointerException("arguments must not be null"); + Capacity.Builder capacityBuilder = Capacity.Builder.newInstance(); + for (int i = 0; i < Math.max(cap1.getNuOfDimensions(), cap2.getNuOfDimensions()); i++) { + capacityBuilder.addDimension(i, cap1.get(i) + cap2.get(i)); + } + return capacityBuilder.build(); + } - */ - public static Capacity addup(Capacity cap1, Capacity cap2){ - if(cap1==null || cap2==null) throw new NullPointerException("arguments must not be null"); - Capacity.Builder capacityBuilder= Capacity.Builder.newInstance(); - for(int i=0;icap1.getNuOfDimension() != cap2.getNuOfDimension()). - * - */ - public static Capacity subtract(Capacity cap, Capacity cap2subtract){ - if(cap==null || cap2subtract==null) throw new NullPointerException("arguments must not be null"); - Capacity.Builder capacityBuilder= Capacity.Builder.newInstance(); - for(int i=0;iIf both nominator.get(i) and denominator.get(i) equal to 0, dimension i is ignored. - *

If both capacities are have only dimensions with dimensionVal=0, it returns 0.0 - * @param numerator the numerator - * @param denominator the denominator - * @return quotient - * @throws IllegalStateException if numerator.get(i) != 0 and denominator.get(i) == 0 - */ - public static double divide(Capacity numerator, Capacity denominator){ - int nuOfDimensions = 0; - double sumQuotients = 0.0; - for(int index=0;index 0 and denominator = 0. cannot divide by 0"); - } - else if(numerator.get(index) == 0 && denominator.get(index) == 0){ - continue; - } - else{ - nuOfDimensions++; - sumQuotients += (double)numerator.get(index)/(double)denominator.get(index); - } - } - if(nuOfDimensions > 0) return sumQuotients/(double)nuOfDimensions; - return 0.0; - } - - /** - * Makes a deep copy of Capacity. - * - * @param capacity capacity to be copied - * @return copy - */ - public static Capacity copyOf(Capacity capacity){ - if(capacity == null) return null; - return new Capacity(capacity); - } - - /** - * Builder that builds Capacity - * - * @author schroeder - * - */ - public static class Builder { - - /** - * default is 1 dimension with size of zero - */ - private int[] dimensions = new int[1]; - - /** - * Returns a new instance of Capacity with one dimension and a value/size of 0 - * - * @return this builder - */ - public static Builder newInstance(){ - return new Builder(); - } - - Builder(){} - - /** - * add capacity dimension - * - *

Note that it automatically resizes dimensions according to index, i.e. if index=7 there are 8 dimensions. - * New dimensions then are initialized with 0 - * - * @param index dimensionIndex - * @param dimValue dimensionValue - * @return this builder - */ - public Builder addDimension(int index, int dimValue){ - if(index < dimensions.length){ - dimensions[index] = dimValue; - } - else{ - int requiredSize = index + 1; - int[] newDimensions = new int[requiredSize]; - copy(dimensions,newDimensions); - newDimensions[index]=dimValue; - this.dimensions=newDimensions; - } - return this; - } - - private void copy(int[] from, int[] to) { - for(int i=0;icap1.getNuOfDimension() != cap2.getNuOfDimension()). + */ + public static Capacity subtract(Capacity cap, Capacity cap2subtract) { + if (cap == null || cap2subtract == null) throw new NullPointerException("arguments must not be null"); + Capacity.Builder capacityBuilder = Capacity.Builder.newInstance(); + for (int i = 0; i < Math.max(cap.getNuOfDimensions(), cap2subtract.getNuOfDimensions()); i++) { + int dimValue = cap.get(i) - cap2subtract.get(i); + capacityBuilder.addDimension(i, dimValue); + } + return capacityBuilder.build(); + } - /** - * Builds an immutable Capacity and returns it. - * - * @return Capacity - */ - public Capacity build() { - return new Capacity(this); - } + /** + * Returns the inverted capacity, i.e. it multiplies all capacity dimensions with -1. + * + * @param cap2invert capacity to be inverted + * @return inverted capacity + * @throws NullPointerException if one of the args is null + */ + public static Capacity invert(Capacity cap2invert) { + if (cap2invert == null) throw new NullPointerException("arguments must not be null"); + Capacity.Builder capacityBuilder = Capacity.Builder.newInstance(); + for (int i = 0; i < cap2invert.getNuOfDimensions(); i++) { + int dimValue = cap2invert.get(i) * -1; + capacityBuilder.addDimension(i, dimValue); + } + return capacityBuilder.build(); + } - - } - - private int[] dimensions; - - /** - * copy constructor - * - * @param capacity capacity to be copied - */ - Capacity(Capacity capacity){ - this.dimensions = new int[capacity.getNuOfDimensions()]; - for(int i=0;i + *

If both nominator.get(i) and denominator.get(i) equal to 0, dimension i is ignored. + *

If both capacities are have only dimensions with dimensionVal=0, it returns 0.0 + * + * @param numerator the numerator + * @param denominator the denominator + * @return quotient + * @throws IllegalStateException if numerator.get(i) != 0 and denominator.get(i) == 0 + */ + public static double divide(Capacity numerator, Capacity denominator) { + int nuOfDimensions = 0; + double sumQuotients = 0.0; + for (int index = 0; index < Math.max(numerator.getNuOfDimensions(), denominator.getNuOfDimensions()); index++) { + if (numerator.get(index) != 0 && denominator.get(index) == 0) { + throw new IllegalStateException("numerator > 0 and denominator = 0. cannot divide by 0"); + } else if (numerator.get(index) == 0 && denominator.get(index) == 0) { + continue; + } else { + nuOfDimensions++; + sumQuotients += (double) numerator.get(index) / (double) denominator.get(index); + } + } + if (nuOfDimensions > 0) return sumQuotients / (double) nuOfDimensions; + return 0.0; + } - /** - * Returns the number of specified capacity dimensions. - * - * @return noDimensions - */ - public int getNuOfDimensions(){ - return dimensions.length; - } + /** + * Makes a deep copy of Capacity. + * + * @param capacity capacity to be copied + * @return copy + */ + public static Capacity copyOf(Capacity capacity) { + if (capacity == null) return null; + return new Capacity(capacity); + } + + /** + * Builder that builds Capacity + * + * @author schroeder + */ + public static class Builder { + + /** + * default is 1 dimension with size of zero + */ + private int[] dimensions = new int[1]; + + /** + * Returns a new instance of Capacity with one dimension and a value/size of 0 + * + * @return this builder + */ + public static Builder newInstance() { + return new Builder(); + } + + Builder() { + } + + /** + * add capacity dimension + *

+ *

Note that it automatically resizes dimensions according to index, i.e. if index=7 there are 8 dimensions. + * New dimensions then are initialized with 0 + * + * @param index dimensionIndex + * @param dimValue dimensionValue + * @return this builder + */ + public Builder addDimension(int index, int dimValue) { + if (index < dimensions.length) { + dimensions[index] = dimValue; + } else { + int requiredSize = index + 1; + int[] newDimensions = new int[requiredSize]; + copy(dimensions, newDimensions); + newDimensions[index] = dimValue; + this.dimensions = newDimensions; + } + return this; + } + + private void copy(int[] from, int[] to) { + for (int i = 0; i < dimensions.length; i++) { + to[i] = from[i]; + } + } + + /** + * Builds an immutable Capacity and returns it. + * + * @return Capacity + */ + public Capacity build() { + return new Capacity(this); + } - - /** - * Returns value of capacity-dimension with specified index. - * - *

If capacity dimension does not exist, it returns 0 (rather than IndexOutOfBoundsException). - * - * @param index dimension index of the capacity value to be retrieved - * @return the according dimension value - */ - public int get(int index){ - if(index than the corresponding dimension in toCompare. - * - * @param toCompare the capacity to compare - * @return true if this capacity is less or equal than toCompare - * @throws NullPointerException if one of the args is null - */ - public boolean isLessOrEqual(Capacity toCompare){ - if(toCompare == null) throw new NullPointerException(); - for(int i=0;i toCompare.get(i)) return false; - } - return true; - } - - /** - * Returns true if this capacity is greater or equal than the capacity toCompare - * - * @param toCompare the capacity to compare - * @return true if this capacity is greater or equal than toCompare - * @throws NullPointerException if one of the args is null - - */ - public boolean isGreaterOrEqual(Capacity toCompare) { - if(toCompare == null) throw new NullPointerException(); - for(int i=0;i + *

If capacity dimension does not exist, it returns 0 (rather than IndexOutOfBoundsException). + * + * @param index dimension index of the capacity value to be retrieved + * @return the according dimension value + */ + public int get(int index) { + if (index < dimensions.length) return dimensions[index]; + return 0; + } + + /** + * Returns true if this capacity is less or equal than the capacity toCompare, i.e. if none of the capacity dimensions > than the corresponding dimension in toCompare. + * + * @param toCompare the capacity to compare + * @return true if this capacity is less or equal than toCompare + * @throws NullPointerException if one of the args is null + */ + public boolean isLessOrEqual(Capacity toCompare) { + if (toCompare == null) throw new NullPointerException(); + for (int i = 0; i < this.getNuOfDimensions(); i++) { + if (this.get(i) > toCompare.get(i)) return false; + } + return true; + } + + /** + * Returns true if this capacity is greater or equal than the capacity toCompare + * + * @param toCompare the capacity to compare + * @return true if this capacity is greater or equal than toCompare + * @throws NullPointerException if one of the args is null + */ + public boolean isGreaterOrEqual(Capacity toCompare) { + if (toCompare == null) throw new NullPointerException(); + for (int i = 0; i < Math.max(this.getNuOfDimensions(), toCompare.getNuOfDimensions()); i++) { + if (this.get(i) < toCompare.get(i)) return false; + } + return true; + } + + @Override + public String toString() { + String string = "[noDimensions=" + getNuOfDimensions() + "]"; + for (int i = 0; i < getNuOfDimensions(); i++) { + string += "[[dimIndex=" + i + "][dimValue=" + dimensions[i] + "]]"; } return string; - } + } + + /** + * Return the maximum, i.e. the maximum of each capacity dimension. + * + * @param cap1 first capacity to compare + * @param cap2 second capacity to compare + * @return capacity maximum of each capacity dimension + */ + public static Capacity max(Capacity cap1, Capacity cap2) { + if (cap1 == null || cap2 == null) throw new IllegalArgumentException("arg must not be null"); + Capacity.Builder toReturnBuilder = Capacity.Builder.newInstance(); + for (int i = 0; i < Math.max(cap1.getNuOfDimensions(), cap2.getNuOfDimensions()); i++) { + toReturnBuilder.addDimension(i, Math.max(cap1.get(i), cap2.get(i))); + } + return toReturnBuilder.build(); + } + + public static Capacity min(Capacity cap1, Capacity cap2) { + if (cap1 == null || cap2 == null) throw new IllegalArgumentException("arg must not be null"); + Capacity.Builder toReturnBuilder = Capacity.Builder.newInstance(); + for (int i = 0; i < Math.max(cap1.getNuOfDimensions(), cap2.getNuOfDimensions()); i++) { + toReturnBuilder.addDimension(i, Math.min(cap1.get(i), cap2.get(i))); + } + return toReturnBuilder.build(); + } - /** - * Return the maximum, i.e. the maximum of each capacity dimension. - * - * @param cap1 first capacity to compare - * @param cap2 second capacity to compare - * @return capacity maximum of each capacity dimension - */ - public static Capacity max(Capacity cap1, Capacity cap2) { - if(cap1 == null || cap2 == null) throw new IllegalArgumentException("arg must not be null"); - Capacity.Builder toReturnBuilder = Capacity.Builder.newInstance(); - for(int i=0;i= 0"); + public Builder setIndex(int index) { + if (index < 0) throw new IllegalArgumentException("index must be >= 0"); this.index = index; return this; } - public Builder setCoordinate(Coordinate coordinate){ + public Builder setCoordinate(Coordinate coordinate) { this.coordinate = coordinate; return this; } - public Builder setId(String id){ + public Builder setId(String id) { this.id = id; return this; } - public Location build(){ - if(id == null && coordinate == null){ - if(index == -1) throw new IllegalStateException("either id or coordinate or index must be set"); + public Location build() { + if (id == null && coordinate == null) { + if (index == -1) throw new IllegalStateException("either id or coordinate or index must be set"); } - if(coordinate != null && id == null){ + if (coordinate != null && id == null) { this.id = coordinate.toString(); } - if(index != -1 && id == null){ + if (index != -1 && id == null) { this.id = Integer.toString(index); } return new Location(this); @@ -120,7 +122,7 @@ public final class Location implements HasIndex, HasId{ return index; } - public Coordinate getCoordinate(){ + public Coordinate getCoordinate() { return coordinate; } @@ -148,6 +150,6 @@ public final class Location implements HasIndex, HasId{ @Override public String toString() { - return "[id="+id+"][index="+index+"][coordinate="+coordinate+"]"; + return "[id=" + id + "][index=" + index + "][coordinate=" + coordinate + "]"; } } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/Skills.java b/jsprit-core/src/main/java/jsprit/core/problem/Skills.java index 36142574..ba5d255f 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/Skills.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/Skills.java @@ -34,7 +34,7 @@ public class Skills { * * @return builder */ - public static Builder newInstance(){ + public static Builder newInstance() { return new Builder(); } @@ -46,8 +46,8 @@ public class Skills { * @param skill skill to be added * @return builder */ - public Builder addSkill(String skill){ - skills.add(skill.toLowerCase()); + public Builder addSkill(String skill) { + skills.add(skill.trim().toLowerCase()); return this; } @@ -57,8 +57,8 @@ public class Skills { * @param skills collection of skills to be added * @return builder */ - public Builder addAllSkills(Collection skills){ - for(String skill : skills) this.skills.add(skill); + public Builder addAllSkills(Collection skills) { + for (String skill : skills) addSkill(skill); return this; } @@ -67,7 +67,7 @@ public class Skills { * * @return skills */ - public Skills build(){ + public Skills build() { return new Skills(this); } @@ -75,7 +75,7 @@ public class Skills { private Set skills = new HashSet(); - private Skills(Builder builder){ + private Skills(Builder builder) { skills.addAll(builder.skills); } @@ -84,19 +84,18 @@ public class Skills { * * @return set of skills in this containter */ - public Set values(){ + public Set values() { return Collections.unmodifiableSet(skills); } - public String toString(){ + public String toString() { String s = "["; boolean first = true; - for(String skill : values()){ - if(first){ + for (String skill : values()) { + if (first) { s += skill; first = false; - } - else s += ", " + skill; + } else s += ", " + skill; } s += "]"; return s; @@ -108,7 +107,7 @@ public class Skills { * @param skill which is checked whether it is in skill container or not * @return true if skill is included, false otherwise */ - public boolean containsSkill(String skill){ + public boolean containsSkill(String skill) { return skills.contains(skill.toLowerCase()); } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/VehicleRoutingProblem.java b/jsprit-core/src/main/java/jsprit/core/problem/VehicleRoutingProblem.java index 57a4c376..bdfdcde2 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/VehicleRoutingProblem.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/VehicleRoutingProblem.java @@ -11,18 +11,19 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.problem; import jsprit.core.problem.cost.VehicleRoutingActivityCosts; import jsprit.core.problem.cost.VehicleRoutingTransportCosts; -import jsprit.core.problem.driver.Driver; +import jsprit.core.problem.cost.WaitingTimeCosts; import jsprit.core.problem.job.Job; import jsprit.core.problem.job.Service; import jsprit.core.problem.job.Shipment; import jsprit.core.problem.solution.route.VehicleRoute; +import jsprit.core.problem.solution.route.activity.BreakActivity; import jsprit.core.problem.solution.route.activity.DefaultShipmentActivityFactory; import jsprit.core.problem.solution.route.activity.DefaultTourActivityFactory; import jsprit.core.problem.solution.route.activity.TourActivity; @@ -41,79 +42,65 @@ import java.util.*; /** * Contains and defines the vehicle routing problem. - * + *

*

A routing problem is defined as jobs, vehicles, costs and constraints. - * - *

To construct the problem, use VehicleRoutingProblem.Builder. Get an instance of this by using the static method VehicleRoutingProblem.Builder.newInstance(). - * + *

+ *

To construct the problem, use VehicleRoutingProblem.Builder. Get an instance of this by using the static method VehicleRoutingProblem.Builder.newInstance(). + *

*

By default, fleetSize is INFINITE, transport-costs are calculated as euclidean-distance (CrowFlyCosts), * and activity-costs are set to zero. - * - * - * - * @author stefan schroeder * + * @author stefan schroeder */ public class VehicleRoutingProblem { - - /** - * Builder to build the routing-problem. - * - * @author stefan schroeder - * - */ - public static class Builder { + /** + * Builder to build the routing-problem. + * + * @author stefan schroeder + */ + public static class Builder { /** - * Returns a new instance of this builder. - * - * @return builder - */ - public static Builder newInstance(){ return new Builder(); } + * Returns a new instance of this builder. + * + * @return builder + */ + public static Builder newInstance() { + return new Builder(); + } - private VehicleRoutingTransportCosts transportCosts; - - private VehicleRoutingActivityCosts activityCosts = new VehicleRoutingActivityCosts() { - - @Override - public double getActivityCost(TourActivity tourAct, double arrivalTime, Driver driver, Vehicle vehicle) { - return 0; - } - - @Override - public String toString() { - return "[name=defaultActivityCosts]"; - } - - }; + private VehicleRoutingTransportCosts transportCosts; - private Map jobs = new LinkedHashMap(); - - private Map tentativeJobs = new LinkedHashMap(); - - private Set jobsInInitialRoutes = new HashSet(); - - private Map tentative_coordinates = new HashMap(); + private VehicleRoutingActivityCosts activityCosts = new WaitingTimeCosts(); - private FleetSize fleetSize = FleetSize.INFINITE; - - private Collection vehicleTypes = new ArrayList(); - - private Collection initialRoutes = new ArrayList(); - - private Set uniqueVehicles = new HashSet(); + private Map jobs = new LinkedHashMap(); - private JobActivityFactory jobActivityFactory = new JobActivityFactory() { + private Map tentativeJobs = new LinkedHashMap(); + + private Set jobsInInitialRoutes = new HashSet(); + + private Map tentative_coordinates = new HashMap(); + + private FleetSize fleetSize = FleetSize.INFINITE; + + private Collection vehicleTypes = new ArrayList(); + + private Collection initialRoutes = new ArrayList(); + + private Set uniqueVehicles = new HashSet(); + + private boolean hasBreaks = false; + + private JobActivityFactory jobActivityFactory = new JobActivityFactory() { @Override public List createActivities(Job job) { List acts = new ArrayList(); - if(job instanceof Service){ + if (job instanceof Service) { acts.add(serviceActivityFactory.createActivity((Service) job)); - } - else if(job instanceof Shipment){ + } else if (job instanceof Shipment) { acts.add(shipmentActivityFactory.createPickup((Shipment) job)); acts.add(shipmentActivityFactory.createDelivery((Shipment) job)); } @@ -130,97 +117,102 @@ public class VehicleRoutingProblem { private int vehicleTypeIdIndexCounter = 1; - private Map typeKeyIndices = new HashMap(); + private Map typeKeyIndices = new HashMap(); - private Map> activityMap = new HashMap>(); + private Map> activityMap = new HashMap>(); private final DefaultShipmentActivityFactory shipmentActivityFactory = new DefaultShipmentActivityFactory(); private final DefaultTourActivityFactory serviceActivityFactory = new DefaultTourActivityFactory(); - private void incJobIndexCounter(){ + private void incJobIndexCounter() { jobIndexCounter++; } - private void incActivityIndexCounter(){ + private void incActivityIndexCounter() { activityIndexCounter++; } - private void incVehicleTypeIdIndexCounter() { vehicleTypeIdIndexCounter++; } + private void incVehicleTypeIdIndexCounter() { + vehicleTypeIdIndexCounter++; + } - /** - * Returns the unmodifiable map of collected locations (mapped by their location-id). - * - * @return map with locations - */ - public Map getLocationMap(){ - return Collections.unmodifiableMap(tentative_coordinates); - } + private Set allLocations = new HashSet(); - /** - * Returns the locations collected SO FAR by this builder. - * - *

Locations are cached when adding a shipment, service, depot, vehicle. - * - * @return locations - * - **/ - public Locations getLocations(){ - return new Locations() { + /** + * Returns the unmodifiable map of collected locations (mapped by their location-id). + * + * @return map with locations + */ + public Map getLocationMap() { + return Collections.unmodifiableMap(tentative_coordinates); + } - @Override - public Coordinate getCoord(String id) { - return tentative_coordinates.get(id); - } - - }; - } - /** - * Sets routing costs. - * - * @param costs the routingCosts - * @return builder - * @see VehicleRoutingTransportCosts - */ - public Builder setRoutingCost(VehicleRoutingTransportCosts costs){ - this.transportCosts = costs; - return this; - } - - /** - * Sets the type of fleetSize. - * - *

FleetSize is either FleetSize.INFINITE or FleetSize.FINITE. By default it is FleetSize.INFINITE. - * - * @param fleetSize the fleet size used in this problem. it can either be FleetSize.INFINITE or FleetSize.FINITE - * @return this builder - */ - public Builder setFleetSize(FleetSize fleetSize){ - this.fleetSize = fleetSize; - return this; - } + /** + * Returns the locations collected SO FAR by this builder. + *

+ *

Locations are cached when adding a shipment, service, depot, vehicle. + * + * @return locations + */ + public Locations getLocations() { + return new Locations() { - /** - * Adds a job which is either a service or a shipment. - * - *

Note that job.getId() must be unique, i.e. no job (either it is a shipment or a service) is allowed to have an already allocated id. - * - * @param job job to be added - * @return this builder - * @throws IllegalStateException if job is neither a shipment nor a service, or jobId has already been added. - * @deprecated use addJob(AbstractJob job) instead - */ - @Deprecated - public Builder addJob(Job job) { - if(!(job instanceof AbstractJob)) throw new IllegalArgumentException("job must be of type AbstractJob"); - return addJob((AbstractJob)job); - } + @Override + public Coordinate getCoord(String id) { + return tentative_coordinates.get(id); + } + + }; + } + + /** + * Sets routing costs. + * + * @param costs the routingCosts + * @return builder + * @see VehicleRoutingTransportCosts + */ + public Builder setRoutingCost(VehicleRoutingTransportCosts costs) { + this.transportCosts = costs; + return this; + } + + + /** + * Sets the type of fleetSize. + *

+ *

FleetSize is either FleetSize.INFINITE or FleetSize.FINITE. By default it is FleetSize.INFINITE. + * + * @param fleetSize the fleet size used in this problem. it can either be FleetSize.INFINITE or FleetSize.FINITE + * @return this builder + */ + public Builder setFleetSize(FleetSize fleetSize) { + this.fleetSize = fleetSize; + return this; + } /** * Adds a job which is either a service or a shipment. + *

+ *

Note that job.getId() must be unique, i.e. no job (either it is a shipment or a service) is allowed to have an already allocated id. * + * @param job job to be added + * @return this builder + * @throws IllegalStateException if job is neither a shipment nor a service, or jobId has already been added. + * @deprecated use addJob(AbstractJob job) instead + */ + @Deprecated + public Builder addJob(Job job) { + if (!(job instanceof AbstractJob)) throw new IllegalArgumentException("job must be of type AbstractJob"); + return addJob((AbstractJob) job); + } + + /** + * Adds a job which is either a service or a shipment. + *

*

Note that job.getId() must be unique, i.e. no job (either it is a shipment or a service) is allowed to have an already allocated id. * * @param job job to be added @@ -228,43 +220,67 @@ public class VehicleRoutingProblem { * @throws IllegalStateException if job is neither a shipment nor a service, or jobId has already been added. */ public Builder addJob(AbstractJob job) { - if(tentativeJobs.containsKey(job.getId())) throw new IllegalStateException("jobList already contains a job with id " + job.getId() + ". make sure you use unique ids for your jobs (i.e. service and shipments)"); - if(!(job instanceof Service || job instanceof Shipment)) throw new IllegalStateException("job must be either a service or a shipment"); + if (tentativeJobs.containsKey(job.getId())) + throw new IllegalStateException("vehicle routing problem already contains a service or shipment with id " + job.getId() + ". make sure you use unique ids for all services and shipments"); + if (!(job instanceof Service || job instanceof Shipment)) + throw new IllegalStateException("job must be either a service or a shipment"); job.setIndex(jobIndexCounter); incJobIndexCounter(); tentativeJobs.put(job.getId(), job); addLocationToTentativeLocations(job); return this; } - - private void addLocationToTentativeLocations(Job job) { - if(job instanceof Service) { - tentative_coordinates.put(((Service)job).getLocation().getId(), ((Service)job).getLocation().getCoordinate()); - } - else if(job instanceof Shipment){ - Shipment shipment = (Shipment)job; - tentative_coordinates.put(shipment.getPickupLocation().getId(), shipment.getPickupLocation().getCoordinate()); - tentative_coordinates.put(shipment.getDeliveryLocation().getId(), shipment.getDeliveryLocation().getCoordinate()); - } - } - private void addJobToFinalJobMapAndCreateActivities(Job job){ - if(job instanceof Service) { + private void addLocationToTentativeLocations(Job job) { + if (job instanceof Service) { + Location location = ((Service) job).getLocation(); +// tentative_coordinates.put(location.getId(), location.getCoordinate()); + addLocationToTentativeLocations(location); + } else if (job instanceof Shipment) { + Shipment shipment = (Shipment) job; + Location pickupLocation = shipment.getPickupLocation(); + addLocationToTentativeLocations(pickupLocation); +// tentative_coordinates.put(pickupLocation.getId(), pickupLocation.getCoordinate()); + Location deliveryLocation = shipment.getDeliveryLocation(); + addLocationToTentativeLocations(deliveryLocation); +// tentative_coordinates.put(deliveryLocation.getId(), deliveryLocation.getCoordinate()); + } + } + + private void addLocationToTentativeLocations(Location location) { + tentative_coordinates.put(location.getId(), location.getCoordinate()); + allLocations.add(location); + } + + private void addJobToFinalJobMapAndCreateActivities(Job job) { + if (job instanceof Service) { Service service = (Service) job; - addService(service); - } - else if(job instanceof Shipment){ - Shipment shipment = (Shipment)job; + addService(service); + } else if (job instanceof Shipment) { + Shipment shipment = (Shipment) job; addShipment(shipment); - } + } List jobActs = jobActivityFactory.createActivities(job); - for(AbstractActivity act : jobActs){ + for (AbstractActivity act : jobActs) { act.setIndex(activityIndexCounter); incActivityIndexCounter(); } activityMap.put(job, jobActs); - } + } + private boolean addBreaksToActivityMap() { + boolean hasBreaks = false; + for (Vehicle v : uniqueVehicles) { + if (v.getBreak() != null) { + hasBreaks = true; + AbstractActivity breakActivity = BreakActivity.newInstance(v.getBreak()); + breakActivity.setIndex(activityIndexCounter); + incActivityIndexCounter(); + activityMap.put(v.getBreak(), Arrays.asList(breakActivity)); + } + } + return hasBreaks; + } /** * Adds an initial vehicle route. @@ -272,38 +288,31 @@ public class VehicleRoutingProblem { * @param route initial route * @return the builder */ - public Builder addInitialVehicleRoute(VehicleRoute route){ - addVehicle((AbstractVehicle)route.getVehicle()); - for(TourActivity act : route.getActivities()){ + public Builder addInitialVehicleRoute(VehicleRoute route) { + addVehicle((AbstractVehicle) route.getVehicle()); + for (TourActivity act : route.getActivities()) { AbstractActivity abstractAct = (AbstractActivity) act; abstractAct.setIndex(activityIndexCounter); incActivityIndexCounter(); - if(act instanceof TourActivity.JobActivity) { + if (act instanceof TourActivity.JobActivity) { Job job = ((TourActivity.JobActivity) act).getJob(); jobsInInitialRoutes.add(job.getId()); - registerLocation(job); + addLocationToTentativeLocations(job); registerJobAndActivity(abstractAct, job); } } - initialRoutes.add(route); - return this; - } - - private void registerLocation(Job job) { - if (job instanceof Service) tentative_coordinates.put(((Service) job).getLocation().getId(), ((Service) job).getLocation().getCoordinate()); - if (job instanceof Shipment) { - Shipment shipment = (Shipment) job; - tentative_coordinates.put(shipment.getPickupLocation().getId(), shipment.getPickupLocation().getCoordinate()); - tentative_coordinates.put(shipment.getDeliveryLocation().getId(), shipment.getDeliveryLocation().getCoordinate()); - } + initialRoutes.add(route); + return this; } + + private void registerJobAndActivity(AbstractActivity abstractAct, Job job) { - if(activityMap.containsKey(job)) activityMap.get(job).add(abstractAct); - else{ + if (activityMap.containsKey(job)) activityMap.get(job).add(abstractAct); + else { List actList = new ArrayList(); actList.add(abstractAct); - activityMap.put(job,actList); + activityMap.put(job, actList); } } @@ -313,62 +322,65 @@ public class VehicleRoutingProblem { * @param routes initial routes * @return the builder */ - public Builder addInitialVehicleRoutes(Collection routes){ - for(VehicleRoute r : routes){ - addInitialVehicleRoute(r); - } - return this; - } - - private void addShipment(Shipment job) { - if(jobs.containsKey(job.getId())){ logger.warn("job " + job + " already in job list. overrides existing job."); } - tentative_coordinates.put(job.getPickupLocation().getId(), job.getPickupLocation().getCoordinate()); - tentative_coordinates.put(job.getDeliveryLocation().getId(), job.getDeliveryLocation().getCoordinate()); - jobs.put(job.getId(),job); - } + public Builder addInitialVehicleRoutes(Collection routes) { + for (VehicleRoute r : routes) { + addInitialVehicleRoute(r); + } + return this; + } - /** - * Adds a vehicle. - * - * - * @param vehicle vehicle to be added - * @return this builder - * @deprecated use addVehicle(AbstractVehicle vehicle) instead - */ - @Deprecated - public Builder addVehicle(Vehicle vehicle) { - if(!(vehicle instanceof AbstractVehicle)) throw new IllegalStateException("vehicle must be an AbstractVehicle"); - return addVehicle((AbstractVehicle)vehicle); - } + private void addShipment(Shipment job) { + if (jobs.containsKey(job.getId())) { + logger.warn("job " + job + " already in job list. overrides existing job."); + } + addLocationToTentativeLocations(job); +// tentative_coordinates.put(job.getPickupLocation().getId(), job.getPickupLocation().getCoordinate()); +// tentative_coordinates.put(job.getDeliveryLocation().getId(), job.getDeliveryLocation().getCoordinate()); + jobs.put(job.getId(), job); + } /** * Adds a vehicle. * + * @param vehicle vehicle to be added + * @return this builder + * @deprecated use addVehicle(AbstractVehicle vehicle) instead + */ + @Deprecated + public Builder addVehicle(Vehicle vehicle) { + if (!(vehicle instanceof AbstractVehicle)) + throw new IllegalStateException("vehicle must be an AbstractVehicle"); + return addVehicle((AbstractVehicle) vehicle); + } + + /** + * Adds a vehicle. * * @param vehicle vehicle to be added * @return this builder */ public Builder addVehicle(AbstractVehicle vehicle) { - if(!uniqueVehicles.contains(vehicle)){ + if (!uniqueVehicles.contains(vehicle)) { vehicle.setIndex(vehicleIndexCounter); incVehicleIndexCounter(); } - if(typeKeyIndices.containsKey(vehicle.getVehicleTypeIdentifier())){ + if (typeKeyIndices.containsKey(vehicle.getVehicleTypeIdentifier())) { vehicle.getVehicleTypeIdentifier().setIndex(typeKeyIndices.get(vehicle.getVehicleTypeIdentifier())); - } - else { + } else { vehicle.getVehicleTypeIdentifier().setIndex(vehicleTypeIdIndexCounter); - typeKeyIndices.put(vehicle.getVehicleTypeIdentifier(),vehicleTypeIdIndexCounter); + typeKeyIndices.put(vehicle.getVehicleTypeIdentifier(), vehicleTypeIdIndexCounter); incVehicleTypeIdIndexCounter(); } uniqueVehicles.add(vehicle); - if(!vehicleTypes.contains(vehicle.getType())){ + if (!vehicleTypes.contains(vehicle.getType())) { vehicleTypes.add(vehicle.getType()); } String startLocationId = vehicle.getStartLocation().getId(); - tentative_coordinates.put(startLocationId, vehicle.getStartLocation().getCoordinate()); - if(!vehicle.getEndLocation().getId().equals(startLocationId)){ - tentative_coordinates.put(vehicle.getEndLocation().getId(), vehicle.getEndLocation().getCoordinate()); + addLocationToTentativeLocations(vehicle.getStartLocation()); +// tentative_coordinates.put(startLocationId, vehicle.getStartLocation().getCoordinate()); + if (!vehicle.getEndLocation().getId().equals(startLocationId)) { + addLocationToTentativeLocations(vehicle.getEndLocation()); +// tentative_coordinates.put(vehicle.getEndLocation().getId(), vehicle.getEndLocation().getCoordinate()); } return this; } @@ -378,159 +390,167 @@ public class VehicleRoutingProblem { } /** - * Sets the activity-costs. - * - *

By default it is set to zero. - * - * @param activityCosts activity costs of the problem - * @return this builder - * @see VehicleRoutingActivityCosts - */ - public Builder setActivityCosts(VehicleRoutingActivityCosts activityCosts){ - this.activityCosts = activityCosts; - return this; - } + * Sets the activity-costs. + *

+ *

By default it is set to zero. + * + * @param activityCosts activity costs of the problem + * @return this builder + * @see VehicleRoutingActivityCosts + */ + public Builder setActivityCosts(VehicleRoutingActivityCosts activityCosts) { + this.activityCosts = activityCosts; + return this; + } - /** - * Builds the {@link VehicleRoutingProblem}. - * - *

If {@link VehicleRoutingTransportCosts} are not set, {@link CrowFlyCosts} is used. - * - * @return {@link VehicleRoutingProblem} - */ - public VehicleRoutingProblem build() { - if(transportCosts == null){ - transportCosts = new CrowFlyCosts(getLocations()); - } - for(Job job : tentativeJobs.values()) + /** + * Builds the {@link VehicleRoutingProblem}. + *

+ *

If {@link VehicleRoutingTransportCosts} are not set, {@link CrowFlyCosts} is used. + * + * @return {@link VehicleRoutingProblem} + */ + public VehicleRoutingProblem build() { + if (transportCosts == null) { + transportCosts = new CrowFlyCosts(getLocations()); + } + for (Job job : tentativeJobs.values()) { if (!jobsInInitialRoutes.contains(job.getId())) { addJobToFinalJobMapAndCreateActivities(job); } - return new VehicleRoutingProblem(this); - } + } + boolean hasBreaks = addBreaksToActivityMap(); + if (hasBreaks && fleetSize.equals(FleetSize.INFINITE)) + throw new UnsupportedOperationException("breaks are not yet supported when dealing with infinite fleet. either set it to finite or omit breaks."); + return new VehicleRoutingProblem(this); + } @SuppressWarnings("UnusedDeclaration") public Builder addLocation(String locationId, Coordinate coordinate) { - tentative_coordinates.put(locationId, coordinate); - return this; - } + tentative_coordinates.put(locationId, coordinate); + return this; + } - /** - * Adds a collection of jobs. - * - * @param jobs which is a collection of jobs that subclasses Job - * @return this builder - */ - @SuppressWarnings("deprecation") + /** + * Adds a collection of jobs. + * + * @param jobs which is a collection of jobs that subclasses Job + * @return this builder + */ + @SuppressWarnings("deprecation") public Builder addAllJobs(Collection jobs) { - for(Job j : jobs){ - addJob(j); - } - return this; - } + for (Job j : jobs) { + addJob(j); + } + return this; + } - /** - * Adds a collection of vehicles. - * - * @param vehicles vehicles to be added - * @return this builder - */ - @SuppressWarnings("deprecation") + /** + * Adds a collection of vehicles. + * + * @param vehicles vehicles to be added + * @return this builder + */ + @SuppressWarnings("deprecation") public Builder addAllVehicles(Collection vehicles) { - for(Vehicle v : vehicles){ - addVehicle(v); - } - return this; - } - - /** - * Gets an unmodifiable collection of already added vehicles. - * - * @return collection of vehicles - */ - public Collection getAddedVehicles(){ - return Collections.unmodifiableCollection(uniqueVehicles); - } - - /** - * Gets an unmodifiable collection of already added vehicle-types. - * - * @return collection of vehicle-types - */ - public Collection getAddedVehicleTypes(){ - return Collections.unmodifiableCollection(vehicleTypes); - } + for (Vehicle v : vehicles) { + addVehicle(v); + } + return this; + } + + /** + * Gets an unmodifiable collection of already added vehicles. + * + * @return collection of vehicles + */ + public Collection getAddedVehicles() { + return Collections.unmodifiableCollection(uniqueVehicles); + } + + /** + * Gets an unmodifiable collection of already added vehicle-types. + * + * @return collection of vehicle-types + */ + public Collection getAddedVehicleTypes() { + return Collections.unmodifiableCollection(vehicleTypes); + } /** * Returns an unmodifiable collection of already added jobs. * * @return collection of jobs */ - public Collection getAddedJobs(){ - return Collections.unmodifiableCollection(tentativeJobs.values()); - } + public Collection getAddedJobs() { + return Collections.unmodifiableCollection(tentativeJobs.values()); + } - private Builder addService(Service service){ - tentative_coordinates.put(service.getLocation().getId(), service.getLocation().getCoordinate()); - if(jobs.containsKey(service.getId())){ logger.warn("service " + service + " already in job list. overrides existing job."); } - jobs.put(service.getId(),service); - return this; - } + private Builder addService(Service service) { +// tentative_coordinates.put(service.getLocation().getId(), service.getLocation().getCoordinate()); + addLocationToTentativeLocations(service); + if (jobs.containsKey(service.getId())) { + logger.warn("service " + service + " already in job list. overrides existing job."); + } + jobs.put(service.getId(), service); + return this; + } - -} - - /** - * Enum that characterizes the fleet-size. - * - * @author sschroeder - * - */ - public static enum FleetSize { - FINITE, INFINITE - } - - /** - * logger logging for this class - */ - private final static Logger logger = LogManager.getLogger(VehicleRoutingProblem.class); - /** - * contains transportation costs, i.e. the costs traveling from location A to B - */ - private final VehicleRoutingTransportCosts transportCosts; - - /** - * contains activity costs, i.e. the costs imposed by an activity - */ - private final VehicleRoutingActivityCosts activityCosts; - - /** - * map of jobs, stored by jobId - */ - private final Map jobs; + } - /** - * Collection that contains available vehicles. - */ - private final Collection vehicles; - - /** - * Collection that contains all available types. - */ - private final Collection vehicleTypes; - - - private final Collection initialVehicleRoutes; - - /** - * An enum that indicates type of fleetSize. By default, it is INFINTE - */ - private final FleetSize fleetSize; + /** + * Enum that characterizes the fleet-size. + * + * @author sschroeder + */ + public static enum FleetSize { + FINITE, INFINITE + } - private final Locations locations; + /** + * logger logging for this class + */ + private final static Logger logger = LogManager.getLogger(VehicleRoutingProblem.class); - private Map> activityMap; + /** + * contains transportation costs, i.e. the costs traveling from location A to B + */ + private final VehicleRoutingTransportCosts transportCosts; + + /** + * contains activity costs, i.e. the costs imposed by an activity + */ + private final VehicleRoutingActivityCosts activityCosts; + + /** + * map of jobs, stored by jobId + */ + private final Map jobs; + + /** + * Collection that contains available vehicles. + */ + private final Collection vehicles; + + /** + * Collection that contains all available types. + */ + private final Collection vehicleTypes; + + + private final Collection initialVehicleRoutes; + + private final Collection allLocations; + + /** + * An enum that indicates type of fleetSize. By default, it is INFINTE + */ + private final FleetSize fleetSize; + + private final Locations locations; + + private Map> activityMap; private int nuActivities; @@ -542,122 +562,130 @@ public class VehicleRoutingProblem { } }; - - private VehicleRoutingProblem(Builder builder) { - this.jobs = builder.jobs; - this.fleetSize = builder.fleetSize; - this.vehicles=builder.uniqueVehicles; - this.vehicleTypes = builder.vehicleTypes; - this.initialVehicleRoutes = builder.initialRoutes; - this.transportCosts = builder.transportCosts; - this.activityCosts = builder.activityCosts; - this.locations = builder.getLocations(); + + private VehicleRoutingProblem(Builder builder) { + this.jobs = builder.jobs; + this.fleetSize = builder.fleetSize; + this.vehicles = builder.uniqueVehicles; + this.vehicleTypes = builder.vehicleTypes; + this.initialVehicleRoutes = builder.initialRoutes; + this.transportCosts = builder.transportCosts; + this.activityCosts = builder.activityCosts; + this.locations = builder.getLocations(); this.activityMap = builder.activityMap; this.nuActivities = builder.activityIndexCounter; - logger.info("setup problem: " + this); - } + this.allLocations = builder.allLocations; + logger.info("setup problem: {}", this); + } @Override - public String toString() { - return "[fleetSize="+fleetSize+"][#jobs="+jobs.size()+"][#vehicles="+vehicles.size()+"][#vehicleTypes="+vehicleTypes.size()+"]["+ - "transportCost="+transportCosts+"][activityCosts="+activityCosts+"]"; - } + public String toString() { + return "[fleetSize=" + fleetSize + "][#jobs=" + jobs.size() + "][#vehicles=" + vehicles.size() + "][#vehicleTypes=" + vehicleTypes.size() + "][" + + "transportCost=" + transportCosts + "][activityCosts=" + activityCosts + "]"; + } - /** - * Returns type of fleetSize, either INFINITE or FINITE. - * - *

By default, it is INFINITE. - * - * @return either FleetSize.INFINITE or FleetSize.FINITE - */ - public FleetSize getFleetSize() { - return fleetSize; - } - - /** - * Returns the unmodifiable job map. - * - * @return unmodifiable jobMap - */ - public Map getJobs() { - return Collections.unmodifiableMap(jobs); - } + /** + * Returns type of fleetSize, either INFINITE or FINITE. + *

+ *

By default, it is INFINITE. + * + * @return either FleetSize.INFINITE or FleetSize.FINITE + */ + public FleetSize getFleetSize() { + return fleetSize; + } + + /** + * Returns the unmodifiable job map. + * + * @return unmodifiable jobMap + */ + public Map getJobs() { + return Collections.unmodifiableMap(jobs); + } /** * Returns a copy of initial vehicle routes. * * @return copied collection of initial vehicle routes */ - public Collection getInitialVehicleRoutes(){ - Collection copiedInitialRoutes = new ArrayList(); - for(VehicleRoute route : initialVehicleRoutes){ + public Collection getInitialVehicleRoutes() { + Collection copiedInitialRoutes = new ArrayList(); + for (VehicleRoute route : initialVehicleRoutes) { copiedInitialRoutes.add(VehicleRoute.copyOf(route)); } return copiedInitialRoutes; - } + } - /** - * Returns the entire, unmodifiable collection of types. - * - * @return unmodifiable collection of types - * @see VehicleTypeImpl - */ - public Collection getTypes(){ - return Collections.unmodifiableCollection(vehicleTypes); - } - - - /** - * Returns the entire, unmodifiable collection of vehicles. - * - * @return unmodifiable collection of vehicles - * @see Vehicle - */ - public Collection getVehicles() { - return Collections.unmodifiableCollection(vehicles); - } + /** + * Returns the entire, unmodifiable collection of types. + * + * @return unmodifiable collection of types + * @see VehicleTypeImpl + */ + public Collection getTypes() { + return Collections.unmodifiableCollection(vehicleTypes); + } - /** - * Returns routing costs. - * - * @return routingCosts - * @see VehicleRoutingTransportCosts - */ - public VehicleRoutingTransportCosts getTransportCosts() { - return transportCosts; - } - /** - * Returns activityCosts. - */ - public VehicleRoutingActivityCosts getActivityCosts(){ - return activityCosts; - } + /** + * Returns the entire, unmodifiable collection of vehicles. + * + * @return unmodifiable collection of vehicles + * @see Vehicle + */ + public Collection getVehicles() { + return Collections.unmodifiableCollection(vehicles); + } + + /** + * Returns routing costs. + * + * @return routingCosts + * @see VehicleRoutingTransportCosts + */ + public VehicleRoutingTransportCosts getTransportCosts() { + return transportCosts; + } + + /** + * Returns activityCosts. + */ + public VehicleRoutingActivityCosts getActivityCosts() { + return activityCosts; + } /** * @return returns all location, i.e. from vehicles and jobs. */ - public Locations getLocations(){ - return locations; - } + @Deprecated + public Locations getLocations() { + return locations; + } + + public Collection getAllLocations(){ + return allLocations; + } /** * @param job for which the corresponding activities needs to be returned * @return associated activities */ - public List getActivities(Job job){ + public List getActivities(Job job) { return Collections.unmodifiableList(activityMap.get(job)); } /** * @return total number of activities */ - public int getNuActivities(){ return nuActivities; } + public int getNuActivities() { + return nuActivities; + } /** * @return factory that creates the activities associated to a job */ - public JobActivityFactory getJobActivityFactory(){ + public JobActivityFactory getJobActivityFactory() { return jobActivityFactory; } @@ -665,12 +693,12 @@ public class VehicleRoutingProblem { * @param job for which the corresponding activities needs to be returned * @return a copy of the activities that are associated to the specified job */ - public List copyAndGetActivities(Job job){ + public List copyAndGetActivities(Job job) { List acts = new ArrayList(); - if(activityMap.containsKey(job)) { + if (activityMap.containsKey(job)) { for (AbstractActivity act : activityMap.get(job)) acts.add((AbstractActivity) act.duplicate()); } return acts; } - + } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/constraint/AdditionalTransportationCosts.java b/jsprit-core/src/main/java/jsprit/core/problem/constraint/AdditionalTransportationCosts.java index 40c7bd1d..777716e3 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/constraint/AdditionalTransportationCosts.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/constraint/AdditionalTransportationCosts.java @@ -24,63 +24,61 @@ import jsprit.core.util.CalculationUtils; /** * Calculates additional transportation costs induced by inserting newAct. - * - * @author schroeder * + * @author schroeder */ -class AdditionalTransportationCosts implements SoftActivityConstraint{ +class AdditionalTransportationCosts implements SoftActivityConstraint { - private VehicleRoutingTransportCosts routingCosts; - - /** - * Constructs the calculator that calculates additional transportation costs induced by inserting new activity. - * - *

It is calculated at local level, i.e. the additional costs of inserting act_new between act_i and act_j is c(act_i,act_new,newVehicle)+c(act_new,act_j,newVehicle)-c(act_i,act_j,oldVehicle) - *

If newVehicle.isReturnToDepot == false then the additional costs of inserting act_new between act_i and end is c(act_i,act_new) [since act_new is then the new end-of-route] - * - * @param routingCosts - */ - public AdditionalTransportationCosts(VehicleRoutingTransportCosts routingCosts) { - super(); - this.routingCosts = routingCosts; - } + private VehicleRoutingTransportCosts routingCosts; - /** - * Returns additional transportation costs induced by inserting newAct. - * - *

It is calculated at local level, i.e. the additional costs of inserting act_new between act_i and act_j is c(act_i,act_new,newVehicle)+c(act_new,act_j,newVehicle)-c(act_i,act_j,oldVehicle) - *

If newVehicle.isReturnToDepot == false then the additional costs of inserting act_new between act_i and end is c(act_i,act_new) [since act_new is then the new end-of-route] - */ - @Override - public double getCosts(JobInsertionContext iFacts, TourActivity prevAct,TourActivity newAct, TourActivity nextAct, double depTimeAtPrevAct) { - double tp_costs_prevAct_newAct = routingCosts.getTransportCost(prevAct.getLocation(), newAct.getLocation(), depTimeAtPrevAct, iFacts.getNewDriver(), iFacts.getNewVehicle()); - double tp_time_prevAct_newAct = routingCosts.getTransportTime(prevAct.getLocation(), newAct.getLocation(), depTimeAtPrevAct, iFacts.getNewDriver(), iFacts.getNewVehicle()); - - double newAct_arrTime = depTimeAtPrevAct + tp_time_prevAct_newAct; - double newAct_endTime = CalculationUtils.getActivityEndTime(newAct_arrTime, newAct); - - //open routes - if(nextAct instanceof End){ - if(!iFacts.getNewVehicle().isReturnToDepot()){ - return tp_costs_prevAct_newAct; - } - } - - double tp_costs_newAct_nextAct = routingCosts.getTransportCost(newAct.getLocation(), nextAct.getLocation(), newAct_endTime, iFacts.getNewDriver(), iFacts.getNewVehicle()); - double totalCosts = tp_costs_prevAct_newAct + tp_costs_newAct_nextAct; - - double oldCosts; - if(iFacts.getRoute().isEmpty()){ - double tp_costs_prevAct_nextAct = routingCosts.getTransportCost(prevAct.getLocation(), nextAct.getLocation(), depTimeAtPrevAct, iFacts.getNewDriver(), iFacts.getNewVehicle()); - oldCosts = tp_costs_prevAct_nextAct; - } - else{ - double tp_costs_prevAct_nextAct = routingCosts.getTransportCost(prevAct.getLocation(), nextAct.getLocation(), prevAct.getEndTime(), iFacts.getRoute().getDriver(), iFacts.getRoute().getVehicle()); - oldCosts = tp_costs_prevAct_nextAct; - } - - double additionalCosts = totalCosts - oldCosts; - return additionalCosts; - } + /** + * Constructs the calculator that calculates additional transportation costs induced by inserting new activity. + *

+ *

It is calculated at local level, i.e. the additional costs of inserting act_new between act_i and act_j is c(act_i,act_new,newVehicle)+c(act_new,act_j,newVehicle)-c(act_i,act_j,oldVehicle) + *

If newVehicle.isReturnToDepot == false then the additional costs of inserting act_new between act_i and end is c(act_i,act_new) [since act_new is then the new end-of-route] + * + * @param routingCosts + */ + public AdditionalTransportationCosts(VehicleRoutingTransportCosts routingCosts) { + super(); + this.routingCosts = routingCosts; + } + + /** + * Returns additional transportation costs induced by inserting newAct. + *

+ *

It is calculated at local level, i.e. the additional costs of inserting act_new between act_i and act_j is c(act_i,act_new,newVehicle)+c(act_new,act_j,newVehicle)-c(act_i,act_j,oldVehicle) + *

If newVehicle.isReturnToDepot == false then the additional costs of inserting act_new between act_i and end is c(act_i,act_new) [since act_new is then the new end-of-route] + */ + @Override + public double getCosts(JobInsertionContext iFacts, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double depTimeAtPrevAct) { + double tp_costs_prevAct_newAct = routingCosts.getTransportCost(prevAct.getLocation(), newAct.getLocation(), depTimeAtPrevAct, iFacts.getNewDriver(), iFacts.getNewVehicle()); + double tp_time_prevAct_newAct = routingCosts.getTransportTime(prevAct.getLocation(), newAct.getLocation(), depTimeAtPrevAct, iFacts.getNewDriver(), iFacts.getNewVehicle()); + + double newAct_arrTime = depTimeAtPrevAct + tp_time_prevAct_newAct; + double newAct_endTime = CalculationUtils.getActivityEndTime(newAct_arrTime, newAct); + + //open routes + if (nextAct instanceof End) { + if (!iFacts.getNewVehicle().isReturnToDepot()) { + return tp_costs_prevAct_newAct; + } + } + + double tp_costs_newAct_nextAct = routingCosts.getTransportCost(newAct.getLocation(), nextAct.getLocation(), newAct_endTime, iFacts.getNewDriver(), iFacts.getNewVehicle()); + double totalCosts = tp_costs_prevAct_newAct + tp_costs_newAct_nextAct; + + double oldCosts; + if (iFacts.getRoute().isEmpty()) { + double tp_costs_prevAct_nextAct = routingCosts.getTransportCost(prevAct.getLocation(), nextAct.getLocation(), depTimeAtPrevAct, iFacts.getNewDriver(), iFacts.getNewVehicle()); + oldCosts = tp_costs_prevAct_nextAct; + } else { + double tp_costs_prevAct_nextAct = routingCosts.getTransportCost(prevAct.getLocation(), nextAct.getLocation(), prevAct.getEndTime(), iFacts.getRoute().getDriver(), iFacts.getRoute().getVehicle()); + oldCosts = tp_costs_prevAct_nextAct; + } + + double additionalCosts = totalCosts - oldCosts; + return additionalCosts; + } } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/constraint/Constraint.java b/jsprit-core/src/main/java/jsprit/core/problem/constraint/Constraint.java index 63be9230..41aed9c5 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/constraint/Constraint.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/constraint/Constraint.java @@ -1,18 +1,18 @@ /******************************************************************************* * Copyright (c) 2014 Stefan Schroeder. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . - * + * * Contributors: * Stefan Schroeder - initial API and implementation ******************************************************************************/ diff --git a/jsprit-core/src/main/java/jsprit/core/problem/constraint/ConstraintManager.java b/jsprit-core/src/main/java/jsprit/core/problem/constraint/ConstraintManager.java index 13a13edf..65b2212c 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/constraint/ConstraintManager.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/constraint/ConstraintManager.java @@ -30,143 +30,142 @@ import java.util.List; /** * Manager that manage hard- and soft constraints, both on route and activity level. - * - * @author schroeder * + * @author schroeder */ -public class ConstraintManager implements HardActivityConstraint, HardRouteConstraint, SoftActivityConstraint, SoftRouteConstraint{ +public class ConstraintManager implements HardActivityConstraint, HardRouteConstraint, SoftActivityConstraint, SoftRouteConstraint { public static enum Priority { - CRITICAL, HIGH, LOW - } - - private static Logger log = LogManager.getLogger(ConstraintManager.class); - - private HardActivityLevelConstraintManager actLevelConstraintManager = new HardActivityLevelConstraintManager(); - - private HardRouteLevelConstraintManager routeLevelConstraintManager = new HardRouteLevelConstraintManager(); - - private SoftActivityConstraintManager softActivityConstraintManager = new SoftActivityConstraintManager(); - - private SoftRouteConstraintManager softRouteConstraintManager = new SoftRouteConstraintManager(); - - private VehicleRoutingProblem vrp; - - private RouteAndActivityStateGetter stateManager; - - private boolean loadConstraintsSet = false; - - private boolean timeWindowConstraintsSet = false; + CRITICAL, HIGH, LOW + } + + private static Logger log = LogManager.getLogger(ConstraintManager.class); + + private HardActivityLevelConstraintManager actLevelConstraintManager = new HardActivityLevelConstraintManager(); + + private HardRouteLevelConstraintManager routeLevelConstraintManager = new HardRouteLevelConstraintManager(); + + private SoftActivityConstraintManager softActivityConstraintManager = new SoftActivityConstraintManager(); + + private SoftRouteConstraintManager softRouteConstraintManager = new SoftRouteConstraintManager(); + + private VehicleRoutingProblem vrp; + + private RouteAndActivityStateGetter stateManager; + + private boolean loadConstraintsSet = false; + + private boolean timeWindowConstraintsSet = false; private boolean skillconstraintSet = false; - - public ConstraintManager(VehicleRoutingProblem vrp, RouteAndActivityStateGetter stateManager) { - this.vrp = vrp; - this.stateManager = stateManager; - } - - public ConstraintManager(VehicleRoutingProblem vrp, RouteAndActivityStateGetter stateManager, Collection constraints) { - this.vrp = vrp; - this.stateManager = stateManager; - resolveConstraints(constraints); - } - - private void resolveConstraints(Collection constraints) { - for(jsprit.core.problem.constraint.Constraint c : constraints){ - boolean constraintTypeKnown = false; - if(c instanceof HardActivityConstraint) { - actLevelConstraintManager.addConstraint((HardActivityConstraint) c, Priority.HIGH); - constraintTypeKnown = true; - } - if(c instanceof HardRouteConstraint) { - routeLevelConstraintManager.addConstraint((HardRouteConstraint) c); - constraintTypeKnown = true; - } - if(c instanceof SoftRouteConstraint){ - softRouteConstraintManager.addConstraint((SoftRouteConstraint)c); - constraintTypeKnown = true; - } - if(c instanceof SoftActivityConstraint){ - softActivityConstraintManager.addConstraint((SoftActivityConstraint)c); - constraintTypeKnown = true; - } - if(!constraintTypeKnown){ - log.warn("constraint " + c + " unknown thus ignores the constraint. currently, a constraint must implement either HardActivityStateLevelConstraint or HardRouteStateLevelConstraint"); - } - } - - } - public void addTimeWindowConstraint(){ - if(!timeWindowConstraintsSet){ - addConstraint(new VehicleDependentTimeWindowConstraints(stateManager, vrp.getTransportCosts()),Priority.HIGH); - timeWindowConstraintsSet = true; - } - } + public ConstraintManager(VehicleRoutingProblem vrp, RouteAndActivityStateGetter stateManager) { + this.vrp = vrp; + this.stateManager = stateManager; + } - - public void addLoadConstraint(){ - if(!loadConstraintsSet){ - addConstraint(new PickupAndDeliverShipmentLoadActivityLevelConstraint(stateManager),Priority.CRITICAL); - addConstraint(new ServiceLoadRouteLevelConstraint(stateManager)); - addConstraint(new ServiceLoadActivityLevelConstraint(stateManager),Priority.LOW); - loadConstraintsSet=true; - } - } + public ConstraintManager(VehicleRoutingProblem vrp, RouteAndActivityStateGetter stateManager, Collection constraints) { + this.vrp = vrp; + this.stateManager = stateManager; + resolveConstraints(constraints); + } - public void addSkillsConstraint() { - if (!skillconstraintSet){ - addConstraint(new HardSkillConstraint(stateManager)); - skillconstraintSet=true; + private void resolveConstraints(Collection constraints) { + for (jsprit.core.problem.constraint.Constraint c : constraints) { + boolean constraintTypeKnown = false; + if (c instanceof HardActivityConstraint) { + actLevelConstraintManager.addConstraint((HardActivityConstraint) c, Priority.HIGH); + constraintTypeKnown = true; + } + if (c instanceof HardRouteConstraint) { + routeLevelConstraintManager.addConstraint((HardRouteConstraint) c); + constraintTypeKnown = true; + } + if (c instanceof SoftRouteConstraint) { + softRouteConstraintManager.addConstraint((SoftRouteConstraint) c); + constraintTypeKnown = true; + } + if (c instanceof SoftActivityConstraint) { + softActivityConstraintManager.addConstraint((SoftActivityConstraint) c); + constraintTypeKnown = true; + } + if (!constraintTypeKnown) { + log.warn("constraint " + c + " unknown thus ignores the constraint. currently, a constraint must implement either HardActivityStateLevelConstraint or HardRouteStateLevelConstraint"); + } + } + + } + + public void addTimeWindowConstraint() { + if (!timeWindowConstraintsSet) { + addConstraint(new VehicleDependentTimeWindowConstraints(stateManager, vrp.getTransportCosts()), Priority.HIGH); + timeWindowConstraintsSet = true; } } - + + + public void addLoadConstraint() { + if (!loadConstraintsSet) { + addConstraint(new PickupAndDeliverShipmentLoadActivityLevelConstraint(stateManager), Priority.CRITICAL); + addConstraint(new ServiceLoadRouteLevelConstraint(stateManager)); + addConstraint(new ServiceLoadActivityLevelConstraint(stateManager), Priority.LOW); + loadConstraintsSet = true; + } + } + + public void addSkillsConstraint() { + if (!skillconstraintSet) { + addConstraint(new HardSkillConstraint(stateManager)); + skillconstraintSet = true; + } + } + // public void add - - public void addConstraint(HardActivityConstraint actLevelConstraint, Priority priority){ - actLevelConstraintManager.addConstraint(actLevelConstraint,priority); - } - - public void addConstraint(HardRouteConstraint routeLevelConstraint){ - routeLevelConstraintManager.addConstraint(routeLevelConstraint); - } - - public void addConstraint(SoftActivityConstraint softActivityConstraint){ - softActivityConstraintManager.addConstraint(softActivityConstraint); - } - - public void addConstraint(SoftRouteConstraint softRouteConstraint){ - softRouteConstraintManager.addConstraint(softRouteConstraint); - } - - @Override - public boolean fulfilled(JobInsertionContext insertionContext) { - return routeLevelConstraintManager.fulfilled(insertionContext); - } - @Override - public ConstraintsStatus fulfilled(JobInsertionContext iFacts, TourActivity prevAct,TourActivity newAct, TourActivity nextAct, double prevActDepTime) { - return actLevelConstraintManager.fulfilled(iFacts, prevAct, newAct, nextAct, prevActDepTime); - } - - public Collection getConstraints(){ - List constraints = new ArrayList(); - constraints.addAll(actLevelConstraintManager.getAllConstraints()); - constraints.addAll(routeLevelConstraintManager.getConstraints()); - constraints.addAll(softActivityConstraintManager.getConstraints()); - constraints.addAll(softRouteConstraintManager.getConstraints()); - return Collections.unmodifiableCollection(constraints); - } + public void addConstraint(HardActivityConstraint actLevelConstraint, Priority priority) { + actLevelConstraintManager.addConstraint(actLevelConstraint, priority); + } - @Override - public double getCosts(JobInsertionContext insertionContext) { - return softRouteConstraintManager.getCosts(insertionContext); - } + public void addConstraint(HardRouteConstraint routeLevelConstraint) { + routeLevelConstraintManager.addConstraint(routeLevelConstraint); + } + + public void addConstraint(SoftActivityConstraint softActivityConstraint) { + softActivityConstraintManager.addConstraint(softActivityConstraint); + } + + public void addConstraint(SoftRouteConstraint softRouteConstraint) { + softRouteConstraintManager.addConstraint(softRouteConstraint); + } + + @Override + public boolean fulfilled(JobInsertionContext insertionContext) { + return routeLevelConstraintManager.fulfilled(insertionContext); + } + + @Override + public ConstraintsStatus fulfilled(JobInsertionContext iFacts, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double prevActDepTime) { + return actLevelConstraintManager.fulfilled(iFacts, prevAct, newAct, nextAct, prevActDepTime); + } + + public Collection getConstraints() { + List constraints = new ArrayList(); + constraints.addAll(actLevelConstraintManager.getAllConstraints()); + constraints.addAll(routeLevelConstraintManager.getConstraints()); + constraints.addAll(softActivityConstraintManager.getConstraints()); + constraints.addAll(softRouteConstraintManager.getConstraints()); + return Collections.unmodifiableCollection(constraints); + } + + @Override + public double getCosts(JobInsertionContext insertionContext) { + return softRouteConstraintManager.getCosts(insertionContext); + } + + @Override + public double getCosts(JobInsertionContext iFacts, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double prevActDepTime) { + return softActivityConstraintManager.getCosts(iFacts, prevAct, newAct, nextAct, prevActDepTime); + } - @Override - public double getCosts(JobInsertionContext iFacts, TourActivity prevAct,TourActivity newAct, TourActivity nextAct, double prevActDepTime) { - return softActivityConstraintManager.getCosts(iFacts, prevAct, newAct, nextAct, prevActDepTime); - } - } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/constraint/HardActivityConstraint.java b/jsprit-core/src/main/java/jsprit/core/problem/constraint/HardActivityConstraint.java index 707c57d8..a11cfbd7 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/constraint/HardActivityConstraint.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/constraint/HardActivityConstraint.java @@ -22,61 +22,61 @@ import jsprit.core.problem.solution.route.activity.TourActivity; /** * Hard constraint that evaluates whether a new activity can be inserted between an activity segment (prevAct,nextAct). */ -public interface HardActivityConstraint extends HardConstraint{ +public interface HardActivityConstraint extends HardConstraint { /** * Indicates whether a hard activity constraint is fulfilled or not */ - static enum ConstraintsStatus { + static enum ConstraintsStatus { - NOT_FULFILLED_BREAK, NOT_FULFILLED, FULFILLED + NOT_FULFILLED_BREAK, NOT_FULFILLED, FULFILLED - } + } /** * Returns whether newAct can be inserted in between prevAct and nextAct. - * - *

+ *

+ *

* When you check activities, you need to understand the following: - * + *

* Let us assume an existing route; - * + *

* start, ..., i-1, i, j, j+1, ..., end - * + *

* When inserting a shipment, two activities will be inserted, pickupShipment k_pick and deliverShipment k_deliver, * i.e. jsprit loops through this route (activity sequence) and checks hard and soft constraints and calculates (marginal) insertion costs. For * the activity sequence above, it means: - *

+ *

* start, k_pick, start+1 (prevAct, newAct, nextAct)
* ...
* i-1, k_pick, i
* i, k_pick, j
* ...
- *

+ *

* accordingly:
* start, k_pick, k_delivery (prevAct, newAct, nextAct)
* ...
* i-1, k_delivery, i
* i, k_delivery, j
* ...
- *

+ *

* You specify a hard activity constraint, you to check whether for example k_pick can be inserted between prevActivity and nextActivity at all. * If so, your hard constraint should return ConstraintsStatus.FULFILLED.
* If not, you can return ConstraintsStatus.NOT_FULFILLED or ConstraintsStatus.NOT_FULFILLED_BREAK.
- * + *

* Latter should be used, if your constraint can never be fulfilled anymore when looping further through your route. - *

+ *

* Since constraint checking at activity level is rather time consuming (you need to do this thousand/millions times), * you can memorize states behind activities to avoid additional loopings through your activity sequence and thus to * check your constraint locally (only by looking at prevAct, newAct, nextAct) in constant time. * - * @param iFacts JobInsertionContext provides additional information that might be important when evaluating the insertion of newAct - * @param prevAct the previous activity, i.e. the activity before the new activity - * @param newAct the new activity to be inserted in between prevAct and nextAct - * @param nextAct the next activity, i.e. the activity after the new activity + * @param iFacts JobInsertionContext provides additional information that might be important when evaluating the insertion of newAct + * @param prevAct the previous activity, i.e. the activity before the new activity + * @param newAct the new activity to be inserted in between prevAct and nextAct + * @param nextAct the next activity, i.e. the activity after the new activity * @param prevActDepTime the departure time at previous activity (prevAct) with the new vehicle (iFacts.getNewVehicle()) * @return fulfilled if hard constraint is met, other not fulfilled. */ - public ConstraintsStatus fulfilled(JobInsertionContext iFacts, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double prevActDepTime); + public ConstraintsStatus fulfilled(JobInsertionContext iFacts, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double prevActDepTime); } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/constraint/HardActivityLevelConstraintManager.java b/jsprit-core/src/main/java/jsprit/core/problem/constraint/HardActivityLevelConstraintManager.java index 6f4d9e98..608a31a8 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/constraint/HardActivityLevelConstraintManager.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/constraint/HardActivityLevelConstraintManager.java @@ -28,75 +28,77 @@ import java.util.List; class HardActivityLevelConstraintManager implements HardActivityConstraint { - private Collection criticalConstraints = new ArrayList(); - - private Collection highPrioConstraints = new ArrayList(); - - private Collection lowPrioConstraints = new ArrayList(); - - public void addConstraint(HardActivityConstraint constraint, Priority priority){ - if(priority.equals(Priority.CRITICAL)){ - criticalConstraints.add(constraint); - } - else if(priority.equals(Priority.HIGH)){ - highPrioConstraints.add(constraint); - } - else{ - lowPrioConstraints.add(constraint); - } - } - - Collection getCriticalConstraints(){ return Collections.unmodifiableCollection(criticalConstraints); } - - Collection getHighPrioConstraints(){ return Collections.unmodifiableCollection(highPrioConstraints); } - - Collection getLowPrioConstraints(){ return Collections.unmodifiableCollection(lowPrioConstraints); } - - Collection getAllConstraints(){ - List c = new ArrayList(); - c.addAll(criticalConstraints); - c.addAll(highPrioConstraints); - c.addAll(lowPrioConstraints); - return Collections.unmodifiableCollection(c); - } - - @Override - public ConstraintsStatus fulfilled(JobInsertionContext iFacts, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double prevActDepTime) { - ConstraintsStatus notFulfilled = null; - for(HardActivityConstraint c : criticalConstraints){ - ConstraintsStatus status = c.fulfilled(iFacts, prevAct, newAct, nextAct, prevActDepTime); - if(status.equals(ConstraintsStatus.NOT_FULFILLED_BREAK)){ - return status; - } - else{ - if(status.equals(ConstraintsStatus.NOT_FULFILLED)){ - notFulfilled = status; - } - } - } - if(notFulfilled != null) return notFulfilled; - - for(HardActivityConstraint c : highPrioConstraints){ - ConstraintsStatus status = c.fulfilled(iFacts, prevAct, newAct, nextAct, prevActDepTime); - if(status.equals(ConstraintsStatus.NOT_FULFILLED_BREAK)){ - return status; - } - else{ - if(status.equals(ConstraintsStatus.NOT_FULFILLED)){ - notFulfilled = status; - } - } - } - if(notFulfilled != null) return notFulfilled; - - for(HardActivityConstraint constraint : lowPrioConstraints){ - ConstraintsStatus status = constraint.fulfilled(iFacts, prevAct, newAct, nextAct, prevActDepTime); - if(status.equals(ConstraintsStatus.NOT_FULFILLED_BREAK) || status.equals(ConstraintsStatus.NOT_FULFILLED)){ - return status; - } - } - - return ConstraintsStatus.FULFILLED; - } - + private Collection criticalConstraints = new ArrayList(); + + private Collection highPrioConstraints = new ArrayList(); + + private Collection lowPrioConstraints = new ArrayList(); + + public void addConstraint(HardActivityConstraint constraint, Priority priority) { + if (priority.equals(Priority.CRITICAL)) { + criticalConstraints.add(constraint); + } else if (priority.equals(Priority.HIGH)) { + highPrioConstraints.add(constraint); + } else { + lowPrioConstraints.add(constraint); + } + } + + Collection getCriticalConstraints() { + return Collections.unmodifiableCollection(criticalConstraints); + } + + Collection getHighPrioConstraints() { + return Collections.unmodifiableCollection(highPrioConstraints); + } + + Collection getLowPrioConstraints() { + return Collections.unmodifiableCollection(lowPrioConstraints); + } + + Collection getAllConstraints() { + List c = new ArrayList(); + c.addAll(criticalConstraints); + c.addAll(highPrioConstraints); + c.addAll(lowPrioConstraints); + return Collections.unmodifiableCollection(c); + } + + @Override + public ConstraintsStatus fulfilled(JobInsertionContext iFacts, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double prevActDepTime) { + ConstraintsStatus notFulfilled = null; + for (HardActivityConstraint c : criticalConstraints) { + ConstraintsStatus status = c.fulfilled(iFacts, prevAct, newAct, nextAct, prevActDepTime); + if (status.equals(ConstraintsStatus.NOT_FULFILLED_BREAK)) { + return status; + } else { + if (status.equals(ConstraintsStatus.NOT_FULFILLED)) { + notFulfilled = status; + } + } + } + if (notFulfilled != null) return notFulfilled; + + for (HardActivityConstraint c : highPrioConstraints) { + ConstraintsStatus status = c.fulfilled(iFacts, prevAct, newAct, nextAct, prevActDepTime); + if (status.equals(ConstraintsStatus.NOT_FULFILLED_BREAK)) { + return status; + } else { + if (status.equals(ConstraintsStatus.NOT_FULFILLED)) { + notFulfilled = status; + } + } + } + if (notFulfilled != null) return notFulfilled; + + for (HardActivityConstraint constraint : lowPrioConstraints) { + ConstraintsStatus status = constraint.fulfilled(iFacts, prevAct, newAct, nextAct, prevActDepTime); + if (status.equals(ConstraintsStatus.NOT_FULFILLED_BREAK) || status.equals(ConstraintsStatus.NOT_FULFILLED)) { + return status; + } + } + + return ConstraintsStatus.FULFILLED; + } + } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/constraint/HardConstraint.java b/jsprit-core/src/main/java/jsprit/core/problem/constraint/HardConstraint.java index eb57f4ba..39f10844 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/constraint/HardConstraint.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/constraint/HardConstraint.java @@ -1,23 +1,23 @@ /******************************************************************************* * Copyright (c) 2014 Stefan Schroeder. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . - * + * * Contributors: * Stefan Schroeder - initial API and implementation ******************************************************************************/ package jsprit.core.problem.constraint; -public interface HardConstraint extends Constraint{ +public interface HardConstraint extends Constraint { } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/constraint/HardRouteConstraint.java b/jsprit-core/src/main/java/jsprit/core/problem/constraint/HardRouteConstraint.java index 050afb60..20068cd4 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/constraint/HardRouteConstraint.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/constraint/HardRouteConstraint.java @@ -22,7 +22,7 @@ import jsprit.core.problem.misc.JobInsertionContext; * Hard constraint that evaluates whether a new job (insertionContext.getJob()) can be inserted * existing route (insertionContext.getRoute()). */ -public interface HardRouteConstraint extends HardConstraint{ +public interface HardRouteConstraint extends HardConstraint { /** * Returns whether a job can be inserted in route. @@ -33,6 +33,6 @@ public interface HardRouteConstraint extends HardConstraint{ * time at this vehicle's start location (insertionContext.getNewDepartureTime()). * @return true if constraint is met, false otherwise */ - public boolean fulfilled(JobInsertionContext insertionContext); - + public boolean fulfilled(JobInsertionContext insertionContext); + } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/constraint/HardRouteLevelConstraintManager.java b/jsprit-core/src/main/java/jsprit/core/problem/constraint/HardRouteLevelConstraintManager.java index 73ed2fff..dc51465a 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/constraint/HardRouteLevelConstraintManager.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/constraint/HardRouteLevelConstraintManager.java @@ -25,22 +25,24 @@ import java.util.Collections; class HardRouteLevelConstraintManager implements HardRouteConstraint { - private Collection hardConstraints = new ArrayList(); - - public void addConstraint(HardRouteConstraint constraint){ - hardConstraints.add(constraint); - } - - Collection getConstraints(){ return Collections.unmodifiableCollection(hardConstraints); } + private Collection hardConstraints = new ArrayList(); + + public void addConstraint(HardRouteConstraint constraint) { + hardConstraints.add(constraint); + } + + Collection getConstraints() { + return Collections.unmodifiableCollection(hardConstraints); + } + + @Override + public boolean fulfilled(JobInsertionContext insertionContext) { + for (HardRouteConstraint constraint : hardConstraints) { + if (!constraint.fulfilled(insertionContext)) { + return false; + } + } + return true; + } - @Override - public boolean fulfilled(JobInsertionContext insertionContext) { - for(HardRouteConstraint constraint : hardConstraints){ - if(!constraint.fulfilled(insertionContext)){ - return false; - } - } - return true; - } - } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/constraint/HardSkillConstraint.java b/jsprit-core/src/main/java/jsprit/core/problem/constraint/HardSkillConstraint.java index f437b42a..9ba8ab5e 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/constraint/HardSkillConstraint.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/constraint/HardSkillConstraint.java @@ -24,7 +24,6 @@ import jsprit.core.problem.solution.route.state.RouteAndActivityStateGetter; /** * SkillConstraint that ensures that only vehicles with according skills can serve route and job to be inserted. - * */ public class HardSkillConstraint implements HardRouteConstraint { @@ -38,15 +37,15 @@ public class HardSkillConstraint implements HardRouteConstraint { @Override public boolean fulfilled(JobInsertionContext insertionContext) { - for(String skill : insertionContext.getJob().getRequiredSkills().values()){ - if(!insertionContext.getNewVehicle().getSkills().containsSkill(skill)){ + for (String skill : insertionContext.getJob().getRequiredSkills().values()) { + if (!insertionContext.getNewVehicle().getSkills().containsSkill(skill)) { return false; } } Skills requiredSkillsForRoute = states.getRouteState(insertionContext.getRoute(), InternalStates.SKILLS, Skills.class); - if(requiredSkillsForRoute == null) requiredSkillsForRoute = defaultSkills; - for(String skill : requiredSkillsForRoute.values()){ - if(!insertionContext.getNewVehicle().getSkills().containsSkill(skill)){ + if (requiredSkillsForRoute == null) requiredSkillsForRoute = defaultSkills; + for (String skill : requiredSkillsForRoute.values()) { + if (!insertionContext.getNewVehicle().getSkills().containsSkill(skill)) { return false; } } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/constraint/PickupAndDeliverShipmentLoadActivityLevelConstraint.java b/jsprit-core/src/main/java/jsprit/core/problem/constraint/PickupAndDeliverShipmentLoadActivityLevelConstraint.java index 4eed6053..7a5fdb59 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/constraint/PickupAndDeliverShipmentLoadActivityLevelConstraint.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/constraint/PickupAndDeliverShipmentLoadActivityLevelConstraint.java @@ -28,63 +28,59 @@ import jsprit.core.problem.solution.route.state.RouteAndActivityStateGetter; /** * Constraint that ensures capacity constraint at each activity. - * + *

*

This is critical to consistently calculate pd-problems with capacity constraints. Critical means * that is MUST be visited. It also assumes that pd-activities are visited in the order they occur in a tour. - * - * @author schroeder * + * @author schroeder */ public class PickupAndDeliverShipmentLoadActivityLevelConstraint implements HardActivityConstraint { - - private RouteAndActivityStateGetter stateManager; + + private RouteAndActivityStateGetter stateManager; private Capacity defaultValue; - - /** - * Constructs the constraint ensuring capacity constraint at each activity. - * - *

This is critical to consistently calculate pd-problems with capacity constraints. Critical means - * that is MUST be visited. It also assumes that pd-activities are visited in the order they occur in a tour. - * - * - * @param stateManager the stateManager - */ - public PickupAndDeliverShipmentLoadActivityLevelConstraint(RouteAndActivityStateGetter stateManager) { - super(); - this.stateManager = stateManager; + + /** + * Constructs the constraint ensuring capacity constraint at each activity. + *

+ *

This is critical to consistently calculate pd-problems with capacity constraints. Critical means + * that is MUST be visited. It also assumes that pd-activities are visited in the order they occur in a tour. + * + * @param stateManager the stateManager + */ + public PickupAndDeliverShipmentLoadActivityLevelConstraint(RouteAndActivityStateGetter stateManager) { + super(); + this.stateManager = stateManager; defaultValue = Capacity.Builder.newInstance().build(); - } - - /** - * Checks whether there is enough capacity to insert newAct between prevAct and nextAct. - * - */ - @Override - public ConstraintsStatus fulfilled(JobInsertionContext iFacts, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double prevActDepTime) { - if(!(newAct instanceof PickupShipment) && !(newAct instanceof DeliverShipment)){ - return ConstraintsStatus.FULFILLED; - } - Capacity loadAtPrevAct; - if(prevAct instanceof Start){ - loadAtPrevAct = stateManager.getRouteState(iFacts.getRoute(), InternalStates.LOAD_AT_BEGINNING, Capacity.class); - if(loadAtPrevAct == null) loadAtPrevAct = defaultValue; - } - else{ - loadAtPrevAct = stateManager.getActivityState(prevAct, InternalStates.LOAD, Capacity.class); - if(loadAtPrevAct == null) loadAtPrevAct = defaultValue; - } - if(newAct instanceof PickupShipment){ - if(!Capacity.addup(loadAtPrevAct, newAct.getSize()).isLessOrEqual(iFacts.getNewVehicle().getType().getCapacityDimensions())){ - return ConstraintsStatus.NOT_FULFILLED; - } - } - if(newAct instanceof DeliverShipment){ - if(!Capacity.addup(loadAtPrevAct, Capacity.invert(newAct.getSize())).isLessOrEqual(iFacts.getNewVehicle().getType().getCapacityDimensions())) + } + + /** + * Checks whether there is enough capacity to insert newAct between prevAct and nextAct. + */ + @Override + public ConstraintsStatus fulfilled(JobInsertionContext iFacts, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double prevActDepTime) { + if (!(newAct instanceof PickupShipment) && !(newAct instanceof DeliverShipment)) { + return ConstraintsStatus.FULFILLED; + } + Capacity loadAtPrevAct; + if (prevAct instanceof Start) { + loadAtPrevAct = stateManager.getRouteState(iFacts.getRoute(), InternalStates.LOAD_AT_BEGINNING, Capacity.class); + if (loadAtPrevAct == null) loadAtPrevAct = defaultValue; + } else { + loadAtPrevAct = stateManager.getActivityState(prevAct, InternalStates.LOAD, Capacity.class); + if (loadAtPrevAct == null) loadAtPrevAct = defaultValue; + } + if (newAct instanceof PickupShipment) { + if (!Capacity.addup(loadAtPrevAct, newAct.getSize()).isLessOrEqual(iFacts.getNewVehicle().getType().getCapacityDimensions())) { + return ConstraintsStatus.NOT_FULFILLED; + } + } + if (newAct instanceof DeliverShipment) { + if (!Capacity.addup(loadAtPrevAct, Capacity.invert(newAct.getSize())).isLessOrEqual(iFacts.getNewVehicle().getType().getCapacityDimensions())) return ConstraintsStatus.NOT_FULFILLED_BREAK; - } - return ConstraintsStatus.FULFILLED; - } - - + } + return ConstraintsStatus.FULFILLED; + } + + } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/constraint/ServiceDeliveriesFirstConstraint.java b/jsprit-core/src/main/java/jsprit/core/problem/constraint/ServiceDeliveriesFirstConstraint.java index ecc26431..334f3ef7 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/constraint/ServiceDeliveriesFirstConstraint.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/constraint/ServiceDeliveriesFirstConstraint.java @@ -21,19 +21,35 @@ import jsprit.core.problem.solution.route.activity.*; public class ServiceDeliveriesFirstConstraint implements HardActivityConstraint { - @Override - public ConstraintsStatus fulfilled(JobInsertionContext iFacts, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double prevActDepTime) { - if(newAct instanceof PickupService && nextAct instanceof DeliverService){ return ConstraintsStatus.NOT_FULFILLED; } - if(newAct instanceof ServiceActivity && nextAct instanceof DeliverService){ return ConstraintsStatus.NOT_FULFILLED; } - if(newAct instanceof DeliverService && prevAct instanceof PickupService){ return ConstraintsStatus.NOT_FULFILLED_BREAK; } - if(newAct instanceof DeliverService && prevAct instanceof ServiceActivity){ return ConstraintsStatus.NOT_FULFILLED_BREAK; } - - if(newAct instanceof DeliverService && prevAct instanceof PickupShipment){ return ConstraintsStatus.NOT_FULFILLED_BREAK; } - if(newAct instanceof DeliverService && prevAct instanceof DeliverShipment){ return ConstraintsStatus.NOT_FULFILLED_BREAK; } - if(newAct instanceof PickupShipment && nextAct instanceof DeliverService){ return ConstraintsStatus.NOT_FULFILLED;} - if(newAct instanceof DeliverShipment && nextAct instanceof DeliverService){ return ConstraintsStatus.NOT_FULFILLED;} - - return ConstraintsStatus.FULFILLED; - } - + @Override + public ConstraintsStatus fulfilled(JobInsertionContext iFacts, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double prevActDepTime) { + if (newAct instanceof PickupService && nextAct instanceof DeliverService) { + return ConstraintsStatus.NOT_FULFILLED; + } + if (newAct instanceof ServiceActivity && nextAct instanceof DeliverService) { + return ConstraintsStatus.NOT_FULFILLED; + } + if (newAct instanceof DeliverService && prevAct instanceof PickupService) { + return ConstraintsStatus.NOT_FULFILLED_BREAK; + } + if (newAct instanceof DeliverService && prevAct instanceof ServiceActivity) { + return ConstraintsStatus.NOT_FULFILLED_BREAK; + } + + if (newAct instanceof DeliverService && prevAct instanceof PickupShipment) { + return ConstraintsStatus.NOT_FULFILLED_BREAK; + } + if (newAct instanceof DeliverService && prevAct instanceof DeliverShipment) { + return ConstraintsStatus.NOT_FULFILLED_BREAK; + } + if (newAct instanceof PickupShipment && nextAct instanceof DeliverService) { + return ConstraintsStatus.NOT_FULFILLED; + } + if (newAct instanceof DeliverShipment && nextAct instanceof DeliverService) { + return ConstraintsStatus.NOT_FULFILLED; + } + + return ConstraintsStatus.FULFILLED; + } + } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/constraint/ServiceLoadActivityLevelConstraint.java b/jsprit-core/src/main/java/jsprit/core/problem/constraint/ServiceLoadActivityLevelConstraint.java index 03b7a029..3d45b3d0 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/constraint/ServiceLoadActivityLevelConstraint.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/constraint/ServiceLoadActivityLevelConstraint.java @@ -25,52 +25,49 @@ import jsprit.core.problem.solution.route.state.RouteAndActivityStateGetter; /** * Ensures load constraint for inserting ServiceActivity. - * + *

*

When using this, you need to use
- * - * - * @author schroeder * + * @author schroeder */ -class ServiceLoadActivityLevelConstraint implements HardActivityConstraint { - - private RouteAndActivityStateGetter stateManager; +public class ServiceLoadActivityLevelConstraint implements HardActivityConstraint { + + private RouteAndActivityStateGetter stateManager; private Capacity defaultValue; - - public ServiceLoadActivityLevelConstraint(RouteAndActivityStateGetter stateManager) { - super(); - this.stateManager = stateManager; - defaultValue = Capacity.Builder.newInstance().build(); - } - @Override - public ConstraintsStatus fulfilled(JobInsertionContext iFacts, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double prevActDepTime) { - Capacity futureMaxLoad; - Capacity prevMaxLoad; - if(prevAct instanceof Start){ - futureMaxLoad = stateManager.getRouteState(iFacts.getRoute(), InternalStates.MAXLOAD, Capacity.class); - if(futureMaxLoad == null) futureMaxLoad = defaultValue; - prevMaxLoad = stateManager.getRouteState(iFacts.getRoute(), InternalStates.LOAD_AT_BEGINNING, Capacity.class); - if(prevMaxLoad == null) prevMaxLoad = defaultValue; - } - else{ - futureMaxLoad = stateManager.getActivityState(prevAct, InternalStates.FUTURE_MAXLOAD, Capacity.class); - if(futureMaxLoad == null) futureMaxLoad = defaultValue; - prevMaxLoad = stateManager.getActivityState(prevAct, InternalStates.PAST_MAXLOAD, Capacity.class); - if(prevMaxLoad == null) prevMaxLoad = defaultValue; - - } - if(newAct instanceof PickupService || newAct instanceof ServiceActivity){ - if(!Capacity.addup(newAct.getSize(), futureMaxLoad).isLessOrEqual(iFacts.getNewVehicle().getType().getCapacityDimensions())){ - return ConstraintsStatus.NOT_FULFILLED; - } - } - if(newAct instanceof DeliverService){ - if(!Capacity.addup(Capacity.invert(newAct.getSize()), prevMaxLoad).isLessOrEqual(iFacts.getNewVehicle().getType().getCapacityDimensions())){ - return ConstraintsStatus.NOT_FULFILLED_BREAK; - } - } - return ConstraintsStatus.FULFILLED; - } + public ServiceLoadActivityLevelConstraint(RouteAndActivityStateGetter stateManager) { + super(); + this.stateManager = stateManager; + defaultValue = Capacity.Builder.newInstance().build(); + } + + @Override + public ConstraintsStatus fulfilled(JobInsertionContext iFacts, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double prevActDepTime) { + Capacity futureMaxLoad; + Capacity prevMaxLoad; + if (prevAct instanceof Start) { + futureMaxLoad = stateManager.getRouteState(iFacts.getRoute(), InternalStates.MAXLOAD, Capacity.class); + if (futureMaxLoad == null) futureMaxLoad = defaultValue; + prevMaxLoad = stateManager.getRouteState(iFacts.getRoute(), InternalStates.LOAD_AT_BEGINNING, Capacity.class); + if (prevMaxLoad == null) prevMaxLoad = defaultValue; + } else { + futureMaxLoad = stateManager.getActivityState(prevAct, InternalStates.FUTURE_MAXLOAD, Capacity.class); + if (futureMaxLoad == null) futureMaxLoad = defaultValue; + prevMaxLoad = stateManager.getActivityState(prevAct, InternalStates.PAST_MAXLOAD, Capacity.class); + if (prevMaxLoad == null) prevMaxLoad = defaultValue; + + } + if (newAct instanceof PickupService || newAct instanceof ServiceActivity) { + if (!Capacity.addup(newAct.getSize(), futureMaxLoad).isLessOrEqual(iFacts.getNewVehicle().getType().getCapacityDimensions())) { + return ConstraintsStatus.NOT_FULFILLED; + } + } + if (newAct instanceof DeliverService) { + if (!Capacity.addup(Capacity.invert(newAct.getSize()), prevMaxLoad).isLessOrEqual(iFacts.getNewVehicle().getType().getCapacityDimensions())) { + return ConstraintsStatus.NOT_FULFILLED_BREAK; + } + } + return ConstraintsStatus.FULFILLED; + } } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/constraint/ServiceLoadRouteLevelConstraint.java b/jsprit-core/src/main/java/jsprit/core/problem/constraint/ServiceLoadRouteLevelConstraint.java index 87c30fb2..deb92d45 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/constraint/ServiceLoadRouteLevelConstraint.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/constraint/ServiceLoadRouteLevelConstraint.java @@ -27,47 +27,45 @@ import jsprit.core.problem.solution.route.state.RouteAndActivityStateGetter; /** * Ensures that capacity constraint is met, i.e. that current load plus * new job size does not exceeds capacity of new vehicle. - * + *

*

If job is neither Pickup, Delivery nor Service, it returns true. - * - * @author stefan * + * @author stefan */ -class ServiceLoadRouteLevelConstraint implements HardRouteConstraint { +public class ServiceLoadRouteLevelConstraint implements HardRouteConstraint { - private RouteAndActivityStateGetter stateManager; + private RouteAndActivityStateGetter stateManager; private Capacity defaultValue; - - public ServiceLoadRouteLevelConstraint(RouteAndActivityStateGetter stateManager) { - super(); - this.stateManager = stateManager; - this.defaultValue = Capacity.Builder.newInstance().build(); - } - @Override - public boolean fulfilled(JobInsertionContext insertionContext) { - Capacity maxLoadAtRoute = stateManager.getRouteState(insertionContext.getRoute(), InternalStates.MAXLOAD, Capacity.class); - if(maxLoadAtRoute == null) maxLoadAtRoute = defaultValue; + public ServiceLoadRouteLevelConstraint(RouteAndActivityStateGetter stateManager) { + super(); + this.stateManager = stateManager; + this.defaultValue = Capacity.Builder.newInstance().build(); + } + + @Override + public boolean fulfilled(JobInsertionContext insertionContext) { + Capacity maxLoadAtRoute = stateManager.getRouteState(insertionContext.getRoute(), InternalStates.MAXLOAD, Capacity.class); + if (maxLoadAtRoute == null) maxLoadAtRoute = defaultValue; Capacity capacityDimensions = insertionContext.getNewVehicle().getType().getCapacityDimensions(); - if(!maxLoadAtRoute.isLessOrEqual(capacityDimensions)){ - return false; - } - if(insertionContext.getJob() instanceof Delivery){ - Capacity loadAtDepot = stateManager.getRouteState(insertionContext.getRoute(), InternalStates.LOAD_AT_BEGINNING, Capacity.class); - if(loadAtDepot == null) loadAtDepot = defaultValue; - if(!Capacity.addup(loadAtDepot, insertionContext.getJob().getSize()).isLessOrEqual(capacityDimensions)){ - return false; - } - } - else if(insertionContext.getJob() instanceof Pickup || insertionContext.getJob() instanceof Service){ - Capacity loadAtEnd = stateManager.getRouteState(insertionContext.getRoute(), InternalStates.LOAD_AT_END, Capacity.class); - if(loadAtEnd == null) loadAtEnd = defaultValue; - if(!Capacity.addup(loadAtEnd, insertionContext.getJob().getSize()).isLessOrEqual(capacityDimensions)){ - return false; - } - } - return true; - } - + if (!maxLoadAtRoute.isLessOrEqual(capacityDimensions)) { + return false; + } + if (insertionContext.getJob() instanceof Delivery) { + Capacity loadAtDepot = stateManager.getRouteState(insertionContext.getRoute(), InternalStates.LOAD_AT_BEGINNING, Capacity.class); + if (loadAtDepot == null) loadAtDepot = defaultValue; + if (!Capacity.addup(loadAtDepot, insertionContext.getJob().getSize()).isLessOrEqual(capacityDimensions)) { + return false; + } + } else if (insertionContext.getJob() instanceof Pickup || insertionContext.getJob() instanceof Service) { + Capacity loadAtEnd = stateManager.getRouteState(insertionContext.getRoute(), InternalStates.LOAD_AT_END, Capacity.class); + if (loadAtEnd == null) loadAtEnd = defaultValue; + if (!Capacity.addup(loadAtEnd, insertionContext.getJob().getSize()).isLessOrEqual(capacityDimensions)) { + return false; + } + } + return true; + } + } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/constraint/ShipmentPickupsFirstConstraint.java b/jsprit-core/src/main/java/jsprit/core/problem/constraint/ShipmentPickupsFirstConstraint.java index 293e6b87..fb9421f6 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/constraint/ShipmentPickupsFirstConstraint.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/constraint/ShipmentPickupsFirstConstraint.java @@ -23,11 +23,15 @@ import jsprit.core.problem.solution.route.activity.TourActivity; public class ShipmentPickupsFirstConstraint implements HardActivityConstraint { - @Override - public ConstraintsStatus fulfilled(JobInsertionContext iFacts, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double prevActDepTime) { - if(newAct instanceof DeliverShipment && nextAct instanceof PickupShipment){ return ConstraintsStatus.NOT_FULFILLED; } - if(newAct instanceof PickupShipment && prevAct instanceof DeliverShipment){ return ConstraintsStatus.NOT_FULFILLED_BREAK; } - return ConstraintsStatus.FULFILLED; - } - + @Override + public ConstraintsStatus fulfilled(JobInsertionContext iFacts, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double prevActDepTime) { + if (newAct instanceof DeliverShipment && nextAct instanceof PickupShipment) { + return ConstraintsStatus.NOT_FULFILLED; + } + if (newAct instanceof PickupShipment && prevAct instanceof DeliverShipment) { + return ConstraintsStatus.NOT_FULFILLED_BREAK; + } + return ConstraintsStatus.FULFILLED; + } + } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/constraint/SoftActivityConstraint.java b/jsprit-core/src/main/java/jsprit/core/problem/constraint/SoftActivityConstraint.java index 77ec7ea4..4694044c 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/constraint/SoftActivityConstraint.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/constraint/SoftActivityConstraint.java @@ -1,18 +1,18 @@ /******************************************************************************* * Copyright (c) 2014 Stefan Schroeder. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . - * + * * Contributors: * Stefan Schroeder - initial API and implementation ******************************************************************************/ @@ -21,8 +21,8 @@ package jsprit.core.problem.constraint; import jsprit.core.problem.misc.JobInsertionContext; import jsprit.core.problem.solution.route.activity.TourActivity; -public interface SoftActivityConstraint extends SoftConstraint{ +public interface SoftActivityConstraint extends SoftConstraint { + + public double getCosts(JobInsertionContext iFacts, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double prevActDepTime); - public double getCosts(JobInsertionContext iFacts, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double prevActDepTime); - } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/constraint/SoftActivityConstraintManager.java b/jsprit-core/src/main/java/jsprit/core/problem/constraint/SoftActivityConstraintManager.java index 5aae9d89..f2dfd02e 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/constraint/SoftActivityConstraintManager.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/constraint/SoftActivityConstraintManager.java @@ -1,18 +1,18 @@ /******************************************************************************* * Copyright (c) 2014 Stefan Schroeder. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . - * + * * Contributors: * Stefan Schroeder - initial API and implementation ******************************************************************************/ @@ -25,23 +25,25 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; -class SoftActivityConstraintManager implements SoftActivityConstraint{ +class SoftActivityConstraintManager implements SoftActivityConstraint { - private Collection softConstraints = new ArrayList(); - - public void addConstraint(SoftActivityConstraint constraint){ - softConstraints.add(constraint); - } - - Collection getConstraints(){ return Collections.unmodifiableCollection(softConstraints); } - - @Override - public double getCosts(JobInsertionContext iFacts, TourActivity prevAct,TourActivity newAct, TourActivity nextAct, double prevActDepTime) { - double sumCosts = 0.0; - for(SoftActivityConstraint c : softConstraints){ - sumCosts += c.getCosts(iFacts, prevAct, newAct, nextAct, prevActDepTime); - } - return sumCosts; - } + private Collection softConstraints = new ArrayList(); + + public void addConstraint(SoftActivityConstraint constraint) { + softConstraints.add(constraint); + } + + Collection getConstraints() { + return Collections.unmodifiableCollection(softConstraints); + } + + @Override + public double getCosts(JobInsertionContext iFacts, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double prevActDepTime) { + double sumCosts = 0.0; + for (SoftActivityConstraint c : softConstraints) { + sumCosts += c.getCosts(iFacts, prevAct, newAct, nextAct, prevActDepTime); + } + return sumCosts; + } } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/constraint/SoftConstraint.java b/jsprit-core/src/main/java/jsprit/core/problem/constraint/SoftConstraint.java index 10dbde67..97a7ceb0 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/constraint/SoftConstraint.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/constraint/SoftConstraint.java @@ -1,23 +1,23 @@ /******************************************************************************* * Copyright (c) 2014 Stefan Schroeder. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . - * + * * Contributors: * Stefan Schroeder - initial API and implementation ******************************************************************************/ package jsprit.core.problem.constraint; -public interface SoftConstraint extends Constraint{ +public interface SoftConstraint extends Constraint { } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/constraint/SoftRouteConstraint.java b/jsprit-core/src/main/java/jsprit/core/problem/constraint/SoftRouteConstraint.java index 73a902d9..f673c128 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/constraint/SoftRouteConstraint.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/constraint/SoftRouteConstraint.java @@ -1,18 +1,18 @@ /******************************************************************************* * Copyright (c) 2014 Stefan Schroeder. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . - * + * * Contributors: * Stefan Schroeder - initial API and implementation ******************************************************************************/ @@ -20,8 +20,8 @@ package jsprit.core.problem.constraint; import jsprit.core.problem.misc.JobInsertionContext; -public interface SoftRouteConstraint extends SoftConstraint{ - - public double getCosts(JobInsertionContext insertionContext); +public interface SoftRouteConstraint extends SoftConstraint { + + public double getCosts(JobInsertionContext insertionContext); } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/constraint/SoftRouteConstraintManager.java b/jsprit-core/src/main/java/jsprit/core/problem/constraint/SoftRouteConstraintManager.java index 18810dd5..89a53853 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/constraint/SoftRouteConstraintManager.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/constraint/SoftRouteConstraintManager.java @@ -1,18 +1,18 @@ /******************************************************************************* * Copyright (c) 2014 Stefan Schroeder. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . - * + * * Contributors: * Stefan Schroeder - initial API and implementation ******************************************************************************/ @@ -24,23 +24,25 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; -class SoftRouteConstraintManager implements SoftRouteConstraint{ +class SoftRouteConstraintManager implements SoftRouteConstraint { - private Collection softConstraints = new ArrayList(); - - public void addConstraint(SoftRouteConstraint constraint){ - softConstraints.add(constraint); - } - - Collection getConstraints(){ return Collections.unmodifiableCollection(softConstraints); } - - @Override - public double getCosts(JobInsertionContext insertionContext) { - double sumCosts = 0.0; - for(SoftRouteConstraint c : softConstraints){ - sumCosts += c.getCosts(insertionContext); - } - return sumCosts; - } + private Collection softConstraints = new ArrayList(); + + public void addConstraint(SoftRouteConstraint constraint) { + softConstraints.add(constraint); + } + + Collection getConstraints() { + return Collections.unmodifiableCollection(softConstraints); + } + + @Override + public double getCosts(JobInsertionContext insertionContext) { + double sumCosts = 0.0; + for (SoftRouteConstraint c : softConstraints) { + sumCosts += c.getCosts(insertionContext); + } + return sumCosts; + } } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/constraint/SwitchNotFeasible.java b/jsprit-core/src/main/java/jsprit/core/problem/constraint/SwitchNotFeasible.java new file mode 100644 index 00000000..c0ad04a2 --- /dev/null +++ b/jsprit-core/src/main/java/jsprit/core/problem/constraint/SwitchNotFeasible.java @@ -0,0 +1,26 @@ +package jsprit.core.problem.constraint; + +import jsprit.core.algorithm.state.InternalStates; +import jsprit.core.algorithm.state.StateManager; +import jsprit.core.problem.misc.JobInsertionContext; + +/** + * Created by schroeder on 19/09/15. + */ +public class SwitchNotFeasible implements HardRouteConstraint { + + private StateManager stateManager; + + public SwitchNotFeasible(StateManager stateManager) { + this.stateManager = stateManager; + } + + @Override + public boolean fulfilled(JobInsertionContext insertionContext) { + Boolean notFeasible = stateManager.getRouteState(insertionContext.getRoute(), insertionContext.getNewVehicle(), InternalStates.SWITCH_NOT_FEASIBLE, Boolean.class); + if (notFeasible == null || insertionContext.getRoute().getVehicle().getVehicleTypeIdentifier().equals(insertionContext.getNewVehicle().getVehicleTypeIdentifier())) + return true; + else return !notFeasible; + } + +} diff --git a/jsprit-core/src/main/java/jsprit/core/problem/constraint/TimeWindowConstraint.java b/jsprit-core/src/main/java/jsprit/core/problem/constraint/TimeWindowConstraint.java index 9be1d1f3..6b09061d 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/constraint/TimeWindowConstraint.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/constraint/TimeWindowConstraint.java @@ -27,118 +27,116 @@ import jsprit.core.util.CalculationUtils; /** - * - * @author stefan - * - */ - class TimeWindowConstraint implements HardActivityConstraint { + * @author stefan + */ +class TimeWindowConstraint implements HardActivityConstraint { - private RouteAndActivityStateGetter states; - - private VehicleRoutingTransportCosts routingCosts; - - public TimeWindowConstraint(RouteAndActivityStateGetter states, VehicleRoutingTransportCosts routingCosts) { - super(); - this.states = states; - this.routingCosts = routingCosts; - } + private RouteAndActivityStateGetter states; - @Override - public ConstraintsStatus fulfilled(JobInsertionContext iFacts, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double prevActDepTime) { - double latestVehicleArrival = iFacts.getNewVehicle().getLatestArrival(); - Double latestArrTimeAtNextAct; - Location nextActLocation; - if(nextAct instanceof End) { - latestArrTimeAtNextAct = latestVehicleArrival; - nextActLocation = iFacts.getNewVehicle().getEndLocation(); - if(!iFacts.getNewVehicle().isReturnToDepot()){ - nextActLocation = newAct.getLocation(); - } - } - else{ - latestArrTimeAtNextAct = states.getActivityState(nextAct, InternalStates.LATEST_OPERATION_START_TIME, Double.class); - if(latestArrTimeAtNextAct==null) latestArrTimeAtNextAct=nextAct.getTheoreticalLatestOperationStartTime(); - nextActLocation = nextAct.getLocation(); + private VehicleRoutingTransportCosts routingCosts; + + public TimeWindowConstraint(RouteAndActivityStateGetter states, VehicleRoutingTransportCosts routingCosts) { + super(); + this.states = states; + this.routingCosts = routingCosts; + } + + @Override + public ConstraintsStatus fulfilled(JobInsertionContext iFacts, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double prevActDepTime) { + double latestVehicleArrival = iFacts.getNewVehicle().getLatestArrival(); + Double latestArrTimeAtNextAct; + Location nextActLocation; + if (nextAct instanceof End) { + latestArrTimeAtNextAct = latestVehicleArrival; + nextActLocation = iFacts.getNewVehicle().getEndLocation(); + if (!iFacts.getNewVehicle().isReturnToDepot()) { + nextActLocation = newAct.getLocation(); } + } else { + latestArrTimeAtNextAct = states.getActivityState(nextAct, InternalStates.LATEST_OPERATION_START_TIME, Double.class); + if (latestArrTimeAtNextAct == null) + latestArrTimeAtNextAct = nextAct.getTheoreticalLatestOperationStartTime(); + nextActLocation = nextAct.getLocation(); + } /* - * if latest arrival of vehicle (at its end) is smaller than earliest operation start times of activities, + * if latest arrival of vehicle (at its end) is smaller than earliest operation start times of activities, * then vehicle can never conduct activities. - * + * * |--- vehicle's operation time ---| * |--- prevAct or newAct or nextAct ---| */ - if(latestVehicleArrival < prevAct.getTheoreticalEarliestOperationStartTime() || - latestVehicleArrival < newAct.getTheoreticalEarliestOperationStartTime() || - latestVehicleArrival < nextAct.getTheoreticalEarliestOperationStartTime()){ - return ConstraintsStatus.NOT_FULFILLED_BREAK; - } - /* - * if the latest operation start-time of new activity is smaller than the earliest start of prev. activity, - * then - * + if (latestVehicleArrival < prevAct.getTheoreticalEarliestOperationStartTime() || + latestVehicleArrival < newAct.getTheoreticalEarliestOperationStartTime() || + latestVehicleArrival < nextAct.getTheoreticalEarliestOperationStartTime()) { + return ConstraintsStatus.NOT_FULFILLED_BREAK; + } + /* + * if the latest operation start-time of new activity is smaller than the earliest start of prev. activity, + * then + * * |--- prevAct ---| * |--- newAct ---| */ - if(newAct.getTheoreticalLatestOperationStartTime() < prevAct.getTheoreticalEarliestOperationStartTime()){ - return ConstraintsStatus.NOT_FULFILLED_BREAK; - } - + if (newAct.getTheoreticalLatestOperationStartTime() < prevAct.getTheoreticalEarliestOperationStartTime()) { + return ConstraintsStatus.NOT_FULFILLED_BREAK; + } + /* - * |--- prevAct ---| + * |--- prevAct ---| * |- earliest arrival of vehicle * |--- nextAct ---| */ - double arrTimeAtNextOnDirectRouteWithNewVehicle = prevActDepTime + routingCosts.getTransportTime(prevAct.getLocation(), nextAct.getLocation(), prevActDepTime, iFacts.getNewDriver(), iFacts.getNewVehicle()); - if(arrTimeAtNextOnDirectRouteWithNewVehicle > nextAct.getTheoreticalLatestOperationStartTime()){ - return ConstraintsStatus.NOT_FULFILLED_BREAK; - } - /* - * |--- newAct ---| + double arrTimeAtNextOnDirectRouteWithNewVehicle = prevActDepTime + routingCosts.getTransportTime(prevAct.getLocation(), nextAct.getLocation(), prevActDepTime, iFacts.getNewDriver(), iFacts.getNewVehicle()); + if (arrTimeAtNextOnDirectRouteWithNewVehicle > nextAct.getTheoreticalLatestOperationStartTime()) { + return ConstraintsStatus.NOT_FULFILLED_BREAK; + } + /* + * |--- newAct ---| * |--- nextAct ---| */ - if(newAct.getTheoreticalEarliestOperationStartTime() > nextAct.getTheoreticalLatestOperationStartTime()){ - return ConstraintsStatus.NOT_FULFILLED; - } - // log.info("check insertion of " + newAct + " between " + prevAct + " and " + nextAct + ". prevActDepTime=" + prevActDepTime); + if (newAct.getTheoreticalEarliestOperationStartTime() > nextAct.getTheoreticalLatestOperationStartTime()) { + return ConstraintsStatus.NOT_FULFILLED; + } + // log.info("check insertion of " + newAct + " between " + prevAct + " and " + nextAct + ". prevActDepTime=" + prevActDepTime); // double latestArrTimeAtNextAct = states.getActivityState(nextAct, StateFactory.LATEST_OPERATION_START_TIME, Double.class); - double arrTimeAtNewAct = prevActDepTime + routingCosts.getTransportTime(prevAct.getLocation(), newAct.getLocation(), prevActDepTime, iFacts.getNewDriver(), iFacts.getNewVehicle()); + double arrTimeAtNewAct = prevActDepTime + routingCosts.getTransportTime(prevAct.getLocation(), newAct.getLocation(), prevActDepTime, iFacts.getNewDriver(), iFacts.getNewVehicle()); - double latestArrTimeAtNewAct = Math.min(newAct.getTheoreticalLatestOperationStartTime(),latestArrTimeAtNextAct - - routingCosts.getBackwardTransportTime(nextActLocation, newAct.getLocation(), latestArrTimeAtNextAct, iFacts.getNewDriver(), - iFacts.getNewVehicle()) - newAct.getOperationTime()); - /* - * |--- prevAct ---| + double latestArrTimeAtNewAct = Math.min(newAct.getTheoreticalLatestOperationStartTime(), latestArrTimeAtNextAct - + routingCosts.getBackwardTransportTime(nextActLocation, newAct.getLocation(), latestArrTimeAtNextAct, iFacts.getNewDriver(), + iFacts.getNewVehicle()) - newAct.getOperationTime()); + /* + * |--- prevAct ---| * |--- vehicle's arrival @newAct - * latest arrival of vehicle @newAct ---| + * latest arrival of vehicle @newAct ---| */ - if(arrTimeAtNewAct > latestArrTimeAtNewAct){ - return ConstraintsStatus.NOT_FULFILLED; - } - - if(nextAct instanceof End){ - if(!iFacts.getNewVehicle().isReturnToDepot()){ - return ConstraintsStatus.FULFILLED; - } - } + if (arrTimeAtNewAct > latestArrTimeAtNewAct) { + return ConstraintsStatus.NOT_FULFILLED; + } + + if (nextAct instanceof End) { + if (!iFacts.getNewVehicle().isReturnToDepot()) { + return ConstraintsStatus.FULFILLED; + } + } // log.info(newAct + " arrTime=" + arrTimeAtNewAct); - double endTimeAtNewAct = CalculationUtils.getActivityEndTime(arrTimeAtNewAct, newAct); - double arrTimeAtNextAct = endTimeAtNewAct + routingCosts.getTransportTime(newAct.getLocation(), nextAct.getLocation(), endTimeAtNewAct, iFacts.getNewDriver(), iFacts.getNewVehicle()); + double endTimeAtNewAct = CalculationUtils.getActivityEndTime(arrTimeAtNewAct, newAct); + double arrTimeAtNextAct = endTimeAtNewAct + routingCosts.getTransportTime(newAct.getLocation(), nextAct.getLocation(), endTimeAtNewAct, iFacts.getNewDriver(), iFacts.getNewVehicle()); /* - * |--- newAct ---| + * |--- newAct ---| * |--- vehicle's arrival @nextAct - * latest arrival of vehicle @nextAct ---| + * latest arrival of vehicle @nextAct ---| */ - if(arrTimeAtNextAct > latestArrTimeAtNextAct){ - return ConstraintsStatus.NOT_FULFILLED; - } - + if (arrTimeAtNextAct > latestArrTimeAtNextAct) { + return ConstraintsStatus.NOT_FULFILLED; + } + // if vehicle cannot even manage direct-route - break - if(arrTimeAtNextOnDirectRouteWithNewVehicle > latestArrTimeAtNextAct){ - return ConstraintsStatus.NOT_FULFILLED_BREAK; - } - return ConstraintsStatus.FULFILLED; - } - } + if (arrTimeAtNextOnDirectRouteWithNewVehicle > latestArrTimeAtNextAct) { + return ConstraintsStatus.NOT_FULFILLED_BREAK; + } + return ConstraintsStatus.FULFILLED; + } +} diff --git a/jsprit-core/src/main/java/jsprit/core/problem/constraint/VehicleDependentTimeWindowConstraints.java b/jsprit-core/src/main/java/jsprit/core/problem/constraint/VehicleDependentTimeWindowConstraints.java index f43c619c..d9bd2c97 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/constraint/VehicleDependentTimeWindowConstraints.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/constraint/VehicleDependentTimeWindowConstraints.java @@ -27,11 +27,8 @@ import jsprit.core.problem.solution.route.state.RouteAndActivityStateGetter; import jsprit.core.util.CalculationUtils; - /** - * * @author stefan - * */ public class VehicleDependentTimeWindowConstraints implements HardActivityConstraint { @@ -60,28 +57,28 @@ public class VehicleDependentTimeWindowConstraints implements HardActivityConstr Location nextActLocation; double nextAct_theoreticalLatestOperationStartTime = getLatestOperationStartTime(nextAct); - if(nextAct instanceof End) { + if (nextAct instanceof End) { latestArrTimeAtNextAct = latestVehicleArrival; nextActLocation = iFacts.getNewVehicle().getEndLocation(); - if(!iFacts.getNewVehicle().isReturnToDepot()){ + if (!iFacts.getNewVehicle().isReturnToDepot()) { nextActLocation = newAct.getLocation(); } - } - else{ + } else { //try to get latest_operation_start_time of newVehicle - latestArrTimeAtNextAct = states.getActivityState(nextAct, iFacts.getNewVehicle(), InternalStates.LATEST_OPERATION_START_TIME ,Double.class); + latestArrTimeAtNextAct = states.getActivityState(nextAct, iFacts.getNewVehicle(), InternalStates.LATEST_OPERATION_START_TIME, Double.class); // if(latestArrTimeAtNextAct == null) //try to get latest_operation_start_time of currVehicle // latestArrTimeAtNextAct = states.getActivityState(nextAct, iFacts.getRoute().getVehicle(), StateFactory.LATEST_OPERATION_START_TIME ,Double.class); - if(latestArrTimeAtNextAct == null) {//otherwise set it to theoretical_latest_operation_startTime - latestArrTimeAtNextAct = nextAct_theoreticalLatestOperationStartTime; -// throw new IllegalStateException("this is strange and should not be"); + if (latestArrTimeAtNextAct == null) {//otherwise set it to theoretical_latest_operation_startTime + latestArrTimeAtNextAct = nextAct.getTheoreticalLatestOperationStartTime(); +// latestArrTimeAtNextAct = nextAct_theoreticalLatestOperationStartTime; +// throw new IllegalStateException("this is strange and should not be"); //ToDo here, there should be another solution } nextActLocation = nextAct.getLocation(); } /* - * if latest arrival of vehicle (at its end) is smaller than earliest operation start times of activities, + * if latest arrival of vehicle (at its end) is smaller than earliest operation start times of activities, * then vehicle can never conduct activities. * * |--- vehicle's operation time ---| @@ -93,37 +90,36 @@ public class VehicleDependentTimeWindowConstraints implements HardActivityConstr double nextAct_theoreticalEarliestOperationStartTime = getEarliestOperationStartTime(nextAct); // nextAct.getTheoreticalEarliestOperationStartTime(); - if(latestVehicleArrival < prevAct_theoreticalEarliestOperationStartTime || - latestVehicleArrival < newAct_theoreticalEarliestOperationStartTime || - latestVehicleArrival < nextAct_theoreticalEarliestOperationStartTime){ + if (latestVehicleArrival < prevAct.getTheoreticalEarliestOperationStartTime() || + latestVehicleArrival < newAct.getTheoreticalEarliestOperationStartTime() || + latestVehicleArrival < nextAct.getTheoreticalEarliestOperationStartTime()) { return ConstraintsStatus.NOT_FULFILLED_BREAK; } - /* - * if the latest operation start-time of new activity is smaller than the earliest start of prev. activity, + /* + * if the latest operation start-time of new activity is smaller than the earliest start of prev. activity, * then * * |--- prevAct ---| * |--- newAct ---| */ double newAct_theoreticalLatestOperationStartTime = getLatestOperationStartTime(newAct); -// newAct.getTheoreticalLatestOperationStartTime(); - if(newAct_theoreticalLatestOperationStartTime < prevAct_theoreticalEarliestOperationStartTime){ + if (newAct.getTheoreticalLatestOperationStartTime() < prevAct.getTheoreticalEarliestOperationStartTime()) { return ConstraintsStatus.NOT_FULFILLED_BREAK; } /* - * |--- prevAct ---| + * |--- prevAct ---| * |- earliest arrival of vehicle * |--- nextAct ---| */ double arrTimeAtNextOnDirectRouteWithNewVehicle = prevActDepTime + routingCosts.getTransportTime(prevAct.getLocation(), nextActLocation, prevActDepTime, iFacts.getNewDriver(), iFacts.getNewVehicle()); - if(arrTimeAtNextOnDirectRouteWithNewVehicle > latestArrTimeAtNextAct){ + if (arrTimeAtNextOnDirectRouteWithNewVehicle > latestArrTimeAtNextAct) { return ConstraintsStatus.NOT_FULFILLED_BREAK; } /* - * |--- newAct ---| + * |--- newAct ---| * |--- nextAct ---| */ if(newAct_theoreticalEarliestOperationStartTime > nextAct_theoreticalLatestOperationStartTime){ @@ -133,23 +129,23 @@ public class VehicleDependentTimeWindowConstraints implements HardActivityConstr double arrTimeAtNewAct = prevActDepTime + routingCosts.getTransportTime(prevAct.getLocation(), newAct.getLocation(), prevActDepTime, iFacts.getNewDriver(), iFacts.getNewVehicle()); double endTimeAtNewAct = CalculationUtils.getActivityEndTime(arrTimeAtNewAct, newAct); double latestArrTimeAtNewAct = - Math.min(newAct_theoreticalLatestOperationStartTime, - latestArrTimeAtNextAct - - routingCosts.getBackwardTransportTime(newAct.getLocation(),nextActLocation,latestArrTimeAtNextAct,iFacts.getNewDriver(),iFacts.getNewVehicle()) - - newAct.getOperationTime() - ); + Math.min(newAct_theoreticalLatestOperationStartTime, + latestArrTimeAtNextAct - + routingCosts.getBackwardTransportTime(newAct.getLocation(),nextActLocation,latestArrTimeAtNextAct,iFacts.getNewDriver(),iFacts.getNewVehicle()) + - newAct.getOperationTime() + ); /* - * |--- prevAct ---| + * |--- prevAct ---| * |--- vehicle's arrival @newAct * latest arrival of vehicle @newAct ---| */ - if(arrTimeAtNewAct > latestArrTimeAtNewAct){ + if (arrTimeAtNewAct > latestArrTimeAtNewAct) { return ConstraintsStatus.NOT_FULFILLED; } - if(nextAct instanceof End){ - if(!iFacts.getNewVehicle().isReturnToDepot()){ + if (nextAct instanceof End) { + if (!iFacts.getNewVehicle().isReturnToDepot()) { return ConstraintsStatus.FULFILLED; } } @@ -158,11 +154,11 @@ public class VehicleDependentTimeWindowConstraints implements HardActivityConstr double arrTimeAtNextAct = endTimeAtNewAct + routingCosts.getTransportTime(newAct.getLocation(), nextActLocation, endTimeAtNewAct, iFacts.getNewDriver(), iFacts.getNewVehicle()); /* - * |--- newAct ---| + * |--- newAct ---| * |--- vehicle's arrival @nextAct * latest arrival of vehicle @nextAct ---| */ - if(arrTimeAtNextAct > latestArrTimeAtNextAct){ + if (arrTimeAtNextAct > latestArrTimeAtNextAct) { return ConstraintsStatus.NOT_FULFILLED; } return ConstraintsStatus.FULFILLED; diff --git a/jsprit-core/src/main/java/jsprit/core/problem/cost/AbstractForwardVehicleRoutingTransportCosts.java b/jsprit-core/src/main/java/jsprit/core/problem/cost/AbstractForwardVehicleRoutingTransportCosts.java index e96725f1..57750d30 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/cost/AbstractForwardVehicleRoutingTransportCosts.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/cost/AbstractForwardVehicleRoutingTransportCosts.java @@ -20,22 +20,22 @@ import jsprit.core.problem.Location; import jsprit.core.problem.driver.Driver; import jsprit.core.problem.vehicle.Vehicle; -public abstract class AbstractForwardVehicleRoutingTransportCosts implements VehicleRoutingTransportCosts{ +public abstract class AbstractForwardVehicleRoutingTransportCosts implements VehicleRoutingTransportCosts { - @Override - public abstract double getTransportTime(Location from, Location to,double departureTime, Driver driver, Vehicle vehicle); - - @Override - public abstract double getTransportCost(Location from, Location to,double departureTime, Driver driver, Vehicle vehicle); + @Override + public abstract double getTransportTime(Location from, Location to, double departureTime, Driver driver, Vehicle vehicle); - @Override - public double getBackwardTransportTime(Location from, Location to,double arrivalTime, Driver driver, Vehicle vehicle) { - return getTransportTime(from, to, arrivalTime, driver, vehicle); - } + @Override + public abstract double getTransportCost(Location from, Location to, double departureTime, Driver driver, Vehicle vehicle); - @Override - public double getBackwardTransportCost(Location from, Location to,double arrivalTime, Driver driver, Vehicle vehicle) { - return getTransportCost(from, to, arrivalTime, driver, vehicle); - } + @Override + public double getBackwardTransportTime(Location from, Location to, double arrivalTime, Driver driver, Vehicle vehicle) { + return getTransportTime(from, to, arrivalTime, driver, vehicle); + } + + @Override + public double getBackwardTransportCost(Location from, Location to, double arrivalTime, Driver driver, Vehicle vehicle) { + return getTransportCost(from, to, arrivalTime, driver, vehicle); + } } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/cost/BackwardTransportCost.java b/jsprit-core/src/main/java/jsprit/core/problem/cost/BackwardTransportCost.java index 80549d3e..a586aa01 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/cost/BackwardTransportCost.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/cost/BackwardTransportCost.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.problem.cost; @@ -22,6 +22,6 @@ import jsprit.core.problem.vehicle.Vehicle; public interface BackwardTransportCost { - public double getBackwardTransportCost(Location from, Location to,double arrivalTime, Driver driver, Vehicle vehicle); + public double getBackwardTransportCost(Location from, Location to, double arrivalTime, Driver driver, Vehicle vehicle); } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/cost/BackwardTransportTime.java b/jsprit-core/src/main/java/jsprit/core/problem/cost/BackwardTransportTime.java index 888b04ae..849a7e5b 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/cost/BackwardTransportTime.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/cost/BackwardTransportTime.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.problem.cost; @@ -22,6 +22,6 @@ import jsprit.core.problem.vehicle.Vehicle; public interface BackwardTransportTime { - public double getBackwardTransportTime(Location from, Location to, double arrivalTime, Driver driver, Vehicle vehicle); + public double getBackwardTransportTime(Location from, Location to, double arrivalTime, Driver driver, Vehicle vehicle); } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/cost/ForwardTransportCost.java b/jsprit-core/src/main/java/jsprit/core/problem/cost/ForwardTransportCost.java index f2bad16f..53cd9a04 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/cost/ForwardTransportCost.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/cost/ForwardTransportCost.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.problem.cost; @@ -22,6 +22,6 @@ import jsprit.core.problem.vehicle.Vehicle; public interface ForwardTransportCost { - public double getTransportCost(Location from, Location to, double departureTime, Driver driver, Vehicle vehicle); + public double getTransportCost(Location from, Location to, double departureTime, Driver driver, Vehicle vehicle); } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/cost/ForwardTransportTime.java b/jsprit-core/src/main/java/jsprit/core/problem/cost/ForwardTransportTime.java index 1d79c594..c77232bd 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/cost/ForwardTransportTime.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/cost/ForwardTransportTime.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.problem.cost; @@ -22,6 +22,6 @@ import jsprit.core.problem.vehicle.Vehicle; public interface ForwardTransportTime { - public double getTransportTime(Location from, Location to, double departureTime, Driver driver, Vehicle vehicle); + public double getTransportTime(Location from, Location to, double departureTime, Driver driver, Vehicle vehicle); } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/cost/TransportCost.java b/jsprit-core/src/main/java/jsprit/core/problem/cost/TransportCost.java index fedf31c6..c4375be2 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/cost/TransportCost.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/cost/TransportCost.java @@ -1,22 +1,22 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.problem.cost; -public interface TransportCost extends ForwardTransportCost, BackwardTransportCost{ +public interface TransportCost extends ForwardTransportCost, BackwardTransportCost { } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/cost/TransportTime.java b/jsprit-core/src/main/java/jsprit/core/problem/cost/TransportTime.java index fdc70e29..077f9bd0 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/cost/TransportTime.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/cost/TransportTime.java @@ -1,22 +1,22 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.problem.cost; -public interface TransportTime extends ForwardTransportTime, BackwardTransportTime{ +public interface TransportTime extends ForwardTransportTime, BackwardTransportTime { } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/cost/VehicleRoutingActivityCosts.java b/jsprit-core/src/main/java/jsprit/core/problem/cost/VehicleRoutingActivityCosts.java index 786800c9..ec9ea858 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/cost/VehicleRoutingActivityCosts.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/cost/VehicleRoutingActivityCosts.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.problem.cost; @@ -22,44 +22,41 @@ import jsprit.core.problem.vehicle.Vehicle; /** * Interface for overall routing and operation costs. - * + *

*

This calculates activity and leg-based costs. If you want to consider for example costs incurred by missed time-windows, you can do it here. - * - * @author schroeder * + * @author schroeder */ public interface VehicleRoutingActivityCosts { - - public static class Time { - - public static double TOUREND = -2.0; - - public static double TOURSTART = -1.0; - - public static double UNDEFINED = -3.0; - } - - public static interface Parameter { - - public double getPenaltyForMissedTimeWindow(); - - } - - /** - * Calculates and returns the activity cost at tourAct. - * - *

Here waiting-times, service-times and missed time-windows can be considered. - * - * @param tourAct - * @param arrivalTime is actually the arrival time at this tourActivity, which must not nessecarrily be the operation start time. If the theoretical earliest - * operation start time at this activity is later than actualStartTime, the driver must wait at this activity. - * @param driver - * @param vehicle - * - * if earliestStartTime > latestStartTime activity operations cannot be conducted within the given time-window. - * @return - */ - public double getActivityCost(TourActivity tourAct, double arrivalTime, Driver driver, Vehicle vehicle); - + public static class Time { + + public static double TOUREND = -2.0; + + public static double TOURSTART = -1.0; + + public static double UNDEFINED = -3.0; + } + + public static interface Parameter { + + public double getPenaltyForMissedTimeWindow(); + + } + + /** + * Calculates and returns the activity cost at tourAct. + *

+ *

Here waiting-times, service-times and missed time-windows can be considered. + * + * @param tourAct + * @param arrivalTime is actually the arrival time at this tourActivity, which must not nessecarrily be the operation start time. If the theoretical earliest + * operation start time at this activity is later than actualStartTime, the driver must wait at this activity. + * @param driver + * @param vehicle if earliestStartTime > latestStartTime activity operations cannot be conducted within the given time-window. + * @return + */ + public double getActivityCost(TourActivity tourAct, double arrivalTime, Driver driver, Vehicle vehicle); + + } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/cost/VehicleRoutingTransportCosts.java b/jsprit-core/src/main/java/jsprit/core/problem/cost/VehicleRoutingTransportCosts.java index 60a2c2b3..2d4ef280 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/cost/VehicleRoutingTransportCosts.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/cost/VehicleRoutingTransportCosts.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.problem.cost; @@ -19,12 +19,11 @@ package jsprit.core.problem.cost; /** * Interface for transportCost and transportTime. - * + *

*

Transport here is what happens between two activities within the transport system, i.e. in the physical transport network. And * must give the answer of how long does it take from A to B, and how much does this cost. - * + * * @author schroeder - * */ public interface VehicleRoutingTransportCosts extends TransportTime, TransportCost { diff --git a/jsprit-core/src/main/java/jsprit/core/problem/cost/WaitingTimeCosts.java b/jsprit-core/src/main/java/jsprit/core/problem/cost/WaitingTimeCosts.java new file mode 100644 index 00000000..73b9a35a --- /dev/null +++ b/jsprit-core/src/main/java/jsprit/core/problem/cost/WaitingTimeCosts.java @@ -0,0 +1,22 @@ +package jsprit.core.problem.cost; + +import jsprit.core.problem.driver.Driver; +import jsprit.core.problem.solution.route.activity.TourActivity; +import jsprit.core.problem.vehicle.Vehicle; + +/** + * Created by schroeder on 23/07/15. + */ +public class WaitingTimeCosts implements VehicleRoutingActivityCosts { + + @Override + public double getActivityCost(TourActivity tourAct, double arrivalTime, Driver driver, Vehicle vehicle) { + if (vehicle != null) { + double waiting = vehicle.getType().getVehicleCostParams().perWaitingTimeUnit * Math.max(0., tourAct.getTheoreticalEarliestOperationStartTime() - arrivalTime); + double servicing = vehicle.getType().getVehicleCostParams().perServiceTimeUnit * tourAct.getOperationTime(); + return waiting + servicing; + } + return 0; + } + +} diff --git a/jsprit-core/src/main/java/jsprit/core/problem/driver/Driver.java b/jsprit-core/src/main/java/jsprit/core/problem/driver/Driver.java index c64f4d39..da06de59 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/driver/Driver.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/driver/Driver.java @@ -1,23 +1,23 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.problem.driver; public interface Driver { - public String getId(); + public String getId(); } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/driver/DriverImpl.java b/jsprit-core/src/main/java/jsprit/core/problem/driver/DriverImpl.java index a4787ac5..bc8d6c97 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/driver/DriverImpl.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/driver/DriverImpl.java @@ -1,74 +1,74 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.problem.driver; public class DriverImpl implements Driver { - public static NoDriver noDriver(){ - return new NoDriver(); - } - - public static class NoDriver extends DriverImpl { + public static NoDriver noDriver() { + return new NoDriver(); + } - public NoDriver() { - super("noDriver"); - } - - } - - private String id; + public static class NoDriver extends DriverImpl { - private double earliestStart = 0.0; + public NoDriver() { + super("noDriver"); + } - private double latestEnd = Double.MAX_VALUE; + } - private String home; + private String id; - private DriverImpl(String id) { - super(); - this.id = id; - } + private double earliestStart = 0.0; - public String getId() { - return id; - } + private double latestEnd = Double.MAX_VALUE; - public double getEarliestStart() { - return earliestStart; - } + private String home; - public void setEarliestStart(double earliestStart) { - this.earliestStart = earliestStart; - } + private DriverImpl(String id) { + super(); + this.id = id; + } - public double getLatestEnd() { - return latestEnd; - } + public String getId() { + return id; + } - public void setLatestEnd(double latestEnd) { - this.latestEnd = latestEnd; - } + public double getEarliestStart() { + return earliestStart; + } - public void setHomeLocation(String locationId) { - this.home = locationId; - } + public void setEarliestStart(double earliestStart) { + this.earliestStart = earliestStart; + } - public String getHomeLocation() { - return this.home; - } + public double getLatestEnd() { + return latestEnd; + } + + public void setLatestEnd(double latestEnd) { + this.latestEnd = latestEnd; + } + + public void setHomeLocation(String locationId) { + this.home = locationId; + } + + public String getHomeLocation() { + return this.home; + } } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/io/Schema.java b/jsprit-core/src/main/java/jsprit/core/problem/io/Schema.java index 9bbdbb7b..d7edc5cc 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/io/Schema.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/io/Schema.java @@ -1,63 +1,65 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.problem.io; final class Schema { - public static final String PROBLEM = "problem"; - public static final String VEHICLE = "vehicle"; - public static final String TYPES = "vehicleTypes"; - public static final String VEHICLES = "vehicles"; - public static final String SHIPMENTS = "shipments"; - public static final String SHIPMENT = "shipment"; - public static final String SERVICETIME = "serviceTime"; - public static final String PICKUP = "pickup"; - public static final String TYPE = "type"; - - - public void dot(){ - - } - - public static class PathBuilder { - - StringBuilder stringBuilder = new StringBuilder(); - boolean justCreated = true; - - - public PathBuilder dot(String string){ - stringBuilder.append(".").append(string); - return this; - } - - public PathBuilder append(String string){ - stringBuilder.append(string); - return this; - } - - public String build(){ return stringBuilder.toString(); } - - } - - public static PathBuilder builder(){ - return new PathBuilder(); - } - - private Schema(){ - - } + public static final String PROBLEM = "problem"; + public static final String VEHICLE = "vehicle"; + public static final String TYPES = "vehicleTypes"; + public static final String VEHICLES = "vehicles"; + public static final String SHIPMENTS = "shipments"; + public static final String SHIPMENT = "shipment"; + public static final String SERVICETIME = "serviceTime"; + public static final String PICKUP = "pickup"; + public static final String TYPE = "type"; + + + public void dot() { + + } + + public static class PathBuilder { + + StringBuilder stringBuilder = new StringBuilder(); + boolean justCreated = true; + + + public PathBuilder dot(String string) { + stringBuilder.append(".").append(string); + return this; + } + + public PathBuilder append(String string) { + stringBuilder.append(string); + return this; + } + + public String build() { + return stringBuilder.toString(); + } + + } + + public static PathBuilder builder() { + return new PathBuilder(); + } + + private Schema() { + + } } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/io/VrpXMLReader.java b/jsprit-core/src/main/java/jsprit/core/problem/io/VrpXMLReader.java index 5747c0bb..89104e09 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/io/VrpXMLReader.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/io/VrpXMLReader.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.problem.io; @@ -46,587 +46,584 @@ import java.io.IOException; import java.io.InputStream; import java.util.*; -public class VrpXMLReader{ - - public interface ServiceBuilderFactory { - Service.Builder createBuilder(String serviceType, String id, Integer size); - } - - static class DefaultServiceBuilderFactory implements ServiceBuilderFactory{ +public class VrpXMLReader { - @Override - public jsprit.core.problem.job.Service.Builder createBuilder(String serviceType, String id, Integer size) { - if(serviceType.equals("pickup")){ - if(size != null) return Pickup.Builder.newInstance(id).addSizeDimension(0, size); - else return Pickup.Builder.newInstance(id); - } - else if(serviceType.equals("delivery")){ - if(size != null) return Delivery.Builder.newInstance(id).addSizeDimension(0, size); - else return Delivery.Builder.newInstance(id); - } - else{ - if(size != null) return Service.Builder.newInstance(id).addSizeDimension(0, size); - else return Service.Builder.newInstance(id); - - } - } - } + public interface ServiceBuilderFactory { + Service.Builder createBuilder(String serviceType, String id, Integer size); + } + + static class DefaultServiceBuilderFactory implements ServiceBuilderFactory { + + @Override + public jsprit.core.problem.job.Service.Builder createBuilder(String serviceType, String id, Integer size) { + if (serviceType.equals("pickup")) { + if (size != null) return Pickup.Builder.newInstance(id).addSizeDimension(0, size); + else return Pickup.Builder.newInstance(id); + } else if (serviceType.equals("delivery")) { + if (size != null) return Delivery.Builder.newInstance(id).addSizeDimension(0, size); + else return Delivery.Builder.newInstance(id); + } else { + if (size != null) return Service.Builder.newInstance(id).addSizeDimension(0, size); + else return Service.Builder.newInstance(id); + + } + } + } @Deprecated - interface JobConfigReader { + interface JobConfigReader { - void readConfig(XMLConfiguration vrpProblem); - } + void readConfig(XMLConfiguration vrpProblem); + } - private static Logger logger = LogManager.getLogger(VrpXMLReader.class); - - private VehicleRoutingProblem.Builder vrpBuilder; - - private Map vehicleMap; + private static Logger logger = LogManager.getLogger(VrpXMLReader.class); - private Map serviceMap; - - private Map shipmentMap; - - private Set freezedJobIds = new HashSet(); - - private boolean schemaValidation = true; + private VehicleRoutingProblem.Builder vrpBuilder; - private Collection solutions; - - private ServiceBuilderFactory serviceBuilderFactory = new DefaultServiceBuilderFactory(); - - private Collection jobConfigReaders = new ArrayList(); + private Map vehicleMap; - @Deprecated - public void addJobConfigReader(JobConfigReader reader){ - jobConfigReaders.add(reader); - } + private Map serviceMap; + + private Map shipmentMap; + + private Set freezedJobIds = new HashSet(); + + private boolean schemaValidation = true; + + private Collection solutions; + + private ServiceBuilderFactory serviceBuilderFactory = new DefaultServiceBuilderFactory(); + + private Collection jobConfigReaders = new ArrayList(); @Deprecated - public void setTourActivityFactory(TourActivityFactory tourActivityFactory){ - } + public void addJobConfigReader(JobConfigReader reader) { + jobConfigReaders.add(reader); + } @Deprecated - public void setServiceBuilderFactory(ServiceBuilderFactory serviceBuilderFactory){ - this.serviceBuilderFactory=serviceBuilderFactory; - } - - /** - * @param schemaValidation the schemaValidation to set - */ - @SuppressWarnings("UnusedDeclaration") + public void setTourActivityFactory(TourActivityFactory tourActivityFactory) { + } + + @Deprecated + public void setServiceBuilderFactory(ServiceBuilderFactory serviceBuilderFactory) { + this.serviceBuilderFactory = serviceBuilderFactory; + } + + /** + * @param schemaValidation the schemaValidation to set + */ + @SuppressWarnings("UnusedDeclaration") public void setSchemaValidation(boolean schemaValidation) { - this.schemaValidation = schemaValidation; - } + this.schemaValidation = schemaValidation; + } - public VrpXMLReader(VehicleRoutingProblem.Builder vrpBuilder, Collection solutions){ - this.vrpBuilder = vrpBuilder; - this.vehicleMap = new LinkedHashMap(); - this.serviceMap = new LinkedHashMap(); - this.shipmentMap = new LinkedHashMap(); - this.solutions = solutions; - } - - public VrpXMLReader(VehicleRoutingProblem.Builder vrpBuilder){ - this.vrpBuilder = vrpBuilder; - this.vehicleMap = new LinkedHashMap(); - this.serviceMap = new LinkedHashMap(); - this.shipmentMap = new LinkedHashMap(); - this.solutions = null; - } - - public void read(String filename) { - logger.debug("read vrp: " + filename); - XMLConfiguration xmlConfig = new XMLConfiguration(); - xmlConfig.setFileName(filename); - xmlConfig.setAttributeSplittingDisabled(true); - xmlConfig.setDelimiterParsingDisabled(true); - - if(schemaValidation){ - final InputStream resource = Resource.getAsInputStream("vrp_xml_schema.xsd"); - if(resource != null) { - EntityResolver resolver = new EntityResolver() { + public VrpXMLReader(VehicleRoutingProblem.Builder vrpBuilder, Collection solutions) { + this.vrpBuilder = vrpBuilder; + this.vehicleMap = new LinkedHashMap(); + this.serviceMap = new LinkedHashMap(); + this.shipmentMap = new LinkedHashMap(); + this.solutions = solutions; + } - @Override - public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { - { - InputSource is = new InputSource(resource); - return is; - } - } - }; - xmlConfig.setEntityResolver(resolver); - xmlConfig.setSchemaValidation(true); - } - else{ - logger.debug("cannot find schema-xsd file (vrp_xml_schema.xsd). try to read xml without xml-file-validation."); - } - } - try { - xmlConfig.load(); - } catch (ConfigurationException e) { - logger.error(e); - e.printStackTrace(); - System.exit(1); - } - readProblemType(xmlConfig); - readVehiclesAndTheirTypes(xmlConfig); - - readShipments(xmlConfig); - readServices(xmlConfig); - - readInitialRoutes(xmlConfig); - readSolutions(xmlConfig); - - addJobsAndTheirLocationsToVrp(); - } + public VrpXMLReader(VehicleRoutingProblem.Builder vrpBuilder) { + this.vrpBuilder = vrpBuilder; + this.vehicleMap = new LinkedHashMap(); + this.serviceMap = new LinkedHashMap(); + this.shipmentMap = new LinkedHashMap(); + this.solutions = null; + } - private void addJobsAndTheirLocationsToVrp() { - for(Service service : serviceMap.values()) { - if(!freezedJobIds.contains(service.getId())){ - vrpBuilder.addJob(service); - } - } - for(Shipment shipment : shipmentMap.values()){ - if(!freezedJobIds.contains(shipment.getId())){ - vrpBuilder.addJob(shipment); - } - } - } - private void readInitialRoutes(XMLConfiguration xmlConfig) { - List initialRouteConfigs = xmlConfig.configurationsAt("initialRoutes.route"); - for(HierarchicalConfiguration routeConfig : initialRouteConfigs){ - Driver driver = DriverImpl.noDriver(); - String vehicleId = routeConfig.getString("vehicleId"); - Vehicle vehicle = getVehicle(vehicleId); - if(vehicle == null) throw new IllegalStateException("vehicle is missing."); - String start = routeConfig.getString("start"); - if(start == null) throw new IllegalStateException("route start-time is missing."); - double departureTime = Double.parseDouble(start); - - VehicleRoute.Builder routeBuilder = VehicleRoute.Builder.newInstance(vehicle, driver); - routeBuilder.setDepartureTime(departureTime); - - List actConfigs = routeConfig.configurationsAt("act"); - for(HierarchicalConfiguration actConfig : actConfigs){ - String type = actConfig.getString("[@type]"); - if(type == null) throw new IllegalStateException("act[@type] is missing."); - double arrTime = 0.; - double endTime = 0.; - String arrTimeS = actConfig.getString("arrTime"); - if(arrTimeS!=null) arrTime=Double.parseDouble(arrTimeS); - String endTimeS = actConfig.getString("endTime"); - if(endTimeS!=null) endTime=Double.parseDouble(endTimeS); - - String serviceId = actConfig.getString("serviceId"); - if(serviceId != null) { - Service service = getService(serviceId); - if(service==null) throw new IllegalStateException("service to serviceId " + serviceId + " is missing (reference in one of your initial routes). make sure you define the service you refer to here in ."); - //!!!since job is part of initial route, it does not belong to jobs in problem, i.e. variable jobs that can be assigned/scheduled - freezedJobIds.add(serviceId); - routeBuilder.addService(service); - } - else{ - String shipmentId = actConfig.getString("shipmentId"); - if(shipmentId == null) throw new IllegalStateException("either serviceId or shipmentId is missing"); - Shipment shipment = getShipment(shipmentId); - if(shipment == null) throw new IllegalStateException("shipment to shipmentId " + shipmentId + " is missing (reference in one of your initial routes). make sure you define the shipment you refer to here in ."); - freezedJobIds.add(shipmentId); - if(type.equals("pickupShipment")){ - routeBuilder.addPickup(shipment); - } - else if(type.equals("deliverShipment")){ - routeBuilder.addDelivery(shipment); - } - else throw new IllegalStateException("type " + type + " is not supported. Use 'pickupShipment' or 'deliverShipment' here"); - } - } - VehicleRoute route = routeBuilder.build(); - vrpBuilder.addInitialVehicleRoute(route); - } - - } - private void readSolutions(XMLConfiguration vrpProblem) { - if(solutions == null) return; - List solutionConfigs = vrpProblem.configurationsAt("solutions.solution"); - for(HierarchicalConfiguration solutionConfig : solutionConfigs){ - String totalCost = solutionConfig.getString("cost"); - double cost = -1; - if(totalCost != null) cost = Double.parseDouble(totalCost); - List routeConfigs = solutionConfig.configurationsAt("routes.route"); - List routes = new ArrayList(); - for(HierarchicalConfiguration routeConfig : routeConfigs){ - //! here, driverId is set to noDriver, no matter whats in driverId. - Driver driver = DriverImpl.noDriver(); - String vehicleId = routeConfig.getString("vehicleId"); - Vehicle vehicle = getVehicle(vehicleId); - if(vehicle == null) throw new IllegalStateException("vehicle is missing."); - String start = routeConfig.getString("start"); - if(start == null) throw new IllegalStateException("route start-time is missing."); - double departureTime = Double.parseDouble(start); - - String end = routeConfig.getString("end"); - if(end == null) throw new IllegalStateException("route end-time is missing."); - - VehicleRoute.Builder routeBuilder = VehicleRoute.Builder.newInstance(vehicle, driver); - routeBuilder.setDepartureTime(departureTime); - routeBuilder.setRouteEndArrivalTime(Double.parseDouble(end)); - List actConfigs = routeConfig.configurationsAt("act"); - for(HierarchicalConfiguration actConfig : actConfigs){ - String type = actConfig.getString("[@type]"); - if(type == null) throw new IllegalStateException("act[@type] is missing."); - double arrTime = 0.; - double endTime = 0.; - String arrTimeS = actConfig.getString("arrTime"); - if(arrTimeS!=null) arrTime=Double.parseDouble(arrTimeS); - String endTimeS = actConfig.getString("endTime"); - if(endTimeS!=null) endTime=Double.parseDouble(endTimeS); - - String serviceId = actConfig.getString("serviceId"); - if(serviceId != null) { - Service service = getService(serviceId); - routeBuilder.addService(service); - } - else{ - String shipmentId = actConfig.getString("shipmentId"); - if(shipmentId == null) throw new IllegalStateException("either serviceId or shipmentId is missing"); - Shipment shipment = getShipment(shipmentId); - if(shipment == null) throw new IllegalStateException("shipment with id " + shipmentId + " does not exist."); - if(type.equals("pickupShipment")){ - routeBuilder.addPickup(shipment); - } - else if(type.equals("deliverShipment")){ - routeBuilder.addDelivery(shipment); - } - else throw new IllegalStateException("type " + type + " is not supported. Use 'pickupShipment' or 'deliverShipment' here"); - } - } - routes.add(routeBuilder.build()); - } + public void read(String filename) { + logger.debug("read vrp: {}", filename); + XMLConfiguration xmlConfig = new XMLConfiguration(); + xmlConfig.setFileName(filename); + xmlConfig.setAttributeSplittingDisabled(true); + xmlConfig.setDelimiterParsingDisabled(true); + + if (schemaValidation) { + final InputStream resource = Resource.getAsInputStream("vrp_xml_schema.xsd"); + if (resource != null) { + EntityResolver resolver = new EntityResolver() { + + @Override + public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { + { + InputSource is = new InputSource(resource); + return is; + } + } + }; + xmlConfig.setEntityResolver(resolver); + xmlConfig.setSchemaValidation(true); + } else { + logger.debug("cannot find schema-xsd file (vrp_xml_schema.xsd). try to read xml without xml-file-validation."); + } + } + try { + xmlConfig.load(); + } catch (ConfigurationException e) { + throw new RuntimeException(e); + } + readProblemType(xmlConfig); + readVehiclesAndTheirTypes(xmlConfig); + + readShipments(xmlConfig); + readServices(xmlConfig); + + readInitialRoutes(xmlConfig); + readSolutions(xmlConfig); + + addJobsAndTheirLocationsToVrp(); + } + + private void addJobsAndTheirLocationsToVrp() { + for (Service service : serviceMap.values()) { + if (!freezedJobIds.contains(service.getId())) { + vrpBuilder.addJob(service); + } + } + for (Shipment shipment : shipmentMap.values()) { + if (!freezedJobIds.contains(shipment.getId())) { + vrpBuilder.addJob(shipment); + } + } + } + + private void readInitialRoutes(XMLConfiguration xmlConfig) { + List initialRouteConfigs = xmlConfig.configurationsAt("initialRoutes.route"); + for (HierarchicalConfiguration routeConfig : initialRouteConfigs) { + Driver driver = DriverImpl.noDriver(); + String vehicleId = routeConfig.getString("vehicleId"); + Vehicle vehicle = getVehicle(vehicleId); + if (vehicle == null) throw new IllegalStateException("vehicle is missing."); + String start = routeConfig.getString("start"); + if (start == null) throw new IllegalStateException("route start-time is missing."); + double departureTime = Double.parseDouble(start); + + VehicleRoute.Builder routeBuilder = VehicleRoute.Builder.newInstance(vehicle, driver); + routeBuilder.setDepartureTime(departureTime); + + List actConfigs = routeConfig.configurationsAt("act"); + for (HierarchicalConfiguration actConfig : actConfigs) { + String type = actConfig.getString("[@type]"); + if (type == null) throw new IllegalStateException("act[@type] is missing."); + double arrTime = 0.; + double endTime = 0.; + String arrTimeS = actConfig.getString("arrTime"); + if (arrTimeS != null) arrTime = Double.parseDouble(arrTimeS); + String endTimeS = actConfig.getString("endTime"); + if (endTimeS != null) endTime = Double.parseDouble(endTimeS); + + String serviceId = actConfig.getString("serviceId"); + if (serviceId != null) { + Service service = getService(serviceId); + if (service == null) + throw new IllegalStateException("service to serviceId " + serviceId + " is missing (reference in one of your initial routes). make sure you define the service you refer to here in ."); + //!!!since job is part of initial route, it does not belong to jobs in problem, i.e. variable jobs that can be assigned/scheduled + freezedJobIds.add(serviceId); + routeBuilder.addService(service); + } else { + String shipmentId = actConfig.getString("shipmentId"); + if (shipmentId == null) + throw new IllegalStateException("either serviceId or shipmentId is missing"); + Shipment shipment = getShipment(shipmentId); + if (shipment == null) + throw new IllegalStateException("shipment to shipmentId " + shipmentId + " is missing (reference in one of your initial routes). make sure you define the shipment you refer to here in ."); + freezedJobIds.add(shipmentId); + if (type.equals("pickupShipment")) { + routeBuilder.addPickup(shipment); + } else if (type.equals("deliverShipment")) { + routeBuilder.addDelivery(shipment); + } else + throw new IllegalStateException("type " + type + " is not supported. Use 'pickupShipment' or 'deliverShipment' here"); + } + } + VehicleRoute route = routeBuilder.build(); + vrpBuilder.addInitialVehicleRoute(route); + } + + } + + private void readSolutions(XMLConfiguration vrpProblem) { + if (solutions == null) return; + List solutionConfigs = vrpProblem.configurationsAt("solutions.solution"); + for (HierarchicalConfiguration solutionConfig : solutionConfigs) { + String totalCost = solutionConfig.getString("cost"); + double cost = -1; + if (totalCost != null) cost = Double.parseDouble(totalCost); + List routeConfigs = solutionConfig.configurationsAt("routes.route"); + List routes = new ArrayList(); + for (HierarchicalConfiguration routeConfig : routeConfigs) { + //! here, driverId is set to noDriver, no matter whats in driverId. + Driver driver = DriverImpl.noDriver(); + String vehicleId = routeConfig.getString("vehicleId"); + Vehicle vehicle = getVehicle(vehicleId); + if (vehicle == null) throw new IllegalStateException("vehicle is missing."); + String start = routeConfig.getString("start"); + if (start == null) throw new IllegalStateException("route start-time is missing."); + double departureTime = Double.parseDouble(start); + + String end = routeConfig.getString("end"); + if (end == null) throw new IllegalStateException("route end-time is missing."); + + VehicleRoute.Builder routeBuilder = VehicleRoute.Builder.newInstance(vehicle, driver); + routeBuilder.setDepartureTime(departureTime); + routeBuilder.setRouteEndArrivalTime(Double.parseDouble(end)); + List actConfigs = routeConfig.configurationsAt("act"); + for (HierarchicalConfiguration actConfig : actConfigs) { + String type = actConfig.getString("[@type]"); + if (type == null) throw new IllegalStateException("act[@type] is missing."); + double arrTime = 0.; + double endTime = 0.; + String arrTimeS = actConfig.getString("arrTime"); + if (arrTimeS != null) arrTime = Double.parseDouble(arrTimeS); + String endTimeS = actConfig.getString("endTime"); + if (endTimeS != null) endTime = Double.parseDouble(endTimeS); + + String serviceId = actConfig.getString("serviceId"); + if (serviceId != null) { + Service service = getService(serviceId); + routeBuilder.addService(service); + } else { + String shipmentId = actConfig.getString("shipmentId"); + if (shipmentId == null) + throw new IllegalStateException("either serviceId or shipmentId is missing"); + Shipment shipment = getShipment(shipmentId); + if (shipment == null) + throw new IllegalStateException("shipment with id " + shipmentId + " does not exist."); + if (type.equals("pickupShipment")) { + routeBuilder.addPickup(shipment); + } else if (type.equals("deliverShipment")) { + routeBuilder.addDelivery(shipment); + } else + throw new IllegalStateException("type " + type + " is not supported. Use 'pickupShipment' or 'deliverShipment' here"); + } + } + routes.add(routeBuilder.build()); + } VehicleRoutingProblemSolution solution = new VehicleRoutingProblemSolution(routes, cost); List unassignedJobConfigs = solutionConfig.configurationsAt("unassignedJobs.job"); - for(HierarchicalConfiguration unassignedJobConfig : unassignedJobConfigs){ + for (HierarchicalConfiguration unassignedJobConfig : unassignedJobConfigs) { String jobId = unassignedJobConfig.getString("[@id]"); Job job = getShipment(jobId); - if(job == null) job = getService(jobId); - if(job == null) throw new IllegalStateException("cannot find unassignedJob with id " + jobId); + if (job == null) job = getService(jobId); + if (job == null) throw new IllegalStateException("cannot find unassignedJob with id " + jobId); solution.getUnassignedJobs().add(job); } - solutions.add(solution); - } - } - - private Shipment getShipment(String shipmentId) { - return shipmentMap.get(shipmentId); - } - private Service getService(String serviceId) { - return serviceMap.get(serviceId); - } + solutions.add(solution); + } + } - private Vehicle getVehicle(String vehicleId) { - return vehicleMap.get(vehicleId); - } + private Shipment getShipment(String shipmentId) { + return shipmentMap.get(shipmentId); + } - private void readProblemType(XMLConfiguration vrpProblem) { - String fleetSize = vrpProblem.getString("problemType.fleetSize"); - if(fleetSize == null) vrpBuilder.setFleetSize(FleetSize.INFINITE); - else if(fleetSize.toUpperCase().equals(FleetSize.INFINITE.toString())) vrpBuilder.setFleetSize(FleetSize.INFINITE); - else vrpBuilder.setFleetSize(FleetSize.FINITE); - } - - private void readShipments(XMLConfiguration config){ - List shipmentConfigs = config.configurationsAt("shipments.shipment"); - for(HierarchicalConfiguration shipmentConfig : shipmentConfigs){ - String id = shipmentConfig.getString("[@id]"); - if(id == null) throw new IllegalStateException("shipment[@id] is missing."); - - String capacityString = shipmentConfig.getString("capacity-demand"); - boolean capacityDimensionsExist = shipmentConfig.containsKey("capacity-dimensions.dimension(0)"); - if(capacityString == null && !capacityDimensionsExist){ - throw new IllegalStateException("capacity of shipment is not set. use 'capacity-dimensions'"); - } - if(capacityString != null && capacityDimensionsExist){ - throw new IllegalStateException("either use capacity or capacity-dimension, not both. prefer the use of 'capacity-dimensions' over 'capacity'."); - } - - Shipment.Builder builder; - if(capacityString != null){ - builder = Shipment.Builder.newInstance(id).addSizeDimension(0, Integer.parseInt(capacityString)); - } - else { - builder = Shipment.Builder.newInstance(id); - List dimensionConfigs = shipmentConfig.configurationsAt("capacity-dimensions.dimension"); - for(HierarchicalConfiguration dimension : dimensionConfigs){ - Integer index = dimension.getInt("[@index]"); - Integer value = dimension.getInt(""); - builder.addSizeDimension(index, value); - } - } + private Service getService(String serviceId) { + return serviceMap.get(serviceId); + } + + private Vehicle getVehicle(String vehicleId) { + return vehicleMap.get(vehicleId); + } + + private void readProblemType(XMLConfiguration vrpProblem) { + String fleetSize = vrpProblem.getString("problemType.fleetSize"); + if (fleetSize == null) vrpBuilder.setFleetSize(FleetSize.INFINITE); + else if (fleetSize.toUpperCase().equals(FleetSize.INFINITE.toString())) + vrpBuilder.setFleetSize(FleetSize.INFINITE); + else vrpBuilder.setFleetSize(FleetSize.FINITE); + } + + private void readShipments(XMLConfiguration config) { + List shipmentConfigs = config.configurationsAt("shipments.shipment"); + for (HierarchicalConfiguration shipmentConfig : shipmentConfigs) { + String id = shipmentConfig.getString("[@id]"); + if (id == null) throw new IllegalStateException("shipment[@id] is missing."); + + String capacityString = shipmentConfig.getString("capacity-demand"); + boolean capacityDimensionsExist = shipmentConfig.containsKey("capacity-dimensions.dimension(0)"); + if (capacityString == null && !capacityDimensionsExist) { + throw new IllegalStateException("capacity of shipment is not set. use 'capacity-dimensions'"); + } + if (capacityString != null && capacityDimensionsExist) { + throw new IllegalStateException("either use capacity or capacity-dimension, not both. prefer the use of 'capacity-dimensions' over 'capacity'."); + } + + Shipment.Builder builder; + if (capacityString != null) { + builder = Shipment.Builder.newInstance(id).addSizeDimension(0, Integer.parseInt(capacityString)); + } else { + builder = Shipment.Builder.newInstance(id); + List dimensionConfigs = shipmentConfig.configurationsAt("capacity-dimensions.dimension"); + for (HierarchicalConfiguration dimension : dimensionConfigs) { + Integer index = dimension.getInt("[@index]"); + Integer value = dimension.getInt(""); + builder.addSizeDimension(index, value); + } + } //name String name = shipmentConfig.getString("name"); - if(name != null) builder.setName(name); + if (name != null) builder.setName(name); //pickup location - //pickup-locationId + //pickup-locationId Location.Builder pickupLocationBuilder = Location.Builder.newInstance(); - String pickupLocationId = shipmentConfig.getString("pickup.locationId"); - if(pickupLocationId == null) pickupLocationId = shipmentConfig.getString("pickup.location.id"); - if(pickupLocationId != null){ + String pickupLocationId = shipmentConfig.getString("pickup.locationId"); + if (pickupLocationId == null) pickupLocationId = shipmentConfig.getString("pickup.location.id"); + if (pickupLocationId != null) { pickupLocationBuilder.setId(pickupLocationId); - } - - //pickup-coord - Coordinate pickupCoord = getCoord(shipmentConfig,"pickup."); - if(pickupCoord == null) pickupCoord = getCoord(shipmentConfig,"pickup.location."); - if(pickupCoord != null){ + } + + //pickup-coord + Coordinate pickupCoord = getCoord(shipmentConfig, "pickup."); + if (pickupCoord == null) pickupCoord = getCoord(shipmentConfig, "pickup.location."); + if (pickupCoord != null) { pickupLocationBuilder.setCoordinate(pickupCoord); - } + } //pickup.location.index String pickupLocationIndex = shipmentConfig.getString("pickup.location.index"); - if(pickupLocationIndex != null) pickupLocationBuilder.setIndex(Integer.parseInt(pickupLocationIndex)); + if (pickupLocationIndex != null) pickupLocationBuilder.setIndex(Integer.parseInt(pickupLocationIndex)); builder.setPickupLocation(pickupLocationBuilder.build()); - //pickup-serviceTime - String pickupServiceTime = shipmentConfig.getString("pickup.duration"); - if(pickupServiceTime != null) builder.setPickupServiceTime(Double.parseDouble(pickupServiceTime)); - - //pickup-tw - String pickupTWStart = shipmentConfig.getString("pickup.timeWindows.timeWindow(0).start"); - String pickupTWEnd = shipmentConfig.getString("pickup.timeWindows.timeWindow(0).end"); - if(pickupTWStart != null && pickupTWEnd != null){ - TimeWindow pickupTW = TimeWindow.newInstance(Double.parseDouble(pickupTWStart), Double.parseDouble(pickupTWEnd)); - builder.setPickupTimeWindow(pickupTW); - } + //pickup-serviceTime + String pickupServiceTime = shipmentConfig.getString("pickup.duration"); + if (pickupServiceTime != null) builder.setPickupServiceTime(Double.parseDouble(pickupServiceTime)); + + //pickup-tw + String pickupTWStart = shipmentConfig.getString("pickup.timeWindows.timeWindow(0).start"); + String pickupTWEnd = shipmentConfig.getString("pickup.timeWindows.timeWindow(0).end"); + if (pickupTWStart != null && pickupTWEnd != null) { + TimeWindow pickupTW = TimeWindow.newInstance(Double.parseDouble(pickupTWStart), Double.parseDouble(pickupTWEnd)); + builder.setPickupTimeWindow(pickupTW); + } //delivery location - //delivery-locationId + //delivery-locationId Location.Builder deliveryLocationBuilder = Location.Builder.newInstance(); - String deliveryLocationId = shipmentConfig.getString("delivery.locationId"); - if(deliveryLocationId == null) deliveryLocationId = shipmentConfig.getString("delivery.location.id"); - if(deliveryLocationId != null){ + String deliveryLocationId = shipmentConfig.getString("delivery.locationId"); + if (deliveryLocationId == null) deliveryLocationId = shipmentConfig.getString("delivery.location.id"); + if (deliveryLocationId != null) { deliveryLocationBuilder.setId(deliveryLocationId); // builder.setDeliveryLocationId(deliveryLocationId); - } - - //delivery-coord - Coordinate deliveryCoord = getCoord(shipmentConfig,"delivery."); - if(deliveryCoord == null) deliveryCoord = getCoord(shipmentConfig,"delivery.location."); - if(deliveryCoord != null){ + } + + //delivery-coord + Coordinate deliveryCoord = getCoord(shipmentConfig, "delivery."); + if (deliveryCoord == null) deliveryCoord = getCoord(shipmentConfig, "delivery.location."); + if (deliveryCoord != null) { deliveryLocationBuilder.setCoordinate(deliveryCoord); - } + } String deliveryLocationIndex = shipmentConfig.getString("delivery.location.index"); - if(deliveryLocationIndex != null) deliveryLocationBuilder.setIndex(Integer.parseInt(deliveryLocationIndex)); + if (deliveryLocationIndex != null) + deliveryLocationBuilder.setIndex(Integer.parseInt(deliveryLocationIndex)); builder.setDeliveryLocation(deliveryLocationBuilder.build()); - //delivery-serviceTime - String deliveryServiceTime = shipmentConfig.getString("delivery.duration"); - if(deliveryServiceTime != null) builder.setDeliveryServiceTime(Double.parseDouble(deliveryServiceTime)); - - //delivery-tw - String delTWStart = shipmentConfig.getString("delivery.timeWindows.timeWindow(0).start"); - String delTWEnd = shipmentConfig.getString("delivery.timeWindows.timeWindow(0).end"); - if(delTWStart != null && delTWEnd != null){ - TimeWindow delTW = TimeWindow.newInstance(Double.parseDouble(delTWStart), Double.parseDouble(delTWEnd)); - builder.setDeliveryTimeWindow(delTW); - } + //delivery-serviceTime + String deliveryServiceTime = shipmentConfig.getString("delivery.duration"); + if (deliveryServiceTime != null) builder.setDeliveryServiceTime(Double.parseDouble(deliveryServiceTime)); + + //delivery-tw + String delTWStart = shipmentConfig.getString("delivery.timeWindows.timeWindow(0).start"); + String delTWEnd = shipmentConfig.getString("delivery.timeWindows.timeWindow(0).end"); + if (delTWStart != null && delTWEnd != null) { + TimeWindow delTW = TimeWindow.newInstance(Double.parseDouble(delTWStart), Double.parseDouble(delTWEnd)); + builder.setDeliveryTimeWindow(delTW); + } //read skills String skillString = shipmentConfig.getString("requiredSkills"); - if(skillString != null){ - String cleaned = skillString.replaceAll("\\s",""); + if (skillString != null) { + String cleaned = skillString.replaceAll("\\s", ""); String[] skillTokens = cleaned.split("[,;]"); - for(String skill : skillTokens) builder.addRequiredSkill(skill.toLowerCase()); + for (String skill : skillTokens) builder.addRequiredSkill(skill.toLowerCase()); } - //build shipment - Shipment shipment = builder.build(); + //build shipment + Shipment shipment = builder.build(); // vrpBuilder.addJob(shipment); - shipmentMap.put(shipment.getId(),shipment); - } - } + shipmentMap.put(shipment.getId(), shipment); + } + } - private static Coordinate getCoord(HierarchicalConfiguration serviceConfig, String prefix) { - Coordinate pickupCoord = null; - if(serviceConfig.getString(prefix + "coord[@x]") != null && serviceConfig.getString(prefix + "coord[@y]") != null){ - double x = Double.parseDouble(serviceConfig.getString(prefix + "coord[@x]")); - double y = Double.parseDouble(serviceConfig.getString(prefix + "coord[@y]")); - pickupCoord = Coordinate.newInstance(x,y); - } - return pickupCoord; - } + private static Coordinate getCoord(HierarchicalConfiguration serviceConfig, String prefix) { + Coordinate pickupCoord = null; + if (serviceConfig.getString(prefix + "coord[@x]") != null && serviceConfig.getString(prefix + "coord[@y]") != null) { + double x = Double.parseDouble(serviceConfig.getString(prefix + "coord[@x]")); + double y = Double.parseDouble(serviceConfig.getString(prefix + "coord[@y]")); + pickupCoord = Coordinate.newInstance(x, y); + } + return pickupCoord; + } - private void readServices(XMLConfiguration vrpProblem) { - List serviceConfigs = vrpProblem.configurationsAt("services.service"); - for(HierarchicalConfiguration serviceConfig : serviceConfigs){ - String id = serviceConfig.getString("[@id]"); - if(id == null) throw new IllegalStateException("service[@id] is missing."); - String type = serviceConfig.getString("[@type]"); - if(type == null) type = "service"; - - String capacityString = serviceConfig.getString("capacity-demand"); - boolean capacityDimensionsExist = serviceConfig.containsKey("capacity-dimensions.dimension(0)"); - if(capacityString == null && !capacityDimensionsExist){ - throw new IllegalStateException("capacity of service is not set. use 'capacity-dimensions'"); - } - if(capacityString != null && capacityDimensionsExist){ - throw new IllegalStateException("either use capacity or capacity-dimension, not both. prefer the use of 'capacity-dimensions' over 'capacity'."); - } - - Service.Builder builder; - if(capacityString != null){ - builder = serviceBuilderFactory.createBuilder(type, id, Integer.parseInt(capacityString)); - } - else { - builder = serviceBuilderFactory.createBuilder(type, id, null); - List dimensionConfigs = serviceConfig.configurationsAt("capacity-dimensions.dimension"); - for(HierarchicalConfiguration dimension : dimensionConfigs){ - Integer index = dimension.getInt("[@index]"); - Integer value = dimension.getInt(""); - builder.addSizeDimension(index, value); - } - } + private void readServices(XMLConfiguration vrpProblem) { + List serviceConfigs = vrpProblem.configurationsAt("services.service"); + for (HierarchicalConfiguration serviceConfig : serviceConfigs) { + String id = serviceConfig.getString("[@id]"); + if (id == null) throw new IllegalStateException("service[@id] is missing."); + String type = serviceConfig.getString("[@type]"); + if (type == null) type = "service"; + + String capacityString = serviceConfig.getString("capacity-demand"); + boolean capacityDimensionsExist = serviceConfig.containsKey("capacity-dimensions.dimension(0)"); + if (capacityString == null && !capacityDimensionsExist) { + throw new IllegalStateException("capacity of service is not set. use 'capacity-dimensions'"); + } + if (capacityString != null && capacityDimensionsExist) { + throw new IllegalStateException("either use capacity or capacity-dimension, not both. prefer the use of 'capacity-dimensions' over 'capacity'."); + } + + Service.Builder builder; + if (capacityString != null) { + builder = serviceBuilderFactory.createBuilder(type, id, Integer.parseInt(capacityString)); + } else { + builder = serviceBuilderFactory.createBuilder(type, id, null); + List dimensionConfigs = serviceConfig.configurationsAt("capacity-dimensions.dimension"); + for (HierarchicalConfiguration dimension : dimensionConfigs) { + Integer index = dimension.getInt("[@index]"); + Integer value = dimension.getInt(""); + builder.addSizeDimension(index, value); + } + } //name String name = serviceConfig.getString("name"); - if(name != null) builder.setName(name); + if (name != null) builder.setName(name); //location Location.Builder locationBuilder = Location.Builder.newInstance(); - String serviceLocationId = serviceConfig.getString("locationId"); - if(serviceLocationId == null) { + String serviceLocationId = serviceConfig.getString("locationId"); + if (serviceLocationId == null) { serviceLocationId = serviceConfig.getString("location.id"); } - if(serviceLocationId != null) locationBuilder.setId(serviceLocationId); + if (serviceLocationId != null) locationBuilder.setId(serviceLocationId); - Coordinate serviceCoord = getCoord(serviceConfig,""); - if(serviceCoord == null) serviceCoord = getCoord(serviceConfig,"location."); - if(serviceCoord != null){ - locationBuilder.setCoordinate(serviceCoord); - } + Coordinate serviceCoord = getCoord(serviceConfig, ""); + if (serviceCoord == null) serviceCoord = getCoord(serviceConfig, "location."); + if (serviceCoord != null) { + locationBuilder.setCoordinate(serviceCoord); + } String locationIndex = serviceConfig.getString("location.index"); - if(locationIndex != null) locationBuilder.setIndex(Integer.parseInt(locationIndex)); + if (locationIndex != null) locationBuilder.setIndex(Integer.parseInt(locationIndex)); builder.setLocation(locationBuilder.build()); - if(serviceConfig.containsKey("duration")){ - builder.setServiceTime(serviceConfig.getDouble("duration")); - } - List deliveryTWConfigs = serviceConfig.configurationsAt("timeWindows.timeWindow"); - if(!deliveryTWConfigs.isEmpty()){ - for(HierarchicalConfiguration twConfig : deliveryTWConfigs){ - builder.setTimeWindow(TimeWindow.newInstance(twConfig.getDouble("start"), twConfig.getDouble("end"))); - } - } + if (serviceConfig.containsKey("duration")) { + builder.setServiceTime(serviceConfig.getDouble("duration")); + } + List deliveryTWConfigs = serviceConfig.configurationsAt("timeWindows.timeWindow"); + if (!deliveryTWConfigs.isEmpty()) { + for (HierarchicalConfiguration twConfig : deliveryTWConfigs) { + builder.setTimeWindow(TimeWindow.newInstance(twConfig.getDouble("start"), twConfig.getDouble("end"))); + } + } //read skills String skillString = serviceConfig.getString("requiredSkills"); - if(skillString != null){ - String cleaned = skillString.replaceAll("\\s",""); + if (skillString != null) { + String cleaned = skillString.replaceAll("\\s", ""); String[] skillTokens = cleaned.split("[,;]"); - for(String skill : skillTokens) builder.addRequiredSkill(skill.toLowerCase()); + for (String skill : skillTokens) builder.addRequiredSkill(skill.toLowerCase()); } //build service - Service service = builder.build(); - serviceMap.put(service.getId(),service); + Service service = builder.build(); + serviceMap.put(service.getId(), service); // vrpBuilder.addJob(service); - } - } + } + } - private void readVehiclesAndTheirTypes(XMLConfiguration vrpProblem) { + private void readVehiclesAndTheirTypes(XMLConfiguration vrpProblem) { - //read vehicle-types - Map types = new HashMap(); - List typeConfigs = vrpProblem.configurationsAt("vehicleTypes.type"); - for(HierarchicalConfiguration typeConfig : typeConfigs){ - String typeId = typeConfig.getString("id"); - if(typeId == null) throw new IllegalStateException("typeId is missing."); - - String capacityString = typeConfig.getString("capacity"); - boolean capacityDimensionsExist = typeConfig.containsKey("capacity-dimensions.dimension(0)"); - if(capacityString == null && !capacityDimensionsExist){ - throw new IllegalStateException("capacity of type is not set. use 'capacity-dimensions'"); - } - if(capacityString != null && capacityDimensionsExist){ - throw new IllegalStateException("either use capacity or capacity-dimension, not both. prefer the use of 'capacity-dimensions' over 'capacity'."); - } - - VehicleTypeImpl.Builder typeBuilder; - if(capacityString != null){ - typeBuilder = VehicleTypeImpl.Builder.newInstance(typeId).addCapacityDimension(0, Integer.parseInt(capacityString)); - } - else { - typeBuilder = VehicleTypeImpl.Builder.newInstance(typeId); - List dimensionConfigs = typeConfig.configurationsAt("capacity-dimensions.dimension"); - for(HierarchicalConfiguration dimension : dimensionConfigs){ - Integer index = dimension.getInt("[@index]"); - Integer value = dimension.getInt(""); - typeBuilder.addCapacityDimension(index, value); - } - } - Double fix = typeConfig.getDouble("costs.fixed"); - Double timeC = typeConfig.getDouble("costs.time"); - Double distC = typeConfig.getDouble("costs.distance"); - - if(fix != null) typeBuilder.setFixedCost(fix); - if(timeC != null) typeBuilder.setCostPerTime(timeC); - if(distC != null) typeBuilder.setCostPerDistance(distC); - VehicleType type = typeBuilder.build(); - String id = type.getTypeId(); - types.put(id, type); - } - - //read vehicles - List vehicleConfigs = vrpProblem.configurationsAt("vehicles.vehicle"); - boolean doNotWarnAgain = false; - for(HierarchicalConfiguration vehicleConfig : vehicleConfigs){ - String vehicleId = vehicleConfig.getString("id"); - if(vehicleId == null) throw new IllegalStateException("vehicleId is missing."); - Builder builder = VehicleImpl.Builder.newInstance(vehicleId); - String typeId = vehicleConfig.getString("typeId"); - if(typeId == null) throw new IllegalStateException("typeId is missing."); - String vType = vehicleConfig.getString("[@type]"); - if(vType!=null){ - if(vType.equals("penalty")){ - typeId+="_penalty"; - } - } - VehicleType type = types.get(typeId); - if(type == null) throw new IllegalStateException("vehicleType with typeId " + typeId + " is missing."); - builder.setType(type); + //read vehicle-types + Map types = new HashMap(); + List typeConfigs = vrpProblem.configurationsAt("vehicleTypes.type"); + for (HierarchicalConfiguration typeConfig : typeConfigs) { + String typeId = typeConfig.getString("id"); + if (typeId == null) throw new IllegalStateException("typeId is missing."); + + String capacityString = typeConfig.getString("capacity"); + boolean capacityDimensionsExist = typeConfig.containsKey("capacity-dimensions.dimension(0)"); + if (capacityString == null && !capacityDimensionsExist) { + throw new IllegalStateException("capacity of type is not set. use 'capacity-dimensions'"); + } + if (capacityString != null && capacityDimensionsExist) { + throw new IllegalStateException("either use capacity or capacity-dimension, not both. prefer the use of 'capacity-dimensions' over 'capacity'."); + } + + VehicleTypeImpl.Builder typeBuilder; + if (capacityString != null) { + typeBuilder = VehicleTypeImpl.Builder.newInstance(typeId).addCapacityDimension(0, Integer.parseInt(capacityString)); + } else { + typeBuilder = VehicleTypeImpl.Builder.newInstance(typeId); + List dimensionConfigs = typeConfig.configurationsAt("capacity-dimensions.dimension"); + for (HierarchicalConfiguration dimension : dimensionConfigs) { + Integer index = dimension.getInt("[@index]"); + Integer value = dimension.getInt(""); + typeBuilder.addCapacityDimension(index, value); + } + } + Double fix = typeConfig.getDouble("costs.fixed"); + Double timeC = typeConfig.getDouble("costs.time"); + Double distC = typeConfig.getDouble("costs.distance"); + + if (fix != null) typeBuilder.setFixedCost(fix); + if (timeC != null) typeBuilder.setCostPerTime(timeC); + if (distC != null) typeBuilder.setCostPerDistance(distC); + VehicleType type = typeBuilder.build(); + String id = type.getTypeId(); + types.put(id, type); + } + + //read vehicles + List vehicleConfigs = vrpProblem.configurationsAt("vehicles.vehicle"); + boolean doNotWarnAgain = false; + for (HierarchicalConfiguration vehicleConfig : vehicleConfigs) { + String vehicleId = vehicleConfig.getString("id"); + if (vehicleId == null) throw new IllegalStateException("vehicleId is missing."); + Builder builder = VehicleImpl.Builder.newInstance(vehicleId); + String typeId = vehicleConfig.getString("typeId"); + if (typeId == null) throw new IllegalStateException("typeId is missing."); + String vType = vehicleConfig.getString("[@type]"); + if (vType != null) { + if (vType.equals("penalty")) { + typeId += "_penalty"; + } + } + VehicleType type = types.get(typeId); + if (type == null) throw new IllegalStateException("vehicleType with typeId " + typeId + " is missing."); + builder.setType(type); //read startlocation Location.Builder startLocationBuilder = Location.Builder.newInstance(); String locationId = vehicleConfig.getString("location.id"); - if(locationId == null) { - locationId = vehicleConfig.getString("startLocation.id"); - } + if (locationId == null) { + locationId = vehicleConfig.getString("startLocation.id"); + } startLocationBuilder.setId(locationId); - String coordX = vehicleConfig.getString("location.coord[@x]"); - String coordY = vehicleConfig.getString("location.coord[@y]"); - if(coordX == null || coordY == null) { - coordX = vehicleConfig.getString("startLocation.coord[@x]"); - coordY = vehicleConfig.getString("startLocation.coord[@y]"); - } - if(coordX == null || coordY == null) { - if(!doNotWarnAgain) { - logger.debug("location.coord is missing. will not warn you again."); - doNotWarnAgain = true; - } - } - else{ - Coordinate coordinate = Coordinate.newInstance(Double.parseDouble(coordX), Double.parseDouble(coordY)); + String coordX = vehicleConfig.getString("location.coord[@x]"); + String coordY = vehicleConfig.getString("location.coord[@y]"); + if (coordX == null || coordY == null) { + coordX = vehicleConfig.getString("startLocation.coord[@x]"); + coordY = vehicleConfig.getString("startLocation.coord[@y]"); + } + if (coordX == null || coordY == null) { + if (!doNotWarnAgain) { + logger.debug("location.coord is missing. will not warn you again."); + doNotWarnAgain = true; + } + } else { + Coordinate coordinate = Coordinate.newInstance(Double.parseDouble(coordX), Double.parseDouble(coordY)); startLocationBuilder.setCoordinate(coordinate); } String index = vehicleConfig.getString("startLocation.index"); - if(index == null) index = vehicleConfig.getString("location.index"); - if(index != null){ + if (index == null) index = vehicleConfig.getString("location.index"); + if (index != null) { startLocationBuilder.setIndex(Integer.parseInt(index)); } builder.setStartLocation(startLocationBuilder.build()); @@ -634,59 +631,57 @@ public class VrpXMLReader{ //read endlocation Location.Builder endLocationBuilder = Location.Builder.newInstance(); boolean hasEndLocation = false; - String endLocationId = vehicleConfig.getString("endLocation.id"); - if(endLocationId != null) { + String endLocationId = vehicleConfig.getString("endLocation.id"); + if (endLocationId != null) { hasEndLocation = true; endLocationBuilder.setId(endLocationId); } - String endCoordX = vehicleConfig.getString("endLocation.coord[@x]"); - String endCoordY = vehicleConfig.getString("endLocation.coord[@y]"); - if(endCoordX == null || endCoordY == null) { - if(!doNotWarnAgain) { - logger.debug("endLocation.coord is missing. will not warn you again."); - doNotWarnAgain = true; - } - } - else{ - Coordinate coordinate = Coordinate.newInstance(Double.parseDouble(endCoordX), Double.parseDouble(endCoordY)); + String endCoordX = vehicleConfig.getString("endLocation.coord[@x]"); + String endCoordY = vehicleConfig.getString("endLocation.coord[@y]"); + if (endCoordX == null || endCoordY == null) { + if (!doNotWarnAgain) { + logger.debug("endLocation.coord is missing. will not warn you again."); + doNotWarnAgain = true; + } + } else { + Coordinate coordinate = Coordinate.newInstance(Double.parseDouble(endCoordX), Double.parseDouble(endCoordY)); hasEndLocation = true; endLocationBuilder.setCoordinate(coordinate); - } - String endLocationIndex = vehicleConfig.getString("endLocation.index"); - if(endLocationIndex != null) { + } + String endLocationIndex = vehicleConfig.getString("endLocation.index"); + if (endLocationIndex != null) { hasEndLocation = true; endLocationBuilder.setIndex(Integer.parseInt(endLocationIndex)); } - if(hasEndLocation) builder.setEndLocation(endLocationBuilder.build()); - - //read timeSchedule - String start = vehicleConfig.getString("timeSchedule.start"); - String end = vehicleConfig.getString("timeSchedule.end"); - if(start != null) builder.setEarliestStart(Double.parseDouble(start)); - if(end != null) builder.setLatestArrival(Double.parseDouble(end)); + if (hasEndLocation) builder.setEndLocation(endLocationBuilder.build()); - //read return2depot + //read timeSchedule + String start = vehicleConfig.getString("timeSchedule.start"); + String end = vehicleConfig.getString("timeSchedule.end"); + if (start != null) builder.setEarliestStart(Double.parseDouble(start)); + if (end != null) builder.setLatestArrival(Double.parseDouble(end)); + + //read return2depot String returnToDepot = vehicleConfig.getString("returnToDepot"); - if(returnToDepot != null){ - builder.setReturnToDepot(vehicleConfig.getBoolean("returnToDepot")); - } + if (returnToDepot != null) { + builder.setReturnToDepot(vehicleConfig.getBoolean("returnToDepot")); + } //read skills String skillString = vehicleConfig.getString("skills"); - if(skillString != null){ + if (skillString != null) { String cleaned = skillString.replaceAll("\\s", ""); String[] skillTokens = cleaned.split("[,;]"); - for(String skill : skillTokens) builder.addSkill(skill.toLowerCase()); + for (String skill : skillTokens) builder.addSkill(skill.toLowerCase()); } //build vehicle - VehicleImpl vehicle = builder.build(); - vrpBuilder.addVehicle(vehicle); - vehicleMap.put(vehicleId, vehicle); - } + VehicleImpl vehicle = builder.build(); + vrpBuilder.addVehicle(vehicle); + vehicleMap.put(vehicleId, vehicle); + } + + } - } - - } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/io/VrpXMLWriter.java b/jsprit-core/src/main/java/jsprit/core/problem/io/VrpXMLWriter.java index 75d58aec..f06aa2a1 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/io/VrpXMLWriter.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/io/VrpXMLWriter.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.problem.io; @@ -46,340 +46,333 @@ import java.util.List; public class VrpXMLWriter { - - static class XMLConf extends XMLConfiguration { - - - /** - * - */ - private static final long serialVersionUID = 1L; - public Document createDoc() throws ConfigurationException{ - return createDocument(); - } - } - - private Logger log = LogManager.getLogger(VrpXMLWriter.class); - - private VehicleRoutingProblem vrp; - - private Collection solutions; - - public VrpXMLWriter(VehicleRoutingProblem vrp, Collection solutions) { - this.vrp = vrp; - this.solutions = solutions; - } - - public VrpXMLWriter(VehicleRoutingProblem vrp) { - this.vrp = vrp; - this.solutions = null; - } - - private static Logger logger = LogManager.getLogger(VrpXMLWriter.class); - - public void write(String filename){ - if(!filename.endsWith(".xml")) filename+=".xml"; - log.info("write vrp: " + filename); - XMLConf xmlConfig = new XMLConf(); - xmlConfig.setFileName(filename); - xmlConfig.setRootElementName("problem"); - xmlConfig.setAttributeSplittingDisabled(true); - xmlConfig.setDelimiterParsingDisabled(true); - - writeProblemType(xmlConfig); - writeVehiclesAndTheirTypes(xmlConfig); - - //might be sorted? - List jobs = new ArrayList(); - jobs.addAll(vrp.getJobs().values()); - for(VehicleRoute r : vrp.getInitialVehicleRoutes()){ - jobs.addAll(r.getTourActivities().getJobs()); - } - - writeServices(xmlConfig,jobs); - writeShipments(xmlConfig,jobs); - - writeInitialRoutes(xmlConfig); - writeSolutions(xmlConfig); - - - OutputFormat format = new OutputFormat(); - format.setIndenting(true); - format.setIndent(5); - - try { - Document document = xmlConfig.createDoc(); - - Element element = document.getDocumentElement(); - element.setAttribute("xmlns", "http://www.w3schools.com"); - element.setAttribute("xmlns:xsi","http://www.w3.org/2001/XMLSchema-instance"); - element.setAttribute("xsi:schemaLocation","http://www.w3schools.com vrp_xml_schema.xsd"); - - } catch (ConfigurationException e) { - logger.error(e); - e.printStackTrace(); - System.exit(1); - } - - try { - Writer out = new FileWriter(filename); - XMLSerializer serializer = new XMLSerializer(out, format); - serializer.serialize(xmlConfig.getDocument()); - out.close(); - } catch (IOException e) { - logger.error(e); - e.printStackTrace(); - System.exit(1); - } - - - } + static class XMLConf extends XMLConfiguration { - private void writeInitialRoutes(XMLConf xmlConfig) { - if(vrp.getInitialVehicleRoutes().isEmpty()) return; - String path = "initialRoutes.route"; - int routeCounter = 0; - for(VehicleRoute route : vrp.getInitialVehicleRoutes()){ - xmlConfig.setProperty(path + "(" + routeCounter + ").driverId", route.getDriver().getId()); - xmlConfig.setProperty(path + "(" + routeCounter + ").vehicleId", route.getVehicle().getId()); - xmlConfig.setProperty(path + "(" + routeCounter + ").start", route.getStart().getEndTime()); - int actCounter = 0; - for(TourActivity act : route.getTourActivities().getActivities()){ - xmlConfig.setProperty(path + "(" + routeCounter + ").act("+actCounter+")[@type]", act.getName()); - if(act instanceof JobActivity){ - Job job = ((JobActivity) act).getJob(); - if(job instanceof Service){ - xmlConfig.setProperty(path + "(" + routeCounter + ").act("+actCounter+").serviceId", job.getId()); - } - else if(job instanceof Shipment){ - xmlConfig.setProperty(path + "(" + routeCounter + ").act("+actCounter+").shipmentId", job.getId()); - } - else{ - throw new IllegalStateException("cannot write solution correctly since job-type is not know. make sure you use either service or shipment, or another writer"); - } - } - xmlConfig.setProperty(path + "(" + routeCounter + ").act("+actCounter+").arrTime", act.getArrTime()); - xmlConfig.setProperty(path + "(" + routeCounter + ").act("+actCounter+").endTime", act.getEndTime()); - actCounter++; - } - xmlConfig.setProperty(path + "(" + routeCounter + ").end", route.getEnd().getArrTime()); - routeCounter++; - } - } + /** + * + */ + private static final long serialVersionUID = 1L; - private void writeSolutions(XMLConf xmlConfig) { - if(solutions == null) return; - String solutionPath = "solutions.solution"; - int counter = 0; - for(VehicleRoutingProblemSolution solution : solutions){ - xmlConfig.setProperty(solutionPath + "(" + counter + ").cost", solution.getCost()); - int routeCounter = 0; - for(VehicleRoute route : solution.getRoutes()){ + public Document createDoc() throws ConfigurationException { + return createDocument(); + } + } + + private Logger log = LogManager.getLogger(VrpXMLWriter.class); + + private VehicleRoutingProblem vrp; + + private Collection solutions; + + public VrpXMLWriter(VehicleRoutingProblem vrp, Collection solutions) { + this.vrp = vrp; + this.solutions = solutions; + } + + public VrpXMLWriter(VehicleRoutingProblem vrp) { + this.vrp = vrp; + this.solutions = null; + } + + private static Logger logger = LogManager.getLogger(VrpXMLWriter.class); + + public void write(String filename) { + if (!filename.endsWith(".xml")) filename += ".xml"; + log.info("write vrp: " + filename); + XMLConf xmlConfig = new XMLConf(); + xmlConfig.setFileName(filename); + xmlConfig.setRootElementName("problem"); + xmlConfig.setAttributeSplittingDisabled(true); + xmlConfig.setDelimiterParsingDisabled(true); + + writeProblemType(xmlConfig); + writeVehiclesAndTheirTypes(xmlConfig); + + //might be sorted? + List jobs = new ArrayList(); + jobs.addAll(vrp.getJobs().values()); + for (VehicleRoute r : vrp.getInitialVehicleRoutes()) { + jobs.addAll(r.getTourActivities().getJobs()); + } + + writeServices(xmlConfig, jobs); + writeShipments(xmlConfig, jobs); + + writeInitialRoutes(xmlConfig); + writeSolutions(xmlConfig); + + + OutputFormat format = new OutputFormat(); + format.setIndenting(true); + format.setIndent(5); + + try { + Document document = xmlConfig.createDoc(); + + Element element = document.getDocumentElement(); + element.setAttribute("xmlns", "http://www.w3schools.com"); + element.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); + element.setAttribute("xsi:schemaLocation", "http://www.w3schools.com vrp_xml_schema.xsd"); + + } catch (ConfigurationException e) { + throw new RuntimeException(e); + } + + try { + Writer out = new FileWriter(filename); + XMLSerializer serializer = new XMLSerializer(out, format); + serializer.serialize(xmlConfig.getDocument()); + out.close(); + } catch (IOException e) { + throw new RuntimeException(e); + } + + + } + + private void writeInitialRoutes(XMLConf xmlConfig) { + if (vrp.getInitialVehicleRoutes().isEmpty()) return; + String path = "initialRoutes.route"; + int routeCounter = 0; + for (VehicleRoute route : vrp.getInitialVehicleRoutes()) { + xmlConfig.setProperty(path + "(" + routeCounter + ").driverId", route.getDriver().getId()); + xmlConfig.setProperty(path + "(" + routeCounter + ").vehicleId", route.getVehicle().getId()); + xmlConfig.setProperty(path + "(" + routeCounter + ").start", route.getStart().getEndTime()); + int actCounter = 0; + for (TourActivity act : route.getTourActivities().getActivities()) { + xmlConfig.setProperty(path + "(" + routeCounter + ").act(" + actCounter + ")[@type]", act.getName()); + if (act instanceof JobActivity) { + Job job = ((JobActivity) act).getJob(); + if (job instanceof Service) { + xmlConfig.setProperty(path + "(" + routeCounter + ").act(" + actCounter + ").serviceId", job.getId()); + } else if (job instanceof Shipment) { + xmlConfig.setProperty(path + "(" + routeCounter + ").act(" + actCounter + ").shipmentId", job.getId()); + } else { + throw new IllegalStateException("cannot write solution correctly since job-type is not know. make sure you use either service or shipment, or another writer"); + } + } + xmlConfig.setProperty(path + "(" + routeCounter + ").act(" + actCounter + ").arrTime", act.getArrTime()); + xmlConfig.setProperty(path + "(" + routeCounter + ").act(" + actCounter + ").endTime", act.getEndTime()); + actCounter++; + } + xmlConfig.setProperty(path + "(" + routeCounter + ").end", route.getEnd().getArrTime()); + routeCounter++; + } + + } + + private void writeSolutions(XMLConf xmlConfig) { + if (solutions == null) return; + String solutionPath = "solutions.solution"; + int counter = 0; + for (VehicleRoutingProblemSolution solution : solutions) { + xmlConfig.setProperty(solutionPath + "(" + counter + ").cost", solution.getCost()); + int routeCounter = 0; + for (VehicleRoute route : solution.getRoutes()) { // xmlConfig.setProperty(solutionPath + "(" + counter + ").routes.route(" + routeCounter + ").cost", route.getCost()); - xmlConfig.setProperty(solutionPath + "(" + counter + ").routes.route(" + routeCounter + ").driverId", route.getDriver().getId()); - xmlConfig.setProperty(solutionPath + "(" + counter + ").routes.route(" + routeCounter + ").vehicleId", route.getVehicle().getId()); - xmlConfig.setProperty(solutionPath + "(" + counter + ").routes.route(" + routeCounter + ").start", route.getStart().getEndTime()); - int actCounter = 0; - for(TourActivity act : route.getTourActivities().getActivities()){ - xmlConfig.setProperty(solutionPath + "(" + counter + ").routes.route(" + routeCounter + ").act("+actCounter+")[@type]", act.getName()); - if(act instanceof JobActivity){ - Job job = ((JobActivity) act).getJob(); - if(job instanceof Service){ - xmlConfig.setProperty(solutionPath + "(" + counter + ").routes.route(" + routeCounter + ").act("+actCounter+").serviceId", job.getId()); - } - else if(job instanceof Shipment){ - xmlConfig.setProperty(solutionPath + "(" + counter + ").routes.route(" + routeCounter + ").act("+actCounter+").shipmentId", job.getId()); - } - else{ - throw new IllegalStateException("cannot write solution correctly since job-type is not know. make sure you use either service or shipment, or another writer"); - } - } - xmlConfig.setProperty(solutionPath + "(" + counter + ").routes.route(" + routeCounter + ").act("+actCounter+").arrTime", act.getArrTime()); - xmlConfig.setProperty(solutionPath + "(" + counter + ").routes.route(" + routeCounter + ").act("+actCounter+").endTime", act.getEndTime()); - actCounter++; - } - xmlConfig.setProperty(solutionPath + "(" + counter + ").routes.route(" + routeCounter + ").end", route.getEnd().getArrTime()); - routeCounter++; - } + xmlConfig.setProperty(solutionPath + "(" + counter + ").routes.route(" + routeCounter + ").driverId", route.getDriver().getId()); + xmlConfig.setProperty(solutionPath + "(" + counter + ").routes.route(" + routeCounter + ").vehicleId", route.getVehicle().getId()); + xmlConfig.setProperty(solutionPath + "(" + counter + ").routes.route(" + routeCounter + ").start", route.getStart().getEndTime()); + int actCounter = 0; + for (TourActivity act : route.getTourActivities().getActivities()) { + xmlConfig.setProperty(solutionPath + "(" + counter + ").routes.route(" + routeCounter + ").act(" + actCounter + ")[@type]", act.getName()); + if (act instanceof JobActivity) { + Job job = ((JobActivity) act).getJob(); + if (job instanceof Service) { + xmlConfig.setProperty(solutionPath + "(" + counter + ").routes.route(" + routeCounter + ").act(" + actCounter + ").serviceId", job.getId()); + } else if (job instanceof Shipment) { + xmlConfig.setProperty(solutionPath + "(" + counter + ").routes.route(" + routeCounter + ").act(" + actCounter + ").shipmentId", job.getId()); + } else { + throw new IllegalStateException("cannot write solution correctly since job-type is not know. make sure you use either service or shipment, or another writer"); + } + } + xmlConfig.setProperty(solutionPath + "(" + counter + ").routes.route(" + routeCounter + ").act(" + actCounter + ").arrTime", act.getArrTime()); + xmlConfig.setProperty(solutionPath + "(" + counter + ").routes.route(" + routeCounter + ").act(" + actCounter + ").endTime", act.getEndTime()); + actCounter++; + } + xmlConfig.setProperty(solutionPath + "(" + counter + ").routes.route(" + routeCounter + ").end", route.getEnd().getArrTime()); + routeCounter++; + } int unassignedJobCounter = 0; - for(Job unassignedJob : solution.getUnassignedJobs()){ + for (Job unassignedJob : solution.getUnassignedJobs()) { xmlConfig.setProperty(solutionPath + "(" + counter + ").unassignedJobs.job(" + unassignedJobCounter + ")[@id]", unassignedJob.getId()); unassignedJobCounter++; } - counter++; - } - } + counter++; + } + } - private void writeServices(XMLConf xmlConfig, List jobs) { - String shipmentPathString = "services.service"; - int counter = 0; - for(Job j : jobs){ - if(!(j instanceof Service)) continue; - Service service = (Service) j; - xmlConfig.setProperty(shipmentPathString + "("+counter+")[@id]", service.getId()); - xmlConfig.setProperty(shipmentPathString + "("+counter+")[@type]", service.getType()); - if(service.getLocation().getId() != null) xmlConfig.setProperty(shipmentPathString + "("+counter+").location.id", service.getLocation().getId()); - if(service.getLocation().getCoordinate() != null) { - xmlConfig.setProperty(shipmentPathString + "(" + counter + ").location.coord[@x]", service.getLocation().getCoordinate().getX()); - xmlConfig.setProperty(shipmentPathString + "("+counter+").location.coord[@y]", service.getLocation().getCoordinate().getY()); - } - if(service.getLocation().getIndex() != Location.NO_INDEX){ + private void writeServices(XMLConf xmlConfig, List jobs) { + String shipmentPathString = "services.service"; + int counter = 0; + for (Job j : jobs) { + if (!(j instanceof Service)) continue; + Service service = (Service) j; + xmlConfig.setProperty(shipmentPathString + "(" + counter + ")[@id]", service.getId()); + xmlConfig.setProperty(shipmentPathString + "(" + counter + ")[@type]", service.getType()); + if (service.getLocation().getId() != null) + xmlConfig.setProperty(shipmentPathString + "(" + counter + ").location.id", service.getLocation().getId()); + if (service.getLocation().getCoordinate() != null) { + xmlConfig.setProperty(shipmentPathString + "(" + counter + ").location.coord[@x]", service.getLocation().getCoordinate().getX()); + xmlConfig.setProperty(shipmentPathString + "(" + counter + ").location.coord[@y]", service.getLocation().getCoordinate().getY()); + } + if (service.getLocation().getIndex() != Location.NO_INDEX) { xmlConfig.setProperty(shipmentPathString + "(" + counter + ").location.index", service.getLocation().getIndex()); } - for(int i=0;i jobs) { - String shipmentPathString = "shipments.shipment"; - int counter = 0; - for(Job j : jobs){ - if(!(j instanceof Shipment)) continue; - Shipment shipment = (Shipment) j; - xmlConfig.setProperty(shipmentPathString + "("+counter+")[@id]", shipment.getId()); + counter++; + } + } + + private void writeShipments(XMLConf xmlConfig, List jobs) { + String shipmentPathString = "shipments.shipment"; + int counter = 0; + for (Job j : jobs) { + if (!(j instanceof Shipment)) continue; + Shipment shipment = (Shipment) j; + xmlConfig.setProperty(shipmentPathString + "(" + counter + ")[@id]", shipment.getId()); // xmlConfig.setProperty(shipmentPathString + "("+counter+")[@type]", service.getType()); - if(shipment.getPickupLocation().getId() != null) xmlConfig.setProperty(shipmentPathString + "("+counter+").pickup.location.id", shipment.getPickupLocation().getId()); - if(shipment.getPickupLocation().getCoordinate() != null) { - xmlConfig.setProperty(shipmentPathString + "("+counter+").pickup.location.coord[@x]", shipment.getPickupLocation().getCoordinate().getX()); - xmlConfig.setProperty(shipmentPathString + "("+counter+").pickup.location.coord[@y]", shipment.getPickupLocation().getCoordinate().getY()); - } - if(shipment.getPickupLocation().getIndex() != Location.NO_INDEX){ + if (shipment.getPickupLocation().getId() != null) + xmlConfig.setProperty(shipmentPathString + "(" + counter + ").pickup.location.id", shipment.getPickupLocation().getId()); + if (shipment.getPickupLocation().getCoordinate() != null) { + xmlConfig.setProperty(shipmentPathString + "(" + counter + ").pickup.location.coord[@x]", shipment.getPickupLocation().getCoordinate().getX()); + xmlConfig.setProperty(shipmentPathString + "(" + counter + ").pickup.location.coord[@y]", shipment.getPickupLocation().getCoordinate().getY()); + } + if (shipment.getPickupLocation().getIndex() != Location.NO_INDEX) { xmlConfig.setProperty(shipmentPathString + "(" + counter + ").pickup.location.index", shipment.getPickupLocation().getIndex()); } - - xmlConfig.setProperty(shipmentPathString + "("+counter+").pickup.duration", shipment.getPickupServiceTime()); - xmlConfig.setProperty(shipmentPathString + "("+counter+").pickup.timeWindows.timeWindow(0).start", shipment.getPickupTimeWindow().getStart()); - xmlConfig.setProperty(shipmentPathString + "("+counter+").pickup.timeWindows.timeWindow(0).end", shipment.getPickupTimeWindow().getEnd()); - - - if(shipment.getDeliveryLocation().getId() != null) xmlConfig.setProperty(shipmentPathString + "("+counter+").delivery.location.id", shipment.getDeliveryLocation().getId()); - if(shipment.getDeliveryLocation().getCoordinate() != null) { - xmlConfig.setProperty(shipmentPathString + "(" + counter + ").delivery.location.coord[@x]", shipment.getDeliveryLocation().getCoordinate().getX()); - xmlConfig.setProperty(shipmentPathString + "(" + counter + ").delivery.location.coord[@y]", shipment.getDeliveryLocation().getCoordinate().getY()); - } - if(shipment.getDeliveryLocation().getIndex() != Location.NO_INDEX){ - xmlConfig.setProperty(shipmentPathString + "("+counter+").delivery.location.index", shipment.getDeliveryLocation().getIndex()); + + xmlConfig.setProperty(shipmentPathString + "(" + counter + ").pickup.duration", shipment.getPickupServiceTime()); + xmlConfig.setProperty(shipmentPathString + "(" + counter + ").pickup.timeWindows.timeWindow(0).start", shipment.getPickupTimeWindow().getStart()); + xmlConfig.setProperty(shipmentPathString + "(" + counter + ").pickup.timeWindows.timeWindow(0).end", shipment.getPickupTimeWindow().getEnd()); + + + if (shipment.getDeliveryLocation().getId() != null) + xmlConfig.setProperty(shipmentPathString + "(" + counter + ").delivery.location.id", shipment.getDeliveryLocation().getId()); + if (shipment.getDeliveryLocation().getCoordinate() != null) { + xmlConfig.setProperty(shipmentPathString + "(" + counter + ").delivery.location.coord[@x]", shipment.getDeliveryLocation().getCoordinate().getX()); + xmlConfig.setProperty(shipmentPathString + "(" + counter + ").delivery.location.coord[@y]", shipment.getDeliveryLocation().getCoordinate().getY()); + } + if (shipment.getDeliveryLocation().getIndex() != Location.NO_INDEX) { + xmlConfig.setProperty(shipmentPathString + "(" + counter + ").delivery.location.index", shipment.getDeliveryLocation().getIndex()); + } + + xmlConfig.setProperty(shipmentPathString + "(" + counter + ").delivery.duration", shipment.getDeliveryServiceTime()); + xmlConfig.setProperty(shipmentPathString + "(" + counter + ").delivery.timeWindows.timeWindow(0).start", shipment.getDeliveryTimeWindow().getStart()); + xmlConfig.setProperty(shipmentPathString + "(" + counter + ").delivery.timeWindows.timeWindow(0).end", shipment.getDeliveryTimeWindow().getEnd()); + + for (int i = 0; i < shipment.getSize().getNuOfDimensions(); i++) { + xmlConfig.setProperty(shipmentPathString + "(" + counter + ").capacity-dimensions.dimension(" + i + ")[@index]", i); + xmlConfig.setProperty(shipmentPathString + "(" + counter + ").capacity-dimensions.dimension(" + i + ")", shipment.getSize().get(i)); } - - xmlConfig.setProperty(shipmentPathString + "("+counter+").delivery.duration", shipment.getDeliveryServiceTime()); - xmlConfig.setProperty(shipmentPathString + "("+counter+").delivery.timeWindows.timeWindow(0).start", shipment.getDeliveryTimeWindow().getStart()); - xmlConfig.setProperty(shipmentPathString + "("+counter+").delivery.timeWindows.timeWindow(0).end", shipment.getDeliveryTimeWindow().getEnd()); - - for(int i=0;i. + ******************************************************************************/ +package jsprit.core.problem.job; + + +import jsprit.core.problem.Capacity; +import jsprit.core.problem.Skills; + +/** + * Pickup extends Service and is intended to model a Service where smth is LOADED (i.e. picked up) to a transport unit. + * + * @author schroeder + */ +public class Break extends Service { + + public static class Builder extends Service.Builder { + + /** + * Returns a new instance of builder that builds a pickup. + * + * @param id the id of the pickup + * @return the builder + */ + public static Builder newInstance(String id) { + return new Builder(id); + } + + private boolean variableLocation = true; + + Builder(String id) { + super(id); + } + + /** + * Builds Pickup. + *

+ *

Pickup type is "pickup" + * + * @return pickup + * @throws IllegalStateException if neither locationId nor coordinate has been set + */ + public Break build() { + if (location != null) { + variableLocation = false; + } + this.setType("break"); + super.capacity = Capacity.Builder.newInstance().build(); + super.skills = Skills.Builder.newInstance().build(); + return new Break(this); + } + + } + + private boolean variableLocation = true; + + Break(Builder builder) { + super(builder); + this.variableLocation = builder.variableLocation; + } + + public boolean hasVariableLocation() { + return variableLocation; + } + +} diff --git a/jsprit-core/src/main/java/jsprit/core/problem/job/Delivery.java b/jsprit-core/src/main/java/jsprit/core/problem/job/Delivery.java index e98b043b..8a95f69a 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/job/Delivery.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/job/Delivery.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.problem.job; @@ -19,47 +19,46 @@ package jsprit.core.problem.job; /** * Delivery extends Service and is intended to model a Service where smth is UNLOADED (i.e. delivered) from a transport unit. - * - * @author schroeder * + * @author schroeder */ -public class Delivery extends Service{ - - public static class Builder extends Service.Builder { +public class Delivery extends Service { - /** - * Returns a new instance of builder that builds a delivery. - * - * @param id the id of the delivery - * @return the builder - */ - public static Builder newInstance(String id){ - return new Builder(id); - } + public static class Builder extends Service.Builder { - Builder(String id) { - super(id); - } - - /** - * Builds Delivery. - * - * @return delivery - * @throws IllegalStateException if neither locationId nor coord is set - */ - public Delivery build(){ - if(location == null) throw new IllegalStateException("location is missing"); - this.setType("delivery"); - super.capacity = super.capacityBuilder.build(); + /** + * Returns a new instance of builder that builds a delivery. + * + * @param id the id of the delivery + * @return the builder + */ + public static Builder newInstance(String id) { + return new Builder(id); + } + + Builder(String id) { + super(id); + } + + /** + * Builds Delivery. + * + * @return delivery + * @throws IllegalStateException if neither locationId nor coord is set + */ + public Delivery build() { + if (location == null) throw new IllegalStateException("location is missing"); + this.setType("delivery"); + super.capacity = super.capacityBuilder.build(); super.skills = super.skillBuilder.build(); - return new Delivery(this); - } - - } + return new Delivery(this); + } - Delivery(Builder builder) { - super(builder); - - } + } + + Delivery(Builder builder) { + super(builder); + + } } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/job/Job.java b/jsprit-core/src/main/java/jsprit/core/problem/job/Job.java index 19302f82..cdd57702 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/job/Job.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/job/Job.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.problem.job; @@ -24,25 +24,24 @@ import jsprit.core.problem.Skills; /** * Basic interface for all jobs. - * - * @author schroeder * + * @author schroeder */ public interface Job extends HasId, HasIndex { - /** - * Returns the unique identifier (id) of a job. - * - * @return id - */ - public String getId(); + /** + * Returns the unique identifier (id) of a job. + * + * @return id + */ + public String getId(); - /** - * Returns size, i.e. capacity-demand, of this job which can consist of an arbitrary number of capacity dimensions. - * - * @return Capacity - */ - public Capacity getSize(); + /** + * Returns size, i.e. capacity-demand, of this job which can consist of an arbitrary number of capacity dimensions. + * + * @return Capacity + */ + public Capacity getSize(); public Skills getRequiredSkills(); diff --git a/jsprit-core/src/main/java/jsprit/core/problem/job/Pickup.java b/jsprit-core/src/main/java/jsprit/core/problem/job/Pickup.java index 862a1f7d..ce3e05ff 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/job/Pickup.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/job/Pickup.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.problem.job; @@ -19,48 +19,47 @@ package jsprit.core.problem.job; /** * Pickup extends Service and is intended to model a Service where smth is LOADED (i.e. picked up) to a transport unit. - * - * @author schroeder * + * @author schroeder */ public class Pickup extends Service { - public static class Builder extends Service.Builder { - - /** - * Returns a new instance of builder that builds a pickup. - * - * @param id the id of the pickup - * @return the builder - */ - public static Builder newInstance(String id){ - return new Builder(id); - } + public static class Builder extends Service.Builder { - Builder(String id) { - super(id); - } - - /** - * Builds Pickup. - * - *

Pickup type is "pickup" - * - * @return pickup - * @throws IllegalStateException if neither locationId nor coordinate has been set - */ - public Pickup build(){ - if(location == null) throw new IllegalStateException("location is missing"); - this.setType("pickup"); - super.capacity = super.capacityBuilder.build(); + /** + * Returns a new instance of builder that builds a pickup. + * + * @param id the id of the pickup + * @return the builder + */ + public static Builder newInstance(String id) { + return new Builder(id); + } + + Builder(String id) { + super(id); + } + + /** + * Builds Pickup. + *

+ *

Pickup type is "pickup" + * + * @return pickup + * @throws IllegalStateException if neither locationId nor coordinate has been set + */ + public Pickup build() { + if (location == null) throw new IllegalStateException("location is missing"); + this.setType("pickup"); + super.capacity = super.capacityBuilder.build(); super.skills = super.skillBuilder.build(); - return new Pickup(this); - } - - } + return new Pickup(this); + } + + } + + Pickup(Builder builder) { + super(builder); + } - Pickup(Builder builder) { - super(builder); - } - } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/job/Service.java b/jsprit-core/src/main/java/jsprit/core/problem/job/Service.java index 32851f86..b28a6a24 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/job/Service.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/job/Service.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.problem.job; @@ -29,55 +29,50 @@ import java.util.Collection; /** * Service implementation of a job. - * + *

*

A service distinguishes itself from a shipment such that it has only one location. Thus a service * is a single point in space (where a service-activity occurs). - * + *

*

Note that two services are equal if they have the same id. - * - * @author schroeder * + * @author schroeder */ public class Service extends AbstractJob { - - /** - * Builder that builds a service. - * - * @author schroeder - * - */ - public static class Builder { - + * Builder that builds a service. + * + * @author schroeder + */ + public static class Builder { /** - * Returns a new instance of builder that builds a service. - * - * @param id the id of the service - * @return the builder - */ - public static Builder newInstance(String id){ - return new Builder(id); - } - - private String id; - - protected String locationId; - - private String type = "service"; - - protected Coordinate coord; - - protected double serviceTime; - - protected TimeWindow timeWindow = TimeWindow.newInstance(0.0, Double.MAX_VALUE); - - protected Capacity.Builder capacityBuilder = Capacity.Builder.newInstance(); - - protected Capacity capacity; + * Returns a new instance of builder that builds a service. + * + * @param id the id of the service + * @return the builder + */ + public static Builder newInstance(String id) { + return new Builder(id); + } + + private String id; + + protected String locationId; + + private String type = "service"; + + protected Coordinate coord; + + protected double serviceTime; + + protected TimeWindow timeWindow = TimeWindow.newInstance(0.0, Double.MAX_VALUE); + + protected Capacity.Builder capacityBuilder = Capacity.Builder.newInstance(); + + protected Capacity capacity; protected Skills.Builder skillBuilder = Skills.Builder.newInstance(); @@ -87,7 +82,7 @@ public class Service extends AbstractJob { protected Location location; - protected TimeWindows timeWindows = new TimeWindowsImpl(); + protected TimeWindows timeWindows = new TimeWindowsImpl(); private boolean twAdded = false; @@ -96,19 +91,19 @@ public class Service extends AbstractJob { timeWindows = new TimeWindowsImpl(); ((TimeWindowsImpl)timeWindows).add(timeWindow); } - - /** - * Protected method to set the type-name of the service. - * - *

Currently there are {@link Service}, {@link Pickup} and {@link Delivery}. - * - * @param name the name of service - * @return the builder - */ - protected Builder setType(String name){ - this.type = name; - return this; - } + + /** + * Protected method to set the type-name of the service. + *

+ *

Currently there are {@link Service}, {@link Pickup} and {@link Delivery}. + * + * @param name the name of service + * @return the builder + */ + protected Builder setType(String name) { + this.type = name; + return this; + } /** * Sets location @@ -116,123 +111,125 @@ public class Service extends AbstractJob { * @param location location * @return builder */ - public Builder setLocation(Location location){ + public Builder setLocation(Location location) { this.location = location; return this; } - public Builder setTimeWindows(TimeWindows timeWindows){ - this.timeWindows = timeWindows; - return this; - } + /** + * Sets the serviceTime of this service. + *

+ *

It is understood as time that a service or its implied activity takes at the service-location, for instance + * to unload goods. + * + * @param serviceTime the service time / duration of service to be set + * @return builder + * @throws IllegalArgumentException if serviceTime < 0 + */ + public Builder setServiceTime(double serviceTime) { + if (serviceTime < 0) + throw new IllegalArgumentException("serviceTime must be greater than or equal to zero"); + this.serviceTime = serviceTime; + return this; + } - /** - * Sets the serviceTime of this service. - * - *

It is understood as time that a service or its implied activity takes at the service-location, for instance - * to unload goods. - * - * @param serviceTime the service time / duration of service to be set - * @return builder - * @throws IllegalArgumentException if serviceTime < 0 - */ - public Builder setServiceTime(double serviceTime){ - if(serviceTime < 0) throw new IllegalArgumentException("serviceTime must be greater than or equal to zero"); - this.serviceTime = serviceTime; - return this; - } - - /** - * Adds capacity dimension. - * - * @param dimensionIndex the dimension index of the capacity value - * @param dimensionValue the capacity value - * @return the builder - * @throws IllegalArgumentException if dimensionValue < 0 - */ - public Builder addSizeDimension(int dimensionIndex, int dimensionValue){ - if(dimensionValue<0) throw new IllegalArgumentException("capacity value cannot be negative"); - capacityBuilder.addDimension(dimensionIndex, dimensionValue); - return this; - } - - /** - * Sets the time-window of this service. - * - *

The time-window indicates the time period a service/activity/operation is allowed to start. - * - * @param tw the time-window to be set - * @return builder - * @throws IllegalArgumentException if timeWindow is null - */ - public Builder setTimeWindow(TimeWindow tw){ - if(tw == null) throw new IllegalArgumentException("time-window arg must not be null"); - this.timeWindow = tw; - this.timeWindows = new TimeWindowsImpl(); - ((TimeWindowsImpl) timeWindows).add(tw); - return this; - } + public Builder setTimeWindows(TimeWindows timeWindows){ + this.timeWindows = timeWindows; + return this; + } - public Builder addTimeWindow(TimeWindow timeWindow) { - if(timeWindow == null) throw new IllegalArgumentException("time-window arg must not be null"); - if(!twAdded){ - timeWindows = new TimeWindowsImpl(); - twAdded = true; - } - for(TimeWindow tw : ((TimeWindowsImpl)timeWindows).getTimeWindows()){ - if(timeWindow.getStart() > tw.getStart() && timeWindow.getStart() < tw.getEnd()){ - throw new IllegalStateException("time-windows cannot overlap each other. overlap: " + tw + ", " + timeWindow); - } - if(timeWindow.getEnd() > tw.getStart() && timeWindow.getEnd() < tw.getEnd()){ - throw new IllegalStateException("time-windows cannot overlap each other. overlap: " + tw + ", " + timeWindow); - } - } - ((TimeWindowsImpl) timeWindows).add(timeWindow); - return this; - } + /** + * Adds capacity dimension. + * + * @param dimensionIndex the dimension index of the capacity value + * @param dimensionValue the capacity value + * @return the builder + * @throws IllegalArgumentException if dimensionValue < 0 + */ + public Builder addSizeDimension(int dimensionIndex, int dimensionValue) { + if (dimensionValue < 0) throw new IllegalArgumentException("capacity value cannot be negative"); + capacityBuilder.addDimension(dimensionIndex, dimensionValue); + return this; + } - public Builder addTimeWindow(double earliest, double latest) { - return addTimeWindow(TimeWindow.newInstance(earliest, latest)); - } - - /** - * Builds the service. - * - * @return {@link Service} - * @throws IllegalStateException if neither locationId nor coordinate is set. - */ - public Service build(){ - if(location == null) throw new IllegalStateException("location is missing"); - this.setType("service"); - capacity = capacityBuilder.build(); + public Builder setTimeWindow(TimeWindow tw){ + if(tw == null) throw new IllegalArgumentException("time-window arg must not be null"); + this.timeWindow = tw; + this.timeWindows = new TimeWindowsImpl(); + ((TimeWindowsImpl) timeWindows).add(tw); + return this; + } + + public Builder addTimeWindow(TimeWindow timeWindow) { + if(timeWindow == null) throw new IllegalArgumentException("time-window arg must not be null"); + if(!twAdded){ + timeWindows = new TimeWindowsImpl(); + twAdded = true; + } + for(TimeWindow tw : ((TimeWindowsImpl)timeWindows).getTimeWindows()){ + if(timeWindow.getStart() > tw.getStart() && timeWindow.getStart() < tw.getEnd()){ + throw new IllegalStateException("time-windows cannot overlap each other. overlap: " + tw + ", " + timeWindow); + } + if(timeWindow.getEnd() > tw.getStart() && timeWindow.getEnd() < tw.getEnd()){ + throw new IllegalStateException("time-windows cannot overlap each other. overlap: " + tw + ", " + timeWindow); + } + } + ((TimeWindowsImpl) timeWindows).add(timeWindow); + return this; + } + + public Builder addTimeWindow(double earliest, double latest) { + return addTimeWindow(TimeWindow.newInstance(earliest, latest)); + } + + /** + * Builds the service. + * + * @return {@link Service} + * @throws IllegalStateException if neither locationId nor coordinate is set. + */ + public T build() { + if (location == null) throw new IllegalStateException("location is missing"); + this.setType("service"); + capacity = capacityBuilder.build(); skills = skillBuilder.build(); - return new Service(this); - } + return (T) new Service(this); + } - public Builder addRequiredSkill(String skill) { + public Builder addRequiredSkill(String skill) { skillBuilder.addSkill(skill); return this; } - public Builder setName(String name) { + public Builder setName(String name) { this.name = name; return this; } + public Builder addAllRequiredSkills(Skills skills){ + for(String s : skills.values()){ + skillBuilder.addSkill(s); + } + return this; + } + public Builder addAllSizeDimensions(Capacity size){ + for(int i=0;iString is built as follows: [attr1=val1][attr2=val2]... - */ - @Override - public String toString() { - return "[id=" + id + "][name="+name+"][type="+type+"][location=" + location + "][capacity=" + size + "][serviceTime=" + serviceTime + "][timeWindow=" + timeWindow + "]"; - } + /** + * @return the name + */ + public String getType() { + return type; + } + + /** + * Returns a string with the service's attributes. + *

+ *

String is built as follows: [attr1=val1][attr2=val2]... + */ + @Override + public String toString() { + return "[id=" + id + "][name=" + name + "][type=" + type + "][location=" + location + "][capacity=" + size + "][serviceTime=" + serviceTime + "][timeWindow=" + timeWindow + "]"; + } - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((id == null) ? 0 : id.hashCode()); - return result; - } + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((id == null) ? 0 : id.hashCode()); + return result; + } - /** - * Two services are equal if they have the same id. - * - */ - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - Service other = (Service) obj; - if (id == null) { - if (other.id != null) - return false; - } else if (!id.equals(other.id)) - return false; - return true; - } + /** + * Two services are equal if they have the same id. + */ + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Service other = (Service) obj; + if (id == null) { + if (other.id != null) + return false; + } else if (!id.equals(other.id)) + return false; + return true; + } - @Override - public Capacity getSize() { - return size; - } + @Override + public Capacity getSize() { + return size; + } @Override public Skills getRequiredSkills() { diff --git a/jsprit-core/src/main/java/jsprit/core/problem/job/Shipment.java b/jsprit-core/src/main/java/jsprit/core/problem/job/Shipment.java index 6a826ffc..da877166 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/job/Shipment.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/job/Shipment.java @@ -25,46 +25,43 @@ import jsprit.core.problem.solution.route.activity.TimeWindow; /** * Shipment is an implementation of Job and consists of a pickup and a delivery of something. - * - *

It distinguishes itself from {@link Service} as two locations are involved a pickup where usually + *

+ *

It distinguishes itself from {@link Service} as two locations are involved a pickup where usually * something is loaded to the transport unit and a delivery where something is unloaded. - * + *

*

By default serviceTimes of both pickup and delivery is 0.0 and timeWindows of both is [0.0, Double.MAX_VALUE], - * + *

*

A shipment can be built with a builder. You can get an instance of the builder by coding Shipment.Builder.newInstance(...). - * This way you can specify the shipment. Once you build the shipment, it is immutable, i.e. fields/attributes cannot be changed anymore and + * This way you can specify the shipment. Once you build the shipment, it is immutable, i.e. fields/attributes cannot be changed anymore and * you can only 'get' the specified values. - * + *

*

Note that two shipments are equal if they have the same id. - * - * @author schroeder * + * @author schroeder */ -public class Shipment extends AbstractJob{ - +public class Shipment extends AbstractJob { /** - * Builder that builds the shipment. - * - * @author schroeder - * - */ - public static class Builder { - - private String id; + * Builder that builds the shipment. + * + * @author schroeder + */ + public static class Builder { - private double pickupServiceTime = 0.0; + private String id; - private double deliveryServiceTime = 0.0; + private double pickupServiceTime = 0.0; - private TimeWindow deliveryTimeWindow = TimeWindow.newInstance(0.0, Double.MAX_VALUE); + private double deliveryServiceTime = 0.0; - private TimeWindow pickupTimeWindow = TimeWindow.newInstance(0.0, Double.MAX_VALUE); - - private Capacity.Builder capacityBuilder = Capacity.Builder.newInstance(); - - private Capacity capacity; + private TimeWindow deliveryTimeWindow = TimeWindow.newInstance(0.0, Double.MAX_VALUE); + + private TimeWindow pickupTimeWindow = TimeWindow.newInstance(0.0, Double.MAX_VALUE); + + private Capacity.Builder capacityBuilder = Capacity.Builder.newInstance(); + + private Capacity capacity; private Skills.Builder skillBuilder = Skills.Builder.newInstance(); @@ -77,61 +74,61 @@ public class Shipment extends AbstractJob{ private Location deliveryLocation_; /** - * Returns new instance of this builder. - * - * @param id the id of the shipment which must be a unique identifier among all jobs - * @return the builder - */ - public static Builder newInstance(String id){ - return new Builder(id); - } - - Builder(String id){ - if(id == null) throw new IllegalArgumentException("id must not be null"); - this.id = id; - } + * Returns new instance of this builder. + * + * @param id the id of the shipment which must be a unique identifier among all jobs + * @return the builder + */ + public static Builder newInstance(String id) { + return new Builder(id); + } - /** + Builder(String id) { + if (id == null) throw new IllegalArgumentException("id must not be null"); + this.id = id; + } + + /** * Sets pickup location. * * @param pickupLocation pickup location * @return builder */ - public Builder setPickupLocation(Location pickupLocation){ + public Builder setPickupLocation(Location pickupLocation) { this.pickupLocation_ = pickupLocation; return this; } - /** - * Sets pickupServiceTime. - * - *

ServiceTime is intended to be the time the implied activity takes at the pickup-location. - * - * @param serviceTime the service time / duration the pickup of the associated shipment takes - * @return builder - * @throws IllegalArgumentException if servicTime < 0.0 - */ - public Builder setPickupServiceTime(double serviceTime){ - if(serviceTime < 0.0) throw new IllegalArgumentException("serviceTime must not be < 0.0"); - this.pickupServiceTime = serviceTime; - return this; - } - - /** - * Sets the timeWindow for the pickup, i.e. the time-period in which a pickup operation is - * allowed to START. - * - *

By default timeWindow is [0.0, Double.MAX_VALUE} - * - * @param timeWindow the time window within the pickup operation/activity can START - * @return builder - * @throws IllegalArgumentException if timeWindow is null - */ - public Builder setPickupTimeWindow(TimeWindow timeWindow){ - if(timeWindow == null) throw new IllegalArgumentException("timeWindow cannot be null"); - this.pickupTimeWindow = timeWindow; - return this; - } + /** + * Sets pickupServiceTime. + *

+ *

ServiceTime is intended to be the time the implied activity takes at the pickup-location. + * + * @param serviceTime the service time / duration the pickup of the associated shipment takes + * @return builder + * @throws IllegalArgumentException if servicTime < 0.0 + */ + public Builder setPickupServiceTime(double serviceTime) { + if (serviceTime < 0.0) throw new IllegalArgumentException("serviceTime must not be < 0.0"); + this.pickupServiceTime = serviceTime; + return this; + } + + /** + * Sets the timeWindow for the pickup, i.e. the time-period in which a pickup operation is + * allowed to START. + *

+ *

By default timeWindow is [0.0, Double.MAX_VALUE} + * + * @param timeWindow the time window within the pickup operation/activity can START + * @return builder + * @throws IllegalArgumentException if timeWindow is null + */ + public Builder setPickupTimeWindow(TimeWindow timeWindow) { + if (timeWindow == null) throw new IllegalArgumentException("timeWindow cannot be null"); + this.pickupTimeWindow = timeWindow; + return this; + } /** * Sets delivery location. @@ -139,71 +136,71 @@ public class Shipment extends AbstractJob{ * @param deliveryLocation delivery location * @return builder */ - public Builder setDeliveryLocation(Location deliveryLocation){ + public Builder setDeliveryLocation(Location deliveryLocation) { this.deliveryLocation_ = deliveryLocation; return this; } - /** - * Sets the delivery service-time. - * - *

ServiceTime is intended to be the time the implied activity takes at the delivery-location. - * - * @param deliveryServiceTime the service time / duration of shipment's delivery - * @return builder - * @throws IllegalArgumentException if serviceTime < 0.0 - */ - public Builder setDeliveryServiceTime(double deliveryServiceTime){ - if(deliveryServiceTime < 0.0) throw new IllegalArgumentException("deliveryServiceTime must not be < 0.0"); - this.deliveryServiceTime = deliveryServiceTime; - return this; - } - - /** - * Sets the timeWindow for the delivery, i.e. the time-period in which a delivery operation is - * allowed to start. - * - *

By default timeWindow is [0.0, Double.MAX_VALUE} - * - * @param timeWindow the time window within the associated delivery is allowed to START - * @return builder - * @throws IllegalArgumentException if timeWindow is null - */ - public Builder setDeliveryTimeWindow(TimeWindow timeWindow){ - if(timeWindow == null) throw new IllegalArgumentException("delivery time-window must not be null"); - this.deliveryTimeWindow = timeWindow; - return this; - } - - /** - * Adds capacity dimension. - * - * @param dimensionIndex the dimension index of the corresponding capacity value - * @param dimensionValue the capacity value - * @return builder - * @throws IllegalArgumentException if dimVal < 0 - */ - public Builder addSizeDimension(int dimensionIndex, int dimensionValue) { - if(dimensionValue<0) throw new IllegalArgumentException("capacity value cannot be negative"); - capacityBuilder.addDimension(dimensionIndex, dimensionValue); - return this; - } - + /** + * Sets the delivery service-time. + *

+ *

ServiceTime is intended to be the time the implied activity takes at the delivery-location. + * + * @param deliveryServiceTime the service time / duration of shipment's delivery + * @return builder + * @throws IllegalArgumentException if serviceTime < 0.0 + */ + public Builder setDeliveryServiceTime(double deliveryServiceTime) { + if (deliveryServiceTime < 0.0) throw new IllegalArgumentException("deliveryServiceTime must not be < 0.0"); + this.deliveryServiceTime = deliveryServiceTime; + return this; + } - /** - * Builds the shipment. - * - * @return shipment - * @throws IllegalStateException if neither pickup-location nor pickup-coord is set or if neither delivery-location nor delivery-coord - * is set - */ - public Shipment build(){ - if(pickupLocation_ == null) throw new IllegalStateException("pickup location is missing"); - if(deliveryLocation_ == null) throw new IllegalStateException("delivery location is missing"); - capacity = capacityBuilder.build(); + /** + * Sets the timeWindow for the delivery, i.e. the time-period in which a delivery operation is + * allowed to start. + *

+ *

By default timeWindow is [0.0, Double.MAX_VALUE} + * + * @param timeWindow the time window within the associated delivery is allowed to START + * @return builder + * @throws IllegalArgumentException if timeWindow is null + */ + public Builder setDeliveryTimeWindow(TimeWindow timeWindow) { + if (timeWindow == null) throw new IllegalArgumentException("delivery time-window must not be null"); + this.deliveryTimeWindow = timeWindow; + return this; + } + + /** + * Adds capacity dimension. + * + * @param dimensionIndex the dimension index of the corresponding capacity value + * @param dimensionValue the capacity value + * @return builder + * @throws IllegalArgumentException if dimVal < 0 + */ + public Builder addSizeDimension(int dimensionIndex, int dimensionValue) { + if (dimensionValue < 0) throw new IllegalArgumentException("capacity value cannot be negative"); + capacityBuilder.addDimension(dimensionIndex, dimensionValue); + return this; + } + + + /** + * Builds the shipment. + * + * @return shipment + * @throws IllegalStateException if neither pickup-location nor pickup-coord is set or if neither delivery-location nor delivery-coord + * is set + */ + public Shipment build() { + if (pickupLocation_ == null) throw new IllegalStateException("pickup location is missing"); + if (deliveryLocation_ == null) throw new IllegalStateException("delivery location is missing"); + capacity = capacityBuilder.build(); skills = skillBuilder.build(); - return new Shipment(this); - } + return new Shipment(this); + } public Builder addRequiredSkill(String skill) { @@ -216,18 +213,18 @@ public class Shipment extends AbstractJob{ return this; } } - - private final String id; - private final double pickupServiceTime; + private final String id; - private final double deliveryServiceTime; + private final double pickupServiceTime; - private final TimeWindow deliveryTimeWindow; + private final double deliveryServiceTime; - private final TimeWindow pickupTimeWindow; - - private final Capacity capacity; + private final TimeWindow deliveryTimeWindow; + + private final TimeWindow pickupTimeWindow; + + private final Capacity capacity; private final Skills skills; @@ -237,100 +234,104 @@ public class Shipment extends AbstractJob{ private final Location deliveryLocation_; - Shipment(Builder builder){ - this.id = builder.id; - this.pickupServiceTime = builder.pickupServiceTime; - this.pickupTimeWindow = builder.pickupTimeWindow; - this.deliveryServiceTime = builder.deliveryServiceTime; - this.deliveryTimeWindow = builder.deliveryTimeWindow; - this.capacity = builder.capacity; + Shipment(Builder builder) { + this.id = builder.id; + this.pickupServiceTime = builder.pickupServiceTime; + this.pickupTimeWindow = builder.pickupTimeWindow; + this.deliveryServiceTime = builder.deliveryServiceTime; + this.deliveryTimeWindow = builder.deliveryTimeWindow; + this.capacity = builder.capacity; this.skills = builder.skills; this.name = builder.name; this.pickupLocation_ = builder.pickupLocation_; this.deliveryLocation_ = builder.deliveryLocation_; - } - - @Override - public String getId() { - return id; - } + } - public Location getPickupLocation(){ return pickupLocation_; } + @Override + public String getId() { + return id; + } - /** - * Returns the pickup service-time. - * - *

By default service-time is 0.0. - * - * @return service-time - */ - public double getPickupServiceTime() { - return pickupServiceTime; - } + public Location getPickupLocation() { + return pickupLocation_; + } - public Location getDeliveryLocation() { return deliveryLocation_; } + /** + * Returns the pickup service-time. + *

+ *

By default service-time is 0.0. + * + * @return service-time + */ + public double getPickupServiceTime() { + return pickupServiceTime; + } - /** - * Returns service-time of delivery. - * - * @return service-time of delivery - */ - public double getDeliveryServiceTime() { - return deliveryServiceTime; - } + public Location getDeliveryLocation() { + return deliveryLocation_; + } - /** - * Returns the time-window of delivery. - * - * @return time-window of delivery - */ - public TimeWindow getDeliveryTimeWindow() { - return deliveryTimeWindow; - } + /** + * Returns service-time of delivery. + * + * @return service-time of delivery + */ + public double getDeliveryServiceTime() { + return deliveryServiceTime; + } - /** - * Returns the time-window of pickup. - * - * @return time-window of pickup - */ - public TimeWindow getPickupTimeWindow() { - return pickupTimeWindow; - } + /** + * Returns the time-window of delivery. + * + * @return time-window of delivery + */ + public TimeWindow getDeliveryTimeWindow() { + return deliveryTimeWindow; + } - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((id == null) ? 0 : id.hashCode()); - return result; - } + /** + * Returns the time-window of pickup. + * + * @return time-window of pickup + */ + public TimeWindow getPickupTimeWindow() { + return pickupTimeWindow; + } - /** - * Two shipments are equal if they have the same id. - * - * @return true if shipments are equal (have the same id) - */ - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - Shipment other = (Shipment) obj; - if (id == null) { - if (other.id != null) - return false; - } else if (!id.equals(other.id)) - return false; - return true; - } + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((id == null) ? 0 : id.hashCode()); + return result; + } - @Override - public Capacity getSize() { - return capacity; - } + /** + * Two shipments are equal if they have the same id. + * + * @return true if shipments are equal (have the same id) + */ + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Shipment other = (Shipment) obj; + if (id == null) { + if (other.id != null) + return false; + } else if (!id.equals(other.id)) + return false; + return true; + } + + @Override + public Capacity getSize() { + return capacity; + } @Override public Skills getRequiredSkills() { diff --git a/jsprit-core/src/main/java/jsprit/core/problem/misc/ActivityContext.java b/jsprit-core/src/main/java/jsprit/core/problem/misc/ActivityContext.java index ea64de7d..935a250a 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/misc/ActivityContext.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/misc/ActivityContext.java @@ -48,14 +48,14 @@ public class ActivityContext { /** * Returns the insertion index of the associated vehicle. - * + *

*

The associated activity is not inserted yet. The actual insertion position is still to be evaluated. * Thus this insertion index is related to the potential insertion index which is the position before * the activity at this index in the existing route. - * + *

* if insertionIndex == 0, the associated activity will be inserted between start of vehicle and the first * activity in activity sequence. - * + *

* if insertionIndex == relatedRoute.getActivities().size(), the associated activity will be inserted between * the last activity in the activity sequence and the end of vehicle. * diff --git a/jsprit-core/src/main/java/jsprit/core/problem/misc/JobInsertionContext.java b/jsprit-core/src/main/java/jsprit/core/problem/misc/JobInsertionContext.java index 749ee8a7..c88f45af 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/misc/JobInsertionContext.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/misc/JobInsertionContext.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.problem.misc; @@ -27,88 +27,87 @@ import java.util.List; /** * Provides context information about a particular job insertion. - * */ public class JobInsertionContext { private VehicleRoute route; - private Job job; + private Job job; - private Vehicle newVehicle; + private Vehicle newVehicle; - private Driver newDriver; + private Driver newDriver; - private double newDepTime; + private double newDepTime; private List associatedActivities = new ArrayList(); private ActivityContext pickupContext; - - /** + + /** * Returns the existing route where the .getJob() needs to be inserted in. * - * @return the route - */ - public VehicleRoute getRoute() { - return route; - } + * @return the route + */ + public VehicleRoute getRoute() { + return route; + } - /** + /** * Returns the job that needs to be inserted. * - * @return the job - */ - public Job getJob() { - return job; - } + * @return the job + */ + public Job getJob() { + return job; + } - /** + /** * Returns the vehicle that should operate the new route, i.e. route this.getRoute() + new job this.getJob(). * - * @return the newVehicle - */ - public Vehicle getNewVehicle() { - return newVehicle; - } + * @return the newVehicle + */ + public Vehicle getNewVehicle() { + return newVehicle; + } - /** + /** * Returns the driver that should operate the new route, i.e. route this.getRoute() + new job this.getJob(). - * + *

*

Currently the driver is just a mock, it has no functions

* - * @return the newDriver - */ - public Driver getNewDriver() { - return newDriver; - } + * @return the newDriver + */ + public Driver getNewDriver() { + return newDriver; + } - /** + /** * Returns the new departure time at the new vehicle's start location. * - * @return the newDepTime - */ - public double getNewDepTime() { - return newDepTime; - } + * @return the newDepTime + */ + public double getNewDepTime() { + return newDepTime; + } /** * Constructs the context. * - * @param route the existing route where the job needs to be inserted in - * @param job the job to be inserted + * @param route the existing route where the job needs to be inserted in + * @param job the job to be inserted * @param newVehicle the new vehicle that should operate the new route - * @param newDriver the new driver that should operate the new route + * @param newDriver the new driver that should operate the new route * @param newDepTime the new departure time at the new vehicle's start location */ - public JobInsertionContext(VehicleRoute route, Job job, Vehicle newVehicle, Driver newDriver, double newDepTime) { - super(); - this.route = route; - this.job = job; - this.newVehicle = newVehicle; - this.newDriver = newDriver; - this.newDepTime = newDepTime; - } + public JobInsertionContext(VehicleRoute route, Job job, Vehicle newVehicle, Driver newDriver, double newDepTime) { + super(); + this.route = route; + this.job = job; + this.newVehicle = newVehicle; + this.newDriver = newDriver; + this.newDepTime = newDepTime; + } public List getAssociatedActivities() { return associatedActivities; @@ -119,7 +118,7 @@ public class JobInsertionContext { * * @param pickupContext pickup context */ - public void setRelatedActivityContext(ActivityContext pickupContext){ + public void setRelatedActivityContext(ActivityContext pickupContext) { this.pickupContext = pickupContext; } @@ -128,7 +127,7 @@ public class JobInsertionContext { * * @return pickup context */ - public ActivityContext getRelatedActivityContext(){ + public ActivityContext getRelatedActivityContext() { return this.pickupContext; } } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/solution/InitialSolutionFactory.java b/jsprit-core/src/main/java/jsprit/core/problem/solution/InitialSolutionFactory.java index 6670745e..7153269d 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/solution/InitialSolutionFactory.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/solution/InitialSolutionFactory.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.problem.solution; @@ -20,18 +20,17 @@ import jsprit.core.problem.VehicleRoutingProblem; /** * Interface for all factories that create initial solutions for the specified {@link VehicleRoutingProblem}. - * - * @author schroeder * + * @author schroeder */ public interface InitialSolutionFactory { - /** - * Creates an initial solution for the specified {@link VehicleRoutingProblem}. - * - * @param vrp - * @return - */ - public VehicleRoutingProblemSolution createSolution(VehicleRoutingProblem vrp); + /** + * Creates an initial solution for the specified {@link VehicleRoutingProblem}. + * + * @param vrp + * @return + */ + public VehicleRoutingProblemSolution createSolution(VehicleRoutingProblem vrp); } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/solution/SolutionCostCalculator.java b/jsprit-core/src/main/java/jsprit/core/problem/solution/SolutionCostCalculator.java index f82656fc..ef454286 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/solution/SolutionCostCalculator.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/solution/SolutionCostCalculator.java @@ -1,37 +1,36 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.problem.solution; /** * Interface for all solutionCostCalculators which should be the objective-functions of the problem. - * + *

*

It evaluates VehicleRoutingProblemSolution and returns its costs. - * - * @author schroeder * + * @author schroeder */ public interface SolutionCostCalculator { - - /** - * Returns costs of solution. - * - * @param solution - * @return costs - */ - public double getCosts(VehicleRoutingProblemSolution solution); + + /** + * Returns costs of solution. + * + * @param solution + * @return costs + */ + public double getCosts(VehicleRoutingProblemSolution solution); } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/solution/VehicleRoutingProblemSolution.java b/jsprit-core/src/main/java/jsprit/core/problem/solution/VehicleRoutingProblemSolution.java index 1062e36c..b5aeaf50 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/solution/VehicleRoutingProblemSolution.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/solution/VehicleRoutingProblemSolution.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.problem.solution; @@ -25,57 +25,55 @@ import java.util.Collection; /** * Contains the solution of a vehicle routing problem and its corresponding costs. - * - * @author stefan schroeder * + * @author stefan schroeder */ public class VehicleRoutingProblemSolution { - /** - * Makes a deep copy of the solution to be copied. - * - * @param solution2copy solution to be copied - * @return solution - */ - public static VehicleRoutingProblemSolution copyOf(VehicleRoutingProblemSolution solution2copy){ - return new VehicleRoutingProblemSolution(solution2copy); - } - - private final Collection routes; + /** + * Makes a deep copy of the solution to be copied. + * + * @param solution2copy solution to be copied + * @return solution + */ + public static VehicleRoutingProblemSolution copyOf(VehicleRoutingProblemSolution solution2copy) { + return new VehicleRoutingProblemSolution(solution2copy); + } + + private final Collection routes; private Collection unassignedJobs = new ArrayList(); - private double cost; + private double cost; - private VehicleRoutingProblemSolution(VehicleRoutingProblemSolution solution){ - routes = new ArrayList(); - for(VehicleRoute r : solution.getRoutes()){ - VehicleRoute route = VehicleRoute.copyOf(r); - routes.add(route); - } - this.cost = solution.getCost(); + private VehicleRoutingProblemSolution(VehicleRoutingProblemSolution solution) { + routes = new ArrayList(); + for (VehicleRoute r : solution.getRoutes()) { + VehicleRoute route = VehicleRoute.copyOf(r); + routes.add(route); + } + this.cost = solution.getCost(); unassignedJobs.addAll(solution.getUnassignedJobs()); - } - - /** - * Constructs a solution with a number of {@link VehicleRoute}s and their corresponding aggregate cost value. - * - * @param routes routes being part of the solution - * @param cost total costs of solution - */ - public VehicleRoutingProblemSolution(Collection routes, double cost) { - super(); - this.routes = routes; - this.cost = cost; - } + } + + /** + * Constructs a solution with a number of {@link VehicleRoute}s and their corresponding aggregate cost value. + * + * @param routes routes being part of the solution + * @param cost total costs of solution + */ + public VehicleRoutingProblemSolution(Collection routes, double cost) { + super(); + this.routes = routes; + this.cost = cost; + } /** * Constructs a solution with a number of {@link VehicleRoute}s, bad jobs and their corresponding aggregate cost value. * - * @param routes routes being part of the solution + * @param routes routes being part of the solution * @param unassignedJobs jobs that could not be assigned to any vehicle - * @param cost total costs of solution - * + * @param cost total costs of solution */ public VehicleRoutingProblemSolution(Collection routes, Collection unassignedJobs, double cost) { super(); @@ -84,44 +82,44 @@ public class VehicleRoutingProblemSolution { this.cost = cost; } - /** - * Returns a collection of vehicle-routes. - * - * @return collection of vehicle-routes - */ - public Collection getRoutes() { - return routes; - } + /** + * Returns a collection of vehicle-routes. + * + * @return collection of vehicle-routes + */ + public Collection getRoutes() { + return routes; + } - /** - * Returns cost of this solution. - * - * @return costs - */ - public double getCost() { - return cost; - } - - /** - * Sets the costs of this solution. - * - * @param cost the cost to assigned to this solution - */ - public void setCost(double cost){ - this.cost = cost; - } + /** + * Returns cost of this solution. + * + * @return costs + */ + public double getCost() { + return cost; + } + + /** + * Sets the costs of this solution. + * + * @param cost the cost to assigned to this solution + */ + public void setCost(double cost) { + this.cost = cost; + } /** * Returns bad jobs, i.e. jobs that are not assigned to any vehicle route. * * @return bad jobs */ - public Collection getUnassignedJobs(){ + public Collection getUnassignedJobs() { return unassignedJobs; } - @Override - public String toString() { - return "[costs=" + cost + "][routes="+routes.size()+"][unassigned="+unassignedJobs.size()+"]"; - } + @Override + public String toString() { + return "[costs=" + cost + "][routes=" + routes.size() + "][unassigned=" + unassignedJobs.size() + "]"; + } } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/ReverseRouteActivityVisitor.java b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/ReverseRouteActivityVisitor.java index 26cf747e..f9234abe 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/ReverseRouteActivityVisitor.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/ReverseRouteActivityVisitor.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.problem.solution.route; @@ -24,46 +24,46 @@ import java.util.Collection; import java.util.Iterator; -public class ReverseRouteActivityVisitor implements RouteVisitor{ +public class ReverseRouteActivityVisitor implements RouteVisitor { - private Collection visitors = new ArrayList(); - - @Override - public void visit(VehicleRoute route) { - if(visitors.isEmpty()) return; - if(route.isEmpty()) return; - begin(route); - Iterator revIterator = route.getTourActivities().reverseActivityIterator(); - while(revIterator.hasNext()){ - TourActivity act = revIterator.next(); - visit(act); - } - finish(route); - } + private Collection visitors = new ArrayList(); - private void finish(VehicleRoute route) { - for(ReverseActivityVisitor visitor : visitors){ - visitor.finish(); - } - - } + @Override + public void visit(VehicleRoute route) { + if (visitors.isEmpty()) return; + if (route.isEmpty()) return; + begin(route); + Iterator revIterator = route.getTourActivities().reverseActivityIterator(); + while (revIterator.hasNext()) { + TourActivity act = revIterator.next(); + visit(act); + } + finish(route); + } - private void visit(TourActivity act) { - for(ReverseActivityVisitor visitor : visitors){ - visitor.visit(act); - } - } + private void finish(VehicleRoute route) { + for (ReverseActivityVisitor visitor : visitors) { + visitor.finish(); + } - private void begin(VehicleRoute route) { - for(ReverseActivityVisitor visitor : visitors){ - visitor.begin(route); - } - - } + } - public void addActivityVisitor(ReverseActivityVisitor activityVisitor){ - if(!visitors.contains(activityVisitor)){ - visitors.add(activityVisitor); - } - } + private void visit(TourActivity act) { + for (ReverseActivityVisitor visitor : visitors) { + visitor.visit(act); + } + } + + private void begin(VehicleRoute route) { + for (ReverseActivityVisitor visitor : visitors) { + visitor.begin(route); + } + + } + + public void addActivityVisitor(ReverseActivityVisitor activityVisitor) { + if (!visitors.contains(activityVisitor)) { + visitors.add(activityVisitor); + } + } } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/RouteActivityVisitor.java b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/RouteActivityVisitor.java index 42e94129..1faa16c4 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/RouteActivityVisitor.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/RouteActivityVisitor.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.problem.solution.route; @@ -23,44 +23,44 @@ import java.util.ArrayList; import java.util.Collection; -public class RouteActivityVisitor implements RouteVisitor{ +public class RouteActivityVisitor implements RouteVisitor { - private Collection visitors = new ArrayList(); - - @Override - public void visit(VehicleRoute route) { - if(visitors.isEmpty()) return; - begin(route); - for(TourActivity act : route.getTourActivities().getActivities()){ - visit(act); - } - end(route); - } + private Collection visitors = new ArrayList(); - private void end(VehicleRoute route) { - for(ActivityVisitor visitor : visitors){ - visitor.finish(); - } - - } + @Override + public void visit(VehicleRoute route) { + if (visitors.isEmpty()) return; + begin(route); + for (TourActivity act : route.getTourActivities().getActivities()) { + visit(act); + } + end(route); + } - private void visit(TourActivity act) { - for(ActivityVisitor visitor : visitors){ - visitor.visit(act); - } - } + private void end(VehicleRoute route) { + for (ActivityVisitor visitor : visitors) { + visitor.finish(); + } - private void begin(VehicleRoute route) { - for(ActivityVisitor visitor : visitors){ - visitor.begin(route); - } - - } + } - public RouteActivityVisitor addActivityVisitor(ActivityVisitor activityVisitor){ - if(!visitors.contains(activityVisitor)){ - visitors.add(activityVisitor); - } - return this; - } + private void visit(TourActivity act) { + for (ActivityVisitor visitor : visitors) { + visitor.visit(act); + } + } + + private void begin(VehicleRoute route) { + for (ActivityVisitor visitor : visitors) { + visitor.begin(route); + } + + } + + public RouteActivityVisitor addActivityVisitor(ActivityVisitor activityVisitor) { + if (!visitors.contains(activityVisitor)) { + visitors.add(activityVisitor); + } + return this; + } } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/RouteVisitor.java b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/RouteVisitor.java index 8fdc412c..78559542 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/RouteVisitor.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/RouteVisitor.java @@ -1,24 +1,24 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.problem.solution.route; public interface RouteVisitor { - - public void visit(VehicleRoute route); + + public void visit(VehicleRoute route); } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/VehicleRoute.java b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/VehicleRoute.java index 210bd5c3..6f948e1d 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/VehicleRoute.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/VehicleRoute.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.problem.solution.route; @@ -30,108 +30,108 @@ import java.util.*; /** * Contains the tour, i.e. a number of activities, a vehicle servicing the tour and a driver. - * - * - * @author stefan * + * @author stefan */ public class VehicleRoute { - - /** - * Returns a deep copy of this vehicleRoute. - * - * @param route route to copy - * @return copied route - * @throws IllegalArgumentException if route is null - */ - public static VehicleRoute copyOf(VehicleRoute route) { - if(route == null) throw new IllegalArgumentException("route must not be null"); - return new VehicleRoute(route); - } - - /** - * Returns an empty route. - * - *

An empty route has an empty list of tour-activities, no driver (DriverImpl.noDriver()) and no vehicle (VehicleImpl.createNoVehicle()). - * - * @return empty route - */ - public static VehicleRoute emptyRoute() { - return Builder.newInstance(VehicleImpl.createNoVehicle(), DriverImpl.noDriver()).build(); - } - - /** - * Builder that builds the vehicle route. - * - * @author stefan - * - */ - public static class Builder { + + /** + * Returns a deep copy of this vehicleRoute. + * + * @param route route to copy + * @return copied route + * @throws IllegalArgumentException if route is null + */ + public static VehicleRoute copyOf(VehicleRoute route) { + if (route == null) throw new IllegalArgumentException("route must not be null"); + return new VehicleRoute(route); + } + + /** + * Returns an empty route. + *

+ *

An empty route has an empty list of tour-activities, no driver (DriverImpl.noDriver()) and no vehicle (VehicleImpl.createNoVehicle()). + * + * @return empty route + */ + public static VehicleRoute emptyRoute() { + return Builder.newInstance(VehicleImpl.createNoVehicle(), DriverImpl.noDriver()).build(); + } + + /** + * Builder that builds the vehicle route. + * + * @author stefan + */ + public static class Builder { private Map openActivities = new HashMap(); /** - * Returns new instance of this builder. - * - *

Construction-settings of vehicleRoute: - *

startLocation == vehicle.getStartLocationId() - *

endLocation == vehicle.getEndLocationId() - *

departureTime == vehicle.getEarliestDepartureTime() - *

latestStart == Double.MAX_VALUE - *

earliestEnd == 0.0 - * - * @param vehicle employed vehicle - * @param driver employed driver - * @return this builder - */ - public static Builder newInstance(Vehicle vehicle, Driver driver){ - if(vehicle == null || driver == null) throw new IllegalArgumentException("null arguments not accepted. ini emptyRoute with VehicleImpl.createNoVehicle() and DriverImpl.noDriver()"); - return new Builder(vehicle,driver); - } - - /** - * Returns new instance of this builder. - * - *

Construction-settings of vehicleRoute: - *

startLocation == vehicle.getStartLocationId() - *

endLocation == vehicle.getEndLocationId() - *

departureTime == vehicle.getEarliestDepartureTime() - *

latestStart == Double.MAX_VALUE - *

earliestEnd == 0.0 - * - * @param vehicle employed vehicle - * @return this builder - */ - public static Builder newInstance(Vehicle vehicle){ - if(vehicle == null) throw new IllegalArgumentException("null arguments not accepted. ini emptyRoute with VehicleImpl.createNoVehicle() and DriverImpl.noDriver()"); - return new Builder(vehicle,DriverImpl.noDriver()); - } - - private Vehicle vehicle; - - private Driver driver; - - private Start start; - - private End end; - - private TourActivities tourActivities = new TourActivities(); - - private TourActivityFactory serviceActivityFactory = new DefaultTourActivityFactory(); - - private TourShipmentActivityFactory shipmentActivityFactory = new DefaultShipmentActivityFactory(); - - private Set openShipments = new HashSet(); + * Returns new instance of this builder. + *

+ *

Construction-settings of vehicleRoute: + *

startLocation == vehicle.getStartLocationId() + *

endLocation == vehicle.getEndLocationId() + *

departureTime == vehicle.getEarliestDepartureTime() + *

latestStart == Double.MAX_VALUE + *

earliestEnd == 0.0 + * + * @param vehicle employed vehicle + * @param driver employed driver + * @return this builder + */ + public static Builder newInstance(Vehicle vehicle, Driver driver) { + if (vehicle == null || driver == null) + throw new IllegalArgumentException("null arguments not accepted. ini emptyRoute with VehicleImpl.createNoVehicle() and DriverImpl.noDriver()"); + return new Builder(vehicle, driver); + } + + /** + * Returns new instance of this builder. + *

+ *

Construction-settings of vehicleRoute: + *

startLocation == vehicle.getStartLocationId() + *

endLocation == vehicle.getEndLocationId() + *

departureTime == vehicle.getEarliestDepartureTime() + *

latestStart == Double.MAX_VALUE + *

earliestEnd == 0.0 + * + * @param vehicle employed vehicle + * @return this builder + */ + public static Builder newInstance(Vehicle vehicle) { + if (vehicle == null) + throw new IllegalArgumentException("null arguments not accepted. ini emptyRoute with VehicleImpl.createNoVehicle() and DriverImpl.noDriver()"); + return new Builder(vehicle, DriverImpl.noDriver()); + } + + private Vehicle vehicle; + + private Driver driver; + + private Start start; + + private End end; + + private TourActivities tourActivities = new TourActivities(); + + private TourActivityFactory serviceActivityFactory = new DefaultTourActivityFactory(); + + private TourShipmentActivityFactory shipmentActivityFactory = new DefaultShipmentActivityFactory(); + + private Set openShipments = new HashSet(); private JobActivityFactory jobActivityFactory = new JobActivityFactory() { @Override public List createActivities(Job job) { List acts = new ArrayList(); - if(job instanceof Service){ + if (job instanceof Break) { + acts.add(BreakActivity.newInstance((Break) job)); + } else if (job instanceof Service) { acts.add(serviceActivityFactory.createActivity((Service) job)); - } - else if(job instanceof Shipment){ + } else if (job instanceof Shipment) { acts.add(shipmentActivityFactory.createPickup((Shipment) job)); acts.add(shipmentActivityFactory.createDelivery((Shipment) job)); } @@ -139,94 +139,96 @@ public class VehicleRoute { } }; - - /** - * Sets the serviceActivityFactory to create serviceActivities. - * - *

By default {@link DefaultTourActivityFactory} is used. - * - * @param serviceActivityFactory the factory to create serviceActivities - */ - @Deprecated - public Builder setServiceActivityFactory(TourActivityFactory serviceActivityFactory) { - this.serviceActivityFactory = serviceActivityFactory; - return this; - } - /** - * Sets the shipmentActivityFactory to create shipmentActivities. - * - *

By default {@link DefaultShipmentActivityFactory} is used. - * - * @param shipmentActivityFactory the factory to create shipmentActivities - */ + /** + * Sets the serviceActivityFactory to create serviceActivities. + *

+ *

By default {@link DefaultTourActivityFactory} is used. + * + * @param serviceActivityFactory the factory to create serviceActivities + */ @Deprecated - public Builder setShipmentActivityFactory(TourShipmentActivityFactory shipmentActivityFactory) { - this.shipmentActivityFactory = shipmentActivityFactory; + public Builder setServiceActivityFactory(TourActivityFactory serviceActivityFactory) { + this.serviceActivityFactory = serviceActivityFactory; return this; - } + } - public Builder setJobActivityFactory(JobActivityFactory jobActivityFactory){ + /** + * Sets the shipmentActivityFactory to create shipmentActivities. + *

+ *

By default {@link DefaultShipmentActivityFactory} is used. + * + * @param shipmentActivityFactory the factory to create shipmentActivities + */ + @Deprecated + public Builder setShipmentActivityFactory(TourShipmentActivityFactory shipmentActivityFactory) { + this.shipmentActivityFactory = shipmentActivityFactory; + return this; + } + + public Builder setJobActivityFactory(JobActivityFactory jobActivityFactory) { this.jobActivityFactory = jobActivityFactory; return this; } - private Builder(Vehicle vehicle, Driver driver) { - super(); - this.vehicle = vehicle; - this.driver = driver; - start = new Start(vehicle.getStartLocation(), vehicle.getEarliestDeparture(), Double.MAX_VALUE); - start.setEndTime(vehicle.getEarliestDeparture()); - end = new End(vehicle.getEndLocation(), 0.0, vehicle.getLatestArrival()); - } + private Builder(Vehicle vehicle, Driver driver) { + super(); + this.vehicle = vehicle; + this.driver = driver; + start = new Start(vehicle.getStartLocation(), vehicle.getEarliestDeparture(), Double.MAX_VALUE); + start.setEndTime(vehicle.getEarliestDeparture()); + end = new End(vehicle.getEndLocation(), 0.0, vehicle.getLatestArrival()); + } - /** - * Sets the departure-time of the route, i.e. which is the time the vehicle departs from start-location. - * - *

Note that departureTime cannot be lower than earliestDepartureTime of vehicle. - * - * @param departureTime departure time of vehicle being employed for this route - * @return builder - * @throws IllegalArgumentException if departureTime < vehicle.getEarliestDeparture() - */ - public Builder setDepartureTime(double departureTime){ - if(departureTime < start.getEndTime()) throw new IllegalArgumentException("departureTime < vehicle.getEarliestDepartureTime(). this must not be."); - start.setEndTime(departureTime); - return this; - } - - /** - * Sets the end-time of the route, i.e. which is the time the vehicle has to be at its end-location at latest. - * - * @param endTime endTime of route - * @return this builder - * @throws IllegalArgumentException if endTime > vehicle.getLatestArrival() - */ + /** + * Sets the departure-time of the route, i.e. which is the time the vehicle departs from start-location. + *

+ *

Note that departureTime cannot be lower than earliestDepartureTime of vehicle. + * + * @param departureTime departure time of vehicle being employed for this route + * @return builder + * @throws IllegalArgumentException if departureTime < vehicle.getEarliestDeparture() + */ + public Builder setDepartureTime(double departureTime) { + if (departureTime < start.getEndTime()) + throw new IllegalArgumentException("departureTime < vehicle.getEarliestDepartureTime(). this must not be."); + start.setEndTime(departureTime); + return this; + } + + /** + * Sets the end-time of the route, i.e. which is the time the vehicle has to be at its end-location at latest. + * + * @param endTime endTime of route + * @return this builder + * @throws IllegalArgumentException if endTime > vehicle.getLatestArrival() + */ @Deprecated - public Builder setRouteEndArrivalTime(double endTime){ - if(endTime > vehicle.getLatestArrival()) throw new IllegalArgumentException("endTime > vehicle.getLatestArrival(). this must not be."); - end.setArrTime(endTime); - return this; - } - - /** - * Adds a service to this route. - * - *

This implies that for this service a serviceActivity is created with {@link TourActivityFactory} and added to the sequence of tourActivities. - * - *

The resulting activity occurs in the activity-sequence in the order adding/inserting. - * - * @param service to be added - * @return this builder - * @throws IllegalArgumentException if service is null - */ - public Builder addService(Service service){ - if(service == null) throw new IllegalArgumentException("service must not be null"); + public Builder setRouteEndArrivalTime(double endTime) { + if (endTime > vehicle.getLatestArrival()) + throw new IllegalArgumentException("endTime > vehicle.getLatestArrival(). this must not be."); + end.setArrTime(endTime); + return this; + } + + /** + * Adds a service to this route. + *

+ *

This implies that for this service a serviceActivity is created with {@link TourActivityFactory} and added to the sequence of tourActivities. + *

+ *

The resulting activity occurs in the activity-sequence in the order adding/inserting. + * + * @param service to be added + * @return this builder + * @throws IllegalArgumentException if service is null + */ + public Builder addService(Service service) { + if (service == null) throw new IllegalArgumentException("service must not be null"); List acts = jobActivityFactory.createActivities(service); TourActivity act = acts.get(0); tourActivities.addActivity(act); - return this; - } + return this; + } /** * Adds a pickup to this route. @@ -234,8 +236,8 @@ public class VehicleRoute { * @param pickup pickup to be added * @return the builder */ - public Builder addPickup(Pickup pickup){ - if(pickup == null) throw new IllegalArgumentException("pickup must not be null"); + public Builder addPickup(Pickup pickup) { + if (pickup == null) throw new IllegalArgumentException("pickup must not be null"); addService(pickup); return this; } @@ -246,216 +248,220 @@ public class VehicleRoute { * @param delivery delivery to be added * @return the builder */ - public Builder addDelivery(Delivery delivery){ - if(delivery == null) throw new IllegalArgumentException("delivery must not be null"); + public Builder addDelivery(Delivery delivery) { + if (delivery == null) throw new IllegalArgumentException("delivery must not be null"); addService(delivery); return this; } /** - * Adds a the pickup of the specified shipment. - * - * @param shipment to be picked up and added to this route - * @throws IllegalStateException if method has already been called with the specified shipment. - * @return the builder - */ - public Builder addPickup(Shipment shipment){ - if(openShipments.contains(shipment)) throw new IllegalStateException("shipment has already been added. cannot add it twice."); - List acts = jobActivityFactory.createActivities(shipment); + * Adds a the pickup of the specified shipment. + * + * @param shipment to be picked up and added to this route + * @return the builder + * @throws IllegalStateException if method has already been called with the specified shipment. + */ + public Builder addPickup(Shipment shipment) { + if (openShipments.contains(shipment)) + throw new IllegalStateException("shipment has already been added. cannot add it twice."); + List acts = jobActivityFactory.createActivities(shipment); TourActivity act = acts.get(0); - tourActivities.addActivity(act); - openShipments.add(shipment); - openActivities.put(shipment,acts.get(1)); + tourActivities.addActivity(act); + openShipments.add(shipment); + openActivities.put(shipment, acts.get(1)); return this; - } + } - /** - * Adds a the delivery of the specified shipment. - * - * @param shipment to be delivered and add to this vehicleRoute - * @throws IllegalStateException if specified shipment has not been picked up yet (i.e. method addPickup(shipment) has not been called yet). - * @return builder - */ - public Builder addDelivery(Shipment shipment){ - if(openShipments.contains(shipment)){ - TourActivity act = openActivities.get(shipment); - tourActivities.addActivity(act); - openShipments.remove(shipment); - } - else{ throw new IllegalStateException("cannot deliver shipment. shipment " + shipment + " needs to be picked up first."); } + /** + * Adds a the delivery of the specified shipment. + * + * @param shipment to be delivered and add to this vehicleRoute + * @return builder + * @throws IllegalStateException if specified shipment has not been picked up yet (i.e. method addPickup(shipment) has not been called yet). + */ + public Builder addDelivery(Shipment shipment) { + if (openShipments.contains(shipment)) { + TourActivity act = openActivities.get(shipment); + tourActivities.addActivity(act); + openShipments.remove(shipment); + } else { + throw new IllegalStateException("cannot deliver shipment. shipment " + shipment + " needs to be picked up first."); + } return this; - } + } - - /** - * Builds the route. - * - * @return {@link VehicleRoute} - * @throws IllegalStateException if there are still shipments that have been picked up though but not delivery. - */ - public VehicleRoute build(){ - if(!openShipments.isEmpty()){ - throw new IllegalStateException("there are still shipments that have not been delivered yet."); - } - if(!vehicle.isReturnToDepot()){ - if(!tourActivities.isEmpty()){ - end.setLocation(tourActivities.getActivities().get(tourActivities.getActivities().size() - 1).getLocation()); - } - } - return new VehicleRoute(this); - } - } - - private TourActivities tourActivities; + /** + * Builds the route. + * + * @return {@link VehicleRoute} + * @throws IllegalStateException if there are still shipments that have been picked up though but not delivery. + */ + public VehicleRoute build() { + if (!openShipments.isEmpty()) { + throw new IllegalStateException("there are still shipments that have not been delivered yet."); + } + if (!vehicle.isReturnToDepot()) { + if (!tourActivities.isEmpty()) { + end.setLocation(tourActivities.getActivities().get(tourActivities.getActivities().size() - 1).getLocation()); + } + } + return new VehicleRoute(this); + } - private Vehicle vehicle; - - private Driver driver; - - private Start start; - - private End end; - - /** - * Copy constructor copying a route. - * - * @param route to copy - */ - private VehicleRoute(VehicleRoute route){ - this.start = Start.copyOf(route.getStart()); - this.end = End.copyOf(route.getEnd()); - this.tourActivities = TourActivities.copyOf(route.getTourActivities()); - this.vehicle = route.getVehicle(); - this.driver = route.getDriver(); - } - - /** - * Constructs route. - * - * @param builder used to build route - */ - private VehicleRoute(Builder builder){ - this.tourActivities = builder.tourActivities; - this.vehicle = builder.vehicle; - this.driver = builder.driver; - this.start = builder.start; - this.end = builder.end; - } + } - /** - * Returns an unmodifiable list of activities on this route (without start/end). - * - * @return list of tourActivities - */ - public List getActivities(){ - return Collections.unmodifiableList(tourActivities.getActivities()); - } - - /** - * Returns TourActivities. - * - * @return {@link TourActivities} - */ - public TourActivities getTourActivities() { - return tourActivities; - } - - /** - * Returns the vehicle operating this route. - * - * @return Vehicle - */ - public Vehicle getVehicle() { - return vehicle; - } + private TourActivities tourActivities; - /** - * Returns the driver operating this route. - * - * @return Driver - */ - public Driver getDriver() { - return driver; - } + private Vehicle vehicle; - /** - * Sets the vehicle and its departureTime from vehicle.getStartLocationId(). - * - *

This implies the following:
- * if start and end are null, new start and end activities are created.
- *

startActivity is initialized with the start-location of the specified vehicle (vehicle.getStartLocationId()). the time-window of this activity is initialized - * such that [startActivity.getTheoreticalEarliestOperationStartTime() = vehicle.getEarliestDeparture()][startActivity.getTheoreticalLatestOperationStartTime() = vehicle.getLatestArrival()] - *

endActivity is initialized with the end-location of the specified vehicle (vehicle.getEndLocationId()). The time-window of the - * endActivity is initialized such that [endActivity.getTheoreticalEarliestOperationStartTime() = vehicle.getEarliestDeparture()][endActivity.getTheoreticalLatestOperationStartTime() = vehicle.getLatestArrival()] - *

startActivity.endTime (startActivity.getEndTime()) is set to max{vehicle.getEarliestDeparture(), vehicleDepTime}. - * thus, vehicle.getEarliestDeparture() is a physical constraint that has to be met. - * - * @param vehicle to be employed - * @param vehicleDepTime of employed vehicle - */ - public void setVehicleAndDepartureTime(Vehicle vehicle, double vehicleDepTime){ - this.vehicle = vehicle; - setStartAndEnd(vehicle, vehicleDepTime); - } - private void setStartAndEnd(Vehicle vehicle, double vehicleDepTime) { - if(!(vehicle instanceof NoVehicle)){ - if(start == null && end == null){ - start = new Start(vehicle.getStartLocation(), vehicle.getEarliestDeparture(), vehicle.getLatestArrival()); - end = new End(vehicle.getEndLocation(), vehicle.getEarliestDeparture(), vehicle.getLatestArrival()); - } - start.setEndTime(Math.max(vehicleDepTime, vehicle.getEarliestDeparture())); - start.setTheoreticalEarliestOperationStartTime(vehicle.getEarliestDeparture()); - start.setTheoreticalLatestOperationStartTime(vehicle.getLatestArrival()); - start.setLocation(vehicle.getStartLocation()); - end.setLocation(vehicle.getEndLocation()); - end.setTheoreticalEarliestOperationStartTime(vehicle.getEarliestDeparture()); - end.setTheoreticalLatestOperationStartTime(vehicle.getLatestArrival()); - } - - } + private Driver driver; - /** - * Returns the departureTime of this vehicle in this route. - * - * @return departureTime - * @throws IllegalStateException if start is null - */ - public double getDepartureTime(){ - if(start == null) throw new IllegalStateException("cannot get departureTime without having a vehicle on this route. use setVehicle(vehicle,departureTime) instead."); - return start.getEndTime(); - } - - /** - * Returns tour if tour-activity-sequence is empty, i.e. to activity on the tour yet. - * - * @return true if route is empty - */ - public boolean isEmpty() { - return tourActivities.isEmpty(); - } + private Start start; - /** - * Returns start-activity of this route. - * - * @return start - */ - public Start getStart() { - return start; - } + private End end; - /** - * Returns end-activity of this route. - * - * @return end - */ - public End getEnd() { - return end; - } - - @Override - public String toString() { - return "[start="+start+"][end=" + end + "][departureTime=" + start.getEndTime() + "][vehicle=" + vehicle + "][driver=" + driver + "][nuOfActs="+tourActivities.getActivities().size()+"]"; - } + /** + * Copy constructor copying a route. + * + * @param route to copy + */ + private VehicleRoute(VehicleRoute route) { + this.start = Start.copyOf(route.getStart()); + this.end = End.copyOf(route.getEnd()); + this.tourActivities = TourActivities.copyOf(route.getTourActivities()); + this.vehicle = route.getVehicle(); + this.driver = route.getDriver(); + } + + /** + * Constructs route. + * + * @param builder used to build route + */ + private VehicleRoute(Builder builder) { + this.tourActivities = builder.tourActivities; + this.vehicle = builder.vehicle; + this.driver = builder.driver; + this.start = builder.start; + this.end = builder.end; + } + + /** + * Returns an unmodifiable list of activities on this route (without start/end). + * + * @return list of tourActivities + */ + public List getActivities() { + return Collections.unmodifiableList(tourActivities.getActivities()); + } + + /** + * Returns TourActivities. + * + * @return {@link TourActivities} + */ + public TourActivities getTourActivities() { + return tourActivities; + } + + /** + * Returns the vehicle operating this route. + * + * @return Vehicle + */ + public Vehicle getVehicle() { + return vehicle; + } + + /** + * Returns the driver operating this route. + * + * @return Driver + */ + public Driver getDriver() { + return driver; + } + + /** + * Sets the vehicle and its departureTime from vehicle.getStartLocationId(). + *

+ *

This implies the following:
+ * if start and end are null, new start and end activities are created.
+ *

startActivity is initialized with the start-location of the specified vehicle (vehicle.getStartLocationId()). the time-window of this activity is initialized + * such that [startActivity.getTheoreticalEarliestOperationStartTime() = vehicle.getEarliestDeparture()][startActivity.getTheoreticalLatestOperationStartTime() = vehicle.getLatestArrival()] + *

endActivity is initialized with the end-location of the specified vehicle (vehicle.getEndLocationId()). The time-window of the + * endActivity is initialized such that [endActivity.getTheoreticalEarliestOperationStartTime() = vehicle.getEarliestDeparture()][endActivity.getTheoreticalLatestOperationStartTime() = vehicle.getLatestArrival()] + *

startActivity.endTime (startActivity.getEndTime()) is set to max{vehicle.getEarliestDeparture(), vehicleDepTime}. + * thus, vehicle.getEarliestDeparture() is a physical constraint that has to be met. + * + * @param vehicle to be employed + * @param vehicleDepTime of employed vehicle + */ + public void setVehicleAndDepartureTime(Vehicle vehicle, double vehicleDepTime) { + this.vehicle = vehicle; + setStartAndEnd(vehicle, vehicleDepTime); + } + + private void setStartAndEnd(Vehicle vehicle, double vehicleDepTime) { + if (!(vehicle instanceof NoVehicle)) { + if (start == null && end == null) { + start = new Start(vehicle.getStartLocation(), vehicle.getEarliestDeparture(), vehicle.getLatestArrival()); + end = new End(vehicle.getEndLocation(), vehicle.getEarliestDeparture(), vehicle.getLatestArrival()); + } + start.setEndTime(Math.max(vehicleDepTime, vehicle.getEarliestDeparture())); + start.setTheoreticalEarliestOperationStartTime(vehicle.getEarliestDeparture()); + start.setTheoreticalLatestOperationStartTime(vehicle.getLatestArrival()); + start.setLocation(vehicle.getStartLocation()); + end.setLocation(vehicle.getEndLocation()); + end.setTheoreticalEarliestOperationStartTime(vehicle.getEarliestDeparture()); + end.setTheoreticalLatestOperationStartTime(vehicle.getLatestArrival()); + } + + } + + /** + * Returns the departureTime of this vehicle in this route. + * + * @return departureTime + * @throws IllegalStateException if start is null + */ + public double getDepartureTime() { + if (start == null) + throw new IllegalStateException("cannot get departureTime without having a vehicle on this route. use setVehicle(vehicle,departureTime) instead."); + return start.getEndTime(); + } + + /** + * Returns tour if tour-activity-sequence is empty, i.e. to activity on the tour yet. + * + * @return true if route is empty + */ + public boolean isEmpty() { + return tourActivities.isEmpty(); + } + + /** + * Returns start-activity of this route. + * + * @return start + */ + public Start getStart() { + return start; + } + + /** + * Returns end-activity of this route. + * + * @return end + */ + public End getEnd() { + return end; + } + + @Override + public String toString() { + return "[start=" + start + "][end=" + end + "][departureTime=" + start.getEndTime() + "][vehicle=" + vehicle + "][driver=" + driver + "][nuOfActs=" + tourActivities.getActivities().size() + "]"; + } } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/Activities.java b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/Activities.java index 747b9276..16218831 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/Activities.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/Activities.java @@ -1,30 +1,30 @@ /******************************************************************************* * Copyright (c) 2014 Stefan Schroeder. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . - * + * * Contributors: * Stefan Schroeder - initial API and implementation ******************************************************************************/ package jsprit.core.problem.solution.route.activity; class Activities { - - public static String round(double time) { - if (time == Double.MAX_VALUE) { - return "oo"; - } - return "" + Math.round(time); - } + + public static String round(double time) { + if (time == Double.MAX_VALUE) { + return "oo"; + } + return "" + Math.round(time); + } } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/ActivityVisitor.java b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/ActivityVisitor.java index d85d3465..e319df66 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/ActivityVisitor.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/ActivityVisitor.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.problem.solution.route.activity; @@ -20,11 +20,11 @@ import jsprit.core.problem.solution.route.VehicleRoute; public interface ActivityVisitor { - - public void begin(VehicleRoute route); - - public void visit(TourActivity activity); - - public void finish(); + + public void begin(VehicleRoute route); + + public void visit(TourActivity activity); + + public void finish(); } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/BreakActivity.java b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/BreakActivity.java new file mode 100644 index 00000000..ec1ab168 --- /dev/null +++ b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/BreakActivity.java @@ -0,0 +1,198 @@ +/******************************************************************************* + * Copyright (C) 2014 Stefan Schroeder + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3.0 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + ******************************************************************************/ +package jsprit.core.problem.solution.route.activity; + +import jsprit.core.problem.AbstractActivity; +import jsprit.core.problem.Capacity; +import jsprit.core.problem.Location; +import jsprit.core.problem.job.Break; +import jsprit.core.problem.job.Service; +import jsprit.core.problem.solution.route.activity.TourActivity.JobActivity; + +import java.util.List; + +public class BreakActivity extends AbstractActivity implements JobActivity { + + public static int counter = 0; + + public double arrTime; + + public double endTime; + + private Location location; + + /** + * @return the arrTime + */ + public double getArrTime() { + return arrTime; + } + + /** + * @param arrTime the arrTime to set + */ + public void setArrTime(double arrTime) { + this.arrTime = arrTime; + } + + /** + * @return the endTime + */ + public double getEndTime() { + return endTime; + } + + /** + * @param endTime the endTime to set + */ + public void setEndTime(double endTime) { + this.endTime = endTime; + } + + public static BreakActivity copyOf(BreakActivity breakActivity) { + return new BreakActivity(breakActivity); + } + + public static BreakActivity newInstance(Break aBreak) { + return new BreakActivity(aBreak); + } + + private final Break aBreak; + + private double earliest; + + private double latest; + + protected BreakActivity(Break aBreak) { + counter++; + this.aBreak = aBreak; + } + + protected BreakActivity(BreakActivity breakActivity) { + counter++; + this.aBreak = (Break) breakActivity.getJob(); + this.arrTime = breakActivity.getArrTime(); + this.endTime = breakActivity.getEndTime(); + this.location = breakActivity.getLocation(); + setIndex(breakActivity.getIndex()); + } + + + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((aBreak == null) ? 0 : aBreak.hashCode()); + return result; + } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + BreakActivity other = (BreakActivity) obj; + if (aBreak == null) { + if (other.aBreak != null) + return false; + } else if (!aBreak.equals(other.aBreak)) + return false; + return true; + } + + public double getTheoreticalEarliestOperationStartTime() { + return earliest; + } + + public double getTheoreticalLatestOperationStartTime() { + return latest; + } + + @Override + public double getOperationTime() { + return aBreak.getServiceDuration(); + } + + @Override + public String getLocationId() { + return aBreak.getLocation().getId(); + } + + @Override + public Location getLocation() { + return location; + } + + public void setLocation(Location breakLocation) { + this.location = breakLocation; + } + + @Override + public Service getJob() { + return aBreak; + } + + + @Override + public String toString() { + return "[type=" + getName() + "][location=" + getLocation() + + "][size=" + getSize().toString() + + "][twStart=" + Activities.round(getTheoreticalEarliestOperationStartTime()) + + "][twEnd=" + Activities.round(getTheoreticalLatestOperationStartTime()) + "]"; + } + + @Override + public void setTheoreticalEarliestOperationStartTime(double earliest) { + this.earliest = earliest; + } + + @Override + public void setTheoreticalLatestOperationStartTime(double latest) { + this.latest = latest; + } + + @Override + public List getTimeWindows() { + return null; + } + + @Override + public String getName() { + return aBreak.getType(); + } + + @Override + public TourActivity duplicate() { + return new BreakActivity(this); + } + + @Override + public Capacity getSize() { + return aBreak.getSize(); + } + + +} diff --git a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/DefaultShipmentActivityFactory.java b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/DefaultShipmentActivityFactory.java index f25acd50..c99b3670 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/DefaultShipmentActivityFactory.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/DefaultShipmentActivityFactory.java @@ -1,18 +1,18 @@ /******************************************************************************* * Copyright (c) 2014 Stefan Schroeder. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . - * + * * Contributors: * Stefan Schroeder - initial API and implementation ******************************************************************************/ @@ -21,16 +21,16 @@ package jsprit.core.problem.solution.route.activity; import jsprit.core.problem.AbstractActivity; import jsprit.core.problem.job.Shipment; -public class DefaultShipmentActivityFactory implements TourShipmentActivityFactory{ +public class DefaultShipmentActivityFactory implements TourShipmentActivityFactory { - @Override - public AbstractActivity createPickup(Shipment shipment) { - return new PickupShipment(shipment); - } + @Override + public AbstractActivity createPickup(Shipment shipment) { + return new PickupShipment(shipment); + } - @Override - public AbstractActivity createDelivery(Shipment shipment) { - return new DeliverShipment(shipment); - } + @Override + public AbstractActivity createDelivery(Shipment shipment) { + return new DeliverShipment(shipment); + } } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/DefaultTourActivityFactory.java b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/DefaultTourActivityFactory.java index cf3a61d7..bb6207dc 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/DefaultTourActivityFactory.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/DefaultTourActivityFactory.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.problem.solution.route.activity; @@ -21,21 +21,19 @@ import jsprit.core.problem.job.Delivery; import jsprit.core.problem.job.Pickup; import jsprit.core.problem.job.Service; -public class DefaultTourActivityFactory implements TourActivityFactory{ +public class DefaultTourActivityFactory implements TourActivityFactory { - @Override - public AbstractActivity createActivity(Service service) { - AbstractActivity act; - if(service instanceof Pickup){ - act = new PickupService((Pickup) service); - } - else if(service instanceof Delivery){ - act = new DeliverService((Delivery) service); - } - else{ - act = new PickupService(service); - } - return act; - } + @Override + public AbstractActivity createActivity(Service service) { + AbstractActivity act; + if (service instanceof Pickup) { + act = new PickupService((Pickup) service); + } else if (service instanceof Delivery) { + act = new DeliverService((Delivery) service); + } else { + act = new PickupService(service); + } + return act; + } } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/DeliverService.java b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/DeliverService.java index 295a61d9..5c668b6d 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/DeliverService.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/DeliverService.java @@ -24,64 +24,47 @@ import jsprit.core.problem.job.Delivery; import java.util.ArrayList; import java.util.List; -public final class DeliverService extends AbstractActivity implements DeliveryActivity{ - - private Delivery delivery; - - private Capacity capacity; - - private double arrTime; - - private double endTime; +public final class DeliverService extends AbstractActivity implements DeliveryActivity { - private double theoreticalEarliest; + private Delivery delivery; - private double theoreticalLatest; + private Capacity capacity; - private List timeWindows; - - public DeliverService(Delivery delivery) { - super(); - this.delivery = delivery; - capacity = Capacity.invert(delivery.getSize()); - timeWindows = new ArrayList(delivery.getTimeWindows(0.)); - } - - private DeliverService(DeliverService deliveryActivity){ - this.delivery=deliveryActivity.getJob(); - this.arrTime=deliveryActivity.getArrTime(); - this.endTime=deliveryActivity.getEndTime(); - this.theoreticalEarliest = deliveryActivity.getTheoreticalEarliestOperationStartTime(); - this.theoreticalLatest = deliveryActivity.getTheoreticalLatestOperationStartTime(); - capacity = deliveryActivity.getSize(); + private double arrTime; + + private double endTime; + + private double theoreticalEarliest; + + private double theoreticalLatest; + + private List timeWindows; + + public DeliverService(Delivery delivery) { + super(); + this.delivery = delivery; + capacity = Capacity.invert(delivery.getSize()); + timeWindows = new ArrayList(delivery.getTimeWindows(0.)); + } + + private DeliverService(DeliverService deliveryActivity) { + this.delivery = deliveryActivity.getJob(); + this.arrTime = deliveryActivity.getArrTime(); + this.endTime = deliveryActivity.getEndTime(); + capacity = deliveryActivity.getSize(); setIndex(deliveryActivity.getIndex()); - timeWindows = new ArrayList(delivery.getTimeWindows(0.)); - } + timeWindows = new ArrayList(delivery.getTimeWindows(0.)); + } - @Override - public void setTheoreticalEarliestOperationStartTime(double earliest) { - theoreticalEarliest = earliest; - } + @Override + public String getName() { + return delivery.getType(); + } - @Override - public void setTheoreticalLatestOperationStartTime(double latest) { - theoreticalLatest = latest; - } - - @Override - public List getTimeWindows() { - return timeWindows; - } - - @Override - public String getName() { - return delivery.getType(); - } - - @Override - public String getLocationId() { - return delivery.getLocation().getId(); - } + @Override + public String getLocationId() { + return delivery.getLocation().getId(); + } @Override public Location getLocation() { @@ -89,59 +72,74 @@ public final class DeliverService extends AbstractActivity implements DeliveryAc } @Override - public double getTheoreticalEarliestOperationStartTime() { - return theoreticalEarliest; - } + public void setTheoreticalEarliestOperationStartTime(double earliest) { + theoreticalEarliest = earliest; + } - @Override - public double getTheoreticalLatestOperationStartTime() { - return theoreticalLatest; - } + @Override + public void setTheoreticalLatestOperationStartTime(double latest) { + theoreticalLatest = latest; + } - @Override - public double getOperationTime() { - return delivery.getServiceDuration(); - } + @Override + public List getTimeWindows() { + return timeWindows; + } - @Override - public double getArrTime() { - return arrTime; - } + @Override + public double getTheoreticalEarliestOperationStartTime() { + return theoreticalEarliest; + } - @Override - public double getEndTime() { - return endTime; - } + @Override + public double getTheoreticalLatestOperationStartTime() { + return theoreticalLatest; + } - @Override - public void setArrTime(double arrTime) { - this.arrTime=arrTime; - } + @Override + public double getOperationTime() { + return delivery.getServiceDuration(); + } - @Override - public void setEndTime(double endTime) { - this.endTime=endTime; - } + @Override + public double getArrTime() { + return arrTime; + } - @Override - public TourActivity duplicate() { - return new DeliverService(this); - } + @Override + public double getEndTime() { + return endTime; + } - @Override - public Delivery getJob() { - return delivery; - } + @Override + public void setArrTime(double arrTime) { + this.arrTime = arrTime; + } - public String toString() { - return "[type="+getName()+"][locationId=" + getLocationId() - + "][size=" + getSize().toString() - + "][twStart=" + Activities.round(getTheoreticalEarliestOperationStartTime()) - + "][twEnd=" + Activities.round(getTheoreticalLatestOperationStartTime()) + "]"; - } + @Override + public void setEndTime(double endTime) { + this.endTime = endTime; + } - @Override - public Capacity getSize() { - return capacity; - } + @Override + public TourActivity duplicate() { + return new DeliverService(this); + } + + @Override + public Delivery getJob() { + return delivery; + } + + public String toString() { + return "[type=" + getName() + "][locationId=" + getLocationId() + + "][size=" + getSize().toString() + + "][twStart=" + Activities.round(getTheoreticalEarliestOperationStartTime()) + + "][twEnd=" + Activities.round(getTheoreticalLatestOperationStartTime()) + "]"; + } + + @Override + public Capacity getSize() { + return capacity; + } } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/DeliverShipment.java b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/DeliverShipment.java index 5bd67dbd..19f6688f 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/DeliverShipment.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/DeliverShipment.java @@ -24,61 +24,61 @@ import jsprit.core.problem.job.Shipment; import java.util.List; -public final class DeliverShipment extends AbstractActivity implements DeliveryActivity{ +public final class DeliverShipment extends AbstractActivity implements DeliveryActivity { - private Shipment shipment; - - private double endTime; - - private double arrTime; - - private Capacity capacity; - - public DeliverShipment(Shipment shipment) { - super(); - this.shipment = shipment; - this.capacity = Capacity.invert(shipment.getSize()); - } + private Shipment shipment; + + private double endTime; + + private double arrTime; + + private Capacity capacity; + + public DeliverShipment(Shipment shipment) { + super(); + this.shipment = shipment; + this.capacity = Capacity.invert(shipment.getSize()); + } @Deprecated - public DeliverShipment(DeliverShipment deliveryShipmentActivity) { - this.shipment = (Shipment) deliveryShipmentActivity.getJob(); - this.arrTime = deliveryShipmentActivity.getArrTime(); - this.endTime = deliveryShipmentActivity.getEndTime(); - this.capacity = deliveryShipmentActivity.getSize(); + public DeliverShipment(DeliverShipment deliveryShipmentActivity) { + this.shipment = (Shipment) deliveryShipmentActivity.getJob(); + this.arrTime = deliveryShipmentActivity.getArrTime(); + this.endTime = deliveryShipmentActivity.getEndTime(); + this.capacity = deliveryShipmentActivity.getSize(); setIndex(deliveryShipmentActivity.getIndex()); - } + } - @Override - public Job getJob() { - return shipment; - } + @Override + public Job getJob() { + return shipment; + } - @Override - public void setTheoreticalEarliestOperationStartTime(double earliest) { + @Override + public void setTheoreticalEarliestOperationStartTime(double earliest) { - } + } - @Override - public void setTheoreticalLatestOperationStartTime(double latest) { + @Override + public void setTheoreticalLatestOperationStartTime(double latest) { - } + } - @Override - public List getTimeWindows() { + @Override + public List getTimeWindows() { // return shipment.getDeliveryTimeWindow(); - return null; - } + return null; + } - @Override - public String getName() { - return "deliverShipment"; - } + @Override + public String getName() { + return "deliverShipment"; + } - @Override - public String getLocationId() { - return shipment.getDeliveryLocation().getId(); - } + @Override + public String getLocationId() { + return shipment.getDeliveryLocation().getId(); + } @Override public Location getLocation() { @@ -86,54 +86,54 @@ public final class DeliverShipment extends AbstractActivity implements DeliveryA } @Override - public double getTheoreticalEarliestOperationStartTime() { - return shipment.getDeliveryTimeWindow().getStart(); - } + public double getTheoreticalEarliestOperationStartTime() { + return shipment.getDeliveryTimeWindow().getStart(); + } - @Override - public double getTheoreticalLatestOperationStartTime() { - return shipment.getDeliveryTimeWindow().getEnd(); - } + @Override + public double getTheoreticalLatestOperationStartTime() { + return shipment.getDeliveryTimeWindow().getEnd(); + } - @Override - public double getOperationTime() { - return shipment.getDeliveryServiceTime(); - } + @Override + public double getOperationTime() { + return shipment.getDeliveryServiceTime(); + } - @Override - public double getArrTime() { - return arrTime; - } + @Override + public double getArrTime() { + return arrTime; + } - @Override - public double getEndTime() { - return endTime; - } + @Override + public double getEndTime() { + return endTime; + } - @Override - public void setArrTime(double arrTime) { - this.arrTime=arrTime; - } + @Override + public void setArrTime(double arrTime) { + this.arrTime = arrTime; + } - @Override - public void setEndTime(double endTime) { - this.endTime=endTime; - } + @Override + public void setEndTime(double endTime) { + this.endTime = endTime; + } - @Override - public TourActivity duplicate() { - return new DeliverShipment(this); - } - - public String toString() { - return "[type="+getName()+"][locationId=" + getLocationId() - + "][size=" + getSize().toString() - + "][twStart=" + Activities.round(getTheoreticalEarliestOperationStartTime()) - + "][twEnd=" + Activities.round(getTheoreticalLatestOperationStartTime()) + "]"; - } + @Override + public TourActivity duplicate() { + return new DeliverShipment(this); + } - @Override - public Capacity getSize() { - return capacity; - } + public String toString() { + return "[type=" + getName() + "][locationId=" + getLocationId() + + "][size=" + getSize().toString() + + "][twStart=" + Activities.round(getTheoreticalEarliestOperationStartTime()) + + "][twEnd=" + Activities.round(getTheoreticalLatestOperationStartTime()) + "]"; + } + + @Override + public Capacity getSize() { + return capacity; + } } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/DeliveryActivity.java b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/DeliveryActivity.java index f845c7a1..958ea785 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/DeliveryActivity.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/DeliveryActivity.java @@ -1,24 +1,24 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.problem.solution.route.activity; import jsprit.core.problem.solution.route.activity.TourActivity.JobActivity; -public interface DeliveryActivity extends JobActivity{ +public interface DeliveryActivity extends JobActivity { + - } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/End.java b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/End.java index 80637322..9d803069 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/End.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/End.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.problem.solution.route.activity; @@ -27,115 +27,115 @@ import java.util.List; public final class End extends AbstractActivity implements TourActivity { @Deprecated - public static int creation = 0; - - public static End newInstance(String locationId, double earliestArrival, double latestArrival) { - creation++; - return new End(locationId,earliestArrival,latestArrival); - } - - public static End copyOf(End end){ - return new End(end); - } + public static int creation = 0; - private final static Capacity capacity = Capacity.Builder.newInstance().build(); + public static End newInstance(String locationId, double earliestArrival, double latestArrival) { + creation++; + return new End(locationId, earliestArrival, latestArrival); + } - private Coordinate coordinate; + public static End copyOf(End end) { + return new End(end); + } + + private final static Capacity capacity = Capacity.Builder.newInstance().build(); + + private Coordinate coordinate; @Deprecated - Coordinate getCoordinate() { - return coordinate; - } + Coordinate getCoordinate() { + return coordinate; + } @Deprecated - void setCoordinate(Coordinate coordinate) { - this.coordinate = coordinate; - } + void setCoordinate(Coordinate coordinate) { + this.coordinate = coordinate; + } - private double endTime = -1; - + private double endTime = -1; - private double theoretical_earliestOperationStartTime; - - private double theoretical_latestOperationStartTime; - private double arrTime; + private double theoretical_earliestOperationStartTime; + + private double theoretical_latestOperationStartTime; + + private double arrTime; private Location location; - public void setTheoreticalEarliestOperationStartTime(double theoreticalEarliestOperationStartTime) { - theoretical_earliestOperationStartTime = theoreticalEarliestOperationStartTime; - } + public void setTheoreticalEarliestOperationStartTime(double theoreticalEarliestOperationStartTime) { + theoretical_earliestOperationStartTime = theoreticalEarliestOperationStartTime; + } - public void setTheoreticalLatestOperationStartTime(double theoreticalLatestOperationStartTime) { - theoretical_latestOperationStartTime = theoreticalLatestOperationStartTime; - } + public void setTheoreticalLatestOperationStartTime(double theoreticalLatestOperationStartTime) { + theoretical_latestOperationStartTime = theoreticalLatestOperationStartTime; + } - @Override - public List getTimeWindows() { - return Arrays.asList(TimeWindow.newInstance(theoretical_earliestOperationStartTime,theoretical_latestOperationStartTime)); - } + @Override + public List getTimeWindows() { + return Arrays.asList(TimeWindow.newInstance(theoretical_earliestOperationStartTime,theoretical_latestOperationStartTime)); + } - public End(Location location, double theoreticalStart, double theoreticalEnd) { - super(); - this.location = location; - theoretical_earliestOperationStartTime = theoreticalStart; - theoretical_latestOperationStartTime = theoreticalEnd; - endTime = theoreticalEnd; - setIndex(-2); - } - - public End(String locationId, double theoreticalStart, double theoreticalEnd) { + public End(Location location, double theoreticalStart, double theoreticalEnd) { super(); - if(locationId != null) this.location = Location.Builder.newInstance().setId(locationId).build(); + this.location = location; theoretical_earliestOperationStartTime = theoreticalStart; theoretical_latestOperationStartTime = theoreticalEnd; endTime = theoreticalEnd; setIndex(-2); } - public End(End end) { + public End(String locationId, double theoreticalStart, double theoreticalEnd) { + super(); + if (locationId != null) this.location = Location.Builder.newInstance().setId(locationId).build(); + theoretical_earliestOperationStartTime = theoreticalStart; + theoretical_latestOperationStartTime = theoreticalEnd; + endTime = theoreticalEnd; + setIndex(-2); + } + + public End(End end) { this.location = end.getLocation(); // this.locationId = end.getLocation().getId(); - theoretical_earliestOperationStartTime = end.getTheoreticalEarliestOperationStartTime(); - theoretical_latestOperationStartTime = end.getTheoreticalLatestOperationStartTime(); - arrTime = end.getArrTime(); - endTime = end.getEndTime(); + theoretical_earliestOperationStartTime = end.getTheoreticalEarliestOperationStartTime(); + theoretical_latestOperationStartTime = end.getTheoreticalLatestOperationStartTime(); + arrTime = end.getArrTime(); + endTime = end.getEndTime(); setIndex(-2); - } + } - public double getTheoreticalEarliestOperationStartTime() { - return theoretical_earliestOperationStartTime; - } + public double getTheoreticalEarliestOperationStartTime() { + return theoretical_earliestOperationStartTime; + } - public double getTheoreticalLatestOperationStartTime() { - return theoretical_latestOperationStartTime; - } + public double getTheoreticalLatestOperationStartTime() { + return theoretical_latestOperationStartTime; + } - public double getEndTime() { - return endTime; - } + public double getEndTime() { + return endTime; + } - public void setEndTime(double endTime) { - this.endTime = endTime; - } + public void setEndTime(double endTime) { + this.endTime = endTime; + } @Deprecated - public void setLocationId(String locationId) { - if(locationId == null) return; + public void setLocationId(String locationId) { + if (locationId == null) return; this.location = Location.Builder.newInstance().setId(locationId).build(); - } + } - public void setLocation(Location location){ + public void setLocation(Location location) { this.location = location; } @Deprecated - @Override - public String getLocationId() { - if(location == null) return null; + @Override + public String getLocationId() { + if (location == null) return null; return location.getId(); - } + } @Override public Location getLocation() { @@ -143,43 +143,42 @@ public final class End extends AbstractActivity implements TourActivity { } @Override - public double getOperationTime() { - return 0.0; - } + public double getOperationTime() { + return 0.0; + } - @Override - public String toString() { - return "[type="+getName()+"][location=" + location - + "][twStart=" + Activities.round(theoretical_earliestOperationStartTime) - + "][twEnd=" + Activities.round(theoretical_latestOperationStartTime) + "]"; - } + @Override + public String toString() { + return "[type=" + getName() + "][location=" + location + + "][twStart=" + Activities.round(theoretical_earliestOperationStartTime) + + "][twEnd=" + Activities.round(theoretical_latestOperationStartTime) + "]"; + } + @Override + public String getName() { + return "end"; + } - @Override - public String getName() { - return "end"; - } + @Override + public double getArrTime() { + return this.arrTime; + } - @Override - public double getArrTime() { - return this.arrTime; - } + @Override + public void setArrTime(double arrTime) { + this.arrTime = arrTime; - @Override - public void setArrTime(double arrTime) { - this.arrTime = arrTime; - - } + } - @Override - public TourActivity duplicate() { - return new End(this); - } + @Override + public TourActivity duplicate() { + return new End(this); + } - @Override - public Capacity getSize() { - return capacity; - } + @Override + public Capacity getSize() { + return capacity; + } } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/PickupActivity.java b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/PickupActivity.java index 64ed2595..44de9b0c 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/PickupActivity.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/PickupActivity.java @@ -1,24 +1,24 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.problem.solution.route.activity; import jsprit.core.problem.solution.route.activity.TourActivity.JobActivity; -public interface PickupActivity extends JobActivity{ - - +public interface PickupActivity extends JobActivity { + + } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/PickupService.java b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/PickupService.java index 6b9698a3..03768933 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/PickupService.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/PickupService.java @@ -25,64 +25,49 @@ import jsprit.core.problem.job.Service; import java.util.ArrayList; import java.util.List; -public final class PickupService extends AbstractActivity implements PickupActivity{ - - private Service pickup; - - private double arrTime; - - private double depTime; +public final class PickupService extends AbstractActivity implements PickupActivity { - private double theoreticalEarliest; + private Service pickup; - private double theoreticalLatest; + private double arrTime; - private List timeWindows; - - public PickupService(Pickup pickup) { - super(); - this.pickup = pickup; - timeWindows = new ArrayList(pickup.getTimeWindows(0.)); - } - - public PickupService(Service service){ - this.pickup = service; - } - - private PickupService(PickupService pickupActivity){ - this.pickup=pickupActivity.getJob(); - this.arrTime=pickupActivity.getArrTime(); - this.depTime=pickupActivity.getEndTime(); - this.theoreticalEarliest = pickupActivity.getTheoreticalEarliestOperationStartTime(); - this.theoreticalLatest = pickupActivity.getTheoreticalLatestOperationStartTime(); + private double depTime; + + private double theoreticalEarliest; + + private double theoreticalLatest; + + private List timeWindows; + + + public PickupService(Pickup pickup) { + super(); + this.pickup = pickup; + timeWindows = new ArrayList(pickup.getTimeWindows(0.)); + } + + public PickupService(Service service) { + this.pickup = service; + timeWindows = new ArrayList(service.getTimeWindows(0.)); + } + + private PickupService(PickupService pickupActivity) { + this.pickup = pickupActivity.getJob(); + this.arrTime = pickupActivity.getArrTime(); + this.depTime = pickupActivity.getEndTime(); setIndex(pickupActivity.getIndex()); - timeWindows = new ArrayList(pickup.getTimeWindows(0.)); - } + timeWindows = new ArrayList(pickup.getTimeWindows(0.)); + } - @Override - public void setTheoreticalEarliestOperationStartTime(double earliest) { - this.theoreticalEarliest = earliest; - } + @Override + public String getName() { + return pickup.getType(); + } - @Override - public void setTheoreticalLatestOperationStartTime(double latest) { - this.theoreticalLatest = latest; - } - - @Override - public List getTimeWindows() { - return timeWindows; - } - - @Override - public String getName() { - return pickup.getType(); - } - - @Override - public String getLocationId() { - return pickup.getLocation().getId(); - } + @Override + public String getLocationId() { + return pickup.getLocation().getId(); + } @Override public Location getLocation() { @@ -90,60 +75,75 @@ public final class PickupService extends AbstractActivity implements PickupActiv } @Override - public double getTheoreticalEarliestOperationStartTime() { - return theoreticalEarliest; - } + public double getTheoreticalEarliestOperationStartTime() { + return theoreticalEarliest; + } - @Override - public double getTheoreticalLatestOperationStartTime() { - return theoreticalLatest; - } + @Override + public double getTheoreticalLatestOperationStartTime() { + return theoreticalLatest; + } - @Override - public double getOperationTime() { - return pickup.getServiceDuration(); - } + @Override + public void setTheoreticalEarliestOperationStartTime(double earliest) { + this.theoreticalEarliest = earliest; + } - @Override - public double getArrTime() { - return arrTime; - } + @Override + public void setTheoreticalLatestOperationStartTime(double latest) { + this.theoreticalLatest = latest; + } - @Override - public double getEndTime() { - return depTime; - } + @Override + public List getTimeWindows() { + return timeWindows; + } - @Override - public void setArrTime(double arrTime) { - this.arrTime=arrTime; - } + @Override + public double getOperationTime() { + return pickup.getServiceDuration(); + } - @Override - public void setEndTime(double endTime) { - this.depTime=endTime; - } + @Override + public double getArrTime() { + return arrTime; + } - @Override - public TourActivity duplicate() { - return new PickupService(this); - } + @Override + public double getEndTime() { + return depTime; + } - @Override - public Service getJob() { - return pickup; - } + @Override + public void setArrTime(double arrTime) { + this.arrTime = arrTime; + } - public String toString() { - return "[type="+getName()+"][locationId=" + getLocationId() - + "][size=" + getSize().toString() - + "][twStart=" + Activities.round(getTheoreticalEarliestOperationStartTime()) - + "][twEnd=" + Activities.round(getTheoreticalLatestOperationStartTime()) + "]"; - } + @Override + public void setEndTime(double endTime) { + this.depTime = endTime; + } - @Override - public Capacity getSize() { - return pickup.getSize(); - } + @Override + public TourActivity duplicate() { + return new PickupService(this); + } + + @Override + public Service getJob() { + return pickup; + } + + public String toString() { + return "[type=" + getName() + "][locationId=" + getLocationId() + + "][size=" + getSize().toString() + + "][twStart=" + Activities.round(getTheoreticalEarliestOperationStartTime()) + + "][twEnd=" + Activities.round(getTheoreticalLatestOperationStartTime()) + "]"; + } + + @Override + public Capacity getSize() { + return pickup.getSize(); + } } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/PickupShipment.java b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/PickupShipment.java index c150abc6..55248e08 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/PickupShipment.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/PickupShipment.java @@ -26,54 +26,54 @@ import java.util.List; public final class PickupShipment extends AbstractActivity implements PickupActivity{ - private Shipment shipment; - - private double endTime; - - private double arrTime; - - public PickupShipment(Shipment shipment) { - super(); - this.shipment = shipment; - } + private Shipment shipment; + + private double endTime; + + private double arrTime; + + public PickupShipment(Shipment shipment) { + super(); + this.shipment = shipment; + } @Deprecated - public PickupShipment(PickupShipment pickupShipmentActivity) { - this.shipment = (Shipment) pickupShipmentActivity.getJob(); - this.arrTime = pickupShipmentActivity.getArrTime(); - this.endTime = pickupShipmentActivity.getEndTime(); + public PickupShipment(PickupShipment pickupShipmentActivity) { + this.shipment = (Shipment) pickupShipmentActivity.getJob(); + this.arrTime = pickupShipmentActivity.getArrTime(); + this.endTime = pickupShipmentActivity.getEndTime(); setIndex(pickupShipmentActivity.getIndex()); - } + } - @Override - public Job getJob() { - return shipment; - } + @Override + public Job getJob() { + return shipment; + } - @Override - public void setTheoreticalEarliestOperationStartTime(double earliest) { + @Override + public void setTheoreticalEarliestOperationStartTime(double earliest) { - } + } - @Override - public void setTheoreticalLatestOperationStartTime(double latest) { + @Override + public void setTheoreticalLatestOperationStartTime(double latest) { - } + } - @Override - public List getTimeWindows() { - return null; - } + @Override + public List getTimeWindows() { + return null; + } - @Override - public String getName() { - return "pickupShipment"; - } + @Override + public String getName() { + return "pickupShipment"; + } - @Override - public String getLocationId() { - return shipment.getPickupLocation().getId(); - } + @Override + public String getLocationId() { + return shipment.getPickupLocation().getId(); + } @Override public Location getLocation() { @@ -81,57 +81,56 @@ public final class PickupShipment extends AbstractActivity implements PickupActi } @Override - public double getTheoreticalEarliestOperationStartTime() { - return shipment.getPickupTimeWindow().getStart(); - } + public double getTheoreticalEarliestOperationStartTime() { + return shipment.getPickupTimeWindow().getStart(); + } - @Override - public double getTheoreticalLatestOperationStartTime() { - return shipment.getPickupTimeWindow().getEnd(); - } + @Override + public double getTheoreticalLatestOperationStartTime() { + return shipment.getPickupTimeWindow().getEnd(); + } - @Override - public double getOperationTime() { - return shipment.getPickupServiceTime(); - } + @Override + public double getOperationTime() { + return shipment.getPickupServiceTime(); + } - @Override - public double getArrTime() { - return arrTime; - } + @Override + public double getArrTime() { + return arrTime; + } - @Override - public double getEndTime() { - return endTime; - } + @Override + public double getEndTime() { + return endTime; + } - @Override - public void setArrTime(double arrTime) { - this.arrTime=arrTime; - } + @Override + public void setArrTime(double arrTime) { + this.arrTime = arrTime; + } - @Override - public void setEndTime(double endTime) { - this.endTime=endTime; - } + @Override + public void setEndTime(double endTime) { + this.endTime = endTime; + } - @Override - public TourActivity duplicate() { - return new PickupShipment(this); - } - - public String toString() { - return "[type="+getName()+"][locationId=" + getLocationId() - + "][size=" + getSize().toString() - + "][twStart=" + Activities.round(getTheoreticalEarliestOperationStartTime()) - + "][twEnd=" + Activities.round(getTheoreticalLatestOperationStartTime()) + "]"; - } + @Override + public TourActivity duplicate() { + return new PickupShipment(this); + } - @Override - public Capacity getSize() { - return shipment.getSize(); - } + public String toString() { + return "[type=" + getName() + "][locationId=" + getLocationId() + + "][size=" + getSize().toString() + + "][twStart=" + Activities.round(getTheoreticalEarliestOperationStartTime()) + + "][twEnd=" + Activities.round(getTheoreticalLatestOperationStartTime()) + "]"; + } + @Override + public Capacity getSize() { + return shipment.getSize(); + } } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/ReverseActivityVisitor.java b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/ReverseActivityVisitor.java index ec1c3fc5..c9706204 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/ReverseActivityVisitor.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/ReverseActivityVisitor.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.problem.solution.route.activity; @@ -20,11 +20,11 @@ import jsprit.core.problem.solution.route.VehicleRoute; public interface ReverseActivityVisitor { - - public void begin(VehicleRoute route); - - public void visit(TourActivity activity); - - public void finish(); + + public void begin(VehicleRoute route); + + public void visit(TourActivity activity); + + public void finish(); } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/ServiceActivity.java b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/ServiceActivity.java index 7cb405bd..33703b87 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/ServiceActivity.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/ServiceActivity.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.problem.solution.route.activity; @@ -25,123 +25,139 @@ import jsprit.core.problem.solution.route.activity.TourActivity.JobActivity; import java.util.ArrayList; import java.util.List; -public class ServiceActivity extends AbstractActivity implements JobActivity{ - - @Deprecated - public static int counter = 0; - - public double arrTime; - - public double endTime; +public class ServiceActivity extends AbstractActivity implements JobActivity { - private double theoreticalEarliest; + @Deprecated + public static int counter = 0; - private double theoreticalLatest; - /** - * @return the arrTime - */ - public double getArrTime() { - return arrTime; - } + public double arrTime; - /** - * @param arrTime the arrTime to set - */ - public void setArrTime(double arrTime) { - this.arrTime = arrTime; - } + public double endTime; - /** - * @return the endTime - */ - public double getEndTime() { - return endTime; - } + private double theoreticalEarliest; - /** - * @param endTime the endTime to set - */ - public void setEndTime(double endTime) { - this.endTime = endTime; - } + private double theoreticalLatest; - public static ServiceActivity copyOf(ServiceActivity serviceActivity){ - return new ServiceActivity(serviceActivity); - } - - public static ServiceActivity newInstance(Service service){ - return new ServiceActivity(service); - } + /** + * @return the arrTime + */ + public double getArrTime() { + return arrTime; + } - - private final Service service; + /** + * @param arrTime the arrTime to set + */ + public void setArrTime(double arrTime) { + this.arrTime = arrTime; + } - private List timeWindows; - - protected ServiceActivity(Service service) { - counter++; - this.service = service; - timeWindows = new ArrayList(service.getTimeWindows(0.)); - } - - protected ServiceActivity(ServiceActivity serviceActivity) { - counter++; - this.service = serviceActivity.getJob(); - this.arrTime = serviceActivity.getArrTime(); - this.endTime = serviceActivity.getEndTime(); + /** + * @return the endTime + */ + public double getEndTime() { + return endTime; + } + + /** + * @param endTime the endTime to set + */ + public void setEndTime(double endTime) { + this.endTime = endTime; + } + + public static ServiceActivity copyOf(ServiceActivity serviceActivity) { + return new ServiceActivity(serviceActivity); + } + + public static ServiceActivity newInstance(Service service) { + return new ServiceActivity(service); + } + + + private final Service service; + + private List timeWindows; + + protected ServiceActivity(Service service) { + counter++; + this.service = service; + timeWindows = new ArrayList(service.getTimeWindows(0.)); + } + + protected ServiceActivity(ServiceActivity serviceActivity) { + counter++; + this.service = serviceActivity.getJob(); + this.arrTime = serviceActivity.getArrTime(); + this.endTime = serviceActivity.getEndTime(); setIndex(serviceActivity.getIndex()); - timeWindows = new ArrayList(serviceActivity.getTimeWindows()); - } - - - /* (non-Javadoc) - * @see java.lang.Object#hashCode() - */ - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((service == null) ? 0 : service.hashCode()); - return result; - } + timeWindows = new ArrayList(serviceActivity.getTimeWindows()); + } - /* (non-Javadoc) - * @see java.lang.Object#equals(java.lang.Object) - */ - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - ServiceActivity other = (ServiceActivity) obj; - if (service == null) { - if (other.service != null) - return false; - } else if (!service.equals(other.service)) - return false; - return true; - } - public double getTheoreticalEarliestOperationStartTime() { - return theoreticalEarliest; - } + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((service == null) ? 0 : service.hashCode()); + return result; + } - public double getTheoreticalLatestOperationStartTime() { - return theoreticalLatest; - } + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ServiceActivity other = (ServiceActivity) obj; + if (service == null) { + if (other.service != null) + return false; + } else if (!service.equals(other.service)) + return false; + return true; + } - @Override - public double getOperationTime() { - return service.getServiceDuration(); - } + public double getTheoreticalEarliestOperationStartTime() { + return theoreticalEarliest; + } - @Override - public String getLocationId() { - return service.getLocation().getId(); - } + public double getTheoreticalLatestOperationStartTime() { + return theoreticalLatest; + } + + @Override + public void setTheoreticalEarliestOperationStartTime(double earliest) { + theoreticalEarliest = earliest; + } + + @Override + public void setTheoreticalLatestOperationStartTime(double latest) { + theoreticalLatest = latest; + } + + @Override + public List getTimeWindows() { + return timeWindows; + } + + @Override + public double getOperationTime() { + return service.getServiceDuration(); + } + + @Override + public String getLocationId() { + return service.getLocation().getId(); + } @Override public Location getLocation() { @@ -150,49 +166,33 @@ public class ServiceActivity extends AbstractActivity implements JobActivity{ @Override - public Service getJob() { - return service; - } + public Service getJob() { + return service; + } - - @Override - public String toString() { - return "[type="+getName()+"][locationId=" + getLocationId() - + "][size=" + getSize().toString() - + "][twStart=" + Activities.round(getTheoreticalEarliestOperationStartTime()) - + "][twEnd=" + Activities.round(getTheoreticalLatestOperationStartTime()) + "]"; - } - @Override - public void setTheoreticalEarliestOperationStartTime(double earliest) { - theoreticalEarliest = earliest; - } + @Override + public String toString() { + return "[type=" + getName() + "][locationId=" + getLocationId() + + "][size=" + getSize().toString() + + "][twStart=" + Activities.round(getTheoreticalEarliestOperationStartTime()) + + "][twEnd=" + Activities.round(getTheoreticalLatestOperationStartTime()) + "]"; + } - @Override - public void setTheoreticalLatestOperationStartTime(double latest) { - theoreticalLatest = latest; - } + @Override + public String getName() { + return service.getType(); + } - @Override - public List getTimeWindows() { - return timeWindows; - } + @Override + public TourActivity duplicate() { + return new ServiceActivity(this); + } - @Override - public String getName() { - return service.getType(); - } + @Override + public Capacity getSize() { + return service.getSize(); + } - @Override - public TourActivity duplicate() { - return new ServiceActivity(this); - } - - @Override - public Capacity getSize() { - return service.getSize(); - } - - } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/Start.java b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/Start.java index 000f423f..dd70e307 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/Start.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/Start.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.problem.solution.route.activity; @@ -25,43 +25,43 @@ import java.util.List; public final class Start extends AbstractActivity implements TourActivity { - public final static String ACTIVITY_NAME = "start"; + public final static String ACTIVITY_NAME = "start"; @Deprecated - public static int creation; - - private final static Capacity capacity = Capacity.Builder.newInstance().build(); - - public static Start newInstance(String locationId, double theoreticalStart, double theoreticalEnd){ - creation++; - return new Start(locationId,theoreticalStart,theoreticalEnd); - } - - public static Start copyOf(Start start){ - return new Start(start); - } - - private String locationId; - - private double theoretical_earliestOperationStartTime; - - private double theoretical_latestOperationStartTime; + public static int creation; - private double endTime; + private final static Capacity capacity = Capacity.Builder.newInstance().build(); - private double arrTime; + public static Start newInstance(String locationId, double theoreticalStart, double theoreticalEnd) { + creation++; + return new Start(locationId, theoreticalStart, theoreticalEnd); + } + + public static Start copyOf(Start start) { + return new Start(start); + } + + private String locationId; + + private double theoretical_earliestOperationStartTime; + + private double theoretical_latestOperationStartTime; + + private double endTime; + + private double arrTime; private Location location; @Deprecated - public Start(String locationId, double theoreticalStart, double theoreticalEnd) { - super(); - if(locationId != null) this.location = Location.Builder.newInstance().setId(locationId).build(); - this.theoretical_earliestOperationStartTime = theoreticalStart; - this.theoretical_latestOperationStartTime = theoreticalEnd; - this.endTime = theoreticalStart; + public Start(String locationId, double theoreticalStart, double theoreticalEnd) { + super(); + if (locationId != null) this.location = Location.Builder.newInstance().setId(locationId).build(); + this.theoretical_earliestOperationStartTime = theoreticalStart; + this.theoretical_latestOperationStartTime = theoreticalEnd; + this.endTime = theoreticalStart; setIndex(-1); - } + } public Start(Location location, double theoreticalStart, double theoreticalEnd) { super(); @@ -72,51 +72,56 @@ public final class Start extends AbstractActivity implements TourActivity { setIndex(-1); } - private Start(Start start) { - this.location = start.getLocation(); - theoretical_earliestOperationStartTime = start.getTheoreticalEarliestOperationStartTime(); - theoretical_latestOperationStartTime = start.getTheoreticalLatestOperationStartTime(); - endTime = start.getEndTime(); + private Start(Start start) { + this.location = start.getLocation(); + theoretical_earliestOperationStartTime = start.getTheoreticalEarliestOperationStartTime(); + theoretical_latestOperationStartTime = start.getTheoreticalLatestOperationStartTime(); + endTime = start.getEndTime(); setIndex(-1); - } + } - public double getTheoreticalEarliestOperationStartTime() { - return theoretical_earliestOperationStartTime; - } + public double getTheoreticalEarliestOperationStartTime() { + return theoretical_earliestOperationStartTime; + } @Deprecated - public void setLocationId(String locationId) { - if(locationId == null) return; + public void setLocationId(String locationId) { + if (locationId == null) return; this.location = Location.Builder.newInstance().setId(locationId).build(); - } + } - public void setLocation(Location location) { this.location = location; }; + public void setLocation(Location location) { + this.location = location; + } - public double getTheoreticalLatestOperationStartTime() { - return theoretical_latestOperationStartTime; - } + ; - @Deprecated - public void setTheoreticalEarliestOperationStartTime(double time) { - this.theoretical_earliestOperationStartTime=time; - } + public double getTheoreticalLatestOperationStartTime() { + return theoretical_latestOperationStartTime; + } - @Deprecated - public void setTheoreticalLatestOperationStartTime(double time) { - this.theoretical_latestOperationStartTime=time; - } + @Deprecated + public void setTheoreticalEarliestOperationStartTime(double time) { + this.theoretical_earliestOperationStartTime = time; + } - @Override - public List getTimeWindows() { - return Arrays.asList(TimeWindow.newInstance(theoretical_earliestOperationStartTime,theoretical_latestOperationStartTime)); - } + @Deprecated + public void setTheoreticalLatestOperationStartTime(double time) { + this.theoretical_latestOperationStartTime = time; + } - @Deprecated - @Override - public String getLocationId() { - if(location == null) return null; + @Override + public List getTimeWindows() { + return Arrays.asList(TimeWindow.newInstance(theoretical_earliestOperationStartTime,theoretical_latestOperationStartTime)); + } + + + @Deprecated + @Override + public String getLocationId() { + if (location == null) return null; return location.getId(); - } + } @Override public Location getLocation() { @@ -124,50 +129,50 @@ public final class Start extends AbstractActivity implements TourActivity { } @Override - public double getOperationTime() { - return 0.0; - } + public double getOperationTime() { + return 0.0; + } - @Override - public String toString() { - return "[type="+getName()+"][location=" + location - + "][twStart=" + Activities.round(theoretical_earliestOperationStartTime) - + "][twEnd=" + Activities.round(theoretical_latestOperationStartTime) + "]"; - } + @Override + public String toString() { + return "[type=" + getName() + "][location=" + location + + "][twStart=" + Activities.round(theoretical_earliestOperationStartTime) + + "][twEnd=" + Activities.round(theoretical_latestOperationStartTime) + "]"; + } - @Override - public String getName() { - return "start"; - } + @Override + public String getName() { + return "start"; + } - @Override - public double getArrTime() { - return arrTime; - } + @Override + public double getArrTime() { + return arrTime; + } - @Override - public double getEndTime() { - return endTime; - } + @Override + public double getEndTime() { + return endTime; + } - @Override - public void setArrTime(double arrTime) { - this.arrTime = arrTime; - } + @Override + public void setArrTime(double arrTime) { + this.arrTime = arrTime; + } - @Override - public void setEndTime(double endTime) { - this.endTime = endTime; - } + @Override + public void setEndTime(double endTime) { + this.endTime = endTime; + } - @Override - public TourActivity duplicate() { - return new Start(this); - } + @Override + public TourActivity duplicate() { + return new Start(this); + } - @Override - public Capacity getSize() { - return capacity; - } + @Override + public Capacity getSize() { + return capacity; + } } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/TimeWindow.java b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/TimeWindow.java index 138414f3..933956ec 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/TimeWindow.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/TimeWindow.java @@ -1,114 +1,115 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.problem.solution.route.activity; /** * TimeWindow consists of a startTime and endTime. - * + * * @author stefan schroeder - * */ public class TimeWindow { - - /** - * Returns new instance of TimeWindow. - * - * @param start - * @param end - * @return TimeWindow - * @throw IllegalArgumentException either if start or end < 0.0 or end < start - */ - public static TimeWindow newInstance(double start, double end){ - return new TimeWindow(start,end); - } - - private final double start; - private final double end; - /** - * Constructs the timeWindow - * - * @param start - * @param end - * @throw IllegalArgumentException either if start or end < 0.0 or end < start - */ - public TimeWindow(double start, double end) { - super(); - if(start < 0.0 || end < 0.0) throw new IllegalArgumentException("neither start nor end must be < 0.0"); - if(end < start) throw new IllegalArgumentException("end cannot be smaller than start"); - this.start = start; - this.end = end; - } + /** + * Returns new instance of TimeWindow. + * + * @param start + * @param end + * @return TimeWindow + * @throw IllegalArgumentException either if start or end < 0.0 or end < start + */ + public static TimeWindow newInstance(double start, double end) { + return new TimeWindow(start, end); + } - /** - * Returns startTime of TimeWindow. - * - * @return startTime - */ - public double getStart() { - return start; - } + private final double start; + private final double end; - /** - * Returns endTime of TimeWindow. - * - * @return endTime - */ - public double getEnd() { - return end; - } + /** + * Constructs the timeWindow + * + * @param start + * @param end + * @throw IllegalArgumentException either if start or end < 0.0 or end < start + */ + public TimeWindow(double start, double end) { + super(); + if (start < 0.0 || end < 0.0) + throw new IllegalArgumentException("neither time window start nor end must be < 0.0: " + "[start=" + start + "][end=" + end + "]"); + if (end < start) + throw new IllegalArgumentException("time window end cannot be smaller than its start: " + "[start=" + start + "][end=" + end + "]"); + this.start = start; + this.end = end; + } - @Override - public String toString() { - return "[start=" + start + "][end=" + end + "]"; - } + /** + * Returns startTime of TimeWindow. + * + * @return startTime + */ + public double getStart() { + return start; + } - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - long temp; - temp = Double.doubleToLongBits(end); - result = prime * result + (int) (temp ^ (temp >>> 32)); - temp = Double.doubleToLongBits(start); - result = prime * result + (int) (temp ^ (temp >>> 32)); - return result; - } + /** + * Returns endTime of TimeWindow. + * + * @return endTime + */ + public double getEnd() { + return end; + } + + @Override + public String toString() { + return "[start=" + start + "][end=" + end + "]"; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + long temp; + temp = Double.doubleToLongBits(end); + result = prime * result + (int) (temp ^ (temp >>> 32)); + temp = Double.doubleToLongBits(start); + result = prime * result + (int) (temp ^ (temp >>> 32)); + return result; + } + + /** + * Two timeWindows are equal if they have the same start AND endTime. + */ + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + TimeWindow other = (TimeWindow) obj; + if (Double.doubleToLongBits(end) != Double.doubleToLongBits(other.end)) + return false; + if (Double.doubleToLongBits(start) != Double + .doubleToLongBits(other.start)) + return false; + return true; + } - /** - * Two timeWindows are equal if they have the same start AND endTime. - */ - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - TimeWindow other = (TimeWindow) obj; - if (Double.doubleToLongBits(end) != Double.doubleToLongBits(other.end)) - return false; - if (Double.doubleToLongBits(start) != Double - .doubleToLongBits(other.start)) - return false; - return true; - } - } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/TourActivities.java b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/TourActivities.java index c543475c..946dbe73 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/TourActivities.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/TourActivities.java @@ -11,155 +11,140 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.problem.solution.route.activity; import jsprit.core.problem.job.Job; +import jsprit.core.problem.job.Service; import jsprit.core.problem.solution.route.activity.TourActivity.JobActivity; import java.util.*; - /** - * * @author stefan schroeder - * */ public class TourActivities { - public static TourActivities copyOf(TourActivities tourActivities){ - return new TourActivities(tourActivities); - } + public static TourActivities copyOf(TourActivities tourActivities) { + return new TourActivities(tourActivities); + } public static class ReverseActivityIterator implements Iterator { - private List acts; - private int currentIndex; - - public ReverseActivityIterator(List acts) { - super(); - this.acts = acts; - currentIndex = acts.size()-1; - } + private List acts; + private int currentIndex; - @Override - public boolean hasNext() { - if(currentIndex >= 0) return true; - return false; - } + public ReverseActivityIterator(List acts) { + super(); + this.acts = acts; + currentIndex = acts.size() - 1; + } - @Override - public TourActivity next() { - TourActivity act = acts.get(currentIndex); - currentIndex--; - return act; - } - - public void reset(){ - currentIndex = acts.size()-1; - } + @Override + public boolean hasNext() { + if (currentIndex >= 0) return true; + return false; + } - @Override - public void remove() { - throw new UnsupportedOperationException(); - } - } - + @Override + public TourActivity next() { + TourActivity act = acts.get(currentIndex); + currentIndex--; + return act; + } - public static TourActivities emptyTour(){ - return new TourActivities(); - } - - private final ArrayList tourActivities = new ArrayList(); + public void reset() { + currentIndex = acts.size() - 1; + } - private final Set jobs = new HashSet(); + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + } - private final Set activities = new HashSet(); + private final ArrayList tourActivities = new ArrayList(); - private ReverseActivityIterator backward; - - private TourActivities(TourActivities tour2copy) { - for (TourActivity tourAct : tour2copy.getActivities()) { - TourActivity newAct = tourAct.duplicate(); - this.tourActivities.add(newAct); - addToActivitySet(newAct); + private final Set jobs = new HashSet(); + + private ReverseActivityIterator backward; + + private TourActivities(TourActivities tour2copy) { + for (TourActivity tourAct : tour2copy.getActivities()) { + TourActivity newAct = tourAct.duplicate(); + this.tourActivities.add(newAct); addJob(newAct); - } - } - - private void addToActivitySet(TourActivity newAct) { - activities.add(newAct); + } } - private void removeFromActivitySet(TourActivity act) { - activities.remove(act); + public TourActivities() { + } - public TourActivities(){ - - } - - public List getActivities() { - return Collections.unmodifiableList(tourActivities); - } - - public Iterator iterator(){ - return tourActivities.iterator(); - } + public List getActivities() { + return Collections.unmodifiableList(tourActivities); + } - public boolean isEmpty() { - return (tourActivities.size() == 0); - } - - public Collection getJobs(){ - return Collections.unmodifiableSet(jobs); - } - - /** - * @param job that needs to be looked up - * @return true if job is in jobList, otherwise false. - */ - public boolean servesJob(Job job) { - return jobs.contains(job); - } + public Iterator iterator() { + return tourActivities.iterator(); + } - @Override - public String toString() { - return "[nuOfActivities="+tourActivities.size()+"]"; - } + public boolean isEmpty() { + return (tourActivities.size() == 0); + } - /** - * Removes job AND belonging activity from tour. - * - * @param job to be removed - * @return true if job has been removed, otherwise false. - */ - public boolean removeJob(Job job){ - boolean jobRemoved = false; - if(!jobs.contains(job)){ - return false; - } - else{ - jobRemoved = jobs.remove(job); - } - boolean activityRemoved = false; - List acts = new ArrayList(tourActivities); - for(TourActivity c : acts){ - if(c instanceof JobActivity){ - if(job.equals(((JobActivity) c).getJob())){ - tourActivities.remove(c); - removeFromActivitySet(c); + public Collection getJobs() { + return Collections.unmodifiableSet(jobs); + } + + /** + * @param job that needs to be looked up + * @return true if job is in jobList, otherwise false. + */ + public boolean servesJob(Job job) { + return jobs.contains(job); + } + + @Override + public String toString() { + return "[nuOfActivities=" + tourActivities.size() + "]"; + } + + /** + * Removes job AND belonging activity from tour. + * + * @param job to be removed + * @return true if job has been removed, otherwise false. + */ + public boolean removeJob(Job job) { + boolean jobRemoved = false; + if (!jobs.contains(job)) { + return false; + } else { + jobRemoved = jobs.remove(job); + } + boolean activityRemoved = false; + Iterator iterator = tourActivities.iterator(); + while (iterator.hasNext()) { + TourActivity c = iterator.next(); + if (c instanceof JobActivity) { + Job underlyingJob = ((JobActivity) c).getJob(); + if (job.equals(underlyingJob)) { + iterator.remove(); activityRemoved = true; - } - } - } - assert jobRemoved == activityRemoved : "job removed, but belonging activity not."; - return activityRemoved; - } + if (underlyingJob instanceof Service) { + break; + } + } + } + } + assert jobRemoved == activityRemoved : "job removed, but belonging activity not."; + return activityRemoved; + } /** * Returns true if this contains specified activity. @@ -167,8 +152,9 @@ public class TourActivities { * @param activity to be looked up * @return true if this contains specified activity, false otherwise */ - public boolean hasActivity(TourActivity activity){ - return activities.contains(activity); + @Deprecated + public boolean hasActivity(TourActivity activity) { + return tourActivities.contains(activity); } /** @@ -180,100 +166,95 @@ public class TourActivities { */ public boolean removeActivity(TourActivity activity) { Job job = null; - if(activity instanceof JobActivity){ + if (activity instanceof JobActivity) { job = ((JobActivity) activity).getJob(); } boolean jobIsAlsoAssociateToOtherActs = false; boolean actRemoved = false; List acts = new ArrayList(tourActivities); - for(TourActivity act : acts){ - if(act == activity){ + for (TourActivity act : acts) { + if (act == activity) { tourActivities.remove(act); - removeFromActivitySet(act); actRemoved = true; - } - else{ - if(act instanceof JobActivity && job != null){ - if(((JobActivity) act).getJob().equals(job)){ + } else { + if (act instanceof JobActivity && job != null) { + if (((JobActivity) act).getJob().equals(job)) { jobIsAlsoAssociateToOtherActs = true; } } } } - if(!jobIsAlsoAssociateToOtherActs && actRemoved){ + if (!jobIsAlsoAssociateToOtherActs && actRemoved) { jobs.remove(job); } return actRemoved; } - /** - * Inserts the specified activity add the specified insertionIndex. Shifts the element currently at that position (if any) and - * any subsequent elements to the right (adds one to their indices). - *

If specified activity instanceof JobActivity, it adds job to jobList. - *

If insertionIndex > tourActivitiies.size(), it just adds the specified act at the end. - * - * @param insertionIndex index where activity needs to be inserted - * @param act activity to be inserted - * @throws IndexOutOfBoundsException if insertionIndex < 0; - */ - public void addActivity(int insertionIndex, TourActivity act) { + * Inserts the specified activity add the specified insertionIndex. Shifts the element currently at that position (if any) and + * any subsequent elements to the right (adds one to their indices). + *

If specified activity instanceof JobActivity, it adds job to jobList. + *

If insertionIndex > tourActivitiies.size(), it just adds the specified act at the end. + * + * @param insertionIndex index where activity needs to be inserted + * @param act activity to be inserted + * @throws IndexOutOfBoundsException if insertionIndex < 0; + */ + public void addActivity(int insertionIndex, TourActivity act) { - assert insertionIndex >= 0 : "insertionIndex < 0, this cannot be"; + assert insertionIndex >= 0 : "insertionIndex < 0, this cannot be"; /* - * if 1 --> between start and act(0) --> act(0) + * if 1 --> between start and act(0) --> act(0) * if 2 && 2 <= acts.size --> between act(0) and act(1) --> act(1) * if 2 && 2 > acts.size --> at actEnd * ... - * + * */ - if(insertionIndex < tourActivities.size()) { + if (insertionIndex < tourActivities.size()) { tourActivities.add(insertionIndex, act); - } - else if(insertionIndex >= tourActivities.size()) { + } else if (insertionIndex >= tourActivities.size()) { tourActivities.add(act); } - addToActivitySet(act); addJob(act); - } - - /** - * Adds specified activity at the end of activity-list. - *

If act instanceof JobActivity, it adds underlying job also. - * @throws IllegalStateException if activity-list already contains act. - * @param act to be added - */ - public void addActivity(TourActivity act){ - if(tourActivities.contains(act)) throw new IllegalStateException("act " + act + " already in tour. cannot add act twice."); - tourActivities.add(act); - addToActivitySet(act); + } + + /** + * Adds specified activity at the end of activity-list. + *

If act instanceof JobActivity, it adds underlying job also. + * + * @param act to be added + * @throws IllegalStateException if activity-list already contains act. + */ + public void addActivity(TourActivity act) { + if (tourActivities.contains(act)) + throw new IllegalStateException("act " + act + " already in tour. cannot add act twice."); + tourActivities.add(act); addJob(act); - } + } - private void addJob(TourActivity act) { - if(act instanceof JobActivity){ - Job job = ((JobActivity) act).getJob(); - jobs.add(job); - } - } + private void addJob(TourActivity act) { + if (act instanceof JobActivity) { + Job job = ((JobActivity) act).getJob(); + jobs.add(job); + } + } - /** - * Returns number of jobs assiciated to activities in this activity sequence. - * - * @return no. of jobs - */ - public int jobSize() { - return jobs.size(); - } - - public Iterator reverseActivityIterator(){ - if(backward == null) backward = new ReverseActivityIterator(tourActivities); - else backward.reset(); - return backward; - } + /** + * Returns number of jobs assiciated to activities in this activity sequence. + * + * @return no. of jobs + */ + public int jobSize() { + return jobs.size(); + } + public Iterator reverseActivityIterator() { + if (backward == null) backward = new ReverseActivityIterator(tourActivities); + else backward.reset(); + return backward; + } } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/TourActivity.java b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/TourActivity.java index ac93f96e..6f36087b 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/TourActivity.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/TourActivity.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.problem.solution.route.activity; @@ -25,11 +25,10 @@ import java.util.List; /** * Basic interface for tour-activities. - * + *

*

A tour activity is the basic element of a tour, which is consequently a sequence of tour-activities. - * - * @author schroeder * + * @author schroeder */ public interface TourActivity extends HasIndex { @@ -39,40 +38,39 @@ public interface TourActivity extends HasIndex { public List getTimeWindows(); - /** - * Basic interface of job-activies. - * - *

A job activity is related to a {@link Job}. - * - * @author schroeder - * - */ - public interface JobActivity extends TourActivity { - - /** - * Returns the job that is involved with this activity. - * - * @return job - */ - public Job getJob(); - - } - - /** - * Returns the name of this activity. - * - * @return name - */ - public abstract String getName(); - - /** - * Returns the activity's locationId. - * - * @return locationId + /** + * Basic interface of job-activies. + *

+ *

A job activity is related to a {@link Job}. + * + * @author schroeder + */ + public interface JobActivity extends TourActivity { + + /** + * Returns the job that is involved with this activity. + * + * @return job + */ + public Job getJob(); + + } + + /** + * Returns the name of this activity. + * + * @return name + */ + public abstract String getName(); + + /** + * Returns the activity's locationId. + * + * @return locationId * @deprecated use location - */ + */ @Deprecated - public abstract String getLocationId(); + public abstract String getLocationId(); /** * Returns location. @@ -80,75 +78,74 @@ public interface TourActivity extends HasIndex { * @return location */ public abstract Location getLocation(); - - /** - * Returns the theoretical earliest operation start time, which is the time that is just allowed - * (not earlier) to start this activity, that is for example service.getTimeWindow().getStart(). - * - * @return earliest start time - */ - public abstract double getTheoreticalEarliestOperationStartTime(); - - /** - * Returns the theoretical latest operation start time, which is the time that is just allowed - * (not later) to start this activity, that is for example service.getTimeWindow().getEnd(). - * - * - * @return latest start time - */ - public abstract double getTheoreticalLatestOperationStartTime(); - /** - * Returns the operation-time this activity takes. - * - *

Note that this is not necessarily the duration of this activity, but the - * service time a pickup/delivery actually takes, that is for example service.getServiceTime(). - * - * @return operation time - */ - public abstract double getOperationTime(); - - /** - * Returns the arrival-time of this activity. - * - * @return arrival time - */ - public abstract double getArrTime(); - - /** - * Returns end-time of this activity. - * - * @return end time - */ - public abstract double getEndTime(); - - /** - * Sets the arrival time of that activity. - * - * @param arrTime - */ - public abstract void setArrTime(double arrTime); - - /** - * Sets the end-time of this activity. - * - * @param endTime - */ - public abstract void setEndTime(double endTime); - - /** - * Returns the capacity-demand of that activity, in terms of what needs to be loaded or unloaded at - * this activity. - * - * @return capacity - */ - public abstract Capacity getSize(); - - /** - * Makes a deep copy of this activity. - * - * @return copied activity - */ - public abstract TourActivity duplicate(); - + /** + * Returns the theoretical earliest operation start time, which is the time that is just allowed + * (not earlier) to start this activity, that is for example service.getTimeWindow().getStart(). + * + * @return earliest start time + */ + public abstract double getTheoreticalEarliestOperationStartTime(); + + /** + * Returns the theoretical latest operation start time, which is the time that is just allowed + * (not later) to start this activity, that is for example service.getTimeWindow().getEnd(). + * + * @return latest start time + */ + public abstract double getTheoreticalLatestOperationStartTime(); + + /** + * Returns the operation-time this activity takes. + *

+ *

Note that this is not necessarily the duration of this activity, but the + * service time a pickup/delivery actually takes, that is for example service.getServiceTime(). + * + * @return operation time + */ + public abstract double getOperationTime(); + + /** + * Returns the arrival-time of this activity. + * + * @return arrival time + */ + public abstract double getArrTime(); + + /** + * Returns end-time of this activity. + * + * @return end time + */ + public abstract double getEndTime(); + + /** + * Sets the arrival time of that activity. + * + * @param arrTime + */ + public abstract void setArrTime(double arrTime); + + /** + * Sets the end-time of this activity. + * + * @param endTime + */ + public abstract void setEndTime(double endTime); + + /** + * Returns the capacity-demand of that activity, in terms of what needs to be loaded or unloaded at + * this activity. + * + * @return capacity + */ + public abstract Capacity getSize(); + + /** + * Makes a deep copy of this activity. + * + * @return copied activity + */ + public abstract TourActivity duplicate(); + } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/TourActivityFactory.java b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/TourActivityFactory.java index a6bf2ac9..e49be3d0 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/TourActivityFactory.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/TourActivityFactory.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.problem.solution.route.activity; @@ -20,7 +20,7 @@ import jsprit.core.problem.AbstractActivity; import jsprit.core.problem.job.Service; public interface TourActivityFactory { - - public AbstractActivity createActivity(Service service); + + public AbstractActivity createActivity(Service service); } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/TourShipmentActivityFactory.java b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/TourShipmentActivityFactory.java index 8f0b288f..b9b3dde0 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/TourShipmentActivityFactory.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/TourShipmentActivityFactory.java @@ -1,18 +1,18 @@ /******************************************************************************* * Copyright (c) 2014 Stefan Schroeder. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . - * + * * Contributors: * Stefan Schroeder - initial API and implementation ******************************************************************************/ @@ -22,9 +22,9 @@ import jsprit.core.problem.AbstractActivity; import jsprit.core.problem.job.Shipment; public interface TourShipmentActivityFactory { - - public AbstractActivity createPickup(Shipment shipment); - public AbstractActivity createDelivery(Shipment shipment); - + public AbstractActivity createPickup(Shipment shipment); + + public AbstractActivity createDelivery(Shipment shipment); + } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/state/RouteAndActivityStateGetter.java b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/state/RouteAndActivityStateGetter.java index c2321d8b..f7f35b43 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/state/RouteAndActivityStateGetter.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/state/RouteAndActivityStateGetter.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.problem.solution.route.state; @@ -24,11 +24,11 @@ import jsprit.core.problem.vehicle.Vehicle; public interface RouteAndActivityStateGetter { - public T getActivityState(TourActivity act, StateId stateId, Class type); + public T getActivityState(TourActivity act, StateId stateId, Class type); public T getActivityState(TourActivity act, Vehicle vehicle, StateId stateId, Class type); - - public T getRouteState(VehicleRoute route, StateId stateId, Class type); + + public T getRouteState(VehicleRoute route, StateId stateId, Class type); public T getRouteState(VehicleRoute route, Vehicle vehicle, StateId stateId, Class type); diff --git a/jsprit-core/src/main/java/jsprit/core/problem/vehicle/FiniteFleetManagerFactory.java b/jsprit-core/src/main/java/jsprit/core/problem/vehicle/FiniteFleetManagerFactory.java index ab082b3a..5127ffbe 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/vehicle/FiniteFleetManagerFactory.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/vehicle/FiniteFleetManagerFactory.java @@ -1,53 +1,64 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.problem.vehicle; +import jsprit.core.util.RandomNumberGeneration; + import java.util.Collection; +import java.util.Random; /** * Factory that creates a finite fleetmanager. * * @author schroeder */ -public class FiniteFleetManagerFactory implements VehicleFleetManagerFactory{ +public class FiniteFleetManagerFactory implements VehicleFleetManagerFactory { - private Collection vehicles; - - /** - * Constucts the factory. - * - * @param vehicles vehicles to be added to the fleetManager - */ - public FiniteFleetManagerFactory(Collection vehicles) { - super(); - this.vehicles = vehicles; - } + private Collection vehicles; - /** - * Creates the finite fleetmanager. - * - * @return VehicleFleetManager - * @throws java.lang.IllegalStateException if vehicles == null or vehicles.isEmpty() - */ - @Override - public VehicleFleetManager createFleetManager() { - if(vehicles == null) throw new IllegalStateException("vehicles is null. this must not be."); - if(vehicles.isEmpty()) throw new IllegalStateException("vehicle-collection is empty. this must not be"); - return new VehicleFleetManagerImpl(vehicles); - } + private Random random = RandomNumberGeneration.getRandom(); + + /** + * Constucts the factory. + * + * @param vehicles vehicles to be added to the fleetManager + */ + public FiniteFleetManagerFactory(Collection vehicles) { + super(); + this.vehicles = vehicles; + } + + public void setRandom(Random random) { + this.random = random; + } + + /** + * Creates the finite fleetmanager. + * + * @return VehicleFleetManager + * @throws java.lang.IllegalStateException if vehicles == null or vehicles.isEmpty() + */ + @Override + public VehicleFleetManager createFleetManager() { + if (vehicles == null) throw new IllegalStateException("vehicles is null. this must not be."); + if (vehicles.isEmpty()) throw new IllegalStateException("vehicle-collection is empty. this must not be"); + VehicleFleetManagerImpl vehicleFleetManager = new VehicleFleetManagerImpl(vehicles); + vehicleFleetManager.setRandom(random); + return vehicleFleetManager; + } } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/vehicle/InfiniteFleetManagerFactory.java b/jsprit-core/src/main/java/jsprit/core/problem/vehicle/InfiniteFleetManagerFactory.java index dd7ed83c..3a0f4b09 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/vehicle/InfiniteFleetManagerFactory.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/vehicle/InfiniteFleetManagerFactory.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.problem.vehicle; @@ -23,27 +23,27 @@ import java.util.Collection; * * @author schroeder */ -public class InfiniteFleetManagerFactory implements VehicleFleetManagerFactory{ +public class InfiniteFleetManagerFactory implements VehicleFleetManagerFactory { - private Collection vehicles; - + private Collection vehicles; - /** - * Constructs the factory. - * - * @param vehicles - */ - public InfiniteFleetManagerFactory(Collection vehicles) { - super(); - this.vehicles = vehicles; - } - /** - * Creates the infinite fleetmanager. - */ - @Override - public VehicleFleetManager createFleetManager() { - return new InfiniteVehicles(vehicles); - } + /** + * Constructs the factory. + * + * @param vehicles + */ + public InfiniteFleetManagerFactory(Collection vehicles) { + super(); + this.vehicles = vehicles; + } + + /** + * Creates the infinite fleetmanager. + */ + @Override + public VehicleFleetManager createFleetManager() { + return new InfiniteVehicles(vehicles); + } } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/vehicle/InfiniteVehicles.java b/jsprit-core/src/main/java/jsprit/core/problem/vehicle/InfiniteVehicles.java index 800751e0..df60c65b 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/vehicle/InfiniteVehicles.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/vehicle/InfiniteVehicles.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.problem.vehicle; @@ -25,71 +25,74 @@ import java.util.HashMap; import java.util.Map; +class InfiniteVehicles implements VehicleFleetManager { + private static Logger logger = LogManager.getLogger(InfiniteVehicles.class); + + private Map types = new HashMap(); -class InfiniteVehicles implements VehicleFleetManager{ - - private static Logger logger = LogManager.getLogger(InfiniteVehicles.class); - - private Map types = new HashMap(); - // private List sortedTypes = new ArrayList(); - - public InfiniteVehicles(Collection vehicles){ - extractTypes(vehicles); - logger.debug("initialise " + this); - } - - @Override - public String toString() { - return "[name=infiniteVehicle]"; - } - private void extractTypes(Collection vehicles) { - for(Vehicle v : vehicles){ - VehicleTypeKey typeKey = new VehicleTypeKey(v.getType().getTypeId(), v.getStartLocation().getId(),v.getEndLocation().getId(), v.getEarliestDeparture(), v.getLatestArrival(), v.getSkills()); - types.put(typeKey,v); + public InfiniteVehicles(Collection vehicles) { + extractTypes(vehicles); + logger.debug("initialise " + this); + } + + @Override + public String toString() { + return "[name=infiniteVehicle]"; + } + + private void extractTypes(Collection vehicles) { + for (Vehicle v : vehicles) { +// VehicleTypeKey typeKey = new VehicleTypeKey(v.getType().getTypeId(), v.getStartLocation().getId(), v.getEndLocation().getId(), v.getEarliestDeparture(), v.getLatestArrival(), v.getSkills(), v.isReturnToDepot()); + types.put(v.getVehicleTypeIdentifier(), v); // sortedTypes.add(typeKey); - } - } - - - @Override - public void lock(Vehicle vehicle) { - - } - - @Override - public void unlock(Vehicle vehicle) { - - } + } + } - @Override - public boolean isLocked(Vehicle vehicle) { - return false; - } + @Override + public void lock(Vehicle vehicle) { - @Override - public void unlockAll() { - - } + } - @Override - public Collection getAvailableVehicles() { - return types.values(); - } + @Override + public void unlock(Vehicle vehicle) { - @Override - public Collection getAvailableVehicles(Vehicle withoutThisType) { - Collection vehicles = new ArrayList(); - VehicleTypeKey thisKey = new VehicleTypeKey(withoutThisType.getType().getTypeId(), withoutThisType.getStartLocation().getId(), withoutThisType.getEndLocation().getId(), withoutThisType.getEarliestDeparture(), withoutThisType.getLatestArrival(), withoutThisType.getSkills()); - for(VehicleTypeKey key : types.keySet()){ - if(!key.equals(thisKey)){ - vehicles.add(types.get(key)); - } - } - return vehicles; - } + } + + + @Override + public boolean isLocked(Vehicle vehicle) { + return false; + } + + @Override + public void unlockAll() { + + } + + @Override + public Collection getAvailableVehicles() { + return types.values(); + } + + @Override + public Collection getAvailableVehicles(Vehicle withoutThisType) { + Collection vehicles = new ArrayList(); + VehicleTypeKey thisKey = new VehicleTypeKey(withoutThisType.getType().getTypeId(), withoutThisType.getStartLocation().getId(), withoutThisType.getEndLocation().getId(), withoutThisType.getEarliestDeparture(), withoutThisType.getLatestArrival(), withoutThisType.getSkills(), withoutThisType.isReturnToDepot()); + for (VehicleTypeKey key : types.keySet()) { + if (!key.equals(thisKey)) { + vehicles.add(types.get(key)); + } + } + return vehicles; + } + + @Override + public Vehicle getAvailableVehicle(VehicleTypeKey vehicleTypeIdentifier) { + return types.get(vehicleTypeIdentifier); + } } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/vehicle/Vehicle.java b/jsprit-core/src/main/java/jsprit/core/problem/vehicle/Vehicle.java index b29391d1..0ab8fbf7 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/vehicle/Vehicle.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/vehicle/Vehicle.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.problem.vehicle; @@ -20,56 +20,57 @@ import jsprit.core.problem.HasId; import jsprit.core.problem.HasIndex; import jsprit.core.problem.Location; import jsprit.core.problem.Skills; +import jsprit.core.problem.job.Break; /** * Basic interface for vehicle-data. - * - * @author schroeder * + * @author schroeder */ public interface Vehicle extends HasId, HasIndex { - /** - * Returns the earliest departure of vehicle which should be the lower bound of this vehicle's departure times. - * - * @return earliest departure time - */ - public abstract double getEarliestDeparture(); + /** + * Returns the earliest departure of vehicle which should be the lower bound of this vehicle's departure times. + * + * @return earliest departure time + */ + public abstract double getEarliestDeparture(); - /** - * Returns the latest arrival time at this vehicle's end-location which should be the upper bound of this vehicle's arrival times at end-location. - * - * @return latest arrival time of this vehicle - * - */ - public abstract double getLatestArrival(); + /** + * Returns the latest arrival time at this vehicle's end-location which should be the upper bound of this vehicle's arrival times at end-location. + * + * @return latest arrival time of this vehicle + */ + public abstract double getLatestArrival(); - /** - * Returns the {@link VehicleType} of this vehicle. - * - * @return {@link VehicleType} of this vehicle - */ - public abstract VehicleType getType(); + /** + * Returns the {@link VehicleType} of this vehicle. + * + * @return {@link VehicleType} of this vehicle + */ + public abstract VehicleType getType(); - /** - * Returns the id of this vehicle. - * - * @return id - */ - public abstract String getId(); + /** + * Returns the id of this vehicle. + * + * @return id + */ + public abstract String getId(); - /** - * Returns true if vehicle returns to depot, false otherwise. - * - * @return true if isReturnToDepot - */ - public abstract boolean isReturnToDepot(); + /** + * Returns true if vehicle returns to depot, false otherwise. + * + * @return true if isReturnToDepot + */ + public abstract boolean isReturnToDepot(); public abstract Location getStartLocation(); - - public abstract Location getEndLocation(); - - public abstract VehicleTypeKey getVehicleTypeIdentifier(); + + public abstract Location getEndLocation(); + + public abstract VehicleTypeKey getVehicleTypeIdentifier(); public abstract Skills getSkills(); + + public abstract Break getBreak(); } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/vehicle/VehicleFleetManager.java b/jsprit-core/src/main/java/jsprit/core/problem/vehicle/VehicleFleetManager.java index e468ca86..7fefb989 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/vehicle/VehicleFleetManager.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/vehicle/VehicleFleetManager.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.problem.vehicle; @@ -20,49 +20,51 @@ import java.util.Collection; public interface VehicleFleetManager { - - /** - * Locks vehicle. - * - *

This indicates that this vehicle is being used. Thus it is not in list of available vehicles. - * @param vehicle - */ - public abstract void lock(Vehicle vehicle); - /** - * Unlocks vehicle. - * - *

This indicates that this vehicle is not being used anymore. Thus it is in list of available vehicles. - * @param vehicle - */ - public abstract void unlock(Vehicle vehicle); + /** + * Locks vehicle. + *

+ *

This indicates that this vehicle is being used. Thus it is not in list of available vehicles. + * + * @param vehicle + */ + public abstract void lock(Vehicle vehicle); - /** - * Returns true if locked. - * - * @param vehicle - * @return - */ - public abstract boolean isLocked(Vehicle vehicle); + /** + * Unlocks vehicle. + *

+ *

This indicates that this vehicle is not being used anymore. Thus it is in list of available vehicles. + * + * @param vehicle + */ + public abstract void unlock(Vehicle vehicle); - /** - * Unlocks all locked vehicles. - * - */ - public abstract void unlockAll(); + /** + * Returns true if locked. + * + * @param vehicle + * @return + */ + public abstract boolean isLocked(Vehicle vehicle); - /** - * Returns a collection of available vehicles. - * - *

Note that this does not return ALL available vehicles that were added to the fleetmanager. Vehicles are clustered according - * to {@link VehicleTypeKey}. If there are two unlocked vehicle with the same VehicleTypeKey then only one of them will be returned. - * This is to avoid returning too many vehicles that are basically equal. - *

Look at {@link VehicleTypeKey} to figure out whether two vehicles are equal or not. - * - * @return - */ - public abstract Collection getAvailableVehicles(); - - public Collection getAvailableVehicles(Vehicle withoutThisType); + /** + * Unlocks all locked vehicles. + */ + public abstract void unlockAll(); + /** + * Returns a collection of available vehicles. + *

+ *

Note that this does not return ALL available vehicles that were added to the fleetmanager. Vehicles are clustered according + * to {@link VehicleTypeKey}. If there are two unlocked vehicle with the same VehicleTypeKey then only one of them will be returned. + * This is to avoid returning too many vehicles that are basically equal. + *

Look at {@link VehicleTypeKey} to figure out whether two vehicles are equal or not. + * + * @return + */ + public abstract Collection getAvailableVehicles(); + + public Collection getAvailableVehicles(Vehicle withoutThisType); + + public Vehicle getAvailableVehicle(VehicleTypeKey vehicleTypeIdentifier); } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/vehicle/VehicleFleetManagerFactory.java b/jsprit-core/src/main/java/jsprit/core/problem/vehicle/VehicleFleetManagerFactory.java index f8b5e295..834cb69f 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/vehicle/VehicleFleetManagerFactory.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/vehicle/VehicleFleetManagerFactory.java @@ -1,25 +1,25 @@ /******************************************************************************* * Copyright (c) 2014 Stefan Schroeder. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . - * + * * Contributors: * Stefan Schroeder - initial API and implementation ******************************************************************************/ package jsprit.core.problem.vehicle; public interface VehicleFleetManagerFactory { - - public VehicleFleetManager createFleetManager(); + + public VehicleFleetManager createFleetManager(); } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/vehicle/VehicleFleetManagerImpl.java b/jsprit-core/src/main/java/jsprit/core/problem/vehicle/VehicleFleetManagerImpl.java index e5786b66..209f2d0f 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/vehicle/VehicleFleetManagerImpl.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/vehicle/VehicleFleetManagerImpl.java @@ -1,210 +1,220 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.problem.vehicle; import jsprit.core.problem.vehicle.VehicleImpl.NoVehicle; +import jsprit.core.util.RandomNumberGeneration; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Random; class VehicleFleetManagerImpl implements VehicleFleetManager { - - public VehicleFleetManagerImpl newInstance(Collection vehicles){ - return new VehicleFleetManagerImpl(vehicles); - } - - static class TypeContainer { - - private ArrayList vehicleList; - - public TypeContainer() { - super(); - vehicleList = new ArrayList(); - } - - void add(Vehicle vehicle){ - if(vehicleList.contains(vehicle)){ - throw new IllegalStateException("cannot add vehicle twice " + vehicle.getId()); - } - vehicleList.add(vehicle); - } - - void remove(Vehicle vehicle){ - vehicleList.remove(vehicle); - } - public Vehicle getVehicle() { - return vehicleList.get(0); -// return vehicleList.getFirst(); - } + public VehicleFleetManagerImpl newInstance(Collection vehicles) { + return new VehicleFleetManagerImpl(vehicles); + } - public boolean isEmpty() { - return vehicleList.isEmpty(); - } - - } - - private static Logger logger = LogManager.getLogger(VehicleFleetManagerImpl.class); - - private Collection vehicles; - - private Set lockedVehicles; + static class TypeContainer { - private Map typeMapOfAvailableVehicles; - - private Map penaltyVehicles = new HashMap(); + private ArrayList vehicleList; - - public VehicleFleetManagerImpl(Collection vehicles) { - super(); - this.vehicles = vehicles; - this.lockedVehicles = new HashSet(); - makeMap(); - logger.debug("initialise " + this); - } + private Random random = RandomNumberGeneration.getRandom(); - @Override - public String toString() { - return "[name=finiteVehicles]"; - } + public TypeContainer() { + super(); + vehicleList = new ArrayList(); + } - private void makeMap() { - typeMapOfAvailableVehicles = new HashMap(); - penaltyVehicles = new HashMap(); - for(Vehicle v : vehicles){ - addVehicle(v); - } - } + public void setRandom(Random random) { + this.random = random; + } - private void addVehicle(Vehicle v) { - if(v.getType() == null){ - throw new IllegalStateException("vehicle needs type"); - } - VehicleTypeKey typeKey = new VehicleTypeKey(v.getType().getTypeId(), v.getStartLocation().getId(), v.getEndLocation().getId(), v.getEarliestDeparture(), v.getLatestArrival(), v.getSkills()); - if(!typeMapOfAvailableVehicles.containsKey(typeKey)){ - typeMapOfAvailableVehicles.put(typeKey, new TypeContainer()); - } - typeMapOfAvailableVehicles.get(typeKey).add(v); + void add(Vehicle vehicle) { + if (vehicleList.contains(vehicle)) { + throw new IllegalStateException("cannot add vehicle twice " + vehicle.getId()); + } + vehicleList.add(vehicle); + } - } - - private void removeVehicle(Vehicle v){ - VehicleTypeKey key = new VehicleTypeKey(v.getType().getTypeId(), v.getStartLocation().getId(), v.getEndLocation().getId(), v.getEarliestDeparture(), v.getLatestArrival(), v.getSkills()); - if(typeMapOfAvailableVehicles.containsKey(key)){ - typeMapOfAvailableVehicles.get(key).remove(v); - } - } + void remove(Vehicle vehicle) { + vehicleList.remove(vehicle); + } - - /** - * Returns a collection of available vehicles. - * - *

If there is no vehicle with a certain type and location anymore, it looks up whether a penalty vehicle has been specified with - * this type and location. If so, it returns this penalty vehicle. If not, no vehicle with this type and location is returned. - */ - @Override - public Collection getAvailableVehicles() { - List vehicles = new ArrayList(); - for(VehicleTypeKey key : typeMapOfAvailableVehicles.keySet()){ - if(!typeMapOfAvailableVehicles.get(key).isEmpty()){ - vehicles.add(typeMapOfAvailableVehicles.get(key).getVehicle()); - } - else{ - if(penaltyVehicles.containsKey(key)){ - vehicles.add(penaltyVehicles.get(key)); - } - } - } - return vehicles; - } - - @Override - public Collection getAvailableVehicles(Vehicle withoutThisType) { - List vehicles = new ArrayList(); - VehicleTypeKey thisKey = new VehicleTypeKey(withoutThisType.getType().getTypeId(), withoutThisType.getStartLocation().getId(), withoutThisType.getEndLocation().getId(), withoutThisType.getEarliestDeparture(), withoutThisType.getLatestArrival(), withoutThisType.getSkills()); - for(VehicleTypeKey key : typeMapOfAvailableVehicles.keySet()){ - if(key.equals(thisKey)) continue; - if(!typeMapOfAvailableVehicles.get(key).isEmpty()){ - vehicles.add(typeMapOfAvailableVehicles.get(key).getVehicle()); - } - else{ - if(penaltyVehicles.containsKey(key)){ - vehicles.add(penaltyVehicles.get(key)); - } - } - } - return vehicles; - } + public Vehicle getVehicle() { + int randomIndex = random.nextInt(vehicleList.size()); + return vehicleList.get(randomIndex); + } - /* (non-Javadoc) - * @see org.matsim.contrib.freight.vrp.basics.VehicleFleetManager#lock(org.matsim.contrib.freight.vrp.basics.Vehicle) - */ - @Override - public void lock(Vehicle vehicle){ - if(vehicles.isEmpty() || vehicle instanceof NoVehicle){ - return; - } - boolean locked = lockedVehicles.add(vehicle); - removeVehicle(vehicle); - if(!locked){ - throw new IllegalStateException("cannot lock vehicle twice " + vehicle.getId()); - } - } - - /* (non-Javadoc) - * @see org.matsim.contrib.freight.vrp.basics.VehicleFleetManager#unlock(org.matsim.contrib.freight.vrp.basics.Vehicle) - */ - @Override - public void unlock(Vehicle vehicle){ - if(vehicles.isEmpty() || vehicle instanceof NoVehicle){ - return; - } - if(vehicle == null) return; - lockedVehicles.remove(vehicle); - addVehicle(vehicle); - } + public boolean isEmpty() { + return vehicleList.isEmpty(); + } - /* (non-Javadoc) - * @see org.matsim.contrib.freight.vrp.basics.VehicleFleetManager#isLocked(org.matsim.contrib.freight.vrp.basics.Vehicle) - */ - @Override - public boolean isLocked(Vehicle vehicle) { - return lockedVehicles.contains(vehicle); - } + } - /* (non-Javadoc) - * @see org.matsim.contrib.freight.vrp.basics.VehicleFleetManager#unlockAll() - */ - @Override - public void unlockAll() { - Collection locked = new ArrayList(lockedVehicles); - for(Vehicle v : locked){ - unlock(v); - } - if(!lockedVehicles.isEmpty()){ - throw new IllegalStateException("no vehicle must be locked"); - } - } + private static Logger logger = LogManager.getLogger(VehicleFleetManagerImpl.class); - @Deprecated - public int sizeOfLockedVehicles(){ - return lockedVehicles.size(); - } + private Collection vehicles; + + private TypeContainer[] vehicleTypes; + + private boolean[] locked; + + private Vehicle[] vehicleArr; + + private Random random = RandomNumberGeneration.getRandom(); + + public VehicleFleetManagerImpl(Collection vehicles) { + super(); + this.vehicles = vehicles; + int arrSize = vehicles.size() + 2; + locked = new boolean[arrSize]; + vehicleArr = new Vehicle[arrSize]; + initializeVehicleTypes(); + logger.debug("initialise {}",this); + } + + public void setRandom(Random random) { + this.random = random; + } + + @Override + public String toString() { + return "[name=finiteVehicles]"; + } + + private void initializeVehicleTypes() { + int maxTypeIndex = 0; + for(Vehicle v : vehicles){ + if(v.getVehicleTypeIdentifier().getIndex() > maxTypeIndex){ + maxTypeIndex = v.getVehicleTypeIdentifier().getIndex(); + } + } + vehicleTypes = new TypeContainer[maxTypeIndex+1]; + for(int i=0;i< vehicleTypes.length;i++){ + TypeContainer typeContainer = new TypeContainer(); + typeContainer.setRandom(random); + vehicleTypes[i] = typeContainer; + } + for (Vehicle v : vehicles) { + vehicleArr[v.getIndex()]=v; + addVehicle(v); + } + } + + private void addVehicle(Vehicle v) { + if (v.getType() == null) { + throw new IllegalStateException("vehicle needs type"); + } + vehicleTypes[v.getVehicleTypeIdentifier().getIndex()].add(v); + } + + private void removeVehicle(Vehicle v) { + vehicleTypes[v.getVehicleTypeIdentifier().getIndex()].remove(v); + } + + + /** + * Returns a collection of available vehicles. + *

+ *

If there is no vehicle with a certain type and location anymore, it looks up whether a penalty vehicle has been specified with + * this type and location. If so, it returns this penalty vehicle. If not, no vehicle with this type and location is returned. + */ + @Override + public Collection getAvailableVehicles() { + List vehicles = new ArrayList(); + for(int i=0;i< vehicleTypes.length;i++){ + if(!vehicleTypes[i].isEmpty()){ + vehicles.add(vehicleTypes[i].getVehicle()); + } + } + return vehicles; + } + + @Override + public Collection getAvailableVehicles(Vehicle withoutThisType) { + List vehicles = new ArrayList(); + for(int i=0;i< vehicleTypes.length;i++){ + if(!vehicleTypes[i].isEmpty() && i != withoutThisType.getVehicleTypeIdentifier().getIndex()){ + vehicles.add(vehicleTypes[i].getVehicle()); + } + } + return vehicles; + } + + @Override + public Vehicle getAvailableVehicle(VehicleTypeKey vehicleTypeIdentifier) { + if(!vehicleTypes[vehicleTypeIdentifier.getIndex()].isEmpty()){ + return vehicleTypes[vehicleTypeIdentifier.getIndex()].getVehicle(); + } + return null; + } + + /* (non-Javadoc) + * @see org.matsim.contrib.freight.vrp.basics.VehicleFleetManager#lock(org.matsim.contrib.freight.vrp.basics.Vehicle) + */ + @Override + public void lock(Vehicle vehicle) { + if (vehicles.isEmpty() || vehicle instanceof NoVehicle) { + return; + } + if(locked[vehicle.getIndex()]){ + throw new IllegalStateException("cannot lock vehicle twice " + vehicle.getId()); + } + else{ + locked[vehicle.getIndex()] = true; + removeVehicle(vehicle); + } + } + + /* (non-Javadoc) + * @see org.matsim.contrib.freight.vrp.basics.VehicleFleetManager#unlock(org.matsim.contrib.freight.vrp.basics.Vehicle) + */ + @Override + public void unlock(Vehicle vehicle) { + if (vehicle == null || vehicles.isEmpty() || vehicle instanceof NoVehicle) { + return; + } + locked[vehicle.getIndex()] = false; + addVehicle(vehicle); + } + + /* (non-Javadoc) + * @see org.matsim.contrib.freight.vrp.basics.VehicleFleetManager#isLocked(org.matsim.contrib.freight.vrp.basics.Vehicle) + */ + @Override + public boolean isLocked(Vehicle vehicle) { + return locked[vehicle.getIndex()]; + } + + /* (non-Javadoc) + * @see org.matsim.contrib.freight.vrp.basics.VehicleFleetManager#unlockAll() + */ + @Override + public void unlockAll() { + for(int i=0;i. ******************************************************************************/ package jsprit.core.problem.vehicle; @@ -19,38 +19,34 @@ package jsprit.core.problem.vehicle; import jsprit.core.problem.AbstractVehicle; import jsprit.core.problem.Location; import jsprit.core.problem.Skills; +import jsprit.core.problem.job.Break; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; - /** * Implementation of {@link Vehicle}. - * + * * @author stefan schroeder - * */ -public class VehicleImpl extends AbstractVehicle{ - - +public class VehicleImpl extends AbstractVehicle { /** - * Extension of {@link VehicleImpl} representing an unspecified vehicle with the id 'noVehicle' - * (to avoid null). - * - * @author schroeder - * - */ - public static class NoVehicle extends AbstractVehicle { + * Extension of {@link VehicleImpl} representing an unspecified vehicle with the id 'noVehicle' + * (to avoid null). + * + * @author schroeder + */ + public static class NoVehicle extends AbstractVehicle { private String id = "noVehicle"; private VehicleType type = VehicleTypeImpl.Builder.newInstance("noType").build(); - public NoVehicle() { - } + public NoVehicle() { + } @Override public double getEarliestDeparture() { @@ -91,31 +87,37 @@ public class VehicleImpl extends AbstractVehicle{ public Skills getSkills() { return null; } + + + @Override + public Break getBreak() { + return null; + } + } - - /** - * Builder that builds the vehicle. - * - *

By default, earliestDepartureTime is 0.0, latestDepartureTime is Double.MAX_VALUE, - * it returns to the depot and its {@link VehicleType} is the DefaultType with typeId equal to 'default' - * and a capacity of 0. - * - * @author stefan - * - */ - public static class Builder { + + /** + * Builder that builds the vehicle. + *

+ *

By default, earliestDepartureTime is 0.0, latestDepartureTime is Double.MAX_VALUE, + * it returns to the depot and its {@link VehicleType} is the DefaultType with typeId equal to 'default' + * and a capacity of 0. + * + * @author stefan + */ + public static class Builder { static final Logger log = LogManager.getLogger(Builder.class.getName()); private String id; - private double earliestStart = 0.0; + private double earliestStart = 0.0; - private double latestArrival = Double.MAX_VALUE; + private double latestArrival = Double.MAX_VALUE; - private boolean returnToDepot = true; - - private VehicleType type = VehicleTypeImpl.Builder.newInstance("default").build(); + private boolean returnToDepot = true; + + private VehicleType type = VehicleTypeImpl.Builder.newInstance("default").build(); private Skills.Builder skillBuilder = Skills.Builder.newInstance(); @@ -125,148 +127,165 @@ public class VehicleImpl extends AbstractVehicle{ private Location endLocation; + private Break aBreak; + private Builder(String id) { - super(); - this.id = id; - } - - /** - * Sets the {@link VehicleType}.
- * - * @param type the type to be set - * @throws IllegalStateException if type is null - * @return this builder - */ - public Builder setType(VehicleType type){ - if(type==null) throw new IllegalStateException("type cannot be null."); - this.type = type; - return this; - } - - /** - * Sets the flag whether the vehicle must return to depot or not. - * - *

If returnToDepot is true, the vehicle must return to specified end-location. If you - * omit specifying the end-location, vehicle returns to start-location (that must to be set). If - * you specify it, it returns to specified end-location. - * - *

If returnToDepot is false, the end-location of the vehicle is endogenous. - * - * @param returnToDepot true if vehicle need to return to depot, otherwise false - * @return this builder - */ - public Builder setReturnToDepot(boolean returnToDepot){ - this.returnToDepot = returnToDepot; - return this; - } + super(); + this.id = id; + } + + /** + * Sets the {@link VehicleType}.
+ * + * @param type the type to be set + * @return this builder + * @throws IllegalStateException if type is null + */ + public Builder setType(VehicleType type) { + if (type == null) throw new IllegalStateException("type cannot be null."); + this.type = type; + return this; + } + + /** + * Sets the flag whether the vehicle must return to depot or not. + *

+ *

If returnToDepot is true, the vehicle must return to specified end-location. If you + * omit specifying the end-location, vehicle returns to start-location (that must to be set). If + * you specify it, it returns to specified end-location. + *

+ *

If returnToDepot is false, the end-location of the vehicle is endogenous. + * + * @param returnToDepot true if vehicle need to return to depot, otherwise false + * @return this builder + */ + public Builder setReturnToDepot(boolean returnToDepot) { + this.returnToDepot = returnToDepot; + return this; + } /** * Sets start location. + * * @param startLocation start location * @return start location */ - public Builder setStartLocation(Location startLocation){ + public Builder setStartLocation(Location startLocation) { this.startLocation = startLocation; return this; } - public Builder setEndLocation(Location endLocation){ + public Builder setEndLocation(Location endLocation) { this.endLocation = endLocation; return this; } - - /** - * Sets earliest-start of vehicle which should be the lower bound of the vehicle's departure times. - * - * @param earliest_startTime the earliest start time / departure time of the vehicle at its start location - * @return this builder - */ - public Builder setEarliestStart(double earliest_startTime){ - this.earliestStart = earliest_startTime; - return this; - } - - /** - * Sets the latest arrival at vehicle's end-location which is the upper bound of the vehicle's arrival times. - * - * @param latest_arrTime the latest arrival time of the vehicle at its end location - * @return this builder - */ - public Builder setLatestArrival(double latest_arrTime){ - this.latestArrival = latest_arrTime; - return this; - } - public Builder addSkill(String skill){ + /** + * Sets earliest-start of vehicle which should be the lower bound of the vehicle's departure times. + * + * @param earliest_startTime the earliest start time / departure time of the vehicle at its start location + * @return this builder + */ + public Builder setEarliestStart(double earliest_startTime) { + if (earliest_startTime < 0) + throw new IllegalArgumentException("earliest start of vehicle " + id + " must not be negative"); + this.earliestStart = earliest_startTime; + return this; + } + + /** + * Sets the latest arrival at vehicle's end-location which is the upper bound of the vehicle's arrival times. + * + * @param latest_arrTime the latest arrival time of the vehicle at its end location + * @return this builder + */ + public Builder setLatestArrival(double latest_arrTime) { + if (latest_arrTime < 0) + throw new IllegalArgumentException("latest arrival time of vehicle " + id + " must not be negative"); + this.latestArrival = latest_arrTime; + return this; + } + + public Builder addSkill(String skill) { skillBuilder.addSkill(skill); return this; } - - /** - * Builds and returns the vehicle. - * - *

if {@link VehicleType} is not set, default vehicle-type is set with id="default" and - * capacity=0 - * - *

if startLocationId || locationId is null (=> startLocationCoordinate || locationCoordinate must be set) then startLocationId=startLocationCoordinate.toString() - * and locationId=locationCoordinate.toString() [coord.toString() --> [x=x_val][y=y_val]) - *

if endLocationId is null and endLocationCoordinate is set then endLocationId=endLocationCoordinate.toString() - *

if endLocationId==null AND endLocationCoordinate==null then endLocationId=startLocationId AND endLocationCoord=startLocationCoord - * Thus endLocationId can never be null even returnToDepot is false. - * - * @return vehicle - * @throws IllegalStateException if both locationId and locationCoord is not set or (endLocationCoord!=null AND returnToDepot=false) - * or (endLocationId!=null AND returnToDepot=false) - */ - public VehicleImpl build(){ - if(startLocation != null && endLocation != null){ - if( !startLocation.getId().equals(endLocation.getId()) && !returnToDepot) throw new IllegalStateException("this must not be. you specified both endLocationId and open-routes. this is contradictory.
" + + + /** + * Builds and returns the vehicle. + *

+ *

if {@link VehicleType} is not set, default vehicle-type is set with id="default" and + * capacity=0 + *

+ *

if startLocationId || locationId is null (=> startLocationCoordinate || locationCoordinate must be set) then startLocationId=startLocationCoordinate.toString() + * and locationId=locationCoordinate.toString() [coord.toString() --> [x=x_val][y=y_val]) + *

if endLocationId is null and endLocationCoordinate is set then endLocationId=endLocationCoordinate.toString() + *

if endLocationId==null AND endLocationCoordinate==null then endLocationId=startLocationId AND endLocationCoord=startLocationCoord + * Thus endLocationId can never be null even returnToDepot is false. + * + * @return vehicle + * @throws IllegalStateException if both locationId and locationCoord is not set or (endLocationCoord!=null AND returnToDepot=false) + * or (endLocationId!=null AND returnToDepot=false) + */ + public VehicleImpl build() { + if (latestArrival < earliestStart) + throw new IllegalStateException("latest arrival of vehicle " + id + " must not be smaller than its start time"); + if (startLocation != null && endLocation != null) { + if (!startLocation.getId().equals(endLocation.getId()) && !returnToDepot) + throw new IllegalStateException("this must not be. you specified both endLocationId and open-routes. this is contradictory.
" + "if you set endLocation, returnToDepot must be true. if returnToDepot is false, endLocationCoord must not be specified."); } if (startLocation != null && endLocation == null) { endLocation = startLocation; } - if(startLocation == null && endLocation == null) { - throw new IllegalStateException("vehicle requires startLocation. but neither locationId nor locationCoord nor startLocationId nor startLocationCoord has been set"); - } + if (startLocation == null && endLocation == null) { + throw new IllegalStateException("vehicle requires startLocation. but neither locationId nor locationCoord nor startLocationId nor startLocationCoord has been set"); + } skills = skillBuilder.build(); return new VehicleImpl(this); - } - - /** - * Returns new instance of vehicle builder. - * - * @param vehicleId the id of the vehicle which must be a unique identifier among all vehicles - * @return vehicle builder - */ - public static Builder newInstance(String vehicleId){ return new Builder(vehicleId); } + } + + /** + * Returns new instance of vehicle builder. + * + * @param vehicleId the id of the vehicle which must be a unique identifier among all vehicles + * @return vehicle builder + */ + public static Builder newInstance(String vehicleId) { + return new Builder(vehicleId); + } public Builder addSkills(Skills skills) { this.skillBuilder.addAllSkills(skills.values()); return this; } + + public Builder setBreak(Break aBreak) { + this.aBreak = aBreak; + return this; + } } - /** - * Returns empty/noVehicle which is a vehicle having no capacity, no type and no reasonable id. - * - *

NoVehicle has id="noVehicle" and extends {@link VehicleImpl} - * - * @return emptyVehicle - */ - public static NoVehicle createNoVehicle(){ - return new NoVehicle(); - } - - private final String id; + /** + * Returns empty/noVehicle which is a vehicle having no capacity, no type and no reasonable id. + *

+ *

NoVehicle has id="noVehicle" and extends {@link VehicleImpl} + * + * @return emptyVehicle + */ + public static NoVehicle createNoVehicle() { + return new NoVehicle(); + } - private final VehicleType type; + private final String id; - private final double earliestDeparture; + private final VehicleType type; - private final double latestArrival; - - private final boolean returnToDepot; + private final double earliestDeparture; + + private final double latestArrival; + + private final boolean returnToDepot; private final Skills skills; @@ -274,57 +293,61 @@ public class VehicleImpl extends AbstractVehicle{ private final Location startLocation; - private VehicleImpl(Builder builder){ - id = builder.id; - type = builder.type; - earliestDeparture = builder.earliestStart; - latestArrival = builder.latestArrival; - returnToDepot = builder.returnToDepot; - skills = builder.skills; + private final Break aBreak; + + private VehicleImpl(Builder builder) { + id = builder.id; + type = builder.type; + earliestDeparture = builder.earliestStart; + latestArrival = builder.latestArrival; + returnToDepot = builder.returnToDepot; + skills = builder.skills; endLocation = builder.endLocation; startLocation = builder.startLocation; - setVehicleIdentifier(new VehicleTypeKey(type.getTypeId(),startLocation.getId(),endLocation.getId(),earliestDeparture,latestArrival,skills)); - } - - /** - * Returns String with attributes of this vehicle - * - *

String has the following format [attr1=val1][attr2=val2]...[attrn=valn] - */ - @Override - public String toString() { - return "[id="+id+"]" + - "[type="+type+"]" + - "[startLocation="+startLocation+"]" + - "[endLocation=" + endLocation+"]" + - "[isReturnToDepot=" + isReturnToDepot() + "]" + - "[skills="+ skills + "]"; + aBreak = builder.aBreak; +// setVehicleIdentifier(new VehicleTypeKey(type.getTypeId(),startLocation.getId(),endLocation.getId(),earliestDeparture,latestArrival,skills)); + setVehicleIdentifier(new VehicleTypeKey(type.getTypeId(), startLocation.getId(), endLocation.getId(), earliestDeparture, latestArrival, skills, returnToDepot)); + } - } + /** + * Returns String with attributes of this vehicle + *

+ *

String has the following format [attr1=val1][attr2=val2]...[attrn=valn] + */ + @Override + public String toString() { + return "[id=" + id + "]" + + "[type=" + type + "]" + + "[startLocation=" + startLocation + "]" + + "[endLocation=" + endLocation + "]" + + "[isReturnToDepot=" + isReturnToDepot() + "]" + + "[skills=" + skills + "]"; + } - @Override - public double getEarliestDeparture() { - return earliestDeparture; - } - @Override - public double getLatestArrival() { - return latestArrival; - } + @Override + public double getEarliestDeparture() { + return earliestDeparture; + } - @Override - public VehicleType getType() { - return type; - } + @Override + public double getLatestArrival() { + return latestArrival; + } - @Override - public String getId() { - return id; - } + @Override + public VehicleType getType() { + return type; + } - public boolean isReturnToDepot() { - return returnToDepot; - } + @Override + public String getId() { + return id; + } + + public boolean isReturnToDepot() { + return returnToDepot; + } @Override public Location getStartLocation() { @@ -341,44 +364,47 @@ public class VehicleImpl extends AbstractVehicle{ return skills; } + @Override + public Break getBreak() { + return aBreak; + } + /* (non-Javadoc) * @see java.lang.Object#hashCode() */ - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((id == null) ? 0 : id.hashCode()); - result = prime * result + ((type == null) ? 0 : type.hashCode()); - return result; - } + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((id == null) ? 0 : id.hashCode()); + result = prime * result + ((type == null) ? 0 : type.hashCode()); + return result; + } - /** - * Two vehicles are equal if they have the same id and if their types are equal. - */ - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - VehicleImpl other = (VehicleImpl) obj; - if (id == null) { - if (other.id != null) - return false; - } else if (!id.equals(other.id)) - return false; - if (type == null) { - if (other.type != null) - return false; - } else if (!type.equals(other.type)) - return false; - return true; - } + /** + * Two vehicles are equal if they have the same id and if their types are equal. + */ + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + VehicleImpl other = (VehicleImpl) obj; + if (id == null) { + if (other.id != null) + return false; + } else if (!id.equals(other.id)) + return false; + if (type == null) { + if (other.type != null) + return false; + } else if (!type.equals(other.type)) + return false; + return true; + } - - - } + diff --git a/jsprit-core/src/main/java/jsprit/core/problem/vehicle/VehicleType.java b/jsprit-core/src/main/java/jsprit/core/problem/vehicle/VehicleType.java index c60e8392..69b28650 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/vehicle/VehicleType.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/vehicle/VehicleType.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.problem.vehicle; @@ -21,40 +21,39 @@ import jsprit.core.problem.vehicle.VehicleTypeImpl.VehicleCostParams; /** * Basic interface for vehicle-type-data. - * - * @author schroeder * + * @author schroeder */ public interface VehicleType { - /** - * Returns typeId. - * - * @return typeId - */ - public String getTypeId(); + /** + * Returns typeId. + * + * @return typeId + */ + public String getTypeId(); - /** - * Returns capacity dimensions. - * - * @return {@link Capacity} - */ - public Capacity getCapacityDimensions(); - - /** - * Returns maximum velocity of this vehicle-type. - * - * @return max velocity - */ - public double getMaxVelocity(); + /** + * Returns capacity dimensions. + * + * @return {@link Capacity} + */ + public Capacity getCapacityDimensions(); - /** - * Return the cost-parameter of this vehicle-type. - * - * @return parameter - */ - public VehicleCostParams getVehicleCostParams(); + /** + * Returns maximum velocity of this vehicle-type. + * + * @return max velocity + */ + public double getMaxVelocity(); - public String getProfile(); + /** + * Return the cost-parameter of this vehicle-type. + * + * @return parameter + */ + public VehicleCostParams getVehicleCostParams(); + + public String getProfile(); } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/vehicle/VehicleTypeImpl.java b/jsprit-core/src/main/java/jsprit/core/problem/vehicle/VehicleTypeImpl.java index fe1d5d34..fcdd8162 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/vehicle/VehicleTypeImpl.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/vehicle/VehicleTypeImpl.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.problem.vehicle; @@ -21,280 +21,348 @@ import jsprit.core.problem.Capacity; /** * Implementation of {@link VehicleType}. - * + *

*

Two vehicle-types are equal if they have the same typeId. - * - * @author schroeder * + * @author schroeder */ public class VehicleTypeImpl implements VehicleType { - - /** - * CostParameter consisting of fixed cost parameter, time-based cost parameter and distance-based cost parameter. - * - * @author schroeder - * - */ - public static class VehicleCostParams { - - public static VehicleTypeImpl.VehicleCostParams newInstance(double fix, double perTimeUnit,double perDistanceUnit){ - return new VehicleCostParams(fix, perTimeUnit, perDistanceUnit); - } - - public final double fix; - public final double perTimeUnit; - public final double perDistanceUnit; - private VehicleCostParams(double fix, double perTimeUnit,double perDistanceUnit) { - super(); - this.fix = fix; - this.perTimeUnit = perTimeUnit; - this.perDistanceUnit = perDistanceUnit; - } - - @Override - public String toString() { - return "[fixed="+fix+"][perTime="+perTimeUnit+"][perDistance="+perDistanceUnit+"]"; - } - } + /** + * CostParameter consisting of fixed cost parameter, time-based cost parameter and distance-based cost parameter. + * + * @author schroeder + */ + public static class VehicleCostParams { - /** - * Builder that builds the vehicle-type. - * - * @author schroeder - * - */ - public static class Builder{ - - public static VehicleTypeImpl.Builder newInstance(String id) { - if(id==null) throw new IllegalStateException(); - return new Builder(id); - } - - private String id; - private int capacity = 0; - private double maxVelo = Double.MAX_VALUE; - /** - * default cost values for default vehicle type - */ - private double fixedCost = 0.0; - private double perDistance = 1.0; - private double perTime = 0.0; - private String profile = "car"; - - private Capacity.Builder capacityBuilder = Capacity.Builder.newInstance(); - - private Capacity capacityDimensions = null; - - private boolean dimensionAdded = false; + public static VehicleTypeImpl.VehicleCostParams newInstance(double fix, double perTimeUnit, double perDistanceUnit) { + return new VehicleCostParams(fix, perTimeUnit, perDistanceUnit); + } - private Builder(String id) { - this.id = id; - } + public final double fix; + @Deprecated + public final double perTimeUnit; + public final double perTransportTimeUnit; + public final double perDistanceUnit; + public final double perWaitingTimeUnit; + public final double perServiceTimeUnit; - /** - * Sets the maximum velocity this vehicle-type can go [in meter per seconds]. - * - * @param inMeterPerSeconds - * @return this builder - * @throws IllegalStateException if velocity is smaller than zero - */ - public VehicleTypeImpl.Builder setMaxVelocity(double inMeterPerSeconds){ - if(inMeterPerSeconds < 0.0) throw new IllegalStateException("velocity cannot be smaller than zero"); - this.maxVelo = inMeterPerSeconds; return this; - } - - /** - * Sets the fixed costs of the vehicle-type. - * - *

by default it is 0. - * - * @param fixedCost - * @return this builder - * @throws IllegalStateException if fixedCost is smaller than zero - */ - public VehicleTypeImpl.Builder setFixedCost(double fixedCost) { - if(fixedCost < 0.0) throw new IllegalStateException("fixed costs cannot be smaller than zero"); - this.fixedCost = fixedCost; - return this; - } + private VehicleCostParams(double fix, double perTimeUnit, double perDistanceUnit) { + super(); + this.fix = fix; + this.perTimeUnit = perTimeUnit; + this.perTransportTimeUnit = perTimeUnit; + this.perDistanceUnit = perDistanceUnit; + this.perWaitingTimeUnit = 0.; + this.perServiceTimeUnit = 0.; + } - /** - * Sets the cost per distance unit, for instance € per meter. - * - *

by default it is 1.0 - * - * @param perDistance - * @return this builder - * @throws IllegalStateException if perDistance is smaller than zero - */ - public VehicleTypeImpl.Builder setCostPerDistance(double perDistance){ - if(perDistance < 0.0) throw new IllegalStateException("cost per distance must not be smaller than zero"); - this.perDistance = perDistance; - return this; - } + public VehicleCostParams(double fix, double perTimeUnit, double perDistanceUnit, double perWaitingTimeUnit) { + this.fix = fix; + this.perTimeUnit = perTimeUnit; + this.perTransportTimeUnit = perTimeUnit; + this.perDistanceUnit = perDistanceUnit; + this.perWaitingTimeUnit = perWaitingTimeUnit; + this.perServiceTimeUnit = 0.; + } - /** - * Sets cost per time unit, for instance € per second. - * - *

by default it is 0.0 - * - * @param perTime - * @return this builder - * @throws IllegalStateException if costPerTime is smaller than zero - */ - public VehicleTypeImpl.Builder setCostPerTime(double perTime){ - if(perTime < 0.0) throw new IllegalStateException(); - this.perTime = perTime; - return this; - } - - /** - * Builds the vehicle-type. - * - * @return VehicleTypeImpl - */ - public VehicleTypeImpl build(){ - if(capacityDimensions == null){ - capacityDimensions = capacityBuilder.build(); - } - return new VehicleTypeImpl(this); - } + public VehicleCostParams(double fix, double perTimeUnit, double perDistanceUnit, double perWaitingTimeUnit, double perServiceTimeUnit) { + this.fix = fix; + this.perTimeUnit = perTimeUnit; + this.perTransportTimeUnit = perTimeUnit; + this.perDistanceUnit = perDistanceUnit; + this.perWaitingTimeUnit = perWaitingTimeUnit; + this.perServiceTimeUnit = perServiceTimeUnit; + } - /** - * Adds a capacity dimension. - * - * @param dimIndex - * @param dimVal - * @return the builder - * @throws IllegalArgumentException if dimVal < 0 - * @throws IllegalStateException if capacity dimension is already set - */ - public Builder addCapacityDimension(int dimIndex, int dimVal) { - if(dimVal<0) throw new IllegalArgumentException("capacity value cannot be negative"); - if(capacityDimensions != null) throw new IllegalStateException("either build your dimension with build your dimensions with " + - "addCapacityDimension(int dimIndex, int dimVal) or set the already built dimensions with .setCapacityDimensions(Capacity capacity)." + - "You used both methods."); - dimensionAdded = true; - capacityBuilder.addDimension(dimIndex,dimVal); - return this; - } + @Override + public String toString() { + return "[fixed=" + fix + "][perTime=" + perTransportTimeUnit + "][perDistance=" + perDistanceUnit + "][perWaitingTimeUnit=" + perWaitingTimeUnit + "]"; + } + } - /** - * Sets capacity dimensions. - * - *

Note if you use this you cannot use addCapacityDimension(int dimIndex, int dimVal) anymore. Thus either build - * your dimensions with addCapacityDimension(int dimIndex, int dimVal) or set the already built dimensions with - * this method. - * - * @param capacity - * @return this builder - * @throws IllegalStateException if capacityDimension has already been added - */ - public Builder setCapacityDimensions(Capacity capacity){ - if(dimensionAdded) throw new IllegalStateException("either build your dimension with build your dimensions with " + - "addCapacityDimension(int dimIndex, int dimVal) or set the already built dimensions with .setCapacityDimensions(Capacity capacity)." + - "You used both methods."); - this.capacityDimensions = capacity; - return this; - } + /** + * Builder that builds the vehicle-type. + * + * @author schroeder + */ + public static class Builder { - public Builder setProfile(String profile){ - this.profile = profile; - return this; - } - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result - + ((typeId == null) ? 0 : typeId.hashCode()); - return result; - } - /** - * Two vehicle-types are equal if they have the same vehicleId. - */ - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - VehicleTypeImpl other = (VehicleTypeImpl) obj; - if (typeId == null) { - if (other.typeId != null) - return false; - } else if (!typeId.equals(other.typeId)) - return false; - return true; - } + public static VehicleTypeImpl.Builder newInstance(String id) { + if (id == null) throw new IllegalStateException(); + return new Builder(id); + } - private final String typeId; - - private final int capacity; + private String id; + private int capacity = 0; + private double maxVelo = Double.MAX_VALUE; + /** + * default cost values for default vehicle type + */ + private double fixedCost = 0.0; + private double perDistance = 1.0; + private double perTime = 0.0; + private double perWaitingTime = 0.0; + private double perServiceTime = 0.0; - private final String profile; - - private final VehicleTypeImpl.VehicleCostParams vehicleCostParams; - - private final Capacity capacityDimensions; + private String profile = "car"; - private final double maxVelocity; - - /** - * priv constructor constructing vehicle-type - * - * @param builder - */ - private VehicleTypeImpl(VehicleTypeImpl.Builder builder){ - typeId = builder.id; - capacity = builder.capacity; - maxVelocity = builder.maxVelo; - vehicleCostParams = new VehicleCostParams(builder.fixedCost, builder.perTime, builder.perDistance); - capacityDimensions = builder.capacityDimensions; - profile = builder.profile; - } + private Capacity.Builder capacityBuilder = Capacity.Builder.newInstance(); - /* (non-Javadoc) - * @see basics.route.VehicleType#getTypeId() - */ - @Override - public String getTypeId() { - return typeId; - } + private Capacity capacityDimensions = null; - /* (non-Javadoc) - * @see basics.route.VehicleType#getVehicleCostParams() - */ - @Override - public VehicleTypeImpl.VehicleCostParams getVehicleCostParams() { - return vehicleCostParams; - } + private boolean dimensionAdded = false; - @Override - public String toString() { - return "[typeId="+typeId+"]" + - "[capacity="+capacityDimensions+"]" + - "[costs=" + vehicleCostParams + "]"; - } + private Builder(String id) { + this.id = id; + } - @Override - public double getMaxVelocity() { - return maxVelocity; - } + /** + * Sets the maximum velocity this vehicle-type can go [in meter per seconds]. + * + * @param inMeterPerSeconds + * @return this builder + * @throws IllegalStateException if velocity is smaller than zero + */ + public VehicleTypeImpl.Builder setMaxVelocity(double inMeterPerSeconds) { + if (inMeterPerSeconds < 0.0) throw new IllegalStateException("velocity cannot be smaller than zero"); + this.maxVelo = inMeterPerSeconds; + return this; + } - @Override - public Capacity getCapacityDimensions() { - return capacityDimensions; - } + /** + * Sets the fixed costs of the vehicle-type. + *

+ *

by default it is 0. + * + * @param fixedCost + * @return this builder + * @throws IllegalStateException if fixedCost is smaller than zero + */ + public VehicleTypeImpl.Builder setFixedCost(double fixedCost) { + if (fixedCost < 0.0) throw new IllegalStateException("fixed costs cannot be smaller than zero"); + this.fixedCost = fixedCost; + return this; + } - @Override - public String getProfile(){ return profile; } + /** + * Sets the cost per distance unit, for instance € per meter. + *

+ *

by default it is 1.0 + * + * @param perDistance + * @return this builder + * @throws IllegalStateException if perDistance is smaller than zero + */ + public VehicleTypeImpl.Builder setCostPerDistance(double perDistance) { + if (perDistance < 0.0) throw new IllegalStateException("cost per distance must not be smaller than zero"); + this.perDistance = perDistance; + return this; + } + + /** + * Sets cost per time unit, for instance € per second. + *

+ *

by default it is 0.0 + * + * @param perTime + * @return this builder + * @throws IllegalStateException if costPerTime is smaller than zero + * @deprecated use .setCostPerTransportTime(..) instead + */ + @Deprecated + public VehicleTypeImpl.Builder setCostPerTime(double perTime) { + if (perTime < 0.0) throw new IllegalStateException(); + this.perTime = perTime; + return this; + } + + /** + * Sets cost per time unit, for instance € per second. + *

+ *

by default it is 0.0 + * + * @param perTime + * @return this builder + * @throws IllegalStateException if costPerTime is smaller than zero + */ + public VehicleTypeImpl.Builder setCostPerTransportTime(double perTime) { + if (perTime < 0.0) throw new IllegalStateException(); + this.perTime = perTime; + return this; + } + + /** + * Sets cost per waiting time unit, for instance € per second. + *

+ *

by default it is 0.0 + * + * @param perWaitingTime + * @return this builder + * @throws IllegalStateException if costPerTime is smaller than zero + */ + public VehicleTypeImpl.Builder setCostPerWaitingTime(double perWaitingTime) { + if (perWaitingTime < 0.0) throw new IllegalStateException(); + this.perWaitingTime = perWaitingTime; + return this; + } + + public VehicleTypeImpl.Builder setCostPerServiceTime(double perServiceTime) { + this.perServiceTime = perServiceTime; + return this; + } + + /** + * Builds the vehicle-type. + * + * @return VehicleTypeImpl + */ + public VehicleTypeImpl build() { + if (capacityDimensions == null) { + capacityDimensions = capacityBuilder.build(); + } + return new VehicleTypeImpl(this); + } + + /** + * Adds a capacity dimension. + * + * @param dimIndex + * @param dimVal + * @return the builder + * @throws IllegalArgumentException if dimVal < 0 + * @throws IllegalStateException if capacity dimension is already set + */ + public Builder addCapacityDimension(int dimIndex, int dimVal) { + if (dimVal < 0) throw new IllegalArgumentException("capacity value cannot be negative"); + if (capacityDimensions != null) + throw new IllegalStateException("either build your dimension with build your dimensions with " + + "addCapacityDimension(int dimIndex, int dimVal) or set the already built dimensions with .setCapacityDimensions(Capacity capacity)." + + "You used both methods."); + dimensionAdded = true; + capacityBuilder.addDimension(dimIndex, dimVal); + return this; + } + + /** + * Sets capacity dimensions. + *

+ *

Note if you use this you cannot use addCapacityDimension(int dimIndex, int dimVal) anymore. Thus either build + * your dimensions with addCapacityDimension(int dimIndex, int dimVal) or set the already built dimensions with + * this method. + * + * @param capacity + * @return this builder + * @throws IllegalStateException if capacityDimension has already been added + */ + public Builder setCapacityDimensions(Capacity capacity) { + if (dimensionAdded) + throw new IllegalStateException("either build your dimension with build your dimensions with " + + "addCapacityDimension(int dimIndex, int dimVal) or set the already built dimensions with .setCapacityDimensions(Capacity capacity)." + + "You used both methods."); + this.capacityDimensions = capacity; + return this; + } + + public Builder setProfile(String profile) { + this.profile = profile; + return this; + } + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + + ((typeId == null) ? 0 : typeId.hashCode()); + return result; + } + + /** + * Two vehicle-types are equal if they have the same vehicleId. + */ + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + VehicleTypeImpl other = (VehicleTypeImpl) obj; + if (typeId == null) { + if (other.typeId != null) + return false; + } else if (!typeId.equals(other.typeId)) + return false; + return true; + } + + private final String typeId; + + private final int capacity; + + private final String profile; + + private final VehicleTypeImpl.VehicleCostParams vehicleCostParams; + + private final Capacity capacityDimensions; + + private final double maxVelocity; + + /** + * priv constructor constructing vehicle-type + * + * @param builder + */ + private VehicleTypeImpl(VehicleTypeImpl.Builder builder) { + typeId = builder.id; + capacity = builder.capacity; + maxVelocity = builder.maxVelo; + vehicleCostParams = new VehicleCostParams(builder.fixedCost, builder.perTime, builder.perDistance, builder.perWaitingTime, builder.perServiceTime); + capacityDimensions = builder.capacityDimensions; + profile = builder.profile; + } + + /* (non-Javadoc) + * @see basics.route.VehicleType#getTypeId() + */ + @Override + public String getTypeId() { + return typeId; + } + + /* (non-Javadoc) + * @see basics.route.VehicleType#getVehicleCostParams() + */ + @Override + public VehicleTypeImpl.VehicleCostParams getVehicleCostParams() { + return vehicleCostParams; + } + + @Override + public String toString() { + return "[typeId=" + typeId + "]" + + "[capacity=" + capacityDimensions + "]" + + "[costs=" + vehicleCostParams + "]"; + } + + @Override + public double getMaxVelocity() { + return maxVelocity; + } + + @Override + public Capacity getCapacityDimensions() { + return capacityDimensions; + } + + @Override + public String getProfile() { + return profile; + } } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/vehicle/VehicleTypeKey.java b/jsprit-core/src/main/java/jsprit/core/problem/vehicle/VehicleTypeKey.java index ce050058..da9bfc0f 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/vehicle/VehicleTypeKey.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/vehicle/VehicleTypeKey.java @@ -1,18 +1,18 @@ /******************************************************************************* * Copyright (c) 2014 Stefan Schroeder. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . - * + * * Contributors: * Stefan Schroeder - initial API and implementation ******************************************************************************/ @@ -23,40 +23,42 @@ import jsprit.core.problem.Skills; /** * Key to identify similar vehicles - * + *

*

Two vehicles are equal if they share the same type, the same start and end-location and the same earliestStart and latestStart. - * - * @author stefan * + * @author stefan */ -public class VehicleTypeKey extends AbstractVehicle.AbstractTypeKey{ - - public final String type; - public final String startLocationId; - public final String endLocationId; - public final double earliestStart; - public final double latestEnd; +public class VehicleTypeKey extends AbstractVehicle.AbstractTypeKey { + + public final String type; + public final String startLocationId; + public final String endLocationId; + public final double earliestStart; + public final double latestEnd; public final Skills skills; - - public VehicleTypeKey(String typeId, String startLocationId, String endLocationId, double earliestStart, double latestEnd, Skills skills) { - super(); - this.type = typeId; - this.startLocationId = startLocationId; - this.endLocationId = endLocationId; - this.earliestStart = earliestStart; - this.latestEnd = latestEnd; + public final boolean returnToDepot; + + public VehicleTypeKey(String typeId, String startLocationId, String endLocationId, double earliestStart, double latestEnd, Skills skills, boolean returnToDepot) { + super(); + this.type = typeId; + this.startLocationId = startLocationId; + this.endLocationId = endLocationId; + this.earliestStart = earliestStart; + this.latestEnd = latestEnd; this.skills = skills; - } + this.returnToDepot = returnToDepot; + } @Override public boolean equals(Object o) { if (this == o) return true; - if (!(o instanceof VehicleTypeKey)) return false; + if (o == null || getClass() != o.getClass()) return false; VehicleTypeKey that = (VehicleTypeKey) o; if (Double.compare(that.earliestStart, earliestStart) != 0) return false; if (Double.compare(that.latestEnd, latestEnd) != 0) return false; + if (returnToDepot != that.returnToDepot) return false; if (!endLocationId.equals(that.endLocationId)) return false; if (!skills.equals(that.skills)) return false; if (!startLocationId.equals(that.startLocationId)) return false; @@ -77,17 +79,17 @@ public class VehicleTypeKey extends AbstractVehicle.AbstractTypeKey{ temp = Double.doubleToLongBits(latestEnd); result = 31 * result + (int) (temp ^ (temp >>> 32)); result = 31 * result + skills.hashCode(); + result = 31 * result + (returnToDepot ? 1 : 0); return result; } @Override - public String toString() { - StringBuilder stringBuilder = new StringBuilder(); - stringBuilder.append(type).append("_").append(startLocationId).append("_").append(endLocationId) - .append("_").append(Double.toString(earliestStart)).append("_").append(Double.toString(latestEnd)); - return stringBuilder.toString(); - } + public String toString() { + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append(type).append("_").append(startLocationId).append("_").append(endLocationId) + .append("_").append(Double.toString(earliestStart)).append("_").append(Double.toString(latestEnd)); + return stringBuilder.toString(); + } + - - } diff --git a/jsprit-core/src/main/java/jsprit/core/reporting/SolutionPrinter.java b/jsprit-core/src/main/java/jsprit/core/reporting/SolutionPrinter.java index 20ffeb3b..0f3d24f6 100644 --- a/jsprit-core/src/main/java/jsprit/core/reporting/SolutionPrinter.java +++ b/jsprit-core/src/main/java/jsprit/core/reporting/SolutionPrinter.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.reporting; @@ -25,135 +25,185 @@ import jsprit.core.problem.solution.route.VehicleRoute; import jsprit.core.problem.solution.route.activity.TourActivity; import jsprit.core.problem.solution.route.activity.TourActivity.JobActivity; +import java.io.PrintWriter; + /** * Printer to print the details of a vehicle-routing-problem solution. - * - * @author stefan schroeder * + * @author stefan schroeder */ public class SolutionPrinter { - - /** - * Enum to indicate verbose-level. - * - *

Print.CONCISE and Print.VERBOSE are available. - * - * @author stefan schroeder - * - */ - public enum Print { - - CONCISE,VERBOSE - } - - /** - * Prints costs and #vehicles to stdout (System.out.println). - * - * @param solution the solution to be printed - */ - public static void print(VehicleRoutingProblemSolution solution){ - System.out.println("[costs="+solution.getCost() + "]"); - System.out.println("[#vehicles="+solution.getRoutes().size() + "]"); - - } - - private static class Jobs { - int nServices; - int nShipments; - public Jobs(int nServices, int nShipments) { - super(); - this.nServices = nServices; - this.nShipments = nShipments; - } - } - - public static void print(VehicleRoutingProblem problem, VehicleRoutingProblemSolution solution, Print print){ - String leftAlign = "| %-13s | %-8s | %n"; - - System.out.format("+--------------------------+%n"); - System.out.printf("| problem |%n"); - System.out.format("+---------------+----------+%n"); - System.out.printf("| indicator | value |%n"); - System.out.format("+---------------+----------+%n"); - - System.out.format(leftAlign, "noJobs", problem.getJobs().values().size()); - Jobs jobs = getNuOfJobs(problem); - System.out.format(leftAlign, "noServices",jobs.nServices); - System.out.format(leftAlign, "noShipments",jobs.nShipments); - System.out.format(leftAlign, "fleetsize",problem.getFleetSize().toString()); - System.out.format("+--------------------------+%n"); - - - String leftAlignSolution = "| %-13s | %-40s | %n"; - System.out.format("+----------------------------------------------------------+%n"); - System.out.printf("| solution |%n"); - System.out.format("+---------------+------------------------------------------+%n"); - System.out.printf("| indicator | value |%n"); - System.out.format("+---------------+------------------------------------------+%n"); - System.out.format(leftAlignSolution, "costs",solution.getCost()); - System.out.format(leftAlignSolution, "noVehicles",solution.getRoutes().size()); - System.out.format(leftAlignSolution, "unassgndJobs", solution.getUnassignedJobs().size()); - System.out.format("+----------------------------------------------------------+%n"); - - if(print.equals(Print.VERBOSE)){ - printVerbose(problem,solution); - } - } - private static void printVerbose(VehicleRoutingProblem problem, VehicleRoutingProblemSolution solution) { - String leftAlgin = "| %-7s | %-20s | %-21s | %-15s | %-15s | %-15s | %-15s |%n"; - System.out.format("+--------------------------------------------------------------------------------------------------------------------------------+%n"); - System.out.printf("| detailed solution |%n"); - System.out.format("+---------+----------------------+-----------------------+-----------------+-----------------+-----------------+-----------------+%n"); - System.out.printf("| route | vehicle | activity | job | arrTime | endTime | costs |%n"); - int routeNu = 1; - for(VehicleRoute route : solution.getRoutes()){ - System.out.format("+---------+----------------------+-----------------------+-----------------+-----------------+-----------------+-----------------+%n"); - double costs = 0; - System.out.format(leftAlgin, routeNu, getVehicleString(route), route.getStart().getName(), "-", "undef", Math.round(route.getStart().getEndTime()),Math.round(costs)); - TourActivity prevAct = route.getStart(); - for(TourActivity act : route.getActivities()){ - String jobId; - if(act instanceof JobActivity) jobId = ((JobActivity)act).getJob().getId(); - else jobId = "-"; - double c = problem.getTransportCosts().getTransportCost(prevAct.getLocation(), act.getLocation(), prevAct.getEndTime(), route.getDriver(), route.getVehicle()); - c+= problem.getActivityCosts().getActivityCost(act, act.getArrTime(), route.getDriver(), route.getVehicle()); - costs+=c; - System.out.format(leftAlgin, routeNu, getVehicleString(route), act.getName(), jobId, Math.round(act.getArrTime()), Math.round(act.getEndTime()),Math.round(costs)); - prevAct=act; - } - double c = problem.getTransportCosts().getTransportCost(prevAct.getLocation(), route.getEnd().getLocation(), prevAct.getEndTime(), route.getDriver(), route.getVehicle()); - c+= problem.getActivityCosts().getActivityCost(route.getEnd(), route.getEnd().getArrTime(), route.getDriver(), route.getVehicle()); - costs+=c; - System.out.format(leftAlgin, routeNu, getVehicleString(route), route.getEnd().getName(), "-", Math.round(route.getEnd().getArrTime()), "undef", Math.round(costs)); - routeNu++; - } - System.out.format("+--------------------------------------------------------------------------------------------------------------------------------+%n"); - if(!solution.getUnassignedJobs().isEmpty()) { - System.out.format("+----------------+%n"); - System.out.format("| unassignedJobs |%n"); - System.out.format("+----------------+%n"); - String unassignedJobAlgin = "| %-14s |%n"; - for (Job j : solution.getUnassignedJobs()) { - System.out.format(unassignedJobAlgin, j.getId()); - } - System.out.format("+----------------+%n"); - } - } + // Wrapping System.out into a PrintWriter + private static final PrintWriter SYSTEM_OUT_AS_PRINT_WRITER = new PrintWriter(System.out); - private static String getVehicleString(VehicleRoute route) { - return route.getVehicle().getId(); + /** + * Enum to indicate verbose-level. + *

+ *

+ * Print.CONCISE and Print.VERBOSE are available. + * + * @author stefan schroeder + */ + public enum Print { + + CONCISE, VERBOSE + } + + private static class Jobs { + int nServices; + int nShipments; + + public Jobs(int nServices, int nShipments) { + super(); + this.nServices = nServices; + this.nShipments = nShipments; + } + } + + + /** + * Prints costs and #vehicles to stdout (out.println). + * + * @param solution the solution to be printed + */ + public static void print(VehicleRoutingProblemSolution solution) { + print(SYSTEM_OUT_AS_PRINT_WRITER, solution); + SYSTEM_OUT_AS_PRINT_WRITER.flush(); + } + + /** + * Prints costs and #vehicles to the given writer + * + * @param out the destination writer + * @param solution the solution to be printed + */ + public static void print(PrintWriter out, VehicleRoutingProblemSolution solution) { + out.println("[costs=" + solution.getCost() + "]"); + out.println("[#vehicles=" + solution.getRoutes().size() + "]"); + } + + /** + * Prints costs and #vehicles to the to stdout (out.println). + * + * @param out the destination writer + * @param solution the solution to be printed + */ + public static void print(VehicleRoutingProblem problem, VehicleRoutingProblemSolution solution, Print print) { + print(SYSTEM_OUT_AS_PRINT_WRITER, problem, solution, print); + SYSTEM_OUT_AS_PRINT_WRITER.flush(); + } + + /** + * Prints costs and #vehicles to the given writer + * + * @param out the destination writer + * @param solution the solution to be printed + */ + public static void print(PrintWriter out, VehicleRoutingProblem problem, VehicleRoutingProblemSolution solution, Print print) { + String leftAlign = "| %-13s | %-8s | %n"; + + out.format("+--------------------------+%n"); + out.printf("| problem |%n"); + out.format("+---------------+----------+%n"); + out.printf("| indicator | value |%n"); + out.format("+---------------+----------+%n"); + + out.format(leftAlign, "noJobs", problem.getJobs().values().size()); + Jobs jobs = getNuOfJobs(problem); + out.format(leftAlign, "noServices", jobs.nServices); + out.format(leftAlign, "noShipments", jobs.nShipments); + out.format(leftAlign, "fleetsize", problem.getFleetSize().toString()); + out.format("+--------------------------+%n"); + + + String leftAlignSolution = "| %-13s | %-40s | %n"; + out.format("+----------------------------------------------------------+%n"); + out.printf("| solution |%n"); + out.format("+---------------+------------------------------------------+%n"); + out.printf("| indicator | value |%n"); + out.format("+---------------+------------------------------------------+%n"); + out.format(leftAlignSolution, "costs", solution.getCost()); + out.format(leftAlignSolution, "noVehicles", solution.getRoutes().size()); + out.format(leftAlignSolution, "unassgndJobs", solution.getUnassignedJobs().size()); + out.format("+----------------------------------------------------------+%n"); + + if (print.equals(Print.VERBOSE)) { + printVerbose(out, problem, solution); + } + } + + private static void printVerbose(VehicleRoutingProblem problem, VehicleRoutingProblemSolution solution) { + printVerbose(SYSTEM_OUT_AS_PRINT_WRITER, problem, solution); + SYSTEM_OUT_AS_PRINT_WRITER.flush(); + } + + private static void printVerbose(PrintWriter out, VehicleRoutingProblem problem, VehicleRoutingProblemSolution solution) { + String leftAlgin = "| %-7s | %-20s | %-21s | %-15s | %-15s | %-15s | %-15s |%n"; + out.format("+--------------------------------------------------------------------------------------------------------------------------------+%n"); + out.printf("| detailed solution |%n"); + out.format("+---------+----------------------+-----------------------+-----------------+-----------------+-----------------+-----------------+%n"); + out.printf("| route | vehicle | activity | job | arrTime | endTime | costs |%n"); + int routeNu = 1; + for (VehicleRoute route : solution.getRoutes()) { + out.format("+---------+----------------------+-----------------------+-----------------+-----------------+-----------------+-----------------+%n"); + double costs = 0; + out.format(leftAlgin, routeNu, getVehicleString(route), route.getStart().getName(), "-", "undef", Math.round(route.getStart().getEndTime()), + Math.round(costs)); + TourActivity prevAct = route.getStart(); + for (TourActivity act : route.getActivities()) { + String jobId; + if (act instanceof JobActivity) { + jobId = ((JobActivity) act).getJob().getId(); + } else { + jobId = "-"; + } + double c = problem.getTransportCosts().getTransportCost(prevAct.getLocation(), act.getLocation(), prevAct.getEndTime(), route.getDriver(), + route.getVehicle()); + c += problem.getActivityCosts().getActivityCost(act, act.getArrTime(), route.getDriver(), route.getVehicle()); + costs += c; + out.format(leftAlgin, routeNu, getVehicleString(route), act.getName(), jobId, Math.round(act.getArrTime()), + Math.round(act.getEndTime()), Math.round(costs)); + prevAct = act; + } + double c = problem.getTransportCosts().getTransportCost(prevAct.getLocation(), route.getEnd().getLocation(), prevAct.getEndTime(), + route.getDriver(), route.getVehicle()); + c += problem.getActivityCosts().getActivityCost(route.getEnd(), route.getEnd().getArrTime(), route.getDriver(), route.getVehicle()); + costs += c; + out.format(leftAlgin, routeNu, getVehicleString(route), route.getEnd().getName(), "-", Math.round(route.getEnd().getArrTime()), "undef", + Math.round(costs)); + routeNu++; + } + out.format("+--------------------------------------------------------------------------------------------------------------------------------+%n"); + if (!solution.getUnassignedJobs().isEmpty()) { + out.format("+----------------+%n"); + out.format("| unassignedJobs |%n"); + out.format("+----------------+%n"); + String unassignedJobAlgin = "| %-14s |%n"; + for (Job j : solution.getUnassignedJobs()) { + out.format(unassignedJobAlgin, j.getId()); + } + out.format("+----------------+%n"); + } + } + + private static String getVehicleString(VehicleRoute route) { + return route.getVehicle().getId(); + } + + private static Jobs getNuOfJobs(VehicleRoutingProblem problem) { + int nShipments = 0; + int nServices = 0; + for (Job j : problem.getJobs().values()) { + if (j instanceof Shipment) { + nShipments++; + } + if (j instanceof Service) { + nServices++; + } + } + return new Jobs(nServices, nShipments); } - private static Jobs getNuOfJobs(VehicleRoutingProblem problem) { - int nShipments = 0; - int nServices = 0; - for(Job j : problem.getJobs().values()){ - if(j instanceof Shipment) nShipments++; - if(j instanceof Service) nServices++; - } - return new Jobs(nServices,nShipments); - } - } diff --git a/jsprit-core/src/main/java/jsprit/core/util/ActivityTimeTracker.java b/jsprit-core/src/main/java/jsprit/core/util/ActivityTimeTracker.java index 9fda4ea9..97734570 100644 --- a/jsprit-core/src/main/java/jsprit/core/util/ActivityTimeTracker.java +++ b/jsprit-core/src/main/java/jsprit/core/util/ActivityTimeTracker.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.util; @@ -24,7 +24,7 @@ import jsprit.core.problem.solution.route.VehicleRoute; import jsprit.core.problem.solution.route.activity.ActivityVisitor; import jsprit.core.problem.solution.route.activity.TourActivity; -public class ActivityTimeTracker implements ActivityVisitor{ +public class ActivityTimeTracker implements ActivityVisitor { public static enum ActivityPolicy { @@ -32,22 +32,22 @@ public class ActivityTimeTracker implements ActivityVisitor{ } - private ForwardTransportTime transportTime; - - private TourActivity prevAct = null; - - private double startAtPrevAct; - - private VehicleRoute route; - - private boolean beginFirst = false; - - private double actArrTime; - - private double actEndTime; + private ForwardTransportTime transportTime; + + private TourActivity prevAct = null; + + private double startAtPrevAct; + + private VehicleRoute route; + + private boolean beginFirst = false; + + private double actArrTime; + + private double actEndTime; + + private ActivityStartStrategy startStrategy; - private ActivityStartStrategy startStrategy; - public ActivityTimeTracker(ForwardTransportTime transportTime) { super(); this.transportTime = transportTime; @@ -63,61 +63,51 @@ public class ActivityTimeTracker implements ActivityVisitor{ else this.startStrategy = new ActivityStartsAsSoonAsNextTimeWindowOpens(); } - public ActivityTimeTracker(ForwardTransportTime transportTime, ActivityStartStrategy startStrategy) { - super(); - this.transportTime = transportTime; - this.startStrategy = startStrategy; - } + public ActivityTimeTracker(ForwardTransportTime transportTime, ActivityStartStrategy startStrategy) { + super(); + this.transportTime = transportTime; + this.startStrategy = startStrategy; + } - public double getActArrTime(){ - return actArrTime; - } - - public double getActEndTime(){ - return actEndTime; - } - - @Override - public void begin(VehicleRoute route) { - prevAct = route.getStart(); -// System.out.println(prevAct); - startAtPrevAct = prevAct.getEndTime(); + public double getActArrTime() { + return actArrTime; + } + + public double getActEndTime() { + return actEndTime; + } + + @Override + public void begin(VehicleRoute route) { + prevAct = route.getStart(); + startAtPrevAct = prevAct.getEndTime(); actEndTime = startAtPrevAct; this.route = route; beginFirst = true; - } + } - @Override - public void visit(TourActivity activity) { - if(!beginFirst) throw new IllegalStateException("never called begin. this however is essential here"); - double transportTime = this.transportTime.getTransportTime(prevAct.getLocation(), activity.getLocation(), startAtPrevAct, route.getDriver(), route.getVehicle()); - double arrivalTimeAtCurrAct = startAtPrevAct + transportTime; - actArrTime = arrivalTimeAtCurrAct; -// System.out.println("oldArrTime: " + activity.getArrTime()); -// System.out.println(actArrTime + " " + activity + " tws: " + activity.getTimeWindows().toString()); + @Override + public void visit(TourActivity activity) { + if(!beginFirst) throw new IllegalStateException("never called begin. this however is essential here"); + double transportTime = this.transportTime.getTransportTime(prevAct.getLocation(), activity.getLocation(), startAtPrevAct, route.getDriver(), route.getVehicle()); + double arrivalTimeAtCurrAct = startAtPrevAct + transportTime; + actArrTime = arrivalTimeAtCurrAct; + assert actArrTime <= activity.getTimeWindows().get(activity.getTimeWindows().size()-1).getEnd() : "that should not be"; + double operationEndTime = startStrategy.getActivityStartTime(activity,arrivalTimeAtCurrAct) + activity.getOperationTime(); + actEndTime = operationEndTime; + prevAct = activity; + startAtPrevAct = operationEndTime; + } - assert actArrTime <= activity.getTimeWindows().get(activity.getTimeWindows().size()-1).getEnd() : "that should not be"; + @Override + public void finish() { + double transportTime = this.transportTime.getTransportTime(prevAct.getLocation(), route.getEnd().getLocation(), startAtPrevAct, route.getDriver(), route.getVehicle()); + double arrivalTimeAtCurrAct = startAtPrevAct + transportTime; + actArrTime = arrivalTimeAtCurrAct; + assert actArrTime <= route.getVehicle().getLatestArrival() : "oohh. this should not be"; + actEndTime = arrivalTimeAtCurrAct; + beginFirst = false; + } - double operationEndTime = startStrategy.getActivityStartTime(activity,arrivalTimeAtCurrAct) + activity.getOperationTime(); - actEndTime = operationEndTime; - prevAct = activity; - startAtPrevAct = operationEndTime; - } - - @Override - public void finish() { - double transportTime = this.transportTime.getTransportTime(prevAct.getLocation(), route.getEnd().getLocation(), startAtPrevAct, route.getDriver(), route.getVehicle()); - double arrivalTimeAtCurrAct = startAtPrevAct + transportTime; - actArrTime = arrivalTimeAtCurrAct; - -// System.out.println("end arr time: " + actArrTime); - assert actArrTime <= route.getVehicle().getLatestArrival() : "oohh. this should not be"; - - actEndTime = arrivalTimeAtCurrAct; - beginFirst = false; - } - - - } diff --git a/jsprit-core/src/main/java/jsprit/core/util/ArrayUtils.java b/jsprit-core/src/main/java/jsprit/core/util/ArrayUtils.java index e995448e..8d695946 100644 --- a/jsprit-core/src/main/java/jsprit/core/util/ArrayUtils.java +++ b/jsprit-core/src/main/java/jsprit/core/util/ArrayUtils.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.util; @@ -21,20 +21,20 @@ import java.util.List; public class ArrayUtils { - public static double[] toPrimitiveArray(List list){ - double[] arr = new double[list.size()]; - for(int i=0;i list) { + double[] arr = new double[list.size()]; + for (int i = 0; i < list.size(); i++) arr[i] = list.get(i); + return arr; + } + + public static double[] toPrimitiveArray(Collection collection) { + double[] arr = new double[collection.size()]; + int i = 0; + for (Double d : collection) { + arr[i] = d; + i++; + } + return arr; + } - public static double[] toPrimitiveArray(Collection collection){ - double[] arr = new double[collection.size()]; - int i=0; - for(Double d : collection){ - arr[i]=d; - i++; - } - return arr; - } - } diff --git a/jsprit-core/src/main/java/jsprit/core/util/BenchmarkInstance.java b/jsprit-core/src/main/java/jsprit/core/util/BenchmarkInstance.java index 02279bda..9e90c255 100644 --- a/jsprit-core/src/main/java/jsprit/core/util/BenchmarkInstance.java +++ b/jsprit-core/src/main/java/jsprit/core/util/BenchmarkInstance.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.util; @@ -19,15 +19,16 @@ package jsprit.core.util; import jsprit.core.problem.VehicleRoutingProblem; public class BenchmarkInstance { - public final String name; - public final VehicleRoutingProblem vrp; - public final Double bestKnownResult; - public Double bestKnownVehicles; - public BenchmarkInstance(String name, VehicleRoutingProblem vrp, Double bestKnownResult, Double bestKnowVehicles) { - super(); - this.name = name; - this.vrp = vrp; - this.bestKnownResult = bestKnownResult; - this.bestKnownVehicles = bestKnowVehicles; - } + public final String name; + public final VehicleRoutingProblem vrp; + public final Double bestKnownResult; + public Double bestKnownVehicles; + + public BenchmarkInstance(String name, VehicleRoutingProblem vrp, Double bestKnownResult, Double bestKnowVehicles) { + super(); + this.name = name; + this.vrp = vrp; + this.bestKnownResult = bestKnownResult; + this.bestKnownVehicles = bestKnowVehicles; + } } diff --git a/jsprit-core/src/main/java/jsprit/core/util/BenchmarkResult.java b/jsprit-core/src/main/java/jsprit/core/util/BenchmarkResult.java index 6192db4e..c7c03d57 100644 --- a/jsprit-core/src/main/java/jsprit/core/util/BenchmarkResult.java +++ b/jsprit-core/src/main/java/jsprit/core/util/BenchmarkResult.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.util; @@ -19,54 +19,53 @@ package jsprit.core.util; import org.apache.commons.math.stat.descriptive.DescriptiveStatistics; - public class BenchmarkResult { - private double[] results; - private double[] vehicles; - private double[] times; - - private DescriptiveStatistics statsResults; - private DescriptiveStatistics statsVehicles; - private DescriptiveStatistics statsTimes; - - public final BenchmarkInstance instance; - - public final int runs; - - public BenchmarkResult(BenchmarkInstance instance, int runs, double[] results, double[] compTimes, double[] vehicles) { - super(); - this.results = results; - this.runs = runs; - this.times = compTimes; - this.instance = instance; - this.vehicles = vehicles; - this.statsResults = new DescriptiveStatistics(results); - this.statsTimes = new DescriptiveStatistics(times); - this.statsVehicles = new DescriptiveStatistics(vehicles); - } - - public double[] getResults(){ - return results; - } - - public double[] getVehicles(){ - return vehicles; - } - - public double[] getCompTimes(){ - return times; - } - - public DescriptiveStatistics getResultStats(){ - return statsResults; - } - - public DescriptiveStatistics getVehicleStats(){ - return statsVehicles; - } - - public DescriptiveStatistics getTimesStats(){ - return statsTimes; - } - + private double[] results; + private double[] vehicles; + private double[] times; + + private DescriptiveStatistics statsResults; + private DescriptiveStatistics statsVehicles; + private DescriptiveStatistics statsTimes; + + public final BenchmarkInstance instance; + + public final int runs; + + public BenchmarkResult(BenchmarkInstance instance, int runs, double[] results, double[] compTimes, double[] vehicles) { + super(); + this.results = results; + this.runs = runs; + this.times = compTimes; + this.instance = instance; + this.vehicles = vehicles; + this.statsResults = new DescriptiveStatistics(results); + this.statsTimes = new DescriptiveStatistics(times); + this.statsVehicles = new DescriptiveStatistics(vehicles); + } + + public double[] getResults() { + return results; + } + + public double[] getVehicles() { + return vehicles; + } + + public double[] getCompTimes() { + return times; + } + + public DescriptiveStatistics getResultStats() { + return statsResults; + } + + public DescriptiveStatistics getVehicleStats() { + return statsVehicles; + } + + public DescriptiveStatistics getTimesStats() { + return statsTimes; + } + } diff --git a/jsprit-core/src/main/java/jsprit/core/util/CalculationUtils.java b/jsprit-core/src/main/java/jsprit/core/util/CalculationUtils.java index de5a6a3a..70572bfa 100644 --- a/jsprit-core/src/main/java/jsprit/core/util/CalculationUtils.java +++ b/jsprit-core/src/main/java/jsprit/core/util/CalculationUtils.java @@ -22,17 +22,17 @@ import jsprit.core.algorithm.state.ActivityStartsAsSoonAsNextTimeWindowOpens; import jsprit.core.problem.solution.route.activity.TourActivity; public class CalculationUtils { - - /** - * Calculates actEndTime assuming that activity can at earliest start at act.getTheoreticalEarliestOperationStartTime(). - * - * @param actArrTime - * @param act - * @return - */ - public static double getActivityEndTime(double actArrTime, TourActivity act){ - return new ActivityStartsAsSoonAsNextTimeWindowOpens().getActivityStartTime(act,actArrTime) + act.getOperationTime(); + + /** + * Calculates actEndTime assuming that activity can at earliest start at act.getTheoreticalEarliestOperationStartTime(). + * + * @param actArrTime + * @param act + * @return + */ + public static double getActivityEndTime(double actArrTime, TourActivity act){ + return new ActivityStartsAsSoonAsNextTimeWindowOpens().getActivityStartTime(act, actArrTime) + act.getOperationTime(); // return Math.max(actArrTime, act.getTheoreticalEarliestOperationStartTime()) + act.getOperationTime(); - } + } } diff --git a/jsprit-core/src/main/java/jsprit/core/util/Coordinate.java b/jsprit-core/src/main/java/jsprit/core/util/Coordinate.java index 03d87ec9..431d9a06 100644 --- a/jsprit-core/src/main/java/jsprit/core/util/Coordinate.java +++ b/jsprit-core/src/main/java/jsprit/core/util/Coordinate.java @@ -1,76 +1,76 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.util; public class Coordinate { - public static Coordinate newInstance(double x, double y) { - return new Coordinate(x,y); - } + public static Coordinate newInstance(double x, double y) { + return new Coordinate(x, y); + } - private double x; + private double x; - private double y; + private double y; - public Coordinate(double x, double y) { - super(); - this.x = x; - this.y = y; - } + public Coordinate(double x, double y) { + super(); + this.x = x; + this.y = y; + } - public double getX() { - return x; - } + public double getX() { + return x; + } - public double getY() { - return y; - } - - @Override - public String toString() { - return "[x="+x+"][y="+y+"]"; - } + public double getY() { + return y; + } - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - long temp; - temp = Double.doubleToLongBits(x); - result = prime * result + (int) (temp ^ (temp >>> 32)); - temp = Double.doubleToLongBits(y); - result = prime * result + (int) (temp ^ (temp >>> 32)); - return result; - } + @Override + public String toString() { + return "[x=" + x + "][y=" + y + "]"; + } - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - Coordinate other = (Coordinate) obj; - if (Double.doubleToLongBits(x) != Double.doubleToLongBits(other.x)) - return false; - if (Double.doubleToLongBits(y) != Double.doubleToLongBits(other.y)) - return false; - return true; - } + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + long temp; + temp = Double.doubleToLongBits(x); + result = prime * result + (int) (temp ^ (temp >>> 32)); + temp = Double.doubleToLongBits(y); + result = prime * result + (int) (temp ^ (temp >>> 32)); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Coordinate other = (Coordinate) obj; + if (Double.doubleToLongBits(x) != Double.doubleToLongBits(other.x)) + return false; + if (Double.doubleToLongBits(y) != Double.doubleToLongBits(other.y)) + return false; + return true; + } } diff --git a/jsprit-core/src/main/java/jsprit/core/util/CrowFlyCosts.java b/jsprit-core/src/main/java/jsprit/core/util/CrowFlyCosts.java index f41f516b..2c4b7bb6 100644 --- a/jsprit-core/src/main/java/jsprit/core/util/CrowFlyCosts.java +++ b/jsprit-core/src/main/java/jsprit/core/util/CrowFlyCosts.java @@ -11,11 +11,11 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ /** - * + * */ package jsprit.core.util; @@ -26,78 +26,75 @@ import jsprit.core.problem.driver.Driver; import jsprit.core.problem.vehicle.Vehicle; - /** * @author stefan schroeder - * */ -public class CrowFlyCosts extends AbstractForwardVehicleRoutingTransportCosts implements TransportDistance{ +public class CrowFlyCosts extends AbstractForwardVehicleRoutingTransportCosts implements TransportDistance { - public int speed = 1; + public int speed = 1; - public double detourFactor = 1.0; + public double detourFactor = 1.0; - private Locations locations; + private Locations locations; - public CrowFlyCosts(Locations locations) { - super(); - this.locations = locations; - } - - @Override - public String toString() { - return "[name=crowFlyCosts]"; - } + public CrowFlyCosts(Locations locations) { + super(); + this.locations = locations; + } - @Override - public double getTransportCost(Location from, Location to, double time, Driver driver, Vehicle vehicle) { - double distance; - try { - distance = calculateDistance(from, to); - } catch (NullPointerException e) { - throw new NullPointerException("cannot calculate euclidean distance. coordinates are missing. either add coordinates or use another transport-cost-calculator."); - } - double costs = distance; - if(vehicle != null){ - if(vehicle.getType() != null){ - costs = distance * vehicle.getType().getVehicleCostParams().perDistanceUnit; - } - } - return costs; - } + @Override + public String toString() { + return "[name=crowFlyCosts]"; + } - private double calculateDistance(Location fromLocation, Location toLocation) { - Coordinate from = null; - Coordinate to = null; - if(fromLocation.getCoordinate() != null & toLocation.getCoordinate() != null){ - from = fromLocation.getCoordinate(); - to = toLocation.getCoordinate(); - } - else if(locations != null){ - from = locations.getCoord(fromLocation.getId()); - to = locations.getCoord(toLocation.getId()); - } - if(from == null || to == null) throw new NullPointerException(); - return calculateDistance(from,to); - } + @Override + public double getTransportCost(Location from, Location to, double time, Driver driver, Vehicle vehicle) { + double distance; + try { + distance = calculateDistance(from, to); + } catch (NullPointerException e) { + throw new NullPointerException("cannot calculate euclidean distance. coordinates are missing. either add coordinates or use another transport-cost-calculator."); + } + double costs = distance; + if (vehicle != null) { + if (vehicle.getType() != null) { + costs = distance * vehicle.getType().getVehicleCostParams().perDistanceUnit; + } + } + return costs; + } - private double calculateDistance(Coordinate from, Coordinate to) { - return EuclideanDistanceCalculator.calculateDistance(from,to) * detourFactor; - } + private double calculateDistance(Location fromLocation, Location toLocation) { + Coordinate from = null; + Coordinate to = null; + if (fromLocation.getCoordinate() != null & toLocation.getCoordinate() != null) { + from = fromLocation.getCoordinate(); + to = toLocation.getCoordinate(); + } else if (locations != null) { + from = locations.getCoord(fromLocation.getId()); + to = locations.getCoord(toLocation.getId()); + } + if (from == null || to == null) throw new NullPointerException(); + return calculateDistance(from, to); + } - @Override - public double getTransportTime(Location from, Location to, double time, Driver driver, Vehicle vehicle) { - double distance; - try { - distance = calculateDistance(from, to); - } catch (NullPointerException e) { - throw new NullPointerException("cannot calculate euclidean distance. coordinates are missing. either add coordinates or use another transport-cost-calculator."); - } - return distance / speed; - } + private double calculateDistance(Coordinate from, Coordinate to) { + return EuclideanDistanceCalculator.calculateDistance(from, to) * detourFactor; + } - @Override - public double getDistance(Location from, Location to) { - return calculateDistance(from,to); - } + @Override + public double getTransportTime(Location from, Location to, double time, Driver driver, Vehicle vehicle) { + double distance; + try { + distance = calculateDistance(from, to); + } catch (NullPointerException e) { + throw new NullPointerException("cannot calculate euclidean distance. coordinates are missing. either add coordinates or use another transport-cost-calculator."); + } + return distance / speed; + } + + @Override + public double getDistance(Location from, Location to) { + return calculateDistance(from, to); + } } diff --git a/jsprit-core/src/main/java/jsprit/core/util/DistanceUnit.java b/jsprit-core/src/main/java/jsprit/core/util/DistanceUnit.java index 18accdbb..66ec5a90 100644 --- a/jsprit-core/src/main/java/jsprit/core/util/DistanceUnit.java +++ b/jsprit-core/src/main/java/jsprit/core/util/DistanceUnit.java @@ -18,8 +18,8 @@ package jsprit.core.util; /** -* Created by schroeder on 04.12.14. -*/ + * Created by schroeder on 04.12.14. + */ public enum DistanceUnit { Meter("m"), Kilometer("km"); @@ -30,7 +30,7 @@ public enum DistanceUnit { this.abbr = abbr; } - public String abbreviation(){ + public String abbreviation() { return abbr; } } diff --git a/jsprit-core/src/main/java/jsprit/core/util/EuclideanCosts.java b/jsprit-core/src/main/java/jsprit/core/util/EuclideanCosts.java index 7b67e4a1..7cee59f0 100644 --- a/jsprit-core/src/main/java/jsprit/core/util/EuclideanCosts.java +++ b/jsprit-core/src/main/java/jsprit/core/util/EuclideanCosts.java @@ -11,11 +11,11 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ /** - * + * */ package jsprit.core.util; @@ -28,64 +28,63 @@ import jsprit.core.problem.vehicle.Vehicle; /** * @author stefan schroeder - * */ -public class EuclideanCosts extends AbstractForwardVehicleRoutingTransportCosts implements TransportDistance{ +public class EuclideanCosts extends AbstractForwardVehicleRoutingTransportCosts implements TransportDistance { - public int speed = 1; + public int speed = 1; - public double detourFactor = 1.0; - - @Override - public String toString() { - return "[name=crowFlyCosts]"; - } + public double detourFactor = 1.0; - @Override - public double getTransportCost(Location from, Location to, double time, Driver driver, Vehicle vehicle) { - double distance; - try { - distance = calculateDistance(from, to); - } catch (NullPointerException e) { - throw new NullPointerException("cannot calculate euclidean distance. coordinates are missing. either add coordinates or use another transport-cost-calculator."); - } - double costs = distance; - if(vehicle != null){ - if(vehicle.getType() != null){ - costs = distance * vehicle.getType().getVehicleCostParams().perDistanceUnit; - } - } - return costs; - } + @Override + public String toString() { + return "[name=crowFlyCosts]"; + } - private double calculateDistance(Location fromLocation, Location toLocation) { - Coordinate from = null; - Coordinate to = null; - if(fromLocation.getCoordinate() != null & toLocation.getCoordinate() != null){ - from = fromLocation.getCoordinate(); - to = toLocation.getCoordinate(); - } - if(from == null || to == null) throw new NullPointerException(); - return calculateDistance(from,to); - } + @Override + public double getTransportCost(Location from, Location to, double time, Driver driver, Vehicle vehicle) { + double distance; + try { + distance = calculateDistance(from, to); + } catch (NullPointerException e) { + throw new NullPointerException("cannot calculate euclidean distance. coordinates are missing. either add coordinates or use another transport-cost-calculator."); + } + double costs = distance; + if (vehicle != null) { + if (vehicle.getType() != null) { + costs = distance * vehicle.getType().getVehicleCostParams().perDistanceUnit; + } + } + return costs; + } - private double calculateDistance(Coordinate from, Coordinate to) { - return EuclideanDistanceCalculator.calculateDistance(from,to) * detourFactor; - } + private double calculateDistance(Location fromLocation, Location toLocation) { + Coordinate from = null; + Coordinate to = null; + if (fromLocation.getCoordinate() != null & toLocation.getCoordinate() != null) { + from = fromLocation.getCoordinate(); + to = toLocation.getCoordinate(); + } + if (from == null || to == null) throw new NullPointerException(); + return calculateDistance(from, to); + } - @Override - public double getTransportTime(Location from, Location to, double time, Driver driver, Vehicle vehicle) { - double distance; - try { - distance = calculateDistance(from, to); - } catch (NullPointerException e) { - throw new NullPointerException("cannot calculate euclidean distance. coordinates are missing. either add coordinates or use another transport-cost-calculator."); - } - return distance / speed; - } + private double calculateDistance(Coordinate from, Coordinate to) { + return EuclideanDistanceCalculator.calculateDistance(from, to) * detourFactor; + } - @Override - public double getDistance(Location from, Location to) { - return calculateDistance(from,to); - } + @Override + public double getTransportTime(Location from, Location to, double time, Driver driver, Vehicle vehicle) { + double distance; + try { + distance = calculateDistance(from, to); + } catch (NullPointerException e) { + throw new NullPointerException("cannot calculate euclidean distance. coordinates are missing. either add coordinates or use another transport-cost-calculator."); + } + return distance / speed; + } + + @Override + public double getDistance(Location from, Location to) { + return calculateDistance(from, to); + } } diff --git a/jsprit-core/src/main/java/jsprit/core/util/EuclideanDistanceCalculator.java b/jsprit-core/src/main/java/jsprit/core/util/EuclideanDistanceCalculator.java index a5419d99..638b7977 100644 --- a/jsprit-core/src/main/java/jsprit/core/util/EuclideanDistanceCalculator.java +++ b/jsprit-core/src/main/java/jsprit/core/util/EuclideanDistanceCalculator.java @@ -1,29 +1,28 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.util; - public class EuclideanDistanceCalculator { - public static double calculateDistance(Coordinate coord1, Coordinate coord2) { - double xDiff = coord1.getX() - coord2.getX(); - double yDiff = coord1.getY() - coord2.getY(); - return Math.sqrt((xDiff * xDiff) + (yDiff * yDiff)); - } + public static double calculateDistance(Coordinate coord1, Coordinate coord2) { + double xDiff = coord1.getX() - coord2.getX(); + double yDiff = coord1.getY() - coord2.getY(); + return Math.sqrt((xDiff * xDiff) + (yDiff * yDiff)); + } } diff --git a/jsprit-core/src/main/java/jsprit/core/util/FastVehicleRoutingTransportCostsMatrix.java b/jsprit-core/src/main/java/jsprit/core/util/FastVehicleRoutingTransportCostsMatrix.java index 84d58046..8209d8b1 100644 --- a/jsprit-core/src/main/java/jsprit/core/util/FastVehicleRoutingTransportCostsMatrix.java +++ b/jsprit-core/src/main/java/jsprit/core/util/FastVehicleRoutingTransportCostsMatrix.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.util; @@ -28,133 +28,144 @@ import jsprit.core.problem.vehicle.VehicleTypeImpl.VehicleCostParams; * CostMatrix that allows pre-compiled time and distance-matrices to be considered as {@link jsprit.core.problem.cost.VehicleRoutingTransportCosts} * in the {@link jsprit.core.problem.VehicleRoutingProblem}. *

Note that you can also use it with distance matrix only (or time matrix). - * @author schroeder * + * @author schroeder */ public class FastVehicleRoutingTransportCostsMatrix extends AbstractForwardVehicleRoutingTransportCosts implements TransportDistance { - /** - * Builder that builds the matrix. - * - * @author schroeder - * - */ - public static class Builder { + /** + * Builder that builds the matrix. + * + * @author schroeder + */ + public static class Builder { - private boolean isSymmetric; + private boolean isSymmetric; private double[][][] matrix; - /** - * Creates a new builder returning the matrix-builder. - *

If you want to consider symmetric matrices, set isSymmetric to true. - * @param isSymmetric true if matrix is symmetric, false otherwise - * @return builder - */ - public static Builder newInstance(int noLocations, boolean isSymmetric){ - return new Builder(noLocations, isSymmetric); - } - - private Builder(int noLocations, boolean isSymmetric){ - this.isSymmetric = isSymmetric; - matrix = new double[noLocations][noLocations][2]; - } - - /** - * Adds a transport-distance for a particular relation. - * @param fromIndex from location index - * @param toIndex to location index - * @param distance the distance to be added - * @return builder - */ - public Builder addTransportDistance(int fromIndex, int toIndex, double distance){ - add(fromIndex,toIndex,0,distance); - return this; - } - - private void add(int fromIndex, int toIndex, int indicatorIndex, double distance){ - if(isSymmetric){ - if(fromIndex < toIndex) matrix[fromIndex][toIndex][indicatorIndex] = distance; - else matrix[toIndex][fromIndex][indicatorIndex] = distance; - } - else matrix[fromIndex][toIndex][indicatorIndex] = distance; + /** + * Creates a new builder returning the matrix-builder. + *

If you want to consider symmetric matrices, set isSymmetric to true. + * + * @param isSymmetric true if matrix is symmetric, false otherwise + * @return builder + */ + public static Builder newInstance(int noLocations, boolean isSymmetric) { + return new Builder(noLocations, isSymmetric); } - /** - * Adds transport-time for a particular relation. - * @param fromIndex from location index - * @param toIndex to location index - * @param time the time to be added - * @return builder - */ - public Builder addTransportTime(int fromIndex, int toIndex, double time){ - add(fromIndex,toIndex,1,time); - return this; - } + private Builder(int noLocations, boolean isSymmetric) { + this.isSymmetric = isSymmetric; + matrix = new double[noLocations][noLocations][2]; + } - /** - * Builds the matrix. - * @return matrix - */ - public FastVehicleRoutingTransportCostsMatrix build(){ - return new FastVehicleRoutingTransportCostsMatrix(this); - } + /** + * Adds a transport-distance for a particular relation. + * + * @param fromIndex from location index + * @param toIndex to location index + * @param distance the distance to be added + * @return builder + */ + public Builder addTransportDistance(int fromIndex, int toIndex, double distance) { + add(fromIndex, toIndex, 0, distance); + return this; + } + + private void add(int fromIndex, int toIndex, int indicatorIndex, double distance) { + if (isSymmetric) { + if (fromIndex < toIndex) matrix[fromIndex][toIndex][indicatorIndex] = distance; + else matrix[toIndex][fromIndex][indicatorIndex] = distance; + } else matrix[fromIndex][toIndex][indicatorIndex] = distance; + } + + /** + * Adds transport-time for a particular relation. + * + * @param fromIndex from location index + * @param toIndex to location index + * @param time the time to be added + * @return builder + */ + public Builder addTransportTime(int fromIndex, int toIndex, double time) { + add(fromIndex, toIndex, 1, time); + return this; + } + + /** + * Builds the matrix. + * + * @return matrix + */ + public FastVehicleRoutingTransportCostsMatrix build() { + return new FastVehicleRoutingTransportCostsMatrix(this); + } - } + } private final boolean isSymmetric; private final double[][][] matrix; - private FastVehicleRoutingTransportCostsMatrix(Builder builder){ - this.isSymmetric = builder.isSymmetric; - matrix = builder.matrix; - } + private FastVehicleRoutingTransportCostsMatrix(Builder builder) { + this.isSymmetric = builder.isSymmetric; + matrix = builder.matrix; + } + /** + * First dim is from, second to and third indicates whether it is a distance value (index=0) or time value (index=1). + * + * @return + */ + public double[][][] getMatrix() { + return matrix; + } - @Override - public double getTransportTime(Location from, Location to, double departureTime, Driver driver, Vehicle vehicle) { - if(from.getIndex() < 0 || to.getIndex() < 0) throw new IllegalArgumentException("index of from " + from + " to " + to + " < 0 "); + @Override + public double getTransportTime(Location from, Location to, double departureTime, Driver driver, Vehicle vehicle) { + if (from.getIndex() < 0 || to.getIndex() < 0) + throw new IllegalArgumentException("index of from " + from + " to " + to + " < 0 "); int timeIndex = 1; - return get(from.getIndex(),to.getIndex(), timeIndex); - } + return get(from.getIndex(), to.getIndex(), timeIndex); + } - private double get(int from, int to, int indicatorIndex){ + private double get(int from, int to, int indicatorIndex) { double value; - if(isSymmetric){ - if(from < to) value = matrix[from][to][indicatorIndex]; + if (isSymmetric) { + if (from < to) value = matrix[from][to][indicatorIndex]; else value = matrix[to][from][indicatorIndex]; - } - else{ + } else { value = matrix[from][to][indicatorIndex]; } return value; } - /** - * Returns the distance from to to. - * - * @param fromIndex from location index - * @param toIndex to location index - * @return the distance - */ - public double getDistance(int fromIndex, int toIndex) { + /** + * Returns the distance from to to. + * + * @param fromIndex from location index + * @param toIndex to location index + * @return the distance + */ + public double getDistance(int fromIndex, int toIndex) { int distanceIndex = 0; return get(fromIndex, toIndex, distanceIndex); - } + } - @Override - public double getDistance(Location from, Location to) { - return getDistance(from.getIndex(),to.getIndex()); - } + @Override + public double getDistance(Location from, Location to) { + return getDistance(from.getIndex(), to.getIndex()); + } + + @Override + public double getTransportCost(Location from, Location to, double departureTime, Driver driver, Vehicle vehicle) { + if (from.getIndex() < 0 || to.getIndex() < 0) + throw new IllegalArgumentException("index of from " + from + " to " + to + " < 0 "); + if (vehicle == null) return getDistance(from.getIndex(), to.getIndex()); + VehicleCostParams costParams = vehicle.getType().getVehicleCostParams(); + return costParams.perDistanceUnit * getDistance(from.getIndex(), to.getIndex()) + costParams.perTimeUnit * getTransportTime(from, to, departureTime, driver, vehicle); + } - @Override - public double getTransportCost(Location from, Location to, double departureTime, Driver driver, Vehicle vehicle) { - if(from.getIndex() < 0 || to.getIndex() < 0) throw new IllegalArgumentException("index of from " + from + " to " + to + " < 0 "); - if(vehicle == null) return getDistance(from.getIndex(), to.getIndex()); - VehicleCostParams costParams = vehicle.getType().getVehicleCostParams(); - return costParams.perDistanceUnit * getDistance(from.getIndex(), to.getIndex()) + costParams.perTimeUnit * getTransportTime(from, to, departureTime, driver, vehicle); - } - } diff --git a/jsprit-core/src/main/java/jsprit/core/util/GreatCircleCosts.java b/jsprit-core/src/main/java/jsprit/core/util/GreatCircleCosts.java index 91b84723..e86be112 100644 --- a/jsprit-core/src/main/java/jsprit/core/util/GreatCircleCosts.java +++ b/jsprit-core/src/main/java/jsprit/core/util/GreatCircleCosts.java @@ -11,13 +11,12 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.util; - import jsprit.core.problem.Location; import jsprit.core.problem.cost.AbstractForwardVehicleRoutingTransportCosts; import jsprit.core.problem.cost.TransportDistance; @@ -25,14 +24,12 @@ import jsprit.core.problem.driver.Driver; import jsprit.core.problem.vehicle.Vehicle; /** - * * @author stefan schroeder - * */ -public class GreatCircleCosts extends AbstractForwardVehicleRoutingTransportCosts implements TransportDistance{ +public class GreatCircleCosts extends AbstractForwardVehicleRoutingTransportCosts implements TransportDistance { - private double speed = 1.; + private double speed = 1.; private double detour = 1.; @@ -45,6 +42,7 @@ public class GreatCircleCosts extends AbstractForwardVehicleRoutingTransportCost *

* The distance is calculated by the great circle distance * detour factor. *

+ * * @param detour */ public void setDetour(double detour) { @@ -56,10 +54,10 @@ public class GreatCircleCosts extends AbstractForwardVehicleRoutingTransportCost private DistanceUnit distanceUnit = DistanceUnit.Kilometer; @Deprecated - public GreatCircleCosts(Locations locations) { - super(); - this.locations = locations; - } + public GreatCircleCosts(Locations locations) { + super(); + this.locations = locations; + } public GreatCircleCosts() { super(); @@ -78,45 +76,43 @@ public class GreatCircleCosts extends AbstractForwardVehicleRoutingTransportCost } - @Override - public double getTransportCost(Location from, Location to, double time,Driver driver, Vehicle vehicle) { + @Override + public double getTransportCost(Location from, Location to, double time, Driver driver, Vehicle vehicle) { double distance; try { - distance = calculateDistance(from,to); + distance = calculateDistance(from, to); } catch (NullPointerException e) { throw new NullPointerException("cannot calculate euclidean distance. coordinates are missing. either add coordinates or use another transport-cost-calculator."); } double costs = distance; - if(vehicle != null){ - if(vehicle.getType() != null){ + if (vehicle != null) { + if (vehicle.getType() != null) { costs = distance * vehicle.getType().getVehicleCostParams().perDistanceUnit; } } return costs; - } + } private double calculateDistance(Location fromLocation, Location toLocation) { Coordinate from = null; Coordinate to = null; - if(fromLocation.getCoordinate() != null & toLocation.getCoordinate() != null){ + if (fromLocation.getCoordinate() != null & toLocation.getCoordinate() != null) { from = fromLocation.getCoordinate(); to = toLocation.getCoordinate(); - } - else if(locations != null){ + } else if (locations != null) { from = locations.getCoord(fromLocation.getId()); to = locations.getCoord(toLocation.getId()); } - if(from == null || to == null) throw new NullPointerException("either from or to location is null"); + if (from == null || to == null) throw new NullPointerException("either from or to location is null"); return GreatCircleDistanceCalculator.calculateDistance(from, to, distanceUnit) * detour; } - @Override - public double getTransportTime(Location from, Location to, double time, Driver driver, Vehicle vehicle) { - return calculateDistance(from, to) / speed; - } + @Override + public double getTransportTime(Location from, Location to, double time, Driver driver, Vehicle vehicle) { + return calculateDistance(from, to) / speed; + } /** - * * @param fromId * @param toId * @return @@ -124,10 +120,10 @@ public class GreatCircleCosts extends AbstractForwardVehicleRoutingTransportCost */ @Deprecated public double getDistance(String fromId, String toId) { - Coordinate fromCoordinate = locations.getCoord(fromId); + Coordinate fromCoordinate = locations.getCoord(fromId); Coordinate toCoordinate = locations.getCoord(toId); return GreatCircleDistanceCalculator.calculateDistance(fromCoordinate, toCoordinate, distanceUnit) * detour; - } + } @Override public double getDistance(Location from, Location to) { diff --git a/jsprit-core/src/main/java/jsprit/core/util/GreatCircleDistanceCalculator.java b/jsprit-core/src/main/java/jsprit/core/util/GreatCircleDistanceCalculator.java index 67188d28..534e0e9c 100644 --- a/jsprit-core/src/main/java/jsprit/core/util/GreatCircleDistanceCalculator.java +++ b/jsprit-core/src/main/java/jsprit/core/util/GreatCircleDistanceCalculator.java @@ -26,7 +26,7 @@ public class GreatCircleDistanceCalculator { /** * Harversine method. - * + *

* double lon1 = coord1.getX(); * double lon2 = coord2.getX(); * double lat1 = coord1.getY(); @@ -36,7 +36,7 @@ public class GreatCircleDistanceCalculator { * @param coord2 - to coord * @return great circle distance */ - public static double calculateDistance(Coordinate coord1, Coordinate coord2, DistanceUnit distanceUnit){ + public static double calculateDistance(Coordinate coord1, Coordinate coord2, DistanceUnit distanceUnit) { double lon1 = coord1.getX(); double lon2 = coord2.getX(); double lat1 = coord1.getY(); @@ -50,7 +50,7 @@ public class GreatCircleDistanceCalculator { double a = Math.sin(delta_Lat / 2) * Math.sin(delta_Lat / 2) + Math.sin(delta_Lon / 2) * Math.sin(delta_Lon / 2) * Math.cos(lat1) * Math.cos(lat2); double c = 2 * Math.asin(Math.sqrt(a)); double distance = R * c; - if(distanceUnit.equals(DistanceUnit.Meter)){ + if (distanceUnit.equals(DistanceUnit.Meter)) { distance = distance * 1000.; } return distance; diff --git a/jsprit-core/src/main/java/jsprit/core/util/Locations.java b/jsprit-core/src/main/java/jsprit/core/util/Locations.java index 739fb824..4e7e55ea 100644 --- a/jsprit-core/src/main/java/jsprit/core/util/Locations.java +++ b/jsprit-core/src/main/java/jsprit/core/util/Locations.java @@ -1,26 +1,24 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.util; - - public interface Locations { - public abstract Coordinate getCoord(String id); + public abstract Coordinate getCoord(String id); } diff --git a/jsprit-core/src/main/java/jsprit/core/util/ManhattanCosts.java b/jsprit-core/src/main/java/jsprit/core/util/ManhattanCosts.java index db8a841d..81755001 100644 --- a/jsprit-core/src/main/java/jsprit/core/util/ManhattanCosts.java +++ b/jsprit-core/src/main/java/jsprit/core/util/ManhattanCosts.java @@ -11,13 +11,12 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.util; - import jsprit.core.problem.Location; import jsprit.core.problem.cost.AbstractForwardVehicleRoutingTransportCosts; import jsprit.core.problem.cost.TransportDistance; @@ -25,69 +24,66 @@ import jsprit.core.problem.driver.Driver; import jsprit.core.problem.vehicle.Vehicle; /** - * * @author stefan schroeder - * */ public class ManhattanCosts extends AbstractForwardVehicleRoutingTransportCosts implements TransportDistance { - public double speed = 1; + public double speed = 1; - private Locations locations; + private Locations locations; - public ManhattanCosts(Locations locations) { - super(); - this.locations = locations; - } + public ManhattanCosts(Locations locations) { + super(); + this.locations = locations; + } - public ManhattanCosts(){ + public ManhattanCosts() { - } + } - @Override - public double getTransportCost(Location from, Location to, double time, Driver driver, Vehicle vehicle) { + @Override + public double getTransportCost(Location from, Location to, double time, Driver driver, Vehicle vehicle) { double distance; try { - distance = calculateDistance(from, to); - } catch (NullPointerException e) { + distance = calculateDistance(from, to); + } catch (NullPointerException e) { throw new NullPointerException("cannot calculate euclidean distance. coordinates are missing. either add coordinates or use another transport-cost-calculator."); } double costs = distance; - if(vehicle != null){ - if(vehicle.getType() != null){ + if (vehicle != null) { + if (vehicle.getType() != null) { costs = distance * vehicle.getType().getVehicleCostParams().perDistanceUnit; } } return costs; - } + } - @Override - public double getTransportTime(Location from, Location to, double time,Driver driver, Vehicle vehicle) { - return calculateDistance(from, to) / speed; - } + @Override + public double getTransportTime(Location from, Location to, double time, Driver driver, Vehicle vehicle) { + return calculateDistance(from, to) / speed; + } - private double calculateDistance(Location fromLocation, Location toLocation) { - Coordinate from = null; - Coordinate to = null; - if(fromLocation.getCoordinate() != null & toLocation.getCoordinate() != null){ - from = fromLocation.getCoordinate(); - to = toLocation.getCoordinate(); - } - else if(locations != null){ - from = locations.getCoord(fromLocation.getId()); - to = locations.getCoord(toLocation.getId()); - } - if(from == null || to == null) throw new NullPointerException(); - return calculateDistance(from,to); - } + private double calculateDistance(Location fromLocation, Location toLocation) { + Coordinate from = null; + Coordinate to = null; + if (fromLocation.getCoordinate() != null & toLocation.getCoordinate() != null) { + from = fromLocation.getCoordinate(); + to = toLocation.getCoordinate(); + } else if (locations != null) { + from = locations.getCoord(fromLocation.getId()); + to = locations.getCoord(toLocation.getId()); + } + if (from == null || to == null) throw new NullPointerException(); + return calculateDistance(from, to); + } - private double calculateDistance(Coordinate from, Coordinate to) { - return Math.abs(from.getX() - to.getX()) + Math.abs(from.getY() - to.getY()); - } + private double calculateDistance(Coordinate from, Coordinate to) { + return Math.abs(from.getX() - to.getX()) + Math.abs(from.getY() - to.getY()); + } - @Override - public double getDistance(Location from, Location to) { - return calculateDistance(from,to); - } + @Override + public double getDistance(Location from, Location to) { + return calculateDistance(from, to); + } } diff --git a/jsprit-core/src/main/java/jsprit/core/util/ManhattanDistanceCalculator.java b/jsprit-core/src/main/java/jsprit/core/util/ManhattanDistanceCalculator.java index 90acf6e6..bcfa9794 100644 --- a/jsprit-core/src/main/java/jsprit/core/util/ManhattanDistanceCalculator.java +++ b/jsprit-core/src/main/java/jsprit/core/util/ManhattanDistanceCalculator.java @@ -11,18 +11,17 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.util; - public class ManhattanDistanceCalculator { - public static double calculateDistance(Coordinate coord1, Coordinate coord2) { - return Math.abs(coord1.getX() - coord2.getX()) - + Math.abs(coord1.getY() - coord2.getY()); - } + public static double calculateDistance(Coordinate coord1, Coordinate coord2) { + return Math.abs(coord1.getX() - coord2.getX()) + + Math.abs(coord1.getY() - coord2.getY()); + } } diff --git a/jsprit-core/src/main/java/jsprit/core/util/RandomNumberGeneration.java b/jsprit-core/src/main/java/jsprit/core/util/RandomNumberGeneration.java index 9447b922..3cfa7194 100644 --- a/jsprit-core/src/main/java/jsprit/core/util/RandomNumberGeneration.java +++ b/jsprit-core/src/main/java/jsprit/core/util/RandomNumberGeneration.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.util; @@ -20,28 +20,28 @@ import java.util.Random; public class RandomNumberGeneration { - private static long DEFAULT_SEED = 4711L; + private static long DEFAULT_SEED = 4711L; - private static Random random = new Random(DEFAULT_SEED); + private static Random random = new Random(DEFAULT_SEED); - public static Random newInstance(){ - return new Random(DEFAULT_SEED); - } + public static Random newInstance() { + return new Random(DEFAULT_SEED); + } - public static Random getRandom() { - return random; - } + public static Random getRandom() { + return random; + } - public static void setSeed(long seed) { - random.setSeed(seed); - } + public static void setSeed(long seed) { + random.setSeed(seed); + } - public static void reset() { - reset(random); - } + public static void reset() { + reset(random); + } - public static void reset(Random random){ - random.setSeed(DEFAULT_SEED); - } + public static void reset(Random random) { + random.setSeed(DEFAULT_SEED); + } } diff --git a/jsprit-core/src/main/java/jsprit/core/util/RandomUtils.java b/jsprit-core/src/main/java/jsprit/core/util/RandomUtils.java index 370e9307..02ddcbba 100644 --- a/jsprit-core/src/main/java/jsprit/core/util/RandomUtils.java +++ b/jsprit-core/src/main/java/jsprit/core/util/RandomUtils.java @@ -12,29 +12,29 @@ import java.util.Random; */ public class RandomUtils { - public static VehicleRoute nextRoute(Collection routes, Random random){ - return nextItem(routes,random); + public static VehicleRoute nextRoute(Collection routes, Random random) { + return nextItem(routes, random); } - public static Job nextJob(Collection jobs, Random random){ - return nextItem(jobs,random); + public static Job nextJob(Collection jobs, Random random) { + return nextItem(jobs, random); } - public static Job nextJob(List jobs, Random random){ - return nextItem(jobs,random); + public static Job nextJob(List jobs, Random random) { + return nextItem(jobs, random); } - public static T nextItem(Collection items, Random random){ + public static T nextItem(Collection items, Random random) { int randomIndex = random.nextInt(items.size()); int count = 0; - for(T item : items){ - if(count == randomIndex) return item; + for (T item : items) { + if (count == randomIndex) return item; count++; } return null; } - public static T nextItem(List items, Random random){ + public static T nextItem(List items, Random random) { int randomIndex = random.nextInt(items.size()); return items.get(randomIndex); } diff --git a/jsprit-core/src/main/java/jsprit/core/util/Resource.java b/jsprit-core/src/main/java/jsprit/core/util/Resource.java index 9e230782..6aa97936 100644 --- a/jsprit-core/src/main/java/jsprit/core/util/Resource.java +++ b/jsprit-core/src/main/java/jsprit/core/util/Resource.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.util; @@ -28,50 +28,48 @@ import java.net.URL; /** - * * @author stefan schroeder, pierre-david belanger - * */ public class Resource { - - private static Logger log = LogManager.getLogger(Resource.class); - - public final static URL getAsURL(final String filename) { - URL url = Resource.class.getClassLoader().getResource(filename); - if (url != null) { - return url; - } - log.debug("resource: " + filename + " is unreachable by the current class loader, try the filesystem"); - File file = new File(filename); - if (!file.exists()) { - log.debug("resource: " + filename + " do not exists on the filesystem"); - return null; - } - try { - return file.toURI().toURL(); - } catch (MalformedURLException e) { - log.debug("resource: " + filename + " exists on the filesystem, but its URL is invalid: " + e.getMessage()); - return null; - } - } - public final static InputStream getAsInputStream(final String filename) { - InputStream stream = Resource.class.getClassLoader().getResourceAsStream(filename); - if (stream != null) { - return stream; - } - log.debug("resource: " + filename + " is unreachable by the current class loader, try the filesystem"); - File file = new File(filename); - if (!file.exists()) { - log.debug("resource: " + filename + " do not exists on the filesystem"); - return null; - } - try { - return new FileInputStream(file); - } catch (FileNotFoundException e) { - log.debug("resource: " + filename + " exists on the filesystem, but its URL is invalid: " + e.getMessage()); - return null; - } - } - + private static Logger log = LogManager.getLogger(Resource.class); + + public final static URL getAsURL(final String filename) { + URL url = Resource.class.getClassLoader().getResource(filename); + if (url != null) { + return url; + } + log.debug("resource: " + filename + " is unreachable by the current class loader, try the filesystem"); + File file = new File(filename); + if (!file.exists()) { + log.debug("resource: " + filename + " do not exists on the filesystem"); + return null; + } + try { + return file.toURI().toURL(); + } catch (MalformedURLException e) { + log.debug("resource: " + filename + " exists on the filesystem, but its URL is invalid: " + e.getMessage()); + return null; + } + } + + public final static InputStream getAsInputStream(final String filename) { + InputStream stream = Resource.class.getClassLoader().getResourceAsStream(filename); + if (stream != null) { + return stream; + } + log.debug("resource: " + filename + " is unreachable by the current class loader, try the filesystem"); + File file = new File(filename); + if (!file.exists()) { + log.debug("resource: " + filename + " do not exists on the filesystem"); + return null; + } + try { + return new FileInputStream(file); + } catch (FileNotFoundException e) { + log.debug("resource: " + filename + " exists on the filesystem, but its URL is invalid: " + e.getMessage()); + return null; + } + } + } diff --git a/jsprit-core/src/main/java/jsprit/core/util/RouteUtils.java b/jsprit-core/src/main/java/jsprit/core/util/RouteUtils.java index 840b76f4..a7ff0e5f 100644 --- a/jsprit-core/src/main/java/jsprit/core/util/RouteUtils.java +++ b/jsprit-core/src/main/java/jsprit/core/util/RouteUtils.java @@ -29,83 +29,83 @@ import java.util.Collection; @Deprecated public class RouteUtils { - - /** - * Returns total service time, i.e. sum of service time of each job. - * - * @param routes - * @return - */ - public static double calculateServiceTime(Collection routes) { - double serviceTime = 0.; - for(VehicleRoute r : routes){ - for(Job j : r.getTourActivities().getJobs()){ - serviceTime += ((Service)j).getServiceDuration(); - } - } - return serviceTime; - } - - /** - * Returns total transport time. - * - * @param routes - * @param transportTimes - * @return - */ - public static double calculateTransportTime(Collection routes, TransportTime transportTimes) { - double tpTime = 0.; - for(VehicleRoute r : routes){ - TourActivity lastact = r.getStart(); - double lastActDepTime = r.getDepartureTime(); - for(TourActivity act : r.getActivities()){ - tpTime += transportTimes.getTransportTime(lastact.getLocation(), act.getLocation(), lastActDepTime, DriverImpl.noDriver(), r.getVehicle()); - lastact=act; - lastActDepTime=act.getEndTime(); - } - tpTime+=transportTimes.getTransportTime(lastact.getLocation(), r.getEnd().getLocation(), lastActDepTime, DriverImpl.noDriver(), r.getVehicle()); - } - return tpTime; - } - - /** - * Returns total waiting time. - * - * @param routes - * @return - */ - public static double calculateWaitingTime(Collection routes) { - double waitingTime = 0.; - for(VehicleRoute r : routes){ - for(TourActivity act : r.getActivities()){ - waitingTime += Math.max(0., act.getTheoreticalEarliestOperationStartTime() - act.getArrTime()); - } - } - return waitingTime; - } - - /** - * Returns total operation time. - * - * @param routes - * @return - */ - public static double calulateOperationTime(Collection routes) { - double opTime = 0.; - for(VehicleRoute r : routes){ - opTime += r.getEnd().getArrTime() - r.getDepartureTime(); - } - return opTime; - } - - /** - * Updates activity arrival/end-times of activities in specified route. - * - * @param route - * @param transportTimes - */ - public static void updateActivityTimes(VehicleRoute route, TransportTime transportTimes){ - new RouteActivityVisitor().addActivityVisitor(new UpdateActivityTimes(transportTimes)).visit(route); - } + + /** + * Returns total service time, i.e. sum of service time of each job. + * + * @param routes + * @return + */ + public static double calculateServiceTime(Collection routes) { + double serviceTime = 0.; + for (VehicleRoute r : routes) { + for (Job j : r.getTourActivities().getJobs()) { + serviceTime += ((Service) j).getServiceDuration(); + } + } + return serviceTime; + } + + /** + * Returns total transport time. + * + * @param routes + * @param transportTimes + * @return + */ + public static double calculateTransportTime(Collection routes, TransportTime transportTimes) { + double tpTime = 0.; + for (VehicleRoute r : routes) { + TourActivity lastact = r.getStart(); + double lastActDepTime = r.getDepartureTime(); + for (TourActivity act : r.getActivities()) { + tpTime += transportTimes.getTransportTime(lastact.getLocation(), act.getLocation(), lastActDepTime, DriverImpl.noDriver(), r.getVehicle()); + lastact = act; + lastActDepTime = act.getEndTime(); + } + tpTime += transportTimes.getTransportTime(lastact.getLocation(), r.getEnd().getLocation(), lastActDepTime, DriverImpl.noDriver(), r.getVehicle()); + } + return tpTime; + } + + /** + * Returns total waiting time. + * + * @param routes + * @return + */ + public static double calculateWaitingTime(Collection routes) { + double waitingTime = 0.; + for (VehicleRoute r : routes) { + for (TourActivity act : r.getActivities()) { + waitingTime += Math.max(0., act.getTheoreticalEarliestOperationStartTime() - act.getArrTime()); + } + } + return waitingTime; + } + + /** + * Returns total operation time. + * + * @param routes + * @return + */ + public static double calulateOperationTime(Collection routes) { + double opTime = 0.; + for (VehicleRoute r : routes) { + opTime += r.getEnd().getArrTime() - r.getDepartureTime(); + } + return opTime; + } + + /** + * Updates activity arrival/end-times of activities in specified route. + * + * @param route + * @param transportTimes + */ + public static void updateActivityTimes(VehicleRoute route, TransportTime transportTimes) { + new RouteActivityVisitor().addActivityVisitor(new UpdateActivityTimes(transportTimes)).visit(route); + } } diff --git a/jsprit-core/src/main/java/jsprit/core/util/SolutionVerifier.java b/jsprit-core/src/main/java/jsprit/core/util/SolutionVerifier.java index fc5bdd73..e6eb4087 100644 --- a/jsprit-core/src/main/java/jsprit/core/util/SolutionVerifier.java +++ b/jsprit-core/src/main/java/jsprit/core/util/SolutionVerifier.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.util; @@ -27,22 +27,22 @@ import java.util.HashSet; import java.util.Set; -public class SolutionVerifier implements AlgorithmEndsListener{ +public class SolutionVerifier implements AlgorithmEndsListener { - @Override - public void informAlgorithmEnds(VehicleRoutingProblem problem, Collection solutions) { - - for(VehicleRoutingProblemSolution solution : solutions){ - Set jobsInSolution = new HashSet(); - for(VehicleRoute route : solution.getRoutes()){ - jobsInSolution.addAll(route.getTourActivities().getJobs()); - } - if(jobsInSolution.size() != problem.getJobs().size()){ - throw new IllegalStateException("we are at the end of the algorithm and still have not found a valid solution." + - "This cannot be."); - } - } - - } + @Override + public void informAlgorithmEnds(VehicleRoutingProblem problem, Collection solutions) { + + for (VehicleRoutingProblemSolution solution : solutions) { + Set jobsInSolution = new HashSet(); + for (VehicleRoute route : solution.getRoutes()) { + jobsInSolution.addAll(route.getTourActivities().getJobs()); + } + if (jobsInSolution.size() != problem.getJobs().size()) { + throw new IllegalStateException("we are at the end of the algorithm and still have not found a valid solution." + + "This cannot be."); + } + } + + } } diff --git a/jsprit-core/src/main/java/jsprit/core/util/Solutions.java b/jsprit-core/src/main/java/jsprit/core/util/Solutions.java index 1e2921b2..7e181500 100644 --- a/jsprit-core/src/main/java/jsprit/core/util/Solutions.java +++ b/jsprit-core/src/main/java/jsprit/core/util/Solutions.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.util; @@ -22,14 +22,14 @@ import java.util.Collection; public class Solutions { - - public static VehicleRoutingProblemSolution bestOf(Collection solutions){ - VehicleRoutingProblemSolution best = null; - for(VehicleRoutingProblemSolution s : solutions){ - if(best == null) best = s; - else if(s.getCost() < best.getCost()) best = s; - } - return best; - } + + public static VehicleRoutingProblemSolution bestOf(Collection solutions) { + VehicleRoutingProblemSolution best = null; + for (VehicleRoutingProblemSolution s : solutions) { + if (best == null) best = s; + else if (s.getCost() < best.getCost()) best = s; + } + return best; + } } diff --git a/jsprit-core/src/main/java/jsprit/core/util/StopWatch.java b/jsprit-core/src/main/java/jsprit/core/util/StopWatch.java index 6efadb98..80fb771e 100644 --- a/jsprit-core/src/main/java/jsprit/core/util/StopWatch.java +++ b/jsprit-core/src/main/java/jsprit/core/util/StopWatch.java @@ -1,52 +1,52 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.util; public class StopWatch { - - private double ran; - - private double startTime; - - public double getCompTimeInSeconds(){ - return (ran)/1000.0; - } - public void stop(){ - ran += System.currentTimeMillis() - startTime; - } - - public void start(){ - startTime = System.currentTimeMillis(); - } - - public void reset(){ - startTime = 0; - ran = 0; - } - - @Override - public String toString() { - return getCompTimeInSeconds() + " sec"; - } + private double ran; + + private double startTime; + + public double getCompTimeInSeconds() { + return (ran) / 1000.0; + } + + public void stop() { + ran += System.currentTimeMillis() - startTime; + } + + public void start() { + startTime = System.currentTimeMillis(); + } + + public void reset() { + startTime = 0; + ran = 0; + } + + @Override + public String toString() { + return getCompTimeInSeconds() + " sec"; + } + + public double getCurrTimeInSeconds() { + return (System.currentTimeMillis() - startTime) / 1000.0; + } - public double getCurrTimeInSeconds() { - return (System.currentTimeMillis()-startTime)/1000.0; - } - } diff --git a/jsprit-core/src/main/java/jsprit/core/util/Time.java b/jsprit-core/src/main/java/jsprit/core/util/Time.java index 7f1f92e8..a5690353 100644 --- a/jsprit-core/src/main/java/jsprit/core/util/Time.java +++ b/jsprit-core/src/main/java/jsprit/core/util/Time.java @@ -24,86 +24,83 @@ public class Time { * @param seconds seconds * @return time string */ - public static String parseSecondsToTime(double seconds){ - int hours = (int)Math.floor(seconds / 3600.); - int min = (int)Math.floor((seconds - hours * 3600.) / 60.); - int secs = (int)(seconds - (hours * 3600. + min * 60.)); + public static String parseSecondsToTime(double seconds) { + int hours = (int) Math.floor(seconds / 3600.); + int min = (int) Math.floor((seconds - hours * 3600.) / 60.); + int secs = (int) (seconds - (hours * 3600. + min * 60.)); String dayTime = "AM"; - if(hours > 12) { + if (hours > 12) { dayTime = "PM"; hours -= 12; } String hourString = "0" + hours; - if(hours > 9) hourString = "" + hours; + if (hours > 9) hourString = "" + hours; String minString = "" + min; - if(min < 10) minString = "0" + min; + if (min < 10) minString = "0" + min; String secString = "" + secs; - if(secs < 10) secString = "0" + secs; + if (secs < 10) secString = "0" + secs; return hourString + ":" + minString + ":" + secString + " " + dayTime; } - /** - * Parse time to seconds. - * - *

If you add PM or AM to timeString, it considers english-time, otherwise not. - * - *

timeString can be 6AM, 06AM, 6 am, 6:01AM, 6:1 pM, 6:12:1 pm, 6:12:01 am, 06:12:01 Pm etc. - but not more precise than seconds. - *

example: 12 AM returns 12*3600. sec - * 6:30 AM --> 6*3600. + 30*60. - * 0:30:20 AM --> 30*3600. + 20. - * 6:00 PM --> 6*3600. + 12.*3600. - * 6:00:12 --> 6*3600. + 12. - * - * @return seconds - */ - public static double parseTimeToSeconds(String timeString){ - if(timeString.substring(0, 1).matches("\\D")) throw new IllegalArgumentException("timeString must start with digit [0-9]"); - double dayTime = 0.; - if(timeString.toLowerCase().contains("pm")){ - dayTime = 12.*3600.; - } - String[] tokens = timeString.split(":"); - - if(tokens.length == 1){ //1 AM or 01 AM - return getHourInSeconds(tokens[0]) + dayTime; - } - else if(tokens.length == 2){ - return getHourInSeconds(tokens[0]) + getMinInSeconds(tokens[1]) + dayTime; - } - else if(tokens.length == 3){ - return getHourInSeconds(tokens[0]) + getMinInSeconds(tokens[1]) + getSecondsInSeconds(tokens[2]) + dayTime; - } - else { - throw new IllegalArgumentException("wrong timeString"); - } - - } - private static double getSecondsInSeconds(String secString) { - return getDigit(secString); - } + /** + * Parse time to seconds. + *

+ *

If you add PM or AM to timeString, it considers english-time, otherwise not. + *

+ *

timeString can be 6AM, 06AM, 6 am, 6:01AM, 6:1 pM, 6:12:1 pm, 6:12:01 am, 06:12:01 Pm etc. - but not more precise than seconds. + *

example: 12 AM returns 12*3600. sec + * 6:30 AM --> 6*3600. + 30*60. + * 0:30:20 AM --> 30*3600. + 20. + * 6:00 PM --> 6*3600. + 12.*3600. + * 6:00:12 --> 6*3600. + 12. + * + * @return seconds + */ + public static double parseTimeToSeconds(String timeString) { + if (timeString.substring(0, 1).matches("\\D")) + throw new IllegalArgumentException("timeString must start with digit [0-9]"); + double dayTime = 0.; + if (timeString.toLowerCase().contains("pm")) { + dayTime = 12. * 3600.; + } + String[] tokens = timeString.split(":"); - private static double getMinInSeconds(String minString) { - return getDigit(minString)*60.; - } + if (tokens.length == 1) { //1 AM or 01 AM + return getHourInSeconds(tokens[0]) + dayTime; + } else if (tokens.length == 2) { + return getHourInSeconds(tokens[0]) + getMinInSeconds(tokens[1]) + dayTime; + } else if (tokens.length == 3) { + return getHourInSeconds(tokens[0]) + getMinInSeconds(tokens[1]) + getSecondsInSeconds(tokens[2]) + dayTime; + } else { + throw new IllegalArgumentException("wrong timeString"); + } - private static double getHourInSeconds(String hourString) { - return getDigit(hourString)*3600.; - } + } - private static double getDigit(String digitString) { - if(digitString.length() == 1){ - return Double.parseDouble(digitString); - } - if(digitString.substring(1, 2).matches("\\D")){ - return Double.parseDouble(digitString.substring(0, 1)); - } - else{ - if(digitString.startsWith("0")){ - return Double.parseDouble(digitString.substring(1, 2)); - } - else{ - return Double.parseDouble(digitString.substring(0, 2)); - } - } - } + private static double getSecondsInSeconds(String secString) { + return getDigit(secString); + } + + private static double getMinInSeconds(String minString) { + return getDigit(minString) * 60.; + } + + private static double getHourInSeconds(String hourString) { + return getDigit(hourString) * 3600.; + } + + private static double getDigit(String digitString) { + if (digitString.length() == 1) { + return Double.parseDouble(digitString); + } + if (digitString.substring(1, 2).matches("\\D")) { + return Double.parseDouble(digitString.substring(0, 1)); + } else { + if (digitString.startsWith("0")) { + return Double.parseDouble(digitString.substring(1, 2)); + } else { + return Double.parseDouble(digitString.substring(0, 2)); + } + } + } } diff --git a/jsprit-core/src/main/java/jsprit/core/util/VehicleRoutingTransportCostsMatrix.java b/jsprit-core/src/main/java/jsprit/core/util/VehicleRoutingTransportCostsMatrix.java index c94e50cb..febfc243 100644 --- a/jsprit-core/src/main/java/jsprit/core/util/VehicleRoutingTransportCostsMatrix.java +++ b/jsprit-core/src/main/java/jsprit/core/util/VehicleRoutingTransportCostsMatrix.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.util; @@ -32,227 +32,232 @@ import java.util.Map; * CostMatrix that allows pre-compiled time and distance-matrices to be considered as {@link jsprit.core.problem.cost.VehicleRoutingTransportCosts} * in the {@link jsprit.core.problem.VehicleRoutingProblem}. *

Note that you can also use it with distance matrix only (or time matrix). But ones - * you set a particular distance, this expects distance-entries for all relations. This counts also - * for a particular time. If the method getTransportCosts(...) is then invoked for a relation, where no distance can be found, an + * you set a particular distance, this expects distance-entries for all relations. This counts also + * for a particular time. If the method getTransportCosts(...) is then invoked for a relation, where no distance can be found, an * IllegalStateException will be thrown. Thus if you want to only use distances only, do not use addTransportTime(...). - * @author schroeder * + * @author schroeder */ public class VehicleRoutingTransportCostsMatrix extends AbstractForwardVehicleRoutingTransportCosts { static class RelationKey { - - static RelationKey newKey(String from, String to){ - return new RelationKey(from, to); - } - - final String from; - final String to; - - public RelationKey(String from, String to) { - super(); - this.from = from; - this.to = to; - } - /* (non-Javadoc) - * @see java.lang.Object#hashCode() - */ - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((from == null) ? 0 : from.hashCode()); - result = prime * result + ((to == null) ? 0 : to.hashCode()); - return result; - } + static RelationKey newKey(String from, String to) { + return new RelationKey(from, to); + } - /* (non-Javadoc) - * @see java.lang.Object#equals(java.lang.Object) - */ - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - RelationKey other = (RelationKey) obj; - if (from == null) { - if (other.from != null) - return false; - } else if (!from.equals(other.from)) - return false; - if (to == null) { - if (other.to != null) - return false; - } else if (!to.equals(other.to)) - return false; - return true; - } - } + final String from; + final String to; - - /** - * Builder that builds the matrix. - * - * @author schroeder - * - */ - public static class Builder { - private static Logger log = LogManager.getLogger(Builder.class); - - private boolean isSymmetric; - - private Map distances = new HashMap(); - - private Map times = new HashMap(); - - private boolean distancesSet = false; - - private boolean timesSet = false; - - /** - * Creates a new builder returning the matrix-builder. - *

If you want to consider symmetric matrices, set isSymmetric to true. - * @param isSymmetric true if matrix is symmetric, false otherwise - * @return builder - */ - public static Builder newInstance(boolean isSymmetric){ - return new Builder(isSymmetric); - } - - private Builder(boolean isSymmetric){ - this.isSymmetric = isSymmetric; - } - - /** - * Adds a transport-distance for a particular relation. - * @param from from loactionId - * @param to to locationId - * @param distance the distance to be added - * @return builder - */ - public Builder addTransportDistance(String from, String to, double distance){ - RelationKey key = RelationKey.newKey(from, to); - if(!distancesSet) distancesSet = true; - if(distances.containsKey(key)){ - log.warn("distance from " + from + " to " + to + " already exists. This overrides distance."); - } - distances.put(key, distance); - if(isSymmetric) { - RelationKey revKey = RelationKey.newKey(to, from); - if(distances.containsKey(revKey)) distances.put(revKey, distance); - } - return this; - } - - /** - * Adds transport-time for a particular relation. - * @param from from locationId - * @param to to locationId - * @param time the time to be added - * @return builder - */ - public Builder addTransportTime(String from, String to, double time){ - RelationKey key = RelationKey.newKey(from, to); - if(!timesSet) timesSet = true; - if(times.containsKey(key)){ - log.warn("transport-time from " + from + " to " + to + " already exists. This overrides times."); - } - times.put(key, time); - if(isSymmetric) { - RelationKey revKey = RelationKey.newKey(to, from); - if(times.containsKey(revKey)) times.put(revKey, time); - } - return this; - } - - /** - * Builds the matrix. - * @return matrix - */ - public VehicleRoutingTransportCostsMatrix build(){ - return new VehicleRoutingTransportCostsMatrix(this); - } - - - } - - private Map distances = new HashMap(); - - private Map times = new HashMap(); - - private boolean isSymmetric; - - private boolean timesSet; - - private boolean distancesSet; - - private VehicleRoutingTransportCostsMatrix(Builder builder){ - this.isSymmetric = builder.isSymmetric; - distances.putAll(builder.distances); - times.putAll(builder.times); - timesSet = builder.timesSet; - distancesSet = builder.distancesSet; - } + public RelationKey(String from, String to) { + super(); + this.from = from; + this.to = to; + } + + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((from == null) ? 0 : from.hashCode()); + result = prime * result + ((to == null) ? 0 : to.hashCode()); + return result; + } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + RelationKey other = (RelationKey) obj; + if (from == null) { + if (other.from != null) + return false; + } else if (!from.equals(other.from)) + return false; + if (to == null) { + if (other.to != null) + return false; + } else if (!to.equals(other.to)) + return false; + return true; + } + } - @Override - public double getTransportTime(Location from, Location to, double departureTime, Driver driver, Vehicle vehicle) { - return getTime(from.getId(), to.getId()); - } + /** + * Builder that builds the matrix. + * + * @author schroeder + */ + public static class Builder { + private static Logger log = LogManager.getLogger(Builder.class); + + private boolean isSymmetric; + + private Map distances = new HashMap(); + + private Map times = new HashMap(); + + private boolean distancesSet = false; + + private boolean timesSet = false; + + /** + * Creates a new builder returning the matrix-builder. + *

If you want to consider symmetric matrices, set isSymmetric to true. + * + * @param isSymmetric true if matrix is symmetric, false otherwise + * @return builder + */ + public static Builder newInstance(boolean isSymmetric) { + return new Builder(isSymmetric); + } + + private Builder(boolean isSymmetric) { + this.isSymmetric = isSymmetric; + } + + /** + * Adds a transport-distance for a particular relation. + * + * @param from from loactionId + * @param to to locationId + * @param distance the distance to be added + * @return builder + */ + public Builder addTransportDistance(String from, String to, double distance) { + RelationKey key = RelationKey.newKey(from, to); + if (!distancesSet) distancesSet = true; + if (distances.containsKey(key)) { + log.warn("distance from " + from + " to " + to + " already exists. This overrides distance."); + } + distances.put(key, distance); + if (isSymmetric) { + RelationKey revKey = RelationKey.newKey(to, from); + if (distances.containsKey(revKey)) distances.put(revKey, distance); + } + return this; + } + + /** + * Adds transport-time for a particular relation. + * + * @param from from locationId + * @param to to locationId + * @param time the time to be added + * @return builder + */ + public Builder addTransportTime(String from, String to, double time) { + RelationKey key = RelationKey.newKey(from, to); + if (!timesSet) timesSet = true; + if (times.containsKey(key)) { + log.warn("transport-time from " + from + " to " + to + " already exists. This overrides times."); + } + times.put(key, time); + if (isSymmetric) { + RelationKey revKey = RelationKey.newKey(to, from); + if (times.containsKey(revKey)) times.put(revKey, time); + } + return this; + } + + /** + * Builds the matrix. + * + * @return matrix + */ + public VehicleRoutingTransportCostsMatrix build() { + return new VehicleRoutingTransportCostsMatrix(this); + } - private double getTime(String fromId, String toId) { - if(fromId.equals(toId)) return 0.0; - if(!timesSet) return 0.0; - RelationKey key = RelationKey.newKey(fromId, toId); - if(!isSymmetric){ - if(times.containsKey(key)) return times.get(key); - else throw new IllegalStateException("time value for relation from " + fromId + " to " + toId + " does not exist"); - } - else{ - Double time = times.get(key); - if(time == null){ - time = times.get(RelationKey.newKey(toId, fromId)); - } - if(time != null) return time; - else throw new IllegalStateException("time value for relation from " + fromId + " to " + toId + " does not exist"); - } - } + } - /** - * Returns the distance fromId to toId. - * - * @param fromId from locationId - * @param toId to locationId - * @return the distance from fromId to toId - * @throws IllegalStateException if distance of fromId -> toId is not found - */ - public double getDistance(String fromId, String toId) { - if(fromId.equals(toId)) return 0.0; - if(!distancesSet) return 0.0; - RelationKey key = RelationKey.newKey(fromId, toId); - if(!isSymmetric){ - if(distances.containsKey(key)) return distances.get(key); - else throw new IllegalStateException("distance value for relation from " + fromId + " to " + toId + " does not exist"); - } - else{ - Double time = distances.get(key); - if(time == null){ - time = distances.get(RelationKey.newKey(toId, fromId)); - } - if(time != null) return time; - else throw new IllegalStateException("distance value for relation from " + fromId + " to " + toId + " does not exist"); - } - } + private Map distances = new HashMap(); + + private Map times = new HashMap(); + + private boolean isSymmetric; + + private boolean timesSet; + + private boolean distancesSet; + + private VehicleRoutingTransportCostsMatrix(Builder builder) { + this.isSymmetric = builder.isSymmetric; + distances.putAll(builder.distances); + times.putAll(builder.times); + timesSet = builder.timesSet; + distancesSet = builder.distancesSet; + } + + + @Override + public double getTransportTime(Location from, Location to, double departureTime, Driver driver, Vehicle vehicle) { + return getTime(from.getId(), to.getId()); + } + + + private double getTime(String fromId, String toId) { + if (fromId.equals(toId)) return 0.0; + if (!timesSet) return 0.0; + RelationKey key = RelationKey.newKey(fromId, toId); + if (!isSymmetric) { + if (times.containsKey(key)) return times.get(key); + else + throw new IllegalStateException("time value for relation from " + fromId + " to " + toId + " does not exist"); + } else { + Double time = times.get(key); + if (time == null) { + time = times.get(RelationKey.newKey(toId, fromId)); + } + if (time != null) return time; + else + throw new IllegalStateException("time value for relation from " + fromId + " to " + toId + " does not exist"); + } + } + + /** + * Returns the distance fromId to toId. + * + * @param fromId from locationId + * @param toId to locationId + * @return the distance from fromId to toId + * @throws IllegalStateException if distance of fromId -> toId is not found + */ + public double getDistance(String fromId, String toId) { + if (fromId.equals(toId)) return 0.0; + if (!distancesSet) return 0.0; + RelationKey key = RelationKey.newKey(fromId, toId); + if (!isSymmetric) { + if (distances.containsKey(key)) return distances.get(key); + else + throw new IllegalStateException("distance value for relation from " + fromId + " to " + toId + " does not exist"); + } else { + Double time = distances.get(key); + if (time == null) { + time = distances.get(RelationKey.newKey(toId, fromId)); + } + if (time != null) return time; + else + throw new IllegalStateException("distance value for relation from " + fromId + " to " + toId + " does not exist"); + } + } + + @Override + public double getTransportCost(Location from, Location to, double departureTime, Driver driver, Vehicle vehicle) { + if (vehicle == null) return getDistance(from.getId(), to.getId()); + VehicleCostParams costParams = vehicle.getType().getVehicleCostParams(); + return costParams.perDistanceUnit * getDistance(from.getId(), to.getId()) + costParams.perTimeUnit * getTime(from.getId(), to.getId()); + } - @Override - public double getTransportCost(Location from, Location to, double departureTime, Driver driver, Vehicle vehicle) { - if(vehicle == null) return getDistance(from.getId(), to.getId()); - VehicleCostParams costParams = vehicle.getType().getVehicleCostParams(); - return costParams.perDistanceUnit*getDistance(from.getId(), to.getId()) + costParams.perTimeUnit*getTime(from.getId(), to.getId()); - } - } diff --git a/jsprit-core/src/main/resources/algorithm_schema.xsd b/jsprit-core/src/main/resources/algorithm_schema.xsd index 17d06146..e616b274 100644 --- a/jsprit-core/src/main/resources/algorithm_schema.xsd +++ b/jsprit-core/src/main/resources/algorithm_schema.xsd @@ -17,259 +17,260 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~--> + xmlns="http://www.w3schools.com" elementFormDefault="qualified"> - - - - - - - + + + + + + + - - - + + + + + + + + + + + + + + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + diff --git a/jsprit-core/src/main/resources/config.xml b/jsprit-core/src/main/resources/config.xml index 3451440e..71fad959 100755 --- a/jsprit-core/src/main/resources/config.xml +++ b/jsprit-core/src/main/resources/config.xml @@ -1,67 +1,67 @@ - - 2000 - - - - - - - - 3 - - - - - - - - - 0.5 - - - - 0.5 - - - - - - - - - 0.3 - euclid - - - - 0.5 - - - - - - - - - - - --> - - - - - - - - + + 2000 + + + + + + + + 3 + + + + + + + + + 0.5 + + + + 0.5 + + + + + + + + + 0.3 + euclid + + + + 0.5 + + + + + + + + + + + --> + + + + + + + + diff --git a/jsprit-core/src/main/resources/greedySchrimpf.xml b/jsprit-core/src/main/resources/greedySchrimpf.xml index e2fff496..58fedc6c 100755 --- a/jsprit-core/src/main/resources/greedySchrimpf.xml +++ b/jsprit-core/src/main/resources/greedySchrimpf.xml @@ -1,48 +1,49 @@ - - 2000 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.w3schools.com algorithm_schema.xsd"> + + 2000 + + + + + + + 1 + + + + + + + + 0.5 + + + + + + 0.5 + + + + + + + + + 0.3 + + + + + + 0.5 + + + + - - - - - - 1 - - - - - - - - 0.5 - - - - - - 0.5 - - - - - - - - - 0.3 - - - - - - 0.5 - - - - - diff --git a/jsprit-core/src/main/resources/randomWalk.xml b/jsprit-core/src/main/resources/randomWalk.xml index 71deaf48..5edcc3f9 100755 --- a/jsprit-core/src/main/resources/randomWalk.xml +++ b/jsprit-core/src/main/resources/randomWalk.xml @@ -1,46 +1,47 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.w3schools.com algorithm_schema.xsd"> + + + + + + + 1 + + + + + + + + 0.5 + + + + + + 0.5 + + + + + + + + + 0.3 + + + + + + 0.5 + + + + - - - - - - 1 - - - - - - - - 0.5 - - - - - - 0.5 - - - - - - - - - 0.3 - - - - - - 0.5 - - - - - diff --git a/jsprit-core/src/main/resources/schrimpf.xml b/jsprit-core/src/main/resources/schrimpf.xml index a7fca75f..97052620 100755 --- a/jsprit-core/src/main/resources/schrimpf.xml +++ b/jsprit-core/src/main/resources/schrimpf.xml @@ -1,51 +1,52 @@ - - 2000 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.w3schools.com algorithm_schema.xsd"> + + 2000 + + + + + + + 1 + + + + + 0.4 + 100 + + + + + 0.5 + + + + + + 0.5 + + + + + + + + + 0.3 + + + + + + 0.5 + + + + - - - - - - 1 - - - - - 0.4 - 100 - - - - - 0.5 - - - - - - 0.5 - - - - - - - - - 0.3 - - - - - - 0.5 - - - - - diff --git a/jsprit-core/src/main/resources/vrp_xml_schema.xsd b/jsprit-core/src/main/resources/vrp_xml_schema.xsd index c0e878cd..8ed94b85 100644 --- a/jsprit-core/src/main/resources/vrp_xml_schema.xsd +++ b/jsprit-core/src/main/resources/vrp_xml_schema.xsd @@ -18,330 +18,359 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~--> + xmlns="http://www.w3schools.com" elementFormDefault="qualified"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + - - - - - - - + + + + - - - - - - - + + + + + + + + + + + + + + + + + + - - - - - - + + + - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/jsprit-core/src/test/java/jsprit/core/IntegrationTest.java b/jsprit-core/src/test/java/jsprit/core/IntegrationTest.java new file mode 100644 index 00000000..b16ee817 --- /dev/null +++ b/jsprit-core/src/test/java/jsprit/core/IntegrationTest.java @@ -0,0 +1,7 @@ +package jsprit.core; + +/** + * Created by schroeder on 17/09/15. + */ +public interface IntegrationTest { +} diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/BuildCVRPAlgoFromScratch_IT.java b/jsprit-core/src/test/java/jsprit/core/algorithm/BuildCVRPAlgoFromScratch_IT.java index c177b709..fbe11cab 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/BuildCVRPAlgoFromScratch_IT.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/BuildCVRPAlgoFromScratch_IT.java @@ -11,11 +11,12 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm; +import jsprit.core.IntegrationTest; import jsprit.core.algorithm.acceptor.GreedyAcceptance; import jsprit.core.algorithm.module.RuinAndRecreateModule; import jsprit.core.algorithm.recreate.BestInsertionBuilder; @@ -38,6 +39,7 @@ import jsprit.core.problem.vehicle.VehicleFleetManager; import jsprit.core.util.Solutions; import org.junit.Before; import org.junit.Test; +import org.junit.experimental.categories.Category; import java.util.Collection; @@ -45,61 +47,62 @@ import static org.junit.Assert.assertEquals; public class BuildCVRPAlgoFromScratch_IT { - - 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 StateManager stateManager = new StateManager(vrp); - ConstraintManager cManager = new ConstraintManager(vrp, stateManager); - VehicleFleetManager fleetManager = new InfiniteFleetManagerFactory(vrp.getVehicles()).createFleetManager(); - - InsertionStrategy bestInsertion = new BestInsertionBuilder(vrp, fleetManager, stateManager, cManager).build(); - - RuinStrategy radial = new RadialRuinStrategyFactory(0.15, new AvgServiceDistance(vrp.getTransportCosts())).createStrategy(vrp); - RuinStrategy random = new RandomRuinStrategyFactory(0.25).createStrategy(vrp); - - SolutionCostCalculator solutionCostCalculator = new SolutionCostCalculator() { - - @Override - public double getCosts(VehicleRoutingProblemSolution solution) { - double costs = 0.0; - for(VehicleRoute route : solution.getRoutes()){ - costs += stateManager.getRouteState(route, InternalStates.COSTS,Double.class); - } - return costs; - } - }; - - SearchStrategy randomStrategy = new SearchStrategy("random", new SelectBest(), new GreedyAcceptance(1), solutionCostCalculator); - RuinAndRecreateModule randomModule = new RuinAndRecreateModule("randomRuin_bestInsertion", bestInsertion, random); - randomStrategy.addModule(randomModule); - - SearchStrategy radialStrategy = new SearchStrategy("radial", new SelectBest(), new GreedyAcceptance(1), solutionCostCalculator); - RuinAndRecreateModule radialModule = new RuinAndRecreateModule("radialRuin_bestInsertion", bestInsertion, radial); - radialStrategy.addModule(radialModule); + VehicleRoutingProblem vrp; - vra = new PrettyAlgorithmBuilder(vrp,fleetManager,stateManager,cManager) - .withStrategy(randomStrategy,0.5).withStrategy(radialStrategy,0.5) - .addCoreStateAndConstraintStuff() - .constructInitialSolutionWith(bestInsertion,solutionCostCalculator).build(); - vra.setMaxIterations(2000); + VehicleRoutingAlgorithm vra; - } - - @Test - public void testVRA(){ - Collection solutions = vra.searchSolutions(); - System.out.println("costs="+Solutions.bestOf(solutions).getCost()+";#routes="+Solutions.bestOf(solutions).getRoutes().size()); - assertEquals(530.0, Solutions.bestOf(solutions).getCost(),50.0); - assertEquals(5, Solutions.bestOf(solutions).getRoutes().size()); - } + @Before + public void setup() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(builder).read("src/test/resources/vrpnc1-jsprit.xml"); + vrp = builder.build(); + + final StateManager stateManager = new StateManager(vrp); + ConstraintManager cManager = new ConstraintManager(vrp, stateManager); + + VehicleFleetManager fleetManager = new InfiniteFleetManagerFactory(vrp.getVehicles()).createFleetManager(); + + InsertionStrategy bestInsertion = new BestInsertionBuilder(vrp, fleetManager, stateManager, cManager).build(); + + RuinStrategy radial = new RadialRuinStrategyFactory(0.15, new AvgServiceDistance(vrp.getTransportCosts())).createStrategy(vrp); + RuinStrategy random = new RandomRuinStrategyFactory(0.25).createStrategy(vrp); + + SolutionCostCalculator solutionCostCalculator = new SolutionCostCalculator() { + + @Override + public double getCosts(VehicleRoutingProblemSolution solution) { + double costs = 0.0; + for (VehicleRoute route : solution.getRoutes()) { + costs += stateManager.getRouteState(route, InternalStates.COSTS, Double.class); + } + return costs; + } + }; + + SearchStrategy randomStrategy = new SearchStrategy("random", new SelectBest(), new GreedyAcceptance(1), solutionCostCalculator); + RuinAndRecreateModule randomModule = new RuinAndRecreateModule("randomRuin_bestInsertion", bestInsertion, random); + randomStrategy.addModule(randomModule); + + SearchStrategy radialStrategy = new SearchStrategy("radial", new SelectBest(), new GreedyAcceptance(1), solutionCostCalculator); + RuinAndRecreateModule radialModule = new RuinAndRecreateModule("radialRuin_bestInsertion", bestInsertion, radial); + radialStrategy.addModule(radialModule); + + vra = new PrettyAlgorithmBuilder(vrp, fleetManager, stateManager, cManager) + .withStrategy(randomStrategy, 0.5).withStrategy(radialStrategy, 0.5) + .addCoreStateAndConstraintStuff() + .constructInitialSolutionWith(bestInsertion, solutionCostCalculator).build(); + vra.setMaxIterations(2000); + + } + + @Test + @Category(IntegrationTest.class) + public void testVRA() { + Collection solutions = vra.searchSolutions(); + System.out.println("costs=" + Solutions.bestOf(solutions).getCost() + ";#routes=" + Solutions.bestOf(solutions).getRoutes().size()); + assertEquals(530.0, Solutions.bestOf(solutions).getCost(), 50.0); + assertEquals(5, Solutions.bestOf(solutions).getRoutes().size()); + } } diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/BuildPDVRPAlgoFromScratch_IT.java b/jsprit-core/src/test/java/jsprit/core/algorithm/BuildPDVRPAlgoFromScratch_IT.java index 5b6220a1..59a559c0 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/BuildPDVRPAlgoFromScratch_IT.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/BuildPDVRPAlgoFromScratch_IT.java @@ -11,11 +11,12 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm; +import jsprit.core.IntegrationTest; import jsprit.core.algorithm.acceptor.GreedyAcceptance; import jsprit.core.algorithm.module.RuinAndRecreateModule; import jsprit.core.algorithm.recreate.BestInsertionBuilder; @@ -42,77 +43,78 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.junit.Before; import org.junit.Test; +import org.junit.experimental.categories.Category; import java.util.Collection; public class BuildPDVRPAlgoFromScratch_IT { - - VehicleRoutingProblem vrp; - - VehicleRoutingAlgorithm vra; - static Logger log = LogManager.getLogger(BuildPDVRPAlgoFromScratch_IT.class); - - @Before - public void setup(){ - - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder).read("src/test/resources/pd_solomon_r101.xml"); - vrp = builder.build(); - - final StateManager stateManager = new StateManager(vrp); - - ConstraintManager constraintManager = new ConstraintManager(vrp,stateManager); + VehicleRoutingProblem vrp; - VehicleFleetManager fleetManager = new InfiniteFleetManagerFactory(vrp.getVehicles()).createFleetManager(); + VehicleRoutingAlgorithm vra; - InsertionStrategy bestInsertion = new BestInsertionBuilder(vrp, fleetManager, stateManager, constraintManager).build(); + static Logger log = LogManager.getLogger(BuildPDVRPAlgoFromScratch_IT.class); - RuinStrategy radial = new RadialRuinStrategyFactory( 0.15, new AvgServiceDistance(vrp.getTransportCosts())).createStrategy(vrp); - RuinStrategy random = new RandomRuinStrategyFactory(0.25).createStrategy(vrp); - - SolutionCostCalculator solutionCostCalculator = new SolutionCostCalculator() { - - @Override - public double getCosts(VehicleRoutingProblemSolution solution) { - double costs = 0.0; - for(VehicleRoute route : solution.getRoutes()){ - Double cost_of_route = stateManager.getRouteState(route, InternalStates.COSTS, Double.class); - if(cost_of_route == null) cost_of_route = 0.; - costs += cost_of_route; - } - return costs; - } - }; - - SearchStrategy randomStrategy = new SearchStrategy("random", new SelectBest(), new GreedyAcceptance(1), solutionCostCalculator); - RuinAndRecreateModule randomModule = new RuinAndRecreateModule("randomRuin_bestInsertion", bestInsertion, random); - randomStrategy.addModule(randomModule); - - SearchStrategy radialStrategy = new SearchStrategy("radial", new SelectBest(), new GreedyAcceptance(1), solutionCostCalculator); - RuinAndRecreateModule radialModule = new RuinAndRecreateModule("radialRuin_bestInsertion", bestInsertion, radial); - radialStrategy.addModule(radialModule); + @Before + public void setup() { - vra = new PrettyAlgorithmBuilder(vrp,fleetManager,stateManager,constraintManager) - .addCoreStateAndConstraintStuff().constructInitialSolutionWith(bestInsertion,solutionCostCalculator) - .withStrategy(radialStrategy,0.5).withStrategy(randomStrategy,0.5).build(); + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(builder).read("src/test/resources/pd_solomon_r101.xml"); + vrp = builder.build(); - vra.setMaxIterations(1000); - vra.setPrematureAlgorithmTermination(new IterationWithoutImprovementTermination(100)); - - } - - @Test - public void test(){ - try { - Collection solutions = vra.searchSolutions(); - System.out.println(Solutions.bestOf(solutions).getCost()); - Assert.assertTrue(true); - } - catch (Exception e){ - Assert.assertTrue(false); - } - } + final StateManager stateManager = new StateManager(vrp); + + ConstraintManager constraintManager = new ConstraintManager(vrp, stateManager); + + VehicleFleetManager fleetManager = new InfiniteFleetManagerFactory(vrp.getVehicles()).createFleetManager(); + + 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); + + SolutionCostCalculator solutionCostCalculator = new SolutionCostCalculator() { + + @Override + public double getCosts(VehicleRoutingProblemSolution solution) { + double costs = 0.0; + for (VehicleRoute route : solution.getRoutes()) { + Double cost_of_route = stateManager.getRouteState(route, InternalStates.COSTS, Double.class); + if (cost_of_route == null) cost_of_route = 0.; + costs += cost_of_route; + } + return costs; + } + }; + + SearchStrategy randomStrategy = new SearchStrategy("random", new SelectBest(), new GreedyAcceptance(1), solutionCostCalculator); + RuinAndRecreateModule randomModule = new RuinAndRecreateModule("randomRuin_bestInsertion", bestInsertion, random); + randomStrategy.addModule(randomModule); + + SearchStrategy radialStrategy = new SearchStrategy("radial", new SelectBest(), new GreedyAcceptance(1), solutionCostCalculator); + RuinAndRecreateModule radialModule = new RuinAndRecreateModule("radialRuin_bestInsertion", bestInsertion, radial); + radialStrategy.addModule(radialModule); + + 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 + @Category(IntegrationTest.class) + public void test() { + try { + Collection solutions = vra.searchSolutions(); + System.out.println(Solutions.bestOf(solutions).getCost()); + Assert.assertTrue(true); + } catch (Exception e) { + Assert.assertTrue(false); + } + } } diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/BuildPDVRPWithShipmentsAlgoFromScratch_IT.java b/jsprit-core/src/test/java/jsprit/core/algorithm/BuildPDVRPWithShipmentsAlgoFromScratch_IT.java index 509fc00b..9c756ca4 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/BuildPDVRPWithShipmentsAlgoFromScratch_IT.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/BuildPDVRPWithShipmentsAlgoFromScratch_IT.java @@ -11,11 +11,12 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm; +import jsprit.core.IntegrationTest; import jsprit.core.algorithm.acceptor.GreedyAcceptance; import jsprit.core.algorithm.module.RuinAndRecreateModule; import jsprit.core.algorithm.recreate.BestInsertionBuilder; @@ -37,6 +38,7 @@ import jsprit.core.problem.solution.route.VehicleRoute; import jsprit.core.problem.vehicle.InfiniteFleetManagerFactory; import jsprit.core.problem.vehicle.VehicleFleetManager; import org.junit.Test; +import org.junit.experimental.categories.Category; import java.util.Collection; @@ -45,8 +47,9 @@ import static org.junit.Assert.assertTrue; public class BuildPDVRPWithShipmentsAlgoFromScratch_IT { - @Test - public void test(){ + @Test + @Category(IntegrationTest.class) + public void test() { VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); new VrpXMLReader(builder).read("src/test/resources/pdp.xml"); @@ -57,17 +60,17 @@ public class BuildPDVRPWithShipmentsAlgoFromScratch_IT { // stateManager.updateTimeWindowStates(); stateManager.addStateUpdater(new UpdateVariableCosts(vrp.getActivityCosts(), vrp.getTransportCosts(), stateManager)); - ConstraintManager constraintManager = new ConstraintManager(vrp,stateManager); + ConstraintManager constraintManager = new ConstraintManager(vrp, stateManager); // constraintManager.addTimeWindowConstraint(); constraintManager.addLoadConstraint(); VehicleFleetManager fleetManager = new InfiniteFleetManagerFactory(vrp.getVehicles()).createFleetManager(); - BestInsertionBuilder bestIBuilder = new BestInsertionBuilder(vrp, fleetManager, stateManager,constraintManager); + BestInsertionBuilder bestIBuilder = new BestInsertionBuilder(vrp, fleetManager, stateManager, constraintManager); InsertionStrategy bestInsertion = bestIBuilder.build(); - RuinStrategy radial = new RadialRuinStrategyFactory( 0.3, new AvgServiceAndShipmentDistance(vrp.getTransportCosts())).createStrategy(vrp); + RuinStrategy radial = new RadialRuinStrategyFactory(0.3, new AvgServiceAndShipmentDistance(vrp.getTransportCosts())).createStrategy(vrp); RuinStrategy random = new RandomRuinStrategyFactory(0.5).createStrategy(vrp); @@ -76,18 +79,18 @@ public class BuildPDVRPWithShipmentsAlgoFromScratch_IT { @Override public double getCosts(VehicleRoutingProblemSolution solution) { double costs = 0.0; - for(VehicleRoute route : solution.getRoutes()){ + for (VehicleRoute route : solution.getRoutes()) { costs += stateManager.getRouteState(route, InternalStates.COSTS, Double.class); } return costs; } }; - SearchStrategy randomStrategy = new SearchStrategy("random",new SelectBest(), new GreedyAcceptance(1), solutionCostCalculator); + SearchStrategy randomStrategy = new SearchStrategy("random", new SelectBest(), new GreedyAcceptance(1), solutionCostCalculator); RuinAndRecreateModule randomModule = new RuinAndRecreateModule("randomRuin_bestInsertion", bestInsertion, random); randomStrategy.addModule(randomModule); - SearchStrategy radialStrategy = new SearchStrategy("radial",new SelectBest(), new GreedyAcceptance(1), solutionCostCalculator); + SearchStrategy radialStrategy = new SearchStrategy("radial", new SelectBest(), new GreedyAcceptance(1), solutionCostCalculator); RuinAndRecreateModule radialModule = new RuinAndRecreateModule("radialRuin_bestInsertion", bestInsertion, radial); radialStrategy.addModule(radialModule); @@ -103,10 +106,9 @@ public class BuildPDVRPWithShipmentsAlgoFromScratch_IT { vra.addInitialSolution(iniSolution); vra.setMaxIterations(3); - Collection solutions = vra.searchSolutions(); - assertTrue(!solutions.isEmpty()); - } - + Collection solutions = vra.searchSolutions(); + assertTrue(!solutions.isEmpty()); + } } diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/CVRPwithDeliveriesAndDifferentInsertionStrategies_IT.java b/jsprit-core/src/test/java/jsprit/core/algorithm/CVRPwithDeliveriesAndDifferentInsertionStrategies_IT.java index 9c92d6c3..19cdd207 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/CVRPwithDeliveriesAndDifferentInsertionStrategies_IT.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/CVRPwithDeliveriesAndDifferentInsertionStrategies_IT.java @@ -16,35 +16,38 @@ ******************************************************************************/ package jsprit.core.algorithm; +import jsprit.core.IntegrationTest; import jsprit.core.algorithm.io.VehicleRoutingAlgorithms; import jsprit.core.problem.VehicleRoutingProblem; import jsprit.core.problem.io.VrpXMLReader; import jsprit.core.problem.solution.VehicleRoutingProblemSolution; import junit.framework.Assert; import org.junit.Test; +import org.junit.experimental.categories.Category; import java.util.Collection; public class CVRPwithDeliveriesAndDifferentInsertionStrategies_IT { - - @Test - public void whenWithTwoInsertionStrategiesWhereOnleOneIsInAlgo_itShouldWork(){ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpBuilder).read("src/test/resources/vrpnc1-jsprit-with-deliveries.xml"); - VehicleRoutingProblem vrp = vrpBuilder.build(); - VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/algorithmConfig_greedyWithRegret.xml"); - vra.setMaxIterations(10); - try { - Collection solutions = vra.searchSolutions(); - Assert.assertTrue(true); - } - catch (Exception e){ - Assert.assertTrue(false); - } - } @Test - public void whenWithTwoInsertionStrategiesWhereBothAreInAlgo_itShouldWork(){ + @Category(IntegrationTest.class) + public void whenWithTwoInsertionStrategiesWhereOnleOneIsInAlgo_itShouldWork() { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(vrpBuilder).read("src/test/resources/vrpnc1-jsprit-with-deliveries.xml"); + VehicleRoutingProblem vrp = vrpBuilder.build(); + VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/algorithmConfig_greedyWithRegret.xml"); + vra.setMaxIterations(10); + try { + Collection solutions = vra.searchSolutions(); + Assert.assertTrue(true); + } catch (Exception e) { + Assert.assertTrue(false); + } + } + + @Test + @Category(IntegrationTest.class) + public void whenWithTwoInsertionStrategiesWhereBothAreInAlgo_itShouldWork() { VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); new VrpXMLReader(vrpBuilder).read("src/test/resources/vrpnc1-jsprit-with-deliveries.xml"); VehicleRoutingProblem vrp = vrpBuilder.build(); @@ -53,8 +56,7 @@ public class CVRPwithDeliveriesAndDifferentInsertionStrategies_IT { try { Collection solutions = vra.searchSolutions(); Assert.assertTrue(true); - } - catch (Exception e){ + } catch (Exception e) { Assert.assertTrue(false); } } diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/CVRPwithDeliveries_IT.java b/jsprit-core/src/test/java/jsprit/core/algorithm/CVRPwithDeliveries_IT.java index 0e67036d..ba823254 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/CVRPwithDeliveries_IT.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/CVRPwithDeliveries_IT.java @@ -16,6 +16,7 @@ ******************************************************************************/ package jsprit.core.algorithm; +import jsprit.core.IntegrationTest; import jsprit.core.algorithm.box.Jsprit; import jsprit.core.algorithm.io.VehicleRoutingAlgorithms; import jsprit.core.problem.VehicleRoutingProblem; @@ -23,33 +24,36 @@ import jsprit.core.problem.io.VrpXMLReader; import jsprit.core.problem.solution.VehicleRoutingProblemSolution; import jsprit.core.util.Solutions; import org.junit.Test; +import org.junit.experimental.categories.Category; import java.util.Collection; import static org.junit.Assert.assertEquals; public class CVRPwithDeliveries_IT { - - @Test - public void whenSolvingVRPNC1withDeliveries_solutionsMustNoBeWorseThan5PercentOfBestKnownSolution(){ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpBuilder).read("src/test/resources/vrpnc1-jsprit-with-deliveries.xml"); - VehicleRoutingProblem vrp = vrpBuilder.build(); - VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/algorithmConfig.xml"); - Collection solutions = vra.searchSolutions(); - assertEquals(530.0, Solutions.bestOf(solutions).getCost(),50.0); - assertEquals(5, Solutions.bestOf(solutions).getRoutes().size()); - } - @Test - public void whenSolvingVRPNC1withDeliveriesWithJsprit_solutionsMustNoBeWorseThan5PercentOfBestKnownSolution(){ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpBuilder).read("src/test/resources/vrpnc1-jsprit-with-deliveries.xml"); - VehicleRoutingProblem vrp = vrpBuilder.build(); - VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp); - Collection solutions = vra.searchSolutions(); - assertEquals(530.0, Solutions.bestOf(solutions).getCost(), 50.0); - assertEquals(5, Solutions.bestOf(solutions).getRoutes().size()); - } + @Test + @Category(IntegrationTest.class) + public void whenSolvingVRPNC1withDeliveries_solutionsMustNoBeWorseThan5PercentOfBestKnownSolution() { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(vrpBuilder).read("src/test/resources/vrpnc1-jsprit-with-deliveries.xml"); + VehicleRoutingProblem vrp = vrpBuilder.build(); + VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/algorithmConfig.xml"); + Collection solutions = vra.searchSolutions(); + assertEquals(530.0, Solutions.bestOf(solutions).getCost(), 50.0); + assertEquals(5, Solutions.bestOf(solutions).getRoutes().size()); + } + + @Test + @Category(IntegrationTest.class) + public void whenSolvingVRPNC1withDeliveriesWithJsprit_solutionsMustNoBeWorseThan5PercentOfBestKnownSolution() { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(vrpBuilder).read("src/test/resources/vrpnc1-jsprit-with-deliveries.xml"); + VehicleRoutingProblem vrp = vrpBuilder.build(); + VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp); + Collection solutions = vra.searchSolutions(); + assertEquals(530.0, Solutions.bestOf(solutions).getCost(), 50.0); + assertEquals(5, Solutions.bestOf(solutions).getRoutes().size()); + } } diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/CVRPwithMatrix_IT.java b/jsprit-core/src/test/java/jsprit/core/algorithm/CVRPwithMatrix_IT.java index ccf33482..a37205de 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/CVRPwithMatrix_IT.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/CVRPwithMatrix_IT.java @@ -16,6 +16,7 @@ ******************************************************************************/ package jsprit.core.algorithm; +import jsprit.core.IntegrationTest; import jsprit.core.algorithm.io.VehicleRoutingAlgorithms; import jsprit.core.analysis.SolutionAnalyser; import jsprit.core.problem.Location; @@ -31,6 +32,7 @@ import jsprit.core.util.EuclideanDistanceCalculator; import jsprit.core.util.FastVehicleRoutingTransportCostsMatrix; import jsprit.core.util.Solutions; import org.junit.Test; +import org.junit.experimental.categories.Category; import java.util.ArrayList; import java.util.Collection; @@ -40,96 +42,97 @@ import static org.junit.Assert.*; public class CVRPwithMatrix_IT { - private int index = 0; + private int index = 0; - @Test - public void whenReturnToDepot_itShouldWorkWithMatrix(){ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpBuilder).read("src/test/resources/vrpnc1-jsprit-with-deliveries.xml"); - VehicleRoutingProblem vrp_ = vrpBuilder.build(); - VehicleRoutingProblem vrp = createVrpWithLocationIndecesAndMatrix(vrp_, true); - VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/algorithmConfig.xml"); - Collection solutions = vra.searchSolutions(); - assertEquals(530.0, Solutions.bestOf(solutions).getCost(),50.0); + @Test + @Category(IntegrationTest.class) + public void whenReturnToDepot_itShouldWorkWithMatrix() { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(vrpBuilder).read("src/test/resources/vrpnc1-jsprit-with-deliveries.xml"); + VehicleRoutingProblem vrp_ = vrpBuilder.build(); + VehicleRoutingProblem vrp = createVrpWithLocationIndecesAndMatrix(vrp_, true); + VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/algorithmConfig.xml"); + Collection solutions = vra.searchSolutions(); + assertEquals(530.0, Solutions.bestOf(solutions).getCost(), 50.0); assertEquals(5, Solutions.bestOf(solutions).getRoutes().size()); - } + } - @Test - public void whenNotReturnToDepot_itShouldWorkWithMatrix(){ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpBuilder).read("src/test/resources/vrpnc1-jsprit-with-deliveries.xml"); - VehicleRoutingProblem vrp_ = vrpBuilder.build(); - VehicleRoutingProblem vrp = createVrpWithLocationIndecesAndMatrix(vrp_,false); - VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/algorithmConfig.xml"); - try { - Collection solutions = vra.searchSolutions(); - assertTrue(true); - } - catch (Exception e){ - assertFalse(true); - } - } + @Test + @Category(IntegrationTest.class) + public void whenNotReturnToDepot_itShouldWorkWithMatrix() { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(vrpBuilder).read("src/test/resources/vrpnc1-jsprit-with-deliveries.xml"); + VehicleRoutingProblem vrp_ = vrpBuilder.build(); + VehicleRoutingProblem vrp = createVrpWithLocationIndecesAndMatrix(vrp_, false); + VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/algorithmConfig.xml"); + try { + Collection solutions = vra.searchSolutions(); + assertTrue(true); + } catch (Exception e) { + assertFalse(true); + } + } - @Test - public void whenCalcTimeWithSolutionAnalyser_itShouldWork(){ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpBuilder).read("src/test/resources/vrpnc1-jsprit-with-deliveries.xml"); - VehicleRoutingProblem vrp_ = vrpBuilder.build(); - final VehicleRoutingProblem vrp = createVrpWithLocationIndecesAndMatrix(vrp_,false); - VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/algorithmConfig.xml"); - Collection solutions = vra.searchSolutions(); - SolutionAnalyser sa = new SolutionAnalyser(vrp, Solutions.bestOf(solutions), new TransportDistance() { - @Override - public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from,to,0.,null,null); - } - }); - System.out.println(sa.getDistance()); - System.out.println(sa.getTransportTime()); - } + @Test + @Category(IntegrationTest.class) + public void whenCalcTimeWithSolutionAnalyser_itShouldWork() { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(vrpBuilder).read("src/test/resources/vrpnc1-jsprit-with-deliveries.xml"); + VehicleRoutingProblem vrp_ = vrpBuilder.build(); + final VehicleRoutingProblem vrp = createVrpWithLocationIndecesAndMatrix(vrp_, false); + VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/algorithmConfig.xml"); + Collection solutions = vra.searchSolutions(); + SolutionAnalyser sa = new SolutionAnalyser(vrp, Solutions.bestOf(solutions), new TransportDistance() { + @Override + public double getDistance(Location from, Location to) { + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); + } + }); + System.out.println(sa.getDistance()); + System.out.println(sa.getTransportTime()); + } - - private VehicleRoutingProblem createVrpWithLocationIndecesAndMatrix(VehicleRoutingProblem vrp_, boolean return_to_depot) { - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - List locations = new ArrayList(); - for (Vehicle v : vrp_.getVehicles()) { - Location l = Location.Builder.newInstance().setIndex(getIndex()).setId(v.getStartLocation().getId()) - .setCoordinate(v.getStartLocation().getCoordinate()).build(); - VehicleImpl.Builder newVehicleBuilder = VehicleImpl.Builder.newInstance(v.getId()).setType(v.getType()) - .setEarliestStart(v.getEarliestDeparture()).setLatestArrival(v.getLatestArrival()) - .setStartLocation(l).setReturnToDepot(return_to_depot); - VehicleImpl newVehicle = newVehicleBuilder.build(); - vrpBuilder.addVehicle(newVehicle); - locations.add(l); - } - for (Job j : vrp_.getJobs().values()){ - Service s = (Service) j; - Location l = Location.Builder.newInstance().setIndex(getIndex()) - .setId(s.getLocation().getId()).setCoordinate(s.getLocation().getCoordinate()).build(); - Service newService = Service.Builder.newInstance(s.getId()).setServiceTime(s.getServiceDuration()) - .addSizeDimension(0,s.getSize().get(0)) - .setLocation(l).build(); - vrpBuilder.addJob(newService); - locations.add(l); - } - FastVehicleRoutingTransportCostsMatrix.Builder matrixBuilder = FastVehicleRoutingTransportCostsMatrix.Builder.newInstance(locations.size(),true); - for(Location from : locations){ - for(Location to : locations){ - double distance = EuclideanDistanceCalculator.calculateDistance(from.getCoordinate(), to.getCoordinate()); - matrixBuilder.addTransportDistance(from.getIndex(),to.getIndex(), distance); - matrixBuilder.addTransportTime(from.getIndex(),to.getIndex(),distance); - } - } - vrpBuilder.setRoutingCost(matrixBuilder.build()); - return vrpBuilder.build(); - } + private VehicleRoutingProblem createVrpWithLocationIndecesAndMatrix(VehicleRoutingProblem vrp_, boolean return_to_depot) { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + List locations = new ArrayList(); + for (Vehicle v : vrp_.getVehicles()) { + Location l = Location.Builder.newInstance().setIndex(getIndex()).setId(v.getStartLocation().getId()) + .setCoordinate(v.getStartLocation().getCoordinate()).build(); + VehicleImpl.Builder newVehicleBuilder = VehicleImpl.Builder.newInstance(v.getId()).setType(v.getType()) + .setEarliestStart(v.getEarliestDeparture()).setLatestArrival(v.getLatestArrival()) + .setStartLocation(l).setReturnToDepot(return_to_depot); + VehicleImpl newVehicle = newVehicleBuilder.build(); + vrpBuilder.addVehicle(newVehicle); + locations.add(l); + } + for (Job j : vrp_.getJobs().values()) { + Service s = (Service) j; + Location l = Location.Builder.newInstance().setIndex(getIndex()) + .setId(s.getLocation().getId()).setCoordinate(s.getLocation().getCoordinate()).build(); + Service newService = Service.Builder.newInstance(s.getId()).setServiceTime(s.getServiceDuration()) + .addSizeDimension(0, s.getSize().get(0)) + .setLocation(l).build(); + vrpBuilder.addJob(newService); + locations.add(l); + } + FastVehicleRoutingTransportCostsMatrix.Builder matrixBuilder = FastVehicleRoutingTransportCostsMatrix.Builder.newInstance(locations.size(), true); + for (Location from : locations) { + for (Location to : locations) { + double distance = EuclideanDistanceCalculator.calculateDistance(from.getCoordinate(), to.getCoordinate()); + matrixBuilder.addTransportDistance(from.getIndex(), to.getIndex(), distance); + matrixBuilder.addTransportTime(from.getIndex(), to.getIndex(), distance); + } + } + vrpBuilder.setRoutingCost(matrixBuilder.build()); + return vrpBuilder.build(); + } - public int getIndex() { - int i = index; - index++; - return i; - } + public int getIndex() { + int i = index; + index++; + return i; + } } diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/CVRPwithPickups_IT.java b/jsprit-core/src/test/java/jsprit/core/algorithm/CVRPwithPickups_IT.java index a37ea13a..c80d4e73 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/CVRPwithPickups_IT.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/CVRPwithPickups_IT.java @@ -16,6 +16,7 @@ ******************************************************************************/ package jsprit.core.algorithm; +import jsprit.core.IntegrationTest; import jsprit.core.algorithm.box.Jsprit; import jsprit.core.algorithm.io.VehicleRoutingAlgorithms; import jsprit.core.problem.VehicleRoutingProblem; @@ -23,34 +24,37 @@ import jsprit.core.problem.io.VrpXMLReader; import jsprit.core.problem.solution.VehicleRoutingProblemSolution; import jsprit.core.util.Solutions; import org.junit.Test; +import org.junit.experimental.categories.Category; import java.util.Collection; import static org.junit.Assert.assertEquals; public class CVRPwithPickups_IT { - - @Test - public void whenSolvingVRPNC1WithPickups_solutionsMustNoBeWorseThan5PercentOfBestKnownSolution(){ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpBuilder).read("src/test/resources/vrpnc1-jsprit-with-pickups.xml"); - VehicleRoutingProblem vrp = vrpBuilder.build(); - VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/algorithmConfig.xml"); - Collection solutions = vra.searchSolutions(); - assertEquals(530.0, Solutions.bestOf(solutions).getCost(),50.0); - assertEquals(5, Solutions.bestOf(solutions).getRoutes().size()); - } - @Test - public void whenSolvingVRPNC1WithPickupsWithJsprit_solutionsMustNoBeWorseThan5PercentOfBestKnownSolution(){ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpBuilder).read("src/test/resources/vrpnc1-jsprit-with-pickups.xml"); - VehicleRoutingProblem vrp = vrpBuilder.build(); - VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp); - vra.setMaxIterations(1000); - Collection solutions = vra.searchSolutions(); - assertEquals(530.0, Solutions.bestOf(solutions).getCost(),50.0); - assertEquals(5, Solutions.bestOf(solutions).getRoutes().size()); - } + @Test + @Category(IntegrationTest.class) + public void whenSolvingVRPNC1WithPickups_solutionsMustNoBeWorseThan5PercentOfBestKnownSolution() { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(vrpBuilder).read("src/test/resources/vrpnc1-jsprit-with-pickups.xml"); + VehicleRoutingProblem vrp = vrpBuilder.build(); + VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/algorithmConfig.xml"); + Collection solutions = vra.searchSolutions(); + assertEquals(530.0, Solutions.bestOf(solutions).getCost(), 50.0); + assertEquals(5, Solutions.bestOf(solutions).getRoutes().size()); + } + + @Test + @Category(IntegrationTest.class) + public void whenSolvingVRPNC1WithPickupsWithJsprit_solutionsMustNoBeWorseThan5PercentOfBestKnownSolution() { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(vrpBuilder).read("src/test/resources/vrpnc1-jsprit-with-pickups.xml"); + VehicleRoutingProblem vrp = vrpBuilder.build(); + VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp); + vra.setMaxIterations(1000); + Collection solutions = vra.searchSolutions(); + assertEquals(530.0, Solutions.bestOf(solutions).getCost(), 50.0); + assertEquals(5, Solutions.bestOf(solutions).getRoutes().size()); + } } diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/DeactivateTimeWindowsTest.java b/jsprit-core/src/test/java/jsprit/core/algorithm/DeactivateTimeWindowsTest.java index ff5a9970..3fb28e47 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/DeactivateTimeWindowsTest.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/DeactivateTimeWindowsTest.java @@ -36,12 +36,12 @@ import java.util.Collection; public class DeactivateTimeWindowsTest { @Test - public void activityTimesShouldIgnoreTimeWindows(){ + public void activityTimesShouldIgnoreTimeWindows() { Service service = Service.Builder.newInstance("s").setLocation(Location.newInstance(20, 0)) - .setTimeWindow(TimeWindow.newInstance(40, 50)).build(); + .setTimeWindow(TimeWindow.newInstance(40, 50)).build(); VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0, 0)).build(); VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(service).addVehicle(vehicle).build(); - VehicleRoutingAlgorithmBuilder vraBuilder = new VehicleRoutingAlgorithmBuilder(vrp,"src/test/resources/algorithmConfig.xml"); + VehicleRoutingAlgorithmBuilder vraBuilder = new VehicleRoutingAlgorithmBuilder(vrp, "src/test/resources/algorithmConfig.xml"); vraBuilder.addDefaultCostCalculators(); VehicleRoutingAlgorithm vra = vraBuilder.build(); //this should ignore any constraints vra.setMaxIterations(10); @@ -52,16 +52,16 @@ public class DeactivateTimeWindowsTest { } @Test - public void whenNotActivatingViaStateManager_activityTimesShouldConsiderTimeWindows(){ + public void whenNotActivatingViaStateManager_activityTimesShouldConsiderTimeWindows() { Service service = Service.Builder.newInstance("s").setLocation(Location.newInstance(20, 0)) - .setTimeWindow(TimeWindow.newInstance(40, 50)).build(); + .setTimeWindow(TimeWindow.newInstance(40, 50)).build(); VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0, 0)).build(); VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(service).addVehicle(vehicle).build(); - VehicleRoutingAlgorithmBuilder vraBuilder = new VehicleRoutingAlgorithmBuilder(vrp,"src/test/resources/algorithmConfig.xml"); + VehicleRoutingAlgorithmBuilder vraBuilder = new VehicleRoutingAlgorithmBuilder(vrp, "src/test/resources/algorithmConfig.xml"); vraBuilder.addDefaultCostCalculators(); StateManager stateManager = new StateManager(vrp); - ConstraintManager constraintManager = new ConstraintManager(vrp,stateManager); - vraBuilder.setStateAndConstraintManager(stateManager,constraintManager); + ConstraintManager constraintManager = new ConstraintManager(vrp, stateManager); + vraBuilder.setStateAndConstraintManager(stateManager, constraintManager); VehicleRoutingAlgorithm vra = vraBuilder.build(); //this should ignore any constraints vra.setMaxIterations(10); Collection solutions = vra.searchSolutions(); @@ -71,12 +71,12 @@ public class DeactivateTimeWindowsTest { } @Test - public void activityTimesShouldConsiderTimeWindows(){ + public void activityTimesShouldConsiderTimeWindows() { Service service = Service.Builder.newInstance("s").setLocation(Location.newInstance(20, 0)) - .setTimeWindow(TimeWindow.newInstance(40, 50)).build(); + .setTimeWindow(TimeWindow.newInstance(40, 50)).build(); VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0, 0)).build(); VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(service).addVehicle(vehicle).build(); - VehicleRoutingAlgorithmBuilder vraBuilder = new VehicleRoutingAlgorithmBuilder(vrp,"src/test/resources/algorithmConfig.xml"); + VehicleRoutingAlgorithmBuilder vraBuilder = new VehicleRoutingAlgorithmBuilder(vrp, "src/test/resources/algorithmConfig.xml"); vraBuilder.addCoreConstraints(); vraBuilder.addDefaultCostCalculators(); VehicleRoutingAlgorithm vra = vraBuilder.build(); //this should ignore any constraints @@ -88,18 +88,18 @@ public class DeactivateTimeWindowsTest { } @Test - public void whenActivatingViaStateManager_activityTimesShouldConsiderTimeWindows(){ + public void whenActivatingViaStateManager_activityTimesShouldConsiderTimeWindows() { Service service = Service.Builder.newInstance("s").setLocation(Location.newInstance(20, 0)) - .setTimeWindow(TimeWindow.newInstance(40, 50)).build(); + .setTimeWindow(TimeWindow.newInstance(40, 50)).build(); VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0, 0)).build(); VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(service).addVehicle(vehicle).build(); - VehicleRoutingAlgorithmBuilder vraBuilder = new VehicleRoutingAlgorithmBuilder(vrp,"src/test/resources/algorithmConfig.xml"); + VehicleRoutingAlgorithmBuilder vraBuilder = new VehicleRoutingAlgorithmBuilder(vrp, "src/test/resources/algorithmConfig.xml"); vraBuilder.addDefaultCostCalculators(); StateManager stateManager = new StateManager(vrp); stateManager.updateTimeWindowStates(); - ConstraintManager constraintManager = new ConstraintManager(vrp,stateManager); + ConstraintManager constraintManager = new ConstraintManager(vrp, stateManager); constraintManager.addTimeWindowConstraint(); - vraBuilder.setStateAndConstraintManager(stateManager,constraintManager); + vraBuilder.setStateAndConstraintManager(stateManager, constraintManager); VehicleRoutingAlgorithm vra = vraBuilder.build(); //this should ignore any constraints vra.setMaxIterations(10); Collection solutions = vra.searchSolutions(); diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/ExampleActivityCostFunction.java b/jsprit-core/src/test/java/jsprit/core/algorithm/ExampleActivityCostFunction.java index ddd29449..3054ed95 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/ExampleActivityCostFunction.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/ExampleActivityCostFunction.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm; @@ -23,39 +23,38 @@ import jsprit.core.problem.solution.route.activity.TourActivity.JobActivity; import jsprit.core.problem.vehicle.Vehicle; -public class ExampleActivityCostFunction implements VehicleRoutingActivityCosts{ - - public ExampleActivityCostFunction() { - super(); - } - - public double parameter_timeAtAct; +public class ExampleActivityCostFunction implements VehicleRoutingActivityCosts { - public double parameter_penaltyTooLate; + public ExampleActivityCostFunction() { + super(); + } + + public double parameter_timeAtAct; + + public double parameter_penaltyTooLate; - @Override - public double getActivityCost(TourActivity tourAct, double arrivalTime, Driver driver, Vehicle vehicle) { - if(arrivalTime == Time.TOURSTART || arrivalTime == Time.UNDEFINED ){ - return 0.0; - } - else{ - //waiting + act-time - double endTime = Math.max(arrivalTime, tourAct.getTheoreticalEarliestOperationStartTime()) + tourAct.getOperationTime(); - double timeAtAct = endTime - arrivalTime; - - double totalCost = timeAtAct * parameter_timeAtAct; + @Override + public double getActivityCost(TourActivity tourAct, double arrivalTime, Driver driver, Vehicle vehicle) { + if (arrivalTime == Time.TOURSTART || arrivalTime == Time.UNDEFINED) { + return 0.0; + } else { + //waiting + act-time + double endTime = Math.max(arrivalTime, tourAct.getTheoreticalEarliestOperationStartTime()) + tourAct.getOperationTime(); + double timeAtAct = endTime - arrivalTime; - //penalty tooLate - if(tourAct instanceof JobActivity){ - if(arrivalTime > tourAct.getTheoreticalLatestOperationStartTime()){ - double penTime = arrivalTime - tourAct.getTheoreticalLatestOperationStartTime(); - totalCost += penTime * parameter_penaltyTooLate; - } - } - return totalCost; + double totalCost = timeAtAct * parameter_timeAtAct; - } - } + //penalty tooLate + if (tourAct instanceof JobActivity) { + if (arrivalTime > tourAct.getTheoreticalLatestOperationStartTime()) { + double penTime = arrivalTime - tourAct.getTheoreticalLatestOperationStartTime(); + totalCost += penTime * parameter_penaltyTooLate; + } + } + return totalCost; + + } + } } diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/ExternalInitialSolutionIsInValidTest.java b/jsprit-core/src/test/java/jsprit/core/algorithm/ExternalInitialSolutionIsInValidTest.java index 5189a665..ccbe943b 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/ExternalInitialSolutionIsInValidTest.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/ExternalInitialSolutionIsInValidTest.java @@ -18,12 +18,12 @@ import java.util.Collection; public class ExternalInitialSolutionIsInValidTest { @Test - public void itShouldSolveProblemWithIniSolutionExternallyCreated(){ + public void itShouldSolveProblemWithIniSolutionExternallyCreated() { Service s1 = Service.Builder.newInstance("s1").setLocation(Location.newInstance(10, 0)).build(); - Service s2 = Service.Builder.newInstance("s2").setLocation(Location.newInstance(0,10)).build(); + Service s2 = Service.Builder.newInstance("s2").setLocation(Location.newInstance(0, 10)).build(); - VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v1").setStartLocation(Location.newInstance(0,0)).build(); + VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v1").setStartLocation(Location.newInstance(0, 0)).build(); VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(s1).addJob(s2).addVehicle(vehicle).build(); @@ -34,7 +34,7 @@ public class ExternalInitialSolutionIsInValidTest { */ VehicleRoute route1 = VehicleRoute.Builder.newInstance(vehicle).setJobActivityFactory(vrp.getJobActivityFactory()).addService(s1).build(); - vra.addInitialSolution(new VehicleRoutingProblemSolution(Arrays.asList(route1),20.)); + vra.addInitialSolution(new VehicleRoutingProblemSolution(Arrays.asList(route1), 20.)); Collection solutions = vra.searchSolutions(); diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/FiniteVehicleFleetManagerIdentifiesDistinctVehicle_IT.java b/jsprit-core/src/test/java/jsprit/core/algorithm/FiniteVehicleFleetManagerIdentifiesDistinctVehicle_IT.java index c20250d0..42b48d3e 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/FiniteVehicleFleetManagerIdentifiesDistinctVehicle_IT.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/FiniteVehicleFleetManagerIdentifiesDistinctVehicle_IT.java @@ -1,23 +1,24 @@ /******************************************************************************* * Copyright (c) 2014 Stefan Schroeder. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . - * + * * Contributors: * Stefan Schroeder - initial API and implementation ******************************************************************************/ package jsprit.core.algorithm; +import jsprit.core.IntegrationTest; import jsprit.core.algorithm.box.Jsprit; import jsprit.core.algorithm.box.SchrimpfFactory; import jsprit.core.algorithm.recreate.NoSolutionFoundException; @@ -25,6 +26,7 @@ import jsprit.core.problem.VehicleRoutingProblem; import jsprit.core.problem.io.VrpXMLReader; import jsprit.core.problem.solution.VehicleRoutingProblemSolution; import org.junit.Test; +import org.junit.experimental.categories.Category; import java.util.ArrayList; import java.util.Collection; @@ -33,49 +35,48 @@ import java.util.List; import static org.junit.Assert.assertTrue; public class FiniteVehicleFleetManagerIdentifiesDistinctVehicle_IT { - - @Test - public void whenEmployingVehicleWhereOnlyOneDistinctVehicleCanServeAParticularJob_algorithmShouldFoundDistinctSolution(){ - final List testFailed = new ArrayList(); - for(int i=0;i<10;i++){ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpBuilder).read("src/test/resources/biggerProblem.xml"); - VehicleRoutingProblem vrp = vrpBuilder.build(); - VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp); - vra.setMaxIterations(10); - try{ - @SuppressWarnings("unused") - Collection solutions = vra.searchSolutions(); - } - catch(NoSolutionFoundException e){ - testFailed.add(true); - } - } - System.out.println("failed: " + testFailed.size()); - assertTrue(testFailed.isEmpty()); - } + @Test + @Category(IntegrationTest.class) + public void whenEmployingVehicleWhereOnlyOneDistinctVehicleCanServeAParticularJob_algorithmShouldFoundDistinctSolution() { + final List testFailed = new ArrayList(); + for (int i = 0; i < 10; i++) { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(vrpBuilder).read("src/test/resources/biggerProblem.xml"); + VehicleRoutingProblem vrp = vrpBuilder.build(); - @Test - public void whenEmployingVehicleWhereOnlyOneDistinctVehicleCanServeAParticularJobWith_jspritAlgorithmShouldFoundDistinctSolution(){ - final List testFailed = new ArrayList(); - for(int i=0;i<10;i++){ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpBuilder).read("src/test/resources/biggerProblem.xml"); - VehicleRoutingProblem vrp = vrpBuilder.build(); + VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp); + vra.setMaxIterations(10); + try { + @SuppressWarnings("unused") + Collection solutions = vra.searchSolutions(); + } catch (NoSolutionFoundException e) { + testFailed.add(true); + } + } + System.out.println("failed: " + testFailed.size()); + assertTrue(testFailed.isEmpty()); + } - VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp); - vra.setMaxIterations(10); - try{ - @SuppressWarnings("unused") - Collection solutions = vra.searchSolutions(); - } - catch(NoSolutionFoundException e){ - testFailed.add(true); - } - } - System.out.println("failed: " + testFailed.size()); - assertTrue(testFailed.isEmpty()); - } + @Test + public void whenEmployingVehicleWhereOnlyOneDistinctVehicleCanServeAParticularJobWith_jspritAlgorithmShouldFoundDistinctSolution() { + final List testFailed = new ArrayList(); + for (int i = 0; i < 10; i++) { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(vrpBuilder).read("src/test/resources/biggerProblem.xml"); + VehicleRoutingProblem vrp = vrpBuilder.build(); + + VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp); + vra.setMaxIterations(10); + try { + @SuppressWarnings("unused") + Collection solutions = vra.searchSolutions(); + } catch (NoSolutionFoundException e) { + testFailed.add(true); + } + } + System.out.println("failed: " + testFailed.size()); + assertTrue(testFailed.isEmpty()); + } } diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/InitialRoutesTest.java b/jsprit-core/src/test/java/jsprit/core/algorithm/InitialRoutesTest.java index 8599dec7..1e395411 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/InitialRoutesTest.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/InitialRoutesTest.java @@ -20,10 +20,18 @@ package jsprit.core.algorithm; import jsprit.core.algorithm.box.GreedySchrimpfFactory; import jsprit.core.algorithm.box.Jsprit; +import jsprit.core.algorithm.box.Jsprit.Builder; import jsprit.core.algorithm.box.SchrimpfFactory; +import jsprit.core.algorithm.state.StateManager; +import jsprit.core.algorithm.state.UpdateEndLocationIfRouteIsOpen; +import jsprit.core.algorithm.state.UpdateVariableCosts; import jsprit.core.problem.AbstractActivity; import jsprit.core.problem.Location; import jsprit.core.problem.VehicleRoutingProblem; +import jsprit.core.problem.constraint.ConstraintManager; +import jsprit.core.problem.constraint.ConstraintManager.Priority; +import jsprit.core.problem.constraint.ServiceLoadActivityLevelConstraint; +import jsprit.core.problem.constraint.ServiceLoadRouteLevelConstraint; import jsprit.core.problem.io.VrpXMLReader; import jsprit.core.problem.job.Job; import jsprit.core.problem.job.Service; @@ -48,56 +56,56 @@ import static org.junit.Assert.*; public class InitialRoutesTest { @Test - public void whenReading_jobMapShouldOnlyContainJob2(){ + public void whenReading_jobMapShouldOnlyContainJob2() { VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem_iniRoutes.xml"); VehicleRoutingProblem vrp = vrpBuilder.build(); - assertEquals(1,getNuServices(vrp)); + assertEquals(1, getNuServices(vrp)); assertTrue(vrp.getJobs().containsKey("2")); } @Test - public void whenReadingProblem2_jobMapShouldContain_service2(){ + public void whenReadingProblem2_jobMapShouldContain_service2() { VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem_inclShipments_iniRoutes.xml"); VehicleRoutingProblem vrp = vrpBuilder.build(); - assertEquals(1,getNuServices(vrp)); + assertEquals(1, getNuServices(vrp)); assertTrue(vrp.getJobs().containsKey("2")); } @Test - public void whenReading_jobMapShouldContain_shipment4(){ + public void whenReading_jobMapShouldContain_shipment4() { VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem_inclShipments_iniRoutes.xml"); VehicleRoutingProblem vrp = vrpBuilder.build(); - assertEquals(1,getNuShipments(vrp)); + assertEquals(1, getNuShipments(vrp)); assertTrue(vrp.getJobs().containsKey("4")); } private int getNuShipments(VehicleRoutingProblem vrp) { int nuShipments = 0; - for(Job job : vrp.getJobs().values()){ - if(job instanceof Shipment) nuShipments++; + for (Job job : vrp.getJobs().values()) { + if (job instanceof Shipment) nuShipments++; } return nuShipments; } private int getNuServices(VehicleRoutingProblem vrp) { int nuServices = 0; - for(Job job : vrp.getJobs().values()){ - if(job instanceof Service) nuServices++; + for (Job job : vrp.getJobs().values()) { + if (job instanceof Service) nuServices++; } return nuServices; } @Test - public void whenReading_thereShouldBeOnlyOneActAssociatedToJob2(){ + public void whenReading_thereShouldBeOnlyOneActAssociatedToJob2() { VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem_iniRoutes.xml"); @@ -107,7 +115,7 @@ public class InitialRoutesTest { } @Test - public void whenReading_thereShouldBeOnlyOneActAssociatedToJob2_v2(){ + public void whenReading_thereShouldBeOnlyOneActAssociatedToJob2_v2() { VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem_inclShipments_iniRoutes.xml"); @@ -117,7 +125,7 @@ public class InitialRoutesTest { } @Test - public void whenReading_thereShouldBeTwoActsAssociatedToShipment4(){ + public void whenReading_thereShouldBeTwoActsAssociatedToShipment4() { VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem_inclShipments_iniRoutes.xml"); @@ -130,7 +138,7 @@ public class InitialRoutesTest { } @Test - public void whenSolving_nuJobsInSolutionShouldBe2(){ + public void whenSolving_nuJobsInSolutionShouldBe2() { VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem_iniRoutes.xml"); @@ -140,13 +148,13 @@ public class InitialRoutesTest { Collection solutions = vra.searchSolutions(); VehicleRoutingProblemSolution solution = Solutions.bestOf(solutions); - SolutionPrinter.print(vrp,solution, SolutionPrinter.Print.VERBOSE); + SolutionPrinter.print(vrp, solution, SolutionPrinter.Print.VERBOSE); - assertEquals(2,solution.getRoutes().iterator().next().getTourActivities().getJobs().size()); + assertEquals(2, solution.getRoutes().iterator().next().getTourActivities().getJobs().size()); } @Test - public void whenSolvingProblem2_nuJobsInSolutionShouldBe4(){ + public void whenSolvingProblem2_nuJobsInSolutionShouldBe4() { VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem_inclShipments_iniRoutes.xml"); @@ -156,17 +164,17 @@ public class InitialRoutesTest { Collection solutions = vra.searchSolutions(); VehicleRoutingProblemSolution solution = Solutions.bestOf(solutions); - SolutionPrinter.print(vrp,solution, SolutionPrinter.Print.VERBOSE); + SolutionPrinter.print(vrp, solution, SolutionPrinter.Print.VERBOSE); int jobsInSolution = 0; - for(VehicleRoute r : solution.getRoutes()){ + for (VehicleRoute r : solution.getRoutes()) { jobsInSolution += r.getTourActivities().jobSize(); } - assertEquals(4,jobsInSolution); + assertEquals(4, jobsInSolution); } @Test - public void whenSolving_nuActsShouldBe2(){ + public void whenSolving_nuActsShouldBe2() { VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem_iniRoutes.xml"); @@ -176,13 +184,13 @@ public class InitialRoutesTest { Collection solutions = vra.searchSolutions(); VehicleRoutingProblemSolution solution = Solutions.bestOf(solutions); - SolutionPrinter.print(vrp,solution, SolutionPrinter.Print.VERBOSE); + SolutionPrinter.print(vrp, solution, SolutionPrinter.Print.VERBOSE); assertEquals(2, solution.getRoutes().iterator().next().getActivities().size()); } @Test - public void whenSolvingProblem2_nuActsShouldBe6(){ + public void whenSolvingProblem2_nuActsShouldBe6() { VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem_inclShipments_iniRoutes.xml"); @@ -193,14 +201,14 @@ public class InitialRoutesTest { VehicleRoutingProblemSolution solution = Solutions.bestOf(solutions); int nuActs = 0; - for(VehicleRoute r : solution.getRoutes()){ + for (VehicleRoute r : solution.getRoutes()) { nuActs += r.getActivities().size(); } assertEquals(6, nuActs); } @Test - public void whenSolving_deliverService1_shouldBeInRoute(){ + public void whenSolving_deliverService1_shouldBeInRoute() { VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem_iniRoutes.xml"); @@ -210,23 +218,23 @@ public class InitialRoutesTest { Collection solutions = vra.searchSolutions(); VehicleRoutingProblemSolution solution = Solutions.bestOf(solutions); - SolutionPrinter.print(vrp,solution, SolutionPrinter.Print.VERBOSE); + SolutionPrinter.print(vrp, solution, SolutionPrinter.Print.VERBOSE); - Job job = getInitialJob("1",vrp); - assertTrue(hasActivityIn(solution,"veh1", job)); + Job job = getInitialJob("1", vrp); + assertTrue(hasActivityIn(solution, "veh1", job)); } private Job getInitialJob(String jobId, VehicleRoutingProblem vrp) { - for(VehicleRoute r : vrp.getInitialVehicleRoutes()){ - for(Job j : r.getTourActivities().getJobs()){ - if(j.getId().equals(jobId)) return j; + for (VehicleRoute r : vrp.getInitialVehicleRoutes()) { + for (Job j : r.getTourActivities().getJobs()) { + if (j.getId().equals(jobId)) return j; } } return null; } @Test - public void whenSolvingWithJsprit_deliverService1_shouldBeInRoute(){ + public void whenSolvingWithJsprit_deliverService1_shouldBeInRoute() { VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem_iniRoutes_3.xml"); @@ -236,14 +244,14 @@ public class InitialRoutesTest { Collection solutions = vra.searchSolutions(); VehicleRoutingProblemSolution solution = Solutions.bestOf(solutions); - SolutionPrinter.print(vrp,solution, SolutionPrinter.Print.VERBOSE); + SolutionPrinter.print(vrp, solution, SolutionPrinter.Print.VERBOSE); - Job job = getInitialJob("1",vrp); - assertTrue(hasActivityIn(solution,"veh1", job)); + Job job = getInitialJob("1", vrp); + assertTrue(hasActivityIn(solution, "veh1", job)); } @Test - public void whenSolvingProblem2With_deliverServices_and_allShipmentActs_shouldBeInRoute(){ + public void whenSolvingProblem2With_deliverServices_and_allShipmentActs_shouldBeInRoute() { VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem_inclShipments_iniRoutes.xml"); @@ -253,17 +261,17 @@ public class InitialRoutesTest { Collection solutions = vra.searchSolutions(); VehicleRoutingProblemSolution solution = Solutions.bestOf(solutions); - assertTrue(hasActivityIn(solution.getRoutes(),"1")); - assertTrue(hasActivityIn(solution.getRoutes(),"2")); - assertTrue(hasActivityIn(solution.getRoutes(),"3")); - assertTrue(hasActivityIn(solution.getRoutes(),"4")); + assertTrue(hasActivityIn(solution.getRoutes(), "1")); + assertTrue(hasActivityIn(solution.getRoutes(), "2")); + assertTrue(hasActivityIn(solution.getRoutes(), "3")); + assertTrue(hasActivityIn(solution.getRoutes(), "4")); - assertTrue(hasActivityIn(solution,"veh1", getInitialJob("1",vrp))); - assertTrue(hasActivityIn(solution,"veh2", getInitialJob("3",vrp))); + assertTrue(hasActivityIn(solution, "veh1", getInitialJob("1", vrp))); + assertTrue(hasActivityIn(solution, "veh2", getInitialJob("3", vrp))); } @Test - public void whenSolvingProblem2WithJsprit_deliverServices_and_allShipmentActs_shouldBeInRoute(){ + public void whenSolvingProblem2WithJsprit_deliverServices_and_allShipmentActs_shouldBeInRoute() { VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem_inclShipments_iniRoutes.xml"); @@ -273,18 +281,18 @@ public class InitialRoutesTest { Collection solutions = vra.searchSolutions(); VehicleRoutingProblemSolution solution = Solutions.bestOf(solutions); - assertTrue(hasActivityIn(solution.getRoutes(),"1")); - assertTrue(hasActivityIn(solution.getRoutes(),"2")); - assertTrue(hasActivityIn(solution.getRoutes(),"3")); - assertTrue(hasActivityIn(solution.getRoutes(),"4")); + assertTrue(hasActivityIn(solution.getRoutes(), "1")); + assertTrue(hasActivityIn(solution.getRoutes(), "2")); + assertTrue(hasActivityIn(solution.getRoutes(), "3")); + assertTrue(hasActivityIn(solution.getRoutes(), "4")); - assertTrue(hasActivityIn(solution,"veh1", getInitialJob("1",vrp))); - assertTrue(hasActivityIn(solution,"veh2", getInitialJob("3",vrp))); + assertTrue(hasActivityIn(solution, "veh1", getInitialJob("1", vrp))); + assertTrue(hasActivityIn(solution, "veh2", getInitialJob("3", vrp))); } private boolean hasActivityIn(Collection routes, String jobId) { boolean isInRoute = false; - for(VehicleRoute route : routes) { + for (VehicleRoute route : routes) { for (TourActivity act : route.getActivities()) { if (act instanceof TourActivity.JobActivity) { if (((TourActivity.JobActivity) act).getJob().getId().equals(jobId)) isInRoute = true; @@ -295,10 +303,10 @@ public class InitialRoutesTest { } private boolean hasActivityIn(VehicleRoutingProblemSolution solution, String vehicleId, Job job) { - for(VehicleRoute route : solution.getRoutes()){ + for (VehicleRoute route : solution.getRoutes()) { String vehicleId_ = route.getVehicle().getId(); - if(vehicleId_.equals(vehicleId)){ - if(route.getTourActivities().servesJob(job)){ + if (vehicleId_.equals(vehicleId)) { + if (route.getTourActivities().servesJob(job)) { return true; } } @@ -307,18 +315,18 @@ public class InitialRoutesTest { } - private boolean hasActivityIn(VehicleRoute route, String jobId){ + private boolean hasActivityIn(VehicleRoute route, String jobId) { boolean isInRoute = false; - for(TourActivity act : route.getActivities()){ - if(act instanceof TourActivity.JobActivity){ - if(((TourActivity.JobActivity) act).getJob().getId().equals(jobId)) isInRoute = true; + for (TourActivity act : route.getActivities()) { + if (act instanceof TourActivity.JobActivity) { + if (((TourActivity.JobActivity) act).getJob().getId().equals(jobId)) isInRoute = true; } } return isInRoute; } @Test - public void whenSolving_deliverService2_shouldBeInRoute(){ + public void whenSolving_deliverService2_shouldBeInRoute() { VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem_iniRoutes.xml"); @@ -332,29 +340,29 @@ public class InitialRoutesTest { } @Test - public void maxCapacityShouldNotBeExceeded(){ + public void maxCapacityShouldNotBeExceeded() { VehicleType type = VehicleTypeImpl.Builder.newInstance("type").addCapacityDimension(0, 100).build(); VehicleImpl vehicle = VehicleImpl.Builder.newInstance("veh") - .setStartLocation(Location.Builder.newInstance().setId("start").setCoordinate(Coordinate.newInstance(0, 0)).build()) - .setType(type) - .build(); + .setStartLocation(Location.Builder.newInstance().setId("start").setCoordinate(Coordinate.newInstance(0, 0)).build()) + .setType(type) + .build(); Shipment shipment = Shipment.Builder.newInstance("s") - .setPickupLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(10, 0)).setId("pick").build()) - .setDeliveryLocation(Location.Builder.newInstance().setId("del").setCoordinate(Coordinate.newInstance(0, 10)).build()) - .addSizeDimension(0, 100) - .build(); + .setPickupLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(10, 0)).setId("pick").build()) + .setDeliveryLocation(Location.Builder.newInstance().setId("del").setCoordinate(Coordinate.newInstance(0, 10)).build()) + .addSizeDimension(0, 100) + .build(); Shipment another_shipment = Shipment.Builder.newInstance("another_s") - .setPickupLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(10, 0)).setId("pick").build()) - .setDeliveryLocation(Location.Builder.newInstance().setId("del").setCoordinate(Coordinate.newInstance(0, 10)).build()) - .addSizeDimension(0, 50) - .build(); + .setPickupLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(10, 0)).setId("pick").build()) + .setDeliveryLocation(Location.Builder.newInstance().setId("del").setCoordinate(Coordinate.newInstance(0, 10)).build()) + .addSizeDimension(0, 50) + .build(); VehicleRoute iniRoute = VehicleRoute.Builder.newInstance(vehicle).addPickup(shipment).addDelivery(shipment).build(); VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(shipment).addVehicle(vehicle).addJob(another_shipment) - .setFleetSize(VehicleRoutingProblem.FleetSize.FINITE).addInitialVehicleRoute(iniRoute).build(); + .setFleetSize(VehicleRoutingProblem.FleetSize.FINITE).addInitialVehicleRoute(iniRoute).build(); VehicleRoutingAlgorithm vra = new GreedySchrimpfFactory().createAlgorithm(vrp); vra.setMaxIterations(10); @@ -366,7 +374,7 @@ public class InitialRoutesTest { } @Test - public void whenReadingProblemFromFile_maxCapacityShouldNotBeExceeded(){ + public void whenReadingProblemFromFile_maxCapacityShouldNotBeExceeded() { VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem_iniRoutes_2.xml"); VehicleRoutingAlgorithm vra = new GreedySchrimpfFactory().createAlgorithm(vrpBuilder.build()); @@ -383,4 +391,49 @@ public class InitialRoutesTest { TourActivity secondAct = solution.getRoutes().iterator().next().getActivities().get(1); return secondAct instanceof PickupShipment; } + + @Test + public void whenAllJobsInInitialRoute_itShouldWork() { + Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance(0, 10)).build(); + VehicleImpl v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0, 0)).build(); + VehicleRoute iniRoute = VehicleRoute.Builder.newInstance(v).addService(s).build(); + VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addInitialVehicleRoute(iniRoute).build(); + VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp); + vra.setMaxIterations(100); + vra.searchSolutions(); + assertTrue(true); + } + + @Test + public void buildWithoutTimeConstraints() { + Service s1 = Service.Builder.newInstance("s1").setLocation(Location.newInstance(0, 10)).addSizeDimension(0, 10).build(); + Service s2 = Service.Builder.newInstance("s2").setLocation(Location.newInstance(10, 20)).addSizeDimension(0, 12).build(); + + VehicleTypeImpl vt = VehicleTypeImpl.Builder.newInstance("vt").addCapacityDimension(0, 15).build(); + VehicleImpl v = VehicleImpl.Builder.newInstance("v").setType(vt).setStartLocation(Location.newInstance(0, 0)).build(); + + VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(s1).addJob(s2).addVehicle(v).build(); + Builder algBuilder = Jsprit.Builder.newInstance(vrp).addCoreStateAndConstraintStuff(false); + + // only required constraints + StateManager stateManager = new StateManager(vrp); + ConstraintManager constraintManager = new ConstraintManager(vrp, stateManager); + constraintManager.addConstraint(new ServiceLoadRouteLevelConstraint(stateManager)); + constraintManager.addConstraint(new ServiceLoadActivityLevelConstraint(stateManager), Priority.LOW); + stateManager.updateLoadStates(); + stateManager.addStateUpdater(new UpdateEndLocationIfRouteIsOpen()); + stateManager.addStateUpdater(new UpdateVariableCosts(vrp.getActivityCosts(), vrp.getTransportCosts(), stateManager)); + + algBuilder.setStateAndConstraintManager(stateManager, constraintManager); + VehicleRoutingAlgorithm vra = algBuilder.buildAlgorithm(); + vra.setMaxIterations(20); + Collection searchSolutions = vra.searchSolutions(); + VehicleRoutingProblemSolution bestOf = Solutions.bestOf(searchSolutions); + + //ensure 2 routes + assertEquals(2, bestOf.getRoutes().size()); + + //ensure no time information in first service of first route + assertEquals(0, bestOf.getRoutes().iterator().next().getActivities().iterator().next().getArrTime(), 0.001); + } } diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/MeetTimeWindowConstraint_IT.java b/jsprit-core/src/test/java/jsprit/core/algorithm/MeetTimeWindowConstraint_IT.java index aa3ec6b4..4160b166 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/MeetTimeWindowConstraint_IT.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/MeetTimeWindowConstraint_IT.java @@ -1,23 +1,24 @@ /******************************************************************************* * Copyright (c) 2014 Stefan Schroeder. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . - * + * * Contributors: * Stefan Schroeder - initial API and implementation ******************************************************************************/ package jsprit.core.algorithm; +import jsprit.core.algorithm.box.GreedySchrimpfFactory; import jsprit.core.algorithm.box.Jsprit; import jsprit.core.algorithm.box.SchrimpfFactory; import jsprit.core.algorithm.io.VehicleRoutingAlgorithms; @@ -29,9 +30,14 @@ import jsprit.core.problem.job.Job; import jsprit.core.problem.solution.VehicleRoutingProblemSolution; import jsprit.core.problem.solution.route.VehicleRoute; import jsprit.core.problem.vehicle.Vehicle; +import jsprit.core.util.FastVehicleRoutingTransportCostsMatrix; import jsprit.core.util.Solutions; import org.junit.Test; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -40,544 +46,589 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; public class MeetTimeWindowConstraint_IT { - - @Test - public void whenEmployingVehicleWithDifferentWorkingShifts_nRoutesShouldBeCorrect(){ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml"); - VehicleRoutingProblem vrp = vrpBuilder.build(); - - VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp); - vra.setMaxIterations(100); - Collection solutions = vra.searchSolutions(); - - assertEquals(2,Solutions.bestOf(solutions).getRoutes().size()); - } - - @Test - public void whenEmployingVehicleWithDifferentWorkingShifts_certainJobsCanNeverBeAssignedToCertainVehicles(){ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml"); - VehicleRoutingProblem vrp = vrpBuilder.build(); - - VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp); - vra.setMaxIterations(100); - final List testFailed = new ArrayList(); - vra.addListener(new JobInsertedListener() { - - @Override - public void informJobInserted(Job job2insert, VehicleRoute inRoute, double additionalCosts, double additionalTime) { - if(job2insert.getId().equals("1")){ - if(inRoute.getVehicle().getId().equals("19")){ - testFailed.add(true); - } - } - if(job2insert.getId().equals("2")){ - if(inRoute.getVehicle().getId().equals("21")){ - testFailed.add(true); - } - } - } - - }); - @SuppressWarnings("unused") - Collection solutions = vra.searchSolutions(); - - assertTrue(testFailed.isEmpty()); - } - - @Test - public void whenEmployingVehicleWithDifferentWorkingShifts_certainVehiclesCanNeverBeAssignedToCertainRoutes(){ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml"); - VehicleRoutingProblem vrp = vrpBuilder.build(); - - VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp); - vra.setMaxIterations(100); - final List testFailed = new ArrayList(); - vra.addListener(new VehicleSwitchedListener() { - - @Override - public void vehicleSwitched(VehicleRoute vehicleRoute, Vehicle oldVehicle, Vehicle newVehicle) { - if(oldVehicle==null) return; - if(oldVehicle.getId().equals("21") && newVehicle.getId().equals("19")){ - for(Job j : vehicleRoute.getTourActivities().getJobs()){ - if(j.getId().equals("1")){ - testFailed.add(true); - } - } - } - if(oldVehicle.getId().equals("19") && newVehicle.getId().equals("21")){ - for(Job j : vehicleRoute.getTourActivities().getJobs()){ - if(j.getId().equals("2")){ - testFailed.add(true); - } - } - } - } - - }); - - - @SuppressWarnings("unused") - Collection solutions = vra.searchSolutions(); - System.out.println("failed " + testFailed.size()); - assertTrue(testFailed.isEmpty()); - } - - @Test - public void whenEmployingVehicleWithDifferentWorkingShifts_job2CanNeverBeInVehicle21(){ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml"); - VehicleRoutingProblem vrp = vrpBuilder.build(); - - VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp); - vra.setMaxIterations(100); - Collection solutions = vra.searchSolutions(); - - assertEquals(2,Solutions.bestOf(solutions).getRoutes().size()); - } - - @Test - public void whenEmployingVehicleWithDifferentWorkingShifts_job1ShouldBeAssignedCorrectly(){ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml"); - VehicleRoutingProblem vrp = vrpBuilder.build(); - - VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp); - vra.setMaxIterations(100); - Collection solutions = vra.searchSolutions(); - -// assertEquals(2,Solutions.bestOf(solutions).getRoutes().size()); - assertTrue(containsJob(vrp.getJobs().get("1"),getRoute("21",Solutions.bestOf(solutions)))); - } - - @Test - public void whenEmployingVehicleWithDifferentWorkingShifts_job2ShouldBeAssignedCorrectly(){ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml"); - VehicleRoutingProblem vrp = vrpBuilder.build(); - - VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp); - vra.setMaxIterations(100); - Collection solutions = vra.searchSolutions(); - -// assertEquals(2,Solutions.bestOf(solutions).getRoutes().size()); - assertTrue(containsJob(vrp.getJobs().get("2"),getRoute("19",Solutions.bestOf(solutions)))); - } - - - - - @Test - public void whenEmployingVehicleWithDifferentWorkingShifts_and_vehicleSwitchIsNotAllowed_nRoutesShouldBeCorrect(){ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml"); - VehicleRoutingProblem vrp = vrpBuilder.build(); - - VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/schrimpf_vehicleSwitchNotAllowed.xml"); - vra.setMaxIterations(100); - Collection solutions = vra.searchSolutions(); - - assertEquals(2,Solutions.bestOf(solutions).getRoutes().size()); - } - - @Test - public void whenEmployingVehicleWithDifferentWorkingShifts_and_vehicleSwitchIsNotAllowed_certainJobsCanNeverBeAssignedToCertainVehicles(){ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml"); - VehicleRoutingProblem vrp = vrpBuilder.build(); - - VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/schrimpf_vehicleSwitchNotAllowed.xml"); - vra.setMaxIterations(100); - final List testFailed = new ArrayList(); - vra.addListener(new JobInsertedListener() { - - @Override - public void informJobInserted(Job job2insert, VehicleRoute inRoute, double additionalCosts, double additionalTime) { - if(job2insert.getId().equals("1")){ - if(inRoute.getVehicle().getId().equals("19")){ - testFailed.add(true); - } - } - if(job2insert.getId().equals("2")){ - if(inRoute.getVehicle().getId().equals("21")){ - testFailed.add(true); - } - } - } - - }); - @SuppressWarnings("unused") - Collection solutions = vra.searchSolutions(); - - assertTrue(testFailed.isEmpty()); - } - - @Test - public void whenEmployingVehicleWithDifferentWorkingShifts_and_vehicleSwitchIsNotAllowed_certainVehiclesCanNeverBeAssignedToCertainRoutes(){ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml"); - VehicleRoutingProblem vrp = vrpBuilder.build(); - - VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/schrimpf_vehicleSwitchNotAllowed.xml"); - vra.setMaxIterations(100); - final List testFailed = new ArrayList(); - vra.addListener(new VehicleSwitchedListener() { - - @Override - public void vehicleSwitched(VehicleRoute vehicleRoute, Vehicle oldVehicle, Vehicle newVehicle) { - if(oldVehicle==null) return; - if(oldVehicle.getId().equals("21") && newVehicle.getId().equals("19")){ - for(Job j : vehicleRoute.getTourActivities().getJobs()){ - if(j.getId().equals("1")){ - testFailed.add(true); - } - } - } - if(oldVehicle.getId().equals("19") && newVehicle.getId().equals("21")){ - for(Job j : vehicleRoute.getTourActivities().getJobs()){ - if(j.getId().equals("2")){ - testFailed.add(true); - } - } - } - } - - }); - - - @SuppressWarnings("unused") - Collection solutions = vra.searchSolutions(); - System.out.println("failed " + testFailed.size()); - assertTrue(testFailed.isEmpty()); - } - - @Test - public void whenEmployingVehicleWithDifferentWorkingShifts_and_vehicleSwitchIsNotAllowed_job2CanNeverBeInVehicle21(){ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml"); - VehicleRoutingProblem vrp = vrpBuilder.build(); - - VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/schrimpf_vehicleSwitchNotAllowed.xml"); - vra.setMaxIterations(100); - Collection solutions = vra.searchSolutions(); - - assertEquals(2,Solutions.bestOf(solutions).getRoutes().size()); - } - - @Test - public void whenEmployingVehicleWithDifferentWorkingShifts_and_vehicleSwitchIsNotAllowed_job1ShouldBeAssignedCorrectly(){ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml"); - VehicleRoutingProblem vrp = vrpBuilder.build(); - - VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/schrimpf_vehicleSwitchNotAllowed.xml"); - vra.setMaxIterations(100); - Collection solutions = vra.searchSolutions(); - - assertEquals(2,Solutions.bestOf(solutions).getRoutes().size()); - assertTrue(containsJob(vrp.getJobs().get("1"),getRoute("21",Solutions.bestOf(solutions)))); - } - - @Test - public void whenEmployingVehicleWithDifferentWorkingShifts_and_vehicleSwitchIsNotAllowed_job2ShouldBeAssignedCorrectly(){ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml"); - VehicleRoutingProblem vrp = vrpBuilder.build(); - - VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/schrimpf_vehicleSwitchNotAllowed.xml"); - vra.setMaxIterations(100); - Collection solutions = vra.searchSolutions(); - - assertEquals(2,Solutions.bestOf(solutions).getRoutes().size()); - assertTrue(containsJob(vrp.getJobs().get("2"),getRoute("19",Solutions.bestOf(solutions)))); - } + + @Test + public void whenEmployingVehicleWithDifferentWorkingShifts_nRoutesShouldBeCorrect() { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml"); + VehicleRoutingProblem vrp = vrpBuilder.build(); + + VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp); + vra.setMaxIterations(100); + Collection solutions = vra.searchSolutions(); + + assertEquals(2, Solutions.bestOf(solutions).getRoutes().size()); + } + + @Test + public void whenEmployingVehicleWithDifferentWorkingShifts_certainJobsCanNeverBeAssignedToCertainVehicles() { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml"); + VehicleRoutingProblem vrp = vrpBuilder.build(); + + VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp); + vra.setMaxIterations(100); + final List testFailed = new ArrayList(); + vra.addListener(new JobInsertedListener() { + + @Override + public void informJobInserted(Job job2insert, VehicleRoute inRoute, double additionalCosts, double additionalTime) { + if (job2insert.getId().equals("1")) { + if (inRoute.getVehicle().getId().equals("19")) { + testFailed.add(true); + } + } + if (job2insert.getId().equals("2")) { + if (inRoute.getVehicle().getId().equals("21")) { + testFailed.add(true); + } + } + } + + }); + @SuppressWarnings("unused") + Collection solutions = vra.searchSolutions(); + + assertTrue(testFailed.isEmpty()); + } + + @Test + public void whenEmployingVehicleWithDifferentWorkingShifts_certainVehiclesCanNeverBeAssignedToCertainRoutes() { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml"); + VehicleRoutingProblem vrp = vrpBuilder.build(); + + VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp); + vra.setMaxIterations(100); + final List testFailed = new ArrayList(); + vra.addListener(new VehicleSwitchedListener() { + + @Override + public void vehicleSwitched(VehicleRoute vehicleRoute, Vehicle oldVehicle, Vehicle newVehicle) { + if (oldVehicle == null) return; + if (oldVehicle.getId().equals("21") && newVehicle.getId().equals("19")) { + for (Job j : vehicleRoute.getTourActivities().getJobs()) { + if (j.getId().equals("1")) { + testFailed.add(true); + } + } + } + if (oldVehicle.getId().equals("19") && newVehicle.getId().equals("21")) { + for (Job j : vehicleRoute.getTourActivities().getJobs()) { + if (j.getId().equals("2")) { + testFailed.add(true); + } + } + } + } + + }); + @SuppressWarnings("unused") + Collection solutions = vra.searchSolutions(); + System.out.println("failed " + testFailed.size()); + assertTrue(testFailed.isEmpty()); + } + @Test + public void whenEmployingVehicleWithDifferentWorkingShifts_job2CanNeverBeInVehicle21() { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml"); + VehicleRoutingProblem vrp = vrpBuilder.build(); + VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp); + vra.setMaxIterations(100); + Collection solutions = vra.searchSolutions(); + assertEquals(2, Solutions.bestOf(solutions).getRoutes().size()); + } + @Test + public void whenEmployingVehicleWithDifferentWorkingShifts_job1ShouldBeAssignedCorrectly() { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml"); + VehicleRoutingProblem vrp = vrpBuilder.build(); - - - - - @Test - public void whenEmployingVehicleWithDifferentWorkingShifts_jsprit_nRoutesShouldBeCorrect(){ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml"); - VehicleRoutingProblem vrp = vrpBuilder.build(); - - VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp); - vra.setMaxIterations(100); - Collection solutions = vra.searchSolutions(); - - assertEquals(2,Solutions.bestOf(solutions).getRoutes().size()); - } - - @Test - public void whenEmployingVehicleWithDifferentWorkingShifts_jsprit_certainJobsCanNeverBeAssignedToCertainVehicles(){ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml"); - VehicleRoutingProblem vrp = vrpBuilder.build(); - - VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp); - vra.setMaxIterations(100); - final List testFailed = new ArrayList(); - vra.addListener(new JobInsertedListener() { - - @Override - public void informJobInserted(Job job2insert, VehicleRoute inRoute, double additionalCosts, double additionalTime) { - if(job2insert.getId().equals("1")){ - if(inRoute.getVehicle().getId().equals("19")){ - testFailed.add(true); - } - } - if(job2insert.getId().equals("2")){ - if(inRoute.getVehicle().getId().equals("21")){ - testFailed.add(true); - } - } - } - - }); - @SuppressWarnings("unused") - Collection solutions = vra.searchSolutions(); - - assertTrue(testFailed.isEmpty()); - } - - @Test - public void whenEmployingVehicleWithDifferentWorkingShifts_jsprit_certainVehiclesCanNeverBeAssignedToCertainRoutes(){ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml"); - VehicleRoutingProblem vrp = vrpBuilder.build(); - - VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp); - vra.setMaxIterations(100); - final List testFailed = new ArrayList(); - vra.addListener(new VehicleSwitchedListener() { - - @Override - public void vehicleSwitched(VehicleRoute vehicleRoute, Vehicle oldVehicle, Vehicle newVehicle) { - if(oldVehicle==null) return; - if(oldVehicle.getId().equals("21") && newVehicle.getId().equals("19")){ - for(Job j : vehicleRoute.getTourActivities().getJobs()){ - if(j.getId().equals("1")){ - testFailed.add(true); - } - } - } - if(oldVehicle.getId().equals("19") && newVehicle.getId().equals("21")){ - for(Job j : vehicleRoute.getTourActivities().getJobs()){ - if(j.getId().equals("2")){ - testFailed.add(true); - } - } - } - } - - }); - - - @SuppressWarnings("unused") - Collection solutions = vra.searchSolutions(); - System.out.println("failed " + testFailed.size()); - assertTrue(testFailed.isEmpty()); - } - - @Test - public void whenEmployingVehicleWithDifferentWorkingShifts_jsprit_job2CanNeverBeInVehicle21(){ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml"); - VehicleRoutingProblem vrp = vrpBuilder.build(); - - VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp); - vra.setMaxIterations(100); - Collection solutions = vra.searchSolutions(); - - assertEquals(2,Solutions.bestOf(solutions).getRoutes().size()); - } - - @Test - public void whenEmployingVehicleWithDifferentWorkingShifts_jsprit_job1ShouldBeAssignedCorrectly(){ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml"); - VehicleRoutingProblem vrp = vrpBuilder.build(); - - VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp); - vra.setMaxIterations(100); - Collection solutions = vra.searchSolutions(); + VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp); + vra.setMaxIterations(100); + Collection solutions = vra.searchSolutions(); // assertEquals(2,Solutions.bestOf(solutions).getRoutes().size()); - assertTrue(containsJob(vrp.getJobs().get("1"),getRoute("21",Solutions.bestOf(solutions)))); - } + assertTrue(containsJob(vrp.getJobs().get("1"), getRoute("21", Solutions.bestOf(solutions)))); + } - @Test - public void whenEmployingVehicleWithDifferentWorkingShifts_jsprit_job2ShouldBeAssignedCorrectly(){ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml"); - VehicleRoutingProblem vrp = vrpBuilder.build(); + @Test + public void whenEmployingVehicleWithDifferentWorkingShifts_job2ShouldBeAssignedCorrectly() { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml"); + VehicleRoutingProblem vrp = vrpBuilder.build(); - VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp); - vra.setMaxIterations(100); - Collection solutions = vra.searchSolutions(); + VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp); + vra.setMaxIterations(100); + Collection solutions = vra.searchSolutions(); // assertEquals(2,Solutions.bestOf(solutions).getRoutes().size()); - assertTrue(containsJob(vrp.getJobs().get("2"),getRoute("19",Solutions.bestOf(solutions)))); - } + assertTrue(containsJob(vrp.getJobs().get("2"), getRoute("19", Solutions.bestOf(solutions)))); + } + @Test + public void whenEmployingVehicleWithDifferentWorkingShifts_and_vehicleSwitchIsNotAllowed_nRoutesShouldBeCorrect() { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml"); + VehicleRoutingProblem vrp = vrpBuilder.build(); + + VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/schrimpf_vehicleSwitchNotAllowed.xml"); + vra.setMaxIterations(100); + Collection solutions = vra.searchSolutions(); + + assertEquals(2, Solutions.bestOf(solutions).getRoutes().size()); + } + + @Test + public void whenEmployingVehicleWithDifferentWorkingShifts_and_vehicleSwitchIsNotAllowed_certainJobsCanNeverBeAssignedToCertainVehicles() { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml"); + VehicleRoutingProblem vrp = vrpBuilder.build(); + + VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/schrimpf_vehicleSwitchNotAllowed.xml"); + vra.setMaxIterations(100); + final List testFailed = new ArrayList(); + vra.addListener(new JobInsertedListener() { + + @Override + public void informJobInserted(Job job2insert, VehicleRoute inRoute, double additionalCosts, double additionalTime) { + if (job2insert.getId().equals("1")) { + if (inRoute.getVehicle().getId().equals("19")) { + testFailed.add(true); + } + } + if (job2insert.getId().equals("2")) { + if (inRoute.getVehicle().getId().equals("21")) { + testFailed.add(true); + } + } + } + + }); + @SuppressWarnings("unused") + Collection solutions = vra.searchSolutions(); + + assertTrue(testFailed.isEmpty()); + } + + @Test + public void whenEmployingVehicleWithDifferentWorkingShifts_and_vehicleSwitchIsNotAllowed_certainVehiclesCanNeverBeAssignedToCertainRoutes() { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml"); + VehicleRoutingProblem vrp = vrpBuilder.build(); + + VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/schrimpf_vehicleSwitchNotAllowed.xml"); + vra.setMaxIterations(100); + final List testFailed = new ArrayList(); + vra.addListener(new VehicleSwitchedListener() { + + @Override + public void vehicleSwitched(VehicleRoute vehicleRoute, Vehicle oldVehicle, Vehicle newVehicle) { + if (oldVehicle == null) return; + if (oldVehicle.getId().equals("21") && newVehicle.getId().equals("19")) { + for (Job j : vehicleRoute.getTourActivities().getJobs()) { + if (j.getId().equals("1")) { + testFailed.add(true); + } + } + } + if (oldVehicle.getId().equals("19") && newVehicle.getId().equals("21")) { + for (Job j : vehicleRoute.getTourActivities().getJobs()) { + if (j.getId().equals("2")) { + testFailed.add(true); + } + } + } + } + + }); - @Test - public void whenEmployingVehicleWithDifferentWorkingShifts_jsprit_and_vehicleSwitchIsNotAllowed_nRoutesShouldBeCorrect(){ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml"); - VehicleRoutingProblem vrp = vrpBuilder.build(); + @SuppressWarnings("unused") + Collection solutions = vra.searchSolutions(); + System.out.println("failed " + testFailed.size()); + assertTrue(testFailed.isEmpty()); + } - VehicleRoutingAlgorithm vra = Jsprit.Builder.newInstance(vrp).setProperty(Jsprit.Parameter.VEHICLE_SWITCH, "false").buildAlgorithm(); - vra.setMaxIterations(100); - Collection solutions = vra.searchSolutions(); + @Test + public void whenEmployingVehicleWithDifferentWorkingShifts_and_vehicleSwitchIsNotAllowed_job2CanNeverBeInVehicle21() { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml"); + VehicleRoutingProblem vrp = vrpBuilder.build(); - assertEquals(2,Solutions.bestOf(solutions).getRoutes().size()); - } + VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/schrimpf_vehicleSwitchNotAllowed.xml"); + vra.setMaxIterations(100); + Collection solutions = vra.searchSolutions(); - @Test - public void whenEmployingVehicleWithDifferentWorkingShifts_and_vehicleSwitchIsNotAllowed_jsprit_certainJobsCanNeverBeAssignedToCertainVehicles(){ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml"); - VehicleRoutingProblem vrp = vrpBuilder.build(); + assertEquals(2, Solutions.bestOf(solutions).getRoutes().size()); + } - VehicleRoutingAlgorithm vra = Jsprit.Builder.newInstance(vrp).setProperty(Jsprit.Parameter.VEHICLE_SWITCH,"false").buildAlgorithm(); - vra.setMaxIterations(100); - final List testFailed = new ArrayList(); - vra.addListener(new JobInsertedListener() { + @Test + public void whenEmployingVehicleWithDifferentWorkingShifts_and_vehicleSwitchIsNotAllowed_job1ShouldBeAssignedCorrectly() { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml"); + VehicleRoutingProblem vrp = vrpBuilder.build(); - @Override - public void informJobInserted(Job job2insert, VehicleRoute inRoute, double additionalCosts, double additionalTime) { - if(job2insert.getId().equals("1")){ - if(inRoute.getVehicle().getId().equals("19")){ - testFailed.add(true); - } - } - if(job2insert.getId().equals("2")){ - if(inRoute.getVehicle().getId().equals("21")){ - testFailed.add(true); - } - } - } + VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/schrimpf_vehicleSwitchNotAllowed.xml"); + vra.setMaxIterations(100); + Collection solutions = vra.searchSolutions(); - }); - @SuppressWarnings("unused") - Collection solutions = vra.searchSolutions(); + assertEquals(2, Solutions.bestOf(solutions).getRoutes().size()); + assertTrue(containsJob(vrp.getJobs().get("1"), getRoute("21", Solutions.bestOf(solutions)))); + } - assertTrue(testFailed.isEmpty()); - } + @Test + public void whenEmployingVehicleWithDifferentWorkingShifts_and_vehicleSwitchIsNotAllowed_job2ShouldBeAssignedCorrectly() { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml"); + VehicleRoutingProblem vrp = vrpBuilder.build(); - @Test - public void whenEmployingVehicleWithDifferentWorkingShifts_and_vehicleSwitchIsNotAllowed_jsprit_certainVehiclesCanNeverBeAssignedToCertainRoutes(){ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml"); - VehicleRoutingProblem vrp = vrpBuilder.build(); + VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/schrimpf_vehicleSwitchNotAllowed.xml"); + vra.setMaxIterations(100); + Collection solutions = vra.searchSolutions(); - VehicleRoutingAlgorithm vra = Jsprit.Builder.newInstance(vrp).setProperty(Jsprit.Parameter.VEHICLE_SWITCH,"false").buildAlgorithm(); - vra.setMaxIterations(100); - final List testFailed = new ArrayList(); - vra.addListener(new VehicleSwitchedListener() { - - @Override - public void vehicleSwitched(VehicleRoute vehicleRoute, Vehicle oldVehicle, Vehicle newVehicle) { - if(oldVehicle==null) return; - if(oldVehicle.getId().equals("21") && newVehicle.getId().equals("19")){ - for(Job j : vehicleRoute.getTourActivities().getJobs()){ - if(j.getId().equals("1")){ - testFailed.add(true); - } - } - } - if(oldVehicle.getId().equals("19") && newVehicle.getId().equals("21")){ - for(Job j : vehicleRoute.getTourActivities().getJobs()){ - if(j.getId().equals("2")){ - testFailed.add(true); - } - } - } - } - - }); + assertEquals(2, Solutions.bestOf(solutions).getRoutes().size()); + assertTrue(containsJob(vrp.getJobs().get("2"), getRoute("19", Solutions.bestOf(solutions)))); + } - @SuppressWarnings("unused") - Collection solutions = vra.searchSolutions(); - System.out.println("failed " + testFailed.size()); - assertTrue(testFailed.isEmpty()); - } + @Test + public void whenEmployingVehicleWithDifferentWorkingShifts_jsprit_nRoutesShouldBeCorrect() { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml"); + VehicleRoutingProblem vrp = vrpBuilder.build(); - @Test - public void whenEmployingVehicleWithDifferentWorkingShifts_and_vehicleSwitchIsNotAllowed_jsprit_job2CanNeverBeInVehicle21(){ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml"); - VehicleRoutingProblem vrp = vrpBuilder.build(); + VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp); + vra.setMaxIterations(100); + Collection solutions = vra.searchSolutions(); - VehicleRoutingAlgorithm vra = Jsprit.Builder.newInstance(vrp).setProperty(Jsprit.Parameter.VEHICLE_SWITCH,"false").buildAlgorithm(); - vra.setMaxIterations(100); - Collection solutions = vra.searchSolutions(); + assertEquals(2, Solutions.bestOf(solutions).getRoutes().size()); + } - assertEquals(2,Solutions.bestOf(solutions).getRoutes().size()); - } + @Test + public void whenEmployingVehicleWithDifferentWorkingShifts_jsprit_certainJobsCanNeverBeAssignedToCertainVehicles() { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml"); + VehicleRoutingProblem vrp = vrpBuilder.build(); - @Test - public void whenEmployingVehicleWithDifferentWorkingShifts_and_vehicleSwitchIsNotAllowed_jsprit_job1ShouldBeAssignedCorrectly(){ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml"); - VehicleRoutingProblem vrp = vrpBuilder.build(); + VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp); + vra.setMaxIterations(100); + final List testFailed = new ArrayList(); + vra.addListener(new JobInsertedListener() { - VehicleRoutingAlgorithm vra = Jsprit.Builder.newInstance(vrp).setProperty(Jsprit.Parameter.VEHICLE_SWITCH,"false").buildAlgorithm(); - vra.setMaxIterations(100); - Collection solutions = vra.searchSolutions(); + @Override + public void informJobInserted(Job job2insert, VehicleRoute inRoute, double additionalCosts, double additionalTime) { + if (job2insert.getId().equals("1")) { + if (inRoute.getVehicle().getId().equals("19")) { + testFailed.add(true); + } + } + if (job2insert.getId().equals("2")) { + if (inRoute.getVehicle().getId().equals("21")) { + testFailed.add(true); + } + } + } - assertEquals(2,Solutions.bestOf(solutions).getRoutes().size()); - assertTrue(containsJob(vrp.getJobs().get("1"),getRoute("21",Solutions.bestOf(solutions)))); - } + }); + @SuppressWarnings("unused") + Collection solutions = vra.searchSolutions(); - @Test - public void whenEmployingVehicleWithDifferentWorkingShifts_and_vehicleSwitchIsNotAllowed_jsprit_job2ShouldBeAssignedCorrectly(){ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml"); - VehicleRoutingProblem vrp = vrpBuilder.build(); + assertTrue(testFailed.isEmpty()); + } - VehicleRoutingAlgorithm vra = Jsprit.Builder.newInstance(vrp).setProperty(Jsprit.Parameter.VEHICLE_SWITCH,"false").buildAlgorithm(); - vra.setMaxIterations(100); - Collection solutions = vra.searchSolutions(); + @Test + public void whenEmployingVehicleWithDifferentWorkingShifts_jsprit_certainVehiclesCanNeverBeAssignedToCertainRoutes() { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml"); + VehicleRoutingProblem vrp = vrpBuilder.build(); - assertEquals(2,Solutions.bestOf(solutions).getRoutes().size()); - assertTrue(containsJob(vrp.getJobs().get("2"),getRoute("19",Solutions.bestOf(solutions)))); - } + VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp); + vra.setMaxIterations(100); + final List testFailed = new ArrayList(); + vra.addListener(new VehicleSwitchedListener() { + + @Override + public void vehicleSwitched(VehicleRoute vehicleRoute, Vehicle oldVehicle, Vehicle newVehicle) { + if (oldVehicle == null) return; + if (oldVehicle.getId().equals("21") && newVehicle.getId().equals("19")) { + for (Job j : vehicleRoute.getTourActivities().getJobs()) { + if (j.getId().equals("1")) { + testFailed.add(true); + } + } + } + if (oldVehicle.getId().equals("19") && newVehicle.getId().equals("21")) { + for (Job j : vehicleRoute.getTourActivities().getJobs()) { + if (j.getId().equals("2")) { + testFailed.add(true); + } + } + } + } + + }); + @SuppressWarnings("unused") + Collection solutions = vra.searchSolutions(); + System.out.println("failed " + testFailed.size()); + assertTrue(testFailed.isEmpty()); + } + + @Test + public void whenEmployingVehicleWithDifferentWorkingShifts_jsprit_job2CanNeverBeInVehicle21() { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml"); + VehicleRoutingProblem vrp = vrpBuilder.build(); + + VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp); + vra.setMaxIterations(100); + Collection solutions = vra.searchSolutions(); + + assertEquals(2, Solutions.bestOf(solutions).getRoutes().size()); + } + + @Test + public void whenEmployingVehicleWithDifferentWorkingShifts_jsprit_job1ShouldBeAssignedCorrectly() { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml"); + VehicleRoutingProblem vrp = vrpBuilder.build(); + + VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp); + vra.setMaxIterations(100); + Collection solutions = vra.searchSolutions(); + +// assertEquals(2,Solutions.bestOf(solutions).getRoutes().size()); + assertTrue(containsJob(vrp.getJobs().get("1"), getRoute("21", Solutions.bestOf(solutions)))); + } + + @Test + public void whenEmployingVehicleWithDifferentWorkingShifts_jsprit_job2ShouldBeAssignedCorrectly() { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml"); + VehicleRoutingProblem vrp = vrpBuilder.build(); + + VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp); + vra.setMaxIterations(100); + Collection solutions = vra.searchSolutions(); + +// assertEquals(2,Solutions.bestOf(solutions).getRoutes().size()); + assertTrue(containsJob(vrp.getJobs().get("2"), getRoute("19", Solutions.bestOf(solutions)))); + } + @Test + public void whenEmployingVehicleWithDifferentWorkingShifts_jsprit_and_vehicleSwitchIsNotAllowed_nRoutesShouldBeCorrect() { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml"); + VehicleRoutingProblem vrp = vrpBuilder.build(); - private boolean containsJob(Job job, VehicleRoute route) { - if(route == null) return false; - for(Job j : route.getTourActivities().getJobs()){ - if(job == j){ - return true; - } - } - return false; - } + VehicleRoutingAlgorithm vra = Jsprit.Builder.newInstance(vrp).setProperty(Jsprit.Parameter.VEHICLE_SWITCH, "false").buildAlgorithm(); + vra.setMaxIterations(100); + Collection solutions = vra.searchSolutions(); - private VehicleRoute getRoute(String vehicleId, VehicleRoutingProblemSolution vehicleRoutingProblemSolution) { - for(VehicleRoute r : vehicleRoutingProblemSolution.getRoutes()){ - if(r.getVehicle().getId().equals(vehicleId)){ - return r; - } - } - return null; - } + assertEquals(2, Solutions.bestOf(solutions).getRoutes().size()); + } + + @Test + public void whenEmployingVehicleWithDifferentWorkingShifts_and_vehicleSwitchIsNotAllowed_jsprit_certainJobsCanNeverBeAssignedToCertainVehicles() { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml"); + VehicleRoutingProblem vrp = vrpBuilder.build(); + + VehicleRoutingAlgorithm vra = Jsprit.Builder.newInstance(vrp).setProperty(Jsprit.Parameter.VEHICLE_SWITCH, "false").buildAlgorithm(); + vra.setMaxIterations(100); + final List testFailed = new ArrayList(); + vra.addListener(new JobInsertedListener() { + + @Override + public void informJobInserted(Job job2insert, VehicleRoute inRoute, double additionalCosts, double additionalTime) { + if (job2insert.getId().equals("1")) { + if (inRoute.getVehicle().getId().equals("19")) { + testFailed.add(true); + } + } + if (job2insert.getId().equals("2")) { + if (inRoute.getVehicle().getId().equals("21")) { + testFailed.add(true); + } + } + } + + }); + @SuppressWarnings("unused") + Collection solutions = vra.searchSolutions(); + + assertTrue(testFailed.isEmpty()); + } + + @Test + public void whenEmployingVehicleWithDifferentWorkingShifts_and_vehicleSwitchIsNotAllowed_jsprit_certainVehiclesCanNeverBeAssignedToCertainRoutes() { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml"); + VehicleRoutingProblem vrp = vrpBuilder.build(); + + VehicleRoutingAlgorithm vra = Jsprit.Builder.newInstance(vrp).setProperty(Jsprit.Parameter.VEHICLE_SWITCH, "false").buildAlgorithm(); + vra.setMaxIterations(100); + final List testFailed = new ArrayList(); + vra.addListener(new VehicleSwitchedListener() { + + @Override + public void vehicleSwitched(VehicleRoute vehicleRoute, Vehicle oldVehicle, Vehicle newVehicle) { + if (oldVehicle == null) return; + if (oldVehicle.getId().equals("21") && newVehicle.getId().equals("19")) { + for (Job j : vehicleRoute.getTourActivities().getJobs()) { + if (j.getId().equals("1")) { + testFailed.add(true); + } + } + } + if (oldVehicle.getId().equals("19") && newVehicle.getId().equals("21")) { + for (Job j : vehicleRoute.getTourActivities().getJobs()) { + if (j.getId().equals("2")) { + testFailed.add(true); + } + } + } + } + + }); + + + @SuppressWarnings("unused") + Collection solutions = vra.searchSolutions(); + System.out.println("failed " + testFailed.size()); + assertTrue(testFailed.isEmpty()); + } + + @Test + public void whenEmployingVehicleWithDifferentWorkingShifts_and_vehicleSwitchIsNotAllowed_jsprit_job2CanNeverBeInVehicle21() { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml"); + VehicleRoutingProblem vrp = vrpBuilder.build(); + + VehicleRoutingAlgorithm vra = Jsprit.Builder.newInstance(vrp).setProperty(Jsprit.Parameter.VEHICLE_SWITCH, "false").buildAlgorithm(); + vra.setMaxIterations(100); + Collection solutions = vra.searchSolutions(); + + assertEquals(2, Solutions.bestOf(solutions).getRoutes().size()); + } + + @Test + public void whenEmployingVehicleWithDifferentWorkingShifts_and_vehicleSwitchIsNotAllowed_jsprit_job1ShouldBeAssignedCorrectly() { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml"); + VehicleRoutingProblem vrp = vrpBuilder.build(); + + VehicleRoutingAlgorithm vra = Jsprit.Builder.newInstance(vrp).setProperty(Jsprit.Parameter.VEHICLE_SWITCH, "false").buildAlgorithm(); + vra.setMaxIterations(100); + Collection solutions = vra.searchSolutions(); + + assertEquals(2, Solutions.bestOf(solutions).getRoutes().size()); + assertTrue(containsJob(vrp.getJobs().get("1"), getRoute("21", Solutions.bestOf(solutions)))); + } + + @Test + public void whenEmployingVehicleWithDifferentWorkingShifts_and_vehicleSwitchIsNotAllowed_jsprit_job2ShouldBeAssignedCorrectly() { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml"); + VehicleRoutingProblem vrp = vrpBuilder.build(); + + VehicleRoutingAlgorithm vra = Jsprit.Builder.newInstance(vrp).setProperty(Jsprit.Parameter.VEHICLE_SWITCH, "false").buildAlgorithm(); + vra.setMaxIterations(100); + Collection solutions = vra.searchSolutions(); + + assertEquals(2, Solutions.bestOf(solutions).getRoutes().size()); + assertTrue(containsJob(vrp.getJobs().get("2"), getRoute("19", Solutions.bestOf(solutions)))); + } + + @Test + public void whenUsingJsprit_driverTimesShouldBeMet() throws IOException { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(vrpBuilder).read("src/test/resources/twbug.xml"); + final FastVehicleRoutingTransportCostsMatrix matrix = createMatrix(); + vrpBuilder.setRoutingCost(matrix); + VehicleRoutingProblem vrp = vrpBuilder.build(); + VehicleRoutingAlgorithm algorithm = Jsprit.Builder.newInstance(vrp).buildAlgorithm(); + algorithm.setMaxIterations(1000); + VehicleRoutingProblemSolution solution = Solutions.bestOf(algorithm.searchSolutions()); + for (VehicleRoute r : solution.getRoutes()) { + assertTrue(r.getVehicle().getEarliestDeparture() <= r.getDepartureTime()); + assertTrue(r.getVehicle().getLatestArrival() >= r.getEnd().getArrTime()); + } + } + + @Test + public void whenUsingSchrimpf_driverTimesShouldBeMet() throws IOException { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(vrpBuilder).read("src/test/resources/twbug.xml"); + final FastVehicleRoutingTransportCostsMatrix matrix = createMatrix(); + vrpBuilder.setRoutingCost(matrix); + VehicleRoutingProblem vrp = vrpBuilder.build(); + VehicleRoutingAlgorithm algorithm = new SchrimpfFactory().createAlgorithm(vrp); + algorithm.setMaxIterations(1000); + VehicleRoutingProblemSolution solution = Solutions.bestOf(algorithm.searchSolutions()); + for (VehicleRoute r : solution.getRoutes()) { + assertTrue(r.getVehicle().getEarliestDeparture() <= r.getDepartureTime()); + assertTrue(r.getVehicle().getLatestArrival() >= r.getEnd().getArrTime()); + } + } + + @Test + public void whenUsingGreedySchrimpf_driverTimesShouldBeMet() throws IOException { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(vrpBuilder).read("src/test/resources/twbug.xml"); + final FastVehicleRoutingTransportCostsMatrix matrix = createMatrix(); + vrpBuilder.setRoutingCost(matrix); + VehicleRoutingProblem vrp = vrpBuilder.build(); + VehicleRoutingAlgorithm algorithm = new GreedySchrimpfFactory().createAlgorithm(vrp); + algorithm.setMaxIterations(1000); + VehicleRoutingProblemSolution solution = Solutions.bestOf(algorithm.searchSolutions()); + for (VehicleRoute r : solution.getRoutes()) { + assertTrue(r.getVehicle().getEarliestDeparture() <= r.getDepartureTime()); + assertTrue(r.getVehicle().getLatestArrival() >= r.getEnd().getArrTime()); + } + } + + + private FastVehicleRoutingTransportCostsMatrix createMatrix() throws IOException { + BufferedReader reader = new BufferedReader(new FileReader(new File("src/test/resources/matrix.txt"))); + String line; + FastVehicleRoutingTransportCostsMatrix.Builder builder = FastVehicleRoutingTransportCostsMatrix.Builder.newInstance(11, false); + while ((line = reader.readLine()) != null) { + String[] split = line.split("\t"); + builder.addTransportDistance(Integer.parseInt(split[0]), Integer.parseInt(split[1]), Double.parseDouble(split[2])); + builder.addTransportTime(Integer.parseInt(split[0]), Integer.parseInt(split[1]), Double.parseDouble(split[3])); + } + return builder.build(); + } + + + private boolean containsJob(Job job, VehicleRoute route) { + if (route == null) return false; + for (Job j : route.getTourActivities().getJobs()) { + if (job == j) { + return true; + } + } + return false; + } + + private VehicleRoute getRoute(String vehicleId, VehicleRoutingProblemSolution vehicleRoutingProblemSolution) { + for (VehicleRoute r : vehicleRoutingProblemSolution.getRoutes()) { + if (r.getVehicle().getId().equals(vehicleId)) { + return r; + } + } + return null; + } } diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/OpenRoutesTest.java b/jsprit-core/src/test/java/jsprit/core/algorithm/OpenRoutesTest.java index 50680400..ee5fa064 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/OpenRoutesTest.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/OpenRoutesTest.java @@ -1,18 +1,18 @@ /******************************************************************************* * Copyright (c) 2014 Stefan Schroeder. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . - * + * * Contributors: * Stefan Schroeder - initial API and implementation ******************************************************************************/ @@ -39,137 +39,133 @@ import java.util.Collection; import static org.junit.Assert.*; public class OpenRoutesTest { - - @Test - public void whenDealingWithOpenRouteAndShipments_insertionShouldNotRequireRouteToBeClosed(){ - VehicleType type = VehicleTypeImpl.Builder.newInstance("type").build(); - - VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setLatestArrival(11.) - .setType(type).setReturnToDepot(false).setStartLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(0, 0)).build()).build(); - - Shipment shipment = Shipment.Builder.newInstance("s").setPickupLocation(TestUtils.loc(Coordinate.newInstance(5, 0))) - .setDeliveryLocation(TestUtils.loc(Coordinate.newInstance(10, 0))).build(); - - VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(shipment).addVehicle(vehicle).build(); - - VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp); - vra.setMaxIterations(10); - - try{ - @SuppressWarnings("unused") - Collection solutions = vra.searchSolutions(); - assertTrue(true); - } - catch(NoSolutionFoundException e){ - assertFalse(true); - } - - } - - @Test - public void whenDealingWithOpenRoute_insertionShouldNotRequireRouteToBeClosed(){ - VehicleType type = VehicleTypeImpl.Builder.newInstance("type").build(); - VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setLatestArrival(9.) - .setType(type).setReturnToDepot(false) - .setStartLocation(TestUtils.loc(Coordinate.newInstance(0, 0))) - .build(); - - Service service = Service.Builder.newInstance("s") - .setLocation(TestUtils.loc(Coordinate.newInstance(5, 0))) - .build(); - - VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(service).addVehicle(vehicle).build(); - - VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp); - vra.setMaxIterations(10); - - try{ - @SuppressWarnings("unused") - Collection solutions = vra.searchSolutions(); - assertTrue(true); - } - catch(NoSolutionFoundException e){ - assertFalse(true); - } - - } - - - - @Test - public void whenDealingWithOpenRouteAndShipments_algorithmShouldCalculateCorrectCosts(){ - VehicleType type = VehicleTypeImpl.Builder.newInstance("type").build(); - VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setLatestArrival(20.) - .setType(type).setReturnToDepot(false).setStartLocation(Location.Builder.newInstance() - .setCoordinate(Coordinate.newInstance(0, 0)).build()).build(); - - Shipment shipment = Shipment.Builder.newInstance("s") - .setPickupLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(5, 0)).build()) - .setDeliveryLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(10, 0)).build()) - .build(); - - VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(shipment).addVehicle(vehicle).build(); - - VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp); - vra.setMaxIterations(10); - - Collection solutions = vra.searchSolutions(); - - assertEquals(10.,Solutions.bestOf(solutions).getCost(),0.01); - - } - - @Test - public void whenDealingWithOpenRoute_algorithmShouldCalculateCorrectCosts(){ - VehicleType type = VehicleTypeImpl.Builder.newInstance("type").build(); - VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setLatestArrival(10.) - .setType(type).setReturnToDepot(false).setStartLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(0, 0)).build()).build(); - - Service service = Service.Builder.newInstance("s") - .setLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(5, 0)).build()).build(); - - VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(service).addVehicle(vehicle).build(); - - VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp); - vra.setMaxIterations(10); - - Collection solutions = vra.searchSolutions(); - - assertEquals(5.,Solutions.bestOf(solutions).getCost(),0.01); + @Test + public void whenDealingWithOpenRouteAndShipments_insertionShouldNotRequireRouteToBeClosed() { + VehicleType type = VehicleTypeImpl.Builder.newInstance("type").build(); - } + VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setLatestArrival(11.) + .setType(type).setReturnToDepot(false).setStartLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(0, 0)).build()).build(); - @Test - public void whenDealingWithOpenRouteAndGreatCircleCost_algorithmShouldRunWithoutException(){ - VehicleType type = VehicleTypeImpl.Builder.newInstance("type").build(); - VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v") - .setType(type).setReturnToDepot(false) - .setStartLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(0, 0)).build()) - .build(); + Shipment shipment = Shipment.Builder.newInstance("s").setPickupLocation(TestUtils.loc(Coordinate.newInstance(5, 0))) + .setDeliveryLocation(TestUtils.loc(Coordinate.newInstance(10, 0))).build(); - Service service = Service.Builder.newInstance("s") - .setLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(50, 0)).build()).build(); + VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(shipment).addVehicle(vehicle).build(); - VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance() - .addJob(service).addVehicle(vehicle) - .setRoutingCost(new GreatCircleCosts()) - .build(); + VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp); + vra.setMaxIterations(10); - VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp); - vra.setMaxIterations(10); + try { + @SuppressWarnings("unused") + Collection solutions = vra.searchSolutions(); + assertTrue(true); + } catch (NoSolutionFoundException e) { + assertFalse(true); + } - try { - @SuppressWarnings("UnusedDeclaration") - Collection solutions = vra.searchSolutions(); - assertTrue(true); - } - catch (Exception e){ - assertTrue(false); - } + } + + @Test + public void whenDealingWithOpenRoute_insertionShouldNotRequireRouteToBeClosed() { + VehicleType type = VehicleTypeImpl.Builder.newInstance("type").build(); + VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setLatestArrival(9.) + .setType(type).setReturnToDepot(false) + .setStartLocation(TestUtils.loc(Coordinate.newInstance(0, 0))) + .build(); + + Service service = Service.Builder.newInstance("s") + .setLocation(TestUtils.loc(Coordinate.newInstance(5, 0))) + .build(); + + VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(service).addVehicle(vehicle).build(); + + VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp); + vra.setMaxIterations(10); + + try { + @SuppressWarnings("unused") + Collection solutions = vra.searchSolutions(); + assertTrue(true); + } catch (NoSolutionFoundException e) { + assertFalse(true); + } + + } - } + @Test + public void whenDealingWithOpenRouteAndShipments_algorithmShouldCalculateCorrectCosts() { + VehicleType type = VehicleTypeImpl.Builder.newInstance("type").build(); + + VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setLatestArrival(20.) + .setType(type).setReturnToDepot(false).setStartLocation(Location.Builder.newInstance() + .setCoordinate(Coordinate.newInstance(0, 0)).build()).build(); + + Shipment shipment = Shipment.Builder.newInstance("s") + .setPickupLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(5, 0)).build()) + .setDeliveryLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(10, 0)).build()) + .build(); + + VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(shipment).addVehicle(vehicle).build(); + + VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp); + vra.setMaxIterations(10); + + Collection solutions = vra.searchSolutions(); + + assertEquals(10., Solutions.bestOf(solutions).getCost(), 0.01); + + } + + @Test + public void whenDealingWithOpenRoute_algorithmShouldCalculateCorrectCosts() { + VehicleType type = VehicleTypeImpl.Builder.newInstance("type").build(); + VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setLatestArrival(10.) + .setType(type).setReturnToDepot(false).setStartLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(0, 0)).build()).build(); + + Service service = Service.Builder.newInstance("s") + .setLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(5, 0)).build()).build(); + + VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(service).addVehicle(vehicle).build(); + + VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp); + vra.setMaxIterations(10); + + Collection solutions = vra.searchSolutions(); + + assertEquals(5., Solutions.bestOf(solutions).getCost(), 0.01); + + } + + @Test + public void whenDealingWithOpenRouteAndGreatCircleCost_algorithmShouldRunWithoutException() { + VehicleType type = VehicleTypeImpl.Builder.newInstance("type").build(); + VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v") + .setType(type).setReturnToDepot(false) + .setStartLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(0, 0)).build()) + .build(); + + Service service = Service.Builder.newInstance("s") + .setLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(50, 0)).build()).build(); + + VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance() + .addJob(service).addVehicle(vehicle) + .setRoutingCost(new GreatCircleCosts()) + .build(); + + VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp); + vra.setMaxIterations(10); + + try { + @SuppressWarnings("UnusedDeclaration") + Collection solutions = vra.searchSolutions(); + assertTrue(true); + } catch (Exception e) { + assertTrue(false); + } + + + } } diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/PDTW_IT.java b/jsprit-core/src/test/java/jsprit/core/algorithm/PDTW_IT.java deleted file mode 100644 index e83b657a..00000000 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/PDTW_IT.java +++ /dev/null @@ -1,187 +0,0 @@ -package jsprit.core.algorithm; - - -import jsprit.core.algorithm.box.Jsprit; -import jsprit.core.algorithm.box.SchrimpfFactory; -import jsprit.core.problem.AbstractJob; -import jsprit.core.problem.Location; -import jsprit.core.problem.VehicleRoutingProblem; -import jsprit.core.problem.VehicleRoutingProblem.FleetSize; -import jsprit.core.problem.job.Service; -import jsprit.core.problem.job.Shipment; -import jsprit.core.problem.solution.VehicleRoutingProblemSolution; -import jsprit.core.problem.solution.route.VehicleRoute; -import jsprit.core.problem.solution.route.activity.TourActivity; -import jsprit.core.problem.vehicle.Vehicle; -import jsprit.core.problem.vehicle.VehicleImpl; -import jsprit.core.problem.vehicle.VehicleImpl.Builder; -import jsprit.core.problem.vehicle.VehicleType; -import jsprit.core.problem.vehicle.VehicleTypeImpl; -import jsprit.core.util.Coordinate; -import jsprit.core.util.Solutions; -import org.junit.Test; - -import java.util.Collection; -import java.util.Random; - -import static org.junit.Assert.assertFalse; - - -public class PDTW_IT { - - int nJobs = 200; - int nVehicles = 40; - Random random = new Random(1623); - int nextShipmentId=1; - int nextVehicleId=1; - - @Test - public void whenDealingWithShipments_timeWindowsShouldNOTbeBroken() { - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - for(int i =0 ; i < nVehicles ; i++){ - vrpBuilder.addVehicle(createVehicle()); - } - for(int i =0 ; i < nJobs;i++){ - vrpBuilder.addJob(createShipment()); - } - vrpBuilder.setFleetSize(FleetSize.FINITE); - VehicleRoutingProblem problem = vrpBuilder.build(); - VehicleRoutingAlgorithm algorithm = new SchrimpfFactory().createAlgorithm(problem); - algorithm.setMaxIterations(0); - Collection solutions = algorithm.searchSolutions(); - VehicleRoutingProblemSolution bestSolution = Solutions.bestOf(solutions); - - for(VehicleRoute route : bestSolution.getRoutes()){ - Vehicle v = route.getVehicle(); - for(TourActivity ta : route.getActivities()){ - if(ta.getArrTime() > v.getLatestArrival() * 1.00001){ - assertFalse(true); - } - } - } - } - - - @Test - public void whenDealingWithServices_timeWindowsShouldNOTbeBroken() { - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - for(int i =0 ; i < nVehicles ; i++){ - vrpBuilder.addVehicle(createVehicle()); - } - for(int i =0 ; i < nJobs;i++){ - vrpBuilder.addJob(createService()); - } - vrpBuilder.setFleetSize(FleetSize.FINITE); - VehicleRoutingProblem problem = vrpBuilder.build(); - VehicleRoutingAlgorithm algorithm = new SchrimpfFactory().createAlgorithm(problem); - algorithm.setMaxIterations(100); - Collection solutions = algorithm.searchSolutions(); - VehicleRoutingProblemSolution bestSolution = Solutions.bestOf(solutions); - - for(VehicleRoute route : bestSolution.getRoutes()){ - Vehicle v = route.getVehicle(); - for(TourActivity ta : route.getActivities()){ - if(ta.getArrTime() * 1.000001 > v.getLatestArrival()){ - assertFalse(true); - } - } - } - } - - @Test - public void whenDealingWithShipments_usingJsprit_timeWindowsShouldNOTbeBroken() { - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - for(int i =0 ; i < nVehicles ; i++){ - vrpBuilder.addVehicle(createVehicle()); - } - for(int i =0 ; i < nJobs;i++){ - vrpBuilder.addJob(createShipment()); - } - vrpBuilder.setFleetSize(FleetSize.FINITE); - VehicleRoutingProblem problem = vrpBuilder.build(); - VehicleRoutingAlgorithm algorithm = Jsprit.createAlgorithm(problem); - algorithm.setMaxIterations(0); - Collection solutions = algorithm.searchSolutions(); - VehicleRoutingProblemSolution bestSolution = Solutions.bestOf(solutions); - - for(VehicleRoute route : bestSolution.getRoutes()){ - Vehicle v = route.getVehicle(); - for(TourActivity ta : route.getActivities()){ - if(ta.getArrTime() > v.getLatestArrival() * 1.00001){ - assertFalse(true); - } - } - } - } - - - @Test - public void whenDealingWithServices_usingJsprit_timeWindowsShouldNOTbeBroken() { - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - for(int i =0 ; i < nVehicles ; i++){ - vrpBuilder.addVehicle(createVehicle()); - } - for(int i =0 ; i < nJobs;i++){ - vrpBuilder.addJob(createService()); - } - vrpBuilder.setFleetSize(FleetSize.FINITE); - VehicleRoutingProblem problem = vrpBuilder.build(); - VehicleRoutingAlgorithm algorithm = Jsprit.createAlgorithm(problem); - algorithm.setMaxIterations(100); - Collection solutions = algorithm.searchSolutions(); - VehicleRoutingProblemSolution bestSolution = Solutions.bestOf(solutions); - - for(VehicleRoute route : bestSolution.getRoutes()){ - Vehicle v = route.getVehicle(); - for(TourActivity ta : route.getActivities()){ - if(ta.getArrTime() * 1.000001 > v.getLatestArrival()){ - assertFalse(true); - } - } - } - } - - private AbstractJob createService() { - Service.Builder b = Service.Builder.newInstance(Integer.toString(nextShipmentId++)); - b.addSizeDimension(0, 1); - b.setServiceTime(random.nextDouble() * 5); - b.setLocation(createLocation()); - return b.build(); - } - - private Location createLocation(){ - return loc(new Coordinate(50*random.nextDouble(), 50*random.nextDouble())); - } - - private Shipment createShipment(){ - Shipment.Builder b = Shipment.Builder.newInstance(Integer.toString(nextShipmentId++)); - b.addSizeDimension(0, 1); - b.setPickupServiceTime(random.nextDouble() * 5); - b.setDeliveryServiceTime(random.nextDouble() * 5); - b.setDeliveryLocation(createLocation()); - b.setPickupLocation(createLocation()); - return b.build(); - } - private VehicleImpl createVehicle(){ - VehicleTypeImpl.Builder vehicleTypeBuilder = VehicleTypeImpl.Builder.newInstance("vehicleType" + nextVehicleId).addCapacityDimension(0, 2); - vehicleTypeBuilder.setCostPerDistance(1.0); - vehicleTypeBuilder.setCostPerTime(1); - vehicleTypeBuilder.setFixedCost(1000); - VehicleType vehicleType = vehicleTypeBuilder.build(); - Builder v = VehicleImpl.Builder.newInstance("vehicle" + nextVehicleId); - Location l = createLocation(); - v.setStartLocation(l); - v.setEndLocation(l); - v.setType(vehicleType); - v.setEarliestStart(50); - v.setLatestArrival(200); - nextVehicleId++; - return v.build(); - } - - - private static Location loc(Coordinate coordinate){ - return Location.Builder.newInstance().setCoordinate(coordinate).build(); - } -} - diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/PickupsAndDeliveries_IT.java b/jsprit-core/src/test/java/jsprit/core/algorithm/PickupsAndDeliveries_IT.java index 71832e06..2c36121f 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/PickupsAndDeliveries_IT.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/PickupsAndDeliveries_IT.java @@ -1,23 +1,24 @@ /******************************************************************************* * Copyright (c) 2014 Stefan Schroeder. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . - * + * * Contributors: * Stefan Schroeder - initial API and implementation ******************************************************************************/ package jsprit.core.algorithm; +import jsprit.core.IntegrationTest; import jsprit.core.algorithm.box.Jsprit; import jsprit.core.algorithm.io.VehicleRoutingAlgorithms; import jsprit.core.problem.VehicleRoutingProblem; @@ -25,34 +26,37 @@ import jsprit.core.problem.io.VrpXMLReader; import jsprit.core.problem.solution.VehicleRoutingProblemSolution; import jsprit.core.util.Solutions; import org.junit.Test; +import org.junit.experimental.categories.Category; import java.util.Collection; import static org.junit.Assert.assertEquals; public class PickupsAndDeliveries_IT { - - @Test - public void whenSolvingLR101InstanceOfLiLim_solutionsMustNoBeWorseThan5PercentOfBestKnownSolution(){ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpBuilder).read("src/test/resources/lilim_lr101.xml"); - VehicleRoutingProblem vrp = vrpBuilder.build(); - VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/lilim_algorithmConfig.xml"); - Collection solutions = vra.searchSolutions(); - assertEquals(1650.8,Solutions.bestOf(solutions).getCost(),80.); - assertEquals(19,Solutions.bestOf(solutions).getRoutes().size(),1); - } - @Test - public void whenSolvingLR101InstanceOfLiLim_withJsprit_solutionsMustNoBeWorseThan5PercentOfBestKnownSolution(){ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpBuilder).read("src/test/resources/lilim_lr101.xml"); - VehicleRoutingProblem vrp = vrpBuilder.build(); - VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp); - vra.setMaxIterations(1000); - Collection solutions = vra.searchSolutions(); - assertEquals(1650.8,Solutions.bestOf(solutions).getCost(),80.); - assertEquals(19,Solutions.bestOf(solutions).getRoutes().size(),1); - } + @Test + @Category(IntegrationTest.class) + public void whenSolvingLR101InstanceOfLiLim_solutionsMustNoBeWorseThan5PercentOfBestKnownSolution() { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(vrpBuilder).read("src/test/resources/lilim_lr101.xml"); + VehicleRoutingProblem vrp = vrpBuilder.build(); + VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/lilim_algorithmConfig.xml"); + Collection solutions = vra.searchSolutions(); + assertEquals(1650.8, Solutions.bestOf(solutions).getCost(), 80.); + assertEquals(19, Solutions.bestOf(solutions).getRoutes().size(), 1); + } + + @Test + @Category(IntegrationTest.class) + public void whenSolvingLR101InstanceOfLiLim_withJsprit_solutionsMustNoBeWorseThan5PercentOfBestKnownSolution() { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(vrpBuilder).read("src/test/resources/lilim_lr101.xml"); + VehicleRoutingProblem vrp = vrpBuilder.build(); + VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp); + vra.setMaxIterations(1000); + Collection solutions = vra.searchSolutions(); + assertEquals(1650.8, Solutions.bestOf(solutions).getCost(), 80.); + assertEquals(19, Solutions.bestOf(solutions).getRoutes().size(), 1); + } } diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/RefuseCollectionWithCostsHigherThanTimesAndFiniteFleet_IT.java b/jsprit-core/src/test/java/jsprit/core/algorithm/RefuseCollectionWithCostsHigherThanTimesAndFiniteFleet_IT.java index 5bc014bc..2e815568 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/RefuseCollectionWithCostsHigherThanTimesAndFiniteFleet_IT.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/RefuseCollectionWithCostsHigherThanTimesAndFiniteFleet_IT.java @@ -1,21 +1,22 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm; +import jsprit.core.IntegrationTest; import jsprit.core.algorithm.box.GreedySchrimpfFactory; import jsprit.core.algorithm.termination.IterationWithoutImprovementTermination; import jsprit.core.problem.Location; @@ -32,6 +33,7 @@ import jsprit.core.util.Solutions; import jsprit.core.util.VehicleRoutingTransportCostsMatrix; import jsprit.core.util.VehicleRoutingTransportCostsMatrix.Builder; import org.junit.Test; +import org.junit.experimental.categories.Category; import java.io.*; import java.util.Collection; @@ -39,162 +41,161 @@ import java.util.Collection; import static org.junit.Assert.assertEquals; - public class RefuseCollectionWithCostsHigherThanTimesAndFiniteFleet_IT { - - static class RelationKey { - - static RelationKey newKey(String from, String to){ - int fromInt = Integer.parseInt(from); - int toInt = Integer.parseInt(to); - if(fromInt < toInt){ - return new RelationKey(from, to); - } - else { - return new RelationKey(to, from); - } - } - - final String from; - final String to; - - public RelationKey(String from, String to) { - super(); - this.from = from; - this.to = to; - } - /* (non-Javadoc) - * @see java.lang.Object#hashCode() - */ - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((from == null) ? 0 : from.hashCode()); - result = prime * result + ((to == null) ? 0 : to.hashCode()); - return result; - } + static class RelationKey { - /* (non-Javadoc) - * @see java.lang.Object#equals(java.lang.Object) - */ - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - RelationKey other = (RelationKey) obj; - if (from == null) { - if (other.from != null) - return false; - } else if (!from.equals(other.from)) - return false; - if (to == null) { - if (other.to != null) - return false; - } else if (!to.equals(other.to)) - return false; - return true; - } - } - - @Test - public void testAlgo(){ - - - /* - * create vehicle-type and vehicle - */ - VehicleTypeImpl.Builder typeBuilder = VehicleTypeImpl.Builder.newInstance("vehicle-type").addCapacityDimension(0, 23); - typeBuilder.setCostPerDistance(1.0); - VehicleTypeImpl bigType = typeBuilder.build(); - - VehicleImpl.Builder vehicleBuilder = VehicleImpl.Builder.newInstance("vehicle"); - vehicleBuilder.setStartLocation(Location.newInstance("1")); - vehicleBuilder.setType(bigType); - vehicleBuilder.setLatestArrival(220); - Vehicle bigVehicle = vehicleBuilder.build(); - - /* - * start building the problem - */ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - vrpBuilder.setFleetSize(FleetSize.INFINITE); - vrpBuilder.addVehicle(bigVehicle); - - /* - * create cost-matrix - */ - VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(true); - /* - * read demand quantities - */ - try { - readDemandQuantities(vrpBuilder); - readDistances(matrixBuilder); - } catch (FileNotFoundException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - - vrpBuilder.setRoutingCost(matrixBuilder.build()); - VehicleRoutingProblem vrp = vrpBuilder.build(); - VehicleRoutingAlgorithm vra = new GreedySchrimpfFactory().createAlgorithm(vrp); - vra.setPrematureAlgorithmTermination(new IterationWithoutImprovementTermination(100)); - Collection solutions = vra.searchSolutions(); - - SolutionPrinter.print(vrp, Solutions.bestOf(solutions), Print.VERBOSE); - - assertEquals(2.*397.,Solutions.bestOf(solutions).getCost(),0.01); - assertEquals(2,Solutions.bestOf(solutions).getRoutes().size()); - } + static RelationKey newKey(String from, String to) { + int fromInt = Integer.parseInt(from); + int toInt = Integer.parseInt(to); + if (fromInt < toInt) { + return new RelationKey(from, to); + } else { + return new RelationKey(to, from); + } + } + + final String from; + final String to; + + public RelationKey(String from, String to) { + super(); + this.from = from; + this.to = to; + } + + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((from == null) ? 0 : from.hashCode()); + result = prime * result + ((to == null) ? 0 : to.hashCode()); + return result; + } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + RelationKey other = (RelationKey) obj; + if (from == null) { + if (other.from != null) + return false; + } else if (!from.equals(other.from)) + return false; + if (to == null) { + if (other.to != null) + return false; + } else if (!to.equals(other.to)) + return false; + return true; + } + } + + @Test + @Category(IntegrationTest.class) + public void testAlgo() { - private static void readDemandQuantities(VehicleRoutingProblem.Builder vrpBuilder) throws FileNotFoundException, IOException { - BufferedReader reader = new BufferedReader(new FileReader(new File("src/test/resources/refuseCollectionExample_Quantities"))); - String line = null; - boolean firstLine = true; - while((line = reader.readLine()) != null){ - if(firstLine) { - firstLine = false; - continue; - } - String[] lineTokens = line.split(","); - /* - * build service + /* + * create vehicle-type and vehicle + */ + VehicleTypeImpl.Builder typeBuilder = VehicleTypeImpl.Builder.newInstance("vehicle-type").addCapacityDimension(0, 23); + typeBuilder.setCostPerDistance(1.0); + VehicleTypeImpl bigType = typeBuilder.build(); + + VehicleImpl.Builder vehicleBuilder = VehicleImpl.Builder.newInstance("vehicle"); + vehicleBuilder.setStartLocation(Location.newInstance("1")); + vehicleBuilder.setType(bigType); + vehicleBuilder.setLatestArrival(220); + Vehicle bigVehicle = vehicleBuilder.build(); + + /* + * start building the problem + */ + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + vrpBuilder.setFleetSize(FleetSize.INFINITE); + vrpBuilder.addVehicle(bigVehicle); + + /* + * create cost-matrix + */ + VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(true); + /* + * read demand quantities + */ + try { + readDemandQuantities(vrpBuilder); + readDistances(matrixBuilder); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + + vrpBuilder.setRoutingCost(matrixBuilder.build()); + VehicleRoutingProblem vrp = vrpBuilder.build(); + VehicleRoutingAlgorithm vra = new GreedySchrimpfFactory().createAlgorithm(vrp); + vra.setPrematureAlgorithmTermination(new IterationWithoutImprovementTermination(100)); + Collection solutions = vra.searchSolutions(); + + SolutionPrinter.print(vrp, Solutions.bestOf(solutions), Print.VERBOSE); + + assertEquals(2. * 397., Solutions.bestOf(solutions).getCost(), 0.01); + assertEquals(2, Solutions.bestOf(solutions).getRoutes().size()); + } + + + private static void readDemandQuantities(VehicleRoutingProblem.Builder vrpBuilder) throws FileNotFoundException, IOException { + BufferedReader reader = new BufferedReader(new FileReader(new File("src/test/resources/refuseCollectionExample_Quantities"))); + String line = null; + boolean firstLine = true; + while ((line = reader.readLine()) != null) { + if (firstLine) { + firstLine = false; + continue; + } + String[] lineTokens = line.split(","); + /* + * build service */ - Service service = Service.Builder.newInstance(lineTokens[0]).addSizeDimension(0, Integer.parseInt(lineTokens[1])) - .setLocation(Location.newInstance(lineTokens[0])).build(); - /* + 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); - } - reader.close(); - } - + vrpBuilder.addJob(service); + } + reader.close(); + } - private static void readDistances(Builder matrixBuilder) throws IOException { - BufferedReader reader = new BufferedReader(new FileReader(new File("src/test/resources/refuseCollectionExample_Distances"))); - String line = null; - boolean firstLine = true; - while((line = reader.readLine()) != null){ - if(firstLine) { - firstLine = false; - continue; - } - String[] lineTokens = line.split(","); - matrixBuilder.addTransportDistance(lineTokens[0],lineTokens[1], 2.*Integer.parseInt(lineTokens[2])); - matrixBuilder.addTransportTime(lineTokens[0],lineTokens[1], Integer.parseInt(lineTokens[2])); - } - reader.close(); - - } + + private static void readDistances(Builder matrixBuilder) throws IOException { + BufferedReader reader = new BufferedReader(new FileReader(new File("src/test/resources/refuseCollectionExample_Distances"))); + String line = null; + boolean firstLine = true; + while ((line = reader.readLine()) != null) { + if (firstLine) { + firstLine = false; + continue; + } + String[] lineTokens = line.split(","); + matrixBuilder.addTransportDistance(lineTokens[0], lineTokens[1], 2. * Integer.parseInt(lineTokens[2])); + matrixBuilder.addTransportTime(lineTokens[0], lineTokens[1], Integer.parseInt(lineTokens[2])); + } + reader.close(); + + } } diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/RefuseCollectionWithCostsHigherThanTimesAndFiniteFleet_withTimeAndDistanceCosts_IT.java b/jsprit-core/src/test/java/jsprit/core/algorithm/RefuseCollectionWithCostsHigherThanTimesAndFiniteFleet_withTimeAndDistanceCosts_IT.java index d7d30071..37c44ca2 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/RefuseCollectionWithCostsHigherThanTimesAndFiniteFleet_withTimeAndDistanceCosts_IT.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/RefuseCollectionWithCostsHigherThanTimesAndFiniteFleet_withTimeAndDistanceCosts_IT.java @@ -1,21 +1,22 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm; +import jsprit.core.IntegrationTest; import jsprit.core.algorithm.box.GreedySchrimpfFactory; import jsprit.core.algorithm.termination.IterationWithoutImprovementTermination; import jsprit.core.problem.Location; @@ -32,6 +33,7 @@ import jsprit.core.util.Solutions; import jsprit.core.util.VehicleRoutingTransportCostsMatrix; import jsprit.core.util.VehicleRoutingTransportCostsMatrix.Builder; import org.junit.Test; +import org.junit.experimental.categories.Category; import java.io.*; import java.util.Collection; @@ -39,162 +41,161 @@ import java.util.Collection; import static org.junit.Assert.assertEquals; - public class RefuseCollectionWithCostsHigherThanTimesAndFiniteFleet_withTimeAndDistanceCosts_IT { - - static class RelationKey { - - static RelationKey newKey(String from, String to){ - int fromInt = Integer.parseInt(from); - int toInt = Integer.parseInt(to); - if(fromInt < toInt){ - return new RelationKey(from, to); - } - else { - return new RelationKey(to, from); - } - } - - final String from; - final String to; - - public RelationKey(String from, String to) { - super(); - this.from = from; - this.to = to; - } - /* (non-Javadoc) - * @see java.lang.Object#hashCode() - */ - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((from == null) ? 0 : from.hashCode()); - result = prime * result + ((to == null) ? 0 : to.hashCode()); - return result; - } + static class RelationKey { - /* (non-Javadoc) - * @see java.lang.Object#equals(java.lang.Object) - */ - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - RelationKey other = (RelationKey) obj; - if (from == null) { - if (other.from != null) - return false; - } else if (!from.equals(other.from)) - return false; - if (to == null) { - if (other.to != null) - return false; - } else if (!to.equals(other.to)) - return false; - return true; - } - } - - @Test - public void testAlgo(){ - - - /* - * create vehicle-type and vehicle - */ - VehicleTypeImpl.Builder typeBuilder = VehicleTypeImpl.Builder.newInstance("vehicle-type").addCapacityDimension(0, 23); - typeBuilder.setCostPerDistance(1.0).setCostPerTime(1.); - VehicleTypeImpl bigType = typeBuilder.build(); - - VehicleImpl.Builder vehicleBuilder = VehicleImpl.Builder.newInstance("vehicle"); - vehicleBuilder.setStartLocation(Location.newInstance("1")); - vehicleBuilder.setType(bigType); - vehicleBuilder.setLatestArrival(220); - Vehicle bigVehicle = vehicleBuilder.build(); - - /* - * start building the problem - */ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - vrpBuilder.setFleetSize(FleetSize.INFINITE); - vrpBuilder.addVehicle(bigVehicle); - - /* - * create cost-matrix - */ - VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(true); - /* - * read demand quantities - */ - try { - readDemandQuantities(vrpBuilder); - readDistances(matrixBuilder); - } catch (FileNotFoundException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - - vrpBuilder.setRoutingCost(matrixBuilder.build()); - VehicleRoutingProblem vrp = vrpBuilder.build(); - VehicleRoutingAlgorithm vra = new GreedySchrimpfFactory().createAlgorithm(vrp); - vra.setPrematureAlgorithmTermination(new IterationWithoutImprovementTermination(100)); - Collection solutions = vra.searchSolutions(); - - SolutionPrinter.print(vrp, Solutions.bestOf(solutions), Print.VERBOSE); - - assertEquals(2.*397.+397.,Solutions.bestOf(solutions).getCost(),0.01); - assertEquals(2,Solutions.bestOf(solutions).getRoutes().size()); - } + static RelationKey newKey(String from, String to) { + int fromInt = Integer.parseInt(from); + int toInt = Integer.parseInt(to); + if (fromInt < toInt) { + return new RelationKey(from, to); + } else { + return new RelationKey(to, from); + } + } + + final String from; + final String to; + + public RelationKey(String from, String to) { + super(); + this.from = from; + this.to = to; + } + + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((from == null) ? 0 : from.hashCode()); + result = prime * result + ((to == null) ? 0 : to.hashCode()); + return result; + } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + RelationKey other = (RelationKey) obj; + if (from == null) { + if (other.from != null) + return false; + } else if (!from.equals(other.from)) + return false; + if (to == null) { + if (other.to != null) + return false; + } else if (!to.equals(other.to)) + return false; + return true; + } + } + + @Test + @Category(IntegrationTest.class) + public void testAlgo() { - private static void readDemandQuantities(VehicleRoutingProblem.Builder vrpBuilder) throws FileNotFoundException, IOException { - BufferedReader reader = new BufferedReader(new FileReader(new File("src/test/resources/refuseCollectionExample_Quantities"))); - String line = null; - boolean firstLine = true; - while((line = reader.readLine()) != null){ - if(firstLine) { - firstLine = false; - continue; - } - String[] lineTokens = line.split(","); - /* - * build service + /* + * create vehicle-type and vehicle + */ + VehicleTypeImpl.Builder typeBuilder = VehicleTypeImpl.Builder.newInstance("vehicle-type").addCapacityDimension(0, 23); + typeBuilder.setCostPerDistance(1.0).setCostPerTime(1.); + VehicleTypeImpl bigType = typeBuilder.build(); + + VehicleImpl.Builder vehicleBuilder = VehicleImpl.Builder.newInstance("vehicle"); + vehicleBuilder.setStartLocation(Location.newInstance("1")); + vehicleBuilder.setType(bigType); + vehicleBuilder.setLatestArrival(220); + Vehicle bigVehicle = vehicleBuilder.build(); + + /* + * start building the problem + */ + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + vrpBuilder.setFleetSize(FleetSize.INFINITE); + vrpBuilder.addVehicle(bigVehicle); + + /* + * create cost-matrix + */ + VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(true); + /* + * read demand quantities + */ + try { + readDemandQuantities(vrpBuilder); + readDistances(matrixBuilder); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + + vrpBuilder.setRoutingCost(matrixBuilder.build()); + VehicleRoutingProblem vrp = vrpBuilder.build(); + VehicleRoutingAlgorithm vra = new GreedySchrimpfFactory().createAlgorithm(vrp); + vra.setPrematureAlgorithmTermination(new IterationWithoutImprovementTermination(100)); + Collection solutions = vra.searchSolutions(); + + SolutionPrinter.print(vrp, Solutions.bestOf(solutions), Print.VERBOSE); + + assertEquals(2. * 397. + 397., Solutions.bestOf(solutions).getCost(), 0.01); + assertEquals(2, Solutions.bestOf(solutions).getRoutes().size()); + } + + + private static void readDemandQuantities(VehicleRoutingProblem.Builder vrpBuilder) throws FileNotFoundException, IOException { + BufferedReader reader = new BufferedReader(new FileReader(new File("src/test/resources/refuseCollectionExample_Quantities"))); + String line = null; + boolean firstLine = true; + while ((line = reader.readLine()) != null) { + if (firstLine) { + firstLine = false; + continue; + } + String[] lineTokens = line.split(","); + /* + * build service */ - Service service = Service.Builder.newInstance(lineTokens[0]).addSizeDimension(0, Integer.parseInt(lineTokens[1])) - .setLocation(Location.newInstance(lineTokens[0])).build(); - /* + 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); - } - reader.close(); - } - + vrpBuilder.addJob(service); + } + reader.close(); + } - private static void readDistances(Builder matrixBuilder) throws IOException { - BufferedReader reader = new BufferedReader(new FileReader(new File("src/test/resources/refuseCollectionExample_Distances"))); - String line = null; - boolean firstLine = true; - while((line = reader.readLine()) != null){ - if(firstLine) { - firstLine = false; - continue; - } - String[] lineTokens = line.split(","); - matrixBuilder.addTransportDistance(lineTokens[0],lineTokens[1], 2.*Integer.parseInt(lineTokens[2])); - matrixBuilder.addTransportTime(lineTokens[0],lineTokens[1], Integer.parseInt(lineTokens[2])); - } - reader.close(); - - } + + private static void readDistances(Builder matrixBuilder) throws IOException { + BufferedReader reader = new BufferedReader(new FileReader(new File("src/test/resources/refuseCollectionExample_Distances"))); + String line = null; + boolean firstLine = true; + while ((line = reader.readLine()) != null) { + if (firstLine) { + firstLine = false; + continue; + } + String[] lineTokens = line.split(","); + matrixBuilder.addTransportDistance(lineTokens[0], lineTokens[1], 2. * Integer.parseInt(lineTokens[2])); + matrixBuilder.addTransportTime(lineTokens[0], lineTokens[1], Integer.parseInt(lineTokens[2])); + } + reader.close(); + + } } diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/RefuseCollection_IT.java b/jsprit-core/src/test/java/jsprit/core/algorithm/RefuseCollection_IT.java index 5a9bf6f4..48838c15 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/RefuseCollection_IT.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/RefuseCollection_IT.java @@ -11,11 +11,12 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm; +import jsprit.core.IntegrationTest; import jsprit.core.algorithm.box.Jsprit; import jsprit.core.algorithm.box.SchrimpfFactory; import jsprit.core.algorithm.termination.IterationWithoutImprovementTermination; @@ -34,6 +35,7 @@ import jsprit.core.util.Solutions; import jsprit.core.util.VehicleRoutingTransportCostsMatrix; import jsprit.core.util.VehicleRoutingTransportCostsMatrix.Builder; import org.junit.Test; +import org.junit.experimental.categories.Category; import java.io.*; import java.util.Collection; @@ -41,101 +43,102 @@ import java.util.Collection; import static org.junit.Assert.assertEquals; - public class RefuseCollection_IT { - - - @Test - public void whenReadingServices_itShouldCalculateCorrectly(){ + + @Test + @Category(IntegrationTest.class) + public void whenReadingServices_itShouldCalculateCorrectly() { /* - * create vehicle-type and vehicle + * create vehicle-type and vehicle */ - VehicleTypeImpl.Builder typeBuilder = VehicleTypeImpl.Builder.newInstance("vehicle-type").addCapacityDimension(0, 23); - typeBuilder.setCostPerDistance(1.0); - VehicleTypeImpl bigType = typeBuilder.build(); - - VehicleImpl.Builder vehicleBuilder = VehicleImpl.Builder.newInstance("vehicle"); - vehicleBuilder.setStartLocation(Location.newInstance("1")); - vehicleBuilder.setType(bigType); - VehicleImpl bigVehicle = vehicleBuilder.build(); - + VehicleTypeImpl.Builder typeBuilder = VehicleTypeImpl.Builder.newInstance("vehicle-type").addCapacityDimension(0, 23); + typeBuilder.setCostPerDistance(1.0); + VehicleTypeImpl bigType = typeBuilder.build(); + + VehicleImpl.Builder vehicleBuilder = VehicleImpl.Builder.newInstance("vehicle"); + vehicleBuilder.setStartLocation(Location.newInstance("1")); + vehicleBuilder.setType(bigType); + VehicleImpl bigVehicle = vehicleBuilder.build(); + /* - * start building the problem + * start building the problem */ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - vrpBuilder.setFleetSize(FleetSize.INFINITE); - vrpBuilder.addVehicle(bigVehicle); - + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + vrpBuilder.setFleetSize(FleetSize.INFINITE); + vrpBuilder.addVehicle(bigVehicle); + /* - * create cost-matrix + * create cost-matrix */ - VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(true); + VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(true); + /* + * read demand quantities + */ + readDemandQuantitiesAsServices(vrpBuilder); + readDistances(matrixBuilder); + + vrpBuilder.setRoutingCost(matrixBuilder.build()); + VehicleRoutingProblem vrp = vrpBuilder.build(); + VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp); + vra.setPrematureAlgorithmTermination(new IterationWithoutImprovementTermination(100)); + Collection solutions = vra.searchSolutions(); + + SolutionPrinter.print(vrp, Solutions.bestOf(solutions), Print.VERBOSE); + + assertEquals(397.0, Solutions.bestOf(solutions).getCost(), 40.); + assertEquals(2, Solutions.bestOf(solutions).getRoutes().size()); + } + + @Test + @Category(IntegrationTest.class) + public void whenReadingServices_usingJsprit_itShouldCalculateCorrectly() { + /* + * create vehicle-type and vehicle + */ + VehicleTypeImpl.Builder typeBuilder = VehicleTypeImpl.Builder.newInstance("vehicle-type").addCapacityDimension(0, 23); + typeBuilder.setCostPerDistance(1.0); + VehicleTypeImpl bigType = typeBuilder.build(); + + VehicleImpl.Builder vehicleBuilder = VehicleImpl.Builder.newInstance("vehicle"); + vehicleBuilder.setStartLocation(Location.newInstance("1")); + vehicleBuilder.setType(bigType); + VehicleImpl bigVehicle = vehicleBuilder.build(); + + /* + * start building the problem + */ + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + vrpBuilder.setFleetSize(FleetSize.INFINITE); + vrpBuilder.addVehicle(bigVehicle); + + /* + * create cost-matrix + */ + VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(true); + /* * read demand quantities */ readDemandQuantitiesAsServices(vrpBuilder); readDistances(matrixBuilder); vrpBuilder.setRoutingCost(matrixBuilder.build()); - VehicleRoutingProblem vrp = vrpBuilder.build(); - VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp); - vra.setPrematureAlgorithmTermination(new IterationWithoutImprovementTermination(100)); - Collection solutions = vra.searchSolutions(); - - SolutionPrinter.print(vrp, Solutions.bestOf(solutions), Print.VERBOSE); - - assertEquals(397.0,Solutions.bestOf(solutions).getCost(),40.); - assertEquals(2,Solutions.bestOf(solutions).getRoutes().size()); - } + VehicleRoutingProblem vrp = vrpBuilder.build(); + VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp); + vra.setPrematureAlgorithmTermination(new IterationWithoutImprovementTermination(100)); + Collection solutions = vra.searchSolutions(); - @Test - public void whenReadingServices_usingJsprit_itShouldCalculateCorrectly(){ + SolutionPrinter.print(vrp, Solutions.bestOf(solutions), Print.VERBOSE); - /* - * create vehicle-type and vehicle - */ - VehicleTypeImpl.Builder typeBuilder = VehicleTypeImpl.Builder.newInstance("vehicle-type").addCapacityDimension(0, 23); - typeBuilder.setCostPerDistance(1.0); - VehicleTypeImpl bigType = typeBuilder.build(); - - VehicleImpl.Builder vehicleBuilder = VehicleImpl.Builder.newInstance("vehicle"); - vehicleBuilder.setStartLocation(Location.newInstance("1")); - vehicleBuilder.setType(bigType); - VehicleImpl bigVehicle = vehicleBuilder.build(); - - /* - * start building the problem - */ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - vrpBuilder.setFleetSize(FleetSize.INFINITE); - vrpBuilder.addVehicle(bigVehicle); - - /* - * create cost-matrix - */ - VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(true); - /* - * read demand quantities - */ - readDemandQuantitiesAsServices(vrpBuilder); - readDistances(matrixBuilder); - - vrpBuilder.setRoutingCost(matrixBuilder.build()); - VehicleRoutingProblem vrp = vrpBuilder.build(); - VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp); - vra.setPrematureAlgorithmTermination(new IterationWithoutImprovementTermination(100)); - Collection solutions = vra.searchSolutions(); - - SolutionPrinter.print(vrp, Solutions.bestOf(solutions), Print.VERBOSE); - - assertEquals(397.0,Solutions.bestOf(solutions).getCost(),40.); - assertEquals(2,Solutions.bestOf(solutions).getRoutes().size()); - } + assertEquals(397.0, Solutions.bestOf(solutions).getCost(), 40.); + assertEquals(2, Solutions.bestOf(solutions).getRoutes().size()); + } @Test - public void whenReadingPickups_itShouldCalculateCorrectly(){ + @Category(IntegrationTest.class) + public void whenReadingPickups_itShouldCalculateCorrectly() { /* * create vehicle-type and vehicle @@ -174,12 +177,13 @@ public class RefuseCollection_IT { SolutionPrinter.print(vrp, Solutions.bestOf(solutions), Print.VERBOSE); - assertEquals(397.0,Solutions.bestOf(solutions).getCost(),40.); - assertEquals(2,Solutions.bestOf(solutions).getRoutes().size()); + assertEquals(397.0, Solutions.bestOf(solutions).getCost(), 40.); + assertEquals(2, Solutions.bestOf(solutions).getRoutes().size()); } @Test - public void whenReadingDeliveries_itShouldCalculateCorrectly(){ + @Category(IntegrationTest.class) + public void whenReadingDeliveries_itShouldCalculateCorrectly() { /* * create vehicle-type and vehicle @@ -218,33 +222,33 @@ public class RefuseCollection_IT { SolutionPrinter.print(vrp, Solutions.bestOf(solutions), Print.VERBOSE); - assertEquals(397.0,Solutions.bestOf(solutions).getCost(),40.); - assertEquals(2,Solutions.bestOf(solutions).getRoutes().size()); + assertEquals(397.0, Solutions.bestOf(solutions).getCost(), 40.); + assertEquals(2, Solutions.bestOf(solutions).getRoutes().size()); } - private static void readDemandQuantitiesAsServices(VehicleRoutingProblem.Builder vrpBuilder) { - BufferedReader reader = getBufferedReader("src/test/resources/refuseCollectionExample_Quantities"); - String line; - boolean firstLine = true; - while((line = readLine(reader)) != null){ - if(firstLine) { - firstLine = false; - continue; - } - String[] lineTokens = line.split(","); + private static void readDemandQuantitiesAsServices(VehicleRoutingProblem.Builder vrpBuilder) { + BufferedReader reader = getBufferedReader("src/test/resources/refuseCollectionExample_Quantities"); + String line; + boolean firstLine = true; + while ((line = readLine(reader)) != null) { + if (firstLine) { + firstLine = false; + continue; + } + String[] lineTokens = line.split(","); /* * build service */ - Service service = Service.Builder.newInstance(lineTokens[0]).addSizeDimension(0, Integer.parseInt(lineTokens[1])) - .setLocation(Location.newInstance(lineTokens[0])).build(); + 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); - } - close(reader); - } + vrpBuilder.addJob(service); + } + close(reader); + } private static BufferedReader getBufferedReader(String s) { BufferedReader reader = null; @@ -256,12 +260,12 @@ public class RefuseCollection_IT { return reader; } - private static void readDemandQuantitiesAsPickups(VehicleRoutingProblem.Builder vrpBuilder) { + private static void readDemandQuantitiesAsPickups(VehicleRoutingProblem.Builder vrpBuilder) { BufferedReader reader = getBufferedReader("src/test/resources/refuseCollectionExample_Quantities"); String line; boolean firstLine = true; - while((line = readLine(reader)) != null){ - if(firstLine) { + while ((line = readLine(reader)) != null) { + if (firstLine) { firstLine = false; continue; } @@ -269,8 +273,8 @@ public class RefuseCollection_IT { /* * build service */ - Pickup service = (Pickup) Pickup.Builder.newInstance(lineTokens[0]).addSizeDimension(0, Integer.parseInt(lineTokens[1])) - .setLocation(Location.newInstance(lineTokens[0])).build(); + Pickup service = Pickup.Builder.newInstance(lineTokens[0]).addSizeDimension(0, Integer.parseInt(lineTokens[1])) + .setLocation(Location.newInstance(lineTokens[0])).build(); /* * and add it to problem */ @@ -279,12 +283,12 @@ public class RefuseCollection_IT { close(reader); } - private static void readDemandQuantitiesAsDeliveries(VehicleRoutingProblem.Builder vrpBuilder) { + private static void readDemandQuantitiesAsDeliveries(VehicleRoutingProblem.Builder vrpBuilder) { BufferedReader reader = getBufferedReader("src/test/resources/refuseCollectionExample_Quantities"); String line; boolean firstLine = true; - while((line = readLine(reader)) != null){ - if(firstLine) { + while ((line = readLine(reader)) != null) { + if (firstLine) { firstLine = false; continue; } @@ -293,7 +297,7 @@ public class RefuseCollection_IT { * build service */ Delivery service = (Delivery) Delivery.Builder.newInstance(lineTokens[0]).addSizeDimension(0, Integer.parseInt(lineTokens[1])) - .setLocation(Location.newInstance(lineTokens[0])).build(); + .setLocation(Location.newInstance(lineTokens[0])).build(); /* * and add it to problem */ @@ -302,7 +306,7 @@ public class RefuseCollection_IT { close(reader); } - private static String readLine(BufferedReader reader){ + private static String readLine(BufferedReader reader) { String line = null; try { line = reader.readLine(); @@ -312,29 +316,29 @@ public class RefuseCollection_IT { return line; } - private static void close(Reader reader){ + private static void close(Reader reader) { try { reader.close(); } catch (IOException e) { e.printStackTrace(); } } - - private static void readDistances(Builder matrixBuilder) { - BufferedReader reader = getBufferedReader("src/test/resources/refuseCollectionExample_Distances"); - String line; - boolean firstLine = true; - while((line = readLine(reader)) != null){ - if(firstLine) { - firstLine = false; - continue; - } - String[] lineTokens = line.split(","); - matrixBuilder.addTransportDistance(lineTokens[0],lineTokens[1], Integer.parseInt(lineTokens[2])); - matrixBuilder.addTransportTime(lineTokens[0],lineTokens[1], Integer.parseInt(lineTokens[2])); - } - close(reader); + + private static void readDistances(Builder matrixBuilder) { + BufferedReader reader = getBufferedReader("src/test/resources/refuseCollectionExample_Distances"); + String line; + boolean firstLine = true; + while ((line = readLine(reader)) != null) { + if (firstLine) { + firstLine = false; + continue; + } + String[] lineTokens = line.split(","); + matrixBuilder.addTransportDistance(lineTokens[0], lineTokens[1], Integer.parseInt(lineTokens[2])); + matrixBuilder.addTransportTime(lineTokens[0], lineTokens[1], Integer.parseInt(lineTokens[2])); + } + close(reader); } diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/SearchStrategyManagerTest.java b/jsprit-core/src/test/java/jsprit/core/algorithm/SearchStrategyManagerTest.java index 044558cf..21b4309d 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/SearchStrategyManagerTest.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/SearchStrategyManagerTest.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm; @@ -33,56 +33,55 @@ import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.*; - public class SearchStrategyManagerTest { - @Test - public void StrategyManagerInAction_addingStrategy_IsSuccessful(){ - SearchStrategyManager manager = new SearchStrategyManager(); - SearchStrategy strat1 = mock(SearchStrategy.class); - SearchStrategy strat2 = mock(SearchStrategy.class); + @Test + public void StrategyManagerInAction_addingStrategy_IsSuccessful() { + SearchStrategyManager manager = new SearchStrategyManager(); + SearchStrategy strat1 = mock(SearchStrategy.class); + SearchStrategy strat2 = mock(SearchStrategy.class); when(strat1.getId()).thenReturn("strat1"); when(strat2.getId()).thenReturn("strat2"); - manager.addStrategy(strat1, 0.5); - manager.addStrategy(strat2, 0.5); - assertTrue(true); - } - - @Test(expected=IllegalStateException.class) - public void StrategyManagerInAction_strategyIsNull_throwsException(){ - SearchStrategyManager manager = new SearchStrategyManager(); - manager.addStrategy(null, 1.0); - assertTrue(false); - } - - @Test(expected=IllegalStateException.class) - public void StrategyManagerInAction_probabilityIsLowerThanZero_throwsException(){ - SearchStrategyManager manager = new SearchStrategyManager(); - SearchStrategy strat = mock(SearchStrategy.class); + manager.addStrategy(strat1, 0.5); + manager.addStrategy(strat2, 0.5); + assertTrue(true); + } + + @Test(expected = IllegalStateException.class) + public void StrategyManagerInAction_strategyIsNull_throwsException() { + SearchStrategyManager manager = new SearchStrategyManager(); + manager.addStrategy(null, 1.0); + assertTrue(false); + } + + @Test(expected = IllegalStateException.class) + public void StrategyManagerInAction_probabilityIsLowerThanZero_throwsException() { + SearchStrategyManager manager = new SearchStrategyManager(); + SearchStrategy strat = mock(SearchStrategy.class); when(strat.getId()).thenReturn("strat1"); - manager.addStrategy(strat, -1.0); - assertTrue(false); - } - + manager.addStrategy(strat, -1.0); + assertTrue(false); + } + @Test - public void itShouldReturnStrategy2(){ - SearchStrategyManager manager = new SearchStrategyManager(); - SearchStrategy mockedStrat1 = mock(SearchStrategy.class); - SearchStrategy mockedStrat2 = mock(SearchStrategy.class); + public void itShouldReturnStrategy2() { + SearchStrategyManager manager = new SearchStrategyManager(); + SearchStrategy mockedStrat1 = mock(SearchStrategy.class); + SearchStrategy mockedStrat2 = mock(SearchStrategy.class); when(mockedStrat1.getId()).thenReturn("strat1"); when(mockedStrat2.getId()).thenReturn("strat2"); - manager.addStrategy(mockedStrat1, 0.5); - manager.addStrategy(mockedStrat2, 1.5); + manager.addStrategy(mockedStrat1, 0.5); + manager.addStrategy(mockedStrat2, 1.5); Random mockedRandom = mock(Random.class); manager.setRandom(mockedRandom); stub(mockedRandom.nextDouble()).toReturn(0.25); assertThat(manager.getRandomStrategy(), is(mockedStrat2)); - } + } @Test - public void whenStratWeightChanged_itShouldReturnStrategy1(){ + public void whenStratWeightChanged_itShouldReturnStrategy1() { SearchStrategyManager manager = new SearchStrategyManager(); SearchStrategy mockedStrat1 = mock(SearchStrategy.class); SearchStrategy mockedStrat2 = mock(SearchStrategy.class); @@ -99,13 +98,13 @@ public class SearchStrategyManagerTest { assertThat(manager.getRandomStrategy(), is(mockedStrat2)); - manager.informStrategyWeightChanged("strat2",1.4); + manager.informStrategyWeightChanged("strat2", 1.4); assertThat(manager.getRandomStrategy(), is(mockedStrat1)); } @Test - public void itShouldReturnStrategy1(){ + public void itShouldReturnStrategy1() { SearchStrategyManager manager = new SearchStrategyManager(); SearchStrategy mockedStrat1 = mock(SearchStrategy.class); SearchStrategy mockedStrat2 = mock(SearchStrategy.class); @@ -122,12 +121,12 @@ public class SearchStrategyManagerTest { assertThat(manager.getRandomStrategy(), is(mockedStrat1)); } - - @Test - public void whenRandomDices_0point1_returnsStrategy1(){ - SearchStrategyManager managerUnderTest = new SearchStrategyManager(); - SearchStrategy mockedStrategy1 = mock(SearchStrategy.class); - SearchStrategy mockedStrategy2 = mock(SearchStrategy.class); + + @Test + public void whenRandomDices_0point1_returnsStrategy1() { + SearchStrategyManager managerUnderTest = new SearchStrategyManager(); + SearchStrategy mockedStrategy1 = mock(SearchStrategy.class); + SearchStrategy mockedStrategy2 = mock(SearchStrategy.class); when(mockedStrategy1.getId()).thenReturn("strat1"); when(mockedStrategy2.getId()).thenReturn("strat2"); @@ -136,18 +135,18 @@ public class SearchStrategyManagerTest { managerUnderTest.addStrategy(mockedStrategy2, 0.8); Random mockedRandom = mock(Random.class); - managerUnderTest.setRandom(mockedRandom); - stub(mockedRandom.nextDouble()).toReturn(0.1); - - assertThat(managerUnderTest.getRandomStrategy(), is(mockedStrategy1)); - - } - - @Test - public void whenRandomDices_0point5_returnsStrategy2(){ - SearchStrategyManager managerUnderTest = new SearchStrategyManager(); - SearchStrategy mockedStrategy1 = mock(SearchStrategy.class); - SearchStrategy mockedStrategy2 = mock(SearchStrategy.class); + managerUnderTest.setRandom(mockedRandom); + stub(mockedRandom.nextDouble()).toReturn(0.1); + + assertThat(managerUnderTest.getRandomStrategy(), is(mockedStrategy1)); + + } + + @Test + public void whenRandomDices_0point5_returnsStrategy2() { + SearchStrategyManager managerUnderTest = new SearchStrategyManager(); + SearchStrategy mockedStrategy1 = mock(SearchStrategy.class); + SearchStrategy mockedStrategy2 = mock(SearchStrategy.class); when(mockedStrategy1.getId()).thenReturn("strat1"); when(mockedStrategy2.getId()).thenReturn("strat2"); @@ -156,18 +155,18 @@ public class SearchStrategyManagerTest { managerUnderTest.addStrategy(mockedStrategy2, 0.8); Random mockedRandom = mock(Random.class); - managerUnderTest.setRandom(mockedRandom); - when(mockedRandom.nextDouble()).thenReturn(0.5); - - assertThat(managerUnderTest.getRandomStrategy(), is(mockedStrategy2)); - - } - - @Test - public void whenRandomDices_0point0_returnsStrategy1(){ - SearchStrategyManager managerUnderTest = new SearchStrategyManager(); - SearchStrategy mockedStrategy1 = mock(SearchStrategy.class); - SearchStrategy mockedStrategy2 = mock(SearchStrategy.class); + managerUnderTest.setRandom(mockedRandom); + when(mockedRandom.nextDouble()).thenReturn(0.5); + + assertThat(managerUnderTest.getRandomStrategy(), is(mockedStrategy2)); + + } + + @Test + public void whenRandomDices_0point0_returnsStrategy1() { + SearchStrategyManager managerUnderTest = new SearchStrategyManager(); + SearchStrategy mockedStrategy1 = mock(SearchStrategy.class); + SearchStrategy mockedStrategy2 = mock(SearchStrategy.class); when(mockedStrategy1.getId()).thenReturn("strat1"); when(mockedStrategy2.getId()).thenReturn("strat2"); @@ -176,57 +175,57 @@ public class SearchStrategyManagerTest { managerUnderTest.addStrategy(mockedStrategy2, 0.8); Random mockedRandom = mock(Random.class); - managerUnderTest.setRandom(mockedRandom); - when(mockedRandom.nextDouble()).thenReturn(0.0); - - assertThat(managerUnderTest.getRandomStrategy(), is(mockedStrategy1)); - - } - - @Test(expected=IllegalStateException.class) - public void whenRandomIsNull_throwException(){ - SearchStrategyManager managerUnderTest = new SearchStrategyManager(); - SearchStrategy mockedStrategy1 = mock(SearchStrategy.class); - SearchStrategy mockedStrategy2 = mock(SearchStrategy.class); - managerUnderTest.addStrategy(mockedStrategy1, 0.2); - managerUnderTest.addStrategy(mockedStrategy2, 0.8); + managerUnderTest.setRandom(mockedRandom); + when(mockedRandom.nextDouble()).thenReturn(0.0); + + assertThat(managerUnderTest.getRandomStrategy(), is(mockedStrategy1)); + + } + + @Test(expected = IllegalStateException.class) + public void whenRandomIsNull_throwException() { + SearchStrategyManager managerUnderTest = new SearchStrategyManager(); + SearchStrategy mockedStrategy1 = mock(SearchStrategy.class); + SearchStrategy mockedStrategy2 = mock(SearchStrategy.class); + managerUnderTest.addStrategy(mockedStrategy1, 0.2); + managerUnderTest.addStrategy(mockedStrategy2, 0.8); when(mockedStrategy1.getId()).thenReturn("strat1"); when(mockedStrategy2.getId()).thenReturn("strat2"); Random mockedRandom = null; - managerUnderTest.setRandom(mockedRandom); - managerUnderTest.getRandomStrategy(); - - } + managerUnderTest.setRandom(mockedRandom); + managerUnderTest.getRandomStrategy(); - @Test - public void strategyDrawShouldBeReproducible(){ - RandomNumberGeneration.reset(); - SearchStrategyManager managerUnderTest = new SearchStrategyManager(); - SearchStrategy mockedStrategy1 = new SearchStrategy("strat1" - ,mock(SolutionSelector.class),mock(SolutionAcceptor.class),mock(SolutionCostCalculator.class)); - SearchStrategy mockedStrategy2 = new SearchStrategy("strat2" - ,mock(SolutionSelector.class),mock(SolutionAcceptor.class),mock(SolutionCostCalculator.class)); + } - managerUnderTest.addStrategy(mockedStrategy1, 0.2); - managerUnderTest.addStrategy(mockedStrategy2, 0.8); - List firstRecord = new ArrayList(); - for(int i=0; i<1000;i++){ - firstRecord.add(managerUnderTest.getRandomStrategy().getId()); - } + @Test + public void strategyDrawShouldBeReproducible() { + RandomNumberGeneration.reset(); + SearchStrategyManager managerUnderTest = new SearchStrategyManager(); + SearchStrategy mockedStrategy1 = new SearchStrategy("strat1" + , mock(SolutionSelector.class), mock(SolutionAcceptor.class), mock(SolutionCostCalculator.class)); + SearchStrategy mockedStrategy2 = new SearchStrategy("strat2" + , mock(SolutionSelector.class), mock(SolutionAcceptor.class), mock(SolutionCostCalculator.class)); - RandomNumberGeneration.reset(); - List secondRecord = new ArrayList(); - for(int i=0; i<1000;i++){ - secondRecord.add(managerUnderTest.getRandomStrategy().getId()); - } + managerUnderTest.addStrategy(mockedStrategy1, 0.2); + managerUnderTest.addStrategy(mockedStrategy2, 0.8); + List firstRecord = new ArrayList(); + for (int i = 0; i < 1000; i++) { + firstRecord.add(managerUnderTest.getRandomStrategy().getId()); + } - for(int i=0;i<1000;i++){ - if(!firstRecord.get(i).equals(secondRecord.get(i))){ - Assert.assertFalse(true); - } - } - Assert.assertTrue(true); - } + RandomNumberGeneration.reset(); + List secondRecord = new ArrayList(); + for (int i = 0; i < 1000; i++) { + secondRecord.add(managerUnderTest.getRandomStrategy().getId()); + } + + for (int i = 0; i < 1000; i++) { + if (!firstRecord.get(i).equals(secondRecord.get(i))) { + Assert.assertFalse(true); + } + } + Assert.assertTrue(true); + } } diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/SearchStrategyTest.java b/jsprit-core/src/test/java/jsprit/core/algorithm/SearchStrategyTest.java index e6c1703c..cf22d8da 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/SearchStrategyTest.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/SearchStrategyTest.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm; @@ -33,204 +33,202 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; - - public class SearchStrategyTest { - - @Test(expected=IllegalStateException.class) - public void whenANullModule_IsAdded_throwException(){ - SolutionSelector select = mock(SolutionSelector.class); - SolutionAcceptor accept = mock(SolutionAcceptor.class); - SolutionCostCalculator calc = mock(SolutionCostCalculator.class); - - SearchStrategy strat = new SearchStrategy("strat", select, accept, calc); - strat.addModule(null); - - } - - @Test - public void whenStratRunsWithOneModule_runItOnes(){ - SolutionSelector select = mock(SolutionSelector.class); - SolutionAcceptor accept = mock(SolutionAcceptor.class); - SolutionCostCalculator calc = mock(SolutionCostCalculator.class); - - final VehicleRoutingProblem vrp = mock(VehicleRoutingProblem.class); - final VehicleRoutingProblemSolution newSol = mock(VehicleRoutingProblemSolution.class); - - when(select.selectSolution(null)).thenReturn(newSol); - - final Collection runs = new ArrayList(); - - SearchStrategy strat = new SearchStrategy("strat", select, accept, calc); - SearchStrategyModule mod = new SearchStrategyModule() { - - @Override - public VehicleRoutingProblemSolution runAndGetSolution(VehicleRoutingProblemSolution vrpSolution) { - runs.add(1); - return vrpSolution; - } - @Override - public String getName() { - return null; - } + @Test(expected = IllegalStateException.class) + public void whenANullModule_IsAdded_throwException() { + SolutionSelector select = mock(SolutionSelector.class); + SolutionAcceptor accept = mock(SolutionAcceptor.class); + SolutionCostCalculator calc = mock(SolutionCostCalculator.class); - @Override - public void addModuleListener( - SearchStrategyModuleListener moduleListener) { + SearchStrategy strat = new SearchStrategy("strat", select, accept, calc); + strat.addModule(null); - } - }; - strat.addModule(mod); - strat.run(vrp, null); - - assertEquals(runs.size(), 1); - } - - @Test - public void whenStratRunsWithTwoModule_runItTwice(){ - SolutionSelector select = mock(SolutionSelector.class); - SolutionAcceptor accept = mock(SolutionAcceptor.class); - SolutionCostCalculator calc = mock(SolutionCostCalculator.class); - - final VehicleRoutingProblem vrp = mock(VehicleRoutingProblem.class); - final VehicleRoutingProblemSolution newSol = mock(VehicleRoutingProblemSolution.class); - - when(select.selectSolution(null)).thenReturn(newSol); - - final Collection runs = new ArrayList(); - - SearchStrategy strat = new SearchStrategy("strat", select, accept, calc); - - SearchStrategyModule mod = new SearchStrategyModule() { - - @Override - public VehicleRoutingProblemSolution runAndGetSolution(VehicleRoutingProblemSolution vrpSolution) { - runs.add(1); - return vrpSolution; - } + } - @Override - public String getName() { - return null; - } + @Test + public void whenStratRunsWithOneModule_runItOnes() { + SolutionSelector select = mock(SolutionSelector.class); + SolutionAcceptor accept = mock(SolutionAcceptor.class); + SolutionCostCalculator calc = mock(SolutionCostCalculator.class); - @Override - public void addModuleListener( - SearchStrategyModuleListener moduleListener) { + final VehicleRoutingProblem vrp = mock(VehicleRoutingProblem.class); + final VehicleRoutingProblemSolution newSol = mock(VehicleRoutingProblemSolution.class); - } - }; - SearchStrategyModule mod2 = new SearchStrategyModule() { - - @Override - public VehicleRoutingProblemSolution runAndGetSolution(VehicleRoutingProblemSolution vrpSolution) { - runs.add(1); - return vrpSolution; - } + when(select.selectSolution(null)).thenReturn(newSol); - @Override - public String getName() { - return null; - } + final Collection runs = new ArrayList(); - @Override - public void addModuleListener( - SearchStrategyModuleListener moduleListener) { + SearchStrategy strat = new SearchStrategy("strat", select, accept, calc); + SearchStrategyModule mod = new SearchStrategyModule() { - } - }; - strat.addModule(mod); - strat.addModule(mod2); - strat.run(vrp, null); - - assertEquals(runs.size(), 2); - } - - @Test - public void whenStratRunsWithNModule_runItNTimes(){ - SolutionSelector select = mock(SolutionSelector.class); - SolutionAcceptor accept = mock(SolutionAcceptor.class); - SolutionCostCalculator calc = mock(SolutionCostCalculator.class); - - final VehicleRoutingProblem vrp = mock(VehicleRoutingProblem.class); - final VehicleRoutingProblemSolution newSol = mock(VehicleRoutingProblemSolution.class); - - when(select.selectSolution(null)).thenReturn(newSol); - - int N = new Random().nextInt(1000); - - final Collection runs = new ArrayList(); - - SearchStrategy strat = new SearchStrategy("strat", select, accept, calc); - - for(int i=0;i runs = new ArrayList(); - - SearchStrategy strat = new SearchStrategy("strat", select, accept, calc); - - for(int i=0;i runs = new ArrayList(); + + SearchStrategy strat = new SearchStrategy("strat", select, accept, calc); + + SearchStrategyModule mod = new SearchStrategyModule() { + + @Override + public VehicleRoutingProblemSolution runAndGetSolution(VehicleRoutingProblemSolution vrpSolution) { + runs.add(1); + return vrpSolution; + } + + @Override + public String getName() { + return null; + } + + @Override + public void addModuleListener( + SearchStrategyModuleListener moduleListener) { + + } + }; + SearchStrategyModule mod2 = new SearchStrategyModule() { + + @Override + public VehicleRoutingProblemSolution runAndGetSolution(VehicleRoutingProblemSolution vrpSolution) { + runs.add(1); + return vrpSolution; + } + + @Override + public String getName() { + return null; + } + + @Override + public void addModuleListener( + SearchStrategyModuleListener moduleListener) { + + } + }; + strat.addModule(mod); + strat.addModule(mod2); + strat.run(vrp, null); + + assertEquals(runs.size(), 2); + } + + @Test + public void whenStratRunsWithNModule_runItNTimes() { + SolutionSelector select = mock(SolutionSelector.class); + SolutionAcceptor accept = mock(SolutionAcceptor.class); + SolutionCostCalculator calc = mock(SolutionCostCalculator.class); + + final VehicleRoutingProblem vrp = mock(VehicleRoutingProblem.class); + final VehicleRoutingProblemSolution newSol = mock(VehicleRoutingProblemSolution.class); + + when(select.selectSolution(null)).thenReturn(newSol); + + int N = new Random().nextInt(1000); + + final Collection runs = new ArrayList(); + + SearchStrategy strat = new SearchStrategy("strat", select, accept, calc); + + for (int i = 0; i < N; i++) { + SearchStrategyModule mod = new SearchStrategyModule() { + + @Override + public VehicleRoutingProblemSolution runAndGetSolution(VehicleRoutingProblemSolution vrpSolution) { + runs.add(1); + return vrpSolution; + } + + @Override + public String getName() { + return null; + } + + @Override + public void addModuleListener( + SearchStrategyModuleListener moduleListener) { + + } + }; + strat.addModule(mod); + } + strat.run(vrp, null); + assertEquals(runs.size(), N); + } + + @Test(expected = IllegalStateException.class) + public void whenSelectorDeliversNullSolution_throwException() { + SolutionSelector select = mock(SolutionSelector.class); + SolutionAcceptor accept = mock(SolutionAcceptor.class); + SolutionCostCalculator calc = mock(SolutionCostCalculator.class); + + final VehicleRoutingProblem vrp = mock(VehicleRoutingProblem.class); + + when(select.selectSolution(null)).thenReturn(null); + + int N = new Random().nextInt(1000); + + final Collection runs = new ArrayList(); + + SearchStrategy strat = new SearchStrategy("strat", select, accept, calc); + + for (int i = 0; i < N; i++) { + SearchStrategyModule mod = new SearchStrategyModule() { + + @Override + public VehicleRoutingProblemSolution runAndGetSolution(VehicleRoutingProblemSolution vrpSolution) { + runs.add(1); + return vrpSolution; + } + + @Override + public String getName() { + return null; + } + + @Override + public void addModuleListener( + SearchStrategyModuleListener moduleListener) { + + } + }; + strat.addModule(mod); + } + strat.run(vrp, null); + assertEquals(runs.size(), N); + } - } - }; - strat.addModule(mod); - } - strat.run(vrp, null); - assertEquals(runs.size(), N); - } - } diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/SelectRandomlyTest.java b/jsprit-core/src/test/java/jsprit/core/algorithm/SelectRandomlyTest.java index 38aa54ec..a0fd134b 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/SelectRandomlyTest.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/SelectRandomlyTest.java @@ -9,16 +9,16 @@ import static org.junit.Assert.fail; public class SelectRandomlyTest { - @Test - public void loadAnAlgorithmWithSelectRandomly() { - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml"); - VehicleRoutingProblem vrp = vrpBuilder.build(); - try { - VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/algorithmConfig_selectRandomly.xml"); - } catch (Exception e) { - e.printStackTrace(); - fail("Should be able to load an algorithm that uses : " + e.getMessage()); - } - } + @Test + public void loadAnAlgorithmWithSelectRandomly() { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml"); + VehicleRoutingProblem vrp = vrpBuilder.build(); + try { + VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/algorithmConfig_selectRandomly.xml"); + } catch (Exception e) { + e.printStackTrace(); + fail("Should be able to load an algorithm that uses : " + e.getMessage()); + } + } } diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/state/SolomonSkills_IT.java b/jsprit-core/src/test/java/jsprit/core/algorithm/SolomonSkills_IT.java similarity index 70% rename from jsprit-core/src/test/java/jsprit/core/algorithm/state/SolomonSkills_IT.java rename to jsprit-core/src/test/java/jsprit/core/algorithm/SolomonSkills_IT.java index b0b661ba..e358360d 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/state/SolomonSkills_IT.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/SolomonSkills_IT.java @@ -15,11 +15,11 @@ * License along with this library. If not, see . ******************************************************************************/ -package jsprit.core.algorithm.state; +package jsprit.core.algorithm; -import jsprit.core.algorithm.VehicleRoutingAlgorithm; -import jsprit.core.algorithm.VehicleRoutingAlgorithmBuilder; +import jsprit.core.IntegrationTest; import jsprit.core.algorithm.recreate.NoSolutionFoundException; +import jsprit.core.algorithm.state.StateManager; import jsprit.core.problem.Skills; import jsprit.core.problem.VehicleRoutingProblem; import jsprit.core.problem.constraint.ConstraintManager; @@ -34,6 +34,7 @@ import jsprit.core.problem.vehicle.VehicleType; import jsprit.core.util.Solutions; import jsprit.core.util.TestUtils; import org.junit.Test; +import org.junit.experimental.categories.Category; import java.util.Collection; @@ -45,7 +46,8 @@ import static org.junit.Assert.*; public class SolomonSkills_IT { @Test - public void itShouldMakeCorrectAssignmentAccordingToSkills(){ + @Category(IntegrationTest.class) + public void itShouldMakeCorrectAssignmentAccordingToSkills() { VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); new VrpXMLReader(vrpBuilder).read("src/test/resources/solomon_c101.xml"); VehicleRoutingProblem vrp = vrpBuilder.build(); @@ -55,37 +57,37 @@ public class SolomonSkills_IT { Vehicle solomonVehicle = vrp.getVehicles().iterator().next(); VehicleType newType = solomonVehicle.getType(); VehicleRoutingProblem.Builder skillProblemBuilder = VehicleRoutingProblem.Builder.newInstance(); - for(int i=0;i<6;i++) { - VehicleImpl skill1Vehicle = VehicleImpl.Builder.newInstance("skill1_vehicle_"+i).addSkill("skill1") - .setStartLocation(TestUtils.loc(solomonVehicle.getStartLocation().getId(), solomonVehicle.getStartLocation().getCoordinate())) - .setEarliestStart(solomonVehicle.getEarliestDeparture()) - .setType(newType).build(); - VehicleImpl skill2Vehicle = VehicleImpl.Builder.newInstance("skill2_vehicle_"+i).addSkill("skill2") - .setStartLocation(TestUtils.loc(solomonVehicle.getStartLocation().getId(), solomonVehicle.getStartLocation().getCoordinate())) - .setEarliestStart(solomonVehicle.getEarliestDeparture()) - .setType(newType).build(); + for (int i = 0; i < 6; i++) { + VehicleImpl skill1Vehicle = VehicleImpl.Builder.newInstance("skill1_vehicle_" + i).addSkill("skill1") + .setStartLocation(TestUtils.loc(solomonVehicle.getStartLocation().getId(), solomonVehicle.getStartLocation().getCoordinate())) + .setEarliestStart(solomonVehicle.getEarliestDeparture()) + .setType(newType).build(); + VehicleImpl skill2Vehicle = VehicleImpl.Builder.newInstance("skill2_vehicle_" + i).addSkill("skill2") + .setStartLocation(TestUtils.loc(solomonVehicle.getStartLocation().getId(), solomonVehicle.getStartLocation().getCoordinate())) + .setEarliestStart(solomonVehicle.getEarliestDeparture()) + .setType(newType).build(); skillProblemBuilder.addVehicle(skill1Vehicle).addVehicle(skill2Vehicle); } - for(Job job : vrp.getJobs().values()){ + for (Job job : vrp.getJobs().values()) { Service service = (Service) job; Service.Builder skillServiceBuilder = Service.Builder.newInstance(service.getId()).setServiceTime(service.getServiceDuration()) - .setLocation(TestUtils.loc(service.getLocation().getId(), service.getLocation().getCoordinate())).setTimeWindow(service.getTimeWindow()) - .addSizeDimension(0, service.getSize().get(0)); - if(service.getLocation().getCoordinate().getY()<50) skillServiceBuilder.addRequiredSkill("skill2"); + .setLocation(TestUtils.loc(service.getLocation().getId(), service.getLocation().getCoordinate())).setTimeWindow(service.getTimeWindow()) + .addSizeDimension(0, service.getSize().get(0)); + if (service.getLocation().getCoordinate().getY() < 50) skillServiceBuilder.addRequiredSkill("skill2"); else skillServiceBuilder.addRequiredSkill("skill1"); skillProblemBuilder.addJob(skillServiceBuilder.build()); } skillProblemBuilder.setFleetSize(VehicleRoutingProblem.FleetSize.FINITE); VehicleRoutingProblem skillProblem = skillProblemBuilder.build(); - VehicleRoutingAlgorithmBuilder vraBuilder = new VehicleRoutingAlgorithmBuilder(skillProblem,"src/test/resources/algorithmConfig.xml"); + VehicleRoutingAlgorithmBuilder vraBuilder = new VehicleRoutingAlgorithmBuilder(skillProblem, "src/test/resources/algorithmConfig.xml"); vraBuilder.addCoreConstraints(); vraBuilder.addDefaultCostCalculators(); StateManager stateManager = new StateManager(skillProblem); stateManager.updateSkillStates(); - ConstraintManager constraintManager = new ConstraintManager(skillProblem,stateManager); + ConstraintManager constraintManager = new ConstraintManager(skillProblem, stateManager); constraintManager.addSkillsConstraint(); VehicleRoutingAlgorithm vra = vraBuilder.build(); @@ -95,19 +97,18 @@ public class SolomonSkills_IT { Collection solutions = vra.searchSolutions(); VehicleRoutingProblemSolution solution = Solutions.bestOf(solutions); assertEquals(828.94, solution.getCost(), 0.01); - for(VehicleRoute route : solution.getRoutes()){ + for (VehicleRoute route : solution.getRoutes()) { Skills vehicleSkill = route.getVehicle().getSkills(); - for(Job job : route.getTourActivities().getJobs()){ - for(String skill : job.getRequiredSkills().values()){ - if(!vehicleSkill.containsSkill(skill)){ + for (Job job : route.getTourActivities().getJobs()) { + for (String skill : job.getRequiredSkills().values()) { + if (!vehicleSkill.containsSkill(skill)) { assertFalse(true); } } } } assertTrue(true); - } - catch (NoSolutionFoundException e){ + } catch (NoSolutionFoundException e) { System.out.println(e.toString()); assertFalse(true); } diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/state/Solomon_IT.java b/jsprit-core/src/test/java/jsprit/core/algorithm/Solomon_IT.java similarity index 55% rename from jsprit-core/src/test/java/jsprit/core/algorithm/state/Solomon_IT.java rename to jsprit-core/src/test/java/jsprit/core/algorithm/Solomon_IT.java index 23918b3f..39b24daa 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/state/Solomon_IT.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/Solomon_IT.java @@ -1,12 +1,13 @@ -package jsprit.core.algorithm.state; +package jsprit.core.algorithm; -import jsprit.core.algorithm.VehicleRoutingAlgorithm; -import jsprit.core.algorithm.io.VehicleRoutingAlgorithms; +import jsprit.core.IntegrationTest; +import jsprit.core.algorithm.box.Jsprit; import jsprit.core.problem.VehicleRoutingProblem; import jsprit.core.problem.io.VrpXMLReader; import jsprit.core.problem.solution.VehicleRoutingProblemSolution; import jsprit.core.util.Solutions; import org.junit.Test; +import org.junit.experimental.categories.Category; import java.util.Collection; @@ -18,15 +19,20 @@ import static org.junit.Assert.assertEquals; public class Solomon_IT { @Test - public void itShouldFindTheBestKnownSolution(){ + @Category(IntegrationTest.class) + public void itShouldFindTheBestKnownSolution() { VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); new VrpXMLReader(vrpBuilder).read("src/test/resources/solomon_c101.xml"); VehicleRoutingProblem vrp = vrpBuilder.build(); - VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp,"src/test/resources/algorithmConfig.xml"); - vra.setMaxIterations(500); + VehicleRoutingAlgorithm vra = Jsprit.Builder.newInstance(vrp) +// .setProperty(Jsprit.Parameter.THREADS,"3") +// .setProperty(Jsprit.Parameter.FAST_REGRET,"true") + .buildAlgorithm(); +// VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/algorithmConfig.xml"); + vra.setMaxIterations(2000); Collection solutions = vra.searchSolutions(); - assertEquals(828.94, Solutions.bestOf(solutions).getCost(),0.01); + assertEquals(828.94, Solutions.bestOf(solutions).getCost(), 0.01); } } diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/UnassignedJobListTest.java b/jsprit-core/src/test/java/jsprit/core/algorithm/UnassignedJobListTest.java index 6fafc90b..a0a452d8 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/UnassignedJobListTest.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/UnassignedJobListTest.java @@ -17,7 +17,7 @@ import static org.junit.Assert.assertTrue; public class UnassignedJobListTest { @Test - public void job2ShouldBeInBadJobList_dueToTimeWindow(){ + public void job2ShouldBeInBadJobList_dueToTimeWindow() { VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); builder.addVehicle(VehicleImpl.Builder.newInstance("v1").setEarliestStart(0).setLatestArrival(12).setStartLocation(Location.newInstance(1, 1)).build()); Service job1 = Service.Builder.newInstance("job1").setLocation(Location.newInstance(0, 0)).setTimeWindow(TimeWindow.newInstance(0, 12)).setServiceTime(1).build(); @@ -36,12 +36,12 @@ public class UnassignedJobListTest { } @Test - public void job2ShouldBeInBadJobList_dueToSize(){ + public void job2ShouldBeInBadJobList_dueToSize() { VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); builder.addVehicle(VehicleImpl.Builder.newInstance("v1").setEarliestStart(0).setLatestArrival(12).setStartLocation(Location.newInstance(1, 1)).build()); Service job1 = Service.Builder.newInstance("job1").setLocation(Location.newInstance(0, 0)).setTimeWindow(TimeWindow.newInstance(0, 12)).setServiceTime(1).build(); builder.addJob(job1); - Service job2 = Service.Builder.newInstance("job2").setLocation(Location.newInstance(2, 2)).addSizeDimension(0,10).setTimeWindow(TimeWindow.newInstance(0, 12)).setServiceTime(1).build(); + Service job2 = Service.Builder.newInstance("job2").setLocation(Location.newInstance(2, 2)).addSizeDimension(0, 10).setTimeWindow(TimeWindow.newInstance(0, 12)).setServiceTime(1).build(); builder.addJob(job2); VehicleRoutingProblem vrp = builder.build(); diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/VariableDepartureAndWaitingTime_IT.java b/jsprit-core/src/test/java/jsprit/core/algorithm/VariableDepartureAndWaitingTime_IT.java new file mode 100644 index 00000000..6d94565c --- /dev/null +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/VariableDepartureAndWaitingTime_IT.java @@ -0,0 +1,111 @@ +package jsprit.core.algorithm; + +import jsprit.core.IntegrationTest; +import jsprit.core.algorithm.box.Jsprit; +import jsprit.core.algorithm.state.StateManager; +import jsprit.core.analysis.SolutionAnalyser; +import jsprit.core.problem.Location; +import jsprit.core.problem.VehicleRoutingProblem; +import jsprit.core.problem.constraint.ConstraintManager; +import jsprit.core.problem.cost.TransportDistance; +import jsprit.core.problem.cost.VehicleRoutingActivityCosts; +import jsprit.core.problem.driver.Driver; +import jsprit.core.problem.job.Service; +import jsprit.core.problem.solution.SolutionCostCalculator; +import jsprit.core.problem.solution.VehicleRoutingProblemSolution; +import jsprit.core.problem.solution.route.activity.TimeWindow; +import jsprit.core.problem.solution.route.activity.TourActivity; +import jsprit.core.problem.vehicle.Vehicle; +import jsprit.core.problem.vehicle.VehicleImpl; +import jsprit.core.util.CostFactory; +import jsprit.core.util.Solutions; +import junit.framework.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +/** + * Created by schroeder on 22/07/15. + */ +public class VariableDepartureAndWaitingTime_IT { + + static interface AlgorithmFactory { + VehicleRoutingAlgorithm createAlgorithm(VehicleRoutingProblem vrp); + } + + VehicleRoutingActivityCosts activityCosts; + + AlgorithmFactory algorithmFactory; + + @Before + public void doBefore() { + activityCosts = new VehicleRoutingActivityCosts() { + + @Override + public double getActivityCost(TourActivity tourAct, double arrivalTime, Driver driver, Vehicle vehicle) { + return vehicle.getType().getVehicleCostParams().perWaitingTimeUnit * Math.max(0, tourAct.getTheoreticalEarliestOperationStartTime() - arrivalTime); + } + + }; + algorithmFactory = new AlgorithmFactory() { + @Override + public VehicleRoutingAlgorithm createAlgorithm(final VehicleRoutingProblem vrp) { + StateManager stateManager = new StateManager(vrp); + ConstraintManager constraintManager = new ConstraintManager(vrp, stateManager); + + return Jsprit.Builder.newInstance(vrp) + .addCoreStateAndConstraintStuff(true) + .setStateAndConstraintManager(stateManager, constraintManager) + .setObjectiveFunction(new SolutionCostCalculator() { + @Override + public double getCosts(VehicleRoutingProblemSolution solution) { + SolutionAnalyser sa = new SolutionAnalyser(vrp, solution, new TransportDistance() { + @Override + public double getDistance(Location from, Location to) { + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); + } + }); + return sa.getWaitingTime() + sa.getDistance(); + } + }) + .buildAlgorithm(); + } + }; + } + + @Test + @Category(IntegrationTest.class) + public void plainSetupShouldWork() { + VehicleImpl v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0, 0)).build(); + Service s1 = Service.Builder.newInstance("s1").setLocation(Location.newInstance(10, 0)).build(); + Service s2 = Service.Builder.newInstance("s2").setLocation(Location.newInstance(20, 0)).build(); + VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance() + .addJob(s1).addJob(s2).addVehicle(v) + .setFleetSize(VehicleRoutingProblem.FleetSize.FINITE) + .setRoutingCost(CostFactory.createManhattanCosts()) + .setActivityCosts(activityCosts) + .build(); + VehicleRoutingAlgorithm vra = algorithmFactory.createAlgorithm(vrp); + VehicleRoutingProblemSolution solution = Solutions.bestOf(vra.searchSolutions()); + Assert.assertEquals(40., solution.getCost()); + } + + @Test + @Category(IntegrationTest.class) + public void withTimeWindowsShouldWork() { + VehicleImpl v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0, 0)).build(); + Service s1 = Service.Builder.newInstance("s1").setTimeWindow(TimeWindow.newInstance(1010, 1100)).setLocation(Location.newInstance(10, 0)).build(); + Service s2 = Service.Builder.newInstance("s2").setTimeWindow(TimeWindow.newInstance(1020, 1100)).setLocation(Location.newInstance(20, 0)).build(); + final VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance() + .addJob(s1).addJob(s2).addVehicle(v) + .setFleetSize(VehicleRoutingProblem.FleetSize.FINITE) + .setRoutingCost(CostFactory.createManhattanCosts()) + .setActivityCosts(activityCosts) + .build(); + VehicleRoutingAlgorithm vra = algorithmFactory.createAlgorithm(vrp); + VehicleRoutingProblemSolution solution = Solutions.bestOf(vra.searchSolutions()); + Assert.assertEquals(40. + 1000., solution.getCost()); + } + + +} diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/VehicleRoutingAlgorithmTest.java b/jsprit-core/src/test/java/jsprit/core/algorithm/VehicleRoutingAlgorithmTest.java index b8462332..5f0df33a 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/VehicleRoutingAlgorithmTest.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/VehicleRoutingAlgorithmTest.java @@ -31,96 +31,71 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; public class VehicleRoutingAlgorithmTest { - - @Test - public void whenSettingIterations_itIsSetCorrectly(){ - VehicleRoutingAlgorithm algorithm = new VehicleRoutingAlgorithm(mock(VehicleRoutingProblem.class), - mock(SearchStrategyManager.class)); - algorithm.setMaxIterations(50); - assertEquals(50,algorithm.getMaxIterations()); - } @Test - public void whenSettingIterationsWithMaxIterations_itIsSetCorrectly(){ + public void whenSettingIterations_itIsSetCorrectly() { VehicleRoutingAlgorithm algorithm = new VehicleRoutingAlgorithm(mock(VehicleRoutingProblem.class), - mock(SearchStrategyManager.class)); + mock(SearchStrategyManager.class)); algorithm.setMaxIterations(50); - assertEquals(50,algorithm.getMaxIterations()); + assertEquals(50, algorithm.getMaxIterations()); } - - private static class CountIterations implements IterationStartsListener { - - private int countIterations = 0; - - @Override - public void informIterationStarts(int i, VehicleRoutingProblem problem,Collection solutions) { - countIterations++; - } - - public int getCountIterations() { - return countIterations; - } - - } @Test - public void whenSettingIterationsWithMaxIterations_iterAreExecutedCorrectly(){ + public void whenSettingIterationsWithMaxIterations_itIsSetCorrectly() { + VehicleRoutingAlgorithm algorithm = new VehicleRoutingAlgorithm(mock(VehicleRoutingProblem.class), + mock(SearchStrategyManager.class)); + algorithm.setMaxIterations(50); + assertEquals(50, algorithm.getMaxIterations()); + } + + private static class CountIterations implements IterationStartsListener { + + private int countIterations = 0; + + @Override + public void informIterationStarts(int i, VehicleRoutingProblem problem, Collection solutions) { + countIterations++; + } + + public int getCountIterations() { + return countIterations; + } + + } + + @Test + public void whenSettingIterationsWithMaxIterations_iterAreExecutedCorrectly() { SearchStrategyManager stratManager = mock(SearchStrategyManager.class); VehicleRoutingAlgorithm algorithm = new VehicleRoutingAlgorithm(mock(VehicleRoutingProblem.class), - stratManager); + stratManager); when(stratManager.getRandomStrategy()).thenReturn(mock(SearchStrategy.class)); when(stratManager.getProbabilities()).thenReturn(Arrays.asList(1.0)); algorithm.setMaxIterations(1000); CountIterations counter = new CountIterations(); algorithm.addListener(counter); algorithm.searchSolutions(); - assertEquals(1000,counter.getCountIterations()); + assertEquals(1000, counter.getCountIterations()); } - @Test - public void whenSettingIterations_iterAreExecutedCorrectly(){ - SearchStrategyManager stratManager = mock(SearchStrategyManager.class); - VehicleRoutingAlgorithm algorithm = new VehicleRoutingAlgorithm(mock(VehicleRoutingProblem.class), - stratManager); - when(stratManager.getRandomStrategy()).thenReturn(mock(SearchStrategy.class)); - when(stratManager.getProbabilities()).thenReturn(Arrays.asList(1.0)); - algorithm.setMaxIterations(1000); - CountIterations counter = new CountIterations(); - algorithm.addListener(counter); - algorithm.searchSolutions(); - assertEquals(1000,counter.getCountIterations()); - } - - @Test - public void whenSettingPrematureTermination_itIsExecutedCorrectly(){ - SearchStrategyManager stratManager = mock(SearchStrategyManager.class); - VehicleRoutingAlgorithm algorithm = new VehicleRoutingAlgorithm(mock(VehicleRoutingProblem.class), - stratManager); - when(stratManager.getRandomStrategy()).thenReturn(mock(SearchStrategy.class)); - when(stratManager.getProbabilities()).thenReturn(Arrays.asList(1.0)); - algorithm.setMaxIterations(1000); - PrematureAlgorithmTermination termination = new PrematureAlgorithmTermination() { - - private int nuOfIterations = 1; - - @Override - public boolean isPrematureBreak(DiscoveredSolution discoveredSolution) { - if(nuOfIterations == 50) return true; - nuOfIterations++; - return false; - } - }; - CountIterations counter = new CountIterations(); - algorithm.addListener(counter); - algorithm.setPrematureAlgorithmTermination(termination); - algorithm.searchSolutions(); - assertEquals(50,counter.getCountIterations()); - } + @Test + public void whenSettingIterations_iterAreExecutedCorrectly() { + SearchStrategyManager stratManager = mock(SearchStrategyManager.class); + VehicleRoutingAlgorithm algorithm = new VehicleRoutingAlgorithm(mock(VehicleRoutingProblem.class), + stratManager); + when(stratManager.getRandomStrategy()).thenReturn(mock(SearchStrategy.class)); + when(stratManager.getProbabilities()).thenReturn(Arrays.asList(1.0)); + algorithm.setMaxIterations(1000); + CountIterations counter = new CountIterations(); + algorithm.addListener(counter); + algorithm.searchSolutions(); + assertEquals(1000, counter.getCountIterations()); + } @Test - public void whenAddingPrematureTermination_itIsExecutedCorrectly(){ + public void whenSettingPrematureTermination_itIsExecutedCorrectly() { SearchStrategyManager stratManager = mock(SearchStrategyManager.class); - VehicleRoutingAlgorithm algorithm = new VehicleRoutingAlgorithm(mock(VehicleRoutingProblem.class),stratManager); + VehicleRoutingAlgorithm algorithm = new VehicleRoutingAlgorithm(mock(VehicleRoutingProblem.class), + stratManager); when(stratManager.getRandomStrategy()).thenReturn(mock(SearchStrategy.class)); when(stratManager.getProbabilities()).thenReturn(Arrays.asList(1.0)); algorithm.setMaxIterations(1000); @@ -130,7 +105,32 @@ public class VehicleRoutingAlgorithmTest { @Override public boolean isPrematureBreak(DiscoveredSolution discoveredSolution) { - if(nuOfIterations == 50) return true; + if (nuOfIterations == 50) return true; + nuOfIterations++; + return false; + } + }; + CountIterations counter = new CountIterations(); + algorithm.addListener(counter); + algorithm.setPrematureAlgorithmTermination(termination); + algorithm.searchSolutions(); + assertEquals(50, counter.getCountIterations()); + } + + @Test + public void whenAddingPrematureTermination_itIsExecutedCorrectly() { + SearchStrategyManager stratManager = mock(SearchStrategyManager.class); + VehicleRoutingAlgorithm algorithm = new VehicleRoutingAlgorithm(mock(VehicleRoutingProblem.class), stratManager); + when(stratManager.getRandomStrategy()).thenReturn(mock(SearchStrategy.class)); + when(stratManager.getProbabilities()).thenReturn(Arrays.asList(1.0)); + algorithm.setMaxIterations(1000); + PrematureAlgorithmTermination termination = new PrematureAlgorithmTermination() { + + private int nuOfIterations = 1; + + @Override + public boolean isPrematureBreak(DiscoveredSolution discoveredSolution) { + if (nuOfIterations == 50) return true; nuOfIterations++; return false; } @@ -140,13 +140,13 @@ public class VehicleRoutingAlgorithmTest { algorithm.addListener(counter); algorithm.addTerminationCriterion(termination); algorithm.searchSolutions(); - assertEquals(50,counter.getCountIterations()); + assertEquals(50, counter.getCountIterations()); } @Test - public void whenAddingPrematureTwoTerminationCriteria_itIsExecutedCorrectly(){ + public void whenAddingPrematureTwoTerminationCriteria_itIsExecutedCorrectly() { SearchStrategyManager stratManager = mock(SearchStrategyManager.class); - VehicleRoutingAlgorithm algorithm = new VehicleRoutingAlgorithm(mock(VehicleRoutingProblem.class),stratManager); + VehicleRoutingAlgorithm algorithm = new VehicleRoutingAlgorithm(mock(VehicleRoutingProblem.class), stratManager); when(stratManager.getRandomStrategy()).thenReturn(mock(SearchStrategy.class)); when(stratManager.getProbabilities()).thenReturn(Arrays.asList(1.0)); algorithm.setMaxIterations(1000); @@ -156,7 +156,7 @@ public class VehicleRoutingAlgorithmTest { @Override public boolean isPrematureBreak(DiscoveredSolution discoveredSolution) { - if(nuOfIterations == 50) return true; + if (nuOfIterations == 50) return true; nuOfIterations++; return false; } @@ -168,7 +168,7 @@ public class VehicleRoutingAlgorithmTest { @Override public boolean isPrematureBreak(DiscoveredSolution discoveredSolution) { - if(nuOfIterations == 25) return true; + if (nuOfIterations == 25) return true; nuOfIterations++; return false; } @@ -179,7 +179,7 @@ public class VehicleRoutingAlgorithmTest { algorithm.addTerminationCriterion(termination); algorithm.addTerminationCriterion(termination2); algorithm.searchSolutions(); - assertEquals(25,counter.getCountIterations()); + assertEquals(25, counter.getCountIterations()); } } diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/acceptor/AcceptNewRemoveWorstTest.java b/jsprit-core/src/test/java/jsprit/core/algorithm/acceptor/AcceptNewRemoveWorstTest.java index 8e3b5df5..871d10c4 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/acceptor/AcceptNewRemoveWorstTest.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/acceptor/AcceptNewRemoveWorstTest.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.acceptor; @@ -29,28 +29,26 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; - - public class AcceptNewRemoveWorstTest { - - @Test - public void whenHavingNewSolAndLimitedMemory_removeWorstAndAddNew(){ - - VehicleRoutingProblemSolution sol1 = mock(VehicleRoutingProblemSolution.class); - VehicleRoutingProblemSolution sol2 = mock(VehicleRoutingProblemSolution.class); - when(sol1.getCost()).thenReturn(1.0); - when(sol2.getCost()).thenReturn(2.0); - - List solList = new ArrayList(); - solList.add(sol1); - solList.add(sol2); - - VehicleRoutingProblemSolution sol3 = mock(VehicleRoutingProblemSolution.class); - - new GreedyAcceptance(2).acceptSolution(solList, sol3); - - assertEquals(2,solList.size()); - assertThat(sol3,is(solList.get(1))); - } + + @Test + public void whenHavingNewSolAndLimitedMemory_removeWorstAndAddNew() { + + VehicleRoutingProblemSolution sol1 = mock(VehicleRoutingProblemSolution.class); + VehicleRoutingProblemSolution sol2 = mock(VehicleRoutingProblemSolution.class); + when(sol1.getCost()).thenReturn(1.0); + when(sol2.getCost()).thenReturn(2.0); + + List solList = new ArrayList(); + solList.add(sol1); + solList.add(sol2); + + VehicleRoutingProblemSolution sol3 = mock(VehicleRoutingProblemSolution.class); + + new GreedyAcceptance(2).acceptSolution(solList, sol3); + + assertEquals(2, solList.size()); + assertThat(sol3, is(solList.get(1))); + } } diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/acceptor/SchrimpfAcceptanceTest.java b/jsprit-core/src/test/java/jsprit/core/algorithm/acceptor/SchrimpfAcceptanceTest.java index 9305d5e0..b82df7d0 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/acceptor/SchrimpfAcceptanceTest.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/acceptor/SchrimpfAcceptanceTest.java @@ -32,121 +32,120 @@ import static org.mockito.Mockito.when; public class SchrimpfAcceptanceTest { - protected SchrimpfAcceptance schrimpfAcceptance; - protected Collection memory; + protected SchrimpfAcceptance schrimpfAcceptance; + protected Collection memory; - protected static VehicleRoutingProblemSolution createSolutionWithCost(double cost) { - return when(mock(VehicleRoutingProblemSolution.class).getCost()).thenReturn(cost).getMock(); - } + protected static VehicleRoutingProblemSolution createSolutionWithCost(double cost) { + return when(mock(VehicleRoutingProblemSolution.class).getCost()).thenReturn(cost).getMock(); + } - @SuppressWarnings("deprecation") - @Before - public void setup() { - schrimpfAcceptance = new SchrimpfAcceptance(1, 0.3); - // we skip the warmup, but still want to test that the initialThreshold is set - schrimpfAcceptance.setInitialThreshold(0.0); - // create empty memory with an initial capacity of 1 - memory = new ArrayList(1); - // insert the initial (worst) solution, will be accepted anyway since its the first in the memory - assertTrue("Solution (initial cost = 2.0) should be accepted since the memory is empty", schrimpfAcceptance.acceptSolution(memory, createSolutionWithCost(2.0))); - } + @SuppressWarnings("deprecation") + @Before + public void setup() { + schrimpfAcceptance = new SchrimpfAcceptance(1, 0.3); + // we skip the warmup, but still want to test that the initialThreshold is set + schrimpfAcceptance.setInitialThreshold(0.0); + // create empty memory with an initial capacity of 1 + memory = new ArrayList(1); + // insert the initial (worst) solution, will be accepted anyway since its the first in the memory + assertTrue("Solution (initial cost = 2.0) should be accepted since the memory is empty", schrimpfAcceptance.acceptSolution(memory, createSolutionWithCost(2.0))); + } - @Test - public void respectsTheZeroThreshold_usingWorstCostSolution() { - assertFalse("Worst cost solution (2.1 > 2.0) should not be accepted", schrimpfAcceptance.acceptSolution(memory, createSolutionWithCost(2.1))); - } + @Test + public void respectsTheZeroThreshold_usingWorstCostSolution() { + assertFalse("Worst cost solution (2.1 > 2.0) should not be accepted", schrimpfAcceptance.acceptSolution(memory, createSolutionWithCost(2.1))); + } - @Test - public void respectsTheZeroThreshold_usingBetterCostSolution() { - assertTrue("Better cost solution (1.9 < 2.0) should be accepted", schrimpfAcceptance.acceptSolution(memory, createSolutionWithCost(1.9))); - } + @Test + public void respectsTheZeroThreshold_usingBetterCostSolution() { + assertTrue("Better cost solution (1.9 < 2.0) should be accepted", schrimpfAcceptance.acceptSolution(memory, createSolutionWithCost(1.9))); + } - @Test - public void respectsTheZeroThreshold_usingSameCostSolution() { - assertFalse("Same cost solution (2.0 == 2.0) should not be accepted", schrimpfAcceptance.acceptSolution(memory, createSolutionWithCost(2.0))); - } + @Test + public void respectsTheZeroThreshold_usingSameCostSolution() { + assertFalse("Same cost solution (2.0 == 2.0) should not be accepted", schrimpfAcceptance.acceptSolution(memory, createSolutionWithCost(2.0))); + } - @Test - public void respectsTheNonZeroThreshold_usingWorstCostSolution() { - schrimpfAcceptance.setInitialThreshold(0.5); - /* - * it should be accepted since 2.1 < 2.0 + 0.5 (2.0 is the best solution found so far and 0.5 the ini threshold + @Test + public void respectsTheNonZeroThreshold_usingWorstCostSolution() { + schrimpfAcceptance.setInitialThreshold(0.5); + /* + * it should be accepted since 2.1 < 2.0 + 0.5 (2.0 is the best solution found so far and 0.5 the ini threshold * since the threshold of 0.5 allows new solutions to be <0.5 worse than the current best solution */ - assertTrue("Worst cost solution (2.1 > 2.0) should be accepted", schrimpfAcceptance.acceptSolution(memory, createSolutionWithCost(2.1))); - } + assertTrue("Worst cost solution (2.1 > 2.0) should be accepted", schrimpfAcceptance.acceptSolution(memory, createSolutionWithCost(2.1))); + } - @Test - public void respectsTheNonZeroThreshold_usingBetterCostSolution() { - schrimpfAcceptance.setInitialThreshold(0.5); - assertTrue("Better cost solution (1.0 < 2.0) should be accepted since the better cost bust the threshold", schrimpfAcceptance.acceptSolution(memory, createSolutionWithCost(1.0))); - } + @Test + public void respectsTheNonZeroThreshold_usingBetterCostSolution() { + schrimpfAcceptance.setInitialThreshold(0.5); + assertTrue("Better cost solution (1.0 < 2.0) should be accepted since the better cost bust the threshold", schrimpfAcceptance.acceptSolution(memory, createSolutionWithCost(1.0))); + } + + @Test + public void respectsTheNonZeroThreshold_usingBetterButBelowTheThresholdCostSolution() { + schrimpfAcceptance.setInitialThreshold(0.5); + //new solution can also be in between 2.0 and 2.5, but it is even better than 2.0 --> thus true + assertTrue("Better cost solution (1.9 < 2.0) should not be accepted since the better cost is still below the threshold", schrimpfAcceptance.acceptSolution(memory, createSolutionWithCost(1.9))); + } + + @Test + public void respectsTheNonZeroThreshold_usingSameCostSolution() { + schrimpfAcceptance.setInitialThreshold(0.5); + assertTrue("Same cost solution (2.0 == 2.0) should not be accepted", schrimpfAcceptance.acceptSolution(memory, createSolutionWithCost(2.0))); + } + + @Test + public void whenIniThresholdIsSetAndCurrentIterationIs0_itShouldJustAcceptSolution() { + schrimpfAcceptance.setInitialThreshold(0.5); + schrimpfAcceptance.informIterationStarts(0, mock(VehicleRoutingProblem.class), Collections.emptyList()); + boolean accepted = schrimpfAcceptance.acceptSolution(memory, createSolutionWithCost(2.499999)); + assertTrue(accepted); + } + + @Test + public void whenIniThresholdIsSetAndCurrentIterationIs500_itShouldJustAcceptSolution() { + //1000 is the default totalNuOfIterations + schrimpfAcceptance.setInitialThreshold(0.5); + schrimpfAcceptance.informIterationStarts(500, mock(VehicleRoutingProblem.class), Collections.emptyList()); + //according to the acceptance-function, it should just accept every solution less than 2.0 + 0.15749013123 + //threshold(500) = 0.15749013123 + boolean accepted = schrimpfAcceptance.acceptSolution(memory, createSolutionWithCost(2.15748)); + assertTrue(accepted); + } + + @Test + public void whenIniThresholdIsSetAndCurrentIterationIs500_itShouldJustNotAcceptSolution() { + //1000 is the default totalNuOfIterations + schrimpfAcceptance.setInitialThreshold(0.5); + schrimpfAcceptance.informIterationStarts(500, mock(VehicleRoutingProblem.class), Collections.emptyList()); + //according to the acceptance-function, it should just accept every solution less than 2.0 + 0.15749013123 + //threshold(500) = 0.15749013123 + boolean accepted = schrimpfAcceptance.acceptSolution(memory, createSolutionWithCost(2.1575)); + assertFalse(accepted); + } + + @Test + public void whenIniThresholdIsSetAndCurrentIterationIs1000_itShouldJustAcceptSolution() { + //1000 is the default totalNuOfIterations + schrimpfAcceptance.setInitialThreshold(0.5); + schrimpfAcceptance.informIterationStarts(1000, mock(VehicleRoutingProblem.class), Collections.emptyList()); + //according to the acceptance-function, it should just accept every solution less than 2.0 + 0.04960628287 + //threshold(1000)= 0.04960628287 + boolean accepted = schrimpfAcceptance.acceptSolution(memory, createSolutionWithCost(2.0496)); + assertTrue(accepted); + } + + @Test + public void whenIniThresholdIsSetAndCurrentIterationIs1000_itShouldJustNotAcceptSolution() { + //1000 is the default totalNuOfIterations + schrimpfAcceptance.setInitialThreshold(0.5); + schrimpfAcceptance.informIterationStarts(1000, mock(VehicleRoutingProblem.class), Collections.emptyList()); + //according to the acceptance-function, it should just accept every solution less than 2.0 + 0.04960628287 + //threshold(1000)=0.04960628287 + boolean accepted = schrimpfAcceptance.acceptSolution(memory, createSolutionWithCost(2.0497)); + assertFalse(accepted); + } - @Test - public void respectsTheNonZeroThreshold_usingBetterButBelowTheThresholdCostSolution() { - schrimpfAcceptance.setInitialThreshold(0.5); - //new solution can also be in between 2.0 and 2.5, but it is even better than 2.0 --> thus true - assertTrue("Better cost solution (1.9 < 2.0) should not be accepted since the better cost is still below the threshold", schrimpfAcceptance.acceptSolution(memory, createSolutionWithCost(1.9))); - } - @Test - public void respectsTheNonZeroThreshold_usingSameCostSolution() { - schrimpfAcceptance.setInitialThreshold(0.5); - assertTrue("Same cost solution (2.0 == 2.0) should not be accepted", schrimpfAcceptance.acceptSolution(memory, createSolutionWithCost(2.0))); - } - - @Test - public void whenIniThresholdIsSetAndCurrentIterationIs0_itShouldJustAcceptSolution(){ - schrimpfAcceptance.setInitialThreshold(0.5); - schrimpfAcceptance.informIterationStarts(0, mock(VehicleRoutingProblem.class), Collections.emptyList()); - boolean accepted = schrimpfAcceptance.acceptSolution(memory, createSolutionWithCost(2.499999)); - assertTrue(accepted); - } - - @Test - public void whenIniThresholdIsSetAndCurrentIterationIs500_itShouldJustAcceptSolution(){ - //1000 is the default totalNuOfIterations - schrimpfAcceptance.setInitialThreshold(0.5); - schrimpfAcceptance.informIterationStarts(500, mock(VehicleRoutingProblem.class), Collections.emptyList()); - //according to the acceptance-function, it should just accept every solution less than 2.0 + 0.15749013123 - //threshold(500) = 0.15749013123 - boolean accepted = schrimpfAcceptance.acceptSolution(memory, createSolutionWithCost(2.15748)); - assertTrue(accepted); - } - - @Test - public void whenIniThresholdIsSetAndCurrentIterationIs500_itShouldJustNotAcceptSolution(){ - //1000 is the default totalNuOfIterations - schrimpfAcceptance.setInitialThreshold(0.5); - schrimpfAcceptance.informIterationStarts(500, mock(VehicleRoutingProblem.class), Collections.emptyList()); - //according to the acceptance-function, it should just accept every solution less than 2.0 + 0.15749013123 - //threshold(500) = 0.15749013123 - boolean accepted = schrimpfAcceptance.acceptSolution(memory, createSolutionWithCost(2.1575)); - assertFalse(accepted); - } - - @Test - public void whenIniThresholdIsSetAndCurrentIterationIs1000_itShouldJustAcceptSolution(){ - //1000 is the default totalNuOfIterations - schrimpfAcceptance.setInitialThreshold(0.5); - schrimpfAcceptance.informIterationStarts(1000, mock(VehicleRoutingProblem.class), Collections.emptyList()); - //according to the acceptance-function, it should just accept every solution less than 2.0 + 0.04960628287 - //threshold(1000)= 0.04960628287 - boolean accepted = schrimpfAcceptance.acceptSolution(memory, createSolutionWithCost(2.0496)); - assertTrue(accepted); - } - - @Test - public void whenIniThresholdIsSetAndCurrentIterationIs1000_itShouldJustNotAcceptSolution(){ - //1000 is the default totalNuOfIterations - schrimpfAcceptance.setInitialThreshold(0.5); - schrimpfAcceptance.informIterationStarts(1000, mock(VehicleRoutingProblem.class), Collections.emptyList()); - //according to the acceptance-function, it should just accept every solution less than 2.0 + 0.04960628287 - //threshold(1000)=0.04960628287 - boolean accepted = schrimpfAcceptance.acceptSolution(memory, createSolutionWithCost(2.0497)); - assertFalse(accepted); - } - - - } diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/box/JspritTest.java b/jsprit-core/src/test/java/jsprit/core/algorithm/box/JspritTest.java index 198ac009..b5e6c1cb 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/box/JspritTest.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/box/JspritTest.java @@ -7,17 +7,14 @@ import jsprit.core.algorithm.recreate.InsertionData; import jsprit.core.algorithm.recreate.listener.BeforeJobInsertionListener; import jsprit.core.algorithm.recreate.listener.JobInsertedListener; import jsprit.core.algorithm.ruin.listener.RuinListener; -import jsprit.core.algorithm.termination.VariationCoefficientTermination; import jsprit.core.problem.Location; import jsprit.core.problem.VehicleRoutingProblem; -import jsprit.core.problem.io.VrpXMLReader; import jsprit.core.problem.job.Job; import jsprit.core.problem.job.Service; import jsprit.core.problem.solution.VehicleRoutingProblemSolution; import jsprit.core.problem.solution.route.VehicleRoute; import jsprit.core.problem.vehicle.VehicleImpl; import jsprit.core.util.RandomNumberGeneration; -import jsprit.core.util.Solutions; import junit.framework.Assert; import org.junit.Test; @@ -29,16 +26,14 @@ import java.util.*; public class JspritTest { - - @Test - public void whenRunningJspritWithSingleCustomer_itShouldWork(){ - Service s = Service.Builder.newInstance("s1").setLocation(Location.newInstance(1,1)).build(); - VehicleImpl v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0,0)).build(); + public void whenRunningJspritWithSingleCustomer_itShouldWork() { + Service s = Service.Builder.newInstance("s1").setLocation(Location.newInstance(1, 1)).build(); + VehicleImpl v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0, 0)).build(); VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addVehicle(v).addJob(s).build(); VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp); - vra.setMaxIterations(10000); - final Map counts = new HashMap(); + vra.setMaxIterations(10); + final Map counts = new HashMap(); vra.addListener(new StrategySelectedListener() { @Override @@ -47,104 +42,30 @@ public class JspritTest { } private void count(String strategyId) { - if(!counts.containsKey(strategyId)) counts.put(strategyId,1); - counts.put(strategyId,counts.get(strategyId)+1); + if (!counts.containsKey(strategyId)) counts.put(strategyId, 1); + counts.put(strategyId, counts.get(strategyId) + 1); } }); try { vra.searchSolutions(); Assert.assertTrue(true); - } - catch (Exception e){ + } catch (Exception e) { Assert.assertTrue(false); } } -// @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 counts = new HashMap(); -// vra.addListener(new StrategySelectedListener() { -// -// @Override -// public void informSelectedStrategy(SearchStrategy.DiscoveredSolution discoveredSolution, VehicleRoutingProblem vehicleRoutingProblem, Collection 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 counts = new HashMap(); -// vra.addListener(new StrategySelectedListener() { -// -// @Override -// public void informSelectedStrategy(SearchStrategy.DiscoveredSolution discoveredSolution, VehicleRoutingProblem vehicleRoutingProblem, Collection 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(){ - 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(); + public void whenActivatingStrat_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.RADIAL_BEST,"100.").buildAlgorithm(); - vra.setMaxIterations(5000); - final Map counts = new HashMap(); + .setProperty(Jsprit.Strategy.RADIAL_BEST, "100.").buildAlgorithm(); + vra.setMaxIterations(100); + final Map counts = new HashMap(); vra.addListener(new StrategySelectedListener() { @Override @@ -153,9 +74,9 @@ public class JspritTest { } private void count(String strategyId) { - if(!counts.containsKey(strategyId)) counts.put(strategyId,1); + if (!counts.containsKey(strategyId)) counts.put(strategyId, 1); Integer integer = counts.get(strategyId); - counts.put(strategyId, integer +1); + counts.put(strategyId, integer + 1); } }); @@ -164,16 +85,16 @@ public class JspritTest { } @Test - public void test_v3(){ - Service s = Service.Builder.newInstance("s1").setLocation(Location.newInstance(1,1)).build(); - Service s2 = Service.Builder.newInstance("s2").setLocation(Location.newInstance(1,2)).build(); - Service s3 = Service.Builder.newInstance("s3").setLocation(Location.newInstance(1,2)).build(); + public void whenActivatingStrat_itShouldBeReflectedV2() { + Service s = Service.Builder.newInstance("s1").setLocation(Location.newInstance(1, 1)).build(); + Service s2 = Service.Builder.newInstance("s2").setLocation(Location.newInstance(1, 2)).build(); + Service s3 = Service.Builder.newInstance("s3").setLocation(Location.newInstance(1, 2)).build(); - VehicleImpl v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0,0)).build(); + VehicleImpl v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0, 0)).build(); VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(s3).addVehicle(v).addJob(s2).addJob(s).build(); VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp); - vra.setMaxIterations(5000); - final Map counts = new HashMap(); + vra.setMaxIterations(100); + final Map counts = new HashMap(); vra.addListener(new StrategySelectedListener() { @Override @@ -182,8 +103,8 @@ public class JspritTest { } private void count(String strategyId) { - if(!counts.containsKey(strategyId)) counts.put(strategyId,1); - counts.put(strategyId,counts.get(strategyId)+1); + if (!counts.containsKey(strategyId)) counts.put(strategyId, 1); + counts.put(strategyId, counts.get(strategyId) + 1); } }); @@ -192,17 +113,17 @@ public class JspritTest { } @Test - public void test_v4(){ - Service s = Service.Builder.newInstance("s1").setLocation(Location.newInstance(1,1)).build(); - Service s2 = Service.Builder.newInstance("s2").setLocation(Location.newInstance(1,2)).build(); - Service s3 = Service.Builder.newInstance("s3").setLocation(Location.newInstance(1,2)).build(); - Service s4 = Service.Builder.newInstance("s4").setLocation(Location.newInstance(1,2)).build(); + public void test_v4() { + Service s = Service.Builder.newInstance("s1").setLocation(Location.newInstance(1, 1)).build(); + Service s2 = Service.Builder.newInstance("s2").setLocation(Location.newInstance(1, 2)).build(); + Service s3 = Service.Builder.newInstance("s3").setLocation(Location.newInstance(1, 2)).build(); + Service s4 = Service.Builder.newInstance("s4").setLocation(Location.newInstance(1, 2)).build(); - VehicleImpl v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0,0)).build(); + VehicleImpl v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0, 0)).build(); VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(s4).addJob(s3).addVehicle(v).addJob(s2).addJob(s).build(); VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp); - vra.setMaxIterations(5000); - final Map counts = new HashMap(); + vra.setMaxIterations(100); + final Map counts = new HashMap(); vra.addListener(new StrategySelectedListener() { @Override @@ -211,8 +132,8 @@ public class JspritTest { } private void count(String strategyId) { - if(!counts.containsKey(strategyId)) counts.put(strategyId,1); - counts.put(strategyId,counts.get(strategyId)+1); + if (!counts.containsKey(strategyId)) counts.put(strategyId, 1); + counts.put(strategyId, counts.get(strategyId) + 1); } }); @@ -222,16 +143,16 @@ public class JspritTest { @Test - public void strategyDrawShouldBeReproducible(){ - Service s = Service.Builder.newInstance("s1").setLocation(Location.newInstance(1,1)).build(); - Service s2 = Service.Builder.newInstance("s2").setLocation(Location.newInstance(1,2)).build(); - Service s3 = Service.Builder.newInstance("s3").setLocation(Location.newInstance(1,2)).build(); - Service s4 = Service.Builder.newInstance("s4").setLocation(Location.newInstance(1,2)).build(); + public void strategyDrawShouldBeReproducible() { + Service s = Service.Builder.newInstance("s1").setLocation(Location.newInstance(1, 1)).build(); + Service s2 = Service.Builder.newInstance("s2").setLocation(Location.newInstance(1, 2)).build(); + Service s3 = Service.Builder.newInstance("s3").setLocation(Location.newInstance(1, 2)).build(); + Service s4 = Service.Builder.newInstance("s4").setLocation(Location.newInstance(1, 2)).build(); - VehicleImpl v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0,0)).build(); + VehicleImpl v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0, 0)).build(); VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(s4).addJob(s3).addVehicle(v).addJob(s2).addJob(s).build(); VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp); - vra.setMaxIterations(1000); + vra.setMaxIterations(100); final List firstRecord = new ArrayList(); vra.addListener(new StrategySelectedListener() { @@ -245,7 +166,7 @@ public class JspritTest { RandomNumberGeneration.reset(); VehicleRoutingAlgorithm second = Jsprit.createAlgorithm(vrp); - second.setMaxIterations(1000); + second.setMaxIterations(100); final List secondRecord = new ArrayList(); second.addListener(new StrategySelectedListener() { @@ -257,8 +178,8 @@ public class JspritTest { }); second.searchSolutions(); - for(int i=0;i<1000;i++){ - if(!firstRecord.get(i).equals(secondRecord.get(i))){ + for (int i = 0; i < 100; i++) { + if (!firstRecord.get(i).equals(secondRecord.get(i))) { org.junit.Assert.assertFalse(true); } } @@ -267,16 +188,127 @@ public class JspritTest { } @Test - public void ruinedJobsShouldBeReproducible(){ - Service s = Service.Builder.newInstance("s1").setLocation(Location.newInstance(1,1)).build(); - Service s2 = Service.Builder.newInstance("s2").setLocation(Location.newInstance(1,2)).build(); - Service s3 = Service.Builder.newInstance("s3").setLocation(Location.newInstance(1,2)).build(); - Service s4 = Service.Builder.newInstance("s4").setLocation(Location.newInstance(1,2)).build(); + public void strategyDrawShouldBeReproducibleV2() { + Service s = Service.Builder.newInstance("s1").setLocation(Location.newInstance(1, 1)).build(); + Service s2 = Service.Builder.newInstance("s2").setLocation(Location.newInstance(1, 2)).build(); + Service s3 = Service.Builder.newInstance("s3").setLocation(Location.newInstance(1, 2)).build(); + Service s4 = Service.Builder.newInstance("s4").setLocation(Location.newInstance(1, 2)).build(); - VehicleImpl v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0,0)).build(); + VehicleImpl v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0, 0)).build(); + VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(s4).addJob(s3).addVehicle(v).addJob(s2).addJob(s).build(); + VehicleRoutingAlgorithm vra = Jsprit.Builder.newInstance(vrp).setProperty(Jsprit.Parameter.THREADS, "4").buildAlgorithm(); + vra.setMaxIterations(100); + final List firstRecord = new ArrayList(); + vra.addListener(new StrategySelectedListener() { + + @Override + public void informSelectedStrategy(SearchStrategy.DiscoveredSolution discoveredSolution, VehicleRoutingProblem vehicleRoutingProblem, Collection vehicleRoutingProblemSolutions) { + firstRecord.add(discoveredSolution.getStrategyId()); + } + + }); + vra.searchSolutions(); + + RandomNumberGeneration.reset(); + VehicleRoutingAlgorithm second = Jsprit.Builder.newInstance(vrp).setProperty(Jsprit.Parameter.THREADS, "2").buildAlgorithm(); + second.setMaxIterations(100); + final List secondRecord = new ArrayList(); + second.addListener(new StrategySelectedListener() { + + @Override + public void informSelectedStrategy(SearchStrategy.DiscoveredSolution discoveredSolution, VehicleRoutingProblem vehicleRoutingProblem, Collection vehicleRoutingProblemSolutions) { + secondRecord.add(discoveredSolution.getStrategyId()); + } + + }); + second.searchSolutions(); + + for (int i = 0; i < 100; i++) { + if (!firstRecord.get(i).equals(secondRecord.get(i))) { + org.junit.Assert.assertFalse(true); + } + } + org.junit.Assert.assertTrue(true); + + } + + @Test + public void ruinedJobsShouldBeReproducible() { + Service s = Service.Builder.newInstance("s1").setLocation(Location.newInstance(1, 1)).build(); + Service s2 = Service.Builder.newInstance("s2").setLocation(Location.newInstance(1, 2)).build(); + Service s3 = Service.Builder.newInstance("s3").setLocation(Location.newInstance(1, 2)).build(); + Service s4 = Service.Builder.newInstance("s4").setLocation(Location.newInstance(1, 2)).build(); + + VehicleImpl v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0, 0)).build(); + VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(s4).addJob(s3).addVehicle(v).addJob(s2).addJob(s).build(); + VehicleRoutingAlgorithm vra = Jsprit.Builder.newInstance(vrp) + .setProperty(Jsprit.Strategy.WORST_REGRET, "0.") + .setProperty(Jsprit.Strategy.WORST_BEST, "0.") + .setProperty(Jsprit.Parameter.THREADS, "2").buildAlgorithm(); + vra.setMaxIterations(100); + final List firstRecord = new ArrayList(); + vra.addListener(new RuinListener() { + @Override + public void ruinStarts(Collection routes) { + + } + + @Override + public void ruinEnds(Collection routes, Collection unassignedJobs) { + + } + + @Override + public void removed(Job job, VehicleRoute fromRoute) { + firstRecord.add(job.getId()); + } + }); + vra.searchSolutions(); + + VehicleRoutingAlgorithm second = Jsprit.Builder.newInstance(vrp).setProperty(Jsprit.Parameter.THREADS, "4") + .setProperty(Jsprit.Strategy.WORST_REGRET, "0.") + .setProperty(Jsprit.Strategy.WORST_BEST, "0.") + .buildAlgorithm(); + second.setMaxIterations(100); + final List secondRecord = new ArrayList(); + second.addListener(new RuinListener() { + @Override + public void ruinStarts(Collection routes) { + + } + + @Override + public void ruinEnds(Collection routes, Collection unassignedJobs) { + + } + + @Override + public void removed(Job job, VehicleRoute fromRoute) { + secondRecord.add(job.getId()); + } + }); + second.searchSolutions(); + + Assert.assertEquals(secondRecord.size(), firstRecord.size()); + for (int i = 0; i < firstRecord.size(); i++) { + if (!firstRecord.get(i).equals(secondRecord.get(i))) { + Assert.assertFalse(true); + } + } + Assert.assertTrue(true); + } + + @Test + public void ruinedJobsShouldBeReproducibleV2() { + Service s = Service.Builder.newInstance("s1").setLocation(Location.newInstance(1, 1)).build(); + Service s2 = Service.Builder.newInstance("s2").setLocation(Location.newInstance(1, 2)).build(); + Service s3 = Service.Builder.newInstance("s3").setLocation(Location.newInstance(1, 2)).build(); + Service s4 = Service.Builder.newInstance("s4").setLocation(Location.newInstance(1, 2)).build(); + + VehicleImpl v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0, 0)).build(); VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(s4).addJob(s3).addVehicle(v).addJob(s2).addJob(s).build(); VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp); - vra.setMaxIterations(1000); + vra.setMaxIterations(100); final List firstRecord = new ArrayList(); vra.addListener(new RuinListener() { @Override @@ -297,7 +329,7 @@ public class JspritTest { vra.searchSolutions(); VehicleRoutingAlgorithm second = Jsprit.createAlgorithm(vrp); - second.setMaxIterations(1000); + second.setMaxIterations(100); final List secondRecord = new ArrayList(); second.addListener(new RuinListener() { @Override @@ -317,9 +349,9 @@ public class JspritTest { }); second.searchSolutions(); - Assert.assertEquals(secondRecord.size(),firstRecord.size()); - for(int i=0;i firstRecord = new ArrayList(); - vra.addListener(new RuinListener() { - @Override - public void ruinStarts(Collection routes) { + public void insertionShouldBeReproducible() { + Service s = Service.Builder.newInstance("s1").setLocation(Location.newInstance(1, 1)).build(); + Service s2 = Service.Builder.newInstance("s2").setLocation(Location.newInstance(1, 2)).build(); + Service s3 = Service.Builder.newInstance("s3").setLocation(Location.newInstance(1, 2)).build(); + Service s4 = Service.Builder.newInstance("s4").setLocation(Location.newInstance(1, 2)).build(); - } - - @Override - public void ruinEnds(Collection routes, Collection unassignedJobs) { - - } - - @Override - public void removed(Job job, VehicleRoute fromRoute) { - firstRecord.add(job.getId()); - } - }); - vra.searchSolutions(); - - VehicleRoutingAlgorithm second = Jsprit.createAlgorithm(vrp); - second.setMaxIterations(1000); - final List secondRecord = new ArrayList(); - second.addListener(new RuinListener() { - @Override - public void ruinStarts(Collection routes) { - - } - - @Override - public void ruinEnds(Collection routes, Collection unassignedJobs) { - - } - - @Override - public void removed(Job job, VehicleRoute fromRoute) { - secondRecord.add(job.getId()); - } - }); - second.searchSolutions(); - - Assert.assertEquals(secondRecord.size(),firstRecord.size()); - for(int i=0;i firstRecord = new ArrayList(); vra.addListener(new JobInsertedListener() { @Override @@ -404,7 +380,7 @@ public class JspritTest { vra.searchSolutions(); VehicleRoutingAlgorithm second = Jsprit.createAlgorithm(vrp); - second.setMaxIterations(1000); + second.setMaxIterations(100); final List secondRecord = new ArrayList(); second.addListener(new JobInsertedListener() { @Override @@ -414,9 +390,9 @@ public class JspritTest { }); second.searchSolutions(); - Assert.assertEquals(secondRecord.size(),firstRecord.size()); - for(int i=0;i firstRecord = new ArrayList(); - vra.addListener(new JobInsertedListener() { + final List firstRecordCosts = new ArrayList(); + vra.addListener(new BeforeJobInsertionListener() { @Override - public void informJobInserted(Job job2insert, VehicleRoute inRoute, double additionalCosts, double additionalTime) { - firstRecord.add(job2insert.getId()); + public void informBeforeJobInsertion(Job job, InsertionData data, VehicleRoute route) { + String id = job.getId(); + firstRecordCosts.add(data.getInsertionCost()); + firstRecord.add(id); } }); vra.searchSolutions(); - VehicleRoutingAlgorithm second = Jsprit.createAlgorithm(vrp); - second.setMaxIterations(200); + VehicleRoutingAlgorithm second = Jsprit.Builder.newInstance(vrp) + .setProperty(Jsprit.Strategy.WORST_REGRET, "0.") + .setProperty(Jsprit.Strategy.WORST_BEST, "0.") + .setProperty(Jsprit.Parameter.THREADS, "5").buildAlgorithm(); + second.setMaxIterations(100); final List secondRecord = new ArrayList(); - second.addListener(new JobInsertedListener() { - @Override - public void informJobInserted(Job job2insert, VehicleRoute inRoute, double additionalCosts, double additionalTime) { - secondRecord.add(job2insert.getId()); - } - }); - second.searchSolutions(); - - Assert.assertEquals(secondRecord.size(),firstRecord.size()); - for(int i=0;i firstRecord = new ArrayList(); - vra.addListener(new BeforeJobInsertionListener() { - @Override - public void informBeforeJobInsertion(Job job, InsertionData data, VehicleRoute route) { - firstRecord.add(data.getDeliveryInsertionIndex()); - } - }); - Collection firstSolutions = vra.searchSolutions(); - - VehicleRoutingAlgorithm second = Jsprit.createAlgorithm(vrp); - second.setMaxIterations(200); - final List secondRecord = new ArrayList(); + final List secondRecordCosts = new ArrayList(); second.addListener(new BeforeJobInsertionListener() { @Override public void informBeforeJobInsertion(Job job, InsertionData data, VehicleRoute route) { - secondRecord.add(data.getDeliveryInsertionIndex()); - } - }); - Collection secondSolutions = second.searchSolutions(); - - Assert.assertEquals(secondRecord.size(),firstRecord.size()); - for(int i=0;i firstRecord = new ArrayList(); - vra.addListener(new BeforeJobInsertionListener() { - @Override - public void informBeforeJobInsertion(Job job, InsertionData data, VehicleRoute route) { - firstRecord.add(data.getDeliveryInsertionIndex()); - } - }); - Collection firstSolutions = vra.searchSolutions(); - - VehicleRoutingAlgorithm second = Jsprit.createAlgorithm(vrp); - VariationCoefficientTermination secondTermination = new VariationCoefficientTermination(50, 0.005); - second.setPrematureAlgorithmTermination(secondTermination); - second.addListener(secondTermination); - second.setMaxIterations(1000); - final List secondRecord = new ArrayList(); - second.addListener(new BeforeJobInsertionListener() { - @Override - public void informBeforeJobInsertion(Job job, InsertionData data, VehicleRoute route) { - secondRecord.add(data.getDeliveryInsertionIndex()); - } - }); - Collection secondSolutions = second.searchSolutions(); - - Assert.assertEquals(secondRecord.size(),firstRecord.size()); - for(int i=0;i firstRecord = new ArrayList(); - vra.addListener(new BeforeJobInsertionListener() { - @Override - public void informBeforeJobInsertion(Job job, InsertionData data, VehicleRoute route) { - firstRecord.add(data.getDeliveryInsertionIndex()); - } - }); - Collection firstSolutions = vra.searchSolutions(); - - VehicleRoutingAlgorithm second = Jsprit.createAlgorithm(vrp); - second.setMaxIterations(200); - final List secondRecord = new ArrayList(); - second.addListener(new BeforeJobInsertionListener() { - @Override - public void informBeforeJobInsertion(Job job, InsertionData data, VehicleRoute route) { - secondRecord.add(data.getDeliveryInsertionIndex()); - } - }); - Collection secondSolutions = second.searchSolutions(); - - Assert.assertEquals(secondRecord.size(),firstRecord.size()); - for(int i=0;i firstRecord = new ArrayList(); - vra.addListener(new RuinListener() { - @Override - public void ruinStarts(Collection routes) { - - } - - @Override - public void ruinEnds(Collection routes, Collection unassignedJobs) { - - } - - @Override - public void removed(Job job, VehicleRoute fromRoute) { - firstRecord.add(job.getId()); - } - }); - vra.searchSolutions(); - - VehicleRoutingAlgorithm second = Jsprit.createAlgorithm(vrp); - second.setMaxIterations(200); - final List secondRecord = new ArrayList(); - second.addListener(new RuinListener() { - @Override - public void ruinStarts(Collection routes) { - - } - - @Override - public void ruinEnds(Collection routes, Collection unassignedJobs) { - - } - - @Override - public void removed(Job job, VehicleRoute fromRoute) { secondRecord.add(job.getId()); + secondRecordCosts.add(data.getInsertionCost()); } }); second.searchSolutions(); - Assert.assertEquals(secondRecord.size(),firstRecord.size()); - for(int i=0;i. ******************************************************************************/ package jsprit.core.algorithm.io; @@ -50,27 +50,27 @@ import static org.junit.Assert.assertTrue; public class TestAlgorithmReader { - - AlgorithmConfig config; - - VehicleRoutingProblem vrp; - - Collection solutions; - - @Before - public void doBefore() throws ConfigurationException{ - config = new AlgorithmConfig(); - new AlgorithmConfigXmlReader(config).setSchemaValidation(false).read("src/test/resources/testConfig.xml"); - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - solutions = new ArrayList(); - new VrpXMLReader(vrpBuilder,solutions).read("src/test/resources/finiteVrp.xml"); - vrp = vrpBuilder.build(); - } + + AlgorithmConfig config; + + VehicleRoutingProblem vrp; + + Collection solutions; + + @Before + public void doBefore() throws ConfigurationException { + config = new AlgorithmConfig(); + new AlgorithmConfigXmlReader(config).setSchemaValidation(false).read("src/test/resources/testConfig.xml"); + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + solutions = new ArrayList(); + new VrpXMLReader(vrpBuilder, solutions).read("src/test/resources/finiteVrp.xml"); + vrp = vrpBuilder.build(); + } @Test - public void itShouldReadMaxIterations(){ - VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp,"src/test/resources/algorithmConfigForReaderTest.xml"); - Assert.assertEquals(2000,vra.getMaxIterations()); + public void itShouldReadMaxIterations() { + VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/algorithmConfigForReaderTest.xml"); + Assert.assertEquals(2000, vra.getMaxIterations()); } static class IterationCounter implements IterationEndsListener { @@ -85,207 +85,206 @@ public class TestAlgorithmReader { } @Test - public void whenSettingPrematureBreak_itShouldReadTermination(){ - VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp,"src/test/resources/algorithmConfigForReaderTest2.xml"); + public void whenSettingPrematureBreak_itShouldReadTermination() { + VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/algorithmConfigForReaderTest2.xml"); IterationCounter iCounter = new IterationCounter(); vra.addListener(iCounter); vra.searchSolutions(); - Assert.assertEquals(100,iCounter.iterations); + Assert.assertEquals(100, iCounter.iterations); } @Test - public void itShouldReadTermination(){ - VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp,"src/test/resources/algorithmConfigForReaderTest.xml"); + public void itShouldReadTermination() { + VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/algorithmConfigForReaderTest.xml"); IterationCounter iCounter = new IterationCounter(); vra.addListener(iCounter); vra.searchSolutions(); - Assert.assertEquals(25,iCounter.iterations); + Assert.assertEquals(25, iCounter.iterations); } - - @Test - public void testTypedMap(){ - jsprit.core.algorithm.io.VehicleRoutingAlgorithms.TypedMap typedMap = new jsprit.core.algorithm.io.VehicleRoutingAlgorithms.TypedMap(); - - String acceptorName = "acceptor"; - String acceptorId = "acceptorId"; - - ModKey key = new ModKey(acceptorName,acceptorId); - AcceptorKey accKey = new AcceptorKey(key); - - SolutionAcceptor acceptor = new GreedyAcceptance(1); - - typedMap.put(accKey, acceptor); - - assertEquals(acceptor,typedMap.get(accKey)); - - } - - @Test - public void testTypedMap2(){ - jsprit.core.algorithm.io.VehicleRoutingAlgorithms.TypedMap typedMap = new jsprit.core.algorithm.io.VehicleRoutingAlgorithms.TypedMap(); - - String acceptorName = "acceptor"; - String acceptorId = "acceptorId"; - - String selectorName = "selector"; - String selectorId = "selectorId"; - - ModKey key = new ModKey(acceptorName,acceptorId); - AcceptorKey accKey = new AcceptorKey(key); - SolutionAcceptor acceptor = new GreedyAcceptance(1); - - SelectorKey selKey = new SelectorKey(new ModKey(selectorName,selectorId)); - SolutionSelector selector = new SelectBest(); - - typedMap.put(accKey, acceptor); - typedMap.put(selKey, selector); - - assertEquals(acceptor,typedMap.get(accKey)); - assertEquals(selector, typedMap.get(selKey)); - } - - @Test - public void testTypedMap3(){ - jsprit.core.algorithm.io.VehicleRoutingAlgorithms.TypedMap typedMap = new jsprit.core.algorithm.io.VehicleRoutingAlgorithms.TypedMap(); - - String acceptorName = "acceptor"; - String acceptorId = "acceptorId"; - - String acceptorName2 = "acceptor2"; - String acceptorId2 = "acceptorId2"; - - String selectorName = "selector"; - String selectorId = "selectorId"; - - ModKey key = new ModKey(acceptorName,acceptorId); - AcceptorKey accKey = new AcceptorKey(key); - SolutionAcceptor acceptor = new GreedyAcceptance(1); - - SelectorKey selKey = new SelectorKey(new ModKey(selectorName,selectorId)); - SolutionSelector selector = new SelectBest(); - - AcceptorKey accKey2 = new AcceptorKey(new ModKey(acceptorName2,acceptorId2)); - SolutionAcceptor acceptor2 = new GreedyAcceptance(1); - - typedMap.put(accKey, acceptor); - typedMap.put(selKey, selector); - typedMap.put(accKey2, acceptor2); - - assertEquals(acceptor,typedMap.get(accKey)); - assertEquals(selector, typedMap.get(selKey)); - assertEquals(acceptor2,typedMap.get(accKey2)); - } - - @Test - public void testTypedMap4(){ - jsprit.core.algorithm.io.VehicleRoutingAlgorithms.TypedMap typedMap = new jsprit.core.algorithm.io.VehicleRoutingAlgorithms.TypedMap(); - - String acceptorName = "acceptor"; - String acceptorId = "acceptorId"; - - ModKey key = new ModKey(acceptorName,acceptorId); - RuinStrategyKey accKey = new RuinStrategyKey(key); - RuinStrategy acceptor = new RuinStrategy(){ + @Test + public void testTypedMap() { + jsprit.core.algorithm.io.VehicleRoutingAlgorithms.TypedMap typedMap = new jsprit.core.algorithm.io.VehicleRoutingAlgorithms.TypedMap(); - @Override - public Collection ruin(Collection vehicleRoutes) { - return null; - } + String acceptorName = "acceptor"; + String acceptorId = "acceptorId"; - @Override - public Collection ruin(Collection vehicleRoutes, - Job targetJob, int nOfJobs2BeRemoved) { - return null; - } + ModKey key = new ModKey(acceptorName, acceptorId); + AcceptorKey accKey = new AcceptorKey(key); - @Override - public void addListener(RuinListener ruinListener) { + SolutionAcceptor acceptor = new GreedyAcceptance(1); - } + typedMap.put(accKey, acceptor); - @Override - public void removeListener(RuinListener ruinListener) { + assertEquals(acceptor, typedMap.get(accKey)); - } - - @Override - public Collection getListeners() { - return null; - } - - }; - - StrategyModuleKey moduleKey = new StrategyModuleKey(key); - SearchStrategyModule stratModule = new SearchStrategyModule() { - - @Override - public VehicleRoutingProblemSolution runAndGetSolution(VehicleRoutingProblemSolution vrpSolution) { - return null; - } - - @Override - public String getName() { - return null; - } - - @Override - public void addModuleListener( - SearchStrategyModuleListener moduleListener) { - - } - }; - - typedMap.put(accKey, acceptor); - typedMap.put(moduleKey, stratModule); - typedMap.put(moduleKey, stratModule); - - assertEquals(acceptor,typedMap.get(accKey)); - assertEquals(stratModule, typedMap.get(moduleKey)); - - } - - @Test - public void initialiseConstructionAlgoCorrectly(){ - VehicleRoutingAlgorithms.createAlgorithm(vrp, config); - assertTrue(true); - } - - @Test - public void whenCreatingAlgorithm_nOfStrategiesIsCorrect(){ - VehicleRoutingAlgorithm algo = VehicleRoutingAlgorithms.createAlgorithm(vrp, config); - assertEquals(3, algo.getSearchStrategyManager().getStrategies().size()); - } - - @Test - public void whenCreatingAlgorithm_nOfIterationsIsReadCorrectly(){ - VehicleRoutingAlgorithm algo = VehicleRoutingAlgorithms.createAlgorithm(vrp, config); - assertEquals(10, algo.getMaxIterations()); - } - - @Test - public void whenCreatingAlgorithm_nOfStrategyModulesIsCorrect(){ - VehicleRoutingAlgorithm algo = VehicleRoutingAlgorithms.createAlgorithm(vrp, config); - int nOfModules = 0; - for(SearchStrategy strat : algo.getSearchStrategyManager().getStrategies()){ - nOfModules += strat.getSearchStrategyModules().size(); - } - assertEquals(3, nOfModules); - } + } @Test - public void readerTest_whenReadingAlgoWithSchemaValidation_itReadsCorrectly(){ + public void testTypedMap2() { + jsprit.core.algorithm.io.VehicleRoutingAlgorithms.TypedMap typedMap = new jsprit.core.algorithm.io.VehicleRoutingAlgorithms.TypedMap(); + + String acceptorName = "acceptor"; + String acceptorId = "acceptorId"; + + String selectorName = "selector"; + String selectorId = "selectorId"; + + ModKey key = new ModKey(acceptorName, acceptorId); + AcceptorKey accKey = new AcceptorKey(key); + SolutionAcceptor acceptor = new GreedyAcceptance(1); + + SelectorKey selKey = new SelectorKey(new ModKey(selectorName, selectorId)); + SolutionSelector selector = new SelectBest(); + + typedMap.put(accKey, acceptor); + typedMap.put(selKey, selector); + + assertEquals(acceptor, typedMap.get(accKey)); + assertEquals(selector, typedMap.get(selKey)); + } + + @Test + public void testTypedMap3() { + jsprit.core.algorithm.io.VehicleRoutingAlgorithms.TypedMap typedMap = new jsprit.core.algorithm.io.VehicleRoutingAlgorithms.TypedMap(); + + String acceptorName = "acceptor"; + String acceptorId = "acceptorId"; + + String acceptorName2 = "acceptor2"; + String acceptorId2 = "acceptorId2"; + + String selectorName = "selector"; + String selectorId = "selectorId"; + + ModKey key = new ModKey(acceptorName, acceptorId); + AcceptorKey accKey = new AcceptorKey(key); + SolutionAcceptor acceptor = new GreedyAcceptance(1); + + SelectorKey selKey = new SelectorKey(new ModKey(selectorName, selectorId)); + SolutionSelector selector = new SelectBest(); + + AcceptorKey accKey2 = new AcceptorKey(new ModKey(acceptorName2, acceptorId2)); + SolutionAcceptor acceptor2 = new GreedyAcceptance(1); + + typedMap.put(accKey, acceptor); + typedMap.put(selKey, selector); + typedMap.put(accKey2, acceptor2); + + assertEquals(acceptor, typedMap.get(accKey)); + assertEquals(selector, typedMap.get(selKey)); + assertEquals(acceptor2, typedMap.get(accKey2)); + } + + @Test + public void testTypedMap4() { + jsprit.core.algorithm.io.VehicleRoutingAlgorithms.TypedMap typedMap = new jsprit.core.algorithm.io.VehicleRoutingAlgorithms.TypedMap(); + + String acceptorName = "acceptor"; + String acceptorId = "acceptorId"; + + ModKey key = new ModKey(acceptorName, acceptorId); + RuinStrategyKey accKey = new RuinStrategyKey(key); + RuinStrategy acceptor = new RuinStrategy() { + + @Override + public Collection ruin(Collection vehicleRoutes) { + return null; + } + + @Override + public Collection ruin(Collection vehicleRoutes, + Job targetJob, int nOfJobs2BeRemoved) { + return null; + } + + @Override + public void addListener(RuinListener ruinListener) { + + } + + @Override + public void removeListener(RuinListener ruinListener) { + + } + + @Override + public Collection getListeners() { + return null; + } + + }; + + StrategyModuleKey moduleKey = new StrategyModuleKey(key); + SearchStrategyModule stratModule = new SearchStrategyModule() { + + @Override + public VehicleRoutingProblemSolution runAndGetSolution(VehicleRoutingProblemSolution vrpSolution) { + return null; + } + + @Override + public String getName() { + return null; + } + + @Override + public void addModuleListener( + SearchStrategyModuleListener moduleListener) { + + } + }; + + typedMap.put(accKey, acceptor); + typedMap.put(moduleKey, stratModule); + typedMap.put(moduleKey, stratModule); + + assertEquals(acceptor, typedMap.get(accKey)); + assertEquals(stratModule, typedMap.get(moduleKey)); + + } + + @Test + public void initialiseConstructionAlgoCorrectly() { + VehicleRoutingAlgorithms.createAlgorithm(vrp, config); + assertTrue(true); + } + + @Test + public void whenCreatingAlgorithm_nOfStrategiesIsCorrect() { + VehicleRoutingAlgorithm algo = VehicleRoutingAlgorithms.createAlgorithm(vrp, config); + assertEquals(3, algo.getSearchStrategyManager().getStrategies().size()); + } + + @Test + public void whenCreatingAlgorithm_nOfIterationsIsReadCorrectly() { + VehicleRoutingAlgorithm algo = VehicleRoutingAlgorithms.createAlgorithm(vrp, config); + assertEquals(10, algo.getMaxIterations()); + } + + @Test + public void whenCreatingAlgorithm_nOfStrategyModulesIsCorrect() { + VehicleRoutingAlgorithm algo = VehicleRoutingAlgorithms.createAlgorithm(vrp, config); + int nOfModules = 0; + for (SearchStrategy strat : algo.getSearchStrategyManager().getStrategies()) { + nOfModules += strat.getSearchStrategyModules().size(); + } + assertEquals(3, nOfModules); + } + + @Test + public void readerTest_whenReadingAlgoWithSchemaValidation_itReadsCorrectly() { AlgorithmConfig algoConfig = new AlgorithmConfig(); new AlgorithmConfigXmlReader(algoConfig).read("src/test/resources/algorithmConfig.xml"); } @Test - public void readerTest_whenReadingAlgoWithSchemaValidationWithoutIterations_itReadsCorrectly(){ + public void readerTest_whenReadingAlgoWithSchemaValidationWithoutIterations_itReadsCorrectly() { AlgorithmConfig algoConfig = new AlgorithmConfig(); new AlgorithmConfigXmlReader(algoConfig).read("src/test/resources/algorithmConfig_withoutIterations.xml"); } - + } diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/CalcVehicleTypeDependentServiceInsertionTest.java b/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/CalcVehicleTypeDependentServiceInsertionTest.java index 73d4b6f3..88846578 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/CalcVehicleTypeDependentServiceInsertionTest.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/CalcVehicleTypeDependentServiceInsertionTest.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.recreate; @@ -36,69 +36,69 @@ import static org.mockito.Mockito.when; public class CalcVehicleTypeDependentServiceInsertionTest { - - Vehicle veh1; - Vehicle veh2; - VehicleFleetManager fleetManager; - Service service; - VehicleRoute vehicleRoute; - - @Before - public void doBefore(){ - veh1 = mock(Vehicle.class); - veh2 = mock(Vehicle.class); - when(veh1.getType()).thenReturn(VehicleTypeImpl.Builder.newInstance("type1").build()); - when(veh2.getType()).thenReturn(VehicleTypeImpl.Builder.newInstance("type2").build()); - when(veh1.getStartLocation()).thenReturn(Location.newInstance("loc1")); - when(veh2.getStartLocation()).thenReturn(Location.newInstance("loc2")); - fleetManager = mock(VehicleFleetManager.class); - service = mock(Service.class); - vehicleRoute = mock(VehicleRoute.class); - - when(fleetManager.getAvailableVehicles()).thenReturn(Arrays.asList(veh1,veh2)); - - VehicleType type = mock(VehicleType.class); - when(type.getCapacityDimensions()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 10).build()); - when(veh1.getType()).thenReturn(type); - - when(veh2.getType()).thenReturn(type); - - when(service.getSize()).thenReturn(Capacity.Builder.newInstance().build()); - when(service.getTimeWindow()).thenReturn(TimeWindow.newInstance(0.0, Double.MAX_VALUE)); - - when(vehicleRoute.getDriver()).thenReturn(null); - when(vehicleRoute.getVehicle()).thenReturn(VehicleImpl.createNoVehicle()); - } - - @Test - public void whenHaving2Vehicle_calcInsertionOfCheapest(){ - JobInsertionCostsCalculator calc = mock(JobInsertionCostsCalculator.class); - InsertionData iDataVeh1 = new InsertionData(10.0,InsertionData.NO_INDEX, 1, veh1, null); - InsertionData iDataVeh2 = new InsertionData(20.0,InsertionData.NO_INDEX, 1, veh2, null); - when(calc.getInsertionData(vehicleRoute, service, veh1, veh1.getEarliestDeparture(), null, Double.MAX_VALUE)).thenReturn(iDataVeh1); - when(calc.getInsertionData(vehicleRoute, service, veh2, veh2.getEarliestDeparture(), null, Double.MAX_VALUE)).thenReturn(iDataVeh2); - when(calc.getInsertionData(vehicleRoute, service, veh2, veh2.getEarliestDeparture(), null, 10.0)).thenReturn(iDataVeh2); - VehicleRoutingProblem vrp = mock(VehicleRoutingProblem.class); - when(vrp.getInitialVehicleRoutes()).thenReturn(Collections.emptyList()); - VehicleTypeDependentJobInsertionCalculator insertion = new VehicleTypeDependentJobInsertionCalculator(vrp,fleetManager, calc); - InsertionData iData = insertion.getInsertionData(vehicleRoute, service, null, 0.0, null, Double.MAX_VALUE); - assertThat(iData.getSelectedVehicle(), is(veh1)); - } + Vehicle veh1; + Vehicle veh2; + VehicleFleetManager fleetManager; + Service service; + VehicleRoute vehicleRoute; - @Test - public void whenHaving2Vehicle_calcInsertionOfCheapest2(){ - JobInsertionCostsCalculator calc = mock(JobInsertionCostsCalculator.class); - InsertionData iDataVeh1 = new InsertionData(20.0,InsertionData.NO_INDEX, 1, veh1, null); - InsertionData iDataVeh2 = new InsertionData(10.0,InsertionData.NO_INDEX, 1, veh2, null); - when(calc.getInsertionData(vehicleRoute, service, veh1, veh1.getEarliestDeparture(), null, Double.MAX_VALUE)).thenReturn(iDataVeh1); - when(calc.getInsertionData(vehicleRoute, service, veh2, veh2.getEarliestDeparture(), null, Double.MAX_VALUE)).thenReturn(iDataVeh2); - when(calc.getInsertionData(vehicleRoute, service, veh2, veh2.getEarliestDeparture(), null, 20.0)).thenReturn(iDataVeh2); - VehicleRoutingProblem vrp = mock(VehicleRoutingProblem.class); - when(vrp.getInitialVehicleRoutes()).thenReturn(Collections.emptyList()); - VehicleTypeDependentJobInsertionCalculator insertion = new VehicleTypeDependentJobInsertionCalculator(vrp,fleetManager, calc); - InsertionData iData = insertion.getInsertionData(vehicleRoute, service, null, 0.0, null, Double.MAX_VALUE); - assertThat(iData.getSelectedVehicle(), is(veh2)); + @Before + public void doBefore() { + veh1 = mock(Vehicle.class); + veh2 = mock(Vehicle.class); + when(veh1.getType()).thenReturn(VehicleTypeImpl.Builder.newInstance("type1").build()); + when(veh2.getType()).thenReturn(VehicleTypeImpl.Builder.newInstance("type2").build()); + when(veh1.getStartLocation()).thenReturn(Location.newInstance("loc1")); + when(veh2.getStartLocation()).thenReturn(Location.newInstance("loc2")); + fleetManager = mock(VehicleFleetManager.class); + service = mock(Service.class); + vehicleRoute = mock(VehicleRoute.class); - } + when(fleetManager.getAvailableVehicles()).thenReturn(Arrays.asList(veh1, veh2)); + + VehicleType type = mock(VehicleType.class); + when(type.getCapacityDimensions()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 10).build()); + when(veh1.getType()).thenReturn(type); + + when(veh2.getType()).thenReturn(type); + + when(service.getSize()).thenReturn(Capacity.Builder.newInstance().build()); + when(service.getTimeWindow()).thenReturn(TimeWindow.newInstance(0.0, Double.MAX_VALUE)); + + when(vehicleRoute.getDriver()).thenReturn(null); + when(vehicleRoute.getVehicle()).thenReturn(VehicleImpl.createNoVehicle()); + } + + @Test + public void whenHaving2Vehicle_calcInsertionOfCheapest() { + JobInsertionCostsCalculator calc = mock(JobInsertionCostsCalculator.class); + InsertionData iDataVeh1 = new InsertionData(10.0, InsertionData.NO_INDEX, 1, veh1, null); + InsertionData iDataVeh2 = new InsertionData(20.0, InsertionData.NO_INDEX, 1, veh2, null); + when(calc.getInsertionData(vehicleRoute, service, veh1, veh1.getEarliestDeparture(), null, Double.MAX_VALUE)).thenReturn(iDataVeh1); + when(calc.getInsertionData(vehicleRoute, service, veh2, veh2.getEarliestDeparture(), null, Double.MAX_VALUE)).thenReturn(iDataVeh2); + when(calc.getInsertionData(vehicleRoute, service, veh2, veh2.getEarliestDeparture(), null, 10.0)).thenReturn(iDataVeh2); + VehicleRoutingProblem vrp = mock(VehicleRoutingProblem.class); + when(vrp.getInitialVehicleRoutes()).thenReturn(Collections.emptyList()); + VehicleTypeDependentJobInsertionCalculator insertion = new VehicleTypeDependentJobInsertionCalculator(vrp, fleetManager, calc); + InsertionData iData = insertion.getInsertionData(vehicleRoute, service, null, 0.0, null, Double.MAX_VALUE); + assertThat(iData.getSelectedVehicle(), is(veh1)); + + } + + @Test + public void whenHaving2Vehicle_calcInsertionOfCheapest2() { + JobInsertionCostsCalculator calc = mock(JobInsertionCostsCalculator.class); + InsertionData iDataVeh1 = new InsertionData(20.0, InsertionData.NO_INDEX, 1, veh1, null); + InsertionData iDataVeh2 = new InsertionData(10.0, InsertionData.NO_INDEX, 1, veh2, null); + when(calc.getInsertionData(vehicleRoute, service, veh1, veh1.getEarliestDeparture(), null, Double.MAX_VALUE)).thenReturn(iDataVeh1); + when(calc.getInsertionData(vehicleRoute, service, veh2, veh2.getEarliestDeparture(), null, Double.MAX_VALUE)).thenReturn(iDataVeh2); + when(calc.getInsertionData(vehicleRoute, service, veh2, veh2.getEarliestDeparture(), null, 20.0)).thenReturn(iDataVeh2); + VehicleRoutingProblem vrp = mock(VehicleRoutingProblem.class); + when(vrp.getInitialVehicleRoutes()).thenReturn(Collections.emptyList()); + VehicleTypeDependentJobInsertionCalculator insertion = new VehicleTypeDependentJobInsertionCalculator(vrp, fleetManager, calc); + InsertionData iData = insertion.getInsertionData(vehicleRoute, service, null, 0.0, null, Double.MAX_VALUE); + assertThat(iData.getSelectedVehicle(), is(veh2)); + + } } diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/CalcWithTimeSchedulingTest.java b/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/CalcWithTimeSchedulingTest.java index abafb5ce..adeab6b6 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/CalcWithTimeSchedulingTest.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/CalcWithTimeSchedulingTest.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.recreate; @@ -40,56 +40,56 @@ import static org.junit.Assert.assertEquals; public class CalcWithTimeSchedulingTest { - - - public void timeScheduler(){ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - VehicleImpl vehicle = VehicleImpl.Builder.newInstance("myVehicle").setEarliestStart(0.0).setLatestArrival(100.0). - setStartLocation(TestUtils.loc("0,0", Coordinate.newInstance(0, 0))) - .setType(VehicleTypeImpl.Builder.newInstance("myType").addCapacityDimension(0, 20).setCostPerDistance(1.0).build()).build(); - vrpBuilder.addVehicle(vehicle); - vrpBuilder.addJob(Service.Builder.newInstance("myService").addSizeDimension(0, 2) - .setLocation(TestUtils.loc("0,20",Coordinate.newInstance(0, 20))).build()); - vrpBuilder.setFleetSize(FleetSize.INFINITE); - vrpBuilder.setRoutingCost(getTpCosts(new CrowFlyCosts(vrpBuilder.getLocations()))); - VehicleRoutingProblem vrp = vrpBuilder.build(); - - VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/testConfig.xml"); - Collection solutions = vra.searchSolutions(); - - VehicleRoutingProblemSolution sol = Solutions.bestOf(solutions); - assertEquals(40.0,sol.getCost(),0.01); - assertEquals(1, sol.getRoutes().size()); - VehicleRoute route = sol.getRoutes().iterator().next(); - assertEquals(50.0,route.getStart().getEndTime(),0.01); - } - private VehicleRoutingTransportCosts getTpCosts(final VehicleRoutingTransportCosts baseCosts) { - return new VehicleRoutingTransportCosts() { - - @Override - public double getBackwardTransportCost(Location from, Location to,double arrivalTime, Driver driver, Vehicle vehicle) { - return getTransportCost(from, to, arrivalTime, driver, vehicle); - } - - @Override - public double getTransportCost(Location from, Location to, double departureTime, Driver driver, Vehicle vehicle) { - if(departureTime < 50){ - return baseCosts.getTransportCost(from, to, departureTime, driver, vehicle)*2.0; - } - return baseCosts.getTransportCost(from, to, departureTime, driver, vehicle); - } - - @Override - public double getBackwardTransportTime(Location from, Location to,double arrivalTime, Driver driver, Vehicle vehicle) { - return getTransportTime(from, to, arrivalTime, driver, vehicle); - } - - @Override - public double getTransportTime(Location from, Location to,double departureTime, Driver driver, Vehicle vehicle) { - return getTransportCost(from, to, departureTime, driver, vehicle); - } - }; - } + + public void timeScheduler() { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + VehicleImpl vehicle = VehicleImpl.Builder.newInstance("myVehicle").setEarliestStart(0.0).setLatestArrival(100.0). + setStartLocation(TestUtils.loc("0,0", Coordinate.newInstance(0, 0))) + .setType(VehicleTypeImpl.Builder.newInstance("myType").addCapacityDimension(0, 20).setCostPerDistance(1.0).build()).build(); + vrpBuilder.addVehicle(vehicle); + vrpBuilder.addJob(Service.Builder.newInstance("myService").addSizeDimension(0, 2) + .setLocation(TestUtils.loc("0,20", Coordinate.newInstance(0, 20))).build()); + vrpBuilder.setFleetSize(FleetSize.INFINITE); + vrpBuilder.setRoutingCost(getTpCosts(new CrowFlyCosts(vrpBuilder.getLocations()))); + VehicleRoutingProblem vrp = vrpBuilder.build(); + + VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/testConfig.xml"); + Collection solutions = vra.searchSolutions(); + + VehicleRoutingProblemSolution sol = Solutions.bestOf(solutions); + assertEquals(40.0, sol.getCost(), 0.01); + assertEquals(1, sol.getRoutes().size()); + VehicleRoute route = sol.getRoutes().iterator().next(); + assertEquals(50.0, route.getStart().getEndTime(), 0.01); + } + + private VehicleRoutingTransportCosts getTpCosts(final VehicleRoutingTransportCosts baseCosts) { + return new VehicleRoutingTransportCosts() { + + @Override + public double getBackwardTransportCost(Location from, Location to, double arrivalTime, Driver driver, Vehicle vehicle) { + return getTransportCost(from, to, arrivalTime, driver, vehicle); + } + + @Override + public double getTransportCost(Location from, Location to, double departureTime, Driver driver, Vehicle vehicle) { + if (departureTime < 50) { + return baseCosts.getTransportCost(from, to, departureTime, driver, vehicle) * 2.0; + } + return baseCosts.getTransportCost(from, to, departureTime, driver, vehicle); + } + + @Override + public double getBackwardTransportTime(Location from, Location to, double arrivalTime, Driver driver, Vehicle vehicle) { + return getTransportTime(from, to, arrivalTime, driver, vehicle); + } + + @Override + public double getTransportTime(Location from, Location to, double departureTime, Driver driver, Vehicle vehicle) { + return getTransportCost(from, to, departureTime, driver, vehicle); + } + }; + } } diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/JobInsertionConsideringFixCostsCalculatorTest.java b/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/JobInsertionConsideringFixCostsCalculatorTest.java index af156f00..fbcd7dc2 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/JobInsertionConsideringFixCostsCalculatorTest.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/JobInsertionConsideringFixCostsCalculatorTest.java @@ -1,18 +1,18 @@ /******************************************************************************* * Copyright (c) 2014 Stefan Schroeder. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . - * + * * Contributors: * Stefan Schroeder - initial API and implementation ******************************************************************************/ @@ -34,243 +34,243 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; public class JobInsertionConsideringFixCostsCalculatorTest { - - private JobInsertionConsideringFixCostsCalculator calc; - - private Vehicle oVehicle; - - private Vehicle nVehicle; - - private Job job; - - private VehicleRoute route; - - private RouteAndActivityStateGetter stateGetter; - - @Before - public void doBefore(){ - JobInsertionCostsCalculator jobInsertionCosts = mock(JobInsertionCostsCalculator.class); - job = mock(Job.class); - when(job.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 50).build()); - - oVehicle = mock(Vehicle.class); - VehicleType oType = VehicleTypeImpl.Builder.newInstance("otype").addCapacityDimension(0, 50).setFixedCost(50.0).build(); - when(oVehicle.getType()).thenReturn(oType); - - nVehicle = mock(Vehicle.class); - VehicleType type = VehicleTypeImpl.Builder.newInstance("type").addCapacityDimension(0, 100).setFixedCost(100.0).build(); - when(nVehicle.getType()).thenReturn(type); - - InsertionData iData = new InsertionData(0.0, 1, 1, nVehicle, null); - route = mock(VehicleRoute.class); - - when(jobInsertionCosts.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE)).thenReturn(iData); - - stateGetter = mock(RouteAndActivityStateGetter.class); - when(stateGetter.getRouteState(route, InternalStates.MAXLOAD, Capacity.class)).thenReturn(Capacity.Builder.newInstance().build()); - - calc = new JobInsertionConsideringFixCostsCalculator(jobInsertionCosts, stateGetter); - } - - @Test - public void whenOldVehicleIsNullAndSolutionComplete_itShouldReturnFixedCostsOfNewVehicle(){ - calc.setSolutionCompletenessRatio(1.0); - calc.setWeightOfFixCost(1.0); - //(1.*absFix + 0.*relFix) * completeness * weight = (1.*100. + 0.*50.) * 1. * 1. = 100. - assertEquals(100.,calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01); - } - - @Test - public void whenOldVehicleIsNullAndSolutionIs0PercentComplete_itShouldReturnNoFixedCosts(){ - calc.setSolutionCompletenessRatio(0.0); - calc.setWeightOfFixCost(1.0); - //(0.*absFix + 1.*relFix) * completeness * weight = 0. - assertEquals(0.,calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01); - } - - @Test - public void whenOldVehicleIsNullAndSolutionIs50PercentComplete_itShouldReturnAvgOfRelFixedAndAbsFixedCostOfNewVehicle(){ - calc.setSolutionCompletenessRatio(0.5); - calc.setWeightOfFixCost(1.0); - //(0.5*absFix + 0.5*relFix) * 0.5 * 1. = (0.5*100+0.5*50)*0.5*1. = 37.5 - assertEquals(37.5,calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01); - } - - @Test - public void whenOldVehicleIsNullAndSolutionIs75PercentComplete_itShouldReturnAvgOfRelFixedAndAbsFixedCostOfNewVehicle(){ - calc.setSolutionCompletenessRatio(0.75); - calc.setWeightOfFixCost(1.0); - //(0.75*absFix + 0.25*relFix) * 0.75 * 1.= (0.75*100.+0.25*50.)*0.75*1. = 65.625 - assertEquals(65.625,calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01); - } - - @Test - public void whenOldVehicleIsNullAndSolutionCompleteAndWeightIs05_itShouldReturnHalfOfFixedCostsOfNewVehicle(){ - calc.setSolutionCompletenessRatio(1.0); - calc.setWeightOfFixCost(.5); - //(1.*absFix + 0.*relFix) * 1. * 0.5 = (1.*100. + 0.*50.) * 1. * 0.5 = 5. - assertEquals(50.,calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01); - } - - @Test - public void whenOldVehicleIsNullAndSolutionIs0PercentCompleteAndWeightIs05_itShouldReturnHalfOfNoFixedCosts(){ - calc.setSolutionCompletenessRatio(0.0); - calc.setWeightOfFixCost(.5); - //(0.*absFix + 1.*relFix) * 0. * .5 = 0. - assertEquals(0.,calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01); - } - - @Test - public void whenOldVehicleIsNullAndSolutionIs50PercentCompleteAndWeightIs05_itShouldReturnHalfOfAvgOfRelFixedAndAbsFixedCostOfNewVehicle(){ - calc.setSolutionCompletenessRatio(0.5); - calc.setWeightOfFixCost(.5); - //(0.5*absFix + 0.5*relFix) * 0.5 * 0.= (0.5*100+0.5*50)*0.5*0.5 = 18.75 - assertEquals(18.75,calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01); - } - - @Test - public void whenOldVehicleIsNullAndSolutionIs75PercentCompleteAndWeightIs05_itShouldReturnHalfOfAvgOfRelFixedAndAbsFixedCostOfNewVehicle(){ - calc.setSolutionCompletenessRatio(0.75); - calc.setWeightOfFixCost(0.5); - //(0.75*absFix + 0.25*relFix) * 0.75 * 0.5 = (0.75*100.+0.25*50.)*0.75*0.5 = 32.8125 - assertEquals(32.8125,calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01); - } - @Test - public void whenOldVehicleIsNotNullAndSolutionComplete_itShouldReturnHalfOfFixedCostsOfNewVehicle(){ - calc.setSolutionCompletenessRatio(1.0); - calc.setWeightOfFixCost(1.0); - when(route.getVehicle()).thenReturn(oVehicle); - //(1.*absFix + 0.*relFix) * completeness * weight = (1.*(100.-50.) + 0.*(50.-0.)) * 1. * 1. = 50. - assertEquals(50.,calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01); - } - - @Test - public void whenOldVehicleIsNotNullAndSolutionIs0PercentComplete_itShouldReturnNoFixedCosts(){ - calc.setSolutionCompletenessRatio(0.0); - calc.setWeightOfFixCost(1.0); - when(route.getVehicle()).thenReturn(oVehicle); - //(0.*absFix + 1.*relFix) * completeness * weight = 0. - assertEquals(0.,calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01); - } - - @Test - public void whenOldVehicleIsNotNullAndSolutionIs50PercentComplete_itShouldCorrectVal(){ - calc.setSolutionCompletenessRatio(0.5); - calc.setWeightOfFixCost(1.0); - when(route.getVehicle()).thenReturn(oVehicle); - //(0.5*absFix + 0.5*relFix) * 0.5 * 1. = (0.5*(100-50)+0.5*(50-0))*0.5*1. = 25. - assertEquals(25.,calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01); - } - - @Test - public void whenOldVehicleIsNotNullAndSolutionIs75PercentComplete_itShouldReturnCorrectVal(){ - calc.setSolutionCompletenessRatio(0.75); - calc.setWeightOfFixCost(1.0); - when(route.getVehicle()).thenReturn(oVehicle); - //(0.75*absFix + 0.25*relFix) * 0.75 * 1.= (0.75*(100.-50.)+0.25*(50.-0.))*0.75*1. = 37.5 - assertEquals(37.5,calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01); - } - - @Test - public void whenOldVehicleIsNotNullAndSolutionCompleteAndWeightIs05_itShouldReturnCorrectVal(){ - calc.setSolutionCompletenessRatio(1.0); - calc.setWeightOfFixCost(.5); - when(route.getVehicle()).thenReturn(oVehicle); - //(1.*absFix + 0.*relFix) * 1. * 0.5 = (1.*(100.-50.) + 0.*(50.-0.)) * 1. * 0.5 = 25. - assertEquals(25.,calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01); - } - - @Test - public void whenOldVehicleIsNotNullAndSolutionIs0PercentCompleteAndWeightIs05_itShouldReturnCorrectVal(){ - calc.setSolutionCompletenessRatio(0.0); - calc.setWeightOfFixCost(.5); - when(route.getVehicle()).thenReturn(oVehicle); - //(0.*absFix + 1.*relFix) * 0. * .5 = 0. - assertEquals(0.,calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01); - } - - @Test - public void whenOldVehicleIsNotNullAndSolutionIs50PercentCompleteAndWeightIs05_itShouldReturnCorrectVal(){ - calc.setSolutionCompletenessRatio(0.5); - calc.setWeightOfFixCost(.5); - when(route.getVehicle()).thenReturn(oVehicle); - //(0.5*absFix + 0.5*relFix) * 0.5 * 0.= (0.5*(100-50)+0.5*(50-0))*0.5*0.5 = 12.5 - assertEquals(12.5,calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01); - } - - @Test - public void whenOldVehicleIsNotNullAndSolutionIs75PercentCompleteAndWeightIs05_itShouldReturnCorrectVal(){ - calc.setSolutionCompletenessRatio(0.75); - calc.setWeightOfFixCost(0.5); - when(route.getVehicle()).thenReturn(oVehicle); - //(0.75*absFix + 0.25*relFix) * 0.75 * 0.5 = (0.75*(100.-50.)+0.25*(50.-0.))*0.75*0.5 = 18.75 - assertEquals(18.75,calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01); - } - - @Test - public void whenOldVehicleIsNotNullAndCurrentLoadIs25AndSolutionIs50PercentCompleteAndWeightIs05_itShouldReturnCorrectVal(){ - calc.setSolutionCompletenessRatio(0.5); - calc.setWeightOfFixCost(.5); - when(route.getVehicle()).thenReturn(oVehicle); - when(stateGetter.getRouteState(route, InternalStates.MAXLOAD, Capacity.class)).thenReturn(Capacity.Builder.newInstance().addDimension(0, 25).build()); - //(0.5*absFix + 0.5*relFix) * 0.5 * 0.= (0.5*(100-50)+0.5*(75-25))*0.5*0.5 = 12.5 - assertEquals(12.5,calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01); - } - - @Test - public void whenOldVehicleIsNotNullAndCurrentLoadIs25AndSolutionIs75PercentCompleteAndWeightIs05_itShouldReturnCorrectVal(){ - calc.setSolutionCompletenessRatio(0.75); - calc.setWeightOfFixCost(0.5); - when(route.getVehicle()).thenReturn(oVehicle); - //(0.75*absFix + 0.25*relFix) * 0.75 * 0.5 = (0.75*(100.-50.)+0.25*(75.-25.))*0.75*0.5 = 18.75 - assertEquals(18.75,calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01); - } + private JobInsertionConsideringFixCostsCalculator calc; - @Test - public void whenOldVehicleIsNotNullAndCurrentLoadIs25AndSolutionIs50PercentCompleteAndWeightIs05WithMultipleCapDims_itShouldReturnCorrectVal(){ - calc.setSolutionCompletenessRatio(.5); - calc.setWeightOfFixCost(.5); - - when(job.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 50).addDimension(1, 0).build()); - - VehicleType oType = VehicleTypeImpl.Builder.newInstance("otype").addCapacityDimension(0, 50).addCapacityDimension(1, 100).setFixedCost(50.0).build(); - when(oVehicle.getType()).thenReturn(oType); - - VehicleType type = VehicleTypeImpl.Builder.newInstance("type").addCapacityDimension(0, 100).addCapacityDimension(1, 400).setFixedCost(100.0).build(); - when(nVehicle.getType()).thenReturn(type); - - when(route.getVehicle()).thenReturn(oVehicle); - when(stateGetter.getRouteState(route, InternalStates.MAXLOAD, Capacity.class)).thenReturn(Capacity.Builder.newInstance().addDimension(0, 25).addDimension(1, 100).build()); - //(0.5*absFix + 0.5*relFix) * 0.5 * 0.= (0.5*(100-50)+0.5*(75-25))*0.5*0.5 = 12.5 - /* - * (0.5*(100-50)+0.5*( - * relFixNew - relFixOld = (75/100+100/400)/2.*100 - ((25/50+100/100)/2.*50.) = + private Vehicle oVehicle; + + private Vehicle nVehicle; + + private Job job; + + private VehicleRoute route; + + private RouteAndActivityStateGetter stateGetter; + + @Before + public void doBefore() { + JobInsertionCostsCalculator jobInsertionCosts = mock(JobInsertionCostsCalculator.class); + job = mock(Job.class); + when(job.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 50).build()); + + oVehicle = mock(Vehicle.class); + VehicleType oType = VehicleTypeImpl.Builder.newInstance("otype").addCapacityDimension(0, 50).setFixedCost(50.0).build(); + when(oVehicle.getType()).thenReturn(oType); + + nVehicle = mock(Vehicle.class); + VehicleType type = VehicleTypeImpl.Builder.newInstance("type").addCapacityDimension(0, 100).setFixedCost(100.0).build(); + when(nVehicle.getType()).thenReturn(type); + + InsertionData iData = new InsertionData(0.0, 1, 1, nVehicle, null); + route = mock(VehicleRoute.class); + + when(jobInsertionCosts.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE)).thenReturn(iData); + + stateGetter = mock(RouteAndActivityStateGetter.class); + when(stateGetter.getRouteState(route, InternalStates.MAXLOAD, Capacity.class)).thenReturn(Capacity.Builder.newInstance().build()); + + calc = new JobInsertionConsideringFixCostsCalculator(jobInsertionCosts, stateGetter); + } + + @Test + public void whenOldVehicleIsNullAndSolutionComplete_itShouldReturnFixedCostsOfNewVehicle() { + calc.setSolutionCompletenessRatio(1.0); + calc.setWeightOfFixCost(1.0); + //(1.*absFix + 0.*relFix) * completeness * weight = (1.*100. + 0.*50.) * 1. * 1. = 100. + assertEquals(100., calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01); + } + + @Test + public void whenOldVehicleIsNullAndSolutionIs0PercentComplete_itShouldReturnNoFixedCosts() { + calc.setSolutionCompletenessRatio(0.0); + calc.setWeightOfFixCost(1.0); + //(0.*absFix + 1.*relFix) * completeness * weight = 0. + assertEquals(0., calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01); + } + + @Test + public void whenOldVehicleIsNullAndSolutionIs50PercentComplete_itShouldReturnAvgOfRelFixedAndAbsFixedCostOfNewVehicle() { + calc.setSolutionCompletenessRatio(0.5); + calc.setWeightOfFixCost(1.0); + //(0.5*absFix + 0.5*relFix) * 0.5 * 1. = (0.5*100+0.5*50)*0.5*1. = 37.5 + assertEquals(37.5, calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01); + } + + @Test + public void whenOldVehicleIsNullAndSolutionIs75PercentComplete_itShouldReturnAvgOfRelFixedAndAbsFixedCostOfNewVehicle() { + calc.setSolutionCompletenessRatio(0.75); + calc.setWeightOfFixCost(1.0); + //(0.75*absFix + 0.25*relFix) * 0.75 * 1.= (0.75*100.+0.25*50.)*0.75*1. = 65.625 + assertEquals(65.625, calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01); + } + + @Test + public void whenOldVehicleIsNullAndSolutionCompleteAndWeightIs05_itShouldReturnHalfOfFixedCostsOfNewVehicle() { + calc.setSolutionCompletenessRatio(1.0); + calc.setWeightOfFixCost(.5); + //(1.*absFix + 0.*relFix) * 1. * 0.5 = (1.*100. + 0.*50.) * 1. * 0.5 = 5. + assertEquals(50., calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01); + } + + @Test + public void whenOldVehicleIsNullAndSolutionIs0PercentCompleteAndWeightIs05_itShouldReturnHalfOfNoFixedCosts() { + calc.setSolutionCompletenessRatio(0.0); + calc.setWeightOfFixCost(.5); + //(0.*absFix + 1.*relFix) * 0. * .5 = 0. + assertEquals(0., calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01); + } + + @Test + public void whenOldVehicleIsNullAndSolutionIs50PercentCompleteAndWeightIs05_itShouldReturnHalfOfAvgOfRelFixedAndAbsFixedCostOfNewVehicle() { + calc.setSolutionCompletenessRatio(0.5); + calc.setWeightOfFixCost(.5); + //(0.5*absFix + 0.5*relFix) * 0.5 * 0.= (0.5*100+0.5*50)*0.5*0.5 = 18.75 + assertEquals(18.75, calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01); + } + + @Test + public void whenOldVehicleIsNullAndSolutionIs75PercentCompleteAndWeightIs05_itShouldReturnHalfOfAvgOfRelFixedAndAbsFixedCostOfNewVehicle() { + calc.setSolutionCompletenessRatio(0.75); + calc.setWeightOfFixCost(0.5); + //(0.75*absFix + 0.25*relFix) * 0.75 * 0.5 = (0.75*100.+0.25*50.)*0.75*0.5 = 32.8125 + assertEquals(32.8125, calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01); + } + + @Test + public void whenOldVehicleIsNotNullAndSolutionComplete_itShouldReturnHalfOfFixedCostsOfNewVehicle() { + calc.setSolutionCompletenessRatio(1.0); + calc.setWeightOfFixCost(1.0); + when(route.getVehicle()).thenReturn(oVehicle); + //(1.*absFix + 0.*relFix) * completeness * weight = (1.*(100.-50.) + 0.*(50.-0.)) * 1. * 1. = 50. + assertEquals(50., calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01); + } + + @Test + public void whenOldVehicleIsNotNullAndSolutionIs0PercentComplete_itShouldReturnNoFixedCosts() { + calc.setSolutionCompletenessRatio(0.0); + calc.setWeightOfFixCost(1.0); + when(route.getVehicle()).thenReturn(oVehicle); + //(0.*absFix + 1.*relFix) * completeness * weight = 0. + assertEquals(0., calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01); + } + + @Test + public void whenOldVehicleIsNotNullAndSolutionIs50PercentComplete_itShouldCorrectVal() { + calc.setSolutionCompletenessRatio(0.5); + calc.setWeightOfFixCost(1.0); + when(route.getVehicle()).thenReturn(oVehicle); + //(0.5*absFix + 0.5*relFix) * 0.5 * 1. = (0.5*(100-50)+0.5*(50-0))*0.5*1. = 25. + assertEquals(25., calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01); + } + + @Test + public void whenOldVehicleIsNotNullAndSolutionIs75PercentComplete_itShouldReturnCorrectVal() { + calc.setSolutionCompletenessRatio(0.75); + calc.setWeightOfFixCost(1.0); + when(route.getVehicle()).thenReturn(oVehicle); + //(0.75*absFix + 0.25*relFix) * 0.75 * 1.= (0.75*(100.-50.)+0.25*(50.-0.))*0.75*1. = 37.5 + assertEquals(37.5, calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01); + } + + @Test + public void whenOldVehicleIsNotNullAndSolutionCompleteAndWeightIs05_itShouldReturnCorrectVal() { + calc.setSolutionCompletenessRatio(1.0); + calc.setWeightOfFixCost(.5); + when(route.getVehicle()).thenReturn(oVehicle); + //(1.*absFix + 0.*relFix) * 1. * 0.5 = (1.*(100.-50.) + 0.*(50.-0.)) * 1. * 0.5 = 25. + assertEquals(25., calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01); + } + + @Test + public void whenOldVehicleIsNotNullAndSolutionIs0PercentCompleteAndWeightIs05_itShouldReturnCorrectVal() { + calc.setSolutionCompletenessRatio(0.0); + calc.setWeightOfFixCost(.5); + when(route.getVehicle()).thenReturn(oVehicle); + //(0.*absFix + 1.*relFix) * 0. * .5 = 0. + assertEquals(0., calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01); + } + + @Test + public void whenOldVehicleIsNotNullAndSolutionIs50PercentCompleteAndWeightIs05_itShouldReturnCorrectVal() { + calc.setSolutionCompletenessRatio(0.5); + calc.setWeightOfFixCost(.5); + when(route.getVehicle()).thenReturn(oVehicle); + //(0.5*absFix + 0.5*relFix) * 0.5 * 0.= (0.5*(100-50)+0.5*(50-0))*0.5*0.5 = 12.5 + assertEquals(12.5, calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01); + } + + @Test + public void whenOldVehicleIsNotNullAndSolutionIs75PercentCompleteAndWeightIs05_itShouldReturnCorrectVal() { + calc.setSolutionCompletenessRatio(0.75); + calc.setWeightOfFixCost(0.5); + when(route.getVehicle()).thenReturn(oVehicle); + //(0.75*absFix + 0.25*relFix) * 0.75 * 0.5 = (0.75*(100.-50.)+0.25*(50.-0.))*0.75*0.5 = 18.75 + assertEquals(18.75, calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01); + } + + @Test + public void whenOldVehicleIsNotNullAndCurrentLoadIs25AndSolutionIs50PercentCompleteAndWeightIs05_itShouldReturnCorrectVal() { + calc.setSolutionCompletenessRatio(0.5); + calc.setWeightOfFixCost(.5); + when(route.getVehicle()).thenReturn(oVehicle); + when(stateGetter.getRouteState(route, InternalStates.MAXLOAD, Capacity.class)).thenReturn(Capacity.Builder.newInstance().addDimension(0, 25).build()); + //(0.5*absFix + 0.5*relFix) * 0.5 * 0.= (0.5*(100-50)+0.5*(75-25))*0.5*0.5 = 12.5 + assertEquals(12.5, calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01); + } + + @Test + public void whenOldVehicleIsNotNullAndCurrentLoadIs25AndSolutionIs75PercentCompleteAndWeightIs05_itShouldReturnCorrectVal() { + calc.setSolutionCompletenessRatio(0.75); + calc.setWeightOfFixCost(0.5); + when(route.getVehicle()).thenReturn(oVehicle); + //(0.75*absFix + 0.25*relFix) * 0.75 * 0.5 = (0.75*(100.-50.)+0.25*(75.-25.))*0.75*0.5 = 18.75 + assertEquals(18.75, calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01); + } + + @Test + public void whenOldVehicleIsNotNullAndCurrentLoadIs25AndSolutionIs50PercentCompleteAndWeightIs05WithMultipleCapDims_itShouldReturnCorrectVal() { + calc.setSolutionCompletenessRatio(.5); + calc.setWeightOfFixCost(.5); + + when(job.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 50).addDimension(1, 0).build()); + + VehicleType oType = VehicleTypeImpl.Builder.newInstance("otype").addCapacityDimension(0, 50).addCapacityDimension(1, 100).setFixedCost(50.0).build(); + when(oVehicle.getType()).thenReturn(oType); + + VehicleType type = VehicleTypeImpl.Builder.newInstance("type").addCapacityDimension(0, 100).addCapacityDimension(1, 400).setFixedCost(100.0).build(); + when(nVehicle.getType()).thenReturn(type); + + when(route.getVehicle()).thenReturn(oVehicle); + when(stateGetter.getRouteState(route, InternalStates.MAXLOAD, Capacity.class)).thenReturn(Capacity.Builder.newInstance().addDimension(0, 25).addDimension(1, 100).build()); + //(0.5*absFix + 0.5*relFix) * 0.5 * 0.= (0.5*(100-50)+0.5*(75-25))*0.5*0.5 = 12.5 + /* + * (0.5*(100-50)+0.5*( + * relFixNew - relFixOld = (75/100+100/400)/2.*100 - ((25/50+100/100)/2.*50.) = * )*0.5*0.5 - * = (0.5*(100-50)+0.5*((75/100+100/400)/2.*100 - ((25/50+100/100)/2.*50.)))*0.5*0.5 + * = (0.5*(100-50)+0.5*((75/100+100/400)/2.*100 - ((25/50+100/100)/2.*50.)))*0.5*0.5 * = (0.5*(100-50)+0.5*12.5)*0.5*0.5 = 7.8125 */ - assertEquals(7.8125,calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01); - } - - @Test - public void whenOldVehicleIsNotNullAndCurrentLoadIs25AndSolutionIs75PercentCompleteAndWeightIs05WithMultipleCapDims_itShouldReturnCorrectVal(){ - calc.setSolutionCompletenessRatio(0.75); - calc.setWeightOfFixCost(0.5); - when(job.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 50).addDimension(1, 0).build()); + assertEquals(7.8125, calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01); + } + + @Test + public void whenOldVehicleIsNotNullAndCurrentLoadIs25AndSolutionIs75PercentCompleteAndWeightIs05WithMultipleCapDims_itShouldReturnCorrectVal() { + calc.setSolutionCompletenessRatio(0.75); + calc.setWeightOfFixCost(0.5); + when(job.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 50).addDimension(1, 0).build()); + + VehicleType oType = VehicleTypeImpl.Builder.newInstance("otype").addCapacityDimension(0, 50).addCapacityDimension(1, 100).setFixedCost(50.0).build(); + when(oVehicle.getType()).thenReturn(oType); + + VehicleType type = VehicleTypeImpl.Builder.newInstance("type").addCapacityDimension(0, 100).addCapacityDimension(1, 400).setFixedCost(100.0).build(); + when(nVehicle.getType()).thenReturn(type); + + when(route.getVehicle()).thenReturn(oVehicle); + when(stateGetter.getRouteState(route, InternalStates.MAXLOAD, Capacity.class)).thenReturn(Capacity.Builder.newInstance().addDimension(0, 25).addDimension(1, 100).build()); + //(0.75*absFix + 0.25*relFix) * 0.75 * 0.5 = (0.75*(100.-50.)+0.25*12.5)*0.75*0.5 = 15.234375 + + assertEquals(15.234375, calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01); + } + - VehicleType oType = VehicleTypeImpl.Builder.newInstance("otype").addCapacityDimension(0, 50).addCapacityDimension(1, 100).setFixedCost(50.0).build(); - when(oVehicle.getType()).thenReturn(oType); - - VehicleType type = VehicleTypeImpl.Builder.newInstance("type").addCapacityDimension(0, 100).addCapacityDimension(1, 400).setFixedCost(100.0).build(); - when(nVehicle.getType()).thenReturn(type); - - when(route.getVehicle()).thenReturn(oVehicle); - when(stateGetter.getRouteState(route, InternalStates.MAXLOAD, Capacity.class)).thenReturn(Capacity.Builder.newInstance().addDimension(0, 25).addDimension(1, 100).build()); - //(0.75*absFix + 0.25*relFix) * 0.75 * 0.5 = (0.75*(100.-50.)+0.25*12.5)*0.75*0.5 = 15.234375 - - assertEquals(15.234375,calc.getInsertionData(route, job, nVehicle, 0.0, null, Double.MAX_VALUE).getInsertionCost(), 0.01); - } - - } diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/RegretInsertionTest.java b/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/RegretInsertionTest.java index c9870a6d..5b54e596 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/RegretInsertionTest.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/RegretInsertionTest.java @@ -26,7 +26,9 @@ import jsprit.core.problem.job.Service; import jsprit.core.problem.job.Shipment; import jsprit.core.problem.solution.route.VehicleRoute; import jsprit.core.problem.solution.route.activity.TourActivity; +import jsprit.core.problem.vehicle.FiniteFleetManagerFactory; import jsprit.core.problem.vehicle.Vehicle; +import jsprit.core.problem.vehicle.VehicleFleetManager; import jsprit.core.problem.vehicle.VehicleImpl; import jsprit.core.util.Coordinate; import junit.framework.Assert; @@ -38,77 +40,81 @@ import java.util.Collection; public class RegretInsertionTest { @Test - public void noRoutesShouldBeCorrect(){ + public void noRoutesShouldBeCorrect() { Service s1 = Service.Builder.newInstance("s1").setLocation(Location.newInstance(0, 10)).build(); Service s2 = Service.Builder.newInstance("s2").setLocation(Location.newInstance(0, 5)).build(); VehicleImpl v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0, 0)).build(); VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(s1).addJob(s2).addVehicle(v).build(); + VehicleFleetManager fm = new FiniteFleetManagerFactory(vrp.getVehicles()).createFleetManager(); JobInsertionCostsCalculator calculator = getCalculator(vrp); - RegretInsertion regretInsertion = new RegretInsertion(calculator,vrp); + RegretInsertionFast regretInsertion = new RegretInsertionFast(calculator, vrp, fm); Collection routes = new ArrayList(); - regretInsertion.insertJobs(routes,vrp.getJobs().values()); - Assert.assertEquals(1,routes.size()); + regretInsertion.insertJobs(routes, vrp.getJobs().values()); + Assert.assertEquals(1, routes.size()); } @Test - public void noJobsInRouteShouldBeCorrect(){ + public void noJobsInRouteShouldBeCorrect() { Service s1 = Service.Builder.newInstance("s1").setLocation(Location.newInstance(0, 10)).build(); Service s2 = Service.Builder.newInstance("s2").setLocation(Location.newInstance(0, 5)).build(); VehicleImpl v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0, 0)).build(); VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(s1).addJob(s2).addVehicle(v).build(); + VehicleFleetManager fm = new FiniteFleetManagerFactory(vrp.getVehicles()).createFleetManager(); JobInsertionCostsCalculator calculator = getCalculator(vrp); - RegretInsertion regretInsertion = new RegretInsertion(calculator,vrp); + RegretInsertionFast regretInsertion = new RegretInsertionFast(calculator, vrp, fm); Collection routes = new ArrayList(); - regretInsertion.insertJobs(routes,vrp.getJobs().values()); + regretInsertion.insertJobs(routes, vrp.getJobs().values()); Assert.assertEquals(2, routes.iterator().next().getActivities().size()); } @Test - public void s1ShouldBeAddedFirst(){ + public void s1ShouldBeAddedFirst() { Service s1 = Service.Builder.newInstance("s1").setLocation(Location.newInstance(0, 10)).build(); Service s2 = Service.Builder.newInstance("s2").setLocation(Location.newInstance(0, 5)).build(); - VehicleImpl v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0,0)).build(); + VehicleImpl v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0, 0)).build(); final VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(s1).addJob(s2).addVehicle(v).build(); + VehicleFleetManager fm = new FiniteFleetManagerFactory(vrp.getVehicles()).createFleetManager(); JobInsertionCostsCalculator calculator = getCalculator(vrp); - RegretInsertion regretInsertion = new RegretInsertion(calculator,vrp); + RegretInsertionFast regretInsertion = new RegretInsertionFast(calculator, vrp, fm); Collection routes = new ArrayList(); CkeckJobSequence position = new CkeckJobSequence(2, s1); regretInsertion.addListener(position); - regretInsertion.insertJobs(routes,vrp.getJobs().values()); + regretInsertion.insertJobs(routes, vrp.getJobs().values()); Assert.assertTrue(position.isCorrect()); } @Test - public void shipment1ShouldBeAddedFirst(){ + public void shipment1ShouldBeAddedFirst() { Shipment s1 = Shipment.Builder.newInstance("s1") - .setPickupLocation(Location.Builder.newInstance().setId("pick1").setCoordinate(Coordinate.newInstance(-1, 10)).build()) - .setDeliveryLocation(Location.Builder.newInstance().setId("del1").setCoordinate(Coordinate.newInstance(1, 10)).build()) - .build(); + .setPickupLocation(Location.Builder.newInstance().setId("pick1").setCoordinate(Coordinate.newInstance(-1, 10)).build()) + .setDeliveryLocation(Location.Builder.newInstance().setId("del1").setCoordinate(Coordinate.newInstance(1, 10)).build()) + .build(); Shipment s2 = Shipment.Builder.newInstance("s2") - .setPickupLocation(Location.Builder.newInstance().setId("pick2").setCoordinate(Coordinate.newInstance(-1, 20)).build()) - .setDeliveryLocation(Location.Builder.newInstance().setId("del2").setCoordinate(Coordinate.newInstance(1, 20)).build()) - .build(); + .setPickupLocation(Location.Builder.newInstance().setId("pick2").setCoordinate(Coordinate.newInstance(-1, 20)).build()) + .setDeliveryLocation(Location.Builder.newInstance().setId("del2").setCoordinate(Coordinate.newInstance(1, 20)).build()) + .build(); VehicleImpl v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(0, 0)).build()).build(); final VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(s1).addJob(s2).addVehicle(v).build(); + VehicleFleetManager fm = new FiniteFleetManagerFactory(vrp.getVehicles()).createFleetManager(); JobInsertionCostsCalculator calculator = getShipmentCalculator(vrp); - RegretInsertion regretInsertion = new RegretInsertion(calculator,vrp); + RegretInsertionFast regretInsertion = new RegretInsertionFast(calculator, vrp, fm); Collection routes = new ArrayList(); CkeckJobSequence position = new CkeckJobSequence(2, s2); regretInsertion.addListener(position); - regretInsertion.insertJobs(routes,vrp.getJobs().values()); + regretInsertion.insertJobs(routes, vrp.getJobs().values()); Assert.assertTrue(position.isCorrect()); } @@ -118,11 +124,10 @@ public class RegretInsertionTest { @Override public InsertionData getInsertionData(VehicleRoute currentRoute, Job newJob, Vehicle newVehicle, double newVehicleDepartureTime, Driver newDriver, double bestKnownCosts) { Vehicle vehicle = vrp.getVehicles().iterator().next(); - if(newJob.getId().equals("s1")){ - return new InsertionData(10,0,0,vehicle,newDriver); - } - else{ - return new InsertionData(20,0,0,vehicle,newDriver); + if (newJob.getId().equals("s1")) { + return new InsertionData(10, 0, 0, vehicle, newDriver); + } else { + return new InsertionData(20, 0, 0, vehicle, newDriver); } } }; @@ -146,7 +151,7 @@ public class RegretInsertionTest { @Override public void informBeforeJobInsertion(Job job, InsertionData data, VehicleRoute route) { - if(job == this.job && atPosition == positionCounter){ + if (job == this.job && atPosition == positionCounter) { correct = true; } positionCounter++; @@ -162,16 +167,15 @@ public class RegretInsertionTest { @Override public InsertionData getInsertionData(VehicleRoute currentRoute, Job newJob, Vehicle newVehicle, double newVehicleDepartureTime, Driver newDriver, double bestKnownCosts) { - Service service = (Service)newJob; + Service service = (Service) newJob; Vehicle vehicle = vrp.getVehicles().iterator().next(); InsertionData iData; - if(currentRoute.isEmpty()){ + if (currentRoute.isEmpty()) { double mc = getCost(service.getLocation(), vehicle.getStartLocation()); - iData = new InsertionData(2*mc,-1,0,vehicle,newDriver); - iData.getEvents().add(new InsertActivity(currentRoute,vehicle,vrp.copyAndGetActivities(newJob).get(0),0)); - iData.getEvents().add(new SwitchVehicle(currentRoute,vehicle,newVehicleDepartureTime)); - } - else { + iData = new InsertionData(2 * mc, -1, 0, vehicle, newDriver); + iData.getEvents().add(new InsertActivity(currentRoute, vehicle, vrp.copyAndGetActivities(newJob).get(0), 0)); + iData.getEvents().add(new SwitchVehicle(currentRoute, vehicle, newVehicleDepartureTime)); + } else { double best = Double.MAX_VALUE; int bestIndex = 0; int index = 0; @@ -190,22 +194,22 @@ public class RegretInsertionTest { best = mc; bestIndex = index; } - iData = new InsertionData(best,-1,bestIndex,vehicle,newDriver); - iData.getEvents().add(new InsertActivity(currentRoute,vehicle,vrp.copyAndGetActivities(newJob).get(0),bestIndex)); - iData.getEvents().add(new SwitchVehicle(currentRoute,vehicle,newVehicleDepartureTime)); + iData = new InsertionData(best, -1, bestIndex, vehicle, newDriver); + iData.getEvents().add(new InsertActivity(currentRoute, vehicle, vrp.copyAndGetActivities(newJob).get(0), bestIndex)); + iData.getEvents().add(new SwitchVehicle(currentRoute, vehicle, newVehicleDepartureTime)); } return iData; } private double getMarginalCost(Service service, TourActivity prevAct, TourActivity act) { - double prev_new = getCost(prevAct.getLocation(),service.getLocation()); - double new_act = getCost(service.getLocation(),act.getLocation()); - double prev_act = getCost(prevAct.getLocation(),act.getLocation()); + double prev_new = getCost(prevAct.getLocation(), service.getLocation()); + double new_act = getCost(service.getLocation(), act.getLocation()); + double prev_act = getCost(prevAct.getLocation(), act.getLocation()); return prev_new + new_act - prev_act; } private double getCost(Location loc1, Location loc2) { - return vrp.getTransportCosts().getTransportCost(loc1,loc2,0.,null,null); + return vrp.getTransportCosts().getTransportCost(loc1, loc2, 0., null, null); } }; diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/ServiceInsertionAndLoadConstraintsTest.java b/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/ServiceInsertionAndLoadConstraintsTest.java index 3d9bfaad..c071c26f 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/ServiceInsertionAndLoadConstraintsTest.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/ServiceInsertionAndLoadConstraintsTest.java @@ -53,74 +53,74 @@ import static org.mockito.Mockito.mock; public class ServiceInsertionAndLoadConstraintsTest { - - VehicleRoutingTransportCosts routingCosts; - - VehicleRoutingActivityCosts activityCosts = new VehicleRoutingActivityCosts(){ - @Override - public double getActivityCost(TourActivity tourAct, double arrivalTime,Driver driver, Vehicle vehicle) { - return 0; - } - - }; - - HardActivityConstraint hardActivityLevelConstraint = new HardActivityConstraint() { - - @Override - public ConstraintsStatus fulfilled(JobInsertionContext iFacts, TourActivity prevAct,TourActivity newAct, TourActivity nextAct, double prevActDepTime) { - return ConstraintsStatus.FULFILLED; - } - }; - - HardRouteConstraint hardRouteLevelConstraint = new HardRouteConstraint(){ + VehicleRoutingTransportCosts routingCosts; - @Override - public boolean fulfilled(JobInsertionContext insertionContext) { - return true; - } - - }; - - ActivityInsertionCostsCalculator activityInsertionCostsCalculator; - - ShipmentInsertionCalculator insertionCalculator; + VehicleRoutingActivityCosts activityCosts = new VehicleRoutingActivityCosts() { + + @Override + public double getActivityCost(TourActivity tourAct, double arrivalTime, Driver driver, Vehicle vehicle) { + return 0; + } + + }; + + HardActivityConstraint hardActivityLevelConstraint = new HardActivityConstraint() { + + @Override + public ConstraintsStatus fulfilled(JobInsertionContext iFacts, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double prevActDepTime) { + return ConstraintsStatus.FULFILLED; + } + }; + + HardRouteConstraint hardRouteLevelConstraint = new HardRouteConstraint() { + + @Override + public boolean fulfilled(JobInsertionContext insertionContext) { + return true; + } + + }; + + ActivityInsertionCostsCalculator activityInsertionCostsCalculator; + + ShipmentInsertionCalculator insertionCalculator; VehicleRoutingProblem vehicleRoutingProblem; - - Vehicle vehicle; - - @Before - public void doBefore(){ - routingCosts = CostFactory.createManhattanCosts(); - VehicleType type = VehicleTypeImpl.Builder.newInstance("t").addCapacityDimension(0, 2).setCostPerDistance(1).build(); - vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("0,0")).setType(type).build(); - activityInsertionCostsCalculator = new LocalActivityInsertionCostsCalculator(routingCosts, activityCosts); - createInsertionCalculator(hardRouteLevelConstraint); + + Vehicle vehicle; + + @Before + public void doBefore() { + routingCosts = CostFactory.createManhattanCosts(); + VehicleType type = VehicleTypeImpl.Builder.newInstance("t").addCapacityDimension(0, 2).setCostPerDistance(1).build(); + vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("0,0")).setType(type).build(); + activityInsertionCostsCalculator = new LocalActivityInsertionCostsCalculator(routingCosts, activityCosts, mock(StateManager.class)); + createInsertionCalculator(hardRouteLevelConstraint); vehicleRoutingProblem = mock(VehicleRoutingProblem.class); - } + } - private void createInsertionCalculator(HardRouteConstraint hardRouteLevelConstraint) { - ConstraintManager constraintManager = new ConstraintManager(mock(VehicleRoutingProblem.class), mock(RouteAndActivityStateGetter.class)); - constraintManager.addConstraint(hardRouteLevelConstraint); - insertionCalculator = new ShipmentInsertionCalculator(routingCosts, activityInsertionCostsCalculator, constraintManager); - } - - @Test - public void whenInsertingServiceWhileNoCapIsAvailable_itMustReturnTheCorrectInsertionIndex(){ - Delivery delivery = (Delivery) Delivery.Builder.newInstance("del").addSizeDimension(0, 41).setLocation(Location.newInstance("10,10")).build(); - Pickup pickup = (Pickup) Pickup.Builder.newInstance("pick").addSizeDimension(0, 15).setLocation(Location.newInstance("0,10")).build(); + private void createInsertionCalculator(HardRouteConstraint hardRouteLevelConstraint) { + ConstraintManager constraintManager = new ConstraintManager(mock(VehicleRoutingProblem.class), mock(RouteAndActivityStateGetter.class)); + constraintManager.addConstraint(hardRouteLevelConstraint); + insertionCalculator = new ShipmentInsertionCalculator(routingCosts, activityInsertionCostsCalculator, constraintManager); + } - VehicleType type = VehicleTypeImpl.Builder.newInstance("t").addCapacityDimension(0, 50).setCostPerDistance(1).build(); - VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("0,0")).setType(type).build(); + @Test + public void whenInsertingServiceWhileNoCapIsAvailable_itMustReturnTheCorrectInsertionIndex() { + Delivery delivery = (Delivery) Delivery.Builder.newInstance("del").addSizeDimension(0, 41).setLocation(Location.newInstance("10,10")).build(); + Pickup pickup = (Pickup) Pickup.Builder.newInstance("pick").addSizeDimension(0, 15).setLocation(Location.newInstance("0,10")).build(); + + VehicleType type = VehicleTypeImpl.Builder.newInstance("t").addCapacityDimension(0, 50).setCostPerDistance(1).build(); + VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("0,0")).setType(type).build(); final VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(delivery).addJob(pickup).addVehicle(vehicle).build(); VehicleRoute route = VehicleRoute.emptyRoute(); - route.setVehicleAndDepartureTime(vehicle, 0.0); - - Inserter inserter = new Inserter(new InsertionListeners(), vrp); - inserter.insertJob(delivery, new InsertionData(0,0,0,vehicle,null), route); + route.setVehicleAndDepartureTime(vehicle, 0.0); + + Inserter inserter = new Inserter(new InsertionListeners(), vrp); + inserter.insertJob(delivery, new InsertionData(0, 0, 0, vehicle, null), route); JobActivityFactory activityFactory = new JobActivityFactory() { @Override @@ -129,26 +129,26 @@ public class ServiceInsertionAndLoadConstraintsTest { } }; - StateManager stateManager = new StateManager(vrp); - stateManager.updateLoadStates(); - - ConstraintManager constraintManager = new ConstraintManager(vrp,stateManager); - constraintManager.addLoadConstraint(); - stateManager.informInsertionStarts(Arrays.asList(route), null); - - JobCalculatorSwitcher switcher = new JobCalculatorSwitcher(); - ServiceInsertionCalculator serviceInsertionCalc = new ServiceInsertionCalculator(routingCosts, activityInsertionCostsCalculator, constraintManager); + StateManager stateManager = new StateManager(vrp); + stateManager.updateLoadStates(); + + ConstraintManager constraintManager = new ConstraintManager(vrp, stateManager); + constraintManager.addLoadConstraint(); + stateManager.informInsertionStarts(Arrays.asList(route), null); + + JobCalculatorSwitcher switcher = new JobCalculatorSwitcher(); + ServiceInsertionCalculator serviceInsertionCalc = new ServiceInsertionCalculator(routingCosts, activityInsertionCostsCalculator, constraintManager); serviceInsertionCalc.setJobActivityFactory(activityFactory); - ShipmentInsertionCalculator insertionCalculator = new ShipmentInsertionCalculator(routingCosts, activityInsertionCostsCalculator, constraintManager); + ShipmentInsertionCalculator insertionCalculator = new ShipmentInsertionCalculator(routingCosts, activityInsertionCostsCalculator, constraintManager); insertionCalculator.setJobActivityFactory(activityFactory); - switcher.put(Pickup.class, serviceInsertionCalc); - switcher.put(Delivery.class, serviceInsertionCalc); - switcher.put(Shipment.class, insertionCalculator); + switcher.put(Pickup.class, serviceInsertionCalc); + switcher.put(Delivery.class, serviceInsertionCalc); + switcher.put(Shipment.class, insertionCalculator); - InsertionData iData = switcher.getInsertionData(route, pickup, vehicle, 0, DriverImpl.noDriver(), Double.MAX_VALUE); + InsertionData iData = switcher.getInsertionData(route, pickup, vehicle, 0, DriverImpl.noDriver(), Double.MAX_VALUE); + + assertEquals(1, iData.getDeliveryInsertionIndex()); + } - assertEquals(1, iData.getDeliveryInsertionIndex()); - } - } diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/ShipmentInsertionCalculatorTest.java b/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/ShipmentInsertionCalculatorTest.java index 94dea056..f972b55d 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/ShipmentInsertionCalculatorTest.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/ShipmentInsertionCalculatorTest.java @@ -60,72 +60,72 @@ import static org.mockito.Mockito.when; public class ShipmentInsertionCalculatorTest { - - VehicleRoutingTransportCosts routingCosts; + + VehicleRoutingTransportCosts routingCosts; VehicleRoutingProblem vehicleRoutingProblem; - - VehicleRoutingActivityCosts activityCosts = new VehicleRoutingActivityCosts(){ - @Override - public double getActivityCost(TourActivity tourAct, double arrivalTime,Driver driver, Vehicle vehicle) { - return 0; - } - - }; - - HardRouteConstraint hardRouteLevelConstraint = new HardRouteConstraint(){ + VehicleRoutingActivityCosts activityCosts = new VehicleRoutingActivityCosts() { - @Override - public boolean fulfilled(JobInsertionContext insertionContext) { - return true; - } - - }; - - ActivityInsertionCostsCalculator activityInsertionCostsCalculator; - - ShipmentInsertionCalculator insertionCalculator; - - Vehicle vehicle; - - @Before - public void doBefore(){ - routingCosts = CostFactory.createManhattanCosts(); - VehicleType type = VehicleTypeImpl.Builder.newInstance("t").addCapacityDimension(0, 2).setCostPerDistance(1).build(); - vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("0,0")).setType(type).build(); - activityInsertionCostsCalculator = new LocalActivityInsertionCostsCalculator(routingCosts, activityCosts); - createInsertionCalculator(hardRouteLevelConstraint); + @Override + public double getActivityCost(TourActivity tourAct, double arrivalTime, Driver driver, Vehicle vehicle) { + return 0; + } + + }; + + HardRouteConstraint hardRouteLevelConstraint = new HardRouteConstraint() { + + @Override + public boolean fulfilled(JobInsertionContext insertionContext) { + return true; + } + + }; + + ActivityInsertionCostsCalculator activityInsertionCostsCalculator; + + ShipmentInsertionCalculator insertionCalculator; + + Vehicle vehicle; + + @Before + public void doBefore() { + routingCosts = CostFactory.createManhattanCosts(); + VehicleType type = VehicleTypeImpl.Builder.newInstance("t").addCapacityDimension(0, 2).setCostPerDistance(1).build(); + vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("0,0")).setType(type).build(); + activityInsertionCostsCalculator = new LocalActivityInsertionCostsCalculator(routingCosts, activityCosts, mock(StateManager.class)); + createInsertionCalculator(hardRouteLevelConstraint); vehicleRoutingProblem = mock(VehicleRoutingProblem.class); - } + } - private void createInsertionCalculator(HardRouteConstraint hardRouteLevelConstraint) { - ConstraintManager constraintManager = new ConstraintManager(mock(VehicleRoutingProblem.class), mock(RouteAndActivityStateGetter.class)); - constraintManager.addConstraint(hardRouteLevelConstraint); - insertionCalculator = new ShipmentInsertionCalculator(routingCosts, activityInsertionCostsCalculator, constraintManager); - } - - @Test - public void whenCalculatingInsertionCostsOfShipment_itShouldReturnCorrectCostValue(){ - Shipment shipment = Shipment.Builder.newInstance("s").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("0,10").build()).setDeliveryLocation(Location.newInstance("10,0")).build(); - VehicleRoute route = VehicleRoute.emptyRoute(); + private void createInsertionCalculator(HardRouteConstraint hardRouteLevelConstraint) { + ConstraintManager constraintManager = new ConstraintManager(mock(VehicleRoutingProblem.class), mock(RouteAndActivityStateGetter.class)); + constraintManager.addConstraint(hardRouteLevelConstraint); + insertionCalculator = new ShipmentInsertionCalculator(routingCosts, activityInsertionCostsCalculator, constraintManager); + } + + @Test + public void whenCalculatingInsertionCostsOfShipment_itShouldReturnCorrectCostValue() { + Shipment shipment = Shipment.Builder.newInstance("s").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("0,10").build()).setDeliveryLocation(Location.newInstance("10,0")).build(); + VehicleRoute route = VehicleRoute.emptyRoute(); JobActivityFactory activityFactory = mock(JobActivityFactory.class); List activities = new ArrayList(); activities.add(new PickupShipment(shipment)); activities.add(new DeliverShipment(shipment)); when(activityFactory.createActivities(shipment)).thenReturn(activities); insertionCalculator.setJobActivityFactory(activityFactory); - InsertionData iData = insertionCalculator.getInsertionData(route, shipment, vehicle, 0.0, null, Double.MAX_VALUE); - assertEquals(40.0,iData.getInsertionCost(),0.05); - } - - @Test - public void whenCalculatingInsertionIntoExistingRoute_itShouldReturnCorrectCosts(){ - Shipment shipment = Shipment.Builder.newInstance("s").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("0,10").build()).setDeliveryLocation(Location.newInstance("10,0")).build(); - Shipment shipment2 = Shipment.Builder.newInstance("s2").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("10,10").build()).setDeliveryLocation(Location.newInstance("0,0")).build(); - VehicleRoute route = VehicleRoute.emptyRoute(); - when(vehicleRoutingProblem.copyAndGetActivities(shipment)).thenReturn(getTourActivities(shipment)); - new Inserter(new InsertionListeners(), vehicleRoutingProblem).insertJob(shipment, new InsertionData(0,0,0,vehicle,null), route); + InsertionData iData = insertionCalculator.getInsertionData(route, shipment, vehicle, 0.0, null, Double.MAX_VALUE); + assertEquals(40.0, iData.getInsertionCost(), 0.05); + } + + @Test + public void whenCalculatingInsertionIntoExistingRoute_itShouldReturnCorrectCosts() { + Shipment shipment = Shipment.Builder.newInstance("s").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("0,10").build()).setDeliveryLocation(Location.newInstance("10,0")).build(); + Shipment shipment2 = Shipment.Builder.newInstance("s2").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("10,10").build()).setDeliveryLocation(Location.newInstance("0,0")).build(); + VehicleRoute route = VehicleRoute.emptyRoute(); + when(vehicleRoutingProblem.copyAndGetActivities(shipment)).thenReturn(getTourActivities(shipment)); + new Inserter(new InsertionListeners(), vehicleRoutingProblem).insertJob(shipment, new InsertionData(0, 0, 0, vehicle, null), route); JobActivityFactory activityFactory = mock(JobActivityFactory.class); List activities = new ArrayList(); @@ -134,11 +134,11 @@ public class ShipmentInsertionCalculatorTest { when(activityFactory.createActivities(shipment2)).thenReturn(activities); insertionCalculator.setJobActivityFactory(activityFactory); - InsertionData iData = insertionCalculator.getInsertionData(route, shipment2, vehicle, 0.0, null, Double.MAX_VALUE); - assertEquals(0.0,iData.getInsertionCost(),0.05); - assertEquals(1,iData.getPickupInsertionIndex()); - assertEquals(2,iData.getDeliveryInsertionIndex()); - } + InsertionData iData = insertionCalculator.getInsertionData(route, shipment2, vehicle, 0.0, null, Double.MAX_VALUE); + assertEquals(0.0, iData.getInsertionCost(), 0.05); + assertEquals(1, iData.getPickupInsertionIndex()); + assertEquals(2, iData.getDeliveryInsertionIndex()); + } private List getTourActivities(Shipment shipment) { List acts = new ArrayList(); @@ -150,20 +150,20 @@ public class ShipmentInsertionCalculatorTest { } @Test - public void whenInsertingShipmentInRouteWithNotEnoughCapacity_itShouldReturnNoInsertion(){ - Shipment shipment = Shipment.Builder.newInstance("s").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("0,10").build()).setDeliveryLocation(Location.newInstance("10,0")).build(); - Shipment shipment2 = Shipment.Builder.newInstance("s2").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("10,10").build()).setDeliveryLocation(Location.newInstance("0,0")).build(); - VehicleRoute route = VehicleRoute.emptyRoute(); + public void whenInsertingShipmentInRouteWithNotEnoughCapacity_itShouldReturnNoInsertion() { + Shipment shipment = Shipment.Builder.newInstance("s").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("0,10").build()).setDeliveryLocation(Location.newInstance("10,0")).build(); + Shipment shipment2 = Shipment.Builder.newInstance("s2").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("10,10").build()).setDeliveryLocation(Location.newInstance("0,0")).build(); + VehicleRoute route = VehicleRoute.emptyRoute(); when(vehicleRoutingProblem.copyAndGetActivities(shipment)).thenReturn(getTourActivities(shipment)); - new Inserter(new InsertionListeners(), vehicleRoutingProblem).insertJob(shipment, new InsertionData(0,0,0,vehicle,null), route); - createInsertionCalculator(new HardRouteConstraint() { - - @Override - public boolean fulfilled(JobInsertionContext insertionContext) { - return false; - } - - }); + new Inserter(new InsertionListeners(), vehicleRoutingProblem).insertJob(shipment, new InsertionData(0, 0, 0, vehicle, null), route); + createInsertionCalculator(new HardRouteConstraint() { + + @Override + public boolean fulfilled(JobInsertionContext insertionContext) { + return false; + } + + }); JobActivityFactory activityFactory = mock(JobActivityFactory.class); List activities = new ArrayList(); @@ -173,23 +173,23 @@ public class ShipmentInsertionCalculatorTest { insertionCalculator.setJobActivityFactory(activityFactory); InsertionData iData = insertionCalculator.getInsertionData(route, shipment2, vehicle, 0.0, null, Double.MAX_VALUE); - assertEquals(InsertionData.createEmptyInsertionData(),iData); - - } - - - @Test - public void whenInsertingThirdShipment_itShouldCalcCorrectVal(){ - Shipment shipment = Shipment.Builder.newInstance("s").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("0,10").build()).setDeliveryLocation(Location.newInstance("10,0")).build(); - Shipment shipment2 = Shipment.Builder.newInstance("s2").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("10,10").build()).setDeliveryLocation(Location.newInstance("0,0")).build(); - Shipment shipment3 = Shipment.Builder.newInstance("s3").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("0,0").build()).setDeliveryLocation(Location.newInstance("9,10")).build(); - - VehicleRoute route = VehicleRoute.emptyRoute(); + assertEquals(InsertionData.createEmptyInsertionData(), iData); + + } + + + @Test + public void whenInsertingThirdShipment_itShouldCalcCorrectVal() { + Shipment shipment = Shipment.Builder.newInstance("s").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("0,10").build()).setDeliveryLocation(Location.newInstance("10,0")).build(); + Shipment shipment2 = Shipment.Builder.newInstance("s2").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("10,10").build()).setDeliveryLocation(Location.newInstance("0,0")).build(); + Shipment shipment3 = Shipment.Builder.newInstance("s3").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("0,0").build()).setDeliveryLocation(Location.newInstance("9,10")).build(); + + VehicleRoute route = VehicleRoute.emptyRoute(); when(vehicleRoutingProblem.copyAndGetActivities(shipment)).thenReturn(getTourActivities(shipment)); when(vehicleRoutingProblem.copyAndGetActivities(shipment2)).thenReturn(getTourActivities(shipment2)); - Inserter inserter = new Inserter(new InsertionListeners(),vehicleRoutingProblem ); - inserter.insertJob(shipment, new InsertionData(0,0,0,vehicle,null), route); - inserter.insertJob(shipment2, new InsertionData(0,1,2,vehicle,null),route); + Inserter inserter = new Inserter(new InsertionListeners(), vehicleRoutingProblem); + inserter.insertJob(shipment, new InsertionData(0, 0, 0, vehicle, null), route); + inserter.insertJob(shipment2, new InsertionData(0, 1, 2, vehicle, null), route); JobActivityFactory activityFactory = mock(JobActivityFactory.class); List activities = new ArrayList(); @@ -198,23 +198,23 @@ public class ShipmentInsertionCalculatorTest { when(activityFactory.createActivities(shipment3)).thenReturn(activities); insertionCalculator.setJobActivityFactory(activityFactory); - InsertionData iData = insertionCalculator.getInsertionData(route, shipment3, vehicle, 0.0, null, Double.MAX_VALUE); - assertEquals(0.0,iData.getInsertionCost(),0.05); - assertEquals(0,iData.getPickupInsertionIndex()); - assertEquals(1,iData.getDeliveryInsertionIndex()); - } - - @Test - public void whenInsertingThirdShipment_itShouldCalcCorrectVal2(){ - Shipment shipment = Shipment.Builder.newInstance("s").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("0,10").build()).setDeliveryLocation(Location.newInstance("10,0")).build(); - Shipment shipment2 = Shipment.Builder.newInstance("s2").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("10,10").build()).setDeliveryLocation(Location.newInstance("0,0")).build(); - Shipment shipment3 = Shipment.Builder.newInstance("s3").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("0,0").build()).setDeliveryLocation(Location.newInstance("9,9")).build(); + InsertionData iData = insertionCalculator.getInsertionData(route, shipment3, vehicle, 0.0, null, Double.MAX_VALUE); + assertEquals(0.0, iData.getInsertionCost(), 0.05); + assertEquals(0, iData.getPickupInsertionIndex()); + assertEquals(1, iData.getDeliveryInsertionIndex()); + } + + @Test + public void whenInsertingThirdShipment_itShouldCalcCorrectVal2() { + Shipment shipment = Shipment.Builder.newInstance("s").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("0,10").build()).setDeliveryLocation(Location.newInstance("10,0")).build(); + Shipment shipment2 = Shipment.Builder.newInstance("s2").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("10,10").build()).setDeliveryLocation(Location.newInstance("0,0")).build(); + Shipment shipment3 = Shipment.Builder.newInstance("s3").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("0,0").build()).setDeliveryLocation(Location.newInstance("9,9")).build(); when(vehicleRoutingProblem.copyAndGetActivities(shipment)).thenReturn(getTourActivities(shipment)); when(vehicleRoutingProblem.copyAndGetActivities(shipment2)).thenReturn(getTourActivities(shipment2)); - VehicleRoute route = VehicleRoute.emptyRoute(); - Inserter inserter = new Inserter(new InsertionListeners(), vehicleRoutingProblem); - inserter.insertJob(shipment, new InsertionData(0,0,0,vehicle,null), route); - inserter.insertJob(shipment2, new InsertionData(0,1,2,vehicle,null),route); + VehicleRoute route = VehicleRoute.emptyRoute(); + Inserter inserter = new Inserter(new InsertionListeners(), vehicleRoutingProblem); + inserter.insertJob(shipment, new InsertionData(0, 0, 0, vehicle, null), route); + inserter.insertJob(shipment2, new InsertionData(0, 1, 2, vehicle, null), route); JobActivityFactory activityFactory = mock(JobActivityFactory.class); List activities = new ArrayList(); @@ -225,78 +225,78 @@ public class ShipmentInsertionCalculatorTest { InsertionData iData = insertionCalculator.getInsertionData(route, shipment3, vehicle, 0.0, null, Double.MAX_VALUE); - assertEquals(2.0,iData.getInsertionCost(),0.05); - assertEquals(0,iData.getPickupInsertionIndex()); - assertEquals(1,iData.getDeliveryInsertionIndex()); - } - - @Test - public void whenInstertingShipmentWithLoadConstraintWhereCapIsNotSufficient_capConstraintsAreFulfilled(){ - Shipment shipment = Shipment.Builder.newInstance("s").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("0,10").build()).setDeliveryLocation(Location.newInstance("10,0")).build(); - Shipment shipment2 = Shipment.Builder.newInstance("s2").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("10,10").build()).setDeliveryLocation(Location.newInstance("0,0")).build(); - Shipment shipment3 = Shipment.Builder.newInstance("s3").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("0,0").build()).setDeliveryLocation(Location.newInstance("9,9")).build(); + assertEquals(2.0, iData.getInsertionCost(), 0.05); + assertEquals(0, iData.getPickupInsertionIndex()); + assertEquals(1, iData.getDeliveryInsertionIndex()); + } + + @Test + public void whenInstertingShipmentWithLoadConstraintWhereCapIsNotSufficient_capConstraintsAreFulfilled() { + Shipment shipment = Shipment.Builder.newInstance("s").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("0,10").build()).setDeliveryLocation(Location.newInstance("10,0")).build(); + Shipment shipment2 = Shipment.Builder.newInstance("s2").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("10,10").build()).setDeliveryLocation(Location.newInstance("0,0")).build(); + Shipment shipment3 = Shipment.Builder.newInstance("s3").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("0,0").build()).setDeliveryLocation(Location.newInstance("9,9")).build(); VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); VehicleRoutingProblem vrp = vrpBuilder.addJob(shipment).addJob(shipment2).addJob(shipment3).build(); VehicleRoute route = VehicleRoute.emptyRoute(); - route.setVehicleAndDepartureTime(vehicle, 0.0); - - Inserter inserter = new Inserter(new InsertionListeners(), vrp); - inserter.insertJob(shipment, new InsertionData(0,0,0,vehicle,null), route); - inserter.insertJob(shipment2, new InsertionData(0,1,2,vehicle,null), route); + route.setVehicleAndDepartureTime(vehicle, 0.0); + + Inserter inserter = new Inserter(new InsertionListeners(), vrp); + inserter.insertJob(shipment, new InsertionData(0, 0, 0, vehicle, null), route); + inserter.insertJob(shipment2, new InsertionData(0, 1, 2, vehicle, null), route); StateManager stateManager = new StateManager(vrp); - stateManager.updateLoadStates(); - stateManager.informInsertionStarts(Arrays.asList(route), null); - - ConstraintManager constraintManager = new ConstraintManager(vrp,stateManager); - constraintManager.addConstraint(new PickupAndDeliverShipmentLoadActivityLevelConstraint(stateManager),Priority.CRITICAL); - constraintManager.addConstraint(new ShipmentPickupsFirstConstraint(),Priority.CRITICAL); - - ShipmentInsertionCalculator insertionCalculator = new ShipmentInsertionCalculator(routingCosts, activityInsertionCostsCalculator, - constraintManager); + stateManager.updateLoadStates(); + stateManager.informInsertionStarts(Arrays.asList(route), null); + + ConstraintManager constraintManager = new ConstraintManager(vrp, stateManager); + constraintManager.addConstraint(new PickupAndDeliverShipmentLoadActivityLevelConstraint(stateManager), Priority.CRITICAL); + constraintManager.addConstraint(new ShipmentPickupsFirstConstraint(), Priority.CRITICAL); + + ShipmentInsertionCalculator insertionCalculator = new ShipmentInsertionCalculator(routingCosts, activityInsertionCostsCalculator, + constraintManager); insertionCalculator.setJobActivityFactory(vrp.getJobActivityFactory()); - InsertionData iData = insertionCalculator.getInsertionData(route, shipment3, vehicle, 0.0, DriverImpl.noDriver(), Double.MAX_VALUE); - assertTrue(iData instanceof InsertionData.NoInsertionFound); - - } - - @Test - public void whenInsertingServiceWhileNoCapIsAvailable_itMustReturnNoInsertionData(){ - Shipment shipment = Shipment.Builder.newInstance("s").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("0,10").build()).setDeliveryLocation(Location.newInstance("0,0")).build(); - Shipment shipment2 = Shipment.Builder.newInstance("s2").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("10,10").build()).setDeliveryLocation(Location.newInstance("0,0")).build(); + InsertionData iData = insertionCalculator.getInsertionData(route, shipment3, vehicle, 0.0, DriverImpl.noDriver(), Double.MAX_VALUE); + assertTrue(iData instanceof InsertionData.NoInsertionFound); + + } + + @Test + public void whenInsertingServiceWhileNoCapIsAvailable_itMustReturnNoInsertionData() { + Shipment shipment = Shipment.Builder.newInstance("s").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("0,10").build()).setDeliveryLocation(Location.newInstance("0,0")).build(); + Shipment shipment2 = Shipment.Builder.newInstance("s2").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("10,10").build()).setDeliveryLocation(Location.newInstance("0,0")).build(); VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); VehicleRoutingProblem vrp = vrpBuilder.addJob(shipment).addJob(shipment2).build(); VehicleRoute route = VehicleRoute.emptyRoute(); - route.setVehicleAndDepartureTime(vehicle, 0.0); + route.setVehicleAndDepartureTime(vehicle, 0.0); - Inserter inserter = new Inserter(new InsertionListeners(), vrp); - - inserter.insertJob(shipment, new InsertionData(0,0,0,vehicle,null), route); - inserter.insertJob(shipment2, new InsertionData(0,1,2,vehicle,null), route); + Inserter inserter = new Inserter(new InsertionListeners(), vrp); - StateManager stateManager = new StateManager(vrp); - stateManager.updateLoadStates(); - stateManager.informInsertionStarts(Arrays.asList(route), null); + inserter.insertJob(shipment, new InsertionData(0, 0, 0, vehicle, null), route); + inserter.insertJob(shipment2, new InsertionData(0, 1, 2, vehicle, null), route); + + StateManager stateManager = new StateManager(vrp); + stateManager.updateLoadStates(); + stateManager.informInsertionStarts(Arrays.asList(route), null); + + ConstraintManager constraintManager = new ConstraintManager(vrp, stateManager); + constraintManager.addLoadConstraint(); + + stateManager.informInsertionStarts(Arrays.asList(route), null); + + JobCalculatorSwitcher switcher = new JobCalculatorSwitcher(); + ServiceInsertionCalculator serviceInsertionCalc = new ServiceInsertionCalculator(routingCosts, activityInsertionCostsCalculator, constraintManager); + ShipmentInsertionCalculator insertionCalculator = new ShipmentInsertionCalculator(routingCosts, activityInsertionCostsCalculator, constraintManager); + switcher.put(Pickup.class, serviceInsertionCalc); + switcher.put(Service.class, serviceInsertionCalc); + switcher.put(Shipment.class, insertionCalculator); - ConstraintManager constraintManager = new ConstraintManager(vrp,stateManager); - constraintManager.addLoadConstraint(); - - stateManager.informInsertionStarts(Arrays.asList(route), null); - - JobCalculatorSwitcher switcher = new JobCalculatorSwitcher(); - ServiceInsertionCalculator serviceInsertionCalc = new ServiceInsertionCalculator(routingCosts, activityInsertionCostsCalculator, constraintManager); - ShipmentInsertionCalculator insertionCalculator = new ShipmentInsertionCalculator(routingCosts, activityInsertionCostsCalculator, constraintManager); - switcher.put(Pickup.class, serviceInsertionCalc); - switcher.put(Service.class, serviceInsertionCalc); - switcher.put(Shipment.class, insertionCalculator); - // Service service = Service.Builder.newInstance("pick", 1).setLocationId("5,5").build(); - Pickup service = (Pickup)Pickup.Builder.newInstance("pick").addSizeDimension(0, 1).setLocation(Location.newInstance("5,5")).build(); + Pickup service = (Pickup) Pickup.Builder.newInstance("pick").addSizeDimension(0, 1).setLocation(Location.newInstance("5,5")).build(); JobActivityFactory activityFactory = mock(JobActivityFactory.class); List activities = new ArrayList(); @@ -307,9 +307,9 @@ public class ShipmentInsertionCalculatorTest { InsertionData iData = switcher.getInsertionData(route, service, vehicle, 0, DriverImpl.noDriver(), Double.MAX_VALUE); // routeActVisitor.visit(route); - - assertEquals(3, iData.getDeliveryInsertionIndex()); - } - - + + assertEquals(3, iData.getDeliveryInsertionIndex()); + } + + } diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/TestAuxilliaryCostCalculator.java b/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/TestAuxilliaryCostCalculator.java index 01716a32..720b93ac 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/TestAuxilliaryCostCalculator.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/TestAuxilliaryCostCalculator.java @@ -33,91 +33,91 @@ import static org.mockito.Mockito.when; public class TestAuxilliaryCostCalculator { - private VehicleRoutingTransportCosts routingCosts; - - private VehicleRoutingActivityCosts actCosts; - - private Vehicle vehicle; - - @Before - public void doBefore(){ - vehicle = mock(Vehicle.class); - - routingCosts = mock(VehicleRoutingTransportCosts.class); - actCosts = mock(VehicleRoutingActivityCosts.class); - - when(routingCosts.getTransportCost(loc("i"), loc("j"), 0.0, null, vehicle)).thenReturn(2.0); - when(routingCosts.getTransportTime(loc("i"), loc("j"), 0.0, null, vehicle)).thenReturn(0.0); - when(routingCosts.getTransportCost(loc("i"), loc("k"), 0.0, null, vehicle)).thenReturn(3.0); - when(routingCosts.getTransportTime(loc("i"), loc("k"), 0.0, null, vehicle)).thenReturn(0.0); - when(routingCosts.getTransportCost(loc("k"), loc("j"), 0.0, null, vehicle)).thenReturn(3.0); - when(routingCosts.getTransportTime(loc("k"), loc("j"), 0.0, null, vehicle)).thenReturn(0.0); - } + private VehicleRoutingTransportCosts routingCosts; + + private VehicleRoutingActivityCosts actCosts; + + private Vehicle vehicle; + + @Before + public void doBefore() { + vehicle = mock(Vehicle.class); + + routingCosts = mock(VehicleRoutingTransportCosts.class); + actCosts = mock(VehicleRoutingActivityCosts.class); + + when(routingCosts.getTransportCost(loc("i"), loc("j"), 0.0, null, vehicle)).thenReturn(2.0); + when(routingCosts.getTransportTime(loc("i"), loc("j"), 0.0, null, vehicle)).thenReturn(0.0); + when(routingCosts.getTransportCost(loc("i"), loc("k"), 0.0, null, vehicle)).thenReturn(3.0); + when(routingCosts.getTransportTime(loc("i"), loc("k"), 0.0, null, vehicle)).thenReturn(0.0); + when(routingCosts.getTransportCost(loc("k"), loc("j"), 0.0, null, vehicle)).thenReturn(3.0); + when(routingCosts.getTransportTime(loc("k"), loc("j"), 0.0, null, vehicle)).thenReturn(0.0); + } private Location loc(String i) { return Location.Builder.newInstance().setId(i).build(); } - - @Test - public void whenRouteIsClosed_itCalculatesCostUpToEnd_v1(){ - TourActivity prevAct = mock(TourActivity.class); - when(prevAct.getLocation()).thenReturn(loc("i")); - TourActivity nextAct = mock(TourActivity.class); - when(nextAct.getLocation()).thenReturn(loc("j")); - TourActivity newAct = mock(TourActivity.class); - when(newAct.getLocation()).thenReturn(loc("k")); - - when(vehicle.isReturnToDepot()).thenReturn(true); - - AuxilliaryCostCalculator aCalc = new AuxilliaryCostCalculator(routingCosts, actCosts); - double costs = aCalc.costOfPath(Arrays.asList(prevAct,newAct,nextAct), 0.0, null, vehicle); - assertEquals(6.0,costs,0.01); - } - - @Test - public void whenRouteIsClosed_itCalculatesCostUpToEnd_v2(){ - TourActivity prevAct = mock(TourActivity.class); - when(prevAct.getLocation()).thenReturn(loc("i")); - End nextAct = new End("j", 0.0, 0.0); - TourActivity newAct = mock(TourActivity.class); - when(newAct.getLocation()).thenReturn(loc("k")); - - when(vehicle.isReturnToDepot()).thenReturn(true); - - AuxilliaryCostCalculator aCalc = new AuxilliaryCostCalculator(routingCosts, actCosts); - double costs = aCalc.costOfPath(Arrays.asList(prevAct,newAct,nextAct), 0.0, null, vehicle); - assertEquals(6.0,costs,0.01); - } - - @Test - public void whenRouteIsOpen_itCalculatesCostUpToEnd_v1(){ - TourActivity prevAct = mock(TourActivity.class); - when(prevAct.getLocation()).thenReturn(loc("i")); - TourActivity nextAct = mock(TourActivity.class); - when(nextAct.getLocation()).thenReturn(loc("j")); - TourActivity newAct = mock(TourActivity.class); - when(newAct.getLocation()).thenReturn(loc("k")); - - when(vehicle.isReturnToDepot()).thenReturn(false); - - AuxilliaryCostCalculator aCalc = new AuxilliaryCostCalculator(routingCosts, actCosts); - double costs = aCalc.costOfPath(Arrays.asList(prevAct,newAct,nextAct), 0.0, null, vehicle); - assertEquals(6.0,costs,0.01); - } - - @Test - public void whenRouteIsOpen_itCalculatesCostUpToEnd_v2(){ - TourActivity prevAct = mock(TourActivity.class); - when(prevAct.getLocation()).thenReturn(loc("i")); - End nextAct = End.newInstance("j", 0.0, 0.0); - TourActivity newAct = mock(TourActivity.class); - when(newAct.getLocation()).thenReturn(loc("k")); - - when(vehicle.isReturnToDepot()).thenReturn(false); - - AuxilliaryCostCalculator aCalc = new AuxilliaryCostCalculator(routingCosts, actCosts); - double costs = aCalc.costOfPath(Arrays.asList(prevAct,newAct,nextAct), 0.0, null, vehicle); - assertEquals(3.0,costs,0.01); - } + + @Test + public void whenRouteIsClosed_itCalculatesCostUpToEnd_v1() { + TourActivity prevAct = mock(TourActivity.class); + when(prevAct.getLocation()).thenReturn(loc("i")); + TourActivity nextAct = mock(TourActivity.class); + when(nextAct.getLocation()).thenReturn(loc("j")); + TourActivity newAct = mock(TourActivity.class); + when(newAct.getLocation()).thenReturn(loc("k")); + + when(vehicle.isReturnToDepot()).thenReturn(true); + + AuxilliaryCostCalculator aCalc = new AuxilliaryCostCalculator(routingCosts, actCosts); + double costs = aCalc.costOfPath(Arrays.asList(prevAct, newAct, nextAct), 0.0, null, vehicle); + assertEquals(6.0, costs, 0.01); + } + + @Test + public void whenRouteIsClosed_itCalculatesCostUpToEnd_v2() { + TourActivity prevAct = mock(TourActivity.class); + when(prevAct.getLocation()).thenReturn(loc("i")); + End nextAct = new End("j", 0.0, 0.0); + TourActivity newAct = mock(TourActivity.class); + when(newAct.getLocation()).thenReturn(loc("k")); + + when(vehicle.isReturnToDepot()).thenReturn(true); + + AuxilliaryCostCalculator aCalc = new AuxilliaryCostCalculator(routingCosts, actCosts); + double costs = aCalc.costOfPath(Arrays.asList(prevAct, newAct, nextAct), 0.0, null, vehicle); + assertEquals(6.0, costs, 0.01); + } + + @Test + public void whenRouteIsOpen_itCalculatesCostUpToEnd_v1() { + TourActivity prevAct = mock(TourActivity.class); + when(prevAct.getLocation()).thenReturn(loc("i")); + TourActivity nextAct = mock(TourActivity.class); + when(nextAct.getLocation()).thenReturn(loc("j")); + TourActivity newAct = mock(TourActivity.class); + when(newAct.getLocation()).thenReturn(loc("k")); + + when(vehicle.isReturnToDepot()).thenReturn(false); + + AuxilliaryCostCalculator aCalc = new AuxilliaryCostCalculator(routingCosts, actCosts); + double costs = aCalc.costOfPath(Arrays.asList(prevAct, newAct, nextAct), 0.0, null, vehicle); + assertEquals(6.0, costs, 0.01); + } + + @Test + public void whenRouteIsOpen_itCalculatesCostUpToEnd_v2() { + TourActivity prevAct = mock(TourActivity.class); + when(prevAct.getLocation()).thenReturn(loc("i")); + End nextAct = End.newInstance("j", 0.0, 0.0); + TourActivity newAct = mock(TourActivity.class); + when(newAct.getLocation()).thenReturn(loc("k")); + + when(vehicle.isReturnToDepot()).thenReturn(false); + + AuxilliaryCostCalculator aCalc = new AuxilliaryCostCalculator(routingCosts, actCosts); + double costs = aCalc.costOfPath(Arrays.asList(prevAct, newAct, nextAct), 0.0, null, vehicle); + assertEquals(3.0, costs, 0.01); + } } diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/TestCalculatesServiceInsertion.java b/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/TestCalculatesServiceInsertion.java index 3527e5bc..28dde653 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/TestCalculatesServiceInsertion.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/TestCalculatesServiceInsertion.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.recreate; @@ -50,209 +50,207 @@ import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.mock; - - public class TestCalculatesServiceInsertion { - - ServiceInsertionCalculator serviceInsertion; - - VehicleRoutingTransportCosts costs; - - VehicleImpl vehicle; - - VehicleImpl newVehicle; - private Service first; + ServiceInsertionCalculator serviceInsertion; - private Service third; + VehicleRoutingTransportCosts costs; - private Service second; + VehicleImpl vehicle; - private StateManager states; + VehicleImpl newVehicle; + + private Service first; + + private Service third; + + private Service second; + + private StateManager states; + + private NoDriver driver; - private NoDriver driver; - private VehicleRoutingProblem vrp; - - @Before - public void setup(){ - VehicleType t1 = VehicleTypeImpl.Builder.newInstance("t1").addCapacityDimension(0, 1000).setCostPerDistance(1.0).build(); - vehicle = VehicleImpl.Builder.newInstance("vehicle").setLatestArrival(100.0).setStartLocation(Location.newInstance("0,0")).setType(t1).build(); - - VehicleType t2 = VehicleTypeImpl.Builder.newInstance("t2").addCapacityDimension(0, 1000).setCostPerDistance(2.0).build(); - newVehicle = VehicleImpl.Builder.newInstance("newVehicle").setLatestArrival(100.0).setStartLocation(Location.newInstance("0,0")).setType(t2).build(); - - driver = DriverImpl.noDriver(); - - final Locations locations = new Locations(){ + @Before + public void setup() { - @Override - public Coordinate getCoord(String id) { - //assume: locationId="x,y" - String[] splitted = id.split(","); - return Coordinate.newInstance(Double.parseDouble(splitted[0]), - Double.parseDouble(splitted[1])); - } - - }; - costs = new AbstractForwardVehicleRoutingTransportCosts() { - - @Override - public double getTransportTime(Location from, Location to,double departureTime, Driver driver, Vehicle vehicle) { - return ManhattanDistanceCalculator.calculateDistance(locations.getCoord(from.getId()), locations.getCoord(to.getId())); - } - - @Override - public double getTransportCost(Location from, Location to, double departureTime, Driver driver, Vehicle vehicle) { - return vehicle.getType().getVehicleCostParams().perDistanceUnit*ManhattanDistanceCalculator.calculateDistance(locations.getCoord(from.getId()), locations.getCoord(to.getId())); - } - }; + VehicleType t1 = VehicleTypeImpl.Builder.newInstance("t1").addCapacityDimension(0, 1000).setCostPerDistance(1.0).build(); + vehicle = VehicleImpl.Builder.newInstance("vehicle").setLatestArrival(100.0).setStartLocation(Location.newInstance("0,0")).setType(t1).build(); - - first = Service.Builder.newInstance("1").addSizeDimension(0, 0).setLocation(Location.newInstance("0,10")).setTimeWindow(TimeWindow.newInstance(0.0, 100.0)).build(); - second = Service.Builder.newInstance("2").addSizeDimension(0, 0).setLocation(Location.newInstance("10,10")).setTimeWindow(TimeWindow.newInstance(0.0, 100.0)).build(); - third = Service.Builder.newInstance("3").addSizeDimension(0, 0).setLocation(Location.newInstance("10,0")).setTimeWindow(TimeWindow.newInstance(0.0, 100.0)).build(); - - Collection jobs = new ArrayList(); - jobs.add(first); - jobs.add(third); - jobs.add(second); - - vrp = VehicleRoutingProblem.Builder.newInstance().addAllJobs(jobs) - .addVehicle(vehicle).setRoutingCost(costs).build(); - - states = new StateManager(vrp); - states.updateLoadStates(); - states.updateTimeWindowStates(); - - ConstraintManager cManager = new ConstraintManager(vrp,states); - cManager.addLoadConstraint(); - cManager.addTimeWindowConstraint(); - - VehicleRoutingActivityCosts actCosts = mock(VehicleRoutingActivityCosts.class); - - serviceInsertion = new ServiceInsertionCalculator(costs, new LocalActivityInsertionCostsCalculator(costs, actCosts), cManager); - serviceInsertion.setJobActivityFactory(new JobActivityFactory() { + VehicleType t2 = VehicleTypeImpl.Builder.newInstance("t2").addCapacityDimension(0, 1000).setCostPerDistance(2.0).build(); + newVehicle = VehicleImpl.Builder.newInstance("newVehicle").setLatestArrival(100.0).setStartLocation(Location.newInstance("0,0")).setType(t2).build(); + + driver = DriverImpl.noDriver(); + + final Locations locations = new Locations() { + + @Override + public Coordinate getCoord(String id) { + //assume: locationId="x,y" + String[] splitted = id.split(","); + return Coordinate.newInstance(Double.parseDouble(splitted[0]), + Double.parseDouble(splitted[1])); + } + + }; + costs = new AbstractForwardVehicleRoutingTransportCosts() { + + @Override + public double getTransportTime(Location from, Location to, double departureTime, Driver driver, Vehicle vehicle) { + return ManhattanDistanceCalculator.calculateDistance(locations.getCoord(from.getId()), locations.getCoord(to.getId())); + } + + @Override + public double getTransportCost(Location from, Location to, double departureTime, Driver driver, Vehicle vehicle) { + return vehicle.getType().getVehicleCostParams().perDistanceUnit * ManhattanDistanceCalculator.calculateDistance(locations.getCoord(from.getId()), locations.getCoord(to.getId())); + } + }; + + + first = Service.Builder.newInstance("1").addSizeDimension(0, 0).setLocation(Location.newInstance("0,10")).setTimeWindow(TimeWindow.newInstance(0.0, 100.0)).build(); + second = Service.Builder.newInstance("2").addSizeDimension(0, 0).setLocation(Location.newInstance("10,10")).setTimeWindow(TimeWindow.newInstance(0.0, 100.0)).build(); + third = Service.Builder.newInstance("3").addSizeDimension(0, 0).setLocation(Location.newInstance("10,0")).setTimeWindow(TimeWindow.newInstance(0.0, 100.0)).build(); + + Collection jobs = new ArrayList(); + jobs.add(first); + jobs.add(third); + jobs.add(second); + + vrp = VehicleRoutingProblem.Builder.newInstance().addAllJobs(jobs) + .addVehicle(vehicle).setRoutingCost(costs).build(); + + states = new StateManager(vrp); + states.updateLoadStates(); + states.updateTimeWindowStates(); + + ConstraintManager cManager = new ConstraintManager(vrp, states); + cManager.addLoadConstraint(); + cManager.addTimeWindowConstraint(); + + VehicleRoutingActivityCosts actCosts = mock(VehicleRoutingActivityCosts.class); + + serviceInsertion = new ServiceInsertionCalculator(costs, new LocalActivityInsertionCostsCalculator(costs, actCosts, states), cManager); + serviceInsertion.setJobActivityFactory(new JobActivityFactory() { @Override public List createActivities(Job job) { return vrp.copyAndGetActivities(job); } }); - } - - @Test - public void whenInsertingTheFirstJobInAnEmptyTourWithVehicle_itCalculatesMarginalCostChanges(){ - VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).build(); - states.informInsertionStarts(Arrays.asList(route), null); + } - InsertionData iData = serviceInsertion.getInsertionData(route, first, vehicle, vehicle.getEarliestDeparture(), null, Double.MAX_VALUE); - assertEquals(20.0, iData.getInsertionCost(), 0.2); - assertEquals(0, iData.getDeliveryInsertionIndex()); - } - - @Test - public void whenInsertingTheSecondJobInAnNonEmptyTourWithVehicle_itCalculatesMarginalCostChanges(){ - VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).setJobActivityFactory(vrp.getJobActivityFactory()).addService(first).build(); - states.informInsertionStarts(Arrays.asList(route), null); - - InsertionData iData = serviceInsertion.getInsertionData(route, third, vehicle, vehicle.getEarliestDeparture(), null, Double.MAX_VALUE); - assertEquals(20.0, iData.getInsertionCost(), 0.2); - assertEquals(0, iData.getDeliveryInsertionIndex()); - } - - @Test - public void whenInsertingThirdJobWithVehicle_itCalculatesMarginalCostChanges(){ - VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).setJobActivityFactory(vrp.getJobActivityFactory()).addService(first).addService(third).build(); - states.informInsertionStarts(Arrays.asList(route), null); - - InsertionData iData = serviceInsertion.getInsertionData(route, second, vehicle, vehicle.getEarliestDeparture(), null, Double.MAX_VALUE); - assertEquals(0.0, iData.getInsertionCost(), 0.2); - assertEquals(1, iData.getDeliveryInsertionIndex()); - } - - @Test - public void whenInsertingThirdJobWithNewVehicle_itCalculatesMarginalCostChanges(){ - VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).setJobActivityFactory(vrp.getJobActivityFactory()).addService(first).addService(third).build(); - states.informInsertionStarts(Arrays.asList(route), null); - - InsertionData iData = serviceInsertion.getInsertionData(route, second, newVehicle, newVehicle.getEarliestDeparture(), null, Double.MAX_VALUE); - assertEquals(40.0, iData.getInsertionCost(), 0.2); - assertEquals(1, iData.getDeliveryInsertionIndex()); - } - - @Test - public void whenInsertingASecondJobWithAVehicle_itCalculatesLocalMarginalCostChanges(){ - VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).setJobActivityFactory(vrp.getJobActivityFactory()).addService(first).addService(second).build(); - states.informInsertionStarts(Arrays.asList(route), null); - - InsertionData iData = serviceInsertion.getInsertionData(route, third, vehicle, vehicle.getEarliestDeparture(), null, Double.MAX_VALUE); - assertEquals(0.0, iData.getInsertionCost(), 0.2); - assertEquals(2, iData.getDeliveryInsertionIndex()); - } - - @Test - public void whenInsertingASecondJobWithANewVehicle_itCalculatesLocalMarginalCostChanges(){ + @Test + public void whenInsertingTheFirstJobInAnEmptyTourWithVehicle_itCalculatesMarginalCostChanges() { + VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).build(); + states.informInsertionStarts(Arrays.asList(route), null); - VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).setJobActivityFactory(vrp.getJobActivityFactory()).addService(first).addService(second).build(); + InsertionData iData = serviceInsertion.getInsertionData(route, first, vehicle, vehicle.getEarliestDeparture(), null, Double.MAX_VALUE); + assertEquals(20.0, iData.getInsertionCost(), 0.2); + assertEquals(0, iData.getDeliveryInsertionIndex()); + } - states.informInsertionStarts(Arrays.asList(route), null); - - InsertionData iData = serviceInsertion.getInsertionData(route, third, newVehicle, newVehicle.getEarliestDeparture(), null, Double.MAX_VALUE); - assertEquals(50.0, iData.getInsertionCost(), 0.2); - assertEquals(2, iData.getDeliveryInsertionIndex()); - } - - @Test - public void whenInsertingJobAndCurrRouteIsEmpty_accessEggressCalcShouldReturnZero(){ - VehicleRoute route = VehicleRoute.Builder.newInstance(VehicleImpl.createNoVehicle(), DriverImpl.noDriver()).build(); - AdditionalAccessEgressCalculator accessEgressCalc = new AdditionalAccessEgressCalculator(costs); - Job job = Service.Builder.newInstance("1").addSizeDimension(0, 0).setLocation(Location.newInstance("1")).setTimeWindow(TimeWindow.newInstance(0.0, 100.0)).build(); - JobInsertionContext iContex = new JobInsertionContext(route, job, newVehicle, mock(Driver.class), 0.0); - assertEquals(0.0, accessEgressCalc.getCosts(iContex),0.01); - } - - @Test - public void whenInsertingJobAndCurrRouteAndVehicleHaveTheSameLocation_accessEggressCalcShouldReturnZero(){ - VehicleRoute route = VehicleRoute.Builder.newInstance(newVehicle, DriverImpl.noDriver()) - .addService(first) - .build(); - - AdditionalAccessEgressCalculator accessEgressCalc = new AdditionalAccessEgressCalculator(costs); - JobInsertionContext iContex = new JobInsertionContext(route, first, newVehicle, mock(Driver.class), 0.0); - assertEquals(0.0, accessEgressCalc.getCosts(iContex),0.01); - } - - @Test - public void whenInsertingJobAndCurrRouteAndNewVehicleHaveDifferentLocations_accessEggressCostsMustBeCorrect(){ - final Map coords = new HashMap(); - coords.put("oldV", Coordinate.newInstance(1, 0)); - coords.put("newV", Coordinate.newInstance(5, 0)); - coords.put("service", Coordinate.newInstance(0, 0)); - - AbstractForwardVehicleRoutingTransportCosts routingCosts = new AbstractForwardVehicleRoutingTransportCosts() { - - @Override - public double getTransportTime(Location from, Location to,double departureTime, Driver driver, Vehicle vehicle) { - return getTransportCost(from, to, departureTime, driver, vehicle); - } - - @Override - public double getTransportCost(Location from, Location to,double departureTime, Driver driver, Vehicle vehicle) { - return EuclideanDistanceCalculator.calculateDistance(coords.get(from.getId()), coords.get(to.getId())); - } - }; - Vehicle oldVehicle = VehicleImpl.Builder.newInstance("oldV").setStartLocation(Location.newInstance("oldV")).build(); - - VehicleRoute route = VehicleRoute.Builder.newInstance(oldVehicle, DriverImpl.noDriver()) - .addService(Service.Builder.newInstance("service").addSizeDimension(0, 0).setLocation(Location.newInstance("service")).build()) - .build(); - - Vehicle newVehicle = VehicleImpl.Builder.newInstance("newV").setStartLocation(Location.newInstance("newV")).build(); - - AdditionalAccessEgressCalculator accessEgressCalc = new AdditionalAccessEgressCalculator(routingCosts); - Job job = Service.Builder.newInstance("service2").addSizeDimension(0, 0).setLocation(Location.newInstance("service")).build(); - JobInsertionContext iContex = new JobInsertionContext(route, job, newVehicle, mock(Driver.class), 0.0); - assertEquals(8.0, accessEgressCalc.getCosts(iContex),0.01); - } + @Test + public void whenInsertingTheSecondJobInAnNonEmptyTourWithVehicle_itCalculatesMarginalCostChanges() { + VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).setJobActivityFactory(vrp.getJobActivityFactory()).addService(first).build(); + states.informInsertionStarts(Arrays.asList(route), null); + + InsertionData iData = serviceInsertion.getInsertionData(route, third, vehicle, vehicle.getEarliestDeparture(), null, Double.MAX_VALUE); + assertEquals(20.0, iData.getInsertionCost(), 0.2); + assertEquals(0, iData.getDeliveryInsertionIndex()); + } + + @Test + public void whenInsertingThirdJobWithVehicle_itCalculatesMarginalCostChanges() { + VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).setJobActivityFactory(vrp.getJobActivityFactory()).addService(first).addService(third).build(); + states.informInsertionStarts(Arrays.asList(route), null); + + InsertionData iData = serviceInsertion.getInsertionData(route, second, vehicle, vehicle.getEarliestDeparture(), null, Double.MAX_VALUE); + assertEquals(0.0, iData.getInsertionCost(), 0.2); + assertEquals(1, iData.getDeliveryInsertionIndex()); + } + + @Test + public void whenInsertingThirdJobWithNewVehicle_itCalculatesMarginalCostChanges() { + VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).setJobActivityFactory(vrp.getJobActivityFactory()).addService(first).addService(third).build(); + states.informInsertionStarts(Arrays.asList(route), null); + + InsertionData iData = serviceInsertion.getInsertionData(route, second, newVehicle, newVehicle.getEarliestDeparture(), null, Double.MAX_VALUE); + assertEquals(40.0, iData.getInsertionCost(), 0.2); + assertEquals(1, iData.getDeliveryInsertionIndex()); + } + + @Test + public void whenInsertingASecondJobWithAVehicle_itCalculatesLocalMarginalCostChanges() { + VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).setJobActivityFactory(vrp.getJobActivityFactory()).addService(first).addService(second).build(); + states.informInsertionStarts(Arrays.asList(route), null); + + InsertionData iData = serviceInsertion.getInsertionData(route, third, vehicle, vehicle.getEarliestDeparture(), null, Double.MAX_VALUE); + assertEquals(0.0, iData.getInsertionCost(), 0.2); + assertEquals(2, iData.getDeliveryInsertionIndex()); + } + + @Test + public void whenInsertingASecondJobWithANewVehicle_itCalculatesLocalMarginalCostChanges() { + + VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).setJobActivityFactory(vrp.getJobActivityFactory()).addService(first).addService(second).build(); + + states.informInsertionStarts(Arrays.asList(route), null); + + InsertionData iData = serviceInsertion.getInsertionData(route, third, newVehicle, newVehicle.getEarliestDeparture(), null, Double.MAX_VALUE); + assertEquals(50.0, iData.getInsertionCost(), 0.2); + assertEquals(2, iData.getDeliveryInsertionIndex()); + } + + @Test + public void whenInsertingJobAndCurrRouteIsEmpty_accessEggressCalcShouldReturnZero() { + VehicleRoute route = VehicleRoute.Builder.newInstance(VehicleImpl.createNoVehicle(), DriverImpl.noDriver()).build(); + AdditionalAccessEgressCalculator accessEgressCalc = new AdditionalAccessEgressCalculator(costs); + Job job = Service.Builder.newInstance("1").addSizeDimension(0, 0).setLocation(Location.newInstance("1")).setTimeWindow(TimeWindow.newInstance(0.0, 100.0)).build(); + JobInsertionContext iContex = new JobInsertionContext(route, job, newVehicle, mock(Driver.class), 0.0); + assertEquals(0.0, accessEgressCalc.getCosts(iContex), 0.01); + } + + @Test + public void whenInsertingJobAndCurrRouteAndVehicleHaveTheSameLocation_accessEggressCalcShouldReturnZero() { + VehicleRoute route = VehicleRoute.Builder.newInstance(newVehicle, DriverImpl.noDriver()) + .addService(first) + .build(); + + AdditionalAccessEgressCalculator accessEgressCalc = new AdditionalAccessEgressCalculator(costs); + JobInsertionContext iContex = new JobInsertionContext(route, first, newVehicle, mock(Driver.class), 0.0); + assertEquals(0.0, accessEgressCalc.getCosts(iContex), 0.01); + } + + @Test + public void whenInsertingJobAndCurrRouteAndNewVehicleHaveDifferentLocations_accessEggressCostsMustBeCorrect() { + final Map coords = new HashMap(); + coords.put("oldV", Coordinate.newInstance(1, 0)); + coords.put("newV", Coordinate.newInstance(5, 0)); + coords.put("service", Coordinate.newInstance(0, 0)); + + AbstractForwardVehicleRoutingTransportCosts routingCosts = new AbstractForwardVehicleRoutingTransportCosts() { + + @Override + public double getTransportTime(Location from, Location to, double departureTime, Driver driver, Vehicle vehicle) { + return getTransportCost(from, to, departureTime, driver, vehicle); + } + + @Override + public double getTransportCost(Location from, Location to, double departureTime, Driver driver, Vehicle vehicle) { + return EuclideanDistanceCalculator.calculateDistance(coords.get(from.getId()), coords.get(to.getId())); + } + }; + Vehicle oldVehicle = VehicleImpl.Builder.newInstance("oldV").setStartLocation(Location.newInstance("oldV")).build(); + + VehicleRoute route = VehicleRoute.Builder.newInstance(oldVehicle, DriverImpl.noDriver()) + .addService(Service.Builder.newInstance("service").addSizeDimension(0, 0).setLocation(Location.newInstance("service")).build()) + .build(); + + Vehicle newVehicle = VehicleImpl.Builder.newInstance("newV").setStartLocation(Location.newInstance("newV")).build(); + + AdditionalAccessEgressCalculator accessEgressCalc = new AdditionalAccessEgressCalculator(routingCosts); + Job job = Service.Builder.newInstance("service2").addSizeDimension(0, 0).setLocation(Location.newInstance("service")).build(); + JobInsertionContext iContex = new JobInsertionContext(route, job, newVehicle, mock(Driver.class), 0.0); + assertEquals(8.0, accessEgressCalc.getCosts(iContex), 0.01); + } } diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/TestCalculatesServiceInsertionOnRouteLevel.java b/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/TestCalculatesServiceInsertionOnRouteLevel.java index a17c9017..c9f74ac1 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/TestCalculatesServiceInsertionOnRouteLevel.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/TestCalculatesServiceInsertionOnRouteLevel.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.recreate; @@ -47,40 +47,38 @@ import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.mock; - - public class TestCalculatesServiceInsertionOnRouteLevel { - - ServiceInsertionOnRouteLevelCalculator serviceInsertion; - - VehicleRoutingTransportCosts costs; - - AbstractVehicle vehicle; - - AbstractVehicle newVehicle; - private Service first; + ServiceInsertionOnRouteLevelCalculator serviceInsertion; - private Service second; + VehicleRoutingTransportCosts costs; - private Service third; + AbstractVehicle vehicle; - private StateManager states; + AbstractVehicle newVehicle; - private NoDriver driver; + private Service first; + + private Service second; + + private Service third; + + private StateManager states; + + private NoDriver driver; private VehicleRoutingProblem vrp; - - @Before - public void setup(){ - - costs = mock(VehicleRoutingTransportCosts.class); + @Before + public void setup() { - VehicleType type = VehicleTypeImpl.Builder.newInstance("t").addCapacityDimension(0,1000).build(); + + costs = mock(VehicleRoutingTransportCosts.class); + + VehicleType type = VehicleTypeImpl.Builder.newInstance("t").addCapacityDimension(0, 1000).build(); vehicle = VehicleImpl.Builder.newInstance("v1").setType(type).setStartLocation(Location.newInstance("0,0")).setLatestArrival(100.).build(); newVehicle = VehicleImpl.Builder.newInstance("v2").setType(type).setStartLocation(Location.newInstance("0,0")).setLatestArrival(100.).build(); - driver = DriverImpl.noDriver(); + driver = DriverImpl.noDriver(); costs = new AbstractForwardVehicleRoutingTransportCosts() { @@ -93,97 +91,97 @@ public class TestCalculatesServiceInsertionOnRouteLevel { @Override public double getTransportCost(Location from, Location to, double departureTime, Driver driver, Vehicle vehicle) { - double tpCosts = routingCosts.getTransportCost(from, to,departureTime,driver,vehicle); - if(vehicle.getId().equals("v1")) return tpCosts; + double tpCosts = routingCosts.getTransportCost(from, to, departureTime, driver, vehicle); + if (vehicle.getId().equals("v1")) return tpCosts; return 2. * tpCosts; } }; - first = Service.Builder.newInstance("1").setLocation(Location.newInstance("0,10")).setTimeWindow(TimeWindow.newInstance(0.0, 100.0)).build(); - second = Service.Builder.newInstance("3").setLocation(Location.newInstance("10,0")).setTimeWindow(TimeWindow.newInstance(0.0, 100.0)).build(); - third = Service.Builder.newInstance("2").setLocation(Location.newInstance("10,10")).setTimeWindow(TimeWindow.newInstance(0.0, 100.0)).build(); - Collection jobs = new ArrayList(); - jobs.add(first); - jobs.add(second); - jobs.add(third); - - vrp = VehicleRoutingProblem.Builder.newInstance().addAllJobs(jobs).addVehicle(vehicle).addVehicle(newVehicle).setRoutingCost(costs).build(); - - states = new StateManager(vrp); - states.updateLoadStates(); - states.updateTimeWindowStates(); - states.addStateUpdater(new UpdateVariableCosts(vrp.getActivityCosts(), vrp.getTransportCosts(), states)); - - ConstraintManager cManager = new ConstraintManager(vrp,states); - cManager.addLoadConstraint(); - cManager.addTimeWindowConstraint(); - - - ExampleActivityCostFunction activityCosts = new ExampleActivityCostFunction(); - ActivityInsertionCostsCalculator actInsertionCostCalculator = new RouteLevelActivityInsertionCostsEstimator(costs, activityCosts, states); - serviceInsertion = new ServiceInsertionOnRouteLevelCalculator(costs,activityCosts, actInsertionCostCalculator, cManager, cManager); - serviceInsertion.setNuOfActsForwardLooking(4); - serviceInsertion.setStates(states); + first = Service.Builder.newInstance("1").setLocation(Location.newInstance("0,10")).setTimeWindow(TimeWindow.newInstance(0.0, 100.0)).build(); + second = Service.Builder.newInstance("3").setLocation(Location.newInstance("10,0")).setTimeWindow(TimeWindow.newInstance(0.0, 100.0)).build(); + third = Service.Builder.newInstance("2").setLocation(Location.newInstance("10,10")).setTimeWindow(TimeWindow.newInstance(0.0, 100.0)).build(); + Collection jobs = new ArrayList(); + jobs.add(first); + jobs.add(second); + jobs.add(third); + + vrp = VehicleRoutingProblem.Builder.newInstance().addAllJobs(jobs).addVehicle(vehicle).addVehicle(newVehicle).setRoutingCost(costs).build(); + + states = new StateManager(vrp); + states.updateLoadStates(); + states.updateTimeWindowStates(); + states.addStateUpdater(new UpdateVariableCosts(vrp.getActivityCosts(), vrp.getTransportCosts(), states)); + + ConstraintManager cManager = new ConstraintManager(vrp, states); + cManager.addLoadConstraint(); + cManager.addTimeWindowConstraint(); + + + ExampleActivityCostFunction activityCosts = new ExampleActivityCostFunction(); + ActivityInsertionCostsCalculator actInsertionCostCalculator = new RouteLevelActivityInsertionCostsEstimator(costs, activityCosts, states); + serviceInsertion = new ServiceInsertionOnRouteLevelCalculator(costs, activityCosts, actInsertionCostCalculator, cManager, cManager); + serviceInsertion.setNuOfActsForwardLooking(4); + serviceInsertion.setStates(states); serviceInsertion.setJobActivityFactory(new JobActivityFactory() { @Override public List createActivities(Job job) { return vrp.copyAndGetActivities(job); } }); - - } - - @Test - public void whenInsertingTheFirstJobInAnEmptyTourWithVehicle_itCalculatesMarginalCostChanges(){ - VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).build(); - states.informInsertionStarts(Arrays.asList(route), null); - - InsertionData iData = serviceInsertion.getInsertionData(route, first, vehicle, vehicle.getEarliestDeparture(), null, Double.MAX_VALUE); - assertEquals(20.0, iData.getInsertionCost(), 0.2); - assertEquals(0, iData.getDeliveryInsertionIndex()); - } - - @Test - public void whenInsertingThirdJobWithVehicle_itCalculatesMarginalCostChanges(){ - VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).setJobActivityFactory(vrp.getJobActivityFactory()).addService(first).addService(second).build(); - states.informInsertionStarts(Arrays.asList(route), null); - - InsertionData iData = serviceInsertion.getInsertionData(route, third, vehicle, vehicle.getEarliestDeparture(), null, Double.MAX_VALUE); - assertEquals(0.0, iData.getInsertionCost(), 0.2); - assertEquals(1, iData.getDeliveryInsertionIndex()); - } - - @Test - public void whenInsertingThirdJobWithNewVehicle_itCalculatesMarginalCostChanges(){ - VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).setJobActivityFactory(vrp.getJobActivityFactory()).addService(first).addService(second).build(); - states.informInsertionStarts(Arrays.asList(route), null); - - InsertionData iData = serviceInsertion.getInsertionData(route, third, newVehicle, vehicle.getEarliestDeparture(), null, Double.MAX_VALUE); - assertEquals(40.0, iData.getInsertionCost(), 0.2); - assertEquals(1, iData.getDeliveryInsertionIndex()); - } - - @Test - public void whenInsertingASecondJobWithAVehicle_itCalculatesLocalMarginalCostChanges(){ + } + + + @Test + public void whenInsertingTheFirstJobInAnEmptyTourWithVehicle_itCalculatesMarginalCostChanges() { + VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).build(); + states.informInsertionStarts(Arrays.asList(route), null); + + InsertionData iData = serviceInsertion.getInsertionData(route, first, vehicle, vehicle.getEarliestDeparture(), null, Double.MAX_VALUE); + assertEquals(20.0, iData.getInsertionCost(), 0.2); + assertEquals(0, iData.getDeliveryInsertionIndex()); + } + + @Test + public void whenInsertingThirdJobWithVehicle_itCalculatesMarginalCostChanges() { + VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).setJobActivityFactory(vrp.getJobActivityFactory()).addService(first).addService(second).build(); + states.informInsertionStarts(Arrays.asList(route), null); + + InsertionData iData = serviceInsertion.getInsertionData(route, third, vehicle, vehicle.getEarliestDeparture(), null, Double.MAX_VALUE); + assertEquals(0.0, iData.getInsertionCost(), 0.2); + assertEquals(1, iData.getDeliveryInsertionIndex()); + } + + @Test + public void whenInsertingThirdJobWithNewVehicle_itCalculatesMarginalCostChanges() { + VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).setJobActivityFactory(vrp.getJobActivityFactory()).addService(first).addService(second).build(); + states.informInsertionStarts(Arrays.asList(route), null); + + InsertionData iData = serviceInsertion.getInsertionData(route, third, newVehicle, vehicle.getEarliestDeparture(), null, Double.MAX_VALUE); + assertEquals(40.0, iData.getInsertionCost(), 0.2); + assertEquals(1, iData.getDeliveryInsertionIndex()); + } + + @Test + public void whenInsertingASecondJobWithAVehicle_itCalculatesLocalMarginalCostChanges() { VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).setJobActivityFactory(vrp.getJobActivityFactory()).addService(first).addService(third).build(); - states.informInsertionStarts(Arrays.asList(route), null); - - InsertionData iData = serviceInsertion.getInsertionData(route, second, vehicle, vehicle.getEarliestDeparture(), null, Double.MAX_VALUE); - assertEquals(0.0, iData.getInsertionCost(), 0.2); - assertEquals(2, iData.getDeliveryInsertionIndex()); - } - - @Test - public void whenInsertingASecondJobWithANewVehicle_itCalculatesLocalMarginalCostChanges(){ + states.informInsertionStarts(Arrays.asList(route), null); + + InsertionData iData = serviceInsertion.getInsertionData(route, second, vehicle, vehicle.getEarliestDeparture(), null, Double.MAX_VALUE); + assertEquals(0.0, iData.getInsertionCost(), 0.2); + assertEquals(2, iData.getDeliveryInsertionIndex()); + } + + @Test + public void whenInsertingASecondJobWithANewVehicle_itCalculatesLocalMarginalCostChanges() { VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).setJobActivityFactory(vrp.getJobActivityFactory()).addService(first).addService(third).build(); - states.informInsertionStarts(Arrays.asList(route), null); - - InsertionData iData = serviceInsertion.getInsertionData(route, second, newVehicle, vehicle.getEarliestDeparture(), null, Double.MAX_VALUE); - assertEquals(40.0, iData.getInsertionCost(), 0.2); - assertEquals(2, iData.getDeliveryInsertionIndex()); - } - - + states.informInsertionStarts(Arrays.asList(route), null); + + InsertionData iData = serviceInsertion.getInsertionData(route, second, newVehicle, vehicle.getEarliestDeparture(), null, Double.MAX_VALUE); + assertEquals(40.0, iData.getInsertionCost(), 0.2); + assertEquals(2, iData.getDeliveryInsertionIndex()); + } + + } diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/TestDepartureTimeOpt.java b/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/TestDepartureTimeOpt.java index a1eaa3c3..9ed591c5 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/TestDepartureTimeOpt.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/TestDepartureTimeOpt.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.recreate; @@ -42,180 +42,180 @@ import static org.junit.Assert.assertEquals; @Ignore public class TestDepartureTimeOpt { - - @Test - public void whenSettingOneCustWithTWAnd_NO_DepTimeChoice_totalCostsShouldBe50(){ - TimeWindow timeWindow = TimeWindow.newInstance(40, 45); - Service service = Service.Builder.newInstance("s").setLocation(TestUtils.loc("servLoc",Coordinate.newInstance(0, 10))).setTimeWindow(timeWindow).build(); - Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(TestUtils.loc("vehLoc", Coordinate.newInstance(0, 0))) - .setType(VehicleTypeImpl.Builder.newInstance("vType").build()).build(); - - Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - vrpBuilder.setActivityCosts(new VehicleRoutingActivityCosts(){ - @Override - public double getActivityCost(TourActivity tourAct, double arrivalTime, Driver driver, Vehicle vehicle) { - double waiting = Math.max(0, tourAct.getTheoreticalEarliestOperationStartTime() - arrivalTime)*1; - double late = Math.max(0, arrivalTime - tourAct.getTheoreticalLatestOperationStartTime())*100; - return waiting + late; - } - - }); - VehicleRoutingProblem vrp = vrpBuilder.addJob(service).addVehicle(vehicle).build(); - - VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/algorithmConfig.xml"); - Collection solutions = vra.searchSolutions(); - - assertEquals(20.0+30.0,Solutions.bestOf(solutions).getCost(),0.1); - - } - - @Test - public void whenSettingOneCustWithTWAnd_NO_DepTimeChoice_depTimeShouldBe0(){ - TimeWindow timeWindow = TimeWindow.newInstance(40, 45); - Service service = Service.Builder.newInstance("s") - .setLocation(TestUtils.loc("servLoc",Coordinate.newInstance(0, 10))).setTimeWindow(timeWindow).build(); - Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.Builder.newInstance().setId("vehLoc").setCoordinate(Coordinate.newInstance(0, 0)).build()) - .setType(VehicleTypeImpl.Builder.newInstance("vType").build()).build(); - - Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - vrpBuilder.setActivityCosts(new VehicleRoutingActivityCosts(){ + @Test + public void whenSettingOneCustWithTWAnd_NO_DepTimeChoice_totalCostsShouldBe50() { + TimeWindow timeWindow = TimeWindow.newInstance(40, 45); + Service service = Service.Builder.newInstance("s").setLocation(TestUtils.loc("servLoc", Coordinate.newInstance(0, 10))).setTimeWindow(timeWindow).build(); + Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(TestUtils.loc("vehLoc", Coordinate.newInstance(0, 0))) + .setType(VehicleTypeImpl.Builder.newInstance("vType").build()).build(); - @Override - public double getActivityCost(TourActivity tourAct, double arrivalTime, Driver driver, Vehicle vehicle) { - double waiting = Math.max(0, tourAct.getTheoreticalEarliestOperationStartTime() - arrivalTime)*1; - double late = Math.max(0, arrivalTime - tourAct.getTheoreticalLatestOperationStartTime())*100; - return waiting + late; - } - - }); - VehicleRoutingProblem vrp = vrpBuilder.addJob(service).addVehicle(vehicle).build(); - - VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/algorithmConfig.xml"); - Collection solutions = vra.searchSolutions(); - - assertEquals(0.0,Solutions.bestOf(solutions).getRoutes().iterator().next().getStart().getEndTime(),0.1); - - } - - @Test - public void whenSettingOneCustWithTWAndDepTimeChoice_totalCostsShouldBe50(){ - TimeWindow timeWindow = TimeWindow.newInstance(40, 45); - Service service = Service.Builder.newInstance("s").setLocation(TestUtils.loc("servLoc",Coordinate.newInstance(0, 10))).setTimeWindow(timeWindow).build(); - Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(TestUtils.loc("vehLoc",Coordinate.newInstance(0, 0))) - .setType(VehicleTypeImpl.Builder.newInstance("vType").build()).build(); - - Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - vrpBuilder.setActivityCosts(new VehicleRoutingActivityCosts(){ + Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + vrpBuilder.setActivityCosts(new VehicleRoutingActivityCosts() { - @Override - public double getActivityCost(TourActivity tourAct, double arrivalTime, Driver driver, Vehicle vehicle) { - double waiting = Math.max(0, tourAct.getTheoreticalEarliestOperationStartTime() - arrivalTime)*1; - double late = Math.max(0, arrivalTime - tourAct.getTheoreticalLatestOperationStartTime())*100; - return waiting + late; - } - - }); - VehicleRoutingProblem vrp = vrpBuilder.addJob(service).addVehicle(vehicle).build(); - - - VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/algorithmConfigWithDepartureTimeChoice.xml"); - Collection solutions = vra.searchSolutions(); - - assertEquals(20.0,Solutions.bestOf(solutions).getCost(),0.1); - - } - - @Test - public void whenSettingOneCustWithTWAndDepTimeChoice_depTimeShouldBe0(){ - TimeWindow timeWindow = TimeWindow.newInstance(40, 45); - Service service = Service.Builder.newInstance("s").setLocation(TestUtils.loc("servLoc",Coordinate.newInstance(0, 10))).setTimeWindow(timeWindow).build(); - Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(TestUtils.loc("vehLoc",Coordinate.newInstance(0, 0))) - .setType(VehicleTypeImpl.Builder.newInstance("vType").build()).build(); - - Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - vrpBuilder.setActivityCosts(new VehicleRoutingActivityCosts(){ + @Override + public double getActivityCost(TourActivity tourAct, double arrivalTime, Driver driver, Vehicle vehicle) { + double waiting = Math.max(0, tourAct.getTheoreticalEarliestOperationStartTime() - arrivalTime) * 1; + double late = Math.max(0, arrivalTime - tourAct.getTheoreticalLatestOperationStartTime()) * 100; + return waiting + late; + } - @Override - public double getActivityCost(TourActivity tourAct, double arrivalTime, Driver driver, Vehicle vehicle) { - double waiting = Math.max(0, tourAct.getTheoreticalEarliestOperationStartTime() - arrivalTime)*1; - double late = Math.max(0, arrivalTime - tourAct.getTheoreticalLatestOperationStartTime())*100; - return waiting + late; - } - - }); - VehicleRoutingProblem vrp = vrpBuilder.addJob(service).addVehicle(vehicle).build(); - - - VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/algorithmConfigWithDepartureTimeChoice.xml"); - Collection solutions = vra.searchSolutions(); - - assertEquals(30.0,Solutions.bestOf(solutions).getRoutes().iterator().next().getStart().getEndTime(),0.1); - - } - - @Test - public void whenSettingTwoCustWithTWAndDepTimeChoice_totalCostsShouldBe50(){ - TimeWindow timeWindow = TimeWindow.newInstance(40, 45); - Service service = Service.Builder.newInstance("s").setLocation(TestUtils.loc("servLoc",Coordinate.newInstance(0, 10))).setTimeWindow(timeWindow).build(); - - Service service2 = Service.Builder.newInstance("s2").setLocation(TestUtils.loc("servLoc2",Coordinate.newInstance(0, 20))). - setTimeWindow(TimeWindow.newInstance(30, 40)).build(); - - Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(TestUtils.loc("vehLoc",Coordinate.newInstance(0, 0))) - .setType(VehicleTypeImpl.Builder.newInstance("vType").build()).build(); - - Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - vrpBuilder.setActivityCosts(new VehicleRoutingActivityCosts(){ + }); + VehicleRoutingProblem vrp = vrpBuilder.addJob(service).addVehicle(vehicle).build(); - @Override - public double getActivityCost(TourActivity tourAct, double arrivalTime, Driver driver, Vehicle vehicle) { - double waiting = Math.max(0, tourAct.getTheoreticalEarliestOperationStartTime() - arrivalTime)*1; - double late = Math.max(0, arrivalTime - tourAct.getTheoreticalLatestOperationStartTime())*100; - return waiting + late; - } - - }); - VehicleRoutingProblem vrp = vrpBuilder.addJob(service).addJob(service2).addVehicle(vehicle).build(); - - - VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/algorithmConfigWithDepartureTimeChoice.xml"); - Collection solutions = vra.searchSolutions(); - - assertEquals(40.0,Solutions.bestOf(solutions).getCost(),0.1); - - } - - @Test - public void whenSettingTwoCustWithTWAndDepTimeChoice_depTimeShouldBe10(){ - TimeWindow timeWindow = TimeWindow.newInstance(40, 45); - Service service = Service.Builder.newInstance("s").setLocation(TestUtils.loc("servLoc",Coordinate.newInstance(0, 10))).setTimeWindow(timeWindow).build(); - - Service service2 = Service.Builder.newInstance("s2").setLocation(TestUtils.loc("servLoc2",Coordinate.newInstance(0, 20))). - setTimeWindow(TimeWindow.newInstance(30, 40)).build(); - - Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(TestUtils.loc("vehLoc",Coordinate.newInstance(0, 0))) - .setType(VehicleTypeImpl.Builder.newInstance("vType").build()).build(); - - Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - vrpBuilder.setActivityCosts(new VehicleRoutingActivityCosts(){ + VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/algorithmConfig.xml"); + Collection solutions = vra.searchSolutions(); - @Override - public double getActivityCost(TourActivity tourAct, double arrivalTime, Driver driver, Vehicle vehicle) { - double waiting = Math.max(0, tourAct.getTheoreticalEarliestOperationStartTime() - arrivalTime)*1; - double late = Math.max(0, arrivalTime - tourAct.getTheoreticalLatestOperationStartTime())*100; - return waiting + late; - } - - }); - VehicleRoutingProblem vrp = vrpBuilder.addJob(service).addJob(service2).addVehicle(vehicle).build(); - - - VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/algorithmConfigWithDepartureTimeChoice.xml"); - Collection solutions = vra.searchSolutions(); - - assertEquals(10.0,Solutions.bestOf(solutions).getRoutes().iterator().next().getStart().getEndTime(),0.1); - - } + assertEquals(20.0 + 30.0, Solutions.bestOf(solutions).getCost(), 0.1); + + } + + @Test + public void whenSettingOneCustWithTWAnd_NO_DepTimeChoice_depTimeShouldBe0() { + TimeWindow timeWindow = TimeWindow.newInstance(40, 45); + Service service = Service.Builder.newInstance("s") + .setLocation(TestUtils.loc("servLoc", Coordinate.newInstance(0, 10))).setTimeWindow(timeWindow).build(); + Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.Builder.newInstance().setId("vehLoc").setCoordinate(Coordinate.newInstance(0, 0)).build()) + .setType(VehicleTypeImpl.Builder.newInstance("vType").build()).build(); + + Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + vrpBuilder.setActivityCosts(new VehicleRoutingActivityCosts() { + + @Override + public double getActivityCost(TourActivity tourAct, double arrivalTime, Driver driver, Vehicle vehicle) { + double waiting = Math.max(0, tourAct.getTheoreticalEarliestOperationStartTime() - arrivalTime) * 1; + double late = Math.max(0, arrivalTime - tourAct.getTheoreticalLatestOperationStartTime()) * 100; + return waiting + late; + } + + }); + VehicleRoutingProblem vrp = vrpBuilder.addJob(service).addVehicle(vehicle).build(); + + VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/algorithmConfig.xml"); + Collection solutions = vra.searchSolutions(); + + assertEquals(0.0, Solutions.bestOf(solutions).getRoutes().iterator().next().getStart().getEndTime(), 0.1); + + } + + @Test + public void whenSettingOneCustWithTWAndDepTimeChoice_totalCostsShouldBe50() { + TimeWindow timeWindow = TimeWindow.newInstance(40, 45); + Service service = Service.Builder.newInstance("s").setLocation(TestUtils.loc("servLoc", Coordinate.newInstance(0, 10))).setTimeWindow(timeWindow).build(); + Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(TestUtils.loc("vehLoc", Coordinate.newInstance(0, 0))) + .setType(VehicleTypeImpl.Builder.newInstance("vType").build()).build(); + + Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + vrpBuilder.setActivityCosts(new VehicleRoutingActivityCosts() { + + @Override + public double getActivityCost(TourActivity tourAct, double arrivalTime, Driver driver, Vehicle vehicle) { + double waiting = Math.max(0, tourAct.getTheoreticalEarliestOperationStartTime() - arrivalTime) * 1; + double late = Math.max(0, arrivalTime - tourAct.getTheoreticalLatestOperationStartTime()) * 100; + return waiting + late; + } + + }); + VehicleRoutingProblem vrp = vrpBuilder.addJob(service).addVehicle(vehicle).build(); + + + VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/algorithmConfigWithDepartureTimeChoice.xml"); + Collection solutions = vra.searchSolutions(); + + assertEquals(20.0, Solutions.bestOf(solutions).getCost(), 0.1); + + } + + @Test + public void whenSettingOneCustWithTWAndDepTimeChoice_depTimeShouldBe0() { + TimeWindow timeWindow = TimeWindow.newInstance(40, 45); + Service service = Service.Builder.newInstance("s").setLocation(TestUtils.loc("servLoc", Coordinate.newInstance(0, 10))).setTimeWindow(timeWindow).build(); + Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(TestUtils.loc("vehLoc", Coordinate.newInstance(0, 0))) + .setType(VehicleTypeImpl.Builder.newInstance("vType").build()).build(); + + Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + vrpBuilder.setActivityCosts(new VehicleRoutingActivityCosts() { + + @Override + public double getActivityCost(TourActivity tourAct, double arrivalTime, Driver driver, Vehicle vehicle) { + double waiting = Math.max(0, tourAct.getTheoreticalEarliestOperationStartTime() - arrivalTime) * 1; + double late = Math.max(0, arrivalTime - tourAct.getTheoreticalLatestOperationStartTime()) * 100; + return waiting + late; + } + + }); + VehicleRoutingProblem vrp = vrpBuilder.addJob(service).addVehicle(vehicle).build(); + + + VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/algorithmConfigWithDepartureTimeChoice.xml"); + Collection solutions = vra.searchSolutions(); + + assertEquals(30.0, Solutions.bestOf(solutions).getRoutes().iterator().next().getStart().getEndTime(), 0.1); + + } + + @Test + public void whenSettingTwoCustWithTWAndDepTimeChoice_totalCostsShouldBe50() { + TimeWindow timeWindow = TimeWindow.newInstance(40, 45); + Service service = Service.Builder.newInstance("s").setLocation(TestUtils.loc("servLoc", Coordinate.newInstance(0, 10))).setTimeWindow(timeWindow).build(); + + Service service2 = Service.Builder.newInstance("s2").setLocation(TestUtils.loc("servLoc2", Coordinate.newInstance(0, 20))). + setTimeWindow(TimeWindow.newInstance(30, 40)).build(); + + Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(TestUtils.loc("vehLoc", Coordinate.newInstance(0, 0))) + .setType(VehicleTypeImpl.Builder.newInstance("vType").build()).build(); + + Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + vrpBuilder.setActivityCosts(new VehicleRoutingActivityCosts() { + + @Override + public double getActivityCost(TourActivity tourAct, double arrivalTime, Driver driver, Vehicle vehicle) { + double waiting = Math.max(0, tourAct.getTheoreticalEarliestOperationStartTime() - arrivalTime) * 1; + double late = Math.max(0, arrivalTime - tourAct.getTheoreticalLatestOperationStartTime()) * 100; + return waiting + late; + } + + }); + VehicleRoutingProblem vrp = vrpBuilder.addJob(service).addJob(service2).addVehicle(vehicle).build(); + + + VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/algorithmConfigWithDepartureTimeChoice.xml"); + Collection solutions = vra.searchSolutions(); + + assertEquals(40.0, Solutions.bestOf(solutions).getCost(), 0.1); + + } + + @Test + public void whenSettingTwoCustWithTWAndDepTimeChoice_depTimeShouldBe10() { + TimeWindow timeWindow = TimeWindow.newInstance(40, 45); + Service service = Service.Builder.newInstance("s").setLocation(TestUtils.loc("servLoc", Coordinate.newInstance(0, 10))).setTimeWindow(timeWindow).build(); + + Service service2 = Service.Builder.newInstance("s2").setLocation(TestUtils.loc("servLoc2", Coordinate.newInstance(0, 20))). + setTimeWindow(TimeWindow.newInstance(30, 40)).build(); + + Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(TestUtils.loc("vehLoc", Coordinate.newInstance(0, 0))) + .setType(VehicleTypeImpl.Builder.newInstance("vType").build()).build(); + + Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + vrpBuilder.setActivityCosts(new VehicleRoutingActivityCosts() { + + @Override + public double getActivityCost(TourActivity tourAct, double arrivalTime, Driver driver, Vehicle vehicle) { + double waiting = Math.max(0, tourAct.getTheoreticalEarliestOperationStartTime() - arrivalTime) * 1; + double late = Math.max(0, arrivalTime - tourAct.getTheoreticalLatestOperationStartTime()) * 100; + return waiting + late; + } + + }); + VehicleRoutingProblem vrp = vrpBuilder.addJob(service).addJob(service2).addVehicle(vehicle).build(); + + + VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/algorithmConfigWithDepartureTimeChoice.xml"); + Collection solutions = vra.searchSolutions(); + + assertEquals(10.0, Solutions.bestOf(solutions).getRoutes().iterator().next().getStart().getEndTime(), 0.1); + + } } diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/TestInserter.java b/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/TestInserter.java index 9ad6052c..714f04c7 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/TestInserter.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/TestInserter.java @@ -44,69 +44,68 @@ import static org.mockito.Mockito.when; public class TestInserter { + @Test + public void whenInsertingServiceAndRouteIsClosed_itInsertsCorrectly() { + Service service = mock(Service.class); + Vehicle vehicle = mock(Vehicle.class); + when(vehicle.getStartLocation()).thenReturn(loc("vehLoc")); + when(vehicle.getEndLocation()).thenReturn(loc("vehLoc")); + when(vehicle.isReturnToDepot()).thenReturn(true); + when(vehicle.getId()).thenReturn("vehId"); - @Test - public void whenInsertingServiceAndRouteIsClosed_itInsertsCorrectly(){ - Service service = mock(Service.class); - Vehicle vehicle = mock(Vehicle.class); - when(vehicle.getStartLocation()).thenReturn(loc("vehLoc")); - when(vehicle.getEndLocation()).thenReturn(loc("vehLoc")); - when(vehicle.isReturnToDepot()).thenReturn(true); - when(vehicle.getId()).thenReturn("vehId"); - - VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class)).addService(service).build(); - //start - pick(shipment) - del(shipment) - end - Service serviceToInsert = mock(Service.class); - when(serviceToInsert.getLocation()).thenReturn(loc("delLoc")); - - InsertionData iData = mock(InsertionData.class); - when(iData.getDeliveryInsertionIndex()).thenReturn(1); - when(iData.getSelectedVehicle()).thenReturn(vehicle); + VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class)).addService(service).build(); + //start - pick(shipment) - del(shipment) - end + Service serviceToInsert = mock(Service.class); + when(serviceToInsert.getLocation()).thenReturn(loc("delLoc")); + + InsertionData iData = mock(InsertionData.class); + when(iData.getDeliveryInsertionIndex()).thenReturn(1); + when(iData.getSelectedVehicle()).thenReturn(vehicle); VehicleRoutingProblem vehicleRoutingProblem = mock(VehicleRoutingProblem.class); List acts = new ArrayList(); PickupService act = new PickupService(serviceToInsert); acts.add(act); when(vehicleRoutingProblem.copyAndGetActivities(serviceToInsert)).thenReturn(acts); - Inserter inserter = new Inserter(mock(InsertionListeners.class), vehicleRoutingProblem); - inserter.insertJob(serviceToInsert, iData, route); - - assertEquals(2,route.getTourActivities().getActivities().size()); - assertEquals(route.getTourActivities().getActivities().get(1).getLocation().getId(),serviceToInsert.getLocation().getId()); - assertEquals(route.getEnd().getLocation().getId(),vehicle.getEndLocation().getId()); - } + Inserter inserter = new Inserter(mock(InsertionListeners.class), vehicleRoutingProblem); + inserter.insertJob(serviceToInsert, iData, route); + + assertEquals(2, route.getTourActivities().getActivities().size()); + assertEquals(route.getTourActivities().getActivities().get(1).getLocation().getId(), serviceToInsert.getLocation().getId()); + assertEquals(route.getEnd().getLocation().getId(), vehicle.getEndLocation().getId()); + } private Location loc(String vehLoc) { return Location.Builder.newInstance().setId(vehLoc).build(); } @Test - public void whenInsertingServiceAndRouteIsOpen_itInsertsCorrectlyAndSwitchesEndLocation(){ - Service service = mock(Service.class); - Vehicle vehicle = mock(Vehicle.class); - when(vehicle.getStartLocation()).thenReturn(Location.newInstance("vehLoc")); - when(vehicle.getEndLocation()).thenReturn(Location.newInstance("vehLoc")); - when(vehicle.isReturnToDepot()).thenReturn(false); - when(vehicle.getId()).thenReturn("vehId"); - - VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class)).addService(service).build(); - Service serviceToInsert = mock(Service.class); - when(serviceToInsert.getLocation()).thenReturn(Location.Builder.newInstance().setId("delLoc").build()); - - InsertionData iData = mock(InsertionData.class); - when(iData.getDeliveryInsertionIndex()).thenReturn(1); - when(iData.getSelectedVehicle()).thenReturn(vehicle); + public void whenInsertingServiceAndRouteIsOpen_itInsertsCorrectlyAndSwitchesEndLocation() { + Service service = mock(Service.class); + Vehicle vehicle = mock(Vehicle.class); + when(vehicle.getStartLocation()).thenReturn(Location.newInstance("vehLoc")); + when(vehicle.getEndLocation()).thenReturn(Location.newInstance("vehLoc")); + when(vehicle.isReturnToDepot()).thenReturn(false); + when(vehicle.getId()).thenReturn("vehId"); + + VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class)).addService(service).build(); + Service serviceToInsert = mock(Service.class); + when(serviceToInsert.getLocation()).thenReturn(Location.Builder.newInstance().setId("delLoc").build()); + + InsertionData iData = mock(InsertionData.class); + when(iData.getDeliveryInsertionIndex()).thenReturn(1); + when(iData.getSelectedVehicle()).thenReturn(vehicle); VehicleRoutingProblem vehicleRoutingProblem = mock(VehicleRoutingProblem.class); when(vehicleRoutingProblem.copyAndGetActivities(serviceToInsert)).thenReturn(getTourActivities(serviceToInsert)); - Inserter inserter = new Inserter(mock(InsertionListeners.class),vehicleRoutingProblem); - inserter.insertJob(serviceToInsert, iData, route); - - assertEquals(2,route.getTourActivities().getActivities().size()); - assertEquals(route.getTourActivities().getActivities().get(1).getLocation().getId(),serviceToInsert.getLocation().getId()); - assertEquals(route.getEnd().getLocation().getId(),serviceToInsert.getLocation().getId()); - } + Inserter inserter = new Inserter(mock(InsertionListeners.class), vehicleRoutingProblem); + inserter.insertJob(serviceToInsert, iData, route); + + assertEquals(2, route.getTourActivities().getActivities().size()); + assertEquals(route.getTourActivities().getActivities().get(1).getLocation().getId(), serviceToInsert.getLocation().getId()); + assertEquals(route.getEnd().getLocation().getId(), serviceToInsert.getLocation().getId()); + } private List getTourActivities(Service serviceToInsert) { List acts = new ArrayList(); @@ -116,35 +115,35 @@ public class TestInserter { @Test - public void whenInsertingShipmentAndRouteIsClosed_itInsertsCorrectly(){ - Shipment shipment = mock(Shipment.class); - Capacity capacity = Capacity.Builder.newInstance().build(); - when(shipment.getSize()).thenReturn(capacity); - Vehicle vehicle = mock(Vehicle.class); - when(vehicle.getStartLocation()).thenReturn(loc("vehLoc")); - when(vehicle.getEndLocation()).thenReturn(loc("vehLoc")); - when(vehicle.isReturnToDepot()).thenReturn(true); - when(vehicle.getId()).thenReturn("vehId"); - - VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class)).addPickup(shipment).addDelivery(shipment).build(); - //start - pick(shipment) - del(shipment) - end - Shipment shipmentToInsert = Shipment.Builder.newInstance("s").setDeliveryLocation(Location.newInstance("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); + public void whenInsertingShipmentAndRouteIsClosed_itInsertsCorrectly() { + Shipment shipment = mock(Shipment.class); + Capacity capacity = Capacity.Builder.newInstance().build(); + when(shipment.getSize()).thenReturn(capacity); + Vehicle vehicle = mock(Vehicle.class); + when(vehicle.getStartLocation()).thenReturn(loc("vehLoc")); + when(vehicle.getEndLocation()).thenReturn(loc("vehLoc")); + when(vehicle.isReturnToDepot()).thenReturn(true); + when(vehicle.getId()).thenReturn("vehId"); - InsertionData iData = mock(InsertionData.class); - when(iData.getPickupInsertionIndex()).thenReturn(2); - when(iData.getDeliveryInsertionIndex()).thenReturn(2); - when(iData.getSelectedVehicle()).thenReturn(vehicle); + VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class)).addPickup(shipment).addDelivery(shipment).build(); + //start - pick(shipment) - del(shipment) - end + Shipment shipmentToInsert = Shipment.Builder.newInstance("s").setDeliveryLocation(Location.newInstance("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); + + InsertionData iData = mock(InsertionData.class); + when(iData.getPickupInsertionIndex()).thenReturn(2); + when(iData.getDeliveryInsertionIndex()).thenReturn(2); + when(iData.getSelectedVehicle()).thenReturn(vehicle); VehicleRoutingProblem vehicleRoutingProblem = mock(VehicleRoutingProblem.class); when(vehicleRoutingProblem.copyAndGetActivities(shipmentToInsert)).thenReturn(getTourActivities(shipmentToInsert)); - Inserter inserter = new Inserter(mock(InsertionListeners.class), vehicleRoutingProblem); - inserter.insertJob(shipmentToInsert, iData, route); - - assertEquals(4,route.getTourActivities().getActivities().size()); - assertEquals(route.getTourActivities().getActivities().get(2).getLocation().getId(),shipmentToInsert.getPickupLocation().getId()); - assertEquals(route.getTourActivities().getActivities().get(3).getLocation().getId(),shipmentToInsert.getDeliveryLocation().getId()); - assertEquals(route.getEnd().getLocation().getId(),vehicle.getEndLocation().getId()); - } + Inserter inserter = new Inserter(mock(InsertionListeners.class), vehicleRoutingProblem); + inserter.insertJob(shipmentToInsert, iData, route); + + assertEquals(4, route.getTourActivities().getActivities().size()); + assertEquals(route.getTourActivities().getActivities().get(2).getLocation().getId(), shipmentToInsert.getPickupLocation().getId()); + assertEquals(route.getTourActivities().getActivities().get(3).getLocation().getId(), shipmentToInsert.getDeliveryLocation().getId()); + assertEquals(route.getEnd().getLocation().getId(), vehicle.getEndLocation().getId()); + } private List getTourActivities(Shipment shipmentToInsert) { List acts = new ArrayList(); @@ -154,110 +153,110 @@ public class TestInserter { } @Test - public void whenInsertingShipmentAndRouteIsOpen_itInsertsCorrectlyAndSwitchesEndLocation(){ - Shipment shipment = mock(Shipment.class); - Capacity capacity = Capacity.Builder.newInstance().build(); - when(shipment.getSize()).thenReturn(capacity); - Vehicle vehicle = mock(Vehicle.class); - when(vehicle.isReturnToDepot()).thenReturn(false); - when(vehicle.getId()).thenReturn("vehId"); - - VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class)).addPickup(shipment).addDelivery(shipment).build(); - //start - pick(shipment) - del(shipment) - end - Shipment shipmentToInsert = Shipment.Builder.newInstance("s").setDeliveryLocation(Location.newInstance("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); - InsertionData iData = mock(InsertionData.class); - when(iData.getPickupInsertionIndex()).thenReturn(2); - when(iData.getDeliveryInsertionIndex()).thenReturn(2); - when(iData.getSelectedVehicle()).thenReturn(vehicle); + public void whenInsertingShipmentAndRouteIsOpen_itInsertsCorrectlyAndSwitchesEndLocation() { + Shipment shipment = mock(Shipment.class); + Capacity capacity = Capacity.Builder.newInstance().build(); + when(shipment.getSize()).thenReturn(capacity); + Vehicle vehicle = mock(Vehicle.class); + when(vehicle.isReturnToDepot()).thenReturn(false); + when(vehicle.getId()).thenReturn("vehId"); + + VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class)).addPickup(shipment).addDelivery(shipment).build(); + //start - pick(shipment) - del(shipment) - end + Shipment shipmentToInsert = Shipment.Builder.newInstance("s").setDeliveryLocation(Location.newInstance("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); + InsertionData iData = mock(InsertionData.class); + when(iData.getPickupInsertionIndex()).thenReturn(2); + when(iData.getDeliveryInsertionIndex()).thenReturn(2); + when(iData.getSelectedVehicle()).thenReturn(vehicle); VehicleRoutingProblem vehicleRoutingProblem = mock(VehicleRoutingProblem.class); when(vehicleRoutingProblem.copyAndGetActivities(shipmentToInsert)).thenReturn(getTourActivities(shipmentToInsert)); - Inserter inserter = new Inserter(mock(InsertionListeners.class), vehicleRoutingProblem); - inserter.insertJob(shipmentToInsert, iData, route); - - assertEquals(4,route.getTourActivities().getActivities().size()); - assertEquals(route.getTourActivities().getActivities().get(2).getLocation().getId(),shipmentToInsert.getPickupLocation().getId()); - assertEquals(route.getTourActivities().getActivities().get(3).getLocation().getId(),shipmentToInsert.getDeliveryLocation().getId()); - assertEquals(route.getEnd().getLocation().getId(),shipmentToInsert.getDeliveryLocation().getId()); - } - - @Test - public void whenSwitchingVehicleAndRouteIsClosed_newStartAndEndShouldBeTheLocationOfNewVehicle(){ - Shipment shipment = mock(Shipment.class); - Capacity capacity = Capacity.Builder.newInstance().build(); - when(shipment.getSize()).thenReturn(capacity); - Vehicle vehicle = VehicleImpl.Builder.newInstance("vehId").setStartLocation(Location.newInstance("vehLoc")).setType(mock(VehicleType.class)).build(); - Vehicle newVehicle = VehicleImpl.Builder.newInstance("newVehId").setStartLocation(Location.newInstance("newVehLoc")).setType(mock(VehicleType.class)).build(); - - VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class)).addPickup(shipment).addDelivery(shipment).build(); - //start - pick(shipment) - del(shipment) - end - Shipment shipmentToInsert = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).setDeliveryLocation(Location.newInstance("delLoc")).build(); - - InsertionData iData = mock(InsertionData.class); - when(iData.getPickupInsertionIndex()).thenReturn(2); - when(iData.getDeliveryInsertionIndex()).thenReturn(2); - when(iData.getSelectedVehicle()).thenReturn(newVehicle); + Inserter inserter = new Inserter(mock(InsertionListeners.class), vehicleRoutingProblem); + inserter.insertJob(shipmentToInsert, iData, route); - VehicleRoutingProblem vehicleRoutingProblem = mock(VehicleRoutingProblem.class); - when(vehicleRoutingProblem.copyAndGetActivities(shipmentToInsert)).thenReturn(getTourActivities(shipmentToInsert)); - Inserter inserter = new Inserter(mock(InsertionListeners.class), vehicleRoutingProblem); - inserter.insertJob(shipmentToInsert, iData, route); - - assertEquals(route.getEnd().getLocation().getId(),newVehicle.getEndLocation().getId()); - } - - @Test - public void whenSwitchingVehicleAndRouteIsOpen_endLocationShouldBeTheLocationOfTheLastActivity(){ - Shipment shipment = mock(Shipment.class); - Capacity capacity = Capacity.Builder.newInstance().build(); - when(shipment.getSize()).thenReturn(capacity); - Vehicle vehicle = VehicleImpl.Builder.newInstance("vehId").setReturnToDepot(false).setStartLocation(Location.newInstance("vehLoc")).setType(mock(VehicleType.class)).build(); - Vehicle newVehicle = VehicleImpl.Builder.newInstance("newVehId").setReturnToDepot(false).setStartLocation(Location.newInstance("newVehLoc")).setType(mock(VehicleType.class)).build(); - - VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class)).addPickup(shipment).addDelivery(shipment).build(); - //start - pick(shipment) - del(shipment) - end + assertEquals(4, route.getTourActivities().getActivities().size()); + assertEquals(route.getTourActivities().getActivities().get(2).getLocation().getId(), shipmentToInsert.getPickupLocation().getId()); + assertEquals(route.getTourActivities().getActivities().get(3).getLocation().getId(), shipmentToInsert.getDeliveryLocation().getId()); + assertEquals(route.getEnd().getLocation().getId(), shipmentToInsert.getDeliveryLocation().getId()); + } + + @Test + public void whenSwitchingVehicleAndRouteIsClosed_newStartAndEndShouldBeTheLocationOfNewVehicle() { + Shipment shipment = mock(Shipment.class); + Capacity capacity = Capacity.Builder.newInstance().build(); + when(shipment.getSize()).thenReturn(capacity); + Vehicle vehicle = VehicleImpl.Builder.newInstance("vehId").setStartLocation(Location.newInstance("vehLoc")).setType(mock(VehicleType.class)).build(); + Vehicle newVehicle = VehicleImpl.Builder.newInstance("newVehId").setStartLocation(Location.newInstance("newVehLoc")).setType(mock(VehicleType.class)).build(); + + VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class)).addPickup(shipment).addDelivery(shipment).build(); + //start - pick(shipment) - del(shipment) - end Shipment shipmentToInsert = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).setDeliveryLocation(Location.newInstance("delLoc")).build(); InsertionData iData = mock(InsertionData.class); - when(iData.getPickupInsertionIndex()).thenReturn(2); - when(iData.getDeliveryInsertionIndex()).thenReturn(2); - when(iData.getSelectedVehicle()).thenReturn(newVehicle); + when(iData.getPickupInsertionIndex()).thenReturn(2); + when(iData.getDeliveryInsertionIndex()).thenReturn(2); + when(iData.getSelectedVehicle()).thenReturn(newVehicle); VehicleRoutingProblem vehicleRoutingProblem = mock(VehicleRoutingProblem.class); when(vehicleRoutingProblem.copyAndGetActivities(shipmentToInsert)).thenReturn(getTourActivities(shipmentToInsert)); - Inserter inserter = new Inserter(mock(InsertionListeners.class),vehicleRoutingProblem ); - inserter.insertJob(shipmentToInsert, iData, route); - - assertEquals("delLoc",route.getEnd().getLocation().getId()); - } - - @Test - public void whenInsertingShipmentAtBeginningAndSwitchingVehicleAndRouteIsOpen_endLocationShouldBeTheLocationOfTheLastActivity(){ - Shipment shipment = mock(Shipment.class); - Capacity capacity = Capacity.Builder.newInstance().build(); - when(shipment.getSize()).thenReturn(capacity); - when(shipment.getDeliveryLocation()).thenReturn(Location.Builder.newInstance().setId("oldShipmentDelLoc").build()); - Vehicle vehicle = VehicleImpl.Builder.newInstance("vehId").setReturnToDepot(false).setStartLocation(Location.Builder.newInstance().setId("vehLoc").build()).setType(mock(VehicleType.class)).build(); - Vehicle newVehicle = VehicleImpl.Builder.newInstance("newVehId").setReturnToDepot(false).setStartLocation(Location.Builder.newInstance().setId("newVehLoc").build()).setType(mock(VehicleType.class)).build(); - - VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class)).addPickup(shipment).addDelivery(shipment).build(); - //start - pick(shipment) - del(shipment) - end + Inserter inserter = new Inserter(mock(InsertionListeners.class), vehicleRoutingProblem); + inserter.insertJob(shipmentToInsert, iData, route); + + assertEquals(route.getEnd().getLocation().getId(), newVehicle.getEndLocation().getId()); + } + + @Test + public void whenSwitchingVehicleAndRouteIsOpen_endLocationShouldBeTheLocationOfTheLastActivity() { + Shipment shipment = mock(Shipment.class); + Capacity capacity = Capacity.Builder.newInstance().build(); + when(shipment.getSize()).thenReturn(capacity); + Vehicle vehicle = VehicleImpl.Builder.newInstance("vehId").setReturnToDepot(false).setStartLocation(Location.newInstance("vehLoc")).setType(mock(VehicleType.class)).build(); + Vehicle newVehicle = VehicleImpl.Builder.newInstance("newVehId").setReturnToDepot(false).setStartLocation(Location.newInstance("newVehLoc")).setType(mock(VehicleType.class)).build(); + + VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class)).addPickup(shipment).addDelivery(shipment).build(); + //start - pick(shipment) - del(shipment) - end Shipment shipmentToInsert = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).setDeliveryLocation(Location.newInstance("delLoc")).build(); InsertionData iData = mock(InsertionData.class); - when(iData.getPickupInsertionIndex()).thenReturn(0); - when(iData.getDeliveryInsertionIndex()).thenReturn(0); - when(iData.getSelectedVehicle()).thenReturn(newVehicle); + when(iData.getPickupInsertionIndex()).thenReturn(2); + when(iData.getDeliveryInsertionIndex()).thenReturn(2); + when(iData.getSelectedVehicle()).thenReturn(newVehicle); VehicleRoutingProblem vehicleRoutingProblem = mock(VehicleRoutingProblem.class); when(vehicleRoutingProblem.copyAndGetActivities(shipmentToInsert)).thenReturn(getTourActivities(shipmentToInsert)); - Inserter inserter = new Inserter(mock(InsertionListeners.class),vehicleRoutingProblem ); - inserter.insertJob(shipmentToInsert, iData, route); - - UpdateEndLocationIfRouteIsOpen updateEnd = new UpdateEndLocationIfRouteIsOpen(); - updateEnd.visit(route); - - assertEquals("oldShipmentDelLoc",route.getEnd().getLocation().getId()); - } + Inserter inserter = new Inserter(mock(InsertionListeners.class), vehicleRoutingProblem); + inserter.insertJob(shipmentToInsert, iData, route); + + assertEquals("delLoc", route.getEnd().getLocation().getId()); + } + + @Test + public void whenInsertingShipmentAtBeginningAndSwitchingVehicleAndRouteIsOpen_endLocationShouldBeTheLocationOfTheLastActivity() { + Shipment shipment = mock(Shipment.class); + Capacity capacity = Capacity.Builder.newInstance().build(); + when(shipment.getSize()).thenReturn(capacity); + when(shipment.getDeliveryLocation()).thenReturn(Location.Builder.newInstance().setId("oldShipmentDelLoc").build()); + Vehicle vehicle = VehicleImpl.Builder.newInstance("vehId").setReturnToDepot(false).setStartLocation(Location.Builder.newInstance().setId("vehLoc").build()).setType(mock(VehicleType.class)).build(); + Vehicle newVehicle = VehicleImpl.Builder.newInstance("newVehId").setReturnToDepot(false).setStartLocation(Location.Builder.newInstance().setId("newVehLoc").build()).setType(mock(VehicleType.class)).build(); + + VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class)).addPickup(shipment).addDelivery(shipment).build(); + //start - pick(shipment) - del(shipment) - end + Shipment shipmentToInsert = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).setDeliveryLocation(Location.newInstance("delLoc")).build(); + + InsertionData iData = mock(InsertionData.class); + when(iData.getPickupInsertionIndex()).thenReturn(0); + when(iData.getDeliveryInsertionIndex()).thenReturn(0); + when(iData.getSelectedVehicle()).thenReturn(newVehicle); + + VehicleRoutingProblem vehicleRoutingProblem = mock(VehicleRoutingProblem.class); + when(vehicleRoutingProblem.copyAndGetActivities(shipmentToInsert)).thenReturn(getTourActivities(shipmentToInsert)); + Inserter inserter = new Inserter(mock(InsertionListeners.class), vehicleRoutingProblem); + inserter.insertJob(shipmentToInsert, iData, route); + + UpdateEndLocationIfRouteIsOpen updateEnd = new UpdateEndLocationIfRouteIsOpen(); + updateEnd.visit(route); + + assertEquals("oldShipmentDelLoc", route.getEnd().getLocation().getId()); + } } diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/TestLocalActivityInsertionCostsCalculator.java b/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/TestLocalActivityInsertionCostsCalculator.java index 92b02a7d..a6d4ec08 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/TestLocalActivityInsertionCostsCalculator.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/TestLocalActivityInsertionCostsCalculator.java @@ -16,118 +16,496 @@ ******************************************************************************/ package jsprit.core.algorithm.recreate; +import jsprit.core.algorithm.state.StateManager; +import jsprit.core.algorithm.state.UpdateActivityTimes; +import jsprit.core.algorithm.state.UpdateFutureWaitingTimes; +import jsprit.core.algorithm.state.UpdateVehicleDependentPracticalTimeWindows; import jsprit.core.problem.Location; +import jsprit.core.problem.VehicleRoutingProblem; import jsprit.core.problem.cost.VehicleRoutingActivityCosts; import jsprit.core.problem.cost.VehicleRoutingTransportCosts; +import jsprit.core.problem.cost.WaitingTimeCosts; +import jsprit.core.problem.job.Job; +import jsprit.core.problem.job.Service; import jsprit.core.problem.misc.JobInsertionContext; import jsprit.core.problem.solution.route.VehicleRoute; import jsprit.core.problem.solution.route.activity.End; +import jsprit.core.problem.solution.route.activity.Start; +import jsprit.core.problem.solution.route.activity.TimeWindow; import jsprit.core.problem.solution.route.activity.TourActivity; import jsprit.core.problem.vehicle.Vehicle; +import jsprit.core.problem.vehicle.VehicleImpl; +import jsprit.core.problem.vehicle.VehicleTypeImpl; +import jsprit.core.util.CostFactory; import org.junit.Before; import org.junit.Test; +import java.util.ArrayList; +import java.util.Arrays; + import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; public class TestLocalActivityInsertionCostsCalculator { - VehicleRoutingTransportCosts tpCosts; - - VehicleRoutingActivityCosts actCosts; - - LocalActivityInsertionCostsCalculator calc; - - Vehicle vehicle; - - VehicleRoute route; - - JobInsertionContext jic; - - @Before - public void doBefore(){ - - vehicle = mock(Vehicle.class); - route = mock(VehicleRoute.class); - when(route.isEmpty()).thenReturn(false); - when(route.getVehicle()).thenReturn(vehicle); - - jic = mock(JobInsertionContext.class); - when(jic.getRoute()).thenReturn(route); - when(jic.getNewVehicle()).thenReturn(vehicle); - - tpCosts = mock(VehicleRoutingTransportCosts.class); - when(tpCosts.getTransportCost(loc("i"), loc("j"), 0.0, null, vehicle)).thenReturn(2.0); - when(tpCosts.getTransportTime(loc("i"), loc("j"), 0.0, null, vehicle)).thenReturn(0.0); - when(tpCosts.getTransportCost(loc("i"), loc("k"), 0.0, null, vehicle)).thenReturn(3.0); - when(tpCosts.getTransportTime(loc("i"), loc("k"), 0.0, null, vehicle)).thenReturn(0.0); - when(tpCosts.getTransportCost(loc("k"), loc("j"), 0.0, null, vehicle)).thenReturn(3.0); - when(tpCosts.getTransportTime(loc("k"), loc("j"), 0.0, null, vehicle)).thenReturn(0.0); - - actCosts = mock(VehicleRoutingActivityCosts.class); - calc = new LocalActivityInsertionCostsCalculator(tpCosts, actCosts); - } + VehicleRoutingTransportCosts tpCosts; + + VehicleRoutingActivityCosts actCosts; + + LocalActivityInsertionCostsCalculator calc; + + Vehicle vehicle; + + VehicleRoute route; + + JobInsertionContext jic; + + @Before + public void doBefore() { + + vehicle = mock(Vehicle.class); + route = mock(VehicleRoute.class); + when(route.isEmpty()).thenReturn(false); + when(route.getVehicle()).thenReturn(vehicle); + + jic = mock(JobInsertionContext.class); + when(jic.getRoute()).thenReturn(route); + when(jic.getNewVehicle()).thenReturn(vehicle); + when(vehicle.getType()).thenReturn(VehicleTypeImpl.Builder.newInstance("type").build()); + + tpCosts = mock(VehicleRoutingTransportCosts.class); + when(tpCosts.getTransportCost(loc("i"), loc("j"), 0.0, null, vehicle)).thenReturn(2.0); + when(tpCosts.getTransportTime(loc("i"), loc("j"), 0.0, null, vehicle)).thenReturn(0.0); + when(tpCosts.getTransportCost(loc("i"), loc("k"), 0.0, null, vehicle)).thenReturn(3.0); + when(tpCosts.getTransportTime(loc("i"), loc("k"), 0.0, null, vehicle)).thenReturn(0.0); + when(tpCosts.getTransportCost(loc("k"), loc("j"), 0.0, null, vehicle)).thenReturn(3.0); + when(tpCosts.getTransportTime(loc("k"), loc("j"), 0.0, null, vehicle)).thenReturn(0.0); + + actCosts = mock(VehicleRoutingActivityCosts.class); + calc = new LocalActivityInsertionCostsCalculator(tpCosts, actCosts, mock(StateManager.class)); + } private Location loc(String i) { return Location.Builder.newInstance().setId(i).build(); } @Test - public void whenInsertingActBetweenTwoRouteActs_itCalcsMarginalTpCosts(){ - TourActivity prevAct = mock(TourActivity.class); - when(prevAct.getLocation()).thenReturn(loc("i")); - TourActivity nextAct = mock(TourActivity.class); - when(nextAct.getLocation()).thenReturn(loc("j")); - TourActivity newAct = mock(TourActivity.class); - when(newAct.getLocation()).thenReturn(loc("k")); - - when(vehicle.isReturnToDepot()).thenReturn(true); - - double costs = calc.getCosts(jic, prevAct, nextAct, newAct, 0.0); - assertEquals(4.0,costs,0.01); - } - - @Test - public void whenInsertingActBetweenLastActAndEnd_itCalcsMarginalTpCosts(){ - TourActivity prevAct = mock(TourActivity.class); - when(prevAct.getLocation()).thenReturn(loc("i")); - End nextAct = End.newInstance("j", 0.0, 0.0); - TourActivity newAct = mock(TourActivity.class); - when(newAct.getLocation()).thenReturn(loc("k")); - - when(vehicle.isReturnToDepot()).thenReturn(true); - - double costs = calc.getCosts(jic, prevAct, nextAct, newAct, 0.0); - assertEquals(4.0,costs,0.01); - } + public void whenInsertingActBetweenTwoRouteActs_itCalcsMarginalTpCosts() { + TourActivity prevAct = mock(TourActivity.class); + when(prevAct.getLocation()).thenReturn(loc("i")); + when(prevAct.getIndex()).thenReturn(1); + TourActivity nextAct = mock(TourActivity.class); + when(nextAct.getLocation()).thenReturn(loc("j")); + when(nextAct.getIndex()).thenReturn(1); + TourActivity newAct = mock(TourActivity.class); + when(newAct.getLocation()).thenReturn(loc("k")); + when(newAct.getIndex()).thenReturn(1); - @Test - public void whenInsertingActBetweenTwoRouteActsAndRouteIsOpen_itCalcsMarginalTpCosts(){ - TourActivity prevAct = mock(TourActivity.class); - when(prevAct.getLocation()).thenReturn(loc("i")); - TourActivity nextAct = mock(TourActivity.class); - when(nextAct.getLocation()).thenReturn(loc("j")); - TourActivity newAct = mock(TourActivity.class); - when(newAct.getLocation()).thenReturn(loc("k")); - - when(vehicle.isReturnToDepot()).thenReturn(false); - - double costs = calc.getCosts(jic, prevAct, nextAct, newAct, 0.0); - assertEquals(4.0,costs,0.01); - } - - @Test - public void whenInsertingActBetweenLastActAndEndAndRouteIsOpen_itCalculatesTpCostsFromPrevToNewAct(){ - TourActivity prevAct = mock(TourActivity.class); - when(prevAct.getLocation()).thenReturn(loc("i")); - End nextAct = End.newInstance("j", 0.0, 0.0); - TourActivity newAct = mock(TourActivity.class); - when(newAct.getLocation()).thenReturn(loc("k")); - - when(vehicle.isReturnToDepot()).thenReturn(false); - - double costs = calc.getCosts(jic, prevAct, nextAct, newAct, 0.0); - assertEquals(3.0,costs,0.01); - } + when(vehicle.isReturnToDepot()).thenReturn(true); + + double costs = calc.getCosts(jic, prevAct, nextAct, newAct, 0.0); + assertEquals(4.0, costs, 0.01); + } + + @Test + public void whenInsertingActBetweenLastActAndEnd_itCalcsMarginalTpCosts() { + TourActivity prevAct = mock(TourActivity.class); + when(prevAct.getLocation()).thenReturn(loc("i")); + when(prevAct.getIndex()).thenReturn(1); + End nextAct = End.newInstance("j", 0.0, 0.0); + TourActivity newAct = mock(TourActivity.class); + when(newAct.getLocation()).thenReturn(loc("k")); + when(newAct.getIndex()).thenReturn(1); + + when(vehicle.isReturnToDepot()).thenReturn(true); + + double costs = calc.getCosts(jic, prevAct, nextAct, newAct, 0.0); + assertEquals(4.0, costs, 0.01); + } + + @Test + public void whenInsertingActBetweenTwoRouteActsAndRouteIsOpen_itCalcsMarginalTpCosts() { + TourActivity prevAct = mock(TourActivity.class); + when(prevAct.getLocation()).thenReturn(loc("i")); + when(prevAct.getIndex()).thenReturn(1); + TourActivity nextAct = mock(TourActivity.class); + when(nextAct.getLocation()).thenReturn(loc("j")); + when(nextAct.getIndex()).thenReturn(1); + TourActivity newAct = mock(TourActivity.class); + when(newAct.getLocation()).thenReturn(loc("k")); + when(newAct.getIndex()).thenReturn(1); + + when(vehicle.isReturnToDepot()).thenReturn(false); + + double costs = calc.getCosts(jic, prevAct, nextAct, newAct, 0.0); + assertEquals(4.0, costs, 0.01); + } + + @Test + public void whenInsertingActBetweenLastActAndEndAndRouteIsOpen_itCalculatesTpCostsFromPrevToNewAct() { + TourActivity prevAct = mock(TourActivity.class); + when(prevAct.getLocation()).thenReturn(loc("i")); + when(prevAct.getIndex()).thenReturn(1); + End nextAct = End.newInstance("j", 0.0, 0.0); + TourActivity newAct = mock(TourActivity.class); + when(newAct.getLocation()).thenReturn(loc("k")); + when(newAct.getIndex()).thenReturn(1); + + when(vehicle.isReturnToDepot()).thenReturn(false); + + double costs = calc.getCosts(jic, prevAct, nextAct, newAct, 0.0); + assertEquals(3.0, costs, 0.01); + } + + @Test + public void test() { + VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("t").setCostPerWaitingTime(1.).build(); + VehicleImpl v = VehicleImpl.Builder.newInstance("v").setType(type).setStartLocation(Location.newInstance(0, 0)).build(); + Service prevS = Service.Builder.newInstance("prev").setLocation(Location.newInstance(10, 0)).build(); + Service newS = Service.Builder.newInstance("new").setServiceTime(10).setLocation(Location.newInstance(60, 0)).build(); + Service nextS = Service.Builder.newInstance("next").setLocation(Location.newInstance(30, 0)).setTimeWindow(TimeWindow.newInstance(40, 80)).build(); + + VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(prevS).addJob(newS).addJob(nextS).addVehicle(v).build(); + + TourActivity prevAct = vrp.getActivities(prevS).get(0); + TourActivity newAct = vrp.getActivities(newS).get(0); + TourActivity nextAct = vrp.getActivities(nextS).get(0); + + VehicleRoute route = VehicleRoute.Builder.newInstance(v).setJobActivityFactory(vrp.getJobActivityFactory()).addService(prevS).addService(nextS).build(); + JobInsertionContext context = new JobInsertionContext(route, newS, v, null, 0.); + VehicleRoutingProblem vrpMock = mock(VehicleRoutingProblem.class); + when(vrpMock.getFleetSize()).thenReturn(VehicleRoutingProblem.FleetSize.INFINITE); + LocalActivityInsertionCostsCalculator calc = new LocalActivityInsertionCostsCalculator(CostFactory.createEuclideanCosts(), new WaitingTimeCosts(), new StateManager(vrpMock)); + calc.setSolutionCompletenessRatio(1.); + + double c = calc.getCosts(context, prevAct, nextAct, newAct, 10); + assertEquals(50., c, 0.01); + + /* + new: dist = 90 & wait = 0 + old: dist = 30 & wait = 10 + c = new - old = 90 - 40 = 50 + */ + } + + @Test + public void whenAddingNewBetweenStartAndAct_itShouldCalcInsertionCostsCorrectly() { + VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("t").setCostPerWaitingTime(1.).build(); + + VehicleImpl v = VehicleImpl.Builder.newInstance("v").setType(type).setStartLocation(Location.newInstance(0, 0)).build(); + + Service newS = Service.Builder.newInstance("new").setServiceTime(10).setLocation(Location.newInstance(10, 0)).build(); + Service nextS = Service.Builder.newInstance("next").setLocation(Location.newInstance(30, 0)) + .setTimeWindow(TimeWindow.newInstance(40, 50)).build(); + + VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(newS).addJob(nextS).addVehicle(v).build(); + + Start prevAct = new Start(Location.newInstance(0, 0), 0, 100); + TourActivity newAct = vrp.getActivities(newS).get(0); + TourActivity nextAct = vrp.getActivities(nextS).get(0); + + VehicleRoute route = VehicleRoute.Builder.newInstance(v).setJobActivityFactory(vrp.getJobActivityFactory()).addService(nextS).build(); + JobInsertionContext context = new JobInsertionContext(route, newS, v, null, 0.); + LocalActivityInsertionCostsCalculator calc = new LocalActivityInsertionCostsCalculator(CostFactory.createEuclideanCosts(), new WaitingTimeCosts(), new StateManager(vrp)); + calc.setSolutionCompletenessRatio(1.); + double c = calc.getCosts(context, prevAct, nextAct, newAct, 0); + assertEquals(-10., c, 0.01); + } + + @Test + public void whenAddingNewBetweenStartAndAct2_itShouldCalcInsertionCostsCorrectly() { + VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("t").setCostPerWaitingTime(1.).build(); + + VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2").setType(type).setStartLocation(Location.newInstance(0, 0)).build(); + + Service newS = Service.Builder.newInstance("new").setServiceTime(10).setLocation(Location.newInstance(10, 0)).build(); + Service nextS = Service.Builder.newInstance("next").setLocation(Location.newInstance(30, 0)) + .setTimeWindow(TimeWindow.newInstance(140, 150)).build(); + + VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(newS).addJob(nextS).addVehicle(v2).build(); + + Start prevAct = new Start(Location.newInstance(0, 0), 0, 100); + TourActivity newAct = vrp.getActivities(newS).get(0); + TourActivity nextAct = vrp.getActivities(nextS).get(0); + + VehicleRoute route = VehicleRoute.Builder.newInstance(v2).setJobActivityFactory(vrp.getJobActivityFactory()).addService(nextS).build(); + JobInsertionContext context = new JobInsertionContext(route, newS, v2, null, 0.); + LocalActivityInsertionCostsCalculator calc = new LocalActivityInsertionCostsCalculator(CostFactory.createEuclideanCosts(), new WaitingTimeCosts(), new StateManager(vrp)); + calc.setSolutionCompletenessRatio(1.); + double c = calc.getCosts(context, prevAct, nextAct, newAct, 0); + assertEquals(-10., c, 0.01); + } + + @Test + public void whenAddingNewInEmptyRoute_itShouldCalcInsertionCostsCorrectly() { + VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("t").setCostPerWaitingTime(1.).build(); + VehicleImpl v = VehicleImpl.Builder.newInstance("v").setType(type).setStartLocation(Location.newInstance(0, 0)).build(); + + Service newS = Service.Builder.newInstance("new").setServiceTime(10).setLocation(Location.newInstance(10, 0)).setTimeWindow(TimeWindow.newInstance(100, 150)).build(); + + VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(newS).addVehicle(v).build(); + + Start prevAct = new Start(Location.newInstance(0, 0), 0, 100); + TourActivity newAct = vrp.getActivities(newS).get(0); + End nextAct = new End(Location.newInstance(0, 0), 0, 100); + + VehicleRoute route = VehicleRoute.Builder.newInstance(v).setJobActivityFactory(vrp.getJobActivityFactory()).build(); + JobInsertionContext context = new JobInsertionContext(route, newS, v, null, 0.); + LocalActivityInsertionCostsCalculator calc = new LocalActivityInsertionCostsCalculator(CostFactory.createEuclideanCosts(), new WaitingTimeCosts(), new StateManager(vrp)); + calc.setSolutionCompletenessRatio(1.); + double c = calc.getCosts(context, prevAct, nextAct, newAct, 0); + assertEquals(110., c, 0.01); + } + + @Test + public void whenAddingNewBetweenTwoActs_itShouldCalcInsertionCostsCorrectly() { + VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("t").setCostPerWaitingTime(1.).build(); + + VehicleImpl v = VehicleImpl.Builder.newInstance("v").setType(type).setStartLocation(Location.newInstance(0, 0)).build(); + + Service prevS = Service.Builder.newInstance("prev").setLocation(Location.newInstance(10, 0)).build(); + Service newS = Service.Builder.newInstance("new").setServiceTime(10).setLocation(Location.newInstance(20, 0)).build(); + Service nextS = Service.Builder.newInstance("next").setLocation(Location.newInstance(30, 0)).setTimeWindow(TimeWindow.newInstance(40, 50)).build(); + + VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(prevS).addJob(newS).addJob(nextS).addVehicle(v).build(); + + TourActivity prevAct = vrp.getActivities(prevS).get(0); + TourActivity newAct = vrp.getActivities(newS).get(0); + TourActivity nextAct = vrp.getActivities(nextS).get(0); + + VehicleRoute route = VehicleRoute.Builder.newInstance(v).setJobActivityFactory(vrp.getJobActivityFactory()).addService(prevS).addService(nextS).build(); + JobInsertionContext context = new JobInsertionContext(route, newS, v, null, 0.); + LocalActivityInsertionCostsCalculator calc = new LocalActivityInsertionCostsCalculator(CostFactory.createEuclideanCosts(), new WaitingTimeCosts(), new StateManager(vrp)); + calc.setSolutionCompletenessRatio(1.); + double c = calc.getCosts(context, prevAct, nextAct, newAct, 10); + assertEquals(-10., c, 0.01); + } + + @Test + public void whenAddingNewWithTWBetweenTwoActs_itShouldCalcInsertionCostsCorrectly() { + VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("t").setCostPerWaitingTime(1.).build(); + + VehicleImpl v = VehicleImpl.Builder.newInstance("v").setType(type).setStartLocation(Location.newInstance(0, 0)).build(); + + Service prevS = Service.Builder.newInstance("prev").setLocation(Location.newInstance(10, 0)).build(); + Service newS = Service.Builder.newInstance("new").setServiceTime(10).setTimeWindow(TimeWindow.newInstance(100, 120)).setLocation(Location.newInstance(20, 0)).build(); + Service nextS = Service.Builder.newInstance("next").setLocation(Location.newInstance(30, 0)).setTimeWindow(TimeWindow.newInstance(40, 500)).build(); + + VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(prevS).addJob(newS).addJob(nextS).addVehicle(v).build(); + + TourActivity prevAct = vrp.getActivities(prevS).get(0); + TourActivity newAct = vrp.getActivities(newS).get(0); + TourActivity nextAct = vrp.getActivities(nextS).get(0); + + VehicleRoute route = VehicleRoute.Builder.newInstance(v).setJobActivityFactory(vrp.getJobActivityFactory()).addService(prevS).addService(nextS).build(); + JobInsertionContext context = new JobInsertionContext(route, newS, v, null, 0.); + LocalActivityInsertionCostsCalculator calc = new LocalActivityInsertionCostsCalculator(CostFactory.createEuclideanCosts(), new WaitingTimeCosts(), new StateManager(vrp)); + calc.setSolutionCompletenessRatio(0.5); + double c = calc.getCosts(context, prevAct, nextAct, newAct, 10); + assertEquals(35., c, 0.01); + } + + @Test + public void whenAddingNewWithTWBetweenTwoActs2_itShouldCalcInsertionCostsCorrectly() { + VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("t").setCostPerWaitingTime(1.).build(); + + VehicleImpl v = VehicleImpl.Builder.newInstance("v").setType(type).setStartLocation(Location.newInstance(0, 0)).build(); +// VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2").setHasVariableDepartureTime(true).setType(type).setStartLocation(Location.newInstance(0,0)).build(); + + Service prevS = Service.Builder.newInstance("prev").setLocation(Location.newInstance(10, 0)).build(); + Service newS = Service.Builder.newInstance("new").setServiceTime(10).setTimeWindow(TimeWindow.newInstance(100, 120)).setLocation(Location.newInstance(20, 0)).build(); + Service nextS = Service.Builder.newInstance("next").setLocation(Location.newInstance(30, 0)).setTimeWindow(TimeWindow.newInstance(40, 500)).build(); + + Service afterNextS = Service.Builder.newInstance("afterNext").setLocation(Location.newInstance(40, 0)).setTimeWindow(TimeWindow.newInstance(400, 500)).build(); + + VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(afterNextS).addJob(prevS).addJob(newS).addJob(nextS).addVehicle(v).build(); + + TourActivity prevAct = vrp.getActivities(prevS).get(0); + TourActivity newAct = vrp.getActivities(newS).get(0); + TourActivity nextAct = vrp.getActivities(nextS).get(0); + + VehicleRoute route = VehicleRoute.Builder.newInstance(v).setJobActivityFactory(vrp.getJobActivityFactory()).addService(prevS).addService(nextS).addService(afterNextS).build(); + + StateManager stateManager = getStateManager(vrp, route); + + JobInsertionContext context = new JobInsertionContext(route, newS, v, null, 0.); + LocalActivityInsertionCostsCalculator calc = new LocalActivityInsertionCostsCalculator(CostFactory.createEuclideanCosts(), new WaitingTimeCosts(), stateManager); + calc.setSolutionCompletenessRatio(1.); + double c = calc.getCosts(context, prevAct, nextAct, newAct, 10); + assertEquals(-10., c, 0.01); + // + //old: dist: 0, waiting: 10 + 350 = 360 + //new: dist: 0, waiting: 80 + 270 = 350 + } + + @Test + public void whenAddingNewWithTWBetweenTwoActs3_itShouldCalcInsertionCostsCorrectly() { + VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("t").setCostPerWaitingTime(1.).build(); + + VehicleImpl v = VehicleImpl.Builder.newInstance("v").setType(type).setStartLocation(Location.newInstance(0, 0)).build(); +// VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2").setHasVariableDepartureTime(true).setType(type).setStartLocation(Location.newInstance(0,0)).build(); + + Service prevS = Service.Builder.newInstance("prev").setLocation(Location.newInstance(10, 0)).build(); + Service newS = Service.Builder.newInstance("new").setServiceTime(10).setTimeWindow(TimeWindow.newInstance(100, 120)).setLocation(Location.newInstance(20, 0)).build(); + Service nextS = Service.Builder.newInstance("next").setLocation(Location.newInstance(30, 0)).setTimeWindow(TimeWindow.newInstance(40, 500)).build(); + + Service afterNextS = Service.Builder.newInstance("afterNext").setLocation(Location.newInstance(40, 0)).setTimeWindow(TimeWindow.newInstance(80, 500)).build(); + Service afterAfterNextS = Service.Builder.newInstance("afterAfterNext").setLocation(Location.newInstance(40, 0)).setTimeWindow(TimeWindow.newInstance(100, 500)).build(); + + VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addVehicle(v).addJob(prevS).addJob(newS).addJob(nextS) + .addJob(afterNextS).addJob(afterAfterNextS).build(); + + TourActivity prevAct = vrp.getActivities(prevS).get(0); + TourActivity newAct = vrp.getActivities(newS).get(0); + TourActivity nextAct = vrp.getActivities(nextS).get(0); + + VehicleRoute route = VehicleRoute.Builder.newInstance(v).setJobActivityFactory(vrp.getJobActivityFactory()).addService(prevS).addService(nextS).addService(afterNextS).addService(afterAfterNextS).build(); + + StateManager stateManager = getStateManager(vrp, route); + + JobInsertionContext context = new JobInsertionContext(route, newS, v, null, 0.); + LocalActivityInsertionCostsCalculator calc = new LocalActivityInsertionCostsCalculator(CostFactory.createEuclideanCosts(), new WaitingTimeCosts(), stateManager); + calc.setSolutionCompletenessRatio(1.); + double c = calc.getCosts(context, prevAct, nextAct, newAct, 10); + assertEquals(20., c, 0.01); + //start-delay = new - old = 120 - 40 = 80 > future waiting time savings = 30 + 20 + 10 + //ref: 10 + 50 + 20 = 80 + //new: 80 - 10 - 30 - 20 = 20 + /* + w(new) + w(next) - w_old(next) - min{start_delay(next),future_waiting} + */ + } + + @Test + public void whenAddingNewWithTWBetweenTwoActs4_itShouldCalcInsertionCostsCorrectly() { + VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("t").setCostPerWaitingTime(1.).build(); + + VehicleImpl v = VehicleImpl.Builder.newInstance("v").setType(type).setStartLocation(Location.newInstance(0, 0)).build(); +// VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2").setHasVariableDepartureTime(true).setType(type).setStartLocation(Location.newInstance(0,0)).build(); + + Service prevS = Service.Builder.newInstance("prev").setLocation(Location.newInstance(10, 0)).build(); + Service newS = Service.Builder.newInstance("new").setServiceTime(10).setTimeWindow(TimeWindow.newInstance(100, 120)).setLocation(Location.newInstance(20, 0)).build(); + Service nextS = Service.Builder.newInstance("next").setLocation(Location.newInstance(30, 0)).setTimeWindow(TimeWindow.newInstance(40, 500)).build(); + + Service afterNextS = Service.Builder.newInstance("afterNext").setLocation(Location.newInstance(40, 0)).setTimeWindow(TimeWindow.newInstance(80, 500)).build(); + Service afterAfterNextS = Service.Builder.newInstance("afterAfterNext").setLocation(Location.newInstance(50, 0)).setTimeWindow(TimeWindow.newInstance(100, 500)).build(); + + VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addVehicle(v).addJob(prevS).addJob(newS).addJob(nextS) + .addJob(afterNextS).addJob(afterAfterNextS).build(); + + TourActivity prevAct = vrp.getActivities(prevS).get(0); + TourActivity newAct = vrp.getActivities(newS).get(0); + TourActivity nextAct = vrp.getActivities(nextS).get(0); + + VehicleRoute route = VehicleRoute.Builder.newInstance(v).setJobActivityFactory(vrp.getJobActivityFactory()).addService(prevS).addService(nextS).addService(afterNextS).addService(afterAfterNextS).build(); + JobInsertionContext context = new JobInsertionContext(route, newS, v, null, 0.); + + StateManager stateManager = getStateManager(vrp, route); + + LocalActivityInsertionCostsCalculator calc = new LocalActivityInsertionCostsCalculator(CostFactory.createEuclideanCosts(), new WaitingTimeCosts(), stateManager); + calc.setSolutionCompletenessRatio(1.); + double c = calc.getCosts(context, prevAct, nextAct, newAct, 10); + assertEquals(30., c, 0.01); + //ref: 10 + 30 + 10 = 50 + //new: 50 - 50 = 0 + + /* + activity start time delay at next act = start-time-old - start-time-new is always bigger than subsequent waiting time savings + */ + /* + old = 10 + 30 + 10 = 50 + new = 80 + 0 - 10 - min{80,40} = 30 + */ + } + + @Test + public void whenAddingNewWithTWBetweenTwoActs4WithVarStart_itShouldCalcInsertionCostsCorrectly() { + VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("t").setCostPerWaitingTime(1.).build(); + + VehicleImpl v = VehicleImpl.Builder.newInstance("v").setType(type).setStartLocation(Location.newInstance(0, 0)).build(); +// VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2").setHasVariableDepartureTime(true).setType(type).setStartLocation(Location.newInstance(0,0)).build(); + + Service prevS = Service.Builder.newInstance("prev").setLocation(Location.newInstance(10, 0)).build(); + Service newS = Service.Builder.newInstance("new").setServiceTime(10).setTimeWindow(TimeWindow.newInstance(100, 120)).setLocation(Location.newInstance(20, 0)).build(); + Service nextS = Service.Builder.newInstance("next").setLocation(Location.newInstance(30, 0)).setTimeWindow(TimeWindow.newInstance(40, 500)).build(); + + Service afterNextS = Service.Builder.newInstance("afterNext").setLocation(Location.newInstance(40, 0)).setTimeWindow(TimeWindow.newInstance(80, 500)).build(); + Service afterAfterNextS = Service.Builder.newInstance("afterAfterNext").setLocation(Location.newInstance(50, 0)).setTimeWindow(TimeWindow.newInstance(100, 500)).build(); + + VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addVehicle(v).addJob(prevS).addJob(newS).addJob(nextS) + .addJob(afterNextS).addJob(afterAfterNextS).build(); + + TourActivity prevAct = vrp.getActivities(prevS).get(0); + TourActivity newAct = vrp.getActivities(newS).get(0); + TourActivity nextAct = vrp.getActivities(nextS).get(0); + + VehicleRoute route = VehicleRoute.Builder.newInstance(v).setJobActivityFactory(vrp.getJobActivityFactory()).addService(prevS).addService(nextS).addService(afterNextS).addService(afterAfterNextS).build(); + JobInsertionContext context = new JobInsertionContext(route, newS, v, null, 0.); + + StateManager stateManager = getStateManager(vrp, route); + + LocalActivityInsertionCostsCalculator calc = new LocalActivityInsertionCostsCalculator(CostFactory.createEuclideanCosts(), new WaitingTimeCosts(), stateManager); + calc.setSolutionCompletenessRatio(1.); + double c = calc.getCosts(context, prevAct, nextAct, newAct, 10); + assertEquals(30., c, 0.01); + /* + activity start time delay at next act = start-time-old - start-time-new is always bigger than subsequent waiting time savings + */ + /* + old = 10 + 30 + 10 = 50 + new = 80 + new - old = 80 - 40 = 40 + + */ + } + + @Test + public void whenAddingNewWithTWBetweenTwoActs3WithVarStart_itShouldCalcInsertionCostsCorrectly() { + VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("t").setCostPerWaitingTime(1.).build(); + + VehicleImpl v = VehicleImpl.Builder.newInstance("v").setType(type).setStartLocation(Location.newInstance(0, 0)).build(); +// VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2").setHasVariableDepartureTime(true).setType(type).setStartLocation(Location.newInstance(0,0)).build(); + + Service prevS = Service.Builder.newInstance("prev").setLocation(Location.newInstance(10, 0)).build(); + Service newS = Service.Builder.newInstance("new").setServiceTime(10).setTimeWindow(TimeWindow.newInstance(50, 70)).setLocation(Location.newInstance(20, 0)).build(); + Service nextS = Service.Builder.newInstance("next").setLocation(Location.newInstance(30, 0)).setTimeWindow(TimeWindow.newInstance(40, 70)).build(); + + Service afterNextS = Service.Builder.newInstance("afterNext").setLocation(Location.newInstance(40, 0)).setTimeWindow(TimeWindow.newInstance(50, 100)).build(); + Service afterAfterNextS = Service.Builder.newInstance("afterAfterNext").setLocation(Location.newInstance(50, 0)).setTimeWindow(TimeWindow.newInstance(100, 500)).build(); + + VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addVehicle(v).addJob(prevS).addJob(newS).addJob(nextS) + .addJob(afterNextS).addJob(afterAfterNextS).build(); + + TourActivity prevAct = vrp.getActivities(prevS).get(0); + TourActivity newAct = vrp.getActivities(newS).get(0); + TourActivity nextAct = vrp.getActivities(nextS).get(0); + + VehicleRoute route = VehicleRoute.Builder.newInstance(v).setJobActivityFactory(vrp.getJobActivityFactory()).addService(prevS).addService(nextS).addService(afterNextS).addService(afterAfterNextS).build(); + JobInsertionContext context = new JobInsertionContext(route, newS, v, null, 0.); + + StateManager stateManager = getStateManager(vrp, route); + + LocalActivityInsertionCostsCalculator calc = new LocalActivityInsertionCostsCalculator(CostFactory.createEuclideanCosts(), new WaitingTimeCosts(), stateManager); + calc.setSolutionCompletenessRatio(1.); + double c = calc.getCosts(context, prevAct, nextAct, newAct, 10); + assertEquals(-10., c, 0.01); + /* + activity start time delay at next act = start-time-old - start-time-new is always bigger than subsequent waiting time savings + */ + /* + old = 10 + 40 = 50 + new = 30 + 10 = 40 + */ + } + + + private StateManager getStateManager(VehicleRoutingProblem vrp, VehicleRoute route) { + StateManager stateManager = new StateManager(vrp); + stateManager.addStateUpdater(new UpdateActivityTimes(vrp.getTransportCosts())); + stateManager.addStateUpdater(new UpdateVehicleDependentPracticalTimeWindows(stateManager, vrp.getTransportCosts())); + stateManager.addStateUpdater(new UpdateFutureWaitingTimes(stateManager, vrp.getTransportCosts())); + stateManager.informInsertionStarts(Arrays.asList(route), new ArrayList()); + return stateManager; + } } diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/TestMixedServiceAndShipmentsProblemOnRouteLevel.java b/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/TestMixedServiceAndShipmentsProblemOnRouteLevel.java index 1518f0b9..0b4df767 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/TestMixedServiceAndShipmentsProblemOnRouteLevel.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/TestMixedServiceAndShipmentsProblemOnRouteLevel.java @@ -1,18 +1,18 @@ /******************************************************************************* * Copyright (c) 2014 Stefan Schroeder. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . - * + * * Contributors: * Stefan Schroeder - initial API and implementation ******************************************************************************/ @@ -34,127 +34,123 @@ import static org.junit.Assert.assertTrue; public class TestMixedServiceAndShipmentsProblemOnRouteLevel { - - - - - - @Test(expected=UnsupportedOperationException.class) - public void whenHavingShipmentsAndServicesInOneProblem_andInsertionShouldBeMadeOnRouteLevel_throwException(){ - /* get a vehicle type-builder and build a type with the typeId "vehicleType" and a capacity of 2 - */ - VehicleTypeImpl.Builder vehicleTypeBuilder = VehicleTypeImpl.Builder.newInstance("vehicleType").addCapacityDimension(0, 2); - VehicleType vehicleType = vehicleTypeBuilder.build(); - + + @Test(expected = UnsupportedOperationException.class) + public void whenHavingShipmentsAndServicesInOneProblem_andInsertionShouldBeMadeOnRouteLevel_throwException() { + /* get a vehicle type-builder and build a type with the typeId "vehicleType" and a capacity of 2 + */ + VehicleTypeImpl.Builder vehicleTypeBuilder = VehicleTypeImpl.Builder.newInstance("vehicleType").addCapacityDimension(0, 2); + VehicleType vehicleType = vehicleTypeBuilder.build(); + /* - * get a vehicle-builder and build a vehicle located at (10,10) with type "vehicleType" + * get a vehicle-builder and build a vehicle located at (10,10) with type "vehicleType" */ - Builder vehicleBuilder = VehicleImpl.Builder.newInstance("vehicle"); - vehicleBuilder.setStartLocation(Location.newInstance(10, 10)); - vehicleBuilder.setType(vehicleType); - VehicleImpl vehicle = vehicleBuilder.build(); - + Builder vehicleBuilder = VehicleImpl.Builder.newInstance("vehicle"); + vehicleBuilder.setStartLocation(Location.newInstance(10, 10)); + vehicleBuilder.setType(vehicleType); + VehicleImpl vehicle = vehicleBuilder.build(); + /* - * build shipments at the required locations, each with a capacity-demand of 1. + * build shipments at the required locations, each with a capacity-demand of 1. * 4 shipments * 1: (5,7)->(6,9) * 2: (5,13)->(6,11) * 3: (15,7)->(14,9) * 4: (15,13)->(14,11) */ - - Shipment shipment1 = Shipment.Builder.newInstance("1").addSizeDimension(0, 1).setPickupLocation(TestUtils.loc(Coordinate.newInstance(5, 7))).setDeliveryLocation(TestUtils.loc(Coordinate.newInstance(6, 9))).build(); - Shipment shipment2 = Shipment.Builder.newInstance("2").addSizeDimension(0, 1).setPickupLocation(TestUtils.loc(Coordinate.newInstance(5, 13))).setDeliveryLocation(TestUtils.loc(Coordinate.newInstance(6, 11))).build(); - - Shipment shipment3 = Shipment.Builder.newInstance("3").addSizeDimension(0, 1).setPickupLocation(TestUtils.loc(Coordinate.newInstance(15, 7))).setDeliveryLocation(TestUtils.loc(Coordinate.newInstance(14, 9))).build(); - Shipment shipment4 = Shipment.Builder.newInstance("4").addSizeDimension(0, 1).setPickupLocation(TestUtils.loc(Coordinate.newInstance(15, 13))).setDeliveryLocation(TestUtils.loc(Coordinate.newInstance(14, 11))).build(); - + + Shipment shipment1 = Shipment.Builder.newInstance("1").addSizeDimension(0, 1).setPickupLocation(TestUtils.loc(Coordinate.newInstance(5, 7))).setDeliveryLocation(TestUtils.loc(Coordinate.newInstance(6, 9))).build(); + Shipment shipment2 = Shipment.Builder.newInstance("2").addSizeDimension(0, 1).setPickupLocation(TestUtils.loc(Coordinate.newInstance(5, 13))).setDeliveryLocation(TestUtils.loc(Coordinate.newInstance(6, 11))).build(); + + Shipment shipment3 = Shipment.Builder.newInstance("3").addSizeDimension(0, 1).setPickupLocation(TestUtils.loc(Coordinate.newInstance(15, 7))).setDeliveryLocation(TestUtils.loc(Coordinate.newInstance(14, 9))).build(); + Shipment shipment4 = Shipment.Builder.newInstance("4").addSizeDimension(0, 1).setPickupLocation(TestUtils.loc(Coordinate.newInstance(15, 13))).setDeliveryLocation(TestUtils.loc(Coordinate.newInstance(14, 11))).build(); + /* - * build deliveries, (implicitly picked up in the depot) + * build deliveries, (implicitly picked up in the depot) * 1: (4,8) * 2: (4,12) * 3: (16,8) * 4: (16,12) */ - Delivery delivery1 = (Delivery) Delivery.Builder.newInstance("5").addSizeDimension(0, 1).setLocation(TestUtils.loc(Coordinate.newInstance(4, 8))).build(); - Delivery delivery2 = (Delivery) Delivery.Builder.newInstance("6").addSizeDimension(0, 1).setLocation(TestUtils.loc(Coordinate.newInstance(4, 12))).build(); - Delivery delivery3 = (Delivery) Delivery.Builder.newInstance("7").addSizeDimension(0, 1).setLocation(TestUtils.loc(Coordinate.newInstance(16, 8))).build(); - Delivery delivery4 = (Delivery) Delivery.Builder.newInstance("8").addSizeDimension(0, 1).setLocation(TestUtils.loc(Coordinate.newInstance(16, 12))).build(); - - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - vrpBuilder.addVehicle(vehicle); - vrpBuilder.addJob(shipment1).addJob(shipment2).addJob(shipment3).addJob(shipment4) - .addJob(delivery1).addJob(delivery2).addJob(delivery3).addJob(delivery4).build(); - - VehicleRoutingProblem vrp = vrpBuilder.build(); - - final StateManager stateManager = new StateManager(vrp); - + Delivery delivery1 = (Delivery) Delivery.Builder.newInstance("5").addSizeDimension(0, 1).setLocation(TestUtils.loc(Coordinate.newInstance(4, 8))).build(); + Delivery delivery2 = (Delivery) Delivery.Builder.newInstance("6").addSizeDimension(0, 1).setLocation(TestUtils.loc(Coordinate.newInstance(4, 12))).build(); + Delivery delivery3 = (Delivery) Delivery.Builder.newInstance("7").addSizeDimension(0, 1).setLocation(TestUtils.loc(Coordinate.newInstance(16, 8))).build(); + Delivery delivery4 = (Delivery) Delivery.Builder.newInstance("8").addSizeDimension(0, 1).setLocation(TestUtils.loc(Coordinate.newInstance(16, 12))).build(); - ConstraintManager constraintManager = new ConstraintManager(vrp,stateManager); - constraintManager.addLoadConstraint(); - constraintManager.addTimeWindowConstraint(); - - VehicleFleetManager fleetManager = new InfiniteFleetManagerFactory(vrp.getVehicles()).createFleetManager(); + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + vrpBuilder.addVehicle(vehicle); + vrpBuilder.addJob(shipment1).addJob(shipment2).addJob(shipment3).addJob(shipment4) + .addJob(delivery1).addJob(delivery2).addJob(delivery3).addJob(delivery4).build(); - BestInsertionBuilder bestIBuilder = new BestInsertionBuilder(vrp, fleetManager, stateManager,constraintManager); - bestIBuilder.setRouteLevel(2, 2); - @SuppressWarnings("unused") - InsertionStrategy bestInsertion = bestIBuilder.build(); - - } - - @Test - public void whenHavingOnlyServicesInOneProblem_andInsertionShouldBeMadeOnRouteLevel_itShouldAssertTrue(){ - /* get a vehicle type-builder and build a type with the typeId "vehicleType" and a capacity of 2 - */ - VehicleTypeImpl.Builder vehicleTypeBuilder = VehicleTypeImpl.Builder.newInstance("vehicleType").addCapacityDimension(0, 2); - VehicleType vehicleType = vehicleTypeBuilder.build(); - - /* - * get a vehicle-builder and build a vehicle located at (10,10) with type "vehicleType" - */ - Builder vehicleBuilder = VehicleImpl.Builder.newInstance("vehicle"); - vehicleBuilder.setStartLocation(Location.newInstance(10, 10)); - vehicleBuilder.setType(vehicleType); - VehicleImpl vehicle = vehicleBuilder.build(); - + VehicleRoutingProblem vrp = vrpBuilder.build(); + + final StateManager stateManager = new StateManager(vrp); + + + ConstraintManager constraintManager = new ConstraintManager(vrp, stateManager); + constraintManager.addLoadConstraint(); + constraintManager.addTimeWindowConstraint(); + + VehicleFleetManager fleetManager = new InfiniteFleetManagerFactory(vrp.getVehicles()).createFleetManager(); + + BestInsertionBuilder bestIBuilder = new BestInsertionBuilder(vrp, fleetManager, stateManager, constraintManager); + bestIBuilder.setRouteLevel(2, 2); + @SuppressWarnings("unused") + InsertionStrategy bestInsertion = bestIBuilder.build(); + + } + + @Test + public void whenHavingOnlyServicesInOneProblem_andInsertionShouldBeMadeOnRouteLevel_itShouldAssertTrue() { + /* get a vehicle type-builder and build a type with the typeId "vehicleType" and a capacity of 2 + */ + VehicleTypeImpl.Builder vehicleTypeBuilder = VehicleTypeImpl.Builder.newInstance("vehicleType").addCapacityDimension(0, 2); + VehicleType vehicleType = vehicleTypeBuilder.build(); /* - * build deliveries, (implicitly picked up in the depot) + * get a vehicle-builder and build a vehicle located at (10,10) with type "vehicleType" + */ + Builder vehicleBuilder = VehicleImpl.Builder.newInstance("vehicle"); + vehicleBuilder.setStartLocation(Location.newInstance(10, 10)); + vehicleBuilder.setType(vehicleType); + VehicleImpl vehicle = vehicleBuilder.build(); + + + /* + * build deliveries, (implicitly picked up in the depot) * 1: (4,8) * 2: (4,12) * 3: (16,8) * 4: (16,12) */ - Delivery delivery1 = (Delivery) Delivery.Builder.newInstance("5").addSizeDimension(0, 1).setLocation(Location.newInstance(4, 8)).build(); - Delivery delivery2 = (Delivery) Delivery.Builder.newInstance("6").addSizeDimension(0, 1).setLocation(Location.newInstance(4, 12)).build(); - Delivery delivery3 = (Delivery) Delivery.Builder.newInstance("7").addSizeDimension(0, 1).setLocation(Location.newInstance(16, 8)).build(); - Delivery delivery4 = (Delivery) Delivery.Builder.newInstance("8").addSizeDimension(0, 1).setLocation(Location.newInstance(16, 12)).build(); - - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - vrpBuilder.addVehicle(vehicle) + Delivery delivery1 = (Delivery) Delivery.Builder.newInstance("5").addSizeDimension(0, 1).setLocation(Location.newInstance(4, 8)).build(); + Delivery delivery2 = (Delivery) Delivery.Builder.newInstance("6").addSizeDimension(0, 1).setLocation(Location.newInstance(4, 12)).build(); + Delivery delivery3 = (Delivery) Delivery.Builder.newInstance("7").addSizeDimension(0, 1).setLocation(Location.newInstance(16, 8)).build(); + Delivery delivery4 = (Delivery) Delivery.Builder.newInstance("8").addSizeDimension(0, 1).setLocation(Location.newInstance(16, 12)).build(); + + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + vrpBuilder.addVehicle(vehicle) // vrpBuilder.addJob(shipment1).addJob(shipment2).addJob(shipment3).addJob(shipment4) - .addJob(delivery1).addJob(delivery2).addJob(delivery3).addJob(delivery4).build(); - - VehicleRoutingProblem vrp = vrpBuilder.build(); - - final StateManager stateManager = new StateManager(vrp); + .addJob(delivery1).addJob(delivery2).addJob(delivery3).addJob(delivery4).build(); - ConstraintManager constraintManager = new ConstraintManager(vrp,stateManager); - constraintManager.addLoadConstraint(); - constraintManager.addTimeWindowConstraint(); - - VehicleFleetManager fleetManager = new InfiniteFleetManagerFactory(vrp.getVehicles()).createFleetManager(); + VehicleRoutingProblem vrp = vrpBuilder.build(); - BestInsertionBuilder bestIBuilder = new BestInsertionBuilder(vrp, fleetManager, stateManager,constraintManager); - bestIBuilder.setRouteLevel(2, 2); - @SuppressWarnings("unused") - InsertionStrategy bestInsertion = bestIBuilder.build(); - - assertTrue(true); - - } + final StateManager stateManager = new StateManager(vrp); + + ConstraintManager constraintManager = new ConstraintManager(vrp, stateManager); + constraintManager.addLoadConstraint(); + constraintManager.addTimeWindowConstraint(); + + VehicleFleetManager fleetManager = new InfiniteFleetManagerFactory(vrp.getVehicles()).createFleetManager(); + + BestInsertionBuilder bestIBuilder = new BestInsertionBuilder(vrp, fleetManager, stateManager, constraintManager); + bestIBuilder.setRouteLevel(2, 2); + @SuppressWarnings("unused") + InsertionStrategy bestInsertion = bestIBuilder.build(); + + assertTrue(true); + + } } diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/TestRouteLevelActivityInsertionCostEstimator.java b/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/TestRouteLevelActivityInsertionCostEstimator.java index e3179609..5b74368b 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/TestRouteLevelActivityInsertionCostEstimator.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/TestRouteLevelActivityInsertionCostEstimator.java @@ -1,18 +1,18 @@ /******************************************************************************* * Copyright (c) 2014 Stefan Schroeder. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . - * + * * Contributors: * Stefan Schroeder - initial API and implementation ******************************************************************************/ @@ -63,20 +63,20 @@ public class TestRouteLevelActivityInsertionCostEstimator { private StateManager stateManager; @Before - public void doBefore(){ + public void doBefore() { routingCosts = CostFactory.createEuclideanCosts(); activityCosts = new VehicleRoutingActivityCosts() { @Override public double getActivityCost(TourActivity tourAct, double arrivalTime, Driver driver, Vehicle vehicle) { - return Math.max(0.,arrivalTime - tourAct.getTheoreticalLatestOperationStartTime()); + return Math.max(0., arrivalTime - tourAct.getTheoreticalLatestOperationStartTime()); } }; Service s1 = Service.Builder.newInstance("s1").setLocation(Location.newInstance("10,0")).setTimeWindow(TimeWindow.newInstance(10., 10.)).build(); - Service s2 = Service.Builder.newInstance("s2").setLocation(Location.newInstance("20,0")).setTimeWindow(TimeWindow.newInstance(20.,20.)).build(); - Service s3 = Service.Builder.newInstance("s3").setLocation(Location.newInstance("30,0")).setTimeWindow(TimeWindow.newInstance(30.,30.)).build(); + Service s2 = Service.Builder.newInstance("s2").setLocation(Location.newInstance("20,0")).setTimeWindow(TimeWindow.newInstance(20., 20.)).build(); + Service s3 = Service.Builder.newInstance("s3").setLocation(Location.newInstance("30,0")).setTimeWindow(TimeWindow.newInstance(30., 30.)).build(); VehicleType type = VehicleTypeImpl.Builder.newInstance("type").build(); Vehicle vehicle = VehicleImpl.Builder.newInstance("vehicle").setStartLocation(Location.newInstance("0,0")).setType(type).build(); @@ -93,98 +93,98 @@ public class TestRouteLevelActivityInsertionCostEstimator { }).addService(s1).addService(s2).addService(s3).build(); stateManager = new StateManager(vrp); - stateManager.addStateUpdater(new UpdateVariableCosts(activityCosts,routingCosts,stateManager)); + stateManager.addStateUpdater(new UpdateVariableCosts(activityCosts, routingCosts, stateManager)); stateManager.informInsertionStarts(Arrays.asList(route), Collections.emptyList()); } @Test - public void whenNewActInBetweenFirstAndSecond_and_forwardLookingIs0_itShouldReturnCorrectCosts(){ + public void whenNewActInBetweenFirstAndSecond_and_forwardLookingIs0_itShouldReturnCorrectCosts() { Service s4 = Service.Builder.newInstance("s4").setLocation(Location.newInstance("5,0")).build(); PickupActivity pickupService = new PickupService(s4); - JobInsertionContext context = new JobInsertionContext(route,s4,route.getVehicle(),route.getDriver(),0.); - RouteLevelActivityInsertionCostsEstimator estimator = new RouteLevelActivityInsertionCostsEstimator(routingCosts,activityCosts,stateManager); + JobInsertionContext context = new JobInsertionContext(route, s4, route.getVehicle(), route.getDriver(), 0.); + RouteLevelActivityInsertionCostsEstimator estimator = new RouteLevelActivityInsertionCostsEstimator(routingCosts, activityCosts, stateManager); estimator.setForwardLooking(0); double iCosts = estimator.getCosts(context, route.getStart(), route.getActivities().get(0), pickupService, 0.); - assertEquals(0.,iCosts,0.01); + assertEquals(0., iCosts, 0.01); } @Test - public void whenNewActWithTWInBetweenFirstAndSecond_and_forwardLookingIs0_itShouldReturnCorrectCosts(){ - Service s4 = Service.Builder.newInstance("s4").setLocation(Location.newInstance("5,0")).setTimeWindow(TimeWindow.newInstance(5.,5.)).build(); + public void whenNewActWithTWInBetweenFirstAndSecond_and_forwardLookingIs0_itShouldReturnCorrectCosts() { + Service s4 = Service.Builder.newInstance("s4").setLocation(Location.newInstance("5,0")).setTimeWindow(TimeWindow.newInstance(5., 5.)).build(); PickupActivity pickupService = new PickupService(s4); - JobInsertionContext context = new JobInsertionContext(route,s4,route.getVehicle(),route.getDriver(),0.); - RouteLevelActivityInsertionCostsEstimator estimator = new RouteLevelActivityInsertionCostsEstimator(routingCosts,activityCosts,stateManager); + JobInsertionContext context = new JobInsertionContext(route, s4, route.getVehicle(), route.getDriver(), 0.); + RouteLevelActivityInsertionCostsEstimator estimator = new RouteLevelActivityInsertionCostsEstimator(routingCosts, activityCosts, stateManager); estimator.setForwardLooking(0); double iCosts = estimator.getCosts(context, route.getStart(), route.getActivities().get(0), pickupService, 0.); - assertEquals(0.,iCosts,0.01); + assertEquals(0., iCosts, 0.01); } @Test - public void whenNewActWithTWAndServiceTimeInBetweenFirstAndSecond_and_forwardLookingIs0_itShouldReturnCorrectCosts(){ - Service s4 = Service.Builder.newInstance("s4").setLocation(Location.newInstance("5,0")).setServiceTime(10.).setTimeWindow(TimeWindow.newInstance(5.,5.)).build(); + public void whenNewActWithTWAndServiceTimeInBetweenFirstAndSecond_and_forwardLookingIs0_itShouldReturnCorrectCosts() { + Service s4 = Service.Builder.newInstance("s4").setLocation(Location.newInstance("5,0")).setServiceTime(10.).setTimeWindow(TimeWindow.newInstance(5., 5.)).build(); PickupActivity pickupService = new PickupService(s4); - JobInsertionContext context = new JobInsertionContext(route,s4,route.getVehicle(),route.getDriver(),0.); - RouteLevelActivityInsertionCostsEstimator estimator = new RouteLevelActivityInsertionCostsEstimator(routingCosts,activityCosts,stateManager); + JobInsertionContext context = new JobInsertionContext(route, s4, route.getVehicle(), route.getDriver(), 0.); + RouteLevelActivityInsertionCostsEstimator estimator = new RouteLevelActivityInsertionCostsEstimator(routingCosts, activityCosts, stateManager); estimator.setForwardLooking(0); double iCosts = estimator.getCosts(context, route.getStart(), route.getActivities().get(0), pickupService, 0.); double expectedTransportCosts = 0.; double expectedActivityCosts = 10.; - assertEquals(expectedActivityCosts+expectedTransportCosts,iCosts,0.01); + assertEquals(expectedActivityCosts + expectedTransportCosts, iCosts, 0.01); } @Test - public void whenNewActWithTWAndServiceTimeInBetweenFirstAndSecond_and_forwardLookingIs3_itShouldReturnCorrectCosts(){ - Service s4 = Service.Builder.newInstance("s4").setLocation(Location.newInstance("5,0")).setServiceTime(10.).setTimeWindow(TimeWindow.newInstance(5.,5.)).build(); + public void whenNewActWithTWAndServiceTimeInBetweenFirstAndSecond_and_forwardLookingIs3_itShouldReturnCorrectCosts() { + Service s4 = Service.Builder.newInstance("s4").setLocation(Location.newInstance("5,0")).setServiceTime(10.).setTimeWindow(TimeWindow.newInstance(5., 5.)).build(); PickupActivity pickupService = new PickupService(s4); - JobInsertionContext context = new JobInsertionContext(route,s4,route.getVehicle(),route.getDriver(),0.); - RouteLevelActivityInsertionCostsEstimator estimator = new RouteLevelActivityInsertionCostsEstimator(routingCosts,activityCosts,stateManager); + JobInsertionContext context = new JobInsertionContext(route, s4, route.getVehicle(), route.getDriver(), 0.); + RouteLevelActivityInsertionCostsEstimator estimator = new RouteLevelActivityInsertionCostsEstimator(routingCosts, activityCosts, stateManager); estimator.setForwardLooking(3); double iCosts = estimator.getCosts(context, route.getStart(), route.getActivities().get(0), pickupService, 0.); double expectedTransportCosts = 0.; double expectedActivityCosts = 30.; - assertEquals(expectedActivityCosts+expectedTransportCosts,iCosts,0.01); + assertEquals(expectedActivityCosts + expectedTransportCosts, iCosts, 0.01); } @Test - public void whenNewActInBetweenSecondAndThird_and_forwardLookingIs0_itShouldReturnCorrectCosts(){ + public void whenNewActInBetweenSecondAndThird_and_forwardLookingIs0_itShouldReturnCorrectCosts() { Service s4 = Service.Builder.newInstance("s4").setLocation(Location.newInstance("5,0")).build(); PickupActivity pickupService = new PickupService(s4); - JobInsertionContext context = new JobInsertionContext(route,s4,route.getVehicle(),route.getDriver(),0.); - RouteLevelActivityInsertionCostsEstimator estimator = new RouteLevelActivityInsertionCostsEstimator(routingCosts,activityCosts,stateManager); + JobInsertionContext context = new JobInsertionContext(route, s4, route.getVehicle(), route.getDriver(), 0.); + RouteLevelActivityInsertionCostsEstimator estimator = new RouteLevelActivityInsertionCostsEstimator(routingCosts, activityCosts, stateManager); estimator.setForwardLooking(0); double iCosts = - estimator.getCosts(context, route.getActivities().get(0), route.getActivities().get(1), pickupService, 10.); + estimator.getCosts(context, route.getActivities().get(0), route.getActivities().get(1), pickupService, 10.); double expectedTransportCosts = 10.; double expectedActivityCosts = 10.; - assertEquals(expectedTransportCosts+expectedActivityCosts,iCosts,0.01); + assertEquals(expectedTransportCosts + expectedActivityCosts, iCosts, 0.01); } @Test - public void whenNewActInBetweenSecondAndThird_and_forwardLookingIs3_itShouldReturnCorrectCosts(){ + public void whenNewActInBetweenSecondAndThird_and_forwardLookingIs3_itShouldReturnCorrectCosts() { Service s4 = Service.Builder.newInstance("s4").setLocation(Location.newInstance("5,0")).build(); PickupActivity pickupService = new PickupService(s4); - JobInsertionContext context = new JobInsertionContext(route,s4,route.getVehicle(),route.getDriver(),0.); - RouteLevelActivityInsertionCostsEstimator estimator = new RouteLevelActivityInsertionCostsEstimator(routingCosts,activityCosts,stateManager); + JobInsertionContext context = new JobInsertionContext(route, s4, route.getVehicle(), route.getDriver(), 0.); + RouteLevelActivityInsertionCostsEstimator estimator = new RouteLevelActivityInsertionCostsEstimator(routingCosts, activityCosts, stateManager); estimator.setForwardLooking(3); double iCosts = - estimator.getCosts(context, route.getActivities().get(0), route.getActivities().get(1), pickupService, 10.); + estimator.getCosts(context, route.getActivities().get(0), route.getActivities().get(1), pickupService, 10.); double expectedTransportCosts = 10.; - double expectedActivityCosts = 10.+10.; - assertEquals(expectedTransportCosts+expectedActivityCosts,iCosts,0.01); + double expectedActivityCosts = 10. + 10.; + assertEquals(expectedTransportCosts + expectedActivityCosts, iCosts, 0.01); } @Test - public void whenNewActWithTWInBetweenSecondAndThird_and_forwardLookingIs3_itShouldReturnCorrectCosts(){ - Service s4 = Service.Builder.newInstance("s4").setLocation(Location.newInstance("5,0")).setTimeWindow(TimeWindow.newInstance(5.,5.)).build(); + public void whenNewActWithTWInBetweenSecondAndThird_and_forwardLookingIs3_itShouldReturnCorrectCosts() { + Service s4 = Service.Builder.newInstance("s4").setLocation(Location.newInstance("5,0")).setTimeWindow(TimeWindow.newInstance(5., 5.)).build(); PickupActivity pickupService = new PickupService(s4); - JobInsertionContext context = new JobInsertionContext(route,s4,route.getVehicle(),route.getDriver(),0.); - RouteLevelActivityInsertionCostsEstimator estimator = new RouteLevelActivityInsertionCostsEstimator(routingCosts,activityCosts,stateManager); + JobInsertionContext context = new JobInsertionContext(route, s4, route.getVehicle(), route.getDriver(), 0.); + RouteLevelActivityInsertionCostsEstimator estimator = new RouteLevelActivityInsertionCostsEstimator(routingCosts, activityCosts, stateManager); estimator.setForwardLooking(3); double iCosts = - estimator.getCosts(context, route.getActivities().get(0), route.getActivities().get(1), pickupService, 10.); + estimator.getCosts(context, route.getActivities().get(0), route.getActivities().get(1), pickupService, 10.); double expectedTransportCosts = 10.; - double expectedActivityCosts = 10.+10.+10.; - assertEquals(expectedTransportCosts+expectedActivityCosts,iCosts,0.01); + double expectedActivityCosts = 10. + 10. + 10.; + assertEquals(expectedTransportCosts + expectedActivityCosts, iCosts, 0.01); } } diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/TestRouteLevelServiceInsertionCostEstimator.java b/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/TestRouteLevelServiceInsertionCostEstimator.java index 98a19353..01ca4a44 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/TestRouteLevelServiceInsertionCostEstimator.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/TestRouteLevelServiceInsertionCostEstimator.java @@ -1,18 +1,18 @@ /******************************************************************************* * Copyright (c) 2014 Stefan Schroeder. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . - * + * * Contributors: * Stefan Schroeder - initial API and implementation ******************************************************************************/ @@ -48,6 +48,7 @@ import java.util.List; import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; /** * Created by schroeder on 02.07.14. @@ -69,7 +70,7 @@ public class TestRouteLevelServiceInsertionCostEstimator { private JobActivityFactory activityFactory; @Before - public void doBefore(){ + public void doBefore() { VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); routingCosts = CostFactory.createEuclideanCosts(); @@ -79,15 +80,15 @@ public class TestRouteLevelServiceInsertionCostEstimator { @Override public double getActivityCost(TourActivity tourAct, double arrivalTime, Driver driver, Vehicle vehicle) { - return Math.max(0.,arrivalTime - tourAct.getTheoreticalLatestOperationStartTime()); + return Math.max(0., arrivalTime - tourAct.getTheoreticalLatestOperationStartTime()); } }; vrpBuilder.setActivityCosts(activityCosts); Service s1 = Service.Builder.newInstance("s1").setLocation(Location.newInstance("10,0")).setTimeWindow(TimeWindow.newInstance(10., 10.)).build(); - Service s2 = Service.Builder.newInstance("s2").setLocation(Location.newInstance("20,0")).setTimeWindow(TimeWindow.newInstance(20.,20.)).build(); - Service s3 = Service.Builder.newInstance("s3").setLocation(Location.newInstance("30,0")).setTimeWindow(TimeWindow.newInstance(30.,30.)).build(); + Service s2 = Service.Builder.newInstance("s2").setLocation(Location.newInstance("20,0")).setTimeWindow(TimeWindow.newInstance(20., 20.)).build(); + Service s3 = Service.Builder.newInstance("s3").setLocation(Location.newInstance("30,0")).setTimeWindow(TimeWindow.newInstance(30., 30.)).build(); vrpBuilder.addJob(s1).addJob(s2).addJob(s3); VehicleType type = VehicleTypeImpl.Builder.newInstance("type").build(); @@ -103,128 +104,130 @@ public class TestRouteLevelServiceInsertionCostEstimator { }; route = VehicleRoute.Builder.newInstance(vehicle).setJobActivityFactory(activityFactory).addService(s1).addService(s2).addService(s3).build(); - stateManager = new StateManager(mock(VehicleRoutingProblem.class)); - stateManager.addStateUpdater(new UpdateVariableCosts(activityCosts,routingCosts,stateManager)); + VehicleRoutingProblem vrpMock = mock(VehicleRoutingProblem.class); + when(vrpMock.getFleetSize()).thenReturn(VehicleRoutingProblem.FleetSize.INFINITE); + stateManager = new StateManager(vrpMock); + stateManager.addStateUpdater(new UpdateVariableCosts(activityCosts, routingCosts, stateManager)); stateManager.informInsertionStarts(Arrays.asList(route), Collections.emptyList()); - constraintManager = new ConstraintManager(vrp,stateManager); + constraintManager = new ConstraintManager(vrp, stateManager); } @Test - public void whenNewServiceNeedToBeInserted_itShouldReturnCorrectInsertionCosts(){ - final Service s4 = Service.Builder.newInstance("s4").setLocation(Location.newInstance("5,0")).setTimeWindow(TimeWindow.newInstance(5.,5.)).build(); - RouteLevelActivityInsertionCostsEstimator estimator = new RouteLevelActivityInsertionCostsEstimator(routingCosts,activityCosts,stateManager); + public void whenNewServiceNeedToBeInserted_itShouldReturnCorrectInsertionCosts() { + final Service s4 = Service.Builder.newInstance("s4").setLocation(Location.newInstance("5,0")).setTimeWindow(TimeWindow.newInstance(5., 5.)).build(); + RouteLevelActivityInsertionCostsEstimator estimator = new RouteLevelActivityInsertionCostsEstimator(routingCosts, activityCosts, stateManager); estimator.setForwardLooking(0); ServiceInsertionOnRouteLevelCalculator routeInserter = new ServiceInsertionOnRouteLevelCalculator(routingCosts, - activityCosts,estimator,constraintManager,constraintManager); + activityCosts, estimator, constraintManager, constraintManager); routeInserter.setStates(stateManager); routeInserter.setJobActivityFactory(new JobActivityFactory() { @Override public List createActivities(Job job) { List acts = activityFactory.createActivities(job); - if(acts.isEmpty()){ + if (acts.isEmpty()) { acts.add(new PickupService(s4)); } return acts; } }); - InsertionData iData = routeInserter.getInsertionData(route,s4,route.getVehicle(),route.getDepartureTime(),route.getDriver(),Double.MAX_VALUE); - assertEquals(0.,iData.getInsertionCost(),0.01); + InsertionData iData = routeInserter.getInsertionData(route, s4, route.getVehicle(), route.getDepartureTime(), route.getDriver(), Double.MAX_VALUE); + assertEquals(0., iData.getInsertionCost(), 0.01); } @Test - public void whenNewServiceNeedToBeInserted_itShouldReturnCorrectInsertionIndex(){ - final Service s4 = Service.Builder.newInstance("s4").setLocation(Location.newInstance("5,0")).setTimeWindow(TimeWindow.newInstance(5.,5.)).build(); - RouteLevelActivityInsertionCostsEstimator estimator = new RouteLevelActivityInsertionCostsEstimator(routingCosts,activityCosts,stateManager); + public void whenNewServiceNeedToBeInserted_itShouldReturnCorrectInsertionIndex() { + final Service s4 = Service.Builder.newInstance("s4").setLocation(Location.newInstance("5,0")).setTimeWindow(TimeWindow.newInstance(5., 5.)).build(); + RouteLevelActivityInsertionCostsEstimator estimator = new RouteLevelActivityInsertionCostsEstimator(routingCosts, activityCosts, stateManager); estimator.setForwardLooking(0); final ServiceInsertionOnRouteLevelCalculator routeInserter = new ServiceInsertionOnRouteLevelCalculator(routingCosts, - activityCosts,estimator,constraintManager,constraintManager); + activityCosts, estimator, constraintManager, constraintManager); routeInserter.setStates(stateManager); routeInserter.setJobActivityFactory(new JobActivityFactory() { @Override public List createActivities(Job job) { List acts = activityFactory.createActivities(job); - if(acts.isEmpty()){ + if (acts.isEmpty()) { acts.add(new PickupService(s4)); } return acts; } }); - InsertionData iData = routeInserter.getInsertionData(route,s4,route.getVehicle(),route.getDepartureTime(),route.getDriver(),Double.MAX_VALUE); - assertEquals(0,iData.getDeliveryInsertionIndex(),0.01); + InsertionData iData = routeInserter.getInsertionData(route, s4, route.getVehicle(), route.getDepartureTime(), route.getDriver(), Double.MAX_VALUE); + assertEquals(0, iData.getDeliveryInsertionIndex(), 0.01); } @Test - public void whenNewServiceWithServiceTimeNeedToBeInserted_itShouldReturnCorrectInsertionData(){ - final Service s4 = Service.Builder.newInstance("s4").setServiceTime(10.).setLocation(Location.newInstance("5,0")).setTimeWindow(TimeWindow.newInstance(5.,5.)).build(); - RouteLevelActivityInsertionCostsEstimator estimator = new RouteLevelActivityInsertionCostsEstimator(routingCosts,activityCosts,stateManager); + public void whenNewServiceWithServiceTimeNeedToBeInserted_itShouldReturnCorrectInsertionData() { + final Service s4 = Service.Builder.newInstance("s4").setServiceTime(10.).setLocation(Location.newInstance("5,0")).setTimeWindow(TimeWindow.newInstance(5., 5.)).build(); + RouteLevelActivityInsertionCostsEstimator estimator = new RouteLevelActivityInsertionCostsEstimator(routingCosts, activityCosts, stateManager); estimator.setForwardLooking(0); ServiceInsertionOnRouteLevelCalculator routeInserter = new ServiceInsertionOnRouteLevelCalculator(routingCosts, - activityCosts,estimator,constraintManager,constraintManager); + activityCosts, estimator, constraintManager, constraintManager); routeInserter.setStates(stateManager); routeInserter.setJobActivityFactory(new JobActivityFactory() { @Override public List createActivities(Job job) { List acts = activityFactory.createActivities(job); - if(acts.isEmpty()){ + if (acts.isEmpty()) { acts.add(new PickupService(s4)); } return acts; } }); - InsertionData iData = routeInserter.getInsertionData(route,s4,route.getVehicle(),route.getDepartureTime(),route.getDriver(),Double.MAX_VALUE); - assertEquals(0,iData.getDeliveryInsertionIndex(),0.01); - assertEquals(30.,iData.getInsertionCost(),0.01); + InsertionData iData = routeInserter.getInsertionData(route, s4, route.getVehicle(), route.getDepartureTime(), route.getDriver(), Double.MAX_VALUE); + assertEquals(0, iData.getDeliveryInsertionIndex(), 0.01); + assertEquals(30., iData.getInsertionCost(), 0.01); } @Test - public void whenNewServiceWithServiceTimeNeedToBeInsertedAndRouteIsEmpty_itShouldReturnCorrectInsertionData(){ - final Service s4 = Service.Builder.newInstance("s4").setServiceTime(10.).setLocation(Location.newInstance("5,0")).setTimeWindow(TimeWindow.newInstance(5.,5.)).build(); + public void whenNewServiceWithServiceTimeNeedToBeInsertedAndRouteIsEmpty_itShouldReturnCorrectInsertionData() { + final Service s4 = Service.Builder.newInstance("s4").setServiceTime(10.).setLocation(Location.newInstance("5,0")).setTimeWindow(TimeWindow.newInstance(5., 5.)).build(); // PickupActivity pickupService = new PickupService(s4); VehicleRoute emptyroute = VehicleRoute.emptyRoute(); - RouteLevelActivityInsertionCostsEstimator estimator = new RouteLevelActivityInsertionCostsEstimator(routingCosts,activityCosts,stateManager); + RouteLevelActivityInsertionCostsEstimator estimator = new RouteLevelActivityInsertionCostsEstimator(routingCosts, activityCosts, stateManager); estimator.setForwardLooking(0); ServiceInsertionOnRouteLevelCalculator routeInserter = new ServiceInsertionOnRouteLevelCalculator(routingCosts, - activityCosts,estimator,constraintManager,constraintManager); + activityCosts, estimator, constraintManager, constraintManager); routeInserter.setStates(stateManager); routeInserter.setJobActivityFactory(new JobActivityFactory() { @Override public List createActivities(Job job) { List acts = activityFactory.createActivities(job); - if(acts.isEmpty()){ + if (acts.isEmpty()) { acts.add(new PickupService(s4)); } return acts; } }); - InsertionData iData = routeInserter.getInsertionData(emptyroute,s4,route.getVehicle(),route.getDepartureTime(),route.getDriver(),Double.MAX_VALUE); - assertEquals(0,iData.getDeliveryInsertionIndex(),0.01); - assertEquals(10.,iData.getInsertionCost(),0.01); + InsertionData iData = routeInserter.getInsertionData(emptyroute, s4, route.getVehicle(), route.getDepartureTime(), route.getDriver(), Double.MAX_VALUE); + assertEquals(0, iData.getDeliveryInsertionIndex(), 0.01); + assertEquals(10., iData.getInsertionCost(), 0.01); } @Test - public void whenNewServiceWithServiceTimeAndTWNeedToBeInsertedAndRouteIsEmpty_itShouldReturnCorrectInsertionData(){ - final Service s4 = Service.Builder.newInstance("s4").setServiceTime(10.).setLocation(Location.newInstance("5,0")).setTimeWindow(TimeWindow.newInstance(3.,3.)).build(); + public void whenNewServiceWithServiceTimeAndTWNeedToBeInsertedAndRouteIsEmpty_itShouldReturnCorrectInsertionData() { + final Service s4 = Service.Builder.newInstance("s4").setServiceTime(10.).setLocation(Location.newInstance("5,0")).setTimeWindow(TimeWindow.newInstance(3., 3.)).build(); // PickupActivity pickupService = new PickupService(s4); VehicleRoute emptyroute = VehicleRoute.emptyRoute(); - RouteLevelActivityInsertionCostsEstimator estimator = new RouteLevelActivityInsertionCostsEstimator(routingCosts,activityCosts,stateManager); + RouteLevelActivityInsertionCostsEstimator estimator = new RouteLevelActivityInsertionCostsEstimator(routingCosts, activityCosts, stateManager); estimator.setForwardLooking(0); ServiceInsertionOnRouteLevelCalculator routeInserter = new ServiceInsertionOnRouteLevelCalculator(routingCosts, - activityCosts,estimator,constraintManager,constraintManager); + activityCosts, estimator, constraintManager, constraintManager); routeInserter.setStates(stateManager); routeInserter.setJobActivityFactory(new JobActivityFactory() { @Override public List createActivities(Job job) { List acts = activityFactory.createActivities(job); - if(acts.isEmpty()){ + if (acts.isEmpty()) { acts.add(new PickupService(s4)); } return acts; } }); - InsertionData iData = routeInserter.getInsertionData(emptyroute,s4,route.getVehicle(),route.getDepartureTime(),route.getDriver(),Double.MAX_VALUE); - assertEquals(0,iData.getDeliveryInsertionIndex(),0.01); - assertEquals(10.+2.,iData.getInsertionCost(),0.01); + InsertionData iData = routeInserter.getInsertionData(emptyroute, s4, route.getVehicle(), route.getDepartureTime(), route.getDriver(), Double.MAX_VALUE); + assertEquals(0, iData.getDeliveryInsertionIndex(), 0.01); + assertEquals(10. + 2., iData.getInsertionCost(), 0.01); } } diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/ruin/DBSCANClustererTest.java b/jsprit-core/src/test/java/jsprit/core/algorithm/ruin/DBSCANClustererTest.java index 13c74e40..6d6624fa 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/ruin/DBSCANClustererTest.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/ruin/DBSCANClustererTest.java @@ -12,64 +12,64 @@ import org.junit.Test; import java.util.List; /** -* Created by schroeder on 06/03/15. -*/ + * Created by schroeder on 06/03/15. + */ public class DBSCANClustererTest { @Test - public void itShouldReturnOneClusterOfSizeTwo(){ - Service s1 = Service.Builder.newInstance("s1").setLocation(Location.newInstance(1,1)).build(); - Service s2 = Service.Builder.newInstance("s2").setLocation(Location.newInstance(10,10)).build(); - Service s3 = Service.Builder.newInstance("s3").setLocation(Location.newInstance(9,9)).build(); + public void itShouldReturnOneClusterOfSizeTwo() { + Service s1 = Service.Builder.newInstance("s1").setLocation(Location.newInstance(1, 1)).build(); + Service s2 = Service.Builder.newInstance("s2").setLocation(Location.newInstance(10, 10)).build(); + Service s3 = Service.Builder.newInstance("s3").setLocation(Location.newInstance(9, 9)).build(); - VehicleImpl v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0,0)).build(); + VehicleImpl v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0, 0)).build(); VehicleRoute r = VehicleRoute.Builder.newInstance(v).addService(s1).addService(s2).addService(s3).build(); DBSCANClusterer c = new DBSCANClusterer(new EuclideanCosts()); c.setEpsDistance(3); List cluster = c.getRandomCluster(r); - Assert.assertEquals(2,cluster.size()); + Assert.assertEquals(2, cluster.size()); } @Test - public void itShouldReturnOneCluster(){ - Service s1 = Service.Builder.newInstance("s1").setLocation(Location.newInstance(1,1)).build(); - Service s2 = Service.Builder.newInstance("s2").setLocation(Location.newInstance(10,10)).build(); - Service s3 = Service.Builder.newInstance("s3").setLocation(Location.newInstance(9,9)).build(); + public void itShouldReturnOneCluster() { + Service s1 = Service.Builder.newInstance("s1").setLocation(Location.newInstance(1, 1)).build(); + Service s2 = Service.Builder.newInstance("s2").setLocation(Location.newInstance(10, 10)).build(); + Service s3 = Service.Builder.newInstance("s3").setLocation(Location.newInstance(9, 9)).build(); - VehicleImpl v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0,0)).build(); + VehicleImpl v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0, 0)).build(); VehicleRoute r = VehicleRoute.Builder.newInstance(v).addService(s1).addService(s2).addService(s3).build(); DBSCANClusterer c = new DBSCANClusterer(new EuclideanCosts()); c.setEpsDistance(3); List> cluster = c.getClusters(r); - Assert.assertEquals(1,cluster.size()); + Assert.assertEquals(1, cluster.size()); } @Test - public void itShouldReturnTwoClusters(){ - Service s0 = Service.Builder.newInstance("s0").setLocation(Location.newInstance(9,0)).build(); - Service s1 = Service.Builder.newInstance("s1").setLocation(Location.newInstance(9,1)).build(); - Service s2 = Service.Builder.newInstance("s2").setLocation(Location.newInstance(9,10)).build(); - Service s3 = Service.Builder.newInstance("s3").setLocation(Location.newInstance(9,9)).build(); - Service s4 = Service.Builder.newInstance("s4").setLocation(Location.newInstance(9,16)).build(); - Service s5 = Service.Builder.newInstance("s5").setLocation(Location.newInstance(9,17)).build(); + public void itShouldReturnTwoClusters() { + Service s0 = Service.Builder.newInstance("s0").setLocation(Location.newInstance(9, 0)).build(); + Service s1 = Service.Builder.newInstance("s1").setLocation(Location.newInstance(9, 1)).build(); + Service s2 = Service.Builder.newInstance("s2").setLocation(Location.newInstance(9, 10)).build(); + Service s3 = Service.Builder.newInstance("s3").setLocation(Location.newInstance(9, 9)).build(); + Service s4 = Service.Builder.newInstance("s4").setLocation(Location.newInstance(9, 16)).build(); + Service s5 = Service.Builder.newInstance("s5").setLocation(Location.newInstance(9, 17)).build(); - VehicleImpl v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0,0)).build(); + VehicleImpl v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0, 0)).build(); VehicleRoute r = VehicleRoute.Builder.newInstance(v).addService(s1).addService(s2).addService(s3) - .addService(s0).addService(s4).addService(s5).build(); + .addService(s0).addService(s4).addService(s5).build(); DBSCANClusterer c = new DBSCANClusterer(new EuclideanCosts()); c.setMinPts(1); c.setEpsDistance(2); List> cluster = c.getClusters(r); - for(List l : cluster) { + for (List l : cluster) { System.out.println("--"); for (Job j : l) System.out.println(j); } - Assert.assertEquals(3,cluster.size()); + Assert.assertEquals(3, cluster.size()); } } diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/ruin/JobNeighborhoodsImplTest.java b/jsprit-core/src/test/java/jsprit/core/algorithm/ruin/JobNeighborhoodsImplTest.java index 967a50d6..95ff1b38 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/ruin/JobNeighborhoodsImplTest.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/ruin/JobNeighborhoodsImplTest.java @@ -1,18 +1,18 @@ /******************************************************************************* * Copyright (c) 2014 Stefan Schroeder. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . - * + * * Contributors: * Stefan Schroeder - initial API and implementation ******************************************************************************/ @@ -37,93 +37,93 @@ import static org.junit.Assert.assertTrue; public class JobNeighborhoodsImplTest { - VehicleRoutingProblem vrp; - - JobDistance jobDistance; - - Service target; - Service s2; - Service s3; - Service s4; - Service s5; - Service s6; - Service s7; - - @Before - public void doBefore(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - target = Service.Builder.newInstance("s1").addSizeDimension(0, 1).setLocation(Location.newInstance(0, 5)).build(); - s2 = Service.Builder.newInstance("s2").addSizeDimension(0, 1).setLocation(Location.newInstance(0, 4)).build(); - s3 = Service.Builder.newInstance("s3").addSizeDimension(0, 1).setLocation(Location.newInstance(0, 3)).build(); - s4 = Service.Builder.newInstance("s4").addSizeDimension(0, 1).setLocation(Location.newInstance(0, 2)).build(); - - s5 = Service.Builder.newInstance("s5").addSizeDimension(0, 1).setLocation(Location.newInstance(0, 6)).build(); - s6 = Service.Builder.newInstance("s6").addSizeDimension(0, 1).setLocation(Location.newInstance(0, 7)).build(); - s7 = Service.Builder.newInstance("s7").addSizeDimension(0, 1).setLocation(Location.newInstance(0, 8)).build(); - - vrp = builder.addJob(target).addJob(s2).addJob(s3).addJob(s4).addJob(s5).addJob(s6).addJob(s7).build(); - - jobDistance = new EuclideanServiceDistance(); - } - - @Test - public void whenRequestingNeighborhoodOfTargetJob_nNeighborsShouldBeTwo(){ - JobNeighborhoodsImpl jn = new JobNeighborhoodsImpl(vrp, jobDistance); - jn.initialise(); - Iterator iter = jn.getNearestNeighborsIterator(2, target); - List services = new ArrayList(); - while(iter.hasNext()){ - services.add((Service) iter.next()); - } - assertEquals(2,services.size()); - } - - @Test - public void whenRequestingNeighborhoodOfTargetJob_s2ShouldBeNeighbor(){ - JobNeighborhoodsImpl jn = new JobNeighborhoodsImpl(vrp, jobDistance); - jn.initialise(); - Iterator iter = jn.getNearestNeighborsIterator(2, target); - List services = new ArrayList(); - while(iter.hasNext()){ - services.add((Service) iter.next()); - } - assertTrue(services.contains(s2)); - } - - @Test - public void whenRequestingNeighborhoodOfTargetJob_s4ShouldBeNeighbor(){ - JobNeighborhoodsImpl jn = new JobNeighborhoodsImpl(vrp, jobDistance); - jn.initialise(); - Iterator iter = jn.getNearestNeighborsIterator(2, target); - List services = new ArrayList(); - while(iter.hasNext()){ - services.add((Service) iter.next()); - } - assertTrue(services.contains(s5)); - } - - @Test - public void whenRequestingNeighborhoodOfTargetJob_sizeShouldBe4(){ - JobNeighborhoodsImpl jn = new JobNeighborhoodsImpl(vrp, jobDistance); - jn.initialise(); - Iterator iter = jn.getNearestNeighborsIterator(4, target); - List services = new ArrayList(); - while(iter.hasNext()){ - services.add((Service) iter.next()); - } - assertEquals(4,services.size()); - } - - @Test - public void whenRequestingMoreNeighborsThanExisting_itShouldReturnMaxNeighbors(){ - JobNeighborhoodsImpl jn = new JobNeighborhoodsImpl(vrp, jobDistance); - jn.initialise(); - Iterator iter = jn.getNearestNeighborsIterator(100, target); - List services = new ArrayList(); - while(iter.hasNext()){ - services.add((Service) iter.next()); - } - assertEquals(6,services.size()); - } + VehicleRoutingProblem vrp; + + JobDistance jobDistance; + + Service target; + Service s2; + Service s3; + Service s4; + Service s5; + Service s6; + Service s7; + + @Before + public void doBefore() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + target = Service.Builder.newInstance("s1").addSizeDimension(0, 1).setLocation(Location.newInstance(0, 5)).build(); + s2 = Service.Builder.newInstance("s2").addSizeDimension(0, 1).setLocation(Location.newInstance(0, 4)).build(); + s3 = Service.Builder.newInstance("s3").addSizeDimension(0, 1).setLocation(Location.newInstance(0, 3)).build(); + s4 = Service.Builder.newInstance("s4").addSizeDimension(0, 1).setLocation(Location.newInstance(0, 2)).build(); + + s5 = Service.Builder.newInstance("s5").addSizeDimension(0, 1).setLocation(Location.newInstance(0, 6)).build(); + s6 = Service.Builder.newInstance("s6").addSizeDimension(0, 1).setLocation(Location.newInstance(0, 7)).build(); + s7 = Service.Builder.newInstance("s7").addSizeDimension(0, 1).setLocation(Location.newInstance(0, 8)).build(); + + vrp = builder.addJob(target).addJob(s2).addJob(s3).addJob(s4).addJob(s5).addJob(s6).addJob(s7).build(); + + jobDistance = new EuclideanServiceDistance(); + } + + @Test + public void whenRequestingNeighborhoodOfTargetJob_nNeighborsShouldBeTwo() { + JobNeighborhoodsImpl jn = new JobNeighborhoodsImpl(vrp, jobDistance); + jn.initialise(); + Iterator iter = jn.getNearestNeighborsIterator(2, target); + List services = new ArrayList(); + while (iter.hasNext()) { + services.add((Service) iter.next()); + } + assertEquals(2, services.size()); + } + + @Test + public void whenRequestingNeighborhoodOfTargetJob_s2ShouldBeNeighbor() { + JobNeighborhoodsImpl jn = new JobNeighborhoodsImpl(vrp, jobDistance); + jn.initialise(); + Iterator iter = jn.getNearestNeighborsIterator(2, target); + List services = new ArrayList(); + while (iter.hasNext()) { + services.add((Service) iter.next()); + } + assertTrue(services.contains(s2)); + } + + @Test + public void whenRequestingNeighborhoodOfTargetJob_s4ShouldBeNeighbor() { + JobNeighborhoodsImpl jn = new JobNeighborhoodsImpl(vrp, jobDistance); + jn.initialise(); + Iterator iter = jn.getNearestNeighborsIterator(2, target); + List services = new ArrayList(); + while (iter.hasNext()) { + services.add((Service) iter.next()); + } + assertTrue(services.contains(s5)); + } + + @Test + public void whenRequestingNeighborhoodOfTargetJob_sizeShouldBe4() { + JobNeighborhoodsImpl jn = new JobNeighborhoodsImpl(vrp, jobDistance); + jn.initialise(); + Iterator iter = jn.getNearestNeighborsIterator(4, target); + List services = new ArrayList(); + while (iter.hasNext()) { + services.add((Service) iter.next()); + } + assertEquals(4, services.size()); + } + + @Test + public void whenRequestingMoreNeighborsThanExisting_itShouldReturnMaxNeighbors() { + JobNeighborhoodsImpl jn = new JobNeighborhoodsImpl(vrp, jobDistance); + jn.initialise(); + Iterator iter = jn.getNearestNeighborsIterator(100, target); + List services = new ArrayList(); + while (iter.hasNext()) { + services.add((Service) iter.next()); + } + assertEquals(6, services.size()); + } } diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/ruin/JobNeighborhoodsWithCapRestrictionImplTest.java b/jsprit-core/src/test/java/jsprit/core/algorithm/ruin/JobNeighborhoodsWithCapRestrictionImplTest.java index 107aa807..fc1c2f02 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/ruin/JobNeighborhoodsWithCapRestrictionImplTest.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/ruin/JobNeighborhoodsWithCapRestrictionImplTest.java @@ -1,18 +1,18 @@ /******************************************************************************* * Copyright (c) 2014 Stefan Schroeder. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . - * + * * Contributors: * Stefan Schroeder - initial API and implementation ******************************************************************************/ @@ -37,93 +37,93 @@ import static org.junit.Assert.assertTrue; public class JobNeighborhoodsWithCapRestrictionImplTest { - VehicleRoutingProblem vrp; - - JobDistance jobDistance; - - Service target; - Service s2; - Service s3; - Service s4; - Service s5; - Service s6; - Service s7; - - @Before - public void doBefore(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - target = Service.Builder.newInstance("s1").addSizeDimension(0, 1).setLocation(Location.newInstance(0, 5)).build(); - s2 = Service.Builder.newInstance("s2").addSizeDimension(0, 1).setLocation(Location.newInstance(0, 4)).build(); - s3 = Service.Builder.newInstance("s3").addSizeDimension(0, 1).setLocation(Location.newInstance(0, 3)).build(); - s4 = Service.Builder.newInstance("s4").addSizeDimension(0, 1).setLocation(Location.newInstance(0, 2)).build(); - - s5 = Service.Builder.newInstance("s5").addSizeDimension(0, 1).setLocation(Location.newInstance(0, 6)).build(); - s6 = Service.Builder.newInstance("s6").addSizeDimension(0, 1).setLocation(Location.newInstance(0, 7)).build(); - s7 = Service.Builder.newInstance("s7").addSizeDimension(0, 1).setLocation(Location.newInstance(0, 8)).build(); - - vrp = builder.addJob(target).addJob(s2).addJob(s3).addJob(s4).addJob(s5).addJob(s6).addJob(s7).build(); - - jobDistance = new EuclideanServiceDistance(); - } - - @Test - public void whenRequestingNeighborhoodOfTargetJob_nNeighborsShouldBeTwo(){ - JobNeighborhoodsImplWithCapRestriction jn = new JobNeighborhoodsImplWithCapRestriction(vrp, jobDistance, 2); - jn.initialise(); - Iterator iter = jn.getNearestNeighborsIterator(2, target); - List services = new ArrayList(); - while(iter.hasNext()){ - services.add((Service) iter.next()); - } - assertEquals(2,services.size()); - } - - @Test - public void whenRequestingNeighborhoodOfTargetJob_s2ShouldBeNeighbor(){ - JobNeighborhoodsImplWithCapRestriction jn = new JobNeighborhoodsImplWithCapRestriction(vrp, jobDistance, 2); - jn.initialise(); - Iterator iter = jn.getNearestNeighborsIterator(2, target); - List services = new ArrayList(); - while(iter.hasNext()){ - services.add((Service) iter.next()); - } - assertTrue(services.contains(s2)); - } - - @Test - public void whenRequestingNeighborhoodOfTargetJob_s4ShouldBeNeighbor(){ - JobNeighborhoodsImplWithCapRestriction jn = new JobNeighborhoodsImplWithCapRestriction(vrp, jobDistance, 2); - jn.initialise(); - Iterator iter = jn.getNearestNeighborsIterator(2, target); - List services = new ArrayList(); - while(iter.hasNext()){ - services.add((Service) iter.next()); - } - assertTrue(services.contains(s5)); - } - - @Test - public void whenRequestingNeighborhoodOfTargetJob_sizeShouldBe4(){ - JobNeighborhoodsImplWithCapRestriction jn = new JobNeighborhoodsImplWithCapRestriction(vrp, jobDistance, 4); - jn.initialise(); - Iterator iter = jn.getNearestNeighborsIterator(4, target); - List services = new ArrayList(); - while(iter.hasNext()){ - services.add((Service) iter.next()); - } - assertEquals(4,services.size()); - } - - @Test - public void whenRequestingMoreNeighborsThanExisting_itShouldReturnMaxNeighbors(){ - JobNeighborhoodsImplWithCapRestriction jn = new JobNeighborhoodsImplWithCapRestriction(vrp, jobDistance, 2); - jn.initialise(); - Iterator iter = jn.getNearestNeighborsIterator(100, target); - List services = new ArrayList(); - while(iter.hasNext()){ - services.add((Service) iter.next()); - } - assertEquals(2,services.size()); - } + VehicleRoutingProblem vrp; + + JobDistance jobDistance; + + Service target; + Service s2; + Service s3; + Service s4; + Service s5; + Service s6; + Service s7; + + @Before + public void doBefore() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + target = Service.Builder.newInstance("s1").addSizeDimension(0, 1).setLocation(Location.newInstance(0, 5)).build(); + s2 = Service.Builder.newInstance("s2").addSizeDimension(0, 1).setLocation(Location.newInstance(0, 4)).build(); + s3 = Service.Builder.newInstance("s3").addSizeDimension(0, 1).setLocation(Location.newInstance(0, 3)).build(); + s4 = Service.Builder.newInstance("s4").addSizeDimension(0, 1).setLocation(Location.newInstance(0, 2)).build(); + + s5 = Service.Builder.newInstance("s5").addSizeDimension(0, 1).setLocation(Location.newInstance(0, 6)).build(); + s6 = Service.Builder.newInstance("s6").addSizeDimension(0, 1).setLocation(Location.newInstance(0, 7)).build(); + s7 = Service.Builder.newInstance("s7").addSizeDimension(0, 1).setLocation(Location.newInstance(0, 8)).build(); + + vrp = builder.addJob(target).addJob(s2).addJob(s3).addJob(s4).addJob(s5).addJob(s6).addJob(s7).build(); + + jobDistance = new EuclideanServiceDistance(); + } + + @Test + public void whenRequestingNeighborhoodOfTargetJob_nNeighborsShouldBeTwo() { + JobNeighborhoodsImplWithCapRestriction jn = new JobNeighborhoodsImplWithCapRestriction(vrp, jobDistance, 2); + jn.initialise(); + Iterator iter = jn.getNearestNeighborsIterator(2, target); + List services = new ArrayList(); + while (iter.hasNext()) { + services.add((Service) iter.next()); + } + assertEquals(2, services.size()); + } + + @Test + public void whenRequestingNeighborhoodOfTargetJob_s2ShouldBeNeighbor() { + JobNeighborhoodsImplWithCapRestriction jn = new JobNeighborhoodsImplWithCapRestriction(vrp, jobDistance, 2); + jn.initialise(); + Iterator iter = jn.getNearestNeighborsIterator(2, target); + List services = new ArrayList(); + while (iter.hasNext()) { + services.add((Service) iter.next()); + } + assertTrue(services.contains(s2)); + } + + @Test + public void whenRequestingNeighborhoodOfTargetJob_s4ShouldBeNeighbor() { + JobNeighborhoodsImplWithCapRestriction jn = new JobNeighborhoodsImplWithCapRestriction(vrp, jobDistance, 2); + jn.initialise(); + Iterator iter = jn.getNearestNeighborsIterator(2, target); + List services = new ArrayList(); + while (iter.hasNext()) { + services.add((Service) iter.next()); + } + assertTrue(services.contains(s5)); + } + + @Test + public void whenRequestingNeighborhoodOfTargetJob_sizeShouldBe4() { + JobNeighborhoodsImplWithCapRestriction jn = new JobNeighborhoodsImplWithCapRestriction(vrp, jobDistance, 4); + jn.initialise(); + Iterator iter = jn.getNearestNeighborsIterator(4, target); + List services = new ArrayList(); + while (iter.hasNext()) { + services.add((Service) iter.next()); + } + assertEquals(4, services.size()); + } + + @Test + public void whenRequestingMoreNeighborsThanExisting_itShouldReturnMaxNeighbors() { + JobNeighborhoodsImplWithCapRestriction jn = new JobNeighborhoodsImplWithCapRestriction(vrp, jobDistance, 2); + jn.initialise(); + Iterator iter = jn.getNearestNeighborsIterator(100, target); + List services = new ArrayList(); + while (iter.hasNext()) { + services.add((Service) iter.next()); + } + assertEquals(2, services.size()); + } } diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/ruin/RuinBreakTest.java b/jsprit-core/src/test/java/jsprit/core/algorithm/ruin/RuinBreakTest.java new file mode 100644 index 00000000..193e57a4 --- /dev/null +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/ruin/RuinBreakTest.java @@ -0,0 +1,39 @@ +package jsprit.core.algorithm.ruin; + +import jsprit.core.problem.Location; +import jsprit.core.problem.VehicleRoutingProblem; +import jsprit.core.problem.job.Break; +import jsprit.core.problem.job.Job; +import jsprit.core.problem.solution.route.VehicleRoute; +import jsprit.core.problem.solution.route.activity.BreakActivity; +import jsprit.core.problem.solution.route.activity.TourActivity; +import jsprit.core.problem.vehicle.VehicleImpl; +import junit.framework.Assert; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * Created by schroeder on 04/08/15. + */ +public class RuinBreakTest { + + @Test + public void itShouldRuinBreaks() { + Break aBreak = Break.Builder.newInstance("break").build(); + VehicleImpl v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("loc")) + .setBreak(aBreak).build(); + VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().setFleetSize(VehicleRoutingProblem.FleetSize.FINITE).addVehicle(v).build(); + VehicleRoute route = VehicleRoute.Builder.newInstance(v).setJobActivityFactory(vrp.getJobActivityFactory()).addService(aBreak).build(); + TourActivity tourActivity = route.getActivities().get(0); + System.out.println(tourActivity); + Assert.assertTrue(tourActivity instanceof BreakActivity); + RuinBreaks ruinBreaks = new RuinBreaks(); + List unassigned = new ArrayList(); + ruinBreaks.ruinEnds(Arrays.asList(route), unassigned); + Assert.assertEquals(1, unassigned.size()); + Assert.assertEquals(aBreak, unassigned.get(0)); + } +} diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/ruin/RuinClustersTest.java b/jsprit-core/src/test/java/jsprit/core/algorithm/ruin/RuinClustersTest.java index 5bfcc6ad..25460197 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/ruin/RuinClustersTest.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/ruin/RuinClustersTest.java @@ -7,11 +7,13 @@ import jsprit.core.problem.job.Job; import jsprit.core.problem.job.Service; import jsprit.core.problem.solution.route.VehicleRoute; import jsprit.core.problem.vehicle.VehicleImpl; +import jsprit.core.util.RandomNumberGeneration; import junit.framework.Assert; import org.junit.Test; import java.util.Arrays; import java.util.Collection; +import java.util.Random; /** * Created by schroeder on 06/03/15. @@ -19,30 +21,34 @@ import java.util.Collection; public class RuinClustersTest { @Test - public void itShouldRuinTwoObviousClusters(){ + public void itShouldRuinTwoObviousClusters() { Service s0 = Service.Builder.newInstance("s0").setLocation(Location.newInstance(9, 0)).build(); Service s1 = Service.Builder.newInstance("s1").setLocation(Location.newInstance(9, 1)).build(); - Service s2 = Service.Builder.newInstance("s2").setLocation(Location.newInstance(9,10)).build(); - Service s3 = Service.Builder.newInstance("s3").setLocation(Location.newInstance(9,9)).build(); - Service s4 = Service.Builder.newInstance("s4").setLocation(Location.newInstance(9,16)).build(); - Service s5 = Service.Builder.newInstance("s5").setLocation(Location.newInstance(9,17)).build(); - Service s6 = Service.Builder.newInstance("s6").setLocation(Location.newInstance(9,15.5)).build(); - Service s7 = Service.Builder.newInstance("s7").setLocation(Location.newInstance(9,30)).build(); + Service s2 = Service.Builder.newInstance("s2").setLocation(Location.newInstance(9, 10)).build(); + Service s3 = Service.Builder.newInstance("s3").setLocation(Location.newInstance(9, 9)).build(); + Service s4 = Service.Builder.newInstance("s4").setLocation(Location.newInstance(9, 16)).build(); + Service s5 = Service.Builder.newInstance("s5").setLocation(Location.newInstance(9, 17)).build(); + Service s6 = Service.Builder.newInstance("s6").setLocation(Location.newInstance(9, 15.5)).build(); + Service s7 = Service.Builder.newInstance("s7").setLocation(Location.newInstance(9, 30)).build(); - VehicleImpl v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0,0)).build(); + VehicleImpl v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0, 0)).build(); VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(s1).addJob(s2) - .addJob(s6).addJob(s7).addJob(s0).addJob(s3).addJob(s4).addJob(s5).addVehicle(v).build(); + .addJob(s6).addJob(s7).addJob(s0).addJob(s3).addJob(s4).addJob(s5).addVehicle(v).build(); VehicleRoute vr1 = VehicleRoute.Builder.newInstance(v).addService(s0).addService(s1).addService(s2).addService(s3).setJobActivityFactory(vrp.getJobActivityFactory()).build(); VehicleRoute vr2 = VehicleRoute.Builder.newInstance(v) - .addService(s6).addService(s7).addService(s4).addService(s5).setJobActivityFactory(vrp.getJobActivityFactory()).build(); + .addService(s6).addService(s7).addService(s4).addService(s5).setJobActivityFactory(vrp.getJobActivityFactory()).build(); - JobNeighborhoods n = new JobNeighborhoodsFactory().createNeighborhoods(vrp,new AvgServiceAndShipmentDistance(vrp.getTransportCosts())); + JobNeighborhoods n = new JobNeighborhoodsFactory().createNeighborhoods(vrp, new AvgServiceAndShipmentDistance(vrp.getTransportCosts())); n.initialise(); - RuinClusters rc = new RuinClusters(vrp,5,n); - Collection ruined = rc.ruinRoutes(Arrays.asList(vr1,vr2)); - Assert.assertEquals(5,ruined.size()); + RuinClusters rc = new RuinClusters(vrp, 5, n); + Random r = RandomNumberGeneration.newInstance(); + rc.setRandom(r); + Collection ruined = rc.ruinRoutes(Arrays.asList(vr1, vr2)); + Assert.assertEquals(5, ruined.size()); } + + } diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/ruin/RuinWorstTest.java b/jsprit-core/src/test/java/jsprit/core/algorithm/ruin/RuinWorstTest.java index 4e65494a..253d4a5b 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/ruin/RuinWorstTest.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/ruin/RuinWorstTest.java @@ -22,55 +22,55 @@ import static org.junit.Assert.assertTrue; public class RuinWorstTest { @Test - public void itShouldRemoveCorrectNumber(){ + public void itShouldRemoveCorrectNumber() { Service s1 = Service.Builder.newInstance("s1") - .setLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(1, 1)).build()).build(); + .setLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(1, 1)).build()).build(); Service s2 = Service.Builder.newInstance("s2") - .setLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(3, 1)).build()).build(); + .setLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(3, 1)).build()).build(); Service s3 = Service.Builder.newInstance("s3") - .setLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(10, 10)).build()).build(); + .setLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(10, 10)).build()).build(); VehicleImpl v = VehicleImpl.Builder.newInstance("v") - .setStartLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(0, 0)).build()).build(); + .setStartLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(0, 0)).build()).build(); VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(s1).addJob(s2).addJob(s3).addVehicle(v).build(); - RuinWorst worst = new RuinWorst(vrp,1); + RuinWorst worst = new RuinWorst(vrp, 1); VehicleRoute route = VehicleRoute.Builder.newInstance(v).addService(s1).addService(s2).addService(s3).setJobActivityFactory(vrp.getJobActivityFactory()).build(); Collection unassigned = worst.ruinRoutes(Arrays.asList(route)); - assertEquals(1,unassigned.size()); + assertEquals(1, unassigned.size()); } @Test - public void itShouldRemoveWorst(){ + public void itShouldRemoveWorst() { Service s1 = Service.Builder.newInstance("s1") - .setLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(1, 1)).build()).build(); + .setLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(1, 1)).build()).build(); Service s2 = Service.Builder.newInstance("s2") - .setLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(3, 1)).build()).build(); + .setLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(3, 1)).build()).build(); Service s3 = Service.Builder.newInstance("s3") - .setLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(10, 10)).build()).build(); + .setLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(10, 10)).build()).build(); VehicleImpl v = VehicleImpl.Builder.newInstance("v") - .setStartLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(0, 0)).build()).build(); + .setStartLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(0, 0)).build()).build(); VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(s1).addJob(s2).addJob(s3).addVehicle(v).build(); - RuinWorst worst = new RuinWorst(vrp,1); + RuinWorst worst = new RuinWorst(vrp, 1); VehicleRoute route = VehicleRoute.Builder.newInstance(v).addService(s1).addService(s2).addService(s3).setJobActivityFactory(vrp.getJobActivityFactory()).build(); Collection unassigned = worst.ruinRoutes(Arrays.asList(route)); - assertEquals(s3,unassigned.iterator().next()); + assertEquals(s3, unassigned.iterator().next()); } @Test - public void itShouldRemoveWorstTwo(){ + public void itShouldRemoveWorstTwo() { Service s1 = Service.Builder.newInstance("s1") - .setLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(1, 1)).build()).build(); + .setLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(1, 1)).build()).build(); Service s2 = Service.Builder.newInstance("s2") - .setLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(3, 1)).build()).build(); + .setLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(3, 1)).build()).build(); Service s3 = Service.Builder.newInstance("s3") - .setLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(10, 10)).build()).build(); + .setLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(10, 10)).build()).build(); VehicleImpl v = VehicleImpl.Builder.newInstance("v") - .setStartLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(0, 0)).build()).build(); + .setStartLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(0, 0)).build()).build(); VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(s1).addJob(s2).addJob(s3).addVehicle(v).build(); - RuinWorst worst = new RuinWorst(vrp,1); + RuinWorst worst = new RuinWorst(vrp, 1); worst.setRuinShareFactory(new RuinShareFactory() { @Override public int createNumberToBeRemoved() { @@ -88,21 +88,21 @@ public class RuinWorstTest { } @Test - public void itShouldRemoveShipment(){ + public void itShouldRemoveShipment() { Service s1 = Service.Builder.newInstance("s1") - .setLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(1, 1)).build()).build(); + .setLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(1, 1)).build()).build(); Service s2 = Service.Builder.newInstance("s2") - .setLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(3, 1)).build()).build(); + .setLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(3, 1)).build()).build(); Service s3 = Service.Builder.newInstance("s3") - .setLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(10, 10)).build()).build(); + .setLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(10, 10)).build()).build(); Shipment shipment = Shipment.Builder.newInstance("ship1") - .setPickupLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(2, 2)).build()) - .setDeliveryLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(9, 9)).build()).build(); + .setPickupLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(2, 2)).build()) + .setDeliveryLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(9, 9)).build()).build(); VehicleImpl v = VehicleImpl.Builder.newInstance("v") - .setStartLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(0, 0)).build()).build(); + .setStartLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(0, 0)).build()).build(); VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance() - .addJob(shipment).addJob(s1).addJob(s2).addJob(s3).addVehicle(v).build(); - RuinWorst worst = new RuinWorst(vrp,1); + .addJob(shipment).addJob(s1).addJob(s2).addJob(s3).addVehicle(v).build(); + RuinWorst worst = new RuinWorst(vrp, 1); worst.setRuinShareFactory(new RuinShareFactory() { @Override public int createNumberToBeRemoved() { @@ -111,8 +111,8 @@ public class RuinWorstTest { }); VehicleRoute route = VehicleRoute.Builder.newInstance(v) - .addPickup(shipment).addService(s1).addService(s2).addService(s3).addDelivery(shipment) - .setJobActivityFactory(vrp.getJobActivityFactory()).build(); + .addPickup(shipment).addService(s1).addService(s2).addService(s3).addDelivery(shipment) + .setJobActivityFactory(vrp.getJobActivityFactory()).build(); Collection unassigned = worst.ruinRoutes(Arrays.asList(route)); assertTrue(unassigned.size() == 1); @@ -121,23 +121,23 @@ public class RuinWorstTest { } @Test - public void itShouldRemoveShipmentFromSecondRoute(){ + public void itShouldRemoveShipmentFromSecondRoute() { Service s1 = Service.Builder.newInstance("s1") - .setLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(1, 1)).build()).build(); + .setLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(1, 1)).build()).build(); Service s2 = Service.Builder.newInstance("s2") - .setLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(3, 1)).build()).build(); + .setLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(3, 1)).build()).build(); Service s3 = Service.Builder.newInstance("s3") - .setLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(10, 10)).build()).build(); + .setLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(10, 10)).build()).build(); Shipment shipment = Shipment.Builder.newInstance("ship1") - .setPickupLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(3, 1)).build()) - .setDeliveryLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(10, 10.1)).build()).build(); + .setPickupLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(3, 1)).build()) + .setDeliveryLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(10, 10.1)).build()).build(); VehicleImpl v = VehicleImpl.Builder.newInstance("v") - .setStartLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(0, 0)).build()).build(); + .setStartLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(0, 0)).build()).build(); VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2") - .setStartLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(0, 0)).build()).build(); + .setStartLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(0, 0)).build()).build(); VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance() - .addJob(shipment).addJob(s1).addJob(s2).addJob(s3).addVehicle(v).addVehicle(v2).build(); - RuinWorst worst = new RuinWorst(vrp,1); + .addJob(shipment).addJob(s1).addJob(s2).addJob(s3).addVehicle(v).addVehicle(v2).build(); + RuinWorst worst = new RuinWorst(vrp, 1); worst.setRuinShareFactory(new RuinShareFactory() { @Override public int createNumberToBeRemoved() { @@ -146,11 +146,11 @@ public class RuinWorstTest { }); VehicleRoute route1 = VehicleRoute.Builder.newInstance(v) - .addService(s1).addService(s2).addService(s3) - .setJobActivityFactory(vrp.getJobActivityFactory()).build(); + .addService(s1).addService(s2).addService(s3) + .setJobActivityFactory(vrp.getJobActivityFactory()).build(); VehicleRoute route2 = VehicleRoute.Builder.newInstance(v2) - .addPickup(shipment).addDelivery(shipment).build(); - Collection unassigned = worst.ruinRoutes(Arrays.asList(route1,route2)); + .addPickup(shipment).addDelivery(shipment).build(); + Collection unassigned = worst.ruinRoutes(Arrays.asList(route1, route2)); assertTrue(unassigned.size() == 1); assertTrue(unassigned.contains(shipment)); @@ -158,23 +158,23 @@ public class RuinWorstTest { } @Test - public void itShouldRemoveServiceAndShipmentFromSecondRoute(){ + public void itShouldRemoveServiceAndShipmentFromSecondRoute() { Service s1 = Service.Builder.newInstance("s1") - .setLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(1, 1)).build()).build(); + .setLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(1, 1)).build()).build(); Service s2 = Service.Builder.newInstance("s2") - .setLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(3, 1)).build()).build(); + .setLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(3, 1)).build()).build(); Service s3 = Service.Builder.newInstance("s3") - .setLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(10, 10)).build()).build(); + .setLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(10, 10)).build()).build(); Shipment shipment = Shipment.Builder.newInstance("ship1") - .setPickupLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(3, 1)).build()) - .setDeliveryLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(10, 10.1)).build()).build(); + .setPickupLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(3, 1)).build()) + .setDeliveryLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(10, 10.1)).build()).build(); VehicleImpl v = VehicleImpl.Builder.newInstance("v") - .setStartLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(0, 0)).build()).build(); + .setStartLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(0, 0)).build()).build(); VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2") - .setStartLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(0, 0)).build()).build(); + .setStartLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(0, 0)).build()).build(); VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance() - .addJob(shipment).addJob(s1).addJob(s2).addJob(s3).addVehicle(v).addVehicle(v2).build(); - RuinWorst worst = new RuinWorst(vrp,1); + .addJob(shipment).addJob(s1).addJob(s2).addJob(s3).addVehicle(v).addVehicle(v2).build(); + RuinWorst worst = new RuinWorst(vrp, 1); worst.setRuinShareFactory(new RuinShareFactory() { @Override public int createNumberToBeRemoved() { @@ -183,11 +183,11 @@ public class RuinWorstTest { }); VehicleRoute route1 = VehicleRoute.Builder.newInstance(v) - .addService(s1).addService(s2).addService(s3) - .setJobActivityFactory(vrp.getJobActivityFactory()).build(); + .addService(s1).addService(s2).addService(s3) + .setJobActivityFactory(vrp.getJobActivityFactory()).build(); VehicleRoute route2 = VehicleRoute.Builder.newInstance(v2) - .addPickup(shipment).addDelivery(shipment).build(); - Collection unassigned = worst.ruinRoutes(Arrays.asList(route1,route2)); + .addPickup(shipment).addDelivery(shipment).build(); + Collection unassigned = worst.ruinRoutes(Arrays.asList(route1, route2)); assertTrue(unassigned.size() == 2); assertTrue(unassigned.contains(shipment)); @@ -196,5 +196,4 @@ public class RuinWorstTest { } - } diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/ruin/distance/AverageJobDistanceTest.java b/jsprit-core/src/test/java/jsprit/core/algorithm/ruin/distance/AverageJobDistanceTest.java index 06afaaa6..481bd360 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/ruin/distance/AverageJobDistanceTest.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/ruin/distance/AverageJobDistanceTest.java @@ -31,52 +31,51 @@ import static org.junit.Assert.assertTrue; public class AverageJobDistanceTest { - - private CrowFlyCosts routingCosts; - @Before - public void doBefore(){ - Locations locations = new Locations(){ + private CrowFlyCosts routingCosts; - @Override - public Coordinate getCoord(String id) { - //assume: locationId="x,y" - String[] splitted = id.split(","); - return Coordinate.newInstance(Double.parseDouble(splitted[0]), - Double.parseDouble(splitted[1])); - } - - }; - routingCosts = new CrowFlyCosts(locations); + @Before + public void doBefore() { + Locations locations = new Locations() { - } - - @Test - public void distanceOfTwoEqualShipmentsShouldBeSmallerThanAnyOtherDistance(){ - Shipment s1 = Shipment.Builder.newInstance("s1").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("0,0").build()).setDeliveryLocation(Location.newInstance("10,10")).build(); - Shipment s2 = Shipment.Builder.newInstance("s2").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("0,0").build()).setDeliveryLocation(Location.newInstance("10,10")).build(); - - double dist = new AvgServiceAndShipmentDistance(routingCosts).getDistance(s1, s2); - - for(int i=0;i<10;i++){ - for(int j=0;j<10;j++){ - Shipment other1 = Shipment.Builder.newInstance("s1").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("0,0").build()).setDeliveryLocation(Location.newInstance(i + "," + j)).build(); - Shipment other2 = Shipment.Builder.newInstance("s2").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("0,0").build()).setDeliveryLocation(Location.newInstance("10,10")).build(); - double dist2 = new AvgServiceAndShipmentDistance(routingCosts).getDistance(other1, other2); - System.out.println("("+i+","+j+"), dist=" + dist + ", dist2=" + dist2); - assertTrue(dist<=dist2+dist2*0.001); - } - } - } - - - - @Test - public void whenServicesHaveSameLocation_distanceShouldBeZero(){ - Service s1 = Service.Builder.newInstance("s1").addSizeDimension(0, 1).setLocation(Location.newInstance("10,0")).build(); - Service s2 = Service.Builder.newInstance("s2").addSizeDimension(0, 1).setLocation(Location.newInstance("10,0")).build(); - - double dist = new AvgServiceAndShipmentDistance(routingCosts).getDistance(s1, s2); - assertEquals(0.0,dist,0.01); - } + @Override + public Coordinate getCoord(String id) { + //assume: locationId="x,y" + String[] splitted = id.split(","); + return Coordinate.newInstance(Double.parseDouble(splitted[0]), + Double.parseDouble(splitted[1])); + } + + }; + routingCosts = new CrowFlyCosts(locations); + + } + + @Test + public void distanceOfTwoEqualShipmentsShouldBeSmallerThanAnyOtherDistance() { + Shipment s1 = Shipment.Builder.newInstance("s1").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("0,0").build()).setDeliveryLocation(Location.newInstance("10,10")).build(); + Shipment s2 = Shipment.Builder.newInstance("s2").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("0,0").build()).setDeliveryLocation(Location.newInstance("10,10")).build(); + + double dist = new AvgServiceAndShipmentDistance(routingCosts).getDistance(s1, s2); + + for (int i = 0; i < 10; i++) { + for (int j = 0; j < 10; j++) { + Shipment other1 = Shipment.Builder.newInstance("s1").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("0,0").build()).setDeliveryLocation(Location.newInstance(i + "," + j)).build(); + Shipment other2 = Shipment.Builder.newInstance("s2").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("0,0").build()).setDeliveryLocation(Location.newInstance("10,10")).build(); + double dist2 = new AvgServiceAndShipmentDistance(routingCosts).getDistance(other1, other2); + System.out.println("(" + i + "," + j + "), dist=" + dist + ", dist2=" + dist2); + assertTrue(dist <= dist2 + dist2 * 0.001); + } + } + } + + + @Test + public void whenServicesHaveSameLocation_distanceShouldBeZero() { + Service s1 = Service.Builder.newInstance("s1").addSizeDimension(0, 1).setLocation(Location.newInstance("10,0")).build(); + Service s2 = Service.Builder.newInstance("s2").addSizeDimension(0, 1).setLocation(Location.newInstance("10,0")).build(); + + double dist = new AvgServiceAndShipmentDistance(routingCosts).getDistance(s1, s2); + assertEquals(0.0, dist, 0.01); + } } diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/ruin/distance/TestJobDistanceAvgCosts.java b/jsprit-core/src/test/java/jsprit/core/algorithm/ruin/distance/TestJobDistanceAvgCosts.java index 5953bb1f..23eb5fb6 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/ruin/distance/TestJobDistanceAvgCosts.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/ruin/distance/TestJobDistanceAvgCosts.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.ruin.distance; @@ -25,73 +25,73 @@ import org.junit.Test; public class TestJobDistanceAvgCosts { - - public static void main(String[] args) { - VehicleRoutingTransportCosts costs = new VehicleRoutingTransportCosts() { - - @Override - public double getBackwardTransportTime(Location from, Location to,double arrivalTime, Driver driver, Vehicle vehicle) { - - return 0; - } - - @Override - public double getBackwardTransportCost(Location from, Location to, - double arrivalTime, Driver driver, Vehicle vehicle) { - return 0; - } - - @Override - public double getTransportCost(Location from, Location to, - double departureTime, Driver driver, Vehicle vehicle) { - @SuppressWarnings("unused") - String vehicleId = vehicle.getId(); - return 0; - } - - @Override - public double getTransportTime(Location from, Location to, - double departureTime, Driver driver, Vehicle vehicle) { - return 0; - } - }; - AvgServiceDistance c = new AvgServiceDistance(costs); - c.getDistance(Service.Builder.newInstance("1").addSizeDimension(0, 1).setLocation(Location.newInstance("foo")).build(), Service.Builder.newInstance("2").addSizeDimension(0, 2).setLocation(Location.newInstance("foo")).build()); - } - - @Test(expected=NullPointerException.class) - public void whenVehicleAndDriverIsNull_And_CostsDoesNotProvideAMethodForThis_throwException(){ + + public static void main(String[] args) { + VehicleRoutingTransportCosts costs = new VehicleRoutingTransportCosts() { + + @Override + public double getBackwardTransportTime(Location from, Location to, double arrivalTime, Driver driver, Vehicle vehicle) { + + return 0; + } + + @Override + public double getBackwardTransportCost(Location from, Location to, + double arrivalTime, Driver driver, Vehicle vehicle) { + return 0; + } + + @Override + public double getTransportCost(Location from, Location to, + double departureTime, Driver driver, Vehicle vehicle) { + @SuppressWarnings("unused") + String vehicleId = vehicle.getId(); + return 0; + } + + @Override + public double getTransportTime(Location from, Location to, + double departureTime, Driver driver, Vehicle vehicle) { + return 0; + } + }; + AvgServiceDistance c = new AvgServiceDistance(costs); + c.getDistance(Service.Builder.newInstance("1").addSizeDimension(0, 1).setLocation(Location.newInstance("foo")).build(), Service.Builder.newInstance("2").addSizeDimension(0, 2).setLocation(Location.newInstance("foo")).build()); + } + + @Test(expected = NullPointerException.class) + public void whenVehicleAndDriverIsNull_And_CostsDoesNotProvideAMethodForThis_throwException() { // (expected=NullPointerException.class) - VehicleRoutingTransportCosts costs = new VehicleRoutingTransportCosts() { - - @Override - public double getBackwardTransportTime(Location from, Location to,double arrivalTime, Driver driver, Vehicle vehicle) { - - return 0; - } - - @Override - public double getBackwardTransportCost(Location from, Location to, - double arrivalTime, Driver driver, Vehicle vehicle) { - return 0; - } - - @Override - public double getTransportCost(Location from, Location to, - double departureTime, Driver driver, Vehicle vehicle) { - @SuppressWarnings("unused") - String vehicleId = vehicle.getId(); - return 0; - } - - @Override - public double getTransportTime(Location from, Location to, - double departureTime, Driver driver, Vehicle vehicle) { - return 0; - } - }; - AvgServiceDistance c = new AvgServiceDistance(costs); - c.getDistance(Service.Builder.newInstance("1").addSizeDimension(0, 1).setLocation(Location.newInstance("loc")).build(), Service.Builder.newInstance("2").addSizeDimension(0, 2).setLocation(Location.newInstance("loc")).build()); - } + VehicleRoutingTransportCosts costs = new VehicleRoutingTransportCosts() { + + @Override + public double getBackwardTransportTime(Location from, Location to, double arrivalTime, Driver driver, Vehicle vehicle) { + + return 0; + } + + @Override + public double getBackwardTransportCost(Location from, Location to, + double arrivalTime, Driver driver, Vehicle vehicle) { + return 0; + } + + @Override + public double getTransportCost(Location from, Location to, + double departureTime, Driver driver, Vehicle vehicle) { + @SuppressWarnings("unused") + String vehicleId = vehicle.getId(); + return 0; + } + + @Override + public double getTransportTime(Location from, Location to, + double departureTime, Driver driver, Vehicle vehicle) { + return 0; + } + }; + AvgServiceDistance c = new AvgServiceDistance(costs); + c.getDistance(Service.Builder.newInstance("1").addSizeDimension(0, 1).setLocation(Location.newInstance("loc")).build(), Service.Builder.newInstance("2").addSizeDimension(0, 2).setLocation(Location.newInstance("loc")).build()); + } } diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/selector/SelectBestTest.java b/jsprit-core/src/test/java/jsprit/core/algorithm/selector/SelectBestTest.java index 79a2366e..e8ce3ace 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/selector/SelectBestTest.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/selector/SelectBestTest.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.selector; @@ -29,29 +29,27 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; - - public class SelectBestTest { - - @Test - public void whenHaving2Solutions_selectBest(){ - VehicleRoutingProblemSolution sol1 = mock(VehicleRoutingProblemSolution.class); - VehicleRoutingProblemSolution sol2 = mock(VehicleRoutingProblemSolution.class); - when(sol1.getCost()).thenReturn(1.0); - when(sol2.getCost()).thenReturn(2.0); - assertThat(new SelectBest().selectSolution(Arrays.asList(sol1,sol2)), is(sol1)); - } - - @Test - public void whenHavingOnly1Solutions_selectThisOne(){ - VehicleRoutingProblemSolution sol1 = mock(VehicleRoutingProblemSolution.class); - when(sol1.getCost()).thenReturn(1.0); - assertThat(new SelectBest().selectSolution(Arrays.asList(sol1)), is(sol1)); - } - - @Test - public void whenHavingNoSolutions_returnNull(){ - assertNull(new SelectBest().selectSolution(Collections. emptyList())); - } + + @Test + public void whenHaving2Solutions_selectBest() { + VehicleRoutingProblemSolution sol1 = mock(VehicleRoutingProblemSolution.class); + VehicleRoutingProblemSolution sol2 = mock(VehicleRoutingProblemSolution.class); + when(sol1.getCost()).thenReturn(1.0); + when(sol2.getCost()).thenReturn(2.0); + assertThat(new SelectBest().selectSolution(Arrays.asList(sol1, sol2)), is(sol1)); + } + + @Test + public void whenHavingOnly1Solutions_selectThisOne() { + VehicleRoutingProblemSolution sol1 = mock(VehicleRoutingProblemSolution.class); + when(sol1.getCost()).thenReturn(1.0); + assertThat(new SelectBest().selectSolution(Arrays.asList(sol1)), is(sol1)); + } + + @Test + public void whenHavingNoSolutions_returnNull() { + assertNull(new SelectBest().selectSolution(Collections.emptyList())); + } } diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/selector/SelectRandomlyTest.java b/jsprit-core/src/test/java/jsprit/core/algorithm/selector/SelectRandomlyTest.java index ed0583ff..a32b8920 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/selector/SelectRandomlyTest.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/selector/SelectRandomlyTest.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.algorithm.selector; @@ -30,52 +30,51 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; - public class SelectRandomlyTest { - - @Test - public void whenHaving2Solutions_selectSecond(){ - VehicleRoutingProblemSolution sol1 = mock(VehicleRoutingProblemSolution.class); - VehicleRoutingProblemSolution sol2 = mock(VehicleRoutingProblemSolution.class); - - when(sol1.getCost()).thenReturn(1.0); - when(sol2.getCost()).thenReturn(2.0); - - Random random = mock(Random.class); - when(random.nextInt(2)).thenReturn(1); - SelectRandomly selectRandomly = new SelectRandomly(); - selectRandomly.setRandom(random); - - assertThat(selectRandomly.selectSolution(Arrays.asList(sol1,sol2)), is(sol2)); - } - - @Test - public void whenHaving2Solutions_selectFirst(){ - - VehicleRoutingProblemSolution sol1 = mock(VehicleRoutingProblemSolution.class); - VehicleRoutingProblemSolution sol2 = mock(VehicleRoutingProblemSolution.class); - - when(sol1.getCost()).thenReturn(1.0); - when(sol2.getCost()).thenReturn(2.0); - - Random random = mock(Random.class); - when(random.nextInt(2)).thenReturn(0); + @Test + public void whenHaving2Solutions_selectSecond() { + VehicleRoutingProblemSolution sol1 = mock(VehicleRoutingProblemSolution.class); + VehicleRoutingProblemSolution sol2 = mock(VehicleRoutingProblemSolution.class); - SelectRandomly selectRandomly = new SelectRandomly(); - selectRandomly.setRandom(random); - - assertThat(selectRandomly.selectSolution(Arrays.asList(sol1,sol2)), is(sol1)); - } - - @Test - public void whenHavingNoSolutions_returnNull(){ - Random random = mock(Random.class); - when(random.nextInt(2)).thenReturn(0); + when(sol1.getCost()).thenReturn(1.0); + when(sol2.getCost()).thenReturn(2.0); - SelectRandomly selectRandomly = new SelectRandomly(); - selectRandomly.setRandom(random); - - assertNull(selectRandomly.selectSolution(Collections. emptyList())); - } + Random random = mock(Random.class); + when(random.nextInt(2)).thenReturn(1); + + SelectRandomly selectRandomly = new SelectRandomly(); + selectRandomly.setRandom(random); + + assertThat(selectRandomly.selectSolution(Arrays.asList(sol1, sol2)), is(sol2)); + } + + @Test + public void whenHaving2Solutions_selectFirst() { + + VehicleRoutingProblemSolution sol1 = mock(VehicleRoutingProblemSolution.class); + VehicleRoutingProblemSolution sol2 = mock(VehicleRoutingProblemSolution.class); + + when(sol1.getCost()).thenReturn(1.0); + when(sol2.getCost()).thenReturn(2.0); + + Random random = mock(Random.class); + when(random.nextInt(2)).thenReturn(0); + + SelectRandomly selectRandomly = new SelectRandomly(); + selectRandomly.setRandom(random); + + assertThat(selectRandomly.selectSolution(Arrays.asList(sol1, sol2)), is(sol1)); + } + + @Test + public void whenHavingNoSolutions_returnNull() { + Random random = mock(Random.class); + when(random.nextInt(2)).thenReturn(0); + + SelectRandomly selectRandomly = new SelectRandomly(); + selectRandomly.setRandom(random); + + assertNull(selectRandomly.selectSolution(Collections.emptyList())); + } } diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/state/HardPickupAndDeliveryShipmentActivityConstraintTest.java b/jsprit-core/src/test/java/jsprit/core/algorithm/state/HardPickupAndDeliveryShipmentActivityConstraintTest.java index d02d0f72..78cc9cbb 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/state/HardPickupAndDeliveryShipmentActivityConstraintTest.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/state/HardPickupAndDeliveryShipmentActivityConstraintTest.java @@ -38,73 +38,72 @@ import static org.junit.Assert.assertEquals; public class HardPickupAndDeliveryShipmentActivityConstraintTest { - VehicleImpl vehicle; - - StateManager stateManager; - - Shipment shipment; + VehicleImpl vehicle; + + StateManager stateManager; + + Shipment shipment; Service s1; Service s2; - - PickupAndDeliverShipmentLoadActivityLevelConstraint constraint; - - JobInsertionContext iFacts; + + PickupAndDeliverShipmentLoadActivityLevelConstraint constraint; + + JobInsertionContext iFacts; VehicleRoutingProblem vrp; - - @Before - public void doBefore(){ + + @Before + public void doBefore() { s1 = Service.Builder.newInstance("s1").setLocation(Location.newInstance("loc")).build(); s2 = Service.Builder.newInstance("s2").setLocation(Location.newInstance("loc")).build(); shipment = Shipment.Builder.newInstance("shipment").setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).setDeliveryLocation(Location.newInstance("delLoc")).addSizeDimension(0, 1).build(); // when(vehicle.getCapacity()).thenReturn(2); - VehicleType type = VehicleTypeImpl.Builder.newInstance("t").addCapacityDimension(0,2).build(); + VehicleType type = VehicleTypeImpl.Builder.newInstance("t").addCapacityDimension(0, 2).build(); vehicle = VehicleImpl.Builder.newInstance("v").setType(type).setStartLocation(Location.newInstance("start")).build(); vrp = VehicleRoutingProblem.Builder.newInstance().addJob(s1).addJob(s2).addJob(shipment).addVehicle(vehicle).build(); - stateManager = new StateManager(vrp); + stateManager = new StateManager(vrp); - iFacts = new JobInsertionContext(null, null, vehicle, null, 0.0); - constraint = new PickupAndDeliverShipmentLoadActivityLevelConstraint(stateManager); - } - - @Test - public void whenPickupActivityIsInsertedAndLoadIsSufficient_returnFullFilled(){ - PickupService pickupService = (PickupService) vrp.getActivities(s1).get(0); - PickupService anotherService = (PickupService) vrp.getActivities(s2).get(0); - PickupShipment pickupShipment = (PickupShipment) vrp.getActivities(shipment).get(0); - - assertEquals(ConstraintsStatus.FULFILLED,constraint.fulfilled(iFacts, pickupService, pickupShipment, anotherService, 0.0)); - } - - @Test - public void whenPickupActivityIsInsertedAndLoadIsNotSufficient_returnNOT_FullFilled(){ + iFacts = new JobInsertionContext(null, null, vehicle, null, 0.0); + constraint = new PickupAndDeliverShipmentLoadActivityLevelConstraint(stateManager); + } + + @Test + public void whenPickupActivityIsInsertedAndLoadIsSufficient_returnFullFilled() { + PickupService pickupService = (PickupService) vrp.getActivities(s1).get(0); + PickupService anotherService = (PickupService) vrp.getActivities(s2).get(0); + PickupShipment pickupShipment = (PickupShipment) vrp.getActivities(shipment).get(0); + + assertEquals(ConstraintsStatus.FULFILLED, constraint.fulfilled(iFacts, pickupService, pickupShipment, anotherService, 0.0)); + } + + @Test + public void whenPickupActivityIsInsertedAndLoadIsNotSufficient_returnNOT_FullFilled() { PickupService pickupService = (PickupService) vrp.getActivities(s1).get(0); PickupService anotherService = (PickupService) vrp.getActivities(s2).get(0); PickupShipment pickupShipment = (PickupShipment) vrp.getActivities(shipment).get(0); stateManager.putInternalTypedActivityState(pickupService, InternalStates.LOAD, Capacity.Builder.newInstance().addDimension(0, 2).build()); // when(stateManager.getActivityState(pickupService, StateFactory.LOAD)).thenReturn(StateFactory.createState(2.0)); - assertEquals(ConstraintsStatus.NOT_FULFILLED,constraint.fulfilled(iFacts, pickupService, pickupShipment, anotherService, 0.0)); - } + assertEquals(ConstraintsStatus.NOT_FULFILLED, constraint.fulfilled(iFacts, pickupService, pickupShipment, anotherService, 0.0)); + } - @Test - public void whenDeliveryActivityIsInsertedAndLoadIsSufficient_returnFullFilled(){ + @Test + public void whenDeliveryActivityIsInsertedAndLoadIsSufficient_returnFullFilled() { PickupService pickupService = (PickupService) vrp.getActivities(s1).get(0); PickupService anotherService = (PickupService) vrp.getActivities(s2).get(0); DeliverShipment deliverShipment = (DeliverShipment) vrp.getActivities(shipment).get(1); - - stateManager.putInternalTypedActivityState(pickupService, InternalStates.LOAD, Capacity.Builder.newInstance().addDimension(0, 1).build()); + + stateManager.putInternalTypedActivityState(pickupService, InternalStates.LOAD, Capacity.Builder.newInstance().addDimension(0, 1).build()); // stateManager.putInternalActivityState(pickupService, StateFactory.LOAD, StateFactory.createState(1)); - assertEquals(ConstraintsStatus.FULFILLED,constraint.fulfilled(iFacts, pickupService, deliverShipment, anotherService, 0.0)); - } - - - + assertEquals(ConstraintsStatus.FULFILLED, constraint.fulfilled(iFacts, pickupService, deliverShipment, anotherService, 0.0)); + } + + } diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/state/LoadStateTest.java b/jsprit-core/src/test/java/jsprit/core/algorithm/state/LoadStateTest.java index e8f45c29..d138cc4b 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/state/LoadStateTest.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/state/LoadStateTest.java @@ -47,21 +47,21 @@ public class LoadStateTest { private StateManager stateManager; @Before - public void doBefore(){ + public void doBefore() { Vehicle vehicle = mock(Vehicle.class); VehicleType type = mock(VehicleType.class); - when(type.getCapacityDimensions()).thenReturn(Capacity.Builder.newInstance().addDimension(0,20).build()); + when(type.getCapacityDimensions()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 20).build()); when(vehicle.getType()).thenReturn(type); VehicleRoutingProblem.Builder serviceProblemBuilder = VehicleRoutingProblem.Builder.newInstance(); - Service s1 = Service.Builder.newInstance("s").addSizeDimension(0,10).setLocation(Location.newInstance("loc")).build(); - Service s2 = Service.Builder.newInstance("s2").addSizeDimension(0,5).setLocation(Location.newInstance("loc")).build(); + Service s1 = Service.Builder.newInstance("s").addSizeDimension(0, 10).setLocation(Location.newInstance("loc")).build(); + Service s2 = Service.Builder.newInstance("s2").addSizeDimension(0, 5).setLocation(Location.newInstance("loc")).build(); serviceProblemBuilder.addJob(s1).addJob(s2); final VehicleRoutingProblem serviceProblem = serviceProblemBuilder.build(); final VehicleRoutingProblem.Builder pdProblemBuilder = VehicleRoutingProblem.Builder.newInstance(); - Pickup pickup = (Pickup) Pickup.Builder.newInstance("pick").addSizeDimension(0,10).setLocation(Location.newInstance("loc")).build(); - Delivery delivery = (Delivery) Delivery.Builder.newInstance("del").addSizeDimension(0,5).setLocation(Location.newInstance("loc")).build(); + Pickup pickup = (Pickup) Pickup.Builder.newInstance("pick").addSizeDimension(0, 10).setLocation(Location.newInstance("loc")).build(); + Delivery delivery = (Delivery) Delivery.Builder.newInstance("del").addSizeDimension(0, 5).setLocation(Location.newInstance("loc")).build(); pdProblemBuilder.addJob(pickup).addJob(delivery); final VehicleRoutingProblem pdProblem = pdProblemBuilder.build(); @@ -100,66 +100,68 @@ public class LoadStateTest { }); shipment_route = shipmentRouteBuilder.addPickup(shipment1).addPickup(shipment2).addDelivery(shipment2).addDelivery(shipment1).build(); - stateManager = new StateManager(mock(VehicleRoutingProblem.class)); + VehicleRoutingProblem vrpMock = mock(VehicleRoutingProblem.class); + when(vrpMock.getFleetSize()).thenReturn(VehicleRoutingProblem.FleetSize.FINITE); + stateManager = new StateManager(vrpMock); stateManager.updateLoadStates(); } @Test - public void loadAtEndShouldBe15(){ + public void loadAtEndShouldBe15() { stateManager.informInsertionStarts(Arrays.asList(serviceRoute), Collections.emptyList()); Capacity routeState = stateManager.getRouteState(serviceRoute, InternalStates.LOAD_AT_END, Capacity.class); - assertEquals(15,routeState.get(0)); + assertEquals(15, routeState.get(0)); } @Test - public void loadAtBeginningShouldBe0(){ + public void loadAtBeginningShouldBe0() { stateManager.informInsertionStarts(Arrays.asList(serviceRoute), Collections.emptyList()); Capacity routeState = stateManager.getRouteState(serviceRoute, InternalStates.LOAD_AT_BEGINNING, Capacity.class); - assertEquals(0,routeState.get(0)); + assertEquals(0, routeState.get(0)); } @Test - public void loadAtAct1ShouldBe10(){ + public void loadAtAct1ShouldBe10() { stateManager.informInsertionStarts(Arrays.asList(serviceRoute), Collections.emptyList()); Capacity atAct1 = stateManager.getActivityState(serviceRoute.getActivities().get(0), InternalStates.LOAD, Capacity.class); - assertEquals(10,atAct1.get(0)); + assertEquals(10, atAct1.get(0)); } @Test - public void loadAtAct2ShouldBe15(){ + public void loadAtAct2ShouldBe15() { stateManager.informInsertionStarts(Arrays.asList(serviceRoute), Collections.emptyList()); Capacity atAct2 = stateManager.getActivityState(serviceRoute.getActivities().get(1), InternalStates.LOAD, Capacity.class); - assertEquals(15,atAct2.get(0)); + assertEquals(15, atAct2.get(0)); } @Test - public void futureMaxLoatAtAct1ShouldBe15(){ + public void futureMaxLoatAtAct1ShouldBe15() { stateManager.informInsertionStarts(Arrays.asList(serviceRoute), Collections.emptyList()); Capacity atAct1 = stateManager.getActivityState(serviceRoute.getActivities().get(0), InternalStates.FUTURE_MAXLOAD, Capacity.class); - assertEquals(15,atAct1.get(0)); + assertEquals(15, atAct1.get(0)); } @Test - public void futureMaxLoatAtAct2ShouldBe15(){ + public void futureMaxLoatAtAct2ShouldBe15() { stateManager.informInsertionStarts(Arrays.asList(serviceRoute), Collections.emptyList()); Capacity atAct2 = stateManager.getActivityState(serviceRoute.getActivities().get(1), InternalStates.FUTURE_MAXLOAD, Capacity.class); - assertEquals(15,atAct2.get(0)); + assertEquals(15, atAct2.get(0)); } @Test - public void pastMaxLoatAtAct1ShouldBe0(){ + public void pastMaxLoatAtAct1ShouldBe0() { stateManager.informInsertionStarts(Arrays.asList(serviceRoute), Collections.emptyList()); Capacity atAct1 = stateManager.getActivityState(serviceRoute.getActivities().get(0), InternalStates.PAST_MAXLOAD, Capacity.class); - assertEquals(10,atAct1.get(0)); + assertEquals(10, atAct1.get(0)); } @Test - public void pastMaxLoatAtAct2ShouldBe10(){ + public void pastMaxLoatAtAct2ShouldBe10() { stateManager.informInsertionStarts(Arrays.asList(serviceRoute), Collections.emptyList()); Capacity atAct2 = stateManager.getActivityState(serviceRoute.getActivities().get(1), InternalStates.PAST_MAXLOAD, Capacity.class); - assertEquals(15,atAct2.get(0)); + assertEquals(15, atAct2.get(0)); } /* @@ -167,59 +169,59 @@ public class LoadStateTest { pickup 10 and deliver 5 */ @Test - public void when_pdroute_loadAtEndShouldBe10(){ + public void when_pdroute_loadAtEndShouldBe10() { stateManager.informInsertionStarts(Arrays.asList(pickup_delivery_route), Collections.emptyList()); Capacity routeState = stateManager.getRouteState(pickup_delivery_route, InternalStates.LOAD_AT_END, Capacity.class); - assertEquals(10,routeState.get(0)); + assertEquals(10, routeState.get(0)); } @Test - public void when_pdroute_loadAtBeginningShouldBe5(){ + public void when_pdroute_loadAtBeginningShouldBe5() { stateManager.informInsertionStarts(Arrays.asList(pickup_delivery_route), Collections.emptyList()); Capacity routeState = stateManager.getRouteState(pickup_delivery_route, InternalStates.LOAD_AT_BEGINNING, Capacity.class); - assertEquals(5,routeState.get(0)); + assertEquals(5, routeState.get(0)); } @Test - public void when_pdroute_loadAtAct1ShouldBe15(){ + public void when_pdroute_loadAtAct1ShouldBe15() { stateManager.informInsertionStarts(Arrays.asList(pickup_delivery_route), Collections.emptyList()); Capacity atAct1 = stateManager.getActivityState(pickup_delivery_route.getActivities().get(0), InternalStates.LOAD, Capacity.class); - assertEquals(15,atAct1.get(0)); + assertEquals(15, atAct1.get(0)); } @Test - public void when_pdroute_loadAtAct2ShouldBe10(){ + public void when_pdroute_loadAtAct2ShouldBe10() { stateManager.informInsertionStarts(Arrays.asList(pickup_delivery_route), Collections.emptyList()); Capacity atAct2 = stateManager.getActivityState(pickup_delivery_route.getActivities().get(1), InternalStates.LOAD, Capacity.class); - assertEquals(10,atAct2.get(0)); + assertEquals(10, atAct2.get(0)); } @Test - public void when_pdroute_futureMaxLoatAtAct1ShouldBe15(){ + public void when_pdroute_futureMaxLoatAtAct1ShouldBe15() { stateManager.informInsertionStarts(Arrays.asList(pickup_delivery_route), Collections.emptyList()); Capacity atAct1 = stateManager.getActivityState(pickup_delivery_route.getActivities().get(0), InternalStates.FUTURE_MAXLOAD, Capacity.class); - assertEquals(15,atAct1.get(0)); + assertEquals(15, atAct1.get(0)); } @Test - public void when_pdroute_futureMaxLoatAtAct2ShouldBe10(){ + public void when_pdroute_futureMaxLoatAtAct2ShouldBe10() { stateManager.informInsertionStarts(Arrays.asList(pickup_delivery_route), Collections.emptyList()); Capacity atAct2 = stateManager.getActivityState(pickup_delivery_route.getActivities().get(1), InternalStates.FUTURE_MAXLOAD, Capacity.class); - assertEquals(10,atAct2.get(0)); + assertEquals(10, atAct2.get(0)); } @Test - public void when_pdroute_pastMaxLoatAtAct1ShouldBe15(){ + public void when_pdroute_pastMaxLoatAtAct1ShouldBe15() { stateManager.informInsertionStarts(Arrays.asList(pickup_delivery_route), Collections.emptyList()); Capacity atAct1 = stateManager.getActivityState(pickup_delivery_route.getActivities().get(0), InternalStates.PAST_MAXLOAD, Capacity.class); - assertEquals(15,atAct1.get(0)); + assertEquals(15, atAct1.get(0)); } @Test - public void when_pdroute_pastMaxLoatAtAct2ShouldBe10(){ + public void when_pdroute_pastMaxLoatAtAct2ShouldBe10() { stateManager.informInsertionStarts(Arrays.asList(pickup_delivery_route), Collections.emptyList()); Capacity atAct2 = stateManager.getActivityState(pickup_delivery_route.getActivities().get(1), InternalStates.PAST_MAXLOAD, Capacity.class); - assertEquals(15,atAct2.get(0)); + assertEquals(15, atAct2.get(0)); } /* @@ -230,100 +232,100 @@ public class LoadStateTest { */ @Test - public void when_shipmentroute_loadAtEndShouldBe0(){ + public void when_shipmentroute_loadAtEndShouldBe0() { stateManager.informInsertionStarts(Arrays.asList(shipment_route), Collections.emptyList()); Capacity routeState = stateManager.getRouteState(shipment_route, InternalStates.LOAD_AT_END, Capacity.class); - assertEquals(0,routeState.get(0)); + assertEquals(0, routeState.get(0)); } @Test - public void when_shipmentroute_loadAtBeginningShouldBe0(){ + public void when_shipmentroute_loadAtBeginningShouldBe0() { stateManager.informInsertionStarts(Arrays.asList(shipment_route), Collections.emptyList()); Capacity routeState = stateManager.getRouteState(shipment_route, InternalStates.LOAD_AT_BEGINNING, Capacity.class); - assertEquals(0,routeState.get(0)); + assertEquals(0, routeState.get(0)); } @Test - public void when_shipmentroute_loadAtAct1ShouldBe10(){ + public void when_shipmentroute_loadAtAct1ShouldBe10() { stateManager.informInsertionStarts(Arrays.asList(shipment_route), Collections.emptyList()); Capacity atAct1 = stateManager.getActivityState(shipment_route.getActivities().get(0), InternalStates.LOAD, Capacity.class); - assertEquals(10,atAct1.get(0)); + assertEquals(10, atAct1.get(0)); } @Test - public void when_shipmentroute_loadAtAct2ShouldBe15(){ + public void when_shipmentroute_loadAtAct2ShouldBe15() { stateManager.informInsertionStarts(Arrays.asList(shipment_route), Collections.emptyList()); Capacity atAct2 = stateManager.getActivityState(shipment_route.getActivities().get(1), InternalStates.LOAD, Capacity.class); - assertEquals(15,atAct2.get(0)); + assertEquals(15, atAct2.get(0)); } @Test - public void when_shipmentroute_loadAtAct3ShouldBe10(){ + public void when_shipmentroute_loadAtAct3ShouldBe10() { stateManager.informInsertionStarts(Arrays.asList(shipment_route), Collections.emptyList()); Capacity atAct = stateManager.getActivityState(shipment_route.getActivities().get(2), InternalStates.LOAD, Capacity.class); assertEquals(10, atAct.get(0)); } @Test - public void when_shipmentroute_loadAtAct4ShouldBe0(){ + public void when_shipmentroute_loadAtAct4ShouldBe0() { stateManager.informInsertionStarts(Arrays.asList(shipment_route), Collections.emptyList()); Capacity atAct = stateManager.getActivityState(shipment_route.getActivities().get(3), InternalStates.LOAD, Capacity.class); assertEquals(0, atAct.get(0)); } @Test - public void when_shipmentroute_futureMaxLoatAtAct1ShouldBe15(){ + public void when_shipmentroute_futureMaxLoatAtAct1ShouldBe15() { stateManager.informInsertionStarts(Arrays.asList(shipment_route), Collections.emptyList()); Capacity atAct1 = stateManager.getActivityState(shipment_route.getActivities().get(0), InternalStates.FUTURE_MAXLOAD, Capacity.class); - assertEquals(15,atAct1.get(0)); + assertEquals(15, atAct1.get(0)); } @Test - public void when_shipmentroute_futureMaxLoatAtAct2ShouldBe15(){ + public void when_shipmentroute_futureMaxLoatAtAct2ShouldBe15() { stateManager.informInsertionStarts(Arrays.asList(shipment_route), Collections.emptyList()); Capacity atAct2 = stateManager.getActivityState(shipment_route.getActivities().get(1), InternalStates.FUTURE_MAXLOAD, Capacity.class); - assertEquals(15,atAct2.get(0)); + assertEquals(15, atAct2.get(0)); } @Test - public void when_shipmentroute_futureMaxLoatAtAct3ShouldBe10(){ + public void when_shipmentroute_futureMaxLoatAtAct3ShouldBe10() { stateManager.informInsertionStarts(Arrays.asList(shipment_route), Collections.emptyList()); Capacity atAct = stateManager.getActivityState(shipment_route.getActivities().get(2), InternalStates.FUTURE_MAXLOAD, Capacity.class); - assertEquals(10,atAct.get(0)); + assertEquals(10, atAct.get(0)); } @Test - public void when_shipmentroute_futureMaxLoatAtAct4ShouldBe0(){ + public void when_shipmentroute_futureMaxLoatAtAct4ShouldBe0() { stateManager.informInsertionStarts(Arrays.asList(shipment_route), Collections.emptyList()); Capacity atAct = stateManager.getActivityState(shipment_route.getActivities().get(3), InternalStates.FUTURE_MAXLOAD, Capacity.class); - assertEquals(0,atAct.get(0)); + assertEquals(0, atAct.get(0)); } @Test - public void when_shipmentroute_pastMaxLoatAtAct1ShouldBe10(){ + public void when_shipmentroute_pastMaxLoatAtAct1ShouldBe10() { stateManager.informInsertionStarts(Arrays.asList(shipment_route), Collections.emptyList()); Capacity atAct1 = stateManager.getActivityState(shipment_route.getActivities().get(0), InternalStates.PAST_MAXLOAD, Capacity.class); - assertEquals(10,atAct1.get(0)); + assertEquals(10, atAct1.get(0)); } @Test - public void when_shipmentroute_pastMaxLoatAtAct2ShouldBe10(){ + public void when_shipmentroute_pastMaxLoatAtAct2ShouldBe10() { stateManager.informInsertionStarts(Arrays.asList(shipment_route), Collections.emptyList()); Capacity atAct2 = stateManager.getActivityState(shipment_route.getActivities().get(1), InternalStates.PAST_MAXLOAD, Capacity.class); - assertEquals(15,atAct2.get(0)); + assertEquals(15, atAct2.get(0)); } @Test - public void when_shipmentroute_pastMaxLoatAtAct3ShouldBe15(){ + public void when_shipmentroute_pastMaxLoatAtAct3ShouldBe15() { stateManager.informInsertionStarts(Arrays.asList(shipment_route), Collections.emptyList()); Capacity atAct = stateManager.getActivityState(shipment_route.getActivities().get(2), InternalStates.PAST_MAXLOAD, Capacity.class); - assertEquals(15,atAct.get(0)); + assertEquals(15, atAct.get(0)); } @Test - public void when_shipmentroute_pastMaxLoatAtAct4ShouldBe15(){ + public void when_shipmentroute_pastMaxLoatAtAct4ShouldBe15() { stateManager.informInsertionStarts(Arrays.asList(shipment_route), Collections.emptyList()); Capacity atAct = stateManager.getActivityState(shipment_route.getActivities().get(3), InternalStates.PAST_MAXLOAD, Capacity.class); - assertEquals(15,atAct.get(0)); + assertEquals(15, atAct.get(0)); } } diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/state/StateManagerTest.java b/jsprit-core/src/test/java/jsprit/core/algorithm/state/StateManagerTest.java index dbeef1be..b21a07db 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/state/StateManagerTest.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/state/StateManagerTest.java @@ -26,6 +26,7 @@ import jsprit.core.problem.vehicle.Vehicle; import jsprit.core.problem.vehicle.VehicleImpl; import jsprit.core.problem.vehicle.VehicleType; import jsprit.core.problem.vehicle.VehicleTypeImpl; +import org.junit.Before; import org.junit.Test; import java.util.ArrayList; @@ -37,7 +38,7 @@ import static org.mockito.Mockito.when; public class StateManagerTest { - static class ActFac implements JobActivityFactory{ + static class ActFac implements JobActivityFactory { @Override public List createActivities(Job job) { @@ -53,166 +54,172 @@ public class StateManagerTest { return VehicleRoute.Builder.newInstance(vehicle).setJobActivityFactory(new ActFac()).addService(Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")).build()).build(); } + private VehicleRoutingProblem vrpMock; + + @Before + public void doBefore(){ + vrpMock = mock(VehicleRoutingProblem.class); + when(vrpMock.getFleetSize()).thenReturn(VehicleRoutingProblem.FleetSize.INFINITE); + } @Test - public void whenInternalRouteStateIsSet_itMustBeSetCorrectly(){ + public void whenInternalRouteStateIsSet_itMustBeSetCorrectly() { VehicleRoute route = getRoute(mock(Vehicle.class)); - StateManager stateManager = new StateManager(mock(VehicleRoutingProblem.class)); + StateManager stateManager = new StateManager(vrpMock); StateId id = InternalStates.COSTS; stateManager.putTypedInternalRouteState(route, id, 10.); assertEquals(10., stateManager.getRouteState(route, id, Double.class), 0.01); } @Test - public void whenInternalRouteStateIsNotSet_itShouldReturnNull(){ + public void whenInternalRouteStateIsNotSet_itShouldReturnNull() { VehicleRoute route = getRoute(mock(Vehicle.class)); - StateManager stateManager = new StateManager(mock(VehicleRoutingProblem.class)); + StateManager stateManager = new StateManager(vrpMock); StateId id = InternalStates.COSTS; Double costs = stateManager.getRouteState(route, id, Double.class); assertTrue(costs == null); } @Test - public void whenVehicleDependentInternalRouteStateIsSet_itMustBeSetCorrectly(){ + public void whenVehicleDependentInternalRouteStateIsSet_itMustBeSetCorrectly() { VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("loc")).build(); //noinspection UnusedDeclaration VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addVehicle(vehicle).build(); VehicleRoute route = getRoute(vehicle); - StateManager stateManager = new StateManager(mock(VehicleRoutingProblem.class)); + StateManager stateManager = new StateManager(vrpMock); StateId id = InternalStates.COSTS; stateManager.putTypedInternalRouteState(route, vehicle, id, 10.); - assertEquals(10.,stateManager.getRouteState(route, vehicle, id, Double.class),0.01); + assertEquals(10., stateManager.getRouteState(route, vehicle, id, Double.class), 0.01); } @Test - public void whenVehicleDependentInternalRouteStateIsNotSet_itMustBeSetCorrectly(){ + public void whenVehicleDependentInternalRouteStateIsNotSet_itMustBeSetCorrectly() { VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("loc")).build(); //noinspection UnusedDeclaration VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addVehicle(vehicle).build(); VehicleRoute route = getRoute(vehicle); - StateManager stateManager = new StateManager(mock(VehicleRoutingProblem.class)); + StateManager stateManager = new StateManager(vrpMock); StateId id = InternalStates.COSTS; Double costs = stateManager.getRouteState(route, vehicle, id, Double.class); assertTrue(costs == null); } @Test - public void whenRouteStateIsSetWithGenericMethodAndBoolean_itMustBeSetCorrectly(){ + public void whenRouteStateIsSetWithGenericMethodAndBoolean_itMustBeSetCorrectly() { VehicleRoute route = getRoute(mock(Vehicle.class)); - StateManager stateManager = new StateManager(mock(VehicleRoutingProblem.class)); - StateId id = stateManager.createStateId("myState"); - stateManager.putRouteState(route, id, true); - assertTrue(stateManager.getRouteState(route, id, Boolean.class)); - } - - @Test - public void whenRouteStateIsSetWithGenericMethodAndInteger_itMustBeSetCorrectly(){ - VehicleRoute route = getRoute(mock(Vehicle.class)); - StateManager stateManager = new StateManager(mock(VehicleRoutingProblem.class)); - StateId id = stateManager.createStateId("myState"); - int load = 3; - stateManager.putRouteState(route, id, load); - int getLoad = stateManager.getRouteState(route, id, Integer.class); - assertEquals(3, getLoad); - } - - @Test - public void whenRouteStateIsSetWithGenericMethodAndCapacity_itMustBeSetCorrectly(){ - VehicleRoute route = getRoute(mock(Vehicle.class)); - StateManager stateManager = new StateManager(mock(VehicleRoutingProblem.class)); - StateId id = stateManager.createStateId("myState"); - Capacity capacity = Capacity.Builder.newInstance().addDimension(0, 500).build(); - stateManager.putRouteState(route, id, capacity); - Capacity getCap = stateManager.getRouteState(route, id, Capacity.class); - assertEquals(500, getCap.get(0)); - } - - - - @Test - public void whenActivityStateIsSetWithGenericMethodAndBoolean_itMustBeSetCorrectly(){ - TourActivity activity = mock(TourActivity.class); - when(activity.getIndex()).thenReturn(1); - StateManager stateManager = new StateManager(mock(VehicleRoutingProblem.class)); - StateId id = stateManager.createStateId("myState"); - stateManager.putActivityState(activity, id, true); - assertTrue(stateManager.getActivityState(activity, id, Boolean.class)); - } - - @Test - public void whenActivityStateIsSetWithGenericMethodAndInteger_itMustBeSetCorrectly(){ - TourActivity activity = mock(TourActivity.class); - when(activity.getIndex()).thenReturn(1); - StateManager stateManager = new StateManager(mock(VehicleRoutingProblem.class)); - StateId id = stateManager.createStateId("myState"); - int load = 3; - stateManager.putActivityState(activity, id, load); - int getLoad = stateManager.getActivityState(activity, id, Integer.class); - assertEquals(3, getLoad); - } - - @Test - public void whenActivityStateIsSetWithGenericMethodAndCapacity_itMustBeSetCorrectly(){ - TourActivity activity = mock(TourActivity.class); - when(activity.getIndex()).thenReturn(1); - StateManager stateManager = new StateManager(mock(VehicleRoutingProblem.class)); - StateId id = stateManager.createStateId("myState"); - Capacity capacity = Capacity.Builder.newInstance().addDimension(0, 500).build(); - stateManager.putActivityState(activity, id, capacity); - Capacity getCap = stateManager.getActivityState(activity, id, Capacity.class); - assertEquals(500, getCap.get(0)); - } - - @Test - public void whenProblemStateIsSet_itMustBeSetCorrectly(){ - StateManager stateManager = new StateManager(mock(VehicleRoutingProblem.class)); - StateId id = stateManager.createStateId("problemState"); - stateManager.putProblemState(id, Boolean.class, true); - boolean problemState = stateManager.getProblemState(id, Boolean.class); - assertTrue(problemState); - } - - @Test(expected=NullPointerException.class) - public void whenProblemStateIsSetAndStateManagerClearedAfterwards_itThrowsException(){ - StateManager stateManager = new StateManager(mock(VehicleRoutingProblem.class)); - StateId id = stateManager.createStateId("problemState"); - stateManager.putProblemState(id, Boolean.class, true); - stateManager.clear(); - @SuppressWarnings("unused") - boolean problemState = stateManager.getProblemState(id, Boolean.class); - } - - @Test - public void whenProblemStateIsSetAndStateManagerClearedAfterwards_itReturnsNull(){ - StateManager stateManager = new StateManager(mock(VehicleRoutingProblem.class)); - StateId id = StateFactory.createId("problemState"); - stateManager.putProblemState(id, Boolean.class, true); - stateManager.clear(); - Boolean problemState = stateManager.getProblemState(id, Boolean.class); - assertNull(problemState); - } - - @Test - public void whenCreatingNewState_itShouldHaveAnIndex(){ - StateManager stateManager = new StateManager(mock(VehicleRoutingProblem.class)); - StateId stateId = stateManager.createStateId("foo-state"); - assertEquals(21,stateId.getIndex()); + StateManager stateManager = new StateManager(vrpMock); + StateId id = stateManager.createStateId("myState"); + stateManager.putRouteState(route, id, true); + assertTrue(stateManager.getRouteState(route, id, Boolean.class)); } @Test - public void whenCreatingNewStates_theyShouldHaveAnIndex(){ - StateManager stateManager = new StateManager(mock(VehicleRoutingProblem.class)); + public void whenRouteStateIsSetWithGenericMethodAndInteger_itMustBeSetCorrectly() { + VehicleRoute route = getRoute(mock(Vehicle.class)); + StateManager stateManager = new StateManager(vrpMock); + StateId id = stateManager.createStateId("myState"); + int load = 3; + stateManager.putRouteState(route, id, load); + int getLoad = stateManager.getRouteState(route, id, Integer.class); + assertEquals(3, getLoad); + } + + @Test + public void whenRouteStateIsSetWithGenericMethodAndCapacity_itMustBeSetCorrectly() { + VehicleRoute route = getRoute(mock(Vehicle.class)); + StateManager stateManager = new StateManager(vrpMock); + StateId id = stateManager.createStateId("myState"); + Capacity capacity = Capacity.Builder.newInstance().addDimension(0, 500).build(); + stateManager.putRouteState(route, id, capacity); + Capacity getCap = stateManager.getRouteState(route, id, Capacity.class); + assertEquals(500, getCap.get(0)); + } + + + @Test + public void whenActivityStateIsSetWithGenericMethodAndBoolean_itMustBeSetCorrectly() { + TourActivity activity = mock(TourActivity.class); + when(activity.getIndex()).thenReturn(1); + StateManager stateManager = new StateManager(vrpMock); + StateId id = stateManager.createStateId("myState"); + stateManager.putActivityState(activity, id, true); + assertTrue(stateManager.getActivityState(activity, id, Boolean.class)); + } + + @Test + public void whenActivityStateIsSetWithGenericMethodAndInteger_itMustBeSetCorrectly() { + TourActivity activity = mock(TourActivity.class); + when(activity.getIndex()).thenReturn(1); + StateManager stateManager = new StateManager(vrpMock); + StateId id = stateManager.createStateId("myState"); + int load = 3; + stateManager.putActivityState(activity, id, load); + int getLoad = stateManager.getActivityState(activity, id, Integer.class); + assertEquals(3, getLoad); + } + + @Test + public void whenActivityStateIsSetWithGenericMethodAndCapacity_itMustBeSetCorrectly() { + TourActivity activity = mock(TourActivity.class); + when(activity.getIndex()).thenReturn(1); + StateManager stateManager = new StateManager(vrpMock); + StateId id = stateManager.createStateId("myState"); + Capacity capacity = Capacity.Builder.newInstance().addDimension(0, 500).build(); + stateManager.putActivityState(activity, id, capacity); + Capacity getCap = stateManager.getActivityState(activity, id, Capacity.class); + assertEquals(500, getCap.get(0)); + } + + @Test + public void whenProblemStateIsSet_itMustBeSetCorrectly() { + StateManager stateManager = new StateManager(vrpMock); + StateId id = stateManager.createStateId("problemState"); + stateManager.putProblemState(id, Boolean.class, true); + boolean problemState = stateManager.getProblemState(id, Boolean.class); + assertTrue(problemState); + } + + @Test(expected = NullPointerException.class) + public void whenProblemStateIsSetAndStateManagerClearedAfterwards_itThrowsException() { + StateManager stateManager = new StateManager(vrpMock); + StateId id = stateManager.createStateId("problemState"); + stateManager.putProblemState(id, Boolean.class, true); + stateManager.clear(); + @SuppressWarnings("unused") + boolean problemState = stateManager.getProblemState(id, Boolean.class); + } + + @Test + public void whenProblemStateIsSetAndStateManagerClearedAfterwards_itReturnsNull() { + StateManager stateManager = new StateManager(vrpMock); + StateId id = stateManager.createStateId("problemState"); + stateManager.putProblemState(id, Boolean.class, true); + stateManager.clear(); + Boolean problemState = stateManager.getProblemState(id, Boolean.class); + assertNull(problemState); + } + + @Test + public void whenCreatingNewState_itShouldHaveAnIndex() { + StateManager stateManager = new StateManager(vrpMock); + StateId stateId = stateManager.createStateId("foo-state"); + assertEquals(21, stateId.getIndex()); + } + + @Test + public void whenCreatingNewStates_theyShouldHaveAnIndex() { + StateManager stateManager = new StateManager(vrpMock); StateId fooState = stateManager.createStateId("foo-state"); StateId foofooState = stateManager.createStateId("foo-foo-state"); - assertEquals(21,fooState.getIndex()); - assertEquals(22,foofooState.getIndex()); + assertEquals(21, fooState.getIndex()); + assertEquals(22, foofooState.getIndex()); } @Test - public void whenCreatingTwoStatesWithTheSameName_theyShouldHaveTheSameIndex(){ - StateManager stateManager = new StateManager(mock(VehicleRoutingProblem.class)); + public void whenCreatingTwoStatesWithTheSameName_theyShouldHaveTheSameIndex() { + StateManager stateManager = new StateManager(vrpMock); StateId fooState = stateManager.createStateId("foo-state"); StateId foofooState = stateManager.createStateId("foo-state"); assertEquals(21, fooState.getIndex()); @@ -220,12 +227,12 @@ public class StateManagerTest { } @Test - public void whenCreatingAVehicleDependentRouteState_itShouldBeMemorized(){ + public void whenCreatingAVehicleDependentRouteState_itShouldBeMemorized() { VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("loc")).build(); //noinspection UnusedDeclaration VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addVehicle(vehicle).build(); VehicleRoute route = getRoute(vehicle); - StateManager stateManager = new StateManager(mock(VehicleRoutingProblem.class)); + StateManager stateManager = new StateManager(vrpMock); StateId id = stateManager.createStateId("myState"); Capacity capacity = Capacity.Builder.newInstance().addDimension(0, 500).build(); stateManager.putRouteState(route, vehicle, id, capacity); @@ -234,11 +241,11 @@ public class StateManagerTest { } @Test - public void whenCreatingAVehicleDependentActivityState_itShouldBeMemorized(){ + public void whenCreatingAVehicleDependentActivityState_itShouldBeMemorized() { VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("loc")).build(); //noinspection UnusedDeclaration VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addVehicle(vehicle).build(); - StateManager stateManager = new StateManager(mock(VehicleRoutingProblem.class)); + StateManager stateManager = new StateManager(vrpMock); StateId id = stateManager.createStateId("myState"); Capacity capacity = Capacity.Builder.newInstance().addDimension(0, 500).build(); TourActivity act = mock(TourActivity.class); @@ -249,20 +256,20 @@ public class StateManagerTest { } @Test - public void whenMemorizingVehicleInfo_itShouldBeMemorized(){ + public void whenMemorizingVehicleInfo_itShouldBeMemorized() { VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("loc")).build(); //noinspection UnusedDeclaration VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addVehicle(vehicle).build(); VehicleRoute route = getRoute(vehicle); - StateManager stateManager = new StateManager(mock(VehicleRoutingProblem.class)); + StateManager stateManager = new StateManager(vrpMock); StateId id = stateManager.createStateId("vehicleParam"); double distanceParam = vehicle.getType().getVehicleCostParams().perDistanceUnit; - stateManager.putRouteState(route,vehicle, id,distanceParam); - assertEquals(1.,stateManager.getRouteState(route,vehicle,id, Double.class),0.01); + stateManager.putRouteState(route, vehicle, id, distanceParam); + assertEquals(1., stateManager.getRouteState(route, vehicle, id, Double.class), 0.01); } @Test - public void whenMemorizingTwoVehicleInfoForRoute_itShouldBeMemorized(){ + public void whenMemorizingTwoVehicleInfoForRoute_itShouldBeMemorized() { VehicleType type = VehicleTypeImpl.Builder.newInstance("t").setCostPerDistance(4.).build(); VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("loc")).build(); VehicleImpl vehicle2 = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("loc")).setType(type).build(); @@ -275,14 +282,14 @@ public class StateManagerTest { StateManager stateManager = new StateManager(vrp); StateId id = stateManager.createStateId("vehicleParam"); double distanceParam = vehicle.getType().getVehicleCostParams().perDistanceUnit; - stateManager.putRouteState(route,vehicle, id,distanceParam); - stateManager.putRouteState(route,vehicle2,id,vehicle2.getType().getVehicleCostParams().perDistanceUnit); + stateManager.putRouteState(route, vehicle, id, distanceParam); + stateManager.putRouteState(route, vehicle2, id, vehicle2.getType().getVehicleCostParams().perDistanceUnit); assertEquals(1., stateManager.getRouteState(route, vehicle, id, Double.class), 0.01); - assertEquals(4.,stateManager.getRouteState(route,vehicle2,id, Double.class),0.01); + assertEquals(4., stateManager.getRouteState(route, vehicle2, id, Double.class), 0.01); } @Test - public void whenMemorizingTwoVehicleInfoForAct_itShouldBeMemorized(){ + public void whenMemorizingTwoVehicleInfoForAct_itShouldBeMemorized() { VehicleType type = VehicleTypeImpl.Builder.newInstance("t").setCostPerDistance(4.).build(); VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("loc")).build(); VehicleImpl vehicle2 = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("loc")).setType(type).build(); @@ -300,11 +307,11 @@ public class StateManagerTest { stateManager.putActivityState(act, vehicle2, id, vehicle2.getType().getVehicleCostParams().perDistanceUnit); assertEquals(1., stateManager.getActivityState(act, vehicle, id, Double.class), 0.01); - assertEquals(4.,stateManager.getActivityState(act,vehicle2, id, Double.class),0.01); + assertEquals(4., stateManager.getActivityState(act, vehicle2, id, Double.class), 0.01); } @Test - public void whenClearing_arrElementsShouldBeNull(){ + public void whenClearing_arrElementsShouldBeNull() { VehicleType type = VehicleTypeImpl.Builder.newInstance("t").setCostPerDistance(4.).build(); VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("loc")).build(); VehicleImpl vehicle2 = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("loc")).setType(type).build(); @@ -324,6 +331,6 @@ public class StateManagerTest { stateManager.clear(); assertNull(stateManager.getActivityState(act, vehicle, id, Double.class)); - assertNull(stateManager.getActivityState(act,vehicle2, id, Double.class)); + assertNull(stateManager.getActivityState(act, vehicle2, id, Double.class)); } } diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/state/UpdatePracticalTimeWindowTest.java b/jsprit-core/src/test/java/jsprit/core/algorithm/state/UpdatePracticalTimeWindowTest.java index 97f8b19f..5b97b4a5 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/state/UpdatePracticalTimeWindowTest.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/state/UpdatePracticalTimeWindowTest.java @@ -1,18 +1,18 @@ /******************************************************************************* * Copyright (c) 2014 Stefan Schroeder. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . - * + * * Contributors: * Stefan Schroeder - initial API and implementation ******************************************************************************/ @@ -41,64 +41,67 @@ import java.util.List; import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; public class UpdatePracticalTimeWindowTest { - - private VehicleRoutingTransportCosts routingCosts; - - private ReverseRouteActivityVisitor reverseActivityVisitor; - - private StateManager stateManager; - - private VehicleRoute route; - - @Before - public void doBefore(){ - - routingCosts = CostFactory.createManhattanCosts(); - stateManager = new StateManager(mock(VehicleRoutingProblem.class)); - - reverseActivityVisitor = new ReverseRouteActivityVisitor(); - reverseActivityVisitor.addActivityVisitor(new UpdatePracticalTimeWindows(stateManager, routingCosts)); - - Pickup pickup = (Pickup) Pickup.Builder.newInstance("pick").setLocation(Location.newInstance("0,20")).setTimeWindow(TimeWindow.newInstance(0, 30)).build(); - Delivery delivery = (Delivery) Delivery.Builder.newInstance("del").setLocation(Location.newInstance("20,20")).setTimeWindow(TimeWindow.newInstance(10, 40)).build(); - Pickup pickup2 = (Pickup) Pickup.Builder.newInstance("pick2").setLocation(Location.newInstance("20,0")).setTimeWindow(TimeWindow.newInstance(20, 50)).build(); + private VehicleRoutingTransportCosts routingCosts; - Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("0,0")).setType(mock(VehicleType.class)).build(); + private ReverseRouteActivityVisitor reverseActivityVisitor; + + private StateManager stateManager; + + private VehicleRoute route; + + @Before + public void doBefore() { + + routingCosts = CostFactory.createManhattanCosts(); + + VehicleRoutingProblem vrpMock = mock(VehicleRoutingProblem.class); + when(vrpMock.getFleetSize()).thenReturn(VehicleRoutingProblem.FleetSize.FINITE); + stateManager = new StateManager(vrpMock); + + reverseActivityVisitor = new ReverseRouteActivityVisitor(); + reverseActivityVisitor.addActivityVisitor(new UpdatePracticalTimeWindows(stateManager, routingCosts)); + + Pickup pickup = (Pickup) Pickup.Builder.newInstance("pick").setLocation(Location.newInstance("0,20")).setTimeWindow(TimeWindow.newInstance(0, 30)).build(); + Delivery delivery = (Delivery) Delivery.Builder.newInstance("del").setLocation(Location.newInstance("20,20")).setTimeWindow(TimeWindow.newInstance(10, 40)).build(); + Pickup pickup2 = (Pickup) Pickup.Builder.newInstance("pick2").setLocation(Location.newInstance("20,0")).setTimeWindow(TimeWindow.newInstance(20, 50)).build(); + + Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("0,0")).setType(mock(VehicleType.class)).build(); VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); final VehicleRoutingProblem vrp = vrpBuilder.addJob(pickup).addJob(pickup2).addJob(delivery).build(); - route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class)).setJobActivityFactory(new JobActivityFactory() { + route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class)).setJobActivityFactory(new JobActivityFactory() { @Override public List createActivities(Job job) { return vrp.copyAndGetActivities(job); } }) - .addService(pickup).addService(delivery).addService(pickup2).build(); - - reverseActivityVisitor.visit(route); - - } - - @Test - public void whenVehicleRouteHasPickupAndDeliveryAndPickup_latestStartTimeOfAct3MustBeCorrect(){ - assertEquals(50.,route.getActivities().get(2).getTheoreticalLatestOperationStartTime(),0.01); - assertEquals(50.,stateManager.getActivityState(route.getActivities().get(2), InternalStates.LATEST_OPERATION_START_TIME, Double.class),0.01); - } - - @Test - public void whenVehicleRouteHasPickupAndDeliveryAndPickup_latestStartTimeOfAct2MustBeCorrect(){ - assertEquals(40.,route.getActivities().get(1).getTheoreticalLatestOperationStartTime(),0.01); - assertEquals(30.,stateManager.getActivityState(route.getActivities().get(1), InternalStates.LATEST_OPERATION_START_TIME, Double.class),0.01); - } - - @Test - public void whenVehicleRouteHasPickupAndDeliveryAndPickup_latestStartTimeOfAct1MustBeCorrect(){ - assertEquals(30.,route.getActivities().get(0).getTheoreticalLatestOperationStartTime(),0.01); - assertEquals(10.,stateManager.getActivityState(route.getActivities().get(0), InternalStates.LATEST_OPERATION_START_TIME, Double.class),0.01); - } + .addService(pickup).addService(delivery).addService(pickup2).build(); + + reverseActivityVisitor.visit(route); + + } + + @Test + public void whenVehicleRouteHasPickupAndDeliveryAndPickup_latestStartTimeOfAct3MustBeCorrect() { + assertEquals(50., route.getActivities().get(2).getTheoreticalLatestOperationStartTime(), 0.01); + assertEquals(50., stateManager.getActivityState(route.getActivities().get(2), InternalStates.LATEST_OPERATION_START_TIME, Double.class), 0.01); + } + + @Test + public void whenVehicleRouteHasPickupAndDeliveryAndPickup_latestStartTimeOfAct2MustBeCorrect() { + assertEquals(40., route.getActivities().get(1).getTheoreticalLatestOperationStartTime(), 0.01); + assertEquals(30., stateManager.getActivityState(route.getActivities().get(1), InternalStates.LATEST_OPERATION_START_TIME, Double.class), 0.01); + } + + @Test + public void whenVehicleRouteHasPickupAndDeliveryAndPickup_latestStartTimeOfAct1MustBeCorrect() { + assertEquals(30., route.getActivities().get(0).getTheoreticalLatestOperationStartTime(), 0.01); + assertEquals(10., stateManager.getActivityState(route.getActivities().get(0), InternalStates.LATEST_OPERATION_START_TIME, Double.class), 0.01); + } } diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/state/UpdateRequiredSkillsTest.java b/jsprit-core/src/test/java/jsprit/core/algorithm/state/UpdateRequiredSkillsTest.java index 2837f65d..1c2ef585 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/state/UpdateRequiredSkillsTest.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/state/UpdateRequiredSkillsTest.java @@ -27,26 +27,26 @@ public class UpdateRequiredSkillsTest { private StateManager stateManager; @Before - public void doBefore(){ + public void doBefore() { VehicleType type = VehicleTypeImpl.Builder.newInstance("t").build(); VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")).setType(type).build(); Service service = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")).addRequiredSkill("skill1").build(); Service service2 = Service.Builder.newInstance("s2").setLocation(Location.newInstance("loc")).addRequiredSkill("skill1").addRequiredSkill("skill2").addRequiredSkill("skill3").build(); Service service3 = Service.Builder.newInstance("s3").setLocation(Location.newInstance("loc")).addRequiredSkill("skill4").addRequiredSkill("skill5").build(); VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addVehicle(vehicle).addJob(service) - .addJob(service2).addJob(service3).build(); + .addJob(service2).addJob(service3).build(); route = VehicleRoute.Builder.newInstance(vehicle).setJobActivityFactory(vrp.getJobActivityFactory()).addService(service).addService(service2).addService(service3).build(); stateManager = new StateManager(vrp); stateManager.updateSkillStates(); - stateManager.informInsertionStarts(Arrays.asList(route),null); + stateManager.informInsertionStarts(Arrays.asList(route), null); } @Test - public void whenUpdatingRoute_skillsAtRouteLevelShouldContainAllSkills(){ + public void whenUpdatingRoute_skillsAtRouteLevelShouldContainAllSkills() { Skills skills = stateManager.getRouteState(route, InternalStates.SKILLS, Skills.class); assertNotNull(skills); - Assert.assertEquals(5,skills.values().size()); + Assert.assertEquals(5, skills.values().size()); assertTrue(skills.containsSkill("skill1")); assertTrue(skills.containsSkill("skill2")); assertTrue(skills.containsSkill("skill3")); diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/state/UpdateVariableCostsTest.java b/jsprit-core/src/test/java/jsprit/core/algorithm/state/UpdateVariableCostsTest.java index 6c0f9ce9..1438a00b 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/state/UpdateVariableCostsTest.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/state/UpdateVariableCostsTest.java @@ -1,18 +1,18 @@ /******************************************************************************* * Copyright (c) 2014 Stefan Schroeder. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . - * + * * Contributors: * Stefan Schroeder - initial API and implementation ******************************************************************************/ diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/state/UpdateVehicleDependentTimeWindowTest.java b/jsprit-core/src/test/java/jsprit/core/algorithm/state/UpdateVehicleDependentTimeWindowTest.java index 7bc3ca14..f0dc96bc 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/state/UpdateVehicleDependentTimeWindowTest.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/state/UpdateVehicleDependentTimeWindowTest.java @@ -44,7 +44,7 @@ public class UpdateVehicleDependentTimeWindowTest { private VehicleRoutingProblem vrp; @Before - public void doBefore(){ + public void doBefore() { VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); routingCosts = CostFactory.createEuclideanCosts(); @@ -84,7 +84,7 @@ public class UpdateVehicleDependentTimeWindowTest { stateManager = new StateManager(vrp); - UpdateVehicleDependentPracticalTimeWindows updater = new UpdateVehicleDependentPracticalTimeWindows(stateManager,routingCosts); + UpdateVehicleDependentPracticalTimeWindows updater = new UpdateVehicleDependentPracticalTimeWindows(stateManager, routingCosts); updater.setVehiclesToUpdate(new UpdateVehicleDependentPracticalTimeWindows.VehiclesToUpdate() { @Override @@ -101,9 +101,9 @@ public class UpdateVehicleDependentTimeWindowTest { } @Test - public void whenSwitchIsNotAllowed_itShouldCalOnlyStatesOfCurrentVehicle(){ + public void whenSwitchIsNotAllowed_itShouldCalOnlyStatesOfCurrentVehicle() { stateManager = new StateManager(vrp); - UpdateVehicleDependentPracticalTimeWindows updater = new UpdateVehicleDependentPracticalTimeWindows(stateManager,routingCosts); + UpdateVehicleDependentPracticalTimeWindows updater = new UpdateVehicleDependentPracticalTimeWindows(stateManager, routingCosts); stateManager.addStateUpdater(updater); stateManager.informInsertionStarts(Arrays.asList(route), Collections.emptyList()); @@ -112,70 +112,70 @@ public class UpdateVehicleDependentTimeWindowTest { } @Test - public void stateManagerShouldHaveMemorizedCorrectLatestEndOfAct3(){ - assertEquals(70.,stateManager.getActivityState(route.getActivities().get(2),vehicle, - InternalStates.LATEST_OPERATION_START_TIME, Double.class),0.01); + public void stateManagerShouldHaveMemorizedCorrectLatestEndOfAct3() { + assertEquals(70., stateManager.getActivityState(route.getActivities().get(2), vehicle, + InternalStates.LATEST_OPERATION_START_TIME, Double.class), 0.01); } @Test - public void stateManagerShouldHaveMemorizedCorrectLatestEndOfAct3_v2(){ - assertEquals(70.,stateManager.getActivityState(route.getActivities().get(2),vehicle, - InternalStates.LATEST_OPERATION_START_TIME, Double.class),0.01); + public void stateManagerShouldHaveMemorizedCorrectLatestEndOfAct3_v2() { + assertEquals(70., stateManager.getActivityState(route.getActivities().get(2), vehicle, + InternalStates.LATEST_OPERATION_START_TIME, Double.class), 0.01); } @Test - public void stateManagerShouldHaveMemorizedCorrectLatestEndOfAct3WithVehicle2(){ - assertEquals(30.,stateManager.getActivityState(route.getActivities().get(2),vehicle2, - InternalStates.LATEST_OPERATION_START_TIME, Double.class),0.01); + public void stateManagerShouldHaveMemorizedCorrectLatestEndOfAct3WithVehicle2() { + assertEquals(30., stateManager.getActivityState(route.getActivities().get(2), vehicle2, + InternalStates.LATEST_OPERATION_START_TIME, Double.class), 0.01); } @Test - public void stateManagerShouldHaveMemorizedCorrectLatestEndOfAct3WithVehicle3(){ - assertEquals(90.,stateManager.getActivityState(route.getActivities().get(2),vehicle3, - InternalStates.LATEST_OPERATION_START_TIME, Double.class),0.01); + public void stateManagerShouldHaveMemorizedCorrectLatestEndOfAct3WithVehicle3() { + assertEquals(90., stateManager.getActivityState(route.getActivities().get(2), vehicle3, + InternalStates.LATEST_OPERATION_START_TIME, Double.class), 0.01); } @Test - public void stateManagerShouldHaveMemorizedCorrectLatestEndOfAct2(){ - assertEquals(60.,stateManager.getActivityState(route.getActivities().get(1),vehicle, - InternalStates.LATEST_OPERATION_START_TIME,Double.class),0.01); + public void stateManagerShouldHaveMemorizedCorrectLatestEndOfAct2() { + assertEquals(60., stateManager.getActivityState(route.getActivities().get(1), vehicle, + InternalStates.LATEST_OPERATION_START_TIME, Double.class), 0.01); } @Test - public void stateManagerShouldHaveMemorizedCorrectLatestEndOfAct2_v2(){ - assertEquals(60.,stateManager.getActivityState(route.getActivities().get(1),vehicle, - InternalStates.LATEST_OPERATION_START_TIME, Double.class),0.01); + public void stateManagerShouldHaveMemorizedCorrectLatestEndOfAct2_v2() { + assertEquals(60., stateManager.getActivityState(route.getActivities().get(1), vehicle, + InternalStates.LATEST_OPERATION_START_TIME, Double.class), 0.01); } @Test - public void stateManagerShouldHaveMemorizedCorrectLatestEndOfAct2WithVehicle2(){ - assertEquals(20.,stateManager.getActivityState(route.getActivities().get(1),vehicle2, - InternalStates.LATEST_OPERATION_START_TIME, Double.class),0.01); + public void stateManagerShouldHaveMemorizedCorrectLatestEndOfAct2WithVehicle2() { + assertEquals(20., stateManager.getActivityState(route.getActivities().get(1), vehicle2, + InternalStates.LATEST_OPERATION_START_TIME, Double.class), 0.01); } @Test - public void stateManagerShouldHaveMemorizedCorrectLatestEndOfAct2WithVehicle3(){ - assertEquals(80.,stateManager.getActivityState(route.getActivities().get(1),vehicle3, - InternalStates.LATEST_OPERATION_START_TIME, Double.class),0.01); + public void stateManagerShouldHaveMemorizedCorrectLatestEndOfAct2WithVehicle3() { + assertEquals(80., stateManager.getActivityState(route.getActivities().get(1), vehicle3, + InternalStates.LATEST_OPERATION_START_TIME, Double.class), 0.01); } @Test - public void stateManagerShouldHaveMemorizedCorrectLatestEndOfAct2WithEquivalentOfVehicle3(){ - assertEquals(80.,stateManager.getActivityState(route.getActivities().get(1),equivalentOf3, - InternalStates.LATEST_OPERATION_START_TIME, Double.class),0.01); + public void stateManagerShouldHaveMemorizedCorrectLatestEndOfAct2WithEquivalentOfVehicle3() { + assertEquals(80., stateManager.getActivityState(route.getActivities().get(1), equivalentOf3, + InternalStates.LATEST_OPERATION_START_TIME, Double.class), 0.01); } @Test - public void stateManagerShouldHaveMemorizedCorrectLatestEndOfAct1WithVehicle2(){ - assertEquals(10.,stateManager.getActivityState(route.getActivities().get(0),vehicle2, - InternalStates.LATEST_OPERATION_START_TIME, Double.class),0.01); + public void stateManagerShouldHaveMemorizedCorrectLatestEndOfAct1WithVehicle2() { + assertEquals(10., stateManager.getActivityState(route.getActivities().get(0), vehicle2, + InternalStates.LATEST_OPERATION_START_TIME, Double.class), 0.01); } @Test - public void stateManagerShouldHaveMemorizedCorrectLatestEndOfAct1WithVehicle3(){ - assertEquals(70.,stateManager.getActivityState(route.getActivities().get(0),vehicle3, - InternalStates.LATEST_OPERATION_START_TIME, Double.class),0.01); + public void stateManagerShouldHaveMemorizedCorrectLatestEndOfAct1WithVehicle3() { + assertEquals(70., stateManager.getActivityState(route.getActivities().get(0), vehicle3, + InternalStates.LATEST_OPERATION_START_TIME, Double.class), 0.01); } diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/termination/IterationsWithoutImprovementTest.java b/jsprit-core/src/test/java/jsprit/core/algorithm/termination/IterationsWithoutImprovementTest.java index 3c24051c..044bdd93 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/termination/IterationsWithoutImprovementTest.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/termination/IterationsWithoutImprovementTest.java @@ -11,51 +11,51 @@ import static org.mockito.Mockito.when; public class IterationsWithoutImprovementTest { @Test - public void itShouldTerminateAfter100(){ + public void itShouldTerminateAfter100() { IterationWithoutImprovementTermination termination = new IterationWithoutImprovementTermination(100); SearchStrategy.DiscoveredSolution discoveredSolution = mock(SearchStrategy.DiscoveredSolution.class); when(discoveredSolution.isAccepted()).thenReturn(false); int terminatedAfter = 0; - for(int i=0;i<200;i++){ + for (int i = 0; i < 200; i++) { boolean terminate = termination.isPrematureBreak(discoveredSolution); - if(terminate) { + if (terminate) { terminatedAfter = i; break; } } - Assert.assertEquals(100,terminatedAfter); + Assert.assertEquals(100, terminatedAfter); } @Test - public void itShouldTerminateAfter1(){ + public void itShouldTerminateAfter1() { IterationWithoutImprovementTermination termination = new IterationWithoutImprovementTermination(1); SearchStrategy.DiscoveredSolution discoveredSolution = mock(SearchStrategy.DiscoveredSolution.class); when(discoveredSolution.isAccepted()).thenReturn(false); int terminatedAfter = 0; - for(int i=0;i<200;i++){ + for (int i = 0; i < 200; i++) { boolean terminate = termination.isPrematureBreak(discoveredSolution); - if(terminate) { + if (terminate) { terminatedAfter = i; break; } } - Assert.assertEquals(1,terminatedAfter); + Assert.assertEquals(1, terminatedAfter); } @Test - public void itShouldTerminateAfter150(){ + public void itShouldTerminateAfter150() { IterationWithoutImprovementTermination termination = new IterationWithoutImprovementTermination(100); SearchStrategy.DiscoveredSolution discoveredSolution = mock(SearchStrategy.DiscoveredSolution.class); int terminatedAfter = 0; - for(int i=0;i<200;i++){ + for (int i = 0; i < 200; i++) { when(discoveredSolution.isAccepted()).thenReturn(false); - if(i == 49) when(discoveredSolution.isAccepted()).thenReturn(true); + if (i == 49) when(discoveredSolution.isAccepted()).thenReturn(true); boolean terminate = termination.isPrematureBreak(discoveredSolution); - if(terminate) { + if (terminate) { terminatedAfter = i; break; } } - Assert.assertEquals(150,terminatedAfter); + Assert.assertEquals(150, terminatedAfter); } } diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/termination/TimeTerminationTest.java b/jsprit-core/src/test/java/jsprit/core/algorithm/termination/TimeTerminationTest.java index 07c2bfd6..3c9fb015 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/termination/TimeTerminationTest.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/termination/TimeTerminationTest.java @@ -26,7 +26,7 @@ import org.junit.Test; public class TimeTerminationTest { @Test - public void whenTimeThreshold2000msAndCurrentTime0_itShouldNotBreak(){ + public void whenTimeThreshold2000msAndCurrentTime0_itShouldNotBreak() { long threshold = 2000; TimeTermination tt = new TimeTermination(threshold); tt.setTimeGetter(new TimeTermination.TimeGetter() { @@ -40,7 +40,7 @@ public class TimeTerminationTest { } @Test - public void whenTimeThreshold2000msAndCurrentTime2000ms_itShouldBreak(){ + public void whenTimeThreshold2000msAndCurrentTime2000ms_itShouldBreak() { long threshold = 2000; TimeTermination tt = new TimeTermination(threshold); tt.setTimeGetter(new TimeTermination.TimeGetter() { diff --git a/jsprit-core/src/test/java/jsprit/core/analysis/SolutionAnalyserTest.java b/jsprit-core/src/test/java/jsprit/core/analysis/SolutionAnalyserTest.java index 59f66383..1d1c3e4f 100644 --- a/jsprit-core/src/test/java/jsprit/core/analysis/SolutionAnalyserTest.java +++ b/jsprit-core/src/test/java/jsprit/core/analysis/SolutionAnalyserTest.java @@ -56,142 +56,142 @@ public class SolutionAnalyserTest { @Before - public void doBefore(){ + public void doBefore() { VehicleType type = VehicleTypeImpl.Builder.newInstance("type").setFixedCost(100.).setCostPerDistance(2.).addCapacityDimension(0, 15).build(); VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v1").setType(type) - .setStartLocation(Location.newInstance(-5, 0)) - .addSkill("skill1").addSkill("skill2") - .build(); + .setStartLocation(Location.newInstance(-5, 0)) + .addSkill("skill1").addSkill("skill2") + .build(); VehicleImpl vehicle2 = VehicleImpl.Builder.newInstance("v2").setType(type) - .setStartLocation(Location.newInstance(5, 0)).build(); + .setStartLocation(Location.newInstance(5, 0)).build(); Service s1 = Service.Builder.newInstance("s1") - .setTimeWindow(TimeWindow.newInstance(10, 20)) - .setLocation(Location.newInstance(-10, 1)).addSizeDimension(0, 2) - .addRequiredSkill("skill1") - .build(); + .setTimeWindow(TimeWindow.newInstance(10, 20)) + .setLocation(Location.newInstance(-10, 1)).addSizeDimension(0, 2) + .addRequiredSkill("skill1") + .build(); Service s2 = Service.Builder.newInstance("s2") - .setLocation(Location.newInstance(-10, 10)) - .addSizeDimension(0,3) - .addRequiredSkill("skill2").addRequiredSkill("skill1") - .build(); + .setLocation(Location.newInstance(-10, 10)) + .addSizeDimension(0, 3) + .addRequiredSkill("skill2").addRequiredSkill("skill1") + .build(); Shipment shipment1 = Shipment.Builder.newInstance("ship1") - .setPickupLocation(TestUtils.loc(Coordinate.newInstance(-15, 2))) - .setDeliveryLocation(TestUtils.loc(Coordinate.newInstance(-16, 5))) - .addSizeDimension(0,10) - .setPickupServiceTime(20.) - .setDeliveryServiceTime(20.) - .addRequiredSkill("skill3") - .build(); + .setPickupLocation(TestUtils.loc(Coordinate.newInstance(-15, 2))) + .setDeliveryLocation(TestUtils.loc(Coordinate.newInstance(-16, 5))) + .addSizeDimension(0, 10) + .setPickupServiceTime(20.) + .setDeliveryServiceTime(20.) + .addRequiredSkill("skill3") + .build(); Service s3 = Service.Builder.newInstance("s3") - .setTimeWindow(TimeWindow.newInstance(10, 20)) - .setLocation(TestUtils.loc(Coordinate.newInstance(10, 1))).addSizeDimension(0, 2).build(); - Service s4 = Service.Builder.newInstance("s4").setLocation(TestUtils.loc(Coordinate.newInstance(10, 10))).addSizeDimension(0,3).build(); + .setTimeWindow(TimeWindow.newInstance(10, 20)) + .setLocation(TestUtils.loc(Coordinate.newInstance(10, 1))).addSizeDimension(0, 2).build(); + Service s4 = Service.Builder.newInstance("s4").setLocation(TestUtils.loc(Coordinate.newInstance(10, 10))).addSizeDimension(0, 3).build(); Shipment shipment2 = Shipment.Builder.newInstance("ship2").setPickupLocation(TestUtils.loc(Coordinate.newInstance(15, 2))) - .setPickupServiceTime(20.).setDeliveryServiceTime(20.) - .setDeliveryLocation(TestUtils.loc(Coordinate.newInstance(16, 5))).addSizeDimension(0, 10).build(); - + .setPickupServiceTime(20.).setDeliveryServiceTime(20.) + .setDeliveryLocation(TestUtils.loc(Coordinate.newInstance(16, 5))).addSizeDimension(0, 10).build(); + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance().addVehicle(vehicle) - .addVehicle(vehicle2) - .addJob(s1) - .addJob(s2).addJob(shipment1).addJob(s3).addJob(s4).addJob(shipment2).setFleetSize(VehicleRoutingProblem.FleetSize.FINITE); + .addVehicle(vehicle2) + .addJob(s1) + .addJob(s2).addJob(shipment1).addJob(s3).addJob(s4).addJob(shipment2).setFleetSize(VehicleRoutingProblem.FleetSize.INFINITE); vrpBuilder.setRoutingCost(new ManhattanCosts(vrpBuilder.getLocations())); vrp = vrpBuilder.build(); VehicleRoute route1 = VehicleRoute.Builder.newInstance(vehicle).setJobActivityFactory(vrp.getJobActivityFactory()) - .addService(s1).addPickup(shipment1).addDelivery(shipment1).addService(s2).build(); + .addService(s1).addPickup(shipment1).addDelivery(shipment1).addService(s2).build(); VehicleRoute route2 = VehicleRoute.Builder.newInstance(vehicle).setJobActivityFactory(vrp.getJobActivityFactory()) - .addService(s3).addPickup(shipment2).addDelivery(shipment2).addService(s4).build(); + .addService(s3).addPickup(shipment2).addDelivery(shipment2).addService(s4).build(); - solution = new VehicleRoutingProblemSolution(Arrays.asList(route1,route2),42); + solution = new VehicleRoutingProblemSolution(Arrays.asList(route1, route2), 42); } - - public void buildAnotherScenarioWithOnlyOneVehicleAndWithoutAnyConstraintsBefore(){ + + public void buildAnotherScenarioWithOnlyOneVehicleAndWithoutAnyConstraintsBefore() { VehicleType type = VehicleTypeImpl.Builder.newInstance("type").setFixedCost(100.).setCostPerDistance(2.).addCapacityDimension(0, 15).build(); VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v1").setType(type) - .setStartLocation(Location.newInstance(-5, 0)) - .setLatestArrival(150.) - .build(); + .setStartLocation(Location.newInstance(-5, 0)) + .setLatestArrival(150.) + .build(); Pickup s1 = (Pickup) Pickup.Builder.newInstance("s1") - .setTimeWindow(TimeWindow.newInstance(10, 20)) - .setLocation(Location.newInstance(-10, 1)) - .addSizeDimension(0, 10) - .build(); + .setTimeWindow(TimeWindow.newInstance(10, 20)) + .setLocation(Location.newInstance(-10, 1)) + .addSizeDimension(0, 10) + .build(); Delivery s2 = (Delivery) Delivery.Builder.newInstance("s2") - .setLocation(Location.newInstance(-10, 10)) - .setTimeWindow(TimeWindow.newInstance(10, 20)) - .addSizeDimension(0, 20) - .build(); + .setLocation(Location.newInstance(-10, 10)) + .setTimeWindow(TimeWindow.newInstance(10, 20)) + .addSizeDimension(0, 20) + .build(); Shipment shipment1 = Shipment.Builder.newInstance("ship1").setPickupLocation(TestUtils.loc(Coordinate.newInstance(-15, 2))) - .setDeliveryLocation(TestUtils.loc(Coordinate.newInstance(-16, 5))) - .addSizeDimension(0, 15) - .setPickupServiceTime(20.).setDeliveryServiceTime(20.) - .setPickupTimeWindow(TimeWindow.newInstance(10, 20)).setDeliveryTimeWindow(TimeWindow.newInstance(10, 20)) - .build(); + .setDeliveryLocation(TestUtils.loc(Coordinate.newInstance(-16, 5))) + .addSizeDimension(0, 15) + .setPickupServiceTime(20.).setDeliveryServiceTime(20.) + .setPickupTimeWindow(TimeWindow.newInstance(10, 20)).setDeliveryTimeWindow(TimeWindow.newInstance(10, 20)) + .build(); Pickup s3 = (Pickup) Pickup.Builder.newInstance("s3") - .setTimeWindow(TimeWindow.newInstance(10, 20)) - .setLocation(TestUtils.loc(Coordinate.newInstance(10, 1))) - .addSizeDimension(0, 10) - .build(); + .setTimeWindow(TimeWindow.newInstance(10, 20)) + .setLocation(TestUtils.loc(Coordinate.newInstance(10, 1))) + .addSizeDimension(0, 10) + .build(); Delivery s4 = (Delivery) Delivery.Builder.newInstance("s4").setLocation(Location.newInstance(10, 10)) - .addSizeDimension(0, 20) - .setTimeWindow(TimeWindow.newInstance(10, 20)) - .build(); + .addSizeDimension(0, 20) + .setTimeWindow(TimeWindow.newInstance(10, 20)) + .build(); Shipment shipment2 = Shipment.Builder.newInstance("ship2").setPickupLocation(TestUtils.loc(Coordinate.newInstance(15, 2))) - .setPickupServiceTime(20.).setDeliveryServiceTime(20.) - .setDeliveryLocation(TestUtils.loc(Coordinate.newInstance(16, 5))) - .setPickupTimeWindow(TimeWindow.newInstance(10, 20)).setDeliveryTimeWindow(TimeWindow.newInstance(10, 20)) - .addSizeDimension(0, 15).build(); + .setPickupServiceTime(20.).setDeliveryServiceTime(20.) + .setDeliveryLocation(TestUtils.loc(Coordinate.newInstance(16, 5))) + .setPickupTimeWindow(TimeWindow.newInstance(10, 20)).setDeliveryTimeWindow(TimeWindow.newInstance(10, 20)) + .addSizeDimension(0, 15).build(); VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance().addVehicle(vehicle) - .addJob(s1) - .addJob(s2).addJob(shipment1).addJob(s3).addJob(s4).addJob(shipment2).setFleetSize(VehicleRoutingProblem.FleetSize.FINITE); + .addJob(s1) + .addJob(s2).addJob(shipment1).addJob(s3).addJob(s4).addJob(shipment2).setFleetSize(VehicleRoutingProblem.FleetSize.FINITE); vrpBuilder.setRoutingCost(new ManhattanCosts(vrpBuilder.getLocations())); vrp = vrpBuilder.build(); VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle).setJobActivityFactory(vrp.getJobActivityFactory()) - .addPickup(s3) - .addPickup(shipment2).addDelivery(shipment2) - .addDelivery(s4) - .addDelivery(s2) - .addPickup(shipment1).addDelivery(shipment1) - .addPickup(s1) - .build(); + .addPickup(s3) + .addPickup(shipment2).addDelivery(shipment2) + .addDelivery(s4) + .addDelivery(s2) + .addPickup(shipment1).addDelivery(shipment1) + .addPickup(s1) + .build(); - solution = new VehicleRoutingProblemSolution(Arrays.asList(route),300); + solution = new VehicleRoutingProblemSolution(Arrays.asList(route), 300); } /** * Test the last transport costs at an activity are correct. */ @Test - public void lastTransportCostsOfRoute1ShouldWork(){ + public void lastTransportCostsOfRoute1ShouldWork() { testTransportCosts(TransportCostsTestType.LAST_COST); } - + /** * Test the last transport distance at an activity are correct. */ @Test - public void lastTransportDistanceOfRoute1ShouldWork(){ + public void lastTransportDistanceOfRoute1ShouldWork() { testTransportCosts(TransportCostsTestType.LAST_DISTANCE); } - - + + /** * Test the last transport time at an activity are correct. */ @Test - public void lastTransportTimeOfRoute1ShouldWork(){ + public void lastTransportTimeOfRoute1ShouldWork() { testTransportCosts(TransportCostsTestType.LAST_TIME); } @@ -199,118 +199,119 @@ public class SolutionAnalyserTest { * Test the last transport time at an activity are correct. */ @Test - public void transportTimeAtActivityOfRoute1ShouldWork(){ + public void transportTimeAtActivityOfRoute1ShouldWork() { testTransportCosts(TransportCostsTestType.TRANSPORT_TIME_AT_ACTIVITY); } - private enum TransportCostsTestType{ - LAST_COST, - LAST_TIME, - LAST_DISTANCE, - TRANSPORT_TIME_AT_ACTIVITY, + private enum TransportCostsTestType { + LAST_COST, + LAST_TIME, + LAST_DISTANCE, + TRANSPORT_TIME_AT_ACTIVITY, } /** * Run multiple different tests for transport costs + * * @param type */ - private void testTransportCosts(TransportCostsTestType type) { - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + private void testTransportCosts(TransportCostsTestType type) { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location fromLocationId, Location toLocationId) { - return vrp.getTransportCosts().getTransportCost(fromLocationId,toLocationId,0.,null,null); + return vrp.getTransportCosts().getTransportCost(fromLocationId, toLocationId, 0., null, null); } }); - + // this should be the path taken by route 1 including depots - Coordinate [] route1Path = new Coordinate[]{ - Coordinate.newInstance(-5, 0), - Coordinate.newInstance(-10, 1), - Coordinate.newInstance(-15, 2), - Coordinate.newInstance(-16, 5), - Coordinate.newInstance(-10, 10), - Coordinate.newInstance(-5, 0) - + Coordinate[] route1Path = new Coordinate[]{ + Coordinate.newInstance(-5, 0), + Coordinate.newInstance(-10, 1), + Coordinate.newInstance(-15, 2), + Coordinate.newInstance(-16, 5), + Coordinate.newInstance(-10, 10), + Coordinate.newInstance(-5, 0) + }; - + VehicleRoute route1 = solution.getRoutes().iterator().next(); - + // get route 1 activities List activities = route1.getActivities(); Assert.assertEquals(activities.size(), 4); - + // utility class to calculate manhattan distance - class ManhattanDistance{ - private double calc(Coordinate from , Coordinate to) { - return Math.abs(from.getX() - to.getX()) - + Math.abs(from.getY() - to.getY()); - } + class ManhattanDistance { + private double calc(Coordinate from, Coordinate to) { + return Math.abs(from.getX() - to.getX()) + + Math.abs(from.getY() - to.getY()); + } } ManhattanDistance md = new ManhattanDistance(); - + // loop over all activities on route and do tests - double totalTime=0; - for(int i = 0 ; i < activities.size() ; i++){ - TourActivity activity = activities.get(i); - Coordinate last = route1Path[i]; - Coordinate current = route1Path[i+1]; + double totalTime = 0; + for (int i = 0; i < activities.size(); i++) { + TourActivity activity = activities.get(i); + Coordinate last = route1Path[i]; + Coordinate current = route1Path[i + 1]; - // calculate last distance and time (Manhattan uses speed = 1 so distance = time) - double dist = md.calc(last, current); - double time =dist; - - // test last distance - if(type == TransportCostsTestType.LAST_DISTANCE){ - double savedDist = analyser.getLastTransportDistanceAtActivity(activity, route1); - Assert.assertEquals(dist, savedDist, 1E-10); - } - - // test last time - if(type == TransportCostsTestType.LAST_TIME){ - double savedTime = analyser.getLastTransportTimeAtActivity(activity, route1); - Assert.assertEquals(time, savedTime, 1E-10); - } + // calculate last distance and time (Manhattan uses speed = 1 so distance = time) + double dist = md.calc(last, current); + double time = dist; - // test last cost - if(type == TransportCostsTestType.LAST_COST){ - double perDistanceUnit=1; - Vehicle vehicle = route1.getVehicle(); - if(vehicle != null){ - if(vehicle.getType() != null){ - perDistanceUnit = vehicle.getType().getVehicleCostParams().perDistanceUnit; + // test last distance + if (type == TransportCostsTestType.LAST_DISTANCE) { + double savedDist = analyser.getLastTransportDistanceAtActivity(activity, route1); + Assert.assertEquals(dist, savedDist, 1E-10); + } + + // test last time + if (type == TransportCostsTestType.LAST_TIME) { + double savedTime = analyser.getLastTransportTimeAtActivity(activity, route1); + Assert.assertEquals(time, savedTime, 1E-10); + } + + // test last cost + if (type == TransportCostsTestType.LAST_COST) { + double perDistanceUnit = 1; + Vehicle vehicle = route1.getVehicle(); + if (vehicle != null) { + if (vehicle.getType() != null) { + perDistanceUnit = vehicle.getType().getVehicleCostParams().perDistanceUnit; } } - double cost =dist * perDistanceUnit; + double cost = dist * perDistanceUnit; double savedCost = analyser.getLastTransportCostAtActivity(activity, route1); - Assert.assertEquals(cost, savedCost, 1E-10); - } - - // test total transport time at activity - if(type == TransportCostsTestType.TRANSPORT_TIME_AT_ACTIVITY){ - totalTime += time; - double savedTransportTime = analyser.getTransportTimeAtActivity(activity, route1); - Assert.assertEquals(totalTime, savedTransportTime, 1E-10); - } + Assert.assertEquals(cost, savedCost, 1E-10); + } + + // test total transport time at activity + if (type == TransportCostsTestType.TRANSPORT_TIME_AT_ACTIVITY) { + totalTime += time; + double savedTransportTime = analyser.getTransportTimeAtActivity(activity, route1); + Assert.assertEquals(totalTime, savedTransportTime, 1E-10); + } } - } - + } + @Test - public void constructionShouldWork(){ - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + public void constructionShouldWork() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); Assert.assertTrue(true); } @Test - public void loadAtBeginningOfRoute1ShouldWork(){ - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + public void loadAtBeginningOfRoute1ShouldWork() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); VehicleRoute route = solution.getRoutes().iterator().next(); @@ -318,11 +319,11 @@ public class SolutionAnalyserTest { } @Test - public void loadAtBeginningOfRoute2ShouldWork(){ - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + public void loadAtBeginningOfRoute2ShouldWork() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); Iterator iterator = solution.getRoutes().iterator(); @@ -333,11 +334,11 @@ public class SolutionAnalyserTest { } @Test - public void loadAtEnd_OfRoute1ShouldWork(){ - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + public void loadAtEnd_OfRoute1ShouldWork() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); VehicleRoute route = solution.getRoutes().iterator().next(); @@ -345,11 +346,11 @@ public class SolutionAnalyserTest { } @Test - public void loadAtEnd_OfRoute2ShouldWork(){ - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + public void loadAtEnd_OfRoute2ShouldWork() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); Iterator iterator = solution.getRoutes().iterator(); @@ -360,11 +361,11 @@ public class SolutionAnalyserTest { } @Test - public void loadAfterActivity_ofStartActOfRoute1ShouldWork(){ - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + public void loadAfterActivity_ofStartActOfRoute1ShouldWork() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); VehicleRoute route = solution.getRoutes().iterator().next(); @@ -372,11 +373,11 @@ public class SolutionAnalyserTest { } @Test - public void loadAfterActivity_ofAct1ofRoute1ShouldWork(){ - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + public void loadAfterActivity_ofAct1ofRoute1ShouldWork() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); VehicleRoute route = solution.getRoutes().iterator().next(); @@ -384,11 +385,11 @@ public class SolutionAnalyserTest { } @Test - public void loadAfterActivity_ofAct2ofRoute1ShouldWork(){ - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + public void loadAfterActivity_ofAct2ofRoute1ShouldWork() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); VehicleRoute route = solution.getRoutes().iterator().next(); @@ -396,11 +397,11 @@ public class SolutionAnalyserTest { } @Test - public void loadAfterActivity_ofAct3ofRoute1ShouldWork(){ - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + public void loadAfterActivity_ofAct3ofRoute1ShouldWork() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); VehicleRoute route = solution.getRoutes().iterator().next(); @@ -408,11 +409,11 @@ public class SolutionAnalyserTest { } @Test - public void loadAfterActivity_ofAct4ofRoute1ShouldWork(){ - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + public void loadAfterActivity_ofAct4ofRoute1ShouldWork() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); VehicleRoute route = solution.getRoutes().iterator().next(); @@ -420,11 +421,11 @@ public class SolutionAnalyserTest { } @Test - public void loadAfterActivity_ofEndActOfRoute1ShouldWork(){ - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + public void loadAfterActivity_ofEndActOfRoute1ShouldWork() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); VehicleRoute route = solution.getRoutes().iterator().next(); @@ -432,11 +433,11 @@ public class SolutionAnalyserTest { } @Test - public void loadBeforeActivity_ofStartActOfRoute1ShouldWork(){ - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + public void loadBeforeActivity_ofStartActOfRoute1ShouldWork() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); VehicleRoute route = solution.getRoutes().iterator().next(); @@ -444,11 +445,11 @@ public class SolutionAnalyserTest { } @Test - public void loadBeforeActivity_ofAct1ofRoute1ShouldWork(){ - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + public void loadBeforeActivity_ofAct1ofRoute1ShouldWork() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); VehicleRoute route = solution.getRoutes().iterator().next(); @@ -456,11 +457,11 @@ public class SolutionAnalyserTest { } @Test - public void loadBeforeActivity_ofAct2ofRoute1ShouldWork(){ - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + public void loadBeforeActivity_ofAct2ofRoute1ShouldWork() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); VehicleRoute route = solution.getRoutes().iterator().next(); @@ -468,11 +469,11 @@ public class SolutionAnalyserTest { } @Test - public void loadBeforeActivity_ofAct3ofRoute1ShouldWork(){ - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + public void loadBeforeActivity_ofAct3ofRoute1ShouldWork() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); VehicleRoute route = solution.getRoutes().iterator().next(); @@ -480,11 +481,11 @@ public class SolutionAnalyserTest { } @Test - public void loadBeforeActivity_ofAct4ofRoute1ShouldWork(){ - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + public void loadBeforeActivity_ofAct4ofRoute1ShouldWork() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); VehicleRoute route = solution.getRoutes().iterator().next(); @@ -492,11 +493,11 @@ public class SolutionAnalyserTest { } @Test - public void loadBeforeActivity_ofEndActOfRoute1ShouldWork(){ - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + public void loadBeforeActivity_ofEndActOfRoute1ShouldWork() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); VehicleRoute route = solution.getRoutes().iterator().next(); @@ -504,11 +505,11 @@ public class SolutionAnalyserTest { } @Test - public void maxLoad_OfRoute1ShouldWork(){ - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + public void maxLoad_OfRoute1ShouldWork() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); VehicleRoute route = solution.getRoutes().iterator().next(); @@ -516,11 +517,11 @@ public class SolutionAnalyserTest { } @Test - public void pickupCount_OfRoute1ShouldWork(){ - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + public void pickupCount_OfRoute1ShouldWork() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); VehicleRoute route = solution.getRoutes().iterator().next(); @@ -528,11 +529,11 @@ public class SolutionAnalyserTest { } @Test - public void pickupCountAtBeginning_OfRoute1ShouldWork(){ - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + public void pickupCountAtBeginning_OfRoute1ShouldWork() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); VehicleRoute route = solution.getRoutes().iterator().next(); @@ -540,12 +541,12 @@ public class SolutionAnalyserTest { } @Test - public void pickupCount_OfRoute1OfAnotherSolutionShouldWork(){ + public void pickupCount_OfRoute1OfAnotherSolutionShouldWork() { buildAnotherScenarioWithOnlyOneVehicleAndWithoutAnyConstraintsBefore(); - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); VehicleRoute route = solution.getRoutes().iterator().next(); @@ -553,12 +554,12 @@ public class SolutionAnalyserTest { } @Test - public void pickupCountAtBeginning_OfRoute1OfAnotherSolutionShouldWork(){ + public void pickupCountAtBeginning_OfRoute1OfAnotherSolutionShouldWork() { buildAnotherScenarioWithOnlyOneVehicleAndWithoutAnyConstraintsBefore(); - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); VehicleRoute route = solution.getRoutes().iterator().next(); @@ -566,57 +567,57 @@ public class SolutionAnalyserTest { } @Test - public void pickupCount_onSolutionShouldWork(){ - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + public void pickupCount_onSolutionShouldWork() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); Assert.assertEquals(6, analyser.getNumberOfPickups(), 0.01); } @Test - public void pickupCountAtBeginning_onSolutionShouldWork(){ - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + public void pickupCountAtBeginning_onSolutionShouldWork() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); Assert.assertEquals(0, analyser.getNumberOfPickupsAtBeginning(), 0.01); } @Test - public void pickupCount_onAnotherSolutionShouldWork(){ + public void pickupCount_onAnotherSolutionShouldWork() { buildAnotherScenarioWithOnlyOneVehicleAndWithoutAnyConstraintsBefore(); - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); Assert.assertEquals(4, analyser.getNumberOfPickups(), 0.01); } @Test - public void pickupCountAtBeginning_onAnotherSolutionShouldWork(){ + public void pickupCountAtBeginning_onAnotherSolutionShouldWork() { buildAnotherScenarioWithOnlyOneVehicleAndWithoutAnyConstraintsBefore(); - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); Assert.assertEquals(2, analyser.getNumberOfPickupsAtBeginning(), 0.01); } @Test - public void pickupLoad_OfRoute1ShouldWork(){ - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + public void pickupLoad_OfRoute1ShouldWork() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); VehicleRoute route = solution.getRoutes().iterator().next(); @@ -624,11 +625,11 @@ public class SolutionAnalyserTest { } @Test - public void pickupLoadAtBeginning_OfRoute1ShouldWork(){ - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + public void pickupLoadAtBeginning_OfRoute1ShouldWork() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); VehicleRoute route = solution.getRoutes().iterator().next(); @@ -636,12 +637,12 @@ public class SolutionAnalyserTest { } @Test - public void pickupLoad_OfRoute1OfAnotherShouldWork(){ + public void pickupLoad_OfRoute1OfAnotherShouldWork() { buildAnotherScenarioWithOnlyOneVehicleAndWithoutAnyConstraintsBefore(); - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); VehicleRoute route = solution.getRoutes().iterator().next(); @@ -649,12 +650,12 @@ public class SolutionAnalyserTest { } @Test - public void pickupLoadAtBeginning_OfRoute1OfAnotherShouldWork(){ + public void pickupLoadAtBeginning_OfRoute1OfAnotherShouldWork() { buildAnotherScenarioWithOnlyOneVehicleAndWithoutAnyConstraintsBefore(); - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); VehicleRoute route = solution.getRoutes().iterator().next(); @@ -662,57 +663,57 @@ public class SolutionAnalyserTest { } @Test - public void pickupLoad_onSolutionShouldWork(){ - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + public void pickupLoad_onSolutionShouldWork() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); Assert.assertEquals(30, analyser.getLoadPickedUp().get(0), 0.01); } @Test - public void pickupLoadAtBeginning_onSolutionShouldWork(){ - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + public void pickupLoadAtBeginning_onSolutionShouldWork() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); Assert.assertEquals(0, analyser.getLoadAtBeginning().get(0), 0.01); } @Test - public void pickupLoad_onAnotherSolutionShouldWork(){ + public void pickupLoad_onAnotherSolutionShouldWork() { buildAnotherScenarioWithOnlyOneVehicleAndWithoutAnyConstraintsBefore(); - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); Assert.assertEquals(50, analyser.getLoadPickedUp().get(0), 0.01); } @Test - public void pickupLoadAtBeginning_onAnotherSolutionShouldWork(){ + public void pickupLoadAtBeginning_onAnotherSolutionShouldWork() { buildAnotherScenarioWithOnlyOneVehicleAndWithoutAnyConstraintsBefore(); - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); Assert.assertEquals(40, analyser.getLoadAtBeginning().get(0), 0.01); } @Test - public void deliveryCount_OfRoute1ShouldWork(){ - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + public void deliveryCount_OfRoute1ShouldWork() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); VehicleRoute route = solution.getRoutes().iterator().next(); @@ -720,11 +721,11 @@ public class SolutionAnalyserTest { } @Test - public void deliveryCountAtEnd_OfRoute1ShouldWork(){ - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + public void deliveryCountAtEnd_OfRoute1ShouldWork() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); VehicleRoute route = solution.getRoutes().iterator().next(); @@ -732,12 +733,12 @@ public class SolutionAnalyserTest { } @Test - public void deliveryCount_OfRoute1OfAnotherSolutionShouldWork(){ + public void deliveryCount_OfRoute1OfAnotherSolutionShouldWork() { buildAnotherScenarioWithOnlyOneVehicleAndWithoutAnyConstraintsBefore(); - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); VehicleRoute route = solution.getRoutes().iterator().next(); @@ -745,12 +746,12 @@ public class SolutionAnalyserTest { } @Test - public void deliveryCountAtEnd_OfRoute1OfAnotherSolutionShouldWork(){ + public void deliveryCountAtEnd_OfRoute1OfAnotherSolutionShouldWork() { buildAnotherScenarioWithOnlyOneVehicleAndWithoutAnyConstraintsBefore(); - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); VehicleRoute route = solution.getRoutes().iterator().next(); @@ -758,57 +759,57 @@ public class SolutionAnalyserTest { } @Test - public void deliveryCount_onSolutionShouldWork(){ - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + public void deliveryCount_onSolutionShouldWork() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); Assert.assertEquals(2, analyser.getNumberOfDeliveries(), 0.01); } @Test - public void deliveryCountAtEnd_onSolutionShouldWork(){ - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + public void deliveryCountAtEnd_onSolutionShouldWork() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); Assert.assertEquals(4, analyser.getNumberOfDeliveriesAtEnd(), 0.01); } @Test - public void deliveryCount_onAnotherSolutionShouldWork(){ + public void deliveryCount_onAnotherSolutionShouldWork() { buildAnotherScenarioWithOnlyOneVehicleAndWithoutAnyConstraintsBefore(); - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); Assert.assertEquals(4, analyser.getNumberOfDeliveries(), 0.01); } @Test - public void deliveryCountAtEnd_onAnotherSolutionShouldWork(){ + public void deliveryCountAtEnd_onAnotherSolutionShouldWork() { buildAnotherScenarioWithOnlyOneVehicleAndWithoutAnyConstraintsBefore(); - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); Assert.assertEquals(2, analyser.getNumberOfDeliveriesAtEnd(), 0.01); } @Test - public void deliveryLoad_OfRoute1ShouldWork(){ - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + public void deliveryLoad_OfRoute1ShouldWork() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); VehicleRoute route = solution.getRoutes().iterator().next(); @@ -816,11 +817,11 @@ public class SolutionAnalyserTest { } @Test - public void deliveryLoadAtEnd_OfRoute1ShouldWork(){ - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + public void deliveryLoadAtEnd_OfRoute1ShouldWork() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); VehicleRoute route = solution.getRoutes().iterator().next(); @@ -828,12 +829,12 @@ public class SolutionAnalyserTest { } @Test - public void deliveryLoad_OfRoute1OfAnotherSolutionShouldWork(){ + public void deliveryLoad_OfRoute1OfAnotherSolutionShouldWork() { buildAnotherScenarioWithOnlyOneVehicleAndWithoutAnyConstraintsBefore(); - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); VehicleRoute route = solution.getRoutes().iterator().next(); @@ -841,12 +842,12 @@ public class SolutionAnalyserTest { } @Test - public void deliveryLoadAtEnd_OfRoute1OfAnotherSolutionShouldWork(){ + public void deliveryLoadAtEnd_OfRoute1OfAnotherSolutionShouldWork() { buildAnotherScenarioWithOnlyOneVehicleAndWithoutAnyConstraintsBefore(); - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); VehicleRoute route = solution.getRoutes().iterator().next(); @@ -854,34 +855,34 @@ public class SolutionAnalyserTest { } @Test - public void deliveryLoad_onSolutionShouldWork(){ - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + public void deliveryLoad_onSolutionShouldWork() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); Assert.assertEquals(20, analyser.getLoadDelivered().get(0), 0.01); } @Test - public void deliveryLoadAtEnd_onSolutionShouldWork(){ - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + public void deliveryLoadAtEnd_onSolutionShouldWork() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); Assert.assertEquals(10, analyser.getLoadAtEnd().get(0), 0.01); } @Test - public void deliveryLoad_onAnotherSolutionShouldWork(){ + public void deliveryLoad_onAnotherSolutionShouldWork() { buildAnotherScenarioWithOnlyOneVehicleAndWithoutAnyConstraintsBefore(); - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); VehicleRoute route = solution.getRoutes().iterator().next(); @@ -889,23 +890,23 @@ public class SolutionAnalyserTest { } @Test - public void deliveryLoadAtEnd_onAnotherSolutionShouldWork(){ + public void deliveryLoadAtEnd_onAnotherSolutionShouldWork() { buildAnotherScenarioWithOnlyOneVehicleAndWithoutAnyConstraintsBefore(); - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); Assert.assertEquals(20, analyser.getLoadAtEnd().get(0), 0.01); } @Test - public void operationTime_OfRoute1ShouldWork(){ - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + public void operationTime_OfRoute1ShouldWork() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); VehicleRoute route = solution.getRoutes().iterator().next(); @@ -913,11 +914,11 @@ public class SolutionAnalyserTest { } @Test - public void waitingTime_OfRoute1ShouldWork(){ - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + public void waitingTime_OfRoute1ShouldWork() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); VehicleRoute route = solution.getRoutes().iterator().next(); @@ -925,11 +926,11 @@ public class SolutionAnalyserTest { } @Test - public void transportTime_OfRoute1ShouldWork(){ - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + public void transportTime_OfRoute1ShouldWork() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); VehicleRoute route = solution.getRoutes().iterator().next(); @@ -937,11 +938,11 @@ public class SolutionAnalyserTest { } @Test - public void serviceTime_OfRoute1ShouldWork(){ - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + public void serviceTime_OfRoute1ShouldWork() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); VehicleRoute route = solution.getRoutes().iterator().next(); @@ -949,11 +950,11 @@ public class SolutionAnalyserTest { } @Test - public void distance_OfRoute1ShouldWork(){ - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + public void distance_OfRoute1ShouldWork() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); VehicleRoute route = solution.getRoutes().iterator().next(); @@ -961,11 +962,11 @@ public class SolutionAnalyserTest { } @Test - public void waitingTime_atStartActOfRoute1ShouldWork(){ - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + public void waitingTime_atStartActOfRoute1ShouldWork() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); VehicleRoute route = solution.getRoutes().iterator().next(); @@ -973,11 +974,11 @@ public class SolutionAnalyserTest { } @Test - public void waitingTime_ofAct1ofRoute1ShouldWork(){ - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + public void waitingTime_ofAct1ofRoute1ShouldWork() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); VehicleRoute route = solution.getRoutes().iterator().next(); @@ -985,11 +986,11 @@ public class SolutionAnalyserTest { } @Test - public void waitingTime_ofAct2ofRoute1ShouldWork(){ - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + public void waitingTime_ofAct2ofRoute1ShouldWork() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); VehicleRoute route = solution.getRoutes().iterator().next(); @@ -997,11 +998,11 @@ public class SolutionAnalyserTest { } @Test - public void waitingTime_ofAct3ofRoute1ShouldWork(){ - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + public void waitingTime_ofAct3ofRoute1ShouldWork() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); VehicleRoute route = solution.getRoutes().iterator().next(); @@ -1009,11 +1010,11 @@ public class SolutionAnalyserTest { } @Test - public void waitingTime_ofAct4ofRoute1ShouldWork(){ - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + public void waitingTime_ofAct4ofRoute1ShouldWork() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); VehicleRoute route = solution.getRoutes().iterator().next(); @@ -1021,11 +1022,11 @@ public class SolutionAnalyserTest { } @Test - public void waitingTime_ofEndActOfRoute1ShouldWork(){ - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + public void waitingTime_ofEndActOfRoute1ShouldWork() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); VehicleRoute route = solution.getRoutes().iterator().next(); @@ -1033,11 +1034,11 @@ public class SolutionAnalyserTest { } @Test - public void distance_atStartActOfRoute1ShouldWork(){ - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + public void distance_atStartActOfRoute1ShouldWork() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); VehicleRoute route = solution.getRoutes().iterator().next(); @@ -1045,11 +1046,11 @@ public class SolutionAnalyserTest { } @Test - public void distance_ofAct1ofRoute1ShouldWork(){ - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + public void distance_ofAct1ofRoute1ShouldWork() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); VehicleRoute route = solution.getRoutes().iterator().next(); @@ -1057,11 +1058,11 @@ public class SolutionAnalyserTest { } @Test - public void distance_ofAct2ofRoute1ShouldWork(){ - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + public void distance_ofAct2ofRoute1ShouldWork() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); VehicleRoute route = solution.getRoutes().iterator().next(); @@ -1069,11 +1070,11 @@ public class SolutionAnalyserTest { } @Test - public void distance_ofAct3ofRoute1ShouldWork(){ - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + public void distance_ofAct3ofRoute1ShouldWork() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); VehicleRoute route = solution.getRoutes().iterator().next(); @@ -1081,11 +1082,11 @@ public class SolutionAnalyserTest { } @Test - public void distance_ofAct4ofRoute1ShouldWork(){ - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + public void distance_ofAct4ofRoute1ShouldWork() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); VehicleRoute route = solution.getRoutes().iterator().next(); @@ -1093,11 +1094,11 @@ public class SolutionAnalyserTest { } @Test - public void distance_ofEndActOfRoute1ShouldWork(){ - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + public void distance_ofEndActOfRoute1ShouldWork() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); VehicleRoute route = solution.getRoutes().iterator().next(); @@ -1106,11 +1107,11 @@ public class SolutionAnalyserTest { @Test - public void lateArrivalTimes_atStartActOfRoute1ShouldWork(){ - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + public void lateArrivalTimes_atStartActOfRoute1ShouldWork() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); VehicleRoute route = solution.getRoutes().iterator().next(); @@ -1118,11 +1119,11 @@ public class SolutionAnalyserTest { } @Test - public void lateArrivalTimes_ofAct1ofRoute1ShouldWork(){ - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + public void lateArrivalTimes_ofAct1ofRoute1ShouldWork() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); VehicleRoute route = solution.getRoutes().iterator().next(); @@ -1130,11 +1131,11 @@ public class SolutionAnalyserTest { } @Test - public void lateArrivalTimes_ofAct2ofRoute1ShouldWork(){ - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + public void lateArrivalTimes_ofAct2ofRoute1ShouldWork() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); VehicleRoute route = solution.getRoutes().iterator().next(); @@ -1142,11 +1143,11 @@ public class SolutionAnalyserTest { } @Test - public void lateArrivalTimes_ofAct3ofRoute1ShouldWork(){ - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + public void lateArrivalTimes_ofAct3ofRoute1ShouldWork() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); VehicleRoute route = solution.getRoutes().iterator().next(); @@ -1154,11 +1155,11 @@ public class SolutionAnalyserTest { } @Test - public void lateArrivalTimes_ofAct4ofRoute1ShouldWork(){ - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + public void lateArrivalTimes_ofAct4ofRoute1ShouldWork() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); VehicleRoute route = solution.getRoutes().iterator().next(); @@ -1166,11 +1167,11 @@ public class SolutionAnalyserTest { } @Test - public void lateArrivalTimes_ofEndActOfRoute1ShouldWork(){ - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + public void lateArrivalTimes_ofEndActOfRoute1ShouldWork() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); VehicleRoute route = solution.getRoutes().iterator().next(); @@ -1178,11 +1179,11 @@ public class SolutionAnalyserTest { } @Test - public void lateArrTimes_OfRoute1ShouldWork(){ - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + public void lateArrTimes_OfRoute1ShouldWork() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); VehicleRoute route = solution.getRoutes().iterator().next(); @@ -1190,11 +1191,11 @@ public class SolutionAnalyserTest { } @Test - public void variableTransportCosts_OfRoute1ShouldWork(){ - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + public void variableTransportCosts_OfRoute1ShouldWork() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); VehicleRoute route = solution.getRoutes().iterator().next(); @@ -1202,11 +1203,11 @@ public class SolutionAnalyserTest { } @Test - public void fixedCosts_OfRoute1ShouldWork(){ - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + public void fixedCosts_OfRoute1ShouldWork() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); VehicleRoute route = solution.getRoutes().iterator().next(); @@ -1214,11 +1215,11 @@ public class SolutionAnalyserTest { } @Test - public void transportCosts_atStartActOfRoute1ShouldWork(){ - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + public void transportCosts_atStartActOfRoute1ShouldWork() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); VehicleRoute route = solution.getRoutes().iterator().next(); @@ -1226,599 +1227,597 @@ public class SolutionAnalyserTest { } @Test - public void transportCosts_ofAct1ofRoute1ShouldWork(){ - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + public void transportCosts_ofAct1ofRoute1ShouldWork() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); VehicleRoute route = solution.getRoutes().iterator().next(); - Assert.assertEquals(6.*2., analyser.getVariableTransportCostsAtActivity(route.getActivities().get(0), route), 0.01); + Assert.assertEquals(6. * 2., analyser.getVariableTransportCostsAtActivity(route.getActivities().get(0), route), 0.01); } @Test - public void transportCosts_ofAct2ofRoute1ShouldWork(){ - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + public void transportCosts_ofAct2ofRoute1ShouldWork() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); VehicleRoute route = solution.getRoutes().iterator().next(); - Assert.assertEquals(12.*2., analyser.getVariableTransportCostsAtActivity(route.getActivities().get(1), route), 0.01); + Assert.assertEquals(12. * 2., analyser.getVariableTransportCostsAtActivity(route.getActivities().get(1), route), 0.01); } @Test - public void transportCosts_ofAct3ofRoute1ShouldWork(){ - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + public void transportCosts_ofAct3ofRoute1ShouldWork() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); VehicleRoute route = solution.getRoutes().iterator().next(); - Assert.assertEquals(16.*2., analyser.getVariableTransportCostsAtActivity(route.getActivities().get(2), route), 0.01); + Assert.assertEquals(16. * 2., analyser.getVariableTransportCostsAtActivity(route.getActivities().get(2), route), 0.01); } @Test - public void transportCosts_ofAct4ofRoute1ShouldWork(){ - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + public void transportCosts_ofAct4ofRoute1ShouldWork() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); VehicleRoute route = solution.getRoutes().iterator().next(); - Assert.assertEquals(27.*2., analyser.getVariableTransportCostsAtActivity(route.getActivities().get(3), route), 0.01); + Assert.assertEquals(27. * 2., analyser.getVariableTransportCostsAtActivity(route.getActivities().get(3), route), 0.01); } @Test - public void transportCosts_ofEndActOfRoute1ShouldWork(){ - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + public void transportCosts_ofEndActOfRoute1ShouldWork() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); VehicleRoute route = solution.getRoutes().iterator().next(); - Assert.assertEquals(42.*2., analyser.getVariableTransportCostsAtActivity(route.getEnd(), route), 0.01); + Assert.assertEquals(42. * 2., analyser.getVariableTransportCostsAtActivity(route.getEnd(), route), 0.01); } @Test - public void capacityViolationAtBeginning_shouldWork(){ - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution, new TransportDistance() { + public void capacityViolationAtBeginning_shouldWork() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new TransportDistance() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); VehicleRoute route = solution.getRoutes().iterator().next(); Capacity atBeginning = analyser.getCapacityViolationAtBeginning(route); - for(int i=0;i. - * + * * Contributors: * Stefan Schroeder - initial API and implementation ******************************************************************************/ @@ -25,349 +25,348 @@ import java.util.Random; import static org.junit.Assert.*; public class CapacityTest { - - @Test - public void whenSettingSimplyOneCapDimension_nuOfDimensionMustBeCorrect(){ - Capacity.Builder capBuilder = Capacity.Builder.newInstance(); - capBuilder.addDimension(0, 4); - Capacity cap = capBuilder.build(); - assertEquals(1,cap.getNuOfDimensions()); - } - - @Test - public void whenSettingTwoCapDimension_nuOfDimensionMustBeCorrect(){ - Capacity.Builder capBuilder = Capacity.Builder.newInstance(); - capBuilder.addDimension(0, 4); - capBuilder.addDimension(1,10); - Capacity cap = capBuilder.build(); - assertEquals(2,cap.getNuOfDimensions()); - } - - @Test - public void whenSettingRandomNuOfCapDimension_nuOfDimensionMustBeCorrect(){ - Random rand = new Random(); - int nuOfCapDimensions = 1+rand.nextInt(100); - Capacity.Builder capBuilder = Capacity.Builder.newInstance(); - capBuilder.addDimension(nuOfCapDimensions-1, 4); - Capacity cap = capBuilder.build(); - assertEquals(nuOfCapDimensions,cap.getNuOfDimensions()); - } - - @Test - public void whenSettingOneDimValue_valueMustBeCorrect(){ - Capacity.Builder capBuilder = Capacity.Builder.newInstance(); - capBuilder.addDimension(0, 4); - Capacity cap = capBuilder.build(); - assertEquals(4,cap.get(0)); - } - - @Test - public void whenGettingIndexWhichIsHigherThanNuOfCapDimensions_itShouldReturn0(){ - Capacity.Builder capBuilder = Capacity.Builder.newInstance(); - capBuilder.addDimension(0, 4); - Capacity cap = capBuilder.build(); - assertEquals(0,cap.get(2)); - } - - @Test - public void whenSettingNoDim_DefaultIsOneDimWithDimValueOfZero(){ - Capacity.Builder capBuilder = Capacity.Builder.newInstance(); - Capacity cap = capBuilder.build(); - assertEquals(1, cap.getNuOfDimensions()); - assertEquals(0, cap.get(0)); - } - - @Test - public void whenCopyingCapacityWithTwoCapDim_copiedObjShouldHvSameNuOfDims(){ - Capacity.Builder capBuilder = Capacity.Builder.newInstance(); - capBuilder.addDimension(0, 4); - capBuilder.addDimension(1,10); - Capacity cap = capBuilder.build(); - - Capacity copiedCapacity = Capacity.copyOf(cap); - assertEquals(2,copiedCapacity.getNuOfDimensions()); - } - - @Test - public void whenCopyingCapacityWithTwoCapDim_copiedObjShouldHvSameValues(){ - Capacity.Builder capBuilder = Capacity.Builder.newInstance(); - capBuilder.addDimension(0, 4); - capBuilder.addDimension(1,10); - Capacity cap = capBuilder.build(); - - Capacity copiedCapacity = Capacity.copyOf(cap); - assertEquals(4,copiedCapacity.get(0)); - assertEquals(10,copiedCapacity.get(1)); - } - - @Test - public void whenCopyingNull_itShouldReturnNull(){ - Capacity nullCap = Capacity.copyOf(null); - assertTrue(nullCap==null); - } - - @Test - public void whenAddingUpTwoOneDimensionalCapacities_itShouldReturnCorrectCapacityValues(){ - Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 1).build(); - Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).build(); - Capacity result = Capacity.addup(cap1, cap2); - assertEquals(3, result.get(0)); - } - @Test - public void whenAddingUpTwoOneDimensionalCapacities_itShouldReturnCorrectNuOfDimensions(){ - Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 1).build(); - Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).build(); - Capacity result = Capacity.addup(cap1, cap2); - assertEquals(1, result.getNuOfDimensions()); - } - - @Test - public void whenAddingUpTwoThreeDimensionalCapacities_itShouldReturnCorrectNuOfDimensions(){ - Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 2).addDimension(2, 3).build(); - Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 3).addDimension(2, 4).build(); - Capacity result = Capacity.addup(cap1, cap2); - assertEquals(3, result.getNuOfDimensions()); - } - - @Test - public void whenAddingUpTwoThreeDimensionalCapacities_itShouldReturnCorrectCapValues(){ - Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 2).addDimension(2, 3).build(); - Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 3).addDimension(2, 4).build(); - Capacity result = Capacity.addup(cap1, cap2); - assertEquals(3, result.get(0)); - assertEquals(5, result.get(1)); - assertEquals(7, result.get(2)); - } - - public void whenAddingUpTwoCapacitiesWithDifferentNuOfDimensions_itShouldAddThemCorrectly(){ - Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 2).build(); - Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).build(); - Capacity result = Capacity.addup(cap1, cap2); - assertEquals(3,result.get(0)); - assertEquals(2,result.get(1)); - } - - @Test(expected=NullPointerException.class) - public void whenOneOfArgsIsNullWhenAdding_itShouldThrowException(){ - Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 2).build(); - @SuppressWarnings("unused") - Capacity result = Capacity.addup(cap1, null); - } - - - - @Test - public void whenSubtractingTwoOneDimensionalCapacities_itShouldReturnCorrectCapacityValues(){ - Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 1).build(); - Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).build(); - Capacity result = Capacity.subtract(cap2, cap1); - assertEquals(1, result.get(0)); - } + @Test + public void whenSettingSimplyOneCapDimension_nuOfDimensionMustBeCorrect() { + Capacity.Builder capBuilder = Capacity.Builder.newInstance(); + capBuilder.addDimension(0, 4); + Capacity cap = capBuilder.build(); + assertEquals(1, cap.getNuOfDimensions()); + } - @Test - public void whenSubtractingTwoOneDimensionalCapacities_itShouldReturnCorrectNuOfDimensions(){ - Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 1).build(); - Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).build(); - Capacity result = Capacity.subtract(cap2, cap1); - assertEquals(1, result.getNuOfDimensions()); - } - - @Test - public void whenSubtractingTwoThreeDimensionalCapacities_itShouldReturnCorrectNuOfDimensions(){ - Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 2).addDimension(2, 3).build(); - Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 3).addDimension(2, 4).build(); - Capacity result = Capacity.subtract(cap2, cap1); - assertEquals(3, result.getNuOfDimensions()); - } - - @Test - public void whenSubtractingTwoThreeDimensionalCapacities_itShouldReturnCorrectCapValues(){ - Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 2).addDimension(2, 3).build(); - Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 3).addDimension(2, 4).build(); - Capacity result = Capacity.subtract(cap2, cap1); - assertEquals(1, result.get(0)); - assertEquals(1, result.get(1)); - assertEquals(1, result.get(2)); - } - - @Test - public void whenSubtractingTwoCapacitiesWithDifferentNuOfDimensions_itShouldSubtractCorrectly(){ - Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 2).build(); - Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).build(); - Capacity result = Capacity.subtract(cap2, cap1); - assertEquals(1,result.get(0)); - assertEquals(-2,result.get(1)); - } - - @Test(expected=NullPointerException.class) - public void whenOneOfArgsIsNullWhenSubtracting_itShouldThrowException(){ - Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 2).build(); - @SuppressWarnings("unused") - Capacity result = Capacity.subtract(cap1, null); - } - - @Test - public void whenSubtractingBiggerFromLower_itShouldSubtractCorrectly(){ - Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 2).addDimension(2, 3).build(); - Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 3).addDimension(2, 4).build(); - Capacity result = Capacity.subtract(cap1, cap2); - assertEquals(-1,result.get(0)); - assertEquals(-1,result.get(1)); - assertEquals(-1,result.get(2)); - } - - @Test - public void whenOneCapIsLessThanAnother_itShouldReturnCorrectBoolean(){ - Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 2).addDimension(2, 3).build(); - Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 3).addDimension(2, 4).build(); - assertTrue(cap1.isLessOrEqual(cap2)); - } - - @Test - public void whenOneCapIsLessThanAnother_itShouldReturnCorrectBoolean_v2(){ - Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 2).addDimension(2, 4).build(); - Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 3).addDimension(2, 4).build(); - assertTrue(cap1.isLessOrEqual(cap2)); - } - - @Test - public void whenOneCapIsLessThanAnother_itShouldReturnCorrectBoolean_v3(){ - Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 3).addDimension(2, 4).build(); - Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 3).addDimension(2, 4).build(); - assertTrue(cap1.isLessOrEqual(cap2)); - } - - @Test - public void whenOneCapIsBiggerThanAnother_itShouldReturnCorrectBoolean(){ - Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 3).addDimension(2, 4).build(); - Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 4).addDimension(2, 4).build(); - assertFalse(cap2.isLessOrEqual(cap1)); - } - - @Test - public void whenOneCapIsBiggerThanAnother_greaterOrEqualShouldReturnTrue(){ - Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 3).addDimension(2, 4).build(); - Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 4).addDimension(2, 4).build(); - assertTrue(cap2.isGreaterOrEqual(cap1)); - } - - @Test - public void whenOneCapIsBiggerThanAnother_greaterOrEqualShouldReturnTrue_v2(){ - Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 3).addDimension(2, 4).build(); - //which is zero-cap - Capacity cap2 = Capacity.Builder.newInstance().build(); - assertTrue(cap1.isGreaterOrEqual(cap2)); - } - - @Test - public void whenOneCapIsEqualToAnother_greaterOrEqualShouldReturnTrue(){ - Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 3).addDimension(2, 4).build(); - Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 3).addDimension(2, 4).build(); - assertTrue(cap2.isGreaterOrEqual(cap1)); - } - - @Test - public void whenAddingTwo_itShouldReturnCorrectCap(){ - int wheelChairSpace = 0; - int passengerSeats = 1; - Capacity cap1 = Capacity.Builder.newInstance().addDimension(wheelChairSpace, 2).addDimension(passengerSeats, 10).build(); - Capacity wheelChair = Capacity.Builder.newInstance().addDimension(wheelChairSpace, 1).build(); - Capacity passenger = Capacity.Builder.newInstance().addDimension(passengerSeats, 1).build(); - Capacity wheelChair_plus_passenger = Capacity.addup(wheelChair, passenger); - assertEquals(1,wheelChair_plus_passenger.get(wheelChairSpace)); - assertEquals(1,wheelChair_plus_passenger.get(passengerSeats)); - assertTrue(wheelChair_plus_passenger.isLessOrEqual(cap1)); - } - - @Test - public void whenAddingTwo_itShouldReturnCorrectCap_v2(){ - int wheelChairSpace = 0; - int passengerSeats = 1; - int weight = 2; - Capacity cap1 = Capacity.Builder.newInstance().addDimension(wheelChairSpace, 2).addDimension(passengerSeats, 10).addDimension(2, 100).build(); - Capacity wheelChair = Capacity.Builder.newInstance().addDimension(wheelChairSpace, 1).addDimension(weight, 80).build(); - Capacity passenger = Capacity.Builder.newInstance().addDimension(passengerSeats, 1).addDimension(weight, 30).build(); - Capacity wheelChair_plus_passenger = Capacity.addup(wheelChair, passenger); - assertEquals(1,wheelChair_plus_passenger.get(wheelChairSpace)); - assertEquals(1,wheelChair_plus_passenger.get(passengerSeats)); - assertEquals(110,wheelChair_plus_passenger.get(weight)); - assertFalse(wheelChair_plus_passenger.isLessOrEqual(cap1)); - } - - @Test - public void whenInvertingCap_itShouldBeDoneCorrectly(){ - Capacity cap = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 3).addDimension(2, 4).build(); - Capacity inverted = Capacity.invert(cap); - assertEquals(-2,inverted.get(0)); - assertEquals(-3,inverted.get(1)); - assertEquals(-4,inverted.get(2)); - } - - @Test - public void whenDeterminingTheMaximumOfTwoCapacities_itShouldReturnCapWithMaxOfEachDimension(){ - Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 3).addDimension(1, 3).build(); - Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 4).build(); - assertEquals(3,Capacity.max(cap1,cap2).get(0)); - assertEquals(4,Capacity.max(cap1,cap2).get(1)); - } - - @Test - public void whenDeterminingTheMaximumOfTwoCapacities_itShouldReturnCapWithMaxOfEachDimension_v2(){ - Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 3).build(); - Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 4).build(); - assertEquals(2,Capacity.max(cap1,cap2).get(0)); - assertEquals(4,Capacity.max(cap1,cap2).get(1)); - } - - @Test - public void whenDeterminingTheMaximumOfTwoCapacities_itShouldReturnCapWithMaxOfEachDimension_v3(){ - Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 3).addDimension(2, 3).build(); - Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 4).build(); - assertEquals(2,Capacity.max(cap1,cap2).get(0)); - assertEquals(4,Capacity.max(cap1,cap2).get(1)); - assertEquals(3,Capacity.max(cap1,cap2).get(2)); - } - - @Test - public void whenDividingTwoCapacities_itShouldReturn05(){ - Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 2).build(); - Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 4).build(); - assertEquals(0.5,Capacity.divide(cap1, cap2),0.001); - } - - @Test - public void whenDividingTwoEqualCapacities_itShouldReturn10(){ - Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 4).build(); - Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 4).build(); - assertEquals(1.0,Capacity.divide(cap1, cap2),0.001); - } - - @Test - public void whenDividingTwoCapacities_itShouldReturn00(){ - Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 0).addDimension(1, 0).build(); - Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 4).build(); - assertEquals(0.0,Capacity.divide(cap1, cap2),0.001); - } - - @Test(expected=IllegalStateException.class) - public void whenDividingByAZeroDim_itShouldThrowException(){ - Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 2).build(); - Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 0).build(); - Capacity.divide(cap1, cap2); - } - - @Test - public void whenBothDimOfNominatorAndDenominatorAreZero_divisionShouldIgnoreThisDim(){ - Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 2).addDimension(3, 0).build(); - Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 4).addDimension(3, 0).build(); - assertEquals(0.5,Capacity.divide(cap1, cap2),0.001); - } - - @Test - public void whenDividingZeroCaps_itShouldReturnZero(){ - Capacity cap1 = Capacity.Builder.newInstance().build(); - Capacity cap2 = Capacity.Builder.newInstance().build(); - assertEquals(0.0,Capacity.divide(cap1, cap2),0.001); - } + @Test + public void whenSettingTwoCapDimension_nuOfDimensionMustBeCorrect() { + Capacity.Builder capBuilder = Capacity.Builder.newInstance(); + capBuilder.addDimension(0, 4); + capBuilder.addDimension(1, 10); + Capacity cap = capBuilder.build(); + assertEquals(2, cap.getNuOfDimensions()); + } + + @Test + public void whenSettingRandomNuOfCapDimension_nuOfDimensionMustBeCorrect() { + Random rand = new Random(); + int nuOfCapDimensions = 1 + rand.nextInt(100); + Capacity.Builder capBuilder = Capacity.Builder.newInstance(); + capBuilder.addDimension(nuOfCapDimensions - 1, 4); + Capacity cap = capBuilder.build(); + assertEquals(nuOfCapDimensions, cap.getNuOfDimensions()); + } + + @Test + public void whenSettingOneDimValue_valueMustBeCorrect() { + Capacity.Builder capBuilder = Capacity.Builder.newInstance(); + capBuilder.addDimension(0, 4); + Capacity cap = capBuilder.build(); + assertEquals(4, cap.get(0)); + } + + @Test + public void whenGettingIndexWhichIsHigherThanNuOfCapDimensions_itShouldReturn0() { + Capacity.Builder capBuilder = Capacity.Builder.newInstance(); + capBuilder.addDimension(0, 4); + Capacity cap = capBuilder.build(); + assertEquals(0, cap.get(2)); + } + + @Test + public void whenSettingNoDim_DefaultIsOneDimWithDimValueOfZero() { + Capacity.Builder capBuilder = Capacity.Builder.newInstance(); + Capacity cap = capBuilder.build(); + assertEquals(1, cap.getNuOfDimensions()); + assertEquals(0, cap.get(0)); + } + + @Test + public void whenCopyingCapacityWithTwoCapDim_copiedObjShouldHvSameNuOfDims() { + Capacity.Builder capBuilder = Capacity.Builder.newInstance(); + capBuilder.addDimension(0, 4); + capBuilder.addDimension(1, 10); + Capacity cap = capBuilder.build(); + + Capacity copiedCapacity = Capacity.copyOf(cap); + assertEquals(2, copiedCapacity.getNuOfDimensions()); + } + + @Test + public void whenCopyingCapacityWithTwoCapDim_copiedObjShouldHvSameValues() { + Capacity.Builder capBuilder = Capacity.Builder.newInstance(); + capBuilder.addDimension(0, 4); + capBuilder.addDimension(1, 10); + Capacity cap = capBuilder.build(); + + Capacity copiedCapacity = Capacity.copyOf(cap); + assertEquals(4, copiedCapacity.get(0)); + assertEquals(10, copiedCapacity.get(1)); + } + + @Test + public void whenCopyingNull_itShouldReturnNull() { + Capacity nullCap = Capacity.copyOf(null); + assertTrue(nullCap == null); + } + + @Test + public void whenAddingUpTwoOneDimensionalCapacities_itShouldReturnCorrectCapacityValues() { + Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 1).build(); + Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).build(); + Capacity result = Capacity.addup(cap1, cap2); + assertEquals(3, result.get(0)); + } + + @Test + public void whenAddingUpTwoOneDimensionalCapacities_itShouldReturnCorrectNuOfDimensions() { + Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 1).build(); + Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).build(); + Capacity result = Capacity.addup(cap1, cap2); + assertEquals(1, result.getNuOfDimensions()); + } + + @Test + public void whenAddingUpTwoThreeDimensionalCapacities_itShouldReturnCorrectNuOfDimensions() { + Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 2).addDimension(2, 3).build(); + Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 3).addDimension(2, 4).build(); + Capacity result = Capacity.addup(cap1, cap2); + assertEquals(3, result.getNuOfDimensions()); + } + + @Test + public void whenAddingUpTwoThreeDimensionalCapacities_itShouldReturnCorrectCapValues() { + Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 2).addDimension(2, 3).build(); + Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 3).addDimension(2, 4).build(); + Capacity result = Capacity.addup(cap1, cap2); + assertEquals(3, result.get(0)); + assertEquals(5, result.get(1)); + assertEquals(7, result.get(2)); + } + + public void whenAddingUpTwoCapacitiesWithDifferentNuOfDimensions_itShouldAddThemCorrectly() { + Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 2).build(); + Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).build(); + Capacity result = Capacity.addup(cap1, cap2); + assertEquals(3, result.get(0)); + assertEquals(2, result.get(1)); + } + + @Test(expected = NullPointerException.class) + public void whenOneOfArgsIsNullWhenAdding_itShouldThrowException() { + Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 2).build(); + @SuppressWarnings("unused") + Capacity result = Capacity.addup(cap1, null); + } + + + @Test + public void whenSubtractingTwoOneDimensionalCapacities_itShouldReturnCorrectCapacityValues() { + Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 1).build(); + Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).build(); + Capacity result = Capacity.subtract(cap2, cap1); + assertEquals(1, result.get(0)); + } + + @Test + public void whenSubtractingTwoOneDimensionalCapacities_itShouldReturnCorrectNuOfDimensions() { + Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 1).build(); + Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).build(); + Capacity result = Capacity.subtract(cap2, cap1); + assertEquals(1, result.getNuOfDimensions()); + } + + @Test + public void whenSubtractingTwoThreeDimensionalCapacities_itShouldReturnCorrectNuOfDimensions() { + Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 2).addDimension(2, 3).build(); + Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 3).addDimension(2, 4).build(); + Capacity result = Capacity.subtract(cap2, cap1); + assertEquals(3, result.getNuOfDimensions()); + } + + @Test + public void whenSubtractingTwoThreeDimensionalCapacities_itShouldReturnCorrectCapValues() { + Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 2).addDimension(2, 3).build(); + Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 3).addDimension(2, 4).build(); + Capacity result = Capacity.subtract(cap2, cap1); + assertEquals(1, result.get(0)); + assertEquals(1, result.get(1)); + assertEquals(1, result.get(2)); + } + + @Test + public void whenSubtractingTwoCapacitiesWithDifferentNuOfDimensions_itShouldSubtractCorrectly() { + Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 2).build(); + Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).build(); + Capacity result = Capacity.subtract(cap2, cap1); + assertEquals(1, result.get(0)); + assertEquals(-2, result.get(1)); + } + + @Test(expected = NullPointerException.class) + public void whenOneOfArgsIsNullWhenSubtracting_itShouldThrowException() { + Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 2).build(); + @SuppressWarnings("unused") + Capacity result = Capacity.subtract(cap1, null); + } + + @Test + public void whenSubtractingBiggerFromLower_itShouldSubtractCorrectly() { + Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 2).addDimension(2, 3).build(); + Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 3).addDimension(2, 4).build(); + Capacity result = Capacity.subtract(cap1, cap2); + assertEquals(-1, result.get(0)); + assertEquals(-1, result.get(1)); + assertEquals(-1, result.get(2)); + } + + @Test + public void whenOneCapIsLessThanAnother_itShouldReturnCorrectBoolean() { + Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 2).addDimension(2, 3).build(); + Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 3).addDimension(2, 4).build(); + assertTrue(cap1.isLessOrEqual(cap2)); + } + + @Test + public void whenOneCapIsLessThanAnother_itShouldReturnCorrectBoolean_v2() { + Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 2).addDimension(2, 4).build(); + Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 3).addDimension(2, 4).build(); + assertTrue(cap1.isLessOrEqual(cap2)); + } + + @Test + public void whenOneCapIsLessThanAnother_itShouldReturnCorrectBoolean_v3() { + Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 3).addDimension(2, 4).build(); + Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 3).addDimension(2, 4).build(); + assertTrue(cap1.isLessOrEqual(cap2)); + } + + @Test + public void whenOneCapIsBiggerThanAnother_itShouldReturnCorrectBoolean() { + Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 3).addDimension(2, 4).build(); + Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 4).addDimension(2, 4).build(); + assertFalse(cap2.isLessOrEqual(cap1)); + } + + @Test + public void whenOneCapIsBiggerThanAnother_greaterOrEqualShouldReturnTrue() { + Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 3).addDimension(2, 4).build(); + Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 4).addDimension(2, 4).build(); + assertTrue(cap2.isGreaterOrEqual(cap1)); + } + + @Test + public void whenOneCapIsBiggerThanAnother_greaterOrEqualShouldReturnTrue_v2() { + Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 3).addDimension(2, 4).build(); + //which is zero-cap + Capacity cap2 = Capacity.Builder.newInstance().build(); + assertTrue(cap1.isGreaterOrEqual(cap2)); + } + + @Test + public void whenOneCapIsEqualToAnother_greaterOrEqualShouldReturnTrue() { + Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 3).addDimension(2, 4).build(); + Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 3).addDimension(2, 4).build(); + assertTrue(cap2.isGreaterOrEqual(cap1)); + } + + @Test + public void whenAddingTwo_itShouldReturnCorrectCap() { + int wheelChairSpace = 0; + int passengerSeats = 1; + Capacity cap1 = Capacity.Builder.newInstance().addDimension(wheelChairSpace, 2).addDimension(passengerSeats, 10).build(); + Capacity wheelChair = Capacity.Builder.newInstance().addDimension(wheelChairSpace, 1).build(); + Capacity passenger = Capacity.Builder.newInstance().addDimension(passengerSeats, 1).build(); + Capacity wheelChair_plus_passenger = Capacity.addup(wheelChair, passenger); + assertEquals(1, wheelChair_plus_passenger.get(wheelChairSpace)); + assertEquals(1, wheelChair_plus_passenger.get(passengerSeats)); + assertTrue(wheelChair_plus_passenger.isLessOrEqual(cap1)); + } + + @Test + public void whenAddingTwo_itShouldReturnCorrectCap_v2() { + int wheelChairSpace = 0; + int passengerSeats = 1; + int weight = 2; + Capacity cap1 = Capacity.Builder.newInstance().addDimension(wheelChairSpace, 2).addDimension(passengerSeats, 10).addDimension(2, 100).build(); + Capacity wheelChair = Capacity.Builder.newInstance().addDimension(wheelChairSpace, 1).addDimension(weight, 80).build(); + Capacity passenger = Capacity.Builder.newInstance().addDimension(passengerSeats, 1).addDimension(weight, 30).build(); + Capacity wheelChair_plus_passenger = Capacity.addup(wheelChair, passenger); + assertEquals(1, wheelChair_plus_passenger.get(wheelChairSpace)); + assertEquals(1, wheelChair_plus_passenger.get(passengerSeats)); + assertEquals(110, wheelChair_plus_passenger.get(weight)); + assertFalse(wheelChair_plus_passenger.isLessOrEqual(cap1)); + } + + @Test + public void whenInvertingCap_itShouldBeDoneCorrectly() { + Capacity cap = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 3).addDimension(2, 4).build(); + Capacity inverted = Capacity.invert(cap); + assertEquals(-2, inverted.get(0)); + assertEquals(-3, inverted.get(1)); + assertEquals(-4, inverted.get(2)); + } + + @Test + public void whenDeterminingTheMaximumOfTwoCapacities_itShouldReturnCapWithMaxOfEachDimension() { + Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 3).addDimension(1, 3).build(); + Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 4).build(); + assertEquals(3, Capacity.max(cap1, cap2).get(0)); + assertEquals(4, Capacity.max(cap1, cap2).get(1)); + } + + @Test + public void whenDeterminingTheMaximumOfTwoCapacities_itShouldReturnCapWithMaxOfEachDimension_v2() { + Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 3).build(); + Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 4).build(); + assertEquals(2, Capacity.max(cap1, cap2).get(0)); + assertEquals(4, Capacity.max(cap1, cap2).get(1)); + } + + @Test + public void whenDeterminingTheMaximumOfTwoCapacities_itShouldReturnCapWithMaxOfEachDimension_v3() { + Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 3).addDimension(2, 3).build(); + Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 4).build(); + assertEquals(2, Capacity.max(cap1, cap2).get(0)); + assertEquals(4, Capacity.max(cap1, cap2).get(1)); + assertEquals(3, Capacity.max(cap1, cap2).get(2)); + } + + @Test + public void whenDividingTwoCapacities_itShouldReturn05() { + Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 2).build(); + Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 4).build(); + assertEquals(0.5, Capacity.divide(cap1, cap2), 0.001); + } + + @Test + public void whenDividingTwoEqualCapacities_itShouldReturn10() { + Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 4).build(); + Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 4).build(); + assertEquals(1.0, Capacity.divide(cap1, cap2), 0.001); + } + + @Test + public void whenDividingTwoCapacities_itShouldReturn00() { + Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 0).addDimension(1, 0).build(); + Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 4).build(); + assertEquals(0.0, Capacity.divide(cap1, cap2), 0.001); + } + + @Test(expected = IllegalStateException.class) + public void whenDividingByAZeroDim_itShouldThrowException() { + Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 2).build(); + Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 0).build(); + Capacity.divide(cap1, cap2); + } + + @Test + public void whenBothDimOfNominatorAndDenominatorAreZero_divisionShouldIgnoreThisDim() { + Capacity cap1 = Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 2).addDimension(3, 0).build(); + Capacity cap2 = Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 4).addDimension(3, 0).build(); + assertEquals(0.5, Capacity.divide(cap1, cap2), 0.001); + } + + @Test + public void whenDividingZeroCaps_itShouldReturnZero() { + Capacity cap1 = Capacity.Builder.newInstance().build(); + Capacity cap2 = Capacity.Builder.newInstance().build(); + assertEquals(0.0, Capacity.divide(cap1, cap2), 0.001); + } } diff --git a/jsprit-core/src/test/java/jsprit/core/problem/LocationTest.java b/jsprit-core/src/test/java/jsprit/core/problem/LocationTest.java index e6fdabb7..29962b22 100644 --- a/jsprit-core/src/test/java/jsprit/core/problem/LocationTest.java +++ b/jsprit-core/src/test/java/jsprit/core/problem/LocationTest.java @@ -27,57 +27,57 @@ import org.junit.Test; public class LocationTest { @Test - public void whenIndexSet_buildLocation(){ + public void whenIndexSet_buildLocation() { Location l = Location.Builder.newInstance().setIndex(1).build(); - Assert.assertEquals(1,l.getIndex()); + Assert.assertEquals(1, l.getIndex()); Assert.assertTrue(true); } @Test - public void whenIndexSetWitFactory_returnCorrectLocation(){ + public void whenIndexSetWitFactory_returnCorrectLocation() { Location l = Location.newInstance(1); - Assert.assertEquals(1,l.getIndex()); + Assert.assertEquals(1, l.getIndex()); Assert.assertTrue(true); } @Test(expected = IllegalArgumentException.class) - public void whenIndexSmallerZero_throwException(){ + public void whenIndexSmallerZero_throwException() { Location l = Location.Builder.newInstance().setIndex(-1).build(); } @Test(expected = IllegalStateException.class) - public void whenCoordinateAndIdAndIndexNotSet_throwException(){ + public void whenCoordinateAndIdAndIndexNotSet_throwException() { Location l = Location.Builder.newInstance().build(); } @Test - public void whenIdSet_build(){ + public void whenIdSet_build() { Location l = Location.Builder.newInstance().setId("id").build(); - Assert.assertEquals("id",l.getId()); + Assert.assertEquals("id", l.getId()); Assert.assertTrue(true); } @Test - public void whenIdSetWithFactory_returnCorrectLocation(){ + public void whenIdSetWithFactory_returnCorrectLocation() { Location l = Location.newInstance("id"); - Assert.assertEquals("id",l.getId()); + Assert.assertEquals("id", l.getId()); Assert.assertTrue(true); } @Test - public void whenCoordinateSet_build(){ - Location l = Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(10,20)).build(); - Assert.assertEquals(10.,l.getCoordinate().getX()); - Assert.assertEquals(20.,l.getCoordinate().getY()); + public void whenCoordinateSet_build() { + Location l = Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(10, 20)).build(); + Assert.assertEquals(10., l.getCoordinate().getX()); + Assert.assertEquals(20., l.getCoordinate().getY()); Assert.assertTrue(true); } @Test - public void whenCoordinateSetWithFactory_returnCorrectLocation(){ + public void whenCoordinateSetWithFactory_returnCorrectLocation() { // Location l = Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(10,20)).build(); - Location l = Location.newInstance(10,20); - Assert.assertEquals(10.,l.getCoordinate().getX()); - Assert.assertEquals(20.,l.getCoordinate().getY()); + Location l = Location.newInstance(10, 20); + Assert.assertEquals(10., l.getCoordinate().getX()); + Assert.assertEquals(20., l.getCoordinate().getY()); Assert.assertTrue(true); } diff --git a/jsprit-core/src/test/java/jsprit/core/problem/SkillsTest.java b/jsprit-core/src/test/java/jsprit/core/problem/SkillsTest.java index 38628a8f..263fce72 100644 --- a/jsprit-core/src/test/java/jsprit/core/problem/SkillsTest.java +++ b/jsprit-core/src/test/java/jsprit/core/problem/SkillsTest.java @@ -13,21 +13,28 @@ import static org.junit.Assert.assertTrue; public class SkillsTest { @Test - public void whenSkillsAdded_theyShouldBeinSkillSet(){ + public void whenSkillsAdded_theyShouldBeinSkillSet() { Skills skills = Skills.Builder.newInstance().addSkill("skill1").addSkill("skill2").build(); assertTrue(skills.containsSkill("skill1")); assertTrue(skills.containsSkill("skill2")); } @Test - public void whenSkillsAddedCaseInsensitive_theyShouldBeinSkillSet(){ + public void whenSkillsAddedCaseInsensitive_theyShouldBeinSkillSet() { Skills skills = Skills.Builder.newInstance().addSkill("skill1").addSkill("skill2").build(); assertTrue(skills.containsSkill("skilL1")); assertTrue(skills.containsSkill("skIll2")); } @Test - public void whenSkillsAddedThroughAddAll_theyShouldBeinSkillSet(){ + public void whenSkillsAddedCaseInsensitive2_theyShouldBeinSkillSet() { + Skills skills = Skills.Builder.newInstance().addSkill("Skill1").addSkill("skill2").build(); + assertTrue(skills.containsSkill("skilL1")); + assertTrue(skills.containsSkill("skIll2")); + } + + @Test + public void whenSkillsAddedThroughAddAll_theyShouldBeinSkillSet() { Set skillSet = new HashSet(); skillSet.add("skill1"); skillSet.add("skill2"); @@ -36,4 +43,50 @@ public class SkillsTest { assertTrue(skills.containsSkill("skill2")); } + @Test + public void whenSkillsAddedThroughAddAllCaseInsensitive_theyShouldBeinSkillSet() { + Set skillSet = new HashSet(); + skillSet.add("skill1"); + skillSet.add("skill2"); + Skills skills = Skills.Builder.newInstance().addAllSkills(skillSet).build(); + assertTrue(skills.containsSkill("skilL1")); + assertTrue(skills.containsSkill("skill2")); + } + + @Test + public void whenSkillsAddedThroughAddAllCaseInsensitive2_theyShouldBeinSkillSet() { + Set skillSet = new HashSet(); + skillSet.add("skill1"); + skillSet.add("Skill2"); + Skills skills = Skills.Builder.newInstance().addAllSkills(skillSet).build(); + assertTrue(skills.containsSkill("skill1")); + assertTrue(skills.containsSkill("skill2")); + } + + @Test + public void whenSkillsAddedPrecedingWhitespaceShouldNotMatter() { + Set skillSet = new HashSet(); + skillSet.add(" skill1"); + skillSet.add("Skill2"); + Skills skills = Skills.Builder.newInstance().addAllSkills(skillSet).build(); + assertTrue(skills.containsSkill("skill1")); + assertTrue(skills.containsSkill("skill2")); + } + + @Test + public void whenSkillsAddedTrailingWhitespaceShouldNotMatter() { + Set skillSet = new HashSet(); + skillSet.add("skill1 "); + skillSet.add("Skill2"); + Skills skills = Skills.Builder.newInstance().addAllSkills(skillSet).build(); + assertTrue(skills.containsSkill("skill1")); + assertTrue(skills.containsSkill("skill2")); + } + + @Test + public void whenSkillsAddedTrailingWhitespaceShouldNotMatter2() { + Skills skills = Skills.Builder.newInstance().addSkill("skill1 ").build(); + assertTrue(skills.containsSkill("skill1")); + } + } diff --git a/jsprit-core/src/test/java/jsprit/core/problem/VehicleRoutingProblemTest.java b/jsprit-core/src/test/java/jsprit/core/problem/VehicleRoutingProblemTest.java index 7b6e3c55..62cbeaa7 100644 --- a/jsprit-core/src/test/java/jsprit/core/problem/VehicleRoutingProblemTest.java +++ b/jsprit-core/src/test/java/jsprit/core/problem/VehicleRoutingProblemTest.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.problem; @@ -45,414 +45,420 @@ import static org.mockito.Mockito.when; public class VehicleRoutingProblemTest { - - @Test - public void whenBuildingWithInfiniteFleet_fleetSizeShouldBeInfinite(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - builder.setFleetSize(FleetSize.INFINITE); - VehicleRoutingProblem vrp = builder.build(); - assertEquals(FleetSize.INFINITE,vrp.getFleetSize()); - } - - @Test - public void whenBuildingWithFiniteFleet_fleetSizeShouldBeFinite(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - builder.setFleetSize(FleetSize.FINITE); - VehicleRoutingProblem vrp = builder.build(); - assertEquals(FleetSize.FINITE,vrp.getFleetSize()); - } - @Test - public void whenBuildingWithFourVehicles_vrpShouldContainTheCorrectNuOfVehicles(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - - VehicleImpl v1 = VehicleImpl.Builder.newInstance("v1").setStartLocation(Location.newInstance("start")).build(); + @Test + public void whenBuildingWithInfiniteFleet_fleetSizeShouldBeInfinite() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + builder.setFleetSize(FleetSize.INFINITE); + VehicleRoutingProblem vrp = builder.build(); + assertEquals(FleetSize.INFINITE, vrp.getFleetSize()); + } + + @Test + public void whenBuildingWithFiniteFleet_fleetSizeShouldBeFinite() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + builder.setFleetSize(FleetSize.FINITE); + VehicleRoutingProblem vrp = builder.build(); + assertEquals(FleetSize.FINITE, vrp.getFleetSize()); + } + + @Test + public void whenBuildingWithFourVehicles_vrpShouldContainTheCorrectNuOfVehicles() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + + VehicleImpl v1 = VehicleImpl.Builder.newInstance("v1").setStartLocation(Location.newInstance("start")).build(); VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(Location.newInstance("start")).build(); VehicleImpl v3 = VehicleImpl.Builder.newInstance("v3").setStartLocation(Location.newInstance("start")).build(); VehicleImpl v4 = VehicleImpl.Builder.newInstance("v4").setStartLocation(Location.newInstance("start")).build(); - - builder.addVehicle(v1).addVehicle(v2).addVehicle(v3).addVehicle(v4); - - VehicleRoutingProblem vrp = builder.build(); - assertEquals(4,vrp.getVehicles().size()); - } - - @Test - public void whenAddingFourVehiclesAllAtOnce_vrpShouldContainTheCorrectNuOfVehicles(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - - VehicleImpl v1 = VehicleImpl.Builder.newInstance("v1").setStartLocation(Location.newInstance("start")).build(); + builder.addVehicle(v1).addVehicle(v2).addVehicle(v3).addVehicle(v4); + + VehicleRoutingProblem vrp = builder.build(); + assertEquals(4, vrp.getVehicles().size()); + assertEquals(1, vrp.getAllLocations().size()); + + } + + @Test + public void whenAddingFourVehiclesAllAtOnce_vrpShouldContainTheCorrectNuOfVehicles() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + + VehicleImpl v1 = VehicleImpl.Builder.newInstance("v1").setStartLocation(Location.newInstance("start")).build(); VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(Location.newInstance("start")).build(); VehicleImpl v3 = VehicleImpl.Builder.newInstance("v3").setStartLocation(Location.newInstance("start")).build(); VehicleImpl v4 = VehicleImpl.Builder.newInstance("v4").setStartLocation(Location.newInstance("start")).build(); - - builder.addAllVehicles(Arrays.asList(v1,v2,v3,v4)); - - VehicleRoutingProblem vrp = builder.build(); - assertEquals(4,vrp.getVehicles().size()); - } + builder.addAllVehicles(Arrays.asList(v1, v2, v3, v4)); - @Test - public void whenBuildingWithFourVehiclesAndTwoTypes_vrpShouldContainTheCorrectNuOfTypes(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - - VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("type1").build(); - VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("type2").build(); - - VehicleImpl v1 = VehicleImpl.Builder.newInstance("v1").setStartLocation(Location.newInstance("yo")).setType(type1).build(); - VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(Location.newInstance("yo")).setType(type1).build(); - VehicleImpl v3 = VehicleImpl.Builder.newInstance("v3").setStartLocation(Location.newInstance("yo")).setType(type2).build(); - VehicleImpl v4 = VehicleImpl.Builder.newInstance("v4").setStartLocation(Location.newInstance("yo")).setType(type2).build(); - - builder.addVehicle(v1).addVehicle(v2).addVehicle(v3).addVehicle(v4); - - VehicleRoutingProblem vrp = builder.build(); - assertEquals(2,vrp.getTypes().size()); + VehicleRoutingProblem vrp = builder.build(); + assertEquals(4, vrp.getVehicles().size()); - } + } - @Test - public void whenShipmentsAreAdded_vrpShouldContainThem(){ - Shipment s = Shipment.Builder.newInstance("s").addSizeDimension(0, 10).setPickupLocation(Location.Builder.newInstance().setId("foofoo").build()).setDeliveryLocation(Location.newInstance("foo")).build(); - Shipment s2 = Shipment.Builder.newInstance("s2").addSizeDimension(0, 100).setPickupLocation(Location.Builder.newInstance().setId("foofoo").build()).setDeliveryLocation(Location.newInstance("foo")).build(); - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - vrpBuilder.addJob(s); - vrpBuilder.addJob(s2); - VehicleRoutingProblem vrp = vrpBuilder.build(); - - assertEquals(2,vrp.getJobs().size()); - assertEquals(s,vrp.getJobs().get("s")); - assertEquals(s2,vrp.getJobs().get("s2")); - } - - @Test - public void whenServicesAreAdded_vrpShouldContainThem(){ - Service s1 = mock(Service.class); - when(s1.getId()).thenReturn("s1"); + @Test + public void whenBuildingWithFourVehiclesAndTwoTypes_vrpShouldContainTheCorrectNuOfTypes() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + + VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("type1").build(); + VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("type2").build(); + + VehicleImpl v1 = VehicleImpl.Builder.newInstance("v1").setStartLocation(Location.newInstance("yo")).setType(type1).build(); + VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(Location.newInstance("yo")).setType(type1).build(); + VehicleImpl v3 = VehicleImpl.Builder.newInstance("v3").setStartLocation(Location.newInstance("yo")).setType(type2).build(); + VehicleImpl v4 = VehicleImpl.Builder.newInstance("v4").setStartLocation(Location.newInstance("yo")).setType(type2).build(); + + builder.addVehicle(v1).addVehicle(v2).addVehicle(v3).addVehicle(v4); + + VehicleRoutingProblem vrp = builder.build(); + assertEquals(2, vrp.getTypes().size()); + + } + + @Test + public void whenShipmentsAreAdded_vrpShouldContainThem() { + Shipment s = Shipment.Builder.newInstance("s").addSizeDimension(0, 10).setPickupLocation(Location.Builder.newInstance().setId("foofoo").build()).setDeliveryLocation(Location.newInstance("foo")).build(); + Shipment s2 = Shipment.Builder.newInstance("s2").addSizeDimension(0, 100).setPickupLocation(Location.Builder.newInstance().setId("foofoo").build()).setDeliveryLocation(Location.newInstance("foo")).build(); + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + vrpBuilder.addJob(s); + vrpBuilder.addJob(s2); + VehicleRoutingProblem vrp = vrpBuilder.build(); + + assertEquals(2, vrp.getJobs().size()); + assertEquals(s, vrp.getJobs().get("s")); + assertEquals(s2, vrp.getJobs().get("s2")); + assertEquals(2,vrp.getAllLocations().size()); + } + + @Test + public void whenServicesAreAdded_vrpShouldContainThem() { + Service s1 = mock(Service.class); + when(s1.getId()).thenReturn("s1"); when(s1.getLocation()).thenReturn(Location.Builder.newInstance().setIndex(1).build()); - Service s2 = mock(Service.class); - when(s2.getId()).thenReturn("s2"); + Service s2 = mock(Service.class); + when(s2.getId()).thenReturn("s2"); when(s2.getLocation()).thenReturn(Location.Builder.newInstance().setIndex(1).build()); - - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - vrpBuilder.addJob(s1).addJob(s2); - - VehicleRoutingProblem vrp = vrpBuilder.build(); - - assertEquals(2,vrp.getJobs().size()); - assertEquals(s1,vrp.getJobs().get("s1")); - assertEquals(s2,vrp.getJobs().get("s2")); - } - - @Test - public void whenPickupsAreAdded_vrpShouldContainThem(){ - Pickup s1 = mock(Pickup.class); - when(s1.getId()).thenReturn("s1"); + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + vrpBuilder.addJob(s1).addJob(s2); + + VehicleRoutingProblem vrp = vrpBuilder.build(); + + assertEquals(2, vrp.getJobs().size()); + assertEquals(s1, vrp.getJobs().get("s1")); + assertEquals(s2, vrp.getJobs().get("s2")); + assertEquals(1,vrp.getAllLocations().size()); + } + + + @Test + public void whenPickupsAreAdded_vrpShouldContainThem() { + Pickup s1 = mock(Pickup.class); + when(s1.getId()).thenReturn("s1"); when(s1.getLocation()).thenReturn(Location.Builder.newInstance().setIndex(1).build()); - Pickup s2 = mock(Pickup.class); - when(s2.getId()).thenReturn("s2"); + Pickup s2 = mock(Pickup.class); + when(s2.getId()).thenReturn("s2"); when(s2.getLocation()).thenReturn(Location.Builder.newInstance().setIndex(1).build()); - - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - vrpBuilder.addJob(s1).addJob(s2); - - VehicleRoutingProblem vrp = vrpBuilder.build(); - - assertEquals(2,vrp.getJobs().size()); - assertEquals(s1,vrp.getJobs().get("s1")); - assertEquals(s2,vrp.getJobs().get("s2")); - } - - @Test - public void whenPickupsAreAddedAllAtOnce_vrpShouldContainThem(){ - Pickup s1 = mock(Pickup.class); - when(s1.getId()).thenReturn("s1"); + + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + vrpBuilder.addJob(s1).addJob(s2); + + VehicleRoutingProblem vrp = vrpBuilder.build(); + + assertEquals(2, vrp.getJobs().size()); + assertEquals(s1, vrp.getJobs().get("s1")); + assertEquals(s2, vrp.getJobs().get("s2")); + } + + @Test + public void whenPickupsAreAddedAllAtOnce_vrpShouldContainThem() { + Pickup s1 = mock(Pickup.class); + when(s1.getId()).thenReturn("s1"); when(s1.getLocation()).thenReturn(Location.Builder.newInstance().setIndex(1).build()); - Pickup s2 = mock(Pickup.class); - when(s2.getId()).thenReturn("s2"); + Pickup s2 = mock(Pickup.class); + when(s2.getId()).thenReturn("s2"); when(s2.getLocation()).thenReturn(Location.Builder.newInstance().setIndex(1).build()); - - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - vrpBuilder.addAllJobs(Arrays.asList(s1,s2)); - - VehicleRoutingProblem vrp = vrpBuilder.build(); - - assertEquals(2,vrp.getJobs().size()); - assertEquals(s1,vrp.getJobs().get("s1")); - assertEquals(s2,vrp.getJobs().get("s2")); - } - - @Test - public void whenDelivieriesAreAdded_vrpShouldContainThem(){ - Delivery s1 = mock(Delivery.class); - when(s1.getId()).thenReturn("s1"); + + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + vrpBuilder.addAllJobs(Arrays.asList(s1, s2)); + + VehicleRoutingProblem vrp = vrpBuilder.build(); + + assertEquals(2, vrp.getJobs().size()); + assertEquals(s1, vrp.getJobs().get("s1")); + assertEquals(s2, vrp.getJobs().get("s2")); + } + + @Test + public void whenDelivieriesAreAdded_vrpShouldContainThem() { + Delivery s1 = mock(Delivery.class); + when(s1.getId()).thenReturn("s1"); when(s1.getSize()).thenReturn(Capacity.Builder.newInstance().build()); when(s1.getLocation()).thenReturn(Location.Builder.newInstance().setIndex(1).build()); - Delivery s2 = mock(Delivery.class); - when(s2.getId()).thenReturn("s2"); + Delivery s2 = mock(Delivery.class); + when(s2.getId()).thenReturn("s2"); when(s2.getSize()).thenReturn(Capacity.Builder.newInstance().build()); when(s2.getLocation()).thenReturn(Location.Builder.newInstance().setIndex(1).build()); - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - vrpBuilder.addJob(s1).addJob(s2); - - VehicleRoutingProblem vrp = vrpBuilder.build(); - - assertEquals(2,vrp.getJobs().size()); - assertEquals(s1,vrp.getJobs().get("s1")); - assertEquals(s2,vrp.getJobs().get("s2")); - } - - @Test - public void whenDelivieriesAreAddedAllAtOnce_vrpShouldContainThem(){ - Delivery s1 = mock(Delivery.class); - when(s1.getId()).thenReturn("s1"); + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + vrpBuilder.addJob(s1).addJob(s2); + + VehicleRoutingProblem vrp = vrpBuilder.build(); + + assertEquals(2, vrp.getJobs().size()); + assertEquals(s1, vrp.getJobs().get("s1")); + assertEquals(s2, vrp.getJobs().get("s2")); + } + + @Test + public void whenDelivieriesAreAddedAllAtOnce_vrpShouldContainThem() { + Delivery s1 = mock(Delivery.class); + when(s1.getId()).thenReturn("s1"); when(s1.getSize()).thenReturn(Capacity.Builder.newInstance().build()); when(s1.getLocation()).thenReturn(Location.Builder.newInstance().setIndex(1).build()); - Delivery s2 = mock(Delivery.class); - when(s2.getId()).thenReturn("s2"); + Delivery s2 = mock(Delivery.class); + when(s2.getId()).thenReturn("s2"); when(s2.getSize()).thenReturn(Capacity.Builder.newInstance().build()); when(s2.getLocation()).thenReturn(Location.Builder.newInstance().setIndex(1).build()); - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - vrpBuilder.addAllJobs(Arrays.asList(s1,s2)); - - VehicleRoutingProblem vrp = vrpBuilder.build(); - - assertEquals(2,vrp.getJobs().size()); - assertEquals(s1,vrp.getJobs().get("s1")); - assertEquals(s2,vrp.getJobs().get("s2")); - } - - @Test - public void whenServicesAreAddedAllAtOnce_vrpShouldContainThem(){ - Service s1 = mock(Service.class); - when(s1.getId()).thenReturn("s1"); + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + vrpBuilder.addAllJobs(Arrays.asList(s1, s2)); + + VehicleRoutingProblem vrp = vrpBuilder.build(); + + assertEquals(2, vrp.getJobs().size()); + assertEquals(s1, vrp.getJobs().get("s1")); + assertEquals(s2, vrp.getJobs().get("s2")); + } + + @Test + public void whenServicesAreAddedAllAtOnce_vrpShouldContainThem() { + Service s1 = mock(Service.class); + when(s1.getId()).thenReturn("s1"); when(s1.getLocation()).thenReturn(Location.Builder.newInstance().setIndex(1).build()); - Service s2 = mock(Service.class); - when(s2.getId()).thenReturn("s2"); + Service s2 = mock(Service.class); + when(s2.getId()).thenReturn("s2"); when(s2.getLocation()).thenReturn(Location.Builder.newInstance().setIndex(1).build()); - - Collection services = new ArrayList(); - services.add(s1); - services.add(s2); - - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - vrpBuilder.addAllJobs(services); - - VehicleRoutingProblem vrp = vrpBuilder.build(); - - assertEquals(2,vrp.getJobs().size()); - assertEquals(s1,vrp.getJobs().get("s1")); - assertEquals(s2,vrp.getJobs().get("s2")); - } - - - @Test - public void whenSettingActivityCosts_vrpShouldContainIt(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - builder.setActivityCosts(new VehicleRoutingActivityCosts(){ + Collection services = new ArrayList(); + services.add(s1); + services.add(s2); - @Override - public double getActivityCost(TourActivity tourAct,double arrivalTime, Driver driver, Vehicle vehicle) { - return 4.0; - } - - }); - - VehicleRoutingProblem problem = builder.build(); - assertEquals(4.0,problem.getActivityCosts().getActivityCost(null, 0.0, null, null),0.01); - } - - @Test - public void whenSettingRoutingCosts_vprShouldContainIt(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - - builder.setRoutingCost(new AbstractForwardVehicleRoutingTransportCosts() { - - @Override - public double getTransportTime(Location from, Location to, - double departureTime, Driver driver, Vehicle vehicle) { - return 0; - } - - @Override - public double getTransportCost(Location from, Location to, - double departureTime, Driver driver, Vehicle vehicle) { - return 4.0; - } - }); - - VehicleRoutingProblem problem = builder.build(); - assertEquals(4.0,problem.getTransportCosts().getTransportCost(loc(""), loc(""), 0.0, null, null),0.01); - } + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + vrpBuilder.addAllJobs(services); + + VehicleRoutingProblem vrp = vrpBuilder.build(); + + assertEquals(2, vrp.getJobs().size()); + assertEquals(s1, vrp.getJobs().get("s1")); + assertEquals(s2, vrp.getJobs().get("s2")); + } + + + @Test + public void whenSettingActivityCosts_vrpShouldContainIt() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + builder.setActivityCosts(new VehicleRoutingActivityCosts() { + + @Override + public double getActivityCost(TourActivity tourAct, double arrivalTime, Driver driver, Vehicle vehicle) { + return 4.0; + } + + }); + + VehicleRoutingProblem problem = builder.build(); + assertEquals(4.0, problem.getActivityCosts().getActivityCost(null, 0.0, null, null), 0.01); + } + + @Test + public void whenSettingRoutingCosts_vprShouldContainIt() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + + builder.setRoutingCost(new AbstractForwardVehicleRoutingTransportCosts() { + + @Override + public double getTransportTime(Location from, Location to, + double departureTime, Driver driver, Vehicle vehicle) { + return 0; + } + + @Override + public double getTransportCost(Location from, Location to, + double departureTime, Driver driver, Vehicle vehicle) { + return 4.0; + } + }); + + VehicleRoutingProblem problem = builder.build(); + assertEquals(4.0, problem.getTransportCosts().getTransportCost(loc(""), loc(""), 0.0, null, null), 0.01); + } private Location loc(String i) { return Location.Builder.newInstance().setId(i).build(); } - - @Test - public void whenAddingAVehicle_getAddedVehicleTypesShouldReturnItsType(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - VehicleType type = VehicleTypeImpl.Builder.newInstance("type").build(); - VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("loc")).setType(type).build(); - builder.addVehicle(vehicle); - - assertEquals(1,builder.getAddedVehicleTypes().size()); - assertEquals(type,builder.getAddedVehicleTypes().iterator().next()); - - } - - @Test - public void whenAddingTwoVehicleWithSameType_getAddedVehicleTypesShouldReturnOnlyOneType(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - VehicleType type = VehicleTypeImpl.Builder.newInstance("type").build(); - VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("loc")).setType(type).build(); - VehicleImpl vehicle2 = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("loc")).setType(type).build(); - - builder.addVehicle(vehicle); - builder.addVehicle(vehicle2); - - assertEquals(1,builder.getAddedVehicleTypes().size()); - assertEquals(type,builder.getAddedVehicleTypes().iterator().next()); - } - - @Test - public void whenAddingTwoVehicleWithDiffType_getAddedVehicleTypesShouldReturnTheseType(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - VehicleType type = VehicleTypeImpl.Builder.newInstance("type").build(); - VehicleType type2 = VehicleTypeImpl.Builder.newInstance("type2").build(); - - VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("loc")).setType(type).build(); - VehicleImpl vehicle2 = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("loc")).setType(type2).build(); - - builder.addVehicle(vehicle); - builder.addVehicle(vehicle2); - - assertEquals(2,builder.getAddedVehicleTypes().size()); - - } - - - @Test - public void whenAddingVehicleWithDiffStartAndEnd_startLocationMustBeRegisteredInLocationMap(){ - VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")) - .setEndLocation(Location.newInstance("end")).build(); - - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - vrpBuilder.addVehicle(vehicle); - assertTrue(vrpBuilder.getLocationMap().containsKey("start")); - } - - @Test - public void whenAddingVehicleWithDiffStartAndEnd_endLocationMustBeRegisteredInLocationMap(){ - VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")) - .setEndLocation(Location.newInstance("end")).build(); - - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - vrpBuilder.addVehicle(vehicle); - assertTrue(vrpBuilder.getLocationMap().containsKey("end")); - } - - @Test - public void whenAddingInitialRoute_itShouldBeAddedCorrectly(){ - VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v") - .setStartLocation(Location.newInstance("start")).setEndLocation(Location.newInstance("end")).build(); - VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build(); - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - vrpBuilder.addInitialVehicleRoute(route); - VehicleRoutingProblem vrp = vrpBuilder.build(); - assertTrue(!vrp.getInitialVehicleRoutes().isEmpty()); - } - - @Test - public void whenAddingInitialRoutes_theyShouldBeAddedCorrectly(){ - VehicleImpl vehicle1 = VehicleImpl.Builder.newInstance("v") - .setStartLocation(Location.newInstance("start")).setEndLocation(Location.newInstance("end")).build(); - VehicleRoute route1 = VehicleRoute.Builder.newInstance(vehicle1, DriverImpl.noDriver()).build(); - - VehicleImpl vehicle2 = VehicleImpl.Builder.newInstance("v") - .setStartLocation(Location.newInstance("start")).setEndLocation(Location.newInstance("end")).build(); - VehicleRoute route2 = VehicleRoute.Builder.newInstance(vehicle2, DriverImpl.noDriver()).build(); - - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - vrpBuilder.addInitialVehicleRoutes(Arrays.asList(route1,route2)); - - VehicleRoutingProblem vrp = vrpBuilder.build(); - assertEquals(2,vrp.getInitialVehicleRoutes().size()); - } - - @Test - public void whenAddingInitialRoute_locationOfVehicleMustBeMemorized(){ - VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v") - .setStartLocation(TestUtils.loc("start", Coordinate.newInstance(0, 1))) - .setEndLocation(Location.newInstance("end")).build(); - VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build(); - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - vrpBuilder.addInitialVehicleRoute(route); - VehicleRoutingProblem vrp = vrpBuilder.build(); - assertEquals(0.,vrp.getLocations().getCoord("start").getX(),0.01); - assertEquals(1.,vrp.getLocations().getCoord("start").getY(),0.01); - } - - @Test - public void whenAddingJobAndInitialRouteWithThatJobAfterwards_thisJobShouldNotBeInFinalJobMap(){ - Service service = Service.Builder.newInstance("myService").setLocation(Location.newInstance("loc")).build(); - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - vrpBuilder.addJob(service); - VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v") - .setStartLocation(TestUtils.loc("start", Coordinate.newInstance(0, 1))) - .setEndLocation(Location.newInstance("end")).build(); - VehicleRoute initialRoute = VehicleRoute.Builder.newInstance(vehicle).addService(service).build(); - vrpBuilder.addInitialVehicleRoute(initialRoute); - VehicleRoutingProblem vrp = vrpBuilder.build(); - assertFalse(vrp.getJobs().containsKey("myService")); - } @Test - public void whenAddingTwoJobs_theyShouldHaveProperIndeces(){ - Service service = Service.Builder.newInstance("myService").setLocation(Location.newInstance("loc")).build(); - Shipment shipment = Shipment.Builder.newInstance("shipment").setPickupLocation(Location.Builder.newInstance().setId("pick").build()) - .setDeliveryLocation(Location.newInstance("del")).build(); - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - vrpBuilder.addJob(service); - vrpBuilder.addJob(shipment); - vrpBuilder.build(); + public void whenAddingAVehicle_getAddedVehicleTypesShouldReturnItsType() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + VehicleType type = VehicleTypeImpl.Builder.newInstance("type").build(); + VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("loc")).setType(type).build(); + builder.addVehicle(vehicle); + + assertEquals(1, builder.getAddedVehicleTypes().size()); + assertEquals(type, builder.getAddedVehicleTypes().iterator().next()); - assertEquals(1,service.getIndex()); - assertEquals(2,shipment.getIndex()); } @Test - public void whenAddingTwoVehicles_theyShouldHaveProperIndices(){ + public void whenAddingTwoVehicleWithSameType_getAddedVehicleTypesShouldReturnOnlyOneType() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + VehicleType type = VehicleTypeImpl.Builder.newInstance("type").build(); + VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("loc")).setType(type).build(); + VehicleImpl vehicle2 = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("loc")).setType(type).build(); + + builder.addVehicle(vehicle); + builder.addVehicle(vehicle2); + + assertEquals(1, builder.getAddedVehicleTypes().size()); + assertEquals(type, builder.getAddedVehicleTypes().iterator().next()); + } + + @Test + public void whenAddingTwoVehicleWithDiffType_getAddedVehicleTypesShouldReturnTheseType() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + VehicleType type = VehicleTypeImpl.Builder.newInstance("type").build(); + VehicleType type2 = VehicleTypeImpl.Builder.newInstance("type2").build(); + + VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("loc")).setType(type).build(); + VehicleImpl vehicle2 = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("loc")).setType(type2).build(); + + builder.addVehicle(vehicle); + builder.addVehicle(vehicle2); + + assertEquals(2, builder.getAddedVehicleTypes().size()); + + } + + + @Test + public void whenAddingVehicleWithDiffStartAndEnd_startLocationMustBeRegisteredInLocationMap() { + VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")) + .setEndLocation(Location.newInstance("end")).build(); + + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + vrpBuilder.addVehicle(vehicle); + assertTrue(vrpBuilder.getLocationMap().containsKey("start")); + } + + @Test + public void whenAddingVehicleWithDiffStartAndEnd_endLocationMustBeRegisteredInLocationMap() { + VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")) + .setEndLocation(Location.newInstance("end")).build(); + + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + vrpBuilder.addVehicle(vehicle); + assertTrue(vrpBuilder.getLocationMap().containsKey("end")); + } + + @Test + public void whenAddingInitialRoute_itShouldBeAddedCorrectly() { + VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v") + .setStartLocation(Location.newInstance("start")).setEndLocation(Location.newInstance("end")).build(); + VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build(); + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + vrpBuilder.addInitialVehicleRoute(route); + VehicleRoutingProblem vrp = vrpBuilder.build(); + assertTrue(!vrp.getInitialVehicleRoutes().isEmpty()); + } + + @Test + public void whenAddingInitialRoutes_theyShouldBeAddedCorrectly() { + VehicleImpl vehicle1 = VehicleImpl.Builder.newInstance("v") + .setStartLocation(Location.newInstance("start")).setEndLocation(Location.newInstance("end")).build(); + VehicleRoute route1 = VehicleRoute.Builder.newInstance(vehicle1, DriverImpl.noDriver()).build(); + + VehicleImpl vehicle2 = VehicleImpl.Builder.newInstance("v") + .setStartLocation(Location.newInstance("start")).setEndLocation(Location.newInstance("end")).build(); + VehicleRoute route2 = VehicleRoute.Builder.newInstance(vehicle2, DriverImpl.noDriver()).build(); + + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + vrpBuilder.addInitialVehicleRoutes(Arrays.asList(route1, route2)); + + VehicleRoutingProblem vrp = vrpBuilder.build(); + assertEquals(2, vrp.getInitialVehicleRoutes().size()); + assertEquals(2,vrp.getAllLocations().size()); + } + + @Test + public void whenAddingInitialRoute_locationOfVehicleMustBeMemorized() { + VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v") + .setStartLocation(TestUtils.loc("start", Coordinate.newInstance(0, 1))) + .setEndLocation(Location.newInstance("end")).build(); + VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build(); + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + vrpBuilder.addInitialVehicleRoute(route); + VehicleRoutingProblem vrp = vrpBuilder.build(); + assertEquals(0., vrp.getLocations().getCoord("start").getX(), 0.01); + assertEquals(1., vrp.getLocations().getCoord("start").getY(), 0.01); + } + + @Test + public void whenAddingJobAndInitialRouteWithThatJobAfterwards_thisJobShouldNotBeInFinalJobMap() { + Service service = Service.Builder.newInstance("myService").setLocation(Location.newInstance("loc")).build(); + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + vrpBuilder.addJob(service); + VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v") + .setStartLocation(TestUtils.loc("start", Coordinate.newInstance(0, 1))) + .setEndLocation(Location.newInstance("end")).build(); + VehicleRoute initialRoute = VehicleRoute.Builder.newInstance(vehicle).addService(service).build(); + vrpBuilder.addInitialVehicleRoute(initialRoute); + VehicleRoutingProblem vrp = vrpBuilder.build(); + assertFalse(vrp.getJobs().containsKey("myService")); + assertEquals(3,vrp.getAllLocations().size()); + } + + @Test + public void whenAddingTwoJobs_theyShouldHaveProperIndeces() { + Service service = Service.Builder.newInstance("myService").setLocation(Location.newInstance("loc")).build(); + Shipment shipment = Shipment.Builder.newInstance("shipment").setPickupLocation(Location.Builder.newInstance().setId("pick").build()) + .setDeliveryLocation(Location.newInstance("del")).build(); + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + vrpBuilder.addJob(service); + vrpBuilder.addJob(shipment); + VehicleRoutingProblem vrp = vrpBuilder.build(); + + assertEquals(1, service.getIndex()); + assertEquals(2, shipment.getIndex()); + assertEquals(3,vrp.getAllLocations().size()); + + } + + @Test + public void whenAddingTwoVehicles_theyShouldHaveProperIndices() { VehicleImpl veh1 = VehicleImpl.Builder.newInstance("v1").setStartLocation(TestUtils.loc("start", Coordinate.newInstance(0, 1))) - .setEndLocation(Location.newInstance("end")).build(); + .setEndLocation(Location.newInstance("end")).build(); VehicleImpl veh2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(TestUtils.loc("start", Coordinate.newInstance(0, 1))) - .setEndLocation(Location.newInstance("end")).build(); + .setEndLocation(Location.newInstance("end")).build(); VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); vrpBuilder.addVehicle(veh1); vrpBuilder.addVehicle(veh2); vrpBuilder.build(); - assertEquals(1,veh1.getIndex()); - assertEquals(2,veh2.getIndex()); + assertEquals(1, veh1.getIndex()); + assertEquals(2, veh2.getIndex()); } @Test - public void whenAddingTwoVehiclesWithSameTypeIdentifier_typeIdentifiersShouldHaveSameIndices(){ + public void whenAddingTwoVehiclesWithSameTypeIdentifier_typeIdentifiersShouldHaveSameIndices() { VehicleImpl veh1 = VehicleImpl.Builder.newInstance("v1") - .setStartLocation(TestUtils.loc("start", Coordinate.newInstance(0, 1))) - .setEndLocation(Location.newInstance("end")).build(); + .setStartLocation(TestUtils.loc("start", Coordinate.newInstance(0, 1))) + .setEndLocation(Location.newInstance("end")).build(); VehicleImpl veh2 = VehicleImpl.Builder.newInstance("v2") - .setStartLocation(TestUtils.loc("start", Coordinate.newInstance(0, 1))) - .setEndLocation(Location.newInstance("end")).build(); + .setStartLocation(TestUtils.loc("start", Coordinate.newInstance(0, 1))) + .setEndLocation(Location.newInstance("end")).build(); VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); vrpBuilder.addVehicle(veh1); @@ -465,21 +471,21 @@ public class VehicleRoutingProblemTest { } @Test - public void whenAddingTwoVehiclesDifferentTypeIdentifier_typeIdentifiersShouldHaveDifferentIndices(){ + public void whenAddingTwoVehiclesDifferentTypeIdentifier_typeIdentifiersShouldHaveDifferentIndices() { VehicleImpl veh1 = VehicleImpl.Builder.newInstance("v1") - .setStartLocation(TestUtils.loc("start", Coordinate.newInstance(0, 1))) - .setEndLocation(Location.newInstance("end")).build(); + .setStartLocation(TestUtils.loc("start", Coordinate.newInstance(0, 1))) + .setEndLocation(Location.newInstance("end")).build(); VehicleImpl veh2 = VehicleImpl.Builder.newInstance("v2") - .setStartLocation(TestUtils.loc("startLoc",Coordinate.newInstance(0, 1))) - .setEndLocation(Location.newInstance("end")).build(); + .setStartLocation(TestUtils.loc("startLoc", Coordinate.newInstance(0, 1))) + .setEndLocation(Location.newInstance("end")).build(); VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); vrpBuilder.addVehicle(veh1); vrpBuilder.addVehicle(veh2); vrpBuilder.build(); - assertEquals(1,veh1.getVehicleTypeIdentifier().getIndex()); - assertEquals(2,veh2.getVehicleTypeIdentifier().getIndex()); + assertEquals(1, veh1.getVehicleTypeIdentifier().getIndex()); + assertEquals(2, veh2.getVehicleTypeIdentifier().getIndex()); } } diff --git a/jsprit-core/src/test/java/jsprit/core/problem/constraint/LoadConstraintTest.java b/jsprit-core/src/test/java/jsprit/core/problem/constraint/LoadConstraintTest.java index 1874f592..193e2186 100644 --- a/jsprit-core/src/test/java/jsprit/core/problem/constraint/LoadConstraintTest.java +++ b/jsprit-core/src/test/java/jsprit/core/problem/constraint/LoadConstraintTest.java @@ -50,21 +50,21 @@ public class LoadConstraintTest { private StateManager stateManager; @Before - public void doBefore(){ + public void doBefore() { Vehicle vehicle = mock(Vehicle.class); VehicleType type = mock(VehicleType.class); - when(type.getCapacityDimensions()).thenReturn(Capacity.Builder.newInstance().addDimension(0,20).build()); + when(type.getCapacityDimensions()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 20).build()); when(vehicle.getType()).thenReturn(type); VehicleRoutingProblem.Builder serviceProblemBuilder = VehicleRoutingProblem.Builder.newInstance(); Service s1 = Service.Builder.newInstance("s").addSizeDimension(0, 10).setLocation(Location.newInstance("loc")).build(); - Service s2 = Service.Builder.newInstance("s2").addSizeDimension(0,5).setLocation(Location.newInstance("loc")).build(); + Service s2 = Service.Builder.newInstance("s2").addSizeDimension(0, 5).setLocation(Location.newInstance("loc")).build(); serviceProblemBuilder.addJob(s1).addJob(s2); final VehicleRoutingProblem serviceProblem = serviceProblemBuilder.build(); final VehicleRoutingProblem.Builder pdProblemBuilder = VehicleRoutingProblem.Builder.newInstance(); - Pickup pickup = (Pickup) Pickup.Builder.newInstance("pick").addSizeDimension(0,10).setLocation(Location.newInstance("loc")).build(); - Delivery delivery = (Delivery) Delivery.Builder.newInstance("del").addSizeDimension(0,5).setLocation(Location.newInstance("loc")).build(); + Pickup pickup = (Pickup) Pickup.Builder.newInstance("pick").addSizeDimension(0, 10).setLocation(Location.newInstance("loc")).build(); + Delivery delivery = (Delivery) Delivery.Builder.newInstance("del").addSizeDimension(0, 5).setLocation(Location.newInstance("loc")).build(); pdProblemBuilder.addJob(pickup).addJob(delivery); final VehicleRoutingProblem pdProblem = pdProblemBuilder.build(); @@ -103,7 +103,9 @@ public class LoadConstraintTest { }); shipment_route = shipmentRouteBuilder.addPickup(shipment1).addPickup(shipment2).addDelivery(shipment2).addDelivery(shipment1).build(); - stateManager = new StateManager(mock(VehicleRoutingProblem.class)); + VehicleRoutingProblem vrpMock = mock(VehicleRoutingProblem.class); + when(vrpMock.getFleetSize()).thenReturn(VehicleRoutingProblem.FleetSize.FINITE); + stateManager = new StateManager(vrpMock); stateManager.updateLoadStates(); } @@ -112,79 +114,79 @@ public class LoadConstraintTest { serviceroute */ @Test - public void whenServiceRouteAndNewServiceFitsIn_itShouldReturnFulfilled(){ + public void whenServiceRouteAndNewServiceFitsIn_itShouldReturnFulfilled() { stateManager.informInsertionStarts(Arrays.asList(serviceRoute), Collections.emptyList()); Service s = mock(Service.class); - when(s.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0,5).build()); + when(s.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 5).build()); ServiceLoadRouteLevelConstraint loadconstraint = new ServiceLoadRouteLevelConstraint(stateManager); - JobInsertionContext context = new JobInsertionContext(serviceRoute,s,serviceRoute.getVehicle(),null,0.); + JobInsertionContext context = new JobInsertionContext(serviceRoute, s, serviceRoute.getVehicle(), null, 0.); assertTrue(loadconstraint.fulfilled(context)); } @Test - public void whenServiceRouteAndNewServiceFitsInBetweenStartAndAct1_itShouldReturnFulfilled(){ + public void whenServiceRouteAndNewServiceFitsInBetweenStartAndAct1_itShouldReturnFulfilled() { stateManager.informInsertionStarts(Arrays.asList(serviceRoute), Collections.emptyList()); Service s = mock(Service.class); Capacity newSize = Capacity.Builder.newInstance().addDimension(0, 5).build(); when(s.getSize()).thenReturn(newSize); ServiceLoadActivityLevelConstraint loadConstraint = new ServiceLoadActivityLevelConstraint(stateManager); - JobInsertionContext context = new JobInsertionContext(serviceRoute,s,serviceRoute.getVehicle(),null,0.); + JobInsertionContext context = new JobInsertionContext(serviceRoute, s, serviceRoute.getVehicle(), null, 0.); ServiceActivity newAct = mock(ServiceActivity.class); when(newAct.getSize()).thenReturn(newSize); HardActivityConstraint.ConstraintsStatus status = loadConstraint.fulfilled(context, serviceRoute.getStart(), newAct, serviceRoute.getActivities().get(0), 0.); - assertEquals(HardActivityConstraint.ConstraintsStatus.FULFILLED,status); + assertEquals(HardActivityConstraint.ConstraintsStatus.FULFILLED, status); } @Test - public void whenServiceRouteAndNewServiceFitsInBetweenAc1AndAct2_itShouldReturnFulfilled(){ + public void whenServiceRouteAndNewServiceFitsInBetweenAc1AndAct2_itShouldReturnFulfilled() { stateManager.informInsertionStarts(Arrays.asList(serviceRoute), Collections.emptyList()); Service s = mock(Service.class); Capacity newSize = Capacity.Builder.newInstance().addDimension(0, 5).build(); when(s.getSize()).thenReturn(newSize); ServiceLoadActivityLevelConstraint loadConstraint = new ServiceLoadActivityLevelConstraint(stateManager); - JobInsertionContext context = new JobInsertionContext(serviceRoute,s,serviceRoute.getVehicle(),null,0.); + JobInsertionContext context = new JobInsertionContext(serviceRoute, s, serviceRoute.getVehicle(), null, 0.); ServiceActivity newAct = mock(ServiceActivity.class); when(newAct.getSize()).thenReturn(newSize); HardActivityConstraint.ConstraintsStatus status = loadConstraint.fulfilled(context, serviceRoute.getActivities().get(0), newAct, serviceRoute.getActivities().get(1), 0.); - assertEquals(HardActivityConstraint.ConstraintsStatus.FULFILLED,status); + assertEquals(HardActivityConstraint.ConstraintsStatus.FULFILLED, status); } @Test - public void whenServiceRouteAndNewServiceFitsInBetweenAc2AndEnd_itShouldReturnFulfilled(){ + public void whenServiceRouteAndNewServiceFitsInBetweenAc2AndEnd_itShouldReturnFulfilled() { stateManager.informInsertionStarts(Arrays.asList(serviceRoute), Collections.emptyList()); Service s = mock(Service.class); Capacity newSize = Capacity.Builder.newInstance().addDimension(0, 5).build(); when(s.getSize()).thenReturn(newSize); ServiceLoadActivityLevelConstraint loadConstraint = new ServiceLoadActivityLevelConstraint(stateManager); - JobInsertionContext context = new JobInsertionContext(serviceRoute,s,serviceRoute.getVehicle(),null,0.); + JobInsertionContext context = new JobInsertionContext(serviceRoute, s, serviceRoute.getVehicle(), null, 0.); ServiceActivity newAct = mock(ServiceActivity.class); when(newAct.getSize()).thenReturn(newSize); HardActivityConstraint.ConstraintsStatus status = loadConstraint.fulfilled(context, serviceRoute.getActivities().get(1), newAct, serviceRoute.getEnd(), 0.); - assertEquals(HardActivityConstraint.ConstraintsStatus.FULFILLED,status); + assertEquals(HardActivityConstraint.ConstraintsStatus.FULFILLED, status); } /* service does not fit in at act level */ @Test - public void whenServiceRouteAndNewServiceDoesNotFitInBetweenStartAndAct1_itShouldReturnFulfilled(){ + public void whenServiceRouteAndNewServiceDoesNotFitInBetweenStartAndAct1_itShouldReturnFulfilled() { stateManager.informInsertionStarts(Arrays.asList(serviceRoute), Collections.emptyList()); Service s = mock(Service.class); Capacity newSize = Capacity.Builder.newInstance().addDimension(0, 6).build(); when(s.getSize()).thenReturn(newSize); ServiceLoadActivityLevelConstraint loadConstraint = new ServiceLoadActivityLevelConstraint(stateManager); - JobInsertionContext context = new JobInsertionContext(serviceRoute,s,serviceRoute.getVehicle(),null,0.); + JobInsertionContext context = new JobInsertionContext(serviceRoute, s, serviceRoute.getVehicle(), null, 0.); ServiceActivity newAct = mock(ServiceActivity.class); when(newAct.getSize()).thenReturn(newSize); @@ -194,14 +196,14 @@ public class LoadConstraintTest { } @Test - public void whenServiceRouteAndNewServiceDoesNotFitInBetweenAc1AndAct2_itShouldReturnFulfilled(){ + public void whenServiceRouteAndNewServiceDoesNotFitInBetweenAc1AndAct2_itShouldReturnFulfilled() { stateManager.informInsertionStarts(Arrays.asList(serviceRoute), Collections.emptyList()); Service s = mock(Service.class); Capacity newSize = Capacity.Builder.newInstance().addDimension(0, 6).build(); when(s.getSize()).thenReturn(newSize); ServiceLoadActivityLevelConstraint loadConstraint = new ServiceLoadActivityLevelConstraint(stateManager); - JobInsertionContext context = new JobInsertionContext(serviceRoute,s,serviceRoute.getVehicle(),null,0.); + JobInsertionContext context = new JobInsertionContext(serviceRoute, s, serviceRoute.getVehicle(), null, 0.); ServiceActivity newAct = mock(ServiceActivity.class); when(newAct.getSize()).thenReturn(newSize); @@ -211,14 +213,14 @@ public class LoadConstraintTest { } @Test - public void whenServiceRouteAndNewServiceDoesNotFitInBetweenAc2AndEnd_itShouldReturnFulfilled(){ + public void whenServiceRouteAndNewServiceDoesNotFitInBetweenAc2AndEnd_itShouldReturnFulfilled() { stateManager.informInsertionStarts(Arrays.asList(serviceRoute), Collections.emptyList()); Service s = mock(Service.class); Capacity newSize = Capacity.Builder.newInstance().addDimension(0, 6).build(); when(s.getSize()).thenReturn(newSize); ServiceLoadActivityLevelConstraint loadConstraint = new ServiceLoadActivityLevelConstraint(stateManager); - JobInsertionContext context = new JobInsertionContext(serviceRoute,s,serviceRoute.getVehicle(),null,0.); + JobInsertionContext context = new JobInsertionContext(serviceRoute, s, serviceRoute.getVehicle(), null, 0.); ServiceActivity newAct = mock(ServiceActivity.class); when(newAct.getSize()).thenReturn(newSize); @@ -229,13 +231,13 @@ public class LoadConstraintTest { @Test - public void whenServiceRouteAndNewServiceDoesNotFitIn_itShouldReturnFulfilled(){ + public void whenServiceRouteAndNewServiceDoesNotFitIn_itShouldReturnFulfilled() { stateManager.informInsertionStarts(Arrays.asList(serviceRoute), Collections.emptyList()); Service s = mock(Service.class); - when(s.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0,6).build()); + when(s.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 6).build()); ServiceLoadRouteLevelConstraint loadconstraint = new ServiceLoadRouteLevelConstraint(stateManager); - JobInsertionContext context = new JobInsertionContext(serviceRoute,s,serviceRoute.getVehicle(),null,0.); + JobInsertionContext context = new JobInsertionContext(serviceRoute, s, serviceRoute.getVehicle(), null, 0.); assertFalse(loadconstraint.fulfilled(context)); } @@ -245,46 +247,46 @@ public class LoadConstraintTest { delivery 5 */ @Test - public void whenPDRouteRouteAndNewPickupFitsIn_itShouldReturnFulfilled(){ + public void whenPDRouteRouteAndNewPickupFitsIn_itShouldReturnFulfilled() { stateManager.informInsertionStarts(Arrays.asList(pickup_delivery_route), Collections.emptyList()); Pickup s = mock(Pickup.class); - when(s.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0,10).build()); + when(s.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 10).build()); ServiceLoadRouteLevelConstraint loadconstraint = new ServiceLoadRouteLevelConstraint(stateManager); - JobInsertionContext context = new JobInsertionContext(pickup_delivery_route,s,serviceRoute.getVehicle(),null,0.); + JobInsertionContext context = new JobInsertionContext(pickup_delivery_route, s, serviceRoute.getVehicle(), null, 0.); assertTrue(loadconstraint.fulfilled(context)); } @Test - public void whenPDRouteRouteAndNewDeliveryFitsIn_itShouldReturnFulfilled(){ + public void whenPDRouteRouteAndNewDeliveryFitsIn_itShouldReturnFulfilled() { stateManager.informInsertionStarts(Arrays.asList(pickup_delivery_route), Collections.emptyList()); Delivery s = mock(Delivery.class); - when(s.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0,15).build()); + when(s.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 15).build()); ServiceLoadRouteLevelConstraint loadconstraint = new ServiceLoadRouteLevelConstraint(stateManager); - JobInsertionContext context = new JobInsertionContext(pickup_delivery_route,s,serviceRoute.getVehicle(),null,0.); + JobInsertionContext context = new JobInsertionContext(pickup_delivery_route, s, serviceRoute.getVehicle(), null, 0.); assertTrue(loadconstraint.fulfilled(context)); } @Test - public void whenPDRouteRouteAndNewPickupDoesNotFitIn_itShouldReturnNotFulfilled(){ + public void whenPDRouteRouteAndNewPickupDoesNotFitIn_itShouldReturnNotFulfilled() { stateManager.informInsertionStarts(Arrays.asList(pickup_delivery_route), Collections.emptyList()); Pickup s = mock(Pickup.class); - when(s.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0,11).build()); + when(s.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 11).build()); ServiceLoadRouteLevelConstraint loadconstraint = new ServiceLoadRouteLevelConstraint(stateManager); - JobInsertionContext context = new JobInsertionContext(pickup_delivery_route,s,serviceRoute.getVehicle(),null,0.); + JobInsertionContext context = new JobInsertionContext(pickup_delivery_route, s, serviceRoute.getVehicle(), null, 0.); assertFalse(loadconstraint.fulfilled(context)); } @Test - public void whenPDRouteRouteAndNewDeliveryDoesNotFitIn_itShouldReturnNotFulfilled(){ + public void whenPDRouteRouteAndNewDeliveryDoesNotFitIn_itShouldReturnNotFulfilled() { stateManager.informInsertionStarts(Arrays.asList(pickup_delivery_route), Collections.emptyList()); Delivery s = mock(Delivery.class); - when(s.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0,16).build()); + when(s.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 16).build()); ServiceLoadRouteLevelConstraint loadconstraint = new ServiceLoadRouteLevelConstraint(stateManager); - JobInsertionContext context = new JobInsertionContext(pickup_delivery_route,s,serviceRoute.getVehicle(),null,0.); + JobInsertionContext context = new JobInsertionContext(pickup_delivery_route, s, serviceRoute.getVehicle(), null, 0.); assertFalse(loadconstraint.fulfilled(context)); } @@ -292,102 +294,102 @@ public class LoadConstraintTest { pick fits in between activities */ @Test - public void whenPDRoute_newPickupShouldFitInBetweenStartAndAct1(){ + public void whenPDRoute_newPickupShouldFitInBetweenStartAndAct1() { stateManager.informInsertionStarts(Arrays.asList(pickup_delivery_route), Collections.emptyList()); Pickup s = mock(Pickup.class); Capacity newSize = Capacity.Builder.newInstance().addDimension(0, 5).build(); when(s.getSize()).thenReturn(newSize); ServiceLoadActivityLevelConstraint loadConstraint = new ServiceLoadActivityLevelConstraint(stateManager); - JobInsertionContext context = new JobInsertionContext(pickup_delivery_route,s,pickup_delivery_route.getVehicle(),null,0.); + JobInsertionContext context = new JobInsertionContext(pickup_delivery_route, s, pickup_delivery_route.getVehicle(), null, 0.); PickupService newAct = new PickupService(s); HardActivityConstraint.ConstraintsStatus status = loadConstraint.fulfilled(context, pickup_delivery_route.getStart(), newAct, pickup_delivery_route.getActivities().get(0), 0.); - assertEquals(HardActivityConstraint.ConstraintsStatus.FULFILLED,status); + assertEquals(HardActivityConstraint.ConstraintsStatus.FULFILLED, status); } @Test - public void whenPDRoute_newPickupShouldFitInBetweenAct1AndAct2(){ + public void whenPDRoute_newPickupShouldFitInBetweenAct1AndAct2() { stateManager.informInsertionStarts(Arrays.asList(pickup_delivery_route), Collections.emptyList()); Pickup s = mock(Pickup.class); Capacity newSize = Capacity.Builder.newInstance().addDimension(0, 5).build(); when(s.getSize()).thenReturn(newSize); ServiceLoadActivityLevelConstraint loadConstraint = new ServiceLoadActivityLevelConstraint(stateManager); - JobInsertionContext context = new JobInsertionContext(pickup_delivery_route,s,pickup_delivery_route.getVehicle(),null,0.); + JobInsertionContext context = new JobInsertionContext(pickup_delivery_route, s, pickup_delivery_route.getVehicle(), null, 0.); PickupService newAct = new PickupService(s); HardActivityConstraint.ConstraintsStatus status = loadConstraint.fulfilled(context, pickup_delivery_route.getActivities().get(0), newAct, pickup_delivery_route.getActivities().get(1), 0.); - assertEquals(HardActivityConstraint.ConstraintsStatus.FULFILLED,status); + assertEquals(HardActivityConstraint.ConstraintsStatus.FULFILLED, status); } @Test - public void whenPDRoute_newPickupShouldFitInBetweenAct2AndEnd(){ + public void whenPDRoute_newPickupShouldFitInBetweenAct2AndEnd() { stateManager.informInsertionStarts(Arrays.asList(pickup_delivery_route), Collections.emptyList()); Pickup s = mock(Pickup.class); Capacity newSize = Capacity.Builder.newInstance().addDimension(0, 10).build(); when(s.getSize()).thenReturn(newSize); ServiceLoadActivityLevelConstraint loadConstraint = new ServiceLoadActivityLevelConstraint(stateManager); - JobInsertionContext context = new JobInsertionContext(pickup_delivery_route,s,pickup_delivery_route.getVehicle(),null,0.); + JobInsertionContext context = new JobInsertionContext(pickup_delivery_route, s, pickup_delivery_route.getVehicle(), null, 0.); PickupService newAct = new PickupService(s); HardActivityConstraint.ConstraintsStatus status = loadConstraint.fulfilled(context, pickup_delivery_route.getActivities().get(1), newAct, pickup_delivery_route.getEnd(), 0.); - assertEquals(HardActivityConstraint.ConstraintsStatus.FULFILLED,status); + assertEquals(HardActivityConstraint.ConstraintsStatus.FULFILLED, status); } /* pickup does not fit in between activities */ @Test - public void whenPDRoute_newPickupShouldNotFitInBetweenStartAndAct1(){ + public void whenPDRoute_newPickupShouldNotFitInBetweenStartAndAct1() { stateManager.informInsertionStarts(Arrays.asList(pickup_delivery_route), Collections.emptyList()); Pickup s = mock(Pickup.class); Capacity newSize = Capacity.Builder.newInstance().addDimension(0, 6).build(); when(s.getSize()).thenReturn(newSize); ServiceLoadActivityLevelConstraint loadConstraint = new ServiceLoadActivityLevelConstraint(stateManager); - JobInsertionContext context = new JobInsertionContext(pickup_delivery_route,s,pickup_delivery_route.getVehicle(),null,0.); + JobInsertionContext context = new JobInsertionContext(pickup_delivery_route, s, pickup_delivery_route.getVehicle(), null, 0.); PickupService newAct = new PickupService(s); HardActivityConstraint.ConstraintsStatus status = loadConstraint.fulfilled(context, pickup_delivery_route.getStart(), newAct, pickup_delivery_route.getActivities().get(0), 0.); - assertEquals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED,status); + assertEquals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED, status); } @Test - public void whenPDRoute_newPickupShouldNotFitInBetweenAct1AndAct2(){ + public void whenPDRoute_newPickupShouldNotFitInBetweenAct1AndAct2() { stateManager.informInsertionStarts(Arrays.asList(pickup_delivery_route), Collections.emptyList()); Pickup s = mock(Pickup.class); Capacity newSize = Capacity.Builder.newInstance().addDimension(0, 6).build(); when(s.getSize()).thenReturn(newSize); ServiceLoadActivityLevelConstraint loadConstraint = new ServiceLoadActivityLevelConstraint(stateManager); - JobInsertionContext context = new JobInsertionContext(pickup_delivery_route,s,pickup_delivery_route.getVehicle(),null,0.); + JobInsertionContext context = new JobInsertionContext(pickup_delivery_route, s, pickup_delivery_route.getVehicle(), null, 0.); PickupService newAct = new PickupService(s); HardActivityConstraint.ConstraintsStatus status = loadConstraint.fulfilled(context, pickup_delivery_route.getActivities().get(0), newAct, pickup_delivery_route.getActivities().get(1), 0.); - assertEquals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED,status); + assertEquals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED, status); } @Test - public void whenPDRoute_newPickupShouldNotFitInBetweenAct2AndEnd(){ + public void whenPDRoute_newPickupShouldNotFitInBetweenAct2AndEnd() { stateManager.informInsertionStarts(Arrays.asList(pickup_delivery_route), Collections.emptyList()); Pickup s = mock(Pickup.class); Capacity newSize = Capacity.Builder.newInstance().addDimension(0, 11).build(); when(s.getSize()).thenReturn(newSize); ServiceLoadActivityLevelConstraint loadConstraint = new ServiceLoadActivityLevelConstraint(stateManager); - JobInsertionContext context = new JobInsertionContext(pickup_delivery_route,s,pickup_delivery_route.getVehicle(),null,0.); + JobInsertionContext context = new JobInsertionContext(pickup_delivery_route, s, pickup_delivery_route.getVehicle(), null, 0.); PickupService newAct = new PickupService(s); HardActivityConstraint.ConstraintsStatus status = loadConstraint.fulfilled(context, pickup_delivery_route.getActivities().get(1), newAct, pickup_delivery_route.getEnd(), 0.); - assertEquals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED,status); + assertEquals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED, status); } @@ -395,110 +397,110 @@ public class LoadConstraintTest { pick fits in between activities */ @Test - public void whenPDRoute_newDeliveryShouldFitInBetweenStartAndAct1(){ + public void whenPDRoute_newDeliveryShouldFitInBetweenStartAndAct1() { stateManager.informInsertionStarts(Arrays.asList(pickup_delivery_route), Collections.emptyList()); Delivery s = mock(Delivery.class); Capacity newSize = Capacity.Builder.newInstance().addDimension(0, 15).build(); when(s.getSize()).thenReturn(newSize); ServiceLoadActivityLevelConstraint loadConstraint = new ServiceLoadActivityLevelConstraint(stateManager); - JobInsertionContext context = new JobInsertionContext(pickup_delivery_route,s,pickup_delivery_route.getVehicle(),null,0.); + JobInsertionContext context = new JobInsertionContext(pickup_delivery_route, s, pickup_delivery_route.getVehicle(), null, 0.); DeliverService newAct = new DeliverService(s); HardActivityConstraint.ConstraintsStatus status = loadConstraint.fulfilled(context, pickup_delivery_route.getStart(), newAct, pickup_delivery_route.getActivities().get(0), 0.); - assertEquals(HardActivityConstraint.ConstraintsStatus.FULFILLED,status); + assertEquals(HardActivityConstraint.ConstraintsStatus.FULFILLED, status); } @Test - public void whenPDRoute_newDeliveryShouldNotFitInBetweenStartAndAct1(){ + public void whenPDRoute_newDeliveryShouldNotFitInBetweenStartAndAct1() { stateManager.informInsertionStarts(Arrays.asList(pickup_delivery_route), Collections.emptyList()); Delivery s = mock(Delivery.class); Capacity newSize = Capacity.Builder.newInstance().addDimension(0, 16).build(); when(s.getSize()).thenReturn(newSize); ServiceLoadActivityLevelConstraint loadConstraint = new ServiceLoadActivityLevelConstraint(stateManager); - JobInsertionContext context = new JobInsertionContext(pickup_delivery_route,s,pickup_delivery_route.getVehicle(),null,0.); + JobInsertionContext context = new JobInsertionContext(pickup_delivery_route, s, pickup_delivery_route.getVehicle(), null, 0.); DeliverService newAct = new DeliverService(s); HardActivityConstraint.ConstraintsStatus status = loadConstraint.fulfilled(context, pickup_delivery_route.getStart(), newAct, pickup_delivery_route.getActivities().get(0), 0.); - assertEquals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED_BREAK,status); + assertEquals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED_BREAK, status); } @Test - public void whenPDRoute_newDeliveryShouldFitInBetweenAct1AndAct2(){ + public void whenPDRoute_newDeliveryShouldFitInBetweenAct1AndAct2() { stateManager.informInsertionStarts(Arrays.asList(pickup_delivery_route), Collections.emptyList()); Delivery s = mock(Delivery.class); Capacity newSize = Capacity.Builder.newInstance().addDimension(0, 5).build(); when(s.getSize()).thenReturn(newSize); ServiceLoadActivityLevelConstraint loadConstraint = new ServiceLoadActivityLevelConstraint(stateManager); - JobInsertionContext context = new JobInsertionContext(pickup_delivery_route,s,pickup_delivery_route.getVehicle(),null,0.); + JobInsertionContext context = new JobInsertionContext(pickup_delivery_route, s, pickup_delivery_route.getVehicle(), null, 0.); DeliverService newAct = new DeliverService(s); HardActivityConstraint.ConstraintsStatus status = loadConstraint.fulfilled(context, pickup_delivery_route.getActivities().get(0), newAct, pickup_delivery_route.getActivities().get(1), 0.); - assertEquals(HardActivityConstraint.ConstraintsStatus.FULFILLED,status); + assertEquals(HardActivityConstraint.ConstraintsStatus.FULFILLED, status); } @Test - public void whenPDRoute_newDeliveryNotShouldFitInBetweenAct1AndAct2(){ + public void whenPDRoute_newDeliveryNotShouldFitInBetweenAct1AndAct2() { stateManager.informInsertionStarts(Arrays.asList(pickup_delivery_route), Collections.emptyList()); Delivery s = mock(Delivery.class); Capacity newSize = Capacity.Builder.newInstance().addDimension(0, 6).build(); when(s.getSize()).thenReturn(newSize); ServiceLoadActivityLevelConstraint loadConstraint = new ServiceLoadActivityLevelConstraint(stateManager); - JobInsertionContext context = new JobInsertionContext(pickup_delivery_route,s,pickup_delivery_route.getVehicle(),null,0.); + JobInsertionContext context = new JobInsertionContext(pickup_delivery_route, s, pickup_delivery_route.getVehicle(), null, 0.); DeliverService newAct = new DeliverService(s); HardActivityConstraint.ConstraintsStatus status = loadConstraint.fulfilled(context, pickup_delivery_route.getActivities().get(0), newAct, pickup_delivery_route.getActivities().get(1), 0.); - assertEquals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED_BREAK,status); + assertEquals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED_BREAK, status); } @Test - public void whenPDRoute_newDeliveryShouldFitInBetweenAct2AndEnd(){ + public void whenPDRoute_newDeliveryShouldFitInBetweenAct2AndEnd() { stateManager.informInsertionStarts(Arrays.asList(pickup_delivery_route), Collections.emptyList()); Delivery s = mock(Delivery.class); Capacity newSize = Capacity.Builder.newInstance().addDimension(0, 5).build(); when(s.getSize()).thenReturn(newSize); ServiceLoadActivityLevelConstraint loadConstraint = new ServiceLoadActivityLevelConstraint(stateManager); - JobInsertionContext context = new JobInsertionContext(pickup_delivery_route,s,pickup_delivery_route.getVehicle(),null,0.); + JobInsertionContext context = new JobInsertionContext(pickup_delivery_route, s, pickup_delivery_route.getVehicle(), null, 0.); DeliverService newAct = new DeliverService(s); HardActivityConstraint.ConstraintsStatus status = loadConstraint.fulfilled(context, pickup_delivery_route.getActivities().get(1), newAct, pickup_delivery_route.getEnd(), 0.); - assertEquals(HardActivityConstraint.ConstraintsStatus.FULFILLED,status); + assertEquals(HardActivityConstraint.ConstraintsStatus.FULFILLED, status); } @Test - public void whenPDRoute_newDeliveryShouldNotFitInBetweenAct2AndEnd(){ + public void whenPDRoute_newDeliveryShouldNotFitInBetweenAct2AndEnd() { stateManager.informInsertionStarts(Arrays.asList(pickup_delivery_route), Collections.emptyList()); Delivery s = mock(Delivery.class); Capacity newSize = Capacity.Builder.newInstance().addDimension(0, 6).build(); when(s.getSize()).thenReturn(newSize); ServiceLoadActivityLevelConstraint loadConstraint = new ServiceLoadActivityLevelConstraint(stateManager); - JobInsertionContext context = new JobInsertionContext(pickup_delivery_route,s,pickup_delivery_route.getVehicle(),null,0.); + JobInsertionContext context = new JobInsertionContext(pickup_delivery_route, s, pickup_delivery_route.getVehicle(), null, 0.); DeliverService newAct = new DeliverService(s); HardActivityConstraint.ConstraintsStatus status = loadConstraint.fulfilled(context, pickup_delivery_route.getActivities().get(1), newAct, pickup_delivery_route.getEnd(), 0.); - assertEquals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED_BREAK,status); + assertEquals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED_BREAK, status); } @Test - public void whenPDRouteAndNewServiceFitsInBetweenAc1AndAct2_itShouldReturnFulfilled(){ + public void whenPDRouteAndNewServiceFitsInBetweenAc1AndAct2_itShouldReturnFulfilled() { stateManager.informInsertionStarts(Arrays.asList(pickup_delivery_route), Collections.emptyList()); Service s = mock(Service.class); Capacity newSize = Capacity.Builder.newInstance().addDimension(0, 5).build(); when(s.getSize()).thenReturn(newSize); ServiceLoadActivityLevelConstraint loadConstraint = new ServiceLoadActivityLevelConstraint(stateManager); - JobInsertionContext context = new JobInsertionContext(serviceRoute,s,serviceRoute.getVehicle(),null,0.); + JobInsertionContext context = new JobInsertionContext(serviceRoute, s, serviceRoute.getVehicle(), null, 0.); ServiceActivity newAct = mock(ServiceActivity.class); when(newAct.getSize()).thenReturn(newSize); @@ -508,14 +510,14 @@ public class LoadConstraintTest { } @Test - public void whenPDRouteAndNewServiceFitsInBetweenAc2AndEnd_itShouldReturnFulfilled(){ + public void whenPDRouteAndNewServiceFitsInBetweenAc2AndEnd_itShouldReturnFulfilled() { stateManager.informInsertionStarts(Arrays.asList(pickup_delivery_route), Collections.emptyList()); Service s = mock(Service.class); Capacity newSize = Capacity.Builder.newInstance().addDimension(0, 5).build(); when(s.getSize()).thenReturn(newSize); ServiceLoadActivityLevelConstraint loadConstraint = new ServiceLoadActivityLevelConstraint(stateManager); - JobInsertionContext context = new JobInsertionContext(serviceRoute,s,serviceRoute.getVehicle(),null,0.); + JobInsertionContext context = new JobInsertionContext(serviceRoute, s, serviceRoute.getVehicle(), null, 0.); ServiceActivity newAct = mock(ServiceActivity.class); when(newAct.getSize()).thenReturn(newSize); @@ -528,14 +530,14 @@ public class LoadConstraintTest { service does not fit in at act level */ @Test - public void whenPDRouteAndNewServiceDoesNotFitInBetweenStartAndAct1_itShouldReturnFulfilled(){ + public void whenPDRouteAndNewServiceDoesNotFitInBetweenStartAndAct1_itShouldReturnFulfilled() { stateManager.informInsertionStarts(Arrays.asList(serviceRoute), Collections.emptyList()); Service s = mock(Service.class); Capacity newSize = Capacity.Builder.newInstance().addDimension(0, 6).build(); when(s.getSize()).thenReturn(newSize); ServiceLoadActivityLevelConstraint loadConstraint = new ServiceLoadActivityLevelConstraint(stateManager); - JobInsertionContext context = new JobInsertionContext(serviceRoute,s,serviceRoute.getVehicle(),null,0.); + JobInsertionContext context = new JobInsertionContext(serviceRoute, s, serviceRoute.getVehicle(), null, 0.); ServiceActivity newAct = mock(ServiceActivity.class); when(newAct.getSize()).thenReturn(newSize); @@ -545,14 +547,14 @@ public class LoadConstraintTest { } @Test - public void whenPDRouteAndNewServiceDoesNotFitInBetweenAc1AndAct2_itShouldReturnFulfilled(){ + public void whenPDRouteAndNewServiceDoesNotFitInBetweenAc1AndAct2_itShouldReturnFulfilled() { stateManager.informInsertionStarts(Arrays.asList(pickup_delivery_route), Collections.emptyList()); Service s = mock(Service.class); Capacity newSize = Capacity.Builder.newInstance().addDimension(0, 6).build(); when(s.getSize()).thenReturn(newSize); ServiceLoadActivityLevelConstraint loadConstraint = new ServiceLoadActivityLevelConstraint(stateManager); - JobInsertionContext context = new JobInsertionContext(serviceRoute,s,serviceRoute.getVehicle(),null,0.); + JobInsertionContext context = new JobInsertionContext(serviceRoute, s, serviceRoute.getVehicle(), null, 0.); ServiceActivity newAct = mock(ServiceActivity.class); when(newAct.getSize()).thenReturn(newSize); @@ -562,14 +564,14 @@ public class LoadConstraintTest { } @Test - public void whenPDRouteAndNewServiceDoesNotFitInBetweenAc2AndEnd_itShouldReturnFulfilled(){ + public void whenPDRouteAndNewServiceDoesNotFitInBetweenAc2AndEnd_itShouldReturnFulfilled() { stateManager.informInsertionStarts(Arrays.asList(serviceRoute), Collections.emptyList()); Service s = mock(Service.class); Capacity newSize = Capacity.Builder.newInstance().addDimension(0, 6).build(); when(s.getSize()).thenReturn(newSize); ServiceLoadActivityLevelConstraint loadConstraint = new ServiceLoadActivityLevelConstraint(stateManager); - JobInsertionContext context = new JobInsertionContext(serviceRoute,s,serviceRoute.getVehicle(),null,0.); + JobInsertionContext context = new JobInsertionContext(serviceRoute, s, serviceRoute.getVehicle(), null, 0.); ServiceActivity newAct = mock(ServiceActivity.class); when(newAct.getSize()).thenReturn(newSize); @@ -580,13 +582,13 @@ public class LoadConstraintTest { @Test - public void whenPDRouteAndNewServiceDoesNotFitIn_itShouldReturnFulfilled(){ + public void whenPDRouteAndNewServiceDoesNotFitIn_itShouldReturnFulfilled() { stateManager.informInsertionStarts(Arrays.asList(serviceRoute), Collections.emptyList()); Service s = mock(Service.class); - when(s.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0,6).build()); + when(s.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 6).build()); ServiceLoadRouteLevelConstraint loadconstraint = new ServiceLoadRouteLevelConstraint(stateManager); - JobInsertionContext context = new JobInsertionContext(serviceRoute,s,serviceRoute.getVehicle(),null,0.); + JobInsertionContext context = new JobInsertionContext(serviceRoute, s, serviceRoute.getVehicle(), null, 0.); assertFalse(loadconstraint.fulfilled(context)); } @@ -599,172 +601,172 @@ pickup(s1) pickup(s2) delivery(s2) deliver(s1) */ @Test - public void whenShipmentRouteAndPickupOfNewShipmentShouldFitInBetweenStartAndAct1(){ + public void whenShipmentRouteAndPickupOfNewShipmentShouldFitInBetweenStartAndAct1() { stateManager.informInsertionStarts(Arrays.asList(shipment_route), Collections.emptyList()); Shipment s = mock(Shipment.class); Capacity newSize = Capacity.Builder.newInstance().addDimension(0, 20).build(); when(s.getSize()).thenReturn(newSize); - JobInsertionContext context = new JobInsertionContext(shipment_route,s,shipment_route.getVehicle(),null,0.); + JobInsertionContext context = new JobInsertionContext(shipment_route, s, shipment_route.getVehicle(), null, 0.); PickupShipment newAct = new PickupShipment(s); PickupAndDeliverShipmentLoadActivityLevelConstraint loadConstraint = new PickupAndDeliverShipmentLoadActivityLevelConstraint(stateManager); - HardActivityConstraint.ConstraintsStatus status = loadConstraint.fulfilled(context,shipment_route.getStart(),newAct,shipment_route.getActivities().get(0),0.); + HardActivityConstraint.ConstraintsStatus status = loadConstraint.fulfilled(context, shipment_route.getStart(), newAct, shipment_route.getActivities().get(0), 0.); - assertEquals(HardActivityConstraint.ConstraintsStatus.FULFILLED,status); + assertEquals(HardActivityConstraint.ConstraintsStatus.FULFILLED, status); } @Test - public void whenShipmentRouteAndPickupOfNewShipmentShouldNotFitInBetweenStartAndAct1(){ + public void whenShipmentRouteAndPickupOfNewShipmentShouldNotFitInBetweenStartAndAct1() { stateManager.informInsertionStarts(Arrays.asList(shipment_route), Collections.emptyList()); Shipment s = mock(Shipment.class); Capacity newSize = Capacity.Builder.newInstance().addDimension(0, 21).build(); when(s.getSize()).thenReturn(newSize); - JobInsertionContext context = new JobInsertionContext(shipment_route,s,shipment_route.getVehicle(),null,0.); + JobInsertionContext context = new JobInsertionContext(shipment_route, s, shipment_route.getVehicle(), null, 0.); PickupShipment newAct = new PickupShipment(s); PickupAndDeliverShipmentLoadActivityLevelConstraint loadConstraint = new PickupAndDeliverShipmentLoadActivityLevelConstraint(stateManager); - HardActivityConstraint.ConstraintsStatus status = loadConstraint.fulfilled(context,shipment_route.getStart(),newAct,shipment_route.getActivities().get(0),0.); + HardActivityConstraint.ConstraintsStatus status = loadConstraint.fulfilled(context, shipment_route.getStart(), newAct, shipment_route.getActivities().get(0), 0.); - assertEquals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED,status); + assertEquals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED, status); } @Test - public void whenShipmentRouteAndPickupOfNewShipmentShouldFitInBetweenAct1AndAct2(){ + public void whenShipmentRouteAndPickupOfNewShipmentShouldFitInBetweenAct1AndAct2() { stateManager.informInsertionStarts(Arrays.asList(shipment_route), Collections.emptyList()); Shipment s = mock(Shipment.class); Capacity newSize = Capacity.Builder.newInstance().addDimension(0, 10).build(); when(s.getSize()).thenReturn(newSize); - JobInsertionContext context = new JobInsertionContext(shipment_route,s,shipment_route.getVehicle(),null,0.); + JobInsertionContext context = new JobInsertionContext(shipment_route, s, shipment_route.getVehicle(), null, 0.); PickupShipment newAct = new PickupShipment(s); PickupAndDeliverShipmentLoadActivityLevelConstraint loadConstraint = new PickupAndDeliverShipmentLoadActivityLevelConstraint(stateManager); - HardActivityConstraint.ConstraintsStatus status = loadConstraint.fulfilled(context,shipment_route.getActivities().get(0),newAct,shipment_route.getActivities().get(1),0.); + HardActivityConstraint.ConstraintsStatus status = loadConstraint.fulfilled(context, shipment_route.getActivities().get(0), newAct, shipment_route.getActivities().get(1), 0.); - assertEquals(HardActivityConstraint.ConstraintsStatus.FULFILLED,status); + assertEquals(HardActivityConstraint.ConstraintsStatus.FULFILLED, status); } @Test - public void whenShipmentRouteAndPickupOfNewShipmentShouldNotFitInBetweenAct1AndAct2(){ + public void whenShipmentRouteAndPickupOfNewShipmentShouldNotFitInBetweenAct1AndAct2() { stateManager.informInsertionStarts(Arrays.asList(shipment_route), Collections.emptyList()); Shipment s = mock(Shipment.class); Capacity newSize = Capacity.Builder.newInstance().addDimension(0, 11).build(); when(s.getSize()).thenReturn(newSize); - JobInsertionContext context = new JobInsertionContext(shipment_route,s,shipment_route.getVehicle(),null,0.); + JobInsertionContext context = new JobInsertionContext(shipment_route, s, shipment_route.getVehicle(), null, 0.); PickupShipment newAct = new PickupShipment(s); PickupAndDeliverShipmentLoadActivityLevelConstraint loadConstraint = new PickupAndDeliverShipmentLoadActivityLevelConstraint(stateManager); - HardActivityConstraint.ConstraintsStatus status = loadConstraint.fulfilled(context,shipment_route.getActivities().get(0),newAct,shipment_route.getActivities().get(1),0.); + HardActivityConstraint.ConstraintsStatus status = loadConstraint.fulfilled(context, shipment_route.getActivities().get(0), newAct, shipment_route.getActivities().get(1), 0.); - assertEquals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED,status); + assertEquals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED, status); } @Test - public void whenShipmentRouteAndPickupOfNewShipmentShouldFitInBetweenAct2AndAct3(){ + public void whenShipmentRouteAndPickupOfNewShipmentShouldFitInBetweenAct2AndAct3() { stateManager.informInsertionStarts(Arrays.asList(shipment_route), Collections.emptyList()); Shipment s = mock(Shipment.class); Capacity newSize = Capacity.Builder.newInstance().addDimension(0, 5).build(); when(s.getSize()).thenReturn(newSize); - JobInsertionContext context = new JobInsertionContext(shipment_route,s,shipment_route.getVehicle(),null,0.); + JobInsertionContext context = new JobInsertionContext(shipment_route, s, shipment_route.getVehicle(), null, 0.); PickupShipment newAct = new PickupShipment(s); PickupAndDeliverShipmentLoadActivityLevelConstraint loadConstraint = new PickupAndDeliverShipmentLoadActivityLevelConstraint(stateManager); - HardActivityConstraint.ConstraintsStatus status = loadConstraint.fulfilled(context,shipment_route.getActivities().get(1),newAct,shipment_route.getActivities().get(2),0.); + HardActivityConstraint.ConstraintsStatus status = loadConstraint.fulfilled(context, shipment_route.getActivities().get(1), newAct, shipment_route.getActivities().get(2), 0.); - assertEquals(HardActivityConstraint.ConstraintsStatus.FULFILLED,status); + assertEquals(HardActivityConstraint.ConstraintsStatus.FULFILLED, status); } @Test - public void whenShipmentRouteAndPickupOfNewShipmentShouldNotFitInBetweenAct2AndAct3(){ + public void whenShipmentRouteAndPickupOfNewShipmentShouldNotFitInBetweenAct2AndAct3() { stateManager.informInsertionStarts(Arrays.asList(shipment_route), Collections.emptyList()); Shipment s = mock(Shipment.class); Capacity newSize = Capacity.Builder.newInstance().addDimension(0, 6).build(); when(s.getSize()).thenReturn(newSize); - JobInsertionContext context = new JobInsertionContext(shipment_route,s,shipment_route.getVehicle(),null,0.); + JobInsertionContext context = new JobInsertionContext(shipment_route, s, shipment_route.getVehicle(), null, 0.); PickupShipment newAct = new PickupShipment(s); PickupAndDeliverShipmentLoadActivityLevelConstraint loadConstraint = new PickupAndDeliverShipmentLoadActivityLevelConstraint(stateManager); - HardActivityConstraint.ConstraintsStatus status = loadConstraint.fulfilled(context,shipment_route.getActivities().get(1),newAct,shipment_route.getActivities().get(2),0.); + HardActivityConstraint.ConstraintsStatus status = loadConstraint.fulfilled(context, shipment_route.getActivities().get(1), newAct, shipment_route.getActivities().get(2), 0.); - assertEquals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED,status); + assertEquals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED, status); } @Test - public void whenShipmentRouteAndPickupOfNewShipmentShouldFitInBetweenAct3AndAct4(){ + public void whenShipmentRouteAndPickupOfNewShipmentShouldFitInBetweenAct3AndAct4() { stateManager.informInsertionStarts(Arrays.asList(shipment_route), Collections.emptyList()); Shipment s = mock(Shipment.class); Capacity newSize = Capacity.Builder.newInstance().addDimension(0, 10).build(); when(s.getSize()).thenReturn(newSize); - JobInsertionContext context = new JobInsertionContext(shipment_route,s,shipment_route.getVehicle(),null,0.); + JobInsertionContext context = new JobInsertionContext(shipment_route, s, shipment_route.getVehicle(), null, 0.); PickupShipment newAct = new PickupShipment(s); PickupAndDeliverShipmentLoadActivityLevelConstraint loadConstraint = new PickupAndDeliverShipmentLoadActivityLevelConstraint(stateManager); - HardActivityConstraint.ConstraintsStatus status = loadConstraint.fulfilled(context,shipment_route.getActivities().get(2),newAct,shipment_route.getActivities().get(3),0.); + HardActivityConstraint.ConstraintsStatus status = loadConstraint.fulfilled(context, shipment_route.getActivities().get(2), newAct, shipment_route.getActivities().get(3), 0.); - assertEquals(HardActivityConstraint.ConstraintsStatus.FULFILLED,status); + assertEquals(HardActivityConstraint.ConstraintsStatus.FULFILLED, status); } @Test - public void whenShipmentRouteAndPickupOfNewShipmentShouldNotFitInBetweenAct3AndAct4(){ + public void whenShipmentRouteAndPickupOfNewShipmentShouldNotFitInBetweenAct3AndAct4() { stateManager.informInsertionStarts(Arrays.asList(shipment_route), Collections.emptyList()); Shipment s = mock(Shipment.class); - Capacity newSize = Capacity.Builder.newInstance().addDimension(0,11).build(); + Capacity newSize = Capacity.Builder.newInstance().addDimension(0, 11).build(); when(s.getSize()).thenReturn(newSize); - JobInsertionContext context = new JobInsertionContext(shipment_route,s,shipment_route.getVehicle(),null,0.); + JobInsertionContext context = new JobInsertionContext(shipment_route, s, shipment_route.getVehicle(), null, 0.); PickupShipment newAct = new PickupShipment(s); PickupAndDeliverShipmentLoadActivityLevelConstraint loadConstraint = new PickupAndDeliverShipmentLoadActivityLevelConstraint(stateManager); - HardActivityConstraint.ConstraintsStatus status = loadConstraint.fulfilled(context,shipment_route.getActivities().get(2),newAct,shipment_route.getActivities().get(3),0.); + HardActivityConstraint.ConstraintsStatus status = loadConstraint.fulfilled(context, shipment_route.getActivities().get(2), newAct, shipment_route.getActivities().get(3), 0.); - assertEquals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED,status); + assertEquals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED, status); } @Test - public void whenShipmentRouteAndPickupOfNewShipmentShouldFitInBetweenAct4AndEnd(){ + public void whenShipmentRouteAndPickupOfNewShipmentShouldFitInBetweenAct4AndEnd() { stateManager.informInsertionStarts(Arrays.asList(shipment_route), Collections.emptyList()); Shipment s = mock(Shipment.class); Capacity newSize = Capacity.Builder.newInstance().addDimension(0, 20).build(); when(s.getSize()).thenReturn(newSize); - JobInsertionContext context = new JobInsertionContext(shipment_route,s,shipment_route.getVehicle(),null,0.); + JobInsertionContext context = new JobInsertionContext(shipment_route, s, shipment_route.getVehicle(), null, 0.); PickupShipment newAct = new PickupShipment(s); PickupAndDeliverShipmentLoadActivityLevelConstraint loadConstraint = new PickupAndDeliverShipmentLoadActivityLevelConstraint(stateManager); - HardActivityConstraint.ConstraintsStatus status = loadConstraint.fulfilled(context,shipment_route.getActivities().get(3),newAct,shipment_route.getEnd(),0.); + HardActivityConstraint.ConstraintsStatus status = loadConstraint.fulfilled(context, shipment_route.getActivities().get(3), newAct, shipment_route.getEnd(), 0.); - assertEquals(HardActivityConstraint.ConstraintsStatus.FULFILLED,status); + assertEquals(HardActivityConstraint.ConstraintsStatus.FULFILLED, status); } @Test - public void whenShipmentRouteAndPickupOfNewShipmentShouldNotFitInBetweenAct4AndEnd(){ + public void whenShipmentRouteAndPickupOfNewShipmentShouldNotFitInBetweenAct4AndEnd() { stateManager.informInsertionStarts(Arrays.asList(shipment_route), Collections.emptyList()); Shipment s = mock(Shipment.class); - Capacity newSize = Capacity.Builder.newInstance().addDimension(0,21).build(); + Capacity newSize = Capacity.Builder.newInstance().addDimension(0, 21).build(); when(s.getSize()).thenReturn(newSize); - JobInsertionContext context = new JobInsertionContext(shipment_route,s,shipment_route.getVehicle(),null,0.); + JobInsertionContext context = new JobInsertionContext(shipment_route, s, shipment_route.getVehicle(), null, 0.); PickupShipment newAct = new PickupShipment(s); PickupAndDeliverShipmentLoadActivityLevelConstraint loadConstraint = new PickupAndDeliverShipmentLoadActivityLevelConstraint(stateManager); - HardActivityConstraint.ConstraintsStatus status = loadConstraint.fulfilled(context,shipment_route.getActivities().get(3),newAct,shipment_route.getEnd(),0.); + HardActivityConstraint.ConstraintsStatus status = loadConstraint.fulfilled(context, shipment_route.getActivities().get(3), newAct, shipment_route.getEnd(), 0.); - assertEquals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED,status); + assertEquals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED, status); } @@ -773,172 +775,172 @@ pickup(s1) pickup(s2) delivery(s2) deliver(s1) */ @Test - public void whenShipmentRouteAndDeliveryOfNewShipmentShouldFitInBetweenStartAndAct1(){ + public void whenShipmentRouteAndDeliveryOfNewShipmentShouldFitInBetweenStartAndAct1() { stateManager.informInsertionStarts(Arrays.asList(shipment_route), Collections.emptyList()); Shipment s = mock(Shipment.class); Capacity newSize = Capacity.Builder.newInstance().addDimension(0, 20).build(); when(s.getSize()).thenReturn(newSize); - JobInsertionContext context = new JobInsertionContext(shipment_route,s,shipment_route.getVehicle(),null,0.); + JobInsertionContext context = new JobInsertionContext(shipment_route, s, shipment_route.getVehicle(), null, 0.); DeliverShipment newAct = new DeliverShipment(s); PickupAndDeliverShipmentLoadActivityLevelConstraint loadConstraint = new PickupAndDeliverShipmentLoadActivityLevelConstraint(stateManager); - HardActivityConstraint.ConstraintsStatus status = loadConstraint.fulfilled(context,shipment_route.getStart(),newAct,shipment_route.getActivities().get(0),0.); + HardActivityConstraint.ConstraintsStatus status = loadConstraint.fulfilled(context, shipment_route.getStart(), newAct, shipment_route.getActivities().get(0), 0.); - assertEquals(HardActivityConstraint.ConstraintsStatus.FULFILLED,status); + assertEquals(HardActivityConstraint.ConstraintsStatus.FULFILLED, status); } @Test - public void whenShipmentRouteAndDeliveryOfNewShipmentShouldNotFitInBetweenStartAndAct1(){ + public void whenShipmentRouteAndDeliveryOfNewShipmentShouldNotFitInBetweenStartAndAct1() { stateManager.informInsertionStarts(Arrays.asList(shipment_route), Collections.emptyList()); Shipment s = mock(Shipment.class); Capacity newSize = Capacity.Builder.newInstance().addDimension(0, 21).build(); when(s.getSize()).thenReturn(newSize); - JobInsertionContext context = new JobInsertionContext(shipment_route,s,shipment_route.getVehicle(),null,0.); + JobInsertionContext context = new JobInsertionContext(shipment_route, s, shipment_route.getVehicle(), null, 0.); DeliverShipment newAct = new DeliverShipment(s); PickupAndDeliverShipmentLoadActivityLevelConstraint loadConstraint = new PickupAndDeliverShipmentLoadActivityLevelConstraint(stateManager); - HardActivityConstraint.ConstraintsStatus status = loadConstraint.fulfilled(context,shipment_route.getStart(),newAct,shipment_route.getActivities().get(0),0.); + HardActivityConstraint.ConstraintsStatus status = loadConstraint.fulfilled(context, shipment_route.getStart(), newAct, shipment_route.getActivities().get(0), 0.); - assertEquals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED_BREAK,status); + assertEquals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED_BREAK, status); } @Test - public void whenShipmentRouteAndDeliveryOfNewShipmentShouldFitInBetweenAct1AndAct2(){ + public void whenShipmentRouteAndDeliveryOfNewShipmentShouldFitInBetweenAct1AndAct2() { stateManager.informInsertionStarts(Arrays.asList(shipment_route), Collections.emptyList()); Shipment s = mock(Shipment.class); Capacity newSize = Capacity.Builder.newInstance().addDimension(0, 10).build(); when(s.getSize()).thenReturn(newSize); - JobInsertionContext context = new JobInsertionContext(shipment_route,s,shipment_route.getVehicle(),null,0.); + JobInsertionContext context = new JobInsertionContext(shipment_route, s, shipment_route.getVehicle(), null, 0.); DeliverShipment newAct = new DeliverShipment(s); PickupAndDeliverShipmentLoadActivityLevelConstraint loadConstraint = new PickupAndDeliverShipmentLoadActivityLevelConstraint(stateManager); - HardActivityConstraint.ConstraintsStatus status = loadConstraint.fulfilled(context,shipment_route.getActivities().get(0),newAct,shipment_route.getActivities().get(1),0.); + HardActivityConstraint.ConstraintsStatus status = loadConstraint.fulfilled(context, shipment_route.getActivities().get(0), newAct, shipment_route.getActivities().get(1), 0.); - assertEquals(HardActivityConstraint.ConstraintsStatus.FULFILLED,status); + assertEquals(HardActivityConstraint.ConstraintsStatus.FULFILLED, status); } @Test - public void whenShipmentRouteAndDeliveryOfNewShipmentShouldNotFitInBetweenAct1AndAct2(){ + public void whenShipmentRouteAndDeliveryOfNewShipmentShouldNotFitInBetweenAct1AndAct2() { stateManager.informInsertionStarts(Arrays.asList(shipment_route), Collections.emptyList()); Shipment s = mock(Shipment.class); Capacity newSize = Capacity.Builder.newInstance().addDimension(0, 11).build(); when(s.getSize()).thenReturn(newSize); - JobInsertionContext context = new JobInsertionContext(shipment_route,s,shipment_route.getVehicle(),null,0.); + JobInsertionContext context = new JobInsertionContext(shipment_route, s, shipment_route.getVehicle(), null, 0.); DeliverShipment newAct = new DeliverShipment(s); PickupAndDeliverShipmentLoadActivityLevelConstraint loadConstraint = new PickupAndDeliverShipmentLoadActivityLevelConstraint(stateManager); - HardActivityConstraint.ConstraintsStatus status = loadConstraint.fulfilled(context,shipment_route.getActivities().get(0),newAct,shipment_route.getActivities().get(1),0.); + HardActivityConstraint.ConstraintsStatus status = loadConstraint.fulfilled(context, shipment_route.getActivities().get(0), newAct, shipment_route.getActivities().get(1), 0.); - assertEquals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED_BREAK,status); + assertEquals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED_BREAK, status); } @Test - public void whenShipmentRouteAndDeliveryOfNewShipmentShouldFitInBetweenAct2AndAct3(){ + public void whenShipmentRouteAndDeliveryOfNewShipmentShouldFitInBetweenAct2AndAct3() { stateManager.informInsertionStarts(Arrays.asList(shipment_route), Collections.emptyList()); Shipment s = mock(Shipment.class); Capacity newSize = Capacity.Builder.newInstance().addDimension(0, 5).build(); when(s.getSize()).thenReturn(newSize); - JobInsertionContext context = new JobInsertionContext(shipment_route,s,shipment_route.getVehicle(),null,0.); + JobInsertionContext context = new JobInsertionContext(shipment_route, s, shipment_route.getVehicle(), null, 0.); DeliverShipment newAct = new DeliverShipment(s); PickupAndDeliverShipmentLoadActivityLevelConstraint loadConstraint = new PickupAndDeliverShipmentLoadActivityLevelConstraint(stateManager); - HardActivityConstraint.ConstraintsStatus status = loadConstraint.fulfilled(context,shipment_route.getActivities().get(1),newAct,shipment_route.getActivities().get(2),0.); + HardActivityConstraint.ConstraintsStatus status = loadConstraint.fulfilled(context, shipment_route.getActivities().get(1), newAct, shipment_route.getActivities().get(2), 0.); - assertEquals(HardActivityConstraint.ConstraintsStatus.FULFILLED,status); + assertEquals(HardActivityConstraint.ConstraintsStatus.FULFILLED, status); } @Test - public void whenShipmentRouteAndDeliveryOfNewShipmentShouldNotFitInBetweenAct2AndAct3(){ + public void whenShipmentRouteAndDeliveryOfNewShipmentShouldNotFitInBetweenAct2AndAct3() { stateManager.informInsertionStarts(Arrays.asList(shipment_route), Collections.emptyList()); Shipment s = mock(Shipment.class); Capacity newSize = Capacity.Builder.newInstance().addDimension(0, 6).build(); when(s.getSize()).thenReturn(newSize); - JobInsertionContext context = new JobInsertionContext(shipment_route,s,shipment_route.getVehicle(),null,0.); + JobInsertionContext context = new JobInsertionContext(shipment_route, s, shipment_route.getVehicle(), null, 0.); DeliverShipment newAct = new DeliverShipment(s); PickupAndDeliverShipmentLoadActivityLevelConstraint loadConstraint = new PickupAndDeliverShipmentLoadActivityLevelConstraint(stateManager); - HardActivityConstraint.ConstraintsStatus status = loadConstraint.fulfilled(context,shipment_route.getActivities().get(1),newAct,shipment_route.getActivities().get(2),0.); + HardActivityConstraint.ConstraintsStatus status = loadConstraint.fulfilled(context, shipment_route.getActivities().get(1), newAct, shipment_route.getActivities().get(2), 0.); - assertEquals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED_BREAK,status); + assertEquals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED_BREAK, status); } @Test - public void whenShipmentRouteAndDeliveryOfNewShipmentShouldFitInBetweenAct3AndAct4(){ + public void whenShipmentRouteAndDeliveryOfNewShipmentShouldFitInBetweenAct3AndAct4() { stateManager.informInsertionStarts(Arrays.asList(shipment_route), Collections.emptyList()); Shipment s = mock(Shipment.class); Capacity newSize = Capacity.Builder.newInstance().addDimension(0, 10).build(); when(s.getSize()).thenReturn(newSize); - JobInsertionContext context = new JobInsertionContext(shipment_route,s,shipment_route.getVehicle(),null,0.); + JobInsertionContext context = new JobInsertionContext(shipment_route, s, shipment_route.getVehicle(), null, 0.); DeliverShipment newAct = new DeliverShipment(s); PickupAndDeliverShipmentLoadActivityLevelConstraint loadConstraint = new PickupAndDeliverShipmentLoadActivityLevelConstraint(stateManager); - HardActivityConstraint.ConstraintsStatus status = loadConstraint.fulfilled(context,shipment_route.getActivities().get(2),newAct,shipment_route.getActivities().get(3),0.); + HardActivityConstraint.ConstraintsStatus status = loadConstraint.fulfilled(context, shipment_route.getActivities().get(2), newAct, shipment_route.getActivities().get(3), 0.); - assertEquals(HardActivityConstraint.ConstraintsStatus.FULFILLED,status); + assertEquals(HardActivityConstraint.ConstraintsStatus.FULFILLED, status); } @Test - public void whenShipmentRouteAndDeliveryOfNewShipmentShouldNotFitInBetweenAct3AndAct4(){ + public void whenShipmentRouteAndDeliveryOfNewShipmentShouldNotFitInBetweenAct3AndAct4() { stateManager.informInsertionStarts(Arrays.asList(shipment_route), Collections.emptyList()); Shipment s = mock(Shipment.class); - Capacity newSize = Capacity.Builder.newInstance().addDimension(0,11).build(); + Capacity newSize = Capacity.Builder.newInstance().addDimension(0, 11).build(); when(s.getSize()).thenReturn(newSize); - JobInsertionContext context = new JobInsertionContext(shipment_route,s,shipment_route.getVehicle(),null,0.); + JobInsertionContext context = new JobInsertionContext(shipment_route, s, shipment_route.getVehicle(), null, 0.); DeliverShipment newAct = new DeliverShipment(s); PickupAndDeliverShipmentLoadActivityLevelConstraint loadConstraint = new PickupAndDeliverShipmentLoadActivityLevelConstraint(stateManager); - HardActivityConstraint.ConstraintsStatus status = loadConstraint.fulfilled(context,shipment_route.getActivities().get(2),newAct,shipment_route.getActivities().get(3),0.); + HardActivityConstraint.ConstraintsStatus status = loadConstraint.fulfilled(context, shipment_route.getActivities().get(2), newAct, shipment_route.getActivities().get(3), 0.); - assertEquals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED_BREAK,status); + assertEquals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED_BREAK, status); } @Test - public void whenShipmentRouteAndDeliveryOfNewShipmentShouldFitInBetweenAct4AndEnd(){ + public void whenShipmentRouteAndDeliveryOfNewShipmentShouldFitInBetweenAct4AndEnd() { stateManager.informInsertionStarts(Arrays.asList(shipment_route), Collections.emptyList()); Shipment s = mock(Shipment.class); Capacity newSize = Capacity.Builder.newInstance().addDimension(0, 20).build(); when(s.getSize()).thenReturn(newSize); - JobInsertionContext context = new JobInsertionContext(shipment_route,s,shipment_route.getVehicle(),null,0.); + JobInsertionContext context = new JobInsertionContext(shipment_route, s, shipment_route.getVehicle(), null, 0.); DeliverShipment newAct = new DeliverShipment(s); PickupAndDeliverShipmentLoadActivityLevelConstraint loadConstraint = new PickupAndDeliverShipmentLoadActivityLevelConstraint(stateManager); - HardActivityConstraint.ConstraintsStatus status = loadConstraint.fulfilled(context,shipment_route.getActivities().get(3),newAct,shipment_route.getEnd(),0.); + HardActivityConstraint.ConstraintsStatus status = loadConstraint.fulfilled(context, shipment_route.getActivities().get(3), newAct, shipment_route.getEnd(), 0.); - assertEquals(HardActivityConstraint.ConstraintsStatus.FULFILLED,status); + assertEquals(HardActivityConstraint.ConstraintsStatus.FULFILLED, status); } @Test - public void whenShipmentRouteAndDeliveryOfNewShipmentShouldNotFitInBetweenAct4AndEnd(){ + public void whenShipmentRouteAndDeliveryOfNewShipmentShouldNotFitInBetweenAct4AndEnd() { stateManager.informInsertionStarts(Arrays.asList(shipment_route), Collections.emptyList()); Shipment s = mock(Shipment.class); - Capacity newSize = Capacity.Builder.newInstance().addDimension(0,21).build(); + Capacity newSize = Capacity.Builder.newInstance().addDimension(0, 21).build(); when(s.getSize()).thenReturn(newSize); - JobInsertionContext context = new JobInsertionContext(shipment_route,s,shipment_route.getVehicle(),null,0.); + JobInsertionContext context = new JobInsertionContext(shipment_route, s, shipment_route.getVehicle(), null, 0.); DeliverShipment newAct = new DeliverShipment(s); PickupAndDeliverShipmentLoadActivityLevelConstraint loadConstraint = new PickupAndDeliverShipmentLoadActivityLevelConstraint(stateManager); - HardActivityConstraint.ConstraintsStatus status = loadConstraint.fulfilled(context,shipment_route.getActivities().get(3),newAct,shipment_route.getEnd(),0.); + HardActivityConstraint.ConstraintsStatus status = loadConstraint.fulfilled(context, shipment_route.getActivities().get(3), newAct, shipment_route.getEnd(), 0.); - assertEquals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED_BREAK,status); + assertEquals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED_BREAK, status); } diff --git a/jsprit-core/src/test/java/jsprit/core/problem/constraint/ServiceLoadRouteLevelConstraintTest.java b/jsprit-core/src/test/java/jsprit/core/problem/constraint/ServiceLoadRouteLevelConstraintTest.java index 7a976da0..530045ae 100644 --- a/jsprit-core/src/test/java/jsprit/core/problem/constraint/ServiceLoadRouteLevelConstraintTest.java +++ b/jsprit-core/src/test/java/jsprit/core/problem/constraint/ServiceLoadRouteLevelConstraintTest.java @@ -42,314 +42,315 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; public class ServiceLoadRouteLevelConstraintTest { - - private Vehicle vehicle; - - private VehicleRoute route; - - RouteAndActivityStateGetter stateGetter; - ServiceLoadRouteLevelConstraint constraint; + private Vehicle vehicle; - StateManager stateManager; - - @Before - public void doBefore(){ - VehicleType type = mock(VehicleType.class); - when(type.getCapacityDimensions()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 3).addDimension(1, 3).addDimension(2, 3).build()); - vehicle = mock(Vehicle.class); - when(vehicle.getType()).thenReturn(type); - - route = mock(VehicleRoute.class); - - Capacity currentLoad = Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 1).addDimension(2, 1).build(); - stateGetter = mock(RouteAndActivityStateGetter.class); - when(stateGetter.getRouteState(route, InternalStates.LOAD_AT_BEGINNING, Capacity.class)).thenReturn(currentLoad); - when(stateGetter.getRouteState(route, InternalStates.LOAD_AT_END, Capacity.class)).thenReturn(currentLoad); - when(stateGetter.getRouteState(route, InternalStates.MAXLOAD, Capacity.class)).thenReturn(currentLoad); + private VehicleRoute route; - constraint = new ServiceLoadRouteLevelConstraint(stateGetter); - - stateManager = new StateManager(mock(VehicleRoutingProblem.class)); - stateManager.updateLoadStates(); - } - - @Test - public void whenLoadPlusDeliverySizeDoesNotExceedsVehicleCapacity_itShouldReturnTrue(){ - Service service = mock(Delivery.class); - when(service.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 1).addDimension(2, 1).build()); - - JobInsertionContext iContext = mock(JobInsertionContext.class); - when(iContext.getJob()).thenReturn(service); - when(iContext.getRoute()).thenReturn(route); - when(iContext.getNewVehicle()).thenReturn(vehicle); - - assertTrue(constraint.fulfilled(iContext)); - } - - @Test - public void whenLoadPlusDeliverySizeExceedsVehicleCapacityInAllDimension_itShouldReturnFalse(){ - Service service = mock(Delivery.class); - when(service.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 3).addDimension(1, 3).addDimension(2, 3).build()); - - JobInsertionContext iContext = mock(JobInsertionContext.class); - when(iContext.getJob()).thenReturn(service); - when(iContext.getRoute()).thenReturn(route); - when(iContext.getNewVehicle()).thenReturn(vehicle); - - assertFalse(constraint.fulfilled(iContext)); - } - - @Test - public void whenLoadPlusDeliverySizeExceedsVehicleCapacityInOneDimension_itShouldReturnFalse(){ - Service service = mock(Delivery.class); - when(service.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 1).addDimension(2, 3).build()); - - JobInsertionContext iContext = mock(JobInsertionContext.class); - when(iContext.getJob()).thenReturn(service); - when(iContext.getRoute()).thenReturn(route); - when(iContext.getNewVehicle()).thenReturn(vehicle); - - assertFalse(constraint.fulfilled(iContext)); - } - - @Test - public void whenLoadPlusDeliverySizeJustFitIntoVehicle_itShouldReturnTrue(){ - Service service = mock(Delivery.class); - when(service.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 2).addDimension(2, 2).build()); - - JobInsertionContext iContext = mock(JobInsertionContext.class); - when(iContext.getJob()).thenReturn(service); - when(iContext.getRoute()).thenReturn(route); - when(iContext.getNewVehicle()).thenReturn(vehicle); - - assertTrue(constraint.fulfilled(iContext)); - } + RouteAndActivityStateGetter stateGetter; - @Test - public void whenLoadPlusPickupSizeDoesNotExceedsVehicleCapacity_itShouldReturnTrue(){ - Service service = mock(Pickup.class); - when(service.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 1).addDimension(2, 1).build()); - - JobInsertionContext iContext = mock(JobInsertionContext.class); - when(iContext.getJob()).thenReturn(service); - when(iContext.getRoute()).thenReturn(route); - when(iContext.getNewVehicle()).thenReturn(vehicle); - - assertTrue(constraint.fulfilled(iContext)); - } - - @Test - public void whenLoadPlusPickupSizeExceedsVehicleCapacityInAllDimension_itShouldReturnFalse(){ - Service service = mock(Pickup.class); - when(service.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 3).addDimension(1, 3).addDimension(2, 3).build()); - - JobInsertionContext iContext = mock(JobInsertionContext.class); - when(iContext.getJob()).thenReturn(service); - when(iContext.getRoute()).thenReturn(route); - when(iContext.getNewVehicle()).thenReturn(vehicle); - - assertFalse(constraint.fulfilled(iContext)); - } - - @Test - public void whenLoadPlusPickupSizeExceedsVehicleCapacityInOneDimension_itShouldReturnFalse(){ - Service service = mock(Pickup.class); - when(service.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 1).addDimension(2, 3).build()); - - JobInsertionContext iContext = mock(JobInsertionContext.class); - when(iContext.getJob()).thenReturn(service); - when(iContext.getRoute()).thenReturn(route); - when(iContext.getNewVehicle()).thenReturn(vehicle); - - assertFalse(constraint.fulfilled(iContext)); - } - - @Test - public void whenLoadPlusPickupSizeJustFitIntoVehicle_itShouldReturnTrue(){ - Service service = mock(Pickup.class); - when(service.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 2).addDimension(2, 2).build()); - - JobInsertionContext iContext = mock(JobInsertionContext.class); - when(iContext.getJob()).thenReturn(service); - when(iContext.getRoute()).thenReturn(route); - when(iContext.getNewVehicle()).thenReturn(vehicle); - - assertTrue(constraint.fulfilled(iContext)); - } - - @Test - public void whenLoadPlusServiceSizeDoesNotExceedsVehicleCapacity_itShouldReturnTrue(){ - Service service = mock(Service.class); - when(service.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 1).addDimension(2, 1).build()); - - JobInsertionContext iContext = mock(JobInsertionContext.class); - when(iContext.getJob()).thenReturn(service); - when(iContext.getRoute()).thenReturn(route); - when(iContext.getNewVehicle()).thenReturn(vehicle); - - assertTrue(constraint.fulfilled(iContext)); - } - - @Test - public void whenLoadPlusServiceSizeExceedsVehicleCapacityInAllDimension_itShouldReturnFalse(){ - Service service = mock(Service.class); - when(service.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 3).addDimension(1, 3).addDimension(2, 3).build()); - - JobInsertionContext iContext = mock(JobInsertionContext.class); - when(iContext.getJob()).thenReturn(service); - when(iContext.getRoute()).thenReturn(route); - when(iContext.getNewVehicle()).thenReturn(vehicle); - - assertFalse(constraint.fulfilled(iContext)); - } - - @Test - public void whenLoadPlusServiceSizeExceedsVehicleCapacityInOneDimension_itShouldReturnFalse(){ - Service service = mock(Service.class); - when(service.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 1).addDimension(2, 3).build()); - - JobInsertionContext iContext = mock(JobInsertionContext.class); - when(iContext.getJob()).thenReturn(service); - when(iContext.getRoute()).thenReturn(route); - when(iContext.getNewVehicle()).thenReturn(vehicle); - - assertFalse(constraint.fulfilled(iContext)); - } - - @Test - public void whenLoadPlusServiceSizeJustFitIntoVehicle_itShouldReturnTrue(){ - Service service = mock(Service.class); - when(service.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 2).addDimension(2, 2).build()); - - JobInsertionContext iContext = mock(JobInsertionContext.class); - when(iContext.getJob()).thenReturn(service); - when(iContext.getRoute()).thenReturn(route); - when(iContext.getNewVehicle()).thenReturn(vehicle); - - assertTrue(constraint.fulfilled(iContext)); - } - - @Test - public void whenAddingAServiceAndNewVehicleDoesNotHaveTheCapacity_itShouldReturnFalse(){ - Service service = mock(Service.class); - when(service.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 2).build()); - - Capacity atBeginning = Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 2).addDimension(2, 1).build(); - Capacity atEnd = Capacity.Builder.newInstance().addDimension(0, 0).addDimension(1, 0).addDimension(2, 0).build(); - - RouteAndActivityStateGetter stateGetter = mock(RouteAndActivityStateGetter.class); - when(stateGetter.getRouteState(route, InternalStates.LOAD_AT_BEGINNING, Capacity.class)).thenReturn(atBeginning); - when(stateGetter.getRouteState(route, InternalStates.LOAD_AT_END, Capacity.class)).thenReturn(atEnd); - when(stateGetter.getRouteState(route, InternalStates.MAXLOAD, Capacity.class)).thenReturn(atBeginning); - - JobInsertionContext iContext = mock(JobInsertionContext.class); - when(iContext.getJob()).thenReturn(service); - when(iContext.getRoute()).thenReturn(route); - - VehicleType type = mock(VehicleType.class); - when(type.getCapacityDimensions()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 1).addDimension(2, 2).build()); - Vehicle vehicle = mock(Vehicle.class); - when(vehicle.getType()).thenReturn(type); - - when(iContext.getNewVehicle()).thenReturn(vehicle); - - ServiceLoadRouteLevelConstraint constraint = new ServiceLoadRouteLevelConstraint(stateGetter); - assertFalse(constraint.fulfilled(iContext)); - } - - @Test - public void whenAddingADeliveryAndNewVehicleDoesNotHaveTheCapacity_itShouldReturnFalse(){ - Service service = mock(Delivery.class); - when(service.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 2).build()); - - Capacity atBeginning = Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 2).addDimension(2, 1).build(); - Capacity atEnd = Capacity.Builder.newInstance().addDimension(0, 0).addDimension(1, 0).addDimension(2, 0).build(); - - RouteAndActivityStateGetter stateGetter = mock(RouteAndActivityStateGetter.class); - when(stateGetter.getRouteState(route, InternalStates.LOAD_AT_BEGINNING, Capacity.class)).thenReturn(atBeginning); - when(stateGetter.getRouteState(route, InternalStates.LOAD_AT_END, Capacity.class)).thenReturn(atEnd); - when(stateGetter.getRouteState(route, InternalStates.MAXLOAD, Capacity.class)).thenReturn(atBeginning); - - JobInsertionContext iContext = mock(JobInsertionContext.class); - when(iContext.getJob()).thenReturn(service); - when(iContext.getRoute()).thenReturn(route); - - VehicleType type = mock(VehicleType.class); - when(type.getCapacityDimensions()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 1).addDimension(2, 2).build()); - vehicle = mock(Vehicle.class); - when(vehicle.getType()).thenReturn(type); - - when(iContext.getNewVehicle()).thenReturn(vehicle); - - ServiceLoadRouteLevelConstraint constraint = new ServiceLoadRouteLevelConstraint(stateGetter); - assertFalse(constraint.fulfilled(iContext)); - } - - @Test - public void whenAddingAPickupAndNewVehicleDoesNotHaveTheCapacity_itShouldReturnFalse(){ - Pickup service = mock(Pickup.class); - when(service.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 2).build()); - - Capacity atBeginning = Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 2).addDimension(2, 1).build(); - Capacity atEnd = Capacity.Builder.newInstance().addDimension(0, 0).addDimension(1, 0).addDimension(2, 0).build(); - - RouteAndActivityStateGetter stateGetter = mock(RouteAndActivityStateGetter.class); - when(stateGetter.getRouteState(route, InternalStates.LOAD_AT_BEGINNING, Capacity.class)).thenReturn(atBeginning); - when(stateGetter.getRouteState(route, InternalStates.LOAD_AT_END, Capacity.class)).thenReturn(atEnd); - when(stateGetter.getRouteState(route, InternalStates.MAXLOAD, Capacity.class)).thenReturn(atBeginning); - - JobInsertionContext iContext = mock(JobInsertionContext.class); - when(iContext.getJob()).thenReturn(service); - when(iContext.getRoute()).thenReturn(route); - - VehicleType type = mock(VehicleType.class); - when(type.getCapacityDimensions()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 1).addDimension(2, 2).build()); - vehicle = mock(Vehicle.class); - when(vehicle.getType()).thenReturn(type); - - when(iContext.getNewVehicle()).thenReturn(vehicle); - - ServiceLoadRouteLevelConstraint constraint = new ServiceLoadRouteLevelConstraint(stateGetter); - assertFalse(constraint.fulfilled(iContext)); - } - - @Test - public void whenNewVehicleCapacityIsNotSufficiant1_returnFalse(){ - final Service pickup = createPickup("pick",2); - final Service pickup2 = createPickup("pick2",3); + ServiceLoadRouteLevelConstraint constraint; - VehicleType type = VehicleTypeImpl.Builder.newInstance("type").addCapacityDimension(0,3).build(); + StateManager stateManager; + + @Before + public void doBefore() { + VehicleType type = mock(VehicleType.class); + when(type.getCapacityDimensions()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 3).addDimension(1, 3).addDimension(2, 3).build()); + vehicle = mock(Vehicle.class); + when(vehicle.getType()).thenReturn(type); + + route = mock(VehicleRoute.class); + + Capacity currentLoad = Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 1).addDimension(2, 1).build(); + stateGetter = mock(RouteAndActivityStateGetter.class); + when(stateGetter.getRouteState(route, InternalStates.LOAD_AT_BEGINNING, Capacity.class)).thenReturn(currentLoad); + when(stateGetter.getRouteState(route, InternalStates.LOAD_AT_END, Capacity.class)).thenReturn(currentLoad); + when(stateGetter.getRouteState(route, InternalStates.MAXLOAD, Capacity.class)).thenReturn(currentLoad); + + constraint = new ServiceLoadRouteLevelConstraint(stateGetter); + + VehicleRoutingProblem vrpMock = mock(VehicleRoutingProblem.class); + when(vrpMock.getFleetSize()).thenReturn(VehicleRoutingProblem.FleetSize.INFINITE); + stateManager = new StateManager(vrpMock); + stateManager.updateLoadStates(); + } + + @Test + public void whenLoadPlusDeliverySizeDoesNotExceedsVehicleCapacity_itShouldReturnTrue() { + Service service = mock(Delivery.class); + when(service.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 1).addDimension(2, 1).build()); + + JobInsertionContext iContext = mock(JobInsertionContext.class); + when(iContext.getJob()).thenReturn(service); + when(iContext.getRoute()).thenReturn(route); + when(iContext.getNewVehicle()).thenReturn(vehicle); + + assertTrue(constraint.fulfilled(iContext)); + } + + @Test + public void whenLoadPlusDeliverySizeExceedsVehicleCapacityInAllDimension_itShouldReturnFalse() { + Service service = mock(Delivery.class); + when(service.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 3).addDimension(1, 3).addDimension(2, 3).build()); + + JobInsertionContext iContext = mock(JobInsertionContext.class); + when(iContext.getJob()).thenReturn(service); + when(iContext.getRoute()).thenReturn(route); + when(iContext.getNewVehicle()).thenReturn(vehicle); + + assertFalse(constraint.fulfilled(iContext)); + } + + @Test + public void whenLoadPlusDeliverySizeExceedsVehicleCapacityInOneDimension_itShouldReturnFalse() { + Service service = mock(Delivery.class); + when(service.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 1).addDimension(2, 3).build()); + + JobInsertionContext iContext = mock(JobInsertionContext.class); + when(iContext.getJob()).thenReturn(service); + when(iContext.getRoute()).thenReturn(route); + when(iContext.getNewVehicle()).thenReturn(vehicle); + + assertFalse(constraint.fulfilled(iContext)); + } + + @Test + public void whenLoadPlusDeliverySizeJustFitIntoVehicle_itShouldReturnTrue() { + Service service = mock(Delivery.class); + when(service.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 2).addDimension(2, 2).build()); + + JobInsertionContext iContext = mock(JobInsertionContext.class); + when(iContext.getJob()).thenReturn(service); + when(iContext.getRoute()).thenReturn(route); + when(iContext.getNewVehicle()).thenReturn(vehicle); + + assertTrue(constraint.fulfilled(iContext)); + } + + @Test + public void whenLoadPlusPickupSizeDoesNotExceedsVehicleCapacity_itShouldReturnTrue() { + Service service = mock(Pickup.class); + when(service.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 1).addDimension(2, 1).build()); + + JobInsertionContext iContext = mock(JobInsertionContext.class); + when(iContext.getJob()).thenReturn(service); + when(iContext.getRoute()).thenReturn(route); + when(iContext.getNewVehicle()).thenReturn(vehicle); + + assertTrue(constraint.fulfilled(iContext)); + } + + @Test + public void whenLoadPlusPickupSizeExceedsVehicleCapacityInAllDimension_itShouldReturnFalse() { + Service service = mock(Pickup.class); + when(service.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 3).addDimension(1, 3).addDimension(2, 3).build()); + + JobInsertionContext iContext = mock(JobInsertionContext.class); + when(iContext.getJob()).thenReturn(service); + when(iContext.getRoute()).thenReturn(route); + when(iContext.getNewVehicle()).thenReturn(vehicle); + + assertFalse(constraint.fulfilled(iContext)); + } + + @Test + public void whenLoadPlusPickupSizeExceedsVehicleCapacityInOneDimension_itShouldReturnFalse() { + Service service = mock(Pickup.class); + when(service.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 1).addDimension(2, 3).build()); + + JobInsertionContext iContext = mock(JobInsertionContext.class); + when(iContext.getJob()).thenReturn(service); + when(iContext.getRoute()).thenReturn(route); + when(iContext.getNewVehicle()).thenReturn(vehicle); + + assertFalse(constraint.fulfilled(iContext)); + } + + @Test + public void whenLoadPlusPickupSizeJustFitIntoVehicle_itShouldReturnTrue() { + Service service = mock(Pickup.class); + when(service.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 2).addDimension(2, 2).build()); + + JobInsertionContext iContext = mock(JobInsertionContext.class); + when(iContext.getJob()).thenReturn(service); + when(iContext.getRoute()).thenReturn(route); + when(iContext.getNewVehicle()).thenReturn(vehicle); + + assertTrue(constraint.fulfilled(iContext)); + } + + @Test + public void whenLoadPlusServiceSizeDoesNotExceedsVehicleCapacity_itShouldReturnTrue() { + Service service = mock(Service.class); + when(service.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 1).addDimension(2, 1).build()); + + JobInsertionContext iContext = mock(JobInsertionContext.class); + when(iContext.getJob()).thenReturn(service); + when(iContext.getRoute()).thenReturn(route); + when(iContext.getNewVehicle()).thenReturn(vehicle); + + assertTrue(constraint.fulfilled(iContext)); + } + + @Test + public void whenLoadPlusServiceSizeExceedsVehicleCapacityInAllDimension_itShouldReturnFalse() { + Service service = mock(Service.class); + when(service.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 3).addDimension(1, 3).addDimension(2, 3).build()); + + JobInsertionContext iContext = mock(JobInsertionContext.class); + when(iContext.getJob()).thenReturn(service); + when(iContext.getRoute()).thenReturn(route); + when(iContext.getNewVehicle()).thenReturn(vehicle); + + assertFalse(constraint.fulfilled(iContext)); + } + + @Test + public void whenLoadPlusServiceSizeExceedsVehicleCapacityInOneDimension_itShouldReturnFalse() { + Service service = mock(Service.class); + when(service.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 1).addDimension(2, 3).build()); + + JobInsertionContext iContext = mock(JobInsertionContext.class); + when(iContext.getJob()).thenReturn(service); + when(iContext.getRoute()).thenReturn(route); + when(iContext.getNewVehicle()).thenReturn(vehicle); + + assertFalse(constraint.fulfilled(iContext)); + } + + @Test + public void whenLoadPlusServiceSizeJustFitIntoVehicle_itShouldReturnTrue() { + Service service = mock(Service.class); + when(service.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 2).addDimension(2, 2).build()); + + JobInsertionContext iContext = mock(JobInsertionContext.class); + when(iContext.getJob()).thenReturn(service); + when(iContext.getRoute()).thenReturn(route); + when(iContext.getNewVehicle()).thenReturn(vehicle); + + assertTrue(constraint.fulfilled(iContext)); + } + + @Test + public void whenAddingAServiceAndNewVehicleDoesNotHaveTheCapacity_itShouldReturnFalse() { + Service service = mock(Service.class); + when(service.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 2).build()); + + Capacity atBeginning = Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 2).addDimension(2, 1).build(); + Capacity atEnd = Capacity.Builder.newInstance().addDimension(0, 0).addDimension(1, 0).addDimension(2, 0).build(); + + RouteAndActivityStateGetter stateGetter = mock(RouteAndActivityStateGetter.class); + when(stateGetter.getRouteState(route, InternalStates.LOAD_AT_BEGINNING, Capacity.class)).thenReturn(atBeginning); + when(stateGetter.getRouteState(route, InternalStates.LOAD_AT_END, Capacity.class)).thenReturn(atEnd); + when(stateGetter.getRouteState(route, InternalStates.MAXLOAD, Capacity.class)).thenReturn(atBeginning); + + JobInsertionContext iContext = mock(JobInsertionContext.class); + when(iContext.getJob()).thenReturn(service); + when(iContext.getRoute()).thenReturn(route); + + VehicleType type = mock(VehicleType.class); + when(type.getCapacityDimensions()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 1).addDimension(2, 2).build()); + Vehicle vehicle = mock(Vehicle.class); + when(vehicle.getType()).thenReturn(type); + + when(iContext.getNewVehicle()).thenReturn(vehicle); + + ServiceLoadRouteLevelConstraint constraint = new ServiceLoadRouteLevelConstraint(stateGetter); + assertFalse(constraint.fulfilled(iContext)); + } + + @Test + public void whenAddingADeliveryAndNewVehicleDoesNotHaveTheCapacity_itShouldReturnFalse() { + Service service = mock(Delivery.class); + when(service.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 2).build()); + + Capacity atBeginning = Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 2).addDimension(2, 1).build(); + Capacity atEnd = Capacity.Builder.newInstance().addDimension(0, 0).addDimension(1, 0).addDimension(2, 0).build(); + + RouteAndActivityStateGetter stateGetter = mock(RouteAndActivityStateGetter.class); + when(stateGetter.getRouteState(route, InternalStates.LOAD_AT_BEGINNING, Capacity.class)).thenReturn(atBeginning); + when(stateGetter.getRouteState(route, InternalStates.LOAD_AT_END, Capacity.class)).thenReturn(atEnd); + when(stateGetter.getRouteState(route, InternalStates.MAXLOAD, Capacity.class)).thenReturn(atBeginning); + + JobInsertionContext iContext = mock(JobInsertionContext.class); + when(iContext.getJob()).thenReturn(service); + when(iContext.getRoute()).thenReturn(route); + + VehicleType type = mock(VehicleType.class); + when(type.getCapacityDimensions()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 1).addDimension(2, 2).build()); + vehicle = mock(Vehicle.class); + when(vehicle.getType()).thenReturn(type); + + when(iContext.getNewVehicle()).thenReturn(vehicle); + + ServiceLoadRouteLevelConstraint constraint = new ServiceLoadRouteLevelConstraint(stateGetter); + assertFalse(constraint.fulfilled(iContext)); + } + + @Test + public void whenAddingAPickupAndNewVehicleDoesNotHaveTheCapacity_itShouldReturnFalse() { + Pickup service = mock(Pickup.class); + when(service.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 2).build()); + + Capacity atBeginning = Capacity.Builder.newInstance().addDimension(0, 1).addDimension(1, 2).addDimension(2, 1).build(); + Capacity atEnd = Capacity.Builder.newInstance().addDimension(0, 0).addDimension(1, 0).addDimension(2, 0).build(); + + RouteAndActivityStateGetter stateGetter = mock(RouteAndActivityStateGetter.class); + when(stateGetter.getRouteState(route, InternalStates.LOAD_AT_BEGINNING, Capacity.class)).thenReturn(atBeginning); + when(stateGetter.getRouteState(route, InternalStates.LOAD_AT_END, Capacity.class)).thenReturn(atEnd); + when(stateGetter.getRouteState(route, InternalStates.MAXLOAD, Capacity.class)).thenReturn(atBeginning); + + JobInsertionContext iContext = mock(JobInsertionContext.class); + when(iContext.getJob()).thenReturn(service); + when(iContext.getRoute()).thenReturn(route); + + VehicleType type = mock(VehicleType.class); + when(type.getCapacityDimensions()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 2).addDimension(1, 1).addDimension(2, 2).build()); + vehicle = mock(Vehicle.class); + when(vehicle.getType()).thenReturn(type); + + when(iContext.getNewVehicle()).thenReturn(vehicle); + + ServiceLoadRouteLevelConstraint constraint = new ServiceLoadRouteLevelConstraint(stateGetter); + assertFalse(constraint.fulfilled(iContext)); + } + + @Test + public void whenNewVehicleCapacityIsNotSufficiant1_returnFalse() { + final Service pickup = createPickup("pick", 2); + final Service pickup2 = createPickup("pick2", 3); + + VehicleType type = VehicleTypeImpl.Builder.newInstance("type").addCapacityDimension(0, 3).build(); VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setType(type).setStartLocation(Location.newInstance("loc")).build(); VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addVehicle(vehicle).addJob(pickup).addJob(pickup2).build(); - VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle).setJobActivityFactory(vrp.getJobActivityFactory()).addService(pickup2).build(); + VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle).setJobActivityFactory(vrp.getJobActivityFactory()).addService(pickup2).build(); - stateManager.informInsertionStarts(Arrays.asList(route), null); - JobInsertionContext iContext = new JobInsertionContext(route,pickup,vehicle,null,0.); - assertFalse(new ServiceLoadRouteLevelConstraint(stateManager).fulfilled(iContext)); - } - - @Test - public void whenNewVehicleCapacityIsNotSufficiant2_returnFalse(){ - Pickup service = (Pickup) createPickup("pick",2); - Service serviceInRoute = createPickup("pick1",3); - VehicleType type = VehicleTypeImpl.Builder.newInstance("type").addCapacityDimension(0,3).build(); + stateManager.informInsertionStarts(Arrays.asList(route), null); + JobInsertionContext iContext = new JobInsertionContext(route, pickup, vehicle, null, 0.); + assertFalse(new ServiceLoadRouteLevelConstraint(stateManager).fulfilled(iContext)); + } + + @Test + public void whenNewVehicleCapacityIsNotSufficiant2_returnFalse() { + Pickup service = (Pickup) createPickup("pick", 2); + Service serviceInRoute = createPickup("pick1", 3); + VehicleType type = VehicleTypeImpl.Builder.newInstance("type").addCapacityDimension(0, 3).build(); VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setType(type).setStartLocation(Location.newInstance("loc")).build(); VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addVehicle(vehicle).addJob(service).addJob(serviceInRoute).build(); VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle).setJobActivityFactory(vrp.getJobActivityFactory()).addService(serviceInRoute).build(); stateManager.informInsertionStarts(Arrays.asList(route), null); - JobInsertionContext iContext = new JobInsertionContext(route,service,vehicle,null,0.); + JobInsertionContext iContext = new JobInsertionContext(route, service, vehicle, null, 0.); - assertFalse(new ServiceLoadRouteLevelConstraint(stateManager).fulfilled(iContext)); - } - - + assertFalse(new ServiceLoadRouteLevelConstraint(stateManager).fulfilled(iContext)); + } + + + private Service createPickup(String string, int i) { + return Pickup.Builder.newInstance(string).addSizeDimension(0, i).setLocation(Location.newInstance("loc")).build(); + } - private Service createPickup(String string, int i) { - return Pickup.Builder.newInstance(string).addSizeDimension(0, i).setLocation(Location.newInstance("loc")).build(); - } - } diff --git a/jsprit-core/src/test/java/jsprit/core/problem/constraint/SkillConstraintTest.java b/jsprit-core/src/test/java/jsprit/core/problem/constraint/SkillConstraintTest.java index 79ec5a58..66402c68 100644 --- a/jsprit-core/src/test/java/jsprit/core/problem/constraint/SkillConstraintTest.java +++ b/jsprit-core/src/test/java/jsprit/core/problem/constraint/SkillConstraintTest.java @@ -48,7 +48,7 @@ public class SkillConstraintTest { private VehicleRoutingProblem vrp; @Before - public void doBefore(){ + public void doBefore() { VehicleType type = VehicleTypeImpl.Builder.newInstance("t").build(); vehicle = VehicleImpl.Builder.newInstance("v").addSkill("skill1").addSkill("skill2").addSkill("skill3").addSkill("skill4").setStartLocation(Location.newInstance("start")).setType(type).build(); vehicle2 = VehicleImpl.Builder.newInstance("v").addSkill("skill4").addSkill("skill5").setStartLocation(Location.newInstance("start")).setType(type).build(); @@ -60,44 +60,44 @@ public class SkillConstraintTest { Service service4 = Service.Builder.newInstance("s4").setLocation(Location.newInstance("loc")).addRequiredSkill("skill1").build(); vrp = VehicleRoutingProblem.Builder.newInstance().addVehicle(vehicle).addVehicle(vehicle2).addJob(service) - .addJob(service2).addJob(service3).addJob(service4).build(); + .addJob(service2).addJob(service3).addJob(service4).build(); route = VehicleRoute.Builder.newInstance(vehicle).setJobActivityFactory(vrp.getJobActivityFactory()).addService(service).addService(service2).build(); StateManager stateManager = new StateManager(vrp); stateManager.updateSkillStates(); - stateManager.informInsertionStarts(Arrays.asList(route),null); + stateManager.informInsertionStarts(Arrays.asList(route), null); skillConstraint = new HardSkillConstraint(stateManager); } @Test - public void whenJobToBeInsertedRequiresSkillsThatNewVehicleDoesNotHave_itShouldReturnFalse(){ - JobInsertionContext insertionContext = new JobInsertionContext(route,vrp.getJobs().get("s3"),vehicle,route.getDriver(),0.); + public void whenJobToBeInsertedRequiresSkillsThatNewVehicleDoesNotHave_itShouldReturnFalse() { + JobInsertionContext insertionContext = new JobInsertionContext(route, vrp.getJobs().get("s3"), vehicle, route.getDriver(), 0.); assertFalse(skillConstraint.fulfilled(insertionContext)); } @Test - public void whenJobToBeInsertedRequiresSkillsThatVehicleHave_itShouldReturnTrue(){ - JobInsertionContext insertionContext = new JobInsertionContext(route,vrp.getJobs().get("s4"),vehicle,route.getDriver(),0.); + public void whenJobToBeInsertedRequiresSkillsThatVehicleHave_itShouldReturnTrue() { + JobInsertionContext insertionContext = new JobInsertionContext(route, vrp.getJobs().get("s4"), vehicle, route.getDriver(), 0.); assertTrue(skillConstraint.fulfilled(insertionContext)); } @Test - public void whenRouteToBeOvertakenRequiresSkillsThatVehicleDoesNotHave_itShouldReturnFalse(){ - JobInsertionContext insertionContext = new JobInsertionContext(route,vrp.getJobs().get("s3"),vehicle2,route.getDriver(),0.); + public void whenRouteToBeOvertakenRequiresSkillsThatVehicleDoesNotHave_itShouldReturnFalse() { + JobInsertionContext insertionContext = new JobInsertionContext(route, vrp.getJobs().get("s3"), vehicle2, route.getDriver(), 0.); assertFalse(skillConstraint.fulfilled(insertionContext)); } @Test - public void whenRouteToBeOvertakenRequiresSkillsThatVehicleDoesNotHave2_itShouldReturnFalse(){ - JobInsertionContext insertionContext = new JobInsertionContext(route,vrp.getJobs().get("s4"),vehicle2,route.getDriver(),0.); + public void whenRouteToBeOvertakenRequiresSkillsThatVehicleDoesNotHave2_itShouldReturnFalse() { + JobInsertionContext insertionContext = new JobInsertionContext(route, vrp.getJobs().get("s4"), vehicle2, route.getDriver(), 0.); assertFalse(skillConstraint.fulfilled(insertionContext)); } @Test - public void whenRouteToBeOvertakenRequiresSkillsThatVehicleDoesHave_itShouldReturnTrue(){ - JobInsertionContext insertionContext = new JobInsertionContext(route,vrp.getJobs().get("s4"),vehicle,route.getDriver(),0.); + public void whenRouteToBeOvertakenRequiresSkillsThatVehicleDoesHave_itShouldReturnTrue() { + JobInsertionContext insertionContext = new JobInsertionContext(route, vrp.getJobs().get("s4"), vehicle, route.getDriver(), 0.); assertTrue(skillConstraint.fulfilled(insertionContext)); } diff --git a/jsprit-core/src/test/java/jsprit/core/problem/constraint/SoftActivityConstraintManagerTest.java b/jsprit-core/src/test/java/jsprit/core/problem/constraint/SoftActivityConstraintManagerTest.java index 01063894..c3dbd3f2 100644 --- a/jsprit-core/src/test/java/jsprit/core/problem/constraint/SoftActivityConstraintManagerTest.java +++ b/jsprit-core/src/test/java/jsprit/core/problem/constraint/SoftActivityConstraintManagerTest.java @@ -1,18 +1,18 @@ /******************************************************************************* * Copyright (c) 2014 Stefan Schroeder. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . - * + * * Contributors: * Stefan Schroeder - initial API and implementation ******************************************************************************/ @@ -28,41 +28,41 @@ import static org.mockito.Mockito.when; public class SoftActivityConstraintManagerTest { - @Test - public void whenAddingSoftConstraint_managerShouldHaveIt(){ - SoftActivityConstraint c = mock(SoftActivityConstraint.class); - SoftActivityConstraintManager man = new SoftActivityConstraintManager(); - assertEquals(0,man.getConstraints().size()); - man.addConstraint(c); - assertEquals(1,man.getConstraints().size()); - } - - @Test - public void whenAddingTwoSoftConstraints_managerShouldHaveIt(){ - SoftActivityConstraint c1 = mock(SoftActivityConstraint.class); - SoftActivityConstraint c2 = mock(SoftActivityConstraint.class); - SoftActivityConstraintManager man = new SoftActivityConstraintManager(); - assertEquals(0,man.getConstraints().size()); - man.addConstraint(c1); - man.addConstraint(c2); - assertEquals(2,man.getConstraints().size()); - } + @Test + public void whenAddingSoftConstraint_managerShouldHaveIt() { + SoftActivityConstraint c = mock(SoftActivityConstraint.class); + SoftActivityConstraintManager man = new SoftActivityConstraintManager(); + assertEquals(0, man.getConstraints().size()); + man.addConstraint(c); + assertEquals(1, man.getConstraints().size()); + } - @Test - public void whenAddingTwoSoftConstrainta_managerShouldSumCostsCorrectly(){ - SoftActivityConstraint c1 = mock(SoftActivityConstraint.class); - JobInsertionContext iContext = mock(JobInsertionContext.class); - TourActivity act_i = mock(TourActivity.class); - TourActivity act_k = mock(TourActivity.class); - TourActivity act_j = mock(TourActivity.class); - when(c1.getCosts(iContext,act_i,act_k,act_j,0.0)).thenReturn(1.0); - SoftActivityConstraint c2 = mock(SoftActivityConstraint.class); - when(c2.getCosts(iContext,act_i,act_k,act_j,0.0)).thenReturn(2.0); - - SoftActivityConstraintManager man = new SoftActivityConstraintManager(); - - man.addConstraint(c1); - man.addConstraint(c2); - assertEquals(3.0,man.getCosts(iContext,act_i,act_k,act_j,0.0),0.01); - } + @Test + public void whenAddingTwoSoftConstraints_managerShouldHaveIt() { + SoftActivityConstraint c1 = mock(SoftActivityConstraint.class); + SoftActivityConstraint c2 = mock(SoftActivityConstraint.class); + SoftActivityConstraintManager man = new SoftActivityConstraintManager(); + assertEquals(0, man.getConstraints().size()); + man.addConstraint(c1); + man.addConstraint(c2); + assertEquals(2, man.getConstraints().size()); + } + + @Test + public void whenAddingTwoSoftConstrainta_managerShouldSumCostsCorrectly() { + SoftActivityConstraint c1 = mock(SoftActivityConstraint.class); + JobInsertionContext iContext = mock(JobInsertionContext.class); + TourActivity act_i = mock(TourActivity.class); + TourActivity act_k = mock(TourActivity.class); + TourActivity act_j = mock(TourActivity.class); + when(c1.getCosts(iContext, act_i, act_k, act_j, 0.0)).thenReturn(1.0); + SoftActivityConstraint c2 = mock(SoftActivityConstraint.class); + when(c2.getCosts(iContext, act_i, act_k, act_j, 0.0)).thenReturn(2.0); + + SoftActivityConstraintManager man = new SoftActivityConstraintManager(); + + man.addConstraint(c1); + man.addConstraint(c2); + assertEquals(3.0, man.getCosts(iContext, act_i, act_k, act_j, 0.0), 0.01); + } } diff --git a/jsprit-core/src/test/java/jsprit/core/problem/constraint/SoftRouteConstraintManagerTest.java b/jsprit-core/src/test/java/jsprit/core/problem/constraint/SoftRouteConstraintManagerTest.java index 5188a6c0..f571eb39 100644 --- a/jsprit-core/src/test/java/jsprit/core/problem/constraint/SoftRouteConstraintManagerTest.java +++ b/jsprit-core/src/test/java/jsprit/core/problem/constraint/SoftRouteConstraintManagerTest.java @@ -1,18 +1,18 @@ /******************************************************************************* * Copyright (c) 2014 Stefan Schroeder. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . - * + * * Contributors: * Stefan Schroeder - initial API and implementation ******************************************************************************/ @@ -26,38 +26,38 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; public class SoftRouteConstraintManagerTest { - - @Test - public void whenAddingSoftRouteConstraint_managerShouldHaveIt(){ - SoftRouteConstraint c = mock(SoftRouteConstraint.class); - SoftRouteConstraintManager man = new SoftRouteConstraintManager(); - assertEquals(0,man.getConstraints().size()); - man.addConstraint(c); - assertEquals(1,man.getConstraints().size()); - } - - @Test - public void whenAddingTwoSoftRouteConstraint_managerShouldHaveIt(){ - SoftRouteConstraint c1 = mock(SoftRouteConstraint.class); - SoftRouteConstraint c2 = mock(SoftRouteConstraint.class); - SoftRouteConstraintManager man = new SoftRouteConstraintManager(); - assertEquals(0,man.getConstraints().size()); - man.addConstraint(c1); - man.addConstraint(c2); - assertEquals(2,man.getConstraints().size()); - } - @Test - public void whenAddingTwoSoftRouteConstraint_managerShouldSumCostsCorrectly(){ - SoftRouteConstraint c1 = mock(SoftRouteConstraint.class); - JobInsertionContext iContext = mock(JobInsertionContext.class); - when(c1.getCosts(iContext)).thenReturn(1.0); - SoftRouteConstraint c2 = mock(SoftRouteConstraint.class); - when(c2.getCosts(iContext)).thenReturn(2.0); - SoftRouteConstraintManager man = new SoftRouteConstraintManager(); - - man.addConstraint(c1); - man.addConstraint(c2); - assertEquals(3.0,man.getCosts(iContext),0.01); - } + @Test + public void whenAddingSoftRouteConstraint_managerShouldHaveIt() { + SoftRouteConstraint c = mock(SoftRouteConstraint.class); + SoftRouteConstraintManager man = new SoftRouteConstraintManager(); + assertEquals(0, man.getConstraints().size()); + man.addConstraint(c); + assertEquals(1, man.getConstraints().size()); + } + + @Test + public void whenAddingTwoSoftRouteConstraint_managerShouldHaveIt() { + SoftRouteConstraint c1 = mock(SoftRouteConstraint.class); + SoftRouteConstraint c2 = mock(SoftRouteConstraint.class); + SoftRouteConstraintManager man = new SoftRouteConstraintManager(); + assertEquals(0, man.getConstraints().size()); + man.addConstraint(c1); + man.addConstraint(c2); + assertEquals(2, man.getConstraints().size()); + } + + @Test + public void whenAddingTwoSoftRouteConstraint_managerShouldSumCostsCorrectly() { + SoftRouteConstraint c1 = mock(SoftRouteConstraint.class); + JobInsertionContext iContext = mock(JobInsertionContext.class); + when(c1.getCosts(iContext)).thenReturn(1.0); + SoftRouteConstraint c2 = mock(SoftRouteConstraint.class); + when(c2.getCosts(iContext)).thenReturn(2.0); + SoftRouteConstraintManager man = new SoftRouteConstraintManager(); + + man.addConstraint(c1); + man.addConstraint(c2); + assertEquals(3.0, man.getCosts(iContext), 0.01); + } } diff --git a/jsprit-core/src/test/java/jsprit/core/problem/constraint/TestConstraintManager.java b/jsprit-core/src/test/java/jsprit/core/problem/constraint/TestConstraintManager.java index 87b89936..5cad2d4c 100644 --- a/jsprit-core/src/test/java/jsprit/core/problem/constraint/TestConstraintManager.java +++ b/jsprit-core/src/test/java/jsprit/core/problem/constraint/TestConstraintManager.java @@ -28,62 +28,62 @@ import static org.mockito.Mockito.mock; public class TestConstraintManager { - @Test - public void whenGettingConstraintsViaConstructor_theyShouldBeResolvedCorrectly(){ - List constraints = new ArrayList(); - constraints.add(new ServiceDeliveriesFirstConstraint()); - constraints.add(mock(HardRouteConstraint.class)); - ConstraintManager cManager = new ConstraintManager(mock(VehicleRoutingProblem.class),mock(RouteAndActivityStateGetter.class),constraints); - assertEquals(2,cManager.getConstraints().size()); - } - - @Test - public void whenGettingConstraintsViaConstructorAndAtLeastOneConstraintCannotBeResolved_itShouldOnlyAddTheKnownConstraints(){ - List constraints = new ArrayList(); - constraints.add(new ServiceDeliveriesFirstConstraint()); - constraints.add(mock(Constraint.class)); - ConstraintManager cManager = new ConstraintManager(mock(VehicleRoutingProblem.class),mock(RouteAndActivityStateGetter.class),constraints); - assertEquals(1,cManager.getConstraints().size()); - } - - @Test - public void whenAddingSoftRouteConstraint_managerShouldHaveIt(){ - SoftRouteConstraint c = mock(SoftRouteConstraint.class); - ConstraintManager man = new ConstraintManager(mock(VehicleRoutingProblem.class),mock(RouteAndActivityStateGetter.class)); - assertEquals(0,man.getConstraints().size()); - man.addConstraint(c); - assertEquals(1,man.getConstraints().size()); - } - - @Test - public void whenAddingTwoSoftRouteConstraint_managerShouldHaveIt(){ - SoftRouteConstraint c1 = mock(SoftRouteConstraint.class); - SoftRouteConstraint c2 = mock(SoftRouteConstraint.class); - ConstraintManager man = new ConstraintManager(mock(VehicleRoutingProblem.class),mock(RouteAndActivityStateGetter.class)); - assertEquals(0,man.getConstraints().size()); - man.addConstraint(c1); - man.addConstraint(c2); - assertEquals(2,man.getConstraints().size()); - } - - @Test - public void whenAddingSoftActivityConstraint_managerShouldHaveIt(){ - SoftActivityConstraint c = mock(SoftActivityConstraint.class); - ConstraintManager man = new ConstraintManager(mock(VehicleRoutingProblem.class),mock(RouteAndActivityStateGetter.class)); - assertEquals(0,man.getConstraints().size()); - man.addConstraint(c); - assertEquals(1,man.getConstraints().size()); - } - - @Test - public void whenAddingTwoSoftActivityConstraints_managerShouldHaveIt(){ - SoftActivityConstraint c1 = mock(SoftActivityConstraint.class); - SoftActivityConstraint c2 = mock(SoftActivityConstraint.class); - ConstraintManager man = new ConstraintManager(mock(VehicleRoutingProblem.class),mock(RouteAndActivityStateGetter.class)); - assertEquals(0,man.getConstraints().size()); - man.addConstraint(c1); - man.addConstraint(c2); - assertEquals(2, man.getConstraints().size()); - } + @Test + public void whenGettingConstraintsViaConstructor_theyShouldBeResolvedCorrectly() { + List constraints = new ArrayList(); + constraints.add(new ServiceDeliveriesFirstConstraint()); + constraints.add(mock(HardRouteConstraint.class)); + ConstraintManager cManager = new ConstraintManager(mock(VehicleRoutingProblem.class), mock(RouteAndActivityStateGetter.class), constraints); + assertEquals(2, cManager.getConstraints().size()); + } + + @Test + public void whenGettingConstraintsViaConstructorAndAtLeastOneConstraintCannotBeResolved_itShouldOnlyAddTheKnownConstraints() { + List constraints = new ArrayList(); + constraints.add(new ServiceDeliveriesFirstConstraint()); + constraints.add(mock(Constraint.class)); + ConstraintManager cManager = new ConstraintManager(mock(VehicleRoutingProblem.class), mock(RouteAndActivityStateGetter.class), constraints); + assertEquals(1, cManager.getConstraints().size()); + } + + @Test + public void whenAddingSoftRouteConstraint_managerShouldHaveIt() { + SoftRouteConstraint c = mock(SoftRouteConstraint.class); + ConstraintManager man = new ConstraintManager(mock(VehicleRoutingProblem.class), mock(RouteAndActivityStateGetter.class)); + assertEquals(0, man.getConstraints().size()); + man.addConstraint(c); + assertEquals(1, man.getConstraints().size()); + } + + @Test + public void whenAddingTwoSoftRouteConstraint_managerShouldHaveIt() { + SoftRouteConstraint c1 = mock(SoftRouteConstraint.class); + SoftRouteConstraint c2 = mock(SoftRouteConstraint.class); + ConstraintManager man = new ConstraintManager(mock(VehicleRoutingProblem.class), mock(RouteAndActivityStateGetter.class)); + assertEquals(0, man.getConstraints().size()); + man.addConstraint(c1); + man.addConstraint(c2); + assertEquals(2, man.getConstraints().size()); + } + + @Test + public void whenAddingSoftActivityConstraint_managerShouldHaveIt() { + SoftActivityConstraint c = mock(SoftActivityConstraint.class); + ConstraintManager man = new ConstraintManager(mock(VehicleRoutingProblem.class), mock(RouteAndActivityStateGetter.class)); + assertEquals(0, man.getConstraints().size()); + man.addConstraint(c); + assertEquals(1, man.getConstraints().size()); + } + + @Test + public void whenAddingTwoSoftActivityConstraints_managerShouldHaveIt() { + SoftActivityConstraint c1 = mock(SoftActivityConstraint.class); + SoftActivityConstraint c2 = mock(SoftActivityConstraint.class); + ConstraintManager man = new ConstraintManager(mock(VehicleRoutingProblem.class), mock(RouteAndActivityStateGetter.class)); + assertEquals(0, man.getConstraints().size()); + man.addConstraint(c1); + man.addConstraint(c2); + assertEquals(2, man.getConstraints().size()); + } } diff --git a/jsprit-core/src/test/java/jsprit/core/problem/constraint/VehicleDependentTimeWindowTest.java b/jsprit-core/src/test/java/jsprit/core/problem/constraint/VehicleDependentTimeWindowTest.java index 41f0499d..a9e4a694 100644 --- a/jsprit-core/src/test/java/jsprit/core/problem/constraint/VehicleDependentTimeWindowTest.java +++ b/jsprit-core/src/test/java/jsprit/core/problem/constraint/VehicleDependentTimeWindowTest.java @@ -58,29 +58,29 @@ public class VehicleDependentTimeWindowTest { private VehicleImpl v6; @Before - public void doBefore(){ + public void doBefore() { VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); routingCosts = CostFactory.createEuclideanCosts(); vrpBuilder.setRoutingCost(routingCosts); VehicleType type = VehicleTypeImpl.Builder.newInstance("type").build(); vehicle = VehicleImpl.Builder.newInstance("v").setType(type).setStartLocation(Location.newInstance("0,0")) - .setEarliestStart(0.).setLatestArrival(100.).build(); + .setEarliestStart(0.).setLatestArrival(100.).build(); v2 = VehicleImpl.Builder.newInstance("v2").setType(type).setStartLocation(Location.newInstance("0,0")) - .setEarliestStart(0.).setLatestArrival(60.).build(); + .setEarliestStart(0.).setLatestArrival(60.).build(); v3 = VehicleImpl.Builder.newInstance("v3").setType(type).setStartLocation(Location.newInstance("0,0")) - .setEarliestStart(0.).setLatestArrival(50.).build(); + .setEarliestStart(0.).setLatestArrival(50.).build(); v4 = VehicleImpl.Builder.newInstance("v4").setType(type).setStartLocation(Location.newInstance("0,0")) - .setEarliestStart(0.).setLatestArrival(10.).build(); + .setEarliestStart(0.).setLatestArrival(10.).build(); v5 = VehicleImpl.Builder.newInstance("v5").setType(type).setStartLocation(Location.newInstance("0,0")) - .setEarliestStart(60.).setLatestArrival(100.).build(); + .setEarliestStart(60.).setLatestArrival(100.).build(); v6 = VehicleImpl.Builder.newInstance("v6").setType(type).setStartLocation(Location.newInstance("0,0")) - .setEndLocation(Location.newInstance("40,0")).setEarliestStart(0.).setLatestArrival(40.).build(); + .setEndLocation(Location.newInstance("40,0")).setEarliestStart(0.).setLatestArrival(40.).build(); vrpBuilder.addVehicle(vehicle).addVehicle(v2).addVehicle(v3).addVehicle(v4).addVehicle(v5).addVehicle(v6); @@ -130,32 +130,32 @@ public class VehicleDependentTimeWindowTest { } @Test - public void stateManagerShouldHaveMemorizedCorrectLatestEndOfAct3(){ - assertEquals(70.,stateManager.getActivityState(route.getActivities().get(2), - vehicle, InternalStates.LATEST_OPERATION_START_TIME, Double.class),0.01); + public void stateManagerShouldHaveMemorizedCorrectLatestEndOfAct3() { + assertEquals(70., stateManager.getActivityState(route.getActivities().get(2), + vehicle, InternalStates.LATEST_OPERATION_START_TIME, Double.class), 0.01); } @Test - public void stateManagerShouldHaveMemorizedCorrectLatestEndOfAct2(){ - assertEquals(60.,stateManager.getActivityState(route.getActivities().get(1), - vehicle, InternalStates.LATEST_OPERATION_START_TIME, Double.class),0.01); + public void stateManagerShouldHaveMemorizedCorrectLatestEndOfAct2() { + assertEquals(60., stateManager.getActivityState(route.getActivities().get(1), + vehicle, InternalStates.LATEST_OPERATION_START_TIME, Double.class), 0.01); } @Test - public void stateManagerShouldHaveMemorizedCorrectLatestEndOfAct1(){ - assertEquals(50.,stateManager.getActivityState(route.getActivities().get(0), - vehicle, InternalStates.LATEST_OPERATION_START_TIME, Double.class),0.01); + public void stateManagerShouldHaveMemorizedCorrectLatestEndOfAct1() { + assertEquals(50., stateManager.getActivityState(route.getActivities().get(0), + vehicle, InternalStates.LATEST_OPERATION_START_TIME, Double.class), 0.01); } @Test - public void whenNewJobIsInsertedWithOldVeh_itJustShouldReturnTrue(){ + public void whenNewJobIsInsertedWithOldVeh_itJustShouldReturnTrue() { Service s4 = Service.Builder.newInstance("s4").setLocation(Location.newInstance("50,0")).build(); PickupService serviceAct = new PickupService(s4); - JobInsertionContext insertionContext = new JobInsertionContext(route,s4,vehicle,route.getDriver(),0.); + JobInsertionContext insertionContext = new JobInsertionContext(route, s4, vehicle, route.getDriver(), 0.); - HardActivityConstraint twConstraint = new VehicleDependentTimeWindowConstraints(stateManager,routingCosts); + HardActivityConstraint twConstraint = new VehicleDependentTimeWindowConstraints(stateManager, routingCosts); HardActivityConstraint.ConstraintsStatus status = twConstraint.fulfilled(insertionContext, route.getActivities().get(2), serviceAct, route.getEnd(), 30.); assertTrue(status.equals(HardActivityConstraint.ConstraintsStatus.FULFILLED)); @@ -163,14 +163,14 @@ public class VehicleDependentTimeWindowTest { } @Test - public void whenNewJobIsInsertedWithOldVeh_itJustShouldReturnFalse(){ + public void whenNewJobIsInsertedWithOldVeh_itJustShouldReturnFalse() { Service s4 = Service.Builder.newInstance("s4").setLocation(Location.newInstance("1000,0")).build(); PickupService serviceAct = new PickupService(s4); - JobInsertionContext insertionContext = new JobInsertionContext(route,s4,vehicle,route.getDriver(),0.); + JobInsertionContext insertionContext = new JobInsertionContext(route, s4, vehicle, route.getDriver(), 0.); - HardActivityConstraint twConstraint = new VehicleDependentTimeWindowConstraints(stateManager,routingCosts); + HardActivityConstraint twConstraint = new VehicleDependentTimeWindowConstraints(stateManager, routingCosts); HardActivityConstraint.ConstraintsStatus status = twConstraint.fulfilled(insertionContext, route.getActivities().get(2), serviceAct, route.getEnd(), 30.); assertFalse(status.equals(HardActivityConstraint.ConstraintsStatus.FULFILLED)); @@ -178,14 +178,14 @@ public class VehicleDependentTimeWindowTest { } @Test - public void whenNewJobIsInsertedInBetweenAct1And2WithOldVeh_itJustShouldReturnTrue(){ + public void whenNewJobIsInsertedInBetweenAct1And2WithOldVeh_itJustShouldReturnTrue() { Service s4 = Service.Builder.newInstance("s4").setLocation(Location.newInstance("50,0")).build(); PickupService serviceAct = new PickupService(s4); - JobInsertionContext insertionContext = new JobInsertionContext(route,s4,vehicle,route.getDriver(),0.); + JobInsertionContext insertionContext = new JobInsertionContext(route, s4, vehicle, route.getDriver(), 0.); - HardActivityConstraint twConstraint = new VehicleDependentTimeWindowConstraints(stateManager,routingCosts); + HardActivityConstraint twConstraint = new VehicleDependentTimeWindowConstraints(stateManager, routingCosts); /* driverTime = 10 + 10 + 30 + 20 + 30 = 100 */ @@ -196,18 +196,18 @@ public class VehicleDependentTimeWindowTest { } @Test - public void whenNewJobIsInsertedInBetweenAct1And2WithOldVeh_itJustShouldReturnFalse(){ + public void whenNewJobIsInsertedInBetweenAct1And2WithOldVeh_itJustShouldReturnFalse() { Service s4 = Service.Builder.newInstance("s4").setLocation(Location.newInstance("51,0")).build(); PickupService serviceAct = new PickupService(s4); - JobInsertionContext insertionContext = new JobInsertionContext(route,s4,vehicle,route.getDriver(),0.); + JobInsertionContext insertionContext = new JobInsertionContext(route, s4, vehicle, route.getDriver(), 0.); /* driverTime = 10 + 10 + 31 + 21 + 30 = 102 */ - HardActivityConstraint twConstraint = new VehicleDependentTimeWindowConstraints(stateManager,routingCosts); + HardActivityConstraint twConstraint = new VehicleDependentTimeWindowConstraints(stateManager, routingCosts); HardActivityConstraint.ConstraintsStatus status = twConstraint.fulfilled(insertionContext, route.getActivities().get(1), serviceAct, route.getActivities().get(2), 20.); assertFalse(status.equals(HardActivityConstraint.ConstraintsStatus.FULFILLED)); @@ -215,17 +215,17 @@ public class VehicleDependentTimeWindowTest { } @Test - public void whenJobIsInsertedAlongWithNewVehicleThatNeedsToBeHomeAt60_itShouldReturnFalse(){ + public void whenJobIsInsertedAlongWithNewVehicleThatNeedsToBeHomeAt60_itShouldReturnFalse() { System.out.println("actualEndTime " + route.getEnd().getArrTime()); - assertEquals(60.,route.getEnd().getArrTime(),0.01); + assertEquals(60., route.getEnd().getArrTime(), 0.01); Service s4 = Service.Builder.newInstance("s4").setLocation(Location.newInstance("40,0")).build(); PickupService serviceAct = new PickupService(s4); - JobInsertionContext insertionContext = new JobInsertionContext(route,s4,v2,route.getDriver(),0.); + JobInsertionContext insertionContext = new JobInsertionContext(route, s4, v2, route.getDriver(), 0.); - HardActivityConstraint twConstraint = new VehicleDependentTimeWindowConstraints(stateManager,routingCosts); + HardActivityConstraint twConstraint = new VehicleDependentTimeWindowConstraints(stateManager, routingCosts); HardActivityConstraint.ConstraintsStatus status = twConstraint.fulfilled(insertionContext, route.getActivities().get(2), serviceAct, route.getEnd(), 30.); @@ -234,17 +234,17 @@ public class VehicleDependentTimeWindowTest { } @Test - public void whenJobIsInsertedAlongWithNewVehicleThatNeedsToBeHomeAt50_itShouldReturnFalse(){ + public void whenJobIsInsertedAlongWithNewVehicleThatNeedsToBeHomeAt50_itShouldReturnFalse() { System.out.println("actualEndTime " + route.getEnd().getArrTime()); - assertEquals(60.,route.getEnd().getArrTime(),0.01); + assertEquals(60., route.getEnd().getArrTime(), 0.01); Service s4 = Service.Builder.newInstance("s4").setLocation(Location.newInstance("40,0")).build(); PickupService serviceAct = new PickupService(s4); - JobInsertionContext insertionContext = new JobInsertionContext(route,s4,v3,route.getDriver(),0.); + JobInsertionContext insertionContext = new JobInsertionContext(route, s4, v3, route.getDriver(), 0.); - HardActivityConstraint twConstraint = new VehicleDependentTimeWindowConstraints(stateManager,routingCosts); + HardActivityConstraint twConstraint = new VehicleDependentTimeWindowConstraints(stateManager, routingCosts); HardActivityConstraint.ConstraintsStatus status = twConstraint.fulfilled(insertionContext, route.getActivities().get(2), serviceAct, route.getEnd(), 30.); assertFalse(status.equals(HardActivityConstraint.ConstraintsStatus.FULFILLED)); @@ -252,17 +252,17 @@ public class VehicleDependentTimeWindowTest { } @Test - public void whenJobIsInsertedAlongWithNewVehicleThatNeedsToBeHomeAt10_itShouldReturnFalse(){ + public void whenJobIsInsertedAlongWithNewVehicleThatNeedsToBeHomeAt10_itShouldReturnFalse() { System.out.println("actualEndTime " + route.getEnd().getArrTime()); - assertEquals(60.,route.getEnd().getArrTime(),0.01); + assertEquals(60., route.getEnd().getArrTime(), 0.01); Service s4 = Service.Builder.newInstance("s4").setLocation(Location.newInstance("40,0")).build(); PickupService serviceAct = new PickupService(s4); - JobInsertionContext insertionContext = new JobInsertionContext(route,s4,v4,route.getDriver(),0.); + JobInsertionContext insertionContext = new JobInsertionContext(route, s4, v4, route.getDriver(), 0.); - HardActivityConstraint twConstraint = new VehicleDependentTimeWindowConstraints(stateManager,routingCosts); + HardActivityConstraint twConstraint = new VehicleDependentTimeWindowConstraints(stateManager, routingCosts); HardActivityConstraint.ConstraintsStatus status = twConstraint.fulfilled(insertionContext, route.getActivities().get(2), serviceAct, route.getEnd(), 30.); assertFalse(status.equals(HardActivityConstraint.ConstraintsStatus.FULFILLED)); @@ -270,17 +270,17 @@ public class VehicleDependentTimeWindowTest { } @Test - public void whenJobIsInsertedAlongWithV6BetweenS2AndS3_itShouldReturnFalse(){ + public void whenJobIsInsertedAlongWithV6BetweenS2AndS3_itShouldReturnFalse() { System.out.println("actualEndTime " + route.getEnd().getArrTime()); - assertEquals(60.,route.getEnd().getArrTime(),0.01); + assertEquals(60., route.getEnd().getArrTime(), 0.01); Service s4 = Service.Builder.newInstance("s4").setLocation(Location.newInstance("40,0")).build(); PickupService serviceAct = new PickupService(s4); - JobInsertionContext insertionContext = new JobInsertionContext(route,s4,v6,route.getDriver(),0.); + JobInsertionContext insertionContext = new JobInsertionContext(route, s4, v6, route.getDriver(), 0.); - HardActivityConstraint twConstraint = new VehicleDependentTimeWindowConstraints(stateManager,routingCosts); + HardActivityConstraint twConstraint = new VehicleDependentTimeWindowConstraints(stateManager, routingCosts); HardActivityConstraint.ConstraintsStatus status = twConstraint.fulfilled(insertionContext, route.getActivities().get(1), serviceAct, route.getActivities().get(2), 30.); assertFalse(status.equals(HardActivityConstraint.ConstraintsStatus.FULFILLED)); @@ -288,17 +288,17 @@ public class VehicleDependentTimeWindowTest { } @Test - public void whenJobIsInsertedAlongWithV6BetweenS1AndS2_itShouldReturnFalse(){ + public void whenJobIsInsertedAlongWithV6BetweenS1AndS2_itShouldReturnFalse() { System.out.println("actualEndTime " + route.getEnd().getArrTime()); - assertEquals(60.,route.getEnd().getArrTime(),0.01); + assertEquals(60., route.getEnd().getArrTime(), 0.01); Service s4 = Service.Builder.newInstance("s4").setLocation(Location.newInstance("40,0")).build(); PickupService serviceAct = new PickupService(s4); - JobInsertionContext insertionContext = new JobInsertionContext(route,s4,v6,route.getDriver(),0.); + JobInsertionContext insertionContext = new JobInsertionContext(route, s4, v6, route.getDriver(), 0.); - HardActivityConstraint twConstraint = new VehicleDependentTimeWindowConstraints(stateManager,routingCosts); + HardActivityConstraint twConstraint = new VehicleDependentTimeWindowConstraints(stateManager, routingCosts); HardActivityConstraint.ConstraintsStatus status = twConstraint.fulfilled(insertionContext, route.getActivities().get(0), serviceAct, route.getActivities().get(1), 10.); assertFalse(status.equals(HardActivityConstraint.ConstraintsStatus.FULFILLED)); @@ -306,33 +306,33 @@ public class VehicleDependentTimeWindowTest { } @Test - public void whenJobIsInsertedAlongWithV6AtTheEndOfRoute_itShouldReturnTrue(){ + public void whenJobIsInsertedAlongWithV6AtTheEndOfRoute_itShouldReturnTrue() { System.out.println("actualEndTime " + route.getEnd().getArrTime()); - assertEquals(60.,route.getEnd().getArrTime(),0.01); + assertEquals(60., route.getEnd().getArrTime(), 0.01); Service s4 = Service.Builder.newInstance("s4").setLocation(Location.newInstance("40,0")).build(); PickupService serviceAct = new PickupService(s4); - JobInsertionContext insertionContext = new JobInsertionContext(route,s4,v6,route.getDriver(),0.); + JobInsertionContext insertionContext = new JobInsertionContext(route, s4, v6, route.getDriver(), 0.); - HardActivityConstraint twConstraint = new VehicleDependentTimeWindowConstraints(stateManager,routingCosts); + HardActivityConstraint twConstraint = new VehicleDependentTimeWindowConstraints(stateManager, routingCosts); HardActivityConstraint.ConstraintsStatus status = twConstraint.fulfilled(insertionContext, route.getActivities().get(2), serviceAct, route.getEnd(), 30.); assertTrue(status.equals(HardActivityConstraint.ConstraintsStatus.FULFILLED)); } @Test - public void whenJobIsInsertedAlongWithNewVehicleThatCanOnlyStartAt60_itShouldReturnFalse(){ + public void whenJobIsInsertedAlongWithNewVehicleThatCanOnlyStartAt60_itShouldReturnFalse() { System.out.println("actualEndTime " + route.getEnd().getArrTime()); - assertEquals(60.,route.getEnd().getArrTime(),0.01); + assertEquals(60., route.getEnd().getArrTime(), 0.01); Service s4 = Service.Builder.newInstance("s4").setLocation(Location.newInstance("40,0")).build(); PickupService serviceAct = new PickupService(s4); - JobInsertionContext insertionContext = new JobInsertionContext(route,s4,v5,route.getDriver(),60.); + JobInsertionContext insertionContext = new JobInsertionContext(route, s4, v5, route.getDriver(), 60.); - HardActivityConstraint twConstraint = new VehicleDependentTimeWindowConstraints(stateManager,routingCosts); + HardActivityConstraint twConstraint = new VehicleDependentTimeWindowConstraints(stateManager, routingCosts); HardActivityConstraint.ConstraintsStatus status = twConstraint.fulfilled(insertionContext, route.getActivities().get(2), serviceAct, route.getEnd(), 90.); assertFalse(status.equals(HardActivityConstraint.ConstraintsStatus.FULFILLED)); diff --git a/jsprit-core/src/test/java/jsprit/core/problem/constraint/VehicleDependentTimeWindowWithStartTimeAndMaxOperationTimeTest.java b/jsprit-core/src/test/java/jsprit/core/problem/constraint/VehicleDependentTimeWindowWithStartTimeAndMaxOperationTimeTest.java index fb9a27e0..652e55f4 100644 --- a/jsprit-core/src/test/java/jsprit/core/problem/constraint/VehicleDependentTimeWindowWithStartTimeAndMaxOperationTimeTest.java +++ b/jsprit-core/src/test/java/jsprit/core/problem/constraint/VehicleDependentTimeWindowWithStartTimeAndMaxOperationTimeTest.java @@ -58,29 +58,29 @@ public class VehicleDependentTimeWindowWithStartTimeAndMaxOperationTimeTest { private VehicleImpl v6; @Before - public void doBefore(){ + public void doBefore() { VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); routingCosts = CostFactory.createEuclideanCosts(); vrpBuilder.setRoutingCost(routingCosts); VehicleType type = VehicleTypeImpl.Builder.newInstance("type").build(); vehicle = VehicleImpl.Builder.newInstance("v").setType(type).setStartLocation(Location.newInstance("0,0")) - .setEarliestStart(0.).setLatestArrival(100.).build(); + .setEarliestStart(0.).setLatestArrival(100.).build(); v2 = VehicleImpl.Builder.newInstance("v2").setType(type).setStartLocation(Location.newInstance("0,0")) - .setEarliestStart(0.).setLatestArrival(60.).build(); + .setEarliestStart(0.).setLatestArrival(60.).build(); v3 = VehicleImpl.Builder.newInstance("v3").setType(type).setStartLocation(Location.newInstance("0,0")) - .setEarliestStart(0.).setLatestArrival(50.).build(); + .setEarliestStart(0.).setLatestArrival(50.).build(); v4 = VehicleImpl.Builder.newInstance("v4").setType(type).setStartLocation(Location.newInstance("0,0")) - .setEarliestStart(0.).setLatestArrival(10.).build(); + .setEarliestStart(0.).setLatestArrival(10.).build(); v5 = VehicleImpl.Builder.newInstance("v5").setType(type).setStartLocation(Location.newInstance("0,0")) - .setEarliestStart(60.).setLatestArrival(100.).build(); + .setEarliestStart(60.).setLatestArrival(100.).build(); v6 = VehicleImpl.Builder.newInstance("v6").setType(type).setStartLocation(Location.newInstance("0,0")) - .setEndLocation(Location.newInstance("40,0")).setEarliestStart(0.).setLatestArrival(40.).build(); + .setEndLocation(Location.newInstance("40,0")).setEarliestStart(0.).setLatestArrival(40.).build(); vrpBuilder.addVehicle(vehicle).addVehicle(v2).addVehicle(v3).addVehicle(v4).addVehicle(v5).addVehicle(v6); @@ -130,32 +130,32 @@ public class VehicleDependentTimeWindowWithStartTimeAndMaxOperationTimeTest { } @Test - public void stateManagerShouldHaveMemorizedCorrectLatestEndOfAct3(){ - assertEquals(70.,stateManager.getActivityState(route.getActivities().get(2), - vehicle, InternalStates.LATEST_OPERATION_START_TIME, Double.class),0.01); + public void stateManagerShouldHaveMemorizedCorrectLatestEndOfAct3() { + assertEquals(70., stateManager.getActivityState(route.getActivities().get(2), + vehicle, InternalStates.LATEST_OPERATION_START_TIME, Double.class), 0.01); } @Test - public void stateManagerShouldHaveMemorizedCorrectLatestEndOfAct2(){ - assertEquals(60.,stateManager.getActivityState(route.getActivities().get(1), - vehicle, InternalStates.LATEST_OPERATION_START_TIME, Double.class),0.01); + public void stateManagerShouldHaveMemorizedCorrectLatestEndOfAct2() { + assertEquals(60., stateManager.getActivityState(route.getActivities().get(1), + vehicle, InternalStates.LATEST_OPERATION_START_TIME, Double.class), 0.01); } @Test - public void stateManagerShouldHaveMemorizedCorrectLatestEndOfAct1(){ - assertEquals(50.,stateManager.getActivityState(route.getActivities().get(0), - vehicle, InternalStates.LATEST_OPERATION_START_TIME, Double.class),0.01); + public void stateManagerShouldHaveMemorizedCorrectLatestEndOfAct1() { + assertEquals(50., stateManager.getActivityState(route.getActivities().get(0), + vehicle, InternalStates.LATEST_OPERATION_START_TIME, Double.class), 0.01); } @Test - public void whenNewJobIsInsertedWithOldVeh_itJustShouldReturnTrue(){ + public void whenNewJobIsInsertedWithOldVeh_itJustShouldReturnTrue() { Service s4 = Service.Builder.newInstance("s4").setLocation(Location.newInstance("50,0")).build(); PickupService serviceAct = new PickupService(s4); - JobInsertionContext insertionContext = new JobInsertionContext(route,s4,vehicle,route.getDriver(),0.); + JobInsertionContext insertionContext = new JobInsertionContext(route, s4, vehicle, route.getDriver(), 0.); - HardActivityConstraint twConstraint = new VehicleDependentTimeWindowConstraints(stateManager,routingCosts); + HardActivityConstraint twConstraint = new VehicleDependentTimeWindowConstraints(stateManager, routingCosts); HardActivityConstraint.ConstraintsStatus status = twConstraint.fulfilled(insertionContext, route.getActivities().get(2), serviceAct, route.getEnd(), 30.); assertTrue(status.equals(HardActivityConstraint.ConstraintsStatus.FULFILLED)); @@ -163,14 +163,14 @@ public class VehicleDependentTimeWindowWithStartTimeAndMaxOperationTimeTest { } @Test - public void whenNewJobIsInsertedWithOldVeh_itJustShouldReturnFalse(){ + public void whenNewJobIsInsertedWithOldVeh_itJustShouldReturnFalse() { Service s4 = Service.Builder.newInstance("s4").setLocation(Location.newInstance("1000,0")).build(); PickupService serviceAct = new PickupService(s4); - JobInsertionContext insertionContext = new JobInsertionContext(route,s4,vehicle,route.getDriver(),0.); + JobInsertionContext insertionContext = new JobInsertionContext(route, s4, vehicle, route.getDriver(), 0.); - HardActivityConstraint twConstraint = new VehicleDependentTimeWindowConstraints(stateManager,routingCosts); + HardActivityConstraint twConstraint = new VehicleDependentTimeWindowConstraints(stateManager, routingCosts); HardActivityConstraint.ConstraintsStatus status = twConstraint.fulfilled(insertionContext, route.getActivities().get(2), serviceAct, route.getEnd(), 30.); assertFalse(status.equals(HardActivityConstraint.ConstraintsStatus.FULFILLED)); @@ -178,14 +178,14 @@ public class VehicleDependentTimeWindowWithStartTimeAndMaxOperationTimeTest { } @Test - public void whenNewJobIsInsertedInBetweenAct1And2WithOldVeh_itJustShouldReturnTrue(){ + public void whenNewJobIsInsertedInBetweenAct1And2WithOldVeh_itJustShouldReturnTrue() { Service s4 = Service.Builder.newInstance("s4").setLocation(Location.newInstance("50,0")).build(); PickupService serviceAct = new PickupService(s4); - JobInsertionContext insertionContext = new JobInsertionContext(route,s4,vehicle,route.getDriver(),0.); + JobInsertionContext insertionContext = new JobInsertionContext(route, s4, vehicle, route.getDriver(), 0.); - HardActivityConstraint twConstraint = new VehicleDependentTimeWindowConstraints(stateManager,routingCosts); + HardActivityConstraint twConstraint = new VehicleDependentTimeWindowConstraints(stateManager, routingCosts); /* driverTime = 10 + 10 + 30 + 20 + 30 = 100 */ @@ -196,18 +196,18 @@ public class VehicleDependentTimeWindowWithStartTimeAndMaxOperationTimeTest { } @Test - public void whenNewJobIsInsertedInBetweenAct1And2WithOldVeh_itJustShouldReturnFalse(){ + public void whenNewJobIsInsertedInBetweenAct1And2WithOldVeh_itJustShouldReturnFalse() { Service s4 = Service.Builder.newInstance("s4").setLocation(Location.newInstance("51,0")).build(); PickupService serviceAct = new PickupService(s4); - JobInsertionContext insertionContext = new JobInsertionContext(route,s4,vehicle,route.getDriver(),0.); + JobInsertionContext insertionContext = new JobInsertionContext(route, s4, vehicle, route.getDriver(), 0.); /* driverTime = 10 + 10 + 31 + 21 + 30 = 102 */ - HardActivityConstraint twConstraint = new VehicleDependentTimeWindowConstraints(stateManager,routingCosts); + HardActivityConstraint twConstraint = new VehicleDependentTimeWindowConstraints(stateManager, routingCosts); HardActivityConstraint.ConstraintsStatus status = twConstraint.fulfilled(insertionContext, route.getActivities().get(1), serviceAct, route.getActivities().get(2), 20.); assertFalse(status.equals(HardActivityConstraint.ConstraintsStatus.FULFILLED)); @@ -215,17 +215,17 @@ public class VehicleDependentTimeWindowWithStartTimeAndMaxOperationTimeTest { } @Test - public void whenJobIsInsertedAlongWithNewVehicleThatNeedsToBeHomeAt60_itShouldReturnFalse(){ + public void whenJobIsInsertedAlongWithNewVehicleThatNeedsToBeHomeAt60_itShouldReturnFalse() { System.out.println("actualEndTime " + route.getEnd().getArrTime()); - assertEquals(60.,route.getEnd().getArrTime(),0.01); + assertEquals(60., route.getEnd().getArrTime(), 0.01); Service s4 = Service.Builder.newInstance("s4").setLocation(Location.newInstance("40,0")).build(); PickupService serviceAct = new PickupService(s4); - JobInsertionContext insertionContext = new JobInsertionContext(route,s4,v2,route.getDriver(),0.); + JobInsertionContext insertionContext = new JobInsertionContext(route, s4, v2, route.getDriver(), 0.); - HardActivityConstraint twConstraint = new VehicleDependentTimeWindowConstraints(stateManager,routingCosts); + HardActivityConstraint twConstraint = new VehicleDependentTimeWindowConstraints(stateManager, routingCosts); HardActivityConstraint.ConstraintsStatus status = twConstraint.fulfilled(insertionContext, route.getActivities().get(2), serviceAct, route.getEnd(), 30.); @@ -234,17 +234,17 @@ public class VehicleDependentTimeWindowWithStartTimeAndMaxOperationTimeTest { } @Test - public void whenJobIsInsertedAlongWithNewVehicleThatNeedsToBeHomeAt50_itShouldReturnFalse(){ + public void whenJobIsInsertedAlongWithNewVehicleThatNeedsToBeHomeAt50_itShouldReturnFalse() { System.out.println("actualEndTime " + route.getEnd().getArrTime()); - assertEquals(60.,route.getEnd().getArrTime(),0.01); + assertEquals(60., route.getEnd().getArrTime(), 0.01); Service s4 = Service.Builder.newInstance("s4").setLocation(Location.newInstance("40,0")).build(); PickupService serviceAct = new PickupService(s4); - JobInsertionContext insertionContext = new JobInsertionContext(route,s4,v3,route.getDriver(),0.); + JobInsertionContext insertionContext = new JobInsertionContext(route, s4, v3, route.getDriver(), 0.); - HardActivityConstraint twConstraint = new VehicleDependentTimeWindowConstraints(stateManager,routingCosts); + HardActivityConstraint twConstraint = new VehicleDependentTimeWindowConstraints(stateManager, routingCosts); HardActivityConstraint.ConstraintsStatus status = twConstraint.fulfilled(insertionContext, route.getActivities().get(2), serviceAct, route.getEnd(), 30.); assertFalse(status.equals(HardActivityConstraint.ConstraintsStatus.FULFILLED)); @@ -252,17 +252,17 @@ public class VehicleDependentTimeWindowWithStartTimeAndMaxOperationTimeTest { } @Test - public void whenJobIsInsertedAlongWithNewVehicleThatNeedsToBeHomeAt10_itShouldReturnFalse(){ + public void whenJobIsInsertedAlongWithNewVehicleThatNeedsToBeHomeAt10_itShouldReturnFalse() { System.out.println("actualEndTime " + route.getEnd().getArrTime()); - assertEquals(60.,route.getEnd().getArrTime(),0.01); + assertEquals(60., route.getEnd().getArrTime(), 0.01); Service s4 = Service.Builder.newInstance("s4").setLocation(Location.newInstance("40,0")).build(); PickupService serviceAct = new PickupService(s4); - JobInsertionContext insertionContext = new JobInsertionContext(route,s4,v4,route.getDriver(),0.); + JobInsertionContext insertionContext = new JobInsertionContext(route, s4, v4, route.getDriver(), 0.); - HardActivityConstraint twConstraint = new VehicleDependentTimeWindowConstraints(stateManager,routingCosts); + HardActivityConstraint twConstraint = new VehicleDependentTimeWindowConstraints(stateManager, routingCosts); HardActivityConstraint.ConstraintsStatus status = twConstraint.fulfilled(insertionContext, route.getActivities().get(2), serviceAct, route.getEnd(), 30.); assertFalse(status.equals(HardActivityConstraint.ConstraintsStatus.FULFILLED)); @@ -270,17 +270,17 @@ public class VehicleDependentTimeWindowWithStartTimeAndMaxOperationTimeTest { } @Test - public void whenJobIsInsertedAlongWithV6BetweenS2AndS3_itShouldReturnFalse(){ + public void whenJobIsInsertedAlongWithV6BetweenS2AndS3_itShouldReturnFalse() { System.out.println("actualEndTime " + route.getEnd().getArrTime()); - assertEquals(60.,route.getEnd().getArrTime(),0.01); + assertEquals(60., route.getEnd().getArrTime(), 0.01); Service s4 = Service.Builder.newInstance("s4").setLocation(Location.newInstance("40,0")).build(); PickupService serviceAct = new PickupService(s4); - JobInsertionContext insertionContext = new JobInsertionContext(route,s4,v6,route.getDriver(),0.); + JobInsertionContext insertionContext = new JobInsertionContext(route, s4, v6, route.getDriver(), 0.); - HardActivityConstraint twConstraint = new VehicleDependentTimeWindowConstraints(stateManager,routingCosts); + HardActivityConstraint twConstraint = new VehicleDependentTimeWindowConstraints(stateManager, routingCosts); HardActivityConstraint.ConstraintsStatus status = twConstraint.fulfilled(insertionContext, route.getActivities().get(1), serviceAct, route.getActivities().get(2), 30.); assertFalse(status.equals(HardActivityConstraint.ConstraintsStatus.FULFILLED)); @@ -288,17 +288,17 @@ public class VehicleDependentTimeWindowWithStartTimeAndMaxOperationTimeTest { } @Test - public void whenJobIsInsertedAlongWithV6BetweenS1AndS2_itShouldReturnFalse(){ + public void whenJobIsInsertedAlongWithV6BetweenS1AndS2_itShouldReturnFalse() { System.out.println("actualEndTime " + route.getEnd().getArrTime()); - assertEquals(60.,route.getEnd().getArrTime(),0.01); + assertEquals(60., route.getEnd().getArrTime(), 0.01); Service s4 = Service.Builder.newInstance("s4").setLocation(Location.newInstance("40,0")).build(); PickupService serviceAct = new PickupService(s4); - JobInsertionContext insertionContext = new JobInsertionContext(route,s4,v6,route.getDriver(),0.); + JobInsertionContext insertionContext = new JobInsertionContext(route, s4, v6, route.getDriver(), 0.); - HardActivityConstraint twConstraint = new VehicleDependentTimeWindowConstraints(stateManager,routingCosts); + HardActivityConstraint twConstraint = new VehicleDependentTimeWindowConstraints(stateManager, routingCosts); HardActivityConstraint.ConstraintsStatus status = twConstraint.fulfilled(insertionContext, route.getActivities().get(0), serviceAct, route.getActivities().get(1), 10.); assertFalse(status.equals(HardActivityConstraint.ConstraintsStatus.FULFILLED)); @@ -306,33 +306,33 @@ public class VehicleDependentTimeWindowWithStartTimeAndMaxOperationTimeTest { } @Test - public void whenJobIsInsertedAlongWithV6AtTheEndOfRoute_itShouldReturnTrue(){ + public void whenJobIsInsertedAlongWithV6AtTheEndOfRoute_itShouldReturnTrue() { System.out.println("actualEndTime " + route.getEnd().getArrTime()); - assertEquals(60.,route.getEnd().getArrTime(),0.01); + assertEquals(60., route.getEnd().getArrTime(), 0.01); Service s4 = Service.Builder.newInstance("s4").setLocation(Location.newInstance("40,0")).build(); PickupService serviceAct = new PickupService(s4); - JobInsertionContext insertionContext = new JobInsertionContext(route,s4,v6,route.getDriver(),0.); + JobInsertionContext insertionContext = new JobInsertionContext(route, s4, v6, route.getDriver(), 0.); - HardActivityConstraint twConstraint = new VehicleDependentTimeWindowConstraints(stateManager,routingCosts); + HardActivityConstraint twConstraint = new VehicleDependentTimeWindowConstraints(stateManager, routingCosts); HardActivityConstraint.ConstraintsStatus status = twConstraint.fulfilled(insertionContext, route.getActivities().get(2), serviceAct, route.getEnd(), 30.); assertTrue(status.equals(HardActivityConstraint.ConstraintsStatus.FULFILLED)); } @Test - public void whenJobIsInsertedAlongWithNewVehicleThatCanOnlyStartAt60_itShouldReturnFalse(){ + public void whenJobIsInsertedAlongWithNewVehicleThatCanOnlyStartAt60_itShouldReturnFalse() { System.out.println("actualEndTime " + route.getEnd().getArrTime()); - assertEquals(60.,route.getEnd().getArrTime(),0.01); + assertEquals(60., route.getEnd().getArrTime(), 0.01); Service s4 = Service.Builder.newInstance("s4").setLocation(Location.newInstance("40,0")).build(); PickupService serviceAct = new PickupService(s4); - JobInsertionContext insertionContext = new JobInsertionContext(route,s4,v5,route.getDriver(),60.); + JobInsertionContext insertionContext = new JobInsertionContext(route, s4, v5, route.getDriver(), 60.); - HardActivityConstraint twConstraint = new VehicleDependentTimeWindowConstraints(stateManager,routingCosts); + HardActivityConstraint twConstraint = new VehicleDependentTimeWindowConstraints(stateManager, routingCosts); HardActivityConstraint.ConstraintsStatus status = twConstraint.fulfilled(insertionContext, route.getActivities().get(2), serviceAct, route.getEnd(), 90.); assertFalse(status.equals(HardActivityConstraint.ConstraintsStatus.FULFILLED)); diff --git a/jsprit-core/src/test/java/jsprit/core/problem/io/VrpXMLReaderTest.java b/jsprit-core/src/test/java/jsprit/core/problem/io/VrpXMLReaderTest.java index f471d0a5..73d5d3e3 100644 --- a/jsprit-core/src/test/java/jsprit/core/problem/io/VrpXMLReaderTest.java +++ b/jsprit-core/src/test/java/jsprit/core/problem/io/VrpXMLReaderTest.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.problem.io; @@ -40,16 +40,16 @@ import static org.junit.Assert.*; public class VrpXMLReaderTest { - - private String inFileName; - - @Before - public void doBefore(){ - inFileName = "src/test/resources/finiteVrpForReaderTest.xml"; - } + + private String inFileName; + + @Before + public void doBefore() { + inFileName = "src/test/resources/finiteVrpForReaderTest.xml"; + } @Test - public void shouldReadNameOfService(){ + public void shouldReadNameOfService() { VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); new VrpXMLReader(builder, null).read(inFileName); VehicleRoutingProblem vrp = builder.build(); @@ -58,7 +58,7 @@ public class VrpXMLReaderTest { } @Test - public void shouldReadNameOfShipment(){ + public void shouldReadNameOfShipment() { VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); new VrpXMLReader(builder, null).read(inFileName); VehicleRoutingProblem vrp = builder.build(); @@ -66,127 +66,127 @@ public class VrpXMLReaderTest { assertTrue(s.getName().equals("deliver-smth")); } - @Test - public void whenReadingVrp_problemTypeIsReadCorrectly(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - assertEquals(FleetSize.FINITE,vrp.getFleetSize()); - } - - @Test - public void whenReadingVrp_vehiclesAreReadCorrectly(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - assertEquals(5,vrp.getVehicles().size()); - assertTrue(idsInCollection(Arrays.asList("v1","v2"),vrp.getVehicles())); - } - - @Test - public void whenReadingVrp_vehiclesAreReadCorrectly2(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Vehicle v1 = getVehicle("v1",vrp.getVehicles()); - assertEquals(20,v1.getType().getCapacityDimensions().get(0)); - assertEquals(100.0,v1.getStartLocation().getCoordinate().getX(),0.01); - assertEquals(0.0,v1.getEarliestDeparture(),0.01); - assertEquals("depotLoc2",v1.getStartLocation().getId()); - assertNotNull(v1.getType()); - assertEquals("vehType", v1.getType().getTypeId()); - assertNotNull(v1.getStartLocation()); - assertEquals(1,v1.getStartLocation().getIndex()); - assertEquals(1000.0,v1.getLatestArrival(),0.01); - } - @Test - public void whenReadingVehicles_skill1ShouldBeAssigned(){ + public void whenReadingVrp_problemTypeIsReadCorrectly() { VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); new VrpXMLReader(builder, null).read(inFileName); VehicleRoutingProblem vrp = builder.build(); - Vehicle v1 = getVehicle("v1",vrp.getVehicles()); + assertEquals(FleetSize.FINITE, vrp.getFleetSize()); + } + + @Test + public void whenReadingVrp_vehiclesAreReadCorrectly() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(builder, null).read(inFileName); + VehicleRoutingProblem vrp = builder.build(); + assertEquals(5, vrp.getVehicles().size()); + assertTrue(idsInCollection(Arrays.asList("v1", "v2"), vrp.getVehicles())); + } + + @Test + public void whenReadingVrp_vehiclesAreReadCorrectly2() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(builder, null).read(inFileName); + VehicleRoutingProblem vrp = builder.build(); + Vehicle v1 = getVehicle("v1", vrp.getVehicles()); + assertEquals(20, v1.getType().getCapacityDimensions().get(0)); + assertEquals(100.0, v1.getStartLocation().getCoordinate().getX(), 0.01); + assertEquals(0.0, v1.getEarliestDeparture(), 0.01); + assertEquals("depotLoc2", v1.getStartLocation().getId()); + assertNotNull(v1.getType()); + assertEquals("vehType", v1.getType().getTypeId()); + assertNotNull(v1.getStartLocation()); + assertEquals(1, v1.getStartLocation().getIndex()); + assertEquals(1000.0, v1.getLatestArrival(), 0.01); + } + + @Test + public void whenReadingVehicles_skill1ShouldBeAssigned() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(builder, null).read(inFileName); + VehicleRoutingProblem vrp = builder.build(); + Vehicle v1 = getVehicle("v1", vrp.getVehicles()); assertTrue(v1.getSkills().containsSkill("skill1")); } @Test - public void whenReadingVehicles_skill2ShouldBeAssigned(){ + public void whenReadingVehicles_skill2ShouldBeAssigned() { VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); new VrpXMLReader(builder, null).read(inFileName); VehicleRoutingProblem vrp = builder.build(); - Vehicle v1 = getVehicle("v1",vrp.getVehicles()); + Vehicle v1 = getVehicle("v1", vrp.getVehicles()); assertTrue(v1.getSkills().containsSkill("skill2")); } @Test - public void whenReadingVehicles_nuSkillsShouldBeCorrect(){ + public void whenReadingVehicles_nuSkillsShouldBeCorrect() { VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); new VrpXMLReader(builder, null).read(inFileName); VehicleRoutingProblem vrp = builder.build(); - Vehicle v1 = getVehicle("v1",vrp.getVehicles()); + Vehicle v1 = getVehicle("v1", vrp.getVehicles()); assertEquals(2, v1.getSkills().values().size()); } @Test - public void whenReadingVehicles_nuSkillsOfV2ShouldBeCorrect(){ + public void whenReadingVehicles_nuSkillsOfV2ShouldBeCorrect() { VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); new VrpXMLReader(builder, null).read(inFileName); VehicleRoutingProblem vrp = builder.build(); - Vehicle v = getVehicle("v2",vrp.getVehicles()); + Vehicle v = getVehicle("v2", vrp.getVehicles()); assertEquals(0, v.getSkills().values().size()); } - - private Vehicle getVehicle(String string, Collection vehicles) { - for(Vehicle v : vehicles) if(string.equals(v.getId())) return v; - return null; - } - private boolean idsInCollection(List asList, Collection vehicles) { - List ids = new ArrayList(asList); - for(Vehicle v : vehicles){ - if(ids.contains(v.getId())) ids.remove(v.getId()); - } - return ids.isEmpty(); - } + private Vehicle getVehicle(String string, Collection vehicles) { + for (Vehicle v : vehicles) if (string.equals(v.getId())) return v; + return null; + } - @Test - public void whenReadingVrp_vehicleTypesAreReadCorrectly(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - assertEquals(3,vrp.getTypes().size()); - } - - @Test - public void whenReadingVrpWithInfiniteSize_itReadsCorrectly(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - assertEquals(FleetSize.FINITE,vrp.getFleetSize()); - } - - @Test - public void whenReadingJobs_nuOfJobsIsReadThemCorrectly(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - assertEquals(4, vrp.getJobs().size()); - } - - @Test - public void whenReadingServices_itReadsThemCorrectly(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - int servCounter = 0; - for(Job j : vrp.getJobs().values()){ - if(j instanceof Service) servCounter++; - } - assertEquals(2,servCounter); - } + private boolean idsInCollection(List asList, Collection vehicles) { + List ids = new ArrayList(asList); + for (Vehicle v : vehicles) { + if (ids.contains(v.getId())) ids.remove(v.getId()); + } + return ids.isEmpty(); + } @Test - public void whenReadingService1_skill1ShouldBeAssigned(){ + public void whenReadingVrp_vehicleTypesAreReadCorrectly() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(builder, null).read(inFileName); + VehicleRoutingProblem vrp = builder.build(); + assertEquals(3, vrp.getTypes().size()); + } + + @Test + public void whenReadingVrpWithInfiniteSize_itReadsCorrectly() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(builder, null).read(inFileName); + VehicleRoutingProblem vrp = builder.build(); + assertEquals(FleetSize.FINITE, vrp.getFleetSize()); + } + + @Test + public void whenReadingJobs_nuOfJobsIsReadThemCorrectly() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(builder, null).read(inFileName); + VehicleRoutingProblem vrp = builder.build(); + assertEquals(4, vrp.getJobs().size()); + } + + @Test + public void whenReadingServices_itReadsThemCorrectly() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(builder, null).read(inFileName); + VehicleRoutingProblem vrp = builder.build(); + int servCounter = 0; + for (Job j : vrp.getJobs().values()) { + if (j instanceof Service) servCounter++; + } + assertEquals(2, servCounter); + } + + @Test + public void whenReadingService1_skill1ShouldBeAssigned() { VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); new VrpXMLReader(builder, null).read(inFileName); VehicleRoutingProblem vrp = builder.build(); @@ -195,7 +195,7 @@ public class VrpXMLReaderTest { } @Test - public void whenReadingService1_skill2ShouldBeAssigned(){ + public void whenReadingService1_skill2ShouldBeAssigned() { VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); new VrpXMLReader(builder, null).read(inFileName); VehicleRoutingProblem vrp = builder.build(); @@ -204,37 +204,37 @@ public class VrpXMLReaderTest { } @Test - public void whenReadingService1_nuSkillsShouldBeCorrect(){ + public void whenReadingService1_nuSkillsShouldBeCorrect() { VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); new VrpXMLReader(builder, null).read(inFileName); VehicleRoutingProblem vrp = builder.build(); Service s = (Service) vrp.getJobs().get("1"); - assertEquals(2,s.getRequiredSkills().values().size()); + assertEquals(2, s.getRequiredSkills().values().size()); } @Test - public void whenReadingService2_nuSkillsOfV2ShouldBeCorrect(){ + public void whenReadingService2_nuSkillsOfV2ShouldBeCorrect() { VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); new VrpXMLReader(builder, null).read(inFileName); VehicleRoutingProblem vrp = builder.build(); Service s = (Service) vrp.getJobs().get("2"); - assertEquals(0,s.getRequiredSkills().values().size()); + assertEquals(0, s.getRequiredSkills().values().size()); } - - @Test - public void whenReadingShipments_itReadsThemCorrectly(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - int shipCounter = 0; - for(Job j : vrp.getJobs().values()){ - if(j instanceof Shipment) shipCounter++; - } - assertEquals(2,shipCounter); - } @Test - public void whenReadingShipment3_skill1ShouldBeAssigned(){ + public void whenReadingShipments_itReadsThemCorrectly() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(builder, null).read(inFileName); + VehicleRoutingProblem vrp = builder.build(); + int shipCounter = 0; + for (Job j : vrp.getJobs().values()) { + if (j instanceof Shipment) shipCounter++; + } + assertEquals(2, shipCounter); + } + + @Test + public void whenReadingShipment3_skill1ShouldBeAssigned() { VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); new VrpXMLReader(builder, null).read(inFileName); VehicleRoutingProblem vrp = builder.build(); @@ -243,7 +243,7 @@ public class VrpXMLReaderTest { } @Test - public void whenReadingShipment3_skill2ShouldBeAssigned(){ + public void whenReadingShipment3_skill2ShouldBeAssigned() { VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); new VrpXMLReader(builder, null).read(inFileName); VehicleRoutingProblem vrp = builder.build(); @@ -252,364 +252,364 @@ public class VrpXMLReaderTest { } @Test - public void whenReadingShipment3_nuSkillsShouldBeCorrect(){ + public void whenReadingShipment3_nuSkillsShouldBeCorrect() { VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); new VrpXMLReader(builder, null).read(inFileName); VehicleRoutingProblem vrp = builder.build(); Shipment s = (Shipment) vrp.getJobs().get("3"); - assertEquals(2,s.getRequiredSkills().values().size()); + assertEquals(2, s.getRequiredSkills().values().size()); } @Test - public void whenReadingShipment4_nuSkillsOfV2ShouldBeCorrect(){ + public void whenReadingShipment4_nuSkillsOfV2ShouldBeCorrect() { VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); new VrpXMLReader(builder, null).read(inFileName); VehicleRoutingProblem vrp = builder.build(); Shipment s = (Shipment) vrp.getJobs().get("4"); - assertEquals(0,s.getRequiredSkills().values().size()); + assertEquals(0, s.getRequiredSkills().values().size()); } - - @Test - public void whenReadingServices_capOfService1IsReadCorrectly(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Service s1 = (Service) vrp.getJobs().get("1"); - assertEquals(1,s1.getSize().get(0)); - } - - @Test - public void whenReadingServices_durationOfService1IsReadCorrectly(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Service s1 = (Service) vrp.getJobs().get("1"); - assertEquals(10.0,s1.getServiceDuration(),0.01); - } - - @Test - public void whenReadingServices_twOfService1IsReadCorrectly(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Service s1 = (Service) vrp.getJobs().get("1"); - assertEquals(0.0,s1.getTimeWindow().getStart(),0.01); - assertEquals(4000.0,s1.getTimeWindow().getEnd(),0.01); - } - - @Test - public void whenReadingServices_typeOfService1IsReadCorrectly(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Service s1 = (Service) vrp.getJobs().get("1"); - assertEquals("service",s1.getType()); - } - - @Test - public void whenReadingFile_v2MustNotReturnToDepot(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Vehicle v = getVehicle("v2",vrp.getVehicles()); - assertFalse(v.isReturnToDepot()); - } - - @Test - public void whenReadingFile_v3HasTheCorrectStartLocation(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Vehicle v3 = getVehicle("v3",vrp.getVehicles()); - assertEquals("startLoc",v3.getStartLocation().getId()); - assertNotNull(v3.getEndLocation()); - assertEquals(4,v3.getEndLocation().getIndex()); - } - - @Test - public void whenReadingFile_v3HasTheCorrectEndLocation(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Vehicle v3 = getVehicle("v3",vrp.getVehicles()); - assertEquals("endLoc",v3.getEndLocation().getId()); - } - - @Test - public void whenReadingFile_v3HasTheCorrectEndLocationCoordinate(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Vehicle v3 = getVehicle("v3",vrp.getVehicles()); - assertEquals(1000.0,v3.getEndLocation().getCoordinate().getX(),0.01); - assertEquals(2000.0,v3.getEndLocation().getCoordinate().getY(),0.01); - } - - @Test - public void whenReadingFile_v3HasTheCorrectStartLocationCoordinate(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Vehicle v3 = getVehicle("v3",vrp.getVehicles()); - assertEquals(10.0,v3.getStartLocation().getCoordinate().getX(),0.01); - assertEquals(100.0,v3.getStartLocation().getCoordinate().getY(),0.01); - } - - @Test - public void whenReadingFile_v3HasTheCorrectLocationCoordinate(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Vehicle v3 = getVehicle("v3",vrp.getVehicles()); - assertEquals(10.0,v3.getStartLocation().getCoordinate().getX(),0.01); - assertEquals(100.0,v3.getStartLocation().getCoordinate().getY(),0.01); - } - - @Test - public void whenReadingFile_v3HasTheCorrectLocationId(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Vehicle v3 = getVehicle("v3",vrp.getVehicles()); - assertEquals("startLoc",v3.getStartLocation().getId()); - } - - @Test - public void whenReadingFile_v4HasTheCorrectStartLocation(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Vehicle v = getVehicle("v4",vrp.getVehicles()); - assertEquals("startLoc",v.getStartLocation().getId()); - } - - @Test - public void whenReadingFile_v4HasTheCorrectEndLocation(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Vehicle v = getVehicle("v4",vrp.getVehicles()); - assertEquals("endLoc",v.getEndLocation().getId()); - } - - @Test - public void whenReadingFile_v4HasTheCorrectEndLocationCoordinate(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Vehicle v = getVehicle("v4",vrp.getVehicles()); - assertEquals(1000.0,v.getEndLocation().getCoordinate().getX(),0.01); - assertEquals(2000.0,v.getEndLocation().getCoordinate().getY(),0.01); - } - - @Test - public void whenReadingFile_v4HasTheCorrectStartLocationCoordinate(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Vehicle v = getVehicle("v4",vrp.getVehicles()); - assertEquals(10.0,v.getStartLocation().getCoordinate().getX(),0.01); - assertEquals(100.0,v.getStartLocation().getCoordinate().getY(),0.01); - } - - @Test - public void whenReadingFile_v4HasTheCorrectLocationCoordinate(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Vehicle v = getVehicle("v4",vrp.getVehicles()); - assertEquals(10.0,v.getStartLocation().getCoordinate().getX(),0.01); - assertEquals(100.0,v.getStartLocation().getCoordinate().getY(),0.01); - } - - @Test - public void whenReadingFile_v4HasTheCorrectLocationId(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Vehicle v = getVehicle("v4",vrp.getVehicles()); - assertEquals("startLoc",v.getStartLocation().getId()); - } - - @Test - public void whenReadingJobs_capOfShipment3IsReadCorrectly(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Shipment s = (Shipment) vrp.getJobs().get("3"); - assertEquals(10,s.getSize().get(0)); - } - - @Test - public void whenReadingJobs_pickupServiceTimeOfShipment3IsReadCorrectly(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Shipment s = (Shipment) vrp.getJobs().get("3"); - assertEquals(10.0,s.getPickupServiceTime(),0.01); - } - - @Test - public void whenReadingJobs_pickupTimeWindowOfShipment3IsReadCorrectly(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Shipment s = (Shipment) vrp.getJobs().get("3"); - assertEquals(1000.0,s.getPickupTimeWindow().getStart(),0.01); - assertEquals(4000.0,s.getPickupTimeWindow().getEnd(),0.01); - } - - @Test - public void whenReadingJobs_deliveryTimeWindowOfShipment3IsReadCorrectly(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Shipment s = (Shipment) vrp.getJobs().get("3"); - assertEquals(6000.0,s.getDeliveryTimeWindow().getStart(),0.01); - assertEquals(10000.0,s.getDeliveryTimeWindow().getEnd(),0.01); - } - - @Test - public void whenReadingJobs_deliveryServiceTimeOfShipment3IsReadCorrectly(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Shipment s = (Shipment) vrp.getJobs().get("3"); - assertEquals(100.0,s.getDeliveryServiceTime(),0.01); - } - - @Test - public void whenReadingJobs_deliveryCoordShipment3IsReadCorrectly(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Shipment s = (Shipment) vrp.getJobs().get("3"); - assertEquals(10.0,s.getDeliveryLocation().getCoordinate().getX(),0.01); - assertEquals(0.0,s.getDeliveryLocation().getCoordinate().getY(),0.01); - } - - @Test - public void whenReadingJobs_pickupCoordShipment3IsReadCorrectly(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Shipment s = (Shipment) vrp.getJobs().get("3"); - assertEquals(10.0,s.getPickupLocation().getCoordinate().getX(),0.01); - assertEquals(10.0,s.getPickupLocation().getCoordinate().getY(),0.01); - } - - @Test - public void whenReadingJobs_deliveryIdShipment3IsReadCorrectly(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Shipment s = (Shipment) vrp.getJobs().get("3"); - assertEquals("i(9,9)",s.getDeliveryLocation().getId()); - } - - @Test - public void whenReadingJobs_pickupIdShipment3IsReadCorrectly(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Shipment s = (Shipment) vrp.getJobs().get("3"); - assertEquals("i(3,9)",s.getPickupLocation().getId()); - } - - @Test - public void whenReadingJobs_pickupLocationIdShipment4IsReadCorrectly(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Shipment s = (Shipment) vrp.getJobs().get("4"); - assertEquals("[x=10.0][y=10.0]",s.getPickupLocation().getId()); - } - - @Test - public void whenReadingJobs_deliveryLocationIdShipment4IsReadCorrectly(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Shipment s = (Shipment) vrp.getJobs().get("4"); - assertEquals("[x=10.0][y=0.0]",s.getDeliveryLocation().getId()); - } - - @Test - public void whenReadingJobs_pickupServiceTimeOfShipment4IsReadCorrectly(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Shipment s = (Shipment) vrp.getJobs().get("4"); - assertEquals(0.0,s.getPickupServiceTime(),0.01); - } - - @Test - public void whenReadingJobs_deliveryServiceTimeOfShipment4IsReadCorrectly(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Shipment s = (Shipment) vrp.getJobs().get("4"); - assertEquals(100.0,s.getDeliveryServiceTime(),0.01); - } - - @Test - public void whenReadingFile_v5AndItsTypeHasTheCorrectCapacityDimensionValues(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Vehicle v = getVehicle("v5",vrp.getVehicles()); - assertEquals(100, v.getType().getCapacityDimensions().get(0)); - assertEquals(1000, v.getType().getCapacityDimensions().get(1)); - assertEquals(10000, v.getType().getCapacityDimensions().get(2)); - assertEquals(0, v.getType().getCapacityDimensions().get(3)); - assertEquals(0, v.getType().getCapacityDimensions().get(5)); - assertEquals(100000, v.getType().getCapacityDimensions().get(10)); - } - - @Test - public void whenReadingInitialRouteWithShipment4_thisShipmentShouldNotAppearInJobMap(){ //since it is not part of the problem anymore - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder).read("src/test/resources/finiteVrpWithInitialSolutionForReaderTest.xml"); - VehicleRoutingProblem vrp = builder.build(); - assertFalse(vrp.getJobs().containsKey("4")); - } - - @Test - public void whenReadingInitialRouteWithDepTime10_departureTimeOfRouteShouldBeReadCorrectly(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder).read("src/test/resources/finiteVrpWithInitialSolutionForReaderTest.xml"); - VehicleRoutingProblem vrp = builder.build(); - assertEquals(10.,vrp.getInitialVehicleRoutes().iterator().next().getDepartureTime(),0.01); - } - - @Test - public void whenReadingInitialRoute_nuInitialRoutesShouldBeCorrect(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read("src/test/resources/finiteVrpWithInitialSolutionForReaderTest.xml"); - VehicleRoutingProblem vrp = builder.build(); - assertEquals(1,vrp.getInitialVehicleRoutes().size()); - } - - @Test - public void whenReadingInitialRoute_nuActivitiesShouldBeCorrect(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read("src/test/resources/finiteVrpWithInitialSolutionForReaderTest.xml"); - VehicleRoutingProblem vrp = builder.build(); - assertEquals(2,vrp.getInitialVehicleRoutes().iterator().next().getActivities().size()); - } @Test - public void testRead_ifReaderIsCalled_itReadsSuccessfullyV2(){ + public void whenReadingServices_capOfService1IsReadCorrectly() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(builder, null).read(inFileName); + VehicleRoutingProblem vrp = builder.build(); + Service s1 = (Service) vrp.getJobs().get("1"); + assertEquals(1, s1.getSize().get(0)); + } + + @Test + public void whenReadingServices_durationOfService1IsReadCorrectly() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(builder, null).read(inFileName); + VehicleRoutingProblem vrp = builder.build(); + Service s1 = (Service) vrp.getJobs().get("1"); + assertEquals(10.0, s1.getServiceDuration(), 0.01); + } + + @Test + public void whenReadingServices_twOfService1IsReadCorrectly() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(builder, null).read(inFileName); + VehicleRoutingProblem vrp = builder.build(); + Service s1 = (Service) vrp.getJobs().get("1"); + assertEquals(0.0, s1.getTimeWindow().getStart(), 0.01); + assertEquals(4000.0, s1.getTimeWindow().getEnd(), 0.01); + } + + @Test + public void whenReadingServices_typeOfService1IsReadCorrectly() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(builder, null).read(inFileName); + VehicleRoutingProblem vrp = builder.build(); + Service s1 = (Service) vrp.getJobs().get("1"); + assertEquals("service", s1.getType()); + } + + @Test + public void whenReadingFile_v2MustNotReturnToDepot() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(builder, null).read(inFileName); + VehicleRoutingProblem vrp = builder.build(); + Vehicle v = getVehicle("v2", vrp.getVehicles()); + assertFalse(v.isReturnToDepot()); + } + + @Test + public void whenReadingFile_v3HasTheCorrectStartLocation() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(builder, null).read(inFileName); + VehicleRoutingProblem vrp = builder.build(); + Vehicle v3 = getVehicle("v3", vrp.getVehicles()); + assertEquals("startLoc", v3.getStartLocation().getId()); + assertNotNull(v3.getEndLocation()); + assertEquals(4, v3.getEndLocation().getIndex()); + } + + @Test + public void whenReadingFile_v3HasTheCorrectEndLocation() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(builder, null).read(inFileName); + VehicleRoutingProblem vrp = builder.build(); + Vehicle v3 = getVehicle("v3", vrp.getVehicles()); + assertEquals("endLoc", v3.getEndLocation().getId()); + } + + @Test + public void whenReadingFile_v3HasTheCorrectEndLocationCoordinate() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(builder, null).read(inFileName); + VehicleRoutingProblem vrp = builder.build(); + Vehicle v3 = getVehicle("v3", vrp.getVehicles()); + assertEquals(1000.0, v3.getEndLocation().getCoordinate().getX(), 0.01); + assertEquals(2000.0, v3.getEndLocation().getCoordinate().getY(), 0.01); + } + + @Test + public void whenReadingFile_v3HasTheCorrectStartLocationCoordinate() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(builder, null).read(inFileName); + VehicleRoutingProblem vrp = builder.build(); + Vehicle v3 = getVehicle("v3", vrp.getVehicles()); + assertEquals(10.0, v3.getStartLocation().getCoordinate().getX(), 0.01); + assertEquals(100.0, v3.getStartLocation().getCoordinate().getY(), 0.01); + } + + @Test + public void whenReadingFile_v3HasTheCorrectLocationCoordinate() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(builder, null).read(inFileName); + VehicleRoutingProblem vrp = builder.build(); + Vehicle v3 = getVehicle("v3", vrp.getVehicles()); + assertEquals(10.0, v3.getStartLocation().getCoordinate().getX(), 0.01); + assertEquals(100.0, v3.getStartLocation().getCoordinate().getY(), 0.01); + } + + @Test + public void whenReadingFile_v3HasTheCorrectLocationId() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(builder, null).read(inFileName); + VehicleRoutingProblem vrp = builder.build(); + Vehicle v3 = getVehicle("v3", vrp.getVehicles()); + assertEquals("startLoc", v3.getStartLocation().getId()); + } + + @Test + public void whenReadingFile_v4HasTheCorrectStartLocation() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(builder, null).read(inFileName); + VehicleRoutingProblem vrp = builder.build(); + Vehicle v = getVehicle("v4", vrp.getVehicles()); + assertEquals("startLoc", v.getStartLocation().getId()); + } + + @Test + public void whenReadingFile_v4HasTheCorrectEndLocation() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(builder, null).read(inFileName); + VehicleRoutingProblem vrp = builder.build(); + Vehicle v = getVehicle("v4", vrp.getVehicles()); + assertEquals("endLoc", v.getEndLocation().getId()); + } + + @Test + public void whenReadingFile_v4HasTheCorrectEndLocationCoordinate() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(builder, null).read(inFileName); + VehicleRoutingProblem vrp = builder.build(); + Vehicle v = getVehicle("v4", vrp.getVehicles()); + assertEquals(1000.0, v.getEndLocation().getCoordinate().getX(), 0.01); + assertEquals(2000.0, v.getEndLocation().getCoordinate().getY(), 0.01); + } + + @Test + public void whenReadingFile_v4HasTheCorrectStartLocationCoordinate() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(builder, null).read(inFileName); + VehicleRoutingProblem vrp = builder.build(); + Vehicle v = getVehicle("v4", vrp.getVehicles()); + assertEquals(10.0, v.getStartLocation().getCoordinate().getX(), 0.01); + assertEquals(100.0, v.getStartLocation().getCoordinate().getY(), 0.01); + } + + @Test + public void whenReadingFile_v4HasTheCorrectLocationCoordinate() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(builder, null).read(inFileName); + VehicleRoutingProblem vrp = builder.build(); + Vehicle v = getVehicle("v4", vrp.getVehicles()); + assertEquals(10.0, v.getStartLocation().getCoordinate().getX(), 0.01); + assertEquals(100.0, v.getStartLocation().getCoordinate().getY(), 0.01); + } + + @Test + public void whenReadingFile_v4HasTheCorrectLocationId() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(builder, null).read(inFileName); + VehicleRoutingProblem vrp = builder.build(); + Vehicle v = getVehicle("v4", vrp.getVehicles()); + assertEquals("startLoc", v.getStartLocation().getId()); + } + + @Test + public void whenReadingJobs_capOfShipment3IsReadCorrectly() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(builder, null).read(inFileName); + VehicleRoutingProblem vrp = builder.build(); + Shipment s = (Shipment) vrp.getJobs().get("3"); + assertEquals(10, s.getSize().get(0)); + } + + @Test + public void whenReadingJobs_pickupServiceTimeOfShipment3IsReadCorrectly() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(builder, null).read(inFileName); + VehicleRoutingProblem vrp = builder.build(); + Shipment s = (Shipment) vrp.getJobs().get("3"); + assertEquals(10.0, s.getPickupServiceTime(), 0.01); + } + + @Test + public void whenReadingJobs_pickupTimeWindowOfShipment3IsReadCorrectly() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(builder, null).read(inFileName); + VehicleRoutingProblem vrp = builder.build(); + Shipment s = (Shipment) vrp.getJobs().get("3"); + assertEquals(1000.0, s.getPickupTimeWindow().getStart(), 0.01); + assertEquals(4000.0, s.getPickupTimeWindow().getEnd(), 0.01); + } + + @Test + public void whenReadingJobs_deliveryTimeWindowOfShipment3IsReadCorrectly() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(builder, null).read(inFileName); + VehicleRoutingProblem vrp = builder.build(); + Shipment s = (Shipment) vrp.getJobs().get("3"); + assertEquals(6000.0, s.getDeliveryTimeWindow().getStart(), 0.01); + assertEquals(10000.0, s.getDeliveryTimeWindow().getEnd(), 0.01); + } + + @Test + public void whenReadingJobs_deliveryServiceTimeOfShipment3IsReadCorrectly() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(builder, null).read(inFileName); + VehicleRoutingProblem vrp = builder.build(); + Shipment s = (Shipment) vrp.getJobs().get("3"); + assertEquals(100.0, s.getDeliveryServiceTime(), 0.01); + } + + @Test + public void whenReadingJobs_deliveryCoordShipment3IsReadCorrectly() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(builder, null).read(inFileName); + VehicleRoutingProblem vrp = builder.build(); + Shipment s = (Shipment) vrp.getJobs().get("3"); + assertEquals(10.0, s.getDeliveryLocation().getCoordinate().getX(), 0.01); + assertEquals(0.0, s.getDeliveryLocation().getCoordinate().getY(), 0.01); + } + + @Test + public void whenReadingJobs_pickupCoordShipment3IsReadCorrectly() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(builder, null).read(inFileName); + VehicleRoutingProblem vrp = builder.build(); + Shipment s = (Shipment) vrp.getJobs().get("3"); + assertEquals(10.0, s.getPickupLocation().getCoordinate().getX(), 0.01); + assertEquals(10.0, s.getPickupLocation().getCoordinate().getY(), 0.01); + } + + @Test + public void whenReadingJobs_deliveryIdShipment3IsReadCorrectly() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(builder, null).read(inFileName); + VehicleRoutingProblem vrp = builder.build(); + Shipment s = (Shipment) vrp.getJobs().get("3"); + assertEquals("i(9,9)", s.getDeliveryLocation().getId()); + } + + @Test + public void whenReadingJobs_pickupIdShipment3IsReadCorrectly() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(builder, null).read(inFileName); + VehicleRoutingProblem vrp = builder.build(); + Shipment s = (Shipment) vrp.getJobs().get("3"); + assertEquals("i(3,9)", s.getPickupLocation().getId()); + } + + @Test + public void whenReadingJobs_pickupLocationIdShipment4IsReadCorrectly() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(builder, null).read(inFileName); + VehicleRoutingProblem vrp = builder.build(); + Shipment s = (Shipment) vrp.getJobs().get("4"); + assertEquals("[x=10.0][y=10.0]", s.getPickupLocation().getId()); + } + + @Test + public void whenReadingJobs_deliveryLocationIdShipment4IsReadCorrectly() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(builder, null).read(inFileName); + VehicleRoutingProblem vrp = builder.build(); + Shipment s = (Shipment) vrp.getJobs().get("4"); + assertEquals("[x=10.0][y=0.0]", s.getDeliveryLocation().getId()); + } + + @Test + public void whenReadingJobs_pickupServiceTimeOfShipment4IsReadCorrectly() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(builder, null).read(inFileName); + VehicleRoutingProblem vrp = builder.build(); + Shipment s = (Shipment) vrp.getJobs().get("4"); + assertEquals(0.0, s.getPickupServiceTime(), 0.01); + } + + @Test + public void whenReadingJobs_deliveryServiceTimeOfShipment4IsReadCorrectly() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(builder, null).read(inFileName); + VehicleRoutingProblem vrp = builder.build(); + Shipment s = (Shipment) vrp.getJobs().get("4"); + assertEquals(100.0, s.getDeliveryServiceTime(), 0.01); + } + + @Test + public void whenReadingFile_v5AndItsTypeHasTheCorrectCapacityDimensionValues() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(builder, null).read(inFileName); + VehicleRoutingProblem vrp = builder.build(); + Vehicle v = getVehicle("v5", vrp.getVehicles()); + assertEquals(100, v.getType().getCapacityDimensions().get(0)); + assertEquals(1000, v.getType().getCapacityDimensions().get(1)); + assertEquals(10000, v.getType().getCapacityDimensions().get(2)); + assertEquals(0, v.getType().getCapacityDimensions().get(3)); + assertEquals(0, v.getType().getCapacityDimensions().get(5)); + assertEquals(100000, v.getType().getCapacityDimensions().get(10)); + } + + @Test + public void whenReadingInitialRouteWithShipment4_thisShipmentShouldNotAppearInJobMap() { //since it is not part of the problem anymore + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(builder).read("src/test/resources/finiteVrpWithInitialSolutionForReaderTest.xml"); + VehicleRoutingProblem vrp = builder.build(); + assertFalse(vrp.getJobs().containsKey("4")); + } + + @Test + public void whenReadingInitialRouteWithDepTime10_departureTimeOfRouteShouldBeReadCorrectly() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(builder).read("src/test/resources/finiteVrpWithInitialSolutionForReaderTest.xml"); + VehicleRoutingProblem vrp = builder.build(); + assertEquals(10., vrp.getInitialVehicleRoutes().iterator().next().getDepartureTime(), 0.01); + } + + @Test + public void whenReadingInitialRoute_nuInitialRoutesShouldBeCorrect() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(builder, null).read("src/test/resources/finiteVrpWithInitialSolutionForReaderTest.xml"); + VehicleRoutingProblem vrp = builder.build(); + assertEquals(1, vrp.getInitialVehicleRoutes().size()); + } + + @Test + public void whenReadingInitialRoute_nuActivitiesShouldBeCorrect() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(builder, null).read("src/test/resources/finiteVrpWithInitialSolutionForReaderTest.xml"); + VehicleRoutingProblem vrp = builder.build(); + assertEquals(2, vrp.getInitialVehicleRoutes().iterator().next().getActivities().size()); + } + + @Test + public void testRead_ifReaderIsCalled_itReadsSuccessfullyV2() { VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); ArrayList solutions = new ArrayList(); new VrpXMLReader(vrpBuilder, solutions).read("src/test/resources/finiteVrpWithShipmentsAndSolution.xml"); VehicleRoutingProblem vrp = vrpBuilder.build(); - assertEquals(4,vrp.getJobs().size()); - assertEquals(1,solutions.size()); + assertEquals(4, vrp.getJobs().size()); + assertEquals(1, solutions.size()); - assertEquals(1,solutions.get(0).getRoutes().size()); + assertEquals(1, solutions.get(0).getRoutes().size()); List activities = solutions.get(0).getRoutes().iterator().next().getTourActivities().getActivities(); - assertEquals(4,activities.size()); + assertEquals(4, activities.size()); assertTrue(activities.get(0) instanceof PickupService); assertTrue(activities.get(1) instanceof PickupService); assertTrue(activities.get(2) instanceof PickupShipment); @@ -617,21 +617,21 @@ public class VrpXMLReaderTest { } @Test - public void testRead_ifReaderIsCalled_itReadsSuccessfully(){ + public void testRead_ifReaderIsCalled_itReadsSuccessfully() { new VrpXMLReader(VehicleRoutingProblem.Builder.newInstance(), new ArrayList()).read("src/test/resources/lui-shen-solution.xml"); assertTrue(true); } @Test - public void unassignedJobShouldBeRead(){ + public void unassignedJobShouldBeRead() { VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); ArrayList solutions = new ArrayList(); new VrpXMLReader(vrpBuilder, solutions).read("src/test/resources/finiteVrpWithShipmentsAndSolution.xml"); VehicleRoutingProblemSolution solution = Solutions.bestOf(solutions); - assertEquals(1,solution.getUnassignedJobs().size()); - assertEquals("4",solution.getUnassignedJobs().iterator().next().getId()); + assertEquals(1, solution.getUnassignedJobs().size()); + assertEquals("4", solution.getUnassignedJobs().iterator().next().getId()); } // @Test diff --git a/jsprit-core/src/test/java/jsprit/core/problem/io/VrpXMLWriterTest.java b/jsprit-core/src/test/java/jsprit/core/problem/io/VrpXMLWriterTest.java index 00fb2bce..cfff0393 100644 --- a/jsprit-core/src/test/java/jsprit/core/problem/io/VrpXMLWriterTest.java +++ b/jsprit-core/src/test/java/jsprit/core/problem/io/VrpXMLWriterTest.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.problem.io; @@ -41,89 +41,89 @@ import java.util.List; import static org.junit.Assert.*; public class VrpXMLWriterTest { - - private String infileName; - - @Before - public void doBefore(){ - infileName = "src/test/resources/infiniteWriterV2Test.xml"; - } - @Test - public void whenWritingInfiniteVrp_itWritesCorrectly(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - builder.setFleetSize(FleetSize.INFINITE); - VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("vehType").addCapacityDimension(0, 20).build(); - VehicleImpl vehicle = VehicleImpl.Builder.newInstance("myVehicle").setStartLocation(TestUtils.loc("loc")).setType(type).build(); - builder.addVehicle(vehicle); - VehicleRoutingProblem vrp = builder.build(); - new VrpXMLWriter(vrp, null).write(infileName); - } - - @Test - public void whenWritingFiniteVrp_itWritesCorrectly(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - builder.setFleetSize(FleetSize.FINITE); - VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType").addCapacityDimension(0, 20).build(); - VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("vehType2").addCapacityDimension(0, 200).build(); - VehicleImpl v1 = VehicleImpl.Builder.newInstance("v1").setStartLocation(TestUtils.loc("loc")).setType(type1).build(); - VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(TestUtils.loc("loc")).setType(type2).build(); - builder.addVehicle(v1); - builder.addVehicle(v2); - VehicleRoutingProblem vrp = builder.build(); - new VrpXMLWriter(vrp, null).write(infileName); - } - - @Test - public void t(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - builder.setFleetSize(FleetSize.FINITE); - VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType").addCapacityDimension(0, 20).build(); - VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("vehType2").addCapacityDimension(0, 200).build(); - VehicleImpl v1 = VehicleImpl.Builder.newInstance("v1").setStartLocation(TestUtils.loc("loc")).setType(type1).build(); - VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(TestUtils.loc("loc")).setType(type2).build(); - builder.addVehicle(v1); - builder.addVehicle(v2); - VehicleRoutingProblem vrp = builder.build(); - new VrpXMLWriter(vrp, null).write(infileName); - - VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpToReadBuilder, null).read(infileName); - } - - @Test - public void whenWritingServices_itWritesThemCorrectly(){ - Builder builder = VehicleRoutingProblem.Builder.newInstance(); - - VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType").addCapacityDimension(0, 20).build(); - VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("vehType2").addCapacityDimension(0, 200).build(); - VehicleImpl v1 = VehicleImpl.Builder.newInstance("v1").setStartLocation(TestUtils.loc("loc")).setType(type1).build(); - VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(TestUtils.loc("loc")).setType(type2).build(); - - builder.addVehicle(v1); - builder.addVehicle(v2); - - - Service s1 = Service.Builder.newInstance("1").addSizeDimension(0, 1).setLocation(TestUtils.loc("loc")).setServiceTime(2.0).build(); - Service s2 = Service.Builder.newInstance("2").addSizeDimension(0, 1).setLocation(TestUtils.loc("loc2")).setServiceTime(4.0).build(); - - VehicleRoutingProblem vrp = builder.addJob(s1).addJob(s2).build(); - new VrpXMLWriter(vrp, null).write(infileName); - - VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpToReadBuilder, null).read(infileName); - VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); - assertEquals(2,readVrp.getJobs().size()); - - Service s1_read = (Service) vrp.getJobs().get("1"); - assertEquals("1", s1_read.getId()); - assertEquals("loc", s1_read.getLocation().getId()); - assertEquals("service", s1_read.getType()); - assertEquals(2.0,s1_read.getServiceDuration(),0.01); - } + private String infileName; + + @Before + public void doBefore() { + infileName = "src/test/resources/infiniteWriterV2Test.xml"; + } @Test - public void shouldWriteNameOfService(){ + public void whenWritingInfiniteVrp_itWritesCorrectly() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + builder.setFleetSize(FleetSize.INFINITE); + VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("vehType").addCapacityDimension(0, 20).build(); + VehicleImpl vehicle = VehicleImpl.Builder.newInstance("myVehicle").setStartLocation(TestUtils.loc("loc")).setType(type).build(); + builder.addVehicle(vehicle); + VehicleRoutingProblem vrp = builder.build(); + new VrpXMLWriter(vrp, null).write(infileName); + } + + @Test + public void whenWritingFiniteVrp_itWritesCorrectly() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + builder.setFleetSize(FleetSize.FINITE); + VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType").addCapacityDimension(0, 20).build(); + VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("vehType2").addCapacityDimension(0, 200).build(); + VehicleImpl v1 = VehicleImpl.Builder.newInstance("v1").setStartLocation(TestUtils.loc("loc")).setType(type1).build(); + VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(TestUtils.loc("loc")).setType(type2).build(); + builder.addVehicle(v1); + builder.addVehicle(v2); + VehicleRoutingProblem vrp = builder.build(); + new VrpXMLWriter(vrp, null).write(infileName); + } + + @Test + public void t() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + builder.setFleetSize(FleetSize.FINITE); + VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType").addCapacityDimension(0, 20).build(); + VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("vehType2").addCapacityDimension(0, 200).build(); + VehicleImpl v1 = VehicleImpl.Builder.newInstance("v1").setStartLocation(TestUtils.loc("loc")).setType(type1).build(); + VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(TestUtils.loc("loc")).setType(type2).build(); + builder.addVehicle(v1); + builder.addVehicle(v2); + VehicleRoutingProblem vrp = builder.build(); + new VrpXMLWriter(vrp, null).write(infileName); + + VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(vrpToReadBuilder, null).read(infileName); + } + + @Test + public void whenWritingServices_itWritesThemCorrectly() { + Builder builder = VehicleRoutingProblem.Builder.newInstance(); + + VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType").addCapacityDimension(0, 20).build(); + VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("vehType2").addCapacityDimension(0, 200).build(); + VehicleImpl v1 = VehicleImpl.Builder.newInstance("v1").setStartLocation(TestUtils.loc("loc")).setType(type1).build(); + VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(TestUtils.loc("loc")).setType(type2).build(); + + builder.addVehicle(v1); + builder.addVehicle(v2); + + + Service s1 = Service.Builder.newInstance("1").addSizeDimension(0, 1).setLocation(TestUtils.loc("loc")).setServiceTime(2.0).build(); + Service s2 = Service.Builder.newInstance("2").addSizeDimension(0, 1).setLocation(TestUtils.loc("loc2")).setServiceTime(4.0).build(); + + VehicleRoutingProblem vrp = builder.addJob(s1).addJob(s2).build(); + new VrpXMLWriter(vrp, null).write(infileName); + + VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(vrpToReadBuilder, null).read(infileName); + VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); + assertEquals(2, readVrp.getJobs().size()); + + Service s1_read = (Service) vrp.getJobs().get("1"); + assertEquals("1", s1_read.getId()); + assertEquals("loc", s1_read.getLocation().getId()); + assertEquals("service", s1_read.getType()); + assertEquals(2.0, s1_read.getServiceDuration(), 0.01); + } + + @Test + public void shouldWriteNameOfService() { Builder builder = VehicleRoutingProblem.Builder.newInstance(); Service s1 = Service.Builder.newInstance("1").setName("cleaning").addSizeDimension(0, 1).setLocation(TestUtils.loc("loc")).setServiceTime(2.0).build(); @@ -138,12 +138,12 @@ public class VrpXMLWriterTest { } @Test - public void shouldWriteNameOfShipment(){ + public void shouldWriteNameOfShipment() { Builder builder = VehicleRoutingProblem.Builder.newInstance(); Location pickLocation = Location.Builder.newInstance().setId("pick").setIndex(1).build(); Shipment s1 = Shipment.Builder.newInstance("1").setName("cleaning") - .setPickupLocation(pickLocation) - .setDeliveryLocation(TestUtils.loc("del")).build(); + .setPickupLocation(pickLocation) + .setDeliveryLocation(TestUtils.loc("del")).build(); VehicleRoutingProblem vrp = builder.addJob(s1).build(); new VrpXMLWriter(vrp, null).write(infileName); @@ -153,214 +153,214 @@ public class VrpXMLWriterTest { VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); Shipment s1_read = (Shipment) readVrp.getJobs().get("1"); assertTrue(s1_read.getName().equals("cleaning")); - assertEquals(1,s1_read.getPickupLocation().getIndex()); + assertEquals(1, s1_read.getPickupLocation().getIndex()); } - - @Test - public void whenWritingServicesWithSeveralCapacityDimensions_itWritesThemCorrectly(){ - Builder builder = VehicleRoutingProblem.Builder.newInstance(); - - Service s1 = Service.Builder.newInstance("1") - .addSizeDimension(0, 20) - .addSizeDimension(1, 200) - .setLocation(TestUtils.loc("loc")).setServiceTime(2.0).build(); - Service s2 = Service.Builder.newInstance("2").addSizeDimension(0, 1).setLocation(TestUtils.loc("loc2")).setServiceTime(4.0).build(); - - VehicleRoutingProblem vrp = builder.addJob(s1).addJob(s2).build(); - new VrpXMLWriter(vrp, null).write(infileName); - - VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpToReadBuilder, null).read(infileName); - VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); - assertEquals(2,readVrp.getJobs().size()); - - Service s1_read = (Service) vrp.getJobs().get("1"); - - assertEquals(2, s1_read.getSize().getNuOfDimensions()); - assertEquals(20, s1_read.getSize().get(0)); - assertEquals(200, s1_read.getSize().get(1)); - - } - - @Test - public void whenWritingShipments_readingThemAgainMustReturnTheWrittenLocationIdsOfS1(){ - Builder builder = VehicleRoutingProblem.Builder.newInstance(); - - VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType").addCapacityDimension(0, 20).build(); - VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("vehType2").addCapacityDimension(0, 200).build(); - VehicleImpl v1 = VehicleImpl.Builder.newInstance("v1").setStartLocation(TestUtils.loc("loc")).setType(type1).build(); - VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(TestUtils.loc("loc")).setType(type2).build(); - - builder.addVehicle(v1); - builder.addVehicle(v2); - - Shipment s1 = Shipment.Builder.newInstance("1").addSizeDimension(0, 10) - .setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()) - .setDeliveryLocation(TestUtils.loc("delLoc")).setPickupTimeWindow(TimeWindow.newInstance(1, 2)) - .setDeliveryTimeWindow(TimeWindow.newInstance(3, 4)).build(); - Shipment s2 = Shipment.Builder.newInstance("2").addSizeDimension(0, 20) - .setPickupLocation(Location.Builder.newInstance().setId("pickLocation").build()) - .setDeliveryLocation(TestUtils.loc("delLocation")).setPickupTimeWindow(TimeWindow.newInstance(5, 6)) - .setDeliveryTimeWindow(TimeWindow.newInstance(7, 8)).build(); - - - VehicleRoutingProblem vrp = builder.addJob(s1).addJob(s2).build(); - new VrpXMLWriter(vrp, null).write(infileName); - - VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpToReadBuilder, null).read(infileName); - VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); - assertEquals(2,readVrp.getJobs().size()); - - assertEquals("pickLoc",((Shipment)readVrp.getJobs().get("1")).getPickupLocation().getId()); - assertEquals("delLoc",((Shipment)readVrp.getJobs().get("1")).getDeliveryLocation().getId()); - - } - - @Test - public void whenWritingShipments_readingThemAgainMustReturnTheWrittenPickupTimeWindowsOfS1(){ - Builder builder = VehicleRoutingProblem.Builder.newInstance(); - - VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType").addCapacityDimension(0, 20).build(); - VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("vehType2").addCapacityDimension(0, 200).build(); - VehicleImpl v1 = VehicleImpl.Builder.newInstance("v1").setStartLocation(TestUtils.loc("loc")).setType(type1).build(); - VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(TestUtils.loc("loc")).setType(type2).build(); - - builder.addVehicle(v1); - builder.addVehicle(v2); - - Shipment s1 = Shipment.Builder.newInstance("1").addSizeDimension(0, 10) - .setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()) - .setDeliveryLocation(TestUtils.loc("delLoc")).setPickupTimeWindow(TimeWindow.newInstance(1, 2)) - .setDeliveryTimeWindow(TimeWindow.newInstance(3, 4)).build(); - Shipment s2 = Shipment.Builder.newInstance("2").addSizeDimension(0, 20) - .setPickupLocation(Location.Builder.newInstance().setId("pickLocation").build()) - .setDeliveryLocation(TestUtils.loc("delLocation")).setPickupTimeWindow(TimeWindow.newInstance(5, 6)) - .setDeliveryTimeWindow(TimeWindow.newInstance(7, 8)).build(); - - - VehicleRoutingProblem vrp = builder.addJob(s1).addJob(s2).build(); - new VrpXMLWriter(vrp, null).write(infileName); - - VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpToReadBuilder, null).read(infileName); - VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); - assertEquals(2,readVrp.getJobs().size()); - - assertEquals(1.0,((Shipment)readVrp.getJobs().get("1")).getPickupTimeWindow().getStart(),0.01); - assertEquals(2.0,((Shipment)readVrp.getJobs().get("1")).getPickupTimeWindow().getEnd(),0.01); - - - } - - @Test - public void whenWritingShipments_readingThemAgainMustReturnTheWrittenDeliveryTimeWindowsOfS1(){ - Builder builder = VehicleRoutingProblem.Builder.newInstance(); - - VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType").addCapacityDimension(0, 20).build(); - VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("vehType2").addCapacityDimension(0, 200).build(); - VehicleImpl v1 = VehicleImpl.Builder.newInstance("v1").setStartLocation(TestUtils.loc("loc")).setType(type1).build(); - VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(TestUtils.loc("loc")).setType(type2).build(); - - builder.addVehicle(v1); - builder.addVehicle(v2); - - Shipment s1 = Shipment.Builder.newInstance("1").addSizeDimension(0, 10) - .setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()) - .setDeliveryLocation(TestUtils.loc("delLoc")).setPickupTimeWindow(TimeWindow.newInstance(1, 2)) - .setDeliveryTimeWindow(TimeWindow.newInstance(3, 4)).build(); - Shipment s2 = Shipment.Builder.newInstance("2").addSizeDimension(0, 20) - .setPickupLocation(Location.Builder.newInstance().setId("pickLocation").build()) - .setDeliveryLocation(TestUtils.loc("delLocation")).setPickupTimeWindow(TimeWindow.newInstance(5, 6)) - .setDeliveryTimeWindow(TimeWindow.newInstance(7, 8)).build(); - - - VehicleRoutingProblem vrp = builder.addJob(s1).addJob(s2).build(); - new VrpXMLWriter(vrp, null).write(infileName); - - VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpToReadBuilder, null).read(infileName); - VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); - assertEquals(2,readVrp.getJobs().size()); - - assertEquals(3.0,((Shipment)readVrp.getJobs().get("1")).getDeliveryTimeWindow().getStart(),0.01); - assertEquals(4.0,((Shipment)readVrp.getJobs().get("1")).getDeliveryTimeWindow().getEnd(),0.01); - - } - - @Test - public void whenWritingShipments_readingThemAgainMustReturnTheWrittenDeliveryServiceTimeOfS1(){ - Builder builder = VehicleRoutingProblem.Builder.newInstance(); - - VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType").addCapacityDimension(0, 20).build(); - VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("vehType2").addCapacityDimension(0, 200).build(); - VehicleImpl v1 = VehicleImpl.Builder.newInstance("v1").setStartLocation(TestUtils.loc("loc")).setType(type1).build(); - VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(TestUtils.loc("loc")).setType(type2).build(); - - builder.addVehicle(v1); - builder.addVehicle(v2); - - Shipment s1 = Shipment.Builder.newInstance("1").addSizeDimension(0, 10) - .setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()) - .setDeliveryLocation(TestUtils.loc("delLoc")).setPickupTimeWindow(TimeWindow.newInstance(1, 2)) - .setDeliveryTimeWindow(TimeWindow.newInstance(3, 4)).setPickupServiceTime(100).setDeliveryServiceTime(50).build(); - Shipment s2 = Shipment.Builder.newInstance("2").addSizeDimension(0, 20) - .setPickupLocation(Location.Builder.newInstance().setId("pickLocation").build()) - .setDeliveryLocation(TestUtils.loc("delLocation")).setPickupTimeWindow(TimeWindow.newInstance(5, 6)) - .setDeliveryTimeWindow(TimeWindow.newInstance(7, 8)).build(); - - - VehicleRoutingProblem vrp = builder.addJob(s1).addJob(s2).build(); - new VrpXMLWriter(vrp, null).write(infileName); - - VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpToReadBuilder, null).read(infileName); - VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); - assertEquals(2,readVrp.getJobs().size()); - - assertEquals(100.0,((Shipment)readVrp.getJobs().get("1")).getPickupServiceTime(),0.01); - assertEquals(50.0,((Shipment)readVrp.getJobs().get("1")).getDeliveryServiceTime(),0.01); - - } - - @Test - public void whenWritingShipments_readingThemAgainMustReturnTheWrittenLocationIdOfS1(){ - Builder builder = VehicleRoutingProblem.Builder.newInstance(); - - VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType").addCapacityDimension(0, 20).build(); - VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("vehType2").addCapacityDimension(0, 200).build(); - VehicleImpl v1 = VehicleImpl.Builder.newInstance("v1").setStartLocation(TestUtils.loc("loc")).setType(type1).build(); - VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(TestUtils.loc("loc")).setType(type2).build(); - - builder.addVehicle(v1); - builder.addVehicle(v2); - - Shipment s1 = Shipment.Builder.newInstance("1").addSizeDimension(0, 10) - .setPickupLocation(TestUtils.loc(Coordinate.newInstance(1, 2))).setDeliveryLocation(TestUtils.loc("delLoc")).setPickupTimeWindow(TimeWindow.newInstance(1, 2)) - .setDeliveryTimeWindow(TimeWindow.newInstance(3, 4)).setPickupServiceTime(100).setDeliveryServiceTime(50).build(); - Shipment s2 = Shipment.Builder.newInstance("2").addSizeDimension(0, 20) - .setPickupLocation(Location.Builder.newInstance().setId("pickLocation").build()) - .setDeliveryLocation(TestUtils.loc("delLocation")).setPickupTimeWindow(TimeWindow.newInstance(5, 6)) - .setDeliveryTimeWindow(TimeWindow.newInstance(7, 8)).build(); - - - VehicleRoutingProblem vrp = builder.addJob(s1).addJob(s2).build(); - new VrpXMLWriter(vrp, null).write(infileName); - - VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpToReadBuilder, null).read(infileName); - VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); - assertEquals(2,readVrp.getJobs().size()); - - assertEquals("[x=1.0][y=2.0]",((Shipment)readVrp.getJobs().get("1")).getPickupLocation().getId()); - } @Test - public void whenWritingVehicles_vehShouldHave2Skills(){ + public void whenWritingServicesWithSeveralCapacityDimensions_itWritesThemCorrectly() { + Builder builder = VehicleRoutingProblem.Builder.newInstance(); + + Service s1 = Service.Builder.newInstance("1") + .addSizeDimension(0, 20) + .addSizeDimension(1, 200) + .setLocation(TestUtils.loc("loc")).setServiceTime(2.0).build(); + Service s2 = Service.Builder.newInstance("2").addSizeDimension(0, 1).setLocation(TestUtils.loc("loc2")).setServiceTime(4.0).build(); + + VehicleRoutingProblem vrp = builder.addJob(s1).addJob(s2).build(); + new VrpXMLWriter(vrp, null).write(infileName); + + VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(vrpToReadBuilder, null).read(infileName); + VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); + assertEquals(2, readVrp.getJobs().size()); + + Service s1_read = (Service) vrp.getJobs().get("1"); + + assertEquals(2, s1_read.getSize().getNuOfDimensions()); + assertEquals(20, s1_read.getSize().get(0)); + assertEquals(200, s1_read.getSize().get(1)); + + } + + @Test + public void whenWritingShipments_readingThemAgainMustReturnTheWrittenLocationIdsOfS1() { + Builder builder = VehicleRoutingProblem.Builder.newInstance(); + + VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType").addCapacityDimension(0, 20).build(); + VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("vehType2").addCapacityDimension(0, 200).build(); + VehicleImpl v1 = VehicleImpl.Builder.newInstance("v1").setStartLocation(TestUtils.loc("loc")).setType(type1).build(); + VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(TestUtils.loc("loc")).setType(type2).build(); + + builder.addVehicle(v1); + builder.addVehicle(v2); + + Shipment s1 = Shipment.Builder.newInstance("1").addSizeDimension(0, 10) + .setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()) + .setDeliveryLocation(TestUtils.loc("delLoc")).setPickupTimeWindow(TimeWindow.newInstance(1, 2)) + .setDeliveryTimeWindow(TimeWindow.newInstance(3, 4)).build(); + Shipment s2 = Shipment.Builder.newInstance("2").addSizeDimension(0, 20) + .setPickupLocation(Location.Builder.newInstance().setId("pickLocation").build()) + .setDeliveryLocation(TestUtils.loc("delLocation")).setPickupTimeWindow(TimeWindow.newInstance(5, 6)) + .setDeliveryTimeWindow(TimeWindow.newInstance(7, 8)).build(); + + + VehicleRoutingProblem vrp = builder.addJob(s1).addJob(s2).build(); + new VrpXMLWriter(vrp, null).write(infileName); + + VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(vrpToReadBuilder, null).read(infileName); + VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); + assertEquals(2, readVrp.getJobs().size()); + + assertEquals("pickLoc", ((Shipment) readVrp.getJobs().get("1")).getPickupLocation().getId()); + assertEquals("delLoc", ((Shipment) readVrp.getJobs().get("1")).getDeliveryLocation().getId()); + + } + + @Test + public void whenWritingShipments_readingThemAgainMustReturnTheWrittenPickupTimeWindowsOfS1() { + Builder builder = VehicleRoutingProblem.Builder.newInstance(); + + VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType").addCapacityDimension(0, 20).build(); + VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("vehType2").addCapacityDimension(0, 200).build(); + VehicleImpl v1 = VehicleImpl.Builder.newInstance("v1").setStartLocation(TestUtils.loc("loc")).setType(type1).build(); + VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(TestUtils.loc("loc")).setType(type2).build(); + + builder.addVehicle(v1); + builder.addVehicle(v2); + + Shipment s1 = Shipment.Builder.newInstance("1").addSizeDimension(0, 10) + .setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()) + .setDeliveryLocation(TestUtils.loc("delLoc")).setPickupTimeWindow(TimeWindow.newInstance(1, 2)) + .setDeliveryTimeWindow(TimeWindow.newInstance(3, 4)).build(); + Shipment s2 = Shipment.Builder.newInstance("2").addSizeDimension(0, 20) + .setPickupLocation(Location.Builder.newInstance().setId("pickLocation").build()) + .setDeliveryLocation(TestUtils.loc("delLocation")).setPickupTimeWindow(TimeWindow.newInstance(5, 6)) + .setDeliveryTimeWindow(TimeWindow.newInstance(7, 8)).build(); + + + VehicleRoutingProblem vrp = builder.addJob(s1).addJob(s2).build(); + new VrpXMLWriter(vrp, null).write(infileName); + + VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(vrpToReadBuilder, null).read(infileName); + VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); + assertEquals(2, readVrp.getJobs().size()); + + assertEquals(1.0, ((Shipment) readVrp.getJobs().get("1")).getPickupTimeWindow().getStart(), 0.01); + assertEquals(2.0, ((Shipment) readVrp.getJobs().get("1")).getPickupTimeWindow().getEnd(), 0.01); + + + } + + @Test + public void whenWritingShipments_readingThemAgainMustReturnTheWrittenDeliveryTimeWindowsOfS1() { + Builder builder = VehicleRoutingProblem.Builder.newInstance(); + + VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType").addCapacityDimension(0, 20).build(); + VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("vehType2").addCapacityDimension(0, 200).build(); + VehicleImpl v1 = VehicleImpl.Builder.newInstance("v1").setStartLocation(TestUtils.loc("loc")).setType(type1).build(); + VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(TestUtils.loc("loc")).setType(type2).build(); + + builder.addVehicle(v1); + builder.addVehicle(v2); + + Shipment s1 = Shipment.Builder.newInstance("1").addSizeDimension(0, 10) + .setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()) + .setDeliveryLocation(TestUtils.loc("delLoc")).setPickupTimeWindow(TimeWindow.newInstance(1, 2)) + .setDeliveryTimeWindow(TimeWindow.newInstance(3, 4)).build(); + Shipment s2 = Shipment.Builder.newInstance("2").addSizeDimension(0, 20) + .setPickupLocation(Location.Builder.newInstance().setId("pickLocation").build()) + .setDeliveryLocation(TestUtils.loc("delLocation")).setPickupTimeWindow(TimeWindow.newInstance(5, 6)) + .setDeliveryTimeWindow(TimeWindow.newInstance(7, 8)).build(); + + + VehicleRoutingProblem vrp = builder.addJob(s1).addJob(s2).build(); + new VrpXMLWriter(vrp, null).write(infileName); + + VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(vrpToReadBuilder, null).read(infileName); + VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); + assertEquals(2, readVrp.getJobs().size()); + + assertEquals(3.0, ((Shipment) readVrp.getJobs().get("1")).getDeliveryTimeWindow().getStart(), 0.01); + assertEquals(4.0, ((Shipment) readVrp.getJobs().get("1")).getDeliveryTimeWindow().getEnd(), 0.01); + + } + + @Test + public void whenWritingShipments_readingThemAgainMustReturnTheWrittenDeliveryServiceTimeOfS1() { + Builder builder = VehicleRoutingProblem.Builder.newInstance(); + + VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType").addCapacityDimension(0, 20).build(); + VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("vehType2").addCapacityDimension(0, 200).build(); + VehicleImpl v1 = VehicleImpl.Builder.newInstance("v1").setStartLocation(TestUtils.loc("loc")).setType(type1).build(); + VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(TestUtils.loc("loc")).setType(type2).build(); + + builder.addVehicle(v1); + builder.addVehicle(v2); + + Shipment s1 = Shipment.Builder.newInstance("1").addSizeDimension(0, 10) + .setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()) + .setDeliveryLocation(TestUtils.loc("delLoc")).setPickupTimeWindow(TimeWindow.newInstance(1, 2)) + .setDeliveryTimeWindow(TimeWindow.newInstance(3, 4)).setPickupServiceTime(100).setDeliveryServiceTime(50).build(); + Shipment s2 = Shipment.Builder.newInstance("2").addSizeDimension(0, 20) + .setPickupLocation(Location.Builder.newInstance().setId("pickLocation").build()) + .setDeliveryLocation(TestUtils.loc("delLocation")).setPickupTimeWindow(TimeWindow.newInstance(5, 6)) + .setDeliveryTimeWindow(TimeWindow.newInstance(7, 8)).build(); + + + VehicleRoutingProblem vrp = builder.addJob(s1).addJob(s2).build(); + new VrpXMLWriter(vrp, null).write(infileName); + + VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(vrpToReadBuilder, null).read(infileName); + VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); + assertEquals(2, readVrp.getJobs().size()); + + assertEquals(100.0, ((Shipment) readVrp.getJobs().get("1")).getPickupServiceTime(), 0.01); + assertEquals(50.0, ((Shipment) readVrp.getJobs().get("1")).getDeliveryServiceTime(), 0.01); + + } + + @Test + public void whenWritingShipments_readingThemAgainMustReturnTheWrittenLocationIdOfS1() { + Builder builder = VehicleRoutingProblem.Builder.newInstance(); + + VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType").addCapacityDimension(0, 20).build(); + VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("vehType2").addCapacityDimension(0, 200).build(); + VehicleImpl v1 = VehicleImpl.Builder.newInstance("v1").setStartLocation(TestUtils.loc("loc")).setType(type1).build(); + VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(TestUtils.loc("loc")).setType(type2).build(); + + builder.addVehicle(v1); + builder.addVehicle(v2); + + Shipment s1 = Shipment.Builder.newInstance("1").addSizeDimension(0, 10) + .setPickupLocation(TestUtils.loc(Coordinate.newInstance(1, 2))).setDeliveryLocation(TestUtils.loc("delLoc")).setPickupTimeWindow(TimeWindow.newInstance(1, 2)) + .setDeliveryTimeWindow(TimeWindow.newInstance(3, 4)).setPickupServiceTime(100).setDeliveryServiceTime(50).build(); + Shipment s2 = Shipment.Builder.newInstance("2").addSizeDimension(0, 20) + .setPickupLocation(Location.Builder.newInstance().setId("pickLocation").build()) + .setDeliveryLocation(TestUtils.loc("delLocation")).setPickupTimeWindow(TimeWindow.newInstance(5, 6)) + .setDeliveryTimeWindow(TimeWindow.newInstance(7, 8)).build(); + + + VehicleRoutingProblem vrp = builder.addJob(s1).addJob(s2).build(); + new VrpXMLWriter(vrp, null).write(infileName); + + VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(vrpToReadBuilder, null).read(infileName); + VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); + assertEquals(2, readVrp.getJobs().size()); + + assertEquals("[x=1.0][y=2.0]", ((Shipment) readVrp.getJobs().get("1")).getPickupLocation().getId()); + } + + @Test + public void whenWritingVehicles_vehShouldHave2Skills() { Builder builder = VehicleRoutingProblem.Builder.newInstance(); VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType").addCapacityDimension(0, 20).build(); VehicleImpl v = VehicleImpl.Builder.newInstance("v1").addSkill("SKILL5").addSkill("skill1").addSkill("Skill2") - .setStartLocation(TestUtils.loc("loc")).setType(type1).build(); + .setStartLocation(TestUtils.loc("loc")).setType(type1).build(); builder.addVehicle(v); VehicleRoutingProblem vrp = builder.build(); @@ -369,17 +369,17 @@ public class VrpXMLWriterTest { VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); new VrpXMLReader(vrpToReadBuilder, null).read(infileName); VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); - Vehicle veh1 = getVehicle("v1",readVrp); + Vehicle veh1 = getVehicle("v1", readVrp); - assertEquals(3,veh1.getSkills().values().size()); + assertEquals(3, veh1.getSkills().values().size()); } @Test - public void whenWritingVehicles_vehShouldContain_skill5(){ + public void whenWritingVehicles_vehShouldContain_skill5() { Builder builder = VehicleRoutingProblem.Builder.newInstance(); VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType").addCapacityDimension(0, 20).build(); VehicleImpl v = VehicleImpl.Builder.newInstance("v1").addSkill("SKILL5").addSkill("skill1").addSkill("Skill2") - .setStartLocation(TestUtils.loc("loc")).setType(type1).build(); + .setStartLocation(TestUtils.loc("loc")).setType(type1).build(); builder.addVehicle(v); VehicleRoutingProblem vrp = builder.build(); @@ -388,17 +388,17 @@ public class VrpXMLWriterTest { VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); new VrpXMLReader(vrpToReadBuilder, null).read(infileName); VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); - Vehicle veh1 = getVehicle("v1",readVrp); + Vehicle veh1 = getVehicle("v1", readVrp); assertTrue(veh1.getSkills().containsSkill("skill5")); } @Test - public void whenWritingVehicles_vehShouldContain_skill1(){ + public void whenWritingVehicles_vehShouldContain_skill1() { Builder builder = VehicleRoutingProblem.Builder.newInstance(); VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType").addCapacityDimension(0, 20).build(); VehicleImpl v = VehicleImpl.Builder.newInstance("v1").addSkill("SKILL5").addSkill("skill1").addSkill("Skill2") - .setStartLocation(TestUtils.loc("loc")).setType(type1).build(); + .setStartLocation(TestUtils.loc("loc")).setType(type1).build(); builder.addVehicle(v); VehicleRoutingProblem vrp = builder.build(); @@ -407,17 +407,17 @@ public class VrpXMLWriterTest { VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); new VrpXMLReader(vrpToReadBuilder, null).read(infileName); VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); - Vehicle veh1 = getVehicle("v1",readVrp); + Vehicle veh1 = getVehicle("v1", readVrp); assertTrue(veh1.getSkills().containsSkill("skill1")); } @Test - public void whenWritingVehicles_vehShouldContain_skill2(){ + public void whenWritingVehicles_vehShouldContain_skill2() { Builder builder = VehicleRoutingProblem.Builder.newInstance(); VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType").addCapacityDimension(0, 20).build(); VehicleImpl v = VehicleImpl.Builder.newInstance("v1").addSkill("SKILL5").addSkill("skill1").addSkill("Skill2") - .setStartLocation(TestUtils.loc("loc")).setType(type1).build(); + .setStartLocation(TestUtils.loc("loc")).setType(type1).build(); builder.addVehicle(v); VehicleRoutingProblem vrp = builder.build(); @@ -426,13 +426,13 @@ public class VrpXMLWriterTest { VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); new VrpXMLReader(vrpToReadBuilder, null).read(infileName); VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); - Vehicle veh1 = getVehicle("v1",readVrp); + Vehicle veh1 = getVehicle("v1", readVrp); assertTrue(veh1.getSkills().containsSkill("skill2")); } @Test - public void whenWritingVehicles_vehShouldHave0Skills(){ + public void whenWritingVehicles_vehShouldHave0Skills() { Builder builder = VehicleRoutingProblem.Builder.newInstance(); VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType").addCapacityDimension(0, 20).build(); VehicleImpl v = VehicleImpl.Builder.newInstance("v1").setStartLocation(TestUtils.loc("loc")).setType(type1).build(); @@ -444,28 +444,28 @@ public class VrpXMLWriterTest { VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); new VrpXMLReader(vrpToReadBuilder, null).read(infileName); VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); - Vehicle veh = getVehicle("v1",readVrp); + Vehicle veh = getVehicle("v1", readVrp); - assertEquals(0,veh.getSkills().values().size()); + assertEquals(0, veh.getSkills().values().size()); } private Vehicle getVehicle(String v1, VehicleRoutingProblem readVrp) { - for(Vehicle v : readVrp.getVehicles()){ - if(v.getId().equals(v1)) return v; + for (Vehicle v : readVrp.getVehicles()) { + if (v.getId().equals(v1)) return v; } return null; } @Test - public void whenWritingShipments_shipmentShouldHaveCorrectNuSkills(){ + public void whenWritingShipments_shipmentShouldHaveCorrectNuSkills() { Builder builder = VehicleRoutingProblem.Builder.newInstance(); Shipment s = Shipment.Builder.newInstance("1").addRequiredSkill("skill1").addRequiredSkill("skill2").addRequiredSkill("skill3") - .addSizeDimension(0, 10) - .setPickupLocation(TestUtils.loc(Coordinate.newInstance(1, 2))) - .setDeliveryLocation(TestUtils.loc("delLoc", Coordinate.newInstance(5, 6))) - .setPickupTimeWindow(TimeWindow.newInstance(1, 2)) - .setDeliveryTimeWindow(TimeWindow.newInstance(3, 4)).setPickupServiceTime(100).setDeliveryServiceTime(50).build(); + .addSizeDimension(0, 10) + .setPickupLocation(TestUtils.loc(Coordinate.newInstance(1, 2))) + .setDeliveryLocation(TestUtils.loc("delLoc", Coordinate.newInstance(5, 6))) + .setPickupTimeWindow(TimeWindow.newInstance(1, 2)) + .setDeliveryTimeWindow(TimeWindow.newInstance(3, 4)).setPickupServiceTime(100).setDeliveryServiceTime(50).build(); VehicleRoutingProblem vrp = builder.addJob(s).build(); new VrpXMLWriter(vrp, null).write(infileName); @@ -474,19 +474,19 @@ public class VrpXMLWriterTest { new VrpXMLReader(vrpToReadBuilder, null).read(infileName); VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); - assertEquals(3,readVrp.getJobs().get("1").getRequiredSkills().values().size()); + assertEquals(3, readVrp.getJobs().get("1").getRequiredSkills().values().size()); } @Test - public void whenWritingShipments_shipmentShouldContain_skill1(){ + public void whenWritingShipments_shipmentShouldContain_skill1() { Builder builder = VehicleRoutingProblem.Builder.newInstance(); Shipment s = Shipment.Builder.newInstance("1").addRequiredSkill("skill1").addRequiredSkill("skill2").addRequiredSkill("skill3") - .addSizeDimension(0, 10) - .setPickupLocation(TestUtils.loc(Coordinate.newInstance(1, 2))) - .setDeliveryLocation(TestUtils.loc("delLoc", Coordinate.newInstance(5, 6))) - .setPickupTimeWindow(TimeWindow.newInstance(1, 2)) - .setDeliveryTimeWindow(TimeWindow.newInstance(3, 4)).setPickupServiceTime(100).setDeliveryServiceTime(50).build(); + .addSizeDimension(0, 10) + .setPickupLocation(TestUtils.loc(Coordinate.newInstance(1, 2))) + .setDeliveryLocation(TestUtils.loc("delLoc", Coordinate.newInstance(5, 6))) + .setPickupTimeWindow(TimeWindow.newInstance(1, 2)) + .setDeliveryTimeWindow(TimeWindow.newInstance(3, 4)).setPickupServiceTime(100).setDeliveryServiceTime(50).build(); VehicleRoutingProblem vrp = builder.addJob(s).build(); new VrpXMLWriter(vrp, null).write(infileName); @@ -499,15 +499,15 @@ public class VrpXMLWriterTest { } @Test - public void whenWritingShipments_shipmentShouldContain_skill2(){ + public void whenWritingShipments_shipmentShouldContain_skill2() { Builder builder = VehicleRoutingProblem.Builder.newInstance(); Shipment s = Shipment.Builder.newInstance("1").addRequiredSkill("skill1").addRequiredSkill("Skill2").addRequiredSkill("skill3") - .addSizeDimension(0, 10) - .setPickupLocation(TestUtils.loc(Coordinate.newInstance(1, 2))) - .setDeliveryLocation(TestUtils.loc("delLoc", Coordinate.newInstance(5, 6))) - .setPickupTimeWindow(TimeWindow.newInstance(1, 2)) - .setDeliveryTimeWindow(TimeWindow.newInstance(3, 4)).setPickupServiceTime(100).setDeliveryServiceTime(50).build(); + .addSizeDimension(0, 10) + .setPickupLocation(TestUtils.loc(Coordinate.newInstance(1, 2))) + .setDeliveryLocation(TestUtils.loc("delLoc", Coordinate.newInstance(5, 6))) + .setPickupTimeWindow(TimeWindow.newInstance(1, 2)) + .setDeliveryTimeWindow(TimeWindow.newInstance(3, 4)).setPickupServiceTime(100).setDeliveryServiceTime(50).build(); VehicleRoutingProblem vrp = builder.addJob(s).build(); new VrpXMLWriter(vrp, null).write(infileName); @@ -520,15 +520,15 @@ public class VrpXMLWriterTest { } @Test - public void whenWritingShipments_shipmentShouldContain_skill3(){ + public void whenWritingShipments_shipmentShouldContain_skill3() { Builder builder = VehicleRoutingProblem.Builder.newInstance(); Shipment s = Shipment.Builder.newInstance("1").addRequiredSkill("skill1").addRequiredSkill("Skill2").addRequiredSkill("skill3") - .addSizeDimension(0, 10) - .setPickupLocation(TestUtils.loc(Coordinate.newInstance(1, 2))) - .setDeliveryLocation(TestUtils.loc("delLoc", Coordinate.newInstance(5, 6))) - .setPickupTimeWindow(TimeWindow.newInstance(1, 2)) - .setDeliveryTimeWindow(TimeWindow.newInstance(3, 4)).setPickupServiceTime(100).setDeliveryServiceTime(50).build(); + .addSizeDimension(0, 10) + .setPickupLocation(TestUtils.loc(Coordinate.newInstance(1, 2))) + .setDeliveryLocation(TestUtils.loc("delLoc", Coordinate.newInstance(5, 6))) + .setPickupTimeWindow(TimeWindow.newInstance(1, 2)) + .setDeliveryTimeWindow(TimeWindow.newInstance(3, 4)).setPickupServiceTime(100).setDeliveryServiceTime(50).build(); VehicleRoutingProblem vrp = builder.addJob(s).build(); new VrpXMLWriter(vrp, null).write(infileName); @@ -541,111 +541,111 @@ public class VrpXMLWriterTest { } @Test - public void whenWritingShipments_readingThemAgainMustReturnTheWrittenLocationCoordinateOfS1(){ - Builder builder = VehicleRoutingProblem.Builder.newInstance(); - - VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType").addCapacityDimension(0, 20).build(); - VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("vehType2").addCapacityDimension(0, 200).build(); - VehicleImpl v1 = VehicleImpl.Builder.newInstance("v1").setStartLocation(TestUtils.loc("loc")).setType(type1).build(); - VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(TestUtils.loc("loc")).setType(type2).build(); - - builder.addVehicle(v1); - builder.addVehicle(v2); - - Shipment s1 = Shipment.Builder.newInstance("1").addSizeDimension(0, 10).setPickupLocation(TestUtils.loc(Coordinate.newInstance(1, 2))) - .setDeliveryLocation(TestUtils.loc("delLoc",Coordinate.newInstance(5, 6))) - .setPickupTimeWindow(TimeWindow.newInstance(1, 2)) - .setDeliveryTimeWindow(TimeWindow.newInstance(3, 4)).setPickupServiceTime(100).setDeliveryServiceTime(50).build(); - Shipment s2 = Shipment.Builder.newInstance("2").addSizeDimension(0, 20) - .setPickupLocation(Location.Builder.newInstance().setId("pickLocation").build()) - .setDeliveryLocation(TestUtils.loc("delLocation")) - .setPickupTimeWindow(TimeWindow.newInstance(5, 6)) - .setDeliveryTimeWindow(TimeWindow.newInstance(7, 8)).build(); - - - VehicleRoutingProblem vrp = builder.addJob(s1).addJob(s2).build(); - new VrpXMLWriter(vrp, null).write(infileName); - - VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpToReadBuilder, null).read(infileName); - VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); - assertEquals(2,readVrp.getJobs().size()); - - assertEquals(1.0,((Shipment)readVrp.getJobs().get("1")).getPickupLocation().getCoordinate().getX(),0.01); - assertEquals(2.0,((Shipment)readVrp.getJobs().get("1")).getPickupLocation().getCoordinate().getY(),0.01); - - assertEquals(5.0,((Shipment)readVrp.getJobs().get("1")).getDeliveryLocation().getCoordinate().getX(),0.01); - assertEquals(6.0,((Shipment)readVrp.getJobs().get("1")).getDeliveryLocation().getCoordinate().getY(),0.01); - } - - @Test - public void whenWritingShipmentWithSeveralCapacityDimension_itShouldWriteAndReadItCorrectly(){ - Builder builder = VehicleRoutingProblem.Builder.newInstance(); - - Shipment s1 = Shipment.Builder.newInstance("1") - .setPickupLocation(TestUtils.loc(Coordinate.newInstance(1, 2))) - .setDeliveryLocation(TestUtils.loc("delLoc",Coordinate.newInstance(5, 6))) - .setPickupTimeWindow(TimeWindow.newInstance(1, 2)) - .setDeliveryTimeWindow(TimeWindow.newInstance(3, 4)).setPickupServiceTime(100).setDeliveryServiceTime(50) - .addSizeDimension(0, 10) - .addSizeDimension(2, 100) - .build(); - - Shipment s2 = Shipment.Builder.newInstance("2").addSizeDimension(0, 20) - .setPickupLocation(Location.Builder.newInstance().setId("pickLocation").build()) - .setDeliveryLocation(TestUtils.loc("delLocation")).setPickupTimeWindow(TimeWindow.newInstance(5, 6)) - .setDeliveryTimeWindow(TimeWindow.newInstance(7, 8)).build(); - - VehicleRoutingProblem vrp = builder.addJob(s1).addJob(s2).build(); - new VrpXMLWriter(vrp, null).write(infileName); - - VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpToReadBuilder, null).read(infileName); - VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); - - assertEquals(3,(readVrp.getJobs().get("1")).getSize().getNuOfDimensions()); - assertEquals(10, (readVrp.getJobs().get("1")).getSize().get(0)); - assertEquals(0,(readVrp.getJobs().get("1")).getSize().get(1)); - assertEquals(100,(readVrp.getJobs().get("1")).getSize().get(2)); - - assertEquals(1,(readVrp.getJobs().get("2")).getSize().getNuOfDimensions()); - assertEquals(20,(readVrp.getJobs().get("2")).getSize().get(0)); - } - - @Test - public void whenWritingVehicleV1_itsStartLocationMustBeWrittenCorrectly(){ - Builder builder = VehicleRoutingProblem.Builder.newInstance(); - - VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType").addCapacityDimension(0, 20).build(); - VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("vehType2").addCapacityDimension(0, 200).build(); - VehicleImpl v1 = VehicleImpl.Builder.newInstance("v1").setStartLocation(TestUtils.loc("loc")).setType(type1).build(); - VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(TestUtils.loc("loc")).setType(type2).build(); - - builder.addVehicle(v1); - builder.addVehicle(v2); - - Service s1 = Service.Builder.newInstance("1").addSizeDimension(0, 1).setLocation(TestUtils.loc("loc")).setServiceTime(2.0).build(); - Service s2 = Service.Builder.newInstance("2").addSizeDimension(0, 1).setLocation(TestUtils.loc("loc2")).setServiceTime(4.0).build(); - - VehicleRoutingProblem vrp = builder.addJob(s1).addJob(s2).build(); - new VrpXMLWriter(vrp, null).write(infileName); - - VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpToReadBuilder, null).read(infileName); - VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); + public void whenWritingShipments_readingThemAgainMustReturnTheWrittenLocationCoordinateOfS1() { + Builder builder = VehicleRoutingProblem.Builder.newInstance(); - Vehicle v = getVehicle("v1",readVrp.getVehicles()); - assertEquals("loc",v.getStartLocation().getId()); - assertEquals("loc",v.getEndLocation().getId()); - - } + VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType").addCapacityDimension(0, 20).build(); + VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("vehType2").addCapacityDimension(0, 200).build(); + VehicleImpl v1 = VehicleImpl.Builder.newInstance("v1").setStartLocation(TestUtils.loc("loc")).setType(type1).build(); + VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(TestUtils.loc("loc")).setType(type2).build(); + + builder.addVehicle(v1); + builder.addVehicle(v2); + + Shipment s1 = Shipment.Builder.newInstance("1").addSizeDimension(0, 10).setPickupLocation(TestUtils.loc(Coordinate.newInstance(1, 2))) + .setDeliveryLocation(TestUtils.loc("delLoc", Coordinate.newInstance(5, 6))) + .setPickupTimeWindow(TimeWindow.newInstance(1, 2)) + .setDeliveryTimeWindow(TimeWindow.newInstance(3, 4)).setPickupServiceTime(100).setDeliveryServiceTime(50).build(); + Shipment s2 = Shipment.Builder.newInstance("2").addSizeDimension(0, 20) + .setPickupLocation(Location.Builder.newInstance().setId("pickLocation").build()) + .setDeliveryLocation(TestUtils.loc("delLocation")) + .setPickupTimeWindow(TimeWindow.newInstance(5, 6)) + .setDeliveryTimeWindow(TimeWindow.newInstance(7, 8)).build(); + + + VehicleRoutingProblem vrp = builder.addJob(s1).addJob(s2).build(); + new VrpXMLWriter(vrp, null).write(infileName); + + VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(vrpToReadBuilder, null).read(infileName); + VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); + assertEquals(2, readVrp.getJobs().size()); + + assertEquals(1.0, ((Shipment) readVrp.getJobs().get("1")).getPickupLocation().getCoordinate().getX(), 0.01); + assertEquals(2.0, ((Shipment) readVrp.getJobs().get("1")).getPickupLocation().getCoordinate().getY(), 0.01); + + assertEquals(5.0, ((Shipment) readVrp.getJobs().get("1")).getDeliveryLocation().getCoordinate().getX(), 0.01); + assertEquals(6.0, ((Shipment) readVrp.getJobs().get("1")).getDeliveryLocation().getCoordinate().getY(), 0.01); + } @Test - public void whenWritingService_itShouldHaveTheCorrectNuSkills(){ + public void whenWritingShipmentWithSeveralCapacityDimension_itShouldWriteAndReadItCorrectly() { + Builder builder = VehicleRoutingProblem.Builder.newInstance(); + + Shipment s1 = Shipment.Builder.newInstance("1") + .setPickupLocation(TestUtils.loc(Coordinate.newInstance(1, 2))) + .setDeliveryLocation(TestUtils.loc("delLoc", Coordinate.newInstance(5, 6))) + .setPickupTimeWindow(TimeWindow.newInstance(1, 2)) + .setDeliveryTimeWindow(TimeWindow.newInstance(3, 4)).setPickupServiceTime(100).setDeliveryServiceTime(50) + .addSizeDimension(0, 10) + .addSizeDimension(2, 100) + .build(); + + Shipment s2 = Shipment.Builder.newInstance("2").addSizeDimension(0, 20) + .setPickupLocation(Location.Builder.newInstance().setId("pickLocation").build()) + .setDeliveryLocation(TestUtils.loc("delLocation")).setPickupTimeWindow(TimeWindow.newInstance(5, 6)) + .setDeliveryTimeWindow(TimeWindow.newInstance(7, 8)).build(); + + VehicleRoutingProblem vrp = builder.addJob(s1).addJob(s2).build(); + new VrpXMLWriter(vrp, null).write(infileName); + + VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(vrpToReadBuilder, null).read(infileName); + VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); + + assertEquals(3, (readVrp.getJobs().get("1")).getSize().getNuOfDimensions()); + assertEquals(10, (readVrp.getJobs().get("1")).getSize().get(0)); + assertEquals(0, (readVrp.getJobs().get("1")).getSize().get(1)); + assertEquals(100, (readVrp.getJobs().get("1")).getSize().get(2)); + + assertEquals(1, (readVrp.getJobs().get("2")).getSize().getNuOfDimensions()); + assertEquals(20, (readVrp.getJobs().get("2")).getSize().get(0)); + } + + @Test + public void whenWritingVehicleV1_itsStartLocationMustBeWrittenCorrectly() { + Builder builder = VehicleRoutingProblem.Builder.newInstance(); + + VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType").addCapacityDimension(0, 20).build(); + VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("vehType2").addCapacityDimension(0, 200).build(); + VehicleImpl v1 = VehicleImpl.Builder.newInstance("v1").setStartLocation(TestUtils.loc("loc")).setType(type1).build(); + VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(TestUtils.loc("loc")).setType(type2).build(); + + builder.addVehicle(v1); + builder.addVehicle(v2); + + Service s1 = Service.Builder.newInstance("1").addSizeDimension(0, 1).setLocation(TestUtils.loc("loc")).setServiceTime(2.0).build(); + Service s2 = Service.Builder.newInstance("2").addSizeDimension(0, 1).setLocation(TestUtils.loc("loc2")).setServiceTime(4.0).build(); + + VehicleRoutingProblem vrp = builder.addJob(s1).addJob(s2).build(); + new VrpXMLWriter(vrp, null).write(infileName); + + VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(vrpToReadBuilder, null).read(infileName); + VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); + + Vehicle v = getVehicle("v1", readVrp.getVehicles()); + assertEquals("loc", v.getStartLocation().getId()); + assertEquals("loc", v.getEndLocation().getId()); + + } + + @Test + public void whenWritingService_itShouldHaveTheCorrectNuSkills() { Builder builder = VehicleRoutingProblem.Builder.newInstance(); Service s = Service.Builder.newInstance("1").addRequiredSkill("sKill1").addRequiredSkill("skill2").addSizeDimension(0, 1) - .setLocation(TestUtils.loc("loc")).setServiceTime(2.0).build(); + .setLocation(TestUtils.loc("loc")).setServiceTime(2.0).build(); VehicleRoutingProblem vrp = builder.addJob(s).build(); new VrpXMLWriter(vrp, null).write(infileName); @@ -654,15 +654,15 @@ public class VrpXMLWriterTest { new VrpXMLReader(vrpToReadBuilder, null).read(infileName); VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); - assertEquals(2,readVrp.getJobs().get("1").getRequiredSkills().values().size()); + assertEquals(2, readVrp.getJobs().get("1").getRequiredSkills().values().size()); } @Test - public void whenWritingService_itShouldContain_skill1(){ + public void whenWritingService_itShouldContain_skill1() { Builder builder = VehicleRoutingProblem.Builder.newInstance(); Service s = Service.Builder.newInstance("1").addRequiredSkill("sKill1").addRequiredSkill("skill2").addSizeDimension(0, 1) - .setLocation(TestUtils.loc("loc")).setServiceTime(2.0).build(); + .setLocation(TestUtils.loc("loc")).setServiceTime(2.0).build(); VehicleRoutingProblem vrp = builder.addJob(s).build(); new VrpXMLWriter(vrp, null).write(infileName); @@ -675,11 +675,11 @@ public class VrpXMLWriterTest { } @Test - public void whenWritingService_itShouldContain_skill2(){ + public void whenWritingService_itShouldContain_skill2() { Builder builder = VehicleRoutingProblem.Builder.newInstance(); Service s = Service.Builder.newInstance("1").addRequiredSkill("sKill1").addRequiredSkill("skill2").addSizeDimension(0, 1) - .setLocation(TestUtils.loc("loc")).setServiceTime(2.0).build(); + .setLocation(TestUtils.loc("loc")).setServiceTime(2.0).build(); VehicleRoutingProblem vrp = builder.addJob(s).build(); new VrpXMLWriter(vrp, null).write(infileName); @@ -690,276 +690,276 @@ public class VrpXMLWriterTest { assertTrue(readVrp.getJobs().get("1").getRequiredSkills().containsSkill("skill2")); } - - @Test - public void whenWritingVehicleV1_itDoesNotReturnToDepotMustBeWrittenCorrectly(){ - Builder builder = VehicleRoutingProblem.Builder.newInstance(); - - VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType").addCapacityDimension(0, 20).build(); - VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("vehType2").addCapacityDimension(0, 200).build(); - VehicleImpl v1 = VehicleImpl.Builder.newInstance("v1").setReturnToDepot(false).setStartLocation(TestUtils.loc("loc")) - .setType(type1).build(); - VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(TestUtils.loc("loc")).setType(type2).build(); - - builder.addVehicle(v1); - builder.addVehicle(v2); - - Service s1 = Service.Builder.newInstance("1").addSizeDimension(0, 1).setLocation(TestUtils.loc("loc")).setServiceTime(2.0).build(); - Service s2 = Service.Builder.newInstance("2").addSizeDimension(0, 1).setLocation(TestUtils.loc("loc2")).setServiceTime(4.0).build(); - - VehicleRoutingProblem vrp = builder.addJob(s1).addJob(s2).build(); - new VrpXMLWriter(vrp, null).write(infileName); - - VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpToReadBuilder, null).read(infileName); - VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); - - Vehicle v = getVehicle("v1",readVrp.getVehicles()); - assertFalse(v.isReturnToDepot()); - } - - @Test - public void whenWritingVehicleV1_readingAgainAssignsCorrectType(){ - Builder builder = VehicleRoutingProblem.Builder.newInstance(); - - VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType").addCapacityDimension(0, 20).build(); - VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("vehType2").addCapacityDimension(0, 200).build(); - VehicleImpl v1 = VehicleImpl.Builder.newInstance("v1").setReturnToDepot(false).setStartLocation(TestUtils.loc("loc")).setType(type1).build(); - VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(TestUtils.loc("loc")).setType(type2).build(); - - builder.addVehicle(v1); - builder.addVehicle(v2); - - Service s1 = Service.Builder.newInstance("1").addSizeDimension(0, 1).setLocation(TestUtils.loc("loc")).setServiceTime(2.0).build(); - Service s2 = Service.Builder.newInstance("2").addSizeDimension(0, 1).setLocation(TestUtils.loc("loc2")).setServiceTime(4.0).build(); - - VehicleRoutingProblem vrp = builder.addJob(s1).addJob(s2).build(); - new VrpXMLWriter(vrp, null).write(infileName); - - VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpToReadBuilder, null).read(infileName); - VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); - - Vehicle v = getVehicle("v1",readVrp.getVehicles()); - assertEquals("vehType",v.getType().getTypeId()); - } - - @Test - public void whenWritingVehicleV2_readingAgainAssignsCorrectType(){ - Builder builder = VehicleRoutingProblem.Builder.newInstance(); - - VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType").addCapacityDimension(0, 20).build(); - VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("vehType2").addCapacityDimension(0, 200).build(); - VehicleImpl v1 = VehicleImpl.Builder.newInstance("v1").setReturnToDepot(false).setStartLocation(TestUtils.loc("loc")).setType(type1).build(); - VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(TestUtils.loc("loc")).setType(type2).build(); - - builder.addVehicle(v1); - builder.addVehicle(v2); - - Service s1 = Service.Builder.newInstance("1").addSizeDimension(0, 1).setLocation(TestUtils.loc("loc")).setServiceTime(2.0).build(); - Service s2 = Service.Builder.newInstance("2").addSizeDimension(0, 1).setLocation(TestUtils.loc("loc2")).setServiceTime(4.0).build(); - - VehicleRoutingProblem vrp = builder.addJob(s1).addJob(s2).build(); - new VrpXMLWriter(vrp, null).write(infileName); - - VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpToReadBuilder, null).read(infileName); - VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); - - Vehicle v = getVehicle("v2",readVrp.getVehicles()); - assertEquals("vehType2",v.getType().getTypeId()); - assertEquals(200,v.getType().getCapacityDimensions().get(0)); - - } - - @Test - public void whenWritingVehicleV2_readingItsLocationsAgainReturnsCorrectLocations(){ - Builder builder = VehicleRoutingProblem.Builder.newInstance(); - - VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType").addCapacityDimension(0, 20).build(); - VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("vehType2").addCapacityDimension(0, 200).build(); - VehicleImpl v1 = VehicleImpl.Builder.newInstance("v1").setReturnToDepot(false).setStartLocation(TestUtils.loc("loc")).setType(type1).build(); - VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2") - .setStartLocation(TestUtils.loc("startLoc", Coordinate.newInstance(1, 2))) - .setEndLocation(TestUtils.loc("endLoc", Coordinate.newInstance(4, 5))).setType(type2).build(); - - builder.addVehicle(v1); - builder.addVehicle(v2); - - Service s1 = Service.Builder.newInstance("1").addSizeDimension(0, 1).setLocation(TestUtils.loc("loc")).setServiceTime(2.0).build(); - Service s2 = Service.Builder.newInstance("2").addSizeDimension(0, 1).setLocation(TestUtils.loc("loc2")).setServiceTime(4.0).build(); - - VehicleRoutingProblem vrp = builder.addJob(s1).addJob(s2).build(); - new VrpXMLWriter(vrp, null).write(infileName); - - VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpToReadBuilder, null).read(infileName); - VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); - - Vehicle v = getVehicle("v2",readVrp.getVehicles()); - assertEquals("startLoc",v.getStartLocation().getId()); - assertEquals("endLoc",v.getEndLocation().getId()); - } - - @Test - public void whenWritingVehicleV2_readingItsLocationsCoordsAgainReturnsCorrectLocationsCoords(){ - Builder builder = VehicleRoutingProblem.Builder.newInstance(); - - VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType").addCapacityDimension(0, 20).build(); - VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("vehType2").addCapacityDimension(0, 200).build(); - VehicleImpl v1 = VehicleImpl.Builder.newInstance("v1").setReturnToDepot(false) - .setStartLocation(TestUtils.loc("loc")).setType(type1).build(); - VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2") - .setStartLocation(TestUtils.loc("startLoc", Coordinate.newInstance(1, 2))) - .setEndLocation(TestUtils.loc("endLoc",Coordinate.newInstance(4, 5))).setType(type2).build(); - - builder.addVehicle(v1); - builder.addVehicle(v2); - - Service s1 = Service.Builder.newInstance("1").addSizeDimension(0, 1).setLocation(TestUtils.loc("loc")).setServiceTime(2.0).build(); - Service s2 = Service.Builder.newInstance("2").addSizeDimension(0, 1).setLocation(TestUtils.loc("loc2")).setServiceTime(4.0).build(); - - VehicleRoutingProblem vrp = builder.addJob(s1).addJob(s2).build(); - new VrpXMLWriter(vrp, null).write(infileName); - - VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpToReadBuilder, null).read(infileName); - VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); - - Vehicle v = getVehicle("v2",readVrp.getVehicles()); - assertEquals(1.0,v.getStartLocation().getCoordinate().getX(),0.01); - assertEquals(2.0,v.getStartLocation().getCoordinate().getY(),0.01); - - assertEquals(4.0,v.getEndLocation().getCoordinate().getX(),0.01); - assertEquals(5.0,v.getEndLocation().getCoordinate().getY(),0.01); - } - - @Test - public void whenWritingVehicleWithSeveralCapacityDimensions_itShouldBeWrittenAndRereadCorrectly(){ - Builder builder = VehicleRoutingProblem.Builder.newInstance(); - - VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("type") - .addCapacityDimension(0, 100) - .addCapacityDimension(1, 1000) - .addCapacityDimension(2, 10000) - .build(); - - VehicleImpl v2 = VehicleImpl.Builder.newInstance("v") - .setStartLocation(TestUtils.loc("startLoc",Coordinate.newInstance(1, 2))) - .setEndLocation(TestUtils.loc("endLoc", Coordinate.newInstance(4, 5))).setType(type2).build(); - builder.addVehicle(v2); - - VehicleRoutingProblem vrp = builder.build(); - new VrpXMLWriter(vrp, null).write(infileName); - - VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpToReadBuilder, null).read(infileName); - VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); - - Vehicle v = getVehicle("v",readVrp.getVehicles()); - assertEquals(3,v.getType().getCapacityDimensions().getNuOfDimensions()); - assertEquals(100,v.getType().getCapacityDimensions().get(0)); - assertEquals(1000,v.getType().getCapacityDimensions().get(1)); - assertEquals(10000,v.getType().getCapacityDimensions().get(2)); - } - - @Test - public void whenWritingVehicleWithSeveralCapacityDimensions_itShouldBeWrittenAndRereadCorrectlyV2(){ - Builder builder = VehicleRoutingProblem.Builder.newInstance(); - - VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("type") - .addCapacityDimension(0, 100) - .addCapacityDimension(1, 1000) - .addCapacityDimension(10, 10000) - .build(); - - VehicleImpl v2 = VehicleImpl.Builder.newInstance("v") - .setStartLocation(TestUtils.loc("startLoc",Coordinate.newInstance(1, 2))) - .setEndLocation(TestUtils.loc("endLoc", Coordinate.newInstance(4, 5))).setType(type2).build(); - builder.addVehicle(v2); - - VehicleRoutingProblem vrp = builder.build(); - new VrpXMLWriter(vrp, null).write(infileName); - - VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpToReadBuilder, null).read(infileName); - VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); - - Vehicle v = getVehicle("v",readVrp.getVehicles()); - assertEquals(11,v.getType().getCapacityDimensions().getNuOfDimensions()); - assertEquals(0,v.getType().getCapacityDimensions().get(9)); - assertEquals(10000,v.getType().getCapacityDimensions().get(10)); - } - - private Vehicle getVehicle(String string, Collection vehicles) { - for(Vehicle v : vehicles) if(string.equals(v.getId())) return v; - return null; - } - - @Test - public void whenWritingAndReadingInitialRouteWithShipment4_thisShipmentShouldNotAppearInJobMap(){ //since it is not part of the problem anymore - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder).read("src/test/resources/finiteVrpWithInitialSolutionForReaderTest.xml"); - VehicleRoutingProblem vrp = builder.build(); - - new VrpXMLWriter(vrp).write("src/test/resources/finiteVrpWithInitialSolutionForWriterTest.xml"); - - VehicleRoutingProblem.Builder newBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(newBuilder).read("src/test/resources/finiteVrpWithInitialSolutionForWriterTest.xml"); - VehicleRoutingProblem newVrp = newBuilder.build(); - - assertFalse(newVrp.getJobs().containsKey("4")); - } - - @Test - public void whenReadingInitialRouteWithDepTime10_departureTimeOfRouteShouldBeReadCorrectly(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder).read("src/test/resources/finiteVrpWithInitialSolutionForReaderTest.xml"); - VehicleRoutingProblem vrp = builder.build(); - - new VrpXMLWriter(vrp).write("src/test/resources/finiteVrpWithInitialSolutionForWriterTest.xml"); - - VehicleRoutingProblem.Builder newBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(newBuilder).read("src/test/resources/finiteVrpWithInitialSolutionForWriterTest.xml"); - VehicleRoutingProblem newVrp = newBuilder.build(); - - assertEquals(10.,newVrp.getInitialVehicleRoutes().iterator().next().getDepartureTime(),0.01); - } - - @Test - public void whenReadingInitialRoute_nuInitialRoutesShouldBeCorrect(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read("src/test/resources/finiteVrpWithInitialSolutionForReaderTest.xml"); - VehicleRoutingProblem vrp = builder.build(); - - new VrpXMLWriter(vrp).write("src/test/resources/finiteVrpWithInitialSolutionForWriterTest.xml"); - - VehicleRoutingProblem.Builder newBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(newBuilder).read("src/test/resources/finiteVrpWithInitialSolutionForWriterTest.xml"); - VehicleRoutingProblem newVrp = newBuilder.build(); - - - assertEquals(1,newVrp.getInitialVehicleRoutes().size()); - } - - @Test - public void whenReadingInitialRoute_nuActivitiesShouldBeCorrect(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read("src/test/resources/finiteVrpWithInitialSolutionForReaderTest.xml"); - VehicleRoutingProblem vrp = builder.build(); - - new VrpXMLWriter(vrp).write("src/test/resources/finiteVrpWithInitialSolutionForWriterTest.xml"); - - VehicleRoutingProblem.Builder newBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(newBuilder).read("src/test/resources/finiteVrpWithInitialSolutionForWriterTest.xml"); - VehicleRoutingProblem newVrp = newBuilder.build(); - - - assertEquals(2,newVrp.getInitialVehicleRoutes().iterator().next().getActivities().size()); - } @Test - public void solutionWithoutUnassignedJobsShouldBeWrittenCorrectly(){ + public void whenWritingVehicleV1_itDoesNotReturnToDepotMustBeWrittenCorrectly() { + Builder builder = VehicleRoutingProblem.Builder.newInstance(); + + VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType").addCapacityDimension(0, 20).build(); + VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("vehType2").addCapacityDimension(0, 200).build(); + VehicleImpl v1 = VehicleImpl.Builder.newInstance("v1").setReturnToDepot(false).setStartLocation(TestUtils.loc("loc")) + .setType(type1).build(); + VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(TestUtils.loc("loc")).setType(type2).build(); + + builder.addVehicle(v1); + builder.addVehicle(v2); + + Service s1 = Service.Builder.newInstance("1").addSizeDimension(0, 1).setLocation(TestUtils.loc("loc")).setServiceTime(2.0).build(); + Service s2 = Service.Builder.newInstance("2").addSizeDimension(0, 1).setLocation(TestUtils.loc("loc2")).setServiceTime(4.0).build(); + + VehicleRoutingProblem vrp = builder.addJob(s1).addJob(s2).build(); + new VrpXMLWriter(vrp, null).write(infileName); + + VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(vrpToReadBuilder, null).read(infileName); + VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); + + Vehicle v = getVehicle("v1", readVrp.getVehicles()); + assertFalse(v.isReturnToDepot()); + } + + @Test + public void whenWritingVehicleV1_readingAgainAssignsCorrectType() { + Builder builder = VehicleRoutingProblem.Builder.newInstance(); + + VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType").addCapacityDimension(0, 20).build(); + VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("vehType2").addCapacityDimension(0, 200).build(); + VehicleImpl v1 = VehicleImpl.Builder.newInstance("v1").setReturnToDepot(false).setStartLocation(TestUtils.loc("loc")).setType(type1).build(); + VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(TestUtils.loc("loc")).setType(type2).build(); + + builder.addVehicle(v1); + builder.addVehicle(v2); + + Service s1 = Service.Builder.newInstance("1").addSizeDimension(0, 1).setLocation(TestUtils.loc("loc")).setServiceTime(2.0).build(); + Service s2 = Service.Builder.newInstance("2").addSizeDimension(0, 1).setLocation(TestUtils.loc("loc2")).setServiceTime(4.0).build(); + + VehicleRoutingProblem vrp = builder.addJob(s1).addJob(s2).build(); + new VrpXMLWriter(vrp, null).write(infileName); + + VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(vrpToReadBuilder, null).read(infileName); + VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); + + Vehicle v = getVehicle("v1", readVrp.getVehicles()); + assertEquals("vehType", v.getType().getTypeId()); + } + + @Test + public void whenWritingVehicleV2_readingAgainAssignsCorrectType() { + Builder builder = VehicleRoutingProblem.Builder.newInstance(); + + VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType").addCapacityDimension(0, 20).build(); + VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("vehType2").addCapacityDimension(0, 200).build(); + VehicleImpl v1 = VehicleImpl.Builder.newInstance("v1").setReturnToDepot(false).setStartLocation(TestUtils.loc("loc")).setType(type1).build(); + VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(TestUtils.loc("loc")).setType(type2).build(); + + builder.addVehicle(v1); + builder.addVehicle(v2); + + Service s1 = Service.Builder.newInstance("1").addSizeDimension(0, 1).setLocation(TestUtils.loc("loc")).setServiceTime(2.0).build(); + Service s2 = Service.Builder.newInstance("2").addSizeDimension(0, 1).setLocation(TestUtils.loc("loc2")).setServiceTime(4.0).build(); + + VehicleRoutingProblem vrp = builder.addJob(s1).addJob(s2).build(); + new VrpXMLWriter(vrp, null).write(infileName); + + VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(vrpToReadBuilder, null).read(infileName); + VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); + + Vehicle v = getVehicle("v2", readVrp.getVehicles()); + assertEquals("vehType2", v.getType().getTypeId()); + assertEquals(200, v.getType().getCapacityDimensions().get(0)); + + } + + @Test + public void whenWritingVehicleV2_readingItsLocationsAgainReturnsCorrectLocations() { + Builder builder = VehicleRoutingProblem.Builder.newInstance(); + + VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType").addCapacityDimension(0, 20).build(); + VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("vehType2").addCapacityDimension(0, 200).build(); + VehicleImpl v1 = VehicleImpl.Builder.newInstance("v1").setReturnToDepot(false).setStartLocation(TestUtils.loc("loc")).setType(type1).build(); + VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2") + .setStartLocation(TestUtils.loc("startLoc", Coordinate.newInstance(1, 2))) + .setEndLocation(TestUtils.loc("endLoc", Coordinate.newInstance(4, 5))).setType(type2).build(); + + builder.addVehicle(v1); + builder.addVehicle(v2); + + Service s1 = Service.Builder.newInstance("1").addSizeDimension(0, 1).setLocation(TestUtils.loc("loc")).setServiceTime(2.0).build(); + Service s2 = Service.Builder.newInstance("2").addSizeDimension(0, 1).setLocation(TestUtils.loc("loc2")).setServiceTime(4.0).build(); + + VehicleRoutingProblem vrp = builder.addJob(s1).addJob(s2).build(); + new VrpXMLWriter(vrp, null).write(infileName); + + VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(vrpToReadBuilder, null).read(infileName); + VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); + + Vehicle v = getVehicle("v2", readVrp.getVehicles()); + assertEquals("startLoc", v.getStartLocation().getId()); + assertEquals("endLoc", v.getEndLocation().getId()); + } + + @Test + public void whenWritingVehicleV2_readingItsLocationsCoordsAgainReturnsCorrectLocationsCoords() { + Builder builder = VehicleRoutingProblem.Builder.newInstance(); + + VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType").addCapacityDimension(0, 20).build(); + VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("vehType2").addCapacityDimension(0, 200).build(); + VehicleImpl v1 = VehicleImpl.Builder.newInstance("v1").setReturnToDepot(false) + .setStartLocation(TestUtils.loc("loc")).setType(type1).build(); + VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2") + .setStartLocation(TestUtils.loc("startLoc", Coordinate.newInstance(1, 2))) + .setEndLocation(TestUtils.loc("endLoc", Coordinate.newInstance(4, 5))).setType(type2).build(); + + builder.addVehicle(v1); + builder.addVehicle(v2); + + Service s1 = Service.Builder.newInstance("1").addSizeDimension(0, 1).setLocation(TestUtils.loc("loc")).setServiceTime(2.0).build(); + Service s2 = Service.Builder.newInstance("2").addSizeDimension(0, 1).setLocation(TestUtils.loc("loc2")).setServiceTime(4.0).build(); + + VehicleRoutingProblem vrp = builder.addJob(s1).addJob(s2).build(); + new VrpXMLWriter(vrp, null).write(infileName); + + VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(vrpToReadBuilder, null).read(infileName); + VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); + + Vehicle v = getVehicle("v2", readVrp.getVehicles()); + assertEquals(1.0, v.getStartLocation().getCoordinate().getX(), 0.01); + assertEquals(2.0, v.getStartLocation().getCoordinate().getY(), 0.01); + + assertEquals(4.0, v.getEndLocation().getCoordinate().getX(), 0.01); + assertEquals(5.0, v.getEndLocation().getCoordinate().getY(), 0.01); + } + + @Test + public void whenWritingVehicleWithSeveralCapacityDimensions_itShouldBeWrittenAndRereadCorrectly() { + Builder builder = VehicleRoutingProblem.Builder.newInstance(); + + VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("type") + .addCapacityDimension(0, 100) + .addCapacityDimension(1, 1000) + .addCapacityDimension(2, 10000) + .build(); + + VehicleImpl v2 = VehicleImpl.Builder.newInstance("v") + .setStartLocation(TestUtils.loc("startLoc", Coordinate.newInstance(1, 2))) + .setEndLocation(TestUtils.loc("endLoc", Coordinate.newInstance(4, 5))).setType(type2).build(); + builder.addVehicle(v2); + + VehicleRoutingProblem vrp = builder.build(); + new VrpXMLWriter(vrp, null).write(infileName); + + VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(vrpToReadBuilder, null).read(infileName); + VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); + + Vehicle v = getVehicle("v", readVrp.getVehicles()); + assertEquals(3, v.getType().getCapacityDimensions().getNuOfDimensions()); + assertEquals(100, v.getType().getCapacityDimensions().get(0)); + assertEquals(1000, v.getType().getCapacityDimensions().get(1)); + assertEquals(10000, v.getType().getCapacityDimensions().get(2)); + } + + @Test + public void whenWritingVehicleWithSeveralCapacityDimensions_itShouldBeWrittenAndRereadCorrectlyV2() { + Builder builder = VehicleRoutingProblem.Builder.newInstance(); + + VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("type") + .addCapacityDimension(0, 100) + .addCapacityDimension(1, 1000) + .addCapacityDimension(10, 10000) + .build(); + + VehicleImpl v2 = VehicleImpl.Builder.newInstance("v") + .setStartLocation(TestUtils.loc("startLoc", Coordinate.newInstance(1, 2))) + .setEndLocation(TestUtils.loc("endLoc", Coordinate.newInstance(4, 5))).setType(type2).build(); + builder.addVehicle(v2); + + VehicleRoutingProblem vrp = builder.build(); + new VrpXMLWriter(vrp, null).write(infileName); + + VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(vrpToReadBuilder, null).read(infileName); + VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); + + Vehicle v = getVehicle("v", readVrp.getVehicles()); + assertEquals(11, v.getType().getCapacityDimensions().getNuOfDimensions()); + assertEquals(0, v.getType().getCapacityDimensions().get(9)); + assertEquals(10000, v.getType().getCapacityDimensions().get(10)); + } + + private Vehicle getVehicle(String string, Collection vehicles) { + for (Vehicle v : vehicles) if (string.equals(v.getId())) return v; + return null; + } + + @Test + public void whenWritingAndReadingInitialRouteWithShipment4_thisShipmentShouldNotAppearInJobMap() { //since it is not part of the problem anymore + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(builder).read("src/test/resources/finiteVrpWithInitialSolutionForReaderTest.xml"); + VehicleRoutingProblem vrp = builder.build(); + + new VrpXMLWriter(vrp).write("src/test/resources/finiteVrpWithInitialSolutionForWriterTest.xml"); + + VehicleRoutingProblem.Builder newBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(newBuilder).read("src/test/resources/finiteVrpWithInitialSolutionForWriterTest.xml"); + VehicleRoutingProblem newVrp = newBuilder.build(); + + assertFalse(newVrp.getJobs().containsKey("4")); + } + + @Test + public void whenReadingInitialRouteWithDepTime10_departureTimeOfRouteShouldBeReadCorrectly() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(builder).read("src/test/resources/finiteVrpWithInitialSolutionForReaderTest.xml"); + VehicleRoutingProblem vrp = builder.build(); + + new VrpXMLWriter(vrp).write("src/test/resources/finiteVrpWithInitialSolutionForWriterTest.xml"); + + VehicleRoutingProblem.Builder newBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(newBuilder).read("src/test/resources/finiteVrpWithInitialSolutionForWriterTest.xml"); + VehicleRoutingProblem newVrp = newBuilder.build(); + + assertEquals(10., newVrp.getInitialVehicleRoutes().iterator().next().getDepartureTime(), 0.01); + } + + @Test + public void whenReadingInitialRoute_nuInitialRoutesShouldBeCorrect() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(builder, null).read("src/test/resources/finiteVrpWithInitialSolutionForReaderTest.xml"); + VehicleRoutingProblem vrp = builder.build(); + + new VrpXMLWriter(vrp).write("src/test/resources/finiteVrpWithInitialSolutionForWriterTest.xml"); + + VehicleRoutingProblem.Builder newBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(newBuilder).read("src/test/resources/finiteVrpWithInitialSolutionForWriterTest.xml"); + VehicleRoutingProblem newVrp = newBuilder.build(); + + + assertEquals(1, newVrp.getInitialVehicleRoutes().size()); + } + + @Test + public void whenReadingInitialRoute_nuActivitiesShouldBeCorrect() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(builder, null).read("src/test/resources/finiteVrpWithInitialSolutionForReaderTest.xml"); + VehicleRoutingProblem vrp = builder.build(); + + new VrpXMLWriter(vrp).write("src/test/resources/finiteVrpWithInitialSolutionForWriterTest.xml"); + + VehicleRoutingProblem.Builder newBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(newBuilder).read("src/test/resources/finiteVrpWithInitialSolutionForWriterTest.xml"); + VehicleRoutingProblem newVrp = newBuilder.build(); + + + assertEquals(2, newVrp.getInitialVehicleRoutes().iterator().next().getActivities().size()); + } + + @Test + public void solutionWithoutUnassignedJobsShouldBeWrittenCorrectly() { Builder builder = VehicleRoutingProblem.Builder.newInstance(); VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType").addCapacityDimension(0, 20).build(); @@ -974,7 +974,7 @@ public class VrpXMLWriterTest { VehicleRoute route = VehicleRoute.Builder.newInstance(v1).addService(s1).addService(s2).build(); List routes = new ArrayList(); routes.add(route); - VehicleRoutingProblemSolution solution = new VehicleRoutingProblemSolution(routes,10.); + VehicleRoutingProblemSolution solution = new VehicleRoutingProblemSolution(routes, 10.); List solutions = new ArrayList(); solutions.add(solution); @@ -985,12 +985,12 @@ public class VrpXMLWriterTest { new VrpXMLReader(vrpToReadBuilder, solutionsToRead).read(infileName); assertEquals(1, solutionsToRead.size()); - assertEquals(10., Solutions.bestOf(solutionsToRead).getCost(),0.01); + assertEquals(10., Solutions.bestOf(solutionsToRead).getCost(), 0.01); assertTrue(Solutions.bestOf(solutionsToRead).getUnassignedJobs().isEmpty()); } @Test - public void solutionWithUnassignedJobsShouldBeWrittenCorrectly(){ + public void solutionWithUnassignedJobsShouldBeWrittenCorrectly() { Builder builder = VehicleRoutingProblem.Builder.newInstance(); VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType").addCapacityDimension(0, 20).build(); @@ -1005,7 +1005,7 @@ public class VrpXMLWriterTest { VehicleRoute route = VehicleRoute.Builder.newInstance(v1).addService(s1).build(); List routes = new ArrayList(); routes.add(route); - VehicleRoutingProblemSolution solution = new VehicleRoutingProblemSolution(routes,10.); + VehicleRoutingProblemSolution solution = new VehicleRoutingProblemSolution(routes, 10.); solution.getUnassignedJobs().add(s2); List solutions = new ArrayList(); solutions.add(solution); @@ -1017,7 +1017,7 @@ public class VrpXMLWriterTest { new VrpXMLReader(vrpToReadBuilder, solutionsToRead).read(infileName); assertEquals(1, solutionsToRead.size()); - assertEquals(10., Solutions.bestOf(solutionsToRead).getCost(),0.01); + assertEquals(10., Solutions.bestOf(solutionsToRead).getCost(), 0.01); assertEquals(1, Solutions.bestOf(solutionsToRead).getUnassignedJobs().size()); assertEquals("2", Solutions.bestOf(solutionsToRead).getUnassignedJobs().iterator().next().getId()); } diff --git a/jsprit-core/src/test/java/jsprit/core/problem/job/DeliveryTest.java b/jsprit-core/src/test/java/jsprit/core/problem/job/DeliveryTest.java index 6019060d..cf15491f 100644 --- a/jsprit-core/src/test/java/jsprit/core/problem/job/DeliveryTest.java +++ b/jsprit-core/src/test/java/jsprit/core/problem/job/DeliveryTest.java @@ -22,68 +22,68 @@ import org.junit.Test; import static org.junit.Assert.*; public class DeliveryTest { - - @Test(expected=IllegalStateException.class) - public void whenNeitherLocationIdNorCoordIsSet_itThrowsException(){ - Delivery.Builder.newInstance("p").build(); - } - - @Test - public void whenAddingTwoCapDimension_nuOfDimsShouldBeTwo(){ - Delivery one = (Delivery)Delivery.Builder.newInstance("s").setLocation(Location.newInstance("foofoo")) - .addSizeDimension(0, 2) - .addSizeDimension(1, 4) - .build(); - assertEquals(2,one.getSize().getNuOfDimensions()); - assertEquals(2,one.getSize().get(0)); - assertEquals(4,one.getSize().get(1)); - - } - - @Test - public void whenPickupIsBuiltWithoutSpecifyingCapacity_itShouldHvCapWithOneDimAndDimValOfZero(){ - Delivery one = (Delivery)Delivery.Builder.newInstance("s").setLocation(Location.newInstance("foofoo")) - .build(); - assertEquals(1,one.getSize().getNuOfDimensions()); - assertEquals(0,one.getSize().get(0)); - } - - @Test - public void whenPickupIsBuiltWithConstructorWhereSizeIsSpecified_capacityShouldBeSetCorrectly(){ - Delivery one = (Delivery)Delivery.Builder.newInstance("s").addSizeDimension(0, 1).setLocation(Location.newInstance("foofoo")) - .build(); - assertEquals(1,one.getSize().getNuOfDimensions()); - assertEquals(1,one.getSize().get(0)); - } - - @Test - public void whenAddingSkills_theyShouldBeAddedCorrectly(){ - Delivery s = (Delivery) Delivery.Builder.newInstance("s").setLocation(Location.newInstance("loc")) - .addRequiredSkill("drill").addRequiredSkill("screwdriver").build(); - assertTrue(s.getRequiredSkills().containsSkill("drill")); - assertTrue(s.getRequiredSkills().containsSkill("ScrewDriver")); - } - - @Test - public void whenAddingSkillsCaseSens_theyShouldBeAddedCorrectly(){ - Delivery s = (Delivery) Delivery.Builder.newInstance("s").setLocation(Location.newInstance("loc")) - .addRequiredSkill("DriLl").addRequiredSkill("screwDriver").build(); - assertTrue(s.getRequiredSkills().containsSkill("drill")); - assertTrue(s.getRequiredSkills().containsSkill("drilL")); - } + + @Test(expected = IllegalStateException.class) + public void whenNeitherLocationIdNorCoordIsSet_itThrowsException() { + Delivery.Builder.newInstance("p").build(); + } @Test - public void whenAddingSkillsCaseSensV2_theyShouldBeAddedCorrectly(){ + public void whenAddingTwoCapDimension_nuOfDimsShouldBeTwo() { + Delivery one = (Delivery) Delivery.Builder.newInstance("s").setLocation(Location.newInstance("foofoo")) + .addSizeDimension(0, 2) + .addSizeDimension(1, 4) + .build(); + assertEquals(2, one.getSize().getNuOfDimensions()); + assertEquals(2, one.getSize().get(0)); + assertEquals(4, one.getSize().get(1)); + + } + + @Test + public void whenPickupIsBuiltWithoutSpecifyingCapacity_itShouldHvCapWithOneDimAndDimValOfZero() { + Delivery one = (Delivery) Delivery.Builder.newInstance("s").setLocation(Location.newInstance("foofoo")) + .build(); + assertEquals(1, one.getSize().getNuOfDimensions()); + assertEquals(0, one.getSize().get(0)); + } + + @Test + public void whenPickupIsBuiltWithConstructorWhereSizeIsSpecified_capacityShouldBeSetCorrectly() { + Delivery one = (Delivery) Delivery.Builder.newInstance("s").addSizeDimension(0, 1).setLocation(Location.newInstance("foofoo")) + .build(); + assertEquals(1, one.getSize().getNuOfDimensions()); + assertEquals(1, one.getSize().get(0)); + } + + @Test + public void whenAddingSkills_theyShouldBeAddedCorrectly() { Delivery s = (Delivery) Delivery.Builder.newInstance("s").setLocation(Location.newInstance("loc")) - .addRequiredSkill("screwDriver").build(); + .addRequiredSkill("drill").addRequiredSkill("screwdriver").build(); + assertTrue(s.getRequiredSkills().containsSkill("drill")); + assertTrue(s.getRequiredSkills().containsSkill("ScrewDriver")); + } + + @Test + public void whenAddingSkillsCaseSens_theyShouldBeAddedCorrectly() { + Delivery s = (Delivery) Delivery.Builder.newInstance("s").setLocation(Location.newInstance("loc")) + .addRequiredSkill("DriLl").addRequiredSkill("screwDriver").build(); + assertTrue(s.getRequiredSkills().containsSkill("drill")); + assertTrue(s.getRequiredSkills().containsSkill("drilL")); + } + + @Test + public void whenAddingSkillsCaseSensV2_theyShouldBeAddedCorrectly() { + Delivery s = (Delivery) Delivery.Builder.newInstance("s").setLocation(Location.newInstance("loc")) + .addRequiredSkill("screwDriver").build(); assertFalse(s.getRequiredSkills().containsSkill("drill")); assertFalse(s.getRequiredSkills().containsSkill("drilL")); } @Test - public void nameShouldBeAssigned(){ + public void nameShouldBeAssigned() { Delivery s = (Delivery) Delivery.Builder.newInstance("s").setLocation(Location.newInstance("loc")) - .setName("name").build(); + .setName("name").build(); assertEquals("name", s.getName()); } diff --git a/jsprit-core/src/test/java/jsprit/core/problem/job/PickupTest.java b/jsprit-core/src/test/java/jsprit/core/problem/job/PickupTest.java index 09b95f92..ad8bfbb5 100644 --- a/jsprit-core/src/test/java/jsprit/core/problem/job/PickupTest.java +++ b/jsprit-core/src/test/java/jsprit/core/problem/job/PickupTest.java @@ -22,70 +22,70 @@ import org.junit.Test; import static org.junit.Assert.*; public class PickupTest { - - @Test(expected=IllegalStateException.class) - public void whenNeitherLocationIdNorCoordIsSet_itThrowsException(){ - Pickup.Builder.newInstance("p").build(); - } - - @Test - public void whenAddingTwoCapDimension_nuOfDimsShouldBeTwo(){ - Pickup one = (Pickup)Pickup.Builder.newInstance("s").setLocation(Location.newInstance("foofoo")) - .addSizeDimension(0, 2) - .addSizeDimension(1, 4) - .build(); - assertEquals(2,one.getSize().getNuOfDimensions()); - assertEquals(2,one.getSize().get(0)); - assertEquals(4,one.getSize().get(1)); - - } - - @Test - public void whenPickupIsBuiltWithoutSpecifyingCapacity_itShouldHvCapWithOneDimAndDimValOfZero(){ - Pickup one = (Pickup)Pickup.Builder.newInstance("s").setLocation(Location.newInstance("foofoo")) - .build(); - assertEquals(1,one.getSize().getNuOfDimensions()); - assertEquals(0,one.getSize().get(0)); - } - - @Test - public void whenPickupIsBuiltWithConstructorWhereSizeIsSpecified_capacityShouldBeSetCorrectly(){ - Pickup one = (Pickup)Pickup.Builder.newInstance("s").addSizeDimension(0, 1).setLocation(Location.newInstance("foofoo")) - .build(); - assertEquals(1,one.getSize().getNuOfDimensions()); - assertEquals(1,one.getSize().get(0)); - } - - @Test - public void whenAddingSkills_theyShouldBeAddedCorrectly(){ - Pickup s = (Pickup) Pickup.Builder.newInstance("s").setLocation(Location.newInstance("loc")) - .addRequiredSkill("drill").addRequiredSkill("screwdriver").build(); - assertTrue(s.getRequiredSkills().containsSkill("drill")); - assertTrue(s.getRequiredSkills().containsSkill("drill")); - assertTrue(s.getRequiredSkills().containsSkill("ScrewDriver")); - } - - @Test - public void whenAddingSkillsCaseSens_theyShouldBeAddedCorrectly(){ - Pickup s = (Pickup) Pickup.Builder.newInstance("s").setLocation(Location.newInstance("loc")) - .addRequiredSkill("DriLl").addRequiredSkill("screwDriver").build(); - assertTrue(s.getRequiredSkills().containsSkill("drill")); - assertTrue(s.getRequiredSkills().containsSkill("drilL")); - } + + @Test(expected = IllegalStateException.class) + public void whenNeitherLocationIdNorCoordIsSet_itThrowsException() { + Pickup.Builder.newInstance("p").build(); + } @Test - public void whenAddingSkillsCaseSensV2_theyShouldBeAddedCorrectly(){ + public void whenAddingTwoCapDimension_nuOfDimsShouldBeTwo() { + Pickup one = (Pickup) Pickup.Builder.newInstance("s").setLocation(Location.newInstance("foofoo")) + .addSizeDimension(0, 2) + .addSizeDimension(1, 4) + .build(); + assertEquals(2, one.getSize().getNuOfDimensions()); + assertEquals(2, one.getSize().get(0)); + assertEquals(4, one.getSize().get(1)); + + } + + @Test + public void whenPickupIsBuiltWithoutSpecifyingCapacity_itShouldHvCapWithOneDimAndDimValOfZero() { + Pickup one = (Pickup) Pickup.Builder.newInstance("s").setLocation(Location.newInstance("foofoo")) + .build(); + assertEquals(1, one.getSize().getNuOfDimensions()); + assertEquals(0, one.getSize().get(0)); + } + + @Test + public void whenPickupIsBuiltWithConstructorWhereSizeIsSpecified_capacityShouldBeSetCorrectly() { + Pickup one = (Pickup) Pickup.Builder.newInstance("s").addSizeDimension(0, 1).setLocation(Location.newInstance("foofoo")) + .build(); + assertEquals(1, one.getSize().getNuOfDimensions()); + assertEquals(1, one.getSize().get(0)); + } + + @Test + public void whenAddingSkills_theyShouldBeAddedCorrectly() { Pickup s = (Pickup) Pickup.Builder.newInstance("s").setLocation(Location.newInstance("loc")) - .addRequiredSkill("screwDriver").build(); + .addRequiredSkill("drill").addRequiredSkill("screwdriver").build(); + assertTrue(s.getRequiredSkills().containsSkill("drill")); + assertTrue(s.getRequiredSkills().containsSkill("drill")); + assertTrue(s.getRequiredSkills().containsSkill("ScrewDriver")); + } + + @Test + public void whenAddingSkillsCaseSens_theyShouldBeAddedCorrectly() { + Pickup s = (Pickup) Pickup.Builder.newInstance("s").setLocation(Location.newInstance("loc")) + .addRequiredSkill("DriLl").addRequiredSkill("screwDriver").build(); + assertTrue(s.getRequiredSkills().containsSkill("drill")); + assertTrue(s.getRequiredSkills().containsSkill("drilL")); + } + + @Test + public void whenAddingSkillsCaseSensV2_theyShouldBeAddedCorrectly() { + Pickup s = (Pickup) Pickup.Builder.newInstance("s").setLocation(Location.newInstance("loc")) + .addRequiredSkill("screwDriver").build(); assertFalse(s.getRequiredSkills().containsSkill("drill")); assertFalse(s.getRequiredSkills().containsSkill("drilL")); } @Test - public void nameShouldBeAssigned(){ + public void nameShouldBeAssigned() { Pickup s = (Pickup) Pickup.Builder.newInstance("s").setLocation(Location.newInstance("loc")) - .setName("name").build(); - assertEquals("name",s.getName()); + .setName("name").build(); + assertEquals("name", s.getName()); } diff --git a/jsprit-core/src/test/java/jsprit/core/problem/job/ServiceTest.java b/jsprit-core/src/test/java/jsprit/core/problem/job/ServiceTest.java index 91c017ac..c519b351 100644 --- a/jsprit-core/src/test/java/jsprit/core/problem/job/ServiceTest.java +++ b/jsprit-core/src/test/java/jsprit/core/problem/job/ServiceTest.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.problem.job; @@ -26,162 +26,162 @@ import java.util.Set; import static org.junit.Assert.*; public class ServiceTest { - - @Test - public void whenTwoServicesHaveTheSameId_theirReferencesShouldBeUnEqual(){ - Service one = Service.Builder.newInstance("service").addSizeDimension(0, 10).setLocation(Location.newInstance("foo")).build(); - Service two = Service.Builder.newInstance("service").addSizeDimension(0, 10).setLocation(Location.newInstance("fo")).build(); - - assertTrue(one != two); - } - - @Test - public void whenTwoServicesHaveTheSameId_theyShouldBeEqual(){ - Service one = Service.Builder.newInstance("service").addSizeDimension(0, 10).setLocation(Location.newInstance("foo")).build(); - Service two = Service.Builder.newInstance("service").addSizeDimension(0, 10).setLocation(Location.newInstance("fo")).build(); - - assertTrue(one.equals(two)); - } - - @Test - public void noName(){ - Set serviceSet = new HashSet(); - Service one = Service.Builder.newInstance("service").addSizeDimension(0, 10).setLocation(Location.newInstance("foo")).build(); - Service two = Service.Builder.newInstance("service").addSizeDimension(0, 10).setLocation(Location.newInstance("fo")).build(); - serviceSet.add(one); -// assertTrue(serviceSet.contains(two)); - serviceSet.remove(two); - assertTrue(serviceSet.isEmpty()); - } - - @Test(expected=IllegalArgumentException.class) - public void whenCapacityDimValueIsNegative_throwIllegalStateExpception(){ - @SuppressWarnings("unused") - Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("foo")).addSizeDimension(0, -10).build(); - } - - @Test - public void whenAddingTwoCapDimension_nuOfDimsShouldBeTwo(){ - Service one = Service.Builder.newInstance("s").setLocation(Location.newInstance("foofoo")) - .addSizeDimension(0,2) - .addSizeDimension(1,4) - .build(); - assertEquals(2,one.getSize().getNuOfDimensions()); - } - - @Test - public void whenShipmentIsBuiltWithoutSpecifyingCapacity_itShouldHvCapWithOneDimAndDimValOfZero(){ - Service one = Service.Builder.newInstance("s").setLocation(Location.newInstance("foofoo")) - .build(); - assertEquals(1,one.getSize().getNuOfDimensions()); - assertEquals(0,one.getSize().get(0)); - } - - @Test - public void whenShipmentIsBuiltWithConstructorWhereSizeIsSpecified_capacityShouldBeSetCorrectly(){ - Service one = Service.Builder.newInstance("s").addSizeDimension(0, 1).setLocation(Location.newInstance("foofoo")) - .build(); - assertEquals(1,one.getSize().getNuOfDimensions()); - assertEquals(1,one.getSize().get(0)); - } - - @Test - public void whenCallingForNewInstanceOfBuilder_itShouldReturnBuilderCorrectly(){ - Service.Builder builder = Service.Builder.newInstance("s"); - assertNotNull(builder); - } - - @Test - public void whenSettingNoType_itShouldReturn_service(){ - Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")).build(); - assertEquals("service",s.getType()); - } - - @Test - public void whenSettingLocation_itShouldBeSetCorrectly(){ - Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")).build(); - assertEquals("loc",s.getLocation().getId()); - assertEquals("loc",s.getLocation().getId()); - } @Test - public void whenSettingLocation_itShouldWork(){ - Service s = Service.Builder.newInstance("s").setLocation(Location.Builder.newInstance().setId("loc").build()).build(); - assertEquals("loc",s.getLocation().getId()); - assertEquals("loc",s.getLocation().getId()); + public void whenTwoServicesHaveTheSameId_theirReferencesShouldBeUnEqual() { + Service one = Service.Builder.newInstance("service").addSizeDimension(0, 10).setLocation(Location.newInstance("foo")).build(); + Service two = Service.Builder.newInstance("service").addSizeDimension(0, 10).setLocation(Location.newInstance("fo")).build(); + + assertTrue(one != two); } - - @Test - public void whenSettingLocationCoord_itShouldBeSetCorrectly(){ - Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance(1, 2)).build(); - assertEquals(1.0,s.getLocation().getCoordinate().getX(),0.01); - assertEquals(2.0,s.getLocation().getCoordinate().getY(),0.01); - assertEquals(1.0,s.getLocation().getCoordinate().getX(),0.01); - assertEquals(2.0,s.getLocation().getCoordinate().getY(),0.01); - } - - @Test(expected=IllegalStateException.class) - public void whenSettingNeitherLocationIdNorCoord_throwsException(){ - @SuppressWarnings("unused") - Service s = Service.Builder.newInstance("s").build(); - } - - @Test(expected=IllegalArgumentException.class) - public void whenServiceTimeSmallerZero_throwIllegalStateException(){ - @SuppressWarnings("unused") - Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")).setServiceTime(-1).build(); - } - - @Test - public void whenSettingServiceTime_itShouldBeSetCorrectly(){ - Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")).setServiceTime(1).build(); - assertEquals(1.0,s.getServiceDuration(),0.01); - } - - @Test(expected=IllegalArgumentException.class) - public void whenTimeWindowIsNull_throwException(){ - @SuppressWarnings("unused") - Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")).setTimeWindow(null).build(); - } - - @Test - public void whenSettingTimeWindow_itShouldBeSetCorrectly(){ - Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")).setTimeWindow(TimeWindow.newInstance(1.0, 2.0)).build(); - assertEquals(1.0,s.getTimeWindow().getStart(),0.01); - assertEquals(2.0,s.getTimeWindow().getEnd(),0.01); - } - - @Test - public void whenAddingSkills_theyShouldBeAddedCorrectly(){ - Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")) - .addRequiredSkill("drill").addRequiredSkill("screwdriver").build(); - assertTrue(s.getRequiredSkills().containsSkill("drill")); - assertTrue(s.getRequiredSkills().containsSkill("drill")); - assertTrue(s.getRequiredSkills().containsSkill("ScrewDriver")); - } - - @Test - public void whenAddingSkillsCaseSens_theyShouldBeAddedCorrectly(){ - Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")) - .addRequiredSkill("DriLl").addRequiredSkill("screwDriver").build(); - assertTrue(s.getRequiredSkills().containsSkill("drill")); - assertTrue(s.getRequiredSkills().containsSkill("drilL")); - } + @Test + public void whenTwoServicesHaveTheSameId_theyShouldBeEqual() { + Service one = Service.Builder.newInstance("service").addSizeDimension(0, 10).setLocation(Location.newInstance("foo")).build(); + Service two = Service.Builder.newInstance("service").addSizeDimension(0, 10).setLocation(Location.newInstance("fo")).build(); + + assertTrue(one.equals(two)); + } @Test - public void whenAddingSkillsCaseSensV2_theyShouldBeAddedCorrectly(){ - Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")) - .addRequiredSkill("screwDriver").build(); + public void noName() { + Set serviceSet = new HashSet(); + Service one = Service.Builder.newInstance("service").addSizeDimension(0, 10).setLocation(Location.newInstance("foo")).build(); + Service two = Service.Builder.newInstance("service").addSizeDimension(0, 10).setLocation(Location.newInstance("fo")).build(); + serviceSet.add(one); +// assertTrue(serviceSet.contains(two)); + serviceSet.remove(two); + assertTrue(serviceSet.isEmpty()); + } + + @Test(expected = IllegalArgumentException.class) + public void whenCapacityDimValueIsNegative_throwIllegalStateExpception() { + @SuppressWarnings("unused") + Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("foo")).addSizeDimension(0, -10).build(); + } + + @Test + public void whenAddingTwoCapDimension_nuOfDimsShouldBeTwo() { + Service one = Service.Builder.newInstance("s").setLocation(Location.newInstance("foofoo")) + .addSizeDimension(0, 2) + .addSizeDimension(1, 4) + .build(); + assertEquals(2, one.getSize().getNuOfDimensions()); + } + + @Test + public void whenShipmentIsBuiltWithoutSpecifyingCapacity_itShouldHvCapWithOneDimAndDimValOfZero() { + Service one = Service.Builder.newInstance("s").setLocation(Location.newInstance("foofoo")) + .build(); + assertEquals(1, one.getSize().getNuOfDimensions()); + assertEquals(0, one.getSize().get(0)); + } + + @Test + public void whenShipmentIsBuiltWithConstructorWhereSizeIsSpecified_capacityShouldBeSetCorrectly() { + Service one = Service.Builder.newInstance("s").addSizeDimension(0, 1).setLocation(Location.newInstance("foofoo")) + .build(); + assertEquals(1, one.getSize().getNuOfDimensions()); + assertEquals(1, one.getSize().get(0)); + } + + @Test + public void whenCallingForNewInstanceOfBuilder_itShouldReturnBuilderCorrectly() { + Service.Builder builder = Service.Builder.newInstance("s"); + assertNotNull(builder); + } + + @Test + public void whenSettingNoType_itShouldReturn_service() { + Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")).build(); + assertEquals("service", s.getType()); + } + + @Test + public void whenSettingLocation_itShouldBeSetCorrectly() { + Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")).build(); + assertEquals("loc", s.getLocation().getId()); + assertEquals("loc", s.getLocation().getId()); + } + + @Test + public void whenSettingLocation_itShouldWork() { + Service s = Service.Builder.newInstance("s").setLocation(Location.Builder.newInstance().setId("loc").build()).build(); + assertEquals("loc", s.getLocation().getId()); + assertEquals("loc", s.getLocation().getId()); + } + + + @Test + public void whenSettingLocationCoord_itShouldBeSetCorrectly() { + Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance(1, 2)).build(); + assertEquals(1.0, s.getLocation().getCoordinate().getX(), 0.01); + assertEquals(2.0, s.getLocation().getCoordinate().getY(), 0.01); + assertEquals(1.0, s.getLocation().getCoordinate().getX(), 0.01); + assertEquals(2.0, s.getLocation().getCoordinate().getY(), 0.01); + } + + @Test(expected = IllegalStateException.class) + public void whenSettingNeitherLocationIdNorCoord_throwsException() { + @SuppressWarnings("unused") + Service s = Service.Builder.newInstance("s").build(); + } + + @Test(expected = IllegalArgumentException.class) + public void whenServiceTimeSmallerZero_throwIllegalStateException() { + @SuppressWarnings("unused") + Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")).setServiceTime(-1).build(); + } + + @Test + public void whenSettingServiceTime_itShouldBeSetCorrectly() { + Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")).setServiceTime(1).build(); + assertEquals(1.0, s.getServiceDuration(), 0.01); + } + + @Test(expected = IllegalArgumentException.class) + public void whenTimeWindowIsNull_throwException() { + @SuppressWarnings("unused") + Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")).setTimeWindow(null).build(); + } + + @Test + public void whenSettingTimeWindow_itShouldBeSetCorrectly() { + Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")).setTimeWindow(TimeWindow.newInstance(1.0, 2.0)).build(); + assertEquals(1.0, s.getTimeWindow().getStart(), 0.01); + assertEquals(2.0, s.getTimeWindow().getEnd(), 0.01); + } + + @Test + public void whenAddingSkills_theyShouldBeAddedCorrectly() { + Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")) + .addRequiredSkill("drill").addRequiredSkill("screwdriver").build(); + assertTrue(s.getRequiredSkills().containsSkill("drill")); + assertTrue(s.getRequiredSkills().containsSkill("drill")); + assertTrue(s.getRequiredSkills().containsSkill("ScrewDriver")); + } + + @Test + public void whenAddingSkillsCaseSens_theyShouldBeAddedCorrectly() { + Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")) + .addRequiredSkill("DriLl").addRequiredSkill("screwDriver").build(); + assertTrue(s.getRequiredSkills().containsSkill("drill")); + assertTrue(s.getRequiredSkills().containsSkill("drilL")); + } + + @Test + public void whenAddingSkillsCaseSensV2_theyShouldBeAddedCorrectly() { + Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")) + .addRequiredSkill("screwDriver").build(); assertFalse(s.getRequiredSkills().containsSkill("drill")); assertFalse(s.getRequiredSkills().containsSkill("drilL")); } @Test - public void nameShouldBeAssigned(){ + public void nameShouldBeAssigned() { Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")) - .setName("name").build(); - assertEquals("name",s.getName()); + .setName("name").build(); + assertEquals("name", s.getName()); } @Test diff --git a/jsprit-core/src/test/java/jsprit/core/problem/job/ShipmentTest.java b/jsprit-core/src/test/java/jsprit/core/problem/job/ShipmentTest.java index ab878d05..ac750087 100644 --- a/jsprit-core/src/test/java/jsprit/core/problem/job/ShipmentTest.java +++ b/jsprit-core/src/test/java/jsprit/core/problem/job/ShipmentTest.java @@ -25,285 +25,285 @@ import org.junit.Test; import static org.junit.Assert.*; public class ShipmentTest { - - @Test - public void whenTwoShipmentsHaveTheSameId_theyReferencesShouldBeUnEqual(){ - Shipment one = Shipment.Builder.newInstance("s").addSizeDimension(0, 10).setPickupLocation(Location.Builder.newInstance().setId("foo").build()). - setDeliveryLocation(TestUtils.loc("foofoo")).setPickupServiceTime(10).setDeliveryServiceTime(20).build(); - Shipment two = Shipment.Builder.newInstance("s").addSizeDimension(0, 10).setPickupLocation(Location.Builder.newInstance().setId("foo").build()). - setDeliveryLocation(TestUtils.loc("foofoo")).setPickupServiceTime(10).setDeliveryServiceTime(20).build(); - - assertTrue(one != two); - } - - @Test - public void whenTwoShipmentsHaveTheSameId_theyShouldBeEqual(){ - Shipment one = Shipment.Builder.newInstance("s").addSizeDimension(0, 10).setPickupLocation(Location.Builder.newInstance().setId("foo").build()). - setDeliveryLocation(TestUtils.loc("foofoo")).setPickupServiceTime(10).setDeliveryServiceTime(20).build(); - Shipment two = Shipment.Builder.newInstance("s").addSizeDimension(0, 10).setPickupLocation(Location.Builder.newInstance().setId("foo").build()). - setDeliveryLocation(TestUtils.loc("foofoo")).setPickupServiceTime(10).setDeliveryServiceTime(20).build(); - - assertTrue(one.equals(two)); - } - - @Test - public void whenShipmentIsInstantiatedWithASizeOf10_theSizeShouldBe10(){ - Shipment one = Shipment.Builder.newInstance("s").addSizeDimension(0, 10).setPickupLocation(Location.Builder.newInstance().setId("foo").build()). - setDeliveryLocation(TestUtils.loc("foofoo")).setPickupServiceTime(10).setDeliveryServiceTime(20).build(); - assertEquals(10,one.getSize().get(0)); - } - - @Test(expected=IllegalArgumentException.class) - public void whenShipmentIsBuiltWithNegativeDemand_itShouldThrowException(){ - @SuppressWarnings("unused") - Shipment one = Shipment.Builder.newInstance("s").addSizeDimension(0, -10) - .setPickupLocation(Location.Builder.newInstance().setId("foo").build()) - .setDeliveryLocation(TestUtils.loc("foofoo")).build(); - } - - @Test(expected=IllegalArgumentException.class) - public void whenShipmentIsBuiltWithNegativeDemand_itShouldThrowException_v2(){ - @SuppressWarnings("unused") - Shipment one = Shipment.Builder.newInstance("s").addSizeDimension(0, -10) - .setPickupLocation(Location.Builder.newInstance().setId("foo").build()) - .setDeliveryLocation(TestUtils.loc("foofoo")).build(); - } - - @Test(expected=IllegalArgumentException.class) - public void whenIdIsNull_itShouldThrowException(){ - @SuppressWarnings("unused") - Shipment one = Shipment.Builder.newInstance(null).addSizeDimension(0, 10) - .setPickupLocation(Location.Builder.newInstance().setId("foo").build()) - .setDeliveryLocation(TestUtils.loc("foofoo")).build(); - } - - @Test - public void whenCallingForANewBuilderInstance_itShouldReturnBuilderCorrectly(){ - Shipment.Builder builder = Shipment.Builder.newInstance("s"); - assertNotNull(builder); - } - - @Test(expected=IllegalStateException.class) - public void whenNeitherPickupLocationIdNorPickupCoord_itThrowsException(){ - @SuppressWarnings("unused") - Shipment s = Shipment.Builder.newInstance("s").setDeliveryLocation(TestUtils.loc("delLoc")).build(); - } - - @Test(expected=IllegalStateException.class) - public void whenNeitherDeliveryLocationIdNorDeliveryCoord_itThrowsException(){ - @SuppressWarnings("unused") - Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); - } - - @Test - public void whenPickupLocationIdIsSet_itShouldBeDoneCorrectly(){ - Shipment s = Shipment.Builder.newInstance("s").setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); - assertEquals("pickLoc",s.getPickupLocation().getId()); - assertEquals("pickLoc",s.getPickupLocation().getId()); - } - - @Test(expected=IllegalStateException.class) - public void whenPickupLocationIsNull_itThrowsException(){ - @SuppressWarnings("unused") - Shipment.Builder builder = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId(null).build()); - } - - @Test - public void whenPickupCoordIsSet_itShouldBeDoneCorrectly(){ - Shipment s = Shipment.Builder.newInstance("s") - .setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").setCoordinate(Coordinate.newInstance(1, 2)).build()).build(); - assertEquals(1.0,s.getPickupLocation().getCoordinate().getX(),0.01); - assertEquals(2.0,s.getPickupLocation().getCoordinate().getY(),0.01); - assertEquals(1.0,s.getPickupLocation().getCoordinate().getX(),0.01); - assertEquals(2.0,s.getPickupLocation().getCoordinate().getY(),0.01); - } - - - @Test - public void whenDeliveryLocationIdIsSet_itShouldBeDoneCorrectly(){ - Shipment s = Shipment.Builder.newInstance("s") - .setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); - assertEquals("delLoc",s.getDeliveryLocation().getId()); - assertEquals("delLoc",s.getDeliveryLocation().getId()); - } - - - @Test - public void whenDeliveryCoordIsSet_itShouldBeDoneCorrectly(){ - Shipment s = Shipment.Builder.newInstance("s").setDeliveryLocation(TestUtils.loc("delLoc",Coordinate.newInstance(1, 2))) - .setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()) - .build(); - assertEquals(1.0,s.getDeliveryLocation().getCoordinate().getX(),0.01); - assertEquals(2.0,s.getDeliveryLocation().getCoordinate().getY(),0.01); - assertEquals(1.0,s.getDeliveryLocation().getCoordinate().getX(),0.01); - assertEquals(2.0,s.getDeliveryLocation().getCoordinate().getY(),0.01); - } - - @Test - public void whenPickupServiceTimeIsNotSet_itShouldBeZero(){ - Shipment s = Shipment.Builder.newInstance("s") - .setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); - assertEquals(0.0,s.getPickupServiceTime(),0.01); - } - - @Test - public void whenDeliveryServiceTimeIsNotSet_itShouldBeZero(){ - Shipment s = Shipment.Builder.newInstance("s") - .setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); - assertEquals(0.0,s.getDeliveryServiceTime(),0.01); - } - - @Test - public void whenPickupServiceTimeIsSet_itShouldBeDoneCorrectly(){ - Shipment s = Shipment.Builder.newInstance("s") - .setPickupServiceTime(2.0) - .setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); - assertEquals(2.0,s.getPickupServiceTime(),0.01); - } - - @Test(expected=IllegalArgumentException.class) - public void whenPickupServiceIsSmallerThanZero_itShouldThrowException(){ - @SuppressWarnings("unused") - Shipment s = Shipment.Builder.newInstance("s").setPickupServiceTime(-2.0) - .setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); - } - - @Test - public void whenDeliveryServiceTimeIsSet_itShouldBeDoneCorrectly(){ - Shipment s = Shipment.Builder.newInstance("s").setDeliveryServiceTime(2.0) - .setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); - assertEquals(2.0,s.getDeliveryServiceTime(),0.01); - } - - @Test(expected=IllegalArgumentException.class) - public void whenDeliveryServiceIsSmallerThanZero_itShouldThrowException(){ - @SuppressWarnings("unused") - Shipment s = Shipment.Builder.newInstance("s").setDeliveryServiceTime(-2.0).setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); - } - - @Test - public void whenPickupTimeWindowIsNotSet_itShouldBeTheDefaultOne(){ - Shipment s = Shipment.Builder.newInstance("s").setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); - assertEquals(0.0,s.getPickupTimeWindow().getStart(),0.01); - assertEquals(Double.MAX_VALUE,s.getPickupTimeWindow().getEnd(),0.01); - } - - @Test(expected=IllegalArgumentException.class) - public void whenPickupTimeWindowIsNull_itShouldThrowException(){ - @SuppressWarnings("unused") - Shipment s = Shipment.Builder.newInstance("s").setPickupTimeWindow(null).setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); - } - - @Test - public void whenPickupTimeWindowIsSet_itShouldBeDoneCorrectly(){ - Shipment s = Shipment.Builder.newInstance("s").setPickupTimeWindow(TimeWindow.newInstance(1, 2)) - .setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); - assertEquals(1.0,s.getPickupTimeWindow().getStart(),0.01); - assertEquals(2.0,s.getPickupTimeWindow().getEnd(),0.01); - } - - @Test - public void whenDeliveryTimeWindowIsNotSet_itShouldBeTheDefaultOne(){ - Shipment s = Shipment.Builder.newInstance("s").setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); - assertEquals(0.0,s.getDeliveryTimeWindow().getStart(),0.01); - assertEquals(Double.MAX_VALUE,s.getDeliveryTimeWindow().getEnd(),0.01); - } - - @Test(expected=IllegalArgumentException.class) - public void whenDeliveryTimeWindowIsNull_itShouldThrowException(){ - @SuppressWarnings("unused") - Shipment s = Shipment.Builder.newInstance("s").setDeliveryTimeWindow(null).setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); - } - - @Test - public void whenDeliveryTimeWindowIsSet_itShouldBeDoneCorrectly(){ - Shipment s = Shipment.Builder.newInstance("s").setDeliveryTimeWindow(TimeWindow.newInstance(1, 2)) - .setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); - assertEquals(1.0,s.getDeliveryTimeWindow().getStart(),0.01); - assertEquals(2.0,s.getDeliveryTimeWindow().getEnd(),0.01); - } - - @Test(expected=IllegalArgumentException.class) - public void whenShipmentHasNegativeCapacityVal_throwIllegalStateExpception(){ - @SuppressWarnings("unused") - Shipment one = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("foo").build()) - .setDeliveryLocation(TestUtils.loc("foofoo")) - .addSizeDimension(0, -2) - .build(); - } - - @Test - public void whenAddingTwoCapDimension_nuOfDimsShouldBeTwo(){ - Shipment one = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("foo").build()) - .setDeliveryLocation(TestUtils.loc("foofoo")) - .addSizeDimension(0, 2) - .addSizeDimension(1, 4) - .build(); - assertEquals(2,one.getSize().getNuOfDimensions()); - } - - @Test - public void whenShipmentIsBuiltWithoutSpecifyingCapacity_itShouldHvCapWithOneDimAndDimValOfZero(){ - Shipment one = Shipment.Builder.newInstance("s") - .setPickupLocation(Location.Builder.newInstance().setId("foo").setCoordinate(Coordinate.newInstance(0, 0)).build()) - .setDeliveryLocation(TestUtils.loc("foofoo")).build(); - assertEquals(1,one.getSize().getNuOfDimensions()); - assertEquals(0,one.getSize().get(0)); - } - - @Test - public void whenShipmentIsBuiltWithConstructorWhereSizeIsSpecified_capacityShouldBeSetCorrectly(){ - Shipment one = Shipment.Builder.newInstance("s").addSizeDimension(0, 1) - .setPickupLocation(Location.Builder.newInstance().setId("foo").setCoordinate(Coordinate.newInstance(0, 0)).build()) - .setDeliveryLocation(TestUtils.loc("foofoo")).build(); - assertEquals(1,one.getSize().getNuOfDimensions()); - assertEquals(1,one.getSize().get(0)); - } - - @Test - public void whenAddingSkills_theyShouldBeAddedCorrectly(){ - Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("loc").build()) - .setDeliveryLocation(TestUtils.loc("delLoc")) - .addRequiredSkill("drill").addRequiredSkill("screwdriver").build(); - assertTrue(s.getRequiredSkills().containsSkill("drill")); - assertTrue(s.getRequiredSkills().containsSkill("drill")); - assertTrue(s.getRequiredSkills().containsSkill("ScrewDriver")); - } - - @Test - public void whenAddingSkillsCaseSens_theyShouldBeAddedCorrectly(){ - Shipment s = Shipment.Builder.newInstance("s") - .setPickupLocation(Location.Builder.newInstance().setId("pick").build()) - .setDeliveryLocation(TestUtils.loc("del")) - .addRequiredSkill("DriLl").addRequiredSkill("screwDriver").build(); - assertTrue(s.getRequiredSkills().containsSkill("drill")); - assertTrue(s.getRequiredSkills().containsSkill("drilL")); - } @Test - public void whenAddingSkillsCaseSensV2_theyShouldBeAddedCorrectly(){ + public void whenTwoShipmentsHaveTheSameId_theyReferencesShouldBeUnEqual() { + Shipment one = Shipment.Builder.newInstance("s").addSizeDimension(0, 10).setPickupLocation(Location.Builder.newInstance().setId("foo").build()). + setDeliveryLocation(TestUtils.loc("foofoo")).setPickupServiceTime(10).setDeliveryServiceTime(20).build(); + Shipment two = Shipment.Builder.newInstance("s").addSizeDimension(0, 10).setPickupLocation(Location.Builder.newInstance().setId("foo").build()). + setDeliveryLocation(TestUtils.loc("foofoo")).setPickupServiceTime(10).setDeliveryServiceTime(20).build(); + + assertTrue(one != two); + } + + @Test + public void whenTwoShipmentsHaveTheSameId_theyShouldBeEqual() { + Shipment one = Shipment.Builder.newInstance("s").addSizeDimension(0, 10).setPickupLocation(Location.Builder.newInstance().setId("foo").build()). + setDeliveryLocation(TestUtils.loc("foofoo")).setPickupServiceTime(10).setDeliveryServiceTime(20).build(); + Shipment two = Shipment.Builder.newInstance("s").addSizeDimension(0, 10).setPickupLocation(Location.Builder.newInstance().setId("foo").build()). + setDeliveryLocation(TestUtils.loc("foofoo")).setPickupServiceTime(10).setDeliveryServiceTime(20).build(); + + assertTrue(one.equals(two)); + } + + @Test + public void whenShipmentIsInstantiatedWithASizeOf10_theSizeShouldBe10() { + Shipment one = Shipment.Builder.newInstance("s").addSizeDimension(0, 10).setPickupLocation(Location.Builder.newInstance().setId("foo").build()). + setDeliveryLocation(TestUtils.loc("foofoo")).setPickupServiceTime(10).setDeliveryServiceTime(20).build(); + assertEquals(10, one.getSize().get(0)); + } + + @Test(expected = IllegalArgumentException.class) + public void whenShipmentIsBuiltWithNegativeDemand_itShouldThrowException() { + @SuppressWarnings("unused") + Shipment one = Shipment.Builder.newInstance("s").addSizeDimension(0, -10) + .setPickupLocation(Location.Builder.newInstance().setId("foo").build()) + .setDeliveryLocation(TestUtils.loc("foofoo")).build(); + } + + @Test(expected = IllegalArgumentException.class) + public void whenShipmentIsBuiltWithNegativeDemand_itShouldThrowException_v2() { + @SuppressWarnings("unused") + Shipment one = Shipment.Builder.newInstance("s").addSizeDimension(0, -10) + .setPickupLocation(Location.Builder.newInstance().setId("foo").build()) + .setDeliveryLocation(TestUtils.loc("foofoo")).build(); + } + + @Test(expected = IllegalArgumentException.class) + public void whenIdIsNull_itShouldThrowException() { + @SuppressWarnings("unused") + Shipment one = Shipment.Builder.newInstance(null).addSizeDimension(0, 10) + .setPickupLocation(Location.Builder.newInstance().setId("foo").build()) + .setDeliveryLocation(TestUtils.loc("foofoo")).build(); + } + + @Test + public void whenCallingForANewBuilderInstance_itShouldReturnBuilderCorrectly() { + Shipment.Builder builder = Shipment.Builder.newInstance("s"); + assertNotNull(builder); + } + + @Test(expected = IllegalStateException.class) + public void whenNeitherPickupLocationIdNorPickupCoord_itThrowsException() { + @SuppressWarnings("unused") + Shipment s = Shipment.Builder.newInstance("s").setDeliveryLocation(TestUtils.loc("delLoc")).build(); + } + + @Test(expected = IllegalStateException.class) + public void whenNeitherDeliveryLocationIdNorDeliveryCoord_itThrowsException() { + @SuppressWarnings("unused") + Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); + } + + @Test + public void whenPickupLocationIdIsSet_itShouldBeDoneCorrectly() { + Shipment s = Shipment.Builder.newInstance("s").setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); + assertEquals("pickLoc", s.getPickupLocation().getId()); + assertEquals("pickLoc", s.getPickupLocation().getId()); + } + + @Test(expected = IllegalStateException.class) + public void whenPickupLocationIsNull_itThrowsException() { + @SuppressWarnings("unused") + Shipment.Builder builder = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId(null).build()); + } + + @Test + public void whenPickupCoordIsSet_itShouldBeDoneCorrectly() { + Shipment s = Shipment.Builder.newInstance("s") + .setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").setCoordinate(Coordinate.newInstance(1, 2)).build()).build(); + assertEquals(1.0, s.getPickupLocation().getCoordinate().getX(), 0.01); + assertEquals(2.0, s.getPickupLocation().getCoordinate().getY(), 0.01); + assertEquals(1.0, s.getPickupLocation().getCoordinate().getX(), 0.01); + assertEquals(2.0, s.getPickupLocation().getCoordinate().getY(), 0.01); + } + + + @Test + public void whenDeliveryLocationIdIsSet_itShouldBeDoneCorrectly() { + Shipment s = Shipment.Builder.newInstance("s") + .setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); + assertEquals("delLoc", s.getDeliveryLocation().getId()); + assertEquals("delLoc", s.getDeliveryLocation().getId()); + } + + + @Test + public void whenDeliveryCoordIsSet_itShouldBeDoneCorrectly() { + Shipment s = Shipment.Builder.newInstance("s").setDeliveryLocation(TestUtils.loc("delLoc", Coordinate.newInstance(1, 2))) + .setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()) + .build(); + assertEquals(1.0, s.getDeliveryLocation().getCoordinate().getX(), 0.01); + assertEquals(2.0, s.getDeliveryLocation().getCoordinate().getY(), 0.01); + assertEquals(1.0, s.getDeliveryLocation().getCoordinate().getX(), 0.01); + assertEquals(2.0, s.getDeliveryLocation().getCoordinate().getY(), 0.01); + } + + @Test + public void whenPickupServiceTimeIsNotSet_itShouldBeZero() { + Shipment s = Shipment.Builder.newInstance("s") + .setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); + assertEquals(0.0, s.getPickupServiceTime(), 0.01); + } + + @Test + public void whenDeliveryServiceTimeIsNotSet_itShouldBeZero() { + Shipment s = Shipment.Builder.newInstance("s") + .setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); + assertEquals(0.0, s.getDeliveryServiceTime(), 0.01); + } + + @Test + public void whenPickupServiceTimeIsSet_itShouldBeDoneCorrectly() { + Shipment s = Shipment.Builder.newInstance("s") + .setPickupServiceTime(2.0) + .setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); + assertEquals(2.0, s.getPickupServiceTime(), 0.01); + } + + @Test(expected = IllegalArgumentException.class) + public void whenPickupServiceIsSmallerThanZero_itShouldThrowException() { + @SuppressWarnings("unused") + Shipment s = Shipment.Builder.newInstance("s").setPickupServiceTime(-2.0) + .setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); + } + + @Test + public void whenDeliveryServiceTimeIsSet_itShouldBeDoneCorrectly() { + Shipment s = Shipment.Builder.newInstance("s").setDeliveryServiceTime(2.0) + .setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); + assertEquals(2.0, s.getDeliveryServiceTime(), 0.01); + } + + @Test(expected = IllegalArgumentException.class) + public void whenDeliveryServiceIsSmallerThanZero_itShouldThrowException() { + @SuppressWarnings("unused") + Shipment s = Shipment.Builder.newInstance("s").setDeliveryServiceTime(-2.0).setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); + } + + @Test + public void whenPickupTimeWindowIsNotSet_itShouldBeTheDefaultOne() { + Shipment s = Shipment.Builder.newInstance("s").setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); + assertEquals(0.0, s.getPickupTimeWindow().getStart(), 0.01); + assertEquals(Double.MAX_VALUE, s.getPickupTimeWindow().getEnd(), 0.01); + } + + @Test(expected = IllegalArgumentException.class) + public void whenPickupTimeWindowIsNull_itShouldThrowException() { + @SuppressWarnings("unused") + Shipment s = Shipment.Builder.newInstance("s").setPickupTimeWindow(null).setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); + } + + @Test + public void whenPickupTimeWindowIsSet_itShouldBeDoneCorrectly() { + Shipment s = Shipment.Builder.newInstance("s").setPickupTimeWindow(TimeWindow.newInstance(1, 2)) + .setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); + assertEquals(1.0, s.getPickupTimeWindow().getStart(), 0.01); + assertEquals(2.0, s.getPickupTimeWindow().getEnd(), 0.01); + } + + @Test + public void whenDeliveryTimeWindowIsNotSet_itShouldBeTheDefaultOne() { + Shipment s = Shipment.Builder.newInstance("s").setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); + assertEquals(0.0, s.getDeliveryTimeWindow().getStart(), 0.01); + assertEquals(Double.MAX_VALUE, s.getDeliveryTimeWindow().getEnd(), 0.01); + } + + @Test(expected = IllegalArgumentException.class) + public void whenDeliveryTimeWindowIsNull_itShouldThrowException() { + @SuppressWarnings("unused") + Shipment s = Shipment.Builder.newInstance("s").setDeliveryTimeWindow(null).setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); + } + + @Test + public void whenDeliveryTimeWindowIsSet_itShouldBeDoneCorrectly() { + Shipment s = Shipment.Builder.newInstance("s").setDeliveryTimeWindow(TimeWindow.newInstance(1, 2)) + .setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); + assertEquals(1.0, s.getDeliveryTimeWindow().getStart(), 0.01); + assertEquals(2.0, s.getDeliveryTimeWindow().getEnd(), 0.01); + } + + @Test(expected = IllegalArgumentException.class) + public void whenShipmentHasNegativeCapacityVal_throwIllegalStateExpception() { + @SuppressWarnings("unused") + Shipment one = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("foo").build()) + .setDeliveryLocation(TestUtils.loc("foofoo")) + .addSizeDimension(0, -2) + .build(); + } + + @Test + public void whenAddingTwoCapDimension_nuOfDimsShouldBeTwo() { + Shipment one = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("foo").build()) + .setDeliveryLocation(TestUtils.loc("foofoo")) + .addSizeDimension(0, 2) + .addSizeDimension(1, 4) + .build(); + assertEquals(2, one.getSize().getNuOfDimensions()); + } + + @Test + public void whenShipmentIsBuiltWithoutSpecifyingCapacity_itShouldHvCapWithOneDimAndDimValOfZero() { + Shipment one = Shipment.Builder.newInstance("s") + .setPickupLocation(Location.Builder.newInstance().setId("foo").setCoordinate(Coordinate.newInstance(0, 0)).build()) + .setDeliveryLocation(TestUtils.loc("foofoo")).build(); + assertEquals(1, one.getSize().getNuOfDimensions()); + assertEquals(0, one.getSize().get(0)); + } + + @Test + public void whenShipmentIsBuiltWithConstructorWhereSizeIsSpecified_capacityShouldBeSetCorrectly() { + Shipment one = Shipment.Builder.newInstance("s").addSizeDimension(0, 1) + .setPickupLocation(Location.Builder.newInstance().setId("foo").setCoordinate(Coordinate.newInstance(0, 0)).build()) + .setDeliveryLocation(TestUtils.loc("foofoo")).build(); + assertEquals(1, one.getSize().getNuOfDimensions()); + assertEquals(1, one.getSize().get(0)); + } + + @Test + public void whenAddingSkills_theyShouldBeAddedCorrectly() { Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("loc").build()) - .setDeliveryLocation(TestUtils.loc("del")) - .addRequiredSkill("screwDriver").build(); + .setDeliveryLocation(TestUtils.loc("delLoc")) + .addRequiredSkill("drill").addRequiredSkill("screwdriver").build(); + assertTrue(s.getRequiredSkills().containsSkill("drill")); + assertTrue(s.getRequiredSkills().containsSkill("drill")); + assertTrue(s.getRequiredSkills().containsSkill("ScrewDriver")); + } + + @Test + public void whenAddingSkillsCaseSens_theyShouldBeAddedCorrectly() { + Shipment s = Shipment.Builder.newInstance("s") + .setPickupLocation(Location.Builder.newInstance().setId("pick").build()) + .setDeliveryLocation(TestUtils.loc("del")) + .addRequiredSkill("DriLl").addRequiredSkill("screwDriver").build(); + assertTrue(s.getRequiredSkills().containsSkill("drill")); + assertTrue(s.getRequiredSkills().containsSkill("drilL")); + } + + @Test + public void whenAddingSkillsCaseSensV2_theyShouldBeAddedCorrectly() { + Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("loc").build()) + .setDeliveryLocation(TestUtils.loc("del")) + .addRequiredSkill("screwDriver").build(); assertFalse(s.getRequiredSkills().containsSkill("drill")); assertFalse(s.getRequiredSkills().containsSkill("drilL")); } @Test - public void nameShouldBeAssigned(){ + public void nameShouldBeAssigned() { Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("loc").build()) - .setDeliveryLocation(TestUtils.loc("del")) - .setName("name").build(); - assertEquals("name",s.getName()); + .setDeliveryLocation(TestUtils.loc("del")) + .setName("name").build(); + assertEquals("name", s.getName()); } @Test - public void whenSettingLocation_itShouldWork(){ + public void whenSettingLocation_itShouldWork() { Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("loc").build()) - .setDeliveryLocation(Location.Builder.newInstance().setId("del").build()).build(); + .setDeliveryLocation(Location.Builder.newInstance().setId("del").build()).build(); assertEquals("loc", s.getPickupLocation().getId()); assertEquals("loc", s.getPickupLocation().getId()); - assertEquals("del",s.getDeliveryLocation().getId()); - assertEquals("del",s.getDeliveryLocation().getId()); + assertEquals("del", s.getDeliveryLocation().getId()); + assertEquals("del", s.getDeliveryLocation().getId()); } } diff --git a/jsprit-core/src/test/java/jsprit/core/problem/misc/JobInsertionContextTest.java b/jsprit-core/src/test/java/jsprit/core/problem/misc/JobInsertionContextTest.java index 37f6cb44..dd859345 100644 --- a/jsprit-core/src/test/java/jsprit/core/problem/misc/JobInsertionContextTest.java +++ b/jsprit-core/src/test/java/jsprit/core/problem/misc/JobInsertionContextTest.java @@ -45,49 +45,49 @@ public class JobInsertionContextTest { JobInsertionContext context; @Before - public void doBefore(){ + public void doBefore() { route = mock(VehicleRoute.class); job = mock(Job.class); vehicle = mock(Vehicle.class); driver = mock(Driver.class); depTime = 0.; - context = new JobInsertionContext(route,job,vehicle,driver,depTime); + context = new JobInsertionContext(route, job, vehicle, driver, depTime); } @Test - public void routeShouldBeAssigned(){ - assertEquals(route,context.getRoute()); + public void routeShouldBeAssigned() { + assertEquals(route, context.getRoute()); } @Test - public void jobShouldBeAssigned(){ - assertEquals(job,context.getJob()); + public void jobShouldBeAssigned() { + assertEquals(job, context.getJob()); } @Test - public void vehicleShouldBeAssigned(){ - assertEquals(vehicle,context.getNewVehicle()); + public void vehicleShouldBeAssigned() { + assertEquals(vehicle, context.getNewVehicle()); } @Test - public void driverShouldBeAssigned(){ - assertEquals(driver,context.getNewDriver()); + public void driverShouldBeAssigned() { + assertEquals(driver, context.getNewDriver()); } @Test - public void depTimeShouldBeAssigned(){ - assertEquals(0.,context.getNewDepTime(),0.001); + public void depTimeShouldBeAssigned() { + assertEquals(0., context.getNewDepTime(), 0.001); } @Test - public void relatedActivitiesShouldBeAssigned(){ + public void relatedActivitiesShouldBeAssigned() { context.getAssociatedActivities().add(mock(TourActivity.class)); context.getAssociatedActivities().add(mock(TourActivity.class)); - assertEquals(2,context.getAssociatedActivities().size()); + assertEquals(2, context.getAssociatedActivities().size()); } @Test - public void relatedActivityContextShouldBeAssigned(){ + public void relatedActivityContextShouldBeAssigned() { context.setRelatedActivityContext(mock(ActivityContext.class)); assertNotNull(context.getRelatedActivityContext()); } diff --git a/jsprit-core/src/test/java/jsprit/core/problem/solution/VehicleRoutingProblemSolutionTest.java b/jsprit-core/src/test/java/jsprit/core/problem/solution/VehicleRoutingProblemSolutionTest.java index 81e21ac4..a50ba5c5 100644 --- a/jsprit-core/src/test/java/jsprit/core/problem/solution/VehicleRoutingProblemSolutionTest.java +++ b/jsprit-core/src/test/java/jsprit/core/problem/solution/VehicleRoutingProblemSolutionTest.java @@ -1,18 +1,18 @@ /******************************************************************************* * Copyright (c) 2014 Stefan Schroeder. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . - * + * * Contributors: * Stefan Schroeder - initial API and implementation ******************************************************************************/ @@ -31,40 +31,40 @@ import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.mock; public class VehicleRoutingProblemSolutionTest { - - @Test - public void whenCreatingSolutionWithTwoRoutes_solutionShouldContainTheseRoutes(){ - VehicleRoute r1 = mock(VehicleRoute.class); - VehicleRoute r2 = mock(VehicleRoute.class); - - VehicleRoutingProblemSolution sol = new VehicleRoutingProblemSolution(Arrays.asList(r1,r2), 0.0); - assertEquals(2,sol.getRoutes().size()); - } - - @Test - public void whenSettingSolutionCostsTo10_solutionCostsShouldBe10(){ - VehicleRoutingProblemSolution sol = new VehicleRoutingProblemSolution(Collections.emptyList(), 10.0); - assertEquals(10.0,sol.getCost(),0.01); - } - - @Test - public void whenCreatingSolWithCostsOf10AndSettingCostsAfterwardsTo20_solutionCostsShouldBe20(){ - VehicleRoutingProblemSolution sol = new VehicleRoutingProblemSolution(Collections.emptyList(), 10.0); - sol.setCost(20.0); - assertEquals(20.0,sol.getCost(),0.01); - } @Test - public void sizeOfBadJobsShouldBeCorrect(){ + public void whenCreatingSolutionWithTwoRoutes_solutionShouldContainTheseRoutes() { + VehicleRoute r1 = mock(VehicleRoute.class); + VehicleRoute r2 = mock(VehicleRoute.class); + + VehicleRoutingProblemSolution sol = new VehicleRoutingProblemSolution(Arrays.asList(r1, r2), 0.0); + assertEquals(2, sol.getRoutes().size()); + } + + @Test + public void whenSettingSolutionCostsTo10_solutionCostsShouldBe10() { + VehicleRoutingProblemSolution sol = new VehicleRoutingProblemSolution(Collections.emptyList(), 10.0); + assertEquals(10.0, sol.getCost(), 0.01); + } + + @Test + public void whenCreatingSolWithCostsOf10AndSettingCostsAfterwardsTo20_solutionCostsShouldBe20() { + VehicleRoutingProblemSolution sol = new VehicleRoutingProblemSolution(Collections.emptyList(), 10.0); + sol.setCost(20.0); + assertEquals(20.0, sol.getCost(), 0.01); + } + + @Test + public void sizeOfBadJobsShouldBeCorrect() { Job badJob = mock(Job.class); List badJobs = new ArrayList(); badJobs.add(badJob); VehicleRoutingProblemSolution sol = new VehicleRoutingProblemSolution(Collections.emptyList(), badJobs, 10.0); - assertEquals(1,sol.getUnassignedJobs().size()); + assertEquals(1, sol.getUnassignedJobs().size()); } @Test - public void sizeOfBadJobsShouldBeCorrect_2(){ + public void sizeOfBadJobsShouldBeCorrect_2() { Job badJob = mock(Job.class); List badJobs = new ArrayList(); badJobs.add(badJob); @@ -74,12 +74,12 @@ public class VehicleRoutingProblemSolutionTest { } @Test - public void badJobsShouldBeCorrect(){ + public void badJobsShouldBeCorrect() { Job badJob = mock(Job.class); List badJobs = new ArrayList(); badJobs.add(badJob); VehicleRoutingProblemSolution sol = new VehicleRoutingProblemSolution(Collections.emptyList(), badJobs, 10.0); - assertEquals(badJob,sol.getUnassignedJobs().iterator().next()); + assertEquals(badJob, sol.getUnassignedJobs().iterator().next()); } @Test diff --git a/jsprit-core/src/test/java/jsprit/core/problem/solution/route/TestVehicleRoute.java b/jsprit-core/src/test/java/jsprit/core/problem/solution/route/TestVehicleRoute.java index 3003cb53..488bdba4 100644 --- a/jsprit-core/src/test/java/jsprit/core/problem/solution/route/TestVehicleRoute.java +++ b/jsprit-core/src/test/java/jsprit/core/problem/solution/route/TestVehicleRoute.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.problem.solution.route; @@ -39,264 +39,264 @@ import static org.junit.Assert.assertTrue; public class TestVehicleRoute { - - private VehicleImpl vehicle; - private NoDriver driver; - @Before - public void doBefore(){ - vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("loc")).setType(VehicleTypeImpl.Builder.newInstance("yo").build()).build(); - driver = DriverImpl.noDriver(); - } + private VehicleImpl vehicle; + private NoDriver driver; - @Test - public void whenBuildingEmptyRouteCorrectly_go(){ - VehicleRoute route = VehicleRoute.Builder.newInstance(VehicleImpl.createNoVehicle(),DriverImpl.noDriver()).build(); - assertTrue(route!=null); - } - - @Test - public void whenBuildingEmptyRouteCorrectlyV2_go(){ - VehicleRoute route = VehicleRoute.emptyRoute(); - assertTrue(route!=null); - } - - @Test - public void whenBuildingEmptyRoute_ActivityIteratorIteratesOverZeroActivities(){ - VehicleRoute route = VehicleRoute.emptyRoute(); - Iterator iter = route.getTourActivities().iterator(); - int count=0; - while(iter.hasNext()){ - iter.next(); - count++; - } - assertEquals(0,count); - } - - @Test(expected=IllegalArgumentException.class) - public void whenBuildingRouteWithNulls_itThrowsException(){ - @SuppressWarnings("unused") - VehicleRoute route = VehicleRoute.Builder.newInstance(null, null).build(); - } - - @Test - public void whenBuildingANonEmptyTour2Times_tourIterIteratesOverActivitiesCorrectly(){ - VehicleRoute.Builder routeBuilder = VehicleRoute.Builder.newInstance(vehicle, driver); - routeBuilder.addService(Service.Builder.newInstance("2").addSizeDimension(0, 30).setLocation(Location.newInstance("1")).build()); - VehicleRoute route = routeBuilder.build(); - - { - Iterator iter = route.getTourActivities().iterator(); - int count = 0; - while(iter.hasNext()){ - @SuppressWarnings("unused") - TourActivity act = iter.next(); - count++; - } - assertEquals(1,count); - } - { - route.getTourActivities().addActivity(ServiceActivity.newInstance(Service.Builder.newInstance("3").addSizeDimension(0, 30).setLocation(Location.newInstance("1")).build())); - Iterator iter = route.getTourActivities().iterator(); - int count = 0; - while(iter.hasNext()){ - @SuppressWarnings("unused") - TourActivity act = iter.next(); - count++; - } - assertEquals(2,count); - } - } - - @Test - public void whenBuildingANonEmptyTour_tourReverseIterIteratesOverActivitiesCorrectly(){ - VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).build(); - Iterator iter = route.getTourActivities().reverseActivityIterator(); - int count = 0; - while(iter.hasNext()){ - @SuppressWarnings("unused") - TourActivity act = iter.next(); - count++; - } - assertEquals(0,count); - } - - @Test - public void whenBuildingANonEmptyTourV2_tourReverseIterIteratesOverActivitiesCorrectly(){ - VehicleRoute.Builder routeBuilder = VehicleRoute.Builder.newInstance(vehicle, driver); - routeBuilder.addService(Service.Builder.newInstance("2").addSizeDimension(0, 30).setLocation(Location.newInstance("1")).build()); - VehicleRoute route = routeBuilder.build(); - Iterator iter = route.getTourActivities().reverseActivityIterator(); - int count = 0; - while(iter.hasNext()){ - @SuppressWarnings("unused") - TourActivity act = iter.next(); - count++; - } - assertEquals(1,count); - } - - @Test - public void whenBuildingANonEmptyTour2Times_tourReverseIterIteratesOverActivitiesCorrectly(){ - VehicleRoute.Builder routeBuilder = VehicleRoute.Builder.newInstance(vehicle, driver); - routeBuilder.addService(Service.Builder.newInstance("2").addSizeDimension(0, 30).setLocation(Location.newInstance("1")).build()); - routeBuilder.addService(Service.Builder.newInstance("3").addSizeDimension(0, 30).setLocation(Location.newInstance("2")).build()); - VehicleRoute route = routeBuilder.build(); - { - Iterator iter = route.getTourActivities().reverseActivityIterator(); - int count = 0; - while(iter.hasNext()){ - TourActivity act = iter.next(); - if(count==0) { - assertEquals("2",act.getLocation().getId()); - } - count++; - } - assertEquals(2,count); - } - { - Iterator secondIter = route.getTourActivities().reverseActivityIterator(); - int count = 0; - while(secondIter.hasNext()){ - TourActivity act = secondIter.next(); - if(count==0) { - assertEquals("2",act.getLocation().getId()); - } - count++; - } - assertEquals(2,count); - } - } - - @Test - public void whenBuildingRouteWithVehicleThatHasDifferentStartAndEndLocation_routeMustHaveCorrectStartLocation(){ - Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")).setEndLocation(Location.newInstance("end")).build(); - VehicleRoute vRoute = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build(); - assertTrue(vRoute.getStart().getLocation().getId().equals("start")); - } - - @Test - public void whenBuildingRouteWithVehicleThatHasDifferentStartAndEndLocation_routeMustHaveCorrectEndLocation(){ - Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")).setEndLocation(Location.newInstance("end")).build(); - VehicleRoute vRoute = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build(); - assertTrue(vRoute.getEnd().getLocation().getId().equals("end")); - } - - @Test - public void whenBuildingRouteWithVehicleThatHasSameStartAndEndLocation_routeMustHaveCorrectStartLocation(){ - Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")).setEndLocation(Location.newInstance("end")).build(); - VehicleRoute vRoute = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build(); - assertTrue(vRoute.getStart().getLocation().getId().equals("start")); - } - - @Test - public void whenBuildingRouteWithVehicleThatHasSameStartAndEndLocation_routeMustHaveCorrectEndLocation(){ - Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")).setEndLocation(Location.newInstance("start")).build(); - VehicleRoute vRoute = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build(); - assertTrue(vRoute.getEnd().getLocation().getId().equals("start")); - } - - @Test - public void whenBuildingRouteWithVehicleThatHasSameStartAndEndLocation_routeMustHaveCorrectStartLocationV2(){ - Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")).setEndLocation(Location.newInstance("end")).build(); - VehicleRoute vRoute = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build(); - assertTrue(vRoute.getStart().getLocation().getId().equals("start")); - } - - @Test - public void whenBuildingRouteWithVehicleThatHasSameStartAndEndLocation_routeMustHaveCorrectEndLocationV2(){ - Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")).setEndLocation(Location.newInstance("start")).build(); - VehicleRoute vRoute = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build(); - assertTrue(vRoute.getEnd().getLocation().getId().equals("start")); - } - - @Test - public void whenBuildingRouteWithVehicleThatHasDifferentStartAndEndLocation_routeMustHaveCorrectDepartureTime(){ - Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setEarliestStart(100).setStartLocation(Location.newInstance("start")).setEndLocation(Location.newInstance("end")).build(); - VehicleRoute vRoute = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build(); - assertEquals(vRoute.getDepartureTime(),100.0,0.01); - assertEquals(vRoute.getStart().getEndTime(),100.0,0.01); - } - - @Test - public void whenBuildingRouteWithVehicleThatHasDifferentStartAndEndLocation_routeMustHaveCorrectEndTime(){ - Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setEarliestStart(100).setLatestArrival(200).setStartLocation(Location.newInstance("start")).setEndLocation(Location.newInstance("end")).build(); - VehicleRoute vRoute = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build(); - assertEquals(200.0,vRoute.getEnd().getTheoreticalLatestOperationStartTime(),0.01); - } - - @Test - public void whenSettingDepartureTimeInBetweenEarliestStartAndLatestArr_routeMustHaveCorrectDepartureTime(){ - Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setEarliestStart(100).setLatestArrival(200).setStartLocation(Location.newInstance("start")).setEndLocation(Location.newInstance("end")).build(); - VehicleRoute vRoute = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build(); - vRoute.setVehicleAndDepartureTime(vehicle, 150.0); - assertEquals(vRoute.getStart().getEndTime(),150.0,0.01); - assertEquals(vRoute.getDepartureTime(),150.0,0.01); - } - - @Test - public void whenSettingDepartureEarlierThanEarliestStart_routeMustHaveEarliestDepTimeAsDepTime(){ - Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setEarliestStart(100).setLatestArrival(200).setStartLocation(Location.newInstance("start")).setEndLocation(Location.newInstance("end")).build(); - VehicleRoute vRoute = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build(); - vRoute.setVehicleAndDepartureTime(vehicle, 50.0); - assertEquals(vRoute.getStart().getEndTime(),100.0,0.01); - assertEquals(vRoute.getDepartureTime(),100.0,0.01); - } - - @Test - public void whenSettingDepartureTimeLaterThanLatestArrival_routeMustHaveThisDepTime(){ - Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setEarliestStart(100).setLatestArrival(200).setStartLocation(Location.newInstance("start")).setEndLocation(Location.newInstance("end")).build(); - VehicleRoute vRoute = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build(); - vRoute.setVehicleAndDepartureTime(vehicle, 50.0); - assertEquals(vRoute.getStart().getEndTime(),100.0,0.01); - assertEquals(vRoute.getDepartureTime(),100.0,0.01); - } - - @Test - public void whenCreatingEmptyRoute_itMustReturnEmptyRoute(){ - @SuppressWarnings("unused") - VehicleRoute route = VehicleRoute.emptyRoute(); - assertTrue(true); - } - - @Test - public void whenIniRouteWithNewVehicle_startLocationMustBeCorrect(){ - Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setEarliestStart(100).setLatestArrival(200).setStartLocation(Location.newInstance("start")).setEndLocation(Location.newInstance("end")).build(); - Vehicle new_vehicle = VehicleImpl.Builder.newInstance("new_v").setEarliestStart(1000).setLatestArrival(2000).setStartLocation(Location.newInstance("new_start")).setEndLocation(Location.newInstance("new_end")).build(); - VehicleRoute vRoute = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build(); - vRoute.setVehicleAndDepartureTime(new_vehicle, 50.0); - assertEquals("new_start",vRoute.getStart().getLocation().getId()); - } - - @Test - public void whenIniRouteWithNewVehicle_endLocationMustBeCorrect(){ - Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setEarliestStart(100).setLatestArrival(200).setStartLocation(Location.newInstance("start")).setEndLocation(Location.newInstance("end")).build(); - Vehicle new_vehicle = VehicleImpl.Builder.newInstance("new_v").setEarliestStart(1000).setLatestArrival(2000).setStartLocation(Location.newInstance("new_start")).setEndLocation(Location.newInstance("new_end")).build(); - VehicleRoute vRoute = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build(); - vRoute.setVehicleAndDepartureTime(new_vehicle, 50.0); - assertEquals("new_end",vRoute.getEnd().getLocation().getId()); - } - - @Test - public void whenIniRouteWithNewVehicle_depTimeMustBeEarliestDepTimeOfNewVehicle(){ - Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setEarliestStart(100).setLatestArrival(200).setStartLocation(Location.newInstance("start")).setEndLocation(Location.newInstance("end")).build(); - Vehicle new_vehicle = VehicleImpl.Builder.newInstance("new_v").setEarliestStart(1000).setLatestArrival(2000).setStartLocation(Location.newInstance("new_start")).setEndLocation(Location.newInstance("new_end")).build(); - VehicleRoute vRoute = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build(); - vRoute.setVehicleAndDepartureTime(new_vehicle, 50.0); - assertEquals(1000.0,vRoute.getDepartureTime(),0.01); - } - - @Test - public void whenIniRouteWithNewVehicle_depTimeMustBeSetDepTime(){ - Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setEarliestStart(100).setLatestArrival(200).setStartLocation(Location.newInstance("start")).setEndLocation(Location.newInstance("end")).build(); - Vehicle new_vehicle = VehicleImpl.Builder.newInstance("new_v").setEarliestStart(1000).setLatestArrival(2000).setStartLocation(Location.newInstance("new_start")).setEndLocation(Location.newInstance("new_end")).build(); - VehicleRoute vRoute = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build(); - vRoute.setVehicleAndDepartureTime(new_vehicle, 1500.0); - assertEquals(1500.0,vRoute.getDepartureTime(),0.01); - } + @Before + public void doBefore() { + vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("loc")).setType(VehicleTypeImpl.Builder.newInstance("yo").build()).build(); + driver = DriverImpl.noDriver(); + } @Test - public void whenAddingPickup_itShouldBeTreatedAsPickup(){ + public void whenBuildingEmptyRouteCorrectly_go() { + VehicleRoute route = VehicleRoute.Builder.newInstance(VehicleImpl.createNoVehicle(), DriverImpl.noDriver()).build(); + assertTrue(route != null); + } + + @Test + public void whenBuildingEmptyRouteCorrectlyV2_go() { + VehicleRoute route = VehicleRoute.emptyRoute(); + assertTrue(route != null); + } + + @Test + public void whenBuildingEmptyRoute_ActivityIteratorIteratesOverZeroActivities() { + VehicleRoute route = VehicleRoute.emptyRoute(); + Iterator iter = route.getTourActivities().iterator(); + int count = 0; + while (iter.hasNext()) { + iter.next(); + count++; + } + assertEquals(0, count); + } + + @Test(expected = IllegalArgumentException.class) + public void whenBuildingRouteWithNulls_itThrowsException() { + @SuppressWarnings("unused") + VehicleRoute route = VehicleRoute.Builder.newInstance(null, null).build(); + } + + @Test + public void whenBuildingANonEmptyTour2Times_tourIterIteratesOverActivitiesCorrectly() { + VehicleRoute.Builder routeBuilder = VehicleRoute.Builder.newInstance(vehicle, driver); + routeBuilder.addService(Service.Builder.newInstance("2").addSizeDimension(0, 30).setLocation(Location.newInstance("1")).build()); + VehicleRoute route = routeBuilder.build(); + + { + Iterator iter = route.getTourActivities().iterator(); + int count = 0; + while (iter.hasNext()) { + @SuppressWarnings("unused") + TourActivity act = iter.next(); + count++; + } + assertEquals(1, count); + } + { + route.getTourActivities().addActivity(ServiceActivity.newInstance(Service.Builder.newInstance("3").addSizeDimension(0, 30).setLocation(Location.newInstance("1")).build())); + Iterator iter = route.getTourActivities().iterator(); + int count = 0; + while (iter.hasNext()) { + @SuppressWarnings("unused") + TourActivity act = iter.next(); + count++; + } + assertEquals(2, count); + } + } + + @Test + public void whenBuildingANonEmptyTour_tourReverseIterIteratesOverActivitiesCorrectly() { + VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).build(); + Iterator iter = route.getTourActivities().reverseActivityIterator(); + int count = 0; + while (iter.hasNext()) { + @SuppressWarnings("unused") + TourActivity act = iter.next(); + count++; + } + assertEquals(0, count); + } + + @Test + public void whenBuildingANonEmptyTourV2_tourReverseIterIteratesOverActivitiesCorrectly() { + VehicleRoute.Builder routeBuilder = VehicleRoute.Builder.newInstance(vehicle, driver); + routeBuilder.addService(Service.Builder.newInstance("2").addSizeDimension(0, 30).setLocation(Location.newInstance("1")).build()); + VehicleRoute route = routeBuilder.build(); + Iterator iter = route.getTourActivities().reverseActivityIterator(); + int count = 0; + while (iter.hasNext()) { + @SuppressWarnings("unused") + TourActivity act = iter.next(); + count++; + } + assertEquals(1, count); + } + + @Test + public void whenBuildingANonEmptyTour2Times_tourReverseIterIteratesOverActivitiesCorrectly() { + VehicleRoute.Builder routeBuilder = VehicleRoute.Builder.newInstance(vehicle, driver); + routeBuilder.addService(Service.Builder.newInstance("2").addSizeDimension(0, 30).setLocation(Location.newInstance("1")).build()); + routeBuilder.addService(Service.Builder.newInstance("3").addSizeDimension(0, 30).setLocation(Location.newInstance("2")).build()); + VehicleRoute route = routeBuilder.build(); + { + Iterator iter = route.getTourActivities().reverseActivityIterator(); + int count = 0; + while (iter.hasNext()) { + TourActivity act = iter.next(); + if (count == 0) { + assertEquals("2", act.getLocation().getId()); + } + count++; + } + assertEquals(2, count); + } + { + Iterator secondIter = route.getTourActivities().reverseActivityIterator(); + int count = 0; + while (secondIter.hasNext()) { + TourActivity act = secondIter.next(); + if (count == 0) { + assertEquals("2", act.getLocation().getId()); + } + count++; + } + assertEquals(2, count); + } + } + + @Test + public void whenBuildingRouteWithVehicleThatHasDifferentStartAndEndLocation_routeMustHaveCorrectStartLocation() { + Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")).setEndLocation(Location.newInstance("end")).build(); + VehicleRoute vRoute = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build(); + assertTrue(vRoute.getStart().getLocation().getId().equals("start")); + } + + @Test + public void whenBuildingRouteWithVehicleThatHasDifferentStartAndEndLocation_routeMustHaveCorrectEndLocation() { + Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")).setEndLocation(Location.newInstance("end")).build(); + VehicleRoute vRoute = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build(); + assertTrue(vRoute.getEnd().getLocation().getId().equals("end")); + } + + @Test + public void whenBuildingRouteWithVehicleThatHasSameStartAndEndLocation_routeMustHaveCorrectStartLocation() { + Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")).setEndLocation(Location.newInstance("end")).build(); + VehicleRoute vRoute = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build(); + assertTrue(vRoute.getStart().getLocation().getId().equals("start")); + } + + @Test + public void whenBuildingRouteWithVehicleThatHasSameStartAndEndLocation_routeMustHaveCorrectEndLocation() { + Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")).setEndLocation(Location.newInstance("start")).build(); + VehicleRoute vRoute = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build(); + assertTrue(vRoute.getEnd().getLocation().getId().equals("start")); + } + + @Test + public void whenBuildingRouteWithVehicleThatHasSameStartAndEndLocation_routeMustHaveCorrectStartLocationV2() { + Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")).setEndLocation(Location.newInstance("end")).build(); + VehicleRoute vRoute = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build(); + assertTrue(vRoute.getStart().getLocation().getId().equals("start")); + } + + @Test + public void whenBuildingRouteWithVehicleThatHasSameStartAndEndLocation_routeMustHaveCorrectEndLocationV2() { + Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")).setEndLocation(Location.newInstance("start")).build(); + VehicleRoute vRoute = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build(); + assertTrue(vRoute.getEnd().getLocation().getId().equals("start")); + } + + @Test + public void whenBuildingRouteWithVehicleThatHasDifferentStartAndEndLocation_routeMustHaveCorrectDepartureTime() { + Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setEarliestStart(100).setStartLocation(Location.newInstance("start")).setEndLocation(Location.newInstance("end")).build(); + VehicleRoute vRoute = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build(); + assertEquals(vRoute.getDepartureTime(), 100.0, 0.01); + assertEquals(vRoute.getStart().getEndTime(), 100.0, 0.01); + } + + @Test + public void whenBuildingRouteWithVehicleThatHasDifferentStartAndEndLocation_routeMustHaveCorrectEndTime() { + Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setEarliestStart(100).setLatestArrival(200).setStartLocation(Location.newInstance("start")).setEndLocation(Location.newInstance("end")).build(); + VehicleRoute vRoute = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build(); + assertEquals(200.0, vRoute.getEnd().getTheoreticalLatestOperationStartTime(), 0.01); + } + + @Test + public void whenSettingDepartureTimeInBetweenEarliestStartAndLatestArr_routeMustHaveCorrectDepartureTime() { + Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setEarliestStart(100).setLatestArrival(200).setStartLocation(Location.newInstance("start")).setEndLocation(Location.newInstance("end")).build(); + VehicleRoute vRoute = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build(); + vRoute.setVehicleAndDepartureTime(vehicle, 150.0); + assertEquals(vRoute.getStart().getEndTime(), 150.0, 0.01); + assertEquals(vRoute.getDepartureTime(), 150.0, 0.01); + } + + @Test + public void whenSettingDepartureEarlierThanEarliestStart_routeMustHaveEarliestDepTimeAsDepTime() { + Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setEarliestStart(100).setLatestArrival(200).setStartLocation(Location.newInstance("start")).setEndLocation(Location.newInstance("end")).build(); + VehicleRoute vRoute = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build(); + vRoute.setVehicleAndDepartureTime(vehicle, 50.0); + assertEquals(vRoute.getStart().getEndTime(), 100.0, 0.01); + assertEquals(vRoute.getDepartureTime(), 100.0, 0.01); + } + + @Test + public void whenSettingDepartureTimeLaterThanLatestArrival_routeMustHaveThisDepTime() { + Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setEarliestStart(100).setLatestArrival(200).setStartLocation(Location.newInstance("start")).setEndLocation(Location.newInstance("end")).build(); + VehicleRoute vRoute = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build(); + vRoute.setVehicleAndDepartureTime(vehicle, 50.0); + assertEquals(vRoute.getStart().getEndTime(), 100.0, 0.01); + assertEquals(vRoute.getDepartureTime(), 100.0, 0.01); + } + + @Test + public void whenCreatingEmptyRoute_itMustReturnEmptyRoute() { + @SuppressWarnings("unused") + VehicleRoute route = VehicleRoute.emptyRoute(); + assertTrue(true); + } + + @Test + public void whenIniRouteWithNewVehicle_startLocationMustBeCorrect() { + Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setEarliestStart(100).setLatestArrival(200).setStartLocation(Location.newInstance("start")).setEndLocation(Location.newInstance("end")).build(); + Vehicle new_vehicle = VehicleImpl.Builder.newInstance("new_v").setEarliestStart(1000).setLatestArrival(2000).setStartLocation(Location.newInstance("new_start")).setEndLocation(Location.newInstance("new_end")).build(); + VehicleRoute vRoute = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build(); + vRoute.setVehicleAndDepartureTime(new_vehicle, 50.0); + assertEquals("new_start", vRoute.getStart().getLocation().getId()); + } + + @Test + public void whenIniRouteWithNewVehicle_endLocationMustBeCorrect() { + Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setEarliestStart(100).setLatestArrival(200).setStartLocation(Location.newInstance("start")).setEndLocation(Location.newInstance("end")).build(); + Vehicle new_vehicle = VehicleImpl.Builder.newInstance("new_v").setEarliestStart(1000).setLatestArrival(2000).setStartLocation(Location.newInstance("new_start")).setEndLocation(Location.newInstance("new_end")).build(); + VehicleRoute vRoute = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build(); + vRoute.setVehicleAndDepartureTime(new_vehicle, 50.0); + assertEquals("new_end", vRoute.getEnd().getLocation().getId()); + } + + @Test + public void whenIniRouteWithNewVehicle_depTimeMustBeEarliestDepTimeOfNewVehicle() { + Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setEarliestStart(100).setLatestArrival(200).setStartLocation(Location.newInstance("start")).setEndLocation(Location.newInstance("end")).build(); + Vehicle new_vehicle = VehicleImpl.Builder.newInstance("new_v").setEarliestStart(1000).setLatestArrival(2000).setStartLocation(Location.newInstance("new_start")).setEndLocation(Location.newInstance("new_end")).build(); + VehicleRoute vRoute = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build(); + vRoute.setVehicleAndDepartureTime(new_vehicle, 50.0); + assertEquals(1000.0, vRoute.getDepartureTime(), 0.01); + } + + @Test + public void whenIniRouteWithNewVehicle_depTimeMustBeSetDepTime() { + Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setEarliestStart(100).setLatestArrival(200).setStartLocation(Location.newInstance("start")).setEndLocation(Location.newInstance("end")).build(); + Vehicle new_vehicle = VehicleImpl.Builder.newInstance("new_v").setEarliestStart(1000).setLatestArrival(2000).setStartLocation(Location.newInstance("new_start")).setEndLocation(Location.newInstance("new_end")).build(); + VehicleRoute vRoute = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build(); + vRoute.setVehicleAndDepartureTime(new_vehicle, 1500.0); + assertEquals(1500.0, vRoute.getDepartureTime(), 0.01); + } + + @Test + public void whenAddingPickup_itShouldBeTreatedAsPickup() { Pickup pickup = (Pickup) Pickup.Builder.newInstance("pick").setLocation(Location.newInstance("pickLoc")).build(); VehicleImpl vehicle = VehicleImpl.Builder.newInstance("vehicle").setStartLocation(Location.newInstance("startLoc")).build(); @@ -305,12 +305,12 @@ public class TestVehicleRoute { TourActivity act = route.getActivities().get(0); assertTrue(act.getName().equals("pickup")); assertTrue(act instanceof PickupService); - assertTrue(((TourActivity.JobActivity)act).getJob() instanceof Pickup); + assertTrue(((TourActivity.JobActivity) act).getJob() instanceof Pickup); } @Test - public void whenAddingPickup_itShouldBeAdded(){ + public void whenAddingPickup_itShouldBeAdded() { Pickup pickup = (Pickup) Pickup.Builder.newInstance("pick").setLocation(Location.newInstance("pickLoc")).build(); VehicleImpl vehicle = VehicleImpl.Builder.newInstance("vehicle").setStartLocation(Location.newInstance("startLoc")).build(); @@ -319,12 +319,12 @@ public class TestVehicleRoute { TourActivity act = route.getActivities().get(0); assertTrue(act.getName().equals("pickup")); assertTrue(act instanceof PickupService); - assertTrue(((TourActivity.JobActivity)act).getJob() instanceof Pickup); + assertTrue(((TourActivity.JobActivity) act).getJob() instanceof Pickup); } @Test - public void whenAddingDelivery_itShouldBeTreatedAsDelivery(){ + public void whenAddingDelivery_itShouldBeTreatedAsDelivery() { Delivery delivery = (Delivery) Delivery.Builder.newInstance("delivery").setLocation(Location.newInstance("deliveryLoc")).build(); VehicleImpl vehicle = VehicleImpl.Builder.newInstance("vehicle").setStartLocation(Location.newInstance("startLoc")).build(); @@ -333,12 +333,12 @@ public class TestVehicleRoute { TourActivity act = route.getActivities().get(0); assertTrue(act.getName().equals("delivery")); assertTrue(act instanceof DeliverService); - assertTrue(((TourActivity.JobActivity)act).getJob() instanceof Delivery); + assertTrue(((TourActivity.JobActivity) act).getJob() instanceof Delivery); } @Test - public void whenAddingDelivery_itShouldBeAdded(){ + public void whenAddingDelivery_itShouldBeAdded() { Delivery delivery = (Delivery) Delivery.Builder.newInstance("delivery").setLocation(Location.newInstance("deliveryLoc")).build(); VehicleImpl vehicle = VehicleImpl.Builder.newInstance("vehicle").setStartLocation(Location.newInstance("startLoc")).build(); @@ -347,7 +347,7 @@ public class TestVehicleRoute { TourActivity act = route.getActivities().get(0); assertTrue(act.getName().equals("delivery")); assertTrue(act instanceof DeliverService); - assertTrue(((TourActivity.JobActivity)act).getJob() instanceof Delivery); + assertTrue(((TourActivity.JobActivity) act).getJob() instanceof Delivery); } } diff --git a/jsprit-core/src/test/java/jsprit/core/problem/solution/route/VehicleRouteBuilderTest.java b/jsprit-core/src/test/java/jsprit/core/problem/solution/route/VehicleRouteBuilderTest.java index 2337077a..c0ad72c7 100644 --- a/jsprit-core/src/test/java/jsprit/core/problem/solution/route/VehicleRouteBuilderTest.java +++ b/jsprit-core/src/test/java/jsprit/core/problem/solution/route/VehicleRouteBuilderTest.java @@ -30,149 +30,149 @@ import static org.mockito.Mockito.when; public class VehicleRouteBuilderTest { - - @Test(expected=IllegalStateException.class) - public void whenDeliveryIsAddedBeforePickup_throwsException(){ - Shipment s = mock(Shipment.class); - VehicleRoute.Builder builder = VehicleRoute.Builder.newInstance(mock(Vehicle.class), mock(Driver.class)); - builder.addDelivery(s); - } - - @Test(expected=IllegalStateException.class) - public void whenPickupIsAddedTwice_throwsException(){ - Shipment s = mock(Shipment.class); + + @Test(expected = IllegalStateException.class) + public void whenDeliveryIsAddedBeforePickup_throwsException() { + Shipment s = mock(Shipment.class); + VehicleRoute.Builder builder = VehicleRoute.Builder.newInstance(mock(Vehicle.class), mock(Driver.class)); + builder.addDelivery(s); + } + + @Test(expected = IllegalStateException.class) + public void whenPickupIsAddedTwice_throwsException() { + Shipment s = mock(Shipment.class); when(s.getSize()).thenReturn(Capacity.Builder.newInstance().build()); - VehicleRoute.Builder builder = VehicleRoute.Builder.newInstance(mock(Vehicle.class), mock(Driver.class)); - builder.addPickup(s); - builder.addPickup(s); - } - - @Test(expected=IllegalStateException.class) - public void whenShipmentIsPickedDeliveredAndDeliveredAgain_throwsException(){ - Shipment s = mock(Shipment.class); - Capacity capacity = Capacity.Builder.newInstance().build(); - when(s.getSize()).thenReturn(capacity); - VehicleRoute.Builder builder = VehicleRoute.Builder.newInstance(mock(Vehicle.class), mock(Driver.class)); - builder.addPickup(s); - builder.addDelivery(s); - builder.addDelivery(s); - } - - @Test(expected=IllegalStateException.class) - public void whenShipmentIsPickedUpThoughButHasNotBeenDeliveredAndRouteIsBuilt_throwsException(){ - Shipment s = mock(Shipment.class); - Capacity capacity = Capacity.Builder.newInstance().build(); + VehicleRoute.Builder builder = VehicleRoute.Builder.newInstance(mock(Vehicle.class), mock(Driver.class)); + builder.addPickup(s); + builder.addPickup(s); + } + + @Test(expected = IllegalStateException.class) + public void whenShipmentIsPickedDeliveredAndDeliveredAgain_throwsException() { + Shipment s = mock(Shipment.class); + Capacity capacity = Capacity.Builder.newInstance().build(); + when(s.getSize()).thenReturn(capacity); + VehicleRoute.Builder builder = VehicleRoute.Builder.newInstance(mock(Vehicle.class), mock(Driver.class)); + builder.addPickup(s); + builder.addDelivery(s); + builder.addDelivery(s); + } + + @Test(expected = IllegalStateException.class) + public void whenShipmentIsPickedUpThoughButHasNotBeenDeliveredAndRouteIsBuilt_throwsException() { + Shipment s = mock(Shipment.class); + Capacity capacity = Capacity.Builder.newInstance().build(); Shipment s2 = mock(Shipment.class); when(s2.getSize()).thenReturn(capacity); - when(s.getSize()).thenReturn(capacity); - VehicleRoute.Builder builder = VehicleRoute.Builder.newInstance(mock(Vehicle.class), mock(Driver.class)); - builder.addPickup(s); - builder.addPickup(s2); - builder.addDelivery(s); - builder.build(); - } - - @Test - public void whenTwoShipmentsHaveBeenAdded_nuOfActivitiesMustEqualFour(){ - Shipment s = mock(Shipment.class); - Shipment s2 = mock(Shipment.class); - Capacity capacity = Capacity.Builder.newInstance().build(); - when(s.getSize()).thenReturn(capacity); - when(s2.getSize()).thenReturn(capacity); - VehicleRoute.Builder builder = VehicleRoute.Builder.newInstance(mock(Vehicle.class), mock(Driver.class)); - builder.addPickup(s); - builder.addPickup(s2); - builder.addDelivery(s); - builder.addDelivery(s2); - VehicleRoute route = builder.build(); - assertEquals(4,route.getTourActivities().getActivities().size()); - } + when(s.getSize()).thenReturn(capacity); + VehicleRoute.Builder builder = VehicleRoute.Builder.newInstance(mock(Vehicle.class), mock(Driver.class)); + builder.addPickup(s); + builder.addPickup(s2); + builder.addDelivery(s); + builder.build(); + } - @Test - public void whenBuildingClosedRoute_routeEndShouldHaveLocationOfVehicle(){ - Shipment s = mock(Shipment.class); - Shipment s2 = mock(Shipment.class); - Capacity capacity = Capacity.Builder.newInstance().build(); - when(s.getSize()).thenReturn(capacity); - when(s2.getSize()).thenReturn(capacity); - Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("vehLoc")).setEndLocation(Location.newInstance("vehLoc")) - .build(); + @Test + public void whenTwoShipmentsHaveBeenAdded_nuOfActivitiesMustEqualFour() { + Shipment s = mock(Shipment.class); + Shipment s2 = mock(Shipment.class); + Capacity capacity = Capacity.Builder.newInstance().build(); + when(s.getSize()).thenReturn(capacity); + when(s2.getSize()).thenReturn(capacity); + VehicleRoute.Builder builder = VehicleRoute.Builder.newInstance(mock(Vehicle.class), mock(Driver.class)); + builder.addPickup(s); + builder.addPickup(s2); + builder.addDelivery(s); + builder.addDelivery(s2); + VehicleRoute route = builder.build(); + assertEquals(4, route.getTourActivities().getActivities().size()); + } - VehicleRoute.Builder builder = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class)); - builder.addPickup(s); - builder.addPickup(s2); - builder.addDelivery(s); - builder.addDelivery(s2); - VehicleRoute route = builder.build(); - assertEquals("vehLoc",route.getEnd().getLocation().getId()); - } - - @Test - public void whenBuildingOpenRoute_routeEndShouldHaveLocationOfLastActivity(){ - Shipment s = mock(Shipment.class); - Shipment s2 = mock(Shipment.class); - Capacity capacity = Capacity.Builder.newInstance().build(); - when(s.getSize()).thenReturn(capacity); - when(s2.getSize()).thenReturn(capacity); - when(s2.getDeliveryLocation()).thenReturn(loc("delLoc")); - Vehicle vehicle = mock(Vehicle.class); - when(vehicle.isReturnToDepot()).thenReturn(false); - when(vehicle.getStartLocation()).thenReturn(loc("vehLoc")); - VehicleRoute.Builder builder = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class)); - builder.addPickup(s); - builder.addPickup(s2); - builder.addDelivery(s); - builder.addDelivery(s2); - VehicleRoute route = builder.build(); - assertEquals(route.getEnd().getLocation().getId(), s2.getDeliveryLocation().getId()); - } + @Test + public void whenBuildingClosedRoute_routeEndShouldHaveLocationOfVehicle() { + Shipment s = mock(Shipment.class); + Shipment s2 = mock(Shipment.class); + Capacity capacity = Capacity.Builder.newInstance().build(); + when(s.getSize()).thenReturn(capacity); + when(s2.getSize()).thenReturn(capacity); + Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("vehLoc")).setEndLocation(Location.newInstance("vehLoc")) + .build(); + + VehicleRoute.Builder builder = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class)); + builder.addPickup(s); + builder.addPickup(s2); + builder.addDelivery(s); + builder.addDelivery(s2); + VehicleRoute route = builder.build(); + assertEquals("vehLoc", route.getEnd().getLocation().getId()); + } + + @Test + public void whenBuildingOpenRoute_routeEndShouldHaveLocationOfLastActivity() { + Shipment s = mock(Shipment.class); + Shipment s2 = mock(Shipment.class); + Capacity capacity = Capacity.Builder.newInstance().build(); + when(s.getSize()).thenReturn(capacity); + when(s2.getSize()).thenReturn(capacity); + when(s2.getDeliveryLocation()).thenReturn(loc("delLoc")); + Vehicle vehicle = mock(Vehicle.class); + when(vehicle.isReturnToDepot()).thenReturn(false); + when(vehicle.getStartLocation()).thenReturn(loc("vehLoc")); + VehicleRoute.Builder builder = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class)); + builder.addPickup(s); + builder.addPickup(s2); + builder.addDelivery(s); + builder.addDelivery(s2); + VehicleRoute route = builder.build(); + assertEquals(route.getEnd().getLocation().getId(), s2.getDeliveryLocation().getId()); + } private Location loc(String delLoc) { return Location.Builder.newInstance().setId(delLoc).build(); } @Test - public void whenSettingDepartureTime(){ - Shipment s = mock(Shipment.class); - Shipment s2 = mock(Shipment.class); - Capacity capacity = Capacity.Builder.newInstance().build(); - when(s.getSize()).thenReturn(capacity); - when(s2.getSize()).thenReturn(capacity); - when(s2.getDeliveryLocation()).thenReturn(Location.Builder.newInstance().setId("delLoc").build()); - Vehicle vehicle = mock(Vehicle.class); - when(vehicle.isReturnToDepot()).thenReturn(false); - when(vehicle.getStartLocation()).thenReturn(Location.Builder.newInstance().setId("vehLoc").build()); - VehicleRoute.Builder builder = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class)); - builder.addPickup(s); - builder.addPickup(s2); - builder.addDelivery(s); - builder.addDelivery(s2); - builder.setDepartureTime(100); - VehicleRoute route = builder.build(); - assertEquals(100.0,route.getDepartureTime(),0.01); - assertEquals(100.0,route.getStart().getEndTime(),0.01); - } - - - @Test - public void whenSettingEndTime(){ - Shipment s = mock(Shipment.class); - Shipment s2 = mock(Shipment.class); - Capacity capacity = Capacity.Builder.newInstance().build(); - when(s.getSize()).thenReturn(capacity); - when(s2.getSize()).thenReturn(capacity); - when(s2.getDeliveryLocation()).thenReturn(Location.Builder.newInstance().setId("delLoc").build()); - Vehicle vehicle = mock(Vehicle.class); - when(vehicle.isReturnToDepot()).thenReturn(false); - when(vehicle.getStartLocation()).thenReturn(Location.Builder.newInstance().setId("vehLoc").build()); - when(vehicle.getLatestArrival()).thenReturn(200.0); - VehicleRoute.Builder builder = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class)); - builder.addPickup(s); - builder.addPickup(s2); - builder.addDelivery(s); - builder.addDelivery(s2); - builder.setRouteEndArrivalTime(100.0); - VehicleRoute route = builder.build(); - assertEquals(100.0,route.getEnd().getArrTime(),0.01); - } + public void whenSettingDepartureTime() { + Shipment s = mock(Shipment.class); + Shipment s2 = mock(Shipment.class); + Capacity capacity = Capacity.Builder.newInstance().build(); + when(s.getSize()).thenReturn(capacity); + when(s2.getSize()).thenReturn(capacity); + when(s2.getDeliveryLocation()).thenReturn(Location.Builder.newInstance().setId("delLoc").build()); + Vehicle vehicle = mock(Vehicle.class); + when(vehicle.isReturnToDepot()).thenReturn(false); + when(vehicle.getStartLocation()).thenReturn(Location.Builder.newInstance().setId("vehLoc").build()); + VehicleRoute.Builder builder = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class)); + builder.addPickup(s); + builder.addPickup(s2); + builder.addDelivery(s); + builder.addDelivery(s2); + builder.setDepartureTime(100); + VehicleRoute route = builder.build(); + assertEquals(100.0, route.getDepartureTime(), 0.01); + assertEquals(100.0, route.getStart().getEndTime(), 0.01); + } + + + @Test + public void whenSettingEndTime() { + Shipment s = mock(Shipment.class); + Shipment s2 = mock(Shipment.class); + Capacity capacity = Capacity.Builder.newInstance().build(); + when(s.getSize()).thenReturn(capacity); + when(s2.getSize()).thenReturn(capacity); + when(s2.getDeliveryLocation()).thenReturn(Location.Builder.newInstance().setId("delLoc").build()); + Vehicle vehicle = mock(Vehicle.class); + when(vehicle.isReturnToDepot()).thenReturn(false); + when(vehicle.getStartLocation()).thenReturn(Location.Builder.newInstance().setId("vehLoc").build()); + when(vehicle.getLatestArrival()).thenReturn(200.0); + VehicleRoute.Builder builder = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class)); + builder.addPickup(s); + builder.addPickup(s2); + builder.addDelivery(s); + builder.addDelivery(s2); + builder.setRouteEndArrivalTime(100.0); + VehicleRoute route = builder.build(); + assertEquals(100.0, route.getEnd().getArrTime(), 0.01); + } } diff --git a/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/BreakActivityTest.java b/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/BreakActivityTest.java new file mode 100644 index 00000000..0d168850 --- /dev/null +++ b/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/BreakActivityTest.java @@ -0,0 +1,106 @@ +/******************************************************************************* + * Copyright (C) 2014 Stefan Schroeder + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3.0 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + ******************************************************************************/ +package jsprit.core.problem.solution.route.activity; + +import jsprit.core.problem.Location; +import jsprit.core.problem.job.Break; +import jsprit.core.problem.job.Service; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.*; + + +public class BreakActivityTest { + + private Break service; + + private BreakActivity serviceActivity; + + @Before + public void doBefore() { + service = (Break) Break.Builder.newInstance("service") + .setTimeWindow(TimeWindow.newInstance(1., 2.)).setServiceTime(3).build(); + serviceActivity = BreakActivity.newInstance(service); + } + + @Test + public void whenCallingCapacity_itShouldReturnCorrectCapacity() { + assertEquals(0, serviceActivity.getSize().get(0)); + } + + @Test + public void hasVariableLocationShouldBeTrue() { + Break aBreak = (Break) serviceActivity.getJob(); + assertTrue(aBreak.hasVariableLocation()); + } + + + @Test + public void whenStartIsIniWithEarliestStart_itShouldBeSetCorrectly() { + assertEquals(1., serviceActivity.getTheoreticalEarliestOperationStartTime(), 0.01); + } + + @Test + public void whenStartIsIniWithLatestStart_itShouldBeSetCorrectly() { + assertEquals(2., serviceActivity.getTheoreticalLatestOperationStartTime(), 0.01); + } + + @Test + public void whenSettingArrTime_itShouldBeSetCorrectly() { + serviceActivity.setArrTime(4.0); + assertEquals(4., serviceActivity.getArrTime(), 0.01); + } + + @Test + public void whenSettingEndTime_itShouldBeSetCorrectly() { + serviceActivity.setEndTime(5.0); + assertEquals(5., serviceActivity.getEndTime(), 0.01); + } + + + @Test + public void whenCopyingStart_itShouldBeDoneCorrectly() { + BreakActivity copy = (BreakActivity) serviceActivity.duplicate(); + assertEquals(1., copy.getTheoreticalEarliestOperationStartTime(), 0.01); + assertEquals(2., copy.getTheoreticalLatestOperationStartTime(), 0.01); + assertTrue(copy != serviceActivity); + } + + + @Test + public void whenTwoDeliveriesHaveTheSameUnderlyingJob_theyAreEqual() { + Service s1 = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")).build(); + Service s2 = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")).build(); + + ServiceActivity d1 = ServiceActivity.newInstance(s1); + ServiceActivity d2 = ServiceActivity.newInstance(s2); + + assertTrue(d1.equals(d2)); + } + + @Test + public void whenTwoDeliveriesHaveTheDifferentUnderlyingJob_theyAreNotEqual() { + Service s1 = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")).build(); + Service s2 = Service.Builder.newInstance("s1").setLocation(Location.newInstance("loc")).build(); + + ServiceActivity d1 = ServiceActivity.newInstance(s1); + ServiceActivity d2 = ServiceActivity.newInstance(s2); + + assertFalse(d1.equals(d2)); + } +} diff --git a/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/DefaultShipmentActivityFactoryTest.java b/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/DefaultShipmentActivityFactoryTest.java index 7b2232c1..cbfdae55 100644 --- a/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/DefaultShipmentActivityFactoryTest.java +++ b/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/DefaultShipmentActivityFactoryTest.java @@ -24,24 +24,24 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; public class DefaultShipmentActivityFactoryTest { - - @Test - public void whenCreatingPickupActivityWithShipment_itShouldReturnPickupShipment(){ - DefaultShipmentActivityFactory factory = new DefaultShipmentActivityFactory(); - Shipment shipment = Shipment.Builder.newInstance("s") - .setPickupLocation(Location.Builder.newInstance().setId("pLoc").build()).setDeliveryLocation(Location.newInstance("dLoc")).build(); - TourActivity act = factory.createPickup(shipment); - assertNotNull(act); - assertTrue(act instanceof PickupShipment); - } - - @Test - public void whenCreatingDeliverActivityWithShipment_itShouldReturnDeliverShipment(){ - DefaultShipmentActivityFactory factory = new DefaultShipmentActivityFactory(); - Shipment shipment = Shipment.Builder.newInstance("s") - .setPickupLocation(Location.Builder.newInstance().setId("pLoc").build()).setDeliveryLocation(Location.newInstance("dLoc")).build(); - TourActivity act = factory.createDelivery(shipment); - assertNotNull(act); - assertTrue(act instanceof DeliverShipment); - } + + @Test + public void whenCreatingPickupActivityWithShipment_itShouldReturnPickupShipment() { + DefaultShipmentActivityFactory factory = new DefaultShipmentActivityFactory(); + Shipment shipment = Shipment.Builder.newInstance("s") + .setPickupLocation(Location.Builder.newInstance().setId("pLoc").build()).setDeliveryLocation(Location.newInstance("dLoc")).build(); + TourActivity act = factory.createPickup(shipment); + assertNotNull(act); + assertTrue(act instanceof PickupShipment); + } + + @Test + public void whenCreatingDeliverActivityWithShipment_itShouldReturnDeliverShipment() { + DefaultShipmentActivityFactory factory = new DefaultShipmentActivityFactory(); + Shipment shipment = Shipment.Builder.newInstance("s") + .setPickupLocation(Location.Builder.newInstance().setId("pLoc").build()).setDeliveryLocation(Location.newInstance("dLoc")).build(); + TourActivity act = factory.createDelivery(shipment); + assertNotNull(act); + assertTrue(act instanceof DeliverShipment); + } } diff --git a/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/DefaultTourActivityFactoryTest.java b/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/DefaultTourActivityFactoryTest.java index 21828380..452b005b 100644 --- a/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/DefaultTourActivityFactoryTest.java +++ b/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/DefaultTourActivityFactoryTest.java @@ -1,18 +1,18 @@ /******************************************************************************* * Copyright (c) 2014 Stefan Schroeder. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . - * + * * Contributors: * Stefan Schroeder - initial API and implementation ******************************************************************************/ @@ -28,32 +28,32 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; public class DefaultTourActivityFactoryTest { - - @Test - public void whenCreatingActivityWithService_itShouldReturnPickupService(){ - DefaultTourActivityFactory factory = new DefaultTourActivityFactory(); - Service service = Service.Builder.newInstance("service").setLocation(Location.newInstance("loc")).build(); - TourActivity act = factory.createActivity(service); - assertNotNull(act); - assertTrue(act instanceof PickupService); - } - - @Test - public void whenCreatingActivityWithPickup_itShouldReturnPickupService(){ - DefaultTourActivityFactory factory = new DefaultTourActivityFactory(); - Pickup service = (Pickup) Pickup.Builder.newInstance("service").setLocation(Location.newInstance("loc")).build(); - TourActivity act = factory.createActivity(service); - assertNotNull(act); - assertTrue(act instanceof PickupService); - } - - @Test - public void whenCreatingActivityWithDelivery_itShouldReturnDeliverService(){ - DefaultTourActivityFactory factory = new DefaultTourActivityFactory(); - Delivery service = (Delivery) Delivery.Builder.newInstance("service").setLocation(Location.newInstance("loc")).build(); - TourActivity act = factory.createActivity(service); - assertNotNull(act); - assertTrue(act instanceof DeliverService); - } + + @Test + public void whenCreatingActivityWithService_itShouldReturnPickupService() { + DefaultTourActivityFactory factory = new DefaultTourActivityFactory(); + Service service = Service.Builder.newInstance("service").setLocation(Location.newInstance("loc")).build(); + TourActivity act = factory.createActivity(service); + assertNotNull(act); + assertTrue(act instanceof PickupService); + } + + @Test + public void whenCreatingActivityWithPickup_itShouldReturnPickupService() { + DefaultTourActivityFactory factory = new DefaultTourActivityFactory(); + Pickup service = (Pickup) Pickup.Builder.newInstance("service").setLocation(Location.newInstance("loc")).build(); + TourActivity act = factory.createActivity(service); + assertNotNull(act); + assertTrue(act instanceof PickupService); + } + + @Test + public void whenCreatingActivityWithDelivery_itShouldReturnDeliverService() { + DefaultTourActivityFactory factory = new DefaultTourActivityFactory(); + Delivery service = (Delivery) Delivery.Builder.newInstance("service").setLocation(Location.newInstance("loc")).build(); + TourActivity act = factory.createActivity(service); + assertNotNull(act); + assertTrue(act instanceof DeliverService); + } } diff --git a/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/DeliverServiceTest.java b/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/DeliverServiceTest.java index b26b3c76..880ca947 100644 --- a/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/DeliverServiceTest.java +++ b/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/DeliverServiceTest.java @@ -26,62 +26,62 @@ import static org.junit.Assert.assertTrue; public class DeliverServiceTest { - private Delivery service; - - private DeliverService deliver; - - @Before - public void doBefore(){ - service = (Delivery) Delivery.Builder.newInstance("service").setLocation(Location.newInstance("loc")). - setTimeWindow(TimeWindow.newInstance(1., 2.)). - addSizeDimension(0, 10).addSizeDimension(1, 100).addSizeDimension(2, 1000).build(); - deliver = new DeliverService(service); - } - - @Test - public void whenCallingCapacity_itShouldReturnCorrectCapacity(){ - assertEquals(-10,deliver.getSize().get(0)); - assertEquals(-100,deliver.getSize().get(1)); - assertEquals(-1000,deliver.getSize().get(2)); - } - - @Test - public void whenStartIsIniWithEarliestStart_itShouldBeSetCorrectly(){ - assertEquals(1.,deliver.getTheoreticalEarliestOperationStartTime(),0.01); - } - - @Test - public void whenStartIsIniWithLatestStart_itShouldBeSetCorrectly(){ - assertEquals(2.,deliver.getTheoreticalLatestOperationStartTime(),0.01); - } - - @Test - public void whenSettingArrTime_itShouldBeSetCorrectly(){ - deliver.setArrTime(4.0); - assertEquals(4.,deliver.getArrTime(),0.01); - } - - @Test - public void whenSettingEndTime_itShouldBeSetCorrectly(){ - deliver.setEndTime(5.0); - assertEquals(5.,deliver.getEndTime(),0.01); - } - - @Test - public void whenIniLocationId_itShouldBeSetCorrectly(){ - assertEquals("loc",deliver.getLocation().getId()); - } - - @Test - public void whenCopyingStart_itShouldBeDoneCorrectly(){ - DeliverService copy = (DeliverService) deliver.duplicate(); - assertEquals(1.,copy.getTheoreticalEarliestOperationStartTime(),0.01); - assertEquals(2.,copy.getTheoreticalLatestOperationStartTime(),0.01); - assertEquals("loc",copy.getLocation().getId()); - assertEquals(-10,copy.getSize().get(0)); - assertEquals(-100,copy.getSize().get(1)); - assertEquals(-1000,copy.getSize().get(2)); - assertTrue(copy!=deliver); - } + private Delivery service; + + private DeliverService deliver; + + @Before + public void doBefore() { + service = (Delivery) Delivery.Builder.newInstance("service").setLocation(Location.newInstance("loc")). + setTimeWindow(TimeWindow.newInstance(1., 2.)). + addSizeDimension(0, 10).addSizeDimension(1, 100).addSizeDimension(2, 1000).build(); + deliver = new DeliverService(service); + } + + @Test + public void whenCallingCapacity_itShouldReturnCorrectCapacity() { + assertEquals(-10, deliver.getSize().get(0)); + assertEquals(-100, deliver.getSize().get(1)); + assertEquals(-1000, deliver.getSize().get(2)); + } + + @Test + public void whenStartIsIniWithEarliestStart_itShouldBeSetCorrectly() { + assertEquals(1., deliver.getTheoreticalEarliestOperationStartTime(), 0.01); + } + + @Test + public void whenStartIsIniWithLatestStart_itShouldBeSetCorrectly() { + assertEquals(2., deliver.getTheoreticalLatestOperationStartTime(), 0.01); + } + + @Test + public void whenSettingArrTime_itShouldBeSetCorrectly() { + deliver.setArrTime(4.0); + assertEquals(4., deliver.getArrTime(), 0.01); + } + + @Test + public void whenSettingEndTime_itShouldBeSetCorrectly() { + deliver.setEndTime(5.0); + assertEquals(5., deliver.getEndTime(), 0.01); + } + + @Test + public void whenIniLocationId_itShouldBeSetCorrectly() { + assertEquals("loc", deliver.getLocation().getId()); + } + + @Test + public void whenCopyingStart_itShouldBeDoneCorrectly() { + DeliverService copy = (DeliverService) deliver.duplicate(); + assertEquals(1., copy.getTheoreticalEarliestOperationStartTime(), 0.01); + assertEquals(2., copy.getTheoreticalLatestOperationStartTime(), 0.01); + assertEquals("loc", copy.getLocation().getId()); + assertEquals(-10, copy.getSize().get(0)); + assertEquals(-100, copy.getSize().get(1)); + assertEquals(-1000, copy.getSize().get(2)); + assertTrue(copy != deliver); + } } diff --git a/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/DeliverShipmentTest.java b/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/DeliverShipmentTest.java index d5d39dd3..c26fff73 100644 --- a/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/DeliverShipmentTest.java +++ b/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/DeliverShipmentTest.java @@ -25,73 +25,73 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; public class DeliverShipmentTest { - - private DeliverShipment deliver; - - @Before - public void doBefore(){ - Shipment shipment = Shipment.Builder.newInstance("shipment").setPickupLocation(Location.Builder.newInstance().setId("pickupLoc").build()) - .setDeliveryLocation(Location.newInstance("deliveryLoc")) - .setPickupTimeWindow(TimeWindow.newInstance(1., 2.)) - .setDeliveryTimeWindow(TimeWindow.newInstance(3., 4.)) - .addSizeDimension(0, 10).addSizeDimension(1, 100).addSizeDimension(2, 1000).build(); - deliver = new DeliverShipment(shipment); - } - - @Test - public void whenCallingCapacity_itShouldReturnCorrectCapacity(){ - assertEquals(-10,deliver.getSize().get(0)); - assertEquals(-100,deliver.getSize().get(1)); - assertEquals(-1000,deliver.getSize().get(2)); - } - @Test - public void whenStartIsIniWithEarliestStart_itShouldBeSetCorrectly(){ - assertEquals(3.,deliver.getTheoreticalEarliestOperationStartTime(),0.01); - } - - @Test - public void whenStartIsIniWithLatestStart_itShouldBeSetCorrectly(){ - assertEquals(4.,deliver.getTheoreticalLatestOperationStartTime(),0.01); - } - - @Test - public void whenSettingArrTime_itShouldBeSetCorrectly(){ - deliver.setArrTime(4.0); - assertEquals(4.,deliver.getArrTime(),0.01); - } - - @Test - public void whenSettingEndTime_itShouldBeSetCorrectly(){ - deliver.setEndTime(5.0); - assertEquals(5.,deliver.getEndTime(),0.01); - } - - @Test - public void whenIniLocationId_itShouldBeSetCorrectly(){ - assertEquals("deliveryLoc",deliver.getLocation().getId()); - } - - @Test - public void whenCopyingStart_itShouldBeDoneCorrectly(){ - DeliverShipment copy = (DeliverShipment) deliver.duplicate(); - assertEquals(3.,copy.getTheoreticalEarliestOperationStartTime(),0.01); - assertEquals(4.,copy.getTheoreticalLatestOperationStartTime(),0.01); - assertEquals("deliveryLoc",copy.getLocation().getId()); - assertEquals(-10,copy.getSize().get(0)); - assertEquals(-100,copy.getSize().get(1)); - assertEquals(-1000,copy.getSize().get(2)); - assertTrue(copy!=deliver); - } + private DeliverShipment deliver; - - @Test - public void whenGettingCapacity_itShouldReturnItCorrectly(){ - Shipment shipment = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).setDeliveryLocation(Location.newInstance("delLoc")) - .addSizeDimension(0, 10).addSizeDimension(1, 100).build(); - PickupShipment pick = new PickupShipment(shipment); - assertEquals(10,pick.getSize().get(0)); - assertEquals(100,pick.getSize().get(1)); - } + @Before + public void doBefore() { + Shipment shipment = Shipment.Builder.newInstance("shipment").setPickupLocation(Location.Builder.newInstance().setId("pickupLoc").build()) + .setDeliveryLocation(Location.newInstance("deliveryLoc")) + .setPickupTimeWindow(TimeWindow.newInstance(1., 2.)) + .setDeliveryTimeWindow(TimeWindow.newInstance(3., 4.)) + .addSizeDimension(0, 10).addSizeDimension(1, 100).addSizeDimension(2, 1000).build(); + deliver = new DeliverShipment(shipment); + } + + @Test + public void whenCallingCapacity_itShouldReturnCorrectCapacity() { + assertEquals(-10, deliver.getSize().get(0)); + assertEquals(-100, deliver.getSize().get(1)); + assertEquals(-1000, deliver.getSize().get(2)); + } + + @Test + public void whenStartIsIniWithEarliestStart_itShouldBeSetCorrectly() { + assertEquals(3., deliver.getTheoreticalEarliestOperationStartTime(), 0.01); + } + + @Test + public void whenStartIsIniWithLatestStart_itShouldBeSetCorrectly() { + assertEquals(4., deliver.getTheoreticalLatestOperationStartTime(), 0.01); + } + + @Test + public void whenSettingArrTime_itShouldBeSetCorrectly() { + deliver.setArrTime(4.0); + assertEquals(4., deliver.getArrTime(), 0.01); + } + + @Test + public void whenSettingEndTime_itShouldBeSetCorrectly() { + deliver.setEndTime(5.0); + assertEquals(5., deliver.getEndTime(), 0.01); + } + + @Test + public void whenIniLocationId_itShouldBeSetCorrectly() { + assertEquals("deliveryLoc", deliver.getLocation().getId()); + } + + @Test + public void whenCopyingStart_itShouldBeDoneCorrectly() { + DeliverShipment copy = (DeliverShipment) deliver.duplicate(); + assertEquals(3., copy.getTheoreticalEarliestOperationStartTime(), 0.01); + assertEquals(4., copy.getTheoreticalLatestOperationStartTime(), 0.01); + assertEquals("deliveryLoc", copy.getLocation().getId()); + assertEquals(-10, copy.getSize().get(0)); + assertEquals(-100, copy.getSize().get(1)); + assertEquals(-1000, copy.getSize().get(2)); + assertTrue(copy != deliver); + } + + + @Test + public void whenGettingCapacity_itShouldReturnItCorrectly() { + Shipment shipment = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).setDeliveryLocation(Location.newInstance("delLoc")) + .addSizeDimension(0, 10).addSizeDimension(1, 100).build(); + PickupShipment pick = new PickupShipment(shipment); + assertEquals(10, pick.getSize().get(0)); + assertEquals(100, pick.getSize().get(1)); + } } diff --git a/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/EndTest.java b/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/EndTest.java index 717002f8..e28d372c 100644 --- a/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/EndTest.java +++ b/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/EndTest.java @@ -22,64 +22,64 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; public class EndTest { - - @Test - public void whenCallingCapacity_itShouldReturnEmptyCapacity(){ - End end = End.newInstance("loc", 0., 0.); - assertEquals(0,end.getSize().get(0)); - } - @Test - public void whenStartIsIniWithEarliestStart_itShouldBeSetCorrectly(){ - End end = End.newInstance("loc", 1., 2.); - assertEquals(1.,end.getTheoreticalEarliestOperationStartTime(),0.01); - } - - @Test - public void whenStartIsIniWithLatestStart_itShouldBeSetCorrectly(){ - End end = End.newInstance("loc", 1., 2.); - assertEquals(2.,end.getTheoreticalLatestOperationStartTime(),0.01); - } - - @Test - public void whenSettingEndTime_itShouldBeSetCorrectly(){ - End end = End.newInstance("loc", 1., 2.); - end.setEndTime(4.0); - assertEquals(4.,end.getEndTime(),0.01); - } - - @Test - public void whenSettingLocationId_itShouldBeSetCorrectly(){ - End end = End.newInstance("loc", 1., 2.); - end.setLocationId("newLoc"); - assertEquals("newLoc",end.getLocation().getId()); - } - - @Test - public void whenSettingEarliestStart_itShouldBeSetCorrectly(){ - End end = End.newInstance("loc", 1., 2.); - end.setTheoreticalEarliestOperationStartTime(5.); - assertEquals(5.,end.getTheoreticalEarliestOperationStartTime(),0.01); - } - - @Test - public void whenSettingLatestStart_itShouldBeSetCorrectly(){ - End end = End.newInstance("loc", 1., 2.); - end.setTheoreticalLatestOperationStartTime(5.); - assertEquals(5.,end.getTheoreticalLatestOperationStartTime(),0.01); - } + @Test + public void whenCallingCapacity_itShouldReturnEmptyCapacity() { + End end = End.newInstance("loc", 0., 0.); + assertEquals(0, end.getSize().get(0)); + } - @Test - public void whenCopyingEnd_itShouldBeDoneCorrectly(){ - End end = End.newInstance("loc", 1., 2.); - end.setTheoreticalEarliestOperationStartTime(3.); - end.setTheoreticalLatestOperationStartTime(5.); - - End copy = End.copyOf(end); - assertEquals(3.,copy.getTheoreticalEarliestOperationStartTime(),0.01); - assertEquals(5.,copy.getTheoreticalLatestOperationStartTime(),0.01); - assertEquals("loc",copy.getLocation().getId()); - assertTrue(copy!=end); - } + @Test + public void whenStartIsIniWithEarliestStart_itShouldBeSetCorrectly() { + End end = End.newInstance("loc", 1., 2.); + assertEquals(1., end.getTheoreticalEarliestOperationStartTime(), 0.01); + } + + @Test + public void whenStartIsIniWithLatestStart_itShouldBeSetCorrectly() { + End end = End.newInstance("loc", 1., 2.); + assertEquals(2., end.getTheoreticalLatestOperationStartTime(), 0.01); + } + + @Test + public void whenSettingEndTime_itShouldBeSetCorrectly() { + End end = End.newInstance("loc", 1., 2.); + end.setEndTime(4.0); + assertEquals(4., end.getEndTime(), 0.01); + } + + @Test + public void whenSettingLocationId_itShouldBeSetCorrectly() { + End end = End.newInstance("loc", 1., 2.); + end.setLocationId("newLoc"); + assertEquals("newLoc", end.getLocation().getId()); + } + + @Test + public void whenSettingEarliestStart_itShouldBeSetCorrectly() { + End end = End.newInstance("loc", 1., 2.); + end.setTheoreticalEarliestOperationStartTime(5.); + assertEquals(5., end.getTheoreticalEarliestOperationStartTime(), 0.01); + } + + @Test + public void whenSettingLatestStart_itShouldBeSetCorrectly() { + End end = End.newInstance("loc", 1., 2.); + end.setTheoreticalLatestOperationStartTime(5.); + assertEquals(5., end.getTheoreticalLatestOperationStartTime(), 0.01); + } + + @Test + public void whenCopyingEnd_itShouldBeDoneCorrectly() { + End end = End.newInstance("loc", 1., 2.); + end.setTheoreticalEarliestOperationStartTime(3.); + end.setTheoreticalLatestOperationStartTime(5.); + + End copy = End.copyOf(end); + assertEquals(3., copy.getTheoreticalEarliestOperationStartTime(), 0.01); + assertEquals(5., copy.getTheoreticalLatestOperationStartTime(), 0.01); + assertEquals("loc", copy.getLocation().getId()); + assertTrue(copy != end); + } } diff --git a/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/PickupServiceTest.java b/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/PickupServiceTest.java index 3f34730e..2593ff2a 100644 --- a/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/PickupServiceTest.java +++ b/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/PickupServiceTest.java @@ -25,64 +25,64 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; public class PickupServiceTest { - - private Service service; - - private PickupService pickup; - - @Before - public void doBefore(){ - service = Service.Builder.newInstance("service").setLocation(Location.newInstance("loc")). - setTimeWindow(TimeWindow.newInstance(1., 2.)). - addSizeDimension(0, 10).addSizeDimension(1, 100).addSizeDimension(2, 1000).build(); - pickup = new PickupService(service); - } - - @Test - public void whenCallingCapacity_itShouldReturnCorrectCapacity(){ - assertEquals(10,pickup.getSize().get(0)); - assertEquals(100,pickup.getSize().get(1)); - assertEquals(1000,pickup.getSize().get(2)); - } - - @Test - public void whenStartIsIniWithEarliestStart_itShouldBeSetCorrectly(){ - assertEquals(1.,pickup.getTheoreticalEarliestOperationStartTime(),0.01); - } - - @Test - public void whenStartIsIniWithLatestStart_itShouldBeSetCorrectly(){ - assertEquals(2.,pickup.getTheoreticalLatestOperationStartTime(),0.01); - } - - @Test - public void whenSettingArrTime_itShouldBeSetCorrectly(){ - pickup.setArrTime(4.0); - assertEquals(4.,pickup.getArrTime(),0.01); - } - - @Test - public void whenSettingEndTime_itShouldBeSetCorrectly(){ - pickup.setEndTime(5.0); - assertEquals(5.,pickup.getEndTime(),0.01); - } - - @Test - public void whenIniLocationId_itShouldBeSetCorrectly(){ - assertEquals("loc",pickup.getLocation().getId()); - } - - @Test - public void whenCopyingStart_itShouldBeDoneCorrectly(){ - PickupService copy = (PickupService) pickup.duplicate(); - assertEquals(1.,copy.getTheoreticalEarliestOperationStartTime(),0.01); - assertEquals(2.,copy.getTheoreticalLatestOperationStartTime(),0.01); - assertEquals("loc",copy.getLocation().getId()); - assertEquals(10,copy.getSize().get(0)); - assertEquals(100,copy.getSize().get(1)); - assertEquals(1000,copy.getSize().get(2)); - assertTrue(copy!=pickup); - } + private Service service; + + private PickupService pickup; + + @Before + public void doBefore() { + service = Service.Builder.newInstance("service").setLocation(Location.newInstance("loc")). + setTimeWindow(TimeWindow.newInstance(1., 2.)). + addSizeDimension(0, 10).addSizeDimension(1, 100).addSizeDimension(2, 1000).build(); + pickup = new PickupService(service); + } + + @Test + public void whenCallingCapacity_itShouldReturnCorrectCapacity() { + assertEquals(10, pickup.getSize().get(0)); + assertEquals(100, pickup.getSize().get(1)); + assertEquals(1000, pickup.getSize().get(2)); + } + + + @Test + public void whenStartIsIniWithEarliestStart_itShouldBeSetCorrectly() { + assertEquals(1., pickup.getTheoreticalEarliestOperationStartTime(), 0.01); + } + + @Test + public void whenStartIsIniWithLatestStart_itShouldBeSetCorrectly() { + assertEquals(2., pickup.getTheoreticalLatestOperationStartTime(), 0.01); + } + + @Test + public void whenSettingArrTime_itShouldBeSetCorrectly() { + pickup.setArrTime(4.0); + assertEquals(4., pickup.getArrTime(), 0.01); + } + + @Test + public void whenSettingEndTime_itShouldBeSetCorrectly() { + pickup.setEndTime(5.0); + assertEquals(5., pickup.getEndTime(), 0.01); + } + + @Test + public void whenIniLocationId_itShouldBeSetCorrectly() { + assertEquals("loc", pickup.getLocation().getId()); + } + + @Test + public void whenCopyingStart_itShouldBeDoneCorrectly() { + PickupService copy = (PickupService) pickup.duplicate(); + assertEquals(1., copy.getTheoreticalEarliestOperationStartTime(), 0.01); + assertEquals(2., copy.getTheoreticalLatestOperationStartTime(), 0.01); + assertEquals("loc", copy.getLocation().getId()); + assertEquals(10, copy.getSize().get(0)); + assertEquals(100, copy.getSize().get(1)); + assertEquals(1000, copy.getSize().get(2)); + assertTrue(copy != pickup); + } } diff --git a/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/PickupShipmentTest.java b/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/PickupShipmentTest.java index e1293350..3627d7c0 100644 --- a/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/PickupShipmentTest.java +++ b/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/PickupShipmentTest.java @@ -26,72 +26,72 @@ import static org.junit.Assert.assertTrue; public class PickupShipmentTest { - private PickupShipment pickup; - - @Before - public void doBefore(){ - Shipment shipment = Shipment.Builder.newInstance("shipment").setPickupLocation(Location.Builder.newInstance().setId("pickupLoc").build()) - .setDeliveryLocation(Location.newInstance("deliveryLoc")) - .setPickupTimeWindow(TimeWindow.newInstance(1., 2.)) - .setDeliveryTimeWindow(TimeWindow.newInstance(3., 4.)) - .addSizeDimension(0, 10).addSizeDimension(1, 100).addSizeDimension(2, 1000).build(); - pickup = new PickupShipment(shipment); - } - - @Test - public void whenCallingCapacity_itShouldReturnCorrectCapacity(){ - assertEquals(10,pickup.getSize().get(0)); - assertEquals(100,pickup.getSize().get(1)); - assertEquals(1000,pickup.getSize().get(2)); - } + private PickupShipment pickup; - @Test - public void whenStartIsIniWithEarliestStart_itShouldBeSetCorrectly(){ - assertEquals(1.,pickup.getTheoreticalEarliestOperationStartTime(),0.01); - } - - @Test - public void whenStartIsIniWithLatestStart_itShouldBeSetCorrectly(){ - assertEquals(2.,pickup.getTheoreticalLatestOperationStartTime(),0.01); - } - - @Test - public void whenSettingArrTime_itShouldBeSetCorrectly(){ - pickup.setArrTime(4.0); - assertEquals(4.,pickup.getArrTime(),0.01); - } - - @Test - public void whenSettingEndTime_itShouldBeSetCorrectly(){ - pickup.setEndTime(5.0); - assertEquals(5.,pickup.getEndTime(),0.01); - } - - @Test - public void whenIniLocationId_itShouldBeSetCorrectly(){ - assertEquals("pickupLoc",pickup.getLocation().getId()); - } - - @Test - public void whenCopyingStart_itShouldBeDoneCorrectly(){ - PickupShipment copy = (PickupShipment) pickup.duplicate(); - assertEquals(1.,copy.getTheoreticalEarliestOperationStartTime(),0.01); - assertEquals(2.,copy.getTheoreticalLatestOperationStartTime(),0.01); - assertEquals("pickupLoc",copy.getLocation().getId()); - assertEquals(10,copy.getSize().get(0)); - assertEquals(100,copy.getSize().get(1)); - assertEquals(1000,copy.getSize().get(2)); - assertTrue(copy!=pickup); - } + @Before + public void doBefore() { + Shipment shipment = Shipment.Builder.newInstance("shipment").setPickupLocation(Location.Builder.newInstance().setId("pickupLoc").build()) + .setDeliveryLocation(Location.newInstance("deliveryLoc")) + .setPickupTimeWindow(TimeWindow.newInstance(1., 2.)) + .setDeliveryTimeWindow(TimeWindow.newInstance(3., 4.)) + .addSizeDimension(0, 10).addSizeDimension(1, 100).addSizeDimension(2, 1000).build(); + pickup = new PickupShipment(shipment); + } + + @Test + public void whenCallingCapacity_itShouldReturnCorrectCapacity() { + assertEquals(10, pickup.getSize().get(0)); + assertEquals(100, pickup.getSize().get(1)); + assertEquals(1000, pickup.getSize().get(2)); + } + + @Test + public void whenStartIsIniWithEarliestStart_itShouldBeSetCorrectly() { + assertEquals(1., pickup.getTheoreticalEarliestOperationStartTime(), 0.01); + } + + @Test + public void whenStartIsIniWithLatestStart_itShouldBeSetCorrectly() { + assertEquals(2., pickup.getTheoreticalLatestOperationStartTime(), 0.01); + } + + @Test + public void whenSettingArrTime_itShouldBeSetCorrectly() { + pickup.setArrTime(4.0); + assertEquals(4., pickup.getArrTime(), 0.01); + } + + @Test + public void whenSettingEndTime_itShouldBeSetCorrectly() { + pickup.setEndTime(5.0); + assertEquals(5., pickup.getEndTime(), 0.01); + } + + @Test + public void whenIniLocationId_itShouldBeSetCorrectly() { + assertEquals("pickupLoc", pickup.getLocation().getId()); + } + + @Test + public void whenCopyingStart_itShouldBeDoneCorrectly() { + PickupShipment copy = (PickupShipment) pickup.duplicate(); + assertEquals(1., copy.getTheoreticalEarliestOperationStartTime(), 0.01); + assertEquals(2., copy.getTheoreticalLatestOperationStartTime(), 0.01); + assertEquals("pickupLoc", copy.getLocation().getId()); + assertEquals(10, copy.getSize().get(0)); + assertEquals(100, copy.getSize().get(1)); + assertEquals(1000, copy.getSize().get(2)); + assertTrue(copy != pickup); + } + + + @Test + public void whenGettingCapacity_itShouldReturnItCorrectly() { + Shipment shipment = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).setDeliveryLocation(Location.newInstance("delLoc")) + .addSizeDimension(0, 10).addSizeDimension(1, 100).build(); + PickupShipment pick = new PickupShipment(shipment); + assertEquals(10, pick.getSize().get(0)); + assertEquals(100, pick.getSize().get(1)); + } - - @Test - public void whenGettingCapacity_itShouldReturnItCorrectly(){ - Shipment shipment = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).setDeliveryLocation(Location.newInstance("delLoc")) - .addSizeDimension(0, 10).addSizeDimension(1, 100).build(); - PickupShipment pick = new PickupShipment(shipment); - assertEquals(10,pick.getSize().get(0)); - assertEquals(100,pick.getSize().get(1)); - } - } diff --git a/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/ServiceActivityTest.java b/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/ServiceActivityTest.java index 85a28177..15ead4cd 100644 --- a/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/ServiceActivityTest.java +++ b/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/ServiceActivityTest.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.problem.solution.route.activity; @@ -25,83 +25,83 @@ import static org.junit.Assert.*; public class ServiceActivityTest { - - private Service service; - - private ServiceActivity serviceActivity; - - @Before - public void doBefore(){ - service = Service.Builder.newInstance("service").setLocation(Location.newInstance("loc")). - setTimeWindow(TimeWindow.newInstance(1., 2.)). - addSizeDimension(0, 10).addSizeDimension(1, 100).addSizeDimension(2, 1000).build(); - serviceActivity = ServiceActivity.newInstance(service); - } - - @Test - public void whenCallingCapacity_itShouldReturnCorrectCapacity(){ - assertEquals(10,serviceActivity.getSize().get(0)); - assertEquals(100,serviceActivity.getSize().get(1)); - assertEquals(1000,serviceActivity.getSize().get(2)); - } - - @Test - public void whenStartIsIniWithEarliestStart_itShouldBeSetCorrectly(){ - assertEquals(1.,serviceActivity.getTheoreticalEarliestOperationStartTime(),0.01); - } - - @Test - public void whenStartIsIniWithLatestStart_itShouldBeSetCorrectly(){ - assertEquals(2.,serviceActivity.getTheoreticalLatestOperationStartTime(),0.01); - } - - @Test - public void whenSettingArrTime_itShouldBeSetCorrectly(){ - serviceActivity.setArrTime(4.0); - assertEquals(4.,serviceActivity.getArrTime(),0.01); - } - - @Test - public void whenSettingEndTime_itShouldBeSetCorrectly(){ - serviceActivity.setEndTime(5.0); - assertEquals(5.,serviceActivity.getEndTime(),0.01); - } - - @Test - public void whenIniLocationId_itShouldBeSetCorrectly(){ - assertEquals("loc",serviceActivity.getLocation().getId()); - } - - @Test - public void whenCopyingStart_itShouldBeDoneCorrectly(){ - ServiceActivity copy = (ServiceActivity) serviceActivity.duplicate(); - assertEquals(1.,copy.getTheoreticalEarliestOperationStartTime(),0.01); - assertEquals(2.,copy.getTheoreticalLatestOperationStartTime(),0.01); - assertEquals("loc",copy.getLocation().getId()); - assertTrue(copy!=serviceActivity); - } + private Service service; - - @Test - public void whenTwoDeliveriesHaveTheSameUnderlyingJob_theyAreEqual(){ - Service s1 = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")).build(); - Service s2 = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")).build(); - - ServiceActivity d1 = ServiceActivity.newInstance(s1); - ServiceActivity d2 = ServiceActivity.newInstance(s2); - - assertTrue(d1.equals(d2)); - } - - @Test - public void whenTwoDeliveriesHaveTheDifferentUnderlyingJob_theyAreNotEqual(){ - Service s1 = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")).build(); - Service s2 = Service.Builder.newInstance("s1").setLocation(Location.newInstance("loc")).build(); - - ServiceActivity d1 = ServiceActivity.newInstance(s1); - ServiceActivity d2 = ServiceActivity.newInstance(s2); - - assertFalse(d1.equals(d2)); - } + private ServiceActivity serviceActivity; + + @Before + public void doBefore() { + service = Service.Builder.newInstance("service").setLocation(Location.newInstance("loc")). + setTimeWindow(TimeWindow.newInstance(1., 2.)). + addSizeDimension(0, 10).addSizeDimension(1, 100).addSizeDimension(2, 1000).build(); + serviceActivity = ServiceActivity.newInstance(service); + } + + @Test + public void whenCallingCapacity_itShouldReturnCorrectCapacity() { + assertEquals(10, serviceActivity.getSize().get(0)); + assertEquals(100, serviceActivity.getSize().get(1)); + assertEquals(1000, serviceActivity.getSize().get(2)); + } + + + @Test + public void whenStartIsIniWithEarliestStart_itShouldBeSetCorrectly() { + assertEquals(1., serviceActivity.getTheoreticalEarliestOperationStartTime(), 0.01); + } + + @Test + public void whenStartIsIniWithLatestStart_itShouldBeSetCorrectly() { + assertEquals(2., serviceActivity.getTheoreticalLatestOperationStartTime(), 0.01); + } + + @Test + public void whenSettingArrTime_itShouldBeSetCorrectly() { + serviceActivity.setArrTime(4.0); + assertEquals(4., serviceActivity.getArrTime(), 0.01); + } + + @Test + public void whenSettingEndTime_itShouldBeSetCorrectly() { + serviceActivity.setEndTime(5.0); + assertEquals(5., serviceActivity.getEndTime(), 0.01); + } + + @Test + public void whenIniLocationId_itShouldBeSetCorrectly() { + assertEquals("loc", serviceActivity.getLocation().getId()); + } + + @Test + public void whenCopyingStart_itShouldBeDoneCorrectly() { + ServiceActivity copy = (ServiceActivity) serviceActivity.duplicate(); + assertEquals(1., copy.getTheoreticalEarliestOperationStartTime(), 0.01); + assertEquals(2., copy.getTheoreticalLatestOperationStartTime(), 0.01); + assertEquals("loc", copy.getLocation().getId()); + assertTrue(copy != serviceActivity); + } + + + @Test + public void whenTwoDeliveriesHaveTheSameUnderlyingJob_theyAreEqual() { + Service s1 = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")).build(); + Service s2 = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")).build(); + + ServiceActivity d1 = ServiceActivity.newInstance(s1); + ServiceActivity d2 = ServiceActivity.newInstance(s2); + + assertTrue(d1.equals(d2)); + } + + @Test + public void whenTwoDeliveriesHaveTheDifferentUnderlyingJob_theyAreNotEqual() { + Service s1 = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")).build(); + Service s2 = Service.Builder.newInstance("s1").setLocation(Location.newInstance("loc")).build(); + + ServiceActivity d1 = ServiceActivity.newInstance(s1); + ServiceActivity d2 = ServiceActivity.newInstance(s2); + + assertFalse(d1.equals(d2)); + } } diff --git a/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/StartTest.java b/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/StartTest.java index ceb92e12..89d5bb0b 100644 --- a/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/StartTest.java +++ b/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/StartTest.java @@ -22,64 +22,64 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; public class StartTest { - - @Test - public void whenCallingCapacity_itShouldReturnEmptyCapacity(){ - Start start = Start.newInstance("loc", 0., 0.); - assertEquals(0,start.getSize().get(0)); - } - - @Test - public void whenStartIsIniWithEarliestStart_itShouldBeSetCorrectly(){ - Start start = Start.newInstance("loc", 1., 2.); - assertEquals(1.,start.getTheoreticalEarliestOperationStartTime(),0.01); - } - - @Test - public void whenStartIsIniWithLatestStart_itShouldBeSetCorrectly(){ - Start start = Start.newInstance("loc", 1., 2.); - assertEquals(2.,start.getTheoreticalLatestOperationStartTime(),0.01); - } - - @Test - public void whenSettingStartEndTime_itShouldBeSetCorrectly(){ - Start start = Start.newInstance("loc", 1., 2.); - start.setEndTime(4.0); - assertEquals(4.,start.getEndTime(),0.01); - } - - @Test - public void whenSettingLocationId_itShouldBeSetCorrectly(){ - Start start = Start.newInstance("loc", 1., 2.); - start.setLocationId("newLoc"); - assertEquals("newLoc",start.getLocation().getId()); - } - - @Test - public void whenSettingEarliestStart_itShouldBeSetCorrectly(){ - Start start = Start.newInstance("loc", 1., 2.); - start.setTheoreticalEarliestOperationStartTime(5.); - assertEquals(5.,start.getTheoreticalEarliestOperationStartTime(),0.01); - } - - @Test - public void whenSettingLatestStart_itShouldBeSetCorrectly(){ - Start start = Start.newInstance("loc", 1., 2.); - start.setTheoreticalLatestOperationStartTime(5.); - assertEquals(5.,start.getTheoreticalLatestOperationStartTime(),0.01); - } - - @Test - public void whenCopyingStart_itShouldBeDoneCorrectly(){ - Start start = Start.newInstance("loc", 1., 2.); - start.setTheoreticalEarliestOperationStartTime(3.); - start.setTheoreticalLatestOperationStartTime(5.); - - Start copy = Start.copyOf(start); - assertEquals(3.,copy.getTheoreticalEarliestOperationStartTime(),0.01); - assertEquals(5.,copy.getTheoreticalLatestOperationStartTime(),0.01); - assertEquals("loc",copy.getLocation().getId()); - assertTrue(copy!=start); - } - + + @Test + public void whenCallingCapacity_itShouldReturnEmptyCapacity() { + Start start = Start.newInstance("loc", 0., 0.); + assertEquals(0, start.getSize().get(0)); + } + + @Test + public void whenStartIsIniWithEarliestStart_itShouldBeSetCorrectly() { + Start start = Start.newInstance("loc", 1., 2.); + assertEquals(1., start.getTheoreticalEarliestOperationStartTime(), 0.01); + } + + @Test + public void whenStartIsIniWithLatestStart_itShouldBeSetCorrectly() { + Start start = Start.newInstance("loc", 1., 2.); + assertEquals(2., start.getTheoreticalLatestOperationStartTime(), 0.01); + } + + @Test + public void whenSettingStartEndTime_itShouldBeSetCorrectly() { + Start start = Start.newInstance("loc", 1., 2.); + start.setEndTime(4.0); + assertEquals(4., start.getEndTime(), 0.01); + } + + @Test + public void whenSettingLocationId_itShouldBeSetCorrectly() { + Start start = Start.newInstance("loc", 1., 2.); + start.setLocationId("newLoc"); + assertEquals("newLoc", start.getLocation().getId()); + } + + @Test + public void whenSettingEarliestStart_itShouldBeSetCorrectly() { + Start start = Start.newInstance("loc", 1., 2.); + start.setTheoreticalEarliestOperationStartTime(5.); + assertEquals(5., start.getTheoreticalEarliestOperationStartTime(), 0.01); + } + + @Test + public void whenSettingLatestStart_itShouldBeSetCorrectly() { + Start start = Start.newInstance("loc", 1., 2.); + start.setTheoreticalLatestOperationStartTime(5.); + assertEquals(5., start.getTheoreticalLatestOperationStartTime(), 0.01); + } + + @Test + public void whenCopyingStart_itShouldBeDoneCorrectly() { + Start start = Start.newInstance("loc", 1., 2.); + start.setTheoreticalEarliestOperationStartTime(3.); + start.setTheoreticalLatestOperationStartTime(5.); + + Start copy = Start.copyOf(start); + assertEquals(3., copy.getTheoreticalEarliestOperationStartTime(), 0.01); + assertEquals(5., copy.getTheoreticalLatestOperationStartTime(), 0.01); + assertEquals("loc", copy.getLocation().getId()); + assertTrue(copy != start); + } + } diff --git a/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/TestRefs.java b/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/TestRefs.java index 92c17f6d..30769249 100644 --- a/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/TestRefs.java +++ b/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/TestRefs.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.problem.solution.route.activity; @@ -25,26 +25,26 @@ import static org.junit.Assert.assertTrue; public class TestRefs { - - @Test - public void testReferencs(){ - List starts = new ArrayList(); - starts.add(Start.newInstance("foo0", 0.0, 0.0)); - starts.add(Start.newInstance("foo1", 1.0, 1.0)); - - doSmth(starts); - - assertTrue(starts.get(0).getLocation().getId().startsWith("foo")); - assertTrue(starts.get(1).getLocation().getId().startsWith("foo")); - } - private void doSmth(List starts) { - int count = 0; - for(@SuppressWarnings("unused") Start s : starts){ - s = Start.newInstance("yo_"+count,0.0,0.0); - count++; - } - - } + @Test + public void testReferencs() { + List starts = new ArrayList(); + starts.add(Start.newInstance("foo0", 0.0, 0.0)); + starts.add(Start.newInstance("foo1", 1.0, 1.0)); + + doSmth(starts); + + assertTrue(starts.get(0).getLocation().getId().startsWith("foo")); + assertTrue(starts.get(1).getLocation().getId().startsWith("foo")); + } + + private void doSmth(List starts) { + int count = 0; + for (@SuppressWarnings("unused") Start s : starts) { + s = Start.newInstance("yo_" + count, 0.0, 0.0); + count++; + } + + } } diff --git a/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/TestTourActivities.java b/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/TestTourActivities.java index 3202177a..92c65325 100644 --- a/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/TestTourActivities.java +++ b/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/TestTourActivities.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.problem.solution.route.activity; @@ -25,102 +25,100 @@ import org.junit.Test; import static org.junit.Assert.*; - public class TestTourActivities { - - private Service service; - private ServiceActivity act; - private TourActivities tour; - @Before - public void doBefore(){ - service = Service.Builder.newInstance("yo").addSizeDimension(0, 10).setLocation(Location.newInstance("loc")).build(); - act = ServiceActivity.newInstance(service); - tour = new TourActivities(); - } - - @Test - public void whenAddingServiceAct_serviceActIsAdded(){ - assertFalse(tour.servesJob(service)); - tour.addActivity(act); - assertTrue(tour.servesJob(service)); - } - - @Test(expected=IllegalStateException.class) - public void whenAddingServiceActTwice_anExceptionIsThrown(){ - assertFalse(tour.servesJob(service)); - tour.addActivity(act); - tour.addActivity(act); - } - - @Test - public void whenAddingServiceAndRemovingItImmediately_tourShouldNotServeServiceAnymore(){ - assertFalse(tour.servesJob(service)); - tour.addActivity(act); - assertTrue(tour.servesJob(service)); - tour.removeJob(service); - assertFalse(tour.servesJob(service)); - } - - @Test - public void whenAddingAServiceAndThenRemovingTheServiceAgain_tourShouldNotServeItAnymore(){ - assertEquals(0, tour.getActivities().size()); - tour.addActivity(act); - assertEquals(1, tour.getActivities().size()); - Service anotherServiceInstance = Service.Builder.newInstance("yo").addSizeDimension(0, 10).setLocation(Location.newInstance("loc")).build(); - assertTrue(service.equals(anotherServiceInstance)); - boolean removed = tour.removeJob(anotherServiceInstance); - assertTrue(removed); - assertEquals(0, tour.getActivities().size()); - } - - @Test - public void whenAddingAShipmentActivity_tourShouldServeShipment(){ - Shipment s = Shipment.Builder.newInstance("s").addSizeDimension(0, 1).setDeliveryLocation(Location.newInstance("delLoc")) - .setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); - TourShipmentActivityFactory fac = new DefaultShipmentActivityFactory(); - TourActivity pickupShipment = fac.createPickup(s); - TourActivity deliverShipment = fac.createDelivery(s); - tour.addActivity(pickupShipment); - tour.addActivity(deliverShipment); - assertTrue(tour.servesJob(s)); - assertEquals(2,tour.getActivities().size()); - } - - - - @Test - public void whenRemovingShipment_tourShouldNotServiceItAnymore(){ - Shipment s = Shipment.Builder.newInstance("s").addSizeDimension(0, 1).setDeliveryLocation(Location.newInstance("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); - TourShipmentActivityFactory fac = new DefaultShipmentActivityFactory(); - TourActivity pickupShipment = fac.createPickup(s); - TourActivity deliverShipment = fac.createDelivery(s); - tour.addActivity(pickupShipment); - tour.addActivity(deliverShipment); - - tour.removeJob(s); - assertFalse(tour.servesJob(s)); - } + private Service service; + private ServiceActivity act; + private TourActivities tour; - - @Test - public void whenRemovingShipment_theirCorrespondingActivitiesShouldBeRemoved(){ - Shipment s = Shipment.Builder.newInstance("s").addSizeDimension(0, 1) - .setDeliveryLocation(Location.newInstance("delLoc")) - .setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); - TourShipmentActivityFactory fac = new DefaultShipmentActivityFactory(); - TourActivity pickupShipment = fac.createPickup(s); - TourActivity deliverShipment = fac.createDelivery(s); - tour.addActivity(pickupShipment); - tour.addActivity(deliverShipment); - - assertEquals(2, tour.getActivities().size()); - tour.removeJob(s); - assertEquals(0, tour.getActivities().size()); - } + @Before + public void doBefore() { + service = Service.Builder.newInstance("yo").addSizeDimension(0, 10).setLocation(Location.newInstance("loc")).build(); + act = ServiceActivity.newInstance(service); + tour = new TourActivities(); + } @Test - public void removingActivityShouldWork(){ + public void whenAddingServiceAct_serviceActIsAdded() { + assertFalse(tour.servesJob(service)); + tour.addActivity(act); + assertTrue(tour.servesJob(service)); + } + + @Test(expected = IllegalStateException.class) + public void whenAddingServiceActTwice_anExceptionIsThrown() { + assertFalse(tour.servesJob(service)); + tour.addActivity(act); + tour.addActivity(act); + } + + @Test + public void whenAddingServiceAndRemovingItImmediately_tourShouldNotServeServiceAnymore() { + assertFalse(tour.servesJob(service)); + tour.addActivity(act); + assertTrue(tour.servesJob(service)); + tour.removeJob(service); + assertFalse(tour.servesJob(service)); + } + + @Test + public void whenAddingAServiceAndThenRemovingTheServiceAgain_tourShouldNotServeItAnymore() { + assertEquals(0, tour.getActivities().size()); + tour.addActivity(act); + assertEquals(1, tour.getActivities().size()); + Service anotherServiceInstance = Service.Builder.newInstance("yo").addSizeDimension(0, 10).setLocation(Location.newInstance("loc")).build(); + assertTrue(service.equals(anotherServiceInstance)); + boolean removed = tour.removeJob(anotherServiceInstance); + assertTrue(removed); + assertEquals(0, tour.getActivities().size()); + } + + @Test + public void whenAddingAShipmentActivity_tourShouldServeShipment() { + Shipment s = Shipment.Builder.newInstance("s").addSizeDimension(0, 1).setDeliveryLocation(Location.newInstance("delLoc")) + .setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); + TourShipmentActivityFactory fac = new DefaultShipmentActivityFactory(); + TourActivity pickupShipment = fac.createPickup(s); + TourActivity deliverShipment = fac.createDelivery(s); + tour.addActivity(pickupShipment); + tour.addActivity(deliverShipment); + assertTrue(tour.servesJob(s)); + assertEquals(2, tour.getActivities().size()); + } + + + @Test + public void whenRemovingShipment_tourShouldNotServiceItAnymore() { + Shipment s = Shipment.Builder.newInstance("s").addSizeDimension(0, 1).setDeliveryLocation(Location.newInstance("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); + TourShipmentActivityFactory fac = new DefaultShipmentActivityFactory(); + TourActivity pickupShipment = fac.createPickup(s); + TourActivity deliverShipment = fac.createDelivery(s); + tour.addActivity(pickupShipment); + tour.addActivity(deliverShipment); + + tour.removeJob(s); + assertFalse(tour.servesJob(s)); + } + + + @Test + public void whenRemovingShipment_theirCorrespondingActivitiesShouldBeRemoved() { + Shipment s = Shipment.Builder.newInstance("s").addSizeDimension(0, 1) + .setDeliveryLocation(Location.newInstance("delLoc")) + .setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); + TourShipmentActivityFactory fac = new DefaultShipmentActivityFactory(); + TourActivity pickupShipment = fac.createPickup(s); + TourActivity deliverShipment = fac.createDelivery(s); + tour.addActivity(pickupShipment); + tour.addActivity(deliverShipment); + + assertEquals(2, tour.getActivities().size()); + tour.removeJob(s); + assertEquals(0, tour.getActivities().size()); + } + + @Test + public void removingActivityShouldWork() { tour.addActivity(act); assertTrue(tour.servesJob(service)); assertTrue(tour.hasActivity(act)); @@ -130,11 +128,11 @@ public class TestTourActivities { assertTrue(tour.isEmpty()); assertFalse(tour.hasActivity(act)); assertFalse(tour.servesJob(service)); - assertEquals(0,tour.jobSize()); + assertEquals(0, tour.jobSize()); } @Test - public void copyingSeqShouldWork(){ + public void copyingSeqShouldWork() { tour.addActivity(act); assertTrue(tour.servesJob(service)); @@ -147,25 +145,25 @@ public class TestTourActivities { } @Test - public void removingShipmentActivityShouldWork(){ + public void removingShipmentActivityShouldWork() { Shipment s = Shipment.Builder.newInstance("s").addSizeDimension(0, 1) - .setDeliveryLocation(Location.newInstance("delLoc")) - .setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); + .setDeliveryLocation(Location.newInstance("delLoc")) + .setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); TourShipmentActivityFactory fac = new DefaultShipmentActivityFactory(); TourActivity pickupShipment = fac.createPickup(s); TourActivity deliverShipment = fac.createDelivery(s); tour.addActivity(pickupShipment); tour.addActivity(deliverShipment); - assertEquals(1,tour.jobSize()); - assertEquals(2,tour.getActivities().size()); + assertEquals(1, tour.jobSize()); + assertEquals(2, tour.getActivities().size()); assertTrue(tour.getActivities().contains(pickupShipment)); assertTrue(tour.hasActivity(pickupShipment)); assertTrue(tour.hasActivity(deliverShipment)); tour.removeActivity(pickupShipment); - assertEquals(1,tour.jobSize()); + assertEquals(1, tour.jobSize()); assertEquals(1, tour.getActivities().size()); assertTrue(tour.hasActivity(deliverShipment)); assertFalse(tour.hasActivity(pickupShipment)); @@ -174,60 +172,60 @@ public class TestTourActivities { } @Test - public void whenCopyingShipmentActivitySeq_jobSizeShouldBeCorrect(){ + public void whenCopyingShipmentActivitySeq_jobSizeShouldBeCorrect() { Shipment s = Shipment.Builder.newInstance("s").addSizeDimension(0, 1) - .setDeliveryLocation(Location.newInstance("delLoc")) - .setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); + .setDeliveryLocation(Location.newInstance("delLoc")) + .setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); TourShipmentActivityFactory fac = new DefaultShipmentActivityFactory(); TourActivity pickupShipment = fac.createPickup(s); TourActivity deliverShipment = fac.createDelivery(s); tour.addActivity(pickupShipment); tour.addActivity(deliverShipment); - assertEquals(1,tour.jobSize()); - assertEquals(2,tour.getActivities().size()); + assertEquals(1, tour.jobSize()); + assertEquals(2, tour.getActivities().size()); assertTrue(tour.getActivities().contains(pickupShipment)); assertTrue(tour.hasActivity(pickupShipment)); assertTrue(tour.hasActivity(deliverShipment)); TourActivities copiedTour = TourActivities.copyOf(tour); - assertEquals(1,copiedTour.jobSize()); + assertEquals(1, copiedTour.jobSize()); } @Test - public void whenCopyingShipmentActivitySeq_noActivitiesShouldBeCorrect(){ + public void whenCopyingShipmentActivitySeq_noActivitiesShouldBeCorrect() { Shipment s = Shipment.Builder.newInstance("s").addSizeDimension(0, 1) - .setDeliveryLocation(Location.newInstance("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); + .setDeliveryLocation(Location.newInstance("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); TourShipmentActivityFactory fac = new DefaultShipmentActivityFactory(); TourActivity pickupShipment = fac.createPickup(s); TourActivity deliverShipment = fac.createDelivery(s); tour.addActivity(pickupShipment); tour.addActivity(deliverShipment); - assertEquals(1,tour.jobSize()); - assertEquals(2,tour.getActivities().size()); + assertEquals(1, tour.jobSize()); + assertEquals(2, tour.getActivities().size()); assertTrue(tour.getActivities().contains(pickupShipment)); assertTrue(tour.hasActivity(pickupShipment)); assertTrue(tour.hasActivity(deliverShipment)); TourActivities copiedTour = TourActivities.copyOf(tour); - assertEquals(2,copiedTour.getActivities().size()); + assertEquals(2, copiedTour.getActivities().size()); } @Test - public void whenCopyingShipmentActivitySeq_itShouldContaintPickupAct(){ + public void whenCopyingShipmentActivitySeq_itShouldContaintPickupAct() { Shipment s = Shipment.Builder.newInstance("s").addSizeDimension(0, 1) - .setDeliveryLocation(Location.newInstance("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); + .setDeliveryLocation(Location.newInstance("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); TourShipmentActivityFactory fac = new DefaultShipmentActivityFactory(); TourActivity pickupShipment = fac.createPickup(s); TourActivity deliverShipment = fac.createDelivery(s); tour.addActivity(pickupShipment); tour.addActivity(deliverShipment); - assertEquals(1,tour.jobSize()); - assertEquals(2,tour.getActivities().size()); + assertEquals(1, tour.jobSize()); + assertEquals(2, tour.getActivities().size()); assertTrue(tour.getActivities().contains(pickupShipment)); assertTrue(tour.hasActivity(pickupShipment)); assertTrue(tour.hasActivity(deliverShipment)); @@ -236,5 +234,5 @@ public class TestTourActivities { assertTrue(copiedTour.servesJob(s)); } - + } diff --git a/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/TimeWindowTest.java b/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/TimeWindowTest.java index f2047a97..df2b2eda 100644 --- a/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/TimeWindowTest.java +++ b/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/TimeWindowTest.java @@ -1,18 +1,18 @@ /******************************************************************************* * Copyright (c) 2014 Stefan Schroeder. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . - * + * * Contributors: * Stefan Schroeder - initial API and implementation ******************************************************************************/ diff --git a/jsprit-core/src/test/java/jsprit/core/problem/vehicle/FiniteVehicleFleetManagerFactoryTest.java b/jsprit-core/src/test/java/jsprit/core/problem/vehicle/FiniteVehicleFleetManagerFactoryTest.java index f21e0d7c..e42cf0b8 100644 --- a/jsprit-core/src/test/java/jsprit/core/problem/vehicle/FiniteVehicleFleetManagerFactoryTest.java +++ b/jsprit-core/src/test/java/jsprit/core/problem/vehicle/FiniteVehicleFleetManagerFactoryTest.java @@ -1,18 +1,18 @@ /******************************************************************************* * Copyright (c) 2014 Stefan Schroeder. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . - * + * * Contributors: * Stefan Schroeder - initial API and implementation ******************************************************************************/ @@ -21,11 +21,11 @@ package jsprit.core.problem.vehicle; import org.junit.Test; public class FiniteVehicleFleetManagerFactoryTest { - - @Test - public void whenFiniteVehicleManagerIsCreated_itShouldReturnCorrectManager(){ + + @Test + public void whenFiniteVehicleManagerIsCreated_itShouldReturnCorrectManager() { // VehicleFleetManager vfm = new FiniteFleetManagerFactory(Arrays.asList(mock(Vehicle.class))).createFleetManager(); - - } + + } } diff --git a/jsprit-core/src/test/java/jsprit/core/problem/vehicle/TestVehicleFleetManagerImpl.java b/jsprit-core/src/test/java/jsprit/core/problem/vehicle/TestVehicleFleetManagerImpl.java index ea78129a..5ac8763d 100644 --- a/jsprit-core/src/test/java/jsprit/core/problem/vehicle/TestVehicleFleetManagerImpl.java +++ b/jsprit-core/src/test/java/jsprit/core/problem/vehicle/TestVehicleFleetManagerImpl.java @@ -1,22 +1,23 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.core.problem.vehicle; import jsprit.core.problem.Location; +import jsprit.core.problem.VehicleRoutingProblem; import org.junit.Before; import org.junit.Test; @@ -28,189 +29,191 @@ import java.util.List; import static org.junit.Assert.*; public class TestVehicleFleetManagerImpl { - - VehicleFleetManager fleetManager; - - Vehicle v1; - - Vehicle v2; - - @Before - public void setUp(){ - List vehicles = new ArrayList(); - - v1 = VehicleImpl.Builder.newInstance("standard").setStartLocation(Location.newInstance("loc")).setType(VehicleTypeImpl.Builder.newInstance("standard").build()).build(); - v2 = VehicleImpl.Builder.newInstance("foo").setStartLocation(Location.newInstance("fooLoc")).setType(VehicleTypeImpl.Builder.newInstance("foo").build()).build(); + VehicleFleetManager fleetManager; + + VehicleImpl v1; + + VehicleImpl v2; + + @Before + public void setUp() { + List vehicles = new ArrayList(); + + v1 = VehicleImpl.Builder.newInstance("standard").setStartLocation(Location.newInstance("loc")).setType(VehicleTypeImpl.Builder.newInstance("standard").build()).build(); + v2 = VehicleImpl.Builder.newInstance("foo").setStartLocation(Location.newInstance("fooLoc")).setType(VehicleTypeImpl.Builder.newInstance("foo").build()).build(); + + VehicleRoutingProblem.Builder.newInstance().addVehicle(v1).addVehicle(v2).build(); // v1. - vehicles.add(v1); - vehicles.add(v2); - fleetManager = new FiniteFleetManagerFactory(vehicles).createFleetManager(); - } - - @Test - public void testGetVehicles(){ - Collection vehicles = fleetManager.getAvailableVehicles(); - assertEquals(2, vehicles.size()); - } - - @Test - public void testLock(){ - fleetManager.lock(v1); - Collection vehicles = fleetManager.getAvailableVehicles(); - assertEquals(1, vehicles.size()); - } - - @Test - public void testLockTwice(){ - fleetManager.lock(v1); - Collection vehicles = fleetManager.getAvailableVehicles(); - assertEquals(1, vehicles.size()); - try{ - fleetManager.lock(v1); - @SuppressWarnings("unused") - Collection vehicles_ = fleetManager.getAvailableVehicles(); - assertFalse(true); - } - catch(IllegalStateException e){ - assertTrue(true); - } - } - - @Test - public void testGetVehiclesWithout(){ - Collection vehicles = fleetManager.getAvailableVehicles(v1); - - assertEquals(v2, vehicles.iterator().next()); - assertEquals(1, vehicles.size()); - } - - @Test - public void testUnlock(){ - fleetManager.lock(v1); - Collection vehicles = fleetManager.getAvailableVehicles(); - assertEquals(1, vehicles.size()); - fleetManager.unlock(v1); - Collection vehicles_ = fleetManager.getAvailableVehicles(); - assertEquals(2, vehicles_.size()); - } - - @Test - public void testWithPenalty_whenHavingOneRegularVehicleAvailable_noPenaltyVehicleIsReturn(){ - Vehicle penalty4standard = VehicleImpl.Builder.newInstance("standard_penalty").setStartLocation(Location.newInstance("loc")). - setType(VehicleTypeImpl.Builder.newInstance("standard").build()).build(); - - List vehicles = new ArrayList(); - vehicles.add(v1); - vehicles.add(v2); - vehicles.add(penalty4standard); - VehicleFleetManager fleetManager = new FiniteFleetManagerFactory(vehicles).createFleetManager(); - - Collection availableVehicles = fleetManager.getAvailableVehicles(); - assertEquals(2, availableVehicles.size()); - } + vehicles.add(v1); + vehicles.add(v2); + fleetManager = new FiniteFleetManagerFactory(vehicles).createFleetManager(); + } + + @Test + public void testGetVehicles() { + Collection vehicles = fleetManager.getAvailableVehicles(); + assertEquals(2, vehicles.size()); + } + + @Test + public void testLock() { + fleetManager.lock(v1); + Collection vehicles = fleetManager.getAvailableVehicles(); + assertEquals(1, vehicles.size()); + } + + @Test + public void testLock2() { + fleetManager.lock(v1); + fleetManager.lock(v2); + fleetManager.unlock(v2); + assertTrue(fleetManager.isLocked(v1)); + } + + @Test + public void testIsLocked() { + fleetManager.lock(v1); + assertTrue(fleetManager.isLocked(v1)); + } + + @Test + public void testLockTwice() { + fleetManager.lock(v1); + Collection vehicles = fleetManager.getAvailableVehicles(); + assertEquals(1, vehicles.size()); + try { + fleetManager.lock(v1); + @SuppressWarnings("unused") + Collection vehicles_ = fleetManager.getAvailableVehicles(); + assertFalse(true); + } catch (IllegalStateException e) { + assertTrue(true); + } + } + + @Test + public void testGetVehiclesWithout() { + Collection vehicles = fleetManager.getAvailableVehicles(v1); + + assertEquals(v2, vehicles.iterator().next()); + assertEquals(1, vehicles.size()); + } + + @Test + public void testUnlock() { + fleetManager.lock(v1); + Collection vehicles = fleetManager.getAvailableVehicles(); + assertEquals(1, vehicles.size()); + fleetManager.unlock(v1); + Collection vehicles_ = fleetManager.getAvailableVehicles(); + assertEquals(2, vehicles_.size()); + } + + @Test + public void whenAddingTwoVehiclesWithSameTypeIdAndLocation_getAvailableVehicleShouldReturnOnlyOneOfThem() { + VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("standard").build(); + Vehicle v1 = VehicleImpl.Builder.newInstance("v1").setStartLocation(Location.newInstance("loc")).setType(type).build(); + Vehicle v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(Location.newInstance("loc")).setType(type).build(); + VehicleFleetManager fleetManager = new FiniteFleetManagerFactory(Arrays.asList(v1, v2)).createFleetManager(); + Collection vehicles = fleetManager.getAvailableVehicles(); + assertEquals(1, vehicles.size()); + } + + @Test + public void whenAddingTwoVehiclesWithSameTypeIdStartAndEndLocationAndWorkingShift_getAvailableVehicleShouldReturnOnlyOneOfThem() { + VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("standard").build(); + Vehicle v1 = VehicleImpl.Builder.newInstance("v1").setStartLocation(Location.newInstance("loc")).setEndLocation(Location.newInstance("endLoc")) + .setType(type).setEarliestStart(0.).setLatestArrival(10.).build(); + Vehicle v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(Location.newInstance("loc")).setEndLocation(Location.newInstance("endLoc")) + .setType(type).setEarliestStart(0.).setLatestArrival(10.).build(); + VehicleFleetManager fleetManager = new FiniteFleetManagerFactory(Arrays.asList(v1, v2)).createFleetManager(); + Collection vehicles = fleetManager.getAvailableVehicles(); + assertEquals(1, vehicles.size()); + } + + @Test + public void whenAddingTwoVehiclesWithDifferentType_getAvailableVehicleShouldReturnBoth() { + VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("standard").build(); + VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("type2").build(); + Vehicle v1 = VehicleImpl.Builder.newInstance("v1").setStartLocation(Location.newInstance("loc")).setEndLocation(Location.newInstance("endLoc")) + .setType(type).setEarliestStart(0.).setLatestArrival(10.).build(); + Vehicle v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(Location.newInstance("loc")).setEndLocation(Location.newInstance("endLoc")) + .setType(type2).setEarliestStart(0.).setLatestArrival(10.).build(); + VehicleRoutingProblem.Builder.newInstance().addVehicle(v1).addVehicle(v2).build(); + VehicleFleetManager fleetManager = new FiniteFleetManagerFactory(Arrays.asList(v1, v2)).createFleetManager(); + Collection vehicles = fleetManager.getAvailableVehicles(); + assertEquals(2, vehicles.size()); + assertTrue(vehicleInCollection(v1, vehicles)); + assertTrue(vehicleInCollection(v2, vehicles)); + } + + @Test + public void whenAddingTwoVehiclesWithDifferentStartLocation_getAvailableVehicleShouldReturnBoth() { + VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("standard").build(); + Vehicle v1 = VehicleImpl.Builder.newInstance("v1").setStartLocation(Location.newInstance("startLoc")).setEndLocation(Location.newInstance("endLoc")) + .setType(type).setEarliestStart(0.).setLatestArrival(10.).build(); + Vehicle v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(Location.newInstance("loc")).setEndLocation(Location.newInstance("endLoc")) + .setType(type).setEarliestStart(0.).setLatestArrival(10.).build(); + VehicleRoutingProblem.Builder.newInstance().addVehicle(v1).addVehicle(v2).build(); + VehicleFleetManager fleetManager = new FiniteFleetManagerFactory(Arrays.asList(v1, v2)).createFleetManager(); + Collection vehicles = fleetManager.getAvailableVehicles(); + assertEquals(2, vehicles.size()); + assertTrue(vehicleInCollection(v1, vehicles)); + assertTrue(vehicleInCollection(v2, vehicles)); + } + + @Test + public void whenAddingTwoVehiclesWithDifferentEndLocation_getAvailableVehicleShouldReturnBoth() { + VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("standard").build(); + Vehicle v1 = VehicleImpl.Builder.newInstance("v1").setStartLocation(Location.newInstance("loc")).setEndLocation(Location.newInstance("endLocation")) + .setType(type).setEarliestStart(0.).setLatestArrival(10.).build(); + Vehicle v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(Location.newInstance("loc")).setEndLocation(Location.newInstance("endLoc")) + .setType(type).setEarliestStart(0.).setLatestArrival(10.).build(); + VehicleRoutingProblem.Builder.newInstance().addVehicle(v1).addVehicle(v2).build(); + VehicleFleetManager fleetManager = new FiniteFleetManagerFactory(Arrays.asList(v1, v2)).createFleetManager(); + Collection vehicles = fleetManager.getAvailableVehicles(); + assertEquals(2, vehicles.size()); + assertTrue(vehicleInCollection(v1, vehicles)); + assertTrue(vehicleInCollection(v2, vehicles)); + } + + @Test + public void whenAddingTwoVehiclesWithDifferentEarliestStart_getAvailableVehicleShouldReturnBoth() { + VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("standard").build(); + Vehicle v1 = VehicleImpl.Builder.newInstance("v1").setStartLocation(Location.newInstance("loc")).setEndLocation(Location.newInstance("endLoc")) + .setType(type).setEarliestStart(5.).setLatestArrival(10.).build(); + Vehicle v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(Location.newInstance("loc")).setEndLocation(Location.newInstance("endLoc")) + .setType(type).setEarliestStart(0.).setLatestArrival(10.).build(); + VehicleRoutingProblem.Builder.newInstance().addVehicle(v1).addVehicle(v2).build(); + VehicleFleetManager fleetManager = new FiniteFleetManagerFactory(Arrays.asList(v1, v2)).createFleetManager(); + Collection vehicles = fleetManager.getAvailableVehicles(); + assertEquals(2, vehicles.size()); + assertTrue(vehicleInCollection(v1, vehicles)); + assertTrue(vehicleInCollection(v2, vehicles)); + } + + @Test + public void whenAddingTwoVehiclesWithDifferentLatestArr_getAvailableVehicleShouldReturnBoth() { + VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("standard").build(); + Vehicle v1 = VehicleImpl.Builder.newInstance("v1").setStartLocation(Location.newInstance("loc")).setEndLocation(Location.newInstance("endLoc")) + .setType(type).setEarliestStart(0.).setLatestArrival(20.).build(); + Vehicle v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(Location.newInstance("loc")).setEndLocation(Location.newInstance("endLoc")) + .setType(type).setEarliestStart(0.).setLatestArrival(10.).build(); + VehicleRoutingProblem.Builder.newInstance().addVehicle(v1).addVehicle(v2).build(); + VehicleFleetManager fleetManager = new FiniteFleetManagerFactory(Arrays.asList(v1, v2)).createFleetManager(); + Collection vehicles = fleetManager.getAvailableVehicles(); + assertEquals(2, vehicles.size()); + assertTrue(vehicleInCollection(v1, vehicles)); + assertTrue(vehicleInCollection(v2, vehicles)); + } + + private boolean vehicleInCollection(Vehicle v, Collection vehicles) { + for (Vehicle veh : vehicles) { + if (veh == v) return true; + } + return false; + } - - @Test - public void whenAddingTwoVehiclesWithSameTypeIdAndLocation_getAvailableVehicleShouldReturnOnlyOneOfThem(){ - VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("standard").build(); - Vehicle v1 = VehicleImpl.Builder.newInstance("v1").setStartLocation(Location.newInstance("loc")).setType(type).build(); - Vehicle v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(Location.newInstance("loc")).setType(type).build(); - VehicleFleetManager fleetManager = new FiniteFleetManagerFactory(Arrays.asList(v1,v2)).createFleetManager(); - Collection vehicles = fleetManager.getAvailableVehicles(); - assertEquals(1,vehicles.size()); - } - - @Test - public void whenAddingTwoVehiclesWithSameTypeIdStartAndEndLocationAndWorkingShift_getAvailableVehicleShouldReturnOnlyOneOfThem(){ - VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("standard").build(); - Vehicle v1 = VehicleImpl.Builder.newInstance("v1").setStartLocation(Location.newInstance("loc")).setEndLocation(Location.newInstance("endLoc")) - .setType(type).setEarliestStart(0.).setLatestArrival(10.).build(); - Vehicle v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(Location.newInstance("loc")).setEndLocation(Location.newInstance("endLoc")) - .setType(type).setEarliestStart(0.).setLatestArrival(10.).build(); - VehicleFleetManager fleetManager = new FiniteFleetManagerFactory(Arrays.asList(v1,v2)).createFleetManager(); - Collection vehicles = fleetManager.getAvailableVehicles(); - assertEquals(1,vehicles.size()); - } - - @Test - public void whenAddingTwoVehiclesWithDifferentType_getAvailableVehicleShouldReturnBoth(){ - VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("standard").build(); - VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("type2").build(); - Vehicle v1 = VehicleImpl.Builder.newInstance("v1").setStartLocation(Location.newInstance("loc")).setEndLocation(Location.newInstance("endLoc")) - .setType(type).setEarliestStart(0.).setLatestArrival(10.).build(); - Vehicle v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(Location.newInstance("loc")).setEndLocation(Location.newInstance("endLoc")) - .setType(type2).setEarliestStart(0.).setLatestArrival(10.).build(); - VehicleFleetManager fleetManager = new FiniteFleetManagerFactory(Arrays.asList(v1,v2)).createFleetManager(); - Collection vehicles = fleetManager.getAvailableVehicles(); - assertEquals(2,vehicles.size()); - assertTrue(vehicleInCollection(v1,vehicles)); - assertTrue(vehicleInCollection(v2,vehicles)); - } - - @Test - public void whenAddingTwoVehiclesWithDifferentStartLocation_getAvailableVehicleShouldReturnBoth(){ - VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("standard").build(); - Vehicle v1 = VehicleImpl.Builder.newInstance("v1").setStartLocation(Location.newInstance("startLoc")).setEndLocation(Location.newInstance("endLoc")) - .setType(type).setEarliestStart(0.).setLatestArrival(10.).build(); - Vehicle v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(Location.newInstance("loc")).setEndLocation(Location.newInstance("endLoc")) - .setType(type).setEarliestStart(0.).setLatestArrival(10.).build(); - VehicleFleetManager fleetManager = new FiniteFleetManagerFactory(Arrays.asList(v1,v2)).createFleetManager(); - Collection vehicles = fleetManager.getAvailableVehicles(); - assertEquals(2,vehicles.size()); - assertTrue(vehicleInCollection(v1,vehicles)); - assertTrue(vehicleInCollection(v2,vehicles)); - } - - @Test - public void whenAddingTwoVehiclesWithDifferentEndLocation_getAvailableVehicleShouldReturnBoth(){ - VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("standard").build(); - Vehicle v1 = VehicleImpl.Builder.newInstance("v1").setStartLocation(Location.newInstance("loc")).setEndLocation(Location.newInstance("endLocation")) - .setType(type).setEarliestStart(0.).setLatestArrival(10.).build(); - Vehicle v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(Location.newInstance("loc")).setEndLocation(Location.newInstance("endLoc")) - .setType(type).setEarliestStart(0.).setLatestArrival(10.).build(); - VehicleFleetManager fleetManager = new FiniteFleetManagerFactory(Arrays.asList(v1,v2)).createFleetManager(); - Collection vehicles = fleetManager.getAvailableVehicles(); - assertEquals(2,vehicles.size()); - assertTrue(vehicleInCollection(v1,vehicles)); - assertTrue(vehicleInCollection(v2,vehicles)); - } - - @Test - public void whenAddingTwoVehiclesWithDifferentEarliestStart_getAvailableVehicleShouldReturnBoth(){ - VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("standard").build(); - Vehicle v1 = VehicleImpl.Builder.newInstance("v1").setStartLocation(Location.newInstance("loc")).setEndLocation(Location.newInstance("endLoc")) - .setType(type).setEarliestStart(5.).setLatestArrival(10.).build(); - Vehicle v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(Location.newInstance("loc")).setEndLocation(Location.newInstance("endLoc")) - .setType(type).setEarliestStart(0.).setLatestArrival(10.).build(); - VehicleFleetManager fleetManager = new FiniteFleetManagerFactory(Arrays.asList(v1,v2)).createFleetManager(); - Collection vehicles = fleetManager.getAvailableVehicles(); - assertEquals(2,vehicles.size()); - assertTrue(vehicleInCollection(v1,vehicles)); - assertTrue(vehicleInCollection(v2,vehicles)); - } - - @Test - public void whenAddingTwoVehiclesWithDifferentLatestArr_getAvailableVehicleShouldReturnBoth(){ - VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("standard").build(); - Vehicle v1 = VehicleImpl.Builder.newInstance("v1").setStartLocation(Location.newInstance("loc")).setEndLocation(Location.newInstance("endLoc")) - .setType(type).setEarliestStart(0.).setLatestArrival(20.).build(); - Vehicle v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(Location.newInstance("loc")).setEndLocation(Location.newInstance("endLoc")) - .setType(type).setEarliestStart(0.).setLatestArrival(10.).build(); - VehicleFleetManager fleetManager = new FiniteFleetManagerFactory(Arrays.asList(v1,v2)).createFleetManager(); - Collection vehicles = fleetManager.getAvailableVehicles(); - assertEquals(2,vehicles.size()); - assertTrue(vehicleInCollection(v1,vehicles)); - assertTrue(vehicleInCollection(v2,vehicles)); - } - - private boolean vehicleInCollection(Vehicle v, Collection vehicles) { - for(Vehicle veh : vehicles){ - if(veh == v) return true; - } - return false; - } - - } diff --git a/jsprit-core/src/test/java/jsprit/core/problem/vehicle/VehicleImplTest.java b/jsprit-core/src/test/java/jsprit/core/problem/vehicle/VehicleImplTest.java index 20a2c349..cb62f36e 100644 --- a/jsprit-core/src/test/java/jsprit/core/problem/vehicle/VehicleImplTest.java +++ b/jsprit-core/src/test/java/jsprit/core/problem/vehicle/VehicleImplTest.java @@ -1,18 +1,18 @@ /******************************************************************************* * Copyright (c) 2014 Stefan Schroeder. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . - * + * * Contributors: * Stefan Schroeder - initial API and implementation ******************************************************************************/ @@ -20,206 +20,223 @@ package jsprit.core.problem.vehicle; import jsprit.core.problem.Location; +import jsprit.core.problem.job.Break; +import jsprit.core.problem.solution.route.activity.TimeWindow; import org.junit.Test; import static org.junit.Assert.*; public class VehicleImplTest { - - - - @Test(expected=IllegalStateException.class) - public void whenVehicleIsBuiltWithoutSettingNeitherLocationNorCoord_itThrowsAnIllegalStateException(){ - @SuppressWarnings("unused") - Vehicle v = VehicleImpl.Builder.newInstance("v").build(); - } - - @Test - public void whenVehicleIsBuiltToReturnToDepot_itShouldReturnToDepot(){ - Vehicle v = VehicleImpl.Builder.newInstance("v").setReturnToDepot(true).setStartLocation(Location.newInstance("loc")).build(); - assertTrue(v.isReturnToDepot()); - } - - @Test - public void whenVehicleIsBuiltToNotReturnToDepot_itShouldNotReturnToDepot(){ - Vehicle v = VehicleImpl.Builder.newInstance("v").setReturnToDepot(false).setStartLocation(Location.newInstance("loc")).build(); - assertFalse(v.isReturnToDepot()); - } - - @Test - public void whenVehicleIsBuiltWithLocation_itShouldHvTheCorrectLocation(){ - Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("loc")).build(); - assertEquals("loc",v.getStartLocation().getId()); - } - - @Test - public void whenVehicleIsBuiltWithCoord_itShouldHvTheCorrectCoord(){ - Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(1, 2)).build(); - assertEquals(1.0,v.getStartLocation().getCoordinate().getX(),0.01); - assertEquals(2.0,v.getStartLocation().getCoordinate().getY(),0.01); - } - - @Test - public void whenVehicleIsBuiltAndEarliestStartIsNotSet_itShouldSetTheDefaultOfZero(){ - Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(1, 2)).build(); - assertEquals(0.0,v.getEarliestDeparture(),0.01); - } - - @Test - public void whenVehicleIsBuiltAndEarliestStartSet_itShouldBeSetCorrectly(){ - Vehicle v = VehicleImpl.Builder.newInstance("v").setEarliestStart(10.0).setStartLocation(Location.newInstance(1, 2)).build(); - assertEquals(10.0,v.getEarliestDeparture(),0.01); - } - - @Test - public void whenVehicleIsBuiltAndLatestArrivalIsNotSet_itShouldSetDefaultOfDoubleMaxValue(){ - Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(1, 2)).build(); - assertEquals(Double.MAX_VALUE,v.getLatestArrival(),0.01); - } - - @Test - public void whenVehicleIsBuiltAndLatestArrivalIsSet_itShouldBeSetCorrectly(){ - Vehicle v = VehicleImpl.Builder.newInstance("v").setLatestArrival(30.0).setStartLocation(Location.newInstance(1, 2)).build(); - assertEquals(30.0,v.getLatestArrival(),0.01); - } - - @Test - public void whenNoVehicleIsCreate_itShouldHvTheCorrectId(){ - Vehicle v = VehicleImpl.createNoVehicle(); - assertEquals("noVehicle",v.getId()); - } - - @Test - public void whenStartLocationIsSet_itIsDoneCorrectly(){ - Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("startLoc")).build(); - assertEquals("startLoc", v.getStartLocation().getId()); - } - - @Test(expected=IllegalStateException.class) - public void whenStartLocationIsNull_itThrowsException(){ - @SuppressWarnings("unused") - Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(null)).build(); - } - - @Test - public void whenStartLocationCoordIsSet_itIsDoneCorrectly(){ - Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(1, 2)).build(); - assertEquals(1.0, v.getStartLocation().getCoordinate().getX(),0.01); - assertEquals(2.0, v.getStartLocation().getCoordinate().getY(),0.01); - } - - @Test - public void whenEndLocationIsSet_itIsDoneCorrectly(){ - Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("startLoc")).setEndLocation(Location.newInstance("endLoc")).build(); - assertEquals("startLoc", v.getStartLocation().getId()); - assertEquals("endLoc", v.getEndLocation().getId()); - } - - @Test - public void whenEndLocationCoordIsSet_itIsDoneCorrectly(){ - Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("startLoc")).setEndLocation(Location.newInstance(1, 2)).build(); - assertEquals(1.0, v.getEndLocation().getCoordinate().getX(),0.01); - assertEquals(2.0, v.getEndLocation().getCoordinate().getY(),0.01); - } - - @Test - public void whenNeitherEndLocationIdNorEndLocationCoordAreSet_endLocationIdMustBeEqualToStartLocationId(){ - Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("startLoc")).build(); - assertEquals("startLoc", v.getEndLocation().getId()); - } - - @Test - public void whenNeitherEndLocationIdNorEndLocationCoordAreSet_endLocationCoordMustBeEqualToStartLocationCoord(){ - Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("startLoc")).build(); - assertEquals(v.getEndLocation().getCoordinate(), v.getStartLocation().getCoordinate()); - } - - @Test - public void whenNeitherEndLocationIdNorEndLocationCoordAreSet_endLocationCoordMustBeEqualToStartLocationCoordV2(){ - Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(1.0, 2.0)).build(); - assertEquals(v.getEndLocation().getCoordinate(), v.getStartLocation().getCoordinate()); - } - - @Test - public void whenEndLocationCoordinateIsSetButNoId_idMustBeCoordToString(){ - Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(1.0, 2.0)).setEndLocation(Location.newInstance(3.0, 4.0)).build(); - assertEquals(v.getEndLocation().getCoordinate().toString(), v.getEndLocation().getId()); - } - - @Test(expected=IllegalStateException.class) - public void whenEndLocationIdIsSpecifiedANDReturnToDepotIsFalse_itShouldThrowException(){ - @SuppressWarnings("unused") - Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(1.0, 2.0)).setEndLocation(Location.newInstance("endLoc")).setReturnToDepot(false).build(); - } - - @Test(expected=IllegalStateException.class) - public void whenEndLocationCoordIsSpecifiedANDReturnToDepotIsFalse_itShouldThrowException(){ - @SuppressWarnings("unused") - Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(1.0, 2.0)).setEndLocation(Location.newInstance(3, 4)).setReturnToDepot(false).build(); - } - - @Test - public void whenEndLocationCoordIsNotSpecifiedANDReturnToDepotIsFalse_endLocationCoordMustBeStartLocationCoord(){ - Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(1.0, 2.0)).setReturnToDepot(false).build(); - assertEquals(v.getStartLocation().getCoordinate(),v.getEndLocation().getCoordinate()); - } - - @Test - public void whenEndLocationIdIsNotSpecifiedANDReturnToDepotIsFalse_endLocationIdMustBeStartLocationId(){ - Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(1.0, 2.0)).setReturnToDepot(false).build(); - assertEquals(v.getStartLocation().getCoordinate().toString(),v.getEndLocation().getId()); - } - - @Test(expected=IllegalStateException.class) - public void whenStartAndEndAreUnequalANDReturnToDepotIsFalse_itShouldThrowException(){ - @SuppressWarnings("unused") - Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")).setEndLocation(Location.newInstance("end")).setReturnToDepot(false).build(); - } - - @Test - public void whenStartAndEndAreEqualANDReturnToDepotIsFalse_itShouldThrowException(){ - @SuppressWarnings("unused") - Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")).setEndLocation(Location.newInstance("start")).setReturnToDepot(false).build(); - assertTrue(true); - } - @Test - public void whenTwoVehiclesHaveTheSameId_theyShouldBeEqual(){ - Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")).setEndLocation(Location.newInstance("start")).setReturnToDepot(false).build(); - Vehicle v2 = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")).setEndLocation(Location.newInstance("start")).setReturnToDepot(false).build(); - assertTrue(v.equals(v2)); - } - + @Test(expected = IllegalStateException.class) + public void whenVehicleIsBuiltWithoutSettingNeitherLocationNorCoord_itThrowsAnIllegalStateException() { + @SuppressWarnings("unused") + Vehicle v = VehicleImpl.Builder.newInstance("v").build(); + } + + + @Test + public void whenAddingDriverBreak_itShouldBeAddedCorrectly() { + VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("type").build(); + Break aBreak = (Break) Break.Builder.newInstance("break").setTimeWindow(TimeWindow.newInstance(100, 200)).setServiceTime(30).build(); + Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")) + .setType(type1).setEndLocation(Location.newInstance("start")) + .setBreak(aBreak).build(); + assertNotNull(v.getBreak()); + assertEquals(100., v.getBreak().getTimeWindow().getStart(), 0.1); + assertEquals(200., v.getBreak().getTimeWindow().getEnd(), 0.1); + assertEquals(30., v.getBreak().getServiceDuration(), 0.1); + } + + + @Test + public void whenAddingSkills_theyShouldBeAddedCorrectly() { + VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("type").build(); + Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")).setType(type1).setEndLocation(Location.newInstance("start")) + .addSkill("drill").addSkill("screwdriver").build(); + assertTrue(v.getSkills().containsSkill("drill")); + assertTrue(v.getSkills().containsSkill("drill")); + assertTrue(v.getSkills().containsSkill("screwdriver")); + } + + @Test + public void whenAddingSkillsCaseSens_theyShouldBeAddedCorrectly() { + VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("type").build(); + Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")).setType(type1).setEndLocation(Location.newInstance("start")) + .addSkill("drill").addSkill("screwdriver").build(); + assertTrue(v.getSkills().containsSkill("drill")); + assertTrue(v.getSkills().containsSkill("dRill")); + assertTrue(v.getSkills().containsSkill("ScrewDriver")); + } + + + @Test + public void whenVehicleIsBuiltToReturnToDepot_itShouldReturnToDepot() { + Vehicle v = VehicleImpl.Builder.newInstance("v").setReturnToDepot(true).setStartLocation(Location.newInstance("loc")).build(); + assertTrue(v.isReturnToDepot()); + } + + @Test + public void whenVehicleIsBuiltToNotReturnToDepot_itShouldNotReturnToDepot() { + Vehicle v = VehicleImpl.Builder.newInstance("v").setReturnToDepot(false).setStartLocation(Location.newInstance("loc")).build(); + assertFalse(v.isReturnToDepot()); + } + + @Test + public void whenVehicleIsBuiltWithLocation_itShouldHvTheCorrectLocation() { + Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("loc")).build(); + assertEquals("loc", v.getStartLocation().getId()); + } + + @Test + public void whenVehicleIsBuiltWithCoord_itShouldHvTheCorrectCoord() { + Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(1, 2)).build(); + assertEquals(1.0, v.getStartLocation().getCoordinate().getX(), 0.01); + assertEquals(2.0, v.getStartLocation().getCoordinate().getY(), 0.01); + } + + @Test + public void whenVehicleIsBuiltAndEarliestStartIsNotSet_itShouldSetTheDefaultOfZero() { + Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(1, 2)).build(); + assertEquals(0.0, v.getEarliestDeparture(), 0.01); + } + + @Test + public void whenVehicleIsBuiltAndEarliestStartSet_itShouldBeSetCorrectly() { + Vehicle v = VehicleImpl.Builder.newInstance("v").setEarliestStart(10.0).setStartLocation(Location.newInstance(1, 2)).build(); + assertEquals(10.0, v.getEarliestDeparture(), 0.01); + } + + @Test + public void whenVehicleIsBuiltAndLatestArrivalIsNotSet_itShouldSetDefaultOfDoubleMaxValue() { + Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(1, 2)).build(); + assertEquals(Double.MAX_VALUE, v.getLatestArrival(), 0.01); + } + + @Test + public void whenVehicleIsBuiltAndLatestArrivalIsSet_itShouldBeSetCorrectly() { + Vehicle v = VehicleImpl.Builder.newInstance("v").setLatestArrival(30.0).setStartLocation(Location.newInstance(1, 2)).build(); + assertEquals(30.0, v.getLatestArrival(), 0.01); + } + + @Test + public void whenNoVehicleIsCreate_itShouldHvTheCorrectId() { + Vehicle v = VehicleImpl.createNoVehicle(); + assertEquals("noVehicle", v.getId()); + } + + @Test + public void whenStartLocationIsSet_itIsDoneCorrectly() { + Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("startLoc")).build(); + assertEquals("startLoc", v.getStartLocation().getId()); + } + + @Test(expected = IllegalStateException.class) + public void whenStartLocationIsNull_itThrowsException() { + @SuppressWarnings("unused") + Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(null)).build(); + } + + @Test + public void whenStartLocationCoordIsSet_itIsDoneCorrectly() { + Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(1, 2)).build(); + assertEquals(1.0, v.getStartLocation().getCoordinate().getX(), 0.01); + assertEquals(2.0, v.getStartLocation().getCoordinate().getY(), 0.01); + } + + @Test + public void whenEndLocationIsSet_itIsDoneCorrectly() { + Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("startLoc")).setEndLocation(Location.newInstance("endLoc")).build(); + assertEquals("startLoc", v.getStartLocation().getId()); + assertEquals("endLoc", v.getEndLocation().getId()); + } + + @Test + public void whenEndLocationCoordIsSet_itIsDoneCorrectly() { + Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("startLoc")).setEndLocation(Location.newInstance(1, 2)).build(); + assertEquals(1.0, v.getEndLocation().getCoordinate().getX(), 0.01); + assertEquals(2.0, v.getEndLocation().getCoordinate().getY(), 0.01); + } + + + @Test + public void whenNeitherEndLocationIdNorEndLocationCoordAreSet_endLocationIdMustBeEqualToStartLocationId() { + Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("startLoc")).build(); + assertEquals("startLoc", v.getEndLocation().getId()); + } + + @Test + public void whenNeitherEndLocationIdNorEndLocationCoordAreSet_endLocationCoordMustBeEqualToStartLocationCoord() { + Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("startLoc")).build(); + assertEquals(v.getEndLocation().getCoordinate(), v.getStartLocation().getCoordinate()); + } + + @Test + public void whenNeitherEndLocationIdNorEndLocationCoordAreSet_endLocationCoordMustBeEqualToStartLocationCoordV2() { + Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(1.0, 2.0)).build(); + assertEquals(v.getEndLocation().getCoordinate(), v.getStartLocation().getCoordinate()); + } + + @Test + public void whenEndLocationCoordinateIsSetButNoId_idMustBeCoordToString() { + Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(1.0, 2.0)).setEndLocation(Location.newInstance(3.0, 4.0)).build(); + assertEquals(v.getEndLocation().getCoordinate().toString(), v.getEndLocation().getId()); + } + + @Test(expected = IllegalStateException.class) + public void whenEndLocationIdIsSpecifiedANDReturnToDepotIsFalse_itShouldThrowException() { + @SuppressWarnings("unused") + Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(1.0, 2.0)).setEndLocation(Location.newInstance("endLoc")).setReturnToDepot(false).build(); + } + + @Test(expected = IllegalStateException.class) + public void whenEndLocationCoordIsSpecifiedANDReturnToDepotIsFalse_itShouldThrowException() { + @SuppressWarnings("unused") + Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(1.0, 2.0)).setEndLocation(Location.newInstance(3, 4)).setReturnToDepot(false).build(); + } + + @Test + public void whenEndLocationCoordIsNotSpecifiedANDReturnToDepotIsFalse_endLocationCoordMustBeStartLocationCoord() { + Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(1.0, 2.0)).setReturnToDepot(false).build(); + assertEquals(v.getStartLocation().getCoordinate(), v.getEndLocation().getCoordinate()); + } + + @Test + public void whenEndLocationIdIsNotSpecifiedANDReturnToDepotIsFalse_endLocationIdMustBeStartLocationId() { + Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(1.0, 2.0)).setReturnToDepot(false).build(); + assertEquals(v.getStartLocation().getCoordinate().toString(), v.getEndLocation().getId()); + } + + @Test(expected = IllegalStateException.class) + public void whenStartAndEndAreUnequalANDReturnToDepotIsFalse_itShouldThrowException() { + @SuppressWarnings("unused") + Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")).setEndLocation(Location.newInstance("end")).setReturnToDepot(false).build(); + } + + @Test + public void whenStartAndEndAreEqualANDReturnToDepotIsFalse_itShouldThrowException() { + @SuppressWarnings("unused") + Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")).setEndLocation(Location.newInstance("start")).setReturnToDepot(false).build(); + assertTrue(true); + } + + @Test + public void whenTwoVehiclesHaveTheSameId_theyShouldBeEqual() { + Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")).setEndLocation(Location.newInstance("start")).setReturnToDepot(false).build(); + Vehicle v2 = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")).setEndLocation(Location.newInstance("start")).setReturnToDepot(false).build(); + assertTrue(v.equals(v2)); + } + + + @Test + public void whenAddingSkillsCaseSensV2_theyShouldBeAddedCorrectly() { + VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("type").build(); + Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")).setType(type1).setEndLocation(Location.newInstance("start")) + .addSkill("drill").build(); + assertFalse(v.getSkills().containsSkill("ScrewDriver")); + } + - @Test - public void whenAddingSkills_theyShouldBeAddedCorrectly(){ - VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("type").build(); - Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")).setType(type1).setEndLocation(Location.newInstance("start")) - .addSkill("drill").addSkill("screwdriver").build(); - assertTrue(v.getSkills().containsSkill("drill")); - assertTrue(v.getSkills().containsSkill("drill")); - assertTrue(v.getSkills().containsSkill("screwdriver")); - } - - @Test - public void whenAddingSkillsCaseSens_theyShouldBeAddedCorrectly(){ - VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("type").build(); - Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")).setType(type1).setEndLocation(Location.newInstance("start")) - .addSkill("drill").addSkill("screwdriver").build(); - assertTrue(v.getSkills().containsSkill("drill")); - assertTrue(v.getSkills().containsSkill("dRill")); - assertTrue(v.getSkills().containsSkill("ScrewDriver")); - } - - @Test - public void whenAddingSkillsCaseSensV2_theyShouldBeAddedCorrectly(){ - VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("type").build(); - Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")).setType(type1).setEndLocation(Location.newInstance("start")) - .addSkill("drill").build(); - assertFalse(v.getSkills().containsSkill("ScrewDriver")); - } - - } diff --git a/jsprit-core/src/test/java/jsprit/core/problem/vehicle/VehicleTypeImplTest.java b/jsprit-core/src/test/java/jsprit/core/problem/vehicle/VehicleTypeImplTest.java index 2f082ba0..622447bc 100644 --- a/jsprit-core/src/test/java/jsprit/core/problem/vehicle/VehicleTypeImplTest.java +++ b/jsprit-core/src/test/java/jsprit/core/problem/vehicle/VehicleTypeImplTest.java @@ -1,18 +1,18 @@ /******************************************************************************* * Copyright (c) 2014 Stefan Schroeder. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . - * + * * Contributors: * Stefan Schroeder - initial API and implementation ******************************************************************************/ @@ -24,133 +24,133 @@ import static org.junit.Assert.*; public class VehicleTypeImplTest { - @Test(expected=IllegalArgumentException.class) - public void whenTypeHasNegativeCapacityVal_throwIllegalStateExpception(){ - @SuppressWarnings("unused") - VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("t").addCapacityDimension(0,-10).build(); - } - - @Test - public void whenAddingTwoCapDimension_nuOfDimsShouldBeTwo(){ - VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("t") - .addCapacityDimension(0,2) - .addCapacityDimension(1, 4) - .build(); - assertEquals(2,type.getCapacityDimensions().getNuOfDimensions()); - } - - @Test - public void whenAddingTwoCapDimension_dimValuesMustBeCorrect(){ - VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("t") - .addCapacityDimension(0,2) - .addCapacityDimension(1,4) - .build(); - assertEquals(2,type.getCapacityDimensions().get(0)); - assertEquals(4,type.getCapacityDimensions().get(1)); - } - - @Test - public void whenTypeIsBuiltWithoutSpecifyingCapacity_itShouldHvCapWithOneDim(){ - VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("t").build(); - assertEquals(1,type.getCapacityDimensions().getNuOfDimensions()); - } - - @Test - public void whenTypeIsBuiltWithoutSpecifyingCapacity_itShouldHvCapDimValOfZero(){ - VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("t").build(); - assertEquals(0,type.getCapacityDimensions().get(0)); - } - - @Test - public void whenCallingStaticNewBuilderInstance_itShouldReturnNewBuilderInstance(){ - VehicleTypeImpl.Builder builder = VehicleTypeImpl.Builder.newInstance("foo"); - assertNotNull(builder); - } - - @Test - public void whenBuildingTypeJustByCallingNewInstance_typeIdMustBeCorrect(){ - VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("foo").build(); - assertEquals("foo",type.getTypeId()); - } - - @Test - public void whenBuildingTypeJustByCallingNewInstance_capMustBeCorrect(){ - VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("foo").build(); - assertEquals(0,type.getCapacityDimensions().get(0)); - } - - @Test(expected=IllegalArgumentException.class) - public void whenBuildingTypeWithCapSmallerThanZero_throwIllegalStateException(){ - @SuppressWarnings("unused") - VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("foo").addCapacityDimension(0, -10).build(); - } - - @Test(expected=IllegalStateException.class) - public void whenBuildingTypeWithNullId_throwIllegalStateException(){ - @SuppressWarnings("unused") - VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance(null).addCapacityDimension(0, 10).build(); - } - - - @Test - public void whenSettingMaxVelocity_itShouldBeSetCorrectly(){ - VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type").setMaxVelocity(10).build(); - assertEquals(10,type.getMaxVelocity(),0.0); - } - - - @Test(expected=IllegalStateException.class) - public void whenMaxVelocitySmallerThanZero_itShouldThrowException(){ - @SuppressWarnings("unused") - VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type").setMaxVelocity(-10).build(); - } - - @Test(expected=IllegalStateException.class) - public void whenFixedCostsSmallerThanZero_itShouldThrowException(){ - @SuppressWarnings("unused") - VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type").setFixedCost(-10).build(); - } - - public void whenSettingFixedCosts_itShouldBeSetCorrectly(){ - VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type").setFixedCost(10).build(); - assertEquals(10.0, type.getVehicleCostParams().fix,0.0); - } - - @Test(expected=IllegalStateException.class) - public void whenPerDistanceCostsSmallerThanZero_itShouldThrowException(){ - @SuppressWarnings("unused") - VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type").setCostPerDistance(-10).build(); - } - - public void whenSettingPerDistanceCosts_itShouldBeSetCorrectly(){ - VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type").setCostPerDistance(10).build(); - assertEquals(10.0, type.getVehicleCostParams().perDistanceUnit,0.0); - } - - @Test(expected=IllegalStateException.class) - public void whenPerTimeCostsSmallerThanZero_itShouldThrowException(){ - @SuppressWarnings("unused") - VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type").setCostPerTime(-10).build(); - } - - @Test - public void whenSettingPerTimeCosts_itShouldBeSetCorrectly(){ - VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type").setCostPerTime(10).build(); - assertEquals(10.0, type.getVehicleCostParams().perTimeUnit,0.0); - } - - @Test - public void whenHavingTwoTypesWithTheSameId_theyShouldBeEqual(){ - VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type").setCostPerTime(10).build(); - VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("type").setCostPerTime(10).build(); - assertTrue(type.equals(type2)); - } - - @Test - public void whenAddingProfile_itShouldBeCorrect(){ - VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type").setProfile("car").build(); - assertEquals("car",type.getProfile()); - } - + @Test(expected = IllegalArgumentException.class) + public void whenTypeHasNegativeCapacityVal_throwIllegalStateExpception() { + @SuppressWarnings("unused") + VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("t").addCapacityDimension(0, -10).build(); + } + + @Test + public void whenAddingTwoCapDimension_nuOfDimsShouldBeTwo() { + VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("t") + .addCapacityDimension(0, 2) + .addCapacityDimension(1, 4) + .build(); + assertEquals(2, type.getCapacityDimensions().getNuOfDimensions()); + } + + @Test + public void whenAddingTwoCapDimension_dimValuesMustBeCorrect() { + VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("t") + .addCapacityDimension(0, 2) + .addCapacityDimension(1, 4) + .build(); + assertEquals(2, type.getCapacityDimensions().get(0)); + assertEquals(4, type.getCapacityDimensions().get(1)); + } + + @Test + public void whenTypeIsBuiltWithoutSpecifyingCapacity_itShouldHvCapWithOneDim() { + VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("t").build(); + assertEquals(1, type.getCapacityDimensions().getNuOfDimensions()); + } + + @Test + public void whenTypeIsBuiltWithoutSpecifyingCapacity_itShouldHvCapDimValOfZero() { + VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("t").build(); + assertEquals(0, type.getCapacityDimensions().get(0)); + } + + @Test + public void whenCallingStaticNewBuilderInstance_itShouldReturnNewBuilderInstance() { + VehicleTypeImpl.Builder builder = VehicleTypeImpl.Builder.newInstance("foo"); + assertNotNull(builder); + } + + @Test + public void whenBuildingTypeJustByCallingNewInstance_typeIdMustBeCorrect() { + VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("foo").build(); + assertEquals("foo", type.getTypeId()); + } + + @Test + public void whenBuildingTypeJustByCallingNewInstance_capMustBeCorrect() { + VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("foo").build(); + assertEquals(0, type.getCapacityDimensions().get(0)); + } + + @Test(expected = IllegalArgumentException.class) + public void whenBuildingTypeWithCapSmallerThanZero_throwIllegalStateException() { + @SuppressWarnings("unused") + VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("foo").addCapacityDimension(0, -10).build(); + } + + @Test(expected = IllegalStateException.class) + public void whenBuildingTypeWithNullId_throwIllegalStateException() { + @SuppressWarnings("unused") + VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance(null).addCapacityDimension(0, 10).build(); + } + + + @Test + public void whenSettingMaxVelocity_itShouldBeSetCorrectly() { + VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type").setMaxVelocity(10).build(); + assertEquals(10, type.getMaxVelocity(), 0.0); + } + + + @Test(expected = IllegalStateException.class) + public void whenMaxVelocitySmallerThanZero_itShouldThrowException() { + @SuppressWarnings("unused") + VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type").setMaxVelocity(-10).build(); + } + + @Test(expected = IllegalStateException.class) + public void whenFixedCostsSmallerThanZero_itShouldThrowException() { + @SuppressWarnings("unused") + VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type").setFixedCost(-10).build(); + } + + public void whenSettingFixedCosts_itShouldBeSetCorrectly() { + VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type").setFixedCost(10).build(); + assertEquals(10.0, type.getVehicleCostParams().fix, 0.0); + } + + @Test(expected = IllegalStateException.class) + public void whenPerDistanceCostsSmallerThanZero_itShouldThrowException() { + @SuppressWarnings("unused") + VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type").setCostPerDistance(-10).build(); + } + + public void whenSettingPerDistanceCosts_itShouldBeSetCorrectly() { + VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type").setCostPerDistance(10).build(); + assertEquals(10.0, type.getVehicleCostParams().perDistanceUnit, 0.0); + } + + @Test(expected = IllegalStateException.class) + public void whenPerTimeCostsSmallerThanZero_itShouldThrowException() { + @SuppressWarnings("unused") + VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type").setCostPerTime(-10).build(); + } + + @Test + public void whenSettingPerTimeCosts_itShouldBeSetCorrectly() { + VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type").setCostPerTime(10).build(); + assertEquals(10.0, type.getVehicleCostParams().perTimeUnit, 0.0); + } + + @Test + public void whenHavingTwoTypesWithTheSameId_theyShouldBeEqual() { + VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type").setCostPerTime(10).build(); + VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("type").setCostPerTime(10).build(); + assertTrue(type.equals(type2)); + } + + @Test + public void whenAddingProfile_itShouldBeCorrect() { + VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type").setProfile("car").build(); + assertEquals("car", type.getProfile()); + } + } diff --git a/jsprit-core/src/test/java/jsprit/core/problem/vehicle/VehicleTypeKeyTest.java b/jsprit-core/src/test/java/jsprit/core/problem/vehicle/VehicleTypeKeyTest.java index b8e8632b..5b8bca8e 100644 --- a/jsprit-core/src/test/java/jsprit/core/problem/vehicle/VehicleTypeKeyTest.java +++ b/jsprit-core/src/test/java/jsprit/core/problem/vehicle/VehicleTypeKeyTest.java @@ -10,20 +10,20 @@ import static org.junit.Assert.assertTrue; public class VehicleTypeKeyTest { @Test - public void typeIdentifierShouldBeEqual(){ + public void typeIdentifierShouldBeEqual() { Vehicle v1 = VehicleImpl.Builder.newInstance("v1").setStartLocation(Location.newInstance("start")).addSkill("skill1").addSkill("skill2") - .addSkill("skill3").build(); + .addSkill("skill3").build(); Vehicle v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(Location.newInstance("start")).addSkill("skill2").addSkill("skill1") - .addSkill("skill3").build(); + .addSkill("skill3").build(); assertTrue(v1.getVehicleTypeIdentifier().equals(v2.getVehicleTypeIdentifier())); } @Test - public void typeIdentifierShouldNotBeEqual(){ + public void typeIdentifierShouldNotBeEqual() { Vehicle v1 = VehicleImpl.Builder.newInstance("v1").setStartLocation(Location.newInstance("start")).addSkill("skill1").addSkill("skill2") - .build(); + .build(); Vehicle v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(Location.newInstance("start")).addSkill("skill2").addSkill("skill1") - .addSkill("skill3").build(); + .addSkill("skill3").build(); assertFalse(v1.getVehicleTypeIdentifier().equals(v2.getVehicleTypeIdentifier())); } } diff --git a/jsprit-core/src/test/java/jsprit/core/util/CostFactory.java b/jsprit-core/src/test/java/jsprit/core/util/CostFactory.java index f42f680c..5fc8c4e6 100644 --- a/jsprit-core/src/test/java/jsprit/core/util/CostFactory.java +++ b/jsprit-core/src/test/java/jsprit/core/util/CostFactory.java @@ -1,18 +1,18 @@ /******************************************************************************* * Copyright (c) 2014 Stefan Schroeder. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . - * + * * Contributors: * Stefan Schroeder - initial API and implementation ******************************************************************************/ @@ -24,47 +24,47 @@ public class CostFactory { /** * Return manhattanCosts. - *

+ *

* This retrieves coordinates from locationIds. LocationId has to be locId="{x},{y}". For example, * locId="10,10" is interpreted such that x=10 and y=10. * * @return manhattanCosts */ - public static VehicleRoutingTransportCosts createManhattanCosts(){ - Locations locations = new Locations(){ + public static VehicleRoutingTransportCosts createManhattanCosts() { + Locations locations = new Locations() { - @Override - public Coordinate getCoord(String id) { - //assume: locationId="x,y" - String[] splitted = id.split(","); - return Coordinate.newInstance(Double.parseDouble(splitted[0]), - Double.parseDouble(splitted[1])); - } - - }; - return new ManhattanCosts(locations); - } + @Override + public Coordinate getCoord(String id) { + //assume: locationId="x,y" + String[] splitted = id.split(","); + return Coordinate.newInstance(Double.parseDouble(splitted[0]), + Double.parseDouble(splitted[1])); + } + + }; + return new ManhattanCosts(locations); + } /** * Return euclideanCosts. - *

+ *

* This retrieves coordinates from locationIds. LocationId has to be locId="{x},{y}". For example, * locId="10,10" is interpreted such that x=10 and y=10. * * @return euclidean */ - public static VehicleRoutingTransportCosts createEuclideanCosts(){ - Locations locations = new Locations(){ + public static VehicleRoutingTransportCosts createEuclideanCosts() { + Locations locations = new Locations() { - @Override - public Coordinate getCoord(String id) { - //assume: locationId="x,y" - String[] splitted = id.split(","); - return Coordinate.newInstance(Double.parseDouble(splitted[0]), - Double.parseDouble(splitted[1])); - } - - }; - return new CrowFlyCosts(locations); - } + @Override + public Coordinate getCoord(String id) { + //assume: locationId="x,y" + String[] splitted = id.split(","); + return Coordinate.newInstance(Double.parseDouble(splitted[0]), + Double.parseDouble(splitted[1])); + } + + }; + return new CrowFlyCosts(locations); + } } diff --git a/jsprit-core/src/test/java/jsprit/core/util/FastVehicleRoutingTransportCostsMatrixTest.java b/jsprit-core/src/test/java/jsprit/core/util/FastVehicleRoutingTransportCostsMatrixTest.java index 2b3b1e9d..0aa713bf 100644 --- a/jsprit-core/src/test/java/jsprit/core/util/FastVehicleRoutingTransportCostsMatrixTest.java +++ b/jsprit-core/src/test/java/jsprit/core/util/FastVehicleRoutingTransportCostsMatrixTest.java @@ -27,73 +27,73 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; public class FastVehicleRoutingTransportCostsMatrixTest { - - @Test - public void whenAddingDistanceToSymmetricMatrix_itShouldReturnCorrectValues(){ - FastVehicleRoutingTransportCostsMatrix.Builder matrixBuilder = FastVehicleRoutingTransportCostsMatrix.Builder.newInstance(3,true); - matrixBuilder.addTransportDistance(1, 2, 2.); - FastVehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build(); - assertEquals(2.,matrix.getTransportCost(loc(1), loc(2), 0.0, null, null),0.1); - assertEquals(2.,matrix.getDistance(1, 2),0.1); - assertEquals(2.,matrix.getTransportCost(loc(2), loc(1), 0.0, null, null),0.1); - assertEquals(2.,matrix.getDistance(2, 1),0.1); - } - @Test - public void whenAddingDistanceToAsymmetricMatrix_itShouldReturnCorrectValues(){ - FastVehicleRoutingTransportCostsMatrix.Builder matrixBuilder = FastVehicleRoutingTransportCostsMatrix.Builder.newInstance(3,false); - matrixBuilder.addTransportDistance(1, 2, 2.); - FastVehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build(); - assertEquals(2.,matrix.getTransportCost(loc(1), loc(2), 0.0, null, null),0.1); - } + @Test + public void whenAddingDistanceToSymmetricMatrix_itShouldReturnCorrectValues() { + FastVehicleRoutingTransportCostsMatrix.Builder matrixBuilder = FastVehicleRoutingTransportCostsMatrix.Builder.newInstance(3, true); + matrixBuilder.addTransportDistance(1, 2, 2.); + FastVehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build(); + assertEquals(2., matrix.getTransportCost(loc(1), loc(2), 0.0, null, null), 0.1); + assertEquals(2., matrix.getDistance(1, 2), 0.1); + assertEquals(2., matrix.getTransportCost(loc(2), loc(1), 0.0, null, null), 0.1); + assertEquals(2., matrix.getDistance(2, 1), 0.1); + } + + @Test + public void whenAddingDistanceToAsymmetricMatrix_itShouldReturnCorrectValues() { + FastVehicleRoutingTransportCostsMatrix.Builder matrixBuilder = FastVehicleRoutingTransportCostsMatrix.Builder.newInstance(3, false); + matrixBuilder.addTransportDistance(1, 2, 2.); + FastVehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build(); + assertEquals(2., matrix.getTransportCost(loc(1), loc(2), 0.0, null, null), 0.1); + } private Location loc(int index) { return Location.Builder.newInstance().setIndex(index).build(); } - @Test - public void whenAddingTimeToSymmetricMatrix_itShouldReturnCorrectValues(){ - FastVehicleRoutingTransportCostsMatrix.Builder matrixBuilder = FastVehicleRoutingTransportCostsMatrix.Builder.newInstance(3,true); - matrixBuilder.addTransportTime(1, 2, 2.); - FastVehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build(); - assertEquals(2.,matrix.getTransportTime(loc(1), loc(2), 0.0, null, null),0.1); - assertEquals(2.,matrix.getTransportTime(loc(2), loc(1), 0.0, null, null),0.1); - } + @Test + public void whenAddingTimeToSymmetricMatrix_itShouldReturnCorrectValues() { + FastVehicleRoutingTransportCostsMatrix.Builder matrixBuilder = FastVehicleRoutingTransportCostsMatrix.Builder.newInstance(3, true); + matrixBuilder.addTransportTime(1, 2, 2.); + FastVehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build(); + assertEquals(2., matrix.getTransportTime(loc(1), loc(2), 0.0, null, null), 0.1); + assertEquals(2., matrix.getTransportTime(loc(2), loc(1), 0.0, null, null), 0.1); + } - @Test - public void whenAddingTimeToAsymmetricMatrix_itShouldReturnCorrectValues(){ - FastVehicleRoutingTransportCostsMatrix.Builder matrixBuilder = FastVehicleRoutingTransportCostsMatrix.Builder.newInstance(3,false); - matrixBuilder.addTransportTime(1, 2, 2.); - FastVehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build(); - assertEquals(2.,matrix.getTransportTime(loc(1), loc(2), 0.0, null, null),0.1); - } + @Test + public void whenAddingTimeToAsymmetricMatrix_itShouldReturnCorrectValues() { + FastVehicleRoutingTransportCostsMatrix.Builder matrixBuilder = FastVehicleRoutingTransportCostsMatrix.Builder.newInstance(3, false); + matrixBuilder.addTransportTime(1, 2, 2.); + FastVehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build(); + assertEquals(2., matrix.getTransportTime(loc(1), loc(2), 0.0, null, null), 0.1); + } - @Test - public void whenAddingTimeAndDistanceToSymmetricMatrix_itShouldReturnCorrectValues(){ - FastVehicleRoutingTransportCostsMatrix.Builder matrixBuilder = FastVehicleRoutingTransportCostsMatrix.Builder.newInstance(3,true); - matrixBuilder.addTransportDistance(1, 2, 20.); - matrixBuilder.addTransportTime(1, 2, 2.); - FastVehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build(); - Vehicle vehicle = mock(Vehicle.class); - VehicleType type = VehicleTypeImpl.Builder.newInstance("t").setCostPerDistance(1.).setCostPerTime(2.).build(); - when(vehicle.getType()).thenReturn(type); - assertEquals(24.,matrix.getTransportCost(loc(1), loc(2), 0.0, null, vehicle),0.1); - assertEquals(24.,matrix.getTransportCost(loc(2), loc(1), 0.0, null, vehicle),0.1); - } + @Test + public void whenAddingTimeAndDistanceToSymmetricMatrix_itShouldReturnCorrectValues() { + FastVehicleRoutingTransportCostsMatrix.Builder matrixBuilder = FastVehicleRoutingTransportCostsMatrix.Builder.newInstance(3, true); + matrixBuilder.addTransportDistance(1, 2, 20.); + matrixBuilder.addTransportTime(1, 2, 2.); + FastVehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build(); + Vehicle vehicle = mock(Vehicle.class); + VehicleType type = VehicleTypeImpl.Builder.newInstance("t").setCostPerDistance(1.).setCostPerTime(2.).build(); + when(vehicle.getType()).thenReturn(type); + assertEquals(24., matrix.getTransportCost(loc(1), loc(2), 0.0, null, vehicle), 0.1); + assertEquals(24., matrix.getTransportCost(loc(2), loc(1), 0.0, null, vehicle), 0.1); + } - @Test - public void whenAddingTimeAndDistanceToAsymmetricMatrix_itShouldReturnCorrectValues(){ - FastVehicleRoutingTransportCostsMatrix.Builder matrixBuilder = FastVehicleRoutingTransportCostsMatrix.Builder.newInstance(3,false); - matrixBuilder.addTransportTime(1, 2, 2.); - matrixBuilder.addTransportTime(2, 1, 8.); - FastVehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build(); - Vehicle vehicle = mock(Vehicle.class); - VehicleType type = VehicleTypeImpl.Builder.newInstance("t").setCostPerDistance(1.).setCostPerTime(2.).build(); - when(vehicle.getType()).thenReturn(type); - assertEquals(4.,matrix.getTransportCost(loc(1), loc(2), 0.0, null, vehicle),0.1); - assertEquals(16.,matrix.getTransportCost(loc(2), loc(1), 0.0, null, vehicle),0.1); - } + @Test + public void whenAddingTimeAndDistanceToAsymmetricMatrix_itShouldReturnCorrectValues() { + FastVehicleRoutingTransportCostsMatrix.Builder matrixBuilder = FastVehicleRoutingTransportCostsMatrix.Builder.newInstance(3, false); + matrixBuilder.addTransportTime(1, 2, 2.); + matrixBuilder.addTransportTime(2, 1, 8.); + FastVehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build(); + Vehicle vehicle = mock(Vehicle.class); + VehicleType type = VehicleTypeImpl.Builder.newInstance("t").setCostPerDistance(1.).setCostPerTime(2.).build(); + when(vehicle.getType()).thenReturn(type); + assertEquals(4., matrix.getTransportCost(loc(1), loc(2), 0.0, null, vehicle), 0.1); + assertEquals(16., matrix.getTransportCost(loc(2), loc(1), 0.0, null, vehicle), 0.1); + } } diff --git a/jsprit-core/src/test/java/jsprit/core/util/GreatCircleDistanceCalculatorTest.java b/jsprit-core/src/test/java/jsprit/core/util/GreatCircleDistanceCalculatorTest.java index 59a9b3b0..f1d27144 100644 --- a/jsprit-core/src/test/java/jsprit/core/util/GreatCircleDistanceCalculatorTest.java +++ b/jsprit-core/src/test/java/jsprit/core/util/GreatCircleDistanceCalculatorTest.java @@ -26,7 +26,7 @@ import org.junit.Test; public class GreatCircleDistanceCalculatorTest { @Test - public void test(){ + public void test() { double lon1 = 8.3858333; double lat1 = 49.0047222; @@ -34,15 +34,15 @@ public class GreatCircleDistanceCalculatorTest { double lat2 = 54.0833333; double greatCircle = GreatCircleDistanceCalculator.calculateDistance( - Coordinate.newInstance(lon1,lat1), - Coordinate.newInstance(lon2,lat2), - DistanceUnit.Kilometer + Coordinate.newInstance(lon1, lat1), + Coordinate.newInstance(lon2, lat2), + DistanceUnit.Kilometer ); - Assert.assertEquals(600,greatCircle,30.); + Assert.assertEquals(600, greatCircle, 30.); } @Test - public void testMeter(){ + public void testMeter() { double lon1 = 8.3858333; double lat1 = 49.0047222; @@ -50,11 +50,11 @@ public class GreatCircleDistanceCalculatorTest { double lat2 = 54.0833333; double greatCircle = GreatCircleDistanceCalculator.calculateDistance( - Coordinate.newInstance(lon1,lat1), - Coordinate.newInstance(lon2,lat2), - DistanceUnit.Meter + Coordinate.newInstance(lon1, lat1), + Coordinate.newInstance(lon2, lat2), + DistanceUnit.Meter ); - Assert.assertEquals(600000,greatCircle,30000.); + Assert.assertEquals(600000, greatCircle, 30000.); } } diff --git a/jsprit-core/src/test/java/jsprit/core/util/RandomUtilsTest.java b/jsprit-core/src/test/java/jsprit/core/util/RandomUtilsTest.java index 9e7f1eb7..20e9a7df 100644 --- a/jsprit-core/src/test/java/jsprit/core/util/RandomUtilsTest.java +++ b/jsprit-core/src/test/java/jsprit/core/util/RandomUtilsTest.java @@ -18,26 +18,26 @@ import static org.mockito.Mockito.when; public class RandomUtilsTest { @Test - public void shouldReturnSingleJob(){ + public void shouldReturnSingleJob() { Job job = mock(Job.class); Collection jobs = Arrays.asList(job); Assert.assertEquals(job, RandomUtils.nextItem(jobs, RandomNumberGeneration.getRandom())); } @Test - public void shouldReturnSingleJob_(){ + public void shouldReturnSingleJob_() { Job job = mock(Job.class); Collection jobs = Arrays.asList(job); Assert.assertEquals(job, RandomUtils.nextJob(jobs, RandomNumberGeneration.getRandom())); } @Test - public void shouldReturnJob3(){ + public void shouldReturnJob3() { Job job3 = mock(Job.class); - List jobs = Arrays.asList(mock(Job.class),mock(Job.class),job3); + List jobs = Arrays.asList(mock(Job.class), mock(Job.class), job3); Random random = mock(Random.class); when(random.nextInt(jobs.size())).thenReturn(2); - Assert.assertEquals(job3,RandomUtils.nextJob(jobs,random)); + Assert.assertEquals(job3, RandomUtils.nextJob(jobs, random)); } diff --git a/jsprit-core/src/test/java/jsprit/core/util/TestUtils.java b/jsprit-core/src/test/java/jsprit/core/util/TestUtils.java index f284b116..5e579a2d 100644 --- a/jsprit-core/src/test/java/jsprit/core/util/TestUtils.java +++ b/jsprit-core/src/test/java/jsprit/core/util/TestUtils.java @@ -7,15 +7,15 @@ import jsprit.core.problem.Location; */ public class TestUtils { - public static Location loc(String id, Coordinate coordinate){ + public static Location loc(String id, Coordinate coordinate) { return Location.Builder.newInstance().setId(id).setCoordinate(coordinate).build(); } - public static Location loc(String id){ + public static Location loc(String id) { return Location.Builder.newInstance().setId(id).build(); } - public static Location loc(Coordinate coordinate){ + public static Location loc(Coordinate coordinate) { return Location.Builder.newInstance().setCoordinate(coordinate).build(); } } diff --git a/jsprit-core/src/test/java/jsprit/core/util/TimeTest.java b/jsprit-core/src/test/java/jsprit/core/util/TimeTest.java index bd927bfd..ec6f2879 100644 --- a/jsprit-core/src/test/java/jsprit/core/util/TimeTest.java +++ b/jsprit-core/src/test/java/jsprit/core/util/TimeTest.java @@ -21,166 +21,164 @@ import org.junit.Test; import static org.junit.Assert.assertEquals; public class TimeTest { - - @Test - public void sixAM_shouldBeParsedCorrectly(){ - double sec = Time.parseTimeToSeconds("6AM"); - assertEquals(6.*3600.,sec,0.01); - } - - @Test - public void sixAMWithWhiteSpace_shouldBeParsedCorrectly(){ - double sec = Time.parseTimeToSeconds("6 AM"); - assertEquals(6.*3600.,sec,0.01); - } - - @Test - public void sixaMWithWhiteSpace_shouldBeParsedCorrectly(){ - double sec = Time.parseTimeToSeconds("6 aM"); - assertEquals(6.*3600.,sec,0.01); - } - - @Test - public void sixamWithWhiteSpace_shouldBeParsedCorrectly(){ - double sec = Time.parseTimeToSeconds("6 am"); - assertEquals(6.*3600.,sec,0.01); - } - - @Test - public void sixAmWithWhiteSpace_shouldBeParsedCorrectly(){ - double sec = Time.parseTimeToSeconds("6 Am"); - assertEquals(6.*3600.,sec,0.01); - } - - - - - @Test - public void sixPM_shouldBeParsedCorrectly(){ - double sec = Time.parseTimeToSeconds("6PM"); - assertEquals(6.*3600.+12.*3600.,sec,0.01); - } - - @Test - public void sixPMWithWhiteSpace_shouldBeParsedCorrectly(){ - double sec = Time.parseTimeToSeconds("6 PM"); - assertEquals(6.*3600.+12.*3600.,sec,0.01); - } - - @Test - public void sixpMWithWhiteSpace_shouldBeParsedCorrectly(){ - double sec = Time.parseTimeToSeconds("6 pM"); - assertEquals(6.*3600.+12.*3600.,sec,0.01); - } - - @Test - public void sixpmWithWhiteSpace_shouldBeParsedCorrectly(){ - double sec = Time.parseTimeToSeconds("6 pm"); - assertEquals(6.*3600.+12.*3600.,sec,0.01); - } - - @Test - public void sixPmWithWhiteSpace_shouldBeParsedCorrectly(){ - double sec = Time.parseTimeToSeconds("6 Pm"); - assertEquals(6.*3600.+12.*3600,sec,0.01); - } - - @Test - public void sixAMWithLeadingZero_shouldBeParsedCorrectly(){ - double sec = Time.parseTimeToSeconds("06AM"); - assertEquals(6.*3600.,sec,0.01); - } - - @Test - public void sixHour_twelveMin_AM_shouldBeParsedCorrectly(){ - double sec = Time.parseTimeToSeconds("6:12AM"); - assertEquals(6.*3600.+12.*60.,sec,0.01); - } - - @Test - public void sixHour_sixMin_AM_shouldBeParsedCorrectly(){ - double sec = Time.parseTimeToSeconds("6:6AM"); - assertEquals(6.*3600.+6.*60.,sec,0.01); - } - - @Test - public void sixHour_sixMinWithLeadingZero_AM_shouldBeParsedCorrectly(){ - double sec = Time.parseTimeToSeconds("6:06AM"); - assertEquals(6.*3600.+6.*60.,sec,0.01); - } - - - @Test - public void sixHour_twelveMin_PM_shouldBeParsedCorrectly(){ - double sec = Time.parseTimeToSeconds("6:12PM"); - assertEquals(6.*3600.+12.*60.+12.*3600.,sec,0.01); - } - - @Test - public void sixHour_sixMin_PM_shouldBeParsedCorrectly(){ - double sec = Time.parseTimeToSeconds("6:6PM"); - assertEquals(6.*3600.+6.*60.+12.*3600.,sec,0.01); - } - - @Test - public void sixHour_sixMinWithLeadingZero_PM_shouldBeParsedCorrectly(){ - double sec = Time.parseTimeToSeconds("6:06PM"); - assertEquals(6.*3600.+6.*60.+12.*3600.,sec,0.01); - } - - @Test - public void sixHour_sixMinWithLeadingZero_twelveSec_PM_shouldBeParsedCorrectly(){ - double sec = Time.parseTimeToSeconds("6:06:12PM"); - assertEquals(6.*3600.+6.*60.+12.*3600.+12.,sec,0.01); - } - - @Test - public void sixHour_sixMinWithLeadingZero_twelveSec_shouldBeParsedCorrectly(){ - double sec = Time.parseTimeToSeconds("6:06:12"); - assertEquals(6.*3600.+6.*60.+12.,sec,0.01); - } - - @Test - public void sixHour_sixMinWithLeadingZero_sixSecWithLeadingZero_shouldBeParsedCorrectly(){ - double sec = Time.parseTimeToSeconds("6:06:06"); - assertEquals(6.*3600.+6.*60.+6.,sec,0.01); - } - - @Test(expected=IllegalArgumentException.class) - public void whenTimeStringHasNoDigit_itThrowsException(){ - Time.parseTimeToSeconds("PM"); - } - - @Test(expected=IllegalArgumentException.class) - public void whenTimeStringHasMilliSeconds_itThrowsException(){ - Time.parseTimeToSeconds("01:00:12:01PM"); - } - - @Test - public void zeroHour_zeroMinWithLeadingZero_oneSecWithLeadingZero_shouldBeParsedCorrectly(){ - double sec = Time.parseTimeToSeconds("0:00:01"); - assertEquals(1.,sec,0.01); - } @Test - public void whenSecIs3600_shouldReturnCorrectTimeString(){ + public void sixAM_shouldBeParsedCorrectly() { + double sec = Time.parseTimeToSeconds("6AM"); + assertEquals(6. * 3600., sec, 0.01); + } + + @Test + public void sixAMWithWhiteSpace_shouldBeParsedCorrectly() { + double sec = Time.parseTimeToSeconds("6 AM"); + assertEquals(6. * 3600., sec, 0.01); + } + + @Test + public void sixaMWithWhiteSpace_shouldBeParsedCorrectly() { + double sec = Time.parseTimeToSeconds("6 aM"); + assertEquals(6. * 3600., sec, 0.01); + } + + @Test + public void sixamWithWhiteSpace_shouldBeParsedCorrectly() { + double sec = Time.parseTimeToSeconds("6 am"); + assertEquals(6. * 3600., sec, 0.01); + } + + @Test + public void sixAmWithWhiteSpace_shouldBeParsedCorrectly() { + double sec = Time.parseTimeToSeconds("6 Am"); + assertEquals(6. * 3600., sec, 0.01); + } + + + @Test + public void sixPM_shouldBeParsedCorrectly() { + double sec = Time.parseTimeToSeconds("6PM"); + assertEquals(6. * 3600. + 12. * 3600., sec, 0.01); + } + + @Test + public void sixPMWithWhiteSpace_shouldBeParsedCorrectly() { + double sec = Time.parseTimeToSeconds("6 PM"); + assertEquals(6. * 3600. + 12. * 3600., sec, 0.01); + } + + @Test + public void sixpMWithWhiteSpace_shouldBeParsedCorrectly() { + double sec = Time.parseTimeToSeconds("6 pM"); + assertEquals(6. * 3600. + 12. * 3600., sec, 0.01); + } + + @Test + public void sixpmWithWhiteSpace_shouldBeParsedCorrectly() { + double sec = Time.parseTimeToSeconds("6 pm"); + assertEquals(6. * 3600. + 12. * 3600., sec, 0.01); + } + + @Test + public void sixPmWithWhiteSpace_shouldBeParsedCorrectly() { + double sec = Time.parseTimeToSeconds("6 Pm"); + assertEquals(6. * 3600. + 12. * 3600, sec, 0.01); + } + + @Test + public void sixAMWithLeadingZero_shouldBeParsedCorrectly() { + double sec = Time.parseTimeToSeconds("06AM"); + assertEquals(6. * 3600., sec, 0.01); + } + + @Test + public void sixHour_twelveMin_AM_shouldBeParsedCorrectly() { + double sec = Time.parseTimeToSeconds("6:12AM"); + assertEquals(6. * 3600. + 12. * 60., sec, 0.01); + } + + @Test + public void sixHour_sixMin_AM_shouldBeParsedCorrectly() { + double sec = Time.parseTimeToSeconds("6:6AM"); + assertEquals(6. * 3600. + 6. * 60., sec, 0.01); + } + + @Test + public void sixHour_sixMinWithLeadingZero_AM_shouldBeParsedCorrectly() { + double sec = Time.parseTimeToSeconds("6:06AM"); + assertEquals(6. * 3600. + 6. * 60., sec, 0.01); + } + + + @Test + public void sixHour_twelveMin_PM_shouldBeParsedCorrectly() { + double sec = Time.parseTimeToSeconds("6:12PM"); + assertEquals(6. * 3600. + 12. * 60. + 12. * 3600., sec, 0.01); + } + + @Test + public void sixHour_sixMin_PM_shouldBeParsedCorrectly() { + double sec = Time.parseTimeToSeconds("6:6PM"); + assertEquals(6. * 3600. + 6. * 60. + 12. * 3600., sec, 0.01); + } + + @Test + public void sixHour_sixMinWithLeadingZero_PM_shouldBeParsedCorrectly() { + double sec = Time.parseTimeToSeconds("6:06PM"); + assertEquals(6. * 3600. + 6. * 60. + 12. * 3600., sec, 0.01); + } + + @Test + public void sixHour_sixMinWithLeadingZero_twelveSec_PM_shouldBeParsedCorrectly() { + double sec = Time.parseTimeToSeconds("6:06:12PM"); + assertEquals(6. * 3600. + 6. * 60. + 12. * 3600. + 12., sec, 0.01); + } + + @Test + public void sixHour_sixMinWithLeadingZero_twelveSec_shouldBeParsedCorrectly() { + double sec = Time.parseTimeToSeconds("6:06:12"); + assertEquals(6. * 3600. + 6. * 60. + 12., sec, 0.01); + } + + @Test + public void sixHour_sixMinWithLeadingZero_sixSecWithLeadingZero_shouldBeParsedCorrectly() { + double sec = Time.parseTimeToSeconds("6:06:06"); + assertEquals(6. * 3600. + 6. * 60. + 6., sec, 0.01); + } + + @Test(expected = IllegalArgumentException.class) + public void whenTimeStringHasNoDigit_itThrowsException() { + Time.parseTimeToSeconds("PM"); + } + + @Test(expected = IllegalArgumentException.class) + public void whenTimeStringHasMilliSeconds_itThrowsException() { + Time.parseTimeToSeconds("01:00:12:01PM"); + } + + @Test + public void zeroHour_zeroMinWithLeadingZero_oneSecWithLeadingZero_shouldBeParsedCorrectly() { + double sec = Time.parseTimeToSeconds("0:00:01"); + assertEquals(1., sec, 0.01); + } + + @Test + public void whenSecIs3600_shouldReturnCorrectTimeString() { String time = Time.parseSecondsToTime(3600); System.out.println(time); - assertEquals(3600.,Time.parseTimeToSeconds(time),0.01); + assertEquals(3600., Time.parseTimeToSeconds(time), 0.01); } @Test - public void whenSecIs4000_shouldReturnCorrectTimeString(){ + public void whenSecIs4000_shouldReturnCorrectTimeString() { String time = Time.parseSecondsToTime(4000); System.out.println(time); - assertEquals(4000.,Time.parseTimeToSeconds(time),0.01); + assertEquals(4000., Time.parseTimeToSeconds(time), 0.01); } @Test - public void whenSecIs86399_shouldReturnCorrectTimeString(){ + public void whenSecIs86399_shouldReturnCorrectTimeString() { String time = Time.parseSecondsToTime(86399); System.out.println(time); - assertEquals(86399.,Time.parseTimeToSeconds(time),0.01); + assertEquals(86399., Time.parseTimeToSeconds(time), 0.01); } diff --git a/jsprit-core/src/test/java/jsprit/core/util/VehicleRoutingTransportCostsMatrixTest.java b/jsprit-core/src/test/java/jsprit/core/util/VehicleRoutingTransportCostsMatrixTest.java index 76e4c755..14b134c5 100644 --- a/jsprit-core/src/test/java/jsprit/core/util/VehicleRoutingTransportCostsMatrixTest.java +++ b/jsprit-core/src/test/java/jsprit/core/util/VehicleRoutingTransportCostsMatrixTest.java @@ -27,235 +27,234 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; public class VehicleRoutingTransportCostsMatrixTest { - - @Test - public void whenAddingDistanceToSymmetricMatrix_itShouldReturnCorrectValues(){ - VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(true); - matrixBuilder.addTransportDistance("1", "2", 2.); - VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build(); - assertEquals(2.,matrix.getTransportCost(loc("1"), loc("2"), 0.0, null, null),0.1); - assertEquals(2.,matrix.getDistance("1", "2"),0.1); - assertEquals(2.,matrix.getTransportCost(loc("2"), loc("1"), 0.0, null, null),0.1); - assertEquals(2.,matrix.getDistance("2", "1"),0.1); - } - - @Test - public void whenAddingDistanceToSymmetricMatrixUsingStringAsKey_itShouldReturnCorrectValues(){ - VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(true); - matrixBuilder.addTransportDistance("from", "to", 2.); - VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build(); - assertEquals(2.,matrix.getTransportCost(loc("from"), loc("to"), 0.0, null, null),0.1); - assertEquals(2.,matrix.getDistance("from", "to"),0.1); - assertEquals(2.,matrix.getTransportCost(loc("to"), loc("from"), 0.0, null, null),0.1); - assertEquals(2.,matrix.getDistance("from", "to"),0.1); - } - - @Test - public void whenAddingDistanceToSymmetricMatrixWhereKeyAlreadyExists_itShouldOverrideValues(){ - VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(true); - matrixBuilder.addTransportDistance("from", "to", 2.); - //overide - matrixBuilder.addTransportDistance("from", "to", 4.); - VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build(); - - assertEquals(4.,matrix.getTransportCost(loc("from"), loc("to"), 0.0, null, null),0.1); - assertEquals(4.,matrix.getDistance("from", "to"),0.1); - assertEquals(4.,matrix.getTransportCost(loc("to"), loc("from"), 0.0, null, null),0.1); - assertEquals(4.,matrix.getDistance("from", "to"),0.1); - } - - @Test - public void whenAddingDistanceToSymmetricMatrixWhereReverseKeyAlreadyExists_itShouldOverrideValues(){ - VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(true); - matrixBuilder.addTransportDistance("from", "to", 2.); - //overide - matrixBuilder.addTransportDistance("to", "from", 4.); - VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build(); - - assertEquals(4.,matrix.getTransportCost(loc("from"), loc("to"), 0.0, null, null),0.1); - assertEquals(4.,matrix.getDistance("from", "to"),0.1); - assertEquals(4.,matrix.getTransportCost(loc("to"), loc("from"), 0.0, null, null),0.1); - assertEquals(4.,matrix.getDistance("from", "to"),0.1); - } - - @Test - public void whenAddingDistanceToAsymmetricMatrix_itShouldReturnCorrectValues(){ - VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(false); - matrixBuilder.addTransportDistance("1", "2", 2.); - VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build(); - assertEquals(2.,matrix.getTransportCost(loc("1"), loc("2"), 0.0, null, null),0.1); - } + + @Test + public void whenAddingDistanceToSymmetricMatrix_itShouldReturnCorrectValues() { + VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(true); + matrixBuilder.addTransportDistance("1", "2", 2.); + VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build(); + assertEquals(2., matrix.getTransportCost(loc("1"), loc("2"), 0.0, null, null), 0.1); + assertEquals(2., matrix.getDistance("1", "2"), 0.1); + assertEquals(2., matrix.getTransportCost(loc("2"), loc("1"), 0.0, null, null), 0.1); + assertEquals(2., matrix.getDistance("2", "1"), 0.1); + } + + @Test + public void whenAddingDistanceToSymmetricMatrixUsingStringAsKey_itShouldReturnCorrectValues() { + VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(true); + matrixBuilder.addTransportDistance("from", "to", 2.); + VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build(); + assertEquals(2., matrix.getTransportCost(loc("from"), loc("to"), 0.0, null, null), 0.1); + assertEquals(2., matrix.getDistance("from", "to"), 0.1); + assertEquals(2., matrix.getTransportCost(loc("to"), loc("from"), 0.0, null, null), 0.1); + assertEquals(2., matrix.getDistance("from", "to"), 0.1); + } + + @Test + public void whenAddingDistanceToSymmetricMatrixWhereKeyAlreadyExists_itShouldOverrideValues() { + VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(true); + matrixBuilder.addTransportDistance("from", "to", 2.); + //overide + matrixBuilder.addTransportDistance("from", "to", 4.); + VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build(); + + assertEquals(4., matrix.getTransportCost(loc("from"), loc("to"), 0.0, null, null), 0.1); + assertEquals(4., matrix.getDistance("from", "to"), 0.1); + assertEquals(4., matrix.getTransportCost(loc("to"), loc("from"), 0.0, null, null), 0.1); + assertEquals(4., matrix.getDistance("from", "to"), 0.1); + } + + @Test + public void whenAddingDistanceToSymmetricMatrixWhereReverseKeyAlreadyExists_itShouldOverrideValues() { + VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(true); + matrixBuilder.addTransportDistance("from", "to", 2.); + //overide + matrixBuilder.addTransportDistance("to", "from", 4.); + VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build(); + + assertEquals(4., matrix.getTransportCost(loc("from"), loc("to"), 0.0, null, null), 0.1); + assertEquals(4., matrix.getDistance("from", "to"), 0.1); + assertEquals(4., matrix.getTransportCost(loc("to"), loc("from"), 0.0, null, null), 0.1); + assertEquals(4., matrix.getDistance("from", "to"), 0.1); + } + + @Test + public void whenAddingDistanceToAsymmetricMatrix_itShouldReturnCorrectValues() { + VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(false); + matrixBuilder.addTransportDistance("1", "2", 2.); + VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build(); + assertEquals(2., matrix.getTransportCost(loc("1"), loc("2"), 0.0, null, null), 0.1); + } private Location loc(String s) { return Location.Builder.newInstance().setId(s).build(); } - @Test(expected=IllegalStateException.class) - public void whenRequestingRelationThatDoesNotExist_itShouldThrowException(){ - VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(false); - matrixBuilder.addTransportDistance("1", "2", 2.); - VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build(); - matrix.getTransportCost(loc("2"), loc("1"), 0.0, null, null); - } - - @Test - public void whenAddingDistanceToAsymmetricMatrixUsingStringAsKey_itShouldReturnCorrectValues(){ - VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(false); - matrixBuilder.addTransportDistance("from", "to", 2.); - matrixBuilder.addTransportDistance("to", "from", 4.); - VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build(); - assertEquals(2.,matrix.getTransportCost(loc("from"), loc("to"), 0.0, null, null),0.1); - assertEquals(4.,matrix.getTransportCost(loc("to"), loc("from"), 0.0, null, null),0.1); - } - - @Test - public void whenAddingTimeToSymmetricMatrix_itShouldReturnCorrectValues(){ - VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(true); - matrixBuilder.addTransportTime("1", "2", 2.); - VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build(); - assertEquals(2.,matrix.getTransportTime(loc("1"), loc("2"), 0.0, null, null),0.1); - assertEquals(2.,matrix.getTransportTime(loc("2"), loc("1"), 0.0, null, null),0.1); - } - - @Test - public void whenAddingTimeToSymmetricMatrixUsingStringAsKey_itShouldReturnCorrectValues(){ - VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(true); - matrixBuilder.addTransportTime("from", "to", 2.); - VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build(); - assertEquals(2.,matrix.getTransportTime(loc("from"), loc("to"), 0.0, null, null),0.1); - assertEquals(2.,matrix.getTransportTime(loc("to"), loc("from"), 0.0, null, null),0.1); - } - - @Test - public void whenAddingTimeToAsymmetricMatrix_itShouldReturnCorrectValues(){ - VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(false); - matrixBuilder.addTransportTime("1", "2", 2.); - VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build(); - assertEquals(2.,matrix.getTransportTime(loc("1"), loc("2"), 0.0, null, null),0.1); - } - - @Test(expected=IllegalStateException.class) - public void whenRequestingTimeOfRelationThatDoesNotExist_itShouldThrowException(){ - VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(false); - matrixBuilder.addTransportTime("1", "2", 2.); - VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build(); - matrix.getTransportTime(loc("2"), loc("1"), 0.0, null, null); - } - - @Test - public void whenAddingTimeToAsymmetricMatrixUsingStringAsKey_itShouldReturnCorrectValues(){ - VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(false); - matrixBuilder.addTransportTime("from", "to", 2.); - matrixBuilder.addTransportTime("to", "from", 4.); - VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build(); - assertEquals(2.,matrix.getTransportTime(loc("from"), loc("to"), 0.0, null, null),0.1); - assertEquals(4.,matrix.getTransportTime(loc("to"), loc("from"), 0.0, null, null),0.1); - } - - @Test - public void whenAddingTimeToAsymmetricMatrixUsingStringAsKey_itShouldReturnCorrectCostValues(){ - VehicleType type = VehicleTypeImpl.Builder.newInstance("t").setCostPerDistance(0.).setCostPerTime(1.).build(); - Vehicle vehicle = mock(Vehicle.class); - when(vehicle.getType()).thenReturn(type); - VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(false); - matrixBuilder.addTransportTime("from", "to", 2.); - matrixBuilder.addTransportTime("to", "from", 4.); - VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build(); + @Test(expected = IllegalStateException.class) + public void whenRequestingRelationThatDoesNotExist_itShouldThrowException() { + VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(false); + matrixBuilder.addTransportDistance("1", "2", 2.); + VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build(); + matrix.getTransportCost(loc("2"), loc("1"), 0.0, null, null); + } + + @Test + public void whenAddingDistanceToAsymmetricMatrixUsingStringAsKey_itShouldReturnCorrectValues() { + VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(false); + matrixBuilder.addTransportDistance("from", "to", 2.); + matrixBuilder.addTransportDistance("to", "from", 4.); + VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build(); + assertEquals(2., matrix.getTransportCost(loc("from"), loc("to"), 0.0, null, null), 0.1); + assertEquals(4., matrix.getTransportCost(loc("to"), loc("from"), 0.0, null, null), 0.1); + } + + @Test + public void whenAddingTimeToSymmetricMatrix_itShouldReturnCorrectValues() { + VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(true); + matrixBuilder.addTransportTime("1", "2", 2.); + VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build(); + assertEquals(2., matrix.getTransportTime(loc("1"), loc("2"), 0.0, null, null), 0.1); + assertEquals(2., matrix.getTransportTime(loc("2"), loc("1"), 0.0, null, null), 0.1); + } + + @Test + public void whenAddingTimeToSymmetricMatrixUsingStringAsKey_itShouldReturnCorrectValues() { + VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(true); + matrixBuilder.addTransportTime("from", "to", 2.); + VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build(); + assertEquals(2., matrix.getTransportTime(loc("from"), loc("to"), 0.0, null, null), 0.1); + assertEquals(2., matrix.getTransportTime(loc("to"), loc("from"), 0.0, null, null), 0.1); + } + + @Test + public void whenAddingTimeToAsymmetricMatrix_itShouldReturnCorrectValues() { + VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(false); + matrixBuilder.addTransportTime("1", "2", 2.); + VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build(); + assertEquals(2., matrix.getTransportTime(loc("1"), loc("2"), 0.0, null, null), 0.1); + } + + @Test(expected = IllegalStateException.class) + public void whenRequestingTimeOfRelationThatDoesNotExist_itShouldThrowException() { + VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(false); + matrixBuilder.addTransportTime("1", "2", 2.); + VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build(); + matrix.getTransportTime(loc("2"), loc("1"), 0.0, null, null); + } + + @Test + public void whenAddingTimeToAsymmetricMatrixUsingStringAsKey_itShouldReturnCorrectValues() { + VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(false); + matrixBuilder.addTransportTime("from", "to", 2.); + matrixBuilder.addTransportTime("to", "from", 4.); + VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build(); + assertEquals(2., matrix.getTransportTime(loc("from"), loc("to"), 0.0, null, null), 0.1); + assertEquals(4., matrix.getTransportTime(loc("to"), loc("from"), 0.0, null, null), 0.1); + } + + @Test + public void whenAddingTimeToAsymmetricMatrixUsingStringAsKey_itShouldReturnCorrectCostValues() { + VehicleType type = VehicleTypeImpl.Builder.newInstance("t").setCostPerDistance(0.).setCostPerTime(1.).build(); + Vehicle vehicle = mock(Vehicle.class); + when(vehicle.getType()).thenReturn(type); + VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(false); + matrixBuilder.addTransportTime("from", "to", 2.); + matrixBuilder.addTransportTime("to", "from", 4.); + VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build(); // assertEquals(2.,matrix.getTransportTime("from", "to", 0.0, null, null),0.1); // assertEquals(4.,matrix.getTransportTime("to", "from", 0.0, null, null),0.1); - assertEquals(2.,matrix.getTransportCost(loc("from"), loc("to"), 0.0, null, vehicle),0.1); - assertEquals(4.,matrix.getTransportCost(loc("to"), loc("from"), 0.0, null, vehicle),0.1); - } - - @Test - public void whenAddingTimeAndDistanceToSymmetricMatrix_itShouldReturnCorrectValues(){ - VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(true); - matrixBuilder.addTransportDistance("1", "2", 20.); - matrixBuilder.addTransportTime("1", "2", 2.); - VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build(); - Vehicle vehicle = mock(Vehicle.class); - VehicleType type = VehicleTypeImpl.Builder.newInstance("t").setCostPerDistance(1.).setCostPerTime(2.).build(); - when(vehicle.getType()).thenReturn(type); - assertEquals(24.,matrix.getTransportCost(loc("1"), loc("2"), 0.0, null, vehicle),0.1); - assertEquals(24.,matrix.getTransportCost(loc("2"), loc("1"), 0.0, null, vehicle),0.1); - } - - @Test - public void whenAddingTimeAndDistanceToSymmetricMatrixUsingStringAsKey_itShouldReturnCorrectValues(){ - VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(true); - matrixBuilder.addTransportTime("from", "to", 2.); - Vehicle vehicle = mock(Vehicle.class); - VehicleType type = VehicleTypeImpl.Builder.newInstance("t").setCostPerDistance(1.).setCostPerTime(2.).build(); - when(vehicle.getType()).thenReturn(type); - VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build(); - assertEquals(4.,matrix.getTransportCost(loc("from"), loc("to"), 0.0, null, vehicle),0.1); - assertEquals(4.,matrix.getTransportCost(loc("to"), loc("from"), 0.0, null, vehicle),0.1); - } - - @Test - public void whenAddingTimeAndDistanceToAsymmetricMatrix_itShouldReturnCorrectValues(){ - VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(false); - matrixBuilder.addTransportTime("1", "2", 2.); - matrixBuilder.addTransportTime("2", "1", 8.); - VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build(); - Vehicle vehicle = mock(Vehicle.class); - VehicleType type = VehicleTypeImpl.Builder.newInstance("t").setCostPerDistance(1.).setCostPerTime(2.).build(); - when(vehicle.getType()).thenReturn(type); - assertEquals(4.,matrix.getTransportCost(loc("1"), loc("2"), 0.0, null, vehicle),0.1); - assertEquals(16.,matrix.getTransportCost(loc("2"), loc("1"), 0.0, null, vehicle),0.1); - } - - @Test - public void whenAddingTimeAndDistanceToAsymmetricMatrixUsingStringAsKey_itShouldReturnCorrectValues(){ - VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(false); - matrixBuilder.addTransportTime("from", "to", 2.); - matrixBuilder.addTransportDistance("from", "to", 1.); - matrixBuilder.addTransportTime("to", "from", 4.); - matrixBuilder.addTransportDistance("to", "from", 3.); - VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build(); - Vehicle vehicle = mock(Vehicle.class); - VehicleType type = VehicleTypeImpl.Builder.newInstance("t").setCostPerDistance(1.).setCostPerTime(2.).build(); - when(vehicle.getType()).thenReturn(type); - assertEquals(5.,matrix.getTransportCost(loc("from"), loc("to"), 0.0, null, vehicle),0.1); - assertEquals(11.,matrix.getTransportCost(loc("to"), loc("from"), 0.0, null, vehicle),0.1); - } - - - - @Test - public void whenAddingTimeAndDistanceToAsymmetricMatrixUsingStringAsKey_itShouldReturnCorrectCostValues(){ - VehicleType type = VehicleTypeImpl.Builder.newInstance("t").setCostPerDistance(2.).setCostPerTime(1.).build(); - Vehicle vehicle = mock(Vehicle.class); - when(vehicle.getType()).thenReturn(type); - VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(false); - matrixBuilder.addTransportTime("from", "to", 2.); - matrixBuilder.addTransportDistance("from", "to", 3.); - matrixBuilder.addTransportTime("to", "from", 4.); - matrixBuilder.addTransportDistance("to", "from", 5.); - VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build(); - - assertEquals(8.,matrix.getTransportCost(loc("from"), loc("to"), 0.0, null, vehicle),0.1); - assertEquals(14.,matrix.getTransportCost(loc("to"), loc("from"), 0.0, null, vehicle),0.1); - } - - @Test - public void whenAddingTimeAndDistanceToSymmetricMatrixUsingStringAsKey_and_overridesEntry_itShouldReturnCorrectValues(){ - VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(true); - - matrixBuilder.addTransportDistance("from", "to", 1.); - matrixBuilder.addTransportTime("from", "to", 2.); - - matrixBuilder.addTransportDistance("to", "from", 1.); - matrixBuilder.addTransportTime("to", "from", 2.); - - VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build(); - Vehicle vehicle = mock(Vehicle.class); - VehicleType type = VehicleTypeImpl.Builder.newInstance("t").setCostPerDistance(1.).setCostPerTime(0.).build(); - when(vehicle.getType()).thenReturn(type); - assertEquals(1.,matrix.getDistance("from", "to"),0.1); - assertEquals(1.,matrix.getDistance("to", "from"),0.1); - assertEquals(1.,matrix.getTransportCost(loc("from"), loc("to"), 0.0, null, vehicle),0.1); - assertEquals(1.,matrix.getTransportCost(loc("to"), loc("from"), 0.0, null, vehicle),0.1); - } + assertEquals(2., matrix.getTransportCost(loc("from"), loc("to"), 0.0, null, vehicle), 0.1); + assertEquals(4., matrix.getTransportCost(loc("to"), loc("from"), 0.0, null, vehicle), 0.1); + } + + @Test + public void whenAddingTimeAndDistanceToSymmetricMatrix_itShouldReturnCorrectValues() { + VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(true); + matrixBuilder.addTransportDistance("1", "2", 20.); + matrixBuilder.addTransportTime("1", "2", 2.); + VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build(); + Vehicle vehicle = mock(Vehicle.class); + VehicleType type = VehicleTypeImpl.Builder.newInstance("t").setCostPerDistance(1.).setCostPerTime(2.).build(); + when(vehicle.getType()).thenReturn(type); + assertEquals(24., matrix.getTransportCost(loc("1"), loc("2"), 0.0, null, vehicle), 0.1); + assertEquals(24., matrix.getTransportCost(loc("2"), loc("1"), 0.0, null, vehicle), 0.1); + } + + @Test + public void whenAddingTimeAndDistanceToSymmetricMatrixUsingStringAsKey_itShouldReturnCorrectValues() { + VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(true); + matrixBuilder.addTransportTime("from", "to", 2.); + Vehicle vehicle = mock(Vehicle.class); + VehicleType type = VehicleTypeImpl.Builder.newInstance("t").setCostPerDistance(1.).setCostPerTime(2.).build(); + when(vehicle.getType()).thenReturn(type); + VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build(); + assertEquals(4., matrix.getTransportCost(loc("from"), loc("to"), 0.0, null, vehicle), 0.1); + assertEquals(4., matrix.getTransportCost(loc("to"), loc("from"), 0.0, null, vehicle), 0.1); + } + + @Test + public void whenAddingTimeAndDistanceToAsymmetricMatrix_itShouldReturnCorrectValues() { + VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(false); + matrixBuilder.addTransportTime("1", "2", 2.); + matrixBuilder.addTransportTime("2", "1", 8.); + VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build(); + Vehicle vehicle = mock(Vehicle.class); + VehicleType type = VehicleTypeImpl.Builder.newInstance("t").setCostPerDistance(1.).setCostPerTime(2.).build(); + when(vehicle.getType()).thenReturn(type); + assertEquals(4., matrix.getTransportCost(loc("1"), loc("2"), 0.0, null, vehicle), 0.1); + assertEquals(16., matrix.getTransportCost(loc("2"), loc("1"), 0.0, null, vehicle), 0.1); + } + + @Test + public void whenAddingTimeAndDistanceToAsymmetricMatrixUsingStringAsKey_itShouldReturnCorrectValues() { + VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(false); + matrixBuilder.addTransportTime("from", "to", 2.); + matrixBuilder.addTransportDistance("from", "to", 1.); + matrixBuilder.addTransportTime("to", "from", 4.); + matrixBuilder.addTransportDistance("to", "from", 3.); + VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build(); + Vehicle vehicle = mock(Vehicle.class); + VehicleType type = VehicleTypeImpl.Builder.newInstance("t").setCostPerDistance(1.).setCostPerTime(2.).build(); + when(vehicle.getType()).thenReturn(type); + assertEquals(5., matrix.getTransportCost(loc("from"), loc("to"), 0.0, null, vehicle), 0.1); + assertEquals(11., matrix.getTransportCost(loc("to"), loc("from"), 0.0, null, vehicle), 0.1); + } + + + @Test + public void whenAddingTimeAndDistanceToAsymmetricMatrixUsingStringAsKey_itShouldReturnCorrectCostValues() { + VehicleType type = VehicleTypeImpl.Builder.newInstance("t").setCostPerDistance(2.).setCostPerTime(1.).build(); + Vehicle vehicle = mock(Vehicle.class); + when(vehicle.getType()).thenReturn(type); + VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(false); + matrixBuilder.addTransportTime("from", "to", 2.); + matrixBuilder.addTransportDistance("from", "to", 3.); + matrixBuilder.addTransportTime("to", "from", 4.); + matrixBuilder.addTransportDistance("to", "from", 5.); + VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build(); + + assertEquals(8., matrix.getTransportCost(loc("from"), loc("to"), 0.0, null, vehicle), 0.1); + assertEquals(14., matrix.getTransportCost(loc("to"), loc("from"), 0.0, null, vehicle), 0.1); + } + + @Test + public void whenAddingTimeAndDistanceToSymmetricMatrixUsingStringAsKey_and_overridesEntry_itShouldReturnCorrectValues() { + VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(true); + + matrixBuilder.addTransportDistance("from", "to", 1.); + matrixBuilder.addTransportTime("from", "to", 2.); + + matrixBuilder.addTransportDistance("to", "from", 1.); + matrixBuilder.addTransportTime("to", "from", 2.); + + VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build(); + Vehicle vehicle = mock(Vehicle.class); + VehicleType type = VehicleTypeImpl.Builder.newInstance("t").setCostPerDistance(1.).setCostPerTime(0.).build(); + when(vehicle.getType()).thenReturn(type); + assertEquals(1., matrix.getDistance("from", "to"), 0.1); + assertEquals(1., matrix.getDistance("to", "from"), 0.1); + assertEquals(1., matrix.getTransportCost(loc("from"), loc("to"), 0.0, null, vehicle), 0.1); + assertEquals(1., matrix.getTransportCost(loc("to"), loc("from"), 0.0, null, vehicle), 0.1); + } } diff --git a/jsprit-core/src/test/resources/C101_solomon_pd.xml b/jsprit-core/src/test/resources/C101_solomon_pd.xml index 55d0e3c7..72f3baa0 100644 --- a/jsprit-core/src/test/resources/C101_solomon_pd.xml +++ b/jsprit-core/src/test/resources/C101_solomon_pd.xml @@ -1,2535 +1,2536 @@ - - INFINITE - HOMOGENEOUS - - - - solomonVehicle - solomonType - - 0 - - - - 0.0 - 1236.0 - - - - - - solomonType - 200 - - 0.0 - 1.0 - - - - - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=5.0][y=35.0] - - 90.0 - - - 283.0 - 344.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=5.0][y=45.0] - - 90.0 - - - 665.0 - 716.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=8.0][y=40.0] - - 90.0 - - - 87.0 - 158.0 - - - - 40 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=8.0][y=45.0] - - 90.0 - - - 751.0 - 816.0 - - - - 20 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=0.0][y=45.0] - - 90.0 - - - 567.0 - 624.0 - - - - 20 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=2.0][y=40.0] - - 90.0 - - - 383.0 - 434.0 - - - - 20 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=0.0][y=40.0] - - 90.0 - - - 479.0 - 522.0 - - - - 30 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=33.0][y=35.0] - - 90.0 - - - 16.0 - 80.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=33.0][y=32.0] - - 90.0 - - - 68.0 - 149.0 - - - - 20 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=35.0][y=32.0] - - 90.0 - - - 166.0 - 235.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=35.0][y=30.0] - - 90.0 - - - 264.0 - 321.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=28.0][y=52.0] - - 90.0 - - - 812.0 - 883.0 - - - - 20 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=28.0][y=55.0] - - 90.0 - - - 732.0 - 777.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=25.0][y=50.0] - - 90.0 - - - 65.0 - 144.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=25.0][y=52.0] - - 90.0 - - - 169.0 - 224.0 - - - - 40 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=25.0][y=55.0] - - 90.0 - - - 622.0 - 701.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=23.0][y=52.0] - - 90.0 - - - 261.0 - 316.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=23.0][y=55.0] - - 90.0 - - - 546.0 - 593.0 - - - - 20 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=20.0][y=50.0] - - 90.0 - - - 358.0 - 405.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=42.0][y=66.0] - - 90.0 - - - 65.0 - 146.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=45.0][y=70.0] - - 90.0 - - - 825.0 - 870.0 - - - - 30 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=45.0][y=68.0] - - 90.0 - - - 912.0 - 967.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=20.0][y=55.0] - - 90.0 - - - 449.0 - 504.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=40.0][y=66.0] - - 90.0 - - - 170.0 - 225.0 - - - - 20 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=40.0][y=69.0] - - 90.0 - - - 621.0 - 702.0 - - - - 20 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=42.0][y=65.0] - - 90.0 - - - 15.0 - 67.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=10.0][y=40.0] - - 90.0 - - - 31.0 - 100.0 - - - - 30 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=42.0][y=68.0] - - 90.0 - - - 727.0 - 782.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=10.0][y=35.0] - - 90.0 - - - 200.0 - 237.0 - - - - 20 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=38.0][y=70.0] - - 90.0 - - - 534.0 - 605.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=38.0][y=68.0] - - 90.0 - - - 255.0 - 324.0 - - - - 20 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=15.0][y=80.0] - - 90.0 - - - 278.0 - 345.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=18.0][y=75.0] - - 90.0 - - - 99.0 - 148.0 - - - - 20 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=15.0][y=75.0] - - 90.0 - - - 179.0 - 254.0 - - - - 20 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=20.0][y=80.0] - - 90.0 - - - 384.0 - 429.0 - - - - 40 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=20.0][y=85.0] - - 90.0 - - - 475.0 - 528.0 - - - - 40 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=22.0][y=75.0] - - 90.0 - - - 30.0 - 92.0 - - - - 30 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=22.0][y=85.0] - - 90.0 - - - 567.0 - 620.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=35.0][y=69.0] - - 90.0 - - - 448.0 - 505.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=25.0][y=85.0] - - 90.0 - - - 652.0 - 721.0 - - - - 20 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=30.0][y=52.0] - - 90.0 - - - 914.0 - 965.0 - - - - 20 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=30.0][y=50.0] - - 90.0 - - - 10.0 - 73.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=55.0][y=80.0] - - 90.0 - - - 743.0 - 820.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=55.0][y=85.0] - - 90.0 - - - 647.0 - 726.0 - - - - 20 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=58.0][y=75.0] - - 90.0 - - - 30.0 - 84.0 - - - - 20 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=60.0][y=85.0] - - 90.0 - - - 561.0 - 622.0 - - - - 30 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=60.0][y=80.0] - - 90.0 - - - 95.0 - 156.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=62.0][y=80.0] - - 90.0 - - - 196.0 - 239.0 - - - - 30 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=65.0][y=82.0] - - 90.0 - - - 285.0 - 336.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=65.0][y=85.0] - - 90.0 - - - 475.0 - 518.0 - - - - 40 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=67.0][y=85.0] - - 90.0 - - - 368.0 - 441.0 - - - - 20 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=60.0][y=60.0] - - 90.0 - - - 836.0 - 889.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=60.0][y=55.0] - - 90.0 - - - 20.0 - 84.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=35.0][y=66.0] - - 90.0 - - - 357.0 - 410.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=65.0][y=60.0] - - 90.0 - - - 645.0 - 708.0 - - - - 30 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=63.0][y=58.0] - - 90.0 - - - 737.0 - 802.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=87.0][y=30.0] - - 90.0 - - - 668.0 - 731.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=88.0][y=35.0] - - 90.0 - - - 109.0 - 170.0 - - - - 20 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=88.0][y=30.0] - - 90.0 - - - 574.0 - 643.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=75.0][y=55.0] - - 90.0 - - - 369.0 - 420.0 - - - - 20 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=72.0][y=55.0] - - 90.0 - - - 265.0 - 338.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=85.0][y=25.0] - - 90.0 - - - 769.0 - 820.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=85.0][y=35.0] - - 90.0 - - - 47.0 - 124.0 - - - - 30 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=66.0][y=55.0] - - 90.0 - - - 173.0 - 238.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=65.0][y=55.0] - - 90.0 - - - 85.0 - 144.0 - - - - 20 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=70.0][y=58.0] - - 90.0 - - - 458.0 - 523.0 - - - - 20 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=68.0][y=60.0] - - 90.0 - - - 555.0 - 612.0 - - - - 30 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=47.0][y=40.0] - - 90.0 - - - 12.0 - 77.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=47.0][y=35.0] - - 90.0 - - - 826.0 - 875.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=45.0][y=35.0] - - 90.0 - - - 916.0 - 969.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=45.0][y=30.0] - - 90.0 - - - 734.0 - 777.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=95.0][y=30.0] - - 90.0 - - - 387.0 - 456.0 - - - - 30 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=95.0][y=35.0] - - 90.0 - - - 293.0 - 360.0 - - - - 20 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=53.0][y=30.0] - - 90.0 - - - 450.0 - 505.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=92.0][y=30.0] - - 90.0 - - - 478.0 - 551.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=53.0][y=35.0] - - 90.0 - - - 353.0 - 412.0 - - - - 50 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=45.0][y=65.0] - - 90.0 - - - 997.0 - 1068.0 - - - - 20 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=90.0][y=35.0] - - 90.0 - - - 203.0 - 260.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=38.0][y=15.0] - - 90.0 - - - 651.0 - 740.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=38.0][y=5.0] - - 90.0 - - - 471.0 - 534.0 - - - - 30 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=40.0][y=15.0] - - 90.0 - - - 35.0 - 87.0 - - - - 40 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=40.0][y=5.0] - - 90.0 - - - 385.0 - 436.0 - - - - 30 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=42.0][y=15.0] - - 90.0 - - - 95.0 - 158.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=48.0][y=30.0] - - 90.0 - - - 632.0 - 693.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=48.0][y=40.0] - - 90.0 - - - 76.0 - 129.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=50.0][y=35.0] - - 90.0 - - - 262.0 - 317.0 - - - - 20 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=50.0][y=40.0] - - 90.0 - - - 171.0 - 218.0 - - - - 50 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=35.0][y=5.0] - - 90.0 - - - 562.0 - 629.0 - - - - 20 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=50.0][y=30.0] - - 90.0 - - - 531.0 - 610.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=28.0][y=35.0] - - 90.0 - - - 1001.0 - 1066.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=28.0][y=30.0] - - 90.0 - - - 632.0 - 693.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=30.0][y=30.0] - - 90.0 - - - 541.0 - 600.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=32.0][y=30.0] - - 90.0 - - - 359.0 - 412.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=30.0][y=35.0] - - 90.0 - - - 1054.0 - 1127.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=30.0][y=32.0] - - 90.0 - - - 448.0 - 509.0 - - - - 30 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=25.0][y=30.0] - - 90.0 - - - 725.0 - 786.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=25.0][y=35.0] - - 90.0 - - - 912.0 - 969.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=44.0][y=5.0] - - 90.0 - - - 286.0 - 347.0 - - - - 20 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=42.0][y=10.0] - - 90.0 - - - 186.0 - 257.0 - - - - 40 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=26.0][y=32.0] - - 90.0 - - - 815.0 - 880.0 - - - - 10 - - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.w3schools.com vrp_xml_schema.xsd"> + + INFINITE + HOMOGENEOUS + + + + solomonVehicle + solomonType + + 0 + + + + 0.0 + 1236.0 + + + + + + solomonType + 200 + + 0.0 + 1.0 + + + + + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=5.0][y=35.0] + + 90.0 + + + 283.0 + 344.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=5.0][y=45.0] + + 90.0 + + + 665.0 + 716.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=8.0][y=40.0] + + 90.0 + + + 87.0 + 158.0 + + + + 40 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=8.0][y=45.0] + + 90.0 + + + 751.0 + 816.0 + + + + 20 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=0.0][y=45.0] + + 90.0 + + + 567.0 + 624.0 + + + + 20 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=2.0][y=40.0] + + 90.0 + + + 383.0 + 434.0 + + + + 20 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=0.0][y=40.0] + + 90.0 + + + 479.0 + 522.0 + + + + 30 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=33.0][y=35.0] + + 90.0 + + + 16.0 + 80.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=33.0][y=32.0] + + 90.0 + + + 68.0 + 149.0 + + + + 20 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=35.0][y=32.0] + + 90.0 + + + 166.0 + 235.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=35.0][y=30.0] + + 90.0 + + + 264.0 + 321.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=28.0][y=52.0] + + 90.0 + + + 812.0 + 883.0 + + + + 20 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=28.0][y=55.0] + + 90.0 + + + 732.0 + 777.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=25.0][y=50.0] + + 90.0 + + + 65.0 + 144.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=25.0][y=52.0] + + 90.0 + + + 169.0 + 224.0 + + + + 40 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=25.0][y=55.0] + + 90.0 + + + 622.0 + 701.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=23.0][y=52.0] + + 90.0 + + + 261.0 + 316.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=23.0][y=55.0] + + 90.0 + + + 546.0 + 593.0 + + + + 20 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=20.0][y=50.0] + + 90.0 + + + 358.0 + 405.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=42.0][y=66.0] + + 90.0 + + + 65.0 + 146.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=45.0][y=70.0] + + 90.0 + + + 825.0 + 870.0 + + + + 30 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=45.0][y=68.0] + + 90.0 + + + 912.0 + 967.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=20.0][y=55.0] + + 90.0 + + + 449.0 + 504.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=40.0][y=66.0] + + 90.0 + + + 170.0 + 225.0 + + + + 20 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=40.0][y=69.0] + + 90.0 + + + 621.0 + 702.0 + + + + 20 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=42.0][y=65.0] + + 90.0 + + + 15.0 + 67.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=10.0][y=40.0] + + 90.0 + + + 31.0 + 100.0 + + + + 30 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=42.0][y=68.0] + + 90.0 + + + 727.0 + 782.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=10.0][y=35.0] + + 90.0 + + + 200.0 + 237.0 + + + + 20 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=38.0][y=70.0] + + 90.0 + + + 534.0 + 605.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=38.0][y=68.0] + + 90.0 + + + 255.0 + 324.0 + + + + 20 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=15.0][y=80.0] + + 90.0 + + + 278.0 + 345.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=18.0][y=75.0] + + 90.0 + + + 99.0 + 148.0 + + + + 20 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=15.0][y=75.0] + + 90.0 + + + 179.0 + 254.0 + + + + 20 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=20.0][y=80.0] + + 90.0 + + + 384.0 + 429.0 + + + + 40 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=20.0][y=85.0] + + 90.0 + + + 475.0 + 528.0 + + + + 40 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=22.0][y=75.0] + + 90.0 + + + 30.0 + 92.0 + + + + 30 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=22.0][y=85.0] + + 90.0 + + + 567.0 + 620.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=35.0][y=69.0] + + 90.0 + + + 448.0 + 505.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=25.0][y=85.0] + + 90.0 + + + 652.0 + 721.0 + + + + 20 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=30.0][y=52.0] + + 90.0 + + + 914.0 + 965.0 + + + + 20 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=30.0][y=50.0] + + 90.0 + + + 10.0 + 73.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=55.0][y=80.0] + + 90.0 + + + 743.0 + 820.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=55.0][y=85.0] + + 90.0 + + + 647.0 + 726.0 + + + + 20 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=58.0][y=75.0] + + 90.0 + + + 30.0 + 84.0 + + + + 20 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=60.0][y=85.0] + + 90.0 + + + 561.0 + 622.0 + + + + 30 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=60.0][y=80.0] + + 90.0 + + + 95.0 + 156.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=62.0][y=80.0] + + 90.0 + + + 196.0 + 239.0 + + + + 30 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=65.0][y=82.0] + + 90.0 + + + 285.0 + 336.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=65.0][y=85.0] + + 90.0 + + + 475.0 + 518.0 + + + + 40 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=67.0][y=85.0] + + 90.0 + + + 368.0 + 441.0 + + + + 20 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=60.0][y=60.0] + + 90.0 + + + 836.0 + 889.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=60.0][y=55.0] + + 90.0 + + + 20.0 + 84.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=35.0][y=66.0] + + 90.0 + + + 357.0 + 410.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=65.0][y=60.0] + + 90.0 + + + 645.0 + 708.0 + + + + 30 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=63.0][y=58.0] + + 90.0 + + + 737.0 + 802.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=87.0][y=30.0] + + 90.0 + + + 668.0 + 731.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=88.0][y=35.0] + + 90.0 + + + 109.0 + 170.0 + + + + 20 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=88.0][y=30.0] + + 90.0 + + + 574.0 + 643.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=75.0][y=55.0] + + 90.0 + + + 369.0 + 420.0 + + + + 20 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=72.0][y=55.0] + + 90.0 + + + 265.0 + 338.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=85.0][y=25.0] + + 90.0 + + + 769.0 + 820.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=85.0][y=35.0] + + 90.0 + + + 47.0 + 124.0 + + + + 30 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=66.0][y=55.0] + + 90.0 + + + 173.0 + 238.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=65.0][y=55.0] + + 90.0 + + + 85.0 + 144.0 + + + + 20 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=70.0][y=58.0] + + 90.0 + + + 458.0 + 523.0 + + + + 20 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=68.0][y=60.0] + + 90.0 + + + 555.0 + 612.0 + + + + 30 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=47.0][y=40.0] + + 90.0 + + + 12.0 + 77.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=47.0][y=35.0] + + 90.0 + + + 826.0 + 875.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=45.0][y=35.0] + + 90.0 + + + 916.0 + 969.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=45.0][y=30.0] + + 90.0 + + + 734.0 + 777.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=95.0][y=30.0] + + 90.0 + + + 387.0 + 456.0 + + + + 30 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=95.0][y=35.0] + + 90.0 + + + 293.0 + 360.0 + + + + 20 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=53.0][y=30.0] + + 90.0 + + + 450.0 + 505.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=92.0][y=30.0] + + 90.0 + + + 478.0 + 551.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=53.0][y=35.0] + + 90.0 + + + 353.0 + 412.0 + + + + 50 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=45.0][y=65.0] + + 90.0 + + + 997.0 + 1068.0 + + + + 20 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=90.0][y=35.0] + + 90.0 + + + 203.0 + 260.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=38.0][y=15.0] + + 90.0 + + + 651.0 + 740.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=38.0][y=5.0] + + 90.0 + + + 471.0 + 534.0 + + + + 30 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=40.0][y=15.0] + + 90.0 + + + 35.0 + 87.0 + + + + 40 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=40.0][y=5.0] + + 90.0 + + + 385.0 + 436.0 + + + + 30 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=42.0][y=15.0] + + 90.0 + + + 95.0 + 158.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=48.0][y=30.0] + + 90.0 + + + 632.0 + 693.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=48.0][y=40.0] + + 90.0 + + + 76.0 + 129.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=50.0][y=35.0] + + 90.0 + + + 262.0 + 317.0 + + + + 20 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=50.0][y=40.0] + + 90.0 + + + 171.0 + 218.0 + + + + 50 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=35.0][y=5.0] + + 90.0 + + + 562.0 + 629.0 + + + + 20 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=50.0][y=30.0] + + 90.0 + + + 531.0 + 610.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=28.0][y=35.0] + + 90.0 + + + 1001.0 + 1066.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=28.0][y=30.0] + + 90.0 + + + 632.0 + 693.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=30.0][y=30.0] + + 90.0 + + + 541.0 + 600.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=32.0][y=30.0] + + 90.0 + + + 359.0 + 412.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=30.0][y=35.0] + + 90.0 + + + 1054.0 + 1127.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=30.0][y=32.0] + + 90.0 + + + 448.0 + 509.0 + + + + 30 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=25.0][y=30.0] + + 90.0 + + + 725.0 + 786.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=25.0][y=35.0] + + 90.0 + + + 912.0 + 969.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=44.0][y=5.0] + + 90.0 + + + 286.0 + 347.0 + + + + 20 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=42.0][y=10.0] + + 90.0 + + + 186.0 + 257.0 + + + + 40 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=26.0][y=32.0] + + 90.0 + + + 815.0 + 880.0 + + + + 10 + + diff --git a/jsprit-core/src/test/resources/algorithmConfig.xml b/jsprit-core/src/test/resources/algorithmConfig.xml index c0c03957..913984db 100755 --- a/jsprit-core/src/test/resources/algorithmConfig.xml +++ b/jsprit-core/src/test/resources/algorithmConfig.xml @@ -1,47 +1,48 @@ - - 2000 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.w3schools.com algorithm_schema.xsd"> + + 2000 + + + + + + + 1 + + + + + + + + 0.5 + + + + + + 0.5 + + + + + + + + + 0.3 + + + + + + 0.5 + + + - - - - - - 1 - - - - - - - - 0.5 - - - - - - 0.5 - - - - - - - - - 0.3 - - - - - - 0.5 - - - - diff --git a/jsprit-core/src/test/resources/algorithmConfigForReaderTest.xml b/jsprit-core/src/test/resources/algorithmConfigForReaderTest.xml index e30dc37c..ac2789b6 100755 --- a/jsprit-core/src/test/resources/algorithmConfigForReaderTest.xml +++ b/jsprit-core/src/test/resources/algorithmConfigForReaderTest.xml @@ -17,9 +17,10 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~--> - - 2000 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.w3schools.com algorithm_schema.xsd"> + + 2000 @@ -30,44 +31,44 @@ - - - - - - 1 - - - - - - - - 0.5 - - - - - - 0.5 - - - - - - - - - 0.3 - - - - - - 0.5 - - - - + + + + + + 1 + + + + + + + + 0.5 + + + + + + 0.5 + + + + + + + + + 0.3 + + + + + + 0.5 + + + + diff --git a/jsprit-core/src/test/resources/algorithmConfigForReaderTest2.xml b/jsprit-core/src/test/resources/algorithmConfigForReaderTest2.xml index 6decd70f..edd0065c 100755 --- a/jsprit-core/src/test/resources/algorithmConfigForReaderTest2.xml +++ b/jsprit-core/src/test/resources/algorithmConfigForReaderTest2.xml @@ -17,53 +17,54 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~--> - - 2000 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.w3schools.com algorithm_schema.xsd"> + + 2000 100 - - - - - - 1 - - - - - - - - 0.5 - - - - - - 0.5 - - - - - - - - - 0.3 - - - - - - 0.5 - - - - + + + + + + 1 + + + + + + + + 0.5 + + + + + + 0.5 + + + + + + + + + 0.3 + + + + + + 0.5 + + + + diff --git a/jsprit-core/src/test/resources/algorithmConfigWithDepartureTimeChoice.xml b/jsprit-core/src/test/resources/algorithmConfigWithDepartureTimeChoice.xml index 349126ed..52321845 100755 --- a/jsprit-core/src/test/resources/algorithmConfigWithDepartureTimeChoice.xml +++ b/jsprit-core/src/test/resources/algorithmConfigWithDepartureTimeChoice.xml @@ -1,65 +1,66 @@ - - 2000 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.w3schools.com algorithm_schema.xsd"> + + 2000 + + + + + + + 1 + + + + + + + + 0.5 + + + + + + 0.4 + + + + + + + + + 0.3 + + + + + + 0.4 + + + + + + + + + 0.1 + + + + + + + + 0.2 + + + - - - - - - 1 - - - - - - - - 0.5 - - - - - - 0.4 - - - - - - - - - 0.3 - - - - - - 0.4 - - - - - - - - - 0.1 - - - - - - - - 0.2 - - - - diff --git a/jsprit-core/src/test/resources/algorithmConfig_greedyWithRegret.xml b/jsprit-core/src/test/resources/algorithmConfig_greedyWithRegret.xml index 05b7ac50..01433171 100755 --- a/jsprit-core/src/test/resources/algorithmConfig_greedyWithRegret.xml +++ b/jsprit-core/src/test/resources/algorithmConfig_greedyWithRegret.xml @@ -18,49 +18,50 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~--> + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.w3schools.com algorithm_schema.xsd"> - 2000 - - - - - - - - - 1 - + 2000 + + + + + + + + + 1 + + + + + + + + + 0.5 + + + + + 0.5 + + + + + + + + + 0.3 + + + + + 0.5 + + + - - - - - - - 0.5 - - - - - 0.5 - - - - - - - - - 0.3 - - - - - 0.5 - - - - diff --git a/jsprit-core/src/test/resources/algorithmConfig_greedyWithRegret_v2.xml b/jsprit-core/src/test/resources/algorithmConfig_greedyWithRegret_v2.xml index 7caab620..43566fac 100755 --- a/jsprit-core/src/test/resources/algorithmConfig_greedyWithRegret_v2.xml +++ b/jsprit-core/src/test/resources/algorithmConfig_greedyWithRegret_v2.xml @@ -18,49 +18,50 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~--> + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.w3schools.com algorithm_schema.xsd"> - 2000 - - - - - - - - - 1 - + 2000 + + + + + + + + + 1 + + + + + + + + + 0.5 + + + + + 0.5 + + + + + + + + + 0.3 + + + + + 0.5 + + + - - - - - - - 0.5 - - - - - 0.5 - - - - - - - - - 0.3 - - - - - 0.5 - - - - diff --git a/jsprit-core/src/test/resources/algorithmConfig_selectRandomly.xml b/jsprit-core/src/test/resources/algorithmConfig_selectRandomly.xml index cc1ce87b..a0747716 100755 --- a/jsprit-core/src/test/resources/algorithmConfig_selectRandomly.xml +++ b/jsprit-core/src/test/resources/algorithmConfig_selectRandomly.xml @@ -1,34 +1,34 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.w3schools.com algorithm_schema.xsd"> - 2000 + 2000 - - - + + + - + - 1 + 1 - - - - - - - - 0.5 - - - - - 1 - - - - + + + + + + + + 0.5 + + + + + 1 + + + + diff --git a/jsprit-core/src/test/resources/algorithmConfig_withoutIterations.xml b/jsprit-core/src/test/resources/algorithmConfig_withoutIterations.xml index eb4b8ba1..eccee9f6 100755 --- a/jsprit-core/src/test/resources/algorithmConfig_withoutIterations.xml +++ b/jsprit-core/src/test/resources/algorithmConfig_withoutIterations.xml @@ -1,47 +1,48 @@ - - - - - - - 1 - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.w3schools.com algorithm_schema.xsd"> + + + + + + + 1 + + + + + + + + + 0.5 + + + + + + 0.5 + + + + + + + + + 0.3 + + + + + + 0.5 + + + + - - - - - - - 0.5 - - - - - - 0.5 - - - - - - - - - 0.3 - - - - - - 0.5 - - - - - diff --git a/jsprit-core/src/test/resources/algorithm_without_construction.xml b/jsprit-core/src/test/resources/algorithm_without_construction.xml index 66d4ccc7..6f431864 100755 --- a/jsprit-core/src/test/resources/algorithm_without_construction.xml +++ b/jsprit-core/src/test/resources/algorithm_without_construction.xml @@ -1,43 +1,44 @@ - - 2000 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.w3schools.com algorithm_schema.xsd"> + + 2000 + + + 1 + + + + + + + + 0.5 + + + + + + 0.5 + + + + + + + + + 0.3 + + + + + + 0.5 + + + - - 1 - - - - - - - - 0.5 - - - - - - 0.5 - - - - - - - - - 0.3 - - - - - - 0.5 - - - - diff --git a/jsprit-core/src/test/resources/biggerProblem.xml b/jsprit-core/src/test/resources/biggerProblem.xml index c784a699..bd98dec1 100644 --- a/jsprit-core/src/test/resources/biggerProblem.xml +++ b/jsprit-core/src/test/resources/biggerProblem.xml @@ -1,643 +1,644 @@ - - FINITE - HOMOGENEOUS - - - - 18 - 3.5T - - [x=0.0][y=0.0] - - - - [x=0.0][y=0.0] - - - - 14400.0 - 46800.0 - - true - - - 19 - 3.5T - - [x=0.0][y=0.0] - - - - [x=0.0][y=0.0] - - - - 39600.0 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.w3schools.com vrp_xml_schema.xsd"> + + FINITE + HOMOGENEOUS + + + + 18 + 3.5T + + [x=0.0][y=0.0] + + + + [x=0.0][y=0.0] + + + + 14400.0 + 46800.0 + + true + + + 19 + 3.5T + + [x=0.0][y=0.0] + + + + [x=0.0][y=0.0] + + + + 39600.0 + 64800.0 + + true + + + 20 + 3.5T + + [x=0.0][y=0.0] + + + + [x=0.0][y=0.0] + + + + 14400.0 + 46800.0 + + true + + + 7 + 1.5T + + [x=0.0][y=0.0] + + + + [x=0.0][y=0.0] + + + + 14400.0 + 46800.0 + + true + + + 23 + 5T + + [x=0.0][y=0.0] + + + + [x=0.0][y=0.0] + + + + 14400.0 + 46800.0 + + true + + + 11 + 3.5T + + [x=0.0][y=0.0] + + + + [x=0.0][y=0.0] + + + + 14400.0 + 46800.0 + + true + + + 3 + 1.5T + + [x=0.0][y=0.0] + + + + [x=0.0][y=0.0] + + + + 14400.0 + 46800.0 + + true + + + 1 + 1.5T + + [x=0.0][y=0.0] + + + + [x=0.0][y=0.0] + + + + 14400.0 + 46800.0 + + true + + + 12 + 3.5T + + [x=0.0][y=0.0] + + + + [x=0.0][y=0.0] + + + + 14400.0 + 46800.0 + + true + + + 22 + 5T + + [x=0.0][y=0.0] + + + + [x=0.0][y=0.0] + + + + 14400.0 + 46800.0 + + true + + + 15 + 3.5T + + [x=0.0][y=0.0] + + + + [x=0.0][y=0.0] + + + + 14400.0 + 46800.0 + + true + + + 16 + 3.5T + + [x=0.0][y=0.0] + + + + [x=0.0][y=0.0] + + + + 14400.0 + 46800.0 + + true + + + 9 + 1.5T + + [x=0.0][y=0.0] + + + + [x=0.0][y=0.0] + + + + 14400.0 + 46800.0 + + true + + + 4 + 1.5T + + [x=0.0][y=0.0] + + + + [x=0.0][y=0.0] + + + + 14400.0 + 46800.0 + + true + + + 2 + 1.5T + + [x=0.0][y=0.0] + + + + [x=0.0][y=0.0] + + + + 14400.0 + 46800.0 + + true + + + 24 + 5T + + [x=0.0][y=0.0] + + + + [x=0.0][y=0.0] + + + + 14400.0 + 46800.0 + + true + + + 5 + 1.5T + + [x=0.0][y=0.0] + + + + [x=0.0][y=0.0] + + + + 14400.0 + 46800.0 + + true + + + 17 + 3.5T + + [x=0.0][y=0.0] + + + + [x=0.0][y=0.0] + + + + 14400.0 + 46800.0 + + true + + + 25 + 5T + + [x=0.0][y=0.0] + + + + [x=0.0][y=0.0] + + + + 14400.0 + 46800.0 + + true + + + 13 + 3.5T + + [x=0.0][y=0.0] + + + + [x=0.0][y=0.0] + + + + 14400.0 + 46800.0 + + true + + + 27 + 8T + + [x=0.0][y=0.0] + + + + [x=0.0][y=0.0] + + + + 14400.0 + 46800.0 + + true + + + 6 + 1.5T + + [x=0.0][y=0.0] + + + + [x=0.0][y=0.0] + + + + 14400.0 + 46800.0 + + true + + + 10 + 1.5T + + [x=0.0][y=0.0] + + + + [x=0.0][y=0.0] + + + + 14400.0 + 46800.0 + + true + + + 8 + 1.5T + + [x=0.0][y=0.0] + + + + [x=0.0][y=0.0] + + + + 14400.0 + 46800.0 + + true + + + 26 + 8T + + [x=0.0][y=0.0] + + + + [x=0.0][y=0.0] + + + + 14400.0 + 46800.0 + + true + + + 14 + 3.5T + + [x=0.0][y=0.0] + + + + [x=0.0][y=0.0] + + + + 14400.0 + 46800.0 + + true + + + 21 + 5T + + [x=0.0][y=0.0] + + + + [x=0.0][y=0.0] + + + + 14400.0 + 46800.0 + + true + + + + + 1.5T + + 0 + + + 0.0 + 1.0 + + + + + 3.5T + + 0 + + + 0.0 + 1.0 + + + + + 5T + + 0 + + + 0.0 + 1.0 + + + + + 8T + + 0 + + + 0.0 + 1.0 + + + + + + + [x=1000.0][y=1000.0] + + + 0 + + 0.0 + + + 21600.0 + 36000.0 + + + + + [x=1000.0][y=1000.0] + + + 0 + + 0.0 + + + 21600.0 + 36000.0 + + + + + [x=1000.0][y=1000.0] + + + 0 + + 0.0 + + + 19800.0 + 21600.0 + + + + + [x=1000.0][y=1000.0] + + + 0 + + 0.0 + + + 21600.0 + 43200.0 + + + + + [x=1000.0][y=1000.0] + + + 0 + + 0.0 + + + 21600.0 + 43200.0 + + + + + [x=1000.0][y=1000.0] + + + 0 + + 0.0 + + + 21600.0 + 36000.0 + + + + + [x=1000.0][y=1000.0] + + + 0 + + 0.0 + + + 21600.0 + 36000.0 + + + + + [x=1000.0][y=1000.0] + + + 0 + + 0.0 + + + 54000.0 64800.0 - - true - - - 20 - 3.5T - - [x=0.0][y=0.0] - - - - [x=0.0][y=0.0] - - - - 14400.0 - 46800.0 - - true - - - 7 - 1.5T - - [x=0.0][y=0.0] - - - - [x=0.0][y=0.0] - - - - 14400.0 - 46800.0 - - true - - - 23 - 5T - - [x=0.0][y=0.0] - - - - [x=0.0][y=0.0] - - - - 14400.0 - 46800.0 - - true - - - 11 - 3.5T - - [x=0.0][y=0.0] - - - - [x=0.0][y=0.0] - - - - 14400.0 - 46800.0 - - true - - - 3 - 1.5T - - [x=0.0][y=0.0] - - - - [x=0.0][y=0.0] - - - - 14400.0 - 46800.0 - - true - - - 1 - 1.5T - - [x=0.0][y=0.0] - - - - [x=0.0][y=0.0] - - - - 14400.0 - 46800.0 - - true - - - 12 - 3.5T - - [x=0.0][y=0.0] - - - - [x=0.0][y=0.0] - - - - 14400.0 - 46800.0 - - true - - - 22 - 5T - - [x=0.0][y=0.0] - - - - [x=0.0][y=0.0] - - - - 14400.0 - 46800.0 - - true - - - 15 - 3.5T - - [x=0.0][y=0.0] - - - - [x=0.0][y=0.0] - - - - 14400.0 - 46800.0 - - true - - - 16 - 3.5T - - [x=0.0][y=0.0] - - - - [x=0.0][y=0.0] - - - - 14400.0 - 46800.0 - - true - - - 9 - 1.5T - - [x=0.0][y=0.0] - - - - [x=0.0][y=0.0] - - - - 14400.0 - 46800.0 - - true - - - 4 - 1.5T - - [x=0.0][y=0.0] - - - - [x=0.0][y=0.0] - - - - 14400.0 - 46800.0 - - true - - - 2 - 1.5T - - [x=0.0][y=0.0] - - - - [x=0.0][y=0.0] - - - - 14400.0 - 46800.0 - - true - - - 24 - 5T - - [x=0.0][y=0.0] - - - - [x=0.0][y=0.0] - - - - 14400.0 - 46800.0 - - true - - - 5 - 1.5T - - [x=0.0][y=0.0] - - - - [x=0.0][y=0.0] - - - - 14400.0 - 46800.0 - - true - - - 17 - 3.5T - - [x=0.0][y=0.0] - - - - [x=0.0][y=0.0] - - - - 14400.0 - 46800.0 - - true - - - 25 - 5T - - [x=0.0][y=0.0] - - - - [x=0.0][y=0.0] - - - - 14400.0 - 46800.0 - - true - - - 13 - 3.5T - - [x=0.0][y=0.0] - - - - [x=0.0][y=0.0] - - - - 14400.0 - 46800.0 - - true - - - 27 - 8T - - [x=0.0][y=0.0] - - - - [x=0.0][y=0.0] - - - - 14400.0 - 46800.0 - - true - - - 6 - 1.5T - - [x=0.0][y=0.0] - - - - [x=0.0][y=0.0] - - - - 14400.0 - 46800.0 - - true - - - 10 - 1.5T - - [x=0.0][y=0.0] - - - - [x=0.0][y=0.0] - - - - 14400.0 - 46800.0 - - true - - - 8 - 1.5T - - [x=0.0][y=0.0] - - - - [x=0.0][y=0.0] - - - - 14400.0 - 46800.0 - - true - - - 26 - 8T - - [x=0.0][y=0.0] - - - - [x=0.0][y=0.0] - - - - 14400.0 - 46800.0 - - true - - - 14 - 3.5T - - [x=0.0][y=0.0] - - - - [x=0.0][y=0.0] - - - - 14400.0 - 46800.0 - - true - - - 21 - 5T - - [x=0.0][y=0.0] - - - - [x=0.0][y=0.0] - - - - 14400.0 - 46800.0 - - true - - - - - 1.5T - - 0 - - - 0.0 - 1.0 - - - - - 3.5T - - 0 - - - 0.0 - 1.0 - - - - - 5T - - 0 - - - 0.0 - 1.0 - - - - - 8T - - 0 - - - 0.0 - 1.0 - - - - - - - [x=1000.0][y=1000.0] - - - 0 - - 0.0 - - - 21600.0 - 36000.0 - - - - - [x=1000.0][y=1000.0] - - - 0 - - 0.0 - - - 21600.0 - 36000.0 - - - - - [x=1000.0][y=1000.0] - - - 0 - - 0.0 - - - 19800.0 - 21600.0 - - - - - [x=1000.0][y=1000.0] - - - 0 - - 0.0 - - - 21600.0 - 43200.0 - - - - - [x=1000.0][y=1000.0] - - - 0 - - 0.0 - - - 21600.0 - 43200.0 - - - - - [x=1000.0][y=1000.0] - - - 0 - - 0.0 - - - 21600.0 - 36000.0 - - - - - [x=1000.0][y=1000.0] - - - 0 - - 0.0 - - - 21600.0 - 36000.0 - - - - - [x=1000.0][y=1000.0] - - - 0 - - 0.0 - - - 54000.0 - 64800.0 - - - - - [x=1000.0][y=1000.0] - - - 0 - - 0.0 - - - 21600.0 - 50400.0 - - - - + + + + + [x=1000.0][y=1000.0] + + + 0 + + 0.0 + + + 21600.0 + 50400.0 + + + + diff --git a/jsprit-core/src/test/resources/configWithRegretInsertion.xml b/jsprit-core/src/test/resources/configWithRegretInsertion.xml index 6a7e71ca..67b98c11 100755 --- a/jsprit-core/src/test/resources/configWithRegretInsertion.xml +++ b/jsprit-core/src/test/resources/configWithRegretInsertion.xml @@ -1,72 +1,73 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.w3schools.com algorithm_schema.xsd"> + + 10 + + + + + + + + 1 + + + + + + + + 0.5 + + + + + 0.4 + + + + + + + + + 0.1 + + + + + 0.4 + + + + + + + + + 0.3 + + + + + 0.2 + + + + + + + + + + + + + + - 10 - - - - - - - - 1 - - - - - - - - 0.5 - - - - - 0.4 - - - - - - - - - 0.1 - - - - - 0.4 - - - - - - - - - 0.3 - - - - - 0.2 - - - - - - - - - - - - - - - diff --git a/jsprit-core/src/test/resources/finiteVrp.xml b/jsprit-core/src/test/resources/finiteVrp.xml index 1110c71a..c44b46a1 100644 --- a/jsprit-core/src/test/resources/finiteVrp.xml +++ b/jsprit-core/src/test/resources/finiteVrp.xml @@ -1,89 +1,88 @@ - - FINITE - HETEROGENEOUS - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.w3schools.com vrp_xml_schema.xsd"> + + FINITE + HETEROGENEOUS + - - - v1 - - depotLoc2 - - - vehType - + + + v1 + + depotLoc2 + + + vehType + + 0.0 + 1000.0 + + + + v2 + + depotLoc + + + vehType2 + + 0.0 + 1000.0 + + + + + + vehType + 20 + + 0.0 + 0.0 + + + + + vehType2 + 200 + + 0.0 + 0.0 + + + + + + + + j(1,5) + + 1 + 0.0 + + 0.0 - 1000.0 - - - - v2 - - depotLoc - - - vehType2 - + 4000.0 + + + + + + i(3,9) + + 1 + 0.0 + + 0.0 - 1000.0 - - - - - - vehType - 20 - - 0.0 - 0.0 - - - - - vehType2 - 200 - - 0.0 - 0.0 - - - - - - - - j(1,5) - - 1 - 0.0 - - - 0.0 - 4000.0 - - - - - - i(3,9) - - 1 - 0.0 - - - 0.0 - 4000.0 - - - - - - - - + 4000.0 + + + + + + + diff --git a/jsprit-core/src/test/resources/finiteVrpForReaderTest.xml b/jsprit-core/src/test/resources/finiteVrpForReaderTest.xml index eb74e083..6d3ba822 100644 --- a/jsprit-core/src/test/resources/finiteVrpForReaderTest.xml +++ b/jsprit-core/src/test/resources/finiteVrpForReaderTest.xml @@ -18,220 +18,220 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~--> - - FINITE - HETEROGENEOUS - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.w3schools.com vrp_xml_schema.xsd"> + + FINITE + HETEROGENEOUS + - - - v1 - - depotLoc2 - - 1 - - vehType - + + + v1 + + depotLoc2 + + 1 + + vehType + + 0.0 + 1000.0 + + skill1; SKill2 + + + v2 + + depotLoc + + 2 + + false + vehType2 + + 0.0 + 1000.0 + + + + v3 + + startLoc + + 3 + + + endLoc + + 4 + + vehType2 + + 0.0 + 1000.0 + + + + v4 + + startLoc + + + + endLoc + + + vehType2 + + 0.0 + 1000.0 + + + + v5 + + startLoc + + + + endLoc + + + vehType3 + + 0.0 + 1000.0 + + + + + + vehType + + 20 + + + 0.0 + 0.0 + + + + + vehType2 + 200 + + 0.0 + 0.0 + + + + + vehType3 + + 100 + 1000 + 10000 + 100000 + + + 0.0 + 0.0 + + + + + + + + j(1,5) + cleaning + + + 1 + + 10.0 + + 0.0 - 1000.0 - - skill1; SKill2 - - - v2 - - depotLoc - - 2 - - false - vehType2 - - 0.0 - 1000.0 - - - - v3 - - startLoc - - 3 - - - endLoc - - 4 - - vehType2 - - 0.0 - 1000.0 - - - - v4 - - startLoc - - - - endLoc - - - vehType2 - - 0.0 - 1000.0 - - - - v5 - - startLoc - - - - endLoc - - - vehType3 - - 0.0 - 1000.0 - - - - - - vehType - - 20 - - - 0.0 - 0.0 - - - - - vehType2 - 200 - - 0.0 - 0.0 - - - - - vehType3 - - 100 - 1000 - 10000 - 100000 - - - 0.0 - 0.0 - - - - - - - - j(1,5) - cleaning - - - 1 - - 10.0 - - - 0.0 - 4000.0 - - - skill1, Skill2 - - - - i(3,9) - cleaning - - 1 - 0.0 - - - 0.0 - 4000.0 - - - - - - - - - deliver-smth - - i(3,9) - - 10.0 - - - 1000.0 - 4000.0 - - - - - i(9,9) - - 100.0 - - - 6000.0 - 10000.0 - - - - - 10 - + 4000.0 + + skill1, Skill2 - - - - - - - - 1000.0 - 4000.0 - - - - - - 100.0 - - - 6000.0 - 10000.0 - - - - - 10 - + + + + i(3,9) + cleaning + + 1 + 0.0 + + + 0.0 + 4000.0 + + + + + + + + deliver-smth - - - + + i(3,9) + + 10.0 + + + 1000.0 + 4000.0 + + + + + i(9,9) + + 100.0 + + + 6000.0 + 10000.0 + + + + + 10 + + skill1, Skill2 + + + + + + + + 1000.0 + 4000.0 + + + + + + 100.0 + + + 6000.0 + 10000.0 + + + + + 10 + + deliver-smth + + + diff --git a/jsprit-core/src/test/resources/finiteVrpWithInitialSolutionForReaderTest.xml b/jsprit-core/src/test/resources/finiteVrpWithInitialSolutionForReaderTest.xml index 315386d0..22e367a8 100644 --- a/jsprit-core/src/test/resources/finiteVrpWithInitialSolutionForReaderTest.xml +++ b/jsprit-core/src/test/resources/finiteVrpWithInitialSolutionForReaderTest.xml @@ -1,223 +1,223 @@ - - FINITE - HETEROGENEOUS - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.w3schools.com vrp_xml_schema.xsd"> + + FINITE + HETEROGENEOUS + - - - v1 - - depotLoc2 - - - vehType - + + + v1 + + depotLoc2 + + + vehType + + 0.0 + 1000.0 + + + + v2 + + depotLoc + + + false + vehType2 + + 0.0 + 1000.0 + + + + v3 + + startLoc + + + + endLoc + + + vehType2 + + 0.0 + 1000.0 + + + + v4 + + startLoc + + + + endLoc + + + vehType2 + + 0.0 + 1000.0 + + + + v5 + + startLoc + + + + endLoc + + + vehType3 + + 0.0 + 1000.0 + + + + + + vehType + + 20 + + + 0.0 + 0.0 + + + + + vehType2 + 200 + + 0.0 + 0.0 + + + + + vehType3 + + 100 + 1000 + 10000 + 100000 + + + 0.0 + 0.0 + + + + + + + + j(1,5) + + + 1 + + 10.0 + + 0.0 - 1000.0 - - - - v2 - - depotLoc - - - false - vehType2 - + 4000.0 + + + + + + i(3,9) + + 1 + 0.0 + + 0.0 - 1000.0 - - - - v3 - - startLoc - - - - endLoc - - - vehType2 - - 0.0 - 1000.0 - - - - v4 - - startLoc - - - - endLoc - - - vehType2 - - 0.0 - 1000.0 - - - - v5 - - startLoc - - - - endLoc - - - vehType3 - - 0.0 - 1000.0 - - - - - - vehType - - 20 - - - 0.0 - 0.0 - - - - - vehType2 - 200 - - 0.0 - 0.0 - - - - - vehType3 - - 100 - 1000 - 10000 - 100000 - - - 0.0 - 0.0 - - - - - - - - j(1,5) + 4000.0 + + + + + + + + + + i(3,9) - - 1 - - 10.0 - + 10.0 + - 0.0 - 4000.0 + 1000.0 + 4000.0 - - - - - i(3,9) - - 1 - 0.0 - + + + + i(9,9) + + 100.0 + - 0.0 - 4000.0 + 6000.0 + 10000.0 - - - - - - - - - i(3,9) - - 10.0 - + + + 10 + + + + + + - 1000.0 - 4000.0 + 1000.0 + 4000.0 - - - - i(9,9) - - 100.0 - + + + + + 100.0 + - 6000.0 - 10000.0 + 6000.0 + 10000.0 - - - 10 - - - - - - - - 1000.0 - 4000.0 - - - - - - 100.0 - - - 6000.0 - 10000.0 - - - - - 10 - - - - - - - - noDriver - v1 - 10. - - 4 - - - 4 - - + + + + 10 + + + + + + + + noDriver + v1 + 10. + + 4 + + + 4 + + - - + + diff --git a/jsprit-core/src/test/resources/finiteVrpWithShipmentsAndSolution.xml b/jsprit-core/src/test/resources/finiteVrpWithShipmentsAndSolution.xml index 1171c3b8..89889383 100644 --- a/jsprit-core/src/test/resources/finiteVrpWithShipmentsAndSolution.xml +++ b/jsprit-core/src/test/resources/finiteVrpWithShipmentsAndSolution.xml @@ -1,165 +1,165 @@ - - FINITE - HETEROGENEOUS - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.w3schools.com vrp_xml_schema.xsd"> + + FINITE + HETEROGENEOUS + - - - v1 - - depotLoc2 - - - vehType - + + + v1 + + depotLoc2 + + + vehType + + 0.0 + 1000.0 + + + + v2 + + depotLoc + + + vehType2 + + 0.0 + 1000.0 + + + + + + vehType + 20 + + 0.0 + 0.0 + + + + + vehType2 + 200 + + 0.0 + 0.0 + + + + + + + + j(1,5) + + 1 + 0.0 + + 0.0 - 1000.0 - - - - v2 - - depotLoc - - - vehType2 - + 4000.0 + + + + + + i(3,9) + + 1 + 0.0 + + 0.0 - 1000.0 - - - - - - vehType - 20 - - 0.0 - 0.0 - - - - - vehType2 - 200 - - 0.0 - 0.0 - - - - - - - - j(1,5) + 4000.0 + + + + + + i(3,9) + + 1 + 0.0 + + + 0.0 + 4000.0 + + + + + + + + + i(3,9) - 1 - 0.0 - + 0.0 + - 0.0 - 4000.0 + 0.0 + 4000.0 - - - - - i(3,9) - - 1 - 0.0 - + + + + i(9,9) + + 0.0 + - 0.0 - 4000.0 + 0.0 + 4000.0 - - + + + 1 + + + + + + 100.0 + + + 0.0 + noDriver + v1 + 10.0 + + 1 + 20.0 + 30.0 + + + 2 + 40.0 + 80.0 + + + 3 + 40.0 + 80.0 + + + 3 + 40.0 + 80.0 + + 100.0 + + + + + + + - - i(3,9) - - 1 - 0.0 - - - 0.0 - 4000.0 - - - - - - - - - i(3,9) - - 0.0 - - - 0.0 - 4000.0 - - - - - i(9,9) - - 0.0 - - - 0.0 - 4000.0 - - - - 1 - - - - - - 100.0 - - - 0.0 - noDriver - v1 - 10.0 - - 1 - 20.0 - 30.0 - - - 2 - 40.0 - 80.0 - - - 3 - 40.0 - 80.0 - - - 3 - 40.0 - 80.0 - - 100.0 - - - - - - - - diff --git a/jsprit-core/src/test/resources/finiteVrpWithSolutionForReaderTest.xml b/jsprit-core/src/test/resources/finiteVrpWithSolutionForReaderTest.xml index 9fdde7c3..ccb99096 100644 --- a/jsprit-core/src/test/resources/finiteVrpWithSolutionForReaderTest.xml +++ b/jsprit-core/src/test/resources/finiteVrpWithSolutionForReaderTest.xml @@ -1,207 +1,207 @@ - - FINITE - HETEROGENEOUS - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.w3schools.com vrp_xml_schema.xsd"> + + FINITE + HETEROGENEOUS + - - - v1 - - depotLoc2 - - - vehType - + + + v1 + + depotLoc2 + + + vehType + + 0.0 + 1000.0 + + + + v2 + + depotLoc + + + false + vehType2 + + 0.0 + 1000.0 + + + + v3 + + startLoc + + + + endLoc + + + vehType2 + + 0.0 + 1000.0 + + + + v4 + + startLoc + + + + endLoc + + + vehType2 + + 0.0 + 1000.0 + + + + v5 + + startLoc + + + + endLoc + + + vehType3 + + 0.0 + 1000.0 + + + + + + vehType + + 20 + + + 0.0 + 0.0 + + + + + vehType2 + 200 + + 0.0 + 0.0 + + + + + vehType3 + + 100 + 1000 + 10000 + 100000 + + + 0.0 + 0.0 + + + + + + + + j(1,5) + + + 1 + + 10.0 + + 0.0 - 1000.0 - - - - v2 - - depotLoc - - - false - vehType2 - + 4000.0 + + + + + + i(3,9) + + 1 + 0.0 + + 0.0 - 1000.0 - - - - v3 - - startLoc - - - - endLoc - - - vehType2 - - 0.0 - 1000.0 - - - - v4 - - startLoc - - - - endLoc - - - vehType2 - - 0.0 - 1000.0 - - - - v5 - - startLoc - - - - endLoc - - - vehType3 - - 0.0 - 1000.0 - - - - - - vehType - - 20 - - - 0.0 - 0.0 - - - - - vehType2 - 200 - - 0.0 - 0.0 - - - - - vehType3 - - 100 - 1000 - 10000 - 100000 - - - 0.0 - 0.0 - - - - - - - - j(1,5) + 4000.0 + + + + + + + + + + i(3,9) - - 1 - - 10.0 - + 10.0 + - 0.0 - 4000.0 + 1000.0 + 4000.0 - - - - - i(3,9) - - 1 - 0.0 - + + + + i(9,9) + + 100.0 + - 0.0 - 4000.0 + 6000.0 + 10000.0 - - - - - - - - - i(3,9) - - 10.0 - + + + 10 + + + + + + - 1000.0 - 4000.0 + 1000.0 + 4000.0 - - - - i(9,9) - - 100.0 - + + + + + 100.0 + - 6000.0 - 10000.0 + 6000.0 + 10000.0 - - - 10 - - - - - - - - 1000.0 - 4000.0 - - - - - - 100.0 - - - 6000.0 - 10000.0 - - - - - 10 - - - - + + + + 10 + + + + diff --git a/jsprit-core/src/test/resources/lilim_algorithmConfig.xml b/jsprit-core/src/test/resources/lilim_algorithmConfig.xml index 8466fb31..1fb6ba15 100644 --- a/jsprit-core/src/test/resources/lilim_algorithmConfig.xml +++ b/jsprit-core/src/test/resources/lilim_algorithmConfig.xml @@ -18,54 +18,55 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~--> + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.w3schools.com algorithm_schema.xsd"> - 2000 + 2000 - - - - + + + + - - 1 - - - - - 0.1 - 20 - - - - - 0.4 - - - + + 1 + + + + + 0.1 + 20 + + + + + 0.4 + + + - - 0.5 - + + 0.5 + - - - + + + - - - - 0.3 - - - + + + + 0.3 + + + - - .5 - - - - + + .5 + + + + - \ No newline at end of file + diff --git a/jsprit-core/src/test/resources/lilim_lr101.xml b/jsprit-core/src/test/resources/lilim_lr101.xml index a375627c..f389a4d4 100644 --- a/jsprit-core/src/test/resources/lilim_lr101.xml +++ b/jsprit-core/src/test/resources/lilim_lr101.xml @@ -1,1473 +1,1474 @@ - - INFINITE - HOMOGENEOUS - - - - vehicle - type - - [x=35.0][y=35.0] - - - - [x=35.0][y=35.0] - - - - 0.0 - 230.0 - - true - - - - - type - - 200 - - - 0.0 - 1.0 - - - - - - - - [x=27.0][y=69.0] - - 10.0 - - - 34.0 - 44.0 - - - - - [x=6.0][y=68.0] - - 10.0 - - - 108.0 - 118.0 - - - - - 10 - - - - - [x=15.0][y=77.0] - - 10.0 - - - 73.0 - 83.0 - - - - - [x=13.0][y=52.0] - - 10.0 - - - 165.0 - 175.0 - - - - - 9 - - - - - [x=12.0][y=24.0] - - 10.0 - - - 76.0 - 86.0 - - - - - [x=18.0][y=24.0] - - 10.0 - - - 188.0 - 198.0 - - - - - 13 - - - - - [x=24.0][y=58.0] - - 10.0 - - - 58.0 - 68.0 - - - - - [x=37.0][y=56.0] - - 10.0 - - - 182.0 - 192.0 - - - - - 19 - - - - - [x=56.0][y=39.0] - - 0.0 - - - 142.0 - 152.0 - - - - - [x=56.0][y=39.0] - - 10.0 - - - 142.0 - 152.0 - - - - - 36 - - - - - [x=62.0][y=77.0] - - 10.0 - - - 51.0 - 61.0 - - - - - [x=55.0][y=54.0] - - 10.0 - - - 94.0 - 104.0 - - - - - 20 - - - - - [x=49.0][y=73.0] - - 10.0 - - - 127.0 - 137.0 - - - - - [x=41.0][y=49.0] - - 10.0 - - - 161.0 - 171.0 - - - - - 25 - - - - - [x=46.0][y=13.0] - - 0.0 - - - 149.0 - 159.0 - - - - - [x=46.0][y=13.0] - - 10.0 - - - 149.0 - 159.0 - - - - - 8 - - - - - [x=47.0][y=16.0] - - 10.0 - - - 35.0 - 45.0 - - - - - [x=36.0][y=26.0] - - 10.0 - - - 200.0 - 210.0 - - - - - 25 - - - - - [x=57.0][y=68.0] - - 10.0 - - - 77.0 - 87.0 - - - - - [x=47.0][y=47.0] - - 10.0 - - - 124.0 - 134.0 - - - - - 15 - - - - - [x=37.0][y=47.0] - - 10.0 - - - 50.0 - 60.0 - - - - - [x=55.0][y=45.0] - - 10.0 - - - 116.0 - 126.0 - - - - - 6 - - - - - [x=24.0][y=12.0] - - 10.0 - - - 31.0 - 41.0 - - - - - [x=28.0][y=18.0] - - 10.0 - - - 93.0 - 103.0 - - - - - 5 - - - - - [x=23.0][y=3.0] - - 10.0 - - - 132.0 - 142.0 - - - - - [x=30.0][y=25.0] - - 10.0 - - - 159.0 - 169.0 - - - - - 7 - - - - - [x=11.0][y=14.0] - - 0.0 - - - 69.0 - 79.0 - - - - - [x=11.0][y=14.0] - - 10.0 - - - 69.0 - 79.0 - - - - - 18 - - - - - [x=6.0][y=38.0] - - 10.0 - - - 32.0 - 42.0 - - - - - [x=11.0][y=31.0] - - 10.0 - - - 101.0 - 111.0 - - - - - 16 - - - - - [x=8.0][y=56.0] - - 10.0 - - - 51.0 - 61.0 - - - - - [x=2.0][y=48.0] - - 10.0 - - - 117.0 - 127.0 - - - - - 27 - - - - - [x=49.0][y=58.0] - - 0.0 - - - 88.0 - 98.0 - - - - - [x=49.0][y=58.0] - - 10.0 - - - 88.0 - 98.0 - - - - - 10 - - - - - [x=27.0][y=43.0] - - 10.0 - - - 52.0 - 62.0 - - - - - [x=25.0][y=30.0] - - 10.0 - - - 99.0 - 109.0 - - - - - 9 - - - - - [x=37.0][y=31.0] - - 0.0 - - - 95.0 - 105.0 - - - - - [x=37.0][y=31.0] - - 10.0 - - - 95.0 - 105.0 - - - - - 14 - - - - - [x=10.0][y=43.0] - - 10.0 - - - 95.0 - 105.0 - - - - - [x=5.0][y=30.0] - - 10.0 - - - 157.0 - 167.0 - - - - - 9 - - - - - [x=15.0][y=30.0] - - 10.0 - - - 34.0 - 44.0 - - - - - [x=16.0][y=22.0] - - 10.0 - - - 91.0 - 101.0 - - - - - 26 - - - - - [x=35.0][y=17.0] - - 10.0 - - - 50.0 - 60.0 - - - - - [x=44.0][y=17.0] - - 10.0 - - - 78.0 - 88.0 - - - - - 7 - - - - - [x=63.0][y=23.0] - - 10.0 - - - 136.0 - 146.0 - - - - - [x=65.0][y=20.0] - - 10.0 - - - 172.0 - 182.0 - - - - - 2 - - - - - [x=10.0][y=20.0] - - 10.0 - - - 75.0 - 85.0 - - - - - [x=15.0][y=19.0] - - 10.0 - - - 160.0 - 170.0 - - - - - 19 - - - - - [x=30.0][y=5.0] - - 10.0 - - - 61.0 - 71.0 - - - - - [x=25.0][y=21.0] - - 10.0 - - - 133.0 - 143.0 - - - - - 8 - - - - - [x=15.0][y=10.0] - - 10.0 - - - 32.0 - 42.0 - - - - - [x=5.0][y=5.0] - - 10.0 - - - 83.0 - 93.0 - - - - - 20 - - - - - [x=21.0][y=24.0] - - 10.0 - - - 18.0 - 28.0 - - - - - [x=22.0][y=27.0] - - 10.0 - - - 135.0 - 145.0 - - - - - 28 - - - - - [x=20.0][y=65.0] - - 10.0 - - - 67.0 - 77.0 - - - - - [x=45.0][y=65.0] - - 10.0 - - - 126.0 - 136.0 - - - - - 12 - - - - - [x=53.0][y=12.0] - - 10.0 - - - 130.0 - 140.0 - - - - - [x=55.0][y=20.0] - - 10.0 - - - 149.0 - 159.0 - - - - - 6 - - - - - [x=45.0][y=20.0] - - 10.0 - - - 62.0 - 72.0 - - - - - [x=42.0][y=7.0] - - 10.0 - - - 97.0 - 107.0 - - - - - 11 - - - - - [x=20.0][y=40.0] - - 10.0 - - - 87.0 - 97.0 - - - - - [x=26.0][y=35.0] - - 10.0 - - - 176.0 - 186.0 - - - - - 12 - - - - - [x=2.0][y=60.0] - - 10.0 - - - 41.0 - 51.0 - - - - - [x=15.0][y=60.0] - - 10.0 - - - 76.0 - 86.0 - - - - - 5 - - - - - [x=53.0][y=52.0] - - 10.0 - - - 37.0 - 47.0 - - - - - [x=65.0][y=55.0] - - 10.0 - - - 117.0 - 127.0 - - - - - 11 - - - - - [x=63.0][y=65.0] - - 10.0 - - - 143.0 - 153.0 - - - - - [x=53.0][y=43.0] - - 10.0 - - - 179.0 - 189.0 - - - - - 8 - - - - - [x=40.0][y=60.0] - - 10.0 - - - 71.0 - 81.0 - - - - - [x=55.0][y=60.0] - - 10.0 - - - 97.0 - 107.0 - - - - - 21 - - - - - [x=31.0][y=52.0] - - 10.0 - - - 50.0 - 60.0 - - - - - [x=30.0][y=60.0] - - 10.0 - - - 124.0 - 134.0 - - - - - 27 - - - - - [x=41.0][y=37.0] - - 10.0 - - - 39.0 - 49.0 - - - - - [x=50.0][y=35.0] - - 10.0 - - - 63.0 - 73.0 - - - - - 16 - - - - - [x=64.0][y=42.0] - - 10.0 - - - 63.0 - 73.0 - - - - - [x=61.0][y=52.0] - - 10.0 - - - 96.0 - 106.0 - - - - - 9 - - - - - [x=65.0][y=35.0] - - 10.0 - - - 153.0 - 163.0 - - - - - [x=56.0][y=37.0] - - 10.0 - - - 182.0 - 192.0 - - - - - 3 - - - - - [x=35.0][y=40.0] - - 10.0 - - - 37.0 - 47.0 - - - - - [x=57.0][y=48.0] - - 10.0 - - - 92.0 - 102.0 - - - - - 16 - - - - - [x=40.0][y=25.0] - - 10.0 - - - 85.0 - 95.0 - - - - - [x=45.0][y=30.0] - - 10.0 - - - 132.0 - 142.0 - - - - - 9 - - - - - [x=60.0][y=12.0] - - 10.0 - - - 44.0 - 54.0 - - - - - [x=67.0][y=5.0] - - 10.0 - - - 83.0 - 93.0 - - - - - 31 - - - - - [x=31.0][y=67.0] - - 10.0 - - - 95.0 - 105.0 - - - - - [x=35.0][y=69.0] - - 10.0 - - - 141.0 - 151.0 - - - - - 3 - - - - - [x=26.0][y=52.0] - - 10.0 - - - 74.0 - 84.0 - - - - - [x=20.0][y=50.0] - - 10.0 - - - 81.0 - 91.0 - - - - - 9 - - - - - [x=49.0][y=42.0] - - 10.0 - - - 73.0 - 83.0 - - - - - [x=57.0][y=29.0] - - 10.0 - - - 140.0 - 150.0 - - - - - 13 - - - - - [x=49.0][y=11.0] - - 10.0 - - - 69.0 - 79.0 - - - - - [x=45.0][y=10.0] - - 10.0 - - - 97.0 - 107.0 - - - - - 18 - - - - - [x=14.0][y=37.0] - - 10.0 - - - 44.0 - 54.0 - - - - - [x=20.0][y=20.0] - - 10.0 - - - 134.0 - 144.0 - - - - - 11 - - - - - [x=15.0][y=47.0] - - 10.0 - - - 55.0 - 65.0 - - - - - [x=17.0][y=34.0] - - 10.0 - - - 162.0 - 172.0 - - - - - 16 - - - - - [x=55.0][y=5.0] - - 0.0 - - - 68.0 - 78.0 - - - - - [x=55.0][y=5.0] - - 10.0 - - - 68.0 - 78.0 - - - - - 29 - - - - - [x=25.0][y=24.0] - - 10.0 - - - 39.0 - 49.0 - - - - - [x=18.0][y=18.0] - - 10.0 - - - 185.0 - 195.0 - - - - - 20 - - - - - [x=19.0][y=21.0] - - 10.0 - - - 58.0 - 68.0 - - - - - [x=4.0][y=18.0] - - 10.0 - - - 94.0 - 104.0 - - - - - 10 - - - - - [x=20.0][y=26.0] - - 10.0 - - - 83.0 - 93.0 - - - - - [x=26.0][y=27.0] - - 10.0 - - - 100.0 - 110.0 - - - - - 9 - - - - - [x=22.0][y=22.0] - - 10.0 - - - 18.0 - 28.0 - - - - - [x=32.0][y=12.0] - - 10.0 - - - 101.0 - 111.0 - - - - - 2 - - - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.w3schools.com vrp_xml_schema.xsd"> + + INFINITE + HOMOGENEOUS + + + + vehicle + type + + [x=35.0][y=35.0] + + + + [x=35.0][y=35.0] + + + + 0.0 + 230.0 + + true + + + + + type + + 200 + + + 0.0 + 1.0 + + + + + + + + [x=27.0][y=69.0] + + 10.0 + + + 34.0 + 44.0 + + + + + [x=6.0][y=68.0] + + 10.0 + + + 108.0 + 118.0 + + + + + 10 + + + + + [x=15.0][y=77.0] + + 10.0 + + + 73.0 + 83.0 + + + + + [x=13.0][y=52.0] + + 10.0 + + + 165.0 + 175.0 + + + + + 9 + + + + + [x=12.0][y=24.0] + + 10.0 + + + 76.0 + 86.0 + + + + + [x=18.0][y=24.0] + + 10.0 + + + 188.0 + 198.0 + + + + + 13 + + + + + [x=24.0][y=58.0] + + 10.0 + + + 58.0 + 68.0 + + + + + [x=37.0][y=56.0] + + 10.0 + + + 182.0 + 192.0 + + + + + 19 + + + + + [x=56.0][y=39.0] + + 0.0 + + + 142.0 + 152.0 + + + + + [x=56.0][y=39.0] + + 10.0 + + + 142.0 + 152.0 + + + + + 36 + + + + + [x=62.0][y=77.0] + + 10.0 + + + 51.0 + 61.0 + + + + + [x=55.0][y=54.0] + + 10.0 + + + 94.0 + 104.0 + + + + + 20 + + + + + [x=49.0][y=73.0] + + 10.0 + + + 127.0 + 137.0 + + + + + [x=41.0][y=49.0] + + 10.0 + + + 161.0 + 171.0 + + + + + 25 + + + + + [x=46.0][y=13.0] + + 0.0 + + + 149.0 + 159.0 + + + + + [x=46.0][y=13.0] + + 10.0 + + + 149.0 + 159.0 + + + + + 8 + + + + + [x=47.0][y=16.0] + + 10.0 + + + 35.0 + 45.0 + + + + + [x=36.0][y=26.0] + + 10.0 + + + 200.0 + 210.0 + + + + + 25 + + + + + [x=57.0][y=68.0] + + 10.0 + + + 77.0 + 87.0 + + + + + [x=47.0][y=47.0] + + 10.0 + + + 124.0 + 134.0 + + + + + 15 + + + + + [x=37.0][y=47.0] + + 10.0 + + + 50.0 + 60.0 + + + + + [x=55.0][y=45.0] + + 10.0 + + + 116.0 + 126.0 + + + + + 6 + + + + + [x=24.0][y=12.0] + + 10.0 + + + 31.0 + 41.0 + + + + + [x=28.0][y=18.0] + + 10.0 + + + 93.0 + 103.0 + + + + + 5 + + + + + [x=23.0][y=3.0] + + 10.0 + + + 132.0 + 142.0 + + + + + [x=30.0][y=25.0] + + 10.0 + + + 159.0 + 169.0 + + + + + 7 + + + + + [x=11.0][y=14.0] + + 0.0 + + + 69.0 + 79.0 + + + + + [x=11.0][y=14.0] + + 10.0 + + + 69.0 + 79.0 + + + + + 18 + + + + + [x=6.0][y=38.0] + + 10.0 + + + 32.0 + 42.0 + + + + + [x=11.0][y=31.0] + + 10.0 + + + 101.0 + 111.0 + + + + + 16 + + + + + [x=8.0][y=56.0] + + 10.0 + + + 51.0 + 61.0 + + + + + [x=2.0][y=48.0] + + 10.0 + + + 117.0 + 127.0 + + + + + 27 + + + + + [x=49.0][y=58.0] + + 0.0 + + + 88.0 + 98.0 + + + + + [x=49.0][y=58.0] + + 10.0 + + + 88.0 + 98.0 + + + + + 10 + + + + + [x=27.0][y=43.0] + + 10.0 + + + 52.0 + 62.0 + + + + + [x=25.0][y=30.0] + + 10.0 + + + 99.0 + 109.0 + + + + + 9 + + + + + [x=37.0][y=31.0] + + 0.0 + + + 95.0 + 105.0 + + + + + [x=37.0][y=31.0] + + 10.0 + + + 95.0 + 105.0 + + + + + 14 + + + + + [x=10.0][y=43.0] + + 10.0 + + + 95.0 + 105.0 + + + + + [x=5.0][y=30.0] + + 10.0 + + + 157.0 + 167.0 + + + + + 9 + + + + + [x=15.0][y=30.0] + + 10.0 + + + 34.0 + 44.0 + + + + + [x=16.0][y=22.0] + + 10.0 + + + 91.0 + 101.0 + + + + + 26 + + + + + [x=35.0][y=17.0] + + 10.0 + + + 50.0 + 60.0 + + + + + [x=44.0][y=17.0] + + 10.0 + + + 78.0 + 88.0 + + + + + 7 + + + + + [x=63.0][y=23.0] + + 10.0 + + + 136.0 + 146.0 + + + + + [x=65.0][y=20.0] + + 10.0 + + + 172.0 + 182.0 + + + + + 2 + + + + + [x=10.0][y=20.0] + + 10.0 + + + 75.0 + 85.0 + + + + + [x=15.0][y=19.0] + + 10.0 + + + 160.0 + 170.0 + + + + + 19 + + + + + [x=30.0][y=5.0] + + 10.0 + + + 61.0 + 71.0 + + + + + [x=25.0][y=21.0] + + 10.0 + + + 133.0 + 143.0 + + + + + 8 + + + + + [x=15.0][y=10.0] + + 10.0 + + + 32.0 + 42.0 + + + + + [x=5.0][y=5.0] + + 10.0 + + + 83.0 + 93.0 + + + + + 20 + + + + + [x=21.0][y=24.0] + + 10.0 + + + 18.0 + 28.0 + + + + + [x=22.0][y=27.0] + + 10.0 + + + 135.0 + 145.0 + + + + + 28 + + + + + [x=20.0][y=65.0] + + 10.0 + + + 67.0 + 77.0 + + + + + [x=45.0][y=65.0] + + 10.0 + + + 126.0 + 136.0 + + + + + 12 + + + + + [x=53.0][y=12.0] + + 10.0 + + + 130.0 + 140.0 + + + + + [x=55.0][y=20.0] + + 10.0 + + + 149.0 + 159.0 + + + + + 6 + + + + + [x=45.0][y=20.0] + + 10.0 + + + 62.0 + 72.0 + + + + + [x=42.0][y=7.0] + + 10.0 + + + 97.0 + 107.0 + + + + + 11 + + + + + [x=20.0][y=40.0] + + 10.0 + + + 87.0 + 97.0 + + + + + [x=26.0][y=35.0] + + 10.0 + + + 176.0 + 186.0 + + + + + 12 + + + + + [x=2.0][y=60.0] + + 10.0 + + + 41.0 + 51.0 + + + + + [x=15.0][y=60.0] + + 10.0 + + + 76.0 + 86.0 + + + + + 5 + + + + + [x=53.0][y=52.0] + + 10.0 + + + 37.0 + 47.0 + + + + + [x=65.0][y=55.0] + + 10.0 + + + 117.0 + 127.0 + + + + + 11 + + + + + [x=63.0][y=65.0] + + 10.0 + + + 143.0 + 153.0 + + + + + [x=53.0][y=43.0] + + 10.0 + + + 179.0 + 189.0 + + + + + 8 + + + + + [x=40.0][y=60.0] + + 10.0 + + + 71.0 + 81.0 + + + + + [x=55.0][y=60.0] + + 10.0 + + + 97.0 + 107.0 + + + + + 21 + + + + + [x=31.0][y=52.0] + + 10.0 + + + 50.0 + 60.0 + + + + + [x=30.0][y=60.0] + + 10.0 + + + 124.0 + 134.0 + + + + + 27 + + + + + [x=41.0][y=37.0] + + 10.0 + + + 39.0 + 49.0 + + + + + [x=50.0][y=35.0] + + 10.0 + + + 63.0 + 73.0 + + + + + 16 + + + + + [x=64.0][y=42.0] + + 10.0 + + + 63.0 + 73.0 + + + + + [x=61.0][y=52.0] + + 10.0 + + + 96.0 + 106.0 + + + + + 9 + + + + + [x=65.0][y=35.0] + + 10.0 + + + 153.0 + 163.0 + + + + + [x=56.0][y=37.0] + + 10.0 + + + 182.0 + 192.0 + + + + + 3 + + + + + [x=35.0][y=40.0] + + 10.0 + + + 37.0 + 47.0 + + + + + [x=57.0][y=48.0] + + 10.0 + + + 92.0 + 102.0 + + + + + 16 + + + + + [x=40.0][y=25.0] + + 10.0 + + + 85.0 + 95.0 + + + + + [x=45.0][y=30.0] + + 10.0 + + + 132.0 + 142.0 + + + + + 9 + + + + + [x=60.0][y=12.0] + + 10.0 + + + 44.0 + 54.0 + + + + + [x=67.0][y=5.0] + + 10.0 + + + 83.0 + 93.0 + + + + + 31 + + + + + [x=31.0][y=67.0] + + 10.0 + + + 95.0 + 105.0 + + + + + [x=35.0][y=69.0] + + 10.0 + + + 141.0 + 151.0 + + + + + 3 + + + + + [x=26.0][y=52.0] + + 10.0 + + + 74.0 + 84.0 + + + + + [x=20.0][y=50.0] + + 10.0 + + + 81.0 + 91.0 + + + + + 9 + + + + + [x=49.0][y=42.0] + + 10.0 + + + 73.0 + 83.0 + + + + + [x=57.0][y=29.0] + + 10.0 + + + 140.0 + 150.0 + + + + + 13 + + + + + [x=49.0][y=11.0] + + 10.0 + + + 69.0 + 79.0 + + + + + [x=45.0][y=10.0] + + 10.0 + + + 97.0 + 107.0 + + + + + 18 + + + + + [x=14.0][y=37.0] + + 10.0 + + + 44.0 + 54.0 + + + + + [x=20.0][y=20.0] + + 10.0 + + + 134.0 + 144.0 + + + + + 11 + + + + + [x=15.0][y=47.0] + + 10.0 + + + 55.0 + 65.0 + + + + + [x=17.0][y=34.0] + + 10.0 + + + 162.0 + 172.0 + + + + + 16 + + + + + [x=55.0][y=5.0] + + 0.0 + + + 68.0 + 78.0 + + + + + [x=55.0][y=5.0] + + 10.0 + + + 68.0 + 78.0 + + + + + 29 + + + + + [x=25.0][y=24.0] + + 10.0 + + + 39.0 + 49.0 + + + + + [x=18.0][y=18.0] + + 10.0 + + + 185.0 + 195.0 + + + + + 20 + + + + + [x=19.0][y=21.0] + + 10.0 + + + 58.0 + 68.0 + + + + + [x=4.0][y=18.0] + + 10.0 + + + 94.0 + 104.0 + + + + + 10 + + + + + [x=20.0][y=26.0] + + 10.0 + + + 83.0 + 93.0 + + + + + [x=26.0][y=27.0] + + 10.0 + + + 100.0 + 110.0 + + + + + 9 + + + + + [x=22.0][y=22.0] + + 10.0 + + + 18.0 + 28.0 + + + + + [x=32.0][y=12.0] + + 10.0 + + + 101.0 + 111.0 + + + + + 2 + + + diff --git a/jsprit-core/src/test/resources/lui-shen-solution.xml b/jsprit-core/src/test/resources/lui-shen-solution.xml index c21ee78c..46adb244 100644 --- a/jsprit-core/src/test/resources/lui-shen-solution.xml +++ b/jsprit-core/src/test/resources/lui-shen-solution.xml @@ -1,1918 +1,1919 @@ - - INFINITE - HETEROGENEOUS - - - - A - A - - 0 - - - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.w3schools.com vrp_xml_schema.xsd"> + + INFINITE + HETEROGENEOUS + + + + A + A + + 0 + + + + 0.0 + 1236.0 + + + + B + B + + 0 + + + + 0.0 + 1236.0 + + + + C + C + + 0 + + + + 0.0 + 1236.0 + + + + + + A + 100 + + 300.0 + 1.0 + + + + + B + 200 + + 800.0 + 1.0 + + + + + C + 300 + + 1350.0 + 1.0 + + + + + + + 25 + + 40 + 90.0 + + + 169.0 + 224.0 + + + + + 26 + + 10 + 90.0 + + + 622.0 + 701.0 + + + + + 23 + + 10 + 90.0 + + + 732.0 + 777.0 + + + + + 24 + + 10 + 90.0 + + + 65.0 + 144.0 + + + + + 29 + + 10 + 90.0 + + + 358.0 + 405.0 + + + + + 27 + + 10 + 90.0 + + + 261.0 + 316.0 + + + + + 28 + + 20 + 90.0 + + + 546.0 + 593.0 + + + + + 33 + + 40 + 90.0 + + + 87.0 + 158.0 + + + + + 32 + + 30 + 90.0 + + + 31.0 + 100.0 + + + + + 31 + + 20 + 90.0 + + + 200.0 + 237.0 + + + + + 30 + + 10 + 90.0 + + + 449.0 + 504.0 + + + + + 12 + + 20 + 90.0 + + + 652.0 + 721.0 + + + + + 13 + + 30 + 90.0 + + + 30.0 + 92.0 + + + + + 14 + + 10 + 90.0 + + + 567.0 + 620.0 + + + + + 15 + + 40 + 90.0 + + + 384.0 + 429.0 + + + + + 16 + + 40 + 90.0 + + + 475.0 + 528.0 + + + + + 17 + + 20 + 90.0 + + + 99.0 + 148.0 + + + + + 18 + + 20 + 90.0 + + + 179.0 + 254.0 + + + + + 19 + + 10 + 90.0 + + + 278.0 + 345.0 + + + + + 20 + + 10 + 90.0 + + + 10.0 + 73.0 + + + + + 22 + + 20 + 90.0 + + + 812.0 + 883.0 + + + + + 21 + + 20 + 90.0 + + + 914.0 + 965.0 + + + + + 9 + + 10 + 90.0 + + + 534.0 + 605.0 + + + + + 7 + + 20 + 90.0 + + + 170.0 + 225.0 + + + + + 8 + + 20 + 90.0 + + + 255.0 + 324.0 + + + + + 5 + + 10 + 90.0 + + + 15.0 + 67.0 + + + + + 6 + + 20 + 90.0 + + + 621.0 + 702.0 + + + + + 3 + + 10 + 90.0 + + + 65.0 + 146.0 + + + + + 4 + + 10 + 90.0 + + + 727.0 + 782.0 + + + + + 1 + + 10 + 90.0 + + + 912.0 + 967.0 + + + + + 2 + + 30 + 90.0 + + + 825.0 + 870.0 + + + + + 11 + + 10 + 90.0 + + + 448.0 + 505.0 + + + + + 10 + + 10 + 90.0 + + + 357.0 + 410.0 + + + + + 99 + + 10 + 90.0 + + + 743.0 + 820.0 + + + + + 98 + + 20 + 90.0 + + + 30.0 + 84.0 + + + + + 97 + + 30 + 90.0 + + + 561.0 + 622.0 + + + + + 96 + + 10 + 90.0 + + + 95.0 + 156.0 + + + + + 95 + + 30 + 90.0 + + + 196.0 + 239.0 + + + + + 94 + + 10 + 90.0 + + + 285.0 + 336.0 + + + + + 93 + + 40 + 90.0 + + + 475.0 + 518.0 + + + + + 89 + + 10 + 90.0 + + + 737.0 + 802.0 + + + + + 92 + + 20 + 90.0 + + + 368.0 + 441.0 + + + + + 91 + + 10 + 90.0 + + + 836.0 + 889.0 + + + + + 90 + + 10 + 90.0 + + + 20.0 + 84.0 + + + + + 88 + + 30 + 90.0 + + + 645.0 + 708.0 + + + + + 87 + + 20 + 90.0 + + + 85.0 + 144.0 + + + + + 86 + + 10 + 90.0 + + + 173.0 + 238.0 + + + + + 85 + + 30 + 90.0 + + + 555.0 + 612.0 + + + + + 84 + + 20 + 90.0 + + + 458.0 + 523.0 + + + + + 83 + + 10 + 90.0 + + + 265.0 + 338.0 + + + + + 82 + + 20 + 90.0 + + + 369.0 + 420.0 + + + + + 81 + + 30 + 90.0 + + + 47.0 + 124.0 + + + + + 80 + + 10 + 90.0 + + + 769.0 + 820.0 + + + + + 78 + + 20 + 90.0 + + + 109.0 + 170.0 + + + + + 79 + + 10 + 90.0 + + + 668.0 + 731.0 + + + + + 69 + + 10 + 90.0 + + + 916.0 + 969.0 + + + + + 68 + + 10 + 90.0 + + + 734.0 + 777.0 + + + + + 67 + + 10 + 90.0 + + + 12.0 + 77.0 + + + + + 100 + + 20 + 90.0 + + + 647.0 + 726.0 + + + + + 72 + + 10 + 90.0 + + + 450.0 + 505.0 + + + + + 73 + + 10 + 90.0 + + + 478.0 + 551.0 + + + + + 70 + + 30 + 90.0 + + + 387.0 + 456.0 + + + + + 71 + + 20 + 90.0 + + + 293.0 + 360.0 + + + + + 76 + + 10 + 90.0 + + + 203.0 + 260.0 + + + + + 77 + + 10 + 90.0 + + + 574.0 + 643.0 + + + + + 74 + + 50 + 90.0 + + + 353.0 + 412.0 + + + + + 75 + + 20 + 90.0 + + + 997.0 + 1068.0 + + + + + 57 + + 40 + 90.0 + + + 35.0 + 87.0 + + + + + 56 + + 30 + 90.0 + + + 385.0 + 436.0 + + + + + 59 + + 10 + 90.0 + + + 651.0 + 740.0 + + + + + 58 + + 30 + 90.0 + + + 471.0 + 534.0 + + + + + 60 + + 20 + 90.0 + + + 562.0 + 629.0 + + + + + 61 + + 10 + 90.0 + + + 531.0 + 610.0 + + + + + 62 + + 20 + 90.0 + + + 262.0 + 317.0 + + + + + 63 + + 50 + 90.0 + + + 171.0 + 218.0 + + + + + 64 + + 10 + 90.0 + + + 632.0 + 693.0 + + + + + 65 + + 10 + 90.0 + + + 76.0 + 129.0 + + + + + 66 + + 10 + 90.0 + + + 826.0 + 875.0 + + + + + 49 + + 10 + 90.0 + + + 1001.0 + 1066.0 + + + + + 48 + + 10 + 90.0 + + + 632.0 + 693.0 + + + + + 47 + + 10 + 90.0 + + + 1054.0 + 1127.0 + + + + + 46 + + 30 + 90.0 + + + 448.0 + 509.0 + + + + + 45 + + 10 + 90.0 + + + 541.0 + 600.0 + + + + + 54 + + 40 + 90.0 + + + 186.0 + 257.0 + + + + + 55 + + 10 + 90.0 + + + 95.0 + 158.0 + + + + + 52 + + 10 + 90.0 + + + 912.0 + 969.0 + + + + + 53 + + 20 + 90.0 + + + 286.0 + 347.0 + + + + + 50 + + 10 + 90.0 + + + 815.0 + 880.0 + + + + + 51 + + 10 + 90.0 + + + 725.0 + 786.0 + + + + + 39 + + 20 + 90.0 + + + 567.0 + 624.0 + + + + + 38 + + 30 + 90.0 + + + 479.0 + 522.0 + + + + + 35 + + 10 + 90.0 + + + 283.0 + 344.0 + + + + + 34 + + 20 + 90.0 + + + 751.0 + 816.0 + + + + + 37 + + 20 + 90.0 + + + 383.0 + 434.0 + + + + + 36 + + 10 + 90.0 + + + 665.0 + 716.0 + + + + + 41 + + 10 + 90.0 + + + 166.0 + 235.0 + + + + + 42 + + 20 + 90.0 + + + 68.0 + 149.0 + + + + + 43 + + 10 + 90.0 + + + 16.0 + 80.0 + + + + + 44 + + 10 + 90.0 + + + 359.0 + 412.0 + + + + + 40 + + 10 + 90.0 + + + 264.0 + 321.0 + + + + + + + 7482.673139970934 + + + 370.48433957246027 + noDriver + A 0.0 - 1236.0 - - - - B - B - - 0 - - - + + 77 + 12.206555615733702 + 102.2065556157337 + + + 75 + 103.2065556157337 + 193.2065556157337 + + + 72 + 198.5917204228682 + 352.0 + + + 82 + 357.8309518948453 + 540.0 + + + 71 + 543.0 + 633.0 + + + 74 + 635.0 + 725.0 + + + 78 + 728.0 + 824.0 + + + 76 + 829.3851648071345 + 919.3851648071345 + + + 79 + 921.3851648071345 + 1011.3851648071345 + + 1027.1965531079763 + + + 360.9658621457393 + noDriver + A 0.0 - 1236.0 - - - - C - C - - 0 - - - + + 73 + 14.142135623730951 + 261.0 + + + 84 + 266.8309518948453 + 443.0 + + 462.8494332412792 + + + 336.11724276862367 + noDriver + A 0.0 - 1236.0 - - - - - - A - 100 - - 300.0 - 1.0 - - - - - B - 200 - - 800.0 - 1.0 - - - - - C - 300 - - 1350.0 - 1.0 - - - - - - - 25 - - 40 - 90.0 - - - 169.0 - 224.0 - - - - - 26 - - 10 - 90.0 - - - 622.0 - 701.0 - - - - - 23 - - 10 - 90.0 - - - 732.0 - 777.0 - - - - - 24 - - 10 - 90.0 - - - 65.0 - 144.0 - - - - - 29 - - 10 - 90.0 - - - 358.0 - 405.0 - - - - - 27 - - 10 - 90.0 - - - 261.0 - 316.0 - - - - - 28 - - 20 - 90.0 - - - 546.0 - 593.0 - - - - - 33 - - 40 - 90.0 - - - 87.0 - 158.0 - - - - - 32 - - 30 - 90.0 - - - 31.0 - 100.0 - - - - - 31 - - 20 - 90.0 - - - 200.0 - 237.0 - - - - - 30 - - 10 - 90.0 - - - 449.0 - 504.0 - - - - - 12 - - 20 - 90.0 - - - 652.0 - 721.0 - - - - - 13 - - 30 - 90.0 - - - 30.0 - 92.0 - - - - - 14 - - 10 - 90.0 - - - 567.0 - 620.0 - - - - - 15 - - 40 - 90.0 - - - 384.0 - 429.0 - - - - - 16 - - 40 - 90.0 - - - 475.0 - 528.0 - - - - - 17 - - 20 - 90.0 - - - 99.0 - 148.0 - - - - - 18 - - 20 - 90.0 - - - 179.0 - 254.0 - - - - - 19 - - 10 - 90.0 - - - 278.0 - 345.0 - - - - - 20 - - 10 - 90.0 - - - 10.0 - 73.0 - - - - - 22 - - 20 - 90.0 - - - 812.0 - 883.0 - - - - - 21 - - 20 - 90.0 - - - 914.0 - 965.0 - - - - - 9 - - 10 - 90.0 - - - 534.0 - 605.0 - - - - - 7 - - 20 - 90.0 - - - 170.0 - 225.0 - - - - - 8 - - 20 - 90.0 - - - 255.0 - 324.0 - - - - - 5 - - 10 - 90.0 - - - 15.0 - 67.0 - - - - - 6 - - 20 - 90.0 - - - 621.0 - 702.0 - - - - - 3 - - 10 - 90.0 - - - 65.0 - 146.0 - - - - - 4 - - 10 - 90.0 - - - 727.0 - 782.0 - - - - - 1 - - 10 - 90.0 - - - 912.0 - 967.0 - - - - - 2 - - 30 - 90.0 - - - 825.0 - 870.0 - - - - - 11 - - 10 - 90.0 - - - 448.0 - 505.0 - - - - - 10 - - 10 - 90.0 - - - 357.0 - 410.0 - - - - - 99 - - 10 - 90.0 - - - 743.0 - 820.0 - - - - - 98 - - 20 - 90.0 - - - 30.0 - 84.0 - - - - - 97 - - 30 - 90.0 - - - 561.0 - 622.0 - - - - - 96 - - 10 - 90.0 - - - 95.0 - 156.0 - - - - - 95 - - 30 - 90.0 - - - 196.0 - 239.0 - - - - - 94 - - 10 - 90.0 - - - 285.0 - 336.0 - - - - - 93 - - 40 - 90.0 - - - 475.0 - 518.0 - - - - - 89 - - 10 - 90.0 - - - 737.0 - 802.0 - - - - - 92 - - 20 - 90.0 - - - 368.0 - 441.0 - - - - - 91 - - 10 - 90.0 - - - 836.0 - 889.0 - - - - - 90 - - 10 - 90.0 - - - 20.0 - 84.0 - - - - - 88 - - 30 - 90.0 - - - 645.0 - 708.0 - - - - - 87 - - 20 - 90.0 - - - 85.0 - 144.0 - - - - - 86 - - 10 - 90.0 - - - 173.0 - 238.0 - - - - - 85 - - 30 - 90.0 - - - 555.0 - 612.0 - - - - - 84 - - 20 - 90.0 - - - 458.0 - 523.0 - - - - - 83 - - 10 - 90.0 - - - 265.0 - 338.0 - - - - - 82 - - 20 - 90.0 - - - 369.0 - 420.0 - - - - - 81 - - 30 - 90.0 - - - 47.0 - 124.0 - - - - - 80 - - 10 - 90.0 - - - 769.0 - 820.0 - - - - - 78 - - 20 - 90.0 - - - 109.0 - 170.0 - - - - - 79 - - 10 - 90.0 - - - 668.0 - 731.0 - - - - - 69 - - 10 - 90.0 - - - 916.0 - 969.0 - - - - - 68 - - 10 - 90.0 - - - 734.0 - 777.0 - - - - - 67 - - 10 - 90.0 - - - 12.0 - 77.0 - - - - - 100 - - 20 - 90.0 - - - 647.0 - 726.0 - - - - - 72 - - 10 - 90.0 - - - 450.0 - 505.0 - - - - - 73 - - 10 - 90.0 - - - 478.0 - 551.0 - - - - - 70 - - 30 - 90.0 - - - 387.0 - 456.0 - - - - - 71 - - 20 - 90.0 - - - 293.0 - 360.0 - - - - - 76 - - 10 - 90.0 - - - 203.0 - 260.0 - - - - - 77 - - 10 - 90.0 - - - 574.0 - 643.0 - - - - - 74 - - 50 - 90.0 - - - 353.0 - 412.0 - - - - - 75 - - 20 - 90.0 - - - 997.0 - 1068.0 - - - - - 57 - - 40 - 90.0 - - - 35.0 - 87.0 - - - - - 56 - - 30 - 90.0 - - - 385.0 - 436.0 - - - - - 59 - - 10 - 90.0 - - - 651.0 - 740.0 - - - - - 58 - - 30 - 90.0 - - - 471.0 - 534.0 - - - - - 60 - - 20 - 90.0 - - - 562.0 - 629.0 - - - - - 61 - - 10 - 90.0 - - - 531.0 - 610.0 - - - - - 62 - - 20 - 90.0 - - - 262.0 - 317.0 - - - - - 63 - - 50 - 90.0 - - - 171.0 - 218.0 - - - - - 64 - - 10 - 90.0 - - - 632.0 - 693.0 - - - - - 65 - - 10 - 90.0 - - - 76.0 - 129.0 - - - - - 66 - - 10 - 90.0 - - - 826.0 - 875.0 - - - - - 49 - - 10 - 90.0 - - - 1001.0 - 1066.0 - - - - - 48 - - 10 - 90.0 - - - 632.0 - 693.0 - - - - - 47 - - 10 - 90.0 - - - 1054.0 - 1127.0 - - - - - 46 - - 30 - 90.0 - - - 448.0 - 509.0 - - - - - 45 - - 10 - 90.0 - - - 541.0 - 600.0 - - - - - 54 - - 40 - 90.0 - - - 186.0 - 257.0 - - - - - 55 - - 10 - 90.0 - - - 95.0 - 158.0 - - - - - 52 - - 10 - 90.0 - - - 912.0 - 969.0 - - - - - 53 - - 20 - 90.0 - - - 286.0 - 347.0 - - - - - 50 - - 10 - 90.0 - - - 815.0 - 880.0 - - - - - 51 - - 10 - 90.0 - - - 725.0 - 786.0 - - - - - 39 - - 20 - 90.0 - - - 567.0 - 624.0 - - - - - 38 - - 30 - 90.0 - - - 479.0 - 522.0 - - - - - 35 - - 10 - 90.0 - - - 283.0 - 344.0 - - - - - 34 - - 20 - 90.0 - - - 751.0 - 816.0 - - - - - 37 - - 20 - 90.0 - - - 383.0 - 434.0 - - - - - 36 - - 10 - 90.0 - - - 665.0 - 716.0 - - - - - 41 - - 10 - 90.0 - - - 166.0 - 235.0 - - - - - 42 - - 20 - 90.0 - - - 68.0 - 149.0 - - - - - 43 - - 10 - 90.0 - - - 16.0 - 80.0 - - - - - 44 - - 10 - 90.0 - - - 359.0 - 412.0 - - - - - 40 - - 10 - 90.0 - - - 264.0 - 321.0 - - - - - - - 7482.673139970934 - - - 370.48433957246027 - noDriver - A - 0.0 - - 77 - 12.206555615733702 - 102.2065556157337 - - - 75 - 103.2065556157337 - 193.2065556157337 - - - 72 - 198.5917204228682 - 352.0 - - - 82 - 357.8309518948453 - 540.0 - - - 71 - 543.0 - 633.0 - - - 74 - 635.0 - 725.0 - - - 78 - 728.0 - 824.0 - - - 76 - 829.3851648071345 - 919.3851648071345 - - - 79 - 921.3851648071345 - 1011.3851648071345 - - 1027.1965531079763 - - - 360.9658621457393 - noDriver - A - 0.0 - - 73 - 14.142135623730951 - 261.0 - - - 84 - 266.8309518948453 - 443.0 - - 462.8494332412792 - - - 336.11724276862367 - noDriver - A - 0.0 - - 30 - 10.0 - 100.0 - - - 34 - 105.0 - 195.0 - - - 35 - 197.0 - 287.0 - - - 37 - 289.0 - 379.0 - - 396.11724276862367 - - - 396.97072464514815 - noDriver - A - 0.0 - - 67 - 35.0 - 125.0 - - - 64 - 130.38516480713452 - 276.0 - - - 63 - 281.3851648071345 - 376.0 - - 421.1774279923061 - - - 420.72702457661836 - noDriver - A - 0.0 - - 65 - 35.05709628591621 - 185.0 - - - 66 - 195.19803902718556 - 475.0 - - - 68 - 477.0 - 567.0 - - - 70 - 570.0 - 660.0 - - - 69 - 670.4403065089106 - 760.4403065089106 - - 795.4974027948268 - - - 382.09803902718556 - noDriver - A - 0.0 - - 39 - 20.0 - 448.0 - - - 40 - 453.0 - 543.0 - - - 38 - 546.0 - 636.0 - - - 36 - 638.0 - 728.0 - - - 33 - 731.0 - 822.0 - - - 32 - 825.0 - 915.0 - - - 31 - 917.0 - 1007.0 - - 1017.1980390271856 - - - 382.08680693813784 - noDriver - A - 0.0 - - 42 - 31.622776601683793 - 121.6227766016838 - - - 43 - 123.6227766016838 - 213.6227766016838 - - - 41 - 219.0079414088183 - 309.0079414088183 - - - 45 - 314.0079414088183 - 404.0079414088183 - - 442.08680693813784 - - - 421.4526583493026 - noDriver - A - 0.0 - - 47 - 39.293765408777 - 473.0 - - - 48 - 475.0 - 569.0 - - - 49 - 574.0 - 664.0 - - - 46 - 669.0 - 759.0 - - - 44 - 762.0 - 852.0 - - 884.3882694814033 - - - 396.9751783773217 - noDriver - A - 0.0 - - 108 - 30.805843601498726 - 120.80584360149872 - - - 106 - 126.19100840863322 - 216.19100840863322 - - - 104 - 221.57617321576774 - 375.0 - - - 102 - 378.605551275464 - 468.605551275464 - - - 103 - 470.605551275464 - 565.0 - - 608.0116263352131 - - - 442.4061783214535 - noDriver - A - 0.0 - - 86 - 52.20153254455275 - 293.0 - - - 81 - 298.0 - 388.0 - - - 80 - 393.0 - 483.0 - - - 83 - 486.0 - 576.0 - - - 87 - 580.0 - 670.0 - - - 89 - 671.0 - 761.0 - - - 90 - 766.3851648071345 - 859.0 - - 910.478150704935 - - - 348.0936045857849 - noDriver - A - 0.0 - - 53 - 16.55294535724685 - 106.55294535724684 - - - 52 - 109.55294535724684 - 199.55294535724684 - - - 51 - 201.55294535724684 - 291.5529453572468 - - - 50 - 293.5529453572468 - 383.5529453572468 - - - 54 - 386.5529453572468 - 476.5529453572468 - - 498.0936045857848 - - - 398.9184017049979 - noDriver - A - 0.0 - - 56 - 20.591260281974 - 538.0 - - - 55 - 540.0 - 631.0 - - - 58 - 633.0 - 723.0 - - - 61 - 726.0 - 816.0 - - - 60 - 818.2360679774998 - 908.2360679774998 - - - 62 - 911.3983456376682 - 1002.0 - - - 59 - 1005.0 - 1095.0 - - - 57 - 1097.0 - 1187.0 - - 1205.02775637732 - - - 390.48077199598873 - noDriver - A - 0.0 - - 23 - 30.805843601498726 - 120.80584360149872 - - - 28 - 127.80584360149872 - 269.0 - - - 29 - 274.0 - 368.0 - - - 25 - 373.0 - 474.0 - - 510.0555127546399 - - - 440.799048628923 - noDriver - A - 0.0 - - 27 - 33.301651610693426 - 189.0 - - - 26 - 199.19803902718556 - 565.0 - - - 24 - 567.0 - 657.0 - - - 22 - 660.0 - 750.0 - - - 109 - 780.4138126514911 - 870.4138126514911 - - 903.9548323139879 - - - 417.70181023477153 - noDriver - A - 0.0 - - 91 - 47.43416490252569 - 137.43416490252568 - - - 88 - 140.43416490252568 - 230.43416490252568 - - - 93 - 256.0466618522571 - 355.0 - - - 92 - 358.0 - 459.0 - - - 94 - 464.8309518948453 - 554.8309518948454 - - 585.8793012873655 - - - 347.21360705502025 - noDriver - A - 0.0 - - 15 - 15.132745950421556 - 105.13274595042155 - - - 13 - 106.13274595042155 - 196.13274595042157 - - - 17 - 198.13274595042157 - 288.13274595042157 - - - 18 - 290.9611730751678 - 380.9611730751678 - - - 20 - 384.5667243506318 - 474.5667243506318 - - - 21 - 477.5667243506318 - 567.5667243506318 - - 587.2136070550204 - - - 398.51014755711293 - noDriver - A - 0.0 - - 19 - 20.09975124224178 - 624.0 - - - 16 - 626.2360679774998 - 716.2360679774998 - - - 14 - 718.4721359549997 - 817.0 - - - 12 - 820.605551275464 - 915.0 - - - 11 - 917.0 - 1007.0 - - - 85 - 1010.0 - 1100.0 - - 1115.8113883008418 - - - 386.9734483703083 - noDriver - A - 0.0 - - 100 - 20.615528128088304 - 110.6155281280883 - - - 97 - 115.6155281280883 - 205.6155281280883 - - - 96 - 206.6155281280883 - 296.6155281280883 - - - 95 - 302.0006929352228 - 645.0 - - - 98 - 648.0 - 738.0 - - 764.9258240356726 - - - 443.6982451160345 - noDriver - A - 0.0 - - 105 - 37.20215047547655 - 286.0 - - - 107 - 291.3851648071345 - 651.0 - - - 110 - 656.0 - 746.0 - - - 99 - 774.1602556806574 - 864.1602556806574 - - - 101 - 867.7658069561214 - 957.7658069561214 - - 980.1264867311194 - - - - + + 30 + 10.0 + 100.0 + + + 34 + 105.0 + 195.0 + + + 35 + 197.0 + 287.0 + + + 37 + 289.0 + 379.0 + + 396.11724276862367 + + + 396.97072464514815 + noDriver + A + 0.0 + + 67 + 35.0 + 125.0 + + + 64 + 130.38516480713452 + 276.0 + + + 63 + 281.3851648071345 + 376.0 + + 421.1774279923061 + + + 420.72702457661836 + noDriver + A + 0.0 + + 65 + 35.05709628591621 + 185.0 + + + 66 + 195.19803902718556 + 475.0 + + + 68 + 477.0 + 567.0 + + + 70 + 570.0 + 660.0 + + + 69 + 670.4403065089106 + 760.4403065089106 + + 795.4974027948268 + + + 382.09803902718556 + noDriver + A + 0.0 + + 39 + 20.0 + 448.0 + + + 40 + 453.0 + 543.0 + + + 38 + 546.0 + 636.0 + + + 36 + 638.0 + 728.0 + + + 33 + 731.0 + 822.0 + + + 32 + 825.0 + 915.0 + + + 31 + 917.0 + 1007.0 + + 1017.1980390271856 + + + 382.08680693813784 + noDriver + A + 0.0 + + 42 + 31.622776601683793 + 121.6227766016838 + + + 43 + 123.6227766016838 + 213.6227766016838 + + + 41 + 219.0079414088183 + 309.0079414088183 + + + 45 + 314.0079414088183 + 404.0079414088183 + + 442.08680693813784 + + + 421.4526583493026 + noDriver + A + 0.0 + + 47 + 39.293765408777 + 473.0 + + + 48 + 475.0 + 569.0 + + + 49 + 574.0 + 664.0 + + + 46 + 669.0 + 759.0 + + + 44 + 762.0 + 852.0 + + 884.3882694814033 + + + 396.9751783773217 + noDriver + A + 0.0 + + 108 + 30.805843601498726 + 120.80584360149872 + + + 106 + 126.19100840863322 + 216.19100840863322 + + + 104 + 221.57617321576774 + 375.0 + + + 102 + 378.605551275464 + 468.605551275464 + + + 103 + 470.605551275464 + 565.0 + + 608.0116263352131 + + + 442.4061783214535 + noDriver + A + 0.0 + + 86 + 52.20153254455275 + 293.0 + + + 81 + 298.0 + 388.0 + + + 80 + 393.0 + 483.0 + + + 83 + 486.0 + 576.0 + + + 87 + 580.0 + 670.0 + + + 89 + 671.0 + 761.0 + + + 90 + 766.3851648071345 + 859.0 + + 910.478150704935 + + + 348.0936045857849 + noDriver + A + 0.0 + + 53 + 16.55294535724685 + 106.55294535724684 + + + 52 + 109.55294535724684 + 199.55294535724684 + + + 51 + 201.55294535724684 + 291.5529453572468 + + + 50 + 293.5529453572468 + 383.5529453572468 + + + 54 + 386.5529453572468 + 476.5529453572468 + + 498.0936045857848 + + + 398.9184017049979 + noDriver + A + 0.0 + + 56 + 20.591260281974 + 538.0 + + + 55 + 540.0 + 631.0 + + + 58 + 633.0 + 723.0 + + + 61 + 726.0 + 816.0 + + + 60 + 818.2360679774998 + 908.2360679774998 + + + 62 + 911.3983456376682 + 1002.0 + + + 59 + 1005.0 + 1095.0 + + + 57 + 1097.0 + 1187.0 + + 1205.02775637732 + + + 390.48077199598873 + noDriver + A + 0.0 + + 23 + 30.805843601498726 + 120.80584360149872 + + + 28 + 127.80584360149872 + 269.0 + + + 29 + 274.0 + 368.0 + + + 25 + 373.0 + 474.0 + + 510.0555127546399 + + + 440.799048628923 + noDriver + A + 0.0 + + 27 + 33.301651610693426 + 189.0 + + + 26 + 199.19803902718556 + 565.0 + + + 24 + 567.0 + 657.0 + + + 22 + 660.0 + 750.0 + + + 109 + 780.4138126514911 + 870.4138126514911 + + 903.9548323139879 + + + 417.70181023477153 + noDriver + A + 0.0 + + 91 + 47.43416490252569 + 137.43416490252568 + + + 88 + 140.43416490252568 + 230.43416490252568 + + + 93 + 256.0466618522571 + 355.0 + + + 92 + 358.0 + 459.0 + + + 94 + 464.8309518948453 + 554.8309518948454 + + 585.8793012873655 + + + 347.21360705502025 + noDriver + A + 0.0 + + 15 + 15.132745950421556 + 105.13274595042155 + + + 13 + 106.13274595042155 + 196.13274595042157 + + + 17 + 198.13274595042157 + 288.13274595042157 + + + 18 + 290.9611730751678 + 380.9611730751678 + + + 20 + 384.5667243506318 + 474.5667243506318 + + + 21 + 477.5667243506318 + 567.5667243506318 + + 587.2136070550204 + + + 398.51014755711293 + noDriver + A + 0.0 + + 19 + 20.09975124224178 + 624.0 + + + 16 + 626.2360679774998 + 716.2360679774998 + + + 14 + 718.4721359549997 + 817.0 + + + 12 + 820.605551275464 + 915.0 + + + 11 + 917.0 + 1007.0 + + + 85 + 1010.0 + 1100.0 + + 1115.8113883008418 + + + 386.9734483703083 + noDriver + A + 0.0 + + 100 + 20.615528128088304 + 110.6155281280883 + + + 97 + 115.6155281280883 + 205.6155281280883 + + + 96 + 206.6155281280883 + 296.6155281280883 + + + 95 + 302.0006929352228 + 645.0 + + + 98 + 648.0 + 738.0 + + 764.9258240356726 + + + 443.6982451160345 + noDriver + A + 0.0 + + 105 + 37.20215047547655 + 286.0 + + + 107 + 291.3851648071345 + 651.0 + + + 110 + 656.0 + 746.0 + + + 99 + 774.1602556806574 + 864.1602556806574 + + + 101 + 867.7658069561214 + 957.7658069561214 + + 980.1264867311194 + + + + diff --git a/jsprit-core/src/test/resources/matrix.txt b/jsprit-core/src/test/resources/matrix.txt new file mode 100644 index 00000000..b531634c --- /dev/null +++ b/jsprit-core/src/test/resources/matrix.txt @@ -0,0 +1,121 @@ +0 0 0.0 0.0 +0 1 7641.0 394.0 +0 2 7244.0 370.0 +0 3 15236.0 747.0 +0 4 7841.0 452.0 +0 5 7013.0 388.0 +0 6 3336.0 232.0 +0 7 6729.0 364.0 +0 8 22401.0 918.0 +0 9 16830.0 772.0 +0 10 8311.0 434.0 +1 0 7463.0 381.0 +1 1 0.0 0.0 +1 2 1605.0 90.0 +1 3 8336.0 380.0 +1 4 4949.0 304.0 +1 5 3632.0 221.0 +1 6 5611.0 324.0 +1 7 3407.0 212.0 +1 8 29674.0 1216.0 +1 9 9378.0 513.0 +1 10 633.0 42.0 +2 0 5857.0 291.0 +2 1 1366.0 78.0 +2 2 0.0 0.0 +2 3 8961.0 431.0 +2 4 5346.0 325.0 +2 5 1994.0 144.0 +2 6 4006.0 234.0 +2 7 1802.0 122.0 +2 8 28069.0 1126.0 +2 9 9809.0 536.0 +2 10 2035.0 118.0 +3 0 15179.0 645.0 +3 1 7322.0 329.0 +3 2 7534.0 364.0 +3 3 0.0 0.0 +3 4 10908.0 483.0 +3 5 9605.0 470.0 +3 6 13327.0 588.0 +3 7 9336.0 486.0 +3 8 36409.0 1438.0 +3 9 4130.0 236.0 +3 10 6404.0 321.0 +4 0 7652.0 457.0 +4 1 4611.0 288.0 +4 2 4948.0 303.0 +4 3 10982.0 539.0 +4 4 0.0 0.0 +4 5 6942.0 447.0 +4 6 6199.0 415.0 +4 7 6750.0 425.0 +4 8 29970.0 1270.0 +4 9 10932.0 566.0 +4 10 4384.0 277.0 +5 0 4845.0 284.0 +5 1 3010.0 187.0 +5 2 2612.0 163.0 +5 3 10784.0 530.0 +5 4 6990.0 435.0 +5 5 0.0 0.0 +5 6 2964.0 219.0 +5 7 819.0 68.0 +5 8 27332.0 1124.0 +5 9 13064.0 615.0 +5 10 3679.0 227.0 +6 0 2952.0 209.0 +6 1 5089.0 297.0 +6 2 4691.0 273.0 +6 3 12684.0 650.0 +6 4 6489.0 430.0 +6 5 4460.0 291.0 +6 6 0.0 0.0 +6 7 4176.0 267.0 +6 8 25472.0 1083.0 +6 9 14278.0 675.0 +6 10 5758.0 337.0 +7 0 4334.0 253.0 +7 1 2956.0 182.0 +7 2 2559.0 158.0 +7 3 10551.0 535.0 +7 4 6936.0 429.0 +7 5 2081.0 162.0 +7 6 2453.0 188.0 +7 7 0.0 0.0 +7 8 26821.0 1092.0 +7 9 13010.0 610.0 +7 10 3625.0 222.0 +8 0 22667.0 926.0 +8 1 29281.0 1189.0 +8 2 28884.0 1165.0 +8 3 37504.0 1484.0 +8 4 29608.0 1240.0 +8 5 28008.0 1174.0 +8 6 25198.0 1063.0 +8 7 27518.0 1151.0 +8 8 0.0 0.0 +8 9 36799.0 1529.0 +8 10 29950.0 1230.0 +9 0 15604.0 722.0 +9 1 8945.0 492.0 +9 2 9283.0 507.0 +9 3 3730.0 212.0 +9 4 11018.0 594.0 +9 5 12864.0 633.0 +9 6 13753.0 665.0 +9 7 12558.0 607.0 +9 8 36821.0 1553.0 +9 9 0.0 0.0 +9 10 8307.0 472.0 +10 0 7591.0 404.0 +10 1 1117.0 81.0 +10 2 1733.0 113.0 +10 3 7844.0 354.0 +10 4 5077.0 327.0 +10 5 3914.0 243.0 +10 6 5739.0 347.0 +10 7 3535.0 235.0 +10 8 29802.0 1239.0 +10 9 8906.0 493.0 +10 10 0.0 0.0 diff --git a/jsprit-core/src/test/resources/pdVRP_vrpnc1_jsprit.xml b/jsprit-core/src/test/resources/pdVRP_vrpnc1_jsprit.xml index d35d0432..1f2cb0aa 100644 --- a/jsprit-core/src/test/resources/pdVRP_vrpnc1_jsprit.xml +++ b/jsprit-core/src/test/resources/pdVRP_vrpnc1_jsprit.xml @@ -1,635 +1,636 @@ - - INFINITE - HOMOGENEOUS - - - - christophidesVehicle - christophidesType - - [x=30.0][y=40.0] - - - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.w3schools.com vrp_xml_schema.xsd"> + + INFINITE + HOMOGENEOUS + + + + christophidesVehicle + christophidesType + + [x=30.0][y=40.0] + + + + 0.0 + 999999.0 + + + + + + christophidesType + 50 + + 0.0 + 1.0 + + + + + + + [x=62.0][y=63.0] + + 17 + 0.0 + + 0.0 - 999999.0 - - - - - - christophidesType - 50 - - 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 - - - - + 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-core/src/test/resources/pd_solomon_c101_sol.xml b/jsprit-core/src/test/resources/pd_solomon_c101_sol.xml index d19bd54c..0548472e 100644 --- a/jsprit-core/src/test/resources/pd_solomon_c101_sol.xml +++ b/jsprit-core/src/test/resources/pd_solomon_c101_sol.xml @@ -1,3612 +1,3613 @@ - - INFINITE - HOMOGENEOUS - - - - solomonVehicle - solomonType - - 0 - - - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.w3schools.com vrp_xml_schema.xsd"> + + INFINITE + HOMOGENEOUS + + + + solomonVehicle + solomonType + + 0 + + + + 0.0 + 1236.0 + + + + + + solomonType + 200 + + 0.0 + 1.0 + + + + + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=5.0][y=35.0] + + 0.0 + + + 283.0 + 344.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=5.0][y=45.0] + + 0.0 + + + 665.0 + 716.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=8.0][y=40.0] + + 0.0 + + + 87.0 + 158.0 + + + + 40 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=8.0][y=45.0] + + 0.0 + + + 751.0 + 816.0 + + + + 20 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=0.0][y=45.0] + + 0.0 + + + 567.0 + 624.0 + + + + 20 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=2.0][y=40.0] + + 0.0 + + + 383.0 + 434.0 + + + + 20 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=0.0][y=40.0] + + 0.0 + + + 479.0 + 522.0 + + + + 30 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=33.0][y=35.0] + + 0.0 + + + 16.0 + 80.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=33.0][y=32.0] + + 0.0 + + + 68.0 + 149.0 + + + + 20 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=35.0][y=32.0] + + 0.0 + + + 166.0 + 235.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=35.0][y=30.0] + + 0.0 + + + 264.0 + 321.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=28.0][y=52.0] + + 0.0 + + + 812.0 + 883.0 + + + + 20 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=28.0][y=55.0] + + 0.0 + + + 732.0 + 777.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=25.0][y=50.0] + + 0.0 + + + 65.0 + 144.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=25.0][y=52.0] + + 0.0 + + + 169.0 + 224.0 + + + + 40 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=25.0][y=55.0] + + 0.0 + + + 622.0 + 701.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=23.0][y=52.0] + + 0.0 + + + 261.0 + 316.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=23.0][y=55.0] + + 0.0 + + + 546.0 + 593.0 + + + + 20 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=20.0][y=50.0] + + 0.0 + + + 358.0 + 405.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=42.0][y=66.0] + + 0.0 + + + 65.0 + 146.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=45.0][y=70.0] + + 0.0 + + + 825.0 + 870.0 + + + + 30 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=45.0][y=68.0] + + 0.0 + + + 912.0 + 967.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=20.0][y=55.0] + + 0.0 + + + 449.0 + 504.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=40.0][y=66.0] + + 0.0 + + + 170.0 + 225.0 + + + + 20 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=40.0][y=69.0] + + 0.0 + + + 621.0 + 702.0 + + + + 20 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=10.0][y=40.0] + + 0.0 + + + 31.0 + 100.0 + + + + 30 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=42.0][y=65.0] + + 0.0 + + + 15.0 + 67.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=10.0][y=35.0] + + 0.0 + + + 200.0 + 237.0 + + + + 20 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=42.0][y=68.0] + + 0.0 + + + 727.0 + 782.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=38.0][y=70.0] + + 0.0 + + + 534.0 + 605.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=38.0][y=68.0] + + 0.0 + + + 255.0 + 324.0 + + + + 20 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=15.0][y=80.0] + + 0.0 + + + 278.0 + 345.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=18.0][y=75.0] + + 0.0 + + + 99.0 + 148.0 + + + + 20 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=15.0][y=75.0] + + 0.0 + + + 179.0 + 254.0 + + + + 20 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=20.0][y=80.0] + + 0.0 + + + 384.0 + 429.0 + + + + 40 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=20.0][y=85.0] + + 0.0 + + + 475.0 + 528.0 + + + + 40 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=22.0][y=75.0] + + 0.0 + + + 30.0 + 92.0 + + + + 30 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=22.0][y=85.0] + + 0.0 + + + 567.0 + 620.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=35.0][y=69.0] + + 0.0 + + + 448.0 + 505.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=25.0][y=85.0] + + 0.0 + + + 652.0 + 721.0 + + + + 20 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=30.0][y=52.0] + + 0.0 + + + 914.0 + 965.0 + + + + 20 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=30.0][y=50.0] + + 0.0 + + + 10.0 + 73.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=55.0][y=80.0] + + 0.0 + + + 743.0 + 820.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=55.0][y=85.0] + + 0.0 + + + 647.0 + 726.0 + + + + 20 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=58.0][y=75.0] + + 0.0 + + + 30.0 + 84.0 + + + + 20 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=60.0][y=85.0] + + 0.0 + + + 561.0 + 622.0 + + + + 30 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=60.0][y=80.0] + + 0.0 + + + 95.0 + 156.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=62.0][y=80.0] + + 0.0 + + + 196.0 + 239.0 + + + + 30 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=65.0][y=82.0] + + 0.0 + + + 285.0 + 336.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=65.0][y=85.0] + + 0.0 + + + 475.0 + 518.0 + + + + 40 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=67.0][y=85.0] + + 0.0 + + + 368.0 + 441.0 + + + + 20 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=60.0][y=60.0] + + 0.0 + + + 836.0 + 889.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=60.0][y=55.0] + + 0.0 + + + 20.0 + 84.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=35.0][y=66.0] + + 0.0 + + + 357.0 + 410.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=65.0][y=60.0] + + 0.0 + + + 645.0 + 708.0 + + + + 30 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=63.0][y=58.0] + + 0.0 + + + 737.0 + 802.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=87.0][y=30.0] + + 0.0 + + + 668.0 + 731.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=88.0][y=35.0] + + 0.0 + + + 109.0 + 170.0 + + + + 20 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=88.0][y=30.0] + + 0.0 + + + 574.0 + 643.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=75.0][y=55.0] + + 0.0 + + + 369.0 + 420.0 + + + + 20 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=72.0][y=55.0] + + 0.0 + + + 265.0 + 338.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=85.0][y=25.0] + + 0.0 + + + 769.0 + 820.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=85.0][y=35.0] + + 0.0 + + + 47.0 + 124.0 + + + + 30 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=66.0][y=55.0] + + 0.0 + + + 173.0 + 238.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=65.0][y=55.0] + + 0.0 + + + 85.0 + 144.0 + + + + 20 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=70.0][y=58.0] + + 0.0 + + + 458.0 + 523.0 + + + + 20 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=68.0][y=60.0] + + 0.0 + + + 555.0 + 612.0 + + + + 30 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=47.0][y=40.0] + + 0.0 + + + 12.0 + 77.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=47.0][y=35.0] + + 0.0 + + + 826.0 + 875.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=45.0][y=35.0] + + 0.0 + + + 916.0 + 969.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=45.0][y=30.0] + + 0.0 + + + 734.0 + 777.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=95.0][y=30.0] + + 0.0 + + + 387.0 + 456.0 + + + + 30 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=95.0][y=35.0] + + 0.0 + + + 293.0 + 360.0 + + + + 20 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=53.0][y=30.0] + + 0.0 + + + 450.0 + 505.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=92.0][y=30.0] + + 0.0 + + + 478.0 + 551.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=53.0][y=35.0] + + 0.0 + + + 353.0 + 412.0 + + + + 50 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=45.0][y=65.0] + + 0.0 + + + 997.0 + 1068.0 + + + + 20 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=90.0][y=35.0] + + 0.0 + + + 203.0 + 260.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=38.0][y=15.0] + + 0.0 + + + 651.0 + 740.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=38.0][y=5.0] + + 0.0 + + + 471.0 + 534.0 + + + + 30 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=40.0][y=15.0] + + 0.0 + + + 35.0 + 87.0 + + + + 40 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=40.0][y=5.0] + + 0.0 + + + 385.0 + 436.0 + + + + 30 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=42.0][y=15.0] + + 0.0 + + + 95.0 + 158.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=48.0][y=30.0] + + 0.0 + + + 632.0 + 693.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=48.0][y=40.0] + + 0.0 + + + 76.0 + 129.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=50.0][y=35.0] + + 0.0 + + + 262.0 + 317.0 + + + + 20 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=50.0][y=40.0] + + 0.0 + + + 171.0 + 218.0 + + + + 50 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=35.0][y=5.0] + + 0.0 + + + 562.0 + 629.0 + + + + 20 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=50.0][y=30.0] + + 0.0 + + + 531.0 + 610.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=28.0][y=35.0] + + 0.0 + + + 1001.0 + 1066.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=28.0][y=30.0] + + 0.0 + + + 632.0 + 693.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=30.0][y=30.0] + + 0.0 + + + 541.0 + 600.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=32.0][y=30.0] + + 0.0 + + + 359.0 + 412.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=30.0][y=35.0] + + 0.0 + + + 1054.0 + 1127.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=30.0][y=32.0] + + 0.0 + + + 448.0 + 509.0 + + + + 30 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=25.0][y=30.0] + + 0.0 + + + 725.0 + 786.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=25.0][y=35.0] + + 0.0 + + + 912.0 + 969.0 + + + + 10 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=44.0][y=5.0] + + 0.0 + + + 286.0 + 347.0 + + + + 20 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=42.0][y=10.0] + + 0.0 + + + 186.0 + 257.0 + + + + 40 + + + + [x=40.0][y=50.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=26.0][y=32.0] + + 0.0 + + + 815.0 + 880.0 + + + + 10 + + + + + 931.4150471075089 + + + 84.4406775617744 + noDriver + solomonVehicle 0.0 - 1236.0 - - - - - - solomonType - 200 - - 0.0 - 1.0 - - - - - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=5.0][y=35.0] - - 0.0 - - - 283.0 - 344.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=5.0][y=45.0] - - 0.0 - - - 665.0 - 716.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=8.0][y=40.0] - - 0.0 - - - 87.0 - 158.0 - - - - 40 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=8.0][y=45.0] - - 0.0 - - - 751.0 - 816.0 - - - - 20 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=0.0][y=45.0] - - 0.0 - - - 567.0 - 624.0 - - - - 20 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=2.0][y=40.0] - - 0.0 - - - 383.0 - 434.0 - - - - 20 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=0.0][y=40.0] - - 0.0 - - - 479.0 - 522.0 - - - - 30 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=33.0][y=35.0] - - 0.0 - - - 16.0 - 80.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=33.0][y=32.0] - - 0.0 - - - 68.0 - 149.0 - - - - 20 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=35.0][y=32.0] - - 0.0 - - - 166.0 - 235.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=35.0][y=30.0] - - 0.0 - - - 264.0 - 321.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=28.0][y=52.0] - - 0.0 - - - 812.0 - 883.0 - - - - 20 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=28.0][y=55.0] - - 0.0 - - - 732.0 - 777.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=25.0][y=50.0] - - 0.0 - - - 65.0 - 144.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=25.0][y=52.0] - - 0.0 - - - 169.0 - 224.0 - - - - 40 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=25.0][y=55.0] - - 0.0 - - - 622.0 - 701.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=23.0][y=52.0] - - 0.0 - - - 261.0 - 316.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=23.0][y=55.0] - - 0.0 - - - 546.0 - 593.0 - - - - 20 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=20.0][y=50.0] - - 0.0 - - - 358.0 - 405.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=42.0][y=66.0] - - 0.0 - - - 65.0 - 146.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=45.0][y=70.0] - - 0.0 - - - 825.0 - 870.0 - - - - 30 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=45.0][y=68.0] - - 0.0 - - - 912.0 - 967.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=20.0][y=55.0] - - 0.0 - - - 449.0 - 504.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=40.0][y=66.0] - - 0.0 - - - 170.0 - 225.0 - - - - 20 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=40.0][y=69.0] - - 0.0 - - - 621.0 - 702.0 - - - - 20 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=10.0][y=40.0] - - 0.0 - - - 31.0 - 100.0 - - - - 30 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=42.0][y=65.0] - - 0.0 - - - 15.0 - 67.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=10.0][y=35.0] - - 0.0 - - - 200.0 - 237.0 - - - - 20 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=42.0][y=68.0] - - 0.0 - - - 727.0 - 782.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=38.0][y=70.0] - - 0.0 - - - 534.0 - 605.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=38.0][y=68.0] - - 0.0 - - - 255.0 - 324.0 - - - - 20 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=15.0][y=80.0] - - 0.0 - - - 278.0 - 345.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=18.0][y=75.0] - - 0.0 - - - 99.0 - 148.0 - - - - 20 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=15.0][y=75.0] - - 0.0 - - - 179.0 - 254.0 - - - - 20 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=20.0][y=80.0] - - 0.0 - - - 384.0 - 429.0 - - - - 40 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=20.0][y=85.0] - - 0.0 - - - 475.0 - 528.0 - - - - 40 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=22.0][y=75.0] - - 0.0 - - - 30.0 - 92.0 - - - - 30 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=22.0][y=85.0] - - 0.0 - - - 567.0 - 620.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=35.0][y=69.0] - - 0.0 - - - 448.0 - 505.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=25.0][y=85.0] - - 0.0 - - - 652.0 - 721.0 - - - - 20 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=30.0][y=52.0] - - 0.0 - - - 914.0 - 965.0 - - - - 20 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=30.0][y=50.0] - - 0.0 - - - 10.0 - 73.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=55.0][y=80.0] - - 0.0 - - - 743.0 - 820.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=55.0][y=85.0] - - 0.0 - - - 647.0 - 726.0 - - - - 20 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=58.0][y=75.0] - - 0.0 - - - 30.0 - 84.0 - - - - 20 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=60.0][y=85.0] - - 0.0 - - - 561.0 - 622.0 - - - - 30 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=60.0][y=80.0] - - 0.0 - - - 95.0 - 156.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=62.0][y=80.0] - - 0.0 - - - 196.0 - 239.0 - - - - 30 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=65.0][y=82.0] - - 0.0 - - - 285.0 - 336.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=65.0][y=85.0] - - 0.0 - - - 475.0 - 518.0 - - - - 40 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=67.0][y=85.0] - - 0.0 - - - 368.0 - 441.0 - - - - 20 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=60.0][y=60.0] - - 0.0 - - - 836.0 - 889.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=60.0][y=55.0] - - 0.0 - - - 20.0 - 84.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=35.0][y=66.0] - - 0.0 - - - 357.0 - 410.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=65.0][y=60.0] - - 0.0 - - - 645.0 - 708.0 - - - - 30 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=63.0][y=58.0] - - 0.0 - - - 737.0 - 802.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=87.0][y=30.0] - - 0.0 - - - 668.0 - 731.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=88.0][y=35.0] - - 0.0 - - - 109.0 - 170.0 - - - - 20 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=88.0][y=30.0] - - 0.0 - - - 574.0 - 643.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=75.0][y=55.0] - - 0.0 - - - 369.0 - 420.0 - - - - 20 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=72.0][y=55.0] - - 0.0 - - - 265.0 - 338.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=85.0][y=25.0] - - 0.0 - - - 769.0 - 820.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=85.0][y=35.0] - - 0.0 - - - 47.0 - 124.0 - - - - 30 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=66.0][y=55.0] - - 0.0 - - - 173.0 - 238.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=65.0][y=55.0] - - 0.0 - - - 85.0 - 144.0 - - - - 20 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=70.0][y=58.0] - - 0.0 - - - 458.0 - 523.0 - - - - 20 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=68.0][y=60.0] - - 0.0 - - - 555.0 - 612.0 - - - - 30 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=47.0][y=40.0] - - 0.0 - - - 12.0 - 77.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=47.0][y=35.0] - - 0.0 - - - 826.0 - 875.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=45.0][y=35.0] - - 0.0 - - - 916.0 - 969.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=45.0][y=30.0] - - 0.0 - - - 734.0 - 777.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=95.0][y=30.0] - - 0.0 - - - 387.0 - 456.0 - - - - 30 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=95.0][y=35.0] - - 0.0 - - - 293.0 - 360.0 - - - - 20 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=53.0][y=30.0] - - 0.0 - - - 450.0 - 505.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=92.0][y=30.0] - - 0.0 - - - 478.0 - 551.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=53.0][y=35.0] - - 0.0 - - - 353.0 - 412.0 - - - - 50 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=45.0][y=65.0] - - 0.0 - - - 997.0 - 1068.0 - - - - 20 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=90.0][y=35.0] - - 0.0 - - - 203.0 - 260.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=38.0][y=15.0] - - 0.0 - - - 651.0 - 740.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=38.0][y=5.0] - - 0.0 - - - 471.0 - 534.0 - - - - 30 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=40.0][y=15.0] - - 0.0 - - - 35.0 - 87.0 - - - - 40 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=40.0][y=5.0] - - 0.0 - - - 385.0 - 436.0 - - - - 30 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=42.0][y=15.0] - - 0.0 - - - 95.0 - 158.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=48.0][y=30.0] - - 0.0 - - - 632.0 - 693.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=48.0][y=40.0] - - 0.0 - - - 76.0 - 129.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=50.0][y=35.0] - - 0.0 - - - 262.0 - 317.0 - - - - 20 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=50.0][y=40.0] - - 0.0 - - - 171.0 - 218.0 - - - - 50 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=35.0][y=5.0] - - 0.0 - - - 562.0 - 629.0 - - - - 20 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=50.0][y=30.0] - - 0.0 - - - 531.0 - 610.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=28.0][y=35.0] - - 0.0 - - - 1001.0 - 1066.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=28.0][y=30.0] - - 0.0 - - - 632.0 - 693.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=30.0][y=30.0] - - 0.0 - - - 541.0 - 600.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=32.0][y=30.0] - - 0.0 - - - 359.0 - 412.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=30.0][y=35.0] - - 0.0 - - - 1054.0 - 1127.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=30.0][y=32.0] - - 0.0 - - - 448.0 - 509.0 - - - - 30 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=25.0][y=30.0] - - 0.0 - - - 725.0 - 786.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=25.0][y=35.0] - - 0.0 - - - 912.0 - 969.0 - - - - 10 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=44.0][y=5.0] - - 0.0 - - - 286.0 - 347.0 - - - - 20 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=42.0][y=10.0] - - 0.0 - - - 186.0 - 257.0 - - - - 40 - - - - [x=40.0][y=50.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=26.0][y=32.0] - - 0.0 - - - 815.0 - 880.0 - - - - 10 - - - - - 931.4150471075089 - - - 84.4406775617744 - noDriver - solomonVehicle - 0.0 - - 29 - 0.0 - 0.0 - - - 20 - 0.0 - 0.0 - - - 30 - 0.0 - 0.0 - - - 32 - 0.0 - 0.0 - - - 26 - 0.0 - 0.0 - - - 28 - 0.0 - 0.0 - - - 24 - 0.0 - 0.0 - - - 23 - 0.0 - 0.0 - - - 33 - 0.0 - 0.0 - - - 31 - 0.0 - 0.0 - - - 20 - 10.0 - 10.0 - - - 24 - 15.0 - 65.0 - - - 32 - 83.02775637731995 - 83.02775637731995 - - - 33 - 85.02775637731995 - 87.0 - - - 31 - 92.3851648071345 - 200.0 - - - 29 - 218.02775637731995 - 358.0 - - - 30 - 363.0 - 449.0 - - - 28 - 452.0 - 546.0 - - - 26 - 548.0 - 622.0 - - - 23 - 625.0 - 732.0 - - 745.0 - - - 95.88470913081827 - noDriver - solomonVehicle - 0.0 - - 15 - 0.0 - 0.0 - - - 12 - 0.0 - 0.0 - - - 18 - 0.0 - 0.0 - - - 14 - 0.0 - 0.0 - - - 13 - 0.0 - 0.0 - - - 16 - 0.0 - 0.0 - - - 19 - 0.0 - 0.0 - - - 17 - 0.0 - 0.0 - - - 13 - 30.805843601498726 - 30.805843601498726 - - - 17 - 34.80584360149872 - 99.0 - - - 18 - 102.0 - 179.0 - - - 19 - 184.0 - 278.0 - - - 15 - 283.0 - 384.0 - - - 16 - 389.0 - 475.0 - - - 14 - 477.0 - 567.0 - - - 12 - 570.0 - 652.0 - - 690.0788655293195 - - - 111.98098283607547 - noDriver - solomonVehicle - 0.0 - - 98 - 0.0 - 0.0 - - - 84 - 0.0 - 0.0 - - - 83 - 0.0 - 0.0 - - - 95 - 0.0 - 0.0 - - - 88 - 0.0 - 0.0 - - - 86 - 0.0 - 0.0 - - - 91 - 0.0 - 0.0 - - - 89 - 0.0 - 0.0 - - - 85 - 0.0 - 0.0 - - - 82 - 0.0 - 0.0 - - - 98 - 30.805843601498726 - 30.805843601498726 - - - 95 - 37.20896783893157 - 196.0 - - - 86 - 221.31797780234433 - 221.31797780234433 - - - 83 - 227.31797780234433 - 265.0 - - - 82 - 268.0 - 369.0 - - - 84 - 374.8309518948453 - 458.0 - - - 85 - 460.8284271247462 - 555.0 - - - 88 - 558.0 - 645.0 - - - 89 - 647.8284271247462 - 737.0 - - - 91 - 740.605551275464 - 836.0 - - 858.360679774998 - - - 56.11696343016839 - noDriver - solomonVehicle - 0.0 - - 74 - 0.0 - 0.0 - - - 65 - 0.0 - 0.0 - - - 63 - 0.0 - 0.0 - - - 66 - 0.0 - 0.0 - - - 67 - 0.0 - 0.0 - - - 64 - 0.0 - 0.0 - - - 62 - 0.0 - 0.0 - - - 69 - 0.0 - 0.0 - - - 72 - 0.0 - 0.0 - - - 61 - 0.0 - 0.0 - - - 67 - 12.206555615733702 - 12.206555615733702 - - - 65 - 13.206555615733702 - 76.0 - - - 63 - 78.0 - 171.0 - - - 62 - 176.0 - 262.0 - - - 74 - 265.0 - 353.0 - - - 72 - 358.0 - 450.0 - - - 61 - 453.0 - 531.0 - - - 64 - 533.0 - 632.0 - - - 66 - 637.0990195135928 - 826.0 - - - 69 - 828.0 - 916.0 - - 931.8113883008419 - - - 102.37910960851471 - noDriver - solomonVehicle - 0.0 - - 54 - 0.0 - 0.0 - - - 58 - 0.0 - 0.0 - - - 68 - 0.0 - 0.0 - - - 60 - 0.0 - 0.0 - - - 53 - 0.0 - 0.0 - - - 59 - 0.0 - 0.0 - - - 57 - 0.0 - 0.0 - - - 56 - 0.0 - 0.0 - - - 57 - 35.0 - 35.0 - - - 54 - 40.3851648071345 - 186.0 - - - 53 - 191.38516480713452 - 286.0 - - - 56 - 290.0 - 385.0 - - - 58 - 387.0 - 471.0 - - - 60 - 474.0 - 562.0 - - - 59 - 572.4403065089106 - 651.0 - - - 68 - 667.5529453572468 - 734.0 - - 754.6155281280883 - - - 53.31190824207452 - noDriver - solomonVehicle - 0.0 - - 8 - 0.0 - 0.0 - - - 9 - 0.0 - 0.0 - - - 10 - 0.0 - 0.0 - - - 3 - 0.0 - 0.0 - - - 7 - 0.0 - 0.0 - - - 5 - 0.0 - 0.0 - - - 11 - 0.0 - 0.0 - - - 6 - 0.0 - 0.0 - - - 4 - 0.0 - 0.0 - - - 5 - 15.132745950421556 - 15.132745950421556 - - - 3 - 16.13274595042156 - 65.0 - - - 7 - 67.0 - 170.0 - - - 8 - 172.82842712474618 - 255.0 - - - 10 - 258.605551275464 - 357.0 - - - 11 - 360.0 - 448.0 - - - 9 - 451.1622776601684 - 534.0 - - - 6 - 536.2360679774998 - 621.0 - - - 4 - 623.2360679774998 - 727.0 - - 745.1107702762748 - - - 100.42763486950274 - noDriver - solomonVehicle - 0.0 - - 55 - 0.0 - 0.0 - - - 46 - 0.0 - 0.0 - - - 44 - 0.0 - 0.0 - - - 51 - 0.0 - 0.0 - - - 40 - 0.0 - 0.0 - - - 49 - 0.0 - 0.0 - - - 48 - 0.0 - 0.0 - - - 45 - 0.0 - 0.0 - - - 42 - 0.0 - 0.0 - - - 43 - 0.0 - 0.0 - - - 47 - 0.0 - 0.0 - - - 52 - 0.0 - 0.0 - - - 41 - 0.0 - 0.0 - - - 50 - 0.0 - 0.0 - - - 43 - 16.55294535724685 - 16.55294535724685 - - - 42 - 19.55294535724685 - 68.0 - - - 55 - 87.23538406167134 - 95.0 - - - 41 - 113.38477631085024 - 166.0 - - - 40 - 168.0 - 264.0 - - - 44 - 267.0 - 359.0 - - - 46 - 361.8284271247462 - 448.0 - - - 45 - 450.0 - 541.0 - - - 48 - 543.0 - 632.0 - - - 51 - 635.0 - 725.0 - - - 50 - 727.2360679774998 - 815.0 - - - 52 - 818.1622776601683 - 912.0 - - - 49 - 915.0 - 1001.0 - - - 47 - 1003.0 - 1054.0 - - 1072.02775637732 - - - 133.7631148876197 - noDriver - solomonVehicle - 0.0 - - 87 - 0.0 - 0.0 - - - 79 - 0.0 - 0.0 - - - 77 - 0.0 - 0.0 - - - 81 - 0.0 - 0.0 - - - 76 - 0.0 - 0.0 - - - 90 - 0.0 - 0.0 - - - 78 - 0.0 - 0.0 - - - 80 - 0.0 - 0.0 - - - 73 - 0.0 - 0.0 - - - 71 - 0.0 - 0.0 - - - 70 - 0.0 - 0.0 - - - 90 - 20.615528128088304 - 20.615528128088304 - - - 87 - 25.615528128088304 - 85.0 - - - 81 - 113.2842712474619 - 113.2842712474619 - - - 78 - 116.2842712474619 - 116.2842712474619 - - - 76 - 118.2842712474619 - 203.0 - - - 71 - 208.0 - 293.0 - - - 70 - 298.0 - 387.0 - - - 73 - 390.0 - 478.0 - - - 77 - 482.0 - 574.0 - - - 79 - 575.0 - 668.0 - - - 80 - 673.3851648071345 - 769.0 - - 820.478150704935 - - - 96.99975276181122 - noDriver - solomonVehicle - 0.0 - - 75 - 0.0 - 0.0 - - - 96 - 0.0 - 0.0 - - - 93 - 0.0 - 0.0 - - - 94 - 0.0 - 0.0 - - - 1 - 0.0 - 0.0 - - - 99 - 0.0 - 0.0 - - - 100 - 0.0 - 0.0 - - - 97 - 0.0 - 0.0 - - - 2 - 0.0 - 0.0 - - - 92 - 0.0 - 0.0 - - - 96 - 36.05551275463989 - 95.0 - - - 94 - 100.3851648071345 - 285.0 - - - 92 - 288.605551275464 - 368.0 - - - 93 - 370.0 - 475.0 - - - 97 - 480.0 - 561.0 - - - 100 - 566.0 - 647.0 - - - 99 - 652.0 - 743.0 - - - 2 - 757.142135623731 - 825.0 - - - 1 - 827.0 - 912.0 - - - 75 - 915.0 - 997.0 - - 1012.8113883008419 - - - 96.11019377914941 - noDriver - solomonVehicle - 0.0 - - 36 - 0.0 - 0.0 - - - 35 - 0.0 - 0.0 - - - 25 - 0.0 - 0.0 - - - 34 - 0.0 - 0.0 - - - 37 - 0.0 - 0.0 - - - 27 - 0.0 - 0.0 - - - 21 - 0.0 - 0.0 - - - 22 - 0.0 - 0.0 - - - 39 - 0.0 - 0.0 - - - 38 - 0.0 - 0.0 - - - 25 - 15.132745950421556 - 169.0 - - - 27 - 171.0 - 261.0 - - - 35 - 285.7588368062799 - 285.7588368062799 - - - 37 - 291.5897887011252 - 383.0 - - - 38 - 385.0 - 479.0 - - - 39 - 484.0 - 567.0 - - - 36 - 572.0 - 665.0 - - - 34 - 668.0 - 751.0 - - - 22 - 772.1896201004171 - 812.0 - - - 21 - 814.0 - 914.0 - - 924.1980390271856 - - - - + + 29 + 0.0 + 0.0 + + + 20 + 0.0 + 0.0 + + + 30 + 0.0 + 0.0 + + + 32 + 0.0 + 0.0 + + + 26 + 0.0 + 0.0 + + + 28 + 0.0 + 0.0 + + + 24 + 0.0 + 0.0 + + + 23 + 0.0 + 0.0 + + + 33 + 0.0 + 0.0 + + + 31 + 0.0 + 0.0 + + + 20 + 10.0 + 10.0 + + + 24 + 15.0 + 65.0 + + + 32 + 83.02775637731995 + 83.02775637731995 + + + 33 + 85.02775637731995 + 87.0 + + + 31 + 92.3851648071345 + 200.0 + + + 29 + 218.02775637731995 + 358.0 + + + 30 + 363.0 + 449.0 + + + 28 + 452.0 + 546.0 + + + 26 + 548.0 + 622.0 + + + 23 + 625.0 + 732.0 + + 745.0 + + + 95.88470913081827 + noDriver + solomonVehicle + 0.0 + + 15 + 0.0 + 0.0 + + + 12 + 0.0 + 0.0 + + + 18 + 0.0 + 0.0 + + + 14 + 0.0 + 0.0 + + + 13 + 0.0 + 0.0 + + + 16 + 0.0 + 0.0 + + + 19 + 0.0 + 0.0 + + + 17 + 0.0 + 0.0 + + + 13 + 30.805843601498726 + 30.805843601498726 + + + 17 + 34.80584360149872 + 99.0 + + + 18 + 102.0 + 179.0 + + + 19 + 184.0 + 278.0 + + + 15 + 283.0 + 384.0 + + + 16 + 389.0 + 475.0 + + + 14 + 477.0 + 567.0 + + + 12 + 570.0 + 652.0 + + 690.0788655293195 + + + 111.98098283607547 + noDriver + solomonVehicle + 0.0 + + 98 + 0.0 + 0.0 + + + 84 + 0.0 + 0.0 + + + 83 + 0.0 + 0.0 + + + 95 + 0.0 + 0.0 + + + 88 + 0.0 + 0.0 + + + 86 + 0.0 + 0.0 + + + 91 + 0.0 + 0.0 + + + 89 + 0.0 + 0.0 + + + 85 + 0.0 + 0.0 + + + 82 + 0.0 + 0.0 + + + 98 + 30.805843601498726 + 30.805843601498726 + + + 95 + 37.20896783893157 + 196.0 + + + 86 + 221.31797780234433 + 221.31797780234433 + + + 83 + 227.31797780234433 + 265.0 + + + 82 + 268.0 + 369.0 + + + 84 + 374.8309518948453 + 458.0 + + + 85 + 460.8284271247462 + 555.0 + + + 88 + 558.0 + 645.0 + + + 89 + 647.8284271247462 + 737.0 + + + 91 + 740.605551275464 + 836.0 + + 858.360679774998 + + + 56.11696343016839 + noDriver + solomonVehicle + 0.0 + + 74 + 0.0 + 0.0 + + + 65 + 0.0 + 0.0 + + + 63 + 0.0 + 0.0 + + + 66 + 0.0 + 0.0 + + + 67 + 0.0 + 0.0 + + + 64 + 0.0 + 0.0 + + + 62 + 0.0 + 0.0 + + + 69 + 0.0 + 0.0 + + + 72 + 0.0 + 0.0 + + + 61 + 0.0 + 0.0 + + + 67 + 12.206555615733702 + 12.206555615733702 + + + 65 + 13.206555615733702 + 76.0 + + + 63 + 78.0 + 171.0 + + + 62 + 176.0 + 262.0 + + + 74 + 265.0 + 353.0 + + + 72 + 358.0 + 450.0 + + + 61 + 453.0 + 531.0 + + + 64 + 533.0 + 632.0 + + + 66 + 637.0990195135928 + 826.0 + + + 69 + 828.0 + 916.0 + + 931.8113883008419 + + + 102.37910960851471 + noDriver + solomonVehicle + 0.0 + + 54 + 0.0 + 0.0 + + + 58 + 0.0 + 0.0 + + + 68 + 0.0 + 0.0 + + + 60 + 0.0 + 0.0 + + + 53 + 0.0 + 0.0 + + + 59 + 0.0 + 0.0 + + + 57 + 0.0 + 0.0 + + + 56 + 0.0 + 0.0 + + + 57 + 35.0 + 35.0 + + + 54 + 40.3851648071345 + 186.0 + + + 53 + 191.38516480713452 + 286.0 + + + 56 + 290.0 + 385.0 + + + 58 + 387.0 + 471.0 + + + 60 + 474.0 + 562.0 + + + 59 + 572.4403065089106 + 651.0 + + + 68 + 667.5529453572468 + 734.0 + + 754.6155281280883 + + + 53.31190824207452 + noDriver + solomonVehicle + 0.0 + + 8 + 0.0 + 0.0 + + + 9 + 0.0 + 0.0 + + + 10 + 0.0 + 0.0 + + + 3 + 0.0 + 0.0 + + + 7 + 0.0 + 0.0 + + + 5 + 0.0 + 0.0 + + + 11 + 0.0 + 0.0 + + + 6 + 0.0 + 0.0 + + + 4 + 0.0 + 0.0 + + + 5 + 15.132745950421556 + 15.132745950421556 + + + 3 + 16.13274595042156 + 65.0 + + + 7 + 67.0 + 170.0 + + + 8 + 172.82842712474618 + 255.0 + + + 10 + 258.605551275464 + 357.0 + + + 11 + 360.0 + 448.0 + + + 9 + 451.1622776601684 + 534.0 + + + 6 + 536.2360679774998 + 621.0 + + + 4 + 623.2360679774998 + 727.0 + + 745.1107702762748 + + + 100.42763486950274 + noDriver + solomonVehicle + 0.0 + + 55 + 0.0 + 0.0 + + + 46 + 0.0 + 0.0 + + + 44 + 0.0 + 0.0 + + + 51 + 0.0 + 0.0 + + + 40 + 0.0 + 0.0 + + + 49 + 0.0 + 0.0 + + + 48 + 0.0 + 0.0 + + + 45 + 0.0 + 0.0 + + + 42 + 0.0 + 0.0 + + + 43 + 0.0 + 0.0 + + + 47 + 0.0 + 0.0 + + + 52 + 0.0 + 0.0 + + + 41 + 0.0 + 0.0 + + + 50 + 0.0 + 0.0 + + + 43 + 16.55294535724685 + 16.55294535724685 + + + 42 + 19.55294535724685 + 68.0 + + + 55 + 87.23538406167134 + 95.0 + + + 41 + 113.38477631085024 + 166.0 + + + 40 + 168.0 + 264.0 + + + 44 + 267.0 + 359.0 + + + 46 + 361.8284271247462 + 448.0 + + + 45 + 450.0 + 541.0 + + + 48 + 543.0 + 632.0 + + + 51 + 635.0 + 725.0 + + + 50 + 727.2360679774998 + 815.0 + + + 52 + 818.1622776601683 + 912.0 + + + 49 + 915.0 + 1001.0 + + + 47 + 1003.0 + 1054.0 + + 1072.02775637732 + + + 133.7631148876197 + noDriver + solomonVehicle + 0.0 + + 87 + 0.0 + 0.0 + + + 79 + 0.0 + 0.0 + + + 77 + 0.0 + 0.0 + + + 81 + 0.0 + 0.0 + + + 76 + 0.0 + 0.0 + + + 90 + 0.0 + 0.0 + + + 78 + 0.0 + 0.0 + + + 80 + 0.0 + 0.0 + + + 73 + 0.0 + 0.0 + + + 71 + 0.0 + 0.0 + + + 70 + 0.0 + 0.0 + + + 90 + 20.615528128088304 + 20.615528128088304 + + + 87 + 25.615528128088304 + 85.0 + + + 81 + 113.2842712474619 + 113.2842712474619 + + + 78 + 116.2842712474619 + 116.2842712474619 + + + 76 + 118.2842712474619 + 203.0 + + + 71 + 208.0 + 293.0 + + + 70 + 298.0 + 387.0 + + + 73 + 390.0 + 478.0 + + + 77 + 482.0 + 574.0 + + + 79 + 575.0 + 668.0 + + + 80 + 673.3851648071345 + 769.0 + + 820.478150704935 + + + 96.99975276181122 + noDriver + solomonVehicle + 0.0 + + 75 + 0.0 + 0.0 + + + 96 + 0.0 + 0.0 + + + 93 + 0.0 + 0.0 + + + 94 + 0.0 + 0.0 + + + 1 + 0.0 + 0.0 + + + 99 + 0.0 + 0.0 + + + 100 + 0.0 + 0.0 + + + 97 + 0.0 + 0.0 + + + 2 + 0.0 + 0.0 + + + 92 + 0.0 + 0.0 + + + 96 + 36.05551275463989 + 95.0 + + + 94 + 100.3851648071345 + 285.0 + + + 92 + 288.605551275464 + 368.0 + + + 93 + 370.0 + 475.0 + + + 97 + 480.0 + 561.0 + + + 100 + 566.0 + 647.0 + + + 99 + 652.0 + 743.0 + + + 2 + 757.142135623731 + 825.0 + + + 1 + 827.0 + 912.0 + + + 75 + 915.0 + 997.0 + + 1012.8113883008419 + + + 96.11019377914941 + noDriver + solomonVehicle + 0.0 + + 36 + 0.0 + 0.0 + + + 35 + 0.0 + 0.0 + + + 25 + 0.0 + 0.0 + + + 34 + 0.0 + 0.0 + + + 37 + 0.0 + 0.0 + + + 27 + 0.0 + 0.0 + + + 21 + 0.0 + 0.0 + + + 22 + 0.0 + 0.0 + + + 39 + 0.0 + 0.0 + + + 38 + 0.0 + 0.0 + + + 25 + 15.132745950421556 + 169.0 + + + 27 + 171.0 + 261.0 + + + 35 + 285.7588368062799 + 285.7588368062799 + + + 37 + 291.5897887011252 + 383.0 + + + 38 + 385.0 + 479.0 + + + 39 + 484.0 + 567.0 + + + 36 + 572.0 + 665.0 + + + 34 + 668.0 + 751.0 + + + 22 + 772.1896201004171 + 812.0 + + + 21 + 814.0 + 914.0 + + 924.1980390271856 + + + + diff --git a/jsprit-core/src/test/resources/pd_solomon_r101.xml b/jsprit-core/src/test/resources/pd_solomon_r101.xml index df35bceb..e6c08797 100644 --- a/jsprit-core/src/test/resources/pd_solomon_r101.xml +++ b/jsprit-core/src/test/resources/pd_solomon_r101.xml @@ -1,1235 +1,1236 @@ - - INFINITE - HOMOGENEOUS - - - - solomonVehicle - solomonType - - 0 - - - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.w3schools.com vrp_xml_schema.xsd"> + + INFINITE + HOMOGENEOUS + + + + solomonVehicle + solomonType + + 0 + + + + 0.0 + 230.0 + + + + + + solomonType + 200 + + 0.0 + 1.0 + + + + + + + [x=63.0][y=65.0] + + 8 + 10.0 + + 0.0 - 230.0 - - - - - - solomonType - 200 - - 0.0 - 1.0 - - - - - - - [x=63.0][y=65.0] - - 8 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=2.0][y=60.0] - - 5 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=53.0][y=52.0] - - 11 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=65.0][y=55.0] - - 14 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=60.0][y=12.0] - - 31 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=20.0][y=20.0] - - 8 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=5.0][y=5.0] - - 16 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=23.0][y=3.0] - - 7 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=24.0][y=12.0] - - 5 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=42.0][y=7.0] - - 5 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=40.0][y=25.0] - - 9 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=45.0][y=10.0] - - 18 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=55.0][y=5.0] - - 29 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=65.0][y=35.0] - - 3 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=65.0][y=20.0] - - 6 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=45.0][y=30.0] - - 17 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=35.0][y=40.0] - - 16 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=41.0][y=37.0] - - 16 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=64.0][y=42.0] - - 9 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=55.0][y=45.0] - - 13 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=35.0][y=17.0] - - 7 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=41.0][y=49.0] - - 10 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=40.0][y=60.0] - - 21 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=20.0][y=50.0] - - 5 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=25.0][y=30.0] - - 3 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=15.0][y=30.0] - - 26 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=35.0][y=69.0] - - 23 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=55.0][y=20.0] - - 19 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=31.0][y=52.0] - - 27 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=55.0][y=60.0] - - 16 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=10.0][y=43.0] - - 9 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=15.0][y=60.0] - - 17 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=5.0][y=30.0] - - 2 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=20.0][y=40.0] - - 12 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=30.0][y=5.0] - - 8 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=10.0][y=20.0] - - 19 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=30.0][y=25.0] - - 23 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=15.0][y=10.0] - - 20 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=20.0][y=65.0] - - 12 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=50.0][y=35.0] - - 19 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=45.0][y=20.0] - - 11 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=45.0][y=65.0] - - 9 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=20.0][y=26.0] - - 9 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=18.0][y=18.0] - - 17 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=19.0][y=21.0] - - 10 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=25.0][y=21.0] - - 12 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=22.0][y=27.0] - - 11 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=25.0][y=24.0] - - 20 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=26.0][y=27.0] - - 27 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=18.0][y=24.0] - - 22 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=22.0][y=22.0] - - 2 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=15.0][y=19.0] - - 1 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=31.0][y=67.0] - - 3 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=30.0][y=60.0] - - 16 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=26.0][y=52.0] - - 9 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=26.0][y=35.0] - - 15 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=57.0][y=48.0] - - 23 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=61.0][y=52.0] - - 3 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=53.0][y=43.0] - - 14 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=15.0][y=47.0] - - 16 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=14.0][y=37.0] - - 11 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=56.0][y=37.0] - - 6 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=55.0][y=54.0] - - 26 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=4.0][y=18.0] - - 35 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=28.0][y=18.0] - - 26 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=11.0][y=31.0] - - 7 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=16.0][y=22.0] - - 41 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=67.0][y=5.0] - - 25 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=49.0][y=73.0] - - 25 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=37.0][y=47.0] - - 6 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=56.0][y=39.0] - - 36 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=37.0][y=56.0] - - 5 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=57.0][y=68.0] - - 15 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=47.0][y=16.0] - - 25 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=44.0][y=17.0] - - 9 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=46.0][y=13.0] - - 8 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=49.0][y=11.0] - - 18 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=49.0][y=42.0] - - 13 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=21.0][y=24.0] - - 28 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=36.0][y=26.0] - - 18 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=32.0][y=12.0] - - 7 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=53.0][y=12.0] - - 6 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=63.0][y=23.0] - - 2 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=15.0][y=77.0] - - 9 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=62.0][y=77.0] - - 20 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=24.0][y=58.0] - - 19 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=27.0][y=69.0] - - 10 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=17.0][y=34.0] - - 3 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=12.0][y=24.0] - - 13 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=6.0][y=68.0] - - 30 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=13.0][y=52.0] - - 36 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=6.0][y=38.0] - - 16 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=11.0][y=14.0] - - 18 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=8.0][y=56.0] - - 27 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=2.0][y=48.0] - - 1 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=49.0][y=58.0] - - 10 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=27.0][y=43.0] - - 9 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=37.0][y=31.0] - - 14 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=57.0][y=29.0] - - 18 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=47.0][y=47.0] - - 13 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - + 1.7976931348623157E308 + + + + + [x=2.0][y=60.0] + + 5 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=53.0][y=52.0] + + 11 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=65.0][y=55.0] + + 14 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=60.0][y=12.0] + + 31 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=20.0][y=20.0] + + 8 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=5.0][y=5.0] + + 16 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=23.0][y=3.0] + + 7 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=24.0][y=12.0] + + 5 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=42.0][y=7.0] + + 5 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=40.0][y=25.0] + + 9 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=45.0][y=10.0] + + 18 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=55.0][y=5.0] + + 29 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=65.0][y=35.0] + + 3 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=65.0][y=20.0] + + 6 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=45.0][y=30.0] + + 17 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=35.0][y=40.0] + + 16 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=41.0][y=37.0] + + 16 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=64.0][y=42.0] + + 9 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=55.0][y=45.0] + + 13 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=35.0][y=17.0] + + 7 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=41.0][y=49.0] + + 10 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=40.0][y=60.0] + + 21 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=20.0][y=50.0] + + 5 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=25.0][y=30.0] + + 3 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=15.0][y=30.0] + + 26 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=35.0][y=69.0] + + 23 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=55.0][y=20.0] + + 19 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=31.0][y=52.0] + + 27 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=55.0][y=60.0] + + 16 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=10.0][y=43.0] + + 9 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=15.0][y=60.0] + + 17 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=5.0][y=30.0] + + 2 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=20.0][y=40.0] + + 12 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=30.0][y=5.0] + + 8 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=10.0][y=20.0] + + 19 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=30.0][y=25.0] + + 23 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=15.0][y=10.0] + + 20 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=20.0][y=65.0] + + 12 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=50.0][y=35.0] + + 19 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=45.0][y=20.0] + + 11 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=45.0][y=65.0] + + 9 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=20.0][y=26.0] + + 9 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=18.0][y=18.0] + + 17 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=19.0][y=21.0] + + 10 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=25.0][y=21.0] + + 12 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=22.0][y=27.0] + + 11 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=25.0][y=24.0] + + 20 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=26.0][y=27.0] + + 27 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=18.0][y=24.0] + + 22 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=22.0][y=22.0] + + 2 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=15.0][y=19.0] + + 1 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=31.0][y=67.0] + + 3 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=30.0][y=60.0] + + 16 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=26.0][y=52.0] + + 9 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=26.0][y=35.0] + + 15 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=57.0][y=48.0] + + 23 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=61.0][y=52.0] + + 3 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=53.0][y=43.0] + + 14 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=15.0][y=47.0] + + 16 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=14.0][y=37.0] + + 11 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=56.0][y=37.0] + + 6 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=55.0][y=54.0] + + 26 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=4.0][y=18.0] + + 35 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=28.0][y=18.0] + + 26 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=11.0][y=31.0] + + 7 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=16.0][y=22.0] + + 41 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=67.0][y=5.0] + + 25 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=49.0][y=73.0] + + 25 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=37.0][y=47.0] + + 6 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=56.0][y=39.0] + + 36 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=37.0][y=56.0] + + 5 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=57.0][y=68.0] + + 15 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=47.0][y=16.0] + + 25 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=44.0][y=17.0] + + 9 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=46.0][y=13.0] + + 8 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=49.0][y=11.0] + + 18 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=49.0][y=42.0] + + 13 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=21.0][y=24.0] + + 28 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=36.0][y=26.0] + + 18 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=32.0][y=12.0] + + 7 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=53.0][y=12.0] + + 6 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=63.0][y=23.0] + + 2 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=15.0][y=77.0] + + 9 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=62.0][y=77.0] + + 20 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=24.0][y=58.0] + + 19 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=27.0][y=69.0] + + 10 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=17.0][y=34.0] + + 3 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=12.0][y=24.0] + + 13 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=6.0][y=68.0] + + 30 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=13.0][y=52.0] + + 36 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=6.0][y=38.0] + + 16 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=11.0][y=14.0] + + 18 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=8.0][y=56.0] + + 27 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=2.0][y=48.0] + + 1 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=49.0][y=58.0] + + 10 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=27.0][y=43.0] + + 9 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=37.0][y=31.0] + + 14 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=57.0][y=29.0] + + 18 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=47.0][y=47.0] + + 13 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + diff --git a/jsprit-core/src/test/resources/pdp.xml b/jsprit-core/src/test/resources/pdp.xml index 3f3800f1..dd4dc4ec 100644 --- a/jsprit-core/src/test/resources/pdp.xml +++ b/jsprit-core/src/test/resources/pdp.xml @@ -1,511 +1,512 @@ - - INFINITE - HOMOGENEOUS - - - - v - t - - [x=10.0][y=10.0] - - - - 0.0 - 500.0 - - - - - - t - 5 - - 0.0 - 1.0 - - - - - - - - [x=77.0][y=23.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=20.0][y=39.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - 1 - - - - [x=67.0][y=1.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=41.0][y=7.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - 1 - - - - [x=57.0][y=96.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=36.0][y=97.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - 1 - - - - [x=28.0][y=84.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=93.0][y=44.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - 1 - - - - [x=3.0][y=36.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=77.0][y=6.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - 1 - - - - [x=45.0][y=11.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=63.0][y=80.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - 1 - - - - [x=4.0][y=84.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=93.0][y=23.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - 1 - - - - [x=80.0][y=9.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=19.0][y=76.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - 1 - - - - [x=8.0][y=23.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=84.0][y=33.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - 1 - - - - [x=26.0][y=89.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=48.0][y=55.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - 1 - - - - [x=78.0][y=43.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=66.0][y=44.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - 1 - - - - [x=73.0][y=38.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=89.0][y=40.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - 1 - - - - [x=22.0][y=62.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=6.0][y=60.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - 1 - - - - [x=56.0][y=17.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=84.0][y=71.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - 1 - - - - [x=26.0][y=60.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=37.0][y=25.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - 1 - - - - [x=96.0][y=35.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=93.0][y=20.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - 1 - - - - [x=1.0][y=18.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=56.0][y=33.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - 1 - - - - [x=93.0][y=44.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=5.0][y=90.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - 1 - - - - [x=31.0][y=63.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=12.0][y=56.0] - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - 1 - - - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.w3schools.com vrp_xml_schema.xsd"> + + INFINITE + HOMOGENEOUS + + + + v + t + + [x=10.0][y=10.0] + + + + 0.0 + 500.0 + + + + + + t + 5 + + 0.0 + 1.0 + + + + + + + + [x=77.0][y=23.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=20.0][y=39.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + 1 + + + + [x=67.0][y=1.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=41.0][y=7.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + 1 + + + + [x=57.0][y=96.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=36.0][y=97.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + 1 + + + + [x=28.0][y=84.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=93.0][y=44.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + 1 + + + + [x=3.0][y=36.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=77.0][y=6.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + 1 + + + + [x=45.0][y=11.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=63.0][y=80.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + 1 + + + + [x=4.0][y=84.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=93.0][y=23.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + 1 + + + + [x=80.0][y=9.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=19.0][y=76.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + 1 + + + + [x=8.0][y=23.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=84.0][y=33.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + 1 + + + + [x=26.0][y=89.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=48.0][y=55.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + 1 + + + + [x=78.0][y=43.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=66.0][y=44.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + 1 + + + + [x=73.0][y=38.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=89.0][y=40.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + 1 + + + + [x=22.0][y=62.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=6.0][y=60.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + 1 + + + + [x=56.0][y=17.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=84.0][y=71.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + 1 + + + + [x=26.0][y=60.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=37.0][y=25.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + 1 + + + + [x=96.0][y=35.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=93.0][y=20.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + 1 + + + + [x=1.0][y=18.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=56.0][y=33.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + 1 + + + + [x=93.0][y=44.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=5.0][y=90.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + 1 + + + + [x=31.0][y=63.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=12.0][y=56.0] + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + 1 + + + diff --git a/jsprit-core/src/test/resources/schrimpf_vehicleSwitchNotAllowed.xml b/jsprit-core/src/test/resources/schrimpf_vehicleSwitchNotAllowed.xml index c2799761..c8b8fe83 100644 --- a/jsprit-core/src/test/resources/schrimpf_vehicleSwitchNotAllowed.xml +++ b/jsprit-core/src/test/resources/schrimpf_vehicleSwitchNotAllowed.xml @@ -18,55 +18,56 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~--> + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.w3schools.com algorithm_schema.xsd"> - 2000 + 2000 - - - false - - + + + false + + - - 1 - - - - - 0.1 - 20 - - - - - 0.3 - - - + + 1 + + + + + 0.1 + 20 + + + + + 0.3 + + + - - 0.5 - + + 0.5 + - - - + + + - - - - 0.1 - - - + + + + 0.1 + + + - - .5 - - - - + + .5 + + + + - \ No newline at end of file + diff --git a/jsprit-core/src/test/resources/simpleProblem.xml b/jsprit-core/src/test/resources/simpleProblem.xml index bdbb7480..03134d1b 100644 --- a/jsprit-core/src/test/resources/simpleProblem.xml +++ b/jsprit-core/src/test/resources/simpleProblem.xml @@ -1,98 +1,99 @@ - - FINITE - HOMOGENEOUS - - - - 21 - 5 - - [x=0.0][y=0.0] - - - - [x=0.0][y=0.0] - - - - 14400.0 - 46800.0 - - true - - - 19 - 3.5 - - [x=0.0][y=0.0] - - - - [x=0.0][y=0.0] - - - - 39600.0 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.w3schools.com vrp_xml_schema.xsd"> + + FINITE + HOMOGENEOUS + + + + 21 + 5 + + [x=0.0][y=0.0] + + + + [x=0.0][y=0.0] + + + + 14400.0 + 46800.0 + + true + + + 19 + 3.5 + + [x=0.0][y=0.0] + + + + [x=0.0][y=0.0] + + + + 39600.0 + 64800.0 + + true + + + + + 5 + + 0 + + + 0.0 + 1.0 + + + + + 3.5 + + 0 + + + 0.0 + 1.0 + + + + + + + [x=2000.0][y=0.0] + + + 0 + + 0.0 + + + 54000.0 64800.0 - - true - - - - - 5 - - 0 - - - 0.0 - 1.0 - - - - - 3.5 - - 0 - - - 0.0 - 1.0 - - - - - - - [x=2000.0][y=0.0] - - - 0 - - 0.0 - - - 54000.0 - 64800.0 - - - - - [x=1000.0][y=1000.0] - - - 0 - - 0.0 - - - 19800.0 - 21600.0 - - - - + + + + + [x=1000.0][y=1000.0] + + + 0 + + 0.0 + + + 19800.0 + 21600.0 + + + + diff --git a/jsprit-core/src/test/resources/simpleProblem_inclShipments_iniRoutes.xml b/jsprit-core/src/test/resources/simpleProblem_inclShipments_iniRoutes.xml index 0b18d0b7..2b646d33 100644 --- a/jsprit-core/src/test/resources/simpleProblem_inclShipments_iniRoutes.xml +++ b/jsprit-core/src/test/resources/simpleProblem_inclShipments_iniRoutes.xml @@ -1,77 +1,78 @@ - - FINITE - HOMOGENEOUS - - - - veh1 - type1 - - [x=0.0][y=0.0] - - - - [x=0.0][y=0.0] - - - - 0.0 - 46800.0 - - true - - - veh2 - type1 - - [x=0.0][y=0.0] - - - - [x=0.0][y=0.0] - - - - 0.0 - 64800.0 - - true - - - - - type1 - - 0 - - - 0.0 - 1.0 - - - - - - - loc_s2 - - - 0 - - 0.0 - - - loc_s1 - - - 0 - - 0.0 - - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.w3schools.com vrp_xml_schema.xsd"> + + FINITE + HOMOGENEOUS + + + + veh1 + type1 + + [x=0.0][y=0.0] + + + + [x=0.0][y=0.0] + + + + 0.0 + 46800.0 + + true + + + veh2 + type1 + + [x=0.0][y=0.0] + + + + [x=0.0][y=0.0] + + + + 0.0 + 64800.0 + + true + + + + + type1 + + 0 + + + 0.0 + 1.0 + + + + + + + loc_s2 + + + 0 + + 0.0 + + + loc_s1 + + + 0 + + 0.0 + + diff --git a/jsprit-core/src/test/resources/simpleProblem_iniRoutes.xml b/jsprit-core/src/test/resources/simpleProblem_iniRoutes.xml index 1db2a906..a0b8ae6f 100644 --- a/jsprit-core/src/test/resources/simpleProblem_iniRoutes.xml +++ b/jsprit-core/src/test/resources/simpleProblem_iniRoutes.xml @@ -1,77 +1,78 @@ - - FINITE - HOMOGENEOUS - - - - veh1 - type1 - - [x=0.0][y=0.0] - - - - [x=0.0][y=0.0] - - - - 0.0 - 46800.0 - - true - - - 2 - type1 - - [x=0.0][y=0.0] - - - - [x=0.0][y=0.0] - - - - 0.0 - 64800.0 - - true - - - - - type1 - - 0 - - - 0.0 - 1.0 - - - - - - - loc_s2 - - - 0 - - 0.0 - - - loc_s3 - - - 0 - - 0.0 - - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.w3schools.com vrp_xml_schema.xsd"> + + FINITE + HOMOGENEOUS + + + + veh1 + type1 + + [x=0.0][y=0.0] + + + + [x=0.0][y=0.0] + + + + 0.0 + 46800.0 + + true + + + 2 + type1 + + [x=0.0][y=0.0] + + + + [x=0.0][y=0.0] + + + + 0.0 + 64800.0 + + true + + + + + type1 + + 0 + + + 0.0 + 1.0 + + + + + + + loc_s2 + + + 0 + + 0.0 + + + loc_s3 + + + 0 + + 0.0 + + noDriver diff --git a/jsprit-core/src/test/resources/simpleProblem_iniRoutes_2.xml b/jsprit-core/src/test/resources/simpleProblem_iniRoutes_2.xml index c370023c..1705ba96 100644 --- a/jsprit-core/src/test/resources/simpleProblem_iniRoutes_2.xml +++ b/jsprit-core/src/test/resources/simpleProblem_iniRoutes_2.xml @@ -1,42 +1,43 @@ - - FINITE - HOMOGENEOUS - - - - veh1 - type1 - - [x=0.0][y=0.0] - - - - [x=0.0][y=0.0] - - - - 0.0 - 46800.0 - - true - - - - - type1 - - 100 - - - 0.0 - 1.0 - - - - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.w3schools.com vrp_xml_schema.xsd"> + + FINITE + HOMOGENEOUS + + + + veh1 + type1 + + [x=0.0][y=0.0] + + + + [x=0.0][y=0.0] + + + + 0.0 + 46800.0 + + true + + + + + type1 + + 100 + + + 0.0 + 1.0 + + + + diff --git a/jsprit-core/src/test/resources/simpleProblem_iniRoutes_3.xml b/jsprit-core/src/test/resources/simpleProblem_iniRoutes_3.xml index 3489c4e1..c2602237 100644 --- a/jsprit-core/src/test/resources/simpleProblem_iniRoutes_3.xml +++ b/jsprit-core/src/test/resources/simpleProblem_iniRoutes_3.xml @@ -1,69 +1,70 @@ - - FINITE - HOMOGENEOUS - - - - veh1 - type1 - - [x=5000.0][y=5000.0] - - - - 0.0 - 46800.0 - - true - - - veh2 - type1 - - [x=0.0][y=0.0] - - - - 0.0 - 64800.0 - - true - - - - - type1 - - 0 - - - 0.0 - 1.0 - - - - - - - loc_s2 - - - 0 - - 0.0 - - - loc_s3 - - - 0 - - 0.0 - - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.w3schools.com vrp_xml_schema.xsd"> + + FINITE + HOMOGENEOUS + + + + veh1 + type1 + + [x=5000.0][y=5000.0] + + + + 0.0 + 46800.0 + + true + + + veh2 + type1 + + [x=0.0][y=0.0] + + + + 0.0 + 64800.0 + + true + + + + + type1 + + 0 + + + 0.0 + 1.0 + + + + + + + loc_s2 + + + 0 + + 0.0 + + + loc_s3 + + + 0 + + 0.0 + + noDriver diff --git a/jsprit-core/src/test/resources/solomon_c101.xml b/jsprit-core/src/test/resources/solomon_c101.xml index a9ebce9e..53f89b67 100644 --- a/jsprit-core/src/test/resources/solomon_c101.xml +++ b/jsprit-core/src/test/resources/solomon_c101.xml @@ -1,1441 +1,1442 @@ - - INFINITE - - - - solomonVehicle - solomonType - - 0 - - - - 0 - - - - 0.0 - 1236.0 - - true - - - - - solomonType - - 200 - - - 0.0 - 1.0 - - - - - - - 35 - - - 10 - - 90.0 - - - 283.0 - 344.0 - - - - - 36 - - - 10 - - 90.0 - - - 665.0 - 716.0 - - - - - 33 - - - 40 - - 90.0 - - - 87.0 - 158.0 - - - - - 34 - - - 20 - - 90.0 - - - 751.0 - 816.0 - - - - - 39 - - - 20 - - 90.0 - - - 567.0 - 624.0 - - - - - 37 - - - 20 - - 90.0 - - - 383.0 - 434.0 - - - - - 38 - - - 30 - - 90.0 - - - 479.0 - 522.0 - - - - - 43 - - - 10 - - 90.0 - - - 16.0 - 80.0 - - - - - 42 - - - 20 - - 90.0 - - - 68.0 - 149.0 - - - - - 41 - - - 10 - - 90.0 - - - 166.0 - 235.0 - - - - - 40 - - - 10 - - 90.0 - - - 264.0 - 321.0 - - - - - 22 - - - 20 - - 90.0 - - - 812.0 - 883.0 - - - - - 23 - - - 10 - - 90.0 - - - 732.0 - 777.0 - - - - - 24 - - - 10 - - 90.0 - - - 65.0 - 144.0 - - - - - 25 - - - 40 - - 90.0 - - - 169.0 - 224.0 - - - - - 26 - - - 10 - - 90.0 - - - 622.0 - 701.0 - - - - - 27 - - - 10 - - 90.0 - - - 261.0 - 316.0 - - - - - 28 - - - 20 - - 90.0 - - - 546.0 - 593.0 - - - - - 29 - - - 10 - - 90.0 - - - 358.0 - 405.0 - - - - - 3 - - - 10 - - 90.0 - - - 65.0 - 146.0 - - - - - 2 - - - 30 - - 90.0 - - - 825.0 - 870.0 - - - - - 1 - - - 10 - - 90.0 - - - 912.0 - 967.0 - - - - - 30 - - - 10 - - 90.0 - - - 449.0 - 504.0 - - - - - 7 - - - 20 - - 90.0 - - - 170.0 - 225.0 - - - - - 6 - - - 20 - - 90.0 - - - 621.0 - 702.0 - - - - - 5 - - - 10 - - 90.0 - - - 15.0 - 67.0 - - - - - 32 - - - 30 - - 90.0 - - - 31.0 - 100.0 - - - - - 4 - - - 10 - - 90.0 - - - 727.0 - 782.0 - - - - - 31 - - - 20 - - 90.0 - - - 200.0 - 237.0 - - - - - 9 - - - 10 - - 90.0 - - - 534.0 - 605.0 - - - - - 8 - - - 20 - - 90.0 - - - 255.0 - 324.0 - - - - - 19 - - - 10 - - 90.0 - - - 278.0 - 345.0 - - - - - 17 - - - 20 - - 90.0 - - - 99.0 - 148.0 - - - - - 18 - - - 20 - - 90.0 - - - 179.0 - 254.0 - - - - - 15 - - - 40 - - 90.0 - - - 384.0 - 429.0 - - - - - 16 - - - 40 - - 90.0 - - - 475.0 - 528.0 - - - - - 13 - - - 30 - - 90.0 - - - 30.0 - 92.0 - - - - - 14 - - - 10 - - 90.0 - - - 567.0 - 620.0 - - - - - 11 - - - 10 - - 90.0 - - - 448.0 - 505.0 - - - - - 12 - - - 20 - - 90.0 - - - 652.0 - 721.0 - - - - - 21 - - - 20 - - 90.0 - - - 914.0 - 965.0 - - - - - 20 - - - 10 - - 90.0 - - - 10.0 - 73.0 - - - - - 99 - - - 10 - - 90.0 - - - 743.0 - 820.0 - - - - - 100 - - - 20 - - 90.0 - - - 647.0 - 726.0 - - - - - 98 - - - 20 - - 90.0 - - - 30.0 - 84.0 - - - - - 97 - - - 30 - - 90.0 - - - 561.0 - 622.0 - - - - - 96 - - - 10 - - 90.0 - - - 95.0 - 156.0 - - - - - 95 - - - 30 - - 90.0 - - - 196.0 - 239.0 - - - - - 94 - - - 10 - - 90.0 - - - 285.0 - 336.0 - - - - - 93 - - - 40 - - 90.0 - - - 475.0 - 518.0 - - - - - 92 - - - 20 - - 90.0 - - - 368.0 - 441.0 - - - - - 91 - - - 10 - - 90.0 - - - 836.0 - 889.0 - - - - - 90 - - - 10 - - 90.0 - - - 20.0 - 84.0 - - - - - 10 - - - 10 - - 90.0 - - - 357.0 - 410.0 - - - - - 88 - - - 30 - - 90.0 - - - 645.0 - 708.0 - - - - - 89 - - - 10 - - 90.0 - - - 737.0 - 802.0 - - - - - 79 - - - 10 - - 90.0 - - - 668.0 - 731.0 - - - - - 78 - - - 20 - - 90.0 - - - 109.0 - 170.0 - - - - - 77 - - - 10 - - 90.0 - - - 574.0 - 643.0 - - - - - 82 - - - 20 - - 90.0 - - - 369.0 - 420.0 - - - - - 83 - - - 10 - - 90.0 - - - 265.0 - 338.0 - - - - - 80 - - - 10 - - 90.0 - - - 769.0 - 820.0 - - - - - 81 - - - 30 - - 90.0 - - - 47.0 - 124.0 - - - - - 86 - - - 10 - - 90.0 - - - 173.0 - 238.0 - - - - - 87 - - - 20 - - 90.0 - - - 85.0 - 144.0 - - - - - 84 - - - 20 - - 90.0 - - - 458.0 - 523.0 - - - - - 85 - - - 30 - - 90.0 - - - 555.0 - 612.0 - - - - - 67 - - - 10 - - 90.0 - - - 12.0 - 77.0 - - - - - 66 - - - 10 - - 90.0 - - - 826.0 - 875.0 - - - - - 69 - - - 10 - - 90.0 - - - 916.0 - 969.0 - - - - - 68 - - - 10 - - 90.0 - - - 734.0 - 777.0 - - - - - 70 - - - 30 - - 90.0 - - - 387.0 - 456.0 - - - - - 71 - - - 20 - - 90.0 - - - 293.0 - 360.0 - - - - - 72 - - - 10 - - 90.0 - - - 450.0 - 505.0 - - - - - 73 - - - 10 - - 90.0 - - - 478.0 - 551.0 - - - - - 74 - - - 50 - - 90.0 - - - 353.0 - 412.0 - - - - - 75 - - - 20 - - 90.0 - - - 997.0 - 1068.0 - - - - - 76 - - - 10 - - 90.0 - - - 203.0 - 260.0 - - - - - 59 - - - 10 - - 90.0 - - - 651.0 - 740.0 - - - - - 58 - - - 30 - - 90.0 - - - 471.0 - 534.0 - - - - - 57 - - - 40 - - 90.0 - - - 35.0 - 87.0 - - - - - 56 - - - 30 - - 90.0 - - - 385.0 - 436.0 - - - - - 55 - - - 10 - - 90.0 - - - 95.0 - 158.0 - - - - - 64 - - - 10 - - 90.0 - - - 632.0 - 693.0 - - - - - 65 - - - 10 - - 90.0 - - - 76.0 - 129.0 - - - - - 62 - - - 20 - - 90.0 - - - 262.0 - 317.0 - - - - - 63 - - - 50 - - 90.0 - - - 171.0 - 218.0 - - - - - 60 - - - 20 - - 90.0 - - - 562.0 - 629.0 - - - - - 61 - - - 10 - - 90.0 - - - 531.0 - 610.0 - - - - - 49 - - - 10 - - 90.0 - - - 1001.0 - 1066.0 - - - - - 48 - - - 10 - - 90.0 - - - 632.0 - 693.0 - - - - - 45 - - - 10 - - 90.0 - - - 541.0 - 600.0 - - - - - 44 - - - 10 - - 90.0 - - - 359.0 - 412.0 - - - - - 47 - - - 10 - - 90.0 - - - 1054.0 - 1127.0 - - - - - 46 - - - 30 - - 90.0 - - - 448.0 - 509.0 - - - - - 51 - - - 10 - - 90.0 - - - 725.0 - 786.0 - - - - - 52 - - - 10 - - 90.0 - - - 912.0 - 969.0 - - - - - 53 - - - 20 - - 90.0 - - - 286.0 - 347.0 - - - - - 54 - - - 40 - - 90.0 - - - 186.0 - 257.0 - - - - - 50 - - - 10 - - 90.0 - - - 815.0 - 880.0 - - - - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.w3schools.com vrp_xml_schema.xsd"> + + INFINITE + + + + solomonVehicle + solomonType + + 0 + + + + 0 + + + + 0.0 + 1236.0 + + true + + + + + solomonType + + 200 + + + 0.0 + 1.0 + + + + + + + 35 + + + 10 + + 90.0 + + + 283.0 + 344.0 + + + + + 36 + + + 10 + + 90.0 + + + 665.0 + 716.0 + + + + + 33 + + + 40 + + 90.0 + + + 87.0 + 158.0 + + + + + 34 + + + 20 + + 90.0 + + + 751.0 + 816.0 + + + + + 39 + + + 20 + + 90.0 + + + 567.0 + 624.0 + + + + + 37 + + + 20 + + 90.0 + + + 383.0 + 434.0 + + + + + 38 + + + 30 + + 90.0 + + + 479.0 + 522.0 + + + + + 43 + + + 10 + + 90.0 + + + 16.0 + 80.0 + + + + + 42 + + + 20 + + 90.0 + + + 68.0 + 149.0 + + + + + 41 + + + 10 + + 90.0 + + + 166.0 + 235.0 + + + + + 40 + + + 10 + + 90.0 + + + 264.0 + 321.0 + + + + + 22 + + + 20 + + 90.0 + + + 812.0 + 883.0 + + + + + 23 + + + 10 + + 90.0 + + + 732.0 + 777.0 + + + + + 24 + + + 10 + + 90.0 + + + 65.0 + 144.0 + + + + + 25 + + + 40 + + 90.0 + + + 169.0 + 224.0 + + + + + 26 + + + 10 + + 90.0 + + + 622.0 + 701.0 + + + + + 27 + + + 10 + + 90.0 + + + 261.0 + 316.0 + + + + + 28 + + + 20 + + 90.0 + + + 546.0 + 593.0 + + + + + 29 + + + 10 + + 90.0 + + + 358.0 + 405.0 + + + + + 3 + + + 10 + + 90.0 + + + 65.0 + 146.0 + + + + + 2 + + + 30 + + 90.0 + + + 825.0 + 870.0 + + + + + 1 + + + 10 + + 90.0 + + + 912.0 + 967.0 + + + + + 30 + + + 10 + + 90.0 + + + 449.0 + 504.0 + + + + + 7 + + + 20 + + 90.0 + + + 170.0 + 225.0 + + + + + 6 + + + 20 + + 90.0 + + + 621.0 + 702.0 + + + + + 5 + + + 10 + + 90.0 + + + 15.0 + 67.0 + + + + + 32 + + + 30 + + 90.0 + + + 31.0 + 100.0 + + + + + 4 + + + 10 + + 90.0 + + + 727.0 + 782.0 + + + + + 31 + + + 20 + + 90.0 + + + 200.0 + 237.0 + + + + + 9 + + + 10 + + 90.0 + + + 534.0 + 605.0 + + + + + 8 + + + 20 + + 90.0 + + + 255.0 + 324.0 + + + + + 19 + + + 10 + + 90.0 + + + 278.0 + 345.0 + + + + + 17 + + + 20 + + 90.0 + + + 99.0 + 148.0 + + + + + 18 + + + 20 + + 90.0 + + + 179.0 + 254.0 + + + + + 15 + + + 40 + + 90.0 + + + 384.0 + 429.0 + + + + + 16 + + + 40 + + 90.0 + + + 475.0 + 528.0 + + + + + 13 + + + 30 + + 90.0 + + + 30.0 + 92.0 + + + + + 14 + + + 10 + + 90.0 + + + 567.0 + 620.0 + + + + + 11 + + + 10 + + 90.0 + + + 448.0 + 505.0 + + + + + 12 + + + 20 + + 90.0 + + + 652.0 + 721.0 + + + + + 21 + + + 20 + + 90.0 + + + 914.0 + 965.0 + + + + + 20 + + + 10 + + 90.0 + + + 10.0 + 73.0 + + + + + 99 + + + 10 + + 90.0 + + + 743.0 + 820.0 + + + + + 100 + + + 20 + + 90.0 + + + 647.0 + 726.0 + + + + + 98 + + + 20 + + 90.0 + + + 30.0 + 84.0 + + + + + 97 + + + 30 + + 90.0 + + + 561.0 + 622.0 + + + + + 96 + + + 10 + + 90.0 + + + 95.0 + 156.0 + + + + + 95 + + + 30 + + 90.0 + + + 196.0 + 239.0 + + + + + 94 + + + 10 + + 90.0 + + + 285.0 + 336.0 + + + + + 93 + + + 40 + + 90.0 + + + 475.0 + 518.0 + + + + + 92 + + + 20 + + 90.0 + + + 368.0 + 441.0 + + + + + 91 + + + 10 + + 90.0 + + + 836.0 + 889.0 + + + + + 90 + + + 10 + + 90.0 + + + 20.0 + 84.0 + + + + + 10 + + + 10 + + 90.0 + + + 357.0 + 410.0 + + + + + 88 + + + 30 + + 90.0 + + + 645.0 + 708.0 + + + + + 89 + + + 10 + + 90.0 + + + 737.0 + 802.0 + + + + + 79 + + + 10 + + 90.0 + + + 668.0 + 731.0 + + + + + 78 + + + 20 + + 90.0 + + + 109.0 + 170.0 + + + + + 77 + + + 10 + + 90.0 + + + 574.0 + 643.0 + + + + + 82 + + + 20 + + 90.0 + + + 369.0 + 420.0 + + + + + 83 + + + 10 + + 90.0 + + + 265.0 + 338.0 + + + + + 80 + + + 10 + + 90.0 + + + 769.0 + 820.0 + + + + + 81 + + + 30 + + 90.0 + + + 47.0 + 124.0 + + + + + 86 + + + 10 + + 90.0 + + + 173.0 + 238.0 + + + + + 87 + + + 20 + + 90.0 + + + 85.0 + 144.0 + + + + + 84 + + + 20 + + 90.0 + + + 458.0 + 523.0 + + + + + 85 + + + 30 + + 90.0 + + + 555.0 + 612.0 + + + + + 67 + + + 10 + + 90.0 + + + 12.0 + 77.0 + + + + + 66 + + + 10 + + 90.0 + + + 826.0 + 875.0 + + + + + 69 + + + 10 + + 90.0 + + + 916.0 + 969.0 + + + + + 68 + + + 10 + + 90.0 + + + 734.0 + 777.0 + + + + + 70 + + + 30 + + 90.0 + + + 387.0 + 456.0 + + + + + 71 + + + 20 + + 90.0 + + + 293.0 + 360.0 + + + + + 72 + + + 10 + + 90.0 + + + 450.0 + 505.0 + + + + + 73 + + + 10 + + 90.0 + + + 478.0 + 551.0 + + + + + 74 + + + 50 + + 90.0 + + + 353.0 + 412.0 + + + + + 75 + + + 20 + + 90.0 + + + 997.0 + 1068.0 + + + + + 76 + + + 10 + + 90.0 + + + 203.0 + 260.0 + + + + + 59 + + + 10 + + 90.0 + + + 651.0 + 740.0 + + + + + 58 + + + 30 + + 90.0 + + + 471.0 + 534.0 + + + + + 57 + + + 40 + + 90.0 + + + 35.0 + 87.0 + + + + + 56 + + + 30 + + 90.0 + + + 385.0 + 436.0 + + + + + 55 + + + 10 + + 90.0 + + + 95.0 + 158.0 + + + + + 64 + + + 10 + + 90.0 + + + 632.0 + 693.0 + + + + + 65 + + + 10 + + 90.0 + + + 76.0 + 129.0 + + + + + 62 + + + 20 + + 90.0 + + + 262.0 + 317.0 + + + + + 63 + + + 50 + + 90.0 + + + 171.0 + 218.0 + + + + + 60 + + + 20 + + 90.0 + + + 562.0 + 629.0 + + + + + 61 + + + 10 + + 90.0 + + + 531.0 + 610.0 + + + + + 49 + + + 10 + + 90.0 + + + 1001.0 + 1066.0 + + + + + 48 + + + 10 + + 90.0 + + + 632.0 + 693.0 + + + + + 45 + + + 10 + + 90.0 + + + 541.0 + 600.0 + + + + + 44 + + + 10 + + 90.0 + + + 359.0 + 412.0 + + + + + 47 + + + 10 + + 90.0 + + + 1054.0 + 1127.0 + + + + + 46 + + + 30 + + 90.0 + + + 448.0 + 509.0 + + + + + 51 + + + 10 + + 90.0 + + + 725.0 + 786.0 + + + + + 52 + + + 10 + + 90.0 + + + 912.0 + 969.0 + + + + + 53 + + + 20 + + 90.0 + + + 286.0 + 347.0 + + + + + 54 + + + 40 + + 90.0 + + + 186.0 + 257.0 + + + + + 50 + + + 10 + + 90.0 + + + 815.0 + 880.0 + + + + diff --git a/jsprit-core/src/test/resources/testConfig.xml b/jsprit-core/src/test/resources/testConfig.xml index 5398d7a0..084e0a4c 100755 --- a/jsprit-core/src/test/resources/testConfig.xml +++ b/jsprit-core/src/test/resources/testConfig.xml @@ -2,69 +2,69 @@ - 10 + 10 + + + + + + + 1 + + + + + + + + 0.5 + + + + + 0.4 + + + + + + + + + 0.1 + + + + + 0.4 + + + + + + + + + 0.3 + + + + + 0.2 + + + + + + + + + + + + + + - - - - - - 1 - - - - - - - - 0.5 - - - - - 0.4 - - - - - - - - - 0.1 - - - - - 0.4 - - - - - - - - - 0.3 - - - - - 0.2 - - - - - - - - - - - - - - - diff --git a/jsprit-core/src/test/resources/testConfig2.xml b/jsprit-core/src/test/resources/testConfig2.xml index c62327c4..ced4b0b9 100755 --- a/jsprit-core/src/test/resources/testConfig2.xml +++ b/jsprit-core/src/test/resources/testConfig2.xml @@ -2,65 +2,65 @@ - 10 - - - - - - - 1 - - - - - - - 0.5 - - - - - 0.4 - - - - - - - - 0.1 - - - - 0.4 - - - - - - - - 0.3 - euclid - - - - 0.2 - - - - - - - - - - - - - - - + 10 + + + + + + + 1 + + + + + + + 0.5 + + + + + 0.4 + + + + + + + + 0.1 + + + + 0.4 + + + + + + + + 0.3 + euclid + + + + 0.2 + + + + + + + + + + + + + + + diff --git a/jsprit-core/src/test/resources/twbug.xml b/jsprit-core/src/test/resources/twbug.xml new file mode 100644 index 00000000..83c9ef42 --- /dev/null +++ b/jsprit-core/src/test/resources/twbug.xml @@ -0,0 +1,407 @@ + + + + FINITE + + + + vehicle0 + vehicle_type_0 + + v0_start + 0 + + + v0_start + 0 + + + 60.0 + 18060.0 + + true + primemover + + + vehicle1 + vehicle_type_1 + + v1_start + 0 + + + v1_start + 0 + + + 60.0 + 18060.0 + + true + primemover + + + vehicle2 + vehicle_type_2 + + v2_start + 0 + + + v2_start + 0 + + + 7200.0 + 36060.0 + + true + primemover + + + vehicle3 + vehicle_type_3 + + v3_start + 0 + + + v3_start + 0 + + + 36000.0 + 54060.0 + + true + primemover + + + vehicle4 + vehicle_type_4 + + v4_start + 0 + + + v4_start + 0 + + + 36000.0 + 54060.0 + + true + primemover + + + + + vehicle_type_0 + + 20 + + + 0.0 + 0.0 + + + + + vehicle_type_1 + + 20 + + + 0.0 + 0.0 + + + + + vehicle_type_2 + + 20 + + + 0.0 + 0.0 + + + + + vehicle_type_3 + + 20 + + + 0.0 + 0.0 + + + + + vehicle_type_4 + + 20 + + + 0.0 + 0.0 + + + + + + + + js0 + 1 + + + 1 + + 600.0 + + + 0.0 + 1800.0 + + + Test + + + + js2 + 2 + + + 2 + + 600.0 + + + 5400.0 + 7200.0 + + + Test + + + + js5 + 3 + + + 10 + + 1800.0 + + + 17100.0 + 18000.0 + + + Test + + + + js6 + 4 + + + 2 + + 900.0 + + + 0.0 + 1.7976931348623157E308 + + + Test + + + + js8 + 5 + + + 4 + + 600.0 + + + 0.0 + 1.7976931348623157E308 + + + Test + + + + js10 + 6 + + + 10 + + 1500.0 + + + 29700.0 + 32400.0 + + + Test + + + + jsp3 + 7 + + + 0 + + 5594.0 + + + 0.0 + 1.7976931348623157E308 + + + Test + + + + + + + jsp1 + 1 + + 900.0 + + + 0.0 + 1.7976931348623157E308 + + + + + + jsd1 + 8 + + 900.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 0 + + Test + + + + + jsp4 + 9 + + 1200.0 + + + 21600.0 + 23400.0 + + + + + + jsd4 + 8 + + 900.0 + + + 25200.0 + 27000.0 + + + + + 0 + + Test + + + + + jsp7 + 9 + + 1200.0 + + + 37800.0 + 41400.0 + + + + + + jsd7 + 8 + + 1800.0 + + + 43200.0 + 45900.0 + + + + + 0 + + Test + + + + + jsp9 + 10 + + 300.0 + + + 45000.0 + 48600.0 + + + + + + jsd9 + 8 + + 300.0 + + + 50400.0 + 52200.0 + + + + + 0 + + Test + + + diff --git a/jsprit-core/src/test/resources/vrp-solution.json b/jsprit-core/src/test/resources/vrp-solution.json index 11c3bb7f..f3440cbe 100644 --- a/jsprit-core/src/test/resources/vrp-solution.json +++ b/jsprit-core/src/test/resources/vrp-solution.json @@ -1,25 +1,27 @@ { - "solution" : { - "costs" : 84.7213595499958, - "fixed_costs" : 0.0, - "variable_costs" : 84.7213595499958, - "distance" : 84.7213595499958, - "time" : 84.7213595499958, - "no_routes" : 1, - "no_unassigned_jobs" : 0, - "routes" : [ { - "fixed_costs" : 0.0, - "variable_costs" : 84.7213595499958, - "no_activities" : 1, - "start_time" : 0.0, - "act" : { - "type" : "service", - "job_id" : "s", - "arr_time" : 44.721359549995796, - "end_time" : 44.721359549995796 - }, - "end_time" : 84.7213595499958 - } ], - "unassigned_jobs" : [ ] - } -} \ No newline at end of file + "solution": { + "costs": 84.7213595499958, + "fixed_costs": 0.0, + "variable_costs": 84.7213595499958, + "distance": 84.7213595499958, + "time": 84.7213595499958, + "no_routes": 1, + "no_unassigned_jobs": 0, + "routes": [ + { + "fixed_costs": 0.0, + "variable_costs": 84.7213595499958, + "no_activities": 1, + "start_time": 0.0, + "act": { + "type": "service", + "job_id": "s", + "arr_time": 44.721359549995796, + "end_time": 44.721359549995796 + }, + "end_time": 84.7213595499958 + } + ], + "unassigned_jobs": [] + } +} diff --git a/jsprit-core/src/test/resources/vrp.json b/jsprit-core/src/test/resources/vrp.json index b9907a95..58d8119a 100644 --- a/jsprit-core/src/test/resources/vrp.json +++ b/jsprit-core/src/test/resources/vrp.json @@ -1,85 +1,106 @@ { - "meta-info" : { - "distance-unit" : "m", - "time-unit" : "sec" - }, - "vrp" : { - "fleet_size" : "FINITE", - "vehicles" : [ { - "id" : "v1", - "start_address" : { - "id" : "startLoc", - "lon" : 0.0, - "lat" : 0.0 - }, - "return_to_depot" : true, - "end_address" : { - "id" : "endLoc", - "lon" : 12.0, - "lat" : 13.0 - }, - "earliest_start" : 0.0, - "latest_end" : 1000.0, - "type_id" : "small", - "skills" : [ "screw-driver" ] - }, { - "id" : "v2", - "start_address" : { - "id" : "startLoc", - "lon" : 0.0, - "lat" : 0.0 - }, - "return_to_depot" : false, - "earliest_start" : 0.0, - "latest_end" : 1.7976931348623157E308, - "type_id" : "medium", - "skills" : [ "joo" ] - } ], - "vehicle_types" : [ { - "id" : "medium", - "capacity" : [ 1000, 4000 ], - "fixed_costs" : 1000.0, - "distance_dependent_costs" : 1.0, - "time_dependent_costs" : 200.0 - }, { - "id" : "small", - "capacity" : [ 100, 400 ], - "fixed_costs" : 0.0, - "distance_dependent_costs" : 1.0, - "time_dependent_costs" : 20.0 - } ], - "services" : [ { - "id" : "s1", - "type" : "service", - "name" : "no-name", - "address" : { - "id" : "s1_loc", - "lon" : 40.0, - "lat" : 10.0 - }, - "service_duration" : 1.0, - "time_window" : { - "start" : 0.0, - "end" : 1.7976931348623157E308 - }, - "size" : [ 20, 40 ], - "required_skills" : [ "joo-foo" ] - }, { - "id" : "pickup2", - "type" : "pickup", - "name" : "no-name", - "address" : { - "id" : "s2_loc", - "lon" : 40.0, - "lat" : 10.0 - }, - "service_duration" : 2.0, - "time_window" : { - "start" : 10.0, - "end" : 200.0 - }, - "size" : [ 10, 30 ], - "required_skills" : [ "screw-driver" ] - } ] - } -} \ No newline at end of file + "meta-info": { + "distance-unit": "m", + "time-unit": "sec" + }, + "vrp": { + "fleet_size": "FINITE", + "vehicles": [ + { + "id": "v1", + "start_address": { + "id": "startLoc", + "lon": 0.0, + "lat": 0.0 + }, + "return_to_depot": true, + "end_address": { + "id": "endLoc", + "lon": 12.0, + "lat": 13.0 + }, + "earliest_start": 0.0, + "latest_end": 1000.0, + "type_id": "small", + "skills": ["screw-driver"] + }, + { + "id": "v2", + "start_address": { + "id": "startLoc", + "lon": 0.0, + "lat": 0.0 + }, + "return_to_depot": false, + "earliest_start": 0.0, + "latest_end": 1.7976931348623157E308, + "type_id": "medium", + "skills": ["joo"] + } + ], + "vehicle_types": [ + { + "id": "medium", + "capacity": [ + 1000, + 4000 + ], + "fixed_costs": 1000.0, + "distance_dependent_costs": 1.0, + "time_dependent_costs": 200.0 + }, + { + "id": "small", + "capacity": [ + 100, + 400 + ], + "fixed_costs": 0.0, + "distance_dependent_costs": 1.0, + "time_dependent_costs": 20.0 + } + ], + "services": [ + { + "id": "s1", + "type": "service", + "name": "no-name", + "address": { + "id": "s1_loc", + "lon": 40.0, + "lat": 10.0 + }, + "service_duration": 1.0, + "time_window": { + "start": 0.0, + "end": 1.7976931348623157E308 + }, + "size": [ + 20, + 40 + ], + "required_skills": ["joo-foo"] + }, + { + "id": "pickup2", + "type": "pickup", + "name": "no-name", + "address": { + "id": "s2_loc", + "lon": 40.0, + "lat": 10.0 + }, + "service_duration": 2.0, + "time_window": { + "start": 10.0, + "end": 200.0 + }, + "size": [ + 10, + 30 + ], + "required_skills": ["screw-driver"] + } + ] + } +} diff --git a/jsprit-core/src/test/resources/vrpnc1-jsprit-with-deliveries.xml b/jsprit-core/src/test/resources/vrpnc1-jsprit-with-deliveries.xml index 1b617120..9e7433f0 100644 --- a/jsprit-core/src/test/resources/vrpnc1-jsprit-with-deliveries.xml +++ b/jsprit-core/src/test/resources/vrpnc1-jsprit-with-deliveries.xml @@ -17,636 +17,637 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~--> - - INFINITE - HOMOGENEOUS - - - - christophidesVehicle - christophidesType - - [x=30.0][y=40.0] - - - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.w3schools.com vrp_xml_schema.xsd"> + + 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 - 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 - - - - + 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-core/src/test/resources/vrpnc1-jsprit-with-pickups.xml b/jsprit-core/src/test/resources/vrpnc1-jsprit-with-pickups.xml index b03b1b51..b972dfcc 100644 --- a/jsprit-core/src/test/resources/vrpnc1-jsprit-with-pickups.xml +++ b/jsprit-core/src/test/resources/vrpnc1-jsprit-with-pickups.xml @@ -17,636 +17,637 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~--> - - INFINITE - HOMOGENEOUS - - - - christophidesVehicle - christophidesType - - [x=30.0][y=40.0] - - - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.w3schools.com vrp_xml_schema.xsd"> + + 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 - 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 - - - - + 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-core/src/test/resources/vrpnc1-jsprit.xml b/jsprit-core/src/test/resources/vrpnc1-jsprit.xml index 5d3ff044..19c20222 100644 --- a/jsprit-core/src/test/resources/vrpnc1-jsprit.xml +++ b/jsprit-core/src/test/resources/vrpnc1-jsprit.xml @@ -1,635 +1,636 @@ - - INFINITE - HOMOGENEOUS - - - - christophidesVehicle - christophidesType - - [x=30.0][y=40.0] - - - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.w3schools.com vrp_xml_schema.xsd"> + + 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 - 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 - - - - + 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/algorithmConfig.xml b/jsprit-examples/input/algorithmConfig.xml index 80b86e3a..0ede01ea 100755 --- a/jsprit-examples/input/algorithmConfig.xml +++ b/jsprit-examples/input/algorithmConfig.xml @@ -18,70 +18,71 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~--> - - 2000 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.w3schools.com algorithm_schema.xsd"> + + 2000 + + + + + + + + + 1 + + + + + 0.2 + 20 + + + + + 0.5 + + + + + + 0.4 + + + + + + + + + + 0.3 + + + + + + 0.4 + + + + + + + + + 0.05 + + + + + + 0.2 + + + + - - - - - - - - 1 - - - - - 0.2 - 20 - - - - - 0.5 - - - - - - 0.4 - - - - - - - - - - 0.3 - - - - - - 0.4 - - - - - - - - - 0.05 - - - - - - 0.2 - - - - - diff --git a/jsprit-examples/input/algorithmConfigWithSchrimpfAcceptance.xml b/jsprit-examples/input/algorithmConfigWithSchrimpfAcceptance.xml index 799b1feb..58e66c0a 100755 --- a/jsprit-examples/input/algorithmConfigWithSchrimpfAcceptance.xml +++ b/jsprit-examples/input/algorithmConfigWithSchrimpfAcceptance.xml @@ -18,54 +18,55 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~--> - - 2000 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.w3schools.com algorithm_schema.xsd"> + + 2000 + + + + + + + 1 + + + + + 0.1 + 20 + + + + + + 0.5 + + + + + + 0.5 + + + + + + + + + + 0.3 + + + + + + 0.5 + + + + - - - - - - 1 - - - - - 0.1 - 20 - - - - - - 0.5 - - - - - - 0.5 - - - - - - - - - - 0.3 - - - - - - 0.5 - - - - - diff --git a/jsprit-examples/input/algorithmConfig_considerFixedCosts.xml b/jsprit-examples/input/algorithmConfig_considerFixedCosts.xml index 1db7d383..fb65a5fa 100755 --- a/jsprit-examples/input/algorithmConfig_considerFixedCosts.xml +++ b/jsprit-examples/input/algorithmConfig_considerFixedCosts.xml @@ -1,56 +1,57 @@ - - 2000 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.w3schools.com algorithm_schema.xsd"> + + 2000 + + + + true + + + + + 1 + + + + + 0.05 + 20 + + + + + + 0.5 + + + + + + 0.5 + + + + + + + + + + 0.3 + + + + + + 0.5 + + + + - - - true - - - - - 1 - - - - - 0.05 - 20 - - - - - - 0.5 - - - - - - 0.5 - - - - - - - - - - 0.3 - - - - - - 0.5 - - - - - diff --git a/jsprit-examples/input/algorithmConfig_considerFixedCosts_routeLevel.xml b/jsprit-examples/input/algorithmConfig_considerFixedCosts_routeLevel.xml index 35c279de..bdd7734b 100755 --- a/jsprit-examples/input/algorithmConfig_considerFixedCosts_routeLevel.xml +++ b/jsprit-examples/input/algorithmConfig_considerFixedCosts_routeLevel.xml @@ -1,57 +1,58 @@ - - 2000 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.w3schools.com algorithm_schema.xsd"> + + 2000 + + + + route + true + + + + + 1 + + + + + 0.05 + 20 + + + + + + 0.5 + + + + + + 0.5 + + + + + + + + + + 0.3 + + + + + + 0.5 + + + + - - - route - true - - - - - 1 - - - - - 0.05 - 20 - - - - - - 0.5 - - - - - - 0.5 - - - - - - - - - - 0.3 - - - - - - 0.5 - - - - - diff --git a/jsprit-examples/input/algorithmConfig_fix.xml b/jsprit-examples/input/algorithmConfig_fix.xml index 7d01a4f3..d29e0791 100755 --- a/jsprit-examples/input/algorithmConfig_fix.xml +++ b/jsprit-examples/input/algorithmConfig_fix.xml @@ -1,49 +1,50 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.w3schools.com algorithm_schema.xsd"> - 2000 - - - - true - - - - - 1 - + 2000 + + + + true + + + + + 1 + + + + + + + + + 0.5 + + + + + 0.5 + + + + + + + + + 0.3 + + + + + 0.5 + + + - - - - - - - 0.5 - - - - - 0.5 - - - - - - - - - 0.3 - - - - - 0.5 - - - - diff --git a/jsprit-examples/input/algorithmConfig_fix_schrimpf.xml b/jsprit-examples/input/algorithmConfig_fix_schrimpf.xml index ab7f6d05..611f7c82 100755 --- a/jsprit-examples/input/algorithmConfig_fix_schrimpf.xml +++ b/jsprit-examples/input/algorithmConfig_fix_schrimpf.xml @@ -1,52 +1,53 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.w3schools.com algorithm_schema.xsd"> - 2000 - - - - true - - - - - 1 - + 2000 + + + + true + + + + + 1 + + + + + + 0.05 + 20 + + + + + 0.5 + + + + + 0.5 + + + + + + + + + 0.3 + + + + + 0.5 + + + - - - - 0.05 - 20 - - - - - 0.5 - - - - - 0.5 - - - - - - - - - 0.3 - - - - - 0.5 - - - - diff --git a/jsprit-examples/input/algorithmConfig_greedyWithRegret.xml b/jsprit-examples/input/algorithmConfig_greedyWithRegret.xml index 17bc0aaf..6a9bd2ab 100755 --- a/jsprit-examples/input/algorithmConfig_greedyWithRegret.xml +++ b/jsprit-examples/input/algorithmConfig_greedyWithRegret.xml @@ -18,49 +18,50 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~--> + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.w3schools.com algorithm_schema.xsd"> - 2000 - - - - - - - - - 1 - + 2000 + + + + + + + + + 1 + + + + + + + + + 0.5 + + + + + 0.5 + + + + + + + + + 0.3 + + + + + 0.5 + + + - - - - - - - 0.5 - - - - - 0.5 - - - - - - - - - 0.3 - - - - - 0.5 - - - - diff --git a/jsprit-examples/input/algorithmConfig_noVehicleSwitch.xml b/jsprit-examples/input/algorithmConfig_noVehicleSwitch.xml index e58e5a6e..8d52d194 100755 --- a/jsprit-examples/input/algorithmConfig_noVehicleSwitch.xml +++ b/jsprit-examples/input/algorithmConfig_noVehicleSwitch.xml @@ -1,68 +1,69 @@ - - 2000 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.w3schools.com algorithm_schema.xsd"> + + 2000 + + + + false + + + + + 1 + + + + + + + + + 0.3 + + + + + + 0.2 + + + + + + + + + + 0.15 + + + + + + 0.2 + + + + + + + + + 0.05 + + + + + + 0.6 + + + + - - - false - - - - - 1 - - - - - - - - - 0.3 - - - - - - 0.2 - - - - - - - - - - 0.15 - - - - - - 0.2 - - - - - - - - - 0.05 - - - - - - 0.6 - - - - - diff --git a/jsprit-examples/input/algorithmConfig_open.xml b/jsprit-examples/input/algorithmConfig_open.xml index b79ffc2a..756b9a75 100755 --- a/jsprit-examples/input/algorithmConfig_open.xml +++ b/jsprit-examples/input/algorithmConfig_open.xml @@ -18,53 +18,54 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~--> - - 20000 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.w3schools.com algorithm_schema.xsd"> + + 20000 + + + + true + + + + + 1 + + + + + 0.2 + 20 + + + + + 0.5 + + + + + + 0.5 + + + + + + + + + 0.3 + + + + + + 0.5 + + + - - - true - - - - - 1 - - - - - 0.2 - 20 - - - - - 0.5 - - - - - - 0.5 - - - - - - - - - 0.3 - - - - - - 0.5 - - - - diff --git a/jsprit-examples/input/algorithmConfig_solomon.xml b/jsprit-examples/input/algorithmConfig_solomon.xml index b34e133a..11d98877 100755 --- a/jsprit-examples/input/algorithmConfig_solomon.xml +++ b/jsprit-examples/input/algorithmConfig_solomon.xml @@ -1,49 +1,50 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.w3schools.com algorithm_schema.xsd"> - 2000 - - - - - - - - - 1 - + 2000 + + + + + + + + + 1 + + + + + + + + + 0.5 + + + + + 0.5 + + + + + + + + + 0.3 + + + + + 0.5 + + + - - - - - - - 0.5 - - - - - 0.5 - - - - - - - - - 0.3 - - - - - 0.5 - - - - diff --git a/jsprit-examples/input/cordeau01.xml b/jsprit-examples/input/cordeau01.xml index 2232742d..085ac195 100644 --- a/jsprit-examples/input/cordeau01.xml +++ b/jsprit-examples/input/cordeau01.xml @@ -1,1030 +1,1031 @@ - - FINITE - HOMOGENEOUS - - - - 2_2_vehicle - 2_type - - [x=30.0][y=40.0] - - - - [x=30.0][y=40.0] - - - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.w3schools.com vrp_xml_schema.xsd"> + + FINITE + HOMOGENEOUS + + + + 2_2_vehicle + 2_type + + [x=30.0][y=40.0] + + + + [x=30.0][y=40.0] + + + + 0.0 + 1.7976931348623157E308 + + true + + + 4_2_vehicle + 4_type + + [x=60.0][y=50.0] + + + + [x=60.0][y=50.0] + + + + 0.0 + 1.7976931348623157E308 + + true + + + 3_1_vehicle + 3_type + + [x=50.0][y=30.0] + + + + [x=50.0][y=30.0] + + + + 0.0 + 1.7976931348623157E308 + + true + + + 4_4_vehicle + 4_type + + [x=60.0][y=50.0] + + + + [x=60.0][y=50.0] + + + + 0.0 + 1.7976931348623157E308 + + true + + + 4_3_vehicle + 4_type + + [x=60.0][y=50.0] + + + + [x=60.0][y=50.0] + + + + 0.0 + 1.7976931348623157E308 + + true + + + 4_1_vehicle + 4_type + + [x=60.0][y=50.0] + + + + [x=60.0][y=50.0] + + + + 0.0 + 1.7976931348623157E308 + + true + + + 1_4_vehicle + 1_type + + [x=20.0][y=20.0] + + + + [x=20.0][y=20.0] + + + + 0.0 + 1.7976931348623157E308 + + true + + + 2_4_vehicle + 2_type + + [x=30.0][y=40.0] + + + + [x=30.0][y=40.0] + + + + 0.0 + 1.7976931348623157E308 + + true + + + 2_3_vehicle + 2_type + + [x=30.0][y=40.0] + + + + [x=30.0][y=40.0] + + + + 0.0 + 1.7976931348623157E308 + + true + + + 1_3_vehicle + 1_type + + [x=20.0][y=20.0] + + + + [x=20.0][y=20.0] + + + + 0.0 + 1.7976931348623157E308 + + true + + + 3_4_vehicle + 3_type + + [x=50.0][y=30.0] + + + + [x=50.0][y=30.0] + + + + 0.0 + 1.7976931348623157E308 + + true + + + 3_2_vehicle + 3_type + + [x=50.0][y=30.0] + + + + [x=50.0][y=30.0] + + + + 0.0 + 1.7976931348623157E308 + + true + + + 2_1_vehicle + 2_type + + [x=30.0][y=40.0] + + + + [x=30.0][y=40.0] + + + + 0.0 + 1.7976931348623157E308 + + true + + + 3_3_vehicle + 3_type + + [x=50.0][y=30.0] + + + + [x=50.0][y=30.0] + + + + 0.0 + 1.7976931348623157E308 + + true + + + 1_2_vehicle + 1_type + + [x=20.0][y=20.0] + + + + [x=20.0][y=20.0] + + + + 0.0 + 1.7976931348623157E308 + + true + + + 1_1_vehicle + 1_type + + [x=20.0][y=20.0] + + + + [x=20.0][y=20.0] + + + + 0.0 + 1.7976931348623157E308 + + true + + + + + 1_type + + 80 + + + 0.0 + 1.0 + + + + + 2_type + + 80 + + + 0.0 + 1.0 + + + + + 3_type + + 80 + + + 0.0 + 1.0 + + + + + 4_type + + 80 + + + 0.0 + 1.0 + + + + + + + 35 + + + 17 + + 0.0 + + 0.0 1.7976931348623157E308 - - true - - - 4_2_vehicle - 4_type - - [x=60.0][y=50.0] - - - - [x=60.0][y=50.0] - - - + + + + + 36 + + + 6 + + 0.0 + + 0.0 1.7976931348623157E308 - - true - - - 3_1_vehicle - 3_type - - [x=50.0][y=30.0] - - - - [x=50.0][y=30.0] - - - + + + + + 33 + + + 23 + + 0.0 + + 0.0 1.7976931348623157E308 - - true - - - 4_4_vehicle - 4_type - - [x=60.0][y=50.0] - - - - [x=60.0][y=50.0] - - - + + + + + 34 + + + 26 + + 0.0 + + 0.0 1.7976931348623157E308 - - true - - - 4_3_vehicle - 4_type - - [x=60.0][y=50.0] - - - - [x=60.0][y=50.0] - - - + + + + + 39 + + + 14 + + 0.0 + + 0.0 1.7976931348623157E308 - - true - - - 4_1_vehicle - 4_type - - [x=60.0][y=50.0] - - - - [x=60.0][y=50.0] - - - + + + + + 37 + + + 9 + + 0.0 + + 0.0 1.7976931348623157E308 - - true - - - 1_4_vehicle - 1_type - - [x=20.0][y=20.0] - - - - [x=20.0][y=20.0] - - - + + + + + 38 + + + 15 + + 0.0 + + 0.0 1.7976931348623157E308 - - true - - - 2_4_vehicle - 2_type - - [x=30.0][y=40.0] - - - - [x=30.0][y=40.0] - - - + + + + + 43 + + + 11 + + 0.0 + + 0.0 1.7976931348623157E308 - - true - - - 2_3_vehicle - 2_type - - [x=30.0][y=40.0] - - - - [x=30.0][y=40.0] - - - + + + + + 42 + + + 13 + + 0.0 + + 0.0 1.7976931348623157E308 - - true - - - 1_3_vehicle - 1_type - - [x=20.0][y=20.0] - - - - [x=20.0][y=20.0] - - - + + + + + 41 + + + 27 + + 0.0 + + 0.0 1.7976931348623157E308 - - true - - - 3_4_vehicle - 3_type - - [x=50.0][y=30.0] - - - - [x=50.0][y=30.0] - - - + + + + + 40 + + + 7 + + 0.0 + + 0.0 1.7976931348623157E308 - - true - - - 3_2_vehicle - 3_type - - [x=50.0][y=30.0] - - - - [x=50.0][y=30.0] - - - + + + + + 22 + + + 8 + + 0.0 + + 0.0 1.7976931348623157E308 - - true - - - 2_1_vehicle - 2_type - - [x=30.0][y=40.0] - - - - [x=30.0][y=40.0] - - - + + + + + 23 + + + 16 + + 0.0 + + 0.0 1.7976931348623157E308 - - true - - - 3_3_vehicle - 3_type - - [x=50.0][y=30.0] - - - - [x=50.0][y=30.0] - - - + + + + + 24 + + + 10 + + 0.0 + + 0.0 1.7976931348623157E308 - - true - - - 1_2_vehicle - 1_type - - [x=20.0][y=20.0] - - - - [x=20.0][y=20.0] - - - + + + + + 25 + + + 28 + + 0.0 + + 0.0 1.7976931348623157E308 - - true - - - 1_1_vehicle - 1_type - - [x=20.0][y=20.0] - - - - [x=20.0][y=20.0] - - - + + + + + 26 + + + 7 + + 0.0 + + 0.0 1.7976931348623157E308 - - true - - - - - 1_type - - 80 - - - 0.0 - 1.0 - - - - - 2_type - - 80 - - - 0.0 - 1.0 - - - - - 3_type - - 80 - - - 0.0 - 1.0 - - - - - 4_type - - 80 - - - 0.0 - 1.0 - - - - - - - 35 - - - 17 - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 36 - - - 6 - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 33 - - - 23 - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 34 - - - 26 - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 39 - - - 14 - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 37 - - - 9 - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 38 - - - 15 - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 43 - - - 11 - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 42 - - - 13 - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 41 - - - 27 - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 40 - - - 7 - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 22 - - - 8 - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 23 - - - 16 - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 24 - - - 10 - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 25 - - - 28 - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 26 - - - 7 - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 27 - - - 15 - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 28 - - - 14 - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 29 - - - 6 - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 3 - - - 16 - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 2 - - - 30 - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 1 - - - 7 - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 7 - - - 19 - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 30 - - - 19 - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 6 - - - 15 - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 5 - - - 21 - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 32 - - - 12 - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 4 - - - 9 - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 31 - - - 11 - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 9 - - - 11 - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 8 - - - 23 - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 19 - - - 9 - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 17 - - - 3 - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 18 - - - 41 - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 15 - - - 10 - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 16 - - - 15 - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 13 - - - 23 - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 14 - - - 21 - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 11 - - - 19 - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 12 - - - 29 - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 21 - - - 8 - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 20 - - - 28 - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 49 - - - 18 - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 48 - - - 17 - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 45 - - - 10 - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 44 - - - 16 - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 47 - - - 25 - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 46 - - - 5 - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 10 - - - 5 - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 50 - - - 10 - - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - + + + + + 27 + + + 15 + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 28 + + + 14 + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 29 + + + 6 + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 3 + + + 16 + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 2 + + + 30 + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 1 + + + 7 + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 7 + + + 19 + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 30 + + + 19 + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 6 + + + 15 + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 5 + + + 21 + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 32 + + + 12 + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 4 + + + 9 + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 31 + + + 11 + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 9 + + + 11 + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 8 + + + 23 + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 19 + + + 9 + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 17 + + + 3 + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 18 + + + 41 + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 15 + + + 10 + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 16 + + + 15 + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 13 + + + 23 + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 14 + + + 21 + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 11 + + + 19 + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 12 + + + 29 + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 21 + + + 8 + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 20 + + + 28 + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 49 + + + 18 + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 48 + + + 17 + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 45 + + + 10 + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 44 + + + 16 + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 47 + + + 25 + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 46 + + + 5 + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 10 + + + 5 + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 50 + + + 10 + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + diff --git a/jsprit-examples/input/cordeau_p01.xml b/jsprit-examples/input/cordeau_p01.xml index 10970505..992d6c82 100644 --- a/jsprit-examples/input/cordeau_p01.xml +++ b/jsprit-examples/input/cordeau_p01.xml @@ -1,842 +1,843 @@ - - INFINITE - HOMOGENEOUS - - - - 1_1_cordeauVehicle - 1_cordeauType - - [x=20.0][y=20.0] - - - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.w3schools.com vrp_xml_schema.xsd"> + + INFINITE + HOMOGENEOUS + + + + 1_1_cordeauVehicle + 1_cordeauType + + [x=20.0][y=20.0] + + + + 0.0 + 999999.0 + + + + 1_2_cordeauVehicle + 1_cordeauType + + [x=20.0][y=20.0] + + + + 0.0 + 999999.0 + + + + 1_3_cordeauVehicle + 1_cordeauType + + [x=20.0][y=20.0] + + + + 0.0 + 999999.0 + + + + 1_4_cordeauVehicle + 1_cordeauType + + [x=20.0][y=20.0] + + + + 0.0 + 999999.0 + + + + 2_1_cordeauVehicle + 2_cordeauType + + [x=30.0][y=40.0] + + + + 0.0 + 999999.0 + + + + 2_2_cordeauVehicle + 2_cordeauType + + [x=30.0][y=40.0] + + + + 0.0 + 999999.0 + + + + 2_3_cordeauVehicle + 2_cordeauType + + [x=30.0][y=40.0] + + + + 0.0 + 999999.0 + + + + 2_4_cordeauVehicle + 2_cordeauType + + [x=30.0][y=40.0] + + + + 0.0 + 999999.0 + + + + 3_1_cordeauVehicle + 3_cordeauType + + [x=50.0][y=30.0] + + + + 0.0 + 999999.0 + + + + 3_2_cordeauVehicle + 3_cordeauType + + [x=50.0][y=30.0] + + + + 0.0 + 999999.0 + + + + 3_3_cordeauVehicle + 3_cordeauType + + [x=50.0][y=30.0] + + + + 0.0 + 999999.0 + + + + 3_4_cordeauVehicle + 3_cordeauType + + [x=50.0][y=30.0] + + + + 0.0 + 999999.0 + + + + 4_1_cordeauVehicle + 4_cordeauType + + [x=60.0][y=50.0] + + + + 0.0 + 999999.0 + + + + 4_2_cordeauVehicle + 4_cordeauType + + [x=60.0][y=50.0] + + + + 0.0 + 999999.0 + + + + 4_3_cordeauVehicle + 4_cordeauType + + [x=60.0][y=50.0] + + + + 0.0 + 999999.0 + + + + 4_4_cordeauVehicle + 4_cordeauType + + [x=60.0][y=50.0] + + + + 0.0 + 999999.0 + + + + + + 1_cordeauType + 80 + + 0.0 + 1.0 + + + + + 2_cordeauType + 80 + + 0.0 + 1.0 + + + + + 3_cordeauType + 80 + + 0.0 + 1.0 + + + + + 4_cordeauType + 80 + + 0.0 + 1.0 + + + + + + + [x=62.0][y=63.0] + + 17 + 0.0 + + 0.0 - 999999.0 - - - - 1_2_cordeauVehicle - 1_cordeauType - - [x=20.0][y=20.0] - - - + 1.7976931348623157E308 + + + + + [x=63.0][y=69.0] + + 6 + 0.0 + + 0.0 - 999999.0 - - - - 1_3_cordeauVehicle - 1_cordeauType - - [x=20.0][y=20.0] - - - + 1.7976931348623157E308 + + + + + [x=46.0][y=10.0] + + 23 + 0.0 + + 0.0 - 999999.0 - - - - 1_4_cordeauVehicle - 1_cordeauType - - [x=20.0][y=20.0] - - - + 1.7976931348623157E308 + + + + + [x=61.0][y=33.0] + + 26 + 0.0 + + 0.0 - 999999.0 - - - - 2_1_cordeauVehicle - 2_cordeauType - - [x=30.0][y=40.0] - - - + 1.7976931348623157E308 + + + + + [x=59.0][y=15.0] + + 14 + 0.0 + + 0.0 - 999999.0 - - - - 2_2_cordeauVehicle - 2_cordeauType - - [x=30.0][y=40.0] - - - + 1.7976931348623157E308 + + + + + [x=32.0][y=22.0] + + 9 + 0.0 + + 0.0 - 999999.0 - - - - 2_3_cordeauVehicle - 2_cordeauType - - [x=30.0][y=40.0] - - - + 1.7976931348623157E308 + + + + + [x=45.0][y=35.0] + + 15 + 0.0 + + 0.0 - 999999.0 - - - - 2_4_cordeauVehicle - 2_cordeauType - - [x=30.0][y=40.0] - - - + 1.7976931348623157E308 + + + + + [x=5.0][y=64.0] + + 11 + 0.0 + + 0.0 - 999999.0 - - - - 3_1_cordeauVehicle - 3_cordeauType - - [x=50.0][y=30.0] - - - + 1.7976931348623157E308 + + + + + [x=21.0][y=10.0] + + 13 + 0.0 + + 0.0 - 999999.0 - - - - 3_2_cordeauVehicle - 3_cordeauType - - [x=50.0][y=30.0] - - - + 1.7976931348623157E308 + + + + + [x=10.0][y=17.0] + + 27 + 0.0 + + 0.0 - 999999.0 - - - - 3_3_cordeauVehicle - 3_cordeauType - - [x=50.0][y=30.0] - - - + 1.7976931348623157E308 + + + + + [x=5.0][y=6.0] + + 7 + 0.0 + + 0.0 - 999999.0 - - - - 3_4_cordeauVehicle - 3_cordeauType - - [x=50.0][y=30.0] - - - + 1.7976931348623157E308 + + + + + [x=42.0][y=57.0] + + 8 + 0.0 + + 0.0 - 999999.0 - - - - 4_1_cordeauVehicle - 4_cordeauType - - [x=60.0][y=50.0] - - - + 1.7976931348623157E308 + + + + + [x=16.0][y=57.0] + + 16 + 0.0 + + 0.0 - 999999.0 - - - - 4_2_cordeauVehicle - 4_cordeauType - - [x=60.0][y=50.0] - - - + 1.7976931348623157E308 + + + + + [x=8.0][y=52.0] + + 10 + 0.0 + + 0.0 - 999999.0 - - - - 4_3_cordeauVehicle - 4_cordeauType - - [x=60.0][y=50.0] - - - + 1.7976931348623157E308 + + + + + [x=7.0][y=38.0] + + 28 + 0.0 + + 0.0 - 999999.0 - - - - 4_4_cordeauVehicle - 4_cordeauType - - [x=60.0][y=50.0] - - - + 1.7976931348623157E308 + + + + + [x=27.0][y=68.0] + + 7 + 0.0 + + 0.0 - 999999.0 - - - - - - 1_cordeauType - 80 - - 0.0 - 1.0 - - - - - 2_cordeauType - 80 - - 0.0 - 1.0 - - - - - 3_cordeauType - 80 - - 0.0 - 1.0 - - - - - 4_cordeauType - 80 - - 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=58.0][y=27.0] - - 19 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=17.0][y=63.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 - - - - + 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=58.0][y=27.0] + + 19 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=17.0][y=63.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/cordeau_p08.xml b/jsprit-examples/input/cordeau_p08.xml index e2d57e61..ea55a764 100644 --- a/jsprit-examples/input/cordeau_p08.xml +++ b/jsprit-examples/input/cordeau_p08.xml @@ -1,3356 +1,3357 @@ - - INFINITE - HOMOGENEOUS - - - - 1_1_cordeauVehicle - 1_cordeauType - - [x=-33.0][y=33.0] - - - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.w3schools.com vrp_xml_schema.xsd"> + + INFINITE + HOMOGENEOUS + + + + 1_1_cordeauVehicle + 1_cordeauType + + [x=-33.0][y=33.0] + + + + 0.0 + 310.0 + + + + 1_2_cordeauVehicle + 1_cordeauType + + [x=-33.0][y=33.0] + + + + 0.0 + 310.0 + + + + 1_3_cordeauVehicle + 1_cordeauType + + [x=-33.0][y=33.0] + + + + 0.0 + 310.0 + + + + 1_4_cordeauVehicle + 1_cordeauType + + [x=-33.0][y=33.0] + + + + 0.0 + 310.0 + + + + 1_5_cordeauVehicle + 1_cordeauType + + [x=-33.0][y=33.0] + + + + 0.0 + 310.0 + + + + 1_6_cordeauVehicle + 1_cordeauType + + [x=-33.0][y=33.0] + + + + 0.0 + 310.0 + + + + 1_7_cordeauVehicle + 1_cordeauType + + [x=-33.0][y=33.0] + + + + 0.0 + 310.0 + + + + 1_8_cordeauVehicle + 1_cordeauType + + [x=-33.0][y=33.0] + + + + 0.0 + 310.0 + + + + 1_9_cordeauVehicle + 1_cordeauType + + [x=-33.0][y=33.0] + + + + 0.0 + 310.0 + + + + 1_10_cordeauVehicle + 1_cordeauType + + [x=-33.0][y=33.0] + + + + 0.0 + 310.0 + + + + 1_11_cordeauVehicle + 1_cordeauType + + [x=-33.0][y=33.0] + + + + 0.0 + 310.0 + + + + 1_12_cordeauVehicle + 1_cordeauType + + [x=-33.0][y=33.0] + + + + 0.0 + 310.0 + + + + 1_13_cordeauVehicle + 1_cordeauType + + [x=-33.0][y=33.0] + + + + 0.0 + 310.0 + + + + 1_14_cordeauVehicle + 1_cordeauType + + [x=-33.0][y=33.0] + + + + 0.0 + 310.0 + + + + 2_1_cordeauVehicle + 2_cordeauType + + [x=33.0][y=-33.0] + + + + 0.0 + 310.0 + + + + 2_2_cordeauVehicle + 2_cordeauType + + [x=33.0][y=-33.0] + + + + 0.0 + 310.0 + + + + 2_3_cordeauVehicle + 2_cordeauType + + [x=33.0][y=-33.0] + + + + 0.0 + 310.0 + + + + 2_4_cordeauVehicle + 2_cordeauType + + [x=33.0][y=-33.0] + + + + 0.0 + 310.0 + + + + 2_5_cordeauVehicle + 2_cordeauType + + [x=33.0][y=-33.0] + + + + 0.0 + 310.0 + + + + 2_6_cordeauVehicle + 2_cordeauType + + [x=33.0][y=-33.0] + + + + 0.0 + 310.0 + + + + 2_7_cordeauVehicle + 2_cordeauType + + [x=33.0][y=-33.0] + + + + 0.0 + 310.0 + + + + 2_8_cordeauVehicle + 2_cordeauType + + [x=33.0][y=-33.0] + + + + 0.0 + 310.0 + + + + 2_9_cordeauVehicle + 2_cordeauType + + [x=33.0][y=-33.0] + + + + 0.0 + 310.0 + + + + 2_10_cordeauVehicle + 2_cordeauType + + [x=33.0][y=-33.0] + + + + 0.0 + 310.0 + + + + 2_11_cordeauVehicle + 2_cordeauType + + [x=33.0][y=-33.0] + + + + 0.0 + 310.0 + + + + 2_12_cordeauVehicle + 2_cordeauType + + [x=33.0][y=-33.0] + + + + 0.0 + 310.0 + + + + 2_13_cordeauVehicle + 2_cordeauType + + [x=33.0][y=-33.0] + + + + 0.0 + 310.0 + + + + 2_14_cordeauVehicle + 2_cordeauType + + [x=33.0][y=-33.0] + + + + 0.0 + 310.0 + + + + + + 1_cordeauType + 500 + + 0.0 + 1.0 + + + + + 2_cordeauType + 500 + + 0.0 + 1.0 + + + + + + + [x=37.0][y=-90.0] + + 9 + 0.0 + + 0.0 - 310.0 - - - - 1_2_cordeauVehicle - 1_cordeauType - - [x=-33.0][y=33.0] - - - + 1.7976931348623157E308 + + + + + [x=-83.0][y=49.0] + + 74 + 0.0 + + 0.0 - 310.0 - - - - 1_3_cordeauVehicle - 1_cordeauType - - [x=-33.0][y=33.0] - - - + 1.7976931348623157E308 + + + + + [x=-54.0][y=-50.0] + + 47 + 0.0 + + 0.0 - 310.0 - - - - 1_4_cordeauVehicle - 1_cordeauType - - [x=-33.0][y=33.0] - - - + 1.7976931348623157E308 + + + + + [x=99.0][y=81.0] + + 46 + 0.0 + + 0.0 - 310.0 - - - - 1_5_cordeauVehicle - 1_cordeauType - - [x=-33.0][y=33.0] - - - + 1.7976931348623157E308 + + + + + [x=8.0][y=-84.0] + + 57 + 0.0 + + 0.0 - 310.0 - - - - 1_6_cordeauVehicle - 1_cordeauType - - [x=-33.0][y=33.0] - - - + 1.7976931348623157E308 + + + + + [x=93.0][y=49.0] + + 79 + 0.0 + + 0.0 - 310.0 - - - - 1_7_cordeauVehicle - 1_cordeauType - - [x=-33.0][y=33.0] - - - + 1.7976931348623157E308 + + + + + [x=12.0][y=48.0] + + 42 + 0.0 + + 0.0 - 310.0 - - - - 1_8_cordeauVehicle - 1_cordeauType - - [x=-33.0][y=33.0] - - - + 1.7976931348623157E308 + + + + + [x=-17.0][y=49.0] + + 79 + 0.0 + + 0.0 - 310.0 - - - - 1_9_cordeauVehicle - 1_cordeauType - - [x=-33.0][y=33.0] - - - + 1.7976931348623157E308 + + + + + [x=32.0][y=-68.0] + + 97 + 0.0 + + 0.0 - 310.0 - - - - 1_10_cordeauVehicle - 1_cordeauType - - [x=-33.0][y=33.0] - - - + 1.7976931348623157E308 + + + + + [x=35.0][y=-1.0] + + 83 + 0.0 + + 0.0 - 310.0 - - - - 1_11_cordeauVehicle - 1_cordeauType - - [x=-33.0][y=33.0] - - - + 1.7976931348623157E308 + + + + + [x=-44.0][y=-95.0] + + 65 + 0.0 + + 0.0 - 310.0 - - - - 1_12_cordeauVehicle - 1_cordeauType - - [x=-33.0][y=33.0] - - - + 1.7976931348623157E308 + + + + + [x=7.0][y=59.0] + + 96 + 0.0 + + 0.0 - 310.0 - - - - 1_13_cordeauVehicle - 1_cordeauType - - [x=-33.0][y=33.0] - - - + 1.7976931348623157E308 + + + + + [x=-25.0][y=-89.0] + + 97 + 0.0 + + 0.0 - 310.0 - - - - 1_14_cordeauVehicle - 1_cordeauType - - [x=-33.0][y=33.0] - - - + 1.7976931348623157E308 + + + + + [x=39.0][y=-49.0] + + 24 + 0.0 + + 0.0 - 310.0 - - - - 2_1_cordeauVehicle - 2_cordeauType - - [x=33.0][y=-33.0] - - - + 1.7976931348623157E308 + + + + + [x=-67.0][y=72.0] + + 69 + 0.0 + + 0.0 - 310.0 - - - - 2_2_cordeauVehicle - 2_cordeauType - - [x=33.0][y=-33.0] - - - + 1.7976931348623157E308 + + + + + [x=-80.0][y=55.0] + + 83 + 0.0 + + 0.0 - 310.0 - - - - 2_3_cordeauVehicle - 2_cordeauType - - [x=33.0][y=-33.0] - - - + 1.7976931348623157E308 + + + + + [x=81.0][y=-86.0] + + 22 + 0.0 + + 0.0 - 310.0 - - - - 2_4_cordeauVehicle - 2_cordeauType - - [x=33.0][y=-33.0] - - - + 1.7976931348623157E308 + + + + + [x=-7.0][y=52.0] + + 43 + 0.0 + + 0.0 - 310.0 - - - - 2_5_cordeauVehicle - 2_cordeauType - - [x=33.0][y=-33.0] - - - + 1.7976931348623157E308 + + + + + [x=-3.0][y=97.0] + + 56 + 0.0 + + 0.0 - 310.0 - - - - 2_6_cordeauVehicle - 2_cordeauType - - [x=33.0][y=-33.0] - - - + 1.7976931348623157E308 + + + + + [x=92.0][y=28.0] + + 22 + 0.0 + + 0.0 - 310.0 - - - - 2_7_cordeauVehicle - 2_cordeauType - - [x=33.0][y=-33.0] - - - + 1.7976931348623157E308 + + + + + [x=57.0][y=95.0] + + 80 + 0.0 + + 0.0 - 310.0 - - - - 2_8_cordeauVehicle - 2_cordeauType - - [x=33.0][y=-33.0] - - - + 1.7976931348623157E308 + + + + + [x=-73.0][y=-96.0] + + 92 + 0.0 + + 0.0 - 310.0 - - - - 2_9_cordeauVehicle - 2_cordeauType - - [x=33.0][y=-33.0] - - - + 1.7976931348623157E308 + + + + + [x=-29.0][y=72.0] + + 1 + 0.0 + + 0.0 - 310.0 - - - - 2_10_cordeauVehicle - 2_cordeauType - - [x=33.0][y=-33.0] - - - + 1.7976931348623157E308 + + + + + [x=-47.0][y=12.0] + + 2 + 0.0 + + 0.0 - 310.0 - - - - 2_11_cordeauVehicle - 2_cordeauType - - [x=33.0][y=-33.0] - - - + 1.7976931348623157E308 + + + + + [x=-88.0][y=-61.0] + + 63 + 0.0 + + 0.0 - 310.0 - - - - 2_12_cordeauVehicle - 2_cordeauType - - [x=33.0][y=-33.0] - - - + 1.7976931348623157E308 + + + + + [x=50.0][y=-37.0] + + 11 + 0.0 + + 0.0 - 310.0 - - - - 2_13_cordeauVehicle - 2_cordeauType - - [x=33.0][y=-33.0] - - - + 1.7976931348623157E308 + + + + + [x=59.0][y=71.0] + + 98 + 0.0 + + 0.0 - 310.0 - - - - 2_14_cordeauVehicle - 2_cordeauType - - [x=33.0][y=-33.0] - - - + 1.7976931348623157E308 + + + + + [x=54.0][y=-21.0] + + 40 + 0.0 + + 0.0 - 310.0 - - - - - - 1_cordeauType - 500 - - 0.0 - 1.0 - - - - - 2_cordeauType - 500 - - 0.0 - 1.0 - - - - - - - [x=37.0][y=-90.0] - - 9 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-83.0][y=49.0] - - 74 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-54.0][y=-50.0] - - 47 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=99.0][y=81.0] - - 46 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=8.0][y=-84.0] - - 57 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=93.0][y=49.0] - - 79 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=12.0][y=48.0] - - 42 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-17.0][y=49.0] - - 79 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=32.0][y=-68.0] - - 97 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=35.0][y=-1.0] - - 83 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-44.0][y=-95.0] - - 65 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=7.0][y=59.0] - - 96 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-25.0][y=-89.0] - - 97 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=39.0][y=-49.0] - - 24 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-67.0][y=72.0] - - 69 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-80.0][y=55.0] - - 83 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=81.0][y=-86.0] - - 22 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-7.0][y=52.0] - - 43 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-3.0][y=97.0] - - 56 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=92.0][y=28.0] - - 22 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=57.0][y=95.0] - - 80 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-73.0][y=-96.0] - - 92 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-29.0][y=72.0] - - 1 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-47.0][y=12.0] - - 2 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-88.0][y=-61.0] - - 63 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=50.0][y=-37.0] - - 11 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=59.0][y=71.0] - - 98 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=54.0][y=-21.0] - - 40 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=64.0][y=-17.0] - - 8 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=40.0][y=27.0] - - 49 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=55.0][y=89.0] - - 69 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=17.0][y=-25.0] - - 93 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-88.0][y=36.0] - - 57 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-61.0][y=66.0] - - 29 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-42.0][y=-6.0] - - 23 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-46.0][y=-3.0] - - 50 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-61.0][y=26.0] - - 5 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=38.0][y=8.0] - - 3 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=26.0][y=-37.0] - - 19 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=17.0][y=-72.0] - - 53 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=19.0][y=93.0] - - 40 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-39.0][y=-67.0] - - 24 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=79.0][y=38.0] - - 8 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-67.0][y=88.0] - - 19 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=0.0][y=14.0] - - 93 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=63.0][y=-41.0] - - 39 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-59.0][y=50.0] - - 72 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=38.0][y=39.0] - - 94 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-28.0][y=39.0] - - 97 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-99.0][y=-97.0] - - 6 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-2.0][y=-47.0] - - 18 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-62.0][y=-2.0] - - 24 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=5.0][y=-41.0] - - 1 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=31.0][y=12.0] - - 43 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=52.0][y=66.0] - - 13 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-69.0][y=-19.0] - - 5 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=10.0][y=-49.0] - - 52 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-90.0][y=-68.0] - - 53 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-17.0][y=-66.0] - - 28 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-64.0][y=70.0] - - 53 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-12.0][y=10.0] - - 36 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-80.0][y=-31.0] - - 18 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=93.0][y=-50.0] - - 77 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=92.0][y=27.0] - - 14 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-4.0][y=-7.0] - - 49 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=54.0][y=-48.0] - - 58 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-47.0][y=-26.0] - - 88 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-20.0][y=-5.0] - - 28 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-22.0][y=73.0] - - 72 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=60.0][y=-39.0] - - 59 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=42.0][y=96.0] - - 51 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=29.0][y=41.0] - - 41 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=91.0][y=15.0] - - 84 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-65.0][y=0.0] - - 47 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-16.0][y=36.0] - - 36 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=24.0][y=41.0] - - 66 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-70.0][y=39.0] - - 84 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=25.0][y=58.0] - - 10 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=17.0][y=21.0] - - 37 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=54.0][y=-82.0] - - 58 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-53.0][y=88.0] - - 57 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=83.0][y=-24.0] - - 1 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-18.0][y=64.0] - - 25 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-77.0][y=-16.0] - - 50 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-61.0][y=56.0] - - 96 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-35.0][y=-54.0] - - 48 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=43.0][y=33.0] - - 58 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=85.0][y=36.0] - - 75 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=75.0][y=-18.0] - - 56 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=31.0][y=85.0] - - 67 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-18.0][y=-39.0] - - 15 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-69.0][y=19.0] - - 21 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-87.0][y=51.0] - - 98 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-96.0][y=-36.0] - - 77 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=49.0][y=8.0] - - 57 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-5.0][y=54.0] - - 39 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-26.0][y=43.0] - - 99 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-11.0][y=60.0] - - 83 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=40.0][y=61.0] - - 54 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=82.0][y=35.0] - - 86 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-92.0][y=12.0] - - 2 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=0.0][y=-78.0] - - 18 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-93.0][y=-86.0] - - 14 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=69.0][y=-46.0] - - 99 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-84.0][y=74.0] - - 55 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=49.0][y=-47.0] - - 85 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-12.0][y=85.0] - - 63 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=42.0][y=33.0] - - 60 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=16.0][y=-81.0] - - 33 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-78.0][y=53.0] - - 62 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=53.0][y=-80.0] - - 70 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-46.0][y=-26.0] - - 79 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-25.0][y=-54.0] - - 98 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=7.0][y=-4.0] - - 5 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-61.0][y=-26.0] - - 48 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=95.0][y=-9.0] - - 93 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=51.0][y=70.0] - - 31 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-53.0][y=62.0] - - 78 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=79.0][y=-62.0] - - 8 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-28.0][y=-71.0] - - 64 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-24.0][y=4.0] - - 71 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=11.0][y=96.0] - - 85 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=91.0][y=36.0] - - 50 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=62.0][y=-8.0] - - 42 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-3.0][y=17.0] - - 18 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=53.0][y=-90.0] - - 38 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-20.0][y=51.0] - - 99 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-81.0][y=37.0] - - 29 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=6.0][y=94.0] - - 3 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-19.0][y=-62.0] - - 52 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=83.0][y=-91.0] - - 98 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-7.0][y=-92.0] - - 4 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=7.0][y=31.0] - - 12 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=52.0][y=12.0] - - 50 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=60.0][y=58.0] - - 56 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-43.0][y=47.0] - - 86 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=14.0][y=89.0] - - 56 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=6.0][y=-6.0] - - 2 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-18.0][y=34.0] - - 39 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=70.0][y=99.0] - - 31 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-63.0][y=-75.0] - - 9 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=68.0][y=-29.0] - - 54 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-83.0][y=84.0] - - 81 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-1.0][y=49.0] - - 4 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-4.0][y=17.0] - - 23 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-82.0][y=-3.0] - - 11 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-94.0][y=-30.0] - - 87 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-46.0][y=-82.0] - - 15 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-86.0][y=-79.0] - - 4 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=58.0][y=-19.0] - - 29 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-43.0][y=-30.0] - - 58 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-44.0][y=7.0] - - 73 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-3.0][y=-20.0] - - 5 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=36.0][y=41.0] - - 12 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-30.0][y=-94.0] - - 3 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=88.0][y=65.0] - - 50 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=2.0][y=29.0] - - 25 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=64.0][y=37.0] - - 72 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=41.0][y=42.0] - - 90 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-70.0][y=-19.0] - - 10 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-76.0][y=55.0] - - 62 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-38.0][y=-56.0] - - 51 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-28.0][y=73.0] - - 100 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-80.0][y=-95.0] - - 29 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=7.0][y=73.0] - - 37 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=33.0][y=57.0] - - 71 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=28.0][y=93.0] - - 5 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-70.0][y=6.0] - - 85 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-37.0][y=46.0] - - 60 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-97.0][y=35.0] - - 95 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-12.0][y=42.0] - - 37 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=51.0][y=-45.0] - - 80 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=92.0][y=40.0] - - 57 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-21.0][y=77.0] - - 81 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-84.0][y=-29.0] - - 44 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-94.0][y=-20.0] - - 17 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-82.0][y=-14.0] - - 79 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=76.0][y=-22.0] - - 38 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=69.0][y=-19.0] - - 79 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=49.0][y=-71.0] - - 11 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-30.0][y=-68.0] - - 82 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=1.0][y=34.0] - - 50 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=77.0][y=-43.0] - - 73 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=77.0][y=79.0] - - 39 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=42.0][y=-15.0] - - 12 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-58.0][y=64.0] - - 6 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=25.0][y=91.0] - - 8 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=82.0][y=-97.0] - - 87 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=59.0][y=-49.0] - - 32 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=69.0][y=59.0] - - 14 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=29.0][y=33.0] - - 17 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-97.0][y=9.0] - - 19 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-58.0][y=9.0] - - 44 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-5.0][y=-39.0] - - 55 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-61.0][y=-76.0] - - 100 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=8.0][y=-22.0] - - 45 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=74.0][y=-70.0] - - 4 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=86.0][y=35.0] - - 68 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-40.0][y=-84.0] - - 77 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=93.0][y=-29.0] - - 42 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-96.0][y=85.0] - - 39 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=64.0][y=20.0] - - 25 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=1.0][y=-17.0] - - 93 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=15.0][y=98.0] - - 74 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=20.0][y=42.0] - - 84 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-46.0][y=-79.0] - - 21 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-42.0][y=63.0] - - 33 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-30.0][y=-63.0] - - 99 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=92.0][y=-17.0] - - 84 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=66.0][y=39.0] - - 71 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-36.0][y=4.0] - - 26 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=9.0][y=-79.0] - - 72 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=78.0][y=-87.0] - - 36 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=66.0][y=-48.0] - - 4 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=85.0][y=11.0] - - 98 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=71.0][y=-61.0] - - 45 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-83.0][y=-30.0] - - 33 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=82.0][y=-74.0] - - 56 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-70.0][y=85.0] - - 24 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=98.0][y=-17.0] - - 53 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-16.0][y=62.0] - - 15 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-55.0][y=39.0] - - 19 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=5.0][y=97.0] - - 19 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=0.0][y=95.0] - - 35 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=70.0][y=-14.0] - - 90 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-63.0][y=-14.0] - - 94 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-16.0][y=16.0] - - 75 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-39.0][y=61.0] - - 13 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=51.0][y=-77.0] - - 89 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-45.0][y=7.0] - - 76 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=38.0][y=-24.0] - - 3 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=70.0][y=-80.0] - - 92 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-38.0][y=-81.0] - - 78 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=26.0][y=22.0] - - 98 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=3.0][y=66.0] - - 36 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-14.0][y=44.0] - - 50 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-77.0][y=80.0] - - 43 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=96.0][y=-83.0] - - 64 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=17.0][y=-35.0] - - 65 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-66.0][y=63.0] - - 42 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=44.0][y=-84.0] - - 96 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-57.0][y=-84.0] - - 55 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-72.0][y=-87.0] - - 14 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-56.0][y=-62.0] - - 18 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=23.0][y=52.0] - - 2 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=63.0][y=-14.0] - - 22 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-19.0][y=59.0] - - 17 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-19.0][y=87.0] - - 3 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=-13.0][y=38.0] - - 28 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - + 1.7976931348623157E308 + + + + + [x=64.0][y=-17.0] + + 8 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=40.0][y=27.0] + + 49 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=55.0][y=89.0] + + 69 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=17.0][y=-25.0] + + 93 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-88.0][y=36.0] + + 57 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-61.0][y=66.0] + + 29 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-42.0][y=-6.0] + + 23 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-46.0][y=-3.0] + + 50 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-61.0][y=26.0] + + 5 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=38.0][y=8.0] + + 3 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=26.0][y=-37.0] + + 19 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=17.0][y=-72.0] + + 53 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=19.0][y=93.0] + + 40 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-39.0][y=-67.0] + + 24 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=79.0][y=38.0] + + 8 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-67.0][y=88.0] + + 19 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=0.0][y=14.0] + + 93 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=63.0][y=-41.0] + + 39 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-59.0][y=50.0] + + 72 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=38.0][y=39.0] + + 94 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-28.0][y=39.0] + + 97 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-99.0][y=-97.0] + + 6 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-2.0][y=-47.0] + + 18 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-62.0][y=-2.0] + + 24 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=5.0][y=-41.0] + + 1 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=31.0][y=12.0] + + 43 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=52.0][y=66.0] + + 13 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-69.0][y=-19.0] + + 5 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=10.0][y=-49.0] + + 52 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-90.0][y=-68.0] + + 53 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-17.0][y=-66.0] + + 28 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-64.0][y=70.0] + + 53 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-12.0][y=10.0] + + 36 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-80.0][y=-31.0] + + 18 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=93.0][y=-50.0] + + 77 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=92.0][y=27.0] + + 14 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-4.0][y=-7.0] + + 49 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=54.0][y=-48.0] + + 58 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-47.0][y=-26.0] + + 88 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-20.0][y=-5.0] + + 28 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-22.0][y=73.0] + + 72 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=60.0][y=-39.0] + + 59 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=42.0][y=96.0] + + 51 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=29.0][y=41.0] + + 41 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=91.0][y=15.0] + + 84 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-65.0][y=0.0] + + 47 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-16.0][y=36.0] + + 36 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=24.0][y=41.0] + + 66 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-70.0][y=39.0] + + 84 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=25.0][y=58.0] + + 10 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=17.0][y=21.0] + + 37 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=54.0][y=-82.0] + + 58 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-53.0][y=88.0] + + 57 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=83.0][y=-24.0] + + 1 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-18.0][y=64.0] + + 25 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-77.0][y=-16.0] + + 50 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-61.0][y=56.0] + + 96 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-35.0][y=-54.0] + + 48 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=43.0][y=33.0] + + 58 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=85.0][y=36.0] + + 75 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=75.0][y=-18.0] + + 56 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=31.0][y=85.0] + + 67 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-18.0][y=-39.0] + + 15 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-69.0][y=19.0] + + 21 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-87.0][y=51.0] + + 98 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-96.0][y=-36.0] + + 77 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=49.0][y=8.0] + + 57 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-5.0][y=54.0] + + 39 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-26.0][y=43.0] + + 99 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-11.0][y=60.0] + + 83 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=40.0][y=61.0] + + 54 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=82.0][y=35.0] + + 86 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-92.0][y=12.0] + + 2 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=0.0][y=-78.0] + + 18 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-93.0][y=-86.0] + + 14 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=69.0][y=-46.0] + + 99 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-84.0][y=74.0] + + 55 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=49.0][y=-47.0] + + 85 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-12.0][y=85.0] + + 63 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=42.0][y=33.0] + + 60 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=16.0][y=-81.0] + + 33 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-78.0][y=53.0] + + 62 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=53.0][y=-80.0] + + 70 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-46.0][y=-26.0] + + 79 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-25.0][y=-54.0] + + 98 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=7.0][y=-4.0] + + 5 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-61.0][y=-26.0] + + 48 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=95.0][y=-9.0] + + 93 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=51.0][y=70.0] + + 31 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-53.0][y=62.0] + + 78 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=79.0][y=-62.0] + + 8 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-28.0][y=-71.0] + + 64 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-24.0][y=4.0] + + 71 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=11.0][y=96.0] + + 85 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=91.0][y=36.0] + + 50 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=62.0][y=-8.0] + + 42 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-3.0][y=17.0] + + 18 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=53.0][y=-90.0] + + 38 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-20.0][y=51.0] + + 99 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-81.0][y=37.0] + + 29 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=6.0][y=94.0] + + 3 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-19.0][y=-62.0] + + 52 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=83.0][y=-91.0] + + 98 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-7.0][y=-92.0] + + 4 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=7.0][y=31.0] + + 12 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=52.0][y=12.0] + + 50 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=60.0][y=58.0] + + 56 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-43.0][y=47.0] + + 86 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=14.0][y=89.0] + + 56 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=6.0][y=-6.0] + + 2 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-18.0][y=34.0] + + 39 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=70.0][y=99.0] + + 31 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-63.0][y=-75.0] + + 9 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=68.0][y=-29.0] + + 54 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-83.0][y=84.0] + + 81 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-1.0][y=49.0] + + 4 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-4.0][y=17.0] + + 23 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-82.0][y=-3.0] + + 11 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-94.0][y=-30.0] + + 87 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-46.0][y=-82.0] + + 15 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-86.0][y=-79.0] + + 4 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=58.0][y=-19.0] + + 29 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-43.0][y=-30.0] + + 58 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-44.0][y=7.0] + + 73 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-3.0][y=-20.0] + + 5 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=36.0][y=41.0] + + 12 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-30.0][y=-94.0] + + 3 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=88.0][y=65.0] + + 50 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=2.0][y=29.0] + + 25 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=64.0][y=37.0] + + 72 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=41.0][y=42.0] + + 90 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-70.0][y=-19.0] + + 10 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-76.0][y=55.0] + + 62 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-38.0][y=-56.0] + + 51 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-28.0][y=73.0] + + 100 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-80.0][y=-95.0] + + 29 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=7.0][y=73.0] + + 37 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=33.0][y=57.0] + + 71 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=28.0][y=93.0] + + 5 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-70.0][y=6.0] + + 85 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-37.0][y=46.0] + + 60 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-97.0][y=35.0] + + 95 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-12.0][y=42.0] + + 37 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=51.0][y=-45.0] + + 80 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=92.0][y=40.0] + + 57 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-21.0][y=77.0] + + 81 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-84.0][y=-29.0] + + 44 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-94.0][y=-20.0] + + 17 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-82.0][y=-14.0] + + 79 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=76.0][y=-22.0] + + 38 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=69.0][y=-19.0] + + 79 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=49.0][y=-71.0] + + 11 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-30.0][y=-68.0] + + 82 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=1.0][y=34.0] + + 50 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=77.0][y=-43.0] + + 73 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=77.0][y=79.0] + + 39 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=42.0][y=-15.0] + + 12 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-58.0][y=64.0] + + 6 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=25.0][y=91.0] + + 8 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=82.0][y=-97.0] + + 87 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=59.0][y=-49.0] + + 32 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=69.0][y=59.0] + + 14 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=29.0][y=33.0] + + 17 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-97.0][y=9.0] + + 19 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-58.0][y=9.0] + + 44 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-5.0][y=-39.0] + + 55 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-61.0][y=-76.0] + + 100 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=8.0][y=-22.0] + + 45 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=74.0][y=-70.0] + + 4 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=86.0][y=35.0] + + 68 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-40.0][y=-84.0] + + 77 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=93.0][y=-29.0] + + 42 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-96.0][y=85.0] + + 39 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=64.0][y=20.0] + + 25 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=1.0][y=-17.0] + + 93 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=15.0][y=98.0] + + 74 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=20.0][y=42.0] + + 84 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-46.0][y=-79.0] + + 21 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-42.0][y=63.0] + + 33 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-30.0][y=-63.0] + + 99 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=92.0][y=-17.0] + + 84 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=66.0][y=39.0] + + 71 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-36.0][y=4.0] + + 26 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=9.0][y=-79.0] + + 72 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=78.0][y=-87.0] + + 36 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=66.0][y=-48.0] + + 4 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=85.0][y=11.0] + + 98 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=71.0][y=-61.0] + + 45 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-83.0][y=-30.0] + + 33 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=82.0][y=-74.0] + + 56 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-70.0][y=85.0] + + 24 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=98.0][y=-17.0] + + 53 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-16.0][y=62.0] + + 15 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-55.0][y=39.0] + + 19 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=5.0][y=97.0] + + 19 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=0.0][y=95.0] + + 35 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=70.0][y=-14.0] + + 90 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-63.0][y=-14.0] + + 94 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-16.0][y=16.0] + + 75 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-39.0][y=61.0] + + 13 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=51.0][y=-77.0] + + 89 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-45.0][y=7.0] + + 76 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=38.0][y=-24.0] + + 3 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=70.0][y=-80.0] + + 92 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-38.0][y=-81.0] + + 78 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=26.0][y=22.0] + + 98 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=3.0][y=66.0] + + 36 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-14.0][y=44.0] + + 50 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-77.0][y=80.0] + + 43 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=96.0][y=-83.0] + + 64 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=17.0][y=-35.0] + + 65 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-66.0][y=63.0] + + 42 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=44.0][y=-84.0] + + 96 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-57.0][y=-84.0] + + 55 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-72.0][y=-87.0] + + 14 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-56.0][y=-62.0] + + 18 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=23.0][y=52.0] + + 2 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=63.0][y=-14.0] + + 22 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-19.0][y=59.0] + + 17 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-19.0][y=87.0] + + 3 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=-13.0][y=38.0] + + 28 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + diff --git a/jsprit-examples/input/deliveries_solomon_c101.xml b/jsprit-examples/input/deliveries_solomon_c101.xml index 00b54342..58718e65 100644 --- a/jsprit-examples/input/deliveries_solomon_c101.xml +++ b/jsprit-examples/input/deliveries_solomon_c101.xml @@ -1,1235 +1,1236 @@ - - INFINITE - HOMOGENEOUS - - - - solomonVehicle - solomonType - - 0 - - - - 0.0 - 1236.0 - - - - - - solomonType - 200 - - 0.0 - 1.0 - - - - - - - [x=5.0][y=35.0] - - 10 - 90.0 - - - 283.0 - 344.0 - - - - - [x=5.0][y=45.0] - - 10 - 90.0 - - - 665.0 - 716.0 - - - - - [x=8.0][y=40.0] - - 40 - 90.0 - - - 87.0 - 158.0 - - - - - [x=8.0][y=45.0] - - 20 - 90.0 - - - 751.0 - 816.0 - - - - - [x=0.0][y=45.0] - - 20 - 90.0 - - - 567.0 - 624.0 - - - - - [x=2.0][y=40.0] - - 20 - 90.0 - - - 383.0 - 434.0 - - - - - [x=0.0][y=40.0] - - 30 - 90.0 - - - 479.0 - 522.0 - - - - - [x=33.0][y=35.0] - - 10 - 90.0 - - - 16.0 - 80.0 - - - - - [x=33.0][y=32.0] - - 20 - 90.0 - - - 68.0 - 149.0 - - - - - [x=35.0][y=32.0] - - 10 - 90.0 - - - 166.0 - 235.0 - - - - - [x=35.0][y=30.0] - - 10 - 90.0 - - - 264.0 - 321.0 - - - - - [x=28.0][y=52.0] - - 20 - 90.0 - - - 812.0 - 883.0 - - - - - [x=28.0][y=55.0] - - 10 - 90.0 - - - 732.0 - 777.0 - - - - - [x=25.0][y=50.0] - - 10 - 90.0 - - - 65.0 - 144.0 - - - - - [x=25.0][y=52.0] - - 40 - 90.0 - - - 169.0 - 224.0 - - - - - [x=25.0][y=55.0] - - 10 - 90.0 - - - 622.0 - 701.0 - - - - - [x=23.0][y=52.0] - - 10 - 90.0 - - - 261.0 - 316.0 - - - - - [x=23.0][y=55.0] - - 20 - 90.0 - - - 546.0 - 593.0 - - - - - [x=20.0][y=50.0] - - 10 - 90.0 - - - 358.0 - 405.0 - - - - - [x=42.0][y=66.0] - - 10 - 90.0 - - - 65.0 - 146.0 - - - - - [x=45.0][y=70.0] - - 30 - 90.0 - - - 825.0 - 870.0 - - - - - [x=45.0][y=68.0] - - 10 - 90.0 - - - 912.0 - 967.0 - - - - - [x=20.0][y=55.0] - - 10 - 90.0 - - - 449.0 - 504.0 - - - - - [x=40.0][y=66.0] - - 20 - 90.0 - - - 170.0 - 225.0 - - - - - [x=40.0][y=69.0] - - 20 - 90.0 - - - 621.0 - 702.0 - - - - - [x=42.0][y=65.0] - - 10 - 90.0 - - - 15.0 - 67.0 - - - - - [x=10.0][y=40.0] - - 30 - 90.0 - - - 31.0 - 100.0 - - - - - [x=42.0][y=68.0] - - 10 - 90.0 - - - 727.0 - 782.0 - - - - - [x=10.0][y=35.0] - - 20 - 90.0 - - - 200.0 - 237.0 - - - - - [x=38.0][y=70.0] - - 10 - 90.0 - - - 534.0 - 605.0 - - - - - [x=38.0][y=68.0] - - 20 - 90.0 - - - 255.0 - 324.0 - - - - - [x=15.0][y=80.0] - - 10 - 90.0 - - - 278.0 - 345.0 - - - - - [x=18.0][y=75.0] - - 20 - 90.0 - - - 99.0 - 148.0 - - - - - [x=15.0][y=75.0] - - 20 - 90.0 - - - 179.0 - 254.0 - - - - - [x=20.0][y=80.0] - - 40 - 90.0 - - - 384.0 - 429.0 - - - - - [x=20.0][y=85.0] - - 40 - 90.0 - - - 475.0 - 528.0 - - - - - [x=22.0][y=75.0] - - 30 - 90.0 - - - 30.0 - 92.0 - - - - - [x=22.0][y=85.0] - - 10 - 90.0 - - - 567.0 - 620.0 - - - - - [x=35.0][y=69.0] - - 10 - 90.0 - - - 448.0 - 505.0 - - - - - [x=25.0][y=85.0] - - 20 - 90.0 - - - 652.0 - 721.0 - - - - - [x=30.0][y=52.0] - - 20 - 90.0 - - - 914.0 - 965.0 - - - - - [x=30.0][y=50.0] - - 10 - 90.0 - - - 10.0 - 73.0 - - - - - [x=55.0][y=80.0] - - 10 - 90.0 - - - 743.0 - 820.0 - - - - - [x=55.0][y=85.0] - - 20 - 90.0 - - - 647.0 - 726.0 - - - - - [x=58.0][y=75.0] - - 20 - 90.0 - - - 30.0 - 84.0 - - - - - [x=60.0][y=85.0] - - 30 - 90.0 - - - 561.0 - 622.0 - - - - - [x=60.0][y=80.0] - - 10 - 90.0 - - - 95.0 - 156.0 - - - - - [x=62.0][y=80.0] - - 30 - 90.0 - - - 196.0 - 239.0 - - - - - [x=65.0][y=82.0] - - 10 - 90.0 - - - 285.0 - 336.0 - - - - - [x=65.0][y=85.0] - - 40 - 90.0 - - - 475.0 - 518.0 - - - - - [x=67.0][y=85.0] - - 20 - 90.0 - - - 368.0 - 441.0 - - - - - [x=60.0][y=60.0] - - 10 - 90.0 - - - 836.0 - 889.0 - - - - - [x=60.0][y=55.0] - - 10 - 90.0 - - - 20.0 - 84.0 - - - - - [x=35.0][y=66.0] - - 10 - 90.0 - - - 357.0 - 410.0 - - - - - [x=65.0][y=60.0] - - 30 - 90.0 - - - 645.0 - 708.0 - - - - - [x=63.0][y=58.0] - - 10 - 90.0 - - - 737.0 - 802.0 - - - - - [x=87.0][y=30.0] - - 10 - 90.0 - - - 668.0 - 731.0 - - - - - [x=88.0][y=35.0] - - 20 - 90.0 - - - 109.0 - 170.0 - - - - - [x=88.0][y=30.0] - - 10 - 90.0 - - - 574.0 - 643.0 - - - - - [x=75.0][y=55.0] - - 20 - 90.0 - - - 369.0 - 420.0 - - - - - [x=72.0][y=55.0] - - 10 - 90.0 - - - 265.0 - 338.0 - - - - - [x=85.0][y=25.0] - - 10 - 90.0 - - - 769.0 - 820.0 - - - - - [x=85.0][y=35.0] - - 30 - 90.0 - - - 47.0 - 124.0 - - - - - [x=66.0][y=55.0] - - 10 - 90.0 - - - 173.0 - 238.0 - - - - - [x=65.0][y=55.0] - - 20 - 90.0 - - - 85.0 - 144.0 - - - - - [x=70.0][y=58.0] - - 20 - 90.0 - - - 458.0 - 523.0 - - - - - [x=68.0][y=60.0] - - 30 - 90.0 - - - 555.0 - 612.0 - - - - - [x=47.0][y=40.0] - - 10 - 90.0 - - - 12.0 - 77.0 - - - - - [x=47.0][y=35.0] - - 10 - 90.0 - - - 826.0 - 875.0 - - - - - [x=45.0][y=35.0] - - 10 - 90.0 - - - 916.0 - 969.0 - - - - - [x=45.0][y=30.0] - - 10 - 90.0 - - - 734.0 - 777.0 - - - - - [x=95.0][y=30.0] - - 30 - 90.0 - - - 387.0 - 456.0 - - - - - [x=95.0][y=35.0] - - 20 - 90.0 - - - 293.0 - 360.0 - - - - - [x=53.0][y=30.0] - - 10 - 90.0 - - - 450.0 - 505.0 - - - - - [x=92.0][y=30.0] - - 10 - 90.0 - - - 478.0 - 551.0 - - - - - [x=53.0][y=35.0] - - 50 - 90.0 - - - 353.0 - 412.0 - - - - - [x=45.0][y=65.0] - - 20 - 90.0 - - - 997.0 - 1068.0 - - - - - [x=90.0][y=35.0] - - 10 - 90.0 - - - 203.0 - 260.0 - - - - - [x=38.0][y=15.0] - - 10 - 90.0 - - - 651.0 - 740.0 - - - - - [x=38.0][y=5.0] - - 30 - 90.0 - - - 471.0 - 534.0 - - - - - [x=40.0][y=15.0] - - 40 - 90.0 - - - 35.0 - 87.0 - - - - - [x=40.0][y=5.0] - - 30 - 90.0 - - - 385.0 - 436.0 - - - - - [x=42.0][y=15.0] - - 10 - 90.0 - - - 95.0 - 158.0 - - - - - [x=48.0][y=30.0] - - 10 - 90.0 - - - 632.0 - 693.0 - - - - - [x=48.0][y=40.0] - - 10 - 90.0 - - - 76.0 - 129.0 - - - - - [x=50.0][y=35.0] - - 20 - 90.0 - - - 262.0 - 317.0 - - - - - [x=50.0][y=40.0] - - 50 - 90.0 - - - 171.0 - 218.0 - - - - - [x=35.0][y=5.0] - - 20 - 90.0 - - - 562.0 - 629.0 - - - - - [x=50.0][y=30.0] - - 10 - 90.0 - - - 531.0 - 610.0 - - - - - [x=28.0][y=35.0] - - 10 - 90.0 - - - 1001.0 - 1066.0 - - - - - [x=28.0][y=30.0] - - 10 - 90.0 - - - 632.0 - 693.0 - - - - - [x=30.0][y=30.0] - - 10 - 90.0 - - - 541.0 - 600.0 - - - - - [x=32.0][y=30.0] - - 10 - 90.0 - - - 359.0 - 412.0 - - - - - [x=30.0][y=35.0] - - 10 - 90.0 - - - 1054.0 - 1127.0 - - - - - [x=30.0][y=32.0] - - 30 - 90.0 - - - 448.0 - 509.0 - - - - - [x=25.0][y=30.0] - - 10 - 90.0 - - - 725.0 - 786.0 - - - - - [x=25.0][y=35.0] - - 10 - 90.0 - - - 912.0 - 969.0 - - - - - [x=44.0][y=5.0] - - 20 - 90.0 - - - 286.0 - 347.0 - - - - - [x=42.0][y=10.0] - - 40 - 90.0 - - - 186.0 - 257.0 - - - - - [x=26.0][y=32.0] - - 10 - 90.0 - - - 815.0 - 880.0 - - - - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.w3schools.com vrp_xml_schema.xsd"> + + INFINITE + HOMOGENEOUS + + + + solomonVehicle + solomonType + + 0 + + + + 0.0 + 1236.0 + + + + + + solomonType + 200 + + 0.0 + 1.0 + + + + + + + [x=5.0][y=35.0] + + 10 + 90.0 + + + 283.0 + 344.0 + + + + + [x=5.0][y=45.0] + + 10 + 90.0 + + + 665.0 + 716.0 + + + + + [x=8.0][y=40.0] + + 40 + 90.0 + + + 87.0 + 158.0 + + + + + [x=8.0][y=45.0] + + 20 + 90.0 + + + 751.0 + 816.0 + + + + + [x=0.0][y=45.0] + + 20 + 90.0 + + + 567.0 + 624.0 + + + + + [x=2.0][y=40.0] + + 20 + 90.0 + + + 383.0 + 434.0 + + + + + [x=0.0][y=40.0] + + 30 + 90.0 + + + 479.0 + 522.0 + + + + + [x=33.0][y=35.0] + + 10 + 90.0 + + + 16.0 + 80.0 + + + + + [x=33.0][y=32.0] + + 20 + 90.0 + + + 68.0 + 149.0 + + + + + [x=35.0][y=32.0] + + 10 + 90.0 + + + 166.0 + 235.0 + + + + + [x=35.0][y=30.0] + + 10 + 90.0 + + + 264.0 + 321.0 + + + + + [x=28.0][y=52.0] + + 20 + 90.0 + + + 812.0 + 883.0 + + + + + [x=28.0][y=55.0] + + 10 + 90.0 + + + 732.0 + 777.0 + + + + + [x=25.0][y=50.0] + + 10 + 90.0 + + + 65.0 + 144.0 + + + + + [x=25.0][y=52.0] + + 40 + 90.0 + + + 169.0 + 224.0 + + + + + [x=25.0][y=55.0] + + 10 + 90.0 + + + 622.0 + 701.0 + + + + + [x=23.0][y=52.0] + + 10 + 90.0 + + + 261.0 + 316.0 + + + + + [x=23.0][y=55.0] + + 20 + 90.0 + + + 546.0 + 593.0 + + + + + [x=20.0][y=50.0] + + 10 + 90.0 + + + 358.0 + 405.0 + + + + + [x=42.0][y=66.0] + + 10 + 90.0 + + + 65.0 + 146.0 + + + + + [x=45.0][y=70.0] + + 30 + 90.0 + + + 825.0 + 870.0 + + + + + [x=45.0][y=68.0] + + 10 + 90.0 + + + 912.0 + 967.0 + + + + + [x=20.0][y=55.0] + + 10 + 90.0 + + + 449.0 + 504.0 + + + + + [x=40.0][y=66.0] + + 20 + 90.0 + + + 170.0 + 225.0 + + + + + [x=40.0][y=69.0] + + 20 + 90.0 + + + 621.0 + 702.0 + + + + + [x=42.0][y=65.0] + + 10 + 90.0 + + + 15.0 + 67.0 + + + + + [x=10.0][y=40.0] + + 30 + 90.0 + + + 31.0 + 100.0 + + + + + [x=42.0][y=68.0] + + 10 + 90.0 + + + 727.0 + 782.0 + + + + + [x=10.0][y=35.0] + + 20 + 90.0 + + + 200.0 + 237.0 + + + + + [x=38.0][y=70.0] + + 10 + 90.0 + + + 534.0 + 605.0 + + + + + [x=38.0][y=68.0] + + 20 + 90.0 + + + 255.0 + 324.0 + + + + + [x=15.0][y=80.0] + + 10 + 90.0 + + + 278.0 + 345.0 + + + + + [x=18.0][y=75.0] + + 20 + 90.0 + + + 99.0 + 148.0 + + + + + [x=15.0][y=75.0] + + 20 + 90.0 + + + 179.0 + 254.0 + + + + + [x=20.0][y=80.0] + + 40 + 90.0 + + + 384.0 + 429.0 + + + + + [x=20.0][y=85.0] + + 40 + 90.0 + + + 475.0 + 528.0 + + + + + [x=22.0][y=75.0] + + 30 + 90.0 + + + 30.0 + 92.0 + + + + + [x=22.0][y=85.0] + + 10 + 90.0 + + + 567.0 + 620.0 + + + + + [x=35.0][y=69.0] + + 10 + 90.0 + + + 448.0 + 505.0 + + + + + [x=25.0][y=85.0] + + 20 + 90.0 + + + 652.0 + 721.0 + + + + + [x=30.0][y=52.0] + + 20 + 90.0 + + + 914.0 + 965.0 + + + + + [x=30.0][y=50.0] + + 10 + 90.0 + + + 10.0 + 73.0 + + + + + [x=55.0][y=80.0] + + 10 + 90.0 + + + 743.0 + 820.0 + + + + + [x=55.0][y=85.0] + + 20 + 90.0 + + + 647.0 + 726.0 + + + + + [x=58.0][y=75.0] + + 20 + 90.0 + + + 30.0 + 84.0 + + + + + [x=60.0][y=85.0] + + 30 + 90.0 + + + 561.0 + 622.0 + + + + + [x=60.0][y=80.0] + + 10 + 90.0 + + + 95.0 + 156.0 + + + + + [x=62.0][y=80.0] + + 30 + 90.0 + + + 196.0 + 239.0 + + + + + [x=65.0][y=82.0] + + 10 + 90.0 + + + 285.0 + 336.0 + + + + + [x=65.0][y=85.0] + + 40 + 90.0 + + + 475.0 + 518.0 + + + + + [x=67.0][y=85.0] + + 20 + 90.0 + + + 368.0 + 441.0 + + + + + [x=60.0][y=60.0] + + 10 + 90.0 + + + 836.0 + 889.0 + + + + + [x=60.0][y=55.0] + + 10 + 90.0 + + + 20.0 + 84.0 + + + + + [x=35.0][y=66.0] + + 10 + 90.0 + + + 357.0 + 410.0 + + + + + [x=65.0][y=60.0] + + 30 + 90.0 + + + 645.0 + 708.0 + + + + + [x=63.0][y=58.0] + + 10 + 90.0 + + + 737.0 + 802.0 + + + + + [x=87.0][y=30.0] + + 10 + 90.0 + + + 668.0 + 731.0 + + + + + [x=88.0][y=35.0] + + 20 + 90.0 + + + 109.0 + 170.0 + + + + + [x=88.0][y=30.0] + + 10 + 90.0 + + + 574.0 + 643.0 + + + + + [x=75.0][y=55.0] + + 20 + 90.0 + + + 369.0 + 420.0 + + + + + [x=72.0][y=55.0] + + 10 + 90.0 + + + 265.0 + 338.0 + + + + + [x=85.0][y=25.0] + + 10 + 90.0 + + + 769.0 + 820.0 + + + + + [x=85.0][y=35.0] + + 30 + 90.0 + + + 47.0 + 124.0 + + + + + [x=66.0][y=55.0] + + 10 + 90.0 + + + 173.0 + 238.0 + + + + + [x=65.0][y=55.0] + + 20 + 90.0 + + + 85.0 + 144.0 + + + + + [x=70.0][y=58.0] + + 20 + 90.0 + + + 458.0 + 523.0 + + + + + [x=68.0][y=60.0] + + 30 + 90.0 + + + 555.0 + 612.0 + + + + + [x=47.0][y=40.0] + + 10 + 90.0 + + + 12.0 + 77.0 + + + + + [x=47.0][y=35.0] + + 10 + 90.0 + + + 826.0 + 875.0 + + + + + [x=45.0][y=35.0] + + 10 + 90.0 + + + 916.0 + 969.0 + + + + + [x=45.0][y=30.0] + + 10 + 90.0 + + + 734.0 + 777.0 + + + + + [x=95.0][y=30.0] + + 30 + 90.0 + + + 387.0 + 456.0 + + + + + [x=95.0][y=35.0] + + 20 + 90.0 + + + 293.0 + 360.0 + + + + + [x=53.0][y=30.0] + + 10 + 90.0 + + + 450.0 + 505.0 + + + + + [x=92.0][y=30.0] + + 10 + 90.0 + + + 478.0 + 551.0 + + + + + [x=53.0][y=35.0] + + 50 + 90.0 + + + 353.0 + 412.0 + + + + + [x=45.0][y=65.0] + + 20 + 90.0 + + + 997.0 + 1068.0 + + + + + [x=90.0][y=35.0] + + 10 + 90.0 + + + 203.0 + 260.0 + + + + + [x=38.0][y=15.0] + + 10 + 90.0 + + + 651.0 + 740.0 + + + + + [x=38.0][y=5.0] + + 30 + 90.0 + + + 471.0 + 534.0 + + + + + [x=40.0][y=15.0] + + 40 + 90.0 + + + 35.0 + 87.0 + + + + + [x=40.0][y=5.0] + + 30 + 90.0 + + + 385.0 + 436.0 + + + + + [x=42.0][y=15.0] + + 10 + 90.0 + + + 95.0 + 158.0 + + + + + [x=48.0][y=30.0] + + 10 + 90.0 + + + 632.0 + 693.0 + + + + + [x=48.0][y=40.0] + + 10 + 90.0 + + + 76.0 + 129.0 + + + + + [x=50.0][y=35.0] + + 20 + 90.0 + + + 262.0 + 317.0 + + + + + [x=50.0][y=40.0] + + 50 + 90.0 + + + 171.0 + 218.0 + + + + + [x=35.0][y=5.0] + + 20 + 90.0 + + + 562.0 + 629.0 + + + + + [x=50.0][y=30.0] + + 10 + 90.0 + + + 531.0 + 610.0 + + + + + [x=28.0][y=35.0] + + 10 + 90.0 + + + 1001.0 + 1066.0 + + + + + [x=28.0][y=30.0] + + 10 + 90.0 + + + 632.0 + 693.0 + + + + + [x=30.0][y=30.0] + + 10 + 90.0 + + + 541.0 + 600.0 + + + + + [x=32.0][y=30.0] + + 10 + 90.0 + + + 359.0 + 412.0 + + + + + [x=30.0][y=35.0] + + 10 + 90.0 + + + 1054.0 + 1127.0 + + + + + [x=30.0][y=32.0] + + 30 + 90.0 + + + 448.0 + 509.0 + + + + + [x=25.0][y=30.0] + + 10 + 90.0 + + + 725.0 + 786.0 + + + + + [x=25.0][y=35.0] + + 10 + 90.0 + + + 912.0 + 969.0 + + + + + [x=44.0][y=5.0] + + 20 + 90.0 + + + 286.0 + 347.0 + + + + + [x=42.0][y=10.0] + + 40 + 90.0 + + + 186.0 + 257.0 + + + + + [x=26.0][y=32.0] + + 10 + 90.0 + + + 815.0 + 880.0 + + + + diff --git a/jsprit-examples/input/deliveries_solomon_open_c101.xml b/jsprit-examples/input/deliveries_solomon_open_c101.xml index 6dd2ab3f..dda2728e 100644 --- a/jsprit-examples/input/deliveries_solomon_open_c101.xml +++ b/jsprit-examples/input/deliveries_solomon_open_c101.xml @@ -1,1236 +1,1237 @@ - - INFINITE - HOMOGENEOUS - - - - solomonVehicle - solomonType - - 0 - - - - 0.0 - 1236.0 - - false - - - - - solomonType - 200 - - 0.0 - 1.0 - - - - - - - [x=5.0][y=35.0] - - 10 - 90.0 - - - 283.0 - 344.0 - - - - - [x=5.0][y=45.0] - - 10 - 90.0 - - - 665.0 - 716.0 - - - - - [x=8.0][y=40.0] - - 40 - 90.0 - - - 87.0 - 158.0 - - - - - [x=8.0][y=45.0] - - 20 - 90.0 - - - 751.0 - 816.0 - - - - - [x=0.0][y=45.0] - - 20 - 90.0 - - - 567.0 - 624.0 - - - - - [x=2.0][y=40.0] - - 20 - 90.0 - - - 383.0 - 434.0 - - - - - [x=0.0][y=40.0] - - 30 - 90.0 - - - 479.0 - 522.0 - - - - - [x=33.0][y=35.0] - - 10 - 90.0 - - - 16.0 - 80.0 - - - - - [x=33.0][y=32.0] - - 20 - 90.0 - - - 68.0 - 149.0 - - - - - [x=35.0][y=32.0] - - 10 - 90.0 - - - 166.0 - 235.0 - - - - - [x=35.0][y=30.0] - - 10 - 90.0 - - - 264.0 - 321.0 - - - - - [x=28.0][y=52.0] - - 20 - 90.0 - - - 812.0 - 883.0 - - - - - [x=28.0][y=55.0] - - 10 - 90.0 - - - 732.0 - 777.0 - - - - - [x=25.0][y=50.0] - - 10 - 90.0 - - - 65.0 - 144.0 - - - - - [x=25.0][y=52.0] - - 40 - 90.0 - - - 169.0 - 224.0 - - - - - [x=25.0][y=55.0] - - 10 - 90.0 - - - 622.0 - 701.0 - - - - - [x=23.0][y=52.0] - - 10 - 90.0 - - - 261.0 - 316.0 - - - - - [x=23.0][y=55.0] - - 20 - 90.0 - - - 546.0 - 593.0 - - - - - [x=20.0][y=50.0] - - 10 - 90.0 - - - 358.0 - 405.0 - - - - - [x=42.0][y=66.0] - - 10 - 90.0 - - - 65.0 - 146.0 - - - - - [x=45.0][y=70.0] - - 30 - 90.0 - - - 825.0 - 870.0 - - - - - [x=45.0][y=68.0] - - 10 - 90.0 - - - 912.0 - 967.0 - - - - - [x=20.0][y=55.0] - - 10 - 90.0 - - - 449.0 - 504.0 - - - - - [x=40.0][y=66.0] - - 20 - 90.0 - - - 170.0 - 225.0 - - - - - [x=40.0][y=69.0] - - 20 - 90.0 - - - 621.0 - 702.0 - - - - - [x=42.0][y=65.0] - - 10 - 90.0 - - - 15.0 - 67.0 - - - - - [x=10.0][y=40.0] - - 30 - 90.0 - - - 31.0 - 100.0 - - - - - [x=42.0][y=68.0] - - 10 - 90.0 - - - 727.0 - 782.0 - - - - - [x=10.0][y=35.0] - - 20 - 90.0 - - - 200.0 - 237.0 - - - - - [x=38.0][y=70.0] - - 10 - 90.0 - - - 534.0 - 605.0 - - - - - [x=38.0][y=68.0] - - 20 - 90.0 - - - 255.0 - 324.0 - - - - - [x=15.0][y=80.0] - - 10 - 90.0 - - - 278.0 - 345.0 - - - - - [x=18.0][y=75.0] - - 20 - 90.0 - - - 99.0 - 148.0 - - - - - [x=15.0][y=75.0] - - 20 - 90.0 - - - 179.0 - 254.0 - - - - - [x=20.0][y=80.0] - - 40 - 90.0 - - - 384.0 - 429.0 - - - - - [x=20.0][y=85.0] - - 40 - 90.0 - - - 475.0 - 528.0 - - - - - [x=22.0][y=75.0] - - 30 - 90.0 - - - 30.0 - 92.0 - - - - - [x=22.0][y=85.0] - - 10 - 90.0 - - - 567.0 - 620.0 - - - - - [x=35.0][y=69.0] - - 10 - 90.0 - - - 448.0 - 505.0 - - - - - [x=25.0][y=85.0] - - 20 - 90.0 - - - 652.0 - 721.0 - - - - - [x=30.0][y=52.0] - - 20 - 90.0 - - - 914.0 - 965.0 - - - - - [x=30.0][y=50.0] - - 10 - 90.0 - - - 10.0 - 73.0 - - - - - [x=55.0][y=80.0] - - 10 - 90.0 - - - 743.0 - 820.0 - - - - - [x=55.0][y=85.0] - - 20 - 90.0 - - - 647.0 - 726.0 - - - - - [x=58.0][y=75.0] - - 20 - 90.0 - - - 30.0 - 84.0 - - - - - [x=60.0][y=85.0] - - 30 - 90.0 - - - 561.0 - 622.0 - - - - - [x=60.0][y=80.0] - - 10 - 90.0 - - - 95.0 - 156.0 - - - - - [x=62.0][y=80.0] - - 30 - 90.0 - - - 196.0 - 239.0 - - - - - [x=65.0][y=82.0] - - 10 - 90.0 - - - 285.0 - 336.0 - - - - - [x=65.0][y=85.0] - - 40 - 90.0 - - - 475.0 - 518.0 - - - - - [x=67.0][y=85.0] - - 20 - 90.0 - - - 368.0 - 441.0 - - - - - [x=60.0][y=60.0] - - 10 - 90.0 - - - 836.0 - 889.0 - - - - - [x=60.0][y=55.0] - - 10 - 90.0 - - - 20.0 - 84.0 - - - - - [x=35.0][y=66.0] - - 10 - 90.0 - - - 357.0 - 410.0 - - - - - [x=65.0][y=60.0] - - 30 - 90.0 - - - 645.0 - 708.0 - - - - - [x=63.0][y=58.0] - - 10 - 90.0 - - - 737.0 - 802.0 - - - - - [x=87.0][y=30.0] - - 10 - 90.0 - - - 668.0 - 731.0 - - - - - [x=88.0][y=35.0] - - 20 - 90.0 - - - 109.0 - 170.0 - - - - - [x=88.0][y=30.0] - - 10 - 90.0 - - - 574.0 - 643.0 - - - - - [x=75.0][y=55.0] - - 20 - 90.0 - - - 369.0 - 420.0 - - - - - [x=72.0][y=55.0] - - 10 - 90.0 - - - 265.0 - 338.0 - - - - - [x=85.0][y=25.0] - - 10 - 90.0 - - - 769.0 - 820.0 - - - - - [x=85.0][y=35.0] - - 30 - 90.0 - - - 47.0 - 124.0 - - - - - [x=66.0][y=55.0] - - 10 - 90.0 - - - 173.0 - 238.0 - - - - - [x=65.0][y=55.0] - - 20 - 90.0 - - - 85.0 - 144.0 - - - - - [x=70.0][y=58.0] - - 20 - 90.0 - - - 458.0 - 523.0 - - - - - [x=68.0][y=60.0] - - 30 - 90.0 - - - 555.0 - 612.0 - - - - - [x=47.0][y=40.0] - - 10 - 90.0 - - - 12.0 - 77.0 - - - - - [x=47.0][y=35.0] - - 10 - 90.0 - - - 826.0 - 875.0 - - - - - [x=45.0][y=35.0] - - 10 - 90.0 - - - 916.0 - 969.0 - - - - - [x=45.0][y=30.0] - - 10 - 90.0 - - - 734.0 - 777.0 - - - - - [x=95.0][y=30.0] - - 30 - 90.0 - - - 387.0 - 456.0 - - - - - [x=95.0][y=35.0] - - 20 - 90.0 - - - 293.0 - 360.0 - - - - - [x=53.0][y=30.0] - - 10 - 90.0 - - - 450.0 - 505.0 - - - - - [x=92.0][y=30.0] - - 10 - 90.0 - - - 478.0 - 551.0 - - - - - [x=53.0][y=35.0] - - 50 - 90.0 - - - 353.0 - 412.0 - - - - - [x=45.0][y=65.0] - - 20 - 90.0 - - - 997.0 - 1068.0 - - - - - [x=90.0][y=35.0] - - 10 - 90.0 - - - 203.0 - 260.0 - - - - - [x=38.0][y=15.0] - - 10 - 90.0 - - - 651.0 - 740.0 - - - - - [x=38.0][y=5.0] - - 30 - 90.0 - - - 471.0 - 534.0 - - - - - [x=40.0][y=15.0] - - 40 - 90.0 - - - 35.0 - 87.0 - - - - - [x=40.0][y=5.0] - - 30 - 90.0 - - - 385.0 - 436.0 - - - - - [x=42.0][y=15.0] - - 10 - 90.0 - - - 95.0 - 158.0 - - - - - [x=48.0][y=30.0] - - 10 - 90.0 - - - 632.0 - 693.0 - - - - - [x=48.0][y=40.0] - - 10 - 90.0 - - - 76.0 - 129.0 - - - - - [x=50.0][y=35.0] - - 20 - 90.0 - - - 262.0 - 317.0 - - - - - [x=50.0][y=40.0] - - 50 - 90.0 - - - 171.0 - 218.0 - - - - - [x=35.0][y=5.0] - - 20 - 90.0 - - - 562.0 - 629.0 - - - - - [x=50.0][y=30.0] - - 10 - 90.0 - - - 531.0 - 610.0 - - - - - [x=28.0][y=35.0] - - 10 - 90.0 - - - 1001.0 - 1066.0 - - - - - [x=28.0][y=30.0] - - 10 - 90.0 - - - 632.0 - 693.0 - - - - - [x=30.0][y=30.0] - - 10 - 90.0 - - - 541.0 - 600.0 - - - - - [x=32.0][y=30.0] - - 10 - 90.0 - - - 359.0 - 412.0 - - - - - [x=30.0][y=35.0] - - 10 - 90.0 - - - 1054.0 - 1127.0 - - - - - [x=30.0][y=32.0] - - 30 - 90.0 - - - 448.0 - 509.0 - - - - - [x=25.0][y=30.0] - - 10 - 90.0 - - - 725.0 - 786.0 - - - - - [x=25.0][y=35.0] - - 10 - 90.0 - - - 912.0 - 969.0 - - - - - [x=44.0][y=5.0] - - 20 - 90.0 - - - 286.0 - 347.0 - - - - - [x=42.0][y=10.0] - - 40 - 90.0 - - - 186.0 - 257.0 - - - - - [x=26.0][y=32.0] - - 10 - 90.0 - - - 815.0 - 880.0 - - - - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.w3schools.com vrp_xml_schema.xsd"> + + INFINITE + HOMOGENEOUS + + + + solomonVehicle + solomonType + + 0 + + + + 0.0 + 1236.0 + + false + + + + + solomonType + 200 + + 0.0 + 1.0 + + + + + + + [x=5.0][y=35.0] + + 10 + 90.0 + + + 283.0 + 344.0 + + + + + [x=5.0][y=45.0] + + 10 + 90.0 + + + 665.0 + 716.0 + + + + + [x=8.0][y=40.0] + + 40 + 90.0 + + + 87.0 + 158.0 + + + + + [x=8.0][y=45.0] + + 20 + 90.0 + + + 751.0 + 816.0 + + + + + [x=0.0][y=45.0] + + 20 + 90.0 + + + 567.0 + 624.0 + + + + + [x=2.0][y=40.0] + + 20 + 90.0 + + + 383.0 + 434.0 + + + + + [x=0.0][y=40.0] + + 30 + 90.0 + + + 479.0 + 522.0 + + + + + [x=33.0][y=35.0] + + 10 + 90.0 + + + 16.0 + 80.0 + + + + + [x=33.0][y=32.0] + + 20 + 90.0 + + + 68.0 + 149.0 + + + + + [x=35.0][y=32.0] + + 10 + 90.0 + + + 166.0 + 235.0 + + + + + [x=35.0][y=30.0] + + 10 + 90.0 + + + 264.0 + 321.0 + + + + + [x=28.0][y=52.0] + + 20 + 90.0 + + + 812.0 + 883.0 + + + + + [x=28.0][y=55.0] + + 10 + 90.0 + + + 732.0 + 777.0 + + + + + [x=25.0][y=50.0] + + 10 + 90.0 + + + 65.0 + 144.0 + + + + + [x=25.0][y=52.0] + + 40 + 90.0 + + + 169.0 + 224.0 + + + + + [x=25.0][y=55.0] + + 10 + 90.0 + + + 622.0 + 701.0 + + + + + [x=23.0][y=52.0] + + 10 + 90.0 + + + 261.0 + 316.0 + + + + + [x=23.0][y=55.0] + + 20 + 90.0 + + + 546.0 + 593.0 + + + + + [x=20.0][y=50.0] + + 10 + 90.0 + + + 358.0 + 405.0 + + + + + [x=42.0][y=66.0] + + 10 + 90.0 + + + 65.0 + 146.0 + + + + + [x=45.0][y=70.0] + + 30 + 90.0 + + + 825.0 + 870.0 + + + + + [x=45.0][y=68.0] + + 10 + 90.0 + + + 912.0 + 967.0 + + + + + [x=20.0][y=55.0] + + 10 + 90.0 + + + 449.0 + 504.0 + + + + + [x=40.0][y=66.0] + + 20 + 90.0 + + + 170.0 + 225.0 + + + + + [x=40.0][y=69.0] + + 20 + 90.0 + + + 621.0 + 702.0 + + + + + [x=42.0][y=65.0] + + 10 + 90.0 + + + 15.0 + 67.0 + + + + + [x=10.0][y=40.0] + + 30 + 90.0 + + + 31.0 + 100.0 + + + + + [x=42.0][y=68.0] + + 10 + 90.0 + + + 727.0 + 782.0 + + + + + [x=10.0][y=35.0] + + 20 + 90.0 + + + 200.0 + 237.0 + + + + + [x=38.0][y=70.0] + + 10 + 90.0 + + + 534.0 + 605.0 + + + + + [x=38.0][y=68.0] + + 20 + 90.0 + + + 255.0 + 324.0 + + + + + [x=15.0][y=80.0] + + 10 + 90.0 + + + 278.0 + 345.0 + + + + + [x=18.0][y=75.0] + + 20 + 90.0 + + + 99.0 + 148.0 + + + + + [x=15.0][y=75.0] + + 20 + 90.0 + + + 179.0 + 254.0 + + + + + [x=20.0][y=80.0] + + 40 + 90.0 + + + 384.0 + 429.0 + + + + + [x=20.0][y=85.0] + + 40 + 90.0 + + + 475.0 + 528.0 + + + + + [x=22.0][y=75.0] + + 30 + 90.0 + + + 30.0 + 92.0 + + + + + [x=22.0][y=85.0] + + 10 + 90.0 + + + 567.0 + 620.0 + + + + + [x=35.0][y=69.0] + + 10 + 90.0 + + + 448.0 + 505.0 + + + + + [x=25.0][y=85.0] + + 20 + 90.0 + + + 652.0 + 721.0 + + + + + [x=30.0][y=52.0] + + 20 + 90.0 + + + 914.0 + 965.0 + + + + + [x=30.0][y=50.0] + + 10 + 90.0 + + + 10.0 + 73.0 + + + + + [x=55.0][y=80.0] + + 10 + 90.0 + + + 743.0 + 820.0 + + + + + [x=55.0][y=85.0] + + 20 + 90.0 + + + 647.0 + 726.0 + + + + + [x=58.0][y=75.0] + + 20 + 90.0 + + + 30.0 + 84.0 + + + + + [x=60.0][y=85.0] + + 30 + 90.0 + + + 561.0 + 622.0 + + + + + [x=60.0][y=80.0] + + 10 + 90.0 + + + 95.0 + 156.0 + + + + + [x=62.0][y=80.0] + + 30 + 90.0 + + + 196.0 + 239.0 + + + + + [x=65.0][y=82.0] + + 10 + 90.0 + + + 285.0 + 336.0 + + + + + [x=65.0][y=85.0] + + 40 + 90.0 + + + 475.0 + 518.0 + + + + + [x=67.0][y=85.0] + + 20 + 90.0 + + + 368.0 + 441.0 + + + + + [x=60.0][y=60.0] + + 10 + 90.0 + + + 836.0 + 889.0 + + + + + [x=60.0][y=55.0] + + 10 + 90.0 + + + 20.0 + 84.0 + + + + + [x=35.0][y=66.0] + + 10 + 90.0 + + + 357.0 + 410.0 + + + + + [x=65.0][y=60.0] + + 30 + 90.0 + + + 645.0 + 708.0 + + + + + [x=63.0][y=58.0] + + 10 + 90.0 + + + 737.0 + 802.0 + + + + + [x=87.0][y=30.0] + + 10 + 90.0 + + + 668.0 + 731.0 + + + + + [x=88.0][y=35.0] + + 20 + 90.0 + + + 109.0 + 170.0 + + + + + [x=88.0][y=30.0] + + 10 + 90.0 + + + 574.0 + 643.0 + + + + + [x=75.0][y=55.0] + + 20 + 90.0 + + + 369.0 + 420.0 + + + + + [x=72.0][y=55.0] + + 10 + 90.0 + + + 265.0 + 338.0 + + + + + [x=85.0][y=25.0] + + 10 + 90.0 + + + 769.0 + 820.0 + + + + + [x=85.0][y=35.0] + + 30 + 90.0 + + + 47.0 + 124.0 + + + + + [x=66.0][y=55.0] + + 10 + 90.0 + + + 173.0 + 238.0 + + + + + [x=65.0][y=55.0] + + 20 + 90.0 + + + 85.0 + 144.0 + + + + + [x=70.0][y=58.0] + + 20 + 90.0 + + + 458.0 + 523.0 + + + + + [x=68.0][y=60.0] + + 30 + 90.0 + + + 555.0 + 612.0 + + + + + [x=47.0][y=40.0] + + 10 + 90.0 + + + 12.0 + 77.0 + + + + + [x=47.0][y=35.0] + + 10 + 90.0 + + + 826.0 + 875.0 + + + + + [x=45.0][y=35.0] + + 10 + 90.0 + + + 916.0 + 969.0 + + + + + [x=45.0][y=30.0] + + 10 + 90.0 + + + 734.0 + 777.0 + + + + + [x=95.0][y=30.0] + + 30 + 90.0 + + + 387.0 + 456.0 + + + + + [x=95.0][y=35.0] + + 20 + 90.0 + + + 293.0 + 360.0 + + + + + [x=53.0][y=30.0] + + 10 + 90.0 + + + 450.0 + 505.0 + + + + + [x=92.0][y=30.0] + + 10 + 90.0 + + + 478.0 + 551.0 + + + + + [x=53.0][y=35.0] + + 50 + 90.0 + + + 353.0 + 412.0 + + + + + [x=45.0][y=65.0] + + 20 + 90.0 + + + 997.0 + 1068.0 + + + + + [x=90.0][y=35.0] + + 10 + 90.0 + + + 203.0 + 260.0 + + + + + [x=38.0][y=15.0] + + 10 + 90.0 + + + 651.0 + 740.0 + + + + + [x=38.0][y=5.0] + + 30 + 90.0 + + + 471.0 + 534.0 + + + + + [x=40.0][y=15.0] + + 40 + 90.0 + + + 35.0 + 87.0 + + + + + [x=40.0][y=5.0] + + 30 + 90.0 + + + 385.0 + 436.0 + + + + + [x=42.0][y=15.0] + + 10 + 90.0 + + + 95.0 + 158.0 + + + + + [x=48.0][y=30.0] + + 10 + 90.0 + + + 632.0 + 693.0 + + + + + [x=48.0][y=40.0] + + 10 + 90.0 + + + 76.0 + 129.0 + + + + + [x=50.0][y=35.0] + + 20 + 90.0 + + + 262.0 + 317.0 + + + + + [x=50.0][y=40.0] + + 50 + 90.0 + + + 171.0 + 218.0 + + + + + [x=35.0][y=5.0] + + 20 + 90.0 + + + 562.0 + 629.0 + + + + + [x=50.0][y=30.0] + + 10 + 90.0 + + + 531.0 + 610.0 + + + + + [x=28.0][y=35.0] + + 10 + 90.0 + + + 1001.0 + 1066.0 + + + + + [x=28.0][y=30.0] + + 10 + 90.0 + + + 632.0 + 693.0 + + + + + [x=30.0][y=30.0] + + 10 + 90.0 + + + 541.0 + 600.0 + + + + + [x=32.0][y=30.0] + + 10 + 90.0 + + + 359.0 + 412.0 + + + + + [x=30.0][y=35.0] + + 10 + 90.0 + + + 1054.0 + 1127.0 + + + + + [x=30.0][y=32.0] + + 30 + 90.0 + + + 448.0 + 509.0 + + + + + [x=25.0][y=30.0] + + 10 + 90.0 + + + 725.0 + 786.0 + + + + + [x=25.0][y=35.0] + + 10 + 90.0 + + + 912.0 + 969.0 + + + + + [x=44.0][y=5.0] + + 20 + 90.0 + + + 286.0 + 347.0 + + + + + [x=42.0][y=10.0] + + 40 + 90.0 + + + 186.0 + 257.0 + + + + + [x=26.0][y=32.0] + + 10 + 90.0 + + + 815.0 + 880.0 + + + + diff --git a/jsprit-examples/input/deliveries_solomon_specifiedVehicleEndLocations_c101.xml b/jsprit-examples/input/deliveries_solomon_specifiedVehicleEndLocations_c101.xml index da1e27ce..f063f1c4 100644 --- a/jsprit-examples/input/deliveries_solomon_specifiedVehicleEndLocations_c101.xml +++ b/jsprit-examples/input/deliveries_solomon_specifiedVehicleEndLocations_c101.xml @@ -1,1240 +1,1241 @@ - - INFINITE - HOMOGENEOUS - - - - solomonVehicle - solomonType - - 0 - - - - 101 - - - - 0.0 - 1236.0 - - true - - - - - solomonType - 200 - - 1000.0 - 1.0 - - - - - - - [x=5.0][y=35.0] - - 10 - 90.0 - - - 283.0 - 344.0 - - - - - [x=5.0][y=45.0] - - 10 - 90.0 - - - 665.0 - 716.0 - - - - - [x=8.0][y=40.0] - - 40 - 90.0 - - - 87.0 - 158.0 - - - - - [x=8.0][y=45.0] - - 20 - 90.0 - - - 751.0 - 816.0 - - - - - [x=0.0][y=45.0] - - 20 - 90.0 - - - 567.0 - 624.0 - - - - - [x=2.0][y=40.0] - - 20 - 90.0 - - - 383.0 - 434.0 - - - - - [x=0.0][y=40.0] - - 30 - 90.0 - - - 479.0 - 522.0 - - - - - [x=33.0][y=35.0] - - 10 - 90.0 - - - 16.0 - 80.0 - - - - - [x=33.0][y=32.0] - - 20 - 90.0 - - - 68.0 - 149.0 - - - - - [x=35.0][y=32.0] - - 10 - 90.0 - - - 166.0 - 235.0 - - - - - [x=35.0][y=30.0] - - 10 - 90.0 - - - 264.0 - 321.0 - - - - - [x=28.0][y=52.0] - - 20 - 90.0 - - - 812.0 - 883.0 - - - - - [x=28.0][y=55.0] - - 10 - 90.0 - - - 732.0 - 777.0 - - - - - [x=25.0][y=50.0] - - 10 - 90.0 - - - 65.0 - 144.0 - - - - - [x=25.0][y=52.0] - - 40 - 90.0 - - - 169.0 - 224.0 - - - - - [x=25.0][y=55.0] - - 10 - 90.0 - - - 622.0 - 701.0 - - - - - [x=23.0][y=52.0] - - 10 - 90.0 - - - 261.0 - 316.0 - - - - - [x=23.0][y=55.0] - - 20 - 90.0 - - - 546.0 - 593.0 - - - - - [x=20.0][y=50.0] - - 10 - 90.0 - - - 358.0 - 405.0 - - - - - [x=42.0][y=66.0] - - 10 - 90.0 - - - 65.0 - 146.0 - - - - - [x=45.0][y=70.0] - - 30 - 90.0 - - - 825.0 - 870.0 - - - - - [x=45.0][y=68.0] - - 10 - 90.0 - - - 912.0 - 967.0 - - - - - [x=20.0][y=55.0] - - 10 - 90.0 - - - 449.0 - 504.0 - - - - - [x=40.0][y=66.0] - - 20 - 90.0 - - - 170.0 - 225.0 - - - - - [x=40.0][y=69.0] - - 20 - 90.0 - - - 621.0 - 702.0 - - - - - [x=42.0][y=65.0] - - 10 - 90.0 - - - 15.0 - 67.0 - - - - - [x=10.0][y=40.0] - - 30 - 90.0 - - - 31.0 - 100.0 - - - - - [x=42.0][y=68.0] - - 10 - 90.0 - - - 727.0 - 782.0 - - - - - [x=10.0][y=35.0] - - 20 - 90.0 - - - 200.0 - 237.0 - - - - - [x=38.0][y=70.0] - - 10 - 90.0 - - - 534.0 - 605.0 - - - - - [x=38.0][y=68.0] - - 20 - 90.0 - - - 255.0 - 324.0 - - - - - [x=15.0][y=80.0] - - 10 - 90.0 - - - 278.0 - 345.0 - - - - - [x=18.0][y=75.0] - - 20 - 90.0 - - - 99.0 - 148.0 - - - - - [x=15.0][y=75.0] - - 20 - 90.0 - - - 179.0 - 254.0 - - - - - [x=20.0][y=80.0] - - 40 - 90.0 - - - 384.0 - 429.0 - - - - - [x=20.0][y=85.0] - - 40 - 90.0 - - - 475.0 - 528.0 - - - - - [x=22.0][y=75.0] - - 30 - 90.0 - - - 30.0 - 92.0 - - - - - [x=22.0][y=85.0] - - 10 - 90.0 - - - 567.0 - 620.0 - - - - - [x=35.0][y=69.0] - - 10 - 90.0 - - - 448.0 - 505.0 - - - - - [x=25.0][y=85.0] - - 20 - 90.0 - - - 652.0 - 721.0 - - - - - [x=30.0][y=52.0] - - 20 - 90.0 - - - 914.0 - 965.0 - - - - - [x=30.0][y=50.0] - - 10 - 90.0 - - - 10.0 - 73.0 - - - - - [x=55.0][y=80.0] - - 10 - 90.0 - - - 743.0 - 820.0 - - - - - [x=55.0][y=85.0] - - 20 - 90.0 - - - 647.0 - 726.0 - - - - - [x=58.0][y=75.0] - - 20 - 90.0 - - - 30.0 - 84.0 - - - - - [x=60.0][y=85.0] - - 30 - 90.0 - - - 561.0 - 622.0 - - - - - [x=60.0][y=80.0] - - 10 - 90.0 - - - 95.0 - 156.0 - - - - - [x=62.0][y=80.0] - - 30 - 90.0 - - - 196.0 - 239.0 - - - - - [x=65.0][y=82.0] - - 10 - 90.0 - - - 285.0 - 336.0 - - - - - [x=65.0][y=85.0] - - 40 - 90.0 - - - 475.0 - 518.0 - - - - - [x=67.0][y=85.0] - - 20 - 90.0 - - - 368.0 - 441.0 - - - - - [x=60.0][y=60.0] - - 10 - 90.0 - - - 836.0 - 889.0 - - - - - [x=60.0][y=55.0] - - 10 - 90.0 - - - 20.0 - 84.0 - - - - - [x=35.0][y=66.0] - - 10 - 90.0 - - - 357.0 - 410.0 - - - - - [x=65.0][y=60.0] - - 30 - 90.0 - - - 645.0 - 708.0 - - - - - [x=63.0][y=58.0] - - 10 - 90.0 - - - 737.0 - 802.0 - - - - - [x=87.0][y=30.0] - - 10 - 90.0 - - - 668.0 - 731.0 - - - - - [x=88.0][y=35.0] - - 20 - 90.0 - - - 109.0 - 170.0 - - - - - [x=88.0][y=30.0] - - 10 - 90.0 - - - 574.0 - 643.0 - - - - - [x=75.0][y=55.0] - - 20 - 90.0 - - - 369.0 - 420.0 - - - - - [x=72.0][y=55.0] - - 10 - 90.0 - - - 265.0 - 338.0 - - - - - [x=85.0][y=25.0] - - 10 - 90.0 - - - 769.0 - 820.0 - - - - - [x=85.0][y=35.0] - - 30 - 90.0 - - - 47.0 - 124.0 - - - - - [x=66.0][y=55.0] - - 10 - 90.0 - - - 173.0 - 238.0 - - - - - [x=65.0][y=55.0] - - 20 - 90.0 - - - 85.0 - 144.0 - - - - - [x=70.0][y=58.0] - - 20 - 90.0 - - - 458.0 - 523.0 - - - - - [x=68.0][y=60.0] - - 30 - 90.0 - - - 555.0 - 612.0 - - - - - [x=47.0][y=40.0] - - 10 - 90.0 - - - 12.0 - 77.0 - - - - - [x=47.0][y=35.0] - - 10 - 90.0 - - - 826.0 - 875.0 - - - - - [x=45.0][y=35.0] - - 10 - 90.0 - - - 916.0 - 969.0 - - - - - [x=45.0][y=30.0] - - 10 - 90.0 - - - 734.0 - 777.0 - - - - - [x=95.0][y=30.0] - - 30 - 90.0 - - - 387.0 - 456.0 - - - - - [x=95.0][y=35.0] - - 20 - 90.0 - - - 293.0 - 360.0 - - - - - [x=53.0][y=30.0] - - 10 - 90.0 - - - 450.0 - 505.0 - - - - - [x=92.0][y=30.0] - - 10 - 90.0 - - - 478.0 - 551.0 - - - - - [x=53.0][y=35.0] - - 50 - 90.0 - - - 353.0 - 412.0 - - - - - [x=45.0][y=65.0] - - 20 - 90.0 - - - 997.0 - 1068.0 - - - - - [x=90.0][y=35.0] - - 10 - 90.0 - - - 203.0 - 260.0 - - - - - [x=38.0][y=15.0] - - 10 - 90.0 - - - 651.0 - 740.0 - - - - - [x=38.0][y=5.0] - - 30 - 90.0 - - - 471.0 - 534.0 - - - - - [x=40.0][y=15.0] - - 40 - 90.0 - - - 35.0 - 87.0 - - - - - [x=40.0][y=5.0] - - 30 - 90.0 - - - 385.0 - 436.0 - - - - - [x=42.0][y=15.0] - - 10 - 90.0 - - - 95.0 - 158.0 - - - - - [x=48.0][y=30.0] - - 10 - 90.0 - - - 632.0 - 693.0 - - - - - [x=48.0][y=40.0] - - 10 - 90.0 - - - 76.0 - 129.0 - - - - - [x=50.0][y=35.0] - - 20 - 90.0 - - - 262.0 - 317.0 - - - - - [x=50.0][y=40.0] - - 50 - 90.0 - - - 171.0 - 218.0 - - - - - [x=35.0][y=5.0] - - 20 - 90.0 - - - 562.0 - 629.0 - - - - - [x=50.0][y=30.0] - - 10 - 90.0 - - - 531.0 - 610.0 - - - - - [x=28.0][y=35.0] - - 10 - 90.0 - - - 1001.0 - 1066.0 - - - - - [x=28.0][y=30.0] - - 10 - 90.0 - - - 632.0 - 693.0 - - - - - [x=30.0][y=30.0] - - 10 - 90.0 - - - 541.0 - 600.0 - - - - - [x=32.0][y=30.0] - - 10 - 90.0 - - - 359.0 - 412.0 - - - - - [x=30.0][y=35.0] - - 10 - 90.0 - - - 1054.0 - 1127.0 - - - - - [x=30.0][y=32.0] - - 30 - 90.0 - - - 448.0 - 509.0 - - - - - [x=25.0][y=30.0] - - 10 - 90.0 - - - 725.0 - 786.0 - - - - - [x=25.0][y=35.0] - - 10 - 90.0 - - - 912.0 - 969.0 - - - - - [x=44.0][y=5.0] - - 20 - 90.0 - - - 286.0 - 347.0 - - - - - [x=42.0][y=10.0] - - 40 - 90.0 - - - 186.0 - 257.0 - - - - - [x=26.0][y=32.0] - - 10 - 90.0 - - - 815.0 - 880.0 - - - - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.w3schools.com vrp_xml_schema.xsd"> + + INFINITE + HOMOGENEOUS + + + + solomonVehicle + solomonType + + 0 + + + + 101 + + + + 0.0 + 1236.0 + + true + + + + + solomonType + 200 + + 1000.0 + 1.0 + + + + + + + [x=5.0][y=35.0] + + 10 + 90.0 + + + 283.0 + 344.0 + + + + + [x=5.0][y=45.0] + + 10 + 90.0 + + + 665.0 + 716.0 + + + + + [x=8.0][y=40.0] + + 40 + 90.0 + + + 87.0 + 158.0 + + + + + [x=8.0][y=45.0] + + 20 + 90.0 + + + 751.0 + 816.0 + + + + + [x=0.0][y=45.0] + + 20 + 90.0 + + + 567.0 + 624.0 + + + + + [x=2.0][y=40.0] + + 20 + 90.0 + + + 383.0 + 434.0 + + + + + [x=0.0][y=40.0] + + 30 + 90.0 + + + 479.0 + 522.0 + + + + + [x=33.0][y=35.0] + + 10 + 90.0 + + + 16.0 + 80.0 + + + + + [x=33.0][y=32.0] + + 20 + 90.0 + + + 68.0 + 149.0 + + + + + [x=35.0][y=32.0] + + 10 + 90.0 + + + 166.0 + 235.0 + + + + + [x=35.0][y=30.0] + + 10 + 90.0 + + + 264.0 + 321.0 + + + + + [x=28.0][y=52.0] + + 20 + 90.0 + + + 812.0 + 883.0 + + + + + [x=28.0][y=55.0] + + 10 + 90.0 + + + 732.0 + 777.0 + + + + + [x=25.0][y=50.0] + + 10 + 90.0 + + + 65.0 + 144.0 + + + + + [x=25.0][y=52.0] + + 40 + 90.0 + + + 169.0 + 224.0 + + + + + [x=25.0][y=55.0] + + 10 + 90.0 + + + 622.0 + 701.0 + + + + + [x=23.0][y=52.0] + + 10 + 90.0 + + + 261.0 + 316.0 + + + + + [x=23.0][y=55.0] + + 20 + 90.0 + + + 546.0 + 593.0 + + + + + [x=20.0][y=50.0] + + 10 + 90.0 + + + 358.0 + 405.0 + + + + + [x=42.0][y=66.0] + + 10 + 90.0 + + + 65.0 + 146.0 + + + + + [x=45.0][y=70.0] + + 30 + 90.0 + + + 825.0 + 870.0 + + + + + [x=45.0][y=68.0] + + 10 + 90.0 + + + 912.0 + 967.0 + + + + + [x=20.0][y=55.0] + + 10 + 90.0 + + + 449.0 + 504.0 + + + + + [x=40.0][y=66.0] + + 20 + 90.0 + + + 170.0 + 225.0 + + + + + [x=40.0][y=69.0] + + 20 + 90.0 + + + 621.0 + 702.0 + + + + + [x=42.0][y=65.0] + + 10 + 90.0 + + + 15.0 + 67.0 + + + + + [x=10.0][y=40.0] + + 30 + 90.0 + + + 31.0 + 100.0 + + + + + [x=42.0][y=68.0] + + 10 + 90.0 + + + 727.0 + 782.0 + + + + + [x=10.0][y=35.0] + + 20 + 90.0 + + + 200.0 + 237.0 + + + + + [x=38.0][y=70.0] + + 10 + 90.0 + + + 534.0 + 605.0 + + + + + [x=38.0][y=68.0] + + 20 + 90.0 + + + 255.0 + 324.0 + + + + + [x=15.0][y=80.0] + + 10 + 90.0 + + + 278.0 + 345.0 + + + + + [x=18.0][y=75.0] + + 20 + 90.0 + + + 99.0 + 148.0 + + + + + [x=15.0][y=75.0] + + 20 + 90.0 + + + 179.0 + 254.0 + + + + + [x=20.0][y=80.0] + + 40 + 90.0 + + + 384.0 + 429.0 + + + + + [x=20.0][y=85.0] + + 40 + 90.0 + + + 475.0 + 528.0 + + + + + [x=22.0][y=75.0] + + 30 + 90.0 + + + 30.0 + 92.0 + + + + + [x=22.0][y=85.0] + + 10 + 90.0 + + + 567.0 + 620.0 + + + + + [x=35.0][y=69.0] + + 10 + 90.0 + + + 448.0 + 505.0 + + + + + [x=25.0][y=85.0] + + 20 + 90.0 + + + 652.0 + 721.0 + + + + + [x=30.0][y=52.0] + + 20 + 90.0 + + + 914.0 + 965.0 + + + + + [x=30.0][y=50.0] + + 10 + 90.0 + + + 10.0 + 73.0 + + + + + [x=55.0][y=80.0] + + 10 + 90.0 + + + 743.0 + 820.0 + + + + + [x=55.0][y=85.0] + + 20 + 90.0 + + + 647.0 + 726.0 + + + + + [x=58.0][y=75.0] + + 20 + 90.0 + + + 30.0 + 84.0 + + + + + [x=60.0][y=85.0] + + 30 + 90.0 + + + 561.0 + 622.0 + + + + + [x=60.0][y=80.0] + + 10 + 90.0 + + + 95.0 + 156.0 + + + + + [x=62.0][y=80.0] + + 30 + 90.0 + + + 196.0 + 239.0 + + + + + [x=65.0][y=82.0] + + 10 + 90.0 + + + 285.0 + 336.0 + + + + + [x=65.0][y=85.0] + + 40 + 90.0 + + + 475.0 + 518.0 + + + + + [x=67.0][y=85.0] + + 20 + 90.0 + + + 368.0 + 441.0 + + + + + [x=60.0][y=60.0] + + 10 + 90.0 + + + 836.0 + 889.0 + + + + + [x=60.0][y=55.0] + + 10 + 90.0 + + + 20.0 + 84.0 + + + + + [x=35.0][y=66.0] + + 10 + 90.0 + + + 357.0 + 410.0 + + + + + [x=65.0][y=60.0] + + 30 + 90.0 + + + 645.0 + 708.0 + + + + + [x=63.0][y=58.0] + + 10 + 90.0 + + + 737.0 + 802.0 + + + + + [x=87.0][y=30.0] + + 10 + 90.0 + + + 668.0 + 731.0 + + + + + [x=88.0][y=35.0] + + 20 + 90.0 + + + 109.0 + 170.0 + + + + + [x=88.0][y=30.0] + + 10 + 90.0 + + + 574.0 + 643.0 + + + + + [x=75.0][y=55.0] + + 20 + 90.0 + + + 369.0 + 420.0 + + + + + [x=72.0][y=55.0] + + 10 + 90.0 + + + 265.0 + 338.0 + + + + + [x=85.0][y=25.0] + + 10 + 90.0 + + + 769.0 + 820.0 + + + + + [x=85.0][y=35.0] + + 30 + 90.0 + + + 47.0 + 124.0 + + + + + [x=66.0][y=55.0] + + 10 + 90.0 + + + 173.0 + 238.0 + + + + + [x=65.0][y=55.0] + + 20 + 90.0 + + + 85.0 + 144.0 + + + + + [x=70.0][y=58.0] + + 20 + 90.0 + + + 458.0 + 523.0 + + + + + [x=68.0][y=60.0] + + 30 + 90.0 + + + 555.0 + 612.0 + + + + + [x=47.0][y=40.0] + + 10 + 90.0 + + + 12.0 + 77.0 + + + + + [x=47.0][y=35.0] + + 10 + 90.0 + + + 826.0 + 875.0 + + + + + [x=45.0][y=35.0] + + 10 + 90.0 + + + 916.0 + 969.0 + + + + + [x=45.0][y=30.0] + + 10 + 90.0 + + + 734.0 + 777.0 + + + + + [x=95.0][y=30.0] + + 30 + 90.0 + + + 387.0 + 456.0 + + + + + [x=95.0][y=35.0] + + 20 + 90.0 + + + 293.0 + 360.0 + + + + + [x=53.0][y=30.0] + + 10 + 90.0 + + + 450.0 + 505.0 + + + + + [x=92.0][y=30.0] + + 10 + 90.0 + + + 478.0 + 551.0 + + + + + [x=53.0][y=35.0] + + 50 + 90.0 + + + 353.0 + 412.0 + + + + + [x=45.0][y=65.0] + + 20 + 90.0 + + + 997.0 + 1068.0 + + + + + [x=90.0][y=35.0] + + 10 + 90.0 + + + 203.0 + 260.0 + + + + + [x=38.0][y=15.0] + + 10 + 90.0 + + + 651.0 + 740.0 + + + + + [x=38.0][y=5.0] + + 30 + 90.0 + + + 471.0 + 534.0 + + + + + [x=40.0][y=15.0] + + 40 + 90.0 + + + 35.0 + 87.0 + + + + + [x=40.0][y=5.0] + + 30 + 90.0 + + + 385.0 + 436.0 + + + + + [x=42.0][y=15.0] + + 10 + 90.0 + + + 95.0 + 158.0 + + + + + [x=48.0][y=30.0] + + 10 + 90.0 + + + 632.0 + 693.0 + + + + + [x=48.0][y=40.0] + + 10 + 90.0 + + + 76.0 + 129.0 + + + + + [x=50.0][y=35.0] + + 20 + 90.0 + + + 262.0 + 317.0 + + + + + [x=50.0][y=40.0] + + 50 + 90.0 + + + 171.0 + 218.0 + + + + + [x=35.0][y=5.0] + + 20 + 90.0 + + + 562.0 + 629.0 + + + + + [x=50.0][y=30.0] + + 10 + 90.0 + + + 531.0 + 610.0 + + + + + [x=28.0][y=35.0] + + 10 + 90.0 + + + 1001.0 + 1066.0 + + + + + [x=28.0][y=30.0] + + 10 + 90.0 + + + 632.0 + 693.0 + + + + + [x=30.0][y=30.0] + + 10 + 90.0 + + + 541.0 + 600.0 + + + + + [x=32.0][y=30.0] + + 10 + 90.0 + + + 359.0 + 412.0 + + + + + [x=30.0][y=35.0] + + 10 + 90.0 + + + 1054.0 + 1127.0 + + + + + [x=30.0][y=32.0] + + 30 + 90.0 + + + 448.0 + 509.0 + + + + + [x=25.0][y=30.0] + + 10 + 90.0 + + + 725.0 + 786.0 + + + + + [x=25.0][y=35.0] + + 10 + 90.0 + + + 912.0 + 969.0 + + + + + [x=44.0][y=5.0] + + 20 + 90.0 + + + 286.0 + 347.0 + + + + + [x=42.0][y=10.0] + + 40 + 90.0 + + + 186.0 + 257.0 + + + + + [x=26.0][y=32.0] + + 10 + 90.0 + + + 815.0 + 880.0 + + + + diff --git a/jsprit-examples/input/fastAlgo.xml b/jsprit-examples/input/fastAlgo.xml index 883fac54..6a76b186 100755 --- a/jsprit-examples/input/fastAlgo.xml +++ b/jsprit-examples/input/fastAlgo.xml @@ -1,55 +1,56 @@ - - 2000 - - 0.01 - 50 - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.w3schools.com algorithm_schema.xsd"> + + 2000 + + 0.01 + 50 + + + + + + + + 1 + + + + + + + + 0.3 + + + + + + 0.5 + + + + + + + + + + 0.15 + + + + + + 0.5 + + + + + - - - - - - 1 - - - - - - - - 0.3 - - - - - - 0.5 - - - - - - - - - - 0.15 - - - - - - 0.5 - - - - - - diff --git a/jsprit-examples/input/pd_christophides_vrpnc1_vcap50.xml b/jsprit-examples/input/pd_christophides_vrpnc1_vcap50.xml index d35d0432..1f2cb0aa 100644 --- a/jsprit-examples/input/pd_christophides_vrpnc1_vcap50.xml +++ b/jsprit-examples/input/pd_christophides_vrpnc1_vcap50.xml @@ -1,635 +1,636 @@ - - INFINITE - HOMOGENEOUS - - - - christophidesVehicle - christophidesType - - [x=30.0][y=40.0] - - - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.w3schools.com vrp_xml_schema.xsd"> + + INFINITE + HOMOGENEOUS + + + + christophidesVehicle + christophidesType + + [x=30.0][y=40.0] + + + + 0.0 + 999999.0 + + + + + + christophidesType + 50 + + 0.0 + 1.0 + + + + + + + [x=62.0][y=63.0] + + 17 + 0.0 + + 0.0 - 999999.0 - - - - - - christophidesType - 50 - - 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 - - - - + 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/pickups_and_deliveries_solomon_c101.xml b/jsprit-examples/input/pickups_and_deliveries_solomon_c101.xml index b7cdbd74..f4e42e55 100644 --- a/jsprit-examples/input/pickups_and_deliveries_solomon_c101.xml +++ b/jsprit-examples/input/pickups_and_deliveries_solomon_c101.xml @@ -1,1235 +1,1236 @@ - - INFINITE - HOMOGENEOUS - - - - solomonVehicle - solomonType - - 0 - - - - 0.0 - 1236.0 - - - - - - solomonType - 200 - - 0.0 - 1.0 - - - - - - - [x=5.0][y=35.0] - - 10 - 90.0 - - - 283.0 - 344.0 - - - - - [x=5.0][y=45.0] - - 10 - 90.0 - - - 665.0 - 716.0 - - - - - [x=8.0][y=40.0] - - 40 - 90.0 - - - 87.0 - 158.0 - - - - - [x=8.0][y=45.0] - - 20 - 90.0 - - - 751.0 - 816.0 - - - - - [x=0.0][y=45.0] - - 20 - 90.0 - - - 567.0 - 624.0 - - - - - [x=2.0][y=40.0] - - 20 - 90.0 - - - 383.0 - 434.0 - - - - - [x=0.0][y=40.0] - - 30 - 90.0 - - - 479.0 - 522.0 - - - - - [x=33.0][y=35.0] - - 10 - 90.0 - - - 16.0 - 80.0 - - - - - [x=33.0][y=32.0] - - 20 - 90.0 - - - 68.0 - 149.0 - - - - - [x=35.0][y=32.0] - - 10 - 90.0 - - - 166.0 - 235.0 - - - - - [x=35.0][y=30.0] - - 10 - 90.0 - - - 264.0 - 321.0 - - - - - [x=28.0][y=52.0] - - 20 - 90.0 - - - 812.0 - 883.0 - - - - - [x=28.0][y=55.0] - - 10 - 90.0 - - - 732.0 - 777.0 - - - - - [x=25.0][y=50.0] - - 10 - 90.0 - - - 65.0 - 144.0 - - - - - [x=25.0][y=52.0] - - 40 - 90.0 - - - 169.0 - 224.0 - - - - - [x=25.0][y=55.0] - - 10 - 90.0 - - - 622.0 - 701.0 - - - - - [x=23.0][y=52.0] - - 10 - 90.0 - - - 261.0 - 316.0 - - - - - [x=23.0][y=55.0] - - 20 - 90.0 - - - 546.0 - 593.0 - - - - - [x=20.0][y=50.0] - - 10 - 90.0 - - - 358.0 - 405.0 - - - - - [x=42.0][y=66.0] - - 10 - 90.0 - - - 65.0 - 146.0 - - - - - [x=45.0][y=70.0] - - 30 - 90.0 - - - 825.0 - 870.0 - - - - - [x=45.0][y=68.0] - - 10 - 90.0 - - - 912.0 - 967.0 - - - - - [x=20.0][y=55.0] - - 10 - 90.0 - - - 449.0 - 504.0 - - - - - [x=40.0][y=66.0] - - 20 - 90.0 - - - 170.0 - 225.0 - - - - - [x=40.0][y=69.0] - - 20 - 90.0 - - - 621.0 - 702.0 - - - - - [x=42.0][y=65.0] - - 10 - 90.0 - - - 15.0 - 67.0 - - - - - [x=10.0][y=40.0] - - 30 - 90.0 - - - 31.0 - 100.0 - - - - - [x=42.0][y=68.0] - - 10 - 90.0 - - - 727.0 - 782.0 - - - - - [x=10.0][y=35.0] - - 20 - 90.0 - - - 200.0 - 237.0 - - - - - [x=38.0][y=70.0] - - 10 - 90.0 - - - 534.0 - 605.0 - - - - - [x=38.0][y=68.0] - - 20 - 90.0 - - - 255.0 - 324.0 - - - - - [x=15.0][y=80.0] - - 10 - 90.0 - - - 278.0 - 345.0 - - - - - [x=18.0][y=75.0] - - 20 - 90.0 - - - 99.0 - 148.0 - - - - - [x=15.0][y=75.0] - - 20 - 90.0 - - - 179.0 - 254.0 - - - - - [x=20.0][y=80.0] - - 40 - 90.0 - - - 384.0 - 429.0 - - - - - [x=20.0][y=85.0] - - 40 - 90.0 - - - 475.0 - 528.0 - - - - - [x=22.0][y=75.0] - - 30 - 90.0 - - - 30.0 - 92.0 - - - - - [x=22.0][y=85.0] - - 10 - 90.0 - - - 567.0 - 620.0 - - - - - [x=35.0][y=69.0] - - 10 - 90.0 - - - 448.0 - 505.0 - - - - - [x=25.0][y=85.0] - - 20 - 90.0 - - - 652.0 - 721.0 - - - - - [x=30.0][y=52.0] - - 20 - 90.0 - - - 914.0 - 965.0 - - - - - [x=30.0][y=50.0] - - 10 - 90.0 - - - 10.0 - 73.0 - - - - - [x=55.0][y=80.0] - - 10 - 90.0 - - - 743.0 - 820.0 - - - - - [x=55.0][y=85.0] - - 20 - 90.0 - - - 647.0 - 726.0 - - - - - [x=58.0][y=75.0] - - 20 - 90.0 - - - 30.0 - 84.0 - - - - - [x=60.0][y=85.0] - - 30 - 90.0 - - - 561.0 - 622.0 - - - - - [x=60.0][y=80.0] - - 10 - 90.0 - - - 95.0 - 156.0 - - - - - [x=62.0][y=80.0] - - 30 - 90.0 - - - 196.0 - 239.0 - - - - - [x=65.0][y=82.0] - - 10 - 90.0 - - - 285.0 - 336.0 - - - - - [x=65.0][y=85.0] - - 40 - 90.0 - - - 475.0 - 518.0 - - - - - [x=67.0][y=85.0] - - 20 - 90.0 - - - 368.0 - 441.0 - - - - - [x=60.0][y=60.0] - - 10 - 90.0 - - - 836.0 - 889.0 - - - - - [x=60.0][y=55.0] - - 10 - 90.0 - - - 20.0 - 84.0 - - - - - [x=35.0][y=66.0] - - 10 - 90.0 - - - 357.0 - 410.0 - - - - - [x=65.0][y=60.0] - - 30 - 90.0 - - - 645.0 - 708.0 - - - - - [x=63.0][y=58.0] - - 10 - 90.0 - - - 737.0 - 802.0 - - - - - [x=87.0][y=30.0] - - 10 - 90.0 - - - 668.0 - 731.0 - - - - - [x=88.0][y=35.0] - - 20 - 90.0 - - - 109.0 - 170.0 - - - - - [x=88.0][y=30.0] - - 10 - 90.0 - - - 574.0 - 643.0 - - - - - [x=75.0][y=55.0] - - 20 - 90.0 - - - 369.0 - 420.0 - - - - - [x=72.0][y=55.0] - - 10 - 90.0 - - - 265.0 - 338.0 - - - - - [x=85.0][y=25.0] - - 10 - 90.0 - - - 769.0 - 820.0 - - - - - [x=85.0][y=35.0] - - 30 - 90.0 - - - 47.0 - 124.0 - - - - - [x=66.0][y=55.0] - - 10 - 90.0 - - - 173.0 - 238.0 - - - - - [x=65.0][y=55.0] - - 20 - 90.0 - - - 85.0 - 144.0 - - - - - [x=70.0][y=58.0] - - 20 - 90.0 - - - 458.0 - 523.0 - - - - - [x=68.0][y=60.0] - - 30 - 90.0 - - - 555.0 - 612.0 - - - - - [x=47.0][y=40.0] - - 10 - 90.0 - - - 12.0 - 77.0 - - - - - [x=47.0][y=35.0] - - 10 - 90.0 - - - 826.0 - 875.0 - - - - - [x=45.0][y=35.0] - - 10 - 90.0 - - - 916.0 - 969.0 - - - - - [x=45.0][y=30.0] - - 10 - 90.0 - - - 734.0 - 777.0 - - - - - [x=95.0][y=30.0] - - 30 - 90.0 - - - 387.0 - 456.0 - - - - - [x=95.0][y=35.0] - - 20 - 90.0 - - - 293.0 - 360.0 - - - - - [x=53.0][y=30.0] - - 10 - 90.0 - - - 450.0 - 505.0 - - - - - [x=92.0][y=30.0] - - 10 - 90.0 - - - 478.0 - 551.0 - - - - - [x=53.0][y=35.0] - - 50 - 90.0 - - - 353.0 - 412.0 - - - - - [x=45.0][y=65.0] - - 20 - 90.0 - - - 997.0 - 1068.0 - - - - - [x=90.0][y=35.0] - - 10 - 90.0 - - - 203.0 - 260.0 - - - - - [x=38.0][y=15.0] - - 10 - 90.0 - - - 651.0 - 740.0 - - - - - [x=38.0][y=5.0] - - 30 - 90.0 - - - 471.0 - 534.0 - - - - - [x=40.0][y=15.0] - - 40 - 90.0 - - - 35.0 - 87.0 - - - - - [x=40.0][y=5.0] - - 30 - 90.0 - - - 385.0 - 436.0 - - - - - [x=42.0][y=15.0] - - 10 - 90.0 - - - 95.0 - 158.0 - - - - - [x=48.0][y=30.0] - - 10 - 90.0 - - - 632.0 - 693.0 - - - - - [x=48.0][y=40.0] - - 10 - 90.0 - - - 76.0 - 129.0 - - - - - [x=50.0][y=35.0] - - 20 - 90.0 - - - 262.0 - 317.0 - - - - - [x=50.0][y=40.0] - - 50 - 90.0 - - - 171.0 - 218.0 - - - - - [x=35.0][y=5.0] - - 20 - 90.0 - - - 562.0 - 629.0 - - - - - [x=50.0][y=30.0] - - 10 - 90.0 - - - 531.0 - 610.0 - - - - - [x=28.0][y=35.0] - - 10 - 90.0 - - - 1001.0 - 1066.0 - - - - - [x=28.0][y=30.0] - - 10 - 90.0 - - - 632.0 - 693.0 - - - - - [x=30.0][y=30.0] - - 10 - 90.0 - - - 541.0 - 600.0 - - - - - [x=32.0][y=30.0] - - 10 - 90.0 - - - 359.0 - 412.0 - - - - - [x=30.0][y=35.0] - - 10 - 90.0 - - - 1054.0 - 1127.0 - - - - - [x=30.0][y=32.0] - - 30 - 90.0 - - - 448.0 - 509.0 - - - - - [x=25.0][y=30.0] - - 10 - 90.0 - - - 725.0 - 786.0 - - - - - [x=25.0][y=35.0] - - 10 - 90.0 - - - 912.0 - 969.0 - - - - - [x=44.0][y=5.0] - - 20 - 90.0 - - - 286.0 - 347.0 - - - - - [x=42.0][y=10.0] - - 40 - 90.0 - - - 186.0 - 257.0 - - - - - [x=26.0][y=32.0] - - 10 - 90.0 - - - 815.0 - 880.0 - - - - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.w3schools.com vrp_xml_schema.xsd"> + + INFINITE + HOMOGENEOUS + + + + solomonVehicle + solomonType + + 0 + + + + 0.0 + 1236.0 + + + + + + solomonType + 200 + + 0.0 + 1.0 + + + + + + + [x=5.0][y=35.0] + + 10 + 90.0 + + + 283.0 + 344.0 + + + + + [x=5.0][y=45.0] + + 10 + 90.0 + + + 665.0 + 716.0 + + + + + [x=8.0][y=40.0] + + 40 + 90.0 + + + 87.0 + 158.0 + + + + + [x=8.0][y=45.0] + + 20 + 90.0 + + + 751.0 + 816.0 + + + + + [x=0.0][y=45.0] + + 20 + 90.0 + + + 567.0 + 624.0 + + + + + [x=2.0][y=40.0] + + 20 + 90.0 + + + 383.0 + 434.0 + + + + + [x=0.0][y=40.0] + + 30 + 90.0 + + + 479.0 + 522.0 + + + + + [x=33.0][y=35.0] + + 10 + 90.0 + + + 16.0 + 80.0 + + + + + [x=33.0][y=32.0] + + 20 + 90.0 + + + 68.0 + 149.0 + + + + + [x=35.0][y=32.0] + + 10 + 90.0 + + + 166.0 + 235.0 + + + + + [x=35.0][y=30.0] + + 10 + 90.0 + + + 264.0 + 321.0 + + + + + [x=28.0][y=52.0] + + 20 + 90.0 + + + 812.0 + 883.0 + + + + + [x=28.0][y=55.0] + + 10 + 90.0 + + + 732.0 + 777.0 + + + + + [x=25.0][y=50.0] + + 10 + 90.0 + + + 65.0 + 144.0 + + + + + [x=25.0][y=52.0] + + 40 + 90.0 + + + 169.0 + 224.0 + + + + + [x=25.0][y=55.0] + + 10 + 90.0 + + + 622.0 + 701.0 + + + + + [x=23.0][y=52.0] + + 10 + 90.0 + + + 261.0 + 316.0 + + + + + [x=23.0][y=55.0] + + 20 + 90.0 + + + 546.0 + 593.0 + + + + + [x=20.0][y=50.0] + + 10 + 90.0 + + + 358.0 + 405.0 + + + + + [x=42.0][y=66.0] + + 10 + 90.0 + + + 65.0 + 146.0 + + + + + [x=45.0][y=70.0] + + 30 + 90.0 + + + 825.0 + 870.0 + + + + + [x=45.0][y=68.0] + + 10 + 90.0 + + + 912.0 + 967.0 + + + + + [x=20.0][y=55.0] + + 10 + 90.0 + + + 449.0 + 504.0 + + + + + [x=40.0][y=66.0] + + 20 + 90.0 + + + 170.0 + 225.0 + + + + + [x=40.0][y=69.0] + + 20 + 90.0 + + + 621.0 + 702.0 + + + + + [x=42.0][y=65.0] + + 10 + 90.0 + + + 15.0 + 67.0 + + + + + [x=10.0][y=40.0] + + 30 + 90.0 + + + 31.0 + 100.0 + + + + + [x=42.0][y=68.0] + + 10 + 90.0 + + + 727.0 + 782.0 + + + + + [x=10.0][y=35.0] + + 20 + 90.0 + + + 200.0 + 237.0 + + + + + [x=38.0][y=70.0] + + 10 + 90.0 + + + 534.0 + 605.0 + + + + + [x=38.0][y=68.0] + + 20 + 90.0 + + + 255.0 + 324.0 + + + + + [x=15.0][y=80.0] + + 10 + 90.0 + + + 278.0 + 345.0 + + + + + [x=18.0][y=75.0] + + 20 + 90.0 + + + 99.0 + 148.0 + + + + + [x=15.0][y=75.0] + + 20 + 90.0 + + + 179.0 + 254.0 + + + + + [x=20.0][y=80.0] + + 40 + 90.0 + + + 384.0 + 429.0 + + + + + [x=20.0][y=85.0] + + 40 + 90.0 + + + 475.0 + 528.0 + + + + + [x=22.0][y=75.0] + + 30 + 90.0 + + + 30.0 + 92.0 + + + + + [x=22.0][y=85.0] + + 10 + 90.0 + + + 567.0 + 620.0 + + + + + [x=35.0][y=69.0] + + 10 + 90.0 + + + 448.0 + 505.0 + + + + + [x=25.0][y=85.0] + + 20 + 90.0 + + + 652.0 + 721.0 + + + + + [x=30.0][y=52.0] + + 20 + 90.0 + + + 914.0 + 965.0 + + + + + [x=30.0][y=50.0] + + 10 + 90.0 + + + 10.0 + 73.0 + + + + + [x=55.0][y=80.0] + + 10 + 90.0 + + + 743.0 + 820.0 + + + + + [x=55.0][y=85.0] + + 20 + 90.0 + + + 647.0 + 726.0 + + + + + [x=58.0][y=75.0] + + 20 + 90.0 + + + 30.0 + 84.0 + + + + + [x=60.0][y=85.0] + + 30 + 90.0 + + + 561.0 + 622.0 + + + + + [x=60.0][y=80.0] + + 10 + 90.0 + + + 95.0 + 156.0 + + + + + [x=62.0][y=80.0] + + 30 + 90.0 + + + 196.0 + 239.0 + + + + + [x=65.0][y=82.0] + + 10 + 90.0 + + + 285.0 + 336.0 + + + + + [x=65.0][y=85.0] + + 40 + 90.0 + + + 475.0 + 518.0 + + + + + [x=67.0][y=85.0] + + 20 + 90.0 + + + 368.0 + 441.0 + + + + + [x=60.0][y=60.0] + + 10 + 90.0 + + + 836.0 + 889.0 + + + + + [x=60.0][y=55.0] + + 10 + 90.0 + + + 20.0 + 84.0 + + + + + [x=35.0][y=66.0] + + 10 + 90.0 + + + 357.0 + 410.0 + + + + + [x=65.0][y=60.0] + + 30 + 90.0 + + + 645.0 + 708.0 + + + + + [x=63.0][y=58.0] + + 10 + 90.0 + + + 737.0 + 802.0 + + + + + [x=87.0][y=30.0] + + 10 + 90.0 + + + 668.0 + 731.0 + + + + + [x=88.0][y=35.0] + + 20 + 90.0 + + + 109.0 + 170.0 + + + + + [x=88.0][y=30.0] + + 10 + 90.0 + + + 574.0 + 643.0 + + + + + [x=75.0][y=55.0] + + 20 + 90.0 + + + 369.0 + 420.0 + + + + + [x=72.0][y=55.0] + + 10 + 90.0 + + + 265.0 + 338.0 + + + + + [x=85.0][y=25.0] + + 10 + 90.0 + + + 769.0 + 820.0 + + + + + [x=85.0][y=35.0] + + 30 + 90.0 + + + 47.0 + 124.0 + + + + + [x=66.0][y=55.0] + + 10 + 90.0 + + + 173.0 + 238.0 + + + + + [x=65.0][y=55.0] + + 20 + 90.0 + + + 85.0 + 144.0 + + + + + [x=70.0][y=58.0] + + 20 + 90.0 + + + 458.0 + 523.0 + + + + + [x=68.0][y=60.0] + + 30 + 90.0 + + + 555.0 + 612.0 + + + + + [x=47.0][y=40.0] + + 10 + 90.0 + + + 12.0 + 77.0 + + + + + [x=47.0][y=35.0] + + 10 + 90.0 + + + 826.0 + 875.0 + + + + + [x=45.0][y=35.0] + + 10 + 90.0 + + + 916.0 + 969.0 + + + + + [x=45.0][y=30.0] + + 10 + 90.0 + + + 734.0 + 777.0 + + + + + [x=95.0][y=30.0] + + 30 + 90.0 + + + 387.0 + 456.0 + + + + + [x=95.0][y=35.0] + + 20 + 90.0 + + + 293.0 + 360.0 + + + + + [x=53.0][y=30.0] + + 10 + 90.0 + + + 450.0 + 505.0 + + + + + [x=92.0][y=30.0] + + 10 + 90.0 + + + 478.0 + 551.0 + + + + + [x=53.0][y=35.0] + + 50 + 90.0 + + + 353.0 + 412.0 + + + + + [x=45.0][y=65.0] + + 20 + 90.0 + + + 997.0 + 1068.0 + + + + + [x=90.0][y=35.0] + + 10 + 90.0 + + + 203.0 + 260.0 + + + + + [x=38.0][y=15.0] + + 10 + 90.0 + + + 651.0 + 740.0 + + + + + [x=38.0][y=5.0] + + 30 + 90.0 + + + 471.0 + 534.0 + + + + + [x=40.0][y=15.0] + + 40 + 90.0 + + + 35.0 + 87.0 + + + + + [x=40.0][y=5.0] + + 30 + 90.0 + + + 385.0 + 436.0 + + + + + [x=42.0][y=15.0] + + 10 + 90.0 + + + 95.0 + 158.0 + + + + + [x=48.0][y=30.0] + + 10 + 90.0 + + + 632.0 + 693.0 + + + + + [x=48.0][y=40.0] + + 10 + 90.0 + + + 76.0 + 129.0 + + + + + [x=50.0][y=35.0] + + 20 + 90.0 + + + 262.0 + 317.0 + + + + + [x=50.0][y=40.0] + + 50 + 90.0 + + + 171.0 + 218.0 + + + + + [x=35.0][y=5.0] + + 20 + 90.0 + + + 562.0 + 629.0 + + + + + [x=50.0][y=30.0] + + 10 + 90.0 + + + 531.0 + 610.0 + + + + + [x=28.0][y=35.0] + + 10 + 90.0 + + + 1001.0 + 1066.0 + + + + + [x=28.0][y=30.0] + + 10 + 90.0 + + + 632.0 + 693.0 + + + + + [x=30.0][y=30.0] + + 10 + 90.0 + + + 541.0 + 600.0 + + + + + [x=32.0][y=30.0] + + 10 + 90.0 + + + 359.0 + 412.0 + + + + + [x=30.0][y=35.0] + + 10 + 90.0 + + + 1054.0 + 1127.0 + + + + + [x=30.0][y=32.0] + + 30 + 90.0 + + + 448.0 + 509.0 + + + + + [x=25.0][y=30.0] + + 10 + 90.0 + + + 725.0 + 786.0 + + + + + [x=25.0][y=35.0] + + 10 + 90.0 + + + 912.0 + 969.0 + + + + + [x=44.0][y=5.0] + + 20 + 90.0 + + + 286.0 + 347.0 + + + + + [x=42.0][y=10.0] + + 40 + 90.0 + + + 186.0 + 257.0 + + + + + [x=26.0][y=32.0] + + 10 + 90.0 + + + 815.0 + 880.0 + + + + diff --git a/jsprit-examples/input/pickups_and_deliveries_solomon_c101_withoutTWs.xml b/jsprit-examples/input/pickups_and_deliveries_solomon_c101_withoutTWs.xml index 928e7774..71394972 100644 --- a/jsprit-examples/input/pickups_and_deliveries_solomon_c101_withoutTWs.xml +++ b/jsprit-examples/input/pickups_and_deliveries_solomon_c101_withoutTWs.xml @@ -1,1235 +1,1236 @@ - - INFINITE - HOMOGENEOUS - - - - solomonVehicle - solomonType - - 0 - - - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.w3schools.com vrp_xml_schema.xsd"> + + INFINITE + HOMOGENEOUS + + + + solomonVehicle + solomonType + + 0 + + + + 0.0 + 1236.0 + + + + + + solomonType + 200 + + 0.0 + 1.0 + + + + + + + [x=5.0][y=35.0] + + 10 + 90.0 + + 0.0 - 1236.0 - - - - - - solomonType - 200 - - 0.0 - 1.0 - - - - - - - [x=5.0][y=35.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=5.0][y=45.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=8.0][y=40.0] - - 40 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=8.0][y=45.0] - - 20 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=0.0][y=45.0] - - 20 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=2.0][y=40.0] - - 20 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=0.0][y=40.0] - - 30 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=33.0][y=35.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=33.0][y=32.0] - - 20 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=35.0][y=32.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=35.0][y=30.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=28.0][y=52.0] - - 20 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=28.0][y=55.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=25.0][y=50.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=25.0][y=52.0] - - 40 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=25.0][y=55.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=23.0][y=52.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=23.0][y=55.0] - - 20 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=20.0][y=50.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=42.0][y=66.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=45.0][y=70.0] - - 30 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=45.0][y=68.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=20.0][y=55.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=40.0][y=66.0] - - 20 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=40.0][y=69.0] - - 20 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=42.0][y=65.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=10.0][y=40.0] - - 30 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=42.0][y=68.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=10.0][y=35.0] - - 20 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=38.0][y=70.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=38.0][y=68.0] - - 20 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=15.0][y=80.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=18.0][y=75.0] - - 20 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=15.0][y=75.0] - - 20 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=20.0][y=80.0] - - 40 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=20.0][y=85.0] - - 40 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=22.0][y=75.0] - - 30 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=22.0][y=85.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=35.0][y=69.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=25.0][y=85.0] - - 20 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=30.0][y=52.0] - - 20 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=30.0][y=50.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=55.0][y=80.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=55.0][y=85.0] - - 20 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=58.0][y=75.0] - - 20 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=60.0][y=85.0] - - 30 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=60.0][y=80.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=62.0][y=80.0] - - 30 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=65.0][y=82.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=65.0][y=85.0] - - 40 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=67.0][y=85.0] - - 20 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=60.0][y=60.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=60.0][y=55.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=35.0][y=66.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=65.0][y=60.0] - - 30 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=63.0][y=58.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=87.0][y=30.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=88.0][y=35.0] - - 20 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=88.0][y=30.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=75.0][y=55.0] - - 20 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=72.0][y=55.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=85.0][y=25.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=85.0][y=35.0] - - 30 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=66.0][y=55.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=65.0][y=55.0] - - 20 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=70.0][y=58.0] - - 20 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=68.0][y=60.0] - - 30 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=47.0][y=40.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=47.0][y=35.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=45.0][y=35.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=45.0][y=30.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=95.0][y=30.0] - - 30 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=95.0][y=35.0] - - 20 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=53.0][y=30.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=92.0][y=30.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=53.0][y=35.0] - - 50 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=45.0][y=65.0] - - 20 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=90.0][y=35.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=38.0][y=15.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=38.0][y=5.0] - - 30 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=40.0][y=15.0] - - 40 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=40.0][y=5.0] - - 30 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=42.0][y=15.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=48.0][y=30.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=48.0][y=40.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=50.0][y=35.0] - - 20 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=50.0][y=40.0] - - 50 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=35.0][y=5.0] - - 20 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=50.0][y=30.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=28.0][y=35.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=28.0][y=30.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=30.0][y=30.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=32.0][y=30.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=30.0][y=35.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=30.0][y=32.0] - - 30 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=25.0][y=30.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=25.0][y=35.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=44.0][y=5.0] - - 20 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=42.0][y=10.0] - - 40 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=26.0][y=32.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - + 1.7976931348623157E308 + + + + + [x=5.0][y=45.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=8.0][y=40.0] + + 40 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=8.0][y=45.0] + + 20 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=0.0][y=45.0] + + 20 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=2.0][y=40.0] + + 20 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=0.0][y=40.0] + + 30 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=33.0][y=35.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=33.0][y=32.0] + + 20 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=35.0][y=32.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=35.0][y=30.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=28.0][y=52.0] + + 20 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=28.0][y=55.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=25.0][y=50.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=25.0][y=52.0] + + 40 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=25.0][y=55.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=23.0][y=52.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=23.0][y=55.0] + + 20 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=20.0][y=50.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=42.0][y=66.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=45.0][y=70.0] + + 30 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=45.0][y=68.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=20.0][y=55.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=40.0][y=66.0] + + 20 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=40.0][y=69.0] + + 20 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=42.0][y=65.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=10.0][y=40.0] + + 30 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=42.0][y=68.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=10.0][y=35.0] + + 20 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=38.0][y=70.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=38.0][y=68.0] + + 20 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=15.0][y=80.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=18.0][y=75.0] + + 20 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=15.0][y=75.0] + + 20 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=20.0][y=80.0] + + 40 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=20.0][y=85.0] + + 40 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=22.0][y=75.0] + + 30 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=22.0][y=85.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=35.0][y=69.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=25.0][y=85.0] + + 20 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=30.0][y=52.0] + + 20 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=30.0][y=50.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=55.0][y=80.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=55.0][y=85.0] + + 20 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=58.0][y=75.0] + + 20 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=60.0][y=85.0] + + 30 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=60.0][y=80.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=62.0][y=80.0] + + 30 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=65.0][y=82.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=65.0][y=85.0] + + 40 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=67.0][y=85.0] + + 20 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=60.0][y=60.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=60.0][y=55.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=35.0][y=66.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=65.0][y=60.0] + + 30 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=63.0][y=58.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=87.0][y=30.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=88.0][y=35.0] + + 20 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=88.0][y=30.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=75.0][y=55.0] + + 20 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=72.0][y=55.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=85.0][y=25.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=85.0][y=35.0] + + 30 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=66.0][y=55.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=65.0][y=55.0] + + 20 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=70.0][y=58.0] + + 20 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=68.0][y=60.0] + + 30 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=47.0][y=40.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=47.0][y=35.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=45.0][y=35.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=45.0][y=30.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=95.0][y=30.0] + + 30 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=95.0][y=35.0] + + 20 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=53.0][y=30.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=92.0][y=30.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=53.0][y=35.0] + + 50 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=45.0][y=65.0] + + 20 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=90.0][y=35.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=38.0][y=15.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=38.0][y=5.0] + + 30 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=40.0][y=15.0] + + 40 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=40.0][y=5.0] + + 30 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=42.0][y=15.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=48.0][y=30.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=48.0][y=40.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=50.0][y=35.0] + + 20 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=50.0][y=40.0] + + 50 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=35.0][y=5.0] + + 20 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=50.0][y=30.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=28.0][y=35.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=28.0][y=30.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=30.0][y=30.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=32.0][y=30.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=30.0][y=35.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=30.0][y=32.0] + + 30 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=25.0][y=30.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=25.0][y=35.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=44.0][y=5.0] + + 20 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=42.0][y=10.0] + + 40 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=26.0][y=32.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + diff --git a/jsprit-examples/input/pickups_and_deliveries_solomon_c101_withoutTWs_and_specifiedVehicleEndLocations.xml b/jsprit-examples/input/pickups_and_deliveries_solomon_c101_withoutTWs_and_specifiedVehicleEndLocations.xml index e13eeccd..0812b5b9 100644 --- a/jsprit-examples/input/pickups_and_deliveries_solomon_c101_withoutTWs_and_specifiedVehicleEndLocations.xml +++ b/jsprit-examples/input/pickups_and_deliveries_solomon_c101_withoutTWs_and_specifiedVehicleEndLocations.xml @@ -1,1239 +1,1240 @@ - - INFINITE - HOMOGENEOUS - - - - solomonVehicle - solomonType - - 0 - - - - 101 - - - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.w3schools.com vrp_xml_schema.xsd"> + + INFINITE + HOMOGENEOUS + + + + solomonVehicle + solomonType + + 0 + + + + 101 + + + + 0.0 + 1236.0 + + + + + + solomonType + 200 + + 500.0 + 1.0 + + + + + + + [x=5.0][y=35.0] + + 10 + 90.0 + + 0.0 - 1236.0 - - - - - - solomonType - 200 - - 500.0 - 1.0 - - - - - - - [x=5.0][y=35.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=5.0][y=45.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=8.0][y=40.0] - - 40 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=8.0][y=45.0] - - 20 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=0.0][y=45.0] - - 20 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=2.0][y=40.0] - - 20 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=0.0][y=40.0] - - 30 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=33.0][y=35.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=33.0][y=32.0] - - 20 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=35.0][y=32.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=35.0][y=30.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=28.0][y=52.0] - - 20 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=28.0][y=55.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=25.0][y=50.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=25.0][y=52.0] - - 40 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=25.0][y=55.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=23.0][y=52.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=23.0][y=55.0] - - 20 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=20.0][y=50.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=42.0][y=66.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=45.0][y=70.0] - - 30 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=45.0][y=68.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=20.0][y=55.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=40.0][y=66.0] - - 20 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=40.0][y=69.0] - - 20 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=42.0][y=65.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=10.0][y=40.0] - - 30 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=42.0][y=68.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=10.0][y=35.0] - - 20 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=38.0][y=70.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=38.0][y=68.0] - - 20 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=15.0][y=80.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=18.0][y=75.0] - - 20 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=15.0][y=75.0] - - 20 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=20.0][y=80.0] - - 40 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=20.0][y=85.0] - - 40 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=22.0][y=75.0] - - 30 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=22.0][y=85.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=35.0][y=69.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=25.0][y=85.0] - - 20 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=30.0][y=52.0] - - 20 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=30.0][y=50.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=55.0][y=80.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=55.0][y=85.0] - - 20 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=58.0][y=75.0] - - 20 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=60.0][y=85.0] - - 30 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=60.0][y=80.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=62.0][y=80.0] - - 30 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=65.0][y=82.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=65.0][y=85.0] - - 40 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=67.0][y=85.0] - - 20 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=60.0][y=60.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=60.0][y=55.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=35.0][y=66.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=65.0][y=60.0] - - 30 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=63.0][y=58.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=87.0][y=30.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=88.0][y=35.0] - - 20 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=88.0][y=30.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=75.0][y=55.0] - - 20 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=72.0][y=55.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=85.0][y=25.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=85.0][y=35.0] - - 30 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=66.0][y=55.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=65.0][y=55.0] - - 20 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=70.0][y=58.0] - - 20 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=68.0][y=60.0] - - 30 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=47.0][y=40.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=47.0][y=35.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=45.0][y=35.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=45.0][y=30.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=95.0][y=30.0] - - 30 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=95.0][y=35.0] - - 20 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=53.0][y=30.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=92.0][y=30.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=53.0][y=35.0] - - 50 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=45.0][y=65.0] - - 20 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=90.0][y=35.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=38.0][y=15.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=38.0][y=5.0] - - 30 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=40.0][y=15.0] - - 40 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=40.0][y=5.0] - - 30 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=42.0][y=15.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=48.0][y=30.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=48.0][y=40.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=50.0][y=35.0] - - 20 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=50.0][y=40.0] - - 50 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=35.0][y=5.0] - - 20 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=50.0][y=30.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=28.0][y=35.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=28.0][y=30.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=30.0][y=30.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=32.0][y=30.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=30.0][y=35.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=30.0][y=32.0] - - 30 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=25.0][y=30.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=25.0][y=35.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=44.0][y=5.0] - - 20 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=42.0][y=10.0] - - 40 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=26.0][y=32.0] - - 10 - 90.0 - - - 0.0 - 1.7976931348623157E308 - - - - + 1.7976931348623157E308 + + + + + [x=5.0][y=45.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=8.0][y=40.0] + + 40 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=8.0][y=45.0] + + 20 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=0.0][y=45.0] + + 20 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=2.0][y=40.0] + + 20 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=0.0][y=40.0] + + 30 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=33.0][y=35.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=33.0][y=32.0] + + 20 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=35.0][y=32.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=35.0][y=30.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=28.0][y=52.0] + + 20 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=28.0][y=55.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=25.0][y=50.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=25.0][y=52.0] + + 40 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=25.0][y=55.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=23.0][y=52.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=23.0][y=55.0] + + 20 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=20.0][y=50.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=42.0][y=66.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=45.0][y=70.0] + + 30 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=45.0][y=68.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=20.0][y=55.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=40.0][y=66.0] + + 20 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=40.0][y=69.0] + + 20 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=42.0][y=65.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=10.0][y=40.0] + + 30 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=42.0][y=68.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=10.0][y=35.0] + + 20 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=38.0][y=70.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=38.0][y=68.0] + + 20 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=15.0][y=80.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=18.0][y=75.0] + + 20 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=15.0][y=75.0] + + 20 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=20.0][y=80.0] + + 40 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=20.0][y=85.0] + + 40 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=22.0][y=75.0] + + 30 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=22.0][y=85.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=35.0][y=69.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=25.0][y=85.0] + + 20 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=30.0][y=52.0] + + 20 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=30.0][y=50.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=55.0][y=80.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=55.0][y=85.0] + + 20 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=58.0][y=75.0] + + 20 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=60.0][y=85.0] + + 30 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=60.0][y=80.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=62.0][y=80.0] + + 30 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=65.0][y=82.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=65.0][y=85.0] + + 40 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=67.0][y=85.0] + + 20 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=60.0][y=60.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=60.0][y=55.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=35.0][y=66.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=65.0][y=60.0] + + 30 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=63.0][y=58.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=87.0][y=30.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=88.0][y=35.0] + + 20 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=88.0][y=30.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=75.0][y=55.0] + + 20 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=72.0][y=55.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=85.0][y=25.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=85.0][y=35.0] + + 30 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=66.0][y=55.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=65.0][y=55.0] + + 20 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=70.0][y=58.0] + + 20 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=68.0][y=60.0] + + 30 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=47.0][y=40.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=47.0][y=35.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=45.0][y=35.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=45.0][y=30.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=95.0][y=30.0] + + 30 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=95.0][y=35.0] + + 20 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=53.0][y=30.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=92.0][y=30.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=53.0][y=35.0] + + 50 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=45.0][y=65.0] + + 20 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=90.0][y=35.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=38.0][y=15.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=38.0][y=5.0] + + 30 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=40.0][y=15.0] + + 40 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=40.0][y=5.0] + + 30 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=42.0][y=15.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=48.0][y=30.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=48.0][y=40.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=50.0][y=35.0] + + 20 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=50.0][y=40.0] + + 50 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=35.0][y=5.0] + + 20 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=50.0][y=30.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=28.0][y=35.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=28.0][y=30.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=30.0][y=30.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=32.0][y=30.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=30.0][y=35.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=30.0][y=32.0] + + 30 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=25.0][y=30.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=25.0][y=35.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=44.0][y=5.0] + + 20 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=42.0][y=10.0] + + 40 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=26.0][y=32.0] + + 10 + 90.0 + + + 0.0 + 1.7976931348623157E308 + + + + diff --git a/jsprit-examples/input/pickups_and_deliveries_solomon_r101.xml b/jsprit-examples/input/pickups_and_deliveries_solomon_r101.xml index cda89ffa..5a7e7967 100644 --- a/jsprit-examples/input/pickups_and_deliveries_solomon_r101.xml +++ b/jsprit-examples/input/pickups_and_deliveries_solomon_r101.xml @@ -1,1235 +1,1236 @@ - - INFINITE - HOMOGENEOUS - - - - solomonVehicle - solomonType - - 0 - - - - 0.0 - 230.0 - - - - - - solomonType - 200 - - 0.0 - 1.0 - - - - - - - [x=63.0][y=65.0] - - 8 - 10.0 - - - 143.0 - 153.0 - - - - - [x=2.0][y=60.0] - - 5 - 10.0 - - - 41.0 - 51.0 - - - - - [x=53.0][y=52.0] - - 11 - 10.0 - - - 37.0 - 47.0 - - - - - [x=65.0][y=55.0] - - 14 - 10.0 - - - 117.0 - 127.0 - - - - - [x=60.0][y=12.0] - - 31 - 10.0 - - - 44.0 - 54.0 - - - - - [x=20.0][y=20.0] - - 8 - 10.0 - - - 134.0 - 144.0 - - - - - [x=5.0][y=5.0] - - 16 - 10.0 - - - 83.0 - 93.0 - - - - - [x=23.0][y=3.0] - - 7 - 10.0 - - - 132.0 - 142.0 - - - - - [x=24.0][y=12.0] - - 5 - 10.0 - - - 31.0 - 41.0 - - - - - [x=42.0][y=7.0] - - 5 - 10.0 - - - 97.0 - 107.0 - - - - - [x=40.0][y=25.0] - - 9 - 10.0 - - - 85.0 - 95.0 - - - - - [x=45.0][y=10.0] - - 18 - 10.0 - - - 97.0 - 107.0 - - - - - [x=55.0][y=5.0] - - 29 - 10.0 - - - 68.0 - 78.0 - - - - - [x=65.0][y=35.0] - - 3 - 10.0 - - - 153.0 - 163.0 - - - - - [x=65.0][y=20.0] - - 6 - 10.0 - - - 172.0 - 182.0 - - - - - [x=45.0][y=30.0] - - 17 - 10.0 - - - 132.0 - 142.0 - - - - - [x=35.0][y=40.0] - - 16 - 10.0 - - - 37.0 - 47.0 - - - - - [x=41.0][y=37.0] - - 16 - 10.0 - - - 39.0 - 49.0 - - - - - [x=64.0][y=42.0] - - 9 - 10.0 - - - 63.0 - 73.0 - - - - - [x=55.0][y=45.0] - - 13 - 10.0 - - - 116.0 - 126.0 - - - - - [x=35.0][y=17.0] - - 7 - 10.0 - - - 50.0 - 60.0 - - - - - [x=41.0][y=49.0] - - 10 - 10.0 - - - 161.0 - 171.0 - - - - - [x=40.0][y=60.0] - - 21 - 10.0 - - - 71.0 - 81.0 - - - - - [x=20.0][y=50.0] - - 5 - 10.0 - - - 81.0 - 91.0 - - - - - [x=25.0][y=30.0] - - 3 - 10.0 - - - 99.0 - 109.0 - - - - - [x=15.0][y=30.0] - - 26 - 10.0 - - - 34.0 - 44.0 - - - - - [x=35.0][y=69.0] - - 23 - 10.0 - - - 141.0 - 151.0 - - - - - [x=55.0][y=20.0] - - 19 - 10.0 - - - 149.0 - 159.0 - - - - - [x=31.0][y=52.0] - - 27 - 10.0 - - - 50.0 - 60.0 - - - - - [x=55.0][y=60.0] - - 16 - 10.0 - - - 97.0 - 107.0 - - - - - [x=10.0][y=43.0] - - 9 - 10.0 - - - 95.0 - 105.0 - - - - - [x=15.0][y=60.0] - - 17 - 10.0 - - - 76.0 - 86.0 - - - - - [x=5.0][y=30.0] - - 2 - 10.0 - - - 157.0 - 167.0 - - - - - [x=20.0][y=40.0] - - 12 - 10.0 - - - 87.0 - 97.0 - - - - - [x=30.0][y=5.0] - - 8 - 10.0 - - - 61.0 - 71.0 - - - - - [x=10.0][y=20.0] - - 19 - 10.0 - - - 75.0 - 85.0 - - - - - [x=30.0][y=25.0] - - 23 - 10.0 - - - 159.0 - 169.0 - - - - - [x=15.0][y=10.0] - - 20 - 10.0 - - - 32.0 - 42.0 - - - - - [x=20.0][y=65.0] - - 12 - 10.0 - - - 67.0 - 77.0 - - - - - [x=50.0][y=35.0] - - 19 - 10.0 - - - 63.0 - 73.0 - - - - - [x=45.0][y=20.0] - - 11 - 10.0 - - - 62.0 - 72.0 - - - - - [x=45.0][y=65.0] - - 9 - 10.0 - - - 126.0 - 136.0 - - - - - [x=20.0][y=26.0] - - 9 - 10.0 - - - 83.0 - 93.0 - - - - - [x=18.0][y=18.0] - - 17 - 10.0 - - - 185.0 - 195.0 - - - - - [x=19.0][y=21.0] - - 10 - 10.0 - - - 58.0 - 68.0 - - - - - [x=25.0][y=21.0] - - 12 - 10.0 - - - 133.0 - 143.0 - - - - - [x=22.0][y=27.0] - - 11 - 10.0 - - - 135.0 - 145.0 - - - - - [x=25.0][y=24.0] - - 20 - 10.0 - - - 39.0 - 49.0 - - - - - [x=26.0][y=27.0] - - 27 - 10.0 - - - 100.0 - 110.0 - - - - - [x=18.0][y=24.0] - - 22 - 10.0 - - - 188.0 - 198.0 - - - - - [x=22.0][y=22.0] - - 2 - 10.0 - - - 18.0 - 28.0 - - - - - [x=15.0][y=19.0] - - 1 - 10.0 - - - 160.0 - 170.0 - - - - - [x=31.0][y=67.0] - - 3 - 10.0 - - - 95.0 - 105.0 - - - - - [x=30.0][y=60.0] - - 16 - 10.0 - - - 124.0 - 134.0 - - - - - [x=26.0][y=52.0] - - 9 - 10.0 - - - 74.0 - 84.0 - - - - - [x=26.0][y=35.0] - - 15 - 10.0 - - - 176.0 - 186.0 - - - - - [x=57.0][y=48.0] - - 23 - 10.0 - - - 92.0 - 102.0 - - - - - [x=61.0][y=52.0] - - 3 - 10.0 - - - 96.0 - 106.0 - - - - - [x=53.0][y=43.0] - - 14 - 10.0 - - - 179.0 - 189.0 - - - - - [x=15.0][y=47.0] - - 16 - 10.0 - - - 55.0 - 65.0 - - - - - [x=14.0][y=37.0] - - 11 - 10.0 - - - 44.0 - 54.0 - - - - - [x=56.0][y=37.0] - - 6 - 10.0 - - - 182.0 - 192.0 - - - - - [x=55.0][y=54.0] - - 26 - 10.0 - - - 94.0 - 104.0 - - - - - [x=4.0][y=18.0] - - 35 - 10.0 - - - 94.0 - 104.0 - - - - - [x=28.0][y=18.0] - - 26 - 10.0 - - - 93.0 - 103.0 - - - - - [x=11.0][y=31.0] - - 7 - 10.0 - - - 101.0 - 111.0 - - - - - [x=16.0][y=22.0] - - 41 - 10.0 - - - 91.0 - 101.0 - - - - - [x=67.0][y=5.0] - - 25 - 10.0 - - - 83.0 - 93.0 - - - - - [x=49.0][y=73.0] - - 25 - 10.0 - - - 127.0 - 137.0 - - - - - [x=37.0][y=47.0] - - 6 - 10.0 - - - 50.0 - 60.0 - - - - - [x=56.0][y=39.0] - - 36 - 10.0 - - - 142.0 - 152.0 - - - - - [x=37.0][y=56.0] - - 5 - 10.0 - - - 182.0 - 192.0 - - - - - [x=57.0][y=68.0] - - 15 - 10.0 - - - 77.0 - 87.0 - - - - - [x=47.0][y=16.0] - - 25 - 10.0 - - - 35.0 - 45.0 - - - - - [x=44.0][y=17.0] - - 9 - 10.0 - - - 78.0 - 88.0 - - - - - [x=46.0][y=13.0] - - 8 - 10.0 - - - 149.0 - 159.0 - - - - - [x=49.0][y=11.0] - - 18 - 10.0 - - - 69.0 - 79.0 - - - - - [x=49.0][y=42.0] - - 13 - 10.0 - - - 73.0 - 83.0 - - - - - [x=21.0][y=24.0] - - 28 - 10.0 - - - 18.0 - 28.0 - - - - - [x=36.0][y=26.0] - - 18 - 10.0 - - - 200.0 - 210.0 - - - - - [x=32.0][y=12.0] - - 7 - 10.0 - - - 101.0 - 111.0 - - - - - [x=53.0][y=12.0] - - 6 - 10.0 - - - 130.0 - 140.0 - - - - - [x=63.0][y=23.0] - - 2 - 10.0 - - - 136.0 - 146.0 - - - - - [x=15.0][y=77.0] - - 9 - 10.0 - - - 73.0 - 83.0 - - - - - [x=62.0][y=77.0] - - 20 - 10.0 - - - 51.0 - 61.0 - - - - - [x=24.0][y=58.0] - - 19 - 10.0 - - - 58.0 - 68.0 - - - - - [x=27.0][y=69.0] - - 10 - 10.0 - - - 34.0 - 44.0 - - - - - [x=17.0][y=34.0] - - 3 - 10.0 - - - 162.0 - 172.0 - - - - - [x=12.0][y=24.0] - - 13 - 10.0 - - - 76.0 - 86.0 - - - - - [x=6.0][y=68.0] - - 30 - 10.0 - - - 108.0 - 118.0 - - - - - [x=13.0][y=52.0] - - 36 - 10.0 - - - 165.0 - 175.0 - - - - - [x=6.0][y=38.0] - - 16 - 10.0 - - - 32.0 - 42.0 - - - - - [x=11.0][y=14.0] - - 18 - 10.0 - - - 69.0 - 79.0 - - - - - [x=8.0][y=56.0] - - 27 - 10.0 - - - 51.0 - 61.0 - - - - - [x=2.0][y=48.0] - - 1 - 10.0 - - - 117.0 - 127.0 - - - - - [x=49.0][y=58.0] - - 10 - 10.0 - - - 88.0 - 98.0 - - - - - [x=27.0][y=43.0] - - 9 - 10.0 - - - 52.0 - 62.0 - - - - - [x=37.0][y=31.0] - - 14 - 10.0 - - - 95.0 - 105.0 - - - - - [x=57.0][y=29.0] - - 18 - 10.0 - - - 140.0 - 150.0 - - - - - [x=47.0][y=47.0] - - 13 - 10.0 - - - 124.0 - 134.0 - - - - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.w3schools.com vrp_xml_schema.xsd"> + + INFINITE + HOMOGENEOUS + + + + solomonVehicle + solomonType + + 0 + + + + 0.0 + 230.0 + + + + + + solomonType + 200 + + 0.0 + 1.0 + + + + + + + [x=63.0][y=65.0] + + 8 + 10.0 + + + 143.0 + 153.0 + + + + + [x=2.0][y=60.0] + + 5 + 10.0 + + + 41.0 + 51.0 + + + + + [x=53.0][y=52.0] + + 11 + 10.0 + + + 37.0 + 47.0 + + + + + [x=65.0][y=55.0] + + 14 + 10.0 + + + 117.0 + 127.0 + + + + + [x=60.0][y=12.0] + + 31 + 10.0 + + + 44.0 + 54.0 + + + + + [x=20.0][y=20.0] + + 8 + 10.0 + + + 134.0 + 144.0 + + + + + [x=5.0][y=5.0] + + 16 + 10.0 + + + 83.0 + 93.0 + + + + + [x=23.0][y=3.0] + + 7 + 10.0 + + + 132.0 + 142.0 + + + + + [x=24.0][y=12.0] + + 5 + 10.0 + + + 31.0 + 41.0 + + + + + [x=42.0][y=7.0] + + 5 + 10.0 + + + 97.0 + 107.0 + + + + + [x=40.0][y=25.0] + + 9 + 10.0 + + + 85.0 + 95.0 + + + + + [x=45.0][y=10.0] + + 18 + 10.0 + + + 97.0 + 107.0 + + + + + [x=55.0][y=5.0] + + 29 + 10.0 + + + 68.0 + 78.0 + + + + + [x=65.0][y=35.0] + + 3 + 10.0 + + + 153.0 + 163.0 + + + + + [x=65.0][y=20.0] + + 6 + 10.0 + + + 172.0 + 182.0 + + + + + [x=45.0][y=30.0] + + 17 + 10.0 + + + 132.0 + 142.0 + + + + + [x=35.0][y=40.0] + + 16 + 10.0 + + + 37.0 + 47.0 + + + + + [x=41.0][y=37.0] + + 16 + 10.0 + + + 39.0 + 49.0 + + + + + [x=64.0][y=42.0] + + 9 + 10.0 + + + 63.0 + 73.0 + + + + + [x=55.0][y=45.0] + + 13 + 10.0 + + + 116.0 + 126.0 + + + + + [x=35.0][y=17.0] + + 7 + 10.0 + + + 50.0 + 60.0 + + + + + [x=41.0][y=49.0] + + 10 + 10.0 + + + 161.0 + 171.0 + + + + + [x=40.0][y=60.0] + + 21 + 10.0 + + + 71.0 + 81.0 + + + + + [x=20.0][y=50.0] + + 5 + 10.0 + + + 81.0 + 91.0 + + + + + [x=25.0][y=30.0] + + 3 + 10.0 + + + 99.0 + 109.0 + + + + + [x=15.0][y=30.0] + + 26 + 10.0 + + + 34.0 + 44.0 + + + + + [x=35.0][y=69.0] + + 23 + 10.0 + + + 141.0 + 151.0 + + + + + [x=55.0][y=20.0] + + 19 + 10.0 + + + 149.0 + 159.0 + + + + + [x=31.0][y=52.0] + + 27 + 10.0 + + + 50.0 + 60.0 + + + + + [x=55.0][y=60.0] + + 16 + 10.0 + + + 97.0 + 107.0 + + + + + [x=10.0][y=43.0] + + 9 + 10.0 + + + 95.0 + 105.0 + + + + + [x=15.0][y=60.0] + + 17 + 10.0 + + + 76.0 + 86.0 + + + + + [x=5.0][y=30.0] + + 2 + 10.0 + + + 157.0 + 167.0 + + + + + [x=20.0][y=40.0] + + 12 + 10.0 + + + 87.0 + 97.0 + + + + + [x=30.0][y=5.0] + + 8 + 10.0 + + + 61.0 + 71.0 + + + + + [x=10.0][y=20.0] + + 19 + 10.0 + + + 75.0 + 85.0 + + + + + [x=30.0][y=25.0] + + 23 + 10.0 + + + 159.0 + 169.0 + + + + + [x=15.0][y=10.0] + + 20 + 10.0 + + + 32.0 + 42.0 + + + + + [x=20.0][y=65.0] + + 12 + 10.0 + + + 67.0 + 77.0 + + + + + [x=50.0][y=35.0] + + 19 + 10.0 + + + 63.0 + 73.0 + + + + + [x=45.0][y=20.0] + + 11 + 10.0 + + + 62.0 + 72.0 + + + + + [x=45.0][y=65.0] + + 9 + 10.0 + + + 126.0 + 136.0 + + + + + [x=20.0][y=26.0] + + 9 + 10.0 + + + 83.0 + 93.0 + + + + + [x=18.0][y=18.0] + + 17 + 10.0 + + + 185.0 + 195.0 + + + + + [x=19.0][y=21.0] + + 10 + 10.0 + + + 58.0 + 68.0 + + + + + [x=25.0][y=21.0] + + 12 + 10.0 + + + 133.0 + 143.0 + + + + + [x=22.0][y=27.0] + + 11 + 10.0 + + + 135.0 + 145.0 + + + + + [x=25.0][y=24.0] + + 20 + 10.0 + + + 39.0 + 49.0 + + + + + [x=26.0][y=27.0] + + 27 + 10.0 + + + 100.0 + 110.0 + + + + + [x=18.0][y=24.0] + + 22 + 10.0 + + + 188.0 + 198.0 + + + + + [x=22.0][y=22.0] + + 2 + 10.0 + + + 18.0 + 28.0 + + + + + [x=15.0][y=19.0] + + 1 + 10.0 + + + 160.0 + 170.0 + + + + + [x=31.0][y=67.0] + + 3 + 10.0 + + + 95.0 + 105.0 + + + + + [x=30.0][y=60.0] + + 16 + 10.0 + + + 124.0 + 134.0 + + + + + [x=26.0][y=52.0] + + 9 + 10.0 + + + 74.0 + 84.0 + + + + + [x=26.0][y=35.0] + + 15 + 10.0 + + + 176.0 + 186.0 + + + + + [x=57.0][y=48.0] + + 23 + 10.0 + + + 92.0 + 102.0 + + + + + [x=61.0][y=52.0] + + 3 + 10.0 + + + 96.0 + 106.0 + + + + + [x=53.0][y=43.0] + + 14 + 10.0 + + + 179.0 + 189.0 + + + + + [x=15.0][y=47.0] + + 16 + 10.0 + + + 55.0 + 65.0 + + + + + [x=14.0][y=37.0] + + 11 + 10.0 + + + 44.0 + 54.0 + + + + + [x=56.0][y=37.0] + + 6 + 10.0 + + + 182.0 + 192.0 + + + + + [x=55.0][y=54.0] + + 26 + 10.0 + + + 94.0 + 104.0 + + + + + [x=4.0][y=18.0] + + 35 + 10.0 + + + 94.0 + 104.0 + + + + + [x=28.0][y=18.0] + + 26 + 10.0 + + + 93.0 + 103.0 + + + + + [x=11.0][y=31.0] + + 7 + 10.0 + + + 101.0 + 111.0 + + + + + [x=16.0][y=22.0] + + 41 + 10.0 + + + 91.0 + 101.0 + + + + + [x=67.0][y=5.0] + + 25 + 10.0 + + + 83.0 + 93.0 + + + + + [x=49.0][y=73.0] + + 25 + 10.0 + + + 127.0 + 137.0 + + + + + [x=37.0][y=47.0] + + 6 + 10.0 + + + 50.0 + 60.0 + + + + + [x=56.0][y=39.0] + + 36 + 10.0 + + + 142.0 + 152.0 + + + + + [x=37.0][y=56.0] + + 5 + 10.0 + + + 182.0 + 192.0 + + + + + [x=57.0][y=68.0] + + 15 + 10.0 + + + 77.0 + 87.0 + + + + + [x=47.0][y=16.0] + + 25 + 10.0 + + + 35.0 + 45.0 + + + + + [x=44.0][y=17.0] + + 9 + 10.0 + + + 78.0 + 88.0 + + + + + [x=46.0][y=13.0] + + 8 + 10.0 + + + 149.0 + 159.0 + + + + + [x=49.0][y=11.0] + + 18 + 10.0 + + + 69.0 + 79.0 + + + + + [x=49.0][y=42.0] + + 13 + 10.0 + + + 73.0 + 83.0 + + + + + [x=21.0][y=24.0] + + 28 + 10.0 + + + 18.0 + 28.0 + + + + + [x=36.0][y=26.0] + + 18 + 10.0 + + + 200.0 + 210.0 + + + + + [x=32.0][y=12.0] + + 7 + 10.0 + + + 101.0 + 111.0 + + + + + [x=53.0][y=12.0] + + 6 + 10.0 + + + 130.0 + 140.0 + + + + + [x=63.0][y=23.0] + + 2 + 10.0 + + + 136.0 + 146.0 + + + + + [x=15.0][y=77.0] + + 9 + 10.0 + + + 73.0 + 83.0 + + + + + [x=62.0][y=77.0] + + 20 + 10.0 + + + 51.0 + 61.0 + + + + + [x=24.0][y=58.0] + + 19 + 10.0 + + + 58.0 + 68.0 + + + + + [x=27.0][y=69.0] + + 10 + 10.0 + + + 34.0 + 44.0 + + + + + [x=17.0][y=34.0] + + 3 + 10.0 + + + 162.0 + 172.0 + + + + + [x=12.0][y=24.0] + + 13 + 10.0 + + + 76.0 + 86.0 + + + + + [x=6.0][y=68.0] + + 30 + 10.0 + + + 108.0 + 118.0 + + + + + [x=13.0][y=52.0] + + 36 + 10.0 + + + 165.0 + 175.0 + + + + + [x=6.0][y=38.0] + + 16 + 10.0 + + + 32.0 + 42.0 + + + + + [x=11.0][y=14.0] + + 18 + 10.0 + + + 69.0 + 79.0 + + + + + [x=8.0][y=56.0] + + 27 + 10.0 + + + 51.0 + 61.0 + + + + + [x=2.0][y=48.0] + + 1 + 10.0 + + + 117.0 + 127.0 + + + + + [x=49.0][y=58.0] + + 10 + 10.0 + + + 88.0 + 98.0 + + + + + [x=27.0][y=43.0] + + 9 + 10.0 + + + 52.0 + 62.0 + + + + + [x=37.0][y=31.0] + + 14 + 10.0 + + + 95.0 + 105.0 + + + + + [x=57.0][y=29.0] + + 18 + 10.0 + + + 140.0 + 150.0 + + + + + [x=47.0][y=47.0] + + 13 + 10.0 + + + 124.0 + 134.0 + + + + diff --git a/jsprit-examples/input/pickups_and_deliveries_solomon_r101_open.xml b/jsprit-examples/input/pickups_and_deliveries_solomon_r101_open.xml index 758cfab0..bb3296cf 100644 --- a/jsprit-examples/input/pickups_and_deliveries_solomon_r101_open.xml +++ b/jsprit-examples/input/pickups_and_deliveries_solomon_r101_open.xml @@ -1,1236 +1,1237 @@ - - INFINITE - HOMOGENEOUS - - - - solomonVehicle - solomonType - - 0 - - - - 0.0 - 230.0 - - false - - - - - solomonType - 200 - - 100.0 - 1.0 - - - - - - - [x=63.0][y=65.0] - - 8 - 10.0 - - - 143.0 - 153.0 - - - - - [x=2.0][y=60.0] - - 5 - 10.0 - - - 41.0 - 51.0 - - - - - [x=53.0][y=52.0] - - 11 - 10.0 - - - 37.0 - 47.0 - - - - - [x=65.0][y=55.0] - - 14 - 10.0 - - - 117.0 - 127.0 - - - - - [x=60.0][y=12.0] - - 31 - 10.0 - - - 44.0 - 54.0 - - - - - [x=20.0][y=20.0] - - 8 - 10.0 - - - 134.0 - 144.0 - - - - - [x=5.0][y=5.0] - - 16 - 10.0 - - - 83.0 - 93.0 - - - - - [x=23.0][y=3.0] - - 7 - 10.0 - - - 132.0 - 142.0 - - - - - [x=24.0][y=12.0] - - 5 - 10.0 - - - 31.0 - 41.0 - - - - - [x=42.0][y=7.0] - - 5 - 10.0 - - - 97.0 - 107.0 - - - - - [x=40.0][y=25.0] - - 9 - 10.0 - - - 85.0 - 95.0 - - - - - [x=45.0][y=10.0] - - 18 - 10.0 - - - 97.0 - 107.0 - - - - - [x=55.0][y=5.0] - - 29 - 10.0 - - - 68.0 - 78.0 - - - - - [x=65.0][y=35.0] - - 3 - 10.0 - - - 153.0 - 163.0 - - - - - [x=65.0][y=20.0] - - 6 - 10.0 - - - 172.0 - 182.0 - - - - - [x=45.0][y=30.0] - - 17 - 10.0 - - - 132.0 - 142.0 - - - - - [x=35.0][y=40.0] - - 16 - 10.0 - - - 37.0 - 47.0 - - - - - [x=41.0][y=37.0] - - 16 - 10.0 - - - 39.0 - 49.0 - - - - - [x=64.0][y=42.0] - - 9 - 10.0 - - - 63.0 - 73.0 - - - - - [x=55.0][y=45.0] - - 13 - 10.0 - - - 116.0 - 126.0 - - - - - [x=35.0][y=17.0] - - 7 - 10.0 - - - 50.0 - 60.0 - - - - - [x=41.0][y=49.0] - - 10 - 10.0 - - - 161.0 - 171.0 - - - - - [x=40.0][y=60.0] - - 21 - 10.0 - - - 71.0 - 81.0 - - - - - [x=20.0][y=50.0] - - 5 - 10.0 - - - 81.0 - 91.0 - - - - - [x=25.0][y=30.0] - - 3 - 10.0 - - - 99.0 - 109.0 - - - - - [x=15.0][y=30.0] - - 26 - 10.0 - - - 34.0 - 44.0 - - - - - [x=35.0][y=69.0] - - 23 - 10.0 - - - 141.0 - 151.0 - - - - - [x=55.0][y=20.0] - - 19 - 10.0 - - - 149.0 - 159.0 - - - - - [x=31.0][y=52.0] - - 27 - 10.0 - - - 50.0 - 60.0 - - - - - [x=55.0][y=60.0] - - 16 - 10.0 - - - 97.0 - 107.0 - - - - - [x=10.0][y=43.0] - - 9 - 10.0 - - - 95.0 - 105.0 - - - - - [x=15.0][y=60.0] - - 17 - 10.0 - - - 76.0 - 86.0 - - - - - [x=5.0][y=30.0] - - 2 - 10.0 - - - 157.0 - 167.0 - - - - - [x=20.0][y=40.0] - - 12 - 10.0 - - - 87.0 - 97.0 - - - - - [x=30.0][y=5.0] - - 8 - 10.0 - - - 61.0 - 71.0 - - - - - [x=10.0][y=20.0] - - 19 - 10.0 - - - 75.0 - 85.0 - - - - - [x=30.0][y=25.0] - - 23 - 10.0 - - - 159.0 - 169.0 - - - - - [x=15.0][y=10.0] - - 20 - 10.0 - - - 32.0 - 42.0 - - - - - [x=20.0][y=65.0] - - 12 - 10.0 - - - 67.0 - 77.0 - - - - - [x=50.0][y=35.0] - - 19 - 10.0 - - - 63.0 - 73.0 - - - - - [x=45.0][y=20.0] - - 11 - 10.0 - - - 62.0 - 72.0 - - - - - [x=45.0][y=65.0] - - 9 - 10.0 - - - 126.0 - 136.0 - - - - - [x=20.0][y=26.0] - - 9 - 10.0 - - - 83.0 - 93.0 - - - - - [x=18.0][y=18.0] - - 17 - 10.0 - - - 185.0 - 195.0 - - - - - [x=19.0][y=21.0] - - 10 - 10.0 - - - 58.0 - 68.0 - - - - - [x=25.0][y=21.0] - - 12 - 10.0 - - - 133.0 - 143.0 - - - - - [x=22.0][y=27.0] - - 11 - 10.0 - - - 135.0 - 145.0 - - - - - [x=25.0][y=24.0] - - 20 - 10.0 - - - 39.0 - 49.0 - - - - - [x=26.0][y=27.0] - - 27 - 10.0 - - - 100.0 - 110.0 - - - - - [x=18.0][y=24.0] - - 22 - 10.0 - - - 188.0 - 198.0 - - - - - [x=22.0][y=22.0] - - 2 - 10.0 - - - 18.0 - 28.0 - - - - - [x=15.0][y=19.0] - - 1 - 10.0 - - - 160.0 - 170.0 - - - - - [x=31.0][y=67.0] - - 3 - 10.0 - - - 95.0 - 105.0 - - - - - [x=30.0][y=60.0] - - 16 - 10.0 - - - 124.0 - 134.0 - - - - - [x=26.0][y=52.0] - - 9 - 10.0 - - - 74.0 - 84.0 - - - - - [x=26.0][y=35.0] - - 15 - 10.0 - - - 176.0 - 186.0 - - - - - [x=57.0][y=48.0] - - 23 - 10.0 - - - 92.0 - 102.0 - - - - - [x=61.0][y=52.0] - - 3 - 10.0 - - - 96.0 - 106.0 - - - - - [x=53.0][y=43.0] - - 14 - 10.0 - - - 179.0 - 189.0 - - - - - [x=15.0][y=47.0] - - 16 - 10.0 - - - 55.0 - 65.0 - - - - - [x=14.0][y=37.0] - - 11 - 10.0 - - - 44.0 - 54.0 - - - - - [x=56.0][y=37.0] - - 6 - 10.0 - - - 182.0 - 192.0 - - - - - [x=55.0][y=54.0] - - 26 - 10.0 - - - 94.0 - 104.0 - - - - - [x=4.0][y=18.0] - - 35 - 10.0 - - - 94.0 - 104.0 - - - - - [x=28.0][y=18.0] - - 26 - 10.0 - - - 93.0 - 103.0 - - - - - [x=11.0][y=31.0] - - 7 - 10.0 - - - 101.0 - 111.0 - - - - - [x=16.0][y=22.0] - - 41 - 10.0 - - - 91.0 - 101.0 - - - - - [x=67.0][y=5.0] - - 25 - 10.0 - - - 83.0 - 93.0 - - - - - [x=49.0][y=73.0] - - 25 - 10.0 - - - 127.0 - 137.0 - - - - - [x=37.0][y=47.0] - - 6 - 10.0 - - - 50.0 - 60.0 - - - - - [x=56.0][y=39.0] - - 36 - 10.0 - - - 142.0 - 152.0 - - - - - [x=37.0][y=56.0] - - 5 - 10.0 - - - 182.0 - 192.0 - - - - - [x=57.0][y=68.0] - - 15 - 10.0 - - - 77.0 - 87.0 - - - - - [x=47.0][y=16.0] - - 25 - 10.0 - - - 35.0 - 45.0 - - - - - [x=44.0][y=17.0] - - 9 - 10.0 - - - 78.0 - 88.0 - - - - - [x=46.0][y=13.0] - - 8 - 10.0 - - - 149.0 - 159.0 - - - - - [x=49.0][y=11.0] - - 18 - 10.0 - - - 69.0 - 79.0 - - - - - [x=49.0][y=42.0] - - 13 - 10.0 - - - 73.0 - 83.0 - - - - - [x=21.0][y=24.0] - - 28 - 10.0 - - - 18.0 - 28.0 - - - - - [x=36.0][y=26.0] - - 18 - 10.0 - - - 200.0 - 210.0 - - - - - [x=32.0][y=12.0] - - 7 - 10.0 - - - 101.0 - 111.0 - - - - - [x=53.0][y=12.0] - - 6 - 10.0 - - - 130.0 - 140.0 - - - - - [x=63.0][y=23.0] - - 2 - 10.0 - - - 136.0 - 146.0 - - - - - [x=15.0][y=77.0] - - 9 - 10.0 - - - 73.0 - 83.0 - - - - - [x=62.0][y=77.0] - - 20 - 10.0 - - - 51.0 - 61.0 - - - - - [x=24.0][y=58.0] - - 19 - 10.0 - - - 58.0 - 68.0 - - - - - [x=27.0][y=69.0] - - 10 - 10.0 - - - 34.0 - 44.0 - - - - - [x=17.0][y=34.0] - - 3 - 10.0 - - - 162.0 - 172.0 - - - - - [x=12.0][y=24.0] - - 13 - 10.0 - - - 76.0 - 86.0 - - - - - [x=6.0][y=68.0] - - 30 - 10.0 - - - 108.0 - 118.0 - - - - - [x=13.0][y=52.0] - - 36 - 10.0 - - - 165.0 - 175.0 - - - - - [x=6.0][y=38.0] - - 16 - 10.0 - - - 32.0 - 42.0 - - - - - [x=11.0][y=14.0] - - 18 - 10.0 - - - 69.0 - 79.0 - - - - - [x=8.0][y=56.0] - - 27 - 10.0 - - - 51.0 - 61.0 - - - - - [x=2.0][y=48.0] - - 1 - 10.0 - - - 117.0 - 127.0 - - - - - [x=49.0][y=58.0] - - 10 - 10.0 - - - 88.0 - 98.0 - - - - - [x=27.0][y=43.0] - - 9 - 10.0 - - - 52.0 - 62.0 - - - - - [x=37.0][y=31.0] - - 14 - 10.0 - - - 95.0 - 105.0 - - - - - [x=57.0][y=29.0] - - 18 - 10.0 - - - 140.0 - 150.0 - - - - - [x=47.0][y=47.0] - - 13 - 10.0 - - - 124.0 - 134.0 - - - - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.w3schools.com vrp_xml_schema.xsd"> + + INFINITE + HOMOGENEOUS + + + + solomonVehicle + solomonType + + 0 + + + + 0.0 + 230.0 + + false + + + + + solomonType + 200 + + 100.0 + 1.0 + + + + + + + [x=63.0][y=65.0] + + 8 + 10.0 + + + 143.0 + 153.0 + + + + + [x=2.0][y=60.0] + + 5 + 10.0 + + + 41.0 + 51.0 + + + + + [x=53.0][y=52.0] + + 11 + 10.0 + + + 37.0 + 47.0 + + + + + [x=65.0][y=55.0] + + 14 + 10.0 + + + 117.0 + 127.0 + + + + + [x=60.0][y=12.0] + + 31 + 10.0 + + + 44.0 + 54.0 + + + + + [x=20.0][y=20.0] + + 8 + 10.0 + + + 134.0 + 144.0 + + + + + [x=5.0][y=5.0] + + 16 + 10.0 + + + 83.0 + 93.0 + + + + + [x=23.0][y=3.0] + + 7 + 10.0 + + + 132.0 + 142.0 + + + + + [x=24.0][y=12.0] + + 5 + 10.0 + + + 31.0 + 41.0 + + + + + [x=42.0][y=7.0] + + 5 + 10.0 + + + 97.0 + 107.0 + + + + + [x=40.0][y=25.0] + + 9 + 10.0 + + + 85.0 + 95.0 + + + + + [x=45.0][y=10.0] + + 18 + 10.0 + + + 97.0 + 107.0 + + + + + [x=55.0][y=5.0] + + 29 + 10.0 + + + 68.0 + 78.0 + + + + + [x=65.0][y=35.0] + + 3 + 10.0 + + + 153.0 + 163.0 + + + + + [x=65.0][y=20.0] + + 6 + 10.0 + + + 172.0 + 182.0 + + + + + [x=45.0][y=30.0] + + 17 + 10.0 + + + 132.0 + 142.0 + + + + + [x=35.0][y=40.0] + + 16 + 10.0 + + + 37.0 + 47.0 + + + + + [x=41.0][y=37.0] + + 16 + 10.0 + + + 39.0 + 49.0 + + + + + [x=64.0][y=42.0] + + 9 + 10.0 + + + 63.0 + 73.0 + + + + + [x=55.0][y=45.0] + + 13 + 10.0 + + + 116.0 + 126.0 + + + + + [x=35.0][y=17.0] + + 7 + 10.0 + + + 50.0 + 60.0 + + + + + [x=41.0][y=49.0] + + 10 + 10.0 + + + 161.0 + 171.0 + + + + + [x=40.0][y=60.0] + + 21 + 10.0 + + + 71.0 + 81.0 + + + + + [x=20.0][y=50.0] + + 5 + 10.0 + + + 81.0 + 91.0 + + + + + [x=25.0][y=30.0] + + 3 + 10.0 + + + 99.0 + 109.0 + + + + + [x=15.0][y=30.0] + + 26 + 10.0 + + + 34.0 + 44.0 + + + + + [x=35.0][y=69.0] + + 23 + 10.0 + + + 141.0 + 151.0 + + + + + [x=55.0][y=20.0] + + 19 + 10.0 + + + 149.0 + 159.0 + + + + + [x=31.0][y=52.0] + + 27 + 10.0 + + + 50.0 + 60.0 + + + + + [x=55.0][y=60.0] + + 16 + 10.0 + + + 97.0 + 107.0 + + + + + [x=10.0][y=43.0] + + 9 + 10.0 + + + 95.0 + 105.0 + + + + + [x=15.0][y=60.0] + + 17 + 10.0 + + + 76.0 + 86.0 + + + + + [x=5.0][y=30.0] + + 2 + 10.0 + + + 157.0 + 167.0 + + + + + [x=20.0][y=40.0] + + 12 + 10.0 + + + 87.0 + 97.0 + + + + + [x=30.0][y=5.0] + + 8 + 10.0 + + + 61.0 + 71.0 + + + + + [x=10.0][y=20.0] + + 19 + 10.0 + + + 75.0 + 85.0 + + + + + [x=30.0][y=25.0] + + 23 + 10.0 + + + 159.0 + 169.0 + + + + + [x=15.0][y=10.0] + + 20 + 10.0 + + + 32.0 + 42.0 + + + + + [x=20.0][y=65.0] + + 12 + 10.0 + + + 67.0 + 77.0 + + + + + [x=50.0][y=35.0] + + 19 + 10.0 + + + 63.0 + 73.0 + + + + + [x=45.0][y=20.0] + + 11 + 10.0 + + + 62.0 + 72.0 + + + + + [x=45.0][y=65.0] + + 9 + 10.0 + + + 126.0 + 136.0 + + + + + [x=20.0][y=26.0] + + 9 + 10.0 + + + 83.0 + 93.0 + + + + + [x=18.0][y=18.0] + + 17 + 10.0 + + + 185.0 + 195.0 + + + + + [x=19.0][y=21.0] + + 10 + 10.0 + + + 58.0 + 68.0 + + + + + [x=25.0][y=21.0] + + 12 + 10.0 + + + 133.0 + 143.0 + + + + + [x=22.0][y=27.0] + + 11 + 10.0 + + + 135.0 + 145.0 + + + + + [x=25.0][y=24.0] + + 20 + 10.0 + + + 39.0 + 49.0 + + + + + [x=26.0][y=27.0] + + 27 + 10.0 + + + 100.0 + 110.0 + + + + + [x=18.0][y=24.0] + + 22 + 10.0 + + + 188.0 + 198.0 + + + + + [x=22.0][y=22.0] + + 2 + 10.0 + + + 18.0 + 28.0 + + + + + [x=15.0][y=19.0] + + 1 + 10.0 + + + 160.0 + 170.0 + + + + + [x=31.0][y=67.0] + + 3 + 10.0 + + + 95.0 + 105.0 + + + + + [x=30.0][y=60.0] + + 16 + 10.0 + + + 124.0 + 134.0 + + + + + [x=26.0][y=52.0] + + 9 + 10.0 + + + 74.0 + 84.0 + + + + + [x=26.0][y=35.0] + + 15 + 10.0 + + + 176.0 + 186.0 + + + + + [x=57.0][y=48.0] + + 23 + 10.0 + + + 92.0 + 102.0 + + + + + [x=61.0][y=52.0] + + 3 + 10.0 + + + 96.0 + 106.0 + + + + + [x=53.0][y=43.0] + + 14 + 10.0 + + + 179.0 + 189.0 + + + + + [x=15.0][y=47.0] + + 16 + 10.0 + + + 55.0 + 65.0 + + + + + [x=14.0][y=37.0] + + 11 + 10.0 + + + 44.0 + 54.0 + + + + + [x=56.0][y=37.0] + + 6 + 10.0 + + + 182.0 + 192.0 + + + + + [x=55.0][y=54.0] + + 26 + 10.0 + + + 94.0 + 104.0 + + + + + [x=4.0][y=18.0] + + 35 + 10.0 + + + 94.0 + 104.0 + + + + + [x=28.0][y=18.0] + + 26 + 10.0 + + + 93.0 + 103.0 + + + + + [x=11.0][y=31.0] + + 7 + 10.0 + + + 101.0 + 111.0 + + + + + [x=16.0][y=22.0] + + 41 + 10.0 + + + 91.0 + 101.0 + + + + + [x=67.0][y=5.0] + + 25 + 10.0 + + + 83.0 + 93.0 + + + + + [x=49.0][y=73.0] + + 25 + 10.0 + + + 127.0 + 137.0 + + + + + [x=37.0][y=47.0] + + 6 + 10.0 + + + 50.0 + 60.0 + + + + + [x=56.0][y=39.0] + + 36 + 10.0 + + + 142.0 + 152.0 + + + + + [x=37.0][y=56.0] + + 5 + 10.0 + + + 182.0 + 192.0 + + + + + [x=57.0][y=68.0] + + 15 + 10.0 + + + 77.0 + 87.0 + + + + + [x=47.0][y=16.0] + + 25 + 10.0 + + + 35.0 + 45.0 + + + + + [x=44.0][y=17.0] + + 9 + 10.0 + + + 78.0 + 88.0 + + + + + [x=46.0][y=13.0] + + 8 + 10.0 + + + 149.0 + 159.0 + + + + + [x=49.0][y=11.0] + + 18 + 10.0 + + + 69.0 + 79.0 + + + + + [x=49.0][y=42.0] + + 13 + 10.0 + + + 73.0 + 83.0 + + + + + [x=21.0][y=24.0] + + 28 + 10.0 + + + 18.0 + 28.0 + + + + + [x=36.0][y=26.0] + + 18 + 10.0 + + + 200.0 + 210.0 + + + + + [x=32.0][y=12.0] + + 7 + 10.0 + + + 101.0 + 111.0 + + + + + [x=53.0][y=12.0] + + 6 + 10.0 + + + 130.0 + 140.0 + + + + + [x=63.0][y=23.0] + + 2 + 10.0 + + + 136.0 + 146.0 + + + + + [x=15.0][y=77.0] + + 9 + 10.0 + + + 73.0 + 83.0 + + + + + [x=62.0][y=77.0] + + 20 + 10.0 + + + 51.0 + 61.0 + + + + + [x=24.0][y=58.0] + + 19 + 10.0 + + + 58.0 + 68.0 + + + + + [x=27.0][y=69.0] + + 10 + 10.0 + + + 34.0 + 44.0 + + + + + [x=17.0][y=34.0] + + 3 + 10.0 + + + 162.0 + 172.0 + + + + + [x=12.0][y=24.0] + + 13 + 10.0 + + + 76.0 + 86.0 + + + + + [x=6.0][y=68.0] + + 30 + 10.0 + + + 108.0 + 118.0 + + + + + [x=13.0][y=52.0] + + 36 + 10.0 + + + 165.0 + 175.0 + + + + + [x=6.0][y=38.0] + + 16 + 10.0 + + + 32.0 + 42.0 + + + + + [x=11.0][y=14.0] + + 18 + 10.0 + + + 69.0 + 79.0 + + + + + [x=8.0][y=56.0] + + 27 + 10.0 + + + 51.0 + 61.0 + + + + + [x=2.0][y=48.0] + + 1 + 10.0 + + + 117.0 + 127.0 + + + + + [x=49.0][y=58.0] + + 10 + 10.0 + + + 88.0 + 98.0 + + + + + [x=27.0][y=43.0] + + 9 + 10.0 + + + 52.0 + 62.0 + + + + + [x=37.0][y=31.0] + + 14 + 10.0 + + + 95.0 + 105.0 + + + + + [x=57.0][y=29.0] + + 18 + 10.0 + + + 140.0 + 150.0 + + + + + [x=47.0][y=47.0] + + 13 + 10.0 + + + 124.0 + 134.0 + + + + diff --git a/jsprit-examples/input/pickups_and_deliveries_solomon_r101_withoutTWs.xml b/jsprit-examples/input/pickups_and_deliveries_solomon_r101_withoutTWs.xml index df35bceb..e6c08797 100644 --- a/jsprit-examples/input/pickups_and_deliveries_solomon_r101_withoutTWs.xml +++ b/jsprit-examples/input/pickups_and_deliveries_solomon_r101_withoutTWs.xml @@ -1,1235 +1,1236 @@ - - INFINITE - HOMOGENEOUS - - - - solomonVehicle - solomonType - - 0 - - - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.w3schools.com vrp_xml_schema.xsd"> + + INFINITE + HOMOGENEOUS + + + + solomonVehicle + solomonType + + 0 + + + + 0.0 + 230.0 + + + + + + solomonType + 200 + + 0.0 + 1.0 + + + + + + + [x=63.0][y=65.0] + + 8 + 10.0 + + 0.0 - 230.0 - - - - - - solomonType - 200 - - 0.0 - 1.0 - - - - - - - [x=63.0][y=65.0] - - 8 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=2.0][y=60.0] - - 5 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=53.0][y=52.0] - - 11 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=65.0][y=55.0] - - 14 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=60.0][y=12.0] - - 31 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=20.0][y=20.0] - - 8 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=5.0][y=5.0] - - 16 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=23.0][y=3.0] - - 7 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=24.0][y=12.0] - - 5 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=42.0][y=7.0] - - 5 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=40.0][y=25.0] - - 9 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=45.0][y=10.0] - - 18 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=55.0][y=5.0] - - 29 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=65.0][y=35.0] - - 3 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=65.0][y=20.0] - - 6 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=45.0][y=30.0] - - 17 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=35.0][y=40.0] - - 16 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=41.0][y=37.0] - - 16 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=64.0][y=42.0] - - 9 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=55.0][y=45.0] - - 13 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=35.0][y=17.0] - - 7 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=41.0][y=49.0] - - 10 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=40.0][y=60.0] - - 21 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=20.0][y=50.0] - - 5 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=25.0][y=30.0] - - 3 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=15.0][y=30.0] - - 26 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=35.0][y=69.0] - - 23 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=55.0][y=20.0] - - 19 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=31.0][y=52.0] - - 27 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=55.0][y=60.0] - - 16 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=10.0][y=43.0] - - 9 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=15.0][y=60.0] - - 17 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=5.0][y=30.0] - - 2 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=20.0][y=40.0] - - 12 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=30.0][y=5.0] - - 8 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=10.0][y=20.0] - - 19 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=30.0][y=25.0] - - 23 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=15.0][y=10.0] - - 20 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=20.0][y=65.0] - - 12 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=50.0][y=35.0] - - 19 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=45.0][y=20.0] - - 11 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=45.0][y=65.0] - - 9 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=20.0][y=26.0] - - 9 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=18.0][y=18.0] - - 17 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=19.0][y=21.0] - - 10 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=25.0][y=21.0] - - 12 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=22.0][y=27.0] - - 11 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=25.0][y=24.0] - - 20 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=26.0][y=27.0] - - 27 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=18.0][y=24.0] - - 22 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=22.0][y=22.0] - - 2 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=15.0][y=19.0] - - 1 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=31.0][y=67.0] - - 3 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=30.0][y=60.0] - - 16 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=26.0][y=52.0] - - 9 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=26.0][y=35.0] - - 15 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=57.0][y=48.0] - - 23 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=61.0][y=52.0] - - 3 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=53.0][y=43.0] - - 14 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=15.0][y=47.0] - - 16 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=14.0][y=37.0] - - 11 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=56.0][y=37.0] - - 6 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=55.0][y=54.0] - - 26 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=4.0][y=18.0] - - 35 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=28.0][y=18.0] - - 26 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=11.0][y=31.0] - - 7 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=16.0][y=22.0] - - 41 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=67.0][y=5.0] - - 25 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=49.0][y=73.0] - - 25 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=37.0][y=47.0] - - 6 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=56.0][y=39.0] - - 36 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=37.0][y=56.0] - - 5 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=57.0][y=68.0] - - 15 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=47.0][y=16.0] - - 25 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=44.0][y=17.0] - - 9 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=46.0][y=13.0] - - 8 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=49.0][y=11.0] - - 18 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=49.0][y=42.0] - - 13 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=21.0][y=24.0] - - 28 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=36.0][y=26.0] - - 18 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=32.0][y=12.0] - - 7 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=53.0][y=12.0] - - 6 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=63.0][y=23.0] - - 2 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=15.0][y=77.0] - - 9 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=62.0][y=77.0] - - 20 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=24.0][y=58.0] - - 19 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=27.0][y=69.0] - - 10 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=17.0][y=34.0] - - 3 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=12.0][y=24.0] - - 13 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=6.0][y=68.0] - - 30 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=13.0][y=52.0] - - 36 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=6.0][y=38.0] - - 16 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=11.0][y=14.0] - - 18 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=8.0][y=56.0] - - 27 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=2.0][y=48.0] - - 1 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=49.0][y=58.0] - - 10 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=27.0][y=43.0] - - 9 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=37.0][y=31.0] - - 14 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=57.0][y=29.0] - - 18 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=47.0][y=47.0] - - 13 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - + 1.7976931348623157E308 + + + + + [x=2.0][y=60.0] + + 5 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=53.0][y=52.0] + + 11 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=65.0][y=55.0] + + 14 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=60.0][y=12.0] + + 31 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=20.0][y=20.0] + + 8 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=5.0][y=5.0] + + 16 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=23.0][y=3.0] + + 7 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=24.0][y=12.0] + + 5 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=42.0][y=7.0] + + 5 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=40.0][y=25.0] + + 9 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=45.0][y=10.0] + + 18 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=55.0][y=5.0] + + 29 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=65.0][y=35.0] + + 3 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=65.0][y=20.0] + + 6 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=45.0][y=30.0] + + 17 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=35.0][y=40.0] + + 16 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=41.0][y=37.0] + + 16 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=64.0][y=42.0] + + 9 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=55.0][y=45.0] + + 13 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=35.0][y=17.0] + + 7 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=41.0][y=49.0] + + 10 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=40.0][y=60.0] + + 21 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=20.0][y=50.0] + + 5 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=25.0][y=30.0] + + 3 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=15.0][y=30.0] + + 26 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=35.0][y=69.0] + + 23 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=55.0][y=20.0] + + 19 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=31.0][y=52.0] + + 27 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=55.0][y=60.0] + + 16 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=10.0][y=43.0] + + 9 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=15.0][y=60.0] + + 17 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=5.0][y=30.0] + + 2 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=20.0][y=40.0] + + 12 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=30.0][y=5.0] + + 8 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=10.0][y=20.0] + + 19 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=30.0][y=25.0] + + 23 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=15.0][y=10.0] + + 20 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=20.0][y=65.0] + + 12 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=50.0][y=35.0] + + 19 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=45.0][y=20.0] + + 11 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=45.0][y=65.0] + + 9 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=20.0][y=26.0] + + 9 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=18.0][y=18.0] + + 17 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=19.0][y=21.0] + + 10 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=25.0][y=21.0] + + 12 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=22.0][y=27.0] + + 11 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=25.0][y=24.0] + + 20 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=26.0][y=27.0] + + 27 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=18.0][y=24.0] + + 22 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=22.0][y=22.0] + + 2 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=15.0][y=19.0] + + 1 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=31.0][y=67.0] + + 3 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=30.0][y=60.0] + + 16 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=26.0][y=52.0] + + 9 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=26.0][y=35.0] + + 15 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=57.0][y=48.0] + + 23 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=61.0][y=52.0] + + 3 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=53.0][y=43.0] + + 14 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=15.0][y=47.0] + + 16 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=14.0][y=37.0] + + 11 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=56.0][y=37.0] + + 6 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=55.0][y=54.0] + + 26 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=4.0][y=18.0] + + 35 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=28.0][y=18.0] + + 26 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=11.0][y=31.0] + + 7 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=16.0][y=22.0] + + 41 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=67.0][y=5.0] + + 25 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=49.0][y=73.0] + + 25 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=37.0][y=47.0] + + 6 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=56.0][y=39.0] + + 36 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=37.0][y=56.0] + + 5 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=57.0][y=68.0] + + 15 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=47.0][y=16.0] + + 25 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=44.0][y=17.0] + + 9 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=46.0][y=13.0] + + 8 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=49.0][y=11.0] + + 18 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=49.0][y=42.0] + + 13 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=21.0][y=24.0] + + 28 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=36.0][y=26.0] + + 18 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=32.0][y=12.0] + + 7 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=53.0][y=12.0] + + 6 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=63.0][y=23.0] + + 2 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=15.0][y=77.0] + + 9 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=62.0][y=77.0] + + 20 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=24.0][y=58.0] + + 19 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=27.0][y=69.0] + + 10 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=17.0][y=34.0] + + 3 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=12.0][y=24.0] + + 13 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=6.0][y=68.0] + + 30 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=13.0][y=52.0] + + 36 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=6.0][y=38.0] + + 16 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=11.0][y=14.0] + + 18 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=8.0][y=56.0] + + 27 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=2.0][y=48.0] + + 1 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=49.0][y=58.0] + + 10 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=27.0][y=43.0] + + 9 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=37.0][y=31.0] + + 14 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=57.0][y=29.0] + + 18 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=47.0][y=47.0] + + 13 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + diff --git a/jsprit-examples/input/pickups_and_deliveries_solomon_r101_withoutTWs_open.xml b/jsprit-examples/input/pickups_and_deliveries_solomon_r101_withoutTWs_open.xml index 46fba629..24fd7a52 100644 --- a/jsprit-examples/input/pickups_and_deliveries_solomon_r101_withoutTWs_open.xml +++ b/jsprit-examples/input/pickups_and_deliveries_solomon_r101_withoutTWs_open.xml @@ -1,1236 +1,1237 @@ - - INFINITE - HOMOGENEOUS - - - - solomonVehicle - solomonType - - 0 - - - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.w3schools.com vrp_xml_schema.xsd"> + + INFINITE + HOMOGENEOUS + + + + solomonVehicle + solomonType + + 0 + + + + 0.0 + 230.0 + + false + + + + + solomonType + 200 + + 0.0 + 1.0 + + + + + + + [x=63.0][y=65.0] + + 8 + 10.0 + + 0.0 - 230.0 - - false - - - - - solomonType - 200 - - 0.0 - 1.0 - - - - - - - [x=63.0][y=65.0] - - 8 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=2.0][y=60.0] - - 5 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=53.0][y=52.0] - - 11 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=65.0][y=55.0] - - 14 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=60.0][y=12.0] - - 31 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=20.0][y=20.0] - - 8 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=5.0][y=5.0] - - 16 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=23.0][y=3.0] - - 7 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=24.0][y=12.0] - - 5 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=42.0][y=7.0] - - 5 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=40.0][y=25.0] - - 9 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=45.0][y=10.0] - - 18 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=55.0][y=5.0] - - 29 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=65.0][y=35.0] - - 3 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=65.0][y=20.0] - - 6 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=45.0][y=30.0] - - 17 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=35.0][y=40.0] - - 16 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=41.0][y=37.0] - - 16 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=64.0][y=42.0] - - 9 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=55.0][y=45.0] - - 13 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=35.0][y=17.0] - - 7 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=41.0][y=49.0] - - 10 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=40.0][y=60.0] - - 21 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=20.0][y=50.0] - - 5 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=25.0][y=30.0] - - 3 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=15.0][y=30.0] - - 26 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=35.0][y=69.0] - - 23 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=55.0][y=20.0] - - 19 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=31.0][y=52.0] - - 27 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=55.0][y=60.0] - - 16 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=10.0][y=43.0] - - 9 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=15.0][y=60.0] - - 17 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=5.0][y=30.0] - - 2 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=20.0][y=40.0] - - 12 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=30.0][y=5.0] - - 8 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=10.0][y=20.0] - - 19 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=30.0][y=25.0] - - 23 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=15.0][y=10.0] - - 20 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=20.0][y=65.0] - - 12 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=50.0][y=35.0] - - 19 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=45.0][y=20.0] - - 11 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=45.0][y=65.0] - - 9 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=20.0][y=26.0] - - 9 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=18.0][y=18.0] - - 17 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=19.0][y=21.0] - - 10 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=25.0][y=21.0] - - 12 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=22.0][y=27.0] - - 11 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=25.0][y=24.0] - - 20 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=26.0][y=27.0] - - 27 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=18.0][y=24.0] - - 22 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=22.0][y=22.0] - - 2 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=15.0][y=19.0] - - 1 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=31.0][y=67.0] - - 3 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=30.0][y=60.0] - - 16 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=26.0][y=52.0] - - 9 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=26.0][y=35.0] - - 15 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=57.0][y=48.0] - - 23 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=61.0][y=52.0] - - 3 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=53.0][y=43.0] - - 14 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=15.0][y=47.0] - - 16 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=14.0][y=37.0] - - 11 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=56.0][y=37.0] - - 6 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=55.0][y=54.0] - - 26 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=4.0][y=18.0] - - 35 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=28.0][y=18.0] - - 26 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=11.0][y=31.0] - - 7 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=16.0][y=22.0] - - 41 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=67.0][y=5.0] - - 25 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=49.0][y=73.0] - - 25 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=37.0][y=47.0] - - 6 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=56.0][y=39.0] - - 36 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=37.0][y=56.0] - - 5 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=57.0][y=68.0] - - 15 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=47.0][y=16.0] - - 25 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=44.0][y=17.0] - - 9 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=46.0][y=13.0] - - 8 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=49.0][y=11.0] - - 18 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=49.0][y=42.0] - - 13 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=21.0][y=24.0] - - 28 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=36.0][y=26.0] - - 18 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=32.0][y=12.0] - - 7 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=53.0][y=12.0] - - 6 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=63.0][y=23.0] - - 2 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=15.0][y=77.0] - - 9 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=62.0][y=77.0] - - 20 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=24.0][y=58.0] - - 19 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=27.0][y=69.0] - - 10 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=17.0][y=34.0] - - 3 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=12.0][y=24.0] - - 13 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=6.0][y=68.0] - - 30 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=13.0][y=52.0] - - 36 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=6.0][y=38.0] - - 16 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=11.0][y=14.0] - - 18 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=8.0][y=56.0] - - 27 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=2.0][y=48.0] - - 1 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=49.0][y=58.0] - - 10 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=27.0][y=43.0] - - 9 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=37.0][y=31.0] - - 14 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=57.0][y=29.0] - - 18 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - - [x=47.0][y=47.0] - - 13 - 10.0 - - - 0.0 - 1.7976931348623157E308 - - - - + 1.7976931348623157E308 + + + + + [x=2.0][y=60.0] + + 5 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=53.0][y=52.0] + + 11 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=65.0][y=55.0] + + 14 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=60.0][y=12.0] + + 31 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=20.0][y=20.0] + + 8 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=5.0][y=5.0] + + 16 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=23.0][y=3.0] + + 7 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=24.0][y=12.0] + + 5 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=42.0][y=7.0] + + 5 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=40.0][y=25.0] + + 9 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=45.0][y=10.0] + + 18 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=55.0][y=5.0] + + 29 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=65.0][y=35.0] + + 3 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=65.0][y=20.0] + + 6 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=45.0][y=30.0] + + 17 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=35.0][y=40.0] + + 16 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=41.0][y=37.0] + + 16 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=64.0][y=42.0] + + 9 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=55.0][y=45.0] + + 13 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=35.0][y=17.0] + + 7 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=41.0][y=49.0] + + 10 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=40.0][y=60.0] + + 21 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=20.0][y=50.0] + + 5 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=25.0][y=30.0] + + 3 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=15.0][y=30.0] + + 26 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=35.0][y=69.0] + + 23 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=55.0][y=20.0] + + 19 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=31.0][y=52.0] + + 27 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=55.0][y=60.0] + + 16 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=10.0][y=43.0] + + 9 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=15.0][y=60.0] + + 17 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=5.0][y=30.0] + + 2 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=20.0][y=40.0] + + 12 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=30.0][y=5.0] + + 8 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=10.0][y=20.0] + + 19 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=30.0][y=25.0] + + 23 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=15.0][y=10.0] + + 20 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=20.0][y=65.0] + + 12 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=50.0][y=35.0] + + 19 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=45.0][y=20.0] + + 11 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=45.0][y=65.0] + + 9 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=20.0][y=26.0] + + 9 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=18.0][y=18.0] + + 17 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=19.0][y=21.0] + + 10 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=25.0][y=21.0] + + 12 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=22.0][y=27.0] + + 11 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=25.0][y=24.0] + + 20 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=26.0][y=27.0] + + 27 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=18.0][y=24.0] + + 22 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=22.0][y=22.0] + + 2 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=15.0][y=19.0] + + 1 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=31.0][y=67.0] + + 3 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=30.0][y=60.0] + + 16 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=26.0][y=52.0] + + 9 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=26.0][y=35.0] + + 15 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=57.0][y=48.0] + + 23 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=61.0][y=52.0] + + 3 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=53.0][y=43.0] + + 14 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=15.0][y=47.0] + + 16 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=14.0][y=37.0] + + 11 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=56.0][y=37.0] + + 6 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=55.0][y=54.0] + + 26 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=4.0][y=18.0] + + 35 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=28.0][y=18.0] + + 26 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=11.0][y=31.0] + + 7 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=16.0][y=22.0] + + 41 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=67.0][y=5.0] + + 25 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=49.0][y=73.0] + + 25 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=37.0][y=47.0] + + 6 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=56.0][y=39.0] + + 36 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=37.0][y=56.0] + + 5 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=57.0][y=68.0] + + 15 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=47.0][y=16.0] + + 25 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=44.0][y=17.0] + + 9 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=46.0][y=13.0] + + 8 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=49.0][y=11.0] + + 18 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=49.0][y=42.0] + + 13 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=21.0][y=24.0] + + 28 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=36.0][y=26.0] + + 18 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=32.0][y=12.0] + + 7 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=53.0][y=12.0] + + 6 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=63.0][y=23.0] + + 2 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=15.0][y=77.0] + + 9 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=62.0][y=77.0] + + 20 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=24.0][y=58.0] + + 19 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=27.0][y=69.0] + + 10 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=17.0][y=34.0] + + 3 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=12.0][y=24.0] + + 13 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=6.0][y=68.0] + + 30 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=13.0][y=52.0] + + 36 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=6.0][y=38.0] + + 16 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=11.0][y=14.0] + + 18 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=8.0][y=56.0] + + 27 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=2.0][y=48.0] + + 1 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=49.0][y=58.0] + + 10 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=27.0][y=43.0] + + 9 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=37.0][y=31.0] + + 14 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=57.0][y=29.0] + + 18 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + + [x=47.0][y=47.0] + + 13 + 10.0 + + + 0.0 + 1.7976931348623157E308 + + + + diff --git a/jsprit-examples/input/pickups_solomon_c101.xml b/jsprit-examples/input/pickups_solomon_c101.xml index 90d6cea1..f9a6cf46 100644 --- a/jsprit-examples/input/pickups_solomon_c101.xml +++ b/jsprit-examples/input/pickups_solomon_c101.xml @@ -1,1235 +1,1236 @@ - - INFINITE - HOMOGENEOUS - - - - solomonVehicle - solomonType - - 0 - - - - 0.0 - 1236.0 - - - - - - solomonType - 200 - - 0.0 - 1.0 - - - - - - - [x=5.0][y=35.0] - - 10 - 90.0 - - - 283.0 - 344.0 - - - - - [x=5.0][y=45.0] - - 10 - 90.0 - - - 665.0 - 716.0 - - - - - [x=8.0][y=40.0] - - 40 - 90.0 - - - 87.0 - 158.0 - - - - - [x=8.0][y=45.0] - - 20 - 90.0 - - - 751.0 - 816.0 - - - - - [x=0.0][y=45.0] - - 20 - 90.0 - - - 567.0 - 624.0 - - - - - [x=2.0][y=40.0] - - 20 - 90.0 - - - 383.0 - 434.0 - - - - - [x=0.0][y=40.0] - - 30 - 90.0 - - - 479.0 - 522.0 - - - - - [x=33.0][y=35.0] - - 10 - 90.0 - - - 16.0 - 80.0 - - - - - [x=33.0][y=32.0] - - 20 - 90.0 - - - 68.0 - 149.0 - - - - - [x=35.0][y=32.0] - - 10 - 90.0 - - - 166.0 - 235.0 - - - - - [x=35.0][y=30.0] - - 10 - 90.0 - - - 264.0 - 321.0 - - - - - [x=28.0][y=52.0] - - 20 - 90.0 - - - 812.0 - 883.0 - - - - - [x=28.0][y=55.0] - - 10 - 90.0 - - - 732.0 - 777.0 - - - - - [x=25.0][y=50.0] - - 10 - 90.0 - - - 65.0 - 144.0 - - - - - [x=25.0][y=52.0] - - 40 - 90.0 - - - 169.0 - 224.0 - - - - - [x=25.0][y=55.0] - - 10 - 90.0 - - - 622.0 - 701.0 - - - - - [x=23.0][y=52.0] - - 10 - 90.0 - - - 261.0 - 316.0 - - - - - [x=23.0][y=55.0] - - 20 - 90.0 - - - 546.0 - 593.0 - - - - - [x=20.0][y=50.0] - - 10 - 90.0 - - - 358.0 - 405.0 - - - - - [x=42.0][y=66.0] - - 10 - 90.0 - - - 65.0 - 146.0 - - - - - [x=45.0][y=70.0] - - 30 - 90.0 - - - 825.0 - 870.0 - - - - - [x=45.0][y=68.0] - - 10 - 90.0 - - - 912.0 - 967.0 - - - - - [x=20.0][y=55.0] - - 10 - 90.0 - - - 449.0 - 504.0 - - - - - [x=40.0][y=66.0] - - 20 - 90.0 - - - 170.0 - 225.0 - - - - - [x=40.0][y=69.0] - - 20 - 90.0 - - - 621.0 - 702.0 - - - - - [x=42.0][y=65.0] - - 10 - 90.0 - - - 15.0 - 67.0 - - - - - [x=10.0][y=40.0] - - 30 - 90.0 - - - 31.0 - 100.0 - - - - - [x=42.0][y=68.0] - - 10 - 90.0 - - - 727.0 - 782.0 - - - - - [x=10.0][y=35.0] - - 20 - 90.0 - - - 200.0 - 237.0 - - - - - [x=38.0][y=70.0] - - 10 - 90.0 - - - 534.0 - 605.0 - - - - - [x=38.0][y=68.0] - - 20 - 90.0 - - - 255.0 - 324.0 - - - - - [x=15.0][y=80.0] - - 10 - 90.0 - - - 278.0 - 345.0 - - - - - [x=18.0][y=75.0] - - 20 - 90.0 - - - 99.0 - 148.0 - - - - - [x=15.0][y=75.0] - - 20 - 90.0 - - - 179.0 - 254.0 - - - - - [x=20.0][y=80.0] - - 40 - 90.0 - - - 384.0 - 429.0 - - - - - [x=20.0][y=85.0] - - 40 - 90.0 - - - 475.0 - 528.0 - - - - - [x=22.0][y=75.0] - - 30 - 90.0 - - - 30.0 - 92.0 - - - - - [x=22.0][y=85.0] - - 10 - 90.0 - - - 567.0 - 620.0 - - - - - [x=35.0][y=69.0] - - 10 - 90.0 - - - 448.0 - 505.0 - - - - - [x=25.0][y=85.0] - - 20 - 90.0 - - - 652.0 - 721.0 - - - - - [x=30.0][y=52.0] - - 20 - 90.0 - - - 914.0 - 965.0 - - - - - [x=30.0][y=50.0] - - 10 - 90.0 - - - 10.0 - 73.0 - - - - - [x=55.0][y=80.0] - - 10 - 90.0 - - - 743.0 - 820.0 - - - - - [x=55.0][y=85.0] - - 20 - 90.0 - - - 647.0 - 726.0 - - - - - [x=58.0][y=75.0] - - 20 - 90.0 - - - 30.0 - 84.0 - - - - - [x=60.0][y=85.0] - - 30 - 90.0 - - - 561.0 - 622.0 - - - - - [x=60.0][y=80.0] - - 10 - 90.0 - - - 95.0 - 156.0 - - - - - [x=62.0][y=80.0] - - 30 - 90.0 - - - 196.0 - 239.0 - - - - - [x=65.0][y=82.0] - - 10 - 90.0 - - - 285.0 - 336.0 - - - - - [x=65.0][y=85.0] - - 40 - 90.0 - - - 475.0 - 518.0 - - - - - [x=67.0][y=85.0] - - 20 - 90.0 - - - 368.0 - 441.0 - - - - - [x=60.0][y=60.0] - - 10 - 90.0 - - - 836.0 - 889.0 - - - - - [x=60.0][y=55.0] - - 10 - 90.0 - - - 20.0 - 84.0 - - - - - [x=35.0][y=66.0] - - 10 - 90.0 - - - 357.0 - 410.0 - - - - - [x=65.0][y=60.0] - - 30 - 90.0 - - - 645.0 - 708.0 - - - - - [x=63.0][y=58.0] - - 10 - 90.0 - - - 737.0 - 802.0 - - - - - [x=87.0][y=30.0] - - 10 - 90.0 - - - 668.0 - 731.0 - - - - - [x=88.0][y=35.0] - - 20 - 90.0 - - - 109.0 - 170.0 - - - - - [x=88.0][y=30.0] - - 10 - 90.0 - - - 574.0 - 643.0 - - - - - [x=75.0][y=55.0] - - 20 - 90.0 - - - 369.0 - 420.0 - - - - - [x=72.0][y=55.0] - - 10 - 90.0 - - - 265.0 - 338.0 - - - - - [x=85.0][y=25.0] - - 10 - 90.0 - - - 769.0 - 820.0 - - - - - [x=85.0][y=35.0] - - 30 - 90.0 - - - 47.0 - 124.0 - - - - - [x=66.0][y=55.0] - - 10 - 90.0 - - - 173.0 - 238.0 - - - - - [x=65.0][y=55.0] - - 20 - 90.0 - - - 85.0 - 144.0 - - - - - [x=70.0][y=58.0] - - 20 - 90.0 - - - 458.0 - 523.0 - - - - - [x=68.0][y=60.0] - - 30 - 90.0 - - - 555.0 - 612.0 - - - - - [x=47.0][y=40.0] - - 10 - 90.0 - - - 12.0 - 77.0 - - - - - [x=47.0][y=35.0] - - 10 - 90.0 - - - 826.0 - 875.0 - - - - - [x=45.0][y=35.0] - - 10 - 90.0 - - - 916.0 - 969.0 - - - - - [x=45.0][y=30.0] - - 10 - 90.0 - - - 734.0 - 777.0 - - - - - [x=95.0][y=30.0] - - 30 - 90.0 - - - 387.0 - 456.0 - - - - - [x=95.0][y=35.0] - - 20 - 90.0 - - - 293.0 - 360.0 - - - - - [x=53.0][y=30.0] - - 10 - 90.0 - - - 450.0 - 505.0 - - - - - [x=92.0][y=30.0] - - 10 - 90.0 - - - 478.0 - 551.0 - - - - - [x=53.0][y=35.0] - - 50 - 90.0 - - - 353.0 - 412.0 - - - - - [x=45.0][y=65.0] - - 20 - 90.0 - - - 997.0 - 1068.0 - - - - - [x=90.0][y=35.0] - - 10 - 90.0 - - - 203.0 - 260.0 - - - - - [x=38.0][y=15.0] - - 10 - 90.0 - - - 651.0 - 740.0 - - - - - [x=38.0][y=5.0] - - 30 - 90.0 - - - 471.0 - 534.0 - - - - - [x=40.0][y=15.0] - - 40 - 90.0 - - - 35.0 - 87.0 - - - - - [x=40.0][y=5.0] - - 30 - 90.0 - - - 385.0 - 436.0 - - - - - [x=42.0][y=15.0] - - 10 - 90.0 - - - 95.0 - 158.0 - - - - - [x=48.0][y=30.0] - - 10 - 90.0 - - - 632.0 - 693.0 - - - - - [x=48.0][y=40.0] - - 10 - 90.0 - - - 76.0 - 129.0 - - - - - [x=50.0][y=35.0] - - 20 - 90.0 - - - 262.0 - 317.0 - - - - - [x=50.0][y=40.0] - - 50 - 90.0 - - - 171.0 - 218.0 - - - - - [x=35.0][y=5.0] - - 20 - 90.0 - - - 562.0 - 629.0 - - - - - [x=50.0][y=30.0] - - 10 - 90.0 - - - 531.0 - 610.0 - - - - - [x=28.0][y=35.0] - - 10 - 90.0 - - - 1001.0 - 1066.0 - - - - - [x=28.0][y=30.0] - - 10 - 90.0 - - - 632.0 - 693.0 - - - - - [x=30.0][y=30.0] - - 10 - 90.0 - - - 541.0 - 600.0 - - - - - [x=32.0][y=30.0] - - 10 - 90.0 - - - 359.0 - 412.0 - - - - - [x=30.0][y=35.0] - - 10 - 90.0 - - - 1054.0 - 1127.0 - - - - - [x=30.0][y=32.0] - - 30 - 90.0 - - - 448.0 - 509.0 - - - - - [x=25.0][y=30.0] - - 10 - 90.0 - - - 725.0 - 786.0 - - - - - [x=25.0][y=35.0] - - 10 - 90.0 - - - 912.0 - 969.0 - - - - - [x=44.0][y=5.0] - - 20 - 90.0 - - - 286.0 - 347.0 - - - - - [x=42.0][y=10.0] - - 40 - 90.0 - - - 186.0 - 257.0 - - - - - [x=26.0][y=32.0] - - 10 - 90.0 - - - 815.0 - 880.0 - - - - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.w3schools.com vrp_xml_schema.xsd"> + + INFINITE + HOMOGENEOUS + + + + solomonVehicle + solomonType + + 0 + + + + 0.0 + 1236.0 + + + + + + solomonType + 200 + + 0.0 + 1.0 + + + + + + + [x=5.0][y=35.0] + + 10 + 90.0 + + + 283.0 + 344.0 + + + + + [x=5.0][y=45.0] + + 10 + 90.0 + + + 665.0 + 716.0 + + + + + [x=8.0][y=40.0] + + 40 + 90.0 + + + 87.0 + 158.0 + + + + + [x=8.0][y=45.0] + + 20 + 90.0 + + + 751.0 + 816.0 + + + + + [x=0.0][y=45.0] + + 20 + 90.0 + + + 567.0 + 624.0 + + + + + [x=2.0][y=40.0] + + 20 + 90.0 + + + 383.0 + 434.0 + + + + + [x=0.0][y=40.0] + + 30 + 90.0 + + + 479.0 + 522.0 + + + + + [x=33.0][y=35.0] + + 10 + 90.0 + + + 16.0 + 80.0 + + + + + [x=33.0][y=32.0] + + 20 + 90.0 + + + 68.0 + 149.0 + + + + + [x=35.0][y=32.0] + + 10 + 90.0 + + + 166.0 + 235.0 + + + + + [x=35.0][y=30.0] + + 10 + 90.0 + + + 264.0 + 321.0 + + + + + [x=28.0][y=52.0] + + 20 + 90.0 + + + 812.0 + 883.0 + + + + + [x=28.0][y=55.0] + + 10 + 90.0 + + + 732.0 + 777.0 + + + + + [x=25.0][y=50.0] + + 10 + 90.0 + + + 65.0 + 144.0 + + + + + [x=25.0][y=52.0] + + 40 + 90.0 + + + 169.0 + 224.0 + + + + + [x=25.0][y=55.0] + + 10 + 90.0 + + + 622.0 + 701.0 + + + + + [x=23.0][y=52.0] + + 10 + 90.0 + + + 261.0 + 316.0 + + + + + [x=23.0][y=55.0] + + 20 + 90.0 + + + 546.0 + 593.0 + + + + + [x=20.0][y=50.0] + + 10 + 90.0 + + + 358.0 + 405.0 + + + + + [x=42.0][y=66.0] + + 10 + 90.0 + + + 65.0 + 146.0 + + + + + [x=45.0][y=70.0] + + 30 + 90.0 + + + 825.0 + 870.0 + + + + + [x=45.0][y=68.0] + + 10 + 90.0 + + + 912.0 + 967.0 + + + + + [x=20.0][y=55.0] + + 10 + 90.0 + + + 449.0 + 504.0 + + + + + [x=40.0][y=66.0] + + 20 + 90.0 + + + 170.0 + 225.0 + + + + + [x=40.0][y=69.0] + + 20 + 90.0 + + + 621.0 + 702.0 + + + + + [x=42.0][y=65.0] + + 10 + 90.0 + + + 15.0 + 67.0 + + + + + [x=10.0][y=40.0] + + 30 + 90.0 + + + 31.0 + 100.0 + + + + + [x=42.0][y=68.0] + + 10 + 90.0 + + + 727.0 + 782.0 + + + + + [x=10.0][y=35.0] + + 20 + 90.0 + + + 200.0 + 237.0 + + + + + [x=38.0][y=70.0] + + 10 + 90.0 + + + 534.0 + 605.0 + + + + + [x=38.0][y=68.0] + + 20 + 90.0 + + + 255.0 + 324.0 + + + + + [x=15.0][y=80.0] + + 10 + 90.0 + + + 278.0 + 345.0 + + + + + [x=18.0][y=75.0] + + 20 + 90.0 + + + 99.0 + 148.0 + + + + + [x=15.0][y=75.0] + + 20 + 90.0 + + + 179.0 + 254.0 + + + + + [x=20.0][y=80.0] + + 40 + 90.0 + + + 384.0 + 429.0 + + + + + [x=20.0][y=85.0] + + 40 + 90.0 + + + 475.0 + 528.0 + + + + + [x=22.0][y=75.0] + + 30 + 90.0 + + + 30.0 + 92.0 + + + + + [x=22.0][y=85.0] + + 10 + 90.0 + + + 567.0 + 620.0 + + + + + [x=35.0][y=69.0] + + 10 + 90.0 + + + 448.0 + 505.0 + + + + + [x=25.0][y=85.0] + + 20 + 90.0 + + + 652.0 + 721.0 + + + + + [x=30.0][y=52.0] + + 20 + 90.0 + + + 914.0 + 965.0 + + + + + [x=30.0][y=50.0] + + 10 + 90.0 + + + 10.0 + 73.0 + + + + + [x=55.0][y=80.0] + + 10 + 90.0 + + + 743.0 + 820.0 + + + + + [x=55.0][y=85.0] + + 20 + 90.0 + + + 647.0 + 726.0 + + + + + [x=58.0][y=75.0] + + 20 + 90.0 + + + 30.0 + 84.0 + + + + + [x=60.0][y=85.0] + + 30 + 90.0 + + + 561.0 + 622.0 + + + + + [x=60.0][y=80.0] + + 10 + 90.0 + + + 95.0 + 156.0 + + + + + [x=62.0][y=80.0] + + 30 + 90.0 + + + 196.0 + 239.0 + + + + + [x=65.0][y=82.0] + + 10 + 90.0 + + + 285.0 + 336.0 + + + + + [x=65.0][y=85.0] + + 40 + 90.0 + + + 475.0 + 518.0 + + + + + [x=67.0][y=85.0] + + 20 + 90.0 + + + 368.0 + 441.0 + + + + + [x=60.0][y=60.0] + + 10 + 90.0 + + + 836.0 + 889.0 + + + + + [x=60.0][y=55.0] + + 10 + 90.0 + + + 20.0 + 84.0 + + + + + [x=35.0][y=66.0] + + 10 + 90.0 + + + 357.0 + 410.0 + + + + + [x=65.0][y=60.0] + + 30 + 90.0 + + + 645.0 + 708.0 + + + + + [x=63.0][y=58.0] + + 10 + 90.0 + + + 737.0 + 802.0 + + + + + [x=87.0][y=30.0] + + 10 + 90.0 + + + 668.0 + 731.0 + + + + + [x=88.0][y=35.0] + + 20 + 90.0 + + + 109.0 + 170.0 + + + + + [x=88.0][y=30.0] + + 10 + 90.0 + + + 574.0 + 643.0 + + + + + [x=75.0][y=55.0] + + 20 + 90.0 + + + 369.0 + 420.0 + + + + + [x=72.0][y=55.0] + + 10 + 90.0 + + + 265.0 + 338.0 + + + + + [x=85.0][y=25.0] + + 10 + 90.0 + + + 769.0 + 820.0 + + + + + [x=85.0][y=35.0] + + 30 + 90.0 + + + 47.0 + 124.0 + + + + + [x=66.0][y=55.0] + + 10 + 90.0 + + + 173.0 + 238.0 + + + + + [x=65.0][y=55.0] + + 20 + 90.0 + + + 85.0 + 144.0 + + + + + [x=70.0][y=58.0] + + 20 + 90.0 + + + 458.0 + 523.0 + + + + + [x=68.0][y=60.0] + + 30 + 90.0 + + + 555.0 + 612.0 + + + + + [x=47.0][y=40.0] + + 10 + 90.0 + + + 12.0 + 77.0 + + + + + [x=47.0][y=35.0] + + 10 + 90.0 + + + 826.0 + 875.0 + + + + + [x=45.0][y=35.0] + + 10 + 90.0 + + + 916.0 + 969.0 + + + + + [x=45.0][y=30.0] + + 10 + 90.0 + + + 734.0 + 777.0 + + + + + [x=95.0][y=30.0] + + 30 + 90.0 + + + 387.0 + 456.0 + + + + + [x=95.0][y=35.0] + + 20 + 90.0 + + + 293.0 + 360.0 + + + + + [x=53.0][y=30.0] + + 10 + 90.0 + + + 450.0 + 505.0 + + + + + [x=92.0][y=30.0] + + 10 + 90.0 + + + 478.0 + 551.0 + + + + + [x=53.0][y=35.0] + + 50 + 90.0 + + + 353.0 + 412.0 + + + + + [x=45.0][y=65.0] + + 20 + 90.0 + + + 997.0 + 1068.0 + + + + + [x=90.0][y=35.0] + + 10 + 90.0 + + + 203.0 + 260.0 + + + + + [x=38.0][y=15.0] + + 10 + 90.0 + + + 651.0 + 740.0 + + + + + [x=38.0][y=5.0] + + 30 + 90.0 + + + 471.0 + 534.0 + + + + + [x=40.0][y=15.0] + + 40 + 90.0 + + + 35.0 + 87.0 + + + + + [x=40.0][y=5.0] + + 30 + 90.0 + + + 385.0 + 436.0 + + + + + [x=42.0][y=15.0] + + 10 + 90.0 + + + 95.0 + 158.0 + + + + + [x=48.0][y=30.0] + + 10 + 90.0 + + + 632.0 + 693.0 + + + + + [x=48.0][y=40.0] + + 10 + 90.0 + + + 76.0 + 129.0 + + + + + [x=50.0][y=35.0] + + 20 + 90.0 + + + 262.0 + 317.0 + + + + + [x=50.0][y=40.0] + + 50 + 90.0 + + + 171.0 + 218.0 + + + + + [x=35.0][y=5.0] + + 20 + 90.0 + + + 562.0 + 629.0 + + + + + [x=50.0][y=30.0] + + 10 + 90.0 + + + 531.0 + 610.0 + + + + + [x=28.0][y=35.0] + + 10 + 90.0 + + + 1001.0 + 1066.0 + + + + + [x=28.0][y=30.0] + + 10 + 90.0 + + + 632.0 + 693.0 + + + + + [x=30.0][y=30.0] + + 10 + 90.0 + + + 541.0 + 600.0 + + + + + [x=32.0][y=30.0] + + 10 + 90.0 + + + 359.0 + 412.0 + + + + + [x=30.0][y=35.0] + + 10 + 90.0 + + + 1054.0 + 1127.0 + + + + + [x=30.0][y=32.0] + + 30 + 90.0 + + + 448.0 + 509.0 + + + + + [x=25.0][y=30.0] + + 10 + 90.0 + + + 725.0 + 786.0 + + + + + [x=25.0][y=35.0] + + 10 + 90.0 + + + 912.0 + 969.0 + + + + + [x=44.0][y=5.0] + + 20 + 90.0 + + + 286.0 + 347.0 + + + + + [x=42.0][y=10.0] + + 40 + 90.0 + + + 186.0 + 257.0 + + + + + [x=26.0][y=32.0] + + 10 + 90.0 + + + 815.0 + 880.0 + + + + diff --git a/jsprit-examples/input/vrp_cordeau_01.xml b/jsprit-examples/input/vrp_cordeau_01.xml index 20a9e895..c3c8d211 100644 --- a/jsprit-examples/input/vrp_cordeau_01.xml +++ b/jsprit-examples/input/vrp_cordeau_01.xml @@ -1,607 +1,608 @@ - - - - 35 - - 17 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 36 - - 6 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 33 - - 23 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 34 - - 26 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 39 - - 14 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 37 - - 9 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 38 - - 15 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 43 - - 11 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 42 - - 13 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 41 - - 27 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 40 - - 7 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 22 - - 8 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 23 - - 16 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 24 - - 10 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 25 - - 28 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 26 - - 7 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 27 - - 15 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 28 - - 14 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 29 - - 6 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 3 - - 16 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 2 - - 30 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 1 - - 7 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 7 - - 19 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 30 - - 19 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 6 - - 15 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 5 - - 21 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 32 - - 12 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 4 - - 9 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 31 - - 11 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 9 - - 11 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 8 - - 23 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 19 - - 9 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 17 - - 3 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 18 - - 41 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 15 - - 10 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 16 - - 15 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 13 - - 23 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 14 - - 21 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 11 - - 19 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 12 - - 29 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 21 - - 8 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 20 - - 28 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 49 - - 18 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 48 - - 17 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 45 - - 10 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 44 - - 16 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 47 - - 25 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 46 - - 5 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 10 - - 5 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 50 - - 10 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.w3schools.com vrp_xml_schema.xsd"> + + + + 35 + + 17 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 36 + + 6 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 33 + + 23 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 34 + + 26 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 39 + + 14 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 37 + + 9 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 38 + + 15 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 43 + + 11 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 42 + + 13 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 41 + + 27 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 40 + + 7 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 22 + + 8 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 23 + + 16 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 24 + + 10 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 25 + + 28 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 26 + + 7 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 27 + + 15 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 28 + + 14 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 29 + + 6 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 3 + + 16 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 2 + + 30 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 1 + + 7 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 7 + + 19 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 30 + + 19 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 6 + + 15 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 5 + + 21 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 32 + + 12 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 4 + + 9 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 31 + + 11 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 9 + + 11 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 8 + + 23 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 19 + + 9 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 17 + + 3 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 18 + + 41 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 15 + + 10 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 16 + + 15 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 13 + + 23 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 14 + + 21 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 11 + + 19 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 12 + + 29 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 21 + + 8 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 20 + + 28 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 49 + + 18 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 48 + + 17 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 45 + + 10 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 44 + + 16 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 47 + + 25 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 46 + + 5 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 10 + + 5 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 50 + + 10 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + diff --git a/jsprit-examples/input/vrp_cordeau_08.xml b/jsprit-examples/input/vrp_cordeau_08.xml index 23f9e48e..9ecbbd96 100644 --- a/jsprit-examples/input/vrp_cordeau_08.xml +++ b/jsprit-examples/input/vrp_cordeau_08.xml @@ -1,2995 +1,2996 @@ - - - - 35 - - 9 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 36 - - 74 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 33 - - 47 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 159 - - 46 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 34 - - 57 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 158 - - 79 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 39 - - 42 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 157 - - 79 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 156 - - 97 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 37 - - 83 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 155 - - 65 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 38 - - 96 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 154 - - 97 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 152 - - 24 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 153 - - 69 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 150 - - 83 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 151 - - 22 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 43 - - 43 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 42 - - 56 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 41 - - 22 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 40 - - 80 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 202 - - 92 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 203 - - 1 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 204 - - 2 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 205 - - 63 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 200 - - 11 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 201 - - 98 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 22 - - 40 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 23 - - 8 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 169 - - 49 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 24 - - 69 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 25 - - 93 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 206 - - 57 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 26 - - 29 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 166 - - 23 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 207 - - 50 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 27 - - 5 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 165 - - 3 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 208 - - 19 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 28 - - 53 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 168 - - 40 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 209 - - 24 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 29 - - 8 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 167 - - 19 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 3 - - 93 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 161 - - 39 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 2 - - 72 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 162 - - 94 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 1 - - 6 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 163 - - 97 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 164 - - 18 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 7 - - 1 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 30 - - 24 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 6 - - 43 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 5 - - 5 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 32 - - 13 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 4 - - 28 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 31 - - 53 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 160 - - 52 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 9 - - 53 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 8 - - 36 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 211 - - 18 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 212 - - 77 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 210 - - 14 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 215 - - 49 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 216 - - 58 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 213 - - 28 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 19 - - 88 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 214 - - 72 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 219 - - 41 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 17 - - 51 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 179 - - 59 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 18 - - 47 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 178 - - 84 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 217 - - 84 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 15 - - 66 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 177 - - 36 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 218 - - 58 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 16 - - 37 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 176 - - 10 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 13 - - 57 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 14 - - 1 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 11 - - 25 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 12 - - 50 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 21 - - 48 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 170 - - 96 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 20 - - 75 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 171 - - 58 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 174 - - 56 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 175 - - 67 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 172 - - 15 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 173 - - 21 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 220 - - 98 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 221 - - 77 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 222 - - 57 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 223 - - 39 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 224 - - 99 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 225 - - 83 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 226 - - 54 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 227 - - 86 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 228 - - 2 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 188 - - 18 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 229 - - 14 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 187 - - 99 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 189 - - 55 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 180 - - 85 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 10 - - 63 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 181 - - 60 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 182 - - 33 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 183 - - 62 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 184 - - 70 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 185 - - 79 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 186 - - 98 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 116 - - 5 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 79 - - 48 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 117 - - 93 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 78 - - 31 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 114 - - 78 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 77 - - 8 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 115 - - 64 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 112 - - 71 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 113 - - 85 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 110 - - 50 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 111 - - 42 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 118 - - 18 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 119 - - 38 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 82 - - 99 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 83 - - 29 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 80 - - 3 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 81 - - 52 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 86 - - 98 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 87 - - 4 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 84 - - 12 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 85 - - 50 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 67 - - 56 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 125 - - 86 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 66 - - 56 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 126 - - 2 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 69 - - 39 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 127 - - 31 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 68 - - 9 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 128 - - 54 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 121 - - 81 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 122 - - 4 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 123 - - 23 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 124 - - 11 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 129 - - 87 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 70 - - 15 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 71 - - 4 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 120 - - 29 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 72 - - 58 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 73 - - 73 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 74 - - 5 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 75 - - 12 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 76 - - 3 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 134 - - 50 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 135 - - 25 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 132 - - 72 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 59 - - 90 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 133 - - 10 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 58 - - 62 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 138 - - 51 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 57 - - 100 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 139 - - 29 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 56 - - 37 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 136 - - 71 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 55 - - 5 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 137 - - 85 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 64 - - 60 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 65 - - 95 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 62 - - 37 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 63 - - 80 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 60 - - 57 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 131 - - 81 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 61 - - 44 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 130 - - 17 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 49 - - 79 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 143 - - 38 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 48 - - 79 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 144 - - 11 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 145 - - 82 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 146 - - 50 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 45 - - 73 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 147 - - 39 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 44 - - 12 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 148 - - 6 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 47 - - 8 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 149 - - 87 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 46 - - 32 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 51 - - 14 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 52 - - 17 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 53 - - 19 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 54 - - 44 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 140 - - 55 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 142 - - 100 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 50 - - 4 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 141 - - 45 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 109 - - 68 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 108 - - 77 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 107 - - 42 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 106 - - 39 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 105 - - 25 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 104 - - 93 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 103 - - 74 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 99 - - 21 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 102 - - 84 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 101 - - 33 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 100 - - 99 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 98 - - 84 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 97 - - 71 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 96 - - 26 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 95 - - 72 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 94 - - 36 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 93 - - 4 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 92 - - 98 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 91 - - 45 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 90 - - 33 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 88 - - 56 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 89 - - 24 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 240 - - 53 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 241 - - 15 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 195 - - 19 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 194 - - 19 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 197 - - 35 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 196 - - 90 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 191 - - 94 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 190 - - 75 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 193 - - 13 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 192 - - 89 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 198 - - 76 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 199 - - 3 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 245 - - 92 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 244 - - 78 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 243 - - 98 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 242 - - 36 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 249 - - 50 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 248 - - 43 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 247 - - 64 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 246 - - 65 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 230 - - 42 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 239 - - 96 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 232 - - 55 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 231 - - 14 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 234 - - 18 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 233 - - 2 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 236 - - 22 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 235 - - 17 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 238 - - 3 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - - 237 - - 28 - 0.0 - - - 0.0 - 1.7976931348623157E308 - - - - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.w3schools.com vrp_xml_schema.xsd"> + + + + 35 + + 9 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 36 + + 74 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 33 + + 47 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 159 + + 46 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 34 + + 57 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 158 + + 79 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 39 + + 42 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 157 + + 79 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 156 + + 97 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 37 + + 83 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 155 + + 65 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 38 + + 96 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 154 + + 97 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 152 + + 24 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 153 + + 69 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 150 + + 83 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 151 + + 22 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 43 + + 43 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 42 + + 56 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 41 + + 22 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 40 + + 80 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 202 + + 92 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 203 + + 1 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 204 + + 2 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 205 + + 63 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 200 + + 11 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 201 + + 98 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 22 + + 40 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 23 + + 8 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 169 + + 49 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 24 + + 69 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 25 + + 93 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 206 + + 57 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 26 + + 29 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 166 + + 23 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 207 + + 50 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 27 + + 5 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 165 + + 3 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 208 + + 19 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 28 + + 53 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 168 + + 40 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 209 + + 24 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 29 + + 8 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 167 + + 19 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 3 + + 93 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 161 + + 39 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 2 + + 72 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 162 + + 94 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 1 + + 6 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 163 + + 97 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 164 + + 18 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 7 + + 1 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 30 + + 24 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 6 + + 43 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 5 + + 5 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 32 + + 13 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 4 + + 28 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 31 + + 53 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 160 + + 52 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 9 + + 53 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 8 + + 36 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 211 + + 18 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 212 + + 77 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 210 + + 14 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 215 + + 49 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 216 + + 58 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 213 + + 28 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 19 + + 88 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 214 + + 72 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 219 + + 41 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 17 + + 51 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 179 + + 59 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 18 + + 47 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 178 + + 84 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 217 + + 84 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 15 + + 66 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 177 + + 36 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 218 + + 58 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 16 + + 37 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 176 + + 10 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 13 + + 57 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 14 + + 1 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 11 + + 25 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 12 + + 50 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 21 + + 48 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 170 + + 96 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 20 + + 75 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 171 + + 58 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 174 + + 56 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 175 + + 67 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 172 + + 15 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 173 + + 21 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 220 + + 98 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 221 + + 77 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 222 + + 57 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 223 + + 39 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 224 + + 99 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 225 + + 83 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 226 + + 54 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 227 + + 86 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 228 + + 2 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 188 + + 18 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 229 + + 14 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 187 + + 99 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 189 + + 55 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 180 + + 85 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 10 + + 63 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 181 + + 60 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 182 + + 33 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 183 + + 62 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 184 + + 70 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 185 + + 79 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 186 + + 98 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 116 + + 5 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 79 + + 48 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 117 + + 93 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 78 + + 31 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 114 + + 78 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 77 + + 8 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 115 + + 64 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 112 + + 71 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 113 + + 85 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 110 + + 50 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 111 + + 42 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 118 + + 18 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 119 + + 38 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 82 + + 99 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 83 + + 29 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 80 + + 3 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 81 + + 52 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 86 + + 98 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 87 + + 4 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 84 + + 12 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 85 + + 50 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 67 + + 56 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 125 + + 86 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 66 + + 56 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 126 + + 2 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 69 + + 39 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 127 + + 31 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 68 + + 9 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 128 + + 54 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 121 + + 81 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 122 + + 4 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 123 + + 23 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 124 + + 11 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 129 + + 87 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 70 + + 15 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 71 + + 4 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 120 + + 29 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 72 + + 58 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 73 + + 73 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 74 + + 5 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 75 + + 12 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 76 + + 3 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 134 + + 50 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 135 + + 25 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 132 + + 72 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 59 + + 90 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 133 + + 10 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 58 + + 62 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 138 + + 51 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 57 + + 100 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 139 + + 29 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 56 + + 37 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 136 + + 71 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 55 + + 5 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 137 + + 85 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 64 + + 60 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 65 + + 95 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 62 + + 37 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 63 + + 80 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 60 + + 57 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 131 + + 81 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 61 + + 44 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 130 + + 17 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 49 + + 79 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 143 + + 38 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 48 + + 79 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 144 + + 11 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 145 + + 82 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 146 + + 50 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 45 + + 73 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 147 + + 39 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 44 + + 12 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 148 + + 6 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 47 + + 8 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 149 + + 87 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 46 + + 32 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 51 + + 14 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 52 + + 17 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 53 + + 19 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 54 + + 44 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 140 + + 55 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 142 + + 100 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 50 + + 4 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 141 + + 45 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 109 + + 68 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 108 + + 77 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 107 + + 42 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 106 + + 39 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 105 + + 25 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 104 + + 93 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 103 + + 74 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 99 + + 21 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 102 + + 84 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 101 + + 33 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 100 + + 99 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 98 + + 84 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 97 + + 71 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 96 + + 26 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 95 + + 72 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 94 + + 36 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 93 + + 4 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 92 + + 98 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 91 + + 45 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 90 + + 33 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 88 + + 56 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 89 + + 24 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 240 + + 53 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 241 + + 15 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 195 + + 19 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 194 + + 19 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 197 + + 35 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 196 + + 90 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 191 + + 94 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 190 + + 75 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 193 + + 13 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 192 + + 89 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 198 + + 76 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 199 + + 3 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 245 + + 92 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 244 + + 78 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 243 + + 98 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 242 + + 36 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 249 + + 50 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 248 + + 43 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 247 + + 64 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 246 + + 65 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 230 + + 42 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 239 + + 96 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 232 + + 55 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 231 + + 14 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 234 + + 18 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 233 + + 2 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 236 + + 22 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 235 + + 17 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 238 + + 3 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + 237 + + 28 + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + diff --git a/jsprit-examples/input/vrpnc1-jsprit.xml b/jsprit-examples/input/vrpnc1-jsprit.xml index 5d3ff044..19c20222 100644 --- a/jsprit-examples/input/vrpnc1-jsprit.xml +++ b/jsprit-examples/input/vrpnc1-jsprit.xml @@ -1,635 +1,636 @@ - - INFINITE - HOMOGENEOUS - - - - christophidesVehicle - christophidesType - - [x=30.0][y=40.0] - - - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://www.w3schools.com vrp_xml_schema.xsd"> + + 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 - 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 - - - - + 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/pom.xml b/jsprit-examples/pom.xml index db679921..bd76979f 100644 --- a/jsprit-examples/pom.xml +++ b/jsprit-examples/pom.xml @@ -1,62 +1,62 @@ + + + jsprit + jsprit + 1.6.2-SNAPSHOT + + 4.0.0 - - - jsprit - jsprit - 1.6.1-SNAPSHOT - - 4.0.0 - - jsprit-examples - - - - - - org.eclipse.m2e - lifecycle-mapping - 1.0.0 - - - - - - org.apache.maven.plugins - maven-enforcer-plugin - [1.0.0,) - - enforce - - - - - - - - - - - - - - - - - ${project.groupId} - jsprit-instances - ${project.version} - - - - ${project.groupId} - jsprit-core - ${project.version} - - - ${project.groupId} - jsprit-analysis - ${project.version} - - + jsprit-examples + + + + + + org.eclipse.m2e + lifecycle-mapping + 1.0.0 + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + [1.0.0,) + + enforce + + + + + + + + + + + + + + + + + ${project.groupId} + jsprit-instances + ${project.version} + + + + ${project.groupId} + jsprit-core + ${project.version} + + + ${project.groupId} + jsprit-analysis + ${project.version} + + diff --git a/jsprit-examples/src/main/java/jsprit/examples/AdditionalDistanceConstraintExample.java b/jsprit-examples/src/main/java/jsprit/examples/AdditionalDistanceConstraintExample.java index 4b01fe30..42cca63f 100644 --- a/jsprit-examples/src/main/java/jsprit/examples/AdditionalDistanceConstraintExample.java +++ b/jsprit-examples/src/main/java/jsprit/examples/AdditionalDistanceConstraintExample.java @@ -1,4 +1,3 @@ - /******************************************************************************* * Copyright (C) 2014 Stefan Schroeder * @@ -52,7 +51,7 @@ public class AdditionalDistanceConstraintExample { private final VehicleRoutingTransportCostsMatrix costMatrix; -// private final StateFactory.StateId distanceStateId; //v1.3.1 + // private final StateFactory.StateId distanceStateId; //v1.3.1 private final StateId distanceStateId; //head of development - upcoming release private VehicleRoute vehicleRoute; @@ -61,8 +60,8 @@ public class AdditionalDistanceConstraintExample { private TourActivity prevAct; -// public DistanceUpdater(StateFactory.StateId distanceStateId, StateManager stateManager, VehicleRoutingTransportCostsMatrix costMatrix) { //v1.3.1 - public DistanceUpdater(StateId distanceStateId, StateManager stateManager, VehicleRoutingTransportCostsMatrix transportCosts) { //head of development - upcoming release (v1.4) + // public DistanceUpdater(StateFactory.StateId distanceStateId, StateManager stateManager, VehicleRoutingTransportCostsMatrix costMatrix) { //v1.3.1 + public DistanceUpdater(StateId distanceStateId, StateManager stateManager, VehicleRoutingTransportCostsMatrix transportCosts) { //head of development - upcoming release (v1.4) this.costMatrix = transportCosts; this.stateManager = stateManager; this.distanceStateId = distanceStateId; @@ -77,18 +76,18 @@ public class AdditionalDistanceConstraintExample { @Override public void visit(TourActivity tourActivity) { - distance += getDistance(prevAct,tourActivity); + distance += getDistance(prevAct, tourActivity); prevAct = tourActivity; } @Override public void finish() { - distance += getDistance(prevAct,vehicleRoute.getEnd()); + distance += getDistance(prevAct, vehicleRoute.getEnd()); // stateManager.putTypedRouteState(vehicleRoute,distanceStateId,Double.class,distance); //v1.3.1 stateManager.putRouteState(vehicleRoute, distanceStateId, distance); //head of development - upcoming release (v1.4) } - double getDistance(TourActivity from, TourActivity to){ + double getDistance(TourActivity from, TourActivity to) { return costMatrix.getDistance(from.getLocation().getId(), to.getLocation().getId()); } } @@ -101,10 +100,10 @@ public class AdditionalDistanceConstraintExample { private final double maxDistance; -// private final StateFactory.StateId distanceStateId; //v1.3.1 + // private final StateFactory.StateId distanceStateId; //v1.3.1 private final StateId distanceStateId; //head of development - upcoming release (v1.4) -// DistanceConstraint(double maxDistance, StateFactory.StateId distanceStateId, StateManager stateManager, VehicleRoutingTransportCostsMatrix costsMatrix) { //v1.3.1 + // DistanceConstraint(double maxDistance, StateFactory.StateId distanceStateId, StateManager stateManager, VehicleRoutingTransportCostsMatrix costsMatrix) { //v1.3.1 DistanceConstraint(double maxDistance, StateId distanceStateId, StateManager stateManager, VehicleRoutingTransportCostsMatrix transportCosts) { //head of development - upcoming release (v1.4) this.costsMatrix = transportCosts; this.maxDistance = maxDistance; @@ -114,21 +113,21 @@ public class AdditionalDistanceConstraintExample { @Override public ConstraintsStatus fulfilled(JobInsertionContext context, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double v) { - double additionalDistance = getDistance(prevAct,newAct) + getDistance(newAct,nextAct) - getDistance(prevAct,nextAct); + double additionalDistance = getDistance(prevAct, newAct) + getDistance(newAct, nextAct) - getDistance(prevAct, nextAct); Double routeDistance = stateManager.getRouteState(context.getRoute(), distanceStateId, Double.class); - if(routeDistance == null) routeDistance = 0.; + if (routeDistance == null) routeDistance = 0.; double newRouteDistance = routeDistance + additionalDistance; - if(newRouteDistance > maxDistance) { + if (newRouteDistance > maxDistance) { return ConstraintsStatus.NOT_FULFILLED; - } - else return ConstraintsStatus.FULFILLED; + } else return ConstraintsStatus.FULFILLED; } - double getDistance(TourActivity from, TourActivity to){ + double getDistance(TourActivity from, TourActivity to) { return costsMatrix.getDistance(from.getLocation().getId(), to.getLocation().getId()); } } + public static void main(String[] args) { //route length 618 @@ -139,7 +138,7 @@ public class AdditionalDistanceConstraintExample { vrpBuilder.setRoutingCost(costMatrix); VehicleRoutingProblem vrp = vrpBuilder.build(); - VehicleRoutingAlgorithmBuilder vraBuilder = new VehicleRoutingAlgorithmBuilder(vrp,"input/algorithmConfig_solomon.xml"); + VehicleRoutingAlgorithmBuilder vraBuilder = new VehicleRoutingAlgorithmBuilder(vrp, "input/algorithmConfig_solomon.xml"); // StateManager stateManager = new StateManager(vrp.getTransportCosts()); //v1.3.1 StateManager stateManager = new StateManager(vrp); //head of development - upcoming release (v1.4) @@ -149,13 +148,13 @@ public class AdditionalDistanceConstraintExample { stateManager.addStateUpdater(new DistanceUpdater(distanceStateId, stateManager, costMatrix)); // stateManager.updateLoadStates(); - ConstraintManager constraintManager = new ConstraintManager(vrp,stateManager); - constraintManager.addConstraint(new DistanceConstraint(120.,distanceStateId,stateManager,costMatrix), ConstraintManager.Priority.CRITICAL); + ConstraintManager constraintManager = new ConstraintManager(vrp, stateManager); + constraintManager.addConstraint(new DistanceConstraint(120., distanceStateId, stateManager, costMatrix), ConstraintManager.Priority.CRITICAL); // constraintManager.addLoadConstraint(); // vraBuilder.addCoreConstraints(); vraBuilder.addDefaultCostCalculators(); - vraBuilder.setStateAndConstraintManager(stateManager,constraintManager); + vraBuilder.setStateAndConstraintManager(stateManager, constraintManager); VehicleRoutingAlgorithm vra = vraBuilder.build(); // vra.setMaxIterations(250); //v1.3.1 @@ -165,18 +164,18 @@ public class AdditionalDistanceConstraintExample { SolutionPrinter.print(vrp, Solutions.bestOf(solutions), SolutionPrinter.Print.VERBOSE); - new Plotter(vrp, Solutions.bestOf(solutions)).plot("output/plot","plot"); + new Plotter(vrp, Solutions.bestOf(solutions)).plot("output/plot", "plot"); } private static VehicleRoutingTransportCostsMatrix createMatrix(VehicleRoutingProblem.Builder vrpBuilder) { VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(true); - for(String from : vrpBuilder.getLocationMap().keySet()){ - for(String to : vrpBuilder.getLocationMap().keySet()){ + for (String from : vrpBuilder.getLocationMap().keySet()) { + for (String to : vrpBuilder.getLocationMap().keySet()) { Coordinate fromCoord = vrpBuilder.getLocationMap().get(from); Coordinate toCoord = vrpBuilder.getLocationMap().get(to); double distance = EuclideanDistanceCalculator.calculateDistance(fromCoord, toCoord); - matrixBuilder.addTransportDistance(from,to,distance); - matrixBuilder.addTransportTime(from,to,(distance / 2.)); + matrixBuilder.addTransportDistance(from, to, distance); + matrixBuilder.addTransportTime(from, to, (distance / 2.)); } } return matrixBuilder.build(); diff --git a/jsprit-examples/src/main/java/jsprit/examples/BicycleMessenger.java b/jsprit-examples/src/main/java/jsprit/examples/BicycleMessenger.java index 08704696..92bd6b0c 100644 --- a/jsprit-examples/src/main/java/jsprit/examples/BicycleMessenger.java +++ b/jsprit-examples/src/main/java/jsprit/examples/BicycleMessenger.java @@ -64,186 +64,184 @@ import java.util.Map; /** * This class provides the/a solution to the following problem: - * + *

* Statement of the problem (see Stackoverflow: http://stackoverflow.com/questions/19080537/bicycle-messenger-tsppd-with-optaplanner/20412598#20412598): - * - * Optimize the routes for a bicycle messenger service! + *

+ * Optimize the routes for a bicycle messenger service! * Assume 5 messengers that have to pick up 30 envelopes distributed through the city. These 5 messengers are distributed through the city as well. Thus * there is no single depot and they do not need to go back to their original starting location. - * + *

* Additional hard constraints: * 1) Every messenger can carry up to fifteen envelopes * 2) The way an evelopes travels should be less than three times the direct route (so delivery does not take too long) - * + *

* Thus this problem is basically a Capacitated VRP with Pickups and Deliveries, Multiple Depots, Open Routes and Time Windows/Restrictions. - * - * @author stefan schroeder * + * @author stefan schroeder */ public class BicycleMessenger { - /** - * Hard constraint: delivery of envelope must not take longer than 3*bestDirect (i.e. fastest messenger on direct delivery) - * - * @author stefan - * - */ - static class ThreeTimesLessThanBestDirectRouteConstraint implements HardActivityConstraint { + /** + * Hard constraint: delivery of envelope must not take longer than 3*bestDirect (i.e. fastest messenger on direct delivery) + * + * @author stefan + */ + static class ThreeTimesLessThanBestDirectRouteConstraint implements HardActivityConstraint { - private final VehicleRoutingTransportCosts routingCosts; - - private final RouteAndActivityStateGetter stateManager; - - //jobId map direct-distance by nearestMessenger - private final Map bestMessengers; + private final VehicleRoutingTransportCosts routingCosts; + + private final RouteAndActivityStateGetter stateManager; + + //jobId map direct-distance by nearestMessenger + private final Map bestMessengers; private final StateId latest_act_arrival_time_stateId; - - public ThreeTimesLessThanBestDirectRouteConstraint(StateId latest_act_arrival_time, Map nearestMessengers, VehicleRoutingTransportCosts routingCosts, RouteAndActivityStateGetter stateManager) { - this.bestMessengers = nearestMessengers; - this.routingCosts = routingCosts; - this.stateManager = stateManager; + + public ThreeTimesLessThanBestDirectRouteConstraint(StateId latest_act_arrival_time, Map nearestMessengers, VehicleRoutingTransportCosts routingCosts, RouteAndActivityStateGetter stateManager) { + this.bestMessengers = nearestMessengers; + this.routingCosts = routingCosts; + this.stateManager = stateManager; this.latest_act_arrival_time_stateId = latest_act_arrival_time; - } + } - @Override - public ConstraintsStatus fulfilled(JobInsertionContext iFacts,TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double prevActDepTime) { - //make sure vehicle can manage direct path - double arrTime_at_nextAct_onDirectRoute = prevActDepTime + routingCosts.getTransportTime(prevAct.getLocation(), nextAct.getLocation(), prevActDepTime, iFacts.getNewDriver(), iFacts.getNewVehicle()); + @Override + public ConstraintsStatus fulfilled(JobInsertionContext iFacts, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double prevActDepTime) { + //make sure vehicle can manage direct path + double arrTime_at_nextAct_onDirectRoute = prevActDepTime + routingCosts.getTransportTime(prevAct.getLocation(), nextAct.getLocation(), prevActDepTime, iFacts.getNewDriver(), iFacts.getNewVehicle()); Double latest_arrTime_at_nextAct = stateManager.getActivityState(nextAct, latest_act_arrival_time_stateId, Double.class); - if(latest_arrTime_at_nextAct == null) latest_arrTime_at_nextAct = nextAct.getTheoreticalLatestOperationStartTime(); - if(arrTime_at_nextAct_onDirectRoute > latest_arrTime_at_nextAct){ + if (latest_arrTime_at_nextAct == null) + latest_arrTime_at_nextAct = nextAct.getTheoreticalLatestOperationStartTime(); + if (arrTime_at_nextAct_onDirectRoute > latest_arrTime_at_nextAct) { //constraint can never be fulfilled anymore, thus .NOT_FULFILLED_BREAK - return ConstraintsStatus.NOT_FULFILLED_BREAK; - } - - double arrTime_at_newAct = prevActDepTime + routingCosts.getTransportTime(prevAct.getLocation(), newAct.getLocation(), prevActDepTime, iFacts.getNewDriver(), iFacts.getNewVehicle()); - //local impact - //no matter whether it is a pickupShipment or deliverShipment activities. both arrivalTimes must be < 3*best. - double directTimeOfNearestMessenger = bestMessengers.get(((JobActivity) newAct).getJob().getId()); - if(arrTime_at_newAct > 3 * directTimeOfNearestMessenger){ - //not fulfilled AND it can never be fulfilled anymore by going forward in route, thus NOT_FULFILLED_BREAK - return ConstraintsStatus.NOT_FULFILLED_BREAK; - } + return ConstraintsStatus.NOT_FULFILLED_BREAK; + } - //impact on whole route, since insertion of newAct shifts all subsequent activities forward in time - double departureTime_at_newAct = arrTime_at_newAct + newAct.getOperationTime(); - double latest_arrTime_at_newAct = latest_arrTime_at_nextAct - routingCosts.getTransportTime(newAct.getLocation(),nextAct.getLocation(),departureTime_at_newAct,iFacts.getNewDriver(),iFacts.getNewVehicle()); - if(arrTime_at_newAct > latest_arrTime_at_newAct){ + double arrTime_at_newAct = prevActDepTime + routingCosts.getTransportTime(prevAct.getLocation(), newAct.getLocation(), prevActDepTime, iFacts.getNewDriver(), iFacts.getNewVehicle()); + //local impact + //no matter whether it is a pickupShipment or deliverShipment activities. both arrivalTimes must be < 3*best. + double directTimeOfNearestMessenger = bestMessengers.get(((JobActivity) newAct).getJob().getId()); + if (arrTime_at_newAct > 3 * directTimeOfNearestMessenger) { + //not fulfilled AND it can never be fulfilled anymore by going forward in route, thus NOT_FULFILLED_BREAK + return ConstraintsStatus.NOT_FULFILLED_BREAK; + } + + //impact on whole route, since insertion of newAct shifts all subsequent activities forward in time + double departureTime_at_newAct = arrTime_at_newAct + newAct.getOperationTime(); + double latest_arrTime_at_newAct = latest_arrTime_at_nextAct - routingCosts.getTransportTime(newAct.getLocation(), nextAct.getLocation(), departureTime_at_newAct, iFacts.getNewDriver(), iFacts.getNewVehicle()); + if (arrTime_at_newAct > latest_arrTime_at_newAct) { return ConstraintsStatus.NOT_FULFILLED; } double arrTime_at_nextAct = departureTime_at_newAct + routingCosts.getTransportTime(newAct.getLocation(), nextAct.getLocation(), departureTime_at_newAct, iFacts.getNewDriver(), iFacts.getNewVehicle()); - //here you need an activity state - if(arrTime_at_nextAct > latest_arrTime_at_nextAct){ - return ConstraintsStatus.NOT_FULFILLED; - } - return ConstraintsStatus.FULFILLED; - } - - } - - /** - * When inserting the activities of an envelope which are pickup and deliver envelope, this constraint makes insertion procedure to ignore messengers that are too far away to meet the 3*directTime-Constraint. - * - *

one does not need this constraint. but it is faster. the earlier the solution-space can be constraint the better/faster. - * @author schroeder - * - */ - static class IgnoreMessengerThatCanNeverMeetTimeRequirements implements HardRouteConstraint { + //here you need an activity state + if (arrTime_at_nextAct > latest_arrTime_at_nextAct) { + return ConstraintsStatus.NOT_FULFILLED; + } + return ConstraintsStatus.FULFILLED; + } - private final Map bestMessengers; - - private final VehicleRoutingTransportCosts routingCosts; - - public IgnoreMessengerThatCanNeverMeetTimeRequirements(Map bestMessengers, VehicleRoutingTransportCosts routingCosts) { - super(); - this.bestMessengers = bestMessengers; - this.routingCosts = routingCosts; - } + } - @Override - public boolean fulfilled(JobInsertionContext insertionContext) { - double timeOfDirectRoute = getTimeOfDirectRoute(insertionContext.getJob(), insertionContext.getNewVehicle(), routingCosts); - double timeOfNearestMessenger = bestMessengers.get(insertionContext.getJob().getId()); - return !(timeOfDirectRoute > 3 * timeOfNearestMessenger); - } - - } - - /** - * updates the state "latest-activity-start-time" (required above) once route/activity states changed, i.e. when removing or inserting an envelope-activity - * - *

thus once either the insertion-procedure starts or an envelope has been inserted, this visitor runs through the route in reverse order (i.e. starting with the end of the route) and - * calculates the latest-activity-start-time (or latest-activity-arrival-time) which is the time to just meet the constraints of subsequent activities. - * - * @author schroeder - * - */ - static class UpdateLatestActivityStartTimes implements StateUpdater, ReverseActivityVisitor { + /** + * When inserting the activities of an envelope which are pickup and deliver envelope, this constraint makes insertion procedure to ignore messengers that are too far away to meet the 3*directTime-Constraint. + *

+ *

one does not need this constraint. but it is faster. the earlier the solution-space can be constraint the better/faster. + * + * @author schroeder + */ + static class IgnoreMessengerThatCanNeverMeetTimeRequirements implements HardRouteConstraint { - private final StateManager stateManager; - - private final VehicleRoutingTransportCosts routingCosts; - - private final Map bestMessengers; - - private VehicleRoute route; - - private TourActivity prevAct; - - private double latest_arrTime_at_prevAct; + private final Map bestMessengers; + + private final VehicleRoutingTransportCosts routingCosts; + + public IgnoreMessengerThatCanNeverMeetTimeRequirements(Map bestMessengers, VehicleRoutingTransportCosts routingCosts) { + super(); + this.bestMessengers = bestMessengers; + this.routingCosts = routingCosts; + } + + @Override + public boolean fulfilled(JobInsertionContext insertionContext) { + double timeOfDirectRoute = getTimeOfDirectRoute(insertionContext.getJob(), insertionContext.getNewVehicle(), routingCosts); + double timeOfNearestMessenger = bestMessengers.get(insertionContext.getJob().getId()); + return !(timeOfDirectRoute > 3 * timeOfNearestMessenger); + } + + } + + /** + * updates the state "latest-activity-start-time" (required above) once route/activity states changed, i.e. when removing or inserting an envelope-activity + *

+ *

thus once either the insertion-procedure starts or an envelope has been inserted, this visitor runs through the route in reverse order (i.e. starting with the end of the route) and + * calculates the latest-activity-start-time (or latest-activity-arrival-time) which is the time to just meet the constraints of subsequent activities. + * + * @author schroeder + */ + static class UpdateLatestActivityStartTimes implements StateUpdater, ReverseActivityVisitor { + + private final StateManager stateManager; + + private final VehicleRoutingTransportCosts routingCosts; + + private final Map bestMessengers; + + private VehicleRoute route; + + private TourActivity prevAct; + + private double latest_arrTime_at_prevAct; private final StateId latest_act_arrival_time_stateId; - - public UpdateLatestActivityStartTimes(StateId latest_act_arrival_time, StateManager stateManager, VehicleRoutingTransportCosts routingCosts, Map bestMessengers) { - super(); - this.stateManager = stateManager; - this.routingCosts = routingCosts; - this.bestMessengers = bestMessengers; + + public UpdateLatestActivityStartTimes(StateId latest_act_arrival_time, StateManager stateManager, VehicleRoutingTransportCosts routingCosts, Map bestMessengers) { + super(); + this.stateManager = stateManager; + this.routingCosts = routingCosts; + this.bestMessengers = bestMessengers; this.latest_act_arrival_time_stateId = latest_act_arrival_time; - } + } - @Override - public void begin(VehicleRoute route) { - this.route = route; - latest_arrTime_at_prevAct = route.getEnd().getTheoreticalLatestOperationStartTime(); - prevAct = route.getEnd(); - } + @Override + public void begin(VehicleRoute route) { + this.route = route; + latest_arrTime_at_prevAct = route.getEnd().getTheoreticalLatestOperationStartTime(); + prevAct = route.getEnd(); + } - @Override - public void visit(TourActivity currAct) { - double timeOfNearestMessenger = bestMessengers.get(((JobActivity)currAct).getJob().getId()); - double potential_latest_arrTime_at_currAct = - latest_arrTime_at_prevAct - routingCosts.getBackwardTransportTime(currAct.getLocation(), prevAct.getLocation(), latest_arrTime_at_prevAct, route.getDriver(),route.getVehicle()) - currAct.getOperationTime(); - double latest_arrTime_at_currAct = Math.min(3*timeOfNearestMessenger, potential_latest_arrTime_at_currAct); - stateManager.putActivityState(currAct, latest_act_arrival_time_stateId, latest_arrTime_at_currAct); - assert currAct.getArrTime() <= latest_arrTime_at_currAct : "this must not be since it breaks condition; actArrTime: " + currAct.getArrTime() + " latestArrTime: " + latest_arrTime_at_currAct + " vehicle: " + route.getVehicle().getId(); - latest_arrTime_at_prevAct = latest_arrTime_at_currAct; - prevAct = currAct; - } + @Override + public void visit(TourActivity currAct) { + double timeOfNearestMessenger = bestMessengers.get(((JobActivity) currAct).getJob().getId()); + double potential_latest_arrTime_at_currAct = + latest_arrTime_at_prevAct - routingCosts.getBackwardTransportTime(currAct.getLocation(), prevAct.getLocation(), latest_arrTime_at_prevAct, route.getDriver(), route.getVehicle()) - currAct.getOperationTime(); + double latest_arrTime_at_currAct = Math.min(3 * timeOfNearestMessenger, potential_latest_arrTime_at_currAct); + stateManager.putActivityState(currAct, latest_act_arrival_time_stateId, latest_arrTime_at_currAct); + assert currAct.getArrTime() <= latest_arrTime_at_currAct : "this must not be since it breaks condition; actArrTime: " + currAct.getArrTime() + " latestArrTime: " + latest_arrTime_at_currAct + " vehicle: " + route.getVehicle().getId(); + latest_arrTime_at_prevAct = latest_arrTime_at_currAct; + prevAct = currAct; + } + + @Override + public void finish() { + } + + } + + /** + * @throws IOException + */ + public static void main(String[] args) throws IOException { + Examples.createOutputFolder(); - @Override - public void finish() {} - - } - - /** - * - * @throws IOException - */ - public static void main(String[] args) throws IOException { - Examples.createOutputFolder(); - /* - build the problem + build the problem */ - VehicleRoutingProblem.Builder problemBuilder = VehicleRoutingProblem.Builder.newInstance(); - problemBuilder.setFleetSize(FleetSize.FINITE); - readEnvelopes(problemBuilder); - readMessengers(problemBuilder); - //add constraints to problem - VehicleRoutingTransportCosts routingCosts = new CrowFlyCosts(problemBuilder.getLocations()); //which is the default VehicleRoutingTransportCosts in builder above + VehicleRoutingProblem.Builder problemBuilder = VehicleRoutingProblem.Builder.newInstance(); + problemBuilder.setFleetSize(FleetSize.FINITE); + readEnvelopes(problemBuilder); + readMessengers(problemBuilder); + //add constraints to problem + VehicleRoutingTransportCosts routingCosts = new CrowFlyCosts(problemBuilder.getLocations()); //which is the default VehicleRoutingTransportCosts in builder above problemBuilder.setRoutingCost(routingCosts); //finally build the problem // problemBuilder.addPenaltyVehicles(20.0,50000); @@ -253,7 +251,7 @@ public class BicycleMessenger { define states and constraints */ //map mapping nearest messengers, i.e. for each envelope the direct-delivery-time with the fastest messenger is stored here - Map nearestMessengers = getNearestMessengers(routingCosts, problemBuilder.getAddedJobs(), problemBuilder.getAddedVehicles()); + Map nearestMessengers = getNearestMessengers(routingCosts, problemBuilder.getAddedJobs(), problemBuilder.getAddedVehicles()); //define stateManager to update the required activity-state: "latest-activity-start-time" StateManager stateManager = new StateManager(bicycleMessengerProblem); @@ -263,13 +261,13 @@ public class BicycleMessenger { stateManager.addStateUpdater(new UpdateLatestActivityStartTimes(latest_act_arrival_time_stateId, stateManager, routingCosts, nearestMessengers)); stateManager.updateLoadStates(); - ConstraintManager constraintManager = new ConstraintManager(bicycleMessengerProblem,stateManager); + ConstraintManager constraintManager = new ConstraintManager(bicycleMessengerProblem, stateManager); constraintManager.addLoadConstraint(); - constraintManager.addConstraint(new ThreeTimesLessThanBestDirectRouteConstraint(latest_act_arrival_time_stateId,nearestMessengers,routingCosts,stateManager), ConstraintManager.Priority.CRITICAL); + constraintManager.addConstraint(new ThreeTimesLessThanBestDirectRouteConstraint(latest_act_arrival_time_stateId, nearestMessengers, routingCosts, stateManager), ConstraintManager.Priority.CRITICAL); constraintManager.addConstraint(new IgnoreMessengerThatCanNeverMeetTimeRequirements(nearestMessengers, routingCosts)); //create your algorithm - VehicleRoutingAlgorithmBuilder vraBuilder = new VehicleRoutingAlgorithmBuilder(bicycleMessengerProblem,"input/algorithmConfig.xml"); + VehicleRoutingAlgorithmBuilder vraBuilder = new VehicleRoutingAlgorithmBuilder(bicycleMessengerProblem, "input/algorithmConfig.xml"); // vraBuilder.setNuOfThreads(2); vraBuilder.addDefaultCostCalculators(); vraBuilder.setStateAndConstraintManager(stateManager, constraintManager); @@ -294,110 +292,115 @@ public class BicycleMessenger { // VariationCoefficientTermination prematureAlgorithmTermination = new VariationCoefficientTermination(200, 0.001); // algorithm.setPrematureAlgorithmTermination(prematureAlgorithmTermination); // algorithm.addListener(prematureAlgorithmTermination); - algorithm.addListener(new AlgorithmSearchProgressChartListener("output/progress.png")); + algorithm.addListener(new AlgorithmSearchProgressChartListener("output/progress.png")); //search - Collection solutions = algorithm.searchSolutions(); - - //this is just to ensure that solution meet the above constraints - validateSolution(Solutions.bestOf(solutions), bicycleMessengerProblem, nearestMessengers); + Collection solutions = algorithm.searchSolutions(); + + //this is just to ensure that solution meet the above constraints + validateSolution(Solutions.bestOf(solutions), bicycleMessengerProblem, nearestMessengers); SolutionPrinter.print(bicycleMessengerProblem, Solutions.bestOf(solutions), SolutionPrinter.Print.VERBOSE); - //you may want to plot the problem - Plotter plotter = new Plotter(bicycleMessengerProblem); + //you may want to plot the problem + Plotter plotter = new Plotter(bicycleMessengerProblem); // plotter.setBoundingBox(10000, 47500, 20000, 67500); - plotter.plotShipments(true); - plotter.plot("output/bicycleMessengerProblem.png", "bicycleMessenger"); - - //and the problem as well as the solution - Plotter plotter1 = new Plotter(bicycleMessengerProblem, Solutions.bestOf(solutions)); - plotter1.setLabel(Plotter.Label.ID); + plotter.plotShipments(true); + plotter.plot("output/bicycleMessengerProblem.png", "bicycleMessenger"); + + //and the problem as well as the solution + Plotter plotter1 = new Plotter(bicycleMessengerProblem, Solutions.bestOf(solutions)); + plotter1.setLabel(Plotter.Label.ID); plotter1.plotShipments(false); // plotter1.setBoundingBox(5000, 45500, 25000, 66500); - plotter1.plot("output/bicycleMessengerSolution.png", "bicycleMessenger"); - - //and write out your solution in xml + plotter1.plot("output/bicycleMessengerSolution.png", "bicycleMessenger"); + + //and write out your solution in xml // new VrpXMLWriter(bicycleMessengerProblem, solutions).write("output/bicycleMessenger.xml"); - - - new GraphStreamViewer(bicycleMessengerProblem).labelWith(Label.ID).setRenderShipments(true).setRenderDelay(150).display(); -// - new GraphStreamViewer(bicycleMessengerProblem, Solutions.bestOf(solutions)).setGraphStreamFrameScalingFactor(1.5).setCameraView(12500, 55000, 0.25).labelWith(Label.ACTIVITY).setRenderShipments(true).setRenderDelay(150).display(); - } + new GraphStreamViewer(bicycleMessengerProblem).labelWith(Label.ID).setRenderShipments(true).setRenderDelay(150).display(); +// + new GraphStreamViewer(bicycleMessengerProblem, Solutions.bestOf(solutions)).setGraphStreamFrameScalingFactor(1.5).setCameraView(12500, 55000, 0.25).labelWith(Label.ACTIVITY).setRenderShipments(true).setRenderDelay(150).display(); - //if you wanne run this enable assertion by putting an '-ea' in your vmargument list - Run As --> Run Configurations --> (x)=Arguments --> VM arguments: -ea - private static void validateSolution(VehicleRoutingProblemSolution bestOf, VehicleRoutingProblem bicycleMessengerProblem, Map nearestMessengers) { - for(VehicleRoute route : bestOf.getRoutes()){ - for(TourActivity act : route.getActivities()){ - if(act.getArrTime() > 3*nearestMessengers.get(((JobActivity)act).getJob().getId())){ - SolutionPrinter.print(bicycleMessengerProblem, bestOf, SolutionPrinter.Print.VERBOSE); - throw new IllegalStateException("three times less than ... constraint broken. this must not be. act.getArrTime(): " + act.getArrTime() + " allowed: " + 3*nearestMessengers.get(((JobActivity)act).getJob().getId())); - } - } - } - } + } - static Map getNearestMessengers(VehicleRoutingTransportCosts routingCosts, Collection envelopes, Collection messengers) { - Map nearestMessengers = new HashMap(); - for(Job envelope : envelopes){ - double minDirect = Double.MAX_VALUE; - for(Vehicle m : messengers){ - double direct = getTimeOfDirectRoute(envelope, m, routingCosts); - if(direct < minDirect){ - minDirect = direct; - } - } - nearestMessengers.put(envelope.getId(), minDirect); - } - return nearestMessengers; - } - - static double getTimeOfDirectRoute(Job job, Vehicle v, VehicleRoutingTransportCosts routingCosts) { - Shipment envelope = (Shipment) job; - return routingCosts.getTransportTime(v.getStartLocation(), envelope.getPickupLocation(), 0.0, DriverImpl.noDriver(), v) + - routingCosts.getTransportTime(envelope.getPickupLocation(), envelope.getDeliveryLocation(), 0.0, DriverImpl.noDriver(), v); - } + //if you wanne run this enable assertion by putting an '-ea' in your vmargument list - Run As --> Run Configurations --> (x)=Arguments --> VM arguments: -ea + private static void validateSolution(VehicleRoutingProblemSolution bestOf, VehicleRoutingProblem bicycleMessengerProblem, Map nearestMessengers) { + for (VehicleRoute route : bestOf.getRoutes()) { + for (TourActivity act : route.getActivities()) { + if (act.getArrTime() > 3 * nearestMessengers.get(((JobActivity) act).getJob().getId())) { + SolutionPrinter.print(bicycleMessengerProblem, bestOf, SolutionPrinter.Print.VERBOSE); + throw new IllegalStateException("three times less than ... constraint broken. this must not be. act.getArrTime(): " + act.getArrTime() + " allowed: " + 3 * nearestMessengers.get(((JobActivity) act).getJob().getId())); + } + } + } + } - private static void readEnvelopes(Builder problemBuilder) throws IOException { - BufferedReader reader = new BufferedReader(new FileReader(new File("input/bicycle_messenger_demand.txt"))); - String line; - boolean firstLine = true; - while((line = reader.readLine()) != null){ - if(firstLine) { firstLine = false; continue; } - String[] tokens = line.split("\\s+"); - //define your envelope which is basically a shipment from A to B - Shipment envelope = Shipment.Builder.newInstance(tokens[1]).addSizeDimension(0, 1) - .setPickupLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(Double.parseDouble(tokens[2]), Double.parseDouble(tokens[3]))).build()) - .setDeliveryLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(Double.parseDouble(tokens[4]), Double.parseDouble(tokens[5]))).build()).build(); - problemBuilder.addJob(envelope); - } - reader.close(); - } + static Map getNearestMessengers(VehicleRoutingTransportCosts routingCosts, Collection envelopes, Collection messengers) { + Map nearestMessengers = new HashMap(); + for (Job envelope : envelopes) { + double minDirect = Double.MAX_VALUE; + for (Vehicle m : messengers) { + double direct = getTimeOfDirectRoute(envelope, m, routingCosts); + if (direct < minDirect) { + minDirect = direct; + } + } + nearestMessengers.put(envelope.getId(), minDirect); + } + return nearestMessengers; + } - private static void readMessengers(Builder problemBuilder) throws IOException { - BufferedReader reader = new BufferedReader(new FileReader(new File("input/bicycle_messenger_supply.txt"))); - String line; - boolean firstLine = true; - VehicleType messengerType = VehicleTypeImpl.Builder.newInstance("messengerType").addCapacityDimension(0, 15).setCostPerDistance(1).build(); - /* - * the algo requires some time and space to search for a valid solution. if you ommit a penalty-type, it probably throws an Exception once it cannot insert an envelope anymore + static double getTimeOfDirectRoute(Job job, Vehicle v, VehicleRoutingTransportCosts routingCosts) { + Shipment envelope = (Shipment) job; + return routingCosts.getTransportTime(v.getStartLocation(), envelope.getPickupLocation(), 0.0, DriverImpl.noDriver(), v) + + routingCosts.getTransportTime(envelope.getPickupLocation(), envelope.getDeliveryLocation(), 0.0, DriverImpl.noDriver(), v); + } + + private static void readEnvelopes(Builder problemBuilder) throws IOException { + BufferedReader reader = new BufferedReader(new FileReader(new File("input/bicycle_messenger_demand.txt"))); + String line; + boolean firstLine = true; + while ((line = reader.readLine()) != null) { + if (firstLine) { + firstLine = false; + continue; + } + String[] tokens = line.split("\\s+"); + //define your envelope which is basically a shipment from A to B + Shipment envelope = Shipment.Builder.newInstance(tokens[1]).addSizeDimension(0, 1) + .setPickupLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(Double.parseDouble(tokens[2]), Double.parseDouble(tokens[3]))).build()) + .setDeliveryLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(Double.parseDouble(tokens[4]), Double.parseDouble(tokens[5]))).build()).build(); + problemBuilder.addJob(envelope); + } + reader.close(); + } + + private static void readMessengers(Builder problemBuilder) throws IOException { + BufferedReader reader = new BufferedReader(new FileReader(new File("input/bicycle_messenger_supply.txt"))); + String line; + boolean firstLine = true; + VehicleType messengerType = VehicleTypeImpl.Builder.newInstance("messengerType").addCapacityDimension(0, 15).setCostPerDistance(1).build(); + /* + * the algo requires some time and space to search for a valid solution. if you ommit a penalty-type, it probably throws an Exception once it cannot insert an envelope anymore * thus, give it space by defining a penalty/shadow vehicle with higher variable and fixed costs to up the pressure to find solutions without penalty type - * + * * it is important to give it the same typeId as the type you want to shadow */ - while((line = reader.readLine()) != null){ - if(firstLine) { firstLine = false; continue; } - String[] tokens = line.split("\\s+"); - //build your vehicle - VehicleImpl vehicle = VehicleImpl.Builder.newInstance(tokens[1]) - .setStartLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(Double.parseDouble(tokens[2]), Double.parseDouble(tokens[3]))).build()) - .setReturnToDepot(false).setType(messengerType).build(); - problemBuilder.addVehicle(vehicle); - } - reader.close(); - } + while ((line = reader.readLine()) != null) { + if (firstLine) { + firstLine = false; + continue; + } + String[] tokens = line.split("\\s+"); + //build your vehicle + VehicleImpl vehicle = VehicleImpl.Builder.newInstance(tokens[1]) + .setStartLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(Double.parseDouble(tokens[2]), Double.parseDouble(tokens[3]))).build()) + .setReturnToDepot(false).setType(messengerType).build(); + problemBuilder.addVehicle(vehicle); + } + reader.close(); + } } diff --git a/jsprit-examples/src/main/java/jsprit/examples/BreakExample.java b/jsprit-examples/src/main/java/jsprit/examples/BreakExample.java new file mode 100644 index 00000000..f17afeaa --- /dev/null +++ b/jsprit-examples/src/main/java/jsprit/examples/BreakExample.java @@ -0,0 +1,107 @@ +/******************************************************************************* + * Copyright (C) 2014 Stefan Schroeder + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3.0 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + ******************************************************************************/ +package jsprit.examples; + +import jsprit.analysis.toolbox.Plotter; +import jsprit.core.algorithm.VehicleRoutingAlgorithm; +import jsprit.core.algorithm.box.Jsprit; +import jsprit.core.problem.Location; +import jsprit.core.problem.VehicleRoutingProblem; +import jsprit.core.problem.job.Break; +import jsprit.core.problem.job.Service; +import jsprit.core.problem.solution.VehicleRoutingProblemSolution; +import jsprit.core.problem.solution.route.activity.TimeWindow; +import jsprit.core.problem.vehicle.VehicleImpl; +import jsprit.core.problem.vehicle.VehicleImpl.Builder; +import jsprit.core.problem.vehicle.VehicleType; +import jsprit.core.problem.vehicle.VehicleTypeImpl; +import jsprit.core.reporting.SolutionPrinter; +import jsprit.core.util.Solutions; + +import java.util.Collection; + + +public class BreakExample { + + + 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 + */ + 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") + .setTimeWindow(TimeWindow.newInstance(10, 15)).setServiceTime(100).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(); + /* + * 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 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(); + + /* + * 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(); + /* + * and search a solution + */ + Collection solutions = algorithm.searchSolutions(); + + /* + * get the best + */ + VehicleRoutingProblemSolution bestSolution = Solutions.bestOf(solutions); + + SolutionPrinter.print(problem, bestSolution, SolutionPrinter.Print.VERBOSE); + + /* + * plot + */ + new Plotter(problem, bestSolution).plot("output/plot", "breaks"); + + + } + +} diff --git a/jsprit-examples/src/main/java/jsprit/examples/BuildAlgorithmFromScratch.java b/jsprit-examples/src/main/java/jsprit/examples/BuildAlgorithmFromScratch.java index c5f3af93..22d60d2d 100644 --- a/jsprit-examples/src/main/java/jsprit/examples/BuildAlgorithmFromScratch.java +++ b/jsprit-examples/src/main/java/jsprit/examples/BuildAlgorithmFromScratch.java @@ -72,15 +72,15 @@ public class BuildAlgorithmFromScratch { List unassigned = new ArrayList(unassignedJobs); Collections.shuffle(unassigned, random); - for(Job j : unassigned){ + for (Job j : unassigned) { InsertionData bestInsertionData = InsertionData.createEmptyInsertionData(); VehicleRoute bestRoute = null; //look for inserting unassigned job into existing route - for(VehicleRoute r : vehicleRoutes){ - InsertionData insertionData = insertionCalculator.getInsertionData(j,r,bestInsertionData.getInsertionCost()); - if(insertionData instanceof InsertionData.NoInsertionFound) continue; - if(insertionData.getInsertionCost() < bestInsertionData.getInsertionCost()){ + for (VehicleRoute r : vehicleRoutes) { + InsertionData insertionData = insertionCalculator.getInsertionData(j, r, bestInsertionData.getInsertionCost()); + if (insertionData instanceof InsertionData.NoInsertionFound) continue; + if (insertionData.getInsertionCost() < bestInsertionData.getInsertionCost()) { bestInsertionData = insertionData; bestRoute = r; } @@ -88,14 +88,13 @@ public class BuildAlgorithmFromScratch { //try whole new route VehicleRoute empty = VehicleRoute.emptyRoute(); InsertionData insertionData = insertionCalculator.getInsertionData(j, empty, bestInsertionData.getInsertionCost()); - if(!(insertionData instanceof InsertionData.NoInsertionFound)) { + if (!(insertionData instanceof InsertionData.NoInsertionFound)) { if (insertionData.getInsertionCost() < bestInsertionData.getInsertionCost()) { vehicleRoutes.add(empty); insertJob(j, insertionData, empty); } - } - else { - if(bestRoute != null) insertJob(j,bestInsertionData,bestRoute); + } else { + if (bestRoute != null) insertJob(j, bestInsertionData, bestRoute); else badJobs.add(j); } } @@ -115,8 +114,8 @@ public class BuildAlgorithmFromScratch { VehicleRoutingAlgorithm vra = createAlgorithm(vrp); vra.setMaxIterations(100); - AlgorithmEventsRecorder eventsRecorder = new AlgorithmEventsRecorder(vrp,"output/events.dgs.gz"); - eventsRecorder.setRecordingRange(90,100); + AlgorithmEventsRecorder eventsRecorder = new AlgorithmEventsRecorder(vrp, "output/events.dgs.gz"); + eventsRecorder.setRecordingRange(90, 100); vra.addListener(eventsRecorder); VehicleRoutingProblemSolution solution = Solutions.bestOf(vra.searchSolutions()); @@ -129,35 +128,35 @@ public class BuildAlgorithmFromScratch { } - public static VehicleRoutingAlgorithm createAlgorithm(final VehicleRoutingProblem vrp){ + public static VehicleRoutingAlgorithm createAlgorithm(final VehicleRoutingProblem vrp) { VehicleFleetManager fleetManager = new FiniteFleetManagerFactory(vrp.getVehicles()).createFleetManager(); StateManager stateManager = new StateManager(vrp); - ConstraintManager constraintManager = new ConstraintManager(vrp,stateManager); + ConstraintManager constraintManager = new ConstraintManager(vrp, stateManager); /* * insertion strategies */ //my custom best insertion - MyBestStrategy best = new MyBestStrategy(vrp,fleetManager,stateManager,constraintManager); + MyBestStrategy best = new MyBestStrategy(vrp, fleetManager, stateManager, constraintManager); //regret insertion InsertionBuilder iBuilder = new InsertionBuilder(vrp, fleetManager, stateManager, constraintManager); iBuilder.setInsertionStrategy(InsertionBuilder.Strategy.REGRET); - RegretInsertion regret = (RegretInsertion) iBuilder.build(); - RegretInsertion.DefaultScorer scoringFunction = new RegretInsertion.DefaultScorer(vrp); + RegretInsertionFast regret = (RegretInsertionFast) iBuilder.build(); + DefaultScorer scoringFunction = new DefaultScorer(vrp); scoringFunction.setDepotDistanceParam(0.2); scoringFunction.setTimeWindowParam(-.2); regret.setScoringFunction(scoringFunction); /* - * ruin strategies + * ruin strategies */ RuinStrategy randomRuin = new RandomRuinStrategyFactory(0.5).createStrategy(vrp); RuinStrategy radialRuin = new RadialRuinStrategyFactory(0.3, new AvgServiceAndShipmentDistance(vrp.getTransportCosts())).createStrategy(vrp); /* - * objective function + * objective function */ SolutionCostCalculator objectiveFunction = getObjectiveFunction(vrp); @@ -170,12 +169,12 @@ public class BuildAlgorithmFromScratch { SearchStrategy thirdStrategy = new SearchStrategy("thirdStrategy", new SelectBest(), new GreedyAcceptance(1), objectiveFunction); secondStrategy.addModule(new RuinAndRecreateModule("radRuinBestIns", regret, radialRuin)); - PrettyAlgorithmBuilder prettyAlgorithmBuilder = PrettyAlgorithmBuilder.newInstance(vrp,fleetManager,stateManager,constraintManager); + PrettyAlgorithmBuilder prettyAlgorithmBuilder = PrettyAlgorithmBuilder.newInstance(vrp, fleetManager, stateManager, constraintManager); final VehicleRoutingAlgorithm vra = prettyAlgorithmBuilder - .withStrategy(firstStrategy, 0.5).withStrategy(secondStrategy, 0.5).withStrategy(thirdStrategy, 0.2) - .addCoreStateAndConstraintStuff() - .constructInitialSolutionWith(regret, objectiveFunction) - .build(); + .withStrategy(firstStrategy, 0.5).withStrategy(secondStrategy, 0.5).withStrategy(thirdStrategy, 0.2) + .addCoreStateAndConstraintStuff() + .constructInitialSolutionWith(regret, objectiveFunction) + .build(); //if you want to switch on/off strategies or adapt their weight within the search, you can do the following //e.g. from iteration 50 on, switch off first strategy @@ -183,12 +182,12 @@ public class BuildAlgorithmFromScratch { IterationStartsListener strategyAdaptor = new IterationStartsListener() { @Override public void informIterationStarts(int i, VehicleRoutingProblem problem, Collection solutions) { - if(i == 50){ - vra.getSearchStrategyManager().informStrategyWeightChanged("firstStrategy",0.0); + if (i == 50) { + vra.getSearchStrategyManager().informStrategyWeightChanged("firstStrategy", 0.0); System.out.println("switched off firstStrategy"); } - if(i == 90){ - vra.getSearchStrategyManager().informStrategyWeightChanged("firstStrategy",0.7); + if (i == 90) { + vra.getSearchStrategyManager().informStrategyWeightChanged("firstStrategy", 0.7); System.out.println("switched on firstStrategy again with higher weight"); } } @@ -204,10 +203,10 @@ public class BuildAlgorithmFromScratch { @Override public double getCosts(VehicleRoutingProblemSolution solution) { - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution,new SolutionAnalyser.DistanceCalculator() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new SolutionAnalyser.DistanceCalculator() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); return analyser.getVariableTransportCosts() + solution.getUnassignedJobs().size() * 500.; diff --git a/jsprit-examples/src/main/java/jsprit/examples/CircleExample.java b/jsprit-examples/src/main/java/jsprit/examples/CircleExample.java index f053277e..de3de0cb 100644 --- a/jsprit-examples/src/main/java/jsprit/examples/CircleExample.java +++ b/jsprit-examples/src/main/java/jsprit/examples/CircleExample.java @@ -40,12 +40,12 @@ import java.util.Collection; */ public class CircleExample { - public static Collection createCoordinates(double center_x, double center_y, double radius, double step){ + public static Collection createCoordinates(double center_x, double center_y, double radius, double step) { Collection coords = new ArrayList(); - for(double theta = 0; theta < 2*Math.PI; theta += step){ - double x = center_x + radius*Math.cos(theta); - double y = center_y - radius*Math.sin(theta); - coords.add(Coordinate.newInstance(x,y)); + for (double theta = 0; theta < 2 * Math.PI; theta += step) { + double x = center_x + radius * Math.cos(theta); + double y = center_y - radius * Math.sin(theta); + coords.add(Coordinate.newInstance(x, y)); } return coords; } @@ -53,21 +53,21 @@ public class CircleExample { public static void main(String[] args) { File dir = new File("output"); // if the directory does not exist, create it - if (!dir.exists()){ + if (!dir.exists()) { System.out.println("creating directory ./output"); boolean result = dir.mkdir(); - if(result) System.out.println("./output created"); + if (result) System.out.println("./output created"); } VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); VehicleImpl v = VehicleImpl.Builder.newInstance("v") - .setStartLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(0, 0)).build()).build(); + .setStartLocation(Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(0, 0)).build()).build(); vrpBuilder.addVehicle(v); - double step = 2*Math.PI/50.; - Collection circle = createCoordinates(0,0,20,step); + double step = 2 * Math.PI / 50.; + Collection circle = createCoordinates(0, 0, 20, step); int id = 1; - for(Coordinate c : circle){ + for (Coordinate c : circle) { Service s = Service.Builder.newInstance(Integer.toString(id)).setLocation(Location.Builder.newInstance().setCoordinate(c).build()).build(); vrpBuilder.addJob(s); id++; @@ -75,8 +75,8 @@ public class CircleExample { VehicleRoutingProblem vrp = vrpBuilder.build(); //only works with latest snapshot: 1.4.3 - AlgorithmEventsRecorder eventsRecorder = new AlgorithmEventsRecorder(vrp,"output/events.dgs.gz"); - eventsRecorder.setRecordingRange(0,50); + AlgorithmEventsRecorder eventsRecorder = new AlgorithmEventsRecorder(vrp, "output/events.dgs.gz"); + eventsRecorder.setRecordingRange(0, 50); VehicleRoutingAlgorithm vra = new GreedySchrimpfFactory().createAlgorithm(vrp); vra.setMaxIterations(50); @@ -86,8 +86,8 @@ public class CircleExample { VehicleRoutingProblemSolution solution = Solutions.bestOf(vra.searchSolutions()); - new Plotter(vrp,solution).plot("output/circle.png","circleProblem"); - new GraphStreamViewer(vrp,solution).display(); + new Plotter(vrp, solution).plot("output/circle.png", "circleProblem"); + new GraphStreamViewer(vrp, solution).display(); //only works with latest snapshot: 1.4.3 AlgorithmEventsViewer viewer = new AlgorithmEventsViewer(); diff --git a/jsprit-examples/src/main/java/jsprit/examples/ConfigureAlgorithmInCodeInsteadOfPerXml.java b/jsprit-examples/src/main/java/jsprit/examples/ConfigureAlgorithmInCodeInsteadOfPerXml.java index d10f3ef1..17da1351 100644 --- a/jsprit-examples/src/main/java/jsprit/examples/ConfigureAlgorithmInCodeInsteadOfPerXml.java +++ b/jsprit-examples/src/main/java/jsprit/examples/ConfigureAlgorithmInCodeInsteadOfPerXml.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.examples; @@ -38,97 +38,97 @@ import java.util.Collection; public class ConfigureAlgorithmInCodeInsteadOfPerXml { - - public static void main(String[] args) { - /* - * some preparation - create output folder - */ - Examples.createOutputFolder(); - - /* - * get a vehicle type-builder and build a type with the typeId "vehicleType" and a capacity of 2 - */ - VehicleTypeImpl.Builder vehicleTypeBuilder = VehicleTypeImpl.Builder.newInstance("vehicleType").addCapacityDimension(0, 2); - VehicleType vehicleType = vehicleTypeBuilder.build(); - - /* - * get a vehicle-builder and build a vehicle located at (10,10) with type "vehicleType" - */ - Builder vehicleBuilder = VehicleImpl.Builder.newInstance("vehicle"); - vehicleBuilder.setStartLocation(Location.newInstance(10, 10)); - vehicleBuilder.setType(vehicleType); - VehicleImpl vehicle = vehicleBuilder.build(); - - /* - * build services at the required locations, each with a capacity-demand of 1. - */ - Service service1 = Service.Builder.newInstance("1").addSizeDimension(0, 1).setLocation(Location.newInstance(5, 7)).build(); - Service service2 = Service.Builder.newInstance("2").addSizeDimension(0, 1).setLocation(Location.newInstance(5, 13)).build(); - - Service service3 = Service.Builder.newInstance("3").addSizeDimension(0, 1).setLocation(Location.newInstance(15, 7)).build(); - Service service4 = Service.Builder.newInstance("4").addSizeDimension(0, 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); - - VehicleRoutingProblem problem = vrpBuilder.build(); - - /* - * get the algorithm out-of-the-box. - */ - AlgorithmConfig algorithmConfig = getAlgorithmConfig(); - VehicleRoutingAlgorithm algorithm = VehicleRoutingAlgorithms.createAlgorithm(problem,algorithmConfig); - - /* - * and search a solution - */ - Collection solutions = algorithm.searchSolutions(); - - /* - * get the best - */ - VehicleRoutingProblemSolution bestSolution = Solutions.bestOf(solutions); - - new VrpXMLWriter(problem, solutions).write("output/problem-with-solution.xml"); - - SolutionPrinter.print(bestSolution); - - /* - * plot - */ - new Plotter(problem,bestSolution).plot("output/solution.png", "solution"); - } - private static AlgorithmConfig getAlgorithmConfig() { - AlgorithmConfig config = new AlgorithmConfig(); - XMLConfiguration xmlConfig = config.getXMLConfiguration(); - xmlConfig.setProperty("iterations", "2000"); - xmlConfig.setProperty("construction.insertion[@name]","bestInsertion"); - - xmlConfig.setProperty("strategy.memory", 1); - String searchStrategy = "strategy.searchStrategies.searchStrategy"; + public static void main(String[] args) { + /* + * some preparation - create output folder + */ + Examples.createOutputFolder(); - xmlConfig.setProperty(searchStrategy + "(0)[@name]","random_best"); - xmlConfig.setProperty(searchStrategy + "(0).selector[@name]","selectBest"); - xmlConfig.setProperty(searchStrategy + "(0).acceptor[@name]","acceptNewRemoveWorst"); - xmlConfig.setProperty(searchStrategy + "(0).modules.module(0)[@name]","ruin_and_recreate"); - xmlConfig.setProperty(searchStrategy + "(0).modules.module(0).ruin[@name]","randomRuin"); - xmlConfig.setProperty(searchStrategy + "(0).modules.module(0).ruin.share","0.3"); - xmlConfig.setProperty(searchStrategy + "(0).modules.module(0).insertion[@name]","bestInsertion"); - xmlConfig.setProperty(searchStrategy + "(0).probability","0.5"); + /* + * get a vehicle type-builder and build a type with the typeId "vehicleType" and a capacity of 2 + */ + VehicleTypeImpl.Builder vehicleTypeBuilder = VehicleTypeImpl.Builder.newInstance("vehicleType").addCapacityDimension(0, 2); + VehicleType vehicleType = vehicleTypeBuilder.build(); - xmlConfig.setProperty(searchStrategy + "(1)[@name]","radial_best"); - xmlConfig.setProperty(searchStrategy + "(1).selector[@name]","selectBest"); - xmlConfig.setProperty(searchStrategy + "(1).acceptor[@name]","acceptNewRemoveWorst"); - xmlConfig.setProperty(searchStrategy + "(1).modules.module(0)[@name]","ruin_and_recreate"); - xmlConfig.setProperty(searchStrategy + "(1).modules.module(0).ruin[@name]","radialRuin"); - xmlConfig.setProperty(searchStrategy + "(1).modules.module(0).ruin.share","0.15"); - xmlConfig.setProperty(searchStrategy + "(1).modules.module(0).insertion[@name]","bestInsertion"); - xmlConfig.setProperty(searchStrategy + "(1).probability","0.5"); - - return config; - } + /* + * get a vehicle-builder and build a vehicle located at (10,10) with type "vehicleType" + */ + Builder vehicleBuilder = VehicleImpl.Builder.newInstance("vehicle"); + vehicleBuilder.setStartLocation(Location.newInstance(10, 10)); + vehicleBuilder.setType(vehicleType); + VehicleImpl vehicle = vehicleBuilder.build(); + + /* + * build services at the required locations, each with a capacity-demand of 1. + */ + Service service1 = Service.Builder.newInstance("1").addSizeDimension(0, 1).setLocation(Location.newInstance(5, 7)).build(); + Service service2 = Service.Builder.newInstance("2").addSizeDimension(0, 1).setLocation(Location.newInstance(5, 13)).build(); + + Service service3 = Service.Builder.newInstance("3").addSizeDimension(0, 1).setLocation(Location.newInstance(15, 7)).build(); + Service service4 = Service.Builder.newInstance("4").addSizeDimension(0, 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); + + VehicleRoutingProblem problem = vrpBuilder.build(); + + /* + * get the algorithm out-of-the-box. + */ + AlgorithmConfig algorithmConfig = getAlgorithmConfig(); + VehicleRoutingAlgorithm algorithm = VehicleRoutingAlgorithms.createAlgorithm(problem, algorithmConfig); + + /* + * and search a solution + */ + Collection solutions = algorithm.searchSolutions(); + + /* + * get the best + */ + VehicleRoutingProblemSolution bestSolution = Solutions.bestOf(solutions); + + new VrpXMLWriter(problem, solutions).write("output/problem-with-solution.xml"); + + SolutionPrinter.print(bestSolution); + + /* + * plot + */ + new Plotter(problem, bestSolution).plot("output/solution.png", "solution"); + } + + private static AlgorithmConfig getAlgorithmConfig() { + AlgorithmConfig config = new AlgorithmConfig(); + XMLConfiguration xmlConfig = config.getXMLConfiguration(); + xmlConfig.setProperty("iterations", "2000"); + xmlConfig.setProperty("construction.insertion[@name]", "bestInsertion"); + + xmlConfig.setProperty("strategy.memory", 1); + String searchStrategy = "strategy.searchStrategies.searchStrategy"; + + xmlConfig.setProperty(searchStrategy + "(0)[@name]", "random_best"); + xmlConfig.setProperty(searchStrategy + "(0).selector[@name]", "selectBest"); + xmlConfig.setProperty(searchStrategy + "(0).acceptor[@name]", "acceptNewRemoveWorst"); + xmlConfig.setProperty(searchStrategy + "(0).modules.module(0)[@name]", "ruin_and_recreate"); + xmlConfig.setProperty(searchStrategy + "(0).modules.module(0).ruin[@name]", "randomRuin"); + xmlConfig.setProperty(searchStrategy + "(0).modules.module(0).ruin.share", "0.3"); + xmlConfig.setProperty(searchStrategy + "(0).modules.module(0).insertion[@name]", "bestInsertion"); + xmlConfig.setProperty(searchStrategy + "(0).probability", "0.5"); + + xmlConfig.setProperty(searchStrategy + "(1)[@name]", "radial_best"); + xmlConfig.setProperty(searchStrategy + "(1).selector[@name]", "selectBest"); + xmlConfig.setProperty(searchStrategy + "(1).acceptor[@name]", "acceptNewRemoveWorst"); + xmlConfig.setProperty(searchStrategy + "(1).modules.module(0)[@name]", "ruin_and_recreate"); + xmlConfig.setProperty(searchStrategy + "(1).modules.module(0).ruin[@name]", "radialRuin"); + xmlConfig.setProperty(searchStrategy + "(1).modules.module(0).ruin.share", "0.15"); + xmlConfig.setProperty(searchStrategy + "(1).modules.module(0).insertion[@name]", "bestInsertion"); + xmlConfig.setProperty(searchStrategy + "(1).probability", "0.5"); + + return config; + } } diff --git a/jsprit-examples/src/main/java/jsprit/examples/CostMatrixExample.java b/jsprit-examples/src/main/java/jsprit/examples/CostMatrixExample.java index 17bc0d74..4f9d06ab 100644 --- a/jsprit-examples/src/main/java/jsprit/examples/CostMatrixExample.java +++ b/jsprit-examples/src/main/java/jsprit/examples/CostMatrixExample.java @@ -11,14 +11,14 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.examples; import jsprit.analysis.toolbox.Plotter; import jsprit.core.algorithm.VehicleRoutingAlgorithm; -import jsprit.core.algorithm.io.VehicleRoutingAlgorithms; +import jsprit.core.algorithm.box.Jsprit; import jsprit.core.problem.Location; import jsprit.core.problem.VehicleRoutingProblem; import jsprit.core.problem.VehicleRoutingProblem.FleetSize; @@ -38,29 +38,28 @@ import java.util.Collection; /** * Illustrates how you can use jsprit with an already compiled distance and time matrix. - * - * @author schroeder * + * @author schroeder */ public class CostMatrixExample { - public static void main(String[] args) { - /* - * some preparation - create output folder + public static void main(String[] args) { + /* + * some preparation - create output folder */ - Examples.createOutputFolder(); - - VehicleType type = VehicleTypeImpl.Builder.newInstance("type").addCapacityDimension(0, 2).setCostPerDistance(1).setCostPerTime(2).build(); - VehicleImpl vehicle = VehicleImpl.Builder.newInstance("vehicle") - .setStartLocation(Location.newInstance("0")).setType(type).build(); - - Service s1 = Service.Builder.newInstance("1").addSizeDimension(0, 1).setLocation(Location.newInstance("1")).build(); - Service s2 = Service.Builder.newInstance("2").addSizeDimension(0, 1).setLocation(Location.newInstance("2")).build(); - Service s3 = Service.Builder.newInstance("3").addSizeDimension(0, 1).setLocation(Location.newInstance("3")).build(); - - + Examples.createOutputFolder(); + + VehicleType type = VehicleTypeImpl.Builder.newInstance("type").addCapacityDimension(0, 2).setCostPerDistance(1).setCostPerTime(2).build(); + VehicleImpl vehicle = VehicleImpl.Builder.newInstance("vehicle") + .setStartLocation(Location.newInstance("0")).setType(type).build(); + + Service s1 = Service.Builder.newInstance("1").addSizeDimension(0, 1).setLocation(Location.newInstance("1")).build(); + Service s2 = Service.Builder.newInstance("2").addSizeDimension(0, 1).setLocation(Location.newInstance("2")).build(); + Service s3 = Service.Builder.newInstance("3").addSizeDimension(0, 1).setLocation(Location.newInstance("3")).build(); + + /* - * Assume the following symmetric distance-matrix + * Assume the following symmetric distance-matrix * from,to,distance * 0,1,10.0 * 0,2,20.0 @@ -68,7 +67,7 @@ public class CostMatrixExample { * 1,2,4.0 * 1,3,1.0 * 2,3,2.0 - * + * * and this time-matrix * 0,1,5.0 * 0,2,10.0 @@ -77,35 +76,35 @@ public class CostMatrixExample { * 1,3,0.5 * 2,3,1.0 */ - //define a matrix-builder building a symmetric matrix - VehicleRoutingTransportCostsMatrix.Builder costMatrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(true); - costMatrixBuilder.addTransportDistance("0", "1", 10.0); - costMatrixBuilder.addTransportDistance("0", "2", 20.0); - costMatrixBuilder.addTransportDistance("0", "3", 5.0); - costMatrixBuilder.addTransportDistance("1", "2", 4.0); - costMatrixBuilder.addTransportDistance("1", "3", 1.0); - costMatrixBuilder.addTransportDistance("2", "3", 2.0); - - costMatrixBuilder.addTransportTime("0", "1", 10.0); - costMatrixBuilder.addTransportTime("0", "2", 20.0); - costMatrixBuilder.addTransportTime("0", "3", 5.0); - costMatrixBuilder.addTransportTime("1", "2", 4.0); - costMatrixBuilder.addTransportTime("1", "3", 1.0); - costMatrixBuilder.addTransportTime("2", "3", 2.0); - - VehicleRoutingTransportCosts costMatrix = costMatrixBuilder.build(); - - VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().setFleetSize(FleetSize.INFINITE).setRoutingCost(costMatrix) - .addVehicle(vehicle).addJob(s1).addJob(s2).addJob(s3).build(); - - VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "input/fastAlgo.xml"); - - Collection solutions = vra.searchSolutions(); - - SolutionPrinter.print(Solutions.bestOf(solutions)); - - new Plotter(vrp, Solutions.bestOf(solutions)).plot("output/yo.png", "po"); - - } + //define a matrix-builder building a symmetric matrix + VehicleRoutingTransportCostsMatrix.Builder costMatrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(true); + costMatrixBuilder.addTransportDistance("0", "1", 10.0); + costMatrixBuilder.addTransportDistance("0", "2", 20.0); + costMatrixBuilder.addTransportDistance("0", "3", 5.0); + costMatrixBuilder.addTransportDistance("1", "2", 4.0); + costMatrixBuilder.addTransportDistance("1", "3", 1.0); + costMatrixBuilder.addTransportDistance("2", "3", 2.0); + + costMatrixBuilder.addTransportTime("0", "1", 10.0); + costMatrixBuilder.addTransportTime("0", "2", 20.0); + costMatrixBuilder.addTransportTime("0", "3", 5.0); + costMatrixBuilder.addTransportTime("1", "2", 4.0); + costMatrixBuilder.addTransportTime("1", "3", 1.0); + costMatrixBuilder.addTransportTime("2", "3", 2.0); + + VehicleRoutingTransportCosts costMatrix = costMatrixBuilder.build(); + + VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().setFleetSize(FleetSize.INFINITE).setRoutingCost(costMatrix) + .addVehicle(vehicle).addJob(s1).addJob(s2).addJob(s3).build(); + + VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp); + + Collection solutions = vra.searchSolutions(); + + SolutionPrinter.print(Solutions.bestOf(solutions)); + + new Plotter(vrp, Solutions.bestOf(solutions)).plot("output/yo.png", "po"); + + } } diff --git a/jsprit-examples/src/main/java/jsprit/examples/EnRoutePickupAndDeliveryWithMultipleDepotsAndOpenRoutesExample.java b/jsprit-examples/src/main/java/jsprit/examples/EnRoutePickupAndDeliveryWithMultipleDepotsAndOpenRoutesExample.java index 303b8380..c473b322 100644 --- a/jsprit-examples/src/main/java/jsprit/examples/EnRoutePickupAndDeliveryWithMultipleDepotsAndOpenRoutesExample.java +++ b/jsprit-examples/src/main/java/jsprit/examples/EnRoutePickupAndDeliveryWithMultipleDepotsAndOpenRoutesExample.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.examples; @@ -41,131 +41,131 @@ import java.util.Collection; public class EnRoutePickupAndDeliveryWithMultipleDepotsAndOpenRoutesExample { - - public static void main(String[] args) { - /* - * some preparation - create output folder + + public static void main(String[] args) { + /* + * some preparation - create output folder */ - Examples.createOutputFolder(); - + Examples.createOutputFolder(); + /* - * get a vehicle type-builder and build a type with the typeId "vehicleType" and a capacity of 2 + * get a vehicle type-builder and build a type with the typeId "vehicleType" and a capacity of 2 */ - VehicleTypeImpl.Builder vehicleTypeBuilder = VehicleTypeImpl.Builder.newInstance("vehicleType").addCapacityDimension(0, 2); - vehicleTypeBuilder.setCostPerDistance(1.0); - VehicleType vehicleType = vehicleTypeBuilder.build(); - + VehicleTypeImpl.Builder vehicleTypeBuilder = VehicleTypeImpl.Builder.newInstance("vehicleType").addCapacityDimension(0, 2); + vehicleTypeBuilder.setCostPerDistance(1.0); + VehicleType vehicleType = vehicleTypeBuilder.build(); + /* - * define two vehicles and their start-locations - * + * define two vehicles and their start-locations + * * the first two do need to return to depot */ - Builder vehicleBuilder1 = VehicleImpl.Builder.newInstance("vehicles@[10,10]"); - vehicleBuilder1.setStartLocation(loc(Coordinate.newInstance(10, 10))).setReturnToDepot(false); - vehicleBuilder1.setType(vehicleType); - VehicleImpl vehicle1 = vehicleBuilder1.build(); - - Builder vehicleBuilder2 = VehicleImpl.Builder.newInstance("vehicles@[30,30]"); - vehicleBuilder2.setStartLocation(loc(Coordinate.newInstance(30, 30))).setReturnToDepot(false); - vehicleBuilder2.setType(vehicleType); - VehicleImpl vehicle2 = vehicleBuilder2.build(); - - Builder vehicleBuilder3 = VehicleImpl.Builder.newInstance("vehicles@[10,30]"); - vehicleBuilder3.setStartLocation(loc(Coordinate.newInstance(10, 30))); - vehicleBuilder3.setType(vehicleType); - VehicleImpl vehicle3 = vehicleBuilder3.build(); - - Builder vehicleBuilder4 = VehicleImpl.Builder.newInstance("vehicles@[30,10]"); - vehicleBuilder4.setStartLocation(loc(Coordinate.newInstance(30, 10))); - vehicleBuilder4.setType(vehicleType); - VehicleImpl vehicle4 = vehicleBuilder4.build(); - + Builder vehicleBuilder1 = VehicleImpl.Builder.newInstance("vehicles@[10,10]"); + vehicleBuilder1.setStartLocation(loc(Coordinate.newInstance(10, 10))).setReturnToDepot(false); + vehicleBuilder1.setType(vehicleType); + VehicleImpl vehicle1 = vehicleBuilder1.build(); + + Builder vehicleBuilder2 = VehicleImpl.Builder.newInstance("vehicles@[30,30]"); + vehicleBuilder2.setStartLocation(loc(Coordinate.newInstance(30, 30))).setReturnToDepot(false); + vehicleBuilder2.setType(vehicleType); + VehicleImpl vehicle2 = vehicleBuilder2.build(); + + Builder vehicleBuilder3 = VehicleImpl.Builder.newInstance("vehicles@[10,30]"); + vehicleBuilder3.setStartLocation(loc(Coordinate.newInstance(10, 30))); + vehicleBuilder3.setType(vehicleType); + VehicleImpl vehicle3 = vehicleBuilder3.build(); + + Builder vehicleBuilder4 = VehicleImpl.Builder.newInstance("vehicles@[30,10]"); + vehicleBuilder4.setStartLocation(loc(Coordinate.newInstance(30, 10))); + vehicleBuilder4.setType(vehicleType); + VehicleImpl vehicle4 = vehicleBuilder4.build(); + /* - * build shipments at the required locations, each with a capacity-demand of 1. + * build shipments at the required locations, each with a capacity-demand of 1. */ - - Shipment shipment1 = Shipment.Builder.newInstance("1").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(5, 7))).setDeliveryLocation(loc(Coordinate.newInstance(6, 9))).build(); - Shipment shipment2 = Shipment.Builder.newInstance("2").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(5, 13))).setDeliveryLocation(loc(Coordinate.newInstance(6, 11))).build(); - - Shipment shipment3 = Shipment.Builder.newInstance("3").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(15, 7))).setDeliveryLocation(loc(Coordinate.newInstance(14, 9))).build(); - Shipment shipment4 = Shipment.Builder.newInstance("4").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(15, 13))).setDeliveryLocation(loc(Coordinate.newInstance(14, 11))).build(); - - Shipment shipment5 = Shipment.Builder.newInstance("5").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(25, 27))).setDeliveryLocation(loc(Coordinate.newInstance(26, 29))).build(); - Shipment shipment6 = Shipment.Builder.newInstance("6").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(25, 33))).setDeliveryLocation(loc(Coordinate.newInstance(26, 31))).build(); - - Shipment shipment7 = Shipment.Builder.newInstance("7").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(35, 27))).setDeliveryLocation(loc(Coordinate.newInstance(34, 29))).build(); - Shipment shipment8 = Shipment.Builder.newInstance("8").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(35, 33))).setDeliveryLocation(loc(Coordinate.newInstance(34, 31))).build(); - - Shipment shipment9 = Shipment.Builder.newInstance("9").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(5, 27))).setDeliveryLocation(loc(Coordinate.newInstance(6, 29))).build(); - Shipment shipment10 = Shipment.Builder.newInstance("10").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(5, 33))).setDeliveryLocation(loc(Coordinate.newInstance(6, 31))).build(); - - Shipment shipment11 = Shipment.Builder.newInstance("11").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(15, 27))).setDeliveryLocation(loc(Coordinate.newInstance(14, 29))).build(); - Shipment shipment12 = Shipment.Builder.newInstance("12").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(15, 33))).setDeliveryLocation(loc(Coordinate.newInstance(14, 31))).build(); - - Shipment shipment13 = Shipment.Builder.newInstance("13").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(25, 7))).setDeliveryLocation(loc(Coordinate.newInstance(26, 9))).build(); - Shipment shipment14 = Shipment.Builder.newInstance("14").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(25, 13))).setDeliveryLocation(loc(Coordinate.newInstance(26, 11))).build(); - - Shipment shipment15 = Shipment.Builder.newInstance("15").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(35, 7))).setDeliveryLocation(loc(Coordinate.newInstance(34, 9))).build(); - Shipment shipment16 = Shipment.Builder.newInstance("16").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(35, 13))).setDeliveryLocation(loc(Coordinate.newInstance(34, 11))).build(); - - - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - vrpBuilder.addVehicle(vehicle1).addVehicle(vehicle2).addVehicle(vehicle3).addVehicle(vehicle4); - vrpBuilder.addJob(shipment1).addJob(shipment2).addJob(shipment3).addJob(shipment4); - vrpBuilder.addJob(shipment5).addJob(shipment6).addJob(shipment7).addJob(shipment8); - vrpBuilder.addJob(shipment9).addJob(shipment10).addJob(shipment11).addJob(shipment12); - vrpBuilder.addJob(shipment13).addJob(shipment14).addJob(shipment15).addJob(shipment16); - - vrpBuilder.setFleetSize(FleetSize.FINITE); - VehicleRoutingProblem problem = vrpBuilder.build(); - + + Shipment shipment1 = Shipment.Builder.newInstance("1").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(5, 7))).setDeliveryLocation(loc(Coordinate.newInstance(6, 9))).build(); + Shipment shipment2 = Shipment.Builder.newInstance("2").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(5, 13))).setDeliveryLocation(loc(Coordinate.newInstance(6, 11))).build(); + + Shipment shipment3 = Shipment.Builder.newInstance("3").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(15, 7))).setDeliveryLocation(loc(Coordinate.newInstance(14, 9))).build(); + Shipment shipment4 = Shipment.Builder.newInstance("4").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(15, 13))).setDeliveryLocation(loc(Coordinate.newInstance(14, 11))).build(); + + Shipment shipment5 = Shipment.Builder.newInstance("5").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(25, 27))).setDeliveryLocation(loc(Coordinate.newInstance(26, 29))).build(); + Shipment shipment6 = Shipment.Builder.newInstance("6").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(25, 33))).setDeliveryLocation(loc(Coordinate.newInstance(26, 31))).build(); + + Shipment shipment7 = Shipment.Builder.newInstance("7").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(35, 27))).setDeliveryLocation(loc(Coordinate.newInstance(34, 29))).build(); + Shipment shipment8 = Shipment.Builder.newInstance("8").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(35, 33))).setDeliveryLocation(loc(Coordinate.newInstance(34, 31))).build(); + + Shipment shipment9 = Shipment.Builder.newInstance("9").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(5, 27))).setDeliveryLocation(loc(Coordinate.newInstance(6, 29))).build(); + Shipment shipment10 = Shipment.Builder.newInstance("10").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(5, 33))).setDeliveryLocation(loc(Coordinate.newInstance(6, 31))).build(); + + Shipment shipment11 = Shipment.Builder.newInstance("11").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(15, 27))).setDeliveryLocation(loc(Coordinate.newInstance(14, 29))).build(); + Shipment shipment12 = Shipment.Builder.newInstance("12").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(15, 33))).setDeliveryLocation(loc(Coordinate.newInstance(14, 31))).build(); + + Shipment shipment13 = Shipment.Builder.newInstance("13").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(25, 7))).setDeliveryLocation(loc(Coordinate.newInstance(26, 9))).build(); + Shipment shipment14 = Shipment.Builder.newInstance("14").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(25, 13))).setDeliveryLocation(loc(Coordinate.newInstance(26, 11))).build(); + + Shipment shipment15 = Shipment.Builder.newInstance("15").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(35, 7))).setDeliveryLocation(loc(Coordinate.newInstance(34, 9))).build(); + Shipment shipment16 = Shipment.Builder.newInstance("16").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(35, 13))).setDeliveryLocation(loc(Coordinate.newInstance(34, 11))).build(); + + + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + vrpBuilder.addVehicle(vehicle1).addVehicle(vehicle2).addVehicle(vehicle3).addVehicle(vehicle4); + vrpBuilder.addJob(shipment1).addJob(shipment2).addJob(shipment3).addJob(shipment4); + vrpBuilder.addJob(shipment5).addJob(shipment6).addJob(shipment7).addJob(shipment8); + vrpBuilder.addJob(shipment9).addJob(shipment10).addJob(shipment11).addJob(shipment12); + vrpBuilder.addJob(shipment13).addJob(shipment14).addJob(shipment15).addJob(shipment16); + + vrpBuilder.setFleetSize(FleetSize.FINITE); + VehicleRoutingProblem problem = vrpBuilder.build(); + /* - * get the algorithm out-of-the-box. + * get the algorithm out-of-the-box. */ - VehicleRoutingAlgorithm algorithm = VehicleRoutingAlgorithms.readAndCreateAlgorithm(problem, "input/algorithmConfig.xml"); + VehicleRoutingAlgorithm algorithm = VehicleRoutingAlgorithms.readAndCreateAlgorithm(problem, "input/algorithmConfig.xml"); // algorithm.setMaxIterations(30000); - /* - * and search a solution + /* + * and search a solution */ - Collection solutions = algorithm.searchSolutions(); - + Collection solutions = algorithm.searchSolutions(); + /* - * get the best + * get the best */ - VehicleRoutingProblemSolution bestSolution = Solutions.bestOf(solutions); - + VehicleRoutingProblemSolution bestSolution = Solutions.bestOf(solutions); + /* * write out problem and solution to xml-file */ - new VrpXMLWriter(problem, solutions).write("output/shipment-problem-with-solution.xml"); - + new VrpXMLWriter(problem, solutions).write("output/shipment-problem-with-solution.xml"); + /* * print nRoutes and totalCosts of bestSolution */ - SolutionPrinter.print(bestSolution); - + SolutionPrinter.print(bestSolution); + /* * plot problem without solution */ - Plotter problemPlotter = new Plotter(problem); - problemPlotter.plotShipments(true); - problemPlotter.plot("output/enRoutePickupAndDeliveryWithMultipleLocationsExample_problem.png", "en-route pickup and delivery"); - + Plotter problemPlotter = new Plotter(problem); + problemPlotter.plotShipments(true); + problemPlotter.plot("output/enRoutePickupAndDeliveryWithMultipleLocationsExample_problem.png", "en-route pickup and delivery"); + /* * plot problem with solution */ - Plotter solutionPlotter = new Plotter(problem,Arrays.asList(Solutions.bestOf(solutions).getRoutes().iterator().next())); - solutionPlotter.plotShipments(true); - solutionPlotter.plot("output/enRoutePickupAndDeliveryWithMultipleLocationsExample_solution.png", "en-route pickup and delivery"); - - new GraphStreamViewer(problem,Solutions.bestOf(solutions)).labelWith(Label.ACTIVITY).setRenderDelay(100).setRenderShipments(true).display(); - - } + Plotter solutionPlotter = new Plotter(problem, Arrays.asList(Solutions.bestOf(solutions).getRoutes().iterator().next())); + solutionPlotter.plotShipments(true); + solutionPlotter.plot("output/enRoutePickupAndDeliveryWithMultipleLocationsExample_solution.png", "en-route pickup and delivery"); - private static Location loc(Coordinate coordinate){ - return Location.Builder.newInstance().setCoordinate(coordinate).build(); - } + new GraphStreamViewer(problem, Solutions.bestOf(solutions)).labelWith(Label.ACTIVITY).setRenderDelay(100).setRenderShipments(true).display(); + + } + + private static Location loc(Coordinate coordinate) { + return Location.Builder.newInstance().setCoordinate(coordinate).build(); + } } diff --git a/jsprit-examples/src/main/java/jsprit/examples/HVRPExample.java b/jsprit-examples/src/main/java/jsprit/examples/HVRPExample.java index c69dfe76..922f2b5e 100644 --- a/jsprit-examples/src/main/java/jsprit/examples/HVRPExample.java +++ b/jsprit-examples/src/main/java/jsprit/examples/HVRPExample.java @@ -34,99 +34,98 @@ import java.util.Collection; /** * customers (id,x,y,demand) - * 1 22 22 18 - * 2 36 26 26 - * 3 21 45 11 - * 4 45 35 30 - * 5 55 20 21 - * 6 33 34 19 - * 7 50 50 15 - * 8 55 45 16 - * 9 26 59 29 + * 1 22 22 18 + * 2 36 26 26 + * 3 21 45 11 + * 4 45 35 30 + * 5 55 20 21 + * 6 33 34 19 + * 7 50 50 15 + * 8 55 45 16 + * 9 26 59 29 * 10 40 66 26 - * 11 55 65 37 - * 12 35 51 16 - * 13 62 35 12 - * 14 62 57 31 - * 15 62 24 8 - * 16 21 36 19 - * 17 33 44 20 - * 18 9 56 13 - * 19 62 48 15 + * 11 55 65 37 + * 12 35 51 16 + * 13 62 35 12 + * 14 62 57 31 + * 15 62 24 8 + * 16 21 36 19 + * 17 33 44 20 + * 18 9 56 13 + * 19 62 48 15 * 20 66 14 22 - * + *

* vehicles (id,cap,fixed costs, perDistance, #vehicles) at location (40,40) * 1 120 1000 1.0 2 * 2 160 1500 1.1 1 * 3 300 3500 1.4 1 - * - * @author schroeder * + * @author schroeder */ public class HVRPExample { - - - public static void main(String[] args) { - - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - - //add customers - vrpBuilder.addJob(Service.Builder.newInstance("1").addSizeDimension(0, 18).setLocation(Location.newInstance(22, 22)).build()); - vrpBuilder.addJob(Service.Builder.newInstance("2").addSizeDimension(0, 26).setLocation(Location.newInstance(36, 26)).build()); - vrpBuilder.addJob(Service.Builder.newInstance("3").addSizeDimension(0, 11).setLocation(Location.newInstance(21, 45)).build()); - vrpBuilder.addJob(Service.Builder.newInstance("4").addSizeDimension(0, 30).setLocation(Location.newInstance(45, 35)).build()); - vrpBuilder.addJob(Service.Builder.newInstance("5").addSizeDimension(0, 21).setLocation(Location.newInstance(55, 20)).build()); - vrpBuilder.addJob(Service.Builder.newInstance("6").addSizeDimension(0, 19).setLocation(Location.newInstance(33, 34)).build()); - vrpBuilder.addJob(Service.Builder.newInstance("7").addSizeDimension(0, 15).setLocation(Location.newInstance(50, 50)).build()); - vrpBuilder.addJob(Service.Builder.newInstance("8").addSizeDimension(0, 16).setLocation(Location.newInstance(55, 45)).build()); - vrpBuilder.addJob(Service.Builder.newInstance("9").addSizeDimension(0, 29).setLocation(Location.newInstance(26, 59)).build()); - vrpBuilder.addJob(Service.Builder.newInstance("10").addSizeDimension(0, 26).setLocation(Location.newInstance(40, 66)).build()); - vrpBuilder.addJob(Service.Builder.newInstance("11").addSizeDimension(0, 37).setLocation(Location.newInstance(55, 56)).build()); - vrpBuilder.addJob(Service.Builder.newInstance("12").addSizeDimension(0, 16).setLocation(Location.newInstance(35, 51)).build()); - vrpBuilder.addJob(Service.Builder.newInstance("13").addSizeDimension(0, 12).setLocation(Location.newInstance(62, 35)).build()); - vrpBuilder.addJob(Service.Builder.newInstance("14").addSizeDimension(0, 31).setLocation(Location.newInstance(62, 57)).build()); - vrpBuilder.addJob(Service.Builder.newInstance("15").addSizeDimension(0, 8).setLocation(Location.newInstance(62, 24)).build()); - vrpBuilder.addJob(Service.Builder.newInstance("16").addSizeDimension(0, 19).setLocation(Location.newInstance(21, 36)).build()); - vrpBuilder.addJob(Service.Builder.newInstance("17").addSizeDimension(0, 20).setLocation(Location.newInstance(33, 44)).build()); - vrpBuilder.addJob(Service.Builder.newInstance("18").addSizeDimension(0, 13).setLocation(Location.newInstance(9, 56)).build()); - vrpBuilder.addJob(Service.Builder.newInstance("19").addSizeDimension(0, 15).setLocation(Location.newInstance(62, 48)).build()); - vrpBuilder.addJob(Service.Builder.newInstance("20").addSizeDimension(0, 22).setLocation(Location.newInstance(66, 14)).build()); - - - //add vehicle - finite fleet - //2xtype1 - VehicleType type1 = VehicleTypeImpl.Builder.newInstance("type_1").addCapacityDimension(0, 120).setCostPerDistance(1.0).build(); - VehicleImpl vehicle1_1 = VehicleImpl.Builder.newInstance("1_1").setStartLocation(Location.newInstance(40, 40)).setType(type1).build(); - vrpBuilder.addVehicle(vehicle1_1); - VehicleImpl vehicle1_2 = VehicleImpl.Builder.newInstance("1_2").setStartLocation(Location.newInstance(40, 40)).setType(type1).build(); - vrpBuilder.addVehicle(vehicle1_2); - //1xtype2 - VehicleType type2 = VehicleTypeImpl.Builder.newInstance("type_2").addCapacityDimension(0, 160).setCostPerDistance(1.1).build(); - VehicleImpl vehicle2_1 = VehicleImpl.Builder.newInstance("2_1").setStartLocation(Location.newInstance(40, 40)).setType(type2).build(); - vrpBuilder.addVehicle(vehicle2_1); - //1xtype3 - VehicleType type3 = VehicleTypeImpl.Builder.newInstance("type_3").addCapacityDimension(0, 300).setCostPerDistance(1.3).build(); - VehicleImpl vehicle3_1 = VehicleImpl.Builder.newInstance("3_1").setStartLocation(Location.newInstance(40, 40)).setType(type3).build(); - vrpBuilder.addVehicle(vehicle3_1); - - //add penaltyVehicles to allow invalid solutions temporarily + + + public static void main(String[] args) { + + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + + //add customers + vrpBuilder.addJob(Service.Builder.newInstance("1").addSizeDimension(0, 18).setLocation(Location.newInstance(22, 22)).build()); + vrpBuilder.addJob(Service.Builder.newInstance("2").addSizeDimension(0, 26).setLocation(Location.newInstance(36, 26)).build()); + vrpBuilder.addJob(Service.Builder.newInstance("3").addSizeDimension(0, 11).setLocation(Location.newInstance(21, 45)).build()); + vrpBuilder.addJob(Service.Builder.newInstance("4").addSizeDimension(0, 30).setLocation(Location.newInstance(45, 35)).build()); + vrpBuilder.addJob(Service.Builder.newInstance("5").addSizeDimension(0, 21).setLocation(Location.newInstance(55, 20)).build()); + vrpBuilder.addJob(Service.Builder.newInstance("6").addSizeDimension(0, 19).setLocation(Location.newInstance(33, 34)).build()); + vrpBuilder.addJob(Service.Builder.newInstance("7").addSizeDimension(0, 15).setLocation(Location.newInstance(50, 50)).build()); + vrpBuilder.addJob(Service.Builder.newInstance("8").addSizeDimension(0, 16).setLocation(Location.newInstance(55, 45)).build()); + vrpBuilder.addJob(Service.Builder.newInstance("9").addSizeDimension(0, 29).setLocation(Location.newInstance(26, 59)).build()); + vrpBuilder.addJob(Service.Builder.newInstance("10").addSizeDimension(0, 26).setLocation(Location.newInstance(40, 66)).build()); + vrpBuilder.addJob(Service.Builder.newInstance("11").addSizeDimension(0, 37).setLocation(Location.newInstance(55, 56)).build()); + vrpBuilder.addJob(Service.Builder.newInstance("12").addSizeDimension(0, 16).setLocation(Location.newInstance(35, 51)).build()); + vrpBuilder.addJob(Service.Builder.newInstance("13").addSizeDimension(0, 12).setLocation(Location.newInstance(62, 35)).build()); + vrpBuilder.addJob(Service.Builder.newInstance("14").addSizeDimension(0, 31).setLocation(Location.newInstance(62, 57)).build()); + vrpBuilder.addJob(Service.Builder.newInstance("15").addSizeDimension(0, 8).setLocation(Location.newInstance(62, 24)).build()); + vrpBuilder.addJob(Service.Builder.newInstance("16").addSizeDimension(0, 19).setLocation(Location.newInstance(21, 36)).build()); + vrpBuilder.addJob(Service.Builder.newInstance("17").addSizeDimension(0, 20).setLocation(Location.newInstance(33, 44)).build()); + vrpBuilder.addJob(Service.Builder.newInstance("18").addSizeDimension(0, 13).setLocation(Location.newInstance(9, 56)).build()); + vrpBuilder.addJob(Service.Builder.newInstance("19").addSizeDimension(0, 15).setLocation(Location.newInstance(62, 48)).build()); + vrpBuilder.addJob(Service.Builder.newInstance("20").addSizeDimension(0, 22).setLocation(Location.newInstance(66, 14)).build()); + + + //add vehicle - finite fleet + //2xtype1 + VehicleType type1 = VehicleTypeImpl.Builder.newInstance("type_1").addCapacityDimension(0, 120).setCostPerDistance(1.0).build(); + VehicleImpl vehicle1_1 = VehicleImpl.Builder.newInstance("1_1").setStartLocation(Location.newInstance(40, 40)).setType(type1).build(); + vrpBuilder.addVehicle(vehicle1_1); + VehicleImpl vehicle1_2 = VehicleImpl.Builder.newInstance("1_2").setStartLocation(Location.newInstance(40, 40)).setType(type1).build(); + vrpBuilder.addVehicle(vehicle1_2); + //1xtype2 + VehicleType type2 = VehicleTypeImpl.Builder.newInstance("type_2").addCapacityDimension(0, 160).setCostPerDistance(1.1).build(); + VehicleImpl vehicle2_1 = VehicleImpl.Builder.newInstance("2_1").setStartLocation(Location.newInstance(40, 40)).setType(type2).build(); + vrpBuilder.addVehicle(vehicle2_1); + //1xtype3 + VehicleType type3 = VehicleTypeImpl.Builder.newInstance("type_3").addCapacityDimension(0, 300).setCostPerDistance(1.3).build(); + VehicleImpl vehicle3_1 = VehicleImpl.Builder.newInstance("3_1").setStartLocation(Location.newInstance(40, 40)).setType(type3).build(); + vrpBuilder.addVehicle(vehicle3_1); + + //add penaltyVehicles to allow invalid solutions temporarily // vrpBuilder.addPenaltyVehicles(5, 1000); - - //set fleetsize finite - vrpBuilder.setFleetSize(FleetSize.FINITE); - - //build problem - VehicleRoutingProblem vrp = vrpBuilder.build(); - - VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "input/algorithmConfigWithSchrimpfAcceptance.xml"); - Collection solutions = vra.searchSolutions(); - - VehicleRoutingProblemSolution best = Solutions.bestOf(solutions); - - SolutionPrinter.print(vrp, best, SolutionPrinter.Print.VERBOSE); - - new GraphStreamViewer(vrp, best).setRenderDelay(100).display(); - - } + + //set fleetsize finite + vrpBuilder.setFleetSize(FleetSize.FINITE); + + //build problem + VehicleRoutingProblem vrp = vrpBuilder.build(); + + VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "input/algorithmConfigWithSchrimpfAcceptance.xml"); + Collection solutions = vra.searchSolutions(); + + VehicleRoutingProblemSolution best = Solutions.bestOf(solutions); + + SolutionPrinter.print(vrp, best, SolutionPrinter.Print.VERBOSE); + + new GraphStreamViewer(vrp, best).setRenderDelay(100).display(); + + } } diff --git a/jsprit-examples/src/main/java/jsprit/examples/JobAndActivityDependenciesExample.java b/jsprit-examples/src/main/java/jsprit/examples/JobAndActivityDependenciesExample.java index b0872790..9a7dab58 100644 --- a/jsprit-examples/src/main/java/jsprit/examples/JobAndActivityDependenciesExample.java +++ b/jsprit-examples/src/main/java/jsprit/examples/JobAndActivityDependenciesExample.java @@ -43,11 +43,10 @@ import java.util.Collection; /** * Illustrates dependencies between jobs. - * + *

* The hard requirement here is that three jobs with name "get key", "use key" and "deliver key" need to * be not only in loose sequence in one particular route but also one after another (without any other activities * between them). - * */ public class JobAndActivityDependenciesExample { @@ -78,19 +77,18 @@ public class JobAndActivityDependenciesExample { @Override public void visit(TourActivity activity) { - if(((TourActivity.JobActivity)activity).getJob().getName().equals("use key")) { + if (((TourActivity.JobActivity) activity).getJob().getName().equals("use key")) { stateManager.putProblemState(keyUsedStateId, VehicleRoute.class, route); - } - else if(((TourActivity.JobActivity)activity).getJob().getName().equals("get key")) { + } else if (((TourActivity.JobActivity) activity).getJob().getName().equals("get key")) { stateManager.putProblemState(keyPickedStateId, VehicleRoute.class, route); - } - else if(((TourActivity.JobActivity)activity).getJob().getName().equals("deliver key")) { + } else if (((TourActivity.JobActivity) activity).getJob().getName().equals("deliver key")) { stateManager.putProblemState(keyDeliveredStateId, VehicleRoute.class, route); } } @Override - public void finish() {} + public void finish() { + } } static class GetUseAndDeliverHardRouteContraint implements HardRouteConstraint { @@ -112,20 +110,20 @@ public class JobAndActivityDependenciesExample { @Override public boolean fulfilled(JobInsertionContext iFacts) { - if(iFacts.getJob().getName().equals("get key") || iFacts.getJob().getName().equals("use key") - || iFacts.getJob().getName().equals("deliver key")){ + if (iFacts.getJob().getName().equals("get key") || iFacts.getJob().getName().equals("use key") + || iFacts.getJob().getName().equals("deliver key")) { VehicleRoute routeOfPickupKey = stateManager.getProblemState(keyPickedStateId, VehicleRoute.class); VehicleRoute routeOfUseKey = stateManager.getProblemState(keyUsedStateId, VehicleRoute.class); VehicleRoute routeOfDeliverKey = stateManager.getProblemState(keyDeliveredStateId, VehicleRoute.class); - if( routeOfPickupKey != null ){ - if( routeOfPickupKey != iFacts.getRoute() ) return false; + if (routeOfPickupKey != null) { + if (routeOfPickupKey != iFacts.getRoute()) return false; } - if( routeOfUseKey != null ){ - if( routeOfUseKey != iFacts.getRoute() ) return false; + if (routeOfUseKey != null) { + if (routeOfUseKey != iFacts.getRoute()) return false; } - if( routeOfDeliverKey != null ) { - if( routeOfDeliverKey != iFacts.getRoute() ) return false; + if (routeOfDeliverKey != null) { + if (routeOfDeliverKey != iFacts.getRoute()) return false; } } return true; @@ -157,50 +155,50 @@ public class JobAndActivityDependenciesExample { VehicleRoute routeOfUseKey = stateManager.getProblemState(keyUsedStateId, VehicleRoute.class); VehicleRoute routeOfDeliverKey = stateManager.getProblemState(keyDeliveredStateId, VehicleRoute.class); - if( !isPickupKey(newAct) && !isUseKey(newAct) && !isDeliverKey(newAct) ){ - if(isPickupKey(prevAct) && isUseKey(nextAct)) return ConstraintsStatus.NOT_FULFILLED; - if(isPickupKey(prevAct) && isDeliverKey(nextAct)) return ConstraintsStatus.NOT_FULFILLED; - if(isUseKey(prevAct) && isDeliverKey(nextAct)) return ConstraintsStatus.NOT_FULFILLED; + if (!isPickupKey(newAct) && !isUseKey(newAct) && !isDeliverKey(newAct)) { + if (isPickupKey(prevAct) && isUseKey(nextAct)) return ConstraintsStatus.NOT_FULFILLED; + if (isPickupKey(prevAct) && isDeliverKey(nextAct)) return ConstraintsStatus.NOT_FULFILLED; + if (isUseKey(prevAct) && isDeliverKey(nextAct)) return ConstraintsStatus.NOT_FULFILLED; } - if( isPickupKey(newAct) ) { - if ( routeOfUseKey != null){ - if ( !isUseKey(nextAct) ) return ConstraintsStatus.NOT_FULFILLED; + if (isPickupKey(newAct)) { + if (routeOfUseKey != null) { + if (!isUseKey(nextAct)) return ConstraintsStatus.NOT_FULFILLED; } - if ( routeOfDeliverKey != null ){ - if ( !isDeliverKey( nextAct )) return ConstraintsStatus.NOT_FULFILLED; + if (routeOfDeliverKey != null) { + if (!isDeliverKey(nextAct)) return ConstraintsStatus.NOT_FULFILLED; } return ConstraintsStatus.FULFILLED; } - if( isUseKey(newAct) ) { - if ( routeOfPickupKey != null ) { - if ( !isPickupKey(prevAct) ) return ConstraintsStatus.NOT_FULFILLED; + if (isUseKey(newAct)) { + if (routeOfPickupKey != null) { + if (!isPickupKey(prevAct)) return ConstraintsStatus.NOT_FULFILLED; } - if ( routeOfDeliverKey != null ) { - if ( !isDeliverKey(nextAct) ) return ConstraintsStatus.NOT_FULFILLED; + if (routeOfDeliverKey != null) { + if (!isDeliverKey(nextAct)) return ConstraintsStatus.NOT_FULFILLED; } return ConstraintsStatus.FULFILLED; } - if( isDeliverKey(newAct) ){ - if( routeOfUseKey != null ) { - if ( !isUseKey(prevAct) ) return ConstraintsStatus.NOT_FULFILLED; + if (isDeliverKey(newAct)) { + if (routeOfUseKey != null) { + if (!isUseKey(prevAct)) return ConstraintsStatus.NOT_FULFILLED; } } return ConstraintsStatus.FULFILLED; } private boolean isPickupKey(TourActivity act) { - if(!(act instanceof TourActivity.JobActivity)) return false; - return ((TourActivity.JobActivity)act).getJob().getName().equals("get key"); + if (!(act instanceof TourActivity.JobActivity)) return false; + return ((TourActivity.JobActivity) act).getJob().getName().equals("get key"); } private boolean isUseKey(TourActivity act) { - if(!(act instanceof TourActivity.JobActivity)) return false; - return ((TourActivity.JobActivity)act).getJob().getName().equals("use key"); + if (!(act instanceof TourActivity.JobActivity)) return false; + return ((TourActivity.JobActivity) act).getJob().getName().equals("use key"); } private boolean isDeliverKey(TourActivity act) { - if(!(act instanceof TourActivity.JobActivity)) return false; - return ((TourActivity.JobActivity)act).getJob().getName().equals("deliver key"); + if (!(act instanceof TourActivity.JobActivity)) return false; + return ((TourActivity.JobActivity) act).getJob().getName().equals("deliver key"); } @@ -209,54 +207,54 @@ public class JobAndActivityDependenciesExample { public static void main(String[] args) { VehicleImpl driver1 = VehicleImpl.Builder.newInstance("driver1") - .addSkill("driver1") - .setStartLocation(Location.newInstance(0, 0)).setReturnToDepot(false).build(); + .addSkill("driver1") + .setStartLocation(Location.newInstance(0, 0)).setReturnToDepot(false).build(); VehicleImpl driver3 = VehicleImpl.Builder.newInstance("driver3") - .addSkill("driver3") - .setStartLocation(Location.newInstance(-3, 5)).setReturnToDepot(true).build(); + .addSkill("driver3") + .setStartLocation(Location.newInstance(-3, 5)).setReturnToDepot(true).build(); Service s1 = Service.Builder.newInstance("s1") - .addRequiredSkill("driver1") - .setName("install new device") - .setLocation(Location.newInstance(2, 2)).build(); + .addRequiredSkill("driver1") + .setName("install new device") + .setLocation(Location.newInstance(2, 2)).build(); Service s2 = Service.Builder.newInstance("s2") - .addRequiredSkill("driver3") - .setName("deliver key") - .setLocation(Location.newInstance(2, 4)).build(); + .addRequiredSkill("driver3") + .setName("deliver key") + .setLocation(Location.newInstance(2, 4)).build(); Service s3 = Service.Builder.newInstance("s3") - .addRequiredSkill("driver1") - .setName("repair heater") - .setLocation(Location.newInstance(-2, 2)).build(); + .addRequiredSkill("driver1") + .setName("repair heater") + .setLocation(Location.newInstance(-2, 2)).build(); Service s4 = Service.Builder.newInstance("s4") - .addRequiredSkill("driver3") - .setName("get key") - .setLocation(Location.newInstance(-2.3, 4)).build(); + .addRequiredSkill("driver3") + .setName("get key") + .setLocation(Location.newInstance(-2.3, 4)).build(); Service s5 = Service.Builder.newInstance("s5") - .addRequiredSkill("driver1") - .setName("cleaning") - .setLocation(Location.newInstance(1, 5)).build(); + .addRequiredSkill("driver1") + .setName("cleaning") + .setLocation(Location.newInstance(1, 5)).build(); Service s6 = Service.Builder.newInstance("s6") - .addRequiredSkill("driver3") - .setName("use key") - .setLocation(Location.newInstance(-2, 3)).build(); + .addRequiredSkill("driver3") + .setName("use key") + .setLocation(Location.newInstance(-2, 3)).build(); Service s7 = Service.Builder.newInstance("s7") - .addRequiredSkill("driver3") - .setName("maintenance") - .setLocation(Location.newInstance(-1.7, 3.5)).build(); + .addRequiredSkill("driver3") + .setName("maintenance") + .setLocation(Location.newInstance(-1.7, 3.5)).build(); VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance().setFleetSize(VehicleRoutingProblem.FleetSize.FINITE) - .addJob(s1).addJob(s2).addJob(s3).addJob(s4).addJob(s5).addJob(s6).addJob(s7) - .addVehicle(driver1).addVehicle(driver3); + .addJob(s1).addJob(s2).addJob(s3).addJob(s4).addJob(s5).addJob(s6).addJob(s7) + .addVehicle(driver1).addVehicle(driver3); VehicleRoutingProblem vrp = vrpBuilder.build(); - VehicleRoutingAlgorithmBuilder vraBuilder = new VehicleRoutingAlgorithmBuilder(vrp,"input/algorithmConfig.xml"); + VehicleRoutingAlgorithmBuilder vraBuilder = new VehicleRoutingAlgorithmBuilder(vrp, "input/algorithmConfig.xml"); vraBuilder.addDefaultCostCalculators(); vraBuilder.addCoreConstraints(); @@ -264,13 +262,13 @@ public class JobAndActivityDependenciesExample { StateId keyPicked = stateManager.createStateId("key-picked"); StateId keyUsed = stateManager.createStateId("key-used"); StateId keyDelivered = stateManager.createStateId("key-delivered"); - stateManager.addStateUpdater(new KeyStatusUpdater(stateManager,keyPicked,keyUsed,keyDelivered)); + stateManager.addStateUpdater(new KeyStatusUpdater(stateManager, keyPicked, keyUsed, keyDelivered)); - ConstraintManager constraintManager = new ConstraintManager(vrp,stateManager); - constraintManager.addConstraint(new GetUseAndDeliverKeySimpleHardActivityConstraint(stateManager,keyPicked,keyUsed,keyDelivered), ConstraintManager.Priority.CRITICAL); - constraintManager.addConstraint(new GetUseAndDeliverHardRouteContraint(stateManager,keyPicked,keyUsed,keyDelivered)); + ConstraintManager constraintManager = new ConstraintManager(vrp, stateManager); + constraintManager.addConstraint(new GetUseAndDeliverKeySimpleHardActivityConstraint(stateManager, keyPicked, keyUsed, keyDelivered), ConstraintManager.Priority.CRITICAL); + constraintManager.addConstraint(new GetUseAndDeliverHardRouteContraint(stateManager, keyPicked, keyUsed, keyDelivered)); - vraBuilder.setStateAndConstraintManager(stateManager,constraintManager); + vraBuilder.setStateAndConstraintManager(stateManager, constraintManager); VehicleRoutingAlgorithm vra = vraBuilder.build(); vra.setMaxIterations(100); diff --git a/jsprit-examples/src/main/java/jsprit/examples/MultipleDepotExample.java b/jsprit-examples/src/main/java/jsprit/examples/MultipleDepotExample.java index daca79ce..88cffa3c 100644 --- a/jsprit-examples/src/main/java/jsprit/examples/MultipleDepotExample.java +++ b/jsprit-examples/src/main/java/jsprit/examples/MultipleDepotExample.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.examples; @@ -41,74 +41,74 @@ import java.util.Collection; public class MultipleDepotExample { - public static void main(String[] args) { - /* - * some preparation - create output folder + public static void main(String[] args) { + /* + * some preparation - create output folder */ - Examples.createOutputFolder(); - - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - /* - * Read cordeau-instance p01, BUT only its services without any vehicles + Examples.createOutputFolder(); + + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + /* + * Read cordeau-instance p01, BUT only its services without any vehicles */ - new VrpXMLReader(vrpBuilder).read("input/vrp_cordeau_01.xml"); - + new VrpXMLReader(vrpBuilder).read("input/vrp_cordeau_01.xml"); + /* - * add vehicles with its depots + * add vehicles with its depots * 4 depots: * (20,20) * (30,40) * (50,30) * (60,50) - * + * * each with 4 vehicles each with a capacity of 80 */ - int nuOfVehicles = 4; - int capacity = 80; - Coordinate firstDepotCoord = Coordinate.newInstance(20, 20); - Coordinate second = Coordinate.newInstance(30, 40); - Coordinate third = Coordinate.newInstance(50, 30); - Coordinate fourth = Coordinate.newInstance(60, 50); - - int depotCounter = 1; - for(Coordinate depotCoord : Arrays.asList(firstDepotCoord,second,third,fourth)){ - for(int i=0;i solutions = vra.searchSolutions(); - - SolutionPrinter.print(Solutions.bestOf(solutions)); - - new Plotter(vrp, Solutions.bestOf(solutions)).plot("output/p01_solution.png", "p01"); - - new GraphStreamViewer(vrp, Solutions.bestOf(solutions)).setRenderDelay(100).display(); - - } + VehicleRoutingAlgorithm vra = Jsprit.Builder.newInstance(vrp).setProperty(Jsprit.Parameter.THREADS, "5").buildAlgorithm(); + vra.getAlgorithmListeners().addListener(new StopWatch(), Priority.HIGH); + vra.getAlgorithmListeners().addListener(new AlgorithmSearchProgressChartListener("output/progress.png")); + Collection solutions = vra.searchSolutions(); + + SolutionPrinter.print(Solutions.bestOf(solutions)); + + new Plotter(vrp, Solutions.bestOf(solutions)).plot("output/p01_solution.png", "p01"); + + new GraphStreamViewer(vrp, Solutions.bestOf(solutions)).setRenderDelay(100).display(); + + } } diff --git a/jsprit-examples/src/main/java/jsprit/examples/MultipleDepotExample2.java b/jsprit-examples/src/main/java/jsprit/examples/MultipleDepotExample2.java index d3e14ed9..c737ed1a 100644 --- a/jsprit-examples/src/main/java/jsprit/examples/MultipleDepotExample2.java +++ b/jsprit-examples/src/main/java/jsprit/examples/MultipleDepotExample2.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.examples; @@ -43,78 +43,78 @@ import java.util.Collection; public class MultipleDepotExample2 { - public static void main(String[] args) { - /* - * some preparation - create output folder + public static void main(String[] args) { + /* + * some preparation - create output folder */ - Examples.createOutputFolder(); - - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - /* - * Read cordeau-instance p01, BUT only its services without any vehicles + Examples.createOutputFolder(); + + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + /* + * Read cordeau-instance p01, BUT only its services without any vehicles */ - new CordeauReader(vrpBuilder).read("input/p08"); - + new CordeauReader(vrpBuilder).read("input/p08"); + /* - * add vehicles with its depots + * add vehicles with its depots * 2 depots: * (-33,33) * (33,-33) - * + * * each with 14 vehicles each with a capacity of 500 and a maximum duration of 310 */ - int nuOfVehicles = 13; - int capacity = 500; - double maxDuration = 310; - Coordinate firstDepotCoord = Coordinate.newInstance(-33, 33); - Coordinate second = Coordinate.newInstance(33, -33); - - int depotCounter = 1; - for(Coordinate depotCoord : Arrays.asList(firstDepotCoord,second)){ - for(int i=0;i solutions = vra.searchSolutions(); - - SolutionPrinter.print(vrp, Solutions.bestOf(solutions), jsprit.core.reporting.SolutionPrinter.Print.VERBOSE); + VehicleRoutingAlgorithm vra = Jsprit.Builder.newInstance(vrp).setProperty(Jsprit.Parameter.THREADS, "5").buildAlgorithm(); + vra.setMaxIterations(2000); + vra.getAlgorithmListeners().addListener(new StopWatch(), Priority.HIGH); + vra.getAlgorithmListeners().addListener(new AlgorithmSearchProgressChartListener("output/progress.png")); + Collection solutions = vra.searchSolutions(); - new Plotter(vrp, Solutions.bestOf(solutions)).plot("output/p08_solution.png", "p08"); - - new GraphStreamViewer(vrp,Solutions.bestOf(solutions)).setRenderDelay(50).display(); - } + SolutionPrinter.print(vrp, Solutions.bestOf(solutions), jsprit.core.reporting.SolutionPrinter.Print.VERBOSE); + + new Plotter(vrp, Solutions.bestOf(solutions)).plot("output/p08_solution.png", "p08"); + + new GraphStreamViewer(vrp, Solutions.bestOf(solutions)).setRenderDelay(50).display(); + } } diff --git a/jsprit-examples/src/main/java/jsprit/examples/MultipleDepotWithInitialRoutesExample.java b/jsprit-examples/src/main/java/jsprit/examples/MultipleDepotWithInitialRoutesExample.java index 05b6acbe..c824a0ea 100644 --- a/jsprit-examples/src/main/java/jsprit/examples/MultipleDepotWithInitialRoutesExample.java +++ b/jsprit-examples/src/main/java/jsprit/examples/MultipleDepotWithInitialRoutesExample.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.examples; @@ -38,40 +38,40 @@ import java.util.Collection; public class MultipleDepotWithInitialRoutesExample { - public static void main(String[] args) { - /* - * some preparation - create output folder + public static void main(String[] args) { + /* + * some preparation - create output folder */ - Examples.createOutputFolder(); - - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - /* - * Read cordeau-instance p01 + Examples.createOutputFolder(); + + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + /* + * Read cordeau-instance p01 */ - new VrpXMLReader(vrpBuilder).read("input/cordeau01.xml"); - + new VrpXMLReader(vrpBuilder).read("input/cordeau01.xml"); + /* - * Add initial route with 1_4_vehicle and services 44, 26 + * Add initial route with 1_4_vehicle and services 44, 26 */ - VehicleRoute initialRoute = VehicleRoute.Builder.newInstance(getVehicle("1_4_vehicle",vrpBuilder)).addService(getService("44",vrpBuilder)) - .addService(getService("26",vrpBuilder)).build(); - vrpBuilder.addInitialVehicleRoute(initialRoute); - + VehicleRoute initialRoute = VehicleRoute.Builder.newInstance(getVehicle("1_4_vehicle", vrpBuilder)).addService(getService("44", vrpBuilder)) + .addService(getService("26", vrpBuilder)).build(); + vrpBuilder.addInitialVehicleRoute(initialRoute); + /* - * build the problem + * build the problem */ - VehicleRoutingProblem vrp = vrpBuilder.build(); - /* - * since job (service) 26 and 44 are already planned in initial route and thus static AND sequence is fixed they + VehicleRoutingProblem vrp = vrpBuilder.build(); + /* + * since job (service) 26 and 44 are already planned in initial route and thus static AND sequence is fixed they * should not be in jobMap anymore (only variable jobs are in jobMap) */ - assert !vrp.getJobs().containsKey("26") : "strange. service 26 should not be part of the problem"; - assert !vrp.getJobs().containsKey("44") : "strange. service 44 should not be part of the problem"; - + assert !vrp.getJobs().containsKey("26") : "strange. service 26 should not be part of the problem"; + 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"); + new Plotter(vrp).setLabel(Label.ID).plot("output/cordeau01_problem_withInitialRoute.png", "c"); /* * solve the problem @@ -79,30 +79,30 @@ public class MultipleDepotWithInitialRoutesExample { // VehicleRoutingAlgorithm vra = Jsprit.Builder.newInstance(vrp) // .setProperty(Jsprit.Parameter.ITERATIONS,"10000").buildAlgorithm(); - VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "input/algorithmConfig_noVehicleSwitch.xml"); - Collection solutions = vra.searchSolutions(); - - SolutionPrinter.print(Solutions.bestOf(solutions)); - - new Plotter(vrp, Solutions.bestOf(solutions)).setLabel(Label.ID).plot("output/cordeau01_solution_withInitialRoute.png", "p01"); - - - } + VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "input/algorithmConfig_noVehicleSwitch.xml"); + Collection solutions = vra.searchSolutions(); - private static Service getService(String serviceId, Builder vrpBuilder) { - for(Job j : vrpBuilder.getAddedJobs()){ - if(j.getId().equals(serviceId)){ - return (Service)j; - } - } - return null; - } + SolutionPrinter.print(Solutions.bestOf(solutions)); - private static Vehicle getVehicle(String vehicleId, Builder vrpBuilder) { - for(Vehicle v : vrpBuilder.getAddedVehicles()){ - if(v.getId().equals(vehicleId)) return v; - } - return null; - } + new Plotter(vrp, Solutions.bestOf(solutions)).setLabel(Label.ID).plot("output/cordeau01_solution_withInitialRoute.png", "p01"); + + + } + + private static Service getService(String serviceId, Builder vrpBuilder) { + for (Job j : vrpBuilder.getAddedJobs()) { + if (j.getId().equals(serviceId)) { + return (Service) j; + } + } + return null; + } + + private static Vehicle getVehicle(String vehicleId, Builder vrpBuilder) { + for (Vehicle v : vrpBuilder.getAddedVehicles()) { + if (v.getId().equals(vehicleId)) return v; + } + return null; + } } diff --git a/jsprit-examples/src/main/java/jsprit/examples/MultipleProductsWithLoadConstraintExample.java b/jsprit-examples/src/main/java/jsprit/examples/MultipleProductsWithLoadConstraintExample.java index 595464d5..34c0d057 100644 --- a/jsprit-examples/src/main/java/jsprit/examples/MultipleProductsWithLoadConstraintExample.java +++ b/jsprit-examples/src/main/java/jsprit/examples/MultipleProductsWithLoadConstraintExample.java @@ -47,12 +47,12 @@ import java.util.Collection; /** * Illustrates a VRP with multiple products. - * + *

* It has the hard requirements that no two different products can be transported in the same vehicle at the same time. * This might be important if products require different temperatures. For example, if a vehicle transports * apples then no bananas can be loaded (and the other way around). Once all apples have been unloaded, bananas can * be loaded. - * + *

* See also the discussion here: https://groups.google.com/forum/#!topic/jsprit-mailing-list/2JQqY4loC0U */ public class MultipleProductsWithLoadConstraintExample { @@ -61,21 +61,22 @@ public class MultipleProductsWithLoadConstraintExample { static final int APPLES_DIMENSION_INDEX = 1; -// static class BananasFirst implements HardActivityStateLevelConstraint { //v1.3.1 + // static class BananasFirst implements HardActivityStateLevelConstraint { //v1.3.1 static class BananasFirst implements HardActivityConstraint { @Override public ConstraintsStatus fulfilled(JobInsertionContext jobInsertionContext, TourActivity prevActivity, TourActivity newActivity, TourActivity nextActivity, double departureTimeAtPrevActivity) { - if(isBananaPickup(newActivity) && isApplePickup(prevActivity)) return ConstraintsStatus.NOT_FULFILLED_BREAK; - if(isBananaPickup(nextActivity) && isApplePickup(newActivity)) return ConstraintsStatus.NOT_FULFILLED; + if (isBananaPickup(newActivity) && isApplePickup(prevActivity)) + return ConstraintsStatus.NOT_FULFILLED_BREAK; + if (isBananaPickup(nextActivity) && isApplePickup(newActivity)) return ConstraintsStatus.NOT_FULFILLED; return ConstraintsStatus.FULFILLED; } - private boolean isApplePickup(TourActivity act){ + private boolean isApplePickup(TourActivity act) { return act.getSize().get(APPLES_DIMENSION_INDEX) > 0; } - private boolean isBananaPickup(TourActivity act){ + private boolean isBananaPickup(TourActivity act) { return act.getSize().get(BANANAS_DIMENSION_INDEX) > 0; } } @@ -93,21 +94,21 @@ public class MultipleProductsWithLoadConstraintExample { public ConstraintsStatus fulfilled(JobInsertionContext jobInsertionContext, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double departureTimeAtPrevAct) { Capacity loadAtPrevAct = getLoadAtPreviousAct(prevAct); - if( isPickup(newAct) ){ - if( ( isApplePickup(newAct) && hasBananasInVehicle(loadAtPrevAct) ) || - ( isBananaPickup(newAct) && hasApplesInVehicle(loadAtPrevAct) ) ){ + if (isPickup(newAct)) { + if ((isApplePickup(newAct) && hasBananasInVehicle(loadAtPrevAct)) || + (isBananaPickup(newAct) && hasApplesInVehicle(loadAtPrevAct))) { return ConstraintsStatus.NOT_FULFILLED; } - if( ( isApplePickup(newAct) && isBananaPickup(nextAct) ) || - ( isBananaPickup(newAct) && isApplePickup(nextAct) ) ){ + if ((isApplePickup(newAct) && isBananaPickup(nextAct)) || + (isBananaPickup(newAct) && isApplePickup(nextAct))) { return ConstraintsStatus.NOT_FULFILLED; } return ConstraintsStatus.FULFILLED; } - if( isDelivery(newAct) ){ - if( ( isAppleDelivery(newAct) && hasBananasInVehicle(loadAtPrevAct) ) || - ( isBananaDelivery(newAct) && hasApplesInVehicle(loadAtPrevAct) ) ){ + if (isDelivery(newAct)) { + if ((isAppleDelivery(newAct) && hasBananasInVehicle(loadAtPrevAct)) || + (isBananaDelivery(newAct) && hasApplesInVehicle(loadAtPrevAct))) { return ConstraintsStatus.NOT_FULFILLED_BREAK; // if so constraint is broken forever -> break here } return ConstraintsStatus.FULFILLED; @@ -119,23 +120,23 @@ public class MultipleProductsWithLoadConstraintExample { return loadAtPrevAct.get(APPLES_DIMENSION_INDEX) > 0; } - private boolean hasBananasInVehicle(Capacity loadAtPrevAct){ + private boolean hasBananasInVehicle(Capacity loadAtPrevAct) { return loadAtPrevAct.get(BANANAS_DIMENSION_INDEX) > 0; } - private boolean isBananaPickup(TourActivity act){ + private boolean isBananaPickup(TourActivity act) { return act.getSize().get(BANANAS_DIMENSION_INDEX) > 0; } - private boolean isBananaDelivery(TourActivity act){ + private boolean isBananaDelivery(TourActivity act) { return act.getSize().get(BANANAS_DIMENSION_INDEX) < 0; } - private boolean isApplePickup(TourActivity act){ + private boolean isApplePickup(TourActivity act) { return act.getSize().get(APPLES_DIMENSION_INDEX) > 0; } - private boolean isAppleDelivery(TourActivity act){ + private boolean isAppleDelivery(TourActivity act) { return act.getSize().get(APPLES_DIMENSION_INDEX) < 0; } @@ -150,47 +151,46 @@ public class MultipleProductsWithLoadConstraintExample { private Capacity getLoadAtPreviousAct(TourActivity prevAct) { // Capacity prevLoad = stateManager.getActivityState(prevAct, StateFactory.LOAD, Capacity.class); //v1.3.1 Capacity prevLoad = stateManager.getActivityState(prevAct, InternalStates.LOAD, Capacity.class); //1.3.2-SNAPSHOT & upcoming release v1.4 - if(prevLoad != null) return prevLoad; + if (prevLoad != null) return prevLoad; else return Capacity.Builder.newInstance().build(); } } - public static void main(String[] args) { - VehicleType type = VehicleTypeImpl.Builder.newInstance("type").addCapacityDimension(BANANAS_DIMENSION_INDEX,10) - .addCapacityDimension(APPLES_DIMENSION_INDEX, 20).build(); + VehicleType type = VehicleTypeImpl.Builder.newInstance("type").addCapacityDimension(BANANAS_DIMENSION_INDEX, 10) + .addCapacityDimension(APPLES_DIMENSION_INDEX, 20).build(); VehicleImpl vehicle = VehicleImpl.Builder.newInstance("vehicle").setStartLocation(loc(Coordinate.newInstance(0, 0))) - .setType(type).build(); + .setType(type).build(); - Shipment bananas = Shipment.Builder.newInstance("bananas_1").addSizeDimension(BANANAS_DIMENSION_INDEX,1) - .setPickupLocation(loc(Coordinate.newInstance(1, 8))).setDeliveryLocation(loc(Coordinate.newInstance(10, 8))).build(); + Shipment bananas = Shipment.Builder.newInstance("bananas_1").addSizeDimension(BANANAS_DIMENSION_INDEX, 1) + .setPickupLocation(loc(Coordinate.newInstance(1, 8))).setDeliveryLocation(loc(Coordinate.newInstance(10, 8))).build(); - Shipment bananas_2 = Shipment.Builder.newInstance("bananas_2").addSizeDimension(BANANAS_DIMENSION_INDEX,1) - .setPickupLocation(loc(Coordinate.newInstance(2, 8))).setDeliveryLocation(loc(Coordinate.newInstance(11, 8))).build(); + Shipment bananas_2 = Shipment.Builder.newInstance("bananas_2").addSizeDimension(BANANAS_DIMENSION_INDEX, 1) + .setPickupLocation(loc(Coordinate.newInstance(2, 8))).setDeliveryLocation(loc(Coordinate.newInstance(11, 8))).build(); - Shipment bananas_3 = Shipment.Builder.newInstance("bananas_3").addSizeDimension(BANANAS_DIMENSION_INDEX,1) - .setPickupLocation(loc(Coordinate.newInstance(3, 8))).setDeliveryLocation(loc(Coordinate.newInstance(12, 8))).build(); + Shipment bananas_3 = Shipment.Builder.newInstance("bananas_3").addSizeDimension(BANANAS_DIMENSION_INDEX, 1) + .setPickupLocation(loc(Coordinate.newInstance(3, 8))).setDeliveryLocation(loc(Coordinate.newInstance(12, 8))).build(); - Shipment apples = Shipment.Builder.newInstance("apples_1").addSizeDimension(APPLES_DIMENSION_INDEX,1) - .setPickupLocation(loc(Coordinate.newInstance(1, 6))).setDeliveryLocation(loc(Coordinate.newInstance(10, 12))).build(); + Shipment apples = Shipment.Builder.newInstance("apples_1").addSizeDimension(APPLES_DIMENSION_INDEX, 1) + .setPickupLocation(loc(Coordinate.newInstance(1, 6))).setDeliveryLocation(loc(Coordinate.newInstance(10, 12))).build(); - Shipment apples_2 = Shipment.Builder.newInstance("apples_2").addSizeDimension(APPLES_DIMENSION_INDEX,1) - .setPickupLocation(loc(Coordinate.newInstance(1, 5))).setDeliveryLocation(loc(Coordinate.newInstance(10, 11))).build(); + Shipment apples_2 = Shipment.Builder.newInstance("apples_2").addSizeDimension(APPLES_DIMENSION_INDEX, 1) + .setPickupLocation(loc(Coordinate.newInstance(1, 5))).setDeliveryLocation(loc(Coordinate.newInstance(10, 11))).build(); VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().setFleetSize(VehicleRoutingProblem.FleetSize.INFINITE) - .addVehicle(vehicle) - .addJob(bananas).addJob(apples).addJob(bananas_2).addJob(bananas_3).addJob(apples_2).build(); + .addVehicle(vehicle) + .addJob(bananas).addJob(apples).addJob(bananas_2).addJob(bananas_3).addJob(apples_2).build(); StateManager stateManager = new StateManager(vrp); - ConstraintManager constraintManager = new ConstraintManager(vrp,stateManager); + ConstraintManager constraintManager = new ConstraintManager(vrp, stateManager); constraintManager.addConstraint(new NoBananasANDApplesConstraint(stateManager), ConstraintManager.Priority.CRITICAL); // constraintManager.addConstraint(new BananasFirst(),ConstraintManager.Priority.CRITICAL); - VehicleRoutingAlgorithm vra = Jsprit.Builder.newInstance(vrp).setStateAndConstraintManager(stateManager,constraintManager) - .buildAlgorithm(); + VehicleRoutingAlgorithm vra = Jsprit.Builder.newInstance(vrp).setStateAndConstraintManager(stateManager, constraintManager) + .buildAlgorithm(); Collection solutions = vra.searchSolutions(); diff --git a/jsprit-examples/src/main/java/jsprit/examples/PickupAndDeliveryExample.java b/jsprit-examples/src/main/java/jsprit/examples/PickupAndDeliveryExample.java index fbb9230d..5362b692 100644 --- a/jsprit-examples/src/main/java/jsprit/examples/PickupAndDeliveryExample.java +++ b/jsprit-examples/src/main/java/jsprit/examples/PickupAndDeliveryExample.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.examples; @@ -34,74 +34,74 @@ import java.util.Collection; public class PickupAndDeliveryExample { - - public static void main(String[] args) { - + + public static void main(String[] args) { + /* - * some preparation - create output folder + * some preparation - create output folder */ - Examples.createOutputFolder(); - + Examples.createOutputFolder(); + /* - * Build the problem. - * + * Build the problem. + * * But define a problem-builder first. */ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + /* - * A solomonReader reads solomon-instance files, and stores the required information in the builder. + * A solomonReader reads solomon-instance files, and stores the required information in the builder. */ - new VrpXMLReader(vrpBuilder).read("input/pickups_and_deliveries_solomon_r101_withoutTWs.xml"); - + new VrpXMLReader(vrpBuilder).read("input/pickups_and_deliveries_solomon_r101_withoutTWs.xml"); + /* - * Finally, the problem can be built. By default, transportCosts are crowFlyDistances (as usually used for vrp-instances). + * Finally, the problem can be built. By default, transportCosts are crowFlyDistances (as usually used for vrp-instances). */ - - final VehicleRoutingProblem vrp = vrpBuilder.build(); - - new Plotter(vrp).plot("output/pd_solomon_r101.png", "pd_r101"); - - + + final VehicleRoutingProblem vrp = vrpBuilder.build(); + + new Plotter(vrp).plot("output/pd_solomon_r101.png", "pd_r101"); + + /* - * 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. */ // VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp); - VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "input/algorithmConfig_solomon.xml"); - vra.getAlgorithmListeners().addListener(new AlgorithmSearchProgressChartListener("output/sol_progress.png")); - /* - * Solve the problem. - * + VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "input/algorithmConfig_solomon.xml"); + vra.getAlgorithmListeners().addListener(new AlgorithmSearchProgressChartListener("output/sol_progress.png")); + /* + * Solve the problem. + * * */ - Collection solutions = vra.searchSolutions(); - + Collection solutions = vra.searchSolutions(); + /* - * Retrieve best solution. + * Retrieve best solution. */ - VehicleRoutingProblemSolution solution = new SelectBest().selectSolution(solutions); - + VehicleRoutingProblemSolution solution = new SelectBest().selectSolution(solutions); + /* * print solution */ - SolutionPrinter.print(solution); - + SolutionPrinter.print(solution); + /* - * Plot solution. + * Plot solution. */ // SolutionPlotter.plotSolutionAsPNG(vrp, solution, "output/pd_solomon_r101_solution.png","pd_r101"); - Plotter plotter = new Plotter(vrp, solution); - plotter.setLabel(Label.SIZE); - plotter.plot("output/pd_solomon_r101_solution.png","pd_r101"); + Plotter plotter = new Plotter(vrp, solution); + plotter.setLabel(Label.SIZE); + plotter.plot("output/pd_solomon_r101_solution.png", "pd_r101"); //some stats - SolutionAnalyser analyser = new SolutionAnalyser(vrp,solution,new SolutionAnalyser.DistanceCalculator() { + SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new SolutionAnalyser.DistanceCalculator() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); diff --git a/jsprit-examples/src/main/java/jsprit/examples/PickupAndDeliveryExample2.java b/jsprit-examples/src/main/java/jsprit/examples/PickupAndDeliveryExample2.java index b3c4adbe..a86054fd 100644 --- a/jsprit-examples/src/main/java/jsprit/examples/PickupAndDeliveryExample2.java +++ b/jsprit-examples/src/main/java/jsprit/examples/PickupAndDeliveryExample2.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.examples; @@ -33,71 +33,71 @@ import java.util.Collection; public class PickupAndDeliveryExample2 { - - public static void main(String[] args) { + + public static void main(String[] args) { /* - * some preparation - create output folder + * some preparation - create output folder */ - Examples.createOutputFolder(); - + Examples.createOutputFolder(); + /* - * Build the problem. - * + * Build the problem. + * * But define a problem-builder first. */ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + /* - * A solomonReader reads solomon-instance files, and stores the required information in the builder. + * A solomonReader reads solomon-instance files, and stores the required information in the builder. */ - new VrpXMLReader(vrpBuilder).read("input/pd_christophides_vrpnc1_vcap50.xml"); - + new VrpXMLReader(vrpBuilder).read("input/pd_christophides_vrpnc1_vcap50.xml"); + /* - * Finally, the problem can be built. By default, transportCosts are crowFlyDistances (as usually used for vrp-instances). + * Finally, the problem can be built. By default, transportCosts are crowFlyDistances (as usually used for vrp-instances). */ - - VehicleRoutingProblem vrp = vrpBuilder.build(); - - new Plotter(vrp).plot("output/pd_christophides_vrpnc1.png", "pd_vrpnc1"); - - + + VehicleRoutingProblem vrp = vrpBuilder.build(); + + new Plotter(vrp).plot("output/pd_christophides_vrpnc1.png", "pd_vrpnc1"); + + /* - * 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. */ // VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp); - VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "input/algorithmConfig_solomon.xml"); - vra.getAlgorithmListeners().addListener(new AlgorithmSearchProgressChartListener("output/sol_progress.png")); - /* - * Solve the problem. - * + VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "input/algorithmConfig_solomon.xml"); + vra.getAlgorithmListeners().addListener(new AlgorithmSearchProgressChartListener("output/sol_progress.png")); + /* + * Solve the problem. + * * */ - Collection solutions = vra.searchSolutions(); - + Collection solutions = vra.searchSolutions(); + /* - * Retrieve best solution. + * Retrieve best solution. */ - VehicleRoutingProblemSolution solution = new SelectBest().selectSolution(solutions); - + VehicleRoutingProblemSolution solution = new SelectBest().selectSolution(solutions); + /* - * print solution + * print solution */ - SolutionPrinter.print(solution); - + SolutionPrinter.print(solution); + /* - * Plot solution. + * Plot solution. */ // SolutionPlotter.plotSolutionAsPNG(vrp, solution, "output/pd_solomon_r101_solution.png","pd_r101"); - Plotter plotter = new Plotter(vrp, solution); - plotter.setLabel(Label.SIZE); - plotter.plot("output/pd_christophides_vrpnc1_solution.png","pd_vrpnc1"); - - - new GraphStreamViewer(vrp, solution).setRenderDelay(200).display(); - - } + Plotter plotter = new Plotter(vrp, solution); + plotter.setLabel(Label.SIZE); + plotter.plot("output/pd_christophides_vrpnc1_solution.png", "pd_vrpnc1"); + + + new GraphStreamViewer(vrp, solution).setRenderDelay(200).display(); + + } } diff --git a/jsprit-examples/src/main/java/jsprit/examples/PickupAndDeliveryOpenExample.java b/jsprit-examples/src/main/java/jsprit/examples/PickupAndDeliveryOpenExample.java index e6eead1c..aa0c8328 100644 --- a/jsprit-examples/src/main/java/jsprit/examples/PickupAndDeliveryOpenExample.java +++ b/jsprit-examples/src/main/java/jsprit/examples/PickupAndDeliveryOpenExample.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.examples; @@ -32,69 +32,68 @@ import java.util.Collection; public class PickupAndDeliveryOpenExample { - - public static void main(String[] args) { - + + public static void main(String[] args) { + /* - * some preparation - create output folder + * some preparation - create output folder */ - Examples.createOutputFolder(); - + Examples.createOutputFolder(); + /* - * Build the problem. - * + * Build the problem. + * * But define a problem-builder first. */ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + /* - * A solomonReader reads solomon-instance files, and stores the required information in the builder. + * A solomonReader reads solomon-instance files, and stores the required information in the builder. */ - new VrpXMLReader(vrpBuilder).read("input/pickups_and_deliveries_solomon_r101_withoutTWs_open.xml"); - + new VrpXMLReader(vrpBuilder).read("input/pickups_and_deliveries_solomon_r101_withoutTWs_open.xml"); + /* - * Finally, the problem can be built. By default, transportCosts are crowFlyDistances (as usually used for vrp-instances). + * Finally, the problem can be built. By default, transportCosts are crowFlyDistances (as usually used for vrp-instances). */ - - VehicleRoutingProblem vrp = vrpBuilder.build(); - + + VehicleRoutingProblem vrp = vrpBuilder.build(); + // SolutionPlotter.plotVrpAsPNG(vrp, "output/pd_solomon_r101_o.png", "pd_r101"); - + /* - * 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. */ // VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp); - VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "input/algorithmConfig_open.xml"); - vra.getAlgorithmListeners().addListener(new AlgorithmSearchProgressChartListener("output/sol_progress.png")); - /* - * Solve the problem. - * + VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "input/algorithmConfig_open.xml"); + vra.getAlgorithmListeners().addListener(new AlgorithmSearchProgressChartListener("output/sol_progress.png")); + /* + * Solve the problem. + * * */ - Collection solutions = vra.searchSolutions(); - + Collection solutions = vra.searchSolutions(); + /* - * Retrieve best solution. + * Retrieve best solution. */ - VehicleRoutingProblemSolution solution = new SelectBest().selectSolution(solutions); - + VehicleRoutingProblemSolution solution = new SelectBest().selectSolution(solutions); + /* * print solution */ - SolutionPrinter.print(solution); - + SolutionPrinter.print(solution); + /* - * Plot solution. + * Plot solution. */ // SolutionPlotter.plotSolutionAsPNG(vrp, solution, "output/pd_solomon_r101_solution.png","pd_r101"); - Plotter plotter = new Plotter(vrp, solution); - plotter.setLabel(Label.SIZE); - plotter.plot("output/pd_solomon_r101_solution_open.png","pd_r101"); - - - - } + Plotter plotter = new Plotter(vrp, solution); + plotter.setLabel(Label.SIZE); + plotter.plot("output/pd_solomon_r101_solution_open.png", "pd_r101"); + + + } } diff --git a/jsprit-examples/src/main/java/jsprit/examples/RefuseCollectionExample.java b/jsprit-examples/src/main/java/jsprit/examples/RefuseCollectionExample.java index 97e45109..8784f252 100644 --- a/jsprit-examples/src/main/java/jsprit/examples/RefuseCollectionExample.java +++ b/jsprit-examples/src/main/java/jsprit/examples/RefuseCollectionExample.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.examples; @@ -40,104 +40,102 @@ import java.io.IOException; import java.util.Collection; - /** * This example is base on * http://web.mit.edu/urban_or_book/www/book/chapter6/6.4.12.html - * - * @author stefan schroeder * + * @author stefan schroeder */ public class RefuseCollectionExample { - public static void main(String[] args) throws IOException { - /* - * some preparation - create output folder + public static void main(String[] args) throws IOException { + /* + * some preparation - create output folder */ - Examples.createOutputFolder(); - - /* - * create vehicle-type and vehicle - */ - VehicleTypeImpl.Builder typeBuilder = VehicleTypeImpl.Builder.newInstance("vehicle-type").addCapacityDimension(0, 23); - typeBuilder.setCostPerDistance(1.0); - VehicleTypeImpl bigType = typeBuilder.build(); - - VehicleImpl.Builder vehicleBuilder = VehicleImpl.Builder.newInstance("vehicle"); - vehicleBuilder.setStartLocation(Location.newInstance("1")); - vehicleBuilder.setType(bigType); - VehicleImpl bigVehicle = vehicleBuilder.build(); - - /* - * start building the problem - */ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - vrpBuilder.setFleetSize(FleetSize.INFINITE); - vrpBuilder.addVehicle(bigVehicle); - - /* - * read demand quantities - */ - readDemandQuantities(vrpBuilder); - - /* - * create cost-matrix - */ - VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(true); - readDistances(matrixBuilder); + Examples.createOutputFolder(); - vrpBuilder.setRoutingCost(matrixBuilder.build()); - - VehicleRoutingProblem vrp = vrpBuilder.build(); - - VehicleRoutingAlgorithm vra = new GreedySchrimpfFactory().createAlgorithm(vrp); - vra.setPrematureAlgorithmTermination(new IterationWithoutImprovementTermination(100)); - Collection solutions = vra.searchSolutions(); - - SolutionPrinter.print(Solutions.bestOf(solutions)); - - new VrpXMLWriter(vrp, solutions).write("output/refuseCollectionExampleSolution.xml"); - - } + /* + * create vehicle-type and vehicle + */ + VehicleTypeImpl.Builder typeBuilder = VehicleTypeImpl.Builder.newInstance("vehicle-type").addCapacityDimension(0, 23); + typeBuilder.setCostPerDistance(1.0); + VehicleTypeImpl bigType = typeBuilder.build(); + + VehicleImpl.Builder vehicleBuilder = VehicleImpl.Builder.newInstance("vehicle"); + vehicleBuilder.setStartLocation(Location.newInstance("1")); + vehicleBuilder.setType(bigType); + VehicleImpl bigVehicle = vehicleBuilder.build(); + + /* + * start building the problem + */ + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + vrpBuilder.setFleetSize(FleetSize.INFINITE); + vrpBuilder.addVehicle(bigVehicle); + + /* + * read demand quantities + */ + readDemandQuantities(vrpBuilder); + + /* + * create cost-matrix + */ + VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(true); + readDistances(matrixBuilder); + + vrpBuilder.setRoutingCost(matrixBuilder.build()); + + VehicleRoutingProblem vrp = vrpBuilder.build(); + + VehicleRoutingAlgorithm vra = new GreedySchrimpfFactory().createAlgorithm(vrp); + vra.setPrematureAlgorithmTermination(new IterationWithoutImprovementTermination(100)); + Collection solutions = vra.searchSolutions(); + + SolutionPrinter.print(Solutions.bestOf(solutions)); + + new VrpXMLWriter(vrp, solutions).write("output/refuseCollectionExampleSolution.xml"); + + } - private static void readDemandQuantities(VehicleRoutingProblem.Builder vrpBuilder) throws IOException { - BufferedReader reader = new BufferedReader(new FileReader(new File("input/RefuseCollectionExample_Quantities"))); - String line; - boolean firstLine = true; - while((line = reader.readLine()) != null){ - if(firstLine) { - firstLine = false; - continue; - } - String[] lineTokens = line.split(","); - /* - * build service + private static void readDemandQuantities(VehicleRoutingProblem.Builder vrpBuilder) throws IOException { + BufferedReader reader = new BufferedReader(new FileReader(new File("input/RefuseCollectionExample_Quantities"))); + String line; + boolean firstLine = true; + while ((line = reader.readLine()) != null) { + if (firstLine) { + firstLine = false; + continue; + } + String[] lineTokens = line.split(","); + /* + * build service */ - Service service = Service.Builder.newInstance(lineTokens[0]).addSizeDimension(0, Integer.parseInt(lineTokens[1])).setLocation(Location.newInstance(lineTokens[0])).build(); - /* + 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); - } - reader.close(); - } - + vrpBuilder.addJob(service); + } + reader.close(); + } - private static void readDistances(Builder matrixBuilder) throws IOException { - BufferedReader reader = new BufferedReader(new FileReader(new File("input/RefuseCollectionExample_Distances"))); - String line; - boolean firstLine = true; - while((line = reader.readLine()) != null){ - if(firstLine) { - firstLine = false; - continue; - } - String[] lineTokens = line.split(","); - matrixBuilder.addTransportDistance(lineTokens[0],lineTokens[1], Integer.parseInt(lineTokens[2])); - } - reader.close(); - - } + + private static void readDistances(Builder matrixBuilder) throws IOException { + BufferedReader reader = new BufferedReader(new FileReader(new File("input/RefuseCollectionExample_Distances"))); + String line; + boolean firstLine = true; + while ((line = reader.readLine()) != null) { + if (firstLine) { + firstLine = false; + continue; + } + String[] lineTokens = line.split(","); + matrixBuilder.addTransportDistance(lineTokens[0], lineTokens[1], Integer.parseInt(lineTokens[2])); + } + reader.close(); + + } } diff --git a/jsprit-examples/src/main/java/jsprit/examples/RefuseCollectionWithFastMatrixExample.java b/jsprit-examples/src/main/java/jsprit/examples/RefuseCollectionWithFastMatrixExample.java index d1d80ab5..9eb7a50c 100644 --- a/jsprit-examples/src/main/java/jsprit/examples/RefuseCollectionWithFastMatrixExample.java +++ b/jsprit-examples/src/main/java/jsprit/examples/RefuseCollectionWithFastMatrixExample.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.examples; @@ -42,103 +42,102 @@ import java.util.Collection; /** * This example is base on * http://web.mit.edu/urban_or_book/www/book/chapter6/6.4.12.html - * - * @author stefan schroeder * + * @author stefan schroeder */ public class RefuseCollectionWithFastMatrixExample { - public static void main(String[] args) throws IOException { - /* - * some preparation - create output folder + public static void main(String[] args) throws IOException { + /* + * some preparation - create output folder */ - Examples.createOutputFolder(); + Examples.createOutputFolder(); /* - * create vehicle-type and vehicle + * create vehicle-type and vehicle */ - VehicleTypeImpl.Builder typeBuilder = VehicleTypeImpl.Builder.newInstance("vehicle-type").addCapacityDimension(0, 23); - typeBuilder.setCostPerDistance(1.0); - VehicleTypeImpl bigType = typeBuilder.build(); + VehicleTypeImpl.Builder typeBuilder = VehicleTypeImpl.Builder.newInstance("vehicle-type").addCapacityDimension(0, 23); + typeBuilder.setCostPerDistance(1.0); + VehicleTypeImpl bigType = typeBuilder.build(); - VehicleImpl.Builder vehicleBuilder = VehicleImpl.Builder.newInstance("vehicle"); - vehicleBuilder.setStartLocation(Location.Builder.newInstance().setIndex(1).build()); - vehicleBuilder.setType(bigType); - VehicleImpl bigVehicle = vehicleBuilder.build(); + VehicleImpl.Builder vehicleBuilder = VehicleImpl.Builder.newInstance("vehicle"); + vehicleBuilder.setStartLocation(Location.Builder.newInstance().setIndex(1).build()); + vehicleBuilder.setType(bigType); + VehicleImpl bigVehicle = vehicleBuilder.build(); /* - * start building the problem + * start building the problem */ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - vrpBuilder.setFleetSize(FleetSize.INFINITE); - vrpBuilder.addVehicle(bigVehicle); + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + vrpBuilder.setFleetSize(FleetSize.INFINITE); + vrpBuilder.addVehicle(bigVehicle); /* - * read demand quantities + * read demand quantities */ - readDemandQuantities(vrpBuilder); + readDemandQuantities(vrpBuilder); /* - * create cost-matrix + * create cost-matrix */ - FastVehicleRoutingTransportCostsMatrix.Builder matrixBuilder = FastVehicleRoutingTransportCostsMatrix.Builder.newInstance(11,true); - readDistances(matrixBuilder); + FastVehicleRoutingTransportCostsMatrix.Builder matrixBuilder = FastVehicleRoutingTransportCostsMatrix.Builder.newInstance(11, true); + readDistances(matrixBuilder); - vrpBuilder.setRoutingCost(matrixBuilder.build()); - - VehicleRoutingProblem vrp = vrpBuilder.build(); - - VehicleRoutingAlgorithm vra = new GreedySchrimpfFactory().createAlgorithm(vrp); - vra.setPrematureAlgorithmTermination(new IterationWithoutImprovementTermination(100)); - Collection solutions = vra.searchSolutions(); - - SolutionPrinter.print(Solutions.bestOf(solutions)); - - new VrpXMLWriter(vrp, solutions).write("output/refuseCollectionExampleSolution.xml"); - - } + vrpBuilder.setRoutingCost(matrixBuilder.build()); + + VehicleRoutingProblem vrp = vrpBuilder.build(); + + VehicleRoutingAlgorithm vra = new GreedySchrimpfFactory().createAlgorithm(vrp); + vra.setPrematureAlgorithmTermination(new IterationWithoutImprovementTermination(100)); + Collection solutions = vra.searchSolutions(); + + SolutionPrinter.print(Solutions.bestOf(solutions)); + + new VrpXMLWriter(vrp, solutions).write("output/refuseCollectionExampleSolution.xml"); + + } - private static void readDemandQuantities(VehicleRoutingProblem.Builder vrpBuilder) throws IOException { - BufferedReader reader = new BufferedReader(new FileReader(new File("input/RefuseCollectionExample_Quantities"))); - String line; - boolean firstLine = true; - while((line = reader.readLine()) != null){ - if(firstLine) { - firstLine = false; - continue; - } - String[] lineTokens = line.split(","); - /* - * build service + private static void readDemandQuantities(VehicleRoutingProblem.Builder vrpBuilder) throws IOException { + BufferedReader reader = new BufferedReader(new FileReader(new File("input/RefuseCollectionExample_Quantities"))); + String line; + boolean firstLine = true; + while ((line = reader.readLine()) != null) { + if (firstLine) { + firstLine = false; + continue; + } + String[] lineTokens = line.split(","); + /* + * build service */ - Service service = Service.Builder.newInstance(lineTokens[0]) - .addSizeDimension(0, Integer.parseInt(lineTokens[1])) - .setLocation(Location.Builder.newInstance().setIndex(Integer.parseInt(lineTokens[0])).build()) - .build(); - /* + Service service = Service.Builder.newInstance(lineTokens[0]) + .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); - } - reader.close(); - } - + vrpBuilder.addJob(service); + } + reader.close(); + } - private static void readDistances(FastVehicleRoutingTransportCostsMatrix.Builder matrixBuilder) throws IOException { - BufferedReader reader = new BufferedReader(new FileReader(new File("input/RefuseCollectionExample_Distances"))); - String line; - boolean firstLine = true; - while((line = reader.readLine()) != null){ - if(firstLine) { - firstLine = false; - continue; - } - String[] lineTokens = line.split(","); - matrixBuilder.addTransportDistance(Integer.parseInt(lineTokens[0]),Integer.parseInt(lineTokens[1]), Integer.parseInt(lineTokens[2])); - } - reader.close(); - - } + + private static void readDistances(FastVehicleRoutingTransportCostsMatrix.Builder matrixBuilder) throws IOException { + BufferedReader reader = new BufferedReader(new FileReader(new File("input/RefuseCollectionExample_Distances"))); + String line; + boolean firstLine = true; + while ((line = reader.readLine()) != null) { + if (firstLine) { + firstLine = false; + continue; + } + String[] lineTokens = line.split(","); + matrixBuilder.addTransportDistance(Integer.parseInt(lineTokens[0]), Integer.parseInt(lineTokens[1]), Integer.parseInt(lineTokens[2])); + } + reader.close(); + + } } diff --git a/jsprit-examples/src/main/java/jsprit/examples/ServicePickupsWithMultipleDepotsExample.java b/jsprit-examples/src/main/java/jsprit/examples/ServicePickupsWithMultipleDepotsExample.java index b3834971..8faa4c77 100644 --- a/jsprit-examples/src/main/java/jsprit/examples/ServicePickupsWithMultipleDepotsExample.java +++ b/jsprit-examples/src/main/java/jsprit/examples/ServicePickupsWithMultipleDepotsExample.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.examples; @@ -39,106 +39,106 @@ import java.util.Collection; public class ServicePickupsWithMultipleDepotsExample { - - public static void main(String[] args) { - /* - * some preparation - create output folder + + public static void main(String[] args) { + /* + * some preparation - create output folder */ - Examples.createOutputFolder(); - + Examples.createOutputFolder(); + /* - * get a vehicle type-builder and build a type with the typeId "vehicleType" and a capacity of 2 + * get a vehicle type-builder and build a type with the typeId "vehicleType" and a capacity of 2 */ - VehicleTypeImpl.Builder vehicleTypeBuilder = VehicleTypeImpl.Builder.newInstance("vehicleType").addCapacityDimension(0, 8); - vehicleTypeBuilder.setCostPerDistance(1.0); - VehicleType vehicleType = vehicleTypeBuilder.build(); - + VehicleTypeImpl.Builder vehicleTypeBuilder = VehicleTypeImpl.Builder.newInstance("vehicleType").addCapacityDimension(0, 8); + vehicleTypeBuilder.setCostPerDistance(1.0); + VehicleType vehicleType = vehicleTypeBuilder.build(); + /* - * define two depots, i.e. two vehicle locations ([10,10],[50,50]) and equip them with an infinite number of vehicles of type 'vehicleType' + * define two depots, i.e. two vehicle locations ([10,10],[50,50]) and equip them with an infinite number of vehicles of type 'vehicleType' */ - Builder vehicleBuilder1 = VehicleImpl.Builder.newInstance("vehicles@[10,10]"); - vehicleBuilder1.setStartLocation(Location.newInstance(10, 10)); - vehicleBuilder1.setType(vehicleType); - VehicleImpl vehicle1 = vehicleBuilder1.build(); - - Builder vehicleBuilder2 = VehicleImpl.Builder.newInstance("vehicles@[50,50]"); - vehicleBuilder2.setStartLocation(Location.newInstance(50, 50)); - vehicleBuilder2.setType(vehicleType); - VehicleImpl vehicle2 = vehicleBuilder2.build(); - - + Builder vehicleBuilder1 = VehicleImpl.Builder.newInstance("vehicles@[10,10]"); + vehicleBuilder1.setStartLocation(Location.newInstance(10, 10)); + vehicleBuilder1.setType(vehicleType); + VehicleImpl vehicle1 = vehicleBuilder1.build(); + + Builder vehicleBuilder2 = VehicleImpl.Builder.newInstance("vehicles@[50,50]"); + vehicleBuilder2.setStartLocation(Location.newInstance(50, 50)); + vehicleBuilder2.setType(vehicleType); + VehicleImpl vehicle2 = vehicleBuilder2.build(); + + /* - * build shipments at the required locations, each with a capacity-demand of 1. + * build shipments at the required locations, each with a capacity-demand of 1. * 4 shipments * 1: (5,7)->(6,9) * 2: (5,13)->(6,11) * 3: (15,7)->(14,9) * 4: (15,13)->(14,11) */ - - Service shipment1 = Service.Builder.newInstance("1").addSizeDimension(0, 1).setLocation(Location.newInstance(5, 7)).build(); - Service shipment2 = Service.Builder.newInstance("2").addSizeDimension(0, 1).setLocation(Location.newInstance(5, 13)).build(); - - Service shipment3 = Service.Builder.newInstance("3").addSizeDimension(0, 1).setLocation(Location.newInstance(15, 7)).build(); - Service shipment4 = Service.Builder.newInstance("4").addSizeDimension(0, 1).setLocation(Location.newInstance(15, 13)).build(); - - Service shipment5 = Service.Builder.newInstance("5").addSizeDimension(0, 1).setLocation(Location.newInstance(55, 57)).build(); - Service shipment6 = Service.Builder.newInstance("6").addSizeDimension(0, 1).setLocation(Location.newInstance(55, 63)).build(); - - Service shipment7 = Service.Builder.newInstance("7").addSizeDimension(0, 1).setLocation(Location.newInstance(65, 57)).build(); - Service shipment8 = Service.Builder.newInstance("8").addSizeDimension(0, 1).setLocation(Location.newInstance(65, 63)).build(); - - - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - vrpBuilder.addVehicle(vehicle1).addVehicle(vehicle2); - vrpBuilder.addJob(shipment1).addJob(shipment2).addJob(shipment3).addJob(shipment4); - vrpBuilder.addJob(shipment5).addJob(shipment6).addJob(shipment7).addJob(shipment8); - + + Service shipment1 = Service.Builder.newInstance("1").addSizeDimension(0, 1).setLocation(Location.newInstance(5, 7)).build(); + Service shipment2 = Service.Builder.newInstance("2").addSizeDimension(0, 1).setLocation(Location.newInstance(5, 13)).build(); + + Service shipment3 = Service.Builder.newInstance("3").addSizeDimension(0, 1).setLocation(Location.newInstance(15, 7)).build(); + Service shipment4 = Service.Builder.newInstance("4").addSizeDimension(0, 1).setLocation(Location.newInstance(15, 13)).build(); + + Service shipment5 = Service.Builder.newInstance("5").addSizeDimension(0, 1).setLocation(Location.newInstance(55, 57)).build(); + Service shipment6 = Service.Builder.newInstance("6").addSizeDimension(0, 1).setLocation(Location.newInstance(55, 63)).build(); + + Service shipment7 = Service.Builder.newInstance("7").addSizeDimension(0, 1).setLocation(Location.newInstance(65, 57)).build(); + Service shipment8 = Service.Builder.newInstance("8").addSizeDimension(0, 1).setLocation(Location.newInstance(65, 63)).build(); + + + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + vrpBuilder.addVehicle(vehicle1).addVehicle(vehicle2); + vrpBuilder.addJob(shipment1).addJob(shipment2).addJob(shipment3).addJob(shipment4); + vrpBuilder.addJob(shipment5).addJob(shipment6).addJob(shipment7).addJob(shipment8); + // vrpBuilder.setFleetSize(FleetSize.FINITE); - VehicleRoutingProblem problem = vrpBuilder.build(); - + VehicleRoutingProblem problem = vrpBuilder.build(); + /* - * get the algorithm out-of-the-box. + * get the algorithm out-of-the-box. */ - VehicleRoutingAlgorithm algorithm = VehicleRoutingAlgorithms.readAndCreateAlgorithm(problem, "input/algorithmConfig.xml"); - algorithm.setMaxIterations(10); - + VehicleRoutingAlgorithm algorithm = VehicleRoutingAlgorithms.readAndCreateAlgorithm(problem, "input/algorithmConfig.xml"); + algorithm.setMaxIterations(10); + /* - * and search a solution + * and search a solution */ - Collection solutions = algorithm.searchSolutions(); - + Collection solutions = algorithm.searchSolutions(); + /* - * get the best + * get the best */ - VehicleRoutingProblemSolution bestSolution = Solutions.bestOf(solutions); - + 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"); - + new VrpXMLWriter(problem, solutions).write("output/shipment-problem-with-solution.xml"); + /* * print nRoutes and totalCosts of bestSolution */ - SolutionPrinter.print(bestSolution); - + SolutionPrinter.print(bestSolution); + /* * plot problem without solution */ - Plotter problemPlotter = new Plotter(problem); - problemPlotter.plotShipments(true); - problemPlotter.plot("output/enRoutePickupAndDeliveryWithMultipleLocationsExample_problem.png", "en-route pickup and delivery"); - + Plotter problemPlotter = new Plotter(problem); + problemPlotter.plotShipments(true); + problemPlotter.plot("output/enRoutePickupAndDeliveryWithMultipleLocationsExample_problem.png", "en-route pickup and delivery"); + /* * plot problem with solution */ - Plotter solutionPlotter = new Plotter(problem,Arrays.asList(Solutions.bestOf(solutions).getRoutes().iterator().next())); - solutionPlotter.plotShipments(true); - solutionPlotter.plot("output/enRoutePickupAndDeliveryWithMultipleLocationsExample_solution.png", "en-route pickup and delivery"); - - new GraphStreamViewer(problem,Solutions.bestOf(solutions)).labelWith(Label.ACTIVITY).setRenderDelay(100).setRenderShipments(true).display(); - - } + Plotter solutionPlotter = new Plotter(problem, Arrays.asList(Solutions.bestOf(solutions).getRoutes().iterator().next())); + solutionPlotter.plotShipments(true); + solutionPlotter.plot("output/enRoutePickupAndDeliveryWithMultipleLocationsExample_solution.png", "en-route pickup and delivery"); + + new GraphStreamViewer(problem, Solutions.bestOf(solutions)).labelWith(Label.ACTIVITY).setRenderDelay(100).setRenderShipments(true).display(); + + } } diff --git a/jsprit-examples/src/main/java/jsprit/examples/SimpleDepotBoundedPickupAndDeliveryExample.java b/jsprit-examples/src/main/java/jsprit/examples/SimpleDepotBoundedPickupAndDeliveryExample.java index db6e884a..18e5bc66 100644 --- a/jsprit-examples/src/main/java/jsprit/examples/SimpleDepotBoundedPickupAndDeliveryExample.java +++ b/jsprit-examples/src/main/java/jsprit/examples/SimpleDepotBoundedPickupAndDeliveryExample.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.examples; @@ -38,70 +38,71 @@ import java.util.Collection; public class SimpleDepotBoundedPickupAndDeliveryExample { - - public static void main(String[] args) { - /* - * some preparation - create output folder - */ - Examples.createOutputFolder(); - - /* - * get a vehicle type-builder and build a type with the typeId "vehicleType" and a capacity of 2 - */ - VehicleTypeImpl.Builder vehicleTypeBuilder = VehicleTypeImpl.Builder.newInstance("vehicleType").addCapacityDimension(0, 2); - VehicleType vehicleType = vehicleTypeBuilder.build(); - - /* - * get a vehicle-builder and build a vehicle located at (10,10) with type "vehicleType" - */ - Builder vehicleBuilder = VehicleImpl.Builder.newInstance("vehicle"); - vehicleBuilder.setStartLocation(Location.newInstance(10, 10)); - vehicleBuilder.setType(vehicleType); - VehicleImpl vehicle = vehicleBuilder.build(); - - /* - * build pickups and deliveries at the required locations, each with a capacity-demand of 1. - */ - Pickup pickup1 = (Pickup) Pickup.Builder.newInstance("1").addSizeDimension(0, 1).setLocation(Location.newInstance(5, 7)).build(); - Delivery delivery1 = (Delivery) Delivery.Builder.newInstance("2").addSizeDimension(0, 1).setLocation(Location.newInstance(5, 13)).build(); - - Pickup pickup2 = (Pickup) Pickup.Builder.newInstance("3").addSizeDimension(0, 1).setLocation(Location.newInstance(15, 7)).build(); - Delivery delivery2 = (Delivery) Delivery.Builder.newInstance("4").addSizeDimension(0, 1).setLocation(Location.newInstance(15, 13)).build(); - - - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - vrpBuilder.addVehicle(vehicle); - vrpBuilder.addJob(pickup1).addJob(pickup2).addJob(delivery1).addJob(delivery2); - - - VehicleRoutingProblem problem = vrpBuilder.build(); - - /* - * get the algorithm out-of-the-box. - */ - VehicleRoutingAlgorithm algorithm = new SchrimpfFactory().createAlgorithm(problem); - - /* - * and search a solution - */ - Collection solutions = algorithm.searchSolutions(); - - /* - * get the best - */ - VehicleRoutingProblemSolution bestSolution = Solutions.bestOf(solutions); - - new VrpXMLWriter(problem, solutions).write("output/problem-with-solution.xml"); - - SolutionPrinter.print(bestSolution); - - /* - * plot - */ - Plotter plotter = new Plotter(problem,bestSolution); - plotter.setLabel(Label.SIZE); - plotter.plot("output/solution.png", "solution"); - } + public static void main(String[] args) { + /* + * some preparation - create output folder + */ + Examples.createOutputFolder(); + + /* + * get a vehicle type-builder and build a type with the typeId "vehicleType" and a capacity of 2 + */ + VehicleTypeImpl.Builder vehicleTypeBuilder = VehicleTypeImpl.Builder.newInstance("vehicleType").addCapacityDimension(0, 2); + VehicleType vehicleType = vehicleTypeBuilder.build(); + + /* + * get a vehicle-builder and build a vehicle located at (10,10) with type "vehicleType" + */ + Builder vehicleBuilder = VehicleImpl.Builder.newInstance("vehicle"); + vehicleBuilder.setStartLocation(Location.newInstance(10, 10)); + vehicleBuilder.setType(vehicleType); + VehicleImpl vehicle = vehicleBuilder.build(); + + /* + * build pickups and deliveries at the required locations, each with a capacity-demand of 1. + */ + + Pickup pickup1 = Pickup.Builder.newInstance("1").addSizeDimension(0, 1).setLocation(Location.newInstance(5, 7)).build(); + Delivery delivery1 = Delivery.Builder.newInstance("2").addSizeDimension(0, 1).setLocation(Location.newInstance(5, 13)).build(); + + Pickup pickup2 = Pickup.Builder.newInstance("3").addSizeDimension(0, 1).setLocation(Location.newInstance(15, 7)).build(); + Delivery delivery2 = Delivery.Builder.newInstance("4").addSizeDimension(0, 1).setLocation(Location.newInstance(15, 13)).build(); + + + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + vrpBuilder.addVehicle(vehicle); + vrpBuilder.addJob(pickup1).addJob(pickup2).addJob(delivery1).addJob(delivery2); + + + VehicleRoutingProblem problem = vrpBuilder.build(); + + /* + * get the algorithm out-of-the-box. + */ + VehicleRoutingAlgorithm algorithm = new SchrimpfFactory().createAlgorithm(problem); + + /* + * and search a solution + */ + Collection solutions = algorithm.searchSolutions(); + + /* + * get the best + */ + VehicleRoutingProblemSolution bestSolution = Solutions.bestOf(solutions); + + new VrpXMLWriter(problem, solutions).write("output/problem-with-solution.xml"); + + SolutionPrinter.print(bestSolution); + + /* + * plot + */ + Plotter plotter = new Plotter(problem, bestSolution); + plotter.setLabel(Label.SIZE); + plotter.plot("output/solution.png", "solution"); + + } } diff --git a/jsprit-examples/src/main/java/jsprit/examples/SimpleEnRoutePickupAndDeliveryExample.java b/jsprit-examples/src/main/java/jsprit/examples/SimpleEnRoutePickupAndDeliveryExample.java index 899a7b78..4a12c0af 100644 --- a/jsprit-examples/src/main/java/jsprit/examples/SimpleEnRoutePickupAndDeliveryExample.java +++ b/jsprit-examples/src/main/java/jsprit/examples/SimpleEnRoutePickupAndDeliveryExample.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.examples; @@ -39,94 +39,94 @@ import java.util.Collection; public class SimpleEnRoutePickupAndDeliveryExample { - - public static void main(String[] args) { - /* - * some preparation - create output folder + + public static void main(String[] args) { + /* + * some preparation - create output folder */ - Examples.createOutputFolder(); - + Examples.createOutputFolder(); + /* - * get a vehicle type-builder and build a type with the typeId "vehicleType" and a capacity of 2 + * get a vehicle type-builder and build a type with the typeId "vehicleType" and a capacity of 2 */ - VehicleTypeImpl.Builder vehicleTypeBuilder = VehicleTypeImpl.Builder.newInstance("vehicleType").addCapacityDimension(0, 2); - VehicleType vehicleType = vehicleTypeBuilder.build(); - + VehicleTypeImpl.Builder vehicleTypeBuilder = VehicleTypeImpl.Builder.newInstance("vehicleType").addCapacityDimension(0, 2); + VehicleType vehicleType = vehicleTypeBuilder.build(); + /* - * get a vehicle-builder and build a vehicle located at (10,10) with type "vehicleType" + * get a vehicle-builder and build a vehicle located at (10,10) with type "vehicleType" */ - Builder vehicleBuilder = VehicleImpl.Builder.newInstance("vehicle"); - vehicleBuilder.setStartLocation(loc(Coordinate.newInstance(10, 10))); - vehicleBuilder.setType(vehicleType); - VehicleImpl vehicle = vehicleBuilder.build(); - + Builder vehicleBuilder = VehicleImpl.Builder.newInstance("vehicle"); + vehicleBuilder.setStartLocation(loc(Coordinate.newInstance(10, 10))); + vehicleBuilder.setType(vehicleType); + VehicleImpl vehicle = vehicleBuilder.build(); + /* - * build shipments at the required locations, each with a capacity-demand of 1. + * build shipments at the required locations, each with a capacity-demand of 1. * 4 shipments * 1: (5,7)->(6,9) * 2: (5,13)->(6,11) * 3: (15,7)->(14,9) * 4: (15,13)->(14,11) */ - - Shipment shipment1 = Shipment.Builder.newInstance("1").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(5, 7))).setDeliveryLocation(loc(Coordinate.newInstance(6, 9))).build(); - Shipment shipment2 = Shipment.Builder.newInstance("2").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(5, 13))).setDeliveryLocation(loc(Coordinate.newInstance(6, 11))).build(); - - Shipment shipment3 = Shipment.Builder.newInstance("3").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(15, 7))).setDeliveryLocation(loc(Coordinate.newInstance(14, 9))).build(); - Shipment shipment4 = Shipment.Builder.newInstance("4").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(15, 13))).setDeliveryLocation(loc(Coordinate.newInstance(14, 11))).build(); - - - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - vrpBuilder.addVehicle(vehicle); - vrpBuilder.addJob(shipment1).addJob(shipment2).addJob(shipment3).addJob(shipment4); - - VehicleRoutingProblem problem = vrpBuilder.build(); - + + Shipment shipment1 = Shipment.Builder.newInstance("1").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(5, 7))).setDeliveryLocation(loc(Coordinate.newInstance(6, 9))).build(); + Shipment shipment2 = Shipment.Builder.newInstance("2").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(5, 13))).setDeliveryLocation(loc(Coordinate.newInstance(6, 11))).build(); + + Shipment shipment3 = Shipment.Builder.newInstance("3").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(15, 7))).setDeliveryLocation(loc(Coordinate.newInstance(14, 9))).build(); + Shipment shipment4 = Shipment.Builder.newInstance("4").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(15, 13))).setDeliveryLocation(loc(Coordinate.newInstance(14, 11))).build(); + + + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + vrpBuilder.addVehicle(vehicle); + vrpBuilder.addJob(shipment1).addJob(shipment2).addJob(shipment3).addJob(shipment4); + + VehicleRoutingProblem problem = vrpBuilder.build(); + /* - * get the algorithm out-of-the-box. + * get the algorithm out-of-the-box. */ - VehicleRoutingAlgorithm algorithm = new SchrimpfFactory().createAlgorithm(problem); - + VehicleRoutingAlgorithm algorithm = new SchrimpfFactory().createAlgorithm(problem); + /* - * and search a solution + * and search a solution */ - Collection solutions = algorithm.searchSolutions(); - + Collection solutions = algorithm.searchSolutions(); + /* - * get the best + * get the best */ - VehicleRoutingProblemSolution bestSolution = Solutions.bestOf(solutions); - + 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"); - + new VrpXMLWriter(problem, solutions).write("output/shipment-problem-with-solution.xml"); + /* * print nRoutes and totalCosts of bestSolution */ - SolutionPrinter.print(bestSolution); - + SolutionPrinter.print(bestSolution); + /* * plot problem without solution */ - Plotter problemPlotter = new Plotter(problem); - problemPlotter.plotShipments(true); - problemPlotter.plot("output/simpleEnRoutePickupAndDeliveryExample_problem.png", "en-route pickup and delivery"); - + Plotter problemPlotter = new Plotter(problem); + problemPlotter.plotShipments(true); + problemPlotter.plot("output/simpleEnRoutePickupAndDeliveryExample_problem.png", "en-route pickup and delivery"); + /* * plot problem with solution */ - Plotter solutionPlotter = new Plotter(problem,Arrays.asList(Solutions.bestOf(solutions).getRoutes().iterator().next())); - solutionPlotter.plotShipments(true); - solutionPlotter.plot("output/simpleEnRoutePickupAndDeliveryExample_solution.png", "en-route pickup and delivery"); - - new GraphStreamViewer(problem).setRenderShipments(true).display(); - - } + Plotter solutionPlotter = new Plotter(problem, Arrays.asList(Solutions.bestOf(solutions).getRoutes().iterator().next())); + solutionPlotter.plotShipments(true); + solutionPlotter.plot("output/simpleEnRoutePickupAndDeliveryExample_solution.png", "en-route pickup and delivery"); - private static Location loc(Coordinate coordinate) { - return Location.Builder.newInstance().setCoordinate(coordinate).build(); - } + new GraphStreamViewer(problem).setRenderShipments(true).display(); + + } + + private static Location loc(Coordinate coordinate) { + return Location.Builder.newInstance().setCoordinate(coordinate).build(); + } } diff --git a/jsprit-examples/src/main/java/jsprit/examples/SimpleEnRoutePickupAndDeliveryOpenRoutesExample.java b/jsprit-examples/src/main/java/jsprit/examples/SimpleEnRoutePickupAndDeliveryOpenRoutesExample.java index e3a43610..f878a8b2 100644 --- a/jsprit-examples/src/main/java/jsprit/examples/SimpleEnRoutePickupAndDeliveryOpenRoutesExample.java +++ b/jsprit-examples/src/main/java/jsprit/examples/SimpleEnRoutePickupAndDeliveryOpenRoutesExample.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.examples; @@ -38,94 +38,94 @@ import java.util.Collection; public class SimpleEnRoutePickupAndDeliveryOpenRoutesExample { - - public static void main(String[] args) { - /* - * some preparation - create output folder + + public static void main(String[] args) { + /* + * some preparation - create output folder */ - Examples.createOutputFolder(); - + Examples.createOutputFolder(); + /* - * get a vehicle type-builder and build a type with the typeId "vehicleType" and a capacity of 2 + * get a vehicle type-builder and build a type with the typeId "vehicleType" and a capacity of 2 */ - VehicleTypeImpl.Builder vehicleTypeBuilder = VehicleTypeImpl.Builder.newInstance("vehicleType").addCapacityDimension(0, 2); - VehicleType vehicleType = vehicleTypeBuilder.build(); - + VehicleTypeImpl.Builder vehicleTypeBuilder = VehicleTypeImpl.Builder.newInstance("vehicleType").addCapacityDimension(0, 2); + VehicleType vehicleType = vehicleTypeBuilder.build(); + /* - * get a vehicle-builder and build a vehicle located at (10,10) with type "vehicleType" + * get a vehicle-builder and build a vehicle located at (10,10) with type "vehicleType" */ - Builder vehicleBuilder = VehicleImpl.Builder.newInstance("vehicle"); - vehicleBuilder.setStartLocation(loc(Coordinate.newInstance(10, 10))); - vehicleBuilder.setType(vehicleType); - vehicleBuilder.setReturnToDepot(false); - VehicleImpl vehicle = vehicleBuilder.build(); - + Builder vehicleBuilder = VehicleImpl.Builder.newInstance("vehicle"); + vehicleBuilder.setStartLocation(loc(Coordinate.newInstance(10, 10))); + vehicleBuilder.setType(vehicleType); + vehicleBuilder.setReturnToDepot(false); + VehicleImpl vehicle = vehicleBuilder.build(); + /* - * build shipments at the required locations, each with a capacity-demand of 1. + * build shipments at the required locations, each with a capacity-demand of 1. * 4 shipments * 1: (5,7)->(6,9) * 2: (5,13)->(6,11) * 3: (15,7)->(14,9) * 4: (15,13)->(14,11) */ - - Shipment shipment1 = Shipment.Builder.newInstance("1").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(5, 7))).setDeliveryLocation(loc(Coordinate.newInstance(6, 9))).build(); - Shipment shipment2 = Shipment.Builder.newInstance("2").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(5, 13))).setDeliveryLocation(loc(Coordinate.newInstance(6, 11))).build(); - - Shipment shipment3 = Shipment.Builder.newInstance("3").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(15, 7))).setDeliveryLocation(loc(Coordinate.newInstance(14, 9))).build(); - Shipment shipment4 = Shipment.Builder.newInstance("4").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(15, 13))).setDeliveryLocation(loc(Coordinate.newInstance(14, 11))).build(); - - - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - vrpBuilder.addVehicle(vehicle); - vrpBuilder.addJob(shipment1).addJob(shipment2).addJob(shipment3).addJob(shipment4); - - VehicleRoutingProblem problem = vrpBuilder.build(); - + + Shipment shipment1 = Shipment.Builder.newInstance("1").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(5, 7))).setDeliveryLocation(loc(Coordinate.newInstance(6, 9))).build(); + Shipment shipment2 = Shipment.Builder.newInstance("2").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(5, 13))).setDeliveryLocation(loc(Coordinate.newInstance(6, 11))).build(); + + Shipment shipment3 = Shipment.Builder.newInstance("3").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(15, 7))).setDeliveryLocation(loc(Coordinate.newInstance(14, 9))).build(); + Shipment shipment4 = Shipment.Builder.newInstance("4").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(15, 13))).setDeliveryLocation(loc(Coordinate.newInstance(14, 11))).build(); + + + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + vrpBuilder.addVehicle(vehicle); + vrpBuilder.addJob(shipment1).addJob(shipment2).addJob(shipment3).addJob(shipment4); + + VehicleRoutingProblem problem = vrpBuilder.build(); + /* - * get the algorithm out-of-the-box. + * get the algorithm out-of-the-box. */ - VehicleRoutingAlgorithm algorithm = new SchrimpfFactory().createAlgorithm(problem); - + VehicleRoutingAlgorithm algorithm = new SchrimpfFactory().createAlgorithm(problem); + /* - * and search a solution + * and search a solution */ - Collection solutions = algorithm.searchSolutions(); - + Collection solutions = algorithm.searchSolutions(); + /* - * get the best + * get the best */ - VehicleRoutingProblemSolution bestSolution = Solutions.bestOf(solutions); - + 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"); - + new VrpXMLWriter(problem, solutions).write("output/shipment-problem-with-solution.xml"); + /* * print nRoutes and totalCosts of bestSolution */ - SolutionPrinter.print(problem, bestSolution, SolutionPrinter.Print.VERBOSE); - + SolutionPrinter.print(problem, bestSolution, SolutionPrinter.Print.VERBOSE); + /* * plot problem without solution */ - Plotter problemPlotter = new Plotter(problem); - problemPlotter.plotShipments(true); - problemPlotter.plot("output/simpleEnRoutePickupAndDeliveryExample_problem.png", "en-route pickup and delivery"); - + Plotter problemPlotter = new Plotter(problem); + problemPlotter.plotShipments(true); + problemPlotter.plot("output/simpleEnRoutePickupAndDeliveryExample_problem.png", "en-route pickup and delivery"); + /* * plot problem with solution */ - Plotter solutionPlotter = new Plotter(problem,Solutions.bestOf(solutions).getRoutes()); - solutionPlotter.plotShipments(true); - solutionPlotter.plot("output/simpleEnRoutePickupAndDeliveryExample_solution.png", "en-route pickup and delivery"); - - new GraphStreamViewer(problem, bestSolution).setRenderShipments(true).setRenderDelay(100).display(); - } + Plotter solutionPlotter = new Plotter(problem, Solutions.bestOf(solutions).getRoutes()); + solutionPlotter.plotShipments(true); + solutionPlotter.plot("output/simpleEnRoutePickupAndDeliveryExample_solution.png", "en-route pickup and delivery"); - private static Location loc(Coordinate coordinate) { - return Location.Builder.newInstance().setCoordinate(coordinate).build(); - } + new GraphStreamViewer(problem, bestSolution).setRenderShipments(true).setRenderDelay(100).display(); + } + + private static Location loc(Coordinate coordinate) { + return Location.Builder.newInstance().setCoordinate(coordinate).build(); + } } diff --git a/jsprit-examples/src/main/java/jsprit/examples/SimpleEnRoutePickupAndDeliveryWithDepotBoundedDeliveriesExample.java b/jsprit-examples/src/main/java/jsprit/examples/SimpleEnRoutePickupAndDeliveryWithDepotBoundedDeliveriesExample.java index 46b6f402..6c6a3739 100644 --- a/jsprit-examples/src/main/java/jsprit/examples/SimpleEnRoutePickupAndDeliveryWithDepotBoundedDeliveriesExample.java +++ b/jsprit-examples/src/main/java/jsprit/examples/SimpleEnRoutePickupAndDeliveryWithDepotBoundedDeliveriesExample.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.examples; @@ -41,102 +41,102 @@ import java.util.Collection; public class SimpleEnRoutePickupAndDeliveryWithDepotBoundedDeliveriesExample { - - public static void main(String[] args) { - /* - * some preparation - create output folder + + public static void main(String[] args) { + /* + * some preparation - create output folder */ - Examples.createOutputFolder(); - + Examples.createOutputFolder(); + /* - * get a vehicle type-builder and build a type with the typeId "vehicleType" and a capacity of 2 + * get a vehicle type-builder and build a type with the typeId "vehicleType" and a capacity of 2 */ - VehicleTypeImpl.Builder vehicleTypeBuilder = VehicleTypeImpl.Builder.newInstance("vehicleType").addCapacityDimension(0, 2); - VehicleType vehicleType = vehicleTypeBuilder.build(); - + VehicleTypeImpl.Builder vehicleTypeBuilder = VehicleTypeImpl.Builder.newInstance("vehicleType").addCapacityDimension(0, 2); + VehicleType vehicleType = vehicleTypeBuilder.build(); + /* - * get a vehicle-builder and build a vehicle located at (10,10) with type "vehicleType" + * get a vehicle-builder and build a vehicle located at (10,10) with type "vehicleType" */ - Builder vehicleBuilder = VehicleImpl.Builder.newInstance("vehicle"); - vehicleBuilder.setStartLocation(loc(Coordinate.newInstance(10, 10))); - vehicleBuilder.setType(vehicleType); - VehicleImpl vehicle = vehicleBuilder.build(); - + Builder vehicleBuilder = VehicleImpl.Builder.newInstance("vehicle"); + vehicleBuilder.setStartLocation(loc(Coordinate.newInstance(10, 10))); + vehicleBuilder.setType(vehicleType); + VehicleImpl vehicle = vehicleBuilder.build(); + /* - * build shipments at the required locations, each with a capacity-demand of 1. + * build shipments at the required locations, each with a capacity-demand of 1. * 4 shipments * 1: (5,7)->(6,9) * 2: (5,13)->(6,11) * 3: (15,7)->(14,9) * 4: (15,13)->(14,11) */ - - Shipment shipment1 = Shipment.Builder.newInstance("1").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(5, 7))).setDeliveryLocation(loc(Coordinate.newInstance(6, 9))).build(); - Shipment shipment2 = Shipment.Builder.newInstance("2").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(5, 13))).setDeliveryLocation(loc(Coordinate.newInstance(6, 11))).build(); - - Shipment shipment3 = Shipment.Builder.newInstance("3").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(15, 7))).setDeliveryLocation(loc(Coordinate.newInstance(14, 9))).build(); - Shipment shipment4 = Shipment.Builder.newInstance("4").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(15, 13))).setDeliveryLocation(loc(Coordinate.newInstance(14, 11))).build(); -// - /* - * build deliveries, (implicitly picked up in the depot) + + Shipment shipment1 = Shipment.Builder.newInstance("1").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(5, 7))).setDeliveryLocation(loc(Coordinate.newInstance(6, 9))).build(); + Shipment shipment2 = Shipment.Builder.newInstance("2").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(5, 13))).setDeliveryLocation(loc(Coordinate.newInstance(6, 11))).build(); + + Shipment shipment3 = Shipment.Builder.newInstance("3").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(15, 7))).setDeliveryLocation(loc(Coordinate.newInstance(14, 9))).build(); + Shipment shipment4 = Shipment.Builder.newInstance("4").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(15, 13))).setDeliveryLocation(loc(Coordinate.newInstance(14, 11))).build(); +// + /* + * build deliveries, (implicitly picked up in the depot) * 1: (4,8) * 2: (4,12) * 3: (16,8) * 4: (16,12) */ - Delivery delivery1 = (Delivery) Delivery.Builder.newInstance("5").addSizeDimension(0, 1).setLocation(loc(Coordinate.newInstance(4, 8))).build(); - Delivery delivery2 = (Delivery) Delivery.Builder.newInstance("6").addSizeDimension(0, 1).setLocation(loc(Coordinate.newInstance(4, 12))).build(); - Delivery delivery3 = (Delivery) Delivery.Builder.newInstance("7").addSizeDimension(0, 1).setLocation(loc(Coordinate.newInstance(16, 8))).build(); - Delivery delivery4 = (Delivery) Delivery.Builder.newInstance("8").addSizeDimension(0, 1).setLocation(loc(Coordinate.newInstance(16, 12))).build(); - - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - vrpBuilder.addVehicle(vehicle); - vrpBuilder.addJob(shipment1).addJob(shipment2).addJob(shipment3).addJob(shipment4) - .addJob(delivery1).addJob(delivery2).addJob(delivery3).addJob(delivery4).build(); + Delivery delivery1 = (Delivery) Delivery.Builder.newInstance("5").addSizeDimension(0, 1).setLocation(loc(Coordinate.newInstance(4, 8))).build(); + Delivery delivery2 = (Delivery) Delivery.Builder.newInstance("6").addSizeDimension(0, 1).setLocation(loc(Coordinate.newInstance(4, 12))).build(); + Delivery delivery3 = (Delivery) Delivery.Builder.newInstance("7").addSizeDimension(0, 1).setLocation(loc(Coordinate.newInstance(16, 8))).build(); + Delivery delivery4 = (Delivery) Delivery.Builder.newInstance("8").addSizeDimension(0, 1).setLocation(loc(Coordinate.newInstance(16, 12))).build(); + + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + vrpBuilder.addVehicle(vehicle); + vrpBuilder.addJob(shipment1).addJob(shipment2).addJob(shipment3).addJob(shipment4) + .addJob(delivery1).addJob(delivery2).addJob(delivery3).addJob(delivery4).build(); + + VehicleRoutingProblem problem = vrpBuilder.build(); - VehicleRoutingProblem problem = vrpBuilder.build(); - /* - * build the algorithm + * build the algorithm */ - VehicleRoutingAlgorithmBuilder vraBuilder = new VehicleRoutingAlgorithmBuilder(problem,"input/algorithmConfig.xml"); + VehicleRoutingAlgorithmBuilder vraBuilder = new VehicleRoutingAlgorithmBuilder(problem, "input/algorithmConfig.xml"); vraBuilder.addCoreConstraints(); vraBuilder.addDefaultCostCalculators(); StateManager stateManager = new StateManager(problem); - ConstraintManager constraintManager = new ConstraintManager(problem,stateManager); + ConstraintManager constraintManager = new ConstraintManager(problem, stateManager); constraintManager.addConstraint(new ServiceDeliveriesFirstConstraint(), ConstraintManager.Priority.CRITICAL); - vraBuilder.setStateAndConstraintManager(stateManager,constraintManager); + vraBuilder.setStateAndConstraintManager(stateManager, constraintManager); VehicleRoutingAlgorithm algorithm = vraBuilder.build(); - + /* - * and search a solution + * and search a solution */ - Collection solutions = algorithm.searchSolutions(); - + Collection solutions = algorithm.searchSolutions(); + /* - * get the best + * get the best */ - VehicleRoutingProblemSolution bestSolution = Solutions.bestOf(solutions); - - new VrpXMLWriter(problem, solutions).write("output/mixed-shipments-services-problem-with-solution.xml"); - - SolutionPrinter.print(bestSolution); - + VehicleRoutingProblemSolution bestSolution = Solutions.bestOf(solutions); + + new VrpXMLWriter(problem, solutions).write("output/mixed-shipments-services-problem-with-solution.xml"); + + SolutionPrinter.print(bestSolution); + /* * plot */ - Plotter problemPlotter = new Plotter(problem); - problemPlotter.plotShipments(true); - problemPlotter.plot("output/simpleMixedEnRoutePickupAndDeliveryExample_problem.png", "en-route pd and depot bounded deliveries"); - - Plotter solutionPlotter = new Plotter(problem,Solutions.bestOf(solutions)); - solutionPlotter.plotShipments(true); - solutionPlotter.plot("output/simpleMixedEnRoutePickupAndDeliveryExample_solution.png", "en-route pd and depot bounded deliveries"); - - } + Plotter problemPlotter = new Plotter(problem); + problemPlotter.plotShipments(true); + problemPlotter.plot("output/simpleMixedEnRoutePickupAndDeliveryExample_problem.png", "en-route pd and depot bounded deliveries"); - private static Location loc(Coordinate coordinate) { - return Location.Builder.newInstance().setCoordinate(coordinate).build(); - } + Plotter solutionPlotter = new Plotter(problem, Solutions.bestOf(solutions)); + solutionPlotter.plotShipments(true); + solutionPlotter.plot("output/simpleMixedEnRoutePickupAndDeliveryExample_solution.png", "en-route pd and depot bounded deliveries"); + + } + + private static Location loc(Coordinate coordinate) { + return Location.Builder.newInstance().setCoordinate(coordinate).build(); + } } diff --git a/jsprit-examples/src/main/java/jsprit/examples/SimpleExample.java b/jsprit-examples/src/main/java/jsprit/examples/SimpleExample.java index 029d3947..e03f1eec 100644 --- a/jsprit-examples/src/main/java/jsprit/examples/SimpleExample.java +++ b/jsprit-examples/src/main/java/jsprit/examples/SimpleExample.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.examples; @@ -37,77 +37,76 @@ import java.util.Collection; public class SimpleExample { - - - - public static void main(String[] args) { - /* - * some preparation - create output folder - */ - File dir = new File("output"); - // if the directory does not exist, create it - if (!dir.exists()){ - System.out.println("creating directory ./output"); - boolean result = dir.mkdir(); - if(result) System.out.println("./output created"); - } - - /* - * 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); - VehicleType vehicleType = vehicleTypeBuilder.build(); - - /* - * get a vehicle-builder and build a vehicle located at (10,10) with type "vehicleType" - */ - Builder vehicleBuilder = VehicleImpl.Builder.newInstance("vehicle"); - vehicleBuilder.setStartLocation(Location.newInstance(10, 10)); - vehicleBuilder.setType(vehicleType); - VehicleImpl vehicle = vehicleBuilder.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 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); - VehicleRoutingProblem problem = vrpBuilder.build(); - - /* - * get the algorithm out-of-the-box. + + public static void main(String[] args) { + /* + * some preparation - create output folder */ - VehicleRoutingAlgorithm algorithm = new SchrimpfFactory().createAlgorithm(problem); - + File dir = new File("output"); + // if the directory does not exist, create it + if (!dir.exists()) { + System.out.println("creating directory ./output"); + boolean result = dir.mkdir(); + if (result) System.out.println("./output created"); + } + /* - * and search a solution + * 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 */ - Collection solutions = algorithm.searchSolutions(); - + final int WEIGHT_INDEX = 0; + VehicleTypeImpl.Builder vehicleTypeBuilder = VehicleTypeImpl.Builder.newInstance("vehicleType").addCapacityDimension(WEIGHT_INDEX, 2); + VehicleType vehicleType = vehicleTypeBuilder.build(); + /* - * get the best + * get a vehicle-builder and build a vehicle located at (10,10) with type "vehicleType" */ - VehicleRoutingProblemSolution bestSolution = Solutions.bestOf(solutions); - - new VrpXMLWriter(problem, solutions).write("output/problem-with-solution.xml"); - - SolutionPrinter.print(problem, bestSolution, SolutionPrinter.Print.VERBOSE); - + Builder vehicleBuilder = VehicleImpl.Builder.newInstance("vehicle"); + vehicleBuilder.setStartLocation(Location.newInstance(10, 10)); + vehicleBuilder.setType(vehicleType); + VehicleImpl vehicle = vehicleBuilder.build(); + /* - * plot + * 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 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); + + VehicleRoutingProblem problem = vrpBuilder.build(); + + /* + * get the algorithm out-of-the-box. + */ + VehicleRoutingAlgorithm algorithm = new SchrimpfFactory().createAlgorithm(problem); + + /* + * and search a solution + */ + Collection solutions = algorithm.searchSolutions(); + + /* + * get the best + */ + VehicleRoutingProblemSolution bestSolution = Solutions.bestOf(solutions); + + new VrpXMLWriter(problem, solutions).write("output/problem-with-solution.xml"); + + SolutionPrinter.print(problem, bestSolution, SolutionPrinter.Print.VERBOSE); + + /* + * plot */ // SolutionPlotter.plotSolutionAsPNG(problem, bestSolution, "output/solution.png", "solution"); - - new GraphStreamViewer(problem, bestSolution).labelWith(Label.ID).setRenderDelay(200).display(); - } + + new GraphStreamViewer(problem, bestSolution).labelWith(Label.ID).setRenderDelay(200).display(); + } } diff --git a/jsprit-examples/src/main/java/jsprit/examples/SimpleExampleOpenRoutes.java b/jsprit-examples/src/main/java/jsprit/examples/SimpleExampleOpenRoutes.java index 23257b90..b56b01e9 100644 --- a/jsprit-examples/src/main/java/jsprit/examples/SimpleExampleOpenRoutes.java +++ b/jsprit-examples/src/main/java/jsprit/examples/SimpleExampleOpenRoutes.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.examples; @@ -36,71 +36,71 @@ import java.util.Collection; public class SimpleExampleOpenRoutes { - - public static void main(String[] args) { - /* - * some preparation - create output folder + + public static void main(String[] args) { + /* + * some preparation - create output folder */ - Examples.createOutputFolder(); - + Examples.createOutputFolder(); + /* - * get a vehicle type-builder and build a type with the typeId "vehicleType" and a capacity of 2 + * get a vehicle type-builder and build a type with the typeId "vehicleType" and a capacity of 2 */ - VehicleTypeImpl.Builder vehicleTypeBuilder = VehicleTypeImpl.Builder.newInstance("vehicleType").addCapacityDimension(0, 2); - vehicleTypeBuilder.setFixedCost(100); - VehicleType vehicleType = vehicleTypeBuilder.build(); - + VehicleTypeImpl.Builder vehicleTypeBuilder = VehicleTypeImpl.Builder.newInstance("vehicleType").addCapacityDimension(0, 2); + vehicleTypeBuilder.setFixedCost(100); + VehicleType vehicleType = vehicleTypeBuilder.build(); + /* - * get a vehicle-builder and build a vehicle located at (10,10) with type "vehicleType" + * get a vehicle-builder and build a vehicle located at (10,10) with type "vehicleType" */ - Builder vehicleBuilder = VehicleImpl.Builder.newInstance("vehicle"); - vehicleBuilder.setStartLocation(Location.newInstance(10, 10)); - vehicleBuilder.setType(vehicleType); - vehicleBuilder.setReturnToDepot(false); - - VehicleImpl vehicle = vehicleBuilder.build(); - + Builder vehicleBuilder = VehicleImpl.Builder.newInstance("vehicle"); + vehicleBuilder.setStartLocation(Location.newInstance(10, 10)); + vehicleBuilder.setType(vehicleType); + vehicleBuilder.setReturnToDepot(false); + + VehicleImpl vehicle = vehicleBuilder.build(); + /* - * build services at the required locations, each with a capacity-demand of 1. + * build services at the required locations, each with a capacity-demand of 1. */ - Service service1 = Service.Builder.newInstance("1").addSizeDimension(0, 1).setLocation(Location.newInstance(5, 7)).build(); - Service service2 = Service.Builder.newInstance("2").addSizeDimension(0, 1).setLocation(Location.newInstance(5, 13)).build(); - - Service service3 = Service.Builder.newInstance("3").addSizeDimension(0, 1).setLocation(Location.newInstance(15, 7)).build(); - Service service4 = Service.Builder.newInstance("4").addSizeDimension(0, 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); - - VehicleRoutingProblem problem = vrpBuilder.build(); - + Service service1 = Service.Builder.newInstance("1").addSizeDimension(0, 1).setLocation(Location.newInstance(5, 7)).build(); + Service service2 = Service.Builder.newInstance("2").addSizeDimension(0, 1).setLocation(Location.newInstance(5, 13)).build(); + + Service service3 = Service.Builder.newInstance("3").addSizeDimension(0, 1).setLocation(Location.newInstance(15, 7)).build(); + Service service4 = Service.Builder.newInstance("4").addSizeDimension(0, 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); + + VehicleRoutingProblem problem = vrpBuilder.build(); + /* - * get the algorithm out-of-the-box. + * get the algorithm out-of-the-box. */ - VehicleRoutingAlgorithm algorithm = VehicleRoutingAlgorithms.readAndCreateAlgorithm(problem, "input/algorithmConfig_fix.xml"); - + VehicleRoutingAlgorithm algorithm = VehicleRoutingAlgorithms.readAndCreateAlgorithm(problem, "input/algorithmConfig_fix.xml"); + /* - * and search a solution + * and search a solution */ - Collection solutions = algorithm.searchSolutions(); - + Collection solutions = algorithm.searchSolutions(); + /* - * get the best + * get the best */ - VehicleRoutingProblemSolution bestSolution = Solutions.bestOf(solutions); - - new VrpXMLWriter(problem, solutions).write("output/problem-with-solution.xml"); - - SolutionPrinter.print(bestSolution); - + VehicleRoutingProblemSolution bestSolution = Solutions.bestOf(solutions); + + new VrpXMLWriter(problem, solutions).write("output/problem-with-solution.xml"); + + SolutionPrinter.print(bestSolution); + /* - * plot + * plot */ - - new Plotter(problem, bestSolution).plot("output/solution.png", "solution"); - - } + + new Plotter(problem, bestSolution).plot("output/solution.png", "solution"); + + } } diff --git a/jsprit-examples/src/main/java/jsprit/examples/SimpleExampleWithSkills.java b/jsprit-examples/src/main/java/jsprit/examples/SimpleExampleWithSkills.java index d64d0ee1..b6b72b54 100644 --- a/jsprit-examples/src/main/java/jsprit/examples/SimpleExampleWithSkills.java +++ b/jsprit-examples/src/main/java/jsprit/examples/SimpleExampleWithSkills.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.examples; @@ -41,61 +41,60 @@ import java.util.Collection; public class SimpleExampleWithSkills { - - public static void main(String[] args) { - /* - * some preparation - create output folder + public static void main(String[] args) { + /* + * some preparation - create output folder */ - File dir = new File("output"); - // if the directory does not exist, create it - if (!dir.exists()){ - System.out.println("creating directory ./output"); - boolean result = dir.mkdir(); - if(result) System.out.println("./output created"); - } + File dir = new File("output"); + // if the directory does not exist, create it + if (!dir.exists()) { + System.out.println("creating directory ./output"); + boolean result = dir.mkdir(); + if (result) System.out.println("./output created"); + } /* - * 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); - VehicleType vehicleType = vehicleTypeBuilder.build(); + final int WEIGHT_INDEX = 0; + VehicleTypeImpl.Builder vehicleTypeBuilder = VehicleTypeImpl.Builder.newInstance("vehicleType").addCapacityDimension(WEIGHT_INDEX, 2); + VehicleType vehicleType = vehicleTypeBuilder.build(); /* - * get a vehicle-builder and build a vehicle located at (10,10) with type "vehicleType" + * get a vehicle-builder and build a vehicle located at (10,10) with type "vehicleType" */ - Builder vehicleBuilder = Builder.newInstance("vehicle"); - vehicleBuilder.setStartLocation(Location.newInstance(10, 10)); - vehicleBuilder.setType(vehicleType); - VehicleImpl vehicle = vehicleBuilder.build(); + Builder vehicleBuilder = Builder.newInstance("vehicle"); + vehicleBuilder.setStartLocation(Location.newInstance(10, 10)); + vehicleBuilder.setType(vehicleType); + VehicleImpl vehicle = vehicleBuilder.build(); Builder vehicle2Builder = Builder.newInstance("vehicle2"); vehicle2Builder.setStartLocation(Location.newInstance(1, 1)); vehicle2Builder.setType(vehicleType); vehicle2Builder.addSkill("drill"); VehicleImpl vehicle2 = vehicle2Builder.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 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).addRequiredSkill("drill").setLocation(Location.newInstance(15, 13)).build(); - - - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - vrpBuilder.addVehicle(vehicle).addVehicle(vehicle2); - vrpBuilder.addJob(service1).addJob(service2).addJob(service3).addJob(service4); - - VehicleRoutingProblem problem = vrpBuilder.build(); - /* - * get the algorithm out-of-the-box. + * build services at the required locations, each with a capacity-demand of 1. */ - VehicleRoutingAlgorithmBuilder vraBuilder = new VehicleRoutingAlgorithmBuilder(problem,"input/algorithmConfig.xml"); + 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).addRequiredSkill("drill").setLocation(Location.newInstance(15, 13)).build(); + + + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + vrpBuilder.addVehicle(vehicle).addVehicle(vehicle2); + vrpBuilder.addJob(service1).addJob(service2).addJob(service3).addJob(service4); + + VehicleRoutingProblem problem = vrpBuilder.build(); + + /* + * get the algorithm out-of-the-box. + */ + VehicleRoutingAlgorithmBuilder vraBuilder = new VehicleRoutingAlgorithmBuilder(problem, "input/algorithmConfig.xml"); vraBuilder.addCoreConstraints(); vraBuilder.addDefaultCostCalculators(); @@ -103,33 +102,33 @@ public class SimpleExampleWithSkills { StateManager stateManager = new StateManager(problem); stateManager.updateSkillStates(); - ConstraintManager constraintManager = new ConstraintManager(problem,stateManager); + ConstraintManager constraintManager = new ConstraintManager(problem, stateManager); constraintManager.addSkillsConstraint(); - vraBuilder.setStateAndConstraintManager(stateManager,constraintManager); + vraBuilder.setStateAndConstraintManager(stateManager, constraintManager); + + VehicleRoutingAlgorithm algorithm = vraBuilder.build(); - VehicleRoutingAlgorithm algorithm = vraBuilder.build(); - /* - * and search a solution + * and search a solution */ - Collection solutions = algorithm.searchSolutions(); - + Collection solutions = algorithm.searchSolutions(); + /* - * get the best + * get the best */ - VehicleRoutingProblemSolution bestSolution = Solutions.bestOf(solutions); - - new VrpXMLWriter(problem, solutions).write("output/problem-with-solution.xml"); - - SolutionPrinter.print(problem, bestSolution, SolutionPrinter.Print.VERBOSE); - + VehicleRoutingProblemSolution bestSolution = Solutions.bestOf(solutions); + + new VrpXMLWriter(problem, solutions).write("output/problem-with-solution.xml"); + + SolutionPrinter.print(problem, bestSolution, SolutionPrinter.Print.VERBOSE); + /* - * plot + * plot */ // SolutionPlotter.plotSolutionAsPNG(problem, bestSolution, "output/solution.png", "solution"); - - new GraphStreamViewer(problem, bestSolution).labelWith(Label.ID).setRenderDelay(200).display(); - } + + new GraphStreamViewer(problem, bestSolution).labelWith(Label.ID).setRenderDelay(200).display(); + } } diff --git a/jsprit-examples/src/main/java/jsprit/examples/SimpleVRPWithBackhaulsExample.java b/jsprit-examples/src/main/java/jsprit/examples/SimpleVRPWithBackhaulsExample.java index 99eb6413..a831be8b 100644 --- a/jsprit-examples/src/main/java/jsprit/examples/SimpleVRPWithBackhaulsExample.java +++ b/jsprit-examples/src/main/java/jsprit/examples/SimpleVRPWithBackhaulsExample.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.examples; @@ -41,74 +41,74 @@ import java.util.Collection; public class SimpleVRPWithBackhaulsExample { - - public static void main(String[] args) { - /* - * some preparation - create output folder - */ - Examples.createOutputFolder(); - - /* - * get a vehicle type-builder and build a type with the typeId "vehicleType" and a capacity of 2 - */ - VehicleTypeImpl.Builder vehicleTypeBuilder = VehicleTypeImpl.Builder.newInstance("vehicleType").addCapacityDimension(0, 2); - VehicleType vehicleType = vehicleTypeBuilder.build(); - - /* - * get a vehicle-builder and build a vehicle located at (10,10) with type "vehicleType" - */ - Builder vehicleBuilder = VehicleImpl.Builder.newInstance("vehicle"); - vehicleBuilder.setStartLocation(Location.newInstance(10, 10)); - vehicleBuilder.setType(vehicleType); - VehicleImpl vehicle = vehicleBuilder.build(); - - /* - * build pickups and deliveries at the required locations, each with a capacity-demand of 1. - */ - Pickup pickup1 = (Pickup) Pickup.Builder.newInstance("1").addSizeDimension(0, 1).setLocation(Location.newInstance(5, 7)).build(); - Delivery delivery1 = (Delivery) Delivery.Builder.newInstance("2").addSizeDimension(0, 1).setLocation(Location.newInstance(5, 13)).build(); - - Pickup pickup2 = (Pickup) Pickup.Builder.newInstance("3").addSizeDimension(0, 1).setLocation(Location.newInstance(15, 7)).build(); - Delivery delivery2 = (Delivery) Delivery.Builder.newInstance("4").addSizeDimension(0, 1).setLocation(Location.newInstance(15, 13)).build(); - - - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - vrpBuilder.addVehicle(vehicle); - - vrpBuilder.addJob(pickup1).addJob(pickup2).addJob(delivery1).addJob(delivery2); - VehicleRoutingProblem problem = vrpBuilder.build(); + public static void main(String[] args) { + /* + * some preparation - create output folder + */ + Examples.createOutputFolder(); - VehicleRoutingAlgorithmBuilder vraBuilder = new VehicleRoutingAlgorithmBuilder(problem,"input/algorithmConfig.xml"); + /* + * get a vehicle type-builder and build a type with the typeId "vehicleType" and a capacity of 2 + */ + VehicleTypeImpl.Builder vehicleTypeBuilder = VehicleTypeImpl.Builder.newInstance("vehicleType").addCapacityDimension(0, 2); + VehicleType vehicleType = vehicleTypeBuilder.build(); + + /* + * get a vehicle-builder and build a vehicle located at (10,10) with type "vehicleType" + */ + Builder vehicleBuilder = VehicleImpl.Builder.newInstance("vehicle"); + vehicleBuilder.setStartLocation(Location.newInstance(10, 10)); + vehicleBuilder.setType(vehicleType); + VehicleImpl vehicle = vehicleBuilder.build(); + + /* + * build pickups and deliveries at the required locations, each with a capacity-demand of 1. + */ + Pickup pickup1 = Pickup.Builder.newInstance("1").addSizeDimension(0, 1).setLocation(Location.newInstance(5, 7)).build(); + Delivery delivery1 = Delivery.Builder.newInstance("2").addSizeDimension(0, 1).setLocation(Location.newInstance(5, 13)).build(); + + Pickup pickup2 = Pickup.Builder.newInstance("3").addSizeDimension(0, 1).setLocation(Location.newInstance(15, 7)).build(); + Delivery delivery2 = Delivery.Builder.newInstance("4").addSizeDimension(0, 1).setLocation(Location.newInstance(15, 13)).build(); + + + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + vrpBuilder.addVehicle(vehicle); + + vrpBuilder.addJob(pickup1).addJob(pickup2).addJob(delivery1).addJob(delivery2); + + VehicleRoutingProblem problem = vrpBuilder.build(); + + VehicleRoutingAlgorithmBuilder vraBuilder = new VehicleRoutingAlgorithmBuilder(problem, "input/algorithmConfig.xml"); vraBuilder.addCoreConstraints(); vraBuilder.addDefaultCostCalculators(); StateManager stateManager = new StateManager(problem); - ConstraintManager constraintManager = new ConstraintManager(problem,stateManager); + ConstraintManager constraintManager = new ConstraintManager(problem, stateManager); constraintManager.addConstraint(new ServiceDeliveriesFirstConstraint(), ConstraintManager.Priority.CRITICAL); - vraBuilder.setStateAndConstraintManager(stateManager,constraintManager); + vraBuilder.setStateAndConstraintManager(stateManager, constraintManager); VehicleRoutingAlgorithm algorithm = vraBuilder.build(); /* - * and search a solution + * and search a solution */ - Collection solutions = algorithm.searchSolutions(); - - /* - * get the best - */ - VehicleRoutingProblemSolution bestSolution = Solutions.bestOf(solutions); - - new VrpXMLWriter(problem, solutions).write("output/problem-with-solution.xml"); - - SolutionPrinter.print(bestSolution); - - /* - * plot - */ - Plotter plotter = new Plotter(problem,bestSolution); - plotter.setLabel(Label.SIZE); - plotter.plot("output/solution.png", "solution"); + Collection solutions = algorithm.searchSolutions(); - } + /* + * get the best + */ + VehicleRoutingProblemSolution bestSolution = Solutions.bestOf(solutions); + + new VrpXMLWriter(problem, solutions).write("output/problem-with-solution.xml"); + + SolutionPrinter.print(bestSolution); + + /* + * plot + */ + Plotter plotter = new Plotter(problem, bestSolution); + plotter.setLabel(Label.SIZE); + plotter.plot("output/solution.png", "solution"); + + } } diff --git a/jsprit-examples/src/main/java/jsprit/examples/SolomonExample.java b/jsprit-examples/src/main/java/jsprit/examples/SolomonExample.java index bac3308c..9f88e199 100644 --- a/jsprit-examples/src/main/java/jsprit/examples/SolomonExample.java +++ b/jsprit-examples/src/main/java/jsprit/examples/SolomonExample.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.examples; @@ -32,67 +32,67 @@ import java.util.Collection; public class SolomonExample { - - public static void main(String[] args) { - /* - * some preparation - create output folder + + public static void main(String[] args) { + /* + * some preparation - create output folder */ - Examples.createOutputFolder(); - + Examples.createOutputFolder(); + /* - * Build the problem. - * + * Build the problem. + * * But define a problem-builder first. */ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + /* - * A solomonReader reads solomon-instance files, and stores the required information in the builder. + * A solomonReader reads solomon-instance files, and stores the required information in the builder. */ - new SolomonReader(vrpBuilder).read("input/C101_solomon.txt"); + new SolomonReader(vrpBuilder).read("input/C101_solomon.txt"); /* - * Finally, the problem can be built. By default, transportCosts are crowFlyDistances (as usually used for vrp-instances). + * Finally, the problem can be built. By default, transportCosts are crowFlyDistances (as usually used for vrp-instances). */ - VehicleRoutingProblem vrp = vrpBuilder.build(); + VehicleRoutingProblem vrp = vrpBuilder.build(); + + new Plotter(vrp).plot("output/solomon_C101.png", "C101"); - new Plotter(vrp).plot("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. */ - VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp); + VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp); /* - * Solve the problem. - * + * Solve the problem. + * * */ - Collection solutions = vra.searchSolutions(); - + Collection solutions = vra.searchSolutions(); + /* - * Retrieve best solution. + * Retrieve best solution. */ - VehicleRoutingProblemSolution solution = new SelectBest().selectSolution(solutions); + VehicleRoutingProblemSolution solution = new SelectBest().selectSolution(solutions); /* - * print solution + * print solution */ - SolutionPrinter.print(vrp, solution, SolutionPrinter.Print.VERBOSE); - + SolutionPrinter.print(vrp, solution, SolutionPrinter.Print.VERBOSE); + /* - * Plot solution. + * Plot solution. */ - Plotter plotter = new Plotter(vrp,solution); + Plotter plotter = new Plotter(vrp, solution); // plotter.setBoundingBox(30, 0, 50, 20); - plotter.plot("output/solomon_C101_solution.png", "C101"); + plotter.plot("output/solomon_C101_solution.png", "C101"); - new GraphStreamViewer(vrp,solution).setCameraView(30, 30, 0.25).labelWith(Label.ID).setRenderDelay(100).display(); - - } + new GraphStreamViewer(vrp, solution).setCameraView(30, 30, 0.25).labelWith(Label.ID).setRenderDelay(100).display(); + + } } diff --git a/jsprit-examples/src/main/java/jsprit/examples/SolomonExampleWithSpecifiedVehicleEndLocations.java b/jsprit-examples/src/main/java/jsprit/examples/SolomonExampleWithSpecifiedVehicleEndLocations.java index 6371c9f3..a6dfe33c 100644 --- a/jsprit-examples/src/main/java/jsprit/examples/SolomonExampleWithSpecifiedVehicleEndLocations.java +++ b/jsprit-examples/src/main/java/jsprit/examples/SolomonExampleWithSpecifiedVehicleEndLocations.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.examples; @@ -33,77 +33,77 @@ import java.util.Collection; public class SolomonExampleWithSpecifiedVehicleEndLocations { - - public static void main(String[] args) { - /* - * some preparation - create output folder + + public static void main(String[] args) { + /* + * some preparation - create output folder */ - File dir = new File("output"); - // if the directory does not exist, create it - if (!dir.exists()){ - System.out.println("creating directory ./output"); - boolean result = dir.mkdir(); - if(result) System.out.println("./output created"); - } - + File dir = new File("output"); + // if the directory does not exist, create it + if (!dir.exists()) { + System.out.println("creating directory ./output"); + boolean result = dir.mkdir(); + if (result) System.out.println("./output created"); + } + /* - * Build the problem. - * + * Build the problem. + * * But define a problem-builder first. */ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + /* - * A solomonReader reads solomon-instance files, and stores the required information in the builder. + * A solomonReader reads solomon-instance files, and stores the required information in the builder. */ - new VrpXMLReader(vrpBuilder).read("input/deliveries_solomon_specifiedVehicleEndLocations_c101.xml"); - + new VrpXMLReader(vrpBuilder).read("input/deliveries_solomon_specifiedVehicleEndLocations_c101.xml"); + /* - * Finally, the problem can be built. By default, transportCosts are crowFlyDistances (as usually used for vrp-instances). + * Finally, the problem can be built. By default, transportCosts are crowFlyDistances (as usually used for vrp-instances). */ - VehicleRoutingProblem vrp = vrpBuilder.build(); - - Plotter pblmPlotter = new Plotter(vrp); - pblmPlotter.plot("output/solomon_C101_specifiedVehicleEndLocations.png","C101"); - + VehicleRoutingProblem vrp = vrpBuilder.build(); + + Plotter pblmPlotter = new Plotter(vrp); + pblmPlotter.plot("output/solomon_C101_specifiedVehicleEndLocations.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. */ // VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp); - VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "input/algorithmConfig_fix.xml"); - vra.setMaxIterations(20000); + VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "input/algorithmConfig_fix.xml"); + vra.setMaxIterations(20000); // vra.setPrematureBreak(100); - vra.getAlgorithmListeners().addListener(new AlgorithmSearchProgressChartListener("output/sol_progress.png")); - /* - * Solve the problem. - * + vra.getAlgorithmListeners().addListener(new AlgorithmSearchProgressChartListener("output/sol_progress.png")); + /* + * Solve the problem. + * * */ - Collection solutions = vra.searchSolutions(); - + Collection solutions = vra.searchSolutions(); + /* - * Retrieve best solution. + * Retrieve best solution. */ - VehicleRoutingProblemSolution solution = new SelectBest().selectSolution(solutions); - + VehicleRoutingProblemSolution solution = new SelectBest().selectSolution(solutions); + /* * print solution */ - SolutionPrinter.print(solution); - + SolutionPrinter.print(solution); + /* - * Plot solution. + * Plot solution. */ // SolutionPlotter.plotSolutionAsPNG(vrp, solution, "output/solomon_C101_specifiedVehicleEndLocations_solution.png","C101"); - Plotter solPlotter = new Plotter(vrp, solution); - solPlotter.plot("output/solomon_C101_specifiedVehicleEndLocations_solution.png","C101"); - - - new GraphStreamViewer(vrp, solution).setRenderDelay(50).labelWith(Label.ID).setEnableAutoLayout(true).display(); - - - } + Plotter solPlotter = new Plotter(vrp, solution); + solPlotter.plot("output/solomon_C101_specifiedVehicleEndLocations_solution.png", "C101"); + + + new GraphStreamViewer(vrp, solution).setRenderDelay(50).labelWith(Label.ID).setEnableAutoLayout(true).display(); + + + } } diff --git a/jsprit-examples/src/main/java/jsprit/examples/SolomonExampleWithSpecifiedVehicleEndLocationsWithoutTWs.java b/jsprit-examples/src/main/java/jsprit/examples/SolomonExampleWithSpecifiedVehicleEndLocationsWithoutTWs.java index a5ed1922..72a6323b 100644 --- a/jsprit-examples/src/main/java/jsprit/examples/SolomonExampleWithSpecifiedVehicleEndLocationsWithoutTWs.java +++ b/jsprit-examples/src/main/java/jsprit/examples/SolomonExampleWithSpecifiedVehicleEndLocationsWithoutTWs.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.examples; @@ -32,78 +32,78 @@ import java.util.Collection; public class SolomonExampleWithSpecifiedVehicleEndLocationsWithoutTWs { - - public static void main(String[] args) { - /* - * some preparation - create output folder + + public static void main(String[] args) { + /* + * some preparation - create output folder */ - File dir = new File("output"); - // if the directory does not exist, create it - if (!dir.exists()){ - System.out.println("creating directory ./output"); - boolean result = dir.mkdir(); - if(result) System.out.println("./output created"); - } - + File dir = new File("output"); + // if the directory does not exist, create it + if (!dir.exists()) { + System.out.println("creating directory ./output"); + boolean result = dir.mkdir(); + if (result) System.out.println("./output created"); + } + /* - * Build the problem. - * + * Build the problem. + * * But define a problem-builder first. */ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + /* - * A solomonReader reads solomon-instance files, and stores the required information in the builder. + * A solomonReader reads solomon-instance files, and stores the required information in the builder. */ - new VrpXMLReader(vrpBuilder).read("input/pickups_and_deliveries_solomon_c101_withoutTWs_and_specifiedVehicleEndLocations.xml"); - + new VrpXMLReader(vrpBuilder).read("input/pickups_and_deliveries_solomon_c101_withoutTWs_and_specifiedVehicleEndLocations.xml"); + /* - * Finally, the problem can be built. By default, transportCosts are crowFlyDistances (as usually used for vrp-instances). + * Finally, the problem can be built. By default, transportCosts are crowFlyDistances (as usually used for vrp-instances). */ // vrpBuilder.addProblemConstraint(Constraint.DELIVERIES_FIRST); - VehicleRoutingProblem vrp = vrpBuilder.build(); - - Plotter pblmPlotter = new Plotter(vrp); - pblmPlotter.plot("output/solomon_C101_specifiedVehicleEndLocations_withoutTWs.png","C101"); - + VehicleRoutingProblem vrp = vrpBuilder.build(); + + Plotter pblmPlotter = new Plotter(vrp); + pblmPlotter.plot("output/solomon_C101_specifiedVehicleEndLocations_withoutTWs.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. */ // VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp); - VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "input/algorithmConfigWithSchrimpfAcceptance.xml"); - vra.setMaxIterations(20000); + VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "input/algorithmConfigWithSchrimpfAcceptance.xml"); + vra.setMaxIterations(20000); // vra.setPrematureBreak(100); // vra.getAlgorithmListeners().addListener(new AlgorithmSearchProgressChartListener("output/sol_progress.png")); - /* - * Solve the problem. - * + /* + * Solve the problem. + * * */ - Collection solutions = vra.searchSolutions(); - + Collection solutions = vra.searchSolutions(); + /* - * Retrieve best solution. + * Retrieve best solution. */ - VehicleRoutingProblemSolution solution = new SelectBest().selectSolution(solutions); - + VehicleRoutingProblemSolution solution = new SelectBest().selectSolution(solutions); + /* * print solution */ - SolutionPrinter.print(solution); - + SolutionPrinter.print(solution); + /* - * Plot solution. + * Plot solution. */ // SolutionPlotter.plotSolutionAsPNG(vrp, solution, "output/solomon_C101_specifiedVehicleEndLocations_solution.png","C101"); - Plotter solPlotter = new Plotter(vrp, solution); - solPlotter.plot("output/solomon_C101_specifiedVehicleEndLocations_withoutTWs_solution.png","C101"); - - - new GraphStreamViewer(vrp, solution).setRenderDelay(50).labelWith(Label.ID).setEnableAutoLayout(true).display(); - - - } + Plotter solPlotter = new Plotter(vrp, solution); + solPlotter.plot("output/solomon_C101_specifiedVehicleEndLocations_withoutTWs_solution.png", "C101"); + + + new GraphStreamViewer(vrp, solution).setRenderDelay(50).labelWith(Label.ID).setEnableAutoLayout(true).display(); + + + } } diff --git a/jsprit-examples/src/main/java/jsprit/examples/SolomonOpenExample.java b/jsprit-examples/src/main/java/jsprit/examples/SolomonOpenExample.java index 685a38c7..e32c5296 100644 --- a/jsprit-examples/src/main/java/jsprit/examples/SolomonOpenExample.java +++ b/jsprit-examples/src/main/java/jsprit/examples/SolomonOpenExample.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.examples; @@ -32,68 +32,68 @@ import java.util.Collection; public class SolomonOpenExample { - - public static void main(String[] args) { - /* - * some preparation - create output folder + + public static void main(String[] args) { + /* + * some preparation - create output folder */ - Examples.createOutputFolder(); - + Examples.createOutputFolder(); + /* - * Build the problem. - * + * Build the problem. + * * But define a problem-builder first. */ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + /* - * A solomonReader reads solomon-instance files, and stores the required information in the builder. + * A solomonReader reads solomon-instance files, and stores the required information in the builder. */ - new VrpXMLReader(vrpBuilder).read("input/deliveries_solomon_open_c101.xml"); - + new VrpXMLReader(vrpBuilder).read("input/deliveries_solomon_open_c101.xml"); + /* - * Finally, the problem can be built. By default, transportCosts are crowFlyDistances (as usually used for vrp-instances). + * Finally, the problem can be built. By default, transportCosts are crowFlyDistances (as usually used for vrp-instances). */ - VehicleRoutingProblem vrp = vrpBuilder.build(); - - new Plotter(vrp).plot("output/solomon_C101_open.png", "C101"); - + VehicleRoutingProblem vrp = vrpBuilder.build(); + + new Plotter(vrp).plot("output/solomon_C101_open.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. */ // VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp); // VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "input/algorithmConfig_fix.xml"); - VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp); + VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp); // vra.setPrematureBreak(100); // vra.getAlgorithmListeners().addListener(new AlgorithmSearchProgressChartListener("output/sol_progress.png")); - /* - * Solve the problem. - * + /* + * Solve the problem. + * * */ - Collection solutions = vra.searchSolutions(); - + Collection solutions = vra.searchSolutions(); + /* - * Retrieve best solution. + * Retrieve best solution. */ - VehicleRoutingProblemSolution solution = new SelectBest().selectSolution(solutions); - + VehicleRoutingProblemSolution solution = new SelectBest().selectSolution(solutions); + /* * print solution */ - SolutionPrinter.print(solution); - + SolutionPrinter.print(solution); + /* - * Plot solution. + * Plot solution. */ // SolutionPlotter.plotSolutionAsPNG(vrp, solution, "output/solomon_C101_open_solution.png","C101"); - - - new GraphStreamViewer(vrp, solution).setRenderDelay(150).labelWith(Label.ID).setEnableAutoLayout(true).display(); - - - } + + + new GraphStreamViewer(vrp, solution).setRenderDelay(150).labelWith(Label.ID).setEnableAutoLayout(true).display(); + + + } } diff --git a/jsprit-examples/src/main/java/jsprit/examples/SolomonR101Example.java b/jsprit-examples/src/main/java/jsprit/examples/SolomonR101Example.java index 3edd8fed..91658d11 100644 --- a/jsprit-examples/src/main/java/jsprit/examples/SolomonR101Example.java +++ b/jsprit-examples/src/main/java/jsprit/examples/SolomonR101Example.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.examples; @@ -32,65 +32,65 @@ import java.util.Collection; public class SolomonR101Example { - public static void main(String[] args) { - /* - * some preparation - create output folder + public static void main(String[] args) { + /* + * some preparation - create output folder */ - Examples.createOutputFolder(); + Examples.createOutputFolder(); /* - * Build the problem. + * Build the problem. * * But define a problem-builder first. */ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); /* - * A solomonReader reads solomon-instance files, and stores the required information in the builder. + * A solomonReader reads solomon-instance files, and stores the required information in the builder. */ // new SolomonReader(vrpBuilder).read("/Users/schroeder/IdeaProjects/jsprit/jsprit-instances/instances/solomon/R211.txt"); - new VrpXMLReader(vrpBuilder).read("output/R211.xml"); - /* - * Finally, the problem can be built. By default, transportCosts are crowFlyDistances (as usually used for vrp-instances). + new VrpXMLReader(vrpBuilder).read("output/R211.xml"); + /* + * Finally, the problem can be built. By default, transportCosts are crowFlyDistances (as usually used for vrp-instances). */ - VehicleRoutingProblem vrp = vrpBuilder.build(); + VehicleRoutingProblem vrp = vrpBuilder.build(); // new VrpXMLWriter(vrp).write("output/R211.xml"); // new Plotter(vrp).plot("output/solomon_R101.png", "R101"); /* - * 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. */ // VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp); - VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "input/algorithmConfig.xml"); + VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "input/algorithmConfig.xml"); vra.setMaxIterations(20000); // vra.setPrematureBreak(100); - vra.getAlgorithmListeners().addListener(new AlgorithmSearchProgressChartListener("output/sol_progress.png")); - /* - * Solve the problem. + vra.getAlgorithmListeners().addListener(new AlgorithmSearchProgressChartListener("output/sol_progress.png")); + /* + * Solve the problem. * * */ - Collection solutions = vra.searchSolutions(); + Collection solutions = vra.searchSolutions(); /* * Retrieve best solution. */ - VehicleRoutingProblemSolution solution = new SelectBest().selectSolution(solutions); + VehicleRoutingProblemSolution solution = new SelectBest().selectSolution(solutions); /* * print solution */ - SolutionPrinter.print(vrp,solution, SolutionPrinter.Print.VERBOSE); + SolutionPrinter.print(vrp, solution, SolutionPrinter.Print.VERBOSE); - new GraphStreamViewer(vrp,solution).display(); + new GraphStreamViewer(vrp, solution).display(); /* * Plot solution. */ // new Plotter(vrp,solution).plot( "output/solomon_R101_solution.png","R101"); - - } + + } } diff --git a/jsprit-examples/src/main/java/jsprit/examples/SolomonWithRegretInsertionExample.java b/jsprit-examples/src/main/java/jsprit/examples/SolomonWithRegretInsertionExample.java index 19d91188..a9b92a7a 100644 --- a/jsprit-examples/src/main/java/jsprit/examples/SolomonWithRegretInsertionExample.java +++ b/jsprit-examples/src/main/java/jsprit/examples/SolomonWithRegretInsertionExample.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.examples; @@ -34,77 +34,77 @@ import java.util.Collection; public class SolomonWithRegretInsertionExample { - - public static void main(String[] args) { - /* - * some preparation - create output folder + + public static void main(String[] args) { + /* + * some preparation - create output folder */ - Examples.createOutputFolder(); - + Examples.createOutputFolder(); + /* - * Build the problem. - * + * Build the problem. + * * But define a problem-builder first. */ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + /* - * A solomonReader reads solomon-instance files, and stores the required information in the builder. + * A solomonReader reads solomon-instance files, and stores the required information in the builder. */ - new SolomonReader(vrpBuilder).read("input/C101_solomon.txt"); + new SolomonReader(vrpBuilder).read("input/C101_solomon.txt"); /* - * Finally, the problem can be built. By default, transportCosts are crowFlyDistances (as usually used for vrp-instances). + * Finally, the problem can be built. By default, transportCosts are crowFlyDistances (as usually used for vrp-instances). */ - VehicleRoutingProblem vrp = vrpBuilder.build(); + VehicleRoutingProblem vrp = vrpBuilder.build(); + + new Plotter(vrp).plot("output/solomon_C101.png", "C101"); - new Plotter(vrp).plot("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. */ - VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "input/algorithmConfig_greedyWithRegret.xml"); + VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "input/algorithmConfig_greedyWithRegret.xml"); vra.setMaxIterations(2); - AlgorithmEventsRecorder eventsRecorder = new AlgorithmEventsRecorder(vrp,"output/events.dgs.gz"); - eventsRecorder.setRecordingRange(0,50); + AlgorithmEventsRecorder eventsRecorder = new AlgorithmEventsRecorder(vrp, "output/events.dgs.gz"); + eventsRecorder.setRecordingRange(0, 50); vra.addListener(eventsRecorder); /* - * Solve the problem. - * + * Solve the problem. + * * */ - Collection solutions = vra.searchSolutions(); - + Collection solutions = vra.searchSolutions(); + /* - * Retrieve best solution. + * Retrieve best solution. */ - VehicleRoutingProblemSolution solution = new SelectBest().selectSolution(solutions); + VehicleRoutingProblemSolution solution = new SelectBest().selectSolution(solutions); /* - * print solution + * print solution */ - SolutionPrinter.print(vrp, solution, SolutionPrinter.Print.VERBOSE); - + SolutionPrinter.print(vrp, solution, SolutionPrinter.Print.VERBOSE); + /* - * Plot solution. + * Plot solution. */ - Plotter plotter = new Plotter(vrp,solution); + Plotter plotter = new Plotter(vrp, solution); // plotter.setBoundingBox(30, 0, 50, 20); - plotter.plot("output/solomon_C101_solution.png", "C101"); + plotter.plot("output/solomon_C101_solution.png", "C101"); - new GraphStreamViewer(vrp,solution).labelWith(Label.ID).setRenderDelay(100).display(); + new GraphStreamViewer(vrp, solution).labelWith(Label.ID).setRenderDelay(100).display(); AlgorithmEventsViewer viewer = new AlgorithmEventsViewer(); viewer.setRuinDelay(16); viewer.setRecreationDelay(8); viewer.display("output/events.dgs.gz"); - - } + + } } diff --git a/jsprit-examples/src/main/java/jsprit/examples/SolomonWithSkillsExample.java b/jsprit-examples/src/main/java/jsprit/examples/SolomonWithSkillsExample.java index ab38de8f..5208e45a 100644 --- a/jsprit-examples/src/main/java/jsprit/examples/SolomonWithSkillsExample.java +++ b/jsprit-examples/src/main/java/jsprit/examples/SolomonWithSkillsExample.java @@ -51,35 +51,34 @@ public class SolomonWithSkillsExample { Vehicle solomonVehicle = vrp.getVehicles().iterator().next(); VehicleType newType = solomonVehicle.getType(); VehicleRoutingProblem.Builder skillProblemBuilder = VehicleRoutingProblem.Builder.newInstance(); - for(int i=0;i<5;i++) { + for (int i = 0; i < 5; i++) { VehicleImpl skill1Vehicle = VehicleImpl.Builder.newInstance("skill1_vehicle_" + i).addSkill("skill1") - .setStartLocation(Location.Builder.newInstance().setId(solomonVehicle.getStartLocation().getId()).setCoordinate(solomonVehicle.getStartLocation().getCoordinate()).build()) - .setEarliestStart(solomonVehicle.getEarliestDeparture()) - .setType(newType).build(); + .setStartLocation(Location.Builder.newInstance().setId(solomonVehicle.getStartLocation().getId()).setCoordinate(solomonVehicle.getStartLocation().getCoordinate()).build()) + .setEarliestStart(solomonVehicle.getEarliestDeparture()) + .setType(newType).build(); VehicleImpl skill2Vehicle = VehicleImpl.Builder.newInstance("skill2_vehicle_" + i).addSkill("skill2") - .setStartLocation(Location.Builder.newInstance().setId(solomonVehicle.getStartLocation().getId()) - .setCoordinate(solomonVehicle.getStartLocation().getCoordinate()).build()) - .setEarliestStart(solomonVehicle.getEarliestDeparture()) - .setType(newType).build(); + .setStartLocation(Location.Builder.newInstance().setId(solomonVehicle.getStartLocation().getId()) + .setCoordinate(solomonVehicle.getStartLocation().getCoordinate()).build()) + .setEarliestStart(solomonVehicle.getEarliestDeparture()) + .setType(newType).build(); skillProblemBuilder.addVehicle(skill1Vehicle).addVehicle(skill2Vehicle); } - for(Job job : vrp.getJobs().values()){ + for (Job job : vrp.getJobs().values()) { Service service = (Service) job; Service.Builder skillServiceBuilder; - if(service.getLocation().getCoordinate().getY()<50.){ + if (service.getLocation().getCoordinate().getY() < 50.) { skillServiceBuilder = Service.Builder.newInstance(service.getId() + "_skill2").setServiceTime(service.getServiceDuration()) - .setLocation(Location.Builder.newInstance().setId(service.getLocation().getId()) - .setCoordinate(service.getLocation().getCoordinate()).build()).setTimeWindow(service.getTimeWindow()) - .addSizeDimension(0, service.getSize().get(0)); + .setLocation(Location.Builder.newInstance().setId(service.getLocation().getId()) + .setCoordinate(service.getLocation().getCoordinate()).build()).setTimeWindow(service.getTimeWindow()) + .addSizeDimension(0, service.getSize().get(0)); skillServiceBuilder.addRequiredSkill("skill2"); - } - else { - skillServiceBuilder = Service.Builder.newInstance(service.getId()+"_skill1").setServiceTime(service.getServiceDuration()) - .setLocation( - Location.Builder.newInstance().setId(service.getLocation().getId()) - .setCoordinate(service.getLocation().getCoordinate()).build() - ).setTimeWindow(service.getTimeWindow()) - .addSizeDimension(0,service.getSize().get(0)); + } else { + skillServiceBuilder = Service.Builder.newInstance(service.getId() + "_skill1").setServiceTime(service.getServiceDuration()) + .setLocation( + Location.Builder.newInstance().setId(service.getLocation().getId()) + .setCoordinate(service.getLocation().getCoordinate()).build() + ).setTimeWindow(service.getTimeWindow()) + .addSizeDimension(0, service.getSize().get(0)); skillServiceBuilder.addRequiredSkill("skill1"); } skillProblemBuilder.addJob(skillServiceBuilder.build()); @@ -87,25 +86,25 @@ public class SolomonWithSkillsExample { skillProblemBuilder.setFleetSize(VehicleRoutingProblem.FleetSize.FINITE); VehicleRoutingProblem skillProblem = skillProblemBuilder.build(); - VehicleRoutingAlgorithmBuilder vraBuilder = new VehicleRoutingAlgorithmBuilder(skillProblem,"input/algorithmConfig_solomon.xml"); + VehicleRoutingAlgorithmBuilder vraBuilder = new VehicleRoutingAlgorithmBuilder(skillProblem, "input/algorithmConfig_solomon.xml"); vraBuilder.addCoreConstraints(); vraBuilder.addDefaultCostCalculators(); StateManager stateManager = new StateManager(skillProblem); stateManager.updateSkillStates(); - ConstraintManager constraintManager = new ConstraintManager(skillProblem,stateManager); + ConstraintManager constraintManager = new ConstraintManager(skillProblem, stateManager); constraintManager.addSkillsConstraint(); - VehicleRoutingAlgorithm vra = Jsprit.Builder.newInstance(skillProblem).setStateAndConstraintManager(stateManager,constraintManager).buildAlgorithm(); + VehicleRoutingAlgorithm vra = Jsprit.Builder.newInstance(skillProblem).setStateAndConstraintManager(stateManager, constraintManager).buildAlgorithm(); Collection solutions = vra.searchSolutions(); VehicleRoutingProblemSolution solution = Solutions.bestOf(solutions); SolutionPrinter.print(skillProblem, solution, SolutionPrinter.Print.VERBOSE); - new Plotter(skillProblem,solution).plot("output/skill_solution","solomon_with_skills"); + new Plotter(skillProblem, solution).plot("output/skill_solution", "solomon_with_skills"); - new VrpXMLWriter(skillProblem,solutions).write("output/solomon_with_skills"); + new VrpXMLWriter(skillProblem, solutions).write("output/solomon_with_skills"); } } diff --git a/jsprit-examples/src/main/java/jsprit/examples/TransportOfDisabledPeople.java b/jsprit-examples/src/main/java/jsprit/examples/TransportOfDisabledPeople.java index b764acb1..70ac4df0 100644 --- a/jsprit-examples/src/main/java/jsprit/examples/TransportOfDisabledPeople.java +++ b/jsprit-examples/src/main/java/jsprit/examples/TransportOfDisabledPeople.java @@ -43,189 +43,189 @@ import jsprit.util.Examples; import java.util.Collection; public class TransportOfDisabledPeople { - - static int WHEELCHAIRSPACE_INDEX = 0; - - static int PASSENGERSEATS_INDEX = 1; - - public static void main(String[] args) { - /* - * some preparation - create output folder + + static int WHEELCHAIRSPACE_INDEX = 0; + + static int PASSENGERSEATS_INDEX = 1; + + public static void main(String[] args) { + /* + * some preparation - create output folder */ - Examples.createOutputFolder(); - + Examples.createOutputFolder(); + /* - * get a vehicle type-builder and build a type with the typeId "vehicleType" and a capacity of 2 + * get a vehicle type-builder and build a type with the typeId "vehicleType" and a capacity of 2 */ - VehicleTypeImpl.Builder wheelChairTypeBuilder = VehicleTypeImpl.Builder.newInstance("wheelChairBusType") - .addCapacityDimension(WHEELCHAIRSPACE_INDEX, 2) //can transport two people with wheelchair - .addCapacityDimension(PASSENGERSEATS_INDEX, 4); //and 4 without - VehicleType vehicleType_wheelchair = wheelChairTypeBuilder.build(); - - VehicleTypeImpl.Builder soleyPassengerTypeBuilder = VehicleTypeImpl.Builder.newInstance("passengerBusType") - .addCapacityDimension(PASSENGERSEATS_INDEX, 6); //and 4 without - VehicleType vehicleType_solelypassenger = soleyPassengerTypeBuilder.build(); - + VehicleTypeImpl.Builder wheelChairTypeBuilder = VehicleTypeImpl.Builder.newInstance("wheelChairBusType") + .addCapacityDimension(WHEELCHAIRSPACE_INDEX, 2) //can transport two people with wheelchair + .addCapacityDimension(PASSENGERSEATS_INDEX, 4); //and 4 without + VehicleType vehicleType_wheelchair = wheelChairTypeBuilder.build(); + + VehicleTypeImpl.Builder soleyPassengerTypeBuilder = VehicleTypeImpl.Builder.newInstance("passengerBusType") + .addCapacityDimension(PASSENGERSEATS_INDEX, 6); //and 4 without + VehicleType vehicleType_solelypassenger = soleyPassengerTypeBuilder.build(); + /* - * define two vehicles and their locations. - * + * define two vehicles and their locations. + * * this example employs two vehicles. one that has to return to its start-location (vehicle1) and one that has a different * end-location. - * + * * play with these location to see which impact they have on customer-sequences. */ - Builder vehicleBuilder1 = VehicleImpl.Builder.newInstance("wheelchair_bus"); - vehicleBuilder1.setStartLocation(loc(Coordinate.newInstance(10, 10))); - vehicleBuilder1.setType(vehicleType_wheelchair); - VehicleImpl vehicle1 = vehicleBuilder1.build(); - - Builder vehicleBuilder1_2 = VehicleImpl.Builder.newInstance("wheelchair_bus_2"); - vehicleBuilder1_2.setStartLocation(loc(Coordinate.newInstance(10, 10))); - vehicleBuilder1_2.setType(vehicleType_wheelchair); - VehicleImpl vehicle1_2 = vehicleBuilder1_2.build(); - - Builder vehicleBuilder2 = VehicleImpl.Builder.newInstance("passenger_bus"); - vehicleBuilder2.setStartLocation(loc(Coordinate.newInstance(30, 30))).setEndLocation(loc(Coordinate.newInstance(30, 19))); - vehicleBuilder2.setType(vehicleType_solelypassenger); - VehicleImpl vehicle2 = vehicleBuilder2.build(); - - Builder vehicleBuilder2_2 = VehicleImpl.Builder.newInstance("passenger_bus_2"); - vehicleBuilder2_2.setStartLocation(loc(Coordinate.newInstance(30, 30))).setEndLocation(loc(Coordinate.newInstance(30, 19))); - vehicleBuilder2_2.setType(vehicleType_solelypassenger); - VehicleImpl vehicle2_2 = vehicleBuilder2_2.build(); - - + Builder vehicleBuilder1 = VehicleImpl.Builder.newInstance("wheelchair_bus"); + vehicleBuilder1.setStartLocation(loc(Coordinate.newInstance(10, 10))); + vehicleBuilder1.setType(vehicleType_wheelchair); + VehicleImpl vehicle1 = vehicleBuilder1.build(); + + Builder vehicleBuilder1_2 = VehicleImpl.Builder.newInstance("wheelchair_bus_2"); + vehicleBuilder1_2.setStartLocation(loc(Coordinate.newInstance(10, 10))); + vehicleBuilder1_2.setType(vehicleType_wheelchair); + VehicleImpl vehicle1_2 = vehicleBuilder1_2.build(); + + Builder vehicleBuilder2 = VehicleImpl.Builder.newInstance("passenger_bus"); + vehicleBuilder2.setStartLocation(loc(Coordinate.newInstance(30, 30))).setEndLocation(loc(Coordinate.newInstance(30, 19))); + vehicleBuilder2.setType(vehicleType_solelypassenger); + VehicleImpl vehicle2 = vehicleBuilder2.build(); + + Builder vehicleBuilder2_2 = VehicleImpl.Builder.newInstance("passenger_bus_2"); + vehicleBuilder2_2.setStartLocation(loc(Coordinate.newInstance(30, 30))).setEndLocation(loc(Coordinate.newInstance(30, 19))); + vehicleBuilder2_2.setType(vehicleType_solelypassenger); + VehicleImpl vehicle2_2 = vehicleBuilder2_2.build(); + + /* - * build shipments at the required locations, each with a capacity-demand of 1. - * + * build shipments at the required locations, each with a capacity-demand of 1. + * */ - Shipment shipment1 = Shipment.Builder.newInstance("wheelchair_1").addSizeDimension(WHEELCHAIRSPACE_INDEX, 1).setPickupLocation(loc(Coordinate.newInstance(5, 7))).setDeliveryLocation(loc(Coordinate.newInstance(6, 9))).build(); - Shipment shipment2 = Shipment.Builder.newInstance("2").addSizeDimension(PASSENGERSEATS_INDEX, 1).setPickupLocation(loc(Coordinate.newInstance(5, 13))).setDeliveryLocation(loc(Coordinate.newInstance(6, 11))).build(); - - Shipment shipment3 = Shipment.Builder.newInstance("wheelchair_2").addSizeDimension(WHEELCHAIRSPACE_INDEX, 1).setPickupLocation(loc(Coordinate.newInstance(15, 7))).setDeliveryLocation(loc(Coordinate.newInstance(14, 9))).build(); - Shipment shipment4 = Shipment.Builder.newInstance("4").addSizeDimension(PASSENGERSEATS_INDEX, 1).setPickupLocation(loc(Coordinate.newInstance(15, 13))).setDeliveryLocation(loc(Coordinate.newInstance(14, 11))).build(); - - Shipment shipment5 = Shipment.Builder.newInstance("wheelchair_3").addSizeDimension(WHEELCHAIRSPACE_INDEX, 1).setPickupLocation(loc(Coordinate.newInstance(25, 27))).setDeliveryLocation(loc(Coordinate.newInstance(26, 29))).build(); - Shipment shipment6 = Shipment.Builder.newInstance("6").addSizeDimension(PASSENGERSEATS_INDEX, 1).setPickupLocation(loc(Coordinate.newInstance(25, 33))).setDeliveryLocation(loc(Coordinate.newInstance(26, 31))).build(); - - Shipment shipment7 = Shipment.Builder.newInstance("7").addSizeDimension(PASSENGERSEATS_INDEX, 1).setPickupLocation(loc(Coordinate.newInstance(35, 27))).setDeliveryLocation(loc(Coordinate.newInstance(34, 29))).build(); - Shipment shipment8 = Shipment.Builder.newInstance("wheelchair_4").addSizeDimension(WHEELCHAIRSPACE_INDEX, 1).setPickupLocation(loc(Coordinate.newInstance(35, 33))).setDeliveryLocation(loc(Coordinate.newInstance(34, 31))).build(); - - Shipment shipment9 = Shipment.Builder.newInstance("9").addSizeDimension(PASSENGERSEATS_INDEX, 1).setPickupLocation(loc(Coordinate.newInstance(5, 27))).setDeliveryLocation(loc(Coordinate.newInstance(6, 29))).build(); - Shipment shipment10 = Shipment.Builder.newInstance("wheelchair_5").addSizeDimension(WHEELCHAIRSPACE_INDEX, 1).setPickupLocation(loc(Coordinate.newInstance(5, 33))).setDeliveryLocation(loc(Coordinate.newInstance(6, 31))).build(); - - Shipment shipment11 = Shipment.Builder.newInstance("11").addSizeDimension(PASSENGERSEATS_INDEX, 1).setPickupLocation(loc(Coordinate.newInstance(15, 27))).setDeliveryLocation(loc(Coordinate.newInstance(14, 29))).build(); - Shipment shipment12 = Shipment.Builder.newInstance("wheelchair_6").addSizeDimension(WHEELCHAIRSPACE_INDEX, 1).setPickupLocation(loc(Coordinate.newInstance(15, 33))).setDeliveryLocation(loc(Coordinate.newInstance(14, 31))).build(); - - Shipment shipment13 = Shipment.Builder.newInstance("13").addSizeDimension(PASSENGERSEATS_INDEX, 1).setPickupLocation(loc(Coordinate.newInstance(25, 7))).setDeliveryLocation(loc(Coordinate.newInstance(26, 9))).build(); - Shipment shipment14 = Shipment.Builder.newInstance("wheelchair_7").addSizeDimension(WHEELCHAIRSPACE_INDEX, 1).setPickupLocation(loc(Coordinate.newInstance(25, 13))).setDeliveryLocation(loc(Coordinate.newInstance(26, 11))).build(); - - Shipment shipment15 = Shipment.Builder.newInstance("15").addSizeDimension(PASSENGERSEATS_INDEX, 1).setPickupLocation(loc(Coordinate.newInstance(35, 7))).setDeliveryLocation(loc(Coordinate.newInstance(34, 9))).build(); - Shipment shipment16 = Shipment.Builder.newInstance("wheelchair_8").addSizeDimension(WHEELCHAIRSPACE_INDEX, 1).setPickupLocation(loc(Coordinate.newInstance(35, 13))).setDeliveryLocation(loc(Coordinate.newInstance(34, 11))).build(); - - Shipment shipment17 = Shipment.Builder.newInstance("17").addSizeDimension(PASSENGERSEATS_INDEX, 1).setPickupLocation(loc(Coordinate.newInstance(5, 14))).setDeliveryLocation(loc(Coordinate.newInstance(6, 16))).build(); - Shipment shipment18 = Shipment.Builder.newInstance("wheelchair_9").addSizeDimension(WHEELCHAIRSPACE_INDEX, 1).setPickupLocation(loc(Coordinate.newInstance(5, 20))).setDeliveryLocation(loc(Coordinate.newInstance(6, 18))).build(); - - Shipment shipment19 = Shipment.Builder.newInstance("19").addSizeDimension(PASSENGERSEATS_INDEX, 1).setPickupLocation(loc(Coordinate.newInstance(15, 14))).setDeliveryLocation(loc(Coordinate.newInstance(14, 16))).build(); - Shipment shipment20 = Shipment.Builder.newInstance("wheelchair_10").addSizeDimension(WHEELCHAIRSPACE_INDEX, 1).setPickupLocation(loc(Coordinate.newInstance(15, 20))).setDeliveryLocation(loc(Coordinate.newInstance(14, 18))).build(); - - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - vrpBuilder.addVehicle(vehicle1).addVehicle(vehicle2).addVehicle(vehicle1_2).addVehicle(vehicle2_2); - vrpBuilder.addJob(shipment1).addJob(shipment2).addJob(shipment3).addJob(shipment4); - vrpBuilder.addJob(shipment5).addJob(shipment6).addJob(shipment7).addJob(shipment8); - vrpBuilder.addJob(shipment9).addJob(shipment10).addJob(shipment11).addJob(shipment12); - vrpBuilder.addJob(shipment13).addJob(shipment14).addJob(shipment15).addJob(shipment16); - vrpBuilder.addJob(shipment17).addJob(shipment18).addJob(shipment19).addJob(shipment20); - - //you only have two vehicles - vrpBuilder.setFleetSize(FleetSize.FINITE); - + Shipment shipment1 = Shipment.Builder.newInstance("wheelchair_1").addSizeDimension(WHEELCHAIRSPACE_INDEX, 1).setPickupLocation(loc(Coordinate.newInstance(5, 7))).setDeliveryLocation(loc(Coordinate.newInstance(6, 9))).build(); + Shipment shipment2 = Shipment.Builder.newInstance("2").addSizeDimension(PASSENGERSEATS_INDEX, 1).setPickupLocation(loc(Coordinate.newInstance(5, 13))).setDeliveryLocation(loc(Coordinate.newInstance(6, 11))).build(); + + Shipment shipment3 = Shipment.Builder.newInstance("wheelchair_2").addSizeDimension(WHEELCHAIRSPACE_INDEX, 1).setPickupLocation(loc(Coordinate.newInstance(15, 7))).setDeliveryLocation(loc(Coordinate.newInstance(14, 9))).build(); + Shipment shipment4 = Shipment.Builder.newInstance("4").addSizeDimension(PASSENGERSEATS_INDEX, 1).setPickupLocation(loc(Coordinate.newInstance(15, 13))).setDeliveryLocation(loc(Coordinate.newInstance(14, 11))).build(); + + Shipment shipment5 = Shipment.Builder.newInstance("wheelchair_3").addSizeDimension(WHEELCHAIRSPACE_INDEX, 1).setPickupLocation(loc(Coordinate.newInstance(25, 27))).setDeliveryLocation(loc(Coordinate.newInstance(26, 29))).build(); + Shipment shipment6 = Shipment.Builder.newInstance("6").addSizeDimension(PASSENGERSEATS_INDEX, 1).setPickupLocation(loc(Coordinate.newInstance(25, 33))).setDeliveryLocation(loc(Coordinate.newInstance(26, 31))).build(); + + Shipment shipment7 = Shipment.Builder.newInstance("7").addSizeDimension(PASSENGERSEATS_INDEX, 1).setPickupLocation(loc(Coordinate.newInstance(35, 27))).setDeliveryLocation(loc(Coordinate.newInstance(34, 29))).build(); + Shipment shipment8 = Shipment.Builder.newInstance("wheelchair_4").addSizeDimension(WHEELCHAIRSPACE_INDEX, 1).setPickupLocation(loc(Coordinate.newInstance(35, 33))).setDeliveryLocation(loc(Coordinate.newInstance(34, 31))).build(); + + Shipment shipment9 = Shipment.Builder.newInstance("9").addSizeDimension(PASSENGERSEATS_INDEX, 1).setPickupLocation(loc(Coordinate.newInstance(5, 27))).setDeliveryLocation(loc(Coordinate.newInstance(6, 29))).build(); + Shipment shipment10 = Shipment.Builder.newInstance("wheelchair_5").addSizeDimension(WHEELCHAIRSPACE_INDEX, 1).setPickupLocation(loc(Coordinate.newInstance(5, 33))).setDeliveryLocation(loc(Coordinate.newInstance(6, 31))).build(); + + Shipment shipment11 = Shipment.Builder.newInstance("11").addSizeDimension(PASSENGERSEATS_INDEX, 1).setPickupLocation(loc(Coordinate.newInstance(15, 27))).setDeliveryLocation(loc(Coordinate.newInstance(14, 29))).build(); + Shipment shipment12 = Shipment.Builder.newInstance("wheelchair_6").addSizeDimension(WHEELCHAIRSPACE_INDEX, 1).setPickupLocation(loc(Coordinate.newInstance(15, 33))).setDeliveryLocation(loc(Coordinate.newInstance(14, 31))).build(); + + Shipment shipment13 = Shipment.Builder.newInstance("13").addSizeDimension(PASSENGERSEATS_INDEX, 1).setPickupLocation(loc(Coordinate.newInstance(25, 7))).setDeliveryLocation(loc(Coordinate.newInstance(26, 9))).build(); + Shipment shipment14 = Shipment.Builder.newInstance("wheelchair_7").addSizeDimension(WHEELCHAIRSPACE_INDEX, 1).setPickupLocation(loc(Coordinate.newInstance(25, 13))).setDeliveryLocation(loc(Coordinate.newInstance(26, 11))).build(); + + Shipment shipment15 = Shipment.Builder.newInstance("15").addSizeDimension(PASSENGERSEATS_INDEX, 1).setPickupLocation(loc(Coordinate.newInstance(35, 7))).setDeliveryLocation(loc(Coordinate.newInstance(34, 9))).build(); + Shipment shipment16 = Shipment.Builder.newInstance("wheelchair_8").addSizeDimension(WHEELCHAIRSPACE_INDEX, 1).setPickupLocation(loc(Coordinate.newInstance(35, 13))).setDeliveryLocation(loc(Coordinate.newInstance(34, 11))).build(); + + Shipment shipment17 = Shipment.Builder.newInstance("17").addSizeDimension(PASSENGERSEATS_INDEX, 1).setPickupLocation(loc(Coordinate.newInstance(5, 14))).setDeliveryLocation(loc(Coordinate.newInstance(6, 16))).build(); + Shipment shipment18 = Shipment.Builder.newInstance("wheelchair_9").addSizeDimension(WHEELCHAIRSPACE_INDEX, 1).setPickupLocation(loc(Coordinate.newInstance(5, 20))).setDeliveryLocation(loc(Coordinate.newInstance(6, 18))).build(); + + Shipment shipment19 = Shipment.Builder.newInstance("19").addSizeDimension(PASSENGERSEATS_INDEX, 1).setPickupLocation(loc(Coordinate.newInstance(15, 14))).setDeliveryLocation(loc(Coordinate.newInstance(14, 16))).build(); + Shipment shipment20 = Shipment.Builder.newInstance("wheelchair_10").addSizeDimension(WHEELCHAIRSPACE_INDEX, 1).setPickupLocation(loc(Coordinate.newInstance(15, 20))).setDeliveryLocation(loc(Coordinate.newInstance(14, 18))).build(); + + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + vrpBuilder.addVehicle(vehicle1).addVehicle(vehicle2).addVehicle(vehicle1_2).addVehicle(vehicle2_2); + vrpBuilder.addJob(shipment1).addJob(shipment2).addJob(shipment3).addJob(shipment4); + vrpBuilder.addJob(shipment5).addJob(shipment6).addJob(shipment7).addJob(shipment8); + vrpBuilder.addJob(shipment9).addJob(shipment10).addJob(shipment11).addJob(shipment12); + vrpBuilder.addJob(shipment13).addJob(shipment14).addJob(shipment15).addJob(shipment16); + vrpBuilder.addJob(shipment17).addJob(shipment18).addJob(shipment19).addJob(shipment20); + + //you only have two vehicles + vrpBuilder.setFleetSize(FleetSize.FINITE); + /* - * + * * wheelchair-bus can only pickup passenger where x<15 */ - HardRouteConstraint wheelchair_bus_passenger_pickup_constraint = new HardRouteConstraint() { - - @Override - public boolean fulfilled(JobInsertionContext insertionContext) { - Shipment shipment2insert = ((Shipment)insertionContext.getJob()); - if(insertionContext.getNewVehicle().getId().equals("wheelchair_bus")){ - if(shipment2insert.getSize().get(PASSENGERSEATS_INDEX)>0){ - if(shipment2insert.getPickupLocation().getCoordinate().getX() > 15. || shipment2insert.getDeliveryLocation().getCoordinate().getX() > 15.){ - return false; - } - } - } - return true; - } - }; + HardRouteConstraint wheelchair_bus_passenger_pickup_constraint = new HardRouteConstraint() { - //build the problem - VehicleRoutingProblem problem = vrpBuilder.build(); + @Override + public boolean fulfilled(JobInsertionContext insertionContext) { + Shipment shipment2insert = ((Shipment) insertionContext.getJob()); + if (insertionContext.getNewVehicle().getId().equals("wheelchair_bus")) { + if (shipment2insert.getSize().get(PASSENGERSEATS_INDEX) > 0) { + if (shipment2insert.getPickupLocation().getCoordinate().getX() > 15. || shipment2insert.getDeliveryLocation().getCoordinate().getX() > 15.) { + return false; + } + } + } + return true; + } + }; + + //build the problem + VehicleRoutingProblem problem = vrpBuilder.build(); + + StateManager stateManager = new StateManager(problem); + + ConstraintManager constraintManager = new ConstraintManager(problem, stateManager); + constraintManager.addConstraint(wheelchair_bus_passenger_pickup_constraint); - StateManager stateManager = new StateManager(problem); - - ConstraintManager constraintManager = new ConstraintManager(problem, stateManager); - constraintManager.addConstraint(wheelchair_bus_passenger_pickup_constraint); - /* - * get a sample algorithm. - * + * get a sample algorithm. + * * Note that you need to make sure to prohibit vehicle-switching by adding the insertion-tag false. * This way you make sure that no vehicle can take over a route that is employed by another. Allowing this might make sense when dealing with - * a heterogeneous fleet and you want to employ a bigger vehicle on a still existing route. However, allowing it makes constraint-checking + * a heterogeneous fleet and you want to employ a bigger vehicle on a still existing route. However, allowing it makes constraint-checking * bit more complicated and you cannot just add the above hard-constraint. Latter will be covered in another example. - * + * */ - VehicleRoutingAlgorithmBuilder algorithmBuilder = new VehicleRoutingAlgorithmBuilder(problem, "input/algorithmConfig_noVehicleSwitch.xml"); - algorithmBuilder.setStateAndConstraintManager(stateManager, constraintManager); - algorithmBuilder.addCoreConstraints(); - algorithmBuilder.addDefaultCostCalculators(); - - VehicleRoutingAlgorithm algorithm = algorithmBuilder.build(); - algorithm.setPrematureAlgorithmTermination(new IterationWithoutImprovementTermination(100)); + VehicleRoutingAlgorithmBuilder algorithmBuilder = new VehicleRoutingAlgorithmBuilder(problem, "input/algorithmConfig_noVehicleSwitch.xml"); + algorithmBuilder.setStateAndConstraintManager(stateManager, constraintManager); + algorithmBuilder.addCoreConstraints(); + algorithmBuilder.addDefaultCostCalculators(); + + VehicleRoutingAlgorithm algorithm = algorithmBuilder.build(); + algorithm.setPrematureAlgorithmTermination(new IterationWithoutImprovementTermination(100)); /* - * and search a solution + * and search a solution */ - Collection solutions = algorithm.searchSolutions(); - + Collection solutions = algorithm.searchSolutions(); + /* - * get the best + * get the best */ - VehicleRoutingProblemSolution bestSolution = Solutions.bestOf(solutions); - + VehicleRoutingProblemSolution bestSolution = Solutions.bestOf(solutions); + /* * write out problem and solution to xml-file */ // new VrpXMLWriter(problem, solutions).write("output/shipment-problem-with-solution.xml"); - + /* * print nRoutes and totalCosts of bestSolution */ - SolutionPrinter.print(problem, bestSolution, SolutionPrinter.Print.VERBOSE); - + SolutionPrinter.print(problem, bestSolution, SolutionPrinter.Print.VERBOSE); + /* * plot problem without solution */ - Plotter problemPlotter = new Plotter(problem); - problemPlotter.plotShipments(true); - problemPlotter.setLabel(jsprit.analysis.toolbox.Plotter.Label.SIZE); - problemPlotter.plot("output/transportOfDisabledPeopleExample_problem.png", "disabled people tp"); + Plotter problemPlotter = new Plotter(problem); + problemPlotter.plotShipments(true); + problemPlotter.setLabel(jsprit.analysis.toolbox.Plotter.Label.SIZE); + problemPlotter.plot("output/transportOfDisabledPeopleExample_problem.png", "disabled people tp"); - Plotter solutionPlotter = new Plotter(problem,Solutions.bestOf(solutions)); + Plotter solutionPlotter = new Plotter(problem, Solutions.bestOf(solutions)); solutionPlotter.plotShipments(true); solutionPlotter.setLabel(jsprit.analysis.toolbox.Plotter.Label.SIZE); solutionPlotter.plot("output/transportOfDisabledPeopleExample_solution.png", "disabled people tp"); - new GraphStreamViewer(problem).labelWith(Label.ID).setRenderDelay(100).setRenderShipments(true).display(); - - new GraphStreamViewer(problem,Solutions.bestOf(solutions)).labelWith(Label.ACTIVITY).setRenderDelay(100).setRenderShipments(true).display(); - - } + new GraphStreamViewer(problem).labelWith(Label.ID).setRenderDelay(100).setRenderShipments(true).display(); - private static Location loc(Coordinate coordinate) { - return Location.Builder.newInstance().setCoordinate(coordinate).build(); - } + new GraphStreamViewer(problem, Solutions.bestOf(solutions)).labelWith(Label.ACTIVITY).setRenderDelay(100).setRenderShipments(true).display(); + + } + + private static Location loc(Coordinate coordinate) { + return Location.Builder.newInstance().setCoordinate(coordinate).build(); + } } diff --git a/jsprit-examples/src/main/java/jsprit/examples/VRPWithBackhaulsExample.java b/jsprit-examples/src/main/java/jsprit/examples/VRPWithBackhaulsExample.java index 3f48d176..a41b11b7 100644 --- a/jsprit-examples/src/main/java/jsprit/examples/VRPWithBackhaulsExample.java +++ b/jsprit-examples/src/main/java/jsprit/examples/VRPWithBackhaulsExample.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.examples; @@ -34,75 +34,75 @@ import java.util.Collection; public class VRPWithBackhaulsExample { - - public static void main(String[] args) { - + + public static void main(String[] args) { + /* - * some preparation - create output folder + * some preparation - create output folder */ - Examples.createOutputFolder(); - + Examples.createOutputFolder(); + /* - * Build the problem. - * + * Build the problem. + * * But define a problem-builder first. */ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + /* - * A solomonReader reads solomon-instance files, and stores the required information in the builder. + * A solomonReader reads solomon-instance files, and stores the required information in the builder. */ - new VrpXMLReader(vrpBuilder).read("input/pickups_and_deliveries_solomon_r101.xml"); - + new VrpXMLReader(vrpBuilder).read("input/pickups_and_deliveries_solomon_r101.xml"); + /* - * Finally, the problem can be built. By default, transportCosts are crowFlyDistances (as usually used for vrp-instances). + * Finally, the problem can be built. By default, transportCosts are crowFlyDistances (as usually used for vrp-instances). */ // - VehicleRoutingProblem vrp = vrpBuilder.build(); - + VehicleRoutingProblem vrp = vrpBuilder.build(); + // SolutionPlotter.plotVrpAsPNG(vrp, "output/vrpwbh_solomon_r101.png", "pd_r101"); - + /* - * 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. */ - VehicleRoutingAlgorithmBuilder vraBuilder = new VehicleRoutingAlgorithmBuilder(vrp,"input/algorithmConfig_solomon.xml"); + VehicleRoutingAlgorithmBuilder vraBuilder = new VehicleRoutingAlgorithmBuilder(vrp, "input/algorithmConfig_solomon.xml"); vraBuilder.addCoreConstraints(); vraBuilder.addDefaultCostCalculators(); StateManager stateManager = new StateManager(vrp); - ConstraintManager constraintManager = new ConstraintManager(vrp,stateManager); + ConstraintManager constraintManager = new ConstraintManager(vrp, stateManager); constraintManager.addConstraint(new ServiceDeliveriesFirstConstraint(), ConstraintManager.Priority.CRITICAL); - vraBuilder.setStateAndConstraintManager(stateManager,constraintManager); + vraBuilder.setStateAndConstraintManager(stateManager, constraintManager); VehicleRoutingAlgorithm vra = vraBuilder.build(); vra.getAlgorithmListeners().addListener(new AlgorithmSearchProgressChartListener("output/sol_progress.png")); - /* - * Solve the problem. - * + /* + * Solve the problem. + * * */ - Collection solutions = vra.searchSolutions(); - + Collection solutions = vra.searchSolutions(); + /* - * Retrieve best solution. + * Retrieve best solution. */ - VehicleRoutingProblemSolution solution = new SelectBest().selectSolution(solutions); - + VehicleRoutingProblemSolution solution = new SelectBest().selectSolution(solutions); + /* * print solution */ - SolutionPrinter.print(vrp, solution, SolutionPrinter.Print.VERBOSE); - + SolutionPrinter.print(vrp, solution, SolutionPrinter.Print.VERBOSE); + /* - * Plot solution. + * Plot solution. */ // Plotter plotter = new Plotter(vrp, solution); // plotter.setLabel(Label.SIZE); // plotter.setShowFirstActivity(true); // plotter.plot("output/vrpwbh_solomon_r101_solution.png","vrpwbh_r101"); - - new GraphStreamViewer(vrp, solution).setRenderDelay(100).setEnableAutoLayout(false).display(); - - } + + new GraphStreamViewer(vrp, solution).setRenderDelay(100).setEnableAutoLayout(false).display(); + + } } diff --git a/jsprit-examples/src/main/java/jsprit/examples/VRPWithBackhaulsExample2.java b/jsprit-examples/src/main/java/jsprit/examples/VRPWithBackhaulsExample2.java index 0f13a5d8..bda361f6 100644 --- a/jsprit-examples/src/main/java/jsprit/examples/VRPWithBackhaulsExample2.java +++ b/jsprit-examples/src/main/java/jsprit/examples/VRPWithBackhaulsExample2.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.examples; @@ -39,38 +39,38 @@ import java.util.Collection; public class VRPWithBackhaulsExample2 { - - public static void main(String[] args) { - - /* - * some preparation - create output folder - */ - Examples.createOutputFolder(); - - /* - * Build the problem. - * - * But define a problem-builder first. - */ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - - /* - * A solomonReader reads solomon-instance files, and stores the required information in the builder. - */ - new VrpXMLReader(vrpBuilder).read("input/pd_christophides_vrpnc1_vcap50.xml"); - + + public static void main(String[] args) { /* - * Finally, the problem can be built. By default, transportCosts are crowFlyDistances (as usually used for vrp-instances). + * some preparation - create output folder */ - final VehicleRoutingProblem vrp = vrpBuilder.build(); - -// new Plotter(vrp).plot("output/vrpwbh_christophides_vrpnc1.png", "pd_vrpnc1"); - - + Examples.createOutputFolder(); + /* - * Define the required vehicle-routing algorithms to solve the above problem. - * + * Build the problem. + * + * But define a problem-builder first. + */ + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + + /* + * A solomonReader reads solomon-instance files, and stores the required information in the builder. + */ + new VrpXMLReader(vrpBuilder).read("input/pd_christophides_vrpnc1_vcap50.xml"); + + + /* + * Finally, the problem can be built. By default, transportCosts are crowFlyDistances (as usually used for vrp-instances). + */ + final VehicleRoutingProblem vrp = vrpBuilder.build(); + +// new Plotter(vrp).plot("output/vrpwbh_christophides_vrpnc1.png", "pd_vrpnc1"); + + + /* + * Define the required vehicle-routing algorithms to solve the above problem. + * * The algorithm can be defined and configured in an xml-file. */ // VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "input/algorithmConfig_solomon.xml"); @@ -80,7 +80,7 @@ public class VRPWithBackhaulsExample2 { // vraBuilder.addCoreConstraints(); StateManager stateManager = new StateManager(vrp); - ConstraintManager constraintManager = new ConstraintManager(vrp,stateManager); + ConstraintManager constraintManager = new ConstraintManager(vrp, stateManager); constraintManager.addConstraint(new ServiceDeliveriesFirstConstraint(), ConstraintManager.Priority.CRITICAL); // vraBuilder.setStateAndConstraintManager(stateManager,constraintManager); @@ -89,49 +89,49 @@ public class VRPWithBackhaulsExample2 { VehicleRoutingAlgorithm vra = Jsprit.Builder.newInstance(vrp) - .setStateAndConstraintManager(stateManager, constraintManager) - .setProperty(Jsprit.Parameter.FIXED_COST_PARAM.toString(),"0.") - .buildAlgorithm(); + .setStateAndConstraintManager(stateManager, constraintManager) + .setProperty(Jsprit.Parameter.FIXED_COST_PARAM.toString(), "0.") + .buildAlgorithm(); vra.setMaxIterations(2000); vra.addListener(new AlgorithmSearchProgressChartListener("output/search")); /* - * Solve the problem. - * + * Solve the problem. + * * */ - Collection solutions = vra.searchSolutions(); - + Collection solutions = vra.searchSolutions(); + /* - * Retrieve best solution. + * Retrieve best solution. */ - VehicleRoutingProblemSolution solution = new SelectBest().selectSolution(solutions); - + VehicleRoutingProblemSolution solution = new SelectBest().selectSolution(solutions); + /* - * print solution + * print solution */ - SolutionPrinter.print(solution); - + SolutionPrinter.print(solution); + /* - * Plot solution. + * Plot solution. */ // SolutionPlotter.plotSolutionAsPNG(vrp, solution, "output/pd_solomon_r101_solution.png","pd_r101"); - Plotter plotter = new Plotter(vrp, solution); + Plotter plotter = new Plotter(vrp, solution); // plotter.setLabel(Plotter.Label.SIZE); - plotter.plot("output/vrpwbh_christophides_vrpnc1_solution.png","vrpwbh_vrpnc1"); + plotter.plot("output/vrpwbh_christophides_vrpnc1_solution.png", "vrpwbh_vrpnc1"); SolutionAnalyser analyser = new SolutionAnalyser(vrp, solution, new SolutionAnalyser.DistanceCalculator() { @Override public double getDistance(Location from, Location to) { - return vrp.getTransportCosts().getTransportCost(from, to,0.,null,null); + return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null); } }); - for(VehicleRoute route : solution.getRoutes()){ + for (VehicleRoute route : solution.getRoutes()) { System.out.println("------"); System.out.println("vehicleId: " + route.getVehicle().getId()); System.out.println("vehicleCapacity: " + route.getVehicle().getType().getCapacityDimensions() + " maxLoad: " + analyser.getMaxLoad(route)); @@ -150,27 +150,27 @@ public class VRPWithBackhaulsExample2 { System.out.println("timeWindowViolationOnRoute: " + analyser.getTimeWindowViolation(route)); System.out.println("skillConstraintViolatedOnRoute: " + analyser.hasSkillConstraintViolation(route)); - System.out.println("dist@" + route.getStart().getLocation().getId() + ": " + analyser.getDistanceAtActivity(route.getStart(),route)); - System.out.println("timeWindowViolation@" + route.getStart().getLocation().getId() + ": " + analyser.getTimeWindowViolationAtActivity(route.getStart(), route)); - for(TourActivity act : route.getActivities()){ + System.out.println("dist@" + route.getStart().getLocation().getId() + ": " + analyser.getDistanceAtActivity(route.getStart(), route)); + System.out.println("timeWindowViolation@" + route.getStart().getLocation().getId() + ": " + analyser.getTimeWindowViolationAtActivity(route.getStart(), route)); + for (TourActivity act : route.getActivities()) { System.out.println("--"); System.out.println("actType: " + act.getName() + " demand: " + act.getSize()); - System.out.println("dist@" + act.getLocation().getId() + ": " + analyser.getDistanceAtActivity(act,route)); - System.out.println("load(before)@" + act.getLocation().getId() + ": " + analyser.getLoadJustBeforeActivity(act,route)); + System.out.println("dist@" + act.getLocation().getId() + ": " + analyser.getDistanceAtActivity(act, route)); + System.out.println("load(before)@" + act.getLocation().getId() + ": " + analyser.getLoadJustBeforeActivity(act, route)); System.out.println("load(after)@" + act.getLocation().getId() + ": " + analyser.getLoadRightAfterActivity(act, route)); - System.out.println("transportCosts@" + act.getLocation().getId() + ": " + analyser.getVariableTransportCostsAtActivity(act,route)); - System.out.println("capViolation(after)@" + act.getLocation().getId() + ": " + analyser.getCapacityViolationAfterActivity(act,route)); - System.out.println("timeWindowViolation@" + act.getLocation().getId() + ": " + analyser.getTimeWindowViolationAtActivity(act,route)); + System.out.println("transportCosts@" + act.getLocation().getId() + ": " + analyser.getVariableTransportCostsAtActivity(act, route)); + System.out.println("capViolation(after)@" + act.getLocation().getId() + ": " + analyser.getCapacityViolationAfterActivity(act, route)); + System.out.println("timeWindowViolation@" + act.getLocation().getId() + ": " + analyser.getTimeWindowViolationAtActivity(act, route)); System.out.println("skillConstraintViolated@" + act.getLocation().getId() + ": " + analyser.hasSkillConstraintViolationAtActivity(act, route)); } System.out.println("--"); - System.out.println("dist@" + route.getEnd().getLocation().getId() + ": " + analyser.getDistanceAtActivity(route.getEnd(),route)); - System.out.println("timeWindowViolation@" + route.getEnd().getLocation().getId() + ": " + analyser.getTimeWindowViolationAtActivity(route.getEnd(),route)); + System.out.println("dist@" + route.getEnd().getLocation().getId() + ": " + analyser.getDistanceAtActivity(route.getEnd(), route)); + System.out.println("timeWindowViolation@" + route.getEnd().getLocation().getId() + ": " + analyser.getTimeWindowViolationAtActivity(route.getEnd(), route)); } System.out.println("-----"); System.out.println("aggreate solution stats"); - System.out.println("total freight moved: " + Capacity.addup(analyser.getLoadAtBeginning(),analyser.getLoadPickedUp())); + System.out.println("total freight moved: " + Capacity.addup(analyser.getLoadAtBeginning(), analyser.getLoadPickedUp())); System.out.println("total no. picks at beginning: " + analyser.getNumberOfPickupsAtBeginning()); System.out.println("total no. picks on routes: " + analyser.getNumberOfPickups()); System.out.println("total picked load at beginnnig: " + analyser.getLoadAtBeginning()); diff --git a/jsprit-examples/src/main/java/jsprit/util/Examples.java b/jsprit-examples/src/main/java/jsprit/util/Examples.java index 24a1d9f0..845f5264 100644 --- a/jsprit-examples/src/main/java/jsprit/util/Examples.java +++ b/jsprit-examples/src/main/java/jsprit/util/Examples.java @@ -1,18 +1,18 @@ /******************************************************************************* * Copyright (c) 2014 Stefan Schroeder. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . - * + * * Contributors: * Stefan Schroeder - initial API and implementation ******************************************************************************/ @@ -21,15 +21,15 @@ package jsprit.util; import java.io.File; public class Examples { - - public static void createOutputFolder(){ - File dir = new File("output"); - // if the directory does not exist, create it - if (!dir.exists()){ - System.out.println("creating directory ./output"); - boolean result = dir.mkdir(); - if(result) System.out.println("./output created"); - } - } + + public static void createOutputFolder() { + File dir = new File("output"); + // if the directory does not exist, create it + if (!dir.exists()) { + System.out.println("creating directory ./output"); + boolean result = dir.mkdir(); + if (result) System.out.println("./output created"); + } + } } diff --git a/jsprit-instances/pom.xml b/jsprit-instances/pom.xml index 3977b7c0..8e4555bc 100644 --- a/jsprit-instances/pom.xml +++ b/jsprit-instances/pom.xml @@ -1,54 +1,56 @@ + + + jsprit + jsprit + 1.6.2-SNAPSHOT + + 4.0.0 - - - jsprit - jsprit - 1.6.1-SNAPSHOT - - 4.0.0 - - jsprit-instances - jsprit-instances - - jar - - - - - - org.eclipse.m2e - lifecycle-mapping - 1.0.0 - - - - - - org.apache.maven.plugins - maven-enforcer-plugin - [1.0.0,) - - enforce - - - - - - - - - - - - - - - - - ${project.groupId} - jsprit-core - ${project.version} - - + jsprit-instances + jsprit-instances + + jar + + + + + + org.eclipse.m2e + lifecycle-mapping + 1.0.0 + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + [1.0.0,) + + enforce + + + + + + + + + + + + + + + + + + + ${project.groupId} + jsprit-core + ${project.version} + + diff --git a/jsprit-instances/src/main/java/jsprit/instance/reader/ChristofidesReader.java b/jsprit-instances/src/main/java/jsprit/instance/reader/ChristofidesReader.java index c6bda3ed..f532f14e 100644 --- a/jsprit-instances/src/main/java/jsprit/instance/reader/ChristofidesReader.java +++ b/jsprit-instances/src/main/java/jsprit/instance/reader/ChristofidesReader.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.instance.reader; @@ -35,113 +35,103 @@ import java.io.IOException; /** * Reader that reads Christophides, Mingozzi and Toth instances. - * + *

*

Files and file-description can be found here. - * - * @author stefan schroeder * + * @author stefan schroeder */ public class ChristofidesReader { - private static Logger logger = LogManager.getLogger(ChristofidesReader.class); - - private final VehicleRoutingProblem.Builder vrpBuilder; + private static Logger logger = LogManager.getLogger(ChristofidesReader.class); - private double coordProjectionFactor = 1; + private final VehicleRoutingProblem.Builder vrpBuilder; - /** - * Constructs the reader. - * - * @param vrpBuilder the builder - */ - public ChristofidesReader(VehicleRoutingProblem.Builder vrpBuilder) { - super(); - this.vrpBuilder = vrpBuilder; - } - - /** - * Reads instance-file and memorizes vehicles, customers and so forth in - * {@link VehicleRoutingProblem.Builder}. - * - * @param fileName the filename to read - */ - public void read(String fileName){ - vrpBuilder.setFleetSize(FleetSize.INFINITE); - BufferedReader reader = getReader(fileName); - int vehicleCapacity = 0; - double serviceTime = 0.0; - double endTime = Double.MAX_VALUE; - int counter = 0; - String line; - while((line = readLine(reader)) != null){ - line = line.replace("\r", ""); - line = line.trim(); - String[] tokens = line.split(" "); - if(counter == 0){ - vehicleCapacity = Integer.parseInt(tokens[1].trim()); - endTime = Double.parseDouble(tokens[2].trim()); - serviceTime = Double.parseDouble(tokens[3].trim()); - } - else if(counter == 1){ - Coordinate depotCoord = makeCoord(tokens[0].trim(),tokens[1].trim()); - VehicleTypeImpl vehicleType = VehicleTypeImpl.Builder.newInstance("christophidesType").addCapacityDimension(0, vehicleCapacity). - setCostPerDistance(1.0).build(); - VehicleImpl vehicle = VehicleImpl.Builder.newInstance("christophidesVehicle").setLatestArrival(endTime).setStartLocation(Location.newInstance(depotCoord.getX(), depotCoord.getY())). - setType(vehicleType).build(); - vrpBuilder.addVehicle(vehicle); - } - else{ - Coordinate customerCoord = makeCoord(tokens[0].trim(),tokens[1].trim()); - int demand = Integer.parseInt(tokens[2].trim()); - String customer = Integer.valueOf(counter-1).toString(); - Service service = Service.Builder.newInstance(customer).addSizeDimension(0, demand).setServiceTime(serviceTime).setLocation(Location.newInstance(customerCoord.getX(), customerCoord.getY())).build(); - vrpBuilder.addJob(service); - } - counter++; - } - close(reader); - } + private double coordProjectionFactor = 1; - public void setCoordProjectionFactor(double coordProjectionFactor) { - this.coordProjectionFactor = coordProjectionFactor; - } + /** + * Constructs the reader. + * + * @param vrpBuilder the builder + */ + public ChristofidesReader(VehicleRoutingProblem.Builder vrpBuilder) { + super(); + this.vrpBuilder = vrpBuilder; + } - private void close(BufferedReader reader) { - try { - reader.close(); - } catch (IOException e) { - e.printStackTrace(); - logger.error(e); - System.exit(1); - } - } + /** + * Reads instance-file and memorizes vehicles, customers and so forth in + * {@link VehicleRoutingProblem.Builder}. + * + * @param fileName the filename to read + */ + public void read(String fileName) { + vrpBuilder.setFleetSize(FleetSize.INFINITE); + BufferedReader reader = getReader(fileName); + int vehicleCapacity = 0; + double serviceTime = 0.0; + double endTime = Double.MAX_VALUE; + int counter = 0; + String line; + while ((line = readLine(reader)) != null) { + line = line.replace("\r", ""); + line = line.trim(); + String[] tokens = line.split(" "); + if (counter == 0) { + vehicleCapacity = Integer.parseInt(tokens[1].trim()); + endTime = Double.parseDouble(tokens[2].trim()); + serviceTime = Double.parseDouble(tokens[3].trim()); + } else if (counter == 1) { + Coordinate depotCoord = makeCoord(tokens[0].trim(), tokens[1].trim()); + VehicleTypeImpl vehicleType = VehicleTypeImpl.Builder.newInstance("christophidesType").addCapacityDimension(0, vehicleCapacity). + setCostPerDistance(1.0).build(); + VehicleImpl vehicle = VehicleImpl.Builder.newInstance("christophidesVehicle").setLatestArrival(endTime).setStartLocation(Location.newInstance(depotCoord.getX(), depotCoord.getY())). + setType(vehicleType).build(); + vrpBuilder.addVehicle(vehicle); + } else { + Coordinate customerCoord = makeCoord(tokens[0].trim(), tokens[1].trim()); + int demand = Integer.parseInt(tokens[2].trim()); + String customer = Integer.valueOf(counter - 1).toString(); + Service service = Service.Builder.newInstance(customer).addSizeDimension(0, demand).setServiceTime(serviceTime).setLocation(Location.newInstance(customerCoord.getX(), customerCoord.getY())).build(); + vrpBuilder.addJob(service); + } + counter++; + } + close(reader); + } - private String readLine(BufferedReader reader) { - try { - return reader.readLine(); - } catch (IOException e) { - e.printStackTrace(); - logger.error(e); - System.exit(1); - return null; - } - } - - private Coordinate makeCoord(String xString, String yString) { - double x = Double.parseDouble(xString); - double y = Double.parseDouble(yString); - return new Coordinate(x*coordProjectionFactor,y*coordProjectionFactor); - } + public void setCoordProjectionFactor(double coordProjectionFactor) { + this.coordProjectionFactor = coordProjectionFactor; + } - private BufferedReader getReader(String solomonFile) { - BufferedReader reader = null; - try { - reader = new BufferedReader(new FileReader(solomonFile)); - } catch (FileNotFoundException e1) { - e1.printStackTrace(); - logger.error(e1); - System.exit(1); - } - return reader; - } + private void close(BufferedReader reader) { + try { + reader.close(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + private String readLine(BufferedReader reader) { + try { + return reader.readLine(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + private Coordinate makeCoord(String xString, String yString) { + double x = Double.parseDouble(xString); + double y = Double.parseDouble(yString); + return new Coordinate(x * coordProjectionFactor, y * coordProjectionFactor); + } + + private BufferedReader getReader(String solomonFile) { + BufferedReader reader = null; + try { + reader = new BufferedReader(new FileReader(solomonFile)); + } catch (FileNotFoundException e1) { + throw new RuntimeException(e1); + } + return reader; + } } diff --git a/jsprit-instances/src/main/java/jsprit/instance/reader/CordeauReader.java b/jsprit-instances/src/main/java/jsprit/instance/reader/CordeauReader.java index e85fd224..2b5fd9ad 100644 --- a/jsprit-instances/src/main/java/jsprit/instance/reader/CordeauReader.java +++ b/jsprit-instances/src/main/java/jsprit/instance/reader/CordeauReader.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.instance.reader; @@ -38,140 +38,129 @@ import java.util.List; /** * Reader that reads instances developed by: - * - *

Cordeau, J.-F., Gendreau, M. and Laporte, G. (1997), A tabu search heuristic for periodic and multi-depot vehicle routing problems. + *

+ *

Cordeau, J.-F., Gendreau, M. and Laporte, G. (1997), A tabu search heuristic for periodic and multi-depot vehicle routing problems. * Networks, 30: 105–119. doi: 10.1002/(SICI)1097-0037(199709)30:2<105::AID-NET5>3.0.CO;2-G - * - *

Files and file-description can be found here. - * - * @author stefan schroeder + *

+ *

Files and file-description can be found here. * + * @author stefan schroeder */ public class CordeauReader { - private static Logger logger = LogManager.getLogger(CordeauReader.class); - - private final VehicleRoutingProblem.Builder vrpBuilder; + private static Logger logger = LogManager.getLogger(CordeauReader.class); - private double coordProjectionFactor = 1; + private final VehicleRoutingProblem.Builder vrpBuilder; + + private double coordProjectionFactor = 1; - public CordeauReader(VehicleRoutingProblem.Builder vrpBuilder) { - super(); - this.vrpBuilder = vrpBuilder; - } + public CordeauReader(VehicleRoutingProblem.Builder vrpBuilder) { + super(); + this.vrpBuilder = vrpBuilder; + } @Deprecated - public CordeauReader(VehicleRoutingProblem.Builder vrpBuilder, boolean penaltyVehicles) { - super(); - this.vrpBuilder = vrpBuilder; - } - - public void read(String fileName){ - vrpBuilder.setFleetSize(FleetSize.FINITE); - BufferedReader reader = getReader(fileName); - int vrpType; - int nOfDepots = 0; - int nOfCustomers = 0; - int nOfVehiclesAtEachDepot = 0; - - int counter = 0; - String line; - List> vehiclesAtDepot = new ArrayList>(); - int depotCounter = 0; - while((line = readLine(reader)) != null){ - line = line.replace("\r", ""); - line = line.trim(); - String[] tokens = line.split("\\s+"); - if(counter == 0){ - vrpType = Integer.parseInt(tokens[0].trim()); - if(vrpType != 2) throw new IllegalStateException("expect vrpType to be equal to 2 and thus to be MDVRP"); - nOfVehiclesAtEachDepot = Integer.parseInt(tokens[1].trim()); - nOfCustomers = Integer.parseInt(tokens[2].trim()); - nOfDepots = Integer.parseInt(tokens[3].trim()); - } - else if(counter <= nOfDepots){ - String depot = Integer.valueOf(counter).toString(); - int duration = Integer.parseInt(tokens[0].trim()); - if(duration == 0) duration = 999999; - int capacity = Integer.parseInt(tokens[1].trim()); - VehicleTypeImpl vehicleType = VehicleTypeImpl.Builder.newInstance(counter + "_cordeauType").addCapacityDimension(0, capacity). - setCostPerDistance(1.0).setFixedCost(0).build(); - List builders = new ArrayList(); - for(int vehicleCounter=0;vehicleCounter vBuilders = vehiclesAtDepot.get(depotCounter); - for(Builder vBuilder : vBuilders){ - vBuilder.setStartLocation(Location.newInstance(depotCoord.getX(),depotCoord.getY())); - VehicleImpl vehicle = vBuilder.build(); - vrpBuilder.addVehicle(vehicle); - } - depotCounter++; - } - else{ - throw new IllegalStateException("there are more lines than expected in file."); - } - counter++; - } - close(reader); - } + public CordeauReader(VehicleRoutingProblem.Builder vrpBuilder, boolean penaltyVehicles) { + super(); + this.vrpBuilder = vrpBuilder; + } - public void setCoordProjectionFactor(double coordProjectionFactor) { - this.coordProjectionFactor = coordProjectionFactor; - } + public void read(String fileName) { + vrpBuilder.setFleetSize(FleetSize.FINITE); + BufferedReader reader = getReader(fileName); + int vrpType; + int nOfDepots = 0; + int nOfCustomers = 0; + int nOfVehiclesAtEachDepot = 0; - private void close(BufferedReader reader) { - try { - reader.close(); - } catch (IOException e) { - e.printStackTrace(); - logger.error(e); - System.exit(1); - } - } + int counter = 0; + String line; + List> vehiclesAtDepot = new ArrayList>(); + int depotCounter = 0; + while ((line = readLine(reader)) != null) { + line = line.replace("\r", ""); + line = line.trim(); + String[] tokens = line.split("\\s+"); + if (counter == 0) { + vrpType = Integer.parseInt(tokens[0].trim()); + if (vrpType != 2) + throw new IllegalStateException("expect vrpType to be equal to 2 and thus to be MDVRP"); + nOfVehiclesAtEachDepot = Integer.parseInt(tokens[1].trim()); + nOfCustomers = Integer.parseInt(tokens[2].trim()); + nOfDepots = Integer.parseInt(tokens[3].trim()); + } else if (counter <= nOfDepots) { + String depot = Integer.valueOf(counter).toString(); + int duration = Integer.parseInt(tokens[0].trim()); + if (duration == 0) duration = 999999; + int capacity = Integer.parseInt(tokens[1].trim()); + VehicleTypeImpl vehicleType = VehicleTypeImpl.Builder.newInstance(counter + "_cordeauType").addCapacityDimension(0, capacity). + setCostPerDistance(1.0).setFixedCost(0).build(); + List builders = new ArrayList(); + for (int vehicleCounter = 0; vehicleCounter < nOfVehiclesAtEachDepot; vehicleCounter++) { + Builder vBuilder = VehicleImpl.Builder.newInstance(depot + "_" + (vehicleCounter + 1) + "_cordeauVehicle"); + vBuilder.setLatestArrival(duration).setType(vehicleType); + builders.add(vBuilder); + } + vehiclesAtDepot.add(builders); + } else if (counter <= (nOfCustomers + nOfDepots)) { + String id = tokens[0].trim(); + Coordinate customerCoord = makeCoord(tokens[1].trim(), tokens[2].trim()); + double serviceTime = Double.parseDouble(tokens[3].trim()); + int demand = Integer.parseInt(tokens[4].trim()); + Service service = Service.Builder.newInstance(id).addSizeDimension(0, demand).setServiceTime(serviceTime) + .setLocation(Location.Builder.newInstance().setId(id).setCoordinate(customerCoord).build()).build(); + vrpBuilder.addJob(service); + } else if (counter <= (nOfCustomers + nOfDepots + nOfDepots)) { + Coordinate depotCoord = makeCoord(tokens[1].trim(), tokens[2].trim()); + List vBuilders = vehiclesAtDepot.get(depotCounter); + for (Builder vBuilder : vBuilders) { + vBuilder.setStartLocation(Location.newInstance(depotCoord.getX(), depotCoord.getY())); + VehicleImpl vehicle = vBuilder.build(); + vrpBuilder.addVehicle(vehicle); + } + depotCounter++; + } else { + throw new IllegalStateException("there are more lines than expected in file."); + } + counter++; + } + close(reader); + } - private String readLine(BufferedReader reader) { - try { - return reader.readLine(); - } catch (IOException e) { - e.printStackTrace(); - logger.error(e); - System.exit(1); - return null; - } - } - - private Coordinate makeCoord(String xString, String yString) { - double x = Double.parseDouble(xString); - double y = Double.parseDouble(yString); - return new Coordinate(x*coordProjectionFactor,y*coordProjectionFactor); - } + public void setCoordProjectionFactor(double coordProjectionFactor) { + this.coordProjectionFactor = coordProjectionFactor; + } - private BufferedReader getReader(String solomonFile) { - BufferedReader reader = null; - try { - reader = new BufferedReader(new FileReader(solomonFile)); - } catch (FileNotFoundException e1) { - e1.printStackTrace(); - logger.error(e1); - System.exit(1); - } - return reader; - } + private void close(BufferedReader reader) { + try { + reader.close(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + private String readLine(BufferedReader reader) { + try { + return reader.readLine(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + private Coordinate makeCoord(String xString, String yString) { + double x = Double.parseDouble(xString); + double y = Double.parseDouble(yString); + return new Coordinate(x * coordProjectionFactor, y * coordProjectionFactor); + } + + private BufferedReader getReader(String solomonFile) { + BufferedReader reader = null; + try { + reader = new BufferedReader(new FileReader(solomonFile)); + } catch (FileNotFoundException e1) { + throw new RuntimeException(e1); + } + return reader; + } } diff --git a/jsprit-instances/src/main/java/jsprit/instance/reader/Figliozzi.java b/jsprit-instances/src/main/java/jsprit/instance/reader/Figliozzi.java index 5b1029aa..1f151078 100644 --- a/jsprit-instances/src/main/java/jsprit/instance/reader/Figliozzi.java +++ b/jsprit-instances/src/main/java/jsprit/instance/reader/Figliozzi.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.instance.reader; @@ -40,36 +40,68 @@ public class Figliozzi { } - public static TDCosts createCosts(Locations locations, SpeedDistribution speedDistribution, double depotClosingTime){ + public static TDCosts createCosts(Locations locations, SpeedDistribution speedDistribution, double depotClosingTime) { List timeBins = createTimeBins(depotClosingTime); List speedValues = createSpeedValues(speedDistribution); - return new TDCosts(locations,timeBins,speedValues); + return new TDCosts(locations, timeBins, speedValues); } static List createSpeedValues(SpeedDistribution speedDistribution) { List speedValues = Collections.emptyList(); - switch(speedDistribution){ - case TD1a: speedValues = Arrays.asList(1.,1.6,1.05,1.6,1.); break; - case TD2a: speedValues = Arrays.asList(1.,2.,1.5,2.,1.); break; - case TD3a: speedValues = Arrays.asList(1.,2.5,1.75,2.5,1.); break; + switch (speedDistribution) { + case TD1a: + speedValues = Arrays.asList(1., 1.6, 1.05, 1.6, 1.); + break; + case TD2a: + speedValues = Arrays.asList(1., 2., 1.5, 2., 1.); + break; + case TD3a: + speedValues = Arrays.asList(1., 2.5, 1.75, 2.5, 1.); + break; - case TD1b: speedValues = Arrays.asList(1.6,1.,1.05,1.,1.6); break; - case TD2b: speedValues = Arrays.asList(2.,1.,1.5,1.,2.); break; - case TD3b: speedValues = Arrays.asList(2.5,1.,1.75,1.,2.5); break; + case TD1b: + speedValues = Arrays.asList(1.6, 1., 1.05, 1., 1.6); + break; + case TD2b: + speedValues = Arrays.asList(2., 1., 1.5, 1., 2.); + break; + case TD3b: + speedValues = Arrays.asList(2.5, 1., 1.75, 1., 2.5); + break; - case TD1c: speedValues = Arrays.asList(1.6,1.6,1.05,1.,1.); break; - case TD2c: speedValues = Arrays.asList(2.,2.,1.5,1.,1.); break; - case TD3c: speedValues = Arrays.asList(2.5,2.5,1.75,1.,1.); break; + case TD1c: + speedValues = Arrays.asList(1.6, 1.6, 1.05, 1., 1.); + break; + case TD2c: + speedValues = Arrays.asList(2., 2., 1.5, 1., 1.); + break; + case TD3c: + speedValues = Arrays.asList(2.5, 2.5, 1.75, 1., 1.); + break; - case TD1d: speedValues = Arrays.asList(1.,1.,1.05,1.6,1.6); break; - case TD2d: speedValues = Arrays.asList(1.,1.,1.5,2.,2.); break; - case TD3d: speedValues = Arrays.asList(1.,1.,1.75,2.5,2.5); break; + case TD1d: + speedValues = Arrays.asList(1., 1., 1.05, 1.6, 1.6); + break; + case TD2d: + speedValues = Arrays.asList(1., 1., 1.5, 2., 2.); + break; + case TD3d: + speedValues = Arrays.asList(1., 1., 1.75, 2.5, 2.5); + break; - case TD4: speedValues = Arrays.asList(1.1,0.85,1.1,0.85,1.1); break; - case TD5: speedValues = Arrays.asList(1.2,0.8,1.,0.8,1.2); break; - case TD6: speedValues = Arrays.asList(1.2,0.7,1.2,0.7,1.2); break; + case TD4: + speedValues = Arrays.asList(1.1, 0.85, 1.1, 0.85, 1.1); + break; + case TD5: + speedValues = Arrays.asList(1.2, 0.8, 1., 0.8, 1.2); + break; + case TD6: + speedValues = Arrays.asList(1.2, 0.7, 1.2, 0.7, 1.2); + break; - case CLASSIC: speedValues = Arrays.asList(1.,1.,1.,1.,1.); break; + case CLASSIC: + speedValues = Arrays.asList(1., 1., 1., 1., 1.); + break; } return speedValues; } @@ -88,23 +120,23 @@ public class Figliozzi { public static class TDCosts implements VehicleRoutingTransportCosts { - - private List timeBins; - - private List speed; + + private List timeBins; + + private List speed; private Locations locations; private double transportDistanceParameter = 1.; private double transportTimeParameter = 1.; - - public TDCosts(Locations locations, List timeBins, List speedValues) { - super(); - speed = speedValues; - this.timeBins = timeBins; + + public TDCosts(Locations locations, List timeBins, List speedValues) { + super(); + speed = speedValues; + this.timeBins = timeBins; this.locations = locations; - } + } public void setTransportDistanceParameter(double transportDistanceParameter) { this.transportDistanceParameter = transportDistanceParameter; @@ -115,79 +147,75 @@ public class Figliozzi { } @Override - public double getTransportCost(Location from, Location to, double departureTime, Driver driver, Vehicle vehicle) { - return transportDistanceParameter * EuclideanDistanceCalculator.calculateDistance(locations.getCoord(from.getId()),locations.getCoord(to.getId())) + - transportTimeParameter * getTransportTime(from, to,departureTime, driver, vehicle); - } - - @Override - public double getBackwardTransportCost(Location from, Location to,double arrivalTime, Driver driver, Vehicle vehicle) { - return transportDistanceParameter * EuclideanDistanceCalculator.calculateDistance(locations.getCoord(from.getId()),locations.getCoord(to.getId())) + - transportTimeParameter * getBackwardTransportTime(from, to, arrivalTime, driver, vehicle); + public double getTransportCost(Location from, Location to, double departureTime, Driver driver, Vehicle vehicle) { + return transportDistanceParameter * EuclideanDistanceCalculator.calculateDistance(locations.getCoord(from.getId()), locations.getCoord(to.getId())) + + transportTimeParameter * getTransportTime(from, to, departureTime, driver, vehicle); } - - @Override - public double getTransportTime(Location from, Location to, double departureTime, Driver driver, Vehicle vehicle) { - if(from.equals(to)){ - return 0.0; - } - double totalTravelTime = 0.0; - double distanceToTravel = EuclideanDistanceCalculator.calculateDistance(locations.getCoord(from.getId()), locations.getCoord(to.getId())); - double currentTime = departureTime; - for(int i=0;i maxReachableDistance){ - distanceToTravel = distanceToTravel - maxReachableDistance; - totalTravelTime += (timeThreshold-currentTime); - currentTime = timeThreshold; - } - else{ //<= maxReachableDistance - totalTravelTime += distanceToTravel/speed.get(i); - return totalTravelTime; - } - } - } - return Double.MAX_VALUE; - } + @Override + public double getBackwardTransportCost(Location from, Location to, double arrivalTime, Driver driver, Vehicle vehicle) { + return transportDistanceParameter * EuclideanDistanceCalculator.calculateDistance(locations.getCoord(from.getId()), locations.getCoord(to.getId())) + + transportTimeParameter * getBackwardTransportTime(from, to, arrivalTime, driver, vehicle); + } - @Override - public double getBackwardTransportTime(Location from, Location to,double arrivalTime, Driver driver, Vehicle vehicle) { - if(from.equals(to)){ - return 0.0; - } - double totalTravelTime = 0.0; - double distanceToTravel = EuclideanDistanceCalculator.calculateDistance(locations.getCoord(from.getId()), locations.getCoord(to.getId())); - double currentTime = arrivalTime; - for(int i=timeBins.size()-1;i>=0;i--){ - double nextLowerTimeThreshold; - if(i>0){ - nextLowerTimeThreshold = timeBins.get(i-1); - } - else{ - nextLowerTimeThreshold = 0; - } - if(currentTime > nextLowerTimeThreshold){ - double maxReachableDistance = (currentTime - nextLowerTimeThreshold)*speed.get(i); - if(distanceToTravel > maxReachableDistance){ - distanceToTravel = distanceToTravel - maxReachableDistance; - totalTravelTime += (currentTime-nextLowerTimeThreshold); - currentTime = nextLowerTimeThreshold; - } - else{ //<= maxReachableDistance - totalTravelTime += distanceToTravel/speed.get(i); - return totalTravelTime; - } - } - } - return Double.MAX_VALUE; - } + @Override + public double getTransportTime(Location from, Location to, double departureTime, Driver driver, Vehicle vehicle) { + if (from.equals(to)) { + return 0.0; + } + double totalTravelTime = 0.0; + double distanceToTravel = EuclideanDistanceCalculator.calculateDistance(locations.getCoord(from.getId()), locations.getCoord(to.getId())); + double currentTime = departureTime; + for (int i = 0; i < timeBins.size(); i++) { + double timeThreshold = timeBins.get(i); + if (currentTime < timeThreshold) { + double maxReachableDistance = (timeThreshold - currentTime) * speed.get(i); + if (distanceToTravel > maxReachableDistance) { + distanceToTravel = distanceToTravel - maxReachableDistance; + totalTravelTime += (timeThreshold - currentTime); + currentTime = timeThreshold; + } else { //<= maxReachableDistance + totalTravelTime += distanceToTravel / speed.get(i); + return totalTravelTime; + } + } + } + return Double.MAX_VALUE; + } - - } + @Override + public double getBackwardTransportTime(Location from, Location to, double arrivalTime, Driver driver, Vehicle vehicle) { + if (from.equals(to)) { + return 0.0; + } + double totalTravelTime = 0.0; + double distanceToTravel = EuclideanDistanceCalculator.calculateDistance(locations.getCoord(from.getId()), locations.getCoord(to.getId())); + double currentTime = arrivalTime; + for (int i = timeBins.size() - 1; i >= 0; i--) { + double nextLowerTimeThreshold; + if (i > 0) { + nextLowerTimeThreshold = timeBins.get(i - 1); + } else { + nextLowerTimeThreshold = 0; + } + if (currentTime > nextLowerTimeThreshold) { + double maxReachableDistance = (currentTime - nextLowerTimeThreshold) * speed.get(i); + if (distanceToTravel > maxReachableDistance) { + distanceToTravel = distanceToTravel - maxReachableDistance; + totalTravelTime += (currentTime - nextLowerTimeThreshold); + currentTime = nextLowerTimeThreshold; + } else { //<= maxReachableDistance + totalTravelTime += distanceToTravel / speed.get(i); + return totalTravelTime; + } + } + } + return Double.MAX_VALUE; + } + + + } } diff --git a/jsprit-instances/src/main/java/jsprit/instance/reader/LiLimReader.java b/jsprit-instances/src/main/java/jsprit/instance/reader/LiLimReader.java index 5044cceb..092c5dfd 100644 --- a/jsprit-instances/src/main/java/jsprit/instance/reader/LiLimReader.java +++ b/jsprit-instances/src/main/java/jsprit/instance/reader/LiLimReader.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.instance.reader; @@ -39,169 +39,167 @@ import java.util.Map; /** - * test instances for the capacitated vrp with pickup and deliveries and time windows. + * test instances for the capacitated vrp with pickup and deliveries and time windows. * instances are from li and lim and can be found at: * http://www.top.sintef.no/vrp/benchmarks.html - * @author stefan schroeder * + * @author stefan schroeder */ public class LiLimReader { - - static class CustomerData{ - public Coordinate coord; - public double start; - public double end; - public double serviceTime; - - public CustomerData(Coordinate coord, double start, double end, double serviceTime) { - super(); - this.coord = coord; - this.start = start; - this.end = end; - this.serviceTime = serviceTime; - } - } - - static class Relation{ - public String from; - public String to; - public int demand; - public Relation(String from, String to, int demand) { - super(); - this.from = from; - this.to = to; - this.demand = demand; - } - - } - - private static Logger logger = LogManager.getLogger(LiLimReader.class); - - private VehicleRoutingProblem.Builder vrpBuilder; - - private int vehicleCapacity; - - private String depotId; - - private Map customers; - - private Collection relations; - - private double depotOpeningTime; - private double depotClosingTime; + static class CustomerData { + public Coordinate coord; + public double start; + public double end; + public double serviceTime; - private int fixCosts = 0; - - public LiLimReader(Builder vrpBuilder) { - customers = new HashMap(); - relations = new ArrayList(); - this.vrpBuilder = vrpBuilder; - } - - public LiLimReader(Builder builder, int fixCosts) { - customers = new HashMap(); - relations = new ArrayList(); - this.vrpBuilder = builder; - this.fixCosts = fixCosts; - } + public CustomerData(Coordinate coord, double start, double end, double serviceTime) { + super(); + this.coord = coord; + this.start = start; + this.end = end; + this.serviceTime = serviceTime; + } + } - public void read(String filename){ - readShipments(filename); - buildShipments(); - VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type").addCapacityDimension(0, vehicleCapacity) - .setCostPerDistance(1.0).setFixedCost(fixCosts).build(); - VehicleImpl vehicle = VehicleImpl.Builder.newInstance("vehicle") - .setEarliestStart(depotOpeningTime).setLatestArrival(depotClosingTime) - .setStartLocation(Location.Builder.newInstance().setCoordinate(customers.get(depotId).coord).build()).setType(type).build(); - vrpBuilder.addVehicle(vehicle); - } - - private void buildShipments() { - Integer counter = 0; - for(Relation rel : relations){ - counter++; - String from = rel.from; - String to = rel.to; - int demand = rel.demand; - Shipment s = Shipment.Builder.newInstance(counter.toString()).addSizeDimension(0, demand) - .setPickupLocation(Location.Builder.newInstance().setCoordinate(customers.get(from).coord).build()).setPickupServiceTime(customers.get(from).serviceTime) - .setPickupTimeWindow(TimeWindow.newInstance(customers.get(from).start, customers.get(from).end)) - .setDeliveryLocation(Location.Builder.newInstance().setCoordinate(customers.get(to).coord).build()).setDeliveryServiceTime(customers.get(to).serviceTime) - .setDeliveryTimeWindow(TimeWindow.newInstance(customers.get(to).start, customers.get(to).end)).build(); - vrpBuilder.addJob(s); - } - - } - - private BufferedReader getReader(String file) { - BufferedReader reader = null; - try { - reader = new BufferedReader(new FileReader(file)); - } catch (FileNotFoundException e1) { - e1.printStackTrace(); - logger.error(e1); - System.exit(1); - } - return reader; - } + static class Relation { + public String from; + public String to; + public int demand; - private void readShipments(String file) { - BufferedReader reader = getReader(file); - String line = null; - boolean firstLine = true; - try { - while((line = reader.readLine()) != null){ - line = line.replace("\r", ""); - line = line.trim(); - String[] tokens = line.split("\t"); - if(firstLine){ - int vehicleCapacity = getInt(tokens[1]); - this.vehicleCapacity = vehicleCapacity; - firstLine = false; - continue; - } - else{ - String customerId = tokens[0]; - Coordinate coord = makeCoord(tokens[1], tokens[2]); - int demand = getInt(tokens[3]); - double startTimeWindow = getDouble(tokens[4]); - double endTimeWindow = getDouble(tokens[5]); - double serviceTime = getDouble(tokens[6]); + public Relation(String from, String to, int demand) { + super(); + this.from = from; + this.to = to; + this.demand = demand; + } + + } + + private static Logger logger = LogManager.getLogger(LiLimReader.class); + + private VehicleRoutingProblem.Builder vrpBuilder; + + private int vehicleCapacity; + + private String depotId; + + private Map customers; + + private Collection relations; + + private double depotOpeningTime; + + private double depotClosingTime; + + private int fixCosts = 0; + + public LiLimReader(Builder vrpBuilder) { + customers = new HashMap(); + relations = new ArrayList(); + this.vrpBuilder = vrpBuilder; + } + + public LiLimReader(Builder builder, int fixCosts) { + customers = new HashMap(); + relations = new ArrayList(); + this.vrpBuilder = builder; + this.fixCosts = fixCosts; + } + + public void read(String filename) { + readShipments(filename); + buildShipments(); + VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type").addCapacityDimension(0, vehicleCapacity) + .setCostPerDistance(1.0).setFixedCost(fixCosts).build(); + VehicleImpl vehicle = VehicleImpl.Builder.newInstance("vehicle") + .setEarliestStart(depotOpeningTime).setLatestArrival(depotClosingTime) + .setStartLocation(Location.Builder.newInstance().setCoordinate(customers.get(depotId).coord).build()).setType(type).build(); + vrpBuilder.addVehicle(vehicle); + } + + private void buildShipments() { + Integer counter = 0; + for (Relation rel : relations) { + counter++; + String from = rel.from; + String to = rel.to; + int demand = rel.demand; + Shipment s = Shipment.Builder.newInstance(counter.toString()).addSizeDimension(0, demand) + .setPickupLocation(Location.Builder.newInstance().setCoordinate(customers.get(from).coord).build()).setPickupServiceTime(customers.get(from).serviceTime) + .setPickupTimeWindow(TimeWindow.newInstance(customers.get(from).start, customers.get(from).end)) + .setDeliveryLocation(Location.Builder.newInstance().setCoordinate(customers.get(to).coord).build()).setDeliveryServiceTime(customers.get(to).serviceTime) + .setDeliveryTimeWindow(TimeWindow.newInstance(customers.get(to).start, customers.get(to).end)).build(); + vrpBuilder.addJob(s); + } + + } + + private BufferedReader getReader(String file) { + BufferedReader reader = null; + try { + reader = new BufferedReader(new FileReader(file)); + } catch (FileNotFoundException e1) { + throw new RuntimeException(e1); + } + return reader; + } + + private void readShipments(String file) { + BufferedReader reader = getReader(file); + String line = null; + boolean firstLine = true; + try { + while ((line = reader.readLine()) != null) { + line = line.replace("\r", ""); + line = line.trim(); + String[] tokens = line.split("\t"); + if (firstLine) { + int vehicleCapacity = getInt(tokens[1]); + this.vehicleCapacity = vehicleCapacity; + firstLine = false; + continue; + } else { + String customerId = tokens[0]; + Coordinate coord = makeCoord(tokens[1], tokens[2]); + int demand = getInt(tokens[3]); + double startTimeWindow = getDouble(tokens[4]); + double endTimeWindow = getDouble(tokens[5]); + double serviceTime = getDouble(tokens[6]); // vrpBuilder.addLocation(customerId, coord); - customers.put(customerId, new CustomerData(coord,startTimeWindow,endTimeWindow, serviceTime)); - if(customerId.equals("0")){ - depotId = customerId; - depotOpeningTime = startTimeWindow; - depotClosingTime = endTimeWindow; - } - if(demand > 0){ - relations.add(new Relation(customerId,tokens[8],demand)); - } - } - } - reader.close(); - } catch (IOException e) { - e.printStackTrace(); - } - - } - - private Coordinate makeCoord(String xString, String yString) { - double x = Double.parseDouble(xString); - double y = Double.parseDouble(yString); - return new Coordinate(x,y); - } - - private double getDouble(String string) { - return Double.parseDouble(string); - } + customers.put(customerId, new CustomerData(coord, startTimeWindow, endTimeWindow, serviceTime)); + if (customerId.equals("0")) { + depotId = customerId; + depotOpeningTime = startTimeWindow; + depotClosingTime = endTimeWindow; + } + if (demand > 0) { + relations.add(new Relation(customerId, tokens[8], demand)); + } + } + } + reader.close(); + } catch (IOException e) { + e.printStackTrace(); + } - private int getInt(String string) { - return Integer.parseInt(string); - } + } + + private Coordinate makeCoord(String xString, String yString) { + double x = Double.parseDouble(xString); + double y = Double.parseDouble(yString); + return new Coordinate(x, y); + } + + private double getDouble(String string) { + return Double.parseDouble(string); + } + + private int getInt(String string) { + return Integer.parseInt(string); + } } diff --git a/jsprit-instances/src/main/java/jsprit/instance/reader/LopezIbanezBlumReader.java b/jsprit-instances/src/main/java/jsprit/instance/reader/LopezIbanezBlumReader.java index 6ade4941..e84a1034 100644 --- a/jsprit-instances/src/main/java/jsprit/instance/reader/LopezIbanezBlumReader.java +++ b/jsprit-instances/src/main/java/jsprit/instance/reader/LopezIbanezBlumReader.java @@ -27,42 +27,39 @@ public class LopezIbanezBlumReader { this.builder = builder; } - public void read(String instanceFile){ + public void read(String instanceFile) { builder.setFleetSize(VehicleRoutingProblem.FleetSize.FINITE); BufferedReader reader = getReader(instanceFile); String line; int noNodes = 0; int lineCount = 1; FastVehicleRoutingTransportCostsMatrix.Builder matrixBuilder = null; - while((line = readLine(reader)) != null){ - if(line.startsWith("#")) continue; - if(lineCount == 1){ + while ((line = readLine(reader)) != null) { + if (line.startsWith("#")) continue; + if (lineCount == 1) { noNodes = Integer.parseInt(line); - matrixBuilder = FastVehicleRoutingTransportCostsMatrix.Builder.newInstance(noNodes,false); + matrixBuilder = FastVehicleRoutingTransportCostsMatrix.Builder.newInstance(noNodes, false); lineCount++; continue; - } - else if(lineCount <= 1 + noNodes){ + } else if (lineCount <= 1 + noNodes) { String[] wimaTokens = line.split("\\s+"); int nodeIndex = lineCount - 2; - for(int toIndex=0;toIndex1: " + vrp.getTransportCosts().getTransportCost(Location.newInstance(0), Location.newInstance(1), 0, null, null)); - System.out.println("0->20: " + vrp.getTransportCosts().getTransportCost(Location.newInstance(0), Location.newInstance(20),0,null,null)); - System.out.println("4->18: " + vrp.getTransportCosts().getTransportCost(Location.newInstance(4), Location.newInstance(18),0,null,null)); - System.out.println("20->8: " + vrp.getTransportCosts().getTransportCost(Location.newInstance(20), Location.newInstance(8),0,null,null)); - System.out.println("18: " + ((Service)vrp.getJobs().get(""+18)).getTimeWindow().getStart() + " " + ((Service)vrp.getJobs().get(""+18)).getTimeWindow().getEnd()); - System.out.println("20: " + ((Service)vrp.getJobs().get(""+20)).getTimeWindow().getStart() + " " + ((Service)vrp.getJobs().get(""+20)).getTimeWindow().getEnd()); - System.out.println("1: " + ((Service)vrp.getJobs().get(""+1)).getTimeWindow().getStart() + " " + ((Service)vrp.getJobs().get(""+1)).getTimeWindow().getEnd()); + System.out.println("0->20: " + vrp.getTransportCosts().getTransportCost(Location.newInstance(0), Location.newInstance(20), 0, null, null)); + System.out.println("4->18: " + vrp.getTransportCosts().getTransportCost(Location.newInstance(4), Location.newInstance(18), 0, null, null)); + System.out.println("20->8: " + vrp.getTransportCosts().getTransportCost(Location.newInstance(20), Location.newInstance(8), 0, null, null)); + System.out.println("18: " + ((Service) vrp.getJobs().get("" + 18)).getTimeWindow().getStart() + " " + ((Service) vrp.getJobs().get("" + 18)).getTimeWindow().getEnd()); + System.out.println("20: " + ((Service) vrp.getJobs().get("" + 20)).getTimeWindow().getStart() + " " + ((Service) vrp.getJobs().get("" + 20)).getTimeWindow().getEnd()); + System.out.println("1: " + ((Service) vrp.getJobs().get("" + 1)).getTimeWindow().getStart() + " " + ((Service) vrp.getJobs().get("" + 1)).getTimeWindow().getEnd()); } - private void close(BufferedReader reader) { + private void close(BufferedReader reader) { try { reader.close(); } catch (IOException e) { - e.printStackTrace(); - logger.error(e); - System.exit(1); + throw new RuntimeException(e); } } @@ -99,10 +94,7 @@ public class LopezIbanezBlumReader { try { return reader.readLine(); } catch (IOException e) { - e.printStackTrace(); - logger.error(e); - System.exit(1); - return null; + throw new RuntimeException(e); } } @@ -111,9 +103,7 @@ public class LopezIbanezBlumReader { try { reader = new BufferedReader(new FileReader(solomonFile)); } catch (FileNotFoundException e1) { - e1.printStackTrace(); - logger.error(e1); - System.exit(1); + throw new RuntimeException(e1); } return reader; } diff --git a/jsprit-instances/src/main/java/jsprit/instance/reader/LuiShenReader.java b/jsprit-instances/src/main/java/jsprit/instance/reader/LuiShenReader.java index 32c1189f..a22526d7 100644 --- a/jsprit-instances/src/main/java/jsprit/instance/reader/LuiShenReader.java +++ b/jsprit-instances/src/main/java/jsprit/instance/reader/LuiShenReader.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.instance.reader; @@ -36,155 +36,144 @@ import java.io.IOException; public class LuiShenReader { - private static Logger logger = LogManager.getLogger(LuiShenReader.class); - - private final VehicleRoutingProblem.Builder vrpBuilder; + private static Logger logger = LogManager.getLogger(LuiShenReader.class); - private double coordProjectionFactor = 1; + private final VehicleRoutingProblem.Builder vrpBuilder; - public LuiShenReader(VehicleRoutingProblem.Builder vrpBuilder) { - super(); - this.vrpBuilder = vrpBuilder; - } - - /** - * Reads input files to build Liu Shen problem. - * - *

The instance-file is a solomon file. The vehicle-file is a - * txt-file that has the following columns: - *

Vehicle;Capacity;Cost_a;Cost_b;Cost_c - *

Concrete vehicleType: - *

A;100;300;60;30 - * - *

In the example above, the vehicle-type with typeId A has - * a capacity of 100, and fixed costs of 100 in cost scenario "a", - * 300 in "b" and 30 in "c". + private double coordProjectionFactor = 1; - * @param instanceFile is a solomon-instance-file - * @param vehicleFile - * @param costScenario is either "a", "b" or "c" - */ - public void read(String instanceFile, String vehicleFile, String costScenario){ - vrpBuilder.setFleetSize(FleetSize.INFINITE); - BufferedReader reader = getReader(instanceFile); - int counter = 0; - String line = null; - while((line = readLine(reader)) != null){ - line = line.replace("\r", ""); - line = line.trim(); - String[] tokens = line.split(" +"); - counter++; - if(counter > 9){ - if(tokens.length < 7) continue; - Coordinate coord = makeCoord(tokens[1],tokens[2]); - String customerId = tokens[0]; - int demand = Integer.parseInt(tokens[3]); - double start = Double.parseDouble(tokens[4])*coordProjectionFactor ; - double end = Double.parseDouble(tokens[5])*coordProjectionFactor; - double serviceTime = Double.parseDouble(tokens[6])*coordProjectionFactor; - if(counter == 10){ - createVehicles(vehicleFile,costScenario,customerId,coord,start,end); - } - else{ - Service service = Service.Builder.newInstance("" + counter).addSizeDimension(0, demand) - .setLocation(Location.Builder.newInstance().setCoordinate(coord).setId(customerId).build()).setServiceTime(serviceTime) - .setTimeWindow(TimeWindow.newInstance(start, end)).build(); - vrpBuilder.addJob(service); - } - } - } - close(reader); - } + public LuiShenReader(VehicleRoutingProblem.Builder vrpBuilder) { + super(); + this.vrpBuilder = vrpBuilder; + } - private void createVehicles(String vehicleFileName, String costScenario, String locationId, Coordinate coord, double start, double end) { - BufferedReader reader = getReader(vehicleFileName); - - int costScenarioColumn = getCostScenarioColumn(costScenario); - int vehicleIdColumn = 0; - int capacityColumn = 1; - - - - boolean firstLine = true; - String line = null; - while((line = readLine(reader)) != null){ - if(firstLine){ - firstLine = false; - continue; - } - String[] tokens = line.split(";"); - String vehicleId = tokens[vehicleIdColumn]; - int capacity = Integer.parseInt(tokens[capacityColumn]); - int fixCost = Integer.parseInt(tokens[costScenarioColumn]); - - VehicleTypeImpl.Builder typeBuilder = VehicleTypeImpl.Builder.newInstance(vehicleId).addCapacityDimension(0, capacity); - typeBuilder.setFixedCost(fixCost).setCostPerDistance(1.0); - - VehicleTypeImpl type = typeBuilder.build(); - - VehicleImpl reprVehicle = VehicleImpl.Builder.newInstance(vehicleId).setEarliestStart(start).setLatestArrival(end). - setStartLocation(Location.Builder.newInstance().setId(locationId).setCoordinate(coord).build()) - .setType(type).build(); - - vrpBuilder.addVehicle(reprVehicle); - - } - close(reader); - } - - private int getCostScenarioColumn(String costScenario) { - if(costScenario.equals("a")){ - return 2; - } - else if(costScenario.equals("b")){ - return 3; - } - else if(costScenario.equals("c")){ - return 4; - } - throw new IllegalStateException("costScenario " + costScenario + " not known"); - } - - public void setCoordProjectionFactor(double coordProjectionFactor) { - this.coordProjectionFactor = coordProjectionFactor; - } + /** + * Reads input files to build Liu Shen problem. + *

+ *

The instance-file is a solomon file. The vehicle-file is a + * txt-file that has the following columns: + *

Vehicle;Capacity;Cost_a;Cost_b;Cost_c + *

Concrete vehicleType: + *

A;100;300;60;30 + *

+ *

In the example above, the vehicle-type with typeId A has + * a capacity of 100, and fixed costs of 100 in cost scenario "a", + * 300 in "b" and 30 in "c". + * + * @param instanceFile is a solomon-instance-file + * @param vehicleFile + * @param costScenario is either "a", "b" or "c" + */ + public void read(String instanceFile, String vehicleFile, String costScenario) { + vrpBuilder.setFleetSize(FleetSize.INFINITE); + BufferedReader reader = getReader(instanceFile); + int counter = 0; + String line = null; + while ((line = readLine(reader)) != null) { + line = line.replace("\r", ""); + line = line.trim(); + String[] tokens = line.split(" +"); + counter++; + if (counter > 9) { + if (tokens.length < 7) continue; + Coordinate coord = makeCoord(tokens[1], tokens[2]); + String customerId = tokens[0]; + int demand = Integer.parseInt(tokens[3]); + double start = Double.parseDouble(tokens[4]) * coordProjectionFactor; + double end = Double.parseDouble(tokens[5]) * coordProjectionFactor; + double serviceTime = Double.parseDouble(tokens[6]) * coordProjectionFactor; + if (counter == 10) { + createVehicles(vehicleFile, costScenario, customerId, coord, start, end); + } else { + Service service = Service.Builder.newInstance("" + counter).addSizeDimension(0, demand) + .setLocation(Location.Builder.newInstance().setCoordinate(coord).setId(customerId).build()).setServiceTime(serviceTime) + .setTimeWindow(TimeWindow.newInstance(start, end)).build(); + vrpBuilder.addJob(service); + } + } + } + close(reader); + } - private void close(BufferedReader reader) { - try { - reader.close(); - } catch (IOException e) { - e.printStackTrace(); - logger.error(e); - System.exit(1); - } - } + private void createVehicles(String vehicleFileName, String costScenario, String locationId, Coordinate coord, double start, double end) { + BufferedReader reader = getReader(vehicleFileName); - private String readLine(BufferedReader reader) { - try { - return reader.readLine(); - } catch (IOException e) { - e.printStackTrace(); - logger.error(e); - System.exit(1); - return null; - } - } - - private Coordinate makeCoord(String xString, String yString) { - double x = Double.parseDouble(xString); - double y = Double.parseDouble(yString); - return new Coordinate(x*coordProjectionFactor,y*coordProjectionFactor); - } + int costScenarioColumn = getCostScenarioColumn(costScenario); + int vehicleIdColumn = 0; + int capacityColumn = 1; - private BufferedReader getReader(String solomonFile) { - BufferedReader reader = null; - try { - reader = new BufferedReader(new FileReader(solomonFile)); - } catch (FileNotFoundException e1) { - e1.printStackTrace(); - logger.error(e1); - System.exit(1); - } - return reader; - } + + boolean firstLine = true; + String line = null; + while ((line = readLine(reader)) != null) { + if (firstLine) { + firstLine = false; + continue; + } + String[] tokens = line.split(";"); + String vehicleId = tokens[vehicleIdColumn]; + int capacity = Integer.parseInt(tokens[capacityColumn]); + int fixCost = Integer.parseInt(tokens[costScenarioColumn]); + + VehicleTypeImpl.Builder typeBuilder = VehicleTypeImpl.Builder.newInstance(vehicleId).addCapacityDimension(0, capacity); + typeBuilder.setFixedCost(fixCost).setCostPerDistance(1.0); + + VehicleTypeImpl type = typeBuilder.build(); + + VehicleImpl reprVehicle = VehicleImpl.Builder.newInstance(vehicleId).setEarliestStart(start).setLatestArrival(end). + setStartLocation(Location.Builder.newInstance().setId(locationId).setCoordinate(coord).build()) + .setType(type).build(); + + vrpBuilder.addVehicle(reprVehicle); + + } + close(reader); + } + + private int getCostScenarioColumn(String costScenario) { + if (costScenario.equals("a")) { + return 2; + } else if (costScenario.equals("b")) { + return 3; + } else if (costScenario.equals("c")) { + return 4; + } + throw new IllegalStateException("costScenario " + costScenario + " not known"); + } + + public void setCoordProjectionFactor(double coordProjectionFactor) { + this.coordProjectionFactor = coordProjectionFactor; + } + + private void close(BufferedReader reader) { + try { + reader.close(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + private String readLine(BufferedReader reader) { + try { + return reader.readLine(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + private Coordinate makeCoord(String xString, String yString) { + double x = Double.parseDouble(xString); + double y = Double.parseDouble(yString); + return new Coordinate(x * coordProjectionFactor, y * coordProjectionFactor); + } + + private BufferedReader getReader(String solomonFile) { + BufferedReader reader = null; + try { + reader = new BufferedReader(new FileReader(solomonFile)); + } catch (FileNotFoundException e1) { + throw new RuntimeException(e1); + } + return reader; + } } diff --git a/jsprit-instances/src/main/java/jsprit/instance/reader/SolomonReader.java b/jsprit-instances/src/main/java/jsprit/instance/reader/SolomonReader.java index d3ac83d5..07cf7140 100644 --- a/jsprit-instances/src/main/java/jsprit/instance/reader/SolomonReader.java +++ b/jsprit-instances/src/main/java/jsprit/instance/reader/SolomonReader.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.instance.reader; @@ -36,136 +36,127 @@ import java.io.IOException; /** * Reader that reads the well-known solomon-instances. - * + *

*

See: neo.org - * - * @author stefan * + * @author stefan */ public class SolomonReader { - /** - * @param costProjectionFactor the costProjectionFactor to set - */ - public void setVariableCostProjectionFactor(double costProjectionFactor) { - this.variableCostProjectionFactor = costProjectionFactor; - } + /** + * @param costProjectionFactor the costProjectionFactor to set + */ + public void setVariableCostProjectionFactor(double costProjectionFactor) { + this.variableCostProjectionFactor = costProjectionFactor; + } - private static Logger logger = LogManager.getLogger(SolomonReader.class); - - private final VehicleRoutingProblem.Builder vrpBuilder; + private static Logger logger = LogManager.getLogger(SolomonReader.class); - private double coordProjectionFactor = 1; + private final VehicleRoutingProblem.Builder vrpBuilder; - private double timeProjectionFactor = 1; - - private double variableCostProjectionFactor = 1; - - private double fixedCostPerVehicle = 0.0; - - public SolomonReader(VehicleRoutingProblem.Builder vrpBuilder) { - super(); - this.vrpBuilder = vrpBuilder; - } - - public SolomonReader(VehicleRoutingProblem.Builder vrpBuilder, double fixedCostPerVehicle) { - super(); - this.vrpBuilder = vrpBuilder; - this.fixedCostPerVehicle=fixedCostPerVehicle; - } - - public void read(String solomonFile){ - vrpBuilder.setFleetSize(FleetSize.INFINITE); - BufferedReader reader = getReader(solomonFile); - int vehicleCapacity = 0; - - int counter = 0; - String line; - while((line = readLine(reader)) != null){ - line = line.replace("\r", ""); - line = line.trim(); - String[] tokens = line.split(" +"); - counter++; - if(counter == 5){ - vehicleCapacity = Integer.parseInt(tokens[1]); - continue; - } - if(counter > 9){ - if(tokens.length < 7) continue; - Coordinate coord = makeCoord(tokens[1],tokens[2]); - String customerId = tokens[0]; - int demand = Integer.parseInt(tokens[3]); - double start = Double.parseDouble(tokens[4])*timeProjectionFactor; - double end = Double.parseDouble(tokens[5])*timeProjectionFactor; - double serviceTime = Double.parseDouble(tokens[6])*timeProjectionFactor; - if(counter == 10){ - VehicleTypeImpl.Builder typeBuilder = VehicleTypeImpl.Builder.newInstance("solomonType").addCapacityDimension(0, vehicleCapacity); - typeBuilder.setCostPerDistance(1.0*variableCostProjectionFactor).setFixedCost(fixedCostPerVehicle); - VehicleTypeImpl vehicleType = typeBuilder.build(); + private double coordProjectionFactor = 1; - VehicleImpl vehicle = VehicleImpl.Builder.newInstance("solomonVehicle").setEarliestStart(start).setLatestArrival(end) - .setStartLocation(Location.Builder.newInstance().setId(customerId) - .setCoordinate(coord).build()).setType(vehicleType).build(); - vrpBuilder.addVehicle(vehicle); - - } - else{ - Service service = Service.Builder.newInstance(customerId).addSizeDimension(0, demand) - .setLocation(Location.Builder.newInstance().setCoordinate(coord).setId(customerId).build()).setServiceTime(serviceTime) - .setTimeWindow(TimeWindow.newInstance(start, end)).build(); - vrpBuilder.addJob(service); - } - } - } - close(reader); - } + private double timeProjectionFactor = 1; - public void setCoordProjectionFactor(double coordProjectionFactor) { - this.coordProjectionFactor = coordProjectionFactor; - } + private double variableCostProjectionFactor = 1; - private void close(BufferedReader reader) { - try { - reader.close(); - } catch (IOException e) { - e.printStackTrace(); - logger.error(e); - System.exit(1); - } - } + private double fixedCostPerVehicle = 0.0; - private String readLine(BufferedReader reader) { - try { - return reader.readLine(); - } catch (IOException e) { - e.printStackTrace(); - logger.error(e); - System.exit(1); - return null; - } - } - - private Coordinate makeCoord(String xString, String yString) { - double x = Double.parseDouble(xString); - double y = Double.parseDouble(yString); - return new Coordinate(x*coordProjectionFactor,y*coordProjectionFactor); - } + public SolomonReader(VehicleRoutingProblem.Builder vrpBuilder) { + super(); + this.vrpBuilder = vrpBuilder; + } - private BufferedReader getReader(String solomonFile) { - BufferedReader reader = null; - try { - reader = new BufferedReader(new FileReader(solomonFile)); - } catch (FileNotFoundException e1) { - e1.printStackTrace(); - logger.error(e1); - System.exit(1); - } - return reader; - } + public SolomonReader(VehicleRoutingProblem.Builder vrpBuilder, double fixedCostPerVehicle) { + super(); + this.vrpBuilder = vrpBuilder; + this.fixedCostPerVehicle = fixedCostPerVehicle; + } - public void setTimeProjectionFactor(double timeProjection) { - this.timeProjectionFactor=timeProjection; - - } + public void read(String solomonFile) { + vrpBuilder.setFleetSize(FleetSize.INFINITE); + BufferedReader reader = getReader(solomonFile); + int vehicleCapacity = 0; + + int counter = 0; + String line; + while ((line = readLine(reader)) != null) { + line = line.replace("\r", ""); + line = line.trim(); + String[] tokens = line.split(" +"); + counter++; + if (counter == 5) { + vehicleCapacity = Integer.parseInt(tokens[1]); + continue; + } + if (counter > 9) { + if (tokens.length < 7) continue; + Coordinate coord = makeCoord(tokens[1], tokens[2]); + String customerId = tokens[0]; + int demand = Integer.parseInt(tokens[3]); + double start = Double.parseDouble(tokens[4]) * timeProjectionFactor; + double end = Double.parseDouble(tokens[5]) * timeProjectionFactor; + double serviceTime = Double.parseDouble(tokens[6]) * timeProjectionFactor; + if (counter == 10) { + VehicleTypeImpl.Builder typeBuilder = VehicleTypeImpl.Builder.newInstance("solomonType").addCapacityDimension(0, vehicleCapacity); + typeBuilder.setCostPerDistance(1.0 * variableCostProjectionFactor).setFixedCost(fixedCostPerVehicle); + VehicleTypeImpl vehicleType = typeBuilder.build(); + + VehicleImpl vehicle = VehicleImpl.Builder.newInstance("solomonVehicle").setEarliestStart(start).setLatestArrival(end) + .setStartLocation(Location.Builder.newInstance().setId(customerId) + .setCoordinate(coord).build()).setType(vehicleType).build(); + vrpBuilder.addVehicle(vehicle); + + } else { + Service service = Service.Builder.newInstance(customerId).addSizeDimension(0, demand) + .setLocation(Location.Builder.newInstance().setCoordinate(coord).setId(customerId).build()).setServiceTime(serviceTime) + .setTimeWindow(TimeWindow.newInstance(start, end)).build(); + vrpBuilder.addJob(service); + } + } + } + close(reader); + } + + public void setCoordProjectionFactor(double coordProjectionFactor) { + this.coordProjectionFactor = coordProjectionFactor; + } + + private void close(BufferedReader reader) { + try { + reader.close(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + private String readLine(BufferedReader reader) { + try { + return reader.readLine(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + private Coordinate makeCoord(String xString, String yString) { + double x = Double.parseDouble(xString); + double y = Double.parseDouble(yString); + return new Coordinate(x * coordProjectionFactor, y * coordProjectionFactor); + } + + private BufferedReader getReader(String solomonFile) { + BufferedReader reader = null; + try { + reader = new BufferedReader(new FileReader(solomonFile)); + } catch (FileNotFoundException e1) { + throw new RuntimeException(e1); + } + return reader; + } + + public void setTimeProjectionFactor(double timeProjection) { + this.timeProjectionFactor = timeProjection; + + } } diff --git a/jsprit-instances/src/main/java/jsprit/instance/reader/TSPLIB95CostMatrixReader.java b/jsprit-instances/src/main/java/jsprit/instance/reader/TSPLIB95CostMatrixReader.java index 8fe324e6..fbdbd572 100644 --- a/jsprit-instances/src/main/java/jsprit/instance/reader/TSPLIB95CostMatrixReader.java +++ b/jsprit-instances/src/main/java/jsprit/instance/reader/TSPLIB95CostMatrixReader.java @@ -30,27 +30,27 @@ public class TSPLIB95CostMatrixReader { this.costMatrixBuilder = costMatrixBuilder; } - public void read(String matrixFile){ + public void read(String matrixFile) { BufferedReader reader = getBufferedReader(matrixFile); String line; boolean isEdgeWeights = false; int fromIndex = 0; - while( ( line = getLine(reader) ) != null ){ - if(line.startsWith("EDGE_WEIGHT_SECTION")){ + while ((line = getLine(reader)) != null) { + if (line.startsWith("EDGE_WEIGHT_SECTION")) { isEdgeWeights = true; continue; } - if(line.startsWith("DEMAND_SECTION")){ + if (line.startsWith("DEMAND_SECTION")) { isEdgeWeights = false; continue; } - if(isEdgeWeights){ + if (isEdgeWeights) { String[] tokens = line.split("\\s+"); String fromId = "" + (fromIndex + 1); - for(int i=0;i edgeWeights = new ArrayList(); int dimensions = 0; int coordIndex = 0; - Map indexMap = new HashMap(); - while( ( line_ = getLine(reader) ) != null ){ + Map indexMap = new HashMap(); + while ((line_ = getLine(reader)) != null) { String line = line_.trim(); - if(line.startsWith("EOF") || line.contains("EOF")){ + if (line.startsWith("EOF") || line.contains("EOF")) { break; } - if(line.startsWith("DIMENSION")){ + if (line.startsWith("DIMENSION")) { String[] tokens = line.split(":"); String dim = tokens[1].trim(); dimensions = Integer.parseInt(dim); @@ -79,86 +79,85 @@ public class TSPLIB95Reader { demands = new int[dimensions]; continue; } - if(line.startsWith("CAPACITY")){ + if (line.startsWith("CAPACITY")) { String[] tokens = line.trim().split(":"); capacity = Integer.parseInt(tokens[1].trim()); continue; } - if(line.startsWith("EDGE_WEIGHT_TYPE")){ + if (line.startsWith("EDGE_WEIGHT_TYPE")) { String[] tokens = line.trim().split(":"); edgeType = tokens[1].trim(); continue; } - if(line.startsWith("EDGE_WEIGHT_FORMAT")){ + if (line.startsWith("EDGE_WEIGHT_FORMAT")) { String[] tokens = line.trim().split(":"); edgeWeightFormat = tokens[1].trim(); continue; } - if(line.startsWith("NODE_COORD_SECTION")){ + if (line.startsWith("NODE_COORD_SECTION")) { isCoordSection = true; isDemandSection = false; isDepotSection = false; isEdgeWeightSection = false; continue; } - if(line.startsWith("DEMAND_SECTION")){ + if (line.startsWith("DEMAND_SECTION")) { isDemandSection = true; isCoordSection = false; isDepotSection = false; isEdgeWeightSection = false; continue; } - if(line.startsWith("DEPOT_SECTION")){ + if (line.startsWith("DEPOT_SECTION")) { isDepotSection = true; isDemandSection = false; isCoordSection = false; isEdgeWeightSection = false; continue; } - if(line.startsWith("EDGE_WEIGHT_SECTION")){ + if (line.startsWith("EDGE_WEIGHT_SECTION")) { isDepotSection = false; isCoordSection = false; isDemandSection = false; isEdgeWeightSection = true; continue; } - if(line.startsWith("DISPLAY_DATA_SECTION")){ + if (line.startsWith("DISPLAY_DATA_SECTION")) { isDepotSection = false; isCoordSection = true; isDemandSection = false; isEdgeWeightSection = false; continue; } - if(isCoordSection){ - if(coords == null) throw new IllegalStateException("DIMENSION tag missing"); + if (isCoordSection) { + if (coords == null) throw new IllegalStateException("DIMENSION tag missing"); String[] tokens = line.trim().split("\\s+"); Integer id = Integer.parseInt(tokens[0]); - if(switchCoordinates){ + if (switchCoordinates) { coords[coordIndex] = Coordinate.newInstance(Double.parseDouble(tokens[2]), Double.parseDouble(tokens[1])); - } - else coords[coordIndex] = Coordinate.newInstance(Double.parseDouble(tokens[1]), Double.parseDouble(tokens[2])); - indexMap.put(id,coordIndex); + } else + coords[coordIndex] = Coordinate.newInstance(Double.parseDouble(tokens[1]), Double.parseDouble(tokens[2])); + indexMap.put(id, coordIndex); coordIndex++; continue; } - if(isDemandSection){ - if(demands == null) throw new IllegalStateException("DIMENSION tag missing"); + if (isDemandSection) { + if (demands == null) throw new IllegalStateException("DIMENSION tag missing"); String[] tokens = line.trim().split("\\s+"); Integer id = Integer.parseInt(tokens[0]); int index = indexMap.get(id); demands[index] = Integer.parseInt(tokens[1]); continue; } - if(isDepotSection){ - if(line.equals("-1")){ + if (isDepotSection) { + if (line.equals("-1")) { isDepotSection = false; - } - else{ + } else { depotIds.add(Integer.parseInt(line)); } continue; } - if(isEdgeWeightSection){ + if (isEdgeWeightSection) { String[] tokens = line.trim().split("\\s+"); for (String s : tokens) edgeWeights.add(Double.parseDouble(s)); continue; @@ -166,113 +165,108 @@ public class TSPLIB95Reader { } close(reader); vrpBuilder.setFleetSize(VehicleRoutingProblem.FleetSize.FINITE); - for(Integer depotId : depotIds){ - VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type").addCapacityDimension(0,capacity).build(); + for (Integer depotId : depotIds) { + VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type").addCapacityDimension(0, capacity).build(); VehicleImpl vehicle = VehicleImpl.Builder.newInstance("vehicle") - .setStartLocation(Location.Builder.newInstance().setId(depotId.toString()).setCoordinate(coords[depotId - 1]).build()) - .setType(type).build(); + .setStartLocation(Location.Builder.newInstance().setId(depotId.toString()).setCoordinate(coords[depotId - 1]).build()) + .setType(type).build(); vrpBuilder.addVehicle(vehicle); } for (Integer id_ : indexMap.keySet()) { String id = id_.toString(); int index = indexMap.get(id_); - if(depotIds.isEmpty()){ - if(index == 0) { + if (depotIds.isEmpty()) { + if (index == 0) { VehicleImpl vehicle = VehicleImpl.Builder.newInstance("traveling_salesman") - .setStartLocation(Location.Builder.newInstance().setId(id) - .setCoordinate(coords[index]).setIndex(index).build()) - .build(); + .setStartLocation(Location.Builder.newInstance().setId(id) + .setCoordinate(coords[index]).setIndex(index).build()) + .build(); vrpBuilder.addVehicle(vehicle); continue; } } Service service = Service.Builder.newInstance(id) - .setLocation(Location.Builder.newInstance().setId(id) - .setCoordinate(coords[index]).setIndex(index).build()) - .addSizeDimension(0, demands[index]).build(); + .setLocation(Location.Builder.newInstance().setId(id) + .setCoordinate(coords[index]).setIndex(index).build()) + .addSizeDimension(0, demands[index]).build(); vrpBuilder.addJob(service); } - if(edgeType.equals("GEO")){ + if (edgeType.equals("GEO")) { List locations = new ArrayList(); - for(Vehicle v : vrpBuilder.getAddedVehicles()) locations.add(v.getStartLocation()); - for(Job j : vrpBuilder.getAddedJobs()) locations.add(((Service)j).getLocation()); + for (Vehicle v : vrpBuilder.getAddedVehicles()) locations.add(v.getStartLocation()); + for (Job j : vrpBuilder.getAddedJobs()) locations.add(((Service) j).getLocation()); vrpBuilder.setRoutingCost(getGEOMatrix(locations)); - } - else if(edgeType.equals("EXPLICIT")){ - if(edgeWeightFormat.equals("UPPER_ROW")){ - FastVehicleRoutingTransportCostsMatrix.Builder matrixBuilder = FastVehicleRoutingTransportCostsMatrix.Builder.newInstance(dimensions,true); + } else if (edgeType.equals("EXPLICIT")) { + if (edgeWeightFormat.equals("UPPER_ROW")) { + FastVehicleRoutingTransportCostsMatrix.Builder matrixBuilder = FastVehicleRoutingTransportCostsMatrix.Builder.newInstance(dimensions, true); int fromIndex = 0; int toIndex = 1; - for(int i=0;i fromIndex){ + for (int i = 0; i < edgeWeights.size(); i++) { + if (toIndex > fromIndex) { fromIndex++; toIndex = 0; } - matrixBuilder.addTransportDistance(fromIndex,toIndex,edgeWeights.get(i)); - matrixBuilder.addTransportTime(fromIndex,toIndex,edgeWeights.get(i)); + matrixBuilder.addTransportDistance(fromIndex, toIndex, edgeWeights.get(i)); + matrixBuilder.addTransportTime(fromIndex, toIndex, edgeWeights.get(i)); toIndex++; } vrpBuilder.setRoutingCost(matrixBuilder.build()); - } - else if(edgeWeightFormat.equals("FULL_MATRIX")){ - FastVehicleRoutingTransportCostsMatrix.Builder matrixBuilder = FastVehicleRoutingTransportCostsMatrix.Builder.newInstance(dimensions,false); + } else if (edgeWeightFormat.equals("FULL_MATRIX")) { + FastVehicleRoutingTransportCostsMatrix.Builder matrixBuilder = FastVehicleRoutingTransportCostsMatrix.Builder.newInstance(dimensions, false); int fromIndex = 0; int toIndex = 0; - for(int i=0;i noLocations) { - FastVehicleRoutingTransportCostsMatrix.Builder matrixBuilder = FastVehicleRoutingTransportCostsMatrix.Builder.newInstance(noLocations.size(),true); - for(Location i : noLocations){ - for(Location j : noLocations){ - matrixBuilder.addTransportDistance(i.getIndex(),j.getIndex(),getDistance(i,j)); + FastVehicleRoutingTransportCostsMatrix.Builder matrixBuilder = FastVehicleRoutingTransportCostsMatrix.Builder.newInstance(noLocations.size(), true); + for (Location i : noLocations) { + for (Location j : noLocations) { + matrixBuilder.addTransportDistance(i.getIndex(), j.getIndex(), getDistance(i, j)); matrixBuilder.addTransportTime(i.getIndex(), j.getIndex(), getDistance(i, j)); } } @@ -284,10 +278,10 @@ public class TSPLIB95Reader { double longitude_to = getLongitude(to); double latitude_from = getLatitude(from); double latitude_to = getLatitude(to); - double q1 = Math.cos( longitude_from - longitude_to); - double q2 = Math.cos( latitude_from - latitude_to); - double q3 = Math.cos( latitude_from + latitude_to); - return 6378.388 * Math.acos( .5 * ( ( 1. + q1 ) * q2 - ( 1. - q1 ) * q3 ) ) + 1.; + double q1 = Math.cos(longitude_from - longitude_to); + double q2 = Math.cos(latitude_from - latitude_to); + double q3 = Math.cos(latitude_from + latitude_to); + return 6378.388 * Math.acos(.5 * ((1. + q1) * q2 - (1. - q1) * q3)) + 1.; } private double getLatitude(Location loc) { @@ -303,7 +297,6 @@ public class TSPLIB95Reader { } - private void close(BufferedReader reader) { try { reader.close(); @@ -316,7 +309,7 @@ public class TSPLIB95Reader { private String getLine(BufferedReader reader) { String s = null; try { - s = reader.readLine(); + s = reader.readLine(); } catch (IOException e) { e.printStackTrace(); } diff --git a/jsprit-instances/src/main/java/jsprit/instance/reader/Taillard.java b/jsprit-instances/src/main/java/jsprit/instance/reader/Taillard.java index 56e3f07c..842583bd 100644 --- a/jsprit-instances/src/main/java/jsprit/instance/reader/Taillard.java +++ b/jsprit-instances/src/main/java/jsprit/instance/reader/Taillard.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.instance.reader; @@ -96,7 +96,7 @@ package jsprit.instance.reader; // //public class Taillard { // -// +// // static class MyLocations implements Locations{ // // private Map locations = new HashMap(); @@ -110,9 +110,9 @@ package jsprit.instance.reader; // return locations.get(id); // } // } -// +// // public static final String VRPHE = "vrphe"; -// +// // public static final String VFM = "vfm"; // // private static Logger logger = Logger.getLogger(Christophides.class); @@ -126,7 +126,7 @@ package jsprit.instance.reader; // private String vehicleFile; // // private String vehicleCostScenario; -// +// // private String vrpType; // // private ResultWriter resultWriter; @@ -142,15 +142,15 @@ package jsprit.instance.reader; // this.vehicleCostScenario = vehicleCostScenario; // this.vrpType = vrpType; // } -// +// // public static void main(String[] args) throws IOException { // System.out.println("start " + System.currentTimeMillis()); -// Logger.getRootLogger().setLevel(Level.INFO); -// +// Logger.getRootLogger().setLevel(Level.INFO); +// // int nOfProcessors = Runtime.getRuntime().availableProcessors(); // logger.info("nOfProcessors: " + nOfProcessors); // ExecutorService executor = Executors.newFixedThreadPool(nOfProcessors+2); -// +// // ResultWriter resultWriter = new ResultWriter(); //// String vrpType = "VFM"; // String vrpType = VRPHE; @@ -159,7 +159,7 @@ package jsprit.instance.reader; // // String problem = "100_" + pblm_abbr + "_LuiShen"; // String problemFile = pblm_abbr + ".txt"; -// Taillard luiShen = new Taillard("/Users/stefan/Documents/Schroeder/Dissertation/vrpInstances/cvrptw_solomon/nOfCust100/"+problemFile, +// Taillard luiShen = new Taillard("/Users/stefan/Documents/Schroeder/Dissertation/vrpInstances/cvrptw_solomon/nOfCust100/"+problemFile, // problem, "/Users/stefan/Documents/Schroeder/Dissertation/vrpInstances/vrphe_taillard/"+costScen+".txt", costScen, vrpType); // luiShen.setResultWriter(resultWriter); // luiShen.run(executor); @@ -176,7 +176,7 @@ package jsprit.instance.reader; // e.printStackTrace(); // } // } -// +// // private static String getName(int i) { // if(i<10){ // return "0" + i; @@ -188,27 +188,27 @@ package jsprit.instance.reader; // // private void setResultWriter(ResultWriter resultWriter) { // this.resultWriter = resultWriter; -// +// // } // // public void run(ExecutorService executor){ -// +// // final MyLocations myLocations = new MyLocations(); // Collection jobs = new ArrayList(); // final Map jobMap = readLocationsAndJobs(myLocations,jobs); -// +// // VehicleRoutingCosts costs = new VehicleRoutingCosts() { -// +// // @Override // public double getBackwardTransportTime(String fromId, String toId, double arrivalTime, Driver driver, Vehicle vehicle) { // return getTransportTime(fromId, toId, arrivalTime, null, null); // } -// +// // @Override // public double getBackwardTransportCost(String fromId, String toId, double arrivalTime, Driver driver, Vehicle vehicle) { // return getTransportCost(fromId, toId, arrivalTime, null, null); // } -// +// // @Override // public double getTransportCost(String fromId, String toId, double departureTime, Driver driver, Vehicle vehicle) { // double variableCost; @@ -220,59 +220,59 @@ package jsprit.instance.reader; // } // return variableCost*EuclideanDistanceCalculator.calculateDistance(myLocations.getCoord(fromId), myLocations.getCoord(toId)); // } -// +// // @Override // public double getTransportTime(String fromId, String toId, double departureTime, Driver driver, Vehicle vehicle) { // return getTransportCost(fromId, toId, departureTime, driver, vehicle); // } // }; -// +// // VrpBuilder vrpBuilder = new VrpBuilder(costs); // for(Job j : jobs){ // vrpBuilder.addJob(j); // } // createVehicles(vrpBuilder); // VehicleRoutingProblem vrp = vrpBuilder.build(); -// +// // VehicleRoutingMetaAlgorithm metaAlgorithm = new VehicleRoutingMetaAlgorithm(vrp); // configure(metaAlgorithm,vrp,executor,myLocations); // metaAlgorithm.run(); -// +// // printSolutions(vrp); -// +// // VehicleRoutingProblemSolution bestSolution = new SelectBest().selectSolution(vrp); -// +// // resultWriter.addResult(instanceName+"_"+vehicleCostScenario , instanceName, RouteUtils.getNuOfActiveRoutes(bestSolution.getRoutes()), bestSolution.getCost()); // resultWriter.addSolution(bestSolution); -// -// +// +// // } -// +// // private void printSolutions(VehicleRoutingProblem vrp) { // for(VehicleRoutingProblemSolution s : vrp.getSolutions()){ // System.out.println("total: " + s.getCost()); // System.out.println("activeTours: " + RouteUtils.getNuOfActiveRoutes(s.getRoutes())); // System.out.println(""); // } -// +// // } // // private void configure(VehicleRoutingMetaAlgorithm metaAlgorithm, final VehicleRoutingProblem vrp, ExecutorService executor, MyLocations myLocations) { // VehicleRoute.VehicleRouteCostCalculator = new VehicleRouteCostCalculator() { -// +// // @Override // public double calculate(Tour tour, Vehicle vehicle, Driver driver) { //// return vehicle.getType().vehicleCostParams.fix + tour.getCost(); // return tour.getCost(); // } -// +// // }; -// +// //// final VehicleFleetManager vehicleFleetManager = new InfiniteVehicles(vrp.getVehicles()); // final VehicleFleetManager vehicleFleetManager = new VehicleFleetManagerImpl(vrp.getVehicles()); -// +// // final VehicleRouteCostFunctionFactory costFuncFac = getFac(); -// +// // AuxilliaryCostCalculator auxilliaryCostCalculator = new AuxilliaryCostCalculator(vrp.getCosts(), costFuncFac); // CalculatesActivityInsertion actInsertion = new CalculatesActivityInsertion(auxilliaryCostCalculator,0,5); //// CalculatesServiceInsertion standardServiceInsertion = new CalculatesServiceInsertion(actInsertion); @@ -280,82 +280,82 @@ package jsprit.instance.reader; // CalculatesServiceInsertionOnRouteLevel.MEMORYSIZE_FORPROMISING_INSERTIONPOSITIONS = 2; // CalculatesServiceInsertionConsideringFixCost withFixCost = new CalculatesServiceInsertionConsideringFixCost(standardServiceInsertion); // withFixCost.setWeightOfFixCost(0.0); -// +// // final JobInsertionCalculator vehicleTypeDepInsertionCost = new CalculatesVehTypeDepServiceInsertion(vehicleFleetManager, standardServiceInsertion); -// +// // final TourStateUpdater tourStateCalculator = new TourStateUpdater(vrp.getCosts(),costFuncFac); // tourStateCalculator.setTimeWindowUpdate(false); -// +// // RouteAgentFactory routeAgentFactory = new RouteAgentFactory(){ // // @Override // public RouteAlgorithm createAgent(VehicleRoute route) { // VehicleSwitchedListener switched = new VehicleSwitchedListener() { -// +// // @Override // public void vehicleSwitched(Vehicle oldVehicle, Vehicle newVehicle) { // vehicleFleetManager.unlock(oldVehicle); // vehicleFleetManager.lock(newVehicle); // } -// +// // }; // RouteAlgorithmImpl agent = new RouteAlgorithmImpl(vehicleTypeDepInsertionCost, tourStateCalculator); // agent.getListeners().add(switched); // return agent; // } -// +// // }; -// +// // ParRegretInsertion regretInsertion = new ParRegretInsertion(executor, routeAgentFactory); // regretInsertion.getListener().add(new ConfigureFixCostCalculator(vrp, withFixCost)); // regretInsertion.setJobDistance(new DepotDistance(myLocations, depotId)); // regretInsertion.scoreParam_of_timeWindowLegth = 0.5; // regretInsertion.scoreParam_of_distance = 0.2; // regretInsertion.setVehicleRouteFactory(new VehicleRouteFactoryImpl(depotId)); -// -// +// +// // RecreationBestInsertion bestInsertion = new RecreationBestInsertion(routeAgentFactory); // bestInsertion.getListener().add(new ConfigureFixCostCalculator(vrp, withFixCost)); // bestInsertion.setVehicleRouteFactory(new VehicleRouteFactoryImpl(depotId)); -// +// //// for(int i=0;i<3;i++){ // VehicleRoutingProblemSolution vrpSol = new CreateInitialSolution(bestInsertion).createInitialSolution(vrp); // vrp.getSolutions().add(vrpSol); //// } -// +// // // RadialAndRandomRemoveBestInsert smallNeighborHoodSearchModule = new RadialAndRandomRemoveBestInsert(vrp, vehicleFleetManager, routeAlgorithm); // smallNeighborHoodSearchModule.setCalcConsideringFix(withFixCost); // smallNeighborHoodSearchModule.setStateCalc(tourStateCalculator); // smallNeighborHoodSearchModule.setInsertionStrategy(bestInsertion); // smallNeighborHoodSearchModule.setAuxilliaryCostCalculator(auxilliaryCostCalculator); -// +// // SearchStrategy smallNeighborHoodSearch = new SearchStrategy(new SelectRandomly(), new AcceptNewRemoveWorst()); -// +// // smallNeighborHoodSearch.addModule(smallNeighborHoodSearchModule); // -// GendreauPostOpt postOpt = new GendreauPostOpt(vrp, routeAgentFactory, -// (RuinRadial) new RadialRuinFactory(0.2, new JobDistanceAvgCosts(vrp.getCosts()), routeAgentFactory).createStrategy(vrp), +// GendreauPostOpt postOpt = new GendreauPostOpt(vrp, routeAgentFactory, +// (RuinRadial) new RadialRuinFactory(0.2, new JobDistanceAvgCosts(vrp.getCosts()), routeAgentFactory).createStrategy(vrp), // bestInsertion); // postOpt.setFleetManager(vehicleFleetManager); // postOpt.setVehicleRouteFactory(new VehicleRouteFactoryImpl(depotId)); // postOpt.setMaxIterations(2000); // postOpt.setShareOfJobsToRuin(0.18); //// smallNeighborHoodSearch.addModule(postOpt); -// -// +// +// //// SearchStrategy strat2 = new SearchStrategy(new SelectBest(), new AcceptNewRemoveWorst()); -//// GendreauPostOpt postOpt2 = new GendreauPostOpt(vrp, routeAgentFactory, -//// (RuinRadial) new RadialRuinFactory(0.2, new JobDistanceAvgCosts(vrp.getCosts()), routeAgentFactory).createStrategy(vrp), +//// GendreauPostOpt postOpt2 = new GendreauPostOpt(vrp, routeAgentFactory, +//// (RuinRadial) new RadialRuinFactory(0.2, new JobDistanceAvgCosts(vrp.getCosts()), routeAgentFactory).createStrategy(vrp), //// bestInsertion); //// postOpt2.setFleetManager(vehicleFleetManager); //// postOpt2.setVehicleRouteFactory(new VehicleRouteFactoryImpl(depotId)); //// postOpt2.setMaxIterations(2000); //// postOpt2.setShareOfJobsToRuin(0.1); //// strat2.addModule(postOpt2); -// +// // SearchStrategyModule solutionVerifier = new SearchStrategyModule() { -// +// // @Override // public VehicleRoutingProblemSolution runAndGetSolution(VehicleRoutingProblemSolution vrpSolution) { // logger.info("verify solution"); @@ -364,27 +364,27 @@ package jsprit.instance.reader; // } // }; // smallNeighborHoodSearch.addModule(solutionVerifier); -// +// // SearchStrategyManager strategyManager = new SearchStrategyManager(); // strategyManager.addStrategy(smallNeighborHoodSearch, 1.0); //// strategyManager.addStrategy(strat2, 0.3); -// +// // metaAlgorithm.setSearchStrategyManager(strategyManager); // metaAlgorithm.setMaxIterations(20); // VehicleRoutingProblem.SOLUTION_MEMORY = 4; -// -// +// +// // } -// +// // private VehicleRouteCostFunctionFactory getFac() { // VehicleRouteCostFunctionFactory fac = new VehicleRouteCostFunctionFactory() { -// +// // @Override // public VehicleRouteCostFunction createCostFunction(Vehicle vehicle, Driver driver) { // return new VehicleRouteCostFunction(){ // // double cost = 0.0; -// +// // @Override // public void handleActivity(TourActivity tourAct, double startTime, double endTime) { // if(startTime > tourAct.getLatestOperationStartTime()){ @@ -395,7 +395,7 @@ package jsprit.instance.reader; // @Override // public void handleLeg(TourActivity fromAct, TourActivity toAct, double depTime, double tpCost) { // cost += tpCost; -// +// // } // // @Override @@ -405,15 +405,15 @@ package jsprit.instance.reader; // // @Override // public void finish() { -// -// +// +// // } // // @Override // public void reset() { -// +// // } -// +// // }; // } // }; @@ -477,7 +477,7 @@ package jsprit.instance.reader; // int vehicleCap = Integer.parseInt(tokens[1]); // continue; // } -// +// // if(counter > 9){ // Coordinate coord = makeCoord(tokens[1],tokens[2]); // double depotStart = 0.0; @@ -492,18 +492,18 @@ package jsprit.instance.reader; // depotStart = start; // depotEnd = end; // depotId = tokens[0]; -// +// // } // else{ // Service service = VrpUtils.createService("" + counter, customerId, demand, 0.0, 0.0, Double.MAX_VALUE); -//// Shipment shipment = VrpUtils.createShipment("" + counter, depotId, customerId, demand, +//// Shipment shipment = VrpUtils.createShipment("" + counter, depotId, customerId, demand, //// VrpUtils.createTimeWindow(depotStart, depotEnd), VrpUtils.createTimeWindow(start, end)); //// shipment.setDeliveryServiceTime(serviceTime); // jobs.add(service); // jobMap.put(customerId, service); //// jobs.add(shipment); //// j -//// Shipment shipment = VrpUtils.createShipment("" + counter, depotId, customerId, demand, +//// Shipment shipment = VrpUtils.createShipment("" + counter, depotId, customerId, demand, //// VrpUtils.createTimeWindow(depotStart, depotEnd), VrpUtils.createTimeWindow(start, end)); //// shipment.setDeliveryServiceTime(serviceTime); //// jobs.add(shipment); @@ -520,7 +520,7 @@ package jsprit.instance.reader; // } // return jobMap; // } -// +// // private Coordinate makeCoord(String xString, String yString) { // double x = Double.parseDouble(xString); // double y = Double.parseDouble(yString); diff --git a/jsprit-instances/src/main/java/jsprit/instance/reader/VrphGoldenReader.java b/jsprit-instances/src/main/java/jsprit/instance/reader/VrphGoldenReader.java index 95a4714b..707de375 100644 --- a/jsprit-instances/src/main/java/jsprit/instance/reader/VrphGoldenReader.java +++ b/jsprit-instances/src/main/java/jsprit/instance/reader/VrphGoldenReader.java @@ -30,158 +30,144 @@ import jsprit.core.util.Coordinate; import java.io.*; /** - * Reads modified files from Taillard's website - * http://mistic.heig-vd.ch/taillard/problemes.dir/vrp.dir/vrp.html. You can find the modified version here: + * Reads modified files from Taillard's website + * http://mistic.heig-vd.ch/taillard/problemes.dir/vrp.dir/vrp.html. You can find the modified version here: * jsprit-instances/instances/vrph. - * + *

*

See {@link VrphType} what kind of problems can be generated - * - * @author schroeder * + * @author schroeder */ public class VrphGoldenReader { - - /** - * - * FSMD - Fleet Size and Mix with Dependent costs - *

FSMF - Fleet Size and Mix with Fixed costs - *

FSMFD - Fleet Size and Mix with Fixed and Dependent costs - *

HVRPD - Heterogeneous Vehicle Routing Problem with Dependent costs and finite (limited) fleet - *

HVRPFD - Heterogeneous Vehicle Routing Problem with Fixed and Dependent costs and finite (limited) fleet - * - * @author schroeder - * - */ - public enum VrphType { - FSMD, - HVRPD, - FSMF, - FSMFD, - HVRPFD - } - - private final VehicleRoutingProblem.Builder vrpBuilder; - - private final VrphType vrphType; - - public VrphGoldenReader(Builder vrpBuilder, VrphType vrphType) { - super(); - this.vrpBuilder = vrpBuilder; - this.vrphType = vrphType; - } - public void read(String filename){ - BufferedReader reader = getReader(filename); - String line; - boolean firstline = true; - Coordinate depotCoord = null; - int customerCount=0; - Integer nuOfCustomer = 0; - while((line=readLine(reader))!=null){ - String trimedLine = line.trim(); - if(trimedLine.startsWith("//")) continue; - String[] tokens = trimedLine.split("\\s+"); - if(firstline){ - nuOfCustomer=Integer.parseInt(tokens[0]); - customerCount=0; - firstline=false; - } - else if(customerCount<=nuOfCustomer) { - if(customerCount == 0){ - depotCoord = Coordinate.newInstance(Double.parseDouble(tokens[1]), Double.parseDouble(tokens[2])); - } - else{ - Service.Builder serviceBuilder = Service.Builder.newInstance(tokens[0]).addSizeDimension(0, Integer.parseInt(tokens[3])); - serviceBuilder.setLocation(Location.newInstance(Double.parseDouble(tokens[1]), Double.parseDouble(tokens[2]))); - vrpBuilder.addJob(serviceBuilder.build()); - } - customerCount++; - } - else if(trimedLine.startsWith("v")){ - VehicleTypeImpl.Builder typeBuilder = VehicleTypeImpl.Builder.newInstance("type_"+tokens[1]).addCapacityDimension(0, Integer.parseInt(tokens[2])); - int nuOfVehicles = 1; - if(vrphType.equals(VrphType.FSMF)){ - typeBuilder.setFixedCost(Double.parseDouble(tokens[3])); - } - else if(vrphType.equals(VrphType.FSMFD)){ - typeBuilder.setFixedCost(Double.parseDouble(tokens[3])); - if(tokens.length > 4){ - typeBuilder.setCostPerDistance(Double.parseDouble(tokens[4])); - } - else throw new IllegalStateException("option " + vrphType + " cannot be applied with this instance"); - } - else if(vrphType.equals(VrphType.FSMD)){ - if(tokens.length > 4){ - typeBuilder.setCostPerDistance(Double.parseDouble(tokens[4])); - } - else throw new IllegalStateException("option " + vrphType + " cannot be applied with this instance"); - } - else if(vrphType.equals(VrphType.HVRPD)){ - if(tokens.length > 4){ - typeBuilder.setCostPerDistance(Double.parseDouble(tokens[4])); - nuOfVehicles = Integer.parseInt(tokens[5]); - vrpBuilder.setFleetSize(FleetSize.FINITE); - } - else throw new IllegalStateException("option " + vrphType + " cannot be applied with this instance"); - } - else if (vrphType.equals(VrphType.HVRPFD)){ - if(tokens.length > 4){ - typeBuilder.setFixedCost(Double.parseDouble(tokens[3])); - typeBuilder.setCostPerDistance(Double.parseDouble(tokens[4])); - nuOfVehicles = Integer.parseInt(tokens[5]); - vrpBuilder.setFleetSize(FleetSize.FINITE); - } - else throw new IllegalStateException("option " + vrphType + " cannot be applied with this instance"); - } - for(int i=0;iFSMD - Fleet Size and Mix with Dependent costs + *

FSMF - Fleet Size and Mix with Fixed costs + *

FSMFD - Fleet Size and Mix with Fixed and Dependent costs + *

HVRPD - Heterogeneous Vehicle Routing Problem with Dependent costs and finite (limited) fleet + *

HVRPFD - Heterogeneous Vehicle Routing Problem with Fixed and Dependent costs and finite (limited) fleet + * + * @author schroeder + */ + public enum VrphType { + FSMD, + HVRPD, + FSMF, + FSMFD, + HVRPFD + } - private void closeReader(BufferedReader reader) { - try { - reader.close(); - } catch (IOException e) { - e.printStackTrace(); - System.exit(1); - } - } + private final VehicleRoutingProblem.Builder vrpBuilder; - private String readLine(BufferedReader reader) { - String readLine = null; - try { - readLine = reader.readLine(); - } catch (IOException e) { - e.printStackTrace(); - System.exit(1); - } - return readLine; - } + private final VrphType vrphType; - private BufferedReader getReader(String filename) { - BufferedReader bufferedReader = null; - try { - bufferedReader = new BufferedReader(new FileReader(new File(filename))); - return bufferedReader; - } catch (FileNotFoundException e) { - e.printStackTrace(); - System.exit(1); - } - return bufferedReader; - } - - public static void main(String[] args) { - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - VrphGoldenReader goldenReader = new VrphGoldenReader(vrpBuilder, VrphType.FSMD); - goldenReader.read("instances/vrph/orig/cn_13mix.txt"); - VehicleRoutingProblem vrp = vrpBuilder.build(); - new VrpXMLWriter(vrp).write("instances/vrph/cn_13mix_VRPH_INFINITE.xml"); - } + public VrphGoldenReader(Builder vrpBuilder, VrphType vrphType) { + super(); + this.vrpBuilder = vrpBuilder; + this.vrphType = vrphType; + } + + public void read(String filename) { + BufferedReader reader = getReader(filename); + String line; + boolean firstline = true; + Coordinate depotCoord = null; + int customerCount = 0; + Integer nuOfCustomer = 0; + while ((line = readLine(reader)) != null) { + String trimedLine = line.trim(); + if (trimedLine.startsWith("//")) continue; + String[] tokens = trimedLine.split("\\s+"); + if (firstline) { + nuOfCustomer = Integer.parseInt(tokens[0]); + customerCount = 0; + firstline = false; + } else if (customerCount <= nuOfCustomer) { + if (customerCount == 0) { + depotCoord = Coordinate.newInstance(Double.parseDouble(tokens[1]), Double.parseDouble(tokens[2])); + } else { + Service.Builder serviceBuilder = Service.Builder.newInstance(tokens[0]).addSizeDimension(0, Integer.parseInt(tokens[3])); + serviceBuilder.setLocation(Location.newInstance(Double.parseDouble(tokens[1]), Double.parseDouble(tokens[2]))); + vrpBuilder.addJob(serviceBuilder.build()); + } + customerCount++; + } else if (trimedLine.startsWith("v")) { + VehicleTypeImpl.Builder typeBuilder = VehicleTypeImpl.Builder.newInstance("type_" + tokens[1]).addCapacityDimension(0, Integer.parseInt(tokens[2])); + int nuOfVehicles = 1; + if (vrphType.equals(VrphType.FSMF)) { + typeBuilder.setFixedCost(Double.parseDouble(tokens[3])); + } else if (vrphType.equals(VrphType.FSMFD)) { + typeBuilder.setFixedCost(Double.parseDouble(tokens[3])); + if (tokens.length > 4) { + typeBuilder.setCostPerDistance(Double.parseDouble(tokens[4])); + } else + throw new IllegalStateException("option " + vrphType + " cannot be applied with this instance"); + } else if (vrphType.equals(VrphType.FSMD)) { + if (tokens.length > 4) { + typeBuilder.setCostPerDistance(Double.parseDouble(tokens[4])); + } else + throw new IllegalStateException("option " + vrphType + " cannot be applied with this instance"); + } else if (vrphType.equals(VrphType.HVRPD)) { + if (tokens.length > 4) { + typeBuilder.setCostPerDistance(Double.parseDouble(tokens[4])); + nuOfVehicles = Integer.parseInt(tokens[5]); + vrpBuilder.setFleetSize(FleetSize.FINITE); + } else + throw new IllegalStateException("option " + vrphType + " cannot be applied with this instance"); + } else if (vrphType.equals(VrphType.HVRPFD)) { + if (tokens.length > 4) { + typeBuilder.setFixedCost(Double.parseDouble(tokens[3])); + typeBuilder.setCostPerDistance(Double.parseDouble(tokens[4])); + nuOfVehicles = Integer.parseInt(tokens[5]); + vrpBuilder.setFleetSize(FleetSize.FINITE); + } else + throw new IllegalStateException("option " + vrphType + " cannot be applied with this instance"); + } + for (int i = 0; i < nuOfVehicles; i++) { + VehicleTypeImpl type = typeBuilder.build(); + VehicleImpl vehicle = VehicleImpl.Builder.newInstance("vehicle_" + tokens[1] + "_" + i) + .setStartLocation(Location.newInstance(depotCoord.getX(), depotCoord.getY())).setType(type).build(); + vrpBuilder.addVehicle(vehicle); + } + } + } + closeReader(reader); + } + + private void closeReader(BufferedReader reader) { + try { + reader.close(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + private String readLine(BufferedReader reader) { + String readLine = null; + try { + readLine = reader.readLine(); + } catch (IOException e) { + throw new RuntimeException(e); + } + return readLine; + } + + private BufferedReader getReader(String filename) { + BufferedReader bufferedReader = null; + try { + bufferedReader = new BufferedReader(new FileReader(new File(filename))); + return bufferedReader; + } catch (FileNotFoundException e) { + throw new RuntimeException(e); + } + } + + public static void main(String[] args) { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + VrphGoldenReader goldenReader = new VrphGoldenReader(vrpBuilder, VrphType.FSMD); + goldenReader.read("instances/vrph/orig/cn_13mix.txt"); + VehicleRoutingProblem vrp = vrpBuilder.build(); + new VrpXMLWriter(vrp).write("instances/vrph/cn_13mix_VRPH_INFINITE.xml"); + } } diff --git a/jsprit-instances/src/main/java/jsprit/instance/util/Instances.java b/jsprit-instances/src/main/java/jsprit/instance/util/Instances.java index e227a041..f29d8dd6 100644 --- a/jsprit-instances/src/main/java/jsprit/instance/util/Instances.java +++ b/jsprit-instances/src/main/java/jsprit/instance/util/Instances.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.instance.util; @@ -31,216 +31,219 @@ import java.util.List; public class Instances { - /** - * Returns a collection of {@link BenchmarkInstance} which are Cordeau's p instances. - *

Note that this assumes that within the folder 'inputFolder' 23 p-instances are located with their original name, i.e. p01,p02,...,p23. - *

It also assumes that solution files are also located in inputFolder ending with .res - * - * @param inputFolder where cordeau's p instances are located. It must end without '/' such as instances/cordeau. - * @return a collection of {@link BenchmarkInstance} - */ - public static Collection getAllCordeauP(String inputFolder){ - Collection instances = new ArrayList(); - for(int i=0;i<23;i++){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - String file = inputFolder + "/p"+ getInstanceNu(i+1); - new CordeauReader(builder).read(file); - VehicleRoutingProblem p = builder.build(); - instances.add(new BenchmarkInstance("p" + getInstanceNu(i+1), p, getBestKnown(file), null)); - } - return instances; - } + /** + * Returns a collection of {@link BenchmarkInstance} which are Cordeau's p instances. + *

Note that this assumes that within the folder 'inputFolder' 23 p-instances are located with their original name, i.e. p01,p02,...,p23. + *

It also assumes that solution files are also located in inputFolder ending with .res + * + * @param inputFolder where cordeau's p instances are located. It must end without '/' such as instances/cordeau. + * @return a collection of {@link BenchmarkInstance} + */ + public static Collection getAllCordeauP(String inputFolder) { + Collection instances = new ArrayList(); + for (int i = 0; i < 23; i++) { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + String file = inputFolder + "/p" + getInstanceNu(i + 1); + new CordeauReader(builder).read(file); + VehicleRoutingProblem p = builder.build(); + instances.add(new BenchmarkInstance("p" + getInstanceNu(i + 1), p, getBestKnown(file), null)); + } + return instances; + } - - private static double getBestKnown(String file) { - try { - BufferedReader reader = new BufferedReader(new FileReader(new File(file+".res"))); - String first = reader.readLine(); - Double result = Double.valueOf(first); - reader.close(); - return result; - } catch (FileNotFoundException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - return 0; - } - - private static String getInstanceNu(int i) { - if(i<10) return "0"+i; - return ""+i; - } + private static double getBestKnown(String file) { + try { + BufferedReader reader = new BufferedReader(new FileReader(new File(file + ".res"))); + String first = reader.readLine(); + Double result = Double.valueOf(first); + reader.close(); + return result; + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + return 0; + } - /** - * Returns a collection of {@link BenchmarkInstance} which are Cordeau's pr instances. - *

Note that this assumes that within the folder 'inputFolder' 10 p-instances are located with their original name, i.e. pr01,pr02,...,pr10. - *

It also assumes that solution files are also located in inputFolder ending with .res - * @param inputFolder - * @param inputFolder where cordeau's pr instances are located. It must end without '/' such as instances/cordeau. - * - * @return a collection of {@link BenchmarkInstance} - */ - public static Collection getAllCordeauPR(String inputFolder){ - Collection instances = new ArrayList(); - for(int i=0;i<10;i++){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - String file = inputFolder + "/pr"+ getInstanceNu(i+1); - new CordeauReader(builder).read(file); - VehicleRoutingProblem p = builder.build(); - instances.add(new BenchmarkInstance("pr" + getInstanceNu(i+1), p, getBestKnown(file),null)); - } - return instances; - } - - /** - * Returns a collection of {@link BenchmarkInstance} which are Christofides vrpnc instances. - *

Note that this assumes that within the folder 'inputFolder' 14 vrpnc-instances are located with their original name, i.e. vrpnc1,vrpnc2,...,vrpnc14. - * - * @param inputFolder where christofides vrpnc instances are located. It must end without '/' such as instances/christofides. - * - * @return a collection of {@link BenchmarkInstance} - */ - public static Collection getAllChristofides(String inputFolder){ - List bestKnown = Arrays.asList(524.61,835.26,826.14,1028.42,1291.29,555.43,909.68,865.49,1162.55,1395.85,1042.11,819.56,1541.14,866.37); - Collection instances = new ArrayList(); - for(int i=0;i<14;i++){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - String file = inputFolder + "/vrpnc"+ (i+1) + ".txt"; - new ChristofidesReader(builder).read(file); - VehicleRoutingProblem p = builder.build(); - instances.add(new BenchmarkInstance("vrpnc" + getInstanceNu(i+1), p, bestKnown.get(i).doubleValue(), null)); - } - return instances; - } - - /** - * Returns a collection of {@link BenchmarkInstance} which are Solomon instances. - *

Note that this assumes that within the folder 'inputFolder' 9 C1-instances are located with their original name, i.e. C101.txt,C102.txt,...,C109.txt. - *

Note that unlike the original problems, a fixed-cost value of 1000 is set for each employed vehicle. - * @param inputFolder where solomon C1 instances are located. It must end without '/' such as instances/solomon. - * - * @return a collection of {@link BenchmarkInstance} - */ - public static Collection getAllSolomonC1(String inputFolder){ - List bestKnown = Arrays.asList(828.94,828.94,828.06,824.78,828.94,828.94,828.94,828.94,828.94); - List bestKnowVehicles = Arrays.asList(10.0,10.0,10.0,10.0,10.0,10.0,10.0,10.0,10.0); - Collection instances = new ArrayList(); - for(int i=0;i<9;i++){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - String file = inputFolder + "/C1"+ getInstanceNu(i+1) + ".txt"; - new SolomonReader(builder).read(file); - VehicleRoutingProblem p = builder.build(); - instances.add(new BenchmarkInstance("C1" + getInstanceNu(i+1), p, bestKnown.get(i).doubleValue(), bestKnowVehicles.get(i).doubleValue())); - } - return instances; - } - - /** - * Returns a collection of {@link BenchmarkInstance} which are Solomon instances. - *

Note that this assumes that within the folder 'inputFolder' 8 C2-instances are located with their original name, i.e. C201.txt,C202.txt,...,C208.txt. - *

Note that unlike the original problems, a fixed-cost value of 1000 is set for each employed vehicle. - * @param inputFolder where solomon C2 instances are located. It must end without '/' such as instances/solomon. - * @return a collection of {@link BenchmarkInstance} - */ - public static Collection getAllSolomonC2(String inputFolder){ - List bestKnown = Arrays.asList(591.56,591.56,591.17,590.60,588.88,588.49,588.29,588.32); - List bestKnowVehicles = Arrays.asList(3.0,3.0,3.0,3.0,3.0,3.0,3.0,3.0); - Collection instances = new ArrayList(); - for(int i=0;i<8;i++){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - String file = inputFolder + "/C2"+ getInstanceNu(i+1) + ".txt"; - new SolomonReader(builder).read(file); - VehicleRoutingProblem p = builder.build(); - instances.add(new BenchmarkInstance("C2" + getInstanceNu(i+1), p, bestKnown.get(i).doubleValue(), bestKnowVehicles.get(i).doubleValue())); - } - return instances; - } - - /** - * Returns a collection of {@link BenchmarkInstance} which are Solomon instances. - *

Note that this assumes that within the folder 'inputFolder' 12 R1-instances are located with their original name, i.e. R101.txt,R102.txt,...,R112.txt. - *

Note that unlike the original problems, a fixed-cost value of 1000 is set for each employed vehicle. - * @param inputFolder where solomon R1 instances are located. It must end without '/' such as instances/solomon. - * @return a collection of {@link BenchmarkInstance} - */ - public static Collection getAllSolomonR1(String inputFolder){ - List bestKnown = Arrays.asList(1650.80,1486.12,1292.68,1007.31,1377.11,1252.03,1104.66,960.88,1194.73,1118.84,1096.72,982.14); - List bestKnowVehicles = Arrays.asList(19.0,17.0,13.0,9.0,14.0,12.0,10.0,9.0,11.0,10.0,10.0,9.0); - Collection instances = new ArrayList(); - for(int i=0;i<12;i++){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - String file = inputFolder + "/R1"+ getInstanceNu(i+1) + ".txt"; - new SolomonReader(builder).read(file); - VehicleRoutingProblem p = builder.build(); - instances.add(new BenchmarkInstance("R1" + getInstanceNu(i+1), p, bestKnown.get(i).doubleValue(), bestKnowVehicles.get(i).doubleValue())); - } - return instances; - } - - /** - * Returns a collection of {@link BenchmarkInstance} which are Solomon instances. - *

Note that this assumes that within the folder 'inputFolder' 11 R1-instances are located with their original name, i.e. R201.txt,R202.txt,...,R111.txt. - *

Note that unlike the original problems, a fixed-cost value of 1000 is set for each employed vehicle. - * @param inputFolder - * @param inputFolder where solomon R2 instances are located. It must end without '/' such as instances/solomon. - * @return a collection of {@link BenchmarkInstance} - */ - public static Collection getAllSolomonR2(String inputFolder){ - List bestKnown = Arrays.asList(1252.37,1191.70,939.50,825.52,994.42,906.14,890.61,726.82,909.16,939.37,885.71); - List bestKnowVehicles = Arrays.asList(4.0,3.0,3.0,2.0,3.0,3.0,2.0,2.0,3.0,3.0,2.0); - Collection instances = new ArrayList(); - for(int i=0;i<11;i++){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - String file = inputFolder + "/R2"+ getInstanceNu(i+1) + ".txt"; - new SolomonReader(builder).read(file); - VehicleRoutingProblem p = builder.build(); - instances.add(new BenchmarkInstance("R2" + getInstanceNu(i+1), p, bestKnown.get(i).doubleValue(), bestKnowVehicles.get(i).doubleValue())); - } - return instances; - } - - /** - * Returns a collection of {@link BenchmarkInstance} which are Solomon instances. - *

Note that this assumes that within the folder 'inputFolder' 8 RC1-instances are located with their original name, i.e. RC101.txt,RC102.txt,...,RC108.txt. - *

Note that unlike the original problems, a fixed-cost value of 1000 is set for each employed vehicle. - * @param inputFolder where solomon RC1 instances are located. It must end without '/' such as instances/solomon. - * @return a collection of {@link BenchmarkInstance} - */ - public static Collection getAllSolomonRC1(String inputFolder){ - List bestKnown = Arrays.asList(1696.94,1554.75,1261.67,1135.48,1629.44,1424.73,1230.48,1139.82); - List bestKnowVehicles = Arrays.asList(14.0,12.0,11.0,10.0,13.0,11.0,11.0,10.0); - Collection instances = new ArrayList(); - for(int i=0;i<8;i++){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - String file = inputFolder + "/RC1"+ getInstanceNu(i+1) + ".txt"; - new SolomonReader(builder).read(file); - VehicleRoutingProblem p = builder.build(); - instances.add(new BenchmarkInstance("RC1" + getInstanceNu(i+1), p, bestKnown.get(i).doubleValue(), bestKnowVehicles.get(i).doubleValue())); - } - return instances; - } - - /** - * Returns a collection of {@link BenchmarkInstance} which are Solomon instances. - *

Note that this assumes that within the folder 'inputFolder' 8 RC2-instances are located with their original name, i.e. RC201.txt,RC202.txt,...,RC208.txt. - *

Note that unlike the original problems, a fixed-cost value of 1000 is set for each employed vehicle. - * @param inputFolder - * @param inputFolder where solomon RC2 instances are located. It must end without '/' such as instances/solomon. - * @return a collection of {@link BenchmarkInstance} - */ - public static Collection getAllSolomonRC2(String inputFolder){ - List bestKnown = Arrays.asList(1406.94,1365.65,1049.62,798.46,1297.65,1146.32,1061.14,828.14); - List bestKnowVehicles = Arrays.asList(4.0,3.0,3.0,3.0,4.0,3.0,3.0,3.0); - Collection instances = new ArrayList(); - for(int i=0;i<8;i++){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - String file = inputFolder + "/RC2"+ getInstanceNu(i+1) + ".txt"; - new SolomonReader(builder).read(file); - VehicleRoutingProblem p = builder.build(); - instances.add(new BenchmarkInstance("RC2" + getInstanceNu(i+1), p, bestKnown.get(i).doubleValue(), bestKnowVehicles.get(i).doubleValue())); - } - return instances; - } + private static String getInstanceNu(int i) { + if (i < 10) return "0" + i; + return "" + i; + } + + /** + * Returns a collection of {@link BenchmarkInstance} which are Cordeau's pr instances. + *

Note that this assumes that within the folder 'inputFolder' 10 p-instances are located with their original name, i.e. pr01,pr02,...,pr10. + *

It also assumes that solution files are also located in inputFolder ending with .res + * + * @param inputFolder + * @param inputFolder where cordeau's pr instances are located. It must end without '/' such as instances/cordeau. + * @return a collection of {@link BenchmarkInstance} + */ + public static Collection getAllCordeauPR(String inputFolder) { + Collection instances = new ArrayList(); + for (int i = 0; i < 10; i++) { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + String file = inputFolder + "/pr" + getInstanceNu(i + 1); + new CordeauReader(builder).read(file); + VehicleRoutingProblem p = builder.build(); + instances.add(new BenchmarkInstance("pr" + getInstanceNu(i + 1), p, getBestKnown(file), null)); + } + return instances; + } + + /** + * Returns a collection of {@link BenchmarkInstance} which are Christofides vrpnc instances. + *

Note that this assumes that within the folder 'inputFolder' 14 vrpnc-instances are located with their original name, i.e. vrpnc1,vrpnc2,...,vrpnc14. + * + * @param inputFolder where christofides vrpnc instances are located. It must end without '/' such as instances/christofides. + * @return a collection of {@link BenchmarkInstance} + */ + public static Collection getAllChristofides(String inputFolder) { + List bestKnown = Arrays.asList(524.61, 835.26, 826.14, 1028.42, 1291.29, 555.43, 909.68, 865.49, 1162.55, 1395.85, 1042.11, 819.56, 1541.14, 866.37); + Collection instances = new ArrayList(); + for (int i = 0; i < 14; i++) { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + String file = inputFolder + "/vrpnc" + (i + 1) + ".txt"; + new ChristofidesReader(builder).read(file); + VehicleRoutingProblem p = builder.build(); + instances.add(new BenchmarkInstance("vrpnc" + getInstanceNu(i + 1), p, bestKnown.get(i).doubleValue(), null)); + } + return instances; + } + + /** + * Returns a collection of {@link BenchmarkInstance} which are Solomon instances. + *

Note that this assumes that within the folder 'inputFolder' 9 C1-instances are located with their original name, i.e. C101.txt,C102.txt,...,C109.txt. + *

Note that unlike the original problems, a fixed-cost value of 1000 is set for each employed vehicle. + * + * @param inputFolder where solomon C1 instances are located. It must end without '/' such as instances/solomon. + * @return a collection of {@link BenchmarkInstance} + */ + public static Collection getAllSolomonC1(String inputFolder) { + List bestKnown = Arrays.asList(828.94, 828.94, 828.06, 824.78, 828.94, 828.94, 828.94, 828.94, 828.94); + List bestKnowVehicles = Arrays.asList(10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0); + Collection instances = new ArrayList(); + for (int i = 0; i < 9; i++) { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + String file = inputFolder + "/C1" + getInstanceNu(i + 1) + ".txt"; + new SolomonReader(builder).read(file); + VehicleRoutingProblem p = builder.build(); + instances.add(new BenchmarkInstance("C1" + getInstanceNu(i + 1), p, bestKnown.get(i).doubleValue(), bestKnowVehicles.get(i).doubleValue())); + } + return instances; + } + + /** + * Returns a collection of {@link BenchmarkInstance} which are Solomon instances. + *

Note that this assumes that within the folder 'inputFolder' 8 C2-instances are located with their original name, i.e. C201.txt,C202.txt,...,C208.txt. + *

Note that unlike the original problems, a fixed-cost value of 1000 is set for each employed vehicle. + * + * @param inputFolder where solomon C2 instances are located. It must end without '/' such as instances/solomon. + * @return a collection of {@link BenchmarkInstance} + */ + public static Collection getAllSolomonC2(String inputFolder) { + List bestKnown = Arrays.asList(591.56, 591.56, 591.17, 590.60, 588.88, 588.49, 588.29, 588.32); + List bestKnowVehicles = Arrays.asList(3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0, 3.0); + Collection instances = new ArrayList(); + for (int i = 0; i < 8; i++) { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + String file = inputFolder + "/C2" + getInstanceNu(i + 1) + ".txt"; + new SolomonReader(builder).read(file); + VehicleRoutingProblem p = builder.build(); + instances.add(new BenchmarkInstance("C2" + getInstanceNu(i + 1), p, bestKnown.get(i).doubleValue(), bestKnowVehicles.get(i).doubleValue())); + } + return instances; + } + + /** + * Returns a collection of {@link BenchmarkInstance} which are Solomon instances. + *

Note that this assumes that within the folder 'inputFolder' 12 R1-instances are located with their original name, i.e. R101.txt,R102.txt,...,R112.txt. + *

Note that unlike the original problems, a fixed-cost value of 1000 is set for each employed vehicle. + * + * @param inputFolder where solomon R1 instances are located. It must end without '/' such as instances/solomon. + * @return a collection of {@link BenchmarkInstance} + */ + public static Collection getAllSolomonR1(String inputFolder) { + List bestKnown = Arrays.asList(1650.80, 1486.12, 1292.68, 1007.31, 1377.11, 1252.03, 1104.66, 960.88, 1194.73, 1118.84, 1096.72, 982.14); + List bestKnowVehicles = Arrays.asList(19.0, 17.0, 13.0, 9.0, 14.0, 12.0, 10.0, 9.0, 11.0, 10.0, 10.0, 9.0); + Collection instances = new ArrayList(); + for (int i = 0; i < 12; i++) { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + String file = inputFolder + "/R1" + getInstanceNu(i + 1) + ".txt"; + new SolomonReader(builder).read(file); + VehicleRoutingProblem p = builder.build(); + instances.add(new BenchmarkInstance("R1" + getInstanceNu(i + 1), p, bestKnown.get(i).doubleValue(), bestKnowVehicles.get(i).doubleValue())); + } + return instances; + } + + /** + * Returns a collection of {@link BenchmarkInstance} which are Solomon instances. + *

Note that this assumes that within the folder 'inputFolder' 11 R1-instances are located with their original name, i.e. R201.txt,R202.txt,...,R111.txt. + *

Note that unlike the original problems, a fixed-cost value of 1000 is set for each employed vehicle. + * + * @param inputFolder + * @param inputFolder where solomon R2 instances are located. It must end without '/' such as instances/solomon. + * @return a collection of {@link BenchmarkInstance} + */ + public static Collection getAllSolomonR2(String inputFolder) { + List bestKnown = Arrays.asList(1252.37, 1191.70, 939.50, 825.52, 994.42, 906.14, 890.61, 726.82, 909.16, 939.37, 885.71); + List bestKnowVehicles = Arrays.asList(4.0, 3.0, 3.0, 2.0, 3.0, 3.0, 2.0, 2.0, 3.0, 3.0, 2.0); + Collection instances = new ArrayList(); + for (int i = 0; i < 11; i++) { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + String file = inputFolder + "/R2" + getInstanceNu(i + 1) + ".txt"; + new SolomonReader(builder).read(file); + VehicleRoutingProblem p = builder.build(); + instances.add(new BenchmarkInstance("R2" + getInstanceNu(i + 1), p, bestKnown.get(i).doubleValue(), bestKnowVehicles.get(i).doubleValue())); + } + return instances; + } + + /** + * Returns a collection of {@link BenchmarkInstance} which are Solomon instances. + *

Note that this assumes that within the folder 'inputFolder' 8 RC1-instances are located with their original name, i.e. RC101.txt,RC102.txt,...,RC108.txt. + *

Note that unlike the original problems, a fixed-cost value of 1000 is set for each employed vehicle. + * + * @param inputFolder where solomon RC1 instances are located. It must end without '/' such as instances/solomon. + * @return a collection of {@link BenchmarkInstance} + */ + public static Collection getAllSolomonRC1(String inputFolder) { + List bestKnown = Arrays.asList(1696.94, 1554.75, 1261.67, 1135.48, 1629.44, 1424.73, 1230.48, 1139.82); + List bestKnowVehicles = Arrays.asList(14.0, 12.0, 11.0, 10.0, 13.0, 11.0, 11.0, 10.0); + Collection instances = new ArrayList(); + for (int i = 0; i < 8; i++) { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + String file = inputFolder + "/RC1" + getInstanceNu(i + 1) + ".txt"; + new SolomonReader(builder).read(file); + VehicleRoutingProblem p = builder.build(); + instances.add(new BenchmarkInstance("RC1" + getInstanceNu(i + 1), p, bestKnown.get(i).doubleValue(), bestKnowVehicles.get(i).doubleValue())); + } + return instances; + } + + /** + * Returns a collection of {@link BenchmarkInstance} which are Solomon instances. + *

Note that this assumes that within the folder 'inputFolder' 8 RC2-instances are located with their original name, i.e. RC201.txt,RC202.txt,...,RC208.txt. + *

Note that unlike the original problems, a fixed-cost value of 1000 is set for each employed vehicle. + * + * @param inputFolder + * @param inputFolder where solomon RC2 instances are located. It must end without '/' such as instances/solomon. + * @return a collection of {@link BenchmarkInstance} + */ + public static Collection getAllSolomonRC2(String inputFolder) { + List bestKnown = Arrays.asList(1406.94, 1365.65, 1049.62, 798.46, 1297.65, 1146.32, 1061.14, 828.14); + List bestKnowVehicles = Arrays.asList(4.0, 3.0, 3.0, 3.0, 4.0, 3.0, 3.0, 3.0); + Collection instances = new ArrayList(); + for (int i = 0; i < 8; i++) { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + String file = inputFolder + "/RC2" + getInstanceNu(i + 1) + ".txt"; + new SolomonReader(builder).read(file); + VehicleRoutingProblem p = builder.build(); + instances.add(new BenchmarkInstance("RC2" + getInstanceNu(i + 1), p, bestKnown.get(i).doubleValue(), bestKnowVehicles.get(i).doubleValue())); + } + return instances; + } } diff --git a/jsprit-instances/src/test/java/jsprit/instance/reader/ChristophidesReaderTest.java b/jsprit-instances/src/test/java/jsprit/instance/reader/ChristophidesReaderTest.java index c975b7a2..8333310b 100644 --- a/jsprit-instances/src/test/java/jsprit/instance/reader/ChristophidesReaderTest.java +++ b/jsprit-instances/src/test/java/jsprit/instance/reader/ChristophidesReaderTest.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.instance.reader; @@ -28,78 +28,76 @@ import static org.junit.Assert.assertEquals; public class ChristophidesReaderTest { - - @Test - public void whenReadingInstance_nuOfCustomersIsCorrect(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new ChristofidesReader(builder).read(getPath("vrpnc1.txt")); - VehicleRoutingProblem vrp = builder.build(); - assertEquals(50,vrp.getJobs().values().size()); - } - private String getPath(String string) { - URL resource = this.getClass().getClassLoader().getResource(string); - if(resource == null) throw new IllegalStateException("resource " + string + " does not exist"); - return resource.getPath(); - } - - @Test - public void whenReadingInstance_fleetSizeIsInfinite(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new ChristofidesReader(builder).read(getPath("vrpnc1.txt")); - VehicleRoutingProblem vrp = builder.build(); - assertEquals(FleetSize.INFINITE,vrp.getFleetSize()); - } - - @Test - public void whenReadingInstance_vehicleCapacitiesAreCorrect(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new ChristofidesReader(builder).read(getPath("vrpnc1.txt")); - VehicleRoutingProblem vrp = builder.build(); - for(Vehicle v : vrp.getVehicles()){ - assertEquals(160,v.getType().getCapacityDimensions().get(0)); - } - } - - @Test - public void whenReadingInstance_vehicleLocationsAreCorrect_and_correspondToDepotLocation(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new ChristofidesReader(builder).read(getPath("vrpnc1.txt")); - VehicleRoutingProblem vrp = builder.build(); - for(Vehicle v : vrp.getVehicles()){ - assertEquals(30.0,v.getStartLocation().getCoordinate().getX(),0.01); - assertEquals(40.0,v.getStartLocation().getCoordinate().getY(),0.01); - } - } - - @Test - public void whenReadingInstance_vehicleDurationsAreCorrect(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new ChristofidesReader(builder).read(getPath("vrpnc13.txt")); - VehicleRoutingProblem vrp = builder.build(); - for(Vehicle v : vrp.getVehicles()){ - assertEquals(0.0,v.getEarliestDeparture(),0.01); - assertEquals(720.0,v.getLatestArrival()-v.getEarliestDeparture(),0.01); - } - } - - @Test - public void whenReadingInstance_demandOfCustomerOneIsCorrect(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new ChristofidesReader(builder).read(getPath("vrpnc1.txt")); - VehicleRoutingProblem vrp = builder.build(); - assertEquals(7,vrp.getJobs().get("1").getSize().get(0)); - } - - @Test - public void whenReadingInstance_serviceDurationOfCustomerTwoIsCorrect(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new ChristofidesReader(builder).read(getPath("vrpnc13.txt")); - VehicleRoutingProblem vrp = builder.build(); - assertEquals(50.0,((Service)vrp.getJobs().get("2")).getServiceDuration(),0.1); - } - - - + @Test + public void whenReadingInstance_nuOfCustomersIsCorrect() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + new ChristofidesReader(builder).read(getPath("vrpnc1.txt")); + VehicleRoutingProblem vrp = builder.build(); + assertEquals(50, vrp.getJobs().values().size()); + } + + private String getPath(String string) { + URL resource = this.getClass().getClassLoader().getResource(string); + if (resource == null) throw new IllegalStateException("resource " + string + " does not exist"); + return resource.getPath(); + } + + @Test + public void whenReadingInstance_fleetSizeIsInfinite() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + new ChristofidesReader(builder).read(getPath("vrpnc1.txt")); + VehicleRoutingProblem vrp = builder.build(); + assertEquals(FleetSize.INFINITE, vrp.getFleetSize()); + } + + @Test + public void whenReadingInstance_vehicleCapacitiesAreCorrect() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + new ChristofidesReader(builder).read(getPath("vrpnc1.txt")); + VehicleRoutingProblem vrp = builder.build(); + for (Vehicle v : vrp.getVehicles()) { + assertEquals(160, v.getType().getCapacityDimensions().get(0)); + } + } + + @Test + public void whenReadingInstance_vehicleLocationsAreCorrect_and_correspondToDepotLocation() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + new ChristofidesReader(builder).read(getPath("vrpnc1.txt")); + VehicleRoutingProblem vrp = builder.build(); + for (Vehicle v : vrp.getVehicles()) { + assertEquals(30.0, v.getStartLocation().getCoordinate().getX(), 0.01); + assertEquals(40.0, v.getStartLocation().getCoordinate().getY(), 0.01); + } + } + + @Test + public void whenReadingInstance_vehicleDurationsAreCorrect() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + new ChristofidesReader(builder).read(getPath("vrpnc13.txt")); + VehicleRoutingProblem vrp = builder.build(); + for (Vehicle v : vrp.getVehicles()) { + assertEquals(0.0, v.getEarliestDeparture(), 0.01); + assertEquals(720.0, v.getLatestArrival() - v.getEarliestDeparture(), 0.01); + } + } + + @Test + public void whenReadingInstance_demandOfCustomerOneIsCorrect() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + new ChristofidesReader(builder).read(getPath("vrpnc1.txt")); + VehicleRoutingProblem vrp = builder.build(); + assertEquals(7, vrp.getJobs().get("1").getSize().get(0)); + } + + @Test + public void whenReadingInstance_serviceDurationOfCustomerTwoIsCorrect() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + new ChristofidesReader(builder).read(getPath("vrpnc13.txt")); + VehicleRoutingProblem vrp = builder.build(); + assertEquals(50.0, ((Service) vrp.getJobs().get("2")).getServiceDuration(), 0.1); + } + } diff --git a/jsprit-instances/src/test/java/jsprit/instance/reader/CordeauReaderTest.java b/jsprit-instances/src/test/java/jsprit/instance/reader/CordeauReaderTest.java index 7a9f351d..d48f401b 100644 --- a/jsprit-instances/src/test/java/jsprit/instance/reader/CordeauReaderTest.java +++ b/jsprit-instances/src/test/java/jsprit/instance/reader/CordeauReaderTest.java @@ -11,7 +11,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.instance.reader; @@ -29,125 +29,129 @@ import static org.junit.Assert.assertTrue; public class CordeauReaderTest { - - @Test - public void testCordeauReader(){ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new CordeauReader(vrpBuilder).read(getPath("p01")); - vrpBuilder.build(); - - } - private String getPath(String string) { - URL resource = this.getClass().getClassLoader().getResource(string); - if(resource == null) throw new IllegalStateException("resource " + string + " does not exist"); - return resource.getPath(); - } - - @Test - public void whenReadingInstance_fleetSizeIsFinite(){ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new CordeauReader(vrpBuilder).read(getPath("p01")); - VehicleRoutingProblem vrp = vrpBuilder.build(); - assertEquals(FleetSize.FINITE, vrp.getFleetSize()); - } - - @Test - public void testNuOfVehicles(){ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new CordeauReader(vrpBuilder).read(getPath("p01")); - VehicleRoutingProblem vrp = vrpBuilder.build(); - - assertEquals(16,vrp.getVehicles().size()); - } - - @Test - public void whenReadingCordeauInstance_vehiclesHaveTheCorrectCapacity(){ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new CordeauReader(vrpBuilder).read(getPath("p01")); - VehicleRoutingProblem vrp = vrpBuilder.build(); - for(Vehicle v : vrp.getVehicles()){ - assertEquals(80, v.getType().getCapacityDimensions().get(0)); - } - } - - @Test - public void whenReadingCordeauInstance_vehiclesHaveTheCorrectDuration(){ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new CordeauReader(vrpBuilder).read(getPath("p08")); - VehicleRoutingProblem vrp = vrpBuilder.build(); - for(Vehicle v : vrp.getVehicles()){ - assertEquals(0.0,v.getEarliestDeparture(),0.1); - assertEquals(310.0, v.getLatestArrival()-v.getEarliestDeparture(),0.1); - } - } - - @Test - public void whenReadingCustomersCordeauInstance_customerOneShouldHaveCorrectCoordinates(){ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new CordeauReader(vrpBuilder).read(getPath("p01")); - VehicleRoutingProblem vrp = vrpBuilder.build(); - Service service = (Service) vrp.getJobs().get("1"); - assertEquals(37.0, service.getLocation().getCoordinate().getX(), 0.1); - assertEquals(52.0, service.getLocation().getCoordinate().getY(), 0.1); - } - - @Test - public void whenReadingCustomersCordeauInstance_customerTwoShouldHaveCorrectServiceDuration(){ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new CordeauReader(vrpBuilder).read(getPath("p01")); - VehicleRoutingProblem vrp = vrpBuilder.build(); - Service service = (Service) vrp.getJobs().get("2"); - assertEquals(0.0, service.getServiceDuration(), 0.1); - } - - @Test - public void whenReadingCustomersCordeauInstance_customerThreeShouldHaveCorrectDemand(){ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new CordeauReader(vrpBuilder).read(getPath("p01")); - VehicleRoutingProblem vrp = vrpBuilder.build(); - Service service = (Service) vrp.getJobs().get("3"); - assertEquals(16.0, service.getSize().get(0), 0.1); - } - - @Test - public void whenReadingCustomersCordeauInstance_customerFortySevenShouldHaveCorrectDemand(){ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new CordeauReader(vrpBuilder).read(getPath("p01")); - VehicleRoutingProblem vrp = vrpBuilder.build(); - Service service = (Service) vrp.getJobs().get("47"); - assertEquals(25.0, service.getSize().get(0), 0.1); - } - - @Test - public void testLocationsAndCapOfVehicles(){ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new CordeauReader(vrpBuilder).read(getPath("p01")); - VehicleRoutingProblem vrp = vrpBuilder.build(); - boolean capacityOk = true; - boolean loc1ok = false; - boolean loc2ok = false; - boolean loc3ok = false; - boolean loc4ok = false; - for(Vehicle v : vrp.getVehicles()){ - if(v.getType().getCapacityDimensions().get(0) != 80) capacityOk = false; - if(v.getStartLocation().getCoordinate().getX() == 20.0 && v.getStartLocation().getCoordinate().getY() == 20.0) loc1ok = true; - if(v.getStartLocation().getCoordinate().getX() == 30.0 && v.getStartLocation().getCoordinate().getY() == 40.0) loc2ok = true; - if(v.getStartLocation().getCoordinate().getX() == 50.0 && v.getStartLocation().getCoordinate().getY() == 30.0) loc3ok = true; - if(v.getStartLocation().getCoordinate().getX() == 60.0 && v.getStartLocation().getCoordinate().getY() == 50.0) loc4ok = true; - } - assertTrue(capacityOk); - assertTrue(loc1ok); - assertTrue(loc2ok); - assertTrue(loc3ok); - assertTrue(loc4ok); - } - - @Test - public void testNuOfCustomers(){ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new CordeauReader(vrpBuilder).read(getPath("p01")); - VehicleRoutingProblem vrp = vrpBuilder.build(); - assertEquals(50,vrp.getJobs().values().size()); - } + @Test + public void testCordeauReader() { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new CordeauReader(vrpBuilder).read(getPath("p01")); + vrpBuilder.build(); + + } + + private String getPath(String string) { + URL resource = this.getClass().getClassLoader().getResource(string); + if (resource == null) throw new IllegalStateException("resource " + string + " does not exist"); + return resource.getPath(); + } + + @Test + public void whenReadingInstance_fleetSizeIsFinite() { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new CordeauReader(vrpBuilder).read(getPath("p01")); + VehicleRoutingProblem vrp = vrpBuilder.build(); + assertEquals(FleetSize.FINITE, vrp.getFleetSize()); + } + + @Test + public void testNuOfVehicles() { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new CordeauReader(vrpBuilder).read(getPath("p01")); + VehicleRoutingProblem vrp = vrpBuilder.build(); + + assertEquals(16, vrp.getVehicles().size()); + } + + @Test + public void whenReadingCordeauInstance_vehiclesHaveTheCorrectCapacity() { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new CordeauReader(vrpBuilder).read(getPath("p01")); + VehicleRoutingProblem vrp = vrpBuilder.build(); + for (Vehicle v : vrp.getVehicles()) { + assertEquals(80, v.getType().getCapacityDimensions().get(0)); + } + } + + @Test + public void whenReadingCordeauInstance_vehiclesHaveTheCorrectDuration() { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new CordeauReader(vrpBuilder).read(getPath("p08")); + VehicleRoutingProblem vrp = vrpBuilder.build(); + for (Vehicle v : vrp.getVehicles()) { + assertEquals(0.0, v.getEarliestDeparture(), 0.1); + assertEquals(310.0, v.getLatestArrival() - v.getEarliestDeparture(), 0.1); + } + } + + @Test + public void whenReadingCustomersCordeauInstance_customerOneShouldHaveCorrectCoordinates() { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new CordeauReader(vrpBuilder).read(getPath("p01")); + VehicleRoutingProblem vrp = vrpBuilder.build(); + Service service = (Service) vrp.getJobs().get("1"); + assertEquals(37.0, service.getLocation().getCoordinate().getX(), 0.1); + assertEquals(52.0, service.getLocation().getCoordinate().getY(), 0.1); + } + + @Test + public void whenReadingCustomersCordeauInstance_customerTwoShouldHaveCorrectServiceDuration() { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new CordeauReader(vrpBuilder).read(getPath("p01")); + VehicleRoutingProblem vrp = vrpBuilder.build(); + Service service = (Service) vrp.getJobs().get("2"); + assertEquals(0.0, service.getServiceDuration(), 0.1); + } + + @Test + public void whenReadingCustomersCordeauInstance_customerThreeShouldHaveCorrectDemand() { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new CordeauReader(vrpBuilder).read(getPath("p01")); + VehicleRoutingProblem vrp = vrpBuilder.build(); + Service service = (Service) vrp.getJobs().get("3"); + assertEquals(16.0, service.getSize().get(0), 0.1); + } + + @Test + public void whenReadingCustomersCordeauInstance_customerFortySevenShouldHaveCorrectDemand() { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new CordeauReader(vrpBuilder).read(getPath("p01")); + VehicleRoutingProblem vrp = vrpBuilder.build(); + Service service = (Service) vrp.getJobs().get("47"); + assertEquals(25.0, service.getSize().get(0), 0.1); + } + + @Test + public void testLocationsAndCapOfVehicles() { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new CordeauReader(vrpBuilder).read(getPath("p01")); + VehicleRoutingProblem vrp = vrpBuilder.build(); + boolean capacityOk = true; + boolean loc1ok = false; + boolean loc2ok = false; + boolean loc3ok = false; + boolean loc4ok = false; + for (Vehicle v : vrp.getVehicles()) { + if (v.getType().getCapacityDimensions().get(0) != 80) capacityOk = false; + if (v.getStartLocation().getCoordinate().getX() == 20.0 && v.getStartLocation().getCoordinate().getY() == 20.0) + loc1ok = true; + if (v.getStartLocation().getCoordinate().getX() == 30.0 && v.getStartLocation().getCoordinate().getY() == 40.0) + loc2ok = true; + if (v.getStartLocation().getCoordinate().getX() == 50.0 && v.getStartLocation().getCoordinate().getY() == 30.0) + loc3ok = true; + if (v.getStartLocation().getCoordinate().getX() == 60.0 && v.getStartLocation().getCoordinate().getY() == 50.0) + loc4ok = true; + } + assertTrue(capacityOk); + assertTrue(loc1ok); + assertTrue(loc2ok); + assertTrue(loc3ok); + assertTrue(loc4ok); + } + + @Test + public void testNuOfCustomers() { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new CordeauReader(vrpBuilder).read(getPath("p01")); + VehicleRoutingProblem vrp = vrpBuilder.build(); + assertEquals(50, vrp.getJobs().values().size()); + } } diff --git a/jsprit-instances/src/test/java/jsprit/instance/reader/FigliozziTest.java b/jsprit-instances/src/test/java/jsprit/instance/reader/FigliozziTest.java index 36923e9f..b9dcb8c5 100644 --- a/jsprit-instances/src/test/java/jsprit/instance/reader/FigliozziTest.java +++ b/jsprit-instances/src/test/java/jsprit/instance/reader/FigliozziTest.java @@ -32,150 +32,150 @@ public class FigliozziTest { Locations locations; @Before - public void doBefore(){ - final Coordinate from = Coordinate.newInstance(0,0); - final Coordinate to = Coordinate.newInstance(100,0); + public void doBefore() { + final Coordinate from = Coordinate.newInstance(0, 0); + final Coordinate to = Coordinate.newInstance(100, 0); - locations = new Locations(){ + locations = new Locations() { @Override public Coordinate getCoord(String id) { - if(id.equals("from")) return from; - if(id.equals("to")) return to; + if (id.equals("from")) return from; + if (id.equals("to")) return to; return null; } }; } @Test - public void factoryShouldReturnCorrectSpeedDistribution(){ + public void factoryShouldReturnCorrectSpeedDistribution() { List speedValues = Figliozzi.TimeDependentTransportCostsFactory.createSpeedValues(Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD1a); - Assert.assertEquals(speedValues.get(0),1.,0.01); - Assert.assertEquals(speedValues.get(1),1.6,0.01); - Assert.assertEquals(speedValues.get(2),1.05,0.01); - Assert.assertEquals(5,speedValues.size()); + Assert.assertEquals(speedValues.get(0), 1., 0.01); + Assert.assertEquals(speedValues.get(1), 1.6, 0.01); + Assert.assertEquals(speedValues.get(2), 1.05, 0.01); + Assert.assertEquals(5, speedValues.size()); } @Test - public void whenAskingForTD2a_factoryShouldReturnCorrectSpeedDistribution(){ + public void whenAskingForTD2a_factoryShouldReturnCorrectSpeedDistribution() { List speedValues = Figliozzi.TimeDependentTransportCostsFactory.createSpeedValues(Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD2a); - Assert.assertEquals(speedValues.get(0),1.,0.01); - Assert.assertEquals(speedValues.get(1),2.,0.01); - Assert.assertEquals(speedValues.get(2),1.5,0.01); - Assert.assertEquals(5,speedValues.size()); + Assert.assertEquals(speedValues.get(0), 1., 0.01); + Assert.assertEquals(speedValues.get(1), 2., 0.01); + Assert.assertEquals(speedValues.get(2), 1.5, 0.01); + Assert.assertEquals(5, speedValues.size()); } @Test - public void whenAskingForTD3a_factoryShouldReturnCorrectSpeedDistribution(){ + public void whenAskingForTD3a_factoryShouldReturnCorrectSpeedDistribution() { List speedValues = Figliozzi.TimeDependentTransportCostsFactory.createSpeedValues(Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD3a); - Assert.assertEquals(speedValues.get(0),1.,0.01); - Assert.assertEquals(speedValues.get(1),2.5,0.01); - Assert.assertEquals(speedValues.get(2),1.75,0.01); - Assert.assertEquals(5,speedValues.size()); + Assert.assertEquals(speedValues.get(0), 1., 0.01); + Assert.assertEquals(speedValues.get(1), 2.5, 0.01); + Assert.assertEquals(speedValues.get(2), 1.75, 0.01); + Assert.assertEquals(5, speedValues.size()); } @Test - public void whenAskingForTD1b_factoryShouldReturnCorrectSpeedDistribution(){ + public void whenAskingForTD1b_factoryShouldReturnCorrectSpeedDistribution() { List speedValues = Figliozzi.TimeDependentTransportCostsFactory.createSpeedValues(Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD1b); - Assert.assertEquals(speedValues.get(0),1.6,0.01); - Assert.assertEquals(speedValues.get(1),1.,0.01); - Assert.assertEquals(speedValues.get(2),1.05,0.01); - Assert.assertEquals(speedValues.get(3),1.,0.01); - Assert.assertEquals(speedValues.get(4),1.6,0.01); - Assert.assertEquals(5,speedValues.size()); + Assert.assertEquals(speedValues.get(0), 1.6, 0.01); + Assert.assertEquals(speedValues.get(1), 1., 0.01); + Assert.assertEquals(speedValues.get(2), 1.05, 0.01); + Assert.assertEquals(speedValues.get(3), 1., 0.01); + Assert.assertEquals(speedValues.get(4), 1.6, 0.01); + Assert.assertEquals(5, speedValues.size()); } @Test - public void whenAskingForTD2b_factoryShouldReturnCorrectSpeedDistribution(){ + public void whenAskingForTD2b_factoryShouldReturnCorrectSpeedDistribution() { List speedValues = Figliozzi.TimeDependentTransportCostsFactory.createSpeedValues(Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD2b); - Assert.assertEquals(speedValues.get(0),2.,0.01); - Assert.assertEquals(speedValues.get(1),1.,0.01); - Assert.assertEquals(speedValues.get(2),1.5,0.01); - Assert.assertEquals(speedValues.get(3),1.,0.01); - Assert.assertEquals(speedValues.get(4),2.,0.01); - Assert.assertEquals(5,speedValues.size()); + Assert.assertEquals(speedValues.get(0), 2., 0.01); + Assert.assertEquals(speedValues.get(1), 1., 0.01); + Assert.assertEquals(speedValues.get(2), 1.5, 0.01); + Assert.assertEquals(speedValues.get(3), 1., 0.01); + Assert.assertEquals(speedValues.get(4), 2., 0.01); + Assert.assertEquals(5, speedValues.size()); } @Test - public void whenAskingForTD3b_factoryShouldReturnCorrectSpeedDistribution(){ + public void whenAskingForTD3b_factoryShouldReturnCorrectSpeedDistribution() { List speedValues = Figliozzi.TimeDependentTransportCostsFactory.createSpeedValues(Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD3b); - Assert.assertEquals(speedValues.get(0),2.5,0.01); - Assert.assertEquals(speedValues.get(1),1.,0.01); - Assert.assertEquals(speedValues.get(2),1.75,0.01); - Assert.assertEquals(speedValues.get(3),1.,0.01); - Assert.assertEquals(speedValues.get(4),2.5,0.01); - Assert.assertEquals(5,speedValues.size()); + Assert.assertEquals(speedValues.get(0), 2.5, 0.01); + Assert.assertEquals(speedValues.get(1), 1., 0.01); + Assert.assertEquals(speedValues.get(2), 1.75, 0.01); + Assert.assertEquals(speedValues.get(3), 1., 0.01); + Assert.assertEquals(speedValues.get(4), 2.5, 0.01); + Assert.assertEquals(5, speedValues.size()); } @Test - public void whenAskingForTD1c_factoryShouldReturnCorrectSpeedDistribution(){ + public void whenAskingForTD1c_factoryShouldReturnCorrectSpeedDistribution() { List speedValues = Figliozzi.TimeDependentTransportCostsFactory.createSpeedValues(Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD1c); - Assert.assertEquals(speedValues.get(0),1.6,0.01); - Assert.assertEquals(speedValues.get(1),1.6,0.01); - Assert.assertEquals(speedValues.get(2),1.05,0.01); - Assert.assertEquals(speedValues.get(3),1.,0.01); - Assert.assertEquals(speedValues.get(4),1.,0.01); - Assert.assertEquals(5,speedValues.size()); + Assert.assertEquals(speedValues.get(0), 1.6, 0.01); + Assert.assertEquals(speedValues.get(1), 1.6, 0.01); + Assert.assertEquals(speedValues.get(2), 1.05, 0.01); + Assert.assertEquals(speedValues.get(3), 1., 0.01); + Assert.assertEquals(speedValues.get(4), 1., 0.01); + Assert.assertEquals(5, speedValues.size()); } @Test - public void whenAskingForTD2c_factoryShouldReturnCorrectSpeedDistribution(){ + public void whenAskingForTD2c_factoryShouldReturnCorrectSpeedDistribution() { List speedValues = Figliozzi.TimeDependentTransportCostsFactory.createSpeedValues(Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD2c); - Assert.assertEquals(speedValues.get(0),2.,0.01); - Assert.assertEquals(speedValues.get(1),2.,0.01); - Assert.assertEquals(speedValues.get(2),1.5,0.01); - Assert.assertEquals(speedValues.get(3),1.,0.01); - Assert.assertEquals(speedValues.get(4),1.,0.01); - Assert.assertEquals(5,speedValues.size()); + Assert.assertEquals(speedValues.get(0), 2., 0.01); + Assert.assertEquals(speedValues.get(1), 2., 0.01); + Assert.assertEquals(speedValues.get(2), 1.5, 0.01); + Assert.assertEquals(speedValues.get(3), 1., 0.01); + Assert.assertEquals(speedValues.get(4), 1., 0.01); + Assert.assertEquals(5, speedValues.size()); } @Test - public void whenAskingForTD3c_factoryShouldReturnCorrectSpeedDistribution(){ + public void whenAskingForTD3c_factoryShouldReturnCorrectSpeedDistribution() { List speedValues = Figliozzi.TimeDependentTransportCostsFactory.createSpeedValues(Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD3c); - Assert.assertEquals(speedValues.get(0),2.5,0.01); - Assert.assertEquals(speedValues.get(1),2.5,0.01); - Assert.assertEquals(speedValues.get(2),1.75,0.01); - Assert.assertEquals(speedValues.get(3),1.,0.01); - Assert.assertEquals(speedValues.get(4),1.,0.01); - Assert.assertEquals(5,speedValues.size()); + Assert.assertEquals(speedValues.get(0), 2.5, 0.01); + Assert.assertEquals(speedValues.get(1), 2.5, 0.01); + Assert.assertEquals(speedValues.get(2), 1.75, 0.01); + Assert.assertEquals(speedValues.get(3), 1., 0.01); + Assert.assertEquals(speedValues.get(4), 1., 0.01); + Assert.assertEquals(5, speedValues.size()); } @Test - public void whenAskingForTD1d_factoryShouldReturnCorrectSpeedDistribution(){ + public void whenAskingForTD1d_factoryShouldReturnCorrectSpeedDistribution() { List speedValues = Figliozzi.TimeDependentTransportCostsFactory.createSpeedValues(Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD1d); - Assert.assertEquals(speedValues.get(0),1.,0.01); - Assert.assertEquals(speedValues.get(1),1.,0.01); - Assert.assertEquals(speedValues.get(2),1.05,0.01); - Assert.assertEquals(speedValues.get(3),1.6,0.01); - Assert.assertEquals(speedValues.get(4),1.6,0.01); - Assert.assertEquals(5,speedValues.size()); + Assert.assertEquals(speedValues.get(0), 1., 0.01); + Assert.assertEquals(speedValues.get(1), 1., 0.01); + Assert.assertEquals(speedValues.get(2), 1.05, 0.01); + Assert.assertEquals(speedValues.get(3), 1.6, 0.01); + Assert.assertEquals(speedValues.get(4), 1.6, 0.01); + Assert.assertEquals(5, speedValues.size()); } @Test - public void whenAskingForTD2d_factoryShouldReturnCorrectSpeedDistribution(){ + public void whenAskingForTD2d_factoryShouldReturnCorrectSpeedDistribution() { List speedValues = Figliozzi.TimeDependentTransportCostsFactory.createSpeedValues(Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD2d); - Assert.assertEquals(speedValues.get(0),1.,0.01); - Assert.assertEquals(speedValues.get(1),1.,0.01); - Assert.assertEquals(speedValues.get(2),1.5,0.01); - Assert.assertEquals(speedValues.get(3),2.,0.01); - Assert.assertEquals(speedValues.get(4),2.,0.01); - Assert.assertEquals(5,speedValues.size()); + Assert.assertEquals(speedValues.get(0), 1., 0.01); + Assert.assertEquals(speedValues.get(1), 1., 0.01); + Assert.assertEquals(speedValues.get(2), 1.5, 0.01); + Assert.assertEquals(speedValues.get(3), 2., 0.01); + Assert.assertEquals(speedValues.get(4), 2., 0.01); + Assert.assertEquals(5, speedValues.size()); } @Test - public void whenAskingForTD3d_factoryShouldReturnCorrectSpeedDistribution(){ + public void whenAskingForTD3d_factoryShouldReturnCorrectSpeedDistribution() { List speedValues = Figliozzi.TimeDependentTransportCostsFactory.createSpeedValues(Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD3d); - Assert.assertEquals(speedValues.get(0),1.,0.01); - Assert.assertEquals(speedValues.get(1),1.,0.01); - Assert.assertEquals(speedValues.get(2),1.75,0.01); - Assert.assertEquals(speedValues.get(3),2.5,0.01); - Assert.assertEquals(speedValues.get(4),2.5,0.01); - Assert.assertEquals(5,speedValues.size()); + Assert.assertEquals(speedValues.get(0), 1., 0.01); + Assert.assertEquals(speedValues.get(1), 1., 0.01); + Assert.assertEquals(speedValues.get(2), 1.75, 0.01); + Assert.assertEquals(speedValues.get(3), 2.5, 0.01); + Assert.assertEquals(speedValues.get(4), 2.5, 0.01); + Assert.assertEquals(5, speedValues.size()); } @Test - public void whenConstantTimeDistribution_forwardTimeShouldBeCalculate100(){ - Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.CLASSIC,100); + public void whenConstantTimeDistribution_forwardTimeShouldBeCalculate100() { + Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.CLASSIC, 100); Assert.assertEquals(100., tdCosts.getTransportTime(loc("from"), loc("to"), 0., null, null), 0.01); } @@ -184,8 +184,8 @@ public class FigliozziTest { } @Test - public void whenTimeDistributionTD1a_forwardTimeShouldBeCalculate100(){ - Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD1a,100); + public void whenTimeDistributionTD1a_forwardTimeShouldBeCalculate100() { + Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD1a, 100); /* 100 (0,20) - 1. --> 20 @@ -196,13 +196,13 @@ public class FigliozziTest { 20 */ - Assert.assertEquals(76.875,tdCosts.getTransportTime(loc("from"),loc("to"),0.,null,null),0.01); + Assert.assertEquals(76.875, tdCosts.getTransportTime(loc("from"), loc("to"), 0., null, null), 0.01); } @Test - public void whenTimeDistributionTD2a_forwardTimeShouldBeCalculate100(){ + public void whenTimeDistributionTD2a_forwardTimeShouldBeCalculate100() { //(1.,2.,1.5,2.,1.) - Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD2a,100); + Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD2a, 100); /* 100 (0,20) - 1. --> 20 dist, 20 time @@ -213,26 +213,26 @@ public class FigliozziTest { 20 */ - Assert.assertEquals(65.,tdCosts.getTransportTime(loc("from"),loc("to"),0.,null,null),0.01); + Assert.assertEquals(65., tdCosts.getTransportTime(loc("from"), loc("to"), 0., null, null), 0.01); } @Test - public void whenTimeDistributionTD3a_forwardTimeShouldBeCalculate100(){ + public void whenTimeDistributionTD3a_forwardTimeShouldBeCalculate100() { //(1.,2.5,1.75,2.5,1.) - Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD3a,100); + Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD3a, 100); /* 100 (0,20) - 1. --> 20 dist, 20 time (20,40) 2.5 = 20 --> 50 dist, 20 time : 70 dist, 40 time (40,60) 1.75 = 30 dist, 17.1428571429 time : 100 dist, 57.1428571429 time */ - Assert.assertEquals(57.1428571429,tdCosts.getTransportTime(loc("from"),loc("to"),0.,null,null),0.01); + Assert.assertEquals(57.1428571429, tdCosts.getTransportTime(loc("from"), loc("to"), 0., null, null), 0.01); } @Test - public void whenTimeDistributionTD2a_backwardTimeShouldBeCalculate100(){ + public void whenTimeDistributionTD2a_backwardTimeShouldBeCalculate100() { //(1.,2.,1.5,2.,1.) - Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD2a,100); + Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD2a, 100); /* 100 (0,20) - 1. --> 20 dist, 20 time @@ -243,12 +243,12 @@ public class FigliozziTest { 20 */ - Assert.assertEquals(65.,tdCosts.getBackwardTransportTime(loc("from"),loc("to"), 100., null, null),0.01); + Assert.assertEquals(65., tdCosts.getBackwardTransportTime(loc("from"), loc("to"), 100., null, null), 0.01); } @Test - public void whenTimeDistributionTD1a_backwardTimeShouldBeCalculate100(){ - Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD1a,100); + public void whenTimeDistributionTD1a_backwardTimeShouldBeCalculate100() { + Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD1a, 100); /* 100 (0,20) - 1. --> 20 @@ -259,217 +259,217 @@ public class FigliozziTest { 20 */ - Assert.assertEquals(76.875,tdCosts.getBackwardTransportTime(loc("from"),loc("to"), 100., null, null),0.01); + Assert.assertEquals(76.875, tdCosts.getBackwardTransportTime(loc("from"), loc("to"), 100., null, null), 0.01); } @Test - public void backwardTimeShouldBeCalculatedCorrectly(){ - Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.CLASSIC,100); - Assert.assertEquals(100.,tdCosts.getBackwardTransportTime(loc("from"),loc("to"),100.,null,null),0.01); + public void backwardTimeShouldBeCalculatedCorrectly() { + Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.CLASSIC, 100); + Assert.assertEquals(100., tdCosts.getBackwardTransportTime(loc("from"), loc("to"), 100., null, null), 0.01); } @Test - public void whenTD1a_distanceShouldBe25PercentMore(){ + public void whenTD1a_distanceShouldBe25PercentMore() { Locations locations = new Locations() { @Override public Coordinate getCoord(String id) { - if(id.equals("from")) return Coordinate.newInstance(0,0); - if(id.equals("to")) return Coordinate.newInstance(125.,0); + if (id.equals("from")) return Coordinate.newInstance(0, 0); + if (id.equals("to")) return Coordinate.newInstance(125., 0); return null; } }; - Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD1a,100); - double time = tdCosts.getTransportTime(loc("from"),loc("to"),0.,null,null); - Assert.assertEquals(100.,time,0.01); + Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD1a, 100); + double time = tdCosts.getTransportTime(loc("from"), loc("to"), 0., null, null); + Assert.assertEquals(100., time, 0.01); } @Test - public void whenTD1b_distanceShouldBe25PercentMore(){ + public void whenTD1b_distanceShouldBe25PercentMore() { Locations locations = new Locations() { @Override public Coordinate getCoord(String id) { - if(id.equals("from")) return Coordinate.newInstance(0,0); - if(id.equals("to")) return Coordinate.newInstance(125.,0); + if (id.equals("from")) return Coordinate.newInstance(0, 0); + if (id.equals("to")) return Coordinate.newInstance(125., 0); return null; } }; - Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD1b,100); - double time = tdCosts.getTransportTime(loc("from"),loc("to"),0.,null,null); - Assert.assertEquals(100.,time,0.01); + Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD1b, 100); + double time = tdCosts.getTransportTime(loc("from"), loc("to"), 0., null, null); + Assert.assertEquals(100., time, 0.01); } @Test - public void whenTD1c_distanceShouldBe25PercentMore(){ + public void whenTD1c_distanceShouldBe25PercentMore() { Locations locations = new Locations() { @Override public Coordinate getCoord(String id) { - if(id.equals("from")) return Coordinate.newInstance(0,0); - if(id.equals("to")) return Coordinate.newInstance(125.,0); + if (id.equals("from")) return Coordinate.newInstance(0, 0); + if (id.equals("to")) return Coordinate.newInstance(125., 0); return null; } }; - Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD1c,100); - double time = tdCosts.getTransportTime(loc("from"),loc("to"),0.,null,null); - Assert.assertEquals(100.,time,0.01); + Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD1c, 100); + double time = tdCosts.getTransportTime(loc("from"), loc("to"), 0., null, null); + Assert.assertEquals(100., time, 0.01); } @Test - public void whenTD1d_distanceShouldBe25PercentMore(){ + public void whenTD1d_distanceShouldBe25PercentMore() { Locations locations = new Locations() { @Override public Coordinate getCoord(String id) { - if(id.equals("from")) return Coordinate.newInstance(0,0); - if(id.equals("to")) return Coordinate.newInstance(125.,0); + if (id.equals("from")) return Coordinate.newInstance(0, 0); + if (id.equals("to")) return Coordinate.newInstance(125., 0); return null; } }; - Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD1d,100); - double time = tdCosts.getTransportTime(loc("from"),loc("to"),0.,null,null); - Assert.assertEquals(100.,time,0.01); + Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD1d, 100); + double time = tdCosts.getTransportTime(loc("from"), loc("to"), 0., null, null); + Assert.assertEquals(100., time, 0.01); } @Test - public void whenTD2a_distanceShouldBe50PercentMore(){ + public void whenTD2a_distanceShouldBe50PercentMore() { Locations locations = new Locations() { @Override public Coordinate getCoord(String id) { - if(id.equals("from")) return Coordinate.newInstance(0,0); - if(id.equals("to")) return Coordinate.newInstance(150.,0); + if (id.equals("from")) return Coordinate.newInstance(0, 0); + if (id.equals("to")) return Coordinate.newInstance(150., 0); return null; } }; - Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD2a,100); - double time = tdCosts.getTransportTime(loc("from"),loc("to"),0.,null,null); - Assert.assertEquals(100.,time,0.01); + Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD2a, 100); + double time = tdCosts.getTransportTime(loc("from"), loc("to"), 0., null, null); + Assert.assertEquals(100., time, 0.01); } @Test - public void whenTD2b_distanceShouldBe50PercentMore(){ + public void whenTD2b_distanceShouldBe50PercentMore() { Locations locations = new Locations() { @Override public Coordinate getCoord(String id) { - if(id.equals("from")) return Coordinate.newInstance(0,0); - if(id.equals("to")) return Coordinate.newInstance(150.,0); + if (id.equals("from")) return Coordinate.newInstance(0, 0); + if (id.equals("to")) return Coordinate.newInstance(150., 0); return null; } }; - Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD2b,100); - double time = tdCosts.getTransportTime(loc("from"),loc("to"),0.,null,null); - Assert.assertEquals(100.,time,0.01); + Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD2b, 100); + double time = tdCosts.getTransportTime(loc("from"), loc("to"), 0., null, null); + Assert.assertEquals(100., time, 0.01); } @Test - public void whenTD2c_distanceShouldBe50PercentMore(){ + public void whenTD2c_distanceShouldBe50PercentMore() { Locations locations = new Locations() { @Override public Coordinate getCoord(String id) { - if(id.equals("from")) return Coordinate.newInstance(0,0); - if(id.equals("to")) return Coordinate.newInstance(150.,0); + if (id.equals("from")) return Coordinate.newInstance(0, 0); + if (id.equals("to")) return Coordinate.newInstance(150., 0); return null; } }; - Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD2c,100); - double time = tdCosts.getTransportTime(loc("from"),loc("to"),0.,null,null); - Assert.assertEquals(100.,time,0.01); + Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD2c, 100); + double time = tdCosts.getTransportTime(loc("from"), loc("to"), 0., null, null); + Assert.assertEquals(100., time, 0.01); } @Test - public void whenTD2d_distanceShouldBe50PercentMore(){ + public void whenTD2d_distanceShouldBe50PercentMore() { Locations locations = new Locations() { @Override public Coordinate getCoord(String id) { - if(id.equals("from")) return Coordinate.newInstance(0,0); - if(id.equals("to")) return Coordinate.newInstance(150.,0); + if (id.equals("from")) return Coordinate.newInstance(0, 0); + if (id.equals("to")) return Coordinate.newInstance(150., 0); return null; } }; - Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD2d,100); - double time = tdCosts.getTransportTime(loc("from"),loc("to"),0.,null,null); - Assert.assertEquals(100.,time,0.01); + Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD2d, 100); + double time = tdCosts.getTransportTime(loc("from"), loc("to"), 0., null, null); + Assert.assertEquals(100., time, 0.01); } @Test - public void whenTD3a_distanceShouldBe75PercentMore(){ + public void whenTD3a_distanceShouldBe75PercentMore() { Locations locations = new Locations() { @Override public Coordinate getCoord(String id) { - if(id.equals("from")) return Coordinate.newInstance(0,0); - if(id.equals("to")) return Coordinate.newInstance(175.,0); + if (id.equals("from")) return Coordinate.newInstance(0, 0); + if (id.equals("to")) return Coordinate.newInstance(175., 0); return null; } }; - Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD3a,100); - double time = tdCosts.getTransportTime(loc("from"),loc("to"),0.,null,null); - Assert.assertEquals(100.,time,0.01); + Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD3a, 100); + double time = tdCosts.getTransportTime(loc("from"), loc("to"), 0., null, null); + Assert.assertEquals(100., time, 0.01); } @Test - public void whenTD3b_distanceShouldBe75PercentMore(){ + public void whenTD3b_distanceShouldBe75PercentMore() { Locations locations = new Locations() { @Override public Coordinate getCoord(String id) { - if(id.equals("from")) return Coordinate.newInstance(0,0); - if(id.equals("to")) return Coordinate.newInstance(175.,0); + if (id.equals("from")) return Coordinate.newInstance(0, 0); + if (id.equals("to")) return Coordinate.newInstance(175., 0); return null; } }; - Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD3b,100); - double time = tdCosts.getTransportTime(loc("from"),loc("to"),0.,null,null); - Assert.assertEquals(100.,time,0.01); + Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD3b, 100); + double time = tdCosts.getTransportTime(loc("from"), loc("to"), 0., null, null); + Assert.assertEquals(100., time, 0.01); } @Test - public void whenTD3c_distanceShouldBe75PercentMore(){ + public void whenTD3c_distanceShouldBe75PercentMore() { Locations locations = new Locations() { @Override public Coordinate getCoord(String id) { - if(id.equals("from")) return Coordinate.newInstance(0,0); - if(id.equals("to")) return Coordinate.newInstance(175.,0); + if (id.equals("from")) return Coordinate.newInstance(0, 0); + if (id.equals("to")) return Coordinate.newInstance(175., 0); return null; } }; - Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD3c,100); - double time = tdCosts.getTransportTime(loc("from"),loc("to"),0.,null,null); - Assert.assertEquals(100.,time,0.01); + Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD3c, 100); + double time = tdCosts.getTransportTime(loc("from"), loc("to"), 0., null, null); + Assert.assertEquals(100., time, 0.01); } @Test - public void whenTD3d_distanceShouldBe75PercentMore(){ + public void whenTD3d_distanceShouldBe75PercentMore() { Locations locations = new Locations() { @Override public Coordinate getCoord(String id) { - if(id.equals("from")) return Coordinate.newInstance(0,0); - if(id.equals("to")) return Coordinate.newInstance(175.,0); + if (id.equals("from")) return Coordinate.newInstance(0, 0); + if (id.equals("to")) return Coordinate.newInstance(175., 0); return null; } }; - Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD3d,100); - double time = tdCosts.getTransportTime(loc("from"),loc("to"),0.,null,null); - Assert.assertEquals(100.,time,0.01); + Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD3d, 100); + double time = tdCosts.getTransportTime(loc("from"), loc("to"), 0., null, null); + Assert.assertEquals(100., time, 0.01); } } diff --git a/jsprit-instances/src/test/java/jsprit/instance/reader/GoldenReaderTest.java b/jsprit-instances/src/test/java/jsprit/instance/reader/GoldenReaderTest.java index 0605158a..15f85f88 100644 --- a/jsprit-instances/src/test/java/jsprit/instance/reader/GoldenReaderTest.java +++ b/jsprit-instances/src/test/java/jsprit/instance/reader/GoldenReaderTest.java @@ -30,297 +30,296 @@ import java.net.URL; import static org.junit.Assert.*; public class GoldenReaderTest { - - @Test - public void whenReadingInstance_itShouldReadCorrectNuOfVehicles(){ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrphGoldenReader(vrpBuilder, VrphType.HVRPD) - .read(getPath("cn_13mix.txt")); - VehicleRoutingProblem vrp = vrpBuilder.build(); - assertEquals(17,vrp.getVehicles().size()); - } - private String getPath(String string) { - URL resource = this.getClass().getClassLoader().getResource(string); - if(resource == null) throw new IllegalStateException("resource " + string + " does not exist"); - return resource.getPath(); - } - - @Test - public void whenReadingInstance_itShouldReadCorrectNuOfType1Vehicles(){ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrphGoldenReader(vrpBuilder, VrphType.HVRPD) - .read(getPath("cn_13mix.txt")); - VehicleRoutingProblem vrp = vrpBuilder.build(); - int nuOfType1Vehicles = 0; - for(Vehicle v : vrp.getVehicles()){ - if(v.getType().getTypeId().equals("type_1")){ - nuOfType1Vehicles++; - } - } - assertEquals(4,nuOfType1Vehicles); - } - - @Test - public void whenReadingInstance_theSumOfType1VehicleShouldHvTheCorrectCapacity(){ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrphGoldenReader(vrpBuilder, VrphType.HVRPD) - .read(getPath("cn_13mix.txt")); - VehicleRoutingProblem vrp = vrpBuilder.build(); - int sumOfType1Cap = 0; - for(Vehicle v : vrp.getVehicles()){ - if(v.getType().getTypeId().equals("type_1")){ - sumOfType1Cap+=v.getType().getCapacityDimensions().get(0); - } - } - assertEquals(80,sumOfType1Cap); - } + @Test + public void whenReadingInstance_itShouldReadCorrectNuOfVehicles() { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrphGoldenReader(vrpBuilder, VrphType.HVRPD) + .read(getPath("cn_13mix.txt")); + VehicleRoutingProblem vrp = vrpBuilder.build(); + assertEquals(17, vrp.getVehicles().size()); + } - @Test - public void whenReadingInstance_itShouldReadCorrectNuOfType2Vehicles(){ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrphGoldenReader(vrpBuilder, VrphType.HVRPD) - .read(getPath("cn_13mix.txt")); - VehicleRoutingProblem vrp = vrpBuilder.build(); - int nuOfType1Vehicles = 0; - for(Vehicle v : vrp.getVehicles()){ - if(v.getType().getTypeId().equals("type_2")){ - nuOfType1Vehicles++; - } - } - assertEquals(2,nuOfType1Vehicles); - } - - @Test - public void whenReadingInstance_theSumOfType2VehicleShouldHvTheCorrectCapacity(){ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrphGoldenReader(vrpBuilder, VrphType.HVRPD) - .read(getPath("cn_13mix.txt")); - VehicleRoutingProblem vrp = vrpBuilder.build(); - int sumOfType1Cap = 0; - for(Vehicle v : vrp.getVehicles()){ - if(v.getType().getTypeId().equals("type_2") ){ - sumOfType1Cap+=v.getType().getCapacityDimensions().get(0); - } - } - assertEquals(60,sumOfType1Cap); - } - - @Test - public void whenReadingInstance_itShouldReadCorrectNuOfType3Vehicles(){ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrphGoldenReader(vrpBuilder, VrphType.HVRPD) - .read(getPath("cn_13mix.txt")); - VehicleRoutingProblem vrp = vrpBuilder.build(); - int nuOfType1Vehicles = 0; - for(Vehicle v : vrp.getVehicles()){ - if(v.getType().getTypeId().equals("type_3")){ - nuOfType1Vehicles++; - } - } - assertEquals(4,nuOfType1Vehicles); - } - - @Test - public void whenReadingInstance_theSumOfType3VehicleShouldHvTheCorrectCapacity(){ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrphGoldenReader(vrpBuilder, VrphType.HVRPD) - .read(getPath("cn_13mix.txt")); - VehicleRoutingProblem vrp = vrpBuilder.build(); - int sumOfType1Cap = 0; - for(Vehicle v : vrp.getVehicles()){ - if(v.getType().getTypeId().equals("type_3")){ - sumOfType1Cap+=v.getType().getCapacityDimensions().get(0); - } - } - assertEquals(160,sumOfType1Cap); - } - - @Test - public void whenReadingInstance_itShouldReadCorrectNuOfType4Vehicles(){ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrphGoldenReader(vrpBuilder, VrphType.HVRPD) - .read(getPath("cn_13mix.txt")); - VehicleRoutingProblem vrp = vrpBuilder.build(); - int nuOfType1Vehicles = 0; - for(Vehicle v : vrp.getVehicles()){ - if(v.getType().getTypeId().equals("type_4")){ - nuOfType1Vehicles++; - } - } - assertEquals(4,nuOfType1Vehicles); - } - - @Test - public void whenReadingInstance_theSumOfType4VehicleShouldHvTheCorrectCapacity(){ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrphGoldenReader(vrpBuilder, VrphType.HVRPD) - .read(getPath("cn_13mix.txt")); - VehicleRoutingProblem vrp = vrpBuilder.build(); - int sumOfType1Cap = 0; - for(Vehicle v : vrp.getVehicles()){ - if(v.getType().getTypeId().equals("type_4")){ - sumOfType1Cap+=v.getType().getCapacityDimensions().get(0); - } - } - assertEquals(280,sumOfType1Cap); - } - - @Test - public void whenReadingInstance_itShouldReadCorrectNuOfType5Vehicles(){ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrphGoldenReader(vrpBuilder, VrphType.HVRPD) - .read(getPath("cn_13mix.txt")); - VehicleRoutingProblem vrp = vrpBuilder.build(); - int nuOfType1Vehicles = 0; - for(Vehicle v : vrp.getVehicles()){ - if(v.getType().getTypeId().equals("type_5") ){ - nuOfType1Vehicles++; - } - } - assertEquals(2,nuOfType1Vehicles); - } - - @Test - public void whenReadingInstance_theSumOfType5VehicleShouldHvTheCorrectCapacity(){ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrphGoldenReader(vrpBuilder, VrphType.HVRPD) - .read(getPath("cn_13mix.txt")); - VehicleRoutingProblem vrp = vrpBuilder.build(); - int sumOfType1Cap = 0; - for(Vehicle v : vrp.getVehicles()){ - if(v.getType().getTypeId().equals("type_5")){ - sumOfType1Cap+=v.getType().getCapacityDimensions().get(0); - } - } - assertEquals(240,sumOfType1Cap); - } - - @Test - public void whenReadingInstance_itShouldReadCorrectNuOfType6Vehicles(){ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrphGoldenReader(vrpBuilder, VrphType.HVRPD) - .read(getPath("cn_13mix.txt")); - VehicleRoutingProblem vrp = vrpBuilder.build(); - int nuOfType1Vehicles = 0; - for(Vehicle v : vrp.getVehicles()){ - if(v.getType().getTypeId().equals("type_6")){ - nuOfType1Vehicles++; - } - } - assertEquals(1,nuOfType1Vehicles); - } - - @Test - public void whenReadingInstance_theSumOfType6VehicleShouldHvTheCorrectCapacity(){ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrphGoldenReader(vrpBuilder, VrphType.HVRPD) - .read(getPath("cn_13mix.txt")); - VehicleRoutingProblem vrp = vrpBuilder.build(); - int sumOfType1Cap = 0; - for(Vehicle v : vrp.getVehicles()){ - if(v.getType().getTypeId().equals("type_6") ){ - sumOfType1Cap+=v.getType().getCapacityDimensions().get(0); - } - } - assertEquals(200,sumOfType1Cap); - } - - @Test - public void whenReadingInstance_vehicleShouldHvTheCorrectCoord(){ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrphGoldenReader(vrpBuilder, VrphType.HVRPD) - .read(getPath("cn_13mix.txt")); - VehicleRoutingProblem vrp = vrpBuilder.build(); - for(Vehicle v : vrp.getVehicles()){ - if(v.getStartLocation().getCoordinate().getX() != 40.0){ - assertFalse(true); - } - if(v.getStartLocation().getCoordinate().getY() != 40.0){ - assertFalse(true); - } - } - assertTrue(true); - } - - @Test - public void whenReadingInstance_service1MustHaveCorrectDemand(){ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrphGoldenReader(vrpBuilder, VrphType.HVRPD) - .read(getPath("cn_13mix.txt")); - VehicleRoutingProblem vrp = vrpBuilder.build(); - Job job = getJob("1",vrp); - assertEquals(18,job.getSize().get(0)); - } - - @Test - public void whenReadingInstance_service1MustHaveCorrectCoordinate(){ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrphGoldenReader(vrpBuilder, VrphType.HVRPD) - .read(getPath("cn_13mix.txt")); - VehicleRoutingProblem vrp = vrpBuilder.build(); - Coordinate coord = getCoord("1",vrp); - assertEquals(22.0,coord.getX(),0.01); - assertEquals(22.0,coord.getY(),0.01); - } - - @Test - public void whenReadingInstance_service15MustHaveCorrectCoordinate(){ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrphGoldenReader(vrpBuilder, VrphType.HVRPD) - .read(getPath("cn_13mix.txt")); - VehicleRoutingProblem vrp = vrpBuilder.build(); - Coordinate coord = getCoord("15",vrp); - assertEquals(62.0,coord.getX(),0.01); - assertEquals(24.0,coord.getY(),0.01); - } - - - - @Test - public void whenReadingInstance_service50MustHaveCorrectCoordinate(){ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrphGoldenReader(vrpBuilder, VrphType.HVRPD) - .read(getPath("cn_13mix.txt")); - VehicleRoutingProblem vrp = vrpBuilder.build(); - Coordinate coord = getCoord("50",vrp); - assertEquals(15.0,coord.getX(),0.01); - assertEquals(56.0,coord.getY(),0.01); - } - - private Coordinate getCoord(String string, VehicleRoutingProblem vrp) { - Job j = getJob(string,vrp); - return ((Service)j).getLocation().getCoordinate(); - } + private String getPath(String string) { + URL resource = this.getClass().getClassLoader().getResource(string); + if (resource == null) throw new IllegalStateException("resource " + string + " does not exist"); + return resource.getPath(); + } + + @Test + public void whenReadingInstance_itShouldReadCorrectNuOfType1Vehicles() { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrphGoldenReader(vrpBuilder, VrphType.HVRPD) + .read(getPath("cn_13mix.txt")); + VehicleRoutingProblem vrp = vrpBuilder.build(); + int nuOfType1Vehicles = 0; + for (Vehicle v : vrp.getVehicles()) { + if (v.getType().getTypeId().equals("type_1")) { + nuOfType1Vehicles++; + } + } + assertEquals(4, nuOfType1Vehicles); + } + + @Test + public void whenReadingInstance_theSumOfType1VehicleShouldHvTheCorrectCapacity() { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrphGoldenReader(vrpBuilder, VrphType.HVRPD) + .read(getPath("cn_13mix.txt")); + VehicleRoutingProblem vrp = vrpBuilder.build(); + int sumOfType1Cap = 0; + for (Vehicle v : vrp.getVehicles()) { + if (v.getType().getTypeId().equals("type_1")) { + sumOfType1Cap += v.getType().getCapacityDimensions().get(0); + } + } + assertEquals(80, sumOfType1Cap); + } + + @Test + public void whenReadingInstance_itShouldReadCorrectNuOfType2Vehicles() { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrphGoldenReader(vrpBuilder, VrphType.HVRPD) + .read(getPath("cn_13mix.txt")); + VehicleRoutingProblem vrp = vrpBuilder.build(); + int nuOfType1Vehicles = 0; + for (Vehicle v : vrp.getVehicles()) { + if (v.getType().getTypeId().equals("type_2")) { + nuOfType1Vehicles++; + } + } + assertEquals(2, nuOfType1Vehicles); + } + + @Test + public void whenReadingInstance_theSumOfType2VehicleShouldHvTheCorrectCapacity() { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrphGoldenReader(vrpBuilder, VrphType.HVRPD) + .read(getPath("cn_13mix.txt")); + VehicleRoutingProblem vrp = vrpBuilder.build(); + int sumOfType1Cap = 0; + for (Vehicle v : vrp.getVehicles()) { + if (v.getType().getTypeId().equals("type_2")) { + sumOfType1Cap += v.getType().getCapacityDimensions().get(0); + } + } + assertEquals(60, sumOfType1Cap); + } + + @Test + public void whenReadingInstance_itShouldReadCorrectNuOfType3Vehicles() { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrphGoldenReader(vrpBuilder, VrphType.HVRPD) + .read(getPath("cn_13mix.txt")); + VehicleRoutingProblem vrp = vrpBuilder.build(); + int nuOfType1Vehicles = 0; + for (Vehicle v : vrp.getVehicles()) { + if (v.getType().getTypeId().equals("type_3")) { + nuOfType1Vehicles++; + } + } + assertEquals(4, nuOfType1Vehicles); + } + + @Test + public void whenReadingInstance_theSumOfType3VehicleShouldHvTheCorrectCapacity() { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrphGoldenReader(vrpBuilder, VrphType.HVRPD) + .read(getPath("cn_13mix.txt")); + VehicleRoutingProblem vrp = vrpBuilder.build(); + int sumOfType1Cap = 0; + for (Vehicle v : vrp.getVehicles()) { + if (v.getType().getTypeId().equals("type_3")) { + sumOfType1Cap += v.getType().getCapacityDimensions().get(0); + } + } + assertEquals(160, sumOfType1Cap); + } + + @Test + public void whenReadingInstance_itShouldReadCorrectNuOfType4Vehicles() { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrphGoldenReader(vrpBuilder, VrphType.HVRPD) + .read(getPath("cn_13mix.txt")); + VehicleRoutingProblem vrp = vrpBuilder.build(); + int nuOfType1Vehicles = 0; + for (Vehicle v : vrp.getVehicles()) { + if (v.getType().getTypeId().equals("type_4")) { + nuOfType1Vehicles++; + } + } + assertEquals(4, nuOfType1Vehicles); + } + + @Test + public void whenReadingInstance_theSumOfType4VehicleShouldHvTheCorrectCapacity() { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrphGoldenReader(vrpBuilder, VrphType.HVRPD) + .read(getPath("cn_13mix.txt")); + VehicleRoutingProblem vrp = vrpBuilder.build(); + int sumOfType1Cap = 0; + for (Vehicle v : vrp.getVehicles()) { + if (v.getType().getTypeId().equals("type_4")) { + sumOfType1Cap += v.getType().getCapacityDimensions().get(0); + } + } + assertEquals(280, sumOfType1Cap); + } + + @Test + public void whenReadingInstance_itShouldReadCorrectNuOfType5Vehicles() { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrphGoldenReader(vrpBuilder, VrphType.HVRPD) + .read(getPath("cn_13mix.txt")); + VehicleRoutingProblem vrp = vrpBuilder.build(); + int nuOfType1Vehicles = 0; + for (Vehicle v : vrp.getVehicles()) { + if (v.getType().getTypeId().equals("type_5")) { + nuOfType1Vehicles++; + } + } + assertEquals(2, nuOfType1Vehicles); + } + + @Test + public void whenReadingInstance_theSumOfType5VehicleShouldHvTheCorrectCapacity() { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrphGoldenReader(vrpBuilder, VrphType.HVRPD) + .read(getPath("cn_13mix.txt")); + VehicleRoutingProblem vrp = vrpBuilder.build(); + int sumOfType1Cap = 0; + for (Vehicle v : vrp.getVehicles()) { + if (v.getType().getTypeId().equals("type_5")) { + sumOfType1Cap += v.getType().getCapacityDimensions().get(0); + } + } + assertEquals(240, sumOfType1Cap); + } + + @Test + public void whenReadingInstance_itShouldReadCorrectNuOfType6Vehicles() { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrphGoldenReader(vrpBuilder, VrphType.HVRPD) + .read(getPath("cn_13mix.txt")); + VehicleRoutingProblem vrp = vrpBuilder.build(); + int nuOfType1Vehicles = 0; + for (Vehicle v : vrp.getVehicles()) { + if (v.getType().getTypeId().equals("type_6")) { + nuOfType1Vehicles++; + } + } + assertEquals(1, nuOfType1Vehicles); + } + + @Test + public void whenReadingInstance_theSumOfType6VehicleShouldHvTheCorrectCapacity() { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrphGoldenReader(vrpBuilder, VrphType.HVRPD) + .read(getPath("cn_13mix.txt")); + VehicleRoutingProblem vrp = vrpBuilder.build(); + int sumOfType1Cap = 0; + for (Vehicle v : vrp.getVehicles()) { + if (v.getType().getTypeId().equals("type_6")) { + sumOfType1Cap += v.getType().getCapacityDimensions().get(0); + } + } + assertEquals(200, sumOfType1Cap); + } + + @Test + public void whenReadingInstance_vehicleShouldHvTheCorrectCoord() { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrphGoldenReader(vrpBuilder, VrphType.HVRPD) + .read(getPath("cn_13mix.txt")); + VehicleRoutingProblem vrp = vrpBuilder.build(); + for (Vehicle v : vrp.getVehicles()) { + if (v.getStartLocation().getCoordinate().getX() != 40.0) { + assertFalse(true); + } + if (v.getStartLocation().getCoordinate().getY() != 40.0) { + assertFalse(true); + } + } + assertTrue(true); + } + + @Test + public void whenReadingInstance_service1MustHaveCorrectDemand() { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrphGoldenReader(vrpBuilder, VrphType.HVRPD) + .read(getPath("cn_13mix.txt")); + VehicleRoutingProblem vrp = vrpBuilder.build(); + Job job = getJob("1", vrp); + assertEquals(18, job.getSize().get(0)); + } + + @Test + public void whenReadingInstance_service1MustHaveCorrectCoordinate() { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrphGoldenReader(vrpBuilder, VrphType.HVRPD) + .read(getPath("cn_13mix.txt")); + VehicleRoutingProblem vrp = vrpBuilder.build(); + Coordinate coord = getCoord("1", vrp); + assertEquals(22.0, coord.getX(), 0.01); + assertEquals(22.0, coord.getY(), 0.01); + } + + @Test + public void whenReadingInstance_service15MustHaveCorrectCoordinate() { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrphGoldenReader(vrpBuilder, VrphType.HVRPD) + .read(getPath("cn_13mix.txt")); + VehicleRoutingProblem vrp = vrpBuilder.build(); + Coordinate coord = getCoord("15", vrp); + assertEquals(62.0, coord.getX(), 0.01); + assertEquals(24.0, coord.getY(), 0.01); + } + + + @Test + public void whenReadingInstance_service50MustHaveCorrectCoordinate() { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrphGoldenReader(vrpBuilder, VrphType.HVRPD) + .read(getPath("cn_13mix.txt")); + VehicleRoutingProblem vrp = vrpBuilder.build(); + Coordinate coord = getCoord("50", vrp); + assertEquals(15.0, coord.getX(), 0.01); + assertEquals(56.0, coord.getY(), 0.01); + } + + private Coordinate getCoord(String string, VehicleRoutingProblem vrp) { + Job j = getJob(string, vrp); + return ((Service) j).getLocation().getCoordinate(); + } + + @Test + public void whenReadingInstance_service4MustHaveCorrectDemand() { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrphGoldenReader(vrpBuilder, VrphType.HVRPD) + .read(getPath("cn_13mix.txt")); + VehicleRoutingProblem vrp = vrpBuilder.build(); + Job job = getJob("4", vrp); + assertEquals(30, job.getSize().get(0)); + } + + @Test + public void whenReadingInstance_service50MustHaveCorrectDemand() { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrphGoldenReader(vrpBuilder, VrphType.HVRPD) + .read(getPath("cn_13mix.txt")); + VehicleRoutingProblem vrp = vrpBuilder.build(); + Job job = getJob("50", vrp); + assertEquals(22, job.getSize().get(0)); + } + + private Job getJob(String string, VehicleRoutingProblem vrp) { + for (Job j : vrp.getJobs().values()) { + if (j.getId().equals(string)) { + return j; + } + } + return null; + } - @Test - public void whenReadingInstance_service4MustHaveCorrectDemand(){ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrphGoldenReader(vrpBuilder, VrphType.HVRPD) - .read(getPath("cn_13mix.txt")); - VehicleRoutingProblem vrp = vrpBuilder.build(); - Job job = getJob("4",vrp); - assertEquals(30,job.getSize().get(0)); - } - - @Test - public void whenReadingInstance_service50MustHaveCorrectDemand(){ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrphGoldenReader(vrpBuilder, VrphType.HVRPD) - .read(getPath("cn_13mix.txt")); - VehicleRoutingProblem vrp = vrpBuilder.build(); - Job job = getJob("50",vrp); - assertEquals(22,job.getSize().get(0)); - } - private Job getJob(String string, VehicleRoutingProblem vrp) { - for(Job j : vrp.getJobs().values()){ - if(j.getId().equals(string)){ - return j; - } - } - return null; - } - - } diff --git a/jsprit-instances/src/test/java/jsprit/instance/reader/LuiShenReaderTest.java b/jsprit-instances/src/test/java/jsprit/instance/reader/LuiShenReaderTest.java index ddcee891..8304dc04 100644 --- a/jsprit-instances/src/test/java/jsprit/instance/reader/LuiShenReaderTest.java +++ b/jsprit-instances/src/test/java/jsprit/instance/reader/LuiShenReaderTest.java @@ -1,60 +1,60 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.instance.reader; -import static org.junit.Assert.assertEquals; import jsprit.core.problem.VehicleRoutingProblem; import jsprit.core.problem.VehicleRoutingProblem.FleetSize; - import org.junit.Before; import org.junit.Test; +import static org.junit.Assert.assertEquals; + public class LuiShenReaderTest { - - VehicleRoutingProblem vrp; - - - @Before - public void doBefore(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new LuiShenReader(builder).read(this.getClass().getClassLoader().getResource("C101_solomon.txt").getPath(), - this.getClass().getClassLoader().getResource("C1_LuiShenVehicles.txt").getPath(), "a"); - vrp = builder.build(); - } - @Test - public void testFleetSize(){ - assertEquals(FleetSize.INFINITE,vrp.getFleetSize()); - } - + VehicleRoutingProblem vrp; - @Test - public void testNuOfTypes(){ - assertEquals(3, vrp.getTypes().size()); - } - - @Test - public void testNuOfRepresentativeVehicles(){ - assertEquals(3, vrp.getVehicles().size()); - } - - @Test - public void testNuOfJobs(){ - assertEquals(100,vrp.getJobs().values().size()); - } + + @Before + public void doBefore() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + new LuiShenReader(builder).read(this.getClass().getClassLoader().getResource("C101_solomon.txt").getPath(), + this.getClass().getClassLoader().getResource("C1_LuiShenVehicles.txt").getPath(), "a"); + vrp = builder.build(); + } + + @Test + public void testFleetSize() { + assertEquals(FleetSize.INFINITE, vrp.getFleetSize()); + } + + + @Test + public void testNuOfTypes() { + assertEquals(3, vrp.getTypes().size()); + } + + @Test + public void testNuOfRepresentativeVehicles() { + assertEquals(3, vrp.getVehicles().size()); + } + + @Test + public void testNuOfJobs() { + assertEquals(100, vrp.getJobs().values().size()); + } } diff --git a/jsprit-instances/src/test/java/jsprit/instance/reader/SolomonReaderTest.java b/jsprit-instances/src/test/java/jsprit/instance/reader/SolomonReaderTest.java index 7ddbb6b5..ee409de4 100644 --- a/jsprit-instances/src/test/java/jsprit/instance/reader/SolomonReaderTest.java +++ b/jsprit-instances/src/test/java/jsprit/instance/reader/SolomonReaderTest.java @@ -1,17 +1,17 @@ /******************************************************************************* * Copyright (C) 2013 Stefan Schroeder - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ package jsprit.instance.reader; @@ -28,81 +28,81 @@ import static org.junit.Assert.assertEquals; public class SolomonReaderTest { - - @Test - public void whenReadingSolomonInstance_nuOfCustomersIsCorrect(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new SolomonReader(builder).read(getPath()); - VehicleRoutingProblem vrp = builder.build(); - assertEquals(100,vrp.getJobs().values().size()); - } - private String getPath() { - URL resource = getClass().getClassLoader().getResource("C101_solomon.txt"); - if(resource == null) throw new IllegalStateException("file C101_solomon.txt does not exist"); - return resource.getPath(); - } + @Test + public void whenReadingSolomonInstance_nuOfCustomersIsCorrect() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + new SolomonReader(builder).read(getPath()); + VehicleRoutingProblem vrp = builder.build(); + assertEquals(100, vrp.getJobs().values().size()); + } + + private String getPath() { + URL resource = getClass().getClassLoader().getResource("C101_solomon.txt"); + if (resource == null) throw new IllegalStateException("file C101_solomon.txt does not exist"); + return resource.getPath(); + } + + @Test + public void whenReadingSolomonInstance_fleetSizeIsInfinite() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + new SolomonReader(builder).read(getPath()); + VehicleRoutingProblem vrp = builder.build(); + assertEquals(FleetSize.INFINITE, vrp.getFleetSize()); + } + + @Test + public void whenReadingSolomonInstance_vehicleCapacitiesAreCorrect() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + new SolomonReader(builder).read(getPath()); + VehicleRoutingProblem vrp = builder.build(); + for (Vehicle v : vrp.getVehicles()) { + assertEquals(200, v.getType().getCapacityDimensions().get(0)); + } + } + + @Test + public void whenReadingSolomonInstance_vehicleLocationsAreCorrect_and_correspondToDepotLocation() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + new SolomonReader(builder).read(getPath()); + VehicleRoutingProblem vrp = builder.build(); + for (Vehicle v : vrp.getVehicles()) { + assertEquals(40.0, v.getStartLocation().getCoordinate().getX(), 0.01); + assertEquals(50.0, v.getStartLocation().getCoordinate().getY(), 0.01); + } + } + + @Test + public void whenReadingSolomonInstance_demandOfCustomerOneIsCorrect() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + new SolomonReader(builder).read(getPath()); + VehicleRoutingProblem vrp = builder.build(); + assertEquals(10, vrp.getJobs().get("1").getSize().get(0)); + } + + @Test + public void whenReadingSolomonInstance_serviceDurationOfCustomerTwoIsCorrect() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + new SolomonReader(builder).read(getPath()); + VehicleRoutingProblem vrp = builder.build(); + assertEquals(90, ((Service) vrp.getJobs().get("2")).getServiceDuration(), 0.1); + } + + @Test + public void whenReadingSolomonInstance_earliestServiceStartTimeOfCustomerSixtyTwoIsCorrect() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + new SolomonReader(builder).read(getPath()); + VehicleRoutingProblem vrp = builder.build(); + assertEquals(262.0, ((Service) vrp.getJobs().get("62")).getTimeWindow().getStart(), 0.1); + } + + @Test + public void whenReadingSolomonInstance_latestServiceStartTimeOfCustomerEightySevenIsCorrect() { + VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); + new SolomonReader(builder).read(getPath()); + VehicleRoutingProblem vrp = builder.build(); + assertEquals(144.0, ((Service) vrp.getJobs().get("87")).getTimeWindow().getEnd(), 0.1); + } - @Test - public void whenReadingSolomonInstance_fleetSizeIsInfinite(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new SolomonReader(builder).read(getPath()); - VehicleRoutingProblem vrp = builder.build(); - assertEquals(FleetSize.INFINITE,vrp.getFleetSize()); - } - - @Test - public void whenReadingSolomonInstance_vehicleCapacitiesAreCorrect(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new SolomonReader(builder).read(getPath()); - VehicleRoutingProblem vrp = builder.build(); - for(Vehicle v : vrp.getVehicles()){ - assertEquals(200,v.getType().getCapacityDimensions().get(0)); - } - } - - @Test - public void whenReadingSolomonInstance_vehicleLocationsAreCorrect_and_correspondToDepotLocation(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new SolomonReader(builder).read(getPath()); - VehicleRoutingProblem vrp = builder.build(); - for(Vehicle v : vrp.getVehicles()){ - assertEquals(40.0,v.getStartLocation().getCoordinate().getX(),0.01); - assertEquals(50.0,v.getStartLocation().getCoordinate().getY(),0.01); - } - } - - @Test - public void whenReadingSolomonInstance_demandOfCustomerOneIsCorrect(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new SolomonReader(builder).read(getPath()); - VehicleRoutingProblem vrp = builder.build(); - assertEquals(10,vrp.getJobs().get("1").getSize().get(0)); - } - - @Test - public void whenReadingSolomonInstance_serviceDurationOfCustomerTwoIsCorrect(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new SolomonReader(builder).read(getPath()); - VehicleRoutingProblem vrp = builder.build(); - assertEquals(90,((Service)vrp.getJobs().get("2")).getServiceDuration(),0.1); - } - - @Test - public void whenReadingSolomonInstance_earliestServiceStartTimeOfCustomerSixtyTwoIsCorrect(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new SolomonReader(builder).read(getPath()); - VehicleRoutingProblem vrp = builder.build(); - assertEquals(262.0,((Service)vrp.getJobs().get("62")).getTimeWindow().getStart(),0.1); - } - - @Test - public void whenReadingSolomonInstance_latestServiceStartTimeOfCustomerEightySevenIsCorrect(){ - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new SolomonReader(builder).read(getPath()); - VehicleRoutingProblem vrp = builder.build(); - assertEquals(144.0,((Service)vrp.getJobs().get("87")).getTimeWindow().getEnd(),0.1); - } - } diff --git a/pom.xml b/pom.xml index 47a8a636..ab9124ab 100644 --- a/pom.xml +++ b/pom.xml @@ -1,4 +1,3 @@ - - - 4.0.0 - - jsprit - jsprit - 1.6.1-SNAPSHOT - - pom - - jsprit - A toolkit to solve vehicle routing problems. - https://github.com/jsprit/jsprit - 2013 - - - - GNU Lesser General Public Licence, version 3.0 - http://opensource.org/licenses/LGPL-3.0 - - - - - - Stefan Schroeder - stefan.schroeder@jspr.it - - - - - 3.0.4 - - - - scm:git:git@github.com:jsprit/jsprit.git - scm:git:https://github.com/jsprit/jsprit.git - http://github.com/jsprit/jsprit/tree/master - HEAD - - - - github - https://github.com/jsprit/jsprit/issues - - - - - jsprit-snapshots - https://github.com/jsprit/mvn-rep/raw/master/snapshots - - - - jsprit-releases - https://github.com/jsprit/mvn-rep/raw/master/releases - - + + 4.0.0 - - jsprit-core - jsprit-analysis - jsprit-examples - jsprit-instances - - - - 1.6 - UTF-8 - 4.10 - 1.9.5 - 2.0 - false + jsprit + jsprit + 1.6.2-SNAPSHOT - - - - src/main/java - src/test/java - target - target/classes - target/test-classes - ${project.artifactId}-${project.version} - - - src/main/resources - - - - - src/test/resources - - - - - - - org.eclipse.m2e - lifecycle-mapping - 1.0.0 - - - - - - org.apache.maven.plugins - maven-enforcer-plugin - [1.0.0,) - - enforce - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - maven-enforcer-plugin - 1.1.1 - - - enforce-versions - initialize - - enforce - - - true - - + pom + + jsprit + A toolkit to solve vehicle routing problems. + https://github.com/jsprit/jsprit + 2013 + + + + GNU Lesser General Public Licence, version 3.0 + http://opensource.org/licenses/LGPL-3.0 + + + + + + Stefan Schroeder + stefan.schroeder@jspr.it + + + + + 3.0.4 + + + + scm:git:git@github.com:jsprit/jsprit.git + scm:git:https://github.com/jsprit/jsprit.git + http://github.com/jsprit/jsprit/tree/master + HEAD + + + + github + https://github.com/jsprit/jsprit/issues + + + + + jsprit-snapshots + https://github.com/jsprit/mvn-rep/raw/master/snapshots + + + + jsprit-releases + https://github.com/jsprit/mvn-rep/raw/master/releases + + + + + jsprit-core + jsprit-analysis + jsprit-examples + jsprit-instances + + + + 1.6 + UTF-8 + 4.10 + 1.9.5 + 2.0 + false + + + + + src/main/java + src/test/java + target + target/classes + target/test-classes + ${project.artifactId}-${project.version} + + + src/main/resources + + + + + src/test/resources + + + + + + + org.eclipse.m2e + lifecycle-mapping + 1.0.0 + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + [1.0.0,) + + enforce + + + + + + + + + + + + + + + + maven-enforcer-plugin + 1.1.1 + + + enforce-versions + initialize + + enforce + + + true + + Some plugin features require a recent Maven runtime to work properly - Current version of Maven ${maven.version} required to build the project should be ${project.prerequisites.maven}, or higher! - [${project.prerequisites.maven},) - - - Current JDK version ${java.version} should be ${jdkVersion}, or higher! - ${jdkVersion} - - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.1 - - ${jdkVersion} - ${jdkVersion} - true - true - ${project.build.sourceEncoding} - - true - 128m - 512m - - 4000 - 100 - - - - - - org.apache.maven.plugins - maven-eclipse-plugin - 2.8 - - - - org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6 - - - - - - - org.apache.maven.plugins - maven-source-plugin - 2.2.1 - - - attach-sources - - jar - - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - 2.9.1 - - - attach-javadocs - - jar - - - - - - - org.apache.maven.plugins - maven-release-plugin - 2.5 - - v@{project.version} - - + Current version of Maven ${maven.version} required to build the project + should be ${project.prerequisites.maven}, or higher! + + [${project.prerequisites.maven},) + + + Current JDK version ${java.version} should be ${jdkVersion}, or higher! + + ${jdkVersion} + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.1 + + ${jdkVersion} + ${jdkVersion} + true + true + ${project.build.sourceEncoding} + + true + 128m + 512m + + 4000 + 100 + + + + + + org.apache.maven.plugins + maven-eclipse-plugin + 2.8 + + + + org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6 + + + + + + + org.apache.maven.plugins + maven-source-plugin + 2.2.1 + + + attach-sources + + jar + + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.9.1 + + + attach-javadocs + + jar + + + + + + + org.apache.maven.plugins + maven-release-plugin + 2.5 + + v@{project.version} + + - - - - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - 2.9.1 - - - - - - - - - junit - junit - ${junit.version} - test - - - - org.mockito - mockito-all - ${mockito.version} - test - - - - org.apache.logging.log4j - log4j-api - ${logger.version} - - - org.apache.logging.log4j - log4j-core - ${logger.version} - + + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.9.1 + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - + + + junit + junit + ${junit.version} + test + + + + org.mockito + mockito-all + ${mockito.version} + test + + + + org.apache.logging.log4j + log4j-api + ${logger.version} + + + org.apache.logging.log4j + log4j-core + ${logger.version} + + + + + + + + + + + + + + + + + + + + + + + + + + + +

" + date + "" + date + "