anylogicdowntime

Trigger Downtime programmatically using ResourceTaskStart .startTask(Agent)


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.sstatic.net/xho4L.png [2]: https://i.sstatic.net/C8Ybx.png [3]: https://i.sstatic.net/pyPGH.png [4]: https://i.sstatic.net/3WX8f.png [5]: https://i.sstatic.net/5M2lc.png [6]: https://i.sstatic.net/xGB1W.png


Solution

  • 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.