Reputation: 1
I'm trying to traverse a graph (directed) where the edges have weights. How do I use the weights to define the order in which an edge is followed: the lower the weight (module of the weight to be exact: edges can have negative values. But this is a detail), then the higher the priority: low weights are executed first. In case (possible) two edges have the same weight I would execute them simultaneously, or, if not possible, at random. The plan is to make a change to one of the nodes' values, and then let it propagate over the graph: the propagation must follow the rules of weights of edges, and each node reached will make a change to one of its values, and so on. I am yet to define the exact changes, and how to solve the cycles, but to begin with, I am unable to propagate on the graph in a controlled manner, following a rule of minimal weights. In order to see the propagation, I'm pushing it into Gephi. I did succeed to push a propagation:
traversal = vg.V().has('Value','SomeStartNodeIChose').repeat(outE().otherV().simplePath()).until(has('Value','SomeEndNodeIChose')).path().by('Value').by('Weight');[]
:> traversal
and this works nicely: I can see the nodes lighting up like a christmas tree. But I cannot insert a min() here for the world.....
Can anyone explain a newbie how this works?
my attempts are clearly confuse, so....
traversal = vg.V().has('Value','AirBnb').repeat(outE().where(min()).otherV().simplePath()).until(has('Value','Comfort')).path().by('Value').by('Update Weight');[]
throws: org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerEdge cannot be cast to java.lang.Comparable
traversal = vg.V().has('Value','AirBnb').repeat(outE().where('Weight',is(min())).otherV().simplePath()).until(has('Value','Comfort')).path().by('Value').by('Update Weight');[]
throws: No signature of method: org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal.where() is applicable for argument types: (String, org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal) values: [Weight, [IsStep(eq([MinGlobalStep]))]]
and I can go on and on... I definitely did not understand how this works...
Upvotes: 0
Views: 62
Reputation: 2769
min()
is a reducing barrier, so you're not going to be able to use that within a repeat()
. Instead, you may want to use order().by().limit(1)
to get the minimum weighted edge:
g.V().has('Value','AirBnb').
repeat(
outE().order().by('weight').limit(1).
inV().
simplePath()
).
until(outE().count().is(eq(0))).path()
Upvotes: 0