-
I've changed up what I want to do with the ABM, and basically we're going to do some variants on the prisoner's dilemma (with environmental and reproduction costs). What I'm wondering is how conceptually to best limit agent pair interactions to once per step. I'm using Each agent will output a message with its strategy, both agents should be affected by the interaction, but two agents in adjacent positions should play each other once, yet be updated with the reward or penalty for the interaction. I'm trying to avoid keeping a second copy of the array in a macro property and host function to track interactions, but maybe this is the only way? I guess the problem I'm facing is fully wrapping my head around the scope of all the variables and where they're allowed to be updated, for example if these were objects, I'd just keep a list of interactions per agent for the current step, and, once they played together they would not attempt again. Here's the basic outline of what I'm doing: FLAMEGPU_AGENT_FUNCTION(interact, flamegpu::MessageArray2D, flamegpu::MessageNone) {
const unsigned int my_x = FLAMEGPU->getVariable<unsigned int>("x_a");
const unsigned int my_y = FLAMEGPU->getVariable<unsigned int>("y_a");
const unsigned int interaction_radius = FLAMEGPU->environment.getProperty<unsigned int>("max_play_distance");
const float reproduction_threshold = FLAMEGPU->environment.getProperty<float>("reproduce_min_energy");
const float reproduction_cost = FLAMEGPU->environment.getProperty<float>("reproduce_cost");
float my_energy = FLAMEGPU->getVariable<float>("energy");
// iterate over all cells in the neighbourhood
// this also wraps across env boundaries.
for (auto &message : FLAMEGPU->message_in.wrap(my_x, my_y, interaction_radius)) {
flamegpu::id_t local_competitor = message.getVariable<flamegpu::id_t>("id");
// play with the competitor
}
if (my_energy <= 0.0) {
return flamegpu::DEAD;
}
if (my_energy > reproduction_threshold) {
// spawn child in a free adjacent cell
FLAMEGPU->setVariable<float>("energy", my_energy - reproduction_cost);
return flamegpu::ALIVE;
}
return flamegpu::ALIVE;
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 13 replies
-
Continuing to think about this, it may help (but I still can't imagine the way to stop race conditions) to increase the number of layers, and make the appropriate layers conditional, as well as adding a couple of extra agent states, (e.g. ready, played_neighbours...) And the layer structure something like:
|
Beta Was this translation helpful? Give feedback.
Continuing to think about this, it may help (but I still can't imagine the way to stop race conditions) to increase the number of layers, and make the appropriate layers conditional, as well as adding a couple of extra agent states, (e.g. ready, played_neighbours...)
And the layer structure something like: