@Override public void handleEvent(LinkLeaveEvent event) { if (event.getVehicleId().toString().startsWith("tr")) { PTVehicle vehicle = ptVehicles.get(event.getVehicleId()); if (vehicle.in) { vehicle.in = false; vehicle.incDistance(network.getLinks().get(event.getLinkId()).getLength()); } } else { TravellerChain chain = chains.get(event.getDriverId()); if (chain == null) { chain = new TravellerChain(); chains.put(event.getDriverId(), chain); chain.modes.add("car"); chain.distances.add(0.0); } else { if (chain.in) { chain.in = false; if (chain.modes.size() == chain.distances.size() && chain.modes.get(chain.modes.size() - 1).equals("car")) { double linkDistance = network.getLinks().get(event.getLinkId()).getLength(); chain.distances.set( chain.distances.size() - 1, chain.distances.get(chain.distances.size() - 1) + linkDistance); } else if (chain.modes.size() == chain.distances.size()) throw new RuntimeException("Person is leaving a link, but is not in a car mode"); else throw new RuntimeException("Modes list has not the same size of distances list (car)"); } else { chain.modes.add("car"); chain.distances.add(0.0); } } } }
@Override public void handleEvent(LinkEnterEvent event) { try { if (ptVehicles.keySet().contains(event.getVehicleId())) { PTVehicle ptVehicle = ptVehicles.get(event.getVehicleId()); ptVehicle.in = true; ptVehicle.setLinkEnterTime(event.getTime()); } else { chains .get(driverIdFromVehicleId.get(event.getVehicleId())) .setLinkEnterTime(event.getTime()); } } catch (Exception e) { System.err.println(e.getStackTrace()); System.err.println(event.toString()); } }
@Override public void handleEvent(LinkLeaveEvent event) { try { if (ptVehicles.keySet().contains(event.getVehicleId())) { PTVehicle vehicle = ptVehicles.get(event.getVehicleId()); if (vehicle.in) vehicle.in = false; vehicle.incDistance(network.getLinks().get(event.getLinkId()).getLength()); } else { TravellerChain chain = chains.get(driverIdFromVehicleId.get(event.getVehicleId())); if (chain.inCar) { Journey journey = chain.getJourneys().getLast(); journey.incrementCarDistance(network.getLinks().get(event.getLinkId()).getLength()); } } } catch (Exception e) { System.err.println(e.getStackTrace()); System.err.println(event.toString()); } }