Skip to content

Commit

Permalink
account for teleportation of bicyclist in DistanceBasedMoneyReward
Browse files Browse the repository at this point in the history
  • Loading branch information
GregorRyb committed Jul 19, 2023
1 parent 7174a2f commit f40bf60
Showing 1 changed file with 20 additions and 32 deletions.
52 changes: 20 additions & 32 deletions src/main/java/org/matsim/policies/DistanceBasedMoneyReward.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
public class DistanceBasedMoneyReward implements PersonDepartureEventHandler,
PersonArrivalEventHandler,
AfterMobsimListener,
PersonEntersVehicleEventHandler,
PersonLeavesVehicleEventHandler,
LinkLeaveEventHandler,
ActivityStartEventHandler {

private final Map<Id<Person>, Double> distanceTravelledWalk = new HashMap<>();
Expand Down Expand Up @@ -64,6 +61,23 @@ public void handleEvent(PersonArrivalEvent event) {
}
}
}

if (event.getLegMode().equals("bicycle")) {
Id<Link> linkId = event.getLinkId();
Coord endcoord = network.getLinks().get(linkId).getCoord();
Coord startCoord = this.agentDepartureLocations.get(event.getPersonId());
if (startCoord != null) {
double beelineDistance = CoordUtils.calcEuclideanDistance(startCoord, endcoord);
double distance = beelineDistance * beelineDistanceFactor;
if (!distanceTravelledBike.containsKey(event.getPersonId())) {
distanceTravelledBike.put(event.getPersonId(), distance);
} else {
distance = distanceTravelledBike.get(event.getPersonId()) + distance;
distanceTravelledBike.replace(event.getPersonId(), distance);
}
}
}

}

@Override
Expand All @@ -77,24 +91,13 @@ public void handleEvent(PersonDepartureEvent event) {
}

if (event.getRoutingMode().equals(TransportMode.bike) || event.getRoutingMode().equals("bicycle")) {
if (!distanceTravelledBike.containsKey(event.getPersonId())) {
distanceTravelledBike.put(event.getPersonId(), 0.0);
}
Id<Link> linkId = event.getLinkId();
Coord coord = network.getLinks().get(linkId).getCoord();
this.agentDepartureLocations.put(event.getPersonId(), coord);
}
}
}

@Override
public void handleEvent(PersonEntersVehicleEvent personEntersVehicleEvent) {
vehicles2Persons.put(personEntersVehicleEvent.getVehicleId(), personEntersVehicleEvent.getPersonId());
}

@Override
public void handleEvent(PersonLeavesVehicleEvent personLeavesVehicleEvent) {
if (vehicles2Persons.containsKey(personLeavesVehicleEvent.getVehicleId())) {
vehicles2Persons.remove(personLeavesVehicleEvent.getVehicleId());
}
}

@Override
public void reset(int iteration) {
Expand Down Expand Up @@ -129,21 +132,6 @@ public void notifyAfterMobsim(AfterMobsimEvent afterMobsimEvent) {
}
}

@Override
public void handleEvent(LinkLeaveEvent linkLeaveEvent) {
if (vehicles2Persons.containsKey(linkLeaveEvent.getVehicleId())) {
Id<Person> personId = vehicles2Persons.get(linkLeaveEvent.getVehicleId());
if (distanceTravelledBike.containsKey(personId)) {
double linkLength = network.getLinks().get(linkLeaveEvent.getLinkId()).getLength();
double distanceTravelled = distanceTravelledBike.get(personId) + linkLength;
distanceTravelledBike.replace(personId, distanceTravelled);
}
}

}




@Override
public void handleEvent(ActivityStartEvent event) {
Expand Down

0 comments on commit f40bf60

Please sign in to comment.