Skip to content

Commit c2a9c89

Browse files
committed
more optimization flag cleanup
1 parent e5e500e commit c2a9c89

17 files changed

+276
-283
lines changed

core/chromosome.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,11 +1045,6 @@ MutationIndex Chromosome::DrawNewMutation(std::pair<slim_position_t, GenomicElem
10451045

10461046
// addition to the main registry and the muttype registries will happen if the new mutation clears the stacking policy
10471047

1048-
// BCH 1/4/2025: For simplicity we assume that this mutation will be added, and call NoteNonNeutralMutation()
1049-
// here. The worst that will happen is that the simulation will shift to non-neutral unnecessarily.
1050-
if (!mutation->is_neutral_)
1051-
species_.NoteNonNeutralMutation(mutation);
1052-
10531048
return new_mut_index;
10541049
}
10551050

@@ -1447,11 +1442,6 @@ MutationIndex Chromosome::DrawNewMutationExtended(std::pair<slim_position_t, Gen
14471442

14481443
// addition to the main registry and the muttype registries will happen if the new mutation clears the stacking policy
14491444

1450-
// BCH 1/4/2025: For simplicity we assume that this mutation will be added, and call NoteNonNeutralMutation()
1451-
// here. The worst that will happen is that the simulation will shift to non-neutral unnecessarily.
1452-
if (!mutation->is_neutral_)
1453-
species_.NoteNonNeutralMutation(mutation);
1454-
14551445
return new_mut_index;
14561446
}
14571447

core/community.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2610,6 +2610,9 @@ void Community::AllSpecies_CheckIntegrity(void)
26102610
// Check the integrity of all substitution objects
26112611
for (Substitution *sub : species->population_.substitutions_)
26122612
sub->SelfConsistencyCheck(" in AllSpecies_CheckIntegrity()");
2613+
2614+
// Check the integrity of Species optimization flags
2615+
species->CheckOptimizationFlags();
26132616
}
26142617
#endif
26152618
}

core/genomic_element_type.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,8 @@ void GenomicElementType::SetProperty(EidosGlobalStringID p_property_id, const Ei
345345
if (!color_.empty())
346346
Eidos_GetColorComponents(color_, &color_red_, &color_green_, &color_blue_);
347347

348-
// tweak a flag to make SLiMgui update
349-
species_.community_.genomic_element_types_changed_ = true;
348+
// let the species know that our configuration has changed
349+
species_.AutogenerationConfigurationChanged();
350350

351351
return;
352352
}
@@ -410,9 +410,6 @@ EidosValue_SP GenomicElementType::ExecuteMethod_setMutationFractions(EidosGlobal
410410
mutation_types.emplace_back(mutation_type_ptr);
411411
mutation_fractions.emplace_back(proportion);
412412

413-
// let the mutation type know that it is being used
414-
mutation_type_ptr->used_in_GEType_ = true;
415-
416413
// check whether the mutation type is non-neutral; if so, the species is now considered non-neutral
417414
// (because we expect that a non-neutral mutation will be generated by this genomic element type)
418415
// see also Species::ExecuteContextFunction_initializeGenomicElementType() for the same logic
@@ -429,7 +426,7 @@ EidosValue_SP GenomicElementType::ExecuteMethod_setMutationFractions(EidosGlobal
429426
InitializeDraws();
430427

431428
// Notify interested parties of the change
432-
species_.community_.genomic_element_types_changed_ = true;
429+
species_.AutogenerationConfigurationChanged();
433430

434431
return gStaticEidosValueVOID;
435432
}

core/haplosome.cpp

Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2583,9 +2583,8 @@ EidosValue_SP Haplosome_Class::ExecuteMethod_addMutations(EidosGlobalStringID p_
25832583

25842584
// No need to add the mutation to the registry; how would the user ever get a Mutation that was not already in it?
25852585

2586-
// BCH 1/4/2025: the mutation is already in the system, so for now we don't need to note it
2587-
//if (!mut_to_add->is_neutral_)
2588-
// species->NoteNonNeutralMutation(mut_to_add);
2586+
// BCH 1/4/2025: the mutation is already in the system, so its effects have been
2587+
// noted; no call to NoteChangedMutation(mut_to_add) is needed
25892588
}
25902589
}
25912590
}
@@ -2964,10 +2963,6 @@ EidosValue_SP Haplosome_Class::ExecuteMethod_addNewMutation(EidosGlobalStringID
29642963
if (p_method_id == gID_addNewDrawnMutation)
29652964
{
29662965
new_mut = new (mut_block_ptr + new_mut_index) Mutation(mutation_type_ptr, chromosome->Index(), position, origin_subpop_id, origin_tick, (int8_t)nucleotide);
2967-
2968-
// this mutation will be added to the simulation somewhere, so tell the species about it
2969-
if (!new_mut->is_neutral_)
2970-
species->NoteNonNeutralMutation(new_mut);
29712966
}
29722967
else // (p_method_id == gID_addNewMutation)
29732968
{
@@ -2984,10 +2979,6 @@ EidosValue_SP Haplosome_Class::ExecuteMethod_addNewMutation(EidosGlobalStringID
29842979
// FIXME MULTITRAIT: This needs to pass in a whole vector of effects and dominance coefficients now... and hemizygous dominance...
29852980
// FIXME MULTITRAIT this code will also now need to handle the independent dominance case
29862981
new_mut = new (mut_block_ptr + new_mut_index) Mutation(mutation_type_ptr, chromosome->Index(), position, static_cast<slim_effect_t>(selection_coeff), mutation_type_ptr->DefaultDominanceForTrait(0), origin_subpop_id, origin_tick, (int8_t)nucleotide);
2987-
2988-
// this mutation will be added to the simulation somewhere, so tell the species about it
2989-
if (!new_mut->is_neutral_)
2990-
species->NoteNonNeutralMutation(new_mut);
29912982
}
29922983

29932984
// add to the registry, return value, haplosome, etc.
@@ -3484,10 +3475,6 @@ EidosValue_SP Haplosome_Class::ExecuteMethod_readHaplosomesFromMS(EidosGlobalStr
34843475
// FIXME MULTITRAIT this code will also now need to handle the independent dominance case
34853476
Mutation *new_mut = new (mut_block_ptr + new_mut_index) Mutation(mutation_type_ptr, chromosome->Index(), position, static_cast<slim_effect_t>(selection_coeff), mutation_type_ptr->DefaultDominanceForTrait(0), subpop_index, origin_tick, nucleotide);
34863477

3487-
// this mutation will be added to the simulation somewhere, so tell the species about it
3488-
if (!new_mut->is_neutral_)
3489-
species.NoteNonNeutralMutation(new_mut);
3490-
34913478
// add it to our local map, so we can find it when making haplosomes, and to the population's mutation registry
34923479
pop.MutationRegistryAdd(new_mut);
34933480
mutation_indices.emplace_back(new_mut_index);
@@ -4136,10 +4123,6 @@ EidosValue_SP Haplosome_Class::ExecuteMethod_readHaplosomesFromVCF(EidosGlobalSt
41364123
new_mut = new (mut_block_ptr + new_mut_index) Mutation(mutation_type_ptr, chromosome->Index(), mut_position, selection_coeff, dominance_coeff, subpop_index, origin_tick, nucleotide);
41374124
}
41384125

4139-
// this mutation will be added to the simulation somewhere, so tell the species about it
4140-
if (!new_mut->is_neutral_)
4141-
species->NoteNonNeutralMutation(new_mut);
4142-
41434126
// add it to our local map, so we can find it when making haplosomes, and to the population's mutation registry
41444127
pop.MutationRegistryAdd(new_mut);
41454128
alt_allele_mut_indices.emplace_back(new_mut_index);
@@ -4391,7 +4374,6 @@ EidosValue_SP Haplosome_Class::ExecuteMethod_removeMutations(EidosGlobalStringID
43914374
// Construct a vector of mutations to remove that is sorted by position
43924375
std::vector<Mutation *> mutations_to_remove;
43934376
Mutation * const *mutations_data = (Mutation * const *)mutations_value->ObjectData();
4394-
slim_trait_index_t trait_count = species->TraitCount();
43954377

43964378
for (int value_index = 0; value_index < mutations_count; ++value_index)
43974379
{
@@ -4405,20 +4387,12 @@ EidosValue_SP Haplosome_Class::ExecuteMethod_removeMutations(EidosGlobalStringID
44054387

44064388
mutations_to_remove.emplace_back(mut);
44074389

4390+
// Note the removal; it might affect our caching, even if the mutation is neutral
4391+
species->NoteChangedMutation(mut);
4392+
44084393
// If we're not already aware of having removed a non-neutral mutation, check on that now
4409-
if (!any_nonneutral_removed)
4410-
{
4411-
MutationTraitInfo *mut_trait_info = mutation_block->TraitInfoForMutation(mut);
4412-
4413-
for (slim_trait_index_t trait_index = 0; trait_index < trait_count; ++trait_index)
4414-
{
4415-
if (mut_trait_info[trait_index].effect_size_ != (slim_effect_t)0.0)
4416-
{
4417-
any_nonneutral_removed = true;
4418-
break;
4419-
}
4420-
}
4421-
}
4394+
if (!mut->is_neutral_for_all_traits_)
4395+
any_nonneutral_removed = true;
44224396
}
44234397

44244398
std::sort(mutations_to_remove.begin(), mutations_to_remove.end(), [ ](Mutation *i1, Mutation *i2) {return i1->position_ < i2->position_;});

core/individual.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1430,7 +1430,7 @@ EidosValue_SP Individual::GetProperty(EidosGlobalStringID p_property_id)
14301430
}
14311431

14321432
Subpopulation *subpop = subpopulation_;
1433-
double fitness = subpop->individual_cached_fitness_OVERRIDE_ ? subpop->individual_cached_fitness_OVERRIDE_value_ : cached_fitness_UNSAFE_;
1433+
double fitness = subpop->individual_cached_fitness_OVERRIDE_ ? subpop->individual_cached_fitness_OVERRIDE_value_ : (double)cached_fitness_UNSAFE_;
14341434

14351435
return EidosValue_SP(new (gEidosValuePool->AllocateChunk()) EidosValue_Float(fitness));
14361436
}
@@ -1955,7 +1955,7 @@ EidosValue *Individual::GetProperty_Accelerated_cachedFitness(EidosGlobalStringI
19551955
{
19561956
Individual *ind = (Individual *)(p_values[value_index]);
19571957

1958-
float_result->set_float_no_check(ind->cached_fitness_UNSAFE_, value_index);
1958+
float_result->set_float_no_check((double)ind->cached_fitness_UNSAFE_, value_index);
19591959
}
19601960
}
19611961
}
@@ -1965,7 +1965,7 @@ EidosValue *Individual::GetProperty_Accelerated_cachedFitness(EidosGlobalStringI
19651965
{
19661966
Individual *ind = (Individual *)(p_values[value_index]);
19671967
Subpopulation *subpop = ind->subpopulation_;
1968-
double fitness = (subpop->individual_cached_fitness_OVERRIDE_ ? subpop->individual_cached_fitness_OVERRIDE_value_ : ind->cached_fitness_UNSAFE_);
1968+
double fitness = (subpop->individual_cached_fitness_OVERRIDE_ ? subpop->individual_cached_fitness_OVERRIDE_value_ : (double)ind->cached_fitness_UNSAFE_);
19691969

19701970
float_result->set_float_no_check(fitness, value_index);
19711971
}
@@ -5493,6 +5493,7 @@ EidosValue_SP Individual_Class::ExecuteMethod_readIndividualsFromVCF(EidosGlobal
54935493
if (info_mutids.size() > 0)
54945494
{
54955495
// a mutation ID was supplied; we use it blindly, having checked above that we are in the case where this is legal
5496+
// FIXME MULTITRAIT: This needs to pass in a whole vector of effects and dominance coefficients now...
54965497
slim_mutationid_t mut_mutid = info_mutids[alt_allele_index];
54975498

54985499
new_mut = new (mut_block_ptr + new_mut_index) Mutation(mut_mutid, mutation_type_ptr, chromosome->Index(), mut_position, selection_coeff, dominance_coeff, subpop_index, origin_tick, nucleotide);
@@ -5504,10 +5505,6 @@ EidosValue_SP Individual_Class::ExecuteMethod_readIndividualsFromVCF(EidosGlobal
55045505
new_mut = new (mut_block_ptr + new_mut_index) Mutation(mutation_type_ptr, chromosome->Index(), mut_position, selection_coeff, dominance_coeff, subpop_index, origin_tick, nucleotide);
55055506
}
55065507

5507-
// all mutations seen here will be added to the simulation somewhere, so tell the species about it
5508-
if (!new_mut->is_neutral_)
5509-
species->NoteNonNeutralMutation(new_mut);
5510-
55115508
// add it to our local map, so we can find it when making haplosomes, and to the population's mutation registry
55125509
pop.MutationRegistryAdd(new_mut);
55135510
alt_allele_mut_indices.emplace_back(new_mut_index);

0 commit comments

Comments
 (0)