# Inspection queue capacity

A runnable discrete-event study of one inspection cell. It compares staffing, admitted work in process (WIP), FIFO and estimated-service dispatch using synthetic arrivals and service times. The model is implemented and the numerical experiments are executed. No factory time study or staffing trial is claimed.

## Run

Use Python 3.11 or later. From this extracted project folder:

```sh
python -m venv .venv
# Linux/macOS: source .venv/bin/activate
# Windows: .venv\Scripts\activate
python -m pip install -r requirements.txt
python run.py
python -m unittest -v
```

Open `report.html` directly. It needs no server or internet after dependency installation. `run.py` executes the tests, runs the experiments, and regenerates CSV results, figures, report and verification records. The full study uses 800 short shift simulations plus an 80,000-job analytical benchmark; allow a few minutes on an ordinary laptop.

## What to change

`inputs.json` holds the reference workload, shift duration, breaks, WIP limits and seed set. `simulation.py` contains the model and workload generator. `run.py` defines the four input conditions: reference, 20% more demand, 20% longer mean service and 30% rework probability.

The arrival generator uses independent piecewise-Poisson arrivals. Service duration is lognormal within two job classes. A job may return after its first two inspections, then leaves after the third. Exit is a completed inspection, not a claimed quality acceptance. Every job's visits are sampled before dispatch, so policy comparisons use the same realized work. SPT sorts by the class estimate, never the sampled service time.

The WIP limit includes jobs running, waiting and waiting to return from rework. New arrivals that cannot enter are counted as turned away; the model does not silently drop them or assume they will never need inspection. Extend the upstream boundary if rejected work must queue elsewhere.

## Experiment boundaries

The operating study starts empty, removes no warm-up, and stops at 8 hours without draining. Unfinished work remains in the outputs. It is a terminating-shift experiment, not a steady-state model. The M/M/1 analytical test has a separate 5,000-job warm-up and checks mean waiting time against 1.5 seconds.

Forty independent seeds run each policy under each condition. Policies share identical job lists within a condition. The confidence intervals are Student-t intervals for replication means, including paired differences against the reference policy. They measure Monte Carlo precision under the stated synthetic assumptions, not uncertainty about real factory inputs. Waiting statistics are means of per-shift empirical p95 values, not pooled customer-level quantiles. The full report explains shift-end censoring and the class-level fairness outputs.

## Files

- `results/replications.csv`: every scenario-shift result, including completed, rejected, unfinished, waiting, utilization and balance checks.
- `results/scenario-means-ci.csv`: means and nominal 95% confidence intervals across shifts.
- `results/rejection-risk-ci.csv`: exact binomial bounds on the probability of any turn-away in a shift; zero observed refusals do not establish zero risk.
- `results/paired-differences-ci.csv`: policy minus baseline using matched seeds.
- `results/class-replications.csv`: quick/detailed counts and observed waits, including unfinished work.
- `results/reference-workload.json`: the first reference seed's jobs and pre-sampled service visits.
- `results/trace-*-events.csv` and `trace-*-jobs.csv`: full event and final job states for that seed under all five policies. The `starts` column lists all service-start times for reworked jobs.
- `results/study-summary.json`: horizon, seed set, conditions and maximum numerical balance discrepancies.
- `time-study-plan.md` and `time-study-template.csv`: a collection plan and blank observation schema for replacing synthetic assumptions.
- `verification.json` and `test-log.txt`: executed tests, counts and source hashes.

The standalone files are sufficient to inspect and rerun the study. Use actual timing data and a supervised operational trial before changing staffing or floor space.

## Completed virtual operating trial

The same `python run.py` command now also runs 800 additional shifts: five-minute arrival batching, a two-hour deferred staff absence, 40% slower service, their combination, and a reference condition. Two or three inspectors use FIFO or estimated-service dispatch with 24 admitted WIP places. Forty matched seeds run each condition/policy pair. The original 800-run study is retained separately.

The new experiment stops arrivals at eight hours and allows at most two hours to clear admitted work. It records regular-shift completion, backlog, refusals, overtime and any work still unfinished. A declared service screen uses <=1% refusal, <=30 minutes clearance and <=15 minutes detailed-job p95 waiting. Failed shifts remain counted, with exact binomial risk intervals; no policy is represented as universally sufficient.

Open `virtual-validation.html`. Raw outputs, confidence intervals and a stress-case job trace are under `results/virtual-*`. `completion.json` records nine acceptance checks and source hashes. Four additional regression tests bring the total to 20. This is the completed synthetic operating trial, not a measured factory trial.

The selected policy is FIFO with three inspectors for the reference or batched case, four for a known absence or slower-service case, and five for combined stress. A separate 500-run holdout uses seeds 16100-16199: all 100 shifts per condition meet the service screen. The two-sided exact 95% upper risk bound is 3.62% per condition, below the declared 10% criterion. This is a reserve-capacity policy, not a claim of minimum cost or zero real-world failure risk. See `selected-operating-envelope.json` and the two `virtual-selected-*.csv` files. The package now executes 800 original study runs, 800 operating-trial runs and 500 holdout runs.
