AI 24/25 Project Software
Documentation for the AI 24/25 course programming project software
Loading...
Searching...
No Matches
i2dual.h
1#ifndef PROBFD_ALGORITHMS_I2DUAL_H
2#define PROBFD_ALGORITHMS_I2DUAL_H
3
4#include "probfd/storage/per_state_storage.h"
5
6#include "probfd/distribution.h"
7#include "probfd/fdr_types.h"
8#include "probfd/mdp_algorithm.h"
9#include "probfd/task_proxy.h"
10#include "probfd/value_type.h"
11
12#include "downward/lp/lp_solver.h"
13
14#include "downward/utils/timer.h"
15
16#include <cstddef>
17#include <iosfwd>
18#include <limits>
19#include <memory>
20#include <vector>
21
22namespace probfd {
23class ProgressReport;
24}
25
26namespace probfd::algorithms::i2dual {
27
28class I2Dual : public MDPAlgorithm<State, OperatorID> {
29 struct IDualData;
30
31 struct Statistics {
32 utils::Timer idual_timer = utils::Timer(true);
33 utils::Timer lp_solver_timer = utils::Timer(true);
34 utils::Timer hpom_timer = utils::Timer(true);
35
36 unsigned long long iterations = 0;
37 unsigned long long expansions = 0;
38 unsigned long long open_states = 0;
39 unsigned long long num_lp_vars = 0;
40 unsigned long long num_lp_constraints = 0;
41 unsigned long long hpom_num_vars = 0;
42 unsigned long long hpom_num_constraints = 0;
43
44 void print(std::ostream& out) const;
45 };
46
47 ProbabilisticTaskProxy task_proxy_;
48 std::shared_ptr<FDRCostFunction> task_cost_function_;
49
50 const bool hpom_enabled_;
51 const bool incremental_hpom_updates_;
52
53 lp::LPSolver lp_solver_;
54
55 size_t next_lp_var_ = 0;
56 size_t next_lp_constr_id_ = 0;
57
58 bool hpom_initialized_ = false;
59 std::vector<int> offset_;
60 named_vector::NamedVector<lp::LPConstraint> hpom_constraints_;
61
62 Statistics statistics_;
63
64 value_t objective_;
65
66 std::vector<OperatorID> aops_;
67 Distribution<StateID> succs_;
68
69public:
70 I2Dual(
71 std::shared_ptr<ProbabilisticTask> task,
72 std::shared_ptr<FDRCostFunction> task_cost_function,
73 bool hpom_enabled,
74 bool incremental_updates,
75 lp::LPSolverType solver_type);
76
77 void print_statistics(std::ostream& out) const override;
78
79 Interval solve(
80 FDRMDP& mdp,
81 FDREvaluator& heuristic,
82 const State& initial_state,
83 ProgressReport progress,
84 double max_time) override;
85
86 std::unique_ptr<PolicyType> compute_policy(
87 FDRMDP& mdp,
88 EvaluatorType& heuristic,
89 const State& initial_state,
90 ProgressReport progress,
91 double max_time) override;
92
93private:
94 bool evaluate_state(
95 FDRMDP& mdp,
96 FDREvaluator& heuristic,
97 const State& state,
98 IDualData& data);
99
100 void prepare_lp();
101
102 void prepare_hpom(lp::LinearProgram& lp);
103
104 void update_hpom_constraints_expanded(
105 FDRMDP& mdp,
106 storage::PerStateStorage<IDualData>& data,
107 const std::vector<StateID>& expanded);
108
109 void update_hpom_constraints_frontier(
110 FDRMDP& mdp,
111 storage::PerStateStorage<IDualData>& data,
112 const std::vector<StateID>& frontier,
113 unsigned start);
114
115 void remove_fringe_state_from_hpom(
116 const State& state,
117 const IDualData& data,
118 named_vector::NamedVector<lp::LPConstraint>& constraints) const;
119
120 void add_fringe_state_to_hpom(
121 const State& state,
122 const IDualData& data,
123 named_vector::NamedVector<lp::LPConstraint>& constraints) const;
124};
125
126} // namespace probfd::algorithms::i2dual
127
128#endif // PROBFD_ALGORITHMS_I2DUAL_H
The top-level namespace of probabilistic Fast Downward.
Definition command_line.h:8
MDP< State, OperatorID > FDRMDP
Type alias for MDPs with states in FDR.
Definition fdr_types.h:42
Evaluator< State > FDREvaluator
Type alias for evaluators for states in FDR.
Definition fdr_types.h:48
double value_t
Typedef for the state value type.
Definition aliases.h:7