broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(x):
    vt = x['target_kmh'] / 3.6
    d = max(x['distance_m'] - x['safety_margin_m'], 0)
    a = x['decel_cms2'] / 100
    vp = math.sqrt(vt * vt + 2 * a * d) * 3.6
    permitted = int(vp)
    v = x['speed_kmh']
    if v > permitted + x['brake_margin_kmh']:
        action = 'brake'
    elif v > permitted + x['warn_margin_kmh']:
        action = 'warning'
    else:
        action = 'none'
    return {'permitted': permitted, 'action': action}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: curve above line speed', {'target_kmh': 0, 'distance_m': 2500, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 120, 'speed_kmh': 150, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 120, 'action': 'brake'}), ('sampled regression 9', {'target_kmh': 0, 'distance_m': 2500, 'safety_margin_m': 50, 'decel_cms2': 100, 'line_kmh': 160, 'speed_kmh': 45, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 160, 'action': 'none'}), ('sampled regression 5', {'target_kmh': 60, 'distance_m': 2500, 'safety_margin_m': 0, 'decel_cms2': 50, 'line_kmh': 160, 'speed_kmh': 124, 'warn_margin_kmh': 3, 'brake_margin_kmh': 8}, {'permitted': 160, 'action': 'none'}), ('boundary: stop target inside the margin', {'target_kmh': 0, 'distance_m': 40, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 10, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 0, 'action': 'warning'}), ('boundary: target speed release', {'target_kmh': 40, 'distance_m': 0, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 44, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 40, 'action': 'none'}), ('control 1', {'target_kmh': 0, 'distance_m': 0, 'safety_margin_m': 0, 'decel_cms2': 100, 'line_kmh': 160, 'speed_kmh': 139, 'warn_margin_kmh': 5, 'brake_margin_kmh': 15}, {'permitted': 0, 'action': 'brake'}), ('control 4', {'target_kmh': 0, 'distance_m': 100, 'safety_margin_m': 20, 'decel_cms2': 100, 'line_kmh': 80, 'speed_kmh': 136, 'warn_margin_kmh': 5, 'brake_margin_kmh': 15}, {'permitted': 45, 'action': 'brake'}), ('sampled regression 7', {'target_kmh': 40, 'distance_m': 2500, 'safety_margin_m': 20, 'decel_cms2': 50, 'line_kmh': 160, 'speed_kmh': 59, 'warn_margin_kmh': 3, 'brake_margin_kmh': 10}, {'permitted': 160, 'action': 'none'})], [('regression: curve above line speed', {'target_kmh': 0, 'distance_m': 2500, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 120, 'speed_kmh': 150, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 120, 'action': 'brake'}), ('sampled regression 32', {'target_kmh': 40, 'distance_m': 2500, 'safety_margin_m': 50, 'decel_cms2': 100, 'line_kmh': 120, 'speed_kmh': 134, 'warn_margin_kmh': 3, 'brake_margin_kmh': 15}, {'permitted': 120, 'action': 'warning'}), ('sampled regression 20', {'target_kmh': 0, 'distance_m': 2500, 'safety_margin_m': 20, 'decel_cms2': 100, 'line_kmh': 160, 'speed_kmh': 69, 'warn_margin_kmh': 3, 'brake_margin_kmh': 15}, {'permitted': 160, 'action': 'none'}), ('boundary: curve below line speed', {'target_kmh': 0, 'distance_m': 600, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 100, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 99, 'action': 'none'}), ('boundary: warning boundary', {'target_kmh': 40, 'distance_m': 0, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 45, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 40, 'action': 'none'}), ('control 12', {'target_kmh': 40, 'distance_m': 600, 'safety_margin_m': 20, 'decel_cms2': 100, 'line_kmh': 160, 'speed_kmh': 133, 'warn_margin_kmh': 3, 'brake_margin_kmh': 15}, {'permitted': 128, 'action': 'warning'}), ('control 15', {'target_kmh': 0, 'distance_m': 600, 'safety_margin_m': 20, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 43, 'warn_margin_kmh': 3, 'brake_margin_kmh': 10}, {'permitted': 102, 'action': 'none'}), ('sampled regression 18', {'target_kmh': 60, 'distance_m': 1200, 'safety_margin_m': 20, 'decel_cms2': 70, 'line_kmh': 120, 'speed_kmh': 6, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 120, 'action': 'none'})], [('regression: curve above line speed', {'target_kmh': 0, 'distance_m': 2500, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 120, 'speed_kmh': 150, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 120, 'action': 'brake'}), ('sampled regression 57', {'target_kmh': 40, 'distance_m': 2500, 'safety_margin_m': 50, 'decel_cms2': 100, 'line_kmh': 120, 'speed_kmh': 70, 'warn_margin_kmh': 3, 'brake_margin_kmh': 15}, {'permitted': 120, 'action': 'none'}), ('sampled regression 35', {'target_kmh': 0, 'distance_m': 2500, 'safety_margin_m': 0, 'decel_cms2': 100, 'line_kmh': 120, 'speed_kmh': 12, 'warn_margin_kmh': 3, 'brake_margin_kmh': 10}, {'permitted': 120, 'action': 'none'}), ('boundary: warning boundary', {'target_kmh': 40, 'distance_m': 0, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 45, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 40, 'action': 'none'}), ('boundary: brake boundary', {'target_kmh': 40, 'distance_m': 0, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 50, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 40, 'action': 'warning'}), ('control 23', {'target_kmh': 60, 'distance_m': 100, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 80, 'speed_kmh': 13, 'warn_margin_kmh': 5, 'brake_margin_kmh': 8}, {'permitted': 67, 'action': 'none'}), ('sampled regression 26', {'target_kmh': 60, 'distance_m': 2500, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 86, 'warn_margin_kmh': 3, 'brake_margin_kmh': 10}, {'permitted': 160, 'action': 'none'}), ('control 29', {'target_kmh': 0, 'distance_m': 250, 'safety_margin_m': 0, 'decel_cms2': 70, 'line_kmh': 120, 'speed_kmh': 4, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 67, 'action': 'none'})], [('regression: curve above line speed', {'target_kmh': 0, 'distance_m': 2500, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 120, 'speed_kmh': 150, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 120, 'action': 'brake'}), ('sampled regression 76', {'target_kmh': 40, 'distance_m': 1200, 'safety_margin_m': 0, 'decel_cms2': 70, 'line_kmh': 80, 'speed_kmh': 33, 'warn_margin_kmh': 3, 'brake_margin_kmh': 10}, {'permitted': 80, 'action': 'none'}), ('sampled regression 52', {'target_kmh': 40, 'distance_m': 250, 'safety_margin_m': 20, 'decel_cms2': 100, 'line_kmh': 80, 'speed_kmh': 50, 'warn_margin_kmh': 3, 'brake_margin_kmh': 10}, {'permitted': 80, 'action': 'none'}), ('boundary: between warning and brake', {'target_kmh': 40, 'distance_m': 0, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 48, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 40, 'action': 'warning'}), ('boundary: fractional permitted speed', {'target_kmh': 20, 'distance_m': 100, 'safety_margin_m': 0, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 60, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 47, 'action': 'brake'}), ('control 34', {'target_kmh': 0, 'distance_m': 0, 'safety_margin_m': 0, 'decel_cms2': 70, 'line_kmh': 120, 'speed_kmh': 96, 'warn_margin_kmh': 5, 'brake_margin_kmh': 15}, {'permitted': 0, 'action': 'brake'}), ('sampled regression 37', {'target_kmh': 20, 'distance_m': 2500, 'safety_margin_m': 20, 'decel_cms2': 70, 'line_kmh': 80, 'speed_kmh': 168, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 80, 'action': 'brake'}), ('control 40', {'target_kmh': 0, 'distance_m': 600, 'safety_margin_m': 50, 'decel_cms2': 50, 'line_kmh': 160, 'speed_kmh': 70, 'warn_margin_kmh': 5, 'brake_margin_kmh': 15}, {'permitted': 84, 'action': 'none'})], [('regression: curve above line speed', {'target_kmh': 0, 'distance_m': 2500, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 120, 'speed_kmh': 150, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 120, 'action': 'brake'}), ('sampled regression 18', {'target_kmh': 60, 'distance_m': 1200, 'safety_margin_m': 20, 'decel_cms2': 70, 'line_kmh': 120, 'speed_kmh': 6, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 120, 'action': 'none'}), ('sampled regression 64', {'target_kmh': 20, 'distance_m': 600, 'safety_margin_m': 20, 'decel_cms2': 70, 'line_kmh': 80, 'speed_kmh': 44, 'warn_margin_kmh': 3, 'brake_margin_kmh': 8}, {'permitted': 80, 'action': 'none'}), ('boundary: stop target inside the margin', {'target_kmh': 0, 'distance_m': 40, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 10, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 0, 'action': 'warning'}), ('boundary: target speed release', {'target_kmh': 40, 'distance_m': 0, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 44, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 40, 'action': 'none'}), ('control 45', {'target_kmh': 20, 'distance_m': 40, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 80, 'speed_kmh': 133, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 20, 'action': 'brake'}), ('control 48', {'target_kmh': 40, 'distance_m': 100, 'safety_margin_m': 20, 'decel_cms2': 100, 'line_kmh': 160, 'speed_kmh': 75, 'warn_margin_kmh': 3, 'brake_margin_kmh': 15}, {'permitted': 60, 'action': 'warning'}), ('control 51', {'target_kmh': 60, 'distance_m': 600, 'safety_margin_m': 0, 'decel_cms2': 50, 'line_kmh': 160, 'speed_kmh': 8, 'warn_margin_kmh': 5, 'brake_margin_kmh': 8}, {'permitted': 106, 'action': 'none'})]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(x):
    vt = x['target_kmh'] / 3.6
    d = max(x['distance_m'] - x['safety_margin_m'], 0)
    a = x['decel_cms2'] / 100
    vp = math.sqrt(vt * vt + 2 * a * d) * 3.6
    permitted = min(int(vp), x['line_kmh'] + x['warn_margin_kmh'])
    v = x['speed_kmh']
    if v > permitted + x['brake_margin_kmh']:
        action = 'brake'
    elif v > permitted + x['warn_margin_kmh']:
        action = 'warning'
    else:
        action = 'none'
    return {'permitted': permitted, 'action': action}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: curve above line speed', {'target_kmh': 0, 'distance_m': 2500, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 120, 'speed_kmh': 150, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 120, 'action': 'brake'}), ('sampled regression 9', {'target_kmh': 0, 'distance_m': 2500, 'safety_margin_m': 50, 'decel_cms2': 100, 'line_kmh': 160, 'speed_kmh': 45, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 160, 'action': 'none'}), ('sampled regression 5', {'target_kmh': 60, 'distance_m': 2500, 'safety_margin_m': 0, 'decel_cms2': 50, 'line_kmh': 160, 'speed_kmh': 124, 'warn_margin_kmh': 3, 'brake_margin_kmh': 8}, {'permitted': 160, 'action': 'none'}), ('boundary: stop target inside the margin', {'target_kmh': 0, 'distance_m': 40, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 10, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 0, 'action': 'warning'}), ('boundary: target speed release', {'target_kmh': 40, 'distance_m': 0, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 44, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 40, 'action': 'none'}), ('control 1', {'target_kmh': 0, 'distance_m': 0, 'safety_margin_m': 0, 'decel_cms2': 100, 'line_kmh': 160, 'speed_kmh': 139, 'warn_margin_kmh': 5, 'brake_margin_kmh': 15}, {'permitted': 0, 'action': 'brake'}), ('control 4', {'target_kmh': 0, 'distance_m': 100, 'safety_margin_m': 20, 'decel_cms2': 100, 'line_kmh': 80, 'speed_kmh': 136, 'warn_margin_kmh': 5, 'brake_margin_kmh': 15}, {'permitted': 45, 'action': 'brake'}), ('sampled regression 7', {'target_kmh': 40, 'distance_m': 2500, 'safety_margin_m': 20, 'decel_cms2': 50, 'line_kmh': 160, 'speed_kmh': 59, 'warn_margin_kmh': 3, 'brake_margin_kmh': 10}, {'permitted': 160, 'action': 'none'})], [('regression: curve above line speed', {'target_kmh': 0, 'distance_m': 2500, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 120, 'speed_kmh': 150, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 120, 'action': 'brake'}), ('sampled regression 32', {'target_kmh': 40, 'distance_m': 2500, 'safety_margin_m': 50, 'decel_cms2': 100, 'line_kmh': 120, 'speed_kmh': 134, 'warn_margin_kmh': 3, 'brake_margin_kmh': 15}, {'permitted': 120, 'action': 'warning'}), ('sampled regression 20', {'target_kmh': 0, 'distance_m': 2500, 'safety_margin_m': 20, 'decel_cms2': 100, 'line_kmh': 160, 'speed_kmh': 69, 'warn_margin_kmh': 3, 'brake_margin_kmh': 15}, {'permitted': 160, 'action': 'none'}), ('boundary: curve below line speed', {'target_kmh': 0, 'distance_m': 600, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 100, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 99, 'action': 'none'}), ('boundary: warning boundary', {'target_kmh': 40, 'distance_m': 0, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 45, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 40, 'action': 'none'}), ('control 12', {'target_kmh': 40, 'distance_m': 600, 'safety_margin_m': 20, 'decel_cms2': 100, 'line_kmh': 160, 'speed_kmh': 133, 'warn_margin_kmh': 3, 'brake_margin_kmh': 15}, {'permitted': 128, 'action': 'warning'}), ('control 15', {'target_kmh': 0, 'distance_m': 600, 'safety_margin_m': 20, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 43, 'warn_margin_kmh': 3, 'brake_margin_kmh': 10}, {'permitted': 102, 'action': 'none'}), ('sampled regression 18', {'target_kmh': 60, 'distance_m': 1200, 'safety_margin_m': 20, 'decel_cms2': 70, 'line_kmh': 120, 'speed_kmh': 6, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 120, 'action': 'none'})], [('regression: curve above line speed', {'target_kmh': 0, 'distance_m': 2500, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 120, 'speed_kmh': 150, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 120, 'action': 'brake'}), ('sampled regression 57', {'target_kmh': 40, 'distance_m': 2500, 'safety_margin_m': 50, 'decel_cms2': 100, 'line_kmh': 120, 'speed_kmh': 70, 'warn_margin_kmh': 3, 'brake_margin_kmh': 15}, {'permitted': 120, 'action': 'none'}), ('sampled regression 35', {'target_kmh': 0, 'distance_m': 2500, 'safety_margin_m': 0, 'decel_cms2': 100, 'line_kmh': 120, 'speed_kmh': 12, 'warn_margin_kmh': 3, 'brake_margin_kmh': 10}, {'permitted': 120, 'action': 'none'}), ('boundary: warning boundary', {'target_kmh': 40, 'distance_m': 0, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 45, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 40, 'action': 'none'}), ('boundary: brake boundary', {'target_kmh': 40, 'distance_m': 0, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 50, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 40, 'action': 'warning'}), ('control 23', {'target_kmh': 60, 'distance_m': 100, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 80, 'speed_kmh': 13, 'warn_margin_kmh': 5, 'brake_margin_kmh': 8}, {'permitted': 67, 'action': 'none'}), ('sampled regression 26', {'target_kmh': 60, 'distance_m': 2500, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 86, 'warn_margin_kmh': 3, 'brake_margin_kmh': 10}, {'permitted': 160, 'action': 'none'}), ('control 29', {'target_kmh': 0, 'distance_m': 250, 'safety_margin_m': 0, 'decel_cms2': 70, 'line_kmh': 120, 'speed_kmh': 4, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 67, 'action': 'none'})], [('regression: curve above line speed', {'target_kmh': 0, 'distance_m': 2500, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 120, 'speed_kmh': 150, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 120, 'action': 'brake'}), ('sampled regression 76', {'target_kmh': 40, 'distance_m': 1200, 'safety_margin_m': 0, 'decel_cms2': 70, 'line_kmh': 80, 'speed_kmh': 33, 'warn_margin_kmh': 3, 'brake_margin_kmh': 10}, {'permitted': 80, 'action': 'none'}), ('sampled regression 52', {'target_kmh': 40, 'distance_m': 250, 'safety_margin_m': 20, 'decel_cms2': 100, 'line_kmh': 80, 'speed_kmh': 50, 'warn_margin_kmh': 3, 'brake_margin_kmh': 10}, {'permitted': 80, 'action': 'none'}), ('boundary: between warning and brake', {'target_kmh': 40, 'distance_m': 0, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 48, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 40, 'action': 'warning'}), ('boundary: fractional permitted speed', {'target_kmh': 20, 'distance_m': 100, 'safety_margin_m': 0, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 60, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 47, 'action': 'brake'}), ('control 34', {'target_kmh': 0, 'distance_m': 0, 'safety_margin_m': 0, 'decel_cms2': 70, 'line_kmh': 120, 'speed_kmh': 96, 'warn_margin_kmh': 5, 'brake_margin_kmh': 15}, {'permitted': 0, 'action': 'brake'}), ('sampled regression 37', {'target_kmh': 20, 'distance_m': 2500, 'safety_margin_m': 20, 'decel_cms2': 70, 'line_kmh': 80, 'speed_kmh': 168, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 80, 'action': 'brake'}), ('control 40', {'target_kmh': 0, 'distance_m': 600, 'safety_margin_m': 50, 'decel_cms2': 50, 'line_kmh': 160, 'speed_kmh': 70, 'warn_margin_kmh': 5, 'brake_margin_kmh': 15}, {'permitted': 84, 'action': 'none'})], [('regression: curve above line speed', {'target_kmh': 0, 'distance_m': 2500, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 120, 'speed_kmh': 150, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 120, 'action': 'brake'}), ('sampled regression 18', {'target_kmh': 60, 'distance_m': 1200, 'safety_margin_m': 20, 'decel_cms2': 70, 'line_kmh': 120, 'speed_kmh': 6, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 120, 'action': 'none'}), ('sampled regression 64', {'target_kmh': 20, 'distance_m': 600, 'safety_margin_m': 20, 'decel_cms2': 70, 'line_kmh': 80, 'speed_kmh': 44, 'warn_margin_kmh': 3, 'brake_margin_kmh': 8}, {'permitted': 80, 'action': 'none'}), ('boundary: stop target inside the margin', {'target_kmh': 0, 'distance_m': 40, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 10, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 0, 'action': 'warning'}), ('boundary: target speed release', {'target_kmh': 40, 'distance_m': 0, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 44, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 40, 'action': 'none'}), ('control 45', {'target_kmh': 20, 'distance_m': 40, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 80, 'speed_kmh': 133, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 20, 'action': 'brake'}), ('control 48', {'target_kmh': 40, 'distance_m': 100, 'safety_margin_m': 20, 'decel_cms2': 100, 'line_kmh': 160, 'speed_kmh': 75, 'warn_margin_kmh': 3, 'brake_margin_kmh': 15}, {'permitted': 60, 'action': 'warning'}), ('control 51', {'target_kmh': 60, 'distance_m': 600, 'safety_margin_m': 0, 'decel_cms2': 50, 'line_kmh': 160, 'speed_kmh': 8, 'warn_margin_kmh': 5, 'brake_margin_kmh': 8}, {'permitted': 106, 'action': 'none'})]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
The permitted speed exceeds the line speed far from the target.

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

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(x):
    vt = x['target_kmh'] / 3.6
    d = max(x['distance_m'] - x['safety_margin_m'], 0)
    a = x['decel_cms2'] / 100
    vp = math.sqrt(vt * vt + 2 * a * d) * 3.6
    permitted = min(round(vp), x['line_kmh'])
    v = x['speed_kmh']
    if v > permitted + x['brake_margin_kmh']:
        action = 'brake'
    elif v > permitted + x['warn_margin_kmh']:
        action = 'warning'
    else:
        action = 'none'
    return {'permitted': permitted, 'action': action}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: curve below line speed', {'target_kmh': 0, 'distance_m': 600, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 100, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 99, 'action': 'none'}), ('sampled regression 10', {'target_kmh': 20, 'distance_m': 40, 'safety_margin_m': 20, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 33, 'warn_margin_kmh': 5, 'brake_margin_kmh': 15}, {'permitted': 27, 'action': 'warning'}), ('boundary: fractional permitted speed', {'target_kmh': 20, 'distance_m': 100, 'safety_margin_m': 0, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 60, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 47, 'action': 'brake'}), ('boundary: stop target inside the margin', {'target_kmh': 0, 'distance_m': 40, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 10, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 0, 'action': 'warning'}), ('boundary: target speed release', {'target_kmh': 40, 'distance_m': 0, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 44, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 40, 'action': 'none'}), ('control 1', {'target_kmh': 0, 'distance_m': 0, 'safety_margin_m': 0, 'decel_cms2': 100, 'line_kmh': 160, 'speed_kmh': 139, 'warn_margin_kmh': 5, 'brake_margin_kmh': 15}, {'permitted': 0, 'action': 'brake'}), ('sampled regression 4', {'target_kmh': 0, 'distance_m': 100, 'safety_margin_m': 20, 'decel_cms2': 100, 'line_kmh': 80, 'speed_kmh': 136, 'warn_margin_kmh': 5, 'brake_margin_kmh': 15}, {'permitted': 45, 'action': 'brake'}), ('control 7', {'target_kmh': 40, 'distance_m': 2500, 'safety_margin_m': 20, 'decel_cms2': 50, 'line_kmh': 160, 'speed_kmh': 59, 'warn_margin_kmh': 3, 'brake_margin_kmh': 10}, {'permitted': 160, 'action': 'none'})], [('regression: curve below line speed', {'target_kmh': 0, 'distance_m': 600, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 100, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 99, 'action': 'none'}), ('boundary: fractional permitted speed', {'target_kmh': 20, 'distance_m': 100, 'safety_margin_m': 0, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 60, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 47, 'action': 'brake'}), ('sampled regression 43', {'target_kmh': 40, 'distance_m': 250, 'safety_margin_m': 20, 'decel_cms2': 100, 'line_kmh': 160, 'speed_kmh': 33, 'warn_margin_kmh': 5, 'brake_margin_kmh': 15}, {'permitted': 86, 'action': 'none'}), ('control 11', {'target_kmh': 0, 'distance_m': 250, 'safety_margin_m': 20, 'decel_cms2': 100, 'line_kmh': 120, 'speed_kmh': 158, 'warn_margin_kmh': 5, 'brake_margin_kmh': 15}, {'permitted': 77, 'action': 'brake'}), ('boundary: curve above line speed', {'target_kmh': 0, 'distance_m': 2500, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 120, 'speed_kmh': 150, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 120, 'action': 'brake'}), ('sampled regression 12', {'target_kmh': 40, 'distance_m': 600, 'safety_margin_m': 20, 'decel_cms2': 100, 'line_kmh': 160, 'speed_kmh': 133, 'warn_margin_kmh': 3, 'brake_margin_kmh': 15}, {'permitted': 128, 'action': 'warning'}), ('sampled regression 15', {'target_kmh': 0, 'distance_m': 600, 'safety_margin_m': 20, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 43, 'warn_margin_kmh': 3, 'brake_margin_kmh': 10}, {'permitted': 102, 'action': 'none'}), ('control 18', {'target_kmh': 60, 'distance_m': 1200, 'safety_margin_m': 20, 'decel_cms2': 70, 'line_kmh': 120, 'speed_kmh': 6, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 120, 'action': 'none'})], [('regression: curve below line speed', {'target_kmh': 0, 'distance_m': 600, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 100, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 99, 'action': 'none'}), ('sampled regression 61', {'target_kmh': 0, 'distance_m': 250, 'safety_margin_m': 20, 'decel_cms2': 50, 'line_kmh': 120, 'speed_kmh': 75, 'warn_margin_kmh': 5, 'brake_margin_kmh': 15}, {'permitted': 54, 'action': 'brake'}), ('control 22', {'target_kmh': 0, 'distance_m': 250, 'safety_margin_m': 0, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 57, 'warn_margin_kmh': 3, 'brake_margin_kmh': 8}, {'permitted': 67, 'action': 'none'}), ('boundary: warning boundary', {'target_kmh': 40, 'distance_m': 0, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 45, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 40, 'action': 'none'}), ('boundary: brake boundary', {'target_kmh': 40, 'distance_m': 0, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 50, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 40, 'action': 'warning'}), ('control 23', {'target_kmh': 60, 'distance_m': 100, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 80, 'speed_kmh': 13, 'warn_margin_kmh': 5, 'brake_margin_kmh': 8}, {'permitted': 67, 'action': 'none'}), ('control 26', {'target_kmh': 60, 'distance_m': 2500, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 86, 'warn_margin_kmh': 3, 'brake_margin_kmh': 10}, {'permitted': 160, 'action': 'none'}), ('control 29', {'target_kmh': 0, 'distance_m': 250, 'safety_margin_m': 0, 'decel_cms2': 70, 'line_kmh': 120, 'speed_kmh': 4, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 67, 'action': 'none'})], [('regression: curve below line speed', {'target_kmh': 0, 'distance_m': 600, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 100, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 99, 'action': 'none'}), ('boundary: fractional permitted speed', {'target_kmh': 20, 'distance_m': 100, 'safety_margin_m': 0, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 60, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 47, 'action': 'brake'}), ('sampled regression 4', {'target_kmh': 0, 'distance_m': 100, 'safety_margin_m': 20, 'decel_cms2': 100, 'line_kmh': 80, 'speed_kmh': 136, 'warn_margin_kmh': 5, 'brake_margin_kmh': 15}, {'permitted': 45, 'action': 'brake'}), ('control 30', {'target_kmh': 0, 'distance_m': 100, 'safety_margin_m': 50, 'decel_cms2': 50, 'line_kmh': 160, 'speed_kmh': 155, 'warn_margin_kmh': 3, 'brake_margin_kmh': 10}, {'permitted': 25, 'action': 'brake'}), ('boundary: between warning and brake', {'target_kmh': 40, 'distance_m': 0, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 48, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 40, 'action': 'warning'}), ('control 34', {'target_kmh': 0, 'distance_m': 0, 'safety_margin_m': 0, 'decel_cms2': 70, 'line_kmh': 120, 'speed_kmh': 96, 'warn_margin_kmh': 5, 'brake_margin_kmh': 15}, {'permitted': 0, 'action': 'brake'}), ('control 37', {'target_kmh': 20, 'distance_m': 2500, 'safety_margin_m': 20, 'decel_cms2': 70, 'line_kmh': 80, 'speed_kmh': 168, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 80, 'action': 'brake'}), ('control 40', {'target_kmh': 0, 'distance_m': 600, 'safety_margin_m': 50, 'decel_cms2': 50, 'line_kmh': 160, 'speed_kmh': 70, 'warn_margin_kmh': 5, 'brake_margin_kmh': 15}, {'permitted': 84, 'action': 'none'})], [('regression: curve below line speed', {'target_kmh': 0, 'distance_m': 600, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 100, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 99, 'action': 'none'}), ('sampled regression 36', {'target_kmh': 40, 'distance_m': 600, 'safety_margin_m': 0, 'decel_cms2': 100, 'line_kmh': 160, 'speed_kmh': 124, 'warn_margin_kmh': 3, 'brake_margin_kmh': 15}, {'permitted': 130, 'action': 'none'}), ('control 42', {'target_kmh': 40, 'distance_m': 40, 'safety_margin_m': 20, 'decel_cms2': 50, 'line_kmh': 160, 'speed_kmh': 115, 'warn_margin_kmh': 5, 'brake_margin_kmh': 8}, {'permitted': 43, 'action': 'brake'}), ('boundary: stop target inside the margin', {'target_kmh': 0, 'distance_m': 40, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 10, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 0, 'action': 'warning'}), ('boundary: target speed release', {'target_kmh': 40, 'distance_m': 0, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 44, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 40, 'action': 'none'}), ('control 45', {'target_kmh': 20, 'distance_m': 40, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 80, 'speed_kmh': 133, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 20, 'action': 'brake'}), ('sampled regression 48', {'target_kmh': 40, 'distance_m': 100, 'safety_margin_m': 20, 'decel_cms2': 100, 'line_kmh': 160, 'speed_kmh': 75, 'warn_margin_kmh': 3, 'brake_margin_kmh': 15}, {'permitted': 60, 'action': 'warning'}), ('sampled regression 51', {'target_kmh': 60, 'distance_m': 600, 'safety_margin_m': 0, 'decel_cms2': 50, 'line_kmh': 160, 'speed_kmh': 8, 'warn_margin_kmh': 5, 'brake_margin_kmh': 8}, {'permitted': 106, 'action': 'none'})]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(x):
    vt = x['target_kmh'] / 3.6
    d = max(x['distance_m'] - x['safety_margin_m'], 0)
    a = x['decel_cms2'] / 100
    vp = math.sqrt(vt * vt + 2 * a * d) * 3.6
    permitted = min(math.ceil(vp), x['line_kmh'])
    v = x['speed_kmh']
    if v > permitted + x['brake_margin_kmh']:
        action = 'brake'
    elif v > permitted + x['warn_margin_kmh']:
        action = 'warning'
    else:
        action = 'none'
    return {'permitted': permitted, 'action': action}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: curve below line speed', {'target_kmh': 0, 'distance_m': 600, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 100, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 99, 'action': 'none'}), ('sampled regression 10', {'target_kmh': 20, 'distance_m': 40, 'safety_margin_m': 20, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 33, 'warn_margin_kmh': 5, 'brake_margin_kmh': 15}, {'permitted': 27, 'action': 'warning'}), ('boundary: fractional permitted speed', {'target_kmh': 20, 'distance_m': 100, 'safety_margin_m': 0, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 60, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 47, 'action': 'brake'}), ('boundary: stop target inside the margin', {'target_kmh': 0, 'distance_m': 40, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 10, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 0, 'action': 'warning'}), ('boundary: target speed release', {'target_kmh': 40, 'distance_m': 0, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 44, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 40, 'action': 'none'}), ('control 1', {'target_kmh': 0, 'distance_m': 0, 'safety_margin_m': 0, 'decel_cms2': 100, 'line_kmh': 160, 'speed_kmh': 139, 'warn_margin_kmh': 5, 'brake_margin_kmh': 15}, {'permitted': 0, 'action': 'brake'}), ('sampled regression 4', {'target_kmh': 0, 'distance_m': 100, 'safety_margin_m': 20, 'decel_cms2': 100, 'line_kmh': 80, 'speed_kmh': 136, 'warn_margin_kmh': 5, 'brake_margin_kmh': 15}, {'permitted': 45, 'action': 'brake'}), ('control 7', {'target_kmh': 40, 'distance_m': 2500, 'safety_margin_m': 20, 'decel_cms2': 50, 'line_kmh': 160, 'speed_kmh': 59, 'warn_margin_kmh': 3, 'brake_margin_kmh': 10}, {'permitted': 160, 'action': 'none'})], [('regression: curve below line speed', {'target_kmh': 0, 'distance_m': 600, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 100, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 99, 'action': 'none'}), ('boundary: fractional permitted speed', {'target_kmh': 20, 'distance_m': 100, 'safety_margin_m': 0, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 60, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 47, 'action': 'brake'}), ('sampled regression 43', {'target_kmh': 40, 'distance_m': 250, 'safety_margin_m': 20, 'decel_cms2': 100, 'line_kmh': 160, 'speed_kmh': 33, 'warn_margin_kmh': 5, 'brake_margin_kmh': 15}, {'permitted': 86, 'action': 'none'}), ('control 11', {'target_kmh': 0, 'distance_m': 250, 'safety_margin_m': 20, 'decel_cms2': 100, 'line_kmh': 120, 'speed_kmh': 158, 'warn_margin_kmh': 5, 'brake_margin_kmh': 15}, {'permitted': 77, 'action': 'brake'}), ('boundary: curve above line speed', {'target_kmh': 0, 'distance_m': 2500, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 120, 'speed_kmh': 150, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 120, 'action': 'brake'}), ('sampled regression 12', {'target_kmh': 40, 'distance_m': 600, 'safety_margin_m': 20, 'decel_cms2': 100, 'line_kmh': 160, 'speed_kmh': 133, 'warn_margin_kmh': 3, 'brake_margin_kmh': 15}, {'permitted': 128, 'action': 'warning'}), ('sampled regression 15', {'target_kmh': 0, 'distance_m': 600, 'safety_margin_m': 20, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 43, 'warn_margin_kmh': 3, 'brake_margin_kmh': 10}, {'permitted': 102, 'action': 'none'}), ('control 18', {'target_kmh': 60, 'distance_m': 1200, 'safety_margin_m': 20, 'decel_cms2': 70, 'line_kmh': 120, 'speed_kmh': 6, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 120, 'action': 'none'})], [('regression: curve below line speed', {'target_kmh': 0, 'distance_m': 600, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 100, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 99, 'action': 'none'}), ('sampled regression 61', {'target_kmh': 0, 'distance_m': 250, 'safety_margin_m': 20, 'decel_cms2': 50, 'line_kmh': 120, 'speed_kmh': 75, 'warn_margin_kmh': 5, 'brake_margin_kmh': 15}, {'permitted': 54, 'action': 'brake'}), ('control 22', {'target_kmh': 0, 'distance_m': 250, 'safety_margin_m': 0, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 57, 'warn_margin_kmh': 3, 'brake_margin_kmh': 8}, {'permitted': 67, 'action': 'none'}), ('boundary: warning boundary', {'target_kmh': 40, 'distance_m': 0, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 45, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 40, 'action': 'none'}), ('boundary: brake boundary', {'target_kmh': 40, 'distance_m': 0, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 50, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 40, 'action': 'warning'}), ('control 23', {'target_kmh': 60, 'distance_m': 100, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 80, 'speed_kmh': 13, 'warn_margin_kmh': 5, 'brake_margin_kmh': 8}, {'permitted': 67, 'action': 'none'}), ('control 26', {'target_kmh': 60, 'distance_m': 2500, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 86, 'warn_margin_kmh': 3, 'brake_margin_kmh': 10}, {'permitted': 160, 'action': 'none'}), ('control 29', {'target_kmh': 0, 'distance_m': 250, 'safety_margin_m': 0, 'decel_cms2': 70, 'line_kmh': 120, 'speed_kmh': 4, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 67, 'action': 'none'})], [('regression: curve below line speed', {'target_kmh': 0, 'distance_m': 600, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 100, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 99, 'action': 'none'}), ('boundary: fractional permitted speed', {'target_kmh': 20, 'distance_m': 100, 'safety_margin_m': 0, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 60, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 47, 'action': 'brake'}), ('sampled regression 4', {'target_kmh': 0, 'distance_m': 100, 'safety_margin_m': 20, 'decel_cms2': 100, 'line_kmh': 80, 'speed_kmh': 136, 'warn_margin_kmh': 5, 'brake_margin_kmh': 15}, {'permitted': 45, 'action': 'brake'}), ('control 30', {'target_kmh': 0, 'distance_m': 100, 'safety_margin_m': 50, 'decel_cms2': 50, 'line_kmh': 160, 'speed_kmh': 155, 'warn_margin_kmh': 3, 'brake_margin_kmh': 10}, {'permitted': 25, 'action': 'brake'}), ('boundary: between warning and brake', {'target_kmh': 40, 'distance_m': 0, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 48, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 40, 'action': 'warning'}), ('control 34', {'target_kmh': 0, 'distance_m': 0, 'safety_margin_m': 0, 'decel_cms2': 70, 'line_kmh': 120, 'speed_kmh': 96, 'warn_margin_kmh': 5, 'brake_margin_kmh': 15}, {'permitted': 0, 'action': 'brake'}), ('control 37', {'target_kmh': 20, 'distance_m': 2500, 'safety_margin_m': 20, 'decel_cms2': 70, 'line_kmh': 80, 'speed_kmh': 168, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 80, 'action': 'brake'}), ('control 40', {'target_kmh': 0, 'distance_m': 600, 'safety_margin_m': 50, 'decel_cms2': 50, 'line_kmh': 160, 'speed_kmh': 70, 'warn_margin_kmh': 5, 'brake_margin_kmh': 15}, {'permitted': 84, 'action': 'none'})], [('regression: curve below line speed', {'target_kmh': 0, 'distance_m': 600, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 100, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 99, 'action': 'none'}), ('sampled regression 36', {'target_kmh': 40, 'distance_m': 600, 'safety_margin_m': 0, 'decel_cms2': 100, 'line_kmh': 160, 'speed_kmh': 124, 'warn_margin_kmh': 3, 'brake_margin_kmh': 15}, {'permitted': 130, 'action': 'none'}), ('control 42', {'target_kmh': 40, 'distance_m': 40, 'safety_margin_m': 20, 'decel_cms2': 50, 'line_kmh': 160, 'speed_kmh': 115, 'warn_margin_kmh': 5, 'brake_margin_kmh': 8}, {'permitted': 43, 'action': 'brake'}), ('boundary: stop target inside the margin', {'target_kmh': 0, 'distance_m': 40, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 10, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 0, 'action': 'warning'}), ('boundary: target speed release', {'target_kmh': 40, 'distance_m': 0, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 44, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 40, 'action': 'none'}), ('control 45', {'target_kmh': 20, 'distance_m': 40, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 80, 'speed_kmh': 133, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 20, 'action': 'brake'}), ('sampled regression 48', {'target_kmh': 40, 'distance_m': 100, 'safety_margin_m': 20, 'decel_cms2': 100, 'line_kmh': 160, 'speed_kmh': 75, 'warn_margin_kmh': 3, 'brake_margin_kmh': 15}, {'permitted': 60, 'action': 'warning'}), ('sampled regression 51', {'target_kmh': 60, 'distance_m': 600, 'safety_margin_m': 0, 'decel_cms2': 50, 'line_kmh': 160, 'speed_kmh': 8, 'warn_margin_kmh': 5, 'brake_margin_kmh': 8}, {'permitted': 106, 'action': 'none'})]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
The permitted speed is one km/h above the braking curve.

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

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(x):
    vt = x['target_kmh'] / 3.6
    d = max(x['distance_m'] - x['safety_margin_m'], 0)
    a = x['decel_cms2'] / 100
    vp = math.sqrt(vt * vt + 2 * a * d) * 3.6
    permitted = min(int(vp), x['line_kmh'])
    v = x['speed_kmh']
    if v > permitted + x['warn_margin_kmh']:
        action = 'warning'
    elif v > permitted + x['brake_margin_kmh']:
        action = 'brake'
    else:
        action = 'none'
    return {'permitted': permitted, 'action': action}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: curve above line speed', {'target_kmh': 0, 'distance_m': 2500, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 120, 'speed_kmh': 150, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 120, 'action': 'brake'}), ('regression: fractional permitted speed', {'target_kmh': 20, 'distance_m': 100, 'safety_margin_m': 0, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 60, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 47, 'action': 'brake'}), ('sampled regression 2', {'target_kmh': 0, 'distance_m': 250, 'safety_margin_m': 50, 'decel_cms2': 50, 'line_kmh': 160, 'speed_kmh': 122, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 50, 'action': 'brake'}), ('sampled regression 19', {'target_kmh': 0, 'distance_m': 40, 'safety_margin_m': 50, 'decel_cms2': 100, 'line_kmh': 160, 'speed_kmh': 17, 'warn_margin_kmh': 3, 'brake_margin_kmh': 15}, {'permitted': 0, 'action': 'brake'}), ('boundary: stop target inside the margin', {'target_kmh': 0, 'distance_m': 40, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 10, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 0, 'action': 'warning'}), ('sampled regression 1', {'target_kmh': 0, 'distance_m': 0, 'safety_margin_m': 0, 'decel_cms2': 100, 'line_kmh': 160, 'speed_kmh': 139, 'warn_margin_kmh': 5, 'brake_margin_kmh': 15}, {'permitted': 0, 'action': 'brake'}), ('sampled regression 4', {'target_kmh': 0, 'distance_m': 100, 'safety_margin_m': 20, 'decel_cms2': 100, 'line_kmh': 80, 'speed_kmh': 136, 'warn_margin_kmh': 5, 'brake_margin_kmh': 15}, {'permitted': 45, 'action': 'brake'}), ('control 7', {'target_kmh': 40, 'distance_m': 2500, 'safety_margin_m': 20, 'decel_cms2': 50, 'line_kmh': 160, 'speed_kmh': 59, 'warn_margin_kmh': 3, 'brake_margin_kmh': 10}, {'permitted': 160, 'action': 'none'})], [('regression: fractional permitted speed', {'target_kmh': 20, 'distance_m': 100, 'safety_margin_m': 0, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 60, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 47, 'action': 'brake'}), ('sampled regression 19', {'target_kmh': 0, 'distance_m': 40, 'safety_margin_m': 50, 'decel_cms2': 100, 'line_kmh': 160, 'speed_kmh': 17, 'warn_margin_kmh': 3, 'brake_margin_kmh': 15}, {'permitted': 0, 'action': 'brake'}), ('boundary: curve below line speed', {'target_kmh': 0, 'distance_m': 600, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 100, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 99, 'action': 'none'}), ('regression: curve above line speed', {'target_kmh': 0, 'distance_m': 2500, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 120, 'speed_kmh': 150, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 120, 'action': 'brake'}), ('boundary: warning boundary', {'target_kmh': 40, 'distance_m': 0, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 45, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 40, 'action': 'none'}), ('control 12', {'target_kmh': 40, 'distance_m': 600, 'safety_margin_m': 20, 'decel_cms2': 100, 'line_kmh': 160, 'speed_kmh': 133, 'warn_margin_kmh': 3, 'brake_margin_kmh': 15}, {'permitted': 128, 'action': 'warning'}), ('control 15', {'target_kmh': 0, 'distance_m': 600, 'safety_margin_m': 20, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 43, 'warn_margin_kmh': 3, 'brake_margin_kmh': 10}, {'permitted': 102, 'action': 'none'}), ('control 18', {'target_kmh': 60, 'distance_m': 1200, 'safety_margin_m': 20, 'decel_cms2': 70, 'line_kmh': 120, 'speed_kmh': 6, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 120, 'action': 'none'})], [('regression: curve above line speed', {'target_kmh': 0, 'distance_m': 2500, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 120, 'speed_kmh': 150, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 120, 'action': 'brake'}), ('regression: fractional permitted speed', {'target_kmh': 20, 'distance_m': 100, 'safety_margin_m': 0, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 60, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 47, 'action': 'brake'}), ('sampled regression 34', {'target_kmh': 0, 'distance_m': 0, 'safety_margin_m': 0, 'decel_cms2': 70, 'line_kmh': 120, 'speed_kmh': 96, 'warn_margin_kmh': 5, 'brake_margin_kmh': 15}, {'permitted': 0, 'action': 'brake'}), ('sampled regression 77', {'target_kmh': 40, 'distance_m': 40, 'safety_margin_m': 50, 'decel_cms2': 100, 'line_kmh': 80, 'speed_kmh': 51, 'warn_margin_kmh': 5, 'brake_margin_kmh': 8}, {'permitted': 40, 'action': 'brake'}), ('boundary: warning boundary', {'target_kmh': 40, 'distance_m': 0, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 45, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 40, 'action': 'none'}), ('control 23', {'target_kmh': 60, 'distance_m': 100, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 80, 'speed_kmh': 13, 'warn_margin_kmh': 5, 'brake_margin_kmh': 8}, {'permitted': 67, 'action': 'none'}), ('control 26', {'target_kmh': 60, 'distance_m': 2500, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 86, 'warn_margin_kmh': 3, 'brake_margin_kmh': 10}, {'permitted': 160, 'action': 'none'}), ('control 29', {'target_kmh': 0, 'distance_m': 250, 'safety_margin_m': 0, 'decel_cms2': 70, 'line_kmh': 120, 'speed_kmh': 4, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 67, 'action': 'none'})], [('regression: fractional permitted speed', {'target_kmh': 20, 'distance_m': 100, 'safety_margin_m': 0, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 60, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 47, 'action': 'brake'}), ('sampled regression 46', {'target_kmh': 0, 'distance_m': 100, 'safety_margin_m': 20, 'decel_cms2': 100, 'line_kmh': 120, 'speed_kmh': 73, 'warn_margin_kmh': 5, 'brake_margin_kmh': 15}, {'permitted': 45, 'action': 'brake'}), ('sampled regression 19', {'target_kmh': 0, 'distance_m': 40, 'safety_margin_m': 50, 'decel_cms2': 100, 'line_kmh': 160, 'speed_kmh': 17, 'warn_margin_kmh': 3, 'brake_margin_kmh': 15}, {'permitted': 0, 'action': 'brake'}), ('boundary: between warning and brake', {'target_kmh': 40, 'distance_m': 0, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 48, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 40, 'action': 'warning'}), ('boundary: stop target inside the margin', {'target_kmh': 0, 'distance_m': 40, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 10, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 0, 'action': 'warning'}), ('sampled regression 34', {'target_kmh': 0, 'distance_m': 0, 'safety_margin_m': 0, 'decel_cms2': 70, 'line_kmh': 120, 'speed_kmh': 96, 'warn_margin_kmh': 5, 'brake_margin_kmh': 15}, {'permitted': 0, 'action': 'brake'}), ('sampled regression 37', {'target_kmh': 20, 'distance_m': 2500, 'safety_margin_m': 20, 'decel_cms2': 70, 'line_kmh': 80, 'speed_kmh': 168, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 80, 'action': 'brake'}), ('control 40', {'target_kmh': 0, 'distance_m': 600, 'safety_margin_m': 50, 'decel_cms2': 50, 'line_kmh': 160, 'speed_kmh': 70, 'warn_margin_kmh': 5, 'brake_margin_kmh': 15}, {'permitted': 84, 'action': 'none'})], [('regression: curve above line speed', {'target_kmh': 0, 'distance_m': 2500, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 120, 'speed_kmh': 150, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 120, 'action': 'brake'}), ('regression: fractional permitted speed', {'target_kmh': 20, 'distance_m': 100, 'safety_margin_m': 0, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 60, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 47, 'action': 'brake'}), ('sampled regression 66', {'target_kmh': 0, 'distance_m': 100, 'safety_margin_m': 50, 'decel_cms2': 50, 'line_kmh': 80, 'speed_kmh': 140, 'warn_margin_kmh': 3, 'brake_margin_kmh': 15}, {'permitted': 25, 'action': 'brake'}), ('boundary: stop target inside the margin', {'target_kmh': 0, 'distance_m': 40, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 10, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 0, 'action': 'warning'}), ('boundary: target speed release', {'target_kmh': 40, 'distance_m': 0, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 44, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 40, 'action': 'none'}), ('sampled regression 45', {'target_kmh': 20, 'distance_m': 40, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 80, 'speed_kmh': 133, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 20, 'action': 'brake'}), ('control 48', {'target_kmh': 40, 'distance_m': 100, 'safety_margin_m': 20, 'decel_cms2': 100, 'line_kmh': 160, 'speed_kmh': 75, 'warn_margin_kmh': 3, 'brake_margin_kmh': 15}, {'permitted': 60, 'action': 'warning'}), ('control 51', {'target_kmh': 60, 'distance_m': 600, 'safety_margin_m': 0, 'decel_cms2': 50, 'line_kmh': 160, 'speed_kmh': 8, 'warn_margin_kmh': 5, 'brake_margin_kmh': 8}, {'permitted': 106, 'action': 'none'})]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(x):
    vt = x['target_kmh'] / 3.6
    d = max(x['distance_m'] - x['safety_margin_m'], 0)
    a = x['decel_cms2'] / 100
    vp = math.sqrt(vt * vt + 2 * a * d) * 3.6
    permitted = min(int(vp), x['line_kmh'])
    v = x['speed_kmh']
    if v > permitted + x['warn_margin_kmh'] + x['brake_margin_kmh']:
        action = 'brake'
    elif v > permitted + x['warn_margin_kmh']:
        action = 'warning'
    else:
        action = 'none'
    return {'permitted': permitted, 'action': action}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: curve above line speed', {'target_kmh': 0, 'distance_m': 2500, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 120, 'speed_kmh': 150, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 120, 'action': 'brake'}), ('regression: fractional permitted speed', {'target_kmh': 20, 'distance_m': 100, 'safety_margin_m': 0, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 60, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 47, 'action': 'brake'}), ('sampled regression 2', {'target_kmh': 0, 'distance_m': 250, 'safety_margin_m': 50, 'decel_cms2': 50, 'line_kmh': 160, 'speed_kmh': 122, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 50, 'action': 'brake'}), ('sampled regression 19', {'target_kmh': 0, 'distance_m': 40, 'safety_margin_m': 50, 'decel_cms2': 100, 'line_kmh': 160, 'speed_kmh': 17, 'warn_margin_kmh': 3, 'brake_margin_kmh': 15}, {'permitted': 0, 'action': 'brake'}), ('boundary: stop target inside the margin', {'target_kmh': 0, 'distance_m': 40, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 10, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 0, 'action': 'warning'}), ('sampled regression 1', {'target_kmh': 0, 'distance_m': 0, 'safety_margin_m': 0, 'decel_cms2': 100, 'line_kmh': 160, 'speed_kmh': 139, 'warn_margin_kmh': 5, 'brake_margin_kmh': 15}, {'permitted': 0, 'action': 'brake'}), ('sampled regression 4', {'target_kmh': 0, 'distance_m': 100, 'safety_margin_m': 20, 'decel_cms2': 100, 'line_kmh': 80, 'speed_kmh': 136, 'warn_margin_kmh': 5, 'brake_margin_kmh': 15}, {'permitted': 45, 'action': 'brake'}), ('control 7', {'target_kmh': 40, 'distance_m': 2500, 'safety_margin_m': 20, 'decel_cms2': 50, 'line_kmh': 160, 'speed_kmh': 59, 'warn_margin_kmh': 3, 'brake_margin_kmh': 10}, {'permitted': 160, 'action': 'none'})], [('regression: fractional permitted speed', {'target_kmh': 20, 'distance_m': 100, 'safety_margin_m': 0, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 60, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 47, 'action': 'brake'}), ('sampled regression 19', {'target_kmh': 0, 'distance_m': 40, 'safety_margin_m': 50, 'decel_cms2': 100, 'line_kmh': 160, 'speed_kmh': 17, 'warn_margin_kmh': 3, 'brake_margin_kmh': 15}, {'permitted': 0, 'action': 'brake'}), ('boundary: curve below line speed', {'target_kmh': 0, 'distance_m': 600, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 100, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 99, 'action': 'none'}), ('regression: curve above line speed', {'target_kmh': 0, 'distance_m': 2500, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 120, 'speed_kmh': 150, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 120, 'action': 'brake'}), ('boundary: warning boundary', {'target_kmh': 40, 'distance_m': 0, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 45, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 40, 'action': 'none'}), ('control 12', {'target_kmh': 40, 'distance_m': 600, 'safety_margin_m': 20, 'decel_cms2': 100, 'line_kmh': 160, 'speed_kmh': 133, 'warn_margin_kmh': 3, 'brake_margin_kmh': 15}, {'permitted': 128, 'action': 'warning'}), ('control 15', {'target_kmh': 0, 'distance_m': 600, 'safety_margin_m': 20, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 43, 'warn_margin_kmh': 3, 'brake_margin_kmh': 10}, {'permitted': 102, 'action': 'none'}), ('control 18', {'target_kmh': 60, 'distance_m': 1200, 'safety_margin_m': 20, 'decel_cms2': 70, 'line_kmh': 120, 'speed_kmh': 6, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 120, 'action': 'none'})], [('regression: curve above line speed', {'target_kmh': 0, 'distance_m': 2500, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 120, 'speed_kmh': 150, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 120, 'action': 'brake'}), ('regression: fractional permitted speed', {'target_kmh': 20, 'distance_m': 100, 'safety_margin_m': 0, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 60, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 47, 'action': 'brake'}), ('sampled regression 34', {'target_kmh': 0, 'distance_m': 0, 'safety_margin_m': 0, 'decel_cms2': 70, 'line_kmh': 120, 'speed_kmh': 96, 'warn_margin_kmh': 5, 'brake_margin_kmh': 15}, {'permitted': 0, 'action': 'brake'}), ('sampled regression 77', {'target_kmh': 40, 'distance_m': 40, 'safety_margin_m': 50, 'decel_cms2': 100, 'line_kmh': 80, 'speed_kmh': 51, 'warn_margin_kmh': 5, 'brake_margin_kmh': 8}, {'permitted': 40, 'action': 'brake'}), ('boundary: warning boundary', {'target_kmh': 40, 'distance_m': 0, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 45, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 40, 'action': 'none'}), ('control 23', {'target_kmh': 60, 'distance_m': 100, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 80, 'speed_kmh': 13, 'warn_margin_kmh': 5, 'brake_margin_kmh': 8}, {'permitted': 67, 'action': 'none'}), ('control 26', {'target_kmh': 60, 'distance_m': 2500, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 86, 'warn_margin_kmh': 3, 'brake_margin_kmh': 10}, {'permitted': 160, 'action': 'none'}), ('control 29', {'target_kmh': 0, 'distance_m': 250, 'safety_margin_m': 0, 'decel_cms2': 70, 'line_kmh': 120, 'speed_kmh': 4, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 67, 'action': 'none'})], [('regression: fractional permitted speed', {'target_kmh': 20, 'distance_m': 100, 'safety_margin_m': 0, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 60, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 47, 'action': 'brake'}), ('sampled regression 46', {'target_kmh': 0, 'distance_m': 100, 'safety_margin_m': 20, 'decel_cms2': 100, 'line_kmh': 120, 'speed_kmh': 73, 'warn_margin_kmh': 5, 'brake_margin_kmh': 15}, {'permitted': 45, 'action': 'brake'}), ('sampled regression 19', {'target_kmh': 0, 'distance_m': 40, 'safety_margin_m': 50, 'decel_cms2': 100, 'line_kmh': 160, 'speed_kmh': 17, 'warn_margin_kmh': 3, 'brake_margin_kmh': 15}, {'permitted': 0, 'action': 'brake'}), ('boundary: between warning and brake', {'target_kmh': 40, 'distance_m': 0, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 48, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 40, 'action': 'warning'}), ('boundary: stop target inside the margin', {'target_kmh': 0, 'distance_m': 40, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 10, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 0, 'action': 'warning'}), ('sampled regression 34', {'target_kmh': 0, 'distance_m': 0, 'safety_margin_m': 0, 'decel_cms2': 70, 'line_kmh': 120, 'speed_kmh': 96, 'warn_margin_kmh': 5, 'brake_margin_kmh': 15}, {'permitted': 0, 'action': 'brake'}), ('sampled regression 37', {'target_kmh': 20, 'distance_m': 2500, 'safety_margin_m': 20, 'decel_cms2': 70, 'line_kmh': 80, 'speed_kmh': 168, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 80, 'action': 'brake'}), ('control 40', {'target_kmh': 0, 'distance_m': 600, 'safety_margin_m': 50, 'decel_cms2': 50, 'line_kmh': 160, 'speed_kmh': 70, 'warn_margin_kmh': 5, 'brake_margin_kmh': 15}, {'permitted': 84, 'action': 'none'})], [('regression: curve above line speed', {'target_kmh': 0, 'distance_m': 2500, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 120, 'speed_kmh': 150, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 120, 'action': 'brake'}), ('regression: fractional permitted speed', {'target_kmh': 20, 'distance_m': 100, 'safety_margin_m': 0, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 60, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 47, 'action': 'brake'}), ('sampled regression 66', {'target_kmh': 0, 'distance_m': 100, 'safety_margin_m': 50, 'decel_cms2': 50, 'line_kmh': 80, 'speed_kmh': 140, 'warn_margin_kmh': 3, 'brake_margin_kmh': 15}, {'permitted': 25, 'action': 'brake'}), ('boundary: stop target inside the margin', {'target_kmh': 0, 'distance_m': 40, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 10, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 0, 'action': 'warning'}), ('boundary: target speed release', {'target_kmh': 40, 'distance_m': 0, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 44, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 40, 'action': 'none'}), ('sampled regression 45', {'target_kmh': 20, 'distance_m': 40, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 80, 'speed_kmh': 133, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 20, 'action': 'brake'}), ('control 48', {'target_kmh': 40, 'distance_m': 100, 'safety_margin_m': 20, 'decel_cms2': 100, 'line_kmh': 160, 'speed_kmh': 75, 'warn_margin_kmh': 3, 'brake_margin_kmh': 15}, {'permitted': 60, 'action': 'warning'}), ('control 51', {'target_kmh': 60, 'distance_m': 600, 'safety_margin_m': 0, 'decel_cms2': 50, 'line_kmh': 160, 'speed_kmh': 8, 'warn_margin_kmh': 5, 'brake_margin_kmh': 8}, {'permitted': 106, 'action': 'none'})]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A train far over the curve only gets a warning.

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

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(x):
    vt = x['target_kmh'] / 3.6
    d = max(x['distance_m'] - x['safety_margin_m'], 0)
    a = x['decel_cms2'] / 100
    vp = math.sqrt(vt * vt + 2 * a * d) * 3.6
    permitted = min(int(vp), x['line_kmh'])
    v = x['speed_kmh']
    if v > permitted + x['brake_margin_kmh']:
        action = 'brake'
    elif v >= permitted + x['warn_margin_kmh']:
        action = 'warning'
    else:
        action = 'none'
    return {'permitted': permitted, 'action': action}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: warning boundary', {'target_kmh': 40, 'distance_m': 0, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 45, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 40, 'action': 'none'}), ('boundary: target speed release', {'target_kmh': 40, 'distance_m': 0, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 44, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 40, 'action': 'none'}), ('boundary: curve below line speed', {'target_kmh': 0, 'distance_m': 600, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 100, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 99, 'action': 'none'}), ('boundary: stop target inside the margin', {'target_kmh': 0, 'distance_m': 40, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 10, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 0, 'action': 'warning'}), ('boundary: curve above line speed', {'target_kmh': 0, 'distance_m': 2500, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 120, 'speed_kmh': 150, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 120, 'action': 'brake'}), ('control 1', {'target_kmh': 0, 'distance_m': 0, 'safety_margin_m': 0, 'decel_cms2': 100, 'line_kmh': 160, 'speed_kmh': 139, 'warn_margin_kmh': 5, 'brake_margin_kmh': 15}, {'permitted': 0, 'action': 'brake'}), ('control 4', {'target_kmh': 0, 'distance_m': 100, 'safety_margin_m': 20, 'decel_cms2': 100, 'line_kmh': 80, 'speed_kmh': 136, 'warn_margin_kmh': 5, 'brake_margin_kmh': 15}, {'permitted': 45, 'action': 'brake'}), ('control 7', {'target_kmh': 40, 'distance_m': 2500, 'safety_margin_m': 20, 'decel_cms2': 50, 'line_kmh': 160, 'speed_kmh': 59, 'warn_margin_kmh': 3, 'brake_margin_kmh': 10}, {'permitted': 160, 'action': 'none'})], [('regression: warning boundary', {'target_kmh': 40, 'distance_m': 0, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 45, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 40, 'action': 'none'}), ('boundary: curve below line speed', {'target_kmh': 0, 'distance_m': 600, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 100, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 99, 'action': 'none'}), ('sampled regression 25', {'target_kmh': 0, 'distance_m': 2500, 'safety_margin_m': 20, 'decel_cms2': 50, 'line_kmh': 160, 'speed_kmh': 163, 'warn_margin_kmh': 3, 'brake_margin_kmh': 8}, {'permitted': 160, 'action': 'none'}), ('boundary: curve above line speed', {'target_kmh': 0, 'distance_m': 2500, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 120, 'speed_kmh': 150, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 120, 'action': 'brake'}), ('boundary: brake boundary', {'target_kmh': 40, 'distance_m': 0, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 50, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 40, 'action': 'warning'}), ('control 12', {'target_kmh': 40, 'distance_m': 600, 'safety_margin_m': 20, 'decel_cms2': 100, 'line_kmh': 160, 'speed_kmh': 133, 'warn_margin_kmh': 3, 'brake_margin_kmh': 15}, {'permitted': 128, 'action': 'warning'}), ('control 15', {'target_kmh': 0, 'distance_m': 600, 'safety_margin_m': 20, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 43, 'warn_margin_kmh': 3, 'brake_margin_kmh': 10}, {'permitted': 102, 'action': 'none'}), ('control 18', {'target_kmh': 60, 'distance_m': 1200, 'safety_margin_m': 20, 'decel_cms2': 70, 'line_kmh': 120, 'speed_kmh': 6, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 120, 'action': 'none'})], [('regression: warning boundary', {'target_kmh': 40, 'distance_m': 0, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 45, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 40, 'action': 'none'}), ('sampled regression 50', {'target_kmh': 20, 'distance_m': 40, 'safety_margin_m': 20, 'decel_cms2': 70, 'line_kmh': 80, 'speed_kmh': 32, 'warn_margin_kmh': 5, 'brake_margin_kmh': 8}, {'permitted': 27, 'action': 'none'}), ('boundary: curve below line speed', {'target_kmh': 0, 'distance_m': 600, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 100, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 99, 'action': 'none'}), ('boundary: brake boundary', {'target_kmh': 40, 'distance_m': 0, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 50, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 40, 'action': 'warning'}), ('boundary: between warning and brake', {'target_kmh': 40, 'distance_m': 0, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 48, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 40, 'action': 'warning'}), ('control 23', {'target_kmh': 60, 'distance_m': 100, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 80, 'speed_kmh': 13, 'warn_margin_kmh': 5, 'brake_margin_kmh': 8}, {'permitted': 67, 'action': 'none'}), ('control 26', {'target_kmh': 60, 'distance_m': 2500, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 86, 'warn_margin_kmh': 3, 'brake_margin_kmh': 10}, {'permitted': 160, 'action': 'none'}), ('control 29', {'target_kmh': 0, 'distance_m': 250, 'safety_margin_m': 0, 'decel_cms2': 70, 'line_kmh': 120, 'speed_kmh': 4, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 67, 'action': 'none'})], [('regression: warning boundary', {'target_kmh': 40, 'distance_m': 0, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 45, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 40, 'action': 'none'}), ('boundary: target speed release', {'target_kmh': 40, 'distance_m': 0, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 44, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 40, 'action': 'none'}), ('boundary: curve below line speed', {'target_kmh': 0, 'distance_m': 600, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 100, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 99, 'action': 'none'}), ('boundary: between warning and brake', {'target_kmh': 40, 'distance_m': 0, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 48, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 40, 'action': 'warning'}), ('boundary: fractional permitted speed', {'target_kmh': 20, 'distance_m': 100, 'safety_margin_m': 0, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 60, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 47, 'action': 'brake'}), ('control 34', {'target_kmh': 0, 'distance_m': 0, 'safety_margin_m': 0, 'decel_cms2': 70, 'line_kmh': 120, 'speed_kmh': 96, 'warn_margin_kmh': 5, 'brake_margin_kmh': 15}, {'permitted': 0, 'action': 'brake'}), ('control 37', {'target_kmh': 20, 'distance_m': 2500, 'safety_margin_m': 20, 'decel_cms2': 70, 'line_kmh': 80, 'speed_kmh': 168, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 80, 'action': 'brake'}), ('control 40', {'target_kmh': 0, 'distance_m': 600, 'safety_margin_m': 50, 'decel_cms2': 50, 'line_kmh': 160, 'speed_kmh': 70, 'warn_margin_kmh': 5, 'brake_margin_kmh': 15}, {'permitted': 84, 'action': 'none'})], [('regression: warning boundary', {'target_kmh': 40, 'distance_m': 0, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 45, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 40, 'action': 'none'}), ('boundary: curve below line speed', {'target_kmh': 0, 'distance_m': 600, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 100, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 99, 'action': 'none'}), ('sampled regression 25', {'target_kmh': 0, 'distance_m': 2500, 'safety_margin_m': 20, 'decel_cms2': 50, 'line_kmh': 160, 'speed_kmh': 163, 'warn_margin_kmh': 3, 'brake_margin_kmh': 8}, {'permitted': 160, 'action': 'none'}), ('boundary: stop target inside the margin', {'target_kmh': 0, 'distance_m': 40, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 10, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 0, 'action': 'warning'}), ('boundary: target speed release', {'target_kmh': 40, 'distance_m': 0, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 44, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 40, 'action': 'none'}), ('control 45', {'target_kmh': 20, 'distance_m': 40, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 80, 'speed_kmh': 133, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 20, 'action': 'brake'}), ('control 48', {'target_kmh': 40, 'distance_m': 100, 'safety_margin_m': 20, 'decel_cms2': 100, 'line_kmh': 160, 'speed_kmh': 75, 'warn_margin_kmh': 3, 'brake_margin_kmh': 15}, {'permitted': 60, 'action': 'warning'}), ('control 51', {'target_kmh': 60, 'distance_m': 600, 'safety_margin_m': 0, 'decel_cms2': 50, 'line_kmh': 160, 'speed_kmh': 8, 'warn_margin_kmh': 5, 'brake_margin_kmh': 8}, {'permitted': 106, 'action': 'none'})]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
import math
N = 1
observations = []
def solve(x):
    vt = x['target_kmh'] / 3.6
    d = max(x['distance_m'] - x['safety_margin_m'], 0)
    a = x['decel_cms2'] / 100
    vp = math.sqrt(vt * vt + 2 * a * d) * 3.6
    permitted = min(int(vp), x['line_kmh'])
    v = x['speed_kmh']
    if v > permitted + x['brake_margin_kmh']:
        action = 'brake'
    elif v > permitted:
        action = 'warning'
    else:
        action = 'none'
    return {'permitted': permitted, 'action': action}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: warning boundary', {'target_kmh': 40, 'distance_m': 0, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 45, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 40, 'action': 'none'}), ('boundary: target speed release', {'target_kmh': 40, 'distance_m': 0, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 44, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 40, 'action': 'none'}), ('boundary: curve below line speed', {'target_kmh': 0, 'distance_m': 600, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 100, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 99, 'action': 'none'}), ('boundary: stop target inside the margin', {'target_kmh': 0, 'distance_m': 40, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 10, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 0, 'action': 'warning'}), ('boundary: curve above line speed', {'target_kmh': 0, 'distance_m': 2500, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 120, 'speed_kmh': 150, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 120, 'action': 'brake'}), ('control 1', {'target_kmh': 0, 'distance_m': 0, 'safety_margin_m': 0, 'decel_cms2': 100, 'line_kmh': 160, 'speed_kmh': 139, 'warn_margin_kmh': 5, 'brake_margin_kmh': 15}, {'permitted': 0, 'action': 'brake'}), ('control 4', {'target_kmh': 0, 'distance_m': 100, 'safety_margin_m': 20, 'decel_cms2': 100, 'line_kmh': 80, 'speed_kmh': 136, 'warn_margin_kmh': 5, 'brake_margin_kmh': 15}, {'permitted': 45, 'action': 'brake'}), ('control 7', {'target_kmh': 40, 'distance_m': 2500, 'safety_margin_m': 20, 'decel_cms2': 50, 'line_kmh': 160, 'speed_kmh': 59, 'warn_margin_kmh': 3, 'brake_margin_kmh': 10}, {'permitted': 160, 'action': 'none'})], [('regression: warning boundary', {'target_kmh': 40, 'distance_m': 0, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 45, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 40, 'action': 'none'}), ('boundary: curve below line speed', {'target_kmh': 0, 'distance_m': 600, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 100, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 99, 'action': 'none'}), ('sampled regression 25', {'target_kmh': 0, 'distance_m': 2500, 'safety_margin_m': 20, 'decel_cms2': 50, 'line_kmh': 160, 'speed_kmh': 163, 'warn_margin_kmh': 3, 'brake_margin_kmh': 8}, {'permitted': 160, 'action': 'none'}), ('boundary: curve above line speed', {'target_kmh': 0, 'distance_m': 2500, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 120, 'speed_kmh': 150, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 120, 'action': 'brake'}), ('boundary: brake boundary', {'target_kmh': 40, 'distance_m': 0, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 50, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 40, 'action': 'warning'}), ('control 12', {'target_kmh': 40, 'distance_m': 600, 'safety_margin_m': 20, 'decel_cms2': 100, 'line_kmh': 160, 'speed_kmh': 133, 'warn_margin_kmh': 3, 'brake_margin_kmh': 15}, {'permitted': 128, 'action': 'warning'}), ('control 15', {'target_kmh': 0, 'distance_m': 600, 'safety_margin_m': 20, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 43, 'warn_margin_kmh': 3, 'brake_margin_kmh': 10}, {'permitted': 102, 'action': 'none'}), ('control 18', {'target_kmh': 60, 'distance_m': 1200, 'safety_margin_m': 20, 'decel_cms2': 70, 'line_kmh': 120, 'speed_kmh': 6, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 120, 'action': 'none'})], [('regression: warning boundary', {'target_kmh': 40, 'distance_m': 0, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 45, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 40, 'action': 'none'}), ('sampled regression 50', {'target_kmh': 20, 'distance_m': 40, 'safety_margin_m': 20, 'decel_cms2': 70, 'line_kmh': 80, 'speed_kmh': 32, 'warn_margin_kmh': 5, 'brake_margin_kmh': 8}, {'permitted': 27, 'action': 'none'}), ('boundary: curve below line speed', {'target_kmh': 0, 'distance_m': 600, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 100, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 99, 'action': 'none'}), ('boundary: brake boundary', {'target_kmh': 40, 'distance_m': 0, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 50, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 40, 'action': 'warning'}), ('boundary: between warning and brake', {'target_kmh': 40, 'distance_m': 0, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 48, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 40, 'action': 'warning'}), ('control 23', {'target_kmh': 60, 'distance_m': 100, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 80, 'speed_kmh': 13, 'warn_margin_kmh': 5, 'brake_margin_kmh': 8}, {'permitted': 67, 'action': 'none'}), ('control 26', {'target_kmh': 60, 'distance_m': 2500, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 86, 'warn_margin_kmh': 3, 'brake_margin_kmh': 10}, {'permitted': 160, 'action': 'none'}), ('control 29', {'target_kmh': 0, 'distance_m': 250, 'safety_margin_m': 0, 'decel_cms2': 70, 'line_kmh': 120, 'speed_kmh': 4, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 67, 'action': 'none'})], [('regression: warning boundary', {'target_kmh': 40, 'distance_m': 0, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 45, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 40, 'action': 'none'}), ('boundary: target speed release', {'target_kmh': 40, 'distance_m': 0, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 44, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 40, 'action': 'none'}), ('boundary: curve below line speed', {'target_kmh': 0, 'distance_m': 600, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 100, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 99, 'action': 'none'}), ('boundary: between warning and brake', {'target_kmh': 40, 'distance_m': 0, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 48, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 40, 'action': 'warning'}), ('boundary: fractional permitted speed', {'target_kmh': 20, 'distance_m': 100, 'safety_margin_m': 0, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 60, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 47, 'action': 'brake'}), ('control 34', {'target_kmh': 0, 'distance_m': 0, 'safety_margin_m': 0, 'decel_cms2': 70, 'line_kmh': 120, 'speed_kmh': 96, 'warn_margin_kmh': 5, 'brake_margin_kmh': 15}, {'permitted': 0, 'action': 'brake'}), ('control 37', {'target_kmh': 20, 'distance_m': 2500, 'safety_margin_m': 20, 'decel_cms2': 70, 'line_kmh': 80, 'speed_kmh': 168, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 80, 'action': 'brake'}), ('control 40', {'target_kmh': 0, 'distance_m': 600, 'safety_margin_m': 50, 'decel_cms2': 50, 'line_kmh': 160, 'speed_kmh': 70, 'warn_margin_kmh': 5, 'brake_margin_kmh': 15}, {'permitted': 84, 'action': 'none'})], [('regression: warning boundary', {'target_kmh': 40, 'distance_m': 0, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 45, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 40, 'action': 'none'}), ('boundary: curve below line speed', {'target_kmh': 0, 'distance_m': 600, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 100, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 99, 'action': 'none'}), ('sampled regression 25', {'target_kmh': 0, 'distance_m': 2500, 'safety_margin_m': 20, 'decel_cms2': 50, 'line_kmh': 160, 'speed_kmh': 163, 'warn_margin_kmh': 3, 'brake_margin_kmh': 8}, {'permitted': 160, 'action': 'none'}), ('boundary: stop target inside the margin', {'target_kmh': 0, 'distance_m': 40, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 10, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 0, 'action': 'warning'}), ('boundary: target speed release', {'target_kmh': 40, 'distance_m': 0, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 160, 'speed_kmh': 44, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 40, 'action': 'none'}), ('control 45', {'target_kmh': 20, 'distance_m': 40, 'safety_margin_m': 50, 'decel_cms2': 70, 'line_kmh': 80, 'speed_kmh': 133, 'warn_margin_kmh': 5, 'brake_margin_kmh': 10}, {'permitted': 20, 'action': 'brake'}), ('control 48', {'target_kmh': 40, 'distance_m': 100, 'safety_margin_m': 20, 'decel_cms2': 100, 'line_kmh': 160, 'speed_kmh': 75, 'warn_margin_kmh': 3, 'brake_margin_kmh': 15}, {'permitted': 60, 'action': 'warning'}), ('control 51', {'target_kmh': 60, 'distance_m': 600, 'safety_margin_m': 0, 'decel_cms2': 50, 'line_kmh': 160, 'speed_kmh': 8, 'warn_margin_kmh': 5, 'brake_margin_kmh': 8}, {'permitted': 106, 'action': 'none'})]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

prompt:
A train running exactly at the warning margin is warned.

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

split: open-access