for (QNodeI node : network.getNetsimNodes().values()) { int i = roundRobin % this.numOfRunners; if ( node instanceof QNodeImpl ) { AbstractQLink qLink = (AbstractQLink) network.getNetsimLink(outLink.getId());
public void addParkedVehicle(MobsimVehicle veh, Id<Link> startLinkId) { if (this.vehicles.put(veh.getId(), (QVehicle) veh) != null) { if (wrnCnt < 1) { wrnCnt++ ; log.warn("existing vehicle in mobsim was just overwritten by other vehicle with same ID. Not clear what this means. Continuing anyways ...") ; log.warn(Gbl.ONLYONCE); } } QLinkI qlink = network.getNetsimLinks().get(startLinkId); if (qlink == null) { throw new RuntimeException("requested link with id=" + startLinkId + " does not exist in network. Possible vehicles " + "or activities or facilities are registered to a different network.") ; } qlink.addParkedVehicle(veh); }
public MobsimAgent unregisterAdditionalAgentOnLink(Id<Person> agentId, Id<Link> linkId) { if (linkId == null) { // seems that this can happen in tests; not sure if it can happen in regular code. kai, jun'15 return null; } QLinkI qLink = this.network.getNetsimLink(linkId); return qLink.unregisterAdditionalAgentOnLink(agentId); }
private static void dummify(QNetwork network) { NetElementActivationRegistry netElementActivator = new NetElementActivationRegistry() { @Override protected void registerNodeAsActive(QNodeImpl node) { } @Override int getNumberOfSimulatedNodes() { return 0; } @Override protected void registerLinkAsActive(QLinkI link) { } @Override int getNumberOfSimulatedLinks() { return 0; } }; for (QNodeI node : network.getNetsimNodes().values()) { if ( node instanceof QNodeImpl ) { ((QNodeImpl) node).setNetElementActivationRegistry(netElementActivator); } } for (QLinkI link : network.getNetsimLinks().values()) { if ( link instanceof QLinkImpl ) { ((QLinkImpl) link).setNetElementActivationRegistry(netElementActivator); } } }
network = new QNetwork( sim.getScenario().getNetwork(), netsimNetworkFactory ) ; } else { Scenario scenario = sim.getScenario(); AgentCounter agentCounter = sim.getAgentCounter() ; netsimNetworkFactory2.initializeFactory(agentCounter, mobsimTimer, ii ); network = new QNetwork(sim.getScenario().getNetwork(), netsimNetworkFactory2 ); network.initialize(this, sim.getAgentCounter(), sim.getSimTimer() );
@Override void initializeFactory(AgentCounter agentCounter, MobsimTimer mobsimTimer, NetsimInternalInterface arg2) { network = arg2.getNetsimNetwork().getNetwork(); double effectiveCellSize = ( network).getEffectiveCellSize() ; SnapshotLinkWidthCalculator linkWidthCalculator = new SnapshotLinkWidthCalculator(); linkWidthCalculator.setLinkWidthForVis( qsimConfig.getLinkWidthForVis() ); if (! Double.isNaN(network.getEffectiveLaneWidth())){ linkWidthCalculator.setLaneWidth( network.getEffectiveLaneWidth() ); } AbstractAgentSnapshotInfoBuilder snapshotInfoBuilder = QNetsimEngine.createAgentSnapshotInfoBuilder( scenario, linkWidthCalculator ); this.context = new NetsimEngineContext( events, effectiveCellSize, agentCounter, snapshotInfoBuilder, qsimConfig, mobsimTimer, linkWidthCalculator ) ; this.netsimEngine = arg2 ; }
@Test public void testInit() { Fixture f = new Fixture(isUsingFastCapacityUpdate); assertNotNull(f.qlink1); assertEquals(1.0, f.qlink1.getSimulatedFlowCapacityPerTimeStep(), EPSILON); assertEquals(1.0, f.qlink1.getSpaceCap(), EPSILON); // TODO dg[april2008] this assertions are not covering everything in // QueueLink's constructor. // Extend the tests by checking the methods initFlowCapacity and // recalcCapacity assertEquals(f.link1, f.qlink1.getLink()); assertEquals(f.queueNetwork.getNetsimNode(Id.create("2", Node.class)), f.qlink1.getToNode()); }
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); } }
QLinkI rightOfWayLink = qNetwork.getNetsimLink(rightOfWayDir.getFromLink());
/** * Loads the inLinks-array with the corresponding links. * Cannot be called in constructor, as the queueNetwork does not yet know * the queueLinks. Should be called by QueueNetwork, after creating all * QueueNodes and QueueLinks. */ @Override public void init() { int i = 0; for (Link l : this.node.getInLinks().values()) { QNetwork network = netsimEngine.getNetsimNetwork() ; this.inLinksArrayCache[i] = network.getNetsimLinks().get(l.getId()); i++; } /* As the order of links has an influence on the simulation results, * the nodes are sorted to avoid indeterministic simulations. dg[april08] */ Arrays.sort(this.inLinksArrayCache, new Comparator<NetsimLink>() { @Override public int compare(NetsimLink o1, NetsimLink o2) { return o1.getLink().getId().compareTo(o2.getLink().getId()); } }); }
/*package*/ Fixture(boolean usingFastCapacityUpdate) { this.scenario = (MutableScenario) ScenarioUtils.createScenario(ConfigUtils.createConfig()); this.scenario.getConfig().qsim().setStuckTime(100); this.scenario.getConfig().qsim().setRemoveStuckVehicles(true); this.scenario.getConfig().qsim().setUsingFastCapacityUpdate(usingFastCapacityUpdate); Network network = (Network) this.scenario.getNetwork(); network.setCapacityPeriod(3600.0); Node node1 = NetworkUtils.createAndAddNode(network, Id.create("1", Node.class), new Coord(0, 0)); Node node2 = NetworkUtils.createAndAddNode(network, Id.create("2", Node.class), new Coord(1, 0)); Node node3 = NetworkUtils.createAndAddNode(network, Id.create("3", Node.class), new Coord(1001, 0)); final Node fromNode = node1; final Node toNode = node2; this.link1 = NetworkUtils.createAndAddLink(network,Id.create("1", Link.class), fromNode, toNode, 1.0, 1.0, 3600.0, 1.0 ); final Node fromNode1 = node2; final Node toNode1 = node3; this.link2 = NetworkUtils.createAndAddLink(network,Id.create("2", Link.class), fromNode1, toNode1, 10 * 7.5, 2.0 * 7.5, 3600.0, 1.0 ); EventsManager eventsManager = EventsUtils.createEventsManager(); PrepareForSimUtils.createDefaultPrepareForSim(scenario).run(); sim = new QSimBuilder(scenario.getConfig()) // .useDefaults() // .build(scenario, eventsManager); this.queueNetwork = (QNetwork) sim.getNetsimNetwork(); this.qlink1 = (QLinkImpl) this.queueNetwork.getNetsimLink(Id.create("1", Link.class)); this.qlink2 = (QLinkImpl) this.queueNetwork.getNetsimLink(Id.create("2", Link.class)); dummify(this.queueNetwork); this.basicVehicle = new VehicleImpl(Id.create("1", Vehicle.class), new VehicleTypeImpl(Id.create("defaultVehicleType", VehicleType.class))); }
@Override public void afterSim() { /* * Calling the afterSim Method of the QSimEngineThreads * will set their simulationRunning flag to false. */ for (QNetsimEngineRunner engine : this.engines) { engine.afterSim(); } if (this.usingThreadpool) { this.pool.shutdown(); } else { /* * Triggering the startBarrier of the QSimEngineThreads. * They will check whether the Simulation is still running. * It is not, so the Threads will stop running. */ this.startBarrier.arriveAndAwaitAdvance(); } /* Reset vehicles on ALL links. We cannot iterate only over the active links * (this.simLinksArray), because there may be links that have vehicles only * in the buffer (such links are *not* active, as the buffer gets emptied * when handling the nodes. */ for (QLinkI link : network.getNetsimLinks().values()) { link.clearVehicles(); } }
return AcceptTurn.ABORT; QLinkI nextQLink = qNetwork.getNetsimLinks().get(nextLinkId);
QLinkI nextQueueLink = this.netsimEngine.getNetsimNetwork().getNetsimLinks().get(nextLinkId); QLaneI nextQueueLane = nextQueueLink.getAcceptingQLane() ; if (nextQueueLane.isAcceptingFromUpstream()) {