How to count the number of people when time equal to 120 seconds during evacuation using the function in anylogic? - anylogic

I am working on fire evacuation of a building floor and would like to count the number of people remaining inside the building after 120 seconds? The timer should start once the evacuation process begins, which is by alarm that goes off after a certain amount of time using an event feature.
I know how to count the total number of people inside the building using the function component getPeopleInsideCount and a text with getPeopleInsideCount(). But I don't know what code to use for my problem.
Below is the code:
return pedOffice.countPeds() + pedStudents.countPeds() - pedSink.sink.count();

With this, it will count the people in the building floor and it will stop counting after 120 seconds...
Step 1:
create an event with trigger type timeout, and mode: user control, and timeout=120 seconds.
Step 2:
create a variable called stopCounting as a boolean with initial value false
create a variable called peopleRemaining as an int
Step 3:
when the evacuation begins run the code:
event.restart();
Step 4:
in your event use the following code:
stopCounting=true;
peopleRemaining=getPeopleInsideCount();
Step 5
In your text use the following code instead of getPeopleInsideCount()
stopCounting ? peopleRemaining : getPeopleInsideCount()

Add a dynamic event that returns the count you need.
Once your alarm goes off, you can call that dynamic event 120 seconds later using create_MyDynamicEvent(120, SECOND);
That will execute the event code 120 seconds later.
cheers

Related

Anylogic - Assembler should stop working for 2 hours after 10 assemblies done

The "Assembler" should stop working for 2 hours after 10 assemblies are done.
How can I achieve that?
There are so many ways to do this depending on what it means to stop working and what the implications are for the incoming parts.. but here's one option
create a resourcePool called Machine, this will be used along with the technicians:
on the "on exit" action of the assembler do this (I use 9 instead of 10 because the out.count() doesn't count until the agent is completely out, so when it counts 9, it means that you have produced 10)
if(self.out.count()==9){
machine.set_capacity(0);
create_MyDynamicEvent(2, HOUR);
}
In your dynamice event (that you have to create) you will add the following code:
machine.set_capacity(1);
A second option is to have a variable countAssembler count the number of items produced... then
on exit you write countAssembler++;
on enter delay you write the following:
if(countAssembler==10){
self.suspend(agent);
create_MyDynamicEvent(2, HOUR,agent);
}
on the dynamic event you write:
assembler.resume(agent);
Don't forget to add the parameter needed in the dynamic event:
Create a variable called countAssembler of type int. Increment this as agents pass through the assembler. Also create a variable called assemblerStopTime. You also record the assembler stop time with assemblerStopTime=time()
Place a selectOutputOut block before the and let them in if countAssembler value is less than 10. Otherwise send to a Wait block.
Now, to maintain the FIFO rule, in the first selectOutputOut condition, you need to check also if there is any agent in the wait block and if the current time - assemblerStopTime is greater than 2. If there is, you free it and send to the assembler with wait.free(0) function. And send the current agent to wait. You also need to reset the countAssembler to zero.

How to call suspend function in anylogic?

I create an integer to count the number of assemblies (e.g. countAssembler)
On exit from FA1 (countAssembler++;)
Then I have an event triggered by a condition such that when the count of assemblies reaches 10 ((countAssembler==10)), it suspends the FA1 for two hours using suspend function.
But how do I implement the suspend function? Do you have any ideas?
note that the suspend function doesn't suspend the assembler, but an item that is currently being processed in the assembler...
have a variable countAssembler count the number of items produced... then
on exit you write countAssembler++;
on enter delay you write the following:
if(countAssembler==10){
self.suspend(agent);
create_MyDynamicEvent(2, HOUR,agent);
}
on the dynamic event you write:
assembler.resume(agent);
Don't forget to add the parameter needed in the dynamic event:
Note that the suspend will start when part 11 starts being assembled, which means that the machine will be suspended for 2 hours + the time between the 10th assembly end and then 11th assembly start... you can fix that easily but im not including it in my answer

Pause then resuming simulation in Anylogic

I would like to give the user a button that allows them to skip ahead 1 hour in the simulation and then continue running the model if play is clicked. The code below allows the user to skip ahead an hour, however they are unable to resume the simulation when play is clicked.
double nextHour = time() + 60;
pauseSimulation();
getEngine().runFast(nextHour); //Runs the model to the next hour when button is clicked
Any help much appreciated.
Try adding runSimulation() after the last line. But probably, that does not work. In that case:
Create a dynamic event (not the normal event) with the line runSimulation() in its action code.
In the button code, before the runFast... line, write create_MyDynamicEvent(1, HOUR). This will trigger the even 1 hour later and unpause the model.
AnyLogic Support suggested the following solution, which I have used:
Unfortunately, Ben's suggestion didn't didn't work; it seems to cause an issue when pauseSimulation() is used.

How do I choose both exact quanitity wait for and quanitity available in the same pick-up block?

So I have a vehicle which is going to pick up exact quantity (Wait for) the first 50 minutes in the simulation. After those 50 minutes have gone by, I want the same vehicle to pick up quantity (if available). How do I go about this?
Alternative approach (avoiding complex Java coding) is to use 2 Pickup blocks, each with a different setup. Put a SelectOutput block before them and route agents into the respective block using time()>50*minute() in the SelectOutput condition
Set it up for the first setup by default.
Create an event to trigger after 50 mins and make it execute this code:
myPickupObject.set_pickupType(PickupType.QUANTITY);
Here is a way to allow container entity to wait in a Pickup for some time t and then leave with whatever entities have been picked up. The example model looks like this:
There are two key components:
ReleaseOnTimeout Dynamic event which has a parameter called '_agent' of type Agent and following code:
for (Object o : pickup.getEmbeddedObjects()) {
// find the Delay object inside Pickup
if (Delay.class == o.getClass().getSuperclass()) {
// remove the container from the Delay
Agent a = ((Delay)o).remove(_agent);
if (a != null) {
// send the removed container into Enter
enter.take(a);
}
}
}
In pickup on enter action contains following code: `create_ReleaseOnTimeout(10, container);
How this works:
pickup is configured to have Exact quantity (wait for) behaviour
a container object enters Pickup block pickup
on entry a dynamic event ReleaseOnTimeout is scheduled in 10 units to check up on container
if sufficient number of entities were available then container picks them up and leaves
alternatively to (4), if by the time 10 units elapsed the container is still stuck in pickup then it will be removed and put into enter

How I can evaluate a condition on next time-step in anylogic?

I am trying to write a code for one state to another state transition where the system will first store the initial model time and then will check a condition (used while loop). It will continue to run the loop until the condition is false and when the condition is false it will record the final model time. So, my main objective is to get the total time that while loop condition is true. The problem is, I don't know how to check the while loop every 1 time step, For example, I tried "wait (1);" in place of "???" section of the below code which is not correct. Can anyone please suggest how I can do this?
My transition code as below:
...
...
initialTime=time();
while ((thisPed.inState(walking) && thisPed.fieldOfVision.contains(pedX, pedY));
{
???
}
finalTime= time();
exposureTime = finalTime - initialTime;
...
...
you can't put while statements in a model that at the same time run with time steps... to do that you have many other ways..
For instance you can generate a transition that goes from that state to the same state (internally) and generate your code there every time step.
Another option is to use a conditional transition in the same way
BUt NOT a while loop