dist = {('A', 'B'): 1.0, ('B', 'C'): 1.0, ('D', 'E'): 3.0}
trains = [('A', 'B', 1.0, 2.0), ('B', 'C', 2.0, 3.0), ('C', 'B', 3.5, 4.5),
    ('B', 'A', 4.5, 5.5), ('D', 'E', 1.0, 5.5)]
sources = set(list([t[0] for t in trains]))
x = pulp.LpVariable.dicts('x', trains, lowBound=0, upBound=1, cat=pulp.
    LpInteger)
y = pulp.LpVariable.dicts('y', list(dist.keys()), lowBound=0, upBound=1, cat=pulp
    .LpInteger)
s = pulp.LpVariable.dicts('s', sources, lowBound=0, upBound=1, cat=pulp.
    LpInteger)
mod = pulp.LpProblem('Train Optimization', pulp.LpMaximize)
mod += sum([(dist[k] * y[k]) for k in dist])
for t in trains:
    mod += x[t] <= s[t[0]] + sum([x[k] for k in trains if k[1] == t[0] and 
        k[3] <= t[2]]) - sum([x[k] for k in trains if k != t and k[0] == t[
        0] and k[2] <= t[2]])
mod += sum([s[k] for k in sources]) == 1
for k in dist:
    mod += y[k] <= sum([x[t] for t in trains if t[0] == k[0] and t[1] == k[
        1] or t[1] == k[0] and t[0] == k[1]])
mod.solve()
for t in trains:
    pass
График с расстоянием и временем в пути: найти наибольшее количество километров за 24 часа (с ограничениями)