@jsb188/schedule 1.1.12 → 1.1.13
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/LICENSE +21 -0
- package/package.json +33 -14
- package/src/constants/schedule.ts +710 -306
- package/src/types/schedule.d.ts +1827 -456
- package/src/ui/ScheduleSettingsUI.tsx +21 -23
- package/src/utils/autofill.ts +469 -0
- package/src/utils/availability.ts +167 -0
- package/src/utils/candidates.ts +447 -0
- package/src/utils/coverage.helpers.ts +509 -554
- package/src/utils/coverage.ts +1121 -526
- package/src/utils/cpm.helpers.ts +27 -29
- package/src/utils/cpm.ts +53 -41
- package/src/utils/cpmLeveling.helpers.ts +89 -16
- package/src/utils/cpmLeveling.ts +28 -26
- package/src/utils/cycle.ts +325 -0
- package/src/utils/demand.ts +239 -0
- package/src/utils/eligibility.ts +553 -400
- package/src/utils/ids.ts +47 -0
- package/src/utils/laborRules.ts +740 -0
- package/src/utils/localTime.ts +312 -0
- package/src/utils/offer.ts +300 -0
- package/src/utils/planCsv.ts +73 -19
- package/src/utils/predicate.ts +111 -0
- package/src/utils/request.ts +212 -114
- package/src/utils/resource.ts +412 -112
- package/src/utils/rule.ts +697 -163
- package/src/utils/rulePresets.ts +116 -0
- package/src/utils/run.ts +0 -8
- package/src/utils/scheduleText.ts +4074 -0
- package/src/utils/shiftChange.ts +279 -0
- package/src/utils/standing.ts +730 -0
- package/src/utils/template.ts +619 -0
- package/src/utils/violation.ts +184 -0
- package/src/utils/workTime.ts +341 -120
- package/src/utils/defaults.ts +0 -8
- package/src/utils/recurrence.ts +0 -616
- package/src/utils/series.ts +0 -161
- package/src/utils/slot.ts +0 -208
- package/tests/coverage.fixtures.ts +0 -111
- package/tests/coverage.test.ts +0 -503
- package/tests/cpm.bench.test.ts +0 -154
- package/tests/cpm.test.ts +0 -354
- package/tests/cpmCorrectness.test.ts +0 -327
- package/tests/cpmLeveling.test.ts +0 -471
- package/tests/eligibility.test.ts +0 -320
- package/tests/gantt-geometry.test.ts +0 -367
- package/tests/gantt-histogram.test.ts +0 -78
- package/tests/gantt-keyboard.test.ts +0 -69
- package/tests/helpers/cpmFixtures.ts +0 -101
- package/tests/projectInputs.test.ts +0 -165
- package/tests/recurrence.test.ts +0 -68
- package/tests/request.test.ts +0 -99
- package/tests/resource.test.ts +0 -95
- package/tests/rule.test.ts +0 -98
- package/tests/series.test.ts +0 -120
- package/tests/workTime.test.ts +0 -1007
- package/tests/workTimeContracts.test.ts +0 -111
- package/tsconfig.json +0 -13
- package/vitest.config.ts +0 -8
package/src/utils/cpm.helpers.ts
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
2
|
SCHEDULE_ACTIVITY_TYPE_ENUMS,
|
|
3
3
|
SCHEDULE_CONSTRAINT_TYPE_ENUMS,
|
|
4
|
+
SCHEDULE_CYCLE_MESSAGE_MAX_HOPS,
|
|
4
5
|
SCHEDULE_DIAGNOSTIC_CAP_PER_CODE,
|
|
5
6
|
SCHEDULE_DIAGNOSTIC_MAX_ACTIVITY_IDS,
|
|
7
|
+
SCHEDULE_LEVELING_DEFAULT_HORIZON_DAYS,
|
|
8
|
+
SCHEDULE_LEVELING_LEDGER_GUARD_DAYS,
|
|
9
|
+
SCHEDULE_LEVELING_PRIORITY_DEFAULT,
|
|
10
|
+
SCHEDULE_LEVELING_PRIORITY_MAX,
|
|
11
|
+
SCHEDULE_LEVELING_PRIORITY_MIN,
|
|
6
12
|
SCHEDULE_LEVELING_PRIORITY_RULE_ENUMS,
|
|
7
13
|
SCHEDULE_RELATIONSHIP_TYPE_ENUMS,
|
|
8
14
|
} from '../constants/schedule.ts';
|
|
@@ -15,6 +21,8 @@ import type {
|
|
|
15
21
|
ScheduleDiagnosticObj,
|
|
16
22
|
ScheduleWorkCalendarDef,
|
|
17
23
|
} from '../types/schedule.d.ts';
|
|
24
|
+
import { compareScheduleIds } from './ids.ts';
|
|
25
|
+
import { toScheduleTimeMs } from './localTime.ts';
|
|
18
26
|
import {
|
|
19
27
|
addWorkingMinutes,
|
|
20
28
|
getWorkingMinutesPerDay,
|
|
@@ -26,14 +34,6 @@ import {
|
|
|
26
34
|
type WorkCalendarTable,
|
|
27
35
|
} from './workTime.ts';
|
|
28
36
|
|
|
29
|
-
export {
|
|
30
|
-
getDayEntry,
|
|
31
|
-
getDateKeyForDayIndex,
|
|
32
|
-
getDayIndexForDateKey,
|
|
33
|
-
getCumulativeMinutesAt,
|
|
34
|
-
getWorkingMinutesOnDayBetween,
|
|
35
|
-
} from './workTime.ts';
|
|
36
|
-
|
|
37
37
|
export interface CpmCalendar {
|
|
38
38
|
def: ScheduleWorkCalendarDef;
|
|
39
39
|
minutesPerDay: number;
|
|
@@ -139,11 +139,14 @@ export class DiagnosticCollector {
|
|
|
139
139
|
}
|
|
140
140
|
}
|
|
141
141
|
|
|
142
|
-
/*
|
|
142
|
+
/*
|
|
143
|
+
* Read an optional instant: null when absent (null, undefined or ''), NaN
|
|
144
|
+
* when unreadable, so validation can tell a missing date from a bad one.
|
|
145
|
+
*/
|
|
143
146
|
export function instant(
|
|
144
147
|
value: Date | string | null | undefined,
|
|
145
148
|
): number | null {
|
|
146
|
-
return value == null || value === '' ? null :
|
|
149
|
+
return value == null || value === '' ? null : toScheduleTimeMs(value);
|
|
147
150
|
}
|
|
148
151
|
|
|
149
152
|
/* Normalize a nonnegative duration without letting NaN contaminate dates. */
|
|
@@ -183,16 +186,6 @@ export function getRemainingMinutes(
|
|
|
183
186
|
);
|
|
184
187
|
}
|
|
185
188
|
|
|
186
|
-
/* Compare numeric identifiers numerically, preserving deterministic ordering for other ids. */
|
|
187
|
-
export function compareActivityIds(a: string, b: string): number {
|
|
188
|
-
if (/^\d+$/.test(a) && /^\d+$/.test(b)) {
|
|
189
|
-
const left = BigInt(a);
|
|
190
|
-
const right = BigInt(b);
|
|
191
|
-
if (left !== right) return left < right ? -1 : 1;
|
|
192
|
-
}
|
|
193
|
-
return a < b ? -1 : a > b ? 1 : 0;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
189
|
/* Normalize constraints once so every scheduling pass applies the same policy. */
|
|
197
190
|
export function getConstraints(activity: CpmActivityInput): CpmConstraints {
|
|
198
191
|
const result: CpmConstraints = {
|
|
@@ -362,11 +355,11 @@ export function validateCpmScheduleInput(
|
|
|
362
355
|
if (
|
|
363
356
|
a.levelingPriority != null &&
|
|
364
357
|
(!Number.isInteger(a.levelingPriority) ||
|
|
365
|
-
a.levelingPriority <
|
|
366
|
-
a.levelingPriority >
|
|
358
|
+
a.levelingPriority < SCHEDULE_LEVELING_PRIORITY_MIN ||
|
|
359
|
+
a.levelingPriority > SCHEDULE_LEVELING_PRIORITY_MAX)
|
|
367
360
|
)
|
|
368
361
|
invalid(
|
|
369
|
-
|
|
362
|
+
`Leveling priority must be an integer from ${SCHEDULE_LEVELING_PRIORITY_MIN} to ${SCHEDULE_LEVELING_PRIORITY_MAX}; ${SCHEDULE_LEVELING_PRIORITY_DEFAULT} is used.`,
|
|
370
363
|
a.id,
|
|
371
364
|
);
|
|
372
365
|
}
|
|
@@ -465,9 +458,13 @@ export function buildCpmCalendarSet(
|
|
|
465
458
|
return {
|
|
466
459
|
byId,
|
|
467
460
|
defaultCalendar: byId.get(input.defaultCalendarId)!,
|
|
468
|
-
rangeFromMs:
|
|
461
|
+
rangeFromMs:
|
|
462
|
+
floorMs - SCHEDULE_LEVELING_LEDGER_GUARD_DAYS * FILE_CONSTANTS.dayMs,
|
|
469
463
|
rangeToMs:
|
|
470
|
-
floorMs +
|
|
464
|
+
floorMs +
|
|
465
|
+
(Math.max(horizonDays, SCHEDULE_LEVELING_DEFAULT_HORIZON_DAYS) +
|
|
466
|
+
SCHEDULE_LEVELING_LEDGER_GUARD_DAYS) *
|
|
467
|
+
FILE_CONSTANTS.dayMs,
|
|
471
468
|
};
|
|
472
469
|
}
|
|
473
470
|
|
|
@@ -609,14 +606,14 @@ export function findStronglyConnectedComponents(
|
|
|
609
606
|
if (component.length > 1)
|
|
610
607
|
components.push(
|
|
611
608
|
component.sort((a, b) =>
|
|
612
|
-
|
|
609
|
+
compareScheduleIds(a.input.id, b.input.id),
|
|
613
610
|
),
|
|
614
611
|
);
|
|
615
612
|
}
|
|
616
613
|
}
|
|
617
614
|
}
|
|
618
615
|
return components.sort((a, b) =>
|
|
619
|
-
|
|
616
|
+
compareScheduleIds(a[0].input.id, b[0].input.id),
|
|
620
617
|
);
|
|
621
618
|
}
|
|
622
619
|
|
|
@@ -636,7 +633,8 @@ export function describeCycle(members: CpmActivityState[]): string {
|
|
|
636
633
|
if (!byId.has(rel.successorId)) continue;
|
|
637
634
|
if (rel.successorId === anchor) {
|
|
638
635
|
const path = frames.map((f) => f.id);
|
|
639
|
-
|
|
636
|
+
const hops = SCHEDULE_CYCLE_MESSAGE_MAX_HOPS;
|
|
637
|
+
return `Relationship loop: ${path.slice(0, hops).join(' → ')}${path.length > hops ? ` → … (${path.length - hops} more)` : ''} → ${anchor}`;
|
|
640
638
|
}
|
|
641
639
|
if (!seen.has(rel.successorId)) {
|
|
642
640
|
seen.add(rel.successorId);
|
|
@@ -651,7 +649,7 @@ export function buildWbsPathIndex(
|
|
|
651
649
|
paths: Record<string, string>,
|
|
652
650
|
): Array<[string, string]> {
|
|
653
651
|
return Object.entries(paths).sort((a, b) =>
|
|
654
|
-
a[1] < b[1] ? -1 : a[1] > b[1] ? 1 :
|
|
652
|
+
a[1] < b[1] ? -1 : a[1] > b[1] ? 1 : compareScheduleIds(a[0], b[0]),
|
|
655
653
|
);
|
|
656
654
|
}
|
|
657
655
|
/* Return the contiguous range belonging to one materialized WBS ancestry prefix. */
|
package/src/utils/cpm.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
SCHEDULE_CRITICAL_FLOAT_THRESHOLD_MINUTES,
|
|
3
|
+
SCHEDULE_RELATIONSHIP_TYPE_ENUMS,
|
|
4
|
+
} from '../constants/schedule.ts';
|
|
2
5
|
import type {
|
|
3
6
|
CpmActivityResult,
|
|
4
7
|
CpmScheduleInput,
|
|
@@ -128,7 +131,7 @@ function buildContext(
|
|
|
128
131
|
input.options?.criticalFloatThresholdMinutes,
|
|
129
132
|
)
|
|
130
133
|
? input.options!.criticalFloatThresholdMinutes!
|
|
131
|
-
:
|
|
134
|
+
: SCHEDULE_CRITICAL_FLOAT_THRESHOLD_MINUTES,
|
|
132
135
|
cursorActivityId: null,
|
|
133
136
|
};
|
|
134
137
|
}
|
|
@@ -333,7 +336,7 @@ function runForwardPass(context: CpmContext, order: CpmActivityState[]): void {
|
|
|
333
336
|
}
|
|
334
337
|
}
|
|
335
338
|
|
|
336
|
-
/* Apply finish/start bounds symmetrically and keep actual starts fixed after progress. */
|
|
339
|
+
/* Apply finish/start bounds symmetrically, cap every finish at the late-finish basis, and keep actual starts fixed after progress. */
|
|
337
340
|
function runBackwardPass(context: CpmContext, order: CpmActivityState[]): void {
|
|
338
341
|
for (let i = order.length - 1; i >= 0; i--) {
|
|
339
342
|
const state = order[i];
|
|
@@ -360,8 +363,11 @@ function runBackwardPass(context: CpmContext, order: CpmActivityState[]): void {
|
|
|
360
363
|
finishBound = Math.min(finishBound, bound);
|
|
361
364
|
else startBound = Math.min(startBound, bound);
|
|
362
365
|
}
|
|
366
|
+
// The project finish is an implicit successor of every activity, so an
|
|
367
|
+
// open (SS/SF-only or absent) or negative-lag finish bound cannot pass it.
|
|
363
368
|
finishBound = Math.min(
|
|
364
369
|
finishBound,
|
|
370
|
+
context.lateFinishBasisMs,
|
|
365
371
|
c.finish.onMs ?? Infinity,
|
|
366
372
|
c.finish.onOrBeforeMs ?? Infinity,
|
|
367
373
|
);
|
|
@@ -371,20 +377,11 @@ function runBackwardPass(context: CpmContext, order: CpmActivityState[]): void {
|
|
|
371
377
|
c.start.onMs ?? Infinity,
|
|
372
378
|
c.start.onOrBeforeMs ?? Infinity,
|
|
373
379
|
);
|
|
374
|
-
if (startBound === Infinity && finishBound === Infinity)
|
|
375
|
-
finishBound = context.lateFinishBasisMs;
|
|
376
380
|
const finish =
|
|
377
|
-
|
|
378
|
-
?
|
|
379
|
-
:
|
|
380
|
-
|
|
381
|
-
: snapFinish(cal, finishBound);
|
|
382
|
-
const fromFinish =
|
|
383
|
-
finish === Infinity
|
|
384
|
-
? Infinity
|
|
385
|
-
: remaining
|
|
386
|
-
? addMinutes(cal, finish, -remaining)
|
|
387
|
-
: finish;
|
|
381
|
+
state.input.type === 'START_MILESTONE'
|
|
382
|
+
? snapStart(cal, finishBound)
|
|
383
|
+
: snapFinish(cal, finishBound);
|
|
384
|
+
const fromFinish = remaining ? addMinutes(cal, finish, -remaining) : finish;
|
|
388
385
|
const fromStart =
|
|
389
386
|
startBound === Infinity
|
|
390
387
|
? Infinity
|
|
@@ -664,31 +661,43 @@ function computeSpanningActivities(context: CpmContext): void {
|
|
|
664
661
|
}
|
|
665
662
|
}
|
|
666
663
|
|
|
667
|
-
/*
|
|
664
|
+
/* Classify an activity's finish: no driving successor (open), only SS/SF successors (dangling), or linked. */
|
|
665
|
+
function getOpenFinish(
|
|
666
|
+
context: CpmContext,
|
|
667
|
+
state: CpmActivityState,
|
|
668
|
+
): 'OPEN' | 'DANGLING' | null {
|
|
669
|
+
let driving = false;
|
|
670
|
+
for (const rel of state.successors) {
|
|
671
|
+
if (!context.states.get(rel.successorId)!.isDriving) continue;
|
|
672
|
+
// FS/FF successors are driven by this activity's finish.
|
|
673
|
+
if (rel.type === 'FS' || rel.type === 'FF') return null;
|
|
674
|
+
driving = true;
|
|
675
|
+
}
|
|
676
|
+
// Zero-duration work starts and finishes together, so an SS/SF link ties both ends.
|
|
677
|
+
return !driving ? 'OPEN' : state.remaining > 0 ? 'DANGLING' : null;
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
/* Report open starts and open or dangling finishes of unstarted work, exempting one true opening and one true closing activity. */
|
|
668
681
|
function reportOpenEnds(context: CpmContext, order: CpmActivityState[]): void {
|
|
669
|
-
const starts =
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
682
|
+
const starts: CpmActivityState[] = [];
|
|
683
|
+
const finishes: Array<[CpmActivityState, 'OPEN' | 'DANGLING']> = [];
|
|
684
|
+
let first: CpmActivityState | null = null;
|
|
685
|
+
let last: CpmActivityState | null = null;
|
|
686
|
+
for (const state of order) {
|
|
687
|
+
if (state.status !== 'NOT_STARTED') continue;
|
|
688
|
+
if (
|
|
689
|
+
!state.constraints.hasStartConstraint &&
|
|
690
|
+
!state.predecessors.some(
|
|
674
691
|
(rel) => context.states.get(rel.predecessorId)!.isDriving,
|
|
675
|
-
)
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
const first = starts.reduce<CpmActivityState | null>(
|
|
685
|
-
(best, s) => (!best || s.es < best.es ? s : best),
|
|
686
|
-
null,
|
|
687
|
-
);
|
|
688
|
-
const last = finishes.reduce<CpmActivityState | null>(
|
|
689
|
-
(best, s) => (!best || s.ef > best.ef ? s : best),
|
|
690
|
-
null,
|
|
691
|
-
);
|
|
692
|
+
)
|
|
693
|
+
) {
|
|
694
|
+
starts.push(state);
|
|
695
|
+
if (!first || state.es < first.es) first = state;
|
|
696
|
+
}
|
|
697
|
+
const finish = getOpenFinish(context, state);
|
|
698
|
+
if (finish) finishes.push([state, finish]);
|
|
699
|
+
if (finish === 'OPEN' && (!last || state.ef > last.ef)) last = state;
|
|
700
|
+
}
|
|
692
701
|
for (const state of starts)
|
|
693
702
|
if (state !== first)
|
|
694
703
|
context.collector.add({
|
|
@@ -697,13 +706,16 @@ function reportOpenEnds(context: CpmContext, order: CpmActivityState[]): void {
|
|
|
697
706
|
activityId: state.input.id,
|
|
698
707
|
message: 'Activity has no predecessor.',
|
|
699
708
|
});
|
|
700
|
-
for (const state of finishes)
|
|
709
|
+
for (const [state, kind] of finishes)
|
|
701
710
|
if (state !== last)
|
|
702
711
|
context.collector.add({
|
|
703
712
|
code: 'OPEN_FINISH',
|
|
704
713
|
severity: 'WARN',
|
|
705
714
|
activityId: state.input.id,
|
|
706
|
-
message:
|
|
715
|
+
message:
|
|
716
|
+
kind === 'OPEN'
|
|
717
|
+
? 'Activity has no successor.'
|
|
718
|
+
: 'Activity finish has no successor; only its start is linked.',
|
|
707
719
|
});
|
|
708
720
|
}
|
|
709
721
|
|
|
@@ -3,18 +3,23 @@ import type {
|
|
|
3
3
|
CpmAssignmentInput,
|
|
4
4
|
CpmExternalUsageInput,
|
|
5
5
|
CpmOverallocation,
|
|
6
|
+
CpmRelationshipInput,
|
|
6
7
|
CpmResourceInput,
|
|
7
8
|
CpmResourceUsage,
|
|
8
9
|
} from '../types/schedule.d.ts';
|
|
9
10
|
import {
|
|
11
|
+
addLag,
|
|
10
12
|
addMinutes,
|
|
11
13
|
instant,
|
|
12
14
|
minutesBetween,
|
|
15
|
+
snapFinish,
|
|
13
16
|
snapStart,
|
|
14
17
|
type CpmActivityState,
|
|
15
18
|
type CpmCalendar,
|
|
19
|
+
type CpmContext,
|
|
16
20
|
type DiagnosticCollector,
|
|
17
21
|
} from './cpm.helpers.ts';
|
|
22
|
+
import { isScheduleDateKey } from './localTime.ts';
|
|
18
23
|
import {
|
|
19
24
|
buildWorkCalendarTable,
|
|
20
25
|
getDayIndexAt,
|
|
@@ -57,16 +62,18 @@ export interface LevelingSearchOptions {
|
|
|
57
62
|
levelWithinFloat: boolean;
|
|
58
63
|
}
|
|
59
64
|
|
|
60
|
-
const FILE_CONSTANTS = {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
)
|
|
69
|
-
|
|
65
|
+
const FILE_CONSTANTS = {
|
|
66
|
+
epsilon: 1e-6,
|
|
67
|
+
dayMs: 86_400_000,
|
|
68
|
+
// People and crews (and equipment) have a daily capacity leveling respects
|
|
69
|
+
levelableKinds: new Set<CpmResourceInput['kind']>([
|
|
70
|
+
'PERSON',
|
|
71
|
+
'LABOR',
|
|
72
|
+
'EQUIPMENT',
|
|
73
|
+
]),
|
|
74
|
+
// Rooms and stock are tracked for usage but never constrain or take time off
|
|
75
|
+
unboundedKinds: new Set<CpmResourceInput['kind']>(['SPACE', 'MATERIAL']),
|
|
76
|
+
};
|
|
70
77
|
|
|
71
78
|
/* Initialize per-day capacity, applying the latest availability window and touched time-off days. */
|
|
72
79
|
export function resolveDailyAvailability(
|
|
@@ -86,9 +93,9 @@ export function resolveDailyAvailability(
|
|
|
86
93
|
const windows = (resource.availability || [])
|
|
87
94
|
.filter((row) => {
|
|
88
95
|
const valid =
|
|
89
|
-
|
|
96
|
+
isScheduleDateKey(row.startsOn) &&
|
|
90
97
|
(!row.endsOn ||
|
|
91
|
-
(
|
|
98
|
+
(isScheduleDateKey(row.endsOn) && row.endsOn >= row.startsOn)) &&
|
|
92
99
|
Number.isFinite(row.maxUnitsPerDay) &&
|
|
93
100
|
row.maxUnitsPerDay >= 0;
|
|
94
101
|
if (!valid)
|
|
@@ -120,8 +127,7 @@ export function resolveDailyAvailability(
|
|
|
120
127
|
? 0
|
|
121
128
|
: available[i] *
|
|
122
129
|
Math.min(1, day.workingMinutes / calendar.minutesPerDay);
|
|
123
|
-
if (resource.kind
|
|
124
|
-
available[i] = NaN;
|
|
130
|
+
if (FILE_CONSTANTS.unboundedKinds.has(resource.kind)) available[i] = NaN;
|
|
125
131
|
}
|
|
126
132
|
for (const row of resource.timeOff || []) {
|
|
127
133
|
const fromMs = instant(row.startAt);
|
|
@@ -146,7 +152,7 @@ export function resolveDailyAvailability(
|
|
|
146
152
|
table.days.length - 1,
|
|
147
153
|
getDayIndexAt(table, new Date(toMs - 1)),
|
|
148
154
|
);
|
|
149
|
-
if (to >= from &&
|
|
155
|
+
if (to >= from && !FILE_CONSTANTS.unboundedKinds.has(resource.kind))
|
|
150
156
|
available.fill(0, from, to + 1);
|
|
151
157
|
}
|
|
152
158
|
return available;
|
|
@@ -197,7 +203,7 @@ export function buildResourceLedger(
|
|
|
197
203
|
canLevel: resource.canLevel !== false,
|
|
198
204
|
levelable:
|
|
199
205
|
resource.canLevel !== false &&
|
|
200
|
-
(resource.kind
|
|
206
|
+
FILE_CONSTANTS.levelableKinds.has(resource.kind) &&
|
|
201
207
|
resource.maxUnitsPerDay !== null,
|
|
202
208
|
maxAvailableDay,
|
|
203
209
|
};
|
|
@@ -475,6 +481,73 @@ export function findFirstFeasibleStart(
|
|
|
475
481
|
}
|
|
476
482
|
}
|
|
477
483
|
|
|
484
|
+
/* Translate one predecessor link, at the given predecessor dates, into the earliest start it allows the successor. */
|
|
485
|
+
export function getLinkStartBound(
|
|
486
|
+
context: CpmContext,
|
|
487
|
+
rel: CpmRelationshipInput,
|
|
488
|
+
pred: CpmActivityState,
|
|
489
|
+
succ: CpmActivityState,
|
|
490
|
+
predStart: number,
|
|
491
|
+
predFinish: number,
|
|
492
|
+
): number {
|
|
493
|
+
let candidate = addLag(
|
|
494
|
+
context,
|
|
495
|
+
rel.type === 'SS' || rel.type === 'SF' ? predStart : predFinish,
|
|
496
|
+
rel.lagMinutes || 0,
|
|
497
|
+
pred,
|
|
498
|
+
succ,
|
|
499
|
+
);
|
|
500
|
+
if ((rel.type === 'FF' || rel.type === 'SF') && succ.remaining)
|
|
501
|
+
candidate = addMinutes(succ.calendar, candidate, -succ.remaining);
|
|
502
|
+
return succ.input.type === 'FINISH_MILESTONE'
|
|
503
|
+
? snapFinish(succ.calendar, candidate)
|
|
504
|
+
: snapStart(succ.calendar, candidate);
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
/* Warn when a placed activity now runs past a successor that leveling cannot move (in progress or MANDATORY_*). */
|
|
508
|
+
export function reportPinnedSuccessorConflicts(
|
|
509
|
+
context: CpmContext,
|
|
510
|
+
state: CpmActivityState,
|
|
511
|
+
pinned: Set<string>,
|
|
512
|
+
): void {
|
|
513
|
+
for (const rel of state.successors) {
|
|
514
|
+
if (!pinned.has(rel.successorId)) continue;
|
|
515
|
+
const succ = context.states.get(rel.successorId)!;
|
|
516
|
+
const inProgress = succ.status === 'IN_PROGRESS';
|
|
517
|
+
// Override logic lets started work ignore its predecessors.
|
|
518
|
+
if (inProgress && context.progressLogic !== 'RETAINED') continue;
|
|
519
|
+
const fixed = inProgress ? succ.resumeStart : succ.start;
|
|
520
|
+
const leveled = getLinkStartBound(
|
|
521
|
+
context,
|
|
522
|
+
rel,
|
|
523
|
+
state,
|
|
524
|
+
succ,
|
|
525
|
+
state.start,
|
|
526
|
+
state.finish,
|
|
527
|
+
);
|
|
528
|
+
// Only the part leveling added: CPM already reports a logic override.
|
|
529
|
+
const unleveled = getLinkStartBound(
|
|
530
|
+
context,
|
|
531
|
+
rel,
|
|
532
|
+
state,
|
|
533
|
+
succ,
|
|
534
|
+
state.es,
|
|
535
|
+
state.ef,
|
|
536
|
+
);
|
|
537
|
+
if (minutesBetween(succ.calendar, Math.max(fixed, unleveled), leveled) <= 0)
|
|
538
|
+
continue;
|
|
539
|
+
context.collector.add({
|
|
540
|
+
code: 'LEVELING_PAST_PINNED_SUCCESSOR',
|
|
541
|
+
severity: 'WARN',
|
|
542
|
+
activityId: state.input.id,
|
|
543
|
+
relatedActivityId: succ.input.id,
|
|
544
|
+
minutes: minutesBetween(succ.calendar, fixed, leveled),
|
|
545
|
+
message:
|
|
546
|
+
'Resource leveling moved this activity past a successor fixed by progress or a mandatory date.',
|
|
547
|
+
});
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
|
|
478
551
|
/* Return populated histogram rows in resource and local-date order. */
|
|
479
552
|
export function collectResourceUsage(
|
|
480
553
|
ledgers: ResourceLedger[],
|
package/src/utils/cpmLeveling.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
|
+
SCHEDULE_LEVELING_DEFAULT_HORIZON_DAYS,
|
|
2
3
|
SCHEDULE_LEVELING_DEFAULT_PRIORITY_RULE,
|
|
4
|
+
SCHEDULE_LEVELING_LEDGER_GUARD_DAYS,
|
|
5
|
+
SCHEDULE_LEVELING_MAX_HORIZON_DAYS,
|
|
6
|
+
SCHEDULE_LEVELING_MIN_HORIZON_DAYS,
|
|
7
|
+
SCHEDULE_LEVELING_PRIORITY_DEFAULT,
|
|
8
|
+
SCHEDULE_LEVELING_PRIORITY_MAX,
|
|
9
|
+
SCHEDULE_LEVELING_PRIORITY_MIN,
|
|
3
10
|
SCHEDULE_LEVELING_PRIORITY_RULE_ENUMS,
|
|
4
11
|
} from '../constants/schedule.ts';
|
|
5
12
|
import type {
|
|
@@ -7,16 +14,13 @@ import type {
|
|
|
7
14
|
ScheduleLevelingPriorityRuleEnum,
|
|
8
15
|
} from '../types/schedule.d.ts';
|
|
9
16
|
import {
|
|
10
|
-
addLag,
|
|
11
17
|
addMinutes,
|
|
12
|
-
compareActivityIds,
|
|
13
18
|
getActivityCalendar,
|
|
14
19
|
minutesBetween,
|
|
15
|
-
snapFinish,
|
|
16
|
-
snapStart,
|
|
17
20
|
type CpmActivityState,
|
|
18
21
|
type CpmContext,
|
|
19
22
|
} from './cpm.helpers.ts';
|
|
23
|
+
import { compareScheduleIds } from './ids.ts';
|
|
20
24
|
import {
|
|
21
25
|
buildDemandProfile,
|
|
22
26
|
buildResourceLedger,
|
|
@@ -24,6 +28,8 @@ import {
|
|
|
24
28
|
collectResourceUsage,
|
|
25
29
|
commitDemand,
|
|
26
30
|
findFirstFeasibleStart,
|
|
31
|
+
getLinkStartBound,
|
|
32
|
+
reportPinnedSuccessorConflicts,
|
|
27
33
|
spreadExternalUsage,
|
|
28
34
|
type LevelingAssignment,
|
|
29
35
|
type ResourceLedger,
|
|
@@ -49,8 +55,14 @@ export function resolveLevelingOptions(
|
|
|
49
55
|
? Math.min(100, Math.max(0, input!.maxOverallocationPercent!)) / 100
|
|
50
56
|
: 0,
|
|
51
57
|
horizonDays: Number.isFinite(input?.horizonDays)
|
|
52
|
-
? Math.min(
|
|
53
|
-
|
|
58
|
+
? Math.min(
|
|
59
|
+
SCHEDULE_LEVELING_MAX_HORIZON_DAYS,
|
|
60
|
+
Math.max(
|
|
61
|
+
SCHEDULE_LEVELING_MIN_HORIZON_DAYS,
|
|
62
|
+
Math.round(input!.horizonDays!),
|
|
63
|
+
),
|
|
64
|
+
)
|
|
65
|
+
: SCHEDULE_LEVELING_DEFAULT_HORIZON_DAYS,
|
|
54
66
|
};
|
|
55
67
|
}
|
|
56
68
|
|
|
@@ -74,10 +86,10 @@ export function compareLevelingPriority(
|
|
|
74
86
|
return state.es;
|
|
75
87
|
case 'PRIORITY':
|
|
76
88
|
return Number.isInteger(state.input.levelingPriority) &&
|
|
77
|
-
state.input.levelingPriority! >=
|
|
78
|
-
state.input.levelingPriority! <=
|
|
89
|
+
state.input.levelingPriority! >= SCHEDULE_LEVELING_PRIORITY_MIN &&
|
|
90
|
+
state.input.levelingPriority! <= SCHEDULE_LEVELING_PRIORITY_MAX
|
|
79
91
|
? state.input.levelingPriority!
|
|
80
|
-
:
|
|
92
|
+
: SCHEDULE_LEVELING_PRIORITY_DEFAULT;
|
|
81
93
|
case 'ORDINAL':
|
|
82
94
|
return Number.isFinite(state.input.ordinal) ? state.input.ordinal! : 0;
|
|
83
95
|
case 'DURATION':
|
|
@@ -90,7 +102,7 @@ export function compareLevelingPriority(
|
|
|
90
102
|
}
|
|
91
103
|
return (
|
|
92
104
|
value(a, 'ORDINAL') - value(b, 'ORDINAL') ||
|
|
93
|
-
|
|
105
|
+
compareScheduleIds(a.input.id, b.input.id)
|
|
94
106
|
);
|
|
95
107
|
}
|
|
96
108
|
|
|
@@ -159,7 +171,8 @@ export function runResourceLeveling(
|
|
|
159
171
|
getActivityCalendar(context.calendarSet, resource.calendarId),
|
|
160
172
|
{
|
|
161
173
|
fromMs: Math.min(context.floorMs, context.dataDateMs),
|
|
162
|
-
toMs:
|
|
174
|
+
toMs:
|
|
175
|
+
horizonEndMs + SCHEDULE_LEVELING_LEDGER_GUARD_DAYS * 86_400_000,
|
|
163
176
|
},
|
|
164
177
|
options.tolerance,
|
|
165
178
|
context.collector,
|
|
@@ -258,22 +271,10 @@ export function runResourceLeveling(
|
|
|
258
271
|
for (const rel of state.predecessors) {
|
|
259
272
|
const pred = context.states.get(rel.predecessorId)!;
|
|
260
273
|
if (!pred.isDriving) continue;
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
rel.lagMinutes || 0,
|
|
265
|
-
pred,
|
|
266
|
-
state,
|
|
274
|
+
bound = Math.max(
|
|
275
|
+
bound,
|
|
276
|
+
getLinkStartBound(context, rel, pred, state, pred.start, pred.finish),
|
|
267
277
|
);
|
|
268
|
-
if (rel.type === 'FF' || rel.type === 'SF')
|
|
269
|
-
candidate = state.remaining
|
|
270
|
-
? addMinutes(state.calendar, candidate, -state.remaining)
|
|
271
|
-
: candidate;
|
|
272
|
-
candidate =
|
|
273
|
-
state.input.type === 'FINISH_MILESTONE'
|
|
274
|
-
? snapFinish(state.calendar, candidate)
|
|
275
|
-
: snapStart(state.calendar, candidate);
|
|
276
|
-
bound = Math.max(bound, candidate);
|
|
277
278
|
}
|
|
278
279
|
const rows = assignments.get(state.input.id) || [];
|
|
279
280
|
let impossible = false;
|
|
@@ -351,6 +352,7 @@ export function runResourceLeveling(
|
|
|
351
352
|
minutes: state.levelingDelay,
|
|
352
353
|
message: 'Activity delayed to fit resource availability.',
|
|
353
354
|
});
|
|
355
|
+
reportPinnedSuccessorConflicts(context, state, pinned);
|
|
354
356
|
}
|
|
355
357
|
for (const rel of state.successors) {
|
|
356
358
|
const count = indegree.get(rel.successorId);
|