AI 24/25 Project Software
Documentation for the AI 24/25 course programming project software
Loading...
Searching...
No Matches
label_reduction.h
1#ifndef MERGE_AND_SHRINK_LABEL_REDUCTION_H
2#define MERGE_AND_SHRINK_LABEL_REDUCTION_H
3
4#include <memory>
5#include <vector>
6
7class TaskProxy;
8
9namespace equivalence_relation {
10class EquivalenceRelation;
11}
12
13namespace utils {
14class LogProxy;
15class RandomNumberGenerator;
16} // namespace utils
17
18namespace merge_and_shrink {
19class FactoredTransitionSystem;
20
21/*
22 two_transition_systems: compute the 'combinable relation'
23 for labels only for the two transition_systems that will
24 be merged next and reduce labels.
25
26 all_transition_systems: compute the 'combinable relation'
27 for labels once for every transition_system and reduce
28 labels.
29
30 all_transition_systems_with_fixpoint: keep computing the
31 'combinable relation' for labels iteratively for all
32 transition systems until no more labels can be reduced.
33*/
34enum class LabelReductionMethod {
35 TWO_TRANSITION_SYSTEMS,
36 ALL_TRANSITION_SYSTEMS,
37 ALL_TRANSITION_SYSTEMS_WITH_FIXPOINT
38};
39/*
40 Order in which iterations of label reduction considers the set of all
41 transition systems. Regular is the fast downward order plus appending
42 new composite transition systems after the atomic ones, reverse is the
43 reversed regular order and random is a random one. All orders are
44 precomputed and reused for every call to reduce().
45*/
46enum class LabelReductionSystemOrder { REGULAR, REVERSE, RANDOM };
47
48class LabelReduction {
49 // Options for label reduction
50 std::vector<int> transition_system_order;
51 bool lr_before_shrinking;
52 bool lr_before_merging;
53 LabelReductionMethod lr_method;
54 LabelReductionSystemOrder lr_system_order;
55 std::shared_ptr<utils::RandomNumberGenerator> rng;
56
57 bool initialized() const;
58 /* Apply the given label equivalence relation to the set of labels and
59 compute the resulting label mapping. */
60 void compute_label_mapping(
61 const equivalence_relation::EquivalenceRelation& relation,
62 const FactoredTransitionSystem& fts,
63 std::vector<std::pair<int, std::vector<int>>>& label_mapping,
64 utils::LogProxy& log) const;
65 equivalence_relation::EquivalenceRelation
66 compute_combinable_equivalence_relation(
67 int ts_index,
68 const FactoredTransitionSystem& fts) const;
69
70public:
71 LabelReduction(
72 bool before_shrinking,
73 bool before_merging,
74 LabelReductionMethod method,
75 LabelReductionSystemOrder system_order,
76 int random_seed);
77 void initialize(const TaskProxy& task_proxy);
78 bool reduce(
79 const std::pair<int, int>& next_merge,
80 FactoredTransitionSystem& fts,
81 utils::LogProxy& log) const;
82 void dump_options(utils::LogProxy& log) const;
83 bool reduce_before_shrinking() const { return lr_before_shrinking; }
84 bool reduce_before_merging() const { return lr_before_merging; }
85};
86} // namespace merge_and_shrink
87
88#endif