assignment-user-matcher 1.9.0 → 1.11.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 (166) hide show
  1. package/README.md +164 -10
  2. package/dist/index.d.ts +2 -1
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +19 -1
  5. package/dist/learning/auto-weights.d.ts +7 -4
  6. package/dist/learning/auto-weights.d.ts.map +1 -1
  7. package/dist/learning/auto-weights.js +7 -6
  8. package/dist/lua/workflow-transition.lua +8 -2
  9. package/dist/managers/LearningManager.d.ts.map +1 -1
  10. package/dist/managers/LearningManager.js +47 -0
  11. package/dist/managers/WorkflowManager.d.ts +7 -1
  12. package/dist/managers/WorkflowManager.d.ts.map +1 -1
  13. package/dist/managers/WorkflowManager.js +85 -12
  14. package/dist/matcher.class.d.ts +35 -3
  15. package/dist/matcher.class.d.ts.map +1 -1
  16. package/dist/matcher.class.js +319 -76
  17. package/dist/queries/users.d.ts +34 -0
  18. package/dist/queries/users.d.ts.map +1 -0
  19. package/dist/queries/users.js +227 -0
  20. package/dist/scheduling/constraints/availability.d.ts +43 -0
  21. package/dist/scheduling/constraints/availability.d.ts.map +1 -0
  22. package/dist/scheduling/constraints/availability.js +165 -0
  23. package/dist/scheduling/constraints/consecutive.d.ts +25 -0
  24. package/dist/scheduling/constraints/consecutive.d.ts.map +1 -0
  25. package/dist/scheduling/constraints/consecutive.js +215 -0
  26. package/dist/scheduling/constraints/constraint.d.ts +35 -0
  27. package/dist/scheduling/constraints/constraint.d.ts.map +1 -0
  28. package/dist/scheduling/constraints/constraint.js +97 -0
  29. package/dist/scheduling/constraints/contract.d.ts +21 -0
  30. package/dist/scheduling/constraints/contract.d.ts.map +1 -0
  31. package/dist/scheduling/constraints/contract.js +120 -0
  32. package/dist/scheduling/constraints/cost.d.ts +18 -0
  33. package/dist/scheduling/constraints/cost.d.ts.map +1 -0
  34. package/dist/scheduling/constraints/cost.js +65 -0
  35. package/dist/scheduling/constraints/daily-rest.d.ts +22 -0
  36. package/dist/scheduling/constraints/daily-rest.d.ts.map +1 -0
  37. package/dist/scheduling/constraints/daily-rest.js +123 -0
  38. package/dist/scheduling/constraints/duty-quota.d.ts +20 -0
  39. package/dist/scheduling/constraints/duty-quota.d.ts.map +1 -0
  40. package/dist/scheduling/constraints/duty-quota.js +95 -0
  41. package/dist/scheduling/constraints/engagement-floor.d.ts +28 -0
  42. package/dist/scheduling/constraints/engagement-floor.d.ts.map +1 -0
  43. package/dist/scheduling/constraints/engagement-floor.js +79 -0
  44. package/dist/scheduling/constraints/fairness.d.ts +34 -0
  45. package/dist/scheduling/constraints/fairness.d.ts.map +1 -0
  46. package/dist/scheduling/constraints/fairness.js +149 -0
  47. package/dist/scheduling/constraints/group-composition.d.ts +19 -0
  48. package/dist/scheduling/constraints/group-composition.d.ts.map +1 -0
  49. package/dist/scheduling/constraints/group-composition.js +92 -0
  50. package/dist/scheduling/constraints/hour-budget.d.ts +13 -0
  51. package/dist/scheduling/constraints/hour-budget.d.ts.map +1 -0
  52. package/dist/scheduling/constraints/hour-budget.js +65 -0
  53. package/dist/scheduling/constraints/in-shift-breaks.d.ts +24 -0
  54. package/dist/scheduling/constraints/in-shift-breaks.d.ts.map +1 -0
  55. package/dist/scheduling/constraints/in-shift-breaks.js +99 -0
  56. package/dist/scheduling/constraints/intervals.d.ts +5 -0
  57. package/dist/scheduling/constraints/intervals.d.ts.map +1 -0
  58. package/dist/scheduling/constraints/intervals.js +17 -0
  59. package/dist/scheduling/constraints/max-shift-duration.d.ts +7 -0
  60. package/dist/scheduling/constraints/max-shift-duration.d.ts.map +1 -0
  61. package/dist/scheduling/constraints/max-shift-duration.js +38 -0
  62. package/dist/scheduling/constraints/min-rest.d.ts +22 -0
  63. package/dist/scheduling/constraints/min-rest.d.ts.map +1 -0
  64. package/dist/scheduling/constraints/min-rest.js +49 -0
  65. package/dist/scheduling/constraints/min-staffing.d.ts +14 -0
  66. package/dist/scheduling/constraints/min-staffing.d.ts.map +1 -0
  67. package/dist/scheduling/constraints/min-staffing.js +59 -0
  68. package/dist/scheduling/constraints/night-work.d.ts +24 -0
  69. package/dist/scheduling/constraints/night-work.d.ts.map +1 -0
  70. package/dist/scheduling/constraints/night-work.js +179 -0
  71. package/dist/scheduling/constraints/no-overlap.d.ts +11 -0
  72. package/dist/scheduling/constraints/no-overlap.d.ts.map +1 -0
  73. package/dist/scheduling/constraints/no-overlap.js +35 -0
  74. package/dist/scheduling/constraints/notice.d.ts +44 -0
  75. package/dist/scheduling/constraints/notice.d.ts.map +1 -0
  76. package/dist/scheduling/constraints/notice.js +140 -0
  77. package/dist/scheduling/constraints/one-shift-per-day.d.ts +7 -0
  78. package/dist/scheduling/constraints/one-shift-per-day.d.ts.map +1 -0
  79. package/dist/scheduling/constraints/one-shift-per-day.js +35 -0
  80. package/dist/scheduling/constraints/overtime.d.ts +47 -0
  81. package/dist/scheduling/constraints/overtime.d.ts.map +1 -0
  82. package/dist/scheduling/constraints/overtime.js +149 -0
  83. package/dist/scheduling/constraints/protections.d.ts +21 -0
  84. package/dist/scheduling/constraints/protections.d.ts.map +1 -0
  85. package/dist/scheduling/constraints/protections.js +93 -0
  86. package/dist/scheduling/constraints/qualification.d.ts +18 -0
  87. package/dist/scheduling/constraints/qualification.d.ts.map +1 -0
  88. package/dist/scheduling/constraints/qualification.js +78 -0
  89. package/dist/scheduling/constraints/rest-days.d.ts +30 -0
  90. package/dist/scheduling/constraints/rest-days.d.ts.map +1 -0
  91. package/dist/scheduling/constraints/rest-days.js +133 -0
  92. package/dist/scheduling/constraints/rolling-hours.d.ts +24 -0
  93. package/dist/scheduling/constraints/rolling-hours.d.ts.map +1 -0
  94. package/dist/scheduling/constraints/rolling-hours.js +147 -0
  95. package/dist/scheduling/constraints/start-interval.d.ts +20 -0
  96. package/dist/scheduling/constraints/start-interval.d.ts.map +1 -0
  97. package/dist/scheduling/constraints/start-interval.js +53 -0
  98. package/dist/scheduling/constraints/support.d.ts +48 -0
  99. package/dist/scheduling/constraints/support.d.ts.map +1 -0
  100. package/dist/scheduling/constraints/support.js +97 -0
  101. package/dist/scheduling/constraints/time-off.d.ts +7 -0
  102. package/dist/scheduling/constraints/time-off.d.ts.map +1 -0
  103. package/dist/scheduling/constraints/time-off.js +42 -0
  104. package/dist/scheduling/constraints/weekly-rest.d.ts +22 -0
  105. package/dist/scheduling/constraints/weekly-rest.d.ts.map +1 -0
  106. package/dist/scheduling/constraints/weekly-rest.js +103 -0
  107. package/dist/scheduling/cost.d.ts +56 -0
  108. package/dist/scheduling/cost.d.ts.map +1 -0
  109. package/dist/scheduling/cost.js +120 -0
  110. package/dist/scheduling/engine/construction.d.ts +22 -0
  111. package/dist/scheduling/engine/construction.d.ts.map +1 -0
  112. package/dist/scheduling/engine/construction.js +104 -0
  113. package/dist/scheduling/engine/explain.d.ts +12 -0
  114. package/dist/scheduling/engine/explain.d.ts.map +1 -0
  115. package/dist/scheduling/engine/explain.js +24 -0
  116. package/dist/scheduling/engine/objective.d.ts +73 -0
  117. package/dist/scheduling/engine/objective.d.ts.map +1 -0
  118. package/dist/scheduling/engine/objective.js +164 -0
  119. package/dist/scheduling/engine/prng.d.ts +5 -0
  120. package/dist/scheduling/engine/prng.d.ts.map +1 -0
  121. package/dist/scheduling/engine/prng.js +24 -0
  122. package/dist/scheduling/engine/propagation.d.ts +19 -0
  123. package/dist/scheduling/engine/propagation.d.ts.map +1 -0
  124. package/dist/scheduling/engine/propagation.js +40 -0
  125. package/dist/scheduling/engine/search.d.ts +50 -0
  126. package/dist/scheduling/engine/search.d.ts.map +1 -0
  127. package/dist/scheduling/engine/search.js +127 -0
  128. package/dist/scheduling/engine/state.d.ts +28 -0
  129. package/dist/scheduling/engine/state.d.ts.map +1 -0
  130. package/dist/scheduling/engine/state.js +96 -0
  131. package/dist/scheduling/engine/timeline.d.ts +179 -0
  132. package/dist/scheduling/engine/timeline.d.ts.map +1 -0
  133. package/dist/scheduling/engine/timeline.js +416 -0
  134. package/dist/scheduling/engine/verdicts.d.ts +18 -0
  135. package/dist/scheduling/engine/verdicts.d.ts.map +1 -0
  136. package/dist/scheduling/engine/verdicts.js +74 -0
  137. package/dist/scheduling/index.d.ts +10 -0
  138. package/dist/scheduling/index.d.ts.map +1 -0
  139. package/dist/scheduling/index.js +29 -0
  140. package/dist/scheduling/model.d.ts +53 -0
  141. package/dist/scheduling/model.d.ts.map +1 -0
  142. package/dist/scheduling/model.js +380 -0
  143. package/dist/scheduling/operations.d.ts +134 -0
  144. package/dist/scheduling/operations.d.ts.map +1 -0
  145. package/dist/scheduling/operations.js +376 -0
  146. package/dist/scheduling/provenance.d.ts +33 -0
  147. package/dist/scheduling/provenance.d.ts.map +1 -0
  148. package/dist/scheduling/provenance.js +70 -0
  149. package/dist/scheduling/rules.d.ts +23 -0
  150. package/dist/scheduling/rules.d.ts.map +1 -0
  151. package/dist/scheduling/rules.js +37 -0
  152. package/dist/scheduling/scheduler.class.d.ts +24 -0
  153. package/dist/scheduling/scheduler.class.d.ts.map +1 -0
  154. package/dist/scheduling/scheduler.class.js +150 -0
  155. package/dist/scheduling/time.d.ts +138 -0
  156. package/dist/scheduling/time.d.ts.map +1 -0
  157. package/dist/scheduling/time.js +267 -0
  158. package/dist/scheduling/types.d.ts +938 -0
  159. package/dist/scheduling/types.d.ts.map +1 -0
  160. package/dist/scheduling/types.js +19 -0
  161. package/dist/types/matcher.d.ts +86 -2
  162. package/dist/types/matcher.d.ts.map +1 -1
  163. package/dist/utils/keys.d.ts +1 -0
  164. package/dist/utils/keys.d.ts.map +1 -1
  165. package/dist/utils/keys.js +6 -0
  166. package/package.json +4 -2
@@ -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,CA8BjD;AAED,sDAAsD;AACtD,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,YAAY,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,GAAG,mBAAmB,EAAE,CAgB9G"}
@@ -0,0 +1,65 @@
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
+ // An already-assigned pair's shift is in the total, so it is not
28
+ // added again (the same self-exclusion `withEntry` gives the
29
+ // timeline rules): re-judging a committed roster must ask "is the
30
+ // total over the cap", not "would the cap survive this twice".
31
+ const current = state.minutesByEmployee.get(pair.employeeId) ?? 0;
32
+ const assigned = state.assignments.get(pair.shiftInstanceId)?.has(pair.employeeId) ?? false;
33
+ const total = assigned ? current : current + inst.workingMinutes;
34
+ return total > employee.maxHoursForPeriod * 60 ? 1 : 0;
35
+ },
36
+ explain(state, pair) {
37
+ const employee = state.ctx.employeeById.get(pair.employeeId);
38
+ if (this.delta(state, pair) > 0 && employee) {
39
+ return `assigning "${pair.shiftInstanceId}" pushes employee "${pair.employeeId}" past ${employee.maxHoursForPeriod}h for the period`;
40
+ }
41
+ return null;
42
+ },
43
+ };
44
+ }
45
+ exports.hourBudget = hourBudget;
46
+ /** Soft min-hours shortfalls of the current state. */
47
+ function minHourViolations(ctx, state, weight) {
48
+ const out = [];
49
+ for (const employee of ctx.employees) {
50
+ if (employee.minHoursForPeriod === undefined)
51
+ continue;
52
+ const worked = state.minutesByEmployee.get(employee.id) ?? 0;
53
+ const needed = employee.minHoursForPeriod * 60;
54
+ if (worked < needed) {
55
+ out.push({
56
+ constraintId: 'hour-budget',
57
+ severity: 'soft',
58
+ employeeId: employee.id,
59
+ message: `employee "${employee.id}" worked ${(worked / 60).toFixed(1)}h, below the ${employee.minHoursForPeriod}h minimum (weight ${weight})`,
60
+ });
61
+ }
62
+ }
63
+ return out;
64
+ }
65
+ 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,CA6EtE"}
@@ -0,0 +1,99 @@
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. Declared break
37
+ // minutes, never span − working: on a duty-scaled shift the difference
38
+ // is duty occupation, not rest.
39
+ const provided = applicable.interruptible
40
+ ? 0
41
+ : applicable.paid
42
+ ? inst.paidBreakMinutes
43
+ : inst.unpaidBreakMinutes + inst.paidBreakMinutes;
44
+ if (provided >= applicable.minMinutes)
45
+ return null;
46
+ return { rule: applicable, provided };
47
+ };
48
+ const constraint = (0, support_1.fromVerdict)({
49
+ id: 'in-shift-breaks',
50
+ hardness: 'medium',
51
+ weight: 50,
52
+ citation: exports.BREAK_CITATION,
53
+ verdict(state, pair) {
54
+ const inst = (0, support_1.instanceOf)(state, pair);
55
+ if (!inst)
56
+ return (0, support_1.pass)('in-shift-breaks', 'unknown shift');
57
+ const missing = shortfall(inst);
58
+ if (!missing)
59
+ return (0, support_1.pass)('in-shift-breaks', 'break entitlement satisfied', { citation: exports.BREAK_CITATION });
60
+ const why = missing.rule.interruptible
61
+ ? 'an interruptible break is working time and does not discharge the entitlement (C-107/19)'
62
+ : `provides only ${(0, support_1.h)(missing.provided)}`;
63
+ 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}`, {
64
+ actual: missing.provided,
65
+ required: missing.rule.minMinutes,
66
+ unit: 'minutes',
67
+ citation: exports.BREAK_CITATION,
68
+ });
69
+ },
70
+ });
71
+ // The defect belongs to the template, not to whoever is rostered on it, so
72
+ // report it once per instance rather than once per assignee.
73
+ constraint.evaluate = (state) => {
74
+ const out = [];
75
+ for (const inst of state.ctx.instances) {
76
+ if ((state.assignments.get(inst.id)?.size ?? 0) === 0)
77
+ continue;
78
+ const missing = shortfall(inst);
79
+ if (!missing)
80
+ continue;
81
+ const why = missing.rule.interruptible
82
+ ? 'its break is interruptible, so it is working time and does not discharge the entitlement (C-107/19)'
83
+ : `provides only ${(0, support_1.h)(missing.provided)}`;
84
+ out.push({
85
+ constraintId: 'in-shift-breaks',
86
+ severity: 'medium',
87
+ shiftInstanceId: inst.id,
88
+ 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}`,
89
+ actual: missing.provided,
90
+ required: missing.rule.minMinutes,
91
+ unit: 'minutes',
92
+ citation: exports.BREAK_CITATION,
93
+ });
94
+ }
95
+ return out;
96
+ };
97
+ return constraint;
98
+ }
99
+ 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;AAGlF,0FAA0F;AAC1F,eAAO,MAAM,wBAAwB,MAAM,CAAC;AAE5C,wBAAgB,OAAO,CAAC,cAAc,EAAE,MAAM,GAAG,oBAAoB,CAuBpE"}
@@ -0,0 +1,49 @@
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
+ const support_1 = require("./support");
22
+ /** EU floor: Directive 2003/88/EC Article 3 — 11 consecutive hours per 24-hour period. */
23
+ exports.DEFAULT_MIN_REST_MINUTES = 660;
24
+ function minRest(minRestMinutes) {
25
+ const breach = (state, pair) => {
26
+ const inst = (0, support_1.instanceOf)(state, pair);
27
+ if (!inst)
28
+ return false;
29
+ // Person timeline, not the per-contract assignment set: rest aggregates
30
+ // on the person (C-585/19), and history is what makes the rule correct
31
+ // at the period boundary. Overlaps read as a zero gap, which breaches
32
+ // here just as it did under the old pairwise arithmetic.
33
+ const gap = (0, support_1.timelineFor)(state, pair.employeeId).minGapAround((0, support_1.rangeOf)(inst), (0, support_1.entryIdOf)(pair));
34
+ return gap < minRestMinutes;
35
+ };
36
+ return {
37
+ id: 'min-rest',
38
+ hardness: 'hard',
39
+ delta(state, pair) {
40
+ return breach(state, pair) ? 1 : 0;
41
+ },
42
+ explain(state, pair) {
43
+ return breach(state, pair)
44
+ ? `employee "${pair.employeeId}" would have less than ${(minRestMinutes / 60).toFixed(1)}h rest around "${pair.shiftInstanceId}"`
45
+ : null;
46
+ },
47
+ };
48
+ }
49
+ 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"}
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ /**
3
+ * Min-staffing — every shift instance needs `minEmployees` assignees, plus
4
+ * per-tag minimums from `tagRequirements`. Hard by default.
5
+ *
6
+ * Assigning a pair can never *breach* a minimum, so `delta` is always 0; the
7
+ * rule's teeth are the per-instance shortfall evaluation in
8
+ * `staffingViolations` (used by the facade for the violation report) and the
9
+ * unfilled-slot penalty in the engine's objective.
10
+ */
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.staffingViolations = exports.minStaffing = void 0;
13
+ function minStaffing() {
14
+ return {
15
+ id: 'min-staffing',
16
+ hardness: 'hard',
17
+ delta: () => 0,
18
+ explain: () => null,
19
+ };
20
+ }
21
+ exports.minStaffing = minStaffing;
22
+ /** Per-instance staffing shortfalls of the current state — the reportable face of the rule. */
23
+ function staffingViolations(ctx, state, severity) {
24
+ const out = [];
25
+ for (const inst of ctx.instances) {
26
+ const assigned = state.assignments.get(inst.id);
27
+ const count = assigned ? assigned.size : 0;
28
+ if (count < inst.minEmployees) {
29
+ out.push({
30
+ constraintId: 'min-staffing',
31
+ severity,
32
+ shiftInstanceId: inst.id,
33
+ message: `shift "${inst.id}" needs ${inst.minEmployees} employees, has ${count}`,
34
+ actual: count,
35
+ required: inst.minEmployees,
36
+ unit: 'count',
37
+ });
38
+ }
39
+ for (const [tag, needed] of Object.entries(inst.tagRequirements)) {
40
+ let have = 0;
41
+ if (assigned) {
42
+ for (const employeeId of assigned) {
43
+ if (ctx.employeeTags.get(employeeId)?.has(tag))
44
+ have++;
45
+ }
46
+ }
47
+ if (have < needed) {
48
+ out.push({
49
+ constraintId: 'min-staffing',
50
+ severity,
51
+ shiftInstanceId: inst.id,
52
+ message: `shift "${inst.id}" needs ${needed} employees with tag "${tag}", has ${have}`,
53
+ });
54
+ }
55
+ }
56
+ }
57
+ return out;
58
+ }
59
+ exports.staffingViolations = staffingViolations;
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Night work — Directive 2003/88/EC Art 2(3), 2(4) and 8.
3
+ *
4
+ * Art 8 has two limbs that behave differently and are routinely conflated:
5
+ *
6
+ * - **8(a)** caps a night worker's normal hours at an *average* of eight per
7
+ * 24h, over a reference period national law sets (the Directive fixes no
8
+ * ceiling on it);
9
+ * - **8(b)** caps night work involving *special hazards or heavy physical or
10
+ * mental strain* at eight hours in any 24h — **absolute, no averaging**.
11
+ *
12
+ * So the same eight-hour figure is a soft average for most workers and a hard
13
+ * per-day ceiling for some, selected per person by a `hazardousNight`
14
+ * protection. Getting that backwards under-protects exactly the people the
15
+ * provision exists for.
16
+ *
17
+ * The night band itself is national and, in Poland, employer-chosen: it ranges
18
+ * from 20:00–06:00 (BE) to 00:00–07:00 (IE), subject to the Art 2(3) floor of
19
+ * at least seven hours including 00:00–05:00.
20
+ */
21
+ import type { NightWorkRule, SchedulingConstraint } from '../types';
22
+ export declare const NIGHT_WORK_CITATION = "Directive 2003/88/EC Art 8";
23
+ export declare function nightWork(rule: NightWorkRule): SchedulingConstraint;
24
+ //# sourceMappingURL=night-work.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"night-work.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/night-work.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAe,oBAAoB,EAAe,MAAM,UAAU,CAAC;AAI9F,eAAO,MAAM,mBAAmB,+BAA+B,CAAC;AAEhE,wBAAgB,SAAS,CAAC,IAAI,EAAE,aAAa,GAAG,oBAAoB,CAmInE"}