0
votes

In a model I have two agent populations: OriginalAgent and CopiedAgent. They are different agent types. Each CopiedAgent is copied from a OrginalAgent, and they share the same values for p_id.

What I want to achieve is to remove an instance of CopiedAgent once OriginalAgent enters a final state in its statechart.

I have created a function myfunction that is called in the Action field of the final state in the statechart of OriginalAgent. The function errors when called, but it shows what I've tried:

int agent_index = 99999;
for(int i=0; i<main.CopiedAgent.size();i++){
    if(p_id == main.CopiedAgent(i).p_id){
        agent_index = main.CopiedAgent(i).p_id;
    }
}

if(my_biopsy_index != 99999)
main.remove_CopiedAgent(agent_index);

I believe the error originates from the loop, as the if-statement works as expected if I hardcode a specific index-value and comment out the loop.

1
can you specify the exact error you get?Felipe

1 Answers

1
votes

try this maybe?

for(int i=0; i<main.CopiedAgent.size();i++){
    if(p_id == main.CopiedAgent(i).p_id){
        main.remove_CopiedAgent(i);
        break;
    }
}