AvidaGP.hpp
This is a simple, efficient CPU for and applied version of Avida.
- Todo:
Should we save a copy of the original genome? (or create a new “memory” member)
We should clean up how we handle scope; the root scope is zero, so the arg-based scopes are 1-16 (or however many). Right now we increment the value in various places and should be more consistent.
How should Avida-GP organisms take an action? Options include sending ALL outputs and picking the maximum field; sending a single output and using its value; having specialized commands…
-
template<typename HARDWARE>
class AvidaCPU_Base - #include <AvidaGP.hpp>
Public Types
-
using this_t = AvidaCPU_Base<HARDWARE>
-
using inst_t = Instruction
-
using arg_t = size_t
-
using inst_lib_t = AvidaCPU_InstLib<hardware_t, arg_t, INST_ARGS>
-
using genome_t = Genome<Instruction, inst_lib_t>
Public Functions
-
inline void ExitScope()
-
inline void BypassScope(size_t scope)
-
inline AvidaCPU_Base()
Create a default AvidaCPU (no genome sequence, default instruction set)
-
inline AvidaCPU_Base(Ptr<const inst_lib_t> inst_lib)
Create an AvidaCPU with a specified instruction set (but no genome sequence)
-
inline AvidaCPU_Base(const inst_lib_t &inst_lib)
-
AvidaCPU_Base(const AvidaCPU_Base&) = default
Copy constructor.
-
AvidaCPU_Base(AvidaCPU_Base&&) = default
Move constructor.
-
inline virtual ~AvidaCPU_Base()
Destructor.
-
inline void Reset()
Reset the entire CPU to a starting state, without a genome.
-
inline virtual void ResetHardware()
Reset just the CPU hardware, but keep the genome and traits.
-
inline void ResetIP()
Reset the instruction pointer to the beginning of the genome AND reset scope.
-
inline Ptr<const inst_lib_t> GetInstLib() const
-
inline size_t GetSize() const
-
inline size_t size() const
-
inline double GetReg(size_t id) const
-
inline double GetInput(int id) const
-
inline size_t GetNumInputs() const
-
inline double GetOutput(int id) const
-
inline size_t GetNumOutputs() const
-
inline int GetFunStart(size_t id) const
-
inline size_t GetIP() const
-
inline size_t CurScope() const
-
inline size_t GetNumErrors() const
-
inline double GetTrait(size_t id) const
-
inline size_t GetNumTraits() const
-
inline void SetInst(size_t pos, size_t id, size_t a0 = 0, size_t a1 = 0, size_t a2 = 0)
-
inline void SetReg(size_t id, double val)
-
inline void SetInput(int input_id, double value)
-
inline void SetOutput(int output_id, double value)
-
inline double PopStack(size_t id)
-
inline void PushStack(size_t id, double value)
-
inline void SetFunStart(size_t id, int value)
-
inline void SetIP(size_t pos)
-
inline void PushRegInfo(size_t scope_id, size_t reg_id)
-
inline void PushCallInfo(size_t pos)
-
inline void IncErrors()
-
inline void SetTrait(size_t id, double val)
-
inline void PushTrait(double val)
-
inline void PushInst(size_t id, size_t a0 = 0, size_t a1 = 0, size_t a2 = 0)
Add a new instruction to the end of the genome, by ID and args.
-
inline void PushInst(const std::string &name, size_t a0 = 0, size_t a1 = 0, size_t a2 = 0)
Add a new instruction to the end of the genome, by NAME and args.
-
inline void PushInst(const Instruction &inst)
Add a specified new instruction to the end of the genome.
-
inline void PushInst(const Instruction &inst, size_t count)
Add multiple copies of a specified instruction to the end of the genome.
-
inline void PushDefaultInst(size_t count = 1)
Add one or more default instructions to the end of the genome.
-
inline void ProcessInst(const inst_t &inst)
Process a specified instruction, provided by the caller.
-
size_t InstScope(const inst_t &inst) const
Determine the scope associated with a particular instruction.
-
inline void SingleProcess()
Process the NEXT instruction pointed to be the instruction pointer.
-
inline void Process(size_t num_inst)
Process the next SERIES of instructions, directed by the instruction pointer.
-
void PrintInst(const inst_t &inst, std::ostream &os = std::cout) const
Print out a single instruction, with its arguments.
-
void PrintSymbols(std::ostream &os = std::cout) const
Print out a short version of the genome as a single string.
-
size_t PredictNextInst() const
Figure out which instruction is going to actually be run next SingleProcess()
Public Static Attributes
-
static constexpr size_t CPU_SIZE = 16
-
static constexpr size_t INST_ARGS = 3
-
static constexpr size_t STACK_CAP = 16
-
struct Instruction : public InstructionBase
- #include <AvidaGP.hpp>
Public Functions
-
inline Instruction(size_t _id = 0, size_t a0 = 0, size_t a1 = 0, size_t a2 = 0)
-
Instruction(const Instruction&) = default
-
Instruction(Instruction&&) = default
-
Instruction &operator=(const Instruction&) = default
-
Instruction &operator=(Instruction&&) = default
-
inline bool operator<(const Instruction &in) const
-
inline bool operator==(const Instruction &in) const
-
inline bool operator!=(const Instruction &in) const
-
inline bool operator>(const Instruction &in) const
-
inline bool operator>=(const Instruction &in) const
-
inline bool operator<=(const Instruction &in) const
-
inline void Set(size_t _id, size_t _a0 = 0, size_t _a1 = 0, size_t _a2 = 0)
-
inline size_t GetIndex() const override
-
inline Instruction(size_t _id = 0, size_t a0 = 0, size_t a1 = 0, size_t a2 = 0)
-
struct RegBackup
- #include <AvidaGP.hpp>
-
struct ScopeInfo
- #include <AvidaGP.hpp>
-
using this_t = AvidaCPU_Base<HARDWARE>
-
class AvidaGP : public AvidaCPU_Base<AvidaGP>
- #include <AvidaGP.hpp>
Public Types
-
using base_t = AvidaCPU_Base<AvidaGP>
-
using base_t = AvidaCPU_Base<AvidaGP>