Skip to content
Snippets Groups Projects
Commit 60c41092 authored by beginner1010's avatar beginner1010
Browse files

Graph.java is added

parent 9d983e0b
No related branches found
No related tags found
No related merge requests found
......@@ -19,6 +19,8 @@ public class Graph {
private Vscore[] S;
private int degeneracy; // contains degeneracy value
long [] tri ;
int [] degen ;
HashMap <String, Integer> vertexIndex ;
int numberOfVertices;
......@@ -26,11 +28,9 @@ public class Graph {
private Map<Integer, Integer> degenscores; // (key, value) pair; key = vertex, value = degeneracy score
private Map<Integer, Integer> trianglecount; // (key, value) pair; key = vertex, value = triangle count
ArrayList<Integer> degreeOrder;
ArrayList<Integer> triangleOrder;
ArrayList<Integer> degenOrder;
private static long ttime;
public Graph() {
......@@ -122,8 +122,6 @@ public class Graph {
if (u == v) return ;
if (this.AdjList.get(v).contains(u) == false) {
long t1 = System.currentTimeMillis();
if (!trianglecount.keySet().contains(u))
......@@ -174,11 +172,8 @@ public class Graph {
}
return false;
}
public void removeEdge(int u, int v) {
if (AdjList.get(u) != null) {
if (AdjList.get(u).contains(v)) {
AdjList.get(u).remove(v);
......@@ -298,7 +293,6 @@ public class Graph {
// Adopted this code from
// https://github.com/jgrapht/jgrapht/blob/master/jgrapht-core/src/main/java/org/jgrapht/alg/scoring/Coreness.java
public void computeDegeneracy() {
if (degenscores != null) {
return;
}
......@@ -362,29 +356,44 @@ public class Graph {
Collections.sort(degenOrder, (a,b) -> this.degeneracyOf(a) - this.degeneracyOf(b));
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Graph g = new Graph("C:/Users/apurd/Documents/data/sx_stackoverflow_a2q_edges");
int maxdegree = g.MaxDegree();
System.out.println("max degree of sx_stackoverflow: " + maxdegree);
// g = new Graph("/home/apurba/data/ER-2M-15M-edges");
// maxdegree = g.MaxDegree();
public void triangleCount() {
tri = new long [this.numV()] ;
for (int i = 0 ; i < this.numV() ; i ++) {
triangleCount(i);
}
}
// System.out.println("max degree of 2M-15M: " + maxdegree);
public void triangleCount (int v) {
for (int neighbor : this.AdjList.get(v)) {
for (int neighbor2 : this.AdjList.get(v)) {
if (this.AdjList.get(neighbor).contains(neighbor2))
tri [v] ++ ;
}
}
}
// g.removeEdge(1,2);
// g.removeEdge(2,3);
// System.out.println("After removal of (1,2) and (2,3)");
// g.print();
public void degen () {
degen = new int [this.numV()] ;
TreeSet <Long> set = new TreeSet <Long>() ;
long shift = (long)1e9 ;
for (int i = 0; i < this.numV(); i++) {
degen [i] = this.AdjList.get(i).size();
set.add(degen [i] * shift + i) ;
}
while (!set.isEmpty()) {
long fst = set.iterator().next() ;
set.remove(fst) ;
int id = (int)(fst % shift) ;
for (int neighbor : this.AdjList.get(id)) {
if (degen [neighbor] > degen [id]) {
degen [neighbor] -- ;
set.add(degen [neighbor] * shift + neighbor) ;
}
}
}
}
// new Tomita(g);
}
public void printedges(FileWriter fw) throws Exception {
String[] edges = new String[numE()];
......@@ -424,10 +433,27 @@ public class Graph {
}
public int getId(int v) {
return this.vertexIndex.get(String.valueOf(v));
}
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("java.util.concurrent.ForkJoinPool.common.parallelism", args[1]);
System.out.println("ParMCEDegree : degree based vertex ordering");
System.out.println("Input Graph: " + args[0]);
//System.out.println("Number of threads used: " + args[1]);
Graph G = new Graph(args[0]);
long t1 = System.currentTimeMillis();
G.degen();
System.out.println("Time taken for degenarcy:" + (System.currentTimeMillis() - t1) / 1000.) ;
t1 = System.currentTimeMillis() ;
G.triangleCount();
System.out.println("Time taken for trianle count:" + (System.currentTimeMillis() - t1) / 1000.) ;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment