Ejemplo n.º 1
0
  public boolean addE(Edge myE) {
    if (!existingEdges.contains(myE.toString())) {
      existingEdges.add(myE.toString());
      edgeRef.put(myE.toString(), myE);
      Vertex src = myE.getSource();
      Vertex trg = myE.getTarget();

      if (src == null) {
        if (__DEBUG) {
          a.e.println("src node not found ");
        }
        return false;
      }
      if (trg == null) {
        if (__DEBUG) {
          a.e.println("trg node not found ");
        }
        return false;
      }

      if (__DEBUG && a.e.__HIGHDETAILS) {
        a.e.println(src.name + " " + inDegreeOf(src));
      }
      if (__DEBUG && a.e.__HIGHDETAILS) {
        a.e.println(trg.toString() + " ");
      }
      return this.addEdge(src, trg, myE);
    }
    return false;
  }
Ejemplo n.º 2
0
  @Override
  public String toString() {
    String result = a.e.dent() + "g[{" + "NODES:" + a.e.endl;
    a.e.incIndent();
    for (Vertex t : vertexSet()) {
      result += a.e.dent() + t.toString() + a.e.endl;
    }
    result += "}{EDGES: " + a.e.endl;

    for (Edge e : edgeSet()) {
      result += a.e.dent() + e.toString() + a.e.endl;
    }
    a.e.decIndent();
    if (processPools.size() > 0) {
      result += a.e.dent() + "Pools:(" + a.e.endl;
      a.e.incIndent();
      for (String key : processPools.keySet()) {
        result += processPools.get(key).toString();
      }
      a.e.decIndent();
      result += ")[End of Pools]" + a.e.endl;
    }

    return result + "}]" + a.e.endl;
  }
Ejemplo n.º 3
0
 @Override
 public String toString() {
   StringBuffer buf = new StringBuffer();
   for (Edge edge : edges) {
     buf.append(edge.toString() + "\n");
   }
   return buf.toString();
 }
Ejemplo n.º 4
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.º 5
0
  protected Edge newEdgeGreater(
      Edge previous,
      int keyMax,
      char[] existing,
      int matchesTo,
      char[] key,
      int keyIndex,
      int keyEnd,
      E value) {
    // found our break point
    char[] newRootKey = new char[matchesTo];
    char[] newExistingKey = new char[existing.length - newRootKey.length];
    char[] newInsertedKey = new char[keyMax - newRootKey.length];

    // copy the common root into our new parent edge
    System.arraycopy(existing, 0, newRootKey, 0, newRootKey.length);
    Edge newRoot = new Edge(newRootKey, 0, newRootKey.length);

    // trim the existing key to it's unique suffix value
    System.arraycopy(existing, newRootKey.length, newExistingKey, 0, newExistingKey.length);
    previous.key = newExistingKey;

    // create a new node for our value
    System.arraycopy(key, keyIndex + newRootKey.length, newInsertedKey, 0, newInsertedKey.length);
    Edge newEdge = new Edge(newInsertedKey, 0, newInsertedKey.length);
    newEdge.value = value;

    assert newRoot.key.length > 0;
    assert previous.key.length > 0;
    assert newEdge.key.length > 0;

    newRoot.lesser = previous;
    newRoot.greater = newEdge;
    assert newEdge.toString().compareTo(previous.toString()) > 0;

    return newRoot;
  }
 /** {@inheritDoc} */
 @Override
 public String toString() {
   StringBuilder builder = new StringBuilder();
   builder
       .append("vertex:")
       .append(" value=")
       .append(value)
       .append(" weight=")
       .append(weight)
       .append("\n");
   for (Edge<T> e : edges) {
     builder.append("\t").append(e.toString());
   }
   return builder.toString();
 }
Ejemplo n.º 7
0
  @Override
  public String toString() {

    StringBuilder s = new StringBuilder();
    s.append("Nodes: ");
    for (Node<N, E> n : getNodes()) {
      s.append(n.toString());
      s.append("\n");
    }

    s.append("Edges: ");

    for (Edge<N, E> e : getEdges()) {
      s.append(e.toString());
      s.append("\n");
    }

    return s.toString();
  }
Ejemplo n.º 8
0
 public void printAllEdges() {
   for (Edge edge : edges) {
     System.out.println(edge.toString());
   }
 }
Ejemplo n.º 9
0
 public boolean removeE(Edge myE) {
   existingEdges.remove(myE.toString());
   edgeRef.remove(myE.toString());
   this.removeEdge(myE);
   return true;
 }