/** * Constructs all the possible shortest paths from the source node to the * destination (end). Warning: this construction is VERY HEAVY ! * * @param end * The destination to which shortest paths are computed. * @return a list of shortest paths given with * {@link org.graphstream.graph.Path} objects. */ public List<Path> getPathSetShortestPaths(Node end) { ArrayList<Path> paths = new ArrayList<Path>(); pathSetShortestPath_facilitate(end, new Path(), paths); return paths; }
/** * Constructs all the possible shortest paths from the source node to the * destination (end). Warning: this construction is VERY HEAVY ! * * @param end * The destination to which shortest paths are computed. * @return a list of shortest paths given with * {@link org.graphstream.graph.Path} objects. */ public List<Path> getPathSetShortestPaths(Node end) { ArrayList<Path> paths = new ArrayList<Path>(); pathSetShortestPath_facilitate(end, new Path(), paths); return paths; }
/** * Get a copy of this path * * @return A copy of this path. */ @SuppressWarnings("unchecked") public Path getACopy() { Path newPath = new Path(); newPath.root = this.root; newPath.edgePath = (Stack<Edge>) edgePath.clone(); newPath.nodePath = (Stack<Node>) nodePath.clone(); return newPath; }
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())); }
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())); }
/** * Get a copy of this path * * @return A copy of this path. */ @SuppressWarnings("unchecked") public Path getACopy() { Path newPath = new Path(); newPath.root = this.root; newPath.edgePath = (Stack<Edge>) edgePath.clone(); newPath.nodePath = (Stack<Node>) nodePath.clone(); return newPath; }
/** * Build the shortest path from the target/destination node, following the * parent links. * * @param target * The destination node. * @return The path. */ public Path buildPath(AStarNode target) { Path path = new Path(); ArrayList<AStarNode> thePath = new ArrayList<AStarNode>(); AStarNode node = target; while (node != null) { thePath.add(node); node = node.parent; } int n = thePath.size(); if (n > 1) { AStarNode current = thePath.get(n - 1); AStarNode follow = thePath.get(n - 2); path.add(current.node, follow.edge); current = follow; for (int i = n - 3; i >= 0; i--) { follow = thePath.get(i); path.add(follow.edge); current = follow; } } return path; }
/** * Build the shortest path from the target/destination node, following the * parent links. * * @param target * The destination node. * @return The path. */ public Path buildPath(AStarNode target) { Path path = new Path(); ArrayList<AStarNode> thePath = new ArrayList<AStarNode>(); AStarNode node = target; while (node != null) { thePath.add(node); node = node.parent; } int n = thePath.size(); if (n > 1) { AStarNode current = thePath.get(n - 1); AStarNode follow = thePath.get(n - 2); path.add(current.node, follow.edge); current = follow; for (int i = n - 3; i >= 0; i--) { follow = thePath.get(i); path.add(follow.edge); current = follow; } } return path; }
public Path getShortestPathTo(String other) { TargetPath tpath = targets.get(other); // XXX Probably a bug here in the Path class usage. // TODO update this to create an edge path to be compatible with // multi-graphs. if (tpath != null) { Path path = new Path(); // XXX use the Path object directly. ArrayList<Node> nodePath = new ArrayList<Node>(); nodePath.add(source); nodePath.add(tpath.target); // Recursively build the path between the source and target node // by exploring pass-by nodes. expandPath(1, this, tpath, nodePath); // Build a Path object. for (int i = 0; i < nodePath.size() - 1; ++i) { // XXX XXX complicated ? path.add( nodePath.get(i), nodePath.get(i).getEdgeToward( nodePath.get(i + 1).getId())); } return path; } return null; }
public Path getShortestPathTo(String other) { TargetPath tpath = targets.get(other); // XXX Probably a bug here in the Path class usage. // TODO update this to create an edge path to be compatible with // multi-graphs. if (tpath != null) { Path path = new Path(); // XXX use the Path object directly. ArrayList<Node> nodePath = new ArrayList<Node>(); nodePath.add(source); nodePath.add(tpath.target); // Recursively build the path between the source and target node // by exploring pass-by nodes. expandPath(1, this, tpath, nodePath); // Build a Path object. for (int i = 0; i < nodePath.size() - 1; ++i) { // XXX XXX complicated ? path.add( nodePath.get(i), nodePath.get(i).getEdgeToward( nodePath.get(i + 1).getId())); } return path; } return null; }
/** * gets longest path * * @return longest path */ public Path getLongestPath() { Path path = new Path(); for (int i = 0; i < longestPath.size(); i++) { for (Edge edge : graph.getEachEdge()) { if (!edge.getSourceNode().equals(longestPath.get(i))) { continue; } if (!edge.getTargetNode().equals(longestPath.get(i + 1))) { continue; } path.add(edge.getSourceNode(), edge); } } 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 (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; } }
Path p = new Path(); if (target == source ) { return p;
Path p = new Path(); if (target == source ) { return p;