Skip to main content

Call Signature

function schedule<R, S, T, TRules>(config): Schedule<BuiltInCpsatRuleRegistry>;
Create a schedule definition. Returns an immutable Schedule that can be composed via .with() and solved via .solve().

Type Parameters

R

R extends readonly string[]

S

S extends readonly string[] = readonly []

T

T extends Record<string, SemanticTimeEntry> = Record<string, SemanticTimeEntry>

TRules

TRules extends readonly unknown[] = readonly ScheduleRuleEntry<BuiltInCpsatRuleRegistry>[]

Parameters

config

BuiltInScheduleConfigInput<R, S, T, TRules>

Returns

Schedule<BuiltInCpsatRuleRegistry>

Remarks

schedule() always uses the built-in rule registry as its default. Passing ruleRegistry extends that default with custom rules.

Example

const venue = schedule({
  roleIds: ["waiter", "runner", "manager"],
  skillIds: ["senior"],
  times: {
    lunch: time({ startTime: t(12), endTime: t(15) }),
    dinner: time(
      { startTime: t(17), endTime: t(21) },
      { startTime: t(18), endTime: t(22), dayOfWeek: weekend },
    ),
  },
  coverage: [
    cover("lunch", "waiter", 2),
    cover("dinner", "waiter", 4, { dayOfWeek: weekdays }),
    cover("dinner", "waiter", 5, { dayOfWeek: weekend }),
    cover("dinner", "manager", 1),
  ],
  shiftPatterns: [
    shift("lunch_shift", t(11, 30), t(15)),
    shift("evening", t(17), t(22)),
  ],
  rules: [
    maxHoursPerDay(10),
    maxHoursPerWeek(48),
    minRestBetweenShifts(11),
  ],
});

Call Signature

function schedule<R, S, T, TCustomRuleRegistry, TRules>(config): Schedule<BuiltInCpsatRuleRegistry & TCustomRuleRegistry>;
Create a schedule definition. Returns an immutable Schedule that can be composed via .with() and solved via .solve().

Type Parameters

R

R extends readonly string[]

S

S extends readonly string[] = readonly []

T

T extends Record<string, SemanticTimeEntry> = Record<string, SemanticTimeEntry>

TCustomRuleRegistry

TCustomRuleRegistry extends CpsatRuleRegistry = CpsatRuleRegistry

TRules

TRules extends readonly unknown[] = readonly ScheduleRuleEntry<BuiltInCpsatRuleRegistry & TCustomRuleRegistry>[]

Parameters

config

CustomScheduleConfigInput<R, S, T, TCustomRuleRegistry, TRules>

Returns

Schedule<BuiltInCpsatRuleRegistry & TCustomRuleRegistry>

Remarks

schedule() always uses the built-in rule registry as its default. Passing ruleRegistry extends that default with custom rules.

Example

const venue = schedule({
  roleIds: ["waiter", "runner", "manager"],
  skillIds: ["senior"],
  times: {
    lunch: time({ startTime: t(12), endTime: t(15) }),
    dinner: time(
      { startTime: t(17), endTime: t(21) },
      { startTime: t(18), endTime: t(22), dayOfWeek: weekend },
    ),
  },
  coverage: [
    cover("lunch", "waiter", 2),
    cover("dinner", "waiter", 4, { dayOfWeek: weekdays }),
    cover("dinner", "waiter", 5, { dayOfWeek: weekend }),
    cover("dinner", "manager", 1),
  ],
  shiftPatterns: [
    shift("lunch_shift", t(11, 30), t(15)),
    shift("evening", t(17), t(22)),
  ],
  rules: [
    maxHoursPerDay(10),
    maxHoursPerWeek(48),
    minRestBetweenShifts(11),
  ],
});