source: src/main/java/weka/clusterers/forMetisMQI/Uncoarse.java @ 18

Last change on this file since 18 was 18, checked in by gnappo, 14 years ago

Implementato raffinamento KL in metis; implementata ottimizzazione di mqi sulla conduttanza.

File size: 1.7 KB
Line 
1package weka.clusterers.forMetisMQI;
2
3import java.util.Iterator;
4import java.util.Stack;
5
6import weka.clusterers.forMetisMQI.graph.Bisection;
7import weka.clusterers.forMetisMQI.graph.Node;
8import weka.clusterers.forMetisMQI.graph.Subgraph;
9import weka.clusterers.forMetisMQI.graph.UndirectedGraph;
10import weka.clusterers.forMetisMQI.util.CoarserGraphElement;
11
12public 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}
Note: See TracBrowser for help on using the repository browser.