-
Notifications
You must be signed in to change notification settings - Fork 218
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 5 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,11 @@ | ||
| SPECIFICATION Spec | ||
|
|
||
| CONSTANT | ||
| Processes = {p1, p2, p3} | ||
| Null = null | ||
|
|
||
| INVARIANT TypeOK | ||
| INVARIANT ValidStates | ||
| INVARIANT MutualExclusion | ||
|
|
||
| PROPERTY EventuallyIdle |
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,99 @@ | ||||||||||||||
| -------------------------------- MODULE deli -------------------------------- | ||||||||||||||
| (***************************************************************************) | ||||||||||||||
| (* A specification of a deli ordering system with a ticket-queue model. *) | ||||||||||||||
| (* Customers arrive (TakeOrder), get assigned to a worker who prepares *) | ||||||||||||||
| (* their order (PrepareOrder), then the order is served (Serve), and the *) | ||||||||||||||
| (* system returns to Idle (ReturnToIdle) to process the next customer. *) | ||||||||||||||
| (***************************************************************************) | ||||||||||||||
|
|
||||||||||||||
| EXTENDS Naturals, Sequences | ||||||||||||||
|
|
||||||||||||||
| CONSTANTS Processes, Null | ||||||||||||||
|
|
||||||||||||||
| VARIABLES ticket, worker, customer, state, orderQueue | ||||||||||||||
|
|
||||||||||||||
| (***************************************************************************) | ||||||||||||||
| (* 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) | ||||||||||||||
|
|
||||||||||||||
| Init == | ||||||||||||||
| /\ ticket = 0 | ||||||||||||||
| /\ worker = Null | ||||||||||||||
| /\ customer = Null | ||||||||||||||
| /\ state = "Idle" | ||||||||||||||
| /\ orderQueue = <<>> | ||||||||||||||
|
|
||||||||||||||
| (* Customer arrives, gets a ticket number, and joins the queue *) | ||||||||||||||
| TakeOrder == | ||||||||||||||
| /\ state = "Idle" | ||||||||||||||
| /\ \E c \in Processes : | ||||||||||||||
| /\ ticket' = ticket + 1 | ||||||||||||||
| /\ orderQueue' = Append(orderQueue, c) | ||||||||||||||
| /\ state' = "TakingOrder" | ||||||||||||||
|
||||||||||||||
| /\ 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 | ||||||||||||||
|
|
||||||||||||||
| (* The assigned worker serves the current customer *) | ||||||||||||||
| Serve == | ||||||||||||||
| /\ state = "PreparingOrder" | ||||||||||||||
| /\ state' = "Serving" | ||||||||||||||
| /\ UNCHANGED <<ticket, worker, customer, orderQueue>> | ||||||||||||||
|
|
||||||||||||||
| (* Customer is served, worker and customer reset, ready for the next order *) | ||||||||||||||
| ReturnToIdle == | ||||||||||||||
| /\ state = "Serving" | ||||||||||||||
| /\ state' = "Idle" | ||||||||||||||
| /\ worker' = Null | ||||||||||||||
| /\ customer' = Null | ||||||||||||||
| /\ UNCHANGED <<ticket, orderQueue>> | ||||||||||||||
|
|
||||||||||||||
| 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) |
Copilot
AI
Mar 9, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EventuallyIdle == <> (state = "Idle") is vacuously true because Init already sets state = "Idle", so the liveness property doesn't actually check that the system returns to idle after taking an order. If the intent is progress, consider a stronger temporal property (e.g., []<>(state = "Idle") or a leads-to property from non-idle states) and add fairness assumptions as needed.
| (* Liveness: The system eventually returns to Idle (progress) *) | |
| EventuallyIdle == | |
| <> (state = "Idle") | |
| (* Liveness: The system returns to Idle infinitely often (progress) *) | |
| EventuallyIdle == | |
| []<> (state = "Idle") |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| { | ||
| "sources": [], | ||
| "authors": [ | ||
| "Eric Spencer" | ||
| ], | ||
| "tags": [], | ||
| "modules": [ | ||
| { | ||
| "path": "specifications/deli/deli.tla", | ||
| "features": [], | ||
| "models": [ | ||
| { | ||
| "path": "specifications/deli/deli.cfg", | ||
| "runtime": "00:00:05", | ||
| "mode": "exhaustive search", | ||
| "result": "success" | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.