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

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

Un po' di refactoring e implementazione dell'algoritmo di raffinamento.

File size: 1.4 KB
Line 
1package weka.clusterers.forMetisMQI;
2
3import java.util.Iterator;
4import java.util.Stack;
5
6import weka.clusterers.forMetisMQI.coarse.CoarserGraphElement;
7import weka.clusterers.forMetisMQI.graph.Bisection;
8import weka.clusterers.forMetisMQI.graph.Node;
9import weka.clusterers.forMetisMQI.graph.Subgraph;
10import weka.clusterers.forMetisMQI.graph.UndirectedGraph;
11
12public class Uncoarse {
13       
14        private 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        public 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        public Bisection uncoarse(Stack<CoarserGraphElement> stack, Bisection partition) {
39                while(stack.size() > 0) {
40                        CoarserGraphElement element = stack.pop();
41                        partition = uncoarseOneStep(partition,element);
42                }
43                return partition;
44        }
45       
46        public Uncoarse() {
47        }
48
49}
Note: See TracBrowser for help on using the repository browser.