fix min summed shifts
This commit is contained in:
+32
-9
@@ -1029,13 +1029,15 @@ class RotaBuilder(object):
|
||||
for day in days_list:
|
||||
# Only consider if all shifts are present that day
|
||||
if all(shift in self.get_shift_names_by_week_day(week, day) for shift in constraint.shifts):
|
||||
self.model.constraints.add(
|
||||
sum(
|
||||
worker.grade * self.model.works[worker.id, week, day, shift]
|
||||
for shift in constraint.shifts
|
||||
for worker in self.get_workers_for_shift(self.get_shift_by_name(shift))
|
||||
) >= constraint.min_grade_sum
|
||||
)
|
||||
expr_terms = [
|
||||
worker.grade * self.model.works[worker.id, week, day, shift]
|
||||
for shift in constraint.shifts
|
||||
for worker in self.get_workers_for_shift(self.get_shift_by_name(shift))
|
||||
]
|
||||
if expr_terms: # Only add constraint if there are eligible workers
|
||||
self.model.constraints.add(
|
||||
sum(expr_terms) >= constraint.min_grade_sum
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -1783,6 +1785,15 @@ class RotaBuilder(object):
|
||||
- adjusted_balance_offset * self.balance_offset_modifier
|
||||
)
|
||||
|
||||
# --- Store for export ---
|
||||
if not hasattr(worker, "hard_constrain_shift_limits"):
|
||||
worker.hard_constrain_shift_limits = {}
|
||||
worker.hard_constrain_shift_limits[shift.name] = {
|
||||
"min_shifts": min_shifts,
|
||||
"max_shifts": max_shifts,
|
||||
"target_shifts": target_shifts,
|
||||
}
|
||||
|
||||
self.model.constraints.add(
|
||||
inequality(
|
||||
min_shifts,
|
||||
@@ -1791,8 +1802,6 @@ class RotaBuilder(object):
|
||||
for week, day in self.get_week_day_combinations_for_shift(
|
||||
shift
|
||||
)
|
||||
# for week, day in self.get_week_day_combinations()
|
||||
# if shift.name in self.get_shift_names_by_week_day(week, day)
|
||||
),
|
||||
max_shifts,
|
||||
)
|
||||
@@ -4190,6 +4199,15 @@ class RotaBuilder(object):
|
||||
|
||||
joined_timetable = "\n".join(timetable)
|
||||
|
||||
hard_constrain_shift_info = []
|
||||
for worker in self.workers:
|
||||
for shift_name, limits in getattr(worker, "hard_constrain_shift_limits", {}).items():
|
||||
hard_constrain_shift_info.append({
|
||||
"worker": worker.name,
|
||||
"shift": shift_name,
|
||||
**limits,
|
||||
})
|
||||
|
||||
html = f"""
|
||||
<body>
|
||||
<div class="table-div" id="{table_name}">
|
||||
@@ -4246,6 +4264,11 @@ class RotaBuilder(object):
|
||||
<br/>
|
||||
<div>
|
||||
</details>
|
||||
<details><summary><h2>Hard Constrain Shift Min/Max</h2></summary>
|
||||
<pre>
|
||||
{json.dumps(hard_constrain_shift_info, indent=4)}
|
||||
"</pre></details>
|
||||
|
||||
</div
|
||||
</body>
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user