assignment-user-matcher 1.9.0 → 1.10.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 +106 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -1
- package/dist/matcher.class.d.ts.map +1 -1
- package/dist/matcher.class.js +11 -0
- package/dist/scheduling/constraints/availability.d.ts +44 -0
- package/dist/scheduling/constraints/availability.d.ts.map +1 -0
- package/dist/scheduling/constraints/availability.js +142 -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 +106 -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 +118 -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 +59 -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 +97 -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 +60 -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 +163 -0
- package/dist/scheduling/constraints/no-overlap.d.ts +7 -0
- package/dist/scheduling/constraints/no-overlap.d.ts.map +1 -0
- package/dist/scheduling/constraints/no-overlap.js +36 -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 +92 -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 +97 -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 +379 -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 +132 -0
- package/dist/scheduling/time.d.ts.map +1 -0
- package/dist/scheduling/time.js +256 -0
- package/dist/scheduling/types.d.ts +932 -0
- package/dist/scheduling/types.d.ts.map +1 -0
- package/dist/scheduling/types.js +19 -0
- package/dist/types/matcher.d.ts +15 -0
- package/dist/types/matcher.d.ts.map +1 -1
- package/package.json +4 -2
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Time-off — an employee never works during their blocked intervals. Hard by
|
|
3
|
+
* default; prunes ineligible pairs before search.
|
|
4
|
+
*/
|
|
5
|
+
import type { SchedulingConstraint } from '../types';
|
|
6
|
+
export declare function timeOff(): SchedulingConstraint;
|
|
7
|
+
//# sourceMappingURL=time-off.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"time-off.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/time-off.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAGrD,wBAAgB,OAAO,IAAI,oBAAoB,CA6B9C"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Time-off — an employee never works during their blocked intervals. Hard by
|
|
4
|
+
* default; prunes ineligible pairs before search.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.timeOff = void 0;
|
|
8
|
+
const intervals_1 = require("./intervals");
|
|
9
|
+
function timeOff() {
|
|
10
|
+
return {
|
|
11
|
+
id: 'time-off',
|
|
12
|
+
hardness: 'hard',
|
|
13
|
+
prune(ctx, eligibility) {
|
|
14
|
+
for (const [employeeId, instances] of eligibility) {
|
|
15
|
+
const blocked = ctx.employeeBlockedIntervals.get(employeeId) ?? [];
|
|
16
|
+
if (blocked.length === 0)
|
|
17
|
+
continue;
|
|
18
|
+
for (const instanceId of [...instances]) {
|
|
19
|
+
const inst = ctx.instanceById.get(instanceId);
|
|
20
|
+
if (!inst)
|
|
21
|
+
continue;
|
|
22
|
+
if (blocked.some((b) => (0, intervals_1.overlaps)(inst.startMinute, inst.endMinute, b.start, b.end))) {
|
|
23
|
+
instances.delete(instanceId);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
delta(state, pair) {
|
|
29
|
+
const inst = state.ctx.instanceById.get(pair.shiftInstanceId);
|
|
30
|
+
if (!inst)
|
|
31
|
+
return 0;
|
|
32
|
+
const blocked = state.ctx.employeeBlockedIntervals.get(pair.employeeId) ?? [];
|
|
33
|
+
return blocked.some((b) => (0, intervals_1.overlaps)(inst.startMinute, inst.endMinute, b.start, b.end)) ? 1 : 0;
|
|
34
|
+
},
|
|
35
|
+
explain(state, pair) {
|
|
36
|
+
return this.delta(state, pair) > 0
|
|
37
|
+
? `employee "${pair.employeeId}" has time off during "${pair.shiftInstanceId}"`
|
|
38
|
+
: null;
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
exports.timeOff = timeOff;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Weekly rest — Directive 2003/88/EC Art 5, with the Art 16(a) averaging option.
|
|
3
|
+
*
|
|
4
|
+
* Art 5 is "24 uninterrupted hours plus the 11 hours' daily rest per each
|
|
5
|
+
* seven-day period" — 35h — dropping to 24h where objective, technical or work
|
|
6
|
+
* organisation conditions justify it. National floors range from 24h (IT, IE)
|
|
7
|
+
* through 35h (FR, PL, DK, FI, CZ, PT) and 36h (NL, SE, AT) to 48h (RO, EE).
|
|
8
|
+
*
|
|
9
|
+
* Two shapes matter beyond the number:
|
|
10
|
+
*
|
|
11
|
+
* - **Rolling, not calendar.** "Per each seven-day period" is any seven days,
|
|
12
|
+
* so a person can satisfy every Monday-to-Sunday week and still go eleven
|
|
13
|
+
* days without a proper break across a week boundary.
|
|
14
|
+
* - **Two-level.** Estonia requires 36h every week *and* 48h averaged over the
|
|
15
|
+
* reference period; Poland 24h with a 35h two-week average. A single
|
|
16
|
+
* threshold cannot express that, so `absoluteFloorMinutes` sits underneath
|
|
17
|
+
* `minMinutes` and both are checked.
|
|
18
|
+
*/
|
|
19
|
+
import type { SchedulingConstraint, WeeklyRestRule } from '../types';
|
|
20
|
+
export declare const WEEKLY_REST_CITATION = "Directive 2003/88/EC Art 5";
|
|
21
|
+
export declare function weeklyRest(rule: WeeklyRestRule): SchedulingConstraint;
|
|
22
|
+
//# sourceMappingURL=weekly-rest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"weekly-rest.d.ts","sourceRoot":"","sources":["../../../src/scheduling/constraints/weekly-rest.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAe,oBAAoB,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAIlF,eAAO,MAAM,oBAAoB,+BAA+B,CAAC;AAEjE,wBAAgB,UAAU,CAAC,IAAI,EAAE,cAAc,GAAG,oBAAoB,CA2DrE"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Weekly rest — Directive 2003/88/EC Art 5, with the Art 16(a) averaging option.
|
|
4
|
+
*
|
|
5
|
+
* Art 5 is "24 uninterrupted hours plus the 11 hours' daily rest per each
|
|
6
|
+
* seven-day period" — 35h — dropping to 24h where objective, technical or work
|
|
7
|
+
* organisation conditions justify it. National floors range from 24h (IT, IE)
|
|
8
|
+
* through 35h (FR, PL, DK, FI, CZ, PT) and 36h (NL, SE, AT) to 48h (RO, EE).
|
|
9
|
+
*
|
|
10
|
+
* Two shapes matter beyond the number:
|
|
11
|
+
*
|
|
12
|
+
* - **Rolling, not calendar.** "Per each seven-day period" is any seven days,
|
|
13
|
+
* so a person can satisfy every Monday-to-Sunday week and still go eleven
|
|
14
|
+
* days without a proper break across a week boundary.
|
|
15
|
+
* - **Two-level.** Estonia requires 36h every week *and* 48h averaged over the
|
|
16
|
+
* reference period; Poland 24h with a 35h two-week average. A single
|
|
17
|
+
* threshold cannot express that, so `absoluteFloorMinutes` sits underneath
|
|
18
|
+
* `minMinutes` and both are checked.
|
|
19
|
+
*/
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.weeklyRest = exports.WEEKLY_REST_CITATION = void 0;
|
|
22
|
+
const support_1 = require("./support");
|
|
23
|
+
exports.WEEKLY_REST_CITATION = 'Directive 2003/88/EC Art 5';
|
|
24
|
+
function weeklyRest(rule) {
|
|
25
|
+
const windowMinutes = rule.windowDays * support_1.MINUTES_PER_DAY;
|
|
26
|
+
const averagingMinutes = rule.averageOverDays ? rule.averageOverDays * support_1.MINUTES_PER_DAY : undefined;
|
|
27
|
+
return (0, support_1.fromVerdict)({
|
|
28
|
+
id: 'weekly-rest',
|
|
29
|
+
hardness: 'hard',
|
|
30
|
+
weight: 1,
|
|
31
|
+
citation: exports.WEEKLY_REST_CITATION,
|
|
32
|
+
verdict(state, pair) {
|
|
33
|
+
const inst = (0, support_1.instanceOf)(state, pair);
|
|
34
|
+
if (!inst)
|
|
35
|
+
return (0, support_1.pass)('weekly-rest', 'unknown shift');
|
|
36
|
+
const timeline = (0, support_1.timelineFor)(state, pair.employeeId);
|
|
37
|
+
const range = (0, support_1.rangeOf)(inst);
|
|
38
|
+
// Only windows the new shift could have worsened are worth testing.
|
|
39
|
+
const bounds = { start: range.start - windowMinutes, end: range.end + windowMinutes };
|
|
40
|
+
const probeEntry = { ...range, id: (0, support_1.entryIdOf)(pair), workingMinutes: inst.workingMinutes };
|
|
41
|
+
return timeline.withEntry(probeEntry, (t) => {
|
|
42
|
+
// The floor that must hold in *every* window. Without averaging
|
|
43
|
+
// the headline figure is itself the per-window requirement.
|
|
44
|
+
const floor = averagingMinutes ? (rule.absoluteFloorMinutes ?? 0) : rule.minMinutes;
|
|
45
|
+
if (floor > 0) {
|
|
46
|
+
const worst = t.minLongestRestInAnyWindow(windowMinutes, bounds);
|
|
47
|
+
if (worst < floor) {
|
|
48
|
+
return (0, support_1.fail)('weekly-rest', 'hard', `employee "${pair.employeeId}" would have only ${(0, support_1.h)(worst)} continuous rest in some ${rule.windowDays}-day window, below the ${(0, support_1.h)(floor)} floor`, { actual: worst, required: floor, unit: 'minutes', citation: exports.WEEKLY_REST_CITATION });
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (averagingMinutes) {
|
|
52
|
+
// Over the longer window the person must accumulate the rest
|
|
53
|
+
// they would have had from each short window.
|
|
54
|
+
const windows = averagingMinutes / windowMinutes;
|
|
55
|
+
const required = rule.minMinutes * windows;
|
|
56
|
+
const worstAveraged = totalQualifyingRest(t, averagingMinutes, bounds, rule.minMinutes);
|
|
57
|
+
if (worstAveraged < required) {
|
|
58
|
+
return (0, support_1.fail)('weekly-rest', 'hard', `employee "${pair.employeeId}" would average ${(0, support_1.h)(worstAveraged / windows)} weekly rest over ${rule.averageOverDays} days, below the ${(0, support_1.h)(rule.minMinutes)} average`, { actual: worstAveraged, required, unit: 'minutes', citation: exports.WEEKLY_REST_CITATION });
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return (0, support_1.pass)('weekly-rest', `weekly rest of at least ${(0, support_1.h)(rule.minMinutes)} preserved`, {
|
|
62
|
+
required: rule.minMinutes,
|
|
63
|
+
unit: 'minutes',
|
|
64
|
+
citation: exports.WEEKLY_REST_CITATION,
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
exports.weeklyRest = weeklyRest;
|
|
71
|
+
/**
|
|
72
|
+
* Total rest, counting only stretches long enough to qualify, in the worst
|
|
73
|
+
* averaging window.
|
|
74
|
+
*
|
|
75
|
+
* Averaging counts *rest periods*, not idle minutes: eight scattered hours are
|
|
76
|
+
* not half a weekly rest. Only unbroken stretches of at least `minPer` count,
|
|
77
|
+
* and each contributes at most one qualifying period's worth.
|
|
78
|
+
*/
|
|
79
|
+
function totalQualifyingRest(timeline, averagingMinutes, bounds, minPer) {
|
|
80
|
+
let worst = Infinity;
|
|
81
|
+
for (let start = bounds.start; start <= bounds.end; start += support_1.MINUTES_PER_DAY) {
|
|
82
|
+
const window = { start, end: start + averagingMinutes };
|
|
83
|
+
let total = 0;
|
|
84
|
+
for (const gap of timeline.restGapsIn(window)) {
|
|
85
|
+
if (gap >= minPer)
|
|
86
|
+
total += minPer * Math.floor(gap / minPer);
|
|
87
|
+
}
|
|
88
|
+
if (total < worst)
|
|
89
|
+
worst = total;
|
|
90
|
+
}
|
|
91
|
+
return worst === Infinity ? 0 : worst;
|
|
92
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Labour-cost arithmetic — pure logic, shared by the solve objective, the
|
|
3
|
+
* repair candidate ranking and the result's cost summary.
|
|
4
|
+
*
|
|
5
|
+
* One implementation on purpose: an objective that minimises a different cost
|
|
6
|
+
* than the ranking reports would steer the roster one way and justify it
|
|
7
|
+
* another. All money is minor units (cents), integral until the final rounding.
|
|
8
|
+
*
|
|
9
|
+
* What is priced, and what deliberately is not:
|
|
10
|
+
*
|
|
11
|
+
* - The *working* portion of a span is paid at the hourly rate, uplifted by
|
|
12
|
+
* whichever premium bands apply (night / Sunday / holiday), stacked
|
|
13
|
+
* additively or by maximum as the cost model says.
|
|
14
|
+
* - The non-working remainder of a *duty-classified* span — stand-by hours
|
|
15
|
+
* that occupy the clock without counting as work — is paid flat at
|
|
16
|
+
* `standbyRateFraction` of the rate (Estonia's *valveaeg* owes ≥ 1/10 of
|
|
17
|
+
* the agreed wage). No premiums apply to it; unset means unpaid.
|
|
18
|
+
* - Overtime is a per-employee surcharge on the minutes worked past
|
|
19
|
+
* `overtimeAfterMinutes`, at `(overtimeMultiplier − 1)` on top of the base
|
|
20
|
+
* already priced per shift. Kept separate from the per-shift price because
|
|
21
|
+
* which minutes are "the overtime ones" is an accounting fiction — the
|
|
22
|
+
* surcharge belongs to the person's total, not to any one shift.
|
|
23
|
+
*/
|
|
24
|
+
import type { Employee, EmployeeCost, EngagementRule, SearchState, ShiftInstance } from './types';
|
|
25
|
+
/**
|
|
26
|
+
* Price of one shift for one cost model, excluding any overtime surcharge.
|
|
27
|
+
*
|
|
28
|
+
* Premium predicates are judged on the instance: `night` applies when any of
|
|
29
|
+
* the shift falls in the configured night band, `sunday`/`holiday` on the start
|
|
30
|
+
* day. Romania stacks premiums additively (overtime 75% + night 25% + holiday
|
|
31
|
+
* 100%); most jurisdictions apply only the largest, so `'max'` is the default —
|
|
32
|
+
* under-stating the Romanian bill rather than over-stating everyone else's.
|
|
33
|
+
*/
|
|
34
|
+
export declare function shiftCostCents(inst: ShiftInstance, cost: EmployeeCost | undefined, engagement?: EngagementRule): number;
|
|
35
|
+
/**
|
|
36
|
+
* Surcharge owed on `workedMinutes` of total working time — the extra above
|
|
37
|
+
* base rate for the minutes past the overtime threshold. Base pay for those
|
|
38
|
+
* minutes is already in the per-shift price, so only the uplift is added here.
|
|
39
|
+
*/
|
|
40
|
+
export declare function overtimeSurchargeCents(workedMinutes: number, cost: EmployeeCost | undefined): number;
|
|
41
|
+
/**
|
|
42
|
+
* Marginal cost of adding one shift on top of `workedMinutes` already assigned:
|
|
43
|
+
* the shift's own price plus the overtime surcharge it newly triggers. This is
|
|
44
|
+
* the number a call-out decision needs — the same shift is dearer in the hands
|
|
45
|
+
* of someone already at their threshold.
|
|
46
|
+
*/
|
|
47
|
+
export declare function marginalCostCents(inst: ShiftInstance, employee: Employee, workedMinutes: number, engagement?: EngagementRule): number;
|
|
48
|
+
/**
|
|
49
|
+
* Whole-roster cost, per employee and total, or `undefined` when nobody has a
|
|
50
|
+
* cost model — so rosters without one keep a byte-identical result shape.
|
|
51
|
+
*/
|
|
52
|
+
export declare function rosterCost(state: SearchState): {
|
|
53
|
+
totalCents: number;
|
|
54
|
+
byEmployee: Record<string, number>;
|
|
55
|
+
} | undefined;
|
|
56
|
+
//# sourceMappingURL=cost.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cost.d.ts","sourceRoot":"","sources":["../../src/scheduling/cost.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,cAAc,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAGlG;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,YAAY,GAAG,SAAS,EAAE,UAAU,CAAC,EAAE,cAAc,GAAG,MAAM,CAsBvH;AAaD;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,aAAa,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,GAAG,SAAS,GAAG,MAAM,CAIpG;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC7B,IAAI,EAAE,aAAa,EACnB,QAAQ,EAAE,QAAQ,EAClB,aAAa,EAAE,MAAM,EACrB,UAAU,CAAC,EAAE,cAAc,GAC5B,MAAM,CAQR;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,WAAW,GAAG;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,GAAG,SAAS,CAiBrH"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Labour-cost arithmetic — pure logic, shared by the solve objective, the
|
|
4
|
+
* repair candidate ranking and the result's cost summary.
|
|
5
|
+
*
|
|
6
|
+
* One implementation on purpose: an objective that minimises a different cost
|
|
7
|
+
* than the ranking reports would steer the roster one way and justify it
|
|
8
|
+
* another. All money is minor units (cents), integral until the final rounding.
|
|
9
|
+
*
|
|
10
|
+
* What is priced, and what deliberately is not:
|
|
11
|
+
*
|
|
12
|
+
* - The *working* portion of a span is paid at the hourly rate, uplifted by
|
|
13
|
+
* whichever premium bands apply (night / Sunday / holiday), stacked
|
|
14
|
+
* additively or by maximum as the cost model says.
|
|
15
|
+
* - The non-working remainder of a *duty-classified* span — stand-by hours
|
|
16
|
+
* that occupy the clock without counting as work — is paid flat at
|
|
17
|
+
* `standbyRateFraction` of the rate (Estonia's *valveaeg* owes ≥ 1/10 of
|
|
18
|
+
* the agreed wage). No premiums apply to it; unset means unpaid.
|
|
19
|
+
* - Overtime is a per-employee surcharge on the minutes worked past
|
|
20
|
+
* `overtimeAfterMinutes`, at `(overtimeMultiplier − 1)` on top of the base
|
|
21
|
+
* already priced per shift. Kept separate from the per-shift price because
|
|
22
|
+
* which minutes are "the overtime ones" is an accounting fiction — the
|
|
23
|
+
* surcharge belongs to the person's total, not to any one shift.
|
|
24
|
+
*/
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.rosterCost = exports.marginalCostCents = exports.overtimeSurchargeCents = exports.shiftCostCents = void 0;
|
|
27
|
+
const engagement_floor_1 = require("./constraints/engagement-floor");
|
|
28
|
+
/**
|
|
29
|
+
* Price of one shift for one cost model, excluding any overtime surcharge.
|
|
30
|
+
*
|
|
31
|
+
* Premium predicates are judged on the instance: `night` applies when any of
|
|
32
|
+
* the shift falls in the configured night band, `sunday`/`holiday` on the start
|
|
33
|
+
* day. Romania stacks premiums additively (overtime 75% + night 25% + holiday
|
|
34
|
+
* 100%); most jurisdictions apply only the largest, so `'max'` is the default —
|
|
35
|
+
* under-stating the Romanian bill rather than over-stating everyone else's.
|
|
36
|
+
*/
|
|
37
|
+
function shiftCostCents(inst, cost, engagement) {
|
|
38
|
+
if (!cost?.hourlyRateCents)
|
|
39
|
+
return 0;
|
|
40
|
+
const paid = (0, engagement_floor_1.paidMinutesFor)(inst, engagement);
|
|
41
|
+
const base = (paid / 60) * cost.hourlyRateCents;
|
|
42
|
+
const multipliers = [];
|
|
43
|
+
for (const premium of cost.premiums ?? []) {
|
|
44
|
+
const applies = (premium.predicate === 'night' && inst.nightMinutes > 0) ||
|
|
45
|
+
(premium.predicate === 'sunday' && inst.isSunday) ||
|
|
46
|
+
(premium.predicate === 'holiday' && inst.isPublicHoliday);
|
|
47
|
+
if (applies)
|
|
48
|
+
multipliers.push(premium.multiplier);
|
|
49
|
+
}
|
|
50
|
+
const uplift = multipliers.length === 0
|
|
51
|
+
? 1
|
|
52
|
+
: cost.stacking === 'add'
|
|
53
|
+
? 1 + multipliers.reduce((sum, m) => sum + (m - 1), 0)
|
|
54
|
+
: Math.max(...multipliers);
|
|
55
|
+
return Math.round(base * uplift + standbyAllowanceCents(inst, cost));
|
|
56
|
+
}
|
|
57
|
+
exports.shiftCostCents = shiftCostCents;
|
|
58
|
+
/**
|
|
59
|
+
* The stand-by allowance for the non-working remainder of a duty-classified
|
|
60
|
+
* span. Only duty-classified instances have one — for a plain shift the
|
|
61
|
+
* remainder is the unpaid break, which is unpaid by definition.
|
|
62
|
+
*/
|
|
63
|
+
function standbyAllowanceCents(inst, cost) {
|
|
64
|
+
if (!cost.standbyRateFraction || !inst.duty || inst.duty.countsAsWorkingTime === 'full')
|
|
65
|
+
return 0;
|
|
66
|
+
const standbyMinutes = Math.max(0, inst.durationMinutes - inst.workingMinutes);
|
|
67
|
+
return (standbyMinutes / 60) * cost.hourlyRateCents * cost.standbyRateFraction;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Surcharge owed on `workedMinutes` of total working time — the extra above
|
|
71
|
+
* base rate for the minutes past the overtime threshold. Base pay for those
|
|
72
|
+
* minutes is already in the per-shift price, so only the uplift is added here.
|
|
73
|
+
*/
|
|
74
|
+
function overtimeSurchargeCents(workedMinutes, cost) {
|
|
75
|
+
if (!cost?.hourlyRateCents || cost.overtimeAfterMinutes === undefined || !cost.overtimeMultiplier)
|
|
76
|
+
return 0;
|
|
77
|
+
const overtime = Math.max(0, workedMinutes - cost.overtimeAfterMinutes);
|
|
78
|
+
return Math.round((overtime / 60) * cost.hourlyRateCents * (cost.overtimeMultiplier - 1));
|
|
79
|
+
}
|
|
80
|
+
exports.overtimeSurchargeCents = overtimeSurchargeCents;
|
|
81
|
+
/**
|
|
82
|
+
* Marginal cost of adding one shift on top of `workedMinutes` already assigned:
|
|
83
|
+
* the shift's own price plus the overtime surcharge it newly triggers. This is
|
|
84
|
+
* the number a call-out decision needs — the same shift is dearer in the hands
|
|
85
|
+
* of someone already at their threshold.
|
|
86
|
+
*/
|
|
87
|
+
function marginalCostCents(inst, employee, workedMinutes, engagement) {
|
|
88
|
+
const cost = employee.cost;
|
|
89
|
+
if (!cost?.hourlyRateCents)
|
|
90
|
+
return 0;
|
|
91
|
+
return (shiftCostCents(inst, cost, engagement) +
|
|
92
|
+
overtimeSurchargeCents(workedMinutes + inst.workingMinutes, cost) -
|
|
93
|
+
overtimeSurchargeCents(workedMinutes, cost));
|
|
94
|
+
}
|
|
95
|
+
exports.marginalCostCents = marginalCostCents;
|
|
96
|
+
/**
|
|
97
|
+
* Whole-roster cost, per employee and total, or `undefined` when nobody has a
|
|
98
|
+
* cost model — so rosters without one keep a byte-identical result shape.
|
|
99
|
+
*/
|
|
100
|
+
function rosterCost(state) {
|
|
101
|
+
const ctx = state.ctx;
|
|
102
|
+
if (!ctx.employees.some((e) => e.cost?.hourlyRateCents))
|
|
103
|
+
return undefined;
|
|
104
|
+
const byEmployee = {};
|
|
105
|
+
let totalCents = 0;
|
|
106
|
+
for (const employee of ctx.employees) {
|
|
107
|
+
let cents = 0;
|
|
108
|
+
for (const instanceId of state.byEmployee.get(employee.id) ?? []) {
|
|
109
|
+
const inst = ctx.instanceById.get(instanceId);
|
|
110
|
+
if (inst)
|
|
111
|
+
cents += shiftCostCents(inst, employee.cost, ctx.rules.engagement);
|
|
112
|
+
}
|
|
113
|
+
cents += overtimeSurchargeCents(state.minutesByEmployee.get(employee.id) ?? 0, employee.cost);
|
|
114
|
+
if (cents > 0)
|
|
115
|
+
byEmployee[employee.id] = cents;
|
|
116
|
+
totalCents += cents;
|
|
117
|
+
}
|
|
118
|
+
return { totalCents, byEmployee };
|
|
119
|
+
}
|
|
120
|
+
exports.rosterCost = rosterCost;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Greedy construction — pure logic.
|
|
3
|
+
*
|
|
4
|
+
* Fills most-constrained shift instances first (fewest eligible employees),
|
|
5
|
+
* picking the best employee by objective delta with seeded tie-breaking. A
|
|
6
|
+
* pair is only ever assigned when every hard constraint's `delta` is 0, so a
|
|
7
|
+
* constructed state is always hard-compliant; shortfalls surface as unfilled
|
|
8
|
+
* slots, not breaches.
|
|
9
|
+
*/
|
|
10
|
+
import type { ModelContext } from '../types';
|
|
11
|
+
import type { PropagationResult } from './propagation';
|
|
12
|
+
import { type InternalState } from './state';
|
|
13
|
+
/** Whether assigning the pair keeps every hard constraint satisfied. */
|
|
14
|
+
export declare function hardCompliant(ctx: ModelContext, state: InternalState, employeeId: string, instanceId: string): boolean;
|
|
15
|
+
/** Instances ordered most-constrained-first: fewest eligible employees, then earliest start. */
|
|
16
|
+
export declare function constructionOrder(ctx: ModelContext, propagation: PropagationResult): string[];
|
|
17
|
+
/**
|
|
18
|
+
* Greedily staff `instanceIds` (default: everything, most-constrained first).
|
|
19
|
+
* Shared by initial construction and LNS repair.
|
|
20
|
+
*/
|
|
21
|
+
export declare function greedyFill(ctx: ModelContext, state: InternalState, propagation: PropagationResult, objective: 'standard' | 'balanced', rand: () => number, instanceIds?: string[]): void;
|
|
22
|
+
//# sourceMappingURL=construction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"construction.d.ts","sourceRoot":"","sources":["../../../src/scheduling/engine/construction.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAU,KAAK,aAAa,EAAE,MAAM,SAAS,CAAC;AAErD,wEAAwE;AACxE,wBAAgB,aAAa,CAAC,GAAG,EAAE,YAAY,EAAE,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAKtH;AA8CD,gGAAgG;AAChG,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,YAAY,EAAE,WAAW,EAAE,iBAAiB,GAAG,MAAM,EAAE,CAS7F;AAED;;;GAGG;AACH,wBAAgB,UAAU,CACtB,GAAG,EAAE,YAAY,EACjB,KAAK,EAAE,aAAa,EACpB,WAAW,EAAE,iBAAiB,EAC9B,SAAS,EAAE,UAAU,GAAG,UAAU,EAClC,IAAI,EAAE,MAAM,MAAM,EAClB,WAAW,CAAC,EAAE,MAAM,EAAE,GACvB,IAAI,CAsBN"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Greedy construction — pure logic.
|
|
4
|
+
*
|
|
5
|
+
* Fills most-constrained shift instances first (fewest eligible employees),
|
|
6
|
+
* picking the best employee by objective delta with seeded tie-breaking. A
|
|
7
|
+
* pair is only ever assigned when every hard constraint's `delta` is 0, so a
|
|
8
|
+
* constructed state is always hard-compliant; shortfalls surface as unfilled
|
|
9
|
+
* slots, not breaches.
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.greedyFill = exports.constructionOrder = exports.hardCompliant = void 0;
|
|
13
|
+
const state_1 = require("./state");
|
|
14
|
+
/** Whether assigning the pair keeps every hard constraint satisfied. */
|
|
15
|
+
function hardCompliant(ctx, state, employeeId, instanceId) {
|
|
16
|
+
for (const c of ctx.constraints) {
|
|
17
|
+
if (c.hardness === 'hard' && c.delta(state, { employeeId, shiftInstanceId: instanceId }) > 0)
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
exports.hardCompliant = hardCompliant;
|
|
23
|
+
function rankCandidate(ctx, state, instanceId, employeeId, objective, rand) {
|
|
24
|
+
const reasons = [];
|
|
25
|
+
let rank = 0;
|
|
26
|
+
// Prefer candidates that close an unmet tag requirement.
|
|
27
|
+
const inst = ctx.instanceById.get(instanceId);
|
|
28
|
+
if (inst) {
|
|
29
|
+
const assigned = state.assignments.get(instanceId);
|
|
30
|
+
for (const [tag, needed] of Object.entries(inst.tagRequirements)) {
|
|
31
|
+
let have = 0;
|
|
32
|
+
if (assigned)
|
|
33
|
+
for (const e of assigned)
|
|
34
|
+
if (ctx.employeeTags.get(e)?.has(tag))
|
|
35
|
+
have++;
|
|
36
|
+
if (have < needed && ctx.employeeTags.get(employeeId)?.has(tag)) {
|
|
37
|
+
rank -= 1000;
|
|
38
|
+
reasons.push(`fills tag requirement "${tag}"`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (objective === 'balanced') {
|
|
43
|
+
// Less-loaded employees first so hours equalize.
|
|
44
|
+
rank += (state.minutesByEmployee.get(employeeId) ?? 0) / 60;
|
|
45
|
+
reasons.push('selected to balance hours');
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
reasons.push('eligible under all constraints');
|
|
49
|
+
}
|
|
50
|
+
// Seeded jitter for deterministic tie-breaking.
|
|
51
|
+
rank += rand();
|
|
52
|
+
return { employeeId, rank, reasons };
|
|
53
|
+
}
|
|
54
|
+
/** Instances ordered most-constrained-first: fewest eligible employees, then earliest start. */
|
|
55
|
+
function constructionOrder(ctx, propagation) {
|
|
56
|
+
return ctx.instances
|
|
57
|
+
.map((i) => i.id)
|
|
58
|
+
.sort((a, b) => {
|
|
59
|
+
const ea = propagation.eligibleByInstance.get(a)?.length ?? 0;
|
|
60
|
+
const eb = propagation.eligibleByInstance.get(b)?.length ?? 0;
|
|
61
|
+
if (ea !== eb)
|
|
62
|
+
return ea - eb;
|
|
63
|
+
return ctx.instanceById.get(a).startMinute - ctx.instanceById.get(b).startMinute;
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
exports.constructionOrder = constructionOrder;
|
|
67
|
+
/**
|
|
68
|
+
* Greedily staff `instanceIds` (default: everything, most-constrained first).
|
|
69
|
+
* Shared by initial construction and LNS repair.
|
|
70
|
+
*/
|
|
71
|
+
function greedyFill(ctx, state, propagation, objective, rand, instanceIds) {
|
|
72
|
+
const order = instanceIds ?? constructionOrder(ctx, propagation);
|
|
73
|
+
for (const instanceId of order) {
|
|
74
|
+
const inst = ctx.instanceById.get(instanceId);
|
|
75
|
+
if (!inst)
|
|
76
|
+
continue;
|
|
77
|
+
let need = inst.minEmployees - (state.assignments.get(instanceId)?.size ?? 0);
|
|
78
|
+
if (need <= 0)
|
|
79
|
+
continue;
|
|
80
|
+
const candidates = [];
|
|
81
|
+
for (const employeeId of propagation.eligibleByInstance.get(instanceId) ?? []) {
|
|
82
|
+
if (state.isAssigned(employeeId, instanceId))
|
|
83
|
+
continue;
|
|
84
|
+
if (!hardCompliant(ctx, state, employeeId, instanceId))
|
|
85
|
+
continue;
|
|
86
|
+
candidates.push(rankCandidate(ctx, state, instanceId, employeeId, objective, rand));
|
|
87
|
+
}
|
|
88
|
+
candidates.sort((a, b) => a.rank - b.rank || (a.employeeId < b.employeeId ? -1 : 1));
|
|
89
|
+
for (const c of candidates) {
|
|
90
|
+
if (need <= 0)
|
|
91
|
+
break;
|
|
92
|
+
(0, state_1.assign)(state, c.employeeId, instanceId, c.reasons);
|
|
93
|
+
need--;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
exports.greedyFill = greedyFill;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Explain — per-assignment reason strings from constraint evaluations.
|
|
3
|
+
*
|
|
4
|
+
* Reasons combine what construction/repair recorded at selection time with a
|
|
5
|
+
* compliance confirmation per constraint (`explain` returning null means the
|
|
6
|
+
* pair satisfies the rule). Fits the repo's decision-trace philosophy: every
|
|
7
|
+
* rostered pair can say why it exists.
|
|
8
|
+
*/
|
|
9
|
+
import { type InternalState } from './state';
|
|
10
|
+
/** Reason strings for one assigned pair; empty only for a state built outside the engine. */
|
|
11
|
+
export declare function reasonsFor(state: InternalState, employeeId: string, instanceId: string): string[];
|
|
12
|
+
//# sourceMappingURL=explain.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"explain.d.ts","sourceRoot":"","sources":["../../../src/scheduling/engine/explain.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAW,KAAK,aAAa,EAAE,MAAM,SAAS,CAAC;AAEtD,6FAA6F;AAC7F,wBAAgB,UAAU,CAAC,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,EAAE,CASjG"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Explain — per-assignment reason strings from constraint evaluations.
|
|
4
|
+
*
|
|
5
|
+
* Reasons combine what construction/repair recorded at selection time with a
|
|
6
|
+
* compliance confirmation per constraint (`explain` returning null means the
|
|
7
|
+
* pair satisfies the rule). Fits the repo's decision-trace philosophy: every
|
|
8
|
+
* rostered pair can say why it exists.
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.reasonsFor = void 0;
|
|
12
|
+
const state_1 = require("./state");
|
|
13
|
+
/** Reason strings for one assigned pair; empty only for a state built outside the engine. */
|
|
14
|
+
function reasonsFor(state, employeeId, instanceId) {
|
|
15
|
+
const recorded = state.reasons.get((0, state_1.pairKey)(employeeId, instanceId)) ?? [];
|
|
16
|
+
const out = [...recorded];
|
|
17
|
+
for (const c of state.ctx.constraints) {
|
|
18
|
+
if (c.explain(state, { employeeId, shiftInstanceId: instanceId }) === null) {
|
|
19
|
+
out.push(`satisfies ${c.id}`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return out;
|
|
23
|
+
}
|
|
24
|
+
exports.reasonsFor = reasonsFor;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Objective scoring — pure logic.
|
|
3
|
+
*
|
|
4
|
+
* The score has three lexicographic levels rather than one number:
|
|
5
|
+
*
|
|
6
|
+
* - **hard** — legal or physical impossibility (rest, overlap, expired
|
|
7
|
+
* qualification, contract breach);
|
|
8
|
+
* - **medium** — coverage: unfilled slots and unmet tag requirements;
|
|
9
|
+
* - **soft** — cost, fairness, preferences, hour-balance.
|
|
10
|
+
*
|
|
11
|
+
* They are compared in order, never summed. A weighted sum would let a large
|
|
12
|
+
* enough soft gain buy a hard breach — arrange the weights unluckily and the
|
|
13
|
+
* solver "discovers" that under-resting one person improves fairness for
|
|
14
|
+
* everyone else. Lexicographic ordering makes that trade unrepresentable
|
|
15
|
+
* instead of merely unlikely.
|
|
16
|
+
*
|
|
17
|
+
* Within a level, breaches contribute their *magnitude*, so a rest gap ten
|
|
18
|
+
* minutes short scores better than one six hours short. Local search needs that
|
|
19
|
+
* gradient to climb out of an infeasible region; a 0/1 flag leaves it on a
|
|
20
|
+
* plateau with nothing to follow.
|
|
21
|
+
*
|
|
22
|
+
* Aggregate constraints (`evaluate`) are deliberately not run per move — they
|
|
23
|
+
* are O(roster) and the search calls the objective in its innermost loop. The
|
|
24
|
+
* cheap aggregates that steer the search (coverage, fairness) have dedicated
|
|
25
|
+
* terms here; the full `evaluate` pass runs once when the result is assembled.
|
|
26
|
+
*/
|
|
27
|
+
import type { FairnessRule, ModelContext, SearchState } from '../types';
|
|
28
|
+
export declare const UNFILLED_WEIGHT = 10000;
|
|
29
|
+
export declare const TAG_SHORTFALL_WEIGHT = 5000;
|
|
30
|
+
export declare const MIN_HOURS_WEIGHT = 100;
|
|
31
|
+
/** Default weight applied to a soft constraint that does not declare one. */
|
|
32
|
+
export declare const DEFAULT_SOFT_WEIGHT = 1;
|
|
33
|
+
/** A three-level score. Lower is better at every level. */
|
|
34
|
+
export interface LexScore {
|
|
35
|
+
hard: number;
|
|
36
|
+
medium: number;
|
|
37
|
+
soft: number;
|
|
38
|
+
}
|
|
39
|
+
/** Negative when `a` is better than `b`, positive when worse, 0 when equal. */
|
|
40
|
+
export declare function compareScores(a: LexScore, b: LexScore): number;
|
|
41
|
+
export declare function isBetter(a: LexScore, b: LexScore): boolean;
|
|
42
|
+
/** Missing assignees for an instance (0 when fully staffed). */
|
|
43
|
+
export declare function slotShortage(ctx: ModelContext, state: SearchState, instanceId: string): number;
|
|
44
|
+
/** Missing tagged assignees, summed over the instance's tag requirements. */
|
|
45
|
+
export declare function tagShortage(ctx: ModelContext, state: SearchState, instanceId: string): number;
|
|
46
|
+
/** Total unfilled capacity across the period, in person-slots. */
|
|
47
|
+
export declare function unfilledSlots(ctx: ModelContext, state: SearchState): number;
|
|
48
|
+
/** Variance of worked minutes across employees (0 for an empty roster). */
|
|
49
|
+
export declare function hoursVariance(ctx: ModelContext, state: SearchState): number;
|
|
50
|
+
/** Number of employees below their soft min-hours bound. */
|
|
51
|
+
export declare function minHoursShortfalls(ctx: ModelContext, state: SearchState): number;
|
|
52
|
+
/**
|
|
53
|
+
* Weighted breach total per level, over the currently assigned pairs.
|
|
54
|
+
*
|
|
55
|
+
* This is what gives `SchedulingConstraint.weight` teeth — a caller who softens
|
|
56
|
+
* a built-in via `overrides`, or registers a custom rule, now moves the score
|
|
57
|
+
* instead of being silently ignored.
|
|
58
|
+
*/
|
|
59
|
+
export declare function breachTotals(ctx: ModelContext, state: SearchState): LexScore;
|
|
60
|
+
/** Backwards-compatible soft-breach total, for callers that want a single figure. */
|
|
61
|
+
export declare function softBreaches(ctx: ModelContext, state: SearchState): number;
|
|
62
|
+
/** The full three-level score. Lower is better at every level. */
|
|
63
|
+
export declare function scoreLex(ctx: ModelContext, state: SearchState, objective: 'standard' | 'balanced', minHoursWeight: number, fairnessRules?: FairnessRule[]): LexScore;
|
|
64
|
+
/**
|
|
65
|
+
* Flattened score, lower is better.
|
|
66
|
+
*
|
|
67
|
+
* Retained for callers that need one number. The level separation is preserved
|
|
68
|
+
* by scaling, but comparisons should prefer `compareScores` — a flattened score
|
|
69
|
+
* can only approximate a lexicographic order, and at extreme magnitudes the
|
|
70
|
+
* approximation leaks.
|
|
71
|
+
*/
|
|
72
|
+
export declare function score(ctx: ModelContext, state: SearchState, objective: 'standard' | 'balanced', minHoursWeight: number): number;
|
|
73
|
+
//# sourceMappingURL=objective.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"objective.d.ts","sourceRoot":"","sources":["../../../src/scheduling/engine/objective.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAIxE,eAAO,MAAM,eAAe,QAAS,CAAC;AACtC,eAAO,MAAM,oBAAoB,OAAQ,CAAC;AAC1C,eAAO,MAAM,gBAAgB,MAAM,CAAC;AACpC,6EAA6E;AAC7E,eAAO,MAAM,mBAAmB,IAAI,CAAC;AAErC,2DAA2D;AAC3D,MAAM,WAAW,QAAQ;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CAChB;AAED,+EAA+E;AAC/E,wBAAgB,aAAa,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,QAAQ,GAAG,MAAM,CAI9D;AAED,wBAAgB,QAAQ,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,QAAQ,GAAG,OAAO,CAE1D;AAED,gEAAgE;AAChE,wBAAgB,YAAY,CAAC,GAAG,EAAE,YAAY,EAAE,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAI9F;AAED,6EAA6E;AAC7E,wBAAgB,WAAW,CAAC,GAAG,EAAE,YAAY,EAAE,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAa7F;AAED,kEAAkE;AAClE,wBAAgB,aAAa,CAAC,GAAG,EAAE,YAAY,EAAE,KAAK,EAAE,WAAW,GAAG,MAAM,CAI3E;AAED,2EAA2E;AAC3E,wBAAgB,aAAa,CAAC,GAAG,EAAE,YAAY,EAAE,KAAK,EAAE,WAAW,GAAG,MAAM,CAK3E;AAED,4DAA4D;AAC5D,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,YAAY,EAAE,KAAK,EAAE,WAAW,GAAG,MAAM,CAMhF;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,YAAY,EAAE,KAAK,EAAE,WAAW,GAAG,QAAQ,CAgB5E;AAED,qFAAqF;AACrF,wBAAgB,YAAY,CAAC,GAAG,EAAE,YAAY,EAAE,KAAK,EAAE,WAAW,GAAG,MAAM,CAE1E;AAED,kEAAkE;AAClE,wBAAgB,QAAQ,CACpB,GAAG,EAAE,YAAY,EACjB,KAAK,EAAE,WAAW,EAClB,SAAS,EAAE,UAAU,GAAG,UAAU,EAClC,cAAc,EAAE,MAAM,EACtB,aAAa,CAAC,EAAE,YAAY,EAAE,GAC/B,QAAQ,CAgBV;AAED;;;;;;;GAOG;AACH,wBAAgB,KAAK,CACjB,GAAG,EAAE,YAAY,EACjB,KAAK,EAAE,WAAW,EAClB,SAAS,EAAE,UAAU,GAAG,UAAU,EAClC,cAAc,EAAE,MAAM,GACvB,MAAM,CAGR"}
|