AnyLogic: Changing ResourcePool based on programmatically created schedule - simulation

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

Related

How to remove agents from population at a similar "Rate" that a Source block is creating agents

I am creating a model where I require agents from a population to be removed at a certain rate after a certain moment in time. This rate should be similar and have the same variability as a "Rate" in a source block. My current method runs, but I would like to know whether this method is accurate and if there exists a more elegant solution.
To begin the removal, I set up a Timeout Event that creates a Dynamic Event.
create_dynamicEvent(exponential(rate));
My dynamic event then removes the agent by sending it through an enter block to a sink block, and sets up another instance of itself.
enter_sink.take(population.get(0));
create_dynamicEvent(exponential(rate));
Thank you for your help
I would also use Dynamic Events. You may want to create the DE in the Source block, though, i.e. each created agent already "schedules" its destruction. May be more appropriate, but it depends on the real system.
Apart from that: all good

AnyLogic: Select specific resource set based on condition

I have created a simple model in AnyLogic (see screenshot). Now I want to add a condition that selects one of the two resource sets in the service block. As an example the following scenario shall apply: If there are more than 5 parts in the queue, worker 3 and worker 4 should perform the service. If there are <= 5 parts in the queue, the service shall be performed by worker 1 and worker 2. This is only meant to be a simplified example. I am primarily interested in solving this problem using a condition. I have already tried different approaches, but without success. Does anyone have an idea how the Java code for this condition could look like?
First, you don't need the queue since the service block already has a queue... So For this particular example in your resource choice conditions you will do the following:
service.queueSize()>5 ? (worker3.containsUnit(unit) || worker4.containsUnit(unit))
:
(worker1.containsUnit(unit) || worker2.containsUnit(unit))
You can change service.queueSize() with queue.size() if you insist in using a queue. After that you need to be sure to recalculate the conditions when needed, for this particular example i think you only need to recalculate them on exit action of the service block:
self.recalculateResourceChoiceConditions();
One easy approach is to use Seize and Delay (and Release once done) blocks instead of Service. Before Seize, you can place your condition in a SelectOutputOut block. Like this:

How to change shift group size of resource pool dynamically during simulation in 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')

How do I seize a subset of seized resources?

I have a pool of 25 agents (Operators). When an Order is generated, I seize a few Operators and move them to one of many different ProductionSuites as determined by a parameter in the Order.
Within the ProductionSuite, I have a variable of type ResourcePool that I would like to use to have these Operators perform tasks.
In the main window, I put this code in the "On seize unit:" code box:
agent.assignedSuite.suiteOperatorPool.addAgentToContents(unit);
but this triggers a NullPointerException error. Am I using the addAgentToContents method incorrectly?
You have not initialized your suiteOperatorPool variable, it's "initial value" field is empty. Hence, this is just an empty shell of type ResourcePool that cannot do anything, including adding agents to it.
You would need to initialize it properly using the ResourcePool API, but I don't think that is possible.
Also, you cannot have resources be part of 2 resource pools, as you are trying to do. You should think of a different way to solve your problem. Maybe rephrase the issue so we can think of alternatives. You might not need a RP at all but just use pure agent functionality...?

Anylogic: How to set Service delay time depending on the resourceSet being used

Basically I've got a Service which can work with two alternatives of ResourceSets. Let's say, the Service would optimally work with one Doctor and one Nurse, but it is also possible to work with only one Doctor if a Nurse isn't available.
Now, assuming the Doctor works slower without a Nurse, the Service's delay time must depend upon the resourceSet being employed at the moment (Doctor+Nurse or Doctor). Any idea how can I program this?
You should also have in mind that my model has various Services in parallel working in the same way, it's not just only one Service line.
Thanks!
You're using Services but, to me, using the combination of Seize, Delay and Release gives you more flexibility.
What I've done is set the resource choice according to the image bellow:
It is important to have the nurses prior to the doctors in the first set (for some reason anylogic would opt for using only the doctor if otherwise - even with a nurse available).
Than, I would write this code:
Which means that if the agent was only able to seize one resource it will take longer (15 is just a random value).
In the delay block, I would set the processing time to agent.processTime
The topology I'm using is this:
Obviously this is a workaround and will not work for every case. You can always change the conditions you verify. I couldn't find a way to check which resource set was picked by the seize operation. If you're in a hurry this will do the trick.
Hope that helps,
Luís