I have modeled our City's sewer network in Neo4j. Below describes the model, and after that describes my question. I do not include specific code here because I am fine talking in pseudo-code or generalizations.
I have represented manholes and sewer mains as their own kinds of labeled nodes in a graph. Any given manhole has a relationship with 0 or more sewer mains. 0 or more sewer mains may flow into the manhole and 0 or more sewer mains may flow out of the manhole. These are represented by directional relationships. If more than one sewer main flows out of a manhole, all but one of those sewer mains will be marked as a backup line. Each sewer main node has an attribute to describe how long it is, in feet. One manhole in the entire graph has the label of Head Works. It is where all sewer eventually ends up to be processed. (Note: You do NOT want to go into the Head Works building without a mask, regardless of COVID-19. :) )
The problem I want to solve is this: for each sewer main, I want to find how many feet of sewer main are downstream from it (including itself) on its shortest, directed path to Head Works. I do not want to traverse any lines that are marked as backup lines, but it's okay if the sewer main in question IS a backup line. I want this number of feet to become an attribute on the sewer line. I am not concerned with performance as this will be a rare task to repeat once the final data is generated.
Because this problem deals with accumulation, it is okay if the sewer mains closest to Head Works are first given their own length attribute as the accumulated length. Then every sewer main that flows into those sewer mains add their own length to the accumulated length, and so on in a recursive pattern. I just don't know how to do this, which is why I'm posting it to the experts on this forum.
If you would like me to post some sample Cypher that shows nodes and relationships, I will. Thank you for reading.