From 17803529cf1611c926a0fd4b78b03c562ded4635 Mon Sep 17 00:00:00 2001 From: Eden Xu <130119691+FlyingPufferFish@users.noreply.github.com> Date: Mon, 30 Sep 2024 09:57:10 +1000 Subject: [PATCH 1/4] refactor(database): :pencil2: add missing attributes to Unit and Timetable class --- .../src/main/java/org/acme/domain/Campus.java | 19 ------------ .../java/org/acme/domain/CampusResource.java | 30 ------------------- .../main/java/org/acme/domain/Timetable.java | 4 ++- .../src/main/java/org/acme/domain/Unit.java | 14 +++++---- 4 files changed, 11 insertions(+), 56 deletions(-) delete mode 100644 backend/src/main/java/org/acme/domain/Campus.java delete mode 100644 backend/src/main/java/org/acme/domain/CampusResource.java diff --git a/backend/src/main/java/org/acme/domain/Campus.java b/backend/src/main/java/org/acme/domain/Campus.java deleted file mode 100644 index a08f6e1..0000000 --- a/backend/src/main/java/org/acme/domain/Campus.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.acme.domain; - -// import java.util.List; -import jakarta.persistence.*; -import io.quarkus.hibernate.orm.panache.PanacheEntity; - -@Entity -public class Campus extends PanacheEntity { - - public String name; - - public Campus() { - } - - public Campus(String name) { - this.name = name; - } - -} \ No newline at end of file diff --git a/backend/src/main/java/org/acme/domain/CampusResource.java b/backend/src/main/java/org/acme/domain/CampusResource.java deleted file mode 100644 index f93e55e..0000000 --- a/backend/src/main/java/org/acme/domain/CampusResource.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.acme.domain; - -import java.util.List; - -import jakarta.transaction.Transactional; -import jakarta.ws.rs.Consumes; -import jakarta.ws.rs.GET; -import jakarta.ws.rs.POST; -import jakarta.ws.rs.Path; -import jakarta.ws.rs.Produces; -import jakarta.ws.rs.core.MediaType; -import jakarta.ws.rs.core.Response; - -@Path("/campuses") -public class CampusResource { - - @GET - @Produces(MediaType.APPLICATION_JSON) - public List list() { - return Campus.listAll(); - } - - @POST - @Transactional - @Consumes(MediaType.APPLICATION_JSON) - public Response createCampus(Campus campus) { - campus.persist(); - return Response.status(Response.Status.CREATED).entity(campus).build(); - } -} \ No newline at end of file diff --git a/backend/src/main/java/org/acme/domain/Timetable.java b/backend/src/main/java/org/acme/domain/Timetable.java index cacbc33..8b98933 100644 --- a/backend/src/main/java/org/acme/domain/Timetable.java +++ b/backend/src/main/java/org/acme/domain/Timetable.java @@ -14,7 +14,6 @@ import jakarta.persistence.JoinColumn; import jakarta.persistence.JoinTable; import jakarta.persistence.ManyToMany; -import jakarta.persistence.Transient; import java.time.DayOfWeek; import java.time.LocalTime; @@ -33,6 +32,9 @@ @Entity @PlanningSolution public class Timetable extends PanacheEntity { + + public String campusName; + @ElementCollection @ValueRangeProvider public List daysOfWeek; diff --git a/backend/src/main/java/org/acme/domain/Unit.java b/backend/src/main/java/org/acme/domain/Unit.java index 677a2e6..4f13520 100644 --- a/backend/src/main/java/org/acme/domain/Unit.java +++ b/backend/src/main/java/org/acme/domain/Unit.java @@ -31,17 +31,13 @@ @PlanningEntity public class Unit extends PanacheEntity { - // TODO: change unit to be the owner, rather than the student being owner - @JsonIgnoreProperties("units") - @ManyToMany(mappedBy = "units", fetch = FetchType.LAZY, cascade = {CascadeType.ALL}) - @JsonManagedReference - public List students; - @PlanningId public int unitID; public String name; + public String course; + public Duration duration; @PlanningVariable @@ -50,6 +46,12 @@ public class Unit extends PanacheEntity { @PlanningVariable public LocalTime startTime; + // TODO: change unit to be the owner, rather than the student being owner + @JsonIgnoreProperties("units") + @ManyToMany(mappedBy = "units", fetch = FetchType.LAZY, cascade = {CascadeType.ALL}) + @JsonManagedReference + public List students; + /* * currently each unit only has 1 'slot' on the timetable, so it can only * be associated with one room, but in the final product, we would most From ce6cc2ca6f75292d60c855683cae2ae6f0aa2a0a Mon Sep 17 00:00:00 2001 From: Giang Vu Date: Mon, 30 Sep 2024 15:57:55 +1000 Subject: [PATCH 2/4] fix: deserialize JSON from frontend --- backend/src/main/java/org/acme/TimetableResource.java | 8 ++++++++ backend/src/main/java/org/acme/domain/Room.java | 3 ++- backend/src/main/java/org/acme/domain/Student.java | 2 +- backend/src/main/java/org/acme/domain/Unit.java | 3 ++- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/backend/src/main/java/org/acme/TimetableResource.java b/backend/src/main/java/org/acme/TimetableResource.java index 4d15599..e6b4241 100644 --- a/backend/src/main/java/org/acme/TimetableResource.java +++ b/backend/src/main/java/org/acme/TimetableResource.java @@ -3,6 +3,7 @@ import ai.timefold.solver.core.api.solver.SolverManager; import jakarta.inject.Inject; import jakarta.transaction.Transactional; +import jakarta.ws.rs.Consumes; import jakarta.ws.rs.GET; import jakarta.ws.rs.POST; import jakarta.ws.rs.Path; @@ -50,6 +51,13 @@ public List view() { return Timetable.listAll(); } + @Path("/unit") + @POST + @Consumes(MediaType.APPLICATION_JSON) + public Unit handleUnit(Unit unit) { + return unit; + } + @GET @Transactional @Produces(MediaType.APPLICATION_JSON) diff --git a/backend/src/main/java/org/acme/domain/Room.java b/backend/src/main/java/org/acme/domain/Room.java index 4ed0f00..22ea8f7 100644 --- a/backend/src/main/java/org/acme/domain/Room.java +++ b/backend/src/main/java/org/acme/domain/Room.java @@ -3,6 +3,7 @@ import java.util.ArrayList; import java.util.List; +import com.fasterxml.jackson.annotation.JsonBackReference; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonManagedReference; @@ -36,7 +37,7 @@ public class Room extends PanacheEntity { */ @JsonIgnoreProperties("room") @OneToMany(mappedBy = "room", orphanRemoval = false) - @JsonManagedReference + @JsonBackReference @JsonIgnore public List units = new ArrayList(); diff --git a/backend/src/main/java/org/acme/domain/Student.java b/backend/src/main/java/org/acme/domain/Student.java index e4f10f7..ece4d03 100644 --- a/backend/src/main/java/org/acme/domain/Student.java +++ b/backend/src/main/java/org/acme/domain/Student.java @@ -35,7 +35,7 @@ public class Student extends PanacheEntity{ joinColumns = @JoinColumn(name = "student_id"), inverseJoinColumns = @JoinColumn(name = "unit_id") ) - @JsonManagedReference + // @JsonManagedReference @JsonIgnore public List units = new ArrayList(); diff --git a/backend/src/main/java/org/acme/domain/Unit.java b/backend/src/main/java/org/acme/domain/Unit.java index 4f13520..d91c910 100644 --- a/backend/src/main/java/org/acme/domain/Unit.java +++ b/backend/src/main/java/org/acme/domain/Unit.java @@ -17,6 +17,7 @@ import java.util.ArrayList; import java.util.List; +import com.fasterxml.jackson.annotation.JsonBackReference; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonManagedReference; @@ -49,7 +50,7 @@ public class Unit extends PanacheEntity { // TODO: change unit to be the owner, rather than the student being owner @JsonIgnoreProperties("units") @ManyToMany(mappedBy = "units", fetch = FetchType.LAZY, cascade = {CascadeType.ALL}) - @JsonManagedReference + // @JsonManagedReference public List students; /* From b41d9a8ac7071f16d69e87fa29c9ce3aeb8e3cd3 Mon Sep 17 00:00:00 2001 From: Giang Vu Date: Mon, 30 Sep 2024 16:32:46 +1000 Subject: [PATCH 3/4] fix: many to many relationship annotations --- backend/src/main/java/org/acme/TimetableResource.java | 4 ++++ backend/src/main/java/org/acme/domain/Room.java | 3 +-- backend/src/main/java/org/acme/domain/Timetable.java | 8 +++++--- backend/src/main/java/org/acme/domain/Unit.java | 3 +-- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/backend/src/main/java/org/acme/TimetableResource.java b/backend/src/main/java/org/acme/TimetableResource.java index e6b4241..a7caf6d 100644 --- a/backend/src/main/java/org/acme/TimetableResource.java +++ b/backend/src/main/java/org/acme/TimetableResource.java @@ -36,11 +36,15 @@ public class TimetableResource { private int jobId = 0; @POST + @Transactional public Timetable handleRequest(Timetable problem) throws ExecutionException, InterruptedException { jobId += 1; String name = "Job" + Integer.toString(jobId); + // return problem; + Timetable solution = solverManager.solve(name, problem).getFinalBestSolution(); + solution.persist(); return solution; } diff --git a/backend/src/main/java/org/acme/domain/Room.java b/backend/src/main/java/org/acme/domain/Room.java index 22ea8f7..5e5a048 100644 --- a/backend/src/main/java/org/acme/domain/Room.java +++ b/backend/src/main/java/org/acme/domain/Room.java @@ -37,7 +37,6 @@ public class Room extends PanacheEntity { */ @JsonIgnoreProperties("room") @OneToMany(mappedBy = "room", orphanRemoval = false) - @JsonBackReference @JsonIgnore public List units = new ArrayList(); @@ -46,7 +45,7 @@ public class Room extends PanacheEntity { */ @JsonIgnoreProperties("rooms") @ManyToMany(mappedBy = "rooms", fetch = FetchType.LAZY, cascade = {CascadeType.ALL}) - @JsonManagedReference + // @JsonManagedReference @JsonIgnore public List timetables = new ArrayList(); diff --git a/backend/src/main/java/org/acme/domain/Timetable.java b/backend/src/main/java/org/acme/domain/Timetable.java index 8b98933..b45fb47 100644 --- a/backend/src/main/java/org/acme/domain/Timetable.java +++ b/backend/src/main/java/org/acme/domain/Timetable.java @@ -23,6 +23,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonManagedReference; +import com.fasterxml.jackson.annotation.JsonProperty; /** * Represents a timetable, the solution from the program. @@ -56,9 +57,10 @@ public class Timetable extends PanacheEntity { joinColumns = @JoinColumn(name = "timetable_id"), inverseJoinColumns = @JoinColumn(name = "room_id") ) - @JsonManagedReference + // @JsonManagedReference @ProblemFactCollectionProperty - @JsonIgnore + // @JsonIgnore + // @JsonProperty(access = JsonProperty.Access.WRITE_ONLY) @ValueRangeProvider public List rooms; @@ -74,7 +76,7 @@ public class Timetable extends PanacheEntity { joinColumns = @JoinColumn(name = "timetable_id"), inverseJoinColumns = @JoinColumn(name = "unit_id") ) - @JsonManagedReference + // @JsonManagedReference @PlanningEntityCollectionProperty public List units; diff --git a/backend/src/main/java/org/acme/domain/Unit.java b/backend/src/main/java/org/acme/domain/Unit.java index d91c910..16409e1 100644 --- a/backend/src/main/java/org/acme/domain/Unit.java +++ b/backend/src/main/java/org/acme/domain/Unit.java @@ -63,7 +63,6 @@ public class Unit extends PanacheEntity { @JsonIgnoreProperties("units") @ManyToOne(cascade = {CascadeType.ALL}) @JoinColumn(name = "room_id") - @JsonManagedReference @PlanningVariable public Room room; @@ -74,7 +73,7 @@ public class Unit extends PanacheEntity { */ @JsonIgnoreProperties("units") @ManyToMany(mappedBy = "units", fetch = FetchType.LAZY, cascade = {CascadeType.ALL}) - @JsonManagedReference + // @JsonManagedReference @JsonIgnore public List timetables = new ArrayList(); From 2d4a8c0a6608d862aa8c0bc85052945142f157e6 Mon Sep 17 00:00:00 2001 From: Eden Xu <130119691+FlyingPufferFish@users.noreply.github.com> Date: Mon, 30 Sep 2024 18:06:58 +1000 Subject: [PATCH 4/4] refactor(database): :recycle: refactor Unit constructors, clean code --- .../main/java/org/acme/TimetableResource.java | 14 ++++--- .../src/main/java/org/acme/domain/Room.java | 4 +- .../main/java/org/acme/domain/Student.java | 4 -- .../main/java/org/acme/domain/Timetable.java | 9 +---- .../src/main/java/org/acme/domain/Unit.java | 39 ++++++++++--------- .../TimetableConstraintProviderTest.java | 24 ++++++------ 6 files changed, 43 insertions(+), 51 deletions(-) diff --git a/backend/src/main/java/org/acme/TimetableResource.java b/backend/src/main/java/org/acme/TimetableResource.java index a7caf6d..5a2c5da 100644 --- a/backend/src/main/java/org/acme/TimetableResource.java +++ b/backend/src/main/java/org/acme/TimetableResource.java @@ -41,10 +41,12 @@ public Timetable handleRequest(Timetable problem) throws ExecutionException, Int jobId += 1; String name = "Job" + Integer.toString(jobId); - // return problem; - + // generate solution timetable with TimeFold Solver Timetable solution = solverManager.solve(name, problem).getFinalBestSolution(); + + // store the solution timetable to the database solution.persist(); + return solution; } @@ -81,10 +83,10 @@ public Timetable solveExample() throws ExecutionException, InterruptedException Room r2 = new Room("Room2", 4, false); Room r3 = new Room("Room3", 4, false); - Unit u1 = new Unit(1, "1", Duration.ofHours(2), List.of(a, b), true); - Unit u2 = new Unit(2, "2", Duration.ofHours(2), List.of(a, c, d, e), true); - Unit u3 = new Unit(3, "3", Duration.ofHours(2), List.of(f, g, h, i), false); - Unit u4 = new Unit(4, "4", Duration.ofHours(2), List.of(a, b), false); + Unit u1 = new Unit(1, "1", "Course A", Duration.ofHours(2), List.of(a, b), true); + Unit u2 = new Unit(2, "2", "Course A", Duration.ofHours(2), List.of(a, c, d, e), true); + Unit u3 = new Unit(3, "3", "Course B", Duration.ofHours(2), List.of(f, g, h, i), false); + Unit u4 = new Unit(4, "4", "Course C", Duration.ofHours(2), List.of(a, b), false); var problem = new Timetable( List.of( diff --git a/backend/src/main/java/org/acme/domain/Room.java b/backend/src/main/java/org/acme/domain/Room.java index 5e5a048..d78aec4 100644 --- a/backend/src/main/java/org/acme/domain/Room.java +++ b/backend/src/main/java/org/acme/domain/Room.java @@ -3,10 +3,8 @@ import java.util.ArrayList; import java.util.List; -import com.fasterxml.jackson.annotation.JsonBackReference; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonManagedReference; import ai.timefold.solver.core.api.domain.lookup.PlanningId; import io.quarkus.hibernate.orm.panache.PanacheEntity; @@ -23,6 +21,7 @@ */ @Entity public class Room extends PanacheEntity { + @PlanningId public String roomCode; @@ -45,7 +44,6 @@ public class Room extends PanacheEntity { */ @JsonIgnoreProperties("rooms") @ManyToMany(mappedBy = "rooms", fetch = FetchType.LAZY, cascade = {CascadeType.ALL}) - // @JsonManagedReference @JsonIgnore public List timetables = new ArrayList(); diff --git a/backend/src/main/java/org/acme/domain/Student.java b/backend/src/main/java/org/acme/domain/Student.java index ece4d03..83b20c4 100644 --- a/backend/src/main/java/org/acme/domain/Student.java +++ b/backend/src/main/java/org/acme/domain/Student.java @@ -6,7 +6,6 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonManagedReference; import io.quarkus.hibernate.orm.panache.PanacheEntity; import jakarta.persistence.CascadeType; @@ -24,8 +23,6 @@ @Entity public class Student extends PanacheEntity{ - // String studentID; - public String name; @JsonIgnoreProperties("students") @@ -35,7 +32,6 @@ public class Student extends PanacheEntity{ joinColumns = @JoinColumn(name = "student_id"), inverseJoinColumns = @JoinColumn(name = "unit_id") ) - // @JsonManagedReference @JsonIgnore public List units = new ArrayList(); diff --git a/backend/src/main/java/org/acme/domain/Timetable.java b/backend/src/main/java/org/acme/domain/Timetable.java index b45fb47..43a1cdd 100644 --- a/backend/src/main/java/org/acme/domain/Timetable.java +++ b/backend/src/main/java/org/acme/domain/Timetable.java @@ -20,9 +20,7 @@ import java.util.ArrayList; import java.util.List; -import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonManagedReference; import com.fasterxml.jackson.annotation.JsonProperty; /** @@ -57,10 +55,8 @@ public class Timetable extends PanacheEntity { joinColumns = @JoinColumn(name = "timetable_id"), inverseJoinColumns = @JoinColumn(name = "room_id") ) - // @JsonManagedReference @ProblemFactCollectionProperty - // @JsonIgnore - // @JsonProperty(access = JsonProperty.Access.WRITE_ONLY) + @JsonProperty(access = JsonProperty.Access.WRITE_ONLY) @ValueRangeProvider public List rooms; @@ -76,7 +72,6 @@ public class Timetable extends PanacheEntity { joinColumns = @JoinColumn(name = "timetable_id"), inverseJoinColumns = @JoinColumn(name = "unit_id") ) - // @JsonManagedReference @PlanningEntityCollectionProperty public List units; @@ -191,7 +186,7 @@ public List calculateSoftUnitConflictList() { ArrayList out = new ArrayList(); for (var first : units) { for (var second : units) { - if (first.getUnitID() >= second.getUnitID()) { + if (first.getUnitId() >= second.getUnitId()) { continue; } int numStudents = 0; diff --git a/backend/src/main/java/org/acme/domain/Unit.java b/backend/src/main/java/org/acme/domain/Unit.java index 16409e1..3515d21 100644 --- a/backend/src/main/java/org/acme/domain/Unit.java +++ b/backend/src/main/java/org/acme/domain/Unit.java @@ -17,11 +17,8 @@ import java.util.ArrayList; import java.util.List; -import com.fasterxml.jackson.annotation.JsonBackReference; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonManagedReference; - /** * Represents a unit. @@ -33,7 +30,7 @@ public class Unit extends PanacheEntity { @PlanningId - public int unitID; + public int unitId; public String name; @@ -50,7 +47,6 @@ public class Unit extends PanacheEntity { // TODO: change unit to be the owner, rather than the student being owner @JsonIgnoreProperties("units") @ManyToMany(mappedBy = "units", fetch = FetchType.LAZY, cascade = {CascadeType.ALL}) - // @JsonManagedReference public List students; /* @@ -73,7 +69,6 @@ public class Unit extends PanacheEntity { */ @JsonIgnoreProperties("units") @ManyToMany(mappedBy = "units", fetch = FetchType.LAZY, cascade = {CascadeType.ALL}) - // @JsonManagedReference @JsonIgnore public List timetables = new ArrayList(); @@ -84,13 +79,15 @@ public Unit() { * Creates a unit. * * @param unitID The unit’s ID. - * @param name The unit’s ID. + * @param name The unit’s name. + * @param course The course that the unit belongs to. * @param duration The unit’s duration. * @param students The list of students enrolled in the unit. */ - public Unit(int unitID, String name, Duration duration, List students) { - this.unitID = unitID; + public Unit(int unitID, String name, String course, Duration duration, List students) { + this.unitId = unitID; this.name = name; + this.course = course; this.duration = duration; this.students = students; this.setStudentsUnits(); @@ -100,14 +97,16 @@ public Unit(int unitID, String name, Duration duration, List students) * Creates a unit. * * @param unitID The unit’s ID. - * @param name The unit’s ID. + * @param name The unit’s name. + * @param course The course that the unit belongs to. * @param duration The unit’s duration. * @param students The list of students enrolled in the unit. * @param wantsLab Whether the unit wants a laboratory room. */ - public Unit(int unitID, String name, Duration duration, List students, boolean wantsLab) { - this.unitID = unitID; + public Unit(int unitID, String name, String course, Duration duration, List students, boolean wantsLab) { + this.unitId = unitID; this.name = name; + this.course = course; this.duration = duration; this.students = students; this.wantsLab = wantsLab; @@ -118,15 +117,17 @@ public Unit(int unitID, String name, Duration duration, List students, * Creates a unit. * * @param unitID The unit’s ID. - * @param name The unit’s ID. + * @param name The unit’s name. + * @param course The course that the unit belongs to. * @param duration The unit’s duration. * @param students The list of students enrolled in the unit. * @param wantsLab Whether the unit wants a laboratory room. * @param room The unit's room. */ - public Unit(int unitID, String name, DayOfWeek dayOfWeek, LocalTime startTime, Duration duration, List students, boolean wantsLab, Room room) { - this.unitID = unitID; + public Unit(int unitID, String name, String course, DayOfWeek dayOfWeek, LocalTime startTime, Duration duration, List students, boolean wantsLab, Room room) { + this.unitId = unitID; this.name = name; + this.course = course; this.dayOfWeek = dayOfWeek; this.startTime = startTime; this.duration = duration; @@ -135,12 +136,12 @@ public Unit(int unitID, String name, DayOfWeek dayOfWeek, LocalTime startTime, D this.room = room; } - public int getUnitID() { - return unitID; + public int getUnitId() { + return unitId; } - public void setUnitID(int unitID) { - this.unitID = unitID; + public void setUnitId(int unitID) { + this.unitId = unitID; } public String getName() { diff --git a/backend/src/test/java/org/acme/solver/TimetableConstraintProviderTest.java b/backend/src/test/java/org/acme/solver/TimetableConstraintProviderTest.java index 4ab03fc..74a8011 100644 --- a/backend/src/test/java/org/acme/solver/TimetableConstraintProviderTest.java +++ b/backend/src/test/java/org/acme/solver/TimetableConstraintProviderTest.java @@ -35,9 +35,9 @@ public class TimetableConstraintProviderTest { */ @Test void studentConflict() { - Unit firstUnit = new Unit(1, "unit1", DAY_OF_WEEK, START_TIME, DURATION, List.of(STUDENT1), true, ROOM1); - Unit conflictingUnit = new Unit(2, "unit2", DAY_OF_WEEK, START_TIME, DURATION, List.of(STUDENT1), false, ROOM2); - Unit nonConflictingUnit = new Unit(3, "unit3", DAY_OF_WEEK, START_TIME, DURATION, List.of(STUDENT2), true, ROOM3); + Unit firstUnit = new Unit(1, "unit1", "Course A", DAY_OF_WEEK, START_TIME, DURATION, List.of(STUDENT1), true, ROOM1); + Unit conflictingUnit = new Unit(2, "unit2", "Course A", DAY_OF_WEEK, START_TIME, DURATION, List.of(STUDENT1), false, ROOM2); + Unit nonConflictingUnit = new Unit(3, "unit3","Course B", DAY_OF_WEEK, START_TIME, DURATION, List.of(STUDENT2), true, ROOM3); ConflictingUnit conflictingUnitPair = new ConflictingUnit(firstUnit, conflictingUnit, 1); constraintVerifier.verifyThat(TimetableConstraintProvider::studentConflict) @@ -50,9 +50,9 @@ void studentConflict() { */ @Test void roomConflict() { - Unit firstUnit = new Unit(1, "unit1", DAY_OF_WEEK, START_TIME, DURATION, List.of(STUDENT1), true, ROOM1); - Unit conflictingUnit = new Unit(2, "unit2", DAY_OF_WEEK, START_TIME, DURATION, List.of(STUDENT2), true, ROOM1); - Unit nonConflictingUnit = new Unit(3, "unit3", DAY_OF_WEEK, START_TIME, DURATION, List.of(STUDENT3), false, ROOM2); + Unit firstUnit = new Unit(1, "unit1", "Course A", DAY_OF_WEEK, START_TIME, DURATION, List.of(STUDENT1), true, ROOM1); + Unit conflictingUnit = new Unit(2, "unit2", "Course A", DAY_OF_WEEK, START_TIME, DURATION, List.of(STUDENT2), true, ROOM1); + Unit nonConflictingUnit = new Unit(3, "unit3", "Course A", DAY_OF_WEEK, START_TIME, DURATION, List.of(STUDENT3), false, ROOM2); constraintVerifier.verifyThat(TimetableConstraintProvider::roomConflict) .given(firstUnit, conflictingUnit, nonConflictingUnit) .penalizesBy(1); @@ -63,9 +63,9 @@ void roomConflict() { */ @Test void roomCapacityConflict() { - Unit firstUnit = new Unit(1, "unit1", DAY_OF_WEEK, START_TIME, DURATION, List.of(STUDENT1), true, ROOM1); - Unit conflictingUnit = new Unit(2, "unit2", DAY_OF_WEEK, START_TIME, DURATION, List.of(STUDENT2, STUDENT3, STUDENT4), false, ROOM2); - Unit nonConflictingUnit = new Unit(3, "unit3", DAY_OF_WEEK, START_TIME, DURATION, List.of(STUDENT5), true, ROOM3); + Unit firstUnit = new Unit(1, "unit1", "Course A", DAY_OF_WEEK, START_TIME, DURATION, List.of(STUDENT1), true, ROOM1); + Unit conflictingUnit = new Unit(2, "unit2", "Course A", DAY_OF_WEEK, START_TIME, DURATION, List.of(STUDENT2, STUDENT3, STUDENT4), false, ROOM2); + Unit nonConflictingUnit = new Unit(3, "unit3", "Course A", DAY_OF_WEEK, START_TIME, DURATION, List.of(STUDENT5), true, ROOM3); constraintVerifier.verifyThat(TimetableConstraintProvider::roomCapacity) .given(firstUnit, conflictingUnit, nonConflictingUnit) .penalizesBy(1); @@ -76,9 +76,9 @@ void roomCapacityConflict() { */ @Test void labConflict() { - Unit firstUnit = new Unit(1, "unit1", DAY_OF_WEEK, START_TIME, DURATION, List.of(STUDENT1), true, ROOM1); - Unit conflictingUnit = new Unit(2, "unit2", DAY_OF_WEEK, START_TIME, DURATION, List.of(STUDENT2), true, ROOM2); - Unit nonConflictingUnit = new Unit(3, "unit3", DAY_OF_WEEK, START_TIME, DURATION, List.of(STUDENT5), true, ROOM3); + Unit firstUnit = new Unit(1, "unit1", "Course A", DAY_OF_WEEK, START_TIME, DURATION, List.of(STUDENT1), true, ROOM1); + Unit conflictingUnit = new Unit(2, "unit2", "Course A", DAY_OF_WEEK, START_TIME, DURATION, List.of(STUDENT2), true, ROOM2); + Unit nonConflictingUnit = new Unit(3, "unit3", "Course A", DAY_OF_WEEK, START_TIME, DURATION, List.of(STUDENT5), true, ROOM3); constraintVerifier.verifyThat(TimetableConstraintProvider::labPreference) .given(firstUnit, conflictingUnit, nonConflictingUnit) .penalizesBy(1);