Exemple #1
0
def compute_all_sections():
    # listRounds = decryptScheduleFile(path_to_schedule)
    listOfSections = getListOfSectionsCompleted(meeting_history_file,
                                                pre_schedule_waiting_table,
                                                True)
    for section in listOfSections.sections:
        prev_meetings_matrix = section.meetings_matrix.copy()
        prev_waiting_vector = section.waiting_vector.copy()
        listRounds = getScheduleFileRounds(len(section.pairs))
        referenceMatrix = computeTheoreticalNumberingMatrix(
            section, listRounds)
        # GENERATE INSTANCE OF THE PROBLEM
        instance = BRIDGEInstance(section, prev_meetings_matrix,
                                  prev_waiting_vector, listRounds,
                                  referenceMatrix)
        obj, components = Formigueiro.Solve(antCls=BRIDGEAnt,
                                            instance=instance,
                                            numIterations=5000,
                                            numAnts=50,
                                            alpha=3,
                                            beta=0.8,
                                            Q=2)
        section.setBestFitnessReached(obj)
        res = components
        res.sort(key=operator.itemgetter(0))
        section.setAssignments(res)
        print(
            f'THEORETICAL BEST FITNESS: {instance.fitness_best/instance.fitness_best}'
        )
        print(f'Fitness Overhead: {obj}')
        print(
            f'THEORETICAL WORST FITNESS: {instance.fitness_worst/instance.fitness_best}'
        )
        res = components
        res.sort(key=operator.itemgetter(0))
        # The num of solutions tried is obviously num of iterations * num of ants
        print(f'\nNum of Solutions Constructed: {instance.solutionsTried}\n')
        print(f'\nThe assignments are: {res}\n')
    # Show Results
    for section in listOfSections.sections:
        print('\n\n')
        print(f'Section Fitness: {section.best_fitness}')
        print(f'Assignments: {section.assignments}')
        final_matrix_vector = compute_final_meeting_matrix_from_solution(
            section.listPairNums, listRounds, section.meetings_matrix.copy(),
            section.waiting_vector.copy(), section.assignments)
        print(f'Final Matrix\n{final_matrix_vector[0]}')
        if len(section.pairs) % 2 != 0:
            # print(f'Prev Waiting Vector\n{section.waiting_vector}')
            print(f'Waiting Vector\n{final_matrix_vector[1]}')
Exemple #2
0
def compute_all_sections():
    listRounds = decryptScheduleFile(path_to_schedule)
    listOfSections = getListOfSectionsCompleted(meeting_history_file,
                                                pre_schedule_file, False)
    for section in listOfSections.sections:
        prev_meetings_matrix = section.meetings_matrix.copy()
        referenceMatrix = computeTheoreticalNumberingMatrix(
            section, listRounds)
        # GENERATE INSTANCE OF THE PROBLEM
        instance = BRIDGEInstance(section, prev_meetings_matrix, listRounds,
                                  referenceMatrix)
        obj, components = Formigueiro.Solve(antCls=BRIDGEAnt,
                                            instance=instance,
                                            numIterations=1000,
                                            numAnts=22,
                                            alpha=1,
                                            beta=1)
        section.setBestFitnessReached(obj)
        res = components
        res.sort(key=operator.itemgetter(0))
        section.setAssignments(res)
        print(
            f'THEORETICAL BEST FITNESS: {instance.fitness_best/instance.fitness_best}'
        )
        print(f'Fitness Overhead: {obj}')
        print(
            f'THEORETICAL WORST FITNESS: {instance.fitness_worst/instance.fitness_best}'
        )
        res = components
        res.sort(key=operator.itemgetter(0))
        print(f'\nThe assignments are: {res}\n')
    # Show Results
    for section in listOfSections.sections:
        print(f'Section Fitness: {section.best_fitness}')
        print(f'Assignments: {section.assignments}')
        final_matrix = compute_final_meeting_matrix_from_solution(
            listRounds, section.meetings_matrix.copy(), section.assignments)
        print(f'Final Matrix\n{final_matrix}')
Exemple #3
0
    df.columns = series_cols
    for round in listOfRounds.rounds:
        for meeting in round.getTablePairs():
            # single meeting in schedule file
            pair1id = int(meeting[0])
            pair2id = int(meeting[1])
            df[pair1id][pair2id] += 4
            df[pair2id][pair1id] += 4
    print('Theoretical Assignment Reference Matrix is:')
    print(df)
    return df


listRounds = decryptScheduleFile(path_to_schedule)

listOfSections = getListOfSectionsCompleted(meeting_history_file,
                                            pre_schedule_file)
section = listOfSections.sections[0]
prev_meetings_matrix = section.meetings_matrix.copy()

for pair in section.pairs:
    print(f'Pair NUM: {pair.num} -- ID: {pair.id}')

referenceMatrix = computeTheoreticalNumberingMatrix(section, listRounds)

# GENERATE INSTANCE OF THE PROBLEM
instance = BRIDGEInstance(section, prev_meetings_matrix, listRounds,
                          referenceMatrix)

# ANT-COLONY OPTIMIZATION
# BEST FITNESS IN INTERATION ## GLOBAL BEST FITNESS ## BEST FITNESS FROM ALL ANTS
print('BEST ITER FITNESS -- GLOBAL BEST FITNESS -- BEST ANT FITNESS')
Exemple #4
0
async def main():
    listOfSections = getListOfSectionsCompleted(meeting_history_file,
                                                pre_schedule_waiting_table,
                                                True)
    await compute(listOfSections)