Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

triceo
Copy link
Contributor

@triceo triceo commented May 13, 2024

No description provided.

@triceo triceo marked this pull request as ready for review May 15, 2024 10:13
@triceo
Copy link
Contributor Author

triceo commented May 15, 2024

@Christopher-Chianelli For you to review.
To get used to Python, I will leave this PR open until there is a corresponding PR for the Python solver. (I'm expecting we'll need to introduce the collector there, and some tests.)
Don't keep me waiting for too long. ;-)

@triceo triceo force-pushed the fairness branch 5 times, most recently from df08bb3 to 48e2da8 Compare May 15, 2024 10:52
@triceo triceo force-pushed the fairness branch 3 times, most recently from a05fc60 to 35e8c2b Compare May 15, 2024 11:28
Copy link

sonarcloud bot commented May 15, 2024

Copy link
Contributor

@Christopher-Chianelli Christopher-Chianelli left a 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> {
Copy link
Contributor

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) {
Copy link
Contributor

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"?

@triceo
Copy link
Contributor Author

triceo commented May 31, 2024

Closing this PR and will bring a re-thought approach.

@triceo triceo closed this May 31, 2024
@triceo triceo deleted the fairness branch May 31, 2024 09:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants