How to sort a queue with different agent types by agent comparison in Anylogic?

Let's have a model in which two type of agents arrive to the system: dogs and cats. This agents have a parameter age of type double. The agents go into a unique queue that should be ordered by age and then be served by a single server and get out of the system as seen in the following example Proposed model.

My first question is: How to order the queue by agent comparison using the age attribute?

The main issue I face is that the queue block (as almost all blocks) require to define a single agent type in the advanced properties. First I tried to do it directly in the queue using the agent type "Agent", as the attribute name is the same for both entity types (queue example1), but then I get the error "age cannot be resolved or is not a field" as the general agent type "Agent" doesn't have such an attribute. Then, I tried casting the agent1 and agent2 to dog and cat as seen in (queue example2), but of course during the runtime I get the error dog can't be casted to cat or viceversa as we can't know if agent1 is going to be of type cat or dog at a given time.

Thinking of the version in which I route the agents through exit/enter blocks, I get into the same issue, the only agent type that I could use in the enter block to merge different agent types is "Agent", but then the attribute age of the different agent types can't be used to sort the queue.

My second question is: how to route n agent types to x different locations so that the individual parameters or variables can be used afterwards without casting the agent type (as we don't know which is going to get into the block)?

Upvotes: 0

Views: 1006

Answers (1)

Felipe
Felipe

Reputation: 9431

you need to create another agent type called for example Animal where you will store the age variable... then cat and dog will extends from that agent... you can do that in the advanced properties of the agent: extends.

With that, the agent that will be used in your process will be of type animal... so your second question is not needed anymore.

Upvotes: 1

Related Questions