Implements to pick up of the highest value path in neighborhood Following high value paths can be done two ways.
More...
#include <CellularPathFollower.h>
|
| static std::vector< Path< ACellHolder > > | followAll (const std::vector< ACellHolder * > &cellHolders, const std::vector< WeightedRelation< ACellHolder > > &cellHolderRelations, Weight minStateToFollow=-INFINITY) |
| | Follow paths from all start cells marked with the start flag.
|
| |
| static Path< ACellHolder > | followSingle (ACellHolder *startCellHolder, const std::vector< WeightedRelation< ACellHolder > > &cellHolderRelations, Weight minStateToFollow=-INFINITY) |
| | Follows a single maximal path starting with the given start cell.
|
| |
|
| static void | growAllPaths (Path< ACellHolder > &path, const std::vector< WeightedRelation< ACellHolder > > &cellHolderRelations, std::vector< Path< ACellHolder > > &paths) |
| | Helper function for recursively growing paths.
|
| |
| static bool | validStartCell (const AutomatonCell &automatonCell, Weight minStateToFollow) |
| | Helper function to determine, if the cell has all flags indicating to be a start cell and that its state exceeds the minimal requirement.
|
| |
| static bool | isHighestContinuation (const WeightedRelation< ACellHolder > &relation) |
| | Helper function determining if the given neighbor is one of the best to be followed.
|
| |
| static bool | isHighestContinuation (const ACellHolder &cellHolder, Weight relationWeight, const ACellHolder &neighborCellHolder) |
| | Helper function determining if the given neighbor is one of the best to be followed.
|
| |
template<class ACellHolder>
class Belle2::TrackingUtilities::CellularPathFollower< ACellHolder >
Implements to pick up of the highest value path in neighborhood Following high value paths can be done two ways.
First construct a single path that has the highest value of all. This carried out by follow single which uses the highest cell returned by the cellular automaton. Second construct all paths which are maximal. A maximal path means that there is no longer path including this path. If there are many disjoint paths this is the way to get them. However you most certainly pick up a lot of elements twice if there are many start culminating into a common long path. This is carried out recursively by followAll over the start cells marked with start flag.
Definition at line 37 of file CellularPathFollower.h.
◆ followAll()
template<class ACellHolder>
| static std::vector< Path< ACellHolder > > followAll |
( |
const std::vector< ACellHolder * > & | cellHolders, |
|
|
const std::vector< WeightedRelation< ACellHolder > > & | cellHolderRelations, |
|
|
Weight | minStateToFollow = -INFINITY ) |
|
inlinestatic |
Follow paths from all start cells marked with the start flag.
Definition at line 41 of file CellularPathFollower.h.
45 {
46 B2ASSERT("Expected the relations to be sorted",
47 std::is_sorted(cellHolderRelations.begin(), cellHolderRelations.end()));
48
49
50 std::vector<Path<ACellHolder> > paths;
51
52
53 Path<ACellHolder> path;
54
55 for (ACellHolder* cellHolder : cellHolders) {
56 const AutomatonCell& automatonCell = cellHolder->getAutomatonCell();
57
58 if (validStartCell(automatonCell, minStateToFollow)) {
59
60
61
62 path.clear();
63
64
65 path.push_back(cellHolder);
66
67
68 growAllPaths(path, cellHolderRelations, paths);
69 path.pop_back();
70 }
71 }
72 return paths;
73 }
◆ followSingle()
template<class ACellHolder>
| static Path< ACellHolder > followSingle |
( |
ACellHolder * | startCellHolder, |
|
|
const std::vector< WeightedRelation< ACellHolder > > & | cellHolderRelations, |
|
|
Weight | minStateToFollow = -INFINITY ) |
|
inlinestatic |
Follows a single maximal path starting with the given start cell.
If the start cell is nullptr or has a state lower than the minimum state to follow an empty vector is returned.
Definition at line 80 of file CellularPathFollower.h.
83 {
84 Path<ACellHolder> path;
85 if (not startCellHolder) return path;
86 const AutomatonCell& startCell = startCellHolder->getAutomatonCell();
87 if (not validStartCell(startCell, minStateToFollow)) return path;
88
89
90 path.reserve(20);
91
92
93 path.push_back(startCellHolder);
94 bool grew = true;
95 while (grew) {
96 grew = false;
97 ACellHolder* cellHolder = path.back();
98
99 auto continuations = asRange(std::equal_range(cellHolderRelations.begin(),
100 cellHolderRelations.end(),
101 cellHolder));
102
103 for (const WeightedRelation<ACellHolder>& relation : continuations) {
104
105 if (isHighestContinuation(relation)) {
106 ACellHolder* neighbor = relation.getTo();
107 path.push_back(neighbor);
108 grew = true;
109 break;
110 }
111 }
112 }
113 return path;
114 }
◆ growAllPaths()
template<class ACellHolder>
| static void growAllPaths |
( |
Path< ACellHolder > & | path, |
|
|
const std::vector< WeightedRelation< ACellHolder > > & | cellHolderRelations, |
|
|
std::vector< Path< ACellHolder > > & | paths ) |
|
inlinestaticprivate |
Helper function for recursively growing paths.
- Parameters
-
| [in] | path | Current path to be extended |
| [in] | cellHolderRelations | Considered relations to follow to extend the path |
| [out] | paths | Longest paths generated |
Definition at line 123 of file CellularPathFollower.h.
126 {
127 auto growPathByRelation = [&](const WeightedRelation<ACellHolder>& neighborRelation) {
128 if (!isHighestContinuation(neighborRelation)) return false;
129 ACellHolder* neighbor(neighborRelation.getTo());
130 path.push_back(neighbor);
131 growAllPaths(path, cellHolderRelations, paths);
132 path.pop_back();
133 return true;
134 };
135
136 ACellHolder* lastCellHolder = path.back();
137
138 auto continuations = asRange(std::equal_range(cellHolderRelations.begin(),
139 cellHolderRelations.end(),
140 lastCellHolder));
141 int nRelationsUsed = std::count_if(continuations.begin(),
142 continuations.end(),
143 growPathByRelation);
144
145 if (nRelationsUsed == 0) {
146
147 paths.push_back(path);
148 }
149 }
◆ isHighestContinuation() [1/2]
template<class ACellHolder>
| static bool isHighestContinuation |
( |
const ACellHolder & | cellHolder, |
|
|
Weight | relationWeight, |
|
|
const ACellHolder & | neighborCellHolder ) |
|
inlinestaticprivate |
Helper function determining if the given neighbor is one of the best to be followed.
Since this is an algebraic property no comparison to the other alternatives is necessary.
Definition at line 187 of file CellularPathFollower.h.
190 {
191 const AutomatonCell& automatonCell = cellHolder.getAutomatonCell();
192 const AutomatonCell& neighborAutomatonCell = neighborCellHolder.getAutomatonCell();
193
194 return not neighborAutomatonCell.hasCycleFlag() and not neighborAutomatonCell.hasMaskedFlag() and
195 (automatonCell.getCellState() ==
196 (neighborAutomatonCell.getCellState() + relationWeight + automatonCell.getCellWeight()));
197 }
◆ isHighestContinuation() [2/2]
template<class ACellHolder>
| static bool isHighestContinuation |
( |
const WeightedRelation< ACellHolder > & | relation | ) |
|
|
inlinestaticprivate |
Helper function determining if the given neighbor is one of the best to be followed.
Since this is an algebraic property on comparison to the other alternatives is necessary.
Definition at line 169 of file CellularPathFollower.h.
170 {
171 const ACellHolder* cellHolderPtr(relation.getFrom());
172 const ACellHolder* neighborCellHolderPtr(relation.getTo());
173
174 if (not cellHolderPtr or not neighborCellHolderPtr) return false;
175
176 const ACellHolder& cellHolder = *cellHolderPtr;
177 Weight relationWeight = relation.getWeight();
178 const ACellHolder& neighborCellHolder = *neighborCellHolderPtr;
179
180 return isHighestContinuation(cellHolder, relationWeight, neighborCellHolder);
181 }
◆ validStartCell()
template<class ACellHolder>
| static bool validStartCell |
( |
const AutomatonCell & | automatonCell, |
|
|
Weight | minStateToFollow ) |
|
inlinestaticprivate |
Helper function to determine, if the cell has all flags indicating to be a start cell and that its state exceeds the minimal requirement.
Definition at line 155 of file CellularPathFollower.h.
157 {
158 return
159 automatonCell.hasStartFlag() and
160 not automatonCell.hasMaskedFlag() and
161 not automatonCell.hasCycleFlag() and
162 minStateToFollow <= automatonCell.getCellState();
163 }
The documentation for this class was generated from the following file: