.
This commit is contained in:
@@ -27,21 +27,23 @@ from rota.workers import (
|
|||||||
|
|
||||||
suspend_on_finish = False
|
suspend_on_finish = False
|
||||||
solve = True
|
solve = True
|
||||||
#time_to_run = 508500
|
# time_to_run = 508500
|
||||||
#time_to_run = 2660000
|
# time_to_run = 2660000
|
||||||
time_to_run = 100
|
time_to_run = 100
|
||||||
#allow = 5000
|
# allow = 5000
|
||||||
ratio = 0.41
|
ratio = 0.41
|
||||||
#ratio = 0.9
|
# ratio = 0.9
|
||||||
|
|
||||||
|
|
||||||
start_date = datetime.date(2023, 9, 4)
|
start_date = datetime.date(2023, 9, 4)
|
||||||
#start_date = datetime.date(2023, 5, 1)
|
# start_date = datetime.date(2023, 5, 1)
|
||||||
#start_date = start_date + datetime.timedelta(weeks=13)
|
# start_date = start_date + datetime.timedelta(weeks=13)
|
||||||
# start_date = datetime.date(2022, 10, 10)
|
# start_date = datetime.date(2022, 10, 10)
|
||||||
|
|
||||||
Rota = RotaBuilder(start_date, weeks_to_rota=10, balance_offset_modifier=1)
|
Rota = RotaBuilder(
|
||||||
#Rota = RotaBuilder(start_date, weeks_to_rota=20, balance_offset_modifier=1)
|
start_date, weeks_to_rota=10, balance_offset_modifier=1, name="proc rota"
|
||||||
|
)
|
||||||
|
# Rota = RotaBuilder(start_date, weeks_to_rota=20, balance_offset_modifier=1)
|
||||||
Rota.constraint_options["balance_weekends"] = True
|
Rota.constraint_options["balance_weekends"] = True
|
||||||
Rota.constraint_options["max_night_frequency"] = 3 # 3
|
Rota.constraint_options["max_night_frequency"] = 3 # 3
|
||||||
Rota.constraint_options["max_night_frequency_week_exclusions"] = []
|
Rota.constraint_options["max_night_frequency_week_exclusions"] = []
|
||||||
@@ -132,7 +134,7 @@ Rota.add_shifts(
|
|||||||
constraint=[{"name": "pre", "options": 2}, {"name": "post", "options": 2}],
|
constraint=[{"name": "pre", "options": 2}, {"name": "post", "options": 2}],
|
||||||
),
|
),
|
||||||
SingleShift(
|
SingleShift(
|
||||||
sites=("plymouth","plymouth twilights and weekends"),
|
sites=("plymouth", "plymouth twilights and weekends"),
|
||||||
name="weekend_plymouth2",
|
name="weekend_plymouth2",
|
||||||
length=8,
|
length=8,
|
||||||
days=days[5:],
|
days=days[5:],
|
||||||
@@ -143,7 +145,7 @@ Rota.add_shifts(
|
|||||||
constraint=[{"name": "pre", "options": 2}, {"name": "post", "options": 2}],
|
constraint=[{"name": "pre", "options": 2}, {"name": "post", "options": 2}],
|
||||||
),
|
),
|
||||||
SingleShift(
|
SingleShift(
|
||||||
sites=("plymouth", "plymouth twilights","plymouth twilights and weekends"),
|
sites=("plymouth", "plymouth twilights", "plymouth twilights and weekends"),
|
||||||
name="plymouth_bank_holidays",
|
name="plymouth_bank_holidays",
|
||||||
length=8,
|
length=8,
|
||||||
days=days[5:],
|
days=days[5:],
|
||||||
@@ -195,11 +197,11 @@ Rota.add_shifts(
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
#Rota.add_grade_constraint_by_week([2], [1, 2], ["night_weekday", "night_weekend"])
|
# Rota.add_grade_constraint_by_week([2], [1, 2], ["night_weekday", "night_weekend"])
|
||||||
|
|
||||||
load_leave = True
|
load_leave = True
|
||||||
Rota.build_shifts()
|
Rota.build_shifts()
|
||||||
#Rota.add_grade_constraint_by_week([2], [1], Rota.get_shift_names())
|
# Rota.add_grade_constraint_by_week([2], [1], Rota.get_shift_names())
|
||||||
|
|
||||||
if load_leave:
|
if load_leave:
|
||||||
import leave
|
import leave
|
||||||
@@ -254,13 +256,19 @@ if load_leave:
|
|||||||
# nwds = [i.strip()[:3].capitalize() for i in nwd.split("/")] if nwd else None
|
# nwds = [i.strip()[:3].capitalize() for i in nwd.split("/")] if nwd else None
|
||||||
end_date = end_date if end_date else None
|
end_date = end_date if end_date else None
|
||||||
|
|
||||||
|
|
||||||
if oop:
|
if oop:
|
||||||
formatted_oops = []
|
formatted_oops = []
|
||||||
for dates in oop.split(","):
|
for dates in oop.split(","):
|
||||||
s, e = dates.split("-")
|
s, e = dates.split("-")
|
||||||
formatted_oops.append(
|
formatted_oops.append(
|
||||||
{"start_date": datetime.datetime.strptime(s.strip(), "%d/%m/%y").date(), "end_date": datetime.datetime.strptime(e.strip(), "%d/%m/%y").date()}
|
{
|
||||||
|
"start_date": datetime.datetime.strptime(
|
||||||
|
s.strip(), "%d/%m/%y"
|
||||||
|
).date(),
|
||||||
|
"end_date": datetime.datetime.strptime(
|
||||||
|
e.strip(), "%d/%m/%y"
|
||||||
|
).date(),
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
oop = formatted_oops
|
oop = formatted_oops
|
||||||
@@ -328,14 +336,14 @@ if load_leave:
|
|||||||
|
|
||||||
solver_options = {"ratio": ratio, "seconds": time_to_run, "threads": 10}
|
solver_options = {"ratio": ratio, "seconds": time_to_run, "threads": 10}
|
||||||
|
|
||||||
start_time = time.time()
|
#start_time = time.time()
|
||||||
Rota.build_and_solve(solver_options)
|
Rota.build_and_solve(solver_options, export=True)
|
||||||
#Rota.solve_shifts_by_block(solver_options, block_length=13)
|
# Rota.solve_shifts_by_block(solver_options, block_length=13)
|
||||||
#Rota.solve_shifts_individually(solver_options)
|
# Rota.solve_shifts_individually(solver_options)
|
||||||
# Rota.solve_model(options=solver_options)
|
# Rota.solve_model(options=solver_options)
|
||||||
end_time = time.time()
|
#end_time = time.time()
|
||||||
|
|
||||||
print(f"Time taken {end_time-start_time}")
|
#print(f"Time taken {end_time-start_time}")
|
||||||
|
|
||||||
# print(Rota.get_worker_details())
|
# print(Rota.get_worker_details())
|
||||||
|
|
||||||
@@ -353,7 +361,7 @@ print(f"Time taken {end_time-start_time}")
|
|||||||
# print(worker_timetable_brief)
|
# print(worker_timetable_brief)
|
||||||
|
|
||||||
|
|
||||||
Rota.export_rota_to_html("proc_rota")
|
#Rota.export_rota_to_html("proc_rota")
|
||||||
# Rota.export_rota_to_csv("rota")
|
# Rota.export_rota_to_csv("rota")
|
||||||
|
|
||||||
if suspend_on_finish:
|
if suspend_on_finish:
|
||||||
|
|||||||
+15
-7
@@ -191,19 +191,23 @@ class RotaBuilder(object):
|
|||||||
use_shift_balance_extra: bool = False,
|
use_shift_balance_extra: bool = False,
|
||||||
use_bank_holiday_extra: bool = False,
|
use_bank_holiday_extra: bool = False,
|
||||||
SHIFT_BOUNDS=SHIFT_BOUNDS,
|
SHIFT_BOUNDS=SHIFT_BOUNDS,
|
||||||
|
name: str = "",
|
||||||
):
|
):
|
||||||
|
|
||||||
|
self.name = name
|
||||||
|
|
||||||
console.print(
|
console.print(
|
||||||
Panel(
|
Panel(
|
||||||
f"""[white]
|
f"""[white]
|
||||||
{locals()}
|
{locals()}
|
||||||
""",
|
""",
|
||||||
style="green",
|
style="green",
|
||||||
title="Generating Rota",
|
title=f"Generating Rota: {name}",
|
||||||
),
|
),
|
||||||
justify="left",
|
justify="left",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
self.SHIFT_BOUNDS = SHIFT_BOUNDS
|
self.SHIFT_BOUNDS = SHIFT_BOUNDS
|
||||||
self.shifts: List[SingleShift] = [] # type List[SingleShift]
|
self.shifts: List[SingleShift] = [] # type List[SingleShift]
|
||||||
|
|
||||||
@@ -307,13 +311,11 @@ class RotaBuilder(object):
|
|||||||
):
|
):
|
||||||
console.print("Setting up solver")
|
console.print("Setting up solver")
|
||||||
|
|
||||||
solver = "scip"
|
|
||||||
|
|
||||||
if solver == "scip":
|
if solver == "scip":
|
||||||
if "seconds" in options:
|
if "seconds" in options:
|
||||||
options["limit/time"] = options.pop("seconds")
|
options["limits/time"] = options.pop("seconds")
|
||||||
if "ratio" in options:
|
if "ratio" in options:
|
||||||
options["limit/gap"] = options.pop("ratio")
|
options["limits/gap"] = options.pop("ratio")
|
||||||
if "threads" in options:
|
if "threads" in options:
|
||||||
options.pop("threads")
|
options.pop("threads")
|
||||||
self.opt = SolverFactory(solver, executable="scip")
|
self.opt = SolverFactory(solver, executable="scip")
|
||||||
@@ -322,6 +324,8 @@ class RotaBuilder(object):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
console.print("Solving")
|
console.print("Solving")
|
||||||
|
|
||||||
|
log_file = f"{self.name}_{datetime.datetime.now().strftime('%Y%m%d-%H%M%S')}.log"
|
||||||
if use_neos:
|
if use_neos:
|
||||||
solver_manager = SolverManagerFactory("neos") # Solve using neos server
|
solver_manager = SolverManagerFactory("neos") # Solve using neos server
|
||||||
# results = solver_manager.solve(Rota.model, opt=opt, logfile="test.log")
|
# results = solver_manager.solve(Rota.model, opt=opt, logfile="test.log")
|
||||||
@@ -330,7 +334,7 @@ class RotaBuilder(object):
|
|||||||
keepfiles=True,
|
keepfiles=True,
|
||||||
tee=True,
|
tee=True,
|
||||||
opt=self.opt,
|
opt=self.opt,
|
||||||
logfile="test.log",
|
logfile=log_file,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
results = self.opt.solve(
|
results = self.opt.solve(
|
||||||
@@ -340,7 +344,7 @@ class RotaBuilder(object):
|
|||||||
# options={
|
# options={
|
||||||
# "threads": 10,
|
# "threads": 10,
|
||||||
# },
|
# },
|
||||||
logfile="test.log",
|
logfile=log_file,
|
||||||
keepfiles=True,
|
keepfiles=True,
|
||||||
)
|
)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
@@ -417,6 +421,7 @@ class RotaBuilder(object):
|
|||||||
options={"ratio": 0.1, "seconds": 1000, "threads": 10},
|
options={"ratio": 0.1, "seconds": 1000, "threads": 10},
|
||||||
solve=True,
|
solve=True,
|
||||||
debug_if_fail: bool = False,
|
debug_if_fail: bool = False,
|
||||||
|
export=False
|
||||||
):
|
):
|
||||||
|
|
||||||
self.run_start_time = datetime.datetime.now()
|
self.run_start_time = datetime.datetime.now()
|
||||||
@@ -430,6 +435,9 @@ class RotaBuilder(object):
|
|||||||
|
|
||||||
self.run_end_time = datetime.datetime.now()
|
self.run_end_time = datetime.datetime.now()
|
||||||
|
|
||||||
|
if export:
|
||||||
|
self.export_rota_to_html(self.name)
|
||||||
|
|
||||||
def build_model(self):
|
def build_model(self):
|
||||||
# Initialize model
|
# Initialize model
|
||||||
self.model = ConcreteModel()
|
self.model = ConcreteModel()
|
||||||
|
|||||||
Reference in New Issue
Block a user