Shadow variable listener

20 views
Skip to first unread message

Patrick Ondreovici

unread,
Jan 17, 2023, 3:34:28 AM1/17/23
to OptaPlanner development
Hi, I'm curious if it is possible to use the same listener for 2 shadow variables, so that the listener will be called one time for both variables.

Jiří Locker

unread,
Jan 17, 2023, 10:34:27 AM1/17/23
to OptaPlanner development
Hi Patrick,

If I understand your question correctly, the answer is no. The variable listener is called for each source variable independently. So even when there is a move that changes both source variables of the listener, it will result in two separate invocations of before/afterVariableChanged() on the variable listener.

Does that cause any issues in your use case?

Jiri

holger brandl

unread,
Jan 18, 2023, 3:26:48 AM1/18/23
to OptaPlanner development
Hi there,

isn't this precisely the use-case for a PiggyBackShadowVariable (see https://docs.optaplanner.org/latest/optaplanner-docs/html_single/index.html#_piggyback_shadow_variable)? From my understanding it should allow updating two shadow variables more efficiently with one listener.

Best Holger

Patrick Ondreovici

unread,
Jan 18, 2023, 8:09:18 AM1/18/23
to OptaPlanner development

Thanks for the answer

Jiří Locker

unread,
Jan 18, 2023, 8:17:02 AM1/18/23
to OptaPlanner development
I think Holger is right and my previous answer is not relevant because I missed the word "shadow".
Reply all
Reply to author
Forward
0 new messages