assignment-user-matcher 1.9.0 → 1.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +164 -10
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -1
- package/dist/learning/auto-weights.d.ts +7 -4
- package/dist/learning/auto-weights.d.ts.map +1 -1
- package/dist/learning/auto-weights.js +7 -6
- package/dist/lua/workflow-transition.lua +8 -2
- package/dist/managers/LearningManager.d.ts.map +1 -1
- package/dist/managers/LearningManager.js +47 -0
- package/dist/managers/WorkflowManager.d.ts +7 -1
- package/dist/managers/WorkflowManager.d.ts.map +1 -1
- package/dist/managers/WorkflowManager.js +85 -12
- package/dist/matcher.class.d.ts +35 -3
- package/dist/matcher.class.d.ts.map +1 -1
- package/dist/matcher.class.js +319 -76
- package/dist/queries/users.d.ts +34 -0
- package/dist/queries/users.d.ts.map +1 -0
- package/dist/queries/users.js +227 -0
- package/dist/scheduling/constraints/availability.d.ts +43 -0
- package/dist/scheduling/constraints/availability.d.ts.map +1 -0
- package/dist/scheduling/constraints/availability.js +165 -0
- package/dist/scheduling/constraints/consecutive.d.ts +25 -0
- package/dist/scheduling/constraints/consecutive.d.ts.map +1 -0
- package/dist/scheduling/constraints/consecutive.js +215 -0
- package/dist/scheduling/constraints/constraint.d.ts +35 -0
- package/dist/scheduling/constraints/constraint.d.ts.map +1 -0
- package/dist/scheduling/constraints/constraint.js +97 -0
- package/dist/scheduling/constraints/contract.d.ts +21 -0
- package/dist/scheduling/constraints/contract.d.ts.map +1 -0
- package/dist/scheduling/constraints/contract.js +120 -0
- package/dist/scheduling/constraints/cost.d.ts +18 -0
- package/dist/scheduling/constraints/cost.d.ts.map +1 -0
- package/dist/scheduling/constraints/cost.js +65 -0
- package/dist/scheduling/constraints/daily-rest.d.ts +22 -0
- package/dist/scheduling/constraints/daily-rest.d.ts.map +1 -0
- package/dist/scheduling/constraints/daily-rest.js +123 -0
- package/dist/scheduling/constraints/duty-quota.d.ts +20 -0
- package/dist/scheduling/constraints/duty-quota.d.ts.map +1 -0
- package/dist/scheduling/constraints/duty-quota.js +95 -0
- package/dist/scheduling/constraints/engagement-floor.d.ts +28 -0
- package/dist/scheduling/constraints/engagement-floor.d.ts.map +1 -0
- package/dist/scheduling/constraints/engagement-floor.js +79 -0
- package/dist/scheduling/constraints/fairness.d.ts +34 -0
- package/dist/scheduling/constraints/fairness.d.ts.map +1 -0
- package/dist/scheduling/constraints/fairness.js +149 -0
- package/dist/scheduling/constraints/group-composition.d.ts +19 -0
- package/dist/scheduling/constraints/group-composition.d.ts.map +1 -0
- package/dist/scheduling/constraints/group-composition.js +92 -0
- package/dist/scheduling/constraints/hour-budget.d.ts +13 -0
- package/dist/scheduling/constraints/hour-budget.d.ts.map +1 -0
- package/dist/scheduling/constraints/hour-budget.js +65 -0
- package/dist/scheduling/constraints/in-shift-breaks.d.ts +24 -0
- package/dist/scheduling/constraints/in-shift-breaks.d.ts.map +1 -0
- package/dist/scheduling/constraints/in-shift-breaks.js +99 -0
- package/dist/scheduling/constraints/intervals.d.ts +5 -0
- package/dist/scheduling/constraints/intervals.d.ts.map +1 -0
- package/dist/scheduling/constraints/intervals.js +17 -0
- package/dist/scheduling/constraints/max-shift-duration.d.ts +7 -0
- package/dist/scheduling/constraints/max-shift-duration.d.ts.map +1 -0
- package/dist/scheduling/constraints/max-shift-duration.js +38 -0
- package/dist/scheduling/constraints/min-rest.d.ts +22 -0
- package/dist/scheduling/constraints/min-rest.d.ts.map +1 -0
- package/dist/scheduling/constraints/min-rest.js +49 -0
- package/dist/scheduling/constraints/min-staffing.d.ts +14 -0
- package/dist/scheduling/constraints/min-staffing.d.ts.map +1 -0
- package/dist/scheduling/constraints/min-staffing.js +59 -0
- package/dist/scheduling/constraints/night-work.d.ts +24 -0
- package/dist/scheduling/constraints/night-work.d.ts.map +1 -0
- package/dist/scheduling/constraints/night-work.js +179 -0
- package/dist/scheduling/constraints/no-overlap.d.ts +11 -0
- package/dist/scheduling/constraints/no-overlap.d.ts.map +1 -0
- package/dist/scheduling/constraints/no-overlap.js +35 -0
- package/dist/scheduling/constraints/notice.d.ts +44 -0
- package/dist/scheduling/constraints/notice.d.ts.map +1 -0
- package/dist/scheduling/constraints/notice.js +140 -0
- package/dist/scheduling/constraints/one-shift-per-day.d.ts +7 -0
- package/dist/scheduling/constraints/one-shift-per-day.d.ts.map +1 -0
- package/dist/scheduling/constraints/one-shift-per-day.js +35 -0
- package/dist/scheduling/constraints/overtime.d.ts +47 -0
- package/dist/scheduling/constraints/overtime.d.ts.map +1 -0
- package/dist/scheduling/constraints/overtime.js +149 -0
- package/dist/scheduling/constraints/protections.d.ts +21 -0
- package/dist/scheduling/constraints/protections.d.ts.map +1 -0
- package/dist/scheduling/constraints/protections.js +93 -0
- package/dist/scheduling/constraints/qualification.d.ts +18 -0
- package/dist/scheduling/constraints/qualification.d.ts.map +1 -0
- package/dist/scheduling/constraints/qualification.js +78 -0
- package/dist/scheduling/constraints/rest-days.d.ts +30 -0
- package/dist/scheduling/constraints/rest-days.d.ts.map +1 -0
- package/dist/scheduling/constraints/rest-days.js +133 -0
- package/dist/scheduling/constraints/rolling-hours.d.ts +24 -0
- package/dist/scheduling/constraints/rolling-hours.d.ts.map +1 -0
- package/dist/scheduling/constraints/rolling-hours.js +147 -0
- package/dist/scheduling/constraints/start-interval.d.ts +20 -0
- package/dist/scheduling/constraints/start-interval.d.ts.map +1 -0
- package/dist/scheduling/constraints/start-interval.js +53 -0
- package/dist/scheduling/constraints/support.d.ts +48 -0
- package/dist/scheduling/constraints/support.d.ts.map +1 -0
- package/dist/scheduling/constraints/support.js +97 -0
- package/dist/scheduling/constraints/time-off.d.ts +7 -0
- package/dist/scheduling/constraints/time-off.d.ts.map +1 -0
- package/dist/scheduling/constraints/time-off.js +42 -0
- package/dist/scheduling/constraints/weekly-rest.d.ts +22 -0
- package/dist/scheduling/constraints/weekly-rest.d.ts.map +1 -0
- package/dist/scheduling/constraints/weekly-rest.js +103 -0
- package/dist/scheduling/cost.d.ts +56 -0
- package/dist/scheduling/cost.d.ts.map +1 -0
- package/dist/scheduling/cost.js +120 -0
- package/dist/scheduling/engine/construction.d.ts +22 -0
- package/dist/scheduling/engine/construction.d.ts.map +1 -0
- package/dist/scheduling/engine/construction.js +104 -0
- package/dist/scheduling/engine/explain.d.ts +12 -0
- package/dist/scheduling/engine/explain.d.ts.map +1 -0
- package/dist/scheduling/engine/explain.js +24 -0
- package/dist/scheduling/engine/objective.d.ts +73 -0
- package/dist/scheduling/engine/objective.d.ts.map +1 -0
- package/dist/scheduling/engine/objective.js +164 -0
- package/dist/scheduling/engine/prng.d.ts +5 -0
- package/dist/scheduling/engine/prng.d.ts.map +1 -0
- package/dist/scheduling/engine/prng.js +24 -0
- package/dist/scheduling/engine/propagation.d.ts +19 -0
- package/dist/scheduling/engine/propagation.d.ts.map +1 -0
- package/dist/scheduling/engine/propagation.js +40 -0
- package/dist/scheduling/engine/search.d.ts +50 -0
- package/dist/scheduling/engine/search.d.ts.map +1 -0
- package/dist/scheduling/engine/search.js +127 -0
- package/dist/scheduling/engine/state.d.ts +28 -0
- package/dist/scheduling/engine/state.d.ts.map +1 -0
- package/dist/scheduling/engine/state.js +96 -0
- package/dist/scheduling/engine/timeline.d.ts +179 -0
- package/dist/scheduling/engine/timeline.d.ts.map +1 -0
- package/dist/scheduling/engine/timeline.js +416 -0
- package/dist/scheduling/engine/verdicts.d.ts +18 -0
- package/dist/scheduling/engine/verdicts.d.ts.map +1 -0
- package/dist/scheduling/engine/verdicts.js +74 -0
- package/dist/scheduling/index.d.ts +10 -0
- package/dist/scheduling/index.d.ts.map +1 -0
- package/dist/scheduling/index.js +29 -0
- package/dist/scheduling/model.d.ts +53 -0
- package/dist/scheduling/model.d.ts.map +1 -0
- package/dist/scheduling/model.js +380 -0
- package/dist/scheduling/operations.d.ts +134 -0
- package/dist/scheduling/operations.d.ts.map +1 -0
- package/dist/scheduling/operations.js +376 -0
- package/dist/scheduling/provenance.d.ts +33 -0
- package/dist/scheduling/provenance.d.ts.map +1 -0
- package/dist/scheduling/provenance.js +70 -0
- package/dist/scheduling/rules.d.ts +23 -0
- package/dist/scheduling/rules.d.ts.map +1 -0
- package/dist/scheduling/rules.js +37 -0
- package/dist/scheduling/scheduler.class.d.ts +24 -0
- package/dist/scheduling/scheduler.class.d.ts.map +1 -0
- package/dist/scheduling/scheduler.class.js +150 -0
- package/dist/scheduling/time.d.ts +138 -0
- package/dist/scheduling/time.d.ts.map +1 -0
- package/dist/scheduling/time.js +267 -0
- package/dist/scheduling/types.d.ts +938 -0
- package/dist/scheduling/types.d.ts.map +1 -0
- package/dist/scheduling/types.js +19 -0
- package/dist/types/matcher.d.ts +86 -2
- package/dist/types/matcher.d.ts.map +1 -1
- package/dist/utils/keys.d.ts +1 -0
- package/dist/utils/keys.d.ts.map +1 -1
- package/dist/utils/keys.js +6 -0
- package/package.json +4 -2
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Daily rest — Directive 2003/88/EC Art 3 and its national variants.
|
|
4
|
+
*
|
|
5
|
+
* The EU floor is 11 consecutive hours per 24-hour period; Spain and Romania
|
|
6
|
+
* require 12, Finnish period work allows 9. Derogations under Art 17/18 may
|
|
7
|
+
* reduce it further (8h in NL/DK/CZ, 9h in FR by collective agreement) but only
|
|
8
|
+
* against equivalent compensatory rest — which Jaeger (C-151/02) requires
|
|
9
|
+
* "immediately following" the period worked, and which never licenses breaching
|
|
10
|
+
* the weekly hours cap.
|
|
11
|
+
*
|
|
12
|
+
* Three shapes national law takes that a naive "gap between consecutive shifts"
|
|
13
|
+
* check cannot express, all handled here:
|
|
14
|
+
*
|
|
15
|
+
* - the rest must fit in *every rolling 24h*, not merely between two shifts;
|
|
16
|
+
* - a reduction may be used only so many times per window (NL: once per 7×24h);
|
|
17
|
+
* - the rest may have to *contain* a clock band — Sweden requires the 11h to
|
|
18
|
+
* include 00:00–05:00, which is positional, not a duration at all.
|
|
19
|
+
*/
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.dailyRest = exports.DAILY_REST_CITATION = void 0;
|
|
22
|
+
const support_1 = require("./support");
|
|
23
|
+
exports.DAILY_REST_CITATION = 'Directive 2003/88/EC Art 3';
|
|
24
|
+
function dailyRest(rule) {
|
|
25
|
+
const windowMinutes = rule.perWindowMinutes ?? support_1.MINUTES_PER_DAY;
|
|
26
|
+
// A permitted derogation moves the effective floor down; the allowance on
|
|
27
|
+
// how often it may be used is enforced separately below.
|
|
28
|
+
const floor = rule.reducibleToMinutes ?? rule.minMinutes;
|
|
29
|
+
return (0, support_1.fromVerdict)({
|
|
30
|
+
id: 'daily-rest',
|
|
31
|
+
hardness: 'hard',
|
|
32
|
+
weight: 1,
|
|
33
|
+
citation: exports.DAILY_REST_CITATION,
|
|
34
|
+
verdict(state, pair) {
|
|
35
|
+
const inst = (0, support_1.instanceOf)(state, pair);
|
|
36
|
+
if (!inst)
|
|
37
|
+
return (0, support_1.pass)('daily-rest', 'unknown shift');
|
|
38
|
+
const timeline = (0, support_1.timelineFor)(state, pair.employeeId);
|
|
39
|
+
const range = (0, support_1.rangeOf)(inst);
|
|
40
|
+
const gap = timeline.minGapAround(range, (0, support_1.entryIdOf)(pair));
|
|
41
|
+
if (gap === 0) {
|
|
42
|
+
// Overlapping work is `no-overlap`'s business; reporting it here
|
|
43
|
+
// too would double-count the same defect. A zero gap without an
|
|
44
|
+
// overlap is back-to-back work, and that IS this rule's business
|
|
45
|
+
// — fall through to the floor check.
|
|
46
|
+
const own = (0, support_1.entryIdOf)(pair);
|
|
47
|
+
const overlapping = timeline.entriesIn(range).some((e) => e.id !== own);
|
|
48
|
+
if (overlapping)
|
|
49
|
+
return (0, support_1.pass)('daily-rest', 'overlap is handled by no-overlap');
|
|
50
|
+
}
|
|
51
|
+
if (gap < floor) {
|
|
52
|
+
return (0, support_1.fail)('daily-rest', 'hard', `employee "${pair.employeeId}" would get ${(0, support_1.h)(gap)} rest around "${inst.id}", below the ${(0, support_1.h)(floor)} minimum`, { actual: gap, required: floor, unit: 'minutes', citation: exports.DAILY_REST_CITATION });
|
|
53
|
+
}
|
|
54
|
+
// Art 3 is "per 24-hour period", not "between two shifts". The gap
|
|
55
|
+
// check above misses the case where several duties in one day each
|
|
56
|
+
// leave an acceptable gap but no single stretch of rest reaches the
|
|
57
|
+
// minimum — a 14h duty inside a 24h window cannot yield 11h off,
|
|
58
|
+
// however comfortable the gaps either side of it are.
|
|
59
|
+
const rolling = timeline.withEntry({ ...range, id: (0, support_1.entryIdOf)(pair), workingMinutes: inst.workingMinutes }, (t) => t.minLongestRestInAnyWindow(windowMinutes, {
|
|
60
|
+
start: range.start - windowMinutes,
|
|
61
|
+
end: range.end + windowMinutes,
|
|
62
|
+
}));
|
|
63
|
+
if (rolling < floor) {
|
|
64
|
+
return (0, support_1.fail)('daily-rest', 'hard', `employee "${pair.employeeId}" would have only ${(0, support_1.h)(rolling)} continuous rest in some ${(0, support_1.h)(windowMinutes)} window, below the ${(0, support_1.h)(floor)} minimum`, { actual: rolling, required: floor, unit: 'minutes', citation: exports.DAILY_REST_CITATION });
|
|
65
|
+
}
|
|
66
|
+
// Between the reduced floor and the nominal minimum the assignment
|
|
67
|
+
// is lawful only if a reduction allowance is left.
|
|
68
|
+
if (gap < rule.minMinutes && rule.reductionsPer) {
|
|
69
|
+
const used = countReductions(state, pair, rule);
|
|
70
|
+
if (used > rule.reductionsPer.max) {
|
|
71
|
+
return (0, support_1.fail)('daily-rest', 'hard', `employee "${pair.employeeId}" would use a ${(0, support_1.h)(gap)} reduced rest more than ${rule.reductionsPer.max} time(s) per ${rule.reductionsPer.windowDays} days`, { actual: used, required: rule.reductionsPer.max, unit: 'count', citation: exports.DAILY_REST_CITATION });
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (rule.mustContainClockRange) {
|
|
75
|
+
const intrusion = state.ctx.clock.minutesInClockRange(range, rule.mustContainClockRange);
|
|
76
|
+
if (intrusion > 0) {
|
|
77
|
+
return (0, support_1.fail)('daily-rest', 'hard', `employee "${pair.employeeId}"'s rest must cover ${rule.mustContainClockRange.from}-${rule.mustContainClockRange.to}, but "${inst.id}" works ${(0, support_1.h)(intrusion)} inside it`, { actual: intrusion, required: 0, unit: 'minutes', citation: exports.DAILY_REST_CITATION });
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return (0, support_1.pass)('daily-rest', `${(0, support_1.h)(gap)} rest, at or above the ${(0, support_1.h)(rule.minMinutes)} minimum`, {
|
|
81
|
+
actual: gap,
|
|
82
|
+
required: rule.minMinutes,
|
|
83
|
+
unit: 'minutes',
|
|
84
|
+
citation: exports.DAILY_REST_CITATION,
|
|
85
|
+
});
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
exports.dailyRest = dailyRest;
|
|
90
|
+
/**
|
|
91
|
+
* How many reduced rest periods fall in the allowance window, counting the
|
|
92
|
+
* candidate assignment.
|
|
93
|
+
*
|
|
94
|
+
* Counted over the *gaps between consecutive entries* rather than per entry:
|
|
95
|
+
* one short rest sits between two shifts, so asking each shift about its
|
|
96
|
+
* neighbours would count it twice.
|
|
97
|
+
*/
|
|
98
|
+
function countReductions(state, pair, rule) {
|
|
99
|
+
const inst = state.ctx.instanceById.get(pair.shiftInstanceId);
|
|
100
|
+
const timeline = (0, support_1.timelineFor)(state, pair.employeeId);
|
|
101
|
+
const span = (rule.reductionsPer?.windowDays ?? 7) * support_1.MINUTES_PER_DAY;
|
|
102
|
+
const window = { start: inst.startMinute - span, end: inst.endMinute + span };
|
|
103
|
+
const floor = rule.reducibleToMinutes ?? rule.minMinutes;
|
|
104
|
+
// The candidate is not on the timeline yet, so splice it into the ordered
|
|
105
|
+
// list before measuring the gaps it creates.
|
|
106
|
+
const entries = [...timeline.entriesIn(window).filter((e) => e.id !== (0, support_1.entryIdOf)(pair)), (0, support_1.rangeOf)(inst)].sort((a, b) => a.start - b.start);
|
|
107
|
+
let reductions = 0;
|
|
108
|
+
for (let i = 1; i < entries.length; i++) {
|
|
109
|
+
const gap = entries[i].start - entries[i - 1].end;
|
|
110
|
+
if (gap > 0 && gap < rule.minMinutes && gap >= floor)
|
|
111
|
+
reductions++;
|
|
112
|
+
}
|
|
113
|
+
return reductions;
|
|
114
|
+
}
|
|
115
|
+
/*
|
|
116
|
+
* The clock-band rule reduces to "do not work inside the protected band".
|
|
117
|
+
*
|
|
118
|
+
* An earlier version asked whether *some* nearby night still had an unbroken
|
|
119
|
+
* band free, which passes a shift that eats one night as long as the night
|
|
120
|
+
* before was quiet. Sweden's requirement is that each daily rest include
|
|
121
|
+
* 00:00–05:00, so working through any occurrence of the band breaches it — the
|
|
122
|
+
* check is the intrusion, measured directly on the candidate's own span.
|
|
123
|
+
*/
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Duty-type volume quotas — rolling caps on how much of one duty type a person
|
|
3
|
+
* may hold, matched on `shiftTypeTag`.
|
|
4
|
+
*
|
|
5
|
+
* The canonical case is a stand-by ceiling: "at most 30 hours of *valveaeg* in
|
|
6
|
+
* any month". Working-time limits cannot express it, because a stand-by duty's
|
|
7
|
+
* point is precisely that most of its span does *not* count as working time —
|
|
8
|
+
* so the quota measures **elapsed** duty minutes (how long the duty occupies
|
|
9
|
+
* the person's clock), or a plain occurrence count. Night work has its own
|
|
10
|
+
* quota shape (`NightWorkRule.volumeQuotas`) because "night shift" is a
|
|
11
|
+
* predicate over the clock band, not a tag; everything tag-shaped lands here.
|
|
12
|
+
*
|
|
13
|
+
* Windows are rolling, anchored on the person's own matching duties — a
|
|
14
|
+
* calendar-month grid would miss a run of stand-by straddling the month
|
|
15
|
+
* boundary, which is exactly where such runs cluster.
|
|
16
|
+
*/
|
|
17
|
+
import type { DutyQuota, SchedulingConstraint } from '../types';
|
|
18
|
+
export declare const DUTY_QUOTA_CITATION = "National duty-volume law (e.g. EE T\u00F6\u00F6lepingu seadus \u00A748)";
|
|
19
|
+
export declare function dutyQuotas(quotas: DutyQuota[]): SchedulingConstraint;
|
|
20
|
+
//# sourceMappingURL=duty-quota.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"duty-quota.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/duty-quota.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAe,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAiB7E,eAAO,MAAM,mBAAmB,4EAA6D,CAAC;AAE9F,wBAAgB,UAAU,CAAC,MAAM,EAAE,SAAS,EAAE,GAAG,oBAAoB,CAqDpE"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Duty-type volume quotas — rolling caps on how much of one duty type a person
|
|
4
|
+
* may hold, matched on `shiftTypeTag`.
|
|
5
|
+
*
|
|
6
|
+
* The canonical case is a stand-by ceiling: "at most 30 hours of *valveaeg* in
|
|
7
|
+
* any month". Working-time limits cannot express it, because a stand-by duty's
|
|
8
|
+
* point is precisely that most of its span does *not* count as working time —
|
|
9
|
+
* so the quota measures **elapsed** duty minutes (how long the duty occupies
|
|
10
|
+
* the person's clock), or a plain occurrence count. Night work has its own
|
|
11
|
+
* quota shape (`NightWorkRule.volumeQuotas`) because "night shift" is a
|
|
12
|
+
* predicate over the clock band, not a tag; everything tag-shaped lands here.
|
|
13
|
+
*
|
|
14
|
+
* Windows are rolling, anchored on the person's own matching duties — a
|
|
15
|
+
* calendar-month grid would miss a run of stand-by straddling the month
|
|
16
|
+
* boundary, which is exactly where such runs cluster.
|
|
17
|
+
*/
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.dutyQuotas = exports.DUTY_QUOTA_CITATION = void 0;
|
|
20
|
+
const time_1 = require("../time");
|
|
21
|
+
const support_1 = require("./support");
|
|
22
|
+
exports.DUTY_QUOTA_CITATION = 'National duty-volume law (e.g. EE Töölepingu seadus §48)';
|
|
23
|
+
function dutyQuotas(quotas) {
|
|
24
|
+
return (0, support_1.fromVerdict)({
|
|
25
|
+
id: 'duty-quota',
|
|
26
|
+
hardness: 'hard',
|
|
27
|
+
weight: 1,
|
|
28
|
+
citation: exports.DUTY_QUOTA_CITATION,
|
|
29
|
+
verdict(state, pair) {
|
|
30
|
+
const inst = (0, support_1.instanceOf)(state, pair);
|
|
31
|
+
if (!inst)
|
|
32
|
+
return (0, support_1.pass)('duty-quota', 'unknown shift');
|
|
33
|
+
if (!inst.shiftTypeTag)
|
|
34
|
+
return (0, support_1.pass)('duty-quota', 'shift has no duty type');
|
|
35
|
+
const applied = (0, support_1.rulesFor)(state.ctx, pair.employeeId).dutyQuotas ?? quotas;
|
|
36
|
+
const applicable = applied.filter((q) => q.shiftTypeTag === inst.shiftTypeTag);
|
|
37
|
+
if (applicable.length === 0)
|
|
38
|
+
return (0, support_1.pass)('duty-quota', `no quota covers "${inst.shiftTypeTag}"`);
|
|
39
|
+
const timeline = (0, support_1.timelineFor)(state, pair.employeeId);
|
|
40
|
+
const range = (0, support_1.rangeOf)(inst);
|
|
41
|
+
const probe = { ...range, id: (0, support_1.entryIdOf)(pair), workingMinutes: inst.workingMinutes, tag: inst.shiftTypeTag };
|
|
42
|
+
return timeline.withEntry(probe, (t) => {
|
|
43
|
+
for (const quota of applicable) {
|
|
44
|
+
const span = quota.windowDays * support_1.MINUTES_PER_DAY;
|
|
45
|
+
const citation = quota.citation ?? exports.DUTY_QUOTA_CITATION;
|
|
46
|
+
const label = quota.label ?? `${quota.shiftTypeTag} / ${quota.windowDays}d`;
|
|
47
|
+
if (quota.maxMinutes !== undefined) {
|
|
48
|
+
const worst = worstTagged(t, quota.shiftTypeTag, span, range, sumElapsed);
|
|
49
|
+
if (worst > quota.maxMinutes) {
|
|
50
|
+
return (0, support_1.fail)('duty-quota', 'hard', `employee "${pair.employeeId}" would hold ${(0, support_1.h)(worst)} of "${quota.shiftTypeTag}" duty in some ${quota.windowDays}-day window, over the ${(0, support_1.h)(quota.maxMinutes)} quota (${label})`, { actual: worst, required: quota.maxMinutes, unit: 'minutes', citation });
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (quota.maxCount !== undefined) {
|
|
54
|
+
const worst = worstTagged(t, quota.shiftTypeTag, span, range, (hits) => hits.length);
|
|
55
|
+
if (worst > quota.maxCount) {
|
|
56
|
+
return (0, support_1.fail)('duty-quota', 'hard', `employee "${pair.employeeId}" would hold ${worst} "${quota.shiftTypeTag}" duties in some ${quota.windowDays}-day window, over the ${quota.maxCount} quota (${label})`, { actual: worst, required: quota.maxCount, unit: 'count', citation });
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return (0, support_1.pass)('duty-quota', 'within every configured duty quota', { citation: exports.DUTY_QUOTA_CITATION });
|
|
61
|
+
});
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
exports.dutyQuotas = dutyQuotas;
|
|
66
|
+
/**
|
|
67
|
+
* Worst value of `measure` over matching entries intersected with any window of
|
|
68
|
+
* `span` minutes near `range`. Candidate left edges sit on matching-entry
|
|
69
|
+
* boundaries — sliding a window until an edge meets a boundary never reduces
|
|
70
|
+
* the extreme being sought, so this finite set contains the answer.
|
|
71
|
+
*/
|
|
72
|
+
function worstTagged(timeline, tag, span, range, measure) {
|
|
73
|
+
const bounds = { start: range.start - 2 * span, end: range.end + 2 * span };
|
|
74
|
+
const matching = timeline.entriesIn(bounds).filter((e) => e.tag === tag);
|
|
75
|
+
if (matching.length === 0)
|
|
76
|
+
return 0;
|
|
77
|
+
const starts = new Set();
|
|
78
|
+
for (const entry of matching) {
|
|
79
|
+
starts.add(entry.start);
|
|
80
|
+
starts.add(entry.end - span);
|
|
81
|
+
}
|
|
82
|
+
let worst = 0;
|
|
83
|
+
for (const start of starts) {
|
|
84
|
+
const window = { start, end: start + span };
|
|
85
|
+
const hits = matching.filter((e) => e.start < window.end && e.end > window.start);
|
|
86
|
+
const value = measure(hits, window);
|
|
87
|
+
if (value > worst)
|
|
88
|
+
worst = value;
|
|
89
|
+
}
|
|
90
|
+
return worst;
|
|
91
|
+
}
|
|
92
|
+
/** Elapsed duty minutes inside the window, counting partial overlaps. */
|
|
93
|
+
function sumElapsed(hits, window) {
|
|
94
|
+
return hits.reduce((sum, entry) => sum + (0, time_1.overlapMinutes)(entry, window), 0);
|
|
95
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimum engagement — the rules that decouple *paid* from *worked*.
|
|
3
|
+
*
|
|
4
|
+
* Belgium requires at least three hours per work session (Labour Act 1971
|
|
5
|
+
* art. 21); the Netherlands pays an on-call worker a minimum of three hours per
|
|
6
|
+
* call and credits 30 minutes for any call-out; Germany's TzBfG §12 implies
|
|
7
|
+
* three consecutive hours where none is agreed; Ireland owes the lesser of 25%
|
|
8
|
+
* of contracted hours or 15 hours when someone is sent home early.
|
|
9
|
+
*
|
|
10
|
+
* These constrain *shift design* rather than assignment — a two-hour shift is
|
|
11
|
+
* unlawful in Belgium no matter who works it — so the breach is reported once
|
|
12
|
+
* per instance, and the paid-minutes floor is surfaced for the cost model
|
|
13
|
+
* rather than folded into working time, since a minimum payment does not make
|
|
14
|
+
* the time count against a working-time limit.
|
|
15
|
+
*/
|
|
16
|
+
import type { EngagementRule, SchedulingConstraint, ShiftInstance } from '../types';
|
|
17
|
+
export declare const ENGAGEMENT_CITATION = "National minimum-engagement law (e.g. BE Labour Act 1971 art. 21)";
|
|
18
|
+
export declare function engagementFloor(rule: EngagementRule): SchedulingConstraint;
|
|
19
|
+
/**
|
|
20
|
+
* Minutes that must be *paid* for a shift, which can exceed the minutes worked.
|
|
21
|
+
*
|
|
22
|
+
* Kept separate from working time deliberately: a three-hour minimum payment for
|
|
23
|
+
* a one-hour call-out costs three hours of wages and one hour of the worker's
|
|
24
|
+
* 48-hour weekly allowance. Folding the floor into working time would overstate
|
|
25
|
+
* the second.
|
|
26
|
+
*/
|
|
27
|
+
export declare function paidMinutesFor(inst: ShiftInstance, rule: EngagementRule | undefined): number;
|
|
28
|
+
//# sourceMappingURL=engagement-floor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engagement-floor.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/engagement-floor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAuB,cAAc,EAAe,oBAAoB,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAGtH,eAAO,MAAM,mBAAmB,sEAAsE,CAAC;AAEvG,wBAAgB,eAAe,CAAC,IAAI,EAAE,cAAc,GAAG,oBAAoB,CAiD1E;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,cAAc,GAAG,SAAS,GAAG,MAAM,CAG5F"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Minimum engagement — the rules that decouple *paid* from *worked*.
|
|
4
|
+
*
|
|
5
|
+
* Belgium requires at least three hours per work session (Labour Act 1971
|
|
6
|
+
* art. 21); the Netherlands pays an on-call worker a minimum of three hours per
|
|
7
|
+
* call and credits 30 minutes for any call-out; Germany's TzBfG §12 implies
|
|
8
|
+
* three consecutive hours where none is agreed; Ireland owes the lesser of 25%
|
|
9
|
+
* of contracted hours or 15 hours when someone is sent home early.
|
|
10
|
+
*
|
|
11
|
+
* These constrain *shift design* rather than assignment — a two-hour shift is
|
|
12
|
+
* unlawful in Belgium no matter who works it — so the breach is reported once
|
|
13
|
+
* per instance, and the paid-minutes floor is surfaced for the cost model
|
|
14
|
+
* rather than folded into working time, since a minimum payment does not make
|
|
15
|
+
* the time count against a working-time limit.
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.paidMinutesFor = exports.engagementFloor = exports.ENGAGEMENT_CITATION = void 0;
|
|
19
|
+
const support_1 = require("./support");
|
|
20
|
+
exports.ENGAGEMENT_CITATION = 'National minimum-engagement law (e.g. BE Labour Act 1971 art. 21)';
|
|
21
|
+
function engagementFloor(rule) {
|
|
22
|
+
const tooShort = (inst) => rule.minShiftMinutes !== undefined && inst.durationMinutes < rule.minShiftMinutes;
|
|
23
|
+
const constraint = (0, support_1.fromVerdict)({
|
|
24
|
+
id: 'engagement-floor',
|
|
25
|
+
hardness: 'hard',
|
|
26
|
+
weight: 1,
|
|
27
|
+
citation: exports.ENGAGEMENT_CITATION,
|
|
28
|
+
verdict(state, pair) {
|
|
29
|
+
const inst = (0, support_1.instanceOf)(state, pair);
|
|
30
|
+
if (!inst)
|
|
31
|
+
return (0, support_1.pass)('engagement-floor', 'unknown shift');
|
|
32
|
+
if (tooShort(inst)) {
|
|
33
|
+
return (0, support_1.fail)('engagement-floor', 'hard', `shift "${inst.id}" is ${(0, support_1.h)(inst.durationMinutes)}, below the ${(0, support_1.h)(rule.minShiftMinutes)} minimum engagement`, {
|
|
34
|
+
actual: inst.durationMinutes,
|
|
35
|
+
required: rule.minShiftMinutes,
|
|
36
|
+
unit: 'minutes',
|
|
37
|
+
citation: exports.ENGAGEMENT_CITATION,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
return (0, support_1.pass)('engagement-floor', 'meets the minimum engagement', { citation: exports.ENGAGEMENT_CITATION });
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
constraint.evaluate = (state) => {
|
|
44
|
+
const out = [];
|
|
45
|
+
for (const inst of state.ctx.instances) {
|
|
46
|
+
if ((state.assignments.get(inst.id)?.size ?? 0) === 0)
|
|
47
|
+
continue;
|
|
48
|
+
if (!tooShort(inst))
|
|
49
|
+
continue;
|
|
50
|
+
out.push({
|
|
51
|
+
constraintId: 'engagement-floor',
|
|
52
|
+
severity: 'hard',
|
|
53
|
+
shiftInstanceId: inst.id,
|
|
54
|
+
message: `shift "${inst.id}" is ${(0, support_1.h)(inst.durationMinutes)}, below the ${(0, support_1.h)(rule.minShiftMinutes)} minimum engagement`,
|
|
55
|
+
actual: inst.durationMinutes,
|
|
56
|
+
required: rule.minShiftMinutes,
|
|
57
|
+
unit: 'minutes',
|
|
58
|
+
citation: exports.ENGAGEMENT_CITATION,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
return out;
|
|
62
|
+
};
|
|
63
|
+
return constraint;
|
|
64
|
+
}
|
|
65
|
+
exports.engagementFloor = engagementFloor;
|
|
66
|
+
/**
|
|
67
|
+
* Minutes that must be *paid* for a shift, which can exceed the minutes worked.
|
|
68
|
+
*
|
|
69
|
+
* Kept separate from working time deliberately: a three-hour minimum payment for
|
|
70
|
+
* a one-hour call-out costs three hours of wages and one hour of the worker's
|
|
71
|
+
* 48-hour weekly allowance. Folding the floor into working time would overstate
|
|
72
|
+
* the second.
|
|
73
|
+
*/
|
|
74
|
+
function paidMinutesFor(inst, rule) {
|
|
75
|
+
if (!rule?.minPaidMinutesPerEngagement)
|
|
76
|
+
return inst.workingMinutes;
|
|
77
|
+
return Math.max(inst.workingMinutes, rule.minPaidMinutesPerEngagement);
|
|
78
|
+
}
|
|
79
|
+
exports.paidMinutesFor = paidMinutesFor;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fairness — equalising load across the team.
|
|
3
|
+
*
|
|
4
|
+
* Three deliberate choices:
|
|
5
|
+
*
|
|
6
|
+
* 1. **Per dimension, separately.** Equal total hours says nothing about who
|
|
7
|
+
* takes the nights. Two people can work identical hours while one does every
|
|
8
|
+
* weekend, so hours, nights, weekends and holidays are balanced as separate
|
|
9
|
+
* dimensions rather than rolled into one number.
|
|
10
|
+
*
|
|
11
|
+
* 2. **L1 deviation, not variance.** Variance is quadratic and non-decomposable:
|
|
12
|
+
* changing one person's load changes every other person's contribution
|
|
13
|
+
* through the mean, so it cannot be evaluated incrementally. Summed absolute
|
|
14
|
+
* deviation from the fair share gives the same ordering pressure and stays
|
|
15
|
+
* local.
|
|
16
|
+
*
|
|
17
|
+
* 3. **Realised counts only.** The fair share is computed from what people have
|
|
18
|
+
* actually been assigned, plus `carriedFairness` from previous periods. No
|
|
19
|
+
* behavioural or predictive signal enters — that boundary is what keeps this
|
|
20
|
+
* a constraint solver rather than profiling under AI Act Annex III 4(b).
|
|
21
|
+
*
|
|
22
|
+
* Pro-rata weighting matters legally as well as morally: the part-time,
|
|
23
|
+
* fixed-term and agency directives all require equal treatment on a pro rata
|
|
24
|
+
* temporis basis, so a half-time worker's fair share is half.
|
|
25
|
+
*/
|
|
26
|
+
import type { FairnessRule, SchedulingConstraint, SearchState } from '../types';
|
|
27
|
+
export declare const FAIRNESS_CITATION = "Directive 97/81/EC cl. 4 (pro rata temporis)";
|
|
28
|
+
export declare function fairness(rules: FairnessRule[]): SchedulingConstraint;
|
|
29
|
+
/**
|
|
30
|
+
* Summed absolute deviation from the fair share, across every dimension.
|
|
31
|
+
* Lower is fairer. The objective adds this, weighted, at the soft level.
|
|
32
|
+
*/
|
|
33
|
+
export declare function fairnessPenalty(state: SearchState, rules: FairnessRule[] | undefined): number;
|
|
34
|
+
//# sourceMappingURL=fairness.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fairness.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/fairness.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,KAAK,EAAuB,YAAY,EAAE,oBAAoB,EAAE,WAAW,EAAiB,MAAM,UAAU,CAAC;AAEpH,eAAO,MAAM,iBAAiB,iDAAiD,CAAC;AAEhF,wBAAgB,QAAQ,CAAC,KAAK,EAAE,YAAY,EAAE,GAAG,oBAAoB,CAmCpE;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,YAAY,EAAE,GAAG,SAAS,GAAG,MAAM,CAiB7F"}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Fairness — equalising load across the team.
|
|
4
|
+
*
|
|
5
|
+
* Three deliberate choices:
|
|
6
|
+
*
|
|
7
|
+
* 1. **Per dimension, separately.** Equal total hours says nothing about who
|
|
8
|
+
* takes the nights. Two people can work identical hours while one does every
|
|
9
|
+
* weekend, so hours, nights, weekends and holidays are balanced as separate
|
|
10
|
+
* dimensions rather than rolled into one number.
|
|
11
|
+
*
|
|
12
|
+
* 2. **L1 deviation, not variance.** Variance is quadratic and non-decomposable:
|
|
13
|
+
* changing one person's load changes every other person's contribution
|
|
14
|
+
* through the mean, so it cannot be evaluated incrementally. Summed absolute
|
|
15
|
+
* deviation from the fair share gives the same ordering pressure and stays
|
|
16
|
+
* local.
|
|
17
|
+
*
|
|
18
|
+
* 3. **Realised counts only.** The fair share is computed from what people have
|
|
19
|
+
* actually been assigned, plus `carriedFairness` from previous periods. No
|
|
20
|
+
* behavioural or predictive signal enters — that boundary is what keeps this
|
|
21
|
+
* a constraint solver rather than profiling under AI Act Annex III 4(b).
|
|
22
|
+
*
|
|
23
|
+
* Pro-rata weighting matters legally as well as morally: the part-time,
|
|
24
|
+
* fixed-term and agency directives all require equal treatment on a pro rata
|
|
25
|
+
* temporis basis, so a half-time worker's fair share is half.
|
|
26
|
+
*/
|
|
27
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
+
exports.fairnessPenalty = exports.fairness = exports.FAIRNESS_CITATION = void 0;
|
|
29
|
+
exports.FAIRNESS_CITATION = 'Directive 97/81/EC cl. 4 (pro rata temporis)';
|
|
30
|
+
function fairness(rules) {
|
|
31
|
+
return {
|
|
32
|
+
id: 'fairness',
|
|
33
|
+
hardness: 'soft',
|
|
34
|
+
weight: 1,
|
|
35
|
+
citation: exports.FAIRNESS_CITATION,
|
|
36
|
+
// Fairness is a property of the whole roster; no single assignment
|
|
37
|
+
// breaches it, so the pair-scoped hooks stay silent by construction.
|
|
38
|
+
delta: () => 0,
|
|
39
|
+
explain: () => null,
|
|
40
|
+
evaluate(state) {
|
|
41
|
+
const out = [];
|
|
42
|
+
for (const rule of rules) {
|
|
43
|
+
const loads = loadsFor(state, rule);
|
|
44
|
+
if (loads.size === 0)
|
|
45
|
+
continue;
|
|
46
|
+
const values = [...loads.values()];
|
|
47
|
+
const spread = Math.max(...values) - Math.min(...values);
|
|
48
|
+
if (rule.hardMaxSpread === undefined || spread <= rule.hardMaxSpread)
|
|
49
|
+
continue;
|
|
50
|
+
const highest = [...loads.entries()].sort((a, b) => b[1] - a[1])[0];
|
|
51
|
+
out.push({
|
|
52
|
+
constraintId: 'fairness',
|
|
53
|
+
severity: 'medium',
|
|
54
|
+
employeeId: highest[0],
|
|
55
|
+
message: `${label(rule)} spread across the team is ${round(spread)}, over the ${rule.hardMaxSpread} maximum (highest: "${highest[0]}" at ${round(highest[1])})`,
|
|
56
|
+
actual: spread,
|
|
57
|
+
required: rule.hardMaxSpread,
|
|
58
|
+
unit: 'count',
|
|
59
|
+
citation: exports.FAIRNESS_CITATION,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
return out;
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
exports.fairness = fairness;
|
|
67
|
+
/**
|
|
68
|
+
* Summed absolute deviation from the fair share, across every dimension.
|
|
69
|
+
* Lower is fairer. The objective adds this, weighted, at the soft level.
|
|
70
|
+
*/
|
|
71
|
+
function fairnessPenalty(state, rules) {
|
|
72
|
+
if (!rules?.length)
|
|
73
|
+
return 0;
|
|
74
|
+
let penalty = 0;
|
|
75
|
+
for (const rule of rules) {
|
|
76
|
+
const loads = loadsFor(state, rule);
|
|
77
|
+
if (loads.size === 0)
|
|
78
|
+
continue;
|
|
79
|
+
const shares = shareWeights(state, rule, [...loads.keys()]);
|
|
80
|
+
const total = [...loads.values()].reduce((a, b) => a + b, 0);
|
|
81
|
+
const totalShare = [...shares.values()].reduce((a, b) => a + b, 0) || 1;
|
|
82
|
+
for (const [employeeId, load] of loads) {
|
|
83
|
+
const fair = (total * (shares.get(employeeId) ?? 1)) / totalShare;
|
|
84
|
+
penalty += Math.abs(load - fair) * (rule.weight ?? 1);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return penalty;
|
|
88
|
+
}
|
|
89
|
+
exports.fairnessPenalty = fairnessPenalty;
|
|
90
|
+
/** Per-employee load on one dimension, including counts carried in from prior periods. */
|
|
91
|
+
function loadsFor(state, rule) {
|
|
92
|
+
const key = rule.dimension === 'tag' ? `tag:${rule.tag}` : rule.dimension;
|
|
93
|
+
const loads = new Map();
|
|
94
|
+
for (const employee of state.ctx.employees) {
|
|
95
|
+
let load = employee.carriedFairness?.[key] ?? 0;
|
|
96
|
+
for (const instanceId of state.byEmployee.get(employee.id) ?? []) {
|
|
97
|
+
const inst = state.ctx.instanceById.get(instanceId);
|
|
98
|
+
if (inst)
|
|
99
|
+
load += contribution(rule, inst);
|
|
100
|
+
}
|
|
101
|
+
loads.set(employee.id, load);
|
|
102
|
+
}
|
|
103
|
+
return loads;
|
|
104
|
+
}
|
|
105
|
+
function contribution(rule, inst) {
|
|
106
|
+
switch (rule.dimension) {
|
|
107
|
+
case 'minutes':
|
|
108
|
+
return inst.workingMinutes;
|
|
109
|
+
case 'shifts':
|
|
110
|
+
return 1;
|
|
111
|
+
case 'nights':
|
|
112
|
+
return inst.isNightShift ? 1 : 0;
|
|
113
|
+
case 'weekends':
|
|
114
|
+
return inst.weekday === 6 || inst.weekday === 7 ? 1 : 0;
|
|
115
|
+
case 'holidays':
|
|
116
|
+
return inst.isPublicHoliday ? 1 : 0;
|
|
117
|
+
case 'tag':
|
|
118
|
+
// The load being equalised is shifts *of this type* — matched on the
|
|
119
|
+
// instance's shiftTypeTag, like every other tag-shaped rule. Counting
|
|
120
|
+
// the employee's own tag would just re-count tagged people's totals
|
|
121
|
+
// and pin untagged people at a constant zero.
|
|
122
|
+
return rule.tag !== undefined && inst.shiftTypeTag === rule.tag ? 1 : 0;
|
|
123
|
+
default:
|
|
124
|
+
return 0;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Each person's entitlement weight. Equal by default; proportional to
|
|
129
|
+
* contracted hours when `proRataByContract` is set, which is what the equal
|
|
130
|
+
* treatment directives require for part-timers.
|
|
131
|
+
*/
|
|
132
|
+
function shareWeights(state, rule, employeeIds) {
|
|
133
|
+
const weights = new Map();
|
|
134
|
+
for (const id of employeeIds) {
|
|
135
|
+
if (!rule.proRataByContract) {
|
|
136
|
+
weights.set(id, 1);
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
const weekly = state.ctx.employeeById.get(id)?.contract?.weeklyMinutes;
|
|
140
|
+
weights.set(id, weekly && weekly > 0 ? weekly : 1);
|
|
141
|
+
}
|
|
142
|
+
return weights;
|
|
143
|
+
}
|
|
144
|
+
function label(rule) {
|
|
145
|
+
return rule.dimension === 'tag' ? `"${rule.tag}" shift` : rule.dimension;
|
|
146
|
+
}
|
|
147
|
+
function round(value) {
|
|
148
|
+
return Math.round(value * 10) / 10;
|
|
149
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Group composition — cardinality rules over the *set* assigned to a shift.
|
|
3
|
+
*
|
|
4
|
+
* A different shape from per-employee skill matching, and the one naive engines
|
|
5
|
+
* miss: "at least one senior on every shift", "at most two trainees", "no fewer
|
|
6
|
+
* than 60% registered nurses". None of these are properties of an individual
|
|
7
|
+
* assignment — each is satisfiable or not only once you know the whole team on
|
|
8
|
+
* that shift — so they cannot be expressed as a `delta` on one pair.
|
|
9
|
+
*
|
|
10
|
+
* They are also the rules operational buyers ask about first. German ward
|
|
11
|
+
* staffing (PpUGV) is a ratio by ward and shift; supervision limits on trainees
|
|
12
|
+
* are a maximum; "never work alone" is a floor of two.
|
|
13
|
+
*
|
|
14
|
+
* Maximums *can* be breached by a single assignment, so those are checked per
|
|
15
|
+
* pair as well as reported per instance. Minimums can only ever be reported.
|
|
16
|
+
*/
|
|
17
|
+
import type { SchedulingConstraint } from '../types';
|
|
18
|
+
export declare function groupComposition(): SchedulingConstraint;
|
|
19
|
+
//# sourceMappingURL=group-composition.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"group-composition.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/group-composition.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAoC,oBAAoB,EAA8B,MAAM,UAAU,CAAC;AAGnH,wBAAgB,gBAAgB,IAAI,oBAAoB,CA2EvD"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Group composition — cardinality rules over the *set* assigned to a shift.
|
|
4
|
+
*
|
|
5
|
+
* A different shape from per-employee skill matching, and the one naive engines
|
|
6
|
+
* miss: "at least one senior on every shift", "at most two trainees", "no fewer
|
|
7
|
+
* than 60% registered nurses". None of these are properties of an individual
|
|
8
|
+
* assignment — each is satisfiable or not only once you know the whole team on
|
|
9
|
+
* that shift — so they cannot be expressed as a `delta` on one pair.
|
|
10
|
+
*
|
|
11
|
+
* They are also the rules operational buyers ask about first. German ward
|
|
12
|
+
* staffing (PpUGV) is a ratio by ward and shift; supervision limits on trainees
|
|
13
|
+
* are a maximum; "never work alone" is a floor of two.
|
|
14
|
+
*
|
|
15
|
+
* Maximums *can* be breached by a single assignment, so those are checked per
|
|
16
|
+
* pair as well as reported per instance. Minimums can only ever be reported.
|
|
17
|
+
*/
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.groupComposition = void 0;
|
|
20
|
+
const support_1 = require("./support");
|
|
21
|
+
function groupComposition() {
|
|
22
|
+
const constraint = (0, support_1.fromVerdict)({
|
|
23
|
+
id: 'group-composition',
|
|
24
|
+
hardness: 'hard',
|
|
25
|
+
weight: 1,
|
|
26
|
+
verdict(state, pair) {
|
|
27
|
+
const inst = (0, support_1.instanceOf)(state, pair);
|
|
28
|
+
if (!inst)
|
|
29
|
+
return (0, support_1.pass)('group-composition', 'unknown shift');
|
|
30
|
+
const assigned = state.assignments.get(inst.id) ?? new Set();
|
|
31
|
+
const wouldBe = assigned.has(pair.employeeId) ? assigned.size : assigned.size + 1;
|
|
32
|
+
if (inst.maxEmployees !== undefined && wouldBe > inst.maxEmployees) {
|
|
33
|
+
return (0, support_1.fail)('group-composition', 'hard', `"${inst.id}" already has its maximum of ${inst.maxEmployees} assignees`, { actual: wouldBe, required: inst.maxEmployees, unit: 'count' });
|
|
34
|
+
}
|
|
35
|
+
for (const [tag, max] of Object.entries(inst.tagMaximums)) {
|
|
36
|
+
if (!state.ctx.employeeTags.get(pair.employeeId)?.has(tag))
|
|
37
|
+
continue;
|
|
38
|
+
const current = countTag(state, inst, tag, pair.employeeId);
|
|
39
|
+
if (current + 1 > max) {
|
|
40
|
+
return (0, support_1.fail)('group-composition', 'hard', `"${inst.id}" already has its maximum of ${max} assignee(s) tagged "${tag}"`, { actual: current + 1, required: max, unit: 'count' });
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return (0, support_1.pass)('group-composition', 'composition limits respected');
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
constraint.evaluate = (state) => {
|
|
47
|
+
const out = [];
|
|
48
|
+
for (const inst of state.ctx.instances) {
|
|
49
|
+
const assigned = state.assignments.get(inst.id);
|
|
50
|
+
if (!assigned || assigned.size === 0)
|
|
51
|
+
continue;
|
|
52
|
+
for (const [tag, max] of Object.entries(inst.tagMaximums)) {
|
|
53
|
+
const count = countTag(state, inst, tag);
|
|
54
|
+
if (count > max) {
|
|
55
|
+
out.push({
|
|
56
|
+
constraintId: 'group-composition',
|
|
57
|
+
severity: 'hard',
|
|
58
|
+
shiftInstanceId: inst.id,
|
|
59
|
+
message: `shift "${inst.id}" has ${count} assignee(s) tagged "${tag}", over the maximum of ${max}`,
|
|
60
|
+
actual: count,
|
|
61
|
+
required: max,
|
|
62
|
+
unit: 'count',
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (inst.maxEmployees !== undefined && assigned.size > inst.maxEmployees) {
|
|
67
|
+
out.push({
|
|
68
|
+
constraintId: 'group-composition',
|
|
69
|
+
severity: 'hard',
|
|
70
|
+
shiftInstanceId: inst.id,
|
|
71
|
+
message: `shift "${inst.id}" has ${assigned.size} assignees, over the maximum of ${inst.maxEmployees}`,
|
|
72
|
+
actual: assigned.size,
|
|
73
|
+
required: inst.maxEmployees,
|
|
74
|
+
unit: 'count',
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return out;
|
|
79
|
+
};
|
|
80
|
+
return constraint;
|
|
81
|
+
}
|
|
82
|
+
exports.groupComposition = groupComposition;
|
|
83
|
+
function countTag(state, inst, tag, exclude) {
|
|
84
|
+
let count = 0;
|
|
85
|
+
for (const employeeId of state.assignments.get(inst.id) ?? []) {
|
|
86
|
+
if (employeeId === exclude)
|
|
87
|
+
continue;
|
|
88
|
+
if (state.ctx.employeeTags.get(employeeId)?.has(tag))
|
|
89
|
+
count++;
|
|
90
|
+
}
|
|
91
|
+
return count;
|
|
92
|
+
}
|