1 | package weka.clusterers.forMetisMQI; |
---|
2 | |
---|
3 | import java.util.Iterator; |
---|
4 | import java.util.Stack; |
---|
5 | |
---|
6 | import weka.clusterers.forMetisMQI.graph.Bisection; |
---|
7 | import weka.clusterers.forMetisMQI.graph.Node; |
---|
8 | import weka.clusterers.forMetisMQI.graph.Subgraph; |
---|
9 | import weka.clusterers.forMetisMQI.graph.UndirectedGraph; |
---|
10 | import weka.clusterers.forMetisMQI.util.CoarserGraphElement; |
---|
11 | |
---|
12 | public class Uncoarse { |
---|
13 | |
---|
14 | private static boolean projectedBelongs(Node u, Bisection partition, CoarserGraphElement cge) { |
---|
15 | Subgraph s = partition.getSubgraph(); |
---|
16 | Node mappedNode = cge.getMap().get(u); |
---|
17 | return s.contains(mappedNode); |
---|
18 | } |
---|
19 | |
---|
20 | /** |
---|
21 | * Given the projected graph and the partition of the coarser graph, it builds |
---|
22 | * the projected partition. |
---|
23 | * @param partition |
---|
24 | * @param cge |
---|
25 | */ |
---|
26 | private static Bisection uncoarseOneStep(Bisection partition, CoarserGraphElement cge) { |
---|
27 | UndirectedGraph projected = cge.getProjected(); |
---|
28 | Subgraph part = new Subgraph(projected); |
---|
29 | Iterator<Node> projectedIterator = projected.getVertices().iterator(); |
---|
30 | while(projectedIterator.hasNext()) { |
---|
31 | Node u = projectedIterator.next(); |
---|
32 | if(projectedBelongs(u,partition,cge)) |
---|
33 | part.addVertex(u); |
---|
34 | } |
---|
35 | return new Bisection(part); |
---|
36 | } |
---|
37 | |
---|
38 | /** |
---|
39 | * Given a bisection of the finer graph and the stack of graphs which yielded the finer graph, |
---|
40 | * it returns the bisection projected into the coarser graph. |
---|
41 | * @param stack |
---|
42 | * @param partition |
---|
43 | * @return |
---|
44 | */ |
---|
45 | public static Bisection uncoarse(Stack<CoarserGraphElement> stack, Bisection partition) { |
---|
46 | while(stack.size() > 0) { |
---|
47 | CoarserGraphElement element = stack.pop(); |
---|
48 | partition = uncoarseOneStep(partition,element); |
---|
49 | partition = GraphAlgorithms.KLRefinement(partition); |
---|
50 | } |
---|
51 | return partition; |
---|
52 | } |
---|
53 | } |
---|