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

N = 1
observations = []
def solve(x):
    cars = list(x['cars'])
    order = sorted(cars, key=lambda c: (c['load'] == 0, c['floor'], c['id']))
    t = 0
    starts = {}
    for c in order:
        starts[c['id']] = t
        t += c['floor'] * x['per_floor_s'] + x['door_s']
    pre = x['preselect']
    sel = pre if pre in starts else (order[0]['id'] if order else None)
    return {'order': [c['id'] for c in order], 'starts': starts, 'selected': sel, 'done_s': t}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: out of service car preselected', {'cars': [{'id': 'P1', 'floor': 5, 'load': 0, 'oos': True}, {'id': 'P2', 'floor': 3, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P1'}, {'order': ['P2'], 'starts': {'P2': 0}, 'selected': 'P2', 'done_s': 11}), ('sampled regression 4', {'cars': [{'id': 'P4', 'floor': 5, 'load': 0, 'oos': False}, {'id': 'P1', 'floor': 11, 'load': 0, 'oos': True}, {'id': 'P2', 'floor': 4, 'load': 300, 'oos': False}], 'per_floor_s': 3, 'door_s': 8, 'preselect': None}, {'order': ['P2', 'P4'], 'starts': {'P2': 0, 'P4': 20}, 'selected': 'P2', 'done_s': 43}), ('regression: all cars out of service', {'cars': [{'id': 'P1', 'floor': 3, 'load': 0, 'oos': True}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P1'}, {'order': [], 'starts': {}, 'selected': None, 'done_s': 0}), ('boundary: occupied car first', {'cars': [{'id': 'P1', 'floor': 2, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 9, 'load': 80, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P2', 'P1'], 'starts': {'P2': 0, 'P1': 23}, 'selected': 'P2', 'done_s': 32}), ('boundary: lobby car still takes door time', {'cars': [{'id': 'P1', 'floor': 0, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 4, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P1', 'P2'], 'starts': {'P1': 0, 'P2': 5}, 'selected': 'P1', 'done_s': 18}), ('control 1', {'cars': [{'id': 'P4', 'floor': 4, 'load': 75, 'oos': False}, {'id': 'P1', 'floor': 13, 'load': 300, 'oos': False}], 'per_floor_s': 2, 'door_s': 8, 'preselect': 'P1'}, {'order': ['P4', 'P1'], 'starts': {'P4': 0, 'P1': 16}, 'selected': 'P1', 'done_s': 50}), ('sampled regression 7', {'cars': [{'id': 'P1', 'floor': 9, 'load': 300, 'oos': True}, {'id': 'P4', 'floor': 19, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P3'}, {'order': ['P4'], 'starts': {'P4': 0}, 'selected': 'P4', 'done_s': 43}), ('sampled regression 10', {'cars': [{'id': 'P3', 'floor': 2, 'load': 300, 'oos': False}, {'id': 'P1', 'floor': 3, 'load': 0, 'oos': True}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P2'}, {'order': ['P3'], 'starts': {'P3': 0}, 'selected': 'P3', 'done_s': 9})], [('regression: all cars out of service', {'cars': [{'id': 'P1', 'floor': 3, 'load': 0, 'oos': True}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P1'}, {'order': [], 'starts': {}, 'selected': None, 'done_s': 0}), ('sampled regression 15', {'cars': [{'id': 'P2', 'floor': 14, 'load': 0, 'oos': False}, {'id': 'P3', 'floor': 19, 'load': 75, 'oos': True}], 'per_floor_s': 2, 'door_s': 8, 'preselect': None}, {'order': ['P2'], 'starts': {'P2': 0}, 'selected': 'P2', 'done_s': 36}), ('sampled regression 42', {'cars': [{'id': 'P4', 'floor': 11, 'load': 0, 'oos': False}, {'id': 'P3', 'floor': 11, 'load': 300, 'oos': False}, {'id': 'P2', 'floor': 15, 'load': 0, 'oos': True}, {'id': 'P1', 'floor': 0, 'load': 0, 'oos': False}], 'per_floor_s': 3, 'door_s': 8, 'preselect': 'P2'}, {'order': ['P3', 'P1', 'P4'], 'starts': {'P3': 0, 'P1': 41, 'P4': 49}, 'selected': 'P3', 'done_s': 90}), ('boundary: lobby car still takes door time', {'cars': [{'id': 'P1', 'floor': 0, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 4, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P1', 'P2'], 'starts': {'P1': 0, 'P2': 5}, 'selected': 'P1', 'done_s': 18}), ('boundary: no preselection', {'cars': [{'id': 'P3', 'floor': 6, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 6, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P2', 'P3'], 'starts': {'P2': 0, 'P3': 17}, 'selected': 'P2', 'done_s': 34}), ('sampled regression 12', {'cars': [{'id': 'P2', 'floor': 9, 'load': 0, 'oos': False}, {'id': 'P4', 'floor': 12, 'load': 0, 'oos': True}], 'per_floor_s': 2, 'door_s': 8, 'preselect': 'P2'}, {'order': ['P2'], 'starts': {'P2': 0}, 'selected': 'P2', 'done_s': 26}), ('control 18', {'cars': [{'id': 'P3', 'floor': 7, 'load': 0, 'oos': False}, {'id': 'P4', 'floor': 10, 'load': 300, 'oos': False}, {'id': 'P2', 'floor': 12, 'load': 300, 'oos': False}], 'per_floor_s': 2, 'door_s': 8, 'preselect': 'P2'}, {'order': ['P4', 'P2', 'P3'], 'starts': {'P4': 0, 'P2': 28, 'P3': 60}, 'selected': 'P2', 'done_s': 82}), ('sampled regression 21', {'cars': [{'id': 'P1', 'floor': 13, 'load': 0, 'oos': False}, {'id': 'P4', 'floor': 3, 'load': 75, 'oos': False}, {'id': 'P2', 'floor': 8, 'load': 0, 'oos': True}], 'per_floor_s': 2, 'door_s': 8, 'preselect': 'P4'}, {'order': ['P4', 'P1'], 'starts': {'P4': 0, 'P1': 14}, 'selected': 'P4', 'done_s': 48})], [('regression: out of service car preselected', {'cars': [{'id': 'P1', 'floor': 5, 'load': 0, 'oos': True}, {'id': 'P2', 'floor': 3, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P1'}, {'order': ['P2'], 'starts': {'P2': 0}, 'selected': 'P2', 'done_s': 11}), ('sampled regression 36', {'cars': [{'id': 'P4', 'floor': 11, 'load': 75, 'oos': False}, {'id': 'P2', 'floor': 5, 'load': 75, 'oos': True}, {'id': 'P3', 'floor': 0, 'load': 300, 'oos': True}], 'per_floor_s': 2, 'door_s': 8, 'preselect': 'P4'}, {'order': ['P4'], 'starts': {'P4': 0}, 'selected': 'P4', 'done_s': 30}), ('regression: all cars out of service', {'cars': [{'id': 'P1', 'floor': 3, 'load': 0, 'oos': True}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P1'}, {'order': [], 'starts': {}, 'selected': None, 'done_s': 0}), ('boundary: occupied car first', {'cars': [{'id': 'P1', 'floor': 2, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 9, 'load': 80, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P2', 'P1'], 'starts': {'P2': 0, 'P1': 23}, 'selected': 'P2', 'done_s': 32}), ('boundary: lobby car still takes door time', {'cars': [{'id': 'P1', 'floor': 0, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 4, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P1', 'P2'], 'starts': {'P1': 0, 'P2': 5}, 'selected': 'P1', 'done_s': 18}), ('control 23', {'cars': [{'id': 'P4', 'floor': 10, 'load': 0, 'oos': False}, {'id': 'P1', 'floor': 9, 'load': 75, 'oos': False}, {'id': 'P3', 'floor': 19, 'load': 75, 'oos': False}], 'per_floor_s': 3, 'door_s': 8, 'preselect': 'P3'}, {'order': ['P1', 'P3', 'P4'], 'starts': {'P1': 0, 'P3': 35, 'P4': 100}, 'selected': 'P3', 'done_s': 138}), ('control 26', {'cars': [{'id': 'P2', 'floor': 14, 'load': 300, 'oos': False}, {'id': 'P3', 'floor': 14, 'load': 75, 'oos': False}, {'id': 'P1', 'floor': 3, 'load': 0, 'oos': False}, {'id': 'P4', 'floor': 15, 'load': 75, 'oos': False}], 'per_floor_s': 3, 'door_s': 8, 'preselect': 'P4'}, {'order': ['P2', 'P3', 'P4', 'P1'], 'starts': {'P2': 0, 'P3': 50, 'P4': 100, 'P1': 153}, 'selected': 'P4', 'done_s': 170}), ('control 29', {'cars': [{'id': 'P2', 'floor': 7, 'load': 75, 'oos': False}], 'per_floor_s': 3, 'door_s': 5, 'preselect': 'P1'}, {'order': ['P2'], 'starts': {'P2': 0}, 'selected': 'P2', 'done_s': 26})], [('regression: all cars out of service', {'cars': [{'id': 'P1', 'floor': 3, 'load': 0, 'oos': True}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P1'}, {'order': [], 'starts': {}, 'selected': None, 'done_s': 0}), ('sampled regression 49', {'cars': [{'id': 'P4', 'floor': 2, 'load': 0, 'oos': True}, {'id': 'P1', 'floor': 19, 'load': 300, 'oos': True}, {'id': 'P2', 'floor': 7, 'load': 0, 'oos': True}, {'id': 'P3', 'floor': 16, 'load': 300, 'oos': False}], 'per_floor_s': 3, 'door_s': 8, 'preselect': 'P4'}, {'order': ['P3'], 'starts': {'P3': 0}, 'selected': 'P3', 'done_s': 56}), ('sampled regression 42', {'cars': [{'id': 'P4', 'floor': 11, 'load': 0, 'oos': False}, {'id': 'P3', 'floor': 11, 'load': 300, 'oos': False}, {'id': 'P2', 'floor': 15, 'load': 0, 'oos': True}, {'id': 'P1', 'floor': 0, 'load': 0, 'oos': False}], 'per_floor_s': 3, 'door_s': 8, 'preselect': 'P2'}, {'order': ['P3', 'P1', 'P4'], 'starts': {'P3': 0, 'P1': 41, 'P4': 49}, 'selected': 'P3', 'done_s': 90}), ('boundary: occupied car first', {'cars': [{'id': 'P1', 'floor': 2, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 9, 'load': 80, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P2', 'P1'], 'starts': {'P2': 0, 'P1': 23}, 'selected': 'P2', 'done_s': 32}), ('boundary: lobby car still takes door time', {'cars': [{'id': 'P1', 'floor': 0, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 4, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P1', 'P2'], 'starts': {'P1': 0, 'P2': 5}, 'selected': 'P1', 'done_s': 18}), ('control 34', {'cars': [{'id': 'P2', 'floor': 4, 'load': 300, 'oos': False}], 'per_floor_s': 2, 'door_s': 8, 'preselect': 'P2'}, {'order': ['P2'], 'starts': {'P2': 0}, 'selected': 'P2', 'done_s': 16}), ('control 37', {'cars': [{'id': 'P3', 'floor': 6, 'load': 75, 'oos': False}, {'id': 'P4', 'floor': 14, 'load': 75, 'oos': False}], 'per_floor_s': 3, 'door_s': 8, 'preselect': 'P2'}, {'order': ['P3', 'P4'], 'starts': {'P3': 0, 'P4': 26}, 'selected': 'P3', 'done_s': 76}), ('control 40', {'cars': [{'id': 'P4', 'floor': 16, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 5, 'load': 0, 'oos': False}, {'id': 'P1', 'floor': 1, 'load': 75, 'oos': False}, {'id': 'P3', 'floor': 11, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P3'}, {'order': ['P1', 'P2', 'P3', 'P4'], 'starts': {'P1': 0, 'P2': 7, 'P3': 22, 'P4': 49}, 'selected': 'P3', 'done_s': 86})], [('regression: out of service car preselected', {'cars': [{'id': 'P1', 'floor': 5, 'load': 0, 'oos': True}, {'id': 'P2', 'floor': 3, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P1'}, {'order': ['P2'], 'starts': {'P2': 0}, 'selected': 'P2', 'done_s': 11}), ('sampled regression 61', {'cars': [{'id': 'P2', 'floor': 2, 'load': 300, 'oos': True}, {'id': 'P4', 'floor': 16, 'load': 75, 'oos': False}, {'id': 'P1', 'floor': 14, 'load': 300, 'oos': False}, {'id': 'P3', 'floor': 18, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 8, 'preselect': 'P3'}, {'order': ['P1', 'P4', 'P3'], 'starts': {'P1': 0, 'P4': 36, 'P3': 76}, 'selected': 'P3', 'done_s': 120}), ('regression: all cars out of service', {'cars': [{'id': 'P1', 'floor': 3, 'load': 0, 'oos': True}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P1'}, {'order': [], 'starts': {}, 'selected': None, 'done_s': 0}), ('boundary: no preselection', {'cars': [{'id': 'P3', 'floor': 6, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 6, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P2', 'P3'], 'starts': {'P2': 0, 'P3': 17}, 'selected': 'P2', 'done_s': 34}), ('boundary: occupied car first', {'cars': [{'id': 'P1', 'floor': 2, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 9, 'load': 80, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P2', 'P1'], 'starts': {'P2': 0, 'P1': 23}, 'selected': 'P2', 'done_s': 32}), ('control 45', {'cars': [{'id': 'P3', 'floor': 13, 'load': 75, 'oos': False}, {'id': 'P1', 'floor': 19, 'load': 0, 'oos': False}, {'id': 'P4', 'floor': 5, 'load': 0, 'oos': False}], 'per_floor_s': 3, 'door_s': 8, 'preselect': None}, {'order': ['P3', 'P4', 'P1'], 'starts': {'P3': 0, 'P4': 47, 'P1': 70}, 'selected': 'P3', 'done_s': 135}), ('sampled regression 48', {'cars': [{'id': 'P1', 'floor': 2, 'load': 75, 'oos': True}, {'id': 'P2', 'floor': 16, 'load': 300, 'oos': False}, {'id': 'P4', 'floor': 0, 'load': 0, 'oos': False}], 'per_floor_s': 3, 'door_s': 8, 'preselect': None}, {'order': ['P2', 'P4'], 'starts': {'P2': 0, 'P4': 56}, 'selected': 'P2', 'done_s': 64}), ('control 51', {'cars': [{'id': 'P1', 'floor': 2, 'load': 75, 'oos': False}, {'id': 'P4', 'floor': 4, 'load': 0, 'oos': False}, {'id': 'P3', 'floor': 16, 'load': 300, 'oos': False}, {'id': 'P2', 'floor': 4, 'load': 300, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P4'}, {'order': ['P1', 'P2', 'P3', 'P4'], 'starts': {'P1': 0, 'P2': 9, 'P3': 22, 'P4': 59}, 'selected': 'P4', 'done_s': 72})]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    cars = [c for c in x['cars'] if not c['oos']]
    order = sorted(cars, key=lambda c: (c['load'] == 0, c['floor'], c['id']))
    t = 0
    starts = {}
    for c in order:
        starts[c['id']] = t
        t += c['floor'] * x['per_floor_s'] + x['door_s']
    pre = x['preselect']
    sel = pre if pre in [c['id'] for c in x['cars']] else (order[0]['id'] if order else None)
    return {'order': [c['id'] for c in order], 'starts': starts, 'selected': sel, 'done_s': t}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: out of service car preselected', {'cars': [{'id': 'P1', 'floor': 5, 'load': 0, 'oos': True}, {'id': 'P2', 'floor': 3, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P1'}, {'order': ['P2'], 'starts': {'P2': 0}, 'selected': 'P2', 'done_s': 11}), ('sampled regression 4', {'cars': [{'id': 'P4', 'floor': 5, 'load': 0, 'oos': False}, {'id': 'P1', 'floor': 11, 'load': 0, 'oos': True}, {'id': 'P2', 'floor': 4, 'load': 300, 'oos': False}], 'per_floor_s': 3, 'door_s': 8, 'preselect': None}, {'order': ['P2', 'P4'], 'starts': {'P2': 0, 'P4': 20}, 'selected': 'P2', 'done_s': 43}), ('regression: all cars out of service', {'cars': [{'id': 'P1', 'floor': 3, 'load': 0, 'oos': True}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P1'}, {'order': [], 'starts': {}, 'selected': None, 'done_s': 0}), ('boundary: occupied car first', {'cars': [{'id': 'P1', 'floor': 2, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 9, 'load': 80, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P2', 'P1'], 'starts': {'P2': 0, 'P1': 23}, 'selected': 'P2', 'done_s': 32}), ('boundary: lobby car still takes door time', {'cars': [{'id': 'P1', 'floor': 0, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 4, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P1', 'P2'], 'starts': {'P1': 0, 'P2': 5}, 'selected': 'P1', 'done_s': 18}), ('control 1', {'cars': [{'id': 'P4', 'floor': 4, 'load': 75, 'oos': False}, {'id': 'P1', 'floor': 13, 'load': 300, 'oos': False}], 'per_floor_s': 2, 'door_s': 8, 'preselect': 'P1'}, {'order': ['P4', 'P1'], 'starts': {'P4': 0, 'P1': 16}, 'selected': 'P1', 'done_s': 50}), ('sampled regression 7', {'cars': [{'id': 'P1', 'floor': 9, 'load': 300, 'oos': True}, {'id': 'P4', 'floor': 19, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P3'}, {'order': ['P4'], 'starts': {'P4': 0}, 'selected': 'P4', 'done_s': 43}), ('sampled regression 10', {'cars': [{'id': 'P3', 'floor': 2, 'load': 300, 'oos': False}, {'id': 'P1', 'floor': 3, 'load': 0, 'oos': True}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P2'}, {'order': ['P3'], 'starts': {'P3': 0}, 'selected': 'P3', 'done_s': 9})], [('regression: all cars out of service', {'cars': [{'id': 'P1', 'floor': 3, 'load': 0, 'oos': True}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P1'}, {'order': [], 'starts': {}, 'selected': None, 'done_s': 0}), ('sampled regression 15', {'cars': [{'id': 'P2', 'floor': 14, 'load': 0, 'oos': False}, {'id': 'P3', 'floor': 19, 'load': 75, 'oos': True}], 'per_floor_s': 2, 'door_s': 8, 'preselect': None}, {'order': ['P2'], 'starts': {'P2': 0}, 'selected': 'P2', 'done_s': 36}), ('sampled regression 42', {'cars': [{'id': 'P4', 'floor': 11, 'load': 0, 'oos': False}, {'id': 'P3', 'floor': 11, 'load': 300, 'oos': False}, {'id': 'P2', 'floor': 15, 'load': 0, 'oos': True}, {'id': 'P1', 'floor': 0, 'load': 0, 'oos': False}], 'per_floor_s': 3, 'door_s': 8, 'preselect': 'P2'}, {'order': ['P3', 'P1', 'P4'], 'starts': {'P3': 0, 'P1': 41, 'P4': 49}, 'selected': 'P3', 'done_s': 90}), ('boundary: lobby car still takes door time', {'cars': [{'id': 'P1', 'floor': 0, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 4, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P1', 'P2'], 'starts': {'P1': 0, 'P2': 5}, 'selected': 'P1', 'done_s': 18}), ('boundary: no preselection', {'cars': [{'id': 'P3', 'floor': 6, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 6, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P2', 'P3'], 'starts': {'P2': 0, 'P3': 17}, 'selected': 'P2', 'done_s': 34}), ('sampled regression 12', {'cars': [{'id': 'P2', 'floor': 9, 'load': 0, 'oos': False}, {'id': 'P4', 'floor': 12, 'load': 0, 'oos': True}], 'per_floor_s': 2, 'door_s': 8, 'preselect': 'P2'}, {'order': ['P2'], 'starts': {'P2': 0}, 'selected': 'P2', 'done_s': 26}), ('control 18', {'cars': [{'id': 'P3', 'floor': 7, 'load': 0, 'oos': False}, {'id': 'P4', 'floor': 10, 'load': 300, 'oos': False}, {'id': 'P2', 'floor': 12, 'load': 300, 'oos': False}], 'per_floor_s': 2, 'door_s': 8, 'preselect': 'P2'}, {'order': ['P4', 'P2', 'P3'], 'starts': {'P4': 0, 'P2': 28, 'P3': 60}, 'selected': 'P2', 'done_s': 82}), ('sampled regression 21', {'cars': [{'id': 'P1', 'floor': 13, 'load': 0, 'oos': False}, {'id': 'P4', 'floor': 3, 'load': 75, 'oos': False}, {'id': 'P2', 'floor': 8, 'load': 0, 'oos': True}], 'per_floor_s': 2, 'door_s': 8, 'preselect': 'P4'}, {'order': ['P4', 'P1'], 'starts': {'P4': 0, 'P1': 14}, 'selected': 'P4', 'done_s': 48})], [('regression: out of service car preselected', {'cars': [{'id': 'P1', 'floor': 5, 'load': 0, 'oos': True}, {'id': 'P2', 'floor': 3, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P1'}, {'order': ['P2'], 'starts': {'P2': 0}, 'selected': 'P2', 'done_s': 11}), ('sampled regression 36', {'cars': [{'id': 'P4', 'floor': 11, 'load': 75, 'oos': False}, {'id': 'P2', 'floor': 5, 'load': 75, 'oos': True}, {'id': 'P3', 'floor': 0, 'load': 300, 'oos': True}], 'per_floor_s': 2, 'door_s': 8, 'preselect': 'P4'}, {'order': ['P4'], 'starts': {'P4': 0}, 'selected': 'P4', 'done_s': 30}), ('regression: all cars out of service', {'cars': [{'id': 'P1', 'floor': 3, 'load': 0, 'oos': True}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P1'}, {'order': [], 'starts': {}, 'selected': None, 'done_s': 0}), ('boundary: occupied car first', {'cars': [{'id': 'P1', 'floor': 2, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 9, 'load': 80, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P2', 'P1'], 'starts': {'P2': 0, 'P1': 23}, 'selected': 'P2', 'done_s': 32}), ('boundary: lobby car still takes door time', {'cars': [{'id': 'P1', 'floor': 0, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 4, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P1', 'P2'], 'starts': {'P1': 0, 'P2': 5}, 'selected': 'P1', 'done_s': 18}), ('control 23', {'cars': [{'id': 'P4', 'floor': 10, 'load': 0, 'oos': False}, {'id': 'P1', 'floor': 9, 'load': 75, 'oos': False}, {'id': 'P3', 'floor': 19, 'load': 75, 'oos': False}], 'per_floor_s': 3, 'door_s': 8, 'preselect': 'P3'}, {'order': ['P1', 'P3', 'P4'], 'starts': {'P1': 0, 'P3': 35, 'P4': 100}, 'selected': 'P3', 'done_s': 138}), ('control 26', {'cars': [{'id': 'P2', 'floor': 14, 'load': 300, 'oos': False}, {'id': 'P3', 'floor': 14, 'load': 75, 'oos': False}, {'id': 'P1', 'floor': 3, 'load': 0, 'oos': False}, {'id': 'P4', 'floor': 15, 'load': 75, 'oos': False}], 'per_floor_s': 3, 'door_s': 8, 'preselect': 'P4'}, {'order': ['P2', 'P3', 'P4', 'P1'], 'starts': {'P2': 0, 'P3': 50, 'P4': 100, 'P1': 153}, 'selected': 'P4', 'done_s': 170}), ('control 29', {'cars': [{'id': 'P2', 'floor': 7, 'load': 75, 'oos': False}], 'per_floor_s': 3, 'door_s': 5, 'preselect': 'P1'}, {'order': ['P2'], 'starts': {'P2': 0}, 'selected': 'P2', 'done_s': 26})], [('regression: all cars out of service', {'cars': [{'id': 'P1', 'floor': 3, 'load': 0, 'oos': True}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P1'}, {'order': [], 'starts': {}, 'selected': None, 'done_s': 0}), ('sampled regression 49', {'cars': [{'id': 'P4', 'floor': 2, 'load': 0, 'oos': True}, {'id': 'P1', 'floor': 19, 'load': 300, 'oos': True}, {'id': 'P2', 'floor': 7, 'load': 0, 'oos': True}, {'id': 'P3', 'floor': 16, 'load': 300, 'oos': False}], 'per_floor_s': 3, 'door_s': 8, 'preselect': 'P4'}, {'order': ['P3'], 'starts': {'P3': 0}, 'selected': 'P3', 'done_s': 56}), ('sampled regression 42', {'cars': [{'id': 'P4', 'floor': 11, 'load': 0, 'oos': False}, {'id': 'P3', 'floor': 11, 'load': 300, 'oos': False}, {'id': 'P2', 'floor': 15, 'load': 0, 'oos': True}, {'id': 'P1', 'floor': 0, 'load': 0, 'oos': False}], 'per_floor_s': 3, 'door_s': 8, 'preselect': 'P2'}, {'order': ['P3', 'P1', 'P4'], 'starts': {'P3': 0, 'P1': 41, 'P4': 49}, 'selected': 'P3', 'done_s': 90}), ('boundary: occupied car first', {'cars': [{'id': 'P1', 'floor': 2, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 9, 'load': 80, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P2', 'P1'], 'starts': {'P2': 0, 'P1': 23}, 'selected': 'P2', 'done_s': 32}), ('boundary: lobby car still takes door time', {'cars': [{'id': 'P1', 'floor': 0, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 4, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P1', 'P2'], 'starts': {'P1': 0, 'P2': 5}, 'selected': 'P1', 'done_s': 18}), ('control 34', {'cars': [{'id': 'P2', 'floor': 4, 'load': 300, 'oos': False}], 'per_floor_s': 2, 'door_s': 8, 'preselect': 'P2'}, {'order': ['P2'], 'starts': {'P2': 0}, 'selected': 'P2', 'done_s': 16}), ('control 37', {'cars': [{'id': 'P3', 'floor': 6, 'load': 75, 'oos': False}, {'id': 'P4', 'floor': 14, 'load': 75, 'oos': False}], 'per_floor_s': 3, 'door_s': 8, 'preselect': 'P2'}, {'order': ['P3', 'P4'], 'starts': {'P3': 0, 'P4': 26}, 'selected': 'P3', 'done_s': 76}), ('control 40', {'cars': [{'id': 'P4', 'floor': 16, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 5, 'load': 0, 'oos': False}, {'id': 'P1', 'floor': 1, 'load': 75, 'oos': False}, {'id': 'P3', 'floor': 11, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P3'}, {'order': ['P1', 'P2', 'P3', 'P4'], 'starts': {'P1': 0, 'P2': 7, 'P3': 22, 'P4': 49}, 'selected': 'P3', 'done_s': 86})], [('regression: out of service car preselected', {'cars': [{'id': 'P1', 'floor': 5, 'load': 0, 'oos': True}, {'id': 'P2', 'floor': 3, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P1'}, {'order': ['P2'], 'starts': {'P2': 0}, 'selected': 'P2', 'done_s': 11}), ('sampled regression 61', {'cars': [{'id': 'P2', 'floor': 2, 'load': 300, 'oos': True}, {'id': 'P4', 'floor': 16, 'load': 75, 'oos': False}, {'id': 'P1', 'floor': 14, 'load': 300, 'oos': False}, {'id': 'P3', 'floor': 18, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 8, 'preselect': 'P3'}, {'order': ['P1', 'P4', 'P3'], 'starts': {'P1': 0, 'P4': 36, 'P3': 76}, 'selected': 'P3', 'done_s': 120}), ('regression: all cars out of service', {'cars': [{'id': 'P1', 'floor': 3, 'load': 0, 'oos': True}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P1'}, {'order': [], 'starts': {}, 'selected': None, 'done_s': 0}), ('boundary: no preselection', {'cars': [{'id': 'P3', 'floor': 6, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 6, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P2', 'P3'], 'starts': {'P2': 0, 'P3': 17}, 'selected': 'P2', 'done_s': 34}), ('boundary: occupied car first', {'cars': [{'id': 'P1', 'floor': 2, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 9, 'load': 80, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P2', 'P1'], 'starts': {'P2': 0, 'P1': 23}, 'selected': 'P2', 'done_s': 32}), ('control 45', {'cars': [{'id': 'P3', 'floor': 13, 'load': 75, 'oos': False}, {'id': 'P1', 'floor': 19, 'load': 0, 'oos': False}, {'id': 'P4', 'floor': 5, 'load': 0, 'oos': False}], 'per_floor_s': 3, 'door_s': 8, 'preselect': None}, {'order': ['P3', 'P4', 'P1'], 'starts': {'P3': 0, 'P4': 47, 'P1': 70}, 'selected': 'P3', 'done_s': 135}), ('sampled regression 48', {'cars': [{'id': 'P1', 'floor': 2, 'load': 75, 'oos': True}, {'id': 'P2', 'floor': 16, 'load': 300, 'oos': False}, {'id': 'P4', 'floor': 0, 'load': 0, 'oos': False}], 'per_floor_s': 3, 'door_s': 8, 'preselect': None}, {'order': ['P2', 'P4'], 'starts': {'P2': 0, 'P4': 56}, 'selected': 'P2', 'done_s': 64}), ('control 51', {'cars': [{'id': 'P1', 'floor': 2, 'load': 75, 'oos': False}, {'id': 'P4', 'floor': 4, 'load': 0, 'oos': False}, {'id': 'P3', 'floor': 16, 'load': 300, 'oos': False}, {'id': 'P2', 'floor': 4, 'load': 300, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P4'}, {'order': ['P1', 'P2', 'P3', 'P4'], 'starts': {'P1': 0, 'P2': 9, 'P3': 22, 'P4': 59}, 'selected': 'P4', 'done_s': 72})]]
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:
An out-of-service car is scheduled for return or selected to run.

On emergency power in-service cars (not oos) return to the lobby one at a time: occupied cars (load > 0) first, then by lower floor, then id. Each return takes floor*per_floor_s + door_s; starts are cumulative. Afterwards the preselected car runs if it is in service, otherwise the first car of the return order (None if no car).

split: open-access


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

N = 1
observations = []
def solve(x):
    cars = [c for c in x['cars'] if not c['oos']]
    order = sorted(cars, key=lambda c: (c['load'] > 0, c['floor'], c['id']))
    t = 0
    starts = {}
    for c in order:
        starts[c['id']] = t
        t += c['floor'] * x['per_floor_s'] + x['door_s']
    pre = x['preselect']
    sel = pre if pre in starts else (order[0]['id'] if order else None)
    return {'order': [c['id'] for c in order], 'starts': starts, 'selected': sel, 'done_s': t}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: occupied car first', {'cars': [{'id': 'P1', 'floor': 2, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 9, 'load': 80, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P2', 'P1'], 'starts': {'P2': 0, 'P1': 23}, 'selected': 'P2', 'done_s': 32}), ('sampled regression 6', {'cars': [{'id': 'P1', 'floor': 0, 'load': 300, 'oos': False}, {'id': 'P3', 'floor': 2, 'load': 0, 'oos': False}, {'id': 'P4', 'floor': 7, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 4, 'load': 0, 'oos': False}], 'per_floor_s': 3, 'door_s': 5, 'preselect': 'P3'}, {'order': ['P1', 'P3', 'P2', 'P4'], 'starts': {'P1': 0, 'P3': 5, 'P2': 16, 'P4': 33}, 'selected': 'P3', 'done_s': 59}), ('sampled regression 2', {'cars': [{'id': 'P3', 'floor': 17, 'load': 75, 'oos': False}, {'id': 'P1', 'floor': 0, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 3, 'load': 75, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P2'}, {'order': ['P2', 'P3', 'P1'], 'starts': {'P2': 0, 'P3': 11, 'P1': 50}, 'selected': 'P2', 'done_s': 55}), ('boundary: out of service car preselected', {'cars': [{'id': 'P1', 'floor': 5, 'load': 0, 'oos': True}, {'id': 'P2', 'floor': 3, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P1'}, {'order': ['P2'], 'starts': {'P2': 0}, 'selected': 'P2', 'done_s': 11}), ('boundary: lobby car still takes door time', {'cars': [{'id': 'P1', 'floor': 0, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 4, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P1', 'P2'], 'starts': {'P1': 0, 'P2': 5}, 'selected': 'P1', 'done_s': 18}), ('control 1', {'cars': [{'id': 'P4', 'floor': 4, 'load': 75, 'oos': False}, {'id': 'P1', 'floor': 13, 'load': 300, 'oos': False}], 'per_floor_s': 2, 'door_s': 8, 'preselect': 'P1'}, {'order': ['P4', 'P1'], 'starts': {'P4': 0, 'P1': 16}, 'selected': 'P1', 'done_s': 50}), ('sampled regression 4', {'cars': [{'id': 'P4', 'floor': 5, 'load': 0, 'oos': False}, {'id': 'P1', 'floor': 11, 'load': 0, 'oos': True}, {'id': 'P2', 'floor': 4, 'load': 300, 'oos': False}], 'per_floor_s': 3, 'door_s': 8, 'preselect': None}, {'order': ['P2', 'P4'], 'starts': {'P2': 0, 'P4': 20}, 'selected': 'P2', 'done_s': 43}), ('control 7', {'cars': [{'id': 'P1', 'floor': 9, 'load': 300, 'oos': True}, {'id': 'P4', 'floor': 19, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P3'}, {'order': ['P4'], 'starts': {'P4': 0}, 'selected': 'P4', 'done_s': 43})], [('regression: occupied car first', {'cars': [{'id': 'P1', 'floor': 2, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 9, 'load': 80, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P2', 'P1'], 'starts': {'P2': 0, 'P1': 23}, 'selected': 'P2', 'done_s': 32}), ('sampled regression 26', {'cars': [{'id': 'P2', 'floor': 14, 'load': 300, 'oos': False}, {'id': 'P3', 'floor': 14, 'load': 75, 'oos': False}, {'id': 'P1', 'floor': 3, 'load': 0, 'oos': False}, {'id': 'P4', 'floor': 15, 'load': 75, 'oos': False}], 'per_floor_s': 3, 'door_s': 8, 'preselect': 'P4'}, {'order': ['P2', 'P3', 'P4', 'P1'], 'starts': {'P2': 0, 'P3': 50, 'P4': 100, 'P1': 153}, 'selected': 'P4', 'done_s': 170}), ('sampled regression 28', {'cars': [{'id': 'P3', 'floor': 3, 'load': 0, 'oos': False}, {'id': 'P4', 'floor': 8, 'load': 0, 'oos': False}, {'id': 'P1', 'floor': 15, 'load': 300, 'oos': False}], 'per_floor_s': 3, 'door_s': 5, 'preselect': 'P3'}, {'order': ['P1', 'P3', 'P4'], 'starts': {'P1': 0, 'P3': 50, 'P4': 64}, 'selected': 'P3', 'done_s': 93}), ('boundary: lobby car still takes door time', {'cars': [{'id': 'P1', 'floor': 0, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 4, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P1', 'P2'], 'starts': {'P1': 0, 'P2': 5}, 'selected': 'P1', 'done_s': 18}), ('boundary: no preselection', {'cars': [{'id': 'P3', 'floor': 6, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 6, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P2', 'P3'], 'starts': {'P2': 0, 'P3': 17}, 'selected': 'P2', 'done_s': 34}), ('control 12', {'cars': [{'id': 'P2', 'floor': 9, 'load': 0, 'oos': False}, {'id': 'P4', 'floor': 12, 'load': 0, 'oos': True}], 'per_floor_s': 2, 'door_s': 8, 'preselect': 'P2'}, {'order': ['P2'], 'starts': {'P2': 0}, 'selected': 'P2', 'done_s': 26}), ('control 15', {'cars': [{'id': 'P2', 'floor': 14, 'load': 0, 'oos': False}, {'id': 'P3', 'floor': 19, 'load': 75, 'oos': True}], 'per_floor_s': 2, 'door_s': 8, 'preselect': None}, {'order': ['P2'], 'starts': {'P2': 0}, 'selected': 'P2', 'done_s': 36}), ('sampled regression 18', {'cars': [{'id': 'P3', 'floor': 7, 'load': 0, 'oos': False}, {'id': 'P4', 'floor': 10, 'load': 300, 'oos': False}, {'id': 'P2', 'floor': 12, 'load': 300, 'oos': False}], 'per_floor_s': 2, 'door_s': 8, 'preselect': 'P2'}, {'order': ['P4', 'P2', 'P3'], 'starts': {'P4': 0, 'P2': 28, 'P3': 60}, 'selected': 'P2', 'done_s': 82})], [('regression: occupied car first', {'cars': [{'id': 'P1', 'floor': 2, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 9, 'load': 80, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P2', 'P1'], 'starts': {'P2': 0, 'P1': 23}, 'selected': 'P2', 'done_s': 32}), ('sampled regression 42', {'cars': [{'id': 'P4', 'floor': 11, 'load': 0, 'oos': False}, {'id': 'P3', 'floor': 11, 'load': 300, 'oos': False}, {'id': 'P2', 'floor': 15, 'load': 0, 'oos': True}, {'id': 'P1', 'floor': 0, 'load': 0, 'oos': False}], 'per_floor_s': 3, 'door_s': 8, 'preselect': 'P2'}, {'order': ['P3', 'P1', 'P4'], 'starts': {'P3': 0, 'P1': 41, 'P4': 49}, 'selected': 'P3', 'done_s': 90}), ('sampled regression 48', {'cars': [{'id': 'P1', 'floor': 2, 'load': 75, 'oos': True}, {'id': 'P2', 'floor': 16, 'load': 300, 'oos': False}, {'id': 'P4', 'floor': 0, 'load': 0, 'oos': False}], 'per_floor_s': 3, 'door_s': 8, 'preselect': None}, {'order': ['P2', 'P4'], 'starts': {'P2': 0, 'P4': 56}, 'selected': 'P2', 'done_s': 64}), ('boundary: all cars out of service', {'cars': [{'id': 'P1', 'floor': 3, 'load': 0, 'oos': True}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P1'}, {'order': [], 'starts': {}, 'selected': None, 'done_s': 0}), ('boundary: out of service car preselected', {'cars': [{'id': 'P1', 'floor': 5, 'load': 0, 'oos': True}, {'id': 'P2', 'floor': 3, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P1'}, {'order': ['P2'], 'starts': {'P2': 0}, 'selected': 'P2', 'done_s': 11}), ('sampled regression 23', {'cars': [{'id': 'P4', 'floor': 10, 'load': 0, 'oos': False}, {'id': 'P1', 'floor': 9, 'load': 75, 'oos': False}, {'id': 'P3', 'floor': 19, 'load': 75, 'oos': False}], 'per_floor_s': 3, 'door_s': 8, 'preselect': 'P3'}, {'order': ['P1', 'P3', 'P4'], 'starts': {'P1': 0, 'P3': 35, 'P4': 100}, 'selected': 'P3', 'done_s': 138}), ('sampled regression 26', {'cars': [{'id': 'P2', 'floor': 14, 'load': 300, 'oos': False}, {'id': 'P3', 'floor': 14, 'load': 75, 'oos': False}, {'id': 'P1', 'floor': 3, 'load': 0, 'oos': False}, {'id': 'P4', 'floor': 15, 'load': 75, 'oos': False}], 'per_floor_s': 3, 'door_s': 8, 'preselect': 'P4'}, {'order': ['P2', 'P3', 'P4', 'P1'], 'starts': {'P2': 0, 'P3': 50, 'P4': 100, 'P1': 153}, 'selected': 'P4', 'done_s': 170}), ('control 29', {'cars': [{'id': 'P2', 'floor': 7, 'load': 75, 'oos': False}], 'per_floor_s': 3, 'door_s': 5, 'preselect': 'P1'}, {'order': ['P2'], 'starts': {'P2': 0}, 'selected': 'P2', 'done_s': 26})], [('regression: occupied car first', {'cars': [{'id': 'P1', 'floor': 2, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 9, 'load': 80, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P2', 'P1'], 'starts': {'P2': 0, 'P1': 23}, 'selected': 'P2', 'done_s': 32}), ('sampled regression 53', {'cars': [{'id': 'P1', 'floor': 14, 'load': 0, 'oos': False}, {'id': 'P3', 'floor': 16, 'load': 75, 'oos': False}], 'per_floor_s': 2, 'door_s': 8, 'preselect': None}, {'order': ['P3', 'P1'], 'starts': {'P3': 0, 'P1': 40}, 'selected': 'P3', 'done_s': 76}), ('sampled regression 59', {'cars': [{'id': 'P3', 'floor': 5, 'load': 0, 'oos': True}, {'id': 'P2', 'floor': 2, 'load': 0, 'oos': False}, {'id': 'P1', 'floor': 13, 'load': 0, 'oos': False}, {'id': 'P4', 'floor': 15, 'load': 75, 'oos': False}], 'per_floor_s': 3, 'door_s': 8, 'preselect': None}, {'order': ['P4', 'P2', 'P1'], 'starts': {'P4': 0, 'P2': 53, 'P1': 67}, 'selected': 'P4', 'done_s': 114}), ('boundary: lobby car still takes door time', {'cars': [{'id': 'P1', 'floor': 0, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 4, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P1', 'P2'], 'starts': {'P1': 0, 'P2': 5}, 'selected': 'P1', 'done_s': 18}), ('boundary: no preselection', {'cars': [{'id': 'P3', 'floor': 6, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 6, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P2', 'P3'], 'starts': {'P2': 0, 'P3': 17}, 'selected': 'P2', 'done_s': 34}), ('control 34', {'cars': [{'id': 'P2', 'floor': 4, 'load': 300, 'oos': False}], 'per_floor_s': 2, 'door_s': 8, 'preselect': 'P2'}, {'order': ['P2'], 'starts': {'P2': 0}, 'selected': 'P2', 'done_s': 16}), ('control 37', {'cars': [{'id': 'P3', 'floor': 6, 'load': 75, 'oos': False}, {'id': 'P4', 'floor': 14, 'load': 75, 'oos': False}], 'per_floor_s': 3, 'door_s': 8, 'preselect': 'P2'}, {'order': ['P3', 'P4'], 'starts': {'P3': 0, 'P4': 26}, 'selected': 'P3', 'done_s': 76}), ('sampled regression 40', {'cars': [{'id': 'P4', 'floor': 16, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 5, 'load': 0, 'oos': False}, {'id': 'P1', 'floor': 1, 'load': 75, 'oos': False}, {'id': 'P3', 'floor': 11, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P3'}, {'order': ['P1', 'P2', 'P3', 'P4'], 'starts': {'P1': 0, 'P2': 7, 'P3': 22, 'P4': 49}, 'selected': 'P3', 'done_s': 86})], [('regression: occupied car first', {'cars': [{'id': 'P1', 'floor': 2, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 9, 'load': 80, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P2', 'P1'], 'starts': {'P2': 0, 'P1': 23}, 'selected': 'P2', 'done_s': 32}), ('sampled regression 64', {'cars': [{'id': 'P2', 'floor': 8, 'load': 75, 'oos': True}, {'id': 'P4', 'floor': 6, 'load': 0, 'oos': False}, {'id': 'P1', 'floor': 12, 'load': 0, 'oos': False}, {'id': 'P3', 'floor': 14, 'load': 75, 'oos': False}], 'per_floor_s': 3, 'door_s': 5, 'preselect': 'P3'}, {'order': ['P3', 'P4', 'P1'], 'starts': {'P3': 0, 'P4': 47, 'P1': 70}, 'selected': 'P3', 'done_s': 111}), ('sampled regression 74', {'cars': [{'id': 'P3', 'floor': 4, 'load': 0, 'oos': True}, {'id': 'P4', 'floor': 3, 'load': 75, 'oos': False}, {'id': 'P2', 'floor': 17, 'load': 0, 'oos': True}, {'id': 'P1', 'floor': 3, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 8, 'preselect': None}, {'order': ['P4', 'P1'], 'starts': {'P4': 0, 'P1': 14}, 'selected': 'P4', 'done_s': 28}), ('boundary: no preselection', {'cars': [{'id': 'P3', 'floor': 6, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 6, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P2', 'P3'], 'starts': {'P2': 0, 'P3': 17}, 'selected': 'P2', 'done_s': 34}), ('boundary: all cars out of service', {'cars': [{'id': 'P1', 'floor': 3, 'load': 0, 'oos': True}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P1'}, {'order': [], 'starts': {}, 'selected': None, 'done_s': 0}), ('sampled regression 45', {'cars': [{'id': 'P3', 'floor': 13, 'load': 75, 'oos': False}, {'id': 'P1', 'floor': 19, 'load': 0, 'oos': False}, {'id': 'P4', 'floor': 5, 'load': 0, 'oos': False}], 'per_floor_s': 3, 'door_s': 8, 'preselect': None}, {'order': ['P3', 'P4', 'P1'], 'starts': {'P3': 0, 'P4': 47, 'P1': 70}, 'selected': 'P3', 'done_s': 135}), ('sampled regression 48', {'cars': [{'id': 'P1', 'floor': 2, 'load': 75, 'oos': True}, {'id': 'P2', 'floor': 16, 'load': 300, 'oos': False}, {'id': 'P4', 'floor': 0, 'load': 0, 'oos': False}], 'per_floor_s': 3, 'door_s': 8, 'preselect': None}, {'order': ['P2', 'P4'], 'starts': {'P2': 0, 'P4': 56}, 'selected': 'P2', 'done_s': 64}), ('sampled regression 51', {'cars': [{'id': 'P1', 'floor': 2, 'load': 75, 'oos': False}, {'id': 'P4', 'floor': 4, 'load': 0, 'oos': False}, {'id': 'P3', 'floor': 16, 'load': 300, 'oos': False}, {'id': 'P2', 'floor': 4, 'load': 300, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P4'}, {'order': ['P1', 'P2', 'P3', 'P4'], 'starts': {'P1': 0, 'P2': 9, 'P3': 22, 'P4': 59}, 'selected': 'P4', 'done_s': 72})]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

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

N = 1
observations = []
def solve(x):
    cars = [c for c in x['cars'] if not c['oos']]
    order = sorted(cars, key=lambda c: (c['floor'], c['id']))
    t = 0
    starts = {}
    for c in order:
        starts[c['id']] = t
        t += c['floor'] * x['per_floor_s'] + x['door_s']
    pre = x['preselect']
    sel = pre if pre in starts else (order[0]['id'] if order else None)
    return {'order': [c['id'] for c in order], 'starts': starts, 'selected': sel, 'done_s': t}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: occupied car first', {'cars': [{'id': 'P1', 'floor': 2, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 9, 'load': 80, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P2', 'P1'], 'starts': {'P2': 0, 'P1': 23}, 'selected': 'P2', 'done_s': 32}), ('sampled regression 6', {'cars': [{'id': 'P1', 'floor': 0, 'load': 300, 'oos': False}, {'id': 'P3', 'floor': 2, 'load': 0, 'oos': False}, {'id': 'P4', 'floor': 7, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 4, 'load': 0, 'oos': False}], 'per_floor_s': 3, 'door_s': 5, 'preselect': 'P3'}, {'order': ['P1', 'P3', 'P2', 'P4'], 'starts': {'P1': 0, 'P3': 5, 'P2': 16, 'P4': 33}, 'selected': 'P3', 'done_s': 59}), ('sampled regression 2', {'cars': [{'id': 'P3', 'floor': 17, 'load': 75, 'oos': False}, {'id': 'P1', 'floor': 0, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 3, 'load': 75, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P2'}, {'order': ['P2', 'P3', 'P1'], 'starts': {'P2': 0, 'P3': 11, 'P1': 50}, 'selected': 'P2', 'done_s': 55}), ('boundary: out of service car preselected', {'cars': [{'id': 'P1', 'floor': 5, 'load': 0, 'oos': True}, {'id': 'P2', 'floor': 3, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P1'}, {'order': ['P2'], 'starts': {'P2': 0}, 'selected': 'P2', 'done_s': 11}), ('boundary: lobby car still takes door time', {'cars': [{'id': 'P1', 'floor': 0, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 4, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P1', 'P2'], 'starts': {'P1': 0, 'P2': 5}, 'selected': 'P1', 'done_s': 18}), ('control 1', {'cars': [{'id': 'P4', 'floor': 4, 'load': 75, 'oos': False}, {'id': 'P1', 'floor': 13, 'load': 300, 'oos': False}], 'per_floor_s': 2, 'door_s': 8, 'preselect': 'P1'}, {'order': ['P4', 'P1'], 'starts': {'P4': 0, 'P1': 16}, 'selected': 'P1', 'done_s': 50}), ('sampled regression 4', {'cars': [{'id': 'P4', 'floor': 5, 'load': 0, 'oos': False}, {'id': 'P1', 'floor': 11, 'load': 0, 'oos': True}, {'id': 'P2', 'floor': 4, 'load': 300, 'oos': False}], 'per_floor_s': 3, 'door_s': 8, 'preselect': None}, {'order': ['P2', 'P4'], 'starts': {'P2': 0, 'P4': 20}, 'selected': 'P2', 'done_s': 43}), ('control 7', {'cars': [{'id': 'P1', 'floor': 9, 'load': 300, 'oos': True}, {'id': 'P4', 'floor': 19, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P3'}, {'order': ['P4'], 'starts': {'P4': 0}, 'selected': 'P4', 'done_s': 43})], [('regression: occupied car first', {'cars': [{'id': 'P1', 'floor': 2, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 9, 'load': 80, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P2', 'P1'], 'starts': {'P2': 0, 'P1': 23}, 'selected': 'P2', 'done_s': 32}), ('sampled regression 26', {'cars': [{'id': 'P2', 'floor': 14, 'load': 300, 'oos': False}, {'id': 'P3', 'floor': 14, 'load': 75, 'oos': False}, {'id': 'P1', 'floor': 3, 'load': 0, 'oos': False}, {'id': 'P4', 'floor': 15, 'load': 75, 'oos': False}], 'per_floor_s': 3, 'door_s': 8, 'preselect': 'P4'}, {'order': ['P2', 'P3', 'P4', 'P1'], 'starts': {'P2': 0, 'P3': 50, 'P4': 100, 'P1': 153}, 'selected': 'P4', 'done_s': 170}), ('sampled regression 28', {'cars': [{'id': 'P3', 'floor': 3, 'load': 0, 'oos': False}, {'id': 'P4', 'floor': 8, 'load': 0, 'oos': False}, {'id': 'P1', 'floor': 15, 'load': 300, 'oos': False}], 'per_floor_s': 3, 'door_s': 5, 'preselect': 'P3'}, {'order': ['P1', 'P3', 'P4'], 'starts': {'P1': 0, 'P3': 50, 'P4': 64}, 'selected': 'P3', 'done_s': 93}), ('boundary: lobby car still takes door time', {'cars': [{'id': 'P1', 'floor': 0, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 4, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P1', 'P2'], 'starts': {'P1': 0, 'P2': 5}, 'selected': 'P1', 'done_s': 18}), ('boundary: no preselection', {'cars': [{'id': 'P3', 'floor': 6, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 6, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P2', 'P3'], 'starts': {'P2': 0, 'P3': 17}, 'selected': 'P2', 'done_s': 34}), ('control 12', {'cars': [{'id': 'P2', 'floor': 9, 'load': 0, 'oos': False}, {'id': 'P4', 'floor': 12, 'load': 0, 'oos': True}], 'per_floor_s': 2, 'door_s': 8, 'preselect': 'P2'}, {'order': ['P2'], 'starts': {'P2': 0}, 'selected': 'P2', 'done_s': 26}), ('control 15', {'cars': [{'id': 'P2', 'floor': 14, 'load': 0, 'oos': False}, {'id': 'P3', 'floor': 19, 'load': 75, 'oos': True}], 'per_floor_s': 2, 'door_s': 8, 'preselect': None}, {'order': ['P2'], 'starts': {'P2': 0}, 'selected': 'P2', 'done_s': 36}), ('sampled regression 18', {'cars': [{'id': 'P3', 'floor': 7, 'load': 0, 'oos': False}, {'id': 'P4', 'floor': 10, 'load': 300, 'oos': False}, {'id': 'P2', 'floor': 12, 'load': 300, 'oos': False}], 'per_floor_s': 2, 'door_s': 8, 'preselect': 'P2'}, {'order': ['P4', 'P2', 'P3'], 'starts': {'P4': 0, 'P2': 28, 'P3': 60}, 'selected': 'P2', 'done_s': 82})], [('regression: occupied car first', {'cars': [{'id': 'P1', 'floor': 2, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 9, 'load': 80, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P2', 'P1'], 'starts': {'P2': 0, 'P1': 23}, 'selected': 'P2', 'done_s': 32}), ('sampled regression 42', {'cars': [{'id': 'P4', 'floor': 11, 'load': 0, 'oos': False}, {'id': 'P3', 'floor': 11, 'load': 300, 'oos': False}, {'id': 'P2', 'floor': 15, 'load': 0, 'oos': True}, {'id': 'P1', 'floor': 0, 'load': 0, 'oos': False}], 'per_floor_s': 3, 'door_s': 8, 'preselect': 'P2'}, {'order': ['P3', 'P1', 'P4'], 'starts': {'P3': 0, 'P1': 41, 'P4': 49}, 'selected': 'P3', 'done_s': 90}), ('sampled regression 48', {'cars': [{'id': 'P1', 'floor': 2, 'load': 75, 'oos': True}, {'id': 'P2', 'floor': 16, 'load': 300, 'oos': False}, {'id': 'P4', 'floor': 0, 'load': 0, 'oos': False}], 'per_floor_s': 3, 'door_s': 8, 'preselect': None}, {'order': ['P2', 'P4'], 'starts': {'P2': 0, 'P4': 56}, 'selected': 'P2', 'done_s': 64}), ('boundary: all cars out of service', {'cars': [{'id': 'P1', 'floor': 3, 'load': 0, 'oos': True}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P1'}, {'order': [], 'starts': {}, 'selected': None, 'done_s': 0}), ('boundary: out of service car preselected', {'cars': [{'id': 'P1', 'floor': 5, 'load': 0, 'oos': True}, {'id': 'P2', 'floor': 3, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P1'}, {'order': ['P2'], 'starts': {'P2': 0}, 'selected': 'P2', 'done_s': 11}), ('sampled regression 23', {'cars': [{'id': 'P4', 'floor': 10, 'load': 0, 'oos': False}, {'id': 'P1', 'floor': 9, 'load': 75, 'oos': False}, {'id': 'P3', 'floor': 19, 'load': 75, 'oos': False}], 'per_floor_s': 3, 'door_s': 8, 'preselect': 'P3'}, {'order': ['P1', 'P3', 'P4'], 'starts': {'P1': 0, 'P3': 35, 'P4': 100}, 'selected': 'P3', 'done_s': 138}), ('sampled regression 26', {'cars': [{'id': 'P2', 'floor': 14, 'load': 300, 'oos': False}, {'id': 'P3', 'floor': 14, 'load': 75, 'oos': False}, {'id': 'P1', 'floor': 3, 'load': 0, 'oos': False}, {'id': 'P4', 'floor': 15, 'load': 75, 'oos': False}], 'per_floor_s': 3, 'door_s': 8, 'preselect': 'P4'}, {'order': ['P2', 'P3', 'P4', 'P1'], 'starts': {'P2': 0, 'P3': 50, 'P4': 100, 'P1': 153}, 'selected': 'P4', 'done_s': 170}), ('control 29', {'cars': [{'id': 'P2', 'floor': 7, 'load': 75, 'oos': False}], 'per_floor_s': 3, 'door_s': 5, 'preselect': 'P1'}, {'order': ['P2'], 'starts': {'P2': 0}, 'selected': 'P2', 'done_s': 26})], [('regression: occupied car first', {'cars': [{'id': 'P1', 'floor': 2, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 9, 'load': 80, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P2', 'P1'], 'starts': {'P2': 0, 'P1': 23}, 'selected': 'P2', 'done_s': 32}), ('sampled regression 53', {'cars': [{'id': 'P1', 'floor': 14, 'load': 0, 'oos': False}, {'id': 'P3', 'floor': 16, 'load': 75, 'oos': False}], 'per_floor_s': 2, 'door_s': 8, 'preselect': None}, {'order': ['P3', 'P1'], 'starts': {'P3': 0, 'P1': 40}, 'selected': 'P3', 'done_s': 76}), ('sampled regression 59', {'cars': [{'id': 'P3', 'floor': 5, 'load': 0, 'oos': True}, {'id': 'P2', 'floor': 2, 'load': 0, 'oos': False}, {'id': 'P1', 'floor': 13, 'load': 0, 'oos': False}, {'id': 'P4', 'floor': 15, 'load': 75, 'oos': False}], 'per_floor_s': 3, 'door_s': 8, 'preselect': None}, {'order': ['P4', 'P2', 'P1'], 'starts': {'P4': 0, 'P2': 53, 'P1': 67}, 'selected': 'P4', 'done_s': 114}), ('boundary: lobby car still takes door time', {'cars': [{'id': 'P1', 'floor': 0, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 4, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P1', 'P2'], 'starts': {'P1': 0, 'P2': 5}, 'selected': 'P1', 'done_s': 18}), ('boundary: no preselection', {'cars': [{'id': 'P3', 'floor': 6, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 6, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P2', 'P3'], 'starts': {'P2': 0, 'P3': 17}, 'selected': 'P2', 'done_s': 34}), ('control 34', {'cars': [{'id': 'P2', 'floor': 4, 'load': 300, 'oos': False}], 'per_floor_s': 2, 'door_s': 8, 'preselect': 'P2'}, {'order': ['P2'], 'starts': {'P2': 0}, 'selected': 'P2', 'done_s': 16}), ('control 37', {'cars': [{'id': 'P3', 'floor': 6, 'load': 75, 'oos': False}, {'id': 'P4', 'floor': 14, 'load': 75, 'oos': False}], 'per_floor_s': 3, 'door_s': 8, 'preselect': 'P2'}, {'order': ['P3', 'P4'], 'starts': {'P3': 0, 'P4': 26}, 'selected': 'P3', 'done_s': 76}), ('sampled regression 40', {'cars': [{'id': 'P4', 'floor': 16, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 5, 'load': 0, 'oos': False}, {'id': 'P1', 'floor': 1, 'load': 75, 'oos': False}, {'id': 'P3', 'floor': 11, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P3'}, {'order': ['P1', 'P2', 'P3', 'P4'], 'starts': {'P1': 0, 'P2': 7, 'P3': 22, 'P4': 49}, 'selected': 'P3', 'done_s': 86})], [('regression: occupied car first', {'cars': [{'id': 'P1', 'floor': 2, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 9, 'load': 80, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P2', 'P1'], 'starts': {'P2': 0, 'P1': 23}, 'selected': 'P2', 'done_s': 32}), ('sampled regression 64', {'cars': [{'id': 'P2', 'floor': 8, 'load': 75, 'oos': True}, {'id': 'P4', 'floor': 6, 'load': 0, 'oos': False}, {'id': 'P1', 'floor': 12, 'load': 0, 'oos': False}, {'id': 'P3', 'floor': 14, 'load': 75, 'oos': False}], 'per_floor_s': 3, 'door_s': 5, 'preselect': 'P3'}, {'order': ['P3', 'P4', 'P1'], 'starts': {'P3': 0, 'P4': 47, 'P1': 70}, 'selected': 'P3', 'done_s': 111}), ('sampled regression 74', {'cars': [{'id': 'P3', 'floor': 4, 'load': 0, 'oos': True}, {'id': 'P4', 'floor': 3, 'load': 75, 'oos': False}, {'id': 'P2', 'floor': 17, 'load': 0, 'oos': True}, {'id': 'P1', 'floor': 3, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 8, 'preselect': None}, {'order': ['P4', 'P1'], 'starts': {'P4': 0, 'P1': 14}, 'selected': 'P4', 'done_s': 28}), ('boundary: no preselection', {'cars': [{'id': 'P3', 'floor': 6, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 6, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P2', 'P3'], 'starts': {'P2': 0, 'P3': 17}, 'selected': 'P2', 'done_s': 34}), ('boundary: all cars out of service', {'cars': [{'id': 'P1', 'floor': 3, 'load': 0, 'oos': True}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P1'}, {'order': [], 'starts': {}, 'selected': None, 'done_s': 0}), ('sampled regression 45', {'cars': [{'id': 'P3', 'floor': 13, 'load': 75, 'oos': False}, {'id': 'P1', 'floor': 19, 'load': 0, 'oos': False}, {'id': 'P4', 'floor': 5, 'load': 0, 'oos': False}], 'per_floor_s': 3, 'door_s': 8, 'preselect': None}, {'order': ['P3', 'P4', 'P1'], 'starts': {'P3': 0, 'P4': 47, 'P1': 70}, 'selected': 'P3', 'done_s': 135}), ('sampled regression 48', {'cars': [{'id': 'P1', 'floor': 2, 'load': 75, 'oos': True}, {'id': 'P2', 'floor': 16, 'load': 300, 'oos': False}, {'id': 'P4', 'floor': 0, 'load': 0, 'oos': False}], 'per_floor_s': 3, 'door_s': 8, 'preselect': None}, {'order': ['P2', 'P4'], 'starts': {'P2': 0, 'P4': 56}, 'selected': 'P2', 'done_s': 64}), ('sampled regression 51', {'cars': [{'id': 'P1', 'floor': 2, 'load': 75, 'oos': False}, {'id': 'P4', 'floor': 4, 'load': 0, 'oos': False}, {'id': 'P3', 'floor': 16, 'load': 300, 'oos': False}, {'id': 'P2', 'floor': 4, 'load': 300, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P4'}, {'order': ['P1', 'P2', 'P3', 'P4'], 'starts': {'P1': 0, 'P2': 9, 'P3': 22, 'P4': 59}, 'selected': 'P4', 'done_s': 72})]]
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:
Trapped passengers wait while empty cars return first.

On emergency power in-service cars (not oos) return to the lobby one at a time: occupied cars (load > 0) first, then by lower floor, then id. Each return takes floor*per_floor_s + door_s; starts are cumulative. Afterwards the preselected car runs if it is in service, otherwise the first car of the return order (None if no car).

split: open-access


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

N = 1
observations = []
def solve(x):
    cars = [c for c in x['cars'] if not c['oos']]
    order = sorted(cars, key=lambda c: (c['load'] == 0, c['floor'], c['id']))
    t = 0
    starts = {}
    for c in order:
        starts[c['id']] = t
        t += c['floor'] * x['per_floor_s']
    pre = x['preselect']
    sel = pre if pre in starts else (order[0]['id'] if order else None)
    return {'order': [c['id'] for c in order], 'starts': starts, 'selected': sel, 'done_s': t}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: out of service car preselected', {'cars': [{'id': 'P1', 'floor': 5, 'load': 0, 'oos': True}, {'id': 'P2', 'floor': 3, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P1'}, {'order': ['P2'], 'starts': {'P2': 0}, 'selected': 'P2', 'done_s': 11}), ('regression: no preselection', {'cars': [{'id': 'P3', 'floor': 6, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 6, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P2', 'P3'], 'starts': {'P2': 0, 'P3': 17}, 'selected': 'P2', 'done_s': 34}), ('regression: occupied car first', {'cars': [{'id': 'P1', 'floor': 2, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 9, 'load': 80, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P2', 'P1'], 'starts': {'P2': 0, 'P1': 23}, 'selected': 'P2', 'done_s': 32}), ('regression: lobby car still takes door time', {'cars': [{'id': 'P1', 'floor': 0, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 4, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P1', 'P2'], 'starts': {'P1': 0, 'P2': 5}, 'selected': 'P1', 'done_s': 18}), ('boundary: all cars out of service', {'cars': [{'id': 'P1', 'floor': 3, 'load': 0, 'oos': True}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P1'}, {'order': [], 'starts': {}, 'selected': None, 'done_s': 0}), ('sampled regression 1', {'cars': [{'id': 'P4', 'floor': 4, 'load': 75, 'oos': False}, {'id': 'P1', 'floor': 13, 'load': 300, 'oos': False}], 'per_floor_s': 2, 'door_s': 8, 'preselect': 'P1'}, {'order': ['P4', 'P1'], 'starts': {'P4': 0, 'P1': 16}, 'selected': 'P1', 'done_s': 50}), ('sampled regression 4', {'cars': [{'id': 'P4', 'floor': 5, 'load': 0, 'oos': False}, {'id': 'P1', 'floor': 11, 'load': 0, 'oos': True}, {'id': 'P2', 'floor': 4, 'load': 300, 'oos': False}], 'per_floor_s': 3, 'door_s': 8, 'preselect': None}, {'order': ['P2', 'P4'], 'starts': {'P2': 0, 'P4': 20}, 'selected': 'P2', 'done_s': 43}), ('sampled regression 7', {'cars': [{'id': 'P1', 'floor': 9, 'load': 300, 'oos': True}, {'id': 'P4', 'floor': 19, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P3'}, {'order': ['P4'], 'starts': {'P4': 0}, 'selected': 'P4', 'done_s': 43})], [('regression: occupied car first', {'cars': [{'id': 'P1', 'floor': 2, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 9, 'load': 80, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P2', 'P1'], 'starts': {'P2': 0, 'P1': 23}, 'selected': 'P2', 'done_s': 32}), ('sampled regression 8', {'cars': [{'id': 'P2', 'floor': 13, 'load': 0, 'oos': False}, {'id': 'P4', 'floor': 18, 'load': 0, 'oos': False}], 'per_floor_s': 3, 'door_s': 8, 'preselect': 'P1'}, {'order': ['P2', 'P4'], 'starts': {'P2': 0, 'P4': 47}, 'selected': 'P2', 'done_s': 109}), ('sampled regression 3', {'cars': [{'id': 'P2', 'floor': 15, 'load': 300, 'oos': False}, {'id': 'P1', 'floor': 8, 'load': 300, 'oos': True}, {'id': 'P4', 'floor': 10, 'load': 0, 'oos': True}, {'id': 'P3', 'floor': 12, 'load': 75, 'oos': False}], 'per_floor_s': 3, 'door_s': 5, 'preselect': 'P4'}, {'order': ['P3', 'P2'], 'starts': {'P3': 0, 'P2': 41}, 'selected': 'P3', 'done_s': 91}), ('regression: lobby car still takes door time', {'cars': [{'id': 'P1', 'floor': 0, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 4, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P1', 'P2'], 'starts': {'P1': 0, 'P2': 5}, 'selected': 'P1', 'done_s': 18}), ('regression: no preselection', {'cars': [{'id': 'P3', 'floor': 6, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 6, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P2', 'P3'], 'starts': {'P2': 0, 'P3': 17}, 'selected': 'P2', 'done_s': 34}), ('sampled regression 12', {'cars': [{'id': 'P2', 'floor': 9, 'load': 0, 'oos': False}, {'id': 'P4', 'floor': 12, 'load': 0, 'oos': True}], 'per_floor_s': 2, 'door_s': 8, 'preselect': 'P2'}, {'order': ['P2'], 'starts': {'P2': 0}, 'selected': 'P2', 'done_s': 26}), ('sampled regression 15', {'cars': [{'id': 'P2', 'floor': 14, 'load': 0, 'oos': False}, {'id': 'P3', 'floor': 19, 'load': 75, 'oos': True}], 'per_floor_s': 2, 'door_s': 8, 'preselect': None}, {'order': ['P2'], 'starts': {'P2': 0}, 'selected': 'P2', 'done_s': 36}), ('sampled regression 18', {'cars': [{'id': 'P3', 'floor': 7, 'load': 0, 'oos': False}, {'id': 'P4', 'floor': 10, 'load': 300, 'oos': False}, {'id': 'P2', 'floor': 12, 'load': 300, 'oos': False}], 'per_floor_s': 2, 'door_s': 8, 'preselect': 'P2'}, {'order': ['P4', 'P2', 'P3'], 'starts': {'P4': 0, 'P2': 28, 'P3': 60}, 'selected': 'P2', 'done_s': 82})], [('regression: lobby car still takes door time', {'cars': [{'id': 'P1', 'floor': 0, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 4, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P1', 'P2'], 'starts': {'P1': 0, 'P2': 5}, 'selected': 'P1', 'done_s': 18}), ('sampled regression 15', {'cars': [{'id': 'P2', 'floor': 14, 'load': 0, 'oos': False}, {'id': 'P3', 'floor': 19, 'load': 75, 'oos': True}], 'per_floor_s': 2, 'door_s': 8, 'preselect': None}, {'order': ['P2'], 'starts': {'P2': 0}, 'selected': 'P2', 'done_s': 36}), ('sampled regression 9', {'cars': [{'id': 'P2', 'floor': 9, 'load': 300, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P1'}, {'order': ['P2'], 'starts': {'P2': 0}, 'selected': 'P2', 'done_s': 23}), ('boundary: all cars out of service', {'cars': [{'id': 'P1', 'floor': 3, 'load': 0, 'oos': True}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P1'}, {'order': [], 'starts': {}, 'selected': None, 'done_s': 0}), ('regression: out of service car preselected', {'cars': [{'id': 'P1', 'floor': 5, 'load': 0, 'oos': True}, {'id': 'P2', 'floor': 3, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P1'}, {'order': ['P2'], 'starts': {'P2': 0}, 'selected': 'P2', 'done_s': 11}), ('sampled regression 23', {'cars': [{'id': 'P4', 'floor': 10, 'load': 0, 'oos': False}, {'id': 'P1', 'floor': 9, 'load': 75, 'oos': False}, {'id': 'P3', 'floor': 19, 'load': 75, 'oos': False}], 'per_floor_s': 3, 'door_s': 8, 'preselect': 'P3'}, {'order': ['P1', 'P3', 'P4'], 'starts': {'P1': 0, 'P3': 35, 'P4': 100}, 'selected': 'P3', 'done_s': 138}), ('sampled regression 26', {'cars': [{'id': 'P2', 'floor': 14, 'load': 300, 'oos': False}, {'id': 'P3', 'floor': 14, 'load': 75, 'oos': False}, {'id': 'P1', 'floor': 3, 'load': 0, 'oos': False}, {'id': 'P4', 'floor': 15, 'load': 75, 'oos': False}], 'per_floor_s': 3, 'door_s': 8, 'preselect': 'P4'}, {'order': ['P2', 'P3', 'P4', 'P1'], 'starts': {'P2': 0, 'P3': 50, 'P4': 100, 'P1': 153}, 'selected': 'P4', 'done_s': 170}), ('sampled regression 29', {'cars': [{'id': 'P2', 'floor': 7, 'load': 75, 'oos': False}], 'per_floor_s': 3, 'door_s': 5, 'preselect': 'P1'}, {'order': ['P2'], 'starts': {'P2': 0}, 'selected': 'P2', 'done_s': 26})], [('regression: no preselection', {'cars': [{'id': 'P3', 'floor': 6, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 6, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P2', 'P3'], 'starts': {'P2': 0, 'P3': 17}, 'selected': 'P2', 'done_s': 34}), ('sampled regression 22', {'cars': [{'id': 'P2', 'floor': 0, 'load': 0, 'oos': True}, {'id': 'P1', 'floor': 0, 'load': 0, 'oos': False}], 'per_floor_s': 3, 'door_s': 8, 'preselect': 'P1'}, {'order': ['P1'], 'starts': {'P1': 0}, 'selected': 'P1', 'done_s': 8}), ('sampled regression 14', {'cars': [{'id': 'P3', 'floor': 11, 'load': 300, 'oos': False}], 'per_floor_s': 3, 'door_s': 8, 'preselect': None}, {'order': ['P3'], 'starts': {'P3': 0}, 'selected': 'P3', 'done_s': 41}), ('regression: occupied car first', {'cars': [{'id': 'P1', 'floor': 2, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 9, 'load': 80, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P2', 'P1'], 'starts': {'P2': 0, 'P1': 23}, 'selected': 'P2', 'done_s': 32}), ('regression: lobby car still takes door time', {'cars': [{'id': 'P1', 'floor': 0, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 4, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P1', 'P2'], 'starts': {'P1': 0, 'P2': 5}, 'selected': 'P1', 'done_s': 18}), ('sampled regression 34', {'cars': [{'id': 'P2', 'floor': 4, 'load': 300, 'oos': False}], 'per_floor_s': 2, 'door_s': 8, 'preselect': 'P2'}, {'order': ['P2'], 'starts': {'P2': 0}, 'selected': 'P2', 'done_s': 16}), ('sampled regression 37', {'cars': [{'id': 'P3', 'floor': 6, 'load': 75, 'oos': False}, {'id': 'P4', 'floor': 14, 'load': 75, 'oos': False}], 'per_floor_s': 3, 'door_s': 8, 'preselect': 'P2'}, {'order': ['P3', 'P4'], 'starts': {'P3': 0, 'P4': 26}, 'selected': 'P3', 'done_s': 76}), ('sampled regression 40', {'cars': [{'id': 'P4', 'floor': 16, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 5, 'load': 0, 'oos': False}, {'id': 'P1', 'floor': 1, 'load': 75, 'oos': False}, {'id': 'P3', 'floor': 11, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P3'}, {'order': ['P1', 'P2', 'P3', 'P4'], 'starts': {'P1': 0, 'P2': 7, 'P3': 22, 'P4': 49}, 'selected': 'P3', 'done_s': 86})], [('regression: out of service car preselected', {'cars': [{'id': 'P1', 'floor': 5, 'load': 0, 'oos': True}, {'id': 'P2', 'floor': 3, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P1'}, {'order': ['P2'], 'starts': {'P2': 0}, 'selected': 'P2', 'done_s': 11}), ('sampled regression 29', {'cars': [{'id': 'P2', 'floor': 7, 'load': 75, 'oos': False}], 'per_floor_s': 3, 'door_s': 5, 'preselect': 'P1'}, {'order': ['P2'], 'starts': {'P2': 0}, 'selected': 'P2', 'done_s': 26}), ('sampled regression 19', {'cars': [{'id': 'P2', 'floor': 1, 'load': 75, 'oos': False}], 'per_floor_s': 2, 'door_s': 8, 'preselect': 'P1'}, {'order': ['P2'], 'starts': {'P2': 0}, 'selected': 'P2', 'done_s': 10}), ('regression: no preselection', {'cars': [{'id': 'P3', 'floor': 6, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 6, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P2', 'P3'], 'starts': {'P2': 0, 'P3': 17}, 'selected': 'P2', 'done_s': 34}), ('boundary: all cars out of service', {'cars': [{'id': 'P1', 'floor': 3, 'load': 0, 'oos': True}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P1'}, {'order': [], 'starts': {}, 'selected': None, 'done_s': 0}), ('sampled regression 45', {'cars': [{'id': 'P3', 'floor': 13, 'load': 75, 'oos': False}, {'id': 'P1', 'floor': 19, 'load': 0, 'oos': False}, {'id': 'P4', 'floor': 5, 'load': 0, 'oos': False}], 'per_floor_s': 3, 'door_s': 8, 'preselect': None}, {'order': ['P3', 'P4', 'P1'], 'starts': {'P3': 0, 'P4': 47, 'P1': 70}, 'selected': 'P3', 'done_s': 135}), ('sampled regression 48', {'cars': [{'id': 'P1', 'floor': 2, 'load': 75, 'oos': True}, {'id': 'P2', 'floor': 16, 'load': 300, 'oos': False}, {'id': 'P4', 'floor': 0, 'load': 0, 'oos': False}], 'per_floor_s': 3, 'door_s': 8, 'preselect': None}, {'order': ['P2', 'P4'], 'starts': {'P2': 0, 'P4': 56}, 'selected': 'P2', 'done_s': 64}), ('sampled regression 51', {'cars': [{'id': 'P1', 'floor': 2, 'load': 75, 'oos': False}, {'id': 'P4', 'floor': 4, 'load': 0, 'oos': False}, {'id': 'P3', 'floor': 16, 'load': 300, 'oos': False}, {'id': 'P2', 'floor': 4, 'load': 300, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P4'}, {'order': ['P1', 'P2', 'P3', 'P4'], 'starts': {'P1': 0, 'P2': 9, 'P3': 22, 'P4': 59}, 'selected': 'P4', 'done_s': 72})]]
for label, args, expected in fixtures[N-1]:
    check(label, solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)

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

N = 1
observations = []
def solve(x):
    cars = [c for c in x['cars'] if not c['oos']]
    order = sorted(cars, key=lambda c: (c['load'] == 0, c['floor'], c['id']))
    t = 0
    starts = {}
    for c in order:
        starts[c['id']] = t
        t += (c['floor'] + 1) * x['per_floor_s']
    pre = x['preselect']
    sel = pre if pre in starts else (order[0]['id'] if order else None)
    return {'order': [c['id'] for c in order], 'starts': starts, 'selected': sel, 'done_s': t}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: out of service car preselected', {'cars': [{'id': 'P1', 'floor': 5, 'load': 0, 'oos': True}, {'id': 'P2', 'floor': 3, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P1'}, {'order': ['P2'], 'starts': {'P2': 0}, 'selected': 'P2', 'done_s': 11}), ('regression: no preselection', {'cars': [{'id': 'P3', 'floor': 6, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 6, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P2', 'P3'], 'starts': {'P2': 0, 'P3': 17}, 'selected': 'P2', 'done_s': 34}), ('regression: occupied car first', {'cars': [{'id': 'P1', 'floor': 2, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 9, 'load': 80, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P2', 'P1'], 'starts': {'P2': 0, 'P1': 23}, 'selected': 'P2', 'done_s': 32}), ('regression: lobby car still takes door time', {'cars': [{'id': 'P1', 'floor': 0, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 4, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P1', 'P2'], 'starts': {'P1': 0, 'P2': 5}, 'selected': 'P1', 'done_s': 18}), ('boundary: all cars out of service', {'cars': [{'id': 'P1', 'floor': 3, 'load': 0, 'oos': True}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P1'}, {'order': [], 'starts': {}, 'selected': None, 'done_s': 0}), ('sampled regression 1', {'cars': [{'id': 'P4', 'floor': 4, 'load': 75, 'oos': False}, {'id': 'P1', 'floor': 13, 'load': 300, 'oos': False}], 'per_floor_s': 2, 'door_s': 8, 'preselect': 'P1'}, {'order': ['P4', 'P1'], 'starts': {'P4': 0, 'P1': 16}, 'selected': 'P1', 'done_s': 50}), ('sampled regression 4', {'cars': [{'id': 'P4', 'floor': 5, 'load': 0, 'oos': False}, {'id': 'P1', 'floor': 11, 'load': 0, 'oos': True}, {'id': 'P2', 'floor': 4, 'load': 300, 'oos': False}], 'per_floor_s': 3, 'door_s': 8, 'preselect': None}, {'order': ['P2', 'P4'], 'starts': {'P2': 0, 'P4': 20}, 'selected': 'P2', 'done_s': 43}), ('sampled regression 7', {'cars': [{'id': 'P1', 'floor': 9, 'load': 300, 'oos': True}, {'id': 'P4', 'floor': 19, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P3'}, {'order': ['P4'], 'starts': {'P4': 0}, 'selected': 'P4', 'done_s': 43})], [('regression: occupied car first', {'cars': [{'id': 'P1', 'floor': 2, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 9, 'load': 80, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P2', 'P1'], 'starts': {'P2': 0, 'P1': 23}, 'selected': 'P2', 'done_s': 32}), ('sampled regression 8', {'cars': [{'id': 'P2', 'floor': 13, 'load': 0, 'oos': False}, {'id': 'P4', 'floor': 18, 'load': 0, 'oos': False}], 'per_floor_s': 3, 'door_s': 8, 'preselect': 'P1'}, {'order': ['P2', 'P4'], 'starts': {'P2': 0, 'P4': 47}, 'selected': 'P2', 'done_s': 109}), ('sampled regression 3', {'cars': [{'id': 'P2', 'floor': 15, 'load': 300, 'oos': False}, {'id': 'P1', 'floor': 8, 'load': 300, 'oos': True}, {'id': 'P4', 'floor': 10, 'load': 0, 'oos': True}, {'id': 'P3', 'floor': 12, 'load': 75, 'oos': False}], 'per_floor_s': 3, 'door_s': 5, 'preselect': 'P4'}, {'order': ['P3', 'P2'], 'starts': {'P3': 0, 'P2': 41}, 'selected': 'P3', 'done_s': 91}), ('regression: lobby car still takes door time', {'cars': [{'id': 'P1', 'floor': 0, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 4, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P1', 'P2'], 'starts': {'P1': 0, 'P2': 5}, 'selected': 'P1', 'done_s': 18}), ('regression: no preselection', {'cars': [{'id': 'P3', 'floor': 6, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 6, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P2', 'P3'], 'starts': {'P2': 0, 'P3': 17}, 'selected': 'P2', 'done_s': 34}), ('sampled regression 12', {'cars': [{'id': 'P2', 'floor': 9, 'load': 0, 'oos': False}, {'id': 'P4', 'floor': 12, 'load': 0, 'oos': True}], 'per_floor_s': 2, 'door_s': 8, 'preselect': 'P2'}, {'order': ['P2'], 'starts': {'P2': 0}, 'selected': 'P2', 'done_s': 26}), ('sampled regression 15', {'cars': [{'id': 'P2', 'floor': 14, 'load': 0, 'oos': False}, {'id': 'P3', 'floor': 19, 'load': 75, 'oos': True}], 'per_floor_s': 2, 'door_s': 8, 'preselect': None}, {'order': ['P2'], 'starts': {'P2': 0}, 'selected': 'P2', 'done_s': 36}), ('sampled regression 18', {'cars': [{'id': 'P3', 'floor': 7, 'load': 0, 'oos': False}, {'id': 'P4', 'floor': 10, 'load': 300, 'oos': False}, {'id': 'P2', 'floor': 12, 'load': 300, 'oos': False}], 'per_floor_s': 2, 'door_s': 8, 'preselect': 'P2'}, {'order': ['P4', 'P2', 'P3'], 'starts': {'P4': 0, 'P2': 28, 'P3': 60}, 'selected': 'P2', 'done_s': 82})], [('regression: lobby car still takes door time', {'cars': [{'id': 'P1', 'floor': 0, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 4, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P1', 'P2'], 'starts': {'P1': 0, 'P2': 5}, 'selected': 'P1', 'done_s': 18}), ('sampled regression 15', {'cars': [{'id': 'P2', 'floor': 14, 'load': 0, 'oos': False}, {'id': 'P3', 'floor': 19, 'load': 75, 'oos': True}], 'per_floor_s': 2, 'door_s': 8, 'preselect': None}, {'order': ['P2'], 'starts': {'P2': 0}, 'selected': 'P2', 'done_s': 36}), ('sampled regression 9', {'cars': [{'id': 'P2', 'floor': 9, 'load': 300, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P1'}, {'order': ['P2'], 'starts': {'P2': 0}, 'selected': 'P2', 'done_s': 23}), ('boundary: all cars out of service', {'cars': [{'id': 'P1', 'floor': 3, 'load': 0, 'oos': True}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P1'}, {'order': [], 'starts': {}, 'selected': None, 'done_s': 0}), ('regression: out of service car preselected', {'cars': [{'id': 'P1', 'floor': 5, 'load': 0, 'oos': True}, {'id': 'P2', 'floor': 3, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P1'}, {'order': ['P2'], 'starts': {'P2': 0}, 'selected': 'P2', 'done_s': 11}), ('sampled regression 23', {'cars': [{'id': 'P4', 'floor': 10, 'load': 0, 'oos': False}, {'id': 'P1', 'floor': 9, 'load': 75, 'oos': False}, {'id': 'P3', 'floor': 19, 'load': 75, 'oos': False}], 'per_floor_s': 3, 'door_s': 8, 'preselect': 'P3'}, {'order': ['P1', 'P3', 'P4'], 'starts': {'P1': 0, 'P3': 35, 'P4': 100}, 'selected': 'P3', 'done_s': 138}), ('sampled regression 26', {'cars': [{'id': 'P2', 'floor': 14, 'load': 300, 'oos': False}, {'id': 'P3', 'floor': 14, 'load': 75, 'oos': False}, {'id': 'P1', 'floor': 3, 'load': 0, 'oos': False}, {'id': 'P4', 'floor': 15, 'load': 75, 'oos': False}], 'per_floor_s': 3, 'door_s': 8, 'preselect': 'P4'}, {'order': ['P2', 'P3', 'P4', 'P1'], 'starts': {'P2': 0, 'P3': 50, 'P4': 100, 'P1': 153}, 'selected': 'P4', 'done_s': 170}), ('sampled regression 29', {'cars': [{'id': 'P2', 'floor': 7, 'load': 75, 'oos': False}], 'per_floor_s': 3, 'door_s': 5, 'preselect': 'P1'}, {'order': ['P2'], 'starts': {'P2': 0}, 'selected': 'P2', 'done_s': 26})], [('regression: no preselection', {'cars': [{'id': 'P3', 'floor': 6, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 6, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P2', 'P3'], 'starts': {'P2': 0, 'P3': 17}, 'selected': 'P2', 'done_s': 34}), ('sampled regression 22', {'cars': [{'id': 'P2', 'floor': 0, 'load': 0, 'oos': True}, {'id': 'P1', 'floor': 0, 'load': 0, 'oos': False}], 'per_floor_s': 3, 'door_s': 8, 'preselect': 'P1'}, {'order': ['P1'], 'starts': {'P1': 0}, 'selected': 'P1', 'done_s': 8}), ('sampled regression 14', {'cars': [{'id': 'P3', 'floor': 11, 'load': 300, 'oos': False}], 'per_floor_s': 3, 'door_s': 8, 'preselect': None}, {'order': ['P3'], 'starts': {'P3': 0}, 'selected': 'P3', 'done_s': 41}), ('regression: occupied car first', {'cars': [{'id': 'P1', 'floor': 2, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 9, 'load': 80, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P2', 'P1'], 'starts': {'P2': 0, 'P1': 23}, 'selected': 'P2', 'done_s': 32}), ('regression: lobby car still takes door time', {'cars': [{'id': 'P1', 'floor': 0, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 4, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P1', 'P2'], 'starts': {'P1': 0, 'P2': 5}, 'selected': 'P1', 'done_s': 18}), ('sampled regression 34', {'cars': [{'id': 'P2', 'floor': 4, 'load': 300, 'oos': False}], 'per_floor_s': 2, 'door_s': 8, 'preselect': 'P2'}, {'order': ['P2'], 'starts': {'P2': 0}, 'selected': 'P2', 'done_s': 16}), ('sampled regression 37', {'cars': [{'id': 'P3', 'floor': 6, 'load': 75, 'oos': False}, {'id': 'P4', 'floor': 14, 'load': 75, 'oos': False}], 'per_floor_s': 3, 'door_s': 8, 'preselect': 'P2'}, {'order': ['P3', 'P4'], 'starts': {'P3': 0, 'P4': 26}, 'selected': 'P3', 'done_s': 76}), ('sampled regression 40', {'cars': [{'id': 'P4', 'floor': 16, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 5, 'load': 0, 'oos': False}, {'id': 'P1', 'floor': 1, 'load': 75, 'oos': False}, {'id': 'P3', 'floor': 11, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P3'}, {'order': ['P1', 'P2', 'P3', 'P4'], 'starts': {'P1': 0, 'P2': 7, 'P3': 22, 'P4': 49}, 'selected': 'P3', 'done_s': 86})], [('regression: out of service car preselected', {'cars': [{'id': 'P1', 'floor': 5, 'load': 0, 'oos': True}, {'id': 'P2', 'floor': 3, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P1'}, {'order': ['P2'], 'starts': {'P2': 0}, 'selected': 'P2', 'done_s': 11}), ('sampled regression 29', {'cars': [{'id': 'P2', 'floor': 7, 'load': 75, 'oos': False}], 'per_floor_s': 3, 'door_s': 5, 'preselect': 'P1'}, {'order': ['P2'], 'starts': {'P2': 0}, 'selected': 'P2', 'done_s': 26}), ('sampled regression 19', {'cars': [{'id': 'P2', 'floor': 1, 'load': 75, 'oos': False}], 'per_floor_s': 2, 'door_s': 8, 'preselect': 'P1'}, {'order': ['P2'], 'starts': {'P2': 0}, 'selected': 'P2', 'done_s': 10}), ('regression: no preselection', {'cars': [{'id': 'P3', 'floor': 6, 'load': 0, 'oos': False}, {'id': 'P2', 'floor': 6, 'load': 0, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': None}, {'order': ['P2', 'P3'], 'starts': {'P2': 0, 'P3': 17}, 'selected': 'P2', 'done_s': 34}), ('boundary: all cars out of service', {'cars': [{'id': 'P1', 'floor': 3, 'load': 0, 'oos': True}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P1'}, {'order': [], 'starts': {}, 'selected': None, 'done_s': 0}), ('sampled regression 45', {'cars': [{'id': 'P3', 'floor': 13, 'load': 75, 'oos': False}, {'id': 'P1', 'floor': 19, 'load': 0, 'oos': False}, {'id': 'P4', 'floor': 5, 'load': 0, 'oos': False}], 'per_floor_s': 3, 'door_s': 8, 'preselect': None}, {'order': ['P3', 'P4', 'P1'], 'starts': {'P3': 0, 'P4': 47, 'P1': 70}, 'selected': 'P3', 'done_s': 135}), ('sampled regression 48', {'cars': [{'id': 'P1', 'floor': 2, 'load': 75, 'oos': True}, {'id': 'P2', 'floor': 16, 'load': 300, 'oos': False}, {'id': 'P4', 'floor': 0, 'load': 0, 'oos': False}], 'per_floor_s': 3, 'door_s': 8, 'preselect': None}, {'order': ['P2', 'P4'], 'starts': {'P2': 0, 'P4': 56}, 'selected': 'P2', 'done_s': 64}), ('sampled regression 51', {'cars': [{'id': 'P1', 'floor': 2, 'load': 75, 'oos': False}, {'id': 'P4', 'floor': 4, 'load': 0, 'oos': False}, {'id': 'P3', 'floor': 16, 'load': 300, 'oos': False}, {'id': 'P2', 'floor': 4, 'load': 300, 'oos': False}], 'per_floor_s': 2, 'door_s': 5, 'preselect': 'P4'}, {'order': ['P1', 'P2', 'P3', 'P4'], 'starts': {'P1': 0, 'P2': 9, 'P3': 22, 'P4': 59}, 'selected': 'P4', 'done_s': 72})]]
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:
Return starts are too early because door time is ignored.

On emergency power in-service cars (not oos) return to the lobby one at a time: occupied cars (load > 0) first, then by lower floor, then id. Each return takes floor*per_floor_s + door_s; starts are cumulative. Afterwards the preselected car runs if it is in service, otherwise the first car of the return order (None if no car).

split: open-access