Skip to content

Commit 3c16903

Browse files
authored
Merge pull request #374 from drbergman/fix-attack-no-detach
fix detachments
2 parents 2c88a02 + 9fc5e87 commit 3c16903

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

core/PhysiCell_standard_models.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,7 +1423,8 @@ void dynamic_attachments( Cell* pCell , Phenotype& phenotype, double dt )
14231423
{
14241424
// check for detachments
14251425
double detachment_probability = phenotype.mechanics.detachment_rate * dt;
1426-
for( int j=0; j < pCell->state.attached_cells.size(); j++ )
1426+
// detach_cells swaps the detached cell with the last cell in the vector, so we need to iterate backwards
1427+
for( int j=pCell->state.attached_cells.size()-1; j >= 0; j-- )
14271428
{
14281429
Cell* pTest = pCell->state.attached_cells[j];
14291430
if( UniformRandom() <= detachment_probability )
@@ -1441,8 +1442,6 @@ void dynamic_attachments( Cell* pCell , Phenotype& phenotype, double dt )
14411442
while( done == false && j < pCell->state.neighbors.size() )
14421443
{
14431444
Cell* pTest = pCell->state.neighbors[j];
1444-
if (phenotype.cell_interactions.pAttackTarget==pTest || pTest->phenotype.cell_interactions.pAttackTarget==pCell) // do not let attackers detach randomly
1445-
{ continue; }
14461445
if( pTest->state.number_of_attached_cells() < pTest->phenotype.mechanics.maximum_number_of_attachments )
14471446
{
14481447
// std::string search_string = "adhesive affinity to " + pTest->type_name;
@@ -1467,9 +1466,12 @@ void dynamic_spring_attachments( Cell* pCell , Phenotype& phenotype, double dt )
14671466
{
14681467
// check for detachments
14691468
double detachment_probability = phenotype.mechanics.detachment_rate * dt;
1470-
for( int j=0; j < pCell->state.spring_attachments.size(); j++ )
1469+
// detach_cells_as_spring swaps the detached cell with the last cell in the vector, so we need to iterate backwards
1470+
for( int j=pCell->state.spring_attachments.size()-1; j >= 0; j-- )
14711471
{
1472-
Cell* pTest = pCell->state.spring_attachments[j];
1472+
Cell* pTest = pCell->state.spring_attachments[j];
1473+
if (phenotype.cell_interactions.pAttackTarget==pTest || pTest->phenotype.cell_interactions.pAttackTarget==pCell) // do not let attackers detach randomly
1474+
{ continue; }
14731475
if( UniformRandom() <= detachment_probability )
14741476
{ detach_cells_as_spring( pCell , pTest ); }
14751477
}

0 commit comments

Comments
 (0)