dabke 0.83.0 → 0.84.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -0
- package/README.md +22 -27
- package/dist/client.d.ts +39 -3
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js.map +1 -1
- package/dist/client.schemas.d.ts +118 -18
- package/dist/client.schemas.d.ts.map +1 -1
- package/dist/client.schemas.js +110 -6
- package/dist/client.schemas.js.map +1 -1
- package/dist/client.types.d.ts +63 -7
- package/dist/client.types.d.ts.map +1 -1
- package/dist/client.types.js.map +1 -1
- package/dist/cpsat/cost.d.ts +5 -2
- package/dist/cpsat/cost.d.ts.map +1 -1
- package/dist/cpsat/cost.js +13 -6
- package/dist/cpsat/cost.js.map +1 -1
- package/dist/cpsat/model-builder.d.ts +42 -61
- package/dist/cpsat/model-builder.d.ts.map +1 -1
- package/dist/cpsat/model-builder.js +451 -56
- package/dist/cpsat/model-builder.js.map +1 -1
- package/dist/cpsat/response.d.ts +19 -7
- package/dist/cpsat/response.d.ts.map +1 -1
- package/dist/cpsat/response.js +48 -9
- package/dist/cpsat/response.js.map +1 -1
- package/dist/cpsat/rule-descriptor.d.ts +250 -0
- package/dist/cpsat/rule-descriptor.d.ts.map +1 -0
- package/dist/cpsat/rule-descriptor.js +51 -0
- package/dist/cpsat/rule-descriptor.js.map +1 -0
- package/dist/cpsat/rules/artifacts.d.ts +9 -0
- package/dist/cpsat/rules/artifacts.d.ts.map +1 -0
- package/dist/cpsat/rules/artifacts.js +31 -0
- package/dist/cpsat/rules/artifacts.js.map +1 -0
- package/dist/cpsat/rules/assign-together.d.ts +18 -20
- package/dist/cpsat/rules/assign-together.d.ts.map +1 -1
- package/dist/cpsat/rules/assign-together.js +90 -54
- package/dist/cpsat/rules/assign-together.js.map +1 -1
- package/dist/cpsat/rules/assigned-day.d.ts +12 -0
- package/dist/cpsat/rules/assigned-day.d.ts.map +1 -0
- package/dist/cpsat/rules/assigned-day.js +43 -0
- package/dist/cpsat/rules/assigned-day.js.map +1 -0
- package/dist/cpsat/rules/assignment-priority.d.ts +15 -29
- package/dist/cpsat/rules/assignment-priority.d.ts.map +1 -1
- package/dist/cpsat/rules/assignment-priority.js +47 -50
- package/dist/cpsat/rules/assignment-priority.js.map +1 -1
- package/dist/cpsat/rules/assignment-terms.d.ts +6 -0
- package/dist/cpsat/rules/assignment-terms.d.ts.map +1 -0
- package/dist/cpsat/rules/assignment-terms.js +19 -0
- package/dist/cpsat/rules/assignment-terms.js.map +1 -0
- package/dist/cpsat/rules/concurrent-intervals.d.ts +19 -0
- package/dist/cpsat/rules/concurrent-intervals.d.ts.map +1 -0
- package/dist/cpsat/rules/concurrent-intervals.js +57 -0
- package/dist/cpsat/rules/concurrent-intervals.js.map +1 -0
- package/dist/cpsat/rules/cost-utils.d.ts +1 -3
- package/dist/cpsat/rules/cost-utils.d.ts.map +1 -1
- package/dist/cpsat/rules/cost-utils.js +0 -7
- package/dist/cpsat/rules/cost-utils.js.map +1 -1
- package/dist/cpsat/rules/day-cost-multiplier.d.ts +10 -10
- package/dist/cpsat/rules/day-cost-multiplier.d.ts.map +1 -1
- package/dist/cpsat/rules/day-cost-multiplier.js +88 -77
- package/dist/cpsat/rules/day-cost-multiplier.js.map +1 -1
- package/dist/cpsat/rules/day-cost-surcharge.d.ts +10 -10
- package/dist/cpsat/rules/day-cost-surcharge.d.ts.map +1 -1
- package/dist/cpsat/rules/day-cost-surcharge.js +76 -65
- package/dist/cpsat/rules/day-cost-surcharge.js.map +1 -1
- package/dist/cpsat/rules/index.d.ts +30 -24
- package/dist/cpsat/rules/index.d.ts.map +1 -1
- package/dist/cpsat/rules/index.js +30 -24
- package/dist/cpsat/rules/index.js.map +1 -1
- package/dist/cpsat/rules/location-preference.d.ts +14 -21
- package/dist/cpsat/rules/location-preference.d.ts.map +1 -1
- package/dist/cpsat/rules/location-preference.js +45 -45
- package/dist/cpsat/rules/location-preference.js.map +1 -1
- package/dist/cpsat/rules/max-concurrent-assignments.d.ts +46 -0
- package/dist/cpsat/rules/max-concurrent-assignments.d.ts.map +1 -0
- package/dist/cpsat/rules/max-concurrent-assignments.js +121 -0
- package/dist/cpsat/rules/max-concurrent-assignments.js.map +1 -0
- package/dist/cpsat/rules/max-consecutive-days.d.ts +18 -17
- package/dist/cpsat/rules/max-consecutive-days.d.ts.map +1 -1
- package/dist/cpsat/rules/max-consecutive-days.js +67 -66
- package/dist/cpsat/rules/max-consecutive-days.js.map +1 -1
- package/dist/cpsat/rules/max-days-of-week-per-period.d.ts +45 -0
- package/dist/cpsat/rules/max-days-of-week-per-period.d.ts.map +1 -0
- package/dist/cpsat/rules/max-days-of-week-per-period.js +95 -0
- package/dist/cpsat/rules/max-days-of-week-per-period.js.map +1 -0
- package/dist/cpsat/rules/max-days-week.d.ts +17 -31
- package/dist/cpsat/rules/max-days-week.d.ts.map +1 -1
- package/dist/cpsat/rules/max-days-week.js +69 -81
- package/dist/cpsat/rules/max-days-week.js.map +1 -1
- package/dist/cpsat/rules/max-hours-day.d.ts +14 -31
- package/dist/cpsat/rules/max-hours-day.d.ts.map +1 -1
- package/dist/cpsat/rules/max-hours-day.js +56 -72
- package/dist/cpsat/rules/max-hours-day.js.map +1 -1
- package/dist/cpsat/rules/max-hours-week.d.ts +15 -31
- package/dist/cpsat/rules/max-hours-week.d.ts.map +1 -1
- package/dist/cpsat/rules/max-hours-week.js +60 -75
- package/dist/cpsat/rules/max-hours-week.js.map +1 -1
- package/dist/cpsat/rules/max-shifts-day.d.ts +17 -33
- package/dist/cpsat/rules/max-shifts-day.d.ts.map +1 -1
- package/dist/cpsat/rules/max-shifts-day.js +57 -73
- package/dist/cpsat/rules/max-shifts-day.js.map +1 -1
- package/dist/cpsat/rules/min-consecutive-days.d.ts +18 -18
- package/dist/cpsat/rules/min-consecutive-days.d.ts.map +1 -1
- package/dist/cpsat/rules/min-consecutive-days.js +123 -94
- package/dist/cpsat/rules/min-consecutive-days.js.map +1 -1
- package/dist/cpsat/rules/min-days-of-week-per-period.d.ts +35 -0
- package/dist/cpsat/rules/min-days-of-week-per-period.d.ts.map +1 -0
- package/dist/cpsat/rules/min-days-of-week-per-period.js +108 -0
- package/dist/cpsat/rules/min-days-of-week-per-period.js.map +1 -0
- package/dist/cpsat/rules/min-days-week.d.ts +13 -26
- package/dist/cpsat/rules/min-days-week.d.ts.map +1 -1
- package/dist/cpsat/rules/min-days-week.js +85 -74
- package/dist/cpsat/rules/min-days-week.js.map +1 -1
- package/dist/cpsat/rules/min-hours-day.d.ts +14 -17
- package/dist/cpsat/rules/min-hours-day.d.ts.map +1 -1
- package/dist/cpsat/rules/min-hours-day.js +72 -54
- package/dist/cpsat/rules/min-hours-day.js.map +1 -1
- package/dist/cpsat/rules/min-hours-week.d.ts +15 -18
- package/dist/cpsat/rules/min-hours-week.d.ts.map +1 -1
- package/dist/cpsat/rules/min-hours-week.js +75 -57
- package/dist/cpsat/rules/min-hours-week.js.map +1 -1
- package/dist/cpsat/rules/min-rest-between-shifts.d.ts +14 -17
- package/dist/cpsat/rules/min-rest-between-shifts.d.ts.map +1 -1
- package/dist/cpsat/rules/min-rest-between-shifts.js +148 -138
- package/dist/cpsat/rules/min-rest-between-shifts.js.map +1 -1
- package/dist/cpsat/rules/minimize-cost.d.ts +2 -18
- package/dist/cpsat/rules/minimize-cost.d.ts.map +1 -1
- package/dist/cpsat/rules/minimize-cost.js +151 -163
- package/dist/cpsat/rules/minimize-cost.js.map +1 -1
- package/dist/cpsat/rules/must-assign.d.ts +5 -42
- package/dist/cpsat/rules/must-assign.d.ts.map +1 -1
- package/dist/cpsat/rules/must-assign.js +43 -75
- package/dist/cpsat/rules/must-assign.js.map +1 -1
- package/dist/cpsat/rules/overtime-daily-multiplier.d.ts +6 -10
- package/dist/cpsat/rules/overtime-daily-multiplier.d.ts.map +1 -1
- package/dist/cpsat/rules/overtime-daily-multiplier.js +118 -112
- package/dist/cpsat/rules/overtime-daily-multiplier.js.map +1 -1
- package/dist/cpsat/rules/overtime-daily-surcharge.d.ts +6 -11
- package/dist/cpsat/rules/overtime-daily-surcharge.d.ts.map +1 -1
- package/dist/cpsat/rules/overtime-daily-surcharge.js +104 -99
- package/dist/cpsat/rules/overtime-daily-surcharge.js.map +1 -1
- package/dist/cpsat/rules/overtime-tiered-multiplier.d.ts +9 -21
- package/dist/cpsat/rules/overtime-tiered-multiplier.d.ts.map +1 -1
- package/dist/cpsat/rules/overtime-tiered-multiplier.js +181 -199
- package/dist/cpsat/rules/overtime-tiered-multiplier.js.map +1 -1
- package/dist/cpsat/rules/overtime-weekly-multiplier.d.ts +13 -12
- package/dist/cpsat/rules/overtime-weekly-multiplier.d.ts.map +1 -1
- package/dist/cpsat/rules/overtime-weekly-multiplier.js +143 -143
- package/dist/cpsat/rules/overtime-weekly-multiplier.js.map +1 -1
- package/dist/cpsat/rules/overtime-weekly-surcharge.d.ts +7 -11
- package/dist/cpsat/rules/overtime-weekly-surcharge.d.ts.map +1 -1
- package/dist/cpsat/rules/overtime-weekly-surcharge.js +124 -119
- package/dist/cpsat/rules/overtime-weekly-surcharge.js.map +1 -1
- package/dist/cpsat/rules/pattern-eligibility.d.ts +6 -0
- package/dist/cpsat/rules/pattern-eligibility.d.ts.map +1 -0
- package/dist/cpsat/rules/pattern-eligibility.js +16 -0
- package/dist/cpsat/rules/pattern-eligibility.js.map +1 -0
- package/dist/cpsat/rules/pattern-time.d.ts +5 -0
- package/dist/cpsat/rules/pattern-time.d.ts.map +1 -0
- package/dist/cpsat/rules/pattern-time.js +20 -0
- package/dist/cpsat/rules/pattern-time.js.map +1 -0
- package/dist/cpsat/rules/registry.d.ts +217 -30
- package/dist/cpsat/rules/registry.d.ts.map +1 -1
- package/dist/cpsat/rules/registry.js +98 -34
- package/dist/cpsat/rules/registry.js.map +1 -1
- package/dist/cpsat/rules/resolver.d.ts +9 -7
- package/dist/cpsat/rules/resolver.d.ts.map +1 -1
- package/dist/cpsat/rules/resolver.js +19 -18
- package/dist/cpsat/rules/resolver.js.map +1 -1
- package/dist/cpsat/rules/role-preference.d.ts +24 -0
- package/dist/cpsat/rules/role-preference.d.ts.map +1 -0
- package/dist/cpsat/rules/role-preference.js +72 -0
- package/dist/cpsat/rules/role-preference.js.map +1 -0
- package/dist/cpsat/rules/rules.types.d.ts +90 -17
- package/dist/cpsat/rules/rules.types.d.ts.map +1 -1
- package/dist/cpsat/rules/scope.types.d.ts +24 -11
- package/dist/cpsat/rules/scope.types.d.ts.map +1 -1
- package/dist/cpsat/rules/scope.types.js +14 -19
- package/dist/cpsat/rules/scope.types.js.map +1 -1
- package/dist/cpsat/rules/target-days-week.d.ts +31 -0
- package/dist/cpsat/rules/target-days-week.d.ts.map +1 -0
- package/dist/cpsat/rules/target-days-week.js +80 -0
- package/dist/cpsat/rules/target-days-week.js.map +1 -0
- package/dist/cpsat/rules/target-peak-concurrent-assignments.d.ts +33 -0
- package/dist/cpsat/rules/target-peak-concurrent-assignments.d.ts.map +1 -0
- package/dist/cpsat/rules/target-peak-concurrent-assignments.js +146 -0
- package/dist/cpsat/rules/target-peak-concurrent-assignments.js.map +1 -0
- package/dist/cpsat/rules/time-cost-surcharge.d.ts +15 -14
- package/dist/cpsat/rules/time-cost-surcharge.d.ts.map +1 -1
- package/dist/cpsat/rules/time-cost-surcharge.js +82 -96
- package/dist/cpsat/rules/time-cost-surcharge.js.map +1 -1
- package/dist/cpsat/rules/time-off.d.ts +21 -57
- package/dist/cpsat/rules/time-off.d.ts.map +1 -1
- package/dist/cpsat/rules/time-off.js +114 -127
- package/dist/cpsat/rules/time-off.js.map +1 -1
- package/dist/cpsat/rules/variables.d.ts +4 -0
- package/dist/cpsat/rules/variables.d.ts.map +1 -0
- package/dist/cpsat/rules/variables.js +10 -0
- package/dist/cpsat/rules/variables.js.map +1 -0
- package/dist/cpsat/rules.d.ts +20 -3
- package/dist/cpsat/rules.d.ts.map +1 -1
- package/dist/cpsat/rules.js +19 -2
- package/dist/cpsat/rules.js.map +1 -1
- package/dist/cpsat/semantic-time.d.ts +7 -6
- package/dist/cpsat/semantic-time.d.ts.map +1 -1
- package/dist/cpsat/semantic-time.js +15 -28
- package/dist/cpsat/semantic-time.js.map +1 -1
- package/dist/cpsat/types.d.ts +47 -4
- package/dist/cpsat/types.d.ts.map +1 -1
- package/dist/cpsat/types.js +24 -1
- package/dist/cpsat/types.js.map +1 -1
- package/dist/cpsat/utils.d.ts +23 -6
- package/dist/cpsat/utils.d.ts.map +1 -1
- package/dist/cpsat/utils.js +76 -15
- package/dist/cpsat/utils.js.map +1 -1
- package/dist/cpsat/validation-reporter.d.ts +6 -2
- package/dist/cpsat/validation-reporter.d.ts.map +1 -1
- package/dist/cpsat/validation-reporter.js +122 -10
- package/dist/cpsat/validation-reporter.js.map +1 -1
- package/dist/cpsat/validation.types.d.ts +21 -10
- package/dist/cpsat/validation.types.d.ts.map +1 -1
- package/dist/datetime.utils.d.ts +7 -13
- package/dist/datetime.utils.d.ts.map +1 -1
- package/dist/datetime.utils.js +29 -36
- package/dist/datetime.utils.js.map +1 -1
- package/dist/index.d.ts +12 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -3
- package/dist/index.js.map +1 -1
- package/dist/schedule/cost.d.ts +48 -60
- package/dist/schedule/cost.d.ts.map +1 -1
- package/dist/schedule/cost.js +15 -51
- package/dist/schedule/cost.js.map +1 -1
- package/dist/schedule/coverage.d.ts +57 -28
- package/dist/schedule/coverage.d.ts.map +1 -1
- package/dist/schedule/coverage.js +24 -1
- package/dist/schedule/coverage.js.map +1 -1
- package/dist/schedule/definition.d.ts +138 -19
- package/dist/schedule/definition.d.ts.map +1 -1
- package/dist/schedule/definition.js +99 -90
- package/dist/schedule/definition.js.map +1 -1
- package/dist/schedule/index.d.ts +4 -4
- package/dist/schedule/index.d.ts.map +1 -1
- package/dist/schedule/index.js +2 -2
- package/dist/schedule/index.js.map +1 -1
- package/dist/schedule/rules.d.ts +438 -113
- package/dist/schedule/rules.d.ts.map +1 -1
- package/dist/schedule/rules.js +310 -108
- package/dist/schedule/rules.js.map +1 -1
- package/dist/schedule/shift-patterns.d.ts +0 -17
- package/dist/schedule/shift-patterns.d.ts.map +1 -1
- package/dist/schedule/shift-patterns.js +0 -17
- package/dist/schedule/shift-patterns.js.map +1 -1
- package/dist/schedule/time-periods.d.ts +37 -27
- package/dist/schedule/time-periods.d.ts.map +1 -1
- package/dist/schedule/time-periods.js +37 -27
- package/dist/schedule/time-periods.js.map +1 -1
- package/dist/types.d.ts +67 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +64 -0
- package/dist/types.js.map +1 -1
- package/package.json +8 -9
- package/solver/src/solver/models.py +41 -4
- package/solver/src/solver/solver.py +546 -157
- package/solver/tests/test_solver.py +363 -7
- package/src/client.schemas.ts +127 -10
- package/src/client.ts +3 -0
- package/src/client.types.ts +73 -7
- package/src/cpsat/cost.ts +17 -7
- package/src/cpsat/model-builder.ts +614 -129
- package/src/cpsat/response.ts +57 -13
- package/src/cpsat/rule-descriptor.ts +311 -0
- package/src/cpsat/rules/artifacts.ts +56 -0
- package/src/cpsat/rules/assign-together.ts +104 -69
- package/src/cpsat/rules/assigned-day.ts +70 -0
- package/src/cpsat/rules/assignment-priority.ts +54 -58
- package/src/cpsat/rules/assignment-terms.ts +43 -0
- package/src/cpsat/rules/concurrent-intervals.ts +93 -0
- package/src/cpsat/rules/cost-utils.ts +1 -9
- package/src/cpsat/rules/day-cost-multiplier.ts +101 -81
- package/src/cpsat/rules/day-cost-surcharge.ts +91 -70
- package/src/cpsat/rules/index.ts +30 -24
- package/src/cpsat/rules/location-preference.ts +47 -52
- package/src/cpsat/rules/max-concurrent-assignments.ts +170 -0
- package/src/cpsat/rules/max-consecutive-days.ts +74 -91
- package/src/cpsat/rules/max-days-of-week-per-period.ts +127 -0
- package/src/cpsat/rules/max-days-week.ts +89 -115
- package/src/cpsat/rules/max-hours-day.ts +64 -84
- package/src/cpsat/rules/max-hours-week.ts +74 -90
- package/src/cpsat/rules/max-shifts-day.ts +65 -85
- package/src/cpsat/rules/min-consecutive-days.ts +161 -127
- package/src/cpsat/rules/min-days-of-week-per-period.ts +144 -0
- package/src/cpsat/rules/min-days-week.ts +93 -91
- package/src/cpsat/rules/min-hours-day.ts +79 -58
- package/src/cpsat/rules/min-hours-week.ts +87 -62
- package/src/cpsat/rules/min-rest-between-shifts.ts +191 -178
- package/src/cpsat/rules/minimize-cost.ts +175 -188
- package/src/cpsat/rules/must-assign.ts +44 -81
- package/src/cpsat/rules/overtime-daily-multiplier.ts +158 -140
- package/src/cpsat/rules/overtime-daily-surcharge.ts +141 -126
- package/src/cpsat/rules/overtime-tiered-multiplier.ts +234 -253
- package/src/cpsat/rules/overtime-weekly-multiplier.ts +183 -175
- package/src/cpsat/rules/overtime-weekly-surcharge.ts +161 -150
- package/src/cpsat/rules/pattern-eligibility.ts +26 -0
- package/src/cpsat/rules/pattern-time.ts +30 -0
- package/src/cpsat/rules/registry.ts +140 -62
- package/src/cpsat/rules/resolver.ts +58 -30
- package/src/cpsat/rules/role-preference.ts +92 -0
- package/src/cpsat/rules/rules.types.ts +89 -17
- package/src/cpsat/rules/scope.types.ts +31 -26
- package/src/cpsat/rules/target-days-week.ts +105 -0
- package/src/cpsat/rules/target-peak-concurrent-assignments.ts +212 -0
- package/src/cpsat/rules/time-cost-surcharge.ts +116 -122
- package/src/cpsat/rules/time-off.ts +154 -163
- package/src/cpsat/rules/variables.ts +11 -0
- package/src/cpsat/rules.ts +43 -17
- package/src/cpsat/semantic-time.ts +29 -43
- package/src/cpsat/types.ts +53 -4
- package/src/cpsat/utils.ts +92 -20
- package/src/cpsat/validation-reporter.ts +170 -19
- package/src/cpsat/validation.types.ts +22 -11
- package/src/datetime.utils.ts +45 -44
- package/src/index.ts +64 -12
- package/src/schedule/cost.ts +40 -61
- package/src/schedule/coverage.ts +57 -28
- package/src/schedule/definition.ts +565 -76
- package/src/schedule/index.ts +23 -3
- package/src/schedule/rules.ts +631 -132
- package/src/schedule/shift-patterns.ts +0 -17
- package/src/schedule/time-periods.ts +37 -27
- package/src/types.ts +114 -2
package/dist/schedule/rules.d.ts
CHANGED
|
@@ -1,10 +1,65 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Scheduling rules: constraints, preferences, and time-off.
|
|
3
3
|
*
|
|
4
|
+
* Rules answer "what schedules are allowed or preferred?". Use
|
|
5
|
+
* {@link cover} for lower-bound demand, then use rules for caps, limits, rest
|
|
6
|
+
* periods, time off, fairness, and other constraints on assignments.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* rules: [
|
|
11
|
+
* // Hour and day limits
|
|
12
|
+
* maxHoursPerDay(10),
|
|
13
|
+
* maxHoursPerWeek(48),
|
|
14
|
+
* maxHoursPerWeek(20, { appliesTo: "part-time" }),
|
|
15
|
+
* maxDaysPerWeek(5, { priority: "HIGH" }),
|
|
16
|
+
* targetDaysPerWeek(4, { appliesTo: "full-time", priority: "HIGH" }),
|
|
17
|
+
* minDaysPerWeek(4, { appliesTo: "full-time", priority: "HIGH" }),
|
|
18
|
+
* maxShiftsPerDay(1),
|
|
19
|
+
* maxConcurrentAssignments(5, { appliesTo: "chair_stylist" }),
|
|
20
|
+
* targetPeakConcurrentAssignments(5, { appliesTo: "chair_stylist", dayOfWeek: ["thursday"], priority: "HIGH" }),
|
|
21
|
+
* minRestBetweenShifts(11),
|
|
22
|
+
*
|
|
23
|
+
* // Staffing obligations and preferences
|
|
24
|
+
* mustAssign({ appliesTo: ["diana", "yavuz"] }),
|
|
25
|
+
* timeOff({ appliesTo: "alice", dateRange: { start: "2024-02-01", end: "2024-02-05" } }),
|
|
26
|
+
* timeOff({ appliesTo: "student", dayOfWeek: ["wednesday"], from: t(14) }),
|
|
27
|
+
* preferAssignment({ appliesTo: "waiter" }),
|
|
28
|
+
* avoidAssignment({ appliesTo: "student", dayOfWeek: weekdays }),
|
|
29
|
+
* assignTogether(["alice", "bob"]),
|
|
30
|
+
* ]
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* Custom rules can stay type-safe too:
|
|
34
|
+
*
|
|
35
|
+
* ```typescript
|
|
36
|
+
* const debugRuleRegistry = createCpsatRuleRegistry({
|
|
37
|
+
* debug: defineRuleDescriptor({
|
|
38
|
+
* name: "debug",
|
|
39
|
+
* schema: z.object({ flag: z.boolean() }),
|
|
40
|
+
* compile() {
|
|
41
|
+
* return { rule: "debug", artifacts: [] };
|
|
42
|
+
* },
|
|
43
|
+
* }),
|
|
44
|
+
* });
|
|
45
|
+
*
|
|
46
|
+
* const defineDebugRule = defineRuleFor(debugRuleRegistry);
|
|
47
|
+
*
|
|
48
|
+
* schedule({
|
|
49
|
+
* roleIds: ["waiter"],
|
|
50
|
+
* times: { lunch: time({ startTime: t(12), endTime: t(15) }) },
|
|
51
|
+
* coverage: [cover("lunch", "waiter", 1)],
|
|
52
|
+
* shiftPatterns: [shift("lunch", t(12), t(15))],
|
|
53
|
+
* ruleRegistry: debugRuleRegistry,
|
|
54
|
+
* rules: [defineDebugRule("debug", { flag: true })],
|
|
55
|
+
* });
|
|
56
|
+
* ```
|
|
57
|
+
*
|
|
4
58
|
* @module
|
|
5
59
|
*/
|
|
6
60
|
import type { DayOfWeek, TimeOfDay } from "../types.js";
|
|
7
|
-
import type { Priority } from "../cpsat/types.js";
|
|
61
|
+
import type { Priority, SoftPriority } from "../cpsat/types.js";
|
|
62
|
+
import type { BuiltInCpsatRuleRegistry, CpsatRuleConfigEntryFor, CpsatRuleRegistry } from "../cpsat/rules/rules.types.js";
|
|
8
63
|
import type { RecurringPeriod } from "../cpsat/rules/scope.types.js";
|
|
9
64
|
/**
|
|
10
65
|
* Scoping options shared by most rule functions.
|
|
@@ -13,6 +68,13 @@ import type { RecurringPeriod } from "../cpsat/rules/scope.types.js";
|
|
|
13
68
|
* Default priority is `MANDATORY`. Use `appliesTo` to scope to a
|
|
14
69
|
* role, skill, or member ID. Use time scoping options (`dayOfWeek`,
|
|
15
70
|
* `dateRange`, `dates`) to limit when the rule applies.
|
|
71
|
+
* Scope answers where a rule is evaluated. It does not change the rule's core
|
|
72
|
+
* meaning. For example, `maxDaysPerWeek(4, { dayOfWeek: ["monday"] })` is still
|
|
73
|
+
* a day-cap concept, just scoped to matching scheduling days. Priority is just
|
|
74
|
+
* as important as scope: scope decides where a rule applies, and priority decides how hard the solver should enforce it. Use
|
|
75
|
+
* `"MANDATORY"` for requirements the schedule cannot violate, and softer
|
|
76
|
+
* priorities for things the requirements describe as preferred, ideal, or
|
|
77
|
+
* "where possible".
|
|
16
78
|
* Not all rules support all scoping options. Entity-only rules
|
|
17
79
|
* (e.g., {@link maxConsecutiveDays}) ignore time scoping.
|
|
18
80
|
*
|
|
@@ -41,7 +103,8 @@ export interface RuleOptions {
|
|
|
41
103
|
* @remarks
|
|
42
104
|
* Used by rules whose semantics are inherently per-day or per-week
|
|
43
105
|
* (e.g., {@link minHoursPerDay}, {@link maxConsecutiveDays}) and cannot
|
|
44
|
-
* be meaningfully restricted to a date range or day of week.
|
|
106
|
+
* be meaningfully restricted to a date range or day of week. `priority`
|
|
107
|
+
* still controls whether the rule is a hard requirement or a softer target.
|
|
45
108
|
*
|
|
46
109
|
* @category Rules
|
|
47
110
|
*/
|
|
@@ -91,6 +154,60 @@ export interface AssignTogetherOptions {
|
|
|
91
154
|
/** Defaults to `"MANDATORY"`. */
|
|
92
155
|
priority?: Priority;
|
|
93
156
|
}
|
|
157
|
+
/**
|
|
158
|
+
* Options for {@link maxConcurrentAssignments}.
|
|
159
|
+
*
|
|
160
|
+
* @remarks
|
|
161
|
+
* Use this when the business has a hard productive cap that is independent from
|
|
162
|
+
* its coverage floor, for example when only a fixed number of assignments can
|
|
163
|
+
* overlap productively at once. Omit `startTime`/`endTime` to cap concurrent
|
|
164
|
+
* assignments across the full day. Provide both together to limit concurrency
|
|
165
|
+
* only within a specific time window.
|
|
166
|
+
*
|
|
167
|
+
* @category Rules
|
|
168
|
+
*/
|
|
169
|
+
export interface MaxConcurrentAssignmentsOptions extends RuleOptions {
|
|
170
|
+
/** Optional start of the capped time window. */
|
|
171
|
+
startTime?: TimeOfDay;
|
|
172
|
+
/** Optional end of the capped time window. */
|
|
173
|
+
endTime?: TimeOfDay;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Options for {@link targetDaysPerWeek}.
|
|
177
|
+
*
|
|
178
|
+
* @remarks
|
|
179
|
+
* Use this for stated weekly patterns like "works a 4-day week" when that
|
|
180
|
+
* pattern should remain flexible. This is soft-only by design. Pair it with
|
|
181
|
+
* {@link maxDaysPerWeek} when the same number is also a hard cap, and use
|
|
182
|
+
* {@link minDaysPerWeek} only when the requirements explicitly require a minimum.
|
|
183
|
+
*
|
|
184
|
+
* @category Rules
|
|
185
|
+
*/
|
|
186
|
+
export interface TargetDaysPerWeekOptions extends Omit<EntityOnlyRuleOptions, "priority"> {
|
|
187
|
+
/** Soft only. Defaults to `"HIGH"`. */
|
|
188
|
+
priority?: SoftPriority;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Options for {@link targetPeakConcurrentAssignments}.
|
|
192
|
+
*
|
|
193
|
+
* @remarks
|
|
194
|
+
* Use this when the business wants to hit a peak concurrency target within a
|
|
195
|
+
* day, without making that target a lower bound across the whole day. This is
|
|
196
|
+
* soft-only by design. Unlike {@link cover}, this helper does not establish a
|
|
197
|
+
* minimum that must hold throughout a semantic time. Instead it shifts the
|
|
198
|
+
* solution toward reaching the desired peak within the scoped days. Use
|
|
199
|
+
* {@link cover} for a whole-window minimum, and pair
|
|
200
|
+
* this helper with
|
|
201
|
+
* {@link maxConcurrentAssignments} when the same number is also a hard cap.
|
|
202
|
+
* This is useful for language like "fill all 5 chairs on peak days" or
|
|
203
|
+
* "ideally reach full capacity during the busy point".
|
|
204
|
+
*
|
|
205
|
+
* @category Rules
|
|
206
|
+
*/
|
|
207
|
+
export interface TargetPeakConcurrentAssignmentsOptions extends Omit<RuleOptions, "priority"> {
|
|
208
|
+
/** Soft only. Defaults to `"HIGH"`. */
|
|
209
|
+
priority?: SoftPriority;
|
|
210
|
+
}
|
|
94
211
|
/**
|
|
95
212
|
* Context passed to a rule's resolve function during compilation.
|
|
96
213
|
*
|
|
@@ -103,9 +220,9 @@ export interface RuleResolveContext {
|
|
|
103
220
|
readonly skills: ReadonlySet<string>;
|
|
104
221
|
readonly memberIds: ReadonlySet<string>;
|
|
105
222
|
}
|
|
106
|
-
interface RuleEntryBase {
|
|
223
|
+
interface RuleEntryBase<Name extends string = string> {
|
|
107
224
|
readonly _type: "rule";
|
|
108
|
-
readonly _rule:
|
|
225
|
+
readonly _rule: Name;
|
|
109
226
|
/**
|
|
110
227
|
* Optional custom resolver. When present, `resolveRules()` calls this
|
|
111
228
|
* instead of the default translation path. Built-in rules that need
|
|
@@ -113,171 +230,341 @@ interface RuleEntryBase {
|
|
|
113
230
|
* all other rules use the default resolver.
|
|
114
231
|
*/
|
|
115
232
|
readonly _resolve?: (ctx: RuleResolveContext) => Record<string, unknown> & {
|
|
116
|
-
name:
|
|
233
|
+
name: Name;
|
|
117
234
|
};
|
|
118
235
|
}
|
|
119
236
|
/**
|
|
120
|
-
*
|
|
237
|
+
* A typed rule entry returned by rule helpers and {@link defineRule}.
|
|
121
238
|
*
|
|
122
239
|
* @remarks
|
|
123
|
-
* Pass these directly into the `rules` array of {@link ScheduleConfig}.
|
|
124
|
-
*
|
|
240
|
+
* Pass these directly into the `rules` array of {@link ScheduleConfig}. The
|
|
241
|
+
* internal fields are resolved during compilation.
|
|
242
|
+
*
|
|
243
|
+
* @category Rules
|
|
125
244
|
*/
|
|
126
|
-
export type RuleEntry = RuleEntryBase & Record<string, unknown>;
|
|
245
|
+
export type RuleEntry<Name extends string = string, Fields extends object = Record<string, unknown>> = RuleEntryBase<Name> & Fields & Record<string, unknown>;
|
|
246
|
+
type TypedRuleEntryFor<Registry extends CpsatRuleRegistry> = {
|
|
247
|
+
[K in keyof Registry & string]: RuleEntry<K, Omit<CpsatRuleConfigEntryFor<Pick<Registry, K>>, "name">>;
|
|
248
|
+
}[keyof Registry & string];
|
|
249
|
+
/**
|
|
250
|
+
* A rule entry accepted by {@link ScheduleConfig.rules}.
|
|
251
|
+
*
|
|
252
|
+
* @remarks
|
|
253
|
+
* Built-in rule helpers return entries that are always valid. Custom rules created
|
|
254
|
+
* via {@link defineRule} are checked against the active rule registry when passed
|
|
255
|
+
* to {@link schedule} or {@link partialSchedule}. For registry-bound authoring,
|
|
256
|
+
* prefer {@link defineRuleFor}.
|
|
257
|
+
*
|
|
258
|
+
* @category Rules
|
|
259
|
+
*/
|
|
260
|
+
export type ScheduleRuleEntry<TRuleRegistry extends CpsatRuleRegistry = BuiltInCpsatRuleRegistry> = TypedRuleEntryFor<TRuleRegistry>;
|
|
261
|
+
type SanitizedRuleFields<Fields extends object> = Omit<Fields, "_type" | "_rule">;
|
|
262
|
+
type PeriodLength = {
|
|
263
|
+
type: "weeks";
|
|
264
|
+
value: number;
|
|
265
|
+
} | {
|
|
266
|
+
type: "months";
|
|
267
|
+
value: number;
|
|
268
|
+
};
|
|
269
|
+
type TimeOffRuleEntry = RuleEntry<"time-off", TimeOffOptions>;
|
|
270
|
+
type AssignTogetherRuleEntry = RuleEntry<"assign-together", {
|
|
271
|
+
members: [string, string, ...string[]];
|
|
272
|
+
} & AssignTogetherOptions>;
|
|
273
|
+
type DaysOfWeekPerPeriodRuleFields = {
|
|
274
|
+
days: number;
|
|
275
|
+
dayOfWeek: readonly [DayOfWeek, ...DayOfWeek[]];
|
|
276
|
+
period: PeriodLength;
|
|
277
|
+
appliesTo?: string | string[];
|
|
278
|
+
priority?: Priority;
|
|
279
|
+
};
|
|
280
|
+
type MaxDaysOfWeekPerPeriodRuleEntry = RuleEntry<"max-days-of-week-per-period", DaysOfWeekPerPeriodRuleFields>;
|
|
281
|
+
type MinDaysOfWeekPerPeriodRuleEntry = RuleEntry<"min-days-of-week-per-period", DaysOfWeekPerPeriodRuleFields>;
|
|
127
282
|
/**
|
|
128
283
|
* Creates a rule entry for use in {@link ScheduleConfig.rules}.
|
|
129
284
|
*
|
|
130
|
-
* Built-in rules use the helpers (`maxHoursPerDay`, `timeOff`, etc.).
|
|
131
|
-
*
|
|
132
|
-
*
|
|
285
|
+
* Built-in rules use the helpers (`maxHoursPerDay`, `timeOff`, etc.). Custom
|
|
286
|
+
* rules can use `defineRule` to create entries that plug into the same
|
|
287
|
+
* resolution and compilation pipeline.
|
|
133
288
|
*
|
|
134
|
-
* @
|
|
289
|
+
* @remarks
|
|
290
|
+
* The returned entry always preserves its rule name and fields. To validate custom
|
|
291
|
+
* rules at the point of creation, use {@link defineRuleFor} to bind `defineRule`
|
|
292
|
+
* to a specific registry.
|
|
293
|
+
*
|
|
294
|
+
* @param name - Rule name. Must match a key in the active rule registry.
|
|
135
295
|
* @param fields - Rule-specific configuration fields.
|
|
136
296
|
* @param resolve - Optional custom resolver. When omitted, the default
|
|
137
297
|
* resolution applies: `appliesTo` is mapped to `roleIds`/`skillIds`/`memberIds`,
|
|
138
298
|
* `dates` is renamed to `specificDates`, and all other fields pass through.
|
|
139
299
|
*/
|
|
140
|
-
export declare function defineRule(name:
|
|
141
|
-
name:
|
|
142
|
-
}): RuleEntry
|
|
300
|
+
export declare function defineRule<const Name extends string, const Fields extends object>(name: Name, fields: Fields, resolve?: (ctx: RuleResolveContext) => Record<string, unknown> & {
|
|
301
|
+
name: Name;
|
|
302
|
+
}): RuleEntry<Name, SanitizedRuleFields<Fields>>;
|
|
303
|
+
/**
|
|
304
|
+
* Creates a registry-bound `defineRule` helper.
|
|
305
|
+
*
|
|
306
|
+
* @remarks
|
|
307
|
+
* Use this when authoring custom rules directly and you want immediate
|
|
308
|
+
* compile-time validation of the rule name and config fields against a specific
|
|
309
|
+
* rule registry.
|
|
310
|
+
*
|
|
311
|
+
* @category Rules
|
|
312
|
+
*/
|
|
313
|
+
export declare function defineRuleFor<TRuleRegistry extends CpsatRuleRegistry>(ruleRegistry: TRuleRegistry): <const Name extends keyof TRuleRegistry & string>(name: Name, fields: Omit<CpsatRuleConfigEntryFor<Pick<TRuleRegistry, Name>>, "name">, resolve?: (ctx: RuleResolveContext) => CpsatRuleConfigEntryFor<Pick<TRuleRegistry, Name>>) => RuleEntry<Name, SanitizedRuleFields<Omit<CpsatRuleConfigEntryFor<Pick<TRuleRegistry, Name>>, "name">>>;
|
|
143
314
|
/**
|
|
144
315
|
* Limits hours per day.
|
|
145
316
|
*
|
|
146
|
-
* @
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
* maxHoursPerDay(4, { appliesTo: "student", dayOfWeek: weekdays })
|
|
150
|
-
* ```
|
|
317
|
+
* @remarks
|
|
318
|
+
* Use this when the requirements or operating constraints explicitly impose a
|
|
319
|
+
* daily hours cap. Do not infer it just from the chosen shift pattern lengths.
|
|
151
320
|
*
|
|
152
321
|
* @category Rules
|
|
153
322
|
*/
|
|
154
|
-
export declare function maxHoursPerDay(hours: number, opts?: RuleOptions): RuleEntry
|
|
323
|
+
export declare function maxHoursPerDay(hours: number, opts?: RuleOptions): RuleEntry<"max-hours-day", {
|
|
324
|
+
hours: number;
|
|
325
|
+
} & RuleOptions>;
|
|
155
326
|
/**
|
|
156
327
|
* Limits hours per scheduling week.
|
|
157
328
|
*
|
|
158
|
-
* @
|
|
159
|
-
*
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
* ```
|
|
329
|
+
* @remarks
|
|
330
|
+
* Use this when the requirements or operating constraints explicitly impose a
|
|
331
|
+
* weekly hours cap. Do not infer it just from a stated working pattern such
|
|
332
|
+
* as "4-day week" unless the requirements also make the hour limit explicit.
|
|
163
333
|
*
|
|
164
334
|
* @category Rules
|
|
165
335
|
*/
|
|
166
|
-
export declare function maxHoursPerWeek(hours: number, opts?: RuleOptions): RuleEntry
|
|
336
|
+
export declare function maxHoursPerWeek(hours: number, opts?: RuleOptions): RuleEntry<"max-hours-week", {
|
|
337
|
+
hours: number;
|
|
338
|
+
} & RuleOptions>;
|
|
167
339
|
/**
|
|
168
340
|
* Minimum hours when assigned on a day.
|
|
169
341
|
*
|
|
170
|
-
* @example
|
|
171
|
-
* ```typescript
|
|
172
|
-
* minHoursPerDay(4)
|
|
173
|
-
* ```
|
|
174
|
-
*
|
|
175
342
|
* @category Rules
|
|
176
343
|
*/
|
|
177
|
-
export declare function minHoursPerDay(hours: number, opts?: EntityOnlyRuleOptions): RuleEntry
|
|
344
|
+
export declare function minHoursPerDay(hours: number, opts?: EntityOnlyRuleOptions): RuleEntry<"min-hours-day", {
|
|
345
|
+
hours: number;
|
|
346
|
+
} & EntityOnlyRuleOptions>;
|
|
178
347
|
/**
|
|
179
348
|
* Minimum hours per scheduling week.
|
|
180
349
|
*
|
|
181
|
-
* @
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
350
|
+
* @category Rules
|
|
351
|
+
*/
|
|
352
|
+
export declare function minHoursPerWeek(hours: number, opts?: EntityOnlyRuleOptions): RuleEntry<"min-hours-week", {
|
|
353
|
+
hours: number;
|
|
354
|
+
} & EntityOnlyRuleOptions>;
|
|
355
|
+
/**
|
|
356
|
+
* Caps assigned days per scheduling week.
|
|
357
|
+
*
|
|
358
|
+
* @remarks
|
|
359
|
+
* Use this when the requirements explicitly impose a weekly day cap. If the same
|
|
360
|
+
* number is the normal weekly pattern rather than just a hard limit, pair it
|
|
361
|
+
* with {@link targetDaysPerWeek}.
|
|
185
362
|
*
|
|
186
363
|
* @category Rules
|
|
187
364
|
*/
|
|
188
|
-
export declare function
|
|
365
|
+
export declare function maxDaysPerWeek(days: number, opts?: RuleOptions): RuleEntry<"max-days-week", {
|
|
366
|
+
days: number;
|
|
367
|
+
} & RuleOptions>;
|
|
189
368
|
/**
|
|
190
|
-
*
|
|
369
|
+
* Enforces a minimum number of assigned days per scheduling week.
|
|
191
370
|
*
|
|
192
|
-
* @
|
|
193
|
-
*
|
|
194
|
-
* maxDaysPerWeek
|
|
195
|
-
*
|
|
196
|
-
*
|
|
371
|
+
* @remarks
|
|
372
|
+
* Use this when the requirements explicitly require a weekly minimum. Language like
|
|
373
|
+
* "works a 4-day week" often implies a hard cap via {@link maxDaysPerWeek}
|
|
374
|
+
* and possibly a softer target via {@link targetDaysPerWeek}, not a mandatory
|
|
375
|
+
* weekly minimum for every member.
|
|
197
376
|
*
|
|
198
377
|
* @category Rules
|
|
199
378
|
*/
|
|
200
|
-
export declare function
|
|
379
|
+
export declare function minDaysPerWeek(days: number, opts?: EntityOnlyRuleOptions): RuleEntry<"min-days-week", {
|
|
380
|
+
days: number;
|
|
381
|
+
} & EntityOnlyRuleOptions>;
|
|
201
382
|
/**
|
|
202
|
-
*
|
|
383
|
+
* Softly targets assigned days per scheduling week.
|
|
203
384
|
*
|
|
204
|
-
* @
|
|
205
|
-
*
|
|
206
|
-
*
|
|
207
|
-
*
|
|
208
|
-
*
|
|
385
|
+
* @remarks
|
|
386
|
+
* Use this for stated working patterns like "works a 4-day week" when the
|
|
387
|
+
* pattern should remain the norm but can flex around holidays, time off, or
|
|
388
|
+
* other tradeoffs. Deviations in either direction are penalized, so working
|
|
389
|
+
* fewer days or more days than the target both count as misses. Pair it with
|
|
390
|
+
* {@link maxDaysPerWeek} when the same number is also a hard cap, and use
|
|
391
|
+
* {@link minDaysPerWeek} only when the requirements explicitly require a minimum.
|
|
392
|
+
*
|
|
393
|
+
* @param days - Target number of assigned days per scheduling week.
|
|
394
|
+
* @param opts - Optional entity scope and soft priority.
|
|
209
395
|
*
|
|
210
396
|
* @category Rules
|
|
211
397
|
*/
|
|
212
|
-
export declare function
|
|
398
|
+
export declare function targetDaysPerWeek(days: number, opts?: TargetDaysPerWeekOptions): RuleEntry<"target-days-week", {
|
|
399
|
+
days: number;
|
|
400
|
+
} & TargetDaysPerWeekOptions>;
|
|
213
401
|
/**
|
|
214
402
|
* Maximum distinct shifts per day.
|
|
215
403
|
*
|
|
216
|
-
* @
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
404
|
+
* @category Rules
|
|
405
|
+
*/
|
|
406
|
+
export declare function maxShiftsPerDay(shifts: number, opts?: RuleOptions): RuleEntry<"max-shifts-day", {
|
|
407
|
+
shifts: number;
|
|
408
|
+
} & RuleOptions>;
|
|
409
|
+
/**
|
|
410
|
+
* Caps how many targeted assignments may overlap at the same time.
|
|
411
|
+
*
|
|
412
|
+
* @remarks
|
|
413
|
+
* Use this for hard productive capacity limits that should stay separate from
|
|
414
|
+
* the minimum staffing requirement expressed by {@link cover}. Pair a
|
|
415
|
+
* lower-bound `cover(...)` with `maxConcurrentAssignments(...)` when the
|
|
416
|
+
* business needs both demand and capacity modeled explicitly.
|
|
417
|
+
*
|
|
418
|
+
* On days with staggered opening and closing shifts, keep lower-bound coverage
|
|
419
|
+
* scoped to the windows that truly need minimum staffing. Do not turn a total
|
|
420
|
+
* daily headcount target into a whole-day lower-bound `cover(...)` unless the
|
|
421
|
+
* business explicitly requires that many people in every overlapping bucket.
|
|
422
|
+
*
|
|
423
|
+
* Unlike {@link maxShiftsPerDay}, this limits simultaneous overlap, not total
|
|
424
|
+
* assignments on a day.
|
|
425
|
+
*
|
|
426
|
+
* @param assignments - Maximum number of concurrent overlapping assignments.
|
|
427
|
+
* @param opts - Optional scope and time-window settings.
|
|
221
428
|
*
|
|
222
429
|
* @category Rules
|
|
223
430
|
*/
|
|
224
|
-
export declare function
|
|
431
|
+
export declare function maxConcurrentAssignments(assignments: number, opts?: RuleOptions & {
|
|
432
|
+
startTime?: TimeOfDay;
|
|
433
|
+
endTime?: TimeOfDay;
|
|
434
|
+
}): RuleEntry<"max-concurrent-assignments", {
|
|
435
|
+
assignments: number;
|
|
436
|
+
} & MaxConcurrentAssignmentsOptions>;
|
|
225
437
|
/**
|
|
226
|
-
*
|
|
438
|
+
* Softly targets the daily peak number of concurrent overlapping assignments.
|
|
227
439
|
*
|
|
228
|
-
* @
|
|
229
|
-
*
|
|
230
|
-
*
|
|
231
|
-
*
|
|
440
|
+
* @remarks
|
|
441
|
+
* Use this when the business wants to hit full productive occupancy at the
|
|
442
|
+
* busy point of a day, but does not mean that same number must be present
|
|
443
|
+
* throughout the full span. This is not a whole-day lower bound. Pair it with
|
|
444
|
+
* {@link cover} for edge minima and with
|
|
445
|
+
* {@link maxConcurrentAssignments} when the same value is also a hard cap.
|
|
446
|
+
* Prefer this over a whole-day `cover(...)` when the brief means "reach the
|
|
447
|
+
* peak" rather than "maintain this minimum throughout the day".
|
|
448
|
+
*
|
|
449
|
+
* This is a rule-level peak target, not a variant of {@link cover}. Do not
|
|
450
|
+
* introduce a synthetic semantic time just to attach a whole-window
|
|
451
|
+
* `cover(...)` when the requirement is really about the day's peak.
|
|
452
|
+
*
|
|
453
|
+
* @param assignments - Target peak number of concurrent overlapping assignments.
|
|
454
|
+
* @param opts - Optional scope and soft priority.
|
|
232
455
|
*
|
|
233
456
|
* @category Rules
|
|
234
457
|
*/
|
|
235
|
-
export declare function
|
|
458
|
+
export declare function targetPeakConcurrentAssignments(assignments: number, opts?: TargetPeakConcurrentAssignmentsOptions): RuleEntry<"target-peak-concurrent-assignments", {
|
|
459
|
+
assignments: number;
|
|
460
|
+
} & TargetPeakConcurrentAssignmentsOptions>;
|
|
236
461
|
/**
|
|
237
|
-
*
|
|
462
|
+
* Maximum consecutive assigned days.
|
|
238
463
|
*
|
|
239
|
-
* @
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
464
|
+
* @category Rules
|
|
465
|
+
*/
|
|
466
|
+
export declare function maxConsecutiveDays(days: number, opts?: EntityOnlyRuleOptions): RuleEntry<"max-consecutive-days", {
|
|
467
|
+
days: number;
|
|
468
|
+
} & EntityOnlyRuleOptions>;
|
|
469
|
+
/**
|
|
470
|
+
* Once working, continue for at least this many consecutive days.
|
|
243
471
|
*
|
|
244
472
|
* @category Rules
|
|
245
473
|
*/
|
|
246
|
-
export declare function minConsecutiveDays(days: number, opts?: EntityOnlyRuleOptions): RuleEntry
|
|
474
|
+
export declare function minConsecutiveDays(days: number, opts?: EntityOnlyRuleOptions): RuleEntry<"min-consecutive-days", {
|
|
475
|
+
days: number;
|
|
476
|
+
} & EntityOnlyRuleOptions>;
|
|
247
477
|
/**
|
|
248
478
|
* Minimum rest hours between shifts.
|
|
249
479
|
*
|
|
250
|
-
* @
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
480
|
+
* @category Rules
|
|
481
|
+
*/
|
|
482
|
+
export declare function minRestBetweenShifts(hours: number, opts?: EntityOnlyRuleOptions): RuleEntry<"min-rest-between-shifts", {
|
|
483
|
+
hours: number;
|
|
484
|
+
} & EntityOnlyRuleOptions>;
|
|
485
|
+
/**
|
|
486
|
+
* Nudge the solver toward scheduling targeted members.
|
|
487
|
+
*
|
|
488
|
+
* @remarks
|
|
489
|
+
* Soft constraint. The solver adds a bonus for each assignment of the
|
|
490
|
+
* targeted members, making them more likely to appear on the schedule.
|
|
491
|
+
* Use `priority` to control how strong the nudge is; higher priority
|
|
492
|
+
* means a larger bonus. Even at `"MANDATORY"` strength the solver can
|
|
493
|
+
* still leave a member unassigned if hard constraints prevent it.
|
|
494
|
+
*
|
|
495
|
+
* Opposite of {@link avoidAssignment}. Both map to the same underlying
|
|
496
|
+
* `assignment-priority` rule with different directions.
|
|
497
|
+
*
|
|
498
|
+
* @param opts - See {@link RuleOptions}
|
|
254
499
|
*
|
|
255
500
|
* @category Rules
|
|
256
501
|
*/
|
|
257
|
-
export declare function
|
|
502
|
+
export declare function preferAssignment(opts?: RuleOptions): RuleEntry<"assignment-priority", {
|
|
503
|
+
preference: "prefer";
|
|
504
|
+
} & RuleOptions>;
|
|
258
505
|
/**
|
|
259
|
-
*
|
|
506
|
+
* Nudge the solver away from scheduling targeted members.
|
|
260
507
|
*
|
|
261
|
-
* @
|
|
262
|
-
*
|
|
263
|
-
*
|
|
264
|
-
*
|
|
265
|
-
*
|
|
508
|
+
* @remarks
|
|
509
|
+
* Soft constraint. The solver adds a penalty for each assignment of the
|
|
510
|
+
* targeted members, making them less likely to appear on the schedule.
|
|
511
|
+
* The member is still assigned when coverage requires it; the penalty
|
|
512
|
+
* only matters when the solver has a choice.
|
|
513
|
+
*
|
|
514
|
+
* Opposite of {@link preferAssignment}. Both map to the same underlying
|
|
515
|
+
* `assignment-priority` rule with different directions.
|
|
516
|
+
*
|
|
517
|
+
* @param opts - See {@link RuleOptions}
|
|
266
518
|
*
|
|
267
519
|
* @category Rules
|
|
268
520
|
*/
|
|
269
|
-
export declare function
|
|
521
|
+
export declare function avoidAssignment(opts?: RuleOptions): RuleEntry<"assignment-priority", {
|
|
522
|
+
preference: "avoid";
|
|
523
|
+
} & RuleOptions>;
|
|
270
524
|
/**
|
|
271
|
-
*
|
|
525
|
+
* Steer a multi-role member toward shifts tagged with a specific role.
|
|
272
526
|
*
|
|
273
|
-
* @
|
|
274
|
-
*
|
|
275
|
-
*
|
|
276
|
-
*
|
|
527
|
+
* @remarks
|
|
528
|
+
* Penalizes assignment to shift patterns whose `roleIds` do not include
|
|
529
|
+
* the preferred role. The member is still assigned to other roles when
|
|
530
|
+
* coverage requires it; the penalty only matters when the solver has a
|
|
531
|
+
* choice. Shift patterns without any `roleIds` (open to all) are also
|
|
532
|
+
* penalized since they are not explicitly tagged with the preferred role.
|
|
533
|
+
*
|
|
534
|
+
* The targeted members must actually hold the preferred role in their
|
|
535
|
+
* `roleIds`. If none of them do, compilation reports an error because
|
|
536
|
+
* the rule would silently penalize all their assignments (the opposite
|
|
537
|
+
* of the intent).
|
|
538
|
+
*
|
|
539
|
+
* Typical use case: a waiter who can cover kitchen pass shifts in a
|
|
540
|
+
* pinch. Give the member both roles (`roleIds: ["waiter", "pass"]`)
|
|
541
|
+
* and use `preferRole("waiter", ...)` so the solver keeps them on the
|
|
542
|
+
* floor unless the pass team is short-staffed.
|
|
543
|
+
*
|
|
544
|
+
* @param roleId - The role to prefer
|
|
545
|
+
* @param opts - See {@link EntityOnlyRuleOptions}
|
|
277
546
|
*
|
|
278
547
|
* @category Rules
|
|
279
548
|
*/
|
|
280
|
-
export declare function
|
|
549
|
+
export declare function preferRole(roleId: string, opts?: EntityOnlyRuleOptions): RuleEntry<"role-preference", {
|
|
550
|
+
roleId: string;
|
|
551
|
+
} & EntityOnlyRuleOptions>;
|
|
552
|
+
/**
|
|
553
|
+
* Steer a member toward shifts at a specific location.
|
|
554
|
+
*
|
|
555
|
+
* @remarks
|
|
556
|
+
* Penalizes assignment to shift patterns whose `locationId` does not
|
|
557
|
+
* match the preferred location. The member is still assigned elsewhere
|
|
558
|
+
* when coverage requires it.
|
|
559
|
+
*
|
|
560
|
+
* @param locationId - The location to prefer
|
|
561
|
+
* @param opts - See {@link EntityOnlyRuleOptions}
|
|
562
|
+
*
|
|
563
|
+
* @category Rules
|
|
564
|
+
*/
|
|
565
|
+
export declare function preferLocation(locationId: string, opts?: EntityOnlyRuleOptions): RuleEntry<"location-preference", {
|
|
566
|
+
locationId: string;
|
|
567
|
+
} & EntityOnlyRuleOptions>;
|
|
281
568
|
/**
|
|
282
569
|
* Guarantees that targeted members appear on the schedule each week.
|
|
283
570
|
*
|
|
@@ -292,48 +579,86 @@ export declare function preferLocation(locationId: string, opts?: EntityOnlyRule
|
|
|
292
579
|
* messaging from {@link minDaysPerWeek}. Priority is not configurable;
|
|
293
580
|
* the rule name communicates the intent.
|
|
294
581
|
*
|
|
295
|
-
* @example
|
|
296
|
-
* ```typescript
|
|
297
|
-
* mustAssign({ appliesTo: "diana" })
|
|
298
|
-
* mustAssign({ appliesTo: ["diana", "yavuz"] })
|
|
299
|
-
* ```
|
|
300
|
-
*
|
|
301
582
|
* @category Rules
|
|
302
583
|
*/
|
|
303
584
|
export declare function mustAssign(opts?: {
|
|
304
585
|
appliesTo?: string | string[];
|
|
305
|
-
}): RuleEntry
|
|
586
|
+
}): RuleEntry<"must-assign", {
|
|
587
|
+
appliesTo?: string | string[];
|
|
588
|
+
}>;
|
|
306
589
|
/**
|
|
307
590
|
* Block assignments during specified periods.
|
|
308
591
|
* Requires at least one time scope (`dayOfWeek`, `dateRange`, `dates`, or `from`/`until`).
|
|
309
592
|
*
|
|
310
|
-
* @
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
593
|
+
* @category Rules
|
|
594
|
+
*/
|
|
595
|
+
export declare function timeOff(opts: TimeOffOptions): TimeOffRuleEntry;
|
|
596
|
+
/**
|
|
597
|
+
* Members work the same shifts on days they are both assigned.
|
|
314
598
|
*
|
|
315
|
-
*
|
|
316
|
-
|
|
599
|
+
* @category Rules
|
|
600
|
+
*/
|
|
601
|
+
export declare function assignTogether(memberIds: [string, string, ...string[]], opts?: AssignTogetherOptions): AssignTogetherRuleEntry;
|
|
602
|
+
/**
|
|
603
|
+
* Options for {@link maxDaysOfWeekPerPeriod} and {@link minDaysOfWeekPerPeriod}.
|
|
317
604
|
*
|
|
318
|
-
*
|
|
319
|
-
*
|
|
320
|
-
*
|
|
605
|
+
* Exactly one of `weeks` or `months` must be provided to define the
|
|
606
|
+
* repeating period. Week periods align to `weekStartsOn`. Month periods
|
|
607
|
+
* align to calendar month boundaries.
|
|
321
608
|
*
|
|
322
609
|
* @category Rules
|
|
323
610
|
*/
|
|
324
|
-
export
|
|
611
|
+
export type DaysOfWeekPerPeriodOptions = {
|
|
612
|
+
/** Scope to role, skill, or member ID. */
|
|
613
|
+
appliesTo?: string | string[];
|
|
614
|
+
/** Default `MANDATORY`. */
|
|
615
|
+
priority?: Priority;
|
|
616
|
+
} & ({
|
|
617
|
+
weeks: number;
|
|
618
|
+
months?: never;
|
|
619
|
+
} | {
|
|
620
|
+
months: number;
|
|
621
|
+
weeks?: never;
|
|
622
|
+
});
|
|
325
623
|
/**
|
|
326
|
-
*
|
|
624
|
+
* Caps how many times a person works on specific days of the week within
|
|
625
|
+
* each period.
|
|
327
626
|
*
|
|
328
|
-
* @
|
|
329
|
-
*
|
|
330
|
-
*
|
|
331
|
-
*
|
|
332
|
-
*
|
|
627
|
+
* @remarks
|
|
628
|
+
* The scheduling window is divided into non-overlapping chunks of the
|
|
629
|
+
* configured period length. Within each chunk, only days matching the
|
|
630
|
+
* `dayOfWeek` filter are counted. The constraint bounds that count.
|
|
631
|
+
*
|
|
632
|
+
* @param days - Maximum number of matching days allowed per period.
|
|
633
|
+
* @param dayOfWeek - Which days of the week count toward the limit.
|
|
634
|
+
* @param opts - Period length and optional scoping.
|
|
635
|
+
*
|
|
636
|
+
* @category Rules
|
|
637
|
+
*/
|
|
638
|
+
export declare function maxDaysOfWeekPerPeriod(days: number, dayOfWeek: readonly [DayOfWeek, ...DayOfWeek[]], opts: DaysOfWeekPerPeriodOptions): MaxDaysOfWeekPerPeriodRuleEntry;
|
|
639
|
+
/**
|
|
640
|
+
* Enforces a minimum number of times a person works on specific days of the
|
|
641
|
+
* week within each period.
|
|
642
|
+
*
|
|
643
|
+
* @remarks
|
|
644
|
+
* The scheduling window is divided into non-overlapping chunks of the
|
|
645
|
+
* configured period length. Within each chunk, only days matching the
|
|
646
|
+
* `dayOfWeek` filter are counted. The constraint ensures the count meets
|
|
647
|
+
* the minimum.
|
|
648
|
+
*
|
|
649
|
+
* When the scheduling window does not align evenly with the period
|
|
650
|
+
* boundaries, the last chunk may contain fewer matching days than the
|
|
651
|
+
* minimum. A MANDATORY priority will make the model infeasible in that
|
|
652
|
+
* case. Use a soft priority (HIGH, MEDIUM, LOW) if partial periods at
|
|
653
|
+
* the edges of the window are expected.
|
|
654
|
+
*
|
|
655
|
+
* @param days - Minimum number of matching days required per period.
|
|
656
|
+
* @param dayOfWeek - Which days of the week count toward the limit.
|
|
657
|
+
* @param opts - Period length and optional scoping.
|
|
333
658
|
*
|
|
334
659
|
* @category Rules
|
|
335
660
|
*/
|
|
336
|
-
export declare function
|
|
661
|
+
export declare function minDaysOfWeekPerPeriod(days: number, dayOfWeek: readonly [DayOfWeek, ...DayOfWeek[]], opts: DaysOfWeekPerPeriodOptions): MinDaysOfWeekPerPeriodRuleEntry;
|
|
337
662
|
/**
|
|
338
663
|
* Resolves an `appliesTo` value into entity scope fields.
|
|
339
664
|
*
|