Exemplo n.º 1
0
def period_spread_constraint3(schedule, exams, periods, institute_con):
    """Returns penalty

    This constraint allows an organisation to 'spread' an schedule's examinations over a specified number of periods. 
    This can be thought of an extension of the two constraints previously described.  Within the �Institutional Model 
    Index', a figure is provided relating to how many periods the solution should be �optimised' over.
    """
    period_spread_constraints = institute_con[InstitutionalEnum.PERIODSPREAD]
    period_lengths = period_spread_constraints[0].values if len(period_spread_constraints) > 0 else []
    period_to_exam = get_period_to_exam_mapping(schedule, exams, periods)
    period_to_students = dict()
    for period, exams in period_to_exam.items():
        period_to_students[period] = set(flatten(map(lambda exam: exam.students, exams)))
    periods = sorted(period_to_students.keys())
    violations = 0
    for period_length in period_lengths:
        for period_start in periods:
            cum_union = set()
            for window in range(period_start + period_length, period_start + 1, -1):
                period = period_start + window
                if period in period_to_students:
                    cum_union = cum_union | period_to_students[period]
                if (period - 1) in period_to_students:
                    students_in_period = period_to_students[period - 1]
                    intersect = students_in_period & cum_union
                    violations += len(intersect)
    return violations
Exemplo n.º 2
0
def two_exams_in_a_day_constraint(schedule, periods, exams):
    """Returns penalty

    In the case where there are three periods or more in a day, count the number of occurrences of students having 
    two exams in a day which are not directly adjacent, i.e. not back to back, and multiply this by the ' two in a 
    day' weighting provided within the 'Institutional Model Index'.
    """
    period_to_exam = get_period_to_exam_mapping(schedule, exams, periods)
    violations = 0
    for first_period in range(len(periods)):
        for second_period in range(first_period + 2, len(periods)):
            if periods[first_period].date == periods[second_period].date:
                intersect = student_intersection(period_to_exam[first_period], period_to_exam[second_period])
                violations += len(intersect)
    return violations
Exemplo n.º 3
0
def two_exams_in_a_row_constraint(schedule, periods, exams):
    """Returns penalty

    Count the number of occurrences where two examinations are taken by students straight after one another i.e. back 
    to back. Once this has been established, the number of students involved in each occurance should be added and 
    multiplied by the number provided in the �two in a row' weighting within the �Institutional Model Index'.
    """
    period_to_exam = get_period_to_exam_mapping(schedule, exams, periods)
    periods_idx = range(len(periods))
    violations = 0
    for first_period, second_period in zip(periods_idx[:-1], periods_idx[1:]):
        if first_period in period_to_exam and second_period in period_to_exam and periods[first_period].date == periods[
            second_period].date:
            intersect = student_intersection(period_to_exam[first_period], period_to_exam[second_period])
            violations += len(intersect)
    return violations