0

Question has been asked and answered before, see Anylogic - dynamic specification of resources to seize. But the multiple trolls on stackoverflow requested me to ask same question again, regardless.. - as asking it there is seen as an "answer" and not a "question".

Anylogic 8.7.2.
I create a Resource Pool myworkers.
Of agent type workers.
Open the workers agent and add a variable offloadBay (or parameter, does not matter), INT, default value 0. In main I use a seize block to seize 4 resources from this pool, but they need to meet the condition offloadBay == 0. In the seize block I select Customise resource choice == true ; Recource choice condition = (unit.offloadBay == 0). On running the project, I get the error - "offloadBay cannot be resolved or is not a field".

It seems reference to the keyword unit does not actually reference the resource unit - none of the unit's parameters, variables, functions, etc. are available to be called when referencing unit.

Please advice on what am I doing wrong? Alternatively, how do I select a resource from the ResourcePool based on a certain condition or property of the resource? (demo project can be provided on request, please advice where to send to)

Cecil
  • 55
  • 6

1 Answers1

0

Try enforcing the resource type. This happens because you are in the seize block and when you use "unit" you may be referring to different resource agent types. Not all of them may have the "offloadBay" variable. So, use:

((Worker)unit).offloadBay == 0

Emile Zankoul
  • 2,161
  • 2
  • 6
  • 18
  • Emile, that does not work. Anylogic now responds with two errors: `offloadBay cannot be resolved or is not a field` and `Incompatible operand type Workers and int` – Cecil Dec 27 '20 at 19:49
  • The error "Incompatible operand type Workers and int" appears when the two sides of "==" are of a different type. This is telling you that the 0 is of type int and whatever is on the other side is of type Workers. Can you copy and paste what exactly you wrote in the Resource choice condition? – Emile Zankoul Dec 27 '20 at 19:54
  • I think you wrote "Workers" instead of "Worker". – Emile Zankoul Dec 27 '20 at 19:55
  • hang on a moment please - you are a bit fast on me... the speed of your response is much appreciated though!! I had `(Workers)unit.offloadBay` - seems there is set of extra brackets required? testing at moment – Cecil Dec 27 '20 at 20:00
  • 1
    That is it yes!! Needs the extra brackets `((Workers)unit).offloadBay` - tested it multiple levels, works perfectly!! Thank you Emile, you're a star!! – Cecil Dec 27 '20 at 20:06