From 399535c6d16d5a3eed5c041d5fd6b5ad30d1fb78 Mon Sep 17 00:00:00 2001 From: Austin Ferguson Date: Wed, 6 Jul 2022 16:42:06 -0400 Subject: [PATCH] Track insts. copied and executed in VirtualCPU --- include/emp/hardware/VirtualCPU.hpp | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/include/emp/hardware/VirtualCPU.hpp b/include/emp/hardware/VirtualCPU.hpp index ba5ed2ba82..88d9e0d4ae 100644 --- a/include/emp/hardware/VirtualCPU.hpp +++ b/include/emp/hardware/VirtualCPU.hpp @@ -71,6 +71,8 @@ namespace emp{ /// it should use in a string representation) emp::vector nop_vec; /// Representation of the contiguous sequence of NOP /// instructions following this instruction in the genome + bool has_been_executed = false; /// Has this instruction been executed? + bool has_been_copied = false; // Has this instruction been copied to an offspring? Instruction() = delete; Instruction(size_t _idx, size_t _id=0, emp::vector _nop_vec = {}) @@ -176,6 +178,23 @@ namespace emp{ const std::unordered_map & GetOutputs() const { return outputs; } /// Return a pointer to the CPU's instruction library Ptr GetInstLib() const { return genome.GetInstLib(); } + /// Return the number of instructions that have been executed + size_t GetNumInstsExecuted() const{ + size_t count = 0; + for(auto inst : genome_working){ + if(inst.has_been_executed) count++; + } + return count; + } + /// Return the number of instructions that have been copied + size_t GetNumInstsCopied() const{ + size_t count = 0; + for(auto inst : genome_working){ + if(inst.has_been_copied) count++; + } + return count; + } + //////// SETTERS @@ -279,10 +298,6 @@ namespace emp{ genome_working.erase(genome_working.begin() + idx); nops_need_curated = true; } - /// Return the number of instruction that have been copied - size_t GetNumInstsCopied() const{ - return copied_inst_id_vec.size(); - } @@ -711,6 +726,7 @@ namespace emp{ GetInstLib()->GetName(genome_working[inst_ptr].idx); PrintDetails(); } + genome_working[inst_ptr].has_been_executed = true; GetInstLib()->ProcessInst(ToPtr(this), genome_working[inst_ptr]); AdvanceIP(); num_insts_executed++;