it works?

This commit is contained in:
Ross
2020-05-14 23:40:48 +01:00
parent 0ac1990cfd
commit 12f7b5270c
13 changed files with 1657 additions and 289 deletions
+123 -33
View File
@@ -15,13 +15,17 @@ import datetime
import itertools
import operator
use_neos = False
weeks_to_rota = 26
sites = ("truro", "exeter", "torquay", "barnstaple", "plymouth")
Rota = RotaBuilder(datetime.date(2020, 9, 7),
weeks_to_rota=weeks_to_rota,
balance_offset_modifier=1)
balance_offset_modifier=1,
max_weekend_frequency=1,
max_night_frequency=2)
rota_collections = {
"current": deepcopy(Rota),
@@ -59,27 +63,51 @@ rota_collections['current'].add_shifts(
days[5:],
workers_required=2,
assign_as_block=True),
#SingleShift((sites), "night", 12.5, days, balance_weighting=1, workers_required=3, rota_on_nwds=True),
SingleShift((sites),
"night",
"night_weekday",
12.25,
days,
balance_offset=2,
days[:4],
balance_offset=5,
balance_weighting=1,
workers_required=3,
rota_on_nwds=True),
force_as_block=False,
rota_on_nwds=True,
constraints=["night"]),
SingleShift((sites),
"night_weekend",
12.25,
days[4:],
balance_offset=4,
balance_weighting=1,
workers_required=3,
force_as_block=False,
rota_on_nwds=True,
constraints=["night"]),
)
rota_collections['extended proc nights only'].add_shifts(
#SingleShift((sites), "night", 12.5, days, balance_weighting=1, workers_required=3, rota_on_nwds=True),
SingleShift((sites),
"night",
"night_weekday",
13,
days,
balance_offset=2,
days[:4],
balance_offset=5,
balance_weighting=1,
workers_required=3,
rota_on_nwds=True), )
force_as_block=False,
rota_on_nwds=True,
constraints=["night"]),
SingleShift((sites),
"night_weekend",
13,
days[4:],
balance_offset=4,
balance_weighting=1,
workers_required=3,
force_as_block=False,
rota_on_nwds=True,
constraints=["night"]),
)
rota_collections['no weekends'].add_shifts(
SingleShift(("exeter", ), "exeter_twilight", 12.5, days[:5]),
@@ -88,13 +116,25 @@ rota_collections['no weekends'].add_shifts(
SingleShift(("plymouth", ), "plymouth_twilight", 12.5, days[:5]),
#SingleShift((sites), "night", 12.5, days, balance_weighting=1, workers_required=3, rota_on_nwds=True),
SingleShift((sites),
"night",
"night_weekday",
13,
days,
balance_offset=2,
days[:4],
balance_offset=5,
balance_weighting=1,
workers_required=3,
rota_on_nwds=True),
force_as_block=False,
rota_on_nwds=True,
constraints=["night"]),
SingleShift((sites),
"night_weekend",
13,
days[4:],
balance_offset=4,
balance_weighting=1,
workers_required=3,
force_as_block=False,
rota_on_nwds=True,
constraints=["night"]),
)
rota_collections['no twighlights'].add_shifts(
@@ -121,13 +161,25 @@ rota_collections['no twighlights'].add_shifts(
assign_as_block=True),
#SingleShift((sites), "night", 12.5, days, balance_weighting=1, workers_required=3, rota_on_nwds=True),
SingleShift((sites),
"night",
"night_weekday",
13,
days,
balance_offset=2,
days[:4],
balance_offset=5,
balance_weighting=1,
workers_required=3,
rota_on_nwds=True),
force_as_block=False,
rota_on_nwds=True,
constraints=["night"]),
SingleShift((sites),
"night_weekend",
13,
days[4:],
balance_offset=4,
balance_weighting=1,
workers_required=3,
force_as_block=False,
rota_on_nwds=True,
constraints=["night"]),
)
rota_collections['no nights'].add_shifts(
@@ -184,13 +236,25 @@ rota_collections['nights + proc twighlights + normal weekends'].add_shifts(
assign_as_block=True),
#SingleShift((sites), "night", 12.5, days, balance_weighting=1, workers_required=3, rota_on_nwds=True),
SingleShift((sites),
"night",
"night_weekday",
12.25,
days,
balance_offset=2,
days[:4],
balance_offset=5,
balance_weighting=1,
workers_required=3,
rota_on_nwds=True),
force_as_block=False,
rota_on_nwds=True,
constraints=["night"]),
SingleShift((sites),
"night_weekend",
12.25,
days[4:],
balance_offset=4,
balance_weighting=1,
workers_required=3,
force_as_block=False,
rota_on_nwds=True,
constraints=["night"]),
)
rota_collections['nights + proc twighlights + proc weekends'].add_shifts(
@@ -201,13 +265,25 @@ rota_collections['nights + proc twighlights + proc weekends'].add_shifts(
workers_required=3),
#SingleShift((sites), "night", 12.5, days, balance_weighting=1, workers_required=3, rota_on_nwds=True),
SingleShift((sites),
"night",
"night_weekday",
12.25,
days,
balance_offset=2,
days[:4],
balance_offset=5,
balance_weighting=1,
workers_required=3,
rota_on_nwds=True),
force_as_block=False,
rota_on_nwds=True,
constraints=["night"]),
SingleShift((sites),
"night_weekend",
12.25,
days[4:],
balance_offset=4,
balance_weighting=1,
workers_required=3,
force_as_block=False,
rota_on_nwds=True,
constraints=["night"]),
)
# Import trainee data
@@ -245,16 +321,30 @@ for rot in rota_collections:
Rota.build_shifts_and_workers()
print("-Building model")
Rota.build_model()
print("-Building model: complete")
opt = SolverFactory('cbc') # choose a solver
#opt = SolverFactory('ipopt') # choose a solver
results = opt.solve(
Rota.model, tee=True, options={
"seconds": 1200,
"allow": 3500
}) # solve the model with the, options="seconds=60" selected solver
if use_neos:
print("-Solving with neos")
solver_manager = SolverManagerFactory('neos') # Solve in neos server
results = solver_manager.solve(Rota.model,
opt=opt,
logfile="{}.log".format(rot))
else:
print("-Solving with local cbc")
results = opt.solve(
Rota.model,
tee=True,
options={
"seconds": 3200,
"allow": 2200,
},
logfile="{}.log".format(rot)
) # solve the model with the, options="seconds=60" selected solver
results.solver.status
@@ -285,8 +375,8 @@ for rot in rota_collections:
f.write("<pre>{}</pre>".format(worker_shift_summary))
f.write("\n\n\n")
#workers_no_pref = ResultsHolder.get_no_preference(Rota.model.no_pref) # list with the non-satisfied workers (work on Sat but not on Sun)
worker_night_block = ResultsHolder.get_night_blocks()
multi = ResultsHolder.get_multinight()
#worker_night_block = ResultsHolder.get_night_blocks()
#multi = ResultsHolder.get_multinight()
#break