solver  1.0
KnowledgeBase.h
Go to the documentation of this file.
1 /*
2  This file is part of the EnergyOptimizatorOfRoboticCells program.
3 
4  EnergyOptimizatorOfRoboticCells is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  EnergyOptimizatorOfRoboticCells is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with EnergyOptimizatorOfRoboticCells. If not, see <http://www.gnu.org/licenses/>.
16 */
17 
18 #ifndef HLIDAC_PES_KNOWLEDGE_BASE_H
19 #define HLIDAC_PES_KNOWLEDGE_BASE_H
20 
27 #include <algorithm>
28 #include <atomic>
29 #include <cassert>
30 #include <list>
31 #include <mutex>
32 #include <queue>
33 #include <set>
34 #include <vector>
35 #include <utility>
36 #include "RoboticLine.h"
37 #include "Solution/Solution.h"
40 
47  public:
48  KnowledgeBase();
49 
51  std::list<std::pair<Solution, CircuitTuple>> eliteSolutions();
59  void candidate(const Solution& s, const CircuitTuple& t);
60 
62  void addTuple(CircuitTuple&& t);
64  void addErrorMessage(const std::string& msg);
66  std::vector<std::string> errorMessages() const { return mErrorMessages; }
69 
73  uint64_t numberOfLPBreaks() const { return mInfDueToLP; }
77  uint64_t numberOfLocHeurBreaks() const { return mInfDueToLocHeur; }
81  uint64_t numberOfPwrmHeurBreaks() const { return mInfDueToPwrmHeur; }
85  uint64_t numberOfChangePathBreaks() const { return mInfDueToChangedPath; }
86 
88  void recordInfeasibleLP();
90  double infeasibilityRate();
92  void recordLPCall(double runtime);
94  std::pair<uint64_t, double> infoLP();
96  void recordLPFixDeterioration(double deterioration);
103 
105  void recordLocHeurCall(double runtime);
107  std::pair<uint64_t, double> infoLocHeur();
109  void recordLocHeurRelErr(double relativeEstError);
111  double averageErrOfLocHeur();
112 
114  void recordPwrmHeurCall(double runtime);
116  std::pair<uint64_t, double> infoPwrmHeur();
118  void recordPwrmHeurRelErr(double relativeEstError);
120  double averageErrOfPwrmHeur();
121 
125  uint64_t pathChangeCalls() const { return mPathChangeCalls; }
126 
128  void recordAddTuplesCall(double runtime);
130  std::pair<uint64_t, double> infoTuplesGeneration();
132  void recordNumberOfItersPerTuple(uint64_t iters);
134  std::pair<uint64_t, double> infoItersPerTuple();
136  double percentageOfProcessed();
137  private:
138 
145  template <class T>
146  void record(T value, T& addTo);
147 
156  template <class T>
157  void record(T value, T& addTo, std::atomic<uint64_t>& counter);
158 
165  std::pair<uint64_t, double> getInfo(double& aggregatedValue, std::atomic<uint64_t>& counter);
166 
168  std::queue<CircuitTuple> mTuples;
170  std::vector<std::string> mErrorMessages;
172  std::list<std::pair<Solution, CircuitTuple>> mEliteSolutions;
173 
175  std::atomic<uint64_t> mAddedTuples;
177  std::atomic<uint64_t> mProcessedTuples;
179  std::atomic<uint64_t> mOptimizationPhaseCounter;
180 
182  std::atomic<uint64_t> mInfDueToLP;
184  std::atomic<uint64_t> mInfDueToLocHeur;
186  std::atomic<uint64_t> mInfDueToPwrmHeur;
188  std::atomic<uint64_t> mInfDueToChangedPath;
190  std::atomic<uint64_t> mInfeasibleCounter;
191 
193  std::atomic<uint64_t> mLPCalls;
195  std::atomic<uint64_t> mLPFixCalls;
197  std::atomic<uint64_t> mPartProbCalls;
199  std::atomic<uint64_t> mLocHeurCalls;
201  std::atomic<uint64_t> mPwrmHeurCalls;
203  std::atomic<uint64_t> mPathChangeCalls;
205  std::atomic<uint64_t> mSumOfIters;
206 
208  double mLPTime;
210  double mLocHeurTime;
221 
223  std::mutex mEliteMtx;
225  std::mutex mTuplesMtx;
227  std::mutex mErrorsMtx;
229  std::mutex mStatMtx;
230 };
231 
232 #endif
void reportInfDueToPathChange()
Reports that a diversification change of paths resulted in an infeasible solution.
Definition: KnowledgeBase.h:83
uint64_t numberOfChangePathBreaks() const
Returns how many times the change of paths resulted in infeasibility.
Definition: KnowledgeBase.h:85
void reportInfDueToPwrmHeur()
It reports that a power mode change of HeuristicAlgorithms::heuristicPowerModeSelection sub-heuristic...
Definition: KnowledgeBase.h:79
void addTuple(CircuitTuple &&t)
Add a tuple to the mutex protected queue of tuples.
double mTupleGenTime
Aggregated processor time required for the generation of all the tuples.
The structure representing a solution found by an algorithm.
Definition: Solution.h:50
uint64_t numberOfLocHeurBreaks() const
Returns how many times the change locations sub-heuristic caused the infeasibility of the solution...
Definition: KnowledgeBase.h:77
double mPwrmHeurTime
Aggregated processor time of all the (de)select power mode sub-heuristic calls.
void record(T value, T &addTo)
It carries out "addTo += value" operation, however protected by a mutex.
void candidate(const Solution &s, const CircuitTuple &t)
If a found solution ranks among the top ones, it is added to the list of elite solutions.
std::atomic< uint64_t > mPathChangeCalls
The number of robot path diversifications, i.e. the number of calls of ParallelHeuristicSolver::chang...
std::list< std::pair< Solution, CircuitTuple > > mEliteSolutions
List of elite solutions.
CircuitTuple getTuple()
Returns a partially fixed solution called tuple.
std::list< std::pair< Solution, CircuitTuple > > eliteSolutions()
Returns a list of elite solutions and their tuples from which they have been calculated.
std::atomic< uint64_t > mProcessedTuples
The number of processed tuples.
uint64_t numberOfLPBreaks() const
Returns how many times it was not possible to obtain an initial solution, i.e. timing.
Definition: KnowledgeBase.h:73
std::pair< uint64_t, double > infoLocHeur()
Returns the total number of HeuristicAlgorithms::heuristicLocationChanges calls and average runtime f...
double percentageOfProcessed()
Percentage of the processed tuples.
The structures and methods suitable for fast searching in the data structure of the robotic cell...
std::atomic< uint64_t > mAddedTuples
Total number of generated tuples.
std::atomic< uint64_t > mOptimizationPhaseCounter
Records the number of tuples coming to the optimization process of the heuristic. ...
double mSumOfLocHeurErrs
The sum of the relative estimation errors (calculated by the change locations sub-heuristic) of energ...
std::atomic< uint64_t > mInfDueToPwrmHeur
The number of feasibility breakings caused by (de)select power mode sub-heuristic.
Protected access to the shared data of the threads of the parallel heuristic.
Definition: KnowledgeBase.h:46
Various data structures used by the heuristic.
std::vector< std::string > mErrorMessages
Vector containing error messages of worker threads (to throw an exception later). ...
void recordLPFixDeterioration(double deterioration)
Reports a relative deterioration in the solution quality caused by the resolution of collisions...
std::pair< uint64_t, double > infoLP()
Returns the total number of Linear Programming calls and its average runtime for one worker thread...
void recordInfeasibleLP()
Reports that the solution of the Linear Programming problem was infeasible (one call of LP)...
Solution bestSolution()
Returns the best found solution, throws an exception if not available.
std::atomic< uint64_t > mSumOfIters
The total number of optimization iterations.
void recordChangePathCall()
Reports that robot paths were diversified, i.e. ParallelHeuristicSolver::changeRobotPaths method was ...
std::atomic< uint64_t > mInfeasibleCounter
How many times a Linear Programming solver returned an infeasible solution.
void addErrorMessage(const std::string &msg)
Add an error message to the mutex protected vector of messages.
std::atomic< uint64_t > mPwrmHeurCalls
The number of (de)select power mode sub-heuristic calls.
std::atomic< uint64_t > mInfDueToLP
How many times it was not possible to obtain feasible timing for a tuple.
uint64_t pathChangeCalls() const
The total number of ParallelHeuristicSolver::changeRobotPaths calls.
A partially fixed problem, i.e. tuple.
std::mutex mStatMtx
Mutex ensuring the flawless float operations for multiple concurrent threads.
std::atomic< uint64_t > mLPFixCalls
How many times a partially fixed problem was successfully solved.
void recordPwrmHeurCall(double runtime)
Reports a real time (measured by a timer) required by HeuristicAlgorithms::heuristicPowerModeSelectio...
double mLocHeurTime
Aggregated processor time of all the change locations sub-heuristic calls.
std::atomic< uint64_t > mInfDueToChangedPath
The number of feasibility breakings caused by the path diversification.
void recordLPCall(double runtime)
Reports a real time (measured by a timer) required for solving a partially fixed problem by Linear Pr...
void recordLocHeurRelErr(double relativeEstError)
Reports a relative estimation error of the change locations sub-heuristic for an energy improvement...
void recordNumberOfItersPerTuple(uint64_t iters)
Reports the number of optimization iterations performed for a loaded tuple.
std::mutex mErrorsMtx
Mutex protecting the access to the vector of error messages.
std::atomic< uint64_t > mLocHeurCalls
The number of change locations sub-heuristic calls.
std::atomic< uint64_t > mLPCalls
The number of Linear Programming calls.
std::mutex mTuplesMtx
Mutex protecting the access to the queue that contains tuples.
std::pair< uint64_t, double > infoItersPerTuple()
Returns the total number of tuples used for optimization and the average number of optimization itera...
void recordPwrmHeurRelErr(double relativeEstError)
Reports a relative estimation error of the (de)select power mode sub-heuristic for an energy improvem...
double averageErrOfLocHeur()
Returns an average estimation error of the change locations sub-heuristic.
std::pair< uint64_t, double > getInfo(double &aggregatedValue, std::atomic< uint64_t > &counter)
Auxiliary method used for the calculation of an average time of a call based on a counter value and t...
double averageNumberOfLPCallsForLPFix()
Returns an average number of added precedences required for collisions avoidance. ...
std::atomic< uint64_t > mInfDueToLocHeur
The number of feasibility breakings caused by change locations sub-heuristic.
std::pair< uint64_t, double > infoPwrmHeur()
Returns the total number of HeuristicAlgorithms::heuristicPowerModeSelection calls and average runtim...
std::queue< CircuitTuple > mTuples
Queue with the generated tuples.
void reportInfDueToLocHeur()
It reports that changes of HeuristicAlgorithms::heuristicLocationChanges sub-heuristic caused infeasi...
Definition: KnowledgeBase.h:75
double mLPTime
Aggregated processor time of all the Linear Programming calls.
A representation of the solution that is algorithm independent.
double mSumOfPwrmHeurErrs
The sum of the relative estimation errors (calculated by the (de)select power mode sub-heuristic) of ...
double averageErrOfPwrmHeur()
Returns an average estimation error of the (de)select power mode sub-heuristic.
std::atomic< uint64_t > mPartProbCalls
How many times a partially fixed problem was evaluated, i.e. the number of calls of HeuristicAlgorith...
void recordPartialProblemSolveCall()
Reports that HeuristicAlgorithms::solvePartialProblem method was called.
std::mutex mEliteMtx
Mutex protecting the access to the list of elite solutions.
void reportInfDueToLP()
Reports that it was not possible to obtain a feasible solution from the generated tuple...
Definition: KnowledgeBase.h:71
The file contains various classes devoted to abstract representation of the robotic cell...
double mSumOfDeteriorations
The sum of relative deteriorations of the energy consumption caused by the collision resolution...
double averageLPFixDeterioration()
Returns an average quality deterioration caused by the collisions resolution.
std::pair< uint64_t, double > infoTuplesGeneration()
Returns the total number of generated tuples and the average generation time for one worker thread...
uint64_t numberOfPwrmHeurBreaks() const
Returns how many times the (de)select power mode sub-heuristic caused infeasibility.
Definition: KnowledgeBase.h:81
void recordAddTuplesCall(double runtime)
Reports a real time (measured by a timer) required for ParallelHeuristicSolver::addRandomTuplesToKB c...
double infeasibilityRate()
Infeasibility rate of Linear Programming, i.e. the proportion of infeasible solutions to feasible and...
void recordLocHeurCall(double runtime)
Reports a real time (measured by a timer) required by HeuristicAlgorithms::heuristicLocationChanges s...
std::vector< std::string > errorMessages() const
Returns all the error messages that occurred in the threads of the heuristic.
Definition: KnowledgeBase.h:66