understanding how constraint streams calculate score deltas #1209
Replies: 1 comment 4 replies
-
Hello @Behrouz-Babaki! I remember the ICON challenge well, since I actually contributed much of OptaPlanner's submission there. :-)
There isn't. Constraint Streams API is implemented with an algorithm that is very similar to RETE. As much as it would be good to have an overview of the architecture somewhere in the docs, let's take a look at your second question first, to understand why we haven't spent the time.
The mental model is roughly accurate, but there is so much more going on under the hood. I want to turn the question around - why do you feel like you need to understand what CS does, in order to be able to implement a solution using Timefold Solver? In my opinion, that's the wrong thinking - write a decent object-oriented model, and let it be our job to turn that model into an efficient incremental operation. We do not want people reverse engineering the engine and making their modeling decisions on implementation details. Implementations change, and if understanding these details would be necessary to use Timefold Solver, then we have failed in our mission. My advice is to write simple natural code, measure its performance, and if you see performance issues, then it's time to discuss those. We have also published some general recommendations to avoid the most typical issues. Finally, I hope you don't mind a little correction - it's "Timefold", the "f" is not capitalized. |
Beta Was this translation helpful? Give feedback.
-
First of all, I take this opportunity to thank all TimeFold developers for their amazing work. I first learned about @ge0ffrey 's work in 2014, when OptaPlanner ranked second in the ICON energy scheduling challenge that I was helping organizing. But it was only very recently that I had the opportunity to have a closer look at TimeFold, and I must say that I'm even more impressed.
I'm trying to learn TimeFold by applying it to a real-world project. I have realized that when I'm defining the constraint streams, I need an understanding (even high level) of the delta calculation mechanism, based on which I can choose how to model the problem. I tried to form this understanding by reading the documentation, checking the GitHub discussions, and some of the messages in
optaplanner-dev
group. However, I'm still not sure if I have a correct model of this mechanism. That's why I decided to present my mental model, and ask a few questions. Apologies for the long message.A mental model
Here is my mental model of how score delta calculation works. A move introduces some changes in genuine variables which, as described thoroughly in TimeFold documentation, trigger changes in shadow variables:
My assumption is that every change to a shadow variable is communicated to the
ScoreDirector
inVriableListener
, and that's howScoreDirector
knows about all changed variables:and then when the constraint streams are used for calculating the score delta, in
forEach(SomePlanningEntity.class)
,join(SomePlanningEntity.class)
, etc. there is an implicit filter that only considers the instances of a planning entity that contain a changed genuine or shadow variable.Questions
Thanks again for your time.
Beta Was this translation helpful? Give feedback.
All reactions