Breadth First Search Algorithm Visitor Pattern

Directed Acyclic Graph Tool
Alice Robson: UNIGE
(with thanks to Colin Bernet)
Directed Acyclic Graph (DAG)
8
• Node represents an item
7
• Links between Nodes are directed
4
0
1
5
2
6
• Each Node can have
multiple children
multiple parents
• There are no cycles in the directed graph
3
Aim of this implementation :to support DAG where the Nodes may represent different types
DAG tool implements Visitor Pattern:
It includes
Node<T> Class
Visitor<N> Class Interface
BFSVisitorPattern<N> Class (implementation of Visitor Class)
Where T = Node content
N = Node<T>
The Classes are deliberately kept simple.
Users may also implement their own specialist visitors/or their own Node
classes.
Node Class Implementation
Visitor Class Implementation
Breadth First Search Algorithm Visitor Pattern
8
Eg Start at Node 0-
7
0
4
traverseChildren returns Nodes:
0, 1, 2, 3, 4, 5, 6
1
5
traverseUndirected returns Nodes:
0, 1, 2, 3, 4, 5, 6, 7, 8
2
6
3
Start at Node 4
traverseParents returns Nodes:
4, 1, 7, 0, 8
Examples
Three examples have been constructed
- they use same graph structure
- different types of content <T>
(1) Using Boost::Any: Node<Boost::Any>
(2) Using Polymorphic classes: Node<const Base&>
(3) Using a unique (encoded) long: Node<const long>
Boost:Any
Allows any object to be wrapped inside.
Very easy to wrap stuff up,
To unravel requires working out what it is and casting to
original type
eg
Long Encoded Identifier
The long encodes information about the Node contents
eg
Datatype (eg CLUSTER, TRACK, PARTICLE)
SubType (eg RAW, SMEARED, MERGED)
Unique long
This is approach planned for PAPAS C++ FASTSIM implementation.
Will be used alongside structures such as
std::unordered_map<long, Track>
Given a long encoded id – we can decide what it is and find the corresponding
item.
Available on Git Hub
https://github.com/alicerobson/DAG_tool
Hoping to add other relevant examples as they become
available.