Belle II Software development
CellularAutomaton.h
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8#pragma once
9
10#include <tracking/trackFindingVXD/algorithms/TrackerAlgorithmBase.h>
11
12namespace Belle2 {
20 template<class ContainerType, class ValidatorType>
21 class CellularAutomaton final : public TrackerAlgorithmBase<ContainerType, ValidatorType> {
22 public:
25
26
29
30
32 unsigned int stopInRound = BaseClass::m_validator.nMaxIterations + 2;
33
35 // TODO: Check where the -1 is returned, for bad cases as described above.
36 int apply(ContainerType& aNetworkContainer) override final
37 {
43 unsigned int activeCells = 1, // is set 1 because of following while loop.
44 caRound = 1,
45 goodNeighbours = 0,
46 highestCellState = 0;
47
48 // each iteration of following while loop is one CA-time-step
49 while (activeCells != 0 and caRound < stopInRound) {
50 activeCells = 0;
51
53 // compare cells with inner neighbours:
54 for (auto* aNode : aNetworkContainer) {
55 auto& currentCell = aNode->getMetaInfo();
56 if (currentCell.isActivated() == false) { continue; }
57 goodNeighbours = 0;
58
59 for (auto* aNeighbour : aNode->getInnerNodes()) {
60 // skip if neighbour has not the same state (NOTE if one wants to improve the versatility of the code,
61 // this should actually become a member of the cell-class, which then can add some extra
62 // stuff like checking for loops.
63 if (currentCell != aNeighbour->getMetaInfo()) continue;
64
65 goodNeighbours++;
66 }
67 if (goodNeighbours != 0) {
68 currentCell.setStateUpgrade(true);
69 activeCells++;
70 }
71 }
72
74 for (auto* aNode : aNetworkContainer) {
75 auto& currentCell = aNode->getMetaInfo();
76 if (currentCell.isActivated() == false or currentCell.isUpgradeAllowed() == false) { continue; }
77
78 currentCell.setStateUpgrade(false);
79 currentCell.increaseState();
80 if (currentCell.getState() > highestCellState) { highestCellState = currentCell.getState(); }
81 }
82
84 if (BaseClass::m_validator.isValidRound(caRound) == false) {
85 break;
86 }
87
88 caRound++;
89 } // CA main-loop
90
91 return caRound;
92 }
93
94
98 unsigned int findSeeds(ContainerType& aNetworkContainer, bool strictSeeding = false) override final
99 {
100 unsigned int nSeeds = 0;
101 for (auto* aNode : aNetworkContainer) {
102 if (strictSeeding && !(aNode->getOuterNodes().empty())) continue;
103
104 if (BaseClass::m_validator.checkSeed(aNode->getMetaInfo()) == true) {
105 aNode->getMetaInfo().setSeed(true);
106 nSeeds++;
107 }
108 }
109 return nSeeds;
110 }
111 };
113}
The CellularAutomaton class This class serves as a functor for the algorithm itself.
unsigned int stopInRound
aborts CA after stopInRound iterations - mainly for debugging purposes:
int apply(ContainerType &aNetworkContainer) override final
actual algorithm of Cellular Automaton, returns number of rounds needed to finish or -1 if CA was abo...
unsigned int findSeeds(ContainerType &aNetworkContainer, bool strictSeeding=false) override final
checks network given for seeds, returns number of seeds found (if strictSeeding is set to true,...
base class for TrackerAlgorithms. shall allow a common base for algorithms like the cellular automato...
ValidatorType m_validator
something which checks the quality of the test so far (will be applied by the apply-function
Abstract base class for different kinds of events.