assignment-user-matcher 1.13.0 → 1.15.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 +56 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -1
- package/dist/matcher.class.d.ts +1 -1
- package/dist/matcher.class.js +1 -1
- package/dist/scheduling/constraints/constraint.d.ts.map +1 -1
- package/dist/scheduling/constraints/constraint.js +7 -1
- package/dist/scheduling/constraints/contract.d.ts +1 -0
- package/dist/scheduling/constraints/contract.d.ts.map +1 -1
- package/dist/scheduling/constraints/contract.js +61 -16
- package/dist/scheduling/constraints/fairness.js +1 -1
- package/dist/scheduling/constraints/overtime.d.ts.map +1 -1
- package/dist/scheduling/constraints/overtime.js +4 -2
- package/dist/scheduling/constraints/site-eligibility.d.ts +11 -0
- package/dist/scheduling/constraints/site-eligibility.d.ts.map +1 -0
- package/dist/scheduling/constraints/site-eligibility.js +52 -0
- package/dist/scheduling/constraints/site-home.d.ts +14 -0
- package/dist/scheduling/constraints/site-home.d.ts.map +1 -0
- package/dist/scheduling/constraints/site-home.js +43 -0
- package/dist/scheduling/constraints/site-travel-gap.d.ts +19 -0
- package/dist/scheduling/constraints/site-travel-gap.d.ts.map +1 -0
- package/dist/scheduling/constraints/site-travel-gap.js +88 -0
- package/dist/scheduling/contract-hours.d.ts +42 -0
- package/dist/scheduling/contract-hours.d.ts.map +1 -0
- package/dist/scheduling/contract-hours.js +104 -0
- package/dist/scheduling/engine/construction.d.ts +22 -1
- package/dist/scheduling/engine/construction.d.ts.map +1 -1
- package/dist/scheduling/engine/construction.js +139 -4
- package/dist/scheduling/engine/objective.d.ts.map +1 -1
- package/dist/scheduling/engine/objective.js +5 -0
- package/dist/scheduling/engine/state.d.ts.map +1 -1
- package/dist/scheduling/engine/state.js +1 -0
- package/dist/scheduling/engine/timeline.d.ts +2 -0
- package/dist/scheduling/engine/timeline.d.ts.map +1 -1
- package/dist/scheduling/index.d.ts +4 -1
- package/dist/scheduling/index.d.ts.map +1 -1
- package/dist/scheduling/index.js +14 -1
- package/dist/scheduling/model.d.ts +11 -0
- package/dist/scheduling/model.d.ts.map +1 -1
- package/dist/scheduling/model.js +86 -1
- package/dist/scheduling/operations.d.ts +17 -1
- package/dist/scheduling/operations.d.ts.map +1 -1
- package/dist/scheduling/operations.js +71 -3
- package/dist/scheduling/provenance.d.ts +2 -2
- package/dist/scheduling/provenance.d.ts.map +1 -1
- package/dist/scheduling/provenance.js +15 -1
- package/dist/scheduling/scheduler.class.d.ts.map +1 -1
- package/dist/scheduling/scheduler.class.js +4 -1
- package/dist/scheduling/sites.d.ts +35 -0
- package/dist/scheduling/sites.d.ts.map +1 -0
- package/dist/scheduling/sites.js +112 -0
- package/dist/scheduling/types.d.ts +133 -1
- package/dist/scheduling/types.d.ts.map +1 -1
- package/package.json +13 -1
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Cross-site travel gap.
|
|
4
|
+
*
|
|
5
|
+
* When a person works two consecutive assignments at different sites, the gap
|
|
6
|
+
* between them must be at least the travel time between those sites. Only the
|
|
7
|
+
* immediate predecessor and successor on the person timeline are judged; a
|
|
8
|
+
* non-adjacent assignment does not create a direct travel obligation.
|
|
9
|
+
*
|
|
10
|
+
* The rule only enforces the gap; it does **not** count travel time as working
|
|
11
|
+
* time (CJEU C-266/14 would require that, but it is out of scope here — the
|
|
12
|
+
* caller models working time through `duty` and break rules).
|
|
13
|
+
*
|
|
14
|
+
* Because the default `min-rest` rule requires 11h between any two assignments,
|
|
15
|
+
* this rule mainly matters in split-shift setups where the caller has relaxed
|
|
16
|
+
* `minRestMinutes` or configured a `dailyRest` rule with a shorter window.
|
|
17
|
+
*/
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.siteTravelGap = void 0;
|
|
20
|
+
const sites_1 = require("../sites");
|
|
21
|
+
const support_1 = require("./support");
|
|
22
|
+
function siteTravelGap() {
|
|
23
|
+
return (0, support_1.fromVerdict)({
|
|
24
|
+
id: 'site-travel-gap',
|
|
25
|
+
hardness: 'hard',
|
|
26
|
+
verdict(state, pair) {
|
|
27
|
+
const inst = (0, support_1.instanceOf)(state, pair);
|
|
28
|
+
if (!inst?.siteId)
|
|
29
|
+
return (0, support_1.pass)('site-travel-gap', 'shift has no site');
|
|
30
|
+
const timeline = (0, support_1.timelineFor)(state, pair.employeeId);
|
|
31
|
+
const candidateRange = (0, support_1.rangeOf)(inst);
|
|
32
|
+
const ownId = (0, support_1.entryIdOf)(pair);
|
|
33
|
+
const siteId = inst.siteId;
|
|
34
|
+
let predecessor;
|
|
35
|
+
let successor;
|
|
36
|
+
for (const entry of timeline.all()) {
|
|
37
|
+
if (entry.id === ownId)
|
|
38
|
+
continue;
|
|
39
|
+
if (!entry.siteId || entry.siteId === siteId)
|
|
40
|
+
continue;
|
|
41
|
+
if (entry.end <= candidateRange.start) {
|
|
42
|
+
if (!predecessor || entry.end > predecessor.end) {
|
|
43
|
+
predecessor = entry;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (entry.start >= candidateRange.end) {
|
|
47
|
+
if (!successor || entry.start < successor.start) {
|
|
48
|
+
successor = entry;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
let worstActual = Infinity;
|
|
53
|
+
let worstRequired = 0;
|
|
54
|
+
let worstMessage = '';
|
|
55
|
+
if (predecessor) {
|
|
56
|
+
const needed = (0, sites_1.travelMinutesBetween)(state.ctx.siteIndex, predecessor.siteId, siteId);
|
|
57
|
+
if (needed !== undefined) {
|
|
58
|
+
const gap = candidateRange.start - predecessor.end;
|
|
59
|
+
if (gap < needed) {
|
|
60
|
+
worstActual = gap;
|
|
61
|
+
worstRequired = needed;
|
|
62
|
+
worstMessage = `only ${(0, support_1.h)(gap)} gap after a shift at "${predecessor.siteId}", need ${(0, support_1.h)(needed)} to reach "${siteId}"`;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (successor) {
|
|
67
|
+
const needed = (0, sites_1.travelMinutesBetween)(state.ctx.siteIndex, siteId, successor.siteId);
|
|
68
|
+
if (needed !== undefined) {
|
|
69
|
+
const gap = successor.start - candidateRange.end;
|
|
70
|
+
if (gap < needed && needed - gap > worstRequired - worstActual) {
|
|
71
|
+
worstActual = gap;
|
|
72
|
+
worstRequired = needed;
|
|
73
|
+
worstMessage = `only ${(0, support_1.h)(gap)} gap before a shift at "${successor.siteId}", need ${(0, support_1.h)(needed)} to reach it from "${siteId}"`;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (worstRequired > worstActual) {
|
|
78
|
+
return (0, support_1.fail)('site-travel-gap', 'hard', `site travel: ${worstMessage}`, {
|
|
79
|
+
actual: worstActual,
|
|
80
|
+
required: worstRequired,
|
|
81
|
+
unit: 'minutes',
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
return (0, support_1.pass)('site-travel-gap', `travel gap to "${siteId}" is sufficient`);
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
exports.siteTravelGap = siteTravelGap;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contracted hours — pure arithmetic shared by the model, the contract rule,
|
|
3
|
+
* the objective and the result summary.
|
|
4
|
+
*
|
|
5
|
+
* A person's contracted week can be stated two ways: as minutes
|
|
6
|
+
* (`contract.weeklyMinutes`) or as a fraction of full time (`contract.fte`).
|
|
7
|
+
* Both resolve **once**, in `buildModel`, to `ModelContext.contractedWeeklyMinutes`,
|
|
8
|
+
* and every consumer — the overtime baseline, pro-rata fairness, the
|
|
9
|
+
* contract-hours objective, the period cap — reads that one map. Resolving in
|
|
10
|
+
* each rule separately is how a half-timer ends up with a full-time overtime
|
|
11
|
+
* threshold and a half-time fairness share in the same roster.
|
|
12
|
+
*
|
|
13
|
+
* The full-time week the fraction is measured against is caller data
|
|
14
|
+
* (`rules.contract.fullTimeWeeklyMinutes`, or the ordinary week the overtime
|
|
15
|
+
* rule already states). The engine ships no figure for it: what "full time"
|
|
16
|
+
* means is a contractual or statutory fact that differs by country and by
|
|
17
|
+
* collective agreement, and the library's position is to carry rule shapes and
|
|
18
|
+
* never a jurisdiction's values.
|
|
19
|
+
*/
|
|
20
|
+
import type { ContractHoursSummary, Employee, SearchState, WorkingTimeRules } from './types';
|
|
21
|
+
/** Default `objectives.contractHoursWeight`: one soft point per hour away from contract. */
|
|
22
|
+
export declare const DEFAULT_CONTRACT_HOURS_WEIGHT = 1;
|
|
23
|
+
/** The full-time week the rules state, if any. */
|
|
24
|
+
export declare function fullTimeWeeklyMinutes(rules: WorkingTimeRules | undefined): number | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* A person's contracted week in minutes, or `undefined` when their contract
|
|
27
|
+
* states none. Throws when an `fte` cannot be resolved — the engine never
|
|
28
|
+
* guesses a working week.
|
|
29
|
+
*/
|
|
30
|
+
export declare function resolveContractedWeeklyMinutes(employee: Employee, rules: WorkingTimeRules | undefined): number | undefined;
|
|
31
|
+
/** A weekly figure pro-rated to a period of `periodDays` days. */
|
|
32
|
+
export declare function contractedPeriodMinutes(weeklyMinutes: number, periodDays: number): number;
|
|
33
|
+
/**
|
|
34
|
+
* Summed distance from contract across the roster, in hours, weighted. Lower
|
|
35
|
+
* is better; the objective adds it at the soft level. Symmetric on purpose —
|
|
36
|
+
* with coverage fixed by demand, penalising both surplus and shortfall is what
|
|
37
|
+
* distributes the hours pro rata instead of merely capping the busiest.
|
|
38
|
+
*/
|
|
39
|
+
export declare function contractHoursPenalty(state: SearchState): number;
|
|
40
|
+
/** Planned against contracted, per employee with a contract, in input order. */
|
|
41
|
+
export declare function contractHoursSummary(state: SearchState): ContractHoursSummary[];
|
|
42
|
+
//# sourceMappingURL=contract-hours.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract-hours.d.ts","sourceRoot":"","sources":["../../src/scheduling/contract-hours.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,QAAQ,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAG7F,4FAA4F;AAC5F,eAAO,MAAM,6BAA6B,IAAI,CAAC;AAE/C,kDAAkD;AAClD,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,gBAAgB,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAE7F;AAED;;;;GAIG;AACH,wBAAgB,8BAA8B,CAC1C,QAAQ,EAAE,QAAQ,EAClB,KAAK,EAAE,gBAAgB,GAAG,SAAS,GACpC,MAAM,GAAG,SAAS,CAwBpB;AAED,kEAAkE;AAClE,wBAAgB,uBAAuB,CAAC,aAAa,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAEzF;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,WAAW,GAAG,MAAM,CAS/D;AAED,gFAAgF;AAChF,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,WAAW,GAAG,oBAAoB,EAAE,CAqB/E"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Contracted hours — pure arithmetic shared by the model, the contract rule,
|
|
4
|
+
* the objective and the result summary.
|
|
5
|
+
*
|
|
6
|
+
* A person's contracted week can be stated two ways: as minutes
|
|
7
|
+
* (`contract.weeklyMinutes`) or as a fraction of full time (`contract.fte`).
|
|
8
|
+
* Both resolve **once**, in `buildModel`, to `ModelContext.contractedWeeklyMinutes`,
|
|
9
|
+
* and every consumer — the overtime baseline, pro-rata fairness, the
|
|
10
|
+
* contract-hours objective, the period cap — reads that one map. Resolving in
|
|
11
|
+
* each rule separately is how a half-timer ends up with a full-time overtime
|
|
12
|
+
* threshold and a half-time fairness share in the same roster.
|
|
13
|
+
*
|
|
14
|
+
* The full-time week the fraction is measured against is caller data
|
|
15
|
+
* (`rules.contract.fullTimeWeeklyMinutes`, or the ordinary week the overtime
|
|
16
|
+
* rule already states). The engine ships no figure for it: what "full time"
|
|
17
|
+
* means is a contractual or statutory fact that differs by country and by
|
|
18
|
+
* collective agreement, and the library's position is to carry rule shapes and
|
|
19
|
+
* never a jurisdiction's values.
|
|
20
|
+
*/
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.contractHoursSummary = exports.contractHoursPenalty = exports.contractedPeriodMinutes = exports.resolveContractedWeeklyMinutes = exports.fullTimeWeeklyMinutes = exports.DEFAULT_CONTRACT_HOURS_WEIGHT = void 0;
|
|
23
|
+
const types_1 = require("./types");
|
|
24
|
+
/** Default `objectives.contractHoursWeight`: one soft point per hour away from contract. */
|
|
25
|
+
exports.DEFAULT_CONTRACT_HOURS_WEIGHT = 1;
|
|
26
|
+
/** The full-time week the rules state, if any. */
|
|
27
|
+
function fullTimeWeeklyMinutes(rules) {
|
|
28
|
+
return rules?.contract?.fullTimeWeeklyMinutes ?? rules?.overtime?.ordinaryPerWeekMinutes;
|
|
29
|
+
}
|
|
30
|
+
exports.fullTimeWeeklyMinutes = fullTimeWeeklyMinutes;
|
|
31
|
+
/**
|
|
32
|
+
* A person's contracted week in minutes, or `undefined` when their contract
|
|
33
|
+
* states none. Throws when an `fte` cannot be resolved — the engine never
|
|
34
|
+
* guesses a working week.
|
|
35
|
+
*/
|
|
36
|
+
function resolveContractedWeeklyMinutes(employee, rules) {
|
|
37
|
+
const contract = employee.contract;
|
|
38
|
+
if (!contract)
|
|
39
|
+
return undefined;
|
|
40
|
+
if (contract.weeklyMinutes !== undefined) {
|
|
41
|
+
if (!Number.isFinite(contract.weeklyMinutes) || contract.weeklyMinutes < 0) {
|
|
42
|
+
throw new types_1.ScheduleValidationError(`Employee "${employee.id}" has invalid contract.weeklyMinutes: ${contract.weeklyMinutes}`);
|
|
43
|
+
}
|
|
44
|
+
return contract.weeklyMinutes;
|
|
45
|
+
}
|
|
46
|
+
if (contract.fte === undefined)
|
|
47
|
+
return undefined;
|
|
48
|
+
if (!Number.isFinite(contract.fte) || contract.fte <= 0 || contract.fte > 1) {
|
|
49
|
+
throw new types_1.ScheduleValidationError(`Employee "${employee.id}" has invalid contract.fte: ${contract.fte} (expected 0 < fte <= 1)`);
|
|
50
|
+
}
|
|
51
|
+
const fullTime = fullTimeWeeklyMinutes(rules);
|
|
52
|
+
if (fullTime === undefined) {
|
|
53
|
+
throw new types_1.ScheduleValidationError(`Employee "${employee.id}" has contract.fte but no full-time week to measure it against: set rules.contract.fullTimeWeeklyMinutes (or rules.overtime.ordinaryPerWeekMinutes)`);
|
|
54
|
+
}
|
|
55
|
+
return Math.round(fullTime * contract.fte);
|
|
56
|
+
}
|
|
57
|
+
exports.resolveContractedWeeklyMinutes = resolveContractedWeeklyMinutes;
|
|
58
|
+
/** A weekly figure pro-rated to a period of `periodDays` days. */
|
|
59
|
+
function contractedPeriodMinutes(weeklyMinutes, periodDays) {
|
|
60
|
+
return Math.round((weeklyMinutes * periodDays) / 7);
|
|
61
|
+
}
|
|
62
|
+
exports.contractedPeriodMinutes = contractedPeriodMinutes;
|
|
63
|
+
/**
|
|
64
|
+
* Summed distance from contract across the roster, in hours, weighted. Lower
|
|
65
|
+
* is better; the objective adds it at the soft level. Symmetric on purpose —
|
|
66
|
+
* with coverage fixed by demand, penalising both surplus and shortfall is what
|
|
67
|
+
* distributes the hours pro rata instead of merely capping the busiest.
|
|
68
|
+
*/
|
|
69
|
+
function contractHoursPenalty(state) {
|
|
70
|
+
const weight = state.ctx.contractHoursWeight;
|
|
71
|
+
if (!(weight > 0) || state.ctx.contractedPeriodMinutes.size === 0)
|
|
72
|
+
return 0;
|
|
73
|
+
let penalty = 0;
|
|
74
|
+
for (const [employeeId, contracted] of state.ctx.contractedPeriodMinutes) {
|
|
75
|
+
const planned = state.minutesByEmployee.get(employeeId) ?? 0;
|
|
76
|
+
penalty += Math.abs(planned - contracted) / 60;
|
|
77
|
+
}
|
|
78
|
+
return penalty * weight;
|
|
79
|
+
}
|
|
80
|
+
exports.contractHoursPenalty = contractHoursPenalty;
|
|
81
|
+
/** Planned against contracted, per employee with a contract, in input order. */
|
|
82
|
+
function contractHoursSummary(state) {
|
|
83
|
+
const out = [];
|
|
84
|
+
for (const employee of state.ctx.employees) {
|
|
85
|
+
const weeklyMinutes = state.ctx.contractedWeeklyMinutes.get(employee.id);
|
|
86
|
+
const contractedMinutes = state.ctx.contractedPeriodMinutes.get(employee.id);
|
|
87
|
+
if (weeklyMinutes === undefined || contractedMinutes === undefined)
|
|
88
|
+
continue;
|
|
89
|
+
const plannedMinutes = state.minutesByEmployee.get(employee.id) ?? 0;
|
|
90
|
+
const fullTime = fullTimeWeeklyMinutes(state.ctx.rulesByEmployee.get(employee.id) ?? state.ctx.rules);
|
|
91
|
+
const fte = employee.contract?.fte ??
|
|
92
|
+
(fullTime !== undefined && fullTime > 0 ? Math.round((weeklyMinutes / fullTime) * 1000) / 1000 : undefined);
|
|
93
|
+
out.push({
|
|
94
|
+
employeeId: employee.id,
|
|
95
|
+
weeklyMinutes,
|
|
96
|
+
...(fte !== undefined ? { fte } : {}),
|
|
97
|
+
contractedMinutes,
|
|
98
|
+
plannedMinutes,
|
|
99
|
+
deltaMinutes: plannedMinutes - contractedMinutes,
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
return out;
|
|
103
|
+
}
|
|
104
|
+
exports.contractHoursSummary = contractHoursSummary;
|
|
@@ -6,6 +6,14 @@
|
|
|
6
6
|
* pair is only ever assigned when every hard constraint's `delta` is 0, so a
|
|
7
7
|
* constructed state is always hard-compliant; shortfalls surface as unfilled
|
|
8
8
|
* slots, not breaches.
|
|
9
|
+
*
|
|
10
|
+
* Cover is the floor, not the ceiling. Once every slot has its `minEmployees`
|
|
11
|
+
* a second pass tops people up towards the hours they are owed — the
|
|
12
|
+
* contracted period total, or a `minHoursForPeriod` floor — by adding them to
|
|
13
|
+
* shifts that still have room. Without it a full-timer only ever receives a
|
|
14
|
+
* share of minimum cover: with more contracted hours on the payroll than the
|
|
15
|
+
* demand needs, everyone lands short and the contract-hours objective has no
|
|
16
|
+
* move that could close the gap, because nothing ever staffs past the minimum.
|
|
9
17
|
*/
|
|
10
18
|
import type { ModelContext } from '../types';
|
|
11
19
|
import type { PropagationResult } from './propagation';
|
|
@@ -14,9 +22,22 @@ import { type InternalState } from './state';
|
|
|
14
22
|
export declare function hardCompliant(ctx: ModelContext, state: InternalState, employeeId: string, instanceId: string): boolean;
|
|
15
23
|
/** Instances ordered most-constrained-first: fewest eligible employees, then earliest start. */
|
|
16
24
|
export declare function constructionOrder(ctx: ModelContext, propagation: PropagationResult): string[];
|
|
25
|
+
/**
|
|
26
|
+
* Top people up towards their contracted hours once cover is met.
|
|
27
|
+
*
|
|
28
|
+
* Most-owed person first, so the biggest shortfall gets first pick of the
|
|
29
|
+
* shifts with room. Each pick is the eligible, hard-compliant shift that
|
|
30
|
+
* closes the most of the gap, preferring the least-staffed occurrence so the
|
|
31
|
+
* extra headcount spreads rather than piles onto one day. Repeats until no
|
|
32
|
+
* assignment would bring anyone closer to their target. `maxEmployees` is
|
|
33
|
+
* enforced by the group-composition rule inside `hardCompliant`, and the
|
|
34
|
+
* cheap size check here merely skips the constraint pass for full shifts.
|
|
35
|
+
*/
|
|
36
|
+
export declare function fillToContract(ctx: ModelContext, state: InternalState, propagation: PropagationResult, rand: () => number): void;
|
|
17
37
|
/**
|
|
18
38
|
* Greedily staff `instanceIds` (default: everything, most-constrained first).
|
|
19
|
-
* Shared by initial construction and LNS repair.
|
|
39
|
+
* Shared by initial construction and LNS repair. The full pass (no
|
|
40
|
+
* `instanceIds`) also tops people up to their contracted hours afterwards.
|
|
20
41
|
*/
|
|
21
42
|
export declare function greedyFill(ctx: ModelContext, state: InternalState, propagation: PropagationResult, objective: 'standard' | 'balanced', rand: () => number, instanceIds?: string[]): void;
|
|
22
43
|
//# sourceMappingURL=construction.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"construction.d.ts","sourceRoot":"","sources":["../../../src/scheduling/engine/construction.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"construction.d.ts","sourceRoot":"","sources":["../../../src/scheduling/engine/construction.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAU,KAAK,aAAa,EAAE,MAAM,SAAS,CAAC;AAGrD,wEAAwE;AACxE,wBAAgB,aAAa,CAAC,GAAG,EAAE,YAAY,EAAE,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAKtH;AAsDD,gGAAgG;AAChG,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,YAAY,EAAE,WAAW,EAAE,iBAAiB,GAAG,MAAM,EAAE,CAS7F;AAwDD;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAC1B,GAAG,EAAE,YAAY,EACjB,KAAK,EAAE,aAAa,EACpB,WAAW,EAAE,iBAAiB,EAC9B,IAAI,EAAE,MAAM,MAAM,GACnB,IAAI,CAsCN;AAKD;;;;GAIG;AACH,wBAAgB,UAAU,CACtB,GAAG,EAAE,YAAY,EACjB,KAAK,EAAE,aAAa,EACpB,WAAW,EAAE,iBAAiB,EAC9B,SAAS,EAAE,UAAU,GAAG,UAAU,EAClC,IAAI,EAAE,MAAM,MAAM,EAClB,WAAW,CAAC,EAAE,MAAM,EAAE,GACvB,IAAI,CA6BN"}
|
|
@@ -7,10 +7,19 @@
|
|
|
7
7
|
* pair is only ever assigned when every hard constraint's `delta` is 0, so a
|
|
8
8
|
* constructed state is always hard-compliant; shortfalls surface as unfilled
|
|
9
9
|
* slots, not breaches.
|
|
10
|
+
*
|
|
11
|
+
* Cover is the floor, not the ceiling. Once every slot has its `minEmployees`
|
|
12
|
+
* a second pass tops people up towards the hours they are owed — the
|
|
13
|
+
* contracted period total, or a `minHoursForPeriod` floor — by adding them to
|
|
14
|
+
* shifts that still have room. Without it a full-timer only ever receives a
|
|
15
|
+
* share of minimum cover: with more contracted hours on the payroll than the
|
|
16
|
+
* demand needs, everyone lands short and the contract-hours objective has no
|
|
17
|
+
* move that could close the gap, because nothing ever staffs past the minimum.
|
|
10
18
|
*/
|
|
11
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.greedyFill = exports.constructionOrder = exports.hardCompliant = void 0;
|
|
20
|
+
exports.greedyFill = exports.fillToContract = exports.constructionOrder = exports.hardCompliant = void 0;
|
|
13
21
|
const state_1 = require("./state");
|
|
22
|
+
const support_1 = require("../constraints/support");
|
|
14
23
|
/** Whether assigning the pair keeps every hard constraint satisfied. */
|
|
15
24
|
function hardCompliant(ctx, state, employeeId, instanceId) {
|
|
16
25
|
for (const c of ctx.constraints) {
|
|
@@ -40,8 +49,16 @@ function rankCandidate(ctx, state, instanceId, employeeId, objective, rand) {
|
|
|
40
49
|
}
|
|
41
50
|
}
|
|
42
51
|
if (objective === 'balanced') {
|
|
43
|
-
// Less-loaded employees first so hours equalize
|
|
44
|
-
|
|
52
|
+
// Less-loaded employees first so hours equalize — measured against the
|
|
53
|
+
// hours each of them is owed, not against zero. Raw minutes read a
|
|
54
|
+
// quarter-timer on 15h as emptier than a full-timer on 30h, so cover
|
|
55
|
+
// lands on the smallest contracts and pushes them furthest over; the
|
|
56
|
+
// distance from a contracted total is the load a person actually
|
|
57
|
+
// carries. Without a contract there is nothing to measure against, so
|
|
58
|
+
// absolute hours remain the only reading.
|
|
59
|
+
const planned = state.minutesByEmployee.get(employeeId) ?? 0;
|
|
60
|
+
const contracted = ctx.contractedPeriodMinutes.get(employeeId);
|
|
61
|
+
rank += (contracted === undefined ? planned : planned - contracted) / 60;
|
|
45
62
|
reasons.push('selected to balance hours');
|
|
46
63
|
}
|
|
47
64
|
else {
|
|
@@ -64,9 +81,125 @@ function constructionOrder(ctx, propagation) {
|
|
|
64
81
|
});
|
|
65
82
|
}
|
|
66
83
|
exports.constructionOrder = constructionOrder;
|
|
84
|
+
/**
|
|
85
|
+
* Minutes an employee is still owed against their target, or 0 when nothing
|
|
86
|
+
* pulls them upward. A contracted total is symmetric — the objective penalises
|
|
87
|
+
* surplus as much as shortfall — so only a shift that leaves the person
|
|
88
|
+
* *closer* to it counts as progress; a bare `minHoursForPeriod` is a floor.
|
|
89
|
+
*/
|
|
90
|
+
function hoursOwed(ctx, state, employeeId) {
|
|
91
|
+
const planned = state.minutesByEmployee.get(employeeId) ?? 0;
|
|
92
|
+
const contracted = ceilingFor(ctx, employeeId);
|
|
93
|
+
if (contracted !== undefined)
|
|
94
|
+
return Math.max(0, contracted - planned);
|
|
95
|
+
const floor = ctx.employeeById.get(employeeId)?.minHoursForPeriod;
|
|
96
|
+
return floor !== undefined ? Math.max(0, floor * 60 - planned) : 0;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* How far the top-up may plan this person: their contracted period total, plus
|
|
100
|
+
* whatever surplus the rules already allow (`contract.maxOverMinutes`).
|
|
101
|
+
*
|
|
102
|
+
* The allowance is the caller's stated position on over-contract work, and the
|
|
103
|
+
* `contract` rule enforces it as a hard cap. Reading it here is what lets a
|
|
104
|
+
* part-timer whose remaining room is smaller than any shift be planned at all —
|
|
105
|
+
* five hours short of a 20h contract with only 7.5h shifts on offer is a
|
|
106
|
+
* shortfall no roster can close without it. `undefined` (the default) keeps the
|
|
107
|
+
* contracted total as a strict ceiling.
|
|
108
|
+
*/
|
|
109
|
+
function ceilingFor(ctx, employeeId) {
|
|
110
|
+
if (!(ctx.contractHoursWeight > 0))
|
|
111
|
+
return undefined;
|
|
112
|
+
const contracted = ctx.contractedPeriodMinutes.get(employeeId);
|
|
113
|
+
if (contracted === undefined)
|
|
114
|
+
return undefined;
|
|
115
|
+
return contracted + ((0, support_1.rulesFor)(ctx, employeeId).contract?.maxOverMinutes ?? 0);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Whether the top-up may add `workingMinutes` to this person.
|
|
119
|
+
*
|
|
120
|
+
* A contracted total is a ceiling here, not a target to land nearest to: the
|
|
121
|
+
* shift is added only while it keeps them at or under contract. Judging it by
|
|
122
|
+
* distance instead would plan a half-timer on 15h of a 20h contract a further
|
|
123
|
+
* 7.5h shift — 2.5h over reads as "closer" than 5h short — and the roster would
|
|
124
|
+
* buy hours nobody asked for to shrink a deviation. Work beyond contract is a
|
|
125
|
+
* decision an employer makes (and `rules.contract.maxOverMinutes` bounds), never
|
|
126
|
+
* something the engine helps itself to.
|
|
127
|
+
*
|
|
128
|
+
* `minHoursForPeriod` is a floor rather than a contracted total, so it is
|
|
129
|
+
* judged the only way a floor can be: keep adding while the person is under it.
|
|
130
|
+
*/
|
|
131
|
+
function closesGap(ctx, state, employeeId, workingMinutes) {
|
|
132
|
+
const planned = state.minutesByEmployee.get(employeeId) ?? 0;
|
|
133
|
+
const contracted = ceilingFor(ctx, employeeId);
|
|
134
|
+
if (contracted !== undefined)
|
|
135
|
+
return planned + workingMinutes <= contracted;
|
|
136
|
+
const floor = ctx.employeeById.get(employeeId)?.minHoursForPeriod;
|
|
137
|
+
return floor !== undefined && planned < floor * 60;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Top people up towards their contracted hours once cover is met.
|
|
141
|
+
*
|
|
142
|
+
* Most-owed person first, so the biggest shortfall gets first pick of the
|
|
143
|
+
* shifts with room. Each pick is the eligible, hard-compliant shift that
|
|
144
|
+
* closes the most of the gap, preferring the least-staffed occurrence so the
|
|
145
|
+
* extra headcount spreads rather than piles onto one day. Repeats until no
|
|
146
|
+
* assignment would bring anyone closer to their target. `maxEmployees` is
|
|
147
|
+
* enforced by the group-composition rule inside `hardCompliant`, and the
|
|
148
|
+
* cheap size check here merely skips the constraint pass for full shifts.
|
|
149
|
+
*/
|
|
150
|
+
function fillToContract(ctx, state, propagation, rand) {
|
|
151
|
+
if (!ctx.fillToContract)
|
|
152
|
+
return;
|
|
153
|
+
const owed = ctx.employees
|
|
154
|
+
.map((e) => ({ employeeId: e.id, owed: hoursOwed(ctx, state, e.id) }))
|
|
155
|
+
.filter((e) => e.owed > 0);
|
|
156
|
+
if (owed.length === 0)
|
|
157
|
+
return;
|
|
158
|
+
const exhausted = new Set();
|
|
159
|
+
for (;;) {
|
|
160
|
+
owed.sort((a, b) => b.owed - a.owed || (a.employeeId < b.employeeId ? -1 : 1));
|
|
161
|
+
let progressed = false;
|
|
162
|
+
for (const entry of owed) {
|
|
163
|
+
if (entry.owed <= 0 || exhausted.has(entry.employeeId))
|
|
164
|
+
continue;
|
|
165
|
+
let best;
|
|
166
|
+
for (const instanceId of propagation.eligibility.get(entry.employeeId) ?? []) {
|
|
167
|
+
const inst = ctx.instanceById.get(instanceId);
|
|
168
|
+
if (!inst || inst.workingMinutes <= 0 || state.isAssigned(entry.employeeId, instanceId))
|
|
169
|
+
continue;
|
|
170
|
+
const staffed = state.assignments.get(instanceId)?.size ?? 0;
|
|
171
|
+
if (inst.maxEmployees !== undefined && staffed >= inst.maxEmployees)
|
|
172
|
+
continue;
|
|
173
|
+
if (!closesGap(ctx, state, entry.employeeId, inst.workingMinutes))
|
|
174
|
+
continue;
|
|
175
|
+
// Largest gap closed first, then the least-staffed occurrence,
|
|
176
|
+
// then earliest start; seeded jitter breaks exact ties.
|
|
177
|
+
const gain = Math.min(inst.workingMinutes, entry.owed);
|
|
178
|
+
const rank = -gain * 1000 + staffed * 10 + inst.startMinute / MINUTES_PER_PERIOD_SCALE + rand();
|
|
179
|
+
if (!best || rank < best.rank) {
|
|
180
|
+
if (hardCompliant(ctx, state, entry.employeeId, instanceId))
|
|
181
|
+
best = { instanceId, rank };
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
if (!best) {
|
|
185
|
+
exhausted.add(entry.employeeId);
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
(0, state_1.assign)(state, entry.employeeId, best.instanceId, ['added to reach contracted hours']);
|
|
189
|
+
entry.owed = hoursOwed(ctx, state, entry.employeeId);
|
|
190
|
+
progressed = true;
|
|
191
|
+
}
|
|
192
|
+
if (!progressed)
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
exports.fillToContract = fillToContract;
|
|
197
|
+
/** Scales a period minute into a sub-unit tie-break term below the staffing step. */
|
|
198
|
+
const MINUTES_PER_PERIOD_SCALE = 1000000;
|
|
67
199
|
/**
|
|
68
200
|
* Greedily staff `instanceIds` (default: everything, most-constrained first).
|
|
69
|
-
* Shared by initial construction and LNS repair.
|
|
201
|
+
* Shared by initial construction and LNS repair. The full pass (no
|
|
202
|
+
* `instanceIds`) also tops people up to their contracted hours afterwards.
|
|
70
203
|
*/
|
|
71
204
|
function greedyFill(ctx, state, propagation, objective, rand, instanceIds) {
|
|
72
205
|
const order = instanceIds ?? constructionOrder(ctx, propagation);
|
|
@@ -100,5 +233,7 @@ function greedyFill(ctx, state, propagation, objective, rand, instanceIds) {
|
|
|
100
233
|
need--;
|
|
101
234
|
}
|
|
102
235
|
}
|
|
236
|
+
if (!instanceIds)
|
|
237
|
+
fillToContract(ctx, state, propagation, rand);
|
|
103
238
|
}
|
|
104
239
|
exports.greedyFill = greedyFill;
|
|
@@ -1 +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;
|
|
1
|
+
{"version":3,"file":"objective.d.ts","sourceRoot":"","sources":["../../../src/scheduling/engine/objective.ts"],"names":[],"mappings":"AAAA;;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,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,CAoBV;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"}
|
|
@@ -29,6 +29,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
29
29
|
exports.score = exports.scoreLex = exports.softBreaches = exports.breachTotals = exports.minHoursShortfalls = exports.hoursVariance = exports.unfilledSlots = exports.tagShortage = exports.slotShortage = exports.isBetter = exports.compareScores = exports.DEFAULT_SOFT_WEIGHT = exports.MIN_HOURS_WEIGHT = exports.TAG_SHORTFALL_WEIGHT = exports.UNFILLED_WEIGHT = void 0;
|
|
30
30
|
const fairness_1 = require("../constraints/fairness");
|
|
31
31
|
const availability_1 = require("../constraints/availability");
|
|
32
|
+
const contract_hours_1 = require("../contract-hours");
|
|
32
33
|
exports.UNFILLED_WEIGHT = 10000;
|
|
33
34
|
exports.TAG_SHORTFALL_WEIGHT = 5000;
|
|
34
35
|
exports.MIN_HOURS_WEIGHT = 100;
|
|
@@ -144,6 +145,10 @@ function scoreLex(ctx, state, objective, minHoursWeight, fairnessRules) {
|
|
|
144
145
|
// Preferred/avoid availability windows are scored, not advisory: avoided
|
|
145
146
|
// assignments cost, preferred ones credit, weighted per rule.
|
|
146
147
|
totals.soft += (0, availability_1.preferencePenalty)(state);
|
|
148
|
+
// Contracted hours steer the plan: each person with a known contract is
|
|
149
|
+
// pulled towards their pro-rated period total, so a half-timer is planned
|
|
150
|
+
// half the hours rather than filled to the statutory ceiling.
|
|
151
|
+
totals.soft += (0, contract_hours_1.contractHoursPenalty)(state);
|
|
147
152
|
if (objective === 'balanced')
|
|
148
153
|
totals.soft += hoursVariance(ctx, state) / 60; // hours-scale variance term
|
|
149
154
|
return totals;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../../src/scheduling/engine/state.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAG1D,MAAM,WAAW,aAAc,SAAQ,WAAW;IAC9C,0FAA0F;IAC1F,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;CAClC;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,YAAY,GAAG,aAAa,CAsB5D;AAED,wBAAgB,OAAO,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAEtE;AAED,wBAAgB,MAAM,CAAC,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../../src/scheduling/engine/state.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAG1D,MAAM,WAAW,aAAc,SAAQ,WAAW;IAC9C,0FAA0F;IAC1F,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;CAClC;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,YAAY,GAAG,aAAa,CAsB5D;AAED,wBAAgB,OAAO,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAEtE;AAED,wBAAgB,MAAM,CAAC,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,CAsB5G;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI,CAW3F;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAE9E;AAED,yFAAyF;AACzF,wBAAgB,aAAa,CAAC,KAAK,EAAE,aAAa,GAAG,KAAK,CAAC;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAAC,CAQrG"}
|
|
@@ -34,6 +34,8 @@ export interface TimelineEntry extends MinuteRange {
|
|
|
34
34
|
workingMinutes: number;
|
|
35
35
|
/** Free-form classification tag used by sequence rules (e.g. a shift type). */
|
|
36
36
|
tag?: string;
|
|
37
|
+
/** Site where this span took place; drives cross-site travel-gap rules. */
|
|
38
|
+
siteId?: string;
|
|
37
39
|
/** Historical entries are immutable and never returned by the mutable views. */
|
|
38
40
|
historical?: boolean;
|
|
39
41
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timeline.d.ts","sourceRoot":"","sources":["../../../src/scheduling/engine/timeline.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAG3C,gDAAgD;AAChD,MAAM,WAAW,aAAc,SAAQ,WAAW;IAC9C,0EAA0E;IAC1E,EAAE,EAAE,MAAM,CAAC;IACX,wFAAwF;IACxF,cAAc,EAAE,MAAM,CAAC;IACvB,+E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AAC,MAAM,EAAE,WAAW,GAAG,MAAM;IAe1C;;;;OAIG;IACH,YAAY,CAAC,KAAK,EAAE,WAAW,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM;IAY5D,4DAA4D;IAC5D,OAAO,CAAC,MAAM,EAAE,WAAW,EAAE,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,OAAO,GAAG,MAAM;IAKnF;;;;OAIG;IACH,UAAU,CAAC,SAAS,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,OAAO,GAAG,MAAM;IAehE;;;;OAIG;IACH,sBAAsB,CAAC,UAAU,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,GAAG,MAAM;IAiBtE;;;;;;;;;OASG;IACH,OAAO,CAAC,gBAAgB;IAWxB,OAAO,CAAC,WAAW;IAInB,OAAO,CAAC,OAAO;CAWlB;AAED;;;;;;GAMG;AACH,qBAAa,aAAa;IACtB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAqC;gBAElD,OAAO,GAAE,GAAG,CAAC,MAAM,EAAE,aAAa,EAAE,CAAa;IAM7D,yDAAyD;IACzD,GAAG,CAAC,QAAQ,EAAE,MAAM,GAAG,cAAc;IASrC,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,GAAG,IAAI;IAIjD,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO;IAIlD,SAAS,IAAI,MAAM,EAAE;CAGxB"}
|
|
@@ -5,6 +5,9 @@ export { ScheduleValidationError } from './types';
|
|
|
5
5
|
export { DEFAULT_MIN_REST_MINUTES } from './constraints/min-rest';
|
|
6
6
|
export { checkCompliance, explainCandidate, repairSchedule, rankCandidates, diagnoseInfeasibility, type ComplianceReport, type Disruption, type RepairCandidate, type RepairResult, type InfeasibilityReport, } from './operations';
|
|
7
7
|
export { PeriodClock, type MinuteRange, type ClockRange } from './time';
|
|
8
|
+
export { expandShiftInstances } from './model';
|
|
8
9
|
export { hours, days, weeklyAverageOver } from './rules';
|
|
9
|
-
export
|
|
10
|
+
export { DEFAULT_CONTRACT_HOURS_WEIGHT, contractedPeriodMinutes, fullTimeWeeklyMinutes, resolveContractedWeeklyMinutes, } from './contract-hours';
|
|
11
|
+
export type { AssignmentPair, AvailabilityRule, BreakRule, ClockRangeConfig, ConsecutiveRule, ConstraintOptions, ConstraintViolation, ContractHoursRule, ContractHoursSummary, DailyRestRule, DutyClassification, DutyQuota, Employee, EmployeeContract, EmployeeCost, EmployeeProtection, EngagementRule, FairnessRule, HistoricalAssignment, LedgerEntry, ModelContext, NightVolumeQuota, NightWorkRule, NoticeRule, ObjectiveWeights, OvertimeRule, Qualification, RestDayRule, RollingAverage, RuleVerdict, ScheduleInput, ScheduleProvenance, ScheduleResult, ScheduledAssignment, SchedulingConstraint, SearchState, Severity, ShiftInstance, ShiftTemplate, Site, SiteIndex, TimeOffEntry, WeeklyRestRule, WorkingTimeLimits, WorkingTimeRules, } from './types';
|
|
12
|
+
export type { PersonTimeline, TimelineEntry, TimelineIndex } from './engine/timeline';
|
|
10
13
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/scheduling/index.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAClF,OAAO,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAClD,4FAA4F;AAC5F,OAAO,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAGlE,OAAO,EACH,eAAe,EACf,gBAAgB,EAChB,cAAc,EACd,cAAc,EACd,qBAAqB,EACrB,KAAK,gBAAgB,EACrB,KAAK,UAAU,EACf,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,mBAAmB,GAC3B,MAAM,cAAc,CAAC;AAGt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ACb,WAAW,EACX,cAAc,EACd,WAAW,EACX,aAAa,EACb,kBAAkB,EAClB,cAAc,EACd,mBAAmB,EACnB,oBAAoB,EACpB,WAAW,EACX,QAAQ,EACR,aAAa,EACb,aAAa,EACb,IAAI,EACJ,SAAS,EACT,YAAY,EACZ,cAAc,EACd,iBAAiB,EACjB,gBAAgB,GACnB,MAAM,SAAS,CAAC;AAIjB,YAAY,EAAE,cAAc,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/scheduling/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.weeklyAverageOver = exports.days = exports.hours = exports.PeriodClock = exports.diagnoseInfeasibility = exports.rankCandidates = exports.repairSchedule = exports.explainCandidate = exports.checkCompliance = exports.DEFAULT_MIN_REST_MINUTES = exports.ScheduleValidationError = exports.ENGINE_VERSION = exports.solveSchedule = exports.ShiftScheduler = void 0;
|
|
3
|
+
exports.resolveContractedWeeklyMinutes = exports.fullTimeWeeklyMinutes = exports.contractedPeriodMinutes = exports.DEFAULT_CONTRACT_HOURS_WEIGHT = exports.weeklyAverageOver = exports.days = exports.hours = exports.expandShiftInstances = exports.PeriodClock = exports.diagnoseInfeasibility = exports.rankCandidates = exports.repairSchedule = exports.explainCandidate = exports.checkCompliance = exports.DEFAULT_MIN_REST_MINUTES = exports.ScheduleValidationError = exports.ENGINE_VERSION = exports.solveSchedule = exports.ShiftScheduler = void 0;
|
|
4
4
|
/** Public surface of the scheduling module. */
|
|
5
5
|
var scheduler_class_1 = require("./scheduler.class");
|
|
6
6
|
Object.defineProperty(exports, "ShiftScheduler", { enumerable: true, get: function () { return scheduler_class_1.ShiftScheduler; } });
|
|
@@ -21,9 +21,22 @@ Object.defineProperty(exports, "diagnoseInfeasibility", { enumerable: true, get:
|
|
|
21
21
|
// Time model, exported so hosts can resolve the same wall-clock the engine does.
|
|
22
22
|
var time_1 = require("./time");
|
|
23
23
|
Object.defineProperty(exports, "PeriodClock", { enumerable: true, get: function () { return time_1.PeriodClock; } });
|
|
24
|
+
// The dated occurrences a host draws its planning grid from. Exported so a
|
|
25
|
+
// grid addresses the same `<templateId>@<date>` ids the engine judges, rather
|
|
26
|
+
// than a re-derivation of them that can drift.
|
|
27
|
+
var model_1 = require("./model");
|
|
28
|
+
Object.defineProperty(exports, "expandShiftInstances", { enumerable: true, get: function () { return model_1.expandShiftInstances; } });
|
|
24
29
|
// Rule-authoring arithmetic (no jurisdiction values, just the conversions
|
|
25
30
|
// people get wrong — notably weekly-average → rolling-window-total).
|
|
26
31
|
var rules_1 = require("./rules");
|
|
27
32
|
Object.defineProperty(exports, "hours", { enumerable: true, get: function () { return rules_1.hours; } });
|
|
28
33
|
Object.defineProperty(exports, "days", { enumerable: true, get: function () { return rules_1.days; } });
|
|
29
34
|
Object.defineProperty(exports, "weeklyAverageOver", { enumerable: true, get: function () { return rules_1.weeklyAverageOver; } });
|
|
35
|
+
// Contracted-hours arithmetic, exported so a host resolves `fte` to the same
|
|
36
|
+
// weekly figure the engine plans against (for pay estimates, planned-hours
|
|
37
|
+
// reports) rather than a second derivation that can drift.
|
|
38
|
+
var contract_hours_1 = require("./contract-hours");
|
|
39
|
+
Object.defineProperty(exports, "DEFAULT_CONTRACT_HOURS_WEIGHT", { enumerable: true, get: function () { return contract_hours_1.DEFAULT_CONTRACT_HOURS_WEIGHT; } });
|
|
40
|
+
Object.defineProperty(exports, "contractedPeriodMinutes", { enumerable: true, get: function () { return contract_hours_1.contractedPeriodMinutes; } });
|
|
41
|
+
Object.defineProperty(exports, "fullTimeWeeklyMinutes", { enumerable: true, get: function () { return contract_hours_1.fullTimeWeeklyMinutes; } });
|
|
42
|
+
Object.defineProperty(exports, "resolveContractedWeeklyMinutes", { enumerable: true, get: function () { return contract_hours_1.resolveContractedWeeklyMinutes; } });
|
|
@@ -27,6 +27,17 @@
|
|
|
27
27
|
import type { AvailabilityRule, ConstraintOptions, ModelContext, ObjectiveWeights, ScheduleInput, SchedulingConstraint, ShiftInstance, ShiftTemplate, WorkingTimeRules } from './types';
|
|
28
28
|
import { PeriodClock, MINUTES_PER_DAY } from './time';
|
|
29
29
|
export { daysBetween, addDays } from './time';
|
|
30
|
+
/**
|
|
31
|
+
* Expand a whole input's templates into the dated occurrences the engine will
|
|
32
|
+
* judge — the grid a host draws before anything is assigned.
|
|
33
|
+
*
|
|
34
|
+
* It takes the `ScheduleInput` rather than a clock so the caller cannot hand in
|
|
35
|
+
* a period clock built on a different timezone or length than the solve will
|
|
36
|
+
* use: the ids and wall-clock minutes here are the ones every later call
|
|
37
|
+
* (`explainCandidate`, `checkCompliance`, a returned `ScheduledAssignment`)
|
|
38
|
+
* refers to.
|
|
39
|
+
*/
|
|
40
|
+
export declare function expandShiftInstances(input: ScheduleInput): ShiftInstance[];
|
|
30
41
|
/** Expand one template into its dated instances inside the period. */
|
|
31
42
|
export declare function expandTemplate(template: ShiftTemplate, clock: PeriodClock, periodDays: number, context: {
|
|
32
43
|
nightRule?: WorkingTimeRules['nightWork'];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../src/scheduling/model.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,KAAK,EACR,gBAAgB,EAChB,iBAAiB,EAGjB,YAAY,EACZ,gBAAgB,EAChB,aAAa,EACb,oBAAoB,EACpB,aAAa,EACb,aAAa,EACb,gBAAgB,EACnB,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../src/scheduling/model.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,KAAK,EACR,gBAAgB,EAChB,iBAAiB,EAGjB,YAAY,EACZ,gBAAgB,EAChB,aAAa,EACb,oBAAoB,EACpB,aAAa,EACb,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