dabke 0.82.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 +44 -0
- package/README.md +22 -24
- 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 -21
- package/dist/cpsat/rules/index.d.ts.map +1 -1
- package/dist/cpsat/rules/index.js +30 -21
- 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 +30 -0
- package/dist/cpsat/rules/max-days-week.d.ts.map +1 -0
- package/dist/cpsat/rules/max-days-week.js +83 -0
- package/dist/cpsat/rules/max-days-week.js.map +1 -0
- 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 +21 -0
- package/dist/cpsat/rules/min-days-week.d.ts.map +1 -0
- package/dist/cpsat/rules/min-days-week.js +95 -0
- package/dist/cpsat/rules/min-days-week.js.map +1 -0
- 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 +12 -0
- package/dist/cpsat/rules/must-assign.d.ts.map +1 -0
- package/dist/cpsat/rules/must-assign.js +54 -0
- package/dist/cpsat/rules/must-assign.js.map +1 -0
- 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 -27
- package/dist/cpsat/rules/registry.d.ts.map +1 -1
- package/dist/cpsat/rules/registry.js +98 -31
- 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 +93 -17
- package/dist/cpsat/rules/rules.types.d.ts.map +1 -1
- package/dist/cpsat/rules/scope.types.d.ts +25 -12
- 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 +15 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -4
- package/dist/index.js.map +1 -1
- package/dist/schedule/cost.d.ts +192 -0
- package/dist/schedule/cost.d.ts.map +1 -0
- package/dist/schedule/cost.js +151 -0
- package/dist/schedule/cost.js.map +1 -0
- package/dist/schedule/coverage.d.ts +114 -0
- package/dist/schedule/coverage.d.ts.map +1 -0
- package/dist/schedule/coverage.js +56 -0
- package/dist/schedule/coverage.js.map +1 -0
- package/dist/schedule/definition.d.ts +346 -0
- package/dist/schedule/definition.d.ts.map +1 -0
- package/dist/schedule/definition.js +668 -0
- package/dist/schedule/definition.js.map +1 -0
- package/dist/schedule/index.d.ts +67 -0
- package/dist/schedule/index.d.ts.map +1 -0
- package/dist/schedule/index.js +69 -0
- package/dist/schedule/index.js.map +1 -0
- package/dist/schedule/rules.d.ts +678 -0
- package/dist/schedule/rules.d.ts.map +1 -0
- package/dist/schedule/rules.js +554 -0
- package/dist/schedule/rules.js.map +1 -0
- package/dist/schedule/shift-patterns.d.ts +17 -0
- package/dist/schedule/shift-patterns.d.ts.map +1 -0
- package/dist/schedule/shift-patterns.js +24 -0
- package/dist/schedule/shift-patterns.js.map +1 -0
- package/dist/schedule/time-periods.d.ts +79 -0
- package/dist/schedule/time-periods.d.ts.map +1 -0
- package/dist/schedule/time-periods.js +101 -0
- package/dist/schedule/time-periods.js.map +1 -0
- 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 -14
- 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 -21
- 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 +117 -0
- 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 +122 -0
- 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 +71 -0
- 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 -56
- package/src/cpsat/rules/resolver.ts +58 -30
- package/src/cpsat/rules/role-preference.ts +92 -0
- package/src/cpsat/rules/rules.types.ts +92 -17
- package/src/cpsat/rules/scope.types.ts +32 -27
- 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 +72 -15
- package/src/schedule/cost.ts +221 -0
- package/src/schedule/coverage.ts +164 -0
- package/src/schedule/definition.ts +1447 -0
- package/src/schedule/index.ts +132 -0
- package/src/schedule/rules.ts +1028 -0
- package/src/schedule/shift-patterns.ts +29 -0
- package/src/schedule/time-periods.ts +120 -0
- package/src/types.ts +114 -2
- package/dist/llms.d.ts +0 -2
- package/dist/llms.d.ts.map +0 -1
- package/dist/llms.js +0 -3
- package/dist/llms.js.map +0 -1
- package/dist/schedule.d.ts +0 -917
- package/dist/schedule.d.ts.map +0 -1
- package/dist/schedule.js +0 -1323
- package/dist/schedule.js.map +0 -1
- package/llms.txt +0 -758
- package/src/llms.ts +0 -3
- package/src/schedule.ts +0 -1960
|
@@ -0,0 +1,554 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scheduling rules: constraints, preferences, and time-off.
|
|
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
|
+
*
|
|
58
|
+
* @module
|
|
59
|
+
*/
|
|
60
|
+
export function defineRule(name, fields, resolve) {
|
|
61
|
+
const safeFields = { ...fields };
|
|
62
|
+
delete safeFields._type;
|
|
63
|
+
delete safeFields._rule;
|
|
64
|
+
const entry = {
|
|
65
|
+
_type: "rule",
|
|
66
|
+
_rule: name,
|
|
67
|
+
...safeFields,
|
|
68
|
+
};
|
|
69
|
+
if (resolve) {
|
|
70
|
+
Object.defineProperty(entry, "_resolve", { value: resolve, enumerable: false });
|
|
71
|
+
}
|
|
72
|
+
return entry;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Creates a registry-bound `defineRule` helper.
|
|
76
|
+
*
|
|
77
|
+
* @remarks
|
|
78
|
+
* Use this when authoring custom rules directly and you want immediate
|
|
79
|
+
* compile-time validation of the rule name and config fields against a specific
|
|
80
|
+
* rule registry.
|
|
81
|
+
*
|
|
82
|
+
* @category Rules
|
|
83
|
+
*/
|
|
84
|
+
export function defineRuleFor(ruleRegistry) {
|
|
85
|
+
void ruleRegistry;
|
|
86
|
+
return (name, fields, resolve) => defineRule(name, fields, resolve);
|
|
87
|
+
}
|
|
88
|
+
function makeRule(rule, fields) {
|
|
89
|
+
return defineRule(rule, fields);
|
|
90
|
+
}
|
|
91
|
+
// ============================================================================
|
|
92
|
+
// Constraint Rules
|
|
93
|
+
// ============================================================================
|
|
94
|
+
/**
|
|
95
|
+
* Limits hours per day.
|
|
96
|
+
*
|
|
97
|
+
* @remarks
|
|
98
|
+
* Use this when the requirements or operating constraints explicitly impose a
|
|
99
|
+
* daily hours cap. Do not infer it just from the chosen shift pattern lengths.
|
|
100
|
+
*
|
|
101
|
+
* @category Rules
|
|
102
|
+
*/
|
|
103
|
+
export function maxHoursPerDay(hours, opts) {
|
|
104
|
+
return makeRule("max-hours-day", { hours, ...opts });
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Limits hours per scheduling week.
|
|
108
|
+
*
|
|
109
|
+
* @remarks
|
|
110
|
+
* Use this when the requirements or operating constraints explicitly impose a
|
|
111
|
+
* weekly hours cap. Do not infer it just from a stated working pattern such
|
|
112
|
+
* as "4-day week" unless the requirements also make the hour limit explicit.
|
|
113
|
+
*
|
|
114
|
+
* @category Rules
|
|
115
|
+
*/
|
|
116
|
+
export function maxHoursPerWeek(hours, opts) {
|
|
117
|
+
return makeRule("max-hours-week", { hours, ...opts });
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Minimum hours when assigned on a day.
|
|
121
|
+
*
|
|
122
|
+
* @category Rules
|
|
123
|
+
*/
|
|
124
|
+
export function minHoursPerDay(hours, opts) {
|
|
125
|
+
return makeRule("min-hours-day", { hours, ...opts });
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Minimum hours per scheduling week.
|
|
129
|
+
*
|
|
130
|
+
* @category Rules
|
|
131
|
+
*/
|
|
132
|
+
export function minHoursPerWeek(hours, opts) {
|
|
133
|
+
return makeRule("min-hours-week", { hours, ...opts });
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Caps assigned days per scheduling week.
|
|
137
|
+
*
|
|
138
|
+
* @remarks
|
|
139
|
+
* Use this when the requirements explicitly impose a weekly day cap. If the same
|
|
140
|
+
* number is the normal weekly pattern rather than just a hard limit, pair it
|
|
141
|
+
* with {@link targetDaysPerWeek}.
|
|
142
|
+
*
|
|
143
|
+
* @category Rules
|
|
144
|
+
*/
|
|
145
|
+
export function maxDaysPerWeek(days, opts) {
|
|
146
|
+
return makeRule("max-days-week", { days, ...opts });
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Enforces a minimum number of assigned days per scheduling week.
|
|
150
|
+
*
|
|
151
|
+
* @remarks
|
|
152
|
+
* Use this when the requirements explicitly require a weekly minimum. Language like
|
|
153
|
+
* "works a 4-day week" often implies a hard cap via {@link maxDaysPerWeek}
|
|
154
|
+
* and possibly a softer target via {@link targetDaysPerWeek}, not a mandatory
|
|
155
|
+
* weekly minimum for every member.
|
|
156
|
+
*
|
|
157
|
+
* @category Rules
|
|
158
|
+
*/
|
|
159
|
+
export function minDaysPerWeek(days, opts) {
|
|
160
|
+
return makeRule("min-days-week", { days, ...opts });
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Softly targets assigned days per scheduling week.
|
|
164
|
+
*
|
|
165
|
+
* @remarks
|
|
166
|
+
* Use this for stated working patterns like "works a 4-day week" when the
|
|
167
|
+
* pattern should remain the norm but can flex around holidays, time off, or
|
|
168
|
+
* other tradeoffs. Deviations in either direction are penalized, so working
|
|
169
|
+
* fewer days or more days than the target both count as misses. Pair it with
|
|
170
|
+
* {@link maxDaysPerWeek} when the same number is also a hard cap, and use
|
|
171
|
+
* {@link minDaysPerWeek} only when the requirements explicitly require a minimum.
|
|
172
|
+
*
|
|
173
|
+
* @param days - Target number of assigned days per scheduling week.
|
|
174
|
+
* @param opts - Optional entity scope and soft priority.
|
|
175
|
+
*
|
|
176
|
+
* @category Rules
|
|
177
|
+
*/
|
|
178
|
+
export function targetDaysPerWeek(days, opts) {
|
|
179
|
+
return makeRule("target-days-week", { days, ...opts });
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Maximum distinct shifts per day.
|
|
183
|
+
*
|
|
184
|
+
* @category Rules
|
|
185
|
+
*/
|
|
186
|
+
export function maxShiftsPerDay(shifts, opts) {
|
|
187
|
+
return makeRule("max-shifts-day", { shifts, ...opts });
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Caps how many targeted assignments may overlap at the same time.
|
|
191
|
+
*
|
|
192
|
+
* @remarks
|
|
193
|
+
* Use this for hard productive capacity limits that should stay separate from
|
|
194
|
+
* the minimum staffing requirement expressed by {@link cover}. Pair a
|
|
195
|
+
* lower-bound `cover(...)` with `maxConcurrentAssignments(...)` when the
|
|
196
|
+
* business needs both demand and capacity modeled explicitly.
|
|
197
|
+
*
|
|
198
|
+
* On days with staggered opening and closing shifts, keep lower-bound coverage
|
|
199
|
+
* scoped to the windows that truly need minimum staffing. Do not turn a total
|
|
200
|
+
* daily headcount target into a whole-day lower-bound `cover(...)` unless the
|
|
201
|
+
* business explicitly requires that many people in every overlapping bucket.
|
|
202
|
+
*
|
|
203
|
+
* Unlike {@link maxShiftsPerDay}, this limits simultaneous overlap, not total
|
|
204
|
+
* assignments on a day.
|
|
205
|
+
*
|
|
206
|
+
* @param assignments - Maximum number of concurrent overlapping assignments.
|
|
207
|
+
* @param opts - Optional scope and time-window settings.
|
|
208
|
+
*
|
|
209
|
+
* @category Rules
|
|
210
|
+
*/
|
|
211
|
+
export function maxConcurrentAssignments(assignments, opts) {
|
|
212
|
+
return makeRule("max-concurrent-assignments", { assignments, ...opts });
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Softly targets the daily peak number of concurrent overlapping assignments.
|
|
216
|
+
*
|
|
217
|
+
* @remarks
|
|
218
|
+
* Use this when the business wants to hit full productive occupancy at the
|
|
219
|
+
* busy point of a day, but does not mean that same number must be present
|
|
220
|
+
* throughout the full span. This is not a whole-day lower bound. Pair it with
|
|
221
|
+
* {@link cover} for edge minima and with
|
|
222
|
+
* {@link maxConcurrentAssignments} when the same value is also a hard cap.
|
|
223
|
+
* Prefer this over a whole-day `cover(...)` when the brief means "reach the
|
|
224
|
+
* peak" rather than "maintain this minimum throughout the day".
|
|
225
|
+
*
|
|
226
|
+
* This is a rule-level peak target, not a variant of {@link cover}. Do not
|
|
227
|
+
* introduce a synthetic semantic time just to attach a whole-window
|
|
228
|
+
* `cover(...)` when the requirement is really about the day's peak.
|
|
229
|
+
*
|
|
230
|
+
* @param assignments - Target peak number of concurrent overlapping assignments.
|
|
231
|
+
* @param opts - Optional scope and soft priority.
|
|
232
|
+
*
|
|
233
|
+
* @category Rules
|
|
234
|
+
*/
|
|
235
|
+
export function targetPeakConcurrentAssignments(assignments, opts) {
|
|
236
|
+
return makeRule("target-peak-concurrent-assignments", { assignments, ...opts });
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Maximum consecutive assigned days.
|
|
240
|
+
*
|
|
241
|
+
* @category Rules
|
|
242
|
+
*/
|
|
243
|
+
export function maxConsecutiveDays(days, opts) {
|
|
244
|
+
return makeRule("max-consecutive-days", { days, ...opts });
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Once working, continue for at least this many consecutive days.
|
|
248
|
+
*
|
|
249
|
+
* @category Rules
|
|
250
|
+
*/
|
|
251
|
+
export function minConsecutiveDays(days, opts) {
|
|
252
|
+
return makeRule("min-consecutive-days", { days, ...opts });
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Minimum rest hours between shifts.
|
|
256
|
+
*
|
|
257
|
+
* @category Rules
|
|
258
|
+
*/
|
|
259
|
+
export function minRestBetweenShifts(hours, opts) {
|
|
260
|
+
return makeRule("min-rest-between-shifts", { hours, ...opts });
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Nudge the solver toward scheduling targeted members.
|
|
264
|
+
*
|
|
265
|
+
* @remarks
|
|
266
|
+
* Soft constraint. The solver adds a bonus for each assignment of the
|
|
267
|
+
* targeted members, making them more likely to appear on the schedule.
|
|
268
|
+
* Use `priority` to control how strong the nudge is; higher priority
|
|
269
|
+
* means a larger bonus. Even at `"MANDATORY"` strength the solver can
|
|
270
|
+
* still leave a member unassigned if hard constraints prevent it.
|
|
271
|
+
*
|
|
272
|
+
* Opposite of {@link avoidAssignment}. Both map to the same underlying
|
|
273
|
+
* `assignment-priority` rule with different directions.
|
|
274
|
+
*
|
|
275
|
+
* @param opts - See {@link RuleOptions}
|
|
276
|
+
*
|
|
277
|
+
* @category Rules
|
|
278
|
+
*/
|
|
279
|
+
export function preferAssignment(opts) {
|
|
280
|
+
return makeRule("assignment-priority", { preference: "prefer", ...opts });
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Nudge the solver away from scheduling targeted members.
|
|
284
|
+
*
|
|
285
|
+
* @remarks
|
|
286
|
+
* Soft constraint. The solver adds a penalty for each assignment of the
|
|
287
|
+
* targeted members, making them less likely to appear on the schedule.
|
|
288
|
+
* The member is still assigned when coverage requires it; the penalty
|
|
289
|
+
* only matters when the solver has a choice.
|
|
290
|
+
*
|
|
291
|
+
* Opposite of {@link preferAssignment}. Both map to the same underlying
|
|
292
|
+
* `assignment-priority` rule with different directions.
|
|
293
|
+
*
|
|
294
|
+
* @param opts - See {@link RuleOptions}
|
|
295
|
+
*
|
|
296
|
+
* @category Rules
|
|
297
|
+
*/
|
|
298
|
+
export function avoidAssignment(opts) {
|
|
299
|
+
return makeRule("assignment-priority", { preference: "avoid", ...opts });
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Steer a multi-role member toward shifts tagged with a specific role.
|
|
303
|
+
*
|
|
304
|
+
* @remarks
|
|
305
|
+
* Penalizes assignment to shift patterns whose `roleIds` do not include
|
|
306
|
+
* the preferred role. The member is still assigned to other roles when
|
|
307
|
+
* coverage requires it; the penalty only matters when the solver has a
|
|
308
|
+
* choice. Shift patterns without any `roleIds` (open to all) are also
|
|
309
|
+
* penalized since they are not explicitly tagged with the preferred role.
|
|
310
|
+
*
|
|
311
|
+
* The targeted members must actually hold the preferred role in their
|
|
312
|
+
* `roleIds`. If none of them do, compilation reports an error because
|
|
313
|
+
* the rule would silently penalize all their assignments (the opposite
|
|
314
|
+
* of the intent).
|
|
315
|
+
*
|
|
316
|
+
* Typical use case: a waiter who can cover kitchen pass shifts in a
|
|
317
|
+
* pinch. Give the member both roles (`roleIds: ["waiter", "pass"]`)
|
|
318
|
+
* and use `preferRole("waiter", ...)` so the solver keeps them on the
|
|
319
|
+
* floor unless the pass team is short-staffed.
|
|
320
|
+
*
|
|
321
|
+
* @param roleId - The role to prefer
|
|
322
|
+
* @param opts - See {@link EntityOnlyRuleOptions}
|
|
323
|
+
*
|
|
324
|
+
* @category Rules
|
|
325
|
+
*/
|
|
326
|
+
export function preferRole(roleId, opts) {
|
|
327
|
+
return makeRule("role-preference", { roleId, ...opts });
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Steer a member toward shifts at a specific location.
|
|
331
|
+
*
|
|
332
|
+
* @remarks
|
|
333
|
+
* Penalizes assignment to shift patterns whose `locationId` does not
|
|
334
|
+
* match the preferred location. The member is still assigned elsewhere
|
|
335
|
+
* when coverage requires it.
|
|
336
|
+
*
|
|
337
|
+
* @param locationId - The location to prefer
|
|
338
|
+
* @param opts - See {@link EntityOnlyRuleOptions}
|
|
339
|
+
*
|
|
340
|
+
* @category Rules
|
|
341
|
+
*/
|
|
342
|
+
export function preferLocation(locationId, opts) {
|
|
343
|
+
return makeRule("location-preference", { locationId, ...opts });
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Guarantees that targeted members appear on the schedule each week.
|
|
347
|
+
*
|
|
348
|
+
* @remarks
|
|
349
|
+
* Use for staffing obligations: salaried employees who are paid regardless
|
|
350
|
+
* of whether they work, or contracted staff who must be rostered. The solver
|
|
351
|
+
* ensures each targeted member has at least one assignment per scheduling week.
|
|
352
|
+
*
|
|
353
|
+
* Always a soft constraint (HIGH priority internally). The schedule still
|
|
354
|
+
* generates when a member genuinely cannot be placed (e.g., full week of
|
|
355
|
+
* absences). Violations surface as validation warnings with distinct
|
|
356
|
+
* messaging from {@link minDaysPerWeek}. Priority is not configurable;
|
|
357
|
+
* the rule name communicates the intent.
|
|
358
|
+
*
|
|
359
|
+
* @category Rules
|
|
360
|
+
*/
|
|
361
|
+
export function mustAssign(opts) {
|
|
362
|
+
return makeRule("must-assign", { ...opts });
|
|
363
|
+
}
|
|
364
|
+
// ============================================================================
|
|
365
|
+
// Special Rules (custom resolvers)
|
|
366
|
+
// ============================================================================
|
|
367
|
+
/**
|
|
368
|
+
* Block assignments during specified periods.
|
|
369
|
+
* Requires at least one time scope (`dayOfWeek`, `dateRange`, `dates`, or `from`/`until`).
|
|
370
|
+
*
|
|
371
|
+
* @category Rules
|
|
372
|
+
*/
|
|
373
|
+
export function timeOff(opts) {
|
|
374
|
+
const { from, until, ...rest } = opts;
|
|
375
|
+
return defineRule("time-off", { from, until, ...rest }, (ctx) => {
|
|
376
|
+
if (!rest.dayOfWeek && !rest.dateRange && !rest.dates && !rest.recurringPeriods) {
|
|
377
|
+
throw new Error("timeOff() requires at least one time scope (dayOfWeek, dateRange, dates, or recurringPeriods).");
|
|
378
|
+
}
|
|
379
|
+
const { appliesTo, dates, priority, ...passthrough } = rest;
|
|
380
|
+
const entityScope = resolveAppliesTo(appliesTo, ctx.roles, ctx.skills, ctx.memberIds);
|
|
381
|
+
const resolvedDates = dates ? { specificDates: dates } : {};
|
|
382
|
+
const partialDay = {};
|
|
383
|
+
if (from && until) {
|
|
384
|
+
partialDay.startTime = from;
|
|
385
|
+
partialDay.endTime = until;
|
|
386
|
+
}
|
|
387
|
+
else if (from) {
|
|
388
|
+
partialDay.startTime = from;
|
|
389
|
+
partialDay.endTime = { hours: 23, minutes: 59 };
|
|
390
|
+
}
|
|
391
|
+
else if (until) {
|
|
392
|
+
partialDay.startTime = { hours: 0, minutes: 0 };
|
|
393
|
+
partialDay.endTime = until;
|
|
394
|
+
}
|
|
395
|
+
const resolved = {
|
|
396
|
+
name: "time-off",
|
|
397
|
+
priority: priority ?? "MANDATORY",
|
|
398
|
+
...passthrough,
|
|
399
|
+
...entityScope,
|
|
400
|
+
...resolvedDates,
|
|
401
|
+
...partialDay,
|
|
402
|
+
};
|
|
403
|
+
return resolved;
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* Members work the same shifts on days they are both assigned.
|
|
408
|
+
*
|
|
409
|
+
* @category Rules
|
|
410
|
+
*/
|
|
411
|
+
export function assignTogether(memberIds, opts) {
|
|
412
|
+
return defineRule("assign-together", { members: memberIds, ...opts }, (ctx) => {
|
|
413
|
+
for (const member of memberIds) {
|
|
414
|
+
if (!ctx.memberIds.has(member)) {
|
|
415
|
+
throw new Error(`assignTogether references unknown member "${member}". ` +
|
|
416
|
+
`Known member IDs: ${[...ctx.memberIds].join(", ")}`);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
const resolved = {
|
|
420
|
+
name: "assign-together",
|
|
421
|
+
groupMemberIds: memberIds,
|
|
422
|
+
priority: opts?.priority ?? "MANDATORY",
|
|
423
|
+
};
|
|
424
|
+
return resolved;
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
/**
|
|
428
|
+
* Caps how many times a person works on specific days of the week within
|
|
429
|
+
* each period.
|
|
430
|
+
*
|
|
431
|
+
* @remarks
|
|
432
|
+
* The scheduling window is divided into non-overlapping chunks of the
|
|
433
|
+
* configured period length. Within each chunk, only days matching the
|
|
434
|
+
* `dayOfWeek` filter are counted. The constraint bounds that count.
|
|
435
|
+
*
|
|
436
|
+
* @param days - Maximum number of matching days allowed per period.
|
|
437
|
+
* @param dayOfWeek - Which days of the week count toward the limit.
|
|
438
|
+
* @param opts - Period length and optional scoping.
|
|
439
|
+
*
|
|
440
|
+
* @category Rules
|
|
441
|
+
*/
|
|
442
|
+
export function maxDaysOfWeekPerPeriod(days, dayOfWeek, opts) {
|
|
443
|
+
const { appliesTo, priority, ...periodOpts } = opts;
|
|
444
|
+
const period = "weeks" in periodOpts && periodOpts.weeks != null
|
|
445
|
+
? { type: "weeks", value: periodOpts.weeks }
|
|
446
|
+
: { type: "months", value: periodOpts.months };
|
|
447
|
+
return defineRule("max-days-of-week-per-period", { days, dayOfWeek: [...dayOfWeek], period, appliesTo, priority }, (ctx) => {
|
|
448
|
+
const entityScope = resolveAppliesTo(appliesTo, ctx.roles, ctx.skills, ctx.memberIds);
|
|
449
|
+
const resolved = {
|
|
450
|
+
name: "max-days-of-week-per-period",
|
|
451
|
+
days,
|
|
452
|
+
dayOfWeek: [...dayOfWeek],
|
|
453
|
+
period,
|
|
454
|
+
priority: priority ?? "MANDATORY",
|
|
455
|
+
...entityScope,
|
|
456
|
+
};
|
|
457
|
+
return resolved;
|
|
458
|
+
});
|
|
459
|
+
}
|
|
460
|
+
/**
|
|
461
|
+
* Enforces a minimum number of times a person works on specific days of the
|
|
462
|
+
* week within each period.
|
|
463
|
+
*
|
|
464
|
+
* @remarks
|
|
465
|
+
* The scheduling window is divided into non-overlapping chunks of the
|
|
466
|
+
* configured period length. Within each chunk, only days matching the
|
|
467
|
+
* `dayOfWeek` filter are counted. The constraint ensures the count meets
|
|
468
|
+
* the minimum.
|
|
469
|
+
*
|
|
470
|
+
* When the scheduling window does not align evenly with the period
|
|
471
|
+
* boundaries, the last chunk may contain fewer matching days than the
|
|
472
|
+
* minimum. A MANDATORY priority will make the model infeasible in that
|
|
473
|
+
* case. Use a soft priority (HIGH, MEDIUM, LOW) if partial periods at
|
|
474
|
+
* the edges of the window are expected.
|
|
475
|
+
*
|
|
476
|
+
* @param days - Minimum number of matching days required per period.
|
|
477
|
+
* @param dayOfWeek - Which days of the week count toward the limit.
|
|
478
|
+
* @param opts - Period length and optional scoping.
|
|
479
|
+
*
|
|
480
|
+
* @category Rules
|
|
481
|
+
*/
|
|
482
|
+
export function minDaysOfWeekPerPeriod(days, dayOfWeek, opts) {
|
|
483
|
+
const { appliesTo, priority, ...periodOpts } = opts;
|
|
484
|
+
const period = "weeks" in periodOpts && periodOpts.weeks != null
|
|
485
|
+
? { type: "weeks", value: periodOpts.weeks }
|
|
486
|
+
: { type: "months", value: periodOpts.months };
|
|
487
|
+
return defineRule("min-days-of-week-per-period", { days, dayOfWeek: [...dayOfWeek], period, appliesTo, priority }, (ctx) => {
|
|
488
|
+
const entityScope = resolveAppliesTo(appliesTo, ctx.roles, ctx.skills, ctx.memberIds);
|
|
489
|
+
const resolved = {
|
|
490
|
+
name: "min-days-of-week-per-period",
|
|
491
|
+
days,
|
|
492
|
+
dayOfWeek: [...dayOfWeek],
|
|
493
|
+
period,
|
|
494
|
+
priority: priority ?? "MANDATORY",
|
|
495
|
+
...entityScope,
|
|
496
|
+
};
|
|
497
|
+
return resolved;
|
|
498
|
+
});
|
|
499
|
+
}
|
|
500
|
+
// ============================================================================
|
|
501
|
+
// Internal: appliesTo resolution (shared with definition.ts)
|
|
502
|
+
// ============================================================================
|
|
503
|
+
/**
|
|
504
|
+
* Resolves an `appliesTo` value into entity scope fields.
|
|
505
|
+
*
|
|
506
|
+
* Each target string is checked against roles, skills, then member IDs.
|
|
507
|
+
* If all targets resolve to the same namespace, they are combined into one
|
|
508
|
+
* scope field. If they span namespaces, an error is thrown; the caller
|
|
509
|
+
* should use separate rule entries instead.
|
|
510
|
+
*
|
|
511
|
+
* @internal
|
|
512
|
+
*/
|
|
513
|
+
export function resolveAppliesTo(appliesTo, roles, skills, memberIds) {
|
|
514
|
+
if (!appliesTo)
|
|
515
|
+
return {};
|
|
516
|
+
const targets = Array.isArray(appliesTo) ? appliesTo : [appliesTo];
|
|
517
|
+
if (targets.length === 0)
|
|
518
|
+
return {};
|
|
519
|
+
const resolvedRoles = [];
|
|
520
|
+
const resolvedSkills = [];
|
|
521
|
+
const resolvedMembers = [];
|
|
522
|
+
for (const target of targets) {
|
|
523
|
+
if (roles.has(target)) {
|
|
524
|
+
resolvedRoles.push(target);
|
|
525
|
+
}
|
|
526
|
+
else if (skills.has(target)) {
|
|
527
|
+
resolvedSkills.push(target);
|
|
528
|
+
}
|
|
529
|
+
else if (memberIds.has(target)) {
|
|
530
|
+
resolvedMembers.push(target);
|
|
531
|
+
}
|
|
532
|
+
else {
|
|
533
|
+
throw new Error(`appliesTo target "${target}" is not a declared role, skill, or member ID.`);
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
// Count how many namespaces were used
|
|
537
|
+
const namespacesUsed = [resolvedRoles, resolvedSkills, resolvedMembers].filter((arr) => arr.length > 0).length;
|
|
538
|
+
if (namespacesUsed > 1) {
|
|
539
|
+
throw new Error(`appliesTo targets span multiple namespaces (roles: [${resolvedRoles.join(", ")}], ` +
|
|
540
|
+
`skills: [${resolvedSkills.join(", ")}], members: [${resolvedMembers.join(", ")}]). ` +
|
|
541
|
+
`Use separate rule entries for each namespace.`);
|
|
542
|
+
}
|
|
543
|
+
if (resolvedRoles.length > 0) {
|
|
544
|
+
return { roleIds: resolvedRoles };
|
|
545
|
+
}
|
|
546
|
+
if (resolvedSkills.length > 0) {
|
|
547
|
+
return { skillIds: resolvedSkills };
|
|
548
|
+
}
|
|
549
|
+
if (resolvedMembers.length > 0) {
|
|
550
|
+
return { memberIds: resolvedMembers };
|
|
551
|
+
}
|
|
552
|
+
return {};
|
|
553
|
+
}
|
|
554
|
+
//# sourceMappingURL=rules.js.map
|
|
@@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AAO,EAAE,aAAsC,EAAE,CAAC;IAC7D,CAAC;IACD,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC9B,OAAO,EAAE,QAAQ,EAAE,cAAuC,EAAE,CAAC;IAC/D,CAAC;IACD,IAAI,eAAe,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC/B,OAAO,EAAE,SAAS,EAAE,eAAwC,EAAE,CAAC;IACjE,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shift pattern definitions: time slots available for employee assignment.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import type { TimeOfDay } from "../types.js";
|
|
7
|
+
import type { ShiftPattern } from "../cpsat/types.js";
|
|
8
|
+
/**
|
|
9
|
+
* Define a shift pattern: a time slot available for employee assignment.
|
|
10
|
+
*
|
|
11
|
+
* @remarks
|
|
12
|
+
* Each pattern repeats daily unless filtered by `dayOfWeek`.
|
|
13
|
+
*
|
|
14
|
+
* @category Shift Patterns
|
|
15
|
+
*/
|
|
16
|
+
export declare function shift(id: string, startTime: TimeOfDay, endTime: TimeOfDay, opts?: Pick<ShiftPattern, "roleIds" | "dayOfWeek" | "locationId">): ShiftPattern;
|
|
17
|
+
//# sourceMappingURL=shift-patterns.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shift-patterns.d.ts","sourceRoot":"","sources":["../../src/schedule/shift-patterns.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEtD;;;;;;;GAOG;AACH,wBAAgB,KAAK,CACnB,EAAE,EAAE,MAAM,EACV,SAAS,EAAE,SAAS,EACpB,OAAO,EAAE,SAAS,EAClB,IAAI,CAAC,EAAE,IAAI,CAAC,YAAY,EAAE,SAAS,GAAG,WAAW,GAAG,YAAY,CAAC,GAChE,YAAY,CAMd"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shift pattern definitions: time slots available for employee assignment.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Define a shift pattern: a time slot available for employee assignment.
|
|
8
|
+
*
|
|
9
|
+
* @remarks
|
|
10
|
+
* Each pattern repeats daily unless filtered by `dayOfWeek`.
|
|
11
|
+
*
|
|
12
|
+
* @category Shift Patterns
|
|
13
|
+
*/
|
|
14
|
+
export function shift(id, startTime, endTime, opts) {
|
|
15
|
+
const pattern = { id, startTime, endTime };
|
|
16
|
+
if (opts?.roleIds)
|
|
17
|
+
pattern.roleIds = opts.roleIds;
|
|
18
|
+
if (opts?.dayOfWeek)
|
|
19
|
+
pattern.dayOfWeek = opts.dayOfWeek;
|
|
20
|
+
if (opts?.locationId)
|
|
21
|
+
pattern.locationId = opts.locationId;
|
|
22
|
+
return pattern;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=shift-patterns.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shift-patterns.js","sourceRoot":"","sources":["../../src/schedule/shift-patterns.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH;;;;;;;GAOG;AACH,MAAM,UAAU,KAAK,CACnB,EAAU,EACV,SAAoB,EACpB,OAAkB,EAClB,IAAiE;IAEjE,MAAM,OAAO,GAAiB,EAAE,EAAE,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC;IACzD,IAAI,IAAI,EAAE,OAAO;QAAE,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;IAClD,IAAI,IAAI,EAAE,SAAS;QAAE,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC;IACxD,IAAI,IAAI,EAAE,UAAU;QAAE,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC;IAC3D,OAAO,OAAO,CAAC;AACjB,CAAC"}
|