├── _config.yml ├── examples ├── uam-traveltimes-input │ └── trips.csv ├── uam-test-scenario │ ├── uam_vehicles.xml.gz │ ├── uam_routed_network.xml.gz │ └── uam_distances.csv └── uam-scenario-creation │ ├── flight-nodes.csv │ ├── flight-links.csv │ ├── vehicles.csv │ ├── stations.csv │ └── non-uam-scenario │ ├── config.xml │ └── network.xml ├── src ├── test │ └── resources │ │ └── corsica │ │ ├── corsica_network.xml.gz │ │ ├── corsica_facilities.xml.gz │ │ ├── corsica_households.xml.gz │ │ ├── corsica_population.xml.gz │ │ ├── corsica_transit_schedule.xml.gz │ │ ├── corsica_transit_vehicles.xml.gz │ │ └── uam_network.xml └── main │ ├── java │ └── net │ │ └── bhl │ │ └── matsim │ │ └── uam │ │ ├── schedule │ │ ├── SingleRideAppender.java │ │ ├── UAMTaskType.java │ │ ├── UAMChargingTask.java │ │ ├── UAMTransitEvent.java │ │ ├── UAMDropoffTask.java │ │ └── UAMPickupTask.java │ │ ├── router │ │ ├── package-info.java │ │ ├── UAMFlightSegments.java │ │ ├── strategy │ │ │ ├── UAMStrategy.java │ │ │ ├── UAMMinAccessDistanceStrategy.java │ │ │ ├── UAMMinAccessTravelTimeStrategy.java │ │ │ ├── UAMMinTravelTimeStrategy.java │ │ │ ├── UAMMinDistanceStrategy.java │ │ │ └── UAMStrategyRouter.java │ │ ├── UAMMainModeIdentifier.java │ │ └── UAMRoutingModuleProvider.java │ │ ├── infrastructure │ │ ├── UAMCharger.java │ │ ├── package-info.java │ │ ├── readers │ │ │ ├── package-info.java │ │ │ └── CSVReaders.java │ │ ├── UAMStation.java │ │ ├── UAMStationSimple.java │ │ ├── UAMStationWithChargers.java │ │ ├── UAMStations.java │ │ ├── UAMVehicleType.java │ │ └── UAMVehicle.java │ │ ├── qsim │ │ ├── package-info.java │ │ ├── UAMSpeedModule.java │ │ ├── UAMLinkSpeedCalculator.java │ │ └── UAMTripInfo.java │ │ ├── events │ │ ├── package-info.java │ │ ├── ChargingStartEventHandler.java │ │ ├── UAMTransitEventHandler.java │ │ ├── UAMUtilitiesData.java │ │ ├── ChargingStartEvent.java │ │ ├── UAMUtilitiesAccessEgress.java │ │ ├── UAMUtilitiesTrip.java │ │ └── UAMData.java │ │ ├── scoring │ │ ├── package-info.java │ │ └── UAMScoringFunctionFactory.java │ │ ├── dispatcher │ │ ├── package-info.java │ │ ├── UAMDispatcherListener.java │ │ ├── UAMDispatcher.java │ │ └── UAMManager.java │ │ ├── analysis │ │ ├── trips │ │ │ ├── utils │ │ │ │ ├── HomeActivityTypes.java │ │ │ │ └── BasicHomeActivityTypes.java │ │ │ ├── listeners │ │ │ │ ├── TripListenerItem.java │ │ │ │ └── DeckGLTripListener.java │ │ │ ├── readers │ │ │ │ └── EventsTripReader.java │ │ │ ├── TripItem.java │ │ │ ├── run │ │ │ │ ├── BatchConvertTripsFromEvents.java │ │ │ │ ├── BatchConvertTripsFromPopulation.java │ │ │ │ ├── ConvertTripsFromPopulation.java │ │ │ │ ├── RunConvertDeckGLBuildings.java │ │ │ │ ├── ConvertTripsFromEvents.java │ │ │ │ └── ConvertDeckGLTripsFromEvents.java │ │ │ ├── DeckGLTripItem.java │ │ │ └── CSVTripWriter.java │ │ ├── traveltimes │ │ │ └── utils │ │ │ │ ├── ThreadCounter.java │ │ │ │ ├── TripItem.java │ │ │ │ └── TripItemReader.java │ │ ├── uamdemand │ │ │ ├── listeners │ │ │ │ ├── ChargingItem.java │ │ │ │ ├── UAMListenerItem.java │ │ │ │ └── UAMChargingHandler.java │ │ │ ├── readers │ │ │ │ └── EventsUAMReader.java │ │ │ ├── run │ │ │ │ ├── BatchConvertUAMDemandFromEvents.java │ │ │ │ └── ConvertUAMDemandFromEvents.java │ │ │ ├── UAMDemandItem.java │ │ │ └── CSVUAMDemandWriter.java │ │ ├── traffic │ │ │ ├── LinkStatsItem.java │ │ │ ├── run │ │ │ │ ├── BatchConvertLinkStatsFromEvents.java │ │ │ │ └── ConvertLinkStatsFromEvents.java │ │ │ └── CSVLinkStatsWriter.java │ │ ├── uamstations │ │ │ ├── UAMStationItem.java │ │ │ ├── run │ │ │ │ ├── BatchConvertUAMStationsFromUAMVehicles.java │ │ │ │ └── ConvertUAMStationsFromUAMVehicles.java │ │ │ └── CSVUAMStationWriter.java │ │ ├── linkspeed │ │ │ ├── RunUAMLinkSpeedCheckFromEvents.java │ │ │ └── UAMLinkTravelSpeedHandler.java │ │ └── RunBatchConversions.java │ │ ├── data │ │ ├── UAMAccessLeg.java │ │ ├── UAMFlightLeg.java │ │ ├── UAMRoute.java │ │ ├── UAMFleetData.java │ │ ├── UAMRoutes.java │ │ ├── UAMAccessOptions.java │ │ ├── WaitingStationData.java │ │ ├── WaitingData.java │ │ └── UAMStationConnectionGraph.java │ │ ├── run │ │ ├── UAMConstants.java │ │ └── RunUAMScenario.java │ │ ├── vrpagent │ │ ├── UAMStayActivity.java │ │ └── UAMActionCreator.java │ │ ├── scenario │ │ ├── RunCreateUAMBeelineScenario.java │ │ ├── network │ │ │ └── RunAddModeToNetwork.java │ │ └── population │ │ │ ├── RunFilterPopulation.java │ │ │ ├── RunAddPopulationAttributes.java │ │ │ ├── RunSamplePopulation.java │ │ │ └── RunCreateUAMPersonAttributes.java │ │ ├── passenger │ │ ├── UAMChargingActivity.java │ │ ├── UAMRequestCreator.java │ │ ├── UAMPassengerDropoffActivity.java │ │ ├── UAMRequest.java │ │ └── UAMSinglePassengerPerRequestPickupActivity.java │ │ ├── charging │ │ └── DischargingHandler.java │ │ └── listeners │ │ ├── UAMShutdownListener.java │ │ └── UAMListener.java │ └── assembly │ └── assembly-release.xml ├── .github └── workflows │ └── maven.yml ├── docs └── versioning.md ├── pom.xml └── .gitignore /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-cayman 2 | show_downloads: "true" 3 | -------------------------------------------------------------------------------- /examples/uam-traveltimes-input/trips.csv: -------------------------------------------------------------------------------- 1 | from_x,from_y,to_x,to_y,start_time 2 | 0,0,20040,0,06:00 3 | 20040,0,0,0,07:08:09 -------------------------------------------------------------------------------- /examples/uam-test-scenario/uam_vehicles.xml.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BauhausLuftfahrt/MATSim-UAM/HEAD/examples/uam-test-scenario/uam_vehicles.xml.gz -------------------------------------------------------------------------------- /src/test/resources/corsica/corsica_network.xml.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BauhausLuftfahrt/MATSim-UAM/HEAD/src/test/resources/corsica/corsica_network.xml.gz -------------------------------------------------------------------------------- /examples/uam-test-scenario/uam_routed_network.xml.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BauhausLuftfahrt/MATSim-UAM/HEAD/examples/uam-test-scenario/uam_routed_network.xml.gz -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/schedule/SingleRideAppender.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.schedule; 2 | 3 | public interface SingleRideAppender { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /src/test/resources/corsica/corsica_facilities.xml.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BauhausLuftfahrt/MATSim-UAM/HEAD/src/test/resources/corsica/corsica_facilities.xml.gz -------------------------------------------------------------------------------- /src/test/resources/corsica/corsica_households.xml.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BauhausLuftfahrt/MATSim-UAM/HEAD/src/test/resources/corsica/corsica_households.xml.gz -------------------------------------------------------------------------------- /src/test/resources/corsica/corsica_population.xml.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BauhausLuftfahrt/MATSim-UAM/HEAD/src/test/resources/corsica/corsica_population.xml.gz -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/router/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) 3 | */ 4 | package net.bhl.matsim.uam.router; -------------------------------------------------------------------------------- /src/test/resources/corsica/corsica_transit_schedule.xml.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BauhausLuftfahrt/MATSim-UAM/HEAD/src/test/resources/corsica/corsica_transit_schedule.xml.gz -------------------------------------------------------------------------------- /src/test/resources/corsica/corsica_transit_vehicles.xml.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BauhausLuftfahrt/MATSim-UAM/HEAD/src/test/resources/corsica/corsica_transit_vehicles.xml.gz -------------------------------------------------------------------------------- /examples/uam-scenario-creation/flight-nodes.csv: -------------------------------------------------------------------------------- 1 | node_id,x,y,z 2 | 0,6020,500,600 3 | 1,6020,-500,600 4 | 2,7515,250,600 5 | 3,12525,-250,600 6 | 4,14020,500,600 7 | 5,14020,-500,600 8 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/infrastructure/UAMCharger.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.infrastructure; 2 | 3 | public interface UAMCharger { 4 | 5 | double chargingSpeed(); 6 | 7 | int numberOfChargers(); 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/qsim/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) 3 | */ 4 | /** 5 | * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) 6 | * 7 | */ 8 | package net.bhl.matsim.uam.qsim; -------------------------------------------------------------------------------- /examples/uam-scenario-creation/flight-links.csv: -------------------------------------------------------------------------------- 1 | from_node,to_node,link_capacity,link_freespeed 2 | 0,2,999,35 3 | 1,2,999,35 4 | 2,3,999,35 5 | 3,4,999,35 6 | 3,5,999,35 7 | 2,0,999,35 8 | 2,1,999,35 9 | 3,2,999,35 10 | 4,3,999,35 11 | 5,3,999,35 12 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/events/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) 3 | */ 4 | /** 5 | * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) 6 | * 7 | */ 8 | package net.bhl.matsim.uam.events; -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/scoring/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) 3 | */ 4 | /** 5 | * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) 6 | * 7 | */ 8 | package net.bhl.matsim.uam.scoring; -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/dispatcher/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) 3 | */ 4 | /** 5 | * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) 6 | * 7 | */ 8 | package net.bhl.matsim.uam.dispatcher; -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/infrastructure/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) 3 | */ 4 | /** 5 | * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) 6 | * 7 | */ 8 | package net.bhl.matsim.uam.infrastructure; -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/schedule/UAMTaskType.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.schedule; 2 | 3 | import org.matsim.contrib.dvrp.schedule.Task; 4 | 5 | public enum UAMTaskType implements Task.TaskType { 6 | PICKUP, DROPOFF, FLY, STAY, PARK, TURNAROUND, CHARGING 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/events/ChargingStartEventHandler.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.events; 2 | 3 | import org.matsim.core.events.handler.EventHandler; 4 | 5 | public interface ChargingStartEventHandler extends EventHandler { 6 | void handleEvent(ChargingStartEvent event); 7 | 8 | } 9 | -------------------------------------------------------------------------------- /examples/uam-scenario-creation/vehicles.csv: -------------------------------------------------------------------------------- 1 | vehicle_type,vehicleperstation,starttime,endtime,range,capacity,cruisespeed,verticalspeed,boardingtime,deboardingtime,turnaroundtime,maximumCharge,energyConsumptionHorizontal,energyConsumptionVertical 2 | S,2,00:00:00,24:00:00,60000,2,33.3,10,30,30,120,999,0,0 3 | L,2,05:00:00,21:00:00,30000,4,22.2,10,60,60,300,999,0,0 4 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/analysis/trips/utils/HomeActivityTypes.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.analysis.trips.utils; 2 | 3 | /** 4 | * An interface for home activity types. 5 | * 6 | * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) 7 | */ 8 | public interface HomeActivityTypes { 9 | boolean isHomeActivity(String activityType); 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/data/UAMAccessLeg.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.data; 2 | 3 | import org.matsim.api.core.v01.network.Link; 4 | 5 | import java.util.List; 6 | 7 | public class UAMAccessLeg extends UAMFlightLeg { 8 | public UAMAccessLeg(double travelTime, double distance, List links) { 9 | super(travelTime, distance, links); 10 | } 11 | } -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/analysis/traveltimes/utils/ThreadCounter.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.analysis.traveltimes.utils; 2 | 3 | public class ThreadCounter { 4 | private int processes; 5 | 6 | public synchronized void register() { 7 | processes++; 8 | } 9 | 10 | public synchronized void deregister() { 11 | processes--; 12 | } 13 | 14 | public synchronized int getProcesses() { 15 | return processes; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/events/UAMTransitEventHandler.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.events; 2 | 3 | import net.bhl.matsim.uam.schedule.UAMTransitEvent; 4 | import org.matsim.core.events.handler.EventHandler; 5 | 6 | /** 7 | * An interface for the UAMTransit events. 8 | * 9 | * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) 10 | */ 11 | public interface UAMTransitEventHandler extends EventHandler { 12 | void handleEvent(UAMTransitEvent event); 13 | } -------------------------------------------------------------------------------- /.github/workflows/maven.yml: -------------------------------------------------------------------------------- 1 | name: Maven Test 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | jobs: 10 | build: 11 | 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | - uses: actions/checkout@v2 16 | - name: Set up JDK 21 17 | uses: actions/setup-java@v1 18 | with: 19 | java-version: '21' 20 | - name: Build with Maven 21 | run: mvn verify -B -Dmatsim.preferLocalDtds=true 22 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/infrastructure/readers/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) 3 | *

4 | * This package contains the readers for the stations and vehicles 5 | * files. 6 | */ 7 | /** 8 | * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) 9 | * 10 | * This package contains the readers for the stations and vehicles 11 | * files. 12 | * 13 | */ 14 | package net.bhl.matsim.uam.infrastructure.readers; -------------------------------------------------------------------------------- /examples/uam-scenario-creation/stations.csv: -------------------------------------------------------------------------------- 1 | station_id,station_name,x,y,z,vtol_z,ground_access_capacity,ground_access_freespeed,flight_access_capacity,flight_access_freespeed,preflighttime,postflighttime,defaultwaittime,numberOfChargers,chargingSpeed 2 | A,Alpha,6020,500,0,600,999,35,999,35,900,300,0,99999,99999 3 | B,Bravo,6020,-500,0,600,999,35,999,35,600,120,480,99999,99999 4 | C,Charlie,14020,500,0,600,999,35,999,35,300,60,0,99999,99999 5 | D,Delta,14020,-500,0,600,999,35,999,35,150,30,300,99999,99999 6 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/analysis/trips/utils/BasicHomeActivityTypes.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.analysis.trips.utils; 2 | 3 | /** 4 | * An implementation of {@link HomeActivityTypes} for basic home activities. 5 | * 6 | * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) 7 | */ 8 | public class BasicHomeActivityTypes implements HomeActivityTypes { 9 | @Override 10 | public boolean isHomeActivity(String activityType) { 11 | return activityType.contains("home"); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/data/UAMFlightLeg.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.data; 2 | 3 | import org.matsim.api.core.v01.network.Link; 4 | 5 | import java.util.List; 6 | 7 | public class UAMFlightLeg { 8 | public final double travelTime; 9 | public final double distance; 10 | public final List links; 11 | 12 | public UAMFlightLeg(double travelTime, double distance, List links) { 13 | this.travelTime = travelTime; 14 | this.distance = distance; 15 | this.links = links; 16 | } 17 | } -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/events/UAMUtilitiesData.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.events; 2 | 3 | import java.util.HashSet; 4 | import java.util.Set; 5 | 6 | /** 7 | * Class that stores utilities for trips and access legs. 8 | * 9 | * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) 10 | */ 11 | @Deprecated 12 | public class UAMUtilitiesData { 13 | public static Set accessEgressOptions = new HashSet<>(); 14 | public static Set tripOptions = new HashSet<>(); 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/analysis/uamdemand/listeners/ChargingItem.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.analysis.uamdemand.listeners; 2 | 3 | public class ChargingItem { 4 | public String vehicleId; 5 | public double startingTime; 6 | public double endTime; 7 | public double startingCharge; 8 | public String stationId; 9 | 10 | public ChargingItem(String vehicleId, double startingTime, double endTime, double startingCharge, String stationId) { 11 | this.vehicleId = vehicleId; 12 | this.startingTime = startingTime; 13 | this.startingCharge = startingCharge; 14 | this.endTime = endTime; 15 | this.stationId = stationId; 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/analysis/traveltimes/utils/TripItem.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.analysis.traveltimes.utils; 2 | 3 | import org.matsim.api.core.v01.Coord; 4 | 5 | 6 | public class TripItem { 7 | public Coord origin; 8 | public Coord destination; 9 | public double departureTime; 10 | public double travelTime; 11 | public String description; 12 | 13 | public double distance; 14 | public double accessTime; 15 | public double flightTime; 16 | public double egressTime; 17 | public double processTime; 18 | public String accessMode; 19 | public String egressMode; 20 | public String originStation; 21 | public String destinationStation; 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/events/ChargingStartEvent.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.events; 2 | 3 | import org.matsim.api.core.v01.events.Event; 4 | 5 | import net.bhl.matsim.uam.infrastructure.UAMVehicle; 6 | 7 | public class ChargingStartEvent extends Event{ 8 | 9 | private final static String EVENT_TYPE = "UAMStartChargingEvent"; 10 | 11 | private UAMVehicle uamVehicle; 12 | public ChargingStartEvent(double time, UAMVehicle uamVehicle) { 13 | super(time); 14 | this.uamVehicle = uamVehicle; 15 | } 16 | 17 | public UAMVehicle getUamVehicle() { 18 | return uamVehicle; 19 | } 20 | 21 | @Override 22 | public String getEventType() { 23 | return ChargingStartEvent.EVENT_TYPE; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/schedule/UAMChargingTask.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.schedule; 2 | 3 | import org.matsim.api.core.v01.Id; 4 | import org.matsim.api.core.v01.network.Link; 5 | import org.matsim.contrib.dvrp.schedule.DefaultStayTask; 6 | 7 | import net.bhl.matsim.uam.infrastructure.UAMStation; 8 | 9 | public class UAMChargingTask extends DefaultStayTask{ 10 | 11 | private Id uamStationId; 12 | public UAMChargingTask(TaskType taskType, double beginTime, double endTime, Link link, Id uamStationId) { 13 | super(taskType, beginTime, endTime, link); 14 | this.uamStationId = uamStationId; 15 | 16 | } 17 | public Id getUamStationId() { 18 | return uamStationId; 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/run/UAMConstants.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.run; 2 | 3 | /** 4 | * Provides UAM trip segment identifiers. The following trips are currently being modelled: UAM access trip (via 5 | * traditional mode (e.g. walk, bike, car), UAM station interaction, flight segments, UAM station interaction, 6 | * UAM egress trip. 7 | * 8 | * @author RRothfeld (Raoul Rothfeld) 9 | */ 10 | public class UAMConstants { 11 | public static final String uam = "uam"; 12 | 13 | public static final String access = "access_" + uam + "_"; 14 | public static final String egress = "egress_" + uam + "_"; 15 | 16 | public static final String interaction = uam + "_interaction"; 17 | 18 | public static final String vehicle = uam + "_vh_"; 19 | } -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/router/UAMFlightSegments.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.router; 2 | 3 | import net.bhl.matsim.uam.run.UAMConstants; 4 | 5 | /** 6 | * Provides flight segment identifiers for MATSim network links. Currently uses two flight segments: horizontal (i.e. 7 | * cruise flight), which is the default flight segment, and vertical (i.e. take-off and landings). Can be extended to 8 | * various flight segments in the future. 9 | * 10 | * @author RRothfeld (Raoul Rothfeld) 11 | */ 12 | public class UAMFlightSegments { 13 | public static final String ATTRIBUTE = "type"; 14 | 15 | public static final String HORIZONTAL = UAMConstants.uam + "_horizontal"; 16 | public static final String VERTICAL = UAMConstants.uam + "_vertical"; 17 | } 18 | -------------------------------------------------------------------------------- /examples/uam-test-scenario/uam_distances.csv: -------------------------------------------------------------------------------- 1 | fromStation,fromNode,toStation,toNode,cruisedistance,vtoldistance 2 | D,uam_st_D_fa,C,uam_st_C_fa,3188.3392277060584,1200.0 3 | D,uam_st_D_fa,A,uam_st_A_fa,8066.406052464452,1200.0 4 | D,uam_st_D_fa,B,uam_st_B_fa,8223.227508492435,1200.0 5 | C,uam_st_C_fa,D,uam_st_D_fa,3188.3392277060584,1200.0 6 | C,uam_st_C_fa,A,uam_st_A_fa,8223.227508492435,1200.0 7 | C,uam_st_C_fa,B,uam_st_B_fa,8380.048964520418,1200.0 8 | A,uam_st_A_fa,D,uam_st_D_fa,8066.406052464452,1200.0 9 | A,uam_st_A_fa,C,uam_st_C_fa,8223.227508492435,1200.0 10 | A,uam_st_A_fa,B,uam_st_B_fa,3188.3392277060584,1200.0 11 | B,uam_st_B_fa,D,uam_st_D_fa,8223.227508492435,1200.0 12 | B,uam_st_B_fa,C,uam_st_C_fa,8380.048964520418,1200.0 13 | B,uam_st_B_fa,A,uam_st_A_fa,3188.3392277060584,1200.0 14 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/data/UAMRoute.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.data; 2 | 3 | import net.bhl.matsim.uam.infrastructure.UAMStation; 4 | 5 | /** 6 | * Class that stores information about a UAM route. 7 | * 8 | * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) 9 | */ 10 | public class UAMRoute { 11 | public String accessMode; 12 | public UAMStation bestOriginStation; 13 | public UAMStation bestDestinationStation; 14 | public String egressMode; 15 | 16 | public UAMRoute(String accessMode, UAMStation bestOriginStation, UAMStation bestDestinationStation, String egressMode) { 17 | this.accessMode = accessMode; 18 | this.bestOriginStation = bestOriginStation; 19 | this.bestDestinationStation = bestDestinationStation; 20 | this.egressMode = egressMode; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/analysis/uamdemand/listeners/UAMListenerItem.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.analysis.uamdemand.listeners; 2 | 3 | import net.bhl.matsim.uam.analysis.uamdemand.UAMDemandItem; 4 | import org.matsim.api.core.v01.Coord; 5 | import org.matsim.api.core.v01.Id; 6 | import org.matsim.api.core.v01.population.Person; 7 | 8 | /** 9 | * This class stores information about a UAMtrip performed. 10 | * 11 | * @author Aitanm (Aitan Militao), RRothfeld (Raoul Rothfeld) 12 | */ 13 | public class UAMListenerItem extends UAMDemandItem { 14 | public UAMListenerItem(Id personId, Coord origin, double startTime, String accessMode) { 15 | super(personId, origin, null, null, null, null, null, startTime, Double.NaN, Double.NaN, Double.NaN, Double.NaN, 16 | Double.NaN, "unknown", accessMode, "unknown", false); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/analysis/traffic/LinkStatsItem.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.analysis.traffic; 2 | 3 | import org.matsim.api.core.v01.Id; 4 | import org.matsim.api.core.v01.network.Link; 5 | 6 | import java.util.Map; 7 | 8 | /** 9 | * This class stores link information in a specific time. 10 | * 11 | * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) 12 | */ 13 | public class LinkStatsItem { 14 | public Id linkId; 15 | public double distance; 16 | public double freeSpeed; 17 | public Map timeDependantSpeed; 18 | 19 | public LinkStatsItem(Id linkId, double distance, double freeSpeed, Map timeDependantSpeed) { 20 | this.linkId = linkId; 21 | this.distance = distance; 22 | this.freeSpeed = freeSpeed; 23 | this.timeDependantSpeed = timeDependantSpeed; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/dispatcher/UAMDispatcherListener.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.dispatcher; 2 | 3 | import com.google.inject.Inject; 4 | import org.matsim.core.mobsim.framework.events.MobsimBeforeSimStepEvent; 5 | import org.matsim.core.mobsim.framework.listeners.MobsimBeforeSimStepListener; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * A listener for the UAMDispatchers to prepare for next simulation step. 11 | * 12 | * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) 13 | */ 14 | public class UAMDispatcherListener implements MobsimBeforeSimStepListener { 15 | 16 | @Inject 17 | List dispatchers; 18 | 19 | @Override 20 | public void notifyMobsimBeforeSimStep(MobsimBeforeSimStepEvent e) { 21 | for (UAMDispatcher d : dispatchers) { 22 | d.onNextTimeStep(e.getSimulationTime()); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/vrpagent/UAMStayActivity.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.vrpagent; 2 | 3 | import org.matsim.contrib.dvrp.schedule.StayTask; 4 | import org.matsim.contrib.dynagent.FirstLastSimStepDynActivity; 5 | 6 | /** 7 | * An implementation of AbstractDynActivity for UAM DynAgents for the 8 | * UAMStayTask. 9 | * 10 | * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) 11 | */ 12 | public class UAMStayActivity extends FirstLastSimStepDynActivity { 13 | final private StayTask task; 14 | 15 | public UAMStayActivity(StayTask task, String activityType) { 16 | super(activityType); 17 | this.task = task; 18 | } 19 | 20 | @Override 21 | protected boolean isLastStep(double now) { 22 | if (Double.isInfinite(task.getEndTime())) { 23 | return false; 24 | } else { 25 | return task.getEndTime() <= now; 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/data/UAMFleetData.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.data; 2 | 3 | import java.util.Map; 4 | 5 | import org.matsim.api.core.v01.Id; 6 | import org.matsim.contrib.dvrp.fleet.DvrpVehicle; 7 | import org.matsim.contrib.dvrp.fleet.Fleet; 8 | 9 | import com.google.common.collect.ImmutableMap; 10 | 11 | import net.bhl.matsim.uam.infrastructure.UAMVehicle; 12 | 13 | /** 14 | * An implementation of {@link FleetImpl} for a UAM vehicles fleet. 15 | * 16 | * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) 17 | */ 18 | public class UAMFleetData implements Fleet { 19 | private final Map, UAMVehicle> vehicles; 20 | 21 | public UAMFleetData(Map, UAMVehicle> vehicles) { 22 | this.vehicles = vehicles; 23 | } 24 | 25 | @Override 26 | public ImmutableMap, DvrpVehicle> getVehicles() { 27 | return ImmutableMap.copyOf(vehicles); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/router/strategy/UAMStrategy.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.router.strategy; 2 | 3 | import net.bhl.matsim.uam.data.UAMRoute; 4 | 5 | import java.util.Optional; 6 | 7 | import org.matsim.api.core.v01.population.Person; 8 | import org.matsim.facilities.Facility; 9 | 10 | /** 11 | * Defines classes responsible to generate a UAMRoute based on a specific 12 | * criteria (strategy). 13 | * 14 | * @author Aitanm (Aitan Militao), RRothfeld (Raoul Rothfeld) 15 | */ 16 | public interface UAMStrategy { 17 | UAMStrategyType getUAMStrategyType(); 18 | 19 | /** 20 | * @return The UAMRoute for the passenger based on the selected UAMStrategy 21 | */ 22 | Optional getRoute(Person person, Facility fromFacility, Facility toFacility, double departureTime); 23 | 24 | enum UAMStrategyType { 25 | MINTRAVELTIME, MINACCESSTRAVELTIME, MINDISTANCE, MINACCESSDISTANCE, PREDEFINED 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/analysis/uamstations/UAMStationItem.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.analysis.uamstations; 2 | 3 | import net.bhl.matsim.uam.infrastructure.UAMStation; 4 | import org.matsim.api.core.v01.Id; 5 | 6 | /** 7 | * This class stores information about a UAM Station. 8 | * 9 | * @author Aitanm (Aitan Militao), RRothfeld (Raoul Rothfeld) 10 | */ 11 | public class UAMStationItem { 12 | public String name; 13 | public Id id; 14 | public int preflighttime; 15 | public int postflighttime; 16 | public int defaultwaittime; 17 | public String link; 18 | 19 | public UAMStationItem(String name, Id id, int preflighttime, int postflighttime, 20 | int defaultwaittime, String link) { 21 | this.name = name; 22 | this.id = id; 23 | this.preflighttime = preflighttime; 24 | this.postflighttime = postflighttime; 25 | this.defaultwaittime = defaultwaittime; 26 | this.link = link; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/assembly/assembly-release.xml: -------------------------------------------------------------------------------- 1 | 4 | release 5 | true 6 | ${artifactId}-${version} 7 | 8 | 9 | zip 10 | 11 | 12 | 13 | 14 | ${project.build.directory}/${project.build.finalName}.jar 15 | ./ 16 | 17 | 18 | 19 | 20 | 21 | false 22 | /libs/ 23 | false 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/analysis/traveltimes/utils/TripItemReader.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.analysis.traveltimes.utils; 2 | 3 | import org.matsim.api.core.v01.Coord; 4 | import org.matsim.core.utils.misc.Time; 5 | 6 | import net.bhl.matsim.uam.infrastructure.readers.CSVReaders; 7 | 8 | import java.io.IOException; 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | 12 | public class TripItemReader { 13 | public static List getTripItems(String tripsInput) throws IOException { 14 | List trips = new ArrayList<>(); 15 | List rows = CSVReaders.readCSV(tripsInput); 16 | for (String[] row : rows.subList(1, rows.size())) { 17 | int j = 0; 18 | TripItem trip = new TripItem(); 19 | trip.origin = new Coord(Double.parseDouble(row[j++]), Double.parseDouble(row[j++])); 20 | trip.destination = new Coord(Double.parseDouble(row[j++]), Double.parseDouble(row[j++])); 21 | trip.departureTime = Time.parseTime(row[j]); 22 | trips.add(trip); 23 | } 24 | return trips; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/qsim/UAMSpeedModule.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.qsim; 2 | 3 | import com.google.inject.Provides; 4 | import com.google.inject.Singleton; 5 | 6 | import net.bhl.matsim.uam.infrastructure.readers.UAMXMLReader; 7 | 8 | import org.matsim.core.mobsim.qsim.AbstractQSimModule; 9 | import org.matsim.core.mobsim.qsim.qnetsimengine.linkspeedcalculator.LinkSpeedCalculator; 10 | 11 | /** 12 | * A MATSim Abstract Module for classes used by UAM simulation regarding link 13 | * speeds in the simulation. 14 | * 15 | * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) 16 | */ 17 | public class UAMSpeedModule extends AbstractQSimModule { 18 | 19 | @Override 20 | public void configureQSim() { 21 | bind(LinkSpeedCalculator.class).to(UAMLinkSpeedCalculator.class); 22 | } 23 | 24 | @Provides 25 | @Singleton 26 | public UAMLinkSpeedCalculator provideUAMLinkSpeedCalculator(UAMXMLReader uamReader) { 27 | return new UAMLinkSpeedCalculator(uamReader.getMapVehicleVerticalSpeeds(), uamReader.getMapVehicleHorizontalSpeeds()); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/dispatcher/UAMDispatcher.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.dispatcher; 2 | 3 | import net.bhl.matsim.uam.infrastructure.UAMVehicle; 4 | import net.bhl.matsim.uam.passenger.UAMRequest; 5 | 6 | /** 7 | * Interface for the UAM Dispatchers. 8 | * 9 | * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) 10 | */ 11 | public interface UAMDispatcher { 12 | 13 | /** 14 | * @param request UAM Request 15 | *

16 | * Method that manages a new request 17 | */ 18 | void onRequestSubmitted(UAMRequest request); 19 | 20 | /** 21 | * @param vehicle UAM Vehicle 22 | *

23 | * Method that prepares the UAM Vehicle for the next task 24 | */ 25 | void onNextTaskStarted(UAMVehicle vehicle); 26 | 27 | /** 28 | * @param simulationTime Simulation time 29 | *

30 | * Method used for any change to be performed before the 31 | * next simulation step 32 | */ 33 | void onNextTimeStep(double simulationTime); 34 | 35 | } -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/analysis/trips/listeners/TripListenerItem.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.analysis.trips.listeners; 2 | 3 | import net.bhl.matsim.uam.analysis.trips.TripItem; 4 | import org.matsim.api.core.v01.Coord; 5 | import org.matsim.api.core.v01.Id; 6 | import org.matsim.api.core.v01.network.Link; 7 | import org.matsim.api.core.v01.population.Person; 8 | import org.matsim.api.core.v01.population.PlanElement; 9 | 10 | import java.util.LinkedList; 11 | import java.util.List; 12 | 13 | /** 14 | * This class stores information about a trip performed. 15 | * 16 | * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) 17 | */ 18 | public class TripListenerItem extends TripItem { 19 | public List elements = new LinkedList<>(); 20 | public List> route = new LinkedList<>(); 21 | 22 | public TripListenerItem(Id personId, int personTripId, Coord origin, double startTime, 23 | String startPurpose) { 24 | super(personId, personTripId, origin, null, startTime, Double.NaN, Double.NaN, "unknown", startPurpose, 25 | "unknown", false, Double.NaN); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/scenario/RunCreateUAMBeelineScenario.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.scenario; 2 | 3 | /** 4 | * This script creates UAM-including MATSim network and corresponding 5 | * uam-vehicles file, which are prerequisites for running a UAM-enabled MATSim 6 | * simulation with a UAM flight being beeline connections between all stations. 7 | * 8 | * @author RRothfeld (Raoul Rothfeld) 9 | */ 10 | public class RunCreateUAMBeelineScenario { 11 | public static void main(String[] args) { 12 | System.out.println("ARGS: config.xml* uam-stations.csv* uam-link-freespeed* uam-link-capacity* uam-vehicles.csv"); 13 | System.out.println("(* required)"); 14 | 15 | // ARGS 16 | int j = 0; 17 | String configInput = args[j++]; 18 | String stationInput = args[j++]; 19 | double uamMaxLinkSpeed = Double.parseDouble(args[j++]); 20 | double uamLinkCapacity = Double.parseDouble(args[j++]); 21 | String vehicleInput = null; 22 | 23 | if (args.length > j) 24 | vehicleInput = args[j]; 25 | 26 | // Run 27 | RunCreateUAMRoutedScenario.convert(configInput, stationInput, uamMaxLinkSpeed, uamLinkCapacity, vehicleInput); 28 | } 29 | } -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/scoring/UAMScoringFunctionFactory.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.scoring; 2 | 3 | import org.matsim.api.core.v01.Scenario; 4 | import org.matsim.api.core.v01.population.Person; 5 | import org.matsim.core.scoring.ScoringFunction; 6 | import org.matsim.core.scoring.ScoringFunctionFactory; 7 | import org.matsim.core.scoring.SumScoringFunction; 8 | import org.matsim.core.scoring.functions.CharyparNagelScoringFunctionFactory; 9 | 10 | import com.google.inject.Inject; 11 | import com.google.inject.Singleton; 12 | 13 | /** 14 | * Create new scoring functions for UAM mode. 15 | * 16 | * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) 17 | */ 18 | @Singleton 19 | public class UAMScoringFunctionFactory implements ScoringFunctionFactory { 20 | final private ScoringFunctionFactory standardFactory; 21 | 22 | @Inject 23 | public UAMScoringFunctionFactory(Scenario scenario) { 24 | standardFactory = new CharyparNagelScoringFunctionFactory(scenario); 25 | } 26 | 27 | @Override 28 | public ScoringFunction createNewScoringFunction(Person person) { 29 | return (SumScoringFunction) standardFactory.createNewScoringFunction(person); 30 | } 31 | } -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/infrastructure/readers/CSVReaders.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.infrastructure.readers; 2 | 3 | import com.opencsv.CSVParser; 4 | import com.opencsv.CSVParserBuilder; 5 | import com.opencsv.CSVReader; 6 | import com.opencsv.CSVReaderBuilder; 7 | import com.opencsv.exceptions.CsvException; 8 | import org.matsim.core.utils.io.IOUtils; 9 | 10 | import java.io.IOException; 11 | import java.util.List; 12 | 13 | public class CSVReaders { 14 | public static List readTSV(String file) { 15 | return readFile(file, '\t'); 16 | } 17 | 18 | public static List readCSV(String file) { 19 | return readFile(file, CSVParser.DEFAULT_SEPARATOR); 20 | } 21 | 22 | public static List readSemicolonSV(String file) { 23 | return readFile(file, ';'); 24 | } 25 | 26 | public static List readFile(String file, char separator) { 27 | try (CSVReader reader = new CSVReaderBuilder(IOUtils.getBufferedReader(file)) 28 | .withCSVParser(new CSVParserBuilder().withSeparator(separator).build()).build()) { 29 | return reader.readAll(); 30 | } catch (IOException | CsvException e) { 31 | throw new IllegalArgumentException(e); 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/infrastructure/UAMStation.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.infrastructure; 2 | 3 | import org.matsim.api.core.v01.Id; 4 | import org.matsim.api.core.v01.network.Link; 5 | 6 | /** 7 | * An interface to define UAM Stations methods. 8 | * 9 | * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) 10 | */ 11 | public interface UAMStation { 12 | 13 | Id getId(); 14 | 15 | /** 16 | * This method is used to retrieve the time needed by the passenger to get from 17 | * vertiport entry to his/her aircraft seat in seconds. 18 | * 19 | * @return the time needed by the passenger before entering the aircraft 20 | */ 21 | double getPreFlightTime(); 22 | 23 | /** 24 | * This method is used to retrieve the Time needed by the passenger after 25 | * leaving the aircraft to leave the vertiport in seconds. 26 | * 27 | * @return the time needed by the passenger after the flight to start the next 28 | * leg 29 | */ 30 | double getPostFlightTime(); 31 | 32 | /** 33 | * This method is used to retrieve the default waiting time 34 | * 35 | * @return the default waiting time 36 | */ 37 | double getDefaultWaitTime(); 38 | 39 | Link getLocationLink(); 40 | 41 | String getName(); 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/analysis/trips/readers/EventsTripReader.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.analysis.trips.readers; 2 | 3 | import net.bhl.matsim.uam.analysis.trips.TripItem; 4 | import net.bhl.matsim.uam.analysis.trips.listeners.TripListener; 5 | import org.matsim.core.api.experimental.events.EventsManager; 6 | import org.matsim.core.events.EventsUtils; 7 | import org.matsim.core.events.MatsimEventsReader; 8 | 9 | import java.util.Collection; 10 | 11 | /** 12 | * This class is used to retrieve the a collection of {@link TripItem} by using 13 | * a simulation events file as input 14 | * 15 | * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) 16 | */ 17 | public class EventsTripReader { 18 | final private TripListener tripListener; 19 | 20 | public EventsTripReader(TripListener tripListener) { 21 | this.tripListener = tripListener; 22 | } 23 | 24 | /** 25 | * @param eventsPath the events file path 26 | * @return A collection of {@link TripItem}. 27 | */ 28 | public Collection readTrips(String eventsPath) { 29 | EventsManager eventsManager = EventsUtils.createEventsManager(); 30 | eventsManager.addHandler(tripListener); 31 | new MatsimEventsReader(eventsManager).readFile(eventsPath); 32 | return tripListener.getTripItems(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/analysis/uamdemand/readers/EventsUAMReader.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.analysis.uamdemand.readers; 2 | 3 | import net.bhl.matsim.uam.analysis.uamdemand.UAMDemandItem; 4 | import net.bhl.matsim.uam.analysis.uamdemand.listeners.UAMListener; 5 | import org.matsim.core.api.experimental.events.EventsManager; 6 | import org.matsim.core.events.EventsUtils; 7 | import org.matsim.core.events.MatsimEventsReader; 8 | 9 | import java.util.Collection; 10 | 11 | /** 12 | * This class is used to retrieve the a collection of {@link UAMDemandItem} by 13 | * using a simulation events file as input 14 | * 15 | * @author Aitanm (Aitan Militao), RRothfeld (Raoul Rothfeld) 16 | */ 17 | public class EventsUAMReader { 18 | final private UAMListener uamListener; 19 | 20 | public EventsUAMReader(UAMListener uamListener) { 21 | this.uamListener = uamListener; 22 | } 23 | 24 | /** 25 | * @param eventsPath the events file path 26 | * @return A collection of {@link UAMDemandItem}. 27 | */ 28 | public Collection readUAMData(String eventsPath) { 29 | EventsManager eventsManager = EventsUtils.createEventsManager(); 30 | eventsManager.addHandler(uamListener); 31 | new MatsimEventsReader(eventsManager).readFile(eventsPath); 32 | return uamListener.getUAMItems(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/data/UAMRoutes.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.data; 2 | 3 | import org.matsim.api.core.v01.Id; 4 | import org.matsim.api.core.v01.population.Person; 5 | 6 | import java.util.HashMap; 7 | import java.util.Map; 8 | 9 | /** 10 | * Storage class for UAM leg chains (routes) of access mode, origin and destination stations, and egress mode 11 | * 12 | * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) 13 | *

14 | * TODO: Rework, with faster internal workings than massive HashMap. 15 | */ 16 | public class UAMRoutes { 17 | 18 | private static UAMRoutes instance; 19 | private Map routes; 20 | 21 | private UAMRoutes() { 22 | routes = new HashMap<>(); 23 | } 24 | 25 | public static synchronized UAMRoutes getInstance() { 26 | if (instance == null) { 27 | instance = new UAMRoutes(); 28 | } 29 | return instance; 30 | } 31 | 32 | public static String id(Id personId, double time) { 33 | return "" + personId.toString() + "_" + time; 34 | } 35 | 36 | public void add(Id person, double time, UAMRoute route) { 37 | routes.put(id(person, time), route); 38 | } 39 | 40 | public UAMRoute get(Id person, double time) { 41 | return routes.get(id(person, time)); 42 | } 43 | 44 | public boolean contains(Id person, double time) { 45 | return routes.containsKey(id(person, time)); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/data/UAMAccessOptions.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.data; 2 | 3 | import net.bhl.matsim.uam.infrastructure.UAMStation; 4 | 5 | /** 6 | * This class is used to store data from access/egress legs to/from UAMStations. 7 | * 8 | * @author Aitanm (Aitan Militao), RRothfeld (Raoul Rothfeld) 9 | */ 10 | public class UAMAccessOptions { 11 | private double accessDistance; 12 | private double accessTravelTime; 13 | private String accessBestModeDistance; 14 | private String accessBestModeTime; 15 | private UAMStation station; 16 | 17 | public UAMAccessOptions(double accessDistance, double accessTravelTime, String accessModeDistance, 18 | String accessModeTime, UAMStation station) { 19 | this.accessDistance = accessDistance; 20 | this.accessTravelTime = accessTravelTime; 21 | this.accessBestModeDistance = accessModeDistance; 22 | this.accessBestModeTime = accessModeTime; 23 | this.station = station; 24 | } 25 | 26 | public double getShortestAccessDistance() { 27 | return accessDistance; 28 | } 29 | 30 | public double getFastestAccessTime() { 31 | return accessTravelTime; 32 | } 33 | 34 | public String getShortestDistanceMode() { 35 | return accessBestModeDistance; 36 | } 37 | 38 | public String getFastestTimeMode() { 39 | return accessBestModeTime; 40 | } 41 | 42 | public UAMStation getStation() { 43 | return station; 44 | } 45 | 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/analysis/linkspeed/RunUAMLinkSpeedCheckFromEvents.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.analysis.linkspeed; 2 | 3 | import org.matsim.api.core.v01.network.Network; 4 | import org.matsim.core.api.experimental.events.EventsManager; 5 | import org.matsim.core.events.EventsReaderXMLv1; 6 | import org.matsim.core.events.EventsUtils; 7 | import org.matsim.core.network.NetworkUtils; 8 | import org.matsim.core.network.io.MatsimNetworkReader; 9 | 10 | import java.io.FileWriter; 11 | import java.io.IOException; 12 | 13 | public class RunUAMLinkSpeedCheckFromEvents { 14 | // PROVIDE: NETWORK EVENTS OUTFILE-NAME-CSV 15 | public static void main(String[] args) { 16 | EventsManager manager = EventsUtils.createEventsManager(); 17 | 18 | Network network = NetworkUtils.createNetwork(); 19 | MatsimNetworkReader reader = new MatsimNetworkReader(network); 20 | reader.readFile(args[0]); 21 | 22 | try { 23 | FileWriter fw = new FileWriter(args[2]); 24 | manager.addHandler(new UAMLinkTravelSpeedHandler(network, fw)); 25 | 26 | EventsReaderXMLv1 eventsReader = new EventsReaderXMLv1(manager); 27 | eventsReader.readFile(args[1]); 28 | 29 | fw.close(); 30 | } catch (IOException e) { 31 | e.printStackTrace(); 32 | } 33 | 34 | System.out.println("done."); 35 | 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/test/resources/corsica/uam_network.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 14 | 23 | 24 | 25 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/schedule/UAMTransitEvent.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.schedule; 2 | 3 | import net.bhl.matsim.uam.passenger.UAMRequest; 4 | import net.bhl.matsim.uam.vrpagent.UAMActionCreator; 5 | import org.matsim.api.core.v01.Id; 6 | import org.matsim.api.core.v01.events.Event; 7 | import org.matsim.api.core.v01.events.HasPersonId; 8 | import org.matsim.api.core.v01.population.Person; 9 | 10 | import java.util.Map; 11 | 12 | /** 13 | * Event that is generated when the drop off occurs, in order to know which 14 | * person was dropped off. 15 | * 16 | * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) 17 | */ 18 | public class UAMTransitEvent extends Event implements HasPersonId { 19 | final private UAMRequest request; 20 | 21 | public UAMTransitEvent(UAMRequest request, double time) { 22 | super(time); 23 | this.request = request; 24 | } 25 | 26 | public UAMRequest getRequest() { 27 | return request; 28 | } 29 | 30 | @Override 31 | public String getEventType() { 32 | return UAMActionCreator.TRANSIT_ACTIVITY_TYPE; 33 | } 34 | 35 | @Override 36 | public Map getAttributes() { 37 | Map attr = super.getAttributes(); 38 | attr.put("person", request.getPassengerIds().toString()); 39 | return attr; 40 | } 41 | 42 | @Override 43 | public Id getPersonId() { 44 | //TODO: currently only returning one person, should be corrected int eh future milos '24' 45 | return request.getPassengerIds().get(0); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/analysis/RunBatchConversions.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.analysis; 2 | 3 | import java.io.IOException; 4 | 5 | import net.bhl.matsim.uam.analysis.traffic.run.BatchConvertLinkStatsFromEvents; 6 | import net.bhl.matsim.uam.analysis.trips.run.BatchConvertTripsFromEvents; 7 | import net.bhl.matsim.uam.analysis.trips.run.BatchConvertTripsFromPopulation; 8 | import net.bhl.matsim.uam.analysis.uamdemand.run.BatchConvertUAMDemandFromEvents; 9 | import net.bhl.matsim.uam.analysis.uamstations.run.BatchConvertUAMStationsFromUAMVehicles; 10 | 11 | /** 12 | * This script takes a specific folder path and runs 13 | * {@link BatchConvertUAMStationsFromUAMVehicles}, 14 | * {@link BatchConvertUAMDemandFromEvents}, {@link BatchConvertTripsFromEvents}, 15 | * {@link BatchConvertTransitTripsFromEvents}, 16 | * {@link BatchConvertTripsFromPopulation} and 17 | * {@link BatchConvertLinkStatsFromEvents} consecutively for all MATSim output 18 | * folders within the provided base folder. 19 | * 20 | * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) 21 | */ 22 | public class RunBatchConversions { 23 | 24 | public static void main(String[] args) throws IOException { 25 | // PROVIDE PARENT FOLDER OF OUTPUT FOLDERS 26 | BatchConvertUAMStationsFromUAMVehicles.main(args); 27 | BatchConvertUAMDemandFromEvents.main(args); 28 | BatchConvertTripsFromEvents.main(args); 29 | BatchConvertTripsFromPopulation.main(args); 30 | BatchConvertLinkStatsFromEvents.main(args); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/schedule/UAMDropoffTask.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.schedule; 2 | 3 | import java.util.Collection; 4 | import java.util.HashSet; 5 | import java.util.Set; 6 | 7 | import org.matsim.api.core.v01.network.Link; 8 | import org.matsim.contrib.dvrp.schedule.DefaultStayTask; 9 | 10 | import net.bhl.matsim.uam.passenger.UAMRequest; 11 | 12 | /** 13 | * This task represents the local drop-off of passenger at stations, it doesn't 14 | * include the flying period. 15 | * 16 | * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) 17 | */ 18 | public class UAMDropoffTask extends DefaultStayTask { 19 | private final Set requests = new HashSet<>(); 20 | private final double deboardingTime; 21 | 22 | public UAMDropoffTask(double beginTime, double endTime, Link link, double deboardingTime) { 23 | super(UAMTaskType.DROPOFF, beginTime, endTime, link); 24 | this.deboardingTime = deboardingTime; 25 | } 26 | 27 | public UAMDropoffTask(double beginTime, double endTime, Link link, double deboardingTime, 28 | Collection requests) { 29 | this(beginTime, endTime, link, deboardingTime); 30 | 31 | this.requests.addAll(requests); 32 | for (UAMRequest request : requests) 33 | request.setDropoffTask(this); 34 | } 35 | 36 | public Set getRequests() { 37 | return this.requests; 38 | } 39 | 40 | public void addRequest(UAMRequest request) { 41 | this.requests.add(request); 42 | } 43 | 44 | public double getDeboardingTime() { 45 | return deboardingTime; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/analysis/trips/TripItem.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.analysis.trips; 2 | 3 | import org.matsim.api.core.v01.Coord; 4 | import org.matsim.api.core.v01.Id; 5 | import org.matsim.api.core.v01.population.Person; 6 | 7 | /** 8 | * This class stores information about a trip. 9 | * 10 | * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) 11 | */ 12 | public class TripItem { 13 | public Id personId; 14 | public int personTripId; 15 | public Coord origin; 16 | public Coord destination; 17 | public double startTime; 18 | public double travelTime; 19 | public double networkDistance; 20 | public String mode; 21 | public String followingPurpose; 22 | public String preceedingPurpose; 23 | public boolean returning; 24 | public double crowflyDistance; 25 | 26 | public TripItem(Id personId, int personTripId, Coord origin, Coord destination, double startTime, 27 | double travelTime, double networkDistance, String mode, String preceedingPurpose, String followingPurpose, 28 | boolean returning, double crowflyDistance) { 29 | this.personId = personId; 30 | this.personTripId = personTripId; 31 | this.origin = origin; 32 | this.destination = destination; 33 | this.startTime = startTime; 34 | this.travelTime = travelTime; 35 | this.networkDistance = networkDistance; 36 | this.mode = mode; 37 | this.followingPurpose = followingPurpose; 38 | this.preceedingPurpose = preceedingPurpose; 39 | this.returning = returning; 40 | this.crowflyDistance = crowflyDistance; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/passenger/UAMChargingActivity.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.passenger; 2 | 3 | import org.matsim.contrib.dynagent.DynActivity; 4 | 5 | import net.bhl.matsim.uam.dispatcher.UAMManager; 6 | import net.bhl.matsim.uam.infrastructure.UAMVehicle; 7 | import net.bhl.matsim.uam.schedule.UAMChargingTask; 8 | 9 | public class UAMChargingActivity implements DynActivity { 10 | 11 | public static final String ACTIVITY_TYPE = "Charging"; 12 | private UAMChargingTask chargingTask; 13 | private UAMVehicle uamVehicle; 14 | private UAMManager uamManager; 15 | 16 | private double endTime = END_ACTIVITY_LATER; 17 | 18 | public UAMChargingActivity(UAMChargingTask chargingTask, UAMVehicle uamVehicle, UAMManager uamManager) { 19 | this.chargingTask = chargingTask; 20 | this.uamVehicle = uamVehicle; 21 | this.uamManager = uamManager; 22 | } 23 | 24 | @Override 25 | public String getActivityType() { 26 | return ACTIVITY_TYPE; 27 | } 28 | 29 | @Override 30 | public void doSimStep(double now) { 31 | // check if not charging then increase end time 32 | // if () 33 | // check if charged then adjust end time 34 | if (this.uamManager.getChargeVehicle().get(uamVehicle.getId()) < uamVehicle.getVehicleType().getMaximumCharge()) { 35 | if (this.endTime == now) 36 | this.endTime++; 37 | } 38 | else { 39 | this.endTime = now; 40 | //this means we can unplug the vehicle and move to the StayTask 41 | //make a charger available for the next vehicle 42 | } 43 | } 44 | 45 | @Override 46 | public double getEndTime() { 47 | return endTime; 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/router/UAMMainModeIdentifier.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.router; 2 | 3 | import net.bhl.matsim.uam.run.UAMConstants; 4 | import org.matsim.api.core.v01.TransportMode; 5 | import org.matsim.api.core.v01.population.Leg; 6 | import org.matsim.api.core.v01.population.PlanElement; 7 | import org.matsim.core.router.MainModeIdentifier; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * This class identifies if a trip is using UAM or not. 13 | * 14 | * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) 15 | */ 16 | public class UAMMainModeIdentifier implements MainModeIdentifier { 17 | private final MainModeIdentifier defaultModeIdentifier; 18 | 19 | public UAMMainModeIdentifier(final MainModeIdentifier defaultModeIdentifier) { 20 | this.defaultModeIdentifier = defaultModeIdentifier; 21 | } 22 | 23 | @Override 24 | public String identifyMainMode(List tripElements) { 25 | for (PlanElement pe : tripElements) { 26 | if (pe instanceof Leg && (((Leg) pe).getMode().equals(UAMConstants.uam) 27 | || ((Leg) pe).getMode().equals(UAMConstants.access + TransportMode.walk) 28 | || ((Leg) pe).getMode().equals(UAMConstants.egress + TransportMode.walk) 29 | || ((Leg) pe).getMode().equals(UAMConstants.access + TransportMode.bike) 30 | || ((Leg) pe).getMode().equals(UAMConstants.egress + TransportMode.bike))) { 31 | return UAMConstants.uam; 32 | } 33 | } 34 | // if the trip doesn't contain a uam leg, 35 | // fall back to the default identification method. 36 | return defaultModeIdentifier.identifyMainMode(tripElements); 37 | } 38 | } -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/schedule/UAMPickupTask.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.schedule; 2 | 3 | import java.util.Collection; 4 | import java.util.HashSet; 5 | import java.util.Set; 6 | 7 | import org.matsim.api.core.v01.network.Link; 8 | import org.matsim.contrib.dvrp.passenger.PassengerRequest; 9 | import org.matsim.contrib.dvrp.schedule.DefaultStayTask; 10 | 11 | import net.bhl.matsim.uam.passenger.UAMRequest; 12 | 13 | /** 14 | * This task represents the local pick up of passenger at stations, it doesn't 15 | * include the flying period. 16 | * 17 | * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) 18 | */ 19 | public class UAMPickupTask extends DefaultStayTask { 20 | private final Set requests = new HashSet<>(); 21 | private final double boardingTime; 22 | 23 | public UAMPickupTask(double beginTime, double endTime, Link link, double boardingTime) { 24 | super(UAMTaskType.PICKUP, beginTime, endTime, link); 25 | this.boardingTime = boardingTime; 26 | } 27 | 28 | public UAMPickupTask(double beginTime, double endTime, Link link, double boardingTime, 29 | Collection requests) { 30 | this(beginTime, endTime, link, boardingTime); 31 | 32 | this.requests.addAll(requests); 33 | for (UAMRequest request : requests) 34 | request.setPickupTask(this); 35 | } 36 | 37 | public Set getRequests() { 38 | return this.requests; 39 | } 40 | 41 | @Deprecated 42 | public void addRequest(UAMRequest request) { 43 | requests.add(request); 44 | request.setPickupTask(this); 45 | 46 | } 47 | 48 | public double getBoardingTime() { 49 | return boardingTime; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/scenario/network/RunAddModeToNetwork.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.scenario.network; 2 | 3 | import org.matsim.api.core.v01.Scenario; 4 | import org.matsim.api.core.v01.TransportMode; 5 | import org.matsim.api.core.v01.network.Link; 6 | import org.matsim.api.core.v01.network.Network; 7 | import org.matsim.api.core.v01.network.NetworkWriter; 8 | import org.matsim.core.config.Config; 9 | import org.matsim.core.config.ConfigUtils; 10 | import org.matsim.core.scenario.ScenarioUtils; 11 | 12 | import java.util.HashSet; 13 | import java.util.Set; 14 | 15 | // Adjusted from RunCreateNetworkSHP.java by matsim-code-examples 16 | 17 | /** 18 | * This script adds specified mode(s) to an existing network if other specified 19 | * mode(s) is (are) present. 20 | * 21 | * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) 22 | */ 23 | @Deprecated 24 | public class RunAddModeToNetwork { 25 | 26 | private static final String searchMode = TransportMode.car; 27 | private static final String addedMode = TransportMode.car + "_passenger"; 28 | 29 | public static void main(String[] args) throws Exception { 30 | Config config = ConfigUtils.createConfig(); 31 | config.network().setInputFile(args[0]); 32 | Scenario scenario = ScenarioUtils.loadScenario(config); 33 | Network network = scenario.getNetwork(); 34 | 35 | for (Link l : network.getLinks().values()) { 36 | Set modes = new HashSet<>(l.getAllowedModes()); 37 | if (modes.contains(searchMode)) { 38 | modes.add(addedMode); 39 | l.setAllowedModes(modes); 40 | } 41 | } 42 | 43 | new NetworkWriter(network).write(args[0]); 44 | System.out.println("done."); 45 | } 46 | } -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/charging/DischargingHandler.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.charging; 2 | 3 | import org.matsim.api.core.v01.Id; 4 | import org.matsim.api.core.v01.Scenario; 5 | import org.matsim.api.core.v01.events.LinkLeaveEvent; 6 | import org.matsim.api.core.v01.events.handler.LinkLeaveEventHandler; 7 | import org.matsim.api.core.v01.network.Link; 8 | import org.matsim.contrib.dvrp.fleet.DvrpVehicle; 9 | 10 | import com.google.inject.Inject; 11 | 12 | import net.bhl.matsim.uam.dispatcher.UAMManager; 13 | import net.bhl.matsim.uam.infrastructure.UAMVehicle; 14 | 15 | public class DischargingHandler implements LinkLeaveEventHandler { 16 | 17 | private UAMManager uamManager; 18 | private Scenario scenario; 19 | 20 | @Inject 21 | public DischargingHandler(UAMManager uamManager, Scenario scenario) { 22 | this.uamManager = uamManager; 23 | this.scenario = scenario; 24 | } 25 | 26 | @Override 27 | public void handleEvent(LinkLeaveEvent event) { 28 | 29 | if (event.getVehicleId().toString().contains("uam")) { 30 | UAMVehicle uamVehicle = this.uamManager.getVehicles() 31 | .get(Id.create(event.getVehicleId().toString(), DvrpVehicle.class)); 32 | 33 | Link link = this.scenario.getNetwork().getLinks().get(event.getLinkId()); 34 | double dischargedAmount = link.getAttributes().getAttribute("type").equals("uam_vertical") 35 | ? uamVehicle.getVehicleType().getEnergyConsumptionVertical() * link.getLength() 36 | : uamVehicle.getVehicleType().getEnergyConsumptionHorizontal() * link.getLength(); 37 | this.uamManager.getChargeVehicle().put(uamVehicle.getId(), 38 | this.uamManager.getChargeVehicle().get(uamVehicle.getId()) - dischargedAmount); 39 | 40 | } 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/data/WaitingStationData.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.data; 2 | 3 | import com.google.inject.Inject; 4 | import net.bhl.matsim.uam.dispatcher.UAMManager; 5 | import net.bhl.matsim.uam.infrastructure.UAMStation; 6 | import org.matsim.api.core.v01.Id; 7 | import org.matsim.core.config.Config; 8 | import org.matsim.core.controler.events.BeforeMobsimEvent; 9 | import org.matsim.core.controler.listener.BeforeMobsimListener; 10 | 11 | import java.util.HashMap; 12 | import java.util.Map; 13 | 14 | /** 15 | * Class that stores waiting data of stations. 16 | * 17 | * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) 18 | */ 19 | public class WaitingStationData implements BeforeMobsimListener { 20 | 21 | Map, WaitingData> waitingData = new HashMap<>(); 22 | 23 | @Inject 24 | private UAMManager uamManager; 25 | 26 | @Inject 27 | private Config config; 28 | 29 | public Map, WaitingData> getWaitingData() { 30 | return waitingData; 31 | } 32 | 33 | public WaitingData getWaitingDataForStation(Id stationId) { 34 | return this.waitingData.get(stationId); 35 | } 36 | 37 | @Override 38 | public void notifyBeforeMobsim(BeforeMobsimEvent event) { 39 | waitingData.clear(); 40 | 41 | int simulationEndTime = Integer.parseInt(config.getModules().get("qsim").getParams().get("endTime").substring(0,2)); 42 | double waitingTimeBinSize = Double.parseDouble(config.getModules().get("travelTimeCalculator").getParams().get("travelTimeBinSize")); 43 | for (UAMStation station : uamManager.getStations().getUAMStations().values()) 44 | waitingData.put(station.getId(), new WaitingData(simulationEndTime * 3600, 45 | waitingTimeBinSize, station.getDefaultWaitTime())); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/passenger/UAMRequestCreator.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.passenger; 2 | 3 | import java.util.List; 4 | 5 | import org.matsim.api.core.v01.Id; 6 | import org.matsim.api.core.v01.network.Link; 7 | import org.matsim.api.core.v01.population.Person; 8 | import org.matsim.api.core.v01.population.Route; 9 | import org.matsim.contrib.dvrp.optimizer.Request; 10 | import org.matsim.contrib.dvrp.passenger.PassengerRequest; 11 | import org.matsim.contrib.dvrp.passenger.PassengerRequestCreator; 12 | 13 | import com.google.inject.Inject; 14 | 15 | import net.bhl.matsim.uam.data.UAMStationConnectionGraph; 16 | import net.bhl.matsim.uam.dispatcher.UAMDispatcher; 17 | import net.bhl.matsim.uam.dispatcher.UAMManager; 18 | 19 | /** 20 | * This class creates a UAM request. 21 | * 22 | * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) 23 | */ 24 | public class UAMRequestCreator implements PassengerRequestCreator { 25 | 26 | @Inject 27 | List dispatchers; 28 | 29 | @Inject 30 | private UAMStationConnectionGraph stationConnectionutilities; 31 | 32 | @Inject 33 | private UAMManager uamManager; 34 | 35 | @Override 36 | public PassengerRequest createRequest(Id id, List> passengerIds, Route route, Link fromLink, 37 | Link toLink, double departureTime, double submissionTime) { 38 | // We currently have only one dispatcher, this might change in the future 39 | double distance = stationConnectionutilities.getFlightLeg( 40 | uamManager.getStations().getNearestUAMStation(fromLink).getId(), 41 | uamManager.getStations().getNearestUAMStation(toLink).getId()).distance; 42 | return new UAMRequest(id, passengerIds, fromLink, toLink, departureTime, submissionTime, dispatchers.get(0), 43 | distance); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/analysis/trips/run/BatchConvertTripsFromEvents.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.analysis.trips.run; 2 | 3 | import org.apache.commons.io.FileUtils; 4 | 5 | import java.io.File; 6 | import java.io.IOException; 7 | import java.nio.file.Paths; 8 | import java.util.Collection; 9 | import java.util.HashSet; 10 | 11 | /** 12 | * This script takes a specific folder path and runs 13 | * {@link ConvertTripsFromEvents} for all MATSim output folders within the 14 | * provided base folder. 15 | * 16 | * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) 17 | */ 18 | public class BatchConvertTripsFromEvents { 19 | // PROVIDE PARENT FOLDER OF OUTPUT FOLDERS 20 | private static String eventfile = "output_events.xml"; 21 | private static String networkfile = "output_network.xml"; 22 | 23 | public static void main(final String[] args) throws IOException { 24 | File folder = Paths.get(args[0]).toFile(); 25 | 26 | String[] ext = {"gz", "xml"}; 27 | Collection potentialFiles = FileUtils.listFiles(folder, ext, true); 28 | 29 | String[] ecl = {"csv"}; 30 | Collection alreadyExistingFiles = FileUtils.listFiles(folder, ecl, true); 31 | Collection alreadyExistingFileNames = new HashSet<>(); 32 | for (File f : alreadyExistingFiles) { 33 | alreadyExistingFileNames.add(f.getAbsolutePath()); 34 | } 35 | 36 | for (File f : potentialFiles) { 37 | if (!f.getName().contains(eventfile) || alreadyExistingFileNames.contains(f.getAbsolutePath() + ".csv")) 38 | continue; 39 | 40 | System.err.println("Working on: " + f.getAbsolutePath()); 41 | String network = f.getAbsolutePath().replace(eventfile, networkfile); 42 | ConvertTripsFromEvents.extract(network, f.getAbsolutePath(), f.getAbsolutePath() + ".csv"); 43 | } 44 | 45 | System.err.println("done."); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/analysis/trips/run/BatchConvertTripsFromPopulation.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.analysis.trips.run; 2 | 3 | import org.apache.commons.io.FileUtils; 4 | 5 | import java.io.File; 6 | import java.io.IOException; 7 | import java.nio.file.Paths; 8 | import java.util.Collection; 9 | import java.util.HashSet; 10 | 11 | /** 12 | * This script takes a specific folder path and runs 13 | * {@link ConvertTripsFromPopulation} for all MATSim output folders within the 14 | * provided base folder. 15 | * 16 | * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) 17 | */ 18 | public class BatchConvertTripsFromPopulation { 19 | // PROVIDE PARENT FOLDER OF OUTPUT FOLDERS 20 | private static String eventfile = "output_plans.xml"; 21 | private static String networkfile = "output_network.xml"; 22 | 23 | public static void main(final String[] args) throws IOException { 24 | File folder = Paths.get(args[0]).toFile(); 25 | 26 | String[] ext = {"gz", "xml"}; 27 | Collection potentialFiles = FileUtils.listFiles(folder, ext, true); 28 | 29 | String[] ecl = {"csv"}; 30 | Collection alreadyExistingFiles = FileUtils.listFiles(folder, ecl, true); 31 | Collection alreadyExistingFileNames = new HashSet<>(); 32 | for (File f : alreadyExistingFiles) { 33 | alreadyExistingFileNames.add(f.getAbsolutePath()); 34 | } 35 | 36 | for (File f : potentialFiles) { 37 | if (!f.getName().contains(eventfile) || alreadyExistingFileNames.contains(f.getAbsolutePath() + ".csv")) 38 | continue; 39 | 40 | System.err.println("Working on: " + f.getAbsolutePath()); 41 | String network = f.getAbsolutePath().replace(eventfile, networkfile); 42 | ConvertTripsFromPopulation.extract(network, f.getAbsolutePath(), f.getAbsolutePath() + ".csv"); 43 | } 44 | 45 | System.err.println("done."); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/qsim/UAMLinkSpeedCalculator.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.qsim; 2 | 3 | import net.bhl.matsim.uam.router.UAMFlightSegments; 4 | import org.matsim.api.core.v01.network.Link; 5 | import org.matsim.core.mobsim.qsim.qnetsimengine.QVehicle; 6 | import org.matsim.core.mobsim.qsim.qnetsimengine.linkspeedcalculator.LinkSpeedCalculator; 7 | 8 | import java.util.Map; 9 | 10 | /** 11 | * This class defines the LinkSpeedCalculator for UAM simulation. 12 | * 13 | * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) 14 | */ 15 | public class UAMLinkSpeedCalculator implements LinkSpeedCalculator { 16 | 17 | final private Map mapVehicleVerticalSpeeds; 18 | final private Map mapVehicleHorizontalSpeeds; 19 | 20 | public UAMLinkSpeedCalculator(Map mapVehicleVerticalSpeeds, 21 | Map mapVehicleHorizontalSpeeds ) { 22 | // TODO: Use mapping of vehicle types instead of vehicles themselves. 23 | this.mapVehicleVerticalSpeeds = mapVehicleVerticalSpeeds; 24 | this.mapVehicleHorizontalSpeeds = mapVehicleHorizontalSpeeds; 25 | } 26 | 27 | @Override 28 | public double getMaximumVelocity(QVehicle vehicle, Link link, double time) { 29 | try { 30 | String flightSegment = (String) link.getAttributes().getAttribute(UAMFlightSegments.ATTRIBUTE); 31 | 32 | if (flightSegment.equals(UAMFlightSegments.HORIZONTAL)) 33 | return Math.min(link.getFreespeed(), this.mapVehicleHorizontalSpeeds.get(vehicle.getId().toString())); 34 | 35 | if (flightSegment.equals(UAMFlightSegments.VERTICAL)) 36 | return Math.min(link.getFreespeed(), this.mapVehicleVerticalSpeeds.get(vehicle.getId().toString())); 37 | } catch (NullPointerException e) { 38 | // Non-flight link 39 | } 40 | 41 | return Math.min( vehicle.getMaximumVelocity(), link.getFreespeed( time ) ); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/data/WaitingData.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.data; 2 | 3 | /** 4 | * Class that store waiting times of a UAM station. 5 | * 6 | * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) 7 | */ 8 | public class WaitingData { 9 | private final double[] cumWaitingTimes; 10 | private final int[] count; 11 | 12 | private final double simulationEndTime; 13 | private final double waitingTimeBinSize; 14 | private final double defaultWaitTime; 15 | 16 | public WaitingData(double simulationEndTime, double waitingTimeBinSize, double defaultWaitTime) { 17 | this.simulationEndTime = simulationEndTime; 18 | this.waitingTimeBinSize = waitingTimeBinSize; 19 | this.defaultWaitTime = defaultWaitTime; 20 | 21 | int bins = (int) Math.ceil(simulationEndTime / waitingTimeBinSize); 22 | this.cumWaitingTimes = new double[bins]; 23 | this.count = new int[bins]; 24 | } 25 | 26 | public void addWaitingTime(double waitingTime, double arrivalTime) { 27 | if (arrivalTime < simulationEndTime) { 28 | cumWaitingTimes[getIndex(arrivalTime)] += waitingTime; 29 | count[getIndex(arrivalTime)]++; 30 | } 31 | } 32 | 33 | public double getWaitingTime(double departureTime) { 34 | int i = getIndex(departureTime); 35 | if (count[i] != 0) 36 | return cumWaitingTimes[i] / count[i]; 37 | else 38 | return defaultWaitTime; 39 | } 40 | 41 | private int getIndex(double time) { 42 | return (int) Math.floor(time / waitingTimeBinSize); 43 | } 44 | 45 | public String toCsv() { 46 | StringBuilder sb = new StringBuilder("bin,count,waitingTimeSum,waitingTimeAvg\n"); 47 | for (int i = 0; i < cumWaitingTimes.length; i++) 48 | sb.append(i).append(",").append(count[i]).append(",").append(cumWaitingTimes[i]).append(",") 49 | .append(count[i] == 0 ? defaultWaitTime : cumWaitingTimes[i] / count[i]).append("\n"); 50 | return sb.toString(); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/analysis/traffic/run/BatchConvertLinkStatsFromEvents.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.analysis.traffic.run; 2 | 3 | import org.apache.commons.io.FileUtils; 4 | 5 | import java.io.File; 6 | import java.io.IOException; 7 | import java.nio.file.Paths; 8 | import java.util.Collection; 9 | import java.util.HashSet; 10 | 11 | /** 12 | * This script takes a specific folder path and runs 13 | * {@link ConvertLinkStatsFromEvents} for all all MATSim output folders within 14 | * the provided base folder. 15 | * 16 | * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) 17 | */ 18 | public class BatchConvertLinkStatsFromEvents { 19 | // PROVIDE PARENT FOLDER OF OUTPUT FOLDERS 20 | private static String eventfile = "output_events.xml"; 21 | private static String networkfile = "output_network.xml"; 22 | 23 | private static String fileending = ".linkstats.csv"; 24 | 25 | public static void main(final String[] args) throws IOException { 26 | File folder = Paths.get(args[0]).toFile(); 27 | 28 | String[] ext = {"gz", "xml"}; 29 | Collection potentialFiles = FileUtils.listFiles(folder, ext, true); 30 | 31 | String[] ecl = {"csv"}; 32 | Collection alreadyExistingFiles = FileUtils.listFiles(folder, ecl, true); 33 | Collection alreadyExistingFileNames = new HashSet<>(); 34 | for (File f : alreadyExistingFiles) { 35 | alreadyExistingFileNames.add(f.getAbsolutePath()); 36 | } 37 | 38 | for (File f : potentialFiles) { 39 | if (!f.getName().contains(eventfile) || alreadyExistingFileNames.contains(f.getAbsolutePath() + fileending)) 40 | continue; 41 | 42 | System.err.println("Working on: " + f.getAbsolutePath()); 43 | String network = f.getAbsolutePath().replace(eventfile, networkfile); 44 | ConvertLinkStatsFromEvents.extract(network, f.getAbsolutePath(), f.getAbsolutePath() + fileending); 45 | } 46 | 47 | System.err.println("done."); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/events/UAMUtilitiesAccessEgress.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.events; 2 | 3 | import net.bhl.matsim.uam.infrastructure.UAMStation; 4 | import org.matsim.api.core.v01.Id; 5 | import org.matsim.api.core.v01.network.Link; 6 | import org.matsim.api.core.v01.population.Person; 7 | 8 | /** 9 | * A class that stores information about an access or egress leg to a UAM 10 | * station. 11 | * 12 | * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) 13 | */ 14 | @Deprecated 15 | public class UAMUtilitiesAccessEgress { 16 | private Id person; 17 | private Id station; 18 | private Id link; 19 | private boolean access; 20 | private double utility; 21 | private String mode; 22 | private double time; 23 | 24 | private final String header = "person,station,link,access,utility,mode,time"; 25 | 26 | public UAMUtilitiesAccessEgress(Id person, Id station, Id link, boolean access, 27 | double utility, String mode, double time) { 28 | this.person = person; 29 | this.station = station; 30 | this.link = link; 31 | this.access = access; 32 | this.utility = utility; 33 | this.mode = mode; 34 | this.time = time; 35 | } 36 | 37 | @Override 38 | public boolean equals(Object o) { 39 | if (o == this) { 40 | return true; 41 | } 42 | if (!(o instanceof UAMUtilitiesAccessEgress)) { 43 | return false; 44 | } 45 | UAMUtilitiesAccessEgress other = (UAMUtilitiesAccessEgress) o; 46 | return this.toString().equals(other.toString()); 47 | } 48 | 49 | @Override 50 | public int hashCode() { 51 | return this.toString().hashCode(); 52 | } 53 | 54 | public String getHeader() { 55 | return header; 56 | } 57 | 58 | public String toString() { 59 | String access = this.access ? "access" : "egress"; 60 | return "" + person + "," + station + "," + link + "," + access + "," + utility + "," + mode + "," + time; 61 | } 62 | } -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/analysis/uamstations/run/BatchConvertUAMStationsFromUAMVehicles.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.analysis.uamstations.run; 2 | 3 | import org.apache.commons.io.FileUtils; 4 | 5 | import java.io.File; 6 | import java.io.IOException; 7 | import java.nio.file.Paths; 8 | import java.util.Collection; 9 | import java.util.HashSet; 10 | 11 | /** 12 | * This script takes a specific folder path and runs 13 | * {@link ConvertUAMStationsFromUAMVehicles} for all MATSim output folders 14 | * within the provided base folder. 15 | * 16 | * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) 17 | */ 18 | public class BatchConvertUAMStationsFromUAMVehicles { 19 | // PROVIDE PARENT FOLDER OF OUTPUT FOLDERS 20 | private static String vehiclefile = "output_uam_vehicles.xml"; 21 | private static String networkfile = "output_network.xml"; 22 | 23 | public static void main(final String[] args) throws IOException { 24 | File folder = Paths.get(args[0]).toFile(); 25 | 26 | String[] ext = {"gz", "xml"}; 27 | Collection potentialFiles = FileUtils.listFiles(folder, ext, true); 28 | 29 | String[] ecl = {"csv"}; 30 | Collection alreadyExistingFiles = FileUtils.listFiles(folder, ecl, true); 31 | Collection alreadyExistingFileNames = new HashSet<>(); 32 | for (File f : alreadyExistingFiles) { 33 | alreadyExistingFileNames.add(f.getAbsolutePath()); 34 | } 35 | 36 | for (File f : potentialFiles) { 37 | if (!f.getName().contains(vehiclefile) 38 | || alreadyExistingFileNames.contains(f.getAbsolutePath() + "_stations.csv")) 39 | continue; 40 | 41 | System.err.println("Working on: " + f.getAbsolutePath()); 42 | String network = f.getAbsolutePath().replace(vehiclefile, networkfile); 43 | ConvertUAMStationsFromUAMVehicles.extract(network, f.getAbsolutePath(), 44 | f.getAbsolutePath() + "_stations.csv"); 45 | } 46 | 47 | System.err.println("done."); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/infrastructure/UAMStationSimple.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.infrastructure; 2 | 3 | import org.matsim.api.core.v01.Id; 4 | import org.matsim.api.core.v01.network.Link; 5 | 6 | /** 7 | * This class defines the UAM Station and its properties. 8 | * 9 | * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) 10 | */ 11 | public class UAMStationSimple implements UAMStation { 12 | 13 | // UAM infrastructure-specific properties 14 | private final Link locationLink; 15 | private final Id id; 16 | private final String name; 17 | // parameters added 18 | private final double preFlightTime; 19 | private final double postFlightTime; 20 | private final double defaultWaitTime; 21 | 22 | public UAMStationSimple(double preFlightTime, double postFlightTime, 23 | double defaultWaitTime, Link locationLink, Id id) { 24 | this(preFlightTime, postFlightTime, defaultWaitTime, locationLink, id, 25 | id.toString()); 26 | } 27 | 28 | public UAMStationSimple(double preFlightTime, double postFlightTime, 29 | double defaultWaitTime, Link locationLink, Id id, String name) { 30 | this.locationLink = locationLink; 31 | this.id = id; 32 | this.name = name; 33 | this.preFlightTime = preFlightTime; 34 | this.postFlightTime = postFlightTime; 35 | this.defaultWaitTime = defaultWaitTime; 36 | } 37 | 38 | @Override 39 | public String getName() { 40 | return name; 41 | } 42 | 43 | @Override 44 | public Link getLocationLink() { 45 | return locationLink; 46 | } 47 | 48 | @Override 49 | public Id getId() { 50 | return id; 51 | } 52 | 53 | @Override 54 | public double getPreFlightTime() { 55 | return preFlightTime; 56 | } 57 | 58 | @Override 59 | public double getPostFlightTime() { 60 | return postFlightTime; 61 | } 62 | 63 | @Override 64 | public double getDefaultWaitTime() { 65 | return defaultWaitTime; 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/scenario/population/RunFilterPopulation.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.scenario.population; 2 | 3 | import org.matsim.api.core.v01.Scenario; 4 | import org.matsim.api.core.v01.population.Person; 5 | import org.matsim.api.core.v01.population.Population; 6 | import org.matsim.api.core.v01.population.PopulationWriter; 7 | import org.matsim.core.config.Config; 8 | import org.matsim.core.config.ConfigUtils; 9 | import org.matsim.core.population.io.PopulationReader; 10 | import org.matsim.core.scenario.ScenarioUtils; 11 | 12 | import java.util.Set; 13 | 14 | @Deprecated 15 | public class RunFilterPopulation { 16 | public static void main(final String[] args) { 17 | RunFilterPopulation app = new RunFilterPopulation(); 18 | app.run(args); 19 | } 20 | 21 | void run(final String[] args) { 22 | String inputPopFilename = args[0]; 23 | String outputPopFilename = args[1]; 24 | 25 | Scenario scenario = ScenarioUtils.createScenario(ConfigUtils.createConfig()); 26 | ScenarioUtils.loadScenario(scenario); 27 | Population pop = scenario.getPopulation(); 28 | 29 | PopulationReader pr = new PopulationReader(scenario); 30 | pr.readFile(inputPopFilename); 31 | 32 | Scenario newScenario = ScenarioUtils.createScenario(ConfigUtils.createConfig()); 33 | ScenarioUtils.loadScenario(newScenario); 34 | Population newPop = newScenario.getPopulation(); 35 | 36 | String[] persons = {"65250301","64445001"}; 37 | Set desiredPersons = Set.of(persons); 38 | for (Person person : pop.getPersons().values()) { 39 | if (desiredPersons.contains(person.getId().toString())) 40 | newPop.addPerson(person); 41 | } 42 | 43 | PopulationWriter popwriter = new PopulationWriter(newPop); 44 | popwriter.write(outputPopFilename); 45 | System.out.println("done."); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/passenger/UAMPassengerDropoffActivity.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.passenger; 2 | 3 | import org.matsim.contrib.dvrp.fleet.DvrpVehicle; 4 | import org.matsim.contrib.dvrp.passenger.PassengerEngine; 5 | import org.matsim.contrib.dvrp.passenger.PassengerRequest; 6 | import org.matsim.contrib.dvrp.schedule.StayTask; 7 | import org.matsim.contrib.dynagent.DynActivity; 8 | import org.matsim.contrib.dynagent.DynAgent; 9 | 10 | import java.util.Set; 11 | 12 | /** 13 | * This class defines the drop off activity for the passenger and its properties. 14 | * 15 | * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) 16 | */ 17 | public class UAMPassengerDropoffActivity implements DynActivity { 18 | private final PassengerEngine passengerEngine; 19 | private final DynAgent driver; 20 | private final Set requests; 21 | private final String activityType; 22 | 23 | private double endTime; 24 | 25 | public UAMPassengerDropoffActivity(PassengerEngine passengerEngine, DynAgent driver, DvrpVehicle vehicle, StayTask dropoffTask, 26 | Set requests, double dropoffDuration, String activityType) { 27 | this.activityType = activityType; 28 | this.passengerEngine = passengerEngine; 29 | this.driver = driver; 30 | this.requests = requests; 31 | 32 | if (requests.size() > vehicle.getCapacity()) { 33 | // Number of requests exceeds number of seats 34 | throw new IllegalStateException(); 35 | } 36 | 37 | endTime = dropoffTask.getBeginTime() + dropoffDuration; 38 | } 39 | 40 | @Override 41 | public void finalizeAction(double now) { 42 | for (PassengerRequest request : requests) { 43 | passengerEngine.dropOffPassengers(driver, request.getId(), now); 44 | } 45 | } 46 | 47 | @Override 48 | public double getEndTime() { 49 | return endTime; 50 | } 51 | 52 | @Override 53 | public String getActivityType() { 54 | return activityType; 55 | } 56 | 57 | @Override 58 | public void doSimStep(double now) { 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/analysis/uamdemand/run/BatchConvertUAMDemandFromEvents.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.analysis.uamdemand.run; 2 | 3 | import org.apache.commons.io.FileUtils; 4 | 5 | import java.io.File; 6 | import java.io.IOException; 7 | import java.nio.file.Paths; 8 | import java.util.Collection; 9 | import java.util.HashSet; 10 | 11 | /** 12 | * This script takes a specific folder path and runs 13 | * {@link ConvertUAMDemandFromEvents} for all MATSim output folders within the 14 | * provided base folder. 15 | * 16 | * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) 17 | */ 18 | public class BatchConvertUAMDemandFromEvents { 19 | // PROVIDE PARENT FOLDER OF OUTPUT FOLDERS 20 | private static String eventfile = "output_events.xml"; 21 | private static String networkfile = "output_network.xml"; 22 | private static String vehiclefile = "output_uam_vehicles.xml"; 23 | 24 | public static void main(final String[] args) throws IOException { 25 | File folder = Paths.get(args[0]).toFile(); 26 | 27 | String[] ext = {"gz", "xml"}; 28 | Collection potentialFiles = FileUtils.listFiles(folder, ext, true); 29 | 30 | String[] ecl = {"csv"}; 31 | Collection alreadyExistingFiles = FileUtils.listFiles(folder, ecl, true); 32 | Collection alreadyExistingFileNames = new HashSet<>(); 33 | for (File f : alreadyExistingFiles) { 34 | alreadyExistingFileNames.add(f.getAbsolutePath()); 35 | } 36 | 37 | for (File f : potentialFiles) { 38 | if (!f.getName().contains(vehiclefile) 39 | || alreadyExistingFileNames.contains(f.getAbsolutePath() + "_demand.csv")) 40 | continue; 41 | 42 | System.err.println("Working on: " + f.getAbsolutePath()); 43 | String network = f.getAbsolutePath().replace(vehiclefile, networkfile); 44 | String events = f.getAbsolutePath().replace(vehiclefile, eventfile); 45 | ConvertUAMDemandFromEvents.extract(network, events, f.getAbsolutePath(), 46 | f.getAbsolutePath() + "_demand.csv"); 47 | } 48 | 49 | System.err.println("done."); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/analysis/trips/run/ConvertTripsFromPopulation.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.analysis.trips.run; 2 | 3 | import java.io.IOException; 4 | import java.util.Collection; 5 | 6 | import org.matsim.api.core.v01.network.Network; 7 | import org.matsim.core.network.NetworkUtils; 8 | import org.matsim.core.network.io.MatsimNetworkReader; 9 | import org.matsim.core.router.MainModeIdentifier; 10 | import org.matsim.core.router.MainModeIdentifierImpl; 11 | 12 | import net.bhl.matsim.uam.analysis.trips.CSVTripWriter; 13 | import net.bhl.matsim.uam.analysis.trips.TripItem; 14 | import net.bhl.matsim.uam.analysis.trips.readers.PopulationTripReader; 15 | import net.bhl.matsim.uam.analysis.trips.utils.BasicHomeActivityTypes; 16 | import net.bhl.matsim.uam.analysis.trips.utils.HomeActivityTypes; 17 | import net.bhl.matsim.uam.router.UAMMainModeIdentifier; 18 | 19 | /** 20 | * This script creates a trips file by reading through and gathering trip 21 | * information from an existing population (or plan) file. Necessary inputs are 22 | * in the following order: -Network file; -Plans file; 23 | * 24 | * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) 25 | */ 26 | public class ConvertTripsFromPopulation { 27 | static public void main(String[] args) throws IOException { 28 | // PROVIDE: NETWORK PLANS 29 | extract(args[0], args[1], args[1] + ".trips.csv"); 30 | System.out.println("done."); 31 | } 32 | 33 | static public void extract(String network, String plans, String outfile) throws IOException { 34 | Network netw = NetworkUtils.createNetwork(); 35 | new MatsimNetworkReader(netw).readFile(network); 36 | 37 | HomeActivityTypes homeActivityTypes = new BasicHomeActivityTypes(); 38 | MainModeIdentifier mainModeIdentifier = new UAMMainModeIdentifier(new MainModeIdentifierImpl()); 39 | 40 | PopulationTripReader reader = new PopulationTripReader(netw, homeActivityTypes, mainModeIdentifier); 41 | Collection trips = reader.readTrips(plans); 42 | 43 | new CSVTripWriter(trips).write(outfile); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/events/UAMUtilitiesTrip.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.events; 2 | 3 | import net.bhl.matsim.uam.infrastructure.UAMStation; 4 | import org.matsim.api.core.v01.Id; 5 | import org.matsim.api.core.v01.network.Link; 6 | import org.matsim.api.core.v01.population.Person; 7 | 8 | /** 9 | * Class that stores information about a complete UAM trip, including access and 10 | * egress legs. 11 | * 12 | * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) 13 | */ 14 | @Deprecated 15 | public class UAMUtilitiesTrip { 16 | public Id person; 17 | public Id originLink; 18 | public Id originStation; 19 | public Id destinationStation; 20 | public Id destinationLink; 21 | public String accessMode; 22 | public String egressMode; 23 | public double time; 24 | public double accessUtility; 25 | public double uamWaitUtility; 26 | public double uamFlightUtility; 27 | public double uamIncomeUtility; 28 | public double egressUtility; 29 | public double totalUtility; 30 | 31 | public String getHeader() { 32 | return "person,time,originLink,originStation,destinationStation,destinationLink,accessMode,egressMode," 33 | + "accessUtility,uamWaitUtility,uamFlightUtility,uamIncomeUtility,egressUtility,totalUtility"; 34 | } 35 | 36 | @Override 37 | public boolean equals(Object o) { 38 | if (o == this) { 39 | return true; 40 | } 41 | if (!(o instanceof UAMUtilitiesTrip)) { 42 | return false; 43 | } 44 | UAMUtilitiesTrip other = (UAMUtilitiesTrip) o; 45 | return this.toString().equals(other.toString()); 46 | } 47 | 48 | @Override 49 | public int hashCode() { 50 | return this.toString().hashCode(); 51 | } 52 | 53 | public String toString() { 54 | return "" + person + "," + time + "," + originLink + "," + originStation + "," + destinationStation + "," 55 | + destinationLink + "," + accessMode + "," + egressMode + "," + accessUtility + "," + uamWaitUtility 56 | + "," + uamFlightUtility + "," + uamIncomeUtility + "," + egressUtility + "," + totalUtility; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/analysis/uamstations/CSVUAMStationWriter.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.analysis.uamstations; 2 | 3 | import net.bhl.matsim.uam.run.UAMConstants; 4 | 5 | import java.io.BufferedWriter; 6 | import java.io.FileOutputStream; 7 | import java.io.IOException; 8 | import java.io.OutputStreamWriter; 9 | import java.util.Collection; 10 | import java.util.HashSet; 11 | 12 | /** 13 | * This class writes a CSV file containing UAM Stations data. 14 | * 15 | * @author Aitanm (Aitan Militao), RRothfeld (Raoul Rothfeld) 16 | */ 17 | public class CSVUAMStationWriter { 18 | final private HashSet uamStations; 19 | final private String delimiter; 20 | 21 | public CSVUAMStationWriter(Collection uamStations) { 22 | this(uamStations, ","); 23 | } 24 | 25 | public CSVUAMStationWriter(Collection uamStations, String delimiter) { 26 | this.uamStations = new HashSet<>(uamStations); 27 | this.delimiter = delimiter; 28 | } 29 | 30 | public void write(String outputPath) throws IOException { 31 | BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outputPath))); 32 | writer.write(formatHeader() + "\n"); 33 | writer.flush(); 34 | for (UAMStationItem station : uamStations) { 35 | writer.write(formatData(station) + "\n"); 36 | writer.flush(); 37 | } 38 | writer.flush(); 39 | writer.close(); 40 | } 41 | 42 | private String formatHeader() { 43 | return String.join(delimiter, new String[]{"name", "id", "landingcap", "preflighttime", "postflighttime", 44 | "defaultwaittime", "link"}); 45 | } 46 | 47 | private String formatData(UAMStationItem station) { 48 | try { 49 | return String.join(delimiter, 50 | new String[]{station.name, 51 | station.id.toString(), 52 | String.valueOf(station.preflighttime), 53 | String.valueOf(station.postflighttime), 54 | String.valueOf(station.defaultwaittime), 55 | station.link}); 56 | } catch (Exception ignored) { 57 | } 58 | return UAMConstants.uam + "Data could not be read"; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/listeners/UAMShutdownListener.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.listeners; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.io.InputStream; 6 | import java.io.OutputStream; 7 | 8 | import org.apache.logging.log4j.LogManager; 9 | import org.apache.logging.log4j.Logger; 10 | import org.matsim.core.config.Config; 11 | import org.matsim.core.config.ConfigGroup; 12 | import org.matsim.core.controler.OutputDirectoryHierarchy; 13 | import org.matsim.core.controler.events.ShutdownEvent; 14 | import org.matsim.core.controler.listener.ShutdownListener; 15 | import org.matsim.core.utils.io.IOUtils; 16 | 17 | import com.google.inject.Inject; 18 | 19 | import net.bhl.matsim.uam.config.UAMConfigGroup; 20 | 21 | /** 22 | * This listener copies the input UAM Vehicle file into the output folder after 23 | * the simulation ends 24 | * 25 | * @author Aitanm (Aitan Militao), RRothfeld (Raoul Rothfeld) 26 | */ 27 | 28 | public class UAMShutdownListener implements ShutdownListener { 29 | private static final Logger log = LogManager.getLogger(UAMListener.class); 30 | 31 | @Inject 32 | private OutputDirectoryHierarchy controlerIO; 33 | 34 | @Inject 35 | private Config config; 36 | 37 | @Inject 38 | private UAMConfigGroup uamConfig; 39 | 40 | @Override 41 | public void notifyShutdown(ShutdownEvent event) { 42 | writeUAMVehiclesFile(event); 43 | } 44 | 45 | private void writeUAMVehiclesFile(ShutdownEvent event) { 46 | try { 47 | InputStream fromStream = IOUtils 48 | .getInputStream(ConfigGroup.getInputFileURL(config.getContext(), uamConfig.getInputFile())); 49 | OutputStream toStream = IOUtils.getOutputStream( 50 | new File(controlerIO.getOutputFilename("output_uam_vehicles.xml.gz")).toURI().toURL(), false); 51 | IOUtils.copyStream(fromStream, toStream); 52 | 53 | fromStream.close(); 54 | toStream.close(); 55 | } catch (IOException e) { 56 | log.warn("writing output UAM Vehicles did not work; probably parameters were such that no events were " 57 | + "generated in the final iteration"); 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/analysis/uamstations/run/ConvertUAMStationsFromUAMVehicles.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.analysis.uamstations.run; 2 | 3 | import net.bhl.matsim.uam.analysis.uamstations.CSVUAMStationWriter; 4 | import net.bhl.matsim.uam.analysis.uamstations.UAMStationItem; 5 | import net.bhl.matsim.uam.infrastructure.UAMStation; 6 | import net.bhl.matsim.uam.infrastructure.UAMStations; 7 | import net.bhl.matsim.uam.infrastructure.readers.UAMXMLReader; 8 | import org.matsim.api.core.v01.network.Network; 9 | import org.matsim.core.network.NetworkUtils; 10 | import org.matsim.core.network.io.MatsimNetworkReader; 11 | 12 | import java.io.IOException; 13 | import java.util.Collection; 14 | import java.util.HashSet; 15 | 16 | /** 17 | * This script generates a Generates a csv file containing information about UAM 18 | * Stations. Necessary inputs are in the following order: -Network file; -UAM 19 | * Vehicles file -output file; 20 | * 21 | * @author Aitanm (Aitan Militao), RRothfeld (Raoul Rothfeld) 22 | */ 23 | 24 | public class ConvertUAMStationsFromUAMVehicles { 25 | static public void main(String[] args) throws IOException { 26 | // PROVIDE: NETWORK UAMVEHICLES OUTFILE-NAME 27 | extract(args[0], args[1], args[2]); 28 | System.out.println("done."); 29 | } 30 | 31 | static public void extract(String network, String uamVehicles, String outfile) throws IOException { 32 | Network netw = NetworkUtils.createNetwork(); 33 | new MatsimNetworkReader(netw).readFile(network); 34 | 35 | UAMXMLReader uamReader = new UAMXMLReader(netw); 36 | uamReader.readFile(uamVehicles); 37 | UAMStations uamStations = new UAMStations(uamReader.getStations(), netw); 38 | 39 | Collection uamData = new HashSet<>(); 40 | for (UAMStation station : uamStations.getUAMStations().values()) { 41 | uamData.add(new UAMStationItem(station.getName(), station.getId(), 42 | (int) station.getPreFlightTime(), (int) station.getPostFlightTime(), 43 | (int) station.getDefaultWaitTime(), station.getLocationLink().getId().toString())); 44 | } 45 | 46 | new CSVUAMStationWriter(uamData).write(outfile); 47 | } 48 | } -------------------------------------------------------------------------------- /examples/uam-scenario-creation/non-uam-scenario/config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/analysis/trips/run/RunConvertDeckGLBuildings.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.analysis.trips.run; 2 | 3 | import java.io.*; 4 | 5 | /** 6 | * This script converts QGIS geojson file from OSM buildings to deck.gl-readable 7 | * buildings input file. 8 | * 9 | * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) 10 | */ 11 | public class RunConvertDeckGLBuildings { 12 | static public void main(String[] args) throws IOException { 13 | // PROVIDE: GEOJSON-File 14 | extract(args[0]); 15 | System.out.println("done."); 16 | } 17 | 18 | static public void extract(String geojson) throws IOException { 19 | BufferedReader br = null; 20 | BufferedWriter bw = null; 21 | try { 22 | InputStream fis = new FileInputStream(geojson); 23 | br = new BufferedReader(new InputStreamReader(fis)); 24 | 25 | File file = new File(geojson + ".json"); 26 | if (!file.exists()) { 27 | file.createNewFile(); 28 | } 29 | FileWriter fw = new FileWriter(file); 30 | bw = new BufferedWriter(fw); 31 | 32 | bw.write("[" + System.lineSeparator()); 33 | 34 | boolean first = true; 35 | for (String line = br.readLine(); line != null; line = br.readLine()) { 36 | if (line.contains("coordinates")) { 37 | if (!first) 38 | bw.write("," + System.lineSeparator()); 39 | 40 | int index = line.indexOf("coordinates\": ") + "coordinates\": ".length(); 41 | String linePart = line.substring(index); 42 | linePart = linePart.substring(0, linePart.length() - 4); 43 | linePart = linePart.replace("[ [ [ [ ", "[ [ [ "); 44 | linePart = linePart.replace(" ] ] ] ]", "] ] ] "); 45 | 46 | bw.write("{\"height\": 100, "); 47 | bw.write("\"polygon\": "); 48 | bw.write(linePart); 49 | bw.write("}"); 50 | first = false; 51 | } 52 | } 53 | 54 | bw.write(System.lineSeparator() + "]"); 55 | } catch (IOException e) { 56 | e.printStackTrace(); 57 | } finally { 58 | try { 59 | if (bw != null) 60 | bw.close(); 61 | if (br != null) 62 | br.close(); 63 | } catch (Exception e) { 64 | e.printStackTrace(); 65 | } 66 | } 67 | } 68 | } -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/analysis/trips/DeckGLTripItem.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.analysis.trips; 2 | 3 | import org.geotools.geometry.jts.JTS; 4 | import org.geotools.referencing.CRS; 5 | import org.locationtech.jts.geom.Coordinate; 6 | import org.matsim.api.core.v01.Coord; 7 | import org.matsim.core.utils.geometry.geotools.MGC; 8 | import org.opengis.referencing.FactoryException; 9 | import org.opengis.referencing.crs.CoordinateReferenceSystem; 10 | import org.opengis.referencing.operation.MathTransform; 11 | import org.opengis.referencing.operation.TransformException; 12 | 13 | /** 14 | * This class stores information about a trip for deck.gl format. 15 | * 16 | * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) 17 | */ 18 | public class DeckGLTripItem { 19 | 20 | public Coord location; 21 | public long time; 22 | public long timeShift; 23 | 24 | public DeckGLTripItem(Coord location, long time) { 25 | this(location, time, 0); 26 | } 27 | 28 | public DeckGLTripItem(Coord location, long time, long timeShift) { 29 | this.location = location; 30 | this.time = time; 31 | this.timeShift = timeShift; 32 | } 33 | 34 | @Override 35 | public String toString() { 36 | return "[" + location.getX() + "," + location.getY() + "," + time + "]"; 37 | } 38 | 39 | public String convert(String inputEPSGCode, String outputEPSGCode, long timeMultiplier) { 40 | Coordinate convertedSource = null; 41 | 42 | CoordinateReferenceSystem crsIn; 43 | CoordinateReferenceSystem crsOut = null; 44 | try { 45 | crsIn = MGC.getCRS(inputEPSGCode); // EPSG:code crsOut = 46 | MGC.getCRS(outputEPSGCode); // EPSG:code 47 | MathTransform transform = CRS.findMathTransform(crsIn, crsOut); 48 | Coordinate source = new Coordinate(location.getX(), location.getY()); 49 | convertedSource = JTS.transform(source, null, transform); 50 | 51 | } catch (IllegalArgumentException e) { 52 | System.err.println("Old geotools version is not compatible with Java 9"); 53 | e.printStackTrace(); 54 | System.exit(1); 55 | } catch (FactoryException | TransformException e) { 56 | e.printStackTrace(); 57 | } 58 | 59 | return "[" + convertedSource.x + "," + convertedSource.y + "," + ((time - timeShift) * timeMultiplier) + "]"; 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/analysis/traffic/CSVLinkStatsWriter.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.analysis.traffic; 2 | 3 | import java.io.BufferedWriter; 4 | import java.io.FileOutputStream; 5 | import java.io.IOException; 6 | import java.io.OutputStreamWriter; 7 | import java.util.*; 8 | 9 | /** 10 | * This class writes a CSV file containing information of links for different 11 | * times. 12 | * 13 | * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) 14 | */ 15 | public class CSVLinkStatsWriter { 16 | final private Collection links; 17 | final private String delimiter; 18 | private SortedSet timeHeaders; 19 | 20 | public CSVLinkStatsWriter(Collection links) { 21 | this(links, ","); 22 | } 23 | 24 | public CSVLinkStatsWriter(Collection links, String delimiter) { 25 | this.links = links; 26 | this.delimiter = delimiter; 27 | } 28 | 29 | public void write(String outputPath) throws IOException { 30 | BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outputPath))); 31 | writer.write(formatHeader() + "\n"); 32 | for (LinkStatsItem link : links) { 33 | writer.write(formatLinkStatsItem(link) + "\n"); 34 | } 35 | writer.close(); 36 | } 37 | 38 | private String formatHeader() { 39 | List header = new ArrayList<>(); 40 | header.add("link_id"); 41 | header.add("length_m"); 42 | header.add("freespeed_ms"); 43 | 44 | timeHeaders = new TreeSet<>(); 45 | for (LinkStatsItem link : links) { 46 | timeHeaders.addAll(link.timeDependantSpeed.keySet()); 47 | } 48 | 49 | for (Integer timeHead : timeHeaders) { 50 | header.add("avgspeed_ms_at_H" + (timeHead / 3600) + "M" + ((timeHead % 3600) / 60)); 51 | } 52 | 53 | return String.join(delimiter, header); 54 | } 55 | 56 | private String formatLinkStatsItem(LinkStatsItem link) { 57 | List row = new ArrayList<>(); 58 | row.add(link.linkId.toString()); 59 | row.add(String.valueOf(link.distance)); 60 | row.add(String.valueOf(link.freeSpeed)); 61 | 62 | for (Integer timeHead : timeHeaders) { 63 | if (link.timeDependantSpeed.containsKey(timeHead)) 64 | row.add(String.valueOf(link.timeDependantSpeed.get(timeHead))); 65 | } 66 | 67 | return String.join(delimiter, row); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/analysis/uamdemand/run/ConvertUAMDemandFromEvents.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.analysis.uamdemand.run; 2 | 3 | import java.io.IOException; 4 | import java.util.Arrays; 5 | import java.util.Collection; 6 | 7 | import org.matsim.api.core.v01.TransportMode; 8 | import org.matsim.api.core.v01.network.Network; 9 | import org.matsim.core.network.NetworkUtils; 10 | import org.matsim.core.network.io.MatsimNetworkReader; 11 | import org.matsim.core.router.MainModeIdentifier; 12 | import org.matsim.core.router.MainModeIdentifierImpl; 13 | 14 | import net.bhl.matsim.uam.analysis.uamdemand.CSVUAMDemandWriter; 15 | import net.bhl.matsim.uam.analysis.uamdemand.UAMDemandItem; 16 | import net.bhl.matsim.uam.analysis.uamdemand.listeners.UAMListener; 17 | import net.bhl.matsim.uam.analysis.uamdemand.readers.EventsUAMReader; 18 | import net.bhl.matsim.uam.router.UAMMainModeIdentifier; 19 | import net.bhl.matsim.uam.run.UAMConstants; 20 | 21 | /** 22 | * This script generates a UAMDemand csv file containing UAMDemand data. 23 | * Necessary inputs are in the following order: -Network file; -Events file; 24 | * -UAMConfig file; -output file; 25 | * 26 | * @author Aitanm (Aitan Militao), RRothfeld (Raoul Rothfeld) 27 | */ 28 | 29 | public class ConvertUAMDemandFromEvents { 30 | static public void main(String[] args) throws IOException { 31 | // PROVIDE: NETWORK EVENTS UAMVEHICLES OUTFILE-NAME 32 | extract(args[0], args[1], args[2], args[3]); 33 | System.out.println("done."); 34 | } 35 | 36 | static public void extract(String network, String events, String uamVehicles, String outfile) throws IOException { 37 | Network netw = NetworkUtils.createNetwork(); 38 | new MatsimNetworkReader(netw).readFile(network); 39 | 40 | MainModeIdentifier mainModeIdentifier = new UAMMainModeIdentifier(new MainModeIdentifierImpl()); 41 | Collection networkRouteModes = Arrays.asList(TransportMode.car, UAMConstants.uam, 42 | UAMConstants.access + TransportMode.car, UAMConstants.egress + TransportMode.car); 43 | 44 | UAMListener uamListener = new UAMListener(netw, uamVehicles, mainModeIdentifier, 45 | networkRouteModes); 46 | Collection uamData = new EventsUAMReader(uamListener).readUAMData(events); 47 | 48 | new CSVUAMDemandWriter(uamData).write(outfile); 49 | } 50 | } -------------------------------------------------------------------------------- /docs/versioning.md: -------------------------------------------------------------------------------- 1 | # How to make a new version 2 | 3 | - If you want to create a new version you should have access to the packagecloud repository of uam 4 | 5 | ## Packagecloud configuration 6 | 7 | To use packagecloud, you need to put the following authentication information in your local `.m2/settings.xml` (usually in your home folder, e.g. `~/.m2/settings.xml` on Linux): 8 | 9 | ```xml 10 | 11 | 12 | 13 | packagecloud-uam 14 | USERNAME 15 | API TOKEN 16 | 17 | 18 | 19 | ``` 20 | 21 | The `USERNAME` is your username on packagecloud which has access to the repository. The `API TOKEN` you can generate on packagecloud after your are logged in. The `id` of the server needs to stay as is here, as it is referenced in the `pom.xml` of eqasim. 22 | 23 | ## Which new version number to choose? 24 | 25 | - We follow `semver`, which means `MAJOR.MINOR.PATCH` 26 | - `PATCH` is increased if bugs got fixed and no interfaces have been changed. 27 | - `MINOR` is updated when interfaces change, new functionality is added. 28 | - `MAJOR` is updated when major changes have been done (whatever this means exactly :) 29 | 30 | ## Step by step 31 | 32 | - Create a new branch `versionX.X.X` based on the current `master` 33 | - In the new branch, update the version in the Maven packages by 34 | - `mvn versions:set` and then giving the new version number `X.X.X` 35 | - `mvn versions:commit` to accept the preliminary changes (which you can verify) in the `pom.xml` 36 | - Update all the references to the old version `Y.Y.Y` with the new version `X.X.X` in `README.md` 37 | - Update the `README.md` 38 | - ... by replacing **Development version** with **X.X.X** 39 | - ... by adding a new section **Development version** on top of the changelog and one bullet point "No changes yet" 40 | - Commit the changes to the new branch 41 | - Create a PR on Github and wait until the test have passed. 42 | - Merge the PR on Github in case there are no errors. Call the PR "Release X.X.X". 43 | - Locally, check out the updated `master` branch 44 | - Run `git tag vX.X.X` to create the new verison tag 45 | - Run `git push --tags` to push the new version tag 46 | - Run `mvn deploy` to deploy the Maven artifacts to Bintray 47 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/infrastructure/UAMStationWithChargers.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.infrastructure; 2 | 3 | import org.matsim.api.core.v01.Id; 4 | import org.matsim.api.core.v01.network.Link; 5 | 6 | /** 7 | * This class defines the UAM Station with chargers. * 8 | * 9 | */ 10 | public class UAMStationWithChargers implements UAMStation { 11 | 12 | // UAM infrastructure-specific properties 13 | private final Link locationLink; 14 | private final Id id; 15 | private final String name; 16 | // parameters added 17 | private final double preFlightTime; 18 | private final double postFlightTime; 19 | private final double defaultWaitTime; 20 | private final int numberOfChargers; 21 | private final double chargingSpeed; 22 | 23 | public UAMStationWithChargers(double preFlightTime, double postFlightTime, 24 | double defaultWaitTime, Link locationLink, Id id, 25 | int numberOfChargers, double chargingSpeed) { 26 | this(preFlightTime, postFlightTime, defaultWaitTime, locationLink, id, 27 | id.toString(), numberOfChargers, chargingSpeed); 28 | } 29 | 30 | public UAMStationWithChargers(double preFlightTime, double postFlightTime, 31 | double defaultWaitTime, Link locationLink, Id id, String name, 32 | int numberOfChargers, double chargingSpeed) { 33 | this.locationLink = locationLink; 34 | this.id = id; 35 | this.name = name; 36 | this.preFlightTime = preFlightTime; 37 | this.postFlightTime = postFlightTime; 38 | this.defaultWaitTime = defaultWaitTime; 39 | this.numberOfChargers = numberOfChargers; 40 | this.chargingSpeed = chargingSpeed; 41 | } 42 | 43 | @Override 44 | public String getName() { 45 | return name; 46 | } 47 | 48 | @Override 49 | public Link getLocationLink() { 50 | return locationLink; 51 | } 52 | 53 | @Override 54 | public Id getId() { 55 | return id; 56 | } 57 | 58 | @Override 59 | public double getPreFlightTime() { 60 | return preFlightTime; 61 | } 62 | 63 | @Override 64 | public double getPostFlightTime() { 65 | return postFlightTime; 66 | } 67 | 68 | @Override 69 | public double getDefaultWaitTime() { 70 | return defaultWaitTime; 71 | } 72 | 73 | public int getNumberOfChargers() { 74 | return numberOfChargers; 75 | } 76 | 77 | public double getChargingSpeed() { 78 | return chargingSpeed; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/analysis/trips/run/ConvertTripsFromEvents.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.analysis.trips.run; 2 | 3 | import java.io.IOException; 4 | import java.util.Arrays; 5 | import java.util.Collection; 6 | 7 | import org.matsim.api.core.v01.TransportMode; 8 | import org.matsim.api.core.v01.network.Network; 9 | import org.matsim.core.network.NetworkUtils; 10 | import org.matsim.core.network.io.MatsimNetworkReader; 11 | import org.matsim.core.router.MainModeIdentifier; 12 | import org.matsim.core.router.MainModeIdentifierImpl; 13 | 14 | import net.bhl.matsim.uam.analysis.trips.CSVTripWriter; 15 | import net.bhl.matsim.uam.analysis.trips.TripItem; 16 | import net.bhl.matsim.uam.analysis.trips.listeners.TripListener; 17 | import net.bhl.matsim.uam.analysis.trips.readers.EventsTripReader; 18 | import net.bhl.matsim.uam.analysis.trips.utils.BasicHomeActivityTypes; 19 | import net.bhl.matsim.uam.analysis.trips.utils.HomeActivityTypes; 20 | import net.bhl.matsim.uam.router.UAMMainModeIdentifier; 21 | import net.bhl.matsim.uam.run.UAMConstants; 22 | 23 | /** 24 | * This script creates a trips file by reading through and gathering trip 25 | * information from an existing events file. Necessary inputs are in the 26 | * following order: -Network file; -Events file; -output file; 27 | * 28 | * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) 29 | */ 30 | public class ConvertTripsFromEvents { 31 | static public void main(String[] args) throws IOException { 32 | // PROVIDE: NETWORK EVENTS 33 | extract(args[0], args[1], args[1] + ".trips.csv"); 34 | System.out.println("done."); 35 | } 36 | 37 | static public void extract(String network, String events, String outfile) throws IOException { 38 | Network netw = NetworkUtils.createNetwork(); 39 | new MatsimNetworkReader(netw).readFile(network); 40 | 41 | HomeActivityTypes homeActivityTypes = new BasicHomeActivityTypes(); 42 | MainModeIdentifier mainModeIdentifier = new UAMMainModeIdentifier(new MainModeIdentifierImpl()); 43 | Collection networkRouteModes = Arrays.asList(TransportMode.car, UAMConstants.uam, 44 | UAMConstants.access + TransportMode.car, UAMConstants.egress + TransportMode.car); 45 | 46 | TripListener tripListener = new TripListener(netw, homeActivityTypes, mainModeIdentifier, networkRouteModes); 47 | Collection trips = new EventsTripReader(tripListener).readTrips(events); 48 | 49 | new CSVTripWriter(trips).write(outfile); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/infrastructure/UAMStations.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.infrastructure; 2 | 3 | import org.matsim.api.core.v01.Coord; 4 | import org.matsim.api.core.v01.Id; 5 | import org.matsim.api.core.v01.network.Link; 6 | import org.matsim.api.core.v01.network.Network; 7 | import org.matsim.core.network.NetworkUtils; 8 | import org.matsim.core.utils.collections.QuadTree; 9 | 10 | import java.util.Collection; 11 | import java.util.Map; 12 | 13 | /** 14 | * Class to map stations and its locations in the network. 15 | * 16 | * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) 17 | */ 18 | public class UAMStations { 19 | private Map, UAMStation> stations; 20 | private QuadTree spatialStations; 21 | private QuadTree spatialStationsWithChargers; 22 | 23 | public UAMStations(Map, UAMStation> stations, Network network) { 24 | 25 | this.stations = stations; 26 | double[] bounds = NetworkUtils.getBoundingBox(network.getNodes().values()); // minx, miny, maxx, maxy 27 | 28 | spatialStations = new QuadTree<>(bounds[0], bounds[1], bounds[2], bounds[3]); 29 | for (UAMStation station : stations.values()) { 30 | double x = station.getLocationLink().getCoord().getX(); 31 | double y = station.getLocationLink().getCoord().getY(); 32 | spatialStations.put(x, y, station); 33 | } 34 | 35 | spatialStationsWithChargers = new QuadTree<>(bounds[0], bounds[1], bounds[2], bounds[3]); 36 | for (UAMStation station : stations.values()) { 37 | double x = station.getLocationLink().getCoord().getX(); 38 | double y = station.getLocationLink().getCoord().getY(); 39 | if (station instanceof UAMStationWithChargers) { 40 | if (((UAMStationWithChargers) station).getNumberOfChargers() > 0) { 41 | spatialStationsWithChargers.put(x, y, station); 42 | 43 | } 44 | } 45 | } 46 | } 47 | 48 | public Map, UAMStation> getUAMStations() { 49 | return stations; 50 | } 51 | 52 | public UAMStation getNearestUAMStation(Link link) { 53 | return spatialStations.getClosest(link.getCoord().getX(), link.getCoord().getY()); 54 | } 55 | 56 | public Collection getUAMStationsInRadius(Coord coord, double radius) { 57 | return spatialStations.getDisk(coord.getX(), coord.getY(), radius); 58 | } 59 | 60 | public UAMStation getNearestUAMStationWithCharger(Link link) { 61 | return spatialStationsWithChargers.getClosest(link.getCoord().getX(), link.getCoord().getY()); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/analysis/uamdemand/UAMDemandItem.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.analysis.uamdemand; 2 | 3 | import net.bhl.matsim.uam.infrastructure.UAMStation; 4 | import org.matsim.api.core.v01.Coord; 5 | import org.matsim.api.core.v01.Id; 6 | import org.matsim.api.core.v01.population.Person; 7 | 8 | /** 9 | * This class stores information about a UAM trip. 10 | * 11 | * @author Aitanm (Aitan Militao), RRothfeld (Raoul Rothfeld) 12 | */ 13 | public class UAMDemandItem { 14 | public Id personId; 15 | public Coord origin; 16 | public Coord originStationCoord; 17 | public Coord destinationStationCoord; 18 | public Coord destination; 19 | public Id originStationId; 20 | public Id destinationStationId; 21 | public double startTime; 22 | public double arrivalAtStationTime; 23 | public double takeOffTime; 24 | public double landingTime; 25 | public double departureFromStationTime; 26 | public double endTime; 27 | public String vehicleId; 28 | public String accessMode; 29 | public String egressMode; 30 | public boolean uamTrip; 31 | 32 | public UAMDemandItem(Id personId, Coord origin, Coord originStationCoord, Coord destinationStationCoord, 33 | Coord destination, Id originStationId, Id destinationStationId, double startTime, 34 | double arrivalAtStationTime, double takeOffTime, double landingTime, double departureFromStationTime, 35 | double endTime, String vehicleId, String accessMode, String egressMode, boolean uamTrip) { 36 | super(); 37 | this.personId = personId; 38 | this.origin = origin; 39 | this.originStationCoord = originStationCoord; 40 | this.destinationStationCoord = destinationStationCoord; 41 | this.destination = destination; 42 | this.originStationId = originStationId; 43 | this.destinationStationId = destinationStationId; 44 | this.startTime = startTime; 45 | this.arrivalAtStationTime = arrivalAtStationTime; 46 | this.takeOffTime = takeOffTime; 47 | this.landingTime = landingTime; 48 | this.departureFromStationTime = departureFromStationTime; 49 | this.endTime = endTime; 50 | this.vehicleId = vehicleId; 51 | this.accessMode = accessMode; 52 | this.egressMode = egressMode; 53 | this.uamTrip = uamTrip; 54 | } 55 | 56 | public void setOriginStationId(Id originStationId) { 57 | this.originStationId = originStationId; 58 | } 59 | 60 | public void setTakeOffTime(double takeOffTime) { 61 | this.takeOffTime = takeOffTime; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/analysis/trips/CSVTripWriter.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.analysis.trips; 2 | 3 | import java.io.BufferedWriter; 4 | import java.io.FileOutputStream; 5 | import java.io.IOException; 6 | import java.io.OutputStreamWriter; 7 | import java.util.Collection; 8 | 9 | /** 10 | * This class writes a CSV file containing information about each trip. 11 | * 12 | * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) 13 | */ 14 | public class CSVTripWriter { 15 | final private Collection trips; 16 | final private String delimiter; 17 | 18 | public CSVTripWriter(Collection trips) { 19 | this(trips, ","); 20 | } 21 | 22 | public CSVTripWriter(Collection trips, String delimiter) { 23 | this.trips = trips; 24 | this.delimiter = delimiter; 25 | } 26 | 27 | public void write(String outputPath) throws IOException { 28 | BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outputPath))); 29 | 30 | writer.write(formatHeader() + "\n"); 31 | writer.flush(); 32 | 33 | for (TripItem trip : trips) { 34 | writer.write(formatTrip(trip) + "\n"); 35 | writer.flush(); 36 | } 37 | 38 | writer.flush(); 39 | writer.close(); 40 | } 41 | 42 | private String normalizeActivityType(String activityType) { 43 | return activityType.replaceAll("_[0-9]+$", ""); 44 | } 45 | 46 | private String formatHeader() { 47 | return String.join(delimiter, 48 | new String[]{"person_id", "person_trip_id", "origin_x", "origin_y", "destination_x", "destination_y", 49 | "start_time", "travel_time", "network_distance", "mode", "preceedingPurpose", 50 | "followingPurpose", "returning", "crowfly_distance"}); 51 | } 52 | 53 | private String formatTrip(TripItem trip) { 54 | return String.join(delimiter, new String[]{ 55 | trip.personId.toString(), 56 | String.valueOf(trip.personTripId), 57 | trip.origin == null ? "" : String.valueOf(trip.origin.getX()), 58 | trip.origin == null ? "" : String.valueOf(trip.origin.getY()), 59 | trip.destination == null ? "" : String.valueOf(trip.destination.getX()), 60 | trip.destination == null ? "" : String.valueOf(trip.destination.getY()), 61 | String.valueOf(trip.startTime), 62 | String.valueOf(trip.travelTime), 63 | String.valueOf(trip.networkDistance), 64 | trip.mode, 65 | normalizeActivityType(trip.preceedingPurpose), 66 | normalizeActivityType(trip.followingPurpose), 67 | String.valueOf(trip.returning), 68 | String.valueOf(trip.crowflyDistance)}); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/events/UAMData.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.events; 2 | 3 | import net.bhl.matsim.uam.infrastructure.UAMStation; 4 | import org.matsim.api.core.v01.Id; 5 | import org.matsim.api.core.v01.network.Link; 6 | 7 | /** 8 | * Object of this class contains all the information describing one uam trip. 9 | * 10 | * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) 11 | */ 12 | public class UAMData { 13 | 14 | Link originLink; 15 | Link originStationLink; 16 | Link destinationStationLink; 17 | Link destinationLink; 18 | Id originStationId; 19 | Id destinationStationId; 20 | double startTime; 21 | double arrivalAtStationTime; 22 | double takeOffTime; 23 | double landingTime; 24 | double departureFromStationTime; 25 | double endTime; 26 | String vehicleId = null; 27 | String accessMode; 28 | String egressMode; 29 | boolean uamTrip = false; 30 | 31 | public String toString() { 32 | if (uamTrip && originLink != null && originStationLink != null && destinationLink != null 33 | && destinationStationLink != null) { 34 | return originLink.getCoord().getX() + "," + originLink.getCoord().getY() + "," 35 | + originStationLink.getCoord().getX() + "," + originStationLink.getCoord().getY() + "," 36 | + destinationStationLink.getCoord().getX() + "," + destinationStationLink.getCoord().getY() + "," 37 | + destinationLink.getCoord().getX() + "," + destinationLink.getCoord().getY() + "," + startTime 38 | + "," + arrivalAtStationTime + "," + takeOffTime + "," + landingTime + "," 39 | + departureFromStationTime + "," + endTime + "," + vehicleId + "," + originStationId + "," 40 | + destinationStationId + "," + accessMode + "," + egressMode + "," + uamTrip; 41 | } else if (uamTrip && originLink != null && originStationLink != null && destinationStationLink != null) { 42 | 43 | return originLink.getCoord().getX() + "," + originLink.getCoord().getY() + "," 44 | + originStationLink.getCoord().getX() + "," + originStationLink.getCoord().getY() + "," 45 | + destinationStationLink.getCoord().getX() + "," + destinationStationLink.getCoord().getY() + "," 46 | + "," + "," + startTime + "," + arrivalAtStationTime + "," + takeOffTime + "," + landingTime + "," 47 | + departureFromStationTime + "," + endTime + "," + vehicleId + "," + originStationId + "," 48 | + destinationStationId + "," + accessMode + "," + egressMode + "," + uamTrip; 49 | } else 50 | return originLink.getCoord().getX() + "," + originLink.getCoord().getY() + ",,,,,,," + startTime + ",,,,,,," 51 | + originStationId + ",," + accessMode + ",," + uamTrip; 52 | } 53 | } -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/infrastructure/UAMVehicleType.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.infrastructure; 2 | 3 | import org.matsim.api.core.v01.Id; 4 | 5 | /** 6 | * This class defines the VTOL vehicle type and its properties. 7 | * 8 | * @author Aitanm (Aitan Militao), RRothfeld (Raoul Rothfeld) 9 | */ 10 | 11 | public class UAMVehicleType { 12 | private final Id id; 13 | private final int capacity; 14 | private final double range; // [m] 15 | private final double cruiseSpeed; // [m/s] 16 | private final double verticalSpeed; // [m/s] 17 | private final double boardingTime; // [s] 18 | private final double deboardingTime; // [s] 19 | private final double turnAroundTime; // [s] 20 | private final double maximumCharge; 21 | private final double energyConsumptionVertical; 22 | private final double energyConsumptionHorizontal; 23 | 24 | 25 | 26 | public UAMVehicleType(Id id, int capacity, double range, double cruiseSpeed, double verticalSpeed, 27 | double boardingTime, double deboardingTime, double turnAroundTime, 28 | double energyConsumptionVertical, double energyConsumptionHorizontal, double maximumCharge) { 29 | this.id = id; 30 | this.capacity = capacity; 31 | this.range = range; 32 | this.cruiseSpeed = cruiseSpeed; 33 | this.verticalSpeed = verticalSpeed; 34 | this.boardingTime = boardingTime; 35 | this.deboardingTime = deboardingTime; 36 | this.turnAroundTime = turnAroundTime; 37 | this.energyConsumptionHorizontal = energyConsumptionHorizontal; 38 | this.energyConsumptionVertical = energyConsumptionVertical; 39 | this.maximumCharge = maximumCharge; 40 | } 41 | 42 | public int getCapacity() { // used only in the reader, given that the UAMVehicle superclass already has it 43 | return this.capacity; 44 | } 45 | 46 | public double getRange() { // used only in the reader, given that the UAMVehicle superclass already has it 47 | return this.range; 48 | } 49 | 50 | public double getCruiseSpeed() { 51 | return this.cruiseSpeed; 52 | } 53 | 54 | public double getVerticalSpeed() { 55 | return this.verticalSpeed; 56 | } 57 | 58 | public double getboardingTime() { 59 | return this.boardingTime; 60 | } 61 | 62 | public double getDeboardingTime() { 63 | return this.deboardingTime; 64 | } 65 | 66 | public double getTurnAroundTime() { 67 | return this.turnAroundTime; 68 | } 69 | 70 | public double getMaximumCharge() { 71 | return maximumCharge; 72 | } 73 | 74 | public double getEnergyConsumptionVertical() { 75 | return energyConsumptionVertical; 76 | } 77 | 78 | public double getEnergyConsumptionHorizontal() { 79 | return energyConsumptionHorizontal; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/analysis/trips/listeners/DeckGLTripListener.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.analysis.trips.listeners; 2 | 3 | import net.bhl.matsim.uam.analysis.trips.DeckGLTripItem; 4 | import org.matsim.api.core.v01.Coord; 5 | import org.matsim.api.core.v01.Id; 6 | import org.matsim.api.core.v01.events.LinkEnterEvent; 7 | import org.matsim.api.core.v01.events.LinkLeaveEvent; 8 | import org.matsim.api.core.v01.events.handler.LinkEnterEventHandler; 9 | import org.matsim.api.core.v01.events.handler.LinkLeaveEventHandler; 10 | import org.matsim.api.core.v01.network.Network; 11 | import org.matsim.vehicles.Vehicle; 12 | 13 | import java.util.HashMap; 14 | import java.util.LinkedList; 15 | import java.util.List; 16 | import java.util.Map; 17 | 18 | /** 19 | * A listener that retrieves information from trip events and stores in 20 | * <{@link DeckGLTripItem} format. 21 | * 22 | * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) 23 | */ 24 | public class DeckGLTripListener implements LinkEnterEventHandler, LinkLeaveEventHandler { 25 | 26 | final private Map, List> deckGLTrips; 27 | final private Network network; 28 | final private long minTime; 29 | final private long maxTime; 30 | 31 | public DeckGLTripListener(Network network) { 32 | this(network, 0, Long.MAX_VALUE); 33 | } 34 | 35 | public DeckGLTripListener(Network network, long minTime, long maxTime) { 36 | this.deckGLTrips = new HashMap<>(); 37 | this.network = network; 38 | this.minTime = minTime; 39 | this.maxTime = maxTime; 40 | } 41 | 42 | public Map, List> getDeckGLTripItems() { 43 | return deckGLTrips; 44 | } 45 | 46 | @Override 47 | public void reset(int iteration) { 48 | deckGLTrips.clear(); 49 | } 50 | 51 | @Override 52 | public void handleEvent(LinkEnterEvent event) { 53 | long time = (long) event.getTime(); 54 | 55 | if (minTime <= time && time <= maxTime) { 56 | List trips = deckGLTrips.computeIfAbsent(event.getVehicleId(), k -> new LinkedList<>()); 57 | 58 | Coord location = network.getLinks().get(event.getLinkId()).getFromNode().getCoord(); 59 | trips.add(new DeckGLTripItem(location, time, minTime)); 60 | } 61 | } 62 | 63 | @Override 64 | public void handleEvent(LinkLeaveEvent event) { 65 | long time = (long) event.getTime(); 66 | 67 | if (minTime <= time && time <= maxTime) { 68 | List trips = deckGLTrips.computeIfAbsent(event.getVehicleId(), k -> new LinkedList<>()); 69 | 70 | Coord location = network.getLinks().get(event.getLinkId()).getToNode().getCoord(); 71 | trips.add(new DeckGLTripItem(location, time, minTime)); 72 | } 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/scenario/population/RunAddPopulationAttributes.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.scenario.population; 2 | 3 | import java.util.Random; 4 | 5 | import org.matsim.api.core.v01.Scenario; 6 | import org.matsim.api.core.v01.population.Person; 7 | import org.matsim.api.core.v01.population.Population; 8 | import org.matsim.api.core.v01.population.PopulationWriter; 9 | import org.matsim.core.config.Config; 10 | import org.matsim.core.config.ConfigUtils; 11 | import org.matsim.core.scenario.ScenarioUtils; 12 | 13 | //Adjusted from RunPopulationDownsamplingExample.java by matsim-code-examples 14 | 15 | /** 16 | * This script adds socio-demographic attributes to each person object in an 17 | * existing population (or plan) file. 18 | * 19 | * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) 20 | */ 21 | @Deprecated 22 | public class RunAddPopulationAttributes { 23 | 24 | private double carOwnsershipPercent = 0.75; 25 | private double ptSubscriptionOwnsershipPercent = 0.75; 26 | private double bikeOwnsershipPercent = 0.95; 27 | private double employedPercent = 0.95; 28 | 29 | public static void main(final String[] args) { 30 | RunAddPopulationAttributes app = new RunAddPopulationAttributes(); 31 | app.run(args); 32 | } 33 | 34 | void run(final String[] args) { 35 | // ARGS: population 36 | String inputPopFilename = args[0]; 37 | Config config = ConfigUtils.createConfig(); 38 | config.plans().setInputFile(inputPopFilename); 39 | 40 | Scenario scenario = ScenarioUtils.createScenario(config); 41 | ScenarioUtils.loadScenario(scenario); 42 | 43 | Population pop = scenario.getPopulation(); 44 | for (Person p : pop.getPersons().values()) { 45 | p.getAttributes().putAttribute("age", 30); 46 | p.getAttributes().putAttribute("employed", new Random().nextDouble() < employedPercent); 47 | p.getAttributes().putAttribute("ptSubscription", 48 | new Random().nextDouble() < ptSubscriptionOwnsershipPercent); 49 | p.getAttributes().putAttribute("sex", new Random().nextBoolean() ? "m" : "f"); 50 | p.getAttributes().putAttribute("bikeAvailability", 51 | new Random().nextDouble() < bikeOwnsershipPercent ? "always" : "never"); 52 | 53 | double rand = new Random().nextDouble(); 54 | p.getAttributes().putAttribute("hasLicense", rand < carOwnsershipPercent ? "true" : "false"); // excepted as 55 | // string 56 | // instead 57 | // of 58 | // boolean 59 | p.getAttributes().putAttribute("carAvailability", rand < carOwnsershipPercent ? "always" : "never"); 60 | } 61 | 62 | // add pax to total pop and print new population file 63 | PopulationWriter popwriter = new PopulationWriter(pop); 64 | String[] inputPop = inputPopFilename.split(".xml"); 65 | popwriter.write(inputPop[0] + "_added_attrs.xml" + inputPop[1]); 66 | 67 | System.out.println("done."); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/analysis/linkspeed/UAMLinkTravelSpeedHandler.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.analysis.linkspeed; 2 | 3 | import net.bhl.matsim.uam.run.UAMConstants; 4 | import org.matsim.api.core.v01.Id; 5 | import org.matsim.api.core.v01.events.LinkEnterEvent; 6 | import org.matsim.api.core.v01.events.LinkLeaveEvent; 7 | import org.matsim.api.core.v01.events.PersonDepartureEvent; 8 | import org.matsim.api.core.v01.events.handler.LinkEnterEventHandler; 9 | import org.matsim.api.core.v01.events.handler.LinkLeaveEventHandler; 10 | import org.matsim.api.core.v01.events.handler.PersonDepartureEventHandler; 11 | import org.matsim.api.core.v01.network.Link; 12 | import org.matsim.api.core.v01.network.Network; 13 | import org.matsim.vehicles.Vehicle; 14 | 15 | import java.io.FileWriter; 16 | import java.io.IOException; 17 | import java.util.HashMap; 18 | import java.util.Map; 19 | 20 | public class UAMLinkTravelSpeedHandler implements LinkEnterEventHandler, 21 | LinkLeaveEventHandler, PersonDepartureEventHandler { 22 | 23 | private Map,Double> enteredLinks = new HashMap<>() ; 24 | private Network network; 25 | private FileWriter fw; 26 | 27 | public UAMLinkTravelSpeedHandler(Network network, FileWriter writer) { 28 | this.network = network; 29 | this.fw = writer; 30 | 31 | try { 32 | fw.write("Time,Link,Length,Freespeed,Vehicle,ActualTime,ActualSpeed\n"); 33 | } catch (IOException e) { 34 | e.printStackTrace(); 35 | } 36 | } 37 | 38 | @Override 39 | public void reset(int iteration) { 40 | this.enteredLinks.clear(); 41 | } 42 | 43 | @Override 44 | public void handleEvent(LinkEnterEvent event) { 45 | if(event.getVehicleId().toString().contains(UAMConstants.uam)) 46 | this.enteredLinks.put(event.getVehicleId(), event.getTime()); 47 | } 48 | 49 | @Override 50 | public void handleEvent(LinkLeaveEvent event) { 51 | if(this.enteredLinks.containsKey(event.getVehicleId())) { 52 | Link link = network.getLinks().get(event.getLinkId()); 53 | double actTime = event.getTime() - this.enteredLinks.get(event.getVehicleId()); 54 | double actSpeed = link.getLength() / actTime; 55 | try { 56 | fw.write(event.getTime() + "," 57 | + event.getLinkId() + "," 58 | + link.getLength() + "," 59 | + link.getFreespeed() + "," 60 | + event.getVehicleId() + "," 61 | + actTime + "," 62 | + actSpeed + "\n"); 63 | } catch (IOException e) { 64 | e.printStackTrace(); 65 | } 66 | } 67 | } 68 | 69 | @Override 70 | public void handleEvent(PersonDepartureEvent event) { 71 | Id vehId = Id.create(event.getPersonId(), Vehicle.class); 72 | this.enteredLinks.put(vehId, event.getTime()); 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/qsim/UAMTripInfo.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.qsim; 2 | 3 | import java.util.Collections; 4 | import java.util.Map; 5 | 6 | import org.matsim.api.core.v01.network.Link; 7 | import org.matsim.api.core.v01.population.Route; 8 | import org.matsim.core.mobsim.framework.MobsimPassengerAgent; 9 | import org.matsim.core.mobsim.qsim.interfaces.TripInfoWithRequiredBooking; 10 | import org.matsim.core.router.LinkWrapperFacility; 11 | import org.matsim.facilities.Facility; 12 | 13 | import net.bhl.matsim.uam.run.UAMConstants; 14 | 15 | public class UAMTripInfo implements TripInfoWithRequiredBooking { 16 | private final BookedRequest request; 17 | 18 | public UAMTripInfo(Link fromLink, Link toLink, Route route, double departureTime) { 19 | this.request = new BookedRequest(fromLink, toLink, route, departureTime); 20 | } 21 | 22 | @Override 23 | public Facility getPickupLocation() { 24 | return request.getFromFacility(); 25 | } 26 | 27 | @Override 28 | public Facility getDropoffLocation() { 29 | return request.getToFacility(); 30 | } 31 | 32 | @Override 33 | public double getExpectedBoardingTime() { 34 | return request.getTime(); 35 | } 36 | 37 | @Override 38 | public double getExpectedTravelTime() { 39 | return request.getPlannedRoute().getTravelTime().seconds(); 40 | } 41 | 42 | @Override 43 | public double getMonetaryPrice() { 44 | return 0.0; 45 | } 46 | 47 | @Override 48 | public Map getAdditionalAttributes() { 49 | return Collections.emptyMap(); 50 | } 51 | 52 | @Override 53 | public String getMode() { 54 | return UAMConstants.uam; 55 | } 56 | 57 | @Override 58 | public double getLatestDecisionTime() { 59 | return 0.0; 60 | } 61 | 62 | @Override 63 | public Request getOriginalRequest() { 64 | return request; 65 | } 66 | 67 | @Override 68 | public void bookTrip(MobsimPassengerAgent agent) { 69 | throw new IllegalStateException(); 70 | } 71 | 72 | static public class BookedRequest implements Request { 73 | private final Link fromLink; 74 | private final Link toLink; 75 | private final Route route; 76 | private final double departureTime; 77 | 78 | public BookedRequest(Link fromLink, Link toLink, Route route, double departureTime) { 79 | this.fromLink = fromLink; 80 | this.toLink = toLink; 81 | this.route = route; 82 | this.departureTime = departureTime; 83 | } 84 | 85 | @Override 86 | public Facility getFromFacility() { 87 | return new LinkWrapperFacility(fromLink); 88 | } 89 | 90 | @Override 91 | public Facility getToFacility() { 92 | return new LinkWrapperFacility(toLink); 93 | } 94 | 95 | @Override 96 | public double getTime() { 97 | return departureTime; 98 | } 99 | 100 | @Override 101 | public TimeInterpretation getTimeInterpretation() { 102 | return TimeInterpretation.departure; 103 | } 104 | 105 | @Override 106 | public Route getPlannedRoute() { 107 | return route; 108 | } 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/scenario/population/RunSamplePopulation.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.scenario.population; 2 | 3 | import org.matsim.api.core.v01.Scenario; 4 | import org.matsim.api.core.v01.population.Person; 5 | import org.matsim.api.core.v01.population.Population; 6 | import org.matsim.api.core.v01.population.PopulationWriter; 7 | import org.matsim.core.config.Config; 8 | import org.matsim.core.config.ConfigUtils; 9 | import org.matsim.core.scenario.ScenarioUtils; 10 | 11 | //Adjusted from RunPopulationDownsamplingExample.java by matsim-code-examples 12 | 13 | /** 14 | * This script generates a new population file based on a given population file 15 | * and a percentage. The new population file is a fraction of the original 16 | * population file based on the percentage value provided. 17 | * 18 | * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) 19 | */ 20 | @Deprecated 21 | public class RunSamplePopulation { 22 | public static void main(final String[] args) { 23 | RunSamplePopulation app = new RunSamplePopulation(); 24 | app.run(args); 25 | } 26 | 27 | void run(final String[] args) { 28 | String inputPopFilename = null; 29 | String outputPopFilename = null; 30 | String netFilename = null; 31 | double percentage = 0.1; 32 | 33 | if (args != null) { 34 | if (!(args.length == 3 || args.length == 4)) { 35 | System.err.println("Usage: cmd inputPop.xml.gz outputPop.xml.gz 0.X [network.xml.gz]"); 36 | } else { 37 | inputPopFilename = args[0]; 38 | outputPopFilename = args[1]; 39 | percentage = Double.parseDouble(args[2]); 40 | 41 | if (args.length == 4) { 42 | netFilename = args[3]; 43 | } 44 | } 45 | } 46 | 47 | Config config = ConfigUtils.createConfig(); 48 | config.plans().setInputFile(inputPopFilename); 49 | if (args.length == 4) 50 | config.network().setInputFile(netFilename); 51 | 52 | Scenario scenario = ScenarioUtils.createScenario(config); 53 | ScenarioUtils.loadScenario(scenario); 54 | 55 | Population pop = scenario.getPopulation(); 56 | 57 | Scenario newScenario = ScenarioUtils.createScenario(ConfigUtils.createConfig()); 58 | ScenarioUtils.loadScenario(newScenario); 59 | 60 | Population newPop = newScenario.getPopulation(); 61 | 62 | // if input percentage is >0 (i.e. not a percentage but a defined number of 63 | // agents to sub-sample) 64 | if (percentage > 1) { 65 | double totalPop = pop.getPersons().values().size(); 66 | percentage = percentage / totalPop; 67 | System.err.println("Adjusting percentage to: " + percentage + System.lineSeparator()); 68 | } 69 | 70 | for (Person person : pop.getPersons().values()) { 71 | if (Math.random() < percentage) { 72 | newPop.addPerson(person); 73 | } 74 | } 75 | 76 | PopulationWriter popwriter; 77 | if (args.length == 4) 78 | popwriter = new PopulationWriter(newPop, ScenarioUtils.loadScenario(config).getNetwork()); 79 | else 80 | popwriter = new PopulationWriter(newPop); 81 | 82 | popwriter.write(outputPopFilename); 83 | 84 | System.out.println("done."); 85 | } 86 | 87 | } 88 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/analysis/uamdemand/CSVUAMDemandWriter.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.analysis.uamdemand; 2 | 3 | import net.bhl.matsim.uam.run.UAMConstants; 4 | 5 | import java.io.BufferedWriter; 6 | import java.io.FileOutputStream; 7 | import java.io.IOException; 8 | import java.io.OutputStreamWriter; 9 | import java.util.Collection; 10 | import java.util.HashSet; 11 | 12 | /** 13 | * This class writes a CSV file containing UAMDemand data. 14 | * 15 | * @author Aitanm (Aitan Militao), RRothfeld (Raoul Rothfeld) 16 | */ 17 | public class CSVUAMDemandWriter { 18 | final private HashSet uamData; 19 | final private String delimiter; 20 | 21 | public CSVUAMDemandWriter(Collection uamData) { 22 | this(uamData, ","); 23 | } 24 | 25 | public CSVUAMDemandWriter(Collection uamData, String delimiter) { 26 | this.uamData = new HashSet<>(uamData); 27 | this.delimiter = delimiter; 28 | } 29 | 30 | public void write(String outputPath) throws IOException { 31 | BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outputPath))); 32 | writer.write(formatHeader() + "\n"); 33 | writer.flush(); 34 | for (UAMDemandItem data : uamData) { 35 | writer.write(formatData(data) + "\n"); 36 | writer.flush(); 37 | } 38 | writer.flush(); 39 | writer.close(); 40 | } 41 | 42 | private String formatHeader() { 43 | return String.join(delimiter, 44 | new String[]{"personId", "originCoordX", "originCoordY", "originStationCoordX", "originStationCoordY", 45 | "destinationStationCoordX", "destinationStationCoordY", "destinationCoordX", 46 | "destinationCoordY", "startTime", "arrivalAtStationTime", "takeOffTime", "landingTime", 47 | "departureFromStationTime", "endTime", "vehicleId", "originStationId", "destinationStationId", 48 | "accessMode", "egressMode", UAMConstants.uam + "Trip"}); 49 | } 50 | 51 | private String formatData(UAMDemandItem uamData) { 52 | try { 53 | return String.join(delimiter, 54 | new String[]{uamData.personId.toString(), String.valueOf(uamData.origin.getX()), 55 | String.valueOf(uamData.origin.getY()), String.valueOf(uamData.originStationCoord.getX()), 56 | String.valueOf(uamData.originStationCoord.getY()), 57 | String.valueOf(uamData.destinationStationCoord.getX()), 58 | String.valueOf(uamData.destinationStationCoord.getY()), 59 | String.valueOf(uamData.destination.getX()), String.valueOf(uamData.destination.getY()), 60 | String.valueOf(uamData.startTime), String.valueOf(uamData.arrivalAtStationTime), 61 | String.valueOf(uamData.takeOffTime), String.valueOf(uamData.landingTime), 62 | String.valueOf(uamData.departureFromStationTime), String.valueOf(uamData.endTime), 63 | uamData.vehicleId, uamData.originStationId.toString(), 64 | uamData.destinationStationId.toString(), uamData.accessMode, 65 | uamData.egressMode, String.valueOf(uamData.uamTrip)}); 66 | } catch (Exception ignored) { 67 | } 68 | return UAMConstants.uam + "Data could not be read"; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/infrastructure/UAMVehicle.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.infrastructure; 2 | 3 | import org.matsim.api.core.v01.Id; 4 | import org.matsim.api.core.v01.network.Link; 5 | import org.matsim.contrib.dvrp.fleet.DvrpVehicleImpl; 6 | import org.matsim.contrib.dvrp.fleet.DvrpVehicleSpecification; 7 | 8 | /** 9 | * This class defines the VTOL vehicle and its properties. 10 | * 11 | * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) 12 | */ 13 | public class UAMVehicle extends DvrpVehicleImpl { 14 | 15 | private final Id initialStationId; 16 | private final UAMVehicleType vehicleType; 17 | private double currentCharge; 18 | 19 | public UAMVehicle(DvrpVehicleSpecification specification, Link startLink, Id stationId, 20 | UAMVehicleType vehicleType) { 21 | super(specification, startLink); 22 | this.initialStationId = stationId; 23 | this.vehicleType = vehicleType; 24 | this.setCurrentCharge(this.vehicleType.getMaximumCharge()); 25 | } 26 | 27 | public Id getInitialStationId() { 28 | return initialStationId; 29 | } 30 | 31 | public double getRange() { 32 | return vehicleType.getRange(); 33 | } 34 | 35 | /** 36 | * This method is used to retrieve the vehicle cruise speed during level flight. 37 | * 38 | * @return vehicle cruise speed in meter/second 39 | */ 40 | public double getCruiseSpeed() { 41 | return vehicleType.getCruiseSpeed(); 42 | } 43 | 44 | /** 45 | * This method is used to retrieve the vehicle vertical speed during take-off 46 | * and landing. 47 | * 48 | * @return vehicle vertical speed in meter/second 49 | */ 50 | public double getVerticalSpeed() { 51 | return vehicleType.getVerticalSpeed(); 52 | } 53 | 54 | /** 55 | * This method is used to retrieve the Time for the passenger to board in the 56 | * aircraft in seconds. Used in the UAMPickUpTask. 57 | * 58 | * @return the passenger boarding time in the aircraft 59 | */ 60 | public double getBoardingTime() { 61 | return vehicleType.getboardingTime(); 62 | } 63 | 64 | /** 65 | * This method is used to retrieve the Time for the passenger to board off from 66 | * the aircraft in seconds. Used in the UAMDropOffTask. 67 | * 68 | * @return the passenger deboarding time in from the aircraft 69 | */ 70 | public double getDeboardingTime() { 71 | return vehicleType.getDeboardingTime(); 72 | } 73 | 74 | /** 75 | * This method is used to retrieve the Time needed for the UAM Vehicle to 76 | * perform the TurnAroundTask (unavailable for other trips after 77 | * landing) 78 | * 79 | * @return the UAM Vehicle turn around time (time unavailable for other trips 80 | * after landing) 81 | */ 82 | public double getTurnAroundTime() { 83 | return vehicleType.getTurnAroundTime(); 84 | } 85 | 86 | public UAMVehicleType getVehicleType() { 87 | return this.vehicleType; 88 | } 89 | 90 | public double getCurrentCharge() { 91 | return currentCharge; 92 | } 93 | 94 | public void setCurrentCharge(double currentCharge) { 95 | this.currentCharge = currentCharge; 96 | } 97 | 98 | } 99 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/listeners/UAMListener.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.listeners; 2 | 3 | import java.io.BufferedWriter; 4 | import java.io.IOException; 5 | import java.util.ArrayList; 6 | import java.util.Map; 7 | import java.util.Set; 8 | 9 | import org.matsim.api.core.v01.Id; 10 | import org.matsim.api.core.v01.population.Person; 11 | import org.matsim.core.controler.events.IterationEndsEvent; 12 | import org.matsim.core.controler.listener.IterationEndsListener; 13 | import org.matsim.core.utils.io.IOUtils; 14 | 15 | import com.google.inject.Inject; 16 | 17 | import net.bhl.matsim.uam.analysis.uamdemand.listeners.ChargingItem; 18 | import net.bhl.matsim.uam.analysis.uamdemand.listeners.UAMChargingHandler; 19 | import net.bhl.matsim.uam.events.UAMData; 20 | import net.bhl.matsim.uam.events.UAMDemand; 21 | import net.bhl.matsim.uam.run.UAMConstants; 22 | 23 | /** 24 | * This class provides output for the uam usage. 25 | * 26 | * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) 27 | */ 28 | public class UAMListener implements IterationEndsListener { 29 | 30 | @Inject 31 | UAMDemand uamDemand; 32 | 33 | @Inject 34 | UAMChargingHandler uamChargingDemand; 35 | 36 | @Override 37 | public void notifyIterationEnds(IterationEndsEvent event) { 38 | // UAMDemand 39 | Map, ArrayList> data = this.uamDemand.getDemand(); 40 | BufferedWriter writer = IOUtils.getBufferedWriter(event.getServices().getControlerIO() 41 | .getIterationFilename(event.getIteration(), UAMConstants.uam + "demand.csv")); 42 | 43 | try { 44 | writer.write( 45 | "peronId,originCoordX,originCoordY,originStationCoordX,originStationCoordY,destinationStationCoordX," 46 | + "destinationStationCoordY,destinationCoordX,destinationCoordY,startTime,arrivalAtStationTime,takeOffTime," 47 | + "landingTime,departureFromStationTime,endTime,vehicleId,originStationId,destinationStationId,accessMode," 48 | + "egressMode,uamTrip"); 49 | writer.newLine(); 50 | for (Id personId : data.keySet()) { 51 | for (UAMData d : data.get(personId)) { 52 | writer.write(personId.toString() + ","); 53 | writer.write(d.toString()); 54 | writer.newLine(); 55 | } 56 | } 57 | writer.close(); 58 | 59 | } catch (IOException e) { 60 | e.printStackTrace(); 61 | } 62 | 63 | // UAMChargingDemand 64 | Set chargingData = this.uamChargingDemand.getAllChargingData(); 65 | BufferedWriter writerCharging = IOUtils.getBufferedWriter(event.getServices().getControlerIO() 66 | .getIterationFilename(event.getIteration(), UAMConstants.uam + "charging.csv")); 67 | 68 | try { 69 | writerCharging.write("vehicleid,queueingstart,chargingstart,chargingend,stationid"); 70 | writerCharging.newLine(); 71 | 72 | for (ChargingItem d : chargingData) { 73 | writerCharging.write(String.join(",", d.vehicleId, Double.toString(d.startingTime), 74 | Double.toString(d.startingCharge), Double.toString(d.endTime), d.stationId)); 75 | writerCharging.newLine(); 76 | 77 | } 78 | writerCharging.close(); 79 | 80 | } catch (IOException e) { 81 | e.printStackTrace(); 82 | } 83 | 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/router/UAMRoutingModuleProvider.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.router; 2 | 3 | import java.util.Map; 4 | 5 | import org.matsim.api.core.v01.Scenario; 6 | import org.matsim.api.core.v01.TransportMode; 7 | import org.matsim.api.core.v01.network.Network; 8 | import org.matsim.core.router.RoutingModule; 9 | import org.matsim.core.router.costcalculators.TravelDisutilityFactory; 10 | import org.matsim.core.router.util.LeastCostPathCalculator; 11 | import org.matsim.core.router.util.LeastCostPathCalculatorFactory; 12 | import org.matsim.core.router.util.TravelDisutility; 13 | import org.matsim.core.router.util.TravelTime; 14 | import org.matsim.pt.config.TransitConfigGroup; 15 | import org.matsim.pt.router.TransitRouter; 16 | 17 | import com.google.inject.Inject; 18 | import com.google.inject.Provider; 19 | import com.google.inject.name.Named; 20 | 21 | import net.bhl.matsim.uam.config.UAMConfigGroup; 22 | import net.bhl.matsim.uam.data.UAMStationConnectionGraph; 23 | import net.bhl.matsim.uam.data.WaitingStationData; 24 | import net.bhl.matsim.uam.dispatcher.UAMManager; 25 | import net.bhl.matsim.uam.run.UAMConstants; 26 | 27 | /** 28 | * This class provides the routing module for UAM mode. 29 | * 30 | * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) 31 | */ 32 | public class UAMRoutingModuleProvider implements Provider { 33 | 34 | @Inject 35 | @Named("uam_car") 36 | Network networkCar; 37 | @Inject(optional = true) 38 | @Named(TransportMode.pt) 39 | RoutingModule transitRouting; 40 | @Inject 41 | private Scenario scenario; 42 | @Inject 43 | private UAMManager uamManager; 44 | @Inject 45 | @Named(UAMConstants.uam) 46 | private LeastCostPathCalculator uamPathCalculator; 47 | @Inject 48 | private LeastCostPathCalculatorFactory lcpcf; 49 | @Inject 50 | private Map travelTimes; 51 | @Inject 52 | private Map travelDisutilityFactories; 53 | @Inject 54 | private UAMConfigGroup uamConfig; 55 | @Inject 56 | private TransitConfigGroup transitConfig; 57 | @Inject(optional = true) 58 | private TransitRouter transitRouter; 59 | @Inject 60 | private WaitingStationData waitingData; 61 | 62 | @Inject 63 | private UAMStationConnectionGraph stationConnectionutilities; 64 | 65 | @Override 66 | public RoutingModule get() { 67 | TravelTime travelTime = travelTimes.get(TransportMode.car); 68 | 69 | TravelDisutility travelDisutility = travelDisutilityFactories.get(TransportMode.car) 70 | .createTravelDisutility(travelTime); 71 | 72 | LeastCostPathCalculator pathCalculator = lcpcf.createPathCalculator(networkCar, travelDisutility, travelTime); 73 | 74 | if (scenario.getConfig().transit().isUseTransit()) { 75 | return new UAMCachedIntermodalRoutingModule(scenario, uamManager.getStations(), uamPathCalculator, pathCalculator, 76 | networkCar, transitRouter, uamConfig, transitConfig, transitRouting, waitingData, 77 | stationConnectionutilities); 78 | } else { 79 | return new UAMCachedIntermodalRoutingModule(scenario, uamManager.getStations(), uamPathCalculator, pathCalculator, 80 | networkCar, uamConfig, transitConfig, waitingData, stationConnectionutilities); 81 | } 82 | } 83 | } -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 4 | 4.0.0 5 | 6 | net.bhl.matsim 7 | matsim-uam 8 | 5.0.0 9 | jar 10 | 11 | 12 | UTF-8 13 | 2024.0 14 | 21 15 | 21 16 | 17 | 18 | 19 | 20 | packagecloud-uam 21 | packagecloud+https://packagecloud.io/eth-ivt/uam 22 | 23 | 24 | 25 | 26 | 27 | 28 | maven-assembly-plugin 29 | 30 | 31 | 32 | net.bhl.matsim.uam.run.RunUAMScenario 33 | 34 | 35 | 36 | jar-with-dependencies 37 | 38 | 39 | 40 | 41 | make-assembly 42 | package 43 | 44 | single 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | io.packagecloud.maven.wagon 53 | maven-packagecloud-wagon 54 | 0.0.6 55 | 56 | 57 | 58 | 59 | 60 | 61 | matsim 62 | MATSim Maven repository 63 | https://repo.matsim.org/repository/matsim/ 64 | 65 | 66 | osgeo 67 | Geotools repository 68 | https://repo.osgeo.org/repository/release/ 69 | 70 | 71 | 72 | 73 | 74 | commons-io 75 | commons-io 76 | 2.7 77 | 78 | 79 | org.matsim 80 | matsim 81 | ${matsim.version} 82 | 83 | 84 | org.matsim.contrib 85 | dvrp 86 | ${matsim.version} 87 | 88 | 89 | org.matsim.contrib 90 | discrete_mode_choice 91 | ${matsim.version} 92 | 93 | 94 | org.matsim.contrib 95 | common 96 | ${matsim.version} 97 | 98 | 99 | junit 100 | junit 101 | 4.13.1 102 | test 103 | 104 | 105 | 106 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/analysis/traffic/run/ConvertLinkStatsFromEvents.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.analysis.traffic.run; 2 | 3 | import net.bhl.matsim.uam.analysis.traffic.CSVLinkStatsWriter; 4 | import net.bhl.matsim.uam.analysis.traffic.LinkStatsItem; 5 | import org.matsim.api.core.v01.TransportMode; 6 | import org.matsim.api.core.v01.network.Link; 7 | import org.matsim.api.core.v01.network.Network; 8 | import org.matsim.core.api.experimental.events.EventsManager; 9 | import org.matsim.core.config.groups.TravelTimeCalculatorConfigGroup; 10 | import org.matsim.core.events.EventsReaderXMLv1; 11 | import org.matsim.core.events.EventsUtils; 12 | import org.matsim.core.network.NetworkUtils; 13 | import org.matsim.core.network.io.MatsimNetworkReader; 14 | import org.matsim.core.router.util.TravelTime; 15 | import org.matsim.core.trafficmonitoring.TravelTimeCalculator; 16 | 17 | import java.io.IOException; 18 | import java.util.*; 19 | 20 | /** 21 | * This script generates a csv file containing the average speed per link per 22 | * hour of the input network from an output simulation events file. trips 23 | * performed from an events output file. Necessary inputs are in the following 24 | * order: -Network file; -Events file; -output file; 25 | * 26 | * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) 27 | */ 28 | public class ConvertLinkStatsFromEvents { 29 | 30 | static int timeBinSize = 3600; 31 | static int maxTime = 30 * 3600; 32 | static boolean calculateLinkTravelTimes = true; 33 | static boolean calculateLinkToLinkTravelTimes = false; 34 | static boolean filterModes = true; 35 | static String[] analyzedModes = {TransportMode.car}; 36 | 37 | static public void main(String[] args) throws IOException { 38 | // PROVIDE: NETWORK EVENTS OUTFILE-NAME 39 | extract(args[0], args[1], args[2]); 40 | System.out.println("done."); 41 | } 42 | 43 | static public void extract(String network, String events, String outfile) throws IOException { 44 | Network netw = NetworkUtils.createNetwork(); 45 | new MatsimNetworkReader(netw).readFile(network); 46 | 47 | TravelTimeCalculatorConfigGroup tconfig = new TravelTimeCalculatorConfigGroup(); 48 | 49 | Set modes = new HashSet<>(Arrays.asList(analyzedModes)); 50 | tconfig.setAnalyzedModes(modes); 51 | tconfig.setFilterModes(filterModes); 52 | 53 | tconfig.setCalculateLinkToLinkTravelTimes(calculateLinkToLinkTravelTimes); 54 | tconfig.setCalculateLinkTravelTimes(calculateLinkTravelTimes); 55 | 56 | tconfig.setMaxTime(maxTime); 57 | tconfig.setTraveltimeBinSize(timeBinSize); 58 | 59 | TravelTimeCalculator.Builder builder = new TravelTimeCalculator.Builder(netw); 60 | builder.configure(tconfig); 61 | TravelTimeCalculator ttc = builder.build(); 62 | 63 | EventsManager manager = EventsUtils.createEventsManager(); 64 | manager.addHandler(ttc); 65 | EventsReaderXMLv1 eventsReader = new EventsReaderXMLv1(manager); 66 | eventsReader.readFile(events); 67 | 68 | Collection linkStats = new HashSet<>(); 69 | TravelTime tts = ttc.getLinkTravelTimes(); 70 | for (Link link : netw.getLinks().values()) { 71 | Map timeDependantSpeeds = new HashMap<>(); 72 | for (int time = timeBinSize / 2; time < maxTime; time += timeBinSize) { 73 | timeDependantSpeeds.put(time, link.getLength() / tts.getLinkTravelTime(link, time, null, null)); 74 | } 75 | 76 | linkStats.add(new LinkStatsItem(link.getId(), link.getLength(), link.getFreespeed(), timeDependantSpeeds)); 77 | } 78 | 79 | new CSVLinkStatsWriter(linkStats).write(outfile); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/passenger/UAMRequest.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.passenger; 2 | 3 | import java.util.List; 4 | 5 | import org.matsim.api.core.v01.Id; 6 | import org.matsim.api.core.v01.network.Link; 7 | import org.matsim.api.core.v01.population.Person; 8 | import org.matsim.contrib.dvrp.optimizer.Request; 9 | import org.matsim.contrib.dvrp.passenger.PassengerRequest; 10 | 11 | import net.bhl.matsim.uam.dispatcher.UAMDispatcher; 12 | import net.bhl.matsim.uam.run.UAMConstants; 13 | import net.bhl.matsim.uam.schedule.UAMDropoffTask; 14 | import net.bhl.matsim.uam.schedule.UAMPickupTask; 15 | 16 | /** 17 | * This class defines the UAM Request and its properties. 18 | * 19 | * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) 20 | */ 21 | public class UAMRequest implements PassengerRequest { 22 | final private Id id; 23 | final private double submissionTime; 24 | final private Link originLink; 25 | final private Link destinationLink; 26 | final private List> passengerIds; 27 | private final double quantity; 28 | private final double earliestStartTime; 29 | private final double latestStartTime; 30 | private UAMDropoffTask dropoffTask; 31 | private UAMPickupTask pickupTask; 32 | private UAMDispatcher dispatcher; 33 | private double distance; 34 | 35 | public UAMRequest(Id id, List> passengerIds, Link originLink, Link destinationLink, double pickupTime, 36 | double submissionTime, UAMDispatcher dispatcher, double distance) { 37 | this.id = id; 38 | this.submissionTime = submissionTime; 39 | this.quantity = 1.0; 40 | this.originLink = originLink; 41 | this.destinationLink = destinationLink; 42 | this.earliestStartTime = pickupTime; 43 | this.latestStartTime = pickupTime; 44 | this.passengerIds = passengerIds; 45 | this.dispatcher = dispatcher; 46 | this.distance = distance; 47 | } 48 | 49 | public double getQuantity() { 50 | return this.quantity; 51 | } 52 | 53 | @Override 54 | public double getEarliestStartTime() { 55 | return this.earliestStartTime; 56 | } 57 | 58 | @Override 59 | public double getLatestStartTime() { 60 | return this.latestStartTime; 61 | } 62 | 63 | @Override 64 | public double getSubmissionTime() { 65 | return this.submissionTime; 66 | } 67 | 68 | @Override 69 | public Id getId() { 70 | return this.id; 71 | } 72 | 73 | @Override 74 | public List> getPassengerIds() { 75 | return passengerIds; 76 | } 77 | 78 | @Override 79 | public Link getFromLink() { 80 | return this.originLink; 81 | } 82 | 83 | @Override 84 | public Link getToLink() { 85 | return this.destinationLink; 86 | } 87 | 88 | @Override 89 | public String getMode() { 90 | return UAMConstants.uam; 91 | } 92 | 93 | public UAMDropoffTask getDropoffTask() { 94 | return dropoffTask; 95 | } 96 | 97 | public void setDropoffTask(UAMDropoffTask dropoffTask) { 98 | this.dropoffTask = dropoffTask; 99 | } 100 | 101 | public UAMPickupTask getPickupTask() { 102 | return pickupTask; 103 | } 104 | 105 | public void setPickupTask(UAMPickupTask pickupTask) { 106 | this.pickupTask = pickupTask; 107 | } 108 | 109 | public UAMDispatcher getDispatcher() { 110 | return dispatcher; 111 | } 112 | 113 | public double getDistance() { 114 | return distance; 115 | } 116 | 117 | public void setDistance(double distance) { 118 | this.distance = distance; 119 | } 120 | 121 | @Override 122 | public int getPassengerCount() { 123 | return this.passengerIds.size(); 124 | } 125 | 126 | } 127 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/dispatcher/UAMManager.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.dispatcher; 2 | 3 | import java.util.HashMap; 4 | import java.util.HashSet; 5 | import java.util.Map; 6 | import java.util.Set; 7 | 8 | import org.matsim.api.core.v01.Id; 9 | import org.matsim.api.core.v01.network.Link; 10 | import org.matsim.api.core.v01.network.Network; 11 | import org.matsim.api.core.v01.population.Person; 12 | import org.matsim.contrib.dvrp.fleet.DvrpVehicle; 13 | import org.matsim.core.controler.events.IterationStartsEvent; 14 | import org.matsim.core.controler.listener.IterationStartsListener; 15 | import org.matsim.core.network.NetworkUtils; 16 | import org.matsim.core.utils.collections.QuadTree; 17 | 18 | import net.bhl.matsim.uam.infrastructure.UAMStation; 19 | import net.bhl.matsim.uam.infrastructure.UAMStations; 20 | import net.bhl.matsim.uam.infrastructure.UAMVehicle; 21 | 22 | /** 23 | * A class that stores information about UAM infrastructure and manages its 24 | * changes. 25 | * 26 | * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) 27 | */ 28 | 29 | public class UAMManager implements IterationStartsListener { 30 | 31 | public QuadTree mapAvailableVehicles; 32 | private Set availableVehicles = new HashSet<>(); 33 | private Map, Id> vehicleLocations = new HashMap<>(); 34 | 35 | private UAMStations stations; 36 | private QuadTree stationsTree; 37 | private Map, UAMVehicle> vehicles = new HashMap<>(); 38 | private Map, Double> chargeVehicle = new HashMap<>(); 39 | 40 | private Network network; 41 | 42 | public UAMManager(Network network, UAMStations stations, Map, UAMVehicle> vehicles) { 43 | this.network = network; 44 | this.stations = stations; 45 | this.vehicles = vehicles; 46 | for (UAMVehicle uamVehicle : vehicles.values()) { 47 | chargeVehicle.put(uamVehicle.getId(), uamVehicle.getVehicleType().getMaximumCharge()); 48 | } 49 | } 50 | 51 | public UAMStations getStations() { 52 | return stations; 53 | } 54 | 55 | public Map, UAMVehicle> getVehicles() { 56 | return vehicles; 57 | } 58 | 59 | /** 60 | * Initialize all datasets. 61 | */ 62 | @Override 63 | public void notifyIterationStarts(IterationStartsEvent event) { 64 | double[] bounds = NetworkUtils.getBoundingBox(network.getNodes().values()); // minX, minY, maxX, maxY 65 | 66 | mapAvailableVehicles = new QuadTree<>(bounds[0], bounds[1], bounds[2], bounds[3]); 67 | stationsTree = new QuadTree<>(bounds[0], bounds[1], bounds[2], bounds[3]); 68 | availableVehicles = new HashSet<>(); 69 | 70 | vehicleLocations = new HashMap<>(); 71 | 72 | chargeVehicle.clear(); 73 | 74 | for (UAMStation station : stations.getUAMStations().values()) { 75 | stationsTree.put(station.getLocationLink().getCoord().getX(), station.getLocationLink().getCoord().getY(), 76 | station); 77 | } 78 | 79 | for (UAMVehicle vehicle : vehicles.values()) { 80 | UAMStation station = this.stations.getUAMStations().get((vehicle).getInitialStationId()); 81 | this.vehicleLocations.put(vehicle.getId(), station.getId()); 82 | this.availableVehicles.add(vehicle); 83 | 84 | Link stationLink = station.getLocationLink(); 85 | this.mapAvailableVehicles.put(stationLink.getCoord().getX(), stationLink.getCoord().getY(), vehicle); 86 | } 87 | 88 | for (UAMVehicle uamVehicle : vehicles.values()) { 89 | chargeVehicle.put(uamVehicle.getId(), uamVehicle.getVehicleType().getMaximumCharge()); 90 | } 91 | } 92 | 93 | public Map, Double> getChargeVehicle() { 94 | return chargeVehicle; 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/analysis/uamdemand/listeners/UAMChargingHandler.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.analysis.uamdemand.listeners; 2 | 3 | import java.util.HashMap; 4 | import java.util.HashSet; 5 | import java.util.Map; 6 | import java.util.Set; 7 | 8 | import org.matsim.api.core.v01.Id; 9 | import org.matsim.api.core.v01.Scenario; 10 | import org.matsim.api.core.v01.events.ActivityEndEvent; 11 | import org.matsim.api.core.v01.events.ActivityStartEvent; 12 | import org.matsim.api.core.v01.events.handler.ActivityEndEventHandler; 13 | import org.matsim.api.core.v01.events.handler.ActivityStartEventHandler; 14 | import org.matsim.api.core.v01.network.Link; 15 | 16 | import com.google.inject.Inject; 17 | 18 | import net.bhl.matsim.uam.dispatcher.UAMManager; 19 | import net.bhl.matsim.uam.events.ChargingStartEvent; 20 | import net.bhl.matsim.uam.events.ChargingStartEventHandler; 21 | 22 | /** 23 | * This class should record when the charging happens * 24 | * 25 | * @author balacm 26 | * 27 | */ 28 | public class UAMChargingHandler 29 | implements ActivityStartEventHandler, ActivityEndEventHandler, ChargingStartEventHandler { 30 | 31 | @Inject 32 | private UAMManager uamManager; 33 | @Inject 34 | private Scenario scenario; 35 | private Map mapVehicleChargingInfo = new HashMap<>(); 36 | private Set allChargingData = new HashSet<>(); 37 | 38 | @Override 39 | public void handleEvent(ActivityEndEvent event) { 40 | if (event.getActType().equals("Charging")) { 41 | ChargingItem chargingItem = this.mapVehicleChargingInfo.get(event.getPersonId().toString()); 42 | chargingItem.endTime = event.getTime(); 43 | this.allChargingData.add(chargingItem); 44 | this.mapVehicleChargingInfo.remove(event.getPersonId().toString()); 45 | } 46 | } 47 | 48 | @Override 49 | public void handleEvent(ActivityStartEvent event) { 50 | 51 | if (event.getActType().equals("Charging")) { 52 | if (this.mapVehicleChargingInfo.containsKey(event.getPersonId().toString())) { 53 | Id linkId = event.getLinkId(); 54 | Link link = this.scenario.getNetwork().getLinks().get(linkId); 55 | ChargingItem chargingItem = this.mapVehicleChargingInfo.get(event.getPersonId().toString()); 56 | chargingItem.stationId = this.uamManager.getStations().getNearestUAMStation(link).getId().toString(); 57 | } 58 | else { 59 | Id linkId = event.getLinkId(); 60 | Link link = this.scenario.getNetwork().getLinks().get(linkId); 61 | ChargingItem chargingItem = new ChargingItem(event.getPersonId().toString(), event.getTime(), -1, -1, 62 | this.uamManager.getStations().getNearestUAMStation(link).getId().toString()); 63 | this.mapVehicleChargingInfo.put(event.getPersonId().toString(), chargingItem); 64 | } 65 | } 66 | } 67 | 68 | @Override 69 | public void handleEvent(ChargingStartEvent event) { 70 | 71 | if (this.mapVehicleChargingInfo.get(event.getUamVehicle().getId().toString()) == null) { 72 | 73 | ChargingItem chargingItem = new ChargingItem(event.getUamVehicle().getId().toString(), event.getTime(), -1, event.getTime(), 74 | null); 75 | this.mapVehicleChargingInfo.put(event.getUamVehicle().getId().toString(), chargingItem); 76 | } 77 | else { 78 | ChargingItem chargingItem = this.mapVehicleChargingInfo.get(event.getUamVehicle().getId().toString()); 79 | chargingItem.startingCharge = event.getTime(); 80 | } 81 | 82 | } 83 | 84 | @Override 85 | public void reset(int iteration) { 86 | this.mapVehicleChargingInfo.clear(); 87 | this.allChargingData.clear(); 88 | } 89 | 90 | public Set getAllChargingData() { 91 | return allChargingData; 92 | } 93 | 94 | } 95 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/router/strategy/UAMMinAccessDistanceStrategy.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.router.strategy; 2 | 3 | import net.bhl.matsim.uam.data.UAMAccessOptions; 4 | import net.bhl.matsim.uam.data.UAMRoute; 5 | import net.bhl.matsim.uam.infrastructure.UAMStation; 6 | import org.matsim.api.core.v01.Id; 7 | import org.matsim.api.core.v01.TransportMode; 8 | import org.matsim.api.core.v01.population.Person; 9 | import org.matsim.facilities.Facility; 10 | 11 | import java.util.Collection; 12 | import java.util.Map; 13 | import java.util.Optional; 14 | import java.util.Set; 15 | 16 | /** 17 | * This strategy is used to assign to the passenger a UAMRoute based on the 18 | * minimum travel distance of access to UAM Station and egress from UAM Station. 19 | * 20 | * @author Aitanm (Aitan Militao), RRothfeld (Raoul Rothfeld) 21 | */ 22 | public class UAMMinAccessDistanceStrategy implements UAMStrategy { 23 | private UAMStrategyUtils strategyUtils; 24 | 25 | public UAMMinAccessDistanceStrategy(UAMStrategyUtils strategyUtils) { 26 | this.strategyUtils = strategyUtils; 27 | } 28 | 29 | @Override 30 | public UAMStrategyType getUAMStrategyType() { 31 | return UAMStrategyType.MINACCESSDISTANCE; 32 | } 33 | 34 | @Override 35 | public Optional getRoute(Person person, Facility fromFacility, Facility toFacility, double departureTime) { 36 | UAMStation bestStationOrigin = null, bestStationDestination = null; 37 | Collection stationsOrigin = strategyUtils.getPossibleStations(fromFacility, toFacility); 38 | Collection stationsDestination = strategyUtils.getPossibleStations(toFacility, fromFacility); 39 | Map, UAMAccessOptions> accessRoutesData = strategyUtils.getAccessOptions(true, 40 | stationsOrigin, fromFacility, departureTime); 41 | //access trips 42 | double minAccessDistance = Double.POSITIVE_INFINITY; 43 | for (UAMStation stationOrigin : stationsOrigin) { 44 | if (accessRoutesData.get(stationOrigin.getId()).getShortestAccessDistance() < minAccessDistance) { 45 | bestStationOrigin = stationOrigin; 46 | minAccessDistance = accessRoutesData.get(stationOrigin.getId()).getShortestAccessDistance(); 47 | } 48 | } 49 | 50 | //egress trips 51 | String bestModeEgress = TransportMode.walk; 52 | Set modes = strategyUtils.getModes(); 53 | double minEgressDistance = Double.POSITIVE_INFINITY; 54 | for (UAMStation stationDestination : stationsDestination) { 55 | if (bestStationOrigin == stationDestination) 56 | continue; 57 | 58 | //fly time between stations 59 | double flyTime = strategyUtils.getFlightTime(bestStationOrigin, stationDestination); 60 | //updates departureTime 61 | double currentDepartureTime = departureTime + accessRoutesData.get(bestStationOrigin.getId()).getFastestAccessTime() + flyTime; 62 | for (String mode : modes) { 63 | //Calculates the distance for the egress routes using updated departureTime 64 | double egressDistance = strategyUtils.estimateAccessLeg(false, toFacility, currentDepartureTime, 65 | stationDestination, mode).distance; 66 | 67 | if (egressDistance < minEgressDistance) { 68 | bestStationDestination = stationDestination; 69 | minEgressDistance = egressDistance; 70 | bestModeEgress = mode; 71 | } 72 | } 73 | } 74 | 75 | // TODO: What if non is found? Should return Optional.empty(); 76 | if (bestStationOrigin == null || bestStationDestination == null) 77 | return Optional.empty(); 78 | return Optional.of(new UAMRoute(accessRoutesData.get(bestStationOrigin.getId()).getShortestDistanceMode(), bestStationOrigin, 79 | bestStationDestination, bestModeEgress)); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/vrpagent/UAMActionCreator.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.vrpagent; 2 | 3 | import org.matsim.contrib.dvrp.fleet.DvrpVehicle; 4 | import org.matsim.contrib.dvrp.passenger.PassengerEngine; 5 | import org.matsim.contrib.dvrp.run.DvrpMode; 6 | import org.matsim.contrib.dvrp.schedule.StayTask; 7 | import org.matsim.contrib.dvrp.schedule.Task; 8 | import org.matsim.contrib.dvrp.vrpagent.VrpAgentLogic; 9 | import org.matsim.contrib.dvrp.vrpagent.VrpLegFactory; 10 | import org.matsim.contrib.dynagent.DynAction; 11 | import org.matsim.contrib.dynagent.DynAgent; 12 | import org.matsim.contrib.dynagent.IdleDynActivity; 13 | 14 | import com.google.inject.Inject; 15 | 16 | import net.bhl.matsim.uam.dispatcher.UAMManager; 17 | import net.bhl.matsim.uam.infrastructure.UAMVehicle; 18 | import net.bhl.matsim.uam.passenger.UAMChargingActivity; 19 | import net.bhl.matsim.uam.passenger.UAMPassengerDropoffActivity; 20 | import net.bhl.matsim.uam.passenger.UAMSinglePassengerPerRequestPickupActivity; 21 | import net.bhl.matsim.uam.run.UAMConstants; 22 | import net.bhl.matsim.uam.schedule.UAMChargingTask; 23 | import net.bhl.matsim.uam.schedule.UAMDropoffTask; 24 | import net.bhl.matsim.uam.schedule.UAMPickupTask; 25 | import net.bhl.matsim.uam.schedule.UAMTaskType; 26 | 27 | /** 28 | * Class that is responsible for creating DynAction activities depending on the 29 | * task of the vehicle. 30 | * 31 | * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) 32 | */ 33 | public class UAMActionCreator implements VrpAgentLogic.DynActionCreator { 34 | public static final String PICKUP_ACTIVITY_TYPE = UAMConstants.uam.toUpperCase() + "Pickup"; 35 | public static final String DROPOFF_ACTIVITY_TYPE = UAMConstants.uam.toUpperCase() + "Dropoff"; 36 | public static final String STAY_ACTIVITY_TYPE = UAMConstants.uam.toUpperCase() + "Stay"; 37 | public static final String TURNAROUND_ACTIVITY_TYPE = UAMConstants.uam.toUpperCase() + "TurnAround"; 38 | public static final String TRANSIT_ACTIVITY_TYPE = UAMConstants.uam.toUpperCase() + "Transit"; 39 | public static final String CHARGING_ACTIVITY_TYPE = UAMConstants.uam.toUpperCase() + "Charging"; 40 | 41 | @Inject 42 | @DvrpMode(UAMConstants.uam) 43 | private PassengerEngine passengerEngine; 44 | 45 | @Inject 46 | private VrpLegFactory legCreator; 47 | 48 | @Inject 49 | private UAMManager uamManager; 50 | 51 | @Override 52 | public DynAction createAction(DynAgent dynAgent, DvrpVehicle vehicle, double now) { 53 | Task task = vehicle.getSchedule().getCurrentTask(); 54 | 55 | if (task.getTaskType().equals(UAMTaskType.PICKUP)) { 56 | UAMPickupTask mpt = (UAMPickupTask) task; 57 | return new UAMSinglePassengerPerRequestPickupActivity(passengerEngine, dynAgent, vehicle, mpt, mpt.getRequests(), 58 | mpt.getBoardingTime(), PICKUP_ACTIVITY_TYPE); 59 | } else if (task.getTaskType().equals(UAMTaskType.DROPOFF)) { 60 | UAMDropoffTask mdt = (UAMDropoffTask) task; 61 | return new UAMPassengerDropoffActivity(passengerEngine, dynAgent, vehicle, mdt, mdt.getRequests(), 62 | mdt.getDeboardingTime(), DROPOFF_ACTIVITY_TYPE); 63 | } else if (task.getTaskType().equals(UAMTaskType.FLY)) { 64 | return legCreator.create(vehicle); 65 | } else if (task.getTaskType().equals(UAMTaskType.STAY)) { 66 | return new UAMStayActivity((StayTask) task, STAY_ACTIVITY_TYPE); 67 | } else if (task.getTaskType().equals(UAMTaskType.TURNAROUND)) { 68 | return new IdleDynActivity(TURNAROUND_ACTIVITY_TYPE, task.getEndTime()); 69 | } else if (task.getTaskType().equals(UAMTaskType.CHARGING)) { 70 | return new UAMChargingActivity((UAMChargingTask) task, (UAMVehicle) vehicle, uamManager); 71 | } else { 72 | throw new IllegalStateException(); 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/router/strategy/UAMMinAccessTravelTimeStrategy.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.router.strategy; 2 | 3 | import java.util.Collection; 4 | import java.util.Map; 5 | import java.util.Optional; 6 | import java.util.Set; 7 | 8 | import org.matsim.api.core.v01.Id; 9 | import org.matsim.api.core.v01.TransportMode; 10 | import org.matsim.api.core.v01.population.Person; 11 | import org.matsim.facilities.Facility; 12 | 13 | import net.bhl.matsim.uam.data.UAMAccessLeg; 14 | import net.bhl.matsim.uam.data.UAMAccessOptions; 15 | import net.bhl.matsim.uam.data.UAMRoute; 16 | import net.bhl.matsim.uam.infrastructure.UAMStation; 17 | 18 | /** 19 | * This strategy is used to assign to the passenger the UAMRoute based on the 20 | * minimum travel time to access to UAM Station and egress travel time from UAM 21 | * Station. 22 | * 23 | * @author Aitanm (Aitan Militao), RRothfeld (Raoul Rothfeld) 24 | */ 25 | public class UAMMinAccessTravelTimeStrategy implements UAMStrategy { 26 | private UAMStrategyUtils strategyUtils; 27 | 28 | public UAMMinAccessTravelTimeStrategy(UAMStrategyUtils strategyUtils) { 29 | this.strategyUtils = strategyUtils; 30 | } 31 | 32 | @Override 33 | public UAMStrategyType getUAMStrategyType() { 34 | return UAMStrategyType.MINACCESSTRAVELTIME; 35 | } 36 | 37 | @Override 38 | public Optional getRoute(Person person, Facility fromFacility, Facility toFacility, 39 | double departureTime) { 40 | UAMStation bestStationOrigin = null, bestStationDestination = null; 41 | Collection stationsOrigin = strategyUtils.getPossibleStations(fromFacility, toFacility); 42 | Collection stationsDestination = strategyUtils.getPossibleStations(toFacility, fromFacility); 43 | Map, UAMAccessOptions> accessRoutesData = strategyUtils.getAccessOptions(true, stationsOrigin, 44 | fromFacility, departureTime); 45 | double minAccessTime = Double.POSITIVE_INFINITY; 46 | 47 | for (UAMStation stationOrigin : stationsOrigin) { 48 | if (accessRoutesData.get(stationOrigin.getId()).getFastestAccessTime() < minAccessTime) { 49 | bestStationOrigin = stationOrigin; 50 | minAccessTime = accessRoutesData.get(stationOrigin.getId()).getFastestAccessTime(); 51 | } 52 | } 53 | 54 | if (bestStationOrigin == null) { 55 | return Optional.empty(); 56 | } 57 | 58 | // egress trips 59 | Set modes = strategyUtils.getModes(); 60 | double minEgressTime = Double.POSITIVE_INFINITY; 61 | String bestModeEgress = TransportMode.walk; 62 | for (UAMStation stationDestination : stationsDestination) { 63 | if (bestStationOrigin == stationDestination) 64 | continue; 65 | // fly time between stations 66 | double flyTime = strategyUtils.getFlightTime(bestStationOrigin, stationDestination); 67 | // updates departureTime 68 | double currentDepartureTime = departureTime 69 | + accessRoutesData.get(bestStationOrigin.getId()).getFastestAccessTime() + flyTime; 70 | for (String mode : modes) { 71 | UAMAccessLeg egressLeg = strategyUtils.estimateAccessLeg(false, toFacility, currentDepartureTime, 72 | stationDestination, mode); 73 | if (egressLeg == null) 74 | continue; 75 | double egressTravelTime = egressLeg.travelTime; 76 | if (egressTravelTime < minEgressTime) { 77 | bestStationDestination = stationDestination; 78 | minEgressTime = egressTravelTime; 79 | bestModeEgress = mode; 80 | } 81 | } 82 | } 83 | 84 | if (bestStationDestination == null) { 85 | return Optional.empty(); 86 | } 87 | 88 | return Optional.of(new UAMRoute(accessRoutesData.get(bestStationOrigin.getId()).getFastestTimeMode(), 89 | bestStationOrigin, bestStationDestination, bestModeEgress)); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/analysis/trips/run/ConvertDeckGLTripsFromEvents.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.analysis.trips.run; 2 | 3 | import net.bhl.matsim.uam.analysis.trips.DeckGLTripItem; 4 | import net.bhl.matsim.uam.analysis.trips.listeners.DeckGLTripListener; 5 | import net.bhl.matsim.uam.run.UAMConstants; 6 | import org.matsim.api.core.v01.Id; 7 | import org.matsim.api.core.v01.network.Network; 8 | import org.matsim.core.api.experimental.events.EventsManager; 9 | import org.matsim.core.events.EventsUtils; 10 | import org.matsim.core.events.MatsimEventsReader; 11 | import org.matsim.core.network.NetworkUtils; 12 | import org.matsim.core.network.io.MatsimNetworkReader; 13 | import org.matsim.vehicles.Vehicle; 14 | 15 | import java.io.BufferedWriter; 16 | import java.io.File; 17 | import java.io.FileWriter; 18 | import java.io.IOException; 19 | import java.util.Iterator; 20 | import java.util.List; 21 | import java.util.Map; 22 | 23 | /** 24 | * This script convert events file to deck.gl-readable trips input file. 25 | * Necessary inputs are in the following order: -Network file; -Events file; 26 | * Optional inputs: -EPSG:EPSG-code (Example: EPSG:2154) 27 | * 28 | * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) 29 | */ 30 | public class ConvertDeckGLTripsFromEvents { 31 | 32 | private static String inCRS = "EPSG:2154"; 33 | private static String outCRS = "EPSG:4326"; 34 | private static long deckGLanimationSpeed = 1; 35 | private static long minTime = 21600; 36 | private static long maxTime = minTime + (3600); 37 | 38 | static public void main(String[] args) throws IOException { // PROVIDE: 39 | // NETWORK EVENTS INPUT_CRS* 40 | // * optional 41 | if (args.length == 3) 42 | inCRS = args[2]; 43 | 44 | extract(args[0], args[1]); 45 | System.out.println("done."); 46 | } 47 | 48 | static public void extract(String network, String events) throws IOException { 49 | Network netw = NetworkUtils.createNetwork(); 50 | new MatsimNetworkReader(netw).readFile(network); 51 | 52 | DeckGLTripListener deckGLTripListener = new DeckGLTripListener(netw, minTime, maxTime); 53 | EventsManager eventsManager = EventsUtils.createEventsManager(); 54 | eventsManager.addHandler(deckGLTripListener); 55 | new MatsimEventsReader(eventsManager).readFile(events); 56 | 57 | Map, List> deckGLTrips = deckGLTripListener.getDeckGLTripItems(); 58 | 59 | BufferedWriter bw = null; 60 | try { 61 | File file = new File(events + ".json"); 62 | if (!file.exists()) { 63 | file.createNewFile(); 64 | } 65 | FileWriter fw = new FileWriter(file); 66 | bw = new BufferedWriter(fw); 67 | 68 | bw.write("[" + System.lineSeparator()); 69 | 70 | for (Iterator> it = deckGLTrips.keySet().iterator(); it.hasNext(); ) { 71 | Id id = it.next(); 72 | int vendor = id.toString().contains(UAMConstants.uam) ? 1 : 0; 73 | bw.write("{\"vendor\": " + vendor + ", "); 74 | bw.write("\"segments\": ["); 75 | 76 | for (Iterator itemIter = deckGLTrips.get(id).iterator(); itemIter.hasNext(); ) { 77 | DeckGLTripItem item = itemIter.next(); 78 | bw.write(item.convert(inCRS, outCRS, deckGLanimationSpeed)); 79 | 80 | if (itemIter.hasNext()) 81 | bw.write(","); 82 | } 83 | 84 | bw.write("]}"); 85 | 86 | if (it.hasNext()) 87 | bw.write("," + System.lineSeparator()); 88 | } 89 | 90 | bw.write(System.lineSeparator() + "]"); 91 | } catch (IOException e) { 92 | e.printStackTrace(); 93 | } finally { 94 | try { 95 | if (bw != null) 96 | bw.close(); 97 | } catch (Exception e) { 98 | e.printStackTrace(); 99 | } 100 | } 101 | } 102 | 103 | } -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/router/strategy/UAMMinTravelTimeStrategy.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.router.strategy; 2 | 3 | import net.bhl.matsim.uam.data.UAMAccessLeg; 4 | import net.bhl.matsim.uam.data.UAMAccessOptions; 5 | import net.bhl.matsim.uam.data.UAMRoute; 6 | import net.bhl.matsim.uam.infrastructure.UAMStation; 7 | import org.matsim.api.core.v01.Id; 8 | import org.matsim.api.core.v01.TransportMode; 9 | import org.matsim.api.core.v01.population.Person; 10 | import org.matsim.facilities.Facility; 11 | 12 | import java.util.Collection; 13 | import java.util.Map; 14 | import java.util.Optional; 15 | import java.util.Set; 16 | 17 | /** 18 | * This strategy is used to assign to the passenger a UAMRoute based on the 19 | * minimum total travel time of the route. 20 | * 21 | * @author Aitanm (Aitan Militao), RRothfeld (Raoul Rothfeld) 22 | */ 23 | public class UAMMinTravelTimeStrategy implements UAMStrategy { 24 | private UAMStrategyUtils strategyUtils; 25 | public UAMMinTravelTimeStrategy(UAMStrategyUtils strategyUtils) { 26 | this.strategyUtils = strategyUtils; 27 | } 28 | 29 | @Override 30 | public UAMStrategyType getUAMStrategyType() { 31 | return UAMStrategyType.MINTRAVELTIME; 32 | } 33 | 34 | @Override 35 | public Optional getRoute(Person person, Facility fromFacility, Facility toFacility, double departureTime) { 36 | UAMStation bestStationOrigin = null, bestStationDestination = null; 37 | Collection stationsOrigin = strategyUtils.getPossibleStations(fromFacility, toFacility); 38 | Collection stationsDestination = strategyUtils.getPossibleStations(toFacility, fromFacility); 39 | Map, UAMAccessOptions> accessRoutesData = strategyUtils.getAccessOptions(true, 40 | stationsOrigin, fromFacility, departureTime); 41 | // UAM flight time + access and egress travel time + process times 42 | double minTotalTime = Double.POSITIVE_INFINITY; 43 | Set modes = strategyUtils.getModes(); 44 | String bestModeEgress = TransportMode.walk; 45 | for (UAMStation stationOrigin : stationsOrigin) { 46 | for (UAMStation stationDestination : stationsDestination) { 47 | if (stationOrigin == stationDestination) 48 | continue; 49 | // process times 50 | double process = stationOrigin.getPreFlightTime() + stationDestination.getPostFlightTime(); 51 | // fly time between stations 52 | double flyTime = strategyUtils.getFlightTime(stationOrigin, stationDestination); 53 | // updates departureTime 54 | double currentDepartureTime = departureTime 55 | + accessRoutesData.get(stationOrigin.getId()).getFastestAccessTime() + flyTime + process; 56 | for (String mode : modes) { 57 | // Calculates the time travel for the egress routes 58 | UAMAccessLeg egressLeg = strategyUtils.estimateAccessLeg(false, toFacility, currentDepartureTime, 59 | stationDestination, mode); 60 | if (egressLeg == null) 61 | continue; 62 | double egressTravelTime = egressLeg.travelTime; 63 | // Calculates the minimum total time 64 | double totalTime = accessRoutesData.get(stationOrigin.getId()).getFastestAccessTime() + flyTime 65 | + process + egressTravelTime; 66 | if (totalTime < minTotalTime) { 67 | bestStationOrigin = stationOrigin; 68 | bestStationDestination = stationDestination; 69 | minTotalTime = totalTime; 70 | bestModeEgress = mode; 71 | } 72 | } 73 | } 74 | } 75 | 76 | // TODO: What if non is found? Should return Optional.empty(); 77 | if (bestStationOrigin == null || bestStationDestination == null) 78 | return Optional.empty(); 79 | return Optional.of(new UAMRoute(accessRoutesData.get(bestStationOrigin.getId()).getFastestTimeMode(), bestStationOrigin, 80 | bestStationDestination, bestModeEgress)); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/data/UAMStationConnectionGraph.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.data; 2 | 3 | import static java.lang.Math.min; 4 | 5 | import java.util.HashMap; 6 | import java.util.Map; 7 | 8 | import org.apache.logging.log4j.LogManager; 9 | import org.apache.logging.log4j.Logger; 10 | import org.matsim.api.core.v01.Id; 11 | import org.matsim.api.core.v01.network.Link; 12 | import org.matsim.core.router.util.LeastCostPathCalculator; 13 | import org.matsim.core.router.util.LeastCostPathCalculator.Path; 14 | 15 | import com.google.inject.name.Named; 16 | 17 | import net.bhl.matsim.uam.dispatcher.UAMManager; 18 | import net.bhl.matsim.uam.infrastructure.UAMStation; 19 | import net.bhl.matsim.uam.router.UAMFlightSegments; 20 | import net.bhl.matsim.uam.run.UAMConstants; 21 | 22 | /** 23 | * Class that stores information about UAMStations, such as distances, travel 24 | * times and utilities between stations. 25 | * 26 | * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) 27 | */ 28 | public class UAMStationConnectionGraph { 29 | 30 | final private static Logger log = LogManager.getLogger(UAMStationConnectionGraph.class); 31 | private Map, Map, UAMFlightLeg>> legs; 32 | 33 | public UAMStationConnectionGraph(UAMManager uamManager, 34 | @Named(UAMConstants.uam) LeastCostPathCalculator uamPathCalculator) { 35 | log.info("Calculating travel times and distances between all UAM stations."); 36 | 37 | legs = new HashMap<>(); 38 | 39 | // TODO: For now it assumes there only being one singular UAM vehicle type, 40 | // enhancing this would be part of future work. 41 | double horizontalSpeed = uamManager.getVehicles().entrySet().iterator().next().getValue().getCruiseSpeed(); 42 | double verticalSpeed = uamManager.getVehicles().entrySet().iterator().next().getValue().getVerticalSpeed(); 43 | 44 | for (UAMStation uamStationOrigin : uamManager.getStations().getUAMStations().values()) { 45 | for (UAMStation uamStationDestination : uamManager.getStations().getUAMStations().values()) { 46 | if (uamStationOrigin == uamStationDestination) 47 | continue; 48 | 49 | Path path = uamPathCalculator.calcLeastCostPath(uamStationOrigin.getLocationLink().getFromNode(), 50 | uamStationDestination.getLocationLink().getToNode(), 0.0, null, null); 51 | 52 | if (path == null) { 53 | throw new IllegalStateException(); 54 | } 55 | 56 | double distance = 0; 57 | double travelTime = 0; 58 | 59 | for (Link link : path.links) { 60 | distance += link.getLength(); 61 | 62 | String flightSegment = (String) link.getAttributes().getAttribute(UAMFlightSegments.ATTRIBUTE); 63 | 64 | if (flightSegment == null) 65 | log.error(UAMConstants.uam.toUpperCase() 66 | + " links within the MATSim network do not provide the \"type\" attribute, defining the flight segment."); 67 | 68 | if (flightSegment.equals(UAMFlightSegments.HORIZONTAL)) 69 | travelTime += link.getLength() / min(horizontalSpeed, link.getFreespeed()); 70 | 71 | if (flightSegment.equals(UAMFlightSegments.VERTICAL)) 72 | travelTime += link.getLength() / min(verticalSpeed, link.getFreespeed()); 73 | } 74 | 75 | if (legs.containsKey(uamStationOrigin.getId())) { 76 | this.legs.get(uamStationOrigin.getId()).put(uamStationDestination.getId(), 77 | new UAMFlightLeg(travelTime, distance, path.links)); 78 | } else { 79 | Map, UAMFlightLeg> newEntry = new HashMap<>(); 80 | newEntry.put(uamStationDestination.getId(), new UAMFlightLeg(travelTime, distance, path.links)); 81 | this.legs.put(uamStationOrigin.getId(), newEntry); 82 | } 83 | } 84 | } 85 | } 86 | 87 | public UAMFlightLeg getFlightLeg(Id originStation, Id destinationStation) { 88 | return this.legs.get(originStation).get(destinationStation); 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/router/strategy/UAMMinDistanceStrategy.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.router.strategy; 2 | 3 | import net.bhl.matsim.uam.data.UAMAccessLeg; 4 | import net.bhl.matsim.uam.data.UAMAccessOptions; 5 | import net.bhl.matsim.uam.data.UAMRoute; 6 | import net.bhl.matsim.uam.infrastructure.UAMStation; 7 | import org.matsim.api.core.v01.Id; 8 | import org.matsim.api.core.v01.TransportMode; 9 | import org.matsim.api.core.v01.population.Person; 10 | import org.matsim.facilities.Facility; 11 | 12 | import java.util.Collection; 13 | import java.util.Map; 14 | import java.util.Optional; 15 | import java.util.Set; 16 | 17 | /** 18 | * This strategy is used to assign to the passenger a UAMRoute based on the 19 | * minimum travel distance of the route. 20 | * 21 | * @author Aitanm (Aitan Militao), RRothfeld (Raoul Rothfeld) 22 | */ 23 | public class UAMMinDistanceStrategy implements UAMStrategy { 24 | private UAMStrategyUtils strategyUtils; 25 | 26 | public UAMMinDistanceStrategy(UAMStrategyUtils strategyUtils) { 27 | this.strategyUtils = strategyUtils; 28 | } 29 | 30 | @Override 31 | public UAMStrategyType getUAMStrategyType() { 32 | return UAMStrategyType.MINDISTANCE; 33 | } 34 | 35 | @Override 36 | public Optional getRoute(Person person, Facility fromFacility, Facility toFacility, double departureTime) { 37 | UAMStation bestStationOrigin = null, bestStationDestination = null; 38 | Collection stationsOrigin = strategyUtils.getPossibleStations(fromFacility, toFacility); 39 | Collection stationsDestination = strategyUtils.getPossibleStations(toFacility, fromFacility); 40 | Map, UAMAccessOptions> accessRoutesData = strategyUtils.getAccessOptions(true, 41 | stationsOrigin, fromFacility, departureTime); 42 | String bestModeEgress = TransportMode.walk; 43 | 44 | Set modes = strategyUtils.getModes(); 45 | //UAM Flight Distance + access and egress distance 46 | double minTotalDistance = Double.POSITIVE_INFINITY; 47 | for (UAMStation stationOrigin : stationsOrigin) { 48 | for (UAMStation stationDestination : stationsDestination) { 49 | if (stationOrigin == stationDestination) 50 | continue; 51 | //collects the distance between stations and stores it 52 | double flyDistance = strategyUtils.getFlightDistance(stationOrigin, stationDestination); 53 | 54 | //fly time between stations 55 | double flyTime = strategyUtils.getFlightTime(stationOrigin, stationDestination); 56 | double accessTime = strategyUtils.estimateAccessLeg(true, fromFacility, departureTime, 57 | stationOrigin, accessRoutesData.get(stationOrigin.getId()).getShortestDistanceMode()).travelTime; 58 | //updates departureTime 59 | double currentDepartureTime = departureTime + accessTime + flyTime; 60 | //Calculates the shortest path 61 | for (String mode : modes) { 62 | //Calculates the distance for the egress routes using updated departureTime 63 | UAMAccessLeg egressLeg = strategyUtils.estimateAccessLeg(false, toFacility, currentDepartureTime, 64 | stationDestination, mode); 65 | if (egressLeg == null) 66 | continue; 67 | double egressDistance = egressLeg.distance; 68 | double totalDistance = accessRoutesData.get(stationOrigin.getId()).getShortestAccessDistance() + flyDistance + egressDistance; 69 | if (totalDistance < minTotalDistance) { 70 | minTotalDistance = totalDistance; 71 | bestStationOrigin = stationOrigin; 72 | bestStationDestination = stationDestination; 73 | bestModeEgress = mode; 74 | } 75 | } 76 | } 77 | } 78 | 79 | // TODO: What if non is found? Should return Optional.empty(); 80 | 81 | return Optional.of(new UAMRoute(accessRoutesData.get(bestStationOrigin.getId()).getShortestDistanceMode(), bestStationOrigin, 82 | bestStationDestination, bestModeEgress)); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | output*/ 2 | simulation_output 3 | 4 | # Created by https://www.gitignore.io/api/git,java,maven,eclipse,intellij 5 | # Edit at https://www.gitignore.io/?templates=git,java,maven,eclipse,intellij 6 | 7 | ### Eclipse ### 8 | .metadata 9 | bin/ 10 | tmp/ 11 | *.tmp 12 | *.bak 13 | *.swp 14 | *~.nib 15 | local.properties 16 | .settings/ 17 | .loadpath 18 | .recommenders 19 | 20 | # External tool builders 21 | .externalToolBuilders/ 22 | 23 | # Locally stored "Eclipse launch configurations" 24 | *.launch 25 | 26 | # PyDev specific (Python IDE for Eclipse) 27 | *.pydevproject 28 | 29 | # CDT-specific (C/C++ Development Tooling) 30 | .cproject 31 | 32 | # CDT- autotools 33 | .autotools 34 | 35 | # Java annotation processor (APT) 36 | .factorypath 37 | 38 | # PDT-specific (PHP Development Tools) 39 | .buildpath 40 | 41 | # sbteclipse plugin 42 | .target 43 | 44 | # Tern plugin 45 | .tern-project 46 | 47 | # TeXlipse plugin 48 | .texlipse 49 | 50 | # STS (Spring Tool Suite) 51 | .springBeans 52 | 53 | # Code Recommenders 54 | .recommenders/ 55 | 56 | # Annotation Processing 57 | .apt_generated/ 58 | 59 | # Scala IDE specific (Scala & Java development for Eclipse) 60 | .cache-main 61 | .scala_dependencies 62 | .worksheet 63 | 64 | ### Eclipse Patch ### 65 | # Eclipse Core 66 | .project 67 | 68 | # JDT-specific (Eclipse Java Development Tools) 69 | .classpath 70 | 71 | # Annotation Processing 72 | .apt_generated 73 | 74 | .sts4-cache/ 75 | 76 | ### Git ### 77 | # Created by git for backups. To disable backups in Git: 78 | # $ git config --global mergetool.keepBackup false 79 | *.orig 80 | 81 | # Created by git when using merge tools for conflicts 82 | *.BACKUP.* 83 | *.BASE.* 84 | *.LOCAL.* 85 | *.REMOTE.* 86 | *_BACKUP_*.txt 87 | *_BASE_*.txt 88 | *_LOCAL_*.txt 89 | *_REMOTE_*.txt 90 | 91 | ### Intellij ### 92 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm 93 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 94 | .idea/ 95 | 96 | # CMake 97 | cmake-build-*/ 98 | 99 | # Mongo Explorer plugin 100 | .idea/**/mongoSettings.xml 101 | 102 | # File-based project format 103 | *.iws 104 | 105 | # IntelliJ 106 | out/ 107 | 108 | # mpeltonen/sbt-idea plugin 109 | .idea_modules/ 110 | 111 | # JIRA plugin 112 | atlassian-ide-plugin.xml 113 | 114 | # Cursive Clojure plugin 115 | .idea/replstate.xml 116 | 117 | # Crashlytics plugin (for Android Studio and IntelliJ) 118 | com_crashlytics_export_strings.xml 119 | crashlytics.properties 120 | crashlytics-build.properties 121 | fabric.properties 122 | 123 | # Editor-based Rest Client 124 | .idea/httpRequests 125 | 126 | # Android studio 3.1+ serialized cache file 127 | .idea/caches/build_file_checksums.ser 128 | 129 | ### Intellij Patch ### 130 | # Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 131 | 132 | # *.iml 133 | # modules.xml 134 | # .idea/misc.xml 135 | # *.ipr 136 | 137 | # Sonarlint plugin 138 | .idea/sonarlint 139 | 140 | ### Java ### 141 | # Compiled class file 142 | *.class 143 | 144 | # Log file 145 | *.log 146 | 147 | # BlueJ files 148 | *.ctxt 149 | 150 | # Mobile Tools for Java (J2ME) 151 | .mtj.tmp/ 152 | 153 | # Package Files # 154 | */*.jar 155 | *.war 156 | *.nar 157 | *.ear 158 | *.zip 159 | *.tar.gz 160 | *.rar 161 | 162 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 163 | hs_err_pid* 164 | 165 | ### Maven ### 166 | target/ 167 | pom.xml.tag 168 | pom.xml.releaseBackup 169 | pom.xml.versionsBackup 170 | pom.xml.next 171 | release.properties 172 | dependency-reduced-pom.xml 173 | buildNumber.properties 174 | .mvn/timing.properties 175 | .mvn/wrapper/maven-wrapper.jar 176 | 177 | # End of https://www.gitignore.io/api/git,java,maven,eclipse,intellij 178 | *.iml 179 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/router/strategy/UAMStrategyRouter.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.router.strategy; 2 | 3 | import java.util.Optional; 4 | 5 | import org.apache.logging.log4j.LogManager; 6 | import org.apache.logging.log4j.Logger; 7 | import org.matsim.api.core.v01.Scenario; 8 | import org.matsim.api.core.v01.network.Network; 9 | import org.matsim.api.core.v01.population.Person; 10 | import org.matsim.core.router.util.LeastCostPathCalculator; 11 | import org.matsim.facilities.Facility; 12 | import org.matsim.pt.router.TransitRouter; 13 | 14 | import net.bhl.matsim.uam.config.UAMConfigGroup; 15 | import net.bhl.matsim.uam.data.UAMRoute; 16 | import net.bhl.matsim.uam.data.UAMRoutes; 17 | import net.bhl.matsim.uam.data.UAMStationConnectionGraph; 18 | import net.bhl.matsim.uam.infrastructure.UAMStations; 19 | 20 | /** 21 | * This class uses the strategy selected in the config file to generate the 22 | * routes for agents using UAM. 23 | * 24 | * @author Aitanm (Aitan Militao), RRothfeld (Raoul Rothfeld) 25 | */ 26 | public class UAMStrategyRouter { 27 | private static final Logger log = LogManager.getLogger(UAMStrategyRouter.class); 28 | private final Scenario scenario; 29 | private UAMConfigGroup uamConfig; 30 | private UAMStations landingStations; 31 | private LeastCostPathCalculator plcpccar; 32 | private Network carNetwork; 33 | private TransitRouter transitRouter; 34 | private UAMStationConnectionGraph stationConnectionutilities; 35 | private UAMStrategy strategy; 36 | 37 | public UAMStrategyRouter( 38 | Scenario scenario, UAMConfigGroup uamConfig, 39 | LeastCostPathCalculator plcpccar, UAMStations landingStations, Network carNetwork, 40 | UAMStationConnectionGraph stationConnectionutilities) { 41 | this.scenario = scenario; 42 | this.uamConfig = uamConfig; 43 | this.plcpccar = plcpccar; 44 | this.landingStations = landingStations; 45 | this.carNetwork = carNetwork; 46 | this.stationConnectionutilities = stationConnectionutilities; 47 | } 48 | 49 | public UAMStrategyRouter( 50 | TransitRouter transitRouter, 51 | Scenario scenario, UAMConfigGroup uamConfig, 52 | LeastCostPathCalculator plcpccar, UAMStations landingStations, Network carNetwork, 53 | UAMStationConnectionGraph stationConnectionutilities) { 54 | this(scenario, uamConfig, plcpccar, landingStations, carNetwork, stationConnectionutilities); 55 | this.transitRouter = transitRouter; 56 | } 57 | 58 | public Optional estimateUAMRoute(Person person, Facility fromFacility, Facility toFacility, double departureTime) { 59 | if (strategy == null) 60 | this.setStrategy(); 61 | 62 | Optional route = strategy.getRoute(person, fromFacility, toFacility, departureTime); 63 | 64 | if (route.isPresent()) { 65 | UAMRoutes.getInstance().add(person.getId(), departureTime, route.get()); 66 | } 67 | 68 | return route; 69 | } 70 | 71 | /** 72 | * This method instantiate the strategy according to the parameter set in the Config file. Any new strategy class 73 | * created has to be added here. 74 | */ 75 | private void setStrategy() { 76 | UAMStrategyUtils strategyUtils = new UAMStrategyUtils(this.landingStations, this.uamConfig, this.scenario, 77 | this.stationConnectionutilities, this.carNetwork, this.transitRouter, this.plcpccar); 78 | log.info("Setting UAM routing strategy to " + uamConfig.getRoutingStrategy()); 79 | switch (uamConfig.getRoutingStrategy()) { 80 | case MINTRAVELTIME: 81 | this.strategy = new UAMMinTravelTimeStrategy(strategyUtils); 82 | return; 83 | case MINACCESSTRAVELTIME: 84 | this.strategy = new UAMMinAccessTravelTimeStrategy(strategyUtils); 85 | return; 86 | case MINDISTANCE: 87 | this.strategy = new UAMMinDistanceStrategy(strategyUtils); 88 | return; 89 | case MINACCESSDISTANCE: 90 | this.strategy = new UAMMinAccessDistanceStrategy(strategyUtils); 91 | return; 92 | case PREDEFINED: 93 | this.strategy = new UAMPredefinedStrategy(strategyUtils); 94 | } 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /examples/uam-scenario-creation/non-uam-scenario/network.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/run/RunUAMScenario.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.run; 2 | 3 | import ch.sbb.matsim.routing.pt.raptor.SwissRailRaptorModule; 4 | import net.bhl.matsim.uam.config.UAMConfigGroup; 5 | import net.bhl.matsim.uam.qsim.UAMQSimModule; 6 | import net.bhl.matsim.uam.qsim.UAMSpeedModule; 7 | import org.matsim.api.core.v01.Scenario; 8 | import org.matsim.contrib.dvrp.run.DvrpConfigGroup; 9 | import org.matsim.contrib.dvrp.run.DvrpModule; 10 | import org.matsim.core.config.CommandLine; 11 | import org.matsim.core.config.CommandLine.ConfigurationException; 12 | import org.matsim.core.config.Config; 13 | import org.matsim.core.config.ConfigUtils; 14 | import org.matsim.core.config.groups.QSimConfigGroup.StarttimeInterpretation; 15 | import org.matsim.core.config.groups.ScoringConfigGroup.ActivityParams; 16 | import org.matsim.core.config.groups.ScoringConfigGroup.ModeParams; 17 | import org.matsim.core.controler.Controler; 18 | import org.matsim.core.scenario.ScenarioUtils; 19 | 20 | import com.google.common.collect.ImmutableSet; 21 | 22 | /** 23 | * The RunUAMScenario program start a MATSim run including Urban Air Mobility 24 | * capabilities. 25 | * 26 | * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) 27 | */ 28 | public class RunUAMScenario { 29 | 30 | private static UAMConfigGroup uamConfigGroup; 31 | private static CommandLine cmd; 32 | private static String path; 33 | private static Config config; 34 | private static Controler controler; 35 | private static Scenario scenario; 36 | 37 | public static void main(String[] args) { 38 | parseArguments(args); 39 | setConfig(path); 40 | createScenario(); 41 | createControler().run(); 42 | } 43 | 44 | public static void parseArguments(String[] args) { 45 | try { 46 | cmd = new CommandLine.Builder(args).allowOptions("config-path", "use-charging").build(); 47 | 48 | if (cmd.hasOption("config-path")) 49 | path = cmd.getOption("config-path").get(); 50 | else 51 | path = args[0]; 52 | } catch (ConfigurationException e) { 53 | e.printStackTrace(); 54 | } 55 | uamConfigGroup = new UAMConfigGroup(); 56 | } 57 | 58 | public static Config createConfig() { 59 | return config = ConfigUtils.createConfig(uamConfigGroup, new DvrpConfigGroup()); 60 | } 61 | 62 | public static Config setConfig(String path) { 63 | return config = ConfigUtils.loadConfig(path, uamConfigGroup, new DvrpConfigGroup()); 64 | } 65 | 66 | public static Scenario createScenario() { 67 | scenario = ScenarioUtils.createScenario(config); 68 | ScenarioUtils.loadScenario(scenario); 69 | return scenario; 70 | } 71 | 72 | public static Scenario setScenario(Scenario scenario) { 73 | return RunUAMScenario.scenario = scenario; 74 | } 75 | 76 | public static Controler createControler() { 77 | try { 78 | cmd.applyConfiguration(config); 79 | } catch (ConfigurationException e) { 80 | e.printStackTrace(); 81 | } 82 | 83 | controler = new Controler(scenario); 84 | 85 | controler.addOverridingModule(new DvrpModule()); 86 | 87 | controler.addOverridingModule(new UAMModule(config)); 88 | controler.addOverridingQSimModule(new UAMSpeedModule()); 89 | controler.addOverridingModule(new SwissRailRaptorModule()); 90 | 91 | controler.configureQSimComponents(configurator -> { 92 | UAMQSimModule.activateModes().configure(configurator); 93 | }); 94 | 95 | controler.getConfig().transit().setUseTransit(true); 96 | controler.getConfig().transit().setUsingTransitInMobsim(true); 97 | controler.getConfig().qsim().setSimStarttimeInterpretation(StarttimeInterpretation.onlyUseStarttime); 98 | controler.getConfig().qsim().setStartTime(0.0); 99 | 100 | DvrpConfigGroup.get(config).networkModes = ImmutableSet.of("uam"); 101 | config.scoring().addModeParams(new ModeParams("access_uam_car")); 102 | config.scoring().addModeParams(new ModeParams("egress_uam_car")); 103 | config.scoring().addModeParams(new ModeParams("uam")); 104 | config.scoring() 105 | .addActivityParams(new ActivityParams("uam_interaction").setScoringThisActivityAtAll(false)); 106 | 107 | config.controller().setWriteEventsInterval(1); 108 | 109 | return controler; 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/passenger/UAMSinglePassengerPerRequestPickupActivity.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.passenger; 2 | 3 | import org.matsim.contrib.dvrp.fleet.DvrpVehicle; 4 | import org.matsim.contrib.dvrp.passenger.PassengerEngine; 5 | import org.matsim.contrib.dvrp.passenger.PassengerPickupActivity; 6 | import org.matsim.contrib.dvrp.passenger.PassengerRequest; 7 | import org.matsim.contrib.dvrp.schedule.StayTask; 8 | import org.matsim.contrib.dynagent.DynAgent; 9 | import org.matsim.core.mobsim.framework.MobsimPassengerAgent; 10 | 11 | import java.util.List; 12 | import java.util.Set; 13 | 14 | /** 15 | * This class defines the pick up activity for the passenger and its properties. 16 | * 17 | * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) 18 | */ 19 | 20 | public class UAMSinglePassengerPerRequestPickupActivity implements PassengerPickupActivity { 21 | 22 | private final PassengerEngine passengerEngine; 23 | private final DynAgent driver; 24 | private final Set requests; 25 | private final double pickupDuration; 26 | private final String activityType; 27 | 28 | private double maximumRequestT0 = 0; 29 | 30 | private double endTime; 31 | private int passengersAboard; 32 | 33 | public UAMSinglePassengerPerRequestPickupActivity(PassengerEngine passengerEngine, DynAgent driver, 34 | DvrpVehicle vehicle, StayTask pickupTask, Set requests, 35 | double pickupDuration, String activityType) { 36 | if (requests.size() > vehicle.getCapacity()) { 37 | // Number of requests exceeds number of seats 38 | throw new IllegalStateException(); 39 | } 40 | 41 | this.activityType = activityType; 42 | 43 | this.passengerEngine = passengerEngine; 44 | this.driver = driver; 45 | this.pickupDuration = pickupDuration; 46 | this.requests = requests; 47 | 48 | endTime = pickupTask.getBeginTime(); 49 | passengersAboard = 0; 50 | 51 | double now = pickupTask.getBeginTime(); 52 | int passengerCount = 0; 53 | for (PassengerRequest request : requests) { 54 | passengerCount += request.getPassengerCount(); 55 | if (passengerEngine.tryPickUpPassengers(this, driver, request.getId(), pickupTask.getBeginTime())) { 56 | passengersAboard += request.getPassengerCount(); 57 | } 58 | 59 | if (request.getEarliestStartTime() > maximumRequestT0) { 60 | maximumRequestT0 = request.getEarliestStartTime(); 61 | } 62 | } 63 | 64 | if (passengersAboard == passengerCount) { 65 | endTime = now + pickupDuration; 66 | } else { 67 | setEndTimeIfWaitingForPassengers(now); 68 | } 69 | 70 | } 71 | 72 | private void setEndTimeIfWaitingForPassengers(double now) { 73 | endTime = Math.max(now, maximumRequestT0) + pickupDuration; 74 | 75 | if (endTime == now) { 76 | endTime += 1; 77 | } 78 | } 79 | 80 | @Override 81 | public String getActivityType() { 82 | return activityType; 83 | } 84 | 85 | @Override 86 | public double getEndTime() { 87 | return endTime; 88 | } 89 | 90 | @Override 91 | public void doSimStep(double now) { 92 | if (passengersAboard < requests.size()) { 93 | setEndTimeIfWaitingForPassengers(now); 94 | } 95 | } 96 | 97 | private PassengerRequest getRequestForPassenger(MobsimPassengerAgent passenger) { 98 | for (PassengerRequest request : requests) { 99 | if (request.getPassengerIds().contains( passenger.getId())) 100 | return request; 101 | } 102 | 103 | return null; 104 | } 105 | 106 | 107 | @Override 108 | public void notifyPassengersAreReadyForDeparture(List passengers, double now) { 109 | for (MobsimPassengerAgent mpa : passengers) { 110 | 111 | PassengerRequest pr = getRequestForPassenger(mpa); 112 | if (pr == null) 113 | throw new IllegalArgumentException("I am waiting for a different passenger!"); 114 | if (passengerEngine.tryPickUpPassengers(this, driver, pr.getId(), now)) { 115 | passengersAboard++; 116 | } else { 117 | throw new IllegalStateException("The passenger is not on the link or not available for departure!"); 118 | } 119 | 120 | } 121 | 122 | if (passengersAboard == requests.size()) { 123 | endTime = now + pickupDuration; 124 | } 125 | } 126 | 127 | } 128 | -------------------------------------------------------------------------------- /src/main/java/net/bhl/matsim/uam/scenario/population/RunCreateUAMPersonAttributes.java: -------------------------------------------------------------------------------- 1 | package net.bhl.matsim.uam.scenario.population; 2 | 3 | import java.util.Collection; 4 | import java.util.HashSet; 5 | import java.util.Set; 6 | 7 | import org.matsim.api.core.v01.Coord; 8 | import org.matsim.api.core.v01.Scenario; 9 | import org.matsim.api.core.v01.network.Network; 10 | import org.matsim.api.core.v01.population.Activity; 11 | import org.matsim.api.core.v01.population.Person; 12 | import org.matsim.api.core.v01.population.PlanElement; 13 | import org.matsim.api.core.v01.population.Population; 14 | import org.matsim.contrib.dvrp.run.DvrpConfigGroup; 15 | import org.matsim.core.config.Config; 16 | import org.matsim.core.config.ConfigGroup; 17 | import org.matsim.core.config.ConfigUtils; 18 | import org.matsim.core.network.NetworkUtils; 19 | import org.matsim.core.network.algorithms.TransportModeNetworkFilter; 20 | import org.matsim.core.scenario.ScenarioUtils; 21 | import org.matsim.utils.objectattributes.ObjectAttributes; 22 | import org.matsim.utils.objectattributes.ObjectAttributesXmlWriter; 23 | 24 | import net.bhl.matsim.uam.config.UAMConfigGroup; 25 | import net.bhl.matsim.uam.infrastructure.UAMStation; 26 | import net.bhl.matsim.uam.infrastructure.UAMStations; 27 | import net.bhl.matsim.uam.infrastructure.readers.UAMXMLReader; 28 | import net.bhl.matsim.uam.run.UAMConstants; 29 | 30 | /** 31 | * This script generates a xml subpopulation attributes file containing the id 32 | * of potential uam users based on a provided config file containing a search 33 | * radius. If there is at least one station within reach, the user is considered 34 | * a potential uam user. 35 | * 36 | * @author balacmi (Milos Balac), RRothfeld (Raoul Rothfeld) 37 | */ 38 | @Deprecated 39 | public class RunCreateUAMPersonAttributes { 40 | public static void main(final String[] args) { 41 | // cmd-line input: input-config 42 | String inputConfig = args[0]; 43 | 44 | UAMConfigGroup uamConfigGroup = new UAMConfigGroup(); 45 | Config config = ConfigUtils.loadConfig(inputConfig, uamConfigGroup, new DvrpConfigGroup()); 46 | 47 | Scenario scenario = ScenarioUtils.createScenario(config); 48 | ScenarioUtils.loadScenario(scenario); 49 | 50 | Network network = scenario.getNetwork(); 51 | TransportModeNetworkFilter filter = new TransportModeNetworkFilter(scenario.getNetwork()); 52 | Set modes = new HashSet<>(); 53 | modes.add(UAMConstants.uam); 54 | Network networkUAM = NetworkUtils.createNetwork(); 55 | filter.filter(networkUAM, modes); 56 | 57 | UAMXMLReader uamReader = new UAMXMLReader(networkUAM); 58 | uamReader.readFile(ConfigGroup.getInputFileURL(config.getContext(), uamConfigGroup.getInputFile()).getPath() 59 | .replace("%20", " ")); 60 | final UAMStations uamStations = new UAMStations(uamReader.getStations(), network); 61 | 62 | Population pop = scenario.getPopulation(); 63 | ObjectAttributes objattr = new ObjectAttributes(); 64 | 65 | // filter persons with activities outside the radius 66 | personloop: 67 | for (Person person : pop.getPersons().values()) { 68 | for (PlanElement p : person.getSelectedPlan().getPlanElements()) { 69 | if (p instanceof Activity) { 70 | 71 | Coord originCoord = ((Activity) p).getCoord(); 72 | 73 | if (uamConfigGroup.getUseDynamicSearchRadius()) 74 | System.err.println("Warning: UAM search radius must be dynamic = false! Setting it to static."); 75 | 76 | Collection stations = uamStations.getUAMStationsInRadius(originCoord, 77 | uamConfigGroup.getSearchRadius()); 78 | 79 | if (!stations.isEmpty()) { 80 | // at least one station within reach 81 | objattr.putAttribute(person.getId().toString(), "subpopulation", "potential-uam"); 82 | continue personloop; 83 | } 84 | } 85 | } 86 | // no UAM stations in reach 87 | } 88 | 89 | int radius = (int) uamConfigGroup.getSearchRadius(); 90 | String rangeString = radius > 9999 ? "" + (radius / 1000) + "km" : "" + radius + "m"; 91 | 92 | ObjectAttributesXmlWriter objwriter = new ObjectAttributesXmlWriter(objattr); 93 | objwriter.writeFile(inputConfig.substring(0, inputConfig.lastIndexOf("\\")) + "\\" 94 | + config.plans().getInputFile().split(".xml")[0] + "_attributes_uam-" + rangeString + ".xml.gz"); 95 | 96 | System.out.println("done."); 97 | } 98 | } --------------------------------------------------------------------------------