Algorithm Search⌘K

Algorithmcore

Supremal controllable sublanguage

Also called supremal controllable sublanguage computation.

Computes the largest controllable sublanguage of a regular specification by a fixed point on the product automaton, in time polynomial in the number of product states.

Time
O(n^2 q) worst
Space
O(n q) extra
Where
n = the number of states of the product of H and G; q = the number of events
Properties
deterministicexactoffline
Origin
W. Murray Wonham, Peter J. Ramadge, 1987

The supremal controllable sublanguage of a specification KK is the largest part of KK that a supervisor can enforce on a plant GG, when it may disable only the controllable events. It always exists, because a union of controllable languages is controllable. When GG and the specification are finite automata, it is computed by a fixed point on their product: delete every product state where an uncontrollable event of the plant leads out of the remaining states, delete the states that can no longer reach a marked state, and repeat. What is left is a trim automaton. It is at the same time the least restrictive nonblocking supervisor for KK. The run takes O(n2q)O(n^2 q) time for nn product states and qq events. Unlike the plain product construction, which only intersects two languages, this algorithm removes states for a reason that looks ahead: a state is bad if an event that nobody can stop leads to a bad state.

In plain words

You have a machine and a list of rules. You can stop some of the machine's moves, but not all of them. Run the machine and the rule book side by side, so that each joint position says where both are. Some positions are traps: from there, a move you cannot stop breaks a rule. Delete those positions. Then delete every position from which you can no longer finish a job. Deleting positions can make new traps, because a move you cannot stop may now lead into a deleted position. So repeat both steps until nothing changes. The positions that are left, with their moves, are the best controller: it stops a move only when it must.

The problem

The input is a plant G=(XG,Σ,δG,x0,Xm)G = (X_G, \Sigma, \delta_G, x_{0}, X_{m}), a specification automaton HH over the same alphabet, and the set Σuc⊆Σ\Sigma_{uc} \subseteq \Sigma of uncontrollable events. Both automata are deterministic and finite. Let K=Lm(H)∩Lm(G)K = L_m(H) \cap L_m(G). The output is a trim automaton ASA_S with

Lm(AS)=sup⁡C(K),L(AS)=sup⁡C(K)‾,L_m(A_S) = \sup C(K), \qquad L(A_S) = \overline{\sup C(K)},

where sup⁡C(K)\sup C(K) is the union of all sublanguages M⊆KM \subseteq K that are controllable, M‾ Σuc∩L(G)⊆M‾\overline{M}\,\Sigma_{uc} \cap L(G) \subseteq \overline{M}. The supervisor is ASA_S itself, run in parallel with GG. After a string ss, it disables the controllable events that GG allows but ASA_S does not.

The algorithm

AA is the accessible part of H×GH \times G. Its states are pairs x=(h,g)x = (h, g), and a state is marked when both parts are marked. SS is the set of states that are still alive.

  1. SUP-C(G, H, Σuc)
  2. 1A ← accessible part of H × G; S ← the states of A
  3. 2repeat
  4. 3changed ← false
  5. 4for each state x = (h, g) in S do
  6. 5if some σ in Σuc has δ_G(g, σ) defined and δ_A(x, σ) undefined or not in S then remove x from S; changed ← true
  7. 6S' ← the states of S that are accessible and coaccessible inside S; if S' ≠ S then S ← S'; changed ← true
  8. 7until not changed
  9. 8return A restricted to S

Line L5 is the controllability test. It looks at the events of the plant at gg, not at the events of AA. If the plant can execute an uncontrollable σ\sigma and the specification does not allow it (δA(x,σ)\delta_A(x, \sigma) is undefined), or allows it only into a dead state, then the state xx is a trap and goes. Line L6 is the nonblocking test. It is a forward search from the initial state and a backward search from the marked states, both inside SS. The two tests feed each other. Removing a trap can cut the only path to a marked state, and removing a blocking state can make a new trap. So the loop runs until a round changes nothing. The result is the largest fixed point of the operator "remove traps, then trim", in the sense of Wonham and Ramadge (1987).

Example

The plant GG has states 0 to 4 and the transitions

0→a1,1→u2,2→b3,3→v4,4→d0,0→e0,1→c0,0 \xrightarrow{a} 1, \quad 1 \xrightarrow{u} 2, \quad 2 \xrightarrow{b} 3, \quad 3 \xrightarrow{v} 4, \quad 4 \xrightarrow{d} 0, \quad 0 \xrightarrow{e} 0, \quad 1 \xrightarrow{c} 0,

with Σuc={u,v}\Sigma_{uc} = \{u, v\} and the marked state 0. The specification HH is the same automaton without the vv transition, with all states marked: "the event vv must never occur". The product AA (line L1) has the 4 states (0,0)(0,0), (1,1)(1,1), (2,2)(2,2) and (3,3)(3,3) and 5 transitions; state 4 of GG is not reached, because HH has no vv. Only (0,0)(0,0) is marked.

round removed at L5 removed at L6 SS after the round
1 (3,3)(3,3): GG can do vv, HH cannot (2,2)(2,2): it cannot reach (0,0)(0,0) any more (0,0)(0,0), (1,1)(1,1)
2 (1,1)(1,1): uu leads to the removed (2,2)(2,2) none (0,0)(0,0)
3 none none (0,0)(0,0), stop

The result is the state (0,0)(0,0) with its self-loop ee, so sup⁡C(K)=e∗\sup C(K) = e^*. The reason: after aa, the uncontrollable uu may take the plant to state 2. From there, the only way back to the marked state is bb and then vv, which is forbidden. So the supervisor must never enable aa. The specification itself, K=(e+ac)∗K = (e + ac)^*, is not controllable, because a∈K‾a \in \overline{K} and au∈L(G)au \in L(G) but au∉K‾au \notin \overline{K}.

A second example is the buffer of supervisory control theory. There the product has 8 states and 12 transitions, round 1 removes the two states where the buffer is full and machine 1 works, and the result has 6 states and 8 transitions. The tests of the implementation check both examples.

Correctness

Let RR be the set of states of AA that strings of sup⁡C(K)‾\overline{\sup C(K)} reach. The invariant is R⊆SR \subseteq S: no state of RR is ever removed. A state of RR passes line L5, because sup⁡C(K)\sup C(K) is controllable, so each uncontrollable event of GG leads to another state of RR. It passes line L6, because the strings of sup⁡C(K)\sup C(K) give paths inside RR from the initial state and to a marked state. When the loop stops, ASA_S is trim and no state fails line L5, so Lm(AS)L_m(A_S) is a controllable sublanguage of KK, and it holds sup⁡C(K)\sup C(K) by the invariant. The two inclusions give equality. The full proof is in the correctness proof.

Proof: The fixed point on the product automaton gives the supremal controllable sublanguagefull

Setting. The plant GG and the specification automaton HH are deterministic automata over the alphabet Σ=Σc∪Σuc\Sigma = \Sigma_c \cup \Sigma_{uc}, where Σuc\Sigma_{uc} is the set of uncontrollable events. Let K=Lm(H)∩Lm(G)K = L_m(H) \cap L_m(G). A language M⊆KM \subseteq K is controllable if M‾ Σuc∩L(G)⊆M‾\overline{M}\,\Sigma_{uc} \cap L(G) \subseteq \overline{M}, where M‾\overline{M} is the prefix closure of MM. Line L1 builds AA, the accessible part of H×GH \times G. A state of AA is a pair (h,g)(h, g), and a string ss is defined in AA if and only if it is defined in both HH and GG. So L(A)=L(H)∩L(G)L(A) = L(H) \cap L(G) and Lm(A)=KL_m(A) = K. For s∈L(A)s \in L(A) we write x(s)x(s) for the state of AA that ss reaches. Its second part is the state of GG that ss reaches. We write SS for the set states of the program, and ASA_S for the restriction of AA to SS.

Lemma 1 (union). A union of controllable languages is controllable. So sup⁡C(K)\sup C(K), the union of all controllable sublanguages of KK, is controllable and is the largest one.

Proof. Let M=⋃iMiM = \bigcup_i M_i with each MiM_i controllable. The prefix closure commutes with unions, so M‾=⋃iMi‾\overline{M} = \bigcup_i \overline{M_i}. Take s∈M‾s \in \overline{M} and σ∈Σuc\sigma \in \Sigma_{uc} with sσ∈L(G)s\sigma \in L(G). Then s∈Mi‾s \in \overline{M_i} for some ii, so sσ∈Mi‾⊆M‾s\sigma \in \overline{M_i} \subseteq \overline{M}. ■\blacksquare

Let R={x(s):s∈sup⁡C(K)‾}R = \{x(s) : s \in \overline{\sup C(K)}\}. This is well defined, because sup⁡C(K)‾⊆K‾⊆L(A)\overline{\sup C(K)} \subseteq \overline{K} \subseteq L(A).

Lemma 2 (invariant). At every point of the run, R⊆SR \subseteq S.

Proof. At the start SS is the full state set of AA, so the claim holds. We show that no removal takes away a state of RR. Assume R⊆SR \subseteq S just before a removal.

Line L5 removes x=(h,g)x = (h, g) if some σ∈Σuc\sigma \in \Sigma_{uc} is defined at gg in GG and δA(x,σ)\delta_A(x, \sigma) is undefined or not in SS. Assume x∈Rx \in R, so x=x(s)x = x(s) for some s∈sup⁡C(K)‾s \in \overline{\sup C(K)}. Then sσ∈L(G)s\sigma \in L(G), and by Lemma 1 sσ∈sup⁡C(K)‾s\sigma \in \overline{\sup C(K)}. So sσ∈L(A)s\sigma \in L(A), δA(x,σ)=x(sσ)\delta_A(x, \sigma) = x(s\sigma) is defined, and x(sσ)∈R⊆Sx(s\sigma) \in R \subseteq S. This is a contradiction, so x∉Rx \notin R.

Line L6 keeps the states of SS that are accessible and coaccessible inside SS. Let x=x(s)x = x(s) with s∈sup⁡C(K)‾s \in \overline{\sup C(K)}. Each prefix s′s' of ss is in sup⁡C(K)‾\overline{\sup C(K)}, so x(s′)∈R⊆Sx(s') \in R \subseteq S, and the path of ss from the initial state to xx stays in SS. So xx is accessible in SS. There is tt with st∈sup⁡C(K)st \in \sup C(K). In the same way the path of stst stays in SS, and it ends at x(st)x(st), which is marked in AA because st∈K=Lm(A)st \in K = L_m(A). So xx is coaccessible in SS, and line L6 keeps it. ■\blacksquare

Lemma 3 (the fixed point). Let SS be the set when the loop stops at line L7, and let M=Lm(AS)M = L_m(A_S). Then M⊆KM \subseteq K, M‾=L(AS)\overline{M} = L(A_S), and MM is controllable.

Proof. If SS is empty, M=∅M = \emptyset, and all three claims hold. Otherwise, in the last round line L5 removed nothing, so every state of SS passed the test of line L5 with this same set SS. Line L6 also returned SS, so ASA_S is trim. M⊆Lm(A)=KM \subseteq L_m(A) = K. Each string of L(AS)L(A_S) reaches a state of SS, from which a marked state of SS can be reached inside SS, so L(AS)⊆M‾L(A_S) \subseteq \overline{M}. The other inclusion is clear, so M‾=L(AS)\overline{M} = L(A_S). Now let s∈M‾s \in \overline{M} and σ∈Σuc\sigma \in \Sigma_{uc} with sσ∈L(G)s\sigma \in L(G). The state x(s)=(h,g)x(s) = (h, g) is in SS, and σ\sigma is defined at gg in GG. Because x(s)x(s) passed the test of line L5, δA(x(s),σ)∈S\delta_A(x(s), \sigma) \in S. So sσ∈L(AS)=M‾s\sigma \in L(A_S) = \overline{M}. ■\blacksquare

Theorem (correctness). The automaton that line L8 returns is trim, its marked language is sup⁡C(K)\sup C(K), and its language is sup⁡C(K)‾\overline{\sup C(K)}.

Proof. By Lemma 3, MM is a controllable sublanguage of KK, so M⊆sup⁡C(K)M \subseteq \sup C(K). Conversely, let s∈sup⁡C(K)s \in \sup C(K). By Lemma 2, every prefix of ss reaches a state of SS, so s∈L(AS)s \in L(A_S). The state x(s)x(s) is marked in AA, because s∈Ks \in K, and it is in SS, so s∈Lm(AS)=Ms \in L_m(A_S) = M. So M=sup⁡C(K)M = \sup C(K), and by Lemma 3 L(AS)=M‾L(A_S) = \overline{M}. ■\blacksquare

Theorem (termination and cost). Let nn be the number of states of AA and q=∣Σ∣q = |\Sigma|. The loop of lines L2 to L7 runs at most n+1n + 1 rounds, and the run takes O(n2q)O(n^2 q) dict operations.

Proof. Line L5 and line L6 only remove states. A round that does not stop at line L7 sets changed, so it removes at least one state. So at most nn rounds change SS, and the next round stops. Line L1 does O(nq)O(n q) work, because each state of AA has at most qq outgoing transitions. In one round, line L5 looks at each transition of GG from the gg part of each state of SS, which is O(nq)O(n q) work, and the two searches of line L6 also take O(nq)O(n q). So the total is O(nq)+(n+1)⋅O(nq)=O(n2q)O(n q) + (n + 1) \cdot O(n q) = O(n^2 q). ■\blacksquare

Complexity

The model is the word RAM with hashing, and nn is the number of states of the product AA (at most ∣XH∣⋅∣XG∣|X_H| \cdot |X_G|), q=∣Σ∣q = |\Sigma|. Each state has at most qq outgoing transitions.

  • Line L1 is a search of the product: O(nq)O(n q).
  • One round: line L5 looks at each event of GG at the gg part of each state of SS, so O(nq)O(n q); line L6 is two searches, O(nq)O(n q).
  • Each round except the last removes at least one state, so there are at most n+1n + 1 rounds.

The total is O(n2q)O(n^2 q) time and O(nq)O(n q) space. The bound is in the size of the product, not of GG and HH alone. In terms of the inputs it is O(∣XH∣2∣XG∣2q)O(|X_H|^2 |X_G|^2 q). This page derives the bound for the program above. The cost of one round can drop with a worklist that, when a state goes, re-tests only its uncontrollable predecessors, but the alternation of the two tests can still need many rounds.

Properties

  • Exact. The result is the supremal controllable sublanguage, not an approximation.
  • Least restrictive. Every other supervisor that keeps the closed loop in KK and is nonblocking has a marked language inside sup⁡C(K)\sup C(K).
  • Regular output. The result is given by a subautomaton of H×GH \times G, so sup⁡C(K)\sup C(K) is regular when KK is.
  • Possibly empty. If the initial state goes, sup⁡C(K)=∅\sup C(K) = \emptyset, and no nonblocking supervisor exists for KK.
  • Marking supervisor. ASA_S also marks strings. With a supervisor that only disables events, the marked closed-loop language is sup⁡C(K)‾∩Lm(G)\overline{\sup C(K)} \cap L_m(G), and it equals sup⁡C(K)\sup C(K) when sup⁡C(K)\sup C(K) is Lm(G)L_m(G)-closed. This holds when KK is Lm(G)L_m(G)-closed, for example when HH marks all its states, as in the example above. If HH marks only some states, use ASA_S as a marking supervisor.

Variants and improvements

  • Prefix-closed specifications. If only safety matters, drop line L6 except the accessibility part. Then one backward search over uncontrollable transitions removes all traps in O(nq)O(n q) time, as for the safety part of a game in reactive synthesis.
  • Partial observation. With unobservable events, the supremal controllable and normal sublanguage replaces it. There is no supremal observable sublanguage in general.
  • Modular and decentralized control. One supervisor per specification avoids the product of all specifications. The modules must then be checked for conflicts, that is, for blocking of the joint closed loop.
  • Symbolic computation. For large plants, the states are encoded with binary decision diagrams, and the fixed point is computed on sets of states, as in symbolic model checking.
  • Petri nets. For nets, supervision based on place invariants adds control places instead of building the reachability graph.

When to use it

Use it when the plant and the specification are finite automata of moderate size, and you want the least restrictive nonblocking supervisor. The product can be large: it is the product of all component machines and all specifications. If the product does not fit in memory, use modular or symbolic methods. If some events are unobservable, compute the supremal controllable and normal sublanguage instead. If the specification is a temporal logic formula, the problem is one of reactive synthesis.

Pitfalls

  • Testing the events of AA instead of GG at line L5. The test "some uncontrollable σ\sigma is defined at xx in AA and leads to a removed state" misses the main case, where GG can do σ\sigma but HH forbids it, so σ\sigma is not defined in AA at all. Line L5 must iterate over the events of GG at gg.
  • Stopping after one round. One pass of line L5 and line L6 is not enough. In the example, round 1 leaves (1,1)(1,1), from which uu leads to a removed state. Line L7 must repeat until a round changes nothing. A test of the implementation checks exactly this case.
  • Trimming without the controllability test, or the reverse. A trim product of HH and GG is nonblocking, but it may not be controllable. A controllable product may block. Both lines L5 and L6 are needed in each round.
  • Marking the product by HH only. A state is marked only if both HH and GG mark it, at line L1. With the marking of HH alone, the target language is Lm(H)∩L(G)L_m(H) \cap L(G), and the plant may be stopped in the middle of a task.

Implementations

Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.

supremal_controllable_sublanguage.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/supremal-controllable-sublanguage/. The authors are listed in prov/1CMXJG.jsonl.

"""The supremal controllable sublanguage of a regular specification.

An automaton is a dict with the keys "init" (the initial state), "delta"
(a dict that maps (state, event) to the next state, so the automaton is
deterministic and partial) and "marked" (a set of states). The plant is G,
the specification is H, and K = Lm(H) & Lm(G) is the target language.

supremal_controllable(g, h, uncontrollable) returns a trim automaton A with
Lm(A) = sup C(K) and L(A) = prefix(sup C(K)), where sup C is taken with
respect to L(G) and the set of uncontrollable events. The states of A are
pairs (h, g) of the product H x G. If sup C(K) is empty, A has no states and
its "init" is None.

Cost, with N = |Q_H| |Q_G| product states and an alphabet of size E: the
product takes O(N E) dict operations, one round of the loop takes O(N E),
and there are at most N + 1 rounds, so O(N^2 E) in total.
"""

from collections import deque
from typing import Hashable, Iterable

Automaton = dict


def out_edges(delta: dict) -> dict:
    """Map each state to a dict {event: next state}."""
    out: dict = {}
    for (q, e), r in delta.items():
        out.setdefault(q, {})[e] = r
    return out


def product(h: Automaton, g: Automaton) -> Automaton:
    """The accessible part of H x G, synchronized on every event."""
    eh, eg = out_edges(h["delta"]), out_edges(g["delta"])
    init = (h["init"], g["init"])
    states = {init}
    delta = {}
    queue = deque([init])
    while queue:
        x = queue.popleft()
        for e, g2 in eg.get(x[1], {}).items():
            h2 = eh.get(x[0], {}).get(e)
            if h2 is None:
                continue
            y = (h2, g2)
            delta[(x, e)] = y
            if y not in states:
                states.add(y)
                queue.append(y)
    marked = {x for x in states if x[0] in h["marked"] and x[1] in g["marked"]}
    return {"init": init, "states": states, "delta": delta, "marked": marked}


def trim(states: set, out: dict, init: Hashable, marked: set) -> set:
    """The states of `states` that are accessible from init and coaccessible to a marked state, inside `states`."""
    if init not in states:
        return set()
    acc = {init}
    stack = [init]
    while stack:
        x = stack.pop()
        for y in out.get(x, {}).values():
            if y in states and y not in acc:
                acc.add(y)
                stack.append(y)
    back: dict = {}
    for x in acc:
        for y in out.get(x, {}).values():
            if y in acc:
                back.setdefault(y, []).append(x)
    co = {x for x in acc if x in marked}
    stack = list(co)
    while stack:
        y = stack.pop()
        for x in back.get(y, []):
            if x not in co:
                co.add(x)
                stack.append(x)
    return co


def restrict(a: Automaton, states: set) -> Automaton:
    """The sub-automaton of a on the given states."""
    delta = {(x, e): y for (x, e), y in a["delta"].items() if x in states and y in states}
    init = a["init"] if a["init"] in states else None
    return {"init": init, "states": set(states), "delta": delta, "marked": a["marked"] & states}


def supremal_controllable(g: Automaton, h: Automaton, uncontrollable: Iterable) -> Automaton:
    """A trim automaton for sup C(Lm(H) & Lm(G)) with respect to L(G) and the uncontrollable events."""
    unc = set(uncontrollable)
    a = product(h, g)  # @line L1
    out = out_edges(a["delta"])
    plant = out_edges(g["delta"])
    states = set(a["states"])
    while True:  # @line L2
        changed = False  # @line L3
        for x in list(states):  # @line L4
            for e in plant.get(x[1], {}):
                if e in unc and out.get(x, {}).get(e) not in states:  # @line L5
                    states.discard(x)
                    changed = True
                    break
        kept = trim(states, out, a["init"], a["marked"])  # @line L6
        if kept != states:
            states = kept
            changed = True
        if not changed:  # @line L7
            break
    return restrict(a, states)  # @line L8


def disabled_events(sup: Automaton, g: Automaton) -> dict:
    """For each state (h, g) of sup, the events that G allows at g and the supervisor disables."""
    plant = out_edges(g["delta"])
    out = out_edges(sup["delta"])
    return {x: {e for e in plant.get(x[1], {}) if e not in out.get(x, {})} for x in sup["states"]}
test_supremal_controllable_sublanguage.py 229 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/supremal-controllable-sublanguage/. The authors are listed in prov/1CMXJG.jsonl.

import random

from supremal_controllable_sublanguage import disabled_events, product, supremal_controllable


def step(a, q, e):
    return a["delta"].get((q, e))


def strings_of(a, events, length):
    """All strings s with |s| <= length in L(a), each with the state it reaches."""
    if a["init"] is None:
        return []
    out = [((), a["init"])]
    frontier = [((), a["init"])]
    for _ in range(length):
        nxt = []
        for s, q in frontier:
            for e in events:
                r = step(a, q, e)
                if r is not None:
                    nxt.append((s + (e,), r))
        out.extend(nxt)
        frontier = nxt
    return out


def run(a, s):
    q = a["init"]
    for e in s:
        if q is None:
            return None
        q = step(a, q, e)
    return q


def reach(states, succ, start):
    seen = {start} if start in states else set()
    stack = list(seen)
    while stack:
        x = stack.pop()
        for y in succ(x):
            if y in states and y not in seen:
                seen.add(y)
                stack.append(y)
    return seen


def brute_sup_states(g, h, unc, events):
    """The union of all sets X of product states whose restriction is trim and has no bad state."""
    a = product(h, g)
    order = sorted(a["states"], key=repr)
    succ = {x: [a["delta"][(x, e)] for e in events if (x, e) in a["delta"]] for x in order}
    pred = {x: [] for x in order}
    for x in order:
        for y in succ[x]:
            pred[y].append(x)
    best = set()
    for mask in range(1, 1 << len(order)):
        xs = {order[i] for i in range(len(order)) if mask >> i & 1}
        if a["init"] not in xs:
            continue
        if reach(xs, lambda x: succ[x], a["init"]) != xs:
            continue
        co = set()
        for m in xs & a["marked"]:
            co |= reach(xs, lambda x: pred[x], m)
        if co != xs:
            continue
        ok = True
        for x in xs:
            for e in unc:
                if (x[1], e) in g["delta"] and a["delta"].get((x, e)) not in xs:
                    ok = False
        if ok:
            best |= xs
    return best


def random_automaton(rng, n, events, p=0.55, pm=0.5):
    delta = {(q, e): rng.randrange(n) for q in range(n) for e in events if rng.random() < p}
    marked = {q for q in range(n) if rng.random() < pm} or {rng.randrange(n)}
    return {"init": 0, "delta": delta, "marked": marked}


def check_string_level(g, h, unc, sup, events, length):
    """L(sup) is in L(G), Lm(sup) is in Lm(H) & Lm(G), and L(sup) is controllable, on all strings up to `length`."""
    for s, q in strings_of(sup, events, length):
        gq, hq = run(g, s), run(h, s)
        assert gq is not None and hq is not None
        if q in sup["marked"]:
            assert gq in g["marked"] and hq in h["marked"]
        if len(s) < length:
            for e in unc:
                if step(g, gq, e) is not None:
                    assert step(sup, q, e) is not None


def nonblocking(sup):
    if sup["init"] is None:
        return True
    succ = {}
    for (x, _), y in sup["delta"].items():
        succ.setdefault(x, []).append(y)
    for x in sup["states"]:
        seen = reach(sup["states"], lambda z: succ.get(z, []), x)
        if not seen & sup["marked"]:
            return False
    return True


def factory():
    d = {}
    for m1 in "IW":
        for m2 in "IW":
            s = m1 + m2
            if m1 == "I":
                d[(s, "a1")] = "W" + m2
            else:
                d[(s, "b1")] = "I" + m2
            if m2 == "I":
                d[(s, "a2")] = m1 + "W"
            else:
                d[(s, "b2")] = m1 + "I"
    g = {"init": "II", "delta": d, "marked": {"II"}}
    h = {"init": 0, "delta": {(0, "b1"): 1, (1, "a2"): 0, (0, "a1"): 0, (1, "a1"): 1, (0, "b2"): 0, (1, "b2"): 1}, "marked": {0}}
    return g, h


def three_round():
    gd = {(0, "a"): 1, (1, "u"): 2, (2, "b"): 3, (3, "v"): 4, (4, "d"): 0, (0, "e"): 0, (1, "c"): 0}
    g = {"init": 0, "delta": gd, "marked": {0}}
    h = {"init": 0, "delta": {k: v for k, v in gd.items() if k[1] != "v"}, "marked": {0, 1, 2, 3, 4}}
    return g, h


def test_page_example_three_rounds():
    g, h = three_round()
    sup = supremal_controllable(g, h, {"u", "v"})
    assert sup["states"] == {(0, 0)}
    assert sup["delta"] == {((0, 0), "e"): (0, 0)}
    marked = [s for s, q in strings_of(sup, "abcdeuv", 8) if q in sup["marked"]]
    assert sorted(marked) == [("e",) * k for k in range(9)]


def test_one_round_without_retrim_is_not_enough():
    g, h = three_round()
    a = product(h, g)
    keep = {x for x in a["states"] if x != (3, 3) and x != (2, 2)}
    one_round = {"init": a["init"], "states": keep, "marked": a["marked"] & keep,
                 "delta": {(x, e): y for (x, e), y in a["delta"].items() if x in keep and y in keep}}
    s = ("a",)
    assert run(one_round, s) is not None and step(g, run(g, s), "u") is not None
    assert step(one_round, run(one_round, s), "u") is None


def test_factory_buffer():
    g, h = factory()
    sup = supremal_controllable(g, h, {"b1", "b2"})
    assert len(product(h, g)["states"]) == 8
    assert sup["states"] == {(0, "II"), (0, "IW"), (0, "WI"), (0, "WW"), (1, "II"), (1, "IW")}
    assert len(sup["delta"]) == 8
    dis = disabled_events(sup, g)
    assert dis[(1, "II")] == {"a1"} and dis[(1, "IW")] == {"a1"}
    assert dis[(0, "II")] == {"a2"} and dis[(0, "WI")] == {"a2"}
    assert nonblocking(sup)
    check_string_level(g, h, {"b1", "b2"}, sup, ["a1", "b1", "a2", "b2"], 8)


def test_empty_result():
    g = {"init": 0, "delta": {(0, "u"): 1, (1, "a"): 0}, "marked": {0, 1}}
    h = {"init": 0, "delta": {(0, "a"): 0}, "marked": {0}}
    sup = supremal_controllable(g, h, {"u"})
    assert sup["init"] is None and sup["states"] == set() and sup["delta"] == {}


def test_all_controllable_gives_trim_product():
    rng = random.Random(7)
    for _ in range(100):
        g = random_automaton(rng, 3, "abc")
        h = random_automaton(rng, 2, "abc")
        sup = supremal_controllable(g, h, set())
        a = product(h, g)
        assert sup["states"] == brute_sup_states(g, h, set(), "abc")
        assert sup["states"] <= a["states"]


def test_random_against_subset_brute_force():
    rng = random.Random(2024)
    events = ["a", "b", "c", "u"]
    unc = {"u"}
    strict = 0
    for _ in range(1500):
        g = random_automaton(rng, 3, events, p=0.6, pm=0.5)
        h = random_automaton(rng, 3, events, p=0.8, pm=0.6)
        sup = supremal_controllable(g, h, unc)
        assert sup["states"] == brute_sup_states(g, h, unc, events)
        assert nonblocking(sup)
        strict += 0 < len(sup["states"]) < len(product(h, g)["states"])
    assert strict >= 100


def test_random_two_uncontrollable_events():
    rng = random.Random(31)
    events = ["a", "b", "u", "v"]
    unc = {"u", "v"}
    for _ in range(500):
        g = random_automaton(rng, 3, events)
        h = random_automaton(rng, 2, events)
        sup = supremal_controllable(g, h, unc)
        assert sup["states"] == brute_sup_states(g, h, unc, events)
        assert nonblocking(sup)


def test_random_strings_up_to_length_8():
    rng = random.Random(99)
    events = ["a", "b", "u"]
    unc = {"u"}
    nonempty = 0
    for _ in range(60):
        g = random_automaton(rng, 3, events, p=0.5)
        h = random_automaton(rng, 3, events, p=0.6)
        sup = supremal_controllable(g, h, unc)
        check_string_level(g, h, unc, sup, events, 8)
        nonempty += sup["init"] is not None
    assert nonempty >= 10

History

Ramadge and Wonham introduced controllable languages and supervisors in 1987, in the SIAM Journal on Control and Optimization. In the same volume, Wonham and Ramadge proved that the supremal controllable sublanguage exists, that it is the largest fixpoint of a monotone operator, and that it can be computed for regular languages. The computation on the product automaton became the standard tool of the theory, and the TCT program of Wonham's group implements it.

References

  1. W. M. Wonham and P. J. Ramadge, On the supremal controllable sublanguage of a given language, SIAM Journal on Control and Optimization 25(3), 1987, pages 637 to 659, the existence of the supremal controllable sublanguage, its characterization as the largest fixpoint of a monotone operator, and its computation for regular languages
  2. P. J. Ramadge and W. M. Wonham, Supervisory control of a class of discrete event processes, SIAM Journal on Control and Optimization 25(1), 1987, pages 206 to 230, controllability and the existence of supervisors
  3. Christos G. Cassandras and Stéphane Lafortune, Introduction to Discrete Event Systems, third edition, Springer, 2021, Chapter 3, Supervisory Control (the supremal controllable sublanguage and its computation on automata)
  4. W. Murray Wonham and Kai Cai, Supervisory Control of Discrete-Event Systems, Springer, 2019, Chapter 3, Supervision of Discrete-Event Systems, Basics

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH1 sketch
  • a full proof of time.worst
  • a full proof of space.extra
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • a scene preset for the example