broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
import math
N = 1
observations = []
def solve(x):
    C, g = x['cycle'], x['green']
    lam = Fraction(g, C)
    cap = x['sat_per_lane'] * x['lanes'] * lam
    X = Fraction(x['volume']) / cap
    d = Fraction(1, 2) * C * (1 - lam) ** 2 / (1 - X * lam)
    tenths = int(d * 10 + Fraction(1, 2))
    if X > 1:
        los = 'F'
    else:
        los = 'F'
        for lim, lab in ((100, 'A'), (200, 'B'), (350, 'C'), (550, 'D'), (800, 'E')):
            if tenths <= lim:
                los = lab
                break
    return {'vc_milli': int(X * 1000), 'delay_tenths': tenths, 'los': los}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'cycle': 150, 'green': 101, 'volume': 2622, 'sat_per_lane': 1900, 'lanes': 2}, {'vc_milli': 1024, 'delay_tenths': 245, 'los': 'F'}), ({'cycle': 90, 'green': 30, 'volume': 700, 'sat_per_lane': 1800, 'lanes': 2}, {'vc_milli': 583, 'delay_tenths': 248, 'los': 'C'}), ({'cycle': 90, 'green': 26, 'volume': 553, 'sat_per_lane': 1900, 'lanes': 1}, {'vc_milli': 1007, 'delay_tenths': 320, 'los': 'F'}), ({'cycle': 120, 'green': 86, 'volume': 1979, 'sat_per_lane': 1700, 'lanes': 3}, {'vc_milli': 541, 'delay_tenths': 79, 'los': 'A'}), ({'cycle': 100, 'green': 50, 'volume': 900, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 1000, 'delay_tenths': 250, 'los': 'C'}), ({'cycle': 120, 'green': 40, 'volume': 1300, 'sat_per_lane': 1900, 'lanes': 2}, {'vc_milli': 1026, 'delay_tenths': 400, 'los': 'F'}), ({'cycle': 120, 'green': 29, 'volume': 647, 'sat_per_lane': 1800, 'lanes': 3}, {'vc_milli': 495, 'delay_tenths': 392, 'los': 'D'}), ({'cycle': 120, 'green': 54, 'volume': 4200, 'sat_per_lane': 1900, 'lanes': 3}, {'vc_milli': 1637, 'delay_tenths': 330, 'los': 'F'})], [({'cycle': 100, 'green': 50, 'volume': 675, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 750, 'delay_tenths': 200, 'los': 'B'}), ({'cycle': 120, 'green': 26, 'volume': 376, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 964, 'delay_tenths': 465, 'los': 'D'}), ({'cycle': 60, 'green': 33, 'volume': 1900, 'sat_per_lane': 1700, 'lanes': 2}, {'vc_milli': 1016, 'delay_tenths': 135, 'los': 'F'}), ({'cycle': 140, 'green': 88, 'volume': 765, 'sat_per_lane': 1900, 'lanes': 1}, {'vc_milli': 640, 'delay_tenths': 162, 'los': 'B'}), ({'cycle': 90, 'green': 60, 'volume': 1689, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 1407, 'delay_tenths': 150, 'los': 'F'}), ({'cycle': 130, 'green': 69, 'volume': 1045, 'sat_per_lane': 1900, 'lanes': 1}, {'vc_milli': 1036, 'delay_tenths': 305, 'los': 'F'}), ({'cycle': 60, 'green': 40, 'volume': 800, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 666, 'delay_tenths': 60, 'los': 'A'}), ({'cycle': 120, 'green': 40, 'volume': 1300, 'sat_per_lane': 1900, 'lanes': 2}, {'vc_milli': 1026, 'delay_tenths': 400, 'los': 'F'})], [({'cycle': 100, 'green': 50, 'volume': 900, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 1000, 'delay_tenths': 250, 'los': 'C'}), ({'cycle': 60, 'green': 40, 'volume': 2309, 'sat_per_lane': 1800, 'lanes': 3}, {'vc_milli': 641, 'delay_tenths': 58, 'los': 'A'}), ({'cycle': 130, 'green': 28, 'volume': 848, 'sat_per_lane': 1800, 'lanes': 2}, {'vc_milli': 1093, 'delay_tenths': 510, 'los': 'F'}), ({'cycle': 90, 'green': 30, 'volume': 700, 'sat_per_lane': 1800, 'lanes': 2}, {'vc_milli': 583, 'delay_tenths': 248, 'los': 'C'}), ({'cycle': 100, 'green': 50, 'volume': 675, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 750, 'delay_tenths': 200, 'los': 'B'}), ({'cycle': 90, 'green': 15, 'volume': 386, 'sat_per_lane': 1900, 'lanes': 1}, {'vc_milli': 1218, 'delay_tenths': 375, 'los': 'F'}), ({'cycle': 100, 'green': 37, 'volume': 509, 'sat_per_lane': 1900, 'lanes': 1}, {'vc_milli': 724, 'delay_tenths': 271, 'los': 'C'}), ({'cycle': 80, 'green': 16, 'volume': 670, 'sat_per_lane': 1700, 'lanes': 1}, {'vc_milli': 1970, 'delay_tenths': 320, 'los': 'F'})], [({'cycle': 140, 'green': 41, 'volume': 539, 'sat_per_lane': 1800, 'lanes': 2}, {'vc_milli': 511, 'delay_tenths': 412, 'los': 'D'}), ({'cycle': 100, 'green': 50, 'volume': 900, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 1000, 'delay_tenths': 250, 'los': 'C'}), ({'cycle': 80, 'green': 24, 'volume': 865, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 1601, 'delay_tenths': 280, 'los': 'F'}), ({'cycle': 90, 'green': 30, 'volume': 700, 'sat_per_lane': 1800, 'lanes': 2}, {'vc_milli': 583, 'delay_tenths': 248, 'los': 'C'}), ({'cycle': 130, 'green': 95, 'volume': 3055, 'sat_per_lane': 1900, 'lanes': 2}, {'vc_milli': 1100, 'delay_tenths': 175, 'los': 'F'}), ({'cycle': 80, 'green': 41, 'volume': 5005, 'sat_per_lane': 1800, 'lanes': 3}, {'vc_milli': 1808, 'delay_tenths': 195, 'los': 'F'}), ({'cycle': 100, 'green': 50, 'volume': 675, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 750, 'delay_tenths': 200, 'los': 'B'}), ({'cycle': 90, 'green': 47, 'volume': 1141, 'sat_per_lane': 1800, 'lanes': 3}, {'vc_milli': 404, 'delay_tenths': 130, 'los': 'B'})], [({'cycle': 120, 'green': 62, 'volume': 674, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 724, 'delay_tenths': 224, 'los': 'C'}), ({'cycle': 90, 'green': 30, 'volume': 700, 'sat_per_lane': 1800, 'lanes': 2}, {'vc_milli': 583, 'delay_tenths': 248, 'los': 'C'}), ({'cycle': 100, 'green': 34, 'volume': 2059, 'sat_per_lane': 1900, 'lanes': 2}, {'vc_milli': 1593, 'delay_tenths': 330, 'los': 'F'}), ({'cycle': 120, 'green': 51, 'volume': 1172, 'sat_per_lane': 1900, 'lanes': 1}, {'vc_milli': 1451, 'delay_tenths': 345, 'los': 'F'}), ({'cycle': 100, 'green': 50, 'volume': 900, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 1000, 'delay_tenths': 250, 'los': 'C'}), ({'cycle': 60, 'green': 40, 'volume': 800, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 666, 'delay_tenths': 60, 'los': 'A'}), ({'cycle': 110, 'green': 46, 'volume': 726, 'sat_per_lane': 1700, 'lanes': 2}, {'vc_milli': 510, 'delay_tenths': 237, 'los': 'C'}), ({'cycle': 80, 'green': 16, 'volume': 1796, 'sat_per_lane': 1700, 'lanes': 3}, {'vc_milli': 1760, 'delay_tenths': 320, 'los': 'F'})]]
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
from fractions import Fraction
import math
N = 1
observations = []
def solve(x):
    C, g = x['cycle'], x['green']
    lam = Fraction(g, C)
    cap = x['sat_per_lane'] * x['lanes'] * lam
    X = Fraction(x['volume']) / cap
    d = Fraction(1, 2) * C * (1 - lam) ** 2 / (1 - min(1, X * lam))
    tenths = int(d * 10 + Fraction(1, 2))
    if X > 1:
        los = 'F'
    else:
        los = 'F'
        for lim, lab in ((100, 'A'), (200, 'B'), (350, 'C'), (550, 'D'), (800, 'E')):
            if tenths <= lim:
                los = lab
                break
    return {'vc_milli': int(X * 1000), 'delay_tenths': tenths, 'los': los}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'cycle': 150, 'green': 101, 'volume': 2622, 'sat_per_lane': 1900, 'lanes': 2}, {'vc_milli': 1024, 'delay_tenths': 245, 'los': 'F'}), ({'cycle': 90, 'green': 30, 'volume': 700, 'sat_per_lane': 1800, 'lanes': 2}, {'vc_milli': 583, 'delay_tenths': 248, 'los': 'C'}), ({'cycle': 90, 'green': 26, 'volume': 553, 'sat_per_lane': 1900, 'lanes': 1}, {'vc_milli': 1007, 'delay_tenths': 320, 'los': 'F'}), ({'cycle': 120, 'green': 86, 'volume': 1979, 'sat_per_lane': 1700, 'lanes': 3}, {'vc_milli': 541, 'delay_tenths': 79, 'los': 'A'}), ({'cycle': 100, 'green': 50, 'volume': 900, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 1000, 'delay_tenths': 250, 'los': 'C'}), ({'cycle': 120, 'green': 40, 'volume': 1300, 'sat_per_lane': 1900, 'lanes': 2}, {'vc_milli': 1026, 'delay_tenths': 400, 'los': 'F'}), ({'cycle': 120, 'green': 29, 'volume': 647, 'sat_per_lane': 1800, 'lanes': 3}, {'vc_milli': 495, 'delay_tenths': 392, 'los': 'D'}), ({'cycle': 120, 'green': 54, 'volume': 4200, 'sat_per_lane': 1900, 'lanes': 3}, {'vc_milli': 1637, 'delay_tenths': 330, 'los': 'F'})], [({'cycle': 100, 'green': 50, 'volume': 675, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 750, 'delay_tenths': 200, 'los': 'B'}), ({'cycle': 120, 'green': 26, 'volume': 376, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 964, 'delay_tenths': 465, 'los': 'D'}), ({'cycle': 60, 'green': 33, 'volume': 1900, 'sat_per_lane': 1700, 'lanes': 2}, {'vc_milli': 1016, 'delay_tenths': 135, 'los': 'F'}), ({'cycle': 140, 'green': 88, 'volume': 765, 'sat_per_lane': 1900, 'lanes': 1}, {'vc_milli': 640, 'delay_tenths': 162, 'los': 'B'}), ({'cycle': 90, 'green': 60, 'volume': 1689, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 1407, 'delay_tenths': 150, 'los': 'F'}), ({'cycle': 130, 'green': 69, 'volume': 1045, 'sat_per_lane': 1900, 'lanes': 1}, {'vc_milli': 1036, 'delay_tenths': 305, 'los': 'F'}), ({'cycle': 60, 'green': 40, 'volume': 800, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 666, 'delay_tenths': 60, 'los': 'A'}), ({'cycle': 120, 'green': 40, 'volume': 1300, 'sat_per_lane': 1900, 'lanes': 2}, {'vc_milli': 1026, 'delay_tenths': 400, 'los': 'F'})], [({'cycle': 100, 'green': 50, 'volume': 900, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 1000, 'delay_tenths': 250, 'los': 'C'}), ({'cycle': 60, 'green': 40, 'volume': 2309, 'sat_per_lane': 1800, 'lanes': 3}, {'vc_milli': 641, 'delay_tenths': 58, 'los': 'A'}), ({'cycle': 130, 'green': 28, 'volume': 848, 'sat_per_lane': 1800, 'lanes': 2}, {'vc_milli': 1093, 'delay_tenths': 510, 'los': 'F'}), ({'cycle': 90, 'green': 30, 'volume': 700, 'sat_per_lane': 1800, 'lanes': 2}, {'vc_milli': 583, 'delay_tenths': 248, 'los': 'C'}), ({'cycle': 100, 'green': 50, 'volume': 675, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 750, 'delay_tenths': 200, 'los': 'B'}), ({'cycle': 90, 'green': 15, 'volume': 386, 'sat_per_lane': 1900, 'lanes': 1}, {'vc_milli': 1218, 'delay_tenths': 375, 'los': 'F'}), ({'cycle': 100, 'green': 37, 'volume': 509, 'sat_per_lane': 1900, 'lanes': 1}, {'vc_milli': 724, 'delay_tenths': 271, 'los': 'C'}), ({'cycle': 80, 'green': 16, 'volume': 670, 'sat_per_lane': 1700, 'lanes': 1}, {'vc_milli': 1970, 'delay_tenths': 320, 'los': 'F'})], [({'cycle': 140, 'green': 41, 'volume': 539, 'sat_per_lane': 1800, 'lanes': 2}, {'vc_milli': 511, 'delay_tenths': 412, 'los': 'D'}), ({'cycle': 100, 'green': 50, 'volume': 900, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 1000, 'delay_tenths': 250, 'los': 'C'}), ({'cycle': 80, 'green': 24, 'volume': 865, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 1601, 'delay_tenths': 280, 'los': 'F'}), ({'cycle': 90, 'green': 30, 'volume': 700, 'sat_per_lane': 1800, 'lanes': 2}, {'vc_milli': 583, 'delay_tenths': 248, 'los': 'C'}), ({'cycle': 130, 'green': 95, 'volume': 3055, 'sat_per_lane': 1900, 'lanes': 2}, {'vc_milli': 1100, 'delay_tenths': 175, 'los': 'F'}), ({'cycle': 80, 'green': 41, 'volume': 5005, 'sat_per_lane': 1800, 'lanes': 3}, {'vc_milli': 1808, 'delay_tenths': 195, 'los': 'F'}), ({'cycle': 100, 'green': 50, 'volume': 675, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 750, 'delay_tenths': 200, 'los': 'B'}), ({'cycle': 90, 'green': 47, 'volume': 1141, 'sat_per_lane': 1800, 'lanes': 3}, {'vc_milli': 404, 'delay_tenths': 130, 'los': 'B'})], [({'cycle': 120, 'green': 62, 'volume': 674, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 724, 'delay_tenths': 224, 'los': 'C'}), ({'cycle': 90, 'green': 30, 'volume': 700, 'sat_per_lane': 1800, 'lanes': 2}, {'vc_milli': 583, 'delay_tenths': 248, 'los': 'C'}), ({'cycle': 100, 'green': 34, 'volume': 2059, 'sat_per_lane': 1900, 'lanes': 2}, {'vc_milli': 1593, 'delay_tenths': 330, 'los': 'F'}), ({'cycle': 120, 'green': 51, 'volume': 1172, 'sat_per_lane': 1900, 'lanes': 1}, {'vc_milli': 1451, 'delay_tenths': 345, 'los': 'F'}), ({'cycle': 100, 'green': 50, 'volume': 900, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 1000, 'delay_tenths': 250, 'los': 'C'}), ({'cycle': 60, 'green': 40, 'volume': 800, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 666, 'delay_tenths': 60, 'los': 'A'}), ({'cycle': 110, 'green': 46, 'volume': 726, 'sat_per_lane': 1700, 'lanes': 2}, {'vc_milli': 510, 'delay_tenths': 237, 'los': 'C'}), ({'cycle': 80, 'green': 16, 'volume': 1796, 'sat_per_lane': 1700, 'lanes': 3}, {'vc_milli': 1760, 'delay_tenths': 320, 'los': 'F'})]]
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:
Uniform delay level of service returns a wrong result when the delay denominator uses uncapped X.

Input {cycle, green, volume, sat_per_lane, lanes}. lam = green/cycle, capacity = sat*lanes*lam, X = volume/capacity, uniform delay d = 0.5*C*(1-lam)^2/(1 - min(1,X)*lam) rounded half up to tenths. LOS thresholds on tenths: <=100 A, <=200 B, <=350 C, <=550 D, <=800 E, else F; any X > 1 is F. Return {vc_milli: floor(1000X), delay_tenths, los}.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
import math
N = 1
observations = []
def solve(x):
    C, g = x['cycle'], x['green']
    lam = Fraction(g, C)
    cap = x['sat_per_lane'] * x['lanes'] * lam
    X = Fraction(x['volume']) / cap
    d = Fraction(1, 2) * C * (1 - lam) ** 2 / (1 - min(1, X) * lam)
    tenths = int(d * 10)
    if X > 1:
        los = 'F'
    else:
        los = 'F'
        for lim, lab in ((100, 'A'), (200, 'B'), (350, 'C'), (550, 'D'), (800, 'E')):
            if tenths <= lim:
                los = lab
                break
    return {'vc_milli': int(X * 1000), 'delay_tenths': tenths, 'los': los}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'cycle': 100, 'green': 50, 'volume': 900, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 1000, 'delay_tenths': 250, 'los': 'C'}), ({'cycle': 100, 'green': 50, 'volume': 675, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 750, 'delay_tenths': 200, 'los': 'B'}), ({'cycle': 70, 'green': 37, 'volume': 970, 'sat_per_lane': 1700, 'lanes': 1}, {'vc_milli': 1079, 'delay_tenths': 165, 'los': 'F'}), ({'cycle': 60, 'green': 11, 'volume': 919, 'sat_per_lane': 1700, 'lanes': 3}, {'vc_milli': 982, 'delay_tenths': 244, 'los': 'C'}), ({'cycle': 70, 'green': 21, 'volume': 420, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 777, 'delay_tenths': 224, 'los': 'C'}), ({'cycle': 60, 'green': 40, 'volume': 800, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 666, 'delay_tenths': 60, 'los': 'A'}), ({'cycle': 150, 'green': 103, 'volume': 3653, 'sat_per_lane': 1800, 'lanes': 3}, {'vc_milli': 985, 'delay_tenths': 228, 'los': 'C'}), ({'cycle': 110, 'green': 32, 'volume': 535, 'sat_per_lane': 1700, 'lanes': 3}, {'vc_milli': 360, 'delay_tenths': 309, 'los': 'C'})], [({'cycle': 120, 'green': 40, 'volume': 1300, 'sat_per_lane': 1900, 'lanes': 2}, {'vc_milli': 1026, 'delay_tenths': 400, 'los': 'F'}), ({'cycle': 80, 'green': 50, 'volume': 1381, 'sat_per_lane': 1900, 'lanes': 1}, {'vc_milli': 1162, 'delay_tenths': 150, 'los': 'F'}), ({'cycle': 70, 'green': 13, 'volume': 1930, 'sat_per_lane': 1800, 'lanes': 3}, {'vc_milli': 1924, 'delay_tenths': 285, 'los': 'F'}), ({'cycle': 100, 'green': 50, 'volume': 900, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 1000, 'delay_tenths': 250, 'los': 'C'}), ({'cycle': 70, 'green': 45, 'volume': 1366, 'sat_per_lane': 1800, 'lanes': 3}, {'vc_milli': 393, 'delay_tenths': 60, 'los': 'A'}), ({'cycle': 120, 'green': 64, 'volume': 894, 'sat_per_lane': 1800, 'lanes': 2}, {'vc_milli': 465, 'delay_tenths': 174, 'los': 'B'}), ({'cycle': 80, 'green': 45, 'volume': 1158, 'sat_per_lane': 1800, 'lanes': 2}, {'vc_milli': 571, 'delay_tenths': 113, 'los': 'B'}), ({'cycle': 100, 'green': 50, 'volume': 675, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 750, 'delay_tenths': 200, 'los': 'B'})], [({'cycle': 60, 'green': 40, 'volume': 800, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 666, 'delay_tenths': 60, 'los': 'A'}), ({'cycle': 140, 'green': 22, 'volume': 523, 'sat_per_lane': 1900, 'lanes': 2}, {'vc_milli': 875, 'delay_tenths': 577, 'los': 'E'}), ({'cycle': 90, 'green': 30, 'volume': 2101, 'sat_per_lane': 1700, 'lanes': 2}, {'vc_milli': 1853, 'delay_tenths': 300, 'los': 'F'}), ({'cycle': 100, 'green': 50, 'volume': 900, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 1000, 'delay_tenths': 250, 'los': 'C'}), ({'cycle': 90, 'green': 30, 'volume': 700, 'sat_per_lane': 1800, 'lanes': 2}, {'vc_milli': 583, 'delay_tenths': 248, 'los': 'C'}), ({'cycle': 140, 'green': 38, 'volume': 1193, 'sat_per_lane': 1900, 'lanes': 3}, {'vc_milli': 771, 'delay_tenths': 470, 'los': 'D'}), ({'cycle': 80, 'green': 14, 'volume': 334, 'sat_per_lane': 1700, 'lanes': 1}, {'vc_milli': 1122, 'delay_tenths': 330, 'los': 'F'}), ({'cycle': 130, 'green': 103, 'volume': 1066, 'sat_per_lane': 1800, 'lanes': 2}, {'vc_milli': 373, 'delay_tenths': 40, 'los': 'A'})], [({'cycle': 120, 'green': 40, 'volume': 1300, 'sat_per_lane': 1900, 'lanes': 2}, {'vc_milli': 1026, 'delay_tenths': 400, 'los': 'F'}), ({'cycle': 100, 'green': 50, 'volume': 675, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 750, 'delay_tenths': 200, 'los': 'B'}), ({'cycle': 130, 'green': 50, 'volume': 340, 'sat_per_lane': 1700, 'lanes': 1}, {'vc_milli': 520, 'delay_tenths': 308, 'los': 'C'}), ({'cycle': 150, 'green': 54, 'volume': 754, 'sat_per_lane': 1800, 'lanes': 2}, {'vc_milli': 581, 'delay_tenths': 389, 'los': 'D'}), ({'cycle': 60, 'green': 40, 'volume': 800, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 666, 'delay_tenths': 60, 'los': 'A'}), ({'cycle': 110, 'green': 61, 'volume': 4988, 'sat_per_lane': 1800, 'lanes': 3}, {'vc_milli': 1665, 'delay_tenths': 245, 'los': 'F'}), ({'cycle': 80, 'green': 20, 'volume': 841, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 1868, 'delay_tenths': 300, 'los': 'F'}), ({'cycle': 130, 'green': 67, 'volume': 1113, 'sat_per_lane': 1900, 'lanes': 2}, {'vc_milli': 568, 'delay_tenths': 216, 'los': 'C'})], [({'cycle': 100, 'green': 50, 'volume': 675, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 750, 'delay_tenths': 200, 'los': 'B'}), ({'cycle': 60, 'green': 22, 'volume': 835, 'sat_per_lane': 1700, 'lanes': 2}, {'vc_milli': 669, 'delay_tenths': 160, 'los': 'B'}), ({'cycle': 140, 'green': 116, 'volume': 4381, 'sat_per_lane': 1900, 'lanes': 3}, {'vc_milli': 927, 'delay_tenths': 89, 'los': 'A'}), ({'cycle': 100, 'green': 84, 'volume': 5008, 'sat_per_lane': 1700, 'lanes': 2}, {'vc_milli': 1753, 'delay_tenths': 80, 'los': 'F'}), ({'cycle': 60, 'green': 40, 'volume': 800, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 666, 'delay_tenths': 60, 'los': 'A'}), ({'cycle': 90, 'green': 30, 'volume': 700, 'sat_per_lane': 1800, 'lanes': 2}, {'vc_milli': 583, 'delay_tenths': 248, 'los': 'C'}), ({'cycle': 150, 'green': 13, 'volume': 284, 'sat_per_lane': 1700, 'lanes': 1}, {'vc_milli': 1927, 'delay_tenths': 685, 'los': 'F'}), ({'cycle': 100, 'green': 70, 'volume': 1463, 'sat_per_lane': 1800, 'lanes': 3}, {'vc_milli': 387, 'delay_tenths': 62, 'los': 'A'})]]
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
from fractions import Fraction
import math
N = 1
observations = []
def solve(x):
    C, g = x['cycle'], x['green']
    lam = Fraction(g, C)
    cap = x['sat_per_lane'] * x['lanes'] * lam
    X = Fraction(x['volume']) / cap
    d = Fraction(1, 2) * C * (1 - lam) ** 2 / (1 - min(1, X) * lam)
    tenths = int(d) * 10
    if X > 1:
        los = 'F'
    else:
        los = 'F'
        for lim, lab in ((100, 'A'), (200, 'B'), (350, 'C'), (550, 'D'), (800, 'E')):
            if tenths <= lim:
                los = lab
                break
    return {'vc_milli': int(X * 1000), 'delay_tenths': tenths, 'los': los}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'cycle': 100, 'green': 50, 'volume': 900, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 1000, 'delay_tenths': 250, 'los': 'C'}), ({'cycle': 100, 'green': 50, 'volume': 675, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 750, 'delay_tenths': 200, 'los': 'B'}), ({'cycle': 70, 'green': 37, 'volume': 970, 'sat_per_lane': 1700, 'lanes': 1}, {'vc_milli': 1079, 'delay_tenths': 165, 'los': 'F'}), ({'cycle': 60, 'green': 11, 'volume': 919, 'sat_per_lane': 1700, 'lanes': 3}, {'vc_milli': 982, 'delay_tenths': 244, 'los': 'C'}), ({'cycle': 70, 'green': 21, 'volume': 420, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 777, 'delay_tenths': 224, 'los': 'C'}), ({'cycle': 60, 'green': 40, 'volume': 800, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 666, 'delay_tenths': 60, 'los': 'A'}), ({'cycle': 150, 'green': 103, 'volume': 3653, 'sat_per_lane': 1800, 'lanes': 3}, {'vc_milli': 985, 'delay_tenths': 228, 'los': 'C'}), ({'cycle': 110, 'green': 32, 'volume': 535, 'sat_per_lane': 1700, 'lanes': 3}, {'vc_milli': 360, 'delay_tenths': 309, 'los': 'C'})], [({'cycle': 120, 'green': 40, 'volume': 1300, 'sat_per_lane': 1900, 'lanes': 2}, {'vc_milli': 1026, 'delay_tenths': 400, 'los': 'F'}), ({'cycle': 80, 'green': 50, 'volume': 1381, 'sat_per_lane': 1900, 'lanes': 1}, {'vc_milli': 1162, 'delay_tenths': 150, 'los': 'F'}), ({'cycle': 70, 'green': 13, 'volume': 1930, 'sat_per_lane': 1800, 'lanes': 3}, {'vc_milli': 1924, 'delay_tenths': 285, 'los': 'F'}), ({'cycle': 100, 'green': 50, 'volume': 900, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 1000, 'delay_tenths': 250, 'los': 'C'}), ({'cycle': 70, 'green': 45, 'volume': 1366, 'sat_per_lane': 1800, 'lanes': 3}, {'vc_milli': 393, 'delay_tenths': 60, 'los': 'A'}), ({'cycle': 120, 'green': 64, 'volume': 894, 'sat_per_lane': 1800, 'lanes': 2}, {'vc_milli': 465, 'delay_tenths': 174, 'los': 'B'}), ({'cycle': 80, 'green': 45, 'volume': 1158, 'sat_per_lane': 1800, 'lanes': 2}, {'vc_milli': 571, 'delay_tenths': 113, 'los': 'B'}), ({'cycle': 100, 'green': 50, 'volume': 675, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 750, 'delay_tenths': 200, 'los': 'B'})], [({'cycle': 60, 'green': 40, 'volume': 800, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 666, 'delay_tenths': 60, 'los': 'A'}), ({'cycle': 140, 'green': 22, 'volume': 523, 'sat_per_lane': 1900, 'lanes': 2}, {'vc_milli': 875, 'delay_tenths': 577, 'los': 'E'}), ({'cycle': 90, 'green': 30, 'volume': 2101, 'sat_per_lane': 1700, 'lanes': 2}, {'vc_milli': 1853, 'delay_tenths': 300, 'los': 'F'}), ({'cycle': 100, 'green': 50, 'volume': 900, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 1000, 'delay_tenths': 250, 'los': 'C'}), ({'cycle': 90, 'green': 30, 'volume': 700, 'sat_per_lane': 1800, 'lanes': 2}, {'vc_milli': 583, 'delay_tenths': 248, 'los': 'C'}), ({'cycle': 140, 'green': 38, 'volume': 1193, 'sat_per_lane': 1900, 'lanes': 3}, {'vc_milli': 771, 'delay_tenths': 470, 'los': 'D'}), ({'cycle': 80, 'green': 14, 'volume': 334, 'sat_per_lane': 1700, 'lanes': 1}, {'vc_milli': 1122, 'delay_tenths': 330, 'los': 'F'}), ({'cycle': 130, 'green': 103, 'volume': 1066, 'sat_per_lane': 1800, 'lanes': 2}, {'vc_milli': 373, 'delay_tenths': 40, 'los': 'A'})], [({'cycle': 120, 'green': 40, 'volume': 1300, 'sat_per_lane': 1900, 'lanes': 2}, {'vc_milli': 1026, 'delay_tenths': 400, 'los': 'F'}), ({'cycle': 100, 'green': 50, 'volume': 675, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 750, 'delay_tenths': 200, 'los': 'B'}), ({'cycle': 130, 'green': 50, 'volume': 340, 'sat_per_lane': 1700, 'lanes': 1}, {'vc_milli': 520, 'delay_tenths': 308, 'los': 'C'}), ({'cycle': 150, 'green': 54, 'volume': 754, 'sat_per_lane': 1800, 'lanes': 2}, {'vc_milli': 581, 'delay_tenths': 389, 'los': 'D'}), ({'cycle': 60, 'green': 40, 'volume': 800, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 666, 'delay_tenths': 60, 'los': 'A'}), ({'cycle': 110, 'green': 61, 'volume': 4988, 'sat_per_lane': 1800, 'lanes': 3}, {'vc_milli': 1665, 'delay_tenths': 245, 'los': 'F'}), ({'cycle': 80, 'green': 20, 'volume': 841, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 1868, 'delay_tenths': 300, 'los': 'F'}), ({'cycle': 130, 'green': 67, 'volume': 1113, 'sat_per_lane': 1900, 'lanes': 2}, {'vc_milli': 568, 'delay_tenths': 216, 'los': 'C'})], [({'cycle': 100, 'green': 50, 'volume': 675, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 750, 'delay_tenths': 200, 'los': 'B'}), ({'cycle': 60, 'green': 22, 'volume': 835, 'sat_per_lane': 1700, 'lanes': 2}, {'vc_milli': 669, 'delay_tenths': 160, 'los': 'B'}), ({'cycle': 140, 'green': 116, 'volume': 4381, 'sat_per_lane': 1900, 'lanes': 3}, {'vc_milli': 927, 'delay_tenths': 89, 'los': 'A'}), ({'cycle': 100, 'green': 84, 'volume': 5008, 'sat_per_lane': 1700, 'lanes': 2}, {'vc_milli': 1753, 'delay_tenths': 80, 'los': 'F'}), ({'cycle': 60, 'green': 40, 'volume': 800, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 666, 'delay_tenths': 60, 'los': 'A'}), ({'cycle': 90, 'green': 30, 'volume': 700, 'sat_per_lane': 1800, 'lanes': 2}, {'vc_milli': 583, 'delay_tenths': 248, 'los': 'C'}), ({'cycle': 150, 'green': 13, 'volume': 284, 'sat_per_lane': 1700, 'lanes': 1}, {'vc_milli': 1927, 'delay_tenths': 685, 'los': 'F'}), ({'cycle': 100, 'green': 70, 'volume': 1463, 'sat_per_lane': 1800, 'lanes': 3}, {'vc_milli': 387, 'delay_tenths': 62, 'los': 'A'})]]
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:
Uniform delay level of service returns a wrong result when the delay is truncated to tenths.

Input {cycle, green, volume, sat_per_lane, lanes}. lam = green/cycle, capacity = sat*lanes*lam, X = volume/capacity, uniform delay d = 0.5*C*(1-lam)^2/(1 - min(1,X)*lam) rounded half up to tenths. LOS thresholds on tenths: <=100 A, <=200 B, <=350 C, <=550 D, <=800 E, else F; any X > 1 is F. Return {vc_milli: floor(1000X), delay_tenths, los}.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
import math
N = 1
observations = []
def solve(x):
    C, g = x['cycle'], x['green']
    lam = Fraction(g, C)
    cap = x['sat_per_lane'] * x['lanes'] * lam
    X = Fraction(x['volume']) / cap
    d = Fraction(1, 2) * C * (1 - lam) ** 2 / (1 - min(1, X) * lam)
    tenths = int(d * 10 + Fraction(1, 2))
    if X > 1:
        los = 'F'
    else:
        los = 'F'
        for lim, lab in ((100, 'A'), (200, 'B'), (350, 'C'), (550, 'D'), (800, 'E')):
            if tenths < lim:
                los = lab
                break
    return {'vc_milli': int(X * 1000), 'delay_tenths': tenths, 'los': los}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'cycle': 60, 'green': 40, 'volume': 800, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 666, 'delay_tenths': 60, 'los': 'A'}), ({'cycle': 150, 'green': 123, 'volume': 3014, 'sat_per_lane': 1800, 'lanes': 2}, {'vc_milli': 1021, 'delay_tenths': 135, 'los': 'F'}), ({'cycle': 120, 'green': 23, 'volume': 782, 'sat_per_lane': 1700, 'lanes': 2}, {'vc_milli': 1200, 'delay_tenths': 485, 'los': 'F'}), ({'cycle': 100, 'green': 50, 'volume': 900, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 1000, 'delay_tenths': 250, 'los': 'C'}), ({'cycle': 110, 'green': 84, 'volume': 4598, 'sat_per_lane': 1700, 'lanes': 2}, {'vc_milli': 1770, 'delay_tenths': 130, 'los': 'F'}), ({'cycle': 150, 'green': 80, 'volume': 2720, 'sat_per_lane': 1700, 'lanes': 3}, {'vc_milli': 1000, 'delay_tenths': 350, 'los': 'C'}), ({'cycle': 120, 'green': 50, 'volume': 2125, 'sat_per_lane': 1700, 'lanes': 3}, {'vc_milli': 1000, 'delay_tenths': 350, 'los': 'C'}), ({'cycle': 100, 'green': 50, 'volume': 675, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 750, 'delay_tenths': 200, 'los': 'B'})], [({'cycle': 60, 'green': 40, 'volume': 800, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 666, 'delay_tenths': 60, 'los': 'A'}), ({'cycle': 150, 'green': 19, 'volume': 507, 'sat_per_lane': 1700, 'lanes': 3}, {'vc_milli': 784, 'delay_tenths': 635, 'los': 'E'}), ({'cycle': 70, 'green': 47, 'volume': 2082, 'sat_per_lane': 1700, 'lanes': 2}, {'vc_milli': 912, 'delay_tenths': 97, 'los': 'A'}), ({'cycle': 100, 'green': 29, 'volume': 1805, 'sat_per_lane': 1800, 'lanes': 2}, {'vc_milli': 1728, 'delay_tenths': 355, 'los': 'F'}), ({'cycle': 100, 'green': 50, 'volume': 675, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 750, 'delay_tenths': 200, 'los': 'B'}), ({'cycle': 140, 'green': 76, 'volume': 1466, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 1500, 'delay_tenths': 320, 'los': 'F'}), ({'cycle': 80, 'green': 25, 'volume': 1080, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 1920, 'delay_tenths': 275, 'los': 'F'}), ({'cycle': 100, 'green': 50, 'volume': 900, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 1000, 'delay_tenths': 250, 'los': 'C'})], [({'cycle': 100, 'green': 50, 'volume': 675, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 750, 'delay_tenths': 200, 'los': 'B'}), ({'cycle': 100, 'green': 50, 'volume': 900, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 1000, 'delay_tenths': 250, 'los': 'C'}), ({'cycle': 60, 'green': 29, 'volume': 1124, 'sat_per_lane': 1900, 'lanes': 3}, {'vc_milli': 407, 'delay_tenths': 100, 'los': 'A'}), ({'cycle': 90, 'green': 71, 'volume': 5771, 'sat_per_lane': 1800, 'lanes': 3}, {'vc_milli': 1354, 'delay_tenths': 95, 'los': 'F'}), ({'cycle': 90, 'green': 66, 'volume': 6108, 'sat_per_lane': 1700, 'lanes': 3}, {'vc_milli': 1633, 'delay_tenths': 120, 'los': 'F'}), ({'cycle': 90, 'green': 20, 'volume': 2234, 'sat_per_lane': 1700, 'lanes': 3}, {'vc_milli': 1971, 'delay_tenths': 350, 'los': 'F'}), ({'cycle': 90, 'green': 30, 'volume': 700, 'sat_per_lane': 1800, 'lanes': 2}, {'vc_milli': 583, 'delay_tenths': 248, 'los': 'C'}), ({'cycle': 140, 'green': 108, 'volume': 3411, 'sat_per_lane': 1700, 'lanes': 2}, {'vc_milli': 1300, 'delay_tenths': 160, 'los': 'F'})], [({'cycle': 110, 'green': 70, 'volume': 6812, 'sat_per_lane': 1800, 'lanes': 3}, {'vc_milli': 1982, 'delay_tenths': 200, 'los': 'F'}), ({'cycle': 80, 'green': 49, 'volume': 625, 'sat_per_lane': 1700, 'lanes': 1}, {'vc_milli': 600, 'delay_tenths': 95, 'los': 'A'}), ({'cycle': 90, 'green': 30, 'volume': 700, 'sat_per_lane': 1800, 'lanes': 2}, {'vc_milli': 583, 'delay_tenths': 248, 'los': 'C'}), ({'cycle': 90, 'green': 25, 'volume': 383, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 766, 'delay_tenths': 298, 'los': 'C'}), ({'cycle': 150, 'green': 23, 'volume': 434, 'sat_per_lane': 1900, 'lanes': 1}, {'vc_milli': 1489, 'delay_tenths': 635, 'los': 'F'}), ({'cycle': 100, 'green': 50, 'volume': 900, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 1000, 'delay_tenths': 250, 'los': 'C'}), ({'cycle': 100, 'green': 81, 'volume': 2684, 'sat_per_lane': 1700, 'lanes': 2}, {'vc_milli': 974, 'delay_tenths': 86, 'los': 'A'}), ({'cycle': 100, 'green': 50, 'volume': 675, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 750, 'delay_tenths': 200, 'los': 'B'})], [({'cycle': 100, 'green': 82, 'volume': 911, 'sat_per_lane': 1700, 'lanes': 1}, {'vc_milli': 653, 'delay_tenths': 35, 'los': 'A'}), ({'cycle': 120, 'green': 10, 'volume': 475, 'sat_per_lane': 1900, 'lanes': 3}, {'vc_milli': 1000, 'delay_tenths': 550, 'los': 'D'}), ({'cycle': 130, 'green': 85, 'volume': 4393, 'sat_per_lane': 1800, 'lanes': 3}, {'vc_milli': 1244, 'delay_tenths': 225, 'los': 'F'}), ({'cycle': 90, 'green': 55, 'volume': 1084, 'sat_per_lane': 1700, 'lanes': 2}, {'vc_milli': 521, 'delay_tenths': 100, 'los': 'A'}), ({'cycle': 100, 'green': 50, 'volume': 675, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 750, 'delay_tenths': 200, 'los': 'B'}), ({'cycle': 120, 'green': 40, 'volume': 1300, 'sat_per_lane': 1900, 'lanes': 2}, {'vc_milli': 1026, 'delay_tenths': 400, 'los': 'F'}), ({'cycle': 100, 'green': 50, 'volume': 900, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 1000, 'delay_tenths': 250, 'los': 'C'}), ({'cycle': 90, 'green': 30, 'volume': 700, 'sat_per_lane': 1800, 'lanes': 2}, {'vc_milli': 583, 'delay_tenths': 248, 'los': 'C'})]]
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
from fractions import Fraction
import math
N = 1
observations = []
def solve(x):
    C, g = x['cycle'], x['green']
    lam = Fraction(g, C)
    cap = x['sat_per_lane'] * x['lanes'] * lam
    X = Fraction(x['volume']) / cap
    d = Fraction(1, 2) * C * (1 - lam) ** 2 / (1 - min(1, X) * lam)
    tenths = int(d * 10 + Fraction(1, 2))
    if X > 1:
        los = 'F'
    else:
        los = 'F'
        for lim, lab in ((100, 'A'), (200, 'B'), (350, 'C'), (550, 'D'), (800, 'E')):
            if d <= lim:
                los = lab
                break
    return {'vc_milli': int(X * 1000), 'delay_tenths': tenths, 'los': los}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'cycle': 60, 'green': 40, 'volume': 800, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 666, 'delay_tenths': 60, 'los': 'A'}), ({'cycle': 150, 'green': 123, 'volume': 3014, 'sat_per_lane': 1800, 'lanes': 2}, {'vc_milli': 1021, 'delay_tenths': 135, 'los': 'F'}), ({'cycle': 120, 'green': 23, 'volume': 782, 'sat_per_lane': 1700, 'lanes': 2}, {'vc_milli': 1200, 'delay_tenths': 485, 'los': 'F'}), ({'cycle': 100, 'green': 50, 'volume': 900, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 1000, 'delay_tenths': 250, 'los': 'C'}), ({'cycle': 110, 'green': 84, 'volume': 4598, 'sat_per_lane': 1700, 'lanes': 2}, {'vc_milli': 1770, 'delay_tenths': 130, 'los': 'F'}), ({'cycle': 150, 'green': 80, 'volume': 2720, 'sat_per_lane': 1700, 'lanes': 3}, {'vc_milli': 1000, 'delay_tenths': 350, 'los': 'C'}), ({'cycle': 120, 'green': 50, 'volume': 2125, 'sat_per_lane': 1700, 'lanes': 3}, {'vc_milli': 1000, 'delay_tenths': 350, 'los': 'C'}), ({'cycle': 100, 'green': 50, 'volume': 675, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 750, 'delay_tenths': 200, 'los': 'B'})], [({'cycle': 60, 'green': 40, 'volume': 800, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 666, 'delay_tenths': 60, 'los': 'A'}), ({'cycle': 150, 'green': 19, 'volume': 507, 'sat_per_lane': 1700, 'lanes': 3}, {'vc_milli': 784, 'delay_tenths': 635, 'los': 'E'}), ({'cycle': 70, 'green': 47, 'volume': 2082, 'sat_per_lane': 1700, 'lanes': 2}, {'vc_milli': 912, 'delay_tenths': 97, 'los': 'A'}), ({'cycle': 100, 'green': 29, 'volume': 1805, 'sat_per_lane': 1800, 'lanes': 2}, {'vc_milli': 1728, 'delay_tenths': 355, 'los': 'F'}), ({'cycle': 100, 'green': 50, 'volume': 675, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 750, 'delay_tenths': 200, 'los': 'B'}), ({'cycle': 140, 'green': 76, 'volume': 1466, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 1500, 'delay_tenths': 320, 'los': 'F'}), ({'cycle': 80, 'green': 25, 'volume': 1080, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 1920, 'delay_tenths': 275, 'los': 'F'}), ({'cycle': 100, 'green': 50, 'volume': 900, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 1000, 'delay_tenths': 250, 'los': 'C'})], [({'cycle': 100, 'green': 50, 'volume': 675, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 750, 'delay_tenths': 200, 'los': 'B'}), ({'cycle': 100, 'green': 50, 'volume': 900, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 1000, 'delay_tenths': 250, 'los': 'C'}), ({'cycle': 60, 'green': 29, 'volume': 1124, 'sat_per_lane': 1900, 'lanes': 3}, {'vc_milli': 407, 'delay_tenths': 100, 'los': 'A'}), ({'cycle': 90, 'green': 71, 'volume': 5771, 'sat_per_lane': 1800, 'lanes': 3}, {'vc_milli': 1354, 'delay_tenths': 95, 'los': 'F'}), ({'cycle': 90, 'green': 66, 'volume': 6108, 'sat_per_lane': 1700, 'lanes': 3}, {'vc_milli': 1633, 'delay_tenths': 120, 'los': 'F'}), ({'cycle': 90, 'green': 20, 'volume': 2234, 'sat_per_lane': 1700, 'lanes': 3}, {'vc_milli': 1971, 'delay_tenths': 350, 'los': 'F'}), ({'cycle': 90, 'green': 30, 'volume': 700, 'sat_per_lane': 1800, 'lanes': 2}, {'vc_milli': 583, 'delay_tenths': 248, 'los': 'C'}), ({'cycle': 140, 'green': 108, 'volume': 3411, 'sat_per_lane': 1700, 'lanes': 2}, {'vc_milli': 1300, 'delay_tenths': 160, 'los': 'F'})], [({'cycle': 110, 'green': 70, 'volume': 6812, 'sat_per_lane': 1800, 'lanes': 3}, {'vc_milli': 1982, 'delay_tenths': 200, 'los': 'F'}), ({'cycle': 80, 'green': 49, 'volume': 625, 'sat_per_lane': 1700, 'lanes': 1}, {'vc_milli': 600, 'delay_tenths': 95, 'los': 'A'}), ({'cycle': 90, 'green': 30, 'volume': 700, 'sat_per_lane': 1800, 'lanes': 2}, {'vc_milli': 583, 'delay_tenths': 248, 'los': 'C'}), ({'cycle': 90, 'green': 25, 'volume': 383, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 766, 'delay_tenths': 298, 'los': 'C'}), ({'cycle': 150, 'green': 23, 'volume': 434, 'sat_per_lane': 1900, 'lanes': 1}, {'vc_milli': 1489, 'delay_tenths': 635, 'los': 'F'}), ({'cycle': 100, 'green': 50, 'volume': 900, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 1000, 'delay_tenths': 250, 'los': 'C'}), ({'cycle': 100, 'green': 81, 'volume': 2684, 'sat_per_lane': 1700, 'lanes': 2}, {'vc_milli': 974, 'delay_tenths': 86, 'los': 'A'}), ({'cycle': 100, 'green': 50, 'volume': 675, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 750, 'delay_tenths': 200, 'los': 'B'})], [({'cycle': 100, 'green': 82, 'volume': 911, 'sat_per_lane': 1700, 'lanes': 1}, {'vc_milli': 653, 'delay_tenths': 35, 'los': 'A'}), ({'cycle': 120, 'green': 10, 'volume': 475, 'sat_per_lane': 1900, 'lanes': 3}, {'vc_milli': 1000, 'delay_tenths': 550, 'los': 'D'}), ({'cycle': 130, 'green': 85, 'volume': 4393, 'sat_per_lane': 1800, 'lanes': 3}, {'vc_milli': 1244, 'delay_tenths': 225, 'los': 'F'}), ({'cycle': 90, 'green': 55, 'volume': 1084, 'sat_per_lane': 1700, 'lanes': 2}, {'vc_milli': 521, 'delay_tenths': 100, 'los': 'A'}), ({'cycle': 100, 'green': 50, 'volume': 675, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 750, 'delay_tenths': 200, 'los': 'B'}), ({'cycle': 120, 'green': 40, 'volume': 1300, 'sat_per_lane': 1900, 'lanes': 2}, {'vc_milli': 1026, 'delay_tenths': 400, 'los': 'F'}), ({'cycle': 100, 'green': 50, 'volume': 900, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 1000, 'delay_tenths': 250, 'los': 'C'}), ({'cycle': 90, 'green': 30, 'volume': 700, 'sat_per_lane': 1800, 'lanes': 2}, {'vc_milli': 583, 'delay_tenths': 248, 'los': 'C'})]]
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:
Uniform delay level of service returns a wrong result when lOS thresholds are exclusive.

Input {cycle, green, volume, sat_per_lane, lanes}. lam = green/cycle, capacity = sat*lanes*lam, X = volume/capacity, uniform delay d = 0.5*C*(1-lam)^2/(1 - min(1,X)*lam) rounded half up to tenths. LOS thresholds on tenths: <=100 A, <=200 B, <=350 C, <=550 D, <=800 E, else F; any X > 1 is F. Return {vc_milli: floor(1000X), delay_tenths, los}.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
import math
N = 1
observations = []
def solve(x):
    C, g = x['cycle'], x['green']
    lam = Fraction(g, C)
    cap = x['sat_per_lane'] * x['lanes'] * lam
    X = Fraction(x['volume']) / cap
    d = Fraction(1, 2) * C * (1 - lam) ** 2 / (1 - min(1, X) * lam)
    tenths = int(d * 10 + Fraction(1, 2))
    if X >= 1:
        los = 'F'
    else:
        los = 'F'
        for lim, lab in ((100, 'A'), (200, 'B'), (350, 'C'), (550, 'D'), (800, 'E')):
            if tenths <= lim:
                los = lab
                break
    return {'vc_milli': int(X * 1000), 'delay_tenths': tenths, 'los': los}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'cycle': 100, 'green': 12, 'volume': 215, 'sat_per_lane': 1800, 'lanes': 2}, {'vc_milli': 497, 'delay_tenths': 412, 'los': 'D'}), ({'cycle': 150, 'green': 120, 'volume': 2720, 'sat_per_lane': 1700, 'lanes': 2}, {'vc_milli': 1000, 'delay_tenths': 150, 'los': 'B'}), ({'cycle': 130, 'green': 65, 'volume': 1900, 'sat_per_lane': 1900, 'lanes': 2}, {'vc_milli': 1000, 'delay_tenths': 325, 'los': 'C'}), ({'cycle': 60, 'green': 36, 'volume': 2389, 'sat_per_lane': 1900, 'lanes': 2}, {'vc_milli': 1047, 'delay_tenths': 120, 'los': 'F'}), ({'cycle': 120, 'green': 40, 'volume': 1300, 'sat_per_lane': 1900, 'lanes': 2}, {'vc_milli': 1026, 'delay_tenths': 400, 'los': 'F'}), ({'cycle': 100, 'green': 50, 'volume': 900, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 1000, 'delay_tenths': 250, 'los': 'C'}), ({'cycle': 90, 'green': 30, 'volume': 700, 'sat_per_lane': 1800, 'lanes': 2}, {'vc_milli': 583, 'delay_tenths': 248, 'los': 'C'}), ({'cycle': 140, 'green': 78, 'volume': 3819, 'sat_per_lane': 1900, 'lanes': 3}, {'vc_milli': 1202, 'delay_tenths': 310, 'los': 'F'})], [({'cycle': 120, 'green': 40, 'volume': 1300, 'sat_per_lane': 1900, 'lanes': 2}, {'vc_milli': 1026, 'delay_tenths': 400, 'los': 'F'}), ({'cycle': 100, 'green': 50, 'volume': 900, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 1000, 'delay_tenths': 250, 'los': 'C'}), ({'cycle': 110, 'green': 94, 'volume': 1438, 'sat_per_lane': 1900, 'lanes': 1}, {'vc_milli': 885, 'delay_tenths': 48, 'los': 'A'}), ({'cycle': 150, 'green': 93, 'volume': 3162, 'sat_per_lane': 1700, 'lanes': 3}, {'vc_milli': 1000, 'delay_tenths': 285, 'los': 'C'}), ({'cycle': 110, 'green': 55, 'volume': 2088, 'sat_per_lane': 1900, 'lanes': 2}, {'vc_milli': 1098, 'delay_tenths': 275, 'los': 'F'}), ({'cycle': 70, 'green': 44, 'volume': 6920, 'sat_per_lane': 1900, 'lanes': 3}, {'vc_milli': 1931, 'delay_tenths': 130, 'los': 'F'}), ({'cycle': 120, 'green': 76, 'volume': 3230, 'sat_per_lane': 1700, 'lanes': 3}, {'vc_milli': 1000, 'delay_tenths': 220, 'los': 'C'}), ({'cycle': 100, 'green': 50, 'volume': 675, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 750, 'delay_tenths': 200, 'los': 'B'})], [({'cycle': 60, 'green': 40, 'volume': 800, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 666, 'delay_tenths': 60, 'los': 'A'}), ({'cycle': 120, 'green': 96, 'volume': 1520, 'sat_per_lane': 1900, 'lanes': 1}, {'vc_milli': 1000, 'delay_tenths': 120, 'los': 'B'}), ({'cycle': 100, 'green': 50, 'volume': 675, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 750, 'delay_tenths': 200, 'los': 'B'}), ({'cycle': 90, 'green': 30, 'volume': 700, 'sat_per_lane': 1800, 'lanes': 2}, {'vc_milli': 583, 'delay_tenths': 248, 'los': 'C'}), ({'cycle': 150, 'green': 24, 'volume': 868, 'sat_per_lane': 1800, 'lanes': 3}, {'vc_milli': 1004, 'delay_tenths': 630, 'los': 'F'}), ({'cycle': 120, 'green': 45, 'volume': 1425, 'sat_per_lane': 1900, 'lanes': 2}, {'vc_milli': 1000, 'delay_tenths': 375, 'los': 'D'}), ({'cycle': 100, 'green': 20, 'volume': 1080, 'sat_per_lane': 1800, 'lanes': 3}, {'vc_milli': 1000, 'delay_tenths': 400, 'los': 'D'}), ({'cycle': 140, 'green': 57, 'volume': 804, 'sat_per_lane': 1900, 'lanes': 1}, {'vc_milli': 1039, 'delay_tenths': 415, 'los': 'F'})], [({'cycle': 60, 'green': 40, 'volume': 800, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 666, 'delay_tenths': 60, 'los': 'A'}), ({'cycle': 140, 'green': 56, 'volume': 1477, 'sat_per_lane': 1700, 'lanes': 2}, {'vc_milli': 1086, 'delay_tenths': 420, 'los': 'F'}), ({'cycle': 120, 'green': 40, 'volume': 1300, 'sat_per_lane': 1900, 'lanes': 2}, {'vc_milli': 1026, 'delay_tenths': 400, 'los': 'F'}), ({'cycle': 100, 'green': 46, 'volume': 1656, 'sat_per_lane': 1800, 'lanes': 2}, {'vc_milli': 1000, 'delay_tenths': 270, 'los': 'C'}), ({'cycle': 90, 'green': 59, 'volume': 2360, 'sat_per_lane': 1800, 'lanes': 2}, {'vc_milli': 1000, 'delay_tenths': 155, 'los': 'B'}), ({'cycle': 130, 'green': 28, 'volume': 1476, 'sat_per_lane': 1700, 'lanes': 3}, {'vc_milli': 1343, 'delay_tenths': 510, 'los': 'F'}), ({'cycle': 100, 'green': 50, 'volume': 675, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 750, 'delay_tenths': 200, 'los': 'B'}), ({'cycle': 150, 'green': 119, 'volume': 2856, 'sat_per_lane': 1800, 'lanes': 2}, {'vc_milli': 1000, 'delay_tenths': 155, 'los': 'B'})], [({'cycle': 60, 'green': 40, 'volume': 800, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 666, 'delay_tenths': 60, 'los': 'A'}), ({'cycle': 140, 'green': 115, 'volume': 3804, 'sat_per_lane': 1700, 'lanes': 2}, {'vc_milli': 1362, 'delay_tenths': 125, 'los': 'F'}), ({'cycle': 150, 'green': 77, 'volume': 949, 'sat_per_lane': 1700, 'lanes': 1}, {'vc_milli': 1087, 'delay_tenths': 365, 'los': 'F'}), ({'cycle': 70, 'green': 34, 'volume': 1656, 'sat_per_lane': 1700, 'lanes': 2}, {'vc_milli': 1002, 'delay_tenths': 180, 'los': 'F'}), ({'cycle': 90, 'green': 30, 'volume': 700, 'sat_per_lane': 1800, 'lanes': 2}, {'vc_milli': 583, 'delay_tenths': 248, 'los': 'C'}), ({'cycle': 80, 'green': 20, 'volume': 1275, 'sat_per_lane': 1700, 'lanes': 3}, {'vc_milli': 1000, 'delay_tenths': 300, 'los': 'C'}), ({'cycle': 100, 'green': 75, 'volume': 1275, 'sat_per_lane': 1700, 'lanes': 1}, {'vc_milli': 1000, 'delay_tenths': 125, 'los': 'B'}), ({'cycle': 100, 'green': 50, 'volume': 900, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 1000, 'delay_tenths': 250, 'los': 'C'})]]
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
from fractions import Fraction
import math
N = 1
observations = []
def solve(x):
    C, g = x['cycle'], x['green']
    lam = Fraction(g, C)
    cap = x['sat_per_lane'] * x['lanes'] * lam
    X = Fraction(x['volume']) / cap
    d = Fraction(1, 2) * C * (1 - lam) ** 2 / (1 - min(1, X) * lam)
    tenths = int(d * 10 + Fraction(1, 2))
    if X > Fraction(11, 10):
        los = 'F'
    else:
        los = 'F'
        for lim, lab in ((100, 'A'), (200, 'B'), (350, 'C'), (550, 'D'), (800, 'E')):
            if tenths <= lim:
                los = lab
                break
    return {'vc_milli': int(X * 1000), 'delay_tenths': tenths, 'los': los}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'cycle': 100, 'green': 12, 'volume': 215, 'sat_per_lane': 1800, 'lanes': 2}, {'vc_milli': 497, 'delay_tenths': 412, 'los': 'D'}), ({'cycle': 150, 'green': 120, 'volume': 2720, 'sat_per_lane': 1700, 'lanes': 2}, {'vc_milli': 1000, 'delay_tenths': 150, 'los': 'B'}), ({'cycle': 130, 'green': 65, 'volume': 1900, 'sat_per_lane': 1900, 'lanes': 2}, {'vc_milli': 1000, 'delay_tenths': 325, 'los': 'C'}), ({'cycle': 60, 'green': 36, 'volume': 2389, 'sat_per_lane': 1900, 'lanes': 2}, {'vc_milli': 1047, 'delay_tenths': 120, 'los': 'F'}), ({'cycle': 120, 'green': 40, 'volume': 1300, 'sat_per_lane': 1900, 'lanes': 2}, {'vc_milli': 1026, 'delay_tenths': 400, 'los': 'F'}), ({'cycle': 100, 'green': 50, 'volume': 900, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 1000, 'delay_tenths': 250, 'los': 'C'}), ({'cycle': 90, 'green': 30, 'volume': 700, 'sat_per_lane': 1800, 'lanes': 2}, {'vc_milli': 583, 'delay_tenths': 248, 'los': 'C'}), ({'cycle': 140, 'green': 78, 'volume': 3819, 'sat_per_lane': 1900, 'lanes': 3}, {'vc_milli': 1202, 'delay_tenths': 310, 'los': 'F'})], [({'cycle': 120, 'green': 40, 'volume': 1300, 'sat_per_lane': 1900, 'lanes': 2}, {'vc_milli': 1026, 'delay_tenths': 400, 'los': 'F'}), ({'cycle': 100, 'green': 50, 'volume': 900, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 1000, 'delay_tenths': 250, 'los': 'C'}), ({'cycle': 110, 'green': 94, 'volume': 1438, 'sat_per_lane': 1900, 'lanes': 1}, {'vc_milli': 885, 'delay_tenths': 48, 'los': 'A'}), ({'cycle': 150, 'green': 93, 'volume': 3162, 'sat_per_lane': 1700, 'lanes': 3}, {'vc_milli': 1000, 'delay_tenths': 285, 'los': 'C'}), ({'cycle': 110, 'green': 55, 'volume': 2088, 'sat_per_lane': 1900, 'lanes': 2}, {'vc_milli': 1098, 'delay_tenths': 275, 'los': 'F'}), ({'cycle': 70, 'green': 44, 'volume': 6920, 'sat_per_lane': 1900, 'lanes': 3}, {'vc_milli': 1931, 'delay_tenths': 130, 'los': 'F'}), ({'cycle': 120, 'green': 76, 'volume': 3230, 'sat_per_lane': 1700, 'lanes': 3}, {'vc_milli': 1000, 'delay_tenths': 220, 'los': 'C'}), ({'cycle': 100, 'green': 50, 'volume': 675, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 750, 'delay_tenths': 200, 'los': 'B'})], [({'cycle': 60, 'green': 40, 'volume': 800, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 666, 'delay_tenths': 60, 'los': 'A'}), ({'cycle': 120, 'green': 96, 'volume': 1520, 'sat_per_lane': 1900, 'lanes': 1}, {'vc_milli': 1000, 'delay_tenths': 120, 'los': 'B'}), ({'cycle': 100, 'green': 50, 'volume': 675, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 750, 'delay_tenths': 200, 'los': 'B'}), ({'cycle': 90, 'green': 30, 'volume': 700, 'sat_per_lane': 1800, 'lanes': 2}, {'vc_milli': 583, 'delay_tenths': 248, 'los': 'C'}), ({'cycle': 150, 'green': 24, 'volume': 868, 'sat_per_lane': 1800, 'lanes': 3}, {'vc_milli': 1004, 'delay_tenths': 630, 'los': 'F'}), ({'cycle': 120, 'green': 45, 'volume': 1425, 'sat_per_lane': 1900, 'lanes': 2}, {'vc_milli': 1000, 'delay_tenths': 375, 'los': 'D'}), ({'cycle': 100, 'green': 20, 'volume': 1080, 'sat_per_lane': 1800, 'lanes': 3}, {'vc_milli': 1000, 'delay_tenths': 400, 'los': 'D'}), ({'cycle': 140, 'green': 57, 'volume': 804, 'sat_per_lane': 1900, 'lanes': 1}, {'vc_milli': 1039, 'delay_tenths': 415, 'los': 'F'})], [({'cycle': 60, 'green': 40, 'volume': 800, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 666, 'delay_tenths': 60, 'los': 'A'}), ({'cycle': 140, 'green': 56, 'volume': 1477, 'sat_per_lane': 1700, 'lanes': 2}, {'vc_milli': 1086, 'delay_tenths': 420, 'los': 'F'}), ({'cycle': 120, 'green': 40, 'volume': 1300, 'sat_per_lane': 1900, 'lanes': 2}, {'vc_milli': 1026, 'delay_tenths': 400, 'los': 'F'}), ({'cycle': 100, 'green': 46, 'volume': 1656, 'sat_per_lane': 1800, 'lanes': 2}, {'vc_milli': 1000, 'delay_tenths': 270, 'los': 'C'}), ({'cycle': 90, 'green': 59, 'volume': 2360, 'sat_per_lane': 1800, 'lanes': 2}, {'vc_milli': 1000, 'delay_tenths': 155, 'los': 'B'}), ({'cycle': 130, 'green': 28, 'volume': 1476, 'sat_per_lane': 1700, 'lanes': 3}, {'vc_milli': 1343, 'delay_tenths': 510, 'los': 'F'}), ({'cycle': 100, 'green': 50, 'volume': 675, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 750, 'delay_tenths': 200, 'los': 'B'}), ({'cycle': 150, 'green': 119, 'volume': 2856, 'sat_per_lane': 1800, 'lanes': 2}, {'vc_milli': 1000, 'delay_tenths': 155, 'los': 'B'})], [({'cycle': 60, 'green': 40, 'volume': 800, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 666, 'delay_tenths': 60, 'los': 'A'}), ({'cycle': 140, 'green': 115, 'volume': 3804, 'sat_per_lane': 1700, 'lanes': 2}, {'vc_milli': 1362, 'delay_tenths': 125, 'los': 'F'}), ({'cycle': 150, 'green': 77, 'volume': 949, 'sat_per_lane': 1700, 'lanes': 1}, {'vc_milli': 1087, 'delay_tenths': 365, 'los': 'F'}), ({'cycle': 70, 'green': 34, 'volume': 1656, 'sat_per_lane': 1700, 'lanes': 2}, {'vc_milli': 1002, 'delay_tenths': 180, 'los': 'F'}), ({'cycle': 90, 'green': 30, 'volume': 700, 'sat_per_lane': 1800, 'lanes': 2}, {'vc_milli': 583, 'delay_tenths': 248, 'los': 'C'}), ({'cycle': 80, 'green': 20, 'volume': 1275, 'sat_per_lane': 1700, 'lanes': 3}, {'vc_milli': 1000, 'delay_tenths': 300, 'los': 'C'}), ({'cycle': 100, 'green': 75, 'volume': 1275, 'sat_per_lane': 1700, 'lanes': 1}, {'vc_milli': 1000, 'delay_tenths': 125, 'los': 'B'}), ({'cycle': 100, 'green': 50, 'volume': 900, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 1000, 'delay_tenths': 250, 'los': 'C'})]]
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:
Uniform delay level of service returns a wrong result when oversaturation is only flagged above X = 1.1.

Input {cycle, green, volume, sat_per_lane, lanes}. lam = green/cycle, capacity = sat*lanes*lam, X = volume/capacity, uniform delay d = 0.5*C*(1-lam)^2/(1 - min(1,X)*lam) rounded half up to tenths. LOS thresholds on tenths: <=100 A, <=200 B, <=350 C, <=550 D, <=800 E, else F; any X > 1 is F. Return {vc_milli: floor(1000X), delay_tenths, los}.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from fractions import Fraction
import math
N = 1
observations = []
def solve(x):
    C, g = x['cycle'], x['green']
    lam = Fraction(g, C)
    cap = x['sat_per_lane'] * x['lanes'] * lam
    X = Fraction(x['volume']) / cap
    d = Fraction(1, 2) * g * (1 - lam) ** 2 / (1 - min(1, X) * lam)
    tenths = int(d * 10 + Fraction(1, 2))
    if X > 1:
        los = 'F'
    else:
        los = 'F'
        for lim, lab in ((100, 'A'), (200, 'B'), (350, 'C'), (550, 'D'), (800, 'E')):
            if tenths <= lim:
                los = lab
                break
    return {'vc_milli': int(X * 1000), 'delay_tenths': tenths, 'los': los}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'cycle': 70, 'green': 12, 'volume': 699, 'sat_per_lane': 1800, 'lanes': 3}, {'vc_milli': 755, 'delay_tenths': 276, 'los': 'C'}), ({'cycle': 120, 'green': 40, 'volume': 1300, 'sat_per_lane': 1900, 'lanes': 2}, {'vc_milli': 1026, 'delay_tenths': 400, 'los': 'F'}), ({'cycle': 150, 'green': 114, 'volume': 899, 'sat_per_lane': 1800, 'lanes': 3}, {'vc_milli': 219, 'delay_tenths': 52, 'los': 'A'}), ({'cycle': 80, 'green': 23, 'volume': 720, 'sat_per_lane': 1700, 'lanes': 1}, {'vc_milli': 1473, 'delay_tenths': 285, 'los': 'F'}), ({'cycle': 110, 'green': 46, 'volume': 2980, 'sat_per_lane': 1900, 'lanes': 2}, {'vc_milli': 1875, 'delay_tenths': 320, 'los': 'F'}), ({'cycle': 100, 'green': 50, 'volume': 900, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 1000, 'delay_tenths': 250, 'los': 'C'}), ({'cycle': 60, 'green': 40, 'volume': 800, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 666, 'delay_tenths': 60, 'los': 'A'}), ({'cycle': 90, 'green': 61, 'volume': 5477, 'sat_per_lane': 1700, 'lanes': 3}, {'vc_milli': 1584, 'delay_tenths': 145, 'los': 'F'})], [({'cycle': 90, 'green': 30, 'volume': 700, 'sat_per_lane': 1800, 'lanes': 2}, {'vc_milli': 583, 'delay_tenths': 248, 'los': 'C'}), ({'cycle': 120, 'green': 46, 'volume': 1207, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 1749, 'delay_tenths': 370, 'los': 'F'}), ({'cycle': 100, 'green': 50, 'volume': 675, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 750, 'delay_tenths': 200, 'los': 'B'}), ({'cycle': 80, 'green': 15, 'volume': 1187, 'sat_per_lane': 1700, 'lanes': 2}, {'vc_milli': 1861, 'delay_tenths': 325, 'los': 'F'}), ({'cycle': 140, 'green': 10, 'volume': 336, 'sat_per_lane': 1900, 'lanes': 3}, {'vc_milli': 825, 'delay_tenths': 641, 'los': 'E'}), ({'cycle': 120, 'green': 40, 'volume': 1300, 'sat_per_lane': 1900, 'lanes': 2}, {'vc_milli': 1026, 'delay_tenths': 400, 'los': 'F'}), ({'cycle': 110, 'green': 75, 'volume': 901, 'sat_per_lane': 1900, 'lanes': 2}, {'vc_milli': 347, 'delay_tenths': 73, 'los': 'A'}), ({'cycle': 120, 'green': 37, 'volume': 252, 'sat_per_lane': 1700, 'lanes': 2}, {'vc_milli': 240, 'delay_tenths': 310, 'los': 'C'})], [({'cycle': 60, 'green': 40, 'volume': 800, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 666, 'delay_tenths': 60, 'los': 'A'}), ({'cycle': 120, 'green': 75, 'volume': 5585, 'sat_per_lane': 1900, 'lanes': 3}, {'vc_milli': 1567, 'delay_tenths': 225, 'los': 'F'}), ({'cycle': 90, 'green': 30, 'volume': 1900, 'sat_per_lane': 1900, 'lanes': 3}, {'vc_milli': 1000, 'delay_tenths': 300, 'los': 'C'}), ({'cycle': 130, 'green': 42, 'volume': 1194, 'sat_per_lane': 1900, 'lanes': 1}, {'vc_milli': 1945, 'delay_tenths': 440, 'los': 'F'}), ({'cycle': 90, 'green': 30, 'volume': 700, 'sat_per_lane': 1800, 'lanes': 2}, {'vc_milli': 583, 'delay_tenths': 248, 'los': 'C'}), ({'cycle': 100, 'green': 64, 'volume': 1391, 'sat_per_lane': 1700, 'lanes': 2}, {'vc_milli': 639, 'delay_tenths': 110, 'los': 'B'}), ({'cycle': 100, 'green': 50, 'volume': 900, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 1000, 'delay_tenths': 250, 'los': 'C'}), ({'cycle': 140, 'green': 12, 'volume': 214, 'sat_per_lane': 1700, 'lanes': 1}, {'vc_milli': 1468, 'delay_tenths': 640, 'los': 'F'})], [({'cycle': 90, 'green': 30, 'volume': 700, 'sat_per_lane': 1800, 'lanes': 2}, {'vc_milli': 583, 'delay_tenths': 248, 'los': 'C'}), ({'cycle': 60, 'green': 40, 'volume': 800, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 666, 'delay_tenths': 60, 'los': 'A'}), ({'cycle': 150, 'green': 69, 'volume': 1748, 'sat_per_lane': 1900, 'lanes': 2}, {'vc_milli': 1000, 'delay_tenths': 405, 'los': 'D'}), ({'cycle': 70, 'green': 44, 'volume': 4822, 'sat_per_lane': 1700, 'lanes': 3}, {'vc_milli': 1504, 'delay_tenths': 130, 'los': 'F'}), ({'cycle': 80, 'green': 17, 'volume': 262, 'sat_per_lane': 1900, 'lanes': 3}, {'vc_milli': 216, 'delay_tenths': 260, 'los': 'C'}), ({'cycle': 90, 'green': 58, 'volume': 1641, 'sat_per_lane': 1700, 'lanes': 2}, {'vc_milli': 748, 'delay_tenths': 110, 'los': 'B'}), ({'cycle': 90, 'green': 12, 'volume': 202, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 841, 'delay_tenths': 381, 'los': 'D'}), ({'cycle': 100, 'green': 50, 'volume': 675, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 750, 'delay_tenths': 200, 'los': 'B'})], [({'cycle': 110, 'green': 92, 'volume': 1602, 'sat_per_lane': 1900, 'lanes': 2}, {'vc_milli': 504, 'delay_tenths': 25, 'los': 'A'}), ({'cycle': 120, 'green': 40, 'volume': 1300, 'sat_per_lane': 1900, 'lanes': 2}, {'vc_milli': 1026, 'delay_tenths': 400, 'los': 'F'}), ({'cycle': 140, 'green': 122, 'volume': 538, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 342, 'delay_tenths': 17, 'los': 'A'}), ({'cycle': 60, 'green': 33, 'volume': 2805, 'sat_per_lane': 1700, 'lanes': 3}, {'vc_milli': 1000, 'delay_tenths': 135, 'los': 'B'}), ({'cycle': 60, 'green': 39, 'volume': 1335, 'sat_per_lane': 1700, 'lanes': 1}, {'vc_milli': 1208, 'delay_tenths': 105, 'los': 'F'}), ({'cycle': 130, 'green': 110, 'volume': 2282, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 1498, 'delay_tenths': 100, 'los': 'F'}), ({'cycle': 100, 'green': 50, 'volume': 675, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 750, 'delay_tenths': 200, 'los': 'B'}), ({'cycle': 90, 'green': 30, 'volume': 700, 'sat_per_lane': 1800, 'lanes': 2}, {'vc_milli': 583, 'delay_tenths': 248, 'los': 'C'})]]
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
from fractions import Fraction
import math
N = 1
observations = []
def solve(x):
    C, g = x['cycle'], x['green']
    lam = Fraction(g, C)
    cap = x['sat_per_lane'] * x['lanes'] * lam
    X = Fraction(x['volume']) / cap
    d = C * (1 - lam) ** 2 / (1 - min(1, X) * lam)
    tenths = int(d * 10 + Fraction(1, 2))
    if X > 1:
        los = 'F'
    else:
        los = 'F'
        for lim, lab in ((100, 'A'), (200, 'B'), (350, 'C'), (550, 'D'), (800, 'E')):
            if tenths <= lim:
                los = lab
                break
    return {'vc_milli': int(X * 1000), 'delay_tenths': tenths, 'los': los}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'cycle': 70, 'green': 12, 'volume': 699, 'sat_per_lane': 1800, 'lanes': 3}, {'vc_milli': 755, 'delay_tenths': 276, 'los': 'C'}), ({'cycle': 120, 'green': 40, 'volume': 1300, 'sat_per_lane': 1900, 'lanes': 2}, {'vc_milli': 1026, 'delay_tenths': 400, 'los': 'F'}), ({'cycle': 150, 'green': 114, 'volume': 899, 'sat_per_lane': 1800, 'lanes': 3}, {'vc_milli': 219, 'delay_tenths': 52, 'los': 'A'}), ({'cycle': 80, 'green': 23, 'volume': 720, 'sat_per_lane': 1700, 'lanes': 1}, {'vc_milli': 1473, 'delay_tenths': 285, 'los': 'F'}), ({'cycle': 110, 'green': 46, 'volume': 2980, 'sat_per_lane': 1900, 'lanes': 2}, {'vc_milli': 1875, 'delay_tenths': 320, 'los': 'F'}), ({'cycle': 100, 'green': 50, 'volume': 900, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 1000, 'delay_tenths': 250, 'los': 'C'}), ({'cycle': 60, 'green': 40, 'volume': 800, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 666, 'delay_tenths': 60, 'los': 'A'}), ({'cycle': 90, 'green': 61, 'volume': 5477, 'sat_per_lane': 1700, 'lanes': 3}, {'vc_milli': 1584, 'delay_tenths': 145, 'los': 'F'})], [({'cycle': 90, 'green': 30, 'volume': 700, 'sat_per_lane': 1800, 'lanes': 2}, {'vc_milli': 583, 'delay_tenths': 248, 'los': 'C'}), ({'cycle': 120, 'green': 46, 'volume': 1207, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 1749, 'delay_tenths': 370, 'los': 'F'}), ({'cycle': 100, 'green': 50, 'volume': 675, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 750, 'delay_tenths': 200, 'los': 'B'}), ({'cycle': 80, 'green': 15, 'volume': 1187, 'sat_per_lane': 1700, 'lanes': 2}, {'vc_milli': 1861, 'delay_tenths': 325, 'los': 'F'}), ({'cycle': 140, 'green': 10, 'volume': 336, 'sat_per_lane': 1900, 'lanes': 3}, {'vc_milli': 825, 'delay_tenths': 641, 'los': 'E'}), ({'cycle': 120, 'green': 40, 'volume': 1300, 'sat_per_lane': 1900, 'lanes': 2}, {'vc_milli': 1026, 'delay_tenths': 400, 'los': 'F'}), ({'cycle': 110, 'green': 75, 'volume': 901, 'sat_per_lane': 1900, 'lanes': 2}, {'vc_milli': 347, 'delay_tenths': 73, 'los': 'A'}), ({'cycle': 120, 'green': 37, 'volume': 252, 'sat_per_lane': 1700, 'lanes': 2}, {'vc_milli': 240, 'delay_tenths': 310, 'los': 'C'})], [({'cycle': 60, 'green': 40, 'volume': 800, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 666, 'delay_tenths': 60, 'los': 'A'}), ({'cycle': 120, 'green': 75, 'volume': 5585, 'sat_per_lane': 1900, 'lanes': 3}, {'vc_milli': 1567, 'delay_tenths': 225, 'los': 'F'}), ({'cycle': 90, 'green': 30, 'volume': 1900, 'sat_per_lane': 1900, 'lanes': 3}, {'vc_milli': 1000, 'delay_tenths': 300, 'los': 'C'}), ({'cycle': 130, 'green': 42, 'volume': 1194, 'sat_per_lane': 1900, 'lanes': 1}, {'vc_milli': 1945, 'delay_tenths': 440, 'los': 'F'}), ({'cycle': 90, 'green': 30, 'volume': 700, 'sat_per_lane': 1800, 'lanes': 2}, {'vc_milli': 583, 'delay_tenths': 248, 'los': 'C'}), ({'cycle': 100, 'green': 64, 'volume': 1391, 'sat_per_lane': 1700, 'lanes': 2}, {'vc_milli': 639, 'delay_tenths': 110, 'los': 'B'}), ({'cycle': 100, 'green': 50, 'volume': 900, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 1000, 'delay_tenths': 250, 'los': 'C'}), ({'cycle': 140, 'green': 12, 'volume': 214, 'sat_per_lane': 1700, 'lanes': 1}, {'vc_milli': 1468, 'delay_tenths': 640, 'los': 'F'})], [({'cycle': 90, 'green': 30, 'volume': 700, 'sat_per_lane': 1800, 'lanes': 2}, {'vc_milli': 583, 'delay_tenths': 248, 'los': 'C'}), ({'cycle': 60, 'green': 40, 'volume': 800, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 666, 'delay_tenths': 60, 'los': 'A'}), ({'cycle': 150, 'green': 69, 'volume': 1748, 'sat_per_lane': 1900, 'lanes': 2}, {'vc_milli': 1000, 'delay_tenths': 405, 'los': 'D'}), ({'cycle': 70, 'green': 44, 'volume': 4822, 'sat_per_lane': 1700, 'lanes': 3}, {'vc_milli': 1504, 'delay_tenths': 130, 'los': 'F'}), ({'cycle': 80, 'green': 17, 'volume': 262, 'sat_per_lane': 1900, 'lanes': 3}, {'vc_milli': 216, 'delay_tenths': 260, 'los': 'C'}), ({'cycle': 90, 'green': 58, 'volume': 1641, 'sat_per_lane': 1700, 'lanes': 2}, {'vc_milli': 748, 'delay_tenths': 110, 'los': 'B'}), ({'cycle': 90, 'green': 12, 'volume': 202, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 841, 'delay_tenths': 381, 'los': 'D'}), ({'cycle': 100, 'green': 50, 'volume': 675, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 750, 'delay_tenths': 200, 'los': 'B'})], [({'cycle': 110, 'green': 92, 'volume': 1602, 'sat_per_lane': 1900, 'lanes': 2}, {'vc_milli': 504, 'delay_tenths': 25, 'los': 'A'}), ({'cycle': 120, 'green': 40, 'volume': 1300, 'sat_per_lane': 1900, 'lanes': 2}, {'vc_milli': 1026, 'delay_tenths': 400, 'los': 'F'}), ({'cycle': 140, 'green': 122, 'volume': 538, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 342, 'delay_tenths': 17, 'los': 'A'}), ({'cycle': 60, 'green': 33, 'volume': 2805, 'sat_per_lane': 1700, 'lanes': 3}, {'vc_milli': 1000, 'delay_tenths': 135, 'los': 'B'}), ({'cycle': 60, 'green': 39, 'volume': 1335, 'sat_per_lane': 1700, 'lanes': 1}, {'vc_milli': 1208, 'delay_tenths': 105, 'los': 'F'}), ({'cycle': 130, 'green': 110, 'volume': 2282, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 1498, 'delay_tenths': 100, 'los': 'F'}), ({'cycle': 100, 'green': 50, 'volume': 675, 'sat_per_lane': 1800, 'lanes': 1}, {'vc_milli': 750, 'delay_tenths': 200, 'los': 'B'}), ({'cycle': 90, 'green': 30, 'volume': 700, 'sat_per_lane': 1800, 'lanes': 2}, {'vc_milli': 583, 'delay_tenths': 248, 'los': 'C'})]]
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:
Uniform delay level of service returns a wrong result when the uniform delay uses green instead of cycle.

Input {cycle, green, volume, sat_per_lane, lanes}. lam = green/cycle, capacity = sat*lanes*lam, X = volume/capacity, uniform delay d = 0.5*C*(1-lam)^2/(1 - min(1,X)*lam) rounded half up to tenths. LOS thresholds on tenths: <=100 A, <=200 B, <=350 C, <=550 D, <=800 E, else F; any X > 1 is F. Return {vc_milli: floor(1000X), delay_tenths, los}.

split: open-access


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 st == 'green' 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['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': 'green', 'elapsed': 2, 'min_green': 16, 'preempt_min_green': 8, 'yellow': 6, 'red': 2, 'fdw': 11, 'ped': 'fdw', 'ped_elapsed': 4, 'ped_truncate': False, 'track_current': False}, [15, 7]), ({'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': 3, 'min_green': 8, 'preempt_min_green': 4, 'yellow': 6, 'red': 2, 'fdw': 21, 'ped': 'none', 'ped_elapsed': 19, 'ped_truncate': True, 'track_current': True}, [0, 0]), ({'state': 'green', 'elapsed': 19, 'min_green': 19, 'preempt_min_green': 7, 'yellow': 6, 'red': 2, 'fdw': 21, 'ped': 'none', 'ped_elapsed': 11, 'ped_truncate': True, 'track_current': False}, [8, 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': 14, 'min_green': 17, 'preempt_min_green': 4, 'yellow': 3, 'red': 3, 'fdw': 22, 'ped': 'walk', 'ped_elapsed': 10, 'ped_truncate': True, 'track_current': False}, [6, 0]), ({'state': 'yellow', 'elapsed': 2, 'min_green': 12, 'preempt_min_green': 4, 'yellow': 3, 'red': 1, 'fdw': 20, 'ped': 'none', 'ped_elapsed': 15, 'ped_truncate': True, 'track_current': False}, [2, 0]), ({'state': 'red', 'elapsed': 11, 'min_green': 9, 'preempt_min_green': 4, 'yellow': 4, 'red': 3, 'fdw': 11, 'ped': 'none', 'ped_elapsed': 6, 'ped_truncate': False, 'track_current': False}, [0, 0])], [({'state': 'green', 'elapsed': 16, 'min_green': 16, 'preempt_min_green': 7, 'yellow': 3, 'red': 2, 'fdw': 25, 'ped': 'walk', 'ped_elapsed': 12, 'ped_truncate': False, 'track_current': False}, [30, 25]), ({'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': 'yellow', 'elapsed': 6, 'min_green': 10, 'preempt_min_green': 2, 'yellow': 6, 'red': 3, 'fdw': 18, 'ped': 'none', 'ped_elapsed': 11, 'ped_truncate': True, 'track_current': False}, [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': 7, 'min_green': 13, 'preempt_min_green': 3, 'yellow': 4, 'red': 1, 'fdw': 17, 'ped': 'walk', 'ped_elapsed': 11, 'ped_truncate': True, 'track_current': False}, [5, 0]), ({'state': 'green', 'elapsed': 14, 'min_green': 19, 'preempt_min_green': 9, 'yellow': 5, 'red': 1, 'fdw': 16, 'ped': 'walk', 'ped_elapsed': 10, 'ped_truncate': False, 'track_current': False}, [22, 16]), ({'state': 'green', 'elapsed': 0, 'min_green': 12, 'preempt_min_green': 3, 'yellow': 5, 'red': 2, 'fdw': 21, 'ped': 'fdw', 'ped_elapsed': 12, 'ped_truncate': False, 'track_current': False}, [16, 9]), ({'state': 'green', 'elapsed': 19, 'min_green': 12, 'preempt_min_green': 3, 'yellow': 4, 'red': 2, 'fdw': 25, 'ped': 'walk', 'ped_elapsed': 11, 'ped_truncate': True, 'track_current': False}, [6, 0])], [({'state': 'green', 'elapsed': 14, 'min_green': 10, 'preempt_min_green': 9, 'yellow': 4, 'red': 2, 'fdw': 16, 'ped': 'fdw', 'ped_elapsed': 16, 'ped_truncate': True, 'track_current': False}, [6, 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': 'red', 'elapsed': 18, 'min_green': 20, 'preempt_min_green': 3, 'yellow': 5, 'red': 3, 'fdw': 17, 'ped': 'none', 'ped_elapsed': 13, 'ped_truncate': True, 'track_current': False}, [0, 0]), ({'state': 'red', 'elapsed': 14, 'min_green': 20, 'preempt_min_green': 5, 'yellow': 6, 'red': 3, 'fdw': 23, 'ped': 'none', 'ped_elapsed': 0, 'ped_truncate': False, 'track_current': False}, [0, 0]), ({'state': 'green', 'elapsed': 6, 'min_green': 19, 'preempt_min_green': 5, 'yellow': 3, 'red': 1, 'fdw': 14, 'ped': 'walk', 'ped_elapsed': 0, 'ped_truncate': True, 'track_current': False}, [4, 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': 9, 'min_green': 18, 'preempt_min_green': 9, 'yellow': 4, 'red': 2, 'fdw': 13, 'ped': 'none', 'ped_elapsed': 12, 'ped_truncate': False, 'track_current': False}, [6, 0]), ({'state': 'yellow', 'elapsed': 16, 'min_green': 16, 'preempt_min_green': 10, 'yellow': 4, 'red': 3, 'fdw': 10, 'ped': 'none', 'ped_elapsed': 19, 'ped_truncate': False, 'track_current': False}, [3, 0])], [({'state': 'green', 'elapsed': 7, 'min_green': 16, 'preempt_min_green': 4, 'yellow': 6, 'red': 3, 'fdw': 10, 'ped': 'walk', 'ped_elapsed': 17, 'ped_truncate': False, 'track_current': True}, [0, 0]), ({'state': 'green', 'elapsed': 3, 'min_green': 16, 'preempt_min_green': 8, 'yellow': 3, 'red': 3, 'fdw': 11, 'ped': 'fdw', 'ped_elapsed': 17, 'ped_truncate': True, 'track_current': True}, [0, 0]), ({'state': 'red', 'elapsed': 11, 'min_green': 13, 'preempt_min_green': 2, 'yellow': 3, 'red': 1, 'fdw': 11, 'ped': 'none', 'ped_elapsed': 4, 'ped_truncate': True, 'track_current': True}, [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': 17, 'preempt_min_green': 7, 'yellow': 6, 'red': 3, 'fdw': 21, 'ped': 'none', 'ped_elapsed': 10, 'ped_truncate': False, 'track_current': False}, [9, 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': 20, 'preempt_min_green': 9, 'yellow': 5, 'red': 1, 'fdw': 15, 'ped': 'walk', 'ped_elapsed': 4, 'ped_truncate': True, 'track_current': False}, [6, 0]), ({'state': 'green', 'elapsed': 20, 'min_green': 11, 'preempt_min_green': 9, 'yellow': 5, 'red': 2, 'fdw': 12, 'ped': 'none', 'ped_elapsed': 14, 'ped_truncate': False, 'track_current': True}, [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': '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': 12, 'min_green': 12, 'preempt_min_green': 3, 'yellow': 4, 'red': 1, 'fdw': 25, 'ped': 'none', 'ped_elapsed': 19, 'ped_truncate': True, 'track_current': False}, [1, 0]), ({'state': 'green', 'elapsed': 19, 'min_green': 9, 'preempt_min_green': 8, 'yellow': 3, 'red': 1, 'fdw': 24, 'ped': 'fdw', 'ped_elapsed': 4, 'ped_truncate': True, 'track_current': False}, [4, 0]), ({'state': 'green', 'elapsed': 10, 'min_green': 11, 'preempt_min_green': 9, 'yellow': 4, 'red': 1, 'fdw': 14, 'ped': 'walk', 'ped_elapsed': 10, 'ped_truncate': False, 'track_current': False}, [19, 14]), ({'state': 'yellow', 'elapsed': 13, 'min_green': 15, 'preempt_min_green': 2, 'yellow': 3, 'red': 1, 'fdw': 19, 'ped': 'none', 'ped_elapsed': 19, 'ped_truncate': True, 'track_current': True}, [1, 0]), ({'state': 'green', 'elapsed': 6, 'min_green': 14, 'preempt_min_green': 9, 'yellow': 5, 'red': 3, 'fdw': 9, 'ped': 'fdw', 'ped_elapsed': 7, 'ped_truncate': False, 'track_current': False}, [11, 3]), ({'state': 'green', 'elapsed': 0, 'min_green': 12, 'preempt_min_green': 4, 'yellow': 4, 'red': 2, 'fdw': 8, 'ped': 'fdw', 'ped_elapsed': 20, 'ped_truncate': True, 'track_current': False}, [10, 4])]]
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 == 'green' 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']))
    return [hold + y + r, hold]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[({'state': 'green', 'elapsed': 2, 'min_green': 16, 'preempt_min_green': 8, 'yellow': 6, 'red': 2, 'fdw': 11, 'ped': 'fdw', 'ped_elapsed': 4, 'ped_truncate': False, 'track_current': False}, [15, 7]), ({'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': 3, 'min_green': 8, 'preempt_min_green': 4, 'yellow': 6, 'red': 2, 'fdw': 21, 'ped': 'none', 'ped_elapsed': 19, 'ped_truncate': True, 'track_current': True}, [0, 0]), ({'state': 'green', 'elapsed': 19, 'min_green': 19, 'preempt_min_green': 7, 'yellow': 6, 'red': 2, 'fdw': 21, 'ped': 'none', 'ped_elapsed': 11, 'ped_truncate': True, 'track_current': False}, [8, 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': 14, 'min_green': 17, 'preempt_min_green': 4, 'yellow': 3, 'red': 3, 'fdw': 22, 'ped': 'walk', 'ped_elapsed': 10, 'ped_truncate': True, 'track_current': False}, [6, 0]), ({'state': 'yellow', 'elapsed': 2, 'min_green': 12, 'preempt_min_green': 4, 'yellow': 3, 'red': 1, 'fdw': 20, 'ped': 'none', 'ped_elapsed': 15, 'ped_truncate': True, 'track_current': False}, [2, 0]), ({'state': 'red', 'elapsed': 11, 'min_green': 9, 'preempt_min_green': 4, 'yellow': 4, 'red': 3, 'fdw': 11, 'ped': 'none', 'ped_elapsed': 6, 'ped_truncate': False, 'track_current': False}, [0, 0])], [({'state': 'green', 'elapsed': 16, 'min_green': 16, 'preempt_min_green': 7, 'yellow': 3, 'red': 2, 'fdw': 25, 'ped': 'walk', 'ped_elapsed': 12, 'ped_truncate': False, 'track_current': False}, [30, 25]), ({'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': 'yellow', 'elapsed': 6, 'min_green': 10, 'preempt_min_green': 2, 'yellow': 6, 'red': 3, 'fdw': 18, 'ped': 'none', 'ped_elapsed': 11, 'ped_truncate': True, 'track_current': False}, [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': 7, 'min_green': 13, 'preempt_min_green': 3, 'yellow': 4, 'red': 1, 'fdw': 17, 'ped': 'walk', 'ped_elapsed': 11, 'ped_truncate': True, 'track_current': False}, [5, 0]), ({'state': 'green', 'elapsed': 14, 'min_green': 19, 'preempt_min_green': 9, 'yellow': 5, 'red': 1, 'fdw': 16, 'ped': 'walk', 'ped_elapsed': 10, 'ped_truncate': False, 'track_current': False}, [22, 16]), ({'state': 'green', 'elapsed': 0, 'min_green': 12, 'preempt_min_green': 3, 'yellow': 5, 'red': 2, 'fdw': 21, 'ped': 'fdw', 'ped_elapsed': 12, 'ped_truncate': False, 'track_current': False}, [16, 9]), ({'state': 'green', 'elapsed': 19, 'min_green': 12, 'preempt_min_green': 3, 'yellow': 4, 'red': 2, 'fdw': 25, 'ped': 'walk', 'ped_elapsed': 11, 'ped_truncate': True, 'track_current': False}, [6, 0])], [({'state': 'green', 'elapsed': 14, 'min_green': 10, 'preempt_min_green': 9, 'yellow': 4, 'red': 2, 'fdw': 16, 'ped': 'fdw', 'ped_elapsed': 16, 'ped_truncate': True, 'track_current': False}, [6, 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': 'red', 'elapsed': 18, 'min_green': 20, 'preempt_min_green': 3, 'yellow': 5, 'red': 3, 'fdw': 17, 'ped': 'none', 'ped_elapsed': 13, 'ped_truncate': True, 'track_current': False}, [0, 0]), ({'state': 'red', 'elapsed': 14, 'min_green': 20, 'preempt_min_green': 5, 'yellow': 6, 'red': 3, 'fdw': 23, 'ped': 'none', 'ped_elapsed': 0, 'ped_truncate': False, 'track_current': False}, [0, 0]), ({'state': 'green', 'elapsed': 6, 'min_green': 19, 'preempt_min_green': 5, 'yellow': 3, 'red': 1, 'fdw': 14, 'ped': 'walk', 'ped_elapsed': 0, 'ped_truncate': True, 'track_current': False}, [4, 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': 9, 'min_green': 18, 'preempt_min_green': 9, 'yellow': 4, 'red': 2, 'fdw': 13, 'ped': 'none', 'ped_elapsed': 12, 'ped_truncate': False, 'track_current': False}, [6, 0]), ({'state': 'yellow', 'elapsed': 16, 'min_green': 16, 'preempt_min_green': 10, 'yellow': 4, 'red': 3, 'fdw': 10, 'ped': 'none', 'ped_elapsed': 19, 'ped_truncate': False, 'track_current': False}, [3, 0])], [({'state': 'green', 'elapsed': 7, 'min_green': 16, 'preempt_min_green': 4, 'yellow': 6, 'red': 3, 'fdw': 10, 'ped': 'walk', 'ped_elapsed': 17, 'ped_truncate': False, 'track_current': True}, [0, 0]), ({'state': 'green', 'elapsed': 3, 'min_green': 16, 'preempt_min_green': 8, 'yellow': 3, 'red': 3, 'fdw': 11, 'ped': 'fdw', 'ped_elapsed': 17, 'ped_truncate': True, 'track_current': True}, [0, 0]), ({'state': 'red', 'elapsed': 11, 'min_green': 13, 'preempt_min_green': 2, 'yellow': 3, 'red': 1, 'fdw': 11, 'ped': 'none', 'ped_elapsed': 4, 'ped_truncate': True, 'track_current': True}, [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': 17, 'preempt_min_green': 7, 'yellow': 6, 'red': 3, 'fdw': 21, 'ped': 'none', 'ped_elapsed': 10, 'ped_truncate': False, 'track_current': False}, [9, 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': 20, 'preempt_min_green': 9, 'yellow': 5, 'red': 1, 'fdw': 15, 'ped': 'walk', 'ped_elapsed': 4, 'ped_truncate': True, 'track_current': False}, [6, 0]), ({'state': 'green', 'elapsed': 20, 'min_green': 11, 'preempt_min_green': 9, 'yellow': 5, 'red': 2, 'fdw': 12, 'ped': 'none', 'ped_elapsed': 14, 'ped_truncate': False, 'track_current': True}, [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': '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': 12, 'min_green': 12, 'preempt_min_green': 3, 'yellow': 4, 'red': 1, 'fdw': 25, 'ped': 'none', 'ped_elapsed': 19, 'ped_truncate': True, 'track_current': False}, [1, 0]), ({'state': 'green', 'elapsed': 19, 'min_green': 9, 'preempt_min_green': 8, 'yellow': 3, 'red': 1, 'fdw': 24, 'ped': 'fdw', 'ped_elapsed': 4, 'ped_truncate': True, 'track_current': False}, [4, 0]), ({'state': 'green', 'elapsed': 10, 'min_green': 11, 'preempt_min_green': 9, 'yellow': 4, 'red': 1, 'fdw': 14, 'ped': 'walk', 'ped_elapsed': 10, 'ped_truncate': False, 'track_current': False}, [19, 14]), ({'state': 'yellow', 'elapsed': 13, 'min_green': 15, 'preempt_min_green': 2, 'yellow': 3, 'red': 1, 'fdw': 19, 'ped': 'none', 'ped_elapsed': 19, 'ped_truncate': True, 'track_current': True}, [1, 0]), ({'state': 'green', 'elapsed': 6, 'min_green': 14, 'preempt_min_green': 9, 'yellow': 5, 'red': 3, 'fdw': 9, 'ped': 'fdw', 'ped_elapsed': 7, 'ped_truncate': False, 'track_current': False}, [11, 3]), ({'state': 'green', 'elapsed': 0, 'min_green': 12, 'preempt_min_green': 4, 'yellow': 4, 'red': 2, 'fdw': 8, 'ped': 'fdw', 'ped_elapsed': 20, 'ped_truncate': True, 'track_current': False}, [10, 4])]]
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 the normal minimum green is honoured during preemption entry.

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