Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/maven/geotools.version-31.2
Browse files Browse the repository at this point in the history
  • Loading branch information
jfbischoff authored Jun 19, 2024
2 parents 7e84b62 + 641a44d commit baeaa74
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
import org.matsim.api.core.v01.population.Person;
import org.matsim.utils.objectattributes.attributable.Attributes;

import java.util.Optional;

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

DrtOptimizationConstraintsSet chooseConstraintSet(double departureTime, Link accessActLink, Link egressActLink, Person person,
Attributes tripAttributes);
Optional<DrtOptimizationConstraintsSet> chooseConstraintSet(double departureTime, Link accessActLink,
Link egressActLink, Person person, Attributes tripAttributes);
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.matsim.api.core.v01.population.Person;
import org.matsim.api.core.v01.population.Route;
import org.matsim.contrib.drt.optimizer.constraints.ConstraintSetChooser;
import org.matsim.contrib.drt.optimizer.constraints.DefaultDrtOptimizationConstraintsSet;
import org.matsim.contrib.drt.optimizer.constraints.DrtOptimizationConstraintsSet;
import org.matsim.contrib.drt.run.DrtConfigGroup;
import org.matsim.contrib.dvrp.path.VrpPathWithTravelData;
Expand Down Expand Up @@ -72,7 +71,9 @@ public Route createRoute(double departureTime, Link accessActLink, Link egressAc
double unsharedRideTime = unsharedPath.getTravelTime();//includes first & last link
double unsharedDistance = VrpPaths.calcDistance(unsharedPath);//includes last link

DrtOptimizationConstraintsSet constraintsSet = constraintSetChooser.chooseConstraintSet(departureTime, accessActLink, egressActLink, person, tripAttributes);
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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@

import java.net.URL;
import java.util.List;
import java.util.Optional;

/**
* This is a DRT-customised version of DvrpModeRoutingModule
Expand Down Expand Up @@ -100,7 +101,7 @@ public void install() {
DefaultDrtOptimizationConstraintsSet optimizationConstraintsSet = drtCfg.addOrGetDrtOptimizationConstraintsParams().addOrGetDefaultDrtOptimizationConstraintsSet();
bindModal(ConstraintSetChooser.class).toProvider(
() -> (departureTime, accessActLink, egressActLink, person, tripAttributes)
-> optimizationConstraintsSet
-> Optional.of(optimizationConstraintsSet)
).in(Singleton.class);

switch( drtCfg.operationalScheme ){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ final void testMaterializeAfterReadDrtConstraints() {
}

@Test
final void testMaterializeAfterReadStandardParams3() {
final void testMaterializeAfterReadCustomDrtConstraints() {
{
// generate a test config that sets two values away from their defaults, and write it to file:
Config config = ConfigUtils.createConfig();
Expand All @@ -142,13 +142,13 @@ final void testMaterializeAfterReadStandardParams3() {

{
// load config file without materializing the drt config group
MultiModeDrtConfigGroup multiModeDrtConfigGroup1 =
MultiModeDrtConfigGroup multiModeDrtConfigGroup =
new MultiModeDrtConfigGroup(() -> new DrtConfigGroup(CustomConstraintsSet::new));

Config config = ConfigUtils.loadConfig( new String[] { utils.getOutputDirectory() + "ad-hoc-config-custom-optimization-constraints.xml"}, multiModeDrtConfigGroup1);
Config config = ConfigUtils.loadConfig( new String[] { utils.getOutputDirectory() + "ad-hoc-config-custom-optimization-constraints.xml"}, multiModeDrtConfigGroup);

// materialize the config group
MultiModeDrtConfigGroup multiModeDrtConfigGroup = ConfigUtils.addOrGetModule( config, MultiModeDrtConfigGroup.class );
//MultiModeDrtConfigGroup multiModeDrtConfigGroup = ConfigUtils.addOrGetModule( config, MultiModeDrtConfigGroup.class );
DrtConfigGroup drtConfigGroup = multiModeDrtConfigGroup.getModalElements().iterator().next();

// check if you are getting back the values from the config file:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@

package org.matsim.contrib.drt.routing;

import java.util.Arrays;
import java.util.List;

import com.google.common.collect.ImmutableMap;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
Expand All @@ -30,15 +28,8 @@
import org.matsim.api.core.v01.Scenario;
import org.matsim.api.core.v01.TransportMode;
import org.matsim.api.core.v01.network.Link;
import org.matsim.api.core.v01.population.Activity;
import org.matsim.api.core.v01.population.Leg;
import org.matsim.api.core.v01.population.Person;
import org.matsim.api.core.v01.population.Plan;
import org.matsim.api.core.v01.population.PlanElement;
import org.matsim.api.core.v01.population.PopulationFactory;
import org.matsim.contrib.drt.optimizer.constraints.ConstraintSetChooser;
import org.matsim.api.core.v01.population.*;
import org.matsim.contrib.drt.optimizer.constraints.DefaultDrtOptimizationConstraintsSet;
import org.matsim.contrib.drt.optimizer.constraints.DrtOptimizationConstraintsSet;
import org.matsim.contrib.drt.run.DrtConfigGroup;
import org.matsim.contrib.drt.run.DrtControlerCreator;
import org.matsim.contrib.drt.run.MultiModeDrtConfigGroup;
Expand All @@ -63,8 +54,9 @@
import org.matsim.pt.transitSchedule.api.TransitScheduleReader;
import org.matsim.testcases.MatsimTestUtils;

import com.google.common.collect.ImmutableMap;
import org.matsim.utils.objectattributes.attributable.Attributes;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;

/**
* @author jbischoff
Expand Down Expand Up @@ -102,7 +94,7 @@ void testCottbusClosestAccessEgressStopFinder() {
DrtRouteCreator drtRouteCreator = new DrtRouteCreator(drtCfg, scenario.getNetwork(),
new SpeedyDijkstraFactory(), new FreeSpeedTravelTime(), TimeAsTravelDisutility::new,
new DefaultDrtRouteConstraintsCalculator(),
(departureTime, accessActLink, egressActLink, person, tripAttributes) -> defaultConstraintsSet);
(departureTime, accessActLink, egressActLink, person, tripAttributes) -> Optional.of(defaultConstraintsSet));
DefaultMainLegRouter mainRouter = new DefaultMainLegRouter(drtMode, scenario.getNetwork(),
scenario.getPopulation().getFactory(), drtRouteCreator);
DvrpRoutingModule dvrpRoutingModule = new DvrpRoutingModule(mainRouter, walkRouter, walkRouter, stopFinder,
Expand Down

0 comments on commit baeaa74

Please sign in to comment.