| 1 | package weka.clusterers.forMetisMQI; |
|---|
| 2 | |
|---|
| 3 | import java.util.Iterator; |
|---|
| 4 | import java.util.Stack; |
|---|
| 5 | |
|---|
| 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.Subgraph; |
|---|
| 10 | import weka.clusterers.forMetisMQI.graph.UndirectedGraph; |
|---|
| 11 | |
|---|
| 12 | public 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 | } |
|---|