Search code examples
optaplannertimefold

In Timefold/Optaplanner, what is the difference between annotating a class with @PlanningEntity and listing it as such in the config?


In Timefold/Optaplanner, what is the difference between annotating a class with @PlanningEntity and listing it as such in the configuration? What do these two distinct ways of informing the framework of a class being a planning entity serve?


Solution

  • This question has two answers.

    First answer has to do with timefold-solver-core; if you use that, there is no annotation scanning happening, there is no way for the solver to find out that those classes exist. Which means that the config exists so that you can tell the solver which classes to use. And the annotation exists so that you can optionally configure extra things, such as difficulty weights etc.

    The second answer has to do with timefold-solver-quarkus; Quarkus does annotation scanning for you, and so it will discover the annotated solution and entities. This makes solver config entirely optional under Quarkus.

    If we only had solver config and not the annotations, solver config would always be mandatory. If we only had the annotations and not the solver config, the solver would not work. (Unless we did annotation scanning at runtime, which tends to be frowned upon.)