org.optaplanner.examples.curriculumcourse.domain.CourseSchedule Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of optaplanner-examples Show documentation
Show all versions of optaplanner-examples Show documentation
OptaPlanner solves planning problems.
This lightweight, embeddable planning engine implements powerful and scalable algorithms
to optimize business resource scheduling and planning.
This module contains the examples which demonstrate how to use it in a normal Java application.
package org.optaplanner.examples.curriculumcourse.domain;
import java.util.ArrayList;
import java.util.List;
import org.optaplanner.core.api.domain.solution.PlanningEntityCollectionProperty;
import org.optaplanner.core.api.domain.solution.PlanningScore;
import org.optaplanner.core.api.domain.solution.PlanningSolution;
import org.optaplanner.core.api.domain.solution.ProblemFactCollectionProperty;
import org.optaplanner.core.api.domain.valuerange.ValueRangeProvider;
import org.optaplanner.core.api.score.buildin.hardsoft.HardSoftScore;
import org.optaplanner.examples.common.domain.AbstractPersistable;
import org.optaplanner.examples.curriculumcourse.domain.solver.CourseConflict;
import org.optaplanner.persistence.xstream.api.score.buildin.hardsoft.HardSoftScoreXStreamConverter;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamConverter;
@PlanningSolution
@XStreamAlias("CourseSchedule")
public class CourseSchedule extends AbstractPersistable {
private String name;
private List teacherList;
private List curriculumList;
private List courseList;
private List dayList;
private List timeslotList;
private List periodList;
private List roomList;
private List unavailablePeriodPenaltyList;
private List lectureList;
@XStreamConverter(HardSoftScoreXStreamConverter.class)
private HardSoftScore score;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@ProblemFactCollectionProperty
public List getTeacherList() {
return teacherList;
}
public void setTeacherList(List teacherList) {
this.teacherList = teacherList;
}
@ProblemFactCollectionProperty
public List getCurriculumList() {
return curriculumList;
}
public void setCurriculumList(List curriculumList) {
this.curriculumList = curriculumList;
}
@ProblemFactCollectionProperty
public List getCourseList() {
return courseList;
}
public void setCourseList(List courseList) {
this.courseList = courseList;
}
@ProblemFactCollectionProperty
public List getDayList() {
return dayList;
}
public void setDayList(List dayList) {
this.dayList = dayList;
}
@ProblemFactCollectionProperty
public List getTimeslotList() {
return timeslotList;
}
public void setTimeslotList(List timeslotList) {
this.timeslotList = timeslotList;
}
@ValueRangeProvider(id = "periodRange")
@ProblemFactCollectionProperty
public List getPeriodList() {
return periodList;
}
public void setPeriodList(List periodList) {
this.periodList = periodList;
}
@ValueRangeProvider(id = "roomRange")
@ProblemFactCollectionProperty
public List getRoomList() {
return roomList;
}
public void setRoomList(List roomList) {
this.roomList = roomList;
}
@ProblemFactCollectionProperty
public List getUnavailablePeriodPenaltyList() {
return unavailablePeriodPenaltyList;
}
public void setUnavailablePeriodPenaltyList(List unavailablePeriodPenaltyList) {
this.unavailablePeriodPenaltyList = unavailablePeriodPenaltyList;
}
@PlanningEntityCollectionProperty
public List getLectureList() {
return lectureList;
}
public void setLectureList(List lectureList) {
this.lectureList = lectureList;
}
@PlanningScore
public HardSoftScore getScore() {
return score;
}
public void setScore(HardSoftScore score) {
this.score = score;
}
// ************************************************************************
// Complex methods
// ************************************************************************
@ProblemFactCollectionProperty
private List calculateCourseConflictList() {
List courseConflictList = new ArrayList<>();
for (Course leftCourse : courseList) {
for (Course rightCourse : courseList) {
if (leftCourse.getId() < rightCourse.getId()) {
int conflictCount = 0;
if (leftCourse.getTeacher().equals(rightCourse.getTeacher())) {
conflictCount++;
}
for (Curriculum curriculum : leftCourse.getCurriculumSet()) {
if (rightCourse.getCurriculumSet().contains(curriculum)) {
conflictCount++;
}
}
if (conflictCount > 0) {
courseConflictList.add(new CourseConflict(leftCourse, rightCourse, conflictCount));
}
}
}
}
return courseConflictList;
}
}