Classroom Allocation System
Classroom Allocation System
Department of
Batch: D-75
Submitted By:
Submitted To:
Lecturer, CSE
Dhaka International University
1
Objective
This project aims to develop a Classroom Scheduler that efficiently allocates classrooms to
classes based on their size and timing. The system ensures no overlapping classes are
assigned to the same room, maximizing resource utilization while addressing constraints like
room capacity and timing conflicts.
Problem Statement
Scope
This project focuses on solving the scheduling problem algorithmically using backtracking
and greedy techniques (i.e graph). Nodes represent classes, and edges indicate timing
conflicts. Efficient scheduling algorithms ensure timely and optimal room assignments,
making this project relevant to Algorithm Design & Analysis course.
Algorithm Selection:
Justification:
Methodology
1. Input:
○ Class schedules (start and end times).
○ Room capacities.
○ Class sizes.
2. Backtracking Process:
○ For each class, attempt to assign the largest available room that fits the class
size and does not conflict with other scheduled classes.
○ If a valid assignment cannot be found, backtrack and try a different
configuration.
3. Greedy Optimization:
○ Sort rooms by capacity, and try to assign the largest room to the largest class
first
4. Graph:
5. Output:
Implementation
Language/Tools Used:
Example Input
● Classes:
○ Class1: 9:00-10:30 (30 students)
3
● Rooms:
○ Room1: Capacity 40
○ Room2: Capacity 30
Example Output
● Class1 → Room1
● Class2 → Room2
● Class3 → Not Assigned
4
Performance Analysis
● Time Complexity:
○ Graph Construction: , where is the number of classes.
○ Backtracking: , where is the number of rooms.
● Space Complexity:
○ Graph Storage: , where is the number of edges (overlapping classes).
Discussion
Summary
Future Work
1. Integrate the system with a user interface for easier room assignment management.
2. Improve scalability for larger datasets with optimized algorithms.
3. Add real-time scheduling updates.
4. Extend functionality to include room preferences or special equipment requirements.
Scripts:
main.py:
from datetime import datetime
from graph_builder import build_class_overlap_graph
from scheduler import assign_classrooms
def parse_time(input_time):
"""
Convert user input into a time object.
Parameters:
input_time (str): Time in HH or HH:MM format.
5
Returns:
datetime.time: Parsed time object.
"""
try:
if ":" in input_time:
return datetime.strptime(input_time, "%H:%M").time()
else:
return datetime.strptime(input_time, "%H").time()
except ValueError:
print("Invalid time format. Please enter in HH or HH:MM
format.")
exit()
def collect_input():
"""
Gather user input for classes and rooms.
Returns:
tuple: (classes, rooms)
- classes (dict): Class details with times and sizes.
- rooms (dict): Room names and capacities.
"""
classes = {}
num_classes = int(input("Enter the number of classes: "))
for i in range(1, num_classes + 1):
class_name = f"Class{i}"
start_time = input(f"Enter start time for {class_name} (HH or
HH:MM): ")
end_time = input(f"Enter end time for {class_name} (HH or
HH:MM): ")
size = int(input(f"Enter the number of students in
{class_name}: "))
start_time = parse_time(start_time)
end_time = parse_time(end_time)
rooms = {}
num_rooms = int(input("Enter the number of classrooms: "))
for i in range(1, num_rooms + 1):
room_name = f"Room{i}"
6
def main():
"""
Main function to run the classroom scheduler.
"""
print("Welcome to the Classroom Scheduler!")
graph = build_class_overlap_graph(class_times)
print("\nRoom Allocation:")
for cls in classes:
if cls in room_allocation:
allocated_rooms = ", ".join([f"{room} ({count} students)"
for room, count in room_allocation[cls]])
print(f"{cls} -> {allocated_rooms}")
else:
print(f"{cls} -> Not assigned")
if unassigned:
print("\nUnassigned Classes:")
for cls in unassigned:
print(f"- {cls}")
if __name__ == "__main__":
main()
scheduler.py:
def assign_classrooms(graph, room_caps, class_sizes,
class_times):
7
"""
Assign classrooms to classes, ensuring timing and capacity
constraints are met.
Parameters:
graph (dict): A graph where nodes are classes and edges
represent overlapping classes.
room_caps (dict): A dictionary with room names and their
capacities.
class_sizes (dict): A dictionary with class names and their
sizes.
class_times (dict): A dictionary with class names and their
time periods.
Returns:
tuple: (assigned_rooms, unassigned_classes)
- assigned_rooms (dict): Rooms assigned to each class.
- unassigned_classes (set): Classes that couldn't be
assigned.
"""
sorted_rooms = sorted(room_caps.items(), key=lambda x: -x[1]) #
Sort rooms by capacity (largest first)
room_usage = {room: [] for room in room_caps} # Tracks time
periods each room is occupied
assignments = {}
unassigned = set(graph.keys())
Parameters:
room (str): Room name.
start, end (time): Start and end times of the period.
Returns:
bool: True if room is available, False otherwise.
"""
for occupied_start, occupied_end in room_usage[room]:
if max(start, occupied_start) < min(end, occupied_end):
return False
return True
8
Parameters:
cls (str): Class name.
remaining_students (int): Number of students yet to be
assigned.
start, end (time): Class timing.
Returns:
bool: True if allocation is successful, False otherwise.
"""
for room, capacity in sorted_rooms:
if is_available(room, start, end) and remaining_students >
0:
allocated = min(remaining_students, capacity)
room_caps[room] -= allocated
remaining_students -= allocated
room_usage[room].append((start, end))
if remaining_students == 0:
unassigned.discard(cls)
return True
return False
Graph_builder.py:
def build_class_overlap_graph(class_times):
"""
9
Parameters:
class_times (dict): A dictionary with class names as keys and
time periods as values.
Example: {"Class1": (start1, end1),
"Class2": (start2, end2)}
Returns:
dict: A graph represented as an adjacency list.
Example: {"Class1": ["Class2"], "Class2": ["Class1"]}
"""
graph = {cls: [] for cls in class_times}
Parameters:
t1, t2 (tuple): Start and end times of two periods.
Example: (start1, end1), (start2, end2)
Returns:
bool: True if periods overlap, False otherwise.
"""
return max(t1[0], t2[0]) < min(t1[1], t2[1])
return graph