assignment-user-matcher 1.8.0 → 1.10.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.
Files changed (165) hide show
  1. package/README.md +240 -12
  2. package/dist/index.d.ts +3 -1
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +23 -1
  5. package/dist/matcher.class.d.ts +44 -2
  6. package/dist/matcher.class.d.ts.map +1 -1
  7. package/dist/matcher.class.js +393 -4
  8. package/dist/queries/pagination.d.ts +5 -1
  9. package/dist/queries/pagination.d.ts.map +1 -1
  10. package/dist/queries/pagination.js +14 -3
  11. package/dist/schedule/policy.d.ts +35 -0
  12. package/dist/schedule/policy.d.ts.map +1 -0
  13. package/dist/schedule/policy.js +62 -0
  14. package/dist/scheduling/constraints/availability.d.ts +44 -0
  15. package/dist/scheduling/constraints/availability.d.ts.map +1 -0
  16. package/dist/scheduling/constraints/availability.js +142 -0
  17. package/dist/scheduling/constraints/consecutive.d.ts +25 -0
  18. package/dist/scheduling/constraints/consecutive.d.ts.map +1 -0
  19. package/dist/scheduling/constraints/consecutive.js +215 -0
  20. package/dist/scheduling/constraints/constraint.d.ts +35 -0
  21. package/dist/scheduling/constraints/constraint.d.ts.map +1 -0
  22. package/dist/scheduling/constraints/constraint.js +97 -0
  23. package/dist/scheduling/constraints/contract.d.ts +21 -0
  24. package/dist/scheduling/constraints/contract.d.ts.map +1 -0
  25. package/dist/scheduling/constraints/contract.js +106 -0
  26. package/dist/scheduling/constraints/cost.d.ts +18 -0
  27. package/dist/scheduling/constraints/cost.d.ts.map +1 -0
  28. package/dist/scheduling/constraints/cost.js +65 -0
  29. package/dist/scheduling/constraints/daily-rest.d.ts +22 -0
  30. package/dist/scheduling/constraints/daily-rest.d.ts.map +1 -0
  31. package/dist/scheduling/constraints/daily-rest.js +118 -0
  32. package/dist/scheduling/constraints/duty-quota.d.ts +20 -0
  33. package/dist/scheduling/constraints/duty-quota.d.ts.map +1 -0
  34. package/dist/scheduling/constraints/duty-quota.js +95 -0
  35. package/dist/scheduling/constraints/engagement-floor.d.ts +28 -0
  36. package/dist/scheduling/constraints/engagement-floor.d.ts.map +1 -0
  37. package/dist/scheduling/constraints/engagement-floor.js +79 -0
  38. package/dist/scheduling/constraints/fairness.d.ts +34 -0
  39. package/dist/scheduling/constraints/fairness.d.ts.map +1 -0
  40. package/dist/scheduling/constraints/fairness.js +149 -0
  41. package/dist/scheduling/constraints/group-composition.d.ts +19 -0
  42. package/dist/scheduling/constraints/group-composition.d.ts.map +1 -0
  43. package/dist/scheduling/constraints/group-composition.js +92 -0
  44. package/dist/scheduling/constraints/hour-budget.d.ts +13 -0
  45. package/dist/scheduling/constraints/hour-budget.d.ts.map +1 -0
  46. package/dist/scheduling/constraints/hour-budget.js +59 -0
  47. package/dist/scheduling/constraints/in-shift-breaks.d.ts +24 -0
  48. package/dist/scheduling/constraints/in-shift-breaks.d.ts.map +1 -0
  49. package/dist/scheduling/constraints/in-shift-breaks.js +97 -0
  50. package/dist/scheduling/constraints/intervals.d.ts +5 -0
  51. package/dist/scheduling/constraints/intervals.d.ts.map +1 -0
  52. package/dist/scheduling/constraints/intervals.js +17 -0
  53. package/dist/scheduling/constraints/max-shift-duration.d.ts +7 -0
  54. package/dist/scheduling/constraints/max-shift-duration.d.ts.map +1 -0
  55. package/dist/scheduling/constraints/max-shift-duration.js +38 -0
  56. package/dist/scheduling/constraints/min-rest.d.ts +22 -0
  57. package/dist/scheduling/constraints/min-rest.d.ts.map +1 -0
  58. package/dist/scheduling/constraints/min-rest.js +60 -0
  59. package/dist/scheduling/constraints/min-staffing.d.ts +14 -0
  60. package/dist/scheduling/constraints/min-staffing.d.ts.map +1 -0
  61. package/dist/scheduling/constraints/min-staffing.js +59 -0
  62. package/dist/scheduling/constraints/night-work.d.ts +24 -0
  63. package/dist/scheduling/constraints/night-work.d.ts.map +1 -0
  64. package/dist/scheduling/constraints/night-work.js +163 -0
  65. package/dist/scheduling/constraints/no-overlap.d.ts +7 -0
  66. package/dist/scheduling/constraints/no-overlap.d.ts.map +1 -0
  67. package/dist/scheduling/constraints/no-overlap.js +36 -0
  68. package/dist/scheduling/constraints/notice.d.ts +44 -0
  69. package/dist/scheduling/constraints/notice.d.ts.map +1 -0
  70. package/dist/scheduling/constraints/notice.js +140 -0
  71. package/dist/scheduling/constraints/one-shift-per-day.d.ts +7 -0
  72. package/dist/scheduling/constraints/one-shift-per-day.d.ts.map +1 -0
  73. package/dist/scheduling/constraints/one-shift-per-day.js +35 -0
  74. package/dist/scheduling/constraints/overtime.d.ts +47 -0
  75. package/dist/scheduling/constraints/overtime.d.ts.map +1 -0
  76. package/dist/scheduling/constraints/overtime.js +149 -0
  77. package/dist/scheduling/constraints/protections.d.ts +21 -0
  78. package/dist/scheduling/constraints/protections.d.ts.map +1 -0
  79. package/dist/scheduling/constraints/protections.js +93 -0
  80. package/dist/scheduling/constraints/qualification.d.ts +18 -0
  81. package/dist/scheduling/constraints/qualification.d.ts.map +1 -0
  82. package/dist/scheduling/constraints/qualification.js +78 -0
  83. package/dist/scheduling/constraints/rest-days.d.ts +30 -0
  84. package/dist/scheduling/constraints/rest-days.d.ts.map +1 -0
  85. package/dist/scheduling/constraints/rest-days.js +133 -0
  86. package/dist/scheduling/constraints/rolling-hours.d.ts +24 -0
  87. package/dist/scheduling/constraints/rolling-hours.d.ts.map +1 -0
  88. package/dist/scheduling/constraints/rolling-hours.js +147 -0
  89. package/dist/scheduling/constraints/start-interval.d.ts +20 -0
  90. package/dist/scheduling/constraints/start-interval.d.ts.map +1 -0
  91. package/dist/scheduling/constraints/start-interval.js +53 -0
  92. package/dist/scheduling/constraints/support.d.ts +48 -0
  93. package/dist/scheduling/constraints/support.d.ts.map +1 -0
  94. package/dist/scheduling/constraints/support.js +97 -0
  95. package/dist/scheduling/constraints/time-off.d.ts +7 -0
  96. package/dist/scheduling/constraints/time-off.d.ts.map +1 -0
  97. package/dist/scheduling/constraints/time-off.js +42 -0
  98. package/dist/scheduling/constraints/weekly-rest.d.ts +22 -0
  99. package/dist/scheduling/constraints/weekly-rest.d.ts.map +1 -0
  100. package/dist/scheduling/constraints/weekly-rest.js +92 -0
  101. package/dist/scheduling/cost.d.ts +56 -0
  102. package/dist/scheduling/cost.d.ts.map +1 -0
  103. package/dist/scheduling/cost.js +120 -0
  104. package/dist/scheduling/engine/construction.d.ts +22 -0
  105. package/dist/scheduling/engine/construction.d.ts.map +1 -0
  106. package/dist/scheduling/engine/construction.js +97 -0
  107. package/dist/scheduling/engine/explain.d.ts +12 -0
  108. package/dist/scheduling/engine/explain.d.ts.map +1 -0
  109. package/dist/scheduling/engine/explain.js +24 -0
  110. package/dist/scheduling/engine/objective.d.ts +73 -0
  111. package/dist/scheduling/engine/objective.d.ts.map +1 -0
  112. package/dist/scheduling/engine/objective.js +164 -0
  113. package/dist/scheduling/engine/prng.d.ts +5 -0
  114. package/dist/scheduling/engine/prng.d.ts.map +1 -0
  115. package/dist/scheduling/engine/prng.js +24 -0
  116. package/dist/scheduling/engine/propagation.d.ts +19 -0
  117. package/dist/scheduling/engine/propagation.d.ts.map +1 -0
  118. package/dist/scheduling/engine/propagation.js +40 -0
  119. package/dist/scheduling/engine/search.d.ts +50 -0
  120. package/dist/scheduling/engine/search.d.ts.map +1 -0
  121. package/dist/scheduling/engine/search.js +127 -0
  122. package/dist/scheduling/engine/state.d.ts +28 -0
  123. package/dist/scheduling/engine/state.d.ts.map +1 -0
  124. package/dist/scheduling/engine/state.js +96 -0
  125. package/dist/scheduling/engine/timeline.d.ts +179 -0
  126. package/dist/scheduling/engine/timeline.d.ts.map +1 -0
  127. package/dist/scheduling/engine/timeline.js +416 -0
  128. package/dist/scheduling/engine/verdicts.d.ts +18 -0
  129. package/dist/scheduling/engine/verdicts.d.ts.map +1 -0
  130. package/dist/scheduling/engine/verdicts.js +74 -0
  131. package/dist/scheduling/index.d.ts +10 -0
  132. package/dist/scheduling/index.d.ts.map +1 -0
  133. package/dist/scheduling/index.js +29 -0
  134. package/dist/scheduling/model.d.ts +53 -0
  135. package/dist/scheduling/model.d.ts.map +1 -0
  136. package/dist/scheduling/model.js +379 -0
  137. package/dist/scheduling/operations.d.ts +134 -0
  138. package/dist/scheduling/operations.d.ts.map +1 -0
  139. package/dist/scheduling/operations.js +376 -0
  140. package/dist/scheduling/provenance.d.ts +33 -0
  141. package/dist/scheduling/provenance.d.ts.map +1 -0
  142. package/dist/scheduling/provenance.js +70 -0
  143. package/dist/scheduling/rules.d.ts +23 -0
  144. package/dist/scheduling/rules.d.ts.map +1 -0
  145. package/dist/scheduling/rules.js +37 -0
  146. package/dist/scheduling/scheduler.class.d.ts +24 -0
  147. package/dist/scheduling/scheduler.class.d.ts.map +1 -0
  148. package/dist/scheduling/scheduler.class.js +150 -0
  149. package/dist/scheduling/time.d.ts +132 -0
  150. package/dist/scheduling/time.d.ts.map +1 -0
  151. package/dist/scheduling/time.js +256 -0
  152. package/dist/scheduling/types.d.ts +932 -0
  153. package/dist/scheduling/types.d.ts.map +1 -0
  154. package/dist/scheduling/types.js +19 -0
  155. package/dist/scoring/match-score.d.ts.map +1 -1
  156. package/dist/scoring/match-score.js +1 -3
  157. package/dist/types/matcher.d.ts +195 -1
  158. package/dist/types/matcher.d.ts.map +1 -1
  159. package/dist/utils/keys.d.ts +3 -0
  160. package/dist/utils/keys.d.ts.map +1 -1
  161. package/dist/utils/keys.js +15 -0
  162. package/dist/validation/assignment-lint.d.ts +24 -0
  163. package/dist/validation/assignment-lint.d.ts.map +1 -0
  164. package/dist/validation/assignment-lint.js +132 -0
  165. package/package.json +4 -2
@@ -0,0 +1,149 @@
1
+ "use strict";
2
+ /**
3
+ * Fairness — equalising load across the team.
4
+ *
5
+ * Three deliberate choices:
6
+ *
7
+ * 1. **Per dimension, separately.** Equal total hours says nothing about who
8
+ * takes the nights. Two people can work identical hours while one does every
9
+ * weekend, so hours, nights, weekends and holidays are balanced as separate
10
+ * dimensions rather than rolled into one number.
11
+ *
12
+ * 2. **L1 deviation, not variance.** Variance is quadratic and non-decomposable:
13
+ * changing one person's load changes every other person's contribution
14
+ * through the mean, so it cannot be evaluated incrementally. Summed absolute
15
+ * deviation from the fair share gives the same ordering pressure and stays
16
+ * local.
17
+ *
18
+ * 3. **Realised counts only.** The fair share is computed from what people have
19
+ * actually been assigned, plus `carriedFairness` from previous periods. No
20
+ * behavioural or predictive signal enters — that boundary is what keeps this
21
+ * a constraint solver rather than profiling under AI Act Annex III 4(b).
22
+ *
23
+ * Pro-rata weighting matters legally as well as morally: the part-time,
24
+ * fixed-term and agency directives all require equal treatment on a pro rata
25
+ * temporis basis, so a half-time worker's fair share is half.
26
+ */
27
+ Object.defineProperty(exports, "__esModule", { value: true });
28
+ exports.fairnessPenalty = exports.fairness = exports.FAIRNESS_CITATION = void 0;
29
+ exports.FAIRNESS_CITATION = 'Directive 97/81/EC cl. 4 (pro rata temporis)';
30
+ function fairness(rules) {
31
+ return {
32
+ id: 'fairness',
33
+ hardness: 'soft',
34
+ weight: 1,
35
+ citation: exports.FAIRNESS_CITATION,
36
+ // Fairness is a property of the whole roster; no single assignment
37
+ // breaches it, so the pair-scoped hooks stay silent by construction.
38
+ delta: () => 0,
39
+ explain: () => null,
40
+ evaluate(state) {
41
+ const out = [];
42
+ for (const rule of rules) {
43
+ const loads = loadsFor(state, rule);
44
+ if (loads.size === 0)
45
+ continue;
46
+ const values = [...loads.values()];
47
+ const spread = Math.max(...values) - Math.min(...values);
48
+ if (rule.hardMaxSpread === undefined || spread <= rule.hardMaxSpread)
49
+ continue;
50
+ const highest = [...loads.entries()].sort((a, b) => b[1] - a[1])[0];
51
+ out.push({
52
+ constraintId: 'fairness',
53
+ severity: 'medium',
54
+ employeeId: highest[0],
55
+ message: `${label(rule)} spread across the team is ${round(spread)}, over the ${rule.hardMaxSpread} maximum (highest: "${highest[0]}" at ${round(highest[1])})`,
56
+ actual: spread,
57
+ required: rule.hardMaxSpread,
58
+ unit: 'count',
59
+ citation: exports.FAIRNESS_CITATION,
60
+ });
61
+ }
62
+ return out;
63
+ },
64
+ };
65
+ }
66
+ exports.fairness = fairness;
67
+ /**
68
+ * Summed absolute deviation from the fair share, across every dimension.
69
+ * Lower is fairer. The objective adds this, weighted, at the soft level.
70
+ */
71
+ function fairnessPenalty(state, rules) {
72
+ if (!rules?.length)
73
+ return 0;
74
+ let penalty = 0;
75
+ for (const rule of rules) {
76
+ const loads = loadsFor(state, rule);
77
+ if (loads.size === 0)
78
+ continue;
79
+ const shares = shareWeights(state, rule, [...loads.keys()]);
80
+ const total = [...loads.values()].reduce((a, b) => a + b, 0);
81
+ const totalShare = [...shares.values()].reduce((a, b) => a + b, 0) || 1;
82
+ for (const [employeeId, load] of loads) {
83
+ const fair = (total * (shares.get(employeeId) ?? 1)) / totalShare;
84
+ penalty += Math.abs(load - fair) * (rule.weight ?? 1);
85
+ }
86
+ }
87
+ return penalty;
88
+ }
89
+ exports.fairnessPenalty = fairnessPenalty;
90
+ /** Per-employee load on one dimension, including counts carried in from prior periods. */
91
+ function loadsFor(state, rule) {
92
+ const key = rule.dimension === 'tag' ? `tag:${rule.tag}` : rule.dimension;
93
+ const loads = new Map();
94
+ for (const employee of state.ctx.employees) {
95
+ let load = employee.carriedFairness?.[key] ?? 0;
96
+ for (const instanceId of state.byEmployee.get(employee.id) ?? []) {
97
+ const inst = state.ctx.instanceById.get(instanceId);
98
+ if (inst)
99
+ load += contribution(rule, inst);
100
+ }
101
+ loads.set(employee.id, load);
102
+ }
103
+ return loads;
104
+ }
105
+ function contribution(rule, inst) {
106
+ switch (rule.dimension) {
107
+ case 'minutes':
108
+ return inst.workingMinutes;
109
+ case 'shifts':
110
+ return 1;
111
+ case 'nights':
112
+ return inst.isNightShift ? 1 : 0;
113
+ case 'weekends':
114
+ return inst.weekday === 6 || inst.weekday === 7 ? 1 : 0;
115
+ case 'holidays':
116
+ return inst.isPublicHoliday ? 1 : 0;
117
+ case 'tag':
118
+ // The load being equalised is shifts *of this type* — matched on the
119
+ // instance's shiftTypeTag, like every other tag-shaped rule. Counting
120
+ // the employee's own tag would just re-count tagged people's totals
121
+ // and pin untagged people at a constant zero.
122
+ return rule.tag !== undefined && inst.shiftTypeTag === rule.tag ? 1 : 0;
123
+ default:
124
+ return 0;
125
+ }
126
+ }
127
+ /**
128
+ * Each person's entitlement weight. Equal by default; proportional to
129
+ * contracted hours when `proRataByContract` is set, which is what the equal
130
+ * treatment directives require for part-timers.
131
+ */
132
+ function shareWeights(state, rule, employeeIds) {
133
+ const weights = new Map();
134
+ for (const id of employeeIds) {
135
+ if (!rule.proRataByContract) {
136
+ weights.set(id, 1);
137
+ continue;
138
+ }
139
+ const weekly = state.ctx.employeeById.get(id)?.contract?.weeklyMinutes;
140
+ weights.set(id, weekly && weekly > 0 ? weekly : 1);
141
+ }
142
+ return weights;
143
+ }
144
+ function label(rule) {
145
+ return rule.dimension === 'tag' ? `"${rule.tag}" shift` : rule.dimension;
146
+ }
147
+ function round(value) {
148
+ return Math.round(value * 10) / 10;
149
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Group composition — cardinality rules over the *set* assigned to a shift.
3
+ *
4
+ * A different shape from per-employee skill matching, and the one naive engines
5
+ * miss: "at least one senior on every shift", "at most two trainees", "no fewer
6
+ * than 60% registered nurses". None of these are properties of an individual
7
+ * assignment — each is satisfiable or not only once you know the whole team on
8
+ * that shift — so they cannot be expressed as a `delta` on one pair.
9
+ *
10
+ * They are also the rules operational buyers ask about first. German ward
11
+ * staffing (PpUGV) is a ratio by ward and shift; supervision limits on trainees
12
+ * are a maximum; "never work alone" is a floor of two.
13
+ *
14
+ * Maximums *can* be breached by a single assignment, so those are checked per
15
+ * pair as well as reported per instance. Minimums can only ever be reported.
16
+ */
17
+ import type { SchedulingConstraint } from '../types';
18
+ export declare function groupComposition(): SchedulingConstraint;
19
+ //# sourceMappingURL=group-composition.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"group-composition.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/group-composition.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAoC,oBAAoB,EAA8B,MAAM,UAAU,CAAC;AAGnH,wBAAgB,gBAAgB,IAAI,oBAAoB,CA2EvD"}
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ /**
3
+ * Group composition — cardinality rules over the *set* assigned to a shift.
4
+ *
5
+ * A different shape from per-employee skill matching, and the one naive engines
6
+ * miss: "at least one senior on every shift", "at most two trainees", "no fewer
7
+ * than 60% registered nurses". None of these are properties of an individual
8
+ * assignment — each is satisfiable or not only once you know the whole team on
9
+ * that shift — so they cannot be expressed as a `delta` on one pair.
10
+ *
11
+ * They are also the rules operational buyers ask about first. German ward
12
+ * staffing (PpUGV) is a ratio by ward and shift; supervision limits on trainees
13
+ * are a maximum; "never work alone" is a floor of two.
14
+ *
15
+ * Maximums *can* be breached by a single assignment, so those are checked per
16
+ * pair as well as reported per instance. Minimums can only ever be reported.
17
+ */
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.groupComposition = void 0;
20
+ const support_1 = require("./support");
21
+ function groupComposition() {
22
+ const constraint = (0, support_1.fromVerdict)({
23
+ id: 'group-composition',
24
+ hardness: 'hard',
25
+ weight: 1,
26
+ verdict(state, pair) {
27
+ const inst = (0, support_1.instanceOf)(state, pair);
28
+ if (!inst)
29
+ return (0, support_1.pass)('group-composition', 'unknown shift');
30
+ const assigned = state.assignments.get(inst.id) ?? new Set();
31
+ const wouldBe = assigned.has(pair.employeeId) ? assigned.size : assigned.size + 1;
32
+ if (inst.maxEmployees !== undefined && wouldBe > inst.maxEmployees) {
33
+ return (0, support_1.fail)('group-composition', 'hard', `"${inst.id}" already has its maximum of ${inst.maxEmployees} assignees`, { actual: wouldBe, required: inst.maxEmployees, unit: 'count' });
34
+ }
35
+ for (const [tag, max] of Object.entries(inst.tagMaximums)) {
36
+ if (!state.ctx.employeeTags.get(pair.employeeId)?.has(tag))
37
+ continue;
38
+ const current = countTag(state, inst, tag, pair.employeeId);
39
+ if (current + 1 > max) {
40
+ return (0, support_1.fail)('group-composition', 'hard', `"${inst.id}" already has its maximum of ${max} assignee(s) tagged "${tag}"`, { actual: current + 1, required: max, unit: 'count' });
41
+ }
42
+ }
43
+ return (0, support_1.pass)('group-composition', 'composition limits respected');
44
+ },
45
+ });
46
+ constraint.evaluate = (state) => {
47
+ const out = [];
48
+ for (const inst of state.ctx.instances) {
49
+ const assigned = state.assignments.get(inst.id);
50
+ if (!assigned || assigned.size === 0)
51
+ continue;
52
+ for (const [tag, max] of Object.entries(inst.tagMaximums)) {
53
+ const count = countTag(state, inst, tag);
54
+ if (count > max) {
55
+ out.push({
56
+ constraintId: 'group-composition',
57
+ severity: 'hard',
58
+ shiftInstanceId: inst.id,
59
+ message: `shift "${inst.id}" has ${count} assignee(s) tagged "${tag}", over the maximum of ${max}`,
60
+ actual: count,
61
+ required: max,
62
+ unit: 'count',
63
+ });
64
+ }
65
+ }
66
+ if (inst.maxEmployees !== undefined && assigned.size > inst.maxEmployees) {
67
+ out.push({
68
+ constraintId: 'group-composition',
69
+ severity: 'hard',
70
+ shiftInstanceId: inst.id,
71
+ message: `shift "${inst.id}" has ${assigned.size} assignees, over the maximum of ${inst.maxEmployees}`,
72
+ actual: assigned.size,
73
+ required: inst.maxEmployees,
74
+ unit: 'count',
75
+ });
76
+ }
77
+ }
78
+ return out;
79
+ };
80
+ return constraint;
81
+ }
82
+ exports.groupComposition = groupComposition;
83
+ function countTag(state, inst, tag, exclude) {
84
+ let count = 0;
85
+ for (const employeeId of state.assignments.get(inst.id) ?? []) {
86
+ if (employeeId === exclude)
87
+ continue;
88
+ if (state.ctx.employeeTags.get(employeeId)?.has(tag))
89
+ count++;
90
+ }
91
+ return count;
92
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Hour-budget — per-period worked-minutes bounds. Max is hard by default,
3
+ * min is soft by default (warn, don't block): an under-worked employee is a
4
+ * report, not a breach that should stall staffing.
5
+ *
6
+ * Durations are always true elapsed minutes — overnight shifts count forward
7
+ * into the next day, never `abs()`-wrapped like the legacy solver.
8
+ */
9
+ import type { ConstraintViolation, ModelContext, SchedulingConstraint, SearchState } from '../types';
10
+ export declare function hourBudget(): SchedulingConstraint;
11
+ /** Soft min-hours shortfalls of the current state. */
12
+ export declare function minHourViolations(ctx: ModelContext, state: SearchState, weight: number): ConstraintViolation[];
13
+ //# sourceMappingURL=hour-budget.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hour-budget.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/hour-budget.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,YAAY,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAErG,wBAAgB,UAAU,IAAI,oBAAoB,CAwBjD;AAED,sDAAsD;AACtD,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,YAAY,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,GAAG,mBAAmB,EAAE,CAgB9G"}
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ /**
3
+ * Hour-budget — per-period worked-minutes bounds. Max is hard by default,
4
+ * min is soft by default (warn, don't block): an under-worked employee is a
5
+ * report, not a breach that should stall staffing.
6
+ *
7
+ * Durations are always true elapsed minutes — overnight shifts count forward
8
+ * into the next day, never `abs()`-wrapped like the legacy solver.
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.minHourViolations = exports.hourBudget = void 0;
12
+ function hourBudget() {
13
+ return {
14
+ id: 'hour-budget',
15
+ hardness: 'hard',
16
+ delta(state, pair) {
17
+ const employee = state.ctx.employeeById.get(pair.employeeId);
18
+ const inst = state.ctx.instanceById.get(pair.shiftInstanceId);
19
+ if (!employee || !inst)
20
+ return 0;
21
+ if (employee.maxHoursForPeriod === undefined)
22
+ return 0;
23
+ // Working minutes, not elapsed: `minutesByEmployee` accumulates
24
+ // working time, and the budget is documented as *worked* hours, so
25
+ // the candidate must contribute in the same unit — an unpaid break
26
+ // or a fractional duty must not be double-counted against it.
27
+ const current = state.minutesByEmployee.get(pair.employeeId) ?? 0;
28
+ return current + inst.workingMinutes > employee.maxHoursForPeriod * 60 ? 1 : 0;
29
+ },
30
+ explain(state, pair) {
31
+ const employee = state.ctx.employeeById.get(pair.employeeId);
32
+ if (this.delta(state, pair) > 0 && employee) {
33
+ return `assigning "${pair.shiftInstanceId}" pushes employee "${pair.employeeId}" past ${employee.maxHoursForPeriod}h for the period`;
34
+ }
35
+ return null;
36
+ },
37
+ };
38
+ }
39
+ exports.hourBudget = hourBudget;
40
+ /** Soft min-hours shortfalls of the current state. */
41
+ function minHourViolations(ctx, state, weight) {
42
+ const out = [];
43
+ for (const employee of ctx.employees) {
44
+ if (employee.minHoursForPeriod === undefined)
45
+ continue;
46
+ const worked = state.minutesByEmployee.get(employee.id) ?? 0;
47
+ const needed = employee.minHoursForPeriod * 60;
48
+ if (worked < needed) {
49
+ out.push({
50
+ constraintId: 'hour-budget',
51
+ severity: 'soft',
52
+ employeeId: employee.id,
53
+ message: `employee "${employee.id}" worked ${(worked / 60).toFixed(1)}h, below the ${employee.minHoursForPeriod}h minimum (weight ${weight})`,
54
+ });
55
+ }
56
+ }
57
+ return out;
58
+ }
59
+ exports.minHourViolations = minHourViolations;
@@ -0,0 +1,24 @@
1
+ /**
2
+ * In-shift break entitlement — Directive 2003/88/EC Art 4.
3
+ *
4
+ * Art 4 fixes only the trigger — "where the working day is longer than six
5
+ * hours" — and leaves the duration to member states and collective agreements.
6
+ * The spread is wide: 10 minutes as an Italian floor, 15 in Spain and Belgium,
7
+ * 20 in France, 30 in Germany rising to 45 past nine hours, and a full one to
8
+ * two hours in Portugal, which splits the shift rather than pausing it.
9
+ *
10
+ * This engine assigns people to shifts rather than placing breaks inside them,
11
+ * so the rule is enforced against *shift design*: a template whose working span
12
+ * triggers an entitlement it does not carry is reported, once, rather than
13
+ * silently rostered. `ShiftTemplate.unpaidBreakMinutes` is how a template
14
+ * declares the break it provides.
15
+ *
16
+ * One trap worth encoding: C-107/19 holds that a break the worker must stay
17
+ * reachable through is working time *and* does not discharge the Art 4
18
+ * entitlement. An interruptible break therefore never satisfies the rule, no
19
+ * matter how long it is.
20
+ */
21
+ import type { BreakRule, SchedulingConstraint } from '../types';
22
+ export declare const BREAK_CITATION = "Directive 2003/88/EC Art 4";
23
+ export declare function inShiftBreaks(rules: BreakRule[]): SchedulingConstraint;
24
+ //# sourceMappingURL=in-shift-breaks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"in-shift-breaks.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/in-shift-breaks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAoC,oBAAoB,EAAiB,MAAM,UAAU,CAAC;AAGjH,eAAO,MAAM,cAAc,+BAA+B,CAAC;AAE3D,wBAAgB,aAAa,CAAC,KAAK,EAAE,SAAS,EAAE,GAAG,oBAAoB,CA2EtE"}
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ /**
3
+ * In-shift break entitlement — Directive 2003/88/EC Art 4.
4
+ *
5
+ * Art 4 fixes only the trigger — "where the working day is longer than six
6
+ * hours" — and leaves the duration to member states and collective agreements.
7
+ * The spread is wide: 10 minutes as an Italian floor, 15 in Spain and Belgium,
8
+ * 20 in France, 30 in Germany rising to 45 past nine hours, and a full one to
9
+ * two hours in Portugal, which splits the shift rather than pausing it.
10
+ *
11
+ * This engine assigns people to shifts rather than placing breaks inside them,
12
+ * so the rule is enforced against *shift design*: a template whose working span
13
+ * triggers an entitlement it does not carry is reported, once, rather than
14
+ * silently rostered. `ShiftTemplate.unpaidBreakMinutes` is how a template
15
+ * declares the break it provides.
16
+ *
17
+ * One trap worth encoding: C-107/19 holds that a break the worker must stay
18
+ * reachable through is working time *and* does not discharge the Art 4
19
+ * entitlement. An interruptible break therefore never satisfies the rule, no
20
+ * matter how long it is.
21
+ */
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ exports.inShiftBreaks = exports.BREAK_CITATION = void 0;
24
+ const support_1 = require("./support");
25
+ exports.BREAK_CITATION = 'Directive 2003/88/EC Art 4';
26
+ function inShiftBreaks(rules) {
27
+ // Strictest applicable entitlement wins, so evaluate longest trigger first.
28
+ const ordered = [...rules].sort((a, b) => b.afterMinutes - a.afterMinutes);
29
+ const shortfall = (inst) => {
30
+ const applicable = ordered.find((r) => inst.workingMinutes > r.afterMinutes);
31
+ if (!applicable)
32
+ return null;
33
+ // An interruptible break provides nothing towards the entitlement
34
+ // (C-107/19). A `paid: true` entitlement is discharged only by declared
35
+ // paid break minutes — an unpaid break costs the worker wages, which is
36
+ // exactly what the paid entitlement exists to prevent.
37
+ const provided = applicable.interruptible
38
+ ? 0
39
+ : applicable.paid
40
+ ? inst.paidBreakMinutes
41
+ : inst.durationMinutes - inst.workingMinutes + inst.paidBreakMinutes;
42
+ if (provided >= applicable.minMinutes)
43
+ return null;
44
+ return { rule: applicable, provided };
45
+ };
46
+ const constraint = (0, support_1.fromVerdict)({
47
+ id: 'in-shift-breaks',
48
+ hardness: 'medium',
49
+ weight: 50,
50
+ citation: exports.BREAK_CITATION,
51
+ verdict(state, pair) {
52
+ const inst = (0, support_1.instanceOf)(state, pair);
53
+ if (!inst)
54
+ return (0, support_1.pass)('in-shift-breaks', 'unknown shift');
55
+ const missing = shortfall(inst);
56
+ if (!missing)
57
+ return (0, support_1.pass)('in-shift-breaks', 'break entitlement satisfied', { citation: exports.BREAK_CITATION });
58
+ const why = missing.rule.interruptible
59
+ ? 'an interruptible break is working time and does not discharge the entitlement (C-107/19)'
60
+ : `provides only ${(0, support_1.h)(missing.provided)}`;
61
+ return (0, support_1.fail)('in-shift-breaks', 'medium', `shift "${inst.id}" works ${(0, support_1.h)(inst.workingMinutes)} and owes a ${(0, support_1.h)(missing.rule.minMinutes)} break, but ${why}`, {
62
+ actual: missing.provided,
63
+ required: missing.rule.minMinutes,
64
+ unit: 'minutes',
65
+ citation: exports.BREAK_CITATION,
66
+ });
67
+ },
68
+ });
69
+ // The defect belongs to the template, not to whoever is rostered on it, so
70
+ // report it once per instance rather than once per assignee.
71
+ constraint.evaluate = (state) => {
72
+ const out = [];
73
+ for (const inst of state.ctx.instances) {
74
+ if ((state.assignments.get(inst.id)?.size ?? 0) === 0)
75
+ continue;
76
+ const missing = shortfall(inst);
77
+ if (!missing)
78
+ continue;
79
+ const why = missing.rule.interruptible
80
+ ? 'its break is interruptible, so it is working time and does not discharge the entitlement (C-107/19)'
81
+ : `provides only ${(0, support_1.h)(missing.provided)}`;
82
+ out.push({
83
+ constraintId: 'in-shift-breaks',
84
+ severity: 'medium',
85
+ shiftInstanceId: inst.id,
86
+ message: `shift "${inst.id}" works ${(0, support_1.h)(inst.workingMinutes)} and owes a ${(0, support_1.h)(missing.rule.minMinutes)} break after ${(0, support_1.h)(missing.rule.afterMinutes)}, but ${why}`,
87
+ actual: missing.provided,
88
+ required: missing.rule.minMinutes,
89
+ unit: 'minutes',
90
+ citation: exports.BREAK_CITATION,
91
+ });
92
+ }
93
+ return out;
94
+ };
95
+ return constraint;
96
+ }
97
+ exports.inShiftBreaks = inShiftBreaks;
@@ -0,0 +1,5 @@
1
+ /** Shared interval helpers for the built-in constraints. Minutes since period epoch, half-open [start, end). */
2
+ export declare function overlaps(aStart: number, aEnd: number, bStart: number, bEnd: number): boolean;
3
+ /** Minutes between the end of the earlier interval and the start of the later one; negative when they overlap. */
4
+ export declare function gapBetween(aStart: number, aEnd: number, bStart: number, bEnd: number): number;
5
+ //# sourceMappingURL=intervals.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"intervals.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/intervals.ts"],"names":[],"mappings":"AAAA,gHAAgH;AAEhH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAE5F;AAED,kHAAkH;AAClH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAI7F"}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ /** Shared interval helpers for the built-in constraints. Minutes since period epoch, half-open [start, end). */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.gapBetween = exports.overlaps = void 0;
5
+ function overlaps(aStart, aEnd, bStart, bEnd) {
6
+ return aStart < bEnd && bStart < aEnd;
7
+ }
8
+ exports.overlaps = overlaps;
9
+ /** Minutes between the end of the earlier interval and the start of the later one; negative when they overlap. */
10
+ function gapBetween(aStart, aEnd, bStart, bEnd) {
11
+ if (aEnd <= bStart)
12
+ return bStart - aEnd;
13
+ if (bEnd <= aStart)
14
+ return aStart - bEnd;
15
+ return -Math.min(aEnd, bEnd) + Math.max(aStart, bStart);
16
+ }
17
+ exports.gapBetween = gapBetween;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Max-shift-duration — a single shift never exceeds the employee's per-shift
3
+ * cap. Hard by default; prunes ineligible pairs before search.
4
+ */
5
+ import type { SchedulingConstraint } from '../types';
6
+ export declare function maxShiftDuration(): SchedulingConstraint;
7
+ //# sourceMappingURL=max-shift-duration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"max-shift-duration.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/max-shift-duration.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAErD,wBAAgB,gBAAgB,IAAI,oBAAoB,CA4BvD"}
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ /**
3
+ * Max-shift-duration — a single shift never exceeds the employee's per-shift
4
+ * cap. Hard by default; prunes ineligible pairs before search.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.maxShiftDuration = void 0;
8
+ function maxShiftDuration() {
9
+ const exceeds = (empMax, durationMinutes) => empMax !== undefined && durationMinutes > empMax;
10
+ return {
11
+ id: 'max-shift-duration',
12
+ hardness: 'hard',
13
+ prune(ctx, eligibility) {
14
+ for (const [employeeId, instances] of eligibility) {
15
+ const empMax = ctx.employeeById.get(employeeId)?.maxShiftDurationMinutes;
16
+ if (empMax === undefined)
17
+ continue;
18
+ for (const instanceId of [...instances]) {
19
+ const inst = ctx.instanceById.get(instanceId);
20
+ if (inst && exceeds(empMax, inst.durationMinutes))
21
+ instances.delete(instanceId);
22
+ }
23
+ }
24
+ },
25
+ delta(state, pair) {
26
+ const empMax = state.ctx.employeeById.get(pair.employeeId)?.maxShiftDurationMinutes;
27
+ const inst = state.ctx.instanceById.get(pair.shiftInstanceId);
28
+ return inst && exceeds(empMax, inst.durationMinutes) ? 1 : 0;
29
+ },
30
+ explain(state, pair) {
31
+ const empMax = state.ctx.employeeById.get(pair.employeeId)?.maxShiftDurationMinutes;
32
+ return this.delta(state, pair) > 0
33
+ ? `shift "${pair.shiftInstanceId}" exceeds employee "${pair.employeeId}" max shift duration of ${empMax} minutes`
34
+ : null;
35
+ },
36
+ };
37
+ }
38
+ exports.maxShiftDuration = maxShiftDuration;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Min-rest — a configurable minimum rest between the end of one assignment and
3
+ * the start of the next, across day boundaries. Hard by default.
4
+ *
5
+ * The default is 660 minutes (11h): the floor set by Article 3 of Directive
6
+ * 2003/88/EC. Member states may be stricter (ES and RO require 12h) and
7
+ * derogations may go lower (NL/DK/CZ 8h, FR 9h by collective agreement), so the
8
+ * value is always caller-supplied — the library ships the rule, never a
9
+ * jurisdiction's number.
10
+ *
11
+ * Scope note: this is a *general* inter-assignment rest rule, not a night-shift
12
+ * rule. It was called `rest-after-night` while it was a re-derivation of the
13
+ * legacy Python constraint, which compared `d_off > d` but then computed the
14
+ * gap from the *same* shift's start and end (so it never modeled rest between
15
+ * consecutive days) and hardcoded the shift name `"Night"`. Both bugs are gone;
16
+ * the name went with them.
17
+ */
18
+ import type { SchedulingConstraint } from '../types';
19
+ /** EU floor: Directive 2003/88/EC Article 3 — 11 consecutive hours per 24-hour period. */
20
+ export declare const DEFAULT_MIN_REST_MINUTES = 660;
21
+ export declare function minRest(minRestMinutes: number): SchedulingConstraint;
22
+ //# sourceMappingURL=min-rest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"min-rest.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/min-rest.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAA+B,MAAM,UAAU,CAAC;AAElF,0FAA0F;AAC1F,eAAO,MAAM,wBAAwB,MAAM,CAAC;AAE5C,wBAAgB,OAAO,CAAC,cAAc,EAAE,MAAM,GAAG,oBAAoB,CAgCpE"}
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ /**
3
+ * Min-rest — a configurable minimum rest between the end of one assignment and
4
+ * the start of the next, across day boundaries. Hard by default.
5
+ *
6
+ * The default is 660 minutes (11h): the floor set by Article 3 of Directive
7
+ * 2003/88/EC. Member states may be stricter (ES and RO require 12h) and
8
+ * derogations may go lower (NL/DK/CZ 8h, FR 9h by collective agreement), so the
9
+ * value is always caller-supplied — the library ships the rule, never a
10
+ * jurisdiction's number.
11
+ *
12
+ * Scope note: this is a *general* inter-assignment rest rule, not a night-shift
13
+ * rule. It was called `rest-after-night` while it was a re-derivation of the
14
+ * legacy Python constraint, which compared `d_off > d` but then computed the
15
+ * gap from the *same* shift's start and end (so it never modeled rest between
16
+ * consecutive days) and hardcoded the shift name `"Night"`. Both bugs are gone;
17
+ * the name went with them.
18
+ */
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.minRest = exports.DEFAULT_MIN_REST_MINUTES = void 0;
21
+ /** EU floor: Directive 2003/88/EC Article 3 — 11 consecutive hours per 24-hour period. */
22
+ exports.DEFAULT_MIN_REST_MINUTES = 660;
23
+ function minRest(minRestMinutes) {
24
+ const breach = (state, pair) => {
25
+ const inst = state.ctx.instanceById.get(pair.shiftInstanceId);
26
+ if (!inst)
27
+ return false;
28
+ const assigned = state.byEmployee.get(pair.employeeId);
29
+ if (!assigned)
30
+ return false;
31
+ for (const otherId of assigned) {
32
+ if (otherId === pair.shiftInstanceId)
33
+ continue;
34
+ const other = state.ctx.instanceById.get(otherId);
35
+ if (!other)
36
+ continue;
37
+ const gap = inst.startMinute >= other.endMinute
38
+ ? inst.startMinute - other.endMinute
39
+ : other.startMinute >= inst.endMinute
40
+ ? other.startMinute - inst.endMinute
41
+ : 0; // overlapping: no-overlap owns that, rest sees zero gap
42
+ if (gap < minRestMinutes)
43
+ return true;
44
+ }
45
+ return false;
46
+ };
47
+ return {
48
+ id: 'min-rest',
49
+ hardness: 'hard',
50
+ delta(state, pair) {
51
+ return breach(state, pair) ? 1 : 0;
52
+ },
53
+ explain(state, pair) {
54
+ return breach(state, pair)
55
+ ? `employee "${pair.employeeId}" would have less than ${(minRestMinutes / 60).toFixed(1)}h rest around "${pair.shiftInstanceId}"`
56
+ : null;
57
+ },
58
+ };
59
+ }
60
+ exports.minRest = minRest;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Min-staffing — every shift instance needs `minEmployees` assignees, plus
3
+ * per-tag minimums from `tagRequirements`. Hard by default.
4
+ *
5
+ * Assigning a pair can never *breach* a minimum, so `delta` is always 0; the
6
+ * rule's teeth are the per-instance shortfall evaluation in
7
+ * `staffingViolations` (used by the facade for the violation report) and the
8
+ * unfilled-slot penalty in the engine's objective.
9
+ */
10
+ import type { ConstraintViolation, ModelContext, SchedulingConstraint, SearchState, Severity } from '../types';
11
+ export declare function minStaffing(): SchedulingConstraint;
12
+ /** Per-instance staffing shortfalls of the current state — the reportable face of the rule. */
13
+ export declare function staffingViolations(ctx: ModelContext, state: SearchState, severity: Severity): ConstraintViolation[];
14
+ //# sourceMappingURL=min-staffing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"min-staffing.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/min-staffing.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,YAAY,EAAE,oBAAoB,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAE/G,wBAAgB,WAAW,IAAI,oBAAoB,CAOlD;AAED,+FAA+F;AAC/F,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,YAAY,EAAE,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,QAAQ,GAAG,mBAAmB,EAAE,CAkCnH"}