2

within an AnyLogic project, in the 'seize' block I need to make a custom choice of resources from resource sets. Having in the properties tab of the 'seize' block the field "Resource sets" with the value { {ResourcePool_A, ResourcePool_B} } and the flag "customize resource choice" checked. In the "resource choice condition" code section, I need to make a choice like:

    if (unit isfrom ResourcePool_A)
    {
        if (unit.param_a == value) 
            do something
            ....
    }
    else if (unit isfrom ResourcePool_B)
    {
        if (unit.param_b == value) 
            do something
            ....
    }

How can I check if a resource unit is from a given pool or not and then discriminate resources accordingly with their features? Thank you. Best regards.

Roberto B
  • 43
  • 7

2 Answers2

0

from your question it seems that you don't need to choose a specific resource, but rather do a specific set of actions on the resource once it has been seized. which is why i've added two answers.

1.
If you just want to do a specific set of action. You should just copy your code to the "On seize unit" action in the seize object.

2.
If you want to select a specific resource. the easiest way to do that is to create an Anylogic function resource_selector()that returns a boolean.

if(unit isfrom ResourcePool_A && unit.param_foo == agent.param_bar)
    ...
    your own code 
    ...
    return true;
else
    return false;

and then in the Resource choice condition write:

resource_selector(unit, agent);
0

I solved the issue writing a an Anylogic function that returns a boolean and I used it in the resource choice condition. I implemented "isfrom" to discriminate from which pools the resource is picked up as shown in following code:

`

// cast pool object to the prorper type
ResourcePool t_pool = (ResourcePool)pool;

// resource selection condition
if ( (t_pool == ResourcePool_A && ((Resource_A)unit).param == agent.param_bar) ||
     (t_pool == ResourcePool_B && ((Resource_B)unit).param == agent.param_bar) ) {
    return true;
}
else {
    return false;
}

`

In the Anylogic documentation is not explained that in the resource choice condition of the seize block you have access also to the pool object (this is bad...).

Roberto B
  • 43
  • 7
  • Could you please check what version of AnyLogic is installed on your computer? In the lastest version 7.3.6, "pool" is included into the list of local variables available for the parameter "Resource choice condition". It is also described in the newest help about "Seize"/"Service" block (http://help.anylogic.com/topic/com.xj.anylogic.help/html/_ELR/Seize.html). NOTE: When you click in the edit box of any code parameter, you can see a small light bulb icon in its upper left corner. Hover over it to see the list of possible local variables. – Tatiana Gomzina Jan 11 '17 at 14:22