Changeset 22 for src/main/java
- Timestamp:
- Oct 5, 2010, 5:14:37 PM (14 years ago)
- Location:
- src/main/java/weka/clusterers
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/weka/clusterers/MetisMQIClusterer.java
r14 r22 36 36 */ 37 37 private Map<Node, Integer> nodeMap = null; 38 39 /** 40 * True if a random bisection must be used. 41 */ 42 private boolean randomBisection = false; 38 43 39 44 /** … … 48 53 g.loadFromInstance(data); 49 54 Set<Set<Node>> clusters = GraphAlgorithms.metisMqi(g, numberOfClusters, 50 sizeFinerGraph );55 sizeFinerGraph, randomBisection); 51 56 setNumClusters(clusters.size()); 52 57 int i = 0; … … 118 123 setSizeFinerGraph(Integer.parseInt(optionString)); 119 124 } 125 optionString = Utils.getOption('R', options); 126 setRandomBisection(Boolean.parseBoolean(optionString)); 127 } 128 129 private void setRandomBisection(boolean b) { 130 this.randomBisection = b; 120 131 } 121 132 … … 134 145 result.add("-S"); 135 146 result.add("" + getSizeFinerGraph()); 147 result.add("-R"); 136 148 return (String[]) result.toArray(new String[result.size()]); 137 149 } -
src/main/java/weka/clusterers/forMetisMQI/GraphAlgorithms.java
r21 r22 80 80 * @param sizeFinerGraph 81 81 */ 82 static public Set<Set<Node>> metisMqi(UndirectedGraph g, int numberOfCluster, int sizeFinerGraph ) {82 static public Set<Set<Node>> metisMqi(UndirectedGraph g, int numberOfCluster, int sizeFinerGraph, boolean randomBisection) { 83 83 System.out.println("Vertex count: " + g.getVertexCount()); 84 84 System.out.println("Edges count: " + g.getEdgeCount()); … … 95 95 // Util.viewGraph(g); 96 96 for (int i = 0; i < numberOfCluster; i++) { 97 Bisection partition = metis(g,sizeFinerGraph); 98 // Bisection partition = new Bisection(g); 97 Bisection bisection = null; 98 if(!randomBisection) 99 bisection = metis(g,sizeFinerGraph); 100 else 101 bisection = new Bisection(g); 99 102 System.out.print("Partizione iniziale: "); 100 System.out.print("V1: " + partition.getSubgraph().getVertexCount());101 System.out.print(" V2: " + partition.getComplement().getVertexCount());102 System.out.println(" EC: " + partition.edgeCut() * 0.5);103 System.out.print("V1: " + bisection.getSubgraph().getVertexCount()); 104 System.out.print(" V2: " + bisection.getComplement().getVertexCount()); 105 System.out.println(" EC: " + bisection.edgeCut() * 0.5); 103 106 System.out.println("Conductance: " + 104 ((double) partition.edgeCut() / 2) / Math.min(partition.getSubgraph().totalDegree(),partition.getComplement().totalDegree()));105 Set<Node> cluster = MQI.mqi( partition,true);107 ((double)bisection.edgeCut() / 2) / Math.min(bisection.getSubgraph().totalDegree(),bisection.getComplement().totalDegree())); 108 Set<Node> cluster = MQI.mqi(bisection,true); 106 109 107 110 UndirectedGraph clusterGraph = new Subgraph(gclone,cluster).createInducedSubgraph(); … … 113 116 System.out.println("Conductance: " + newConductance); 114 117 115 116 if(newConductance < 1) { 117 System.out.println("CLUSTER "+ i + ": V=" + clusterGraph.getVertexCount() + ", E=" + clusterGraph.getEdgeCount()+"."); 118 clusters.add(cluster); 119 } 118 System.out.println("CLUSTER "+ i + ": V=" + clusterGraph.getVertexCount() + ", E=" + clusterGraph.getEdgeCount()+"."); 119 clusters.add(cluster); 120 120 121 121 System.out.println(); -
src/main/java/weka/clusterers/forMetisMQI/MQI.java
r21 r22 82 82 static private DirectedGraph<Node, Edge> prepareDirectedGraph( 83 83 Bisection bisection, Node source, Node sink, boolean forConductance) { 84 Subgraph A= bisection.getLargerSubgraph();85 Subgraph B= bisection.getSmallerSubgraph();84 Subgraph B = bisection.getLargerSubgraph(); 85 Subgraph A = bisection.getSmallerSubgraph(); 86 86 int a = 0; 87 87 if (!forConductance) 88 88 a = A.getVertexCount(); 89 89 else { 90 a = Math.min(B.totalDegree(),A.totalDegree()); 90 // a = Math.min(B.totalDegree(),A.totalDegree()); 91 a = A.totalDegree(); 91 92 } 92 93 int c = bisection.edgeCut() / 2; … … 140 141 Node u = nodes.next(); 141 142 if(forConductance) 142 //FIXME: CONTROLLAMI143 143 g.addEdge(new Edge(Integer.toString(id), 1, c * bisection.getGraph().degree(u)), u, sink); 144 144 else … … 161 161 boolean finished = false; 162 162 Bisection bisection = partition; 163 Set<Node> cluster = new HashSet<Node>(partition.get LargerSubgraph()163 Set<Node> cluster = new HashSet<Node>(partition.getSmallerSubgraph() 164 164 .createInducedSubgraph().getVertices()); 165 // System.out.println("IMPROVING SUBGRAPH: " + cluster); 165 166 int maxFlowThreshold = Integer.MAX_VALUE; 166 167 while (!finished) { … … 192 193 * bisection.edgeCut() / 2; 193 194 else { 194 maxFlowThreshold = Math.min(bisection.getLargerSubgraph().totalDegree(), bisection.getSmallerSubgraph().totalDegree()); 195 // maxFlowThreshold = Math.min(bisection.getLargerSubgraph().totalDegree(), bisection.getSmallerSubgraph().totalDegree()); 196 maxFlowThreshold = bisection.getSmallerSubgraph().totalDegree(); 195 197 maxFlowThreshold = maxFlowThreshold 196 198 * (bisection.edgeCut() / 2); 197 199 } 198 200 alg.evaluate(); 199 Util.viewFlowGraph(directedGraph, edgeFlowMap);201 // Util.viewFlowGraph(directedGraph, edgeFlowMap); 200 202 System.out.println("MAX FLOW: " + alg.getMaxFlow() + " THRESHOLD: " 201 203 + maxFlowThreshold); … … 207 209 bisection = new Bisection(new Subgraph( 208 210 bisection.getGraph(), cluster)); 211 // System.out.println("REFINED BISECTION: " + bisection.toString()); 209 212 } else 210 213 finished = true;
Note: See TracChangeset
for help on using the changeset viewer.