コード例 #1
0
ファイル: Group.java プロジェクト: michael-k/ccvisu
 /**
  * adds nodes to a group in function of a given pattern
  *
  * @param pattern
  * @param mode the way of using the pattern.
  */
 public void addViaPattern(String pattern, PatternMode mode) {
   for (GraphVertex graphVertex : graph.getVertices()) {
     switch (mode) {
       case CONTAINS:
         if (graphVertex.getName().matches(".*" + pattern + ".*")) {
           addNode(graphVertex);
         }
         break;
       case ENDS:
         if (graphVertex.getName().endsWith(pattern)) {
           addNode(graphVertex);
         }
         break;
       case EQUALS:
         if (graphVertex.getName().equals(pattern)) {
           addNode(graphVertex);
         }
         break;
       case STARTS:
         if (graphVertex.getName().startsWith(pattern)) {
           addNode(graphVertex);
         }
         break;
     }
   }
 }
コード例 #2
0
 private static void DFS(GraphVertex cur, int time, List<GraphVertex> contacts) {
   for (GraphVertex next : cur.edges) {
     if (next.visitTime != time) {
       next.visitTime = time;
       contacts.add(next);
       DFS(next, time, contacts);
     }
   }
 }
コード例 #3
0
ファイル: Group.java プロジェクト: michael-k/ccvisu
  public void setShape(Shape shape) {
    assert (shape != null);

    this.shape = shape;

    for (GraphVertex graphVertex : nodes) {
      graphVertex.setShape(shape);
    }
  }
コード例 #4
0
ファイル: Group.java プロジェクト: michael-k/ccvisu
  public void filter(String pattern, PatternMode mode, boolean keep) {
    Iterator<GraphVertex> it = getNodes().iterator();
    while (it.hasNext()) {
      GraphVertex vertex = it.next();
      String vertexName = vertex.getName();

      boolean match =
          (mode == PatternMode.EQUALS && vertexName.equals(pattern))
              || (mode == PatternMode.CONTAINS && vertexName.matches(".*" + pattern + ".*"))
              || (mode == PatternMode.STARTS && vertexName.startsWith(pattern))
              || (mode == PatternMode.ENDS && vertexName.endsWith(pattern));

      boolean remove = (match && !keep) || (!match && keep);

      if (remove) {
        removeNode(vertex, true);
      }
    }
  }
コード例 #5
0
  private int addNode(int par) {
    GraphVertex p = verts.get(par);
    p.Marked = true;
    int unmarked = 0;

    // Update min Distance
    double t_min;
    GraphVertex gv;
    for (int i = 0; i < verts.size(); i++) {

      if (i == par) continue;
      gv = verts.get(i);
      if (!gv.Marked) {
        unmarked++;

        t_min = p.distanceTo(gv);
        if (t_min < Queue[i]) {
          // This path is shorter
          Parent[i] = par;
          Queue[i] = t_min;
        }
      }
    }

    // Now pick shortest path in Queue
    double minQ = Double.MAX_VALUE;
    int minI = -1;
    for (int i = 0; i < verts.size(); i++) {
      if (Queue[i] < minQ) {
        minI = i;
        minQ = Queue[i];
      }
    }

    // Add it and mark it
    GraphVertex conn_par = verts.get(Parent[minI]);
    GraphVertex conn_child = verts.get(minI);
    Queue[minI] = Double.MAX_VALUE;
    conn_child.connectTo(conn_par);
    conn_child.Marked = true;
    unmarked--;

    if (unmarked > 0) {
      addNode(minI);
    }

    return unmarked;
  }
コード例 #6
0
ファイル: Group.java プロジェクト: michael-k/ccvisu
 /** @param color color to define. */
 public void setColor(Color color) {
   this.color = color;
   for (GraphVertex vertex : nodes) {
     vertex.setColor(color);
   }
 }
コード例 #7
0
ファイル: Group.java プロジェクト: michael-k/ccvisu
 /**
  * add the given node to the group
  *
  * @param vertex
  */
 public void addNode(GraphVertex vertex) {
   vertex.setColor(color);
   vertex.setShape(shape);
   addNode_WO_COLOR(vertex);
 }