From aa8910d2f31552b400ddbe428717d46f195d4898 Mon Sep 17 00:00:00 2001 From: balacmi Date: Mon, 30 Sep 2024 15:37:46 +0200 Subject: [PATCH 01/19] Update pom.xml update to matsim 2024.0 update java to 21 add common module --- pom.xml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 4463ccb..7e3834d 100644 --- a/pom.xml +++ b/pom.xml @@ -10,9 +10,9 @@ UTF-8 - 13.0 - 11 - 11 + 2024.0 + 21 + 21 @@ -90,6 +90,11 @@ discrete_mode_choice ${matsim.version} + + org.matsim.contrib + common + ${matsim.version} + junit junit From 42f459af8a4f75a835951177d04426d14eb576ae Mon Sep 17 00:00:00 2001 From: balacmi Date: Mon, 30 Sep 2024 15:38:12 +0200 Subject: [PATCH 02/19] Update corsica_config.xml Update config file to the matsim 2024.0 --- src/test/resources/corsica/corsica_config.xml | 91 ++++++++++--------- 1 file changed, 48 insertions(+), 43 deletions(-) diff --git a/src/test/resources/corsica/corsica_config.xml b/src/test/resources/corsica/corsica_config.xml index b088918..b55f72e 100644 --- a/src/test/resources/corsica/corsica_config.xml +++ b/src/test/resources/corsica/corsica_config.xml @@ -10,7 +10,7 @@ - + @@ -20,7 +20,7 @@ - + @@ -107,6 +107,10 @@ + + + + @@ -137,7 +141,7 @@ - @@ -145,7 +149,7 @@ - + @@ -157,7 +161,7 @@ - + @@ -182,15 +186,16 @@ + + + - - - - + + @@ -228,11 +233,6 @@ - - - - - @@ -248,10 +248,21 @@ - - + + + + + + + + + + + + + @@ -261,7 +272,7 @@ - + @@ -274,6 +285,8 @@ + + @@ -301,7 +314,7 @@ - + @@ -511,7 +524,7 @@ - + @@ -611,8 +624,12 @@ + + + + @@ -640,27 +657,11 @@ - - - - - - - - - - - - - - - - - - - + + + @@ -676,7 +677,7 @@ - + @@ -689,7 +690,7 @@ - + @@ -758,6 +759,10 @@ + + + + @@ -766,6 +771,8 @@ + + @@ -807,8 +814,6 @@ - - @@ -828,4 +833,4 @@ - + \ No newline at end of file From 0d872d849c41cff6de633292c5eafe4a2ebd57f4 Mon Sep 17 00:00:00 2001 From: balacmi Date: Mon, 30 Sep 2024 15:38:41 +0200 Subject: [PATCH 03/19] Create CSVReaders.java add our own csvreaders class as it does not exist in matsim anymore --- .../infrastructure/readers/CSVReaders.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/main/java/net/bhl/matsim/uam/infrastructure/readers/CSVReaders.java diff --git a/src/main/java/net/bhl/matsim/uam/infrastructure/readers/CSVReaders.java b/src/main/java/net/bhl/matsim/uam/infrastructure/readers/CSVReaders.java new file mode 100644 index 0000000..ee274c3 --- /dev/null +++ b/src/main/java/net/bhl/matsim/uam/infrastructure/readers/CSVReaders.java @@ -0,0 +1,34 @@ +package net.bhl.matsim.uam.infrastructure.readers; + +import com.opencsv.CSVParser; +import com.opencsv.CSVParserBuilder; +import com.opencsv.CSVReader; +import com.opencsv.CSVReaderBuilder; +import com.opencsv.exceptions.CsvException; +import org.matsim.core.utils.io.IOUtils; + +import java.io.IOException; +import java.util.List; + +public class CSVReaders { + public static List readTSV(String file) { + return readFile(file, '\t'); + } + + public static List readCSV(String file) { + return readFile(file, CSVParser.DEFAULT_SEPARATOR); + } + + public static List readSemicolonSV(String file) { + return readFile(file, ';'); + } + + public static List readFile(String file, char separator) { + try (CSVReader reader = new CSVReaderBuilder(IOUtils.getBufferedReader(file)) + .withCSVParser(new CSVParserBuilder().withSeparator(separator).build()).build()) { + return reader.readAll(); + } catch (IOException | CsvException e) { + throw new IllegalArgumentException(e); + } + } +} \ No newline at end of file From c3b722911956ab74c0220d53e437d14fd715c5ed Mon Sep 17 00:00:00 2001 From: balacmi Date: Tue, 1 Oct 2024 10:22:38 +0200 Subject: [PATCH 04/19] fix logger and config module names --- .../analysis/traveltimes/RunCalculateCarTravelTimes.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/bhl/matsim/uam/analysis/traveltimes/RunCalculateCarTravelTimes.java b/src/main/java/net/bhl/matsim/uam/analysis/traveltimes/RunCalculateCarTravelTimes.java index 39be428..c58f8b3 100644 --- a/src/main/java/net/bhl/matsim/uam/analysis/traveltimes/RunCalculateCarTravelTimes.java +++ b/src/main/java/net/bhl/matsim/uam/analysis/traveltimes/RunCalculateCarTravelTimes.java @@ -5,7 +5,9 @@ import net.bhl.matsim.uam.analysis.traveltimes.utils.TripItem; import net.bhl.matsim.uam.analysis.traveltimes.utils.TripItemReader; import net.bhl.matsim.uam.config.UAMConfigGroup; -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.TransportMode; import org.matsim.api.core.v01.network.Link; @@ -43,7 +45,7 @@ public class RunCalculateCarTravelTimes { private static final int processes = Runtime.getRuntime().availableProcessors(); - private static final Logger log = Logger.getLogger(RunCalculateCarTravelTimes.class); + private static final Logger log = LogManager.getLogger(RunCalculateCarTravelTimes.class); private static ArrayBlockingQueue carRouters = new ArrayBlockingQueue<>(processes); private static boolean writeDescription = true; @@ -80,7 +82,7 @@ public static void main(String[] args) throws Exception { TravelTimeCalculator ttc = builder.build(); TravelTime travelTime = ttc.getLinkTravelTimes(); TravelDisutility travelDisutility = TravelDisutilityUtils - .createFreespeedTravelTimeAndDisutility(config.planCalcScore()); + .createFreespeedTravelTimeAndDisutility(config.scoring()); com.google.inject.Injector injector = Injector.createInjector(config, new AbstractModule() { @Override From 57cee727e24293b589dca13b2deb99d4ae458833 Mon Sep 17 00:00:00 2001 From: balacmi Date: Tue, 1 Oct 2024 10:22:56 +0200 Subject: [PATCH 05/19] fix logger, config module names and router calls --- .../RunCalculatePTTravelTimes.java | 44 ++++++++++++------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/src/main/java/net/bhl/matsim/uam/analysis/traveltimes/RunCalculatePTTravelTimes.java b/src/main/java/net/bhl/matsim/uam/analysis/traveltimes/RunCalculatePTTravelTimes.java index e76a679..2457b6a 100644 --- a/src/main/java/net/bhl/matsim/uam/analysis/traveltimes/RunCalculatePTTravelTimes.java +++ b/src/main/java/net/bhl/matsim/uam/analysis/traveltimes/RunCalculatePTTravelTimes.java @@ -11,20 +11,25 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -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.TransportMode; import org.matsim.api.core.v01.network.Link; import org.matsim.api.core.v01.network.Network; import org.matsim.api.core.v01.population.Leg; +import org.matsim.api.core.v01.population.PlanElement; import org.matsim.core.config.Config; import org.matsim.core.config.ConfigUtils; import org.matsim.core.network.NetworkUtils; +import org.matsim.core.router.DefaultRoutingRequest; import org.matsim.core.router.LinkWrapperFacility; import org.matsim.core.router.RoutingModule; +import org.matsim.core.router.RoutingRequest; import org.matsim.core.router.TeleportationRoutingModule; import org.matsim.core.scenario.ScenarioUtils; import org.matsim.pt.router.TransitRouter; +import org.matsim.utils.objectattributes.attributable.AttributesImpl; import com.opencsv.CSVParser; @@ -53,7 +58,7 @@ public class RunCalculatePTTravelTimes { private static final int processes = Runtime.getRuntime().availableProcessors(); - private static final Logger log = Logger.getLogger(RunCalculatePTTravelTimes.class); + private static final Logger log = LogManager.getLogger(RunCalculatePTTravelTimes.class); private static ArrayBlockingQueue ptRouters = new ArrayBlockingQueue<>(processes); private static boolean writeDescription = true; @@ -175,23 +180,30 @@ public void run() { Link to = NetworkUtils.getNearestLink(network, trip.destination); try { - List legs = transitRouter.calcRoute(new LinkWrapperFacility(from), - new LinkWrapperFacility(to), trip.departureTime, null); + RoutingRequest routingRequest = DefaultRoutingRequest.of( + new LinkWrapperFacility(from), + new LinkWrapperFacility(to), + trip.departureTime, + null, + new AttributesImpl()); + List elements = transitRouter.calcRoute(routingRequest); double time = 0; double distance = 0; StringBuilder routeList = new StringBuilder(); - for (Leg leg : legs) { - if (time != 0 && writeDescription) - routeList.append("->"); - time += leg.getTravelTime().seconds(); - distance += leg.getRoute().getDistance(); - if (writeDescription) { - routeList.append("[mode:").append(leg.getMode()).append("]"); - routeList.append("[start:").append(leg.getRoute().getStartLinkId()).append("]"); - routeList.append("[end:").append(leg.getRoute().getEndLinkId()).append("]"); - routeList.append("[time:").append(leg.getTravelTime()).append("]"); - routeList.append("[distance:").append(leg.getRoute().getDistance()).append("]"); - } + for (PlanElement el : elements) { + if (el instanceof Leg) { + if (time != 0 && writeDescription) + routeList.append("->"); + time += ((Leg)el).getTravelTime().seconds(); + distance += ((Leg)el).getRoute().getDistance(); + if (writeDescription) { + routeList.append("[mode:").append(((Leg)el).getMode()).append("]"); + routeList.append("[start:").append(((Leg)el).getRoute().getStartLinkId()).append("]"); + routeList.append("[end:").append(((Leg)el).getRoute().getEndLinkId()).append("]"); + routeList.append("[time:").append(((Leg)el).getTravelTime()).append("]"); + routeList.append("[distance:").append(((Leg)el).getRoute().getDistance()).append("]"); + } + } } trip.travelTime = time; trip.distance = distance; From a93649101ec7a6b22103433f9a554cbe7bd44241 Mon Sep 17 00:00:00 2001 From: balacmi Date: Tue, 1 Oct 2024 10:25:07 +0200 Subject: [PATCH 06/19] fix logger, config module names and router calls --- .../RunCalculateUAMTravelTimes.java | 7 +- .../uamroutes/run/RunCalculateUAMRoutes.java | 2 +- .../bhl/matsim/uam/config/UAMConfigGroup.java | 14 +- .../uam/data/UAMStationConnectionGraph.java | 5 +- .../infrastructure/readers/UAMXMLReader.java | 15 +- .../uam/listeners/UAMShutdownListener.java | 5 +- .../UAMCachedIntermodalRoutingModule.java | 146 ++++++++++-------- .../strategy/UAMPredefinedStrategy.java | 6 +- .../router/strategy/UAMStrategyRouter.java | 5 +- .../uam/router/strategy/UAMStrategyUtils.java | 34 ++-- .../bhl/matsim/uam/run/RunUAMScenario.java | 18 ++- .../utils/ConfigAddUAMParameters.java | 11 +- 12 files changed, 159 insertions(+), 109 deletions(-) diff --git a/src/main/java/net/bhl/matsim/uam/analysis/traveltimes/RunCalculateUAMTravelTimes.java b/src/main/java/net/bhl/matsim/uam/analysis/traveltimes/RunCalculateUAMTravelTimes.java index 7893c66..acb172d 100644 --- a/src/main/java/net/bhl/matsim/uam/analysis/traveltimes/RunCalculateUAMTravelTimes.java +++ b/src/main/java/net/bhl/matsim/uam/analysis/traveltimes/RunCalculateUAMTravelTimes.java @@ -14,7 +14,8 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -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.TransportMode; import org.matsim.api.core.v01.network.Link; @@ -80,7 +81,7 @@ public class RunCalculateUAMTravelTimes { private static final int processes = Runtime.getRuntime().availableProcessors(); - private static final Logger log = Logger.getLogger(RunCalculateUAMTravelTimes.class); + private static final Logger log = LogManager.getLogger(RunCalculateUAMTravelTimes.class); private static ArrayBlockingQueue carRouters = new ArrayBlockingQueue<>(processes); private static ArrayBlockingQueue ptRouters = new ArrayBlockingQueue<>(processes); private static ArrayBlockingQueue uamRouters = new ArrayBlockingQueue<>(processes); @@ -131,7 +132,7 @@ public static void main(String[] args) throws Exception { TravelTimeCalculator ttc = builder.build(); TravelTime travelTime = ttc.getLinkTravelTimes(); TravelDisutility travelDisutility = TravelDisutilityUtils - .createFreespeedTravelTimeAndDisutility(config.planCalcScore()); + .createFreespeedTravelTimeAndDisutility(config.scoring()); com.google.inject.Injector injector = Injector.createInjector(config, new AbstractModule() { @Override diff --git a/src/main/java/net/bhl/matsim/uam/analysis/uamroutes/run/RunCalculateUAMRoutes.java b/src/main/java/net/bhl/matsim/uam/analysis/uamroutes/run/RunCalculateUAMRoutes.java index 0aee7d1..bb2c46c 100644 --- a/src/main/java/net/bhl/matsim/uam/analysis/uamroutes/run/RunCalculateUAMRoutes.java +++ b/src/main/java/net/bhl/matsim/uam/analysis/uamroutes/run/RunCalculateUAMRoutes.java @@ -72,7 +72,7 @@ static public void extract(String networkString, String uamVehicles, String outf static public UAMStationConnectionGraph calculateRoutes(UAMXMLReader uamReader) { TravelTime tt = new FreeSpeedTravelTime(); TravelDisutility td = TravelDisutilityUtils - .createFreespeedTravelTimeAndDisutility(ConfigUtils.createConfig().planCalcScore()); + .createFreespeedTravelTimeAndDisutility(ConfigUtils.createConfig().scoring()); UAMStations uamStations = new UAMStations(uamReader.getStations(), uamReader.network); UAMManager uamManager = new UAMManager(uamReader.network, uamStations, uamReader.getVehicles()); diff --git a/src/main/java/net/bhl/matsim/uam/config/UAMConfigGroup.java b/src/main/java/net/bhl/matsim/uam/config/UAMConfigGroup.java index 93fff8b..5a96aec 100644 --- a/src/main/java/net/bhl/matsim/uam/config/UAMConfigGroup.java +++ b/src/main/java/net/bhl/matsim/uam/config/UAMConfigGroup.java @@ -6,16 +6,16 @@ import java.util.Set; import java.util.stream.Collectors; -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.NotEmpty; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Positive; - -import org.apache.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.matsim.core.config.Config; import org.matsim.core.config.ReflectiveConfigGroup; import org.matsim.core.config.consistency.BeanValidationConfigConsistencyChecker; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotEmpty; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Positive; import net.bhl.matsim.uam.router.strategy.UAMStrategy.UAMStrategyType; /** @@ -26,7 +26,7 @@ * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) */ public class UAMConfigGroup extends ReflectiveConfigGroup { - private static final Logger log = Logger.getLogger(UAMConfigGroup.class); + private static final Logger log = LogManager.getLogger(UAMConfigGroup.class); public static final String GROUP_NAME = "uam"; diff --git a/src/main/java/net/bhl/matsim/uam/data/UAMStationConnectionGraph.java b/src/main/java/net/bhl/matsim/uam/data/UAMStationConnectionGraph.java index c2e49c5..41f4af7 100644 --- a/src/main/java/net/bhl/matsim/uam/data/UAMStationConnectionGraph.java +++ b/src/main/java/net/bhl/matsim/uam/data/UAMStationConnectionGraph.java @@ -5,7 +5,8 @@ import java.util.HashMap; import java.util.Map; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.matsim.api.core.v01.Id; import org.matsim.api.core.v01.network.Link; import org.matsim.core.router.util.LeastCostPathCalculator; @@ -26,7 +27,7 @@ */ public class UAMStationConnectionGraph { - final private static Logger log = Logger.getLogger(UAMStationConnectionGraph.class); + final private static Logger log = LogManager.getLogger(UAMStationConnectionGraph.class); private Map, Map, UAMFlightLeg>> legs; public UAMStationConnectionGraph(UAMManager uamManager, diff --git a/src/main/java/net/bhl/matsim/uam/infrastructure/readers/UAMXMLReader.java b/src/main/java/net/bhl/matsim/uam/infrastructure/readers/UAMXMLReader.java index b254d77..45a0c02 100644 --- a/src/main/java/net/bhl/matsim/uam/infrastructure/readers/UAMXMLReader.java +++ b/src/main/java/net/bhl/matsim/uam/infrastructure/readers/UAMXMLReader.java @@ -1,14 +1,15 @@ package net.bhl.matsim.uam.infrastructure.readers; import com.google.common.collect.ImmutableMap; + import net.bhl.matsim.uam.infrastructure.UAMStation; -import net.bhl.matsim.uam.infrastructure.UAMStationSimple; import net.bhl.matsim.uam.infrastructure.UAMStationWithChargers; import net.bhl.matsim.uam.infrastructure.UAMVehicle; import net.bhl.matsim.uam.infrastructure.UAMVehicleType; import net.bhl.matsim.uam.run.UAMConstants; -import org.jfree.util.Log; -import org.matsim.api.core.v01.Coord; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.matsim.api.core.v01.Id; import org.matsim.api.core.v01.network.Link; import org.matsim.api.core.v01.network.Network; @@ -33,6 +34,9 @@ */ public class UAMXMLReader extends MatsimXmlParser { + private static final Logger log = LogManager.getLogger(UAMXMLReader.class); + + public final Network network; private final Map, UAMVehicle> vehiclesForData = new HashMap<>(); private final Map, UAMStation> stations = new HashMap<>(); @@ -43,6 +47,7 @@ public class UAMXMLReader extends MatsimXmlParser { private final FleetSpecificationImpl fleetSpecification = new FleetSpecificationImpl(); public UAMXMLReader(Network uamNetwork) { + super(ValidationType.DTD_ONLY); this.network = uamNetwork; } @@ -135,12 +140,12 @@ public void startTag(String name, Attributes atts, Stack context) { vehiclesForData.put(id, vehicleCopy); } catch (NullPointerException e) { - Log.warn(UAMConstants.uam.toUpperCase() + " vehicle " + id + " could not be added. Check correct initial station or vehicle type."); + log.warn(UAMConstants.uam.toUpperCase() + " vehicle " + id + " could not be added. Check correct initial station or vehicle type."); } break; } default: - Log.warn("There was an error parsing the UAM xml-file. Non vehicle/station element found."); + log.warn("There was an error parsing the UAM xml-file. Non vehicle/station element found."); } } diff --git a/src/main/java/net/bhl/matsim/uam/listeners/UAMShutdownListener.java b/src/main/java/net/bhl/matsim/uam/listeners/UAMShutdownListener.java index 14e3f53..f515cae 100644 --- a/src/main/java/net/bhl/matsim/uam/listeners/UAMShutdownListener.java +++ b/src/main/java/net/bhl/matsim/uam/listeners/UAMShutdownListener.java @@ -5,7 +5,8 @@ import java.io.InputStream; import java.io.OutputStream; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.matsim.core.config.Config; import org.matsim.core.config.ConfigGroup; import org.matsim.core.controler.OutputDirectoryHierarchy; @@ -25,7 +26,7 @@ */ public class UAMShutdownListener implements ShutdownListener { - private static final Logger log = Logger.getLogger(UAMListener.class); + private static final Logger log = LogManager.getLogger(UAMListener.class); @Inject private OutputDirectoryHierarchy controlerIO; diff --git a/src/main/java/net/bhl/matsim/uam/router/UAMCachedIntermodalRoutingModule.java b/src/main/java/net/bhl/matsim/uam/router/UAMCachedIntermodalRoutingModule.java index c099477..ba2ed19 100644 --- a/src/main/java/net/bhl/matsim/uam/router/UAMCachedIntermodalRoutingModule.java +++ b/src/main/java/net/bhl/matsim/uam/router/UAMCachedIntermodalRoutingModule.java @@ -4,7 +4,8 @@ import java.util.List; import java.util.Optional; -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.TransportMode; import org.matsim.api.core.v01.network.Link; @@ -15,18 +16,21 @@ import org.matsim.api.core.v01.population.PlanElement; import org.matsim.api.core.v01.population.PopulationFactory; import org.matsim.api.core.v01.population.Route; -import org.matsim.core.config.groups.PlansCalcRouteConfigGroup; +import org.matsim.core.config.groups.RoutingConfigGroup; import org.matsim.core.network.NetworkUtils; import org.matsim.core.population.routes.NetworkRoute; import org.matsim.core.population.routes.RouteFactories; +import org.matsim.core.router.DefaultRoutingRequest; import org.matsim.core.router.LinkWrapperFacility; import org.matsim.core.router.RoutingModule; +import org.matsim.core.router.RoutingRequest; import org.matsim.core.router.util.LeastCostPathCalculator; import org.matsim.core.router.util.LeastCostPathCalculator.Path; import org.matsim.core.utils.geometry.CoordUtils; import org.matsim.facilities.Facility; import org.matsim.pt.config.TransitConfigGroup; import org.matsim.pt.router.TransitRouter; +import org.matsim.utils.objectattributes.attributable.AttributesImpl; import com.google.common.base.Verify; @@ -47,7 +51,7 @@ */ public class UAMCachedIntermodalRoutingModule implements RoutingModule { - private static final Logger log = Logger.getLogger(UAMCachedIntermodalRoutingModule.class); + private static final Logger log = LogManager.getLogger(UAMCachedIntermodalRoutingModule.class); private final int counterLimit = 10; private final Scenario scenario; private int counterWarningWaitingTimeSlot = 0; @@ -90,9 +94,68 @@ public UAMCachedIntermodalRoutingModule(Scenario scenario, UAMStations landingSt carNetwork, stationConnections); } + + private Leg createTeleportationLeg(RouteFactories routeFactory, PopulationFactory populationFactory, + Link originLink, Link destinationLink, String mode, String actualMode) { + + double speed = ((RoutingConfigGroup) scenario.getConfig().getModules().get(RoutingConfigGroup.GROUP_NAME)) + .getTeleportedModeSpeeds().get(mode); + Route route = routeFactory.createRoute(Route.class, originLink.getId(), destinationLink.getId()); + double dist = CoordUtils.calcEuclideanDistance(originLink.getCoord(), destinationLink.getCoord()); + route.setDistance(dist); + route.setTravelTime(dist / speed + 1.0); + + final Leg teleportationleg = populationFactory.createLeg(actualMode); + teleportationleg.setTravelTime(dist / speed + 1.0); + + teleportationleg.setRoute(route); + return teleportationleg; + } + + private Leg createUAMLeg(Link originLink, Link destinationLink, UAMFlightLeg flightLeg, + RouteFactories routeFactory, PopulationFactory populationFactory) { + return createNetworkLeg(UAMConstants.uam, originLink, destinationLink, flightLeg.links, routeFactory, + populationFactory, flightLeg.travelTime, flightLeg.distance); + } + + private Leg createCarLeg(String mode, Link originLink, Link destinationLink, double departureTime, Person person, + RouteFactories routeFactory, PopulationFactory populationFactory) { + Verify.verifyNotNull(originLink); + Verify.verifyNotNull(destinationLink); + Path path = plcpccar.calcLeastCostPath(originLink.getToNode(), destinationLink.getFromNode(), departureTime, + person, null); + + double distance = 0; + for (Link link : path.links) + distance += link.getLength(); + + return createNetworkLeg(mode, originLink, destinationLink, path.links, routeFactory, + populationFactory, path.travelTime, distance); + } + + private Leg createNetworkLeg(String mode, Link originLink, Link destinationLink, List links, + RouteFactories routeFactory, PopulationFactory populationFactory, double travelTime, + double distance) { + NetworkRoute route = routeFactory.createRoute(NetworkRoute.class, originLink.getId(), destinationLink.getId()); + route.setLinkIds(originLink.getId(), NetworkUtils.getLinkIds(links), destinationLink.getId()); + route.setTravelTime(travelTime); + route.setDistance(distance); + + Leg leg = populationFactory.createLeg(mode); + leg.setTravelTime(travelTime); + leg.setRoute(route); + return leg; + } + @Override - public List calcRoute(Facility fromFacility, Facility toFacility, double departureTime, - Person person) { + public List calcRoute(RoutingRequest request) { + + Person person = request.getPerson(); + Facility fromFacility = request.getFromFacility(); + Facility toFacility = request.getToFacility(); + double departureTime = request.getDepartureTime(); + + Network network = scenario.getNetwork(); PopulationFactory populationFactory = scenario.getPopulation().getFactory(); @@ -140,9 +203,16 @@ public List calcRoute(Facility fromFacility, Facility toF case TransportMode.pt: // checks if pt is being simulated before adding the trip if (scenario.getConfig().transit().isUseTransit()) { + + RoutingRequest routingRequest = DefaultRoutingRequest.of( + fromFacility, + new LinkWrapperFacility(uamRoute.bestOriginStation.getLocationLink()), + departureTime, + person, + new AttributesImpl()); + @SuppressWarnings("unchecked") - List legs = (List) this.transitRouterDelegate.calcRoute(fromFacility, - new LinkWrapperFacility(uamRoute.bestOriginStation.getLocationLink()), departureTime, person); + List legs = (List) this.transitRouterDelegate.calcRoute(routingRequest); for (PlanElement leg : legs) { if (leg instanceof Leg) currentTime += ((Leg) leg).getTravelTime().seconds(); @@ -249,10 +319,15 @@ public List calcRoute(Facility fromFacility, Facility toF case TransportMode.pt: // checks if pt is being simulated before adding the trip if (scenario.getConfig().transit().isUseTransit()) { + RoutingRequest routingRequest = DefaultRoutingRequest.of( + new LinkWrapperFacility(uamRoute.bestDestinationStation.getLocationLink()), + toFacility, + currentTime, + person, + new AttributesImpl()); + @SuppressWarnings("unchecked") - List legs = (List) this.transitRouterDelegate.calcRoute( - new LinkWrapperFacility(uamRoute.bestDestinationStation.getLocationLink()), toFacility, - currentTime, person); + List legs = (List) this.transitRouterDelegate.calcRoute(routingRequest); trip.addAll(legs); } else { Leg uavPtEgressLeg = createTeleportationLeg(routeFactory, populationFactory, @@ -269,57 +344,6 @@ public List calcRoute(Facility fromFacility, Facility toF } return trip; - } - - private Leg createTeleportationLeg(RouteFactories routeFactory, PopulationFactory populationFactory, - Link originLink, Link destinationLink, String mode, String actualMode) { - - double speed = ((PlansCalcRouteConfigGroup) scenario.getConfig().getModules().get("planscalcroute")) - .getTeleportedModeSpeeds().get(mode); - Route route = routeFactory.createRoute(Route.class, originLink.getId(), destinationLink.getId()); - double dist = CoordUtils.calcEuclideanDistance(originLink.getCoord(), destinationLink.getCoord()); - route.setDistance(dist); - route.setTravelTime(dist / speed + 1.0); - - final Leg teleportationleg = populationFactory.createLeg(actualMode); - teleportationleg.setTravelTime(dist / speed + 1.0); - - teleportationleg.setRoute(route); - return teleportationleg; - } - - private Leg createUAMLeg(Link originLink, Link destinationLink, UAMFlightLeg flightLeg, - RouteFactories routeFactory, PopulationFactory populationFactory) { - return createNetworkLeg(UAMConstants.uam, originLink, destinationLink, flightLeg.links, routeFactory, - populationFactory, flightLeg.travelTime, flightLeg.distance); - } - private Leg createCarLeg(String mode, Link originLink, Link destinationLink, double departureTime, Person person, - RouteFactories routeFactory, PopulationFactory populationFactory) { - Verify.verifyNotNull(originLink); - Verify.verifyNotNull(destinationLink); - Path path = plcpccar.calcLeastCostPath(originLink.getToNode(), destinationLink.getFromNode(), departureTime, - person, null); - - double distance = 0; - for (Link link : path.links) - distance += link.getLength(); - - return createNetworkLeg(mode, originLink, destinationLink, path.links, routeFactory, - populationFactory, path.travelTime, distance); - } - - private Leg createNetworkLeg(String mode, Link originLink, Link destinationLink, List links, - RouteFactories routeFactory, PopulationFactory populationFactory, double travelTime, - double distance) { - NetworkRoute route = routeFactory.createRoute(NetworkRoute.class, originLink.getId(), destinationLink.getId()); - route.setLinkIds(originLink.getId(), NetworkUtils.getLinkIds(links), destinationLink.getId()); - route.setTravelTime(travelTime); - route.setDistance(distance); - - Leg leg = populationFactory.createLeg(mode); - leg.setTravelTime(travelTime); - leg.setRoute(route); - return leg; } } \ No newline at end of file diff --git a/src/main/java/net/bhl/matsim/uam/router/strategy/UAMPredefinedStrategy.java b/src/main/java/net/bhl/matsim/uam/router/strategy/UAMPredefinedStrategy.java index 301f96b..e65307b 100644 --- a/src/main/java/net/bhl/matsim/uam/router/strategy/UAMPredefinedStrategy.java +++ b/src/main/java/net/bhl/matsim/uam/router/strategy/UAMPredefinedStrategy.java @@ -3,7 +3,9 @@ import net.bhl.matsim.uam.data.UAMRoute; import net.bhl.matsim.uam.infrastructure.UAMStation; import net.bhl.matsim.uam.run.UAMConstants; -import org.apache.log4j.Logger; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.matsim.api.core.v01.population.Activity; import org.matsim.api.core.v01.population.Leg; import org.matsim.api.core.v01.population.Person; @@ -25,7 +27,7 @@ public class UAMPredefinedStrategy implements UAMStrategy { public static final String ORIG_STATION = "originStation"; public static final String DEST_STATION = "destinationStation"; public static final String EGRESS_MODE = "egressMode"; - private static final Logger log = Logger.getLogger(UAMPredefinedStrategy.class); + private static final Logger log = LogManager.getLogger(UAMPredefinedStrategy.class); private UAMStrategyUtils strategyUtils; public UAMPredefinedStrategy(UAMStrategyUtils strategyUtils) { diff --git a/src/main/java/net/bhl/matsim/uam/router/strategy/UAMStrategyRouter.java b/src/main/java/net/bhl/matsim/uam/router/strategy/UAMStrategyRouter.java index 5095cac..ba5db7e 100644 --- a/src/main/java/net/bhl/matsim/uam/router/strategy/UAMStrategyRouter.java +++ b/src/main/java/net/bhl/matsim/uam/router/strategy/UAMStrategyRouter.java @@ -2,7 +2,8 @@ import java.util.Optional; -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.Network; import org.matsim.api.core.v01.population.Person; @@ -23,7 +24,7 @@ * @author Aitanm (Aitan Militao), RRothfeld (Raoul Rothfeld) */ public class UAMStrategyRouter { - private static final Logger log = Logger.getLogger(UAMStrategyRouter.class); + private static final Logger log = LogManager.getLogger(UAMStrategyRouter.class); private final Scenario scenario; private UAMConfigGroup uamConfig; private UAMStations landingStations; diff --git a/src/main/java/net/bhl/matsim/uam/router/strategy/UAMStrategyUtils.java b/src/main/java/net/bhl/matsim/uam/router/strategy/UAMStrategyUtils.java index 0c22223..1fd7db4 100644 --- a/src/main/java/net/bhl/matsim/uam/router/strategy/UAMStrategyUtils.java +++ b/src/main/java/net/bhl/matsim/uam/router/strategy/UAMStrategyUtils.java @@ -7,21 +7,26 @@ import java.util.Map; import java.util.Set; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.matsim.api.core.v01.Id; 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.network.Network; import org.matsim.api.core.v01.population.Leg; -import org.matsim.core.config.groups.PlansCalcRouteConfigGroup; +import org.matsim.api.core.v01.population.PlanElement; +import org.matsim.core.config.groups.RoutingConfigGroup; import org.matsim.core.network.NetworkUtils; +import org.matsim.core.router.DefaultRoutingRequest; import org.matsim.core.router.LinkWrapperFacility; +import org.matsim.core.router.RoutingRequest; import org.matsim.core.router.util.LeastCostPathCalculator; import org.matsim.core.router.util.LeastCostPathCalculator.Path; import org.matsim.core.utils.geometry.CoordUtils; import org.matsim.facilities.Facility; import org.matsim.pt.router.TransitRouter; +import org.matsim.utils.objectattributes.attributable.AttributesImpl; import net.bhl.matsim.uam.config.UAMConfigGroup; import net.bhl.matsim.uam.data.UAMAccessLeg; @@ -36,7 +41,7 @@ * @author Aitanm (Aitan Militao), RRothfeld (Raoul Rothfeld) */ public class UAMStrategyUtils { - private static final Logger log = Logger.getLogger(UAMStrategyUtils.class); + private static final Logger log = LogManager.getLogger(UAMStrategyUtils.class); private final Scenario scenario; private UAMStations landingStations; private UAMConfigGroup uamConfig; @@ -165,16 +170,23 @@ UAMAccessLeg estimateAccessLeg(boolean access, Facility facility, double time, U return new UAMAccessLeg(path.travelTime, distanceByCar, path.links); case TransportMode.pt: if (transitRouter != null) { - List legs = transitRouter.calcRoute(new LinkWrapperFacility(from), new LinkWrapperFacility(to), - time, null); + RoutingRequest routingRequest = DefaultRoutingRequest.of( + new LinkWrapperFacility(from), + new LinkWrapperFacility(to), + time, + null, + new AttributesImpl()); + List elements = transitRouter.calcRoute(routingRequest); double distanceByPt = 0.0; double timeByPt = 0.0; // pt router can return null under certain conditions - if (legs == null) + if (elements == null) return null; - for (Leg leg : legs) { - timeByPt += leg.getTravelTime().seconds(); - distanceByPt += leg.getRoute().getDistance(); + for (PlanElement pe : elements) { + if (pe instanceof Leg) { + timeByPt += ((Leg)pe).getTravelTime().seconds(); + distanceByPt += ((Leg)pe).getRoute().getDistance(); + } } return new UAMAccessLeg(timeByPt, distanceByPt, null); } @@ -184,12 +196,12 @@ UAMAccessLeg estimateAccessLeg(boolean access, Facility facility, double time, U } private UAMAccessLeg getBeelineAccessLeg(Facility facility, UAMStation station, String mode) { - double distanceFactor = ((PlansCalcRouteConfigGroup) scenario.getConfig().getModules().get("planscalcroute")) + double distanceFactor = ((RoutingConfigGroup) scenario.getConfig().getModules().get("routing")) .getBeelineDistanceFactors().get(mode); double distance = CoordUtils.calcEuclideanDistance( scenario.getNetwork().getLinks().get(facility.getLinkId()).getCoord(), station.getLocationLink().getCoord()); - double speed = ((PlansCalcRouteConfigGroup) scenario.getConfig().getModules().get("planscalcroute")) + double speed = ((RoutingConfigGroup) scenario.getConfig().getModules().get("routing")) .getTeleportedModeSpeeds().get(mode); return new UAMAccessLeg(distance * distanceFactor / speed, distance * distanceFactor, null); diff --git a/src/main/java/net/bhl/matsim/uam/run/RunUAMScenario.java b/src/main/java/net/bhl/matsim/uam/run/RunUAMScenario.java index 02ea3fa..3652666 100644 --- a/src/main/java/net/bhl/matsim/uam/run/RunUAMScenario.java +++ b/src/main/java/net/bhl/matsim/uam/run/RunUAMScenario.java @@ -11,12 +11,14 @@ import org.matsim.core.config.CommandLine.ConfigurationException; import org.matsim.core.config.Config; import org.matsim.core.config.ConfigUtils; -import org.matsim.core.config.groups.PlanCalcScoreConfigGroup.ActivityParams; -import org.matsim.core.config.groups.PlanCalcScoreConfigGroup.ModeParams; import org.matsim.core.config.groups.QSimConfigGroup.StarttimeInterpretation; +import org.matsim.core.config.groups.ScoringConfigGroup.ActivityParams; +import org.matsim.core.config.groups.ScoringConfigGroup.ModeParams; import org.matsim.core.controler.Controler; import org.matsim.core.scenario.ScenarioUtils; +import com.google.common.collect.ImmutableSet; + /** * The RunUAMScenario program start a MATSim run including Urban Air Mobility * capabilities. @@ -95,14 +97,14 @@ public static Controler createControler() { controler.getConfig().qsim().setSimStarttimeInterpretation(StarttimeInterpretation.onlyUseStarttime); controler.getConfig().qsim().setStartTime(0.0); - DvrpConfigGroup.get(config).setNetworkModesAsString("uam"); - config.planCalcScore().addModeParams(new ModeParams("access_uam_car")); - config.planCalcScore().addModeParams(new ModeParams("egress_uam_car")); - config.planCalcScore().addModeParams(new ModeParams("uam")); - config.planCalcScore() + DvrpConfigGroup.get(config).networkModes = ImmutableSet.of("uam"); + config.scoring().addModeParams(new ModeParams("access_uam_car")); + config.scoring().addModeParams(new ModeParams("egress_uam_car")); + config.scoring().addModeParams(new ModeParams("uam")); + config.scoring() .addActivityParams(new ActivityParams("uam_interaction").setScoringThisActivityAtAll(false)); - config.controler().setWriteEventsInterval(1); + config.controller().setWriteEventsInterval(1); return controler; } diff --git a/src/main/java/net/bhl/matsim/uam/scenario/utils/ConfigAddUAMParameters.java b/src/main/java/net/bhl/matsim/uam/scenario/utils/ConfigAddUAMParameters.java index 8b9b3ec..632ce5f 100644 --- a/src/main/java/net/bhl/matsim/uam/scenario/utils/ConfigAddUAMParameters.java +++ b/src/main/java/net/bhl/matsim/uam/scenario/utils/ConfigAddUAMParameters.java @@ -9,7 +9,8 @@ import org.matsim.core.config.ConfigGroup; import org.matsim.core.config.ConfigUtils; import org.matsim.core.config.ConfigWriter; -import org.matsim.core.config.groups.PlansCalcRouteConfigGroup; +import org.matsim.core.config.groups.RoutingConfigGroup; +import org.matsim.core.config.groups.RoutingConfigGroup.TeleportedModeParams; import java.util.Collection; @@ -49,10 +50,10 @@ public static void addUAMParameters(Config config, String inputUAMFile, String m boolean ptParamsExistent = false; for (ConfigGroup cg : teleportedModeParameters) { - if (!(cg instanceof PlansCalcRouteConfigGroup.ModeRoutingParams)) + if (!(cg instanceof RoutingConfigGroup.ModeRoutingParams)) continue; - PlansCalcRouteConfigGroup.ModeRoutingParams mrp = (PlansCalcRouteConfigGroup.ModeRoutingParams) cg; + RoutingConfigGroup.ModeRoutingParams mrp = (RoutingConfigGroup.ModeRoutingParams) cg; if (mrp.getMode().equals(TransportMode.pt)) { ptParamsExistent = true; @@ -63,8 +64,8 @@ public static void addUAMParameters(Config config, String inputUAMFile, String m } if (!ptSimulation && !ptParamsExistent) { - PlansCalcRouteConfigGroup.ModeRoutingParams modeRoutingParams = - new PlansCalcRouteConfigGroup.ModeRoutingParams(); + TeleportedModeParams modeRoutingParams = + new TeleportedModeParams(); modeRoutingParams.setMode(TransportMode.pt); modeRoutingParams.setTeleportedModeSpeed(10.0); modeRoutingParams.setBeelineDistanceFactor(1.0); From 4b5005e095f7e2ff661be1d2d5504c4e55b6464c Mon Sep 17 00:00:00 2001 From: balacmi Date: Tue, 1 Oct 2024 10:25:21 +0200 Subject: [PATCH 07/19] fix type --- src/main/java/net/bhl/matsim/uam/data/WaitingStationData.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/bhl/matsim/uam/data/WaitingStationData.java b/src/main/java/net/bhl/matsim/uam/data/WaitingStationData.java index 0fd42a3..6a7354a 100644 --- a/src/main/java/net/bhl/matsim/uam/data/WaitingStationData.java +++ b/src/main/java/net/bhl/matsim/uam/data/WaitingStationData.java @@ -39,7 +39,7 @@ public void notifyBeforeMobsim(BeforeMobsimEvent event) { waitingData.clear(); int simulationEndTime = Integer.parseInt(config.getModules().get("qsim").getParams().get("endTime").substring(0,2)); - int waitingTimeBinSize = Integer.parseInt(config.getModules().get("travelTimeCalculator").getParams().get("travelTimeBinSize")); + double waitingTimeBinSize = Double.parseDouble(config.getModules().get("travelTimeCalculator").getParams().get("travelTimeBinSize")); for (UAMStation station : uamManager.getStations().getUAMStations().values()) waitingData.put(station.getId(), new WaitingData(simulationEndTime * 3600, waitingTimeBinSize, station.getDefaultWaitTime())); From 26215f977fb190f08b0686646469fcfbef4e7133 Mon Sep 17 00:00:00 2001 From: balacmi Date: Tue, 1 Oct 2024 10:25:53 +0200 Subject: [PATCH 08/19] using our own csvreader now --- .../matsim/uam/analysis/traveltimes/utils/TripItemReader.java | 3 ++- .../bhl/matsim/uam/scenario/RunCreateUAMRoutedScenario.java | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/bhl/matsim/uam/analysis/traveltimes/utils/TripItemReader.java b/src/main/java/net/bhl/matsim/uam/analysis/traveltimes/utils/TripItemReader.java index 5836da2..11aba2d 100644 --- a/src/main/java/net/bhl/matsim/uam/analysis/traveltimes/utils/TripItemReader.java +++ b/src/main/java/net/bhl/matsim/uam/analysis/traveltimes/utils/TripItemReader.java @@ -1,9 +1,10 @@ package net.bhl.matsim.uam.analysis.traveltimes.utils; import org.matsim.api.core.v01.Coord; -import org.matsim.contrib.util.CSVReaders; import org.matsim.core.utils.misc.Time; +import net.bhl.matsim.uam.infrastructure.readers.CSVReaders; + import java.io.IOException; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/net/bhl/matsim/uam/scenario/RunCreateUAMRoutedScenario.java b/src/main/java/net/bhl/matsim/uam/scenario/RunCreateUAMRoutedScenario.java index b491dd4..10ce512 100644 --- a/src/main/java/net/bhl/matsim/uam/scenario/RunCreateUAMRoutedScenario.java +++ b/src/main/java/net/bhl/matsim/uam/scenario/RunCreateUAMRoutedScenario.java @@ -21,7 +21,6 @@ import org.matsim.api.core.v01.network.Network; import org.matsim.api.core.v01.network.NetworkWriter; import org.matsim.api.core.v01.network.Node; -import org.matsim.contrib.util.CSVReaders; import org.matsim.core.config.Config; import org.matsim.core.config.ConfigUtils; import org.matsim.core.config.ConfigWriter; @@ -42,6 +41,7 @@ import com.google.common.collect.Iterables; +import net.bhl.matsim.uam.infrastructure.readers.CSVReaders; import net.bhl.matsim.uam.router.UAMFlightSegments; import net.bhl.matsim.uam.router.strategy.UAMStrategy; import net.bhl.matsim.uam.run.UAMConstants; From 2fd63f401385c4a09c16fca411291f38fa12e5eb Mon Sep 17 00:00:00 2001 From: balacmi Date: Tue, 1 Oct 2024 10:29:23 +0200 Subject: [PATCH 09/19] fix a change in api --- .../bhl/matsim/uam/passenger/UAMPassengerDropoffActivity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/bhl/matsim/uam/passenger/UAMPassengerDropoffActivity.java b/src/main/java/net/bhl/matsim/uam/passenger/UAMPassengerDropoffActivity.java index 8b6eb24..0122fd9 100644 --- a/src/main/java/net/bhl/matsim/uam/passenger/UAMPassengerDropoffActivity.java +++ b/src/main/java/net/bhl/matsim/uam/passenger/UAMPassengerDropoffActivity.java @@ -40,7 +40,7 @@ public UAMPassengerDropoffActivity(PassengerEngine passengerEngine, DynAgent dri @Override public void finalizeAction(double now) { for (PassengerRequest request : requests) { - passengerEngine.dropOffPassenger(driver, request, now); + passengerEngine.dropOffPassengers(driver, request.getId(), now); } } From bfd8051ba65c31bed4bad1af808dabfafa644a0f Mon Sep 17 00:00:00 2001 From: balacmi Date: Tue, 1 Oct 2024 10:31:28 +0200 Subject: [PATCH 10/19] fix api PassengerRequest now can have multiple passengers --- .../bhl/matsim/uam/passenger/UAMRequest.java | 17 +++++-- .../uam/passenger/UAMRequestCreator.java | 4 +- ...glePassengerPerRequestPickupActivity.java} | 47 ++++++++++--------- .../matsim/uam/vrpagent/UAMActionCreator.java | 4 +- 4 files changed, 42 insertions(+), 30 deletions(-) rename src/main/java/net/bhl/matsim/uam/passenger/{UAMPassengerPickupActivity.java => UAMSinglePassengerPerRequestPickupActivity.java} (66%) diff --git a/src/main/java/net/bhl/matsim/uam/passenger/UAMRequest.java b/src/main/java/net/bhl/matsim/uam/passenger/UAMRequest.java index 5641765..99835c9 100644 --- a/src/main/java/net/bhl/matsim/uam/passenger/UAMRequest.java +++ b/src/main/java/net/bhl/matsim/uam/passenger/UAMRequest.java @@ -1,5 +1,7 @@ package net.bhl.matsim.uam.passenger; +import java.util.List; + import org.matsim.api.core.v01.Id; import org.matsim.api.core.v01.network.Link; import org.matsim.api.core.v01.population.Person; @@ -21,7 +23,7 @@ public class UAMRequest implements PassengerRequest { final private double submissionTime; final private Link originLink; final private Link destinationLink; - final private Id passengerId; + final private List> passengerIds; private final double quantity; private final double earliestStartTime; private final double latestStartTime; @@ -30,7 +32,7 @@ public class UAMRequest implements PassengerRequest { private UAMDispatcher dispatcher; private double distance; - public UAMRequest(Id id, Id passengerId, Link originLink, Link destinationLink, double pickupTime, + public UAMRequest(Id id, List> passengerIds, Link originLink, Link destinationLink, double pickupTime, double submissionTime, UAMDispatcher dispatcher, double distance) { this.id = id; this.submissionTime = submissionTime; @@ -39,7 +41,7 @@ public UAMRequest(Id id, Id passengerId, Link originLink, Link this.destinationLink = destinationLink; this.earliestStartTime = pickupTime; this.latestStartTime = pickupTime; - this.passengerId = passengerId; + this.passengerIds = passengerIds; this.dispatcher = dispatcher; this.distance = distance; } @@ -69,8 +71,8 @@ public Id getId() { } @Override - public Id getPassengerId() { - return passengerId; + public List> getPassengerIds() { + return passengerIds; } @Override @@ -116,4 +118,9 @@ public void setDistance(double distance) { this.distance = distance; } + @Override + public int getPassengerCount() { + return this.passengerIds.size(); + } + } diff --git a/src/main/java/net/bhl/matsim/uam/passenger/UAMRequestCreator.java b/src/main/java/net/bhl/matsim/uam/passenger/UAMRequestCreator.java index d88486e..c4f57af 100644 --- a/src/main/java/net/bhl/matsim/uam/passenger/UAMRequestCreator.java +++ b/src/main/java/net/bhl/matsim/uam/passenger/UAMRequestCreator.java @@ -33,13 +33,13 @@ public class UAMRequestCreator implements PassengerRequestCreator { private UAMManager uamManager; @Override - public PassengerRequest createRequest(Id id, Id passengerId, Route route, Link fromLink, + public PassengerRequest createRequest(Id id, List> passengerIds, Route route, Link fromLink, Link toLink, double departureTime, double submissionTime) { // We currently have only one dispatcher, this might change in the future double distance = stationConnectionutilities.getFlightLeg( uamManager.getStations().getNearestUAMStation(fromLink).getId(), uamManager.getStations().getNearestUAMStation(toLink).getId()).distance; - return new UAMRequest(id, passengerId, fromLink, toLink, departureTime, submissionTime, dispatchers.get(0), + return new UAMRequest(id, passengerIds, fromLink, toLink, departureTime, submissionTime, dispatchers.get(0), distance); } diff --git a/src/main/java/net/bhl/matsim/uam/passenger/UAMPassengerPickupActivity.java b/src/main/java/net/bhl/matsim/uam/passenger/UAMSinglePassengerPerRequestPickupActivity.java similarity index 66% rename from src/main/java/net/bhl/matsim/uam/passenger/UAMPassengerPickupActivity.java rename to src/main/java/net/bhl/matsim/uam/passenger/UAMSinglePassengerPerRequestPickupActivity.java index 59587a2..c6abf48 100644 --- a/src/main/java/net/bhl/matsim/uam/passenger/UAMPassengerPickupActivity.java +++ b/src/main/java/net/bhl/matsim/uam/passenger/UAMSinglePassengerPerRequestPickupActivity.java @@ -2,13 +2,13 @@ import org.matsim.contrib.dvrp.fleet.DvrpVehicle; import org.matsim.contrib.dvrp.passenger.PassengerEngine; -import org.matsim.contrib.dvrp.passenger.PassengerEngineWithPrebooking; import org.matsim.contrib.dvrp.passenger.PassengerPickupActivity; import org.matsim.contrib.dvrp.passenger.PassengerRequest; import org.matsim.contrib.dvrp.schedule.StayTask; import org.matsim.contrib.dynagent.DynAgent; import org.matsim.core.mobsim.framework.MobsimPassengerAgent; +import java.util.List; import java.util.Set; /** @@ -17,11 +17,11 @@ * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) */ -public class UAMPassengerPickupActivity implements PassengerPickupActivity { +public class UAMSinglePassengerPerRequestPickupActivity implements PassengerPickupActivity { private final PassengerEngine passengerEngine; private final DynAgent driver; - private final Set requests; + private final Set requests; private final double pickupDuration; private final String activityType; @@ -30,13 +30,14 @@ public class UAMPassengerPickupActivity implements PassengerPickupActivity { private double endTime; private int passengersAboard; - public UAMPassengerPickupActivity(PassengerEngine passengerEngine, DynAgent driver, - DvrpVehicle vehicle, StayTask pickupTask, Set requests, + public UAMSinglePassengerPerRequestPickupActivity(PassengerEngine passengerEngine, DynAgent driver, + DvrpVehicle vehicle, StayTask pickupTask, Set requests, double pickupDuration, String activityType) { if (requests.size() > vehicle.getCapacity()) { // Number of requests exceeds number of seats throw new IllegalStateException(); } + this.activityType = activityType; this.passengerEngine = passengerEngine; @@ -48,10 +49,11 @@ public UAMPassengerPickupActivity(PassengerEngine passengerEngine, DynAgent driv passengersAboard = 0; double now = pickupTask.getBeginTime(); - + int passengerCount = 0; for (PassengerRequest request : requests) { - if (passengerEngine.tryPickUpPassenger(this, driver, request, pickupTask.getBeginTime())) { - passengersAboard++; + passengerCount += request.getPassengerCount(); + if (passengerEngine.tryPickUpPassengers(this, driver, request.getId(), pickupTask.getBeginTime())) { + passengersAboard += request.getPassengerCount(); } if (request.getEarliestStartTime() > maximumRequestT0) { @@ -59,11 +61,12 @@ public UAMPassengerPickupActivity(PassengerEngine passengerEngine, DynAgent driv } } - if (passengersAboard == requests.size()) { + if (passengersAboard == passengerCount) { endTime = now + pickupDuration; } else { setEndTimeIfWaitingForPassengers(now); } + } private void setEndTimeIfWaitingForPassengers(double now) { @@ -93,27 +96,29 @@ public void doSimStep(double now) { private PassengerRequest getRequestForPassenger(MobsimPassengerAgent passenger) { for (PassengerRequest request : requests) { - if (passenger.getId().equals(request.getPassengerId())) + if (request.getPassengerIds().contains( passenger.getId())) return request; } return null; } - @Override - public void notifyPassengerIsReadyForDeparture(MobsimPassengerAgent passenger, double now) { - PassengerRequest request = getRequestForPassenger(passenger); - if (request == null) { - throw new IllegalArgumentException("I am waiting for different passengers!"); - } + @Override + public void notifyPassengersAreReadyForDeparture(List passengers, double now) { + for (MobsimPassengerAgent mpa : passengers) { - if (passengerEngine.tryPickUpPassenger(this, driver, request, now)) { - passengersAboard++; - } else { - throw new IllegalStateException("The passenger is not on the link or not available for departure!"); + PassengerRequest pr = getRequestForPassenger(mpa); + if (pr == null) + throw new IllegalArgumentException("I am waiting for a different passenger!"); + if (passengerEngine.tryPickUpPassengers(this, driver, pr.getId(), now)) { + passengersAboard++; + } else { + throw new IllegalStateException("The passenger is not on the link or not available for departure!"); + } + } - + if (passengersAboard == requests.size()) { endTime = now + pickupDuration; } diff --git a/src/main/java/net/bhl/matsim/uam/vrpagent/UAMActionCreator.java b/src/main/java/net/bhl/matsim/uam/vrpagent/UAMActionCreator.java index b017cb6..f3f075e 100644 --- a/src/main/java/net/bhl/matsim/uam/vrpagent/UAMActionCreator.java +++ b/src/main/java/net/bhl/matsim/uam/vrpagent/UAMActionCreator.java @@ -17,7 +17,7 @@ import net.bhl.matsim.uam.infrastructure.UAMVehicle; import net.bhl.matsim.uam.passenger.UAMChargingActivity; import net.bhl.matsim.uam.passenger.UAMPassengerDropoffActivity; -import net.bhl.matsim.uam.passenger.UAMPassengerPickupActivity; +import net.bhl.matsim.uam.passenger.UAMSinglePassengerPerRequestPickupActivity; import net.bhl.matsim.uam.run.UAMConstants; import net.bhl.matsim.uam.schedule.UAMChargingTask; import net.bhl.matsim.uam.schedule.UAMDropoffTask; @@ -54,7 +54,7 @@ public DynAction createAction(DynAgent dynAgent, DvrpVehicle vehicle, double now if (task.getTaskType().equals(UAMTaskType.PICKUP)) { UAMPickupTask mpt = (UAMPickupTask) task; - return new UAMPassengerPickupActivity(passengerEngine, dynAgent, vehicle, mpt, mpt.getRequests(), + return new UAMSinglePassengerPerRequestPickupActivity(passengerEngine, dynAgent, vehicle, mpt, mpt.getRequests(), mpt.getBoardingTime(), PICKUP_ACTIVITY_TYPE); } else if (task.getTaskType().equals(UAMTaskType.DROPOFF)) { UAMDropoffTask mdt = (UAMDropoffTask) task; From 765fe5107fa7ad589cae7219135ecd31b7b15797 Mon Sep 17 00:00:00 2001 From: balacmi Date: Tue, 1 Oct 2024 10:31:40 +0200 Subject: [PATCH 11/19] we need to ahve our own to add uam --- .../DefaultAnalysisMainModeIdentifier.java | 109 ++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 src/main/java/org/matsim/core/router/DefaultAnalysisMainModeIdentifier.java diff --git a/src/main/java/org/matsim/core/router/DefaultAnalysisMainModeIdentifier.java b/src/main/java/org/matsim/core/router/DefaultAnalysisMainModeIdentifier.java new file mode 100644 index 0000000..ab307d2 --- /dev/null +++ b/src/main/java/org/matsim/core/router/DefaultAnalysisMainModeIdentifier.java @@ -0,0 +1,109 @@ +package org.matsim.core.router; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.matsim.api.core.v01.TransportMode; +import org.matsim.api.core.v01.population.Leg; +import org.matsim.api.core.v01.population.PlanElement; + +import java.util.ArrayList; +import java.util.List; + +/** + * Attempt to provide a default {@link AnalysisMainModeIdentifier} that is justified from the transport engineering perspective, not from the + * software perspective. + * If you use other transport modes not included here, please copy this class, add the mode in your copy and bind that copy in your run class. + * + * @author vsp-gleich + * + */ +public final class DefaultAnalysisMainModeIdentifier implements AnalysisMainModeIdentifier { + // Please do not lightheartedly change this class, you are not the only user affected. + + private static final Logger log = LogManager.getLogger(DefaultAnalysisMainModeIdentifier.class); + + private final List modeHierarchy = new ArrayList<>() ; + + public DefaultAnalysisMainModeIdentifier() { + // If you want to change the mode hierarchy, please create your own copy for that. + modeHierarchy.add( TransportMode.non_network_walk ) ; + modeHierarchy.add( "undefined" ) ; + modeHierarchy.add( TransportMode.transit_walk) ; + modeHierarchy.add( TransportMode.other ) ; + modeHierarchy.add( TransportMode.walk ) ; + modeHierarchy.add( TransportMode.bike ) ; + modeHierarchy.add( TransportMode.taxi ) ; + modeHierarchy.add( TransportMode.drt ) ; + modeHierarchy.add( TransportMode.ride ) ; + modeHierarchy.add( TransportMode.motorcycle ) ; + modeHierarchy.add( TransportMode.truck ); + modeHierarchy.add( TransportMode.car ) ; + modeHierarchy.add( TransportMode.pt ) ; + modeHierarchy.add( TransportMode.train ) ; + modeHierarchy.add( TransportMode.ship ) ; + modeHierarchy.add( TransportMode.airplane ) ; + + modeHierarchy.add("access_uam_car"); + modeHierarchy.add("egress_uam_car"); + modeHierarchy.add("access_uam_walk"); + modeHierarchy.add("egress_uam_walk"); + modeHierarchy.add("access_uam_pt"); + modeHierarchy.add("egress_uam_pt"); + modeHierarchy.add("access_uam_bike"); + modeHierarchy.add("egress_uam_bike"); + modeHierarchy.add("access_uam_taxi"); + modeHierarchy.add("egress_uam_taxi"); + modeHierarchy.add("uam"); + modeHierarchy.add( "freight" ) ; // not clear where this should go since it is not passenger traffic, but it is used in many scenarios. + + // NOTE: This hierarchical stuff is not so great: is park-n-ride a car trip or a pt trip? Could weigh it by distance, or by time spent + // in respective mode. Or have combined modes as separate modes. In any case, can't do it at the leg level, since it does not + // make sense to have the system calibrate towards something where we have counted the car and the pt part of a multimodal + // trip as two separate trips. kai, sep'16 + } + + @Override public String identifyMainMode( List planElements ) { + int mainModeIndex = -1 ; + String unknownMode = null; + for ( PlanElement pe : planElements ) { + if (pe instanceof Leg leg) { + int index = modeHierarchy.indexOf( leg.getMode() ) ; + if ( index < 0 ) { + /* + * The current leg mode is not included in the hierarchy above. + * + * If besides this unknown mode there are only (access/egress) non_network_walk and walk, we can assume that this unknown mode + * is the main mode. That assumption saves creating custom AnalysisMainModeIdentifier if new modes not included in the hierarchy + * above are used. However, with multiple modes besides walk and non_network_walk we need to know the hierarchy of those modes + * to determine which of those is the main mode. + */ + if (unknownMode != null && !unknownMode.equals(leg.getMode())) { + log.error("Multiple unknown modes in one trip: " + leg.getMode() + " and " + unknownMode + ". The AnalysisMainModeIdentifier" + + " cannot determine which of those is the main mode because they are both unknown to it. Please bind your own " + + "AnalysisMainModeIdentifier that interprets all modes used in your scenario correctly."); + throw new IllegalStateException("unknown modes in AnalysisMainModeIdentifier: " + leg.getMode() + " and " + unknownMode ) ; + } else { + unknownMode = leg.getMode(); + } + } + if ( index > mainModeIndex ) { + mainModeIndex = index ; + } + } + } + + if (unknownMode != null) { + if (mainModeIndex > modeHierarchy.indexOf( TransportMode.walk )) { + // another mode besides walk and our unknown mode was found before, we don't know which of them is the main mode + log.error("Unknown mode " + unknownMode + " and " + modeHierarchy.get( mainModeIndex ) + " found in the same trip. The " + + "AnalysisMainModeIdentifier cannot determine which of those is the main mode because they are both unknown to it. " + + "Please bind your own AnalysisMainModeIdentifier that interprets all modes used in your scenario correctly."); + throw new IllegalStateException("unknown mode in AnalysisMainModeIdentifier: " + unknownMode); + } else { + return unknownMode; + } + } + + return modeHierarchy.get( mainModeIndex ) ; + } +} \ No newline at end of file From 1fabc65f226ad8cd60dba6a79f261be0b2d6b620 Mon Sep 17 00:00:00 2001 From: balacmi Date: Tue, 1 Oct 2024 10:32:34 +0200 Subject: [PATCH 12/19] update config module names and more added the code to ensure vehicles to not wait forever to enter traffic, especially with undersampled scenarios. --- .../java/net/bhl/matsim/uam/RunCorsicaIT.java | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/test/java/net/bhl/matsim/uam/RunCorsicaIT.java b/src/test/java/net/bhl/matsim/uam/RunCorsicaIT.java index aa000e1..6964c81 100644 --- a/src/test/java/net/bhl/matsim/uam/RunCorsicaIT.java +++ b/src/test/java/net/bhl/matsim/uam/RunCorsicaIT.java @@ -20,10 +20,11 @@ import org.matsim.core.config.CommandLine.ConfigurationException; import org.matsim.core.config.Config; import org.matsim.core.config.ConfigUtils; -import org.matsim.core.config.groups.PlanCalcScoreConfigGroup.ActivityParams; -import org.matsim.core.config.groups.PlanCalcScoreConfigGroup.ModeParams; +import org.matsim.core.config.groups.QSimConfigGroup; import org.matsim.core.config.groups.QSimConfigGroup.StarttimeInterpretation; -import org.matsim.core.config.groups.StrategyConfigGroup.StrategySettings; +import org.matsim.core.config.groups.ReplanningConfigGroup.StrategySettings; +import org.matsim.core.config.groups.ScoringConfigGroup.ActivityParams; +import org.matsim.core.config.groups.ScoringConfigGroup.ModeParams; import org.matsim.core.config.groups.SubtourModeChoiceConfigGroup; import org.matsim.core.controler.Controler; import org.matsim.core.router.TripStructureUtils; @@ -44,8 +45,12 @@ public void testCorsica() throws ConfigurationException { System.out.println(RunCorsicaIT.class.getResource("/corsica/corsica_config.xml")); Config config = ConfigUtils.loadConfig(RunCorsicaIT.class.getResource("/corsica/corsica_config.xml")); - config.controler().setLastIteration(2); - config.controler().setWriteEventsInterval(1); + + ((QSimConfigGroup) config.getModules().get(QSimConfigGroup.GROUP_NAME)) + .setPcuThresholdForFlowCapacityEasing(1.0); + + config.controller().setLastIteration(2); + config.controller().setWriteEventsInterval(1); { // Remove some standard eqasim config groups @@ -55,7 +60,7 @@ public void testCorsica() throws ConfigurationException { // Replace some standard eqasim settings - for (StrategySettings strategy : config.strategy().getStrategySettings()) { + for (StrategySettings strategy : config.replanning().getStrategySettings()) { if (strategy.getStrategyName().equals("DiscreteModeChoice")) { strategy.setStrategyName("SubtourModeChoice"); } else if (strategy.getStrategyName().equals("KeepLastSelected")) { @@ -64,7 +69,7 @@ public void testCorsica() throws ConfigurationException { } String[] modes = { "car", "pt", "walk", "uam", "bike" }; ((SubtourModeChoiceConfigGroup) config.getModules().get("subtourModeChoice")).setModes(modes); - config.strategy().setPlanSelectorForRemoval("WorstPlanSelector"); + config.replanning().setPlanSelectorForRemoval("WorstPlanSelector"); config.transit().setUseTransit(true); config.transit().setUsingTransitInMobsim(true); @@ -75,7 +80,7 @@ public void testCorsica() throws ConfigurationException { DvrpConfigGroup dvrpConfig = new DvrpConfigGroup(); config.addModule(dvrpConfig); - DvrpConfigGroup.get(config).setNetworkModes(ImmutableSet.of("uam")); + dvrpConfig.networkModes = ImmutableSet.of("uam"); // Some necessary DVRP settings config.qsim().setSimStarttimeInterpretation(StarttimeInterpretation.onlyUseStarttime); @@ -95,10 +100,10 @@ public void testCorsica() throws ConfigurationException { uamConfig.setUseCharging("yes"); // Add UAM scoring - config.planCalcScore().addModeParams(new ModeParams("access_uam_car")); - config.planCalcScore().addModeParams(new ModeParams("egress_uam_car")); - config.planCalcScore().addModeParams(new ModeParams("uam")); - config.planCalcScore() + config.scoring().addModeParams(new ModeParams("access_uam_car")); + config.scoring().addModeParams(new ModeParams("egress_uam_car")); + config.scoring().addModeParams(new ModeParams("uam")); + config.scoring() .addActivityParams(new ActivityParams("uam_interaction").setScoringThisActivityAtAll(false)); } From e5df3efd9dedca0c59108bd1ed18e105869171f3 Mon Sep 17 00:00:00 2001 From: balacmi Date: Tue, 1 Oct 2024 10:33:25 +0200 Subject: [PATCH 13/19] defaultlinkspeedcalcualtor is not longer accessible --- .../uam/qsim/UAMLinkSpeedCalculator.java | 8 ++----- .../bhl/matsim/uam/qsim/UAMSpeedModule.java | 23 +++---------------- 2 files changed, 5 insertions(+), 26 deletions(-) diff --git a/src/main/java/net/bhl/matsim/uam/qsim/UAMLinkSpeedCalculator.java b/src/main/java/net/bhl/matsim/uam/qsim/UAMLinkSpeedCalculator.java index daffb7a..0b7dad9 100644 --- a/src/main/java/net/bhl/matsim/uam/qsim/UAMLinkSpeedCalculator.java +++ b/src/main/java/net/bhl/matsim/uam/qsim/UAMLinkSpeedCalculator.java @@ -17,15 +17,11 @@ public class UAMLinkSpeedCalculator implements LinkSpeedCalculator { final private Map mapVehicleVerticalSpeeds; final private Map mapVehicleHorizontalSpeeds; - final private LinkSpeedCalculator delegate; - public UAMLinkSpeedCalculator(Map mapVehicleVerticalSpeeds, - Map mapVehicleHorizontalSpeeds, LinkSpeedCalculator delegate) { + Map mapVehicleHorizontalSpeeds ) { // TODO: Use mapping of vehicle types instead of vehicles themselves. this.mapVehicleVerticalSpeeds = mapVehicleVerticalSpeeds; this.mapVehicleHorizontalSpeeds = mapVehicleHorizontalSpeeds; - - this.delegate = delegate; } @Override @@ -42,6 +38,6 @@ public double getMaximumVelocity(QVehicle vehicle, Link link, double time) { // Non-flight link } - return delegate.getMaximumVelocity(vehicle, link, time); + return Math.min( vehicle.getMaximumVelocity(), link.getFreespeed( time ) ); } } diff --git a/src/main/java/net/bhl/matsim/uam/qsim/UAMSpeedModule.java b/src/main/java/net/bhl/matsim/uam/qsim/UAMSpeedModule.java index e9dd446..41ae1a9 100644 --- a/src/main/java/net/bhl/matsim/uam/qsim/UAMSpeedModule.java +++ b/src/main/java/net/bhl/matsim/uam/qsim/UAMSpeedModule.java @@ -5,15 +5,8 @@ import net.bhl.matsim.uam.infrastructure.readers.UAMXMLReader; -import org.matsim.api.core.v01.Scenario; -import org.matsim.core.api.experimental.events.EventsManager; -import org.matsim.core.controler.AbstractModule; import org.matsim.core.mobsim.qsim.AbstractQSimModule; -import org.matsim.core.mobsim.qsim.qnetsimengine.ConfigurableQNetworkFactory; -import org.matsim.core.mobsim.qsim.qnetsimengine.QNetworkFactory; -import org.matsim.core.mobsim.qsim.qnetsimengine.linkspeedcalculator.DefaultLinkSpeedCalculator; - -import java.util.Map; +import org.matsim.core.mobsim.qsim.qnetsimengine.linkspeedcalculator.LinkSpeedCalculator; /** * A MATSim Abstract Module for classes used by UAM simulation regarding link @@ -25,22 +18,12 @@ public class UAMSpeedModule extends AbstractQSimModule { @Override public void configureQSim() { - - } - - @Provides - @Singleton - public QNetworkFactory provideQNetworkFactory(EventsManager events, Scenario scenario, - UAMLinkSpeedCalculator linkSpeedCalculator) { - ConfigurableQNetworkFactory networkFactory = new ConfigurableQNetworkFactory(events, scenario); - networkFactory.setLinkSpeedCalculator(linkSpeedCalculator); - return networkFactory; + bind(LinkSpeedCalculator.class).to(UAMLinkSpeedCalculator.class); } @Provides @Singleton public UAMLinkSpeedCalculator provideUAMLinkSpeedCalculator(UAMXMLReader uamReader) { - DefaultLinkSpeedCalculator delegate = new DefaultLinkSpeedCalculator(); - return new UAMLinkSpeedCalculator(uamReader.getMapVehicleVerticalSpeeds(), uamReader.getMapVehicleHorizontalSpeeds(), delegate); + return new UAMLinkSpeedCalculator(uamReader.getMapVehicleVerticalSpeeds(), uamReader.getMapVehicleHorizontalSpeeds()); } } From b389df9590f3d64904b7771b09ded3fb46a8ddb4 Mon Sep 17 00:00:00 2001 From: balacmi Date: Tue, 1 Oct 2024 10:33:55 +0200 Subject: [PATCH 14/19] requests can now have multiple passengers --- .../java/net/bhl/matsim/uam/schedule/UAMTransitEvent.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/bhl/matsim/uam/schedule/UAMTransitEvent.java b/src/main/java/net/bhl/matsim/uam/schedule/UAMTransitEvent.java index c312257..c206bb6 100644 --- a/src/main/java/net/bhl/matsim/uam/schedule/UAMTransitEvent.java +++ b/src/main/java/net/bhl/matsim/uam/schedule/UAMTransitEvent.java @@ -4,8 +4,8 @@ import net.bhl.matsim.uam.vrpagent.UAMActionCreator; import org.matsim.api.core.v01.Id; import org.matsim.api.core.v01.events.Event; +import org.matsim.api.core.v01.events.HasPersonId; import org.matsim.api.core.v01.population.Person; -import org.matsim.core.api.internal.HasPersonId; import java.util.Map; @@ -35,12 +35,13 @@ public String getEventType() { @Override public Map getAttributes() { Map attr = super.getAttributes(); - attr.put("person", request.getPassengerId().toString()); + attr.put("person", request.getPassengerIds().toString()); return attr; } @Override public Id getPersonId() { - return request.getPassengerId(); + //TODO: currently only returning one person, should be corrected int eh future milos '24' + return request.getPassengerIds().get(0); } } From d904cb89328c06e50f6199dcc2054be8faaab843 Mon Sep 17 00:00:00 2001 From: balacmi Date: Tue, 1 Oct 2024 10:34:55 +0200 Subject: [PATCH 15/19] fixes due to some dvrp changes i.e., StayTask -> DefaultStayTask; DriveTask -> DefaultDriveTask --- .../bhl/matsim/uam/schedule/UAMChargingTask.java | 4 ++-- .../bhl/matsim/uam/schedule/UAMDropoffTask.java | 4 ++-- .../net/bhl/matsim/uam/schedule/UAMPickupTask.java | 10 ++++++---- .../UAMSingleChargingActivityAppender.java | 6 ++++-- .../matsim/uam/schedule/UAMSingleRideAppender.java | 12 +++++++----- .../UAMSingleRideWithChargingAppender.java | 14 ++++++++------ 6 files changed, 29 insertions(+), 21 deletions(-) diff --git a/src/main/java/net/bhl/matsim/uam/schedule/UAMChargingTask.java b/src/main/java/net/bhl/matsim/uam/schedule/UAMChargingTask.java index 8e5d1a7..f9a3fca 100644 --- a/src/main/java/net/bhl/matsim/uam/schedule/UAMChargingTask.java +++ b/src/main/java/net/bhl/matsim/uam/schedule/UAMChargingTask.java @@ -2,11 +2,11 @@ import org.matsim.api.core.v01.Id; import org.matsim.api.core.v01.network.Link; -import org.matsim.contrib.dvrp.schedule.StayTask; +import org.matsim.contrib.dvrp.schedule.DefaultStayTask; import net.bhl.matsim.uam.infrastructure.UAMStation; -public class UAMChargingTask extends StayTask{ +public class UAMChargingTask extends DefaultStayTask{ private Id uamStationId; public UAMChargingTask(TaskType taskType, double beginTime, double endTime, Link link, Id uamStationId) { diff --git a/src/main/java/net/bhl/matsim/uam/schedule/UAMDropoffTask.java b/src/main/java/net/bhl/matsim/uam/schedule/UAMDropoffTask.java index 8266ba7..362d3fb 100644 --- a/src/main/java/net/bhl/matsim/uam/schedule/UAMDropoffTask.java +++ b/src/main/java/net/bhl/matsim/uam/schedule/UAMDropoffTask.java @@ -5,7 +5,7 @@ import java.util.Set; import org.matsim.api.core.v01.network.Link; -import org.matsim.contrib.dvrp.schedule.StayTask; +import org.matsim.contrib.dvrp.schedule.DefaultStayTask; import net.bhl.matsim.uam.passenger.UAMRequest; @@ -15,7 +15,7 @@ * * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) */ -public class UAMDropoffTask extends StayTask { +public class UAMDropoffTask extends DefaultStayTask { private final Set requests = new HashSet<>(); private final double deboardingTime; diff --git a/src/main/java/net/bhl/matsim/uam/schedule/UAMPickupTask.java b/src/main/java/net/bhl/matsim/uam/schedule/UAMPickupTask.java index e241805..b3f8bea 100644 --- a/src/main/java/net/bhl/matsim/uam/schedule/UAMPickupTask.java +++ b/src/main/java/net/bhl/matsim/uam/schedule/UAMPickupTask.java @@ -5,7 +5,8 @@ import java.util.Set; import org.matsim.api.core.v01.network.Link; -import org.matsim.contrib.dvrp.schedule.StayTask; +import org.matsim.contrib.dvrp.passenger.PassengerRequest; +import org.matsim.contrib.dvrp.schedule.DefaultStayTask; import net.bhl.matsim.uam.passenger.UAMRequest; @@ -15,8 +16,8 @@ * * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) */ -public class UAMPickupTask extends StayTask { - private final Set requests = new HashSet<>(); +public class UAMPickupTask extends DefaultStayTask { + private final Set requests = new HashSet<>(); private final double boardingTime; public UAMPickupTask(double beginTime, double endTime, Link link, double boardingTime) { @@ -33,10 +34,11 @@ public UAMPickupTask(double beginTime, double endTime, Link link, double boardin request.setPickupTask(this); } - public Set getRequests() { + public Set getRequests() { return this.requests; } + @Deprecated public void addRequest(UAMRequest request) { requests.add(request); request.setPickupTask(this); diff --git a/src/main/java/net/bhl/matsim/uam/schedule/UAMSingleChargingActivityAppender.java b/src/main/java/net/bhl/matsim/uam/schedule/UAMSingleChargingActivityAppender.java index d7cd887..7bd0785 100644 --- a/src/main/java/net/bhl/matsim/uam/schedule/UAMSingleChargingActivityAppender.java +++ b/src/main/java/net/bhl/matsim/uam/schedule/UAMSingleChargingActivityAppender.java @@ -8,6 +8,8 @@ import org.matsim.api.core.v01.network.Link; import org.matsim.contrib.dvrp.path.VrpPathWithTravelData; import org.matsim.contrib.dvrp.path.VrpPaths; +import org.matsim.contrib.dvrp.schedule.DefaultDriveTask; +import org.matsim.contrib.dvrp.schedule.DefaultStayTask; import org.matsim.contrib.dvrp.schedule.DriveTask; import org.matsim.contrib.dvrp.schedule.Schedule; import org.matsim.contrib.dvrp.schedule.Schedules; @@ -87,7 +89,7 @@ public void schedule(AppendTask task) throws ExecutionException, InterruptedExce VrpPathWithTravelData chargePathWithTravelData = VrpPaths.createPath(stayTask.getLink(), chargingLink, startTime, pickupPath, travelTime); - DriveTask chargingFlyTask = new DriveTask(UAMTaskType.FLY, chargePathWithTravelData); + DriveTask chargingFlyTask = new DefaultDriveTask(UAMTaskType.FLY, chargePathWithTravelData); schedule.addTask(chargingFlyTask); startTime = chargingFlyTask.getEndTime(); UAMChargingTask chargingTask = new UAMChargingTask(UAMTaskType.CHARGING, chargingFlyTask.getEndTime(), @@ -96,7 +98,7 @@ public void schedule(AppendTask task) throws ExecutionException, InterruptedExce schedule.addTask(chargingTask); } - schedule.addTask(new StayTask(UAMTaskType.STAY, startTime + 60.0, scheduleEndTime, chargingLink)); + schedule.addTask(new DefaultStayTask(UAMTaskType.STAY, startTime + 60.0, scheduleEndTime, chargingLink)); } public void update() { diff --git a/src/main/java/net/bhl/matsim/uam/schedule/UAMSingleRideAppender.java b/src/main/java/net/bhl/matsim/uam/schedule/UAMSingleRideAppender.java index a44861d..4897efb 100644 --- a/src/main/java/net/bhl/matsim/uam/schedule/UAMSingleRideAppender.java +++ b/src/main/java/net/bhl/matsim/uam/schedule/UAMSingleRideAppender.java @@ -7,6 +7,8 @@ import org.matsim.contrib.dvrp.path.VrpPathWithTravelData; import org.matsim.contrib.dvrp.path.VrpPaths; +import org.matsim.contrib.dvrp.schedule.DefaultDriveTask; +import org.matsim.contrib.dvrp.schedule.DefaultStayTask; import org.matsim.contrib.dvrp.schedule.DriveTask; import org.matsim.contrib.dvrp.schedule.Schedule; import org.matsim.contrib.dvrp.schedule.Schedules; @@ -75,7 +77,7 @@ public void schedule(AppendTask task) throws ExecutionException, InterruptedExce VrpPathWithTravelData pickupPathWithTravelData = VrpPaths.createPath(stayTask.getLink(), request.getFromLink(), startTime, pickupPath, travelTime); - DriveTask pickupFlyTask = new DriveTask(UAMTaskType.FLY, pickupPathWithTravelData); + DriveTask pickupFlyTask = new DefaultDriveTask(UAMTaskType.FLY, pickupPathWithTravelData); double pickUpTaskStartTime = request.getEarliestStartTime(); // For the case when the Aircraft is not already at the correct station: @@ -91,7 +93,7 @@ public void schedule(AppendTask task) throws ExecutionException, InterruptedExce VrpPathWithTravelData dropoffPathWithTravelData = VrpPaths.createPath(request.getFromLink(), request.getToLink(), flyTaskStartTime, dropoffPath, travelTime); - DriveTask dropoffFlyTask = new DriveTask(UAMTaskType.FLY, dropoffPathWithTravelData); + DriveTask dropoffFlyTask = new DefaultDriveTask(UAMTaskType.FLY, dropoffPathWithTravelData); double dropOffStartTime = flyTaskStartTime + dropoffPathWithTravelData.getTravelTime(); double tatStartTime = dropOffStartTime + vehicle.getDeboardingTime(); @@ -99,7 +101,7 @@ public void schedule(AppendTask task) throws ExecutionException, InterruptedExce vehicle.getDeboardingTime(), Collections.singletonList(request)); double tatEndTime = tatStartTime + vehicle.getTurnAroundTime(); - StayTask turnAroundTask = new StayTask(UAMTaskType.TURNAROUND, tatStartTime, tatEndTime, request.getToLink()); + StayTask turnAroundTask = new DefaultStayTask(UAMTaskType.TURNAROUND, tatStartTime, tatEndTime, request.getToLink()); double stayEndTime = pickUpTaskStartTime; if (requiresPickupFlight) @@ -109,7 +111,7 @@ public void schedule(AppendTask task) throws ExecutionException, InterruptedExce if (requiresPickupFlight) { schedule.addTask(pickupFlyTask); - StayTask uamStayTask = new StayTask(UAMTaskType.STAY, pickupFlyTask.getEndTime(), pickUpTaskStartTime, + StayTask uamStayTask = new DefaultStayTask(UAMTaskType.STAY, pickupFlyTask.getEndTime(), pickUpTaskStartTime, pickupFlyTask.getPath().getToLink()); schedule.addTask(uamStayTask); } @@ -119,7 +121,7 @@ public void schedule(AppendTask task) throws ExecutionException, InterruptedExce schedule.addTask(dropoffTask); schedule.addTask(turnAroundTask); schedule.addTask( - new StayTask(UAMTaskType.STAY, turnAroundTask.getEndTime(), scheduleEndTime, turnAroundTask.getLink())); + new DefaultStayTask(UAMTaskType.STAY, turnAroundTask.getEndTime(), scheduleEndTime, turnAroundTask.getLink())); } public void update() { diff --git a/src/main/java/net/bhl/matsim/uam/schedule/UAMSingleRideWithChargingAppender.java b/src/main/java/net/bhl/matsim/uam/schedule/UAMSingleRideWithChargingAppender.java index 9015af6..e6c512c 100644 --- a/src/main/java/net/bhl/matsim/uam/schedule/UAMSingleRideWithChargingAppender.java +++ b/src/main/java/net/bhl/matsim/uam/schedule/UAMSingleRideWithChargingAppender.java @@ -9,6 +9,8 @@ import org.matsim.api.core.v01.network.Link; import org.matsim.contrib.dvrp.path.VrpPathWithTravelData; import org.matsim.contrib.dvrp.path.VrpPaths; +import org.matsim.contrib.dvrp.schedule.DefaultDriveTask; +import org.matsim.contrib.dvrp.schedule.DefaultStayTask; import org.matsim.contrib.dvrp.schedule.DriveTask; import org.matsim.contrib.dvrp.schedule.Schedule; import org.matsim.contrib.dvrp.schedule.Schedules; @@ -82,7 +84,7 @@ public void schedule(AppendTask task) throws ExecutionException, InterruptedExce VrpPathWithTravelData pickupPathWithTravelData = VrpPaths.createPath(stayTask.getLink(), request.getFromLink(), startTime, pickupPath, travelTime); - DriveTask pickupFlyTask = new DriveTask(UAMTaskType.FLY, pickupPathWithTravelData); + DriveTask pickupFlyTask = new DefaultDriveTask(UAMTaskType.FLY, pickupPathWithTravelData); double pickUpTaskStartTime = request.getEarliestStartTime(); // For the case when the Aircraft is not already at the correct station: @@ -98,7 +100,7 @@ public void schedule(AppendTask task) throws ExecutionException, InterruptedExce VrpPathWithTravelData dropoffPathWithTravelData = VrpPaths.createPath(request.getFromLink(), request.getToLink(), flyTaskStartTime, dropoffPath, travelTime); - DriveTask dropoffFlyTask = new DriveTask(UAMTaskType.FLY, dropoffPathWithTravelData); + DriveTask dropoffFlyTask = new DefaultDriveTask(UAMTaskType.FLY, dropoffPathWithTravelData); double dropOffStartTime = flyTaskStartTime + dropoffPathWithTravelData.getTravelTime(); double tatStartTime = dropOffStartTime + vehicle.getDeboardingTime(); @@ -106,7 +108,7 @@ public void schedule(AppendTask task) throws ExecutionException, InterruptedExce vehicle.getDeboardingTime(), Collections.singletonList(request)); double tatEndTime = tatStartTime + vehicle.getTurnAroundTime(); - StayTask turnAroundTask = new StayTask(UAMTaskType.TURNAROUND, tatStartTime, tatEndTime, request.getToLink()); + StayTask turnAroundTask = new DefaultStayTask(UAMTaskType.TURNAROUND, tatStartTime, tatEndTime, request.getToLink()); double stayEndTime = pickUpTaskStartTime; if (requiresPickupFlight) @@ -116,7 +118,7 @@ public void schedule(AppendTask task) throws ExecutionException, InterruptedExce if (requiresPickupFlight) { schedule.addTask(pickupFlyTask); - StayTask uamStayTask = new StayTask(UAMTaskType.STAY, pickupFlyTask.getEndTime(), pickUpTaskStartTime, + StayTask uamStayTask = new DefaultStayTask(UAMTaskType.STAY, pickupFlyTask.getEndTime(), pickUpTaskStartTime, pickupFlyTask.getPath().getToLink()); schedule.addTask(uamStayTask); } @@ -143,7 +145,7 @@ public void schedule(AppendTask task) throws ExecutionException, InterruptedExce VrpPathWithTravelData chargingPathWithTravelData = VrpPaths.createPath(dropoffTask.getLink(), chargingLink, turnAroundTask.getEndTime(), chargingPath, travelTime); - DriveTask chargingFlyTask = new DriveTask(UAMTaskType.FLY, chargingPathWithTravelData); + DriveTask chargingFlyTask = new DefaultDriveTask(UAMTaskType.FLY, chargingPathWithTravelData); schedule.addTask(chargingFlyTask); UAMChargingTask chargingTask = new UAMChargingTask(UAMTaskType.CHARGING, chargingFlyTask.getEndTime(), @@ -152,7 +154,7 @@ public void schedule(AppendTask task) throws ExecutionException, InterruptedExce schedule.addTask(chargingTask); } - schedule.addTask(new StayTask(UAMTaskType.STAY, turnAroundTask.getEndTime() + 60, scheduleEndTime, + schedule.addTask(new DefaultStayTask(UAMTaskType.STAY, turnAroundTask.getEndTime() + 60, scheduleEndTime, turnAroundTask.getLink())); } From e7944d2fe3baf22f8ebb0bfe05ce329fb4bd34c0 Mon Sep 17 00:00:00 2001 From: balacmi Date: Tue, 1 Oct 2024 10:35:21 +0200 Subject: [PATCH 16/19] using AbstractDvrpModeModule instead of AbstractModule --- .../net/bhl/matsim/uam/run/UAMModule.java | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/main/java/net/bhl/matsim/uam/run/UAMModule.java b/src/main/java/net/bhl/matsim/uam/run/UAMModule.java index 1aa7c65..fd67c73 100644 --- a/src/main/java/net/bhl/matsim/uam/run/UAMModule.java +++ b/src/main/java/net/bhl/matsim/uam/run/UAMModule.java @@ -6,6 +6,7 @@ import org.matsim.contrib.dvrp.passenger.DefaultPassengerRequestValidator; import org.matsim.contrib.dvrp.passenger.PassengerRequestValidator; import org.matsim.contrib.dvrp.router.DvrpModeRoutingNetworkModule; +import org.matsim.contrib.dvrp.run.AbstractDvrpModeModule; import org.matsim.contrib.dvrp.run.DvrpMode; import org.matsim.contrib.dvrp.run.DvrpModes; import org.matsim.contrib.dvrp.vrpagent.VrpAgentSourceQSimModule; @@ -49,19 +50,20 @@ * * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) */ -public class UAMModule extends AbstractModule { +public class UAMModule extends AbstractDvrpModeModule { private Config config; public UAMModule(Config config) { + super(UAMConstants.uam); this.config = config; } @Override public void install() { - DvrpModes.registerDvrpMode(binder(), UAMConstants.uam); - install(new DvrpModeRoutingNetworkModule(UAMConstants.uam, true)); + DvrpModes.registerDvrpMode(binder(), getMode()); + install(new DvrpModeRoutingNetworkModule(getMode(), true)); + + bindModal(PassengerRequestValidator.class).to(DefaultPassengerRequestValidator.class); - bind(DvrpModes.key(PassengerRequestValidator.class, UAMConstants.uam)) - .toInstance(new DefaultPassengerRequestValidator()); installQSimModule(new UAMQSimModule()); // bining our own scoring function factory @@ -98,11 +100,12 @@ public void install() { // MainModeIdentifierImpl())); // here we provide vehicles and network to be used for uam trips - bind(VehicleType.class).annotatedWith(Names.named(UAMConstants.uam)) - .toInstance(VehicleUtils.getDefaultVehicleType()); + // bind(VehicleType.class).annotatedWith(Names.named(UAMConstants.uam)) + // .toInstance(VehicleUtils.getDefaultVehicleType()); - bind(VehicleType.class).annotatedWith(Names.named(VrpAgentSourceQSimModule.DVRP_VEHICLE_TYPE)) - .toInstance(VehicleUtils.getDefaultVehicleType()); + bindModal(VehicleType.class).toInstance(VehicleUtils.getDefaultVehicleType()); + //bind(VehicleType.class).annotatedWith(Names.named(VrpAgentSourceQSimModule.DVRP_VEHICLE_TYPE)) + // .toInstance(VehicleUtils.getDefaultVehicleType()); bind(TravelTime.class).annotatedWith(Names.named(UAMConstants.uam)).toInstance(new FreeSpeedTravelTime()); From 0b97717ec7f6c05447403c34e08109f765e1f117 Mon Sep 17 00:00:00 2001 From: balacmi Date: Tue, 1 Oct 2024 10:35:36 +0200 Subject: [PATCH 17/19] Update UAMQSimModule.java StayTask-> DefaultStayTask --- src/main/java/net/bhl/matsim/uam/qsim/UAMQSimModule.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/bhl/matsim/uam/qsim/UAMQSimModule.java b/src/main/java/net/bhl/matsim/uam/qsim/UAMQSimModule.java index f51bce6..bea15c3 100644 --- a/src/main/java/net/bhl/matsim/uam/qsim/UAMQSimModule.java +++ b/src/main/java/net/bhl/matsim/uam/qsim/UAMQSimModule.java @@ -21,7 +21,7 @@ import org.matsim.contrib.dvrp.run.AbstractDvrpModeQSimModule; import org.matsim.contrib.dvrp.run.DvrpMode; import org.matsim.contrib.dvrp.run.DvrpQSimComponents; -import org.matsim.contrib.dvrp.schedule.StayTask; +import org.matsim.contrib.dvrp.schedule.DefaultStayTask; import org.matsim.contrib.dvrp.tracker.OnlineTrackerListener; import org.matsim.contrib.dvrp.vrpagent.VrpAgentLogic.DynActionCreator; import org.matsim.contrib.dvrp.vrpagent.VrpAgentSourceQSimModule; @@ -156,7 +156,7 @@ public UAMFleetData provideData(UAMXMLReader uamReader, UAMManager uamManager) { for (DvrpVehicle veh : returnVehicles.values()) { // create a new Fleet every new iteration - veh.getSchedule().addTask(new StayTask(UAMTaskType.STAY, veh.getServiceBeginTime(), + veh.getSchedule().addTask(new DefaultStayTask(UAMTaskType.STAY, veh.getServiceBeginTime(), Double.POSITIVE_INFINITY, veh.getStartLink())); returnVehicles.put(veh.getId(), (UAMVehicle) veh); } From 9ddd62f85d977d1b414fbc0ad06a0546ac76c0f4 Mon Sep 17 00:00:00 2001 From: balacmi Date: Tue, 1 Oct 2024 10:37:37 +0200 Subject: [PATCH 18/19] Update README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 44df499..9bfcf6f 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,9 @@ Versions 4.1.2, 4.1.1, 4.1.0, 4.0.1, 4.0.0, and 3.0.0 are also available. Older ### Development +- Update to MATSim 2024.0 +- Update to Java 21 + ### v4.1.3 - fixed the Bug regarding running the script "RunCalculateUAMTravelTimes.java" on Mac/Linux From 8b8432b2428de3e5cfd6157cf2209b1e0f25e8d7 Mon Sep 17 00:00:00 2001 From: balacmi Date: Tue, 1 Oct 2024 10:46:02 +0200 Subject: [PATCH 19/19] Update maven.yml update to java 21 --- .github/workflows/maven.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index cd59139..9547d28 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -13,9 +13,9 @@ jobs: steps: - uses: actions/checkout@v2 - - name: Set up JDK 11 + - name: Set up JDK 21 uses: actions/setup-java@v1 with: - java-version: 1.11 + java-version: '21' - name: Build with Maven run: mvn verify -B -Dmatsim.preferLocalDtds=true