10#include <tracking/trackFindingCDC/ca/AutomatonCell.h>
11#include <tracking/trackFindingCDC/numerics/Weight.h>
13#include <tracking/trackFindingCDC/utilities/WeightedRelation.h>
15#include <framework/logging/Logger.h>
25 namespace TrackFindingCDC {
29 template<
class ACellHolder>
43 ACellHolder*
applyTo(
const std::vector<ACellHolder*>& cellHolders,
46 B2ASSERT(
"Expected the relations to be sorted",
47 std::is_sorted(cellHolderRelations.begin(), cellHolderRelations.end()));
52 for (ACellHolder* cellHolder : cellHolders) {
79 auto lessStartCellState = [](ACellHolder * lhs, ACellHolder * rhs) {
86 auto itStartCellHolder =
87 std::max_element(cellHolders.begin(), cellHolders.end(), lessStartCellState);
88 if (itStartCellHolder == cellHolders.end())
return nullptr;
89 if (not(*itStartCellHolder)->getAutomatonCell().hasStartFlag())
return nullptr;
90 return *itStartCellHolder;
106 B2DEBUG(25,
"Cycle detected");
117 Weight finalCellState =
updateState(cellHolder, cellHolderRelations);
121 return finalCellState;
139 Weight maxStateWithContinuation = NAN;
142 bool isPriorityPath =
false;
144 auto continuations = asRange(
145 std::equal_range(cellHolderRelations.begin(), cellHolderRelations.end(), cellHolder));
150 ACellHolder* neighborCellHolder = relation.getTo();
153 if (not neighborCellHolder)
continue;
155 AutomatonCell& neighborCell = neighborCellHolder->getAutomatonCell();
163 Weight neighborCellState =
getFinalCellState(neighborCellHolder, cellHolderRelations);
166 Weight stateWithContinuation = neighborCellState + relation.getWeight();
169 if (std::isnan(maxStateWithContinuation) or maxStateWithContinuation < stateWithContinuation) {
170 maxStateWithContinuation = stateWithContinuation;
177 if (std::isnan(maxStateWithContinuation)) {
179 maxStateWithContinuation = 0;
203 for (ACellHolder* cellHolder : cellHolders) {
Cell used by the cellular automata.
bool hasAssignedFlag() const
Gets the current state of the already assigned marker flag.
bool hasCycleFlag() const
Gets the current state of the cycle marker flag.
void setCycleFlag(bool setTo=true)
Sets the cycle marker flag to the given value. Default value true.
bool hasStartFlag() const
Gets the current state of the start marker flag.
void unsetStartFlag()
Resets the start marker flag to false.
void unsetTemporaryFlags()
Resets the assigned, start and cycle marker flag.
bool hasMaskedFlag() const
Gets the current state of the masked marker flag.
Weight getCellWeight() const
Getter for the cell weight.
Weight getCellState() const
Getter for the cell state.
void setAssignedFlag(bool setTo=true)
Sets the already assigned marker flag to the given value. Default value true.
void unsetCycleFlag()
Resets the cycle marker flag to false.
void setCellState(Weight state)
Setter for the cell state.
bool hasPriorityPathFlag() const
Gets the current state of the priority path marker flag.
void setStartFlag(bool setTo=true)
Sets the start marker flag to the given value. Default value true.
bool hasPriorityFlag() const
Gets the current state of the do not use flag marker flag.
void setPriorityPathFlag(bool setTo=true)
Sets the priority path marker flag to the given value. Default value true.
Type for the very basic exception signal used in the detection of cycles.
Implements the weighted cellular automaton algorithm.
Weight updateState(ACellHolder *cellHolder, const std::vector< WeightedRelation< ACellHolder > > &cellHolderRelations) const
Updates the state of a cell considering all continuations recursively.
Weight getFinalCellState(ACellHolder *cellHolder, const std::vector< WeightedRelation< ACellHolder > > &cellHolderRelations) const
Gets the cell state of the cell holder.
ACellHolder * applyTo(const std::vector< ACellHolder * > &cellHolders, const std::vector< WeightedRelation< ACellHolder > > &cellHolderRelations) const
Applies the cellular automaton to the collection of cells and its neighborhood.
void prepareCellFlags(const std::vector< ACellHolder * > &cellHolders) const
Helper function to prepare the stats.
Type for two related objects with a weight.
Abstract base class for different kinds of events.