3
votes

Good morning, I'm new on AnyLogic platform and I have started to study it because I want to use it to map the business processes of the company. I've plan to use the Process Model Library of the tool to model the different departments with the aim to study how are now implemented the information flows between departments.

My diagram will be composed by ''source'' elements and different ''assembler'' elements and I would like that the last ones (the assemblers) work as gateways. I enclose a simple diagram to illustrate better the situation (example).

Suppose that ''sourceA'' and ''sourceB'' (placed in different departments) generate two different documents implemented with two custom agents (e.g. agents generated from ''sourceA'' have an ''orderID'' parameter and agents generated from ''sourceB'' have a ''qualityCheckID'' parameter) that are conveyed on the respective queues before reach the assembler component (placed in a different department). The queues, with an high probability are not aligned during the simulation (queue[10] = agent.orderID is set to 10 and queue[10] = agent.qualityIDCheck is set to 9) becuase the departments are not synchronized. I would like that the assembler work as a gateway so it waits for agents that have ''orderID'' equals to ''qualityCheckID'' (that means that the products on a specific order have been validated by the quality department).

Reading the documentation I saw that the agents reach the assembler port when it is free and wait in the queue otherwise. Due to the asynchronization may happen that in the assembler ports are present agents that not have orderID equals to qualityCheckID and in this case I don't want that the assembler's output will be produced. May happen that the necessary agent is in the queue and not in the port so the "assembler" have to search inside the queues to find if the corrisponding agent is present and if it is remove it from the queue (substitute the wrong agent in the port bringing this last one in the queue and produce the output)

Someone can help me to understand how this scenario can be implemented.

1

1 Answers

1
votes

Good morning Andrea.

There are some alternatives to this. If both the IDs are generated incrementally (1, 2, 3, ...., N) you can use a Match block and it will synchronize your flow. Plus, you can remove your queue elements as this block already has queues incorporated.

However, if the IDs are generated randomly, you might need to do some kind of a work around and use Java code and functions. What I would do would be the following:

Instead of using a Queue (which sends the agents out as soon as the next block is available) I would use the Wait block (which is pretty much a Queue but does not order elements nor does it send the agents out until you want it. Read the description on AnyLogic and it will be clear).

Whenever an agent enter a Wait Block I would add it to a LinkedHashMap or HashMap collection with an Integer (or the type of your order parameter) key and Agent value (one for each Wait Block). This would allow easier information access (rather than searching through the entire Wait contents every time I wanted to check if a specific agent was there). The next step would be to simply check if on the other Wait Block(s) there are the elements I need to perform the assembly task. If so, free them all (and the current agent).

The code is as follows:

On Enter:

WaitBlockHashMap.put(agent.orderID, agent)
if (WaitBlockHashMap2.get(agent.orderID)!=null) { //if the matching element 
                                                  //is on the other Wait Block
    self.free(agent);
    WaitBlock2.free(WaitBlockHashMap2.get(agent.orderID));
}

or

WaitBlockHashMap.put(agent.qualityCheckID, agent)
if (WaitBlockHashMap2.get(agent.qualityCheckID)!=null) { //if the matching element 
                                                         //is on the other Wait Block
    self.free(agent);
    WaitBlock2.free(WaitBlockHashMap2.get(agent.qualityCheckID));
}

Depending on the type of agent in that Wait Block.

I do hope this is helpful, Luís