@Override public void handleEvent(PersonArrivalEvent event) { try { if (isTransitScenario) { if (transitDriverIds.contains(event.getPersonId())) return; } TravellerChain chain = chains.get(event.getPersonId()); switch (event.getLegMode()) { case "walk": case "transit_walk": { Journey journey = chain.getJourneys().getLast(); Walk walk = journey.getWalks().getLast(); walk.setDest(network.getLinks().get(event.getLinkId()).getCoord()); walk.setEndTime(event.getTime()); walk.setDistance(walk.getDuration() * walkSpeed); break; } case TransportMode.car: { Journey journey = chain.getJourneys().getLast(); journey.setDest(network.getLinks().get(event.getLinkId()).getCoord()); journey.setEndTime(event.getTime()); Trip trip = journey.getTrips().getLast(); trip.setDistance(journey.getDistance()); trip.setEndTime(event.getTime()); chain.inCar = false; break; } case "pt": if (isTransitScenario) { Journey journey = chain.getJourneys().getLast(); Trip trip = journey.getTrips().getLast(); trip.setDest(network.getLinks().get(event.getLinkId()).getCoord()); trip.setEndTime(event.getTime()); journey.setPossibleTransfer(new Transfer()); journey.getPossibleTransfer().setStartTime(event.getTime()); journey.getPossibleTransfer().setFromTrip(trip); } else { Journey journey = chain.getJourneys().getLast(); journey.setEndTime(event.getTime()); journey.setDest(network.getLinks().get(event.getLinkId()).getCoord()); journey.setEndTime(event.getTime()); } break; default: Journey journey = chain.getJourneys().getLast(); journey.setEndTime(event.getTime()); journey.setDest(network.getLinks().get(event.getLinkId()).getCoord()); journey.setEndTime(event.getTime()); break; } } catch (Exception e) { System.err.println(e.getStackTrace()); System.err.println(event.toString()); } }
public void testRoundTrip_1(String resource) throws Exception { long start1 = System.currentTimeMillis(); String originalFile = this.getClass().getProtectionDomain().getCodeSource().getLocation().getFile() + resource; long start2 = System.currentTimeMillis(); IsoFile isoFile = new IsoFile(originalFile); long start3 = System.currentTimeMillis(); long start4 = System.currentTimeMillis(); Walk.through(isoFile); long start5 = System.currentTimeMillis(); File result = File.createTempFile(this.getName(), resource.replace("/", "_")); FileOutputStream fos = new FileOutputStream(result); FileChannel fcOut = fos.getChannel(); isoFile.getBox(fcOut); fcOut.close(); fos.close(); long start6 = System.currentTimeMillis(); /* System.err.println("Preparing tmp copy took: " + (start2 - start1) + "ms"); System.err.println("Parsing took : " + (start3 - start2) + "ms"); System.err.println("Writing took : " + (start6 - start3) + "ms"); System.err.println("Walking took : " + (start5 - start4) + "ms");*/ IsoFile copyViaIsoFileReparsed = new IsoFile(result.getAbsolutePath()); BoxComparator.check( isoFile, copyViaIsoFileReparsed, "/moov[0]/mvhd[0]", "/moov[0]/trak[0]/tkhd[0]", "/moov[0]/trak[0]/mdia[0]/mdhd[0]"); isoFile.close(); copyViaIsoFileReparsed.close(); result.deleteOnExit(); // as windows cannot delete file when something is memory mapped and the garbage collector // doesn't necessarily free the Buffers quickly enough we cannot delete the file here (we could // but only for linux) }
@Override public void handleEvent(PersonDepartureEvent event) { try { if (transitDriverIds.contains(event.getPersonId())) return; TravellerChain chain = chains.get(event.getPersonId()); Journey journey; Trip trip; switch (event.getLegMode()) { case TransportMode.walk: // fall through to the next case TransportMode.transit_walk: if (!chain.traveling) { chain.traveling = true; journey = chain.addJourney(); journey.setOrig(network.getLinks().get(event.getLinkId()).getCoord()); journey.setFromAct(chain.getActs().getLast()); journey.setStartTime(event.getTime()); Walk walk = journey.addWalk(); walk.setAccessWalk(true); walk.setStartTime(event.getTime()); walk.setOrig(journey.getOrig()); } else { journey = chain.getJourneys().getLast(); Walk walk = journey.addWalk(); walk.setStartTime(event.getTime()); walk.setOrig(network.getLinks().get(event.getLinkId()).getCoord()); journey.getPossibleTransfer().getWalks().add(walk); } break; case TransportMode.car: chain.inCar = true; journey = chain.addJourney(); journey.setCarJourney(true); journey.setOrig(network.getLinks().get(event.getLinkId()).getCoord()); journey.setFromAct(chain.getActs().getLast()); journey.setStartTime(event.getTime()); trip = journey.addTrip(); trip.setMode("car"); trip.setStartTime(event.getTime()); break; case TransportMode.pt: if (isTransitScenario) { // person waits till they enter the vehicle journey = chain.getJourneys().getLast(); Wait wait = journey.addWait(); if (journey.getWaits().size() == 1) wait.setAccessWait(true); wait.setStartTime(event.getTime()); wait.setCoord(network.getLinks().get(event.getLinkId()).getCoord()); if (!wait.isAccessWait()) { journey.getPossibleTransfer().getWaits().add(wait); } } else { journey = chain.addJourney(); journey.setTeleportJourney(true); journey.setOrig(network.getLinks().get(event.getLinkId()).getCoord()); journey.setFromAct(chain.getActs().getLast()); journey.setStartTime(event.getTime()); journey.setMainmode(event.getLegMode()); trip = journey.addTrip(); trip.setMode(event.getLegMode()); trip.setStartTime(event.getTime()); } break; default: journey = chain.addJourney(); journey.setTeleportJourney(true); journey.setOrig(network.getLinks().get(event.getLinkId()).getCoord()); journey.setFromAct(chain.getActs().getLast()); journey.setStartTime(event.getTime()); journey.setMainmode(event.getLegMode()); trip = journey.addTrip(); trip.setMode(event.getLegMode()); trip.setStartTime(event.getTime()); break; } } catch (Exception e) { System.err.println(e.getStackTrace()); System.err.println(event.toString()); } }