Belle II Software  release-08-01-10
CellularAutomaton< ACellHolder > Class Template Reference

Implements the weighted cellular automaton algorithm. More...

#include <CellularAutomaton.h>

Classes

class  CycleException
 Type for the very basic exception signal used in the detection of cycles. More...
 

Public Member Functions

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. More...
 

Private Member Functions

Weight getFinalCellState (ACellHolder *cellHolder, const std::vector< WeightedRelation< ACellHolder >> &cellHolderRelations) const
 Gets the cell state of the cell holder. More...
 
Weight updateState (ACellHolder *cellHolder, const std::vector< WeightedRelation< ACellHolder >> &cellHolderRelations) const
 Updates the state of a cell considering all continuations recursively.
 
void prepareCellFlags (const std::vector< ACellHolder * > &cellHolders) const
 Helper function to prepare the stats. More...
 

Detailed Description

template<class ACellHolder>
class Belle2::TrackFindingCDC::CellularAutomaton< ACellHolder >

Implements the weighted cellular automaton algorithm.

Definition at line 30 of file CellularAutomaton.h.

Member Function Documentation

◆ applyTo()

ACellHolder* applyTo ( const std::vector< ACellHolder * > &  cellHolders,
const std::vector< WeightedRelation< ACellHolder >> &  cellHolderRelations 
) const
inline

Applies the cellular automaton to the collection of cells and its neighborhood.

Parameters
cellHoldersThe range based iterable containing the cells.
cellHolderRelationsThe weighted relations between the cells.
Returns
The cell holder with the highest cell state found.

Definition at line 43 of file CellularAutomaton.h.

45  {
46  B2ASSERT("Expected the relations to be sorted",
47  std::is_sorted(cellHolderRelations.begin(), cellHolderRelations.end()));
48 
49  // Set all cell states to -inf and the non permanent flags to unset.
50  prepareCellFlags(cellHolders);
51 
52  for (ACellHolder* cellHolder : cellHolders) {
53  AutomatonCell& cell = cellHolder->getAutomatonCell();
54  if (cell.hasMaskedFlag()) continue;
55  if (cell.hasCycleFlag()) continue;
56 
57  if (not cell.hasAssignedFlag()) {
58  // Mark this cell as a start point of a long path since we encountered it in
59  // at the top level of the recursion.
60  cell.setStartFlag();
61  // The flag will be unset when it appears on the _to_ side of a relation.
62  }
63 
64  try {
65  // Assignes flags and the cell state
66  getFinalCellState(cellHolder, cellHolderRelations);
67  } catch (CycleException) {
68  // TODO: Come up with some handeling for cycles.
69  // For now we continue to look for long paths in the graph
70  // hoping to find a part that does not enter the cycle.
71 
72  // Thoughts:
73  // If there is a single cycle in the graph we might be able to break it at some point.
74  // However, if there are multiple cycles intertwined things get very tricky.
75  // But can we actually distinguish the two situations?
76  }
77  }
78 
79  auto lessStartCellState = [](ACellHolder * lhs, ACellHolder * rhs) {
80  const AutomatonCell& lhsCell = lhs->getAutomatonCell();
81  const AutomatonCell& rhsCell = rhs->getAutomatonCell();
82  return (std::make_pair(lhsCell.hasStartFlag(), lhsCell.getCellState()) <
83  std::make_pair(rhsCell.hasStartFlag(), rhsCell.getCellState()));
84  };
85 
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;
91  }
Weight getFinalCellState(ACellHolder *cellHolder, const std::vector< WeightedRelation< ACellHolder >> &cellHolderRelations) const
Gets the cell state of the cell holder.
void prepareCellFlags(const std::vector< ACellHolder * > &cellHolders) const
Helper function to prepare the stats.

◆ getFinalCellState()

Weight getFinalCellState ( ACellHolder *  cellHolder,
const std::vector< WeightedRelation< ACellHolder >> &  cellHolderRelations 
) const
inlineprivate

Gets the cell state of the cell holder.

Determines it if necessary traversing the graph. Throws CycleException if it encounters a cycle in the graph.

Definition at line 99 of file CellularAutomaton.h.

◆ prepareCellFlags()

void prepareCellFlags ( const std::vector< ACellHolder * > &  cellHolders) const
inlineprivate

Helper function to prepare the stats.

Clears all temporary cell flags and sets the cell state to minus infinity.

Definition at line 201 of file CellularAutomaton.h.


The documentation for this class was generated from the following file: