@@ -5398,33 +5398,64 @@ slim_refcount_t Population::TallyMutationReferences(std::vector<Subpopulation*>
53985398 }
53995399 }
54005400
5401+ // std::cout << "TallyMutationReferences() in tick " << species_.community_.tick_ << " :" << std::endl;
5402+ // std::cout << " p_subpops_to_tally == " << p_subpops_to_tally << ", count == " << (p_subpops_to_tally == nullptr ? 0 : p_subpops_to_tally->size()) << std::endl;
5403+ // std::cout << " p_force_recache == " << (p_force_recache ? "T" : "F") << std::endl;
5404+ // std::cout << " cached_tally_genome_count_ == " << cached_tally_genome_count_ << std::endl;
5405+
54015406 // Second, figure out whether the last tally was of the same thing, such that we can skip the work
54025407 if (!p_force_recache && (cached_tally_genome_count_ != 0 ))
54035408 {
5409+ // std::cout << " last_tallied_subpops_.size() == " << last_tallied_subpops_.size() << std::endl;
5410+
54045411 if (((p_subpops_to_tally == nullptr ) && (last_tallied_subpops_.size () == 0 )) ||
54055412 (p_subpops_to_tally && last_tallied_subpops_.size () && (last_tallied_subpops_ == *p_subpops_to_tally)))
54065413 {
54075414 // we can use our cached data; return the cached genome count, which should not have changed
5415+ // std::cout << " REUSING CACHE" << std::endl;
54085416
54095417#if DEBUG
54105418 // check that the cached genome count is correct; note that it includes only non-null genomes
54115419 slim_refcount_t total_genome_count = 0 ;
54125420
5413- for ( const std::pair< const slim_objectid_t ,Subpopulation*> &subpop_pair : subpops_ )
5421+ if (p_subpops_to_tally )
54145422 {
5415- Subpopulation *subpop = subpop_pair.second ;
5416-
5417- slim_popsize_t subpop_genome_count = subpop->CurrentGenomeCount ();
5418- std::vector<Genome *> &subpop_genomes = subpop->CurrentGenomes ();
5419-
5420- for (slim_popsize_t i = 0 ; i < subpop_genome_count; i++)
5423+ // tallying across the specified set of subpops
5424+ for (Subpopulation *subpop : *p_subpops_to_tally)
54215425 {
5422- Genome &genome = *subpop_genomes[i];
5426+ slim_popsize_t subpop_genome_count = subpop->CurrentGenomeCount ();
5427+ std::vector<Genome *> &subpop_genomes = subpop->CurrentGenomes ();
54235428
5424- if (!genome.IsNull ())
5425- total_genome_count++;
5429+ for (slim_popsize_t i = 0 ; i < subpop_genome_count; i++)
5430+ {
5431+ Genome &genome = *subpop_genomes[i];
5432+
5433+ if (!genome.IsNull ())
5434+ total_genome_count++;
5435+ }
54265436 }
54275437 }
5438+ else
5439+ {
5440+ // tallying across all subpops
5441+ for (const std::pair<const slim_objectid_t ,Subpopulation*> &subpop_pair : subpops_)
5442+ {
5443+ Subpopulation *subpop = subpop_pair.second ;
5444+
5445+ slim_popsize_t subpop_genome_count = subpop->CurrentGenomeCount ();
5446+ std::vector<Genome *> &subpop_genomes = subpop->CurrentGenomes ();
5447+
5448+ for (slim_popsize_t i = 0 ; i < subpop_genome_count; i++)
5449+ {
5450+ Genome &genome = *subpop_genomes[i];
5451+
5452+ if (!genome.IsNull ())
5453+ total_genome_count++;
5454+ }
5455+ }
5456+ }
5457+
5458+ // std::cout << " total_genome_count == " << total_genome_count << std::endl;
54285459
54295460 if (total_genome_count != cached_tally_genome_count_)
54305461 EIDOS_TERMINATION << " ERROR (Population::TallyMutationReferences): (internal error) cached case hit incorrectly; cached_tally_genome_count_ is not correct." << EidosTerminate ();
@@ -5434,6 +5465,8 @@ slim_refcount_t Population::TallyMutationReferences(std::vector<Subpopulation*>
54345465 }
54355466 }
54365467
5468+ // std::cout << " CALCULATING FRESH" << std::endl;
5469+
54375470 // Now do the actual tallying, since apparently it is necessary
54385471 if (p_subpops_to_tally)
54395472 {
@@ -5479,6 +5512,7 @@ slim_refcount_t Population::TallyMutationReferences(std::vector<Subpopulation*>
54795512 // set up the cache info
54805513 last_tallied_subpops_ = *p_subpops_to_tally;
54815514 cached_tally_genome_count_ = total_genome_count;
5515+ // std::cout << " cached_tally_genome_count_ == " << cached_tally_genome_count_ << std::endl;
54825516
54835517 return total_genome_count;
54845518 }
@@ -5591,6 +5625,7 @@ slim_refcount_t Population::TallyMutationReferences(std::vector<Subpopulation*>
55915625 gui_total_genome_count_ = total_genome_count;
55925626#endif
55935627
5628+ // std::cout << " cached_tally_genome_count_ == " << cached_tally_genome_count_ << std::endl;
55945629 return total_genome_count;
55955630 }
55965631 else
@@ -5759,6 +5794,7 @@ slim_refcount_t Population::TallyMutationReferences(std::vector<Subpopulation*>
57595794 gui_total_genome_count_ = gui_total_genome_count;
57605795#endif
57615796
5797+ // std::cout << " cached_tally_genome_count_ == " << cached_tally_genome_count_ << std::endl;
57625798 return total_genome_count;
57635799 }
57645800 }
0 commit comments