Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send routing failures to skims #3735

Merged
merged 15 commits into from
Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 55 additions & 1 deletion src/main/java/beam/agentsim/events/ReplanningEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,72 @@ public class ReplanningEvent extends Event implements HasPersonId {
public final static String EVENT_TYPE = "Replanning";
public final static String ATTRIBUTE_PERSON = "person";
public final static String ATTRIBUTE_REPLANNING_REASON = "reason";
public final static String ATTRIBUTE_START_COORDINATE_X = "startX";
public final static String ATTRIBUTE_START_COORDINATE_Y = "startY";
public final static String ATTRIBUTE_END_COORDINATE_X = "endX";
public final static String ATTRIBUTE_END_COORDINATE_Y = "endY";

private final Id<Person> personId;
private final String reason;

private final String startX;

private final String startY;

private final String endX;

private final String endY;

public ReplanningEvent(final double time, final Id<Person> personId, final String reason) {
super(time);
this.personId = personId;
this.reason = reason;
this.startX = "";
this.startY = "";
this.endX = "";
this.endY = "";
}

public ReplanningEvent(final double time,
final Id<Person> personId,
final String reason,
final Double startX,
final Double startY,
final Double endX,
final Double endY) {
super(time);
this.personId = personId;
this.reason = reason;
this.startX = startX.toString();
this.startY = startY.toString();
this.endX = endX.toString();
this.endY = endY.toString();
}

public ReplanningEvent(final double time,
final Id<Person> personId,
final String reason,
final Double startX,
final Double startY) {
super(time);
this.personId = personId;
this.reason = reason;
this.startX = startX.toString();
this.startY = startY.toString();
this.endX = "";
this.endY = "";
}

public static ReplanningEvent apply(Event event) {
if (!(event instanceof ReplanningEvent) && EVENT_TYPE.equalsIgnoreCase(event.getEventType())) {
Map<String, String> attr = event.getAttributes();
return new ReplanningEvent(event.getTime(),
Id.createPersonId(attr.get(ATTRIBUTE_PERSON)),
attr.get(ATTRIBUTE_REPLANNING_REASON)
attr.get(ATTRIBUTE_REPLANNING_REASON),
Double.valueOf(attr.getOrDefault(ATTRIBUTE_START_COORDINATE_X, "0.0").replaceFirst("^$", "0.0")),
Double.valueOf(attr.getOrDefault(ATTRIBUTE_START_COORDINATE_Y, "0.0").replaceFirst("^$", "0.0")),
Double.valueOf(attr.getOrDefault(ATTRIBUTE_END_COORDINATE_X, "0.0").replaceFirst("^$", "0.0")),
Double.valueOf(attr.getOrDefault(ATTRIBUTE_END_COORDINATE_Y, "0.0").replaceFirst("^$", "0.0"))
);
}
return (ReplanningEvent) event;
Expand All @@ -50,6 +100,10 @@ public Map<String, String> getAttributes() {
Map<String, String> attr = super.getAttributes();
attr.put(ATTRIBUTE_PERSON, personId.toString());
attr.put(ATTRIBUTE_REPLANNING_REASON, reason);
attr.put(ATTRIBUTE_START_COORDINATE_X, startX);
attr.put(ATTRIBUTE_START_COORDINATE_Y, startY);
attr.put(ATTRIBUTE_END_COORDINATE_X, endX);
attr.put(ATTRIBUTE_END_COORDINATE_Y, endY);
return attr;
}
}
93 changes: 71 additions & 22 deletions src/main/scala/beam/agentsim/agents/PersonAgent.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import beam.agentsim.events._
import beam.agentsim.events.resources.{ReservationError, ReservationErrorCode}
import beam.agentsim.infrastructure.ChargingNetworkManager._
import beam.agentsim.infrastructure.parking.ParkingMNL
import beam.agentsim.infrastructure.taz.TAZ
import beam.agentsim.infrastructure.{ParkingInquiryResponse, ParkingNetworkManager, ParkingStall}
import beam.agentsim.scheduler.BeamAgentScheduler.{CompletionNotice, IllegalTriggerGoToError, ScheduleTrigger}
import beam.agentsim.scheduler.Trigger.TriggerWithId
Expand Down Expand Up @@ -713,8 +714,17 @@ class PersonAgent(
serviceName = response.rideHailManagerName
)
)
eventsManager.processEvent(new ReplanningEvent(tick, Id.createPersonId(id), replanningReason))
val currentCoord = beamServices.geo.wgs2Utm(data.restOfCurrentTrip.head.beamLeg.travelPath.startPoint).loc

eventsManager.processEvent(
new ReplanningEvent(
tick,
Id.createPersonId(id),
replanningReason,
currentCoord.getX,
currentCoord.getY
)
)
val nextCoord = nextActivity(data).get.getCoord
goto(ChoosingMode) using ChoosesModeData(
data.copy(currentTourMode = None, numberOfReplanningAttempts = data.numberOfReplanningAttempts + 1),
Expand All @@ -740,12 +750,20 @@ class PersonAgent(
) =>
logDebug(s"replanning because ${firstErrorResponse.errorCode}")

val currentCoord = beamServices.geo.wgs2Utm(nextLeg.beamLeg.travelPath.startPoint).loc
val nextCoord = nextActivity(data).get.getCoord
val replanningReason = getReplanningReasonFrom(data, firstErrorResponse.errorCode.entryName)
eventsManager.processEvent(
new ReplanningEvent(_currentTick.get, Id.createPersonId(id), replanningReason)
new ReplanningEvent(
_currentTick.get,
Id.createPersonId(id),
replanningReason,
currentCoord.getX,
currentCoord.getY,
nextCoord.getX,
nextCoord.getY
)
)
val currentCoord = beamServices.geo.wgs2Utm(nextLeg.beamLeg.travelPath.startPoint).loc
val nextCoord = nextActivity(data).get.getCoord
goto(ChoosingMode) using ChoosesModeData(
data.copy(numberOfReplanningAttempts = data.numberOfReplanningAttempts + 1),
currentLocation = SpaceTime(currentCoord, _currentTick.get),
Expand Down Expand Up @@ -975,11 +993,18 @@ class PersonAgent(
case Event(NotAvailable(_), basePersonData: BasePersonData) =>
log.debug("{} replanning because vehicle not available when trying to board")
val replanningReason = getReplanningReasonFrom(basePersonData, ReservationErrorCode.ResourceUnavailable.entryName)
eventsManager.processEvent(
new ReplanningEvent(_currentTick.get, Id.createPersonId(id), replanningReason)
)
val currentCoord =
beamServices.geo.wgs2Utm(basePersonData.restOfCurrentTrip.head.beamLeg.travelPath.startPoint).loc
eventsManager.processEvent(
new ReplanningEvent(
_currentTick.get,
Id.createPersonId(id),
replanningReason,
currentCoord.getX,
currentCoord.getY
)
)

val nextCoord = nextActivity(basePersonData).get.getCoord
goto(ChoosingMode) using ChoosesModeData(
basePersonData.copy(
Expand Down Expand Up @@ -1168,10 +1193,17 @@ class PersonAgent(
log.debug("Missed transit pickup, late by {} sec", _currentTick.get - nextLeg.beamLeg.startTime)

val replanningReason = getReplanningReasonFrom(data, ReservationErrorCode.MissedTransitPickup.entryName)
val currentCoord = beamServices.geo.wgs2Utm(nextLeg.beamLeg.travelPath.startPoint).loc
eventsManager.processEvent(
new ReplanningEvent(_currentTick.get, Id.createPersonId(id), replanningReason)
new ReplanningEvent(
_currentTick.get,
Id.createPersonId(id),
replanningReason,
currentCoord.getX,
currentCoord.getY
)
)
val currentCoord = beamServices.geo.wgs2Utm(nextLeg.beamLeg.travelPath.startPoint).loc

val nextCoord = nextActivity(data).get.getCoord
goto(ChoosingMode) using ChoosesModeData(
personData = data
Expand Down Expand Up @@ -1234,10 +1266,17 @@ class PersonAgent(
log.warning("Missed CAV pickup, late by {} sec", _currentTick.get - nextLeg.beamLeg.startTime)

val replanningReason = getReplanningReasonFrom(data, ReservationErrorCode.MissedTransitPickup.entryName)
val currentCoord = beamServices.geo.wgs2Utm(nextLeg.beamLeg.travelPath.startPoint).loc
eventsManager.processEvent(
new ReplanningEvent(_currentTick.get, Id.createPersonId(id), replanningReason)
new ReplanningEvent(
_currentTick.get,
Id.createPersonId(id),
replanningReason,
currentCoord.getX,
currentCoord.getY
)
)
val currentCoord = beamServices.geo.wgs2Utm(nextLeg.beamLeg.travelPath.startPoint).loc

val nextCoord = nextActivity(data).get.getCoord
goto(ChoosingMode) using ChoosesModeData(
personData = data
Expand Down Expand Up @@ -1460,6 +1499,24 @@ class PersonAgent(
}
}

def getTazFromActivity(activity: Activity): Id[TAZ] = {
val linkId = Option(activity.getLinkId).getOrElse(
Id.createLinkId(
beamServices.geo
.getNearestR5EdgeToUTMCoord(
beamServices.beamScenario.transportNetwork.streetLayer,
activity.getCoord,
beamScenario.beamConfig.beam.routing.r5.linkRadiusMeters
)
.toString
)
)
beamScenario.tazTreeMap
.getTAZfromLink(linkId)
.map(_.tazId)
.getOrElse(beamScenario.tazTreeMap.getTAZ(activity.getCoord).tazId)
}

def generateSkimData(
tick: Int,
trip: EmbodiedBeamTrip,
Expand Down Expand Up @@ -1489,18 +1546,10 @@ class PersonAgent(
)
eventsManager.processEvent(odSkimmerEvent)
if (beamServices.beamConfig.beam.exchange.output.activitySimSkimsEnabled) {
val startLink = currentActivity.getLinkId
val endLinkOption = nextActivity.map(_.getLinkId)
val (origin, destination) =
if (beamScenario.tazTreeMap.tazListContainsGeoms && endLinkOption.isDefined) {
val origGeo = beamScenario.tazTreeMap
.getTAZfromLink(startLink)
.map(_.tazId.toString)
.getOrElse("NA")
val destGeo = beamScenario.tazTreeMap
.getTAZfromLink(endLinkOption.get)
.map(_.tazId.toString)
.getOrElse("NA")
if (beamScenario.tazTreeMap.tazListContainsGeoms) {
val origGeo = getTazFromActivity(currentActivity).toString
val destGeo = nextActivity.map(getTazFromActivity(_).toString).getOrElse("NA")
(origGeo, destGeo)
} else {
beamScenario.exchangeGeoMap match {
Expand Down
Loading