AI 24/25 Project Software
Documentation for the AI 24/25 course programming project software
Loading...
Searching...
No Matches
potential_optimizer.h
1#ifndef POTENTIALS_POTENTIAL_OPTIMIZER_H
2#define POTENTIALS_POTENTIAL_OPTIMIZER_H
3
4#include "downward/task_proxy.h"
5
6#include "downward/lp/lp_solver.h"
7
8#include <memory>
9#include <vector>
10
11namespace potentials {
12class PotentialFunction;
13
14/*
15 Add admissible potential constraints to LP and allow optimizing for
16 different objectives.
17
18 The implementation is based on transforming the task into transition
19 normal form (TNF) (Pommerening and Helmert, ICAPS 2015). We add an
20 undefined value u to each variable's domain, but do not create
21 forgetting operators or change existing operators explicitly.
22 Instead, we ensure that all fact potentials of a variable V are less
23 than or equal to the potential of V=u and implicitly set pre(op) to
24 V=u for operators op where pre(op) is undefined. Similarly, we set
25 s_\star(V) = u for variables V without a goal value.
26
27 For more information we refer to the paper introducing potential
28 heuristics
29
30 Florian Pommerening, Malte Helmert, Gabriele Roeger and Jendrik Seipp.
31 From Non-Negative to General Operator Cost Partitioning.
32 AAAI 2015.
33
34 and the paper comparing various optimization functions
35
36 Jendrik Seipp, Florian Pommerening and Malte Helmert.
37 New Optimization Functions for Potential Heuristics.
38 ICAPS 2015.
39*/
40class PotentialOptimizer {
41 std::shared_ptr<AbstractTask> task;
42 TaskProxy task_proxy;
43 lp::LPSolver lp_solver;
44 const double max_potential;
45 int num_lp_vars;
46 std::vector<std::vector<int>> lp_var_ids;
47 std::vector<std::vector<double>> fact_potentials;
48
49 int get_lp_var_id(const FactProxy& fact) const;
50 void initialize();
51 void construct_lp();
52 void solve_and_extract();
53 void extract_lp_solution();
54
55public:
56 PotentialOptimizer(
57 const std::shared_ptr<AbstractTask>& transform,
58 lp::LPSolverType lpsolver,
59 double max_potential);
60 ~PotentialOptimizer() = default;
61
62 std::shared_ptr<AbstractTask> get_task() const;
63 bool potentials_are_bounded() const;
64
65 void optimize_for_state(const State& state);
66 void optimize_for_all_states();
67 void optimize_for_samples(const std::vector<State>& samples);
68
69 bool has_optimal_solution() const;
70
71 std::unique_ptr<PotentialFunction> get_potential_function() const;
72};
73} // namespace potentials
74
75#endif