Search code examples
priority-queueanylogic

Priority queue from 2 sources in AnyLogic


Good day! I tried to build the network model in AnyLogic 8.7.6. I have 2 sources with different priorities (the packets from the first source obtain priority 2, and the packets from the second source obtain priority 1). The packets from the sources are transmitted to the Queue. The Queue should sort them by Priority.

enter image description here

The priority parameters are defined in Agents at the Sources.

enter image description here

I made a simple experiment. The Source 1 generates 1 agent per sec and the Source 2 generates 10 agents per sec. We see that the queue is empty :(

enter image description here

I have no idea why. The Queue doesn't sort them according to their priority.

P.S. Sorry, I have russian language version of Anylogic.


Solution

  • Without seeing the queue capacities, if you have two queues connected to each other agents will enter the first one and immediately go to the next queue... so they are never prioritized because they never queue in the first queue, where I assume you set up the prioritization.

    Try deleting the connection between the two queues and simply see if the agents get ordered according to your priority.

    See a small test below

    I have a custom agent type with a variable priority and a simple flow chart with 2 sources and a queue

    enter image description here

    As per your example, I am setting the priority variable of the agents generated in Source1 to 2, and in source 2 they are set to 1.

    In the queue, I set my ordering to be based on priority and tell the block to use the priority variable inside the agents (the higher the higher the priority)

    enter image description here

    For the example, I set source1 to generate agents every minute and source 2 to generate every second.

    The expectation is that as soon as an agent from source1 gets generated it will jump the queue and go stand first inline

    When I run the model and I click to see the details of the queue, I can see that as soon as the agent from source1 gets created it jumps the line.

    enter image description here

    You can always create a custom toString() function to determine what must be displayed when you click on the queue block

    enter image description here