def main(): # creates a list of student and course objects in preparation file lists = preparation.main() student_list = lists[0] course_list = lists[1] session_list = lists[2] room_list = lists[3] score_max = 0 # searches 5 times for a local maximum and visualizes the best score for i in range(5): print i # executes simulated annealing local_max_schedule = simulated_annealing(student_list, course_list, session_list, room_list) schedule_room_list = local_max_schedule[0] schedule_student_list = local_max_schedule[1] score_list = score_function.main(schedule_room_list, schedule_student_list, course_list) score_local_max = score_list[0] # when new hillclimber score is better if score_local_max > score_max: max_schedule = local_max_schedule score_max = score_local_max data = max_schedule[2] # writes data of schedule to csv with open("data_simulated_annealing.csv", "wb") as f: writer = csv.writer(f) writer.writerow(["Iteration", "Score", "malus_conflict", "malus_capacity", "malus_spread", "bonus_spread"]) for row in data: writer.writerow(row) # visualizes room schedules schedule_room_list = max_schedule[0] schedule_student_list = max_schedule[1] for schedule_room in schedule_room_list: visualize.visualize(schedule_room) # visualize students schedules for schedule_student in schedule_student_list[151:152]: visualize.visualize(schedule_student) for schedule_student in schedule_student_list[155:156]: visualize.visualize(schedule_student)
import preparation import fitness_function import random global crossover_rate global mutation_rate global repairs # define constants crossover_rate = 0.7 mutation_rate = 0.1 population_size = 10 number_generations = 1000 # instantiates the framework of the schedule prep_schedule, slot_list = preparation.main() # creates 100 random schedules old_generation = [] for i in range(population_size): prep_schedule, slot_list = preparation.main() rand_schedule = random_schedule(prep_schedule, slot_list) old_generation.append(rand_schedule) generation = 0 fitness_total = [] # print results of algo for i in range(number_generations): new_generation = next_generation(old_generation, slot_list)
def main(data): prep_schedule, slot_list, course_list = preparation.main(data) for i in range(100): table_data = hill_climber(data, prep_schedule, slot_list, course_list) if table_data != False: return table_data
import preparation import score_function import schedule_maker # creates a list of student and course objects in preparation file lists = preparation.main() student_list = lists[0] course_list = lists[1] session_list = lists[2] room_list = lists[3] number_courses = len(course_list) total_students = 0 for course in course_list: number_students = len(course.students) total_students += number_students avg_students = total_students / number_courses print avg_students # # create 100 schedules # for i in range (100): # # create schedule # schedule = schedule_maker.main(student_list, course_list, session_list, room_list) # # schedule_room_list = schedule[0] # schedule_student_list = schedule[1] # course_list = schedule[2] #