Skip to content

Class cowboys::LGPAgent

ClassList > cowboys > LGPAgent

Inherits the following classes: cowboys::GPAgentBase

Public Functions

Type Name
void Configure (const LGPAgent & other)
Copies the behavior of another LGPAgent 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 agent to a string.
void GenerateRandomActionList ()
Generate a random list of instructions from a list of possible instructions.
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
Get the action to take.
const std::vector< std::tuple< std::string, int, int > > & GetInstructionsList ()
Get the instruction list for this agent.
virtual void Import (const std::string & encodedLists) override
Load in the string representation of an LGP agent and configure this agent based on it.
bool Initialize () override
Initialize the agent after being given an action map.
LGPAgent (size_t id, const std::string & name)
virtual void MutateAgent (double mutation_rate=0.01) override
Mutate this agent.
virtual void PrintAgent () override
Print the agent.
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

Public Static Functions

Type Name
std::vector< std::string > EncodeActions (const std::unordered_map< std::string, size_t > & action_map, const std::vector< std::string > & sensorsNamesList, const std::vector< std::string > & operationsList, std::vector< std::string > & actionsList)
Encodes the actions from an agent's action map into a vector of string, representing action names.

Protected Attributes

Type Name
std::vector< std::string > actionsList = = {}
size_t currentInstructionIndex = = 0
std::mt19937 gen
std::vector< std::tuple< std::string, int, int > > instructionsList = = {}
std::vector< std::string > operationsList = = {"lessthan", "greaterthan", "equals"}
std::vector< std::string > possibleInstructionsList = = {}
std::random_device rd
std::vector< int > resultsList
std::vector< std::string > sensorsNamesList = = {"getLeft", "getRight", "getUp", "getDown"}

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 Configure

Copies the behavior of another LGPAgent into this agent.

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

Parameters:

function Copy

Copy the behavior of another agent into this agent.

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

Parameters:

  • other The agent to copy.

Implements cowboys::GPAgentBase::Copy

function Export

Export the agent to a string.

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

Returns:

The string representation of the agent

Implements cowboys::GPAgentBase::Export

function GenerateRandomActionList

Generate a random list of instructions from a list of possible instructions.

inline void cowboys::LGPAgent::GenerateRandomActionList () 

Returns:

Success.

function GetAction

Get the action to take.

inline virtual size_t cowboys::LGPAgent::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

Parameters:

  • grid The world grid.
  • type_options The available types of cells in the grid.
  • item_set The set of items in the world.
  • agent_set The set of agents in the world.

Returns:

A size_t corresponding to the action chosen

Implements cowboys::GPAgentBase::GetAction

function GetInstructionsList

Get the instruction list for this agent.

inline const std::vector< std::tuple< std::string, int, int > > & cowboys::LGPAgent::GetInstructionsList () 

Returns:

A const reference to the instruction list for this agent.

function Import

Load in the string representation of an LGP agent and configure this agent based on it.

inline virtual void cowboys::LGPAgent::Import (
    const std::string & encodedLists
) override

Parameters:

  • genotype The string representation of an LGP agent.

Implements cowboys::GPAgentBase::Import

function Initialize

Initialize the agent after being given an action map.

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

Returns:

Success.

function LGPAgent

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

function MutateAgent

Mutate this agent.

inline virtual void cowboys::LGPAgent::MutateAgent (
    double mutation_rate=0.01
) override

Parameters:

  • mutation_rate The probability of any instruction being changed

Implements cowboys::GPAgentBase::MutateAgent

function PrintAgent

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

Implements cowboys::GPAgentBase::PrintAgent

function SerializeGP

Serialize this agent to XML.

inline virtual void cowboys::LGPAgent::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

Public Static Functions Documentation

function EncodeActions

Encodes the actions from an agent's action map into a vector of string, representing action names.

static inline std::vector< std::string > cowboys::LGPAgent::EncodeActions (
    const std::unordered_map< std::string, size_t > & action_map,
    const std::vector< std::string > & sensorsNamesList,
    const std::vector< std::string > & operationsList,
    std::vector< std::string > & actionsList
) 

Parameters:

  • action_map The action map from the agent.
  • sensorsNamesList The list of sensors from the agent.
  • operationsList The list of operations from the agent.
  • actionsList The list of actions from the agent.

Returns:

A vector of strings, representing action names.

Protected Attributes Documentation

variable actionsList

std::vector<std::string> actionsList;

variable currentInstructionIndex

size_t currentInstructionIndex;

variable gen

std::mt19937 gen;

variable instructionsList

std::vector<std::tuple<std::string, int, int> > instructionsList;

variable operationsList

std::vector<std::string> operationsList;

variable possibleInstructionsList

std::vector<std::string> possibleInstructionsList;

variable rd

std::random_device rd;

variable resultsList

std::vector<int> resultsList;

variable sensorsNamesList

std::vector<std::string> sensorsNamesList;

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