broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    state = 'normal'
    cp = True
    alarms = []
    for ev in x['events']:
        if ev == 'cp_blocked':
            cp = False
        elif ev == 'cp_clear':
            cp = True
        elif ev == 'offer':
            if state == 'normal':
                state = 'line_clear'
            else:
                alarms.append('refused')
        elif ev == 'depart':
            if state != 'line_clear':
                alarms.append('unauthorised-departure')
            state = 'train_on_line'
        elif ev == 'arrive_complete':
            if state == 'train_on_line':
                state = 'normal'
        elif ev == 'arrive_no_tail':
            alarms.append('tail-missing')
        elif ev == 'cancel':
            if state == 'line_clear':
                state = 'normal'
    return {'state': state, 'alarms': alarms}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('sampled regression 10', {'events': ['arrive_complete', 'cp_blocked', 'offer', 'arrive_complete', 'depart']}, {'state': 'train_on_line', 'alarms': ['refused', 'unauthorised-departure']}), ('boundary: second offer while line clear', {'events': ['offer', 'offer']}, {'state': 'line_clear', 'alarms': ['refused']}), ('sampled regression 45', {'events': ['depart', 'depart', 'depart', 'cp_blocked', 'depart', 'offer', 'arrive_complete', 'offer']}, {'state': 'normal', 'alarms': ['unauthorised-departure', 'unauthorised-departure', 'unauthorised-departure', 'unauthorised-departure', 'refused', 'refused']}), ('control 4', {'events': ['cancel', 'arrive_no_tail', 'offer', 'offer', 'depart', 'arrive_no_tail']}, {'state': 'train_on_line', 'alarms': ['tail-missing', 'refused', 'tail-missing']}), ('boundary: offer with clearing point fouled', {'events': ['cp_blocked', 'offer', 'cp_clear', 'offer']}, {'state': 'line_clear', 'alarms': ['refused']}), ('control 1', {'events': ['cp_blocked', 'depart', 'arrive_no_tail', 'cp_clear', 'depart']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure', 'tail-missing', 'unauthorised-departure']}), ('control 7', {'events': ['offer', 'arrive_no_tail', 'arrive_complete', 'cp_clear', 'cp_clear', 'arrive_no_tail']}, {'state': 'line_clear', 'alarms': ['tail-missing', 'tail-missing']}), ('control 13', {'events': ['depart', 'offer', 'arrive_complete', 'arrive_complete', 'cp_blocked', 'cp_clear', 'depart']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure', 'refused', 'unauthorised-departure']})], [('sampled regression 33', {'events': ['arrive_no_tail', 'cp_blocked', 'arrive_complete', 'offer']}, {'state': 'normal', 'alarms': ['tail-missing', 'refused']}), ('boundary: second offer while line clear', {'events': ['offer', 'offer']}, {'state': 'line_clear', 'alarms': ['refused']}), ('sampled regression 76', {'events': ['offer', 'offer', 'cp_blocked', 'cancel', 'cp_blocked', 'cp_blocked', 'cp_blocked', 'offer']}, {'state': 'normal', 'alarms': ['refused', 'refused']}), ('control 46', {'events': ['offer', 'offer', 'arrive_complete', 'arrive_no_tail', 'cp_clear', 'arrive_complete', 'cancel', 'arrive_no_tail', 'offer', 'arrive_no_tail']}, {'state': 'line_clear', 'alarms': ['refused', 'tail-missing', 'tail-missing', 'tail-missing']}), ('boundary: second train into occupied block', {'events': ['offer', 'depart', 'depart']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure']}), ('control 12', {'events': ['depart', 'cp_clear', 'arrive_complete', 'depart', 'cp_blocked']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure', 'unauthorised-departure']}), ('control 15', {'events': ['arrive_complete', 'cp_clear', 'cancel']}, {'state': 'normal', 'alarms': []}), ('control 18', {'events': ['cp_clear', 'depart', 'offer', 'cp_blocked']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure', 'refused']})], [('sampled regression 36', {'events': ['cp_blocked', 'cp_blocked', 'offer']}, {'state': 'normal', 'alarms': ['refused']}), ('boundary: second offer while line clear', {'events': ['offer', 'offer']}, {'state': 'line_clear', 'alarms': ['refused']}), ('sampled regression 53', {'events': ['offer', 'offer', 'arrive_complete', 'arrive_complete', 'offer', 'cancel', 'cancel', 'cp_blocked', 'arrive_no_tail', 'offer']}, {'state': 'normal', 'alarms': ['refused', 'refused', 'tail-missing', 'refused']}), ('control 69', {'events': ['offer', 'offer', 'offer']}, {'state': 'line_clear', 'alarms': ['refused', 'refused']}), ('boundary: train arrives without tail lamp', {'events': ['offer', 'depart', 'arrive_no_tail', 'offer']}, {'state': 'train_on_line', 'alarms': ['tail-missing', 'refused']}), ('control 23', {'events': ['depart', 'cp_blocked', 'arrive_no_tail', 'offer', 'cp_clear']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure', 'tail-missing', 'refused']}), ('control 26', {'events': ['cp_clear', 'offer', 'cp_clear', 'cp_clear', 'cp_blocked', 'cp_clear', 'cp_blocked', 'depart']}, {'state': 'train_on_line', 'alarms': []}), ('control 29', {'events': ['arrive_complete', 'depart', 'offer', 'depart', 'arrive_complete', 'arrive_no_tail', 'cp_clear']}, {'state': 'normal', 'alarms': ['unauthorised-departure', 'refused', 'unauthorised-departure', 'tail-missing']})], [('sampled regression 45', {'events': ['depart', 'depart', 'depart', 'cp_blocked', 'depart', 'offer', 'arrive_complete', 'offer']}, {'state': 'normal', 'alarms': ['unauthorised-departure', 'unauthorised-departure', 'unauthorised-departure', 'unauthorised-departure', 'refused', 'refused']}), ('boundary: second offer while line clear', {'events': ['offer', 'offer']}, {'state': 'line_clear', 'alarms': ['refused']}), ('sampled regression 36', {'events': ['cp_blocked', 'cp_blocked', 'offer']}, {'state': 'normal', 'alarms': ['refused']}), ('control 11', {'events': ['arrive_no_tail', 'offer', 'offer', 'arrive_complete', 'cancel', 'arrive_no_tail', 'depart', 'cp_blocked', 'cp_clear']}, {'state': 'train_on_line', 'alarms': ['tail-missing', 'refused', 'tail-missing', 'unauthorised-departure']}), ('boundary: cancel of line clear', {'events': ['offer', 'cancel', 'offer']}, {'state': 'line_clear', 'alarms': []}), ('control 34', {'events': ['cp_blocked', 'arrive_no_tail', 'cancel', 'cp_clear', 'offer', 'arrive_complete', 'cp_blocked']}, {'state': 'line_clear', 'alarms': ['tail-missing']}), ('control 37', {'events': ['offer', 'depart', 'cp_clear', 'cp_clear']}, {'state': 'train_on_line', 'alarms': []}), ('control 40', {'events': ['arrive_complete', 'cp_clear', 'arrive_no_tail']}, {'state': 'normal', 'alarms': ['tail-missing']})], [('sampled regression 51', {'events': ['cp_clear', 'cp_blocked', 'offer']}, {'state': 'normal', 'alarms': ['refused']}), ('boundary: second offer while line clear', {'events': ['offer', 'offer']}, {'state': 'line_clear', 'alarms': ['refused']}), ('sampled regression 72', {'events': ['offer', 'depart', 'arrive_complete', 'cp_blocked', 'offer', 'offer', 'arrive_no_tail', 'cancel']}, {'state': 'normal', 'alarms': ['refused', 'refused', 'tail-missing']}), ('control 49', {'events': ['offer', 'cp_clear', 'offer', 'arrive_no_tail']}, {'state': 'line_clear', 'alarms': ['refused', 'tail-missing']}), ('boundary: offer with clearing point fouled', {'events': ['cp_blocked', 'offer', 'cp_clear', 'offer']}, {'state': 'line_clear', 'alarms': ['refused']}), ('sampled regression 45', {'events': ['depart', 'depart', 'depart', 'cp_blocked', 'depart', 'offer', 'arrive_complete', 'offer']}, {'state': 'normal', 'alarms': ['unauthorised-departure', 'unauthorised-departure', 'unauthorised-departure', 'unauthorised-departure', 'refused', 'refused']}), ('control 48', {'events': ['cp_clear', 'cp_blocked', 'arrive_no_tail', 'depart', 'offer', 'offer', 'arrive_no_tail', 'offer']}, {'state': 'train_on_line', 'alarms': ['tail-missing', 'unauthorised-departure', 'refused', 'refused', 'tail-missing', 'refused']}), ('control 54', {'events': ['offer', 'arrive_no_tail', 'offer', 'depart', 'arrive_complete', 'offer', 'cp_blocked']}, {'state': 'line_clear', 'alarms': ['tail-missing', 'refused']})]]
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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    state = 'normal'
    cp = True
    alarms = []
    for ev in x['events']:
        if ev == 'cp_blocked':
            cp = False
        elif ev == 'cp_clear':
            cp = True
        elif ev == 'offer':
            if state != 'train_on_line' and cp:
                state = 'line_clear'
            else:
                alarms.append('refused')
        elif ev == 'depart':
            if state != 'line_clear':
                alarms.append('unauthorised-departure')
            state = 'train_on_line'
        elif ev == 'arrive_complete':
            if state == 'train_on_line':
                state = 'normal'
        elif ev == 'arrive_no_tail':
            alarms.append('tail-missing')
        elif ev == 'cancel':
            if state == 'line_clear':
                state = 'normal'
    return {'state': state, 'alarms': alarms}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('sampled regression 10', {'events': ['arrive_complete', 'cp_blocked', 'offer', 'arrive_complete', 'depart']}, {'state': 'train_on_line', 'alarms': ['refused', 'unauthorised-departure']}), ('boundary: second offer while line clear', {'events': ['offer', 'offer']}, {'state': 'line_clear', 'alarms': ['refused']}), ('sampled regression 45', {'events': ['depart', 'depart', 'depart', 'cp_blocked', 'depart', 'offer', 'arrive_complete', 'offer']}, {'state': 'normal', 'alarms': ['unauthorised-departure', 'unauthorised-departure', 'unauthorised-departure', 'unauthorised-departure', 'refused', 'refused']}), ('control 4', {'events': ['cancel', 'arrive_no_tail', 'offer', 'offer', 'depart', 'arrive_no_tail']}, {'state': 'train_on_line', 'alarms': ['tail-missing', 'refused', 'tail-missing']}), ('boundary: offer with clearing point fouled', {'events': ['cp_blocked', 'offer', 'cp_clear', 'offer']}, {'state': 'line_clear', 'alarms': ['refused']}), ('control 1', {'events': ['cp_blocked', 'depart', 'arrive_no_tail', 'cp_clear', 'depart']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure', 'tail-missing', 'unauthorised-departure']}), ('control 7', {'events': ['offer', 'arrive_no_tail', 'arrive_complete', 'cp_clear', 'cp_clear', 'arrive_no_tail']}, {'state': 'line_clear', 'alarms': ['tail-missing', 'tail-missing']}), ('control 13', {'events': ['depart', 'offer', 'arrive_complete', 'arrive_complete', 'cp_blocked', 'cp_clear', 'depart']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure', 'refused', 'unauthorised-departure']})], [('sampled regression 33', {'events': ['arrive_no_tail', 'cp_blocked', 'arrive_complete', 'offer']}, {'state': 'normal', 'alarms': ['tail-missing', 'refused']}), ('boundary: second offer while line clear', {'events': ['offer', 'offer']}, {'state': 'line_clear', 'alarms': ['refused']}), ('sampled regression 76', {'events': ['offer', 'offer', 'cp_blocked', 'cancel', 'cp_blocked', 'cp_blocked', 'cp_blocked', 'offer']}, {'state': 'normal', 'alarms': ['refused', 'refused']}), ('control 46', {'events': ['offer', 'offer', 'arrive_complete', 'arrive_no_tail', 'cp_clear', 'arrive_complete', 'cancel', 'arrive_no_tail', 'offer', 'arrive_no_tail']}, {'state': 'line_clear', 'alarms': ['refused', 'tail-missing', 'tail-missing', 'tail-missing']}), ('boundary: second train into occupied block', {'events': ['offer', 'depart', 'depart']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure']}), ('control 12', {'events': ['depart', 'cp_clear', 'arrive_complete', 'depart', 'cp_blocked']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure', 'unauthorised-departure']}), ('control 15', {'events': ['arrive_complete', 'cp_clear', 'cancel']}, {'state': 'normal', 'alarms': []}), ('control 18', {'events': ['cp_clear', 'depart', 'offer', 'cp_blocked']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure', 'refused']})], [('sampled regression 36', {'events': ['cp_blocked', 'cp_blocked', 'offer']}, {'state': 'normal', 'alarms': ['refused']}), ('boundary: second offer while line clear', {'events': ['offer', 'offer']}, {'state': 'line_clear', 'alarms': ['refused']}), ('sampled regression 53', {'events': ['offer', 'offer', 'arrive_complete', 'arrive_complete', 'offer', 'cancel', 'cancel', 'cp_blocked', 'arrive_no_tail', 'offer']}, {'state': 'normal', 'alarms': ['refused', 'refused', 'tail-missing', 'refused']}), ('control 69', {'events': ['offer', 'offer', 'offer']}, {'state': 'line_clear', 'alarms': ['refused', 'refused']}), ('boundary: train arrives without tail lamp', {'events': ['offer', 'depart', 'arrive_no_tail', 'offer']}, {'state': 'train_on_line', 'alarms': ['tail-missing', 'refused']}), ('control 23', {'events': ['depart', 'cp_blocked', 'arrive_no_tail', 'offer', 'cp_clear']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure', 'tail-missing', 'refused']}), ('control 26', {'events': ['cp_clear', 'offer', 'cp_clear', 'cp_clear', 'cp_blocked', 'cp_clear', 'cp_blocked', 'depart']}, {'state': 'train_on_line', 'alarms': []}), ('control 29', {'events': ['arrive_complete', 'depart', 'offer', 'depart', 'arrive_complete', 'arrive_no_tail', 'cp_clear']}, {'state': 'normal', 'alarms': ['unauthorised-departure', 'refused', 'unauthorised-departure', 'tail-missing']})], [('sampled regression 45', {'events': ['depart', 'depart', 'depart', 'cp_blocked', 'depart', 'offer', 'arrive_complete', 'offer']}, {'state': 'normal', 'alarms': ['unauthorised-departure', 'unauthorised-departure', 'unauthorised-departure', 'unauthorised-departure', 'refused', 'refused']}), ('boundary: second offer while line clear', {'events': ['offer', 'offer']}, {'state': 'line_clear', 'alarms': ['refused']}), ('sampled regression 36', {'events': ['cp_blocked', 'cp_blocked', 'offer']}, {'state': 'normal', 'alarms': ['refused']}), ('control 11', {'events': ['arrive_no_tail', 'offer', 'offer', 'arrive_complete', 'cancel', 'arrive_no_tail', 'depart', 'cp_blocked', 'cp_clear']}, {'state': 'train_on_line', 'alarms': ['tail-missing', 'refused', 'tail-missing', 'unauthorised-departure']}), ('boundary: cancel of line clear', {'events': ['offer', 'cancel', 'offer']}, {'state': 'line_clear', 'alarms': []}), ('control 34', {'events': ['cp_blocked', 'arrive_no_tail', 'cancel', 'cp_clear', 'offer', 'arrive_complete', 'cp_blocked']}, {'state': 'line_clear', 'alarms': ['tail-missing']}), ('control 37', {'events': ['offer', 'depart', 'cp_clear', 'cp_clear']}, {'state': 'train_on_line', 'alarms': []}), ('control 40', {'events': ['arrive_complete', 'cp_clear', 'arrive_no_tail']}, {'state': 'normal', 'alarms': ['tail-missing']})], [('sampled regression 51', {'events': ['cp_clear', 'cp_blocked', 'offer']}, {'state': 'normal', 'alarms': ['refused']}), ('boundary: second offer while line clear', {'events': ['offer', 'offer']}, {'state': 'line_clear', 'alarms': ['refused']}), ('sampled regression 72', {'events': ['offer', 'depart', 'arrive_complete', 'cp_blocked', 'offer', 'offer', 'arrive_no_tail', 'cancel']}, {'state': 'normal', 'alarms': ['refused', 'refused', 'tail-missing']}), ('control 49', {'events': ['offer', 'cp_clear', 'offer', 'arrive_no_tail']}, {'state': 'line_clear', 'alarms': ['refused', 'tail-missing']}), ('boundary: offer with clearing point fouled', {'events': ['cp_blocked', 'offer', 'cp_clear', 'offer']}, {'state': 'line_clear', 'alarms': ['refused']}), ('sampled regression 45', {'events': ['depart', 'depart', 'depart', 'cp_blocked', 'depart', 'offer', 'arrive_complete', 'offer']}, {'state': 'normal', 'alarms': ['unauthorised-departure', 'unauthorised-departure', 'unauthorised-departure', 'unauthorised-departure', 'refused', 'refused']}), ('control 48', {'events': ['cp_clear', 'cp_blocked', 'arrive_no_tail', 'depart', 'offer', 'offer', 'arrive_no_tail', 'offer']}, {'state': 'train_on_line', 'alarms': ['tail-missing', 'unauthorised-departure', 'refused', 'refused', 'tail-missing', 'refused']}), ('control 54', {'events': ['offer', 'arrive_no_tail', 'offer', 'depart', 'arrive_complete', 'offer', 'cp_blocked']}, {'state': 'line_clear', 'alarms': ['tail-missing', 'refused']})]]
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)

prompt:
Line clear is given while the clearing point beyond the home signal is fouled.

A block section between two boxes is normal, line_clear or train_on_line. An offer is accepted (line_clear) only from normal with the clearing point clear, otherwise alarm refused. A departure without line clear raises unauthorised-departure; any departure puts the train on line. arrive_complete returns train_on_line to normal; arrive_no_tail raises tail-missing and keeps the block occupied. cancel only withdraws line_clear. cp_blocked/cp_clear set the clearing point.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    state = 'normal'
    cp = True
    alarms = []
    for ev in x['events']:
        if ev == 'cp_blocked':
            cp = False
        elif ev == 'cp_clear':
            cp = True
        elif ev == 'offer':
            if state == 'normal' and cp:
                state = 'line_clear'
            else:
                alarms.append('refused')
        elif ev == 'depart':
            if state == 'normal':
                alarms.append('unauthorised-departure')
            state = 'train_on_line'
        elif ev == 'arrive_complete':
            if state == 'train_on_line':
                state = 'normal'
        elif ev == 'arrive_no_tail':
            alarms.append('tail-missing')
        elif ev == 'cancel':
            if state == 'line_clear':
                state = 'normal'
    return {'state': state, 'alarms': alarms}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: second train into occupied block', {'events': ['offer', 'depart', 'depart']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure']}), ('boundary: departure without offer', {'events': ['depart', 'arrive_complete']}, {'state': 'normal', 'alarms': ['unauthorised-departure']}), ('sampled regression 5', {'events': ['arrive_complete', 'cp_clear', 'offer', 'arrive_no_tail', 'cancel', 'depart', 'depart', 'arrive_complete', 'offer', 'cp_blocked']}, {'state': 'line_clear', 'alarms': ['tail-missing', 'unauthorised-departure', 'unauthorised-departure']}), ('sampled regression 1', {'events': ['cp_blocked', 'depart', 'arrive_no_tail', 'cp_clear', 'depart']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure', 'tail-missing', 'unauthorised-departure']}), ('boundary: offer with clearing point fouled', {'events': ['cp_blocked', 'offer', 'cp_clear', 'offer']}, {'state': 'line_clear', 'alarms': ['refused']}), ('control 4', {'events': ['cancel', 'arrive_no_tail', 'offer', 'offer', 'depart', 'arrive_no_tail']}, {'state': 'train_on_line', 'alarms': ['tail-missing', 'refused', 'tail-missing']}), ('control 7', {'events': ['offer', 'arrive_no_tail', 'arrive_complete', 'cp_clear', 'cp_clear', 'arrive_no_tail']}, {'state': 'line_clear', 'alarms': ['tail-missing', 'tail-missing']}), ('control 10', {'events': ['arrive_complete', 'cp_blocked', 'offer', 'arrive_complete', 'depart']}, {'state': 'train_on_line', 'alarms': ['refused', 'unauthorised-departure']})], [('regression: second train into occupied block', {'events': ['offer', 'depart', 'depart']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure']}), ('boundary: departure without offer', {'events': ['depart', 'arrive_complete']}, {'state': 'normal', 'alarms': ['unauthorised-departure']}), ('sampled regression 29', {'events': ['arrive_complete', 'depart', 'offer', 'depart', 'arrive_complete', 'arrive_no_tail', 'cp_clear']}, {'state': 'normal', 'alarms': ['unauthorised-departure', 'refused', 'unauthorised-departure', 'tail-missing']}), ('control 10', {'events': ['arrive_complete', 'cp_blocked', 'offer', 'arrive_complete', 'depart']}, {'state': 'train_on_line', 'alarms': ['refused', 'unauthorised-departure']}), ('boundary: train arrives without tail lamp', {'events': ['offer', 'depart', 'arrive_no_tail', 'offer']}, {'state': 'train_on_line', 'alarms': ['tail-missing', 'refused']}), ('control 12', {'events': ['depart', 'cp_clear', 'arrive_complete', 'depart', 'cp_blocked']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure', 'unauthorised-departure']}), ('control 15', {'events': ['arrive_complete', 'cp_clear', 'cancel']}, {'state': 'normal', 'alarms': []}), ('control 18', {'events': ['cp_clear', 'depart', 'offer', 'cp_blocked']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure', 'refused']})], [('regression: second train into occupied block', {'events': ['offer', 'depart', 'depart']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure']}), ('boundary: departure without offer', {'events': ['depart', 'arrive_complete']}, {'state': 'normal', 'alarms': ['unauthorised-departure']}), ('sampled regression 57', {'events': ['cp_blocked', 'depart', 'offer', 'cp_blocked', 'depart', 'arrive_no_tail', 'cancel', 'cp_blocked']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure', 'refused', 'unauthorised-departure', 'tail-missing']}), ('sampled regression 17', {'events': ['depart', 'arrive_complete', 'offer', 'arrive_complete', 'depart', 'offer', 'offer', 'depart', 'offer', 'arrive_no_tail']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure', 'refused', 'refused', 'unauthorised-departure', 'refused', 'tail-missing']}), ('boundary: train arrives without tail lamp', {'events': ['offer', 'depart', 'arrive_no_tail', 'offer']}, {'state': 'train_on_line', 'alarms': ['tail-missing', 'refused']}), ('control 23', {'events': ['depart', 'cp_blocked', 'arrive_no_tail', 'offer', 'cp_clear']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure', 'tail-missing', 'refused']}), ('control 26', {'events': ['cp_clear', 'offer', 'cp_clear', 'cp_clear', 'cp_blocked', 'cp_clear', 'cp_blocked', 'depart']}, {'state': 'train_on_line', 'alarms': []}), ('sampled regression 29', {'events': ['arrive_complete', 'depart', 'offer', 'depart', 'arrive_complete', 'arrive_no_tail', 'cp_clear']}, {'state': 'normal', 'alarms': ['unauthorised-departure', 'refused', 'unauthorised-departure', 'tail-missing']})], [('regression: second train into occupied block', {'events': ['offer', 'depart', 'depart']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure']}), ('boundary: departure without offer', {'events': ['depart', 'arrive_complete']}, {'state': 'normal', 'alarms': ['unauthorised-departure']}), ('sampled regression 78', {'events': ['cp_blocked', 'arrive_no_tail', 'depart', 'cancel', 'arrive_no_tail', 'depart']}, {'state': 'train_on_line', 'alarms': ['tail-missing', 'unauthorised-departure', 'tail-missing', 'unauthorised-departure']}), ('control 23', {'events': ['depart', 'cp_blocked', 'arrive_no_tail', 'offer', 'cp_clear']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure', 'tail-missing', 'refused']}), ('boundary: cancel of line clear', {'events': ['offer', 'cancel', 'offer']}, {'state': 'line_clear', 'alarms': []}), ('control 34', {'events': ['cp_blocked', 'arrive_no_tail', 'cancel', 'cp_clear', 'offer', 'arrive_complete', 'cp_blocked']}, {'state': 'line_clear', 'alarms': ['tail-missing']}), ('control 37', {'events': ['offer', 'depart', 'cp_clear', 'cp_clear']}, {'state': 'train_on_line', 'alarms': []}), ('control 40', {'events': ['arrive_complete', 'cp_clear', 'arrive_no_tail']}, {'state': 'normal', 'alarms': ['tail-missing']})], [('regression: second train into occupied block', {'events': ['offer', 'depart', 'depart']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure']}), ('boundary: departure without offer', {'events': ['depart', 'arrive_complete']}, {'state': 'normal', 'alarms': ['unauthorised-departure']}), ('sampled regression 16', {'events': ['arrive_complete', 'cp_blocked', 'depart', 'depart', 'offer', 'cp_clear', 'offer']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure', 'unauthorised-departure', 'refused', 'refused']}), ('sampled regression 30', {'events': ['depart', 'arrive_no_tail', 'depart', 'depart', 'offer', 'depart', 'depart', 'cp_blocked', 'arrive_no_tail', 'arrive_no_tail']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure', 'tail-missing', 'unauthorised-departure', 'unauthorised-departure', 'refused', 'unauthorised-departure', 'unauthorised-departure', 'tail-missing', 'tail-missing']}), ('boundary: offer with clearing point fouled', {'events': ['cp_blocked', 'offer', 'cp_clear', 'offer']}, {'state': 'line_clear', 'alarms': ['refused']}), ('sampled regression 45', {'events': ['depart', 'depart', 'depart', 'cp_blocked', 'depart', 'offer', 'arrive_complete', 'offer']}, {'state': 'normal', 'alarms': ['unauthorised-departure', 'unauthorised-departure', 'unauthorised-departure', 'unauthorised-departure', 'refused', 'refused']}), ('control 48', {'events': ['cp_clear', 'cp_blocked', 'arrive_no_tail', 'depart', 'offer', 'offer', 'arrive_no_tail', 'offer']}, {'state': 'train_on_line', 'alarms': ['tail-missing', 'unauthorised-departure', 'refused', 'refused', 'tail-missing', 'refused']}), ('control 51', {'events': ['cp_clear', 'cp_blocked', 'offer']}, {'state': 'normal', 'alarms': ['refused']})]]
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)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    state = 'normal'
    cp = True
    alarms = []
    for ev in x['events']:
        if ev == 'cp_blocked':
            cp = False
        elif ev == 'cp_clear':
            cp = True
        elif ev == 'offer':
            if state == 'normal' and cp:
                state = 'line_clear'
            else:
                alarms.append('refused')
        elif ev == 'depart':
            if state == 'train_on_line':
                alarms.append('unauthorised-departure')
            state = 'train_on_line'
        elif ev == 'arrive_complete':
            if state == 'train_on_line':
                state = 'normal'
        elif ev == 'arrive_no_tail':
            alarms.append('tail-missing')
        elif ev == 'cancel':
            if state == 'line_clear':
                state = 'normal'
    return {'state': state, 'alarms': alarms}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: second train into occupied block', {'events': ['offer', 'depart', 'depart']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure']}), ('boundary: departure without offer', {'events': ['depart', 'arrive_complete']}, {'state': 'normal', 'alarms': ['unauthorised-departure']}), ('sampled regression 5', {'events': ['arrive_complete', 'cp_clear', 'offer', 'arrive_no_tail', 'cancel', 'depart', 'depart', 'arrive_complete', 'offer', 'cp_blocked']}, {'state': 'line_clear', 'alarms': ['tail-missing', 'unauthorised-departure', 'unauthorised-departure']}), ('sampled regression 1', {'events': ['cp_blocked', 'depart', 'arrive_no_tail', 'cp_clear', 'depart']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure', 'tail-missing', 'unauthorised-departure']}), ('boundary: offer with clearing point fouled', {'events': ['cp_blocked', 'offer', 'cp_clear', 'offer']}, {'state': 'line_clear', 'alarms': ['refused']}), ('control 4', {'events': ['cancel', 'arrive_no_tail', 'offer', 'offer', 'depart', 'arrive_no_tail']}, {'state': 'train_on_line', 'alarms': ['tail-missing', 'refused', 'tail-missing']}), ('control 7', {'events': ['offer', 'arrive_no_tail', 'arrive_complete', 'cp_clear', 'cp_clear', 'arrive_no_tail']}, {'state': 'line_clear', 'alarms': ['tail-missing', 'tail-missing']}), ('control 10', {'events': ['arrive_complete', 'cp_blocked', 'offer', 'arrive_complete', 'depart']}, {'state': 'train_on_line', 'alarms': ['refused', 'unauthorised-departure']})], [('regression: second train into occupied block', {'events': ['offer', 'depart', 'depart']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure']}), ('boundary: departure without offer', {'events': ['depart', 'arrive_complete']}, {'state': 'normal', 'alarms': ['unauthorised-departure']}), ('sampled regression 29', {'events': ['arrive_complete', 'depart', 'offer', 'depart', 'arrive_complete', 'arrive_no_tail', 'cp_clear']}, {'state': 'normal', 'alarms': ['unauthorised-departure', 'refused', 'unauthorised-departure', 'tail-missing']}), ('control 10', {'events': ['arrive_complete', 'cp_blocked', 'offer', 'arrive_complete', 'depart']}, {'state': 'train_on_line', 'alarms': ['refused', 'unauthorised-departure']}), ('boundary: train arrives without tail lamp', {'events': ['offer', 'depart', 'arrive_no_tail', 'offer']}, {'state': 'train_on_line', 'alarms': ['tail-missing', 'refused']}), ('control 12', {'events': ['depart', 'cp_clear', 'arrive_complete', 'depart', 'cp_blocked']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure', 'unauthorised-departure']}), ('control 15', {'events': ['arrive_complete', 'cp_clear', 'cancel']}, {'state': 'normal', 'alarms': []}), ('control 18', {'events': ['cp_clear', 'depart', 'offer', 'cp_blocked']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure', 'refused']})], [('regression: second train into occupied block', {'events': ['offer', 'depart', 'depart']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure']}), ('boundary: departure without offer', {'events': ['depart', 'arrive_complete']}, {'state': 'normal', 'alarms': ['unauthorised-departure']}), ('sampled regression 57', {'events': ['cp_blocked', 'depart', 'offer', 'cp_blocked', 'depart', 'arrive_no_tail', 'cancel', 'cp_blocked']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure', 'refused', 'unauthorised-departure', 'tail-missing']}), ('sampled regression 17', {'events': ['depart', 'arrive_complete', 'offer', 'arrive_complete', 'depart', 'offer', 'offer', 'depart', 'offer', 'arrive_no_tail']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure', 'refused', 'refused', 'unauthorised-departure', 'refused', 'tail-missing']}), ('boundary: train arrives without tail lamp', {'events': ['offer', 'depart', 'arrive_no_tail', 'offer']}, {'state': 'train_on_line', 'alarms': ['tail-missing', 'refused']}), ('control 23', {'events': ['depart', 'cp_blocked', 'arrive_no_tail', 'offer', 'cp_clear']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure', 'tail-missing', 'refused']}), ('control 26', {'events': ['cp_clear', 'offer', 'cp_clear', 'cp_clear', 'cp_blocked', 'cp_clear', 'cp_blocked', 'depart']}, {'state': 'train_on_line', 'alarms': []}), ('sampled regression 29', {'events': ['arrive_complete', 'depart', 'offer', 'depart', 'arrive_complete', 'arrive_no_tail', 'cp_clear']}, {'state': 'normal', 'alarms': ['unauthorised-departure', 'refused', 'unauthorised-departure', 'tail-missing']})], [('regression: second train into occupied block', {'events': ['offer', 'depart', 'depart']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure']}), ('boundary: departure without offer', {'events': ['depart', 'arrive_complete']}, {'state': 'normal', 'alarms': ['unauthorised-departure']}), ('sampled regression 78', {'events': ['cp_blocked', 'arrive_no_tail', 'depart', 'cancel', 'arrive_no_tail', 'depart']}, {'state': 'train_on_line', 'alarms': ['tail-missing', 'unauthorised-departure', 'tail-missing', 'unauthorised-departure']}), ('control 23', {'events': ['depart', 'cp_blocked', 'arrive_no_tail', 'offer', 'cp_clear']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure', 'tail-missing', 'refused']}), ('boundary: cancel of line clear', {'events': ['offer', 'cancel', 'offer']}, {'state': 'line_clear', 'alarms': []}), ('control 34', {'events': ['cp_blocked', 'arrive_no_tail', 'cancel', 'cp_clear', 'offer', 'arrive_complete', 'cp_blocked']}, {'state': 'line_clear', 'alarms': ['tail-missing']}), ('control 37', {'events': ['offer', 'depart', 'cp_clear', 'cp_clear']}, {'state': 'train_on_line', 'alarms': []}), ('control 40', {'events': ['arrive_complete', 'cp_clear', 'arrive_no_tail']}, {'state': 'normal', 'alarms': ['tail-missing']})], [('regression: second train into occupied block', {'events': ['offer', 'depart', 'depart']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure']}), ('boundary: departure without offer', {'events': ['depart', 'arrive_complete']}, {'state': 'normal', 'alarms': ['unauthorised-departure']}), ('sampled regression 16', {'events': ['arrive_complete', 'cp_blocked', 'depart', 'depart', 'offer', 'cp_clear', 'offer']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure', 'unauthorised-departure', 'refused', 'refused']}), ('sampled regression 30', {'events': ['depart', 'arrive_no_tail', 'depart', 'depart', 'offer', 'depart', 'depart', 'cp_blocked', 'arrive_no_tail', 'arrive_no_tail']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure', 'tail-missing', 'unauthorised-departure', 'unauthorised-departure', 'refused', 'unauthorised-departure', 'unauthorised-departure', 'tail-missing', 'tail-missing']}), ('boundary: offer with clearing point fouled', {'events': ['cp_blocked', 'offer', 'cp_clear', 'offer']}, {'state': 'line_clear', 'alarms': ['refused']}), ('sampled regression 45', {'events': ['depart', 'depart', 'depart', 'cp_blocked', 'depart', 'offer', 'arrive_complete', 'offer']}, {'state': 'normal', 'alarms': ['unauthorised-departure', 'unauthorised-departure', 'unauthorised-departure', 'unauthorised-departure', 'refused', 'refused']}), ('control 48', {'events': ['cp_clear', 'cp_blocked', 'arrive_no_tail', 'depart', 'offer', 'offer', 'arrive_no_tail', 'offer']}, {'state': 'train_on_line', 'alarms': ['tail-missing', 'unauthorised-departure', 'refused', 'refused', 'tail-missing', 'refused']}), ('control 51', {'events': ['cp_clear', 'cp_blocked', 'offer']}, {'state': 'normal', 'alarms': ['refused']})]]
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)

prompt:
A second train entering an occupied block raises no alarm.

A block section between two boxes is normal, line_clear or train_on_line. An offer is accepted (line_clear) only from normal with the clearing point clear, otherwise alarm refused. A departure without line clear raises unauthorised-departure; any departure puts the train on line. arrive_complete returns train_on_line to normal; arrive_no_tail raises tail-missing and keeps the block occupied. cancel only withdraws line_clear. cp_blocked/cp_clear set the clearing point.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    state = 'normal'
    cp = True
    alarms = []
    for ev in x['events']:
        if ev == 'cp_blocked':
            cp = False
        elif ev == 'cp_clear':
            cp = True
        elif ev == 'offer':
            if state == 'normal' and cp:
                state = 'line_clear'
            else:
                alarms.append('refused')
        elif ev == 'depart':
            if state != 'line_clear':
                alarms.append('unauthorised-departure')
            state = 'train_on_line'
        elif ev == 'arrive_complete':
            if state == 'train_on_line':
                state = 'normal'
        elif ev == 'arrive_no_tail':
            alarms.append('tail-missing')
            state = 'normal'
        elif ev == 'cancel':
            if state == 'line_clear':
                state = 'normal'
    return {'state': state, 'alarms': alarms}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: train arrives without tail lamp', {'events': ['offer', 'depart', 'arrive_no_tail', 'offer']}, {'state': 'train_on_line', 'alarms': ['tail-missing', 'refused']}), ('sampled regression 2', {'events': ['offer', 'arrive_no_tail', 'depart', 'offer', 'cancel', 'cancel', 'depart', 'cp_clear']}, {'state': 'train_on_line', 'alarms': ['tail-missing', 'refused', 'unauthorised-departure']}), ('sampled regression 4', {'events': ['cancel', 'arrive_no_tail', 'offer', 'offer', 'depart', 'arrive_no_tail']}, {'state': 'train_on_line', 'alarms': ['tail-missing', 'refused', 'tail-missing']}), ('boundary: offer with clearing point fouled', {'events': ['cp_blocked', 'offer', 'cp_clear', 'offer']}, {'state': 'line_clear', 'alarms': ['refused']}), ('boundary: second offer while line clear', {'events': ['offer', 'offer']}, {'state': 'line_clear', 'alarms': ['refused']}), ('control 1', {'events': ['cp_blocked', 'depart', 'arrive_no_tail', 'cp_clear', 'depart']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure', 'tail-missing', 'unauthorised-departure']}), ('sampled regression 7', {'events': ['offer', 'arrive_no_tail', 'arrive_complete', 'cp_clear', 'cp_clear', 'arrive_no_tail']}, {'state': 'line_clear', 'alarms': ['tail-missing', 'tail-missing']}), ('control 10', {'events': ['arrive_complete', 'cp_blocked', 'offer', 'arrive_complete', 'depart']}, {'state': 'train_on_line', 'alarms': ['refused', 'unauthorised-departure']})], [('regression: train arrives without tail lamp', {'events': ['offer', 'depart', 'arrive_no_tail', 'offer']}, {'state': 'train_on_line', 'alarms': ['tail-missing', 'refused']}), ('sampled regression 4', {'events': ['cancel', 'arrive_no_tail', 'offer', 'offer', 'depart', 'arrive_no_tail']}, {'state': 'train_on_line', 'alarms': ['tail-missing', 'refused', 'tail-missing']}), ('sampled regression 35', {'events': ['cp_clear', 'depart', 'cancel', 'cp_blocked', 'arrive_no_tail']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure', 'tail-missing']}), ('control 19', {'events': ['arrive_complete', 'cp_blocked', 'arrive_no_tail', 'depart', 'depart', 'offer', 'depart', 'cp_clear']}, {'state': 'train_on_line', 'alarms': ['tail-missing', 'unauthorised-departure', 'unauthorised-departure', 'refused', 'unauthorised-departure']}), ('boundary: second train into occupied block', {'events': ['offer', 'depart', 'depart']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure']}), ('control 12', {'events': ['depart', 'cp_clear', 'arrive_complete', 'depart', 'cp_blocked']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure', 'unauthorised-departure']}), ('control 15', {'events': ['arrive_complete', 'cp_clear', 'cancel']}, {'state': 'normal', 'alarms': []}), ('control 18', {'events': ['cp_clear', 'depart', 'offer', 'cp_blocked']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure', 'refused']})], [('regression: train arrives without tail lamp', {'events': ['offer', 'depart', 'arrive_no_tail', 'offer']}, {'state': 'train_on_line', 'alarms': ['tail-missing', 'refused']}), ('control 5', {'events': ['arrive_complete', 'cp_clear', 'offer', 'arrive_no_tail', 'cancel', 'depart', 'depart', 'arrive_complete', 'offer', 'cp_blocked']}, {'state': 'line_clear', 'alarms': ['tail-missing', 'unauthorised-departure', 'unauthorised-departure']}), ('sampled regression 64', {'events': ['arrive_complete', 'depart', 'offer', 'depart', 'cancel', 'depart', 'arrive_no_tail', 'offer', 'offer', 'offer']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure', 'refused', 'unauthorised-departure', 'unauthorised-departure', 'tail-missing', 'refused', 'refused', 'refused']}), ('control 34', {'events': ['cp_blocked', 'arrive_no_tail', 'cancel', 'cp_clear', 'offer', 'arrive_complete', 'cp_blocked']}, {'state': 'line_clear', 'alarms': ['tail-missing']}), ('boundary: cancel with train on line', {'events': ['offer', 'depart', 'cancel', 'offer']}, {'state': 'train_on_line', 'alarms': ['refused']}), ('sampled regression 23', {'events': ['depart', 'cp_blocked', 'arrive_no_tail', 'offer', 'cp_clear']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure', 'tail-missing', 'refused']}), ('control 26', {'events': ['cp_clear', 'offer', 'cp_clear', 'cp_clear', 'cp_blocked', 'cp_clear', 'cp_blocked', 'depart']}, {'state': 'train_on_line', 'alarms': []}), ('control 29', {'events': ['arrive_complete', 'depart', 'offer', 'depart', 'arrive_complete', 'arrive_no_tail', 'cp_clear']}, {'state': 'normal', 'alarms': ['unauthorised-departure', 'refused', 'unauthorised-departure', 'tail-missing']})], [('regression: train arrives without tail lamp', {'events': ['offer', 'depart', 'arrive_no_tail', 'offer']}, {'state': 'train_on_line', 'alarms': ['tail-missing', 'refused']}), ('control 6', {'events': ['arrive_no_tail', 'depart', 'offer']}, {'state': 'train_on_line', 'alarms': ['tail-missing', 'unauthorised-departure', 'refused']}), ('sampled regression 4', {'events': ['cancel', 'arrive_no_tail', 'offer', 'offer', 'depart', 'arrive_no_tail']}, {'state': 'train_on_line', 'alarms': ['tail-missing', 'refused', 'tail-missing']}), ('sampled regression 46', {'events': ['offer', 'offer', 'arrive_complete', 'arrive_no_tail', 'cp_clear', 'arrive_complete', 'cancel', 'arrive_no_tail', 'offer', 'arrive_no_tail']}, {'state': 'line_clear', 'alarms': ['refused', 'tail-missing', 'tail-missing', 'tail-missing']}), ('boundary: cancel of line clear', {'events': ['offer', 'cancel', 'offer']}, {'state': 'line_clear', 'alarms': []}), ('control 34', {'events': ['cp_blocked', 'arrive_no_tail', 'cancel', 'cp_clear', 'offer', 'arrive_complete', 'cp_blocked']}, {'state': 'line_clear', 'alarms': ['tail-missing']}), ('control 37', {'events': ['offer', 'depart', 'cp_clear', 'cp_clear']}, {'state': 'train_on_line', 'alarms': []}), ('control 40', {'events': ['arrive_complete', 'cp_clear', 'arrive_no_tail']}, {'state': 'normal', 'alarms': ['tail-missing']})], [('regression: train arrives without tail lamp', {'events': ['offer', 'depart', 'arrive_no_tail', 'offer']}, {'state': 'train_on_line', 'alarms': ['tail-missing', 'refused']}), ('sampled regression 7', {'events': ['offer', 'arrive_no_tail', 'arrive_complete', 'cp_clear', 'cp_clear', 'arrive_no_tail']}, {'state': 'line_clear', 'alarms': ['tail-missing', 'tail-missing']}), ('sampled regression 35', {'events': ['cp_clear', 'depart', 'cancel', 'cp_blocked', 'arrive_no_tail']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure', 'tail-missing']}), ('sampled regression 54', {'events': ['offer', 'arrive_no_tail', 'offer', 'depart', 'arrive_complete', 'offer', 'cp_blocked']}, {'state': 'line_clear', 'alarms': ['tail-missing', 'refused']}), ('boundary: offer with clearing point fouled', {'events': ['cp_blocked', 'offer', 'cp_clear', 'offer']}, {'state': 'line_clear', 'alarms': ['refused']}), ('control 45', {'events': ['depart', 'depart', 'depart', 'cp_blocked', 'depart', 'offer', 'arrive_complete', 'offer']}, {'state': 'normal', 'alarms': ['unauthorised-departure', 'unauthorised-departure', 'unauthorised-departure', 'unauthorised-departure', 'refused', 'refused']}), ('sampled regression 48', {'events': ['cp_clear', 'cp_blocked', 'arrive_no_tail', 'depart', 'offer', 'offer', 'arrive_no_tail', 'offer']}, {'state': 'train_on_line', 'alarms': ['tail-missing', 'unauthorised-departure', 'refused', 'refused', 'tail-missing', 'refused']}), ('control 51', {'events': ['cp_clear', 'cp_blocked', 'offer']}, {'state': 'normal', 'alarms': ['refused']})]]
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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    state = 'normal'
    cp = True
    alarms = []
    for ev in x['events']:
        if ev == 'cp_blocked':
            cp = False
        elif ev == 'cp_clear':
            cp = True
        elif ev == 'offer':
            if state == 'normal' and cp:
                state = 'line_clear'
            else:
                alarms.append('refused')
        elif ev == 'depart':
            if state != 'line_clear':
                alarms.append('unauthorised-departure')
            state = 'train_on_line'
        elif ev == 'arrive_complete':
            if state == 'train_on_line':
                state = 'normal'
        elif ev == 'arrive_no_tail':
            if state == 'train_on_line':
                alarms.append('tail-missing')
        elif ev == 'cancel':
            if state == 'line_clear':
                state = 'normal'
    return {'state': state, 'alarms': alarms}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: train arrives without tail lamp', {'events': ['offer', 'depart', 'arrive_no_tail', 'offer']}, {'state': 'train_on_line', 'alarms': ['tail-missing', 'refused']}), ('sampled regression 2', {'events': ['offer', 'arrive_no_tail', 'depart', 'offer', 'cancel', 'cancel', 'depart', 'cp_clear']}, {'state': 'train_on_line', 'alarms': ['tail-missing', 'refused', 'unauthorised-departure']}), ('sampled regression 4', {'events': ['cancel', 'arrive_no_tail', 'offer', 'offer', 'depart', 'arrive_no_tail']}, {'state': 'train_on_line', 'alarms': ['tail-missing', 'refused', 'tail-missing']}), ('boundary: offer with clearing point fouled', {'events': ['cp_blocked', 'offer', 'cp_clear', 'offer']}, {'state': 'line_clear', 'alarms': ['refused']}), ('boundary: second offer while line clear', {'events': ['offer', 'offer']}, {'state': 'line_clear', 'alarms': ['refused']}), ('control 1', {'events': ['cp_blocked', 'depart', 'arrive_no_tail', 'cp_clear', 'depart']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure', 'tail-missing', 'unauthorised-departure']}), ('sampled regression 7', {'events': ['offer', 'arrive_no_tail', 'arrive_complete', 'cp_clear', 'cp_clear', 'arrive_no_tail']}, {'state': 'line_clear', 'alarms': ['tail-missing', 'tail-missing']}), ('control 10', {'events': ['arrive_complete', 'cp_blocked', 'offer', 'arrive_complete', 'depart']}, {'state': 'train_on_line', 'alarms': ['refused', 'unauthorised-departure']})], [('regression: train arrives without tail lamp', {'events': ['offer', 'depart', 'arrive_no_tail', 'offer']}, {'state': 'train_on_line', 'alarms': ['tail-missing', 'refused']}), ('sampled regression 4', {'events': ['cancel', 'arrive_no_tail', 'offer', 'offer', 'depart', 'arrive_no_tail']}, {'state': 'train_on_line', 'alarms': ['tail-missing', 'refused', 'tail-missing']}), ('sampled regression 35', {'events': ['cp_clear', 'depart', 'cancel', 'cp_blocked', 'arrive_no_tail']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure', 'tail-missing']}), ('control 19', {'events': ['arrive_complete', 'cp_blocked', 'arrive_no_tail', 'depart', 'depart', 'offer', 'depart', 'cp_clear']}, {'state': 'train_on_line', 'alarms': ['tail-missing', 'unauthorised-departure', 'unauthorised-departure', 'refused', 'unauthorised-departure']}), ('boundary: second train into occupied block', {'events': ['offer', 'depart', 'depart']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure']}), ('control 12', {'events': ['depart', 'cp_clear', 'arrive_complete', 'depart', 'cp_blocked']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure', 'unauthorised-departure']}), ('control 15', {'events': ['arrive_complete', 'cp_clear', 'cancel']}, {'state': 'normal', 'alarms': []}), ('control 18', {'events': ['cp_clear', 'depart', 'offer', 'cp_blocked']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure', 'refused']})], [('regression: train arrives without tail lamp', {'events': ['offer', 'depart', 'arrive_no_tail', 'offer']}, {'state': 'train_on_line', 'alarms': ['tail-missing', 'refused']}), ('control 5', {'events': ['arrive_complete', 'cp_clear', 'offer', 'arrive_no_tail', 'cancel', 'depart', 'depart', 'arrive_complete', 'offer', 'cp_blocked']}, {'state': 'line_clear', 'alarms': ['tail-missing', 'unauthorised-departure', 'unauthorised-departure']}), ('sampled regression 64', {'events': ['arrive_complete', 'depart', 'offer', 'depart', 'cancel', 'depart', 'arrive_no_tail', 'offer', 'offer', 'offer']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure', 'refused', 'unauthorised-departure', 'unauthorised-departure', 'tail-missing', 'refused', 'refused', 'refused']}), ('control 34', {'events': ['cp_blocked', 'arrive_no_tail', 'cancel', 'cp_clear', 'offer', 'arrive_complete', 'cp_blocked']}, {'state': 'line_clear', 'alarms': ['tail-missing']}), ('boundary: cancel with train on line', {'events': ['offer', 'depart', 'cancel', 'offer']}, {'state': 'train_on_line', 'alarms': ['refused']}), ('sampled regression 23', {'events': ['depart', 'cp_blocked', 'arrive_no_tail', 'offer', 'cp_clear']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure', 'tail-missing', 'refused']}), ('control 26', {'events': ['cp_clear', 'offer', 'cp_clear', 'cp_clear', 'cp_blocked', 'cp_clear', 'cp_blocked', 'depart']}, {'state': 'train_on_line', 'alarms': []}), ('control 29', {'events': ['arrive_complete', 'depart', 'offer', 'depart', 'arrive_complete', 'arrive_no_tail', 'cp_clear']}, {'state': 'normal', 'alarms': ['unauthorised-departure', 'refused', 'unauthorised-departure', 'tail-missing']})], [('regression: train arrives without tail lamp', {'events': ['offer', 'depart', 'arrive_no_tail', 'offer']}, {'state': 'train_on_line', 'alarms': ['tail-missing', 'refused']}), ('control 6', {'events': ['arrive_no_tail', 'depart', 'offer']}, {'state': 'train_on_line', 'alarms': ['tail-missing', 'unauthorised-departure', 'refused']}), ('sampled regression 4', {'events': ['cancel', 'arrive_no_tail', 'offer', 'offer', 'depart', 'arrive_no_tail']}, {'state': 'train_on_line', 'alarms': ['tail-missing', 'refused', 'tail-missing']}), ('sampled regression 46', {'events': ['offer', 'offer', 'arrive_complete', 'arrive_no_tail', 'cp_clear', 'arrive_complete', 'cancel', 'arrive_no_tail', 'offer', 'arrive_no_tail']}, {'state': 'line_clear', 'alarms': ['refused', 'tail-missing', 'tail-missing', 'tail-missing']}), ('boundary: cancel of line clear', {'events': ['offer', 'cancel', 'offer']}, {'state': 'line_clear', 'alarms': []}), ('control 34', {'events': ['cp_blocked', 'arrive_no_tail', 'cancel', 'cp_clear', 'offer', 'arrive_complete', 'cp_blocked']}, {'state': 'line_clear', 'alarms': ['tail-missing']}), ('control 37', {'events': ['offer', 'depart', 'cp_clear', 'cp_clear']}, {'state': 'train_on_line', 'alarms': []}), ('control 40', {'events': ['arrive_complete', 'cp_clear', 'arrive_no_tail']}, {'state': 'normal', 'alarms': ['tail-missing']})], [('regression: train arrives without tail lamp', {'events': ['offer', 'depart', 'arrive_no_tail', 'offer']}, {'state': 'train_on_line', 'alarms': ['tail-missing', 'refused']}), ('sampled regression 7', {'events': ['offer', 'arrive_no_tail', 'arrive_complete', 'cp_clear', 'cp_clear', 'arrive_no_tail']}, {'state': 'line_clear', 'alarms': ['tail-missing', 'tail-missing']}), ('sampled regression 35', {'events': ['cp_clear', 'depart', 'cancel', 'cp_blocked', 'arrive_no_tail']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure', 'tail-missing']}), ('sampled regression 54', {'events': ['offer', 'arrive_no_tail', 'offer', 'depart', 'arrive_complete', 'offer', 'cp_blocked']}, {'state': 'line_clear', 'alarms': ['tail-missing', 'refused']}), ('boundary: offer with clearing point fouled', {'events': ['cp_blocked', 'offer', 'cp_clear', 'offer']}, {'state': 'line_clear', 'alarms': ['refused']}), ('control 45', {'events': ['depart', 'depart', 'depart', 'cp_blocked', 'depart', 'offer', 'arrive_complete', 'offer']}, {'state': 'normal', 'alarms': ['unauthorised-departure', 'unauthorised-departure', 'unauthorised-departure', 'unauthorised-departure', 'refused', 'refused']}), ('sampled regression 48', {'events': ['cp_clear', 'cp_blocked', 'arrive_no_tail', 'depart', 'offer', 'offer', 'arrive_no_tail', 'offer']}, {'state': 'train_on_line', 'alarms': ['tail-missing', 'unauthorised-departure', 'refused', 'refused', 'tail-missing', 'refused']}), ('control 51', {'events': ['cp_clear', 'cp_blocked', 'offer']}, {'state': 'normal', 'alarms': ['refused']})]]
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)

prompt:
The block is released although the train arrived without its tail lamp.

A block section between two boxes is normal, line_clear or train_on_line. An offer is accepted (line_clear) only from normal with the clearing point clear, otherwise alarm refused. A departure without line clear raises unauthorised-departure; any departure puts the train on line. arrive_complete returns train_on_line to normal; arrive_no_tail raises tail-missing and keeps the block occupied. cancel only withdraws line_clear. cp_blocked/cp_clear set the clearing point.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    state = 'normal'
    cp = True
    alarms = []
    for ev in x['events']:
        if ev == 'cp_blocked':
            cp = False
        elif ev == 'cp_clear':
            cp = True
        elif ev == 'offer':
            if state == 'normal' and cp:
                state = 'line_clear'
            else:
                alarms.append('refused')
        elif ev == 'depart':
            if state != 'line_clear':
                alarms.append('unauthorised-departure')
            state = 'train_on_line'
        elif ev == 'arrive_complete':
            if state == 'train_on_line':
                state = 'normal'
        elif ev == 'arrive_no_tail':
            alarms.append('tail-missing')
        elif ev == 'cancel':
            if state != 'normal':
                state = 'normal'
    return {'state': state, 'alarms': alarms}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: cancel with train on line', {'events': ['offer', 'depart', 'cancel', 'offer']}, {'state': 'train_on_line', 'alarms': ['refused']}), ('sampled regression 35', {'events': ['cp_clear', 'depart', 'cancel', 'cp_blocked', 'arrive_no_tail']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure', 'tail-missing']}), ('sampled regression 22', {'events': ['depart', 'cp_clear', 'offer', 'arrive_no_tail', 'cancel', 'cancel', 'arrive_no_tail']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure', 'refused', 'tail-missing', 'tail-missing']}), ('boundary: offer with clearing point fouled', {'events': ['cp_blocked', 'offer', 'cp_clear', 'offer']}, {'state': 'line_clear', 'alarms': ['refused']}), ('boundary: second offer while line clear', {'events': ['offer', 'offer']}, {'state': 'line_clear', 'alarms': ['refused']}), ('control 1', {'events': ['cp_blocked', 'depart', 'arrive_no_tail', 'cp_clear', 'depart']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure', 'tail-missing', 'unauthorised-departure']}), ('control 4', {'events': ['cancel', 'arrive_no_tail', 'offer', 'offer', 'depart', 'arrive_no_tail']}, {'state': 'train_on_line', 'alarms': ['tail-missing', 'refused', 'tail-missing']}), ('control 7', {'events': ['offer', 'arrive_no_tail', 'arrive_complete', 'cp_clear', 'cp_clear', 'arrive_no_tail']}, {'state': 'line_clear', 'alarms': ['tail-missing', 'tail-missing']})], [('regression: cancel with train on line', {'events': ['offer', 'depart', 'cancel', 'offer']}, {'state': 'train_on_line', 'alarms': ['refused']}), ('sampled regression 35', {'events': ['cp_clear', 'depart', 'cancel', 'cp_blocked', 'arrive_no_tail']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure', 'tail-missing']}), ('boundary: second train into occupied block', {'events': ['offer', 'depart', 'depart']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure']}), ('boundary: departure without offer', {'events': ['depart', 'arrive_complete']}, {'state': 'normal', 'alarms': ['unauthorised-departure']}), ('boundary: train arrives without tail lamp', {'events': ['offer', 'depart', 'arrive_no_tail', 'offer']}, {'state': 'train_on_line', 'alarms': ['tail-missing', 'refused']}), ('control 12', {'events': ['depart', 'cp_clear', 'arrive_complete', 'depart', 'cp_blocked']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure', 'unauthorised-departure']}), ('control 15', {'events': ['arrive_complete', 'cp_clear', 'cancel']}, {'state': 'normal', 'alarms': []}), ('control 18', {'events': ['cp_clear', 'depart', 'offer', 'cp_blocked']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure', 'refused']})], [('regression: cancel with train on line', {'events': ['offer', 'depart', 'cancel', 'offer']}, {'state': 'train_on_line', 'alarms': ['refused']}), ('sampled regression 35', {'events': ['cp_clear', 'depart', 'cancel', 'cp_blocked', 'arrive_no_tail']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure', 'tail-missing']}), ('sampled regression 80', {'events': ['depart', 'offer', 'depart', 'cancel', 'cp_clear', 'arrive_no_tail', 'offer', 'cancel', 'offer', 'cancel']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure', 'refused', 'unauthorised-departure', 'tail-missing', 'refused', 'refused']}), ('boundary: train arrives without tail lamp', {'events': ['offer', 'depart', 'arrive_no_tail', 'offer']}, {'state': 'train_on_line', 'alarms': ['tail-missing', 'refused']}), ('boundary: cancel of line clear', {'events': ['offer', 'cancel', 'offer']}, {'state': 'line_clear', 'alarms': []}), ('control 23', {'events': ['depart', 'cp_blocked', 'arrive_no_tail', 'offer', 'cp_clear']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure', 'tail-missing', 'refused']}), ('control 26', {'events': ['cp_clear', 'offer', 'cp_clear', 'cp_clear', 'cp_blocked', 'cp_clear', 'cp_blocked', 'depart']}, {'state': 'train_on_line', 'alarms': []}), ('control 29', {'events': ['arrive_complete', 'depart', 'offer', 'depart', 'arrive_complete', 'arrive_no_tail', 'cp_clear']}, {'state': 'normal', 'alarms': ['unauthorised-departure', 'refused', 'unauthorised-departure', 'tail-missing']})], [('regression: cancel with train on line', {'events': ['offer', 'depart', 'cancel', 'offer']}, {'state': 'train_on_line', 'alarms': ['refused']}), ('sampled regression 35', {'events': ['cp_clear', 'depart', 'cancel', 'cp_blocked', 'arrive_no_tail']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure', 'tail-missing']}), ('control 76', {'events': ['offer', 'offer', 'cp_blocked', 'cancel', 'cp_blocked', 'cp_blocked', 'cp_blocked', 'offer']}, {'state': 'normal', 'alarms': ['refused', 'refused']}), ('boundary: cancel of line clear', {'events': ['offer', 'cancel', 'offer']}, {'state': 'line_clear', 'alarms': []}), ('boundary: arrival report while only line clear', {'events': ['offer', 'arrive_complete', 'depart']}, {'state': 'train_on_line', 'alarms': []}), ('control 34', {'events': ['cp_blocked', 'arrive_no_tail', 'cancel', 'cp_clear', 'offer', 'arrive_complete', 'cp_blocked']}, {'state': 'line_clear', 'alarms': ['tail-missing']}), ('control 37', {'events': ['offer', 'depart', 'cp_clear', 'cp_clear']}, {'state': 'train_on_line', 'alarms': []}), ('control 40', {'events': ['arrive_complete', 'cp_clear', 'arrive_no_tail']}, {'state': 'normal', 'alarms': ['tail-missing']})], [('regression: cancel with train on line', {'events': ['offer', 'depart', 'cancel', 'offer']}, {'state': 'train_on_line', 'alarms': ['refused']}), ('sampled regression 35', {'events': ['cp_clear', 'depart', 'cancel', 'cp_blocked', 'arrive_no_tail']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure', 'tail-missing']}), ('sampled regression 65', {'events': ['offer', 'depart', 'arrive_complete', 'depart', 'cancel']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure']}), ('boundary: offer with clearing point fouled', {'events': ['cp_blocked', 'offer', 'cp_clear', 'offer']}, {'state': 'line_clear', 'alarms': ['refused']}), ('boundary: second offer while line clear', {'events': ['offer', 'offer']}, {'state': 'line_clear', 'alarms': ['refused']}), ('control 45', {'events': ['depart', 'depart', 'depart', 'cp_blocked', 'depart', 'offer', 'arrive_complete', 'offer']}, {'state': 'normal', 'alarms': ['unauthorised-departure', 'unauthorised-departure', 'unauthorised-departure', 'unauthorised-departure', 'refused', 'refused']}), ('control 48', {'events': ['cp_clear', 'cp_blocked', 'arrive_no_tail', 'depart', 'offer', 'offer', 'arrive_no_tail', 'offer']}, {'state': 'train_on_line', 'alarms': ['tail-missing', 'unauthorised-departure', 'refused', 'refused', 'tail-missing', 'refused']}), ('control 51', {'events': ['cp_clear', 'cp_blocked', 'offer']}, {'state': 'normal', 'alarms': ['refused']})]]
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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    state = 'normal'
    cp = True
    alarms = []
    for ev in x['events']:
        if ev == 'cp_blocked':
            cp = False
        elif ev == 'cp_clear':
            cp = True
        elif ev == 'offer':
            if state == 'normal' and cp:
                state = 'line_clear'
            else:
                alarms.append('refused')
        elif ev == 'depart':
            if state != 'line_clear':
                alarms.append('unauthorised-departure')
            state = 'train_on_line'
        elif ev == 'arrive_complete':
            if state == 'train_on_line':
                state = 'normal'
        elif ev == 'arrive_no_tail':
            alarms.append('tail-missing')
        elif ev == 'cancel':
            if state != 'normal' and cp:
                state = 'normal'
    return {'state': state, 'alarms': alarms}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: cancel with train on line', {'events': ['offer', 'depart', 'cancel', 'offer']}, {'state': 'train_on_line', 'alarms': ['refused']}), ('sampled regression 35', {'events': ['cp_clear', 'depart', 'cancel', 'cp_blocked', 'arrive_no_tail']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure', 'tail-missing']}), ('sampled regression 22', {'events': ['depart', 'cp_clear', 'offer', 'arrive_no_tail', 'cancel', 'cancel', 'arrive_no_tail']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure', 'refused', 'tail-missing', 'tail-missing']}), ('boundary: offer with clearing point fouled', {'events': ['cp_blocked', 'offer', 'cp_clear', 'offer']}, {'state': 'line_clear', 'alarms': ['refused']}), ('boundary: second offer while line clear', {'events': ['offer', 'offer']}, {'state': 'line_clear', 'alarms': ['refused']}), ('control 1', {'events': ['cp_blocked', 'depart', 'arrive_no_tail', 'cp_clear', 'depart']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure', 'tail-missing', 'unauthorised-departure']}), ('control 4', {'events': ['cancel', 'arrive_no_tail', 'offer', 'offer', 'depart', 'arrive_no_tail']}, {'state': 'train_on_line', 'alarms': ['tail-missing', 'refused', 'tail-missing']}), ('control 7', {'events': ['offer', 'arrive_no_tail', 'arrive_complete', 'cp_clear', 'cp_clear', 'arrive_no_tail']}, {'state': 'line_clear', 'alarms': ['tail-missing', 'tail-missing']})], [('regression: cancel with train on line', {'events': ['offer', 'depart', 'cancel', 'offer']}, {'state': 'train_on_line', 'alarms': ['refused']}), ('sampled regression 35', {'events': ['cp_clear', 'depart', 'cancel', 'cp_blocked', 'arrive_no_tail']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure', 'tail-missing']}), ('boundary: second train into occupied block', {'events': ['offer', 'depart', 'depart']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure']}), ('boundary: departure without offer', {'events': ['depart', 'arrive_complete']}, {'state': 'normal', 'alarms': ['unauthorised-departure']}), ('boundary: train arrives without tail lamp', {'events': ['offer', 'depart', 'arrive_no_tail', 'offer']}, {'state': 'train_on_line', 'alarms': ['tail-missing', 'refused']}), ('control 12', {'events': ['depart', 'cp_clear', 'arrive_complete', 'depart', 'cp_blocked']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure', 'unauthorised-departure']}), ('control 15', {'events': ['arrive_complete', 'cp_clear', 'cancel']}, {'state': 'normal', 'alarms': []}), ('control 18', {'events': ['cp_clear', 'depart', 'offer', 'cp_blocked']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure', 'refused']})], [('regression: cancel with train on line', {'events': ['offer', 'depart', 'cancel', 'offer']}, {'state': 'train_on_line', 'alarms': ['refused']}), ('sampled regression 35', {'events': ['cp_clear', 'depart', 'cancel', 'cp_blocked', 'arrive_no_tail']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure', 'tail-missing']}), ('sampled regression 80', {'events': ['depart', 'offer', 'depart', 'cancel', 'cp_clear', 'arrive_no_tail', 'offer', 'cancel', 'offer', 'cancel']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure', 'refused', 'unauthorised-departure', 'tail-missing', 'refused', 'refused']}), ('boundary: train arrives without tail lamp', {'events': ['offer', 'depart', 'arrive_no_tail', 'offer']}, {'state': 'train_on_line', 'alarms': ['tail-missing', 'refused']}), ('boundary: cancel of line clear', {'events': ['offer', 'cancel', 'offer']}, {'state': 'line_clear', 'alarms': []}), ('control 23', {'events': ['depart', 'cp_blocked', 'arrive_no_tail', 'offer', 'cp_clear']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure', 'tail-missing', 'refused']}), ('control 26', {'events': ['cp_clear', 'offer', 'cp_clear', 'cp_clear', 'cp_blocked', 'cp_clear', 'cp_blocked', 'depart']}, {'state': 'train_on_line', 'alarms': []}), ('control 29', {'events': ['arrive_complete', 'depart', 'offer', 'depart', 'arrive_complete', 'arrive_no_tail', 'cp_clear']}, {'state': 'normal', 'alarms': ['unauthorised-departure', 'refused', 'unauthorised-departure', 'tail-missing']})], [('regression: cancel with train on line', {'events': ['offer', 'depart', 'cancel', 'offer']}, {'state': 'train_on_line', 'alarms': ['refused']}), ('sampled regression 35', {'events': ['cp_clear', 'depart', 'cancel', 'cp_blocked', 'arrive_no_tail']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure', 'tail-missing']}), ('control 76', {'events': ['offer', 'offer', 'cp_blocked', 'cancel', 'cp_blocked', 'cp_blocked', 'cp_blocked', 'offer']}, {'state': 'normal', 'alarms': ['refused', 'refused']}), ('boundary: cancel of line clear', {'events': ['offer', 'cancel', 'offer']}, {'state': 'line_clear', 'alarms': []}), ('boundary: arrival report while only line clear', {'events': ['offer', 'arrive_complete', 'depart']}, {'state': 'train_on_line', 'alarms': []}), ('control 34', {'events': ['cp_blocked', 'arrive_no_tail', 'cancel', 'cp_clear', 'offer', 'arrive_complete', 'cp_blocked']}, {'state': 'line_clear', 'alarms': ['tail-missing']}), ('control 37', {'events': ['offer', 'depart', 'cp_clear', 'cp_clear']}, {'state': 'train_on_line', 'alarms': []}), ('control 40', {'events': ['arrive_complete', 'cp_clear', 'arrive_no_tail']}, {'state': 'normal', 'alarms': ['tail-missing']})], [('regression: cancel with train on line', {'events': ['offer', 'depart', 'cancel', 'offer']}, {'state': 'train_on_line', 'alarms': ['refused']}), ('sampled regression 35', {'events': ['cp_clear', 'depart', 'cancel', 'cp_blocked', 'arrive_no_tail']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure', 'tail-missing']}), ('sampled regression 65', {'events': ['offer', 'depart', 'arrive_complete', 'depart', 'cancel']}, {'state': 'train_on_line', 'alarms': ['unauthorised-departure']}), ('boundary: offer with clearing point fouled', {'events': ['cp_blocked', 'offer', 'cp_clear', 'offer']}, {'state': 'line_clear', 'alarms': ['refused']}), ('boundary: second offer while line clear', {'events': ['offer', 'offer']}, {'state': 'line_clear', 'alarms': ['refused']}), ('control 45', {'events': ['depart', 'depart', 'depart', 'cp_blocked', 'depart', 'offer', 'arrive_complete', 'offer']}, {'state': 'normal', 'alarms': ['unauthorised-departure', 'unauthorised-departure', 'unauthorised-departure', 'unauthorised-departure', 'refused', 'refused']}), ('control 48', {'events': ['cp_clear', 'cp_blocked', 'arrive_no_tail', 'depart', 'offer', 'offer', 'arrive_no_tail', 'offer']}, {'state': 'train_on_line', 'alarms': ['tail-missing', 'unauthorised-departure', 'refused', 'refused', 'tail-missing', 'refused']}), ('control 51', {'events': ['cp_clear', 'cp_blocked', 'offer']}, {'state': 'normal', 'alarms': ['refused']})]]
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)

prompt:
Cancelling a block with a train in it frees the section.

A block section between two boxes is normal, line_clear or train_on_line. An offer is accepted (line_clear) only from normal with the clearing point clear, otherwise alarm refused. A departure without line clear raises unauthorised-departure; any departure puts the train on line. arrive_complete returns train_on_line to normal; arrive_no_tail raises tail-missing and keeps the block occupied. cancel only withdraws line_clear. cp_blocked/cp_clear set the clearing point.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(x):
    vt = x['target_kmh'] / 3.6
    d = x['distance_m']
    a = x['decel_cms2'] / 100
    vp = math.sqrt(vt * vt + 2 * a * d) * 3.6
    permitted = min(int(vp), x['line_kmh'])
    v = x['speed_kmh']
    if v > permitted + x['brake_margin_kmh']:
        action = 'brake'
    elif v > permitted + x['warn_margin_kmh']:
        action = 'warning'
    else:
        action = 'none'
    return {'permitted': permitted, 'action': action}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: stop target inside the margin', {'target_kmh': 0, 'distance_m': 40, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 10, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 0, 'action': 'warning'}), ('sampled regression 4', {'target_kmh': 0, 'distance_m': 100, 'safety_margin_m': 20, 'decel_cms2': 100, 'line_kmh': 80, 'speed_kmh': 136, 'warn_margin_kmh': 5, 'brake_margin_kmh': 15}, {'permitted': 45, 'action': 'brake'}), ('boundary: target speed release', {'target_kmh': 40, 'distance_m': 0, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 44, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 40, 'action': 'none'}), ('regression: curve below line speed', {'target_kmh': 0, 'distance_m': 600, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 100, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 99, 'action': 'none'}), ('boundary: curve above line speed', {'target_kmh': 0, 'distance_m': 2500, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 120, 'speed_kmh': 150, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 120, 'action': 'brake'}), ('control 1', {'target_kmh': 0, 'distance_m': 0, 'safety_margin_m': 0, 'decel_cms2': 100, 'line_kmh': 160, 'speed_kmh': 139, 'warn_margin_kmh': 5, 'brake_margin_kmh': 15}, {'permitted': 0, 'action': 'brake'}), ('control 7', {'target_kmh': 40, 'distance_m': 2500, 'safety_margin_m': 20, 'decel_cms2': 50, 'line_kmh': 160, 'speed_kmh': 59, 'warn_margin_kmh': 3, 'brake_margin_kmh': 10}, {'permitted': 160, 'action': 'none'}), ('sampled regression 10', {'target_kmh': 20, 'distance_m': 40, 'safety_margin_m': 20, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 33, 'warn_margin_kmh': 5, 'brake_margin_kmh': 15}, {'permitted': 27, 'action': 'warning'})], [('regression: curve below line speed', {'target_kmh': 0, 'distance_m': 600, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 100, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 99, 'action': 'none'}), ('boundary: target speed release', {'target_kmh': 40, 'distance_m': 0, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 44, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 40, 'action': 'none'}), ('sampled regression 19', {'target_kmh': 0, 'distance_m': 40, 'safety_margin_m': 50, 'decel_cms2': 100, 'line_kmh': 160, 'speed_kmh': 17, 'warn_margin_kmh': 3, 'brake_margin_kmh': 15}, {'permitted': 0, 'action': 'brake'}), ('sampled regression 2', {'target_kmh': 0, 'distance_m': 250, 'safety_margin_m': 50, 'decel_cms2': 50, 'line_kmh': 160, 'speed_kmh': 122, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 50, 'action': 'brake'}), ('boundary: curve above line speed', {'target_kmh': 0, 'distance_m': 2500, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 120, 'speed_kmh': 150, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 120, 'action': 'brake'}), ('sampled regression 12', {'target_kmh': 40, 'distance_m': 600, 'safety_margin_m': 20, 'decel_cms2': 100, 'line_kmh': 160, 'speed_kmh': 133, 'warn_margin_kmh': 3, 'brake_margin_kmh': 15}, {'permitted': 128, 'action': 'warning'}), ('sampled regression 15', {'target_kmh': 0, 'distance_m': 600, 'safety_margin_m': 20, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 43, 'warn_margin_kmh': 3, 'brake_margin_kmh': 10}, {'permitted': 102, 'action': 'none'}), ('control 18', {'target_kmh': 60, 'distance_m': 1200, 'safety_margin_m': 20, 'decel_cms2': 70, 'line_kmh': 120, 'speed_kmh': 6, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 120, 'action': 'none'})], [('regression: stop target inside the margin', {'target_kmh': 0, 'distance_m': 40, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 10, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 0, 'action': 'warning'}), ('regression: curve below line speed', {'target_kmh': 0, 'distance_m': 600, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 100, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 99, 'action': 'none'}), ('sampled regression 42', {'target_kmh': 40, 'distance_m': 40, 'safety_margin_m': 20, 'decel_cms2': 50, 'line_kmh': 160, 'speed_kmh': 115, 'warn_margin_kmh': 5, 'brake_margin_kmh': 8}, {'permitted': 43, 'action': 'brake'}), ('sampled regression 11', {'target_kmh': 0, 'distance_m': 250, 'safety_margin_m': 20, 'decel_cms2': 100, 'line_kmh': 120, 'speed_kmh': 158, 'warn_margin_kmh': 5, 'brake_margin_kmh': 15}, {'permitted': 77, 'action': 'brake'}), ('boundary: warning boundary', {'target_kmh': 40, 'distance_m': 0, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 45, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 40, 'action': 'none'}), ('sampled regression 23', {'target_kmh': 60, 'distance_m': 100, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 80, 'speed_kmh': 13, 'warn_margin_kmh': 5, 'brake_margin_kmh': 8}, {'permitted': 67, 'action': 'none'}), ('control 26', {'target_kmh': 60, 'distance_m': 2500, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 86, 'warn_margin_kmh': 3, 'brake_margin_kmh': 10}, {'permitted': 160, 'action': 'none'}), ('control 29', {'target_kmh': 0, 'distance_m': 250, 'safety_margin_m': 0, 'decel_cms2': 70, 'line_kmh': 120, 'speed_kmh': 4, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 67, 'action': 'none'})], [('regression: curve below line speed', {'target_kmh': 0, 'distance_m': 600, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 100, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 99, 'action': 'none'}), ('boundary: warning boundary', {'target_kmh': 40, 'distance_m': 0, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 45, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 40, 'action': 'none'}), ('sampled regression 54', {'target_kmh': 60, 'distance_m': 1200, 'safety_margin_m': 20, 'decel_cms2': 50, 'line_kmh': 160, 'speed_kmh': 118, 'warn_margin_kmh': 3, 'brake_margin_kmh': 8}, {'permitted': 137, 'action': 'none'}), ('sampled regression 23', {'target_kmh': 60, 'distance_m': 100, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 80, 'speed_kmh': 13, 'warn_margin_kmh': 5, 'brake_margin_kmh': 8}, {'permitted': 67, 'action': 'none'}), ('boundary: between warning and brake', {'target_kmh': 40, 'distance_m': 0, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 48, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 40, 'action': 'warning'}), ('control 34', {'target_kmh': 0, 'distance_m': 0, 'safety_margin_m': 0, 'decel_cms2': 70, 'line_kmh': 120, 'speed_kmh': 96, 'warn_margin_kmh': 5, 'brake_margin_kmh': 15}, {'permitted': 0, 'action': 'brake'}), ('control 37', {'target_kmh': 20, 'distance_m': 2500, 'safety_margin_m': 20, 'decel_cms2': 70, 'line_kmh': 80, 'speed_kmh': 168, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 80, 'action': 'brake'}), ('control 41', {'target_kmh': 40, 'distance_m': 600, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 80, 'speed_kmh': 61, 'warn_margin_kmh': 5, 'brake_margin_kmh': 8}, {'permitted': 80, 'action': 'none'})], [('regression: stop target inside the margin', {'target_kmh': 0, 'distance_m': 40, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 10, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 0, 'action': 'warning'}), ('boundary: brake boundary', {'target_kmh': 40, 'distance_m': 0, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 50, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 40, 'action': 'warning'}), ('sampled regression 70', {'target_kmh': 0, 'distance_m': 100, 'safety_margin_m': 20, 'decel_cms2': 100, 'line_kmh': 80, 'speed_kmh': 42, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 45, 'action': 'none'}), ('sampled regression 40', {'target_kmh': 0, 'distance_m': 600, 'safety_margin_m': 50, 'decel_cms2': 50, 'line_kmh': 160, 'speed_kmh': 70, 'warn_margin_kmh': 5, 'brake_margin_kmh': 15}, {'permitted': 84, 'action': 'none'}), ('boundary: target speed release', {'target_kmh': 40, 'distance_m': 0, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 44, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 40, 'action': 'none'}), ('sampled regression 46', {'target_kmh': 0, 'distance_m': 100, 'safety_margin_m': 20, 'decel_cms2': 100, 'line_kmh': 120, 'speed_kmh': 73, 'warn_margin_kmh': 5, 'brake_margin_kmh': 15}, {'permitted': 45, 'action': 'brake'}), ('control 49', {'target_kmh': 0, 'distance_m': 2500, 'safety_margin_m': 50, 'decel_cms2': 50, 'line_kmh': 160, 'speed_kmh': 148, 'warn_margin_kmh': 5, 'brake_margin_kmh': 15}, {'permitted': 160, 'action': 'none'}), ('control 52', {'target_kmh': 40, 'distance_m': 250, 'safety_margin_m': 20, 'decel_cms2': 100, 'line_kmh': 80, 'speed_kmh': 50, 'warn_margin_kmh': 3, 'brake_margin_kmh': 10}, {'permitted': 80, 'action': 'none'})]]
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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(x):
    vt = x['target_kmh'] / 3.6
    d = max(x['distance_m'], 0) - x['safety_margin_m'] // 2
    a = x['decel_cms2'] / 100
    vp = math.sqrt(vt * vt + 2 * a * d) * 3.6
    permitted = min(int(vp), x['line_kmh'])
    v = x['speed_kmh']
    if v > permitted + x['brake_margin_kmh']:
        action = 'brake'
    elif v > permitted + x['warn_margin_kmh']:
        action = 'warning'
    else:
        action = 'none'
    return {'permitted': permitted, 'action': action}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: stop target inside the margin', {'target_kmh': 0, 'distance_m': 40, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 10, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 0, 'action': 'warning'}), ('sampled regression 4', {'target_kmh': 0, 'distance_m': 100, 'safety_margin_m': 20, 'decel_cms2': 100, 'line_kmh': 80, 'speed_kmh': 136, 'warn_margin_kmh': 5, 'brake_margin_kmh': 15}, {'permitted': 45, 'action': 'brake'}), ('boundary: target speed release', {'target_kmh': 40, 'distance_m': 0, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 44, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 40, 'action': 'none'}), ('regression: curve below line speed', {'target_kmh': 0, 'distance_m': 600, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 100, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 99, 'action': 'none'}), ('boundary: curve above line speed', {'target_kmh': 0, 'distance_m': 2500, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 120, 'speed_kmh': 150, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 120, 'action': 'brake'}), ('control 1', {'target_kmh': 0, 'distance_m': 0, 'safety_margin_m': 0, 'decel_cms2': 100, 'line_kmh': 160, 'speed_kmh': 139, 'warn_margin_kmh': 5, 'brake_margin_kmh': 15}, {'permitted': 0, 'action': 'brake'}), ('control 7', {'target_kmh': 40, 'distance_m': 2500, 'safety_margin_m': 20, 'decel_cms2': 50, 'line_kmh': 160, 'speed_kmh': 59, 'warn_margin_kmh': 3, 'brake_margin_kmh': 10}, {'permitted': 160, 'action': 'none'}), ('sampled regression 10', {'target_kmh': 20, 'distance_m': 40, 'safety_margin_m': 20, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 33, 'warn_margin_kmh': 5, 'brake_margin_kmh': 15}, {'permitted': 27, 'action': 'warning'})], [('regression: curve below line speed', {'target_kmh': 0, 'distance_m': 600, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 100, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 99, 'action': 'none'}), ('boundary: target speed release', {'target_kmh': 40, 'distance_m': 0, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 44, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 40, 'action': 'none'}), ('sampled regression 19', {'target_kmh': 0, 'distance_m': 40, 'safety_margin_m': 50, 'decel_cms2': 100, 'line_kmh': 160, 'speed_kmh': 17, 'warn_margin_kmh': 3, 'brake_margin_kmh': 15}, {'permitted': 0, 'action': 'brake'}), ('sampled regression 2', {'target_kmh': 0, 'distance_m': 250, 'safety_margin_m': 50, 'decel_cms2': 50, 'line_kmh': 160, 'speed_kmh': 122, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 50, 'action': 'brake'}), ('boundary: curve above line speed', {'target_kmh': 0, 'distance_m': 2500, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 120, 'speed_kmh': 150, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 120, 'action': 'brake'}), ('sampled regression 12', {'target_kmh': 40, 'distance_m': 600, 'safety_margin_m': 20, 'decel_cms2': 100, 'line_kmh': 160, 'speed_kmh': 133, 'warn_margin_kmh': 3, 'brake_margin_kmh': 15}, {'permitted': 128, 'action': 'warning'}), ('sampled regression 15', {'target_kmh': 0, 'distance_m': 600, 'safety_margin_m': 20, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 43, 'warn_margin_kmh': 3, 'brake_margin_kmh': 10}, {'permitted': 102, 'action': 'none'}), ('control 18', {'target_kmh': 60, 'distance_m': 1200, 'safety_margin_m': 20, 'decel_cms2': 70, 'line_kmh': 120, 'speed_kmh': 6, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 120, 'action': 'none'})], [('regression: stop target inside the margin', {'target_kmh': 0, 'distance_m': 40, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 10, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 0, 'action': 'warning'}), ('regression: curve below line speed', {'target_kmh': 0, 'distance_m': 600, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 100, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 99, 'action': 'none'}), ('sampled regression 42', {'target_kmh': 40, 'distance_m': 40, 'safety_margin_m': 20, 'decel_cms2': 50, 'line_kmh': 160, 'speed_kmh': 115, 'warn_margin_kmh': 5, 'brake_margin_kmh': 8}, {'permitted': 43, 'action': 'brake'}), ('sampled regression 11', {'target_kmh': 0, 'distance_m': 250, 'safety_margin_m': 20, 'decel_cms2': 100, 'line_kmh': 120, 'speed_kmh': 158, 'warn_margin_kmh': 5, 'brake_margin_kmh': 15}, {'permitted': 77, 'action': 'brake'}), ('boundary: warning boundary', {'target_kmh': 40, 'distance_m': 0, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 45, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 40, 'action': 'none'}), ('sampled regression 23', {'target_kmh': 60, 'distance_m': 100, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 80, 'speed_kmh': 13, 'warn_margin_kmh': 5, 'brake_margin_kmh': 8}, {'permitted': 67, 'action': 'none'}), ('control 26', {'target_kmh': 60, 'distance_m': 2500, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 86, 'warn_margin_kmh': 3, 'brake_margin_kmh': 10}, {'permitted': 160, 'action': 'none'}), ('control 29', {'target_kmh': 0, 'distance_m': 250, 'safety_margin_m': 0, 'decel_cms2': 70, 'line_kmh': 120, 'speed_kmh': 4, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 67, 'action': 'none'})], [('regression: curve below line speed', {'target_kmh': 0, 'distance_m': 600, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 100, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 99, 'action': 'none'}), ('boundary: warning boundary', {'target_kmh': 40, 'distance_m': 0, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 45, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 40, 'action': 'none'}), ('sampled regression 54', {'target_kmh': 60, 'distance_m': 1200, 'safety_margin_m': 20, 'decel_cms2': 50, 'line_kmh': 160, 'speed_kmh': 118, 'warn_margin_kmh': 3, 'brake_margin_kmh': 8}, {'permitted': 137, 'action': 'none'}), ('sampled regression 23', {'target_kmh': 60, 'distance_m': 100, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 80, 'speed_kmh': 13, 'warn_margin_kmh': 5, 'brake_margin_kmh': 8}, {'permitted': 67, 'action': 'none'}), ('boundary: between warning and brake', {'target_kmh': 40, 'distance_m': 0, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 48, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 40, 'action': 'warning'}), ('control 34', {'target_kmh': 0, 'distance_m': 0, 'safety_margin_m': 0, 'decel_cms2': 70, 'line_kmh': 120, 'speed_kmh': 96, 'warn_margin_kmh': 5, 'brake_margin_kmh': 15}, {'permitted': 0, 'action': 'brake'}), ('control 37', {'target_kmh': 20, 'distance_m': 2500, 'safety_margin_m': 20, 'decel_cms2': 70, 'line_kmh': 80, 'speed_kmh': 168, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 80, 'action': 'brake'}), ('control 41', {'target_kmh': 40, 'distance_m': 600, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 80, 'speed_kmh': 61, 'warn_margin_kmh': 5, 'brake_margin_kmh': 8}, {'permitted': 80, 'action': 'none'})], [('regression: stop target inside the margin', {'target_kmh': 0, 'distance_m': 40, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 10, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 0, 'action': 'warning'}), ('boundary: brake boundary', {'target_kmh': 40, 'distance_m': 0, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 50, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 40, 'action': 'warning'}), ('sampled regression 70', {'target_kmh': 0, 'distance_m': 100, 'safety_margin_m': 20, 'decel_cms2': 100, 'line_kmh': 80, 'speed_kmh': 42, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 45, 'action': 'none'}), ('sampled regression 40', {'target_kmh': 0, 'distance_m': 600, 'safety_margin_m': 50, 'decel_cms2': 50, 'line_kmh': 160, 'speed_kmh': 70, 'warn_margin_kmh': 5, 'brake_margin_kmh': 15}, {'permitted': 84, 'action': 'none'}), ('boundary: target speed release', {'target_kmh': 40, 'distance_m': 0, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 44, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 40, 'action': 'none'}), ('sampled regression 46', {'target_kmh': 0, 'distance_m': 100, 'safety_margin_m': 20, 'decel_cms2': 100, 'line_kmh': 120, 'speed_kmh': 73, 'warn_margin_kmh': 5, 'brake_margin_kmh': 15}, {'permitted': 45, 'action': 'brake'}), ('control 49', {'target_kmh': 0, 'distance_m': 2500, 'safety_margin_m': 50, 'decel_cms2': 50, 'line_kmh': 160, 'speed_kmh': 148, 'warn_margin_kmh': 5, 'brake_margin_kmh': 15}, {'permitted': 160, 'action': 'none'}), ('control 52', {'target_kmh': 40, 'distance_m': 250, 'safety_margin_m': 20, 'decel_cms2': 100, 'line_kmh': 80, 'speed_kmh': 50, 'warn_margin_kmh': 3, 'brake_margin_kmh': 10}, {'permitted': 80, 'action': 'none'})]]
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)

prompt:
The permitted speed is supervised against the danger point rather than the margin-reduced target.

Permitted speed at the train is sqrt(vt^2 + 2*a*d) with vt the target speed in m/s, a = decel_cms2/100 m/s^2 and d = max(distance - safety margin, 0); convert back to km/h, truncate to an integer (never round up) and cap at line speed. Action is brake if speed > permitted + brake margin, else warning if speed > permitted + warn margin, else none.

split: open-access