Search code examples
c++feedback

Preventing feedback routing in C++ Class design


What is a recommended implementation for an abstract routing network that prevents or reports feedback loops.

For example:

  • A modulates B
  • B modulates C
  • C modulates A

this exmaple would create a feedback loop. The final value of A is not known until it is assigned and in this system A can't accurately modulate the values that are dependent on A and thus get the final value of A.

The actual implementation is more complex, with more passes where any value can modulate any other value so long as they do not create this kind of feedback loop.

Is there any library or container type that might help to solve this?


Solution

  • From a programming viewpoint, you're looking at a directed graph, and attempting to determine whether it's acyclic. Given that you're using C++, the Boost Graph Library would be the obvious choice for that. If you attempt a topological sort on the graph, it'll fail (by throwing boost::not_a_dag) when/if the graph contains a cycle (since only an acyclic graph can be topologically sorted).