diff --git a/.github/workflows/code-coverage.yaml b/.github/workflows/code-coverage.yaml index 20ffe41971a..bdf0d7bfcde 100644 --- a/.github/workflows/code-coverage.yaml +++ b/.github/workflows/code-coverage.yaml @@ -15,7 +15,7 @@ jobs: uses: actions/checkout@v4 - name: Setup Java - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: java-version: 17 distribution: 'zulu' diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 021bae1c67c..0f30527d41b 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -19,7 +19,7 @@ jobs: uses: actions/checkout@v4 - name: Setup Java - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: java-version: 17 distribution: 'zulu' diff --git a/.github/workflows/deploy-on-pr-merge.yaml b/.github/workflows/deploy-on-pr-merge.yaml index 332a3dfe178..ef046e1bdb0 100644 --- a/.github/workflows/deploy-on-pr-merge.yaml +++ b/.github/workflows/deploy-on-pr-merge.yaml @@ -20,7 +20,7 @@ jobs: uses: actions/checkout@v4 - name: Setup Java - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: java-version: 17 distribution: 'zulu' diff --git a/.github/workflows/deploy-on-release-created.yaml b/.github/workflows/deploy-on-release-created.yaml index 7c37d3c6f7d..ace4f1881fb 100644 --- a/.github/workflows/deploy-on-release-created.yaml +++ b/.github/workflows/deploy-on-release-created.yaml @@ -14,7 +14,7 @@ jobs: uses: actions/checkout@v4 - name: Setup Java - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: java-version: 17 distribution: 'zulu' diff --git a/.github/workflows/deploy-weekly.yaml b/.github/workflows/deploy-weekly.yaml index 0861a80ff91..88e183083b7 100644 --- a/.github/workflows/deploy-weekly.yaml +++ b/.github/workflows/deploy-weekly.yaml @@ -15,7 +15,7 @@ jobs: uses: actions/checkout@v4 - name: Setup Java - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: java-version: 17 distribution: 'zulu' diff --git a/.github/workflows/full-integration.yaml b/.github/workflows/full-integration.yaml index c831df5ec61..e63fc75985b 100644 --- a/.github/workflows/full-integration.yaml +++ b/.github/workflows/full-integration.yaml @@ -25,7 +25,7 @@ jobs: uses: actions/checkout@v4 - name: Setup Java - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: java-version: 17 distribution: 'zulu' diff --git a/.github/workflows/verify-push.yaml b/.github/workflows/verify-push.yaml index f2a5b59d8ee..a4eb837efcb 100644 --- a/.github/workflows/verify-push.yaml +++ b/.github/workflows/verify-push.yaml @@ -84,7 +84,7 @@ jobs: - name: Setup Java if: ${{matrix.module != 'matsim' || steps.detect-changes.outputs.outside-contribs == 'true'}} - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: java-version: 17 distribution: 'zulu' diff --git a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/edrt/optimizer/EDrtVehicleDataEntryFactory.java b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/edrt/optimizer/EDrtVehicleDataEntryFactory.java index f552fb3ecae..76d84a09e32 100644 --- a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/edrt/optimizer/EDrtVehicleDataEntryFactory.java +++ b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/edrt/optimizer/EDrtVehicleDataEntryFactory.java @@ -71,16 +71,23 @@ public VehicleEntry create(DvrpVehicle vehicle, double currentTime) { Battery battery = ((EvDvrpVehicle)vehicle).getElectricVehicle().getBattery(); int nextTaskIdx; double chargeBeforeNextTask; - if (schedule.getStatus() == ScheduleStatus.PLANNED) { - nextTaskIdx = 0; - chargeBeforeNextTask = battery.getCharge(); - } else { // STARTED - Task currentTask = schedule.getCurrentTask(); - ETaskTracker eTracker = (ETaskTracker)currentTask.getTaskTracker(); - chargeBeforeNextTask = eTracker.predictChargeAtEnd(); - nextTaskIdx = currentTask.getTaskIdx() + 1; + + switch (schedule.getStatus()) { + case PLANNED: + nextTaskIdx = 0; + chargeBeforeNextTask = battery.getCharge(); + break; + case STARTED: + Task currentTask = schedule.getCurrentTask(); + ETaskTracker eTracker = (ETaskTracker) currentTask.getTaskTracker(); + chargeBeforeNextTask = eTracker.predictChargeAtEnd(); + nextTaskIdx = currentTask.getTaskIdx() + 1; + break; + default: + return null; } + List tasks = schedule.getTasks(); for (int i = nextTaskIdx; i < tasks.size() - 1; i++) { chargeBeforeNextTask -= ((ETask)tasks.get(i)).getTotalEnergy(); diff --git a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/estimator/DrtInitialEstimator.java b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/estimator/DrtInitialEstimator.java new file mode 100644 index 00000000000..a826a936e46 --- /dev/null +++ b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/estimator/DrtInitialEstimator.java @@ -0,0 +1,9 @@ +package org.matsim.contrib.drt.extension.estimator; + +/** + * This interface is used to provide an initial estimate for the drt service. + * Supposed to be used when no data is available from the simulation yet. + * The interface is exactly the same as {@link DrtEstimator}, but this class won't be called with update events. + */ +public interface DrtInitialEstimator extends DrtEstimator { +} diff --git a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/estimator/BasicDrtEstimator.java b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/estimator/impl/BasicDrtEstimator.java similarity index 85% rename from contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/estimator/BasicDrtEstimator.java rename to contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/estimator/impl/BasicDrtEstimator.java index d446d5f34bc..f1fd6f04c8f 100644 --- a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/estimator/BasicDrtEstimator.java +++ b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/estimator/impl/BasicDrtEstimator.java @@ -1,4 +1,4 @@ -package org.matsim.contrib.drt.extension.estimator; +package org.matsim.contrib.drt.extension.estimator.impl; import org.apache.commons.math3.stat.descriptive.SummaryStatistics; import org.apache.commons.math3.stat.regression.RegressionResults; @@ -9,8 +9,9 @@ import org.matsim.api.core.v01.events.PersonMoneyEvent; import org.matsim.api.core.v01.population.Person; import org.matsim.contrib.drt.analysis.DrtEventSequenceCollector; +import org.matsim.contrib.drt.extension.estimator.DrtEstimator; +import org.matsim.contrib.drt.extension.estimator.DrtInitialEstimator; import org.matsim.contrib.drt.extension.estimator.run.DrtEstimatorConfigGroup; -import org.matsim.contrib.drt.fare.DrtFareParams; import org.matsim.contrib.drt.routing.DrtRoute; import org.matsim.contrib.drt.run.DrtConfigGroup; import org.matsim.contrib.drt.speedup.DrtSpeedUp; @@ -32,6 +33,7 @@ public class BasicDrtEstimator implements DrtEstimator, IterationEndsListener { private final DrtEventSequenceCollector collector; private final DrtEstimatorConfigGroup config; private final DrtConfigGroup drtConfig; + private final DrtInitialEstimator initial; private final SplittableRandom rnd = new SplittableRandom(); /** @@ -40,10 +42,11 @@ public class BasicDrtEstimator implements DrtEstimator, IterationEndsListener { private GlobalEstimate currentEst; private RegressionResults fare; - public BasicDrtEstimator(DrtEventSequenceCollector collector, DrtEstimatorConfigGroup config, - DrtConfigGroup drtConfig) { + public BasicDrtEstimator(DrtEventSequenceCollector collector, DrtInitialEstimator initial, + DrtEstimatorConfigGroup config, DrtConfigGroup drtConfig) { //zones = injector.getModal(DrtZonalSystem.class); this.collector = collector; + this.initial = initial; this.config = config; this.drtConfig = drtConfig; } @@ -115,23 +118,8 @@ public void notifyIterationEnds(IterationEndsEvent event) { public Estimate estimate(DrtRoute route, OptionalTime departureTime) { if (currentEst == null) { - // If not estimates are present, use travel time alpha as detour - // beta is not used, because estimates are supposed to be minimums and not worst cases - double travelTime = Math.min(route.getDirectRideTime() + drtConfig.maxAbsoluteDetour, - route.getDirectRideTime() * drtConfig.maxTravelTimeAlpha); - - double fare = 0; - if (drtConfig.getDrtFareParams().isPresent()) { - DrtFareParams fareParams = drtConfig.getDrtFareParams().get(); - fare = fareParams.distanceFare_m * route.getDistance() - + fareParams.timeFare_h * route.getDirectRideTime() / 3600.0 - + fareParams.baseFare; - - fare = Math.max(fare, fareParams.minFarePerTrip); - } - - // for distance, also use the max travel time alpha - return new Estimate(route.getDistance() * drtConfig.maxTravelTimeAlpha, travelTime, drtConfig.maxWaitTime, fare, 0); + // Same interface, just different binding + return initial.estimate(route, departureTime); } double fare = 0; diff --git a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/estimator/impl/ConstantDrtEstimator.java b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/estimator/impl/ConstantDrtEstimator.java new file mode 100644 index 00000000000..d9a4d4be46f --- /dev/null +++ b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/estimator/impl/ConstantDrtEstimator.java @@ -0,0 +1,50 @@ +package org.matsim.contrib.drt.extension.estimator.impl; + +import org.matsim.contrib.drt.extension.estimator.DrtInitialEstimator; +import org.matsim.contrib.drt.fare.DrtFareParams; +import org.matsim.contrib.drt.routing.DrtRoute; +import org.matsim.contrib.drt.run.DrtConfigGroup; +import org.matsim.core.utils.misc.OptionalTime; + +/** + * Estimates using a constant detour factor and waiting time. + */ +public class ConstantDrtEstimator implements DrtInitialEstimator { + + private final DrtConfigGroup drtConfig; + + /** + * Detour factor for the estimate. 1.0 means no detour, 2.0 means twice the distance. + */ + private final double detourFactor; + + /** + * Constant waiting time estimate in seconds. + */ + private final double waitingTime; + + public ConstantDrtEstimator(DrtConfigGroup drtConfig, double detourFactor, double waitingTime) { + this.drtConfig = drtConfig; + this.detourFactor = detourFactor; + this.waitingTime = waitingTime; + } + + @Override + public Estimate estimate(DrtRoute route, OptionalTime departureTime) { + + double distance = route.getDistance() * detourFactor; + double travelTime = route.getDirectRideTime() * detourFactor; + + double fare = 0; + if (drtConfig.getDrtFareParams().isPresent()) { + DrtFareParams fareParams = drtConfig.getDrtFareParams().get(); + fare = fareParams.distanceFare_m * distance + + fareParams.timeFare_h * travelTime / 3600.0 + + fareParams.baseFare; + + fare = Math.max(fare, fareParams.minFarePerTrip); + } + + return new Estimate(distance, travelTime, waitingTime, fare, 0); + } +} diff --git a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/estimator/impl/PessimisticDrtEstimator.java b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/estimator/impl/PessimisticDrtEstimator.java new file mode 100644 index 00000000000..d26a318c635 --- /dev/null +++ b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/estimator/impl/PessimisticDrtEstimator.java @@ -0,0 +1,40 @@ +package org.matsim.contrib.drt.extension.estimator.impl; + +import org.matsim.contrib.drt.extension.estimator.DrtInitialEstimator; +import org.matsim.contrib.drt.fare.DrtFareParams; +import org.matsim.contrib.drt.routing.DrtRoute; +import org.matsim.contrib.drt.run.DrtConfigGroup; +import org.matsim.core.utils.misc.OptionalTime; + +/** + * Uses the upper bounds from config for the initial estimate. + */ +public class PessimisticDrtEstimator implements DrtInitialEstimator { + private final DrtConfigGroup drtConfig; + + public PessimisticDrtEstimator(DrtConfigGroup drtConfig) { + this.drtConfig = drtConfig; + } + + @Override + public Estimate estimate(DrtRoute route, OptionalTime departureTime) { + // If not estimates are present, use travel time alpha as detour + // beta is not used, because estimates are supposed to be minimums and not worst cases + double travelTime = Math.min(route.getDirectRideTime() + drtConfig.maxAbsoluteDetour, + route.getDirectRideTime() * drtConfig.maxTravelTimeAlpha); + + double fare = 0; + if (drtConfig.getDrtFareParams().isPresent()) { + DrtFareParams fareParams = drtConfig.getDrtFareParams().get(); + fare = fareParams.distanceFare_m * route.getDistance() + + fareParams.timeFare_h * route.getDirectRideTime() / 3600.0 + + fareParams.baseFare; + + fare = Math.max(fare, fareParams.minFarePerTrip); + } + + // for distance, also use the max travel time alpha + return new Estimate(route.getDistance() * drtConfig.maxTravelTimeAlpha, travelTime, drtConfig.maxWaitTime, fare, 0); + } + +} diff --git a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/estimator/run/DrtEstimatorConfigGroup.java b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/estimator/run/DrtEstimatorConfigGroup.java index 107aa2eb53a..985435bcfc3 100644 --- a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/estimator/run/DrtEstimatorConfigGroup.java +++ b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/estimator/run/DrtEstimatorConfigGroup.java @@ -16,6 +16,11 @@ public class DrtEstimatorConfigGroup extends ReflectiveConfigGroupWithConfigurab public enum EstimatorType { BASIC, + /** + * Will use the bound initial estimator, without any updates. + */ + INITIAL, + /** * Custom estimator, that needs to provided via binding. */ @@ -58,4 +63,12 @@ public String getMode() { return mode; } + /** + * Set estimator type and return same instance. + */ + public DrtEstimatorConfigGroup withEstimator(EstimatorType estimator) { + this.estimator = estimator; + return this; + } + } diff --git a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/estimator/run/DrtEstimatorModule.java b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/estimator/run/DrtEstimatorModule.java index 14bc2ae330d..c5a8ed00e7c 100644 --- a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/estimator/run/DrtEstimatorModule.java +++ b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/estimator/run/DrtEstimatorModule.java @@ -3,9 +3,11 @@ import com.google.inject.Singleton; import com.google.inject.multibindings.MapBinder; import org.matsim.contrib.drt.analysis.DrtEventSequenceCollector; -import org.matsim.contrib.drt.extension.estimator.BasicDrtEstimator; import org.matsim.contrib.drt.extension.estimator.DrtEstimateAnalyzer; import org.matsim.contrib.drt.extension.estimator.DrtEstimator; +import org.matsim.contrib.drt.extension.estimator.DrtInitialEstimator; +import org.matsim.contrib.drt.extension.estimator.impl.BasicDrtEstimator; +import org.matsim.contrib.drt.extension.estimator.impl.PessimisticDrtEstimator; import org.matsim.contrib.drt.run.DrtConfigGroup; import org.matsim.contrib.drt.run.MultiModeDrtConfigGroup; import org.matsim.contrib.dvrp.run.AbstractDvrpModeModule; @@ -14,13 +16,22 @@ import org.matsim.core.config.ConfigUtils; import org.matsim.core.controler.AbstractModule; +import java.util.HashMap; +import java.util.Map; import java.util.Optional; +import java.util.function.Function; /** * Main module that needs to be installed if any estimator is to be used. */ public class DrtEstimatorModule extends AbstractModule { + + /** + * Map of initial providers. + */ + private final Map> initial = new HashMap<>(); + @Override public void install() { @@ -35,7 +46,24 @@ public void install() { } } - static final class ModeModule extends AbstractDvrpModeModule { + /** + * Configure initial estimators for the given modes. + * + * @param getter modal getter, which can be used to use other modal components via guice + */ + public DrtEstimatorModule withInitialEstimator(Function getter, String... modes) { + + if (modes.length == 0) + throw new IllegalArgumentException("At least one mode needs to be provided."); + + for (String mode : modes) { + initial.put(mode, getter); + } + + return this; + } + + final class ModeModule extends AbstractDvrpModeModule { private final DrtConfigGroup cfg; private final DrtEstimatorConfigGroup group; @@ -52,10 +80,21 @@ public void install() { // try with default injections and overwrite if (group.estimator == DrtEstimatorConfigGroup.EstimatorType.BASIC) { bindModal(DrtEstimator.class).toProvider(modalProvider( - getter -> new BasicDrtEstimator(getter.getModal(DrtEventSequenceCollector.class), group, cfg) + getter -> new BasicDrtEstimator( + getter.getModal(DrtEventSequenceCollector.class), + getter.getModal(DrtInitialEstimator.class), + group, cfg + ) )).in(Singleton.class); + } else if (group.estimator == DrtEstimatorConfigGroup.EstimatorType.INITIAL) { + bindModal(DrtEstimator.class).to(modalKey(DrtInitialEstimator.class)); } + if (initial.containsKey(group.mode)) { + bindModal(DrtInitialEstimator.class).toProvider(() -> initial.get(group.mode).apply(cfg)).in(Singleton.class); + } else + bindModal(DrtInitialEstimator.class).toInstance(new PessimisticDrtEstimator(cfg)); + // DRT Estimators will be available as Map MapBinder.newMapBinder(this.binder(), DvrpMode.class, DrtEstimator.class) .addBinding(DvrpModes.mode(getMode())) diff --git a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/insertion/DrtInsertionModule.java b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/insertion/DrtInsertionModule.java index 9408dcfd067..23ad52f4e80 100644 --- a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/insertion/DrtInsertionModule.java +++ b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/insertion/DrtInsertionModule.java @@ -15,8 +15,9 @@ import org.matsim.contrib.drt.extension.insertion.constraints.SkillsConstraint.VehicleSkillsSupplier; import org.matsim.contrib.drt.extension.insertion.constraints.VehicleRangeConstraint; import org.matsim.contrib.drt.extension.insertion.constraints.VehicleRangeConstraint.VehicleRangeSupplier; -import org.matsim.contrib.drt.extension.insertion.distances.ApproximateDistanceCalculator; +import org.matsim.contrib.drt.extension.insertion.distances.DistanceApproximator; import org.matsim.contrib.drt.extension.insertion.distances.DistanceCalculator; +import org.matsim.contrib.drt.extension.insertion.distances.EuclideanDistanceApproximator; import org.matsim.contrib.drt.extension.insertion.distances.RoutingDistanceCalculator; import org.matsim.contrib.drt.extension.insertion.objectives.PassengerDelayObjective; import org.matsim.contrib.drt.extension.insertion.objectives.VehicleActiveTimeObjective; @@ -173,10 +174,93 @@ public DrtInsertionModule withConstraint(DrtInsertionConstraint constraint) { return this; } + // DISTANCES + + private DistanceCalculator distanceCalculator; + private DistanceApproximator distanceApproximator; + + private Class distanceCalculatorClass; + private Class distanceApproximatorClass; + + public DrtInsertionModule withDistanceCalculator(DistanceCalculator distanceCalculator) { + Preconditions.checkState(this.distanceCalculator == null && this.distanceCalculatorClass == null); + this.distanceCalculator = distanceCalculator; + return this; + } + + public DrtInsertionModule withDistanceCalculator(Class distanceCalculatorClass) { + Preconditions.checkState(this.distanceCalculator == null && this.distanceCalculatorClass == null); + this.distanceCalculatorClass = distanceCalculatorClass; + return this; + } + + public DrtInsertionModule withDistanceApproximator(DistanceApproximator distanceApproximator) { + Preconditions.checkState(this.distanceApproximator == null && this.distanceApproximatorClass == null); + this.distanceApproximator = distanceApproximator; + return this; + } + + public DrtInsertionModule withDistanceApproximator( + Class distanceApproximatorClass) { + Preconditions.checkState(this.distanceApproximator == null && this.distanceApproximatorClass == null); + this.distanceApproximatorClass = distanceApproximatorClass; + return this; + } + + public DrtInsertionModule withEuclideanDistanceApproximator(double euclideanDistanceFactor) { + Preconditions.checkState(this.distanceApproximator == null && this.distanceApproximatorClass == null); + this.distanceApproximator = new EuclideanDistanceApproximator(euclideanDistanceFactor); + return this; + } + + public DrtInsertionModule withEuclideanDistanceCalculator(double euclideanDistanceFactor) { + Preconditions.checkState(this.distanceCalculator == null && this.distanceCalculatorClass == null); + this.distanceCalculator = new EuclideanDistanceApproximator(euclideanDistanceFactor); + return this; + } + + private void configureDistances() { + bindModal(RoutingDistanceCalculator.class).toProvider(modalProvider(getter -> { + LeastCostPathCalculatorFactory factory = new SpeedyALTFactory(); + + TravelTime travelTime = getter.getModal(TravelTime.class); + TravelDisutility travelDisutility = new OnlyTimeDependentTravelDisutility(travelTime); + Network network = getter.getModal(Network.class); + + printDistanceWarning(); + + return new RoutingDistanceCalculator(factory.createPathCalculator(network, travelDisutility, travelTime), + travelTime); + })); + + if (distanceCalculator == null && distanceCalculatorClass == null) { + distanceCalculatorClass = RoutingDistanceCalculator.class; + } + + if (distanceApproximator == null && distanceApproximatorClass == null) { + distanceApproximator = DistanceApproximator.NULL; + } + + if (distanceCalculator != null) { + bindModal(DistanceCalculator.class).toInstance(distanceCalculator); + } + + if (distanceCalculatorClass != null) { + bindModal(DistanceCalculator.class).to(modalKey(distanceCalculatorClass)); + } + + if (distanceApproximator != null) { + bindModal(DistanceApproximator.class).toInstance(distanceApproximator); + } + + if (distanceApproximatorClass != null) { + bindModal(DistanceApproximator.class).to(modalKey(distanceApproximatorClass)); + } + } + // RANGE CONSTRAINT private boolean useRangeConstraint = false; - private double rangeEstimationFactor = Double.NaN; private VehicleRangeSupplier vehicleRangeSupplier; private Class vehicleRangeSupplierClass; @@ -200,11 +284,6 @@ public DrtInsertionModule withVehicleRange(Class return this; } - public DrtInsertionModule withRangeEstimationFactor(double rangeEstimationFactor) { - this.rangeEstimationFactor = rangeEstimationFactor; - return this; - } - private void configureRangeContraint(List> constraintBindings) { if (useRangeConstraint) { if (vehicleRangeSupplier != null) { @@ -216,10 +295,12 @@ private void configureRangeContraint(List> } bindModal(VehicleRangeConstraint.class).toProvider(modalProvider(getter -> { - DistanceCalculator distanceCalculator = getter.getModal(RoutingDistanceCalculator.class); - DistanceCalculator distanceApproximator = Double.isFinite(rangeEstimationFactor) - ? new ApproximateDistanceCalculator(rangeEstimationFactor) - : null; + DistanceCalculator distanceCalculator = getter.getModal(DistanceCalculator.class); + DistanceApproximator distanceApproximator = getter.getModal(DistanceApproximator.class); + + if (distanceApproximator == DistanceApproximator.NULL) { + distanceApproximator = null; + } return new VehicleRangeConstraint(vehicleRangeSupplier, distanceCalculator, distanceApproximator); })); @@ -362,7 +443,7 @@ private void configureVehicleDistanceObjective() { final DistanceCalculator distanceCalculator; if (Double.isFinite(distanceObjectiveEstimationFactor)) { - distanceCalculator = new ApproximateDistanceCalculator(distanceObjectiveEstimationFactor); + distanceCalculator = new EuclideanDistanceApproximator(distanceObjectiveEstimationFactor); } else { distanceCalculator = getter.getModal(RoutingDistanceCalculator.class); } @@ -373,6 +454,8 @@ private void configureVehicleDistanceObjective() { @Override protected void configureQSim() { + configureDistances(); + List> constraintBindings = new LinkedList<>(); configureExclusivityConstraint(constraintBindings); configureSingleRequestConstraint(constraintBindings); @@ -424,19 +507,6 @@ protected void configureQSim() { bindModal(CostCalculationStrategy.class).to(modalKey(ConfigurableCostCalculatorStrategy.class)); bindModal(DrtOfferAcceptor.class).to(modalKey(PromisedTimeWindowOfferAcceptor.class)); - - bindModal(RoutingDistanceCalculator.class).toProvider(modalProvider(getter -> { - LeastCostPathCalculatorFactory factory = new SpeedyALTFactory(); - - TravelTime travelTime = getter.getModal(TravelTime.class); - TravelDisutility travelDisutility = new OnlyTimeDependentTravelDisutility(travelTime); - Network network = getter.getModal(Network.class); - - printDistanceWarning(); - - return new RoutingDistanceCalculator(factory.createPathCalculator(network, travelDisutility, travelTime), - travelTime); - })); } private final static Logger logger = LogManager.getLogger(DrtInsertionModule.class); diff --git a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/insertion/constraints/VehicleRangeConstraint.java b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/insertion/constraints/VehicleRangeConstraint.java index decf605d71a..649a68fd189 100644 --- a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/insertion/constraints/VehicleRangeConstraint.java +++ b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/insertion/constraints/VehicleRangeConstraint.java @@ -3,6 +3,7 @@ import javax.annotation.Nullable; import org.matsim.contrib.drt.extension.insertion.DrtInsertionConstraint; +import org.matsim.contrib.drt.extension.insertion.distances.DistanceApproximator; import org.matsim.contrib.drt.extension.insertion.distances.DistanceCalculator; import org.matsim.contrib.drt.extension.insertion.distances.InsertionDistanceCalculator; import org.matsim.contrib.drt.extension.insertion.distances.InsertionDistanceCalculator.VehicleDistance; @@ -16,10 +17,10 @@ public class VehicleRangeConstraint implements DrtInsertionConstraint { private final VehicleRangeSupplier rangeSupplier; private final DistanceCalculator distanceCalculator; - private final DistanceCalculator distanceApproximator; + private final DistanceApproximator distanceApproximator; public VehicleRangeConstraint(VehicleRangeSupplier rangeSupplier, DistanceCalculator distanceEstimator, - @Nullable DistanceCalculator distanceApproximator) { + @Nullable DistanceApproximator distanceApproximator) { this.rangeSupplier = rangeSupplier; this.distanceCalculator = distanceEstimator; this.distanceApproximator = distanceApproximator; diff --git a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/insertion/distances/DistanceApproximator.java b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/insertion/distances/DistanceApproximator.java new file mode 100644 index 00000000000..bae08f00040 --- /dev/null +++ b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/insertion/distances/DistanceApproximator.java @@ -0,0 +1,8 @@ +package org.matsim.contrib.drt.extension.insertion.distances; + +public interface DistanceApproximator extends DistanceCalculator { + static public DistanceApproximator NULL = (departureTime, fromLink, toLink) -> { + throw new IllegalStateException( + "The NULL DistanceApproximator is only used as a tag for not using any approximation."); + }; +} diff --git a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/insertion/distances/DistanceCalculator.java b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/insertion/distances/DistanceCalculator.java index ff4943e6a4e..cc74978ac34 100644 --- a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/insertion/distances/DistanceCalculator.java +++ b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/insertion/distances/DistanceCalculator.java @@ -3,5 +3,5 @@ import org.matsim.api.core.v01.network.Link; public interface DistanceCalculator { - double estimateDistance(double departureTime, Link fromLink, Link toLink); + double calculateDistance(double departureTime, Link fromLink, Link toLink); } diff --git a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/insertion/distances/ApproximateDistanceCalculator.java b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/insertion/distances/EuclideanDistanceApproximator.java similarity index 66% rename from contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/insertion/distances/ApproximateDistanceCalculator.java rename to contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/insertion/distances/EuclideanDistanceApproximator.java index 3d2893936d8..9f8c5c4556e 100644 --- a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/insertion/distances/ApproximateDistanceCalculator.java +++ b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/insertion/distances/EuclideanDistanceApproximator.java @@ -3,15 +3,15 @@ import org.matsim.api.core.v01.network.Link; import org.matsim.core.utils.geometry.CoordUtils; -public class ApproximateDistanceCalculator implements DistanceCalculator { +public class EuclideanDistanceApproximator implements DistanceApproximator { private final double distanceEstimationFactor; - public ApproximateDistanceCalculator(double distanceEstimationFactor) { + public EuclideanDistanceApproximator(double distanceEstimationFactor) { this.distanceEstimationFactor = distanceEstimationFactor; } @Override - public double estimateDistance(double departureTime, Link fromLink, Link toLink) { + public double calculateDistance(double departureTime, Link fromLink, Link toLink) { return distanceEstimationFactor * CoordUtils.calcEuclideanDistance(fromLink.getFromNode().getCoord(), toLink.getFromNode().getCoord()); } diff --git a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/insertion/distances/InsertionDistanceCalculator.java b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/insertion/distances/InsertionDistanceCalculator.java index 60e5642746e..01a6c91bf20 100644 --- a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/insertion/distances/InsertionDistanceCalculator.java +++ b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/insertion/distances/InsertionDistanceCalculator.java @@ -68,9 +68,9 @@ public VehicleDistance calculateInsertionDistance(Insertion insertion, DetourTim int beforePickupOccupancy = insertion.pickup.previousWaypoint.getOutgoingOccupancy(); double beforePickupDistance = distanceEstimator - .estimateDistance(insertion.pickup.previousWaypoint.getDepartureTime(), pickupFromLink, pickupNewLink); + .calculateDistance(insertion.pickup.previousWaypoint.getDepartureTime(), pickupFromLink, pickupNewLink); - double afterPickupDistance = distanceEstimator.estimateDistance(detourTimeInfo.pickupDetourInfo.departureTime, + double afterPickupDistance = distanceEstimator.calculateDistance(detourTimeInfo.pickupDetourInfo.departureTime, pickupNewLink, pickupToLink); addedDistances.add(new DistanceEntry(beforePickupDistance, beforePickupOccupancy)); @@ -128,7 +128,7 @@ public VehicleDistance calculateInsertionDistance(Insertion insertion, DetourTim final int beforeDropoffOccupancy; if (insertion.dropoff.index > insertion.pickup.index) { beforeDropoffOccupancy = insertion.dropoff.previousWaypoint.getOutgoingOccupancy() + 1; - double beforeDropoffDistance = distanceEstimator.estimateDistance( + double beforeDropoffDistance = distanceEstimator.calculateDistance( insertion.dropoff.previousWaypoint.getDepartureTime(), dropoffFromLink, dropoffNewLink); addedDistances.add(new DistanceEntry(beforeDropoffDistance, beforeDropoffOccupancy)); @@ -136,7 +136,7 @@ public VehicleDistance calculateInsertionDistance(Insertion insertion, DetourTim beforeDropoffOccupancy = beforePickupOccupancy + 1; } - double afterDropoffDistance = distanceEstimator.estimateDistance(detourTimeInfo.dropoffDetourInfo.arrivalTime, + double afterDropoffDistance = distanceEstimator.calculateDistance(detourTimeInfo.dropoffDetourInfo.arrivalTime, dropoffNewLink, dropoffToLink); addedDistances.add(new DistanceEntry(afterDropoffDistance, beforeDropoffOccupancy - 1)); diff --git a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/insertion/distances/RoutingDistanceCalculator.java b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/insertion/distances/RoutingDistanceCalculator.java index 31ec3a55e06..cf74ff360a1 100644 --- a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/insertion/distances/RoutingDistanceCalculator.java +++ b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/insertion/distances/RoutingDistanceCalculator.java @@ -19,7 +19,7 @@ public RoutingDistanceCalculator(LeastCostPathCalculator router, TravelTime trav // set this up in a more intelligent way, I'm not sure, but I guess that the // constraints are accesses in parallel by DRT. /sh nov'23 @Override - public synchronized double estimateDistance(double departureTime, Link fromLink, Link toLink) { + public synchronized double calculateDistance(double departureTime, Link fromLink, Link toLink) { VrpPathWithTravelData path = VrpPaths.calcAndCreatePath(fromLink, toLink, departureTime, router, travelTime); return VrpPaths.calcDistance(path); } diff --git a/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/estimator/MultiModaFixedDrtLegEstimatorTest.java b/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/estimator/MultiModaFixedDrtLegEstimatorTest.java new file mode 100644 index 00000000000..de1c98e62d1 --- /dev/null +++ b/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/estimator/MultiModaFixedDrtLegEstimatorTest.java @@ -0,0 +1,93 @@ +package org.matsim.contrib.drt.extension.estimator; + +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.matsim.application.MATSimApplication; +import org.matsim.contrib.drt.extension.DrtTestScenario; +import org.matsim.contrib.drt.extension.estimator.impl.ConstantDrtEstimator; +import org.matsim.contrib.drt.extension.estimator.run.DrtEstimatorConfigGroup; +import org.matsim.contrib.drt.extension.estimator.run.DrtEstimatorModule; +import org.matsim.contrib.drt.extension.estimator.run.MultiModeDrtEstimatorConfigGroup; +import org.matsim.core.config.Config; +import org.matsim.core.config.ConfigUtils; +import org.matsim.core.config.groups.ReplanningConfigGroup; +import org.matsim.core.controler.Controler; +import org.matsim.modechoice.InformedModeChoiceModule; +import org.matsim.modechoice.ModeOptions; +import org.matsim.modechoice.estimators.DefaultLegScoreEstimator; +import org.matsim.modechoice.estimators.FixedCostsEstimator; +import org.matsim.testcases.MatsimTestUtils; + +import java.io.File; +import java.util.List; +import java.util.stream.Collectors; + +import static org.assertj.core.api.Assertions.assertThat; + +public class MultiModaFixedDrtLegEstimatorTest { + + @Rule + public MatsimTestUtils utils = new MatsimTestUtils(); + + private Controler controler; + + private static void prepare(Controler controler) { + InformedModeChoiceModule.Builder builder = InformedModeChoiceModule.newBuilder() + .withFixedCosts(FixedCostsEstimator.DailyConstant.class, "car") + .withLegEstimator(DefaultLegScoreEstimator.class, ModeOptions.AlwaysAvailable.class, "bike", "walk", "pt") + .withLegEstimator(DefaultLegScoreEstimator.class, ModeOptions.ConsiderYesAndNo.class, "car") + .withLegEstimator(MultiModalDrtLegEstimator.class, ModeOptions.AlwaysAvailable.class, "drt", "av"); + + controler.addOverridingModule(builder.build()); + controler.addOverridingModule(new DrtEstimatorModule() + .withInitialEstimator(cfg -> new ConstantDrtEstimator(cfg, 1.05, 300), "drt", "av")); + } + + private static void prepare(Config config) { + + MultiModeDrtEstimatorConfigGroup estimators = ConfigUtils.addOrGetModule(config, MultiModeDrtEstimatorConfigGroup.class); + + estimators.addParameterSet(new DrtEstimatorConfigGroup("drt") + .withEstimator(DrtEstimatorConfigGroup.EstimatorType.INITIAL)); + estimators.addParameterSet(new DrtEstimatorConfigGroup("av")); + + // Set subtour mode selection as strategy + List strategies = config.replanning().getStrategySettings().stream() + .filter(s -> !s.getStrategyName().toLowerCase().contains("mode") + ).collect(Collectors.toList()); + + strategies.add(new ReplanningConfigGroup.StrategySettings() + .setStrategyName(InformedModeChoiceModule.SELECT_SUBTOUR_MODE_STRATEGY) + .setSubpopulation("person") + .setWeight(0.2)); + + config.replanning().clearStrategySettings(); + strategies.forEach(s -> config.replanning().addStrategySettings(s)); + + } + + @Before + public void setUp() throws Exception { + + Config config = DrtTestScenario.loadConfig(utils); + + config.controller().setLastIteration(3); + + controler = MATSimApplication.prepare(new DrtTestScenario(MultiModaFixedDrtLegEstimatorTest::prepare, MultiModaFixedDrtLegEstimatorTest::prepare), config); + } + + @Test + public void run() { + + String out = utils.getOutputDirectory(); + + controler.run(); + + assertThat(new File(out, "kelheim-mini-drt.drt_estimates_drt.csv")) + .exists() + .isNotEmpty(); + + + } +} diff --git a/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/insertion/DrtInsertionExtensionIT.java b/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/insertion/DrtInsertionExtensionIT.java index 3740da65f35..001bae2a1e7 100644 --- a/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/insertion/DrtInsertionExtensionIT.java +++ b/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/insertion/DrtInsertionExtensionIT.java @@ -16,7 +16,9 @@ import org.matsim.api.core.v01.IdSet; import org.matsim.api.core.v01.events.LinkEnterEvent; import org.matsim.api.core.v01.events.handler.LinkEnterEventHandler; +import org.matsim.api.core.v01.network.Link; import org.matsim.api.core.v01.network.Network; +import org.matsim.contrib.drt.extension.insertion.distances.DistanceApproximator; import org.matsim.contrib.drt.run.DrtConfigGroup; import org.matsim.contrib.drt.run.DrtControlerCreator; import org.matsim.contrib.drt.run.MultiModeDrtConfigGroup; @@ -33,6 +35,7 @@ import org.matsim.contrib.dvrp.passenger.PassengerRequestSubmittedEventHandler; import org.matsim.contrib.dvrp.passenger.PassengerWaitingEvent; import org.matsim.contrib.dvrp.passenger.PassengerWaitingEventHandler; +import org.matsim.contrib.dvrp.run.AbstractDvrpModeQSimModule; import org.matsim.contrib.dvrp.run.DvrpConfigGroup; import org.matsim.contrib.dvrp.vrpagent.TaskEndedEvent; import org.matsim.contrib.dvrp.vrpagent.TaskEndedEventHandler; @@ -41,6 +44,7 @@ import org.matsim.core.controler.AbstractModule; import org.matsim.core.controler.Controler; import org.matsim.core.controler.OutputDirectoryHierarchy.OverwriteFileSetting; +import org.matsim.core.utils.geometry.CoordUtils; import org.matsim.core.utils.io.IOUtils; import org.matsim.examples.ExamplesUtils; import org.matsim.testcases.MatsimTestUtils; @@ -254,6 +258,86 @@ public void testRangeConstraint() { } } + @Test + public void testRangeConstraintWithCustomInstances() { + Controler controller = createController(); + DrtConfigGroup drtConfig = DrtConfigGroup.getSingleModeDrtConfig(controller.getConfig()); + + CustomCalculator distanceCalculator = new CustomCalculator(); + CustomCalculator distanceApproximator = new CustomCalculator(); + + DrtInsertionModule insertionModule = new DrtInsertionModule(drtConfig) // + .withVehicleRange(100.0 * 1e3) // + .withDistanceCalculator(distanceCalculator) // + .withDistanceApproximator(distanceApproximator); + + controller.addOverridingQSimModule(insertionModule); + + DistanceHandler handler = new DistanceHandler(controller.getScenario().getNetwork()); + handler.install(controller); + + controller.run(); + + for (var item : handler.distances.entrySet()) { + assertTrue(item.getValue() < 100.0 * 1e3); + } + + assertEquals(1470, distanceCalculator.calculatedDistances); + assertEquals(5288, distanceApproximator.calculatedDistances); + } + + @Test + public void testRangeConstraintWithCustomInjection() { + Controler controller = createController(); + DrtConfigGroup drtConfig = DrtConfigGroup.getSingleModeDrtConfig(controller.getConfig()); + + CustomDistanceCalculator distanceCalculator = new CustomDistanceCalculator(); + CustomDistanceApproximator distanceApproximator = new CustomDistanceApproximator(); + + DrtInsertionModule insertionModule = new DrtInsertionModule(drtConfig) // + .withVehicleRange(100.0 * 1e3) // + .withDistanceCalculator(CustomDistanceCalculator.class) // + .withDistanceApproximator(CustomDistanceApproximator.class); + + controller.addOverridingQSimModule(insertionModule); + + controller.addOverridingQSimModule(new AbstractDvrpModeQSimModule("drt") { + @Override + protected void configureQSim() { + bindModal(CustomDistanceCalculator.class).toInstance(distanceCalculator); + bindModal(CustomDistanceApproximator.class).toInstance(distanceApproximator); + } + }); + + DistanceHandler handler = new DistanceHandler(controller.getScenario().getNetwork()); + handler.install(controller); + + controller.run(); + + for (var item : handler.distances.entrySet()) { + assertTrue(item.getValue() < 100.0 * 1e3); + } + + assertEquals(1470, distanceCalculator.calculatedDistances); + assertEquals(5288, distanceApproximator.calculatedDistances); + } + + static class CustomDistanceCalculator extends CustomCalculator { + } + + static class CustomDistanceApproximator extends CustomCalculator { + } + + static class CustomCalculator implements DistanceApproximator { + int calculatedDistances = 0; + + @Override + public synchronized double calculateDistance(double departureTime, Link fromLink, Link toLink) { + calculatedDistances++; + return CoordUtils.calcEuclideanDistance(fromLink.getCoord(), toLink.getCoord()); + } + } + static public class DistanceHandler implements LinkEnterEventHandler { private final Network network; private final IdMap distances = new IdMap<>(Vehicle.class); diff --git a/contribs/hybridsim/pom.xml b/contribs/hybridsim/pom.xml index 52fb9013346..cc8bcea53c5 100644 --- a/contribs/hybridsim/pom.xml +++ b/contribs/hybridsim/pom.xml @@ -11,7 +11,7 @@ 3.25.1 - 1.59.0 + 1.59.1 diff --git a/contribs/parking/src/test/java/org/matsim/contrib/parking/run/RunParkingSearchScenarioIT.java b/contribs/parking/src/test/java/org/matsim/contrib/parking/run/RunParkingSearchScenarioIT.java index eef6af3f609..ef761cedee2 100644 --- a/contribs/parking/src/test/java/org/matsim/contrib/parking/run/RunParkingSearchScenarioIT.java +++ b/contribs/parking/src/test/java/org/matsim/contrib/parking/run/RunParkingSearchScenarioIT.java @@ -17,38 +17,141 @@ * * * *********************************************************************** */ -/** - * - */ package org.matsim.contrib.parking.run; +import org.junit.Assert; import org.junit.Rule; import org.junit.Test; +import org.matsim.api.core.v01.Id; +import org.matsim.api.core.v01.population.Person; +import org.matsim.api.core.v01.population.Population; import org.matsim.contrib.parking.parkingsearch.ParkingSearchStrategy; import org.matsim.contrib.parking.parkingsearch.RunParkingSearchExample; import org.matsim.contrib.parking.parkingsearch.sim.ParkingSearchConfigGroup; import org.matsim.core.config.Config; import org.matsim.core.config.ConfigUtils; +import org.matsim.core.events.EventsUtils; +import org.matsim.core.population.PopulationUtils; import org.matsim.testcases.MatsimTestUtils; +import org.matsim.utils.eventsfilecomparison.EventsFileComparator; /** - * @author jbischoff - * + * @author jbischoff */ public class RunParkingSearchScenarioIT { - @Rule public MatsimTestUtils utils = new MatsimTestUtils() ; + @Rule + public MatsimTestUtils utils = new MatsimTestUtils(); + + @Test + public void testRunParkingBenesonStrategy() { + try { + String configFile = "./src/main/resources/parkingsearch/config.xml"; + Config config = ConfigUtils.loadConfig(configFile, new ParkingSearchConfigGroup()); + config.controller().setLastIteration(0); + config.controller().setOutputDirectory(utils.getOutputDirectory()); + + ParkingSearchConfigGroup configGroup = (ParkingSearchConfigGroup) config.getModules().get(ParkingSearchConfigGroup.GROUP_NAME); + configGroup.setParkingSearchStrategy(ParkingSearchStrategy.Benenson); + + new RunParkingSearchExample().run(config, false); + + } catch (Exception e) { + e.printStackTrace(); + Assert.fail("something went wrong"); + } + } @Test - public void testRunParking() { + public void testRunParkingRandomStrategy() { String configFile = "./src/main/resources/parkingsearch/config.xml"; Config config = ConfigUtils.loadConfig(configFile, new ParkingSearchConfigGroup()); config.controller().setLastIteration(0); - config.controller().setOutputDirectory( utils.getOutputDirectory() ); + config.controller().setOutputDirectory(utils.getOutputDirectory()); ParkingSearchConfigGroup configGroup = (ParkingSearchConfigGroup) config.getModules().get(ParkingSearchConfigGroup.GROUP_NAME); - configGroup.setParkingSearchStrategy(ParkingSearchStrategy.Benenson); + configGroup.setParkingSearchStrategy(ParkingSearchStrategy.Random); + + try { + new RunParkingSearchExample().run(config, false); + } catch (Exception e) { + e.printStackTrace(); + Assert.fail("something went wrong"); + } + } + + @Test + public void testRunParkingDistanceMemoryStrategy() { + try { + String configFile = "./src/main/resources/parkingsearch/config.xml"; + Config config = ConfigUtils.loadConfig(configFile, new ParkingSearchConfigGroup()); + config.controller().setLastIteration(0); + config.controller().setOutputDirectory(utils.getOutputDirectory()); + + ParkingSearchConfigGroup configGroup = (ParkingSearchConfigGroup) config.getModules().get(ParkingSearchConfigGroup.GROUP_NAME); + configGroup.setParkingSearchStrategy(ParkingSearchStrategy.DistanceMemory); + + new RunParkingSearchExample().run(config, false); + { + Population expected = PopulationUtils.createPopulation(ConfigUtils.createConfig()); + PopulationUtils.readPopulation(expected, utils.getInputDirectory() + "/output_plans.xml.gz"); + + Population actual = PopulationUtils.createPopulation(ConfigUtils.createConfig()); + PopulationUtils.readPopulation(actual, utils.getOutputDirectory() + "/output_plans.xml.gz"); + + for (Id personId : expected.getPersons().keySet()) { + double scoreReference = expected.getPersons().get(personId).getSelectedPlan().getScore(); + double scoreCurrent = actual.getPersons().get(personId).getSelectedPlan().getScore(); + Assert.assertEquals("Scores of person=" + personId + " are different", scoreReference, scoreCurrent, MatsimTestUtils.EPSILON); + } + + } + { + String expected = utils.getInputDirectory() + "/output_events.xml.gz"; + String actual = utils.getOutputDirectory() + "/output_events.xml.gz"; + EventsFileComparator.Result result = EventsUtils.compareEventsFiles(expected, actual); + Assert.assertEquals(EventsFileComparator.Result.FILES_ARE_EQUAL, result); + } + } catch (Exception e) { + e.printStackTrace(); + Assert.fail("something went wrong"); + } + } + + @Test + public void testRunParkingNearestParkingSpotStrategy() { + try { + String configFile = "./src/main/resources/parkingsearch/config.xml"; + Config config = ConfigUtils.loadConfig(configFile, new ParkingSearchConfigGroup()); + config.controller().setLastIteration(0); + config.controller().setOutputDirectory(utils.getOutputDirectory()); + + ParkingSearchConfigGroup configGroup = (ParkingSearchConfigGroup) config.getModules().get(ParkingSearchConfigGroup.GROUP_NAME); + configGroup.setParkingSearchStrategy(ParkingSearchStrategy.NearestParkingSpot); + + new RunParkingSearchExample().run(config, false); + { + Population expected = PopulationUtils.createPopulation(ConfigUtils.createConfig()); + PopulationUtils.readPopulation(expected, utils.getInputDirectory() + "/output_plans.xml.gz"); + + Population actual = PopulationUtils.createPopulation(ConfigUtils.createConfig()); + PopulationUtils.readPopulation(actual, utils.getOutputDirectory() + "/output_plans.xml.gz"); - new RunParkingSearchExample().run(config,false); + for (Id personId : expected.getPersons().keySet()) { + double scoreReference = expected.getPersons().get(personId).getSelectedPlan().getScore(); + double scoreCurrent = actual.getPersons().get(personId).getSelectedPlan().getScore(); + Assert.assertEquals("Scores of person=" + personId + " are different", scoreReference, scoreCurrent, MatsimTestUtils.EPSILON); + } + } + { + String expected = utils.getInputDirectory() + "/output_events.xml.gz"; + String actual = utils.getOutputDirectory() + "/output_events.xml.gz"; + EventsFileComparator.Result result = EventsUtils.compareEventsFiles(expected, actual); + Assert.assertEquals(EventsFileComparator.Result.FILES_ARE_EQUAL, result); + } + } catch (Exception e) { + e.printStackTrace(); + Assert.fail("something went wrong"); + } } } diff --git a/contribs/parking/test/input/org/matsim/contrib/parking/run/RunParkingSearchScenarioIT/testRunParkingDistanceMemoryStrategy/output_events.xml.gz b/contribs/parking/test/input/org/matsim/contrib/parking/run/RunParkingSearchScenarioIT/testRunParkingDistanceMemoryStrategy/output_events.xml.gz new file mode 100644 index 00000000000..e80c449a03b Binary files /dev/null and b/contribs/parking/test/input/org/matsim/contrib/parking/run/RunParkingSearchScenarioIT/testRunParkingDistanceMemoryStrategy/output_events.xml.gz differ diff --git a/contribs/parking/test/input/org/matsim/contrib/parking/run/RunParkingSearchScenarioIT/testRunParkingDistanceMemoryStrategy/output_plans.xml.gz b/contribs/parking/test/input/org/matsim/contrib/parking/run/RunParkingSearchScenarioIT/testRunParkingDistanceMemoryStrategy/output_plans.xml.gz new file mode 100644 index 00000000000..e2a50e6fa9a Binary files /dev/null and b/contribs/parking/test/input/org/matsim/contrib/parking/run/RunParkingSearchScenarioIT/testRunParkingDistanceMemoryStrategy/output_plans.xml.gz differ diff --git a/contribs/parking/test/input/org/matsim/contrib/parking/run/RunParkingSearchScenarioIT/testRunParkingNearestParkingSpotStrategy/output_events.xml.gz b/contribs/parking/test/input/org/matsim/contrib/parking/run/RunParkingSearchScenarioIT/testRunParkingNearestParkingSpotStrategy/output_events.xml.gz new file mode 100644 index 00000000000..630fb9fe02f Binary files /dev/null and b/contribs/parking/test/input/org/matsim/contrib/parking/run/RunParkingSearchScenarioIT/testRunParkingNearestParkingSpotStrategy/output_events.xml.gz differ diff --git a/contribs/parking/test/input/org/matsim/contrib/parking/run/RunParkingSearchScenarioIT/testRunParkingNearestParkingSpotStrategy/output_plans.xml.gz b/contribs/parking/test/input/org/matsim/contrib/parking/run/RunParkingSearchScenarioIT/testRunParkingNearestParkingSpotStrategy/output_plans.xml.gz new file mode 100644 index 00000000000..2ca0df2ede0 Binary files /dev/null and b/contribs/parking/test/input/org/matsim/contrib/parking/run/RunParkingSearchScenarioIT/testRunParkingNearestParkingSpotStrategy/output_plans.xml.gz differ diff --git a/matsim/LICENSE b/matsim/LICENSE index e28a6ab76d8..c3676097f92 100755 --- a/matsim/LICENSE +++ b/matsim/LICENSE @@ -1,14 +1,9 @@ ########################################################################### -org.matsim java packages - -Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012 by - Kay W. Axhausen, Michael Balmer, Christoph Dobler, Thibaut Dubernet, - Dominik Grether,Andreas Horni, Gregor Laemmel, Nicolas Lefebvre, - Fabrice Marchal, Konrad Meister, Kai Nagel, Andreas Neumann, - Marcel Rieser, David Strippgen, Rashid Waraich, Michael Zilske, - Technische Universitaet Berlin (TU-Berlin) and - Swiss Federal Institute of Technology Zurich (ETHZ) +org.matsim +and ch.sbb.matsim java packages +Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023 by + The MATSim Contributors This program is free software; you can redistribute it and/or modify diff --git a/matsim/WARRANTY b/matsim/WARRANTY index 450ba1b281c..ff03dcd5ce2 100755 --- a/matsim/WARRANTY +++ b/matsim/WARRANTY @@ -1,12 +1,7 @@ ########################################################################### -Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012 by - Kay W. Axhausen, Michael Balmer, Christoph Dobler, Thibaut Dubernet, - Dominik Grether,Andreas Horni, Gregor Laemmel, Nicolas Lefebvre, - Fabrice Marchal, Konrad Meister, Kai Nagel, Andreas Neumann, - Marcel Rieser, David Strippgen, Rashid Waraich, Michael Zilske, - Technische Universitaet Berlin (TU-Berlin) and - Swiss Federal Institute of Technology Zurich (ETHZ) +Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023 by + The MATSim Contributors The org.matsim java packages are distributed in the hope that they will