70 lines
2.2 KiB
Python
70 lines
2.2 KiB
Python
|
from pyomo.environ import SolverFactory
|
||
|
solver = SolverFactory('glpk')
|
||
|
|
||
|
import pandas as pd
|
||
|
import pyomo.environ as pyo
|
||
|
# Create a model
|
||
|
model = pyo.ConcreteModel()
|
||
|
|
||
|
## Define variables
|
||
|
#model.x = pyo.Var(within=pyo.NonNegativeReals)
|
||
|
#model.y = pyo.Var(within=pyo.NonNegativeReals)
|
||
|
## Define objective
|
||
|
#model.obj = pyo.Objective(expr=model.x + model.y, sense=pyo.minimize)
|
||
|
## Define constraints
|
||
|
#model.con1 = pyo.Constraint(expr=model.x + 2 * model.y >= 4)
|
||
|
#model.con2 = pyo.Constraint(expr=model.x - model.y <= 1)
|
||
|
## Select solver
|
||
|
#solver = pyo.SolverFactory('glpk')
|
||
|
## Solve the problem
|
||
|
#result = solver.solve(model)
|
||
|
## Display results
|
||
|
#print('Status:', result.solver.status)
|
||
|
#print('Termination Condition:', result.solver.termination_condition)
|
||
|
#print('Optimal x:', pyo.value(model.x))
|
||
|
#print('Optimal y:', pyo.value(model.y))
|
||
|
#print('Optimal Objective:', pyo.value(model.obj))
|
||
|
|
||
|
class Scheduler:
|
||
|
def __init__(self, case_file_path, session_file_path, patient_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.")
|
||
|
try:
|
||
|
self.df_sessions = pd.read_csv(session_file_path)
|
||
|
except FileNotFoundError:
|
||
|
print("Session data not found")
|
||
|
try:
|
||
|
self.df_patients = pd.read_csv(patient_file_path)
|
||
|
except FileNotFoundError:
|
||
|
print("Patient data not found")
|
||
|
#self.model = self.create_model()
|
||
|
|
||
|
def date2int(date):
|
||
|
d0 = pd.to_datetime("25/11/2024", dayfirst=True)
|
||
|
delta = (pd.to_datetime(date, dayfirst=True) - d0).days
|
||
|
day = delta%7
|
||
|
week = int((delta - day)/7)
|
||
|
return week,day
|
||
|
|
||
|
|
||
|
path = '/home/hmag/code/pyomo/data'
|
||
|
my = Scheduler(path+'/cases.csv', path+'/sessions.csv', path+'/patients.csv')
|
||
|
|
||
|
print(my.df_cases)
|
||
|
print(my.df_sessions)
|
||
|
#print(my.df_patients)
|
||
|
#for i in my.df_patients:
|
||
|
# print(i)
|
||
|
print(my.df_cases['Date'][0])
|
||
|
date = my.df_cases['Date'][0]
|
||
|
|
||
|
print(date2int(date))
|