@Override public boolean applyAgentFilter(Id<Person> id, double time) { MobsimAgent agent = this.agents.get(id); if (!(links.contains(agent.getCurrentLinkId()))) return false; else return true; } }
private void unregisterAgentAtActivityLocation(final MobsimAgent agent) { Id<Person> agentId = agent.getId(); Id<Link> linkId = agent.getCurrentLinkId(); if (linkId != null) { // may be bushwacking internalInterface.unregisterAdditionalAgentOnLink(agentId, linkId); } }
private void unregisterAgentAtActivityLocation(final MobsimAgent agent) { Id<Person> agentId = agent.getId(); Id<Link> linkId = agent.getCurrentLinkId(); if (linkId != null) { // may be bushwacking internalInterface.unregisterAdditionalAgentOnLink(agentId, linkId); } }
public final void registerAdditionalAgentOnLink(final MobsimAgent planAgent) { Id<Link> linkId = planAgent.getCurrentLinkId(); if (linkId != null) { // may be bushwacking QLinkI qLink = this.network.getNetsimLink(linkId); if ( qLink==null ) { throw new RuntimeException("netsim link lookup failed; agentId=" + planAgent.getId() + "; linkId=" + linkId ) ; } qLink.registerAdditionalAgentOnLink(planAgent); } }
private List<? extends PlanElement> newTripToNewActivity(Activity newAct, String mainMode, double now, MobsimAgent agent, Person person, Scenario scenario) { log.debug("entering newTripToNewActivity") ; Link currentLink = scenario.getNetwork().getLinks().get( agent.getCurrentLinkId() ) ; Facility fromFacility = new LinkWrapperFacility( currentLink ) ; Facility toFacility = scenario.getActivityFacilities().getFacilities().get( newAct.getFacilityId() ) ; if ( toFacility == null ) { toFacility = new ActivityWrapperFacility( newAct ) ; } List<? extends PlanElement> newTrip = tripRouter.calcRoute(mainMode, fromFacility, toFacility, now, person) ; return newTrip; } // replan from stage activity:
final MobsimAgent agent, final Id linkId) { assert agent.getCurrentLinkId().equals( linkId ) : agent+" not at link "+linkId;
private static void replaceRemainderOfCurrentRoute(Leg currentLeg, List<? extends PlanElement> newTrip, MobsimAgent agent) { Leg newCurrentLeg = (Leg) newTrip.get(0) ; Gbl.assertNotNull(newCurrentLeg); // prune remaining route from current route: NetworkRoute oldNWRoute = (NetworkRoute) currentLeg.getRoute(); final Integer currentRouteLinkIdIndex = WithinDayAgentUtils.getCurrentRouteLinkIdIndex(agent); final NetworkRoute newNWRoute = (NetworkRoute)newCurrentLeg.getRoute(); final List<Id<Link>> newLinksIds = newNWRoute.getLinkIds().subList(0,newNWRoute.getLinkIds().size()) ; EditRoutes.spliceNewPathIntoOldRoute(currentRouteLinkIdIndex, newNWRoute.getEndLinkId(), oldNWRoute, newLinksIds, agent.getCurrentLinkId()) ; // for (int ii = currentRouteLinkIdIndex; ii<oldNWRoute.getLinkIds().size() ; ii++ ) { // oldNWRoute.getLinkIds().remove(ii) ; // } // // // now add the new route (yyyyyy not sure if it starts with correct link) // oldNWRoute.getLinkIds().addAll( newNWRoute.getLinkIds() ) ; // // // also change the arrival link id: // oldNWRoute.setEndLinkId( newNWRoute.getEndLinkId() ) ; WithinDayAgentUtils.resetCaches(agent); } private static void pruneUpToCurrentLeg(Leg currentLeg, List<? extends PlanElement> newTrip) {
/** * 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)") ; } }
@Override public boolean handlePassengerEntering(PTPassengerAgent passenger, MobsimVehicle vehicle, Id<TransitStopFacility> fromStopFacilityId, double time) { boolean handled = vehicle.addPassenger(passenger); if(handled){ this.agentTracker.removeAgentFromStop(passenger, fromStopFacilityId); MobsimAgent planAgent = (MobsimAgent) passenger; // if (planAgent instanceof PersonDriverAgentImpl) { Id<Person> agentId = planAgent.getId(); Id<Link> linkId = planAgent.getCurrentLinkId(); this.internalInterface.unregisterAdditionalAgentOnLink(agentId, linkId) ; // } MobsimDriverAgent agent = (MobsimDriverAgent) passenger; eventsManager.processEvent(new PersonEntersVehicleEvent(time, agent.getId(), vehicle.getVehicle().getId())); } return handled; }
switch(perceptID) { case PerceptList.REQUEST_LOCATION: final Link link = scenario.getNetwork().getLinks().get( this.getMobsimAgentFromIdString(agentID).getCurrentLinkId() ); Location[] coords = { new Location(link.getFromNode().getId().toString(), link.getFromNode().getCoord().getX(), link.getFromNode().getCoord().getY()), final Link destLink = NetworkUtils.getNearestLink(getScenario().getNetwork(), coord ); Gbl.assertNotNull(destLink); final Link currentLink = scenario.getNetwork().getLinks().get( this.getMobsimAgentFromIdString(agentID).getCurrentLinkId() ); final double now = getTime();
@Override public void insertAgentsIntoMobsim() { for (MobSimVehicleRoute vRoute : vehicleRoutes) { MobsimAgent agent = this.agentFactory.createMobsimAgentFromPerson(vRoute.getPlan().getPerson()); Vehicle vehicle = null; if(vRoute.getVehicle() == null){ vehicle = VehicleUtils.getFactory().createVehicle(Id.create(agent.getId(), Vehicle.class), VehicleUtils.getDefaultVehicleType()); log.warn("vehicle for agent "+vRoute.getPlan().getPerson().getId() + " is missing. set default vehicle where maxVelocity is solely defined by link.speed."); } else if(vRoute.getVehicle().getType() == null){ vehicle = VehicleUtils.getFactory().createVehicle(Id.create(agent.getId(), Vehicle.class), VehicleUtils.getDefaultVehicleType()); log.warn("vehicleType for agent "+vRoute.getPlan().getPerson().getId() + " is missing. set default vehicleType where maxVelocity is solely defined by link.speed."); } else vehicle = vRoute.getVehicle(); // qsim.createAndParkVehicleOnLink(vehicle, agent.getCurrentLinkId()); QVehicle qVehicle = new QVehicleImpl( vehicle ) ; qsim.addParkedVehicle( qVehicle, agent.getCurrentLinkId() ); // yyyyyy should rather use QVehicleFactory. kai, nov'18 qsim.insertAgentIntoMobsim(agent); mobSimAgents.add(agent); } }
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();
/** * @param mobsimAgent * @param now * @return <code>true</code> if the agent was successfully moved over the node, <code>false</code> * otherwise (e.g. in case where the next link is jammed - not yet implemented) */ boolean moveAgentOverNode(final MobsimAgent mobsimAgent, final double now) { Id<Link> currentLinkId = mobsimAgent.getCurrentLinkId(); Id<Link> nextLinkId = ((MobsimDriverAgent) mobsimAgent).chooseNextLinkId(); Link currentLink = this.simEngine.getMultiModalQLinkExtension(currentLinkId).getLink(); if (nextLinkId != null) { Link nextLink = this.simEngine.getMultiModalQLinkExtension(nextLinkId).getLink(); if ( this.checkNextLinkSemantics(currentLink, nextLink, mobsimAgent) == false ) { moveToAbort(mobsimAgent, now, currentLink, nextLink); } else { // move Agent over the Node ((MobsimDriverAgent)mobsimAgent).notifyMoveOverNode(nextLinkId); this.simEngine.getMultiModalQLinkExtension(nextLinkId).addAgentFromIntersection(mobsimAgent, now); } } // --> nextLink == null else { moveToAbort(mobsimAgent, now, currentLink, null); } return true; }