This project contains a Quarkus application with OptaPlanner's constraint solving Artificial Intelligence (AI) integrated with a database and exposed through a REST API.
This web application optimizes a school timetable for students and teachers.
It assigns Lesson
instances to Timeslot
and Room
instances automatically
by using AI to adhere to hard and soft scheduling constraints, such as:
- Room conflict: A room can have at most one lesson at the same time.
- Teacher conflict: A teacher can teach at most one lesson at the same time.
- Student group conflict: A student can attend at most one lesson at the same time.
- Teacher room stability: A teacher prefers to teach in a single room.
- Teacher time efficiency: A teacher prefers to teach sequential lessons and dislikes gaps between lessons.
- Student group subject variety: A student group dislikes sequential lessons on the same subject.
-
Start the application:
./mvnw quarkus:dev
-
Visit http://localhost:8080 in your browser.
-
Click on the Solve button.
Now try live coding:
- Make some changes in the source code
- Refresh your browser (F5).
Those changes are immediately applied.
When you're done iterating in quarkus:dev
mode, run the application as a conventional jar file.
-
Compile it:
./mvnw package
-
run it:
java -jar ./target/quarkus-app/quarkus-run.jar
Look at how fast it boots!
You can also create a native executable from this application without making any source code changes. A native executable removes the dependency on the JVM: everything needed to run the application on the target platform is included in the executable, allowing the application to run with minimal resource overhead.
Because the quarkus H2 extension does not support compiling the embedded database engine into native images, you need to run the H2 server locally first:
-
Download the H2 engine (Platform-independent zip)
-
Unzip it.
-
Start H2 server with the option
-ifNotExists
(this is not recommended in production but saves you from creating the database manually)cd h2/bin && java -cp h2*.jar org.h2.tools.Server -ifNotExists
The database connection in configured in the application.properties
file,
specifically with the %prod.quarkus.datasource.*
properties.
Compiling a native executable takes a bit of time,
as GraalVM performs additional steps to remove unnecessary codepaths.
Use -Dnative
to compile a native executable:
./mvnw package -Dnative
After getting a cup of coffee, run this binary directly:
./target/optaplanner-quickstart-1.0.0-SNAPSHOT-runner