Skip to content

Is it possible to define PlanningVariables programmatically (at runtime) instead of through annotations?

Honestly, I haven’t tried much as I must have completely missed (or failed to recognize) the relevant sections in the docs.

Here is why I’m asking:

I have a working domain model for a given optimization. I can use the domain for a very similar optimization while changing the PlanningVariable. Instead of having 2 almost identical domains which only differ in what is there PlanningVariable, I would like to have only one domain and be able to switch the PlanningVariable on demand.

Does that make sense?


I am afraid there is no such API allowing that yet (there is a jira for it). But I see your motivation to reduce code duplication. I can only advise sharing as many of the domain classes as you can. In this case, if you say the domains differ only in the PlanningVariable, you need to have separate @PlanningEntity and @PlanningSolution classes. Even further, these might have a common ancestor to reduce the duplication further.

In the solverConfig.xml (one for each of the 2 SolverFactories) you can then use <entityClass> and <solutionClass> for which one to use.