This is a pretty Interesting question. It might help to read a little about data structures, specifically binary trees and linked lists. It won’t be an exact answer since the number of inputs and outputs that you want may vary. Think about a node (or pole) as a single entity first. The node has to identify whether it is attached to a parent, and whether it has child nodes down stream.
Each node A) keeps a reference to the child beneath it, B) has the same state as its parent node and C) is marked as a root node (generator) or not.
When a node is detached from its parent, if it is not a generator, you trigger an event or function that traverses through the lower nodes and updates the pole states.
Sorry if that’s a bit too technical. I’m interested to see where you go with this. I might try it out later if I have time and update.