예제 #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);
    }
  }
예제 #2
0
  /**
   * A split graph of a split pair with respect of some edge is the union of all split components
   * which don't contain that edge
   *
   * @param splitComponents
   * @param edge
   * @return
   */
  public Graph<V, E> splitGraph(List<SplitComponent<V, E>> splitComponents, E edge) {

    List<Graph<V, E>> allComponentsNotContainingEdge = new ArrayList<Graph<V, E>>();
    for (SplitComponent<V, E> component : splitComponents)
      if (!component.getEdges().contains(edge)) allComponentsNotContainingEdge.add(component);

    GraphOperations<V, E> operations = new GraphOperations<>();
    return operations.union(allComponentsNotContainingEdge);
  }
예제 #3
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;
  }