This was done as an application for my diploma.
This repository contains a C# application for generating and managing a timetable schedule with exporting results to Excel. Includes classes for handling groups, professors. This was a proof of concept for using knap-sack problem with schedule building.
- Technologies Used
- Architecture Overview
- TimetableTask Algorithm
- Data Input
- Program Output
- Installation
- Usage
- License
- MathNet.Numerics: Library for mathematical computations.
- xUnit: Framework for unit testing.
- NPOI: Library for exporting results to Excel.
The application consists of several key classes:
- TimetableTask: Partial class handling schedule building and validation.
- TimetableTask.Builder: Partial class for building and verifying initial state of
TimetableTask
instances using a fluid interface builder pattern. - ExcelExport: Exporting results to Excel files.
- Group: Stores data and availability vectors for groups.
- Professor: Similar to
Group
, for professors. - ProfGroup: A shorthand to build task parameters easier.
- Item: Converts abstract lectures into items with weight, value, and references.
- KnapSackProblem: Static class for solving the knapsack problem.
The Solve
method initializes the process:
- Sets up original availabilities.
- Iterates over each professor to solve their scheduling problem.
- Wraps up each iteration to check conditions and update availabilities.
- Exports the schedule to an .xlsx file and verifies the solution.
The SolveByProfessor
method provides iteration-able support for building the timetable:
- Prepares the schedule for a professor by creating items and solving the knapsack problem.
- Assigns items to available hours.
- Updates availabilities and records the schedule in the solution matrix.
Core Algorithm:
- Sort items by value with knapsack algorithm.
- Assign items to the first common available hour.
- Update availability and record the schedule.
// Example 1
var professors = new List<Professor> {
new Professor("p1") { Availability = Vector<float>.Build.Dense(hours * days, 1)},
new Professor("p2") { Availability = Vector<float>.Build.Dense(hours * days, 1)},
};
var task = new TimetableTask.Builder().Professors(professors);
// basically
var professors = new List<Professor>();
professors.Add(new Professor(professor));
var task = new TimetableTask.Builder().Professors(professors);
var groups = new List<Group> {
new Group("Group1") { Availability = Vector<float>.Build.Dense(hours * days, 1)},
new Group("Group2") { Availability = Vector<float>.Build.Dense(hours * days, 1)},
};
var task = new TimetableTask.Builder().Groups(groups);
// Example using List<ProfGroup>
var plannedHoursList = new List<ProfGroup> {
new ProfGroup(professor1, group1, 3),
new ProfGroup(professor2, group2, 4)
};
var task = new TimetableTask.Builder().PlannedHours(plannedHoursList);
// Example using matrix
var plannedHoursMatrix = Matrix<float>.Build.DenseOfArray(new float[,] {
{ 3, 0, 0 },
{ 0, 4, 0 },
{ 0, 0, 2 }
});
var task = new TimetableTask.Builder().PlannedHours(plannedHoursMatrix);
var task = TimetableTask.Builder()
.Days(days) // Number of days
.HoursPerDay(hours) // Max hours per day
.Professors(professors)
.Groups(groups)
.PlannedHours(plannedHoursMatrix);
task.Solve();
The program outputs the solution matrix at each stage and the final .xlsx file with the resolved timetable. Users can review the results through console outputs and Excel sheets.
Timetable limitations created successfully.
DenseMatrix 2x2-Single
2 1
3 3
Weights:
DenseMatrix 2x2-Single
4 1
3 2
DenseMatrix 6x4-Single
1 0 0 0
1 0 0 0
0 0 1 0
0 0 1 0
0 0 1 0
0 0 0 0
DenseMatrix 6x4-Single
1 0 0 1
1 0 0 1
0 1 1 0
0 0 1 0
0 0 1 0
0 0 0 1
Groups:
Profs:
An example with real data
-
Clone the repository:
git clone https://github.com/yourusername/timetable-scheduling-app.git
-
Navigate to the project directory:
cd timetable-scheduling-app
-
Restore dependencies:
dotnet restore
- Build the project:
dotnet build
- Run the tests:
dotnet test
- Run the application:
dotnet run
To run the tests dotnet test
Use it however you want.