0

I am new to Gremlin and I am trying to implement the pagerank algorithm with edge weights from JUNG. These are the steps I have taken. I have 2.0.0.0 version of Gremlin installed. I have created a .graphml file using the iGraph package in R, which I am loading into gremlin.

import edu.uci.ics.jung.algorithms.scoring.PageRank   
g1 = new TinkerGraph()      
g1.loadGraphML('file path.graphml')    

My g1 graph has the following edge attributes:

 g1.E.map
==>{weight=1, freq=1}
==>{weight=1, freq=1}
==>{weight=2, freq=2}
==>{weight=1, freq=1}
==>{weight=1, freq=1}
==>{weight=1, freq=1}
==>{weight=1, freq=1}
==>{weight=1, freq=1}
==>{weight=2, freq=2}

gremlin> g1.V.map
==>{name=a}
==>{name=b}
==>{name=c}
==>{name=d}
==>{name=e}
==>{name=f}
==>{name=g}
==>{name=h}
==>{name=i}
==>{name=k}

j = new GraphJung(g1)    

t = new EdgeWeightTransformer("weight",true, false)
pr = new PageRank<Vertex,Edge>(j, t, 0.15d)  
pr.evaluate()      
j.getVertices().collect{[it, pr.getVertexScore(it)]}

However, my results are

==>[v[n1], 0.046875]
==>[v[n0], 0.046875]
==>[v[n5], 0.046875]
==>[v[n4], 0.046875]
==>[v[n3], 0.046875]
==>[v[n2], 0.046875]
==>[v[n9], 0.046875]
==>[v[n8], 0.046875]
==>[v[n7], 0.046875]
==>[v[n6], 0.046875]

which are are incorrect. Please can someone help me understand what is wrong in the code. I also tried to check the effect of the transformer on the edge weights of j by the following: j.getEdges().t.

I get NULLS when I do this.

But I know there are weights associated with these edges as when I run:

j.getEdges().collect{[it, it.weight]}   

I get the following results:

==>[e[3][n1-_default->n5], 1]

==>[e[2][n0-_default->n4], 1]

==>[e[1][n0-_default->n3], 2]

==>[e[0][n0-_default->n2], 1]

==>[e[7][n1-_default->n8], 1]

==>[e[6][n1-_default->n7], 1]

==>[e[5][n1-_default->n6], 1]

==>[e[4][n1-_default->n1], 1]

==>[e[8][n1-_default->n9], 2]

Finally, I am unable to create automatic keys for my vertices. I tried

g1.createAutoIndex('test', Vertex.class, ['name'] as Set)           

And got the following error:

 No signature of method: groovy.lang.MissingMethodException.createAutoIndex() is applicable for argument types: () values: []  

Thank you

user2172699
  • 21
  • 2
  • 4

1 Answers1

0

I also took a tough time to find how to implement pagerank of weight-edge-graph using Jung. Below is the pesudo code, you should use GrepCode to see the detail implementation of Pagerank.

For(Edge e: edges){  // Edge is a user-defined class
    graph.add(edgeCount,e.getStart,e.getEnd);
    map.put(edgeCount,e.getWeight); // map is HashMap
    edgeCount++;
}
Transformer edge_weights = MapTransformer.getInstance(map) //Key Step!
Pagerank<Vertex,Edge> ranker = new Pagerank<Vertex,Edge>(graph, edge_weights, alpha);

I would recommend you look this example: https://github.com/lintool/Cloud9/blob/master/src/dist/edu/umd/cloud9/example/pagerank/SequentialPageRank.java

You can modify based on this example using my pseudo code.

Jinfeng
  • 99
  • 3
  • 10