I've been looking around but cant seen to find what data structure I can implement to represent a ladder diagram from a PLC program PLC in python.
For those not familiar with ladder diagrams. It is basically a multilevel linked list where nodes in a level can both be connected back to a higher level in the next column and be connected to a node in the same level further down.
I've attached a picture.
I have tried using multilevel linked list where I save previous nodes as left_neighbours and next nodes and right_neighbours.
I am unsure if this is the best approach and also im unsure how I traverse this list to get all nodes without duplicates.
Prerequisites:
- Identical nodes can be present in different places in the diagram
- To check equality you have to check if neighbours are the same?
- Multiple inputs
- Nodes can have multiple neighbours both left and right
- Branches can merge back together
Constraints:
- Just one output
- Making it possbible starting traverse from output node backwards?
The code I have is not possible to understand without context since I have a huge method trimming the custom syntax from the program where I extract text based logic from ladder logic. Also im unsure if its suitable posting it online since its IP not owned by me even though developed by me.
My question is very general and regarding a suitible data structure.
Below is an example picture of ladder logic