blob: 964585417ed73788e32863ec500730c7c4a93c7f [file] [log] [blame]
Yuta HIGUCHIa1e655a2014-01-23 17:43:11 -08001/* Copyright (c) 2013 Stanford University
2 *
3 * Permission to use, copy, modify, and distribute this software for any
4 * purpose with or without fee is hereby granted, provided that the above
5 * copyright notice and this permission notice appear in all copies.
6 *
7 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR(S) DISCLAIM ALL WARRANTIES
8 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL AUTHORS BE LIABLE FOR
10 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14 */
15
yoshi28bac132014-01-22 11:00:17 -080016package com.tinkerpop.blueprints.impls.ramcloud;
17
18import java.awt.Dimension;
19import java.util.logging.Level;
20
21import javax.swing.JFrame;
22
23import org.apache.commons.collections15.Transformer;
24
25import com.tinkerpop.blueprints.Edge;
26import com.tinkerpop.blueprints.Graph;
27import com.tinkerpop.blueprints.Vertex;
28import com.tinkerpop.blueprints.oupls.jung.GraphJung;
29
30import edu.uci.ics.jung.algorithms.layout.BalloonLayout;
31import edu.uci.ics.jung.algorithms.layout.CircleLayout;
32import edu.uci.ics.jung.algorithms.layout.DAGLayout;
33import edu.uci.ics.jung.algorithms.layout.FRLayout;
34import edu.uci.ics.jung.algorithms.layout.FRLayout2;
35import edu.uci.ics.jung.algorithms.layout.ISOMLayout;
36import edu.uci.ics.jung.algorithms.layout.KKLayout;
37import edu.uci.ics.jung.algorithms.layout.Layout;
38import edu.uci.ics.jung.algorithms.scoring.PageRank;
39import edu.uci.ics.jung.visualization.BasicVisualizationServer;
40
41public class JUNGExamples {
42
43 public JUNGExamples() {
44 // TODO Auto-generated constructor stub
45 }
46
47 public static void calculatePageRank(Graph graph) {
48 PageRank<Vertex,Edge> pageRank = new PageRank<Vertex, Edge>(new GraphJung(graph), 0.15d);
49 pageRank.evaluate();
50
51 for (Vertex vertex : graph.getVertices()) {
52 System.out.println("The PageRank score of " + vertex + " is: " + pageRank.getVertexScore(vertex));
53 }
54 }
55
56 public static void displayGraph(Graph graph) {
57 GraphJung gj = new GraphJung(graph);
58
59 Layout<Vertex, Edge> layout = new CircleLayout<Vertex, Edge>(gj);
60 layout.setSize(new Dimension(600, 600));
61 BasicVisualizationServer<Vertex, Edge> viz = new BasicVisualizationServer<Vertex, Edge>(layout);
62 viz.setPreferredSize(new Dimension(650, 650));
63
64 Transformer<Vertex, String> vertexLabelTransformer = new Transformer<Vertex, String>() {
65 public String transform(Vertex vertex) {
66 return (String) vertex.getProperty("name");
67 }
68 };
69
70 Transformer<Edge, String> edgeLabelTransformer = new Transformer<Edge, String>() {
71 public String transform(Edge edge) {
72 return edge.getLabel();
73 }
74 };
75
76 viz.getRenderContext().setEdgeLabelTransformer(edgeLabelTransformer);
77 viz.getRenderContext().setVertexLabelTransformer(vertexLabelTransformer);
78
79 JFrame frame = new JFrame("TinkerPop");
80 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
81 frame.getContentPane().add(viz);
82 frame.pack();
83 frame.setVisible(true);
84
85 try {
86 System.in.read();
87 } catch(Exception e) {
88 // poop
89 }
90 }
91
92 public static void main(String[] args) {
93 Graph graph = new RamCloudGraph(Level.FINER);
94
95 FurnaceExamples.generateDistributionGraph(graph, "ex");
96
97 //calculatePageRank(graph);
98
99 displayGraph(graph);
100
101 graph.shutdown();
102 }
103
104}