AI 24/25 Project Software
Documentation for the AI 24/25 course programming project software
Loading...
Searching...
No Matches
diverse_potential_heuristics.h
1#ifndef POTENTIALS_DIVERSE_POTENTIAL_HEURISTICS_H
2#define POTENTIALS_DIVERSE_POTENTIAL_HEURISTICS_H
3
4#include "downward/potentials/potential_optimizer.h"
5
6#include "downward/utils/logging.h"
7
8#include <memory>
9#include <unordered_map>
10#include <vector>
11
12namespace utils {
13class RandomNumberGenerator;
14}
15
16namespace potentials {
17using SamplesToFunctionsMap =
18 utils::HashMap<State, std::unique_ptr<PotentialFunction>>;
19
20/*
21 Factory class that finds diverse potential functions.
22*/
23class DiversePotentialHeuristics {
24 PotentialOptimizer optimizer;
25 // TODO: Remove max_num_heuristics and control number of heuristics
26 // with num_samples parameter?
27 const int max_num_heuristics;
28 const int num_samples;
29 std::shared_ptr<utils::RandomNumberGenerator> rng;
30 utils::LogProxy log;
31 std::vector<std::unique_ptr<PotentialFunction>> diverse_functions;
32
33 /* Filter dead end samples and duplicates. Store potential heuristics
34 for remaining samples. */
35 SamplesToFunctionsMap
36 filter_samples_and_compute_functions(const std::vector<State>& samples);
37
38 // Remove all samples for which the function achieves maximal values.
39 void remove_covered_samples(
40 const PotentialFunction& chosen_function,
41 SamplesToFunctionsMap& samples_to_functions) const;
42
43 /* Return potential function optimized for remaining samples or a
44 precomputed heuristic if the former does not cover additional samples. */
45 std::unique_ptr<PotentialFunction> find_function_and_remove_covered_samples(
46 SamplesToFunctionsMap& samples_to_functions);
47
48 /* Iteratively try to find potential functions that achieve maximal values
49 for as many samples as possible. */
50 void cover_samples(SamplesToFunctionsMap& samples_to_functions);
51
52public:
53 DiversePotentialHeuristics(
54 int num_samples,
55 int max_num_heuristics,
56 double max_potential,
57 lp::LPSolverType lpsolver,
58 const std::shared_ptr<AbstractTask>& transform,
59 int random_seed,
60 utils::Verbosity verbosity);
61
62 ~DiversePotentialHeuristics();
63
64 // Sample states, then cover them.
65 std::vector<std::unique_ptr<PotentialFunction>> find_functions();
66};
67} // namespace potentials
68#endif