Dynamic Resource Set Assignment Anylogic

I am trying to seize a given number of resources dynamically, but I can't figure out the syntax. In the Resource Sets Dynamic Assignment, each unit is represented by the name of the resource set it belongs to. In the picture, the seize block will seize 3 resources of the set "resourcePool".

I need to seize a specific number of resources for each individual agent. Then I tried creating ArrayList of Resource Pool objects and passing it in the dynamic assignment but it doesn't work as the type doesn't match.

For example, let's say I have an agent which requires 4 resources, so the expression needed is: { resourcePool, resourcePool, resourcePool, resourcePool }. How can I assign this expression in a variable or collection of the agent such that it can be used in the Resource Sets Dynamic Assignment box? I think I should finally get something like:

{{agent.resourceSetsToSeize}}

So how to define "resourceSetsToSeize"?

enter image description here

Upvotes: 1

Views: 538

Answers (1)

Jaco-Ben Vosloo
Jaco-Ben Vosloo

Reputation: 3975

You were so close. The only issue is that the parameters inside the agent must be of type ResourcePool[][], an array of arrays. To convert an array list, in your case resourceSetsToSeize to array you need to call toArray() but with the argument of the specific array you want to convert it to. So your code should have looked like

{agent.resourceSetsToSeize.toArray(new ResourcePool[resourceSetsToSeize.size()]}

(Assuming that resourceSetsToSeize is a List object

The code can be a bit confusing, see another example below of how to rather use an array as the parameter and then use that directly without converting.

Here is an agent with the parameter of type ResourcePool[][]

enter image description here

When you create the agent you then create this array and put it in the constructor. As you can see you don't need to use the empty constructor and then assign it, you can make use of your parameterized constructor.

enter image description here

And then in the seize object you can simply access the parameter.

enter image description here

Upvotes: 1

Related Questions