@SuppressWarnings("static-method") private boolean checkNextLinkSemantics( Link currentLink, Id<Link> nextLinkId, QLinkInternalI nextQLink, QVehicle veh) { if (nextQLink == null) { // throw new IllegalStateException 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 false; } if (currentLink.getToNode() != nextQLink.getLink().getFromNode()) { // throw new RuntimeException log.warn( "Cannot move vehicle " + veh.getId() + " from link " + currentLink.getId() + " to link " + nextQLink.getLink().getId()); return false; } return true; }
/** * Moves vehicles from the inlinks' buffer to the outlinks where possible.<br> * The inLinks are randomly chosen, and for each link all vehicles in the buffer are moved to * their desired outLink as long as there is space. If the front most vehicle in a buffer cannot * move across the node because there is no free space on its destination link, the work on this * inLink is finished and the next inLink's buffer is handled (this means, that at the node, all * links have only like one lane, and there are no separate lanes for the different outLinks. Thus * if the front most vehicle cannot drive further, all other vehicles behind must wait, too, even * if their links would be free). * * @param now The current time in seconds from midnight. * @return Whether the QNode stays active or not. */ /*package*/ boolean doSimStep(final double now) { int inLinksCounter = 0; double inLinksCapSum = 0.0; // Check all incoming links for buffered agents for (QLinkInternalI link : this.inLinksArrayCache) { if (!link.isNotOfferingVehicle()) { this.tempLinks[inLinksCounter] = link; inLinksCounter++; inLinksCapSum += link.getLink().getCapacity(now); } } if (inLinksCounter == 0) { this.active.set(false); return false; // Nothing to do } // randomize based on capacity for (int auxCounter = 0; auxCounter < inLinksCounter; auxCounter++) { double rndNum = random.nextDouble() * inLinksCapSum; double selCap = 0.0; for (int i = 0; i < inLinksCounter; i++) { QLinkInternalI link = this.tempLinks[i]; if (link != null) { selCap += link.getLink().getCapacity(now); if (selCap >= rndNum) { inLinksCapSum -= link.getLink().getCapacity(now); this.tempLinks[i] = null; this.moveLink(link, now); break; } } } } return true; }
private static void moveVehicleFromInlinkToOutlink( final QVehicle veh, final QInternalI fromLane, QLinkInternalI nextQueueLink) { fromLane.popFirstVehicle(); veh.getDriver().notifyMoveOverNode(nextQueueLink.getLink().getId()); nextQueueLink.addFromUpstream(veh); }