コード例 #1
0
def test_small_distance_from_other_schedule(slots, events):
    X_orig = np.array([
        [1, 0, 0, 0, 0, 0, 0],
        [0, 0, 0, 0, 1, 0, 0],
        [0, 1, 0, 0, 0, 0, 0]
    ])
    schedule = scheduler.array_to_schedule(array=X_orig, slots=slots,
                                           events=events)
    solution = scheduler.solution(
        events=events, slots=slots,
        objective_function=of.number_of_changes,
        original_schedule=schedule,
    )
    assert type(solution) is list
    assert list(solution) == [(0, 5), (1, 4), (2, 6)]

    X_orig = np.array([
        [0, 0, 0, 0, 0, 0, 1],
        [0, 0, 1, 0, 0, 0, 0],
        [0, 1, 0, 0, 0, 0, 0]
    ])
    schedule = scheduler.array_to_schedule(array=X_orig, slots=slots,
                                           events=events)
    solution = scheduler.solution(
        events=events, slots=slots,
        objective_function=of.number_of_changes,
        original_schedule=schedule,
    )
    assert list(solution) == [(0, 6), (1, 0), (2, 5)]
コード例 #2
0
def test_unsolvable_raises_error(events):
    slots = [
        Slot(
            venue='Main Hall', starts_at='15-Sep-2016 09:30', duration=30,
            capacity=50, session="01 Morning A"
        )
    ]
    with pytest.raises(ValueError):
        scheduler.solution(events, slots)
コード例 #3
0
def test_unsolvable_raises_error(events):
    slots = [
        Slot(
            venue='Main Hall', starts_at=datetime(2016, 9, 15, 9, 30),
            duration=30, capacity=50, session="01 Morning A"
        )
    ]
    with pytest.raises(ValueError):
        scheduler.solution(events, slots)
コード例 #4
0
def test_demand_difference_schedule(slots, events):
    solution = scheduler.solution(
        events=events, slots=slots,
        objective_function=of.capacity_demand_difference
    )
    assert type(solution) is list
    assert list(solution) == [(0, 3), (1, 4), (2, 6)]
コード例 #5
0
def test_solution_solver_recognised_by_pulp_raises_error(events, slots):
    with pytest.raises(AttributeError):
        scheduler.solution(events, slots, solver="Not a real solver")
コード例 #6
0
speaker_clashes = definition['speaker_clashes']
talk_clashes = {
    talks.index(talk): [
        talks.index(t) for s in clashing_speakers for t in talks
        if t['speaker'] == s
    ]
    for speaker, clashing_speakers in speaker_clashes.items() for talk in talks
    if talk['speaker'] == speaker
}

for talk, clashing_talks in talk_clashes.items():
    events['talk'][talk].add_unavailability(
        *[events['talk'][t] for t in clashing_talks])

solution = scheduler.solution(events['talk'],
                              slots['talk'],
                              solver=pulp.GLPK())

conference = {
    'session_times': session_times,
    'slot_times': slot_times,
    'venues': venues,
    'days': days,
    'slots': slots,
    'events': events,
    'solution': solution
}

with open('definition/conference.bin', 'wb') as file:
    pickle.dump(conference, file)
コード例 #7
0
def solution(shape):
    return [item for item in scheduler.solution(shape)]
コード例 #8
0
def solution(events, slots):
    return list(scheduler.solution(events, slots))