/** * A synonym for {@link #add(Edge)}. */ public void push(Node from, Edge edge) { add(from, edge); }
/** * A synonym for {@link #add(Edge)}. */ public void push(Edge edge) { add(edge); }
/** * A synonym for {@link #add(Edge)}. */ public void push(Node from, Edge edge) { add(from, edge); }
/** * A synonym for {@link #add(Edge)}. */ public void push(Edge edge) { add(edge); }
/** * 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; }
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())); }
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; } }
} else { Edge parentEdge = list.get(0); p.add(v, parentEdge); v = parentEdge.getOpposite(v);
@SuppressWarnings("unchecked") private void pathSetShortestPath_facilitate(Node current, Path path, List<Path> paths) { Node source = graph.getNode(this.source_id); if (current != source) { Node next = null; ArrayList<? extends Edge> predecessors = (ArrayList<? extends Edge>) current .getAttribute(identifier+".predecessors"); while (current != source && predecessors.size() == 1) { Edge e = predecessors.get(0); next = e.getOpposite(current); path.add(current, e); current = next; predecessors = (ArrayList<? extends Edge>) current .getAttribute(identifier+".predecessors"); } if (current != source) { for (Edge e : predecessors) { Path p = path.getACopy(); p.add(current, e); pathSetShortestPath_facilitate(e.getOpposite(current), p, paths); } } } if (current == source) { paths.add(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; } }
@SuppressWarnings("unchecked") private void pathSetShortestPath_facilitate(Node current, Path path, List<Path> paths) { Node source = graph.getNode(this.source_id); if (current != source) { Node next = null; ArrayList<? extends Edge> predecessors = (ArrayList<? extends Edge>) current .getAttribute(identifier+".predecessors"); while (current != source && predecessors.size() == 1) { Edge e = predecessors.get(0); next = e.getOpposite(current); path.add(current, e); current = next; predecessors = (ArrayList<? extends Edge>) current .getAttribute(identifier+".predecessors"); } if (current != source) { for (Edge e : predecessors) { Path p = path.getACopy(); p.add(current, e); pathSetShortestPath_facilitate(e.getOpposite(current), p, paths); } } } if (current == source) { paths.add(path); } }