Run, Analyze, and Redesign

Treat each simulation as a controlled experiment. Validate first, use a fixed seed when comparing alternatives, and change only the factors in your hypothesis.

Establish a baseline

print(plant.validate())
baseline = plant.run(duration=3_600, seed=42)
baseline.report()

Inspect the evidence behind the headline values:

print(baseline.machine_metrics)
print(baseline.buffer_metrics)
print(baseline.transporter_metrics)
print(baseline.from_to_matrix)

Useful plots include:

baseline.plot_wip(path="outputs/plots/baseline_wip.png")
baseline.plot_queue_lengths(path="outputs/plots/baseline_queues.png")
baseline.plot_utilization(path="outputs/plots/baseline_utilization.png")
baseline.plot_travel(path="outputs/plots/baseline_travel.png")
baseline.spaghetti_diagram(path="outputs/plots/baseline_flow.png")

Legends are centered above the axes in a single row so they do not cover the plotted data. Lead time includes waiting, movement, processing, blocking, and resource delays. Average WIP and occupancy are time-weighted rather than simple observation averages.

Create an independent redesign

redesign = plant.copy()
redesign.name = "Compact Assembly Line"

redesign.move(cutting, (21, 25))
redesign.move(wip, (39, 23))
redesign.move(assembly, (55, 25))
redesign.move(shipping, (73, 25))

print(redesign.validate())
redesign.visualize(product="Bracket")
redesign_result = redesign.run(duration=3_600, seed=42)

Move all related components before validation. The baseline remains unchanged because copy() creates independent components, Products, and connections.

Compare like with like

from manufacturing_sim_s import compare

comparison = compare(baseline, redesign_result)
print(comparison.dataframe)
comparison.plot(
    metric="total_material_travel_distance",
    path="outputs/plots/layout_comparison.png",
)
comparison.export_csv("outputs/csv/layout_comparison.csv")

Keep the duration, seed, arrivals, processing times, and handling assignments constant when layout is the only experimental factor. Explain both the KPI change and its engineering cause; shorter geometric distance may still perform poorly if a shared transporter is heavily utilized.

Account for randomness

For stochastic arrivals or processing times, use replications rather than one lucky seed:

replications = redesign.run_replications(
    replications=10,
    duration=3_600,
    seed=100,
)
print(replications.summary)
replications.plot(metric="units_produced")
replications.export_csv("outputs/csv/redesign_replications.csv")

The summary reports the mean, sample standard deviation, and 95% confidence interval for standard KPIs.

Save and restore the layout

redesign.save_config("outputs/configs/compact_layout.json")
restored = Plant.load_config("outputs/configs/compact_layout.json")
print(restored.validate())

JSON preserves component dimensions, distributions, Products, routes, resource assignments, and movement connections. Generated plots, animations, CSVs, and configurations belong under outputs/.

At this point you can replace the tutorial's measurements, process sequence, timing, and material-handling resources with data from your own facility. Re-run the finished-model checklist after each structural change.