Measure intersection delay time - anylogic

Using the Road Traffic Library, I have created a 4-way intersection that is stop-controlled and I need to measure the average delay for each approach. Currently I am using timeMeasureStart and timeMeasureEnd blocks, showing the time taken as the car enters the road/model, until it exits the intersection.
Instead, I want to measure from the time the car slows to 40km/h, until it exits the intersection. Any suggestions?
The initial speed of all cars entering the model is 60 km/hr.

Sure, there is no pre-defined way but this custom approach should work:
make sure your cars are a custom agent type, not the default cars. Lets name it My Car
add a variable myTimeBelow40 into MyCar of type double
check the car speed regularly (every 0.1 sec?!) in an event in MyCar.checkSpeed. Use the getSpeed() function. If it is below 40 KPH, you log the current time into myTimeBelow40
log the departure time of your car: your time since 40 KPH is the difference
Finally, add a statistic across your car population or log your individual car duration into main

#Benjamin thank you for pointing me in the right direction.
Here is my solution, guided by the suggestion. I'm sure it could be refined but in the end it is what worked for me and my limited knowledge of AnyLogic.
For a 4-way intersection, I wanted the delay for each approach, so I created 4 custom car agents, with each populations starting out empty.
In each agent, I had 2 variable blocks - var_Start and var_Slow, an one event block set to Timeout, Cyclic, first read at time(), and proceeding in intervals of 0.1s. In the event action, i specidied the following:
if(getSpeed(KPH) <= 40) {
var_Slow=time();
var_Slow.suspend();
}
In main I used Histogram Data, labeled as dataDelay, and a chart with the mean showing, to see the results. I had one for each intersection.
Back in the car agent, in actions on startup:
var_Start=time();
and on destroy:
if(var_Slow = 0)
main.dataDelay.add(time()-var_Start);
else
main.dataDelay.add(time()-var_Slow);
At the car source block in main, I kept the initial and prefered speed at 60, however if there were cars backed up then new cars were often initiated at a slower speed, sometimes already below 40kph, hence the if,else code on destroy.
I had everything labeled according to its corresponding approach direction, unlike the simplified version I have here.

Related

I have a process to move a picking agent and a product through the same delay block

Currently, I have two delay blocks above each other, where one agent goes through one of the blocks and the other through the other one.
But when I want exponentially distributed values with a mean of 120 seconds, They both need to have the same value always. So they are done at the same time.
You simply need to have the two delay blocks use their own (but with the same seed) random object.
Start off by creating two identical random objects
And have each of the delay blocks use of them of them
Then the numbers they will sample will be the same for every sampling iteration.
See this post for a similar problem
Why do two flowcharts set up exactly the same end with different results every time the simulation is run even when I use a fixed seed?
Not questioning your probably bad design by not using resources, These are the steps to follow to ensure things happen at the exact same time:
1.Create a variable called seed of type long
2.create a cyclic event that runs every 1 minute and has the following code:
seed=(new Random()).nextLong();
3.In both blocks you will use the following code to calculate the exponential distribution:
exponential(120,0,new Random(seed))

System dynamics SEIR infectious curve for 3 waves of Covid

Using system dynamics on anylogic how can you model a simulation that will give an infectious curve of this nature(Below picture) using SEIR.
enter image description here
I have tried to simulate, however my graph goes up and down. It does not oscillate as per the attached picture.
I need to simulate something similar to the graph for my assingment.
There should be three types of events in your model.
First, lets call it "initial spread", is triggered on the start of your simulation.
Second, lets call it "winter season", is triggered annualy in November\December.
Third, lets call it "mass vaccination" - you can decide when to trigger it and for what selection of your agents.
So first two are kind of global events, and the third event is specific to some sub-population (this can make the third wave kind of "toothy" if you trigger it in slightly different moments for different populations).
That is pretty it.
Curios to see how your model will predict the fourth wave - second winter season of your simulation. So keep us updated :)
There are a number of ways to model this. One of the simplest ways is to simply use a time aspect for one of your infection rate parameters so that the infection rate increases or decreases with time.
See the example below.
I took the SIR model from the Cloud https://cloud.anylogic.com/model/d465d1f5-f1fc-464f-857a-d5517edc2355?mode=SETTINGS
And simply added an event to change the Infectivity rate using an event.
Changing the chart to only show infected people the result now looked something like this.
(See the 3 waves that were created)
You will obviously use a parameters optimization experiment to get the parameter settings as close to reality as possible

Anylogic - How to measure work in process inventory (WIP) within simulation

I am currently working on a simple simulation that consists of 4 manufacturing workstations with different processing times and I would like to measure the WIP inside the system. The model is PennyFab2 in case anybody knows it.
So far, I have measured throughput and cycle time and I am calculating WIP using Little's law, however the results don't match he expectations. The cycle time is measured by using the time measure start and time measure end agents and the throughput by simply counting how many pieces flow through the end of the simulation.
Any ideas on how to directly measure WIP without using Little's law?
Thank you!
For little's law you count the arrivals, not the exits... but maybe it doesn't make a difference...
Otherwise.. There are so many ways
you can count the number of agents inside your system using a RestrictedAreaStart block and use the entitiesInside() function
You can just have a variable that adds +1 if something enters and -1 if something exits
No matter what, you need to add the information into a dataset or a statistics object and you get the mean of agents in your system
Little's Law defines the relationship between:
Work in Process =(WIP)
Throughput (or Flow rate)
Lead Time (or Flow Time)
This means that if you have 2 of the three you can calculate the third.
Since you have a simulation model you can record all three items explicitly and this would be my advice.
Little's Law should then be used to validate if you are recording the 3 values correctly.
You can record them as follows.
WIP = Record the average number of items in your system
Simplest way would be to count the number of items that entered the system and subtract the number of items that left the system. You simply do this calculation every time unit that makes sense for the resolution of your model (hourly, daily, weekly etc) and save the values to a DataSet or Statistics Object
Lead Time = The time a unit takes from entering the system to leaving the system
If you are using the Process Modelling Library (PML) simply use the timeMeasureStart and timeMeasureEnd Blocks, see the example model in the help file.
Throughput = the number of units out of the system per time unit
If you run the model and your average WIP is 10 units and on average a unit takes 5 days to exit the system, your throughput will be 10 units/5 days = 2 units/day
You can validate this by taking the total units that exited your system at the end of the simulation and dividing it by the number of time units your model ran
if you run a model with the above characteristics for 10 days you would expect 20 units to have exited the system.

Is there a way to record when (and how often) Transporters get within a certain distance of each other?

I have an AnyLogic simulation model using trucks and forklifts as agents (Transporter type), and among other things would like to identify each time one of them becomes within a certain distance of another one (example within 5 meters). I will record this count as a variable within the main space of the model. I am using path-guided navigation.
I have seen a method "agentsInRange" which will probably be able to do the trick, but am not sure where to call this from. I assume I should be able to use the AL functionality of "Min distance to obstacle" (TransporterFleet) and "Collision detection timeout" (TransporterControl)?
Thanks in advance!
Since there don't seem to be pre-built functions for this, afaik, the easiest way is to:
add an int variable to your transporter agent type counter
add an event to your transporter type checkCollision that triggers every second or so
in the event, loop across the entire population of transporters and count the number that are closer than X meters (use distanceTo(otherTransporter) and write your own custom code)
add that number to counter
Note that this might be very inefficient computationally as it is quite brute-force. But might be good enough :)

Energy Consumption in Anylogic

I would like to analyse the electrical energy consumed by a furnace in a conveyor system. Is there a method or specific function to do this using Anylogic?
I've found little material surrounding this, so pointing in the right direction would be great.
Simple answer: There is no build-in functionality. But you can easily do this yourself.
If you want very high accuracy, you should check system dynamics (but this slows your model quite a bit).
If you want a simple approach, I can think of this:
create a variable elecConsumptionPerMin in your furnace agent
create an event consumeElec in your furnace that cyclically (every minute) adds to the total furnace consumption (another variable)
on model startup, ideally set myFurnace.consumeElec.suspend()
when the furnace starts producing, call ´myFurnace.consumeElec.resume()` to start consuming enegery
Obviously, you can refine this to the nth degree and you might also want to experiment with state charts. But this is the simple approach