added model sets and params

This commit is contained in:
Lewis Woolfson 2020-05-27 18:11:08 +01:00
parent c3935d7446
commit c55a7de0b0
1 changed files with 44 additions and 8 deletions

View File

@ -3,25 +3,55 @@ import numpy as np
import pyomo.environ as pe
import pyomo.gdp as pyogdp
from pyomo.core.base.set_types import Any
import os
# check with Taha if code is too similar to Alstom?
class TheatreScheduler:
def __init__(self):
pass
def __init__(self, case_file_path, session_file_path):
"""
Read case and session data into Pandas DataFrames
Args:
case_file_path (str): path to case data in CSV format
session_file_path (str): path to theatre session data in CSV format
"""
try:
self.df_cases = pd.read_csv(case_file_path)
except FileNotFoundError:
print("Case data not found.")
def _generate_cases(self):
pass
try:
self.df_sessions = pd.read_csv(session_file_path)
except FileNotFoundError:
print("Session data not found")
def _generate_case_durations(self):
"""
Generate mapping of cases IDs to median case time for the procedure
Returns:
(dict): dictionary with CaseID as key and median case time (mins) for procedure as value
"""
return pd.Series(self.df_cases["Median Duration"].values, index=self.df_cases["CaseID"]).to_dict()
def _generate_session_durations(self):
"""
Generate mapping of all theatre sessions IDs to session duration in minutes
Returns:
(dict): dictionary with SessionID as key and session duration as value
"""
return pd.Series(self.df_sessions["Duration"].values, index=self.df_sessions["SessionID"]).to_dict()
def create_model(self):
model = pe.ConcreteModel()
# Model Data
model.CASES = pe.Set() # indexed by (caseID, sessionID)
model.CASE_DURATIONS = pe.Param() # median case times
model.SESSION_DURATIONS = pe.param() # session durations
model.M = pe.Param() # big M
model.CASES = pe.Set(initialize=self.df_cases["CaseID"].tolist())
model.SESSIONS = pe.Set(initialize=self.df_sessions["SessionID"].tolist())
model.TASKS = pe.Set(initialize=model.CASES * model.SESSIONS, dimen=2)
model.CASE_DURATIONS = pe.Param(model.CASES, initialize=self._generate_case_durations())
model.SESSION_DURATIONS = pe.param(model.SESSIONS, initalize=self._generate_session_durations())
model.M = pe.Param(initialize=1e7) # big M
max_util = 0.85
# Decision Variables
@ -62,3 +92,9 @@ class TheatreScheduler:
def solve(self):
pass
if __name__ == "__main__":
case_path = os.path.join(os.path.dirname(os.getcwd()), "data", "case_data.csv")
session_path = os.path.join(os.path.dirname(os.getcwd()), "data", "session_data.csv")
scheduler = TheatreScheduler(case_file_path=case_path, session_file_path=session_path)