@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); }
Id<Vehicle> vehicleId = veh.getId(); Set<MobsimAgent> passengers = this.passengersWaitingForCars.get(vehicleId); if (passengers != null) { final Queue<MobsimDriverAgent> driversWaitingForCar = driversWaitingForCars.get(veh.getId()); final boolean thereIsDriverWaiting = driversWaitingForCar != null && !driversWaitingForCar.isEmpty(); if ( thereIsDriverWaiting ) { if (thereIsDriverWaiting && veh.getDriver() == null) { veh.setDriver(driversWaitingForCar.remove()); if (driversWaitingForCar.isEmpty()) { final Queue<MobsimDriverAgent> r = driversWaitingForCars.remove(veh.getId()); assert r == driversWaitingForCar; removeParkedVehicle( veh.getId() ); this.letVehicleDepart(veh);
private void teleportVehicleTo(QVehicle vehicle, Id<Link> linkId) { if (vehicle.getCurrentLink() != null) { if (cntTeleportVehicle < 9) { cntTeleportVehicle++; log.info("teleport vehicle " + vehicle.getId() + " from link " + vehicle.getCurrentLink().getId() + " to link " + linkId); if (cntTeleportVehicle == 9) { log.info("No more occurrences of teleported vehicles will be reported."); } } QLinkI qlinkOld = (QLinkI) qNetsimEngine.getNetsimNetwork().getNetsimLink(vehicle.getCurrentLink().getId()); QVehicle result = qlinkOld.removeParkedVehicle(vehicle.getId()); if ( result==null ) { throw new RuntimeException( "Could not remove parked vehicle with id " + vehicle.getId() +" on the link id " // + linkId + vehicle.getCurrentLink().getId() + ". Maybe it is currently used by someone else?" + " (In which case ignoring this exception would lead to duplication of this vehicle.) " + "Maybe was never placed onto a link?" ); } } }
@Override public int compare(final QVehicle veh1, final QVehicle veh2) { if (veh1.getEarliestLinkExitTime() > veh2.getEarliestLinkExitTime()) { return 1; } if (veh1.getEarliestLinkExitTime() < veh2.getEarliestLinkExitTime()) { return -1; } // Both depart at the same time -> let the one with the larger id be first return veh2.getId().compareTo(veh1.getId()); } }
@Override public final void addParkedVehicle(MobsimVehicle vehicle) { QVehicle qveh = (QVehicle) vehicle; // cast ok: when it gets here, it needs to be a qvehicle to work. if ( this.parkedVehicles.put(qveh.getId(), qveh) != null ) { if ( wrnCnt < 1 ) { wrnCnt++ ; log.warn( "existing vehicle on link was just overwritten by other vehicle with same ID. Not clear what this means. Continuing anyways ...") ; log.warn( Gbl.ONLYONCE ) ; } } qveh.setCurrentLink(this.link); }
/** * Returns all the people sitting in this vehicle. * * @param vehicle * @return All the people in this vehicle. If there is more than one, the first entry is the driver. */ final static List<Identifiable<?>> getPeopleInVehicle(QVehicle vehicle) { ArrayList<Identifiable<?>> people = new ArrayList<>(); people.add(vehicle.getDriver()); for ( PassengerAgent passenger : vehicle.getPassengers() ) { people.add(passenger) ; } return people; }
log.error( "Agent has no or wrong route! agentId=" + veh.getDriver().getId() + " currentLink=" + currentLink.getId().toString() + ". The agent is removed from the simulation."); log.warn("The link id " + nextLinkId + " is not available in the simulation network, but vehicle " + veh.getId() + " plans to travel on that link from link " + veh.getCurrentLink().getId()); return AcceptTurn.ABORT ; log.warn("Cannot move vehicle " + veh.getId() + " from link " + currentLink.getId() + " to link " + nextQLink.getLink().getId()); return AcceptTurn.ABORT ;
if (veh.getDriver() != null) { if (veh.getDriver().getState() != State.LEG) continue; if (stuckAgents.contains(veh.getDriver().getId())) continue; else stuckAgents.add(veh.getDriver().getId()); new VehicleAbortsEvent(now, veh.getId(), veh.getCurrentLink().getId())); new PersonStuckEvent(now, veh.getDriver().getId(), veh.getCurrentLink().getId(), veh.getDriver().getMode())); context.getAgentCounter().incLost(); context.getAgentCounter().decLiving(); for (PassengerAgent passenger : veh.getPassengers()) { if (stuckAgents.contains(passenger.getId())) continue; else stuckAgents.add(passenger.getId()); new PersonStuckEvent(now, mobsimAgent.getId(), veh.getCurrentLink().getId(), mobsimAgent.getMode())); context.getAgentCounter().incLost(); context.getAgentCounter().decLiving(); if (stuckAgents.contains(veh.getDriver().getId())) continue; else stuckAgents.add(veh.getDriver().getId()); new VehicleAbortsEvent(now, veh.getId(), veh.getCurrentLink().getId())); new PersonStuckEvent(now, veh.getDriver().getId(), veh.getCurrentLink().getId(), veh.getDriver().getMode())); this.context.getAgentCounter().incLost(); this.context.getAgentCounter().decLiving();
private void moveBufferToNextLane(QLaneI qlane) { QVehicle veh; while (!qlane.isNotOfferingVehicle()) { veh = qlane.getFirstVehicle(); Id<Link> toLinkId = veh.getDriver().chooseNextLinkId(); QLaneI nextQueue = this.chooseNextLane(qlane, toLinkId); if (nextQueue != null) { if (nextQueue.isAcceptingFromUpstream()) { qlane.popFirstVehicle(); nextQueue.addFromUpstream(veh); } else { break; } } else { StringBuilder b = new StringBuilder(); b.append("Person Id: ").append(veh.getDriver().getId()); b.append(" is on Lane Id ").append(qlane.getId()); b.append(" on Link Id ").append(this.getLink().getId()); b.append(" and wants to drive to Link Id ").append(toLinkId); b.append(" but there is no Lane leading to that Link!"); log.error(b.toString()); throw new IllegalStateException(b.toString()); } } }
private void moveVehicleFromInlinkToAbort(final QVehicle veh, final QLaneI fromLane, final double now, Id<Link> currentLinkId) { fromLane.popFirstVehicle(); // --> this.context.getEventsManager().processEvent(new LinkLeaveEvent(now, veh.getId(), currentLinkId)); // <-- // first treat the passengers: for ( PassengerAgent pp : veh.getPassengers() ) { if ( pp instanceof MobsimAgent ) { ((MobsimAgent)pp).setStateToAbort(now); netsimEngine.arrangeNextAgentState((MobsimAgent)pp) ; } else if ( wrnCnt < 1 ) { wrnCnt++ ; log.warn("encountering PassengerAgent that cannot be cast into a MobsimAgent; cannot say if this is a problem" ) ; log.warn(Gbl.ONLYONCE) ; } } // now treat the driver: veh.getDriver().setStateToAbort(now) ; netsimEngine.arrangeNextAgentState(veh.getDriver()) ; }
this.context.getEventsManager().processEvent(new LaneEnterEvent( now, veh.getId(), this.qLink.getId(), this.getId() )); if(context.qsimConfig.isSeepModeStorageFree() && context.qsimConfig.getSeepModes().contains( veh.getVehicle().getType().getId().toString() ) ){ usedStorageCapacity += veh.getSizeInEquivalents(); linkTravelTime = context.qsimConfig.getTimeStepSize() * Math.floor( linkTravelTime / context.qsimConfig.getTimeStepSize() ); veh.setEarliestLinkExitTime(now + linkTravelTime); break; case withHoles: this.remainingHolesStorageCapacity -= veh.getSizeInEquivalents(); break; case kinematicWaves: this.remainingHolesStorageCapacity -= veh.getSizeInEquivalents(); this.accumulatedInflowCap -= veh.getFlowCapacityConsumptionInEquivalents() ; break; default: throw new RuntimeException("The traffic dynamics "+context.qsimConfig.getTrafficDynamics()+" is not implemented yet.");
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; }
public final static Integer guessLane(QVehicle veh, int numberOfLanes){ Integer tmpLane; try { tmpLane = Integer.parseInt(veh.getId().toString()) ; } catch ( NumberFormatException ee ) { tmpLane = veh.getId().hashCode() ; if (tmpLane < 0 ){ tmpLane = -tmpLane; } } int lane = 1 + (tmpLane % numberOfLanes); return lane; }
/** * 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()); }
final boolean addTransitToStopQueue(final double now, final QVehicle veh, final Id<Link> linkId) { if (veh.getDriver() instanceof TransitDriverAgent) { TransitDriverAgent driver = (TransitDriverAgent) veh.getDriver(); while (true) { TransitStopFacility stop = driver.getNextTransitStop(); if ((stop != null) && (stop.getLinkId().equals(linkId))) { double delay = driver.handleTransitStop(stop, now); if (delay > 0.0) { // yy removing this condition makes at least one test fail. I still think we could discuss doing this. kai, jun'13 veh.setEarliestLinkExitTime(now + delay); // add it to the stop queue: vehicle that is not yet on the road will never block transitVehicleStopQueue.add(veh); return true; } } else { return false; } } } return false; }
public final static double calcSpeedValueBetweenZeroAndOne(QVehicle veh, double inverseSimulatedFlowCapacity, double now, double freespeed){ int cmp = (int) (veh.getEarliestLinkExitTime() + inverseSimulatedFlowCapacity + 2.0); // "inverseSimulatedFlowCapacity" is there to keep vehicles green that only wait for capacity (i.e. have no vehicle // ahead). Especially important with small samples sizes. This is debatable :-). kai, jan'11 double speed = (now > cmp ? 0.0 : 1.0); return speed; }
@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; } }
@Override public double getMaximumVelocity(QVehicle vehicle, Link link, double time) { return Math.min(vehicle.getMaximumVelocity(), link.getFreespeed(time)); }
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 } }