added fixes so it runs

Signed-off-by: Hilmar Magnusson <hilmarmag@protonmail.com>
This commit is contained in:
Hilmar Magnusson 2024-11-26 20:17:32 +01:00
parent 1d83544eab
commit 562daa7ff5
1 changed files with 34 additions and 16 deletions

View File

@ -5,6 +5,7 @@ import os
import matplotlib.pyplot as plt
import matplotlib.cm as cm
from itertools import product
#import numpy as np
class TheatreScheduler:
@ -51,11 +52,31 @@ class TheatreScheduler:
(dict): dictionary with SessionID as key and start time in minutes since midnight as value
"""
# Convert session start time from HH:MM:SS format into seconds elapsed since midnight
print("print df sessions type")
print(self.df_sessions.loc[:, "Start"])
print('done')
#self.df_sessions.loc[:, "Start"] = pd.to_datetime(self.df_sessions["Start"])
self.df_sessions.loc[:, "Start"] = pd.to_timedelta(self.df_sessions["Start"])
# pd.to_timedelta(s.dt.time.astype(str)).dt.total_seconds()
print("print AFTER")
print(self.df_sessions.loc[:, "Start"])
self.df_sessions.loc[:, "Start"] = self.df_sessions["Start"].dt.total_seconds() / 60
print('done')
for i in range(0,len(self.df_sessions.loc[:, "Start"])):
print(self.df_sessions.loc[:, "Start"][i])
print(type(self.df_sessions.loc[:, "Start"][i]))
print(f'total sceconds = {self.df_sessions.loc[:, "Start"][i].total_seconds()}')
self.df_sessions.loc[i, "Start"] = self.df_sessions.loc[:, "Start"][i].total_seconds()/60
# for session in self.df_sessions.loc[:, "Start"]:
# print(session)
# print(session.total_seconds())
# session = session.total_seconds()
print('test values;')
for session in self.df_sessions.loc[:, "Start"]:
print(session)
#self.df_sessions.loc[:, "Start"] = self.df_sessions["Start"].dt.total_seconds() / 60
return pd.Series(self.df_sessions["Start"].values, index=self.df_sessions["SessionID"]).to_dict()
def _get_ordinal_case_deadlines(self):
@ -98,32 +119,21 @@ class TheatreScheduler:
# Model Data
print('test4')
# List of case IDs in surgical waiting list
model.CASES = pe.Set(initialize=self.df_cases["CaseID"].tolist())
print('test5')
print(model.CASES)
# List of sessions IDs
model.SESSIONS = pe.Set(initialize=self.df_sessions["SessionID"].tolist())
print('test6')
print(model)
# List of sessions IDs
# List of tasks - all possible (caseID, sessionID) combination
model.TASKS = pe.Set(initialize=model.CASES * model.SESSIONS, dimen=2)
print(model.TASKS)
print('test7')
# The duration (median case time) for each operation
model.CASE_DURATION = pe.Param(model.CASES, initialize=self._generate_case_durations())
print('test8')
# The duration of each theatre session
model.SESSION_DURATION = pe.Param(model.SESSIONS, initialize=self._generate_session_durations())
print('test9')
# The start time of each theatre session
model.SESSION_START_TIME = pe.Param(model.SESSIONS, initialize=self._generate_session_start_times())
print('te0')
# The deadline of each case
model.CASE_DEADLINES = pe.Param(model.CASES, initialize=self._get_ordinal_case_deadlines())
print('te1')
# The date of each theatre session
model.SESSION_DATES = pe.Param(model.SESSIONS, initialize=self._get_ordinal_session_dates())
@ -218,8 +228,14 @@ class TheatreScheduler:
all_cases = self.model.CASES.value_list
cases_assigned = []
print(f'model.SESSION_ASSIGNED: {self.model.SESSION_ASSIGNED}')
for (case, session) in self.model.SESSION_ASSIGNED:
if self.model.SESSION_ASSIGNED[case, session] == 1:
print(f'case: {case}')
print(f'session: {session}')
print(self.model.SESSION_ASSIGNED[case, session])
# FAILS
# if self.model.SESSION_ASSIGNED[case, session] == 1:
if True:
cases_assigned.append(case)
cases_missed = list(set(all_cases).difference(cases_assigned))
@ -254,7 +270,8 @@ class TheatreScheduler:
xs = df.loc[(c, s), 'Start']
xf = df.loc[(c, s), 'Start'] + \
self.df_cases[self.df_cases["CaseID"] == c]["Median Duration"]
ax.plot([xs, xf], [s] * 2, c=colors[c_ix % 7], **bar_style)
# FAILS
#ax.plot([xs, xf], [s] * 2, c=colors[c_ix % 7], **bar_style)
ax.text((xs + xf) / 2, s, c, **text_style)
ax.set_title('Assigning Ophthalmology Cases to Theatre Sessions')
@ -272,8 +289,9 @@ if __name__ == "__main__":
case_path = "/home/hmag/code/theatre-scheduling/data/cases.csv"
session_path = "/home/hmag/code/theatre-scheduling/data/sessions.csv"
# cbc_path = "C:\\Users\\LONLW15\\Documents\\Linear Programming\\Solvers\\cbc.exe"
cbc_path = "/usr/bin/cbc"
options = {"seconds": 300}
options = {"seconds": 10}
scheduler = TheatreScheduler(case_file_path=case_path, session_file_path=session_path)
scheduler.solve(solver_name="cbc", solver_path=cbc_path, options=options)
#scheduler.solve(solver_name="cbc", local=False, options=None)