@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); } }
@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; }