Search in sources :

Example 1 with DijkstraShortestPath

use of org.jgrapht.alg.DijkstraShortestPath in project alliance by codice.

the class DAGConverter method printDAG.

public static void printDAG(DAG dag) {
    if (dag.nodes != null && dag.edges != null) {
        Map<Integer, Node> nodeMap = ResultDAGConverter.createNodeMap(dag.nodes);
        DirectedAcyclicGraph<Node, Edge> graph = getNodeEdgeDirectedAcyclicGraph(dag, nodeMap);
        DepthFirstIterator<Node, Edge> depthFirstIterator = new DepthFirstIterator<>(graph);
        Node rootNode = null;
        while (depthFirstIterator.hasNext()) {
            depthFirstIterator.setCrossComponentTraversal(false);
            Node node = depthFirstIterator.next();
            if (rootNode == null) {
                rootNode = node;
            }
            DijkstraShortestPath<Node, Edge> path = new DijkstraShortestPath<>(graph, rootNode, node);
            printNode(node, (int) Math.round(path.getPathLength()));
        }
    }
}
Also used : DepthFirstIterator(org.jgrapht.traverse.DepthFirstIterator) Node(org.codice.alliance.nsili.common.UCO.Node) Edge(org.codice.alliance.nsili.common.UCO.Edge) DijkstraShortestPath(org.jgrapht.alg.DijkstraShortestPath)

Aggregations

Edge (org.codice.alliance.nsili.common.UCO.Edge)1 Node (org.codice.alliance.nsili.common.UCO.Node)1 DijkstraShortestPath (org.jgrapht.alg.DijkstraShortestPath)1 DepthFirstIterator (org.jgrapht.traverse.DepthFirstIterator)1