Search code examples
anylogic

Send Message from Agent Type 1 to Agent Type 2 in Anylogic Agent Based Model


I am trying to send message from Transition 1 (Inside Agent Type Consumers) to Transition 3 (Inside Agent Type Forklift).

So, I have got two agent types Agent Type Consumer has a population of 1000 and Agent Type Forklift has a population of 5

Now, I am trying to send message from Agent Type Consumer to another agent Type Forklift.

Is there a way to send message to Forklift from Consumer using sendToRandom("Buy A!");?


Solution

  • You need to understand model hierarchy and how your agent populations are embedded in your model.

    Assume both are embedded as populations in Main, then you can send a message from a Consumer to a Crane using send("My Message", main.randomFrom(pop_MyCranes);

    But there are a million other ways as well...

    Check this to understand hierarchy: https://anylogic.help/advanced/code/access.html#where-am-i-and-how-do-i-get-to

    Check this to learn more about messages: https://anylogic.help/anylogic/agentbased/communication.html#communication-between-agents