Changeset 18 for src/main/java/weka/clusterers/forMetisMQI/MQI.java
- Timestamp:
- Sep 29, 2010, 9:13:19 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/weka/clusterers/forMetisMQI/MQI.java
r17 r18 16 16 import weka.clusterers.forMetisMQI.graph.Node; 17 17 import weka.clusterers.forMetisMQI.graph.Subgraph; 18 import weka.clusterers.forMetisMQI.graph.UndirectedGraph;19 18 import weka.clusterers.forMetisMQI.util.Util; 20 19 import edu.uci.ics.jung.algorithms.flows.EdmondsKarpMaxFlow; … … 27 26 28 27 static private Set<Node> DFSReversed(Node currentNode, 29 DirectedGraph<Node, Edge> g, Map<Edge, Number> edgeFlowMap, Set<Node> marked) { 28 DirectedGraph<Node, Edge> g, Map<Edge, Number> edgeFlowMap, 29 Set<Node> marked) { 30 30 Collection<Edge> inEdges = g.getInEdges(currentNode); 31 31 Set<Node> result = new HashSet<Node>(); … … 47 47 return result; 48 48 } 49 50 51 49 52 50 static private Set<Node> BFSReversed(Node sink, … … 83 81 84 82 static private DirectedGraph<Node, Edge> prepareDirectedGraph( 85 Bisection partition, Node source, Node sink ) {83 Bisection partition, Node source, Node sink, boolean forConductance) { 86 84 Subgraph A = null; 87 85 Subgraph B = null; … … 94 92 B = partition.getSubgraph(); 95 93 } 96 int a = A.getVertexCount(); 94 int a = 0; 95 if (!forConductance) 96 a = A.getVertexCount(); 97 else { 98 Iterator<Node> aIterator = A.iterator(); 99 while(aIterator.hasNext()) { 100 a += partition.getGraph().degree(aIterator.next()); 101 } 102 } 97 103 int c = partition.edgeCut() / 2; 98 104 … … 120 126 g.addVertex(sink); 121 127 122 123 // build the edges from source to each node of A which previously wasconnected124 // with a node of B.128 // build the edges from source to each node of A which previously was 129 // connected 130 // with a node of B. 125 131 nodes = B.iterator(); 126 132 while (nodes.hasNext()) { … … 131 137 if (A.contains(v)) { 132 138 Edge e = g.findEdge(source, v); 133 if (e != null) {139 if (e != null) { 134 140 e.setCapacity(e.getCapacity() + a); 135 141 } else { 136 g.addEdge(new Edge(Integer.toString(id), 1, a), source, v); 142 g.addEdge(new Edge(Integer.toString(id), 1, a), source, 143 v); 137 144 id++; 138 145 } … … 144 151 while (nodes.hasNext()) { 145 152 Node u = nodes.next(); 146 g.addEdge(new Edge(Integer.toString(id), 1, c), u, sink); 153 if(forConductance) 154 //FIXME: CONTROLLAMI 155 g.addEdge(new Edge(Integer.toString(id), 1, c * partition.getGraph().degree(u)), u, sink); 156 else 157 g.addEdge(new Edge(Integer.toString(id), 1, c), u, sink); 147 158 id++; 148 159 } … … 158 169 * @return 159 170 */ 160 static public Set<Node> mqi(Bisection partition ) {171 static public Set<Node> mqi(Bisection partition, boolean forConductance) { 161 172 // System.out.println("INITIAL BISECTION: " + partition.toString()); 162 173 boolean finished = false; 163 174 Bisection bisection = partition; 164 Set<Node> cluster = new HashSet<Node>(partition 165 .getSmallerNotEmptySubgraph().createInducedSubgraph() 166 .getVertices()); 175 Set<Node> cluster = new HashSet<Node>(partition.getSmallerNotEmptySubgraph() 176 .createInducedSubgraph().getVertices()); 167 177 int maxFlowThreshold = Integer.MAX_VALUE; 168 178 while (!finished) { … … 170 180 Node sink = new Node("$$$$T"); 171 181 DirectedGraph<Node, Edge> directedGraph = prepareDirectedGraph( 172 bisection, source, sink );182 bisection, source, sink, true); 173 183 Transformer<Edge, Number> capTransformer = new Transformer<Edge, Number>() { 174 184 public Double transform(Edge e) { … … 189 199 edgeFactory); 190 200 191 maxFlowThreshold = bisection.getSmallerNotEmptySubgraph() 192 .getVertexCount() 193 * bisection.edgeCut() / 2; 201 if (!forConductance) 202 maxFlowThreshold = bisection.getSmallerNotEmptySubgraph() 203 .getVertexCount() 204 * bisection.edgeCut() / 2; 205 else { 206 Iterator<Node> aIterator = bisection.getSmallerNotEmptySubgraph().iterator(); 207 maxFlowThreshold = 0; 208 while(aIterator.hasNext()) 209 maxFlowThreshold += partition.getGraph().degree(aIterator.next()); 210 maxFlowThreshold = maxFlowThreshold 211 * (bisection.edgeCut() / 2); 212 } 194 213 alg.evaluate(); 195 // Util.viewFlowGraph(directedGraph, edgeFlowMap);214 // Util.viewFlowGraph(directedGraph, edgeFlowMap); 196 215 // System.out.println("MAX FLOW: " + alg.getMaxFlow() + " THRESHOLD: " 197 216 // + maxFlowThreshold); 198 217 if (alg.getMaxFlow() < maxFlowThreshold) { 199 cluster = DFSReversed(sink, directedGraph, edgeFlowMap, new HashSet<Node>()); 200 cluster.remove(sink); 201 bisection = new Bisection(new Subgraph(bisection.getGraph(), 202 cluster)); 203 // System.out.println("NEW BISECTION: " + bisection.toString()); 218 Set<Node> dfsResult = DFSReversed(sink, directedGraph, 219 edgeFlowMap, new HashSet<Node>()); 220 dfsResult.remove(sink); 221 // if (dfsResult.size() > 0) { 222 cluster = dfsResult; 223 bisection = new Bisection(new Subgraph( 224 bisection.getGraph(), cluster)); 225 // System.out 226 // .println("NEW BISECTION: " + bisection.toString()); 227 // } else 228 // finished = true; 204 229 } else 205 230 finished = true;
Note: See TracChangeset
for help on using the changeset viewer.