GEGELATI

Loading...
Searching...
No Matches
parallelLearningAgent.h
1
38#ifndef PARALLEL_LEARNING_AGENT
39#define PARALLEL_LEARNING_AGENT
40
41#include <mutex>
42#include <queue>
43#include <thread>
44
45#include "instructions/set.h"
46#include "tpg/tpgExecutionEngine.h"
47
48#include "learn/evaluationResult.h"
49#include "learn/job.h"
50#include "learn/learningAgent.h"
51#include "learn/learningEnvironment.h"
52#include "learn/learningParameters.h"
53
54 namespace Learn {
65 class ParallelLearningAgent : public LearningAgent
66 {
67 protected:
80 virtual void evaluateAllRootsInParallel(
81 uint64_t generationNumber, LearningMode mode,
82 std::multimap<std::shared_ptr<EvaluationResult>,
83 const TPG::TPGVertex*>& results);
84
99 virtual void evaluateAllRootsInParallelExecute(
100 uint64_t generationNumber, LearningMode mode,
101 std::map<uint64_t, std::pair<std::shared_ptr<EvaluationResult>,
102 std::shared_ptr<Job>>>&
103 resultsPerJobMap,
104 std::map<uint64_t, Archive*>& archiveMap);
105
121 virtual void evaluateAllRootsInParallelCompileResults(
122 std::map<uint64_t, std::pair<std::shared_ptr<EvaluationResult>,
123 std::shared_ptr<Job>>>&
124 resultsPerJobMap,
125 std::multimap<std::shared_ptr<EvaluationResult>,
126 const TPG::TPGVertex*>& results,
127 std::map<uint64_t, Archive*>& archiveMap);
128
149 void slaveEvalJobThread(
150 uint64_t generationNumber, LearningMode mode,
151 std::queue<std::shared_ptr<Learn::Job>>& jobsToProcess,
152 std::mutex& rootsToProcessMutex,
153 std::map<uint64_t, std::pair<std::shared_ptr<EvaluationResult>,
154 std::shared_ptr<Job>>>&
155 resultsPerRootMap,
156 std::mutex& resultsPerRootMapMutex,
157 std::map<uint64_t, Archive*>& archiveMap,
158 std::mutex& archiveMapMutex, bool useMainEnvironment);
159
171 void mergeArchiveMap(std::map<uint64_t, Archive*>& archiveMap);
172
173 public:
186 ParallelLearningAgent(
187 LearningEnvironment& le, const Instructions::Set& iSet,
188 const LearningParameters& p,
189 const TPG::TPGFactory& factory = TPG::TPGFactory())
190 : LearningAgent(le, iSet, p, factory)
191 {
192 // overriding the maxNbThreads that basic LA defined to 1
193 maxNbThreads = p.nbThreads;
194 };
195
213 std::multimap<std::shared_ptr<EvaluationResult>, const TPG::TPGVertex*>
214 evaluateAllRoots(uint64_t generationNumber, LearningMode mode) override;
215 };
216} // namespace Learn
217#endif
Instructions::Set
Class for storing a set of Instruction.
Definition set.h:55
Learn::LearningAgent
Class used to control the learning steps of a TPGGraph within a given LearningEnvironment.
Definition learningAgent.h:64
Learn::LearningAgent::maxNbThreads
uint64_t maxNbThreads
Control the maximum number of threads when running in parallel.
Definition learningAgent.h:106
Learn::LearningEnvironment
Interface for creating a Learning Environment.
Definition learningEnvironment.h:81
Learn::ParallelLearningAgent
Class used to control the learning steps of a TPGGraph within a given LearningEnvironment,...
Definition parallelLearningAgent.h:66
Learn::ParallelLearningAgent::slaveEvalJobThread
void slaveEvalJobThread(uint64_t generationNumber, LearningMode mode, std::queue< std::shared_ptr< Learn::Job > > &jobsToProcess, std::mutex &rootsToProcessMutex, std::map< uint64_t, std::pair< std::shared_ptr< EvaluationResult >, std::shared_ptr< Job > > > &resultsPerRootMap, std::mutex &resultsPerRootMapMutex, std::map< uint64_t, Archive * > &archiveMap, std::mutex &archiveMapMutex, bool useMainEnvironment)
Function implementing the behavior of slave threads during parallel evaluation of roots.
Definition parallelLearningAgent.cpp:88
Learn::ParallelLearningAgent::evaluateAllRootsInParallelExecute
virtual void evaluateAllRootsInParallelExecute(uint64_t generationNumber, LearningMode mode, std::map< uint64_t, std::pair< std::shared_ptr< EvaluationResult >, std::shared_ptr< Job > > > &resultsPerJobMap, std::map< uint64_t, Archive * > &archiveMap)
Subfunction of evaluateAllRootsInParallel which handles the creation of threads, their execution and ...
Definition parallelLearningAgent.cpp:243
Learn::ParallelLearningAgent::evaluateAllRootsInParallelCompileResults
virtual void evaluateAllRootsInParallelCompileResults(std::map< uint64_t, std::pair< std::shared_ptr< EvaluationResult >, std::shared_ptr< Job > > > &resultsPerJobMap, std::multimap< std::shared_ptr< EvaluationResult >, const TPG::TPGVertex * > &results, std::map< uint64_t, Archive * > &archiveMap)
Subfunction of evaluateAllRootsInParallel which handles the gathering of results and the merge of the...
Definition parallelLearningAgent.cpp:281
Learn::ParallelLearningAgent::evaluateAllRoots
std::multimap< std::shared_ptr< EvaluationResult >, const TPG::TPGVertex * > evaluateAllRoots(uint64_t generationNumber, LearningMode mode) override
Evaluate all root TPGVertex of the TPGGraph.
Definition parallelLearningAgent.cpp:53
Learn::ParallelLearningAgent::evaluateAllRootsInParallel
virtual void evaluateAllRootsInParallel(uint64_t generationNumber, LearningMode mode, std::multimap< std::shared_ptr< EvaluationResult >, const TPG::TPGVertex * > &results)
Method for evaluating all roots with parallelism.
Definition parallelLearningAgent.cpp:225
Learn::ParallelLearningAgent::mergeArchiveMap
void mergeArchiveMap(std::map< uint64_t, Archive * > &archiveMap)
Method to merge several Archive created in parallel threads.
Definition parallelLearningAgent.cpp:175
Learn::ParallelLearningAgent::ParallelLearningAgent
ParallelLearningAgent(LearningEnvironment &le, const Instructions::Set &iSet, const LearningParameters &p, const TPG::TPGFactory &factory=TPG::TPGFactory())
Constructor for ParallelLearningAgent.
Definition parallelLearningAgent.h:186
TPG::TPGFactory
Factory for creating all elements constituting a TPG.
Definition tpgFactory.h:71
TPG::TPGVertex
Abstract class representing the vertices of a TPGGraph.
Definition tpgVertex.h:55
Learn
Definition adversarialEvaluationResult.h:45
Learn::LearningMode
LearningMode
Different modes in which the LearningEnvironment can be reset.
Definition learningEnvironment.h:59
Learn::LearningParameters
Structure for simplifying the transmission of LearningParameters to functions.
Definition learningParameters.h:54
Learn::LearningParameters::nbThreads
size_t nbThreads
Number of threads (ParallelLearningAgent only)
Definition learningParameters.h:214