Lesson 7: Observations

Once again, 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())

Lesson 6 showed how to use mark and restore to compare the number of entities in the system at time 3 when there are two versus three servers.

Here is an alternative situation. Suppose the number of entities in the system at time 2 can be observed and the observed value is four. How does this information affect the chance of having five or more entities waiting in the buffer at time 3, even without a change to the number of servers?

To answer this question, use the apply_observation_value function to adjust the engine's internal state to reflect the known number of entities in the system. Here is the code:

engine.apply_observation_value(4)
print(engine.get_number_of_entities_in_system_pmf())

And here is the output:

{4: 1.0}

This confirms that there are four entities in the system.

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

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

The output

{4: 0.1244349802205201, 5: 0.42790034508879715, 6: 0.35896776365625793, 7: 0.08869691103442479}

shows that the chance of having five or more entities waiting in the buffer has become less than 10%.

Here is the complete code:

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.apply_observation_value(4)
print(engine.get_number_of_entities_in_system_pmf())

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