AI 24/25 Project Software
Documentation for the AI 24/25 course programming project software
Loading...
Searching...
No Matches
pattern_collection_generator_multiple.h
1#ifndef PDBS_PATTERN_COLLECTION_GENERATOR_MULTIPLE_H
2#define PDBS_PATTERN_COLLECTION_GENERATOR_MULTIPLE_H
3
4#include "downward/pdbs/pattern_generator.h"
5
6#include <set>
7#include <unordered_set>
8
9namespace utils {
10class CountdownTimer;
11class RandomNumberGenerator;
12} // namespace utils
13
14namespace pdbs {
15/*
16 This pattern collection generator is a general framework for computing a
17 pattern collection for a given planning task. It is an abstract base class
18 which must be subclasses to provide a method for computing a single pattern
19 for the given task and a single goal of the task.
20
21 The algorithm works as follows. It first stores the goals of the task in
22 random order. Then, it repeatedly iterates over all goals and for each goal,
23 it uses the given method for computing a single pattern. If the pattern is
24 new (duplicate detection), it is kept for the final collection.
25
26 The algorithm runs until reaching a given time limit. Another parameter allows
27 exiting early if no new patterns are found for a certain time ("stagnation").
28 Further parameters allow enabling blacklisting for the given pattern
29 computation method after a certain time to force some diversification or to
30 enable said blacklisting when stagnating.
31*/
32class PatternCollectionGeneratorMultiple : public PatternCollectionGenerator {
33 const int max_pdb_size;
34 const double pattern_generation_max_time;
35 const double total_max_time;
36 const double stagnation_limit;
37 const double blacklisting_start_time;
38 const bool enable_blacklist_on_stagnation;
39 std::shared_ptr<utils::RandomNumberGenerator> rng;
40 const int random_seed;
41
42 // Variables used in the main loop.
43 int remaining_collection_size;
44 bool blacklisting;
45 double time_point_of_last_new_pattern;
46
47 void check_blacklist_trigger_timer(const utils::CountdownTimer& timer);
48 std::unordered_set<int>
49 get_blacklisted_variables(std::vector<int>& non_goal_variables);
50 void handle_generated_pattern(
51 PatternInformation&& pattern_info,
52 std::set<Pattern>& generated_patterns,
53 std::shared_ptr<PDBCollection>& generated_pdbs,
54 const utils::CountdownTimer& timer);
55 bool collection_size_limit_reached() const;
56 bool time_limit_reached(const utils::CountdownTimer& timer) const;
57 bool check_for_stagnation(const utils::CountdownTimer& timer);
58 virtual std::string id() const = 0;
59 virtual void initialize(const std::shared_ptr<AbstractTask>& task) = 0;
60 virtual PatternInformation compute_pattern(
61 int max_pdb_size,
62 double max_time,
63 const std::shared_ptr<utils::RandomNumberGenerator>& rng,
64 const std::shared_ptr<AbstractTask>& task,
65 const FactPair& goal,
66 std::unordered_set<int>&& blacklisted_variables) = 0;
67 virtual std::string name() const override;
68 virtual PatternCollectionInformation
69 compute_patterns(const std::shared_ptr<AbstractTask>& task) override;
70
71public:
72 PatternCollectionGeneratorMultiple(
73 int max_pdb_size,
74 int max_collection_size,
75 double pattern_generation_max_time,
76 double total_max_time,
77 double stagnation_limit,
78 double blacklist_trigger_percentage,
79 bool enable_blacklist_on_stagnation,
80 int random_seed,
81 utils::Verbosity verbosity);
82};
83
84} // namespace pdbs
85
86#endif