Changeset 14 for src/main/java/weka/clusterers/forMetisMQI/MQI.java
- Timestamp:
- Sep 17, 2010, 1:09:06 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/weka/clusterers/forMetisMQI/MQI.java
r12 r14 23 23 import weka.clusterers.forMetisMQI.graph.UndirectedGraph; 24 24 import edu.uci.ics.jung.algorithms.flows.EdmondsKarpMaxFlow; 25 import edu.uci.ics.jung.algorithms.layout.FRLayout; 25 26 import edu.uci.ics.jung.algorithms.layout.KKLayout; 26 27 import edu.uci.ics.jung.algorithms.layout.Layout; … … 35 36 static int i = -1; 36 37 37 public static void viewClusters(Graph<Node, Edge> g, Set<Set<Node>> clusters) {38 Layout<Node, Edge> layout = new KKLayout<Node, Edge>(g);39 layout.setSize(new Dimension(800, 600)); // sets the initial size of the space40 // The BasicVisualizationServer<V,E> is parameterized by the edge types41 BasicVisualizationServer<Node, Edge> vv = new BasicVisualizationServer<Node, Edge>(42 layout);43 44 class VertexPaintTransformer implements Transformer<Node, Paint> {45 Set<Set<Node>> clusters = null;46 Map<Set<Node>, Color> clustersColor = null;47 48 public Set<Node> getCluster(Node node) {49 Iterator<Set<Node>> clusterIterator = clusters.iterator();50 while (clusterIterator.hasNext()) {51 Set<Node> cluster = clusterIterator.next();52 if (cluster.contains(node))53 return cluster;54 }55 return null;56 }57 58 public VertexPaintTransformer(Set<Set<Node>> clusters) {59 this.clusters = clusters;60 clustersColor = new HashMap<Set<Node>, Color>(clusters.size());61 Iterator<Set<Node>> clusterIterator = clusters.iterator();62 while (clusterIterator.hasNext()) {63 Set<Node> cluster = clusterIterator.next();64 clustersColor.put(cluster, new Color(Random.instance()65 .nextInt(256), Random.instance().nextInt(256),66 Random.instance().nextInt(256)));67 }68 }69 70 public Paint transform(Node i) {71 Set<Node> cluster = getCluster(i);72 if (cluster == null)73 return Color.RED;74 else75 return clustersColor.get(getCluster(i));76 }77 }78 79 Transformer<Node, Paint> vertexPaint = new VertexPaintTransformer(80 clusters);81 vv.setPreferredSize(new Dimension(800, 600)); // Sets the viewing area82 // size83 vv.getRenderContext().setVertexLabelTransformer(84 new ToStringLabeller<Node>());85 vv.getRenderContext().setEdgeLabelTransformer(86 new ToStringLabeller<Edge>());87 vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);88 JFrame frame = new JFrame("Graph View");89 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);90 frame.getContentPane().add(vv);91 frame.pack();92 frame.setVisible(true);93 }94 95 public static void viewGraph(Graph<Node, Edge> g){96 Layout<Node, Edge> layout = new KKLayout<Node, Edge>(g);97 layout.setSize(new Dimension(800,600)); // sets the initial size of the space98 // The BasicVisualizationServer<V,E> is parameterized by the edge types99 BasicVisualizationServer<Node,Edge> vv =100 new BasicVisualizationServer<Node,Edge>(layout);101 vv.setPreferredSize(new Dimension(800,600)); //Sets the viewing area size102 vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<Node>());103 vv.getRenderContext().setEdgeLabelTransformer(new ToStringLabeller<Edge>());104 105 JFrame frame = new JFrame("Simple Graph View");106 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);107 frame.getContentPane().add(vv);108 frame.pack();109 frame.setVisible(true);110 }111 112 38 static private Set<Node> BFSReversed(Node sink, DirectedGraph<Node, Edge> g, Map<Edge, Number> edgeFlowMap) { 113 39 Set<Node> result = new HashSet<Node>();
Note: See TracChangeset
for help on using the changeset viewer.