assignment-user-matcher 1.15.1 → 1.16.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 (65) hide show
  1. package/README.md +362 -8
  2. package/dist/index.d.ts +4 -2
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +6 -1
  5. package/dist/learning/atomic-ingestion.d.ts +11 -0
  6. package/dist/learning/atomic-ingestion.d.ts.map +1 -0
  7. package/dist/learning/atomic-ingestion.js +187 -0
  8. package/dist/learning/auto-weights.d.ts +13 -2
  9. package/dist/learning/auto-weights.d.ts.map +1 -1
  10. package/dist/learning/auto-weights.js +203 -35
  11. package/dist/learning/features.d.ts +5 -3
  12. package/dist/learning/features.d.ts.map +1 -1
  13. package/dist/learning/features.js +105 -4
  14. package/dist/learning/policy.d.ts +57 -0
  15. package/dist/learning/policy.d.ts.map +1 -0
  16. package/dist/learning/policy.js +71 -0
  17. package/dist/managers/LearningManager.d.ts +312 -35
  18. package/dist/managers/LearningManager.d.ts.map +1 -1
  19. package/dist/managers/LearningManager.js +1006 -168
  20. package/dist/matcher.class.d.ts +98 -11
  21. package/dist/matcher.class.d.ts.map +1 -1
  22. package/dist/matcher.class.js +247 -40
  23. package/dist/scheduling/constraints/cost.d.ts.map +1 -1
  24. package/dist/scheduling/constraints/cost.js +3 -2
  25. package/dist/scheduling/constraints/employee-scope.d.ts +5 -0
  26. package/dist/scheduling/constraints/employee-scope.d.ts.map +1 -0
  27. package/dist/scheduling/constraints/employee-scope.js +157 -0
  28. package/dist/scheduling/constraints/notice.d.ts.map +1 -1
  29. package/dist/scheduling/constraints/notice.js +8 -5
  30. package/dist/scheduling/constraints/rest-days.d.ts.map +1 -1
  31. package/dist/scheduling/constraints/rest-days.js +6 -6
  32. package/dist/scheduling/cost.d.ts.map +1 -1
  33. package/dist/scheduling/cost.js +2 -1
  34. package/dist/scheduling/engine/objective.d.ts +4 -4
  35. package/dist/scheduling/engine/objective.d.ts.map +1 -1
  36. package/dist/scheduling/engine/objective.js +12 -4
  37. package/dist/scheduling/engine/propagation.js +2 -1
  38. package/dist/scheduling/engine/search.d.ts +1 -0
  39. package/dist/scheduling/engine/search.d.ts.map +1 -1
  40. package/dist/scheduling/engine/search.js +1 -1
  41. package/dist/scheduling/engine/state.d.ts.map +1 -1
  42. package/dist/scheduling/engine/state.js +4 -0
  43. package/dist/scheduling/model.d.ts +1 -1
  44. package/dist/scheduling/model.d.ts.map +1 -1
  45. package/dist/scheduling/model.js +45 -31
  46. package/dist/scheduling/operations.d.ts +4 -0
  47. package/dist/scheduling/operations.d.ts.map +1 -1
  48. package/dist/scheduling/operations.js +36 -16
  49. package/dist/scheduling/provenance.d.ts +1 -1
  50. package/dist/scheduling/provenance.d.ts.map +1 -1
  51. package/dist/scheduling/provenance.js +16 -2
  52. package/dist/scheduling/scheduler.class.d.ts +1 -1
  53. package/dist/scheduling/scheduler.class.d.ts.map +1 -1
  54. package/dist/scheduling/scheduler.class.js +5 -3
  55. package/dist/scheduling/time.d.ts +2 -0
  56. package/dist/scheduling/time.d.ts.map +1 -1
  57. package/dist/scheduling/time.js +26 -1
  58. package/dist/scheduling/types.d.ts +12 -3
  59. package/dist/scheduling/types.d.ts.map +1 -1
  60. package/dist/types/matcher.d.ts +309 -4
  61. package/dist/types/matcher.d.ts.map +1 -1
  62. package/dist/utils/keys.d.ts +12 -2
  63. package/dist/utils/keys.d.ts.map +1 -1
  64. package/dist/utils/keys.js +35 -2
  65. package/package.json +2 -1
@@ -1 +1 @@
1
- {"version":3,"file":"notice.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/notice.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EAER,UAAU,EAEV,oBAAoB,EACpB,WAAW,EAEd,MAAM,UAAU,CAAC;AAGlB,eAAO,MAAM,eAAe,oCAAoC,CAAC;AAEjE,wBAAgB,UAAU,CAAC,IAAI,EAAE,UAAU,GAAG,oBAAoB,CAoEjE;AAwBD;;;;;;;;;;;;GAYG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,UAAU,GAAG,SAAS;;;;;;IAwBlF"}
1
+ {"version":3,"file":"notice.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/notice.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EAER,UAAU,EAEV,oBAAoB,EACpB,WAAW,EAEd,MAAM,UAAU,CAAC;AAGlB,eAAO,MAAM,eAAe,oCAAoC,CAAC;AAEjE,wBAAgB,UAAU,CAAC,IAAI,EAAE,UAAU,GAAG,oBAAoB,CAoEjE;AAwBD;;;;;;;;;;;;GAYG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,UAAU,GAAG,SAAS;;;;;;IA2BlF"}
@@ -113,24 +113,27 @@ function noticeShortfall(state, inst, rule) {
113
113
  * that matters.
114
114
  */
115
115
  function cancellationLedger(state, rule) {
116
- if (!rule?.cancellationCompensationMinutes)
117
- return [];
118
116
  const out = [];
119
117
  for (const key of state.ctx.publishedPairs) {
120
118
  const [employeeId, instanceId] = key.split('|');
119
+ const applied = Object.prototype.hasOwnProperty.call(state.ctx.employeeById.get(employeeId)?.rules ?? {}, 'notice')
120
+ ? (0, support_1.rulesFor)(state.ctx, employeeId).notice
121
+ : ((0, support_1.rulesFor)(state.ctx, employeeId).notice ?? rule);
122
+ if (!applied?.cancellationCompensationMinutes)
123
+ continue;
121
124
  if (state.assignments.get(instanceId)?.has(employeeId))
122
125
  continue;
123
126
  const inst = state.ctx.instanceById.get(instanceId);
124
- if (rule.cancellationDeadlineMinutes !== undefined &&
127
+ if (applied.cancellationDeadlineMinutes !== undefined &&
125
128
  state.ctx.asOfMinute !== undefined &&
126
129
  inst !== undefined &&
127
- inst.startMinute - state.ctx.asOfMinute >= rule.cancellationDeadlineMinutes) {
130
+ inst.startMinute - state.ctx.asOfMinute >= applied.cancellationDeadlineMinutes) {
128
131
  continue; // cancelled with the deadline still ahead — no liability
129
132
  }
130
133
  out.push({
131
134
  kind: 'lateCancellationPay',
132
135
  employeeId,
133
- minutes: Math.max(rule.cancellationCompensationMinutes, inst?.workingMinutes ?? 0),
136
+ minutes: Math.max(applied.cancellationCompensationMinutes, inst?.workingMinutes ?? 0),
134
137
  reason: `published assignment "${instanceId}" was cancelled`,
135
138
  citation: exports.NOTICE_CITATION,
136
139
  });
@@ -1 +1 @@
1
- {"version":3,"file":"rest-days.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/rest-days.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAER,WAAW,EACX,WAAW,EAEX,oBAAoB,EACpB,WAAW,EACd,MAAM,UAAU,CAAC;AAIlB,eAAO,MAAM,eAAe,qCAAqC,CAAC;AAElE,wBAAgB,QAAQ,CAAC,IAAI,EAAE,WAAW,GAAG,oBAAoB,CAgEhE;AAwBD;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,WAAW,GAAG,SAAS,GAAG,WAAW,EAAE,CAuBvG"}
1
+ {"version":3,"file":"rest-days.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/rest-days.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAER,WAAW,EACX,WAAW,EAEX,oBAAoB,EACpB,WAAW,EACd,MAAM,UAAU,CAAC;AAIlB,eAAO,MAAM,eAAe,qCAAqC,CAAC;AAElE,wBAAgB,QAAQ,CAAC,IAAI,EAAE,WAAW,GAAG,oBAAoB,CAgEhE;AAwBD;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,WAAW,GAAG,SAAS,GAAG,WAAW,EAAE,CAwBvG"}
@@ -107,18 +107,18 @@ function sundaysInPeriod(state) {
107
107
  * honest output is a dated debt the operator can act on.
108
108
  */
109
109
  function compensatoryRestLedger(state, rule) {
110
- const within = rule?.compensatoryRestWithinDays;
111
- if (!within)
112
- return [];
113
110
  const out = [];
114
111
  for (const [instanceId, employees] of state.assignments) {
115
112
  const inst = state.ctx.instanceById.get(instanceId);
116
113
  if (!inst || employees.size === 0)
117
114
  continue;
118
- const deadlineDays = inst.isPublicHoliday ? within.holiday : inst.isSunday ? within.sunday : undefined;
119
- if (deadlineDays === undefined)
120
- continue;
121
115
  for (const employeeId of employees) {
116
+ const within = (Object.prototype.hasOwnProperty.call(state.ctx.employeeById.get(employeeId)?.rules ?? {}, 'restDays')
117
+ ? (0, support_1.rulesFor)(state.ctx, employeeId).restDays
118
+ : ((0, support_1.rulesFor)(state.ctx, employeeId).restDays ?? rule))?.compensatoryRestWithinDays;
119
+ const deadlineDays = inst.isPublicHoliday ? within?.holiday : inst.isSunday ? within?.sunday : undefined;
120
+ if (deadlineDays === undefined)
121
+ continue;
122
122
  out.push({
123
123
  kind: 'substituteRestDay',
124
124
  employeeId,
@@ -1 +1 @@
1
- {"version":3,"file":"cost.d.ts","sourceRoot":"","sources":["../../src/scheduling/cost.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,cAAc,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAGlG;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,YAAY,GAAG,SAAS,EAAE,UAAU,CAAC,EAAE,cAAc,GAAG,MAAM,CAsBvH;AAaD;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,aAAa,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,GAAG,SAAS,GAAG,MAAM,CAIpG;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC7B,IAAI,EAAE,aAAa,EACnB,QAAQ,EAAE,QAAQ,EAClB,aAAa,EAAE,MAAM,EACrB,UAAU,CAAC,EAAE,cAAc,GAC5B,MAAM,CAQR;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,WAAW,GAAG;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,GAAG,SAAS,CAiBrH"}
1
+ {"version":3,"file":"cost.d.ts","sourceRoot":"","sources":["../../src/scheduling/cost.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAGH,OAAO,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,cAAc,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAGlG;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,YAAY,GAAG,SAAS,EAAE,UAAU,CAAC,EAAE,cAAc,GAAG,MAAM,CAsBvH;AAaD;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,aAAa,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,GAAG,SAAS,GAAG,MAAM,CAIpG;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC7B,IAAI,EAAE,aAAa,EACnB,QAAQ,EAAE,QAAQ,EAClB,aAAa,EAAE,MAAM,EACrB,UAAU,CAAC,EAAE,cAAc,GAC5B,MAAM,CAQR;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,WAAW,GAAG;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,GAAG,SAAS,CAiBrH"}
@@ -24,6 +24,7 @@
24
24
  */
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.rosterCost = exports.marginalCostCents = exports.overtimeSurchargeCents = exports.shiftCostCents = void 0;
27
+ const support_1 = require("./constraints/support");
27
28
  const engagement_floor_1 = require("./constraints/engagement-floor");
28
29
  /**
29
30
  * Price of one shift for one cost model, excluding any overtime surcharge.
@@ -108,7 +109,7 @@ function rosterCost(state) {
108
109
  for (const instanceId of state.byEmployee.get(employee.id) ?? []) {
109
110
  const inst = ctx.instanceById.get(instanceId);
110
111
  if (inst)
111
- cents += shiftCostCents(inst, employee.cost, ctx.rules.engagement);
112
+ cents += shiftCostCents(inst, employee.cost, (0, support_1.rulesFor)(ctx, employee.id).engagement);
112
113
  }
113
114
  cents += overtimeSurchargeCents(state.minutesByEmployee.get(employee.id) ?? 0, employee.cost);
114
115
  if (cents > 0)
@@ -19,10 +19,10 @@
19
19
  * gradient to climb out of an infeasible region; a 0/1 flag leaves it on a
20
20
  * plateau with nothing to follow.
21
21
  *
22
- * Aggregate constraints (`evaluate`) are deliberately not run per move — they
23
- * are O(roster) and the search calls the objective in its innermost loop. The
24
- * cheap aggregates that steer the search (coverage, fairness) have dedicated
25
- * terms here; the full `evaluate` pass runs once when the result is assembled.
22
+ * Built-in aggregates use dedicated scoring terms below. Custom `evaluate`
23
+ * hooks also contribute to the score, so extension rules can steer search.
24
+ * Their authors should keep these hooks cheap: they run for each candidate
25
+ * roster. All aggregate hooks run again during final validation.
26
26
  */
27
27
  import type { FairnessRule, ModelContext, SearchState } from '../types';
28
28
  export declare const UNFILLED_WEIGHT = 10000;
@@ -1 +1 @@
1
- {"version":3,"file":"objective.d.ts","sourceRoot":"","sources":["../../../src/scheduling/engine/objective.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAKxE,eAAO,MAAM,eAAe,QAAS,CAAC;AACtC,eAAO,MAAM,oBAAoB,OAAQ,CAAC;AAC1C,eAAO,MAAM,gBAAgB,MAAM,CAAC;AAC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F;AAED,kEAAkE;AAClE,wBAAgB,aAAa,CAAC,GAAG,EAAE,YAAY,EAAE,KAAK,EAAE,WAAW,GAAG,MAAM,CAI3E;AAED,2EAA2E;AAC3E,wBAAgB,aAAa,CAAC,GAAG,EAAE,YAAY,EAAE,KAAK,EAAE,WAAW,GAAG,MAAM,CAK3E;AAED,4DAA4D;AAC5D,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,YAAY,EAAE,KAAK,EAAE,WAAW,GAAG,MAAM,CAMhF;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,YAAY,EAAE,KAAK,EAAE,WAAW,GAAG,QAAQ,CAgB5E;AAED,qFAAqF;AACrF,wBAAgB,YAAY,CAAC,GAAG,EAAE,YAAY,EAAE,KAAK,EAAE,WAAW,GAAG,MAAM,CAE1E;AAED,kEAAkE;AAClE,wBAAgB,QAAQ,CACpB,GAAG,EAAE,YAAY,EACjB,KAAK,EAAE,WAAW,EAClB,SAAS,EAAE,UAAU,GAAG,UAAU,EAClC,cAAc,EAAE,MAAM,EACtB,aAAa,CAAC,EAAE,YAAY,EAAE,GAC/B,QAAQ,CA6BV;AAED;;;;;;;GAOG;AACH,wBAAgB,KAAK,CACjB,GAAG,EAAE,YAAY,EACjB,KAAK,EAAE,WAAW,EAClB,SAAS,EAAE,UAAU,GAAG,UAAU,EAClC,cAAc,EAAE,MAAM,GACvB,MAAM,CAGR"}
@@ -20,10 +20,10 @@
20
20
  * gradient to climb out of an infeasible region; a 0/1 flag leaves it on a
21
21
  * plateau with nothing to follow.
22
22
  *
23
- * Aggregate constraints (`evaluate`) are deliberately not run per move — they
24
- * are O(roster) and the search calls the objective in its innermost loop. The
25
- * cheap aggregates that steer the search (coverage, fairness) have dedicated
26
- * terms here; the full `evaluate` pass runs once when the result is assembled.
23
+ * Built-in aggregates use dedicated scoring terms below. Custom `evaluate`
24
+ * hooks also contribute to the score, so extension rules can steer search.
25
+ * Their authors should keep these hooks cheap: they run for each candidate
26
+ * roster. All aggregate hooks run again during final validation.
27
27
  */
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
29
  exports.score = exports.scoreLex = exports.softBreaches = exports.breachTotals = exports.minHoursShortfalls = exports.hoursVariance = exports.unfilledSlots = exports.tagShortage = exports.slotShortage = exports.isBetter = exports.compareScores = exports.DEFAULT_SOFT_WEIGHT = exports.MIN_HOURS_WEIGHT = exports.TAG_SHORTFALL_WEIGHT = exports.UNFILLED_WEIGHT = void 0;
@@ -136,6 +136,14 @@ exports.softBreaches = softBreaches;
136
136
  /** The full three-level score. Lower is better at every level. */
137
137
  function scoreLex(ctx, state, objective, minHoursWeight, fairnessRules) {
138
138
  const totals = breachTotals(ctx, state);
139
+ for (const constraint of ctx.aggregateConstraints ?? []) {
140
+ for (const violation of constraint.evaluate?.(state) ?? []) {
141
+ const magnitude = violation.actual !== undefined && violation.required !== undefined
142
+ ? Math.max(1, Math.abs(violation.actual - violation.required))
143
+ : 1;
144
+ totals[violation.severity] += magnitude * (constraint.weight ?? exports.DEFAULT_SOFT_WEIGHT);
145
+ }
146
+ }
139
147
  for (const inst of ctx.instances) {
140
148
  totals.medium += slotShortage(ctx, state, inst.id) * exports.UNFILLED_WEIGHT;
141
149
  totals.medium += tagShortage(ctx, state, inst.id) * exports.TAG_SHORTFALL_WEIGHT;
@@ -15,7 +15,8 @@ function propagate(ctx) {
15
15
  eligibility.set(emp.id, new Set(ctx.instances.map((i) => i.id)));
16
16
  }
17
17
  for (const constraint of ctx.constraints) {
18
- constraint.prune?.(ctx, eligibility);
18
+ if (constraint.hardness === 'hard')
19
+ constraint.prune?.(ctx, eligibility);
19
20
  }
20
21
  const eligibleByInstance = new Map();
21
22
  for (const inst of ctx.instances)
@@ -29,6 +29,7 @@ export interface SearchOptions {
29
29
  objective: 'standard' | 'balanced';
30
30
  minHoursWeight: number;
31
31
  timeBudgetMs: number;
32
+ maxIterations?: number;
32
33
  rand: () => number;
33
34
  now?: () => number;
34
35
  /** Late-acceptance history length. Larger accepts more drift. */
@@ -1 +1 @@
1
- {"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../../src/scheduling/engine/search.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAEvD,OAAO,EAAgE,KAAK,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC1G,OAAO,EAAmC,KAAK,aAAa,EAAE,MAAM,SAAS,CAAC;AAG9E,MAAM,WAAW,aAAa;IAC1B,SAAS,EAAE,UAAU,GAAG,UAAU,CAAC;IACnC,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,MAAM,MAAM,CAAC;IACnB,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;IACnB,iEAAiE;IACjE,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,kEAAkE;IAClE,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE,QAAQ,KAAK,IAAI,CAAC;CACnE;AAED,MAAM,WAAW,aAAa;IAC1B,IAAI,EAAE,aAAa,CAAC;IACpB,iBAAiB,EAAE,MAAM,CAAC;CAC7B;AAiCD;;;;;GAKG;AACH,wBAAgB,cAAc,CAC1B,GAAG,EAAE,YAAY,EACjB,KAAK,EAAE,aAAa,EACpB,WAAW,EAAE,iBAAiB,EAC9B,OAAO,EAAE,aAAa,EACtB,gBAAgB,EAAE,MAAM,aAAa,GACtC,aAAa,CA4Ef"}
1
+ {"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../../src/scheduling/engine/search.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAEvD,OAAO,EAAgE,KAAK,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC1G,OAAO,EAAmC,KAAK,aAAa,EAAE,MAAM,SAAS,CAAC;AAG9E,MAAM,WAAW,aAAa;IAC1B,SAAS,EAAE,UAAU,GAAG,UAAU,CAAC;IACnC,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,IAAI,EAAE,MAAM,MAAM,CAAC;IACnB,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;IACnB,iEAAiE;IACjE,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,kEAAkE;IAClE,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE,QAAQ,KAAK,IAAI,CAAC;CACnE;AAED,MAAM,WAAW,aAAa;IAC1B,IAAI,EAAE,aAAa,CAAC;IACpB,iBAAiB,EAAE,MAAM,CAAC;CAC7B;AAiCD;;;;;GAKG;AACH,wBAAgB,cAAc,CAC1B,GAAG,EAAE,YAAY,EACjB,KAAK,EAAE,aAAa,EACpB,WAAW,EAAE,iBAAiB,EAC9B,OAAO,EAAE,aAAa,EACtB,gBAAgB,EAAE,MAAM,aAAa,GACtC,aAAa,CA4Ef"}
@@ -71,7 +71,7 @@ function improveWithLns(ctx, state, propagation, options, createEmptyState) {
71
71
  const historyLength = Math.max(1, options.historyLength ?? DEFAULT_HISTORY_LENGTH);
72
72
  const history = new Array(historyLength).fill(workingScore);
73
73
  let iteration = 0;
74
- while (now() < deadline) {
74
+ while (now() < deadline && iteration < (options.maxIterations ?? Infinity)) {
75
75
  const total = (0, state_1.assignedPairs)(working).length;
76
76
  if (total === 0)
77
77
  break;
@@ -1 +1 @@
1
- {"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../../src/scheduling/engine/state.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK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AM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAEtE;AAED,wBAAgB,MAAM,CAAC,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,CAuB5G;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI,CAY3F;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAE9E;AAED,yFAAyF;AACzF,wBAAgB,aAAa,CAAC,KAAK,EAAE,aAAa,GAAG,KAAK,CAAC;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAAC,CAQrG"}
@@ -44,6 +44,8 @@ function assign(state, employeeId, instanceId, reasons) {
44
44
  // employee the model never saw would corrupt the fairness and cost sums.
45
45
  if (!inst || !state.ctx.employeeById.has(employeeId))
46
46
  return;
47
+ if (state.isAssigned(employeeId, instanceId))
48
+ return;
47
49
  state.assignments.get(instanceId)?.add(employeeId);
48
50
  state.byEmployee.get(employeeId)?.add(instanceId);
49
51
  // `minutesByEmployee` tracks *working* time, which unpaid breaks and duty
@@ -65,6 +67,8 @@ function unassign(state, employeeId, instanceId) {
65
67
  const inst = state.ctx.instanceById.get(instanceId);
66
68
  if (!inst || !state.ctx.employeeById.has(employeeId))
67
69
  return;
70
+ if (!state.isAssigned(employeeId, instanceId))
71
+ return;
68
72
  state.assignments.get(instanceId)?.delete(employeeId);
69
73
  state.byEmployee.get(employeeId)?.delete(instanceId);
70
74
  state.minutesByEmployee.set(employeeId, (state.minutesByEmployee.get(employeeId) ?? 0) - inst.workingMinutes);
@@ -52,7 +52,7 @@ export declare function expandTemplate(template: ShiftTemplate, clock: PeriodClo
52
52
  */
53
53
  export declare function mergeRules(base: WorkingTimeRules | undefined, override: WorkingTimeRules | undefined): WorkingTimeRules;
54
54
  /** Resolve built-in constraints with caller hardness/weight overrides, then append customs. */
55
- export declare function resolveConstraints(options: ConstraintOptions | undefined, rules?: WorkingTimeRules, objectives?: ObjectiveWeights): SchedulingConstraint[];
55
+ export declare function resolveConstraints(options: ConstraintOptions | undefined, rules?: WorkingTimeRules, objectives?: ObjectiveWeights, employeeRules?: Map<string, WorkingTimeRules>): SchedulingConstraint[];
56
56
  /**
57
57
  * Normalize and validate the scheduling problem. Throws
58
58
  * `ScheduleValidationError` on malformed input — never a silent wrong schedule.
@@ -1 +1 @@
1
- {"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../src/scheduling/model.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,KAAK,EAER,gBAAgB,EAChB,iBAAiB,EAGjB,YAAY,EACZ,gBAAgB,EAChB,aAAa,EACb,oBAAoB,EACpB,aAAa,EACb,aAAa,EACb,gBAAgB,EACnB,MAAM,SAAS,CAAC;AAQjB,OAAO,EAAE,WAAW,EAAE,eAAe,EAAmE,MAAM,QAAQ,CAAC;AAEvH,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAE9C;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,aAAa,GAAG,aAAa,EAAE,CAqB1E;AAED,sEAAsE;AACtE,wBAAgB,cAAc,CAC1B,QAAQ,EAAE,aAAa,EACvB,KAAK,EAAE,WAAW,EAClB,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE;IAAE,SAAS,CAAC,EAAE,gBAAgB,CAAC,WAAW,CAAC,CAAC;IAAC,cAAc,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;CAAE,GACpF,aAAa,EAAE,CAgHjB;AAyND;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,gBAAgB,GAAG,SAAS,EAAE,QAAQ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AAU,CAAC,IAAI,EAAE,gBAAgB,GAAG,SAAS,EAAE,QAAQ,EAAE,gBAAgB,GAAG,SAAS,GAAG,gBAAgB,CAIvH;AAED,+FAA+F;AAC/F,wBAAgB,kBAAkB,CAC9B,OAAO,EAAE,iBAAiB,GAAG,SAAS,EACtC,KAAK,CAAC,EAAE,gBAAgB,EACxB,UAAU,CAAC,EAAE,gBAAgB,EAC7B,aAAa,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,gBAAgB,CAAC,GAC9C,oBAAoB,EAAE,CAwBxB;AAiCD;;;GAGG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,aAAa,GAAG,YAAY,CAuI7D;AAED,gEAAgE;AAChE,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,gBAAgB,EAAE,IAAI,EAAE,aAAa,GAAG,OAAO,CAKxF;AAED,OAAO,EAAE,eAAe,EAAE,CAAC"}
@@ -29,6 +29,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
29
29
  exports.MINUTES_PER_DAY = exports.availabilityApplies = exports.buildModel = exports.resolveConstraints = exports.mergeRules = exports.expandTemplate = exports.expandShiftInstances = exports.addDays = exports.daysBetween = void 0;
30
30
  const types_1 = require("./types");
31
31
  const constraint_1 = require("./constraints/constraint");
32
+ const employee_scope_1 = require("./constraints/employee-scope");
32
33
  const min_rest_1 = require("./constraints/min-rest");
33
34
  const overtime_1 = require("./constraints/overtime");
34
35
  const contract_hours_1 = require("./contract-hours");
@@ -141,11 +142,11 @@ function expandTemplate(template, clock, periodDays, context) {
141
142
  throw new types_1.ScheduleValidationError(`Shift template "${template.id}" resolves to a non-positive duration on ${date}`);
142
143
  }
143
144
  const unpaidBreak = template.unpaidBreakMinutes ?? 0;
144
- if (unpaidBreak < 0 || unpaidBreak >= durationMinutes) {
145
+ if (!Number.isFinite(unpaidBreak) || unpaidBreak < 0 || unpaidBreak >= durationMinutes) {
145
146
  throw new types_1.ScheduleValidationError(`Shift template "${template.id}" has invalid unpaidBreakMinutes`);
146
147
  }
147
148
  const paidBreak = template.paidBreakMinutes ?? 0;
148
- if (paidBreak < 0 || unpaidBreak + paidBreak >= durationMinutes) {
149
+ if (!Number.isFinite(paidBreak) || paidBreak < 0 || unpaidBreak + paidBreak >= durationMinutes) {
149
150
  throw new types_1.ScheduleValidationError(`Shift template "${template.id}" has invalid paidBreakMinutes`);
150
151
  }
151
152
  // A paid break counts as working time, so only the unpaid one is deducted.
@@ -319,9 +320,12 @@ function blockedIntervalsFor(employee, clock, periodDays, instanceById) {
319
320
  continue;
320
321
  }
321
322
  const offset = clock.dayIndexOf(entry.date);
322
- if (offset < 0 || offset >= periodDays)
323
- continue; // outside the period: irrelevant, not an error
324
- out.push({ start: clock.dayStartMinutes(offset), end: clock.dayStartMinutes(offset + 1) });
323
+ const blocked = { start: clock.dayStartMinutes(offset), end: clock.dayStartMinutes(offset + 1) };
324
+ if (offset < 0 || offset >= periodDays) {
325
+ if (![...instanceById.values()].some((inst) => inst.startMinute < blocked.end && blocked.start < inst.endMinute))
326
+ continue;
327
+ }
328
+ out.push(blocked);
325
329
  }
326
330
  // External commitments are blackouts the roster may never override
327
331
  // (Directive (EU) 2019/1152 Art 9 bars treating parallel employment as
@@ -333,15 +337,11 @@ function blockedIntervalsFor(employee, clock, periodDays, instanceById) {
333
337
  }
334
338
  /** Resolve an ISO date or date-time span to period minutes. */
335
339
  function spanToMinutes(from, to, clock, field) {
336
- const parse = (value, endOfDayWhenBare) => {
337
- const [datePart, timePart] = value.split('T');
338
- (0, time_1.assertIsoDate)(datePart, field);
339
- if (timePart)
340
- return clock.toPeriodMinutes(datePart, timePart.slice(0, 5), field);
341
- const dayIndex = clock.dayIndexOf(datePart);
342
- return endOfDayWhenBare ? clock.dayStartMinutes(dayIndex + 1) : clock.dayStartMinutes(dayIndex);
343
- };
344
- return { start: parse(from, false), end: parse(to, true) };
340
+ const start = clock.parseDateTime(from, `${field}.from`);
341
+ const end = clock.parseDateTime(to, `${field}.to`, true);
342
+ if (end <= start)
343
+ throw new types_1.ScheduleValidationError(`${field}: to must follow from`);
344
+ return { start, end };
345
345
  }
346
346
  function validateEmployee(employee) {
347
347
  if (!employee.id)
@@ -404,20 +404,30 @@ function mergeRules(base, override) {
404
404
  }
405
405
  exports.mergeRules = mergeRules;
406
406
  /** Resolve built-in constraints with caller hardness/weight overrides, then append customs. */
407
- function resolveConstraints(options, rules, objectives) {
408
- const constraints = (0, constraint_1.createDefaultConstraints)({
407
+ function resolveConstraints(options, rules, objectives, employeeRules) {
408
+ const defaults = {
409
409
  minRestMinutes: options?.minRestMinutes ?? rules?.dailyRest?.minMinutes ?? min_rest_1.DEFAULT_MIN_REST_MINUTES,
410
410
  oneShiftPerDay: options?.oneShiftPerDay ?? false,
411
411
  rules,
412
412
  objectives,
413
- });
413
+ };
414
+ const constraints = employeeRules
415
+ ? (0, employee_scope_1.scopeEmployeeConstraints)(defaults, employeeRules)
416
+ : (0, constraint_1.createDefaultConstraints)(defaults);
414
417
  const overrides = options?.overrides ?? {};
415
418
  for (const c of constraints) {
416
419
  const o = overrides[c.id];
417
420
  if (!o)
418
421
  continue;
419
- if (o.hardness !== undefined)
422
+ if (o.hardness !== undefined) {
420
423
  c.hardness = o.hardness;
424
+ const verdict = c.verdict?.bind(c);
425
+ if (verdict)
426
+ c.verdict = (state, pair) => ({ ...verdict(state, pair), severity: o.hardness });
427
+ const evaluate = c.evaluate?.bind(c);
428
+ if (evaluate)
429
+ c.evaluate = (state) => evaluate(state).map((v) => ({ ...v, severity: o.hardness }));
430
+ }
421
431
  if (o.weight !== undefined)
422
432
  c.weight = o.weight;
423
433
  }
@@ -456,6 +466,15 @@ function buildHistory(history, clock, personIdOf) {
456
466
  function buildModel(input) {
457
467
  (0, time_1.assertIsoDate)(input.period.startDate, 'period.startDate');
458
468
  (0, time_1.assertIsoDate)(input.period.endDate, 'period.endDate');
469
+ for (const [name, value] of [
470
+ ['timeBudgetMs', input.timeBudgetMs],
471
+ ['maxIterations', input.maxIterations],
472
+ ]) {
473
+ if (value !== undefined &&
474
+ (!Number.isFinite(value) || value < 0 || (name === 'maxIterations' && !Number.isInteger(value)))) {
475
+ throw new types_1.ScheduleValidationError(`${name} must be a finite non-negative ${name === 'maxIterations' ? 'integer' : 'number'}`);
476
+ }
477
+ }
459
478
  const periodDays = (0, time_1.daysBetween)(input.period.startDate, input.period.endDate) + 1;
460
479
  if (periodDays <= 0)
461
480
  throw new types_1.ScheduleValidationError('period.endDate must not precede period.startDate');
@@ -525,6 +544,8 @@ function buildModel(input) {
525
544
  }
526
545
  const absences = new Map();
527
546
  for (const absence of input.absences ?? []) {
547
+ if (!employeeById.has(absence.employeeId))
548
+ throw new types_1.ScheduleValidationError(`Unknown absence employee "${absence.employeeId}"`);
528
549
  const span = spanToMinutes(absence.from, absence.to, clock, 'absences');
529
550
  absences.set(absence.employeeId, [...(absences.get(absence.employeeId) ?? []), { ...span, kind: absence.kind }]);
530
551
  // An absence blocks assignment as firmly as time off does.
@@ -537,18 +558,10 @@ function buildModel(input) {
537
558
  publishedPairs.add(`${assignment.employeeId}|${assignment.shiftInstanceId}`);
538
559
  }
539
560
  const pinned = new Set((input.pinned ?? []).map((p) => `${p.employeeId}|${p.shiftInstanceId}`));
540
- let publishedAtMinute;
541
- if (input.published?.publishedAt) {
542
- const [datePart, timePart] = input.published.publishedAt.split('T');
543
- (0, time_1.assertIsoDate)(datePart, 'published.publishedAt');
544
- publishedAtMinute = clock.toPeriodMinutes(datePart, (timePart ?? '00:00').slice(0, 5), 'published.publishedAt');
545
- }
546
- let asOfMinute;
547
- if (input.asOf) {
548
- const [datePart, timePart] = input.asOf.split('T');
549
- (0, time_1.assertIsoDate)(datePart, 'asOf');
550
- asOfMinute = clock.toPeriodMinutes(datePart, (timePart ?? '00:00').slice(0, 5), 'asOf');
551
- }
561
+ const publishedAtMinute = input.published?.publishedAt === undefined
562
+ ? undefined
563
+ : clock.parseDateTime(input.published.publishedAt, 'published.publishedAt');
564
+ const asOfMinute = input.asOf === undefined ? undefined : clock.parseDateTime(input.asOf, 'asOf');
552
565
  return {
553
566
  periodStartDate: input.period.startDate,
554
567
  periodDays,
@@ -560,7 +573,8 @@ function buildModel(input) {
560
573
  siteIndex,
561
574
  employeeBlockedIntervals,
562
575
  minRestMinutes: input.constraints?.minRestMinutes ?? rules.dailyRest?.minMinutes ?? min_rest_1.DEFAULT_MIN_REST_MINUTES,
563
- constraints: resolveConstraints(input.constraints, rules, input.objectives),
576
+ aggregateConstraints: input.constraints?.custom?.filter((c) => c.evaluate) ?? [],
577
+ constraints: resolveConstraints(input.constraints, rules, input.objectives, rulesByEmployee),
564
578
  clock,
565
579
  rules,
566
580
  rulesByEmployee,
@@ -20,6 +20,10 @@
20
20
  import type { AssignmentPair, ConstraintViolation, LedgerEntry, RuleVerdict, ScheduleInput, ScheduledAssignment, ContractHoursSummary } from './types';
21
21
  export interface ComplianceReport {
22
22
  compliant: boolean;
23
+ /** Whether all headcount and skill coverage requirements are met. */
24
+ coverageComplete: boolean;
25
+ /** A fully covered roster with no hard breaches. */
26
+ publishable: boolean;
23
27
  violations: ConstraintViolation[];
24
28
  /** Per-assignment verdicts for every rule that had something to say. */
25
29
  verdicts: Array<{
@@ -1 +1 @@
1
- {"version":3,"file":"operations.d.ts","sourceRoot":"","sources":["../../src/scheduling/operations.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EACR,cAAc,EACd,mBAAmB,EACnB,WAAW,EACX,WAAW,EACX,aAAa,EACb,mBAAmB,EAEnB,oBAAoB,EACvB,MAAM,SAAS,CAAC;AA0BjB,MAAM,WAAW,gBAAgB;IAC7B,SAAS,EAAE,OAAO,CAAC;IACnB,UAAU,EAAE,mBAAmB,EAAE,CAAC;IAClC,wEAAwE;IACxE,QAAQ,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,cAAc,CAAC;QAAC,QAAQ,EAAE,WAAW,EAAE,CAAA;KAAE,CAAC,CAAC;IACnE;;;;;OAKG;I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FnB;AAwKD,MAAM,WAAW,mBAAmB;IAChC,QAAQ,EAAE,OAAO,CAAC;IAClB,QAAQ,EAAE,KAAK,CAAC;QACZ,IAAI,EAAE,oBAAoB,GAAG,sBAAsB,GAAG,aAAa,CAAC;QACpE,OAAO,EAAE,MAAM,CAAC;QAChB,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,SAAS,CAAC,EAAE,MAAM,CAAC;KACtB,CAAC,CAAC;CACN;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,aAAa,GAAG,mBAAmB,CAmD/E"}
@@ -20,6 +20,10 @@
20
20
  */
21
21
  Object.defineProperty(exports, "__esModule", { value: true });
22
22
  exports.diagnoseInfeasibility = exports.rankCandidates = exports.repairSchedule = exports.explainCandidate = exports.checkCompliance = void 0;
23
+ const support_1 = require("./constraints/support");
24
+ const min_staffing_1 = require("./constraints/min-staffing");
25
+ const hour_budget_1 = require("./constraints/hour-budget");
26
+ const objective_1 = require("./engine/objective");
23
27
  const model_1 = require("./model");
24
28
  const propagation_1 = require("./engine/propagation");
25
29
  const state_1 = require("./engine/state");
@@ -69,6 +73,16 @@ function checkCompliance(input, roster) {
69
73
  });
70
74
  continue;
71
75
  }
76
+ if (state.isAssigned(entry.employeeId, entry.shiftInstanceId)) {
77
+ violations.push({
78
+ constraintId: 'input',
79
+ severity: 'hard',
80
+ employeeId: entry.employeeId,
81
+ shiftInstanceId: entry.shiftInstanceId,
82
+ message: 'roster contains a duplicate assignment',
83
+ });
84
+ continue;
85
+ }
72
86
  (0, state_1.assign)(state, entry.employeeId, entry.shiftInstanceId, entry.reasons ?? []);
73
87
  }
74
88
  // The same two passes the solver runs when it assembles its result.
@@ -80,6 +94,8 @@ function checkCompliance(input, roster) {
80
94
  }
81
95
  }
82
96
  violations.push(...(0, verdicts_1.collectPairViolations)(state), ...(0, verdicts_1.collectAggregateViolations)(state));
97
+ const staffing = (0, min_staffing_1.staffingViolations)(ctx, state, 'medium');
98
+ violations.push(...staffing, ...(0, hour_budget_1.minHourViolations)(ctx, state, ctx.constraints.find((c) => c.id === 'hour-budget')?.weight ?? objective_1.MIN_HOURS_WEIGHT));
83
99
  // The same ledger pass the solver runs at result assembly — one judgement
84
100
  // path, so `checkCompliance` can never disagree with `solveSchedule`
85
101
  // about what a roster owes.
@@ -91,6 +107,8 @@ function checkCompliance(input, roster) {
91
107
  ];
92
108
  return {
93
109
  compliant: violations.every((v) => v.severity !== 'hard'),
110
+ coverageComplete: staffing.length === 0,
111
+ publishable: staffing.length === 0 && violations.every((v) => v.severity !== 'hard'),
94
112
  violations,
95
113
  verdicts,
96
114
  ledger,
@@ -136,8 +154,12 @@ exports.explainCandidate = explainCandidate;
136
154
  * single name.
137
155
  */
138
156
  function repairSchedule(input, disruption, published) {
139
- const openings = openingsFor(disruption, published);
140
- const surviving = published.filter((entry) => !isDropped(entry, disruption));
157
+ const ctx = (0, model_1.buildModel)(input);
158
+ const dropped = (entry) => isDropped(entry, disruption, ctx);
159
+ const openings = disruption.kind === 'cancelShift'
160
+ ? []
161
+ : [...new Set(published.filter(dropped).map((entry) => entry.shiftInstanceId))];
162
+ const surviving = published.filter((entry) => !dropped(entry));
141
163
  // Re-solve with the untouched roster pinned. Only the openings are free.
142
164
  const repaired = (0, scheduler_class_1.solveSchedule)({
143
165
  ...applyDisruption(input, disruption),
@@ -197,7 +219,7 @@ function rankCandidates(input, shiftInstanceId, roster, disruption) {
197
219
  const eligible = blockers.length === 0 && (0, construction_1.hardCompliant)(ctx, state, employee.id, shiftInstanceId);
198
220
  // Marginal against what this person already holds: the same shift is
199
221
  // dearer in the hands of someone past their overtime threshold.
200
- const costCents = (0, cost_1.marginalCostCents)(inst, employee, state.minutesByEmployee.get(employee.id) ?? 0, ctx.rules.engagement);
222
+ const costCents = (0, cost_1.marginalCostCents)(inst, employee, state.minutesByEmployee.get(employee.id) ?? 0, (0, support_1.rulesFor)(ctx, employee.id).engagement);
201
223
  const fairnessDebt = meanExtra - (extraLoad.get(employee.id) ?? 0);
202
224
  const preference = (0, availability_1.preferenceScore)(ctx.clock, employee.availability, inst);
203
225
  const originSiteId = originSiteFor(state, employee.id, inst);
@@ -300,22 +322,20 @@ function extraShiftCounts(state) {
300
322
  function average(values) {
301
323
  return values.length === 0 ? 0 : values.reduce((a, b) => a + b, 0) / values.length;
302
324
  }
303
- function openingsFor(disruption, published) {
304
- switch (disruption.kind) {
305
- case 'noShow':
306
- return [disruption.shiftInstanceId];
307
- case 'absence':
308
- return published.filter((e) => e.employeeId === disruption.employeeId).map((e) => e.shiftInstanceId);
309
- case 'cancelShift':
310
- return [];
311
- }
312
- }
313
- function isDropped(entry, disruption) {
325
+ function isDropped(entry, disruption, ctx) {
314
326
  switch (disruption.kind) {
315
327
  case 'noShow':
316
328
  return entry.employeeId === disruption.employeeId && entry.shiftInstanceId === disruption.shiftInstanceId;
317
- case 'absence':
318
- return entry.employeeId === disruption.employeeId;
329
+ case 'absence': {
330
+ if (entry.employeeId !== disruption.employeeId)
331
+ return false;
332
+ const inst = ctx.instanceById.get(entry.shiftInstanceId);
333
+ if (!inst)
334
+ return false;
335
+ const start = ctx.clock.parseDateTime(disruption.from, 'disruption.from');
336
+ const end = ctx.clock.parseDateTime(disruption.to ?? ctx.clock.dateAt(ctx.periodDays - 1), 'disruption.to', true);
337
+ return inst.startMinute < end && start < inst.endMinute;
338
+ }
319
339
  case 'cancelShift':
320
340
  return entry.shiftInstanceId === disruption.shiftInstanceId;
321
341
  }
@@ -19,7 +19,7 @@ import type { ConstraintOptions, ObjectiveWeights, Site, WorkingTimeRules } from
19
19
  * in property order produce the same digest — otherwise a round-trip through
20
20
  * JSON would look like a rule change.
21
21
  */
22
- export declare function hashRules(rules: WorkingTimeRules | undefined, options: ConstraintOptions | undefined, objectives?: ObjectiveWeights, sites?: Site[], travelSpeedKmh?: number): string;
22
+ export declare function hashRules(rules: WorkingTimeRules | undefined, options: ConstraintOptions | undefined, objectives?: ObjectiveWeights, sites?: Site[], travelSpeedKmh?: number, employeeRules?: Map<string, WorkingTimeRules>): string;
23
23
  /** JSON with object keys sorted recursively. */
24
24
  export declare function stableStringify(value: unknown): string;
25
25
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"provenance.d.ts","sourceRoot":"","sources":["../../src/scheduling/provenance.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,IAAI,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAE3F;;;;;;GAMG;AACH,wBAAgB,SAAS,CACrB,KAAK,EAAE,gBAAgB,GAAG,SAAS,EACnC,OAAO,EAAE,iBAAiB,GAAG,SAAS,EACtC,UAAU,CAAC,EAAE,gBAAgB,EAC7B,KAAK,CAAC,EAAE,IAAI,EAAE,EACd,cAAc,CAAC,EAAE,MAAM,GACxB,MAAM,CAgBR;AAaD,gDAAgD;AAChD,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAOtD;AAED;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAY7C"}
1
+ {"version":3,"file":"provenance.d.ts","sourceRoot":"","sources":["../../src/scheduling/provenance.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,IAAI,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAE3F;;;;;;GAMG;AACH,wBAAgB,SAAS,CACrB,KAAK,EAAE,gBAAgB,GAAG,SAAS,EACnC,OAAO,EAAE,iBAAiB,GAAG,SAAS,EACtC,UAAU,CAAC,EAAE,gBAAgB,EAC7B,KAAK,CAAC,EAAE,IAAI,EAAE,EACd,cAAc,CAAC,EAAE,MAAM,EACvB,aAAa,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,gBAAgB,CAAC,GAC9C,MAAM,CA8BR;AAaD,gDAAgD;AAChD,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAOtD;AAED;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAY7C"}
@@ -21,15 +21,29 @@ exports.fnv1a64 = exports.stableStringify = exports.hashRules = void 0;
21
21
  * in property order produce the same digest — otherwise a round-trip through
22
22
  * JSON would look like a rule change.
23
23
  */
24
- function hashRules(rules, options, objectives, sites, travelSpeedKmh) {
24
+ function hashRules(rules, options, objectives, sites, travelSpeedKmh, employeeRules) {
25
+ // Only the employees whose effective rules actually differ from the global
26
+ // set. `rulesByEmployee` carries an entry for *every* employee, so hashing
27
+ // it whole would make the digest move when a person is added or renamed —
28
+ // and `rulesHash` is a configuration fingerprint, not a roster one.
29
+ const globalDigest = stableStringify(rules ?? {});
30
+ const personalRules = [...(employeeRules ?? [])]
31
+ .filter(([, effective]) => stableStringify(effective) !== globalDigest)
32
+ .sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0));
25
33
  const payload = stableStringify({
26
34
  rules: rules ?? null,
35
+ ...(personalRules.length > 0 ? { employeeRules: personalRules } : {}),
27
36
  // Only the parts of `constraints` that change outcomes: custom rules are
28
37
  // functions and cannot be hashed, so their ids stand in for them.
29
38
  minRestMinutes: options?.minRestMinutes ?? null,
30
39
  oneShiftPerDay: options?.oneShiftPerDay ?? null,
31
40
  overrides: options?.overrides ?? null,
32
- custom: (options?.custom ?? []).map((c) => ({ id: c.id, hardness: c.hardness, weight: c.weight ?? null })),
41
+ custom: (options?.custom ?? []).map((c) => ({
42
+ id: c.id,
43
+ hardness: c.hardness,
44
+ weight: c.weight ?? null,
45
+ ...(c.version === undefined ? {} : { version: c.version }),
46
+ })),
33
47
  objectives: objectives ?? null,
34
48
  // Omit these keys entirely when absent so existing inputs without site data
35
49
  // keep the same rulesHash they had before this feature existed.
@@ -12,7 +12,7 @@
12
12
  * a proof of optimality.
13
13
  */
14
14
  import type { ScheduleInput, ScheduleResult } from './types';
15
- export declare const ENGINE_VERSION = "2";
15
+ export declare const ENGINE_VERSION = "3";
16
16
  export declare class ShiftScheduler {
17
17
  /** Solve a scheduling problem synchronously. Throws `ScheduleValidationError` on malformed input. */
18
18
  solve(input: ScheduleInput): ScheduleResult;
@@ -1 +1 @@
1
- {"version":3,"file":"scheduler.class.d.ts","sourceRoot":"","sources":["../../src/scheduling/scheduler.class.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAoC,aAAa,EAAE,cAAc,EAAuB,MAAM,SAAS,CAAC;AAsBpH,eAAO,MAAM,cAAc,MAAM,CAAC;AAElC,qBAAa,cAAc;IACvB,qGAAqG;IACrG,KAAK,CAAC,KAAK,EAAE,aAAa,GAAG,cAAc;IA+C3C,qFAAqF;IACrF,OAAO,CAAC,QAAQ;CA8EnB;AAUD,+EAA+E;AAC/E,wBAAgB,aAAa,CAAC,KAAK,EAAE,aAAa,GAAG,cAAc,CAElE"}
1
+ {"version":3,"file":"scheduler.class.d.ts","sourceRoot":"","sources":["../../src/scheduling/scheduler.class.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAoC,aAAa,EAAE,cAAc,EAAuB,MAAM,SAAS,CAAC;AAsBpH,eAAO,MAAM,cAAc,MAAM,CAAC;AAElC,qBAAa,cAAc;IACvB,qGAAqG;IACrG,KAAK,CAAC,KAAK,EAAE,aAAa,GAAG,cAAc;IAgD3C,qFAAqF;IACrF,OAAO,CAAC,QAAQ;CAsFnB;AAUD,+EAA+E;AAC/E,wBAAgB,aAAa,CAAC,KAAK,EAAE,aAAa,GAAG,cAAc,CAElE"}