Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/instructions/ci.instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ applyTo: ".github/workflows/**,Taskfile.dist.yaml,**/Taskfile.dist.yaml,.pre-com
under a 12 GB cap (`docs/design.md`, section 8). Reject a CI job or task that runs
`cargo kani` without `--harness`.
- `msrv` checks the library only (`cargo hack check --rust-version --all-features`, no
`--all-targets`): dev-dependencies may need a newer Rust (criterion 0.8 needs 1.86). Do not
`--all-targets`): dev-dependencies may need a newer Rust (proptest 1.12 needs 1.88). Do not
add `--all-targets` back.
- `fuzz/` is a separate nightly workspace. Its tasks live in `fuzz/Taskfile.dist.yaml`,
included as `fuzz:`; CI's `fuzz` job mirrors `task fuzz:build` and `task fuzz:lint`.
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ jobs:
- uses: taiki-e/install-action@25f51f6b1bf4e18876107cece836f4f77ac17c8c # v2.90.7
with:
tool: cargo-hack
# Library only: dev-dependencies (criterion 0.8 needs 1.86) may need a newer Rust than users do.
# Library only: dev-dependencies (proptest 1.12 needs 1.88) may need a newer Rust than users do.
- run: cargo hack check --rust-version --workspace --ignore-private --all-features

# Baseline: the latest release on crates.io.
Expand Down
20 changes: 18 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,24 @@ alloc = []
[dependencies]

[dev-dependencies]
criterion = { version = "0.8", default-features = false, features = ["cargo_bench_support"] }
proptest = { version = "1", default-features = false, features = ["std"] }
criterion = { version = "0.8.2", default-features = false, features = ["cargo_bench_support"] }
proptest = { version = "1.12", default-features = false, features = ["std"] }

# Examples also run as tests (`test = true`), so their assertions are checked in CI.
[[example]]
name = "rover_relay"
required-features = ["alloc"]
test = true

[[example]]
name = "relay_pass"
required-features = ["alloc"]
test = true

[[example]]
name = "observation_campaign"
required-features = ["alloc"]
test = true

[[bench]]
name = "dispatch"
Expand Down
32 changes: 31 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ Part of the [planning and search crates](https://sunsided.github.io/planning-and
- Flight software and robotics engineers who schedule activities with uncertain durations on a
spacecraft, rover or robot and need the timing checked before uplink and executed onboard
without a heap. The design targets adoption by an existing executive such as F Prime or cFS.
- Teams of vehicles (rovers, landers, orbiters) that share one plan but rarely talk: each
gets a part it can execute and change alone, and the parts are merged and rebalanced when
they can communicate, without a central solver.
- Planners that emit temporal plans and need to know whether the plan stays executable under
duration uncertainty, with an explanation when it does not.
- Researchers comparing dynamic controllability algorithms: Morris 2014, RUL⁻, RUL2021, the
Expand Down Expand Up @@ -68,6 +71,11 @@ temporal-control = { version = "0.1", default-features = false }
and Rizzi 2018), RUL2021 (Hunsberger and Posenato 2022), and per-label backpropagation
(cross-check).
- Explanations of non-controllability (semi-reducible negative cycles).
- Multi-agent STNs: temporal decoupling into per-agent local networks that execute
independently (greedy cuts relative to a shared reference point), local changes checked
by the agent alone, distributed consistency checks and re-decoupling from exchanged
summaries of each agent's shared points, and communication windows (relay passes) modelled
as contingent links.
- Onboard dispatcher, `no_std` without `alloc`, fixed capacity, loaded in place from a
`const EMPTY`, with `u16`/`u32`/`usize` index types for its internal handles.
- Compact checksummed encoding (CRC-32) of dispatchable networks, with a no-`alloc` decoder.
Expand All @@ -81,7 +89,29 @@ temporal-control = { version = "0.1", default-features = false }
Reaction-time semantics: an observation at tick `t` may trigger executions at the same tick.
Next-tick reaction is supported by transforming the network (`Stnu::with_reaction`).

Not yet implemented: differential tests against CSTNU-Tool.
Not yet implemented: differential tests against CSTNU-Tool, and optimal (flexibility-maximising)
decoupling.

## Examples

Each example asserts its own results and runs as a test (`cargo test --examples`).

- [`rover_relay`](https://github.com/sunsided/temporal-control/blob/main/examples/rover_relay.rs):
two rovers and an orbiter decouple a joint plan, execute it without talking, absorb a delay
locally, rebalance the slack at the next contact when a delay does not fit, and reject a
conflicting change with the shared constraint it breaks.
- [`relay_pass`](https://github.com/sunsided/temporal-control/blob/main/examples/relay_pass.rs):
a lander downlinks through a relay pass whose opening is uncertain. Dynamic
controllability, the explanation of a deadline that cannot hold, the checksummed uplink and
the heap-free dispatcher reacting to the actual analysis end and pass opening.
- [`observation_campaign`](https://github.com/sunsided/temporal-control/blob/main/examples/observation_campaign.rs):
a telescope night planned request by request with the incremental STN (a rejected request
names the constraints it conflicts with), a 200-field survey checked with P³C instead of
the full matrix, and the dispatchable network of the night.

```sh
cargo run --example rover_relay
```

## Cargo features

Expand Down
81 changes: 81 additions & 0 deletions docs/design.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,67 @@ loading fails with `DispatchError::IndexTypeTooSmall`. Measured per point and pe
24 with `usize`. The saving on 32-bit targets is small because windows and entries hold
8-byte-aligned `i64` ticks.

### 3.4 Multi-agent STNs

A multi-agent STN is an STN with a reference point `z` and an owner `own(t)` in a set of
agents for every other point. A constraint is *local* to agent `a` if each endpoint is `z`
or owned by `a`, and *shared* if its endpoints have different owners.

A *decoupling* adds unary constraints (*cuts*) `t - z >= c` or `t - z <= c` on points of
shared constraints, each given to the owner of its point, such that

1. for every shared distance-graph edge `u -> v` with weight `w`, the owner of `u` has a cut
`t_u - z >= c` and the owner of `v` a cut `t_v - z <= c + w` (so every schedule of both
sides satisfies `t_v - t_u <= w`), and
2. the plan with all cuts added is consistent.

Then every agent's *local network* (its local constraints and its cuts) is consistent, and
any family of schedules, one per local network, with `z = 0` in each, combines into a
schedule of the whole plan: local constraints hold by construction and shared ones by (1).
This is Hunsberger's temporal decoupling problem (AAAI 2002). Cuts are kept for every shared
edge, even where the windows of the joint minimal network already imply it: those windows
may owe their tightness to other agents' constraints, which the local network does not see.

**Choice of the cuts** (`multiagent/cuts.rs`). Shared edges are processed in constraint order
on an `IncrementalStn` of the plan. With the current windows `[L(x), U(x)]` relative to `z`,
`c` is the midpoint (rounded down) of `max(L(u), L(v) - w)` and `min(U(u), U(v) - w)`; an
infinite side is replaced by the other, and `0` is used if both are infinite. Any `c` in
`[L(v) - w, U(u)]` keeps the network consistent (proof in the module docs), and both
operands lie in that interval. If the edge still has slack, the midpoint splits it evenly;
if the windows already imply it, the midpoint tightens neither window. The choice is a
greedy heuristic: it does not maximise the total flexibility (an optimal decoupling can be
posed as a linear program), and the order of the shared constraints matters.

**Summaries.** For a group `G` of agents, agent `a` summarises its local network, plus its
proposals, with the cuts of shared constraints towards members of `G` removed: the minimal
bounds between every pair of `z` and the points of `a`'s shared constraints with members.
Because a consistent STN's minimal network is decomposable, these bounds describe exactly
the projections of `a`'s feasible schedules onto those points. So the *joint network* of a
group (all summaries plus the members' shared constraints) is consistent iff the members'
networks plus their shared constraints are, and it has the same minimal bounds on the
shared points. With every agent in the group, that is the consistency of the plan with
every proposal, and the cuts computed on the joint network equal those of a central
decoupling. A negative verdict names the shared constraints and the agents whose summaries
are on the negative cycle, not their own constraints, which the summaries do not carry.

**Re-decoupling.** Every member builds the same joint network from the same summaries (they
are sorted by agent, so the order of arrival does not matter), computes the cuts of the
group's shared constraints on it, and replaces its own cuts towards members with its side of
the new ones; cuts towards non-members stay, and they are part of every member's summary.
On a positive verdict proposals become local constraints; on a negative one they are
dropped and the cuts stay. The result stays a decoupling only if all members switch: the
protocol must ensure every member holds the full set of summaries before any member applies
them, that no member changes between sending its summary and adopting, and that a single
refusal returns every member to its old cuts. Points that already happened are pinned as
local constraints (`z -> t` in `[t, t]`) before summarising, so new cuts respect the past.
Agents and summaries cross process boundaries as plain data (`AgentParts`,
`Summary::from_parts`, both validated); the wire format is left to the integrator. A summary carries the agent's revision, and an agent refuses a group whose summary of
it is older than its current state.

**Communication windows.** A communication opportunity whose time is uncertain is a
contingent link in an STNU (it opens `lo..hi` after its activation and is observed when it
happens). Dynamic controllability then covers every opening time; no new rules are needed.

## 4. Algorithm choices

| Problem | Algorithm | Cost | Status |
Expand All @@ -214,6 +275,9 @@ loading fails with `DispatchError::IndexTypeTooSmall`. Measured per point and pe
| STNU DC check, cross-check | per-label backpropagation: Morris-style, one propagation per kind of negative in-edge, no normalisation | `O(n (k + 1) (m + n^2) log n)` | done |
| Non-DC explanation | semi-reducible negative cycle collected while Morris's nested propagations unwind, in compact form (each derived edge once, lazily expandable) | `O(n^3)` compact; expansion up to `3 * 2^k - 2` edges | done |
| Dispatchable STN | minimal network + dominated-edge filtering (MMT 1998) | `O(n^3)` | done |
| Temporal decoupling | greedy midpoint cuts per shared edge on an incremental minimal network (section 3.4) | `O(n^3 + (m + s) n^2)` for `s` shared constraints, `n^2` cells | done |
| Distributed consistency check | per-agent minimal-network summaries on the shared points (Floyd-Warshall), then Bellman-Ford on the joint network | `O(n_a^3)` per agent `a`, `O(p b)` for the joint network of `p` points and `b` bounds | done |
| Re-decoupling | the decoupling, run by every member on the joint network | as decoupling, on the joint network | done |

Two independent algorithms per question are a deliberate choice: they cross-check each other
in tests and, on the ground, at runtime. `Stn::minimal_network` already does this: if
Expand Down Expand Up @@ -247,6 +311,7 @@ graph LR
| STN, STNU, DC checking, explanations, dispatchable generation | `alloc` (default feature) | ground side; may also run onboard on a capable processor |
| Compact dispatchable encoding (decoder, validator, `encode_into`), dispatcher | none | const-generic capacity, in-place loading from a `const EMPTY`; `O(degree)` work per event |
| `DispatchableNetwork::encode` / `decode` | `alloc` | ground side; `decode` runs exactly the onboard checks |
| Multi-agent decoupling, summaries, group checks | `alloc` | ground side, or on an agent's own processor; each agent dispatches its local network with the dispatcher |

The onboard side works without `alloc`: `Dispatcher::load_encoded` validates a received
encoding (framing, length, CRC-32, canonical form, indices, bounds, structural invariants such
Expand Down Expand Up @@ -382,6 +447,7 @@ Total length `24 + 21 n + 16 (e + w)`, which must match the buffer exactly. Desi
| Encoding | Round trips of dispatchable STNs and ESTNUs (decode equals the original, re-encoding is byte-identical, simulated dispatch from decoded `usize` and `u16` dispatchers matches the original run); every single-bit flip and every truncation of a sample encoding is rejected and leaves a busy dispatcher unchanged; each `DecodeError`; random bytes and random records behind a valid header and CRC never panic | done |
| Fuzzing | Standalone `fuzz/` crate (not a workspace member): `decode` (raw bytes and framed random records; onboard and ground decoders agree), `dispatch` (arbitrary networks and call sequences, `usize` and `u16` dispatchers agree, rejected loads change nothing), `dc_checkers` (STNUs up to 8 points: all checkers and the closure agree, DC networks load and round-trip), `stn` (STNs up to 8 points with extreme bounds: Bellman-Ford schedules hold, Floyd-Warshall, P³C and the dispatchable filter agree with Bellman-Ford, P³C bounds equal the minimal network's, the incremental STN accepts exactly the consistent constraints and matches the minimal network after every step). Run with `cargo +nightly fuzz run <target> -- -max_total_time=60` or `task fuzz:smoke`; 60 s each found nothing. CI builds and lints the targets | done; fuzzing runs in CI open |
| Model checking | Kani harnesses for the dispatcher calls and the decoder on small fixed capacities: no panic, no overflow, windows respected | done: 11 harnesses verified under Kani 0.68, each under 12 GB (bounds and results below); also run on concrete inputs in unit tests |
| Multi-agent | Schedules picked by each agent alone (earliest, latest, random) from its local network combine into a schedule of the plan; decoupling succeeds exactly on consistent plans; the group check with all agents equals the central check of the plan with the proposals; re-decoupling with all agents equals the central decoupling, agent by agent; after a re-decoupling of two of three agents the third is unchanged and independent schedules still combine; mismatched, incomplete or stale summaries are refused. Mutations (run by hand) must make it fail: skipping the cuts of already implied edges, and cuts outside the feasible interval | done; fuzzing open |
| Simulation | deterministic replay with injected contingent durations and resets: DC network plus dispatcher never violates a requirement constraint | open |

**Kani harnesses.** `src/dispatch/proofs.rs` holds bounded no-panic checks as ordinary
Expand Down Expand Up @@ -443,6 +509,9 @@ harness in one process.
CI.
- A deterministic simulator with injected durations, resets and overruns.
- Adapters: F Prime (WebAssembly sequencing) and cFS demonstrators, in separate crates.
- Multi-agent: an optimal (flexibility-maximising) decoupling, decoupling of STNUs with
contingent links across agents, a wire encoding for agents and summaries, the acknowledgement round
that makes re-decoupling all-or-none, and a fuzz target for the group operations.

## 10. Cross-crate needs

Expand Down Expand Up @@ -482,6 +551,10 @@ harness in one process.
built-in policies (as late as possible, preferred times) or leaves that to the executive via
`can_execute`/`execute`.
- Whether onboard incremental re-checking is required, and its budget.
- Multi-agent decoupling: which flexibility measure missions care about (sum of window
widths, the narrowest window, or the windows of chosen points), and whether that justifies
an LP-based optimal decoupling instead of the greedy midpoint. Default: greedy midpoint, in
constraint order.
- Whether contingent links with `l = 0` must be supported. Morris 2014 allows `0 <= l < u`
(its normal form has `l = 0`); MMV 2001 and Hunsberger 2009 require `0 < l < u`. Default:
reject `l = 0`, accept `l = u` (see section 12).
Expand Down Expand Up @@ -652,3 +725,11 @@ read:
1193-1198 (labelled distance graph; restated in Morris 2014).
- L. Hunsberger. Magic loops in simple temporal networks with uncertainty. ICAART 2013 (2),
157-170.

Cited as background for section 3.4, content not read and not compared with the code:

- L. Hunsberger. Algorithms for a temporal decoupling problem in multi-agent planning. AAAI
2002, 468-475 (the temporal decoupling problem; the cut rule of section 3.4 is this
crate's own).
- J. C. Boerkoel Jr. and E. H. Durfee. Distributed reasoning for multiagent simple temporal
problems. JAIR 47 (2013) 95-156 (agent-local subnetworks with shared points).
11 changes: 9 additions & 2 deletions docs/mermaid.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
rustdoc emits ```mermaid blocks as <pre class="language-mermaid"> (not doctested);
this turns them into diagrams, following the rustdoc light/dark theme. -->
<script type="module">
import mermaid from "https://cdn.jsdelivr.net/npm/mermaid@11.17.2/dist/mermaid.esm.min.mjs";
import mermaid from "https://cdn.jsdelivr.net/npm/mermaid@12.3.0/dist/mermaid.esm.min.mjs";

const theme = document.documentElement.getAttribute("data-theme") || "";
const dark = theme === "dark" || theme === "ayu";
Expand All @@ -14,6 +14,13 @@
pre.replaceWith(diagram);
}

mermaid.initialize({ startOnLoad: false, theme: dark ? "dark" : "default" });
// Mermaid 12 defaults to the ELK layout and the "neo" look; keep the dagre layout and the
// classic look the diagrams were drawn for.
mermaid.initialize({
startOnLoad: false,
theme: dark ? "dark" : "default",
layout: "dagre",
look: "classic",
});
await mermaid.run({ querySelector: "pre.mermaid" });
</script>
Loading