Class cowboys::GPTrainingLoop
template <class AgentType class AgentType, class EnvironmentType class EnvironmentType>
ClassList > cowboys > GPTrainingLoop
Classes
Type | Name |
---|---|
struct | SaveDataParams |
Public Attributes
Type | Name |
---|---|
bool | ScavengerQueuing = = false |
Public Functions
Type | Name |
---|---|
double | AStarFitnessFunction (const cse491::GridPosition & startpos, const cse491::GridPosition & endpos, int arena, int a) |
int | AgentsAnalysisComputationsAndPrint (int generation, double deltaForMaxFitness=0.1) |
std::string | FormatPosition (const cse491::GridPosition & pos, int precision=0) |
std::filesystem::path | FullLoadGrabLatestGeneration () |
GPTrainingLoop (const bool scavengerQueuing=false) : constructor |
|
size_t | Get_A_StarDistance (const cse491::GridPosition & startpos, const cse491::GridPosition & endpos, int arenaIDX, int agentIDX) |
void | GpLoopMutateHelper () Helper function for the GP loop mutate function. |
void | InitTEMPAgentFitness () : initialize the TEMP agent fitness vector |
void | Initialize (size_t numArenas=5, size_t NumAgentsForArena=100) Initialize the training loop with a number of environments and agents per environment. |
void | MemGOBYE () Clears the memory of the training loop. |
void | MutateAgents (int start, int end, const std::vector< std::pair< int, int > > & sortedAgents, std::vector< std::vector< cowboys::GPAgentBase * > > & agents, double mutationRate) Helper function for the GP loop mutate function. This function mutates the agents. This function is called in a thread. |
void | MutateAndCopyAgents (int start, int end, const std::vector< std::pair< int, int > > & sortedAgents, std::vector< std::vector< cowboys::GPAgentBase * > > & agents, int elitePopulationSize) Helper function for the GP loop mutate function. This function copies the elite agents and mutates them. This function is called in a thread. for th. |
void | Printgrid (const std::vector< cse491::GridPosition > & positions, char symbol='S') Prints the grid for a single arena. |
void | ResetMainTagLastGenerations () |
void | Run (size_t numGenerations, size_t numberOfTurns=100, size_t maxThreads=0, bool saveData=false) : runs the Genetic Programming training loop for a number of generations to evolve the agents |
void | RunArena (size_t arena, size_t numberOfTurns) Runs the training loop for a single arena. This function is called in a thread. Each arena is run in a separate thread. |
void | SaveDataCheckPoint (const SaveDataParams & params) |
void | SerializeAgents (int generation, tinyxml2::XMLElement * rootElement, tinyxml2::XMLDocument & paramDocument, size_t topN=5) : Serializes the agents to an XML file. |
double | SimpleFitnessFunction (cse491::AgentBase & agent, cse491::GridPosition startPosition) |
void | SortThemAgents () : sort the agents based on their fitness |
void | ThreadTrainLoop (size_t maxThreads=1, int numberOfTurns=100) |
void | loadLastGeneration () |
void | resetEnvironments () Resets the environments to their initial state. This function is called after each generation. This function currently only soft resets the environments. |
void | saveXMLDoc (tinyxml2::XMLDocument & paramdoc, std::string fullPath) |
~GPTrainingLoop () = default |
Public Static Functions
Type | Name |
---|---|
std::string | getDateStr () |
std::filesystem::path | getSystemPath () |
Public Attributes Documentation
variable ScavengerQueuing
bool ScavengerQueuing;
Public Functions Documentation
function AStarFitnessFunction
inline double cowboys::GPTrainingLoop::AStarFitnessFunction (
const cse491::GridPosition & startpos,
const cse491::GridPosition & endpos,
int arena,
int a
)
function AgentsAnalysisComputationsAndPrint
inline int cowboys::GPTrainingLoop::AgentsAnalysisComputationsAndPrint (
int generation,
double deltaForMaxFitness=0.1
)
Computes agents analysis metrics
Parameters:
generation
Returns:
function FormatPosition
inline std::string cowboys::GPTrainingLoop::FormatPosition (
const cse491::GridPosition & pos,
int precision=0
)
Helper function to format the data analysis
Parameters:
pos
precision
Returns:
function FullLoadGrabLatestGeneration
inline std::filesystem::path cowboys::GPTrainingLoop::FullLoadGrabLatestGeneration ()
function GPTrainingLoop
inline cowboys::GPTrainingLoop::GPTrainingLoop (
const bool scavengerQueuing=false
)
function Get_A_StarDistance
inline size_t cowboys::GPTrainingLoop::Get_A_StarDistance (
const cse491::GridPosition & startpos,
const cse491::GridPosition & endpos,
int arenaIDX,
int agentIDX
)
function GpLoopMutateHelper
inline void cowboys::GPTrainingLoop::GpLoopMutateHelper ()
function InitTEMPAgentFitness
inline void cowboys::GPTrainingLoop::InitTEMPAgentFitness ()
function Initialize
Initialize the training loop with a number of environments and agents per environment.
inline void cowboys::GPTrainingLoop::Initialize (
size_t numArenas=5,
size_t NumAgentsForArena=100
)
Parameters:
numArenas
NumAgentsForArena
function MemGOBYE
inline void cowboys::GPTrainingLoop::MemGOBYE ()
function MutateAgents
Helper function for the GP loop mutate function. This function mutates the agents. This function is called in a thread.
inline void cowboys::GPTrainingLoop::MutateAgents (
int start,
int end,
const std::vector< std::pair< int, int > > & sortedAgents,
std::vector< std::vector< cowboys::GPAgentBase * > > & agents,
double mutationRate
)
Parameters:
start
: The start index of the agents to mutate.end
: The end index of the agents to mutate.sortedAgents
: The sorted agents' index vector.agents
: The agents vector.mutationRate
The mutation rate.
function MutateAndCopyAgents
Helper function for the GP loop mutate function. This function copies the elite agents and mutates them. This function is called in a thread. for th.
inline void cowboys::GPTrainingLoop::MutateAndCopyAgents (
int start,
int end,
const std::vector< std::pair< int, int > > & sortedAgents,
std::vector< std::vector< cowboys::GPAgentBase * > > & agents,
int elitePopulationSize
)
Parameters:
start
end
sortedAgents
agents
elitePopulationSize
function Printgrid
Prints the grid for a single arena.
inline void cowboys::GPTrainingLoop::Printgrid (
const std::vector< cse491::GridPosition > & positions,
char symbol='S'
)
Parameters:
arenaId
Author:
: @amantham20
function ResetMainTagLastGenerations
inline void cowboys::GPTrainingLoop::ResetMainTagLastGenerations ()
Resets the xml for data that needs to be overwritten
function Run
: runs the Genetic Programming training loop for a number of generations to evolve the agents
inline void cowboys::GPTrainingLoop::Run (
size_t numGenerations,
size_t numberOfTurns=100,
size_t maxThreads=0,
bool saveData=false
)
Parameters:
numGenerations
numberOfTurns
maxThreads
function RunArena
Runs the training loop for a single arena. This function is called in a thread. Each arena is run in a separate thread.
inline void cowboys::GPTrainingLoop::RunArena (
size_t arena,
size_t numberOfTurns
)
Author:
: @amantham20
Parameters:
arena
: The arena to run.numberOfTurns
: The number of turns to run the arena for.
function SaveDataCheckPoint
inline void cowboys::GPTrainingLoop::SaveDataCheckPoint (
const SaveDataParams & params
)
Saves checkpoint data to XML files everyso often
Parameters:
params
function SerializeAgents
: Serializes the agents to an XML file.
inline void cowboys::GPTrainingLoop::SerializeAgents (
int generation,
tinyxml2::XMLElement * rootElement,
tinyxml2::XMLDocument & paramDocument,
size_t topN=5
)
Parameters:
countMaxAgents
generation
topN
function SimpleFitnessFunction
inline double cowboys::GPTrainingLoop::SimpleFitnessFunction (
cse491::AgentBase & agent,
cse491::GridPosition startPosition
)
Simple and temporary fitness function
Parameters:
agent
startPosition
Returns:
function SortThemAgents
inline void cowboys::GPTrainingLoop::SortThemAgents ()
function ThreadTrainLoop
inline void cowboys::GPTrainingLoop::ThreadTrainLoop (
size_t maxThreads=1,
int numberOfTurns=100
)
Parameters:
maxThreads
numberOfTurns
function loadLastGeneration
inline void cowboys::GPTrainingLoop::loadLastGeneration ()
function resetEnvironments
inline void cowboys::GPTrainingLoop::resetEnvironments ()
function saveXMLDoc
inline void cowboys::GPTrainingLoop::saveXMLDoc (
tinyxml2::XMLDocument & paramdoc,
std::string fullPath
)
function ~GPTrainingLoop
cowboys::GPTrainingLoop::~GPTrainingLoop () = default
Public Static Functions Documentation
function getDateStr
static inline std::string cowboys::GPTrainingLoop::getDateStr ()
Gets the date and time as a string
Returns:
function getSystemPath
static inline std::filesystem::path cowboys::GPTrainingLoop::getSystemPath ()
Gets the path of the save location
Returns:
The documentation for this class was generated from the following file source/Agents/GP/GPTrainingLoop.hpp