I have a simple pedestrian model where 7000 pedestrians are going from an entry line to target line. I want to know the position of the pedestrians after certain time period for predicting how much time they need for going from one point to another. In anylogic help i saw getX,getY function but where to use these and how?
Pedestrian Model and Simulation
Create a dynamic event called GetCoordinates with 1 argument called ped of type Pedestrian
in the pedGoTo block when an agent enters the block you will use this code:
create_GetCoordinates(1,SECOND,ped);
In the GetCoordinates dynamic event you can now use ped.getX() and ped.getY() to collect the information you need after 1 second.
Related
I am very new to AnyLogic, and I just learned the basic Pedestrian process blocks. The problem I have right now is pulling out a specific number of pedestrians currently inside a pedWait rectangular node when a certain condition is met from a function that is called on begin wait of pedWait.
I need to make a graph Y: Number of Agents out of Block, X: Waiting Time inside the queue of the Block.
The block is service. What is the method (if any) to get the time spent in the queue of the service block.
Or, if it is done by a function, or series of codes, can you write it step by step please, I am new to AnyLogic.
thanks...
Also, I need to make a graph of average waiting time of all process vs total time of event.
thanks.
If i got you right, you want to have a probability density function plotted as a bar chart. The standard way to do that would be to use HistogramData(HD) object to collect samples during simulation and then plot it.
Saving data samples to HD:
i suggest to create a variable in your agent to store the moment of time when agent entered the block, lets say you call it waitStart;
inside your service block put this code in "on enter":
agent.waitStart = time();
inside your service block put this code in "on enter delay":
yourHistogramData.add(time()-agent.waitStart);
And then you just plot your HD to the graph: right-click on you HistogramData and you will see "create chart".
As easy as that.
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.
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 :)
i have a simple anylogic model for pedestrian movement from start line towards target line
i want to change the speed of the moving agents at some condition.
i test the condition using events
if the number of agents in a specific area exceeds 20, i change the speed of the agents in the previous area using agent.setspeed()
when i run the simulation and the event is triggered i get this exception:
This is an interesting problem... and this is the solution...
1) Your population people is NOT of pedestrian type... so you cannot use the pedestrian API even though you are using the pedestrian library... you have to use a pedestrian type:
2) Once you created the pedestrian type, your population "people" has to be created based on that type... only after this you will have a population that allows you to use the pedestrian API
3) In the pedestrian API, setSpeed() function doesn't exist, instead you should replace it with pers.setComfortableSpeed(0.5,MPS); Of course you can only do this once you completed at least my point 1.