Graph graph = TinkerGraphFactory.createTinkerGraph();
//Graph graph = new TinkerGraph();
//GraphMLReader.inputGraph(graph, "/Users/marko/software/tinkerpop/gremlin/data/graph-example-2.xml");
WeightedPageRankProgram program = WeightedPageRankProgram.create().vertexCount(6).edgeWeightFunction(WeightedPageRankProgram.getEdgeWeightPropertyFunction("weight")).build();
SerialGraphComputer computer = new SerialGraphComputer(graph, program, GraphComputer.Isolation.BSP);
computer.execute();
VertexMemory results = computer.getVertexMemory();
System.out.println(results);
double total = 0.0d;
final Map<String, Double> map = new HashMap<String, Double>();
for (Vertex vertex : graph.getVertices()) {
double pageRank = Double.parseDouble(results.getProperty(vertex, WeightedPageRankProgram.PAGE_RANK).toString());
assertTrue(pageRank > 0.0d);
total = total + pageRank;
map.put(vertex.getProperty("name") + " ", pageRank);
}
for (Map.Entry<String, Double> entry : ImmutableSortedMap.copyOf(map, new Comparator<String>() {
public int compare(final String key, final String key2) {
int c = map.get(key2).compareTo(map.get(key));
return c == 0 ? -1 : c;
}
}).entrySet()) {
System.out.println(entry.getKey() + " " + entry.getValue());
}
System.out.println(total);
System.out.println(computer.getGraphMemory().getRuntime());
/*for (int i = 1; i < 7; i++) {
double PAGE_RANK = result.getResult(graph.getVertex(i));
System.out.println(i + " " + (PAGE_RANK / total));
}*/