solver  1.0
Public Member Functions | Private Member Functions | Private Attributes | List of all members
KnowledgeBase Class Reference

Protected access to the shared data of the threads of the parallel heuristic. More...

#include <KnowledgeBase.h>

+ Collaboration diagram for KnowledgeBase:

Public Member Functions

std::list< std::pair< Solution, CircuitTuple > > eliteSolutions ()
 Returns a list of elite solutions and their tuples from which they have been calculated.
 
Solution bestSolution ()
 Returns the best found solution, throws an exception if not available.
 
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. More...
 
void addTuple (CircuitTuple &&t)
 Add a tuple to the mutex protected queue of tuples.
 
void addErrorMessage (const std::string &msg)
 Add an error message to the mutex protected vector of messages.
 
std::vector< std::string > errorMessages () const
 Returns all the error messages that occurred in the threads of the heuristic.
 
CircuitTuple getTuple ()
 Returns a partially fixed solution called tuple.
 
void reportInfDueToLP ()
 Reports that it was not possible to obtain a feasible solution from the generated tuple.
 
uint64_t numberOfLPBreaks () const
 Returns how many times it was not possible to obtain an initial solution, i.e. timing.
 
void reportInfDueToLocHeur ()
 It reports that changes of HeuristicAlgorithms::heuristicLocationChanges sub-heuristic caused infeasibility.
 
uint64_t numberOfLocHeurBreaks () const
 Returns how many times the change locations sub-heuristic caused the infeasibility of the solution.
 
void reportInfDueToPwrmHeur ()
 It reports that a power mode change of HeuristicAlgorithms::heuristicPowerModeSelection sub-heuristic caused infeasibility.
 
uint64_t numberOfPwrmHeurBreaks () const
 Returns how many times the (de)select power mode sub-heuristic caused infeasibility.
 
void reportInfDueToPathChange ()
 Reports that a diversification change of paths resulted in an infeasible solution.
 
uint64_t numberOfChangePathBreaks () const
 Returns how many times the change of paths resulted in infeasibility.
 
void recordInfeasibleLP ()
 Reports that the solution of the Linear Programming problem was infeasible (one call of LP).
 
double infeasibilityRate ()
 Infeasibility rate of Linear Programming, i.e. the proportion of infeasible solutions to feasible and infeasible ones.
 
void recordLPCall (double runtime)
 Reports a real time (measured by a timer) required for solving a partially fixed problem by Linear Programming.
 
std::pair< uint64_t, double > infoLP ()
 Returns the total number of Linear Programming calls and its average runtime for one worker thread.
 
void recordLPFixDeterioration (double deterioration)
 Reports a relative deterioration in the solution quality caused by the resolution of collisions.
 
double averageLPFixDeterioration ()
 Returns an average quality deterioration caused by the collisions resolution.
 
double averageNumberOfLPCallsForLPFix ()
 Returns an average number of added precedences required for collisions avoidance.
 
void recordPartialProblemSolveCall ()
 Reports that HeuristicAlgorithms::solvePartialProblem method was called.
 
void recordLocHeurCall (double runtime)
 Reports a real time (measured by a timer) required by HeuristicAlgorithms::heuristicLocationChanges sub-heuristic per call.
 
std::pair< uint64_t, double > infoLocHeur ()
 Returns the total number of HeuristicAlgorithms::heuristicLocationChanges calls and average runtime for one worker thread.
 
void recordLocHeurRelErr (double relativeEstError)
 Reports a relative estimation error of the change locations sub-heuristic for an energy improvement.
 
double averageErrOfLocHeur ()
 Returns an average estimation error of the change locations sub-heuristic.
 
void recordPwrmHeurCall (double runtime)
 Reports a real time (measured by a timer) required by HeuristicAlgorithms::heuristicPowerModeSelection sub-heuristic per call.
 
std::pair< uint64_t, double > infoPwrmHeur ()
 Returns the total number of HeuristicAlgorithms::heuristicPowerModeSelection calls and average runtime for one worker thread.
 
void recordPwrmHeurRelErr (double relativeEstError)
 Reports a relative estimation error of the (de)select power mode sub-heuristic for an energy improvement.
 
double averageErrOfPwrmHeur ()
 Returns an average estimation error of the (de)select power mode sub-heuristic.
 
void recordChangePathCall ()
 Reports that robot paths were diversified, i.e. ParallelHeuristicSolver::changeRobotPaths method was called.
 
uint64_t pathChangeCalls () const
 The total number of ParallelHeuristicSolver::changeRobotPaths calls.
 
void recordAddTuplesCall (double runtime)
 Reports a real time (measured by a timer) required for ParallelHeuristicSolver::addRandomTuplesToKB call.
 
std::pair< uint64_t, double > infoTuplesGeneration ()
 Returns the total number of generated tuples and the average generation time for one worker thread.
 
void recordNumberOfItersPerTuple (uint64_t iters)
 Reports the number of optimization iterations performed for a loaded tuple.
 
std::pair< uint64_t, double > infoItersPerTuple ()
 Returns the total number of tuples used for optimization and the average number of optimization iterations per tuple.
 
double percentageOfProcessed ()
 Percentage of the processed tuples.
 

Private Member Functions

template<class T >
void record (T value, T &addTo)
 It carries out "addTo += value" operation, however protected by a mutex. More...
 
template<class T >
void record (T value, T &addTo, std::atomic< uint64_t > &counter)
 Performs "addTo += value" operation and increases the value of counter by one. More...
 
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 the total time. More...
 

Private Attributes

std::queue< CircuitTuplemTuples
 Queue with the generated tuples.
 
std::vector< std::string > mErrorMessages
 Vector containing error messages of worker threads (to throw an exception later).
 
std::list< std::pair< Solution, CircuitTuple > > mEliteSolutions
 List of elite solutions.
 
std::atomic< uint64_t > mAddedTuples
 Total number of generated tuples.
 
std::atomic< uint64_t > mProcessedTuples
 The number of processed tuples.
 
std::atomic< uint64_t > mOptimizationPhaseCounter
 Records the number of tuples coming to the optimization process of the heuristic.
 
std::atomic< uint64_t > mInfDueToLP
 How many times it was not possible to obtain feasible timing for a tuple.
 
std::atomic< uint64_t > mInfDueToLocHeur
 The number of feasibility breakings caused by change locations sub-heuristic.
 
std::atomic< uint64_t > mInfDueToPwrmHeur
 The number of feasibility breakings caused by (de)select power mode sub-heuristic.
 
std::atomic< uint64_t > mInfDueToChangedPath
 The number of feasibility breakings caused by the path diversification.
 
std::atomic< uint64_t > mInfeasibleCounter
 How many times a Linear Programming solver returned an infeasible solution.
 
std::atomic< uint64_t > mLPCalls
 The number of Linear Programming calls.
 
std::atomic< uint64_t > mLPFixCalls
 How many times a partially fixed problem was successfully solved.
 
std::atomic< uint64_t > mPartProbCalls
 How many times a partially fixed problem was evaluated, i.e. the number of calls of HeuristicAlgorithms::solvePartialProblem.
 
std::atomic< uint64_t > mLocHeurCalls
 The number of change locations sub-heuristic calls.
 
std::atomic< uint64_t > mPwrmHeurCalls
 The number of (de)select power mode sub-heuristic calls.
 
std::atomic< uint64_t > mPathChangeCalls
 The number of robot path diversifications, i.e. the number of calls of ParallelHeuristicSolver::changeRobotPaths.
 
std::atomic< uint64_t > mSumOfIters
 The total number of optimization iterations.
 
double mLPTime
 Aggregated processor time of all the Linear Programming calls.
 
double mLocHeurTime
 Aggregated processor time of all the change locations sub-heuristic calls.
 
double mPwrmHeurTime
 Aggregated processor time of all the (de)select power mode sub-heuristic calls.
 
double mTupleGenTime
 Aggregated processor time required for the generation of all the tuples.
 
double mSumOfDeteriorations
 The sum of relative deteriorations of the energy consumption caused by the collision resolution.
 
double mSumOfLocHeurErrs
 The sum of the relative estimation errors (calculated by the change locations sub-heuristic) of energy improvements.
 
double mSumOfPwrmHeurErrs
 The sum of the relative estimation errors (calculated by the (de)select power mode sub-heuristic) of energy improvements.
 
std::mutex mEliteMtx
 Mutex protecting the access to the list of elite solutions.
 
std::mutex mTuplesMtx
 Mutex protecting the access to the queue that contains tuples.
 
std::mutex mErrorsMtx
 Mutex protecting the access to the vector of error messages.
 
std::mutex mStatMtx
 Mutex ensuring the flawless float operations for multiple concurrent threads.
 

Detailed Description

Protected access to the shared data of the threads of the parallel heuristic.

Instance of the class stores the best found solutions, generated tuples, and various statistics related to the heuristic performance.

Definition at line 46 of file KnowledgeBase.h.

Member Function Documentation

void KnowledgeBase::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.

Parameters
sA candidate for an elite solution.
tTuple from which the solution was generated.

Definition at line 45 of file KnowledgeBase.cpp.

pair< uint64_t, double > KnowledgeBase::getInfo ( double &  aggregatedValue,
std::atomic< uint64_t > &  counter 
)
private

Auxiliary method used for the calculation of an average time of a call based on a counter value and the total time.

Parameters
aggregatedValueA value with e.g. aggregated time of calls.
counterThe number of e.g. calls.
Returns
A pair { counter, aggregatedValue/counter } if counter > 0.

Definition at line 215 of file KnowledgeBase.cpp.

template<class T >
void KnowledgeBase::record ( value,
T &  addTo 
)
private

It carries out "addTo += value" operation, however protected by a mutex.

Template Parameters
TNumerical type.
Parameters
valueValue to be added to addTo.
addToAccumulated value.

Definition at line 203 of file KnowledgeBase.cpp.

template<class T >
void KnowledgeBase::record ( value,
T &  addTo,
std::atomic< uint64_t > &  counter 
)
private

Performs "addTo += value" operation and increases the value of counter by one.

Template Parameters
TNumerical type.
Parameters
valueValue to be added to addTo.
addToAccumulated value.
counterCounter which somehow relates with the previous parameters.
Note
The method is thread-safe.

Definition at line 210 of file KnowledgeBase.cpp.


The documentation for this class was generated from the following files: