Skip to content

Commit

Permalink
Merge pull request #23 from hotungkhanh/develop
Browse files Browse the repository at this point in the history
Sprint 2: Deployed frontend
  • Loading branch information
JackTong24 authored Sep 25, 2024
2 parents 304489b + 032b94c commit 34bd8d6
Show file tree
Hide file tree
Showing 51 changed files with 3,731 additions and 537 deletions.
48 changes: 39 additions & 9 deletions backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,45 @@
<groupId>ai.timefold.solver</groupId>
<artifactId>timefold-solver-quarkus-jackson</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5-internal</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ai.timefold.solver</groupId>
<artifactId>timefold-solver-test</artifactId>
<version>1.13.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.26.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
<artifactId>quarkus-jdbc-postgresql</artifactId>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-orm-panache</artifactId>
</dependency>
</dependencies>

Expand Down Expand Up @@ -91,10 +121,10 @@
</build>
<profiles>
<profile>
<id>native</id>
<properties>
<quarkus.package.type>native</quarkus.package.type>
</properties>
<id>native</id>
<properties>
<quarkus.package.type>native</quarkus.package.type>
</properties>
</profile>
</profiles>
</project>
16 changes: 0 additions & 16 deletions backend/src/main/java/org/acme/GreetingResource.java

This file was deleted.

95 changes: 95 additions & 0 deletions backend/src/main/java/org/acme/TimetableResource.java
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 backend/src/main/java/org/acme/domain/ConflictingUnit.java
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;
}
}
56 changes: 56 additions & 0 deletions backend/src/main/java/org/acme/domain/Room.java
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;
}
}
48 changes: 48 additions & 0 deletions backend/src/main/java/org/acme/domain/Student.java
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);
}
}
Loading

0 comments on commit 34bd8d6

Please sign in to comment.