From cfa2fa7100bde1ddd97161a770fb61ad162fefa1 Mon Sep 17 00:00:00 2001 From: nkuehnel Date: Wed, 12 Jun 2024 00:48:17 +0200 Subject: [PATCH] add missing classes --- .../constraints/ConstraintSetChooser.java | 14 ++++++ .../DefaultDrtRouteConstraintsCalculator.java | 45 +++++++++++++++++++ .../DrtRouteConstraintsCalculator.java | 13 ++++++ 3 files changed, 72 insertions(+) create mode 100644 contribs/drt/src/main/java/org/matsim/contrib/drt/optimizer/constraints/ConstraintSetChooser.java create mode 100644 contribs/drt/src/main/java/org/matsim/contrib/drt/routing/DefaultDrtRouteConstraintsCalculator.java create mode 100644 contribs/drt/src/main/java/org/matsim/contrib/drt/routing/DrtRouteConstraintsCalculator.java diff --git a/contribs/drt/src/main/java/org/matsim/contrib/drt/optimizer/constraints/ConstraintSetChooser.java b/contribs/drt/src/main/java/org/matsim/contrib/drt/optimizer/constraints/ConstraintSetChooser.java new file mode 100644 index 00000000000..2be22eeb9d8 --- /dev/null +++ b/contribs/drt/src/main/java/org/matsim/contrib/drt/optimizer/constraints/ConstraintSetChooser.java @@ -0,0 +1,14 @@ +package org.matsim.contrib.drt.optimizer.constraints; + +import org.matsim.api.core.v01.network.Link; +import org.matsim.api.core.v01.population.Person; +import org.matsim.utils.objectattributes.attributable.Attributes; + +/** + * @author nkuehnel / MOIA + */ +public interface ConstraintSetChooser { + + DrtOptimizationConstraintsSet chooseConstraintSet(double departureTime, Link accessActLink, Link egressActLink, Person person, + Attributes tripAttributes); +} diff --git a/contribs/drt/src/main/java/org/matsim/contrib/drt/routing/DefaultDrtRouteConstraintsCalculator.java b/contribs/drt/src/main/java/org/matsim/contrib/drt/routing/DefaultDrtRouteConstraintsCalculator.java new file mode 100644 index 00000000000..039890d8801 --- /dev/null +++ b/contribs/drt/src/main/java/org/matsim/contrib/drt/routing/DefaultDrtRouteConstraintsCalculator.java @@ -0,0 +1,45 @@ +package org.matsim.contrib.drt.routing; + +import org.matsim.contrib.drt.optimizer.constraints.DefaultDrtOptimizationConstraintsSet; +import org.matsim.contrib.drt.optimizer.constraints.DrtOptimizationConstraintsSet; + +/** + * @author nkuehnel / MOIA + */ +public class DefaultDrtRouteConstraintsCalculator implements DrtRouteConstraintsCalculator { + + /** + * Calculates the maximum travel time defined as: drtCfg.getMaxTravelTimeAlpha() * unsharedRideTime + drtCfg.getMaxTravelTimeBeta() + * + * @param constraintsSet + * @param unsharedRideTime ride time of the direct (shortest-time) route + * @return maximum travel time + */ + @Override + public double getMaxTravelTime(DrtOptimizationConstraintsSet constraintsSet, double unsharedRideTime) { + if(constraintsSet instanceof DefaultDrtOptimizationConstraintsSet defaultSet) { + return defaultSet.maxTravelTimeAlpha * unsharedRideTime + + defaultSet.maxTravelTimeBeta; + } else { + throw new IllegalArgumentException("Constraint set is not a default set"); + } + } + + /** + * Calculates the maximum ride time defined as: drtCfg.maxDetourAlpha * unsharedRideTime + drtCfg.maxDetourBeta + * + * @param constraintsSet + * @param unsharedRideTime ride time of the direct (shortest-time) route + * @return maximum ride time + */ + @Override + public double getMaxRideTime(DrtOptimizationConstraintsSet constraintsSet, double unsharedRideTime) { + if(constraintsSet instanceof DefaultDrtOptimizationConstraintsSet defaultSet) { + return Math.min(unsharedRideTime + defaultSet.maxAbsoluteDetour, + defaultSet.maxDetourAlpha * unsharedRideTime + + defaultSet.maxDetourBeta); + } else { + throw new IllegalArgumentException("Constraint set is not a default set"); + } + } +} \ No newline at end of file diff --git a/contribs/drt/src/main/java/org/matsim/contrib/drt/routing/DrtRouteConstraintsCalculator.java b/contribs/drt/src/main/java/org/matsim/contrib/drt/routing/DrtRouteConstraintsCalculator.java new file mode 100644 index 00000000000..a22a942f35a --- /dev/null +++ b/contribs/drt/src/main/java/org/matsim/contrib/drt/routing/DrtRouteConstraintsCalculator.java @@ -0,0 +1,13 @@ +package org.matsim.contrib.drt.routing; + +import org.matsim.contrib.drt.optimizer.constraints.DrtOptimizationConstraintsSet; + +/** + * @author nkuehnel / MOIA + */ +public interface DrtRouteConstraintsCalculator { + + double getMaxTravelTime(DrtOptimizationConstraintsSet constraintsSet, double unsharedRideTime); + + double getMaxRideTime(DrtOptimizationConstraintsSet constraintsSet, double unsharedRideTime); +}