IAtari
Genetic algorithm generating AI capable to play Atari2600 games.
genetic_algorithms::distributed_fitness< Res, Params > Class Template Reference

Handle flow control of the algorithm. More...

#include <fitness.hpp>

Public Member Functions

 distributed_fitness (std::function< Res(const std::list< Res > &)> accumulate)
 Standard Constructor. Initialize the accumulate function, set last to false and set ready and processed to 0. More...
 
bool finished ()
 Get the value of stop, i.e. if the algorithm is finished or not. More...
 
std::vector< Params > get_parameters (boost::asio::yield_context yield)
 Decrements ready and get the parameters of the genetic algorithm. More...
 
void set_results (std::vector< std::list< Res >> res, boost::asio::yield_context yield)
 Increments processed, set the results and stop the algorithm if last is true. More...
 
void run (int i, int nb_iterations, const std::vector< Params > &population, std::vector< Res > &results)
 Manage a batch test of agents. More...
 

Private Attributes

std::function< Res(const std::list< Res > &)> accumulate
 
std::vector< Params > params
 
std::vector< std::list< Res > > results
 
boost::interprocess::interprocess_semaphore ready
 
boost::interprocess::interprocess_semaphore processed
 
bool stop = false
 
std::atomic< bool > last
 

Detailed Description

template<typename Res, typename Params>
class genetic_algorithms::distributed_fitness< Res, Params >

Handle flow control of the algorithm.

Constructor & Destructor Documentation

◆ distributed_fitness()

template<typename Res , typename Params >
genetic_algorithms::distributed_fitness< Res, Params >::distributed_fitness ( std::function< Res(const std::list< Res > &)>  accumulate)

Standard Constructor. Initialize the accumulate function, set last to false and set ready and processed to 0.

Parameters
accumulateFunction taking a list of Res and returning a Res, in this case it computes a mean
See also
genetic_algorithms::accumulate

Member Function Documentation

◆ finished()

template<typename Res , typename Params >
bool genetic_algorithms::distributed_fitness< Res, Params >::finished ( )

Get the value of stop, i.e. if the algorithm is finished or not.

Returns
The stop parameter

◆ get_parameters()

template<typename Res , typename Params >
std::vector< Params > genetic_algorithms::distributed_fitness< Res, Params >::get_parameters ( boost::asio::yield_context  yield)

Decrements ready and get the parameters of the genetic algorithm.

Parameters
yieldContext object, represents the currently executing coroutine.
Remarks
yield parameter is unused
Returns
The list of parameters of the genetic algorithm

◆ run()

template<typename Res , typename Params >
void genetic_algorithms::distributed_fitness< Res, Params >::run ( int  i,
int  nb_iterations,
const std::vector< Params > &  population,
std::vector< Res > &  results 
)

Manage a batch test of agents.

Parameters
iCurrent number of generation
nb_iterationsTotal number of generation wanted
[in]populationVector of agents to be tested
[out]resultsVector of results produced by the agents

◆ set_results()

template<typename Res , typename Params >
void genetic_algorithms::distributed_fitness< Res, Params >::set_results ( std::vector< std::list< Res >>  res,
boost::asio::yield_context  yield 
)

Increments processed, set the results and stop the algorithm if last is true.

Parameters
resThe list of results
yieldContext object, represents the currently executing coroutine.

Member Data Documentation

◆ accumulate

template<typename Res , typename Params >
std::function<Res(const std::list<Res>&)> genetic_algorithms::distributed_fitness< Res, Params >::accumulate
private

Function used to compute scores

◆ last

template<typename Res , typename Params >
std::atomic<bool> genetic_algorithms::distributed_fitness< Res, Params >::last
private

Define if the algorithm is on the last iteration

◆ params

template<typename Res , typename Params >
std::vector<Params> genetic_algorithms::distributed_fitness< Res, Params >::params
private

List of agents

◆ processed

template<typename Res , typename Params >
boost::interprocess::interprocess_semaphore genetic_algorithms::distributed_fitness< Res, Params >::processed
private

Interprocess semaphore, prevent the algorithm to process the results if some agents are not tested yet

◆ ready

template<typename Res , typename Params >
boost::interprocess::interprocess_semaphore genetic_algorithms::distributed_fitness< Res, Params >::ready
private

Interprocess semaphore, prevent the algorithm to start a new batch of test from nowhere

◆ results

template<typename Res , typename Params >
std::vector<std::list<Res> > genetic_algorithms::distributed_fitness< Res, Params >::results
private

List of results produced by the agents

◆ stop

template<typename Res , typename Params >
bool genetic_algorithms::distributed_fitness< Res, Params >::stop = false
private

Define if the algorithm is about to end


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