assignment-user-matcher 1.16.1 → 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 +290 -8
- 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/employee-scope.d.ts.map +1 -1
- package/dist/scheduling/constraints/employee-scope.js +10 -2
- 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 +33 -4
- 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 +45 -3
- 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 +9 -1
- package/dist/scheduling/engine/timeline.d.ts.map +1 -1
- package/dist/scheduling/engine/timeline.js +52 -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 +2 -3
- package/dist/scheduling/model.d.ts.map +1 -1
- package/dist/scheduling/model.js +30 -12
- package/dist/scheduling/operations.d.ts +174 -2
- package/dist/scheduling/operations.d.ts.map +1 -1
- package/dist/scheduling/operations.js +513 -15
- 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/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 +107 -1
- 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 +15 -2
|
@@ -8,11 +8,50 @@
|
|
|
8
8
|
* Two judgement paths always drift, and the one that drifts is the one nobody
|
|
9
9
|
* is reading at the time.
|
|
10
10
|
*/
|
|
11
|
-
import type { AssignmentPair, ConstraintViolation, RuleVerdict, SearchState } from '../types';
|
|
11
|
+
import type { AssignmentPair, ConstraintViolation, ModelContext, RuleVerdict, SchedulingConstraint, SearchState } from '../types';
|
|
12
12
|
/** Every rule's verdict on one pair, in registry order. */
|
|
13
13
|
export declare function verdictsFor(state: SearchState, pair: AssignmentPair): RuleVerdict[];
|
|
14
14
|
/** Breaches attributable to individual assignments in the committed roster. */
|
|
15
15
|
export declare function collectPairViolations(state: SearchState): ConstraintViolation[];
|
|
16
|
+
/** Every committed pair with every rule's verdict on it, in assignment order. */
|
|
17
|
+
export declare function collectPairVerdicts(state: SearchState): Array<{
|
|
18
|
+
pair: AssignmentPair;
|
|
19
|
+
verdicts: RuleVerdict[];
|
|
20
|
+
}>;
|
|
21
|
+
/**
|
|
22
|
+
* The failing verdicts of `collectPairVerdicts`, as violations. Split out so a
|
|
23
|
+
* caller that reports the verdicts too (`checkCompliance`) judges each pair
|
|
24
|
+
* once rather than twice — the verdicts are the expensive part.
|
|
25
|
+
*/
|
|
26
|
+
export declare function pairViolationsFrom(pairVerdicts: Array<{
|
|
27
|
+
pair: AssignmentPair;
|
|
28
|
+
verdicts: RuleVerdict[];
|
|
29
|
+
}>): ConstraintViolation[];
|
|
30
|
+
/** Whether any hard rule's `delta` objects to the pair — `hardCompliant`'s question, short-circuited. */
|
|
31
|
+
export declare function anyHardDelta(ctx: ModelContext, state: SearchState, pair: AssignmentPair): boolean;
|
|
32
|
+
/** Whether a built-in rule's per-pair judgement reads who else is on the shift. */
|
|
33
|
+
export declare function readsCrew(c: SchedulingConstraint): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* `anyHardDelta` over one half of the hard rules: those that read the crew of
|
|
36
|
+
* the instance, or those that read only the person. The two halves together
|
|
37
|
+
* are exactly `anyHardDelta`; splitting them lets a caller remember the
|
|
38
|
+
* person half for as long as the person's schedule stands still.
|
|
39
|
+
*/
|
|
40
|
+
export declare function anyHardDeltaIn(ctx: ModelContext, state: SearchState, pair: AssignmentPair, half: 'person' | 'crew'): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Whether the pair is blocked: some verdict fails at hard severity, or some
|
|
43
|
+
* hard rule's `delta` objects. Equal to checking `verdictsFor(...).some(hard
|
|
44
|
+
* failure) || anyHardDelta(...)`, but stops at the first objection and reads a
|
|
45
|
+
* rule's verdict once where its delta is known to mirror it.
|
|
46
|
+
*/
|
|
47
|
+
export declare function hardBlocked(state: SearchState, pair: AssignmentPair): boolean;
|
|
16
48
|
/** Breaches only a whole-roster view can see: coverage, quotas, team fairness. */
|
|
17
49
|
export declare function collectAggregateViolations(state: SearchState): ConstraintViolation[];
|
|
50
|
+
/**
|
|
51
|
+
* `anyHardDelta` for a pair whose `verdictsFor` is already in hand. A rule
|
|
52
|
+
* without a verdict had its verdict synthesised from its delta, and a
|
|
53
|
+
* `fromVerdict` rule's delta mirrors its verdict, so only a rule with its own
|
|
54
|
+
* independent delta is asked again.
|
|
55
|
+
*/
|
|
56
|
+
export declare function anyHardDeltaGiven(state: SearchState, pair: AssignmentPair, verdicts: RuleVerdict[]): boolean;
|
|
18
57
|
//# sourceMappingURL=verdicts.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verdicts.d.ts","sourceRoot":"","sources":["../../../src/scheduling/engine/verdicts.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,mBAAmB,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"verdicts.d.ts","sourceRoot":"","sources":["../../../src/scheduling/engine/verdicts.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,mBAAmB,EAAE,YAAY,EAAE,WAAW,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAGlI,2DAA2D;AAC3D,wBAAgB,WAAW,CAAC,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,cAAc,GAAG,WAAW,EAAE,CAoBnF;AAED,+EAA+E;AAC/E,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,WAAW,GAAG,mBAAmB,EAAE,CAE/E;AAED,iFAAiF;AACjF,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,WAAW,GAAG,KAAK,CAAC;IAAE,IAAI,EAAE,cAAc,CAAC;IAAC,QAAQ,EAAE,WAAW,EAAE,CAAA;CAAE,CAAC,CAShH;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAC9B,YAAY,EAAE,KAAK,CAAC;IAAE,IAAI,EAAE,cAAc,CAAC;IAAC,QAAQ,EAAE,WAAW,EAAE,CAAA;CAAE,CAAC,GACvE,mBAAmB,EAAE,CAmBvB;AAkDD,yGAAyG;AACzG,wBAAgB,YAAY,CAAC,GAAG,EAAE,YAAY,EAAE,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,cAAc,GAAG,OAAO,CAKjG;AASD,mFAAmF;AACnF,wBAAgB,SAAS,CAAC,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAE1D;AAID;;;;;GAKG;AACH,wBAAgB,cAAc,CAC1B,GAAG,EAAE,YAAY,EACjB,KAAK,EAAE,WAAW,EAClB,IAAI,EAAE,cAAc,EACpB,IAAI,EAAE,QAAQ,GAAG,MAAM,GACxB,OAAO,CAWT;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,cAAc,GAAG,OAAO,CAmB7E;AAED,kFAAkF;AAClF,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,WAAW,GAAG,mBAAmB,EAAE,CASpF;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,cAAc,EAAE,QAAQ,EAAE,WAAW,EAAE,GAAG,OAAO,CAY5G"}
|
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
* is reading at the time.
|
|
11
11
|
*/
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.collectAggregateViolations = exports.collectPairViolations = exports.verdictsFor = void 0;
|
|
13
|
+
exports.anyHardDeltaGiven = exports.collectAggregateViolations = exports.hardBlocked = exports.anyHardDeltaIn = exports.readsCrew = exports.anyHardDelta = exports.pairViolationsFrom = exports.collectPairVerdicts = exports.collectPairViolations = exports.verdictsFor = void 0;
|
|
14
|
+
const support_1 = require("../constraints/support");
|
|
14
15
|
/** Every rule's verdict on one pair, in registry order. */
|
|
15
16
|
function verdictsFor(state, pair) {
|
|
16
17
|
const out = [];
|
|
@@ -36,29 +37,165 @@ function verdictsFor(state, pair) {
|
|
|
36
37
|
exports.verdictsFor = verdictsFor;
|
|
37
38
|
/** Breaches attributable to individual assignments in the committed roster. */
|
|
38
39
|
function collectPairViolations(state) {
|
|
40
|
+
return pairViolationsFrom(collectPairVerdicts(state));
|
|
41
|
+
}
|
|
42
|
+
exports.collectPairViolations = collectPairViolations;
|
|
43
|
+
/** Every committed pair with every rule's verdict on it, in assignment order. */
|
|
44
|
+
function collectPairVerdicts(state) {
|
|
39
45
|
const out = [];
|
|
40
46
|
for (const [shiftInstanceId, employees] of state.assignments) {
|
|
41
47
|
for (const employeeId of employees) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
continue;
|
|
45
|
-
out.push({
|
|
46
|
-
constraintId: v.ruleId,
|
|
47
|
-
severity: v.severity,
|
|
48
|
-
employeeId,
|
|
49
|
-
shiftInstanceId,
|
|
50
|
-
message: v.message,
|
|
51
|
-
citation: v.citation,
|
|
52
|
-
actual: v.actual,
|
|
53
|
-
required: v.required,
|
|
54
|
-
unit: v.unit,
|
|
55
|
-
});
|
|
56
|
-
}
|
|
48
|
+
const pair = { employeeId, shiftInstanceId };
|
|
49
|
+
out.push({ pair, verdicts: verdictsFor(state, pair) });
|
|
57
50
|
}
|
|
58
51
|
}
|
|
59
52
|
return out;
|
|
60
53
|
}
|
|
61
|
-
exports.
|
|
54
|
+
exports.collectPairVerdicts = collectPairVerdicts;
|
|
55
|
+
/**
|
|
56
|
+
* The failing verdicts of `collectPairVerdicts`, as violations. Split out so a
|
|
57
|
+
* caller that reports the verdicts too (`checkCompliance`) judges each pair
|
|
58
|
+
* once rather than twice — the verdicts are the expensive part.
|
|
59
|
+
*/
|
|
60
|
+
function pairViolationsFrom(pairVerdicts) {
|
|
61
|
+
const out = [];
|
|
62
|
+
for (const { pair, verdicts } of pairVerdicts) {
|
|
63
|
+
for (const v of verdicts) {
|
|
64
|
+
if (v.pass)
|
|
65
|
+
continue;
|
|
66
|
+
out.push({
|
|
67
|
+
constraintId: v.ruleId,
|
|
68
|
+
severity: v.severity,
|
|
69
|
+
employeeId: pair.employeeId,
|
|
70
|
+
shiftInstanceId: pair.shiftInstanceId,
|
|
71
|
+
message: v.message,
|
|
72
|
+
citation: v.citation,
|
|
73
|
+
actual: v.actual,
|
|
74
|
+
required: v.required,
|
|
75
|
+
unit: v.unit,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return out;
|
|
80
|
+
}
|
|
81
|
+
exports.pairViolationsFrom = pairViolationsFrom;
|
|
82
|
+
/**
|
|
83
|
+
* Relative cost of judging one pair, by rule id. Static facts (time off, site,
|
|
84
|
+
* qualification, availability) are a lookup; timeline rules probe windows.
|
|
85
|
+
* Unknown ids — custom rules — sort with the expensive ones.
|
|
86
|
+
*/
|
|
87
|
+
const RULE_COST = {
|
|
88
|
+
'time-off': 0,
|
|
89
|
+
'site-eligibility': 0,
|
|
90
|
+
qualification: 0,
|
|
91
|
+
'max-shift-duration': 0,
|
|
92
|
+
protections: 0,
|
|
93
|
+
availability: 0,
|
|
94
|
+
'no-overlap': 1,
|
|
95
|
+
'one-shift-per-day': 1,
|
|
96
|
+
'group-composition': 1,
|
|
97
|
+
contract: 1,
|
|
98
|
+
'hour-budget': 1,
|
|
99
|
+
'engagement-floor': 1,
|
|
100
|
+
notice: 1,
|
|
101
|
+
'min-rest': 2,
|
|
102
|
+
'start-interval': 2,
|
|
103
|
+
'site-travel-gap': 2,
|
|
104
|
+
'shift-succession': 2,
|
|
105
|
+
'daily-rest': 2,
|
|
106
|
+
};
|
|
107
|
+
const byCost = new WeakMap();
|
|
108
|
+
/**
|
|
109
|
+
* The context's rules, cheapest first. Only for questions whose answer does
|
|
110
|
+
* not depend on the order the rules are asked in — "does any hard rule
|
|
111
|
+
* object?" — where a cheap early rejection saves the window probes. Custom
|
|
112
|
+
* rules keep their place after every built-in one, so a custom rule is still
|
|
113
|
+
* only consulted once the built-ins have all passed.
|
|
114
|
+
*/
|
|
115
|
+
function constraintsByCost(ctx) {
|
|
116
|
+
let ordered = byCost.get(ctx);
|
|
117
|
+
if (!ordered) {
|
|
118
|
+
const rank = (c) => (support_1.builtInConstraints.has(c) ? RULE_COST[c.id] ?? 3 : 10);
|
|
119
|
+
ordered = ctx.constraints
|
|
120
|
+
.map((c, index) => ({ c, index }))
|
|
121
|
+
.sort((a, b) => rank(a.c) - rank(b.c) || a.index - b.index)
|
|
122
|
+
.map(({ c }) => c);
|
|
123
|
+
byCost.set(ctx, ordered);
|
|
124
|
+
}
|
|
125
|
+
return ordered;
|
|
126
|
+
}
|
|
127
|
+
/** Whether any hard rule's `delta` objects to the pair — `hardCompliant`'s question, short-circuited. */
|
|
128
|
+
function anyHardDelta(ctx, state, pair) {
|
|
129
|
+
for (const c of constraintsByCost(ctx)) {
|
|
130
|
+
if (c.hardness === 'hard' && c.delta(state, pair) > 0)
|
|
131
|
+
return true;
|
|
132
|
+
}
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
exports.anyHardDelta = anyHardDelta;
|
|
136
|
+
/**
|
|
137
|
+
* Built-in rules whose per-pair judgement reads the instance's crew — who else
|
|
138
|
+
* is on the shift — rather than only the person's own timeline and records.
|
|
139
|
+
* Everything else a pair-scoped built-in reads moves only when the person does.
|
|
140
|
+
*/
|
|
141
|
+
const CREW_RULES = new Set(['group-composition', 'hour-budget']);
|
|
142
|
+
/** Whether a built-in rule's per-pair judgement reads who else is on the shift. */
|
|
143
|
+
function readsCrew(c) {
|
|
144
|
+
return CREW_RULES.has(c.id);
|
|
145
|
+
}
|
|
146
|
+
exports.readsCrew = readsCrew;
|
|
147
|
+
const hardSplit = new WeakMap();
|
|
148
|
+
/**
|
|
149
|
+
* `anyHardDelta` over one half of the hard rules: those that read the crew of
|
|
150
|
+
* the instance, or those that read only the person. The two halves together
|
|
151
|
+
* are exactly `anyHardDelta`; splitting them lets a caller remember the
|
|
152
|
+
* person half for as long as the person's schedule stands still.
|
|
153
|
+
*/
|
|
154
|
+
function anyHardDeltaIn(ctx, state, pair, half) {
|
|
155
|
+
let split = hardSplit.get(ctx);
|
|
156
|
+
if (!split) {
|
|
157
|
+
const hard = constraintsByCost(ctx).filter((c) => c.hardness === 'hard');
|
|
158
|
+
split = { person: hard.filter((c) => !CREW_RULES.has(c.id)), crew: hard.filter((c) => CREW_RULES.has(c.id)) };
|
|
159
|
+
hardSplit.set(ctx, split);
|
|
160
|
+
}
|
|
161
|
+
for (const c of split[half]) {
|
|
162
|
+
if (c.delta(state, pair) > 0)
|
|
163
|
+
return true;
|
|
164
|
+
}
|
|
165
|
+
return false;
|
|
166
|
+
}
|
|
167
|
+
exports.anyHardDeltaIn = anyHardDeltaIn;
|
|
168
|
+
/**
|
|
169
|
+
* Whether the pair is blocked: some verdict fails at hard severity, or some
|
|
170
|
+
* hard rule's `delta` objects. Equal to checking `verdictsFor(...).some(hard
|
|
171
|
+
* failure) || anyHardDelta(...)`, but stops at the first objection and reads a
|
|
172
|
+
* rule's verdict once where its delta is known to mirror it.
|
|
173
|
+
*/
|
|
174
|
+
function hardBlocked(state, pair) {
|
|
175
|
+
for (const c of constraintsByCost(state.ctx)) {
|
|
176
|
+
if (c.verdict) {
|
|
177
|
+
const v = c.verdict(state, pair);
|
|
178
|
+
if (!v.pass && v.severity === 'hard')
|
|
179
|
+
return true;
|
|
180
|
+
if (c.hardness === 'hard') {
|
|
181
|
+
if ((0, support_1.deltaMirrorsVerdict)(c)) {
|
|
182
|
+
if (!v.pass)
|
|
183
|
+
return true;
|
|
184
|
+
}
|
|
185
|
+
else if (c.delta(state, pair) > 0) {
|
|
186
|
+
return true;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
else if (c.hardness === 'hard' && c.delta(state, pair) > 0) {
|
|
191
|
+
// A rule without a verdict reports its hardness as its severity,
|
|
192
|
+
// so only a hard one can block.
|
|
193
|
+
return true;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return false;
|
|
197
|
+
}
|
|
198
|
+
exports.hardBlocked = hardBlocked;
|
|
62
199
|
/** Breaches only a whole-roster view can see: coverage, quotas, team fairness. */
|
|
63
200
|
function collectAggregateViolations(state) {
|
|
64
201
|
const out = [];
|
|
@@ -72,3 +209,26 @@ function collectAggregateViolations(state) {
|
|
|
72
209
|
return out;
|
|
73
210
|
}
|
|
74
211
|
exports.collectAggregateViolations = collectAggregateViolations;
|
|
212
|
+
/**
|
|
213
|
+
* `anyHardDelta` for a pair whose `verdictsFor` is already in hand. A rule
|
|
214
|
+
* without a verdict had its verdict synthesised from its delta, and a
|
|
215
|
+
* `fromVerdict` rule's delta mirrors its verdict, so only a rule with its own
|
|
216
|
+
* independent delta is asked again.
|
|
217
|
+
*/
|
|
218
|
+
function anyHardDeltaGiven(state, pair, verdicts) {
|
|
219
|
+
const constraints = state.ctx.constraints;
|
|
220
|
+
for (let i = 0; i < constraints.length; i++) {
|
|
221
|
+
const c = constraints[i];
|
|
222
|
+
if (c.hardness !== 'hard')
|
|
223
|
+
continue;
|
|
224
|
+
if (!c.verdict || (0, support_1.deltaMirrorsVerdict)(c)) {
|
|
225
|
+
if (!verdicts[i].pass)
|
|
226
|
+
return true;
|
|
227
|
+
}
|
|
228
|
+
else if (c.delta(state, pair) > 0) {
|
|
229
|
+
return true;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return false;
|
|
233
|
+
}
|
|
234
|
+
exports.anyHardDeltaGiven = anyHardDeltaGiven;
|
|
@@ -3,11 +3,12 @@ export { ShiftScheduler, solveSchedule, ENGINE_VERSION } from './scheduler.class
|
|
|
3
3
|
export { ScheduleValidationError } from './types';
|
|
4
4
|
/** Directive 2003/88/EC Art 3 floor (11h), the default when `minRestMinutes` is omitted. */
|
|
5
5
|
export { DEFAULT_MIN_REST_MINUTES } from './constraints/min-rest';
|
|
6
|
-
export { checkCompliance, explainCandidate, repairSchedule, rankCandidates, diagnoseInfeasibility, type ComplianceReport, type Disruption, type RepairCandidate, type RepairResult, type InfeasibilityReport, } from './operations';
|
|
6
|
+
export { checkCompliance, explainCandidate, repairSchedule, rankCandidates, rankShiftsFor, assessShiftResilience, rankSwapPartners, checkSwap, diagnoseInfeasibility, type ComplianceReport, type SwapPartner, type SwapPartnerOptions, type SwapTrade, type SwapCheck, type Disruption, type RepairCandidate, type RepairResult, type InfeasibilityReport, type TagCover, type ResilienceOptions, } from './operations';
|
|
7
|
+
export { resilienceTier, type ResilienceTier, type ShiftResilience, type SkillResilience } from './resilience';
|
|
7
8
|
export { PeriodClock, type MinuteRange, type ClockRange } from './time';
|
|
8
9
|
export { expandShiftInstances } from './model';
|
|
9
10
|
export { hours, days, weeklyAverageOver } from './rules';
|
|
10
11
|
export { DEFAULT_CONTRACT_HOURS_WEIGHT, contractedPeriodMinutes, fullTimeWeeklyMinutes, resolveContractedWeeklyMinutes, } from './contract-hours';
|
|
11
|
-
export type { AssignmentPair, AvailabilityRule, BreakRule, ClockRangeConfig, ConsecutiveRule, ConstraintOptions, ConstraintViolation, ContractHoursRule, ContractHoursSummary, DailyRestRule, DutyClassification, DutyQuota, Employee, EmployeeContract, EmployeeCost, EmployeeProtection, EngagementRule, FairnessRule, HistoricalAssignment, LedgerEntry, ModelContext, NightVolumeQuota, NightWorkRule, NoticeRule, ObjectiveWeights, OvertimeRule, Qualification, RestDayRule, RollingAverage, RuleVerdict, ScheduleInput, ScheduleProvenance, ScheduleResult, ScheduledAssignment, SchedulingConstraint, SearchState, Severity, ShiftInstance, ShiftTemplate, TagRequirement, ShiftDemandOverride, Site, SiteIndex, TimeOffEntry, WeeklyRestRule, WorkingTimeLimits, WorkingTimeRules, } from './types';
|
|
12
|
+
export type { AssignmentPair, AvailabilityRule, BreakRule, ClockRangeConfig, ConsecutiveRule, ConstraintOptions, ConstraintViolation, ContractHoursRule, ContractHoursSummary, DailyRestRule, DutyClassification, DutyQuota, Employee, EmployeeContract, EmployeeCost, EmployeePreferenceReport, EmployeeProtection, EngagementRule, FairnessRule, HistoricalAssignment, LedgerEntry, ModelContext, NightVolumeQuota, NightWorkRule, NoticeRule, ObjectiveWeights, OvertimeRule, PreferenceObjective, PreferenceRuleOutcome, Qualification, RestDayRule, RollingAverage, RuleVerdict, ScheduleInput, ScheduleProvenance, ScheduleResult, SearchProgress, ScheduledAssignment, SchedulingConstraint, SearchState, Severity, ShiftInstance, ShiftTemplate, TagRequirement, ShiftDemandOverride, Site, SiteIndex, TimeOffEntry, WeeklyRestRule, WorkingTimeLimits, WorkingTimeRules, } from './types';
|
|
12
13
|
export type { PersonTimeline, TimelineEntry, TimelineIndex } from './engine/timeline';
|
|
13
14
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/scheduling/index.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAClF,OAAO,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAClD,4FAA4F;AAC5F,OAAO,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAGlE,OAAO,EACH,eAAe,EACf,gBAAgB,EAChB,cAAc,EACd,cAAc,EACd,qBAAqB,EACrB,KAAK,gBAAgB,EACrB,KAAK,UAAU,EACf,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,mBAAmB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/scheduling/index.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAClF,OAAO,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAClD,4FAA4F;AAC5F,OAAO,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAGlE,OAAO,EACH,eAAe,EACf,gBAAgB,EAChB,cAAc,EACd,cAAc,EACd,aAAa,EACb,qBAAqB,EACrB,gBAAgB,EAChB,SAAS,EACT,qBAAqB,EACrB,KAAK,gBAAgB,EACrB,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACvB,KAAK,SAAS,EACd,KAAK,SAAS,EACd,KAAK,UAAU,EACf,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,mBAAmB,EACxB,KAAK,QAAQ,EACb,KAAK,iBAAiB,GACzB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,cAAc,EAAE,KAAK,cAAc,EAAE,KAAK,eAAe,EAAE,KAAK,eAAe,EAAE,MAAM,cAAc,CAAC;AAG/G,OAAO,EAAE,WAAW,EAAE,KAAK,WAAW,EAAE,KAAK,UAAU,EAAE,MAAM,QAAQ,CAAC;AAKxE,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAI/C,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAKzD,OAAO,EACH,6BAA6B,EAC7B,uBAAuB,EACvB,qBAAqB,EACrB,8BAA8B,GACjC,MAAM,kBAAkB,CAAC;AAE1B,YAAY,EACR,cAAc,EACd,gBAAgB,EAChB,SAAS,EACT,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EACjB,mBAAmB,EACnB,iBAAiB,EACjB,oBAAoB,EACpB,aAAa,EACb,kBAAkB,EAClB,SAAS,EACT,QAAQ,EACR,gBAAgB,EAChB,YAAY,EACZ,wBAAwB,EACxB,kBAAkB,EAClB,cAAc,EACd,YAAY,EACZ,oBAAoB,EACpB,WAAW,EACX,YAAY,EACZ,gBAAgB,EAChB,aAAa,EACb,UAAU,EACV,gBAAgB,EAChB,YAAY,EACZ,mBAAmB,EACnB,qBAAqB,EACrB,aAAa,EACb,WAAW,EACX,cAAc,EACd,WAAW,EACX,aAAa,EACb,kBAAkB,EAClB,cAAc,EACd,cAAc,EACd,mBAAmB,EACnB,oBAAoB,EACpB,WAAW,EACX,QAAQ,EACR,aAAa,EACb,aAAa,EACb,cAAc,EACd,mBAAmB,EACnB,IAAI,EACJ,SAAS,EACT,YAAY,EACZ,cAAc,EACd,iBAAiB,EACjB,gBAAgB,GACnB,MAAM,SAAS,CAAC;AAIjB,YAAY,EAAE,cAAc,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/scheduling/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.resolveContractedWeeklyMinutes = exports.fullTimeWeeklyMinutes = exports.contractedPeriodMinutes = exports.DEFAULT_CONTRACT_HOURS_WEIGHT = exports.weeklyAverageOver = exports.days = exports.hours = exports.expandShiftInstances = exports.PeriodClock = exports.diagnoseInfeasibility = exports.rankCandidates = exports.repairSchedule = exports.explainCandidate = exports.checkCompliance = exports.DEFAULT_MIN_REST_MINUTES = exports.ScheduleValidationError = exports.ENGINE_VERSION = exports.solveSchedule = exports.ShiftScheduler = void 0;
|
|
3
|
+
exports.resolveContractedWeeklyMinutes = exports.fullTimeWeeklyMinutes = exports.contractedPeriodMinutes = exports.DEFAULT_CONTRACT_HOURS_WEIGHT = exports.weeklyAverageOver = exports.days = exports.hours = exports.expandShiftInstances = exports.PeriodClock = exports.resilienceTier = exports.diagnoseInfeasibility = exports.checkSwap = exports.rankSwapPartners = exports.assessShiftResilience = exports.rankShiftsFor = exports.rankCandidates = exports.repairSchedule = exports.explainCandidate = exports.checkCompliance = exports.DEFAULT_MIN_REST_MINUTES = exports.ScheduleValidationError = exports.ENGINE_VERSION = exports.solveSchedule = exports.ShiftScheduler = void 0;
|
|
4
4
|
/** Public surface of the scheduling module. */
|
|
5
5
|
var scheduler_class_1 = require("./scheduler.class");
|
|
6
6
|
Object.defineProperty(exports, "ShiftScheduler", { enumerable: true, get: function () { return scheduler_class_1.ShiftScheduler; } });
|
|
@@ -17,7 +17,13 @@ Object.defineProperty(exports, "checkCompliance", { enumerable: true, get: funct
|
|
|
17
17
|
Object.defineProperty(exports, "explainCandidate", { enumerable: true, get: function () { return operations_1.explainCandidate; } });
|
|
18
18
|
Object.defineProperty(exports, "repairSchedule", { enumerable: true, get: function () { return operations_1.repairSchedule; } });
|
|
19
19
|
Object.defineProperty(exports, "rankCandidates", { enumerable: true, get: function () { return operations_1.rankCandidates; } });
|
|
20
|
+
Object.defineProperty(exports, "rankShiftsFor", { enumerable: true, get: function () { return operations_1.rankShiftsFor; } });
|
|
21
|
+
Object.defineProperty(exports, "assessShiftResilience", { enumerable: true, get: function () { return operations_1.assessShiftResilience; } });
|
|
22
|
+
Object.defineProperty(exports, "rankSwapPartners", { enumerable: true, get: function () { return operations_1.rankSwapPartners; } });
|
|
23
|
+
Object.defineProperty(exports, "checkSwap", { enumerable: true, get: function () { return operations_1.checkSwap; } });
|
|
20
24
|
Object.defineProperty(exports, "diagnoseInfeasibility", { enumerable: true, get: function () { return operations_1.diagnoseInfeasibility; } });
|
|
25
|
+
var resilience_1 = require("./resilience");
|
|
26
|
+
Object.defineProperty(exports, "resilienceTier", { enumerable: true, get: function () { return resilience_1.resilienceTier; } });
|
|
21
27
|
// Time model, exported so hosts can resolve the same wall-clock the engine does.
|
|
22
28
|
var time_1 = require("./time");
|
|
23
29
|
Object.defineProperty(exports, "PeriodClock", { enumerable: true, get: function () { return time_1.PeriodClock; } });
|
|
@@ -24,8 +24,9 @@
|
|
|
24
24
|
* days, and read only the first key of each time-off entry. All of those are
|
|
25
25
|
* modeled properly here.
|
|
26
26
|
*/
|
|
27
|
-
import type {
|
|
27
|
+
import type { ConstraintOptions, ModelContext, ObjectiveWeights, ScheduleInput, SchedulingConstraint, ShiftInstance, ShiftTemplate, WorkingTimeRules } from './types';
|
|
28
28
|
import { PeriodClock, MINUTES_PER_DAY } from './time';
|
|
29
|
+
export { availabilityApplies } from './preferences';
|
|
29
30
|
export { daysBetween, addDays } from './time';
|
|
30
31
|
/**
|
|
31
32
|
* Expand a whole input's templates into the dated occurrences the engine will
|
|
@@ -63,7 +64,5 @@ export declare function resolveConstraints(options: ConstraintOptions | undefine
|
|
|
63
64
|
* `ScheduleValidationError` on malformed input — never a silent wrong schedule.
|
|
64
65
|
*/
|
|
65
66
|
export declare function buildModel(input: ScheduleInput): ModelContext;
|
|
66
|
-
/** Whether an availability rule applies to a shift instance. */
|
|
67
|
-
export declare function availabilityApplies(rule: AvailabilityRule, inst: ShiftInstance): boolean;
|
|
68
67
|
export { MINUTES_PER_DAY };
|
|
69
68
|
//# sourceMappingURL=model.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../src/scheduling/model.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,KAAK,EAER,
|
|
1
|
+
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../src/scheduling/model.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,KAAK,EAER,iBAAiB,EAGjB,YAAY,EACZ,gBAAgB,EAChB,aAAa,EACb,oBAAoB,EACpB,aAAa,EACb,aAAa,EAGb,gBAAgB,EACnB,MAAM,SAAS,CAAC;AAYjB,OAAO,EAAE,WAAW,EAAE,eAAe,EAAmE,MAAM,QAAQ,CAAC;AAEvH,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAE9C;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,aAAa,GAAG,aAAa,EAAE,CA6B1E;AAiCD,wBAAgB,cAAc,CAC1B,QAAQ,EAAE,aAAa,EACvB,KAAK,EAAE,WAAW,EAClB,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE;IACL,SAAS,CAAC,EAAE,gBAAgB,CAAC,WAAW,CAAC,CAAC;IAC1C,cAAc,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAC5B;;;;OAIG;IACH,cAAc,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;CAC7C,GACF,aAAa,EAAE,CAmIjB;AA4XD;;;;;;GAMG;AACH,wBAAgB,UAAU,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,CAyBxB;AAiCD;;;GAGG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,aAAa,GAAG,YAAY,CAqL7D;AAED,OAAO,EAAE,eAAe,EAAE,CAAC"}
|
package/dist/scheduling/model.js
CHANGED
|
@@ -26,10 +26,12 @@
|
|
|
26
26
|
* modeled properly here.
|
|
27
27
|
*/
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.MINUTES_PER_DAY = exports.
|
|
29
|
+
exports.MINUTES_PER_DAY = exports.buildModel = exports.resolveConstraints = exports.mergeRules = exports.expandTemplate = exports.expandShiftInstances = exports.addDays = exports.daysBetween = exports.availabilityApplies = void 0;
|
|
30
30
|
const types_1 = require("./types");
|
|
31
|
+
const preferences_1 = require("./preferences");
|
|
31
32
|
const constraint_1 = require("./constraints/constraint");
|
|
32
33
|
const employee_scope_1 = require("./constraints/employee-scope");
|
|
34
|
+
const support_1 = require("./constraints/support");
|
|
33
35
|
const min_rest_1 = require("./constraints/min-rest");
|
|
34
36
|
const overtime_1 = require("./constraints/overtime");
|
|
35
37
|
const qualification_1 = require("./constraints/qualification");
|
|
@@ -37,6 +39,8 @@ const contract_hours_1 = require("./contract-hours");
|
|
|
37
39
|
const sites_1 = require("./sites");
|
|
38
40
|
const time_1 = require("./time");
|
|
39
41
|
Object.defineProperty(exports, "MINUTES_PER_DAY", { enumerable: true, get: function () { return time_1.MINUTES_PER_DAY; } });
|
|
42
|
+
var preferences_2 = require("./preferences");
|
|
43
|
+
Object.defineProperty(exports, "availabilityApplies", { enumerable: true, get: function () { return preferences_2.availabilityApplies; } });
|
|
40
44
|
var time_2 = require("./time");
|
|
41
45
|
Object.defineProperty(exports, "daysBetween", { enumerable: true, get: function () { return time_2.daysBetween; } });
|
|
42
46
|
Object.defineProperty(exports, "addDays", { enumerable: true, get: function () { return time_2.addDays; } });
|
|
@@ -522,6 +526,26 @@ function validateEmployee(employee) {
|
|
|
522
526
|
(0, time_1.assertIsoDate)(rule.fromDate, `employee "${employee.id}" availability.fromDate`);
|
|
523
527
|
if (rule.toDate !== undefined)
|
|
524
528
|
(0, time_1.assertIsoDate)(rule.toDate, `employee "${employee.id}" availability.toDate`);
|
|
529
|
+
if (rule.weight !== undefined && !Number.isFinite(rule.weight)) {
|
|
530
|
+
throw new types_1.ScheduleValidationError(`employee "${employee.id}" availability.weight must be a finite number`);
|
|
531
|
+
}
|
|
532
|
+
if (rule.shiftTypeTags !== undefined &&
|
|
533
|
+
(!Array.isArray(rule.shiftTypeTags) || rule.shiftTypeTags.some((t) => typeof t !== 'string' || !t))) {
|
|
534
|
+
throw new types_1.ScheduleValidationError(`employee "${employee.id}" availability.shiftTypeTags must be non-empty strings`);
|
|
535
|
+
}
|
|
536
|
+
// An empty list matches no shift type, so on an `available` rule it
|
|
537
|
+
// would silently make the person unrosterable. Omit the field instead.
|
|
538
|
+
if (rule.shiftTypeTags?.length === 0) {
|
|
539
|
+
throw new types_1.ScheduleValidationError(`employee "${employee.id}" availability.shiftTypeTags must list at least one shift type (omit it to match every shift)`);
|
|
540
|
+
}
|
|
541
|
+
if (rule.priority !== undefined) {
|
|
542
|
+
if (rule.priority !== 'normal' && rule.priority !== 'important') {
|
|
543
|
+
throw new types_1.ScheduleValidationError(`employee "${employee.id}" availability.priority must be normal or important`);
|
|
544
|
+
}
|
|
545
|
+
if (rule.kind !== 'preferred' && rule.kind !== 'avoid') {
|
|
546
|
+
throw new types_1.ScheduleValidationError(`employee "${employee.id}" availability.priority applies only to preferred and avoid rules`);
|
|
547
|
+
}
|
|
548
|
+
}
|
|
525
549
|
}
|
|
526
550
|
for (const q of employee.qualifications ?? []) {
|
|
527
551
|
if (q.validFrom !== undefined)
|
|
@@ -589,6 +613,8 @@ function resolveConstraints(options, rules, objectives, employeeRules) {
|
|
|
589
613
|
if (o.weight !== undefined)
|
|
590
614
|
c.weight = o.weight;
|
|
591
615
|
}
|
|
616
|
+
for (const c of constraints)
|
|
617
|
+
support_1.builtInConstraints.add(c);
|
|
592
618
|
return [...constraints, ...(options?.custom ?? [])];
|
|
593
619
|
}
|
|
594
620
|
exports.resolveConstraints = resolveConstraints;
|
|
@@ -758,6 +784,8 @@ function buildModel(input) {
|
|
|
758
784
|
? undefined
|
|
759
785
|
: clock.parseDateTime(input.published.publishedAt, 'published.publishedAt');
|
|
760
786
|
const asOfMinute = input.asOf === undefined ? undefined : clock.parseDateTime(input.asOf, 'asOf');
|
|
787
|
+
(0, preferences_1.validatePreferenceObjectives)(input.objectives?.preferences);
|
|
788
|
+
const preferenceRules = (0, preferences_1.resolvePreferenceRules)(input.employees, instances, clock, input.objectives?.preferences);
|
|
761
789
|
return {
|
|
762
790
|
periodStartDate: input.period.startDate,
|
|
763
791
|
periodDays,
|
|
@@ -780,6 +808,7 @@ function buildModel(input) {
|
|
|
780
808
|
contractedPeriodMinutes: contractedPeriod,
|
|
781
809
|
contractHoursWeight,
|
|
782
810
|
fillToContract,
|
|
811
|
+
preferenceRules,
|
|
783
812
|
personIdOf,
|
|
784
813
|
employeesOfPerson,
|
|
785
814
|
history: buildHistory(input.history, clock, personIdOf),
|
|
@@ -792,14 +821,3 @@ function buildModel(input) {
|
|
|
792
821
|
};
|
|
793
822
|
}
|
|
794
823
|
exports.buildModel = buildModel;
|
|
795
|
-
/** Whether an availability rule applies to a shift instance. */
|
|
796
|
-
function availabilityApplies(rule, inst) {
|
|
797
|
-
if (rule.daysOfWeek && !rule.daysOfWeek.includes(inst.weekday))
|
|
798
|
-
return false;
|
|
799
|
-
if (rule.fromDate && inst.date < rule.fromDate)
|
|
800
|
-
return false;
|
|
801
|
-
if (rule.toDate && inst.date > rule.toDate)
|
|
802
|
-
return false;
|
|
803
|
-
return true;
|
|
804
|
-
}
|
|
805
|
-
exports.availabilityApplies = availabilityApplies;
|
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
* - `diagnoseInfeasibility` — why the problem cannot be solved, before it is
|
|
18
18
|
* attempted.
|
|
19
19
|
*/
|
|
20
|
-
import type { AssignmentPair, ConstraintViolation, LedgerEntry, RuleVerdict, ScheduleInput, ScheduledAssignment, ContractHoursSummary } from './types';
|
|
20
|
+
import type { AssignmentPair, ConstraintViolation, LedgerEntry, RuleVerdict, ScheduleInput, ScheduledAssignment, ContractHoursSummary, EmployeePreferenceReport } from './types';
|
|
21
|
+
import { type ShiftResilience } from './resilience';
|
|
21
22
|
export interface ComplianceReport {
|
|
22
23
|
compliant: boolean;
|
|
23
24
|
/** Whether all headcount and skill coverage requirements are met. */
|
|
@@ -39,6 +40,8 @@ export interface ComplianceReport {
|
|
|
39
40
|
ledger: LedgerEntry[];
|
|
40
41
|
/** Planned against contracted hours — the same summary the solver reports for the same assignments. */
|
|
41
42
|
contractHours: ContractHoursSummary[];
|
|
43
|
+
/** How each stated preference fared — the same report the solver attaches. */
|
|
44
|
+
preferences: EmployeePreferenceReport[];
|
|
42
45
|
}
|
|
43
46
|
/**
|
|
44
47
|
* Validate an externally-produced or hand-edited roster.
|
|
@@ -97,6 +100,12 @@ export interface RepairCandidate {
|
|
|
97
100
|
distanceKm?: number;
|
|
98
101
|
/** Whether the shift is at this employee's home site. */
|
|
99
102
|
isHomeSite: boolean;
|
|
103
|
+
/**
|
|
104
|
+
* Which of the shift's `tagRequirements` this person holds on its date, at
|
|
105
|
+
* the level asked for — so a list of people can answer "who here is a
|
|
106
|
+
* first-aider". Declared qualifications only; empty when they hold none.
|
|
107
|
+
*/
|
|
108
|
+
tagsHeld: string[];
|
|
100
109
|
}
|
|
101
110
|
export interface RepairResult {
|
|
102
111
|
diff: {
|
|
@@ -138,15 +147,178 @@ export declare function repairSchedule(input: ScheduleInput, disruption: Disrupt
|
|
|
138
147
|
* Annex III point 4(b), which is high-risk with no narrow-task exemption.
|
|
139
148
|
*/
|
|
140
149
|
export declare function rankCandidates(input: ScheduleInput, shiftInstanceId: string, roster: ScheduledAssignment[], disruption?: Disruption): RepairCandidate[];
|
|
150
|
+
/**
|
|
151
|
+
* One person against many shifts: `rankCandidates` turned on its side.
|
|
152
|
+
*
|
|
153
|
+
* The question a worker's phone asks of a list of open shifts is "which of
|
|
154
|
+
* these could *I* take?" Answering it with `rankCandidates` per shift built the
|
|
155
|
+
* model and scored the whole team once per posting, to read one row of each.
|
|
156
|
+
* This builds the model once and scores only that person — through the same
|
|
157
|
+
* `scoreCandidates` judgement, so each answer is exactly the row the
|
|
158
|
+
* team-wide ranking gives them (a candidate is scored independently of the
|
|
159
|
+
* others, so leaving the others out changes nothing about theirs).
|
|
160
|
+
*
|
|
161
|
+
* Returns candidates in the order `shiftInstanceIds` names them, leaving out
|
|
162
|
+
* ids that name no shift and shifts the person already holds — the same
|
|
163
|
+
* people `rankCandidates` leaves out. An unknown employee gets `[]`.
|
|
164
|
+
*/
|
|
165
|
+
export declare function rankShiftsFor(input: ScheduleInput, employeeId: string, shiftInstanceIds: string[], roster: ScheduledAssignment[]): RepairCandidate[];
|
|
166
|
+
export interface ResilienceOptions {
|
|
167
|
+
/** Only these instances; default every instance in the period. */
|
|
168
|
+
shiftInstanceIds?: string[];
|
|
169
|
+
/** Expected dropouts per instance (headcount × absence rate); default 0. */
|
|
170
|
+
expectedDropouts?: Record<string, number>;
|
|
171
|
+
/** How many ranked backups to return per shift; default 5. */
|
|
172
|
+
topBackups?: number;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* The capacity radar's question for every shift in a window: is it short, and
|
|
176
|
+
* who could legally step in if someone drops out?
|
|
177
|
+
*
|
|
178
|
+
* One model build and one working state serve the whole window, as in
|
|
179
|
+
* `rankShiftsFor`. Backups come from `scoreCandidates` — the judgement
|
|
180
|
+
* `rankCandidates` and `rankSwapPartners` use — so the radar and a cover offer
|
|
181
|
+
* can never disagree about who could take a shift.
|
|
182
|
+
*
|
|
183
|
+
* A rostered person the time-off rule refuses on the shift (declared time off,
|
|
184
|
+
* an `absences` span or an external commitment) is reported in `absent`, not
|
|
185
|
+
* counted in `assigned`, and is taken off the working state *before* anyone is
|
|
186
|
+
* judged: they are genuinely off, so they hold no seat on a capped shift and
|
|
187
|
+
* their hours count against nobody. The state is local to the call.
|
|
188
|
+
*
|
|
189
|
+
* Backups are judged with one seat vacated where a crew cap binds (see
|
|
190
|
+
* `backupsFor`): a backup replaces a dropout, and a full shift asked with
|
|
191
|
+
* everyone still on it has room for nobody. `assigned` and `shortBy` are
|
|
192
|
+
* always the real roster.
|
|
193
|
+
*
|
|
194
|
+
* `need` is the folded `minEmployees`: a caller raises it with a
|
|
195
|
+
* `demandOverrides` entry on the input, never through an option here.
|
|
196
|
+
*
|
|
197
|
+
* Profiling-free: declared facts (roster, time off, qualifications, rules) and
|
|
198
|
+
* the caller's aggregate expected-dropout number — nothing behavioural.
|
|
199
|
+
*/
|
|
200
|
+
export declare function assessShiftResilience(input: ScheduleInput, roster: ScheduledAssignment[], options?: ResilienceOptions): ShiftResilience[];
|
|
201
|
+
/** One of a partner's shifts the proposer could take in return. */
|
|
202
|
+
export interface SwapTrade {
|
|
203
|
+
shiftInstanceId: string;
|
|
204
|
+
}
|
|
205
|
+
/** A colleague who could take a shift, and — when asked — what they could give back. */
|
|
206
|
+
export interface SwapPartner extends RepairCandidate {
|
|
207
|
+
/**
|
|
208
|
+
* The partner's own shifts that make a lawful trade: the partner may work
|
|
209
|
+
* the proposer's shift **and** the proposer may work this one, with both of
|
|
210
|
+
* them off the shift they are giving up. Present only when requested.
|
|
211
|
+
*/
|
|
212
|
+
trades?: SwapTrade[];
|
|
213
|
+
}
|
|
214
|
+
export interface SwapPartnerOptions {
|
|
215
|
+
/** Also work out which of each partner's shifts would make a lawful trade. */
|
|
216
|
+
trades?: boolean;
|
|
217
|
+
/** Only offer trades dated on or after this ISO date — typically today. */
|
|
218
|
+
tradesFrom?: string;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Who could take a shift off the person holding it, and what they could swap.
|
|
222
|
+
*
|
|
223
|
+
* `rankCandidates` answers "who can fill this gap?" — a gap nobody is in. A
|
|
224
|
+
* hand-over is asked about a shift somebody *is* in, so the proposer is taken
|
|
225
|
+
* off it first; asked with them still on it, a full shift reads "no room" for
|
|
226
|
+
* everybody.
|
|
227
|
+
*
|
|
228
|
+
* A trade is judged with **both** people off the shift they are giving up,
|
|
229
|
+
* in both directions, on one model build. Rules that span a whole shift or
|
|
230
|
+
* period (tag counts and ratios, aggregates) are not judged here: the host
|
|
231
|
+
* re-checks the full roster before applying, and this list is the prefilter
|
|
232
|
+
* that keeps a worker from asking a question whose answer is always no.
|
|
233
|
+
*
|
|
234
|
+
* Ordering is `rankCandidates`' own, so it stays inside the same
|
|
235
|
+
* profiling-free boundary.
|
|
236
|
+
*/
|
|
237
|
+
export declare function rankSwapPartners(input: ScheduleInput, shiftInstanceId: string, fromEmployeeId: string, roster: ScheduledAssignment[], options?: SwapPartnerOptions): SwapPartner[];
|
|
238
|
+
/** Whether one proposed swap is lawful for both people, and who it is not lawful for. */
|
|
239
|
+
export interface SwapCheck {
|
|
240
|
+
fits: boolean;
|
|
241
|
+
/** Failing hard rules, each naming the person it applies to. */
|
|
242
|
+
blockers: Array<RuleVerdict & {
|
|
243
|
+
employeeId: string;
|
|
244
|
+
}>;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Judge one proposed hand-over or trade, the same way `rankSwapPartners`
|
|
248
|
+
* judges each entry on its list.
|
|
249
|
+
*
|
|
250
|
+
* `toShiftInstanceId` null is a give-away. Either person not holding the shift
|
|
251
|
+
* named is an `input` blocker rather than a pass: a trade of shifts neither
|
|
252
|
+
* holds is not a trade.
|
|
253
|
+
*/
|
|
254
|
+
export declare function checkSwap(input: ScheduleInput, swap: {
|
|
255
|
+
fromEmployeeId: string;
|
|
256
|
+
fromShiftInstanceId: string;
|
|
257
|
+
toEmployeeId: string;
|
|
258
|
+
toShiftInstanceId: string | null;
|
|
259
|
+
}, roster: ScheduledAssignment[]): SwapCheck;
|
|
141
260
|
export interface InfeasibilityReport {
|
|
142
261
|
feasible: boolean;
|
|
143
262
|
findings: Array<{
|
|
144
|
-
kind: 'noEligibleEmployee' | 'insufficientCapacity' | 'tagCapacity';
|
|
263
|
+
kind: 'noEligibleEmployee' | 'noLawfulEmployee' | 'insufficientCapacity' | 'tagCapacity';
|
|
145
264
|
message: string;
|
|
146
265
|
shiftInstanceId?: string;
|
|
147
266
|
tag?: string;
|
|
148
267
|
shortfall?: number;
|
|
268
|
+
/**
|
|
269
|
+
* `noLawfulEmployee` only: why each person who could otherwise work the
|
|
270
|
+
* shift may not, by rule — most people first — with one of their
|
|
271
|
+
* verdicts as the example. A shift that breaks a rule on its own (a
|
|
272
|
+
* night the clocks go back in, 9 real hours against an 8-hour cap)
|
|
273
|
+
* names that rule for everybody.
|
|
274
|
+
*/
|
|
275
|
+
blockers?: Array<{
|
|
276
|
+
ruleId: string;
|
|
277
|
+
employees: number;
|
|
278
|
+
message: string;
|
|
279
|
+
actual?: number;
|
|
280
|
+
required?: number;
|
|
281
|
+
unit?: RuleVerdict['unit'];
|
|
282
|
+
}>;
|
|
283
|
+
/** `noLawfulEmployee` only: the occurrence's real length and working time, in minutes. */
|
|
284
|
+
durationMinutes?: number;
|
|
285
|
+
workingMinutes?: number;
|
|
286
|
+
}>;
|
|
287
|
+
/**
|
|
288
|
+
* Per skill the roster asks for: demand against the people who hold it,
|
|
289
|
+
* day by day. Informational — it never makes a report infeasible on its
|
|
290
|
+
* own, because a short day is a warning a planner can act on, not proof
|
|
291
|
+
* that no roster exists.
|
|
292
|
+
*/
|
|
293
|
+
tagCover: TagCover[];
|
|
294
|
+
}
|
|
295
|
+
/** One skill's demand against its holders over the period. */
|
|
296
|
+
export interface TagCover {
|
|
297
|
+
tag: string;
|
|
298
|
+
/**
|
|
299
|
+
* `'mix'` — some of the people on a shift must hold it (`tagRequirements`,
|
|
300
|
+
* `tagRatios`); `'everyone'` — every person on it must (`requiredTags`).
|
|
301
|
+
* A tag asked both ways reads as `'everyone'`, the stricter of the two.
|
|
302
|
+
*/
|
|
303
|
+
kind: 'mix' | 'everyone';
|
|
304
|
+
/** Shift occurrences asking for it. */
|
|
305
|
+
shifts: number;
|
|
306
|
+
/** People-shifts it asks for: the sum of each occurrence's count. */
|
|
307
|
+
seats: number;
|
|
308
|
+
/** People holding it on at least one day it is wanted. */
|
|
309
|
+
holders: number;
|
|
310
|
+
/**
|
|
311
|
+
* Days it asks for more holders than are free: holding it that day, not
|
|
312
|
+
* on time off, inside their contract. One person counts once per day, so
|
|
313
|
+
* an early and a late both wanting a key-holder need two.
|
|
314
|
+
*/
|
|
315
|
+
shortDates: Array<{
|
|
316
|
+
date: string;
|
|
317
|
+
needed: number;
|
|
318
|
+
available: number;
|
|
149
319
|
}>;
|
|
320
|
+
/** Days with exactly as many free holders as it asks for: one absence from short. */
|
|
321
|
+
tightDates: string[];
|
|
150
322
|
}
|
|
151
323
|
/**
|
|
152
324
|
* Why the problem cannot be solved, before spending a search budget on it.
|