How to configure a VariableListener?

21 views
Skip to first unread message

holger brandl

unread,
Nov 29, 2022, 3:50:25 AM11/29/22
to OptaPlanner development
Hi,

from the manual I've learned that we can set custom properties (https://docs.optaplanner.org/latest/optaplanner-docs/html_single/index.html#customPropertiesConfiguration). However, I struggle to apply this concept to a variable listener implementation (ResponseTimeUpdatingVariableListener), which is configured via annotation in my planning entity class (stripped down for sharing): 

class Task() : PreviousTaskOrTool() {
    @CustomShadowVariable(
        variableListenerClass = ResponseTimeUpdatingVariableListener::class,
        sources = [PlanningVariableReference(variableName = "previousTaskOrTool")]
    )
    var estimatedWaiting: Duration? = null
}

How can I set a custom property in my ResponseTimeUpdatingVariableListener implementation? Following the documentation, I could add a setter


...
    long processOffsetSeconds;

    public void setProcessOffsetSeconds(long processOffsetSeconds) {
        this.processOffsetSeconds = processOffsetSeconds;
    }
...

However, it's unclear to me how to configure the value when creating the solver:

    SolverConfig()
        .withSolutionClass(ProductionSchedule::class.java)
        . <how can we set the process offset here>

In case this approach is not supported, is there an alternative solution to configure classes within an optaplanner solver?

I'd appreciate any pointer or support!

Thanks & kind regards,
Holger

Jiří Locker

unread,
Nov 29, 2022, 9:43:56 AM11/29/22
to OptaPlanner development
Hi Holger,

Unfortunately, what you are looking for is not possible. Custom properties can only be applied to user classes that are specified through the Config API (SolverConifg class or `solverConfig.xml`), for example, score calculator or solution partitioner classes.

It is not possible to apply custom properties to classes specified in the domain model (through annotations). Shadow variable listeners can only be specified using an annotation in the domain.

Regards,
Jiri
Reply all
Reply to author
Forward
0 new messages