To make it simple assume you have only AND and OR gates. Each has two inputs and one output. The output of two inputs can be used as an input for the next gate For example:A AND B -> EC AND D -> FE OR F -> GAssuming an arbitrary number of gates, we want to check if the circuit ever connects back into itself at an earlier state? For example:E AND F -> AThis should be illegal since it creates an endless cycle. What design pattern would best be able to check for these cycles?
When modeling a virtual circuit board, what is the best design pattern to check for cycles?
design patterns;object oriented;algorithms;language agnostic;object oriented design
Looks like you are talking about building a directed graph and checking for cycles. This can be done in many ways. The most basic is a topological sort.https://stackoverflow.com/questions/583876/how-do-i-check-if-a-directed-graph-is-acyclic orhttps://stackoverflow.com/questions/261573/best-algorithm-for-detecting-cycles-in-a-directed-graph