Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
shared-memory-maximal-clique
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
adas
shared-memory-maximal-clique
Commits
60c41092
Commit
60c41092
authored
6 years ago
by
beginner1010
Browse files
Options
Downloads
Patches
Plain Diff
Graph.java is added
parent
9d983e0b
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/Algorithm/Graph.java
+54
-28
54 additions, 28 deletions
src/main/java/Algorithm/Graph.java
with
54 additions
and
28 deletions
src/main/java/Algorithm/Graph.java
+
54
−
28
View file @
60c41092
...
...
@@ -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
)
1
e9
;
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
.)
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment