From 665dc58830ae232a9baf87f0695258c0b933a989 Mon Sep 17 00:00:00 2001 From: Matthew Andres Moreno Date: Wed, 15 Nov 2023 01:20:33 -0500 Subject: [PATCH] Impl, test load/save deme parasite memory score --- avida-core/source/actions/SaveLoadActions.cc | 62 ++++++++++++++++++- avida-core/source/main/cDeme.h | 3 + .../config/detailgermlines-500.sgerm | 5 +- .../demes_loadbirthcounts/config/events.cfg | 5 +- .../expected/data/deme_replication.dat | 1 - .../expected/data/injectlog.dat | 7 --- .../expected/data/out-10.sgerm | 9 +-- .../expected/data/out-10.spop | 4 +- 8 files changed, 76 insertions(+), 20 deletions(-) delete mode 100644 avida-core/tests/demes_loadbirthcounts/expected/data/deme_replication.dat delete mode 100644 avida-core/tests/demes_loadbirthcounts/expected/data/injectlog.dat diff --git a/avida-core/source/actions/SaveLoadActions.cc b/avida-core/source/actions/SaveLoadActions.cc index 6504c3ffc..5e4143862 100644 --- a/avida-core/source/actions/SaveLoadActions.cc +++ b/avida-core/source/actions/SaveLoadActions.cc @@ -188,16 +188,18 @@ class cActionSaveGermlines : public cAction private: cString m_filename; bool m_birthcounts; + bool m_parasitememoryscores; public: cActionSaveGermlines(cWorld* world, const cString& args, Feedback& feedback) - : cAction(world, args), m_filename(""), m_birthcounts(false) + : cAction(world, args), m_filename(""), m_birthcounts(false), m_parasitememoryscores(false) { cArgSchema schema(':','='); // String Entries schema.AddEntry("filename", 0, "detailgermlines"); schema.AddEntry("birthcounts", 0, 0, 1, 0); + schema.AddEntry("parasitememoryscores", 1, 0, 1, 0); cArgContainer* argc = cArgContainer::Load(args, schema, feedback); @@ -206,6 +208,7 @@ class cActionSaveGermlines : public cAction m_filename = argc->GetString(0); // Integer Entries m_birthcounts = argc->GetInt(0); + m_parasitememoryscores = argc->GetInt(1); } delete argc; @@ -233,6 +236,11 @@ class cActionSaveGermlines : public cAction deme.GetBirthCount(), "Deme Birth Count", "deme_birth_count" ); } + if (m_parasitememoryscores) { + df->Write( + deme.GetParasiteMemoryScore(), "Deme Parasite Memory Score", "deme_parasite_memory_score" + ); + } df->Endl(); } @@ -363,6 +371,57 @@ class cActionLoadBirthCounts : public cAction }; +class cActionLoadParasiteMemoryScores : public cAction +{ +private: + cString m_filename; + bool m_verbose; + +public: + cActionLoadParasiteMemoryScores(cWorld* world, const cString& args, Feedback& feedback) + : cAction(world, args), m_filename(""), m_verbose(false) + { + cString largs(args); + if (largs.GetSize()) m_filename = largs.PopWord(); + if (largs.GetSize()) m_verbose = largs.PopWord().AsInt(); + } + + static const cString GetDescription() { return "Arguments: [string filename='detailgermlines']"; } + + void Process(cAvidaContext& ctx) { + cInitFile input_file( + m_filename, + m_world->GetWorkingDir(), + ctx.Driver().Feedback() + ); + assert(input_file.WasOpened()); + if (m_verbose) printf( + "LoadParasiteMemoryScores input file %s has %d lines.\n", + (const char*)m_filename, + input_file.GetNumLines() + ); + + for (int line_id = 0; line_id < input_file.GetNumLines(); line_id++) { + auto file_props = input_file.GetLineAsDict(line_id); + const int deme_id = Apto::StrAs(file_props->Get("deme_id")); + const double deme_parasite_memory_score = Apto::StrAs(file_props->Get("deme_parasite_memory_score")); + if (m_verbose) + printf( + "LoadParasiteMemoryScores deme %d has %f score.\n", deme_id, deme_parasite_memory_score + ); + + auto& deme = m_world->GetPopulation().GetDeme(deme_id); + deme.SetParasiteMemoryScore(deme_parasite_memory_score); + printf( + "LoadParasiteMemoryScores set deme %d score to %f.\n", + deme_id, + deme.GetParasiteMemoryScore() + ); + } + } +}; + + class cActionLoadStructuredSystematicsGroup : public cAction { private: @@ -477,6 +536,7 @@ void RegisterSaveLoadActions(cActionLibrary* action_lib) action_lib->Register("LoadGermlines"); action_lib->Register("SaveGermlines"); action_lib->Register("LoadBirthCounts"); + action_lib->Register("LoadParasiteMemoryScores"); action_lib->Register("LoadStructuredSystematicsGroup"); action_lib->Register("SaveStructuredSystematicsGroup"); action_lib->Register("SaveFlameData"); diff --git a/avida-core/source/main/cDeme.h b/avida-core/source/main/cDeme.h index ccbcbcb09..e557f638a 100644 --- a/avida-core/source/main/cDeme.h +++ b/avida-core/source/main/cDeme.h @@ -195,6 +195,9 @@ class cDeme parasite_memory_score *= decay; } double GetParasiteMemoryScore() const { return parasite_memory_score; } + void SetParasiteMemoryScore(const double score) { + parasite_memory_score = score; + } void IncOrgCount() { cur_org_count++; } void DecOrgCount() { cur_org_count--; } diff --git a/avida-core/tests/demes_loadbirthcounts/config/detailgermlines-500.sgerm b/avida-core/tests/demes_loadbirthcounts/config/detailgermlines-500.sgerm index 14f8eff7f..2b12f58b3 100644 --- a/avida-core/tests/demes_loadbirthcounts/config/detailgermlines-500.sgerm +++ b/avida-core/tests/demes_loadbirthcounts/config/detailgermlines-500.sgerm @@ -1,5 +1,5 @@ #filetype germline_data -#format deme_id hw_type inst_set sequence deme_birth_count +#format deme_id hw_type inst_set sequence deme_birth_count deme_parasite_memory_score # Mode 1 Germline Save # Tue Aug 29 01:14:50 2023 # 1: Deme ID @@ -7,5 +7,6 @@ # 3: Inst Set Name # 4: Genome Sequence # 5: Deme Birth Count +# 6: Deme Parasite Memory Score -0 2 transsmt ycdBCiEdimFjfCDaknmsAjemEEcgccgssmhEEcsdseDcAcBcggclEEcDEgcvrsAmlzessjhcdcggkhamtmciEEvjDdhjidzoAyndvmEdbgznjDmcjohohooayaxdyalbcekzebjcogEtjgjacblDvubADnslyyocgsAcjCbobffhmvnnAdbDfkmxcagBFfndytqhutjdzfdjsnflfoqCwcvhsjcvbmlsqcjrgyiDivvnFhrArcsmifbClvluDqmCBbtiDhiEfACcarpEczijdljujACbfzuDEFyaqqekizDosbbzjgmpczypqvcrGxab 42 +0 2 transsmt ycdBCiEdimFjfCDaknmsAjemEEcgccgssmhEEcsdseDcAcBcggclEEcDEgcvrsAmlzessjhcdcggkhamtmciEEvjDdhjidzoAyndvmEdbgznjDmcjohohooayaxdyalbcekzebjcogEtjgjacblDvubADnslyyocgsAcjCbobffhmvnnAdbDfkmxcagBFfndytqhutjdzfdjsnflfoqCwcvhsjcvbmlsqcjrgyiDivvnFhrArcsmifbClvluDqmCBbtiDhiEfACcarpEczijdljujACbfzuDEFyaqqekizDosbbzjgmpczypqvcrGxab 42 24.8 diff --git a/avida-core/tests/demes_loadbirthcounts/config/events.cfg b/avida-core/tests/demes_loadbirthcounts/config/events.cfg index e7b452b0a..e7b21bc94 100644 --- a/avida-core/tests/demes_loadbirthcounts/config/events.cfg +++ b/avida-core/tests/demes_loadbirthcounts/config/events.cfg @@ -1,10 +1,9 @@ i InjectSequence ycdBCiEdimFjfCDaknmsAjemEEcgccgssmhEEcsdseDcAcBcggclEEcDEgcvrsAmlzessjhcdcggkhamtmciEEvjDdhjidzoAyndvmEdbgznjDmcjohohooayaxdyalbcekzebjcogEtjgjacblDvubADnslyyocgsAcjCbobffhmvnnAdbDfkmxcagBFfndytqhutjdzfdjsnflfoqCwcvhsjcvbmlsqcjrgyiDivvnFhrArcsmifbClvluDqmCBbtiDhiEfACcarpEczijdljujACbfzuDEFyaqqekizDosbbzjgmpczypqvcrGxab 101 i LoadGermlines detailgermlines-500.sgerm i LoadBirthCounts detailgermlines-500.sgerm 1 - -u 5 ReplicateDeme 1 +i LoadParasiteMemoryScores detailgermlines-500.sgerm 1 u 10 SavePopulation filename=out -u 10 SaveGermlines filename=out:birthcounts=1 +u 10 SaveGermlines filename=out:birthcounts=1:parasitememoryscores=1 u 10 Exit diff --git a/avida-core/tests/demes_loadbirthcounts/expected/data/deme_replication.dat b/avida-core/tests/demes_loadbirthcounts/expected/data/deme_replication.dat deleted file mode 100644 index fcf473520..000000000 --- a/avida-core/tests/demes_loadbirthcounts/expected/data/deme_replication.dat +++ /dev/null @@ -1 +0,0 @@ -5,1,0 diff --git a/avida-core/tests/demes_loadbirthcounts/expected/data/injectlog.dat b/avida-core/tests/demes_loadbirthcounts/expected/data/injectlog.dat deleted file mode 100644 index c4648f141..000000000 --- a/avida-core/tests/demes_loadbirthcounts/expected/data/injectlog.dat +++ /dev/null @@ -1,7 +0,0 @@ -# 1: Update -# 2: Organism ID -# 3: Deme ID -# 4: Facing - -5 1 1 3 -5 2 0 3 diff --git a/avida-core/tests/demes_loadbirthcounts/expected/data/out-10.sgerm b/avida-core/tests/demes_loadbirthcounts/expected/data/out-10.sgerm index 854e6c880..67b04966d 100644 --- a/avida-core/tests/demes_loadbirthcounts/expected/data/out-10.sgerm +++ b/avida-core/tests/demes_loadbirthcounts/expected/data/out-10.sgerm @@ -1,12 +1,13 @@ #filetype germline_data -#format deme_id hw_type inst_set sequence deme_birth_count +#format deme_id hw_type inst_set sequence deme_birth_count deme_parasite_memory_score # Mode 1 Germline Save -# Tue Nov 14 22:24:30 2023 +# Wed Nov 15 01:19:51 2023 # 1: Deme ID # 2: Hardware Type ID # 3: Inst Set Name # 4: Genome Sequence # 5: Deme Birth Count +# 6: Deme Parasite Memory Score -0 2 transsmt ycdBCiEdimFjfCDaknmsAjemEEcgccgssmhEEcsdseDcAcBcggclEEcDEgcvrsAmlzessjhcdcggkhamtmciEEvjDdhjidzoAyndvmEdbgznjDmcjohohooayaxdyalbcekzebjcogEtjgjacblDvubADnslyyocgsAcjCbobffhmvnnAdbDfkmxcagBFfndytqhutjdzfdjsnflfoqCwcvhsjcvbmlsqcjrgyiDivvnFhrArcsmifbClvluDqmCBbtiDhiEfACcarpEczijdljujACbfzuDEFyaqqekizDosbbzjgmpczypqvcrGxab 0 -1 2 transsmt ycdBCiEdimFjfCDaknmsAjemEEcgccgssmhEEcsdseDcAcBcggclEEcDEgcvrsAmlzessjhcdcggkhamtmciEEvjDdhjidzoAyndvmEdbgznjDmcjohohooayaxdyalbcekzebjcogEtjgjacblDvubADnslyyocgsAcjCbobffhmvnnAdbDfkmxcagBFfndytqhutjdzfdjsnflfoqCwcvhsjcvbmlsqcjrgyiDivvnFhrArcsmifbClvluDqmCBbtiDhiEfACcarpEczijdljujACbfzuDEFyaqqekizDosbbzjgmpczypqvcrGxab 0 +0 2 transsmt ycdBCiEdimFjfCDaknmsAjemEEcgccgssmhEEcsdseDcAcBcggclEEcDEgcvrsAmlzessjhcdcggkhamtmciEEvjDdhjidzoAyndvmEdbgznjDmcjohohooayaxdyalbcekzebjcogEtjgjacblDvubADnslyyocgsAcjCbobffhmvnnAdbDfkmxcagBFfndytqhutjdzfdjsnflfoqCwcvhsjcvbmlsqcjrgyiDivvnFhrArcsmifbClvluDqmCBbtiDhiEfACcarpEczijdljujACbfzuDEFyaqqekizDosbbzjgmpczypqvcrGxab 42 24.8 +1 2 transsmt ycdBCiEdimFjfCDaknmsAjemEEcgccgssmhEEcsdseDcAcBcggclEEcDEgcvrsAmlzessjhcdcggkhamtmciEEvjDdhjidzoAyndvmEdbgznjDmcjohohooayaxdyalbcekzebjcogEtjgjacblDvubADnslyyocgsAcjCbobffhmvnnAdbDfkmxcagBFfndytqhutjdzfdjsnflfoqCwcvhsjcvbmlsqcjrgyiDivvnFhrArcsmifbClvluDqmCBbtiDhiEfACcarpEczijdljujACbfzuDEFyaqqekizDosbbzjgmpczypqvcrGxab 0 0 diff --git a/avida-core/tests/demes_loadbirthcounts/expected/data/out-10.spop b/avida-core/tests/demes_loadbirthcounts/expected/data/out-10.spop index e6d371635..8ad5b0f5a 100644 --- a/avida-core/tests/demes_loadbirthcounts/expected/data/out-10.spop +++ b/avida-core/tests/demes_loadbirthcounts/expected/data/out-10.spop @@ -1,7 +1,7 @@ #filetype genotype_data #format id src src_args parents num_units total_units length merit gest_time fitness gen_born update_born update_deactivated depth hw_type inst_set sequence cells gest_offset lineage # Structured Population Save -# Tue Nov 14 22:24:30 2023 +# Wed Nov 15 01:19:51 2023 # 1: ID # 2: Source # 3: Source Args @@ -23,4 +23,4 @@ # 19: Gestation (CPU) Cycle Offsets # 20: Lineage Label -2 dup:int germline (none) 2 2 320 0 0 0 0 6 -1 0 2 transsmt ycdBCiEdimFjfCDaknmsAjemEEcgccgssmhEEcsdseDcAcBcggclEEcDEgcvrsAmlzessjhcdcggkhamtmciEEvjDdhjidzoAyndvmEdbgznjDmcjohohooayaxdyalbcekzebjcogEtjgjacblDvubADnslyyocgsAcjCbobffhmvnnAdbDfkmxcagBFfndytqhutjdzfdjsnflfoqCwcvhsjcvbmlsqcjrgyiDivvnFhrArcsmifbClvluDqmCBbtiDhiEfACcarpEczijdljujACbfzuDEFyaqqekizDosbbzjgmpczypqvcrGxab 50,150 0,0 0,0 +1 div:ext (none) (none) 1 1 320 0 0 0 0 -1 -1 0 2 transsmt ycdBCiEdimFjfCDaknmsAjemEEcgccgssmhEEcsdseDcAcBcggclEEcDEgcvrsAmlzessjhcdcggkhamtmciEEvjDdhjidzoAyndvmEdbgznjDmcjohohooayaxdyalbcekzebjcogEtjgjacblDvubADnslyyocgsAcjCbobffhmvnnAdbDfkmxcagBFfndytqhutjdzfdjsnflfoqCwcvhsjcvbmlsqcjrgyiDivvnFhrArcsmifbClvluDqmCBbtiDhiEfACcarpEczijdljujACbfzuDEFyaqqekizDosbbzjgmpczypqvcrGxab 101 0 0