コード例 #1
0
  /**
   * Creates a new iterator for the specified graph. Iteration will start at the specified start
   * vertex. If the specified start vertex is <code>
   * null</code>, Iteration will start at an arbitrary graph vertex.
   *
   * @param g the graph to be iterated.
   * @param startVertex the vertex iteration to be started.
   * @throws IllegalArgumentException if <code>g==null</code> or does not contain <code>startVertex
   *     </code>
   */
  public CrossComponentIterator(Graph<V, E> g, V startVertex) {
    super();

    if (g == null) {
      throw new IllegalArgumentException("graph must not be null");
    }
    graph = g;

    specifics = createGraphSpecifics(g);
    vertexIterator = g.vertexSet().iterator();
    setCrossComponentTraversal(startVertex == null);

    reusableEdgeEvent = new FlyweightEdgeEvent<V, E>(this, null);
    reusableVertexEvent = new FlyweightVertexEvent<V>(this, null);

    if (startVertex == null) {
      // pick a start vertex if graph not empty
      if (vertexIterator.hasNext()) {
        this.startVertex = vertexIterator.next();
      } else {
        this.startVertex = null;
      }
    } else if (g.containsVertex(startVertex)) {
      this.startVertex = startVertex;
    } else {
      throw new IllegalArgumentException("graph must contain the start vertex");
    }
  }
コード例 #2
0
ファイル: PajekImporter.java プロジェクト: 52nlp/graphsm_wsdm
  @Override
  public void generateGraph(
      Graph<V, E> veGraph, VertexFactory<V> vVertexFactory, Map<String, V> stringVMap) {

    Map<Integer, V> intToNodeMap = new HashMap<Integer, V>();

    for (Integer nodeID : selected.vertices.keySet()) {
      V node = vVertexFactory.createVertex();
      if (!veGraph.containsVertex(node)) veGraph.addVertex(node);
      intToNodeMap.put(nodeID, node);
    }

    for (PajekArc arc : selected.arcs) {
      V source = intToNodeMap.get(arc.source);
      V target = intToNodeMap.get(arc.target);
      E edge = null;
      if (!veGraph.containsEdge(source, target)) edge = veGraph.addEdge(source, target);
      else edge = veGraph.getEdge(source, target);

      if (veGraph instanceof WeightedGraph)
        ((WeightedGraph) veGraph).setEdgeWeight(edge, arc.weight);
    }
  }