1 | package weka.clusterers.forMetisMQI; |
---|
2 | |
---|
3 | import java.util.HashSet; |
---|
4 | import java.util.Set; |
---|
5 | import java.util.Stack; |
---|
6 | |
---|
7 | import weka.clusterers.forMetisMQI.coarse.Coarse; |
---|
8 | import weka.clusterers.forMetisMQI.coarse.CoarserGraphElement; |
---|
9 | import weka.clusterers.forMetisMQI.graph.Bisection; |
---|
10 | import weka.clusterers.forMetisMQI.graph.Node; |
---|
11 | import weka.clusterers.forMetisMQI.graph.UndirectedGraph; |
---|
12 | |
---|
13 | public class GraphAlgorithms { |
---|
14 | |
---|
15 | public Bisection KL(UndirectedGraph g) { |
---|
16 | Bisection partition = new Bisection(g); |
---|
17 | Bisection result = partition; |
---|
18 | int bestEdgeCut = Integer.MAX_VALUE; |
---|
19 | Node u = partition.getCandidate(); |
---|
20 | while (u != null) { |
---|
21 | partition.swap(u); |
---|
22 | if (partition.edgeCut() <= bestEdgeCut) { |
---|
23 | bestEdgeCut = partition.edgeCut(); |
---|
24 | result = partition.copy(); |
---|
25 | } |
---|
26 | u = partition.getCandidate(); |
---|
27 | } |
---|
28 | return result; |
---|
29 | } |
---|
30 | |
---|
31 | public void METIS(UndirectedGraph g) { |
---|
32 | // MQI.viewGraph(g); |
---|
33 | Set<Set<Node>> clusters = new HashSet<Set<Node>>(); |
---|
34 | for (int i = 0; i < 8; i++) { |
---|
35 | Coarse.setFinerSize(8); |
---|
36 | Stack<CoarserGraphElement> stack = Coarse.coarse(g); |
---|
37 | Bisection partition = null; |
---|
38 | if (stack.size() > 0) { |
---|
39 | partition = KL(stack.peek().getContracted()); |
---|
40 | // System.out.println(partition.toString()); |
---|
41 | partition = new Uncoarse().uncoarse(stack, partition); |
---|
42 | // System.out.println(partition.toString()); |
---|
43 | Set<Node> cluster = MQI.mqi(partition); |
---|
44 | clusters.add(cluster); |
---|
45 | // Set<Set<Node>> foundCluster = new HashSet<Set<Node>>(); |
---|
46 | // foundCluster.add(cluster); |
---|
47 | // MQI.viewClusters(g, foundCluster); |
---|
48 | } |
---|
49 | } |
---|
50 | MQI.viewClusters(g, clusters); |
---|
51 | } |
---|
52 | |
---|
53 | } |
---|