In Anylogic How can I model truck that deliver orders to multiple clients - anylogic

I'm creating a model based on the product delivery example provided by AnyLogic. In my own model, I want a truck to deliver multiple orders in one trip instead of one. My process diagram is shown below. Here, an order enters via the enter block and several orders are accumulated in the batch block. Every order has a specified destination. How do I model the truck such that it combines two orders and move to the nearest delivery location first and then the second etc?
The main problem is that I don't know the code that accesses the parameter "Delivery location" in each order.
enter image description here
enter image description here
Additional information:
The orders agents are generated and the delivery location is stored in a parameter called "client"
The batch block combines (lets say 2) orders into a batch of the type Order ( advanced settings set to population of agents)
The service block pulls a truck from the resource poule and send the batch of orders to the truck agent using send(batch.unit)
The truck agent stores the order/orders(?) in a variable called "order"
Then, a moveTo function should deliver the order to the first destination
What would be the code to move to the first, second etc., destination?

Here is the conceptual piece you are probably not aware of, and that should help you move in the right direction:
you can have "for loops" as part of your process flows. Below, you see an example where an agent keeps driving to places until it has no more parcels.
Obviously, the details of the blocks depend on your model but in each, you can access the truck's orders if you have them in your Truck agent type (which is needed, obviously).

Related

How to use my agent to enter a process flow of a specific agent (ex: Depot[0]) from a population of agent (ex: Depots)?

So, I have a case in anylogic where a drone needs to be transported via a bike from a certain place (namely, Depot) to a certain place (namely, Stopover Point). After that, the drone will be released from the bike and will do some mapping to a set of designated locations of Mapping Points. For this case, I used a process flow to make the bike (that I treat as a resource unit) to seize the agent (drone) at the Depot before the bike move to the Stopover Point and releasing the drone there.
At first, I used to make some kind of sandbox model where I only use one Depot and one Stopover Point
so that it is easier when I want to use my agent (drone) in a process flow via enter block (ex: I only have to write main.depot.enter.take(this); at my agent (drone) statechart to enter it to the process flow at Depot bacause the Depot is a single agent).
The problem occurs when I tried to use more than one Depot and make it as a population of agent. This makes me unable to use main.depot.enter.take(this); because of the property of the Depot for it is now a population of agent and not a single agent anymore.
The question is how should I do if I want my agent (drone) to enter the process flow of a certain/specific Depot (ex: only Depot[0])? I have used a paramater such as "name" with the value consists of texts like "Depot 1, Depot 2, and so on" and modify the commmand to filter(main.depots, a -> a.name == "Depot 1").enter.take(this); or main.depot[0].enter.take(this); but I think that's not the right way to code it because it didn't works. So, how is exactly the correct way to code or to do it if I want my agent to enter a process flow of a specific agent (ex: Depot[0]) from a population of agent (ex: Depots)? Thank you.
You should use () instead of [] to select one depot from the population.
So to select the one with index 0, you write: main.depot(0).enter.take(this).
To select a depot based on the name parameter, I would use the findFirst function which selects one of the depots. In your exitblock, you could write:
main.depot(findFirst(main.depot, a->a.name.equals("Depot1")).getIndex()).enter.take(this)
The getIndex()method returns the index of the selected agent.

Batching multiple agents based on location of agent

In my model I only want to batch agent which are at the same location. So my source block generates the agents according to a database to a specific node (which is sometimes different for agents), now I want the agents that occur at the same node to batch in sizes of 2 and the one that are left over need to be batched alone.
How can I model this, I know that I can use the selectoutput (which says for example if location=node1 use this output etc) option, but do I than have to add for example manually 100 outputs if I've 100 different locations where the agents start or is there a more simple solution for this problem?
Added later:
Or is there another way to model my idea:
So I'm simulating an hospital environment, where logistic employees (in this case the transporter) based on predefined times collects the thrash on certain areas for example the databaserow I show in the picture below:
At 9:50, the thrash at thrash collection point at LAB_Office_2_H_T_N can be collected by the logistic employee.
So in my model I create this 2 agents (which are 2 containers, last column) based on this time and seize a transporter to collect this thrash. Since a logistic employee is able to collect 2 thrash in one time I want to batch it and let the logistic employee collect 2 thrash containers at once.
After that he transports it to the thrash dump area and is released.
The colors changed after the added information. You can use pickup and dropoff blocks instead. You can define your node requirements in the condition cell. You can use local variables like container and agent to code whatever you want. Or use "Quantity (if available)" option. There you can programmatically define how many units will be picked up by using your own function.

How to create orders for picking process at warehouse operations using Anylogic

During the creation of a generalized warehouse model, I ran into a problem when trying to create an order event that can be used by order pickers to retrieve the products from the storages racks. Currently, I am using a source block which creates "orders" of a single type of pallet (1 to 5). The pickers each travel to pick up a pallet from the rack and transports them to the next location.
Question: How can I create an order consisting out of several pallets consisting of different types.
Question: How can I use a single picker (resource) to pick multiple pallets in a single run through the warehouse before transporting all the pallets to the next location (process).
Kind regards,
Stefan
Question 1
normally i would create a class for the higher level order (say Pickwave class).
And when instantiating it you need to save a list of actual picking orders(pallets) into it (say collection of type ArrayList<Order>).
And to process your pickwave you can use a loop which will steer your resource/transporter/picker to the next Order location until all orders are picked. If everything is picked you exit your loop and move to your next location
Question 2
you don't really pick the orders as you would normally pick them using RackPick block in 1-to-1 scenario. But as you have a refence to all your orders inside you pickwave object you can still control their location/animation programmatically.

How to use "wait" in anylogic?

I have a stock agent which is created in the end of my production line. My products are characterized by their model. I'm trying to create a logic to take out the products from this stock agent when they are to be delivered to the client. This delivery is controlled by an excel sheet and I'm taking the information through a SQL code. However, I was not able to find the right code to take out the products which are to be delivered. My agent population is called ProdutoStock and it's located in my main screen.
I have tried: Main.remove_ProdutoStock() but i couldn't figure out the arguments that i need for this function, since i have to take out of the agent a specific number of agents and also of a specific model.
So, I decided to create a wait block and use the free function to free the specific agents i wanted main.waiting_delivery.free() but i also can't figure out the necessary arguments for this function.
Would someone have any idea how I can take out of my agent/line the products that I need to deliver for my client (considering quality and also model)? This code is not being typed into my main screen.
the argument of the free method is the agent itself.
So you have to do main.waiting_delivery.free(yourAgent);
If you want to free the last agent that entered the wait block:
if(main.waiting_delivery.size()>0)
main.waiting_delivery.free(main.waiting_delivery.get(0));
If you want to free agents following a certain condition
List <YourAgent> theAgents=findAll(main.yourAgentPopulation,a->a.condition==true);
for(YourAgent a : theAgents){
main.waiting_delivery.free(a);
}

How to programmatically manage startWatch and stopWatch in an AnyLogic model

I'm building a model with AnyLogic using the Process Model Library (PML).
In my network I have 4 "source" elements that emits agents, they are all of the same type but with a different "category" string ID inside them (saved as a variable) to differentiate them; they are purchase order from different departments. I have also inserted blocks to measure the time the agents spend to exit from the assembler elements (you will see in the picture inside the red circles). This is the time that I will want to plot in a graph to show how fast they are.
After some test and reading the documentation I have see that when an agent pass under the start photocell (agent of any department) a timer is activated and the opposite when an agent (agent of any department) pass under the stop photocell the timer is stopped. Also in case of agent with different category IDs.
How can I synchronize the timers to measure time of object with the same category ID? I want that if the first source element "Category Nilo&Salmoni" produce an agent the stopWatch measure the time of this one and not of another one, emitted from another category, that reach the stopwatch first.