Hi everyone,
I have a simulation written in C++ in which I need to maintain a variable number of agents, and I am having trouble deciding how to implement it well. Every agent looks something similar to:
class Agent{
public:
Vector2f pos;
float health;
float data[DATASIZE];
vector<Rule> rules;
}
I need to maintain a variable number of agents in my simulation such that:
- Preferably, there is no upper bound on the number of agents
- I can easily add an Agent
- I can easily remove any agent under some condition (say health<0)
- I can easily iterate all agents and do something (say health--)
- Preferably, I can parallelize the work using openMP, because many updates are somewhat costly, but completely independent of other agents.
- (edit) the order of the agents doesn't matter at all
What kind of container or design principles should I use for the agents? Until now I was using a vector, but I think it pretty hard to erase from this structure: something I need to do quite often, as things die all the time. Are there any alternatives I should look at? I thought of something like List, but I don't think they can be parallelized because they are implemented as linked lists with iterator objects?
Thank you