Lesson 6: What-if analysis

For this lesson, go back to the code created in Lesson 4.

from qplex import StandardMultiserver

engine = StandardMultiserver()
engine.number_of_arrivals_pmf = {2: 0.3, 3: 0.7}
engine.service_duration_pmf = {1: 0.6, 2: 0.3, 3: 0.1}
engine.number_of_servers = 2

print(engine.get_number_of_entities_in_system_pmf())

engine.step()
print(engine.get_number_of_entities_in_system_pmf())

engine.step()
print(engine.get_number_of_entities_in_system_pmf())

Suppose an option is available at time 2 to add a server. Whether or not to exercise this option can be based on the chance of having five or more entities waiting in the buffer at time 3 in both scenarios.

The mark function takes a snapsnat of the engine for later use. Call it now, take a step, and print the pmf of the number of entities in the system. Here is the code:

engine.mark()
engine.step()
print(engine.get_number_of_entities_in_system_pmf())

And here is the output:

{2: 0.0034992000000000005, 3: 0.03500820000000001, 4: 0.1405904862385321, 5: 0.287842995412844, 6: 0.31404805045871564, 7: 0.17340676788990833, 8: 0.042174300000000026, 9: 0.0034300000000000034}

There is a greater than 20% chance of having five or more entities waiting in the buffer (seven or more entities in the system at time 3) if the number of servers stays at two.

So what will happen if one server is added? To address this What-if question, use the restore function to rewind the engine back to where it was when mark was called.

engine.restore()
print(engine.get_number_of_entities_in_system_pmf())

The output

{2: 0.03239999999999999, 3: 0.19439999999999996, 4: 0.39239999999999997, 5: 0.30239999999999995, 6: 0.0784}

confirms that it is, indeed, the same as it was at the time of the mark.

Now add one server, take a step, and print the pmf of the number of entities in the system. Here is the code:

engine.number_of_servers = 3
engine.step()
print(engine.get_number_of_entities_in_system_pmf())

And here is the output:

{2: 0.01717551, 3: 0.10169346820132984, 4: 0.24334503074804303, 5: 0.3145063684332127, 6: 0.22486574058412598, 7: 0.08326638953328848, 8: 0.014289992500000008, 9: 0.0008575000000000012}

The chance of having five or more entities waiting in the buffer at time 3 has been reduced to less than 2%.

Here is the complete code so far:

from qplex import StandardMultiserver

engine = StandardMultiserver()
engine.number_of_arrivals_pmf = {2: 0.3, 3: 0.7}
engine.service_duration_pmf = {1: 0.6, 2: 0.3, 3: 0.1}
engine.number_of_servers = 2

print(engine.get_number_of_entities_in_system_pmf())

engine.step()
print(engine.get_number_of_entities_in_system_pmf())

engine.step()
print(engine.get_number_of_entities_in_system_pmf())

engine.mark()
engine.step()
print(engine.get_number_of_entities_in_system_pmf())

engine.restore()
print(engine.get_number_of_entities_in_system_pmf())

engine.number_of_servers = 3
engine.step()
print(engine.get_number_of_entities_in_system_pmf())