Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions Constants/classroom_tt.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class ClassroomTimetable:
def __init__(self):
# Dictionary to hold timetables for each classroom
self.classroom_timetable = {}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is for each classroom timetable and also this will be used for making timetable for the labs

def generate_classroom_timetable(self, chromosome):
for week, days in chromosome.items():
for day, sections in days.items():
Expand Down Expand Up @@ -35,14 +35,14 @@ def save_timetable_to_json(self, file_path="Constants/classroom_timetable.json")
except Exception as e:
print(f"Error saving timetable to '{file_path}': {e}")

if __name__ == "__main__":
# Generate classroom-wise timetable
classroom_timetable = ClassroomTimetable()
w = {
"Week 2": SampleChromosome.schedule2,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This main function was taking chromosome from samples.py and if only the above function will be called then only a json format will be send

"Week 1": SampleChromosome.schedule1
}
classroom_tt = classroom_timetable.generate_classroom_timetable(w)
print(classroom_tt)
# Save as JSON
classroom_timetable.save_timetable_to_json()
# if __name__ == "__main__":
# # Generate classroom-wise timetable
# classroom_timetable = ClassroomTimetable()
# w = {
# "Week 2": SampleChromosome.schedule2,
# "Week 1": SampleChromosome.schedule1
# }
# classroom_tt = classroom_timetable.generate_classroom_timetable(w)
# print(classroom_tt)
# # Save as JSON
# classroom_timetable.save_timetable_to_json()
83 changes: 0 additions & 83 deletions Constants/classroom_tt_csv.py

This file was deleted.

2 changes: 1 addition & 1 deletion Constants/constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Defaults:
starting_section_fitness = 1000
max_class_capacity = 250
initial_no_of_chromosomes = 1000
total_no_of_generations = 100
total_no_of_generations = 10
class_strength = 50


Expand Down
5 changes: 2 additions & 3 deletions Constants/helper_routines.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ def update_matrix_for_best(
slot_index = time_slot_map[time_slot_str]

# Now set availability to False
teacher_availability_matrix[teacher_id][day_index][
slot_index - 1
] = False
if(teacher_id!=None):
teacher_availability_matrix[teacher_id][day_index][slot_index - 1] = False

return teacher_availability_matrix

Expand Down
81 changes: 0 additions & 81 deletions Constants/teacher_tt_csv.py

This file was deleted.

26 changes: 16 additions & 10 deletions GA/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ def __init__(self, config: TimetableConfig):
self.teacher_availability = copy.deepcopy(config.teacher_availability_matrix)
self.lab_availability = copy.deepcopy(config.lab_availability_matrix)

def update_teacher_workload(self, best_teacher_matrix):
teacher_workload = {
teacher: sum(sum(1 for slot in day if not slot) for day in availability)
for teacher, availability in best_teacher_matrix.items()
}
return teacher_workload

def _update_lab_availability(self, best_timetable):
updated_lab = copy.deepcopy(self.config.lab_availability_matrix)
for weekday, daily_schedule in best_timetable.items():
Expand All @@ -54,7 +61,7 @@ def _update_lab_availability(self, best_timetable):
if lab in updated_lab and ts_index is not None:
updated_lab[lab][day_index][ts_index - 1] = False
return updated_lab

def _generate_timetable(self, teacher_matrix):
tg = TimeTableGeneration(
teacher_subject_mapping=self.config.teacher_subject_mapping,
Expand Down Expand Up @@ -104,7 +111,6 @@ def _generate_timetable(self, teacher_matrix):
mutated = [TimeTableMutation().mutate_schedule_for_week(ch) for ch in crossover_chromosomes]
if self.config.prev_mutated:
mutated.extend(self.config.prev_mutated)

best_chromosome, best_score = None, -1
for key, score in selected.items():
score = int(score)
Expand All @@ -125,12 +131,9 @@ def run(self):
self.config.prev_mutated = None

for _ in range(self.config.total_generations):
teacher_copy = copy.deepcopy(initial_teacher)
best, updated_teacher, selected, mutated = self._generate_timetable(teacher_copy)
best, updated_teacher, selected, mutated = self._generate_timetable(copy.deepcopy(initial_teacher))
best_chromosome = best

self.config.prev_selected = selected
self.config.prev_mutated = mutated
self.config.prev_selected, self.config.prev_mutated = selected, mutated

updated_teacher = update_matrix_for_best(
best_chromosome,
Expand All @@ -140,7 +143,10 @@ def run(self):
)

updated_lab = self._update_lab_availability(best_chromosome)
return best_chromosome, updated_teacher, updated_lab
teacher_workload = self.update_teacher_workload(updated_teacher)

return best_chromosome, updated_teacher, updated_lab, teacher_workload



def run_timetable_generation(
Expand Down Expand Up @@ -207,7 +213,7 @@ def run_timetable_generation(
TeacherWorkload.Weekly_workLoad.keys(), 5, 7
)

best_tt, final_teacher, final_lab = run_timetable_generation(
best_tt, final_teacher, final_lab,weekly_workload = run_timetable_generation(
teacher_subject_mapping=SubjectTeacherMap.subject_teacher_map,
total_sections={"A": 70, "B": 100, "C": 75, "D": 100},
total_classrooms={"R1": 200, "R2": 230, "R3": 240, "R4": 250, "R5": 250},
Expand Down Expand Up @@ -255,4 +261,4 @@ def run_timetable_generation(
)

from icecream import ic
ic(best_tt, final_teacher, final_lab)
ic(best_tt, final_teacher, final_lab,weekly_workload)
Loading