From 2361b1d39212cb86f0a714cb2b9803fb86449221 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nico=20K=C3=BChnel?= Date: Mon, 25 Jul 2022 13:08:31 +0200 Subject: [PATCH 1/4] matsim 15.x (#13) * adjust to latest matsim (cherry picked from commit bd67b29d3250208694e480badc098d5ec0910163) * adjust to latest matsim * change to more descriptive variable names --- .../alonso_mora/AlonsoMoraModeQSimModule.java | 47 ++++------------- .../DefaultAlonsoMoraScheduler.java | 9 +++- .../shifts/ShiftAlonsoMoraModule.java | 15 +++--- .../shifts/ShiftAlonsoMoraScheduler.java | 10 ++-- .../alonso_mora/run/AlonsoMoraExamplesIT.java | 51 ++++++++----------- pom.xml | 7 ++- 6 files changed, 57 insertions(+), 82 deletions(-) diff --git a/core/src/main/java/org/matsim/alonso_mora/AlonsoMoraModeQSimModule.java b/core/src/main/java/org/matsim/alonso_mora/AlonsoMoraModeQSimModule.java index 7bae8b5..d1c92a7 100644 --- a/core/src/main/java/org/matsim/alonso_mora/AlonsoMoraModeQSimModule.java +++ b/core/src/main/java/org/matsim/alonso_mora/AlonsoMoraModeQSimModule.java @@ -1,40 +1,17 @@ package org.matsim.alonso_mora; -import static org.matsim.contrib.dvrp.path.VrpPaths.FIRST_LINK_TT; - -import java.io.File; - -import org.matsim.alonso_mora.AlonsoMoraConfigGroup.CbcMpsAssignmentParameters; -import org.matsim.alonso_mora.AlonsoMoraConfigGroup.CbcMpsRelocationParameters; -import org.matsim.alonso_mora.AlonsoMoraConfigGroup.CongestionMitigationParameters; -import org.matsim.alonso_mora.AlonsoMoraConfigGroup.EuclideanEstimatorParameters; -import org.matsim.alonso_mora.AlonsoMoraConfigGroup.GlpkMpsAssignmentParameters; -import org.matsim.alonso_mora.AlonsoMoraConfigGroup.GlpkMpsRelocationParameters; -import org.matsim.alonso_mora.AlonsoMoraConfigGroup.HybridEstimatorParameters; -import org.matsim.alonso_mora.AlonsoMoraConfigGroup.MatrixEstimatorParameters; -import org.matsim.alonso_mora.AlonsoMoraConfigGroup.RoutingEstimatorParameters; -import org.matsim.alonso_mora.algorithm.AlonsoMoraAlgorithm; +import com.google.inject.Singleton; +import org.matsim.alonso_mora.AlonsoMoraConfigGroup.*; +import org.matsim.alonso_mora.algorithm.*; import org.matsim.alonso_mora.algorithm.AlonsoMoraAlgorithm.AlgorithmSettings; -import org.matsim.alonso_mora.algorithm.AlonsoMoraRequestFactory; -import org.matsim.alonso_mora.algorithm.AlonsoMoraVehicleFactory; -import org.matsim.alonso_mora.algorithm.DefaultAlonsoMoraRequestFactory; -import org.matsim.alonso_mora.algorithm.DefaultAlonsoMoraVehicle; -import org.matsim.alonso_mora.algorithm.assignment.AssignmentSolver; -import org.matsim.alonso_mora.algorithm.assignment.CbcMpsAssignmentSolver; -import org.matsim.alonso_mora.algorithm.assignment.GlpkMpsAssignmentSolver; -import org.matsim.alonso_mora.algorithm.assignment.GreedyTripFirstSolver; -import org.matsim.alonso_mora.algorithm.assignment.GreedyVehicleFirstSolver; +import org.matsim.alonso_mora.algorithm.assignment.*; import org.matsim.alonso_mora.algorithm.function.AlonsoMoraFunction; import org.matsim.alonso_mora.algorithm.function.DefaultAlonsoMoraFunction; import org.matsim.alonso_mora.algorithm.function.DefaultAlonsoMoraFunction.Constraint; import org.matsim.alonso_mora.algorithm.function.DefaultAlonsoMoraFunction.MinimumDelay; import org.matsim.alonso_mora.algorithm.function.DefaultAlonsoMoraFunction.NoopConstraint; import org.matsim.alonso_mora.algorithm.function.DefaultAlonsoMoraFunction.Objective; -import org.matsim.alonso_mora.algorithm.function.sequence.CombinedSequenceGenerator; -import org.matsim.alonso_mora.algorithm.function.sequence.EuclideanSequenceGenerator; -import org.matsim.alonso_mora.algorithm.function.sequence.ExtensiveSequenceGenerator; -import org.matsim.alonso_mora.algorithm.function.sequence.InsertiveSequenceGenerator; -import org.matsim.alonso_mora.algorithm.function.sequence.SequenceGeneratorFactory; +import org.matsim.alonso_mora.algorithm.function.sequence.*; import org.matsim.alonso_mora.algorithm.relocation.BestResponseRelocationSolver; import org.matsim.alonso_mora.algorithm.relocation.CbcMpsRelocationSolver; import org.matsim.alonso_mora.algorithm.relocation.GlpkMpsRelocationSolver; @@ -45,13 +22,7 @@ import org.matsim.alonso_mora.scheduling.DefaultAlonsoMoraScheduler.OperationalVoter; import org.matsim.alonso_mora.scheduling.ParallelLeastCostPathCalculator; import org.matsim.alonso_mora.scheduling.StandardRebalancer; -import org.matsim.alonso_mora.travel_time.DrtDetourTravelTimeEstimator; -import org.matsim.alonso_mora.travel_time.EuclideanTravelTimeEstimator; -import org.matsim.alonso_mora.travel_time.HybridTravelTimeEstimator; -import org.matsim.alonso_mora.travel_time.LazyMatrixTravelTimeEstimator; -import org.matsim.alonso_mora.travel_time.MatrixTravelTimeEstimator; -import org.matsim.alonso_mora.travel_time.RoutingTravelTimeEstimator; -import org.matsim.alonso_mora.travel_time.TravelTimeEstimator; +import org.matsim.alonso_mora.travel_time.*; import org.matsim.api.core.v01.network.Network; import org.matsim.contrib.drt.optimizer.DrtOptimizer; import org.matsim.contrib.drt.optimizer.QSimScopeForkJoinPoolHolder; @@ -76,7 +47,9 @@ import org.matsim.core.router.util.LeastCostPathCalculatorFactory; import org.matsim.core.router.util.TravelTime; -import com.google.inject.Singleton; +import java.io.File; + +import static org.matsim.contrib.dvrp.path.VrpPaths.FIRST_LINK_TT; /** * Registers all components for the Alonso-Mora dispatcher in the MATSim QSim @@ -332,7 +305,7 @@ protected void configureQSim() { bindModal(Constraint.class).toInstance(new NoopConstraint()); bindModal(StayTaskEndTimeCalculator.class).toProvider(modalProvider(getter -> { - return new DrtStayTaskEndTimeCalculator(drtConfig); + return new DrtStayTaskEndTimeCalculator((dvrpVehicle, dropOffRequests, pickupRequests) -> drtConfig.getStopDuration()); })); bindModal(AlonsoMoraScheduler.class).toProvider(modalProvider(getter -> { diff --git a/core/src/main/java/org/matsim/alonso_mora/scheduling/DefaultAlonsoMoraScheduler.java b/core/src/main/java/org/matsim/alonso_mora/scheduling/DefaultAlonsoMoraScheduler.java index 76d4ca6..680e675 100644 --- a/core/src/main/java/org/matsim/alonso_mora/scheduling/DefaultAlonsoMoraScheduler.java +++ b/core/src/main/java/org/matsim/alonso_mora/scheduling/DefaultAlonsoMoraScheduler.java @@ -13,6 +13,7 @@ import org.matsim.api.core.v01.network.Link; import org.matsim.api.core.v01.network.Network; import org.matsim.contrib.drt.extension.shifts.schedule.WaitForShiftStayTask; +import org.matsim.contrib.drt.passenger.AcceptedDrtRequest; import org.matsim.contrib.drt.passenger.DrtRequest; import org.matsim.contrib.drt.schedule.DrtDriveTask; import org.matsim.contrib.drt.schedule.DrtStayTask; @@ -288,7 +289,9 @@ public void schedule(AlonsoMoraVehicle vehicle, double now) { // Add requests to the stop task if (stop.getType().equals(StopType.Pickup)) { - stop.getRequest().getDrtRequests().forEach(stopTask::addPickupRequest); + for (DrtRequest drtRequest : stop.getRequest().getDrtRequests()) { + stopTask.addPickupRequest(AcceptedDrtRequest.createFromOriginalRequest(drtRequest)); + } stop.getRequest().setPickupTask(vehicle, stopTask); if (checkDeterminsticTravelTimes) { @@ -298,7 +301,9 @@ public void schedule(AlonsoMoraVehicle vehicle, double now) { "Checking for determinstic travel times and found mismatch between expected stop time and planned stop time."); } } else if (stop.getType().equals(StopType.Dropoff)) { - stop.getRequest().getDrtRequests().forEach(stopTask::addDropoffRequest); + for (DrtRequest drtRequest : stop.getRequest().getDrtRequests()) { + stopTask.addDropoffRequest(AcceptedDrtRequest.createFromOriginalRequest(drtRequest)); + } stop.getRequest().setDropoffTask(vehicle, stopTask); if (checkDeterminsticTravelTimes) { diff --git a/core/src/main/java/org/matsim/alonso_mora/shifts/ShiftAlonsoMoraModule.java b/core/src/main/java/org/matsim/alonso_mora/shifts/ShiftAlonsoMoraModule.java index 8266962..be07f45 100644 --- a/core/src/main/java/org/matsim/alonso_mora/shifts/ShiftAlonsoMoraModule.java +++ b/core/src/main/java/org/matsim/alonso_mora/shifts/ShiftAlonsoMoraModule.java @@ -8,12 +8,11 @@ import org.matsim.alonso_mora.scheduling.DefaultAlonsoMoraScheduler.OperationalVoter; import org.matsim.alonso_mora.travel_time.TravelTimeEstimator; import org.matsim.api.core.v01.network.Network; -import org.matsim.contrib.drt.extension.shifts.config.ShiftDrtConfigGroup; +import org.matsim.contrib.drt.extension.shifts.config.DrtWithShiftsConfigGroup; import org.matsim.contrib.drt.extension.shifts.dispatcher.DrtShiftDispatcher; import org.matsim.contrib.drt.extension.shifts.optimizer.ShiftDrtOptimizer; import org.matsim.contrib.drt.extension.shifts.schedule.ShiftDrtStayTaskEndTimeCalculator; import org.matsim.contrib.drt.optimizer.DrtOptimizer; -import org.matsim.contrib.drt.run.DrtConfigGroup; import org.matsim.contrib.drt.schedule.DrtStayTaskEndTimeCalculator; import org.matsim.contrib.drt.schedule.DrtTaskFactory; import org.matsim.contrib.dvrp.run.AbstractDvrpModeQSimModule; @@ -23,14 +22,12 @@ import org.matsim.core.router.util.TravelTime; public class ShiftAlonsoMoraModule extends AbstractDvrpModeQSimModule { - private final DrtConfigGroup drtConfig; - private final ShiftDrtConfigGroup shiftConfig; + private final DrtWithShiftsConfigGroup drtConfig; private final AlonsoMoraConfigGroup amConfig; - public ShiftAlonsoMoraModule(DrtConfigGroup drtConfig, ShiftDrtConfigGroup shiftConfig, AlonsoMoraConfigGroup amConfig) { + public ShiftAlonsoMoraModule(DrtWithShiftsConfigGroup drtConfig, AlonsoMoraConfigGroup amConfig) { super(drtConfig.getMode()); this.drtConfig = drtConfig; - this.shiftConfig = shiftConfig; this.amConfig = amConfig; } @@ -41,9 +38,9 @@ protected void configureQSim() { })); // TODO: This can become a general binding in DRT - bindModal(StayTaskEndTimeCalculator.class).toProvider(modalProvider(getter -> { - return new ShiftDrtStayTaskEndTimeCalculator(shiftConfig, new DrtStayTaskEndTimeCalculator(drtConfig)); - })); + bindModal(StayTaskEndTimeCalculator.class).toProvider(modalProvider(getter -> + new ShiftDrtStayTaskEndTimeCalculator(drtConfig.getDrtShiftParams(), + new DrtStayTaskEndTimeCalculator((dvrpVehicle, dropoffRequests, pickupRequests) -> drtConfig.getStopDuration())))); bindModal(OperationalVoter.class).toProvider(modalProvider(getter -> { return new ShiftOperationalVoter(); diff --git a/core/src/main/java/org/matsim/alonso_mora/shifts/ShiftAlonsoMoraScheduler.java b/core/src/main/java/org/matsim/alonso_mora/shifts/ShiftAlonsoMoraScheduler.java index 2bb1ada..ca92c3c 100644 --- a/core/src/main/java/org/matsim/alonso_mora/shifts/ShiftAlonsoMoraScheduler.java +++ b/core/src/main/java/org/matsim/alonso_mora/shifts/ShiftAlonsoMoraScheduler.java @@ -17,6 +17,7 @@ import org.matsim.contrib.drt.extension.shifts.schedule.ShiftBreakTask; import org.matsim.contrib.drt.extension.shifts.schedule.ShiftChangeOverTask; import org.matsim.contrib.drt.extension.shifts.schedule.WaitForShiftStayTask; +import org.matsim.contrib.drt.passenger.AcceptedDrtRequest; import org.matsim.contrib.drt.passenger.DrtRequest; import org.matsim.contrib.drt.schedule.DrtDriveTask; import org.matsim.contrib.drt.schedule.DrtStayTask; @@ -292,8 +293,9 @@ public void schedule(AlonsoMoraVehicle vehicle, double now) { // Add requests to the stop task if (stop.getType().equals(StopType.Pickup)) { - stop.getRequest().getDrtRequests().forEach(stopTask::addPickupRequest); - stop.getRequest().setPickupTask(vehicle, stopTask); + for (DrtRequest drtRequest : stop.getRequest().getDrtRequests()) { + stopTask.addPickupRequest(AcceptedDrtRequest.createFromOriginalRequest(drtRequest)); + } stop.getRequest().setPickupTask(vehicle, stopTask); if (checkDeterminsticTravelTimes) { Verify.verify(stop.getTime() == stopTask.getEndTime(), @@ -302,7 +304,9 @@ public void schedule(AlonsoMoraVehicle vehicle, double now) { "Checking for determinstic travel times and found mismatch between expected stop time and planned stop time."); } } else if (stop.getType().equals(StopType.Dropoff)) { - stop.getRequest().getDrtRequests().forEach(stopTask::addDropoffRequest); + for (DrtRequest drtRequest : stop.getRequest().getDrtRequests()) { + stopTask.addDropoffRequest(AcceptedDrtRequest.createFromOriginalRequest(drtRequest)); + } stop.getRequest().setDropoffTask(vehicle, stopTask); if (checkDeterminsticTravelTimes) { diff --git a/core/src/test/java/org/matsim/alonso_mora/run/AlonsoMoraExamplesIT.java b/core/src/test/java/org/matsim/alonso_mora/run/AlonsoMoraExamplesIT.java index da8a21c..748c1e0 100644 --- a/core/src/test/java/org/matsim/alonso_mora/run/AlonsoMoraExamplesIT.java +++ b/core/src/test/java/org/matsim/alonso_mora/run/AlonsoMoraExamplesIT.java @@ -19,19 +19,6 @@ package org.matsim.alonso_mora.run; -import static org.assertj.core.api.Assertions.assertThat; - -import java.io.IOException; -import java.net.URL; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Random; -import java.util.stream.Collectors; - import org.assertj.core.data.Percentage; import org.junit.Rule; import org.junit.Test; @@ -42,20 +29,13 @@ import org.matsim.api.core.v01.Id; import org.matsim.api.core.v01.Scenario; import org.matsim.api.core.v01.network.Link; -import org.matsim.contrib.drt.extension.shifts.config.ShiftDrtConfigGroup; -import org.matsim.contrib.drt.extension.shifts.operationFacilities.OperationFacilitiesSpecification; -import org.matsim.contrib.drt.extension.shifts.operationFacilities.OperationFacilitiesSpecificationImpl; -import org.matsim.contrib.drt.extension.shifts.operationFacilities.OperationFacility; -import org.matsim.contrib.drt.extension.shifts.operationFacilities.OperationFacilitySpecificationImpl; -import org.matsim.contrib.drt.extension.shifts.operationFacilities.OperationFacilityType; +import org.matsim.contrib.drt.extension.shifts.config.DrtShiftParams; +import org.matsim.contrib.drt.extension.shifts.config.DrtWithShiftsConfigGroup; +import org.matsim.contrib.drt.extension.shifts.operationFacilities.*; import org.matsim.contrib.drt.extension.shifts.run.ShiftDrtModeModule; import org.matsim.contrib.drt.extension.shifts.run.ShiftDrtModeOptimizerQSimModule; import org.matsim.contrib.drt.extension.shifts.run.ShiftDvrpFleetQsimModule; -import org.matsim.contrib.drt.extension.shifts.shift.DrtShift; -import org.matsim.contrib.drt.extension.shifts.shift.DrtShiftBreakSpecificationImpl; -import org.matsim.contrib.drt.extension.shifts.shift.DrtShiftSpecificationImpl; -import org.matsim.contrib.drt.extension.shifts.shift.DrtShiftsSpecification; -import org.matsim.contrib.drt.extension.shifts.shift.DrtShiftsSpecificationImpl; +import org.matsim.contrib.drt.extension.shifts.shift.*; import org.matsim.contrib.drt.routing.DrtRoute; import org.matsim.contrib.drt.routing.DrtRouteFactory; import org.matsim.contrib.drt.run.DrtConfigGroup; @@ -67,6 +47,7 @@ import org.matsim.contrib.dvrp.run.DvrpModule; import org.matsim.contrib.dvrp.run.DvrpQSimComponents; import org.matsim.core.config.Config; +import org.matsim.core.config.ConfigGroup; import org.matsim.core.config.ConfigUtils; import org.matsim.core.controler.Controler; import org.matsim.core.controler.OutputDirectoryHierarchy.OverwriteFileSetting; @@ -76,6 +57,15 @@ import org.matsim.testcases.MatsimTestUtils; import org.matsim.vis.otfvis.OTFVisConfigGroup; +import java.io.IOException; +import java.net.URL; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.*; +import java.util.stream.Collectors; + +import static org.assertj.core.api.Assertions.assertThat; + /** * @author sebhoerl */ @@ -132,20 +122,21 @@ public void testRunAlonsoMora() { public void testRunAlonsoMoraWithShifts() { Id.resetCaches(); URL configUrl = IOUtils.extendUrl(ExamplesUtils.getTestScenarioURL("mielec"), "mielec_drt_config.xml"); - Config config = ConfigUtils.loadConfig(configUrl, new MultiModeDrtConfigGroup(), new DvrpConfigGroup(), + Config config = ConfigUtils.loadConfig(configUrl, new MultiModeDrtConfigGroup(DrtWithShiftsConfigGroup::new), new DvrpConfigGroup(), new MultiModeAlonsoMoraConfigGroup(), new OTFVisConfigGroup()); AlonsoMoraConfigGroup amConfig = new AlonsoMoraConfigGroup(); MultiModeAlonsoMoraConfigGroup.get(config).addParameterSet(amConfig); - ShiftDrtConfigGroup shiftDrtConfigGroup = ConfigUtils.addOrGetModule(config, ShiftDrtConfigGroup.class); config.controler().setOverwriteFileSetting(OverwriteFileSetting.deleteDirectoryIfExists); config.controler().setOutputDirectory(utils.getOutputDirectory()); // Remove DRT rebalancer as we want to use AM rebalancer - DrtConfigGroup drtConfig = MultiModeDrtConfigGroup.get(config).getModalElements().iterator().next(); + DrtWithShiftsConfigGroup drtConfig = (DrtWithShiftsConfigGroup) MultiModeDrtConfigGroup.get(config).getModalElements().iterator().next(); drtConfig.removeParameterSet(drtConfig.getRebalancingParams().get()); + ConfigGroup shiftParams = drtConfig.createParameterSet(DrtShiftParams.SET_NAME); + drtConfig.addParameterSet(shiftParams); // Load scenario Scenario scenario = ScenarioUtils.createScenario(config); @@ -221,8 +212,8 @@ public void testRunAlonsoMoraWithShifts() { controller.configureQSimComponents(DvrpQSimComponents.activateAllModes(MultiModeDrtConfigGroup.get(config))); for (DrtConfigGroup drtCfg : MultiModeDrtConfigGroup.get(config).getModalElements()) { - controller.addOverridingModule(new ShiftDrtModeModule(drtCfg, shiftDrtConfigGroup)); - controller.addOverridingQSimModule(new DrtModeQSimModule(drtCfg, new ShiftDrtModeOptimizerQSimModule(drtCfg, shiftDrtConfigGroup))); + controller.addOverridingModule(new ShiftDrtModeModule(drtCfg)); + controller.addOverridingQSimModule(new DrtModeQSimModule(drtCfg, new ShiftDrtModeOptimizerQSimModule(drtCfg))); controller.addOverridingQSimModule(new ShiftDvrpFleetQsimModule(drtCfg.getMode())); } @@ -235,7 +226,7 @@ public void install() { }); AlonsoMoraConfigurator.configure(controller, amConfig.getMode()); - controller.addOverridingQSimModule(new ShiftAlonsoMoraModule(drtConfig, shiftDrtConfigGroup, amConfig)); + controller.addOverridingQSimModule(new ShiftAlonsoMoraModule((DrtWithShiftsConfigGroup) drtConfig, amConfig)); controller.run(); var expectedStats = Stats.newBuilder() // diff --git a/pom.xml b/pom.xml index 468b390..926f47e 100644 --- a/pom.xml +++ b/pom.xml @@ -16,7 +16,7 @@ to the MATSim framework. 11 11 - 14.0 + 15.0-SNAPSHOT @@ -75,6 +75,11 @@ to the MATSim framework. drt ${matsim.version} + + org.matsim.contrib + drt-extensions + ${matsim.version} + org.matsim.contrib dvrp From ade832b8a81dbf8c2430af6be7d5ed72bf9378bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nico=20K=C3=BChnel?= Date: Tue, 6 Sep 2022 16:29:39 +0200 Subject: [PATCH 2/4] fix: Fix determinisim for MPS solvers (#16) (#17) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Sebastian Hörl --- .../alonso_mora/algorithm/assignment/MpsAssignmentWriter.java | 4 ++-- .../org/matsim/alonso_mora/gurobi/CplexAssignmentSolver.java | 4 ++-- .../org/matsim/alonso_mora/glpk/GlpkJniAssignmentSolver.java | 4 ++-- .../org/matsim/alonso_mora/gurobi/GurobiAssignmentSolver.java | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/org/matsim/alonso_mora/algorithm/assignment/MpsAssignmentWriter.java b/core/src/main/java/org/matsim/alonso_mora/algorithm/assignment/MpsAssignmentWriter.java index 584b016..8572fae 100644 --- a/core/src/main/java/org/matsim/alonso_mora/algorithm/assignment/MpsAssignmentWriter.java +++ b/core/src/main/java/org/matsim/alonso_mora/algorithm/assignment/MpsAssignmentWriter.java @@ -33,9 +33,9 @@ public MpsAssignmentWriter(List tripList, double unassignmentPen public void write(File path) throws IOException { List requestList = new ArrayList<>( - tripList.stream().flatMap(t -> t.getRequests().stream()).collect(Collectors.toSet())); + tripList.stream().flatMap(t -> t.getRequests().stream()).distinct().collect(Collectors.toList())); List vehicleList = new ArrayList<>( - tripList.stream().map(t -> t.getVehicle()).collect(Collectors.toSet())); + tripList.stream().map(t -> t.getVehicle()).distinct().collect(Collectors.toList())); int numberOfRequests = requestList.size(); int numberOfTrips = tripList.size(); diff --git a/cplex/src/main/java/org/matsim/alonso_mora/gurobi/CplexAssignmentSolver.java b/cplex/src/main/java/org/matsim/alonso_mora/gurobi/CplexAssignmentSolver.java index 88ca44f..6501232 100644 --- a/cplex/src/main/java/org/matsim/alonso_mora/gurobi/CplexAssignmentSolver.java +++ b/cplex/src/main/java/org/matsim/alonso_mora/gurobi/CplexAssignmentSolver.java @@ -53,9 +53,9 @@ public CplexAssignmentSolver(double unassignmentPenalty, double rejectionPenalty public Solution solve(Stream candidates) { List tripList = candidates.collect(Collectors.toList()); List requestList = new ArrayList<>( - tripList.stream().flatMap(t -> t.getRequests().stream()).collect(Collectors.toSet())); + tripList.stream().flatMap(t -> t.getRequests().stream()).distinct().collect(Collectors.toList())); List vehicleList = new ArrayList<>( - tripList.stream().map(t -> t.getVehicle()).collect(Collectors.toSet())); + tripList.stream().map(t -> t.getVehicle()).distinct().collect(Collectors.toList())); if (requestList.size() == 0) { return new Solution(Status.OPTIMAL, Collections.emptySet()); diff --git a/glpk/src/main/java/org/matsim/alonso_mora/glpk/GlpkJniAssignmentSolver.java b/glpk/src/main/java/org/matsim/alonso_mora/glpk/GlpkJniAssignmentSolver.java index e4dc0a5..32ddb58 100644 --- a/glpk/src/main/java/org/matsim/alonso_mora/glpk/GlpkJniAssignmentSolver.java +++ b/glpk/src/main/java/org/matsim/alonso_mora/glpk/GlpkJniAssignmentSolver.java @@ -54,9 +54,9 @@ public Solution solve(Stream candidates) { List tripList = candidates.collect(Collectors.toList()); List requestList = new ArrayList<>( - tripList.stream().flatMap(t -> t.getRequests().stream()).collect(Collectors.toSet())); + tripList.stream().flatMap(t -> t.getRequests().stream()).distinct().collect(Collectors.toList())); List vehicleList = new ArrayList<>( - tripList.stream().map(t -> t.getVehicle()).collect(Collectors.toSet())); + tripList.stream().map(t -> t.getVehicle()).distinct().collect(Collectors.toList())); int numberOfRequests = requestList.size(); int numberOfTrips = tripList.size(); diff --git a/gurobi/src/main/java/org/matsim/alonso_mora/gurobi/GurobiAssignmentSolver.java b/gurobi/src/main/java/org/matsim/alonso_mora/gurobi/GurobiAssignmentSolver.java index 7f466ea..cd259c9 100644 --- a/gurobi/src/main/java/org/matsim/alonso_mora/gurobi/GurobiAssignmentSolver.java +++ b/gurobi/src/main/java/org/matsim/alonso_mora/gurobi/GurobiAssignmentSolver.java @@ -55,9 +55,9 @@ public GurobiAssignmentSolver(double unassignmentPenalty, double rejectionPenalt public Solution solve(Stream candidates) { List tripList = candidates.collect(Collectors.toList()); List requestList = new ArrayList<>( - tripList.stream().flatMap(t -> t.getRequests().stream()).collect(Collectors.toSet())); + tripList.stream().flatMap(t -> t.getRequests().stream()).distinct().collect(Collectors.toList())); List vehicleList = new ArrayList<>( - tripList.stream().map(t -> t.getVehicle()).collect(Collectors.toSet())); + tripList.stream().map(t -> t.getVehicle()).distinct().collect(Collectors.toList())); if (requestList.size() == 0) { return new Solution(Status.OPTIMAL, Collections.emptySet()); From 91042dfe1b5092cb0cf139657b6257ab56fc4345 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nico=20K=C3=BChnel?= Date: Thu, 22 Sep 2022 18:02:01 +0200 Subject: [PATCH 3/4] update to latest matsim 15.xx (#24) --- .github/workflows/tests.yml | 4 ++-- .../matsim/alonso_mora/algorithm/AlonsoMoraAlgorithm.java | 5 +++-- .../algorithm/assignment/CbcMpsAssignmentSolver.java | 5 +++-- .../algorithm/assignment/GlpkMpsAssignmentSolver.java | 5 +++-- .../algorithm/relocation/CbcMpsRelocationSolver.java | 5 +++-- .../algorithm/relocation/GlpkMpsRelocationSolver.java | 5 +++-- .../matsim/alonso_mora/example/CalculateTravelTimes.java | 5 +++-- .../matsim/alonso_mora/shifts/ShiftAlonsoMoraModule.java | 7 ++++--- .../matsim/alonso_mora/glpk/GlpkJniAssignmentSolver.java | 5 +++-- .../matsim/alonso_mora/glpk/GlpkJniRelocationSolver.java | 5 +++-- 10 files changed, 30 insertions(+), 21 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index ed6e6fd..253882b 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -12,10 +12,10 @@ jobs: steps: - uses: actions/checkout@v2 - - name: Set up JDK 11 + - name: Set up JDK 17 uses: actions/setup-java@v1 with: - java-version: 11 + java-version: 17 - name: Install GLPK and CBC run: sudo apt install glpk-utils coinor-cbc libglpk-java - name: Run tests diff --git a/core/src/main/java/org/matsim/alonso_mora/algorithm/AlonsoMoraAlgorithm.java b/core/src/main/java/org/matsim/alonso_mora/algorithm/AlonsoMoraAlgorithm.java index c5cf057..9851d7b 100644 --- a/core/src/main/java/org/matsim/alonso_mora/algorithm/AlonsoMoraAlgorithm.java +++ b/core/src/main/java/org/matsim/alonso_mora/algorithm/AlonsoMoraAlgorithm.java @@ -18,7 +18,8 @@ import java.util.stream.Stream; import org.apache.commons.lang3.tuple.Pair; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.matsim.alonso_mora.AlonsoMoraConfigGroup; import org.matsim.alonso_mora.AlonsoMoraSubmissionEvent; import org.matsim.alonso_mora.algorithm.AlonsoMoraStop.StopType; @@ -65,7 +66,7 @@ * */ public class AlonsoMoraAlgorithm { - private final Logger logger = Logger.getLogger(AlonsoMoraAlgorithm.class); + private final Logger logger = LogManager.getLogger(AlonsoMoraAlgorithm.class); private RequestGraph requestGraph; private final AssignmentSolver assignmentSolver; diff --git a/core/src/main/java/org/matsim/alonso_mora/algorithm/assignment/CbcMpsAssignmentSolver.java b/core/src/main/java/org/matsim/alonso_mora/algorithm/assignment/CbcMpsAssignmentSolver.java index a949d46..611feaa 100644 --- a/core/src/main/java/org/matsim/alonso_mora/algorithm/assignment/CbcMpsAssignmentSolver.java +++ b/core/src/main/java/org/matsim/alonso_mora/algorithm/assignment/CbcMpsAssignmentSolver.java @@ -13,7 +13,8 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.matsim.alonso_mora.algorithm.AlonsoMoraTrip; import org.matsim.alonso_mora.algorithm.assignment.AssignmentSolver.Solution.Status; @@ -27,7 +28,7 @@ public class CbcMpsAssignmentSolver implements AssignmentSolver { static public final String TYPE = "CbcMps"; - private final static Logger logger = Logger.getLogger(CbcMpsAssignmentSolver.class); + private final static Logger logger = LogManager.getLogger(CbcMpsAssignmentSolver.class); private final double rejectionPenalty; private final double unassignmentPenalty; diff --git a/core/src/main/java/org/matsim/alonso_mora/algorithm/assignment/GlpkMpsAssignmentSolver.java b/core/src/main/java/org/matsim/alonso_mora/algorithm/assignment/GlpkMpsAssignmentSolver.java index bd9f9fd..c33c47e 100644 --- a/core/src/main/java/org/matsim/alonso_mora/algorithm/assignment/GlpkMpsAssignmentSolver.java +++ b/core/src/main/java/org/matsim/alonso_mora/algorithm/assignment/GlpkMpsAssignmentSolver.java @@ -13,7 +13,8 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.matsim.alonso_mora.algorithm.AlonsoMoraTrip; import org.matsim.alonso_mora.algorithm.assignment.AssignmentSolver.Solution.Status; @@ -27,7 +28,7 @@ public class GlpkMpsAssignmentSolver implements AssignmentSolver { static public final String TYPE = "GlpkMps"; - private static final Logger logger = Logger.getLogger(GlpkMpsAssignmentSolver.class); + private static final Logger logger = LogManager.getLogger(GlpkMpsAssignmentSolver.class); private final double unassignmentPenalty; private final double rejectionPenalty; diff --git a/core/src/main/java/org/matsim/alonso_mora/algorithm/relocation/CbcMpsRelocationSolver.java b/core/src/main/java/org/matsim/alonso_mora/algorithm/relocation/CbcMpsRelocationSolver.java index 73ff7df..e8d4949 100644 --- a/core/src/main/java/org/matsim/alonso_mora/algorithm/relocation/CbcMpsRelocationSolver.java +++ b/core/src/main/java/org/matsim/alonso_mora/algorithm/relocation/CbcMpsRelocationSolver.java @@ -12,7 +12,8 @@ import java.util.LinkedList; import java.util.List; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; /** * Solves the relocation problem as described by Alonso-Mora et al. using the @@ -24,7 +25,7 @@ public class CbcMpsRelocationSolver implements RelocationSolver { static public final String TYPE = "CbcMps"; - private final static Logger logger = Logger.getLogger(CbcMpsRelocationSolver.class); + private final static Logger logger = LogManager.getLogger(CbcMpsRelocationSolver.class); private final File problemPath; private final File solutionPath; diff --git a/core/src/main/java/org/matsim/alonso_mora/algorithm/relocation/GlpkMpsRelocationSolver.java b/core/src/main/java/org/matsim/alonso_mora/algorithm/relocation/GlpkMpsRelocationSolver.java index 9096586..d2638a8 100644 --- a/core/src/main/java/org/matsim/alonso_mora/algorithm/relocation/GlpkMpsRelocationSolver.java +++ b/core/src/main/java/org/matsim/alonso_mora/algorithm/relocation/GlpkMpsRelocationSolver.java @@ -12,7 +12,8 @@ import java.util.LinkedList; import java.util.List; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.matsim.alonso_mora.algorithm.assignment.GlpkMpsAssignmentSolver; /** @@ -25,7 +26,7 @@ public class GlpkMpsRelocationSolver implements RelocationSolver { static public final String TYPE = "GlpkMps"; - private static final Logger logger = Logger.getLogger(GlpkMpsRelocationSolver.class); + private static final Logger logger = LogManager.getLogger(GlpkMpsRelocationSolver.class); private final File problemPath; private final File solutionPath; diff --git a/core/src/main/java/org/matsim/alonso_mora/example/CalculateTravelTimes.java b/core/src/main/java/org/matsim/alonso_mora/example/CalculateTravelTimes.java index 3516ced..eb69103 100644 --- a/core/src/main/java/org/matsim/alonso_mora/example/CalculateTravelTimes.java +++ b/core/src/main/java/org/matsim/alonso_mora/example/CalculateTravelTimes.java @@ -16,7 +16,8 @@ import java.util.concurrent.atomic.AtomicLong; import java.util.stream.Collectors; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.matsim.api.core.v01.Scenario; import org.matsim.api.core.v01.network.Link; import org.matsim.api.core.v01.network.Network; @@ -41,7 +42,7 @@ import org.matsim.core.trafficmonitoring.FreeSpeedTravelTime; public class CalculateTravelTimes { - private final static Logger logger = Logger.getLogger(CalculateTravelTimes.class); + private final static Logger logger = LogManager.getLogger(CalculateTravelTimes.class); static public void main(String[] args) throws ConfigurationException { CommandLine cmd = new CommandLine.Builder(args) // diff --git a/core/src/main/java/org/matsim/alonso_mora/shifts/ShiftAlonsoMoraModule.java b/core/src/main/java/org/matsim/alonso_mora/shifts/ShiftAlonsoMoraModule.java index be07f45..64ddc0b 100644 --- a/core/src/main/java/org/matsim/alonso_mora/shifts/ShiftAlonsoMoraModule.java +++ b/core/src/main/java/org/matsim/alonso_mora/shifts/ShiftAlonsoMoraModule.java @@ -38,9 +38,10 @@ protected void configureQSim() { })); // TODO: This can become a general binding in DRT - bindModal(StayTaskEndTimeCalculator.class).toProvider(modalProvider(getter -> - new ShiftDrtStayTaskEndTimeCalculator(drtConfig.getDrtShiftParams(), - new DrtStayTaskEndTimeCalculator((dvrpVehicle, dropoffRequests, pickupRequests) -> drtConfig.getStopDuration())))); + bindModal(StayTaskEndTimeCalculator.class).toProvider(modalProvider(getter -> { + return new ShiftDrtStayTaskEndTimeCalculator(drtConfig.getDrtShiftParams(), + new DrtStayTaskEndTimeCalculator((dvrpVehicle, dropoffRequests, pickupRequests) -> drtConfig.getStopDuration())); + })); bindModal(OperationalVoter.class).toProvider(modalProvider(getter -> { return new ShiftOperationalVoter(); diff --git a/glpk/src/main/java/org/matsim/alonso_mora/glpk/GlpkJniAssignmentSolver.java b/glpk/src/main/java/org/matsim/alonso_mora/glpk/GlpkJniAssignmentSolver.java index 32ddb58..d493427 100644 --- a/glpk/src/main/java/org/matsim/alonso_mora/glpk/GlpkJniAssignmentSolver.java +++ b/glpk/src/main/java/org/matsim/alonso_mora/glpk/GlpkJniAssignmentSolver.java @@ -10,7 +10,8 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.gnu.glpk.GLPK; import org.gnu.glpk.GLPKConstants; import org.gnu.glpk.SWIGTYPE_p_double; @@ -32,7 +33,7 @@ public class GlpkJniAssignmentSolver implements AssignmentSolver { static public final String TYPE = "GlpkJni"; - private static final Logger logger = Logger.getLogger(GlpkJniAssignmentSolver.class); + private static final Logger logger = LogManager.getLogger(GlpkJniAssignmentSolver.class); private final double unassignmentPenalty; private final double rejectionPenalty; diff --git a/glpk/src/main/java/org/matsim/alonso_mora/glpk/GlpkJniRelocationSolver.java b/glpk/src/main/java/org/matsim/alonso_mora/glpk/GlpkJniRelocationSolver.java index d548809..53c53f1 100644 --- a/glpk/src/main/java/org/matsim/alonso_mora/glpk/GlpkJniRelocationSolver.java +++ b/glpk/src/main/java/org/matsim/alonso_mora/glpk/GlpkJniRelocationSolver.java @@ -7,7 +7,8 @@ import java.util.List; import java.util.stream.Collectors; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.gnu.glpk.GLPK; import org.gnu.glpk.GLPKConstants; import org.gnu.glpk.SWIGTYPE_p_double; @@ -26,7 +27,7 @@ public class GlpkJniRelocationSolver implements RelocationSolver { static public final String TYPE = "GlpkJni"; - private static final Logger logger = Logger.getLogger(GlpkJniRelocationSolver.class); + private static final Logger logger = LogManager.getLogger(GlpkJniRelocationSolver.class); @Override public Collection solve(List candidates) { From a0b83c406aa0a092b0071bfb8d18d39d7e395156 Mon Sep 17 00:00:00 2001 From: nkuehnel Date: Wed, 12 Oct 2022 15:43:23 +0200 Subject: [PATCH 4/4] update to latest matsim 15.xx --- .../alonso_mora/AlonsoMoraModeQSimModule.java | 14 +++++----- .../alonso_mora/example/RunNewYork.java | 26 +++++++++---------- .../DefaultAlonsoMoraScheduler.java | 21 ++++++--------- .../shifts/AlonsoMoraShiftConstraint.java | 10 +++---- .../shifts/ShiftAlonsoMoraModule.java | 18 ++++++------- .../shifts/ShiftAlonsoMoraScheduler.java | 25 +++++++----------- .../shifts/ShiftAlonsoMoraVehicle.java | 2 +- .../shifts/ShiftOperationalVoter.java | 8 +++--- .../alonso_mora/run/AlonsoMoraExamplesIT.java | 25 +++++++++--------- pom.xml | 4 +-- 10 files changed, 71 insertions(+), 82 deletions(-) diff --git a/core/src/main/java/org/matsim/alonso_mora/AlonsoMoraModeQSimModule.java b/core/src/main/java/org/matsim/alonso_mora/AlonsoMoraModeQSimModule.java index d1c92a7..e562772 100644 --- a/core/src/main/java/org/matsim/alonso_mora/AlonsoMoraModeQSimModule.java +++ b/core/src/main/java/org/matsim/alonso_mora/AlonsoMoraModeQSimModule.java @@ -192,7 +192,7 @@ protected void configureQSim() { Network network = getter.getModal(Network.class); TravelTime travelTime = getter.getModal(TravelTime.class); - return new ParallelLeastCostPathCalculator(drtConfig.getNumberOfThreads(), factory, network, + return new ParallelLeastCostPathCalculator(drtConfig.numberOfThreads, factory, network, new OnlyTimeDependentTravelDisutility(travelTime), travelTime); })); @@ -295,7 +295,7 @@ protected void configureQSim() { CongestionMitigationParameters congestionParameters = amConfig.getCongestionMitigationParameters(); return new DefaultAlonsoMoraFunction(travelTimeEstimator, sequenceGeneratorFactory, - drtConfig.getStopDuration(), congestionParameters.getAllowPickupViolations(), + drtConfig.stopDuration, congestionParameters.getAllowPickupViolations(), congestionParameters.getAllowPickupsWithDropoffViolations(), amConfig.getCheckDeterminsticTravelTimes(), objective, constraint, amConfig.getViolationFactor(), amConfig.getViolationOffset(), amConfig.getPreferNonViolation()); @@ -305,7 +305,7 @@ protected void configureQSim() { bindModal(Constraint.class).toInstance(new NoopConstraint()); bindModal(StayTaskEndTimeCalculator.class).toProvider(modalProvider(getter -> { - return new DrtStayTaskEndTimeCalculator((dvrpVehicle, dropOffRequests, pickupRequests) -> drtConfig.getStopDuration()); + return new DrtStayTaskEndTimeCalculator((dvrpVehicle, dropOffRequests, pickupRequests) -> drtConfig.stopDuration); })); bindModal(AlonsoMoraScheduler.class).toProvider(modalProvider(getter -> { @@ -318,7 +318,7 @@ protected void configureQSim() { OperationalVoter operationalVoter = getter.getModal(OperationalVoter.class); - return new DefaultAlonsoMoraScheduler(taskFactory, drtConfig.getStopDuration(), + return new DefaultAlonsoMoraScheduler(taskFactory, drtConfig.stopDuration, amConfig.getCheckDeterminsticTravelTimes(), amConfig.getRerouteDuringScheduling(), travelTime, network, endTimeCalculator, router, operationalVoter); })); @@ -329,7 +329,7 @@ protected void configureQSim() { Double rebalancingInterval = null; if (drtConfig.getRebalancingParams().isPresent()) { - rebalancingInterval = (double) drtConfig.getRebalancingParams().get().getInterval(); + rebalancingInterval = (double) drtConfig.getRebalancingParams().get().interval; } return new StandardRebalancer( // @@ -361,7 +361,7 @@ protected void configureQSim() { getter.getModal(AlonsoMoraVehicleFactory.class), // getter.getModal(QSimScopeForkJoinPoolHolder.class).getPool(), // getter.getModal(TravelTimeEstimator.class), // - drtConfig.getStopDuration(), // + drtConfig.stopDuration, // new AlgorithmSettings(amConfig)); })); @@ -381,7 +381,7 @@ protected void configureQSim() { getter.getModal(QSimScopeForkJoinPoolHolder.class).getPool(), // getter.getModal(LeastCostPathCalculator.class), // getter.getModal(TravelTime.class), // - drtConfig.getAdvanceRequestPlanningHorizon(), // + drtConfig.advanceRequestPlanningHorizon, // getter.getModal(InformationCollector.class) // ); })); diff --git a/core/src/main/java/org/matsim/alonso_mora/example/RunNewYork.java b/core/src/main/java/org/matsim/alonso_mora/example/RunNewYork.java index b7f3994..9f98fef 100644 --- a/core/src/main/java/org/matsim/alonso_mora/example/RunNewYork.java +++ b/core/src/main/java/org/matsim/alonso_mora/example/RunNewYork.java @@ -202,19 +202,19 @@ static public void main(String[] args) throws CommandLine.ConfigurationException MultiModeDrtConfigGroup drtConfig = new MultiModeDrtConfigGroup(); config.addModule(drtConfig); - DrtConfigGroup modeConfig = new DrtConfigGroup() // - .setMode(TransportMode.drt) // - .setMaxTravelTimeAlpha(detourFactor) // - .setMaxTravelTimeBeta(stopDuration) // - .setMaxWaitTime(maximumWaitingTime + stopDuration) // - .setStopDuration(stopDuration) // - .setRejectRequestIfMaxWaitOrTravelTimeViolated(true) // - .setUseModeFilteredSubnetwork(false) // - .setIdleVehiclesReturnToDepots(false) // - .setOperationalScheme(DrtConfigGroup.OperationalScheme.door2door) // - .setPlotDetailedCustomerStats(true) // - .setMaxWalkDistance(1000.) // - .setNumberOfThreads(threads); + DrtConfigGroup modeConfig = new DrtConfigGroup(); + modeConfig.mode = TransportMode.drt; + modeConfig.maxTravelTimeAlpha = detourFactor; + modeConfig.maxTravelTimeBeta = stopDuration; + modeConfig.maxWaitTime = maximumWaitingTime + stopDuration; + modeConfig.stopDuration = stopDuration; + modeConfig.rejectRequestIfMaxWaitOrTravelTimeViolated = true; + modeConfig.useModeFilteredSubnetwork = false; + modeConfig.idleVehiclesReturnToDepots = false; + modeConfig.operationalScheme = DrtConfigGroup.OperationalScheme.door2door; + modeConfig.plotDetailedCustomerStats = true; + modeConfig.maxWalkDistance = 1000.; + modeConfig.numberOfThreads = threads; modeConfig.addParameterSet(new ExtensiveInsertionSearchParams()); drtConfig.addParameterSet(modeConfig); diff --git a/core/src/main/java/org/matsim/alonso_mora/scheduling/DefaultAlonsoMoraScheduler.java b/core/src/main/java/org/matsim/alonso_mora/scheduling/DefaultAlonsoMoraScheduler.java index 680e675..cb1c42b 100644 --- a/core/src/main/java/org/matsim/alonso_mora/scheduling/DefaultAlonsoMoraScheduler.java +++ b/core/src/main/java/org/matsim/alonso_mora/scheduling/DefaultAlonsoMoraScheduler.java @@ -1,25 +1,16 @@ package org.matsim.alonso_mora.scheduling; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; - +import com.google.common.base.Verify; import org.matsim.alonso_mora.algorithm.AlonsoMoraRequest; import org.matsim.alonso_mora.algorithm.AlonsoMoraStop; import org.matsim.alonso_mora.algorithm.AlonsoMoraStop.StopType; import org.matsim.alonso_mora.algorithm.AlonsoMoraVehicle; import org.matsim.api.core.v01.network.Link; import org.matsim.api.core.v01.network.Network; -import org.matsim.contrib.drt.extension.shifts.schedule.WaitForShiftStayTask; +import org.matsim.contrib.drt.extension.operations.shifts.schedule.WaitForShiftStayTask; import org.matsim.contrib.drt.passenger.AcceptedDrtRequest; import org.matsim.contrib.drt.passenger.DrtRequest; -import org.matsim.contrib.drt.schedule.DrtDriveTask; -import org.matsim.contrib.drt.schedule.DrtStayTask; -import org.matsim.contrib.drt.schedule.DrtStopTask; -import org.matsim.contrib.drt.schedule.DrtTaskFactory; -import org.matsim.contrib.drt.schedule.DrtTaskType; +import org.matsim.contrib.drt.schedule.*; import org.matsim.contrib.drt.scheduler.EmptyVehicleRelocator; import org.matsim.contrib.dvrp.fleet.DvrpVehicle; import org.matsim.contrib.dvrp.path.VrpPathWithTravelData; @@ -35,7 +26,11 @@ import org.matsim.core.router.util.LeastCostPathCalculator; import org.matsim.core.router.util.TravelTime; -import com.google.common.base.Verify; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; /** * This class translates a sequence of pickups and dropoffs as proposed by the diff --git a/core/src/main/java/org/matsim/alonso_mora/shifts/AlonsoMoraShiftConstraint.java b/core/src/main/java/org/matsim/alonso_mora/shifts/AlonsoMoraShiftConstraint.java index 75429ee..ca53598 100644 --- a/core/src/main/java/org/matsim/alonso_mora/shifts/AlonsoMoraShiftConstraint.java +++ b/core/src/main/java/org/matsim/alonso_mora/shifts/AlonsoMoraShiftConstraint.java @@ -1,9 +1,5 @@ package org.matsim.alonso_mora.shifts; -import java.util.Collection; -import java.util.List; -import java.util.Optional; - import org.matsim.alonso_mora.algorithm.AlonsoMoraRequest; import org.matsim.alonso_mora.algorithm.AlonsoMoraStop; import org.matsim.alonso_mora.algorithm.AlonsoMoraVehicle; @@ -11,11 +7,15 @@ import org.matsim.alonso_mora.algorithm.function.RouteTracker; import org.matsim.alonso_mora.travel_time.TravelTimeEstimator; import org.matsim.api.core.v01.network.Link; -import org.matsim.contrib.drt.extension.shifts.schedule.OperationalStop; +import org.matsim.contrib.drt.extension.operations.shifts.schedule.OperationalStop; import org.matsim.contrib.dvrp.schedule.Schedule; import org.matsim.contrib.dvrp.schedule.StayTask; import org.matsim.contrib.dvrp.schedule.Task; +import java.util.Collection; +import java.util.List; +import java.util.Optional; + /** * Constraint that makes the Alonso-Mora dispatcher take into account shifts and * breaks. diff --git a/core/src/main/java/org/matsim/alonso_mora/shifts/ShiftAlonsoMoraModule.java b/core/src/main/java/org/matsim/alonso_mora/shifts/ShiftAlonsoMoraModule.java index 64ddc0b..df71d2d 100644 --- a/core/src/main/java/org/matsim/alonso_mora/shifts/ShiftAlonsoMoraModule.java +++ b/core/src/main/java/org/matsim/alonso_mora/shifts/ShiftAlonsoMoraModule.java @@ -8,10 +8,10 @@ import org.matsim.alonso_mora.scheduling.DefaultAlonsoMoraScheduler.OperationalVoter; import org.matsim.alonso_mora.travel_time.TravelTimeEstimator; import org.matsim.api.core.v01.network.Network; -import org.matsim.contrib.drt.extension.shifts.config.DrtWithShiftsConfigGroup; -import org.matsim.contrib.drt.extension.shifts.dispatcher.DrtShiftDispatcher; -import org.matsim.contrib.drt.extension.shifts.optimizer.ShiftDrtOptimizer; -import org.matsim.contrib.drt.extension.shifts.schedule.ShiftDrtStayTaskEndTimeCalculator; +import org.matsim.contrib.drt.extension.operations.DrtWithOperationsConfigGroup; +import org.matsim.contrib.drt.extension.operations.shifts.dispatcher.DrtShiftDispatcher; +import org.matsim.contrib.drt.extension.operations.shifts.optimizer.ShiftDrtOptimizer; +import org.matsim.contrib.drt.extension.operations.shifts.schedule.ShiftDrtStayTaskEndTimeCalculator; import org.matsim.contrib.drt.optimizer.DrtOptimizer; import org.matsim.contrib.drt.schedule.DrtStayTaskEndTimeCalculator; import org.matsim.contrib.drt.schedule.DrtTaskFactory; @@ -22,10 +22,10 @@ import org.matsim.core.router.util.TravelTime; public class ShiftAlonsoMoraModule extends AbstractDvrpModeQSimModule { - private final DrtWithShiftsConfigGroup drtConfig; + private final DrtWithOperationsConfigGroup drtConfig; private final AlonsoMoraConfigGroup amConfig; - public ShiftAlonsoMoraModule(DrtWithShiftsConfigGroup drtConfig, AlonsoMoraConfigGroup amConfig) { + public ShiftAlonsoMoraModule(DrtWithOperationsConfigGroup drtConfig, AlonsoMoraConfigGroup amConfig) { super(drtConfig.getMode()); this.drtConfig = drtConfig; this.amConfig = amConfig; @@ -39,8 +39,8 @@ protected void configureQSim() { // TODO: This can become a general binding in DRT bindModal(StayTaskEndTimeCalculator.class).toProvider(modalProvider(getter -> { - return new ShiftDrtStayTaskEndTimeCalculator(drtConfig.getDrtShiftParams(), - new DrtStayTaskEndTimeCalculator((dvrpVehicle, dropoffRequests, pickupRequests) -> drtConfig.getStopDuration())); + return new ShiftDrtStayTaskEndTimeCalculator(drtConfig.getDrtOperationsParams().getShiftsParams().orElseThrow(), + new DrtStayTaskEndTimeCalculator((dvrpVehicle, dropoffRequests, pickupRequests) -> drtConfig.stopDuration)); })); bindModal(OperationalVoter.class).toProvider(modalProvider(getter -> { @@ -68,7 +68,7 @@ protected void configureQSim() { OperationalVoter operationalVoter = getter.getModal(OperationalVoter.class); - return new ShiftAlonsoMoraScheduler(taskFactory, drtConfig.getStopDuration(), + return new ShiftAlonsoMoraScheduler(taskFactory, drtConfig.stopDuration, amConfig.getCheckDeterminsticTravelTimes(), amConfig.getRerouteDuringScheduling(), travelTime, network, endTimeCalculator, router, operationalVoter); })); diff --git a/core/src/main/java/org/matsim/alonso_mora/shifts/ShiftAlonsoMoraScheduler.java b/core/src/main/java/org/matsim/alonso_mora/shifts/ShiftAlonsoMoraScheduler.java index ca92c3c..413eabd 100644 --- a/core/src/main/java/org/matsim/alonso_mora/shifts/ShiftAlonsoMoraScheduler.java +++ b/core/src/main/java/org/matsim/alonso_mora/shifts/ShiftAlonsoMoraScheduler.java @@ -1,11 +1,6 @@ package org.matsim.alonso_mora.shifts; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; - +import com.google.common.base.Verify; import org.matsim.alonso_mora.algorithm.AlonsoMoraRequest; import org.matsim.alonso_mora.algorithm.AlonsoMoraStop; import org.matsim.alonso_mora.algorithm.AlonsoMoraStop.StopType; @@ -14,16 +9,12 @@ import org.matsim.alonso_mora.scheduling.WaitForStopTask; import org.matsim.api.core.v01.network.Link; import org.matsim.api.core.v01.network.Network; -import org.matsim.contrib.drt.extension.shifts.schedule.ShiftBreakTask; -import org.matsim.contrib.drt.extension.shifts.schedule.ShiftChangeOverTask; -import org.matsim.contrib.drt.extension.shifts.schedule.WaitForShiftStayTask; +import org.matsim.contrib.drt.extension.operations.shifts.schedule.ShiftBreakTask; +import org.matsim.contrib.drt.extension.operations.shifts.schedule.ShiftChangeOverTask; +import org.matsim.contrib.drt.extension.operations.shifts.schedule.WaitForShiftStayTask; import org.matsim.contrib.drt.passenger.AcceptedDrtRequest; import org.matsim.contrib.drt.passenger.DrtRequest; -import org.matsim.contrib.drt.schedule.DrtDriveTask; -import org.matsim.contrib.drt.schedule.DrtStayTask; -import org.matsim.contrib.drt.schedule.DrtStopTask; -import org.matsim.contrib.drt.schedule.DrtTaskFactory; -import org.matsim.contrib.drt.schedule.DrtTaskType; +import org.matsim.contrib.drt.schedule.*; import org.matsim.contrib.drt.scheduler.EmptyVehicleRelocator; import org.matsim.contrib.dvrp.fleet.DvrpVehicle; import org.matsim.contrib.dvrp.path.VrpPathWithTravelData; @@ -39,7 +30,11 @@ import org.matsim.core.router.util.LeastCostPathCalculator; import org.matsim.core.router.util.TravelTime; -import com.google.common.base.Verify; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; /** * This class translates a sequence of pickups and dropoffs as proposed by the diff --git a/core/src/main/java/org/matsim/alonso_mora/shifts/ShiftAlonsoMoraVehicle.java b/core/src/main/java/org/matsim/alonso_mora/shifts/ShiftAlonsoMoraVehicle.java index 30edc26..e6f49db 100644 --- a/core/src/main/java/org/matsim/alonso_mora/shifts/ShiftAlonsoMoraVehicle.java +++ b/core/src/main/java/org/matsim/alonso_mora/shifts/ShiftAlonsoMoraVehicle.java @@ -1,7 +1,7 @@ package org.matsim.alonso_mora.shifts; import org.matsim.alonso_mora.algorithm.DefaultAlonsoMoraVehicle; -import org.matsim.contrib.drt.extension.shifts.schedule.OperationalStop; +import org.matsim.contrib.drt.extension.operations.shifts.schedule.OperationalStop; import org.matsim.contrib.dvrp.fleet.DvrpVehicle; import org.matsim.contrib.dvrp.schedule.Schedule; import org.matsim.contrib.dvrp.schedule.Schedule.ScheduleStatus; diff --git a/core/src/main/java/org/matsim/alonso_mora/shifts/ShiftOperationalVoter.java b/core/src/main/java/org/matsim/alonso_mora/shifts/ShiftOperationalVoter.java index 4b3cfde..0121ce6 100644 --- a/core/src/main/java/org/matsim/alonso_mora/shifts/ShiftOperationalVoter.java +++ b/core/src/main/java/org/matsim/alonso_mora/shifts/ShiftOperationalVoter.java @@ -1,10 +1,10 @@ package org.matsim.alonso_mora.shifts; import org.matsim.alonso_mora.scheduling.DefaultAlonsoMoraScheduler.OperationalVoter; -import org.matsim.contrib.drt.extension.shifts.schedule.OperationalStop; -import org.matsim.contrib.drt.extension.shifts.schedule.ShiftBreakTask; -import org.matsim.contrib.drt.extension.shifts.schedule.ShiftChangeOverTask; -import org.matsim.contrib.drt.extension.shifts.scheduler.ShiftTaskScheduler; +import org.matsim.contrib.drt.extension.operations.shifts.schedule.OperationalStop; +import org.matsim.contrib.drt.extension.operations.shifts.schedule.ShiftBreakTask; +import org.matsim.contrib.drt.extension.operations.shifts.schedule.ShiftChangeOverTask; +import org.matsim.contrib.drt.extension.operations.shifts.scheduler.ShiftTaskScheduler; import org.matsim.contrib.drt.schedule.DrtDriveTask; import org.matsim.contrib.drt.schedule.DrtTaskType; import org.matsim.contrib.dvrp.schedule.Task; diff --git a/core/src/test/java/org/matsim/alonso_mora/run/AlonsoMoraExamplesIT.java b/core/src/test/java/org/matsim/alonso_mora/run/AlonsoMoraExamplesIT.java index 748c1e0..fd3e934 100644 --- a/core/src/test/java/org/matsim/alonso_mora/run/AlonsoMoraExamplesIT.java +++ b/core/src/test/java/org/matsim/alonso_mora/run/AlonsoMoraExamplesIT.java @@ -29,13 +29,13 @@ import org.matsim.api.core.v01.Id; import org.matsim.api.core.v01.Scenario; import org.matsim.api.core.v01.network.Link; -import org.matsim.contrib.drt.extension.shifts.config.DrtShiftParams; -import org.matsim.contrib.drt.extension.shifts.config.DrtWithShiftsConfigGroup; -import org.matsim.contrib.drt.extension.shifts.operationFacilities.*; -import org.matsim.contrib.drt.extension.shifts.run.ShiftDrtModeModule; -import org.matsim.contrib.drt.extension.shifts.run.ShiftDrtModeOptimizerQSimModule; -import org.matsim.contrib.drt.extension.shifts.run.ShiftDvrpFleetQsimModule; -import org.matsim.contrib.drt.extension.shifts.shift.*; +import org.matsim.contrib.drt.extension.operations.DrtOperationsParams; +import org.matsim.contrib.drt.extension.operations.DrtWithOperationsConfigGroup; +import org.matsim.contrib.drt.extension.operations.operationFacilities.*; +import org.matsim.contrib.drt.extension.operations.shifts.run.ShiftDrtModeModule; +import org.matsim.contrib.drt.extension.operations.shifts.run.ShiftDrtModeOptimizerQSimModule; +import org.matsim.contrib.drt.extension.operations.shifts.run.ShiftDvrpFleetQsimModule; +import org.matsim.contrib.drt.extension.operations.shifts.shift.*; import org.matsim.contrib.drt.routing.DrtRoute; import org.matsim.contrib.drt.routing.DrtRouteFactory; import org.matsim.contrib.drt.run.DrtConfigGroup; @@ -47,7 +47,6 @@ import org.matsim.contrib.dvrp.run.DvrpModule; import org.matsim.contrib.dvrp.run.DvrpQSimComponents; import org.matsim.core.config.Config; -import org.matsim.core.config.ConfigGroup; import org.matsim.core.config.ConfigUtils; import org.matsim.core.controler.Controler; import org.matsim.core.controler.OutputDirectoryHierarchy.OverwriteFileSetting; @@ -122,7 +121,7 @@ public void testRunAlonsoMora() { public void testRunAlonsoMoraWithShifts() { Id.resetCaches(); URL configUrl = IOUtils.extendUrl(ExamplesUtils.getTestScenarioURL("mielec"), "mielec_drt_config.xml"); - Config config = ConfigUtils.loadConfig(configUrl, new MultiModeDrtConfigGroup(DrtWithShiftsConfigGroup::new), new DvrpConfigGroup(), + Config config = ConfigUtils.loadConfig(configUrl, new MultiModeDrtConfigGroup(DrtWithOperationsConfigGroup::new), new DvrpConfigGroup(), new MultiModeAlonsoMoraConfigGroup(), new OTFVisConfigGroup()); AlonsoMoraConfigGroup amConfig = new AlonsoMoraConfigGroup(); @@ -133,10 +132,10 @@ public void testRunAlonsoMoraWithShifts() { config.controler().setOutputDirectory(utils.getOutputDirectory()); // Remove DRT rebalancer as we want to use AM rebalancer - DrtWithShiftsConfigGroup drtConfig = (DrtWithShiftsConfigGroup) MultiModeDrtConfigGroup.get(config).getModalElements().iterator().next(); + DrtWithOperationsConfigGroup drtConfig = (DrtWithOperationsConfigGroup) MultiModeDrtConfigGroup.get(config).getModalElements().iterator().next(); drtConfig.removeParameterSet(drtConfig.getRebalancingParams().get()); - ConfigGroup shiftParams = drtConfig.createParameterSet(DrtShiftParams.SET_NAME); - drtConfig.addParameterSet(shiftParams); + DrtOperationsParams operationsParams = (DrtOperationsParams) drtConfig.createParameterSet(DrtOperationsParams.SET_NAME); + drtConfig.addParameterSet(operationsParams); // Load scenario Scenario scenario = ScenarioUtils.createScenario(config); @@ -226,7 +225,7 @@ public void install() { }); AlonsoMoraConfigurator.configure(controller, amConfig.getMode()); - controller.addOverridingQSimModule(new ShiftAlonsoMoraModule((DrtWithShiftsConfigGroup) drtConfig, amConfig)); + controller.addOverridingQSimModule(new ShiftAlonsoMoraModule((DrtWithOperationsConfigGroup) drtConfig, amConfig)); controller.run(); var expectedStats = Stats.newBuilder() // diff --git a/pom.xml b/pom.xml index 926f47e..2366daf 100644 --- a/pom.xml +++ b/pom.xml @@ -14,8 +14,8 @@ Alonso-Mora, J., Samaranayake, S., Wallar, A., Frazzoli, E., Rus, D., 2017. On-d to the MATSim framework. - 11 - 11 + 17 + 17 15.0-SNAPSHOT