![]() |
IAtari
Genetic algorithm generating AI capable to play Atari2600 games.
|
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 |
Handle flow control of the algorithm.
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.
accumulate | Function taking a list of Res and returning a Res, in this case it computes a mean |
bool genetic_algorithms::distributed_fitness< Res, Params >::finished | ( | ) |
Get the value of stop, i.e. if the algorithm is finished or not.
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.
yield | Context object, represents the currently executing coroutine. |
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.
i | Current number of generation | |
nb_iterations | Total number of generation wanted | |
[in] | population | Vector of agents to be tested |
[out] | results | Vector of results produced by the agents |
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.
res | The list of results |
yield | Context object, represents the currently executing coroutine. |
|
private |
Function used to compute scores
|
private |
Define if the algorithm is on the last iteration
|
private |
List of agents
|
private |
Interprocess semaphore, prevent the algorithm to process the results if some agents are not tested yet
|
private |
Interprocess semaphore, prevent the algorithm to start a new batch of test from nowhere
|
private |
List of results produced by the agents
|
private |
Define if the algorithm is about to end