Skip to content
Snippets Groups Projects
Commit b9ec71b2 authored by kraleva's avatar kraleva
Browse files

add class for calculating the LCC

parent 344ea4ed
No related branches found
No related tags found
1 merge request!26Add LLC
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
<dependency> <dependency>
<groupId>com.google.protobuf</groupId> <groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId> <artifactId>protobuf-java</artifactId>
<version>3.21.12</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.commons</groupId> <groupId>org.apache.commons</groupId>
...@@ -39,11 +39,12 @@ ...@@ -39,11 +39,12 @@
<artifactId>json</artifactId> <artifactId>json</artifactId>
<version>20230227</version> <version>20230227</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>de.fuberlin.navigator</groupId> <groupId>de.fuberlin.navigator</groupId>
<artifactId>proto</artifactId> <artifactId>proto</artifactId>
<version>1.00.003</version> <version>1.00.06</version>
</dependency> </dependency>
</dependencies> </dependencies>
...@@ -79,4 +80,22 @@ ...@@ -79,4 +80,22 @@
<url>https://git.imp.fu-berlin.de/api/v4/projects/8345/packages/maven</url> <url>https://git.imp.fu-berlin.de/api/v4/projects/8345/packages/maven</url>
</repository> </repository>
</repositories> </repositories>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>3.22.2</version>
</dependency>
</dependencies>
</dependencyManagement>
</project> </project>
...@@ -17,24 +17,24 @@ public class App { ...@@ -17,24 +17,24 @@ public class App {
// A small BBox inside Cottbus // A small BBox inside Cottbus
/* /*
float minLat = 51.765120241998865f; * float minLat = 51.765120241998865f;
float minLon = 14.32669617537409f; * float minLon = 14.32669617537409f;
float maxLat = 51.77116774623326f; * float maxLat = 51.77116774623326f;
float maxLon = 14.330334220133722f; * float maxLon = 14.330334220133722f;
*/ */
// smaller BBox inside Cottbus, better for the debug tool // smaller BBox inside Cottbus, better for the debug tool
float minLat = 51.764092326645475f; float minLat = 51.754092326645475f;
float minLon = 14.310615062713623f; float minLon = 14.300615062713623f;
float maxLat = 51.766591637718435f; float maxLat = 51.766591637718435f;
float maxLon = 14.314413070678711f; float maxLon = 14.314413070678711f;
// BBox around Cottbus // BBox around Cottbus
/* /*
float minLat = 51.714692361306376f; * float minLat = 51.714692361306376f;
float minLon = 14.26197052001953f; * float minLon = 14.26197052001953f;
float maxLat = 51.79290380494767f; * float maxLat = 51.79290380494767f;
float maxLon = 14.415779113769531f; * float maxLon = 14.415779113769531f;
*/ */
BoundingBox bbox = new BoundingBox(minLat, minLon, maxLat, maxLon); BoundingBox bbox = new BoundingBox(minLat, minLon, maxLat, maxLon);
......
package map.builder.utilities;
// Code from : https://www.geeksforgeeks.org/strongly-connected-components/
// Java implementation of Kosaraju's algorithm to print all SCCs
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Stack;
// This class represents a directed ConnectedComponentGraph using adjacency list
// representation
class ConnectedComponentGraph {
private int V; // No. of vertices
private LinkedList<Integer> adj[]; // Adjacency List
// Constructor
ConnectedComponentGraph(int v) {
V = v;
adj = new LinkedList[v];
for (int i = 0; i < v; ++i)
adj[i] = new LinkedList<Integer>();
}
// Function to add an edge into the ConnectedComponentGraph
public void addEdge(int v, int w) {
adj[v].add(w);
}
// A recursive function to print DFS starting from v
public void DFSUtil(int v, boolean visited[]) {
// Mark the current node as visited and print it
visited[v] = true;
System.out.print(v + " ");
int n;
// Recur for all the vertices adjacent to this vertex
Iterator<Integer> i = adj[v].iterator();
while (i.hasNext()) {
n = i.next();
if (!visited[n])
DFSUtil(n, visited);
}
}
// Function that returns reverse (or transpose) of this ConnectedComponentGraph
public ConnectedComponentGraph getTranspose() {
ConnectedComponentGraph g = new ConnectedComponentGraph(V);
for (int v = 0; v < V; v++) {
// Recur for all the vertices adjacent to this vertex
Iterator<Integer> i = adj[v].listIterator();
while (i.hasNext())
g.adj[i.next()].add(v);
}
return g;
}
public void fillOrder(int v, boolean visited[], Stack<Integer> stack) {
// Mark the current node as visited and print it
visited[v] = true;
// Recur for all the vertices adjacent to this vertex
Iterator<Integer> i = adj[v].iterator();
while (i.hasNext()) {
int n = i.next();
if (!visited[n])
fillOrder(n, visited, stack);
}
// All vertices reachable from v are processed by now,
// push v to Stack
stack.push(v);
}
// The main function that finds and prints all strongly
// connected components
public void printSCCs() {
Stack<Integer> stack = new Stack<Integer>();
// Mark all the vertices as not visited (For first DFS)
boolean visited[] = new boolean[V];
for (int i = 0; i < V; i++)
visited[i] = false;
// Fill vertices in stack according to their finishing
// times
for (int i = 0; i < V; i++)
if (visited[i] == false)
fillOrder(i, visited, stack);
// Create a reversed ConnectedComponentGraph
ConnectedComponentGraph gr = getTranspose();
// Mark all the vertices as not visited (For second DFS)
for (int i = 0; i < V; i++)
visited[i] = false;
// Now process all vertices in order defined by Stack
while (stack.empty() == false) {
// Pop a vertex from stack
int v = (int) stack.pop();
// Print Strongly connected component of the popped vertex
if (visited[v] == false) {
gr.DFSUtil(v, visited);
System.out.println();
}
}
}
// Driver method
public static void main(String args[]) {
// Create a ConnectedComponentGraph given in the above diagram
ConnectedComponentGraph g = new ConnectedComponentGraph(5);
g.addEdge(1, 0);
g.addEdge(0, 2);
g.addEdge(2, 1);
g.addEdge(0, 3);
g.addEdge(3, 4);
System.out.println("Following are strongly connected components " +
"in given ConnectedComponentGraph ");
g.printSCCs();
}
}
// This code is contributed by Aakash Hasija
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment