0% found this document useful (0 votes)
17 views10 pages

Classroom Allocation System

Uploaded by

rrmoni625
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views10 pages

Classroom Allocation System

Uploaded by

rrmoni625
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Dhaka International Univeristy

Project Name: Classroom Allocation System

Project Title: Classroom Scheduling and Room


Assignment Using Backtracking

Department of

Computer Science and Engineering

Batch: D-75

Course code: CSE-302

Submission Date: 14.12.2024

Submitted By:

● Rajiya Sultana Sumu (30) - Team Lead


● Muhammad Asif (40)
● Nira Nafisha (15)
● Fiza Moni (20)
● Shakila Ahmed (28)
● Sajib Hira (35)

Submitted To:

● Md Rabiul Hasan Faysal

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

Educational institutions face challenges in managing classroom schedules, especially when


classes overlap or vary in size. Ensuring each class is assigned a suitable room that meets its
capacity requirements while avoiding scheduling conflicts is a persistent problem.

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 and Approach

We used a combination of backtracking and greedy algorithms to solve the problem.

Algorithm Selection:

○ Greedy Algorithm: Larger rooms are prioritized for larger classes to


maximize room utilization.
○ Graph-Based Representation: A graph is used to model class overlaps based
on time, helping us understand which classes must be assigned to different
rooms.
○ Backtracking: This technique is used to assign rooms while ensuring capacity
and timing constraints are respected.

Justification:

Graph-based scheduling efficiently handles overlapping intervals, and backtracking


ensures a thorough exploration of room allocations when direct assignment is not
feasible.
2

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:

Traversal to identify scheduling conflicts.

5. Output:

○ Room assignments for each class.


○ Any errors or conflicts encountered during the process.

Implementation

Language/Tools Used:

● VS Code (Visual Studio Code).


● Programming Language: Python 3.7
● Python environment set.
● Modules: datetime for time parsing and scheduling logic.

Example Input

● Classes:
○ Class1: 9:00-10:30 (30 students)
3

○ Class2: 10:00-11:00 (25 students)

○ Class3: 9:30-11:00 (40 students)

● Rooms:
○ Room1: Capacity 40
○ Room2: Capacity 30

Example Output

● Class1 → Room1
● Class2 → Room2
● Class3 → Not Assigned
4

Results and Evaluation:

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

The algorithm handles moderate-sized schedules efficiently. However, scalability becomes a


challenge with larger datasets, requiring optimization techniques like dynamic programming
or heuristic-based approaches.

Summary

This project demonstrates the practical application of backtracking in solving complex


scheduling problems. By combining greedy strategies for room assignment with
backtracking for conflict resolution, we can efficiently solve real-world scheduling
problems.

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)

classes[class_name] = (start_time, end_time, size)

rooms = {}
num_rooms = int(input("Enter the number of classrooms: "))
for i in range(1, num_rooms + 1):
room_name = f"Room{i}"
6

capacity = int(input(f"Enter capacity for {room_name}: "))


rooms[room_name] = capacity

return classes, rooms

def main():
"""
Main function to run the classroom scheduler.
"""
print("Welcome to the Classroom Scheduler!")

classes, rooms = collect_input()

class_times = {cls: (start, end) for cls, (start, end, _) in


classes.items()}
class_sizes = {cls: size for cls, (_, _, size) in classes.items()}

graph = build_class_overlap_graph(class_times)

room_allocation, unassigned = assign_classrooms(graph, rooms,


class_sizes, 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())

def is_available(room, start, end):


"""
Check if a room is available during the given time period.

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

def allocate_room(cls, remaining_students, start, end):


"""
Attempt to allocate rooms to a class using backtracking.

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

if cls not in assignments:


assignments[cls] = []
assignments[cls].append((room, allocated))

room_usage[room].append((start, end))

if remaining_students == 0:
unassigned.discard(cls)
return True

return False

for cls, size in class_sizes.items():


start, end = class_times[cls]
if not allocate_room(cls, size, start, end):
unassigned.add(cls)

return assignments, unassigned

Graph_builder.py:
def build_class_overlap_graph(class_times):
"""
9

Build a graph where each node represents a class, and an edge


connects classes
that have overlapping time periods.

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}

def is_overlapping(t1, t2):


"""
Check if two time periods overlap.

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])

for cls1, time1 in class_times.items():


for cls2, time2 in class_times.items():
if cls1 != cls2 and is_overlapping(time1, time2):
graph[cls1].append(cls2)

return graph

You might also like