An intelligent timetable generation system using LangChain, Groq LLM, and LangGraph for creating optimal course schedules without conflicts.
- Intelligent Scheduling: Uses Groq LLM (ChatGroq) to generate optimal timetables
- Conflict Resolution: Automatically detects and resolves scheduling conflicts
- Faculty Workload Management: Ensures fair distribution and prevents overloading
- Credit Distribution: Balances course load across days
- Graph-based Workflow: Uses LangGraph for structured processing pipeline
- Course: Course information with credits, faculty, and preferences
- Faculty: Faculty details with workload limits and expertise
- TimetableSlot: Individual schedule entries
- TimeSlot: Time period definitions
- TimetableAgent: LLM-powered agent for generating and optimizing schedules
- Uses ChatGroq for intelligent decision making
- Handles initial generation, conflict resolution, and optimization
- TimetableValidator: Checks for scheduling conflicts
- TimetableOptimizer: Resolves conflicts and improves distribution
- Validates faculty time conflicts, room conflicts, and workload limits
- TimetableGraph: LangGraph-based workflow orchestration
- Manages the complete pipeline from generation to finalization
- Iterative conflict resolution with optimization
- Clone or download the project
- Install dependencies:
pip install -r requirements.txt- Set up your Groq API key:
- Get API key from https://console.groq.com/
- Add to
.envfile:
GROQ_API_KEY=your_actual_api_key_here
Run the main script with sample data:
python main.pyModify custom_example.py to use your own courses and faculty:
from models import Course, Faculty, DayOfWeek
from timetable_graph import TimetableGraph
# Define your faculty
faculty = [
Faculty(
id="F001",
name="Dr. John Doe",
department="Computer Science",
max_hours_per_week=20,
expertise_areas=["Programming", "AI"]
)
]
# Define your courses
courses = [
Course(
code="CS101",
name="Introduction to Programming",
credits=4,
department="Computer Science",
faculty_id="F001",
hours_per_week=4
)
]
# Generate timetable
timetable_graph = TimetableGraph(groq_api_key)
result = timetable_graph.generate_timetable(courses, faculty)Input (Courses + Faculty)
↓
1. Generate Initial Timetable (LLM)
↓
2. Validate for Conflicts
↓
3. Resolve Conflicts (if any) → Back to Validate
↓
4. Optimize Distribution (LLM)
↓
5. Finalize Timetable
↓
Output (Optimized Schedule)
- No Faculty Conflicts: Same faculty cannot teach multiple courses simultaneously
- Workload Limits: Faculty hours don't exceed maximum weekly limit
- Room Conflicts: No double-booking of rooms (if specified)
- Credit Balance: Even distribution of courses across days
- Preference Respect: Consider faculty and course day preferences
The system generates:
- Formatted Timetable: Day-wise schedule display
- Faculty Workload Analysis: Hours and course distribution per faculty
- Conflict Report: Any unresolved scheduling issues
- JSON Export: Machine-readable timetable data
📅 MONDAY
--------------------------------------------------
09:00-10:00 | CS101 | Faculty: F001
10:00-11:00 | MATH201 | Faculty: F003
14:00-15:00 | PHY101 | Faculty: F004
📅 TUESDAY
--------------------------------------------------
09:00-10:00 | CS201 | Faculty: F001
11:00-12:00 | CS401 | Faculty: F002
Default time slots (modifiable in code):
- 09:00-10:00, 10:00-11:00, 11:00-12:00, 12:00-13:00
- 14:00-15:00, 15:00-16:00, 16:00-17:00
Default: Monday to Friday (configurable)
Default: mixtral-8x7b-32768 (Groq)
- High performance for complex scheduling logic
- Can be changed in
TimetableAgentinitialization
Extend the validator to add institution-specific rules:
class CustomValidator(TimetableValidator):
def validate_custom_rules(self, slots):
# Add your custom validation logic
passThe system can be easily integrated into web applications:
from timetable_graph import TimetableGraph
def generate_schedule_api(courses_data, faculty_data):
# Convert data to models
courses = [Course(**course) for course in courses_data]
faculty = [Faculty(**f) for f in faculty_data]
# Generate timetable
graph = TimetableGraph(api_key)
return graph.generate_timetable(courses, faculty)- API Key Error: Ensure GROQ_API_KEY is set correctly in .env
- No Slots Generated: Check if faculty IDs match between courses and faculty
- Too Many Conflicts: Reduce course load or increase faculty availability
- Import Errors: Ensure all dependencies are installed
- Limit courses to ~20-30 for optimal LLM performance
- Use specific day/time preferences to guide generation
- Increase faculty max_hours if schedules are too constrained
To extend the system:
- Add new constraint types in
validators.py - Enhance LLM prompts in
agents.py - Modify workflow in
timetable_graph.py - Add new data models in
models.py
Open source - feel free to modify and adapt for your institution's needs.