Nullability of shadow variables in constraint streams?

10 views
Skip to first unread message

holger brandl

unread,
Jan 20, 2023, 4:14:53 PM1/20/23
to OptaPlanner development
Hi,

I'm using optaplanner from kotlin, so by language design, I am always trying to figure which variables are nullable and which are not. I initially assumed that shadow variables could be not nullable, e.g
@ShadowVariable(sourceVariableName = "foo", variableListenerClass = VehicleAssignmentListener::class)
lateinit var startTime: Instant

I thought that after the construction heuristic has created some ( not necessarily feasible) solution, my VariableListener would kick in, to set the shadow variable(s). However, this does not seem to be the case: Via

  at org.optaplanner.constraint.streams.drools.DroolsConstraintStreamScoreDirector.calculateScore(DroolsConstraintStreamScoreDirector.java:70)
      at org.optaplanner.core.impl.solver.recaller.BestSolutionRecaller.solvingStarted(BestSolutionRecaller.java:50)
      at org.optaplanner.core.impl.solver.AbstractSolver.solvingStarted(AbstractSolver.java:65)
      at org.optaplanner.core.impl.solver.DefaultSolver.solvingStarted(DefaultSolver.java:225)
      at org.optaplanner.core.impl.solver.DefaultSolver.solve(DefaultSolver.java:192)

the solving process is computing a score  - that is consuming all constraints which are dependent on my shadow variables - before the listener can do its magic. Does this mean, that shadow variables must be always nullable even if they should not be after the construction heuristic? If so, doesn't this make constraint implementations more complex because of all the additional null checks? Why is the initial score needed before the construction heuristic?

Maybe I have just missed the relevant part of the documentation, explaining process * reasoning. If so I'd appreciate also a simple link.

Thanks & Kind regards,
Holger
 
Reply all
Reply to author
Forward
0 new messages