Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/backend' into backend
Browse files Browse the repository at this point in the history
  • Loading branch information
ttrubinov committed Jun 24, 2024
2 parents 4e55ed8 + a8c6a65 commit 719fe76
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package org.conferatus.timetable.backend.algorithm.constraints;

import java.util.concurrent.atomic.AtomicReference;

import org.conferatus.timetable.backend.algorithm.scheduling.GroupEvolve;
import org.conferatus.timetable.backend.algorithm.scheduling.LessonWithTime;

import java.util.concurrent.atomic.AtomicReference;

import static org.conferatus.timetable.backend.algorithm.constraints.CalculateResult.ok;
import static org.conferatus.timetable.backend.algorithm.constraints.CalculateResult.problem;

Expand All @@ -15,15 +15,17 @@
* positive if good ending
*/
public enum PenaltyEnum {
TeacherAndAudienceType(
TeacherWish(
(data) -> {
// FIXME видимо просто удалить эти строчки, препод же привязывается сразу в предмету
// LessonWithTime lesson = data.currentLesson();
// if (!lesson.audience().groupCapacity()
// .equals(lesson.teacher().teacherType())) {
// return problem(-100., "Teacher and audience has different types "
// + lesson.teacher() + " " + lesson.audience());
// }
LessonWithTime lesson = data.currentLesson();
var maybeWish = lesson.teacher().wishes().stream().filter(wish -> wish.time().equals(lesson.time())).findAny();
if (maybeWish.isPresent()) {
var wish = maybeWish.get();
return wish.penalty() >= 0
? ok(wish.penalty())
: problem(wish.penalty(), "Teacher {%s} doesn't want this time {%s}"
.formatted(lesson.teacher().toString(), lesson.time()));
}
return ok();
},
true
Expand Down Expand Up @@ -57,7 +59,7 @@ public enum PenaltyEnum {
},
true
),
GroupsInOneAuditory( //todo: fix that
GroupsInOneAuditory(
(data) -> {
LessonWithTime lesson = data.currentLesson();
var otherLessons = data.getOtherLessons(lesson);
Expand Down Expand Up @@ -105,9 +107,9 @@ public enum PenaltyEnum {
LessonWithTime lesson = data.currentLesson();
double roomCapacity = lesson.cell().audience().groupCapacity();
double groupsAmount = lesson.groups().size();
double value = baseVal * 1 - groupsAmount/roomCapacity;
if (value >= 0.666 * baseVal) {
return problem(-value*2, "Audience is almost empty");
double value = baseVal * 1 - groupsAmount / roomCapacity;
if (value >= 0.666 * baseVal) {
return problem(-value * 2, "Audience is almost empty");
}
return ok(-value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ public static void main(String[] args) throws InterruptedException {
int lectureTeachersAmount = 1600;
for (long i = 1; i <= teachersAmount; i++) {
long studyPlan = i % studyPlans + 1;
TeacherEvolve teacherEvolve = new TeacherEvolve(i/*AudienceType.PRACTICAL*/);
TeacherEvolve teacherEvolve = new TeacherEvolve(i/*AudienceType.PRACTICAL*/, null);
planToSeminarTeachers.get(studyPlan).add(teacherEvolve);

}

for (long i = 1; i <= lectureTeachersAmount; i++) {
long studyPlan = i % studyPlans + 1;
TeacherEvolve teacherEvolve = new TeacherEvolve(i/*AudienceType.LECTURE*/);
TeacherEvolve teacherEvolve = new TeacherEvolve(i/*AudienceType.LECTURE*/, null);
planToLectureTeachers.get(studyPlan).add(teacherEvolve);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.conferatus.timetable.backend.algorithm.scheduling;

public enum LessonFixType {
NONE,
SOFT_FIX,
HARD_FIX
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
package org.conferatus.timetable.backend.algorithm.scheduling;

import org.conferatus.timetable.backend.model.entity.Teacher;

import java.util.List;
import java.util.Objects;

public record TeacherEvolve(Long id) {
public record TeacherEvolve(Long id, List<TeacherWishEvolve> wishes) {
public TeacherEvolve(Teacher teacher) {
this(
teacher.getId(),
teacher.getTeacherWishes().stream().map(TeacherWishEvolve::new).toList()
);
}

@Override
public String toString() {
return String.valueOf(id);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.conferatus.timetable.backend.algorithm.scheduling;

import org.conferatus.timetable.backend.model.entity.TeacherWish;
import org.conferatus.timetable.backend.model.enums.TableTime;

public record TeacherWishEvolve(TableTime time, double penalty) {
public TeacherWishEvolve(TeacherWish teacherWish) {
this(new TableTime(teacherWish.getDayOfWeek().getValue(),
(int) teacherWish.getLessonNumber()),
teacherWish.getPriority());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public ScheduleAlgorithmService.StatusId generate(Long semesterId, User user) {

for (SubjectPlan subjectPlan : sp.subjectPlans()) {
SubjectEvolve subjectEvolve;
TeacherEvolve teacherEvolve = new TeacherEvolve(subjectPlan.teacher().getId());
TeacherEvolve teacherEvolve = new TeacherEvolve(subjectPlan.teacher());
Map<TeacherEvolve, List<GroupEvolve>> teacherToGroups = new HashMap<>();
teacherToGroups.put(teacherEvolve, new ArrayList<>());

Expand Down

0 comments on commit 719fe76

Please sign in to comment.