AI 24/25 Project Software
Documentation for the AI 24/25 course programming project software
Loading...
Searching...
No Matches
cost_function.h
1#ifndef PROBFD_COST_FUNCTION_H
2#define PROBFD_COST_FUNCTION_H
3
4#include "probfd/type_traits.h"
5#include "probfd/types.h"
6#include "probfd/value_type.h"
7
8namespace probfd {
9
14 bool is_goal_;
15 value_t terminal_cost_;
16
17 TerminationInfo(bool is_goal, value_t terminal_cost)
18 : is_goal_(is_goal)
19 , terminal_cost_(terminal_cost)
20 {
21 }
22
23public:
24 TerminationInfo() = default;
25
26 static TerminationInfo from_goal() { return {true, 0_vt}; }
27 static TerminationInfo from_non_goal(value_t value)
28 {
29 return {false, value};
30 }
31
33 [[nodiscard]]
34 bool is_goal_state() const
35 {
36 return is_goal_;
37 }
38
40 [[nodiscard]]
42 {
43 return terminal_cost_;
44 }
45};
46
83template <typename State, typename Action>
84class CostFunction {
85public:
86 virtual ~CostFunction() = default;
87
95
100};
101
102template <typename State, typename Action>
103class SimpleCostFunction : public CostFunction<State, Action> {
104public:
108 TerminationInfo get_termination_info(param_type<State> state) final
109 {
110 return is_goal(state) ? TerminationInfo::from_goal()
111 : TerminationInfo::from_non_goal(
112 get_non_goal_termination_cost());
113 }
114
115 virtual bool is_goal(param_type<State> state) const = 0;
116 [[nodiscard]]
117 virtual value_t get_non_goal_termination_cost() const = 0;
118};
119
120} // namespace probfd
121
122#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.
Specifies the termination cost and goal status of a state.
Definition cost_function.h:13
bool is_goal_state() const
Check if this state is a goal.
Definition cost_function.h:34
value_t get_cost() const
Obtains the cost paid upon termination in the state.
Definition cost_function.h:41
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