How to make agent in AnyLogic moveTo() in a order? - anylogic

Hi I am building a model that requires agent to move locations in a sequence.
I used the for loop to iterate all of required locations.
However, the result is ridiculous. The agent is heading direct to the final destination and ignores my order.
How do I fix it?
I tried multiple ways, using isMoving() for indicating if the agent reaches the point, but isMoving always returns true once the process starts.

you need to understand that a moveTo needs to be finished before doing a new one, you can't just do a bunch of moveTo instructions together and expect anylogic to guess what you meant.
So these are the steps
1 create a list in which you define all the destinations in the order that you want
2 go to the first item in the list and use moveTo
3 when the agent arrives to the destination (using statecharts and transition triggered by arrival to destination) remove the first item on the list
4 if there's nothing else in the list, do nothing or return home, otherwise, go back to 2

Related

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

Holding agents before a select output element to avoid default port

I've been trying to model a scenario but still cannot find the best way to do it. The scenario is as follows:
Agents arrive at a point where they need to choose one of three paths. Each path is a delay with capacity 1. If the first path already has an agent in it (in the delay block), then the 1st condition is not met and the agent tries the second port. In the second port, if the delay block is available it can proceed, otherwise it checks the third. If all are busy, then the agent should wait in a queue before the select output.
To model this process, I used the following sequence:
Queue > Hold > Select Output 5 > 1 Delay element of capacity 1 after each of the three first output ports of the select output
The condition for the select output is for example "Delay1.size() == 0" then for the second port "Delay2.size() == 0", etc.
Then, I created a function that checks if all delay.size() == 1, then the hold element is set to blocked to avoid having agents going through the select output's default port. The function is tested at every "On Enter" and "On Exit" fields of all the blocks.
Despite the above, agents are still going through the default port which means that the hold element is not working properly.
Is there a more efficient way to model the described scenario? Thank you!
Well, you are not actually blocking your Hold element at all, hence agents will walk through anytime :-)
There are many ways for such a situation.
You could replace the Delay with a Wait element instead. Whenever an agent leaves one of your Delay blocks, you unblock the Hold.
Whenever an agent passes the Hold, you block it, but only if all 3 pathes are currently busy.
Should do the trick

Avoiding collisions with other objects while moving an Agent to a specific destination

I have in my model some free-moving agents, which travel to specific nodes. I use the function...
moveTo(node)
...to specify the node an agent should visit. Using this function, the agent travels the shortest path to the node. However, the model layout contains areas (i.e. image files), which the agent should not pass. Right now, the agents may travel through these areas to reach their destination. Now I'm wondering, whether there is an easy way to permit an agent to enter specific areas in the model, when traveling to a node.
I already took a look at the example model "Wandering Elephants" where the elephants are permitted to walk through areas with water. The solution there is, that if an elephant meets water in the direction it's currently heading, it randomly searches for another direction, until it finds one without water. However, this approach doesn't really fit to my problem, as the elephants in the model wander around without any specific destination. I'm searching for a method, which works for an agent that travels to a specific point. In the best case, the agent would search the shortest path around the obstacle to reach its destination.
Edit 1: The following figure shows my problem in a nutshell. On the left side is my model structure, while on the right side the state chart of my custom agent. What is happening in the model: The 3 sources are producing agents, which will be delayed for an uncertain time (delay stops with stopDelay()). Everytime an agent enters a delay, the delay is added to the collection request. My customagent check requests in a loop until the collection contains at least one request. Then, the customagent randomly selects a request (i.e. delay object) to serve. Each delay is associated with a node (the collection processNodes maps delays to nodes). Now, I want to cast my customagent to a Transporter and move it to the corresponding node. The agent should avoid collisions with the stripped walls in the model. I want to avoid any seizing and releasing of resources. I just want to adapt the behaviour of the Transport agent from the material handling library to my agent.
Edit 2:
In my current testbed, my custom agent does not consider node 1 or node 2. For testing, the agent should only try to reach node without any collisions.
I found a sufficient work-around. Not exactly what I wanted, but it works. Against my initial intention, I use now seize and release for transports. However, I added a hold-block in front of each seized-block and only a resource, which decides to serve the process, is able to unblock the corresponding hold. The on-enter control of the unblocked hold ensures that the hold is directly blocked again as soon as a single agent flows through. For the case that other users are also interested in the solution, I attached the flow-chart of the process and the state-chart of the Transporter-Agent. The system structure is quite the same as in my initial question.
There is no build-in way unless you use transporters from the Material handling library (or pedestrians). These can do what you need.
So easiest might be to convert you agents to transporters temporarily.
Otherwise, you will have to code something yourself...

Pick front item from a two deep pallet rack

I'm am storing agents two deep in a single pallet rack with a rackStore block. When I take items out of the rack with rackStore it tries the take the agents at the back first and I get the error below saying it couldn't be picked as there are other agents in front of it.
Anyone know how I can pick from the front instead?
This is big fail in the AnyLogic Software and it is something they have to fix urgently. Since when it comes to deep positions, you have to control everything manually.
I will give you an example that is definitely not optimal on how to solve your particular question and it will be just a step for you to understand how to extend it to something more than this. Because even though this should be a very easy question, it is not. This will work only 2 racks with 2 levels deep, 1 level of height, and a unique row.
So this is the structure you would need:
Since I have no idea how long your products stay on the rack, I will assume something, which is that with the event, I will make the decision on wether getting or not a product from the rack every 5 seconds (this is absolutely arbitrary).
You will need a custom agent to store the deep position. I call the agent Box and I will have a population of boxes. Not in the picture that I also add agents to the custom population boxes.The box agent will have 2 variables: deep and position which will store the position and deep level of the agent in the rack (you will need also level and row if you have a more complex rack)
Now on the event, which runs cyclically every 5 seconds, I have the following action: (it activates if there is a box waiting, if there is a resource available and if there is no forklift moving a product to the pallet rack) I have to do this because I cannot know where the forklift is going to put the box until the box is already in the pallet rack. Then I check if a box is not behind another with the findFirst function and if everything ok, a box is sent to be picked.
if(wait.size()>0 && resourcePool.idle()>0 && rackStore.size()==0){
Box bx=findFirst(wait,b->b.deep==0);
if(bx!=null)
wait.free(bx);
}
On the rackStore exit I need to store the positions so in the "on exit" action, this code will help (you check if there is another box in the same position, and if there is, you update the value of the deep variable. Then you store the value of the position and deep of the new agent)
Box box=findFirst(wait,b->b.position==position);
if(box!=null){
box.deep++;
}
agent.deep=0;
agent.position=position;
Finally on the rackPick on exit action, once the product is picked and delivered, you update the deep value of the box that was behind it (if any)
Box bx2=findFirst(wait,b->b.position==agent.position);
if(bx2!=null){
bx2.deep--;
}
I know all this looks a bit crazy, but you have to create all the logic yourself when it comes to using deep levels...

Moving one agent within another agent in Anylogic

I am making simple distribution center in Anylogic.I did make truck agent and i am able to move it from one gis point to another gis point.
But I want to load some other agents(Let's say banana agent) into my truck agent and then trucks start their journey(if truck is full of banana).How can i do this?
I hope you have already solved your problem from almost a year ago. However, since there is no specific answer, I'll leave it here for anyone who might get stuck with the same problem.
Anylogic's Process Modelling Library (PML) has an element called Pickup and its opposite, Dropoff. This is used to do exactly what you asked: to load some element into a transporter (either a truck, a forklift, or even a person).
To use the block as you asked you would need a topology like in the picture:
The Queue elements are necessary to hold elements until the pickup occurs.
The Pickup element might pick elements in three modes:
While a given condition is True;
An exact amount (if available);
All available agents.
I'm assuming all trucks must be completely filled up to its maximum capacity. Hence, the chosen mode will be the second one where the exact amount will be TruckCapacity, a parameter of agent Truck.
The selected mode picks up agents (in this case Bananas) up to the desired amount. However, if nothing is available or the present amount is inferior to the desired, the native behavior of the Pickup block is to allow the container element to simply go through it and pick only what's available.
To prevent such behavior, I've created a restricted area where only 1 Truck can be at a time. Additionally, the Hold block WaitFullyLoaded (set to initially blocked) forces the container agent Truck to be fully loaded. Whenever a Banana enters the Queue waitTruck, a verification is performed to check if 1 Truck can be filled. If so, allows passage for that one truck:
if(self.size()/TruckCapacity>=1){
WaitFullyLoaded.unblock();
}
To block WaitFullyLoaded again, when the truck passes through the restrictedAreaEnd block, it performs WaitFullyLoaded.block();
The main idea is this. However, many features can be added and changed.
Hope this helps,
Luís