AI 24/25 Project Software
Documentation for the AI 24/25 course programming project software
Loading...
Searching...
No Matches
enforced_hill_climbing_search.h
1#ifndef SEARCH_ALGORITHMS_ENFORCED_HILL_CLIMBING_SEARCH_H
2#define SEARCH_ALGORITHMS_ENFORCED_HILL_CLIMBING_SEARCH_H
3
4#include "downward/evaluation_context.h"
5#include "downward/open_list.h"
6#include "downward/search_algorithm.h"
7
8#include <map>
9#include <memory>
10#include <set>
11#include <utility>
12#include <vector>
13
14namespace enforced_hill_climbing_search {
15enum class PreferredUsage { PRUNE_BY_PREFERRED, RANK_PREFERRED_FIRST };
16
17/*
18 Enforced hill-climbing with deferred evaluation.
19
20 TODO: We should test if this lazy implementation really has any benefits over
21 an eager one. We hypothesize that both versions need to evaluate and store
22 the same states anyways.
23*/
24class EnforcedHillClimbingSearch : public SearchAlgorithm {
25 std::unique_ptr<EdgeOpenList> open_list;
26
27 std::shared_ptr<Evaluator> evaluator;
28 std::vector<std::shared_ptr<Evaluator>> preferred_operator_evaluators;
29 std::set<Evaluator*> path_dependent_evaluators;
30 bool use_preferred;
31 PreferredUsage preferred_usage;
32
33 EvaluationContext current_eval_context;
34 int current_phase_start_g;
35
36 // Statistics
37 std::map<int, std::pair<int, int>> d_counts;
38 int num_ehc_phases;
39 int last_num_expanded;
40
41 void insert_successor_into_open_list(
42 const EvaluationContext& eval_context,
43 int parent_g,
44 OperatorID op_id,
45 bool preferred);
46 void expand(EvaluationContext& eval_context);
47 void reach_state(const State& parent, OperatorID op_id, const State& state);
48 SearchStatus ehc();
49
50protected:
51 virtual void initialize() override;
52 virtual SearchStatus step() override;
53
54public:
55 EnforcedHillClimbingSearch(
56 const std::shared_ptr<Evaluator>& h,
57 PreferredUsage preferred_usage,
58 const std::vector<std::shared_ptr<Evaluator>>& preferred,
59 OperatorCost cost_type,
60 int bound,
61 double max_time,
62 const std::string& description,
63 utils::Verbosity verbosity);
64
65 virtual void print_statistics() const override;
66};
67} // namespace enforced_hill_climbing_search
68
69#endif