I want to count the number of agents that pass through 'pedFlowStatistics' line in Anylogic - anylogic

In Anylogic 8.5.1, I am doing a simulation for library evacuation, I have set and agent with Option-list that contains different types of users: students, organizers, graduates, and others. Also, I have set 'custom distribution' parameter to set the distribution values for each user. Until now, I have run the model and every thing is working well.
What I want is:
1. to use 'pedFlowStatistics' line in particular places (I can do this);
2. want to count the users that pass this line (I do not know how to do it);
3. then draw a chart to highlight the different number of users that passes that particular line space (I do not know how to do it).
I need help in the above situation, thanks in advance.
I do not have a Java background.

It's not possible to count based on conditions with pedFlowStatistics... you can only count the total pedestrians using:
pedFlowStatistics.countPeds(); // counts total number of pedestrians
pedFlowStatistics.traffic(); //shows the number of pedestrians per hour
You can use these functions directly in your chart.
But since you want to count based on conditions (the type of user they are), you will need to be smart about this and depending on your model, you will have to count pedestrians in a different place... or maybe use 2 ped go to blocks and count in between... it depends on your layout and model.

Related

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.

Multiple agents arrival based on Variable and database column

In my source block I want to be the amount of agents based on two different factors namely the amount of beds and visitors per bed. The visitors per bed is just a variable (e.g. visitors=3) and the amount of beds is loaded from the database table which is an excel file (see first image). Now I want to code this in the code block as shown in the example in image 2, but I do not know the correct code and do not know if it is even possible.
Simplest solution is just to do the pre-calcs in the input file and have in the dbase.
The more complex solution is to set the Source arrivals as:
Now, you read your dbase code at the start of the model using SQL (i.e. the query constructor). Make the necessary computations and create a Dynamic Event for each arrival when you want it to happen, relative to the model start. Each dynamic event then calls the source.inject(1) method.
Better still is to not use Source at all but a simple Enter block. The dynamic event creates the agent with all relevant properties from your dbase and pushes it into the Enter block using enter.take(myNewAgent)
But as I said: this is not trivial

Parameter Variation: Tracking the Metadata

I am trying to use parameter variation in AnyLogic. My inputs are 3 parameters, each varying 5 times. My output is water demand. What I need from parameter variation is the way in which demand changes according to the different combinations of the three parameters. I imagine something like: there are 10,950 rows (one for each day), the first column is time (in days), the second column are the values for the first combination, the second column is the second combination, and so on and so forth. What would be the best way to track this metadata to then be able to export it to excel? I have added a "dataset" to my main to track demand through each simulation, but I am not sure what to add to the parameter variation experiment interface to track the output across the different iterations. It would also be helpful to have a way to know which combination of inputs produced a given output (for example, have the combination be the name for each column). I see that there are Java Actions, but I haven't been able to figure out the code to do what I need. I appreciate any help with this matter.
The easiest approach is just to track this in output database tables which are then exported to Excel at the end of your run. As long as these tables include outputs from multiple runs (and are, for example, only cleared at the start of the experiment not the run), your Parameter Variation experiment will end up with an Excel file having outcomes from all the runs. (You will probably need to turn off parallel execution in the PV experiment so you don't run into issues trying to write to the same Excel file in parallel.)
So, for example, you might have tables:
run_details with columns id, parm1, parm2 and parm3 (with proper column names given your actual parameters and some unique ID generated for each run)
output_demand with columns run_id, sim_time_hrs and demand_value (if, say, you're storing some demand value each hour of simulated time) where run_id cross-references the run's ID in run_details
(There is extra complexity in how you could allocate a unique run ID and how and when you write to/clear those tables, but I'm just presenting the core design. You can also get round the need-serial-execution point by programmatically controlling when you export to Excel, rather than using the built-in "Export tables at the end of model execution" capability, but that's also more complicated.)

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);
}

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