FA-67291 / Railway interlocking logic / Open access
Flank protection selection: held signal list · case 01
The held signal list repeats a signal or is out of order.
ROOT CAUSE
Held signals are returned in discovery order with duplicates.
VERIFIED REPAIR
Return held signals sorted and unique.
Unsuccessful approach: Sorting without deduplication still repeats a signal held for two flank points.
Case contract
For each route point (sorted) in its lie, the flank table (key point+lie) lists flank points with the protecting lie and an optional flank signal. A flank point is set to its protecting lie if it is free, locked in that lie by another route, or already demanded in that lie by this route; if it is unavailable, its flank signal is held at danger when the signal exists and is holdable; otherwise the route is refused (refused:<flank point>, nothing set or held). Held signals are returned sorted and unique.
Why this case matters
Interlocking logic decides whether trains may be given authority; a wrong decision at this point either grants unsafe movements or strands traffic.
1 / The failure
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(x):
set_pts = {}
held = []
locks = x['point_locks']
for p, pos in sorted(x['route_points'].items()):
for fp, fpos, fsig in x['flank'].get(p + pos, []):
lk = locks.get(fp, set_pts.get(fp))
if lk is None or lk == fpos:
set_pts[fp] = fpos
elif fsig is not None and fsig in x['holdable']:
held.append(fsig)
else:
return {'result': 'refused:' + fp, 'set_points': {}, 'held_signals': []}
return {'result': 'protected', 'set_points': set_pts, 'held_signals': held}
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: same signal held twice', {'route_points': {'P1': 'N', 'P2': 'N'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P7': 'N', 'P8': 'N', 'P9': 'N'}, 'holdable': ['S20', 'S22']}, {'result': 'protected', 'set_points': {'P8': 'N'}, 'held_signals': ['S20', 'S22']}), ('boundary: flank point locked in the protecting lie', {'route_points': {'P1': 'N'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P7': 'R'}, 'holdable': ['S20', 'S21', 'S22', 'S23', 'S24']}, {'result': 'protected', 'set_points': {'P7': 'R', 'P8': 'N'}, 'held_signals': []}), ('boundary: flank point free', {'route_points': {'P1': 'N'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {}, 'holdable': ['S20', 'S21', 'S22', 'S23', 'S24']}, {'result': 'protected', 'set_points': {'P7': 'R', 'P8': 'N'}, 'held_signals': []}), ('boundary: two route points disagree on a flank point', {'route_points': {'P1': 'R', 'P2': 'R'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {}, 'holdable': ['S20', 'S21', 'S22', 'S23', 'S24']}, {'result': 'protected', 'set_points': {'P7': 'N', 'P9': 'N'}, 'held_signals': []}), ('boundary: flank signal not holdable', {'route_points': {'P1': 'R'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P7': 'R'}, 'holdable': []}, {'result': 'refused:P7', 'set_points': {}, 'held_signals': []}), ('control 1', {'route_points': {'P3': 'N'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P7': 'R', 'P9': 'N'}, 'holdable': ['S23', 'S24']}, {'result': 'refused:P9', 'set_points': {}, 'held_signals': []}), ('control 4', {'route_points': {'P2': 'R'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {}, 'holdable': ['S21', 'S22']}, {'result': 'protected', 'set_points': {'P9': 'N', 'P7': 'N'}, 'held_signals': []}), ('control 7', {'route_points': {'P2': 'R', 'P1': 'R', 'P3': 'N'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P7': 'R', 'P8': 'R', 'P9': 'R'}, 'holdable': ['S22', 'S24']}, {'result': 'refused:P7', 'set_points': {}, 'held_signals': []})], [('regression: same signal held twice', {'route_points': {'P1': 'N', 'P2': 'N'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P7': 'N', 'P8': 'N', 'P9': 'N'}, 'holdable': ['S20', 'S22']}, {'result': 'protected', 'set_points': {'P8': 'N'}, 'held_signals': ['S20', 'S22']}), ('boundary: two route points disagree on a flank point', {'route_points': {'P1': 'R', 'P2': 'R'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {}, 'holdable': ['S20', 'S21', 'S22', 'S23', 'S24']}, {'result': 'protected', 'set_points': {'P7': 'N', 'P9': 'N'}, 'held_signals': []}), ('boundary: flank signal not holdable', {'route_points': {'P1': 'R'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P7': 'R'}, 'holdable': []}, {'result': 'refused:P7', 'set_points': {}, 'held_signals': []}), ('boundary: no flank signal available', {'route_points': {'P3': 'N'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P9': 'N'}, 'holdable': ['S20', 'S21', 'S22', 'S23', 'S24']}, {'result': 'refused:P9', 'set_points': {}, 'held_signals': []}), ('boundary: reverse lie flank entry', {'route_points': {'P2': 'R'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P9': 'R'}, 'holdable': ['S20', 'S21', 'S22', 'S23', 'S24']}, {'result': 'protected', 'set_points': {'P7': 'N'}, 'held_signals': ['S23']}), ('control 12', {'route_points': {'P1': 'R', 'P3': 'R'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {}, 'holdable': ['S21', 'S22', 'S24']}, {'result': 'protected', 'set_points': {'P7': 'N', 'P8': 'N'}, 'held_signals': []}), ('control 15', {'route_points': {'P1': 'R'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P9': 'N'}, 'holdable': ['S24']}, {'result': 'protected', 'set_points': {'P7': 'N'}, 'held_signals': []}), ('control 18', {'route_points': {'P3': 'R', 'P1': 'R', 'P2': 'R'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P7': 'N', 'P9': 'N'}, 'holdable': ['S22', 'S23', 'S24']}, {'result': 'protected', 'set_points': {'P7': 'N', 'P9': 'N', 'P8': 'N'}, 'held_signals': []})], [('regression: same signal held twice', {'route_points': {'P1': 'N', 'P2': 'N'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P7': 'N', 'P8': 'N', 'P9': 'N'}, 'holdable': ['S20', 'S22']}, {'result': 'protected', 'set_points': {'P8': 'N'}, 'held_signals': ['S20', 'S22']}), ('boundary: no flank signal available', {'route_points': {'P3': 'N'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P9': 'N'}, 'holdable': ['S20', 'S21', 'S22', 'S23', 'S24']}, {'result': 'refused:P9', 'set_points': {}, 'held_signals': []}), ('boundary: reverse lie flank entry', {'route_points': {'P2': 'R'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P9': 'R'}, 'holdable': ['S20', 'S21', 'S22', 'S23', 'S24']}, {'result': 'protected', 'set_points': {'P7': 'N'}, 'held_signals': ['S23']}), ('boundary: own conflicting demand with a holdable signal', {'route_points': {'P1': 'R', 'P2': 'R'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {}, 'holdable': ['S21', 'S23']}, {'result': 'protected', 'set_points': {'P7': 'N', 'P9': 'N'}, 'held_signals': []}), ('boundary: own conflicting demand without a signal', {'route_points': {'P1': 'N', 'P2': 'R'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {}, 'holdable': ['S20', 'S21', 'S22', 'S23', 'S24']}, {'result': 'refused:P7', 'set_points': {}, 'held_signals': []}), ('control 23', {'route_points': {'P1': 'R', 'P2': 'N', 'P3': 'R'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {}, 'holdable': ['S20', 'S21', 'S22', 'S24']}, {'result': 'protected', 'set_points': {'P7': 'N', 'P8': 'R', 'P9': 'R'}, 'held_signals': ['S24']}), ('control 26', {'route_points': {'P3': 'N'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P7': 'R', 'P8': 'N'}, 'holdable': ['S20', 'S21', 'S22', 'S23', 'S24']}, {'result': 'protected', 'set_points': {'P9': 'R'}, 'held_signals': []}), ('control 29', {'route_points': {'P1': 'R', 'P2': 'R'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P9': 'R'}, 'holdable': ['S20', 'S23']}, {'result': 'protected', 'set_points': {'P7': 'N'}, 'held_signals': ['S23']})], [('regression: same signal held twice', {'route_points': {'P1': 'N', 'P2': 'N'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P7': 'N', 'P8': 'N', 'P9': 'N'}, 'holdable': ['S20', 'S22']}, {'result': 'protected', 'set_points': {'P8': 'N'}, 'held_signals': ['S20', 'S22']}), ('boundary: own conflicting demand with a holdable signal', {'route_points': {'P1': 'R', 'P2': 'R'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {}, 'holdable': ['S21', 'S23']}, {'result': 'protected', 'set_points': {'P7': 'N', 'P9': 'N'}, 'held_signals': []}), ('boundary: own conflicting demand without a signal', {'route_points': {'P1': 'N', 'P2': 'R'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {}, 'holdable': ['S20', 'S21', 'S22', 'S23', 'S24']}, {'result': 'refused:P7', 'set_points': {}, 'held_signals': []}), ('boundary: flank point locked in the protecting lie', {'route_points': {'P1': 'N'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P7': 'R'}, 'holdable': ['S20', 'S21', 'S22', 'S23', 'S24']}, {'result': 'protected', 'set_points': {'P7': 'R', 'P8': 'N'}, 'held_signals': []}), ('boundary: flank point free', {'route_points': {'P1': 'N'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {}, 'holdable': ['S20', 'S21', 'S22', 'S23', 'S24']}, {'result': 'protected', 'set_points': {'P7': 'R', 'P8': 'N'}, 'held_signals': []}), ('control 34', {'route_points': {'P3': 'R', 'P2': 'N'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P7': 'R', 'P9': 'N'}, 'holdable': ['S20', 'S21', 'S24']}, {'result': 'protected', 'set_points': {'P8': 'R'}, 'held_signals': ['S20', 'S24']}), ('control 37', {'route_points': {'P2': 'N', 'P1': 'R', 'P3': 'N'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P8': 'R'}, 'holdable': ['S21', 'S24']}, {'result': 'protected', 'set_points': {'P7': 'N', 'P8': 'R', 'P9': 'R'}, 'held_signals': []}), ('control 40', {'route_points': {'P3': 'R', 'P1': 'R'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {}, 'holdable': ['S20', 'S21', 'S22', 'S24']}, {'result': 'protected', 'set_points': {'P7': 'N', 'P8': 'N'}, 'held_signals': []})], [('regression: same signal held twice', {'route_points': {'P1': 'N', 'P2': 'N'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P7': 'N', 'P8': 'N', 'P9': 'N'}, 'holdable': ['S20', 'S22']}, {'result': 'protected', 'set_points': {'P8': 'N'}, 'held_signals': ['S20', 'S22']}), ('boundary: own conflicting demand without a signal', {'route_points': {'P1': 'N', 'P2': 'R'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {}, 'holdable': ['S20', 'S21', 'S22', 'S23', 'S24']}, {'result': 'refused:P7', 'set_points': {}, 'held_signals': []}), ('boundary: flank point locked in the protecting lie', {'route_points': {'P1': 'N'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P7': 'R'}, 'holdable': ['S20', 'S21', 'S22', 'S23', 'S24']}, {'result': 'protected', 'set_points': {'P7': 'R', 'P8': 'N'}, 'held_signals': []}), ('boundary: flank point free', {'route_points': {'P1': 'N'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {}, 'holdable': ['S20', 'S21', 'S22', 'S23', 'S24']}, {'result': 'protected', 'set_points': {'P7': 'R', 'P8': 'N'}, 'held_signals': []}), ('boundary: two route points disagree on a flank point', {'route_points': {'P1': 'R', 'P2': 'R'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {}, 'holdable': ['S20', 'S21', 'S22', 'S23', 'S24']}, {'result': 'protected', 'set_points': {'P7': 'N', 'P9': 'N'}, 'held_signals': []}), ('control 45', {'route_points': {'P2': 'N', 'P1': 'N', 'P3': 'R'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P7': 'R', 'P8': 'R'}, 'holdable': ['S20', 'S21', 'S23', 'S24']}, {'result': 'refused:P8', 'set_points': {}, 'held_signals': []}), ('control 48', {'route_points': {'P2': 'R', 'P3': 'R'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P7': 'N', 'P8': 'N'}, 'holdable': ['S20', 'S21', 'S22']}, {'result': 'protected', 'set_points': {'P9': 'N', 'P7': 'N', 'P8': 'N'}, 'held_signals': []}), ('control 51', {'route_points': {'P3': 'N', 'P2': 'R'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P9': 'R'}, 'holdable': ['S20', 'S21', 'S22', 'S23', 'S24']}, {'result': 'protected', 'set_points': {'P7': 'N', 'P9': 'R'}, 'held_signals': ['S23']})]]
for label, args, expected in fixtures[N-1]:
check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| regression: same signal held twice | {'held_signals': ['S20', 'S22', 'S20'], 'result': 'protected', 'set_points': {'P8': 'N'}} | {'held_signals': ['S20', 'S22'], 'result': 'protected', 'set_points': {'P8': 'N'}} | Failed |
| boundary: flank point locked in the protecting lie | {'held_signals': [], 'result': 'protected', 'set_points': {'P7': 'R', 'P8': 'N'}} | {'held_signals': [], 'result': 'protected', 'set_points': {'P7': 'R', 'P8': 'N'}} | Passed |
| boundary: flank point free | {'held_signals': [], 'result': 'protected', 'set_points': {'P7': 'R', 'P8': 'N'}} | {'held_signals': [], 'result': 'protected', 'set_points': {'P7': 'R', 'P8': 'N'}} | Passed |
| boundary: two route points disagree on a flank point | {'held_signals': [], 'result': 'protected', 'set_points': {'P7': 'N', 'P9': 'N'}} | {'held_signals': [], 'result': 'protected', 'set_points': {'P7': 'N', 'P9': 'N'}} | Passed |
| boundary: flank signal not holdable | {'held_signals': [], 'result': 'refused:P7', 'set_points': {}} | {'held_signals': [], 'result': 'refused:P7', 'set_points': {}} | Passed |
| control 1 | {'held_signals': [], 'result': 'refused:P9', 'set_points': {}} | {'held_signals': [], 'result': 'refused:P9', 'set_points': {}} | Passed |
| control 4 | {'held_signals': [], 'result': 'protected', 'set_points': {'P7': 'N', 'P9': 'N'}} | {'held_signals': [], 'result': 'protected', 'set_points': {'P7': 'N', 'P9': 'N'}} | Passed |
| control 7 | {'held_signals': [], 'result': 'refused:P7', 'set_points': {}} | {'held_signals': [], 'result': 'refused:P7', 'set_points': {}} | Passed |
SHA-256 / e0a126724958b548baef3a2fb6c8596397fe2b2355b2b9ec13e86a72cd7a9f33
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(x):
set_pts = {}
held = []
locks = x['point_locks']
for p, pos in sorted(x['route_points'].items()):
for fp, fpos, fsig in x['flank'].get(p + pos, []):
lk = locks.get(fp, set_pts.get(fp))
if lk is None or lk == fpos:
set_pts[fp] = fpos
elif fsig is not None and fsig in x['holdable']:
held.append(fsig)
else:
return {'result': 'refused:' + fp, 'set_points': {}, 'held_signals': []}
return {'result': 'protected', 'set_points': set_pts, 'held_signals': sorted(held)}
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: same signal held twice', {'route_points': {'P1': 'N', 'P2': 'N'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P7': 'N', 'P8': 'N', 'P9': 'N'}, 'holdable': ['S20', 'S22']}, {'result': 'protected', 'set_points': {'P8': 'N'}, 'held_signals': ['S20', 'S22']}), ('boundary: flank point locked in the protecting lie', {'route_points': {'P1': 'N'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P7': 'R'}, 'holdable': ['S20', 'S21', 'S22', 'S23', 'S24']}, {'result': 'protected', 'set_points': {'P7': 'R', 'P8': 'N'}, 'held_signals': []}), ('boundary: flank point free', {'route_points': {'P1': 'N'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {}, 'holdable': ['S20', 'S21', 'S22', 'S23', 'S24']}, {'result': 'protected', 'set_points': {'P7': 'R', 'P8': 'N'}, 'held_signals': []}), ('boundary: two route points disagree on a flank point', {'route_points': {'P1': 'R', 'P2': 'R'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {}, 'holdable': ['S20', 'S21', 'S22', 'S23', 'S24']}, {'result': 'protected', 'set_points': {'P7': 'N', 'P9': 'N'}, 'held_signals': []}), ('boundary: flank signal not holdable', {'route_points': {'P1': 'R'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P7': 'R'}, 'holdable': []}, {'result': 'refused:P7', 'set_points': {}, 'held_signals': []}), ('control 1', {'route_points': {'P3': 'N'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P7': 'R', 'P9': 'N'}, 'holdable': ['S23', 'S24']}, {'result': 'refused:P9', 'set_points': {}, 'held_signals': []}), ('control 4', {'route_points': {'P2': 'R'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {}, 'holdable': ['S21', 'S22']}, {'result': 'protected', 'set_points': {'P9': 'N', 'P7': 'N'}, 'held_signals': []}), ('control 7', {'route_points': {'P2': 'R', 'P1': 'R', 'P3': 'N'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P7': 'R', 'P8': 'R', 'P9': 'R'}, 'holdable': ['S22', 'S24']}, {'result': 'refused:P7', 'set_points': {}, 'held_signals': []})], [('regression: same signal held twice', {'route_points': {'P1': 'N', 'P2': 'N'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P7': 'N', 'P8': 'N', 'P9': 'N'}, 'holdable': ['S20', 'S22']}, {'result': 'protected', 'set_points': {'P8': 'N'}, 'held_signals': ['S20', 'S22']}), ('boundary: two route points disagree on a flank point', {'route_points': {'P1': 'R', 'P2': 'R'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {}, 'holdable': ['S20', 'S21', 'S22', 'S23', 'S24']}, {'result': 'protected', 'set_points': {'P7': 'N', 'P9': 'N'}, 'held_signals': []}), ('boundary: flank signal not holdable', {'route_points': {'P1': 'R'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P7': 'R'}, 'holdable': []}, {'result': 'refused:P7', 'set_points': {}, 'held_signals': []}), ('boundary: no flank signal available', {'route_points': {'P3': 'N'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P9': 'N'}, 'holdable': ['S20', 'S21', 'S22', 'S23', 'S24']}, {'result': 'refused:P9', 'set_points': {}, 'held_signals': []}), ('boundary: reverse lie flank entry', {'route_points': {'P2': 'R'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P9': 'R'}, 'holdable': ['S20', 'S21', 'S22', 'S23', 'S24']}, {'result': 'protected', 'set_points': {'P7': 'N'}, 'held_signals': ['S23']}), ('control 12', {'route_points': {'P1': 'R', 'P3': 'R'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {}, 'holdable': ['S21', 'S22', 'S24']}, {'result': 'protected', 'set_points': {'P7': 'N', 'P8': 'N'}, 'held_signals': []}), ('control 15', {'route_points': {'P1': 'R'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P9': 'N'}, 'holdable': ['S24']}, {'result': 'protected', 'set_points': {'P7': 'N'}, 'held_signals': []}), ('control 18', {'route_points': {'P3': 'R', 'P1': 'R', 'P2': 'R'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P7': 'N', 'P9': 'N'}, 'holdable': ['S22', 'S23', 'S24']}, {'result': 'protected', 'set_points': {'P7': 'N', 'P9': 'N', 'P8': 'N'}, 'held_signals': []})], [('regression: same signal held twice', {'route_points': {'P1': 'N', 'P2': 'N'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P7': 'N', 'P8': 'N', 'P9': 'N'}, 'holdable': ['S20', 'S22']}, {'result': 'protected', 'set_points': {'P8': 'N'}, 'held_signals': ['S20', 'S22']}), ('boundary: no flank signal available', {'route_points': {'P3': 'N'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P9': 'N'}, 'holdable': ['S20', 'S21', 'S22', 'S23', 'S24']}, {'result': 'refused:P9', 'set_points': {}, 'held_signals': []}), ('boundary: reverse lie flank entry', {'route_points': {'P2': 'R'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P9': 'R'}, 'holdable': ['S20', 'S21', 'S22', 'S23', 'S24']}, {'result': 'protected', 'set_points': {'P7': 'N'}, 'held_signals': ['S23']}), ('boundary: own conflicting demand with a holdable signal', {'route_points': {'P1': 'R', 'P2': 'R'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {}, 'holdable': ['S21', 'S23']}, {'result': 'protected', 'set_points': {'P7': 'N', 'P9': 'N'}, 'held_signals': []}), ('boundary: own conflicting demand without a signal', {'route_points': {'P1': 'N', 'P2': 'R'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {}, 'holdable': ['S20', 'S21', 'S22', 'S23', 'S24']}, {'result': 'refused:P7', 'set_points': {}, 'held_signals': []}), ('control 23', {'route_points': {'P1': 'R', 'P2': 'N', 'P3': 'R'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {}, 'holdable': ['S20', 'S21', 'S22', 'S24']}, {'result': 'protected', 'set_points': {'P7': 'N', 'P8': 'R', 'P9': 'R'}, 'held_signals': ['S24']}), ('control 26', {'route_points': {'P3': 'N'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P7': 'R', 'P8': 'N'}, 'holdable': ['S20', 'S21', 'S22', 'S23', 'S24']}, {'result': 'protected', 'set_points': {'P9': 'R'}, 'held_signals': []}), ('control 29', {'route_points': {'P1': 'R', 'P2': 'R'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P9': 'R'}, 'holdable': ['S20', 'S23']}, {'result': 'protected', 'set_points': {'P7': 'N'}, 'held_signals': ['S23']})], [('regression: same signal held twice', {'route_points': {'P1': 'N', 'P2': 'N'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P7': 'N', 'P8': 'N', 'P9': 'N'}, 'holdable': ['S20', 'S22']}, {'result': 'protected', 'set_points': {'P8': 'N'}, 'held_signals': ['S20', 'S22']}), ('boundary: own conflicting demand with a holdable signal', {'route_points': {'P1': 'R', 'P2': 'R'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {}, 'holdable': ['S21', 'S23']}, {'result': 'protected', 'set_points': {'P7': 'N', 'P9': 'N'}, 'held_signals': []}), ('boundary: own conflicting demand without a signal', {'route_points': {'P1': 'N', 'P2': 'R'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {}, 'holdable': ['S20', 'S21', 'S22', 'S23', 'S24']}, {'result': 'refused:P7', 'set_points': {}, 'held_signals': []}), ('boundary: flank point locked in the protecting lie', {'route_points': {'P1': 'N'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P7': 'R'}, 'holdable': ['S20', 'S21', 'S22', 'S23', 'S24']}, {'result': 'protected', 'set_points': {'P7': 'R', 'P8': 'N'}, 'held_signals': []}), ('boundary: flank point free', {'route_points': {'P1': 'N'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {}, 'holdable': ['S20', 'S21', 'S22', 'S23', 'S24']}, {'result': 'protected', 'set_points': {'P7': 'R', 'P8': 'N'}, 'held_signals': []}), ('control 34', {'route_points': {'P3': 'R', 'P2': 'N'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P7': 'R', 'P9': 'N'}, 'holdable': ['S20', 'S21', 'S24']}, {'result': 'protected', 'set_points': {'P8': 'R'}, 'held_signals': ['S20', 'S24']}), ('control 37', {'route_points': {'P2': 'N', 'P1': 'R', 'P3': 'N'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P8': 'R'}, 'holdable': ['S21', 'S24']}, {'result': 'protected', 'set_points': {'P7': 'N', 'P8': 'R', 'P9': 'R'}, 'held_signals': []}), ('control 40', {'route_points': {'P3': 'R', 'P1': 'R'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {}, 'holdable': ['S20', 'S21', 'S22', 'S24']}, {'result': 'protected', 'set_points': {'P7': 'N', 'P8': 'N'}, 'held_signals': []})], [('regression: same signal held twice', {'route_points': {'P1': 'N', 'P2': 'N'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P7': 'N', 'P8': 'N', 'P9': 'N'}, 'holdable': ['S20', 'S22']}, {'result': 'protected', 'set_points': {'P8': 'N'}, 'held_signals': ['S20', 'S22']}), ('boundary: own conflicting demand without a signal', {'route_points': {'P1': 'N', 'P2': 'R'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {}, 'holdable': ['S20', 'S21', 'S22', 'S23', 'S24']}, {'result': 'refused:P7', 'set_points': {}, 'held_signals': []}), ('boundary: flank point locked in the protecting lie', {'route_points': {'P1': 'N'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P7': 'R'}, 'holdable': ['S20', 'S21', 'S22', 'S23', 'S24']}, {'result': 'protected', 'set_points': {'P7': 'R', 'P8': 'N'}, 'held_signals': []}), ('boundary: flank point free', {'route_points': {'P1': 'N'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {}, 'holdable': ['S20', 'S21', 'S22', 'S23', 'S24']}, {'result': 'protected', 'set_points': {'P7': 'R', 'P8': 'N'}, 'held_signals': []}), ('boundary: two route points disagree on a flank point', {'route_points': {'P1': 'R', 'P2': 'R'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {}, 'holdable': ['S20', 'S21', 'S22', 'S23', 'S24']}, {'result': 'protected', 'set_points': {'P7': 'N', 'P9': 'N'}, 'held_signals': []}), ('control 45', {'route_points': {'P2': 'N', 'P1': 'N', 'P3': 'R'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P7': 'R', 'P8': 'R'}, 'holdable': ['S20', 'S21', 'S23', 'S24']}, {'result': 'refused:P8', 'set_points': {}, 'held_signals': []}), ('control 48', {'route_points': {'P2': 'R', 'P3': 'R'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P7': 'N', 'P8': 'N'}, 'holdable': ['S20', 'S21', 'S22']}, {'result': 'protected', 'set_points': {'P9': 'N', 'P7': 'N', 'P8': 'N'}, 'held_signals': []}), ('control 51', {'route_points': {'P3': 'N', 'P2': 'R'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P9': 'R'}, 'holdable': ['S20', 'S21', 'S22', 'S23', 'S24']}, {'result': 'protected', 'set_points': {'P7': 'N', 'P9': 'R'}, 'held_signals': ['S23']})]]
for label, args, expected in fixtures[N-1]:
check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| regression: same signal held twice | {'held_signals': ['S20', 'S20', 'S22'], 'result': 'protected', 'set_points': {'P8': 'N'}} | {'held_signals': ['S20', 'S22'], 'result': 'protected', 'set_points': {'P8': 'N'}} | Failed |
| boundary: flank point locked in the protecting lie | {'held_signals': [], 'result': 'protected', 'set_points': {'P7': 'R', 'P8': 'N'}} | {'held_signals': [], 'result': 'protected', 'set_points': {'P7': 'R', 'P8': 'N'}} | Passed |
| boundary: flank point free | {'held_signals': [], 'result': 'protected', 'set_points': {'P7': 'R', 'P8': 'N'}} | {'held_signals': [], 'result': 'protected', 'set_points': {'P7': 'R', 'P8': 'N'}} | Passed |
| boundary: two route points disagree on a flank point | {'held_signals': [], 'result': 'protected', 'set_points': {'P7': 'N', 'P9': 'N'}} | {'held_signals': [], 'result': 'protected', 'set_points': {'P7': 'N', 'P9': 'N'}} | Passed |
| boundary: flank signal not holdable | {'held_signals': [], 'result': 'refused:P7', 'set_points': {}} | {'held_signals': [], 'result': 'refused:P7', 'set_points': {}} | Passed |
| control 1 | {'held_signals': [], 'result': 'refused:P9', 'set_points': {}} | {'held_signals': [], 'result': 'refused:P9', 'set_points': {}} | Passed |
| control 4 | {'held_signals': [], 'result': 'protected', 'set_points': {'P7': 'N', 'P9': 'N'}} | {'held_signals': [], 'result': 'protected', 'set_points': {'P7': 'N', 'P9': 'N'}} | Passed |
| control 7 | {'held_signals': [], 'result': 'refused:P7', 'set_points': {}} | {'held_signals': [], 'result': 'refused:P7', 'set_points': {}} | Passed |
SHA-256 / 5cc2951b245cb116ebe5cde4a49df489563f8a3af3c339c06f16fa84d315f2d8
3 / The verified repair
Exit 0"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(x):
set_pts = {}
held = []
locks = x['point_locks']
for p, pos in sorted(x['route_points'].items()):
for fp, fpos, fsig in x['flank'].get(p + pos, []):
lk = locks.get(fp, set_pts.get(fp))
if lk is None or lk == fpos:
set_pts[fp] = fpos
elif fsig is not None and fsig in x['holdable']:
held.append(fsig)
else:
return {'result': 'refused:' + fp, 'set_points': {}, 'held_signals': []}
return {'result': 'protected', 'set_points': set_pts, 'held_signals': sorted(set(held))}
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: same signal held twice', {'route_points': {'P1': 'N', 'P2': 'N'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P7': 'N', 'P8': 'N', 'P9': 'N'}, 'holdable': ['S20', 'S22']}, {'result': 'protected', 'set_points': {'P8': 'N'}, 'held_signals': ['S20', 'S22']}), ('boundary: flank point locked in the protecting lie', {'route_points': {'P1': 'N'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P7': 'R'}, 'holdable': ['S20', 'S21', 'S22', 'S23', 'S24']}, {'result': 'protected', 'set_points': {'P7': 'R', 'P8': 'N'}, 'held_signals': []}), ('boundary: flank point free', {'route_points': {'P1': 'N'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {}, 'holdable': ['S20', 'S21', 'S22', 'S23', 'S24']}, {'result': 'protected', 'set_points': {'P7': 'R', 'P8': 'N'}, 'held_signals': []}), ('boundary: two route points disagree on a flank point', {'route_points': {'P1': 'R', 'P2': 'R'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {}, 'holdable': ['S20', 'S21', 'S22', 'S23', 'S24']}, {'result': 'protected', 'set_points': {'P7': 'N', 'P9': 'N'}, 'held_signals': []}), ('boundary: flank signal not holdable', {'route_points': {'P1': 'R'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P7': 'R'}, 'holdable': []}, {'result': 'refused:P7', 'set_points': {}, 'held_signals': []}), ('control 1', {'route_points': {'P3': 'N'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P7': 'R', 'P9': 'N'}, 'holdable': ['S23', 'S24']}, {'result': 'refused:P9', 'set_points': {}, 'held_signals': []}), ('control 4', {'route_points': {'P2': 'R'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {}, 'holdable': ['S21', 'S22']}, {'result': 'protected', 'set_points': {'P9': 'N', 'P7': 'N'}, 'held_signals': []}), ('control 7', {'route_points': {'P2': 'R', 'P1': 'R', 'P3': 'N'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P7': 'R', 'P8': 'R', 'P9': 'R'}, 'holdable': ['S22', 'S24']}, {'result': 'refused:P7', 'set_points': {}, 'held_signals': []})], [('regression: same signal held twice', {'route_points': {'P1': 'N', 'P2': 'N'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P7': 'N', 'P8': 'N', 'P9': 'N'}, 'holdable': ['S20', 'S22']}, {'result': 'protected', 'set_points': {'P8': 'N'}, 'held_signals': ['S20', 'S22']}), ('boundary: two route points disagree on a flank point', {'route_points': {'P1': 'R', 'P2': 'R'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {}, 'holdable': ['S20', 'S21', 'S22', 'S23', 'S24']}, {'result': 'protected', 'set_points': {'P7': 'N', 'P9': 'N'}, 'held_signals': []}), ('boundary: flank signal not holdable', {'route_points': {'P1': 'R'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P7': 'R'}, 'holdable': []}, {'result': 'refused:P7', 'set_points': {}, 'held_signals': []}), ('boundary: no flank signal available', {'route_points': {'P3': 'N'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P9': 'N'}, 'holdable': ['S20', 'S21', 'S22', 'S23', 'S24']}, {'result': 'refused:P9', 'set_points': {}, 'held_signals': []}), ('boundary: reverse lie flank entry', {'route_points': {'P2': 'R'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P9': 'R'}, 'holdable': ['S20', 'S21', 'S22', 'S23', 'S24']}, {'result': 'protected', 'set_points': {'P7': 'N'}, 'held_signals': ['S23']}), ('control 12', {'route_points': {'P1': 'R', 'P3': 'R'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {}, 'holdable': ['S21', 'S22', 'S24']}, {'result': 'protected', 'set_points': {'P7': 'N', 'P8': 'N'}, 'held_signals': []}), ('control 15', {'route_points': {'P1': 'R'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P9': 'N'}, 'holdable': ['S24']}, {'result': 'protected', 'set_points': {'P7': 'N'}, 'held_signals': []}), ('control 18', {'route_points': {'P3': 'R', 'P1': 'R', 'P2': 'R'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P7': 'N', 'P9': 'N'}, 'holdable': ['S22', 'S23', 'S24']}, {'result': 'protected', 'set_points': {'P7': 'N', 'P9': 'N', 'P8': 'N'}, 'held_signals': []})], [('regression: same signal held twice', {'route_points': {'P1': 'N', 'P2': 'N'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P7': 'N', 'P8': 'N', 'P9': 'N'}, 'holdable': ['S20', 'S22']}, {'result': 'protected', 'set_points': {'P8': 'N'}, 'held_signals': ['S20', 'S22']}), ('boundary: no flank signal available', {'route_points': {'P3': 'N'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P9': 'N'}, 'holdable': ['S20', 'S21', 'S22', 'S23', 'S24']}, {'result': 'refused:P9', 'set_points': {}, 'held_signals': []}), ('boundary: reverse lie flank entry', {'route_points': {'P2': 'R'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P9': 'R'}, 'holdable': ['S20', 'S21', 'S22', 'S23', 'S24']}, {'result': 'protected', 'set_points': {'P7': 'N'}, 'held_signals': ['S23']}), ('boundary: own conflicting demand with a holdable signal', {'route_points': {'P1': 'R', 'P2': 'R'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {}, 'holdable': ['S21', 'S23']}, {'result': 'protected', 'set_points': {'P7': 'N', 'P9': 'N'}, 'held_signals': []}), ('boundary: own conflicting demand without a signal', {'route_points': {'P1': 'N', 'P2': 'R'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {}, 'holdable': ['S20', 'S21', 'S22', 'S23', 'S24']}, {'result': 'refused:P7', 'set_points': {}, 'held_signals': []}), ('control 23', {'route_points': {'P1': 'R', 'P2': 'N', 'P3': 'R'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {}, 'holdable': ['S20', 'S21', 'S22', 'S24']}, {'result': 'protected', 'set_points': {'P7': 'N', 'P8': 'R', 'P9': 'R'}, 'held_signals': ['S24']}), ('control 26', {'route_points': {'P3': 'N'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P7': 'R', 'P8': 'N'}, 'holdable': ['S20', 'S21', 'S22', 'S23', 'S24']}, {'result': 'protected', 'set_points': {'P9': 'R'}, 'held_signals': []}), ('control 29', {'route_points': {'P1': 'R', 'P2': 'R'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P9': 'R'}, 'holdable': ['S20', 'S23']}, {'result': 'protected', 'set_points': {'P7': 'N'}, 'held_signals': ['S23']})], [('regression: same signal held twice', {'route_points': {'P1': 'N', 'P2': 'N'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P7': 'N', 'P8': 'N', 'P9': 'N'}, 'holdable': ['S20', 'S22']}, {'result': 'protected', 'set_points': {'P8': 'N'}, 'held_signals': ['S20', 'S22']}), ('boundary: own conflicting demand with a holdable signal', {'route_points': {'P1': 'R', 'P2': 'R'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {}, 'holdable': ['S21', 'S23']}, {'result': 'protected', 'set_points': {'P7': 'N', 'P9': 'N'}, 'held_signals': []}), ('boundary: own conflicting demand without a signal', {'route_points': {'P1': 'N', 'P2': 'R'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {}, 'holdable': ['S20', 'S21', 'S22', 'S23', 'S24']}, {'result': 'refused:P7', 'set_points': {}, 'held_signals': []}), ('boundary: flank point locked in the protecting lie', {'route_points': {'P1': 'N'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P7': 'R'}, 'holdable': ['S20', 'S21', 'S22', 'S23', 'S24']}, {'result': 'protected', 'set_points': {'P7': 'R', 'P8': 'N'}, 'held_signals': []}), ('boundary: flank point free', {'route_points': {'P1': 'N'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {}, 'holdable': ['S20', 'S21', 'S22', 'S23', 'S24']}, {'result': 'protected', 'set_points': {'P7': 'R', 'P8': 'N'}, 'held_signals': []}), ('control 34', {'route_points': {'P3': 'R', 'P2': 'N'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P7': 'R', 'P9': 'N'}, 'holdable': ['S20', 'S21', 'S24']}, {'result': 'protected', 'set_points': {'P8': 'R'}, 'held_signals': ['S20', 'S24']}), ('control 37', {'route_points': {'P2': 'N', 'P1': 'R', 'P3': 'N'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P8': 'R'}, 'holdable': ['S21', 'S24']}, {'result': 'protected', 'set_points': {'P7': 'N', 'P8': 'R', 'P9': 'R'}, 'held_signals': []}), ('control 40', {'route_points': {'P3': 'R', 'P1': 'R'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {}, 'holdable': ['S20', 'S21', 'S22', 'S24']}, {'result': 'protected', 'set_points': {'P7': 'N', 'P8': 'N'}, 'held_signals': []})], [('regression: same signal held twice', {'route_points': {'P1': 'N', 'P2': 'N'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P7': 'N', 'P8': 'N', 'P9': 'N'}, 'holdable': ['S20', 'S22']}, {'result': 'protected', 'set_points': {'P8': 'N'}, 'held_signals': ['S20', 'S22']}), ('boundary: own conflicting demand without a signal', {'route_points': {'P1': 'N', 'P2': 'R'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {}, 'holdable': ['S20', 'S21', 'S22', 'S23', 'S24']}, {'result': 'refused:P7', 'set_points': {}, 'held_signals': []}), ('boundary: flank point locked in the protecting lie', {'route_points': {'P1': 'N'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P7': 'R'}, 'holdable': ['S20', 'S21', 'S22', 'S23', 'S24']}, {'result': 'protected', 'set_points': {'P7': 'R', 'P8': 'N'}, 'held_signals': []}), ('boundary: flank point free', {'route_points': {'P1': 'N'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {}, 'holdable': ['S20', 'S21', 'S22', 'S23', 'S24']}, {'result': 'protected', 'set_points': {'P7': 'R', 'P8': 'N'}, 'held_signals': []}), ('boundary: two route points disagree on a flank point', {'route_points': {'P1': 'R', 'P2': 'R'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {}, 'holdable': ['S20', 'S21', 'S22', 'S23', 'S24']}, {'result': 'protected', 'set_points': {'P7': 'N', 'P9': 'N'}, 'held_signals': []}), ('control 45', {'route_points': {'P2': 'N', 'P1': 'N', 'P3': 'R'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P7': 'R', 'P8': 'R'}, 'holdable': ['S20', 'S21', 'S23', 'S24']}, {'result': 'refused:P8', 'set_points': {}, 'held_signals': []}), ('control 48', {'route_points': {'P2': 'R', 'P3': 'R'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P7': 'N', 'P8': 'N'}, 'holdable': ['S20', 'S21', 'S22']}, {'result': 'protected', 'set_points': {'P9': 'N', 'P7': 'N', 'P8': 'N'}, 'held_signals': []}), ('control 51', {'route_points': {'P3': 'N', 'P2': 'R'}, 'flank': {'P1N': [['P7', 'R', 'S20'], ['P8', 'N', None]], 'P1R': [['P7', 'N', 'S21']], 'P2N': [['P8', 'R', 'S22'], ['P9', 'R', 'S20']], 'P2R': [['P9', 'N', 'S23'], ['P7', 'N', None]], 'P3N': [['P9', 'R', None]], 'P3R': [['P8', 'N', 'S24']]}, 'point_locks': {'P9': 'R'}, 'holdable': ['S20', 'S21', 'S22', 'S23', 'S24']}, {'result': 'protected', 'set_points': {'P7': 'N', 'P9': 'R'}, 'held_signals': ['S23']})]]
for label, args, expected in fixtures[N-1]:
check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| regression: same signal held twice | {'held_signals': ['S20', 'S22'], 'result': 'protected', 'set_points': {'P8': 'N'}} | {'held_signals': ['S20', 'S22'], 'result': 'protected', 'set_points': {'P8': 'N'}} | Passed |
| boundary: flank point locked in the protecting lie | {'held_signals': [], 'result': 'protected', 'set_points': {'P7': 'R', 'P8': 'N'}} | {'held_signals': [], 'result': 'protected', 'set_points': {'P7': 'R', 'P8': 'N'}} | Passed |
| boundary: flank point free | {'held_signals': [], 'result': 'protected', 'set_points': {'P7': 'R', 'P8': 'N'}} | {'held_signals': [], 'result': 'protected', 'set_points': {'P7': 'R', 'P8': 'N'}} | Passed |
| boundary: two route points disagree on a flank point | {'held_signals': [], 'result': 'protected', 'set_points': {'P7': 'N', 'P9': 'N'}} | {'held_signals': [], 'result': 'protected', 'set_points': {'P7': 'N', 'P9': 'N'}} | Passed |
| boundary: flank signal not holdable | {'held_signals': [], 'result': 'refused:P7', 'set_points': {}} | {'held_signals': [], 'result': 'refused:P7', 'set_points': {}} | Passed |
| control 1 | {'held_signals': [], 'result': 'refused:P9', 'set_points': {}} | {'held_signals': [], 'result': 'refused:P9', 'set_points': {}} | Passed |
| control 4 | {'held_signals': [], 'result': 'protected', 'set_points': {'P7': 'N', 'P9': 'N'}} | {'held_signals': [], 'result': 'protected', 'set_points': {'P7': 'N', 'P9': 'N'}} | Passed |
| control 7 | {'held_signals': [], 'result': 'refused:P7', 'set_points': {}} | {'held_signals': [], 'result': 'refused:P7', 'set_points': {}} | Passed |
SHA-256 / 3e49c82b552ddfe4ce2e347640341fc5aa1570d5aee4353630ba039b05b31982
Verification & scope
Stipulated toy interlocking contract for a bounded teaching model; it makes no claim of conformance to any railway signalling standard and omits real safety cases. This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.
Observations recorded using Python 3.12.14 at 2026-09-29T14:47:51.372712+00:00.
Case digest / faa79068329e6009d891ec96ba80cb5685fd5bbf94f5b9f561ef9be81e762a71