Step 2: Two servers and a schedule¶
Real servers are not always there, so this step adds a second desk that is closed for the first four hours and open for the last four. The two desks form a resource set, and the service block now seizes the set instead of the one server.
from nagasim import build as nb
m = nb.Model(time_limit=480, warmup=0) # one 8-hour day, in minutes
m.add_resource(name="Server")
arrive = m.create(distribution=nb.Exponential(rate=1.0)) # a customer a minute
serve = m.process(resource_name="Desks", distribution=nb.Exponential(rate=1.25))
arrive >> serve >> m.dispose()
m.add_schedule(name="afternoon", kind="capacity", points=[[240, 0], [240, 1]]) # closed 4 h, open 4 h
m.add_resource(name="Second", capacity=1, capacity_schedule="afternoon")
m.add_resource_set(name="Desks", members=["Server", "Second"], rule="PreferredOrder")
results = m.run(seed=1)
print(round(results.kpi("resource/Desks/Time in Queue Avg"), 2), "minutes mean wait at the desks")
print(results["resource_summary"][["Resource", "Total Seizes", "Usage % (snapshot)"]].to_string(index=False))
A schedule is a list of [duration, value] points, here the capacity 0 for 240 minutes and then 1 for 240 minutes. The set's PreferredOrder rule gives a customer the first free member in list order, so the second desk only takes work the first cannot. Only one line of step 1 changed, the one naming the resource the service block seizes.
It prints:
1.67 minutes mean wait at the desks
Resource Total Seizes Usage % (snapshot)
Server 386 67.10
Second 115 33.14
Desks 501 55.78
The table shows the effect. The first desk serves most customers, and the second desk is busy a third of the half day it is open. The set's row weighs each desk by the hours it was open. The wait drops because capacity arrives when the queue is longest.
Next: A tank level.