In my application, I have what is essentially the syntax tree of a mathematical expression as neo4j graph... a picture is probably helpful:
I'm wondering if it's possible to write a Cypher query that fully evaluates a tree like this for the top node, i.e.:
- gets the average of the connected inputs for Node 1.2,
- the max for 1.1.2
- the average of 1.1.2 and 3 for Node 1.1
- and finally returns the max of 1.2 and 1.1 as value for Node 1
The value is stored in the property status for the input nodes, in the max and avg nodes the value is not present and should be calculated.
Here's the whole thing in neo4j console: http://console.neo4j.org/?id=gopwjn
I have a feeling that it might be possible with some WITH and REDUCE and similar voodoo, but I can't piece it quite together.