/** * Method that adds an edge an a node to the path. The new edge to add is given. * * @param edge The edge to add to the path. */ public void add(Edge edge) { if (nodePath.isEmpty()) { add(null, edge); } else { add(nodePath.peek(), edge); } }
@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 between the source node and one given target. If multiple shortest * paths exist, one of them is returned at random. * * @param target the target of the shortest path starting at the source node given in the * constructor. * @return A {@link org.graphstream.graph.Path} object that constrains the list of nodes and edges * that constitute it. */ @SuppressWarnings("unchecked") public Path getShortestPath(Node target) { Path p = new Path(); if (target == source) { return p; } boolean noPath = false; Node v = target; while (v != source && !noPath) { ArrayList<? extends Edge> list = (ArrayList<? extends Edge>) v.getAttribute(identifier + ".predecessors"); if (list == null) { noPath = true; } else { Edge parentEdge = list.get(0); p.add(v, parentEdge); v = parentEdge.getOpposite(v); } } return p; }
/** 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); }