Skip to content

Commit

Permalink
Merge branch 'feat/car-departure-access' of github.com:eqasim-org/eqa…
Browse files Browse the repository at this point in the history
…sim-java into feat/car-departure-access
  • Loading branch information
sebhoerl committed May 29, 2023
2 parents 4e88e4b + dd673ff commit 8363c31
Show file tree
Hide file tree
Showing 5 changed files with 313 additions and 25 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ included in the (note yet determined) next version number.

**Development version**

- Improve functionality of routing tools to set utilities in detail
- Fix bug in EqasimTransitQSimModule: first check if EqasimConfigGroup has TransitEngineModule before removing it
- Updated config option from `eqasim.tripAnalysisInterval` to `eqasim.analysisInterval`
- Automatically produce analysis output for legs and public transport information
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import org.apache.commons.lang3.tuple.Pair;
import org.eqasim.core.components.headway.HeadwayCalculator;
import org.eqasim.core.misc.ParallelProgress;
import org.matsim.api.core.v01.Coord;
import org.matsim.api.core.v01.TransportMode;
import org.matsim.api.core.v01.network.Network;
import org.matsim.api.core.v01.population.Leg;
import org.matsim.core.network.NetworkUtils;
Expand All @@ -24,6 +23,7 @@
import org.matsim.pt.transitSchedule.api.TransitRoute;
import org.matsim.pt.transitSchedule.api.TransitSchedule;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.inject.Provider;

public class BatchPublicTransportRouter {
Expand All @@ -36,16 +36,19 @@ public class BatchPublicTransportRouter {
private final int numberOfThreads;
private final double interval;

private final Set<String> transitModes;

public BatchPublicTransportRouter(Provider<TransitRouter> routerProvider,
Provider<HeadwayCalculator> headwayCalculatorProvider, TransitSchedule schedule, Network network,
int batchSize, int numberOfThreads, double interval) {
int batchSize, int numberOfThreads, double interval, Set<String> transitModes) {
this.routerProvider = routerProvider;
this.headwayCalculatorProvider = headwayCalculatorProvider;
this.batchSize = batchSize;
this.numberOfThreads = numberOfThreads;
this.schedule = schedule;
this.network = network;
this.interval = interval;
this.transitModes = transitModes;
}

public Pair<Collection<TripInformation>, Collection<LegInformation>> run(Collection<Task> tasks)
Expand Down Expand Up @@ -119,7 +122,6 @@ public void run() {
Facility toFacility = new LinkWrapperFacility(NetworkUtils.getNearestLink(network, toCoord));

List<Leg> legs = router.calcRoute(fromFacility, toFacility, task.departureTime, null);
List<LegInformation> routeInformation = new LinkedList<>();

if (legs != null) {
boolean isFirstVehicularLeg = true;
Expand All @@ -137,21 +139,17 @@ public void run() {
for (Leg leg : legs) {
boolean isFirstLeg = currentIndex == 0;
boolean isLastLeg = currentIndex == legs.size() - 1;
currentIndex++;

if (leg.getMode().equals(TransportMode.access_walk)
|| (leg.getMode().equals(TransportMode.walk) && isFirstLeg)) {
if (leg.getMode().contains("walk") && isFirstLeg) {
tripInformation.accessTravelTime_min += leg.getTravelTime().seconds() / 60.0;
tripInformation.accessDistance_km += leg.getRoute().getDistance() * 1e-3;
} else if (leg.getMode().equals(TransportMode.egress_walk)
|| (leg.getMode().equals(TransportMode.walk) && isLastLeg)) {
} else if (leg.getMode().contains("walk") && isLastLeg) {
tripInformation.egressTravelTime_min += leg.getTravelTime().seconds() / 60.0;
tripInformation.egressDistance_km += leg.getRoute().getDistance() * 1e-3;
} else if (leg.getMode().equals(TransportMode.transit_walk)
|| (leg.getMode().equals(TransportMode.walk) && !isFirstLeg && !isLastLeg)) {
} else if (leg.getMode().contains("walk") && !isFirstLeg && !isLastLeg) {
tripInformation.transferTravelTime_min += leg.getTravelTime().seconds() / 60.0;
tripInformation.transferDistance_km += leg.getRoute().getDistance() * 1e-3;
} else if (leg.getMode().equals(TransportMode.pt)) {
} else if (transitModes.contains(leg.getMode())) {
TransitPassengerRoute route = (TransitPassengerRoute) leg.getRoute();

double waitingTime = route.getBoardingTime().seconds()
Expand Down Expand Up @@ -201,7 +199,7 @@ public void run() {
LegInformation legInformation = new LegInformation();
legInformation.identifier = task.identifier;
legInformation.legIndex = currentIndex;
legInformation.mode = transitMode;
legInformation.transitMode = transitMode;
legInformation.lineId = transitLine.getId().toString();
legInformation.routeId = transitRoute.getId().toString();
legInformation.vehicleId = departure.getVehicleId().toString();
Expand All @@ -214,6 +212,8 @@ public void run() {
} else {
throw new IllegalStateException();
}

currentIndex++;
}

tripInformation.inVehicleTimeTotal_min = tripInformation.inVehicleTimeRail_min
Expand Down Expand Up @@ -262,72 +262,132 @@ private static Departure findDeparture(TransitPassengerRoute passengerRoute, Tra
}

static public class Task {
@JsonProperty("identifier")
public String identifier;

@JsonProperty("origin_x")
public double originX;

@JsonProperty("origin_y")
public double originY;

@JsonProperty("destination_x")
public double destinationX;

@JsonProperty("destination_y")
public double destinationY;

@JsonProperty("departure_time")
public double departureTime;
}

static public class TripInformation {
@JsonProperty("identifier")
public String identifier;

@JsonProperty("access_travel_time_min")
public double accessTravelTime_min;

@JsonProperty("access_distance_km")
public double accessDistance_km;

@JsonProperty("egress_travel_time_min")
public double egressTravelTime_min;

@JsonProperty("egress_distance_km")
public double egressDistance_km;

@JsonProperty("transfer_travel_time_min")
public double transferTravelTime_min;

@JsonProperty("transfer_distance_km")
public double transferDistance_km;

@JsonProperty("total_walk_travel_time_min")
public double totalWalkTravelTime_min;

@JsonProperty("total_walk_distance_km")
public double totalWalkDistance_km;

@JsonProperty("in_vehicle_time_rail_min")
public double inVehicleTimeRail_min;

@JsonProperty("in_vehicle_time_subway_min")
public double inVehicleTimeSubway_min;

@JsonProperty("in_vehicle_time_bus_min")
public double inVehicleTimeBus_min;

@JsonProperty("in_vehicle_time_tram_min")
public double inVehicleTimeTram_min;

@JsonProperty("in_vehicle_time_other_min")
public double inVehicleTimeOther_min;

@JsonProperty("in_vehicle_time_total_min")
public double inVehicleTimeTotal_min;

@JsonProperty("in_vehicle_distance_rail_km")
public double inVehicleDistanceRail_km;

@JsonProperty("in_vehicle_distance_subway_km")
public double inVehicleDistanceSubway_km;

@JsonProperty("in_vehicle_distance_bus_km")
public double inVehicleDistanceBus_km;

@JsonProperty("in_vehicle_distance_tram_km")
public double inVehicleDistanceTram_km;

@JsonProperty("in_vehicle_distance_other_km")
public double inVehicleDistanceOther_km;

@JsonProperty("in_vehicle_distance_total_km")
public double inVehicleDistanceTotal_km;

@JsonProperty("transfers")
public int numberOfTransfers;

@JsonProperty("initial_waiting_time_min")
public double initialWaitingTime_min;

@JsonProperty("transfer_waiting_time_min")
public double transferWaitingTime_min;

@JsonProperty("headway_min")
public double headway_min;

@JsonProperty("is_only_walk")
public int isOnlyWalk;

public String route;

TripInformation(Task task) {
this.identifier = task.identifier;
}
}

static public class LegInformation {
@JsonProperty("identifier")
public String identifier;

@JsonProperty("leg_index")
public int legIndex;

@JsonProperty("line_id")
public String lineId;

@JsonProperty("route_id")
public String routeId;

@JsonProperty("vehicle_id")
public String vehicleId;
public String mode;

@JsonProperty("transit_mode")
public String transitMode;

@JsonProperty("access_time")
public double accessTime;

@JsonProperty("egress_time")
public double egressTime;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.matsim.core.trafficmonitoring.FreeSpeedTravelTime;
import org.matsim.core.utils.geometry.CoordUtils;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.inject.Provider;

public class BatchRoadRouter {
Expand Down Expand Up @@ -126,24 +127,39 @@ public void run() {
}

static public class Task {
@JsonProperty("identifier")
public String identifier;

@JsonProperty("origin_x")
public double originX;

@JsonProperty("origin_y")
public double originY;

@JsonProperty("destination_x")
public double destinationX;

@JsonProperty("destination_y")
public double destinationY;

@JsonProperty("departure_time")
public double departureTime;
}

static public class Result {
@JsonProperty("identifier")
public String identifier;

@JsonProperty("access_euclidean_distance_km")
public double accessEuclideanDistance_km;

@JsonProperty("egress_euclidean_distance_km")
public double egressEuclideanDistance_km;

@JsonProperty("in_vehicle_time_min")
public double inVehicleTime_min;

@JsonProperty("in_vehicle_distance_km")
public double inVehicleDistance_km;

Result(Task task) {
Expand Down
Loading

0 comments on commit 8363c31

Please sign in to comment.