Artificial Intelligence for planning optimization in Kotlin

For OptaPlanner (open source AI constraint solver), we created a quickstart in kotlin.
Video: https://youtu.be/n6fl60gR8Gc
Source code: https://github.com/kiegroup/optaplanner-quickstarts/tree/development/kotlin-quarkus-school-timetabling

I wondering if there are suggestions on how to make the code cleaner, like the 3 constructors in the Lesson class:
https://github.com/kiegroup/optaplanner-quickstarts/blob/development/kotlin-quarkus-school-timetabling/src/main/kotlin/org/acme/kotlin/schooltimetabling/domain/Lesson.kt#L29

2 Likes

Hm, you can use kotlin-jpa https://kotlinlang.org/docs/reference/compiler-plugins.html#no-arg-compiler-plugin to get rid of the no-arg constructor.

The 2 other constructors can be merged in a signle one which has null default values for id, timeslot, room.

Then usually one can just declare all the fields in the constructor as val/var though in this case there are those 3 lateinit properties, which look a bit off, how do those get initialized when JPA creates the class?

1 Like