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;
}
Aggregations