Waiting time in queue of a service block by number of agents out of the service graph? AnyLogic - anylogic

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.

Related

calculate avarage waiting time in anylogic

Two groups of men and women arrive at the same entrance source at the same time to avail a certain service, then how can we get the entire average waiting time of both separately in anylogic .please help me.
You can use these two block provided by AnyLogic.
Or as I do, create two variables for your agents called enterTime and leaveTime and set them to time() when they enter and leave the Queue. Like agent.enterTime = time(). Create a variable in the Main (assuming your blocks are there) called totalTimeInQueueMen and totalTimeInQueueWomen and set it to totalTimeInQueueMen=totalTimeInQueueMen+(agent.leaveTime-agent.enterTime). Also count your number of agents with a variable called count. Every time they enter the queue, increment it by 1; like count+=1;. At the end of the the simulation you can calculate the average as totalTimeInQueueMen/count (the same for women).

agent cannot be resolved to a variable when timing segments of AnyLogic model

In the model, I need to time segments in which some agents go through, but not all, rendering the use of timeMeasureStart and End blocks ineffective as any agents who go through a certain End block MUST go through it's corresponding Start block, but not all agents that will encounter the End block will have gone through it's corresponding Start block.
I have done the following and receive the error that 'agent cannot be resolved to a variable' in the Histogram
Defined the variables startTime endTime cycleTime in the agent class Patient which is being pushed through the model.
Put agent.cycleTime=agent.endTime-agent.startTime; in the On enter slot of the block in which I want the timing to end.
Defined a Histogram Data called myDataSet with the Value agent.cycleTime in Main
Made a histogram in Main which takes myDataSet in it's Histogram slot.
First, you can still use TimeMeasureStart/end blocks. Just let some agents bypass them with a SelectOutput block upstream of the TimeMeasureStart block. The condition would be determined by who should be measured.
Ok, then to your details:
Put agent.cycleTime=agent.endTime-agent.startTime; in the On enter slot of the block in which I want the timing to end.
This is not how you would measure time. The variables are a good start, though. Do this instead:
Wherever timing should start, you write agent.startTime = time() (logs curr model time)
Wherever timing should end, you write agent.cycleTime = time() - agent.startTime, essentially measuring how much time has passed since the start.
Now you do what you want with agent.cycletime
Defined a Histogram Data called myDataSet with the Value agent.cycleTime in Main
this is not how you use Histogram Data. You need to use the API calls on it properly, for example myHistogramData.add(someValue):
Also, always check example models and the help, many issues can be solved by checking those first :)

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

Pedestrian Position/coordination in anylogic in certain time period

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.

Simulink: How to convert event based signal with zero duration values to a time based signal without losing information

I have a matlab function block (which is not relevant) whose input is his previous output (loop). For example, if in a sample period the output is X, his input in the next sample period will be X, and so on.
This image shows a simplification of my simulation. I initialize the input of my function for the first loop.
The problem is that matlab functions recieves an event based signal from de initialization block in the first sample period (zero-duration), which I must convert to a timed based signal (so I can apply the unit delay that avoids an inifite loop, and allows to generate the next input as explained before). So, when I do so, I lose the information contained in the event-based signal (due to the zero-duration values) and the loop does not work.
If there was a way to intialize the loop in the time-based domain (green part of the image) so, in the first sample time, it is not a zero-duration signal, it would avoid the problem.
Is there any way to do so? Or, a different approach for this problem?
Two approaches come to mind
The initial condition can be set in the Unit Delay block, so it's not clear from your simplified example why you need the specific Initialization block.
You could just use a persistent variable inside the MATLAB Function block to maintain the state from one execution of the block to the next (noting that since it is event driven the block may not get called at every time step, only at each event triggger).