private void processArrivalOfHoles() { double now = context.getSimTimer().getTimeOfDay() ; while ( this.holes.size()>0 && this.holes.peek().getEarliestLinkExitTime() < now ) { Hole hole = this.holes.poll() ; // ??? this.remainingHolesStorageCapacity += hole.getSizeInEquivalents() ; } }
private final QVehicle removeFirstVehicle(){ double now = context.getSimTimer().getTimeOfDay() ; QVehicle veh = buffer.poll(); bufferLastMovedTime = now; // just in case there is another vehicle in the buffer that is now the new front-most if( context.qsimConfig.isUsingFastCapacityUpdate() ) { flowcap_accumulate.setTimeStep(now - 1); } return veh; }
private void updateFastFlowAccumulation(){ double now = context.getSimTimer().getTimeOfDay() ; if( this.flowcap_accumulate.getTimeStep() < now && this.flowcap_accumulate.getValue() < flowCapacityPerTimeStep && isNotOfferingVehicle() ){ double timeSteps = (now - flowcap_accumulate.getTimeStep()) / context.qsimConfig.getTimeStepSize(); double accumulateFlowCap = timeSteps * flowCapacityPerTimeStep; double newFlowCap = Math.min(flowcap_accumulate.getValue() + accumulateFlowCap, flowCapacityPerTimeStep); flowcap_accumulate.setValue(newFlowCap); flowcap_accumulate.setTimeStep( now ); } }
private void addToBuffer(final QVehicle veh) { // yy might make sense to just accumulate to "zero" and go into negative when something is used up. // kai/mz/amit, mar'12 double now = context.getSimTimer().getTimeOfDay() ; flowcap_accumulate.addValue(-veh.getFlowCapacityConsumptionInEquivalents(), now); buffer.add(veh); if (buffer.size() == 1) { bufferLastMovedTime = now; // (if there is one vehicle in the buffer now, there were zero vehicles in the buffer before. in consequence, // need to reset the lastMovedTime. If, in contrast, there was already a vehicle in the buffer before, we can // use the lastMovedTime that was (somehow) computed for that vehicle.) } final QNodeI toNode = qLink.getToNodeQ(); if ( toNode instanceof QNodeImpl ) { ((QNodeImpl) toNode).activateNode(); // yy for an "upstream" QLane, this activates the toNode too early. Yet I think I founds this // also in the original QLane code. kai, sep'13 } }
@Override public final void letVehicleDepart(QVehicle vehicle) { double now = context.getSimTimer().getTimeOfDay(); MobsimDriverAgent driver = vehicle.getDriver(); if (driver == null) throw new RuntimeException("Vehicle cannot depart without a driver!"); EventsManager eventsManager = context.getEventsManager(); eventsManager.processEvent(new PersonEntersVehicleEvent(now, driver.getId(), vehicle.getId())); this.addDepartingVehicle(vehicle); }
@Override public final boolean insertPassengerIntoVehicle(MobsimAgent passenger, Id<Vehicle> vehicleId) { double now = context.getSimTimer().getTimeOfDay(); QVehicle vehicle = this.getParkedVehicle(vehicleId); // if the vehicle is not parked at the link, mark the agent as passenger waiting for vehicle if (vehicle == null) { registerPassengerAgentWaitingForCar(passenger, vehicleId); return false; } else { boolean added = vehicle.addPassenger((PassengerAgent) passenger); if (!added) { log.warn("Passenger " + passenger.getId().toString() + " could not be inserted into vehicle " + vehicleId.toString() + " since there is no free seat available!"); return false; } ((PassengerAgent) passenger).setVehicle(vehicle); EventsManager eventsManager = context.getEventsManager(); eventsManager.processEvent(new PersonEntersVehicleEvent(now, passenger.getId(), vehicle.getId())); // TODO: allow setting passenger's currentLinkId to null return true; } }
double now = context.getSimTimer().getTimeOfDay() ;
@Override public void recalcTimeVariantAttributes() { double now = context.getSimTimer().getTimeOfDay() ; qlane.changeUnscaledFlowCapacityPerSecond( this.getLink().getFlowCapacityPerSec(now ) ); qlane.changeEffectiveNumberOfLanes(this.getLink().getNumberOfLanes(now)); // qlane.changeSpeedMetersPerSecond( getLink().getFreespeed(now) ) ; flowCap & nLanes are "push", freeSpeed is //"pull". This is not completely honest w.r.t. freeSpeed consequences to the fdiag, but also wasn't correctly //thought through/implemented when I found it. kai, feb'18 qlane.recalcTimeVariantAttributes(); }
private QVehicle peekFromVehQueue(){ double now = context.getSimTimer().getTimeOfDay() ; QVehicle returnVeh = vehQueue.peek(); if( context.qsimConfig.getLinkDynamics()==LinkDynamics.SeepageQ ) { int maxSeepModeAllowed = 4; if( context.qsimConfig.isRestrictingSeepage() && noOfSeepModeBringFwd == maxSeepModeAllowed) { noOfSeepModeBringFwd = 0; return returnVeh; } VehicleQ<QVehicle> newVehQueue = new PassingVehicleQ(); newVehQueue.addAll(vehQueue); Iterator<QVehicle> it = newVehQueue.iterator(); while(it.hasNext()){ QVehicle veh = newVehQueue.poll(); if( veh.getEarliestLinkExitTime()<=now && context.qsimConfig.getSeepModes().contains(veh.getDriver().getMode()) ) { returnVeh = veh; break; } } } return returnVeh; }
private void removeVehicleFromQueue(final QVehicle veh2Remove) { double now = context.getSimTimer().getTimeOfDay() ;
@Override public Collection<AgentSnapshotInfo> addAgentSnapshotInfo( final Collection<AgentSnapshotInfo> positions) { double now = context.getSimTimer().getTimeOfDay() ; if (visLink != null) { for (QLaneI ql : QLinkLanesImpl.this.laneQueues.values()) { VisLane otfLane = visLink.getLaneData().get( ql.getId().toString()); ((QueueWithBuffer.VisDataImpl) ql.getVisData()).setVisInfo( otfLane.getStartCoord(), otfLane.getEndCoord()); } } for (QLaneI road : QLinkLanesImpl.this.getQueueLanes().values()) { road.getVisData().addAgentSnapshotInfo(positions, now); } int cnt2 = 10; // treat vehicles from transit stops cnt2 = context.snapshotInfoBuilder.positionVehiclesFromTransitStop(positions, getLink(), getTransitQLink().getTransitVehicleStopQueue(), cnt2); // treat vehicles from waiting list: context.snapshotInfoBuilder.positionVehiclesFromWaitingList(positions, QLinkLanesImpl.this.getLink(), cnt2, QLinkLanesImpl.this.getWaitingList()); cnt2 = QLinkLanesImpl.this.getWaitingList().size(); context.snapshotInfoBuilder.positionAgentsInActivities(positions, QLinkLanesImpl.this.getLink(), QLinkLanesImpl.this.getAdditionalAgentsOnLink(), cnt2); return positions; } }
@Override public final QVehicle popFirstVehicle() { double now = context.getSimTimer().getTimeOfDay() ; QVehicle veh = removeFirstVehicle(); if (this.context.qsimConfig.isUseLanes() ) { if ( hasMoreThanOneLane() ) { this.context.getEventsManager().processEvent(new LaneLeaveEvent( now, veh.getId(), this.qLink.getId(), this.getId() )); } } return veh; }
@Override public void addFromUpstream(QVehicle veh) { double now = context.getSimTimer().getTimeOfDay() ; Id<Link> nextL = veh.getDriver().chooseNextLinkId(); Id<Node> leaveId = toQNode.getNode().getId() ; // e.addFromUpstream( getLink().getFromNode().getId(), leaveId, veh); e.addFromUpstream( veh); em.processEvent(new LinkEnterEvent(now, veh.getId(), getLink().getId())); }
@Override public boolean doSimStep() { double now = context.getSimTimer().getTimeOfDay() ; boolean lanesActive = false; boolean movedWaitToRoad = false; if ( context.qsimConfig.isInsertingWaitingVehiclesBeforeDrivingVehicles() ) { //TODO //Because moveBufferToNextLane() (called from moveLanes()) is kind of "moveInternalNodes()", //it should be executed before moveWaitToRoad() to keep the sequence fully consistent. //The sequence is broken only if isInsertingWaitingVehiclesBeforeDrivingVehicles==true. //Currently, the buffer of the accepting lane gets emptied after moveWaitToRoad(), //which gives preference to already driving vehicles //michalm, jan'17 this.moveWaitToRoad(now); this.getTransitQLink().handleTransitVehiclesInStopQueue(now); lanesActive = this.moveLanes(); } else { this.getTransitQLink().handleTransitVehiclesInStopQueue(now); lanesActive = this.moveLanes(); movedWaitToRoad = this.moveWaitToRoad(now); } this.setActive(lanesActive || movedWaitToRoad || (!this.getWaitingList().isEmpty()) || !this.getTransitQLink().getTransitVehicleStopQueue().isEmpty()); return this.isActive(); }
/* package */ final void letVehicleArrive(QVehicle qveh) { addParkedVehicle(qveh); double now = context.getSimTimer().getTimeOfDay();; context.getEventsManager().processEvent(new VehicleLeavesTrafficEvent(now , qveh.getDriver().getId(), this.link.getId(), qveh.getId(), qveh.getDriver().getMode(), 1.0 ) ) ; this.netsimEngine.letVehicleArrive(qveh); makeVehicleAvailableToNextDriver(qveh); }
/** * Move as many waiting cars to the link as it is possible */ private void moveWaitToRoad() { while (!getWaitingList().isEmpty()) { if (!qlane.isAcceptingFromWait(this.getWaitingList().peek())) { return; } QVehicle veh = this.getWaitingList().poll(); double now = context.getSimTimer().getTimeOfDay() ; context.getEventsManager().processEvent( new VehicleEntersTrafficEvent(now, veh.getDriver().getId(), this.getLink().getId(), veh.getId(), veh.getDriver().getMode(), 1.0)); if ( this.getTransitQLink().addTransitToStopQueue(now, veh, this.getLink().getId()) ) { continue ; } if ( veh.getDriver().isWantingToArriveOnCurrentLink() ) { // If the driver wants to stop (again) on this link, give them a special treatment. // addFromWait doesn't work here, because after that, they cannot stop anymore. qlane.addTransitSlightlyUpstreamOfStop(veh) ; continue; } qlane.addFromWait(veh); } }
private void moveVehicleFromInlinkToOutlink(final QVehicle veh, Id<Link> currentLinkId, final QLaneI fromLane, Id<Link> nextLinkId, QLaneI nextQueueLane) { double now = this.context.getSimTimer().getTimeOfDay() ; fromLane.popFirstVehicle(); // --> // network.simEngine.getMobsim().getEventsManager().processEvent(new LaneLeaveEvent(now, veh.getId(), currentLinkId, fromLane.getId())); this.context.getEventsManager().processEvent(new LinkLeaveEvent(now, veh.getId(), currentLinkId)); // <-- veh.getDriver().notifyMoveOverNode( nextLinkId ); // --> this.context.getEventsManager().processEvent(new LinkEnterEvent(now, veh.getId(), nextLinkId )); // <-- nextQueueLane.addFromUpstream(veh); }
@Override public boolean doSimStep() { double now = context.getSimTimer().getTimeOfDay() ; qlane.initBeforeSimStep(); if ( context.qsimConfig.isInsertingWaitingVehiclesBeforeDrivingVehicles() ) { this.moveWaitToRoad(); this.getTransitQLink().handleTransitVehiclesInStopQueue(now); qlane.doSimStep(); } else { this.getTransitQLink().handleTransitVehiclesInStopQueue(now); qlane.doSimStep(); this.moveWaitToRoad(); } this.setActive(this.checkForActivity()); return isActive(); // yy seems to me that for symmetry there should be something like // netElementActivationRegistry.registerLinkAsActive(this); // and may be a qlink.deactivateLink(...) around it (analogous to qlink.activateLink). // That is, do NOT pass the deactivation of the link rather implicitly via returning a false here. // kai, mar'16 }
@Override public Collection<AgentSnapshotInfo> addAgentSnapshotInfo( Collection<AgentSnapshotInfo> positions) { // AbstractAgentSnapshotInfoBuilder snapshotInfoBuilder = qnetwork.simEngine.getAgentSnapshotInfoBuilder(); QLaneI.VisData roadVisData = getAcceptingQLane().getVisData() ; if (visLink != null) { ((QueueWithBuffer.VisDataImpl)roadVisData).setVisInfo(visLink.getLinkStartCoord(), visLink.getLinkEndCoord()) ; // yyyy not so great but an elegant solution needs more thinking about visualizer structure. kai, jun'13 } double now = context.getSimTimer().getTimeOfDay() ; positions = roadVisData.addAgentSnapshotInfo(positions,now) ; int cnt2 = 10 ; // a counter according to which non-moving items can be "spread out" in the visualization // initialize a bit away from the lane // treat vehicles from transit stops cnt2 = context.snapshotInfoBuilder.positionVehiclesFromTransitStop(positions, getLink(), getTransitQLink().getTransitVehicleStopQueue(), cnt2 ); // treat vehicles from waiting list: cnt2 = context.snapshotInfoBuilder.positionVehiclesFromWaitingList(positions, QLinkImpl.this.getLink(), cnt2, QLinkImpl.this.getWaitingList()); cnt2 = context.snapshotInfoBuilder.positionAgentsInActivities(positions, QLinkImpl.this.getLink(), QLinkImpl.this.getAdditionalAgentsOnLink(), cnt2); return positions; }
@Override public final void clearVehicles() { // yyyyyy right now it seems to me that one should rather just abort the agents and have the framework take care of the rest. kai, mar'16 double now = context.getSimTimer().getTimeOfDay() ; for (QVehicle veh : vehQueue) { context.getEventsManager().processEvent( new VehicleAbortsEvent(now, veh.getId(), veh.getCurrentLink().getId())); context.getEventsManager().processEvent( new PersonStuckEvent(now, veh.getDriver().getId(), veh.getCurrentLink().getId(), veh.getDriver().getMode())); context.getAgentCounter().incLost(); context.getAgentCounter().decLiving(); } vehQueue.clear(); for (QVehicle veh : buffer) { context.getEventsManager().processEvent( new VehicleAbortsEvent(now, veh.getId(), veh.getCurrentLink().getId())); context.getEventsManager().processEvent( new PersonStuckEvent(now, veh.getDriver().getId(), veh.getCurrentLink().getId(), veh.getDriver().getMode())); context.getAgentCounter().incLost(); context.getAgentCounter().decLiving(); } buffer.clear(); holes.clear(); this.remainingHolesStorageCapacity = this.storageCapacity; }