Google OR-Tools v9.15
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
course_scheduling.h
Go to the documentation of this file.
1// Copyright 2010-2025 Google LLC
2// Licensed under the Apache License, Version 2.0 (the "License");
3// you may not use this file except in compliance with the License.
4// You may obtain a copy of the License at
5//
6// http://www.apache.org/licenses/LICENSE-2.0
7//
8// Unless required by applicable law or agreed to in writing, software
9// distributed under the License is distributed on an "AS IS" BASIS,
10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11// See the License for the specific language governing permissions and
12// limitations under the License.
13
14#ifndef ORTOOLS_SCHEDULING_COURSE_SCHEDULING_H_
15#define ORTOOLS_SCHEDULING_COURSE_SCHEDULING_H_
16
17#include <utility>
18#include <vector>
19
20#include "absl/container/flat_hash_set.h"
21#include "absl/status/status.h"
22#include "absl/types/span.h"
26
27namespace operations_research {
29 public:
30 CourseSchedulingSolver() : solve_for_rooms_(false) {}
31 virtual ~CourseSchedulingSolver() = default;
32
33 using ConflictPairs = absl::flat_hash_set<std::pair<int, int>>;
34
36
37 protected:
38 virtual absl::Status ValidateModelAndLoadClasses(
39 const CourseSchedulingModel& model);
40
42 const CourseSchedulingModel& model, const ConflictPairs& class_conflicts);
43
44 virtual absl::Status VerifyCourseSchedulingResult(
45 const CourseSchedulingModel& model, const CourseSchedulingResult& result);
46
47 private:
48 CourseSchedulingResult ScheduleCourses(const ConflictPairs& class_conflicts,
49 const CourseSchedulingModel& model);
50
51 // This method will modify the CourseSchedulingResult returned from
52 // ScheduleCoursesMip, which is why the result is passed in as a pointer.
53 ConflictPairs AssignStudents(const CourseSchedulingModel& model,
55
56 int GetTeacherIndex(int course_index, int section);
57
58 void InsertSortedPairs(absl::Span<const int> list, ConflictPairs* pairs);
59
60 bool ShouldCreateVariable(int course_index, int section, int time_slot,
61 int room);
62
63 std::vector<int> GetRoomIndices(const Course& course);
64
65 std::vector<absl::flat_hash_set<int>> GetClassesByTimeSlot(
66 const CourseSchedulingResult* result);
67
68 void AddVariableIfNonNull(double coeff, const MPVariable* var,
69 MPConstraint* ct);
70
71 CourseSchedulingResultStatus MipStatusToCourseSchedulingResultStatus(
72 MPSolver::ResultStatus mip_status);
73
74 bool solve_for_rooms_;
75 int class_count_;
76 int time_slot_count_;
77 int room_count_;
78 ConflictPairs course_conflicts_;
79 std::vector<absl::flat_hash_set<int>> teacher_to_classes_;
80 std::vector<absl::flat_hash_set<int>> teacher_to_restricted_slots_;
81 std::vector<std::vector<int>> course_to_classes_;
82};
83
84} // namespace operations_research
85
86#endif // ORTOOLS_SCHEDULING_COURSE_SCHEDULING_H_
absl::flat_hash_set< std::pair< int, int > > ConflictPairs
virtual CourseSchedulingResult SolveModel(const CourseSchedulingModel &model, const ConflictPairs &class_conflicts)
virtual absl::Status ValidateModelAndLoadClasses(const CourseSchedulingModel &model)
virtual absl::Status VerifyCourseSchedulingResult(const CourseSchedulingModel &model, const CourseSchedulingResult &result)
CourseSchedulingResult Solve(const CourseSchedulingModel &model)
The class for variables of a Mathematical Programming (MP) model.
OR-Tools root namespace.