Hello,
First of all, I need to apologise for my naivety.
I am a complete noob working with Gremlin/Groovy.
This is probably a silly question, but here goes nothing...
I am using the code from the Recipes page on "Traversal Induced Values".
Specifically the "complex" example:
gremlin> g.addV('tank').property('name', 'a').property('amount', 100.0).as('a').
addV('tank').property('name', 'b').property('amount', 0.0).as('b').
addV('tank').property('name', 'c').property('amount', 0.0).as('c').
addE('drain').property('factor', 0.5).from('a').to('b').
addE('drain').property('factor', 0.1).from('b').to('c').iterate()
gremlin> a = g.V().has('name','a').next()
==>v[0]
gremlin> g.withSack(a.value('amount')).
V(a).repeat(outE('drain').sack(mult).by('factor').
inV().property('amount', sack())).
until(__.outE('drain').count().is(0)).iterate()
However, this is replacing the 'amount' in each node. I would like to accumulate it.
So instead of
==>[amount:[100.0],name:[a]]
==>[amount:[50.00],name:[b]]
==>[amount:[5.000],name:[c]]
I would like to have a starting 'amount' for each vertice and in every 'hop' to add the new value to the existing.
i.e. if amount for 'a' was 100, 'b' 10, and 'c' 20, the output would be:
==>[amount:[100.0],name:[a]]
==>[amount:[60.00],name:[b]]
==>[amount:[25.000],name:[c]]
I expect this to be a dead easy solution, but I really cannot figure it out... :|
Thank you in advance.
Theo.