Skip to content

Commit

Permalink
feat: flexibilize DrtRouteConstraintsCalculator
Browse files Browse the repository at this point in the history
  • Loading branch information
sebhoerl committed Sep 12, 2024
1 parent 33c07d3 commit 8032b2d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package org.matsim.contrib.drt.routing;

import org.matsim.api.core.v01.population.Person;
import org.matsim.contrib.drt.optimizer.constraints.DefaultDrtOptimizationConstraintsSet;
import org.matsim.contrib.drt.optimizer.constraints.DrtOptimizationConstraintsSet;
import org.matsim.utils.objectattributes.attributable.Attributes;

/**
* @author nkuehnel / MOIA
Expand All @@ -16,7 +18,7 @@ public class DefaultDrtRouteConstraintsCalculator implements DrtRouteConstraints
* @return maximum travel time
*/
@Override
public double getMaxTravelTime(DrtOptimizationConstraintsSet constraintsSet, double unsharedRideTime) {
public double getMaxTravelTime(DrtOptimizationConstraintsSet constraintsSet, double unsharedRideTime, Person person, Attributes attributes) {
if(constraintsSet instanceof DefaultDrtOptimizationConstraintsSet defaultSet) {
return defaultSet.maxTravelTimeAlpha * unsharedRideTime
+ defaultSet.maxTravelTimeBeta;
Expand All @@ -33,7 +35,7 @@ public double getMaxTravelTime(DrtOptimizationConstraintsSet constraintsSet, dou
* @return maximum ride time
*/
@Override
public double getMaxRideTime(DrtOptimizationConstraintsSet constraintsSet, double unsharedRideTime) {
public double getMaxRideTime(DrtOptimizationConstraintsSet constraintsSet, double unsharedRideTime, Person person, Attributes attributes) {
if(constraintsSet instanceof DefaultDrtOptimizationConstraintsSet defaultSet) {
return Math.min(unsharedRideTime + defaultSet.maxAbsoluteDetour,
defaultSet.maxDetourAlpha * unsharedRideTime
Expand All @@ -42,4 +44,14 @@ public double getMaxRideTime(DrtOptimizationConstraintsSet constraintsSet, doubl
throw new IllegalArgumentException("Constraint set is not a default set");
}
}

@Override
public double getMaxWaitTime(DrtOptimizationConstraintsSet constraintsSet, double unsharedRideTime, Person person,
Attributes tripAttributes) {
if(constraintsSet instanceof DefaultDrtOptimizationConstraintsSet defaultSet) {
return constraintsSet.maxWaitTime;
} else {
throw new IllegalArgumentException("Constraint set is not a default set");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package org.matsim.contrib.drt.routing;

import org.matsim.api.core.v01.population.Person;
import org.matsim.contrib.drt.optimizer.constraints.DrtOptimizationConstraintsSet;
import org.matsim.utils.objectattributes.attributable.Attributes;

/**
* @author nkuehnel / MOIA
*/
public interface DrtRouteConstraintsCalculator {

double getMaxTravelTime(DrtOptimizationConstraintsSet constraintsSet, double unsharedRideTime);
double getMaxTravelTime(DrtOptimizationConstraintsSet constraintsSet, double unsharedRideTime, Person person, Attributes tripAttributes);

double getMaxRideTime(DrtOptimizationConstraintsSet constraintsSet, double unsharedRideTime);
double getMaxRideTime(DrtOptimizationConstraintsSet constraintsSet, double unsharedRideTime, Person person, Attributes tripAttributes);

double getMaxWaitTime(DrtOptimizationConstraintsSet constraintsSet, double unsharedRideTime, Person person, Attributes tripAttributes);
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,16 @@ public Route createRoute(double departureTime, Link accessActLink, Link egressAc
DrtOptimizationConstraintsSet constraintsSet =
constraintSetChooser.chooseConstraintSet(departureTime, accessActLink, egressActLink, person, tripAttributes)
.orElse(drtCfg.addOrGetDrtOptimizationConstraintsParams().addOrGetDefaultDrtOptimizationConstraintsSet());
double maxTravelTime = routeConstraintsCalculator.getMaxTravelTime(constraintsSet, unsharedRideTime);
double maxRideDuration = routeConstraintsCalculator.getMaxRideTime(constraintsSet, unsharedRideTime);
double maxTravelTime = routeConstraintsCalculator.getMaxTravelTime(constraintsSet, unsharedRideTime, person, tripAttributes);
double maxRideDuration = routeConstraintsCalculator.getMaxRideTime(constraintsSet, unsharedRideTime, person, tripAttributes);
double maxWaitTime = routeConstraintsCalculator.getMaxWaitTime(constraintsSet, unsharedRideTime, person, tripAttributes);

DrtRoute route = routeFactories.createRoute(DrtRoute.class, accessActLink.getId(), egressActLink.getId());
route.setDistance(unsharedDistance);
route.setTravelTime(maxTravelTime);
route.setMaxRideTime(maxRideDuration);
route.setDirectRideTime(unsharedRideTime);
route.setMaxWaitTime(constraintsSet.maxWaitTime);
route.setMaxWaitTime(maxWaitTime);

if (this.drtCfg.storeUnsharedPath) {
route.setUnsharedPath(unsharedPath);
Expand Down

0 comments on commit 8032b2d

Please sign in to comment.