public static Map<Id<Link>, ? extends Link> getIncidentLinks(Node node) { Map<Id<Link>, Link> links = new TreeMap<>(node.getInLinks()); links.putAll(node.getOutLinks()); return links; }
public static Link getConnectingLink(final Node fromNode, final Node toNode) { for (Link link : fromNode.getOutLinks().values()) { if (link.getToNode() == toNode) { return link; } } return null; }
private static Link findLink(Node prevNode, Node node) { for (Link link : prevNode.getOutLinks().values()) { if (link.getToNode().equals(node)) { return link; } } return null; }
public static Map<Id<Node>, ? extends Node> getOutNodes(Node node) { Map<Id<Node>, Node> nodes = new TreeMap<>(); for (Link link : node.getOutLinks().values()) { Node outNode = link.getToNode(); nodes.put(outNode.getId(), outNode); } return nodes; }
@Override public final void setSignalized( final boolean isSignalized) { qSignalizedItem = new DefaultSignalizeableItem(qLink.getToNode().getOutLinks().keySet()); }
public static Link findLinkInOppositeDirection(Link link) { for ( Link candidateLink : link.getToNode().getOutLinks().values() ) { if ( candidateLink.getToNode().equals( link.getFromNode() ) ) { return candidateLink ; } } return null ; } public static void readNetwork( Network network, String string ) {
/** * Removes nodes from the network that have no incoming or outgoing links attached to them. */ public void removeNodesWithoutLinks() { List<Node> toBeRemoved = new ArrayList<>(); for (Node node : this.network.getNodes().values()) { if ((node.getInLinks().size() == 0) && (node.getOutLinks().size() == 0)) { toBeRemoved.add(node); } } for (Node node : toBeRemoved) { this.network.removeNode(node.getId()); } }
@Override public final void setSignalStateForTurningMove( final SignalGroupState state, final Id<Link> toLinkId) { if (!qLink.getToNode().getOutLinks().containsKey(toLinkId)){ throw new IllegalArgumentException("ToLink " + toLinkId + " is not reachable from QLink Id " + this.id ); } qSignalizedItem.setSignalStateForTurningMove(state, toLinkId); thisTimeStepGreen = qSignalizedItem.hasGreenForAllToLinks(); // (this is only for capacity accumulation. As soon as at least one turning relation is green, the "link" is considered // green). }
private int getNOfIncidentNodes(final Node node) { HashMap<Id<Node>, Node> nodes = new HashMap<>(); for (Link link : node.getInLinks().values()) { nodes.put(link.getFromNode().getId(), link.getFromNode()); } for (Link link : node.getOutLinks().values()) { nodes.put(link.getToNode().getId(), link.getToNode()); } return nodes.size(); } }
@Override public void run(final Network network) { Set<Node> nodesToRemove; if (this.cutType == CutType.RECTANGLE) nodesToRemove = rectangularCut(network); else if (this.cutType == CutType.CIRCLE) nodesToRemove = circularCut(network); else return; int nofLinksRemoved = 0; for (Node n : nodesToRemove) { nofLinksRemoved += n.getInLinks().size() + n.getOutLinks().size(); network.removeNode(n.getId()); } log.info("number of nodes removed: "+nodesToRemove.size()); log.info("number of links removed: "+nofLinksRemoved); log.info("number of nodes remaining: "+network.getNodes().size()); log.info("number of links remaining: "+network.getLinks().size()); }
private void doRandomChoice() { // Do I want to end at this link? if (MatsimRandom.getRandom().nextInt(10) == 0) {// 10% chance nextLinkId = null; destinationLinkId = currentLinkId; } else { // Where do I want to move next? Link currentLink = network.getLinks().get(currentLinkId); Map<Id<Link>, ?> possibleNextLinks = currentLink.getToNode().getOutLinks(); // Let's choose the next link randomly nextLinkId = RandomDynAgentLogic.chooseRandomElement(possibleNextLinks.keySet()); // at this point the destination can be anything, QSim does not take it into account destinationLinkId = null; } }
public void registerDownstreamSensors(SignalSystem signalSystem){ for (Signal signal : signalSystem.getSignals().values()){ Node systemNode = this.network.getLinks().get(signal.getLinkId()).getToNode(); for (Id<Link> outgoingLinkId : systemNode.getOutLinks().keySet()) { this.sensorManager.registerNumberOfCarsMonitoring(outgoingLinkId); } break; // systemNode is the same for all signals of the system } }
private static Map<Id<Node>, Node> getIncidentNodes(Node node) { Map<Id<Node>, Node> nodes = new TreeMap<>(); for (Link link : node.getInLinks().values()) { nodes.put(link.getFromNode().getId(), link.getFromNode()); } for (Link link : node.getOutLinks().values()) { nodes.put(link.getToNode().getId(), link.getToNode()); } return nodes; }
@Override public Node removeNode(final Id<Node> nodeId) { Node n = this.nodes.remove(nodeId); if (n == null) { return null; } HashSet<Link> links1 = new HashSet<>(); links1.addAll(n.getInLinks().values()); links1.addAll(n.getOutLinks().values()); for (Link l : links1) { removeLink(l.getId()); } if (this.nodeQuadTree != null) { this.nodeQuadTree.remove(n.getCoord().getX(),n.getCoord().getY(),n); } return n; }
/** * Expands the given Node in the routing algorithm; may be overridden in * sub-classes. * * @param outNode * The Node to be expanded. * @param toNode * The target Node of the route. * @param pendingNodes * The set of pending nodes so far. */ protected void relaxNode(final Node outNode, final Node toNode, final RouterPriorityQueue<Node> pendingNodes) { DijkstraNodeData outData = getData(outNode); double currTime = outData.getTime(); double currCost = outData.getCost(); if (this.pruneDeadEnds) { PreProcessDijkstra.DeadEndData ddOutData = getPreProcessData(outNode); for (Link l : outNode.getOutLinks().values()) { relaxNodeLogic(l, pendingNodes, currTime, currCost, toNode, ddOutData); } } else { // this.pruneDeadEnds == false for (Link l : outNode.getOutLinks().values()) { relaxNodeLogic(l, pendingNodes, currTime, currCost, toNode, null); } } }
/** * Expands the given Node in the routing algorithm; may be overridden in * sub-classes. * * @param outNode * The Node to be expanded. * @param pendingNodes * The set of pending nodes so far. */ protected void relaxNode(final Node outNode, final RouterPriorityQueue<Node> pendingNodes) { DijkstraNodeData outData = getData(outNode); double currTime = outData.getTime(); double currCost = outData.getCost(); for (Link l : outNode.getOutLinks().values()) { relaxNodeLogic(l, pendingNodes, currTime, currCost); } }
public boolean allDownstreamLinksEmpty(SignalData signal){ if (signal.getTurningMoveRestrictions() != null) { return allLinksEmpty(signal.getTurningMoveRestrictions()); } // else: if (signal.getLaneIds() != null && !signal.getLaneIds().isEmpty()) { Set<Id<Link>> toLinks = new HashSet<>(); for (Id<Lane> laneId : signal.getLaneIds()) { Lane lane = lanes.getLanesToLinkAssignments().get(signal.getLinkId()).getLanes().get(laneId); toLinks.addAll(lane.getToLinkIds()); } return allLinksEmpty(toLinks); } // else: // if no turning move restrictions and no lanes with to links are set, turning is allowed to all outgoing links Node systemNode = this.network.getLinks().get(signal.getLinkId()).getToNode(); return allLinksEmpty(systemNode.getOutLinks().keySet()); }
private void relaxNode(final Node n, PriorityQueue<Node> pendingNodes) { NodeData nData = nodeData.get(n.getId()); double currTime = nData.getTime(); double currCost = nData.getCost(); for (Link l : n.getOutLinks().values()) { Node nn = l.getToNode(); NodeData nnData = nodeData.get(nn.getId()); if (nnData == null) { nnData = new NodeData(); this.nodeData.put(nn.getId(), nnData); } double visitCost = currCost + tcFunction.getLinkTravelDisutility(l, currTime, PERSON, VEHICLE); double visitTime = currTime + ttFunction.getLinkTravelTime(l, currTime, PERSON, VEHICLE); if (visitCost < nnData.getCost()) { pendingNodes.remove(nn); nnData.visit(n.getId(), visitCost, visitTime); additionalComputationsHook( l, currTime ) ; pendingNodes.add(nn); } } }
private static Link findLinkBetween(final Network network, final Id<Link> fromLinkId, final Id<Link> toLinkId) { Link fromLink = network.getLinks().get(fromLinkId); Link toLink = network.getLinks().get(toLinkId); Node from = fromLink.getToNode(); Node to = toLink.getFromNode(); for (Link link : from.getOutLinks().values()) { if (link.getToNode() == to) { return link; } } return null; }
@Test public void removeLink() { Fixture f = new Fixture(getEmptyTestNetwork()); Assert.assertTrue(f.network.getLinks().containsKey(f.linkIds[1])); Assert.assertEquals(1, f.network.getNodes().get(f.nodeIds[1]).getInLinks().size()); f.network.removeLink(f.linkIds[1]); Assert.assertFalse(f.network.getLinks().containsKey(f.linkIds[1])); Assert.assertEquals(0, f.network.getNodes().get(f.nodeIds[1]).getInLinks().size()); Assert.assertEquals(1, f.network.getNodes().get(f.nodeIds[1]).getOutLinks().size()); Assert.assertTrue(f.network.getLinks().containsKey(f.linkIds[2])); f.network.removeLink(f.linkIds[2]); Assert.assertFalse(f.network.getLinks().containsKey(f.linkIds[2])); Assert.assertTrue(f.network.getNodes().containsKey(f.nodeIds[1])); Assert.assertEquals(0, f.network.getNodes().get(f.nodeIds[1]).getOutLinks().size()); Assert.assertEquals(2, f.network.getNodes().get(f.nodeIds[5]).getOutLinks().size()); Assert.assertEquals(2, f.network.getNodes().get(f.nodeIds[8]).getInLinks().size()); f.network.removeLink(f.linkIds[10]); Assert.assertEquals(1, f.network.getNodes().get(f.nodeIds[5]).getOutLinks().size()); Assert.assertEquals(1, f.network.getNodes().get(f.nodeIds[8]).getInLinks().size()); }