Changeset 10 for src/main/java/weka/clusterers/forMetisMQI/Coarse.java
- Timestamp:
- Sep 14, 2010, 5:27:28 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/weka/clusterers/forMetisMQI/Coarse.java
r9 r10 13 13 public class Coarse { 14 14 15 private static boolean debug = true;15 private static boolean debug = false; 16 16 private static PrintStream debugStream = System.err; 17 17 private static int finerSize = 5; … … 98 98 while(it.hasNext()) 99 99 neighbors.add(getMappedNode(map, it.next())); 100 101 // Set<Node> neighbors = new HashSet<Node>();102 // while(it.hasNext()) {103 // Node v = it.next();104 // neighbors.add(getMappedNode(map,v));105 // }106 // it = g.getNeighbors(getMappedNode(match,u)).iterator();107 // while(it.hasNext()) {108 // Node v = it.next();109 // neighbors.add(getMappedNode(map,v));110 // }111 100 neighbors.remove(getMappedNode(map,u)); 112 101 it = neighbors.iterator(); … … 127 116 Pair<Node> srcDst = g.getEndpoints(oldEdge); 128 117 Node src = srcDst.getFirst(); 129 Node dst = srcDst.get First();118 Node dst = srcDst.getSecond(); 130 119 Node srcMapped = getMappedNode(map, src); 131 120 Node dstMapped = getMappedNode(map, dst); … … 135 124 } 136 125 } 137 138 139 // for(int i=0; i < g.size(); i++) {140 // int u = g.getLabel(i);141 // Iterator<Integer> it = g.getNeighbors(u).iterator();142 // while(it.hasNext()) {143 // int v = it.next();144 // if(getMappedNode(g,map,u) != getMappedNode(g,map,v) && output.isEdge(getMappedNode(g,map,u), getMappedNode(g,map,v)) && u < v) {145 // output.setWeight(getMappedNode(g,map,u), getMappedNode(g,map,v), output.getWeight(getMappedNode(g,map,u), getMappedNode(g,map,v)) + g.getWeight(u, v));146 // }147 // }148 // }149 150 151 126 iterator = g.getVertices().iterator(); 152 127 Set<Node> nodesComplete = new HashSet<Node>(); … … 158 133 getMappedNode(map,u).setVwgt(u.getVwgt() + v.getVwgt()); 159 134 getMappedNode(map,u).setCewgt(u.getCewgt() + v.getCewgt() + g.findEdge(u, v).getWeight()); 160 getMappedNode(map,u).setAdjwgt(u.getAdjwgt() + v.getAdjwgt() - 2 * g.findEdge(u, v).getWeight());161 135 nodesComplete.add(u); 162 136 nodesComplete.add(v); … … 165 139 getMappedNode(map,u).setVwgt(u.getVwgt()); 166 140 getMappedNode(map,u).setCewgt(u.getCewgt()); 167 getMappedNode(map,u).setAdjwgt(u.getAdjwgt());168 141 } 169 142 } … … 174 147 * Performs the first stage of the METIS algorithm, using RM. 175 148 */ 176 p ublicstatic CoarserGraphElement coarseOneStep(UndirectedGraph g) {149 private static CoarserGraphElement coarseOneStep(UndirectedGraph g) { 177 150 UndirectedGraph projected = g; 178 151 UndirectedGraph contracted = null; … … 183 156 return new CoarserGraphElement(contracted, projected, match, map); 184 157 } 158 185 159 160 /** 161 * Performs at least one contraction of the given the graph, and goes on until the graph 162 * is under the desidered size (see setFinerSize()). 163 * @param g 164 * @return the stack of contracted graphs 165 */ 186 166 public static Stack<CoarserGraphElement> coarse(UndirectedGraph g) { 187 167 Stack<CoarserGraphElement> stack = new Stack<CoarserGraphElement>(); 188 CoarserGraphElement e ;168 CoarserGraphElement e = null; 189 169 UndirectedGraph curr = g; 170 int i = 0; 171 190 172 do { 191 173 if(debug) 192 debugStream.println("-------- ---------------------------------------------");174 debugStream.println("--------CONTRACTION-nr" + i +"------------------------------"); 193 175 e = coarseOneStep(curr); 194 176 stack.push(e); 195 177 curr = e.getContracted(); 196 if(debug) 197 debugStream.println("-----------------------------------------------------"); 178 if(debug) { 179 debugStream.println("-----------EXPANDED----------------------------------"); 180 debugStream.println(e.getProjected().toString()); 181 debugStream.println("-----------CONTRACTED--------------------------------"); 182 debugStream.println(e.getContracted().toString()); 183 } 184 i++; 198 185 } while(e.getProjected().getVertexCount() > e.getContracted().getVertexCount() && e.getContracted().getVertexCount() > finerSize); 199 186 return stack;
Note: See TracChangeset
for help on using the changeset viewer.