-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAula18Clique.java
More file actions
71 lines (60 loc) · 2.31 KB
/
Copy pathAula18Clique.java
File metadata and controls
71 lines (60 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Teoria dos Grafos - UFCG
package examples;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.jgrapht.Graph;
import org.jgrapht.alg.clique.DegeneracyBronKerboschCliqueFinder;
import org.jgrapht.alg.clique.PivotBronKerboschCliqueFinder;
import org.jgrapht.graph.SimpleGraph;
public class Aula18Clique {
public static void main(String[] args) {
Graph<DefaultVertex, RelationshipEdge> graphgml = new SimpleGraph<>(RelationshipEdge.class);
MyJGraphTUtil.importGraphGML(graphgml,"./src/main/java/graphs/lesmis.gml");
///////////////
DegeneracyBronKerboschCliqueFinder <DefaultVertex,RelationshipEdge> cf2 =
new DegeneracyBronKerboschCliqueFinder <> (graphgml);
Iterator <Set <DefaultVertex>> it1 = cf2.iterator();
List <Set <DefaultVertex>> t = new ArrayList <>();
while (it1.hasNext()) {
t.add(it1.next());
}
// SORT TO PRINT
Collections.sort( t, new Comparator<Set<DefaultVertex>>()
{
public int compare( Set <DefaultVertex> o1, Set <DefaultVertex> o2 )
{
return (new Integer(o2.size())).compareTo( (new Integer(o1.size())) );
}
} );
System.out.print("DegenearyBronKerboschCliqueFinder cliques: \n");
Iterator <Set<DefaultVertex>> it2 = t.iterator();
while (it2.hasNext()) {
System.out.println(it2.next());
}
///////////////
PivotBronKerboschCliqueFinder <DefaultVertex,RelationshipEdge> cf3 =
new PivotBronKerboschCliqueFinder <> (graphgml);
Iterator <Set <DefaultVertex>> it3 = cf3.iterator();
List <Set <DefaultVertex>> t2 = new ArrayList <>();
while (it3.hasNext()) {
t2.add(it3.next());
}
// SORT TO PRINT
Collections.sort( t2, new Comparator<Set<DefaultVertex>>()
{
public int compare( Set <DefaultVertex> o1, Set <DefaultVertex> o2 )
{
return (new Integer(o2.size())).compareTo( (new Integer(o1.size())) );
}
} );
System.out.print("\n\nPivotBronKerboschCliqueFinder cliques: \n");
Iterator <Set<DefaultVertex>> it4 = t2.iterator();
while (it4.hasNext()) {
System.out.println(it4.next());
}
}
}