@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); } }
/** * A maximal split pair with respect to some edge is a split pair not dominated by any other split * pair with respect to that edge There may several such pairs * * @param graph * @param edge * @return */ public List<SplitPair<V, E>> maximalSplitPairs(Graph<V, E> graph, E edge) { List<SplitPair<V, E>> ret = new ArrayList<SplitPair<V, E>>(); List<SplitPair<V, E>> splitPairs = findAllSplitPairs(graph); SplitPair<V, E> edgeSplit = new SplitPair<V, E>(edge.getOrigin(), edge.getDestination()); for (SplitPair<V, E> splitPair1 : splitPairs) { if (splitPair1.equals(edgeSplit)) continue; boolean maximal = true; for (SplitPair<V, E> splitPair2 : splitPairs) { if (splitPair2.equals(edgeSplit)) continue; if (splitPair1 == splitPair2) continue; if (splitPairIsDominantedBy(graph, splitPair1, splitPair2, edge)) { maximal = false; break; } } if (maximal) ret.add(splitPair1); } return ret; }
@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; }