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