@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 recalcTimeVariantAttributes() { // not speed, since that is looked up anyways. // yy might also make flow and storage self-detecting changes (not really that // much more expensive). kai, feb'18 // log.debug("just entered recalcTimeVariantAttributes; now=" + this.context.getSimTimer().getTimeOfDay() ) ; calculateFlowCapacity(); calculateStorageCapacity(); flowcap_accumulate.setValue(flowCapacityPerTimeStep); }
@Override public final boolean isAcceptingFromWait(QVehicle veh) { return this.hasFlowCapacityLeft(veh) ; }
@Override public final Collection<AgentSnapshotInfo> addAgentSnapshotInfo(Collection<AgentSnapshotInfo> positions, double now) { if ( !buffer.isEmpty() || !vehQueue.isEmpty() || !holes.isEmpty() ) { Gbl.assertNotNull(positions); Gbl.assertNotNull( context.snapshotInfoBuilder ); if ( this.upstreamCoord==null ) { this.upstreamCoord = qLink.getFromNode().getCoord() ; } if ( this.downstreamCoord==null ) { this.downstreamCoord = qLink.getToNode().getCoord() ; } // vehicle positions are computed in snapshotInfoBuilder as a service: positions = context.snapshotInfoBuilder.positionVehiclesAlongLine( positions, now, getAllVehicles(), length, storageCapacity + getBufferStorageCapacity(), this.upstreamCoord, this.downstreamCoord, inverseFlowCapacityPerTimeStep, qLink.getFreespeed(now), // NetworkUtils.getNumberOfLanesAsInt(now, qLink.getLink()), qLink.getNumberOfLanesAsInt(now) , holes ); } return positions ; }
while((veh = peekFromVehQueue()) !=null){ if (handleTransitStop == HandleTransitStopResult.accepted) { removeVehicleFromQueue(veh) ; continue; } else if (handleTransitStop == HandleTransitStopResult.rehandle) { removeVehicleFromQueue( veh ) ; if (!hasFlowCapacityLeft(veh) ) { return; addToBuffer(veh); removeVehicleFromQueue(veh); if(context.qsimConfig.isRestrictingSeepage() && context.qsimConfig.getLinkDynamics()==LinkDynamics.SeepageQ
if ( hasMoreThanOneLane() ) { this.context.getEventsManager().processEvent(new LaneEnterEvent( now, veh.getId(), this.qLink.getId(), this.getId() ));
double totalFlowCapacity = 0.0; for (QLaneI qll : ql.getOfferingQLanes()) { if (((QueueWithBuffer)qll).getId().equals(Id.create(2, Lane.class))) { assertEquals(0.5, qll.getSimulatedFlowCapacityPerTimeStep()); assertEquals(28.0, qll.getStorageCapacity());
private void updateSlowFlowAccumulation(){ if (this.thisTimeStepGreen && this.flowcap_accumulate.getValue() < flowCapacityPerTimeStep && isNotOfferingVehicle() ){ double newFlowCap = Math.min(flowcap_accumulate.getValue() + flowCapacityPerTimeStep, flowCapacityPerTimeStep); flowcap_accumulate.setValue(newFlowCap); } }
@Override public final void addFromWait(final QVehicle veh) { //To protect against calling addToBuffer() without calling hasFlowCapacityLeft() first. //This only could happen for addFromWait(), because it can be called from outside QueueWithBuffer if (flowcap_accumulate.getValue() <= 0.0 && veh.getVehicle().getType().getPcuEquivalents() > context.qsimConfig .getPcuThresholdForFlowCapacityEasing()) { throw new IllegalStateException("Buffer of link " + this.id + " has no space left!"); } addToBuffer(veh); }
storageCapacity = Math.max(storageCapacity, getBufferStorageCapacity());
@Override public QueueWithBuffer createLane( AbstractQLink qLink ) { // a number of things I cannot configure before I have the qlink: if ( id==null ) { id = Id.create( qLink.getLink().getId() , Lane.class ) ; } if ( length==null ) { length = qLink.getLink().getLength() ; } if ( effectiveNumberOfLanes==null ) { effectiveNumberOfLanes = qLink.getLink().getNumberOfLanes() ; } if ( flowCapacity_s==null ) { flowCapacity_s = ((Link)qLink.getLink()).getFlowCapacityPerSec() ; } return new QueueWithBuffer( qLink.getInternalInterface(), vehicleQueue, id, length, effectiveNumberOfLanes, flowCapacity_s, context ) ; } }
@Test public void testAdd() { Fixture f = new Fixture(isUsingFastCapacityUpdate); assertEquals(0, ((QueueWithBuffer) f.qlink1.getAcceptingQLane()).getAllVehicles().size()); QVehicle v = new QVehicleImpl(f.basicVehicle); Person p = PopulationUtils.getFactory().createPerson(Id.create("1", Person.class)); p.addPlan(PopulationUtils.createPlan()); v.setDriver(createAndInsertPersonDriverAgentImpl(p, f.sim)); f.qlink1.getAcceptingQLane().addFromUpstream(v); assertEquals(1, ((QueueWithBuffer) f.qlink1.getAcceptingQLane()).getAllVehicles().size()); assertFalse(f.qlink1.getAcceptingQLane().isAcceptingFromUpstream()); assertTrue(f.qlink1.isNotOfferingVehicle()); }
@Override public final boolean isActive() { if( context.qsimConfig.isUsingFastCapacityUpdate() ){ return (!this.vehQueue.isEmpty()) || (!this.isNotOfferingVehicle() && context.qsimConfig.isUseLanes()) // if lanes, the buffer needs to be active in order to move vehicles over an internal node || ( !this.holes.isEmpty() ) ; } else { return (this.flowcap_accumulate.getValue() < flowCapacityPerTimeStep) // still accumulating, thus active || (!this.vehQueue.isEmpty()) // vehicles are on link, thus active || (!this.isNotOfferingVehicle() && context.qsimConfig.isUseLanes()) // if lanes, the buffer needs to be active in order to move vehicles over an internal node || ( !this.holes.isEmpty() ); // need to process arrival of holes } }
/** * Tests that vehicles parked on a link are found with {@link NetsimLink#getVehicle(Id)} * and {@link NetsimLink#getAllVehicles()}. * * @author mrieser */ @Test public void testGetVehicle_Parking() { Fixture f = new Fixture(isUsingFastCapacityUpdate); Id<Vehicle> id1 = Id.create("1", Vehicle.class); QVehicle veh = new QVehicleImpl(f.basicVehicle); Person p = PopulationUtils.getFactory().createPerson(Id.create(42, Person.class)); p.addPlan(PopulationUtils.createPlan()); veh.setDriver(createAndInsertPersonDriverAgentImpl(p, f.sim)); // start test, check initial conditions assertTrue(f.qlink1.isNotOfferingVehicle()); assertEquals(0, ((QueueWithBuffer) f.qlink1.getAcceptingQLane()).getAllVehicles().size()); assertEquals(0, f.qlink1.getAllVehicles().size()); f.qlink1.addParkedVehicle(veh); assertTrue(f.qlink1.isNotOfferingVehicle()); assertEquals(0, ((QueueWithBuffer) f.qlink1.getAcceptingQLane()).getAllVehicles().size()); // vehicle not on _lane_ assertEquals("vehicle not found in parking list.", veh, f.qlink1.getVehicle(id1)); assertEquals(1, f.qlink1.getAllVehicles().size()); // vehicle indeed on _link_ assertEquals(veh, f.qlink1.getAllVehicles().iterator().next()); assertEquals("removed wrong vehicle.", veh, f.qlink1.removeParkedVehicle(veh.getId())); assertTrue(f.qlink1.isNotOfferingVehicle()); assertEquals(0, ((QueueWithBuffer) f.qlink1.getAcceptingQLane()).getAllVehicles().size()); assertNull("vehicle not found in parking list.", f.qlink1.getVehicle(id1)); assertEquals(0, f.qlink1.getAllVehicles().size()); }
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 ); } }
assertEquals(0, ((QueueWithBuffer) f.qlink1.getAcceptingQLane()).getAllVehicles().size()); assertEquals(1, f.qlink1.getAllVehicles().size()); assertEquals(0, ((QueueWithBuffer) f.qlink1.getAcceptingQLane()).getAllVehicles().size()); // veh not on lane assertEquals("vehicle not found in waiting list.", veh, f.qlink1.getVehicle(id1)); // veh _should_ be on link (in waiting list) assertEquals(1, f.qlink1.getAllVehicles().size()); // dto assertEquals(1, ((QueueWithBuffer) f.qlink1.getAcceptingQLane()).getAllVehicles().size()); // somewhere on lane assertEquals("vehicle not found in buffer.", veh, f.qlink1.getVehicle(id1)); // somewhere on link assertEquals(1, f.qlink1.getAllVehicles().size()); // somewhere on link assertEquals(0, ((QueueWithBuffer) f.qlink1.getAcceptingQLane()).getAllVehicles().size()); assertNull("vehicle should not be on link anymore.", f.qlink1.getVehicle(id1)); assertEquals(0, f.qlink1.getAllVehicles().size());
assertEquals(0, ((QueueWithBuffer) qlink.getAcceptingQLane()).getAllVehicles().size()); assertEquals(1, ((QueueWithBuffer) qlink.getAcceptingQLane()).getAllVehicles().size()); assertTrue(qlink.isNotOfferingVehicle()); assertEquals(1, ((QueueWithBuffer) qlink.getAcceptingQLane()).getAllVehicles().size()); assertFalse(qlink.isNotOfferingVehicle()); assertEquals(2, ((QueueWithBuffer) qlink.getAcceptingQLane()).getAllVehicles().size()); assertFalse(qlink.isNotOfferingVehicle()); assertEquals(2, ((QueueWithBuffer) qlink.getAcceptingQLane()).getAllVehicles().size()); assertFalse(qlink.isNotOfferingVehicle()); assertEquals(1, ((QueueWithBuffer) qlink.getAcceptingQLane()).getAllVehicles().size()); assertTrue(qlink.isNotOfferingVehicle()); assertEquals(1, ((QueueWithBuffer) qlink.getAcceptingQLane()).getAllVehicles().size()); assertFalse(qlink.isNotOfferingVehicle()); assertEquals(0, ((QueueWithBuffer) qlink.getAcceptingQLane()).getAllVehicles().size()); assertTrue(qlink.isNotOfferingVehicle()); assertEquals(0, ((QueueWithBuffer) qlink.getAcceptingQLane()).getAllVehicles().size()); assertTrue(qlink.isNotOfferingVehicle());
assertEquals(0, ((QueueWithBuffer) f.qlink1.getAcceptingQLane()).getAllVehicles().size()); assertNull(f.qlink1.getVehicle(id1)); assertEquals(0, f.qlink1.getAllVehicles().size()); assertEquals(1, ((QueueWithBuffer) f.qlink1.getAcceptingQLane()).getAllVehicles().size()); assertEquals("vehicle not found on link.", veh, f.qlink1.getVehicle(id1)); assertEquals(1, f.qlink1.getAllVehicles().size());