Luiz Calderoni
Luiz Calderoni

Reputation: 25

How to seize resource based on agent condition

I would like to write a code (presumably at Seize > Resources Sets) that allows me to seize from different resources based on agents' paramenter.

I'm developing a health care model where agents are assigned to one specialty (out of 18 possible specialties) using a parameter for that. In the process model they must seize a resource pool that matches the specialty paramenter (currently there is one resource pool for each of the 18 specialties but all of them using the same agent type "Consultant")

I've tried to use a function and then insert in Seize > Resources Set but it is not working. (I also tried this method explained by Jaco-Ben at: Specifying resource sets in seize block based on agent variable but then comes the error message "cannot convert from Resource Pool[][] to ResourcePool".

I can't upload images but here goes an attempt to describe what I've got so far:

A model with two agents: Patient and Consultant that are both initially empty populations. Patient agent has a parameter that define the specialty (int 1 to 3). The model has simple process with a seize block. There are 2 Resource Pool. I just need to seize the Resource Pool that corresponds to Patient's parameter value.

When I use a function, it looks like this: "Returns Value" Type: Other -> ResourcePool no arguments Then:

that is the only way I can access specialty paramenter

for(Patient p:patients){
    if(p.specialty == 1{
    resourcePool;
    } else {
    resourcePool2;
    }
}
 return null;

The error message says "Syntax error, insert "VariableDeclarator" to complete LocalVariableDeclaration

If I initialize a local variable like: ResourcePool j; and then try to make

if...
j=ResourcePool
return j;
}
return null;

Then the error become Exception during discrete event execution: root.seize: Parameter

But if I retunr j instead of null, then the error becomes: The local variable j may not have been initialized

Many thanks!

Upvotes: 0

Views: 296

Answers (1)

Yossi Benagou
Yossi Benagou

Reputation: 358

Unfortunately you didn't show your code, so it's hard to know what exactly is wrong.

In general, you must distinguish between two modes in the settings of Seize block

  1. (alternative) resource sets - Here you can define several alternative resource sets
  2. units of the same pool - Here you can define ResourcePool block from where the resources are requested (For more details, refer to the Using resources article)

The first option receives a two-dimensional array of ResourcePool, this is also the implementation that appears in the example you mentioned in your question.

But from you I understand that this is not your situation, you want to use one ResourcePool at a time and therefore you need to use the second option.

Option to implement your function (after you've defined a ResourcePool population):

enter image description here

Good luck!

Upvotes: 0

Related Questions