コード例 #1
0
ファイル: BellmanFord.java プロジェクト: gjherbiet/gs-algo
  @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);
    }
  }
コード例 #2
0
ファイル: Path.java プロジェクト: rossjudson/gs-core
  /**
   * 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;
  }
コード例 #3
0
ファイル: BellmanFord.java プロジェクト: gjherbiet/gs-algo
 /**
  * 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;
 }