<jupyter_start><jupyter_text>Cases for Nurse Availability Levels with different Utility Functions Task:    Evaluate Shift Coverage, Agent Satisfaction and Agent Productivity over changes in nurse availability<jupyter_code>import abm_scheduling
from abm_scheduling import Schedule as Schedule
from abm_scheduling import Nurse as Nurse
import time
from datetime import datetime

import abm_scheduling.Log
from abm_scheduling.Log import Log as Log

import matplotlib.pylab as plt
%matplotlib inline

log = Log()<jupyter_output><empty_output><jupyter_text>Shift coverage on number of nurses<jupyter_code>beta = 0.8
p_to_accept_negative_change = .001
degree_of_agent_availability = 0.7
min_number_of_runs_with_shift_coverage_1 = 3
works_weekends = True
num_nurses_per_shift = 5
number_of_runs_with_shift_coverage_1 = 0
nurses = []
run_results_SC_over_NN_default_UF = []
run_results_SC_over_NN_AS_UF = []

schedule = Schedule(num_nurses_needed=num_nurses_per_shift, is_random=True)
model = abm_scheduling.NSP_AB_Model()

# run model with default utility function
num_nurses_D_UF = 0
while number_of_runs_with_shift_coverage_1 < min_number_of_runs_with_shift_coverage_1:
    nurse = Nurse(id_name=num_nurses)
    nurse.generate_shift_preferences(degree_of_agent_availability=0.7, works_weekends=True)
    nurses.append(nurse)
    num_nurses_D_UF += 1
    
    results = model.run(schedule_org=schedule,
                       nurses_org=nurses,
                       p_to_accept_negative_change=p_to_accept_negative_change,
                       utility_function_parameters=None,
                       print_stats=False)
    run_results_SC_over_NN_default_UF.append(results)

    if results.shift_coverage >= 1:
        number_of_runs_with_shift_coverage_1 += 1
# run model with agetn satisfaction utility function
utility_function_parameters = abm_scheduling.Utility_Function_Parameters()
utility_function_parameters.utility_function = 'agent_satisfaction'
num_nurses_AS_UF = 0
number_of_runs_with_shift_coverage_1 = 0
    
while number_of_runs_with_shift_coverage_1 < min_number_of_runs_with_shift_coverage_1:
    nurse = Nurse(id_name=num_nurses)
    nurse.generate_shift_preferences(degree_of_agent_availability=0.7, works_weekends=True)
    nurses.append(nurse)
    num_nurses_AS_UF += 1
    
    results = model.run(schedule_org=schedule,
                       nurses_org=nurses,
                       p_to_accept_negative_change=p_to_accept_negative_change,
                       utility_function_parameters = utility_function_parameters,
                       print_stats=False)
    run_results_SC_over_NN_AS_UF.append(results)

    if results.shift_coverage >= 1:
        number_of_runs_with_shift_coverage_1 += 1
plt.figure()
plt.plot(range(num_nurses_D_UF), [r.shift_coverage for r in run_results_SC_over_NN_default_UF], label="Default Util.function")
plt.plot(range(num_nurses), [r.shift_coverage for r in run_results_SC_over_NN_AS_UF], label="A.Satisf.Util.function")
plt.title(f'Shift coverage as a function of number of nurses', y=1.15, fontsize=14)
plt.suptitle(f'Av:0.7, WW = True', y=1.0)
plt.xlabel("Number of nurses")
plt.ylabel("Shift Coverage")
plt.legend()
plt.show()
print(run_results_1[19].shift_coverage)
print(run_results_1[20].shift_coverage)
print(run_results_1[21].shift_coverage)
plt.figure()
plt.plot(range(num_nurses), [r.total_agent_satisfaction for r in run_results_1], label="Agent Satisfaction")
plt.title(f'Agent satisfaction as a function of Number of nurses')
plt.xlabel("Number of nurses")
plt.ylabel("Agent Satisfaction")
plt.legend()
plt.show()
detail_productivity_over_nr_nurses = []
avg_productivity_over_nr_nurses = []
for r in run_results_1:
    data = []
    for nurse in r.nurses:
        assigned_shifts = len(nurse.shifts)
        data.append(assigned_shifts/ nurse.minimum_shifts)
    detail_productivity_over_nr_nurses.append(data)
    avg_productivity_over_nr_nurses.append(sum(data)/len(data))
plt.figure()
plt.plot(range(num_nurses), avg_productivity_over_nr_nurses, label="Average productivity")
plt.title(f'Average nurse productivity (assigned_shifts/minimum_shifts)')
plt.xlabel("Number of nurses")
plt.ylabel("Agent productivity")
plt.legend()
plt.show()
plt.figure()
w = plt.boxplot(detail_productivity_over_nr_nurses)
plt.title(f'Nurse productivity (assigned_shifts/minimum_shifts)')
plt.xlabel("Nurses availability")
plt.ylabel("Agent productivity")
plt.show()
print(avg_productivity_over_nr_nurses)<jupyter_output><empty_output><jupyter_text>Shift coverage over nurse availability<jupyter_code>beta = 0.8
p_to_accept_negative_change = .001
min_number_of_runs_with_shift_coverage_1 = 3
works_weekends = True
num_nurses_per_shift = 5
num_nurses = 22
values_degree_of_agent_availability = [i * 0.1 for i in range(2, 10)]
nurses = []
run_results_2 = []

schedule = Schedule(num_nurses_needed=num_nurses_per_shift, is_random=True)
model = abm_scheduling.NSP_AB_Model()
utility_function_parameters = abm_scheduling.Utility_Function_Parameters()
utility_function_parameters.utility_function = 'agent_satisfaction'


for degree_of_agent_availability in values_degree_of_agent_availability:

    nurses = model.generate_nurses(num_nurses=num_nurses,
                               degree_of_agent_availability=degree_of_agent_availability,
                               works_weekends=works_weekends)

    results = model.run(schedule_org=schedule,
                       nurses_org=nurses,
                       beta=beta,
                       p_to_accept_negative_change=p_to_accept_negative_change,
                       utility_function_parameters=utility_function_parameters,
                       print_stats=False)
    run_results_2.append(results)
plt.figure()
plt.plot(values_degree_of_agent_availability, [r.shift_coverage for r in run_results_2], label="Shift Coverage")
plt.title(f'Shift coverage as a function of nurses availability')
plt.xlabel("Nurses availability")
plt.ylabel("Shift Coverage")
plt.legend()
plt.show()
plt.figure()
plt.plot(values_degree_of_agent_availability, [r.total_agent_satisfaction for r in run_results_2], label="Agent Satisfaction")
plt.title(f'Agent satisfaction as a function of nurses availability')
plt.xlabel("Nurses availability")
plt.ylabel("Agent Satisfaction")
plt.legend()
plt.show()
detail_productivity_over_nr_nurses = []
avg_productivity_over_nr_nurses = []
for r in run_results_2:
    data = []
    for nurse in r.nurses:
        assigned_shifts = len(nurse.shifts)
        data.append(assigned_shifts/ nurse.minimum_shifts)
    detail_productivity_over_nr_nurses.append(data)
    avg_productivity_over_nr_nurses.append(sum(data)/len(data))
plt.figure()
plt.plot(values_degree_of_agent_availability, avg_productivity_over_nr_nurses, label="Average productivity")
plt.title(f'Average nurse productivity (assigned_shifts/minimum_shifts)')
plt.xlabel("Nurses availability")
plt.ylabel("Agent productivity")
plt.legend()
plt.show()
plt.figure()
w = plt.boxplot(detail_productivity_over_nr_nurses)
plt.title(f'Nurse productivity (assigned_shifts/minimum_shifts)')
plt.xlabel("Nurses availability")
plt.ylabel("Agent productivity")
ww = plt.xticks([i for i in range(1, 9)], [f'{i*0.1:1.2f}' for i in range(2, 10)])
print(avg_productivity_over_nr_nurses)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08692075678639978, 'fraction_numerical': 0.01110501782286811, 'mean_word_length': 5.34899912967798, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '150465', 'license': 'MIT', 'n_tokens_mistral': 2639, 'n_tokens_neox': 2481, 'n_words': 415, 'path': '.ipynb_checkpoints/C_nurse_availability_levels_nurse_satisfaction-checkpoint.ipynb', 'repo_name': 'GLopezMUZH/ABM_NurseSchedullingModel', 'size': '7294'}