Assign priorities for multiple Seize Blocks for the same resource in AnyLogic - anylogic

I have a not so typical scenario for which I am not sure how to proceed:
There are two stations located at two different locations.
Both stations require the same resource.
The resource moves from station to station once released. So it keeps going from station 1 to station 2 to station 1, etc. until it is seized again. This is modeled by adding a link from the resource process port of the release block. So it is not completely released unless a condition applies. The condition is that there are agents waiting in the queue of the seize block of that same resource. So it should keep moving until it is needed again. The tricky part is that there are two seize blocks for that resource, one for each station. It is possible that agents are ready and waiting in the resource's seize element at both stations. I am adding an image of the resource's process at release. So at "selectOuput4" it checks whether station 1's seize element has agents waiting, if so, the resource is released and can be seized. Otherwise, it moves to station 2 and checks the same but for station 2.
My concern is that there might be a situation where both stations have agents waiting in their respective seize blocks. How can I make sure the resource will be seized by station 1's seize element and not station 2's, and vice versa. Is there a way to control where the resource is going in a case where two seize elements are waiting for it? Or is it always random?
I apologize for the long post, and I hope I managed to deliver my idea properly.

First, I think your design is a bit weird because you keep the resource always seized.
What I would do is first have a statechart in the resource that controls the resource movement from one place to the next so you have more control over it. The statechart would be used to move your resource ONLY when it's not seized. This will allow a case in which your resource is moving from station 1 to station 2 but something comes to station 1 queue and the resource can immediately react and come back to station 1 before it reaches station 2 (if you think it would be a good idea to do that)
The second is that the seize block defines the priority for a task when the agent arrives to the seize block, and your situation requires changing that priority dynamically, which can't be done as far as I know, so the wait block before the seize block is unfortunately a good option.

Related

In AnyLogic make a resource (like an operator) "drive" an agent from a TransporterFleet

I would like to know if in anylogic there is a way to show that a resource (in my case an operator) moves together with a transporter taken from a TransporterFleet.
I attach an image of the blocks involved. Basically you have a seize of a resource from the Operator1 resource pool which is sent to the node where the transporter is located (forkliftsHome1). Once arrived, the transporter starts its unloading operation from a Storage (so far so good).
However, when the transporter arrives at its destination and has finished unloading (I have chosen the option that the transporter does not return to its home), the Operator1 resource from the resource pool is freed as it is still on forkliftsHome1. In practice, Operator1 is occupied as I wanted, but in fact the transport is carried out only by the transporter. Is there any way to move them together so that when Operator1 is released it is on the transporter's location (or on a nearby node)?
this is the image of the blocks I'm talking about: tree blocks I'm interested are seizeOperator1ForRetrieve , retrievePallet , releaseOperator1
This is cheating a bit, but if you do not actually need the operator to travel with the forklift, my solution in a similar situation was making the operator invisible while the forklift transports the item, then as a custom wrap-up task I made the operator jump beside the forklift with a moveTo block then made it visible again
(see the process flow pictured here). This was possible by connecting the operator and forklift with the 'Link to agents' element, so for the destination of the operator I could obtain the x,y,z coordinates of the forklift.

Truck (Agent) Hitbox in process modeling library

im creating some paths with the process modeling library. The trucks shall stop in series when waiting for the "go" signal to go on.
At the moment the trucks are waiting "within" each other.
How to tell the trucks to recognize not the stopnode only but also the hitbox of the truck which arrived before him?
Thanks in advance
Chris
The trucks shall stop in series when waiting for the "go" signal to go on.
At the moment the trucks are waiting "within" each other. [...]
How to tell the trucks to recognize not the stopnode only but also the
hitbox of the truck which arrived before him?
AnyLogic allows for agents to queue along a path (from an animation perspective) whilst in a Queue block. So don't make them move to the stop-node (which I assume you are doing explicitly): make them (from a process point-of-view) go into a Queue which is animated via the path from the stop node 'backwards'. (This is the "Agent location" setting of the Queue block.) How you hold them in the queue and release them when they need to depends on the nature of your model; e.g.,
Use a Hold block following the Queue (if it makes sense to release them all at once)
Use a 'dangling' Queue block which you pull agents out of programmatically (e.g., via its removeFirst function) and then add them somewhere else in the process via an Enter block.
Use a Seize block (which has a built-in Queue you can set the location of) with the resource seized representing the 'token' you need to proceed.
NB: From the process perspective, they are in a Queue which happens to be animated as queueing along a path. This isn't exactly the same as modelling the 'spatial reality' of being in a queue: see this question.
Simple solution is to turn your truck agents into Transporters from the Material-handling library. They have build-in collision avoidance.
However, this can slow large models so you may want to convert them only when you need collision avoidance and then convert back to "simple" Truck agents again.
Else, you need to build your own additional stop-nodes and code spatial queuing manually. Possible but not straight forward

Priority based queue in Anylogic

I am using a priority based queue to pick agents from a pallet rack. Priority of agents can be 0 or 1. If there are 10 agents in palletRack, I want to pick all the agents having priority=1 first. My problem in the current flowchart is: Agents with priority=0 are pickup up before agents with priority=1. May be because the agents enter & leave the Queue block one by one, multiple agents aren't present in the Queue block at the same time so that they can be sorted. How to resolve this?
put a hold block between queueStorage2 and pickFromStorage1 and on the on enter action of queueStorage2, you check if all your agents are there, and if they are (with whatever condition you need to check to be sure everything is there) you unblock the hold with hold.unblock();

How to don’t seize resource units that are not needed?

I’m simulating an unloading process of a ship. The complete unloading of the ship can be perfectly done with only two resources making round trips (load, move to destination, unload, go back to loading) and the ship would never be idle waiting for trucks to load.
I need to demonstrate that if I increase the number of resource units (trucks) to 3, the third one will never be seized because it’s not needed, the problem is that the seize block seizes all units evenly, so at the end, all units end up with a utilization percentage greater than 0.
How can I configure the seize block to only use the needed resources and leave the “excess” units with utilization of zero?
(The real model by default will have many resources available, and ships could need more than two trucks. What I want with this is to determine the best amount of resources needed).
Thank you.
In the ResourcePool there is an options Customize request choice which when set to True will allow Request choice condition function to be created. There it is possible to make sure that the resources taken first are the ones with utilisation > 0. If your assumption is correct then the 3rd truck will never be taken.
you just need to run two experiments. One with 2 trucks and another with three. Then compare them in terms of ship waiting time and truck pool utilization.
I solved the question in a very easy way:
In the Seize block use the option "Customize Resource Choice" with "Resource selection" equal to "Units with top rating" and "Unit rating" = unit.getUtilization().
In the way, Anylogic sorts the idle resources by utilization rating and chooses the most utilized resource, this means that unneeded resources will never be seized.

AnyLogic "End of Shift" logic

I have a resource pool that adds units into the population "forklifts". The agents of type Forklift are chosen by other agents and later seized for specific tasks. There is also a schedule for the resource pool.
The problem is that whenever capacity decreases, forklifts units that are moving in the model (but not seized yet) are halted because they are no longer active. Is there a way to customize the choice of resources for the "end of shift". I cannot find anything in Help or online.
Thanks!
I have tried iterating through the resource pool but there is no function I could find to determine whether a unit is active or not. There are boolean functions for idle and busy.
agent.unload_forklift = findFirst(forklifts, f->f.in_use == false);
There are agents that choose resource agents based on internal variables. Maybe I could iterate through the resource pool instead of the population...
I expect forklifts' capacity to decrease based on a customize signal not randomly.