Example #1
0
  @SuppressWarnings("unchecked")
  private void formSplitComponent(
      V u,
      V v,
      V current,
      List<E> coveredEdges,
      List<V> coveredVertices,
      SplitComponent<V, E> component,
      Graph<V, E> graph) {

    if (coveredVertices.contains(current)) return;
    coveredVertices.add(current);

    component.addVertex(current);
    for (E e : graph.allEdges(current)) {
      if (coveredEdges.contains(e)) continue;

      coveredEdges.add(e);
      component.addEdge(e);
      V other = e.getDestination() == current ? e.getOrigin() : e.getDestination();
      if (other != u && other != v) {
        formSplitComponent(u, v, other, coveredEdges, coveredVertices, component, graph);
      } else component.addVertex(other);
    }
  }
Example #2
0
  @SuppressWarnings("unchecked")
  public List<SplitComponent<V, E>> findAllSplitComponents(
      Graph<V, E> graph, SplitPair<V, E> splitPair) {

    List<E> coveredEdges = new ArrayList<E>();
    List<SplitComponent<V, E>> ret = new ArrayList<SplitComponent<V, E>>();
    V u = splitPair.getU();
    V v = splitPair.getV();
    // add edge

    List<E> edges = graph.edgeesBetween(u, v);

    for (E e : edges) { // TODO sta ako stvarno ima vise izmedju, da li ovako, ili ne moze...?
      SplitComponent<V, E> component = new SplitComponent<>(splitPair, graph);
      component.addVertex(v);
      component.addVertex(u);
      component.addEdge(e);
      coveredEdges.add(e);
      ret.add(component);
    }

    for (E e : graph.allEdges(u)) {
      if (coveredEdges.contains(e)) continue;
      SplitComponent<V, E> component = new SplitComponent<>(splitPair, graph);

      coveredEdges.add(e);
      component.addVertex(u);
      component.addEdge(e);
      V other = e.getDestination() == u ? e.getOrigin() : e.getDestination();
      if (other == v) // just add split pair vertices and the edge{
      continue;
      else {
        formSplitComponent(u, v, other, coveredEdges, new ArrayList<V>(), component, graph);
      }
      ret.add(component);
    }

    return ret;
  }
Example #3
0
  /**
   * A pair {u,v} of vertices is a split pair if it is an edge in the graph or if it is a separation
   * pair (it increases the number of connected components) in the graph (graph is no longer
   * connected if it is removed)
   *
   * @param graph
   * @return
   */
  public List<SplitPair<V, E>> findAllSplitPairs(Graph<V, E> graph) {

    List<SplitPair<V, E>> ret = new ArrayList<SplitPair<V, E>>();
    List<V> excluding = new ArrayList<V>();

    List<V> vertices = graph.getVertices();

    for (int i = 0; i < vertices.size(); i++)
      for (int j = i + 1; j < vertices.size(); j++) {
        V v1 = vertices.get(i);
        V v2 = vertices.get(j);
        if (graph.hasEdge(v1, v2)) ret.add(new SplitPair<V, E>(v1, v2));
        else {
          excluding.clear();
          excluding.add(v1);
          excluding.add(v2);
          if (!graph.isConnected(excluding)) {
            ret.add(new SplitPair<V, E>(v1, v2));
          }
        }
      }

    return ret;
  }
Example #4
0
 /**
  * A cut vertex is a vertex whose removal would disconnect the remaining graph
  *
  * @param graph
  * @return
  */
 public List<V> findAllCutVertices(Graph<V, E> graph) {
   return graph.listCutVertices();
 }