Control Systems & Delays

Inventory–Workforce Oscillator

Level: Intermediate

workforceseasonalitytime-delaycontrol

What it shows

A hire delay swings seasonal backlog amplitude from 60 down to 7. Workforce turns 14 times in both: amplified seasonality, not an unforced oscillator.

How to use

Open the model in the playground, change one parameter in the YAML, and run it again. The annotated simulation.py below is the model. Each config is a saved scenario: Slow hiring, Fast hiring.

Open in Playground

Key parameters

  • Stocks: workforce, backlog
  • Flows: hiring, layoffs, production, demand
  • Feedback loops: staffing to this period's demand (balancing, lagged)
  • Probes: demand, workforce, backlog

Delays

Learn about delays in systems, how they create oscillations, and their impact on system behavior and decision-making.

Take the Quiz
simulation.py

A season amplified by slow hiring

The cycle is the season, not an unforced oscillator. Demand is a fixed sine wave and headcount chases it through one knob, the hire delay; the backlog is the orders that delay has not yet covered.

At a delay of 12 the backlog amplitude is 60; at 1.5 the same season reaches only 7, and the workforce turns 14 times in both. Zero the seasonal swing and both stocks sit still.


from tys import probe, progress


def simulate(cfg: dict):
    """A longer hire delay amplifies a fixed season. It does not create an unforced oscillator."""

    import math
    import simpy

    env = simpy.Environment()

    demand_base = float(cfg["demand_base"])
    demand_amp = float(cfg["demand_amp"])
    period = float(cfg["demand_period"])
    productivity = float(cfg["productivity"])
    hire_time = max(float(cfg["hire_time"]), 1.0)  # below 1 this step would overshoot
    backlog = float(cfg.get("initial_backlog", 0.0))
    sim_time = int(cfg["sim_time"])
    workforce = demand_base / productivity  # staffed for the season's average

Record after whole seasons, long enough that the hire lag has forgotten the start. The plotted window begins on a season boundary.

    settle_seasons = max(14, math.ceil(8.0 * hire_time / period))
    warmup = int(settle_seasons * period)

    done = env.event()
    backlog_samples: list[float] = []
    workforce_samples: list[float] = []
    told_season = False

    def demand_at(t: float) -> float:
        return demand_base + demand_amp * math.sin(2.0 * math.pi * t / period)  # pure sine, no seed

Hire toward this period's demand only. Chasing the backlog as well can ring on its own; this rule cannot. The delay just decides how much of the season the backlog has to absorb.

    def dynamics():
        nonlocal workforce, backlog, told_season
        for t in range(warmup + sim_time):
            demand = demand_at(t)
            workforce = workforce + (demand / productivity - workforce) / hire_time
            if workforce < 0.0:
                workforce = 0.0

Finish only orders already waiting or arriving now. Spare capacity cannot bank work against a future season.

            capacity = productivity * workforce
            available = max(backlog, 0.0) + max(demand, 0.0)
            production = min(capacity, available)
            backlog = max(0.0, backlog + demand - production)

            if t < warmup:
                yield env.timeout(1)
                continue

            step = t - warmup
            probe("demand", step, demand)
            probe("workforce", step, workforce)
            probe("backlog", step, backlog)
            backlog_samples.append(backlog)
            workforce_samples.append(workforce)

            pct = int(100 * (step + 1) / sim_time)
            if not told_season and demand_amp != 0.0 and step + 1 >= int(period):
                progress(pct, "One season in. Hiring is still catching the same wave.")
                told_season = True
            elif step + 1 < sim_time:
                progress(pct)
            yield env.timeout(1)

        backlog_amplitude = (max(backlog_samples) - min(backlog_samples)) / 2.0
        workforce_turns = _turns(workforce_samples)
        shown = round(backlog_amplitude)
        if demand_amp == 0.0:
            closing = "No season, so the workforce never turns and the backlog sits still. Not an oscillator."
        else:
            closing = (
                f"Backlog amplitude {shown}. "
                f"Workforce turned {workforce_turns} times with the season, not on its own."
            )
        progress(100, closing)
        done.succeed({
            "backlog_amplitude": backlog_amplitude,
            "workforce_turns": workforce_turns,
        })

    env.process(dynamics())
    env.run(until=done)
    return done.value


def _turns(values: list[float]) -> int:
    """Count direction changes. One season contributes a peak and a trough."""
    count = 0
    previous = 0
    for index in range(1, len(values)):
        delta = values[index] - values[index - 1]
        if delta == 0.0:
            continue
        sign = 1 if delta > 0.0 else -1
        if previous != 0 and sign != previous:
            count += 1
        previous = sign
    return count


def requirements():
    return {"external": ["simpy==4.1.1"]}
Slow hiring.yaml
# slow.yaml — the default. A 12-period hire delay lets this season swing the backlog with amplitude 60.
# Same demand, productivity, and starting backlog as fast.yaml. Only hire_time changes.
demand_base: 40
demand_amp: 14.234 # sine coefficient tuned so the two hire delays land on amplitudes 7 and 60
demand_period: 30
productivity: 1.0
hire_time: 12
initial_backlog: 80
sim_time: 210
Charts (Slow hiring)

demand

The season, identical in both presets: a sine wave around 40. Set its swing to zero and the other two charts go flat.

Samples210 @ 0.00–209.00
Valuesmin 25.84, mean 40.00, median 40.00, max 54.16, σ 10.06

workforce

Headcount chasing that season through the hire delay. It turns 14 times in both presets. Fast hiring follows the wave; slow hiring barely moves.

Samples210 @ 0.00–209.00
Valuesmin 34.55, mean 40.00, median 40.00, max 45.45, σ 3.87

backlog

Orders minus output, accumulated. On this shared axis the slow preset swings with amplitude 60 and the fast preset with amplitude 7.

Samples210 @ 0.00–209.00
Valuesmin 20.00, mean 80.00, median 80.00, max 140.00, σ 42.55
Final Results (Slow hiring)
MetricValue
backlog_amplitude60.00
workforce_turns14.00
Fast hiring.yaml
# fast.yaml — the contrast. The same season with a 1.5-period hire delay holds the backlog amplitude to 7.
# Identical to slow.yaml except hire_time.
demand_base: 40
demand_amp: 14.234 # sine coefficient tuned so the two hire delays land on amplitudes 7 and 60
demand_period: 30
productivity: 1.0
hire_time: 1.5
initial_backlog: 80
sim_time: 210
Charts (Fast hiring)

demand

The season, identical in both presets: a sine wave around 40. Set its swing to zero and the other two charts go flat.

Samples210 @ 0.00–209.00
Valuesmin 25.84, mean 40.00, median 40.00, max 54.16, σ 10.06

workforce

Headcount chasing that season through the hire delay. It turns 14 times in both presets. Fast hiring follows the wave; slow hiring barely moves.

Samples210 @ 0.00–209.00
Valuesmin 25.99, mean 40.00, median 40.00, max 54.01, σ 9.90

backlog

Orders minus output, accumulated. On this shared axis the slow preset swings with amplitude 60 and the fast preset with amplitude 7.

Samples210 @ 0.00–209.00
Valuesmin 73.00, mean 80.00, median 80.00, max 87.00, σ 4.95
Final Results (Fast hiring)
MetricValue
backlog_amplitude7.00
workforce_turns14.00
FAQ
What is the one knob, and what does it change?
hire_time, the number of periods it takes to close the gap between today's headcount and the staff this period's demand would need. Everything else, including the season, is identical. At 12 the backlog amplitude is 60. At 1.5 it is 7. Amplitude here is half the peak-to-trough range over the recorded window, which is seven seasons long.
Why does a longer hire delay make a bigger backlog swing?
Output can only come from people already hired. While headcount is still catching the season, orders arrive faster than they are finished, and that gap adds to the backlog. It unwinds on the way back down. A short delay means the workforce is almost in step with demand, so the gap stays small. A long delay means the workforce barely moves and the backlog absorbs nearly the whole season. There is no cliff: the swing grows smoothly as the delay gets longer, up toward the amplitude of a workforce that does not move at all.
Why is this not an unforced oscillator?
An unforced oscillator keeps ringing after the push is gone. The thermostat example does that: a constant outdoor temperature, a delayed sensor, and the room cycles on its own. Here the push is the season. Set demand_amp to 0 and, at either hire delay, the workforce never turns and the backlog sits at its starting level. The hiring rule is a stable lag onto this period's demand. It does not chase the backlog. A rule that also hired extra people to eat the pile down can ring on its own; that loop is left out on purpose, so the chart cannot be mistaken for one.
Why does the workforce turn 14 times in both presets?
The recorded window is seven seasons (210 periods, season length 30), and each season has one peak and one trough. Both presets are locked to that forcing, so both turn 14 times. The slow preset's workforce is a flattened, lagged copy of the same wave, not a different rhythm. A self-sustained oscillator would not keep the same count when the delay changed, and it would still turn after the season was removed.
What is the real-world analog, and what misconception does this debunk?
A seasonal service shop — a holiday carrier, a tax office, a resort — that hires and lays off too slowly. Unmet work swells and shrinks with the calendar even though nothing inside the shop is unstable. People Express is the famous staffing-lag collapse, but that story also mixed in growth and underinvestment; this run keeps only the seasonal piece so the delay's effect is visible on its own. The misconception is that a wiggling chart means the system must be an oscillator. Sometimes the world is already wiggling, and the delay only decides how loudly the backlog repeats it.