-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: loadBalance() constraint collector #841
Conversation
@Christopher-Chianelli For you to review. |
df08bb3
to
48e2da8
Compare
docs/src/modules/ROOT/pages/constraints-and-score/load-balancing-and-fairness.adoc
Outdated
Show resolved
Hide resolved
a05fc60
to
35e8c2b
Compare
Quality Gate passedIssues Measures |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My primary concerns:
- How to load balance minutes
- How
Ann: 5 shifts, Beth: no shifts
should be handled
Formula looks okay and seems to behave well enough, provided
we are okay with a completely fair schedule being penalized.
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
public final class LoadBalanceCalculator implements ObjectCalculator<Object, BigDecimal> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, if I am reading this correctly, this does sqrt(sum(count^2))
?
This has the consequence that a "fair" schedule result increases as the number of shifts increases:
Assume two employees, and a perfectly fair schedule, a perfectly fair schedule that is off by one, and a completely unfair schedule. Then these will be the score impact of fairness:
- 2 shifts: fair:
sqrt(2)
, slightly unfair:sqrt(4)
, completely unfair:sqrt(4)
= 2 (max difference: 0.585786438) - 4 shifts: fair:
sqrt(8)
, slightly unfair:sqrt(10)
, completely unfair:sqrt(16)
= 4 (max difference: 1.171572875) - 8 shifts: fair:
sqrt(32)
, slightly unfair:sqrt(34)
, completely unfair:sqrt(64)
= 8 (max difference: 2.343145751)
This means the "baseline" of a perfectly fair schedule increases, and the maximum difference in score increases linearly with the number of shifts.
An alternative formula is "Root of squared deviation from the mean":
sqrt(sum((count - average count)^2))
.
For the same dataset:
- 2 shifts: fair: 0, slightly unfair:
sqrt(2)
, completely unfair:sqrt(2)
(max difference: sqrt(2) = 1.414213562) - 4 shifts: fair: 0, slightly unfair:
sqrt(2)
, completely unfair:sqrt(8)
(max difference: sqrt(8) = 2.828427125) - 8 shifts: fair: 0, slightly unfair:
sqrt(2)
, completely unfair:sqrt(32)
(max difference: sqrt(32) = 5.656854249)
the baseline remains the same, although the max difference still scales linearly.
private BigDecimal result = null; | ||
|
||
@Override | ||
public void insert(Object o) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does this handle "load balance by minutes worked"?
Closing this PR and will bring a re-thought approach. |
No description provided.