How to change shift group size of resource pool dynamically during simulation in anylogic? - anylogic

I am trying to use anylogic to model labor shortage in production. I have the workers set as a resource pool with the capacity defined using shift plan, defining the number of workers by different shift. I am trying to include a event module that changes labor capacity for each shift during the middle of simulation. However, anylogic showed me an error saying I cannot change shift group size dynamically. Is there any workaround to allow this to happen? Thank you.

You can recreate the schedule within an event each time you need to perform a change.
AnyLogic's API explains this quite well, see https://help.anylogic.com/index.jsp?topic=%2Fcom.anylogic.help%2Fhtml%2Fdata%2FSchedule_API.html (sample model or 'creating and initializing schedule programmatically on model startup')

Related

AnyLogic: Changing ResourcePool based on programmatically created schedule

I refer to a similar problem here.
I implemented a programmatically created schedule same as in the example model from AnyLogic Cloud. Then I added the suggested code in the capacity field.
Still, my problem is the following runtime error: "The parameter capacitySchedule cannot be changed dynamically". Does it just basically does not work with the resource pool compared to the Transporter Fleet presented in the similar problem? Unfortunately it does not work with a fake schedule either.
Here are some screenshots from my model. Thanks in advance.
To work with dynamic capacity of ResourcePool, I use a schedule shift by plan.
in some cases it meets the need.
The implementation of this is simple, in the schedule you give values 1,2,3 etc. They actually point to a position in the array.
Example of the schedule
And inside the ResourcePool you define it as follows:
Example of the ResourcePool by plane
In my example, at times when the schedule value is 4 the capacity of the ResourcePool is 0 and at other times it is as per my parameters.
Change the "Kapaziät definiert" to "By schedule".
Create a fake schedule object fakeSchedule (normally, not programmatically). Make sure it always returns 0 as the value.
Then, use this call for "Kapazität":
' mySchedule == null ? fakeSchedule : mySchedule`
This will tell the pool to use your schedule if it exists, else the fake one

Creating a dataset from queue size in service block

I am a newbie to anylogic simulations. In my project, I want to take out queue size at every time step from a service block and create a dataset. Similarly, I also want to take out the mean queue size from the same after every replication and create a dataset of that as well. Can anyone help me with how to do it?
Welcome to SOF and AnyLogic. Best post separate issues for separate questions, see this intro to SOF for AnyLogic users.
But for now:
I want to take out queue size at every time step from a service block and create a dataset.
Use a cyclic event that calls myDataSet.add(myServiceBlock.queue.size())
I also want to take out the mean queue size from the same after every replication and create a dataset of that as well.
In your experiment, add a DataSet myMeanResults. In the "On Simulation end" code box of your experiment, call myMeanResults.add(root.myDataSet.getYMean())
Make sure your Datasets can keep enough values!
Also, always check the AnyLogic help and example models. Very often, these basics are covered there already. Else, tell us what you already tried :)

Trasporters are jammed at a specific location in AnyLogic

I hope you are having a great day.
Recently, I tried to build an AnyLogic model with free-space transporters, but I encountered an unexpected situation as shown below.
I thought that there is no logical reason why all the transporters are jammed in a specific position. Is there any solution or possible reason for this situation? I have attached my model for your information.
Thank you for reading this question.
The problem with the traffic jam appears to be due to the fact that there are two few attractors available for the transporters to place the items and then they get stuck waiting for an attractor to become available...
When running your model as-is I get a jam in the stage one area
And in the logic blocks, I can see that the transports are stuck in the "Move By Transporter" block.
If I assume the attractors are set to 4 for a reason I would suggest the following logic - similar to what is described here
You create a list of all the attractors available. See the neat trick in AnyLogic where if you select a bunch of objects and then right-click on them you can automatically create a collection.
You can call it something like attractorsAvailabeStage1
And create a new map to store the WIP agents that will be occupying the attractors
And have a function that will provide the available attractors.
Change the move by transporter option to move to an attractor
And also return the attractor as available once it gets moved from its location
Now you only need to prevent mew agents from entering the area if there is no more attractors left or agents on their way to the attractors
I tested it and it works great for stage 1 you need to do it for all the stages.
On second thought....
seeing that you do have resource pools and service blocks. You can achieve the same logic I described by having resources first size the locations, then go to the transport block, and then be delayed
You first seize the space in the stage, then you move to the space, then you delay it.... then you wait, then seize the space in stage 2, then move there, then release stage 1.
I would go for the latter option

Anylogic ‘how to’ questions

I am using Anylogic for a simulation-modeling class, and I am not anylogic or coding smart. My last and only coding class was MatLab based about 16 yrs ago. I have a few questions about how to implement modeling concepts in a discrete model with anylogic.
How can I add/inject agents directly into a queue downstream from a source? I have tried adding an additional source to use the “Calls of inject() function,” but I am not sure how to implement it after selecting it ( example: what do I do after selecting the Calls of inject() function). I have the new source feeding directly into the queue where I want the inject.
How can I set the release of an agent to a defined schedule instead of a rate? Currently, I have my working model set to interarrival time. But I would like to set the agent release to a defined schedule. (example: agent-1 released at 120 seconds, agent-2 released at 150 seconds, agent-3 released at 270 seconds)
Any help would be greatly appreciated, especially if it can be written in a “explain to me like I am 5yrs old” format.
Question 1:
If you have a source connected directly to a queue, then when you call source.inject() an agent will be created at the source block and go to the queue. If you have 1 source with multiple possible destinations, then you will have to use select output blocks and some criteria to go from the source to the desired queue.
Since you mentioned not being a strong programmer, this probably wouldn't be for you, but I often find myself creating agents via add_population and then just adding them to an ArrayList until I am ready to pull them into the DES flow. Really, there are near infinite ways to control agent flow within AnyLogic.
Question 2:
Option a: Arrivals by "Arrival Table in Database" You can link an AnyLogic database table to Excel, and then the source block will just have an agent arrive based on that table.
Option b: Arrival Schedule - you could set this up manually within the development environment or load your schedule from a database. I prefer option a over option b given your brief description.
Option c: Read in data to variable and then write code to release based on next arrival time. 1,000s of ways to do this, but one example could be a list of doubles (your arrival times), set an event to delay until next arrival, call inject function, remove that arrival from the list. I think option a would be best for you, but given that AnyLogic allows you to add java code, there are no limits to how sophisticated you could make your arrival logic.
For 2) You could also use an event or a dynamic event. The action could be source.inject(1); and you can schedule them to your preferences with variables. Just be vigilant that you re-start the events if necessary.
There is a demo-model from AnyLogic for dynamic events.

My goal is that all resources of a resourcePool perform an action at a specific time. How do I create this iteration?

I am simulating a hospital stay with anylogic, on multiple levels. Each level has its own staff, represented by different ResourcePool (doctor, nurses, OSS) I created the flowchart of the actions concerning the patient. Now I would like, at a specific time (lunch and dinner), the OSS do tour the patients.
How do I set up that all OSS of a ResourcePool go to the rooms?
I would like to create a very small parallel flowchart, with sieze, moveTo, delay and release.
TNX
Easiest way is to use the "Downtime" element to prescribe your resources to do some action, see image below:
Under the "task type" selection, you can send them to a separate flow chart using a "ResourceTaskStart" element and they will do what you put downstream of that (moveto, delay...). Make sure to finish that with a ResourceTaskEnd block.
PS: The "Downtime" block can easily be triggered via a schedule. Make sure to read the help on that block (and the ResourceTaskStart/End blocks) and study the example models that use those.