Namespace cowboys
An Agent based on genetic programming. More...
Namespaces
Type | Name |
---|---|
namespace | base64 A namespace for base64 encoding and decoding. Does not convert to and frombase64 in the typical way. Only guarantees that x == b64_inv(b64(x)), aside from doubles which have problems with precision, so x ~= b64_inv(b64(x)). |
Classes
Type | Name |
---|---|
class | CGPAgent An agent based on cartesian genetic programming. |
class | CGPGenotype Holds all the information that uniquely defines a cartesian graph. |
struct | CGPNodeGene Holds the representation of a cartesian graph node. |
struct | CGPParameters Holds the parameters that define the structure of a cartesian graph. |
class | GPAgent |
class | GPAgentAnalyzer |
class | GPAgentBase |
class | GPAgentRegisters Class to hold the registers of the agent. |
class | GPTrainingLoop <class AgentType, class EnvironmentType> |
class | Graph A graph of nodes that can be used to make decisions. |
class | GraphBuilder A class for building graphs. Graphs are a generic representation, so this class is used to build the specific format of a Cartesian Graph , and also preset graphs. |
class | GraphNode A node in a decision graph. |
class | LGPAgent |
struct | NodeFunction A function pointer wrapper that holds extra arguments for the function pointer. |
class | Sensors |
Public Types
Type | Name |
---|---|
typedef std::vector< std::shared_ptr< GraphNode > > | GraphLayer |
typedef double(*)(const GraphNode &, const cse491::AgentBase &) | InnerFunction Function pointer for a node function. |
enum | SensorDirection |
Public Attributes
Type | Name |
---|---|
constexpr char | HEADER_END = = ';' The separator between the header and the genotype. |
constexpr char | HEADER_SEP = = ',' The separator between each parameter in the header, defining the cartesian graph. |
constexpr size_t | INPUT_SIZE = = 9 Don't know the maximum size a state can be, arbitrary large number. |
constexpr size_t | LAYERS_BACK = = 2 The number of layers preceding a node's layer that the node can reference. |
const int | LISTSIZE = = 100 |
constexpr char | NODE_GENE_SEP = = '.' The separator between each attribute in a node. |
constexpr char | NODE_SEP = = ':' The separator between each node in the genotype. |
constexpr size_t | NUM_LAYERS = = 3 Number of computational layers for each agent. |
constexpr size_t | NUM_NODES_PER_LAYER = = 2 The number of nodes in each layer. |
constexpr unsigned int | TRAINING_SEED = = 0 If this is 0, then a random seed will be used. |
Public Static Attributes
Type | Name |
---|---|
const std::vector< InnerFunction > | FUNCTION_SET = = { |
std::vector<InnerFunction> functions; | |
functions.reserve(NODE_FUNCTION_SET.size() + SENSOR_FUNCTION_SET.size()); | |
functions.insert(functions.cend(), NODE_FUNCTION_SET.cbegin(), NODE_FUNCTION_SET.cend()); | |
functions.insert(functions.cend(), SENSOR_FUNCTION_SET.cbegin(), SENSOR_FUNCTION_SET.cend()); | |
return functions; | |
}() A vector of all the node functions and sensors. |
|
const std::vector< InnerFunction > | NODE_FUNCTION_SET = { |
nullptr, Sum, And, AnyEq, Not, Gate, Sin, Cos, Product, Exp, | |
LessThan, GreaterThan, Max, Min, NegSum, Square, PosClamp, NegClamp, Sqrt} A vector of all the node functions. |
|
const std::vector< InnerFunction > | SENSOR_FUNCTION_SET = {WallDistanceUp, WallDistanceDown, WallDistanceLeft, |
WallDistanceRight, AStarDistance} A vector of all the sensor functions. |
|
constexpr int | WALL = = |
2 |
Public Functions
Type | Name |
---|---|
double | AStarDistance (const GraphNode & node, const cse491::AgentBase & agent) Returns the distance to the grid position represented by the first two inputs using A*. |
double | And (const GraphNode & node, const cse491::AgentBase &) Returns 1 if all inputs are not equal to 0, 0 otherwise. |
double | AnyEq (const GraphNode & node, const cse491::AgentBase &) Returns 1 if any of the inputs besides the first are equal to the first input, 0 otherwise. |
double | Cos (const GraphNode & node, const cse491::AgentBase &) Sums the cos(x) of all inputs. |
std::vector< size_t > | EncodeActions (const std::unordered_map< std::string, size_t > & action_map) Encodes the actions from an agent's action map into a vector of size_t, representing action IDs. |
std::vector< double > | EncodeState (const cse491::WorldGrid & grid, const cse491::type_options_t &, const cse491::item_map_t &, const cse491::agent_map_t &, const cse491::AgentBase * agent, const std::unordered_map< std::string, double > & extra_agent_state) Translates state into nodes for the decision graph. |
double | Exp (const GraphNode & node, const cse491::AgentBase &) Returns the sum of the exp(x) of all inputs. |
double | Gate (const GraphNode & node, const cse491::AgentBase &) Returns the input with index 0 if the condition (input with index 1) is not 0. |
double | GreaterThan (const GraphNode & node, const cse491::AgentBase &) Returns 1 if all inputs are in ascending, 0 otherwise. If only one input, then defaults to 1. |
double | LessThan (const GraphNode & node, const cse491::AgentBase &) Returns 1 if all inputs are in ascending, 0 otherwise. If only one input, then defaults to 1. |
double | Max (const GraphNode & node, const cse491::AgentBase &) Returns the maximum value of all inputs. |
double | Min (const GraphNode & node, const cse491::AgentBase &) Returns the minimum value of all inputs. |
double | NegClamp (const GraphNode & node, const cse491::AgentBase &) Returns the sum of negatively clamped inputs. |
double | NegSum (const GraphNode & node, const cse491::AgentBase & agent) Returns the sum of negated inputs. |
double | Not (const GraphNode & node, const cse491::AgentBase &) Returns 1 if the first input is equal to 0 or there are no inputs, 0 otherwise. |
double | PosClamp (const GraphNode & node, const cse491::AgentBase &) Returns the sum of positively clamped inputs. |
double | Product (const GraphNode & node, const cse491::AgentBase &) Returns the product of all inputs. |
double | Reciprocal (const GraphNode & node, const cse491::AgentBase &) Returns the sum of the reciprocal of all inputs. |
double | Sin (const GraphNode & node, const cse491::AgentBase &) Sums the sin(x) of all inputs. |
double | Sqrt (const GraphNode & node, const cse491::AgentBase &) Returns the sum of square root of positively clamped inputs. |
double | Square (const GraphNode & node, const cse491::AgentBase &) Returns the sum of squared inputs. |
double | Sum (const GraphNode & node, const cse491::AgentBase &) Returns the sum all inputs. |
double | WallDistanceDown (const GraphNode &, const cse491::AgentBase & agent) Returns the distance to the nearest obstruction downwards from the agent. |
double | WallDistanceLeft (const GraphNode &, const cse491::AgentBase & agent) Returns the distance to the nearest obstruction to the left of the agent. |
double | WallDistanceRight (const GraphNode &, const cse491::AgentBase & agent) Returns the distance to the nearest obstruction to the right of the agent. |
double | WallDistanceUp (const GraphNode &, const cse491::AgentBase & agent) Returns the distance to the nearest obstruction upwards from the agent. |
Detailed Description
An Agent based on linear genetic programming.
yeeeeeeeehaaaaaaaaa
Namespace for GPAgent and its related classes.
This file is part of the Fall 2023, CSE 491 course project.
Note:
yeeeeeeeehaaaaaaaaa 🤠
This file is part of the Fall 2023, CSE 491 course project.
Note:
Status: PROPOSAL
currently a static class
Author:
@amantham20
currenly supports only wall distance sensors for left, right, top and bottom. this is library of sensors for a given agent return
Public Types Documentation
typedef GraphLayer
using GraphLayer = std::vector<std::shared_ptr<GraphNode> >;
typedef InnerFunction
Function pointer for a node function.
using InnerFunction = double (*)(const GraphNode &, const cse491::AgentBase &);
Forward declaration of GraphNode
enum SensorDirection
enum cowboys::SensorDirection {
LEFT,
RIGHT,
ABOVE,
BELOW
};
Public Attributes Documentation
variable HEADER_END
constexpr char HEADER_END;
variable HEADER_SEP
constexpr char HEADER_SEP;
variable INPUT_SIZE
constexpr size_t INPUT_SIZE;
variable LAYERS_BACK
constexpr size_t LAYERS_BACK;
variable LISTSIZE
const int LISTSIZE;
variable NODE_GENE_SEP
constexpr char NODE_GENE_SEP;
variable NODE_SEP
constexpr char NODE_SEP;
variable NUM_LAYERS
constexpr size_t NUM_LAYERS;
variable NUM_NODES_PER_LAYER
constexpr size_t NUM_NODES_PER_LAYER;
variable TRAINING_SEED
constexpr unsigned int TRAINING_SEED;
Public Static Attributes Documentation
variable FUNCTION_SET
const std::vector<InnerFunction> FUNCTION_SET;
variable NODE_FUNCTION_SET
const std::vector<InnerFunction> NODE_FUNCTION_SET;
variable SENSOR_FUNCTION_SET
const std::vector<InnerFunction> SENSOR_FUNCTION_SET;
variable WALL
constexpr int WALL;
Public Functions Documentation
function AStarDistance
Returns the distance to the grid position represented by the first two inputs using A*.
double cowboys::AStarDistance (
const GraphNode & node,
const cse491::AgentBase & agent
)
Parameters:
node
The node to get the inputs from.agent
The agent that the node belongs to.
Returns:
The distance to the grid position using A*
function And
Returns 1 if all inputs are not equal to 0, 0 otherwise.
double cowboys::And (
const GraphNode & node,
const cse491::AgentBase &
)
Parameters:
node
The node to get the inputs from.
Returns:
The function result as a double.
function AnyEq
Returns 1 if any of the inputs besides the first are equal to the first input, 0 otherwise.
double cowboys::AnyEq (
const GraphNode & node,
const cse491::AgentBase &
)
Parameters:
node
The node to get the inputs from.
Returns:
The function result as a double.
function Cos
Sums the cos(x) of all inputs.
double cowboys::Cos (
const GraphNode & node,
const cse491::AgentBase &
)
Parameters:
node
The node to get the inputs from.
Returns:
The function result as a double.
function EncodeActions
Encodes the actions from an agent's action map into a vector of size_t, representing action IDs.
std::vector< size_t > cowboys::EncodeActions (
const std::unordered_map< std::string, size_t > & action_map
)
Parameters:
action_map
The action map from the agent.
Returns:
A vector of size_t, representing action IDs.
function EncodeState
Translates state into nodes for the decision graph.
std::vector< double > cowboys::EncodeState (
const cse491::WorldGrid & grid,
const cse491::type_options_t &,
const cse491::item_map_t &,
const cse491::agent_map_t &,
const cse491::AgentBase * agent,
const std::unordered_map< std::string, double > & extra_agent_state
)
Returns:
A vector of doubles for the decision graph.
function Exp
Returns the sum of the exp(x) of all inputs.
double cowboys::Exp (
const GraphNode & node,
const cse491::AgentBase &
)
Parameters:
node
The node to get the inputs from.
Returns:
The function result as a double.
function Gate
Returns the input with index 0 if the condition (input with index 1) is not 0.
double cowboys::Gate (
const GraphNode & node,
const cse491::AgentBase &
)
Parameters:
node
The node to get the inputs from.
Returns:
The function result as a double.
function GreaterThan
Returns 1 if all inputs are in ascending, 0 otherwise. If only one input, then defaults to 1.
double cowboys::GreaterThan (
const GraphNode & node,
const cse491::AgentBase &
)
Parameters:
node
The node to get the inputs from.
Returns:
The function result as a double.
function LessThan
Returns 1 if all inputs are in ascending, 0 otherwise. If only one input, then defaults to 1.
double cowboys::LessThan (
const GraphNode & node,
const cse491::AgentBase &
)
Parameters:
node
The node to get the inputs from.
Returns:
The function result as a double.
function Max
Returns the maximum value of all inputs.
double cowboys::Max (
const GraphNode & node,
const cse491::AgentBase &
)
Parameters:
node
The node to get the inputs from.
Returns:
The function result as a double.
function Min
Returns the minimum value of all inputs.
double cowboys::Min (
const GraphNode & node,
const cse491::AgentBase &
)
Parameters:
node
The node to get the inputs from.
Returns:
The function result as a double.
function NegClamp
Returns the sum of negatively clamped inputs.
double cowboys::NegClamp (
const GraphNode & node,
const cse491::AgentBase &
)
Parameters:
node
The node to get the inputs from.
Returns:
The function result as a double.
function NegSum
Returns the sum of negated inputs.
double cowboys::NegSum (
const GraphNode & node,
const cse491::AgentBase & agent
)
Parameters:
node
The node to get the inputs from.
Returns:
The function result as a double.
function Not
Returns 1 if the first input is equal to 0 or there are no inputs, 0 otherwise.
double cowboys::Not (
const GraphNode & node,
const cse491::AgentBase &
)
Parameters:
node
The node to get the inputs from.
Returns:
The function result as a double.
function PosClamp
Returns the sum of positively clamped inputs.
double cowboys::PosClamp (
const GraphNode & node,
const cse491::AgentBase &
)
Parameters:
node
The node to get the inputs from.
Returns:
The function result as a double.
function Product
Returns the product of all inputs.
double cowboys::Product (
const GraphNode & node,
const cse491::AgentBase &
)
Parameters:
node
The node to get the inputs from.
Returns:
The function result as a double.
function Reciprocal
Returns the sum of the reciprocal of all inputs.
double cowboys::Reciprocal (
const GraphNode & node,
const cse491::AgentBase &
)
Parameters:
node
The node to get the inputs from.
Returns:
The function result as a double.
function Sin
Sums the sin(x) of all inputs.
double cowboys::Sin (
const GraphNode & node,
const cse491::AgentBase &
)
Parameters:
node
The node to get the inputs from.
Returns:
The function result as a double.
function Sqrt
Returns the sum of square root of positively clamped inputs.
double cowboys::Sqrt (
const GraphNode & node,
const cse491::AgentBase &
)
Parameters:
node
The node to get the inputs from.
Returns:
The function result as a double.
function Square
Returns the sum of squared inputs.
double cowboys::Square (
const GraphNode & node,
const cse491::AgentBase &
)
Parameters:
node
The node to get the inputs from.
Returns:
The function result as a double.
function Sum
Returns the sum all inputs.
double cowboys::Sum (
const GraphNode & node,
const cse491::AgentBase &
)
Parameters:
node
The node to get the inputs from.
Returns:
The function result as a double.
function WallDistanceDown
Returns the distance to the nearest obstruction downwards from the agent.
double cowboys::WallDistanceDown (
const GraphNode &,
const cse491::AgentBase & agent
)
Parameters:
agent
The agent that the node belongs to.
Returns:
The distance to the nearest obstruction downwards.
function WallDistanceLeft
Returns the distance to the nearest obstruction to the left of the agent.
double cowboys::WallDistanceLeft (
const GraphNode &,
const cse491::AgentBase & agent
)
Parameters:
agent
The agent that the node belongs to.
Returns:
The distance to the nearest obstruction to the left.
function WallDistanceRight
Returns the distance to the nearest obstruction to the right of the agent.
double cowboys::WallDistanceRight (
const GraphNode &,
const cse491::AgentBase & agent
)
Parameters:
agent
The agent that the node belongs to.
Returns:
The distance to the nearest obstruction to the right.
function WallDistanceUp
Returns the distance to the nearest obstruction upwards from the agent.
double cowboys::WallDistanceUp (
const GraphNode &,
const cse491::AgentBase & agent
)
Parameters:
agent
The agent that the node belongs to.
Returns:
The distance to the nearest obstruction upwards.
The documentation for this class was generated from the following file source/Agents/GP/CGPAgent.hpp