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