I'm new to boost graph library and trying to solve the following problem:
In a graph (boost::adjacency_list) I have 3 different vertex types (implemented using std::variant) and currently undirected edges:
- Connector (1)
- Switch (2)
- SwitchState (3) - (ON/OFF)
A typical hierarchy in my graph is like this:
(1a) - (2a) - (1b) - (1d) - (2b) - (1e)
| |
(3a) (3b)
| |
(1c)
What I need to do is to find all reachable vertices from a certain starting point (e.g. 1a):
1a -> 2a -> 1b -> 1d -> 2b -> 1e
Of course just using BFS or DFS come to mind immediately! :-)
However: The state of vertex (2) (a switch or relais) is controlled by the state (boolean) of the directly connected vertex (3). That means that there's no way to traverse from (1a) to (1b) via vertex (2a) if (3a) is (let's say) false. And at last: One cannot traverse from type (2) to type (3) vertices.
My question is: Does anyone have suggestions about how to implement such a graph traversal efficiently? I have implemented this in plain C++ using lots of vectors/maps etc. and DFS already but would like to move code to a higher, more abstract (but hopefully still efficient) implementation of the underlying graph!
I'm unsure if I should:
- Use a filtered_graph and just use BFS or DFS to traverse?
- Create a sub_graph depending on the type 3 vertices state then and apply BFS/DFS?
- There's a way to achieve this "on the fly" while searching via BFS/DFSvisitor?
- Another solution?
Helpful ideas are very welcome!
PS: The code is used to simulate an electrical network - just in case.