Ejemplo n.º 1
0
 /**
  * Trawl through the graph one node at a time looking forward and building up hashsets of nodes
  * and edges.
  *
  * @param vToAdd
  * @param eToAdd
  * @param current
  * @param g
  */
 public void searchAndAdd(
     HashSet<String> vToAdd,
     HashSet<String> eToAdd,
     Vertex current,
     Graph<Vertex, Edge> g,
     Vertex end) {
   // System.out.println("Called searchAndAdd with " + current.toString()
   // );
   for (Edge e : g.outgoingEdgesOf(current)) {
     eToAdd.add(e.toString());
     Edge foundEdge = g.edgeRef.get(e.toString());
     if (foundEdge == null) {
       if (__DEBUG) {
         a.e.println("Found an edge from " + e.toString() + " but counldn't find it in the graph");
       }
       g.addE(e);
       foundEdge = g.edgeRef.get(e.toString());
     }
     Vertex Target = foundEdge.target;
     // a.e.println("Making edge from " + current.toString() + " to " +
     // Target.toString());
     if (Target.toString().compareTo(current.toString()) != 0) {
       if (end != null) {
         if (Target.toString().compareTo(end.toString()) == 0) {
           continue;
         }
       }
       vToAdd.add(g.edgeRef.get(e.toString()).target.id);
       searchAndAdd(vToAdd, eToAdd, g.edgeRef.get(e.toString()).target, g, end);
     }
   }
 }
Ejemplo n.º 2
0
 public Graph<v, e> copyGraph(Graph<v, e> in) {
   Graph<v, e> copy = new Graph<v, e>(Edge.class);
   for (Vertex v : in.vertexSet()) {
     copy.addV(v);
   }
   for (Edge e : in.edgeSet()) {
     copy.addE(e);
   }
   return copy;
 }
Ejemplo n.º 3
0
  /**
   * Copy a graph into the Graph structure
   *
   * @param g
   */
  public void copyInGraph(Graph<Vertex, Edge> g) {
    if (this.subGraphs.contains(g.name)) {
      return;
    }

    for (Vertex v : g.vertexSet()) {
      this.addV(v);
    }
    for (Edge e : g.edgeSet()) {
      this.addE(e);
    }
    this.subGraphs.add(g.name);
    if (!allGraphs.containsKey(g.name)) {
      allGraphs.put(g.name, g);
    }
  }