Search in sources :

Example 1 with SimpleDirectedWeightedGraph

use of org.jgrapht.graph.SimpleDirectedWeightedGraph in project grafikon by jub77.

the class RegionGraphDelegate method getRegionGraph.

Graph<Node, DirectNodeConnection> getRegionGraph() {
    SimpleDirectedWeightedGraph<Node, DirectNodeConnection> graph = new SimpleDirectedWeightedGraph<>(DirectNodeConnection.class);
    net.getNodes().stream().filter(Node::isCenterOfRegions).forEach(graph::addVertex);
    for (Node node : graph.vertexSet()) {
        getRegionConnections(node).forEach(connection -> {
            Node n1 = connection.getFrom();
            Node n2 = connection.getTo().getNode();
            DirectNodeConnectionImpl edge = (DirectNodeConnectionImpl) graph.getEdge(n1, n2);
            if (edge == null) {
                edge = new DirectNodeConnectionImpl(connection.getPath());
                graph.addEdge(n1, n2, edge);
            } else {
                edge.connections.add(connection.getPath());
            }
        });
    }
    return graph;
}
Also used : SimpleDirectedWeightedGraph(org.jgrapht.graph.SimpleDirectedWeightedGraph) Node(net.parostroj.timetable.model.Node)

Example 2 with SimpleDirectedWeightedGraph

use of org.jgrapht.graph.SimpleDirectedWeightedGraph in project BTW by TechnionYearlyProject.

the class BTWGraphInfo method calculateMinimumGraph.

private static Graph<Road, DefaultWeightedEdge> calculateMinimumGraph(BTWDataBase db) {
    SimpleDirectedWeightedGraph<Road, DefaultWeightedEdge> minimunGraph = new SimpleDirectedWeightedGraph<>(DefaultWeightedEdge.class);
    db.getAllTrafficLights().forEach(trafficLight -> {
        Road src = trafficLight.getSourceRoad();
        Road dst = trafficLight.getDestinationRoad();
        // System.out.println(src.getRoadName());
        // System.out.println(dst.getRoadName());
        minimunGraph.addVertex(src);
        minimunGraph.addVertex(dst);
        DefaultWeightedEdge edge = minimunGraph.addEdge(src, dst);
        minimunGraph.setEdgeWeight(edge, trafficLight.getMinimumWeight().seconds() + src.getMinimumWeight().seconds());
    });
    return minimunGraph;
}
Also used : DefaultWeightedEdge(org.jgrapht.graph.DefaultWeightedEdge) Road(il.ac.technion.cs.yp.btw.classes.Road) SimpleDirectedWeightedGraph(org.jgrapht.graph.SimpleDirectedWeightedGraph)

Aggregations

SimpleDirectedWeightedGraph (org.jgrapht.graph.SimpleDirectedWeightedGraph)2 Road (il.ac.technion.cs.yp.btw.classes.Road)1 Node (net.parostroj.timetable.model.Node)1 DefaultWeightedEdge (org.jgrapht.graph.DefaultWeightedEdge)1