Can I split a single agent into multiple ones in an AnyLogic split component?

691 views Asked by At

I've a question about the "split" component of AnyLogic PMI library. To better explain the case I will post a picture of a part of the scenario I'm building. AnyLogic circuit.

In the picture above the source element on the left generates objects of type "Requirement" (it is a custom class that inherit from the Agent class). This class represents a matrix with the requirements for every products "Pi" for every customer "Ci" (an example of matrix is given):

Requirement Matrix

This matrix can be viewed as a collection of agents because every rows is an agent to which a first other of my circuit block is concerned (logically it contains information about the quantity of product Pi to be ordered from the product supplier) and every columns is an agent to which a second other of my circuit block is concerned (logically it contains the forecast of sale for customer Ci).

It is possibile, in the "on at enter" event of the split block, build a script that iterates first the rows and emits each one on the "out" split's port and then iterates the columns and emits each one on the "out-copy" split's port. I will post a pseudo-code of the script that I'm thinking to place in the "on at enter" event:

matrix = (Requirement)agent;
Iterator<Object> reqIter = matrix.getRequirements(); //iterate the rows
while (reqIter.hasNext())
{
   Object current = reqIter.next();
   //PUSH current in the out port of the split
}

Iterator<Object> sellIter = matrix.getRequirements(); //iterate the columns
while (sellIter.hasNext())
{
   Object current = sellIter.next();
   //PUSH current in the out-copy port of the split
}
1

There are 1 answers

0
Gregory  Monahov On BEST ANSWER

I would put Sink or Exit block after nuove matrici. Use Sink in case if initial agent-matrix can be destroyed after generation of agents, or Exit if initial agent should saved and reused somehow later. Split block can be removed. Instead of the block, put two Enter blocks connected to the respective following queues.

Inside On Enter action of Sink\Exit execute the code. The generated agent can be injected into the respective queue with enterBlockName.take(new MyAgent(args...));

E.g., considering that code generates instance of Agent type it will be:

matrix = (Requirement)agent;
Iterator<Object> reqIter = matrix.getRequirements(); //iterate the rows
while (reqIter.hasNext())
{
   Object current = reqIter.next();
   enter.take( new MyAgent(current) ); //PUSH current in the top flow
}

Iterator<Object> sellIter = matrix.getRequirements(); //iterate the columns
while (sellIter.hasNext())
{
   Object current = sellIter.next();
   enter1.take( new MyAgent(current) );   //PUSH current in the bottom flow
}