コード例 #1
0
ファイル: GraphOrdering.java プロジェクト: RomaKoks/jgrapht
  /**
   * @param v1Number the number of the first vertex v1
   * @param v2Number the number of the second vertex v2
   * @return exists the edge from v1 to v2
   */
  public boolean hasEdge(int v1Number, int v2Number) {
    V v1, v2;
    Boolean containsEdge = null;

    if (cacheEdges) {
      containsEdge = adjMatrix[v1Number][v2Number];
    }

    if (!cacheEdges || (containsEdge == null)) {
      v1 = getVertex(v1Number);
      v2 = getVertex(v2Number);
      containsEdge = graph.containsEdge(v1, v2);
    }

    if (cacheEdges && (adjMatrix[v1Number][v2Number] == null)) {
      adjMatrix[v1Number][v2Number] = containsEdge;
    }

    return containsEdge;
  }
コード例 #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);
    }
  }