예제 #1
0
  private SimpleGraph<DefaultVertex, DefaultEdge<DefaultVertex>> constructLineGraph() {

    SimpleGraph<DefaultVertex, DefaultEdge<DefaultVertex>> lg =
        new SimpleGraph<DefaultVertex, DefaultEdge<DefaultVertex>>(graph.getEdgeFactory());

    HashMap<DefaultVertex, DefaultEdge<DefaultVertex>> map =
        new HashMap<DefaultVertex, DefaultEdge<DefaultVertex>>();

    for (DefaultEdge<DefaultVertex> e : graph.edgeSet()) {
      DefaultVertex v = getMidPoint(e.getSource(), e.getTarget());
      lg.addVertex(v);
      map.put(v, e);
    }

    for (DefaultVertex v1 : lg.vertexSet()) {
      for (DefaultVertex v2 : lg.vertexSet()) {
        if (v1 == v2 || lg.containsEdge(v1, v2)) continue;
        DefaultEdge<DefaultVertex> e1 = map.get(v1);
        DefaultEdge<DefaultVertex> e2 = map.get(v2);

        if (Neighbors.isIncidentEdge(graph, e1, e2)) lg.addEdge(v1, v2);
      }
    }

    return lg;
  }