AutoPas  3.0.0
Loading...
Searching...
No Matches
RuleBasedTuning.h
Go to the documentation of this file.
1
7#pragma once
8
9#include <algorithm>
10#include <fstream>
11#include <iostream>
12#include <iterator>
13#include <list>
14#include <unordered_map>
15#include <unordered_set>
16#include <variant>
17
18#ifdef AUTOPAS_ENABLE_RULES_BASED_AND_FUZZY_TUNING
19#include "RuleBasedProgramParser.h"
20#include "RuleBasedProgramTree.h"
21#include "RuleVM.h"
22#endif
23
28
29namespace autopas {
85 public:
90#ifdef AUTOPAS_ENABLE_RULES_BASED_AND_FUZZY_TUNING
91 std::function<void(const RuleSyntax::ConfigurationOrder &order, const Configuration &actualBetterConfig,
92 unsigned long betterRuntime, const Configuration &shouldBeBetterConfig,
93 unsigned long shouldBeBetterRuntime, const LiveInfo &liveInfo)>;
94#else
95 int; // This is simply a dummy type and will never be used.
96#endif
97
105 explicit RuleBasedTuning(const std::set<Configuration> &searchSpace, bool verifyModeEnabled = false,
106 std::string ruleFileName = "tuningRules.rule",
107 PrintTuningErrorFunType tuningErrorPrinter = {});
108
109 TuningStrategyOption getOptionType() const override;
110
111 bool needsLiveInfo() const override;
112
113 void receiveLiveInfo(const LiveInfo &info) override;
114
115 void addEvidence(const Configuration &configuration, const Evidence &evidence) override;
116
117 bool reset(size_t iteration, size_t tuningPhase, std::vector<Configuration> &configQueue,
118 const autopas::EvidenceCollection &evidenceCollection) override;
119
124 [[nodiscard]] long getLifetimeWouldHaveSkippedTuningTime() const;
125
129 [[nodiscard]] long getLifetimeTuningTime() const;
130
131 bool optimizeSuggestions(std::vector<Configuration> &configQueue,
132 const EvidenceCollection &evidenceCollection) override;
133
134 private:
135#ifdef AUTOPAS_ENABLE_RULES_BASED_AND_FUZZY_TUNING
144 std::string rulesToString(const std::string &filePath) const;
145
153 void verifyCurrentConfigTime(const Configuration &configuration) const;
154
159 std::vector<RuleSyntax::ConfigurationOrder> applyRules(const std::vector<Configuration> &searchSpace);
160
161 std::vector<RuleSyntax::ConfigurationOrder> _lastApplicableConfigurationOrders{};
162
163 // The following member variables are only conditionally compiled to avoid warnings about unused variables.
164
165 bool _verifyModeEnabled{};
170 long _tuningTime{0};
171 long _wouldHaveSkippedTuningTime{0};
175 bool _rulesTooHarsh{false};
176 PrintTuningErrorFunType _tuningErrorPrinter{};
177#endif
178
179 std::set<Configuration> _searchSpace{};
180 std::list<Configuration> _originalSearchSpace{};
181 std::set<Configuration> _removedConfigurations{};
182
183 std::string _ruleFileName{};
184
185 std::unordered_map<Configuration, long, ConfigHash> _traversalTimes{};
186
187 long _tuningTimeLifetime{0};
188 long _wouldHaveSkippedTuningTimeLifetime{0};
189
190 LiveInfo _currentLiveInfo{};
191};
192} // 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:31
A tuning strategy that uses information collected live from the domain to exclude configurations that...
Definition: RuleBasedTuning.h:84
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:95
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