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

Vn first multi #57

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft

Vn first multi #57

wants to merge 2 commits into from

Conversation

hhirtz
Copy link
Member

@hhirtz hhirtz commented Mar 24, 2022

Related to #54

It's just a proof of concept and not to be merged.


The current "mono" implementation of vnfirst can actually be used for multi-criteria partitioning, thanks to generic types.

This PR makes use of nalgebra's SVector<T, const D: usize>, a wrapper around [T; D] that implements arithmetic operations and PartialOrd to effectively feed vector of numbers to the mono-criterion implementation of vnfirst.

It also turns out there were some mistakes made during the port from the aire-de-jeu. Those are fixed I think but I didn't have the motivation to split these changes into separate commits.

Limitations

Notably the SVector implementation of PartialOrd returns:

  • Some(Greater)/Some(Lesser)/Some(Equal) when all elements of the first vector are greater/lesser/equal to those of the other,
  • None otherwise,

This is the reason why this if/else has been rewriten:

if new_imbalance <= imbalance {

and also messes with Itertools::minmax calls, I think, where we want the min and the max loads across all criteria.

@hhirtz hhirtz changed the title Vn first multi WIP: Vn first multi Mar 24, 2022
Comment on lines -59 to -78
if imbalance < new_imbalance {
if new_imbalance <= imbalance {
// The move decreases the partition imbalance.
imbalance = new_imbalance;
max_load = new_max_load;
partition[i] = q;
i_last = i;
} else {
// The move does not decrease the partition imbalance.
part_loads[p] += weights[i].clone();
part_loads[q] = part_loads[p].clone() - weights[i].clone();
continue;
}
imbalance = new_imbalance;
max_load = new_max_load;
partition[i] = q;
i_last = i;
Copy link
Member Author

@hhirtz hhirtz Mar 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This diff is so that vnfirst does not make the move when T::partial_cmp(imbalance, new_imbalance) returns None (imbalance < new_imbalance would return false, thus making the move)

However, this means vnfirst only makes a move when there are gains on all criterion at once, which is overly restrictive.

@hhirtz hhirtz marked this pull request as draft May 11, 2022 11:40
@hhirtz hhirtz changed the title WIP: Vn first multi Vn first multi May 11, 2022
@codecov
Copy link

codecov bot commented Jun 28, 2022

Codecov Report

Merging #57 (f9a1e66) into master (0c996e0) will increase coverage by 0.36%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master      #57      +/-   ##
==========================================
+ Coverage   50.25%   50.62%   +0.36%     
==========================================
  Files          42       42              
  Lines        7223     7143      -80     
==========================================
- Hits         3630     3616      -14     
+ Misses       3593     3527      -66     
Impacted Files Coverage Δ
src/algorithms/vn/first.rs 96.49% <100.00%> (+25.17%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0c996e0...f9a1e66. Read the comment docs.

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.

1 participant