- Timestamp:
- Sep 30, 2010, 5:33:45 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/weka/clusterers/forMetisMQI/graph/UndirectedGraph.java
r17 r20 1 1 package weka.clusterers.forMetisMQI.graph; 2 2 3 import java.io.PrintStream; 3 4 import java.util.ArrayList; 4 5 import java.util.Collection; 6 import java.util.HashMap; 5 7 import java.util.Iterator; 6 8 import java.util.List; 9 import java.util.TreeMap; 7 10 8 11 import weka.clusterers.forMetisMQI.Random; … … 109 112 } 110 113 114 public void printForMetis(PrintStream output) { 115 TreeMap<Integer,Node> map = new TreeMap<Integer,Node>(); 116 HashMap<Node,Integer> reverseMap = new HashMap<Node,Integer>(); 117 Iterator<Node> nodesIterator = getVertices().iterator(); 118 int id = 1; 119 while(nodesIterator.hasNext()) { 120 Node node = nodesIterator.next(); 121 map.put(id, node); 122 reverseMap.put(node,id); 123 id++; 124 } 125 output.println(getVertexCount() + " "+ getEdgeCount()); 126 Iterator<Integer> mappedIterator = map.keySet().iterator(); 127 while(mappedIterator.hasNext()) { 128 id = mappedIterator.next(); 129 Iterator<Node> neighbors = getNeighbors(map.get(id)).iterator(); 130 while(neighbors.hasNext()){ 131 output.print(reverseMap.get(neighbors.next())); 132 if(neighbors.hasNext()) output.print(" "); 133 } 134 output.println(); 135 } 136 } 137 111 138 public String toString() { 112 139 StringBuffer sb = new StringBuffer("Vertices:");
Note: See TracChangeset
for help on using the changeset viewer.