AI 24/25 Project Software
Documentation for the AI 24/25 course programming project software
Loading...
Searching...
No Matches
landmark_cost_partitioning_algorithms.h
1#ifndef LANDMARKS_LANDMARK_COST_PARTITIONING_ALGORITHMS_H
2#define LANDMARKS_LANDMARK_COST_PARTITIONING_ALGORITHMS_H
3
4#include "downward/task_proxy.h"
5
6#include "downward/lp/lp_solver.h"
7
8#include <unordered_set>
9#include <vector>
10
11class OperatorsProxy;
12
13namespace landmarks {
14class Landmark;
15class LandmarkGraph;
16class LandmarkNode;
17class LandmarkStatusManager;
18
19class CostPartitioningAlgorithm {
20protected:
21 const LandmarkGraph& lm_graph;
22 const std::vector<int> operator_costs;
23
24 const std::unordered_set<int>&
25 get_achievers(const Landmark& landmark, bool past) const;
26
27public:
28 CostPartitioningAlgorithm(
29 const std::vector<int>& operator_costs,
30 const LandmarkGraph& graph);
31 virtual ~CostPartitioningAlgorithm() = default;
32
33 virtual double get_cost_partitioned_heuristic_value(
34 const LandmarkStatusManager& lm_status_manager,
35 const State& ancestor_state) = 0;
36};
37
38class UniformCostPartitioningAlgorithm : public CostPartitioningAlgorithm {
39 bool use_action_landmarks;
40
41public:
42 UniformCostPartitioningAlgorithm(
43 const std::vector<int>& operator_costs,
44 const LandmarkGraph& graph,
45 bool use_action_landmarks);
46
47 virtual double get_cost_partitioned_heuristic_value(
48 const LandmarkStatusManager& lm_status_manager,
49 const State& ancestor_state) override;
50};
51
52class OptimalCostPartitioningAlgorithm : public CostPartitioningAlgorithm {
53 lp::LPSolver lp_solver;
54 /* We keep an additional copy of the constraints around to avoid
55 some effort with recreating the vector (see issue443). */
56 std::vector<lp::LPConstraint> lp_constraints;
57 /*
58 We keep the vectors for LP variables and constraints around instead of
59 recreating them for every state. The actual constraints have to be
60 recreated because the coefficient matrix of the LP changes from state to
61 state. Reusing the vectors still saves some dynamic allocation overhead.
62 */
63 lp::LinearProgram lp;
64
65 lp::LinearProgram build_initial_lp();
66
67public:
68 OptimalCostPartitioningAlgorithm(
69 const std::vector<int>& operator_costs,
70 const LandmarkGraph& graph,
71 lp::LPSolverType solver_type);
72
73 virtual double get_cost_partitioned_heuristic_value(
74 const LandmarkStatusManager& lm_status_manager,
75 const State& ancestor_state) override;
76};
77} // namespace landmarks
78
79#endif