Changeset 24 for src/main/java/weka/clusterers/forMetisMQI
- Timestamp:
- Oct 6, 2010, 4:02:40 PM (14 years ago)
- Location:
- src/main/java/weka/clusterers/forMetisMQI
- Files:
-
- 2 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/weka/clusterers/forMetisMQI/GraphAlgorithms.java
r23 r24 11 11 import weka.clusterers.forMetisMQI.graph.UndirectedGraph; 12 12 import weka.clusterers.forMetisMQI.util.CoarserGraphElement; 13 import weka.clusterers.forMetisMQI.util.Configuration; 13 14 import weka.clusterers.forMetisMQI.util.GraphsFrame; 14 15 import weka.clusterers.forMetisMQI.util.Util; … … 68 69 if (stack.size() > 0) { 69 70 partition = KL(stack.peek().getContracted()); 71 if(Configuration.instance().getVerboseLevel() > 1) { 72 GraphsFrame.instance().addPanel(Util.panelContractedGraph(stack.peek())); 73 GraphsFrame.instance().addPanel(Util.panelContractedGraph(stack.peek(),partition.getSmallerSubgraph().createInducedSubgraph().getVertices())); 74 } 70 75 partition = Uncoarse.uncoarse(stack, partition); 71 76 } … … 81 86 * @param sizeFinerGraph 82 87 */ 83 static public Set<Set<Node>> metisMqi(UndirectedGraph g, int numberOfCluster, int sizeFinerGraph, boolean randomBisection) { 84 GraphsFrame gf = new GraphsFrame("Prova"); 88 static public Set<Set<Node>> metisMqi(UndirectedGraph g) { 89 int numberOfCluster = Configuration.instance().getNumberOfClusters(); 90 boolean randomBisection = Configuration.instance().isRandomBisection(); 91 int sizeFinerGraph = Configuration.instance().getSizeFinerGraph(); 92 int verboseLevel = Configuration.instance().getVerboseLevel(); 93 GraphsFrame gf = GraphsFrame.instance(); 85 94 System.out.println("Vertex count: " + g.getVertexCount()); 86 95 System.out.println("Edges count: " + g.getEdgeCount()); 87 Iterator<Node> iNodes = g.getVertices().iterator();88 int degreeCounter = 0;89 while(iNodes.hasNext()) {90 Node node = iNodes.next();91 if(g.degree(node) == 1) {92 degreeCounter++;93 }94 }95 96 Set<Set<Node>> clusters = new HashSet<Set<Node>>(); 96 97 UndirectedGraph gclone = g.clone(); 97 gf.addPanel(Util.panelGraph(gclone));98 98 for (int i = 0; i < numberOfCluster; i++) { 99 99 Bisection bisection = null; 100 if(verboseLevel > 1) 101 gf.addPanel(Util.panelGraph(g.clone())); 100 102 if(!randomBisection) 101 103 bisection = metis(g,sizeFinerGraph); 102 104 else 103 105 bisection = new Bisection(g); 106 107 if(verboseLevel > 1) 108 gf.addPanel(Util.panelCluster(g.clone(),bisection.getSmallerSubgraph().createInducedSubgraph().getVertices())); 109 104 110 System.out.print("Partizione iniziale: "); 105 111 System.out.print("V1: " + bisection.getSubgraph().getVertexCount()); … … 127 133 } 128 134 } 129 gf.addPanel(Util.panelClusters(gclone, clusters)); 135 if(verboseLevel > 0) 136 gf.addPanel(Util.panelClusters(gclone, clusters)); 130 137 gf.setVisible(true); 131 138 return clusters; -
src/main/java/weka/clusterers/forMetisMQI/MQI.java
r22 r24 19 19 import edu.uci.ics.jung.graph.DirectedGraph; 20 20 import edu.uci.ics.jung.graph.DirectedSparseGraph; 21 import weka.clusterers.forMetisMQI.util.Configuration; 22 import weka.clusterers.forMetisMQI.util.GraphsFrame; 21 23 import weka.clusterers.forMetisMQI.util.Util; 22 24 … … 199 201 } 200 202 alg.evaluate(); 201 // Util.viewFlowGraph(directedGraph, edgeFlowMap); 203 if(Configuration.instance().getVerboseLevel() > 1) 204 GraphsFrame.instance().addPanel(Util.panelFlowGraph(directedGraph, edgeFlowMap)); 202 205 System.out.println("MAX FLOW: " + alg.getMaxFlow() + " THRESHOLD: " 203 206 + maxFlowThreshold); … … 210 213 bisection.getGraph(), cluster)); 211 214 // System.out.println("REFINED BISECTION: " + bisection.toString()); 215 if(Configuration.instance().getVerboseLevel() > 1) 216 GraphsFrame.instance().addPanel(Util.panelCluster(bisection.getGraph(), cluster)); 212 217 } else 213 218 finished = true; -
src/main/java/weka/clusterers/forMetisMQI/util/GraphsFrame.java
r23 r24 16 16 */ 17 17 private static final long serialVersionUID = 1L; 18 19 private static GraphsFrame instance = null; 18 20 19 21 private int numberOfPanels = 0; … … 23 25 private JButton nextButton = null; 24 26 private JButton prevButton = null; 27 28 public static GraphsFrame instance() { 29 if(instance == null) { 30 instance = new GraphsFrame("Graphs Frame"); 31 } 32 return instance; 33 } 34 35 private GraphsFrame() { 36 37 } 25 38 26 p ublicGraphsFrame(String name) {39 private GraphsFrame(String name) { 27 40 super(name); 28 41 setBounds(new Rectangle(800, 700)); 42 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 43 29 44 30 45 graphPanel = new JPanel(); -
src/main/java/weka/clusterers/forMetisMQI/util/Util.java
r23 r24 4 4 import java.awt.Dimension; 5 5 import java.awt.Paint; 6 import java.util.Collection; 6 7 import java.util.HashMap; 7 8 import java.util.HashSet; … … 9 10 import java.util.Map; 10 11 import java.util.Set; 12 import java.util.Map.Entry; 11 13 12 import javax.swing.JFrame;13 14 import javax.swing.JPanel; 14 15 … … 20 21 import weka.clusterers.forMetisMQI.graph.UndirectedGraph; 21 22 import edu.uci.ics.jung.algorithms.layout.FRLayout; 23 import edu.uci.ics.jung.algorithms.layout.KKLayout; 22 24 import edu.uci.ics.jung.algorithms.layout.Layout; 23 25 import edu.uci.ics.jung.graph.Graph; … … 27 29 public class Util { 28 30 29 public static JPanel panelCluster(Graph<Node, Edge> g, Set<Node> cluster) { 31 public static JPanel panelCluster(Graph<Node, Edge> g, Collection<Node> cluster) { 32 Set<Node> setNodes = new HashSet<Node>(); 33 setNodes.addAll(cluster); 30 34 Set<Set<Node>> clusters = new HashSet<Set<Node>>(); 31 clusters.add( cluster);35 clusters.add(setNodes); 32 36 return panelClusters(g, clusters); 33 37 } 34 38 39 public static JPanel panelClusters(Graph<Node, Edge> g, Set<Set<Node>> clusters) { 40 return panelClusters(g,clusters,new ToStringLabeller<Node>()); 41 } 35 42 36 public static JPanel panelClusters(Graph<Node, Edge> g, Set<Set<Node>> clusters ) {37 Layout<Node, Edge> layout = new FRLayout<Node, Edge>(g);43 public static JPanel panelClusters(Graph<Node, Edge> g, Set<Set<Node>> clusters, Transformer<Node,String> transformer) { 44 Layout<Node, Edge> layout = new KKLayout<Node, Edge>(g); 38 45 layout.setSize(new Dimension(800, 600)); // sets the initial size of the space 39 46 // The BasicVisualizationServer<V,E> is parameterized by the edge types … … 80 87 vv.setPreferredSize(new Dimension(800, 600)); // Sets the viewing area 81 88 // size 82 vv.getRenderContext().setVertexLabelTransformer( 83 new ToStringLabeller<Node>()); 84 vv.getRenderContext().setEdgeLabelTransformer( 85 new ToStringLabeller<Edge>()); 89 vv.getRenderContext().setVertexLabelTransformer(transformer); 86 90 vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint); 87 91 return vv; … … 89 93 90 94 public static JPanel panelGraph(Graph<Node, Edge> g){ 91 Layout<Node, Edge> layout = new FRLayout<Node, Edge>(g);95 Layout<Node, Edge> layout = new KKLayout<Node, Edge>(g); 92 96 layout.setSize(new Dimension(800,600)); // sets the initial size of the space 93 97 // The BasicVisualizationServer<V,E> is parameterized by the edge types … … 96 100 vv.setPreferredSize(new Dimension(800,600)); //Sets the viewing area size 97 101 vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<Node>()); 98 vv.getRenderContext().setEdgeLabelTransformer(new ToStringLabeller<Edge>()); 102 vv.getRenderContext().setEdgeLabelTransformer( 103 new Transformer<Edge, String>() { 104 public String transform(Edge e) { 105 return ""; 106 } 107 }); 99 108 return vv; 100 109 } … … 120 129 return vv; 121 130 } 131 132 static public JPanel panelContractedGraph(CoarserGraphElement cge, Collection<Node> cluster) { 133 Set<Node> setNodes = new HashSet<Node>(); 134 setNodes.addAll(cluster); 135 Set<Set<Node>> clusters = new HashSet<Set<Node>>(); 136 clusters.add(setNodes); 137 return panelClusters(cge.getContracted(), clusters, new ContractedVertexTransformer(cge)); 138 } 139 140 static public JPanel panelContractedGraph(CoarserGraphElement cge) { 141 Layout<Node, Edge> layout = new KKLayout<Node, Edge>(cge.getContracted()); 142 layout.setSize(new Dimension(800,600)); // sets the initial size of the space 143 // The BasicVisualizationServer<V,E> is parameterized by the edge types 144 BasicVisualizationServer<Node,Edge> vv = 145 new BasicVisualizationServer<Node,Edge>(layout); 146 vv.setPreferredSize(new Dimension(800,600)); //Sets the viewing area size 147 vv.getRenderContext().setVertexLabelTransformer(new ContractedVertexTransformer(cge)); 148 return vv; 149 } 150 122 151 123 152 /**
Note: See TracChangeset
for help on using the changeset viewer.