15template<
typename ValueType>
18 builder.setObservation(observation);
24template<
typename ValueType>
27 belief.
forEach([&address](
auto const&,
auto const& value) {
35template<
typename ValueType>
36class BeliefCollectorTest :
public ::testing::Test {
38 using Collector = BeliefCollector<Belief<ValueType>>;
40 static_assert(std::is_nothrow_move_constructible_v<Collector>);
41 static_assert(std::is_nothrow_move_assignable_v<Collector>);
42 static_assert(std::is_nothrow_move_constructible_v<Belief<ValueType>>);
43 static_assert(!std::is_copy_assignable_v<Belief<ValueType>>);
44 static_assert(!std::is_move_assignable_v<Belief<ValueType>>);
46 static void fill(Collector& collector, uint64_t count) {
47 for (uint64_t i = 0;
i <
count; ++
i) {
48 ASSERT_EQ(i, collector.addBelief(makeBelief<ValueType>(2 * i, 2 * (i % 7))));
52 static void checkLookups(Collector
const& collector, uint64_t count) {
53 EXPECT_EQ(count, collector.getNumberOfBeliefIds());
54 for (uint64_t i = 0;
i <
count; ++
i) {
55 auto const belief = makeBelief<ValueType>(2 * i, 2 * (i % 7));
56 EXPECT_TRUE(collector.containsId(i));
57 EXPECT_TRUE(collector.containsBelief(belief));
58 EXPECT_EQ(i, collector.getIdFromBelief(belief));
59 EXPECT_TRUE(belief == collector.getBeliefFromId(i));
64using BeliefValueTypes = ::testing::Types<double, storm::RationalNumber>;
67TYPED_TEST(BeliefCollectorTest, InternsBeliefs) {
68 typename TestFixture::Collector collector;
69 auto const belief = makeBelief<TypeParam>();
70 EXPECT_FALSE(collector.containsId(0));
71 EXPECT_FALSE(collector.containsBelief(belief));
74 EXPECT_EQ(0, collector.getIdOrAddBelief(makeBelief<TypeParam>()));
75 EXPECT_EQ(0, collector.getIdOrAddBelief(makeBelief<TypeParam>()));
76 EXPECT_EQ(1, collector.getNumberOfBeliefIds());
77 EXPECT_EQ(0, collector.getIdFromBelief(belief));
79 EXPECT_EQ(1, collector.getIdOrAddBelief(makeBelief<TypeParam>(0, 0, 0.25)));
80 EXPECT_EQ(2, collector.getIdOrAddBelief(makeBelief<TypeParam>(0, 8)));
81 EXPECT_EQ(2, collector.getIdOrAddBelief(makeBelief<TypeParam>(0, 8)));
82 EXPECT_FALSE(collector.isEqual(0, 1));
83 EXPECT_FALSE(collector.isEqual(0, 2));
84 EXPECT_TRUE(collector.isEqual(0, 0));
85 EXPECT_EQ(3, collector.getNumberOfBeliefIds());
86 EXPECT_FALSE(collector.containsId(3));
87 EXPECT_EQ(
InvalidBeliefId, collector.getIdOptional(makeBelief<TypeParam>(20, 0)));
88 EXPECT_EQ(
InvalidBeliefId, collector.getIdOptional(makeBelief<TypeParam>(0, 3)));
89 EXPECT_FALSE(collector.containsBelief(makeBelief<TypeParam>(0, 99)));
92TYPED_TEST(BeliefCollectorTest, MissingRequiredLookupThrowsStormException) {
93 typename TestFixture::Collector collector;
94 ASSERT_EQ(0, collector.addBelief(makeBelief<TypeParam>()));
95 auto const missingBelief = makeBelief<TypeParam>(20);
97 EXPECT_THROW(collector.getIdFromBelief(missingBelief), storm::exceptions::OutOfRangeException);
98 EXPECT_EQ(0, collector.getIdFromBelief(makeBelief<TypeParam>()));
101TYPED_TEST(BeliefCollectorTest, PreservesDistributionStorageThroughGrowth) {
102 typename TestFixture::Collector collector;
103 auto firstBelief = makeBelief<TypeParam>();
104 auto const* firstValue = firstValueAddress(firstBelief);
105 ASSERT_EQ(0, collector.addBelief(std::move(firstBelief)));
106 EXPECT_EQ(firstValue, firstValueAddress(collector.getBeliefFromId(0)));
108 constexpr uint64_t
count = 1024;
109 for (uint64_t i = 1;
i <
count; ++
i) {
110 ASSERT_EQ(i, collector.addBelief(makeBelief<TypeParam>(2 * i, 2 * (i % 7))));
112 EXPECT_EQ(firstValue, firstValueAddress(collector.getBeliefFromId(0)));
113 TestFixture::checkLookups(collector,
count);
114 EXPECT_EQ(0, collector.getIdOrAddBelief(makeBelief<TypeParam>()));
115 EXPECT_EQ(
count, collector.getNumberOfBeliefIds());
118TYPED_TEST(BeliefCollectorTest, CopiesUseIndependentStorage) {
119 using Collector =
typename TestFixture::Collector;
120 std::optional<Collector> copied;
121 constexpr uint64_t
count = 64;
124 TestFixture::fill(original,
count);
125 copied.emplace(original);
126 EXPECT_NE(firstValueAddress(original.getBeliefFromId(0)), firstValueAddress(copied->getBeliefFromId(0)));
127 original.addBelief(makeBelief<TypeParam>(10000, 20));
128 EXPECT_FALSE(copied->containsBelief(makeBelief<TypeParam>(10000, 20)));
130 TestFixture::checkLookups(*copied,
count);
131 EXPECT_EQ(
count, copied->addBelief(makeBelief<TypeParam>(10000, 20)));
132 EXPECT_EQ(
count, copied->getIdFromBelief(makeBelief<TypeParam>(10000, 20)));
135TYPED_TEST(BeliefCollectorTest, MovesPreserveIndex) {
136 using Collector =
typename TestFixture::Collector;
138 assigned.addBelief(makeBelief<TypeParam>(10000, 20));
139 constexpr uint64_t
count = 64;
142 TestFixture::fill(original,
count);
143 auto const* firstValue = firstValueAddress(original.getBeliefFromId(0));
144 Collector moved(std::move(original));
145 EXPECT_EQ(firstValue, firstValueAddress(moved.getBeliefFromId(0)));
146 TestFixture::checkLookups(moved,
count);
147 assigned = std::move(moved);
148 EXPECT_EQ(firstValue, firstValueAddress(assigned.getBeliefFromId(0)));
149 TestFixture::checkLookups(assigned,
count);
151 TestFixture::checkLookups(assigned,
count);
152 EXPECT_EQ(
count, assigned.addBelief(makeBelief<TypeParam>(10000, 20)));
153 EXPECT_EQ(
count, assigned.getIdFromBelief(makeBelief<TypeParam>(10000, 20)));
156TEST(BeliefCollectorNumericsTest, UsesExistingDoubleEquality) {
158 ASSERT_EQ(0, collector.
addBelief(makeBelief<double>()));
159 auto const equivalent = makeBelief<double>(0, 0, 0.5 + 1e-15);
162 EXPECT_EQ(0, collector.
getIdOrAddBelief(makeBelief<double>(0, 0, 0.5 + 1e-15)));
163 EXPECT_EQ(1, collector.
getIdOrAddBelief(makeBelief<double>(0, 0, 0.5 + 1e-12)));
TEST(RegionConstraintCheckerTest, AffineConstraintHoldsThroughout)
Interns beliefs and assigns them consecutive identifiers.
BeliefType const & getBeliefFromId(BeliefId const &id) const
BeliefId addBelief(BeliefType &&inputBelief)
Adds a fresh belief and returns its ID.
BeliefId getNumberOfBeliefIds() const
BeliefId getIdOrAddBelief(BeliefType &&belief)
Checks if the given belief has already been collected before.
BeliefId getIdFromBelief(BeliefType const &belief) const
Represents a belief of a Pomdp, i.e.
void forEach(FunctionType const &f) const
SFTBDDChecker::ValueType ValueType
constexpr BeliefId InvalidBeliefId
uint64_t BeliefStateType
Shared identifiers and sparse-container types used by the belief subsystem.
uint32_t BeliefObservationType
std::pair< storm::RationalNumber, storm::RationalNumber > count(std::vector< storm::storage::BitVector > const &origSets, std::vector< storm::storage::BitVector > const &intersects, std::vector< storm::storage::BitVector > const &intersectsInfo, storm::RationalNumber val, bool plus, uint64_t remdepth)
TargetType convertNumber(SourceType const &number)
TYPED_TEST(GraphTestAR, SymbolicProb01StochasticGameDieSmall)
TYPED_TEST_SUITE(GraphTestAR, TestingTypes,)