use of org.jgrapht.graph.DefaultWeightedEdge in project cogcomp-nlp by CogComp.
the class ShortestPathInference method runInference.
public List<Node> runInference() {
List<DefaultWeightedEdge> path;
if (negativeWeights) {
path = BellmanFordShortestPath.findPathBetween(graph, source, target);
} else {
path = DijkstraShortestPath.findPathBetween(graph, source, target);
}
shortestPath = new ArrayList<Node>();
if (path == null) {
System.out.println(graph);
}
DefaultWeightedEdge firstEdge = path.get(0);
assert firstEdge != null;
shortestPath.add(graph.getEdgeSource(firstEdge));
for (DefaultWeightedEdge e : path) {
shortestPath.add(graph.getEdgeTarget(e));
}
return shortestPath;
}
use of org.jgrapht.graph.DefaultWeightedEdge in project cogcomp-nlp by CogComp.
the class ShortestPathInference method updateEdgeWeight.
public void updateEdgeWeight(Node s, Node t, double score) {
DefaultWeightedEdge e = graph.getEdge(s, t);
double sc = getNodeScore(t) + score;
graph.setEdgeWeight(e, sc);
if (sc < 0)
negativeWeights = true;
}
use of org.jgrapht.graph.DefaultWeightedEdge 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;
}
use of org.jgrapht.graph.DefaultWeightedEdge in project cogcomp-nlp by CogComp.
the class MaxFlowInference method addEdge.
public void addEdge(Node s, Node t, double score) {
DefaultWeightedEdge e = graph.addEdge(s, t);
double sc = getNodeScore(t) + score;
graph.setEdgeWeight(e, sc);
}
use of org.jgrapht.graph.DefaultWeightedEdge in project cogcomp-nlp by CogComp.
the class MaxFlowInference method updateEdgeWeight.
public void updateEdgeWeight(Node s, Node t, double score) {
DefaultWeightedEdge e = graph.getEdge(s, t);
double sc = getNodeScore(t) + score;
graph.setEdgeWeight(e, sc);
}
Aggregations