AI 24/25 Project Software
Documentation for the AI 24/25 course programming project software
Loading...
Searching...
No Matches
idual.h
1#ifndef PROBFD_ALGORITHMS_IDUAL_H
2#define PROBFD_ALGORITHMS_IDUAL_H
3
4#include "probfd/mdp_algorithm.h"
5
6#include "probfd/storage/per_state_storage.h"
7
8#include "probfd/progress_report.h"
9
10#include "downward/lp/lp_solver.h"
11
12#include <limits>
13#include <set>
14#include <vector>
15
16// Forward Declarations
17namespace utils {
18class CountdownTimer;
19}
20
23
27struct Statistics {
28 unsigned long long iterations = 0;
29 unsigned long long expansions = 0;
30 unsigned long long open = 0;
31 unsigned long long lp_variables = 0;
32 unsigned long long lp_constraints = 0;
33
34 void print(std::ostream& out) const;
35};
36
37struct PerStateInfo {
38 enum { NEW, OPEN, CLOSED, TERMINAL };
39 unsigned var_idx = std::numeric_limits<unsigned>::max();
40 unsigned constraints_idx = std::numeric_limits<unsigned>::max();
41 uint8_t status = NEW;
42};
43
44struct FrontierStateInfo {
45 std::vector<unsigned> incoming;
46};
47
48class ValueGroup {
49public:
50 value_t operator[](unsigned i) const { return values_[i]; }
51
52 unsigned get_id(value_t val);
53
54private:
55 struct Comparator {
56 const std::vector<value_t>& values;
57
58 bool operator()(unsigned x, unsigned y) const
59 {
60 return values[x] < values[y];
61 }
62 };
63
64 std::vector<value_t> values_;
65 std::set<unsigned, Comparator> indices_ =
66 std::set<unsigned, Comparator>(Comparator{values_});
67};
68
75template <typename State, typename Action>
76class IDual : public MDPAlgorithm<State, Action> {
77 using Base = typename IDual::MDPAlgorithm;
78
79 using MDPType = typename Base::MDPType;
80 using EvaluatorType = typename Base::EvaluatorType;
81 using PolicyType = typename Base::PolicyType;
82
83 lp::LPSolver lp_solver_;
84 storage::PerStateStorage<PerStateInfo> state_infos_;
85 ValueGroup terminals_;
86
87 Statistics statistics_;
88
89public:
90 explicit IDual(lp::LPSolverType solver_type);
91
92 Interval solve(
93 MDPType& mdp,
94 EvaluatorType& heuristic,
95 param_type<State> initial_state,
96 ProgressReport progress,
97 double max_time) override;
98
99 std::unique_ptr<PolicyType> compute_policy(
100 MDPType& mdp,
101 EvaluatorType& heuristic,
102 param_type<State> initial_state,
103 ProgressReport progress,
104 double max_time) override;
105
106private:
107 Interval solve(
108 MDPType& mdp,
109 EvaluatorType& heuristic,
110 param_type<State> initial_state,
111 ProgressReport progress,
112 double max_time,
113 std::vector<double>& primal_solution,
114 std::vector<double>& dual_solution);
115};
116
117} // namespace probfd::algorithms::idual
118
119#define GUARD_INCLUDE_PROBFD_ALGORITHMS_IDUAL_H
120#include "probfd/algorithms/idual_impl.h"
121#undef GUARD_INCLUDE_PROBFD_ALGORITHMS_IDUAL_H
122
123#endif // PROBFD_ALGORITHMS_IDUAL_H
Interface for MDP algorithm implementations.
Definition mdp_algorithm.h:29
A registry for print functions related to search progress.
Definition progress_report.h:33
Implementation of the I-Dual algorithm trevizan:etal:ijcai-17 .
Definition idual.h:76
Namespace dedicated to the i-dual MDP algorithm.
Definition idual.h:22
double value_t
Typedef for the state value type.
Definition aliases.h:7
typename std::conditional_t< is_cheap_to_copy_v< T >, T, const T & > param_type
Alias template defining the best way to pass a parameter of a given type.
Definition type_traits.h:25
Represents a closed interval over the extended reals as a pair of lower and upper bound.
Definition interval.h:12
I-Dual algorithm statistics.
Definition idual.h:27