AI 24/25 Project Software
Documentation for the AI 24/25 course programming project software
Loading...
Searching...
No Matches
distances.h
1#ifndef MERGE_AND_SHRINK_DISTANCES_H
2#define MERGE_AND_SHRINK_DISTANCES_H
3
4#include "downward/merge_and_shrink/types.h"
5
6#include <cassert>
7#include <vector>
8
9/*
10 TODO: Possible interface improvements for this class:
11 - Check TODOs in implementation file.
12
13 (Many of these would need performance tests, as distance computation
14 can be one of the bottlenecks in our code.)
15*/
16
17namespace utils {
18class LogProxy;
19}
20
21namespace merge_and_shrink {
22class TransitionSystem;
23
24class Distances {
25 static const int DISTANCE_UNKNOWN = -1;
26 const TransitionSystem& transition_system;
27 std::vector<int> init_distances;
28 std::vector<int> goal_distances;
29 bool init_distances_computed;
30 bool goal_distances_computed;
31
32 void clear_distances();
33 int get_num_states() const;
34 bool is_unit_cost() const;
35
36 void compute_init_distances_unit_cost();
37 void compute_goal_distances_unit_cost();
38 void compute_init_distances_general_cost();
39 void compute_goal_distances_general_cost();
40
41public:
42 explicit Distances(const TransitionSystem& transition_system);
43 ~Distances() = default;
44
45 bool are_init_distances_computed() const { return init_distances_computed; }
46
47 bool are_goal_distances_computed() const { return goal_distances_computed; }
48
49 void compute_distances(
50 bool compute_init_distances,
51 bool compute_goal_distances,
52 utils::LogProxy& log);
53
54 /*
55 Update distances according to the given abstraction. If the abstraction
56 is not f-preserving, distances are directly recomputed.
57
58 It is OK for the abstraction to drop states, but then all
59 dropped states must be unreachable or irrelevant. (Otherwise,
60 the method might fail to detect that the distance information is
61 out of date.)
62 */
63 void apply_abstraction(
64 const StateEquivalenceRelation& state_equivalence_relation,
65 bool compute_init_distances,
66 bool compute_goal_distances,
67 utils::LogProxy& log);
68
69 int get_init_distance(int state) const
70 {
71 assert(are_init_distances_computed());
72 return init_distances[state];
73 }
74
75 int get_goal_distance(int state) const
76 {
77 assert(are_goal_distances_computed());
78 return goal_distances[state];
79 }
80
81 void dump(utils::LogProxy& log) const;
82 void statistics(utils::LogProxy& log) const;
83};
84} // namespace merge_and_shrink
85
86#endif