AI 24/25 Project Software
Documentation for the AI 24/25 course programming project software
Loading...
Searching...
No Matches
search_algorithm.h
1#ifndef SEARCH_ALGORITHM_H
2#define SEARCH_ALGORITHM_H
3
4#include "downward/operator_cost.h"
5#include "downward/operator_id.h"
6#include "downward/plan_manager.h"
7#include "downward/search_progress.h"
8#include "downward/search_space.h"
9#include "downward/search_statistics.h"
10#include "downward/state_registry.h"
11#include "downward/task_proxy.h"
12
13#include "downward/utils/logging.h"
14
15#include <vector>
16
17namespace ordered_set {
18template <typename T>
19class OrderedSet;
20}
21
22namespace successor_generator {
23class SuccessorGenerator;
24}
25
26enum SearchStatus { IN_PROGRESS, TIMEOUT, FAILED, SOLVED };
27
28class SearchAlgorithm {
29 std::string description;
30 SearchStatus status;
31 bool solution_found;
32 Plan plan;
33
34protected:
35 // Hold a reference to the task implementation and pass it to objects that
36 // need it.
37 const std::shared_ptr<AbstractTask> task;
38 // Use task_proxy to access task information.
39 TaskProxy task_proxy;
40
41 mutable utils::LogProxy log;
42 PlanManager plan_manager;
43 StateRegistry state_registry;
44 const successor_generator::SuccessorGenerator& successor_generator;
45 SearchSpace search_space;
46 SearchProgress search_progress;
47 SearchStatistics statistics;
48 int bound;
49 OperatorCost cost_type;
50 bool is_unit_cost;
51 double max_time;
52
53 virtual void initialize() {}
54 virtual SearchStatus step() = 0;
55
56 void set_plan(const Plan& plan);
57 bool check_goal_and_set_plan(const State& state);
58 int get_adjusted_cost(const OperatorProxy& op) const;
59
60public:
61 SearchAlgorithm(
62 OperatorCost cost_type,
63 int bound,
64 double max_time,
65 const std::string& description,
66 utils::Verbosity verbosity);
67
68 virtual ~SearchAlgorithm();
69 virtual void print_statistics() const = 0;
70 virtual void save_plan_if_necessary();
71 bool found_solution() const;
72 SearchStatus get_status() const;
73 const Plan& get_plan() const;
74 void search();
75 const SearchStatistics& get_statistics() const { return statistics; }
76 void set_bound(int b) { bound = b; }
77 int get_bound() { return bound; }
78 PlanManager& get_plan_manager() { return plan_manager; }
79 std::string get_description() { return description; }
80};
81
82/*
83 Print evaluator values of all evaluators evaluated in the evaluation context.
84*/
85extern void
86print_initial_evaluator_values(const EvaluationContext& eval_context);
87
88extern void collect_preferred_operators(
89 EvaluationContext& eval_context,
90 Evaluator* preferred_operator_evaluator,
91 ordered_set::OrderedSet<OperatorID>& preferred_operators);
92
93#endif