-
Notifications
You must be signed in to change notification settings - Fork 217
Add Deli Queue Example #201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 12 commits
9727b40
29feaac
a8853b4
a8b9275
53f3daa
a7971fd
3f7ac8c
13f70ec
bba1b17
dad6d5b
2564308
f590f02
690ca27
6233004
d1b3b55
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| # Deli | ||
|
|
||
| A TLA⁺ specification of a simple deli ordering system with a ticket-queue model. | ||
|
|
||
| The spec models a single worker serving customers in queue order. Customers arrive, receive a ticket number, join an order queue, get assigned to the worker, receive service, and the system resets to serve the next customer. The system cycles through four states: Idle → TakingOrder → PreparingOrder → Serving → ReturnToIdle. | ||
|
|
||
| ## Key Features | ||
|
|
||
| - **Ticket-based ordering**: Customers get monotonically increasing ticket numbers as they arrive | ||
| - **Queue discipline**: Customers are served in FIFO order from the queue | ||
|
EricSpencer00 marked this conversation as resolved.
Outdated
|
||
| - **Worker assignment**: A dedicated worker is assigned in the PrepareOrder phase | ||
| - **State machine with return cycle**: Unlike simpler queue models, the system explicitly returns to Idle, enabling liveness properties | ||
|
|
||
| ## Properties Checked | ||
|
|
||
| The specification includes three safety invariants and one liveness property: | ||
|
|
||
| 1. **TypeOK**: State variables maintain correct types throughout execution | ||
| 2. **ValidStates**: The system never enters an undefined state | ||
| 3. **MutualExclusion**: At most one customer-worker pair is in the Serving state at any time | ||
| 4. **EventuallyIdle**: The system eventually returns to the Idle state (progress/fairness) | ||
|
EricSpencer00 marked this conversation as resolved.
Outdated
EricSpencer00 marked this conversation as resolved.
Outdated
|
||
|
|
||
| The `.tla` file includes formal THEOREM declarations for each property, making the spec suitable for TLC model checking and serving as a test case for the TLC toolchain. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| SPECIFICATION Spec | ||
|
|
||
| CONSTANT | ||
| Processes = {p1, p2, p3} | ||
| Null = null | ||
| MaxArrivals = 2 | ||
|
|
||
| INVARIANT TypeOK | ||
| INVARIANT ValidStates | ||
| INVARIANT MutualExclusion |
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,98 @@ | ||||||||||||||
| -------------------------------- MODULE deli -------------------------------- | ||||||||||||||
| (***************************************************************************) | ||||||||||||||
| (* A specification of a simple deli ordering system with a ticket queue. *) | ||||||||||||||
| (* Customers arrive, get assigned to a worker, their order is prepared, *) | ||||||||||||||
| (* and then served. The system cycles through Idle → TakingOrder → *) | ||||||||||||||
| (* PreparingOrder → Serving → ReturnToIdle to serve the next customer. *) | ||||||||||||||
|
EricSpencer00 marked this conversation as resolved.
Outdated
|
||||||||||||||
| (***************************************************************************) | ||||||||||||||
|
|
||||||||||||||
| EXTENDS Naturals, Sequences | ||||||||||||||
|
|
||||||||||||||
| CONSTANTS Processes, Null, MaxArrivals | ||||||||||||||
|
|
||||||||||||||
| VARIABLES ticket, worker, customer, state, orderQueue, arrivals | ||||||||||||||
|
|
||||||||||||||
| (***************************************************************************) | ||||||||||||||
| (* State variables: *) | ||||||||||||||
| (* - ticket: increasing counter issued to arriving customers *) | ||||||||||||||
| (* - worker: the current worker serving an order, or Null if idle *) | ||||||||||||||
| (* - customer: the current customer being served, or Null if idle *) | ||||||||||||||
| (* - state: the system's current phase: *) | ||||||||||||||
| (* (Idle | TakingOrder | PreparingOrder | Serving) *) | ||||||||||||||
| (* - orderQueue: sequence of customers waiting to be served *) | ||||||||||||||
| (***************************************************************************) | ||||||||||||||
|
|
||||||||||||||
| TypeOK == | ||||||||||||||
| /\ ticket \in Nat | ||||||||||||||
| /\ worker \in Processes \cup {Null} | ||||||||||||||
| /\ customer \in Processes \cup {Null} | ||||||||||||||
| /\ state \in {"Idle", "TakingOrder", "PreparingOrder", "Serving"} | ||||||||||||||
| /\ orderQueue \in Seq(Processes) | ||||||||||||||
| /\ arrivals \in Nat | ||||||||||||||
|
|
||||||||||||||
| Init == | ||||||||||||||
| /\ ticket = 0 | ||||||||||||||
| /\ worker = Null | ||||||||||||||
| /\ customer = Null | ||||||||||||||
| /\ state = "Idle" | ||||||||||||||
| /\ orderQueue = <<>> | ||||||||||||||
| /\ arrivals = 0 | ||||||||||||||
|
|
||||||||||||||
| (* Customer arrives, gets a ticket number, and joins the queue *) | ||||||||||||||
| TakeOrder == | ||||||||||||||
| /\ state = "Idle" | ||||||||||||||
| /\ arrivals < MaxArrivals | ||||||||||||||
| /\ \E c \in Processes : | ||||||||||||||
| /\ ticket' = ticket + 1 | ||||||||||||||
| /\ arrivals' = arrivals + 1 | ||||||||||||||
| /\ orderQueue' = Append(orderQueue, c) | ||||||||||||||
| /\ state' = "TakingOrder" | ||||||||||||||
|
EricSpencer00 marked this conversation as resolved.
Outdated
|
||||||||||||||
| /\ UNCHANGED <<worker, customer>> | ||||||||||||||
|
|
||||||||||||||
| (* The next customer from the queue is called and a worker is assigned *) | ||||||||||||||
| PrepareOrder == | ||||||||||||||
| /\ state = "TakingOrder" | ||||||||||||||
| /\ Len(orderQueue) > 0 | ||||||||||||||
|
EricSpencer00 marked this conversation as resolved.
Outdated
|
||||||||||||||
| /\ LET c == Head(orderQueue) IN | ||||||||||||||
| /\ \E w \in Processes : | ||||||||||||||
| /\ customer' = c | ||||||||||||||
| /\ worker' = w | ||||||||||||||
| /\ orderQueue' = Tail(orderQueue) | ||||||||||||||
| /\ state' = "PreparingOrder" | ||||||||||||||
| /\ UNCHANGED <<ticket, arrivals>> | ||||||||||||||
|
|
||||||||||||||
| (* The assigned worker serves the current customer *) | ||||||||||||||
| Serve == | ||||||||||||||
| /\ state = "PreparingOrder" | ||||||||||||||
| /\ state' = "Serving" | ||||||||||||||
| /\ UNCHANGED <<ticket, worker, customer, orderQueue, arrivals>> | ||||||||||||||
|
|
||||||||||||||
| (* Customer is served, worker and customer reset, ready for the next order *) | ||||||||||||||
| ReturnToIdle == | ||||||||||||||
| /\ state = "Serving" | ||||||||||||||
| /\ state' = "Idle" | ||||||||||||||
| /\ worker' = Null | ||||||||||||||
| /\ customer' = Null | ||||||||||||||
| /\ UNCHANGED <<ticket, orderQueue, arrivals>> | ||||||||||||||
|
|
||||||||||||||
| Next == | ||||||||||||||
| TakeOrder \/ PrepareOrder \/ Serve \/ ReturnToIdle | ||||||||||||||
|
|
||||||||||||||
| (* Safety: System stays in one of the allowed states *) | ||||||||||||||
| ValidStates == | ||||||||||||||
| state \in {"Idle", "TakingOrder", "PreparingOrder", "Serving"} | ||||||||||||||
|
|
||||||||||||||
| (* Safety: At most one customer is being served at any given time *) | ||||||||||||||
| MutualExclusion == | ||||||||||||||
| (state = "Idle") => (customer = Null /\ worker = Null) | ||||||||||||||
|
||||||||||||||
| (* Safety: At most one customer is being served at any given time *) | |
| MutualExclusion == | |
| (state = "Idle") => (customer = Null /\ worker = Null) | |
| (* Safety: The system is idle iff there is no active customer or worker *) | |
| MutualExclusion == | |
| (state = "Idle") <=> (customer = Null /\ worker = Null) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| { | ||
| "sources": [], | ||
| "authors": [ | ||
| "Eric Spencer" | ||
| ], | ||
| "tags": [], | ||
| "modules": [ | ||
| { | ||
| "path": "specifications/deli/deli.tla", | ||
| "features": [], | ||
| "models": [ | ||
| { | ||
| "path": "specifications/deli/deli.cfg", | ||
| "runtime": "00:00:01", | ||
| "mode": "exhaustive search", | ||
| "result": "success", | ||
| "distinctStates": 30, | ||
| "totalStates": 78, | ||
| "stateDepth": 1 | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.