def data_generator_teachers(courses): names = ["Green", "Brown", "Wood", "Steal", "Water"] density = [2, 3] teachers = [] for i in range(len(names)): teachers.append({"id": i, "name": names[i], "courses": []}) teachers_len = len(teachers) for c_id in range(len(courses)): dens = random.randint(*density) teach = random_elements(range(teachers_len), dens) for t in teach: teachers[t]['courses'].append(c_id) return teachers
def next_gen(prev_gen, reproduction_number=10, surviving_number=1, crossover_points=[1, 5], mutation_prob=0.01): population = len(prev_gen) reproduction_gen = prev_gen[:reproduction_number] new_gen = prev_gen[:surviving_number].copy() while len(new_gen) < population: parents = random_elements(reproduction_gen, 2) children = crossover(*parents, random.randint(*crossover_points)) new_gen.append(mutation(children[0], mutation_prob)) new_gen.append(mutation(children[1], mutation_prob)) new_gen = ranking(new_gen[:population]) top5 = [str(penalty(sch)) for sch in new_gen[:5]] print("the best 5: ", ", ".join(top5)) return new_gen
def data_generator_groups(courses): names = ["K-10", "K-11", "K-12", "K-13", "K-14"] students_range = [25, 30] courses_quantity = [4, 6] groups = [] courses_len = len(courses) n_id = -1 for name in names: n_id += 1 groups.append({ "id": n_id, "name": name, "students": random.randint(*students_range), "courses": random_elements(range(courses_len), random.randint(*courses_quantity)) }) return groups