Skip to content
This repository has been archived by the owner on Nov 6, 2023. It is now read-only.

Commit

Permalink
Merge branch 'main' into hotfix
Browse files Browse the repository at this point in the history
  • Loading branch information
jvdcf committed Nov 3, 2023
2 parents 716889e + 9b9da14 commit 71938f5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
11 changes: 11 additions & 0 deletions src/Runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,17 @@ void Runtime::handle_process(Process p) {
Student s = *itr;
OperationResult res = s.verify_add(target);
if (res == OperationResult::Success) {
// Balanced classes | O(n)
std::vector<uint64_t> occupancy;
for (ClassSchedule* class_ : this->find_uc(parse_uc_gen(ops[1]))) {
occupancy.push_back(class_->get_student_count());
}
auto [min, max] = std::minmax_element(occupancy.begin(), occupancy.end());
if (*max - *min > 4) {
std::cerr << "ERROR: Critical conflicts found: the classes will not be balanced. Skipping." << std::endl;
return;
}

students.erase(s);
s.add_to_class(target);
students.insert(s);
Expand Down
9 changes: 0 additions & 9 deletions src/Student.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,6 @@ OperationResult Student::verify_add(ClassSchedule *c) {
return OperationResult::Error;
}

// Balanced classes | O(n)
std::vector<uint64_t> occupancy;
for (ClassSchedule* class_ : this->get_schedule()) {
occupancy.push_back(class_->get_student_count());
}
occupancy.push_back(c->get_student_count());
auto [min, max] = std::minmax_element(occupancy.begin(), occupancy.end());
if (*max - *min > 4) return OperationResult::Error;

// No time conflicts | O(n²)
std::vector<ClassSchedule *> c_sched = this->get_schedule();
c_sched.push_back(c);
Expand Down

0 comments on commit 71938f5

Please sign in to comment.