AI 24/25 Project Software
Documentation for the AI 24/25 course programming project software
Loading...
Searching...
No Matches
vdiff_successor_sampler_impl.h
1#include "probfd/successor_samplers/vdiff_successor_sampler.h"
2
3#include "probfd/algorithms/state_properties.h"
4
5#include "probfd/interval.h"
6
7#include "downward/utils/rng.h"
8
10
11template <typename Action>
12VDiffSuccessorSampler<Action>::VDiffSuccessorSampler(
13 int random_seed,
14 bool prefer_large_gaps)
15 : rng_(std::make_shared<utils::RandomNumberGenerator>(random_seed))
16 , prefer_large_gaps_(prefer_large_gaps)
17{
18}
19
20template <typename Action>
21VDiffSuccessorSampler<Action>::VDiffSuccessorSampler(
22 std::shared_ptr<utils::RandomNumberGenerator> rng,
23 bool prefer_large_gaps)
24 : rng_(std::move(rng))
25 , prefer_large_gaps_(prefer_large_gaps)
26{
27}
28
29template <typename Action>
30StateID VDiffSuccessorSampler<Action>::sample(
31 StateID,
32 Action,
33 const Distribution<StateID>& successors,
34 algorithms::StateProperties& properties)
35{
36 biased_.clear();
37
38 value_t sum = 0;
39 for (const auto& [item, probability] : successors) {
40 const value_t error = properties.lookup_bounds(item).length();
41 const value_t p =
42 probability * (prefer_large_gaps_ ? error : (1_vt - error));
43 if (p > 0_vt) {
44 sum += p;
45 biased_.add_probability(item, p);
46 }
47 }
48 if (biased_.empty()) {
49 return successors.sample(*rng_)->item;
50 }
51 biased_.normalize(1_vt / sum);
52 return biased_.sample(*rng_)->item;
53}
54
55} // namespace probfd::successor_samplers
This namespace contains implementations of transition successor samplers.
Definition arbitrary_sampler.h:7
double value_t
Typedef for the state value type.
Definition aliases.h:7
STL namespace.