Empirical
Classes | Public Types | Public Member Functions | Public Attributes | List of all members
emp::AvidaHardware< CPU_SIZE > Class Template Reference

#include <AvidaHardware.h>

Classes

struct  RegBackup
 Information about a register that is backed up, to be restored when current scope is exited. More...
 
struct  ScopeInfo
 As different scopes are stepped through, this class provides information about each one. More...
 

Public Types

enum  ScopeType {
  ScopeType::NONE =0, ScopeType::ROOT, ScopeType::BASIC, ScopeType::LOOP,
  ScopeType::FUNCTION
}
 
using this_t = AvidaHardware< CPU_SIZE >
 
using stack_t = emp::vector< double >
 

Public Member Functions

 AvidaHardware ()
 Create a new AvidaGP seeding it with a genome. More...
 
 AvidaHardware (const AvidaHardware< CPU_SIZE > &)=default
 Copy constructor. More...
 
 AvidaHardware (AvidaHardware< CPU_SIZE > &&)=default
 Move constructor. More...
 
virtual ~AvidaHardware ()
 Destructor. More...
 
void ExitScope ()
 Run every time we need to exit the current scope. More...
 
virtual void Reset ()
 
void ResetIP ()
 Reset the instruction pointer to the beginning of the genome AND reset scope. More...
 
double GetReg (size_t id) const
 
double GetInput (int id) const
 
const std::unordered_map< int, double > & GetInputs () const
 
size_t GetNumInputs () const
 
double GetOutput (int id) const
 
const std::unordered_map< int, double > & GetOutputs () const
 
size_t GetNumOutputs () const
 
const stack_tGetStack (size_t id) const
 
int GetFunStart (size_t id) const
 
size_t GetIP () const
 
emp::vector< ScopeInfoGetScopeStack () const
 
size_t CurScope () const
 
ScopeType CurScopeType () const
 
emp::vector< RegBackupGetRegStack () const
 
emp::vector< size_t > GetCallStack () const
 
size_t GetNumErrors () const
 
double GetTrait (size_t id) const
 
const emp::vector< double > & GetTraits ()
 
size_t GetNumTraits () const
 
void SetReg (size_t id, double val)
 
void SetInput (int input_id, double value)
 
void SetInputs (const std::unordered_map< int, double > &vals)
 
void SetInputs (std::unordered_map< int, double > &&vals)
 
void SetOutput (int output_id, double value)
 
void SetOutputs (const std::unordered_map< int, double > &vals)
 
void SetOutputs (std::unordered_map< int, double > &&vals)
 
double PopStack (size_t id)
 
void PushStack (size_t id, double value)
 
void SetFunStart (size_t id, int value)
 
void SetIP (size_t pos)
 
void PushRegInfo (size_t scope_id, size_t reg_id)
 
void PushCallInfo (size_t pos)
 
void IncErrors ()
 
void SetTrait (size_t id, double val)
 
void PushTrait (double val)
 
void PrintState (std::ostream &os=std::cout) const
 Print out the state of the virtual CPU. More...
 
void IncReg (size_t reg_id)
 
void DecReg (size_t reg_id)
 
void NotReg (size_t reg_id)
 
void AddRegs (size_t reg0_id, size_t reg1_id, size_t reg2_id)
 
void SubRegs (size_t reg0_id, size_t reg1_id, size_t reg2_id)
 
void MultRegs (size_t reg0_id, size_t reg1_id, size_t reg2_id)
 
void DivRegs (size_t reg0_id, size_t reg1_id, size_t reg2_id)
 
void ModRegs (size_t reg0_id, size_t reg1_id, size_t reg2_id)
 
void RegTestEqu (size_t reg0_id, size_t reg1_id, size_t reg2_id)
 
void RegTestNEqu (size_t reg0_id, size_t reg1_id, size_t reg2_id)
 
void RegTestLess (size_t reg0_id, size_t reg1_id, size_t reg2_id)
 

Public Attributes

emp::array< double, CPU_SIZE > regs
 Registers used in the hardware. More...
 
std::unordered_map< int, double > inputs
 Map of all available inputs (position -> value) More...
 
std::unordered_map< int, double > outputs
 Map of all outputs (position -> value) More...
 
emp::array< stack_t, CPU_SIZE > stacks
 Stacks for long-term storage. More...
 
emp::array< int, CPU_SIZE > fun_starts
 Postions where functions being in genome. More...
 
size_t inst_ptr
 Which code position should be executed next? More...
 
emp::vector< ScopeInfoscope_stack
 What scopes are we nested in? More...
 
emp::vector< RegBackupreg_stack
 What registers have been backed up? More...
 
emp::vector< size_t > call_stack
 What function calls have to be returned from? More...
 
size_t error_count
 How many errors have occurred? More...
 
emp::vector< double > traits
 A simple way of recording which traits a CPU has demonstrated, and at what qaulity. More...
 

Detailed Description

template<size_t CPU_SIZE = 16>
class emp::AvidaHardware< CPU_SIZE >

Core hardware for building an avida CPU.

Parameters
CPU_SIZEdetermines the number of registers, stacks, etc. to use.

Member Typedef Documentation

template<size_t CPU_SIZE = 16>
using emp::AvidaHardware< CPU_SIZE >::stack_t = emp::vector<double>
template<size_t CPU_SIZE = 16>
using emp::AvidaHardware< CPU_SIZE >::this_t = AvidaHardware<CPU_SIZE>

Member Enumeration Documentation

template<size_t CPU_SIZE = 16>
enum emp::AvidaHardware::ScopeType
strong

ScopeType is used for scopes that we need to do something special at the end. Eg: LOOP needs to go back to beginning of loop; FUNCTION needs to return to call.

Enumerator
NONE 
ROOT 
BASIC 
LOOP 
FUNCTION 

Constructor & Destructor Documentation

template<size_t CPU_SIZE = 16>
emp::AvidaHardware< CPU_SIZE >::AvidaHardware ( )
inline

Create a new AvidaGP seeding it with a genome.

template<size_t CPU_SIZE = 16>
emp::AvidaHardware< CPU_SIZE >::AvidaHardware ( const AvidaHardware< CPU_SIZE > &  )
default

Copy constructor.

template<size_t CPU_SIZE = 16>
emp::AvidaHardware< CPU_SIZE >::AvidaHardware ( AvidaHardware< CPU_SIZE > &&  )
default

Move constructor.

template<size_t CPU_SIZE = 16>
virtual emp::AvidaHardware< CPU_SIZE >::~AvidaHardware ( )
inlinevirtual

Destructor.

Member Function Documentation

template<size_t CPU_SIZE = 16>
void emp::AvidaHardware< CPU_SIZE >::AddRegs ( size_t  reg0_id,
size_t  reg1_id,
size_t  reg2_id 
)
inline
template<size_t CPU_SIZE = 16>
size_t emp::AvidaHardware< CPU_SIZE >::CurScope ( ) const
inline
template<size_t CPU_SIZE = 16>
ScopeType emp::AvidaHardware< CPU_SIZE >::CurScopeType ( ) const
inline
template<size_t CPU_SIZE = 16>
void emp::AvidaHardware< CPU_SIZE >::DecReg ( size_t  reg_id)
inline
template<size_t CPU_SIZE = 16>
void emp::AvidaHardware< CPU_SIZE >::DivRegs ( size_t  reg0_id,
size_t  reg1_id,
size_t  reg2_id 
)
inline
template<size_t CPU_SIZE = 16>
void emp::AvidaHardware< CPU_SIZE >::ExitScope ( )
inline

Run every time we need to exit the current scope.

template<size_t CPU_SIZE = 16>
emp::vector<size_t> emp::AvidaHardware< CPU_SIZE >::GetCallStack ( ) const
inline
template<size_t CPU_SIZE = 16>
int emp::AvidaHardware< CPU_SIZE >::GetFunStart ( size_t  id) const
inline
template<size_t CPU_SIZE = 16>
double emp::AvidaHardware< CPU_SIZE >::GetInput ( int  id) const
inline
template<size_t CPU_SIZE = 16>
const std::unordered_map<int,double>& emp::AvidaHardware< CPU_SIZE >::GetInputs ( ) const
inline
template<size_t CPU_SIZE = 16>
size_t emp::AvidaHardware< CPU_SIZE >::GetIP ( ) const
inline
template<size_t CPU_SIZE = 16>
size_t emp::AvidaHardware< CPU_SIZE >::GetNumErrors ( ) const
inline
template<size_t CPU_SIZE = 16>
size_t emp::AvidaHardware< CPU_SIZE >::GetNumInputs ( ) const
inline
template<size_t CPU_SIZE = 16>
size_t emp::AvidaHardware< CPU_SIZE >::GetNumOutputs ( ) const
inline
template<size_t CPU_SIZE = 16>
size_t emp::AvidaHardware< CPU_SIZE >::GetNumTraits ( ) const
inline
template<size_t CPU_SIZE = 16>
double emp::AvidaHardware< CPU_SIZE >::GetOutput ( int  id) const
inline
template<size_t CPU_SIZE = 16>
const std::unordered_map<int,double>& emp::AvidaHardware< CPU_SIZE >::GetOutputs ( ) const
inline
template<size_t CPU_SIZE = 16>
double emp::AvidaHardware< CPU_SIZE >::GetReg ( size_t  id) const
inline
template<size_t CPU_SIZE = 16>
emp::vector<RegBackup> emp::AvidaHardware< CPU_SIZE >::GetRegStack ( ) const
inline
template<size_t CPU_SIZE = 16>
emp::vector<ScopeInfo> emp::AvidaHardware< CPU_SIZE >::GetScopeStack ( ) const
inline
template<size_t CPU_SIZE = 16>
const stack_t& emp::AvidaHardware< CPU_SIZE >::GetStack ( size_t  id) const
inline
template<size_t CPU_SIZE = 16>
double emp::AvidaHardware< CPU_SIZE >::GetTrait ( size_t  id) const
inline
template<size_t CPU_SIZE = 16>
const emp::vector<double>& emp::AvidaHardware< CPU_SIZE >::GetTraits ( )
inline
template<size_t CPU_SIZE = 16>
void emp::AvidaHardware< CPU_SIZE >::IncErrors ( )
inline
template<size_t CPU_SIZE = 16>
void emp::AvidaHardware< CPU_SIZE >::IncReg ( size_t  reg_id)
inline
template<size_t CPU_SIZE = 16>
void emp::AvidaHardware< CPU_SIZE >::ModRegs ( size_t  reg0_id,
size_t  reg1_id,
size_t  reg2_id 
)
inline
template<size_t CPU_SIZE = 16>
void emp::AvidaHardware< CPU_SIZE >::MultRegs ( size_t  reg0_id,
size_t  reg1_id,
size_t  reg2_id 
)
inline
template<size_t CPU_SIZE = 16>
void emp::AvidaHardware< CPU_SIZE >::NotReg ( size_t  reg_id)
inline
template<size_t CPU_SIZE = 16>
double emp::AvidaHardware< CPU_SIZE >::PopStack ( size_t  id)
inline
template<size_t CPU_SIZE = 16>
void emp::AvidaHardware< CPU_SIZE >::PrintState ( std::ostream &  os = std::cout) const

Print out the state of the virtual CPU.

template<size_t CPU_SIZE = 16>
void emp::AvidaHardware< CPU_SIZE >::PushCallInfo ( size_t  pos)
inline
template<size_t CPU_SIZE = 16>
void emp::AvidaHardware< CPU_SIZE >::PushRegInfo ( size_t  scope_id,
size_t  reg_id 
)
inline
template<size_t CPU_SIZE = 16>
void emp::AvidaHardware< CPU_SIZE >::PushStack ( size_t  id,
double  value 
)
inline
template<size_t CPU_SIZE = 16>
void emp::AvidaHardware< CPU_SIZE >::PushTrait ( double  val)
inline
template<size_t CPU_SIZE = 16>
void emp::AvidaHardware< CPU_SIZE >::RegTestEqu ( size_t  reg0_id,
size_t  reg1_id,
size_t  reg2_id 
)
inline
template<size_t CPU_SIZE = 16>
void emp::AvidaHardware< CPU_SIZE >::RegTestLess ( size_t  reg0_id,
size_t  reg1_id,
size_t  reg2_id 
)
inline
template<size_t CPU_SIZE = 16>
void emp::AvidaHardware< CPU_SIZE >::RegTestNEqu ( size_t  reg0_id,
size_t  reg1_id,
size_t  reg2_id 
)
inline
template<size_t CPU_SIZE = 16>
virtual void emp::AvidaHardware< CPU_SIZE >::Reset ( )
inlinevirtual
template<size_t CPU_SIZE = 16>
void emp::AvidaHardware< CPU_SIZE >::ResetIP ( )
inline

Reset the instruction pointer to the beginning of the genome AND reset scope.

template<size_t CPU_SIZE = 16>
void emp::AvidaHardware< CPU_SIZE >::SetFunStart ( size_t  id,
int  value 
)
inline
template<size_t CPU_SIZE = 16>
void emp::AvidaHardware< CPU_SIZE >::SetInput ( int  input_id,
double  value 
)
inline
template<size_t CPU_SIZE = 16>
void emp::AvidaHardware< CPU_SIZE >::SetInputs ( const std::unordered_map< int, double > &  vals)
inline
template<size_t CPU_SIZE = 16>
void emp::AvidaHardware< CPU_SIZE >::SetInputs ( std::unordered_map< int, double > &&  vals)
inline
template<size_t CPU_SIZE = 16>
void emp::AvidaHardware< CPU_SIZE >::SetIP ( size_t  pos)
inline
template<size_t CPU_SIZE = 16>
void emp::AvidaHardware< CPU_SIZE >::SetOutput ( int  output_id,
double  value 
)
inline
template<size_t CPU_SIZE = 16>
void emp::AvidaHardware< CPU_SIZE >::SetOutputs ( const std::unordered_map< int, double > &  vals)
inline
template<size_t CPU_SIZE = 16>
void emp::AvidaHardware< CPU_SIZE >::SetOutputs ( std::unordered_map< int, double > &&  vals)
inline
template<size_t CPU_SIZE = 16>
void emp::AvidaHardware< CPU_SIZE >::SetReg ( size_t  id,
double  val 
)
inline
template<size_t CPU_SIZE = 16>
void emp::AvidaHardware< CPU_SIZE >::SetTrait ( size_t  id,
double  val 
)
inline
template<size_t CPU_SIZE = 16>
void emp::AvidaHardware< CPU_SIZE >::SubRegs ( size_t  reg0_id,
size_t  reg1_id,
size_t  reg2_id 
)
inline

Member Data Documentation

template<size_t CPU_SIZE = 16>
emp::vector<size_t> emp::AvidaHardware< CPU_SIZE >::call_stack

What function calls have to be returned from?

template<size_t CPU_SIZE = 16>
size_t emp::AvidaHardware< CPU_SIZE >::error_count

How many errors have occurred?

template<size_t CPU_SIZE = 16>
emp::array< int, CPU_SIZE > emp::AvidaHardware< CPU_SIZE >::fun_starts

Postions where functions being in genome.

template<size_t CPU_SIZE = 16>
std::unordered_map<int, double> emp::AvidaHardware< CPU_SIZE >::inputs

Map of all available inputs (position -> value)

template<size_t CPU_SIZE = 16>
size_t emp::AvidaHardware< CPU_SIZE >::inst_ptr

Which code position should be executed next?

template<size_t CPU_SIZE = 16>
std::unordered_map<int, double> emp::AvidaHardware< CPU_SIZE >::outputs

Map of all outputs (position -> value)

template<size_t CPU_SIZE = 16>
emp::vector<RegBackup> emp::AvidaHardware< CPU_SIZE >::reg_stack

What registers have been backed up?

template<size_t CPU_SIZE = 16>
emp::array<double, CPU_SIZE> emp::AvidaHardware< CPU_SIZE >::regs

Registers used in the hardware.

template<size_t CPU_SIZE = 16>
emp::vector<ScopeInfo> emp::AvidaHardware< CPU_SIZE >::scope_stack

What scopes are we nested in?

template<size_t CPU_SIZE = 16>
emp::array< stack_t, CPU_SIZE > emp::AvidaHardware< CPU_SIZE >::stacks

Stacks for long-term storage.

template<size_t CPU_SIZE = 16>
emp::vector<double> emp::AvidaHardware< CPU_SIZE >::traits

A simple way of recording which traits a CPU has demonstrated, and at what qaulity.


The documentation for this class was generated from the following file: