Ejemplo n.º 1
0
def test_schedule_unscheduled_event_has_violations(events, slots):
    # schedule with event 1 not scheduled
    schedule = (ScheduledItem(event=events[0], slot=slots[2]),
                ScheduledItem(event=events[2], slot=slots[5]))
    violations = list(validator.schedule_violations(schedule, events, slots))
    assert violations == [
        'Event either not scheduled or scheduled multiple times - event: 1'
    ]
Ejemplo n.º 2
0
def test_unchanged_slot_schedule_difference(events, slots):
    old_schedule = (
        ScheduledItem(events[0], slots[1]),
        ScheduledItem(events[1], slots[4]),
        ScheduledItem(events[2], slots[2])
    )
    difference = scheduler.slot_schedule_difference(
        old_schedule, old_schedule)
    assert difference == []
Ejemplo n.º 3
0
def test_removed_event_schedule_difference(slots):
    events = [
        Event(name='Talk 1', duration=30, demand=30),
        Event(name='Talk 2', duration=30, demand=500),
        Event(name='Workshop 1', duration=60, demand=20),
        Event(name='Workshop 2', duration=60, demand=20)
    ]
    old_schedule = (
        ScheduledItem(events[0], slots[1]),
        ScheduledItem(events[1], slots[4]),
        ScheduledItem(events[2], slots[2]),
        ScheduledItem(events[3], slots[5])
    )
    new_schedule = (
        ScheduledItem(events[0], slots[1]),
        ScheduledItem(events[1], slots[3]),
        ScheduledItem(events[2], slots[4])
    )
    difference = scheduler.event_schedule_difference(
        old_schedule, new_schedule)
    expected = [
        ChangedEventScheduledItem(events[1], slots[4], slots[3]),
        ChangedEventScheduledItem(events[2], slots[2], slots[4]),
        ChangedEventScheduledItem(events[3], slots[5], None)
    ]
    assert difference == expected
Ejemplo n.º 4
0
def test_removed_slot_schedule_difference(events, slots):
    old_schedule = (
        ScheduledItem(events[0], slots[1]),
        ScheduledItem(events[1], slots[4]),
        ScheduledItem(events[2], slots[2])
    )
    new_schedule = (
        ScheduledItem(events[1], slots[1]),
        ScheduledItem(events[0], slots[4]),
    )
    difference = scheduler.slot_schedule_difference(
        old_schedule, new_schedule)
    expected = [
        ChangedSlotScheduledItem(slots[1], events[0], events[1]),
        ChangedSlotScheduledItem(slots[2], events[2], None),
        ChangedSlotScheduledItem(slots[4], events[1], events[0])
    ]
    assert difference == expected
Ejemplo n.º 5
0
def solution_to_schedule(solution, events, slots):
    """Convert a schedule from solution to schedule form

    Parameters
    ----------
    solution : list or tuple
        of tuples of event index and slot index for each scheduled item
    events : list or tuple
        of :py:class:`resources.Event` instances
    slots : list or tuple
        of :py:class:`resources.Slot` instances

    Returns
    -------
    list
        A list of instances of :py:class:`resources.ScheduledItem`
    """
    return [
        ScheduledItem(event=events[item[0]], slot=slots[item[1]])
        for item in solution
    ]
Ejemplo n.º 6
0
def test_changed_event_schedule_difference(events, slots):
    old_schedule = (
        ScheduledItem(events[0], slots[1]),
        ScheduledItem(events[1], slots[4]),
        ScheduledItem(events[2], slots[2])
    )
    new_schedule = (
        ScheduledItem(events[0], slots[1]),
        ScheduledItem(events[1], slots[3]),
        ScheduledItem(events[2], slots[4])
    )
    difference = scheduler.event_schedule_difference(
        old_schedule, new_schedule)
    expected = [
        ChangedEventScheduledItem(events[1], slots[4], slots[3]),
        ChangedEventScheduledItem(events[2], slots[2], slots[4])
    ]
    assert difference == expected
Ejemplo n.º 7
0
def array_to_schedule(array, events, slots):
    """Convert a schedule from array to schedule form

    Parameters
    ----------
    array : np.array
        An E by S array (X) where E is the number of events and S the
        number of slots. Xij is 1 if event i is scheduled in slot j and
        zero otherwise
    events : list or tuple
        of :py:class:`resources.Event` instances
    slots : list or tuple
        of :py:class:`resources.Slot` instances

    Returns
    -------
    list
        A list of instances of :py:class:`resources.ScheduledItem`
    """
    scheduled = np.transpose(np.nonzero(array))
    return [
        ScheduledItem(event=events[item[0]], slot=slots[item[1]])
        for item in scheduled
    ]
Ejemplo n.º 8
0
def schedule(events, slots, constraints=None, existing=None):
    shape = params.Shape(len(events), len(slots))
    return (ScheduledItem(event=events[item[0]], slot=slots[item[1]])
            for item in solution(shape, constraints, existing))
Ejemplo n.º 9
0
def valid_schedule(events, slots):
    return [
        ScheduledItem(event=events[0], slot=slots[2]),
        ScheduledItem(event=events[1], slot=slots[4]),
        ScheduledItem(event=events[2], slot=slots[5])
    ]