@Override public boolean handleDeparture(double now, MobsimAgent mobsimAgent, Id linkId) { if (handledModes.contains(mobsimAgent.getMode())) { if (mobsimAgent instanceof MobsimDriverAgent) { handleMultiModalDeparture(now, (MobsimDriverAgent)mobsimAgent, linkId); return true; } else { throw new UnsupportedOperationException("MobsimAgent is not from type MobsimDriverAgent - cannot handle departure. Found PersonAgent class is " + mobsimAgent.getClass().toString()); } } return false; }
@Override public boolean applyAgentFilter(Id<Person> id, double time) { MobsimAgent agent = this.agents.get(id); if (!(agent.getState() == MobsimAgent.State.LEG)) return false; if (!(modes.contains(agent.getMode()))) return false; return true; } }
@Override public boolean handleDeparture(double now, MobsimAgent agent, Id<Link> linkId) { if (this.transportModes.contains(agent.getMode())) { if ( agent instanceof MobsimDriverAgent ) { handleCarDeparture(now, (MobsimDriverAgent)agent, linkId); return true; } else { throw new UnsupportedOperationException("wrong agent type to depart on a network mode"); } } return false; }
private void addAgent(MobsimAgent mobsimAgent, double now) { Map<String, TravelTime> multiModalTravelTime = this.simEngine.getMultiModalTravelTimes(); Person person = null; if (mobsimAgent instanceof HasPerson) { person = ((HasPerson) mobsimAgent).getPerson(); } double travelTime = multiModalTravelTime.get(mobsimAgent.getMode()).getLinkTravelTime(link, now, person, null); double departureTime = now + travelTime; departureTime = Math.round(departureTime); this.agents.add(new Tuple<>(departureTime, mobsimAgent)); }
@Override public boolean handleDeparture( final double now, final MobsimAgent agent, final Id linkId) { final String mode = agent.getMode(); if ( mode.equals( JointActingTypes.DRIVER ) ) { if ( log.isTraceEnabled() ) { log.trace( "Handling DRIVER departure for agent "+agent ); } handleDriverDeparture( now , agent , linkId ); return true; } if ( mode.equals( JointActingTypes.PASSENGER ) ) { if ( log.isTraceEnabled() ) { log.trace( "Handling PASSENGER departure for agent "+agent ); } handlePassengerDeparture( now , agent , linkId ); return true; } return departureHandler.handleDeparture( now , agent , linkId ); }
@Override public boolean handleDeparture(double now, MobsimAgent agent, Id<Link> linkId) { String requestedMode = agent.getMode(); if (qSim.getScenario().getConfig().transit().getTransitModes().contains(requestedMode)) { handleAgentPTDeparture(agent, linkId); return true ; } return false ; }
@Override public void afterSim() { double now = this.qSim.getSimTimer().getTimeOfDay(); for (Entry<Id<TransitStopFacility>, List<PTPassengerAgent>> agentsAtStop : this.agentTracker.getAgentsAtStop().entrySet()) { TransitStopFacility stop = this.schedule.getFacilities().get(agentsAtStop.getKey()); for (PTPassengerAgent agent : agentsAtStop.getValue()) { this.qSim.getEventsManager().processEvent(new PersonStuckEvent( now, agent.getId(), stop.getLinkId(), ((MobsimAgent)agent).getMode())); this.qSim.getAgentCounter().decLiving(); this.qSim.getAgentCounter().incLost(); } } }
@Override public void afterSim() { double now = internalInterface.getMobsim().getSimTimer().getTimeOfDay(); for (Tuple<Double, MobsimAgent> entry : teleportationList) { MobsimAgent agent = entry.getSecond(); eventsManager.processEvent(new PersonStuckEvent(now, agent.getId(), agent.getDestinationLinkId(), agent.getMode())); } teleportationList.clear(); }
@Override public boolean handleDeparture(double now, MobsimAgent agent, Id<Link> linkId) { if ( agent.getExpectedTravelTime()==null || agent.getExpectedTravelTime()==Time.UNDEFINED_TIME ) { Logger.getLogger( this.getClass() ).info( "mode: " + agent.getMode() ); throw new RuntimeException("teleportation does not work when travel time is undefined. There is also really no magic fix for this," + " since we cannot guess travel times for arbitrary modes and arbitrary landscapes. kai/mz, apr'15 & feb'16") ; } Double travelTime = agent.getExpectedTravelTime() ; if ( withTravelTimeCheck ) { Double speed = scenario.getConfig().plansCalcRoute().getTeleportedModeSpeeds().get( agent.getMode() ) ; Facility dpfac = agent.getCurrentFacility() ; Facility arfac = agent.getDestinationFacility() ; travelTime = DefaultTeleportationEngine.travelTimeCheck(travelTime, speed, dpfac, arfac); } double arrivalTime = now + travelTime ; this.teleportationList.add(new Tuple<>(arrivalTime, agent)); // === below here is only visualization, no dynamics === Id<Person> agentId = agent.getId(); Link currLink = this.scenario .getNetwork().getLinks().get(linkId); Link destLink = this.scenario .getNetwork().getLinks().get(agent.getDestinationLinkId()); Coord fromCoord = currLink.getToNode().getCoord(); Coord toCoord = destLink.getToNode().getCoord(); TeleportationVisData agentInfo = new TeleportationVisData(now, agentId, fromCoord, toCoord, travelTime); this.teleportationData.put(agentId, agentInfo); return true; }
@Override public boolean handleDeparture(double now, MobsimAgent agent, Id<Link> fromLinkId) { if (!agent.getMode().equals(mode)) { return false; } MobsimPassengerAgent passenger = (MobsimPassengerAgent)agent; Id<Link> toLinkId = passenger.getDestinationLinkId(); double departureTime = now; internalInterface.registerAdditionalAgentOnLink(passenger); PassengerRequest prebookedRequest = advanceRequestStorage.retrieveAdvanceRequest(passenger, fromLinkId, toLinkId, now); if (prebookedRequest == null) {// this is an immediate request //TODO what if it was already rejected while prebooking?? createValidateAndSubmitRequest(passenger, fromLinkId, toLinkId, departureTime, now); } else { passengersByRequestId.put(prebookedRequest.getId(), passenger); PassengerPickupActivity awaitingPickup = awaitingPickupStorage.retrieveAwaitingPickup(prebookedRequest); if (awaitingPickup != null) { awaitingPickup.notifyPassengerIsReadyForDeparture(passenger, now); } } // always mark the departure as handled, even if rejected, in order to get more consistency with rejections // that are decided later (for instance, during optimisation which is usually called in the next sim step) // michalm, sep'18 // See: github.com/matsim-org/matsim/pull/362 for some more discussion return true;//!request.isRejected(); }
/** * Informs the simulation that the specified agent wants to depart from its * current activity. The simulation can then put the agent onto its vehicle * on a link or teleport it to its destination. * */ private void arrangeAgentDeparture(final MobsimAgent agent) { double now = this.getSimTimer().getTimeOfDay(); Id<Link> linkId = agent.getCurrentLinkId(); Gbl.assertIf( linkId!=null ); events.processEvent(new PersonDepartureEvent(now, agent.getId(), linkId, agent.getMode())); for (DepartureHandler departureHandler : this.departureHandlers) { if (departureHandler.handleDeparture(now, agent, linkId)) { return; } } log.warn("no departure handler wanted to handle the departure of agent " + agent.getId()); // yy my intuition is that this should be followed by setting the agent state to abort. kai, nov'14 }
private void arrangeNextAgentAction(final MobsimAgent agent) { switch( agent.getState() ) { case ACTIVITY: arrangeAgentActivity(agent); break ; case LEG: this.arrangeAgentDeparture(agent); break ; case ABORT: this.events.processEvent( new PersonStuckEvent(this.simTimer.getTimeOfDay(), agent.getId(), agent.getCurrentLinkId(), agent.getMode())); // NOTE: in the same way as one can register departure handler or activity handler, we could allow to // register abort handlers. If someone ever comes to this place here and needs this. kai, nov'17 this.agents.remove(agent.getId()) ; this.agentCounter.decLiving(); this.agentCounter.incLost(); break ; default: throw new RuntimeException("agent with unknown state (possibly null)") ; } }
public void addDepartingAgent(MobsimAgent mobsimAgent, double now) { this.waitingAfterActivityAgents.add(mobsimAgent); this.activateLink(); this.simEngine.getEventsManager().processEvent( new PersonEntersVehicleEvent(now, mobsimAgent.getId(), Id.create(mobsimAgent.getId(), Vehicle.class))); this.simEngine.getEventsManager().processEvent( new VehicleEntersTrafficEvent(now, mobsimAgent.getId(), link.getId(), Id.create(mobsimAgent.getId(), Vehicle.class), mobsimAgent.getMode(), 1.0)); }
new PersonStuckEvent(now, mobsimAgent.getId(), veh.getCurrentLink().getId(), mobsimAgent.getMode())); context.getAgentCounter().incLost(); context.getAgentCounter().decLiving(); new PersonStuckEvent(now, driver.getId(), driver.getCurrentLinkId(), driver.getMode())); context.getAgentCounter().incLost(); context.getAgentCounter().decLiving(); new PersonStuckEvent(now, driver.getId(), driver.getCurrentLinkId(), driver.getMode())); context.getAgentCounter().incLost(); context.getAgentCounter().decLiving(); new PersonStuckEvent(now, passenger.getId(), passenger.getCurrentLinkId(), passenger.getMode())); this.context.getAgentCounter().incLost(); this.context.getAgentCounter().decLiving();
new VehicleAbortsEvent(now, Id.create(mobsimAgent.getId(), Vehicle.class), link.getId())); this.simEngine.getMobsim().getEventsManager().processEvent( new PersonStuckEvent(now, mobsimAgent.getId(), link.getId(), mobsimAgent.getMode())); this.simEngine.getMobsim().getAgentCounter().incLost(); this.simEngine.getMobsim().getAgentCounter().decLiving(); new VehicleAbortsEvent(now, Id.create(mobsimAgent.getId(), Vehicle.class), link.getId())); this.simEngine.getMobsim().getEventsManager().processEvent( new PersonStuckEvent(now, mobsimAgent.getId(), link.getId(), mobsimAgent.getMode())); this.simEngine.getMobsim().getAgentCounter().incLost(); this.simEngine.getMobsim().getAgentCounter().decLiving(); new VehicleAbortsEvent(now, Id.create(mobsimAgent.getId(), Vehicle.class), link.getId())); this.simEngine.getMobsim().getEventsManager().processEvent( new PersonStuckEvent(now, mobsimAgent.getId(), link.getId(), mobsimAgent.getMode())); this.simEngine.getMobsim().getAgentCounter().incLost(); this.simEngine.getMobsim().getAgentCounter().decLiving();