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

N = 1
observations = []
def solve(x):
    st, el = x['state'], x['elapsed']
    y, r, f = x['yellow'], x['red'], x['fdw']
    if x['track_current']:
        return [0, 0]
    if st == 'red':
        return [max(0, r - el), 0]
    if st == 'yellow':
        return [max(0, y - el) + r, 0]
    ped = 0
    if x['ped'] == 'walk':
        ped = 0 if x['ped_truncate'] else f
    elif x['ped'] == 'fdw':
        ped = 0 if x['ped_truncate'] else max(0, f - x['ped_elapsed'])
    hold = max(ped, max(0, x['preempt_min_green'] - el))
    return [hold + y + r, hold]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'state': 'yellow', 'elapsed': 18, 'min_green': 19, 'preempt_min_green': 6, 'yellow': 5, 'red': 3, 'fdw': 21, 'ped': 'none', 'ped_elapsed': 0, 'ped_truncate': True, 'track_current': True}, [3, 0]), ({'state': 'yellow', 'elapsed': 2, 'min_green': 10, 'preempt_min_green': 4, 'yellow': 4, 'red': 2, 'fdw': 12, 'ped': 'none', 'ped_elapsed': 0, 'ped_truncate': False, 'track_current': True}, [4, 0]), ({'state': 'green', 'elapsed': 18, 'min_green': 15, 'preempt_min_green': 7, 'yellow': 4, 'red': 1, 'fdw': 15, 'ped': 'walk', 'ped_elapsed': 8, 'ped_truncate': True, 'track_current': False}, [5, 0]), ({'state': 'yellow', 'elapsed': 4, 'min_green': 16, 'preempt_min_green': 3, 'yellow': 5, 'red': 3, 'fdw': 14, 'ped': 'none', 'ped_elapsed': 19, 'ped_truncate': False, 'track_current': False}, [4, 0]), ({'state': 'yellow', 'elapsed': 12, 'min_green': 14, 'preempt_min_green': 3, 'yellow': 3, 'red': 2, 'fdw': 23, 'ped': 'none', 'ped_elapsed': 6, 'ped_truncate': True, 'track_current': True}, [2, 0]), ({'state': 'red', 'elapsed': 7, 'min_green': 9, 'preempt_min_green': 10, 'yellow': 3, 'red': 1, 'fdw': 9, 'ped': 'none', 'ped_elapsed': 12, 'ped_truncate': False, 'track_current': False}, [0, 0]), ({'state': 'green', 'elapsed': 1, 'min_green': 15, 'preempt_min_green': 5, 'yellow': 4, 'red': 2, 'fdw': 12, 'ped': 'fdw', 'ped_elapsed': 4, 'ped_truncate': False, 'track_current': False}, [14, 8]), ({'state': 'green', 'elapsed': 20, 'min_green': 18, 'preempt_min_green': 10, 'yellow': 3, 'red': 2, 'fdw': 8, 'ped': 'none', 'ped_elapsed': 7, 'ped_truncate': False, 'track_current': True}, [0, 0])], [({'state': 'green', 'elapsed': 6, 'min_green': 11, 'preempt_min_green': 6, 'yellow': 6, 'red': 3, 'fdw': 11, 'ped': 'none', 'ped_elapsed': 9, 'ped_truncate': False, 'track_current': False}, [9, 0]), ({'state': 'green', 'elapsed': 1, 'min_green': 15, 'preempt_min_green': 5, 'yellow': 4, 'red': 2, 'fdw': 12, 'ped': 'fdw', 'ped_elapsed': 4, 'ped_truncate': False, 'track_current': False}, [14, 8]), ({'state': 'green', 'elapsed': 9, 'min_green': 12, 'preempt_min_green': 3, 'yellow': 4, 'red': 2, 'fdw': 11, 'ped': 'none', 'ped_elapsed': 18, 'ped_truncate': False, 'track_current': False}, [6, 0]), ({'state': 'yellow', 'elapsed': 9, 'min_green': 13, 'preempt_min_green': 8, 'yellow': 5, 'red': 1, 'fdw': 10, 'ped': 'none', 'ped_elapsed': 15, 'ped_truncate': False, 'track_current': True}, [1, 0]), ({'state': 'green', 'elapsed': 10, 'min_green': 10, 'preempt_min_green': 6, 'yellow': 3, 'red': 3, 'fdw': 25, 'ped': 'walk', 'ped_elapsed': 17, 'ped_truncate': False, 'track_current': False}, [31, 25]), ({'state': 'yellow', 'elapsed': 2, 'min_green': 10, 'preempt_min_green': 4, 'yellow': 4, 'red': 2, 'fdw': 12, 'ped': 'none', 'ped_elapsed': 0, 'ped_truncate': False, 'track_current': True}, [4, 0]), ({'state': 'green', 'elapsed': 11, 'min_green': 10, 'preempt_min_green': 4, 'yellow': 5, 'red': 1, 'fdw': 15, 'ped': 'fdw', 'ped_elapsed': 6, 'ped_truncate': True, 'track_current': False}, [6, 0]), ({'state': 'yellow', 'elapsed': 16, 'min_green': 19, 'preempt_min_green': 3, 'yellow': 5, 'red': 2, 'fdw': 13, 'ped': 'none', 'ped_elapsed': 19, 'ped_truncate': True, 'track_current': True}, [2, 0])], [({'state': 'yellow', 'elapsed': 2, 'min_green': 10, 'preempt_min_green': 4, 'yellow': 4, 'red': 2, 'fdw': 12, 'ped': 'none', 'ped_elapsed': 0, 'ped_truncate': False, 'track_current': True}, [4, 0]), ({'state': 'green', 'elapsed': 12, 'min_green': 8, 'preempt_min_green': 7, 'yellow': 5, 'red': 1, 'fdw': 24, 'ped': 'walk', 'ped_elapsed': 4, 'ped_truncate': False, 'track_current': False}, [30, 24]), ({'state': 'red', 'elapsed': 0, 'min_green': 14, 'preempt_min_green': 5, 'yellow': 3, 'red': 1, 'fdw': 15, 'ped': 'none', 'ped_elapsed': 18, 'ped_truncate': False, 'track_current': True}, [1, 0]), ({'state': 'green', 'elapsed': 1, 'min_green': 15, 'preempt_min_green': 5, 'yellow': 4, 'red': 2, 'fdw': 12, 'ped': 'fdw', 'ped_elapsed': 4, 'ped_truncate': False, 'track_current': False}, [14, 8]), ({'state': 'green', 'elapsed': 6, 'min_green': 20, 'preempt_min_green': 9, 'yellow': 4, 'red': 3, 'fdw': 25, 'ped': 'none', 'ped_elapsed': 1, 'ped_truncate': True, 'track_current': False}, [10, 3]), ({'state': 'green', 'elapsed': 10, 'min_green': 18, 'preempt_min_green': 2, 'yellow': 3, 'red': 1, 'fdw': 20, 'ped': 'none', 'ped_elapsed': 20, 'ped_truncate': False, 'track_current': False}, [4, 0]), ({'state': 'red', 'elapsed': 18, 'min_green': 16, 'preempt_min_green': 10, 'yellow': 6, 'red': 2, 'fdw': 25, 'ped': 'none', 'ped_elapsed': 13, 'ped_truncate': False, 'track_current': False}, [0, 0]), ({'state': 'yellow', 'elapsed': 9, 'min_green': 18, 'preempt_min_green': 3, 'yellow': 6, 'red': 3, 'fdw': 15, 'ped': 'none', 'ped_elapsed': 9, 'ped_truncate': False, 'track_current': True}, [3, 0])], [({'state': 'yellow', 'elapsed': 6, 'min_green': 20, 'preempt_min_green': 5, 'yellow': 3, 'red': 3, 'fdw': 19, 'ped': 'none', 'ped_elapsed': 10, 'ped_truncate': True, 'track_current': False}, [3, 0]), ({'state': 'yellow', 'elapsed': 4, 'min_green': 20, 'preempt_min_green': 8, 'yellow': 6, 'red': 1, 'fdw': 14, 'ped': 'none', 'ped_elapsed': 11, 'ped_truncate': True, 'track_current': True}, [3, 0]), ({'state': 'yellow', 'elapsed': 2, 'min_green': 10, 'preempt_min_green': 4, 'yellow': 4, 'red': 2, 'fdw': 12, 'ped': 'none', 'ped_elapsed': 0, 'ped_truncate': False, 'track_current': True}, [4, 0]), ({'state': 'green', 'elapsed': 6, 'min_green': 17, 'preempt_min_green': 4, 'yellow': 4, 'red': 3, 'fdw': 25, 'ped': 'fdw', 'ped_elapsed': 1, 'ped_truncate': False, 'track_current': False}, [31, 24]), ({'state': 'red', 'elapsed': 7, 'min_green': 13, 'preempt_min_green': 2, 'yellow': 6, 'red': 1, 'fdw': 21, 'ped': 'none', 'ped_elapsed': 6, 'ped_truncate': False, 'track_current': False}, [0, 0]), ({'state': 'green', 'elapsed': 1, 'min_green': 15, 'preempt_min_green': 5, 'yellow': 4, 'red': 2, 'fdw': 12, 'ped': 'fdw', 'ped_elapsed': 4, 'ped_truncate': False, 'track_current': False}, [14, 8]), ({'state': 'green', 'elapsed': 2, 'min_green': 20, 'preempt_min_green': 9, 'yellow': 4, 'red': 3, 'fdw': 18, 'ped': 'none', 'ped_elapsed': 6, 'ped_truncate': False, 'track_current': False}, [14, 7]), ({'state': 'yellow', 'elapsed': 12, 'min_green': 12, 'preempt_min_green': 10, 'yellow': 5, 'red': 1, 'fdw': 19, 'ped': 'none', 'ped_elapsed': 9, 'ped_truncate': False, 'track_current': True}, [1, 0])], [({'state': 'red', 'elapsed': 1, 'min_green': 11, 'preempt_min_green': 2, 'yellow': 3, 'red': 3, 'fdw': 22, 'ped': 'none', 'ped_elapsed': 2, 'ped_truncate': True, 'track_current': False}, [2, 0]), ({'state': 'yellow', 'elapsed': 11, 'min_green': 18, 'preempt_min_green': 9, 'yellow': 6, 'red': 3, 'fdw': 25, 'ped': 'none', 'ped_elapsed': 11, 'ped_truncate': False, 'track_current': True}, [3, 0]), ({'state': 'green', 'elapsed': 12, 'min_green': 18, 'preempt_min_green': 10, 'yellow': 6, 'red': 2, 'fdw': 18, 'ped': 'fdw', 'ped_elapsed': 19, 'ped_truncate': False, 'track_current': True}, [0, 0]), ({'state': 'yellow', 'elapsed': 2, 'min_green': 10, 'preempt_min_green': 4, 'yellow': 4, 'red': 2, 'fdw': 12, 'ped': 'none', 'ped_elapsed': 0, 'ped_truncate': False, 'track_current': True}, [4, 0]), ({'state': 'yellow', 'elapsed': 8, 'min_green': 11, 'preempt_min_green': 7, 'yellow': 3, 'red': 3, 'fdw': 22, 'ped': 'none', 'ped_elapsed': 10, 'ped_truncate': True, 'track_current': True}, [3, 0]), ({'state': 'red', 'elapsed': 9, 'min_green': 11, 'preempt_min_green': 10, 'yellow': 5, 'red': 1, 'fdw': 20, 'ped': 'none', 'ped_elapsed': 19, 'ped_truncate': True, 'track_current': False}, [0, 0]), ({'state': 'green', 'elapsed': 1, 'min_green': 15, 'preempt_min_green': 5, 'yellow': 4, 'red': 2, 'fdw': 12, 'ped': 'fdw', 'ped_elapsed': 4, 'ped_truncate': False, 'track_current': False}, [14, 8]), ({'state': 'green', 'elapsed': 13, 'min_green': 14, 'preempt_min_green': 2, 'yellow': 4, 'red': 2, 'fdw': 11, 'ped': 'none', 'ped_elapsed': 19, 'ped_truncate': True, 'track_current': False}, [6, 0])]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check('timing oracle' + ' %d' % i, 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):
    st, el = x['state'], x['elapsed']
    y, r, f = x['yellow'], x['red'], x['fdw']
    if st != 'red' and x['track_current']:
        return [0, 0]
    if st == 'red':
        return [max(0, r - el), 0]
    if st == 'yellow':
        return [max(0, y - el) + r, 0]
    ped = 0
    if x['ped'] == 'walk':
        ped = 0 if x['ped_truncate'] else f
    elif x['ped'] == 'fdw':
        ped = 0 if x['ped_truncate'] else max(0, f - x['ped_elapsed'])
    hold = max(ped, max(0, x['preempt_min_green'] - el))
    return [hold + y + r, hold]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'state': 'yellow', 'elapsed': 18, 'min_green': 19, 'preempt_min_green': 6, 'yellow': 5, 'red': 3, 'fdw': 21, 'ped': 'none', 'ped_elapsed': 0, 'ped_truncate': True, 'track_current': True}, [3, 0]), ({'state': 'yellow', 'elapsed': 2, 'min_green': 10, 'preempt_min_green': 4, 'yellow': 4, 'red': 2, 'fdw': 12, 'ped': 'none', 'ped_elapsed': 0, 'ped_truncate': False, 'track_current': True}, [4, 0]), ({'state': 'green', 'elapsed': 18, 'min_green': 15, 'preempt_min_green': 7, 'yellow': 4, 'red': 1, 'fdw': 15, 'ped': 'walk', 'ped_elapsed': 8, 'ped_truncate': True, 'track_current': False}, [5, 0]), ({'state': 'yellow', 'elapsed': 4, 'min_green': 16, 'preempt_min_green': 3, 'yellow': 5, 'red': 3, 'fdw': 14, 'ped': 'none', 'ped_elapsed': 19, 'ped_truncate': False, 'track_current': False}, [4, 0]), ({'state': 'yellow', 'elapsed': 12, 'min_green': 14, 'preempt_min_green': 3, 'yellow': 3, 'red': 2, 'fdw': 23, 'ped': 'none', 'ped_elapsed': 6, 'ped_truncate': True, 'track_current': True}, [2, 0]), ({'state': 'red', 'elapsed': 7, 'min_green': 9, 'preempt_min_green': 10, 'yellow': 3, 'red': 1, 'fdw': 9, 'ped': 'none', 'ped_elapsed': 12, 'ped_truncate': False, 'track_current': False}, [0, 0]), ({'state': 'green', 'elapsed': 1, 'min_green': 15, 'preempt_min_green': 5, 'yellow': 4, 'red': 2, 'fdw': 12, 'ped': 'fdw', 'ped_elapsed': 4, 'ped_truncate': False, 'track_current': False}, [14, 8]), ({'state': 'green', 'elapsed': 20, 'min_green': 18, 'preempt_min_green': 10, 'yellow': 3, 'red': 2, 'fdw': 8, 'ped': 'none', 'ped_elapsed': 7, 'ped_truncate': False, 'track_current': True}, [0, 0])], [({'state': 'green', 'elapsed': 6, 'min_green': 11, 'preempt_min_green': 6, 'yellow': 6, 'red': 3, 'fdw': 11, 'ped': 'none', 'ped_elapsed': 9, 'ped_truncate': False, 'track_current': False}, [9, 0]), ({'state': 'green', 'elapsed': 1, 'min_green': 15, 'preempt_min_green': 5, 'yellow': 4, 'red': 2, 'fdw': 12, 'ped': 'fdw', 'ped_elapsed': 4, 'ped_truncate': False, 'track_current': False}, [14, 8]), ({'state': 'green', 'elapsed': 9, 'min_green': 12, 'preempt_min_green': 3, 'yellow': 4, 'red': 2, 'fdw': 11, 'ped': 'none', 'ped_elapsed': 18, 'ped_truncate': False, 'track_current': False}, [6, 0]), ({'state': 'yellow', 'elapsed': 9, 'min_green': 13, 'preempt_min_green': 8, 'yellow': 5, 'red': 1, 'fdw': 10, 'ped': 'none', 'ped_elapsed': 15, 'ped_truncate': False, 'track_current': True}, [1, 0]), ({'state': 'green', 'elapsed': 10, 'min_green': 10, 'preempt_min_green': 6, 'yellow': 3, 'red': 3, 'fdw': 25, 'ped': 'walk', 'ped_elapsed': 17, 'ped_truncate': False, 'track_current': False}, [31, 25]), ({'state': 'yellow', 'elapsed': 2, 'min_green': 10, 'preempt_min_green': 4, 'yellow': 4, 'red': 2, 'fdw': 12, 'ped': 'none', 'ped_elapsed': 0, 'ped_truncate': False, 'track_current': True}, [4, 0]), ({'state': 'green', 'elapsed': 11, 'min_green': 10, 'preempt_min_green': 4, 'yellow': 5, 'red': 1, 'fdw': 15, 'ped': 'fdw', 'ped_elapsed': 6, 'ped_truncate': True, 'track_current': False}, [6, 0]), ({'state': 'yellow', 'elapsed': 16, 'min_green': 19, 'preempt_min_green': 3, 'yellow': 5, 'red': 2, 'fdw': 13, 'ped': 'none', 'ped_elapsed': 19, 'ped_truncate': True, 'track_current': True}, [2, 0])], [({'state': 'yellow', 'elapsed': 2, 'min_green': 10, 'preempt_min_green': 4, 'yellow': 4, 'red': 2, 'fdw': 12, 'ped': 'none', 'ped_elapsed': 0, 'ped_truncate': False, 'track_current': True}, [4, 0]), ({'state': 'green', 'elapsed': 12, 'min_green': 8, 'preempt_min_green': 7, 'yellow': 5, 'red': 1, 'fdw': 24, 'ped': 'walk', 'ped_elapsed': 4, 'ped_truncate': False, 'track_current': False}, [30, 24]), ({'state': 'red', 'elapsed': 0, 'min_green': 14, 'preempt_min_green': 5, 'yellow': 3, 'red': 1, 'fdw': 15, 'ped': 'none', 'ped_elapsed': 18, 'ped_truncate': False, 'track_current': True}, [1, 0]), ({'state': 'green', 'elapsed': 1, 'min_green': 15, 'preempt_min_green': 5, 'yellow': 4, 'red': 2, 'fdw': 12, 'ped': 'fdw', 'ped_elapsed': 4, 'ped_truncate': False, 'track_current': False}, [14, 8]), ({'state': 'green', 'elapsed': 6, 'min_green': 20, 'preempt_min_green': 9, 'yellow': 4, 'red': 3, 'fdw': 25, 'ped': 'none', 'ped_elapsed': 1, 'ped_truncate': True, 'track_current': False}, [10, 3]), ({'state': 'green', 'elapsed': 10, 'min_green': 18, 'preempt_min_green': 2, 'yellow': 3, 'red': 1, 'fdw': 20, 'ped': 'none', 'ped_elapsed': 20, 'ped_truncate': False, 'track_current': False}, [4, 0]), ({'state': 'red', 'elapsed': 18, 'min_green': 16, 'preempt_min_green': 10, 'yellow': 6, 'red': 2, 'fdw': 25, 'ped': 'none', 'ped_elapsed': 13, 'ped_truncate': False, 'track_current': False}, [0, 0]), ({'state': 'yellow', 'elapsed': 9, 'min_green': 18, 'preempt_min_green': 3, 'yellow': 6, 'red': 3, 'fdw': 15, 'ped': 'none', 'ped_elapsed': 9, 'ped_truncate': False, 'track_current': True}, [3, 0])], [({'state': 'yellow', 'elapsed': 6, 'min_green': 20, 'preempt_min_green': 5, 'yellow': 3, 'red': 3, 'fdw': 19, 'ped': 'none', 'ped_elapsed': 10, 'ped_truncate': True, 'track_current': False}, [3, 0]), ({'state': 'yellow', 'elapsed': 4, 'min_green': 20, 'preempt_min_green': 8, 'yellow': 6, 'red': 1, 'fdw': 14, 'ped': 'none', 'ped_elapsed': 11, 'ped_truncate': True, 'track_current': True}, [3, 0]), ({'state': 'yellow', 'elapsed': 2, 'min_green': 10, 'preempt_min_green': 4, 'yellow': 4, 'red': 2, 'fdw': 12, 'ped': 'none', 'ped_elapsed': 0, 'ped_truncate': False, 'track_current': True}, [4, 0]), ({'state': 'green', 'elapsed': 6, 'min_green': 17, 'preempt_min_green': 4, 'yellow': 4, 'red': 3, 'fdw': 25, 'ped': 'fdw', 'ped_elapsed': 1, 'ped_truncate': False, 'track_current': False}, [31, 24]), ({'state': 'red', 'elapsed': 7, 'min_green': 13, 'preempt_min_green': 2, 'yellow': 6, 'red': 1, 'fdw': 21, 'ped': 'none', 'ped_elapsed': 6, 'ped_truncate': False, 'track_current': False}, [0, 0]), ({'state': 'green', 'elapsed': 1, 'min_green': 15, 'preempt_min_green': 5, 'yellow': 4, 'red': 2, 'fdw': 12, 'ped': 'fdw', 'ped_elapsed': 4, 'ped_truncate': False, 'track_current': False}, [14, 8]), ({'state': 'green', 'elapsed': 2, 'min_green': 20, 'preempt_min_green': 9, 'yellow': 4, 'red': 3, 'fdw': 18, 'ped': 'none', 'ped_elapsed': 6, 'ped_truncate': False, 'track_current': False}, [14, 7]), ({'state': 'yellow', 'elapsed': 12, 'min_green': 12, 'preempt_min_green': 10, 'yellow': 5, 'red': 1, 'fdw': 19, 'ped': 'none', 'ped_elapsed': 9, 'ped_truncate': False, 'track_current': True}, [1, 0])], [({'state': 'red', 'elapsed': 1, 'min_green': 11, 'preempt_min_green': 2, 'yellow': 3, 'red': 3, 'fdw': 22, 'ped': 'none', 'ped_elapsed': 2, 'ped_truncate': True, 'track_current': False}, [2, 0]), ({'state': 'yellow', 'elapsed': 11, 'min_green': 18, 'preempt_min_green': 9, 'yellow': 6, 'red': 3, 'fdw': 25, 'ped': 'none', 'ped_elapsed': 11, 'ped_truncate': False, 'track_current': True}, [3, 0]), ({'state': 'green', 'elapsed': 12, 'min_green': 18, 'preempt_min_green': 10, 'yellow': 6, 'red': 2, 'fdw': 18, 'ped': 'fdw', 'ped_elapsed': 19, 'ped_truncate': False, 'track_current': True}, [0, 0]), ({'state': 'yellow', 'elapsed': 2, 'min_green': 10, 'preempt_min_green': 4, 'yellow': 4, 'red': 2, 'fdw': 12, 'ped': 'none', 'ped_elapsed': 0, 'ped_truncate': False, 'track_current': True}, [4, 0]), ({'state': 'yellow', 'elapsed': 8, 'min_green': 11, 'preempt_min_green': 7, 'yellow': 3, 'red': 3, 'fdw': 22, 'ped': 'none', 'ped_elapsed': 10, 'ped_truncate': True, 'track_current': True}, [3, 0]), ({'state': 'red', 'elapsed': 9, 'min_green': 11, 'preempt_min_green': 10, 'yellow': 5, 'red': 1, 'fdw': 20, 'ped': 'none', 'ped_elapsed': 19, 'ped_truncate': True, 'track_current': False}, [0, 0]), ({'state': 'green', 'elapsed': 1, 'min_green': 15, 'preempt_min_green': 5, 'yellow': 4, 'red': 2, 'fdw': 12, 'ped': 'fdw', 'ped_elapsed': 4, 'ped_truncate': False, 'track_current': False}, [14, 8]), ({'state': 'green', 'elapsed': 13, 'min_green': 14, 'preempt_min_green': 2, 'yellow': 4, 'red': 2, 'fdw': 11, 'ped': 'none', 'ped_elapsed': 19, 'ped_truncate': True, 'track_current': False}, [6, 0])]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check('timing oracle' + ' %d' % i, 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:
Railroad preemption entry timing returns a wrong result when track phase in yellow is treated as already serving.

Input {state: green|yellow|red (red = all-red clearance), elapsed, min_green, preempt_min_green, yellow, red, fdw, ped: none|walk|fdw, ped_elapsed, ped_truncate, track_current}. If the track clearance phase is already green the answer is [0, 0]. In all-red the remaining red is timed; in yellow the remaining yellow and full red are timed. In green the hold is the larger of the remaining preempt minimum green (not the normal minimum) and the pedestrian time: walk is abandoned and FDW is timed in full, or skipped when ped_truncate; an active FDW completes its remainder unless truncated. Return [seconds until track clearance green, green hold].

split: open-access


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

N = 1
observations = []
def solve(x):
    C = x['cycle']
    a = x['arrival']
    last = x['last_granted']
    if last is not None and x['cycle_index'] - last <= x['lockout']:
        return ['locked', 0]
    gs, ge = x['green_start'], x['green_end']
    if gs <= a < ge:
        return ['none', 0]
    d = (a - ge) % C
    if d < x['max_ext']:
        return ['extend', d + 1]
    wait = (gs - a) % C
    return ['early', min(x['max_early'], wait)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'cycle': 100, 'green_start': 10, 'green_end': 50, 'max_ext': 10, 'max_early': 10, 'arrival': 250, 'last_granted': 3, 'cycle_index': 5, 'lockout': 2}, ['locked', 0]), ({'cycle': 120, 'green_start': 33, 'green_end': 56, 'max_ext': 8, 'max_early': 18, 'arrival': 319, 'last_granted': 8, 'cycle_index': 18, 'lockout': 3}, ['early', 18]), ({'cycle': 80, 'green_start': 26, 'green_end': 41, 'max_ext': 5, 'max_early': 11, 'arrival': 119, 'last_granted': None, 'cycle_index': 7, 'lockout': 2}, ['none', 0]), ({'cycle': 130, 'green_start': 17, 'green_end': 37, 'max_ext': 10, 'max_early': 17, 'arrival': 194, 'last_granted': 5, 'cycle_index': 10, 'lockout': 1}, ['early', 17]), ({'cycle': 100, 'green_start': 10, 'green_end': 45, 'max_ext': 10, 'max_early': 10, 'arrival': 110, 'last_granted': None, 'cycle_index': 4, 'lockout': 1}, ['none', 0]), ({'cycle': 80, 'green_start': 10, 'green_end': 43, 'max_ext': 8, 'max_early': 17, 'arrival': 121, 'last_granted': 9, 'cycle_index': 22, 'lockout': 1}, ['none', 0]), ({'cycle': 100, 'green_start': 30, 'green_end': 45, 'max_ext': 20, 'max_early': 10, 'arrival': 28, 'last_granted': 1, 'cycle_index': 6, 'lockout': 2}, ['early', 2]), ({'cycle': 100, 'green_start': 30, 'green_end': 74, 'max_ext': 6, 'max_early': 18, 'arrival': 212, 'last_granted': None, 'cycle_index': 2, 'lockout': 1}, ['early', 18])], [({'cycle': 90, 'green_start': 13, 'green_end': 37, 'max_ext': 13, 'max_early': 7, 'arrival': 98, 'last_granted': None, 'cycle_index': 20, 'lockout': 3}, ['early', 5]), ({'cycle': 100, 'green_start': 10, 'green_end': 50, 'max_ext': 10, 'max_early': 10, 'arrival': 250, 'last_granted': 3, 'cycle_index': 5, 'lockout': 2}, ['locked', 0]), ({'cycle': 90, 'green_start': 42, 'green_end': 79, 'max_ext': 20, 'max_early': 5, 'arrival': 49, 'last_granted': None, 'cycle_index': 21, 'lockout': 3}, ['none', 0]), ({'cycle': 90, 'green_start': 0, 'green_end': 40, 'max_ext': 12, 'max_early': 8, 'arrival': 40, 'last_granted': None, 'cycle_index': 0, 'lockout': 1}, ['extend', 1]), ({'cycle': 90, 'green_start': 5, 'green_end': 41, 'max_ext': 17, 'max_early': 17, 'arrival': 217, 'last_granted': None, 'cycle_index': 8, 'lockout': 3}, ['none', 0]), ({'cycle': 80, 'green_start': 22, 'green_end': 55, 'max_ext': 8, 'max_early': 9, 'arrival': 17, 'last_granted': None, 'cycle_index': 22, 'lockout': 3}, ['early', 5]), ({'cycle': 100, 'green_start': 10, 'green_end': 45, 'max_ext': 10, 'max_early': 10, 'arrival': 110, 'last_granted': None, 'cycle_index': 4, 'lockout': 1}, ['none', 0]), ({'cycle': 90, 'green_start': 30, 'green_end': 69, 'max_ext': 17, 'max_early': 7, 'arrival': 146, 'last_granted': 7, 'cycle_index': 12, 'lockout': 2}, ['none', 0])], [({'cycle': 120, 'green_start': 38, 'green_end': 79, 'max_ext': 11, 'max_early': 8, 'arrival': 227, 'last_granted': None, 'cycle_index': 17, 'lockout': 1}, ['early', 8]), ({'cycle': 100, 'green_start': 30, 'green_end': 45, 'max_ext': 20, 'max_early': 10, 'arrival': 28, 'last_granted': 1, 'cycle_index': 6, 'lockout': 2}, ['early', 2]), ({'cycle': 80, 'green_start': 6, 'green_end': 32, 'max_ext': 9, 'max_early': 14, 'arrival': 35, 'last_granted': None, 'cycle_index': 15, 'lockout': 2}, ['extend', 4]), ({'cycle': 80, 'green_start': 18, 'green_end': 36, 'max_ext': 15, 'max_early': 11, 'arrival': 98, 'last_granted': 1, 'cycle_index': 3, 'lockout': 1}, ['none', 0]), ({'cycle': 100, 'green_start': 10, 'green_end': 45, 'max_ext': 10, 'max_early': 10, 'arrival': 110, 'last_granted': None, 'cycle_index': 4, 'lockout': 1}, ['none', 0]), ({'cycle': 80, 'green_start': 21, 'green_end': 52, 'max_ext': 17, 'max_early': 8, 'arrival': 75, 'last_granted': None, 'cycle_index': 22, 'lockout': 1}, ['early', 8]), ({'cycle': 120, 'green_start': 60, 'green_end': 90, 'max_ext': 7, 'max_early': 12, 'arrival': 323, 'last_granted': 4, 'cycle_index': 20, 'lockout': 3}, ['none', 0]), ({'cycle': 90, 'green_start': 0, 'green_end': 40, 'max_ext': 12, 'max_early': 8, 'arrival': 40, 'last_granted': None, 'cycle_index': 0, 'lockout': 1}, ['extend', 1])], [({'cycle': 100, 'green_start': 36, 'green_end': 76, 'max_ext': 14, 'max_early': 6, 'arrival': 237, 'last_granted': None, 'cycle_index': 5, 'lockout': 3}, ['none', 0]), ({'cycle': 130, 'green_start': 61, 'green_end': 107, 'max_ext': 6, 'max_early': 17, 'arrival': 254, 'last_granted': None, 'cycle_index': 20, 'lockout': 1}, ['early', 17]), ({'cycle': 120, 'green_start': 17, 'green_end': 34, 'max_ext': 18, 'max_early': 18, 'arrival': 14, 'last_granted': None, 'cycle_index': 19, 'lockout': 2}, ['early', 3]), ({'cycle': 100, 'green_start': 30, 'green_end': 45, 'max_ext': 20, 'max_early': 10, 'arrival': 28, 'last_granted': 1, 'cycle_index': 6, 'lockout': 2}, ['early', 2]), ({'cycle': 110, 'green_start': 12, 'green_end': 40, 'max_ext': 5, 'max_early': 14, 'arrival': 128, 'last_granted': None, 'cycle_index': 12, 'lockout': 3}, ['none', 0]), ({'cycle': 100, 'green_start': 10, 'green_end': 45, 'max_ext': 10, 'max_early': 10, 'arrival': 110, 'last_granted': None, 'cycle_index': 4, 'lockout': 1}, ['none', 0]), ({'cycle': 100, 'green_start': 10, 'green_end': 50, 'max_ext': 10, 'max_early': 10, 'arrival': 250, 'last_granted': 3, 'cycle_index': 5, 'lockout': 2}, ['locked', 0]), ({'cycle': 140, 'green_start': 63, 'green_end': 107, 'max_ext': 8, 'max_early': 20, 'arrival': 247, 'last_granted': None, 'cycle_index': 11, 'lockout': 1}, ['extend', 1])], [({'cycle': 100, 'green_start': 10, 'green_end': 50, 'max_ext': 10, 'max_early': 10, 'arrival': 250, 'last_granted': 3, 'cycle_index': 5, 'lockout': 2}, ['locked', 0]), ({'cycle': 100, 'green_start': 29, 'green_end': 67, 'max_ext': 16, 'max_early': 15, 'arrival': 158, 'last_granted': None, 'cycle_index': 9, 'lockout': 3}, ['none', 0]), ({'cycle': 100, 'green_start': 30, 'green_end': 45, 'max_ext': 20, 'max_early': 10, 'arrival': 28, 'last_granted': 1, 'cycle_index': 6, 'lockout': 2}, ['early', 2]), ({'cycle': 100, 'green_start': 25, 'green_end': 65, 'max_ext': 12, 'max_early': 20, 'arrival': 265, 'last_granted': 9, 'cycle_index': 17, 'lockout': 1}, ['extend', 1]), ({'cycle': 90, 'green_start': 0, 'green_end': 40, 'max_ext': 12, 'max_early': 8, 'arrival': 40, 'last_granted': None, 'cycle_index': 0, 'lockout': 1}, ['extend', 1]), ({'cycle': 100, 'green_start': 16, 'green_end': 46, 'max_ext': 14, 'max_early': 12, 'arrival': 63, 'last_granted': None, 'cycle_index': 18, 'lockout': 3}, ['early', 12]), ({'cycle': 120, 'green_start': 1, 'green_end': 42, 'max_ext': 6, 'max_early': 11, 'arrival': 270, 'last_granted': None, 'cycle_index': 7, 'lockout': 1}, ['none', 0]), ({'cycle': 100, 'green_start': 37, 'green_end': 82, 'max_ext': 20, 'max_early': 5, 'arrival': 167, 'last_granted': None, 'cycle_index': 3, 'lockout': 2}, ['none', 0])]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check('timing oracle' + ' %d' % i, 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):
    C = x['cycle']
    a = min(x['arrival'], C - 1)
    last = x['last_granted']
    if last is not None and x['cycle_index'] - last <= x['lockout']:
        return ['locked', 0]
    gs, ge = x['green_start'], x['green_end']
    if gs <= a < ge:
        return ['none', 0]
    d = (a - ge) % C
    if d < x['max_ext']:
        return ['extend', d + 1]
    wait = (gs - a) % C
    return ['early', min(x['max_early'], wait)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'cycle': 100, 'green_start': 10, 'green_end': 50, 'max_ext': 10, 'max_early': 10, 'arrival': 250, 'last_granted': 3, 'cycle_index': 5, 'lockout': 2}, ['locked', 0]), ({'cycle': 120, 'green_start': 33, 'green_end': 56, 'max_ext': 8, 'max_early': 18, 'arrival': 319, 'last_granted': 8, 'cycle_index': 18, 'lockout': 3}, ['early', 18]), ({'cycle': 80, 'green_start': 26, 'green_end': 41, 'max_ext': 5, 'max_early': 11, 'arrival': 119, 'last_granted': None, 'cycle_index': 7, 'lockout': 2}, ['none', 0]), ({'cycle': 130, 'green_start': 17, 'green_end': 37, 'max_ext': 10, 'max_early': 17, 'arrival': 194, 'last_granted': 5, 'cycle_index': 10, 'lockout': 1}, ['early', 17]), ({'cycle': 100, 'green_start': 10, 'green_end': 45, 'max_ext': 10, 'max_early': 10, 'arrival': 110, 'last_granted': None, 'cycle_index': 4, 'lockout': 1}, ['none', 0]), ({'cycle': 80, 'green_start': 10, 'green_end': 43, 'max_ext': 8, 'max_early': 17, 'arrival': 121, 'last_granted': 9, 'cycle_index': 22, 'lockout': 1}, ['none', 0]), ({'cycle': 100, 'green_start': 30, 'green_end': 45, 'max_ext': 20, 'max_early': 10, 'arrival': 28, 'last_granted': 1, 'cycle_index': 6, 'lockout': 2}, ['early', 2]), ({'cycle': 100, 'green_start': 30, 'green_end': 74, 'max_ext': 6, 'max_early': 18, 'arrival': 212, 'last_granted': None, 'cycle_index': 2, 'lockout': 1}, ['early', 18])], [({'cycle': 90, 'green_start': 13, 'green_end': 37, 'max_ext': 13, 'max_early': 7, 'arrival': 98, 'last_granted': None, 'cycle_index': 20, 'lockout': 3}, ['early', 5]), ({'cycle': 100, 'green_start': 10, 'green_end': 50, 'max_ext': 10, 'max_early': 10, 'arrival': 250, 'last_granted': 3, 'cycle_index': 5, 'lockout': 2}, ['locked', 0]), ({'cycle': 90, 'green_start': 42, 'green_end': 79, 'max_ext': 20, 'max_early': 5, 'arrival': 49, 'last_granted': None, 'cycle_index': 21, 'lockout': 3}, ['none', 0]), ({'cycle': 90, 'green_start': 0, 'green_end': 40, 'max_ext': 12, 'max_early': 8, 'arrival': 40, 'last_granted': None, 'cycle_index': 0, 'lockout': 1}, ['extend', 1]), ({'cycle': 90, 'green_start': 5, 'green_end': 41, 'max_ext': 17, 'max_early': 17, 'arrival': 217, 'last_granted': None, 'cycle_index': 8, 'lockout': 3}, ['none', 0]), ({'cycle': 80, 'green_start': 22, 'green_end': 55, 'max_ext': 8, 'max_early': 9, 'arrival': 17, 'last_granted': None, 'cycle_index': 22, 'lockout': 3}, ['early', 5]), ({'cycle': 100, 'green_start': 10, 'green_end': 45, 'max_ext': 10, 'max_early': 10, 'arrival': 110, 'last_granted': None, 'cycle_index': 4, 'lockout': 1}, ['none', 0]), ({'cycle': 90, 'green_start': 30, 'green_end': 69, 'max_ext': 17, 'max_early': 7, 'arrival': 146, 'last_granted': 7, 'cycle_index': 12, 'lockout': 2}, ['none', 0])], [({'cycle': 120, 'green_start': 38, 'green_end': 79, 'max_ext': 11, 'max_early': 8, 'arrival': 227, 'last_granted': None, 'cycle_index': 17, 'lockout': 1}, ['early', 8]), ({'cycle': 100, 'green_start': 30, 'green_end': 45, 'max_ext': 20, 'max_early': 10, 'arrival': 28, 'last_granted': 1, 'cycle_index': 6, 'lockout': 2}, ['early', 2]), ({'cycle': 80, 'green_start': 6, 'green_end': 32, 'max_ext': 9, 'max_early': 14, 'arrival': 35, 'last_granted': None, 'cycle_index': 15, 'lockout': 2}, ['extend', 4]), ({'cycle': 80, 'green_start': 18, 'green_end': 36, 'max_ext': 15, 'max_early': 11, 'arrival': 98, 'last_granted': 1, 'cycle_index': 3, 'lockout': 1}, ['none', 0]), ({'cycle': 100, 'green_start': 10, 'green_end': 45, 'max_ext': 10, 'max_early': 10, 'arrival': 110, 'last_granted': None, 'cycle_index': 4, 'lockout': 1}, ['none', 0]), ({'cycle': 80, 'green_start': 21, 'green_end': 52, 'max_ext': 17, 'max_early': 8, 'arrival': 75, 'last_granted': None, 'cycle_index': 22, 'lockout': 1}, ['early', 8]), ({'cycle': 120, 'green_start': 60, 'green_end': 90, 'max_ext': 7, 'max_early': 12, 'arrival': 323, 'last_granted': 4, 'cycle_index': 20, 'lockout': 3}, ['none', 0]), ({'cycle': 90, 'green_start': 0, 'green_end': 40, 'max_ext': 12, 'max_early': 8, 'arrival': 40, 'last_granted': None, 'cycle_index': 0, 'lockout': 1}, ['extend', 1])], [({'cycle': 100, 'green_start': 36, 'green_end': 76, 'max_ext': 14, 'max_early': 6, 'arrival': 237, 'last_granted': None, 'cycle_index': 5, 'lockout': 3}, ['none', 0]), ({'cycle': 130, 'green_start': 61, 'green_end': 107, 'max_ext': 6, 'max_early': 17, 'arrival': 254, 'last_granted': None, 'cycle_index': 20, 'lockout': 1}, ['early', 17]), ({'cycle': 120, 'green_start': 17, 'green_end': 34, 'max_ext': 18, 'max_early': 18, 'arrival': 14, 'last_granted': None, 'cycle_index': 19, 'lockout': 2}, ['early', 3]), ({'cycle': 100, 'green_start': 30, 'green_end': 45, 'max_ext': 20, 'max_early': 10, 'arrival': 28, 'last_granted': 1, 'cycle_index': 6, 'lockout': 2}, ['early', 2]), ({'cycle': 110, 'green_start': 12, 'green_end': 40, 'max_ext': 5, 'max_early': 14, 'arrival': 128, 'last_granted': None, 'cycle_index': 12, 'lockout': 3}, ['none', 0]), ({'cycle': 100, 'green_start': 10, 'green_end': 45, 'max_ext': 10, 'max_early': 10, 'arrival': 110, 'last_granted': None, 'cycle_index': 4, 'lockout': 1}, ['none', 0]), ({'cycle': 100, 'green_start': 10, 'green_end': 50, 'max_ext': 10, 'max_early': 10, 'arrival': 250, 'last_granted': 3, 'cycle_index': 5, 'lockout': 2}, ['locked', 0]), ({'cycle': 140, 'green_start': 63, 'green_end': 107, 'max_ext': 8, 'max_early': 20, 'arrival': 247, 'last_granted': None, 'cycle_index': 11, 'lockout': 1}, ['extend', 1])], [({'cycle': 100, 'green_start': 10, 'green_end': 50, 'max_ext': 10, 'max_early': 10, 'arrival': 250, 'last_granted': 3, 'cycle_index': 5, 'lockout': 2}, ['locked', 0]), ({'cycle': 100, 'green_start': 29, 'green_end': 67, 'max_ext': 16, 'max_early': 15, 'arrival': 158, 'last_granted': None, 'cycle_index': 9, 'lockout': 3}, ['none', 0]), ({'cycle': 100, 'green_start': 30, 'green_end': 45, 'max_ext': 20, 'max_early': 10, 'arrival': 28, 'last_granted': 1, 'cycle_index': 6, 'lockout': 2}, ['early', 2]), ({'cycle': 100, 'green_start': 25, 'green_end': 65, 'max_ext': 12, 'max_early': 20, 'arrival': 265, 'last_granted': 9, 'cycle_index': 17, 'lockout': 1}, ['extend', 1]), ({'cycle': 90, 'green_start': 0, 'green_end': 40, 'max_ext': 12, 'max_early': 8, 'arrival': 40, 'last_granted': None, 'cycle_index': 0, 'lockout': 1}, ['extend', 1]), ({'cycle': 100, 'green_start': 16, 'green_end': 46, 'max_ext': 14, 'max_early': 12, 'arrival': 63, 'last_granted': None, 'cycle_index': 18, 'lockout': 3}, ['early', 12]), ({'cycle': 120, 'green_start': 1, 'green_end': 42, 'max_ext': 6, 'max_early': 11, 'arrival': 270, 'last_granted': None, 'cycle_index': 7, 'lockout': 1}, ['none', 0]), ({'cycle': 100, 'green_start': 37, 'green_end': 82, 'max_ext': 20, 'max_early': 5, 'arrival': 167, 'last_granted': None, 'cycle_index': 3, 'lockout': 2}, ['none', 0])]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check('timing oracle' + ' %d' % i, 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:
Transit signal priority decision returns a wrong result when arrival times beyond one cycle are clamped instead of wrapped.

Input {cycle, green_start, green_end (exclusive), max_ext, max_early, arrival (seconds, reduced modulo cycle), last_granted (cycle index or null), cycle_index, lockout}. A request within lockout cycles of the last grant (difference <= lockout) returns ['locked', 0]. Arrival in green needs nothing. If the arrival is less than max_ext seconds after green end (cyclically) green is extended through the arrival second: ['extend', d+1]. Otherwise green starts early by min(max_early, seconds until next green start).

split: open-access


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

N = 1
observations = []
def solve(x):
    C = x['cycle']
    a = x['arrival'] % C
    last = x['last_granted']
    if last is not None and x['cycle_index'] - last < x['lockout']:
        return ['locked', 0]
    gs, ge = x['green_start'], x['green_end']
    if gs <= a < ge:
        return ['none', 0]
    d = (a - ge) % C
    if d < x['max_ext']:
        return ['extend', d + 1]
    wait = (gs - a) % C
    return ['early', min(x['max_early'], wait)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'cycle': 80, 'green_start': 21, 'green_end': 54, 'max_ext': 11, 'max_early': 20, 'arrival': 204, 'last_granted': 18, 'cycle_index': 3, 'lockout': 2}, ['locked', 0]), ({'cycle': 100, 'green_start': 30, 'green_end': 45, 'max_ext': 20, 'max_early': 10, 'arrival': 28, 'last_granted': 1, 'cycle_index': 6, 'lockout': 2}, ['early', 2]), ({'cycle': 140, 'green_start': 22, 'green_end': 82, 'max_ext': 20, 'max_early': 12, 'arrival': 98, 'last_granted': 4, 'cycle_index': 5, 'lockout': 1}, ['locked', 0]), ({'cycle': 90, 'green_start': 7, 'green_end': 37, 'max_ext': 16, 'max_early': 14, 'arrival': 165, 'last_granted': 5, 'cycle_index': 6, 'lockout': 1}, ['locked', 0]), ({'cycle': 100, 'green_start': 10, 'green_end': 45, 'max_ext': 10, 'max_early': 10, 'arrival': 110, 'last_granted': None, 'cycle_index': 4, 'lockout': 1}, ['none', 0]), ({'cycle': 120, 'green_start': 14, 'green_end': 37, 'max_ext': 18, 'max_early': 14, 'arrival': 190, 'last_granted': 12, 'cycle_index': 14, 'lockout': 3}, ['locked', 0]), ({'cycle': 90, 'green_start': 0, 'green_end': 40, 'max_ext': 12, 'max_early': 8, 'arrival': 40, 'last_granted': None, 'cycle_index': 0, 'lockout': 1}, ['extend', 1]), ({'cycle': 90, 'green_start': 8, 'green_end': 29, 'max_ext': 13, 'max_early': 20, 'arrival': 146, 'last_granted': 5, 'cycle_index': 8, 'lockout': 3}, ['locked', 0])], [({'cycle': 90, 'green_start': 0, 'green_end': 40, 'max_ext': 12, 'max_early': 8, 'arrival': 40, 'last_granted': None, 'cycle_index': 0, 'lockout': 1}, ['extend', 1]), ({'cycle': 130, 'green_start': 43, 'green_end': 58, 'max_ext': 17, 'max_early': 10, 'arrival': 7, 'last_granted': 1, 'cycle_index': 7, 'lockout': 1}, ['early', 10]), ({'cycle': 80, 'green_start': 28, 'green_end': 64, 'max_ext': 6, 'max_early': 7, 'arrival': 101, 'last_granted': 9, 'cycle_index': 7, 'lockout': 1}, ['locked', 0]), ({'cycle': 130, 'green_start': 19, 'green_end': 74, 'max_ext': 12, 'max_early': 14, 'arrival': 130, 'last_granted': 14, 'cycle_index': 17, 'lockout': 3}, ['locked', 0]), ({'cycle': 120, 'green_start': 28, 'green_end': 69, 'max_ext': 17, 'max_early': 18, 'arrival': 81, 'last_granted': None, 'cycle_index': 7, 'lockout': 3}, ['extend', 13]), ({'cycle': 100, 'green_start': 10, 'green_end': 50, 'max_ext': 10, 'max_early': 10, 'arrival': 250, 'last_granted': 3, 'cycle_index': 5, 'lockout': 2}, ['locked', 0]), ({'cycle': 100, 'green_start': 30, 'green_end': 45, 'max_ext': 20, 'max_early': 10, 'arrival': 28, 'last_granted': 1, 'cycle_index': 6, 'lockout': 2}, ['early', 2]), ({'cycle': 140, 'green_start': 29, 'green_end': 54, 'max_ext': 14, 'max_early': 5, 'arrival': 42, 'last_granted': 10, 'cycle_index': 13, 'lockout': 3}, ['locked', 0])], [({'cycle': 130, 'green_start': 26, 'green_end': 46, 'max_ext': 9, 'max_early': 13, 'arrival': 214, 'last_granted': 6, 'cycle_index': 19, 'lockout': 3}, ['early', 13]), ({'cycle': 90, 'green_start': 25, 'green_end': 47, 'max_ext': 13, 'max_early': 7, 'arrival': 220, 'last_granted': 5, 'cycle_index': 7, 'lockout': 2}, ['locked', 0]), ({'cycle': 100, 'green_start': 10, 'green_end': 50, 'max_ext': 10, 'max_early': 10, 'arrival': 250, 'last_granted': 3, 'cycle_index': 5, 'lockout': 2}, ['locked', 0]), ({'cycle': 110, 'green_start': 46, 'green_end': 71, 'max_ext': 20, 'max_early': 9, 'arrival': 55, 'last_granted': None, 'cycle_index': 12, 'lockout': 3}, ['none', 0]), ({'cycle': 100, 'green_start': 10, 'green_end': 45, 'max_ext': 10, 'max_early': 10, 'arrival': 110, 'last_granted': None, 'cycle_index': 4, 'lockout': 1}, ['none', 0]), ({'cycle': 90, 'green_start': 0, 'green_end': 40, 'max_ext': 12, 'max_early': 8, 'arrival': 40, 'last_granted': None, 'cycle_index': 0, 'lockout': 1}, ['extend', 1]), ({'cycle': 100, 'green_start': 19, 'green_end': 35, 'max_ext': 18, 'max_early': 15, 'arrival': 139, 'last_granted': None, 'cycle_index': 0, 'lockout': 3}, ['extend', 5]), ({'cycle': 140, 'green_start': 4, 'green_end': 57, 'max_ext': 20, 'max_early': 19, 'arrival': 89, 'last_granted': 18, 'cycle_index': 21, 'lockout': 3}, ['locked', 0])], [({'cycle': 100, 'green_start': 30, 'green_end': 45, 'max_ext': 20, 'max_early': 10, 'arrival': 28, 'last_granted': 1, 'cycle_index': 6, 'lockout': 2}, ['early', 2]), ({'cycle': 100, 'green_start': 10, 'green_end': 45, 'max_ext': 10, 'max_early': 10, 'arrival': 110, 'last_granted': None, 'cycle_index': 4, 'lockout': 1}, ['none', 0]), ({'cycle': 90, 'green_start': 24, 'green_end': 45, 'max_ext': 5, 'max_early': 8, 'arrival': 267, 'last_granted': 2, 'cycle_index': 5, 'lockout': 3}, ['locked', 0]), ({'cycle': 90, 'green_start': 0, 'green_end': 36, 'max_ext': 5, 'max_early': 15, 'arrival': 137, 'last_granted': 16, 'cycle_index': 18, 'lockout': 3}, ['locked', 0]), ({'cycle': 90, 'green_start': 0, 'green_end': 40, 'max_ext': 12, 'max_early': 8, 'arrival': 40, 'last_granted': None, 'cycle_index': 0, 'lockout': 1}, ['extend', 1]), ({'cycle': 120, 'green_start': 13, 'green_end': 64, 'max_ext': 7, 'max_early': 14, 'arrival': 151, 'last_granted': 17, 'cycle_index': 19, 'lockout': 2}, ['locked', 0]), ({'cycle': 140, 'green_start': 53, 'green_end': 103, 'max_ext': 15, 'max_early': 10, 'arrival': 298, 'last_granted': 3, 'cycle_index': 4, 'lockout': 1}, ['locked', 0]), ({'cycle': 120, 'green_start': 45, 'green_end': 69, 'max_ext': 12, 'max_early': 17, 'arrival': 116, 'last_granted': 5, 'cycle_index': 5, 'lockout': 1}, ['locked', 0])], [({'cycle': 100, 'green_start': 10, 'green_end': 45, 'max_ext': 10, 'max_early': 10, 'arrival': 110, 'last_granted': None, 'cycle_index': 4, 'lockout': 1}, ['none', 0]), ({'cycle': 100, 'green_start': 13, 'green_end': 36, 'max_ext': 18, 'max_early': 7, 'arrival': 201, 'last_granted': 13, 'cycle_index': 15, 'lockout': 2}, ['locked', 0]), ({'cycle': 140, 'green_start': 23, 'green_end': 49, 'max_ext': 16, 'max_early': 17, 'arrival': 420, 'last_granted': 19, 'cycle_index': 3, 'lockout': 1}, ['locked', 0]), ({'cycle': 120, 'green_start': 12, 'green_end': 42, 'max_ext': 7, 'max_early': 13, 'arrival': 45, 'last_granted': 6, 'cycle_index': 8, 'lockout': 2}, ['locked', 0]), ({'cycle': 100, 'green_start': 10, 'green_end': 50, 'max_ext': 10, 'max_early': 10, 'arrival': 250, 'last_granted': 3, 'cycle_index': 5, 'lockout': 2}, ['locked', 0]), ({'cycle': 100, 'green_start': 30, 'green_end': 45, 'max_ext': 20, 'max_early': 10, 'arrival': 28, 'last_granted': 1, 'cycle_index': 6, 'lockout': 2}, ['early', 2]), ({'cycle': 80, 'green_start': 24, 'green_end': 55, 'max_ext': 13, 'max_early': 19, 'arrival': 191, 'last_granted': 1, 'cycle_index': 18, 'lockout': 2}, ['none', 0]), ({'cycle': 120, 'green_start': 52, 'green_end': 74, 'max_ext': 20, 'max_early': 13, 'arrival': 248, 'last_granted': None, 'cycle_index': 12, 'lockout': 1}, ['early', 13])]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check('timing oracle' + ' %d' % i, 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):
    C = x['cycle']
    a = x['arrival'] % C
    last = x['last_granted']
    if last is not None and x['cycle_index'] <= x['lockout']:
        return ['locked', 0]
    gs, ge = x['green_start'], x['green_end']
    if gs <= a < ge:
        return ['none', 0]
    d = (a - ge) % C
    if d < x['max_ext']:
        return ['extend', d + 1]
    wait = (gs - a) % C
    return ['early', min(x['max_early'], wait)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'cycle': 80, 'green_start': 21, 'green_end': 54, 'max_ext': 11, 'max_early': 20, 'arrival': 204, 'last_granted': 18, 'cycle_index': 3, 'lockout': 2}, ['locked', 0]), ({'cycle': 100, 'green_start': 30, 'green_end': 45, 'max_ext': 20, 'max_early': 10, 'arrival': 28, 'last_granted': 1, 'cycle_index': 6, 'lockout': 2}, ['early', 2]), ({'cycle': 140, 'green_start': 22, 'green_end': 82, 'max_ext': 20, 'max_early': 12, 'arrival': 98, 'last_granted': 4, 'cycle_index': 5, 'lockout': 1}, ['locked', 0]), ({'cycle': 90, 'green_start': 7, 'green_end': 37, 'max_ext': 16, 'max_early': 14, 'arrival': 165, 'last_granted': 5, 'cycle_index': 6, 'lockout': 1}, ['locked', 0]), ({'cycle': 100, 'green_start': 10, 'green_end': 45, 'max_ext': 10, 'max_early': 10, 'arrival': 110, 'last_granted': None, 'cycle_index': 4, 'lockout': 1}, ['none', 0]), ({'cycle': 120, 'green_start': 14, 'green_end': 37, 'max_ext': 18, 'max_early': 14, 'arrival': 190, 'last_granted': 12, 'cycle_index': 14, 'lockout': 3}, ['locked', 0]), ({'cycle': 90, 'green_start': 0, 'green_end': 40, 'max_ext': 12, 'max_early': 8, 'arrival': 40, 'last_granted': None, 'cycle_index': 0, 'lockout': 1}, ['extend', 1]), ({'cycle': 90, 'green_start': 8, 'green_end': 29, 'max_ext': 13, 'max_early': 20, 'arrival': 146, 'last_granted': 5, 'cycle_index': 8, 'lockout': 3}, ['locked', 0])], [({'cycle': 90, 'green_start': 0, 'green_end': 40, 'max_ext': 12, 'max_early': 8, 'arrival': 40, 'last_granted': None, 'cycle_index': 0, 'lockout': 1}, ['extend', 1]), ({'cycle': 130, 'green_start': 43, 'green_end': 58, 'max_ext': 17, 'max_early': 10, 'arrival': 7, 'last_granted': 1, 'cycle_index': 7, 'lockout': 1}, ['early', 10]), ({'cycle': 80, 'green_start': 28, 'green_end': 64, 'max_ext': 6, 'max_early': 7, 'arrival': 101, 'last_granted': 9, 'cycle_index': 7, 'lockout': 1}, ['locked', 0]), ({'cycle': 130, 'green_start': 19, 'green_end': 74, 'max_ext': 12, 'max_early': 14, 'arrival': 130, 'last_granted': 14, 'cycle_index': 17, 'lockout': 3}, ['locked', 0]), ({'cycle': 120, 'green_start': 28, 'green_end': 69, 'max_ext': 17, 'max_early': 18, 'arrival': 81, 'last_granted': None, 'cycle_index': 7, 'lockout': 3}, ['extend', 13]), ({'cycle': 100, 'green_start': 10, 'green_end': 50, 'max_ext': 10, 'max_early': 10, 'arrival': 250, 'last_granted': 3, 'cycle_index': 5, 'lockout': 2}, ['locked', 0]), ({'cycle': 100, 'green_start': 30, 'green_end': 45, 'max_ext': 20, 'max_early': 10, 'arrival': 28, 'last_granted': 1, 'cycle_index': 6, 'lockout': 2}, ['early', 2]), ({'cycle': 140, 'green_start': 29, 'green_end': 54, 'max_ext': 14, 'max_early': 5, 'arrival': 42, 'last_granted': 10, 'cycle_index': 13, 'lockout': 3}, ['locked', 0])], [({'cycle': 130, 'green_start': 26, 'green_end': 46, 'max_ext': 9, 'max_early': 13, 'arrival': 214, 'last_granted': 6, 'cycle_index': 19, 'lockout': 3}, ['early', 13]), ({'cycle': 90, 'green_start': 25, 'green_end': 47, 'max_ext': 13, 'max_early': 7, 'arrival': 220, 'last_granted': 5, 'cycle_index': 7, 'lockout': 2}, ['locked', 0]), ({'cycle': 100, 'green_start': 10, 'green_end': 50, 'max_ext': 10, 'max_early': 10, 'arrival': 250, 'last_granted': 3, 'cycle_index': 5, 'lockout': 2}, ['locked', 0]), ({'cycle': 110, 'green_start': 46, 'green_end': 71, 'max_ext': 20, 'max_early': 9, 'arrival': 55, 'last_granted': None, 'cycle_index': 12, 'lockout': 3}, ['none', 0]), ({'cycle': 100, 'green_start': 10, 'green_end': 45, 'max_ext': 10, 'max_early': 10, 'arrival': 110, 'last_granted': None, 'cycle_index': 4, 'lockout': 1}, ['none', 0]), ({'cycle': 90, 'green_start': 0, 'green_end': 40, 'max_ext': 12, 'max_early': 8, 'arrival': 40, 'last_granted': None, 'cycle_index': 0, 'lockout': 1}, ['extend', 1]), ({'cycle': 100, 'green_start': 19, 'green_end': 35, 'max_ext': 18, 'max_early': 15, 'arrival': 139, 'last_granted': None, 'cycle_index': 0, 'lockout': 3}, ['extend', 5]), ({'cycle': 140, 'green_start': 4, 'green_end': 57, 'max_ext': 20, 'max_early': 19, 'arrival': 89, 'last_granted': 18, 'cycle_index': 21, 'lockout': 3}, ['locked', 0])], [({'cycle': 100, 'green_start': 30, 'green_end': 45, 'max_ext': 20, 'max_early': 10, 'arrival': 28, 'last_granted': 1, 'cycle_index': 6, 'lockout': 2}, ['early', 2]), ({'cycle': 100, 'green_start': 10, 'green_end': 45, 'max_ext': 10, 'max_early': 10, 'arrival': 110, 'last_granted': None, 'cycle_index': 4, 'lockout': 1}, ['none', 0]), ({'cycle': 90, 'green_start': 24, 'green_end': 45, 'max_ext': 5, 'max_early': 8, 'arrival': 267, 'last_granted': 2, 'cycle_index': 5, 'lockout': 3}, ['locked', 0]), ({'cycle': 90, 'green_start': 0, 'green_end': 36, 'max_ext': 5, 'max_early': 15, 'arrival': 137, 'last_granted': 16, 'cycle_index': 18, 'lockout': 3}, ['locked', 0]), ({'cycle': 90, 'green_start': 0, 'green_end': 40, 'max_ext': 12, 'max_early': 8, 'arrival': 40, 'last_granted': None, 'cycle_index': 0, 'lockout': 1}, ['extend', 1]), ({'cycle': 120, 'green_start': 13, 'green_end': 64, 'max_ext': 7, 'max_early': 14, 'arrival': 151, 'last_granted': 17, 'cycle_index': 19, 'lockout': 2}, ['locked', 0]), ({'cycle': 140, 'green_start': 53, 'green_end': 103, 'max_ext': 15, 'max_early': 10, 'arrival': 298, 'last_granted': 3, 'cycle_index': 4, 'lockout': 1}, ['locked', 0]), ({'cycle': 120, 'green_start': 45, 'green_end': 69, 'max_ext': 12, 'max_early': 17, 'arrival': 116, 'last_granted': 5, 'cycle_index': 5, 'lockout': 1}, ['locked', 0])], [({'cycle': 100, 'green_start': 10, 'green_end': 45, 'max_ext': 10, 'max_early': 10, 'arrival': 110, 'last_granted': None, 'cycle_index': 4, 'lockout': 1}, ['none', 0]), ({'cycle': 100, 'green_start': 13, 'green_end': 36, 'max_ext': 18, 'max_early': 7, 'arrival': 201, 'last_granted': 13, 'cycle_index': 15, 'lockout': 2}, ['locked', 0]), ({'cycle': 140, 'green_start': 23, 'green_end': 49, 'max_ext': 16, 'max_early': 17, 'arrival': 420, 'last_granted': 19, 'cycle_index': 3, 'lockout': 1}, ['locked', 0]), ({'cycle': 120, 'green_start': 12, 'green_end': 42, 'max_ext': 7, 'max_early': 13, 'arrival': 45, 'last_granted': 6, 'cycle_index': 8, 'lockout': 2}, ['locked', 0]), ({'cycle': 100, 'green_start': 10, 'green_end': 50, 'max_ext': 10, 'max_early': 10, 'arrival': 250, 'last_granted': 3, 'cycle_index': 5, 'lockout': 2}, ['locked', 0]), ({'cycle': 100, 'green_start': 30, 'green_end': 45, 'max_ext': 20, 'max_early': 10, 'arrival': 28, 'last_granted': 1, 'cycle_index': 6, 'lockout': 2}, ['early', 2]), ({'cycle': 80, 'green_start': 24, 'green_end': 55, 'max_ext': 13, 'max_early': 19, 'arrival': 191, 'last_granted': 1, 'cycle_index': 18, 'lockout': 2}, ['none', 0]), ({'cycle': 120, 'green_start': 52, 'green_end': 74, 'max_ext': 20, 'max_early': 13, 'arrival': 248, 'last_granted': None, 'cycle_index': 12, 'lockout': 1}, ['early', 13])]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check('timing oracle' + ' %d' % i, 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:
Transit signal priority decision returns a wrong result when the lockout window lets the boundary cycle through.

Input {cycle, green_start, green_end (exclusive), max_ext, max_early, arrival (seconds, reduced modulo cycle), last_granted (cycle index or null), cycle_index, lockout}. A request within lockout cycles of the last grant (difference <= lockout) returns ['locked', 0]. Arrival in green needs nothing. If the arrival is less than max_ext seconds after green end (cyclically) green is extended through the arrival second: ['extend', d+1]. Otherwise green starts early by min(max_early, seconds until next green start).

split: open-access


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

N = 1
observations = []
def solve(x):
    C = x['cycle']
    a = x['arrival'] % C
    last = x['last_granted']
    if last is not None and x['cycle_index'] - last <= x['lockout']:
        return ['locked', 0]
    gs, ge = x['green_start'], x['green_end']
    if gs <= a <= ge:
        return ['none', 0]
    d = (a - ge) % C
    if d < x['max_ext']:
        return ['extend', d + 1]
    wait = (gs - a) % C
    return ['early', min(x['max_early'], wait)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'cycle': 100, 'green_start': 10, 'green_end': 45, 'max_ext': 10, 'max_early': 10, 'arrival': 110, 'last_granted': None, 'cycle_index': 4, 'lockout': 1}, ['none', 0]), ({'cycle': 120, 'green_start': 19, 'green_end': 58, 'max_ext': 13, 'max_early': 8, 'arrival': 110, 'last_granted': 14, 'cycle_index': 21, 'lockout': 2}, ['early', 8]), ({'cycle': 100, 'green_start': 10, 'green_end': 50, 'max_ext': 10, 'max_early': 10, 'arrival': 250, 'last_granted': 3, 'cycle_index': 5, 'lockout': 2}, ['locked', 0]), ({'cycle': 90, 'green_start': 20, 'green_end': 35, 'max_ext': 5, 'max_early': 14, 'arrival': 141, 'last_granted': 16, 'cycle_index': 21, 'lockout': 1}, ['early', 14]), ({'cycle': 90, 'green_start': 0, 'green_end': 40, 'max_ext': 12, 'max_early': 8, 'arrival': 40, 'last_granted': None, 'cycle_index': 0, 'lockout': 1}, ['extend', 1]), ({'cycle': 100, 'green_start': 50, 'green_end': 89, 'max_ext': 17, 'max_early': 13, 'arrival': 150, 'last_granted': None, 'cycle_index': 14, 'lockout': 3}, ['none', 0]), ({'cycle': 80, 'green_start': 3, 'green_end': 37, 'max_ext': 11, 'max_early': 15, 'arrival': 40, 'last_granted': None, 'cycle_index': 22, 'lockout': 1}, ['extend', 4]), ({'cycle': 90, 'green_start': 7, 'green_end': 32, 'max_ext': 8, 'max_early': 14, 'arrival': 32, 'last_granted': 1, 'cycle_index': 10, 'lockout': 1}, ['extend', 1])], [({'cycle': 100, 'green_start': 10, 'green_end': 50, 'max_ext': 10, 'max_early': 10, 'arrival': 250, 'last_granted': 3, 'cycle_index': 5, 'lockout': 2}, ['locked', 0]), ({'cycle': 90, 'green_start': 0, 'green_end': 40, 'max_ext': 12, 'max_early': 8, 'arrival': 40, 'last_granted': None, 'cycle_index': 0, 'lockout': 1}, ['extend', 1]), ({'cycle': 110, 'green_start': 22, 'green_end': 56, 'max_ext': 11, 'max_early': 16, 'arrival': 132, 'last_granted': 17, 'cycle_index': 22, 'lockout': 3}, ['none', 0]), ({'cycle': 90, 'green_start': 37, 'green_end': 54, 'max_ext': 11, 'max_early': 6, 'arrival': 234, 'last_granted': None, 'cycle_index': 3, 'lockout': 2}, ['extend', 1]), ({'cycle': 100, 'green_start': 10, 'green_end': 45, 'max_ext': 10, 'max_early': 10, 'arrival': 110, 'last_granted': None, 'cycle_index': 4, 'lockout': 1}, ['none', 0]), ({'cycle': 130, 'green_start': 27, 'green_end': 52, 'max_ext': 11, 'max_early': 9, 'arrival': 318, 'last_granted': None, 'cycle_index': 1, 'lockout': 2}, ['extend', 7]), ({'cycle': 100, 'green_start': 30, 'green_end': 45, 'max_ext': 20, 'max_early': 10, 'arrival': 28, 'last_granted': 1, 'cycle_index': 6, 'lockout': 2}, ['early', 2]), ({'cycle': 80, 'green_start': 9, 'green_end': 46, 'max_ext': 15, 'max_early': 20, 'arrival': 106, 'last_granted': 20, 'cycle_index': 16, 'lockout': 2}, ['locked', 0])], [({'cycle': 100, 'green_start': 10, 'green_end': 45, 'max_ext': 10, 'max_early': 10, 'arrival': 110, 'last_granted': None, 'cycle_index': 4, 'lockout': 1}, ['none', 0]), ({'cycle': 100, 'green_start': 0, 'green_end': 17, 'max_ext': 7, 'max_early': 8, 'arrival': 265, 'last_granted': None, 'cycle_index': 15, 'lockout': 1}, ['early', 8]), ({'cycle': 90, 'green_start': 40, 'green_end': 65, 'max_ext': 11, 'max_early': 14, 'arrival': 21, 'last_granted': None, 'cycle_index': 15, 'lockout': 1}, ['early', 14]), ({'cycle': 90, 'green_start': 0, 'green_end': 40, 'max_ext': 12, 'max_early': 8, 'arrival': 40, 'last_granted': None, 'cycle_index': 0, 'lockout': 1}, ['extend', 1]), ({'cycle': 100, 'green_start': 10, 'green_end': 50, 'max_ext': 10, 'max_early': 10, 'arrival': 250, 'last_granted': 3, 'cycle_index': 5, 'lockout': 2}, ['locked', 0]), ({'cycle': 90, 'green_start': 26, 'green_end': 47, 'max_ext': 15, 'max_early': 19, 'arrival': 137, 'last_granted': 10, 'cycle_index': 21, 'lockout': 2}, ['extend', 1]), ({'cycle': 140, 'green_start': 29, 'green_end': 55, 'max_ext': 14, 'max_early': 16, 'arrival': 195, 'last_granted': 8, 'cycle_index': 19, 'lockout': 3}, ['extend', 1]), ({'cycle': 110, 'green_start': 46, 'green_end': 66, 'max_ext': 10, 'max_early': 12, 'arrival': 204, 'last_granted': 12, 'cycle_index': 19, 'lockout': 3}, ['early', 12])], [({'cycle': 140, 'green_start': 65, 'green_end': 92, 'max_ext': 12, 'max_early': 13, 'arrival': 196, 'last_granted': None, 'cycle_index': 6, 'lockout': 2}, ['early', 9]), ({'cycle': 100, 'green_start': 3, 'green_end': 52, 'max_ext': 11, 'max_early': 9, 'arrival': 252, 'last_granted': None, 'cycle_index': 13, 'lockout': 1}, ['extend', 1]), ({'cycle': 100, 'green_start': 10, 'green_end': 50, 'max_ext': 10, 'max_early': 10, 'arrival': 250, 'last_granted': 3, 'cycle_index': 5, 'lockout': 2}, ['locked', 0]), ({'cycle': 90, 'green_start': 2, 'green_end': 21, 'max_ext': 13, 'max_early': 19, 'arrival': 182, 'last_granted': None, 'cycle_index': 8, 'lockout': 2}, ['none', 0]), ({'cycle': 100, 'green_start': 10, 'green_end': 45, 'max_ext': 10, 'max_early': 10, 'arrival': 110, 'last_granted': None, 'cycle_index': 4, 'lockout': 1}, ['none', 0]), ({'cycle': 90, 'green_start': 0, 'green_end': 40, 'max_ext': 12, 'max_early': 8, 'arrival': 40, 'last_granted': None, 'cycle_index': 0, 'lockout': 1}, ['extend', 1]), ({'cycle': 130, 'green_start': 65, 'green_end': 93, 'max_ext': 6, 'max_early': 10, 'arrival': 245, 'last_granted': 13, 'cycle_index': 22, 'lockout': 1}, ['early', 10]), ({'cycle': 100, 'green_start': 22, 'green_end': 55, 'max_ext': 19, 'max_early': 16, 'arrival': 255, 'last_granted': None, 'cycle_index': 17, 'lockout': 3}, ['extend', 1])], [({'cycle': 120, 'green_start': 2, 'green_end': 19, 'max_ext': 7, 'max_early': 19, 'arrival': 259, 'last_granted': None, 'cycle_index': 16, 'lockout': 2}, ['extend', 1]), ({'cycle': 100, 'green_start': 30, 'green_end': 45, 'max_ext': 20, 'max_early': 10, 'arrival': 28, 'last_granted': 1, 'cycle_index': 6, 'lockout': 2}, ['early', 2]), ({'cycle': 100, 'green_start': 10, 'green_end': 45, 'max_ext': 10, 'max_early': 10, 'arrival': 110, 'last_granted': None, 'cycle_index': 4, 'lockout': 1}, ['none', 0]), ({'cycle': 100, 'green_start': 34, 'green_end': 62, 'max_ext': 16, 'max_early': 10, 'arrival': 134, 'last_granted': None, 'cycle_index': 4, 'lockout': 2}, ['none', 0]), ({'cycle': 90, 'green_start': 0, 'green_end': 40, 'max_ext': 12, 'max_early': 8, 'arrival': 40, 'last_granted': None, 'cycle_index': 0, 'lockout': 1}, ['extend', 1]), ({'cycle': 140, 'green_start': 49, 'green_end': 114, 'max_ext': 18, 'max_early': 19, 'arrival': 53, 'last_granted': 5, 'cycle_index': 7, 'lockout': 1}, ['none', 0]), ({'cycle': 140, 'green_start': 63, 'green_end': 112, 'max_ext': 9, 'max_early': 6, 'arrival': 347, 'last_granted': None, 'cycle_index': 11, 'lockout': 2}, ['none', 0]), ({'cycle': 100, 'green_start': 40, 'green_end': 58, 'max_ext': 9, 'max_early': 14, 'arrival': 286, 'last_granted': None, 'cycle_index': 22, 'lockout': 1}, ['early', 14])]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check('timing oracle' + ' %d' % i, 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):
    C = x['cycle']
    a = x['arrival'] % C
    last = x['last_granted']
    if last is not None and x['cycle_index'] - last <= x['lockout']:
        return ['locked', 0]
    gs, ge = x['green_start'], x['green_end']
    if gs < a < ge:
        return ['none', 0]
    d = (a - ge) % C
    if d < x['max_ext']:
        return ['extend', d + 1]
    wait = (gs - a) % C
    return ['early', min(x['max_early'], wait)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'cycle': 100, 'green_start': 10, 'green_end': 45, 'max_ext': 10, 'max_early': 10, 'arrival': 110, 'last_granted': None, 'cycle_index': 4, 'lockout': 1}, ['none', 0]), ({'cycle': 120, 'green_start': 19, 'green_end': 58, 'max_ext': 13, 'max_early': 8, 'arrival': 110, 'last_granted': 14, 'cycle_index': 21, 'lockout': 2}, ['early', 8]), ({'cycle': 100, 'green_start': 10, 'green_end': 50, 'max_ext': 10, 'max_early': 10, 'arrival': 250, 'last_granted': 3, 'cycle_index': 5, 'lockout': 2}, ['locked', 0]), ({'cycle': 90, 'green_start': 20, 'green_end': 35, 'max_ext': 5, 'max_early': 14, 'arrival': 141, 'last_granted': 16, 'cycle_index': 21, 'lockout': 1}, ['early', 14]), ({'cycle': 90, 'green_start': 0, 'green_end': 40, 'max_ext': 12, 'max_early': 8, 'arrival': 40, 'last_granted': None, 'cycle_index': 0, 'lockout': 1}, ['extend', 1]), ({'cycle': 100, 'green_start': 50, 'green_end': 89, 'max_ext': 17, 'max_early': 13, 'arrival': 150, 'last_granted': None, 'cycle_index': 14, 'lockout': 3}, ['none', 0]), ({'cycle': 80, 'green_start': 3, 'green_end': 37, 'max_ext': 11, 'max_early': 15, 'arrival': 40, 'last_granted': None, 'cycle_index': 22, 'lockout': 1}, ['extend', 4]), ({'cycle': 90, 'green_start': 7, 'green_end': 32, 'max_ext': 8, 'max_early': 14, 'arrival': 32, 'last_granted': 1, 'cycle_index': 10, 'lockout': 1}, ['extend', 1])], [({'cycle': 100, 'green_start': 10, 'green_end': 50, 'max_ext': 10, 'max_early': 10, 'arrival': 250, 'last_granted': 3, 'cycle_index': 5, 'lockout': 2}, ['locked', 0]), ({'cycle': 90, 'green_start': 0, 'green_end': 40, 'max_ext': 12, 'max_early': 8, 'arrival': 40, 'last_granted': None, 'cycle_index': 0, 'lockout': 1}, ['extend', 1]), ({'cycle': 110, 'green_start': 22, 'green_end': 56, 'max_ext': 11, 'max_early': 16, 'arrival': 132, 'last_granted': 17, 'cycle_index': 22, 'lockout': 3}, ['none', 0]), ({'cycle': 90, 'green_start': 37, 'green_end': 54, 'max_ext': 11, 'max_early': 6, 'arrival': 234, 'last_granted': None, 'cycle_index': 3, 'lockout': 2}, ['extend', 1]), ({'cycle': 100, 'green_start': 10, 'green_end': 45, 'max_ext': 10, 'max_early': 10, 'arrival': 110, 'last_granted': None, 'cycle_index': 4, 'lockout': 1}, ['none', 0]), ({'cycle': 130, 'green_start': 27, 'green_end': 52, 'max_ext': 11, 'max_early': 9, 'arrival': 318, 'last_granted': None, 'cycle_index': 1, 'lockout': 2}, ['extend', 7]), ({'cycle': 100, 'green_start': 30, 'green_end': 45, 'max_ext': 20, 'max_early': 10, 'arrival': 28, 'last_granted': 1, 'cycle_index': 6, 'lockout': 2}, ['early', 2]), ({'cycle': 80, 'green_start': 9, 'green_end': 46, 'max_ext': 15, 'max_early': 20, 'arrival': 106, 'last_granted': 20, 'cycle_index': 16, 'lockout': 2}, ['locked', 0])], [({'cycle': 100, 'green_start': 10, 'green_end': 45, 'max_ext': 10, 'max_early': 10, 'arrival': 110, 'last_granted': None, 'cycle_index': 4, 'lockout': 1}, ['none', 0]), ({'cycle': 100, 'green_start': 0, 'green_end': 17, 'max_ext': 7, 'max_early': 8, 'arrival': 265, 'last_granted': None, 'cycle_index': 15, 'lockout': 1}, ['early', 8]), ({'cycle': 90, 'green_start': 40, 'green_end': 65, 'max_ext': 11, 'max_early': 14, 'arrival': 21, 'last_granted': None, 'cycle_index': 15, 'lockout': 1}, ['early', 14]), ({'cycle': 90, 'green_start': 0, 'green_end': 40, 'max_ext': 12, 'max_early': 8, 'arrival': 40, 'last_granted': None, 'cycle_index': 0, 'lockout': 1}, ['extend', 1]), ({'cycle': 100, 'green_start': 10, 'green_end': 50, 'max_ext': 10, 'max_early': 10, 'arrival': 250, 'last_granted': 3, 'cycle_index': 5, 'lockout': 2}, ['locked', 0]), ({'cycle': 90, 'green_start': 26, 'green_end': 47, 'max_ext': 15, 'max_early': 19, 'arrival': 137, 'last_granted': 10, 'cycle_index': 21, 'lockout': 2}, ['extend', 1]), ({'cycle': 140, 'green_start': 29, 'green_end': 55, 'max_ext': 14, 'max_early': 16, 'arrival': 195, 'last_granted': 8, 'cycle_index': 19, 'lockout': 3}, ['extend', 1]), ({'cycle': 110, 'green_start': 46, 'green_end': 66, 'max_ext': 10, 'max_early': 12, 'arrival': 204, 'last_granted': 12, 'cycle_index': 19, 'lockout': 3}, ['early', 12])], [({'cycle': 140, 'green_start': 65, 'green_end': 92, 'max_ext': 12, 'max_early': 13, 'arrival': 196, 'last_granted': None, 'cycle_index': 6, 'lockout': 2}, ['early', 9]), ({'cycle': 100, 'green_start': 3, 'green_end': 52, 'max_ext': 11, 'max_early': 9, 'arrival': 252, 'last_granted': None, 'cycle_index': 13, 'lockout': 1}, ['extend', 1]), ({'cycle': 100, 'green_start': 10, 'green_end': 50, 'max_ext': 10, 'max_early': 10, 'arrival': 250, 'last_granted': 3, 'cycle_index': 5, 'lockout': 2}, ['locked', 0]), ({'cycle': 90, 'green_start': 2, 'green_end': 21, 'max_ext': 13, 'max_early': 19, 'arrival': 182, 'last_granted': None, 'cycle_index': 8, 'lockout': 2}, ['none', 0]), ({'cycle': 100, 'green_start': 10, 'green_end': 45, 'max_ext': 10, 'max_early': 10, 'arrival': 110, 'last_granted': None, 'cycle_index': 4, 'lockout': 1}, ['none', 0]), ({'cycle': 90, 'green_start': 0, 'green_end': 40, 'max_ext': 12, 'max_early': 8, 'arrival': 40, 'last_granted': None, 'cycle_index': 0, 'lockout': 1}, ['extend', 1]), ({'cycle': 130, 'green_start': 65, 'green_end': 93, 'max_ext': 6, 'max_early': 10, 'arrival': 245, 'last_granted': 13, 'cycle_index': 22, 'lockout': 1}, ['early', 10]), ({'cycle': 100, 'green_start': 22, 'green_end': 55, 'max_ext': 19, 'max_early': 16, 'arrival': 255, 'last_granted': None, 'cycle_index': 17, 'lockout': 3}, ['extend', 1])], [({'cycle': 120, 'green_start': 2, 'green_end': 19, 'max_ext': 7, 'max_early': 19, 'arrival': 259, 'last_granted': None, 'cycle_index': 16, 'lockout': 2}, ['extend', 1]), ({'cycle': 100, 'green_start': 30, 'green_end': 45, 'max_ext': 20, 'max_early': 10, 'arrival': 28, 'last_granted': 1, 'cycle_index': 6, 'lockout': 2}, ['early', 2]), ({'cycle': 100, 'green_start': 10, 'green_end': 45, 'max_ext': 10, 'max_early': 10, 'arrival': 110, 'last_granted': None, 'cycle_index': 4, 'lockout': 1}, ['none', 0]), ({'cycle': 100, 'green_start': 34, 'green_end': 62, 'max_ext': 16, 'max_early': 10, 'arrival': 134, 'last_granted': None, 'cycle_index': 4, 'lockout': 2}, ['none', 0]), ({'cycle': 90, 'green_start': 0, 'green_end': 40, 'max_ext': 12, 'max_early': 8, 'arrival': 40, 'last_granted': None, 'cycle_index': 0, 'lockout': 1}, ['extend', 1]), ({'cycle': 140, 'green_start': 49, 'green_end': 114, 'max_ext': 18, 'max_early': 19, 'arrival': 53, 'last_granted': 5, 'cycle_index': 7, 'lockout': 1}, ['none', 0]), ({'cycle': 140, 'green_start': 63, 'green_end': 112, 'max_ext': 9, 'max_early': 6, 'arrival': 347, 'last_granted': None, 'cycle_index': 11, 'lockout': 2}, ['none', 0]), ({'cycle': 100, 'green_start': 40, 'green_end': 58, 'max_ext': 9, 'max_early': 14, 'arrival': 286, 'last_granted': None, 'cycle_index': 22, 'lockout': 1}, ['early', 14])]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check('timing oracle' + ' %d' % i, 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:
Transit signal priority decision returns a wrong result when a bus arriving at green end is treated as in green.

Input {cycle, green_start, green_end (exclusive), max_ext, max_early, arrival (seconds, reduced modulo cycle), last_granted (cycle index or null), cycle_index, lockout}. A request within lockout cycles of the last grant (difference <= lockout) returns ['locked', 0]. Arrival in green needs nothing. If the arrival is less than max_ext seconds after green end (cyclically) green is extended through the arrival second: ['extend', d+1]. Otherwise green starts early by min(max_early, seconds until next green start).

split: open-access


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

N = 1
observations = []
def solve(x):
    C = x['cycle']
    a = x['arrival'] % C
    last = x['last_granted']
    if last is not None and x['cycle_index'] - last <= x['lockout']:
        return ['locked', 0]
    gs, ge = x['green_start'], x['green_end']
    if gs <= a < ge:
        return ['none', 0]
    d = a - ge
    if d < x['max_ext']:
        return ['extend', d + 1]
    wait = (gs - a) % C
    return ['early', min(x['max_early'], wait)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'cycle': 130, 'green_start': 31, 'green_end': 90, 'max_ext': 11, 'max_early': 18, 'arrival': 239, 'last_granted': 12, 'cycle_index': 10, 'lockout': 3}, ['locked', 0]), ({'cycle': 100, 'green_start': 10, 'green_end': 45, 'max_ext': 10, 'max_early': 10, 'arrival': 110, 'last_granted': None, 'cycle_index': 4, 'lockout': 1}, ['none', 0]), ({'cycle': 110, 'green_start': 54, 'green_end': 69, 'max_ext': 17, 'max_early': 15, 'arrival': 53, 'last_granted': None, 'cycle_index': 5, 'lockout': 2}, ['early', 1]), ({'cycle': 90, 'green_start': 42, 'green_end': 58, 'max_ext': 11, 'max_early': 12, 'arrival': 112, 'last_granted': 14, 'cycle_index': 17, 'lockout': 2}, ['early', 12]), ({'cycle': 130, 'green_start': 36, 'green_end': 55, 'max_ext': 11, 'max_early': 19, 'arrival': 284, 'last_granted': None, 'cycle_index': 5, 'lockout': 3}, ['early', 12]), ({'cycle': 130, 'green_start': 12, 'green_end': 47, 'max_ext': 16, 'max_early': 20, 'arrival': 222, 'last_granted': None, 'cycle_index': 22, 'lockout': 3}, ['early', 20]), ({'cycle': 100, 'green_start': 30, 'green_end': 45, 'max_ext': 20, 'max_early': 10, 'arrival': 28, 'last_granted': 1, 'cycle_index': 6, 'lockout': 2}, ['early', 2]), ({'cycle': 90, 'green_start': 0, 'green_end': 40, 'max_ext': 12, 'max_early': 8, 'arrival': 40, 'last_granted': None, 'cycle_index': 0, 'lockout': 1}, ['extend', 1])], [({'cycle': 120, 'green_start': 42, 'green_end': 99, 'max_ext': 17, 'max_early': 19, 'arrival': 244, 'last_granted': None, 'cycle_index': 8, 'lockout': 1}, ['early', 19]), ({'cycle': 90, 'green_start': 0, 'green_end': 40, 'max_ext': 12, 'max_early': 8, 'arrival': 40, 'last_granted': None, 'cycle_index': 0, 'lockout': 1}, ['extend', 1]), ({'cycle': 80, 'green_start': 40, 'green_end': 58, 'max_ext': 5, 'max_early': 18, 'arrival': 81, 'last_granted': 2, 'cycle_index': 20, 'lockout': 1}, ['early', 18]), ({'cycle': 130, 'green_start': 20, 'green_end': 52, 'max_ext': 18, 'max_early': 6, 'arrival': 274, 'last_granted': None, 'cycle_index': 16, 'lockout': 3}, ['early', 6]), ({'cycle': 100, 'green_start': 10, 'green_end': 50, 'max_ext': 10, 'max_early': 10, 'arrival': 250, 'last_granted': 3, 'cycle_index': 5, 'lockout': 2}, ['locked', 0]), ({'cycle': 80, 'green_start': 19, 'green_end': 54, 'max_ext': 12, 'max_early': 13, 'arrival': 77, 'last_granted': None, 'cycle_index': 4, 'lockout': 3}, ['early', 13]), ({'cycle': 100, 'green_start': 10, 'green_end': 45, 'max_ext': 10, 'max_early': 10, 'arrival': 110, 'last_granted': None, 'cycle_index': 4, 'lockout': 1}, ['none', 0]), ({'cycle': 100, 'green_start': 30, 'green_end': 45, 'max_ext': 20, 'max_early': 10, 'arrival': 28, 'last_granted': 1, 'cycle_index': 6, 'lockout': 2}, ['early', 2])], [({'cycle': 100, 'green_start': 10, 'green_end': 50, 'max_ext': 10, 'max_early': 10, 'arrival': 250, 'last_granted': 3, 'cycle_index': 5, 'lockout': 2}, ['locked', 0]), ({'cycle': 80, 'green_start': 32, 'green_end': 58, 'max_ext': 7, 'max_early': 7, 'arrival': 96, 'last_granted': None, 'cycle_index': 9, 'lockout': 1}, ['early', 7]), ({'cycle': 140, 'green_start': 38, 'green_end': 54, 'max_ext': 20, 'max_early': 8, 'arrival': 37, 'last_granted': 20, 'cycle_index': 8, 'lockout': 2}, ['locked', 0]), ({'cycle': 90, 'green_start': 0, 'green_end': 40, 'max_ext': 12, 'max_early': 8, 'arrival': 40, 'last_granted': None, 'cycle_index': 0, 'lockout': 1}, ['extend', 1]), ({'cycle': 100, 'green_start': 30, 'green_end': 45, 'max_ext': 20, 'max_early': 10, 'arrival': 28, 'last_granted': 1, 'cycle_index': 6, 'lockout': 2}, ['early', 2]), ({'cycle': 110, 'green_start': 21, 'green_end': 65, 'max_ext': 15, 'max_early': 10, 'arrival': 120, 'last_granted': None, 'cycle_index': 18, 'lockout': 2}, ['early', 10]), ({'cycle': 80, 'green_start': 34, 'green_end': 71, 'max_ext': 19, 'max_early': 13, 'arrival': 85, 'last_granted': 4, 'cycle_index': 16, 'lockout': 1}, ['extend', 15]), ({'cycle': 100, 'green_start': 1, 'green_end': 50, 'max_ext': 17, 'max_early': 10, 'arrival': 91, 'last_granted': None, 'cycle_index': 19, 'lockout': 1}, ['early', 10])], [({'cycle': 100, 'green_start': 30, 'green_end': 45, 'max_ext': 20, 'max_early': 10, 'arrival': 28, 'last_granted': 1, 'cycle_index': 6, 'lockout': 2}, ['early', 2]), ({'cycle': 120, 'green_start': 46, 'green_end': 90, 'max_ext': 9, 'max_early': 12, 'arrival': 279, 'last_granted': 4, 'cycle_index': 13, 'lockout': 3}, ['early', 7]), ({'cycle': 100, 'green_start': 10, 'green_end': 45, 'max_ext': 10, 'max_early': 10, 'arrival': 110, 'last_granted': None, 'cycle_index': 4, 'lockout': 1}, ['none', 0]), ({'cycle': 100, 'green_start': 50, 'green_end': 86, 'max_ext': 17, 'max_early': 11, 'arrival': 2, 'last_granted': 2, 'cycle_index': 4, 'lockout': 1}, ['extend', 17]), ({'cycle': 120, 'green_start': 35, 'green_end': 87, 'max_ext': 5, 'max_early': 8, 'arrival': 258, 'last_granted': None, 'cycle_index': 18, 'lockout': 3}, ['early', 8]), ({'cycle': 90, 'green_start': 35, 'green_end': 60, 'max_ext': 12, 'max_early': 15, 'arrival': 214, 'last_granted': 0, 'cycle_index': 5, 'lockout': 3}, ['early', 1]), ({'cycle': 90, 'green_start': 0, 'green_end': 40, 'max_ext': 12, 'max_early': 8, 'arrival': 40, 'last_granted': None, 'cycle_index': 0, 'lockout': 1}, ['extend', 1]), ({'cycle': 100, 'green_start': 10, 'green_end': 50, 'max_ext': 10, 'max_early': 10, 'arrival': 250, 'last_granted': 3, 'cycle_index': 5, 'lockout': 2}, ['locked', 0])], [({'cycle': 100, 'green_start': 10, 'green_end': 45, 'max_ext': 10, 'max_early': 10, 'arrival': 110, 'last_granted': None, 'cycle_index': 4, 'lockout': 1}, ['none', 0]), ({'cycle': 100, 'green_start': 15, 'green_end': 54, 'max_ext': 8, 'max_early': 18, 'arrival': 259, 'last_granted': None, 'cycle_index': 14, 'lockout': 3}, ['extend', 6]), ({'cycle': 90, 'green_start': 26, 'green_end': 46, 'max_ext': 15, 'max_early': 5, 'arrival': 145, 'last_granted': None, 'cycle_index': 1, 'lockout': 1}, ['extend', 10]), ({'cycle': 90, 'green_start': 31, 'green_end': 48, 'max_ext': 14, 'max_early': 16, 'arrival': 19, 'last_granted': None, 'cycle_index': 0, 'lockout': 1}, ['early', 12]), ({'cycle': 110, 'green_start': 16, 'green_end': 66, 'max_ext': 17, 'max_early': 14, 'arrival': 65, 'last_granted': 18, 'cycle_index': 15, 'lockout': 1}, ['locked', 0]), ({'cycle': 130, 'green_start': 56, 'green_end': 77, 'max_ext': 7, 'max_early': 19, 'arrival': 165, 'last_granted': None, 'cycle_index': 14, 'lockout': 3}, ['early', 19]), ({'cycle': 100, 'green_start': 30, 'green_end': 45, 'max_ext': 20, 'max_early': 10, 'arrival': 28, 'last_granted': 1, 'cycle_index': 6, 'lockout': 2}, ['early', 2]), ({'cycle': 90, 'green_start': 0, 'green_end': 40, 'max_ext': 12, 'max_early': 8, 'arrival': 40, 'last_granted': None, 'cycle_index': 0, 'lockout': 1}, ['extend', 1])]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check('timing oracle' + ' %d' % i, 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):
    C = x['cycle']
    a = x['arrival'] % C
    last = x['last_granted']
    if last is not None and x['cycle_index'] - last <= x['lockout']:
        return ['locked', 0]
    gs, ge = x['green_start'], x['green_end']
    if gs <= a < ge:
        return ['none', 0]
    d = abs(a - ge)
    if d < x['max_ext']:
        return ['extend', d + 1]
    wait = (gs - a) % C
    return ['early', min(x['max_early'], wait)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'cycle': 130, 'green_start': 31, 'green_end': 90, 'max_ext': 11, 'max_early': 18, 'arrival': 239, 'last_granted': 12, 'cycle_index': 10, 'lockout': 3}, ['locked', 0]), ({'cycle': 100, 'green_start': 10, 'green_end': 45, 'max_ext': 10, 'max_early': 10, 'arrival': 110, 'last_granted': None, 'cycle_index': 4, 'lockout': 1}, ['none', 0]), ({'cycle': 110, 'green_start': 54, 'green_end': 69, 'max_ext': 17, 'max_early': 15, 'arrival': 53, 'last_granted': None, 'cycle_index': 5, 'lockout': 2}, ['early', 1]), ({'cycle': 90, 'green_start': 42, 'green_end': 58, 'max_ext': 11, 'max_early': 12, 'arrival': 112, 'last_granted': 14, 'cycle_index': 17, 'lockout': 2}, ['early', 12]), ({'cycle': 130, 'green_start': 36, 'green_end': 55, 'max_ext': 11, 'max_early': 19, 'arrival': 284, 'last_granted': None, 'cycle_index': 5, 'lockout': 3}, ['early', 12]), ({'cycle': 130, 'green_start': 12, 'green_end': 47, 'max_ext': 16, 'max_early': 20, 'arrival': 222, 'last_granted': None, 'cycle_index': 22, 'lockout': 3}, ['early', 20]), ({'cycle': 100, 'green_start': 30, 'green_end': 45, 'max_ext': 20, 'max_early': 10, 'arrival': 28, 'last_granted': 1, 'cycle_index': 6, 'lockout': 2}, ['early', 2]), ({'cycle': 90, 'green_start': 0, 'green_end': 40, 'max_ext': 12, 'max_early': 8, 'arrival': 40, 'last_granted': None, 'cycle_index': 0, 'lockout': 1}, ['extend', 1])], [({'cycle': 120, 'green_start': 42, 'green_end': 99, 'max_ext': 17, 'max_early': 19, 'arrival': 244, 'last_granted': None, 'cycle_index': 8, 'lockout': 1}, ['early', 19]), ({'cycle': 90, 'green_start': 0, 'green_end': 40, 'max_ext': 12, 'max_early': 8, 'arrival': 40, 'last_granted': None, 'cycle_index': 0, 'lockout': 1}, ['extend', 1]), ({'cycle': 80, 'green_start': 40, 'green_end': 58, 'max_ext': 5, 'max_early': 18, 'arrival': 81, 'last_granted': 2, 'cycle_index': 20, 'lockout': 1}, ['early', 18]), ({'cycle': 130, 'green_start': 20, 'green_end': 52, 'max_ext': 18, 'max_early': 6, 'arrival': 274, 'last_granted': None, 'cycle_index': 16, 'lockout': 3}, ['early', 6]), ({'cycle': 100, 'green_start': 10, 'green_end': 50, 'max_ext': 10, 'max_early': 10, 'arrival': 250, 'last_granted': 3, 'cycle_index': 5, 'lockout': 2}, ['locked', 0]), ({'cycle': 80, 'green_start': 19, 'green_end': 54, 'max_ext': 12, 'max_early': 13, 'arrival': 77, 'last_granted': None, 'cycle_index': 4, 'lockout': 3}, ['early', 13]), ({'cycle': 100, 'green_start': 10, 'green_end': 45, 'max_ext': 10, 'max_early': 10, 'arrival': 110, 'last_granted': None, 'cycle_index': 4, 'lockout': 1}, ['none', 0]), ({'cycle': 100, 'green_start': 30, 'green_end': 45, 'max_ext': 20, 'max_early': 10, 'arrival': 28, 'last_granted': 1, 'cycle_index': 6, 'lockout': 2}, ['early', 2])], [({'cycle': 100, 'green_start': 10, 'green_end': 50, 'max_ext': 10, 'max_early': 10, 'arrival': 250, 'last_granted': 3, 'cycle_index': 5, 'lockout': 2}, ['locked', 0]), ({'cycle': 80, 'green_start': 32, 'green_end': 58, 'max_ext': 7, 'max_early': 7, 'arrival': 96, 'last_granted': None, 'cycle_index': 9, 'lockout': 1}, ['early', 7]), ({'cycle': 140, 'green_start': 38, 'green_end': 54, 'max_ext': 20, 'max_early': 8, 'arrival': 37, 'last_granted': 20, 'cycle_index': 8, 'lockout': 2}, ['locked', 0]), ({'cycle': 90, 'green_start': 0, 'green_end': 40, 'max_ext': 12, 'max_early': 8, 'arrival': 40, 'last_granted': None, 'cycle_index': 0, 'lockout': 1}, ['extend', 1]), ({'cycle': 100, 'green_start': 30, 'green_end': 45, 'max_ext': 20, 'max_early': 10, 'arrival': 28, 'last_granted': 1, 'cycle_index': 6, 'lockout': 2}, ['early', 2]), ({'cycle': 110, 'green_start': 21, 'green_end': 65, 'max_ext': 15, 'max_early': 10, 'arrival': 120, 'last_granted': None, 'cycle_index': 18, 'lockout': 2}, ['early', 10]), ({'cycle': 80, 'green_start': 34, 'green_end': 71, 'max_ext': 19, 'max_early': 13, 'arrival': 85, 'last_granted': 4, 'cycle_index': 16, 'lockout': 1}, ['extend', 15]), ({'cycle': 100, 'green_start': 1, 'green_end': 50, 'max_ext': 17, 'max_early': 10, 'arrival': 91, 'last_granted': None, 'cycle_index': 19, 'lockout': 1}, ['early', 10])], [({'cycle': 100, 'green_start': 30, 'green_end': 45, 'max_ext': 20, 'max_early': 10, 'arrival': 28, 'last_granted': 1, 'cycle_index': 6, 'lockout': 2}, ['early', 2]), ({'cycle': 120, 'green_start': 46, 'green_end': 90, 'max_ext': 9, 'max_early': 12, 'arrival': 279, 'last_granted': 4, 'cycle_index': 13, 'lockout': 3}, ['early', 7]), ({'cycle': 100, 'green_start': 10, 'green_end': 45, 'max_ext': 10, 'max_early': 10, 'arrival': 110, 'last_granted': None, 'cycle_index': 4, 'lockout': 1}, ['none', 0]), ({'cycle': 100, 'green_start': 50, 'green_end': 86, 'max_ext': 17, 'max_early': 11, 'arrival': 2, 'last_granted': 2, 'cycle_index': 4, 'lockout': 1}, ['extend', 17]), ({'cycle': 120, 'green_start': 35, 'green_end': 87, 'max_ext': 5, 'max_early': 8, 'arrival': 258, 'last_granted': None, 'cycle_index': 18, 'lockout': 3}, ['early', 8]), ({'cycle': 90, 'green_start': 35, 'green_end': 60, 'max_ext': 12, 'max_early': 15, 'arrival': 214, 'last_granted': 0, 'cycle_index': 5, 'lockout': 3}, ['early', 1]), ({'cycle': 90, 'green_start': 0, 'green_end': 40, 'max_ext': 12, 'max_early': 8, 'arrival': 40, 'last_granted': None, 'cycle_index': 0, 'lockout': 1}, ['extend', 1]), ({'cycle': 100, 'green_start': 10, 'green_end': 50, 'max_ext': 10, 'max_early': 10, 'arrival': 250, 'last_granted': 3, 'cycle_index': 5, 'lockout': 2}, ['locked', 0])], [({'cycle': 100, 'green_start': 10, 'green_end': 45, 'max_ext': 10, 'max_early': 10, 'arrival': 110, 'last_granted': None, 'cycle_index': 4, 'lockout': 1}, ['none', 0]), ({'cycle': 100, 'green_start': 15, 'green_end': 54, 'max_ext': 8, 'max_early': 18, 'arrival': 259, 'last_granted': None, 'cycle_index': 14, 'lockout': 3}, ['extend', 6]), ({'cycle': 90, 'green_start': 26, 'green_end': 46, 'max_ext': 15, 'max_early': 5, 'arrival': 145, 'last_granted': None, 'cycle_index': 1, 'lockout': 1}, ['extend', 10]), ({'cycle': 90, 'green_start': 31, 'green_end': 48, 'max_ext': 14, 'max_early': 16, 'arrival': 19, 'last_granted': None, 'cycle_index': 0, 'lockout': 1}, ['early', 12]), ({'cycle': 110, 'green_start': 16, 'green_end': 66, 'max_ext': 17, 'max_early': 14, 'arrival': 65, 'last_granted': 18, 'cycle_index': 15, 'lockout': 1}, ['locked', 0]), ({'cycle': 130, 'green_start': 56, 'green_end': 77, 'max_ext': 7, 'max_early': 19, 'arrival': 165, 'last_granted': None, 'cycle_index': 14, 'lockout': 3}, ['early', 19]), ({'cycle': 100, 'green_start': 30, 'green_end': 45, 'max_ext': 20, 'max_early': 10, 'arrival': 28, 'last_granted': 1, 'cycle_index': 6, 'lockout': 2}, ['early', 2]), ({'cycle': 90, 'green_start': 0, 'green_end': 40, 'max_ext': 12, 'max_early': 8, 'arrival': 40, 'last_granted': None, 'cycle_index': 0, 'lockout': 1}, ['extend', 1])]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check('timing oracle' + ' %d' % i, 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:
Transit signal priority decision returns a wrong result when the extension distance is not wrapped around the cycle.

Input {cycle, green_start, green_end (exclusive), max_ext, max_early, arrival (seconds, reduced modulo cycle), last_granted (cycle index or null), cycle_index, lockout}. A request within lockout cycles of the last grant (difference <= lockout) returns ['locked', 0]. Arrival in green needs nothing. If the arrival is less than max_ext seconds after green end (cyclically) green is extended through the arrival second: ['extend', d+1]. Otherwise green starts early by min(max_early, seconds until next green start).

split: open-access


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

N = 1
observations = []
def solve(x):
    C = x['cycle']
    a = x['arrival'] % C
    last = x['last_granted']
    if last is not None and x['cycle_index'] - last <= x['lockout']:
        return ['locked', 0]
    gs, ge = x['green_start'], x['green_end']
    if gs <= a < ge:
        return ['none', 0]
    d = (a - ge) % C
    if d < x['max_ext']:
        return ['extend', d]
    wait = (gs - a) % C
    return ['early', min(x['max_early'], wait)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'cycle': 90, 'green_start': 0, 'green_end': 40, 'max_ext': 12, 'max_early': 8, 'arrival': 40, 'last_granted': None, 'cycle_index': 0, 'lockout': 1}, ['extend', 1]), ({'cycle': 100, 'green_start': 10, 'green_end': 45, 'max_ext': 10, 'max_early': 10, 'arrival': 110, 'last_granted': None, 'cycle_index': 4, 'lockout': 1}, ['none', 0]), ({'cycle': 100, 'green_start': 10, 'green_end': 50, 'max_ext': 10, 'max_early': 10, 'arrival': 250, 'last_granted': 3, 'cycle_index': 5, 'lockout': 2}, ['locked', 0]), ({'cycle': 80, 'green_start': 38, 'green_end': 70, 'max_ext': 13, 'max_early': 9, 'arrival': 230, 'last_granted': None, 'cycle_index': 17, 'lockout': 1}, ['extend', 1]), ({'cycle': 120, 'green_start': 14, 'green_end': 36, 'max_ext': 11, 'max_early': 6, 'arrival': 251, 'last_granted': None, 'cycle_index': 11, 'lockout': 2}, ['early', 3]), ({'cycle': 100, 'green_start': 27, 'green_end': 52, 'max_ext': 15, 'max_early': 15, 'arrival': 108, 'last_granted': None, 'cycle_index': 0, 'lockout': 2}, ['early', 15]), ({'cycle': 80, 'green_start': 16, 'green_end': 35, 'max_ext': 15, 'max_early': 7, 'arrival': 162, 'last_granted': 15, 'cycle_index': 9, 'lockout': 1}, ['locked', 0]), ({'cycle': 90, 'green_start': 13, 'green_end': 43, 'max_ext': 20, 'max_early': 7, 'arrival': 237, 'last_granted': 0, 'cycle_index': 22, 'lockout': 3}, ['extend', 15])], [({'cycle': 80, 'green_start': 1, 'green_end': 31, 'max_ext': 6, 'max_early': 17, 'arrival': 14, 'last_granted': 10, 'cycle_index': 0, 'lockout': 1}, ['locked', 0]), ({'cycle': 100, 'green_start': 30, 'green_end': 45, 'max_ext': 20, 'max_early': 10, 'arrival': 28, 'last_granted': 1, 'cycle_index': 6, 'lockout': 2}, ['early', 2]), ({'cycle': 120, 'green_start': 17, 'green_end': 63, 'max_ext': 7, 'max_early': 19, 'arrival': 149, 'last_granted': 18, 'cycle_index': 16, 'lockout': 1}, ['locked', 0]), ({'cycle': 140, 'green_start': 24, 'green_end': 42, 'max_ext': 18, 'max_early': 17, 'arrival': 334, 'last_granted': 8, 'cycle_index': 19, 'lockout': 2}, ['extend', 13]), ({'cycle': 90, 'green_start': 34, 'green_end': 71, 'max_ext': 14, 'max_early': 17, 'arrival': 26, 'last_granted': 19, 'cycle_index': 4, 'lockout': 1}, ['locked', 0]), ({'cycle': 130, 'green_start': 50, 'green_end': 83, 'max_ext': 16, 'max_early': 7, 'arrival': 85, 'last_granted': None, 'cycle_index': 18, 'lockout': 2}, ['extend', 3]), ({'cycle': 90, 'green_start': 0, 'green_end': 40, 'max_ext': 12, 'max_early': 8, 'arrival': 40, 'last_granted': None, 'cycle_index': 0, 'lockout': 1}, ['extend', 1]), ({'cycle': 100, 'green_start': 10, 'green_end': 45, 'max_ext': 10, 'max_early': 10, 'arrival': 110, 'last_granted': None, 'cycle_index': 4, 'lockout': 1}, ['none', 0])], [({'cycle': 140, 'green_start': 21, 'green_end': 71, 'max_ext': 11, 'max_early': 13, 'arrival': 64, 'last_granted': 16, 'cycle_index': 19, 'lockout': 2}, ['none', 0]), ({'cycle': 90, 'green_start': 20, 'green_end': 47, 'max_ext': 18, 'max_early': 18, 'arrival': 149, 'last_granted': 4, 'cycle_index': 12, 'lockout': 1}, ['extend', 13]), ({'cycle': 140, 'green_start': 43, 'green_end': 68, 'max_ext': 13, 'max_early': 9, 'arrival': 80, 'last_granted': None, 'cycle_index': 16, 'lockout': 2}, ['extend', 13]), ({'cycle': 110, 'green_start': 41, 'green_end': 72, 'max_ext': 6, 'max_early': 7, 'arrival': 90, 'last_granted': 19, 'cycle_index': 11, 'lockout': 2}, ['locked', 0]), ({'cycle': 90, 'green_start': 17, 'green_end': 57, 'max_ext': 19, 'max_early': 17, 'arrival': 51, 'last_granted': None, 'cycle_index': 8, 'lockout': 1}, ['none', 0]), ({'cycle': 90, 'green_start': 0, 'green_end': 40, 'max_ext': 12, 'max_early': 8, 'arrival': 40, 'last_granted': None, 'cycle_index': 0, 'lockout': 1}, ['extend', 1]), ({'cycle': 100, 'green_start': 10, 'green_end': 50, 'max_ext': 10, 'max_early': 10, 'arrival': 250, 'last_granted': 3, 'cycle_index': 5, 'lockout': 2}, ['locked', 0]), ({'cycle': 100, 'green_start': 10, 'green_end': 45, 'max_ext': 10, 'max_early': 10, 'arrival': 110, 'last_granted': None, 'cycle_index': 4, 'lockout': 1}, ['none', 0])], [({'cycle': 90, 'green_start': 0, 'green_end': 40, 'max_ext': 12, 'max_early': 8, 'arrival': 40, 'last_granted': None, 'cycle_index': 0, 'lockout': 1}, ['extend', 1]), ({'cycle': 110, 'green_start': 51, 'green_end': 87, 'max_ext': 19, 'max_early': 17, 'arrival': 99, 'last_granted': None, 'cycle_index': 18, 'lockout': 3}, ['extend', 13]), ({'cycle': 100, 'green_start': 11, 'green_end': 43, 'max_ext': 14, 'max_early': 11, 'arrival': 226, 'last_granted': None, 'cycle_index': 4, 'lockout': 3}, ['none', 0]), ({'cycle': 100, 'green_start': 30, 'green_end': 45, 'max_ext': 20, 'max_early': 10, 'arrival': 28, 'last_granted': 1, 'cycle_index': 6, 'lockout': 2}, ['early', 2]), ({'cycle': 80, 'green_start': 28, 'green_end': 66, 'max_ext': 10, 'max_early': 8, 'arrival': 195, 'last_granted': 17, 'cycle_index': 2, 'lockout': 2}, ['locked', 0]), ({'cycle': 130, 'green_start': 23, 'green_end': 63, 'max_ext': 18, 'max_early': 10, 'arrival': 202, 'last_granted': 11, 'cycle_index': 20, 'lockout': 1}, ['extend', 10]), ({'cycle': 100, 'green_start': 10, 'green_end': 50, 'max_ext': 10, 'max_early': 10, 'arrival': 250, 'last_granted': 3, 'cycle_index': 5, 'lockout': 2}, ['locked', 0]), ({'cycle': 110, 'green_start': 45, 'green_end': 69, 'max_ext': 14, 'max_early': 15, 'arrival': 27, 'last_granted': None, 'cycle_index': 7, 'lockout': 2}, ['early', 15])], [({'cycle': 100, 'green_start': 10, 'green_end': 45, 'max_ext': 10, 'max_early': 10, 'arrival': 110, 'last_granted': None, 'cycle_index': 4, 'lockout': 1}, ['none', 0]), ({'cycle': 100, 'green_start': 35, 'green_end': 69, 'max_ext': 17, 'max_early': 19, 'arrival': 249, 'last_granted': 16, 'cycle_index': 11, 'lockout': 2}, ['locked', 0]), ({'cycle': 100, 'green_start': 30, 'green_end': 45, 'max_ext': 20, 'max_early': 10, 'arrival': 28, 'last_granted': 1, 'cycle_index': 6, 'lockout': 2}, ['early', 2]), ({'cycle': 110, 'green_start': 39, 'green_end': 82, 'max_ext': 9, 'max_early': 5, 'arrival': 160, 'last_granted': 7, 'cycle_index': 18, 'lockout': 2}, ['none', 0]), ({'cycle': 110, 'green_start': 9, 'green_end': 34, 'max_ext': 20, 'max_early': 9, 'arrival': 45, 'last_granted': None, 'cycle_index': 16, 'lockout': 3}, ['extend', 12]), ({'cycle': 80, 'green_start': 35, 'green_end': 57, 'max_ext': 16, 'max_early': 11, 'arrival': 219, 'last_granted': 4, 'cycle_index': 8, 'lockout': 1}, ['extend', 3]), ({'cycle': 100, 'green_start': 7, 'green_end': 48, 'max_ext': 16, 'max_early': 14, 'arrival': 101, 'last_granted': 2, 'cycle_index': 5, 'lockout': 3}, ['locked', 0]), ({'cycle': 90, 'green_start': 0, 'green_end': 40, 'max_ext': 12, 'max_early': 8, 'arrival': 40, 'last_granted': None, 'cycle_index': 0, 'lockout': 1}, ['extend', 1])]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check('timing oracle' + ' %d' % i, 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):
    C = x['cycle']
    a = x['arrival'] % C
    last = x['last_granted']
    if last is not None and x['cycle_index'] - last <= x['lockout']:
        return ['locked', 0]
    gs, ge = x['green_start'], x['green_end']
    if gs <= a < ge:
        return ['none', 0]
    d = (a - ge) % C
    if d < x['max_ext']:
        return ['extend', x['max_ext']]
    wait = (gs - a) % C
    return ['early', min(x['max_early'], wait)]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'cycle': 90, 'green_start': 0, 'green_end': 40, 'max_ext': 12, 'max_early': 8, 'arrival': 40, 'last_granted': None, 'cycle_index': 0, 'lockout': 1}, ['extend', 1]), ({'cycle': 100, 'green_start': 10, 'green_end': 45, 'max_ext': 10, 'max_early': 10, 'arrival': 110, 'last_granted': None, 'cycle_index': 4, 'lockout': 1}, ['none', 0]), ({'cycle': 100, 'green_start': 10, 'green_end': 50, 'max_ext': 10, 'max_early': 10, 'arrival': 250, 'last_granted': 3, 'cycle_index': 5, 'lockout': 2}, ['locked', 0]), ({'cycle': 80, 'green_start': 38, 'green_end': 70, 'max_ext': 13, 'max_early': 9, 'arrival': 230, 'last_granted': None, 'cycle_index': 17, 'lockout': 1}, ['extend', 1]), ({'cycle': 120, 'green_start': 14, 'green_end': 36, 'max_ext': 11, 'max_early': 6, 'arrival': 251, 'last_granted': None, 'cycle_index': 11, 'lockout': 2}, ['early', 3]), ({'cycle': 100, 'green_start': 27, 'green_end': 52, 'max_ext': 15, 'max_early': 15, 'arrival': 108, 'last_granted': None, 'cycle_index': 0, 'lockout': 2}, ['early', 15]), ({'cycle': 80, 'green_start': 16, 'green_end': 35, 'max_ext': 15, 'max_early': 7, 'arrival': 162, 'last_granted': 15, 'cycle_index': 9, 'lockout': 1}, ['locked', 0]), ({'cycle': 90, 'green_start': 13, 'green_end': 43, 'max_ext': 20, 'max_early': 7, 'arrival': 237, 'last_granted': 0, 'cycle_index': 22, 'lockout': 3}, ['extend', 15])], [({'cycle': 80, 'green_start': 1, 'green_end': 31, 'max_ext': 6, 'max_early': 17, 'arrival': 14, 'last_granted': 10, 'cycle_index': 0, 'lockout': 1}, ['locked', 0]), ({'cycle': 100, 'green_start': 30, 'green_end': 45, 'max_ext': 20, 'max_early': 10, 'arrival': 28, 'last_granted': 1, 'cycle_index': 6, 'lockout': 2}, ['early', 2]), ({'cycle': 120, 'green_start': 17, 'green_end': 63, 'max_ext': 7, 'max_early': 19, 'arrival': 149, 'last_granted': 18, 'cycle_index': 16, 'lockout': 1}, ['locked', 0]), ({'cycle': 140, 'green_start': 24, 'green_end': 42, 'max_ext': 18, 'max_early': 17, 'arrival': 334, 'last_granted': 8, 'cycle_index': 19, 'lockout': 2}, ['extend', 13]), ({'cycle': 90, 'green_start': 34, 'green_end': 71, 'max_ext': 14, 'max_early': 17, 'arrival': 26, 'last_granted': 19, 'cycle_index': 4, 'lockout': 1}, ['locked', 0]), ({'cycle': 130, 'green_start': 50, 'green_end': 83, 'max_ext': 16, 'max_early': 7, 'arrival': 85, 'last_granted': None, 'cycle_index': 18, 'lockout': 2}, ['extend', 3]), ({'cycle': 90, 'green_start': 0, 'green_end': 40, 'max_ext': 12, 'max_early': 8, 'arrival': 40, 'last_granted': None, 'cycle_index': 0, 'lockout': 1}, ['extend', 1]), ({'cycle': 100, 'green_start': 10, 'green_end': 45, 'max_ext': 10, 'max_early': 10, 'arrival': 110, 'last_granted': None, 'cycle_index': 4, 'lockout': 1}, ['none', 0])], [({'cycle': 140, 'green_start': 21, 'green_end': 71, 'max_ext': 11, 'max_early': 13, 'arrival': 64, 'last_granted': 16, 'cycle_index': 19, 'lockout': 2}, ['none', 0]), ({'cycle': 90, 'green_start': 20, 'green_end': 47, 'max_ext': 18, 'max_early': 18, 'arrival': 149, 'last_granted': 4, 'cycle_index': 12, 'lockout': 1}, ['extend', 13]), ({'cycle': 140, 'green_start': 43, 'green_end': 68, 'max_ext': 13, 'max_early': 9, 'arrival': 80, 'last_granted': None, 'cycle_index': 16, 'lockout': 2}, ['extend', 13]), ({'cycle': 110, 'green_start': 41, 'green_end': 72, 'max_ext': 6, 'max_early': 7, 'arrival': 90, 'last_granted': 19, 'cycle_index': 11, 'lockout': 2}, ['locked', 0]), ({'cycle': 90, 'green_start': 17, 'green_end': 57, 'max_ext': 19, 'max_early': 17, 'arrival': 51, 'last_granted': None, 'cycle_index': 8, 'lockout': 1}, ['none', 0]), ({'cycle': 90, 'green_start': 0, 'green_end': 40, 'max_ext': 12, 'max_early': 8, 'arrival': 40, 'last_granted': None, 'cycle_index': 0, 'lockout': 1}, ['extend', 1]), ({'cycle': 100, 'green_start': 10, 'green_end': 50, 'max_ext': 10, 'max_early': 10, 'arrival': 250, 'last_granted': 3, 'cycle_index': 5, 'lockout': 2}, ['locked', 0]), ({'cycle': 100, 'green_start': 10, 'green_end': 45, 'max_ext': 10, 'max_early': 10, 'arrival': 110, 'last_granted': None, 'cycle_index': 4, 'lockout': 1}, ['none', 0])], [({'cycle': 90, 'green_start': 0, 'green_end': 40, 'max_ext': 12, 'max_early': 8, 'arrival': 40, 'last_granted': None, 'cycle_index': 0, 'lockout': 1}, ['extend', 1]), ({'cycle': 110, 'green_start': 51, 'green_end': 87, 'max_ext': 19, 'max_early': 17, 'arrival': 99, 'last_granted': None, 'cycle_index': 18, 'lockout': 3}, ['extend', 13]), ({'cycle': 100, 'green_start': 11, 'green_end': 43, 'max_ext': 14, 'max_early': 11, 'arrival': 226, 'last_granted': None, 'cycle_index': 4, 'lockout': 3}, ['none', 0]), ({'cycle': 100, 'green_start': 30, 'green_end': 45, 'max_ext': 20, 'max_early': 10, 'arrival': 28, 'last_granted': 1, 'cycle_index': 6, 'lockout': 2}, ['early', 2]), ({'cycle': 80, 'green_start': 28, 'green_end': 66, 'max_ext': 10, 'max_early': 8, 'arrival': 195, 'last_granted': 17, 'cycle_index': 2, 'lockout': 2}, ['locked', 0]), ({'cycle': 130, 'green_start': 23, 'green_end': 63, 'max_ext': 18, 'max_early': 10, 'arrival': 202, 'last_granted': 11, 'cycle_index': 20, 'lockout': 1}, ['extend', 10]), ({'cycle': 100, 'green_start': 10, 'green_end': 50, 'max_ext': 10, 'max_early': 10, 'arrival': 250, 'last_granted': 3, 'cycle_index': 5, 'lockout': 2}, ['locked', 0]), ({'cycle': 110, 'green_start': 45, 'green_end': 69, 'max_ext': 14, 'max_early': 15, 'arrival': 27, 'last_granted': None, 'cycle_index': 7, 'lockout': 2}, ['early', 15])], [({'cycle': 100, 'green_start': 10, 'green_end': 45, 'max_ext': 10, 'max_early': 10, 'arrival': 110, 'last_granted': None, 'cycle_index': 4, 'lockout': 1}, ['none', 0]), ({'cycle': 100, 'green_start': 35, 'green_end': 69, 'max_ext': 17, 'max_early': 19, 'arrival': 249, 'last_granted': 16, 'cycle_index': 11, 'lockout': 2}, ['locked', 0]), ({'cycle': 100, 'green_start': 30, 'green_end': 45, 'max_ext': 20, 'max_early': 10, 'arrival': 28, 'last_granted': 1, 'cycle_index': 6, 'lockout': 2}, ['early', 2]), ({'cycle': 110, 'green_start': 39, 'green_end': 82, 'max_ext': 9, 'max_early': 5, 'arrival': 160, 'last_granted': 7, 'cycle_index': 18, 'lockout': 2}, ['none', 0]), ({'cycle': 110, 'green_start': 9, 'green_end': 34, 'max_ext': 20, 'max_early': 9, 'arrival': 45, 'last_granted': None, 'cycle_index': 16, 'lockout': 3}, ['extend', 12]), ({'cycle': 80, 'green_start': 35, 'green_end': 57, 'max_ext': 16, 'max_early': 11, 'arrival': 219, 'last_granted': 4, 'cycle_index': 8, 'lockout': 1}, ['extend', 3]), ({'cycle': 100, 'green_start': 7, 'green_end': 48, 'max_ext': 16, 'max_early': 14, 'arrival': 101, 'last_granted': 2, 'cycle_index': 5, 'lockout': 3}, ['locked', 0]), ({'cycle': 90, 'green_start': 0, 'green_end': 40, 'max_ext': 12, 'max_early': 8, 'arrival': 40, 'last_granted': None, 'cycle_index': 0, 'lockout': 1}, ['extend', 1])]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check('timing oracle' + ' %d' % i, 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:
Transit signal priority decision returns a wrong result when green is extended only up to the arrival second.

Input {cycle, green_start, green_end (exclusive), max_ext, max_early, arrival (seconds, reduced modulo cycle), last_granted (cycle index or null), cycle_index, lockout}. A request within lockout cycles of the last grant (difference <= lockout) returns ['locked', 0]. Arrival in green needs nothing. If the arrival is less than max_ext seconds after green end (cyclically) green is extended through the arrival second: ['extend', d+1]. Otherwise green starts early by min(max_early, seconds until next green start).

split: open-access