Skip to content

Commit

Permalink
feat: departureId in PublicTransitEvent and in eqasim_pt.csv (#279)
Browse files Browse the repository at this point in the history
  • Loading branch information
tkchouaki authored Nov 14, 2024
1 parent a0edb7f commit 60520f1
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.population.Person;
import org.matsim.pt.transitSchedule.api.TransitLine;
import org.matsim.pt.transitSchedule.api.TransitRoute;
import org.matsim.pt.transitSchedule.api.TransitStopArea;
import org.matsim.pt.transitSchedule.api.TransitStopFacility;
import org.matsim.pt.transitSchedule.api.*;

public class PublicTransportLegItem {
public Id<Person> personId;
Expand All @@ -20,12 +17,13 @@ public class PublicTransportLegItem {

public Id<TransitStopArea> accessAreaId;
public Id<TransitStopArea> egressAreaId;
public Id<Departure> departureId;

public String transitMode;

public PublicTransportLegItem(Id<Person> personId, int personTripId, int legIndex,
Id<TransitStopFacility> accessStopId, Id<TransitStopFacility> egressStopId, Id<TransitLine> transitLineId,
Id<TransitRoute> transitRouteId, Id<TransitStopArea> accessAreaId, Id<TransitStopArea> egressAreaId,
Id<TransitRoute> transitRouteId, Id<TransitStopArea> accessAreaId, Id<TransitStopArea> egressAreaId, Id<Departure> departureId,
String transitMode) {
this.personId = personId;
this.personTripId = personTripId;
Expand All @@ -39,6 +37,7 @@ public PublicTransportLegItem(Id<Person> personId, int personTripId, int legInde

this.accessAreaId = accessAreaId;
this.egressAreaId = egressAreaId;
this.departureId = departureId;

this.transitMode = transitMode;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ public void handleEvent(PublicTransitEvent event) {
event.getTransitLineId(), //
event.getTransitRouteId(), //
accessAreaId, //
egressAreaId, //
egressAreaId,
event.getDepartureId(),//
routeMode //
));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ public Collection<PublicTransportLegItem> getPublicTransportLegs(Person person)
Id<TransitStopArea> egressStopAreaId = this.transitSchedule.getFacilities().get(transitPassengerRoute.getEgressStopId()).getStopAreaId();
String mode = this.transitSchedule.getTransitLines().get(transitPassengerRoute.getLineId()).getRoutes().get(transitPassengerRoute.getRouteId()).getTransportMode();

PublicTransportLegItem item = new PublicTransportLegItem(person.getId(), tripIndex, legIndex, transitPassengerRoute.getAccessStopId(), transitPassengerRoute.getEgressStopId(), transitPassengerRoute.getLineId(), transitPassengerRoute.getRouteId(), accessStopAreaId, egressStopAreaId, mode);
//Cannot read a departure ID from a population, as it is determined during MOBSim. We put a null value here.
PublicTransportLegItem item = new PublicTransportLegItem(person.getId(), tripIndex, legIndex, transitPassengerRoute.getAccessStopId(), transitPassengerRoute.getEgressStopId(), transitPassengerRoute.getLineId(), transitPassengerRoute.getRouteId(), accessStopAreaId, egressStopAreaId, null, mode);
legItems.add(item);
}
return legItems;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ private String formatHeader() {
"access_stop_id", //
"egress_stop_id", //
"transit_line_id", //
"transit_route_id", //
"transit_route_id",
"departure_id",//
"access_area_id", //
"egress_area_id", //
"transit_mode" //
Expand All @@ -57,7 +58,8 @@ private String formatTrip(PublicTransportLegItem trip) {
trip.accessStopId.toString(), //
trip.egressStopId.toString(), //
trip.transitLineId.toString(), //
trip.transitRouteId.toString(), //
trip.transitRouteId.toString(),
trip.departureId == null ? "" : trip.departureId.toString(), //
trip.accessAreaId == null ? "" : trip.accessAreaId.toString(), //
trip.egressAreaId == null ? "" : trip.egressAreaId.toString(), //
trip.transitMode //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public boolean handleDeparture(double now, MobsimAgent agent, Id<Link> departure
Id<Link> arrivalLinkId = transitSchedule.getFacilities().get(route.getEgressStopId()).getLinkId();

PublicTransitEvent transitEvent = new PublicTransitEvent(arrivalTime, agent.getId(),
transitLine.getId(), transitRoute.getId(), route.getAccessStopId(), route.getEgressStopId(),
transitLine.getId(), transitRoute.getId(), route.getAccessStopId(), route.getEgressStopId(), stopDeparture.departure.getId(),
vehicleDepartureTime, route.getDistance());

internalInterface.registerAdditionalAgentOnLink(agent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.matsim.api.core.v01.events.GenericEvent;
import org.matsim.api.core.v01.events.HasPersonId;
import org.matsim.api.core.v01.population.Person;
import org.matsim.pt.transitSchedule.api.Departure;
import org.matsim.pt.transitSchedule.api.TransitLine;
import org.matsim.pt.transitSchedule.api.TransitRoute;
import org.matsim.pt.transitSchedule.api.TransitStopFacility;
Expand All @@ -18,11 +19,12 @@ public class PublicTransitEvent extends GenericEvent implements HasPersonId {
final private Id<TransitRoute> transitRouteId;
final private Id<TransitStopFacility> accessStopId;
final private Id<TransitStopFacility> egressStopId;
final private Id<Departure> departureId;
final private double vehicleDepartureTime;
final private double travelDistance;

public PublicTransitEvent(double arrivalTime, Id<Person> personId, Id<TransitLine> transitLineId,
Id<TransitRoute> transitRouteId, Id<TransitStopFacility> accessStopId, Id<TransitStopFacility> egressStopId,
Id<TransitRoute> transitRouteId, Id<TransitStopFacility> accessStopId, Id<TransitStopFacility> egressStopId, Id<Departure> departureId,
double vehicleDepartureTime, double travelDistance) {
super(TYPE, arrivalTime);

Expand All @@ -31,13 +33,14 @@ public PublicTransitEvent(double arrivalTime, Id<Person> personId, Id<TransitLin
this.transitRouteId = transitRouteId;
this.accessStopId = accessStopId;
this.egressStopId = egressStopId;
this.departureId = departureId;
this.vehicleDepartureTime = vehicleDepartureTime;
this.travelDistance = travelDistance;
}

public PublicTransitEvent(double now, PublicTransitEvent delegate) {
this(now, delegate.getPersonId(), delegate.getTransitLineId(), delegate.getTransitRouteId(),
delegate.getAccessStopId(), delegate.getEgressStopId(), delegate.getVehicleDepartureTime(),
delegate.getAccessStopId(), delegate.getEgressStopId(), delegate.getDepartureId(), delegate.getVehicleDepartureTime(),
delegate.getTravelDistance());
}

Expand All @@ -57,6 +60,10 @@ public Id<TransitStopFacility> getEgressStopId() {
return egressStopId;
}

public Id<Departure> getDepartureId() {
return departureId;
}

public double getVehicleDepartureTime() {
return vehicleDepartureTime;
}
Expand All @@ -83,6 +90,7 @@ public Map<String, String> getAttributes() {
attributes.put("route", transitRouteId.toString());
attributes.put("accessStop", accessStopId.toString());
attributes.put("egressStop", egressStopId.toString());
attributes.put("departure", departureId.toString());
attributes.put("vehicleDepartureTime", String.valueOf(vehicleDepartureTime));
attributes.put("travelDistance", String.valueOf(travelDistance));
return attributes;
Expand All @@ -98,9 +106,10 @@ public static PublicTransitEvent convert(GenericEvent genericEvent) {
Id<TransitRoute> transitRouteId = Id.create(attributes.get("route"), TransitRoute.class);
Id<TransitStopFacility> accessStopId = Id.create(attributes.get("accessStop"), TransitStopFacility.class);
Id<TransitStopFacility> egressStopId = Id.create(attributes.get("egressStop"), TransitStopFacility.class);
Id<Departure> departureId = Id.create(attributes.get("departure"), Departure.class);
double vehicleDepartureTime = Double.parseDouble(attributes.get("vehicleDepartureTime"));
double travelDistance = Double.parseDouble(attributes.get("travelDistance"));

return new PublicTransitEvent(genericEvent.getTime(), personId, transitLineId, transitRouteId, accessStopId, egressStopId, vehicleDepartureTime, travelDistance);
return new PublicTransitEvent(genericEvent.getTime(), personId, transitLineId, transitRouteId, accessStopId, egressStopId, departureId, vehicleDepartureTime, travelDistance);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.matsim.api.core.v01.events.GenericEvent;
import org.matsim.api.core.v01.population.Person;
import org.matsim.core.events.MatsimEventsReader.CustomEventMapper;
import org.matsim.pt.transitSchedule.api.Departure;
import org.matsim.pt.transitSchedule.api.TransitLine;
import org.matsim.pt.transitSchedule.api.TransitRoute;
import org.matsim.pt.transitSchedule.api.TransitStopFacility;
Expand All @@ -19,10 +20,11 @@ public PublicTransitEvent apply(GenericEvent event) {
TransitStopFacility.class);
Id<TransitStopFacility> egressStopId = Id.create(event.getAttributes().get("egressStop"),
TransitStopFacility.class);
Id<Departure> departureId = Id.create(event.getAttributes().get("departure"), Departure.class);
double vehicleDepartureTime = Double.parseDouble(event.getAttributes().get("vehicleDepartureTime"));
double travelDistance = Double.parseDouble(event.getAttributes().get("travelDistance"));

return new PublicTransitEvent(arrivalTime, personId, transitLineId, transitRouteId, accessStopId, egressStopId,
return new PublicTransitEvent(arrivalTime, personId, transitLineId, transitRouteId, accessStopId, egressStopId, departureId,
vehicleDepartureTime, travelDistance);
}
}

0 comments on commit 60520f1

Please sign in to comment.