Genetic algorithm - timetable

From Computer Science Wiki
This a problem set for you to work through [1]

This is a problem set. Some of these are easy, others are far more difficult. The purpose of these problems sets are:

  1. to build your skill applying computational thinking to a problem
  2. to assess your knowledge and skills of different programming practices


Learning objective[edit]

The learning objective for this problem set is to apply your understanding of genetic algorithms.

The Problem[edit]

Please find below a python file which creates 4 dictionaries of requests, one for grade 9, 10, 11 and 12.

  1. Please construct a genetic algorithm which ideally meets the maximum number of requests.
  2. Your algorithm should meet the maximum number of requests.
  3. Your algorithm should have a fitness function
  4. Your algorithm should have selection strategy

Please understand we are only dealing with requests. Creating the timetable (when each class meets) is a different problem set.

timetable generator[edit]

I am very grateful to a 12th grade student who wrote this timetable generator for me in 2021. :-)

import random

COURSE_SIZE = 15
CLASS_SIZE = 50
TEACHERS_SIZE = 10
ROOM_SIZE = 10
BLOCKS_SIZE = 4
CAPACITY_MIN = 18
CAPACITY_MAX = 25
REQUEST_COURSE_SIZE = 6

courses = [i for i in range(COURSE_SIZE)]

grade_9_students = [i for i in range(CLASS_SIZE)]
grade_10_students = [i for i in range(CLASS_SIZE, CLASS_SIZE*2)]
grade_11_students = [i for i in range(CLASS_SIZE*2, CLASS_SIZE*3)]
grade_12_students = [i for i in range(CLASS_SIZE*3, CLASS_SIZE*4)]

teachers = [i for i in range(TEACHERS_SIZE)]
rooms = [i for i in range(ROOM_SIZE)]

# for this timetable, there are 4 blocks per day
blocks = [i for i in range(BLOCKS_SIZE)]


# Capacity is the room ID and then capacity of course:
capacity = [[i, random.randint(CAPACITY_MIN, CAPACITY_MAX)] for i in rooms]

def generate_request_dict(grade):
    request_dict = {}
    for i in grade:
        request_dict[i] = random.sample(courses, REQUEST_COURSE_SIZE)
    return request_dict

requests_dict_9, requests_dict_10, requests_dict_11, requests_dict_12 = generate_request_dict(grade_9_students), generate_request_dict(grade_10_students), generate_request_dict(grade_11_students), generate_request_dict(grade_12_students)



# to see the dictionaries for each part of our schedule, uncomment the lines below
# and execute this program
# print(requests_dict_9)
# print(requests_dict_10)
# print(requests_dict_11)
# print(requests_dict_12)

How you will be assessed[edit]

Your solution will be graded using the following axis:


Scope

  • To what extent does your code implement the features required by our specification?
  • To what extent is there evidence of effort?

Correctness

  • To what extent did your code meet specifications?
  • To what extent did your code meet unit tests?
  • To what extent is your code free of bugs?

Design

  • To what extent is your code written well (i.e. clearly, efficiently, elegantly, and/or logically)?
  • To what extent is your code eliminating repetition?
  • To what extent is your code using functions appropriately?

Style

  • To what extent is your code readable?
  • To what extent is your code commented?
  • To what extent are your variables well named?
  • To what extent do you adhere to style guide?

References[edit]

A possible solution[edit]

Click the expand link to see one possible solution, but NOT before you have tried and failed!

not yet!