AutoPas  3.0.0
Loading...
Searching...
No Matches
RuleBasedTuning.h
Go to the documentation of this file.
1
7#pragma once
8
9#include <fstream>
10#include <list>
11#include <unordered_map>
12
13#ifdef AUTOPAS_ENABLE_RULES_BASED_AND_FUZZY_TUNING
14#include "RuleBasedProgramParser.h"
15#include "RuleBasedProgramTree.h"
16#include "RuleVM.h"
18#endif
19
24
25namespace autopas {
81 public:
86#ifdef AUTOPAS_ENABLE_RULES_BASED_AND_FUZZY_TUNING
87 std::function<void(const RuleSyntax::ConfigurationOrder &order, const Configuration &actualBetterConfig,
88 unsigned long betterRuntime, const Configuration &shouldBeBetterConfig,
89 unsigned long shouldBeBetterRuntime, const LiveInfo &liveInfo)>;
90#else
91 int; // This is simply a dummy type and will never be used.
92#endif
93
101 explicit RuleBasedTuning(const std::set<Configuration> &searchSpace, bool verifyModeEnabled = false,
102 std::string ruleFileName = "tuningRules.rule",
103 PrintTuningErrorFunType tuningErrorPrinter = {});
104
105 TuningStrategyOption getOptionType() const override;
106
107 bool needsLiveInfo() const override;
108
109 void receiveLiveInfo(const LiveInfo &info) override;
110
111 void addEvidence(const Configuration &configuration, const Evidence &evidence) override;
112
113 bool reset(size_t iteration, size_t tuningPhase, std::vector<Configuration> &configQueue,
114 const autopas::EvidenceCollection &evidenceCollection) override;
115
120 [[nodiscard]] long getLifetimeWouldHaveSkippedTuningTime() const;
121
125 [[nodiscard]] long getLifetimeTuningTime() const;
126
127 bool optimizeSuggestions(std::vector<Configuration> &configQueue,
128 const EvidenceCollection &evidenceCollection) override;
129
130 private:
131#ifdef AUTOPAS_ENABLE_RULES_BASED_AND_FUZZY_TUNING
140 std::string rulesToString(const std::string &filePath) const;
141
149 void verifyCurrentConfigTime(const Configuration &configuration) const;
150
155 std::vector<RuleSyntax::ConfigurationOrder> applyRules(const std::vector<Configuration> &searchSpace);
156
157 std::vector<RuleSyntax::ConfigurationOrder> _lastApplicableConfigurationOrders{};
158
159 // The following member variables are only conditionally compiled to avoid warnings about unused variables.
160
161 bool _verifyModeEnabled{};
166 long _tuningTime{0};
167 long _wouldHaveSkippedTuningTime{0};
171 bool _rulesTooHarsh{false};
172 PrintTuningErrorFunType _tuningErrorPrinter{};
173#endif
174
175 std::set<Configuration> _searchSpace{};
176 std::list<Configuration> _originalSearchSpace{};
177 std::set<Configuration> _removedConfigurations{};
178
179 std::string _ruleFileName{};
180
181 std::unordered_map<Configuration, long, ConfigHash> _traversalTimes{};
182
183 long _tuningTimeLifetime{0};
184 long _wouldHaveSkippedTuningTimeLifetime{0};
185
186 LiveInfo _currentLiveInfo{};
187};
188} // namespace autopas
Class containing multiple options that form an algorithm configuration for the pairwise iteration.
Definition: Configuration.h:24
Class to manage all evidence.
Definition: EvidenceCollection.h:21
Helper class that associates a measurement with the iteration when it was taken.
Definition: Evidence.h:15
This class is able to gather and store important information for a tuning phase from a container and ...
Definition: LiveInfo.h:32
A tuning strategy that uses information collected live from the domain to exclude configurations that...
Definition: RuleBasedTuning.h:80
bool reset(size_t iteration, size_t tuningPhase, std::vector< Configuration > &configQueue, const autopas::EvidenceCollection &evidenceCollection) override
Reset all internal parameters to the beginning of a new tuning phase.
Definition: RuleBasedTuning.cpp:58
long getLifetimeTuningTime() const
Definition: RuleBasedTuning.cpp:87
void addEvidence(const Configuration &configuration, const Evidence &evidence) override
Notifies the strategy about empirically collected information for the given configuration.
Definition: RuleBasedTuning.cpp:43
TuningStrategyOption getOptionType() const override
Get this object's associated TuningStrategyOption type.
Definition: RuleBasedTuning.cpp:110
long getLifetimeWouldHaveSkippedTuningTime() const
Definition: RuleBasedTuning.cpp:85
void receiveLiveInfo(const LiveInfo &info) override
Virtual method that subclasses can override to receive the LiveInfo object before a tuning phase if t...
Definition: RuleBasedTuning.cpp:41
bool optimizeSuggestions(std::vector< Configuration > &configQueue, const EvidenceCollection &evidenceCollection) override
Optimizes the queue of configurations to process.
Definition: RuleBasedTuning.cpp:89
bool needsLiveInfo() const override
Returns whether this tuning strategy wants to get a LiveInfo object passed before a new tuning phase.
Definition: RuleBasedTuning.cpp:39
int PrintTuningErrorFunType
A function type used to print errors found in verify mode.
Definition: RuleBasedTuning.h:91
Interface for tuning strategies for the auto tuner.
Definition: TuningStrategyInterface.h:23
This is the main namespace of AutoPas.
Definition: AutoPasDecl.h:32
A ConfigurationOrder statement in the rule language e.g.
Definition: RuleBasedProgramTree.h:193