AI 24/25 Project Software
Documentation for the AI 24/25 course programming project software
Loading...
Searching...
No Matches
mdp.h
1#ifndef PROBFD_MDP_H
2#define PROBFD_MDP_H
3
4#include "probfd/cost_function.h" // IWYU pragma: export
5#include "probfd/state_space.h" // IWYU pragma: export
6
7namespace probfd {
8
12template <typename State, typename Action>
13class MDP
14 : public StateSpace<State, Action>
15 , public CostFunction<State, Action> {
20 virtual void print_statistics() const {}
21};
22
26template <typename State, typename Action>
27class SimpleMDP : public MDP<State, Action> {
28public:
30 {
31 return is_goal(state) ? TerminationInfo::from_goal()
32 : TerminationInfo::from_non_goal(
33 get_non_goal_termination_cost());
34 }
35
36 virtual bool is_goal(param_type<State> state) const = 0;
37 [[nodiscard]]
38 virtual value_t get_non_goal_termination_cost() const = 0;
39};
40
47template <typename State, typename Action>
48struct CompositeMDP : public MDP<State, Action> {
49 using TransitionType = Transition<Action>;
50
51 StateSpace<State, Action>& state_space;
52 CostFunction<State, Action>& cost_function;
53
55 StateSpace<State, Action>& state_space,
56 CostFunction<State, Action>& cost_function)
57 : state_space(state_space)
58 , cost_function(cost_function)
59 {
60 }
61
66 {
67 return state_space.get_state_id(state);
68 }
69
73 State get_state(StateID state_id) final
74 {
75 return state_space.get_state(state_id);
76 }
77
83 std::vector<Action>& result) final
84 {
85 return state_space.generate_applicable_actions(state, result);
86 }
87
93 param_type<Action> action,
94 Distribution<StateID>& result) final
95 {
96 return state_space.generate_action_transitions(state, action, result);
97 }
98
104 param_type<State> state,
105 std::vector<Action>& aops,
106 std::vector<Distribution<StateID>>& successors) final
107 {
108 return state_space.generate_all_transitions(state, aops, successors);
109 }
110
112 param_type<State> state,
113 std::vector<TransitionType>& transitions) final
114 {
115 return state_space.generate_all_transitions(state, transitions);
116 }
117
125 {
126 return cost_function.get_termination_info(state);
127 }
128
133 {
134 return cost_function.get_action_cost(action);
135 }
136};
137
138} // namespace probfd
139
140#endif
The interface specifying action and state termination costs, aswell as the goal states of a state spa...
Definition fdr_types.h:14
virtual value_t get_action_cost(param_type< Action > action)=0
Gets the cost of an action.
virtual TerminationInfo get_termination_info(param_type< State > state)=0
Returns the cost to terminate in a given state and checks whether a state is a goal.
A convenience class that represents a finite probability distribution.
Definition task_state_space.h:27
Basic interface for MDPs.
Definition mdp_algorithm.h:14
Basic interface for MDPs.
Definition mdp.h:27
TerminationInfo get_termination_info(param_type< State > state) final
Returns the cost to terminate in a given state and checks whether a state is a goal.
Definition mdp.h:29
An interface representing a Markov Decision Process (MDP) without objective function.
Definition state_space.h:44
virtual void generate_all_transitions(param_type< State > state, std::vector< Action > &aops, std::vector< Distribution< StateID > > &successors)=0
Generates all applicable actions and their corresponding successor distributions for a given state.
virtual State get_state(StateID state_id)=0
Get the state mapped to a given state ID.
virtual void generate_applicable_actions(param_type< State > state, std::vector< Action > &result)=0
Generates the applicable actions of the state.
virtual StateID get_state_id(param_type< State > state)=0
Get the state ID for a given state.
virtual void generate_action_transitions(param_type< State > state, param_type< Action > action, Distribution< StateID > &result)=0
Generates the successor distribution for a given state and action.
Specifies the termination cost and goal status of a state.
Definition cost_function.h:13
The top-level namespace of probabilistic Fast Downward.
Definition command_line.h:8
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
Composes a state space and a cost function to an MDP.
Definition mdp.h:48
State get_state(StateID state_id) final
Get the state mapped to a given state ID.
Definition mdp.h:73
virtual void generate_all_transitions(param_type< State > state, std::vector< TransitionType > &transitions) final
Generates all applicable actions and their corresponding successor distributions for a given state.
Definition mdp.h:111
value_t get_action_cost(param_type< Action > action) final
Gets the action cost of a state-action.
Definition mdp.h:132
StateID get_state_id(param_type< State > state) final
Get the state ID for a given state.
Definition mdp.h:65
void generate_action_transitions(param_type< State > state, param_type< Action > action, Distribution< StateID > &result) final
Generates the successor distribution for a given state and action.
Definition mdp.h:91
void generate_applicable_actions(param_type< State > state, std::vector< Action > &result) final
Generates the applicable actions of the state.
Definition mdp.h:81
TerminationInfo get_termination_info(param_type< State > state) final
Returns the cost to terminate in a given state and checks whether a state is a goal.
Definition mdp.h:124
void generate_all_transitions(param_type< State > state, std::vector< Action > &aops, std::vector< Distribution< StateID > > &successors) final
Generates all applicable actions and their corresponding successor distributions for a given state.
Definition mdp.h:103
A StateID represents a state within a StateIDMap. Just like Fast Downward's StateID type,...
Definition types.h:22