- Timestamp:
- Oct 9, 2010, 12:24:38 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/weka/clusterers/forMetisMQI/GraphAlgorithms.java
r25 r26 1 1 package weka.clusterers.forMetisMQI; 2 2 3 import java.io.File; 4 import java.io.FileOutputStream; 5 import java.io.IOException; 3 6 import java.util.HashSet; 4 7 import java.util.Iterator; 5 8 import java.util.Set; 6 9 import java.util.Stack; 10 11 import org.jdom.Document; 12 import org.jdom.Element; 13 import org.jdom.output.Format; 14 import org.jdom.output.XMLOutputter; 7 15 8 16 import weka.clusterers.forMetisMQI.graph.Bisection; … … 13 21 import weka.clusterers.forMetisMQI.util.Configuration; 14 22 import weka.clusterers.forMetisMQI.util.GraphsFrame; 23 import weka.clusterers.forMetisMQI.util.Random; 15 24 import weka.clusterers.forMetisMQI.util.Util; 16 25 … … 92 101 int verboseLevel = Configuration.instance().getVerboseLevel(); 93 102 GraphsFrame gf = GraphsFrame.instance(); 103 104 Element rootXML = new Element("run"); 105 Document logXML = new Document(rootXML); 106 rootXML.setAttribute("seed", Long.toString(Random.instance().getSeed())); 107 Element graphXML = new Element("graph"); 108 graphXML.addContent(new Element("vertex").setText(Integer.toString(g.getVertexCount()))); 109 graphXML.addContent(new Element("edge").setText(Integer.toString(g.getEdgeCount()))); 110 rootXML.addContent(graphXML); 111 Element clustersXML = new Element("clusters"); 112 rootXML.addContent(clustersXML); 113 94 114 System.out.println("Seed: " + Random.instance().getSeed()); 95 115 System.out.println("Vertex count: " + g.getVertexCount()); … … 97 117 Set<Set<Node>> clusters = new HashSet<Set<Node>>(); 98 118 UndirectedGraph gclone = g.clone(); 119 99 120 for (int i = 0; i < numberOfCluster; i++) { 100 121 Bisection bisection = null; … … 109 130 gf.addPanel(Util.panelCluster(g.clone(),bisection.getSmallerSubgraph().createInducedSubgraph().getVertices())); 110 131 111 System.out.print(" Partizione iniziale: ");132 System.out.print("Initial partition: "); 112 133 System.out.print("V1: " + bisection.getSubgraph().getVertexCount()); 113 134 System.out.print(" V2: " + bisection.getComplement().getVertexCount()); … … 121 142 // System.out.println(cluster); 122 143 Bisection mqiBisection = new Bisection(new Subgraph(g,cluster)); 123 System.out.println(" Partizione raffinata(MQI)");144 System.out.println("Refined partition (MQI)"); 124 145 double newConductance = ((double)mqiBisection.edgeCut() / 2) / Math.min(mqiBisection.getSubgraph().totalDegree(),mqiBisection.getComplement().totalDegree()); 125 System.out.println("Cluster "+ i + ": V=" + clusterGraph.getVertexCount() + ", E=" + clusterGraph.getEdgeCount()+"."); 146 System.out.print("Cluster "+ i + ": V=" + clusterGraph.getVertexCount() + ", E=" + clusterGraph.getEdgeCount()+", "); 147 System.out.println("Cond: " + newConductance); 148 149 150 mqiBisection = new Bisection(new Subgraph(gclone,cluster)); 151 newConductance = ((double)mqiBisection.edgeCut() / 2) / Math.min(mqiBisection.getSubgraph().totalDegree(),mqiBisection.getComplement().totalDegree()); 126 152 System.out.println("Cluster conductance: " + newConductance); 153 154 155 Element clusterXML = new Element("cluster"); 156 clusterXML.setAttribute("id", Integer.toString(i)); 157 clusterXML.addContent(new Element("vertex").setText(Integer.toString(clusterGraph.getVertexCount()))); 158 clusterXML.addContent(new Element("edge").setText(Integer.toString(clusterGraph.getEdgeCount()))); 159 clusterXML.addContent(new Element("conductance").setText(Double.toString(newConductance))); 160 clustersXML.addContent(clusterXML); 127 161 128 162 clusters.add(cluster); … … 134 168 } 135 169 } 170 171 172 XMLOutputter xmlOutputter = new XMLOutputter(); 173 xmlOutputter.setFormat(Format.getPrettyFormat()); 174 try { 175 xmlOutputter.output(logXML, new FileOutputStream(new File(Configuration.instance().getOutputFile()))); 176 } catch (IOException e) { 177 e.printStackTrace(); 178 } 179 136 180 if(verboseLevel > 0) { 137 181 gf.addPanel(Util.panelClusters(gclone, clusters));
Note: See TracChangeset
for help on using the changeset viewer.