1

In my model I have a Resource Pool representing an equipment, which has a downtime defined by a Downtime block. The Downtime is defined by triggers and sends its tasks to a flowchart.

Besides the standard Downtime procedure I want to trigger a Downtime programmatically, using:

`cleaning_and_conditioning_mld_617_411.startTask(Eq_MLD_617_411);`

I get the following error:

Eq_MLD_617_411 cannot be resolved to a variable

How can I fix this?

Edit: changed the code to

cleaning_and_conditioning_mld_617_411.startTask(new Eq_MLD_617_411());

Now I get a NullPointerException (see Picture 6).

Please find attached pictures of the model. [1]: https://i.stack.imgur.com/xho4L.png [2]: https://i.stack.imgur.com/C8Ybx.png [3]: https://i.stack.imgur.com/pyPGH.png [4]: https://i.stack.imgur.com/3WX8f.png [5]: https://i.stack.imgur.com/5M2lc.png [6]: https://i.stack.imgur.com/xGB1W.png

General Grievance
  • 4,555
  • 31
  • 31
  • 45

1 Answers1

0

Eq_MLD_617_411 is the name of your ResourceUnit type. You will need to provide an actual resource unit for the downtime to start.

Unfortuantely you can't simply call cleaning_and_conditioning_mld_617_411.startTask(new Eq_MLD_617_411()); because new Eq_MLD_617_411() will create a new agent but not have any connection to the engine. (hence you got the null pointer exception on ...engine.Utilities.time

Instead, you need to always create agents using the AnyLogic provided add_myPopulation() which becomes available as soon as you create a population of any agent type on the canvas.

Now in your case, since you have a resource pool, we need to access the resource units that belong to that pool... yet there is no resourcePool.getUnit() function available... so now what?

One option is to add the resource units of the pool to a population that you create

enter image description here

And then you can call a resource unit from that population to start downtime

enter image description here

I tested it and pressing the button during run time reduces the available resources.

Jaco-Ben Vosloo
  • 3,770
  • 2
  • 16
  • 33
  • Thanks for your answer. I changed the Code to: `cleaning_and_conditioning_mld_617_411.startTask(new Eq_MLD_617_411());` Now I get a NullPointerException (see EDIT in the OP). – Sebastian Melchior Jul 20 '21 at 10:53
  • Apologies Sebastian, my original answer missed an important aspect of creating agents programmatically, see the updated answer. Let me know if this helps – Jaco-Ben Vosloo Jul 20 '21 at 12:25