Replies: 3 comments 5 replies
-
Hey there! The problem appears to be in your accumulator. You need something like this:
In your accumulator, you're only returning the undo I'll convert this issue to a discussion, as my current understanding indicates this is not a solver problem. If there's still something to explain, we can continue there. |
Beta Was this translation helpful? Give feedback.
-
Side note: if you need a minMax collector, you can |
Beta Was this translation helpful? Give feedback.
-
Thank you very much, @triceo! For anyone encountering a similar task, below you'll find the corrected and simplified Collector.
|
Beta Was this translation helpful? Give feedback.
-
Describe the bug
I'm implementing a custom BiConstraintCollector for use in groupBy() constraint streams.
For some reason, the elements are not collected, the provided ResultContainer remains empty, and the constraint doesn't penalize.
It might very well be that I'm using the API wrong (e.g. the two consecutive calls of groupBy come to mind). I'll gladly take advice in any direction.
Expected behavior
Invocation of the Runnables for each tuple. Passing of the test.
Actual behavior
The Runnables are not invoked. The test fails with
To Reproduce
My minimal example is based on the CloudBalancing example, and introduces the following additional constraint (which seems odd in this particular example, but for demonstration purposes I hope it'll do):
For each computer, I want to penalize the scheduling of processes that have different cpu requirements. And I want to do this in a per-computer way, so the cost doesn't explode when scheduling lots of small tasks.
So I implemented a MinMaxCollector, with the intention to determine the minimum and maximum cpu requirements of scheduled processes per computer.
I forked the timefold-solver repo and added my BiConstraintCollector, the additional constraint and a unit test here:
https://github.com/thimmwork/timefold-solver/blob/4862eef96575fc061eb5b5cb0727b791790e184a/examples/src/test/java/ai/timefold/solver/examples/cloudbalancing/score/CloudBalancingConstraintProviderTest.java#L84C21-L84C21
This is the constraint I added to
CloudBalancingConstraintProvider
.I'm using the computer.id as key and want to collect the min and max requiredCpuPower of all the processes assigned to each computer.
This is my Collector (for easier code analysis I'm using anonymous classes here)
and a unit test that I added to CloudBalancingConstraintProviderTest:
My expectation would be that the above unit test would trigger the same invocations as this test, which tests the collector directly:
This test works, so the problem is either outside of the BiConstraintCollector or in my understanding.
Environment
Timefold Solver Version or Git ref:
tested on solver 1.20, 1.4.0, 1.5.0 and git commit 490490a (current main)
Output of
java -version
:openjdk 17.0.9 2023-10-17
OpenJDK Runtime Environment Temurin-17.0.9+9 (build 17.0.9+9)
OpenJDK 64-Bit Server VM Temurin-17.0.9+9 (build 17.0.9+9, mixed mode)
Output of
uname -a
orver
:Darwin WYJTH5W7YK 22.6.0 Darwin Kernel Version 22.6.0: Fri Sep 15 13:41:28 PDT 2023; root:xnu-8796.141.3.700.8~1/RELEASE_ARM64_T6000 arm64
Additional information
Provide any and all other information which might be relevant to the issue.
Beta Was this translation helpful? Give feedback.
All reactions