/** * Initializes a QueueLink with one QueueLane. * @param context TODO * @param netsimEngine TODO * @param linkSpeedCalculator */ private QLinkLanesImpl(final Link link, final QNodeI toNodeQ, List<ModelLane> lanes, NetsimEngineContext context, NetsimInternalInterface netsimEngine, LinkSpeedCalculator linkSpeedCalculator) { super(link, toNodeQ, context, netsimEngine, linkSpeedCalculator); this.context = context ; this.toQueueNode = toNodeQ; this.laneQueues = new LinkedHashMap<>(); this.toNodeLaneQueues = new ArrayList<>(); this.lanes = lanes; this.nextQueueToLinkCache = new LinkedHashMap<>(); // maps a lane id to a map containing the // downstream queues indexed by a // downstream link this.initLaneQueues(); this.visdata = this.new VisDataImpl(); this.setTransitQLink(new TransitQLink(this.firstLaneQueue)); }
@Override public Collection<MobsimVehicle> getAllNonParkedVehicles(){ Collection<MobsimVehicle> vehicles = new ArrayList<>(); vehicles.addAll(this.getTransitQLink().getTransitVehicleStopQueue()); vehicles.addAll(this.getWaitingList()); vehicles.addAll( qlane.getAllVehicles() ) ; return vehicles; }
public HandleTransitStopResult handleTransitStop(double now, QVehicle veh, TransitDriverAgent driver, Id<Link> linkId) { // yy now would not be needed as an argument. kai, feb'18 // yy linkId would not be needed as an argument. kai, feb'18 return AbstractQLink.this.transitQLink.handleTransitStop(now, veh, driver, linkId) ; }
@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(); }
this.getLink().getId(), veh.getId(), veh.getDriver().getMode(), 1.0)); if (this.getTransitQLink().addTransitToStopQueue(now, veh, this.getLink().getId())) { continue;
@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 }
/** * 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 boolean checkForActivity() { /* * Leave Link active as long as there are vehicles on the link (ignore * buffer because the buffer gets emptied by nodes and not links) and leave * link active until buffercap has accumulated (so a newly arriving vehicle * is not delayed). */ return qlane.isActive() || !this.getWaitingList().isEmpty() || !this.getTransitQLink().getTransitVehicleStopQueue().isEmpty() ; }
private QLinkImpl(final Link link2, final QNodeI toNode, final LaneFactory roadFactory, NetsimEngineContext context, NetsimInternalInterface netsimEngine, LinkSpeedCalculator linkSpeedCalculator) { super(link2, toNode, context, netsimEngine, linkSpeedCalculator) ; this.context = context ; // The next line must must by contract stay within the constructor, // so that the caller can use references to the created roads to wire them together, // if it must. this.qlane = roadFactory.createLane(this); this.visdata = this.new VisDataImpl() ; // instantiating this here and not earlier so we can cache some things super.setTransitQLink( new TransitQLink(this.qlane) ) ; }
@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 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; }