Workshop State Map

A fictional packing station can scan a parcel and label it in either order. Both paths lead to the same ready state. Inspecting an untouched parcel leaves the station in the same state. The first stage uses a FIFO queue to visit each state once and assigns the minimum number of operations from the initial state. The second stage prints the state map.

Run from the Flow package root:

php examples/workshop-state-map.php
0 start
1 scanned
1 labelled
2 ready
3 verified
4 sealed

This model groups histories by their available future operations. If a rule needs to know which operation happened first, the state must capture that fact. Each operation has equal weight here. To compare operations with different costs, use a shortest-path algorithm that accounts for their weights.

Open the PHP source. Original example for Darkwood Code Calendar 2026 edition 05.

Edit this page on GitHub