<jupyter_start><jupyter_text>A simple object-based hospital bed modelThis model mimics the arrival of patients at a hospital with a finite bed supply. Patients are priority 1-3. If the hospital is full beds are allocated by patient priority (first-in-first-out within a priority). The model is divided into the following classes:* *Scenario*: Class for an object that stores all model paraemters. Any of these may be changed by the user.* *Model*: Class for a SimPy model object. It initiates the SimPy model, sets up a hospital object, and creates patient objects which it passes to the hospital. There is an end_run_routine which summarises results.* *Hospital*: A class for hospital objects. Has a given number of beds. The hospital class allocates beds to patients on a priority basis. It holds the queue for patients waiting for beds, and lists (by patient priority) of queue times each patient has waited for a bed. It has an audit method which monitors the number of patients in beds or waiting for beds each day.* *Patient*: A class for patient objects. Each patient has a givem priority and length of stay. The patient objects stores the times that patient started waiting for a bed, when they were allocated a bed, and when they left the hospital.The sequence of calls is:1. The code below sets up a `Scenario` object which holds the model parameters (and which may be changed in the user input below).1. The code below then sets up a `Model` object, passing it the Scenario.1. The `Model` object sets up a `SimPy` environment and a `Hospital` object. It initiates processes which generate `Patient` objects (from within the `Model`), and which audit patients in beds or waiting for beds (in the `Hospital`). `Patients`, as they are generated, are passed to the `Hospital` for allocation to beds.1. At the end of the run, the `Model` summaries statistics for patients waiting for beds, or in beds, and for queue times by patient priority.  Import modulesThe necessary modules are held in the `sim_classes` package directory.<jupyter_code>from sim_classes.model import Model
from sim_classes.parameters import Scenario<jupyter_output><empty_output><jupyter_text>Run with default scenearioIf no paramters are defined in the sceanrio, the default paramters, as found in the Scenario class (in ./sim_classes_parameters).<jupyter_code>scenario = Scenario()

model = Model(scenario)
model.run()

# Print results
print ('Bed and queue numbers\n')
print (model.results_audit)
print ('\nQueue times\n')
print (model.results_qtime)<jupyter_output>Bed and queue numbers

              min  median    max
in_bed      181.0   200.0  200.0
waiting_p1    0.0     0.0    3.0
waiting_p2    0.0     1.0   11.0
waiting_p3    0.0    22.5   36.0

Queue times

   min     median       max
P1   0  0.0519113  0.394693
P2   0  0.0942936   1.54886
P3   0    3.55038   6.54956<jupyter_text>An alterantive scenarioWe can pass model parameters to the model as named arguments.<jupyter_code>scenario = Scenario(interarrival_time=0.103,
                    hospital_beds=100,
                    run_duration=365)

model = Model(scenario)
model.run()

# Print results
print ('Bed and queue numbers\n')
print (model.results_audit)
print ('\nQueue times\n')
print (model.results_qtime)<jupyter_output>Bed and queue numbers

             min  median    max
in_bed      75.0   100.0  100.0
waiting_p1   0.0     0.0    6.0
waiting_p2   0.0     0.0   11.0
waiting_p3   0.0     2.0   45.0

Queue times

   min     median      max
P1   0  0.0187461  1.13879
P2   0  0.0545921  2.36966
P3   0    0.36476  10.9799<jupyter_text>Or we can pass model parameters to the model as a dictionary.<jupyter_code>my_parameters = {
    'interarrival_time': 0.103, 
    'hospital_beds': 100,
    'run_duration': 365
            }

scenario = Scenario(my_parameters)

model = Model(scenario)
model.run()

# Print results
print ('Bed and queue numbers\n')
print (model.results_audit)
print ('\nQueue times\n')
print (model.results_qtime)<jupyter_output>Bed and queue numbers

             min  median    max
in_bed      78.0   100.0  100.0
waiting_p1   0.0     0.0    5.0
waiting_p2   0.0     0.0   16.0
waiting_p3   0.0     5.0   41.0

Queue times

   min     median       max
P1   0  0.0512106  0.859838
P2   0   0.126227   3.19953
P3   0    1.92772   11.8055
{'fraction_non_alphanumeric': 0.06742354031510658, 'fraction_numerical': 0.06232622798887859, 'mean_word_length': 3.278493557978196, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '202975', 'license': 'MIT', 'n_tokens_mistral': 1453, 'n_tokens_neox': 1326, 'n_words': 564, 'path': 'single_model_run.ipynb', 'repo_name': 'MichaelAllen1966/2004_simple_simpy_parallel', 'size': '4316'}