|
| 1 | +package com.baeldung.drools.optaplanner; |
| 2 | + |
| 3 | +import java.util.ArrayList; |
| 4 | +import java.util.List; |
| 5 | + |
| 6 | +import org.optaplanner.core.api.domain.solution.PlanningEntityCollectionProperty; |
| 7 | +import org.optaplanner.core.api.domain.solution.PlanningScore; |
| 8 | +import org.optaplanner.core.api.domain.solution.PlanningSolution; |
| 9 | +import org.optaplanner.core.api.domain.solution.drools.ProblemFactCollectionProperty; |
| 10 | +import org.optaplanner.core.api.domain.valuerange.ValueRangeProvider; |
| 11 | +import org.optaplanner.core.api.score.buildin.hardsoft.HardSoftScore; |
| 12 | +import org.slf4j.Logger; |
| 13 | +import org.slf4j.LoggerFactory; |
| 14 | + |
| 15 | +@PlanningSolution |
| 16 | +public class CourseSchedule { |
| 17 | + |
| 18 | + Logger logger = LoggerFactory.getLogger("CourseSchedule"); |
| 19 | + |
| 20 | + private List<Integer> roomList; |
| 21 | + private List<Integer> periodList; |
| 22 | + private List<Lecture> lectureList; |
| 23 | + private HardSoftScore score; |
| 24 | + |
| 25 | + public CourseSchedule(){ |
| 26 | + roomList = new ArrayList<>(); |
| 27 | + periodList = new ArrayList<>(); |
| 28 | + lectureList = new ArrayList<>(); |
| 29 | + } |
| 30 | + |
| 31 | + @ValueRangeProvider(id = "availableRooms") |
| 32 | + @ProblemFactCollectionProperty |
| 33 | + public List<Integer> getRoomList() { |
| 34 | + return roomList; |
| 35 | + } |
| 36 | + |
| 37 | + @ValueRangeProvider(id = "availablePeriods") |
| 38 | + @ProblemFactCollectionProperty |
| 39 | + public List<Integer> getPeriodList() { |
| 40 | + return periodList; |
| 41 | + } |
| 42 | + |
| 43 | + @PlanningEntityCollectionProperty |
| 44 | + public List<Lecture> getLectureList() { |
| 45 | + return lectureList; |
| 46 | + } |
| 47 | + |
| 48 | + @PlanningScore |
| 49 | + public HardSoftScore getScore() { |
| 50 | + return score; |
| 51 | + } |
| 52 | + |
| 53 | + public void setScore(HardSoftScore score) { |
| 54 | + this.score = score; |
| 55 | + } |
| 56 | + |
| 57 | + public void printCourseSchedule() { |
| 58 | + lectureList.stream() |
| 59 | + .map(c -> "Lecture in Room " + c.getRoomNumber().toString() + " during Period " + c.getPeriod().toString()) |
| 60 | + .forEach(k -> logger.info(k)); |
| 61 | + } |
| 62 | + |
| 63 | +} |
0 commit comments