AI 24/25 Project Software
Documentation for the AI 24/25 course programming project software
Loading...
Searching...
No Matches
sampling.h
1#ifndef TASK_UTILS_SAMPLING_H
2#define TASK_UTILS_SAMPLING_H
3
4#include "downward/task_proxy.h"
5
6#include <functional>
7#include <memory>
8
9class State;
10
11namespace successor_generator {
12class SuccessorGenerator;
13}
14
15namespace utils {
16class RandomNumberGenerator;
17}
18
19using DeadEndDetector = std::function<bool(State)>;
20
21namespace sampling {
22/*
23 Sample states with random walks.
24*/
25class RandomWalkSampler {
26 const OperatorsProxy operators;
27 const std::unique_ptr<successor_generator::SuccessorGenerator>
28 successor_generator;
29 const State initial_state;
30 const double average_operator_costs;
31 utils::RandomNumberGenerator& rng;
32
33public:
34 RandomWalkSampler(
35 const TaskProxy& task_proxy,
36 utils::RandomNumberGenerator& rng);
37 ~RandomWalkSampler();
38
39 /*
40 Perform a single random walk and return the last visited state.
41
42 The walk length is taken from a binomial distribution centered around the
43 estimated plan length, which is computed as the ratio of the h value of
44 the initial state divided by the average operator costs. Whenever a dead
45 end is detected or a state has no successors, restart from the initial
46 state. The function 'is_terminal' should return whether a given state is
47 a dead end. If omitted, no dead end detection is performed. The 'init_h'
48 value should be an estimate of the solution cost.
49 */
50 State sample_state(
51 int init_h,
52 const DeadEndDetector& is_dead_end = [](const State&) {
53 return false;
54 }) const;
55};
56} // namespace sampling
57
58#endif