org.matsim.api.core.v01.network.Node.getOutLinks()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(9.8k)|赞(0)|评价(0)|浏览(174)

本文整理了Java中org.matsim.api.core.v01.network.Node.getOutLinks()方法的一些代码示例,展示了Node.getOutLinks()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Node.getOutLinks()方法的具体详情如下:
包路径:org.matsim.api.core.v01.network.Node
类名称:Node
方法名:getOutLinks

Node.getOutLinks介绍

[英]Returns this node's set of outgoing links. This set might be empty, but it should not be null.
[中]返回此节点的传出链接集。此集合可能为空,但不应为null

代码示例

代码示例来源:origin: matsim-org/matsim

  1. public static Map<Id<Link>, ? extends Link> getIncidentLinks(Node node) {
  2. Map<Id<Link>, Link> links = new TreeMap<>(node.getInLinks());
  3. links.putAll(node.getOutLinks());
  4. return links;
  5. }

代码示例来源:origin: matsim-org/matsim

  1. public static Link getConnectingLink(final Node fromNode, final Node toNode) {
  2. for (Link link : fromNode.getOutLinks().values()) {
  3. if (link.getToNode() == toNode) {
  4. return link;
  5. }
  6. }
  7. return null;
  8. }

代码示例来源:origin: matsim-org/matsim

  1. private static Link findLink(Node prevNode, Node node) {
  2. for (Link link : prevNode.getOutLinks().values()) {
  3. if (link.getToNode().equals(node)) {
  4. return link;
  5. }
  6. }
  7. return null;
  8. }

代码示例来源:origin: matsim-org/matsim

  1. public static Map<Id<Node>, ? extends Node> getOutNodes(Node node) {
  2. Map<Id<Node>, Node> nodes = new TreeMap<>();
  3. for (Link link : node.getOutLinks().values()) {
  4. Node outNode = link.getToNode();
  5. nodes.put(outNode.getId(), outNode);
  6. }
  7. return nodes;
  8. }

代码示例来源:origin: matsim-org/matsim

  1. @Override
  2. public final void setSignalized( final boolean isSignalized) {
  3. qSignalizedItem = new DefaultSignalizeableItem(qLink.getToNode().getOutLinks().keySet());
  4. }

代码示例来源:origin: matsim-org/matsim

  1. public static Link findLinkInOppositeDirection(Link link) {
  2. for ( Link candidateLink : link.getToNode().getOutLinks().values() ) {
  3. if ( candidateLink.getToNode().equals( link.getFromNode() ) ) {
  4. return candidateLink ;
  5. }
  6. }
  7. return null ;
  8. }
  9. public static void readNetwork( Network network, String string ) {

代码示例来源:origin: matsim-org/matsim

  1. /**
  2. * Removes nodes from the network that have no incoming or outgoing links attached to them.
  3. */
  4. public void removeNodesWithoutLinks() {
  5. List<Node> toBeRemoved = new ArrayList<>();
  6. for (Node node : this.network.getNodes().values()) {
  7. if ((node.getInLinks().size() == 0) && (node.getOutLinks().size() == 0)) {
  8. toBeRemoved.add(node);
  9. }
  10. }
  11. for (Node node : toBeRemoved) {
  12. this.network.removeNode(node.getId());
  13. }
  14. }

代码示例来源:origin: matsim-org/matsim

  1. @Override
  2. public final void setSignalStateForTurningMove( final SignalGroupState state, final Id<Link> toLinkId) {
  3. if (!qLink.getToNode().getOutLinks().containsKey(toLinkId)){
  4. throw new IllegalArgumentException("ToLink " + toLinkId + " is not reachable from QLink Id " + this.id );
  5. }
  6. qSignalizedItem.setSignalStateForTurningMove(state, toLinkId);
  7. thisTimeStepGreen = qSignalizedItem.hasGreenForAllToLinks();
  8. // (this is only for capacity accumulation. As soon as at least one turning relation is green, the "link" is considered
  9. // green).
  10. }

代码示例来源:origin: matsim-org/matsim

  1. private int getNOfIncidentNodes(final Node node) {
  2. HashMap<Id<Node>, Node> nodes = new HashMap<>();
  3. for (Link link : node.getInLinks().values()) {
  4. nodes.put(link.getFromNode().getId(), link.getFromNode());
  5. }
  6. for (Link link : node.getOutLinks().values()) {
  7. nodes.put(link.getToNode().getId(), link.getToNode());
  8. }
  9. return nodes.size();
  10. }
  11. }

代码示例来源:origin: matsim-org/matsim

  1. @Override
  2. public void run(final Network network) {
  3. Set<Node> nodesToRemove;
  4. if (this.cutType == CutType.RECTANGLE) nodesToRemove = rectangularCut(network);
  5. else if (this.cutType == CutType.CIRCLE) nodesToRemove = circularCut(network);
  6. else return;
  7. int nofLinksRemoved = 0;
  8. for (Node n : nodesToRemove) {
  9. nofLinksRemoved += n.getInLinks().size() + n.getOutLinks().size();
  10. network.removeNode(n.getId());
  11. }
  12. log.info("number of nodes removed: "+nodesToRemove.size());
  13. log.info("number of links removed: "+nofLinksRemoved);
  14. log.info("number of nodes remaining: "+network.getNodes().size());
  15. log.info("number of links remaining: "+network.getLinks().size());
  16. }

代码示例来源:origin: matsim-org/matsim

  1. private void doRandomChoice() {
  2. // Do I want to end at this link?
  3. if (MatsimRandom.getRandom().nextInt(10) == 0) {// 10% chance
  4. nextLinkId = null;
  5. destinationLinkId = currentLinkId;
  6. } else {
  7. // Where do I want to move next?
  8. Link currentLink = network.getLinks().get(currentLinkId);
  9. Map<Id<Link>, ?> possibleNextLinks = currentLink.getToNode().getOutLinks();
  10. // Let's choose the next link randomly
  11. nextLinkId = RandomDynAgentLogic.chooseRandomElement(possibleNextLinks.keySet());
  12. // at this point the destination can be anything, QSim does not take it into account
  13. destinationLinkId = null;
  14. }
  15. }

代码示例来源:origin: matsim-org/matsim

  1. public void registerDownstreamSensors(SignalSystem signalSystem){
  2. for (Signal signal : signalSystem.getSignals().values()){
  3. Node systemNode = this.network.getLinks().get(signal.getLinkId()).getToNode();
  4. for (Id<Link> outgoingLinkId : systemNode.getOutLinks().keySet()) {
  5. this.sensorManager.registerNumberOfCarsMonitoring(outgoingLinkId);
  6. }
  7. break; // systemNode is the same for all signals of the system
  8. }
  9. }

代码示例来源:origin: matsim-org/matsim

  1. private static Map<Id<Node>, Node> getIncidentNodes(Node node) {
  2. Map<Id<Node>, Node> nodes = new TreeMap<>();
  3. for (Link link : node.getInLinks().values()) {
  4. nodes.put(link.getFromNode().getId(), link.getFromNode());
  5. }
  6. for (Link link : node.getOutLinks().values()) {
  7. nodes.put(link.getToNode().getId(), link.getToNode());
  8. }
  9. return nodes;
  10. }

代码示例来源:origin: matsim-org/matsim

  1. @Override
  2. public Node removeNode(final Id<Node> nodeId) {
  3. Node n = this.nodes.remove(nodeId);
  4. if (n == null) {
  5. return null;
  6. }
  7. HashSet<Link> links1 = new HashSet<>();
  8. links1.addAll(n.getInLinks().values());
  9. links1.addAll(n.getOutLinks().values());
  10. for (Link l : links1) {
  11. removeLink(l.getId());
  12. }
  13. if (this.nodeQuadTree != null) {
  14. this.nodeQuadTree.remove(n.getCoord().getX(),n.getCoord().getY(),n);
  15. }
  16. return n;
  17. }

代码示例来源:origin: matsim-org/matsim

  1. /**
  2. * Expands the given Node in the routing algorithm; may be overridden in
  3. * sub-classes.
  4. *
  5. * @param outNode
  6. * The Node to be expanded.
  7. * @param toNode
  8. * The target Node of the route.
  9. * @param pendingNodes
  10. * The set of pending nodes so far.
  11. */
  12. protected void relaxNode(final Node outNode, final Node toNode, final RouterPriorityQueue<Node> pendingNodes) {
  13. DijkstraNodeData outData = getData(outNode);
  14. double currTime = outData.getTime();
  15. double currCost = outData.getCost();
  16. if (this.pruneDeadEnds) {
  17. PreProcessDijkstra.DeadEndData ddOutData = getPreProcessData(outNode);
  18. for (Link l : outNode.getOutLinks().values()) {
  19. relaxNodeLogic(l, pendingNodes, currTime, currCost, toNode, ddOutData);
  20. }
  21. } else { // this.pruneDeadEnds == false
  22. for (Link l : outNode.getOutLinks().values()) {
  23. relaxNodeLogic(l, pendingNodes, currTime, currCost, toNode, null);
  24. }
  25. }
  26. }

代码示例来源:origin: matsim-org/matsim

  1. /**
  2. * Expands the given Node in the routing algorithm; may be overridden in
  3. * sub-classes.
  4. *
  5. * @param outNode
  6. * The Node to be expanded.
  7. * @param pendingNodes
  8. * The set of pending nodes so far.
  9. */
  10. protected void relaxNode(final Node outNode, final RouterPriorityQueue<Node> pendingNodes) {
  11. DijkstraNodeData outData = getData(outNode);
  12. double currTime = outData.getTime();
  13. double currCost = outData.getCost();
  14. for (Link l : outNode.getOutLinks().values()) {
  15. relaxNodeLogic(l, pendingNodes, currTime, currCost);
  16. }
  17. }

代码示例来源:origin: matsim-org/matsim

  1. public boolean allDownstreamLinksEmpty(SignalData signal){
  2. if (signal.getTurningMoveRestrictions() != null) {
  3. return allLinksEmpty(signal.getTurningMoveRestrictions());
  4. } // else:
  5. if (signal.getLaneIds() != null && !signal.getLaneIds().isEmpty()) {
  6. Set<Id<Link>> toLinks = new HashSet<>();
  7. for (Id<Lane> laneId : signal.getLaneIds()) {
  8. Lane lane = lanes.getLanesToLinkAssignments().get(signal.getLinkId()).getLanes().get(laneId);
  9. toLinks.addAll(lane.getToLinkIds());
  10. }
  11. return allLinksEmpty(toLinks);
  12. } // else:
  13. // if no turning move restrictions and no lanes with to links are set, turning is allowed to all outgoing links
  14. Node systemNode = this.network.getLinks().get(signal.getLinkId()).getToNode();
  15. return allLinksEmpty(systemNode.getOutLinks().keySet());
  16. }

代码示例来源:origin: matsim-org/matsim

  1. private void relaxNode(final Node n, PriorityQueue<Node> pendingNodes) {
  2. NodeData nData = nodeData.get(n.getId());
  3. double currTime = nData.getTime();
  4. double currCost = nData.getCost();
  5. for (Link l : n.getOutLinks().values()) {
  6. Node nn = l.getToNode();
  7. NodeData nnData = nodeData.get(nn.getId());
  8. if (nnData == null) {
  9. nnData = new NodeData();
  10. this.nodeData.put(nn.getId(), nnData);
  11. }
  12. double visitCost = currCost + tcFunction.getLinkTravelDisutility(l, currTime, PERSON, VEHICLE);
  13. double visitTime = currTime + ttFunction.getLinkTravelTime(l, currTime, PERSON, VEHICLE);
  14. if (visitCost < nnData.getCost()) {
  15. pendingNodes.remove(nn);
  16. nnData.visit(n.getId(), visitCost, visitTime);
  17. additionalComputationsHook( l, currTime ) ;
  18. pendingNodes.add(nn);
  19. }
  20. }
  21. }

代码示例来源:origin: matsim-org/matsim

  1. private static Link findLinkBetween(final Network network, final Id<Link> fromLinkId, final Id<Link> toLinkId) {
  2. Link fromLink = network.getLinks().get(fromLinkId);
  3. Link toLink = network.getLinks().get(toLinkId);
  4. Node from = fromLink.getToNode();
  5. Node to = toLink.getFromNode();
  6. for (Link link : from.getOutLinks().values()) {
  7. if (link.getToNode() == to) {
  8. return link;
  9. }
  10. }
  11. return null;
  12. }

代码示例来源:origin: matsim-org/matsim

  1. @Test
  2. public void removeLink() {
  3. Fixture f = new Fixture(getEmptyTestNetwork());
  4. Assert.assertTrue(f.network.getLinks().containsKey(f.linkIds[1]));
  5. Assert.assertEquals(1, f.network.getNodes().get(f.nodeIds[1]).getInLinks().size());
  6. f.network.removeLink(f.linkIds[1]);
  7. Assert.assertFalse(f.network.getLinks().containsKey(f.linkIds[1]));
  8. Assert.assertEquals(0, f.network.getNodes().get(f.nodeIds[1]).getInLinks().size());
  9. Assert.assertEquals(1, f.network.getNodes().get(f.nodeIds[1]).getOutLinks().size());
  10. Assert.assertTrue(f.network.getLinks().containsKey(f.linkIds[2]));
  11. f.network.removeLink(f.linkIds[2]);
  12. Assert.assertFalse(f.network.getLinks().containsKey(f.linkIds[2]));
  13. Assert.assertTrue(f.network.getNodes().containsKey(f.nodeIds[1]));
  14. Assert.assertEquals(0, f.network.getNodes().get(f.nodeIds[1]).getOutLinks().size());
  15. Assert.assertEquals(2, f.network.getNodes().get(f.nodeIds[5]).getOutLinks().size());
  16. Assert.assertEquals(2, f.network.getNodes().get(f.nodeIds[8]).getInLinks().size());
  17. f.network.removeLink(f.linkIds[10]);
  18. Assert.assertEquals(1, f.network.getNodes().get(f.nodeIds[5]).getOutLinks().size());
  19. Assert.assertEquals(1, f.network.getNodes().get(f.nodeIds[8]).getInLinks().size());
  20. }

相关文章