Search in sources :

Example 11 with DefaultWeightedEdge

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;
}
Also used : DefaultWeightedEdge(org.jgrapht.graph.DefaultWeightedEdge)

Example 12 with DefaultWeightedEdge

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;
}
Also used : DefaultWeightedEdge(org.jgrapht.graph.DefaultWeightedEdge)

Example 13 with DefaultWeightedEdge

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;
}
Also used : DefaultWeightedEdge(org.jgrapht.graph.DefaultWeightedEdge) EdmondsKarpMaximumFlow(org.jgrapht.alg.EdmondsKarpMaximumFlow) HashSet(java.util.HashSet)

Example 14 with DefaultWeightedEdge

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);
}
Also used : DefaultWeightedEdge(org.jgrapht.graph.DefaultWeightedEdge)

Example 15 with DefaultWeightedEdge

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);
}
Also used : DefaultWeightedEdge(org.jgrapht.graph.DefaultWeightedEdge)

Aggregations

DefaultWeightedEdge (org.jgrapht.graph.DefaultWeightedEdge)18 ArrayList (java.util.ArrayList)6 HashSet (java.util.HashSet)6 IOException (java.io.IOException)4 List (java.util.List)3 TreeRangeSet (com.google.common.collect.TreeRangeSet)2 AlignmentSegment (cz1.ngs.model.AlignmentSegment)2 Blast6Segment (cz1.ngs.model.Blast6Segment)2 Sequence (cz1.ngs.model.Sequence)2 BufferedReader (java.io.BufferedReader)2 BufferedWriter (java.io.BufferedWriter)2 File (java.io.File)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 SDNControllerClient (nl.uva.cs.lobcder.optimization.SDNControllerClient)2 BidiMap (org.apache.commons.collections4.BidiMap)2 DualHashBidiMap (org.apache.commons.collections4.bidimap.DualHashBidiMap)2 BFSShortestPath (cz1.ngs.model.BFSShortestPath)1 TraceableVertex (cz1.ngs.model.TraceableVertex)1 CigarElement (htsjdk.samtools.CigarElement)1