예제 #1
0
  /** {@inheritDoc} */
  public void generateGraph(
      Graph<V, E> target, final VertexFactory<V> vertexFactory, Map<String, V> resultMap) {
    if (size < 1) {
      return;
    }

    // A little trickery to intercept the rim generation.  This is
    // necessary since target may be initially non-empty, meaning we can't
    // rely on its vertex set after the rim is generated.
    final Collection<V> rim = new ArrayList<V>();
    VertexFactory<V> rimVertexFactory =
        new VertexFactory<V>() {
          public V createVertex() {
            V vertex = vertexFactory.createVertex();
            rim.add(vertex);

            return vertex;
          }
        };

    RingGraphGenerator<V, E> ringGenerator = new RingGraphGenerator<V, E>(size - 1);
    ringGenerator.generateGraph(target, rimVertexFactory, resultMap);

    V hubVertex = vertexFactory.createVertex();
    target.addVertex(hubVertex);

    if (resultMap != null) {
      resultMap.put(HUB_VERTEX, hubVertex);
    }

    for (V rimVertex : rim) {
      if (inwardSpokes) {
        target.addEdge(rimVertex, hubVertex);
      } else {
        target.addEdge(hubVertex, rimVertex);
      }
    }
  }
예제 #2
0
 private SimpleGraph<Integer, DefaultEdge> buildRingGraph(int size) {
   SimpleGraph<Integer, DefaultEdge> clique = new SimpleGraph<>(DefaultEdge.class);
   RingGraphGenerator<Integer, DefaultEdge> graphGenerator = new RingGraphGenerator<>(size);
   graphGenerator.generateGraph(clique, new IntegerVertexFactory(), null);
   return clique;
 }