protected void constructNextPath() { if (nodes.isEmpty()) { nextPath = null; return; } nextPath = new Path(); nextPath.setRoot(source); for (int i = nodes.size() - 1; i > 0; i--) nextPath.add(nodes.get(i).getEdgeToward( nodes.get(i - 1).getId())); }
throw new IllegalArgumentException("From node cannot be null."); } else { setRoot(from);
protected void constructNextPath() { if (nodes.isEmpty()) { nextPath = null; return; } nextPath = new Path(); nextPath.setRoot(source); for (int i = nodes.size() - 1; i > 0; i--) nextPath.add(nodes.get(i).getEdgeToward( nodes.get(i - 1).getId())); }
throw new IllegalArgumentException("From node cannot be null."); } else { setRoot(from);
/** * Returns the shortest path from the source node to a given target node. If * there is no path from the source to the target returns an empty path. * This method constructs a {@link org.graphstream.graph.Path} object which * consumes heap memory proportional to the number of edges and nodes in the * path. When possible, prefer using {@link #getPathNodes(Node)} and * {@link #getPathEdges(Node)} which are more memory- and time-efficient. * * @param target * a node * @return the shortest path from the source to the target * @complexity O(<em>p</em>) where <em>p</em> is the number of the nodes in * the path */ public Path getPath(Node target) { Path path = new Path(); if (Double.isInfinite(getPathLength(target))) return path; Stack<Edge> stack = new Stack<Edge>(); for (Edge e : getPathEdges(target)) stack.push(e); path.setRoot(source); while (!stack.isEmpty()) path.add(stack.pop()); return path; } }
/** * Returns the shortest path from the source node to a given target node. If * there is no path from the source to the target returns an empty path. * This method constructs a {@link org.graphstream.graph.Path} object which * consumes heap memory proportional to the number of edges and nodes in the * path. When possible, prefer using {@link #getPathNodes(Node)} and * {@link #getPathEdges(Node)} which are more memory- and time-efficient. * * @param target * a node * @return the shortest path from the source to the target * @complexity O(<em>p</em>) where <em>p</em> is the number of the nodes in * the path */ public Path getPath(Node target) { Path path = new Path(); if (Double.isInfinite(getPathLength(target))) return path; Stack<Edge> stack = new Stack<Edge>(); for (Edge e : getPathEdges(target)) stack.push(e); path.setRoot(source); while (!stack.isEmpty()) path.add(stack.pop()); return path; } }
/** * Returns the shortest path from the source node to a given target node. If * there is no path from the source to the target returns an empty path. * This method constructs a {@link org.graphstream.graph.Path} object which * consumes heap memory proportional to the number of edges and nodes in the * path. When possible, prefer using {@link #getPathNodes(Node)} and * {@link #getPathEdges(Node)} which are more memory- and time-efficient. * * @param target * a node * @return the shortest path from the source to the target * @complexity O(<em>p</em>) where <em>p</em> is the number of the nodes in * the path */ public Path getPath(Node target) { Path path = new Path(); if (getPathLength(target) == Long.MAX_VALUE) return path; Stack<Edge> stack = new Stack<Edge>(); for (Edge e : getPathEdges(target)) stack.push(e); path.setRoot(graph.getNode(sourceId)); while (!stack.isEmpty()) path.add(stack.pop()); return path; } }
/** * Returns the shortest path from the source node to a given target node. If * there is no path from the source to the target returns an empty path. * This method constructs a {@link org.graphstream.graph.Path} object which * consumes heap memory proportional to the number of edges and nodes in the * path. When possible, prefer using {@link #getPathNodes(Node)} and * {@link #getPathEdges(Node)} which are more memory- and time-efficient. * * @param target * a node * @return the shortest path from the source to the target * @complexity O(<em>p</em>) where <em>p</em> is the number of the nodes in * the path */ public Path getPath(Node target) { Path path = new Path(); if (getPathLength(target) == Long.MAX_VALUE) return path; Stack<Edge> stack = new Stack<Edge>(); for (Edge e : getPathEdges(target)) stack.push(e); path.setRoot(graph.getNode(sourceId)); while (!stack.isEmpty()) path.add(stack.pop()); return path; } }