1

I am using env.run() to run the simulation and my simulation contains a bunch of processes which wait for each other and process some event.

Now I know when we don't specify the time frame for which the simulation should run then the simulation runs till all the events has been processed, so in this case how can I calculate the final time(t) in the code, till which the simulation ran?

bakas
  • 323
  • 2
  • 11

2 Answers2

1

Simply use env.now after the call to env.run().

Example:

import simpy


def func1():
    yield env.timeout(50)
    print("Foo bar")


def func2():
    yield env.timeout(30)
    print("Hello world")


env = simpy.Environment()
env.process(func1())
env.process(func2())
env.run()

print("Simulation ended at: {}".format(env.now))

Output:

Hello world
Foo bar
Simulation ended at: 50
Ollie
  • 473
  • 3
  • 7
  • 19
-1

This is pretty straight forward you check what the time is when you start the simulation, start_time and the time when the simulation ended, end_time. The difference is the time the simulation ran for.

import time
start_time = time.time()
end_time = time.time()
print end_time  - start_time
dmg
  • 87
  • 5
  • I am talking about the simulation time, not the real time for which the simulation ran i.e. in real time the simulation may have run for 2 sec, although in the simulation environment, the whole process ran for 150 secs. – bakas Oct 02 '18 at 06:07