Lab Assignment 2 (Fall 24)
Lab Assignment 2 (Fall 24)
Lab Assignment 2 (Fall 24)
11
10
9
8
7
6
5
4
3
2
1
1
2
3
4
5
6
7
8
9
10
Lab Assignment 2
Part 1 [7 points]
Brac University plans to optimize its course scheduling for the upcoming academic
semester. The university offers a variety of courses across different disciplines,
each with specific scheduling requirements and constraints. The university needs
to find a way to schedule its courses into a limited number of timeslots per day
while ensuring that each course is scheduled exactly once and no timeslot has
more than one course planned at the same time.
You are tasked with optimizing the schedule for courses offered at Brac University
using the popular Genetic Algorithm.
Each chromosome will be a binary string that encodes the schedule of courses
across different timeslots. Here's how we will represent a chromosome:
● Length of the Chromosome: The length of a chromosome will be equal to
NxT ( product of N ∧T ), where N is the number of courses and T is the number
of timeslots.
● Structure of the Chromosome: Each chromosome will be divided into T
segments, where each segment will be of length N . Each segment will
represent a timeslot, and each bit within a segment will represent whether
a particular course is scheduled in that timeslot.
Fitness Calculation:
● The fitness function will evaluate each solution based on the number of
course overlaps and consistency of a course.
● The fitness function evaluates the quality of a schedule based on
minimizing course overlaps and making sure a course is scheduled exactly
once:
Fitness(S)=−[ Penalt y overlap (S)+ Penalt y consistency (S)]
Here:
● Penalt y overlap (S): ∑(Number of courses overlap ∈schedule S∈the same timeslot) .
Overlap Penalty:
Task Breakdown:
1. Model the course schedule array in a way suitable for the problem.
2. Implement the fitness function that penalizes overlapping courses and
ensures each course is scheduled exactly once.
3. Choose two parents based on random selection for crossover. Show it as a
separate function.
4. Perform single-point crossover to create 2 offspring from each pair of
selected parents. Show it as a separate function.
5. Write the mutation function to introduce random changes.
6. Create a population of randomly generated course schedules.
7. Run genetic algorithms on the population until the highest fitness has been
reached and/or the number of maximum iterations has been reached.
Input
The first line has a number N denoting the number of courses and a number T
denoting the number of timeslots for a particular day. It will be followed by N
lines each having a string that represents a course code that needs to be
scheduled where,
T>=N
[In this problem statement, we are considering that 1 course will have only 1
section]
Output
The output should be a binary string denoting 1 for scheduled courses and 0 for
not scheduled courses in each timeslot. A string consisting of all zeros won’t be
accepted. You also need to print the fitness value of the output string.
Example:
Sample Input
33
CSE110
MAT110
PHY112
Sample Output
110110010
-6
Explanation
Chromosome Representation
● N×T=3×3=9
● A chromosome of length 9 represents the schedule of courses across 3 timeslots.
● Each timeslot is represented by a segment of length N=3.
Fitness Calculation
● Timeslot 1: 110
○ CSE110: 1 (scheduled)
○ MAT110: 1 (scheduled)
○ PHY112: 0 (not scheduled)
● Timeslot 2: 110
○ CSE110: 1 (scheduled)
○ MAT110: 1 (scheduled)
○ PHY112: 0 (not scheduled)
● Timeslot 3: 010
○ CSE110: 0 (not scheduled)
○ MAT110: 1 (scheduled)
○ PHY112: 0 (not scheduled)
Penalty Calculation
Overlap Penalty:
Consistency Penalty:
Summary
For this part randomly select two parents from the initial population of your
problem statement. Then perform a two-point crossover to generate two
children. The two points have to be chosen randomly, but it has to be made sure
the second point always comes after the first point.
For two points crossover, we have randomly chosen the following points:
1st point:- between index 2 and index 3
2nd point:- between index 6 and index 7
[In this part, you just need to iterate once and print the resultant offspring after
doing the crossover]
Part 3 [0 points]
In part 1, you selected parents through random sampling from the initial
population. Another advanced technique for parent selection is known as
Tournament Selection. Please take some time to research and understand this
method at home. Might be helpful in the near future!