Search in sources :

Example 1 with EdmondsKarpMaximumFlow

use of org.jgrapht.alg.EdmondsKarpMaximumFlow in project cogcomp-nlp by CogComp.

the class MaxFlowInference method runInference.

@Override
public Set<Node> runInference() throws Exception {
    EdmondsKarpMaximumFlow<Node, DefaultWeightedEdge> algo = new EdmondsKarpMaximumFlow<Node, DefaultWeightedEdge>(graph);
    algo.calculateMaximumFlow(source, sink);
    Map<DefaultWeightedEdge, Double> flow = algo.getMaximumFlow();
    Set<Node> nodes = new HashSet<Node>();
    for (Entry<DefaultWeightedEdge, Double> entry : flow.entrySet()) {
        if (entry.getValue() > 0) {
            DefaultWeightedEdge key = entry.getKey();
            nodes.add(graph.getEdgeSource(key));
            nodes.add(graph.getEdgeTarget(key));
        }
    }
    return nodes;
}
Also used : DefaultWeightedEdge(org.jgrapht.graph.DefaultWeightedEdge) EdmondsKarpMaximumFlow(org.jgrapht.alg.EdmondsKarpMaximumFlow) HashSet(java.util.HashSet)

Aggregations

HashSet (java.util.HashSet)1 EdmondsKarpMaximumFlow (org.jgrapht.alg.EdmondsKarpMaximumFlow)1 DefaultWeightedEdge (org.jgrapht.graph.DefaultWeightedEdge)1