Defining Ant Metadata

Once ants are created and identified, the next steps is to fill some metadata on the ants that will be used for interaction detection, visualisation or for any pre-defined usage.

Ant virtual shapes

In fort-myrmidon each ant has a virtual shape defined as an union of capsules [2], as shown in figure Fig. 1. There are no predefined type in a new experiment, and they must be created [3] before adding a capsule to an ant [4].

An ant virtual shape is defined by a collection of typed capsules

Fig. 1 Ant virtual shape in fort-myrmidon.

Ant virtual shape are defined as a collection of typed capsules. Here each type is assigned an unique color. A capsule is defined as region inside and between two circles.

Capsule are defined in the ant reference frame.

#python
import py_fort_myrmidon as fm

e = fm.Experiment("defining_ant_metadata.myrmidon")

a = e.CreateAnt()

headID = e.CreateAntShapeType("head")
antennaID = e.CreateAntShapeType("antennas")
bodyID = e.CreateAntShapeType("body")


a.AddCapsule(headID,fm.Capsule(c1 = [1,2], c2 = [3,4], r1 = 0.5, r2 = 1.0 ))
a.AddCapsule(antennaID,fm.Capsule(c1 = [1,2], c2 = [3,4], r1 = 0.5, r2 = 1.0 ))
a.AddCapsule(antennaID,fm.Capsule(c1 = [1,2], c2 = [3,4], r1 = 0.5, r2 = 1.0 ))
a.AddCapsule(bodyID,fm.Capsule(c1 = [1,2], c2 = [3,4], r1 = 0.5, r2 = 1.0 ))
a.AddCapsule(bodyID,fm.Capsule(c1 = [1,2], c2 = [3,4], r1 = 0.5, r2 = 1.0 ))

for typeID,c in a.Capsules:
    print(typeID,c)
#R
library(FortMyrmidon)

e <- fmExperimentCreate("defining_ant_metadata.myrmidon")

a <- e$createAnt()

headID = e$createAntShapeType("head")
antennaID = e$createAntShapeType("antennas")
bodyID = e$createAntShapeType("body")


a$addCapsule(headID,fmCapsuleCreate(c1 = c(1,2), c2 = c(3,4), r1 = 0.5, r2 = 1.0 ))
a$addCapsule(antennaID,fmCapsuleCreate(c1 = c(1,2), c2 = c(3,4), r1 = 0.5, r2 = 1.0 ))
a$addCapsule(antennaID,fmCapsuleCreate(c1 = c(1,2), c2 = c(3,4), r1 = 0.5, r2 = 1.0 ))
a$addCapsule(bodyID,fmCapsuleCreate(c1 = c(1,2), c2 = c(3,4), r1 = 0.5, r2 = 1.0 ))
a$addCapsule(bodyID,fmCapsuleCreate(c1 = c(1,2), c2 = c(3,4), r1 = 0.5, r2 = 1.0 ))

a$capsules # a list with all capsules data

for ( typedCapsule in a$capsules ) {
    print(paste(typedCapsule$type,capture.output(typedCapsule$capsule)))
}
#include <fort/myrmidon/Experiment.hpp>

using namespace fort::myrmidon;

auto e = Experiment::Create("defining_ant_metadata.myrmidon");
auto a = e->CreateAnt();

headID = e->CreateAntShapeType("head");
antennaID = e->CreateAntShapeType("antennas");
bodyID = e->CreateAntShapeType("body");


a->AddCapsule(headID,
              std::make_shared<Capsule>(Eigen::Vector2d(1,2),
                                        Eigen::Vector2d(3,4),
                                        0.5,
                                        1.0));
a->AddCapsule(antennaID,
              std::make_shared<Capsule>(Eigen::Vector2d(1,2),
                                        Eigen::Vector2d(3,4),
                                        0.5,
                                        1.0));
a->AddCapsule(antennaID,
              std::make_shared<Capsule>(Eigen::Vector2d(1,2),
                                        Eigen::Vector2d(3,4),
                                        0.5,
                                        1.0));
a->AddCapsule(bodyID,
              std::make_shared<Capsule>(Eigen::Vector2d(1,2),
                                        Eigen::Vector2d(3,4),
                                        0.5,
                                        1.0));
a->AddCapsule(bodyID,
              std::make_shared<Capsule>(Eigen::Vector2d(1,2),
                                        Eigen::Vector2d(3,4),
                                        0.5,
                                        1.0));

for ( const auto & [typeID,capsule] : a->Capsules() ) {
    std::cerr << typeID << " " << *capsule << std::endl;
}

User-defined timed metadata system

fort-studio provides the ability to define timed key/value pair for each ant. Like ant shape type, these keys and their default value must be defined [5] in the experiment before, optionally, be modified [6] or accessed [7] for any ant. Type of key is strongly typed and set in the experiment: i.e. if the key "group" is defined to be a str, assigning an int will result an error. Possible types are restricted to boolean, integer, float, strings or Time [1].

#python
e.SetMetaDataKey("group","worker")
e.SetMetaDataKey("alive",True)

t = fm.Time.Now()

a.GetValue("group",t) # is a worker
a.SetValue("alive",False,t)
a.GetValue("alive",t) # False
a.GetValue("alive",t.Add(-1 * fm.Duration.Second)) # True, it was alive before t
#R
e$setMetaDataKey("group","worker")
e$setMetaDataKey("alive",TRUE)

t <- fmTimeNow()

a$getValue("group",t) # is a "worker"
a$setValue("alive",FALSE,t)
a$getValue("alive",t) # FALSE
a.GetValue("alive",t$add(fmSecond(-1))) # TRUE, it was alive before t
// C++
e->SetMetaDataKey("group","worker");
e->SetMetaDataKey("alive",true);

t = fort::Time::Now();

a->GetValue("group",t); // is a "worker"
a->SetValue("alive",false,t);
a->GetValue("alive",t); // false
a->GetValue("alive",t.Add(-1 * fort::Duration::Second)); // true, it was alive before t

Ant visualization data

It is possible to set or access [8] properties on how ants should be displayed in fort-studio.

#python
a.DisplayColor = fm.DefaultPaletteColor(1)
a.DisplayStatus = fm.Ant.DisplayState.SOLO
#R
a$displayColor = fmDefaultPaletteColor(2)
a$displayStatus = fmAntDisplayState$SOLO
//C++
a->SetDisplayColor(fort::myrmidon::DefaultPaletteColor(1));
a->SetDisplayStatus(fort::myrmidon::Ant::DisplayState::SOLO);