9#include <gtest/gtest.h>
10#include <tracking/trackFindingCDC/findlets/generic/TreeTraversal.h>
11#include <tracking/trackFindingCDC/findlets/generic/WeightedTreeTraversal.h>
13#include <tracking/trackFindingCDC/findlets/base/Findlet.h>
15#include <tracking/trackFindingCDC/numerics/Weight.h>
16#include <tracking/trackFindingCDC/numerics/WithWeight.h>
18#include <tracking/trackFindingCDC/utilities/Functional.h>
19#include <tracking/trackFindingCDC/utilities/Algorithms.h>
24using namespace TrackFindingCDC;
28 using Result = std::vector<const int*>;
30 class AcceptAll :
public Findlet<const int* const, int*> {
32 void apply(
const std::vector<const int*>& currentPath __attribute__((unused)),
33 std::vector<int*>& nextStates __attribute__((unused)))
override
39 class AcceptHighWeight :
public Findlet<const int* const, WithWeight<int*> > {
41 void apply(
const std::vector<const int*>& currentPath __attribute__((unused)),
45 erase_remove_if(nextStates,
GetWeight() < 0.5);
51TEST(TrackFindingCDCTest, Findlet_generic_TreeTraversal)
56 std::vector<int> states({1, 2, 3});
59 std::vector<Relation<int> > stateRelations;
60 stateRelations.push_back({&states[1], &states[2]});
61 stateRelations.push_back({&states[0], &states[2]});
62 stateRelations.push_back({&states[0], &states[1]});
63 std::sort(stateRelations.begin(), stateRelations.end());
66 std::vector<const int*> seedStates;
67 seedStates.push_back(&states[0]);
70 std::vector<std::vector<const int*>> results;
71 testTreeTraversal.
apply(seedStates, stateRelations, results);
73 ASSERT_EQ(2, results.size());
75 ASSERT_EQ(3, results[0].size());
76 EXPECT_EQ(1, *results[0][0]);
77 EXPECT_EQ(2, *results[0][1]);
78 EXPECT_EQ(3, *results[0][2]);
80 ASSERT_EQ(2, results[1].size());
81 EXPECT_EQ(1, *results[1][0]);
82 EXPECT_EQ(3, *results[1][1]);
85TEST(TrackFindingCDCTest, Findlet_generic_WeightedTreeTraversal)
90 std::vector<int> states({1, 2, 3});
93 std::vector<WeightedRelation<int> > stateRelations;
94 stateRelations.push_back({&states[1], 0.1, &states[2]});
95 stateRelations.push_back({&states[0], 1, &states[2]});
96 stateRelations.push_back({&states[0], 1, &states[1]});
97 std::sort(stateRelations.begin(), stateRelations.end());
100 std::vector<const int*> seedStates;
101 seedStates.push_back(&states[0]);
104 std::vector<std::vector<const int*>> results;
105 testWeightedTreeTraversal.
apply(seedStates, stateRelations, results);
107 ASSERT_EQ(2, results.size());
109 ASSERT_EQ(2, results[0].size());
110 EXPECT_EQ(1, *results[0][0]);
111 EXPECT_EQ(2, *results[0][1]);
113 ASSERT_EQ(2, results[1].size());
114 EXPECT_EQ(1, *results[1][0]);
115 EXPECT_EQ(3, *results[1][1]);
Interface for a minimal algorithm part that wants to expose some parameters to a module.
virtual void apply(ToVector< AIOTypes > &... ioVectors)=0
Main function executing the algorithm.
General implementation of a tree search algorithm using a given classes as state and results and one ...
void apply(const std::vector< const AState * > &seededStates, const std::vector< Relation< AState > > &stateRelations, std::vector< AResult > &results) override
Main function of this findlet: traverse a tree starting from a given seed states.
General implementation of a tree search algorithm using a given classes as state and results and one ...
void apply(const std::vector< const AState * > &seededStates, const std::vector< WeightedRelation< AState > > &stateRelations, std::vector< AResult > &results) override
Main function of this findlet: traverse a tree starting from a given seed states.
A mixin class to attach a weight to an object.
Abstract base class for different kinds of events.
Generic functor to get the weight from an object.