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,215 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Sequence rules — limits on runs rather than on totals.
|
|
4
|
+
*
|
|
5
|
+
* These are the rules a per-assignment check structurally cannot see, because
|
|
6
|
+
* the breach lives in the *pattern*, not in any one shift:
|
|
7
|
+
*
|
|
8
|
+
* - **Consecutive working days.** Portugal caps a shift worker at six.
|
|
9
|
+
* - **Consecutive night shifts, and the rest owed when the run ends.** Finland
|
|
10
|
+
* allows five and then requires 24h off; the Netherlands allows seven (eight
|
|
11
|
+
* by collective agreement) and then requires 46h. Only NL and FI legislate a
|
|
12
|
+
* cap at all — elsewhere it is collective-agreement territory, which is
|
|
13
|
+
* exactly why it has to be configuration rather than a built-in number.
|
|
14
|
+
* - **Forbidden successions.** The "quick return" — a late shift followed by
|
|
15
|
+
* an early one — is the single most-requested constraint in nurse rostering
|
|
16
|
+
* and is invisible to a rest rule whenever the gap technically clears the
|
|
17
|
+
* minimum.
|
|
18
|
+
*/
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.shiftSuccession = exports.consecutiveNights = exports.consecutiveDays = exports.consecutiveConstraints = exports.CONSECUTIVE_CITATION = void 0;
|
|
21
|
+
const support_1 = require("./support");
|
|
22
|
+
exports.CONSECUTIVE_CITATION = 'National working-time law / collective agreement';
|
|
23
|
+
/** Every sequence constraint the rule configures. */
|
|
24
|
+
function consecutiveConstraints(rule) {
|
|
25
|
+
const out = [];
|
|
26
|
+
if (rule.maxWorkingDays !== undefined)
|
|
27
|
+
out.push(consecutiveDays(rule.maxWorkingDays));
|
|
28
|
+
if (rule.maxNightShifts !== undefined || rule.restAfterNightBlockMinutes !== undefined) {
|
|
29
|
+
out.push(consecutiveNights(rule));
|
|
30
|
+
}
|
|
31
|
+
if (rule.forbiddenSuccessions?.length)
|
|
32
|
+
out.push(shiftSuccession(rule.forbiddenSuccessions));
|
|
33
|
+
return out;
|
|
34
|
+
}
|
|
35
|
+
exports.consecutiveConstraints = consecutiveConstraints;
|
|
36
|
+
function consecutiveDays(maxDays) {
|
|
37
|
+
return (0, support_1.fromVerdict)({
|
|
38
|
+
id: 'consecutive-days',
|
|
39
|
+
hardness: 'hard',
|
|
40
|
+
weight: 1,
|
|
41
|
+
citation: exports.CONSECUTIVE_CITATION,
|
|
42
|
+
verdict(state, pair) {
|
|
43
|
+
const inst = (0, support_1.instanceOf)(state, pair);
|
|
44
|
+
if (!inst)
|
|
45
|
+
return (0, support_1.pass)('consecutive-days', 'unknown shift');
|
|
46
|
+
const timeline = (0, support_1.timelineFor)(state, pair.employeeId);
|
|
47
|
+
const probe = { ...(0, support_1.rangeOf)(inst), id: (0, support_1.entryIdOf)(pair), workingMinutes: inst.workingMinutes };
|
|
48
|
+
const clock = state.ctx.clock;
|
|
49
|
+
return timeline.withEntry(probe, (t) => {
|
|
50
|
+
const run = t.longestConsecutiveDays((minute) => clock.dayIndexOfMinute(minute));
|
|
51
|
+
if (run > maxDays) {
|
|
52
|
+
return (0, support_1.fail)('consecutive-days', 'hard', `employee "${pair.employeeId}" would work ${run} consecutive days, over the ${maxDays}-day maximum`, { actual: run, required: maxDays, unit: 'days', citation: exports.CONSECUTIVE_CITATION });
|
|
53
|
+
}
|
|
54
|
+
return (0, support_1.pass)('consecutive-days', `${run} consecutive days, within the ${maxDays}-day maximum`, {
|
|
55
|
+
actual: run,
|
|
56
|
+
required: maxDays,
|
|
57
|
+
unit: 'days',
|
|
58
|
+
citation: exports.CONSECUTIVE_CITATION,
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
exports.consecutiveDays = consecutiveDays;
|
|
65
|
+
function consecutiveNights(rule) {
|
|
66
|
+
return (0, support_1.fromVerdict)({
|
|
67
|
+
id: 'consecutive-nights',
|
|
68
|
+
hardness: 'hard',
|
|
69
|
+
weight: 1,
|
|
70
|
+
citation: exports.CONSECUTIVE_CITATION,
|
|
71
|
+
verdict(state, pair) {
|
|
72
|
+
const inst = (0, support_1.instanceOf)(state, pair);
|
|
73
|
+
if (!inst)
|
|
74
|
+
return (0, support_1.pass)('consecutive-nights', 'unknown shift');
|
|
75
|
+
const timeline = (0, support_1.timelineFor)(state, pair.employeeId);
|
|
76
|
+
const probe = {
|
|
77
|
+
...(0, support_1.rangeOf)(inst),
|
|
78
|
+
id: (0, support_1.entryIdOf)(pair),
|
|
79
|
+
workingMinutes: inst.workingMinutes,
|
|
80
|
+
tag: inst.shiftTypeTag,
|
|
81
|
+
};
|
|
82
|
+
return timeline.withEntry(probe, (t) => {
|
|
83
|
+
const nights = nightRuns(state, t);
|
|
84
|
+
if (rule.maxNightShifts !== undefined) {
|
|
85
|
+
const longest = Math.max(0, ...nights.map((run) => run.length));
|
|
86
|
+
if (longest > rule.maxNightShifts) {
|
|
87
|
+
return (0, support_1.fail)('consecutive-nights', 'hard', `employee "${pair.employeeId}" would work ${longest} consecutive night shifts, over the ${rule.maxNightShifts} maximum`, {
|
|
88
|
+
actual: longest,
|
|
89
|
+
required: rule.maxNightShifts,
|
|
90
|
+
unit: 'count',
|
|
91
|
+
citation: exports.CONSECUTIVE_CITATION,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
// The rest owed once a night block ends. Only completed runs can
|
|
96
|
+
// breach it: a run still in progress has no "after" yet.
|
|
97
|
+
if (rule.restAfterNightBlockMinutes !== undefined) {
|
|
98
|
+
for (const run of nights) {
|
|
99
|
+
if (rule.maxNightShifts !== undefined && run.length < rule.maxNightShifts)
|
|
100
|
+
continue;
|
|
101
|
+
const endOfRun = run[run.length - 1].end;
|
|
102
|
+
const next = t.all().find((e) => e.start >= endOfRun && !run.includes(e));
|
|
103
|
+
if (!next)
|
|
104
|
+
continue;
|
|
105
|
+
const gap = next.start - endOfRun;
|
|
106
|
+
if (gap < rule.restAfterNightBlockMinutes) {
|
|
107
|
+
return (0, support_1.fail)('consecutive-nights', 'hard', `employee "${pair.employeeId}" would get ${(0, support_1.h)(gap)} after a block of ${run.length} night shifts, below the ${(0, support_1.h)(rule.restAfterNightBlockMinutes)} required`, {
|
|
108
|
+
actual: gap,
|
|
109
|
+
required: rule.restAfterNightBlockMinutes,
|
|
110
|
+
unit: 'minutes',
|
|
111
|
+
citation: exports.CONSECUTIVE_CITATION,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return (0, support_1.pass)('consecutive-nights', 'night-shift run and post-block rest within limits', {
|
|
117
|
+
citation: exports.CONSECUTIVE_CITATION,
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
exports.consecutiveNights = consecutiveNights;
|
|
124
|
+
function shiftSuccession(forbidden) {
|
|
125
|
+
return (0, support_1.fromVerdict)({
|
|
126
|
+
id: 'shift-succession',
|
|
127
|
+
hardness: 'hard',
|
|
128
|
+
weight: 1,
|
|
129
|
+
citation: exports.CONSECUTIVE_CITATION,
|
|
130
|
+
verdict(state, pair) {
|
|
131
|
+
const inst = (0, support_1.instanceOf)(state, pair);
|
|
132
|
+
if (!inst)
|
|
133
|
+
return (0, support_1.pass)('shift-succession', 'unknown shift');
|
|
134
|
+
const timeline = (0, support_1.timelineFor)(state, pair.employeeId);
|
|
135
|
+
const range = (0, support_1.rangeOf)(inst);
|
|
136
|
+
const ownId = (0, support_1.entryIdOf)(pair);
|
|
137
|
+
const clock = state.ctx.clock;
|
|
138
|
+
const entries = timeline.all().filter((e) => e.id !== ownId);
|
|
139
|
+
// Nearest neighbour on each side, and only when it is close enough
|
|
140
|
+
// to be a *succession*. "Night followed by early" means the next
|
|
141
|
+
// day, not the next shift whenever it happens to fall: without a
|
|
142
|
+
// bound, a night four days earlier is still the nearest preceding
|
|
143
|
+
// shift and every later early would breach.
|
|
144
|
+
const ownDay = clock.dayIndexOfMinute(range.start);
|
|
145
|
+
const adjacent = (entry) => Math.abs(clock.dayIndexOfMinute(entry.start) - ownDay) <= 1;
|
|
146
|
+
const before = [...entries].reverse().find((e) => e.end <= range.start && adjacent(e));
|
|
147
|
+
const after = entries.find((e) => e.start >= range.end && adjacent(e));
|
|
148
|
+
for (const succession of forbidden) {
|
|
149
|
+
const check = (fromTag, toTag, gap) => {
|
|
150
|
+
if (fromTag !== succession.fromTag || toTag !== succession.toTag)
|
|
151
|
+
return null;
|
|
152
|
+
if (succession.minGapMinutes !== undefined && gap >= succession.minGapMinutes)
|
|
153
|
+
return null;
|
|
154
|
+
const detail = succession.minGapMinutes === undefined
|
|
155
|
+
? 'is not allowed'
|
|
156
|
+
: `needs at least ${(0, support_1.h)(succession.minGapMinutes)}, got ${(0, support_1.h)(gap)}`;
|
|
157
|
+
return (0, support_1.fail)('shift-succession', 'hard', `employee "${pair.employeeId}": a "${succession.fromTag}" shift followed by a "${succession.toTag}" shift ${detail}`, {
|
|
158
|
+
actual: gap,
|
|
159
|
+
required: succession.minGapMinutes,
|
|
160
|
+
unit: 'minutes',
|
|
161
|
+
citation: exports.CONSECUTIVE_CITATION,
|
|
162
|
+
});
|
|
163
|
+
};
|
|
164
|
+
if (before) {
|
|
165
|
+
const breach = check(before.tag, inst.shiftTypeTag, range.start - before.end);
|
|
166
|
+
if (breach)
|
|
167
|
+
return breach;
|
|
168
|
+
}
|
|
169
|
+
if (after) {
|
|
170
|
+
const breach = check(inst.shiftTypeTag, after.tag, after.start - range.end);
|
|
171
|
+
if (breach)
|
|
172
|
+
return breach;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return (0, support_1.pass)('shift-succession', 'shift-type succession allowed', { citation: exports.CONSECUTIVE_CITATION });
|
|
176
|
+
},
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
exports.shiftSuccession = shiftSuccession;
|
|
180
|
+
/**
|
|
181
|
+
* Runs of night shifts on consecutive days.
|
|
182
|
+
*
|
|
183
|
+
* "Consecutive" is by calendar day, not by adjacency in the entry list: a night
|
|
184
|
+
* shift, a day off, then another night shift is two runs of one, even though
|
|
185
|
+
* they are neighbours on the timeline.
|
|
186
|
+
*/
|
|
187
|
+
function nightRuns(state, timeline) {
|
|
188
|
+
const clock = state.ctx.clock;
|
|
189
|
+
const nights = timeline.all().filter((e) => isNight(state, e));
|
|
190
|
+
const runs = [];
|
|
191
|
+
let current = [];
|
|
192
|
+
let previousDay;
|
|
193
|
+
for (const entry of nights) {
|
|
194
|
+
const day = clock.dayIndexOfMinute(entry.start);
|
|
195
|
+
if (previousDay !== undefined && day === previousDay + 1)
|
|
196
|
+
current.push(entry);
|
|
197
|
+
else {
|
|
198
|
+
if (current.length)
|
|
199
|
+
runs.push(current);
|
|
200
|
+
current = [entry];
|
|
201
|
+
}
|
|
202
|
+
previousDay = day;
|
|
203
|
+
}
|
|
204
|
+
if (current.length)
|
|
205
|
+
runs.push(current);
|
|
206
|
+
return runs;
|
|
207
|
+
}
|
|
208
|
+
function isNight(state, entry) {
|
|
209
|
+
const instanceId = entry.id.includes('@@') ? entry.id.slice(entry.id.indexOf('@@') + 2) : entry.id;
|
|
210
|
+
const inst = state.ctx.instanceById.get(instanceId);
|
|
211
|
+
if (inst)
|
|
212
|
+
return inst.isNightShift;
|
|
213
|
+
// Historical entries carry only their tag.
|
|
214
|
+
return entry.tag === 'night';
|
|
215
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Constraint registry — pure logic.
|
|
3
|
+
*
|
|
4
|
+
* Built-ins are the legacy rules re-derived correctly; the registry lets
|
|
5
|
+
* callers override hardness/weights or add customs without engine surgery.
|
|
6
|
+
* Adding a built-in = new file here plus one line in `createDefaultConstraints`.
|
|
7
|
+
*
|
|
8
|
+
* `one-shift-per-day` is opt-in rather than always-on: split shifts are lawful
|
|
9
|
+
* and common (Directive 2003/88/EC Art 17(4)(b) names them explicitly), as is
|
|
10
|
+
* an on-call duty attached to the same day as a rostered shift. `no-overlap`
|
|
11
|
+
* plus `min-rest` already prevent the physically impossible cases, so forcing
|
|
12
|
+
* one shift per calendar day is a policy choice, not a safety net.
|
|
13
|
+
*/
|
|
14
|
+
import type { ObjectiveWeights, SchedulingConstraint, WorkingTimeRules } from '../types';
|
|
15
|
+
export interface DefaultConstraintOptions {
|
|
16
|
+
/** Minimum rest between consecutive assignments, in minutes. */
|
|
17
|
+
minRestMinutes: number;
|
|
18
|
+
/** Whether to enforce at most one shift per calendar day. Defaults to false. */
|
|
19
|
+
oneShiftPerDay?: boolean;
|
|
20
|
+
/** The labour-law layer. Each family present here registers its constraint. */
|
|
21
|
+
rules?: WorkingTimeRules;
|
|
22
|
+
/** Optional soft-objective terms; a positive cost weight registers the cost term. */
|
|
23
|
+
objectives?: ObjectiveWeights;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The built-in constraints in evaluation order.
|
|
27
|
+
*
|
|
28
|
+
* The always-on set is the physical/contractual core. Everything driven by
|
|
29
|
+
* `WorkingTimeRules` registers only when its rule family is present, so a
|
|
30
|
+
* caller who supplies no rules pays for nothing, and a sectoral regime that
|
|
31
|
+
* *replaces* a Working Time Directive rule (Art 14/20/21) omits it rather than
|
|
32
|
+
* widening its bounds.
|
|
33
|
+
*/
|
|
34
|
+
export declare function createDefaultConstraints(options: DefaultConstraintOptions): SchedulingConstraint[];
|
|
35
|
+
//# sourceMappingURL=constraint.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constraint.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/constraint.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AA4BzF,MAAM,WAAW,wBAAwB;IACrC,gEAAgE;IAChE,cAAc,EAAE,MAAM,CAAC;IACvB,gFAAgF;IAChF,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,+EAA+E;IAC/E,KAAK,CAAC,EAAE,gBAAgB,CAAC;IACzB,qFAAqF;IACrF,UAAU,CAAC,EAAE,gBAAgB,CAAC;CACjC;AAED;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,wBAAwB,GAAG,oBAAoB,EAAE,CAkClG"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Constraint registry — pure logic.
|
|
4
|
+
*
|
|
5
|
+
* Built-ins are the legacy rules re-derived correctly; the registry lets
|
|
6
|
+
* callers override hardness/weights or add customs without engine surgery.
|
|
7
|
+
* Adding a built-in = new file here plus one line in `createDefaultConstraints`.
|
|
8
|
+
*
|
|
9
|
+
* `one-shift-per-day` is opt-in rather than always-on: split shifts are lawful
|
|
10
|
+
* and common (Directive 2003/88/EC Art 17(4)(b) names them explicitly), as is
|
|
11
|
+
* an on-call duty attached to the same day as a rostered shift. `no-overlap`
|
|
12
|
+
* plus `min-rest` already prevent the physically impossible cases, so forcing
|
|
13
|
+
* one shift per calendar day is a policy choice, not a safety net.
|
|
14
|
+
*/
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.createDefaultConstraints = void 0;
|
|
17
|
+
const one_shift_per_day_1 = require("./one-shift-per-day");
|
|
18
|
+
const no_overlap_1 = require("./no-overlap");
|
|
19
|
+
const min_staffing_1 = require("./min-staffing");
|
|
20
|
+
const time_off_1 = require("./time-off");
|
|
21
|
+
const hour_budget_1 = require("./hour-budget");
|
|
22
|
+
const max_shift_duration_1 = require("./max-shift-duration");
|
|
23
|
+
const min_rest_1 = require("./min-rest");
|
|
24
|
+
const daily_rest_1 = require("./daily-rest");
|
|
25
|
+
const weekly_rest_1 = require("./weekly-rest");
|
|
26
|
+
const rolling_hours_1 = require("./rolling-hours");
|
|
27
|
+
const night_work_1 = require("./night-work");
|
|
28
|
+
const consecutive_1 = require("./consecutive");
|
|
29
|
+
const start_interval_1 = require("./start-interval");
|
|
30
|
+
const in_shift_breaks_1 = require("./in-shift-breaks");
|
|
31
|
+
const rest_days_1 = require("./rest-days");
|
|
32
|
+
const engagement_floor_1 = require("./engagement-floor");
|
|
33
|
+
const notice_1 = require("./notice");
|
|
34
|
+
const fairness_1 = require("./fairness");
|
|
35
|
+
const availability_1 = require("./availability");
|
|
36
|
+
const qualification_1 = require("./qualification");
|
|
37
|
+
const group_composition_1 = require("./group-composition");
|
|
38
|
+
const protections_1 = require("./protections");
|
|
39
|
+
const contract_1 = require("./contract");
|
|
40
|
+
const overtime_1 = require("./overtime");
|
|
41
|
+
const duty_quota_1 = require("./duty-quota");
|
|
42
|
+
const cost_1 = require("./cost");
|
|
43
|
+
/**
|
|
44
|
+
* The built-in constraints in evaluation order.
|
|
45
|
+
*
|
|
46
|
+
* The always-on set is the physical/contractual core. Everything driven by
|
|
47
|
+
* `WorkingTimeRules` registers only when its rule family is present, so a
|
|
48
|
+
* caller who supplies no rules pays for nothing, and a sectoral regime that
|
|
49
|
+
* *replaces* a Working Time Directive rule (Art 14/20/21) omits it rather than
|
|
50
|
+
* widening its bounds.
|
|
51
|
+
*/
|
|
52
|
+
function createDefaultConstraints(options) {
|
|
53
|
+
const constraints = [];
|
|
54
|
+
const rules = options.rules ?? {};
|
|
55
|
+
if (options.oneShiftPerDay)
|
|
56
|
+
constraints.push((0, one_shift_per_day_1.oneShiftPerDay)());
|
|
57
|
+
constraints.push((0, no_overlap_1.noOverlap)(), (0, min_staffing_1.minStaffing)(), (0, time_off_1.timeOff)(), (0, hour_budget_1.hourBudget)(), (0, max_shift_duration_1.maxShiftDuration)());
|
|
58
|
+
// Rest: the rule-driven form supersedes the simple gap check when configured.
|
|
59
|
+
if (rules.dailyRest)
|
|
60
|
+
constraints.push((0, daily_rest_1.dailyRest)(rules.dailyRest));
|
|
61
|
+
else
|
|
62
|
+
constraints.push((0, min_rest_1.minRest)(options.minRestMinutes));
|
|
63
|
+
if (rules.weeklyRest)
|
|
64
|
+
constraints.push((0, weekly_rest_1.weeklyRest)(rules.weeklyRest));
|
|
65
|
+
if (rules.workingTime)
|
|
66
|
+
constraints.push((0, rolling_hours_1.rollingHours)(rules.workingTime));
|
|
67
|
+
if (rules.overtime)
|
|
68
|
+
constraints.push((0, overtime_1.overtime)(rules.overtime));
|
|
69
|
+
if (rules.dutyQuotas?.length)
|
|
70
|
+
constraints.push((0, duty_quota_1.dutyQuotas)(rules.dutyQuotas));
|
|
71
|
+
if (rules.nightWork)
|
|
72
|
+
constraints.push((0, night_work_1.nightWork)(rules.nightWork));
|
|
73
|
+
if (rules.consecutive)
|
|
74
|
+
constraints.push(...(0, consecutive_1.consecutiveConstraints)(rules.consecutive));
|
|
75
|
+
if (rules.minimumStartInterval)
|
|
76
|
+
constraints.push((0, start_interval_1.startInterval)(rules.minimumStartInterval));
|
|
77
|
+
if (rules.breaks?.length)
|
|
78
|
+
constraints.push((0, in_shift_breaks_1.inShiftBreaks)(rules.breaks));
|
|
79
|
+
if (rules.restDays)
|
|
80
|
+
constraints.push((0, rest_days_1.restDays)(rules.restDays));
|
|
81
|
+
if (rules.engagement)
|
|
82
|
+
constraints.push((0, engagement_floor_1.engagementFloor)(rules.engagement));
|
|
83
|
+
if (rules.notice)
|
|
84
|
+
constraints.push((0, notice_1.noticeRule)(rules.notice));
|
|
85
|
+
if (rules.fairness?.length)
|
|
86
|
+
constraints.push((0, fairness_1.fairness)(rules.fairness));
|
|
87
|
+
// Always-on person-scoped rules: they no-op unless the employee carries the
|
|
88
|
+
// relevant data, so they cost nothing for simple rosters.
|
|
89
|
+
constraints.push((0, availability_1.availability)(), (0, qualification_1.qualification)(), (0, group_composition_1.groupComposition)(), (0, protections_1.protections)(), (0, contract_1.contractLimits)());
|
|
90
|
+
// The cost term is score-only: its verdict always passes, so it steers the
|
|
91
|
+
// search without ever appearing as a violation.
|
|
92
|
+
const costWeight = options.objectives?.costWeightPerEuro;
|
|
93
|
+
if (costWeight !== undefined && costWeight > 0)
|
|
94
|
+
constraints.push((0, cost_1.costObjective)(costWeight));
|
|
95
|
+
return constraints;
|
|
96
|
+
}
|
|
97
|
+
exports.createDefaultConstraints = createDefaultConstraints;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contract limits.
|
|
3
|
+
*
|
|
4
|
+
* Two shapes:
|
|
5
|
+
*
|
|
6
|
+
* - **Hours contracts** carry period bounds in minutes, which sit alongside
|
|
7
|
+
* the statutory limits rather than replacing them — a contract may be
|
|
8
|
+
* stricter than the law but never looser.
|
|
9
|
+
* - **Day-count contracts** have no hours limit at all. The French
|
|
10
|
+
* *forfait jours* fixes 218 working *days* a year for autonomous staff, and
|
|
11
|
+
* the daily and weekly hour caps do not apply to them — but the 11h daily
|
|
12
|
+
* and 35h weekly rest still do. Modelling that as a very large hours budget
|
|
13
|
+
* would be wrong in both directions, so it gets its own counter.
|
|
14
|
+
*
|
|
15
|
+
* A contract end date also bounds eligibility: a fixed-term worker cannot be
|
|
16
|
+
* rostered past their last day, which is easy to miss when the roster period
|
|
17
|
+
* outruns the contract.
|
|
18
|
+
*/
|
|
19
|
+
import type { SchedulingConstraint } from '../types';
|
|
20
|
+
export declare function contractLimits(): SchedulingConstraint;
|
|
21
|
+
//# sourceMappingURL=contract.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/contract.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAoC,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAGvF,wBAAgB,cAAc,IAAI,oBAAoB,CAkHrD"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Contract limits.
|
|
4
|
+
*
|
|
5
|
+
* Two shapes:
|
|
6
|
+
*
|
|
7
|
+
* - **Hours contracts** carry period bounds in minutes, which sit alongside
|
|
8
|
+
* the statutory limits rather than replacing them — a contract may be
|
|
9
|
+
* stricter than the law but never looser.
|
|
10
|
+
* - **Day-count contracts** have no hours limit at all. The French
|
|
11
|
+
* *forfait jours* fixes 218 working *days* a year for autonomous staff, and
|
|
12
|
+
* the daily and weekly hour caps do not apply to them — but the 11h daily
|
|
13
|
+
* and 35h weekly rest still do. Modelling that as a very large hours budget
|
|
14
|
+
* would be wrong in both directions, so it gets its own counter.
|
|
15
|
+
*
|
|
16
|
+
* A contract end date also bounds eligibility: a fixed-term worker cannot be
|
|
17
|
+
* rostered past their last day, which is easy to miss when the roster period
|
|
18
|
+
* outruns the contract.
|
|
19
|
+
*/
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.contractLimits = void 0;
|
|
22
|
+
const support_1 = require("./support");
|
|
23
|
+
function contractLimits() {
|
|
24
|
+
const constraint = (0, support_1.fromVerdict)({
|
|
25
|
+
id: 'contract',
|
|
26
|
+
hardness: 'hard',
|
|
27
|
+
weight: 1,
|
|
28
|
+
prune(ctx, eligibility) {
|
|
29
|
+
for (const [employeeId, instances] of eligibility) {
|
|
30
|
+
const endDate = ctx.employeeById.get(employeeId)?.contract?.endDate;
|
|
31
|
+
if (!endDate)
|
|
32
|
+
continue;
|
|
33
|
+
for (const instanceId of [...instances]) {
|
|
34
|
+
const inst = ctx.instanceById.get(instanceId);
|
|
35
|
+
if (inst && inst.date > endDate)
|
|
36
|
+
instances.delete(instanceId);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
verdict(state, pair) {
|
|
41
|
+
const inst = (0, support_1.instanceOf)(state, pair);
|
|
42
|
+
const contract = state.ctx.employeeById.get(pair.employeeId)?.contract;
|
|
43
|
+
if (!inst || !contract)
|
|
44
|
+
return (0, support_1.pass)('contract', 'no contract limits');
|
|
45
|
+
if (contract.endDate && inst.date > contract.endDate) {
|
|
46
|
+
return (0, support_1.fail)('contract', 'hard', `employee "${pair.employeeId}"'s contract ends ${contract.endDate}, before "${inst.id}"`);
|
|
47
|
+
}
|
|
48
|
+
const timeline = (0, support_1.timelineFor)(state, pair.employeeId);
|
|
49
|
+
const probe = {
|
|
50
|
+
start: inst.startMinute,
|
|
51
|
+
end: inst.endMinute,
|
|
52
|
+
id: `${pair.employeeId}@@${pair.shiftInstanceId}`,
|
|
53
|
+
workingMinutes: inst.workingMinutes,
|
|
54
|
+
};
|
|
55
|
+
return timeline.withEntry(probe, (t) => {
|
|
56
|
+
const periodWindow = { start: 0, end: state.ctx.periodDays * support_1.MINUTES_PER_DAY };
|
|
57
|
+
// A contract bounds the employee *record*, not the person (the
|
|
58
|
+
// same per-record reading as the minimum aggregate below and the
|
|
59
|
+
// timeOffInLieu ledger): the person timeline also carries
|
|
60
|
+
// sibling contracts' entries, which must not eat this
|
|
61
|
+
// contract's budget. Roster entries are attributable by their
|
|
62
|
+
// `${employeeId}@@` prefix; history entries are not
|
|
63
|
+
// attributable to either record, so they count conservatively.
|
|
64
|
+
const ownPrefix = `${pair.employeeId}@@`;
|
|
65
|
+
const attributable = t
|
|
66
|
+
.entriesIn(periodWindow)
|
|
67
|
+
.filter((e) => !e.id.includes('@@') || e.id.startsWith(ownPrefix));
|
|
68
|
+
if (contract.kind === 'days' && contract.maxDaysInPeriod !== undefined) {
|
|
69
|
+
const days = new Set(attributable.map((e) => state.ctx.clock.dayIndexOfMinute(e.start))).size;
|
|
70
|
+
if (days > contract.maxDaysInPeriod) {
|
|
71
|
+
return (0, support_1.fail)('contract', 'hard', `employee "${pair.employeeId}" would work ${days} days, over their ${contract.maxDaysInPeriod}-day contract`, { actual: days, required: contract.maxDaysInPeriod, unit: 'days' });
|
|
72
|
+
}
|
|
73
|
+
// Day-count contracts are deliberately silent on hours.
|
|
74
|
+
return (0, support_1.pass)('contract', `${days} of ${contract.maxDaysInPeriod} contract days used`, {
|
|
75
|
+
actual: days,
|
|
76
|
+
required: contract.maxDaysInPeriod,
|
|
77
|
+
unit: 'days',
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
if (contract.maxPeriodMinutes !== undefined) {
|
|
81
|
+
const worked = attributable.reduce((sum, e) => {
|
|
82
|
+
const overlap = Math.min(e.end, periodWindow.end) - Math.max(e.start, periodWindow.start);
|
|
83
|
+
const span = e.end - e.start;
|
|
84
|
+
return sum + (span > 0 ? Math.round((e.workingMinutes * Math.max(0, overlap)) / span) : 0);
|
|
85
|
+
}, 0);
|
|
86
|
+
if (worked > contract.maxPeriodMinutes) {
|
|
87
|
+
return (0, support_1.fail)('contract', 'hard', `employee "${pair.employeeId}" would work ${(0, support_1.h)(worked)}, over their ${(0, support_1.h)(contract.maxPeriodMinutes)} contract maximum`, { actual: worked, required: contract.maxPeriodMinutes, unit: 'minutes' });
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return (0, support_1.pass)('contract', 'within contract limits');
|
|
91
|
+
});
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
// A minimum is only judgeable on the finished roster: every partial roster
|
|
95
|
+
// is below it by construction, so it cannot be a per-pair rule without
|
|
96
|
+
// blocking the very assignments that would satisfy it.
|
|
97
|
+
constraint.evaluate = (state) => {
|
|
98
|
+
const out = [];
|
|
99
|
+
for (const employee of state.ctx.employees) {
|
|
100
|
+
const contract = employee.contract;
|
|
101
|
+
if (!contract || contract.kind === 'days' || contract.minPeriodMinutes === undefined)
|
|
102
|
+
continue;
|
|
103
|
+
const worked = state.minutesByEmployee.get(employee.id) ?? 0;
|
|
104
|
+
if (worked >= contract.minPeriodMinutes)
|
|
105
|
+
continue;
|
|
106
|
+
out.push({
|
|
107
|
+
constraintId: 'contract',
|
|
108
|
+
severity: 'hard',
|
|
109
|
+
employeeId: employee.id,
|
|
110
|
+
message: `employee "${employee.id}" is rostered ${(0, support_1.h)(worked)}, below their ${(0, support_1.h)(contract.minPeriodMinutes)} contract minimum`,
|
|
111
|
+
actual: worked,
|
|
112
|
+
required: contract.minPeriodMinutes,
|
|
113
|
+
unit: 'minutes',
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
return out;
|
|
117
|
+
};
|
|
118
|
+
return constraint;
|
|
119
|
+
}
|
|
120
|
+
exports.contractLimits = contractLimits;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Labour cost as a soft objective term.
|
|
3
|
+
*
|
|
4
|
+
* Opt-in via `ScheduleInput.objectives.costWeightPerEuro`. The term contributes
|
|
5
|
+
* `euros × weight` per assignment to the *soft* level, so the solver prefers
|
|
6
|
+
* cheaper rosters among otherwise-equal ones — and can never buy a hard breach
|
|
7
|
+
* or an unfilled slot with a cost saving, because levels are lexicographic. That
|
|
8
|
+
* ordering is the legal point: "minimise cost" is a legitimate objective only
|
|
9
|
+
* inside the space of lawful, covered rosters.
|
|
10
|
+
*
|
|
11
|
+
* This is not a rule and never fails: its verdict always passes, so it produces
|
|
12
|
+
* no violations — only score. The arithmetic is `cost.ts`'s, shared with the
|
|
13
|
+
* repair ranking and the result's cost summary, so the number the solver
|
|
14
|
+
* minimises is the number the manager is shown.
|
|
15
|
+
*/
|
|
16
|
+
import type { SchedulingConstraint } from '../types';
|
|
17
|
+
export declare function costObjective(weightPerEuro: number): SchedulingConstraint;
|
|
18
|
+
//# sourceMappingURL=cost.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cost.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/cost.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAkB,oBAAoB,EAAe,MAAM,UAAU,CAAC;AAGlF,wBAAgB,aAAa,CAAC,aAAa,EAAE,MAAM,GAAG,oBAAoB,CAuBzE"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Labour cost as a soft objective term.
|
|
4
|
+
*
|
|
5
|
+
* Opt-in via `ScheduleInput.objectives.costWeightPerEuro`. The term contributes
|
|
6
|
+
* `euros × weight` per assignment to the *soft* level, so the solver prefers
|
|
7
|
+
* cheaper rosters among otherwise-equal ones — and can never buy a hard breach
|
|
8
|
+
* or an unfilled slot with a cost saving, because levels are lexicographic. That
|
|
9
|
+
* ordering is the legal point: "minimise cost" is a legitimate objective only
|
|
10
|
+
* inside the space of lawful, covered rosters.
|
|
11
|
+
*
|
|
12
|
+
* This is not a rule and never fails: its verdict always passes, so it produces
|
|
13
|
+
* no violations — only score. The arithmetic is `cost.ts`'s, shared with the
|
|
14
|
+
* repair ranking and the result's cost summary, so the number the solver
|
|
15
|
+
* minimises is the number the manager is shown.
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.costObjective = void 0;
|
|
19
|
+
const cost_1 = require("../cost");
|
|
20
|
+
function costObjective(weightPerEuro) {
|
|
21
|
+
return {
|
|
22
|
+
id: 'cost',
|
|
23
|
+
hardness: 'soft',
|
|
24
|
+
weight: weightPerEuro,
|
|
25
|
+
delta(state, pair) {
|
|
26
|
+
return pairCostCents(state, pair) / 100;
|
|
27
|
+
},
|
|
28
|
+
verdict(state, pair) {
|
|
29
|
+
const cents = pairCostCents(state, pair);
|
|
30
|
+
return {
|
|
31
|
+
ruleId: 'cost',
|
|
32
|
+
pass: true,
|
|
33
|
+
severity: 'soft',
|
|
34
|
+
actual: cents,
|
|
35
|
+
unit: 'count',
|
|
36
|
+
message: `costs €${(cents / 100).toFixed(2)}${cents === 0 ? ' (no cost model)' : ''}`,
|
|
37
|
+
};
|
|
38
|
+
},
|
|
39
|
+
explain() {
|
|
40
|
+
return null;
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
exports.costObjective = costObjective;
|
|
45
|
+
/**
|
|
46
|
+
* The pair's share of its employee's labour cost.
|
|
47
|
+
*
|
|
48
|
+
* For an assigned pair the overtime surcharge is allocated across the person's
|
|
49
|
+
* shifts pro rata by working minutes, so the shares sum exactly to the payroll;
|
|
50
|
+
* for a candidate not yet assigned it is the true marginal cost of adding it.
|
|
51
|
+
*/
|
|
52
|
+
function pairCostCents(state, pair) {
|
|
53
|
+
const employee = state.ctx.employeeById.get(pair.employeeId);
|
|
54
|
+
const inst = state.ctx.instanceById.get(pair.shiftInstanceId);
|
|
55
|
+
if (!employee?.cost?.hourlyRateCents || !inst)
|
|
56
|
+
return 0;
|
|
57
|
+
const worked = state.minutesByEmployee.get(pair.employeeId) ?? 0;
|
|
58
|
+
if (!state.isAssigned(pair.employeeId, pair.shiftInstanceId)) {
|
|
59
|
+
return (0, cost_1.marginalCostCents)(inst, employee, worked, state.ctx.rules.engagement);
|
|
60
|
+
}
|
|
61
|
+
const base = (0, cost_1.shiftCostCents)(inst, employee.cost, state.ctx.rules.engagement);
|
|
62
|
+
const surcharge = (0, cost_1.overtimeSurchargeCents)(worked, employee.cost);
|
|
63
|
+
const share = worked > 0 ? (surcharge * inst.workingMinutes) / worked : 0;
|
|
64
|
+
return base + share;
|
|
65
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Daily rest — Directive 2003/88/EC Art 3 and its national variants.
|
|
3
|
+
*
|
|
4
|
+
* The EU floor is 11 consecutive hours per 24-hour period; Spain and Romania
|
|
5
|
+
* require 12, Finnish period work allows 9. Derogations under Art 17/18 may
|
|
6
|
+
* reduce it further (8h in NL/DK/CZ, 9h in FR by collective agreement) but only
|
|
7
|
+
* against equivalent compensatory rest — which Jaeger (C-151/02) requires
|
|
8
|
+
* "immediately following" the period worked, and which never licenses breaching
|
|
9
|
+
* the weekly hours cap.
|
|
10
|
+
*
|
|
11
|
+
* Three shapes national law takes that a naive "gap between consecutive shifts"
|
|
12
|
+
* check cannot express, all handled here:
|
|
13
|
+
*
|
|
14
|
+
* - the rest must fit in *every rolling 24h*, not merely between two shifts;
|
|
15
|
+
* - a reduction may be used only so many times per window (NL: once per 7×24h);
|
|
16
|
+
* - the rest may have to *contain* a clock band — Sweden requires the 11h to
|
|
17
|
+
* include 00:00–05:00, which is positional, not a duration at all.
|
|
18
|
+
*/
|
|
19
|
+
import type { DailyRestRule, SchedulingConstraint } from '../types';
|
|
20
|
+
export declare const DAILY_REST_CITATION = "Directive 2003/88/EC Art 3";
|
|
21
|
+
export declare function dailyRest(rule: DailyRestRule): SchedulingConstraint;
|
|
22
|
+
//# sourceMappingURL=daily-rest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"daily-rest.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/daily-rest.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAe,oBAAoB,EAA+B,MAAM,UAAU,CAAC;AAG9G,eAAO,MAAM,mBAAmB,+BAA+B,CAAC;AAEhE,wBAAgB,SAAS,CAAC,IAAI,EAAE,aAAa,GAAG,oBAAoB,CA8FnE"}
|