0

I have two variables in agent

  1. handicap = RandonTrue(0.3)
  2. priority.

The priority variable value set in source exit based on wither agent is handicap or not, as shown in the image below.

enter image description here

Now in the queue I set Queuing to priority base and set agent priority to agent.priority . Shown in image below.

enter image description here

Note: Queue capacity is set to 10.

Now when I run the model and 10 agents enter I the queue, according to the priority handicap agents should be on the top of the queue but that is not happening. shown in the image below.

enter image description here

When the agents enter the delay after the queue, I also print their priorities on the console. The result is still the same, no priority is followed.

enter image description here

In the above image it is clear that they are not sorted based on priority. Why priority queue is not working?

Moreover, I also changed the Queuing to LIFO, queue showed the same result, showing zero effect on agents.

2
  • Contrary to popular belief, efficient priority queue implementations are not sorted. They offer no guarantee about the order of storage, but rather they guarantee that items polled from the queue will come out in priority order. If the set is not sorted, that proves nothing, you would need to confirm that removal by polling violates priority ordering. Note — I’m not an Anylogic user, but if I recall correctly it is based on Java. Java’s priority queues work correctly, but exhibit this “out of order” behavior when printed. Commented Feb 4, 2023 at 18:32
  • Thank you for your input. I print the agents priority on console when they leave the queue. They are violating the priority order. i am also adding the screenshot above. Commented Feb 4, 2023 at 18:41

1 Answer 1

1

this happens because contrary to the intuitive idea that events happen in the order you see, they don't... Things occur in the following order:

  1. agent is created with the default value for the priority value
  2. on at exit action is executed
  3. the queue priority value is checked for the queue
  4. the on exit action is executed

So from the point of view of the queue, the priority for all agents is the same

Solution Instead of setting the priority value "on exit" do it on the "on at exit" action of the source block

Sign up to request clarification or add additional context in comments.

1 Comment

Agreed. In general, you are better off using on at exit vs on exit in 95% of use cases anyway so best always do that (until you fully understand the subtle difference)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.