- Timestamp:
- Sep 17, 2010, 1:09:06 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/weka/clusterers/forMetisMQI/GraphAlgorithms.java
r12 r14 5 5 import java.util.Stack; 6 6 7 import weka.clusterers.forMetisMQI.coarse.Coarse;8 import weka.clusterers.forMetisMQI.coarse.CoarserGraphElement;9 7 import weka.clusterers.forMetisMQI.graph.Bisection; 10 8 import weka.clusterers.forMetisMQI.graph.Node; 11 9 import weka.clusterers.forMetisMQI.graph.UndirectedGraph; 10 import weka.clusterers.forMetisMQI.util.CoarserGraphElement; 11 import weka.clusterers.forMetisMQI.util.Util; 12 12 13 13 public class GraphAlgorithms { 14 14 15 public Bisection KL(UndirectedGraph g) { 15 16 /** 17 * Given an undirected graph, performs the Kernighan-Li algorithm to find a bisection and 18 * then returns it. 19 * @param g 20 * @return 21 */ 22 static public Bisection KL(UndirectedGraph g) { 16 23 Bisection partition = new Bisection(g); 17 24 Bisection result = partition; … … 28 35 return result; 29 36 } 37 38 static public Bisection metis(UndirectedGraph g, int sizeFinerGraph) { 39 Coarse.setFinerSize(sizeFinerGraph); 40 Stack<CoarserGraphElement> stack = Coarse.coarse(g); 41 Bisection partition = null; 42 if (stack.size() > 0) { 43 partition = KL(stack.peek().getContracted()); 44 partition = Uncoarse.uncoarse(stack, partition); 45 } 46 return partition; 47 } 30 48 31 public void METIS(UndirectedGraph g) { 32 // MQI.viewGraph(g); 49 /** 50 * Given an UndirectedGraph, runs metis+mqi for <code>numberOfCluster</code> times and 51 * returns a set of clusters. With the third parameter you can control the maximum size of the finer 52 * graph during the coarsening phase. 53 * @param g 54 * @param numberOfCluster 55 * @param sizeFinerGraph 56 */ 57 static public Set<Set<Node>> metisMqi(UndirectedGraph g, int numberOfCluster, int sizeFinerGraph) { 33 58 Set<Set<Node>> clusters = new HashSet<Set<Node>>(); 34 for (int i = 0; i < 8; i++) { 35 Coarse.setFinerSize(8); 36 Stack<CoarserGraphElement> stack = Coarse.coarse(g); 37 Bisection partition = null; 38 if (stack.size() > 0) { 39 partition = KL(stack.peek().getContracted()); 40 // System.out.println(partition.toString()); 41 partition = new Uncoarse().uncoarse(stack, partition); 42 // System.out.println(partition.toString()); 43 Set<Node> cluster = MQI.mqi(partition); 44 clusters.add(cluster); 45 // Set<Set<Node>> foundCluster = new HashSet<Set<Node>>(); 46 // foundCluster.add(cluster); 47 // MQI.viewClusters(g, foundCluster); 48 } 59 for (int i = 0; i < numberOfCluster; i++) { 60 Bisection partition = metis(g,sizeFinerGraph); 61 Set<Node> cluster = MQI.mqi(partition); 62 clusters.add(cluster); 49 63 } 50 MQI.viewClusters(g, clusters);64 return clusters; 51 65 } 52 66
Note: See TracChangeset
for help on using the changeset viewer.