app/src/main/java/org/jgrapht/alg/StoerWagnerMinimumCut.java
protected VertexAndWeight mergeVertices(Set<V> s, Set<V> t)
    {
        //construct the new combinedvertex
        Set<V> set = new HashSet<V>();
        set.addAll(s);
        set.addAll(t);
        workingGraph.addVertex(set);

        //add edges and weights to the combined vertex
        double wsum = 0.0;
        for (Set<V> v : workingGraph.vertexSet()) {
            if ((s != v) && (t != v)) {
                double neww = 0.0;
                DefaultWeightedEdge etv = workingGraph.getEdge(t, v);
                DefaultWeightedEdge esv = workingGraph.getEdge(s, v);
                if (etv != null) {
                    neww += workingGraph.getEdgeWeight(etv);
                }
                if (esv != null) {
                    neww += workingGraph.getEdgeWeight(esv);
                }
                if ((etv != null) || (esv != null)) {
                    wsum += neww;
                    workingGraph.setEdgeWeight(
                        workingGraph.addEdge(set, v),
                        neww);
                }
            }
        }

        //remove original vertices
        workingGraph.removeVertex(t);
        workingGraph.removeVertex(s);

        return new VertexAndWeight(set, wsum, false);
    }
/**
     * Merges vertex t into vertex s, summing the weights as required. Returns
     * the merged vertex and the sum of its weights
     */
Merges vertex t into vertex s, summing the weights as required. Returns
the merged vertex and the sum of its weights
Merges vertex t into vertex s summing the weights as required . Returns the merged vertex and the sum of its weights
protected VertexAndWeight mergeVertices(Set<V> s, Set<V> t)
    {
        Set<V> set = new HashSet<V>();
        set.addAll(s);
        set.addAll(t);
        workingGraph.addVertex(set);
        double wsum = 0.0;
        for (Set<V> v : workingGraph.vertexSet()) {
            if ((s != v) && (t != v)) {
                double neww = 0.0;
                DefaultWeightedEdge etv = workingGraph.getEdge(t, v);
                DefaultWeightedEdge esv = workingGraph.getEdge(s, v);
                if (etv != null) {
                    neww += workingGraph.getEdgeWeight(etv);
                }
                if (esv != null) {
                    neww += workingGraph.getEdgeWeight(esv);
                }
                if ((etv != null) || (esv != null)) {
                    wsum += neww;
                    workingGraph.setEdgeWeight(
                        workingGraph.addEdge(set, v),
                        neww);
                }
            }
        }
        workingGraph.removeVertex(t);
        workingGraph.removeVertex(s);
        return new VertexAndWeight(set, wsum, false);
    }
protected VertexAndWeight mergeVertices ( Set < V > s , Set < V > t ) { Set < V > set = new HashSet < V > ( ) ; set . addAll ( s ) ; set . addAll ( t ) ; workingGraph . addVertex ( set ) ; double wsum = 0.0 ; for ( Set < V > v : workingGraph . vertexSet ( ) ) { if ( ( s != v ) && ( t != v ) ) { double neww = 0.0 ; DefaultWeightedEdge etv = workingGraph . getEdge ( t , v ) ; DefaultWeightedEdge esv = workingGraph . getEdge ( s , v ) ; if ( etv != null ) { neww += workingGraph . getEdgeWeight ( etv ) ; } if ( esv != null ) { neww += workingGraph . getEdgeWeight ( esv ) ; } if ( ( etv != null ) || ( esv != null ) ) { wsum += neww ; workingGraph . setEdgeWeight ( workingGraph . addEdge ( set , v ) , neww ) ; } } } workingGraph . removeVertex ( t ) ; workingGraph . removeVertex ( s ) ; return new VertexAndWeight ( set , wsum , false ) ; }
Merges vertex t into vertex s, summing the weights as required.
Merges vertex t into vertex s summing the weights as required .
//construct the new combinedvertex //add edges and weights to the combined vertex //remove original vertices