AI 24/25 Project Software
Documentation for the AI 24/25 course programming project software
Loading...
Searching...
No Matches
cegar.h
1#ifndef CEGAR_CEGAR_H
2#define CEGAR_CEGAR_H
3
4#include "downward/cartesian_abstractions/abstract_search.h"
5#include "downward/cartesian_abstractions/split_selector.h"
6
7#include "downward/task_proxy.h"
8
9#include "downward/utils/countdown_timer.h"
10
11#include <memory>
12
13namespace utils {
14class RandomNumberGenerator;
15class LogProxy;
16} // namespace utils
17
18namespace cartesian_abstractions {
19class Abstraction;
20struct Flaw;
21
22/*
23 Iteratively refine a Cartesian abstraction with counterexample-guided
24 abstraction refinement (CEGAR).
25
26 Store the abstraction, use AbstractSearch to find abstract solutions, find
27 flaws, use SplitSelector to select splits in case of ambiguities and break
28 spurious solutions.
29*/
30class CEGAR {
31 const TaskProxy task_proxy;
32 const std::vector<int> domain_sizes;
33 const int max_states;
34 const int max_non_looping_transitions;
35 const SplitSelector split_selector;
36
37 std::unique_ptr<Abstraction> abstraction;
38 AbstractSearch abstract_search;
39
40 // Limit the time for building the abstraction.
41 utils::CountdownTimer timer;
42
43 utils::LogProxy& log;
44
45 bool may_keep_refining() const;
46
47 /*
48 Map all states that can only be reached after reaching the goal
49 fact to arbitrary goal states.
50
51 We need this method only for landmark subtasks, but calling it
52 for other subtasks with a single goal fact doesn't hurt and
53 simplifies the implementation.
54 */
55 void separate_facts_unreachable_before_goal();
56
57 /* Try to convert the abstract solution into a concrete trace. Return the
58 first encountered flaw or nullptr if there is no flaw. */
59 std::unique_ptr<Flaw> find_flaw(const Solution& solution);
60
61 // Build abstraction.
62 void refinement_loop(utils::RandomNumberGenerator& rng);
63
64 void print_statistics();
65
66public:
67 CEGAR(
68 const std::shared_ptr<AbstractTask>& task,
69 int max_states,
70 int max_non_looping_transitions,
71 double max_time,
72 PickSplit pick,
73 utils::RandomNumberGenerator& rng,
74 utils::LogProxy& log);
75 ~CEGAR();
76
77 CEGAR(const CEGAR&) = delete;
78
79 std::unique_ptr<Abstraction> extract_abstraction();
80};
81} // namespace cartesian_abstractions
82
83#endif