-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from hotungkhanh/develop
Sprint 2: Deployed frontend
- Loading branch information
Showing
51 changed files
with
3,731 additions
and
537 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package org.acme; | ||
|
||
import ai.timefold.solver.core.api.solver.SolverManager; | ||
import jakarta.inject.Inject; | ||
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 org.acme.domain.Room; | ||
import org.acme.domain.Student; | ||
import org.acme.domain.Timetable; | ||
import org.acme.domain.Unit; | ||
|
||
import java.time.DayOfWeek; | ||
import java.time.Duration; | ||
import java.time.LocalTime; | ||
import java.util.List; | ||
import java.util.concurrent.ExecutionException; | ||
|
||
/** | ||
* Entry to the timetabling program. | ||
* Receives a timetabling problem and outputs the solution | ||
* with the best optimised scores according to the provided constraints. | ||
* | ||
* @author Jet Edge | ||
*/ | ||
@Path("/timetabling") | ||
public class TimetableResource { | ||
|
||
@Inject | ||
SolverManager<Timetable, String> solverManager; | ||
|
||
private int jobId = 0; | ||
|
||
@POST | ||
public Timetable handleRequest(Timetable problem) throws ExecutionException, InterruptedException { | ||
jobId += 1; | ||
String name = "Job" + Integer.toString(jobId); | ||
|
||
Timetable solution = solverManager.solve(name, problem).getFinalBestSolution(); | ||
return solution; | ||
} | ||
|
||
@GET | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public Timetable solveExample() throws ExecutionException, InterruptedException { | ||
|
||
Student a = new Student("a"); | ||
Student b = new Student("b"); | ||
Student c = new Student("c"); | ||
Student d = new Student("d"); | ||
Student e = new Student("e"); | ||
Student f = new Student("f"); | ||
Student g = new Student("g"); | ||
Student h = new Student("h"); | ||
Student i = new Student("i"); | ||
|
||
Room r1 = new Room("Room1", 2, true); | ||
Room r2 = new Room("Room2", 4, false); | ||
Room r3 = new Room("Room3", 4, false); | ||
|
||
var problem = new Timetable( | ||
List.of( | ||
new Unit(1, "1", Duration.ofHours(2), List.of(a, b), true), | ||
new Unit(2, "2", Duration.ofHours(2), List.of(a, c, d, e), true), | ||
new Unit(3, "3", Duration.ofHours(2), List.of(f, g, h, i), false), | ||
new Unit(4, "4", Duration.ofHours(2), List.of(a, b), false) | ||
// new Unit(5, "5", Duration.ofHours(2), List.of(c, d, e)), | ||
// new Unit(6, "6", Duration.ofHours(2), List.of(f, g, h, i)) | ||
), | ||
|
||
List.of( | ||
DayOfWeek.MONDAY, | ||
DayOfWeek.TUESDAY, | ||
DayOfWeek.WEDNESDAY | ||
// DayOfWeek.THURSDAY, | ||
// DayOfWeek.FRIDAY | ||
), | ||
|
||
List.of( | ||
LocalTime.of(15, 0) | ||
// LocalTime.of(17, 0) | ||
// LocalTime.of(16,0), | ||
// LocalTime.of(23,0) | ||
), | ||
List.of(r1, r2, r3) | ||
); | ||
|
||
Timetable solution = solverManager.solve("job 1", problem).getFinalBestSolution(); | ||
|
||
return solution; | ||
} | ||
|
||
} |
62 changes: 62 additions & 0 deletions
62
backend/src/main/java/org/acme/domain/ConflictingUnit.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package org.acme.domain; | ||
|
||
/** | ||
* Represents a pair of conflicting units, which are units with common students. | ||
* | ||
* @author Jet Edge | ||
*/ | ||
public class ConflictingUnit { | ||
private Unit unit1; | ||
|
||
private Unit unit2; | ||
|
||
private int numStudent; | ||
|
||
/** | ||
* Creates a pair of conflicting units. | ||
* | ||
* @param first The first unit. | ||
* @param second The second unit. | ||
*/ | ||
public ConflictingUnit(Unit first, Unit second) { | ||
this.unit1 = first; | ||
this.unit2 = second; | ||
} | ||
|
||
/** | ||
* Creates a pair of conflicting units. | ||
* | ||
* @param first The first unit. | ||
* @param second The second unit. | ||
* @param numStudent The number of common students. | ||
*/ | ||
public ConflictingUnit(Unit first, Unit second, int numStudent) { | ||
this.unit1 = first; | ||
this.unit2 = second; | ||
this.numStudent = numStudent; | ||
} | ||
|
||
public Unit getUnit1() { | ||
return unit1; | ||
} | ||
|
||
public void setUnit1(Unit unit1) { | ||
this.unit1 = unit1; | ||
} | ||
|
||
public Unit getUnit2() { | ||
return unit2; | ||
} | ||
|
||
public void setUnit2(Unit unit2) { | ||
this.unit2 = unit2; | ||
} | ||
|
||
public int getNumStudent() { | ||
return numStudent; | ||
} | ||
|
||
public void setNumStudent(int numStudent) { | ||
this.numStudent = numStudent; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package org.acme.domain; | ||
|
||
import ai.timefold.solver.core.api.domain.lookup.PlanningId; | ||
|
||
/** | ||
* Represents a room. | ||
* | ||
* @author Jet Edge | ||
*/ | ||
public class Room { | ||
@PlanningId | ||
private String id; | ||
|
||
private int capacity; | ||
private boolean isLab; | ||
|
||
public Room() { | ||
} | ||
|
||
/** | ||
* Creates a room with its ID and capacity. | ||
* | ||
* @param id The room’s id. | ||
* @param capacity The room's capacity. | ||
* @param isLab Whether the room is a laboratory. | ||
*/ | ||
public Room(String id, int capacity, boolean isLab) { | ||
this.id = id; | ||
this.capacity = capacity; | ||
this.isLab = isLab; | ||
} | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
public void setId(String id) { | ||
this.id = id; | ||
} | ||
|
||
public int getCapacity() { | ||
return capacity; | ||
} | ||
|
||
public void setCapacity(int capacity) { | ||
this.capacity = capacity; | ||
} | ||
|
||
public boolean isLab() { | ||
return isLab; | ||
} | ||
|
||
public void setLab(boolean lab) { | ||
isLab = lab; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package org.acme.domain; | ||
|
||
import java.util.Objects; | ||
|
||
/** | ||
* Represents a student. | ||
* | ||
* @author Jet Edge | ||
*/ | ||
public class Student { | ||
|
||
// String studentID; | ||
|
||
String name; | ||
|
||
public Student() { | ||
} | ||
|
||
/** | ||
* Creates a student with the specified name. | ||
* | ||
* @param name The student’s name. | ||
*/ | ||
public Student(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
Student student = (Student) o; | ||
return Objects.equals(name, student.name); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(name); | ||
} | ||
} |
Oops, something went wrong.