assignment-user-matcher 1.16.0 → 1.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +312 -20
- package/dist/escalation/policy.d.ts +11 -0
- package/dist/escalation/policy.d.ts.map +1 -1
- package/dist/escalation/policy.js +22 -1
- package/dist/forecasting/backtest.d.ts +52 -0
- package/dist/forecasting/backtest.d.ts.map +1 -0
- package/dist/forecasting/backtest.js +195 -0
- package/dist/forecasting/calendar.d.ts +44 -0
- package/dist/forecasting/calendar.d.ts.map +1 -0
- package/dist/forecasting/calendar.js +85 -0
- package/dist/forecasting/cover.d.ts +69 -0
- package/dist/forecasting/cover.d.ts.map +1 -0
- package/dist/forecasting/cover.js +103 -0
- package/dist/forecasting/days.d.ts +17 -0
- package/dist/forecasting/days.d.ts.map +1 -0
- package/dist/forecasting/days.js +35 -0
- package/dist/forecasting/distributions.d.ts +31 -0
- package/dist/forecasting/distributions.d.ts.map +1 -0
- package/dist/forecasting/distributions.js +154 -0
- package/dist/forecasting/effects.d.ts +88 -0
- package/dist/forecasting/effects.d.ts.map +1 -0
- package/dist/forecasting/effects.js +303 -0
- package/dist/forecasting/erlang.d.ts +31 -0
- package/dist/forecasting/erlang.d.ts.map +1 -0
- package/dist/forecasting/erlang.js +86 -0
- package/dist/forecasting/forecast.d.ts +7 -0
- package/dist/forecasting/forecast.d.ts.map +1 -0
- package/dist/forecasting/forecast.js +221 -0
- package/dist/forecasting/index.d.ts +18 -0
- package/dist/forecasting/index.d.ts.map +1 -0
- package/dist/forecasting/index.js +54 -0
- package/dist/forecasting/model.d.ts +145 -0
- package/dist/forecasting/model.d.ts.map +1 -0
- package/dist/forecasting/model.js +583 -0
- package/dist/forecasting/nowcast.d.ts +26 -0
- package/dist/forecasting/nowcast.d.ts.map +1 -0
- package/dist/forecasting/nowcast.js +92 -0
- package/dist/forecasting/simulation.d.ts +91 -0
- package/dist/forecasting/simulation.d.ts.map +1 -0
- package/dist/forecasting/simulation.js +478 -0
- package/dist/forecasting/spikes.d.ts +6 -0
- package/dist/forecasting/spikes.d.ts.map +1 -0
- package/dist/forecasting/spikes.js +73 -0
- package/dist/forecasting/staffing.d.ts +64 -0
- package/dist/forecasting/staffing.d.ts.map +1 -0
- package/dist/forecasting/staffing.js +765 -0
- package/dist/forecasting/stats.d.ts +11 -0
- package/dist/forecasting/stats.d.ts.map +1 -0
- package/dist/forecasting/stats.js +45 -0
- package/dist/forecasting/types.d.ts +299 -0
- package/dist/forecasting/types.d.ts.map +1 -0
- package/dist/forecasting/types.js +8 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -1
- package/dist/learning/auto-weights.d.ts +1 -5
- package/dist/learning/auto-weights.d.ts.map +1 -1
- package/dist/learning/auto-weights.js +0 -3
- package/dist/lua/book-slot.lua +84 -0
- package/dist/lua/claim-queued.lua +47 -0
- package/dist/managers/DecisionTraceManager.d.ts +15 -0
- package/dist/managers/DecisionTraceManager.d.ts.map +1 -1
- package/dist/managers/DecisionTraceManager.js +117 -11
- package/dist/managers/LearningManager.d.ts +12 -0
- package/dist/managers/LearningManager.d.ts.map +1 -1
- package/dist/managers/LearningManager.js +21 -7
- package/dist/managers/ReliabilityManager.d.ts +1 -2
- package/dist/managers/ReliabilityManager.d.ts.map +1 -1
- package/dist/managers/ReliabilityManager.js +1 -1
- package/dist/managers/TelemetryManager.d.ts.map +1 -1
- package/dist/managers/TelemetryManager.js +9 -3
- package/dist/managers/WorkflowManager.d.ts.map +1 -1
- package/dist/managers/WorkflowManager.js +3 -4
- package/dist/matcher.class.d.ts +319 -4
- package/dist/matcher.class.d.ts.map +1 -1
- package/dist/matcher.class.js +1428 -102
- package/dist/queries/lane-stats.d.ts +51 -0
- package/dist/queries/lane-stats.d.ts.map +1 -0
- package/dist/queries/lane-stats.js +78 -0
- package/dist/schedule/recurrence.d.ts +11 -0
- package/dist/schedule/recurrence.d.ts.map +1 -1
- package/dist/schedule/recurrence.js +19 -2
- package/dist/schedule/slot.d.ts +60 -0
- package/dist/schedule/slot.d.ts.map +1 -0
- package/dist/schedule/slot.js +86 -0
- package/dist/scheduling/constraints/availability.d.ts +2 -14
- package/dist/scheduling/constraints/availability.d.ts.map +1 -1
- package/dist/scheduling/constraints/availability.js +14 -15
- package/dist/scheduling/constraints/consecutive.d.ts +10 -0
- package/dist/scheduling/constraints/consecutive.d.ts.map +1 -1
- package/dist/scheduling/constraints/consecutive.js +64 -1
- package/dist/scheduling/constraints/contract.d.ts.map +1 -1
- package/dist/scheduling/constraints/contract.js +12 -3
- package/dist/scheduling/constraints/employee-scope.d.ts.map +1 -1
- package/dist/scheduling/constraints/employee-scope.js +10 -2
- package/dist/scheduling/constraints/group-composition.js +2 -2
- package/dist/scheduling/constraints/min-staffing.d.ts.map +1 -1
- package/dist/scheduling/constraints/min-staffing.js +51 -8
- package/dist/scheduling/constraints/rolling-hours.d.ts.map +1 -1
- package/dist/scheduling/constraints/rolling-hours.js +29 -4
- package/dist/scheduling/constraints/support.d.ts +4 -8
- package/dist/scheduling/constraints/support.d.ts.map +1 -1
- package/dist/scheduling/constraints/support.js +23 -2
- package/dist/scheduling/constraints/weekly-rest.d.ts +28 -0
- package/dist/scheduling/constraints/weekly-rest.d.ts.map +1 -1
- package/dist/scheduling/constraints/weekly-rest.js +108 -21
- package/dist/scheduling/engine/construction.d.ts.map +1 -1
- package/dist/scheduling/engine/construction.js +56 -7
- package/dist/scheduling/engine/objective.d.ts +0 -1
- package/dist/scheduling/engine/objective.d.ts.map +1 -1
- package/dist/scheduling/engine/objective.js +65 -6
- package/dist/scheduling/engine/search.d.ts +4 -0
- package/dist/scheduling/engine/search.d.ts.map +1 -1
- package/dist/scheduling/engine/search.js +2 -1
- package/dist/scheduling/engine/state.d.ts +14 -0
- package/dist/scheduling/engine/state.d.ts.map +1 -1
- package/dist/scheduling/engine/state.js +7 -0
- package/dist/scheduling/engine/timeline.d.ts +23 -1
- package/dist/scheduling/engine/timeline.d.ts.map +1 -1
- package/dist/scheduling/engine/timeline.js +85 -27
- package/dist/scheduling/engine/verdicts.d.ts +40 -1
- package/dist/scheduling/engine/verdicts.d.ts.map +1 -1
- package/dist/scheduling/engine/verdicts.js +177 -17
- package/dist/scheduling/index.d.ts +3 -2
- package/dist/scheduling/index.d.ts.map +1 -1
- package/dist/scheduling/index.js +7 -1
- package/dist/scheduling/model.d.ts +8 -4
- package/dist/scheduling/model.d.ts.map +1 -1
- package/dist/scheduling/model.js +239 -23
- package/dist/scheduling/operations.d.ts +174 -2
- package/dist/scheduling/operations.d.ts.map +1 -1
- package/dist/scheduling/operations.js +558 -21
- package/dist/scheduling/preference-report.d.ts +15 -0
- package/dist/scheduling/preference-report.d.ts.map +1 -0
- package/dist/scheduling/preference-report.js +111 -0
- package/dist/scheduling/preferences.d.ts +30 -0
- package/dist/scheduling/preferences.d.ts.map +1 -0
- package/dist/scheduling/preferences.js +85 -0
- package/dist/scheduling/resilience.d.ts +46 -0
- package/dist/scheduling/resilience.d.ts.map +1 -0
- package/dist/scheduling/resilience.js +45 -0
- package/dist/scheduling/scheduler.class.d.ts +12 -1
- package/dist/scheduling/scheduler.class.d.ts.map +1 -1
- package/dist/scheduling/scheduler.class.js +28 -4
- package/dist/scheduling/sites.d.ts +1 -1
- package/dist/scheduling/sites.d.ts.map +1 -1
- package/dist/scheduling/sites.js +34 -1
- package/dist/scheduling/time.d.ts +28 -6
- package/dist/scheduling/time.d.ts.map +1 -1
- package/dist/scheduling/time.js +59 -17
- package/dist/scheduling/types.d.ts +247 -7
- package/dist/scheduling/types.d.ts.map +1 -1
- package/dist/scoring/fair-arbitration.d.ts.map +1 -1
- package/dist/scoring/fair-arbitration.js +2 -1
- package/dist/tracing/decision-trace.d.ts +5 -0
- package/dist/tracing/decision-trace.d.ts.map +1 -1
- package/dist/tracing/decision-trace.js +3 -0
- package/dist/types/matcher.d.ts +369 -2
- package/dist/types/matcher.d.ts.map +1 -1
- package/dist/updates/assignment-update.d.ts +93 -0
- package/dist/updates/assignment-update.d.ts.map +1 -0
- package/dist/updates/assignment-update.js +91 -0
- package/dist/utils/keys.d.ts +10 -0
- package/dist/utils/keys.d.ts.map +1 -1
- package/dist/utils/keys.js +43 -0
- package/package.json +25 -3
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.scopeEmployeeConstraints = void 0;
|
|
4
4
|
const constraint_1 = require("./constraint");
|
|
5
5
|
const provenance_1 = require("../provenance");
|
|
6
|
+
const support_1 = require("./support");
|
|
6
7
|
/** Rule families are instantiated once per effective configuration, then dispatched by employee. */
|
|
7
8
|
function scopeEmployeeConstraints(options, rulesByEmployee) {
|
|
8
9
|
const base = (0, constraint_1.createDefaultConstraints)(options);
|
|
@@ -119,7 +120,7 @@ function scopeEmployeeConstraints(options, rulesByEmployee) {
|
|
|
119
120
|
const found = byEmployee.get(pair.employeeId);
|
|
120
121
|
return found && { c: found.constraint, state: { ...state, ctx: found.context(state.ctx) } };
|
|
121
122
|
};
|
|
122
|
-
|
|
123
|
+
const scoped = {
|
|
123
124
|
...prototype,
|
|
124
125
|
delta(state, pair) {
|
|
125
126
|
const d = delegate(state, pair);
|
|
@@ -150,7 +151,14 @@ function scopeEmployeeConstraints(options, rulesByEmployee) {
|
|
|
150
151
|
evaluate: delegates.some((d) => d.constraint.evaluate)
|
|
151
152
|
? (state) => delegates.flatMap((d) => d.constraint.evaluate?.(d.view(state, true)) ?? [])
|
|
152
153
|
: undefined,
|
|
153
|
-
}
|
|
154
|
+
};
|
|
155
|
+
// The wrapper mirrors when every delegate does (a delegate without a
|
|
156
|
+
// verdict has one synthesised from its delta above), and its own
|
|
157
|
+
// no-delegate answer is (0, pass).
|
|
158
|
+
if (delegates.every((d) => !d.constraint.verdict || (0, support_1.deltaMirrorsVerdict)(d.constraint))) {
|
|
159
|
+
(0, support_1.markDeltaMirrorsVerdict)(scoped);
|
|
160
|
+
}
|
|
161
|
+
registry.set(id, scoped);
|
|
154
162
|
}
|
|
155
163
|
return [...registry.values()];
|
|
156
164
|
}
|
|
@@ -33,7 +33,7 @@ function groupComposition() {
|
|
|
33
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
34
|
}
|
|
35
35
|
for (const [tag, max] of Object.entries(inst.tagMaximums)) {
|
|
36
|
-
if (!state.ctx.
|
|
36
|
+
if (!state.ctx.holdsTagOn(pair.employeeId, tag, inst.date))
|
|
37
37
|
continue;
|
|
38
38
|
const current = countTag(state, inst, tag, pair.employeeId);
|
|
39
39
|
if (current + 1 > max) {
|
|
@@ -85,7 +85,7 @@ function countTag(state, inst, tag, exclude) {
|
|
|
85
85
|
for (const employeeId of state.assignments.get(inst.id) ?? []) {
|
|
86
86
|
if (employeeId === exclude)
|
|
87
87
|
continue;
|
|
88
|
-
if (state.ctx.
|
|
88
|
+
if (state.ctx.holdsTagOn(employeeId, tag, inst.date))
|
|
89
89
|
count++;
|
|
90
90
|
}
|
|
91
91
|
return count;
|
|
@@ -1 +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;
|
|
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;AA2B/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,CA4DnH"}
|
|
@@ -10,6 +10,25 @@
|
|
|
10
10
|
*/
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.staffingViolations = exports.minStaffing = void 0;
|
|
13
|
+
/**
|
|
14
|
+
* How many of the assigned team hold a tag on the shift's date, at or above an
|
|
15
|
+
* optional grade floor.
|
|
16
|
+
*
|
|
17
|
+
* One helper for both the count and the ratio, so a graded minimum and a
|
|
18
|
+
* proportion can never disagree about who counts — and both read the date, so a
|
|
19
|
+
* lapsed certificate satisfies neither.
|
|
20
|
+
*/
|
|
21
|
+
function countTag(ctx, assigned, tag, date, minLevel) {
|
|
22
|
+
if (!assigned)
|
|
23
|
+
return 0;
|
|
24
|
+
let have = 0;
|
|
25
|
+
for (const employeeId of assigned) {
|
|
26
|
+
if (minLevel === undefined ? ctx.holdsTagOn(employeeId, tag, date) : ctx.holdsTagAt(employeeId, tag, date, minLevel)) {
|
|
27
|
+
have++;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return have;
|
|
31
|
+
}
|
|
13
32
|
function minStaffing() {
|
|
14
33
|
return {
|
|
15
34
|
id: 'min-staffing',
|
|
@@ -36,20 +55,44 @@ function staffingViolations(ctx, state, severity) {
|
|
|
36
55
|
unit: 'count',
|
|
37
56
|
});
|
|
38
57
|
}
|
|
39
|
-
for (const [tag,
|
|
40
|
-
|
|
41
|
-
if (
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
58
|
+
for (const [tag, requirement] of Object.entries(inst.tagRequirements)) {
|
|
59
|
+
const have = countTag(ctx, assigned, tag, inst.date, requirement.level);
|
|
60
|
+
if (have < requirement.min) {
|
|
61
|
+
const graded = requirement.level === undefined ? '' : ` at level ${requirement.level}`;
|
|
62
|
+
out.push({
|
|
63
|
+
constraintId: 'min-staffing',
|
|
64
|
+
severity,
|
|
65
|
+
shiftInstanceId: inst.id,
|
|
66
|
+
message: `shift "${inst.id}" needs ${requirement.min} employees with tag "${tag}"${graded}, has ${have}`,
|
|
67
|
+
actual: have,
|
|
68
|
+
required: requirement.min,
|
|
69
|
+
unit: 'count',
|
|
70
|
+
});
|
|
46
71
|
}
|
|
72
|
+
}
|
|
73
|
+
/*
|
|
74
|
+
* Proportions, which a headcount cannot express.
|
|
75
|
+
*
|
|
76
|
+
* A floor rounded up: 60% of four people is 2.4, and nobody staffs 2.4.
|
|
77
|
+
* An empty shift is silent — a proportion of nobody is undefined, and
|
|
78
|
+
* reporting it as a breach would bury the real finding, which is the
|
|
79
|
+
* unstaffed shift already reported above.
|
|
80
|
+
*/
|
|
81
|
+
for (const [tag, ratio] of Object.entries(inst.tagRatios)) {
|
|
82
|
+
if (count === 0)
|
|
83
|
+
continue;
|
|
84
|
+
const needed = Math.ceil(ratio * count);
|
|
85
|
+
const have = countTag(ctx, assigned, tag, inst.date);
|
|
47
86
|
if (have < needed) {
|
|
48
87
|
out.push({
|
|
49
88
|
constraintId: 'min-staffing',
|
|
50
89
|
severity,
|
|
51
90
|
shiftInstanceId: inst.id,
|
|
52
|
-
message: `shift "${inst.id}" needs ${
|
|
91
|
+
message: `shift "${inst.id}" needs ${Math.round(ratio * 100)}% of its team tagged "${tag}" ` +
|
|
92
|
+
`(${needed} of ${count}), has ${have} of ${count}`,
|
|
93
|
+
actual: have,
|
|
94
|
+
required: needed,
|
|
95
|
+
unit: 'count',
|
|
53
96
|
});
|
|
54
97
|
}
|
|
55
98
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rolling-hours.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/rolling-hours.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EAAe,oBAAoB,EAAe,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAIlG,eAAO,MAAM,qBAAqB,6CAA6C,CAAC;AAEhF,wBAAgB,YAAY,CAAC,MAAM,EAAE,iBAAiB,GAAG,oBAAoB,
|
|
1
|
+
{"version":3,"file":"rolling-hours.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/rolling-hours.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EAAe,oBAAoB,EAAe,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAIlG,eAAO,MAAM,qBAAqB,6CAA6C,CAAC;AAEhF,wBAAgB,YAAY,CAAC,MAAM,EAAE,iBAAiB,GAAG,oBAAoB,CAoF5E"}
|
|
@@ -57,9 +57,13 @@ function rollingHours(limits) {
|
|
|
57
57
|
return over('week', weekTotal, limits.maxPerWeekAbsoluteMinutes, pair.employeeId, inst.id);
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
|
+
// Which average the opening balance belongs to. Computed once
|
|
61
|
+
// per verdict rather than per average, and ties are harmless:
|
|
62
|
+
// two averages over the same window are the same window.
|
|
63
|
+
const longestWindowDays = Math.max(0, ...(limits.rollingAverages ?? []).map((a) => a.windowDays));
|
|
60
64
|
for (const average of limits.rollingAverages ?? []) {
|
|
61
65
|
const span = average.windowDays * support_1.MINUTES_PER_DAY;
|
|
62
|
-
const breach = worstAverageBreach(state, t, pair.employeeId, average.maxMinutes, span, range, limits);
|
|
66
|
+
const breach = worstAverageBreach(state, t, pair.employeeId, average.maxMinutes, span, range, limits, average.windowDays === longestWindowDays);
|
|
63
67
|
if (breach !== null) {
|
|
64
68
|
const label = average.label ?? `${(0, support_1.h)(average.maxMinutes)}/${average.windowDays}d`;
|
|
65
69
|
return (0, support_1.fail)('rolling-hours', 'hard', `employee "${pair.employeeId}" would work ${(0, support_1.h)(breach.worked)} in some ${average.windowDays}-day window, over the ${label} limit of ${(0, support_1.h)(breach.allowance)}`, {
|
|
@@ -114,14 +118,35 @@ function dayAverageHolds(timeline, limits, range) {
|
|
|
114
118
|
* start, with breakpoints at entry and absence boundaries, so the extreme lies
|
|
115
119
|
* on a window whose edge touches one of those boundaries (or the probe bounds).
|
|
116
120
|
*/
|
|
117
|
-
function worstAverageBreach(state, timeline, employeeId, maxMinutes, span, range, limits) {
|
|
121
|
+
function worstAverageBreach(state, timeline, employeeId, maxMinutes, span, range, limits, appliesTo) {
|
|
118
122
|
const bounds = windowFor(range, span);
|
|
119
123
|
const kinds = limits.neutraliseAbsenceKinds;
|
|
120
124
|
const neutral = kinds?.length
|
|
121
125
|
? (state.ctx.absences.get(employeeId) ?? []).filter((a) => a.kind !== undefined && kinds.includes(a.kind))
|
|
122
126
|
: [];
|
|
127
|
+
/*
|
|
128
|
+
* Hours already inside the window when the period opened.
|
|
129
|
+
*
|
|
130
|
+
* A twelve-month reference period otherwise needs twelve months of
|
|
131
|
+
* shift-level history replayed on every solve, because the only way to put
|
|
132
|
+
* minutes into a window was one assignment at a time. The balance is added
|
|
133
|
+
* to the *worked* side rather than taken off the cap so the reported
|
|
134
|
+
* numbers stay legible: "would work 114h against a 100h budget" is what a
|
|
135
|
+
* person needs to read, not "would work 16h against 2h".
|
|
136
|
+
*
|
|
137
|
+
* It belongs to the **longest** window and to no other. Hours worked last
|
|
138
|
+
* autumn are inside a 365-day window and are plainly not inside the last
|
|
139
|
+
* seven days, so adding the figure to every average made 1,500 hours into
|
|
140
|
+
* an annual budget breach a 48-hour *week* — and the one configuration the
|
|
141
|
+
* field exists for, an annual reference period beside the ordinary weekly
|
|
142
|
+
* average, produced an empty roster with no error at all.
|
|
143
|
+
*
|
|
144
|
+
* The longest window is the reference period the balance was measured over,
|
|
145
|
+
* which is the only window it can honestly be added to.
|
|
146
|
+
*/
|
|
147
|
+
const carried = appliesTo ? (state.ctx.employeeById.get(employeeId)?.contract?.openingBalanceMinutes ?? 0) : 0;
|
|
123
148
|
if (neutral.length === 0) {
|
|
124
|
-
const worked = timeline.maxWorkingMinutesInAnyWindow(span, bounds);
|
|
149
|
+
const worked = timeline.maxWorkingMinutesInAnyWindow(span, bounds) + carried;
|
|
125
150
|
return worked > maxMinutes ? { worked, allowance: maxMinutes } : null;
|
|
126
151
|
}
|
|
127
152
|
const starts = new Set([bounds.start, bounds.end - span]);
|
|
@@ -136,7 +161,7 @@ function worstAverageBreach(state, timeline, employeeId, maxMinutes, span, range
|
|
|
136
161
|
let worst = null;
|
|
137
162
|
for (const start of starts) {
|
|
138
163
|
const window = { start, end: start + span };
|
|
139
|
-
const worked = timeline.workingMinutesIn(window);
|
|
164
|
+
const worked = timeline.workingMinutesIn(window) + carried;
|
|
140
165
|
const neutralMinutes = neutral.reduce((sum, a) => sum + Math.max(0, Math.min(a.end, window.end) - Math.max(a.start, window.start)), 0);
|
|
141
166
|
const allowance = maxMinutes * (1 - Math.min(1, neutralMinutes / span));
|
|
142
167
|
const excess = worked - allowance;
|
|
@@ -33,14 +33,10 @@ export declare function pass(ruleId: string, message: string, extra?: Partial<Ru
|
|
|
33
33
|
export declare function fail(ruleId: string, severity: Severity, message: string, extra?: Partial<RuleVerdict>): RuleVerdict;
|
|
34
34
|
/** Hours, to one decimal, for human-readable messages. */
|
|
35
35
|
export declare function h(minutes: number): string;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
* `magnitude` converts a failing verdict into a breach size: local search needs
|
|
41
|
-
* to know a rest gap is 10 minutes short rather than merely "short", or it sits
|
|
42
|
-
* on a plateau with no gradient to follow.
|
|
43
|
-
*/
|
|
36
|
+
export declare function markDeltaMirrorsVerdict(constraint: SchedulingConstraint): void;
|
|
37
|
+
export declare function deltaMirrorsVerdict(constraint: SchedulingConstraint): boolean;
|
|
38
|
+
/** Rules the library registered itself, as opposed to `constraints.custom`. */
|
|
39
|
+
export declare const builtInConstraints: WeakSet<SchedulingConstraint>;
|
|
44
40
|
export declare function fromVerdict(spec: Omit<SchedulingConstraint, 'delta' | 'explain' | 'verdict'> & {
|
|
45
41
|
verdict(state: SearchState, pair: AssignmentPair): RuleVerdict;
|
|
46
42
|
magnitude?(v: RuleVerdict): number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"support.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/support.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EACR,cAAc,EACd,YAAY,EACZ,WAAW,EACX,oBAAoB,EACpB,WAAW,EACX,QAAQ,EACR,aAAa,EACb,gBAAgB,EACnB,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAGzD,eAAO,MAAM,eAAe,OAAO,CAAC;AAEpC,oDAAoD;AACpD,wBAAgB,WAAW,CAAC,GAAG,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAEzE;AAED,6EAA6E;AAC7E,wBAAgB,WAAW,CAAC,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,GAAG,cAAc,CAElF;AAED,0FAA0F;AAC1F,wBAAgB,QAAQ,CAAC,GAAG,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,GAAG,gBAAgB,CAEhF;AAED,4CAA4C;AAC5C,wBAAgB,OAAO,CAAC,IAAI,EAAE,aAAa,GAAG,WAAW,CAExD;AAED,iGAAiG;AACjG,wBAAgB,SAAS,CAAC,IAAI,EAAE,cAAc,GAAG,MAAM,CAEtD;AAED,6EAA6E;AAC7E,wBAAgB,UAAU,CAAC,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,cAAc,GAAG,aAAa,GAAG,SAAS,CAE9F;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,GAAG,WAAW,CAG1E;AAED,+BAA+B;AAC/B,wBAAgB,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,GAAE,OAAO,CAAC,WAAW,CAAM,GAAG,WAAW,CAEnG;AAED,+BAA+B;AAC/B,wBAAgB,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,GAAE,OAAO,CAAC,WAAW,CAAM,GAAG,WAAW,CAEvH;AAED,0DAA0D;AAC1D,wBAAgB,CAAC,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEzC;AAED
|
|
1
|
+
{"version":3,"file":"support.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/support.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EACR,cAAc,EACd,YAAY,EACZ,WAAW,EACX,oBAAoB,EACpB,WAAW,EACX,QAAQ,EACR,aAAa,EACb,gBAAgB,EACnB,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAGzD,eAAO,MAAM,eAAe,OAAO,CAAC;AAEpC,oDAAoD;AACpD,wBAAgB,WAAW,CAAC,GAAG,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAEzE;AAED,6EAA6E;AAC7E,wBAAgB,WAAW,CAAC,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,GAAG,cAAc,CAElF;AAED,0FAA0F;AAC1F,wBAAgB,QAAQ,CAAC,GAAG,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,GAAG,gBAAgB,CAEhF;AAED,4CAA4C;AAC5C,wBAAgB,OAAO,CAAC,IAAI,EAAE,aAAa,GAAG,WAAW,CAExD;AAED,iGAAiG;AACjG,wBAAgB,SAAS,CAAC,IAAI,EAAE,cAAc,GAAG,MAAM,CAEtD;AAED,6EAA6E;AAC7E,wBAAgB,UAAU,CAAC,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,cAAc,GAAG,aAAa,GAAG,SAAS,CAE9F;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,GAAG,WAAW,CAG1E;AAED,+BAA+B;AAC/B,wBAAgB,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,GAAE,OAAO,CAAC,WAAW,CAAM,GAAG,WAAW,CAEnG;AAED,+BAA+B;AAC/B,wBAAgB,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,GAAE,OAAO,CAAC,WAAW,CAAM,GAAG,WAAW,CAEvH;AAED,0DAA0D;AAC1D,wBAAgB,CAAC,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEzC;AAoBD,wBAAgB,uBAAuB,CAAC,UAAU,EAAE,oBAAoB,GAAG,IAAI,CAE9E;AAED,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,oBAAoB,GAAG,OAAO,CAE7E;AAED,+EAA+E;AAC/E,eAAO,MAAM,kBAAkB,+BAAsC,CAAC;AAEtE,wBAAgB,WAAW,CACvB,IAAI,EAAE,IAAI,CAAC,oBAAoB,EAAE,OAAO,GAAG,SAAS,GAAG,SAAS,CAAC,GAAG;IAChE,OAAO,CAAC,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,cAAc,GAAG,WAAW,CAAC;IAC/D,SAAS,CAAC,CAAC,CAAC,EAAE,WAAW,GAAG,MAAM,CAAC;CACtC,GACF,oBAAoB,CAgBtB"}
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* its rule.
|
|
9
9
|
*/
|
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
-
exports.fromVerdict = exports.h = exports.fail = exports.pass = exports.windowAround = exports.instanceOf = exports.entryIdOf = exports.rangeOf = exports.rulesFor = exports.timelineFor = exports.personIdFor = exports.MINUTES_PER_DAY = void 0;
|
|
11
|
+
exports.fromVerdict = exports.builtInConstraints = exports.deltaMirrorsVerdict = exports.markDeltaMirrorsVerdict = exports.h = exports.fail = exports.pass = exports.windowAround = exports.instanceOf = exports.entryIdOf = exports.rangeOf = exports.rulesFor = exports.timelineFor = exports.personIdFor = exports.MINUTES_PER_DAY = void 0;
|
|
12
12
|
const state_1 = require("../engine/state");
|
|
13
13
|
exports.MINUTES_PER_DAY = 1440;
|
|
14
14
|
/** The natural person behind an employee record. */
|
|
@@ -73,9 +73,28 @@ exports.h = h;
|
|
|
73
73
|
* to know a rest gap is 10 minutes short rather than merely "short", or it sits
|
|
74
74
|
* on a plateau with no gradient to follow.
|
|
75
75
|
*/
|
|
76
|
+
/**
|
|
77
|
+
* `delta` functions that are non-zero exactly when their constraint's
|
|
78
|
+
* `verdict` fails — every `fromVerdict` rule's, and the per-employee scoping
|
|
79
|
+
* wrapper's over them. Lets a hard-breach check read one verdict instead of
|
|
80
|
+
* computing it twice. Keyed by the function, not the constraint, so a rule
|
|
81
|
+
* that replaces its `delta` afterwards (availability keeps soft wishes out of
|
|
82
|
+
* it) is no longer treated as a mirror.
|
|
83
|
+
*/
|
|
84
|
+
const mirroringDeltas = new WeakSet();
|
|
85
|
+
function markDeltaMirrorsVerdict(constraint) {
|
|
86
|
+
mirroringDeltas.add(constraint.delta);
|
|
87
|
+
}
|
|
88
|
+
exports.markDeltaMirrorsVerdict = markDeltaMirrorsVerdict;
|
|
89
|
+
function deltaMirrorsVerdict(constraint) {
|
|
90
|
+
return constraint.verdict !== undefined && mirroringDeltas.has(constraint.delta);
|
|
91
|
+
}
|
|
92
|
+
exports.deltaMirrorsVerdict = deltaMirrorsVerdict;
|
|
93
|
+
/** Rules the library registered itself, as opposed to `constraints.custom`. */
|
|
94
|
+
exports.builtInConstraints = new WeakSet();
|
|
76
95
|
function fromVerdict(spec) {
|
|
77
96
|
const magnitude = spec.magnitude ?? defaultMagnitude;
|
|
78
|
-
|
|
97
|
+
const constraint = {
|
|
79
98
|
...spec,
|
|
80
99
|
verdict: spec.verdict,
|
|
81
100
|
delta(state, pair) {
|
|
@@ -87,6 +106,8 @@ function fromVerdict(spec) {
|
|
|
87
106
|
return v.pass ? null : v.message;
|
|
88
107
|
},
|
|
89
108
|
};
|
|
109
|
+
markDeltaMirrorsVerdict(constraint);
|
|
110
|
+
return constraint;
|
|
90
111
|
}
|
|
91
112
|
exports.fromVerdict = fromVerdict;
|
|
92
113
|
/** Shortfall or excess against the bound, when both are known; 1 otherwise. */
|
|
@@ -17,6 +17,34 @@
|
|
|
17
17
|
* `minMinutes` and both are checked.
|
|
18
18
|
*/
|
|
19
19
|
import type { SchedulingConstraint, WeeklyRestRule } from '../types';
|
|
20
|
+
import type { PersonTimeline } from '../engine/timeline';
|
|
20
21
|
export declare const WEEKLY_REST_CITATION = "Directive 2003/88/EC Art 5";
|
|
21
22
|
export declare function weeklyRest(rule: WeeklyRestRule): SchedulingConstraint;
|
|
23
|
+
/**
|
|
24
|
+
* Rest that counts towards an averaged weekly-rest requirement in the window
|
|
25
|
+
* `[start, start + averagingMinutes)`: each free stretch contributes whole
|
|
26
|
+
* multiples of `minPer`, so two 30h gaps are worth nothing against a 48h
|
|
27
|
+
* requirement and one 100h gap is worth 96h.
|
|
28
|
+
*/
|
|
29
|
+
export declare function qualifyingRestAt(timeline: PersonTimeline, start: number, averagingMinutes: number, minPer: number): number;
|
|
30
|
+
/**
|
|
31
|
+
* The least qualifying rest in any window starting at an integer minute in
|
|
32
|
+
* `[lo, hi]` — exactly, not over a sample of starts.
|
|
33
|
+
*
|
|
34
|
+
* The quantity is a step function of the window start, and its minima are
|
|
35
|
+
* not only where an edge meets a shift boundary: they also sit where the
|
|
36
|
+
* leading or trailing gap crosses a multiple of `minPer`. So the starts are
|
|
37
|
+
* split into segments on which the window's structure is fixed — the same
|
|
38
|
+
* shifts intersect it, and the same edges are free — using every boundary at
|
|
39
|
+
* which that can change. Inside a segment the value is
|
|
40
|
+
*
|
|
41
|
+
* inner + m·⌊(a − s)/m⌋ [leading gap] + m·⌊(s + A − b)/m⌋ [trailing gap]
|
|
42
|
+
*
|
|
43
|
+
* which is falling in `s` with only a leading gap (least at the segment's
|
|
44
|
+
* end), rising with only a trailing one (least at its start), and with both
|
|
45
|
+
* dips one step below `m·⌊C/m⌋` exactly where `(a − s) mod m` exceeds
|
|
46
|
+
* `C mod m`, `C = a + A − b` — the first such start is the only other
|
|
47
|
+
* candidate. Each candidate is then measured directly.
|
|
48
|
+
*/
|
|
49
|
+
export declare function worstQualifyingRest(timeline: PersonTimeline, averagingMinutes: number, lo: number, hi: number, minPer: number): number;
|
|
22
50
|
//# sourceMappingURL=weekly-rest.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"weekly-rest.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/weekly-rest.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAe,oBAAoB,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"weekly-rest.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/weekly-rest.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAe,oBAAoB,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAClF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAGzD,eAAO,MAAM,oBAAoB,+BAA+B,CAAC;AAEjE,wBAAgB,UAAU,CAAC,IAAI,EAAE,cAAc,GAAG,oBAAoB,CAuErE;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAM1H;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,mBAAmB,CAC/B,QAAQ,EAAE,cAAc,EACxB,gBAAgB,EAAE,MAAM,EACxB,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,EACV,MAAM,EAAE,MAAM,GACf,MAAM,CA+DR"}
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
* `minMinutes` and both are checked.
|
|
19
19
|
*/
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
exports.weeklyRest = exports.WEEKLY_REST_CITATION = void 0;
|
|
21
|
+
exports.worstQualifyingRest = exports.qualifyingRestAt = exports.weeklyRest = exports.WEEKLY_REST_CITATION = void 0;
|
|
22
22
|
const support_1 = require("./support");
|
|
23
23
|
exports.WEEKLY_REST_CITATION = 'Directive 2003/88/EC Art 5';
|
|
24
24
|
function weeklyRest(rule) {
|
|
@@ -53,7 +53,13 @@ function weeklyRest(rule) {
|
|
|
53
53
|
// they would have had from each short window.
|
|
54
54
|
const windows = averagingMinutes / windowMinutes;
|
|
55
55
|
const required = rule.minMinutes * windows;
|
|
56
|
-
|
|
56
|
+
// Every averaging window that contains the shift, exactly.
|
|
57
|
+
// Probing a sample of window starts let two checks see
|
|
58
|
+
// different windows: construction added a shift that broke
|
|
59
|
+
// a window it never probed, and the final judgement of an
|
|
60
|
+
// earlier shift in that window then reported a breach the
|
|
61
|
+
// solve had created itself.
|
|
62
|
+
const worstAveraged = worstQualifyingRest(t, averagingMinutes, range.start - averagingMinutes + 1, range.end - 1, rule.minMinutes);
|
|
57
63
|
if (worstAveraged < required) {
|
|
58
64
|
return (0, support_1.fail)('weekly-rest', 'hard', `employee "${pair.employeeId}" would average ${(0, support_1.h)(worstAveraged / windows)} weekly rest over ${rule.averageOverDays} days, below the ${(0, support_1.h)(rule.minMinutes)} average`, { actual: worstAveraged, required, unit: 'minutes', citation: exports.WEEKLY_REST_CITATION });
|
|
59
65
|
}
|
|
@@ -69,35 +75,116 @@ function weeklyRest(rule) {
|
|
|
69
75
|
}
|
|
70
76
|
exports.weeklyRest = weeklyRest;
|
|
71
77
|
/**
|
|
72
|
-
*
|
|
73
|
-
*
|
|
78
|
+
* Rest that counts towards an averaged weekly-rest requirement in the window
|
|
79
|
+
* `[start, start + averagingMinutes)`: each free stretch contributes whole
|
|
80
|
+
* multiples of `minPer`, so two 30h gaps are worth nothing against a 48h
|
|
81
|
+
* requirement and one 100h gap is worth 96h.
|
|
82
|
+
*/
|
|
83
|
+
function qualifyingRestAt(timeline, start, averagingMinutes, minPer) {
|
|
84
|
+
let total = 0;
|
|
85
|
+
for (const gap of timeline.restGapsIn({ start, end: start + averagingMinutes })) {
|
|
86
|
+
if (gap >= minPer)
|
|
87
|
+
total += minPer * Math.floor(gap / minPer);
|
|
88
|
+
}
|
|
89
|
+
return total;
|
|
90
|
+
}
|
|
91
|
+
exports.qualifyingRestAt = qualifyingRestAt;
|
|
92
|
+
/**
|
|
93
|
+
* The least qualifying rest in any window starting at an integer minute in
|
|
94
|
+
* `[lo, hi]` — exactly, not over a sample of starts.
|
|
74
95
|
*
|
|
75
|
-
*
|
|
76
|
-
* not
|
|
77
|
-
*
|
|
96
|
+
* The quantity is a step function of the window start, and its minima are
|
|
97
|
+
* not only where an edge meets a shift boundary: they also sit where the
|
|
98
|
+
* leading or trailing gap crosses a multiple of `minPer`. So the starts are
|
|
99
|
+
* split into segments on which the window's structure is fixed — the same
|
|
100
|
+
* shifts intersect it, and the same edges are free — using every boundary at
|
|
101
|
+
* which that can change. Inside a segment the value is
|
|
102
|
+
*
|
|
103
|
+
* inner + m·⌊(a − s)/m⌋ [leading gap] + m·⌊(s + A − b)/m⌋ [trailing gap]
|
|
104
|
+
*
|
|
105
|
+
* which is falling in `s` with only a leading gap (least at the segment's
|
|
106
|
+
* end), rising with only a trailing one (least at its start), and with both
|
|
107
|
+
* dips one step below `m·⌊C/m⌋` exactly where `(a − s) mod m` exceeds
|
|
108
|
+
* `C mod m`, `C = a + A − b` — the first such start is the only other
|
|
109
|
+
* candidate. Each candidate is then measured directly.
|
|
78
110
|
*/
|
|
79
|
-
function
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
const
|
|
85
|
-
for (const
|
|
86
|
-
for (const
|
|
87
|
-
if (
|
|
88
|
-
|
|
111
|
+
function worstQualifyingRest(timeline, averagingMinutes, lo, hi, minPer) {
|
|
112
|
+
if (hi < lo)
|
|
113
|
+
return Infinity;
|
|
114
|
+
const A = averagingMinutes;
|
|
115
|
+
const entries = timeline.entriesIn({ start: lo, end: hi + A });
|
|
116
|
+
const cuts = new Set([lo, hi + 1]);
|
|
117
|
+
for (const e of entries) {
|
|
118
|
+
for (const at of [e.start, e.end, e.start - A + 1, e.end - A + 1]) {
|
|
119
|
+
if (at > lo && at <= hi)
|
|
120
|
+
cuts.add(at);
|
|
89
121
|
}
|
|
90
122
|
}
|
|
123
|
+
const sorted = [...cuts].sort((x, y) => x - y);
|
|
91
124
|
let worst = Infinity;
|
|
92
|
-
|
|
93
|
-
|
|
125
|
+
// `qualifyingRestAt` over the entries already in hand, without building
|
|
126
|
+
// the gap list: this runs for every candidate the search judges.
|
|
127
|
+
const measure = (s) => {
|
|
128
|
+
const end = s + A;
|
|
94
129
|
let total = 0;
|
|
95
|
-
|
|
130
|
+
let cursor = s;
|
|
131
|
+
for (const e of entries) {
|
|
132
|
+
if (e.start >= end)
|
|
133
|
+
break;
|
|
134
|
+
if (e.end <= s)
|
|
135
|
+
continue;
|
|
136
|
+
if (e.start > cursor) {
|
|
137
|
+
const gap = e.start - cursor;
|
|
138
|
+
if (gap >= minPer)
|
|
139
|
+
total += minPer * Math.floor(gap / minPer);
|
|
140
|
+
}
|
|
141
|
+
if (e.end > cursor)
|
|
142
|
+
cursor = e.end;
|
|
143
|
+
}
|
|
144
|
+
if (end > cursor) {
|
|
145
|
+
const gap = end - cursor;
|
|
96
146
|
if (gap >= minPer)
|
|
97
147
|
total += minPer * Math.floor(gap / minPer);
|
|
98
148
|
}
|
|
99
149
|
if (total < worst)
|
|
100
150
|
worst = total;
|
|
151
|
+
};
|
|
152
|
+
for (let i = 0; i + 1 < sorted.length; i++) {
|
|
153
|
+
const p = sorted[i];
|
|
154
|
+
const q = sorted[i + 1] - 1;
|
|
155
|
+
measure(p);
|
|
156
|
+
if (q !== p)
|
|
157
|
+
measure(q);
|
|
158
|
+
if (q - p < 2 || !(minPer > 0))
|
|
159
|
+
continue;
|
|
160
|
+
// Both edges free throughout the segment? Then the dip, if any.
|
|
161
|
+
let a = Infinity;
|
|
162
|
+
let b = -Infinity;
|
|
163
|
+
for (const e of entries) {
|
|
164
|
+
if (e.start >= p + A)
|
|
165
|
+
break;
|
|
166
|
+
if (e.end <= p)
|
|
167
|
+
continue;
|
|
168
|
+
if (e.start < a)
|
|
169
|
+
a = e.start;
|
|
170
|
+
if (e.end > b)
|
|
171
|
+
b = e.end;
|
|
172
|
+
}
|
|
173
|
+
if (a === Infinity)
|
|
174
|
+
continue;
|
|
175
|
+
if (!(a > q && p + A > b))
|
|
176
|
+
continue;
|
|
177
|
+
const C = a + A - b;
|
|
178
|
+
const r = ((C % minPer) + minPer) % minPer;
|
|
179
|
+
if (r >= minPer - 1)
|
|
180
|
+
continue;
|
|
181
|
+
// u = a − s runs from a − q up to a − p; the first u with residue r + 1.
|
|
182
|
+
const uLo = a - q;
|
|
183
|
+
const target = r + 1;
|
|
184
|
+
const u = uLo + ((((target - uLo) % minPer) + minPer) % minPer);
|
|
185
|
+
if (u <= a - p)
|
|
186
|
+
measure(a - u);
|
|
101
187
|
}
|
|
102
|
-
return worst
|
|
188
|
+
return worst;
|
|
103
189
|
}
|
|
190
|
+
exports.worstQualifyingRest = worstQualifyingRest;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"construction.d.ts","sourceRoot":"","sources":["../../../src/scheduling/engine/construction.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAU,KAAK,aAAa,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"construction.d.ts","sourceRoot":"","sources":["../../../src/scheduling/engine/construction.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAU,KAAK,aAAa,EAAE,MAAM,SAAS,CAAC;AAIrD,wEAAwE;AACxE,wBAAgB,aAAa,CAAC,GAAG,EAAE,YAAY,EAAE,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAuBtH;AA8FD,gGAAgG;AAChG,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,YAAY,EAAE,WAAW,EAAE,iBAAiB,GAAG,MAAM,EAAE,CAS7F;AAwDD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,cAAc,CAC1B,GAAG,EAAE,YAAY,EACjB,KAAK,EAAE,aAAa,EACpB,WAAW,EAAE,iBAAiB,EAC9B,IAAI,EAAE,MAAM,MAAM,GACnB,IAAI,CA0CN;AAKD;;;;GAIG;AACH,wBAAgB,UAAU,CACtB,GAAG,EAAE,YAAY,EACjB,KAAK,EAAE,aAAa,EACpB,WAAW,EAAE,iBAAiB,EAC9B,SAAS,EAAE,UAAU,GAAG,UAAU,EAClC,IAAI,EAAE,MAAM,MAAM,EAClB,WAAW,CAAC,EAAE,MAAM,EAAE,GACvB,IAAI,CA6BN"}
|
|
@@ -20,15 +20,44 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
20
20
|
exports.greedyFill = exports.fillToContract = exports.constructionOrder = exports.hardCompliant = void 0;
|
|
21
21
|
const state_1 = require("./state");
|
|
22
22
|
const support_1 = require("../constraints/support");
|
|
23
|
+
const verdicts_1 = require("./verdicts");
|
|
23
24
|
/** Whether assigning the pair keeps every hard constraint satisfied. */
|
|
24
25
|
function hardCompliant(ctx, state, employeeId, instanceId) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
const pair = { employeeId, shiftInstanceId: instanceId };
|
|
27
|
+
// Rules are asked cheapest first, which cannot change a yes/no over all of them.
|
|
28
|
+
// A solve with a custom rule judges afresh every time: a custom rule could
|
|
29
|
+
// read any part of the state, so no counter can say when its answer went stale.
|
|
30
|
+
if (state.ctx !== ctx || !allBuiltIn(ctx))
|
|
31
|
+
return !(0, verdicts_1.anyHardDelta)(ctx, state, pair);
|
|
32
|
+
// The crew-reading rules are asked live. The rest read only the person's
|
|
33
|
+
// timeline and records, which move exactly when the person's counter does,
|
|
34
|
+
// so their answer is remembered until then — a shift nobody can fill is
|
|
35
|
+
// otherwise re-judged against the whole team on every pass of the search.
|
|
36
|
+
if ((0, verdicts_1.anyHardDeltaIn)(ctx, state, pair, 'crew'))
|
|
37
|
+
return false;
|
|
38
|
+
const person = state.personVersion.get(ctx.personIdOf.get(employeeId) ?? employeeId) ?? 0;
|
|
39
|
+
let byEmployee = state.hardCache.get(instanceId);
|
|
40
|
+
if (!byEmployee) {
|
|
41
|
+
byEmployee = new Map();
|
|
42
|
+
state.hardCache.set(instanceId, byEmployee);
|
|
28
43
|
}
|
|
29
|
-
|
|
44
|
+
const cached = byEmployee.get(employeeId);
|
|
45
|
+
if (cached && cached.person === person)
|
|
46
|
+
return cached.ok;
|
|
47
|
+
const ok = !(0, verdicts_1.anyHardDeltaIn)(ctx, state, pair, 'person');
|
|
48
|
+
byEmployee.set(employeeId, { person, ok });
|
|
49
|
+
return ok;
|
|
30
50
|
}
|
|
31
51
|
exports.hardCompliant = hardCompliant;
|
|
52
|
+
const builtInOnly = new WeakMap();
|
|
53
|
+
function allBuiltIn(ctx) {
|
|
54
|
+
let answer = builtInOnly.get(ctx);
|
|
55
|
+
if (answer === undefined) {
|
|
56
|
+
answer = ctx.constraints.every((c) => support_1.builtInConstraints.has(c));
|
|
57
|
+
builtInOnly.set(ctx, answer);
|
|
58
|
+
}
|
|
59
|
+
return answer;
|
|
60
|
+
}
|
|
32
61
|
function rankCandidate(ctx, state, instanceId, employeeId, objective, rand) {
|
|
33
62
|
const reasons = [];
|
|
34
63
|
let rank = 0;
|
|
@@ -36,17 +65,37 @@ function rankCandidate(ctx, state, instanceId, employeeId, objective, rand) {
|
|
|
36
65
|
const inst = ctx.instanceById.get(instanceId);
|
|
37
66
|
if (inst) {
|
|
38
67
|
const assigned = state.assignments.get(instanceId);
|
|
39
|
-
for (const [tag,
|
|
68
|
+
for (const [tag, requirement] of Object.entries(inst.tagRequirements)) {
|
|
69
|
+
const counts = (id) => requirement.level === undefined
|
|
70
|
+
? ctx.holdsTagOn(id, tag, inst.date)
|
|
71
|
+
: ctx.holdsTagAt(id, tag, inst.date, requirement.level);
|
|
40
72
|
let have = 0;
|
|
41
73
|
if (assigned)
|
|
42
74
|
for (const e of assigned)
|
|
43
|
-
if (
|
|
75
|
+
if (counts(e))
|
|
44
76
|
have++;
|
|
45
|
-
if (have <
|
|
77
|
+
if (have < requirement.min && counts(employeeId)) {
|
|
46
78
|
rank -= 1000;
|
|
47
79
|
reasons.push(`fills tag requirement "${tag}"`);
|
|
48
80
|
}
|
|
49
81
|
}
|
|
82
|
+
// Somebody who moves a proportion toward its floor. Judged against the
|
|
83
|
+
// team as it stands, so the preference strengthens as the shift fills
|
|
84
|
+
// rather than being decided when it was empty.
|
|
85
|
+
const onShift = assigned?.size ?? 0;
|
|
86
|
+
for (const [tag, ratio] of Object.entries(inst.tagRatios)) {
|
|
87
|
+
if (!ctx.holdsTagOn(employeeId, tag, inst.date))
|
|
88
|
+
continue;
|
|
89
|
+
let have = 0;
|
|
90
|
+
if (assigned)
|
|
91
|
+
for (const e of assigned)
|
|
92
|
+
if (ctx.holdsTagOn(e, tag, inst.date))
|
|
93
|
+
have++;
|
|
94
|
+
if (have < Math.ceil(ratio * (onShift + 1))) {
|
|
95
|
+
rank -= 800;
|
|
96
|
+
reasons.push(`helps the "${tag}" ratio`);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
50
99
|
}
|
|
51
100
|
const planned = state.minutesByEmployee.get(employeeId) ?? 0;
|
|
52
101
|
const contracted = ctx.contractedPeriodMinutes.get(employeeId);
|
|
@@ -57,7 +57,6 @@ export declare function minHoursShortfalls(ctx: ModelContext, state: SearchState
|
|
|
57
57
|
* instead of being silently ignored.
|
|
58
58
|
*/
|
|
59
59
|
export declare function breachTotals(ctx: ModelContext, state: SearchState): LexScore;
|
|
60
|
-
/** Backwards-compatible soft-breach total, for callers that want a single figure. */
|
|
61
60
|
export declare function softBreaches(ctx: ModelContext, state: SearchState): number;
|
|
62
61
|
/** The full three-level score. Lower is better at every level. */
|
|
63
62
|
export declare function scoreLex(ctx: ModelContext, state: SearchState, objective: 'standard' | 'balanced', minHoursWeight: number, fairnessRules?: FairnessRule[]): LexScore;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"objective.d.ts","sourceRoot":"","sources":["../../../src/scheduling/engine/objective.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"objective.d.ts","sourceRoot":"","sources":["../../../src/scheduling/engine/objective.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,KAAK,EAAkB,YAAY,EAAE,YAAY,EAAwB,WAAW,EAAE,MAAM,UAAU,CAAC;AAQ9G,eAAO,MAAM,eAAe,QAAS,CAAC;AACtC,eAAO,MAAM,oBAAoB,OAAQ,CAAC;AAC1C,eAAO,MAAM,gBAAgB,MAAM,CAAC;AACpC,6EAA6E;AAC7E,eAAO,MAAM,mBAAmB,IAAI,CAAC;AAErC,2DAA2D;AAC3D,MAAM,WAAW,QAAQ;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CAChB;AAED,+EAA+E;AAC/E,wBAAgB,aAAa,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,QAAQ,GAAG,MAAM,CAI9D;AAED,wBAAgB,QAAQ,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,QAAQ,GAAG,OAAO,CAE1D;AAED,gEAAgE;AAChE,wBAAgB,YAAY,CAAC,GAAG,EAAE,YAAY,EAAE,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAI9F;AAED,6EAA6E;AAC7E,wBAAgB,WAAW,CAAC,GAAG,EAAE,YAAY,EAAE,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CA8B7F;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,CA2B5E;AAyCD,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"}
|