Mirror species
A mirror species keeps its population synchronized with a target population. GAMA reconciles the mirror population during initialization and before its simulation step, creating or disposing mirror agents to match the targets. If the target population changes after that check, the corresponding mirror update occurs at the next reconciliation. Each mirror agent has a target attribute that refers to the agent it represents. Mirror species can also provide an alternate representation of agents, as in the visualization example below.
Declaration​
A mirror species is declared with the mirrors facet. Add this declaration to the model:
species B mirrors: A {
}
In this case, the species B mirrors the species A.
To place each mirror at its target's location, define location in the mirror species:
species B mirrors: A {
point location <- target.location update: target.location;
}
target is a built-in attribute of a mirror species. It refers to the instance of the species tracked.
Attributes of the target agent can be read through target. For example, if species A declares an integer attribute named attribute1, add this variable to species B:
species B mirrors: A {
int value <- target.attribute1;
}
Example​
The example below displays agents of species A as moving white circles and their mirrors in species B as blue spheres positioned five units above their targets on the z-axis.
Here is an example of an implementation for this model:
model Mirror
global {
init{
create A number:100;
}
}
species A skills:[moving]{
reflex update{
do wander();
}
aspect base{
draw circle(1) color: #white border: #black;
}
}
species B mirrors: A{
point location <- target.location update: {target.location.x,target.location.y,target.location.z+5};
aspect base {
draw sphere(2) color: #blue;
}
}
experiment mirroExp mode: gui {
output {
display superposedView renderer: 3d{
species A aspect: base;
species B aspect: base transparency:0.5;
}
}
}
The same example is available in the model library as Mirror species.gaml.
For a population that changes during a simulation, Mirror species - creation and death of agents.gaml demonstrates mirrors being added and removed as their targets change.