ACEAtomic Constraint Engine

The Atomic Constraint Engine

One primitive. Done is derived, never stored.

ACE runs construction work on one kind of record, the atom. A permit, a delivery, an RFI (request for information), an inspection and a whole work area are all atoms, joined by two links: requires, what must finish first, and contains, its children.

No atom has a done field. People record what they did: closed it, signed it, wrote it up. Done is worked out from those facts and the graph each time anyone asks, so there is nothing to keep up to date.

ACE is written in Sprout, this site's own programming language. Each idea below is a short Sprout program, running on this page.

A turbine pedestal as a graph of atoms Permit, survey, engineer reply and rebar on site need nothing first. Excavate requires the permit and the survey; the RFI gate requires the engineer's reply; place rebar requires excavate, the rebar and the RFI; the inspection requires place rebar; the pour requires the inspection. The turbine pedestal is a rollup that contains excavate, place rebar, the inspection and the pour. turbine pedestalrollup permitverified surveyleaf engineer replyleaf rebar on siteleaf excavateleaf RFI: splicegate place rebarleaf inspectionverified pourleaf
  • done
  • workable
  • needs a witness
  • waiting

A turbine pedestal as atoms. Arrows run from what must finish first to the work that requires it; the dashed box is a rollup.

The rebar arrives and the engineer replies. Nobody closes the RFI: it is a gate, and it closes itself.

6 / 9

If you run the work

The schedule, the constraint log, the RFI list, the inspection register and the area rollups all describe the same job. In ACE they are one graph. Close what you finished, and the graph tells you what is done, what can start today, what each piece of work is waiting for, and which chain of work sets the finish. There is no percent-complete column to keep up to date.

If you write the code

An atom is a record and the two links are edges. Done is a fixed point: start from the empty set, add every atom whose rule holds, and repeat until a pass adds nothing. Everything else is a function of the graph. The critical path is a walk, the forecast is a Monte Carlo run over that walk, and the morning ranking is the difference between two sets of workable atoms. Each is a few dozen lines of Sprout.

The primitive

The atom

Everything on the job is the same kind of record. This one is from ace-derive.sp, written one field to a line.

[
id : "place-rebar"The name its links use.
name : "Place rebar"What people call it.
kind : "leaf"Who says it is done: one of five kinds.
closed : falseA fact someone recorded. Done is worked out from facts like this one.
tags : []Free labels. Only one carries a rule: narrative-required.
requires : ["dig", "rebar-on-site", "rfi-splice"]What must finish first.
contains : []Its children. A work area contains the work in it.
]
  • trivialBorn done: a fact other atoms can rely on, such as an issued design basis.
  • leafA person closes it.
  • verifiedClosed and signed by a witness: two locks. Permits and inspections.
  • gateDone when everything it requires is done. RFIs and constraints.
  • rollupDone when all its children are done. Areas and work packages.

A tag carries no rule, with one exception: narrative-required. An atom with it is not done, however it was closed, until someone writes down what happened.

Eight programs

One idea each

Each is a Sprout program of under 200 lines. The interactive ones start as you scroll to them, and most reports print as they come into view; the million runs and the database wait for a tap. Any of them opens in the playground, where you can change the code while it runs.

  1. 01Done is a fixed pointThe five kinds, worked out
  2. 02The boardTap work; the graph does the rest
  3. 03CrewsSequence and capacity, one link
  4. 04The scheduleA distribution, not a date
  5. 05RiskA million runs, what each risk costs
  6. 06The event logAtoms in SQLite, every step written
  7. 07The sitePositions as expressions, rules as constraints
  8. 08The morning questionWhich constraint to kill today

01ace-derive.sp

Done is a fixed point

Each kind of atom has one rule for when it closes. To find out what is done, ACE starts from nothing and closes every atom whose rule holds. Then it goes round again with what it just learned, until a pass closes nothing new. That resting point is the answer, and it is worked out afresh every time anyone asks.

This program prints four snapshots of the pedestal: today; after the rebar arrives and the RFI is answered; after the inspection is signed but not yet written up; and after the write-up.

ace-derive.spRuns when you scroll here
This program prints its report here when you scroll to it.

Look for

  • In the third snapshot the inspection is closed and signed, yet it shows [!]. It carries narrative-required, so it waits for its write-up, and so does the pour.
  • [>] marks work that can start now. Nothing stored that; the report worked it out.
ace-derive.spOpen the whole program
-- does this atom close, given the ids already done?
closes : [a ok |
  links-done : a requires .. (a contains) keep [x | has [ok, x] not] length = 0
  match [a kind, [
    "trivial", true
    "leaf", a closed and (owes-story a not)
    "verified", a closed and (a signed) and (owes-story a not)
    any, links-done
  ]]
]
-- derive: start from nothing and close whatever the graph allows, until nothing changes (a fixed point)
settle : [atoms-in ok |
  more : atoms-in keep [a | has [ok, a id] not and (closes [a, ok])] collect [a | a id]
  more length = 0 [ok] else [settle [atoms-in, ok .. more]]
]

02ace-board.sp

Tap the work, and the graph does the rest

The same idea with a finger on it. A leaf closes with one tap. A verified atom takes two, the work and then the witness. Gates and the rollup are never tapped: they close themselves when what they wait on is done. Blocked work refuses the tap and says what it waits on.

Red marks the critical path, the chain of open work that sets the finish. The inspection has to be written up, and the write-up is structure: choose rework or NCR (non-conformance report) and new atoms join the graph, with the pour waiting for them.

ace-board.spStarts when you scroll here

The board starts when you scroll here.

Try this

  • Tap pour. It shakes and tells you what it waits on.
  • Tap engineer reply and watch the RFI close itself.
  • Work down to the inspection, sign it, and choose NCR.
ace-board.spOpen the whole program
-- derive: done is never stored. Close whatever the graph allows until nothing changes.
closes : [a ok g |
  k : a kind
  needs-met : a requires keep [r | has [ok, r] not] length = 0
  told : (a story else false) not or (g story != "")
  k = "trivial" or (needs-met and (k = "gate" or (has [g closed, a id] and told and (k = "leaf" or (has [g signed, a id])))))
]

03ace-crews.sp

Sequence and capacity, one link

Work waits for two kinds of thing. A sequence constraint points at an atom: the pour requires the rebar. A capacity constraint points at a query: any idle crew of the right trade. Both say that this can't start until that is true, so ACE holds them in the same link.

Each day, every free crew takes the first ready work of its trade. There is one iron crew. Send it home before the rebar starts and the rebar waits, and so does everything behind it: the embeds, the pour, the columns.

ace-crews.spStarts when you scroll here

The crews start when you scroll here.

Try this

  • Tap the line at the top to start the job again, then tap iron 1 straight away to send it home.
  • Watch the rebar wait, then tap iron 1 again to bring it back.
ace-crews.spOpen the whole program
  [id : "rebar", trade : "iron", days : 4, requires : ["piles"]]
  [id : "embeds", trade : "elec", days : 2, requires : ["rebar"]]
  [id : "pour", trade : "civil", days : 1, requires : ["formwork", "rebar", "embeds"]]

  -- the capacity constraint: a crew is free when it's on site and holds no work
  busy : finished keep [p | p status = "working"] collect [p | p crew]
  free : g crews keep [c | c on and (has [busy, c id] not)]
  -- each free crew takes the first waiting work of its trade whose requirements are done
  ready : [p | p status = "waiting" and (p requires keep [r | has [done-ids, r] not] length = 0)]

04ace-schedule.sp

The plan is a distribution, not a date

The critical path is a walk: start at the last atom and step back through whichever requirement finishes last. Give every duration three numbers, fastest, likely and slowest, add one shared risk, wet weather on the pour, and run the job 400 times. The finish becomes a spread.

On likely durations the job finishes on day 21. Across the runs it makes day 21 only 2% of the time, and P80, the day by which 80 runs in 100 have finished, is day 28. Cost is a view of the same graph: crews times rates times days, plus materials, and earned value on a status day.

ace-schedule.spRuns when you scroll here
This program prints its report here when you scroll to it.

Look for

  • The date the plan prints sits in the left tail of the histogram.
  • The same seed always gives the same runs. Change seed in the playground for another 400.
ace-schedule.spOpen the whole program
-- earliest finish: the latest finish of everything required, plus this atom's own time
finish : [want ds |
  a : find [want, ds]
  (a requires collect [r | finish [r, ds]] fold [0, [m x | m max x]]) + (a days)
]
-- the critical path: walk back from the end, always through the requirement that finishes last
path : [want ds |
  a : find [want, ds]
  a requires length = 0 [[want]] else [
    worst : a requires fold ["", [w r | w = "" or (finish [r, ds] > (finish [w, ds])) [r] else [w]]]
    path [worst, ds] .. [want]
  ]
]

05ace-risk.sp

A million runs, and what each risk costs

The same job with a risk register: wet weather on the pour, late rebar, a slow answer to the RFI, a failed inspection. Each run samples every duration, rolls every risk, and walks the graph five times: once with every risk, and once with each one left out. The gap at P80 is what that risk costs.

Sprout's spork works a run out ahead into one kernel of plain number math, then runs it for every input at once on WebAssembly SIMD. A million runs take about a second, and this page runs them off the main thread, so it never stalls.

ace-risk.spWaits for a tap

1,000,000

runs of the pedestal job, each one sampling every duration and rolling every risk in the register.

Edit in the playground

Look for

  • Wet weather adds the most at P80, though late rebar adds more days when it happens. The frequent risk costs more than the big one.
ace-risk.spOpen the whole program
-- the risk register: what can go wrong, how often in a run, how many days it adds, and to what
risks : [
  [name : "wet weather on the pour", chance : 0.30, delay : 3, hits : "pour"]
  [name : "rebar delivered late", chance : 0.15, delay : 5, hits : "rebar"]
  [name : "slow answer to the RFI", chance : 0.20, delay : 4, hits : "rfi"]
  [name : "inspection fails, rework", chance : 0.10, delay : 3, hits : "inspect"]
]

results : range runs spork one-run

06ace-ledger.sp

Every step, written down

Here the atoms live in SQLite, in three tables: the atoms, the links between them, and the events. Done is still derived in Sprout, from the rows, and every closure goes into the event log with the day it happened.

Each run is one day on site: the first workable atom closes and the log grows by a line. The database is kept in this browser, so the job carries on where you left it.

ace-ledger.spWaits for a tap

One day a run

The job lives in a SQLite database in your browser. Each run closes the next workable atom and writes it in the event log.

Edit in the playground

Try this

  • Run six days and the pedestal is finished.
  • Start over to empty the database and begin again on day 1.
ace-ledger.spOpen the whole program
-- derive what can be worked from the rows: done is never a column we trust on its own
workable-in : [rows |
  done : rows keep [a | a closed = 1] collect [a | a id]
  rows keep [a | a closed = 0 and (needs-of (a id) keep [x | has [done, x] not] length = 0)]
]

-- today: close the first workable atom, and write it down
this-day : db query "select count(*) as n from events" first n + 1
today : workable-in (db query "select id, name, closed from atoms order by rowid") first
today != false
  db run ["update atoms set closed = 1 where id = ?", [today id]]
  db run ["insert into events (day, atom, note) values (?, ?, ?)", [this-day, today id, "closed " .. (today name)]]

07ace-site.sp

Positions are expressions, rules are constraints

Nothing on this plan stores a position. Each building's place is an expression over a few named dimensions: the turbine hall sits at the reactor's edge plus the width of the road, and the service building sits below the reactor the same way. Change the reactor and everything that depends on it moves.

Every rule is a constraint with a name. Must not rules are clashes, two things on the same ground. Must rules are limits the design has to meet. The panel under the plan shows each one holding or failing as you go.

ace-site.spStarts when you scroll here

The plan starts when you scroll here.

Try this

  • Drag left and right across the plan. Under 36 m the reactor is too small. From 54 m the cable run is too long, from 57 m the service building lands on the fuel bay, and from 59 m the turbine hall leaves the site.
ace-site.spOpen the whole program
-- the whole plan, worked out from the reactor diameter d
plan : [d |
  rb : [x : 50, y : 55, r : d / 2]
  tb : [x : rb x + (rb r) + gap, y : 30, w : 46, h : 62]
  sb : [x : rb x - 24, y : rb y + (rb r) + gap, w : 48, h : 26]
  fb : [x : 60, y : 124, w : 34, h : 34]
  [reactor : rb, turbine : tb, service : sb, fuel : fb]
]

    [name : "cable run under 65 m", about : ["reactor", "turbine hall"], kind : "must", holds : centre-gap [p reactor, p turbine] < 65]

fails : [p | constraints p keep [c | c holds not]]

08ace-morning.sp

The morning question

Status meetings ask what happened. The job moves on a different question: which constraints, killed today, release the most work? For each open constraint, ACE counts the hours of work that would become workable if it cleared this morning, and ranks them.

Some constraints release nothing on their own, because the work behind them needs a second one too. The program finds the partner each one needs.

ace-morning.spRuns when you scroll here
This program prints its report here when you scroll to it.

Look for

  • The south access road comes first, with 180 hours. RFI 112 releases nothing alone, yet with the north rebar delivery it releases 260.
ace-morning.spOpen the whole program
-- work that can start: not done, and everything it requires is done
workable : [cleared | work keep [w | w done not and (w requires keep [r | has [cleared, r] not] length = 0)]]
-- the work an extra clearance would release: workable then, but not now
released : [extra | now : workable (done-with []) collect [w | w id], workable (done-with extra) keep [w | has [now, w id] not]]

open-ones : constraints keep [c | c open]
ranking : open-ones collect [c |
  r : released [c id]
  [id : c id, name : c name, packages : r, hours : sum (r collect [w | w hours])]
]

Every view on this page reads the same atoms, and none of them stores done.

Field notes

The essays behind ACE

ACE grew out of short notes on how big jobs run. Each takes a couple of minutes to read.