I've built a generic agent
that will be instantiated several times in the environment:
unit agent_u {
monitor : monitor_u is instance;
};
The monitor prints some messages, e.g.:
unit monitor_u {
run() is also {
message(LOW, "Hello monitor!");
};
};
I would like to add to the monitor's messages which agent instance has printed them. For example, for environment:
extend sys {
first_agent : agent_u is instance;
second_agent : agent_u is instance;
};
the desirable output will be something like that:
first_agent: Hello monitor!
second_agent: Hello monitor!
I could not find anything related to instance name in the reflection API... Is there some way to print an instance name in e?
Thank you for your help
printing with message() will already include the instance pointer, in your case something like:
[0] agent_u-@1: Hello monitor!
[0] agent_u-@2: Hello monitor!
you can distinguish by these @NUM.
or include "me.e_path()" in your message, which will give the full instance path:
message(LOW, me.e_path(), ": Hello monitor!");
[0] agent_u-@1: sys.first_agent.monitor: Hello monitor!
[0] agent_u-@2: sys.second_agent.monitor: Hello monitor!