Skip to content

Class cowboys::CGPAgent

ClassList > cowboys > CGPAgent

An agent based on cartesian genetic programming.

  • #include <CGPAgent.hpp>

Inherits the following classes: cowboys::GPAgentBase

Public Functions

Type Name
CGPAgent (size_t id, const std::string & name)
CGPAgent (size_t id, const std::string & name, const CGPGenotype & genotype)
void Configure (const CGPAgent & other)
Copies the genotype and behavior of another CGPAgent into this agent.
virtual void Copy (const GPAgentBase & other) override
Copy the behavior of another agent into this agent.
virtual std::string Export () override
Export the genotype for this agent.
virtual size_t GetAction (const cse491::WorldGrid & grid, const cse491::type_options_t & type_options, const cse491::item_map_t & item_set, const cse491::agent_map_t & agent_set) override
double GetComplexity () const
The complexity of this agent. Used for fitness.
const CGPGenotype & GetGenotype () const
Get the genotype for this agent.
virtual void Import (const std::string & genotype) override
Load in the string representation of a genotype and configure this agent based on it.
bool Initialize () override
Setup graph.
virtual void MutateAgent (double mutation_rate=0.8) override
Mutate this agent.
virtual void PrintAgent () override
virtual void SerializeGP (tinyxml2::XMLDocument & doc, tinyxml2::XMLElement * parentElem, double fitness=-1) override
Serialize this agent to XML.

Public Functions inherited from cowboys::GPAgentBase

See cowboys::GPAgentBase

Type Name
virtual void Copy (const GPAgentBase & other) = 0
Copy the behavior of another agent into this agent.
virtual std::string Export ()
GPAgentBase (size_t id, const std::string & name)
virtual size_t GetAction (const cse491::WorldGrid & grid, const cse491::type_options_t & type_options, const cse491::item_map_t & item_set, const cse491::agent_map_t & agent_set) = 0
const std::unordered_map< std::string, double > GetExtraState () const
Get a map of extra state information.
double GetRandom ()
Return a uniform random value between 0.0 and 1.0.
double GetRandom (double max)
Return a uniform random value between 0.0 and max.
double GetRandom (double min, double max)
Return a uniform random value between min and max.
double GetRandomNormal ()
Return a gaussian random value with mean 0.0 and sd 1.0.
double GetRandomNormal (double mean, double sd=1.0)
Return a gaussian random value with provided mean and sd.
size_t GetRandomULL (size_t max)
Return a uniform random unsigned long long between 0 (inclusive) and max (exclusive)
unsigned int GetSeed () const
Get the seed used to initialize this RNG.
virtual void Import (const std::string & genotype) = 0
bool Initialize () override
Setup graph.
virtual void MutateAgent (double mutation_rate=0.8) = 0
Mutate this agent.
virtual void PrintAgent ()
virtual void Reset (bool=false)
size_t SelectAction (const cse491::WorldGrid & grid, const cse491::type_options_t & type_options, const cse491::item_map_t & item_set, const cse491::agent_map_t & agent_set) override
Choose the action to take a step in the appropriate direction.
virtual void SerializeGP (tinyxml2::XMLDocument & doc, tinyxml2::XMLElement * parentElem, double fitness=-1) = 0
void SetSeed (unsigned int seed)
Set the seed used to initialize this RNG.
~GPAgentBase () = default

Protected Attributes

Type Name
std::unique_ptr< Graph > decision_graph
The decision graph for this agent.
CGPGenotype genotype
The genotype for this agent.

Protected Attributes inherited from cowboys::GPAgentBase

See cowboys::GPAgentBase

Type Name
std::unordered_map< std::string, double > extra_state
A map of extra state information.
std::normal_distribution< double > norm_dist
Normal distribution.
std::mt19937 rng = {seed}
Random number generator.
unsigned int seed = = 0
Seed for the random number generator.
std::uniform_real_distribution< double > uni_dist
Uniform distribution.

Public Functions Documentation

function CGPAgent [1/2]

inline cowboys::CGPAgent::CGPAgent (
    size_t id,
    const std::string & name
) 

function CGPAgent [2/2]

inline cowboys::CGPAgent::CGPAgent (
    size_t id,
    const std::string & name,
    const CGPGenotype & genotype
) 

function Configure

Copies the genotype and behavior of another CGPAgent into this agent.

inline void cowboys::CGPAgent::Configure (
    const CGPAgent & other
) 

Parameters:

function Copy

Copy the behavior of another agent into this agent.

inline virtual void cowboys::CGPAgent::Copy (
    const GPAgentBase & other
) override

Parameters:

  • other The agent to copy.

Implements cowboys::GPAgentBase::Copy

function Export

Export the genotype for this agent.

inline virtual std::string cowboys::CGPAgent::Export () override

Returns:

The string representation of the genotype for this agent.

Implements cowboys::GPAgentBase::Export

function GetAction

inline virtual size_t cowboys::CGPAgent::GetAction (
    const cse491::WorldGrid & grid,
    const cse491::type_options_t & type_options,
    const cse491::item_map_t & item_set,
    const cse491::agent_map_t & agent_set
) override

Implements cowboys::GPAgentBase::GetAction

function GetComplexity

The complexity of this agent. Used for fitness.

inline double cowboys::CGPAgent::GetComplexity () const

Returns:

The complexity of this agent.

function GetGenotype

Get the genotype for this agent.

inline const CGPGenotype & cowboys::CGPAgent::GetGenotype () const

Returns:

A const reference to the genotype for this agent.

function Import

Load in the string representation of a genotype and configure this agent based on it.

inline virtual void cowboys::CGPAgent::Import (
    const std::string & genotype
) override

Parameters:

  • genotype The string representation of a genotype.

Implements cowboys::GPAgentBase::Import

function Initialize

Setup graph.

inline bool cowboys::CGPAgent::Initialize () override

Returns:

Success.

function MutateAgent

Mutate this agent.

inline virtual void cowboys::CGPAgent::MutateAgent (
    double mutation_rate=0.8
) override

Parameters:

  • mutation_rate The mutation rate. Between 0 and 1.

Implements cowboys::GPAgentBase::MutateAgent

function PrintAgent

inline virtual void cowboys::CGPAgent::PrintAgent () override

Implements cowboys::GPAgentBase::PrintAgent

function SerializeGP

Serialize this agent to XML.

inline virtual void cowboys::CGPAgent::SerializeGP (
    tinyxml2::XMLDocument & doc,
    tinyxml2::XMLElement * parentElem,
    double fitness=-1
) override

Parameters:

  • doc The XML document to serialize to.
  • parentElem The parent element to serialize to.
  • fitness The fitness of this agent to write to the XML.

Implements cowboys::GPAgentBase::SerializeGP

Protected Attributes Documentation

variable decision_graph

std::unique_ptr<Graph> decision_graph;

variable genotype

CGPGenotype genotype;

The documentation for this class was generated from the following file source/Agents/GP/CGPAgent.hpp