Search code examples
anylogic

Agent inside of an agent-container


I am new to Anylogic and I have a question, how do I find the agent in the agent-container?

The goal is: I have details that go on a pallet (1 detail on 1 pallet), depending on which detail is on the pallet, I need to select the path (in the SelectOutput block). The pallet and the parts (k1 to k3) are different agents. enter image description here

I tried using "instanceof". I've read that .contents() should give me what's inside the agent-container, but the "agent.contents() instanceof k1" doesn't work.

Thanks in advance!


Solution

  • agent.contents() returns a list of agents. You cannot ask a list of agents if it is instance of K1.

    Instead, you need to decide which agent of the contents to check for.

    One solution: Check the first: agent.contents().get(0) instanceof K1 should work.

    But it is up to you to figure out which content agent to check, or all of them, or else...

    Better approach may be to create a variable myAgent in the Pallet agent and fill it when the pallet is filled. Then just refer to that instead of agent.contents()