Skip to content

Commit

Permalink
Make D'Hondt without Lists give necessary data so it doesn't crash.
Browse files Browse the repository at this point in the history
Also fix a mistyped comparison and add the D'Hondt without Lists method
to the multiwinner.cc runner now that it works.
  • Loading branch information
kristomu committed Aug 26, 2024
1 parent feb613a commit ecea52b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
9 changes: 5 additions & 4 deletions src/main/multiwinner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -538,9 +538,10 @@ int main(int argc, char * * argv) {
false));
other_methods.push_back(std::make_shared<cardinal_ratings>(-10, 10, true));

// TODO: FIX
/*condorcet.push_back(std::make_shared<minmax>(CM_WV));
condorcet.push_back(std::make_shared<minmax>(CM_MARGINS));*/
// These are not all Condorcet. Minmin is not.
// TODO: Better name for the vector.
condorcet.push_back(std::make_shared<ext_minmax>(CM_MARGINS, true));
condorcet.push_back(std::make_shared<ext_minmax>(CM_MARGINS, false));
condorcet.push_back(std::make_shared<schulze>(CM_WV));

for (counter = 0; counter < condorcet.size(); ++counter) {
Expand Down Expand Up @@ -568,7 +569,7 @@ int main(int argc, char * * argv) {

// Maybe: IRV-SNTV

for (counter = 1; counter < condorcet.size(); ++counter) {
for (counter = 0; counter < condorcet.size(); ++counter) {
e_methods.push_back(multiwinner_stats(
std::make_shared<reweighted_condorcet>(
condorcet[counter])));
Expand Down
6 changes: 2 additions & 4 deletions src/multiwinner/dhwl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
std::list<int> reweighted_condorcet::get_council(int council_size,
int num_candidates, const election_t & ballots) const {

if (council_size <= num_candidates) {
if (council_size > num_candidates) {
throw std::invalid_argument("multiwinner: Too few candidates for the council");
}

Expand All @@ -19,8 +19,6 @@ std::list<int> reweighted_condorcet::get_council(int council_size,

while (council_count < council_size) {

std::cerr << "[" << council_count << "]" << std::flush;

// TODO: Fix later. DHwL no longer implements it.
bool tie_at_top = false;

Expand All @@ -46,4 +44,4 @@ std::list<int> reweighted_condorcet::get_council(int council_size,
}

return (council);
}
}
15 changes: 14 additions & 1 deletion src/multiwinner/dhwl_mat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@ void DHwLmatrix::count_ballots(const election_t & scores,
election_t::const_iterator pri;
std::list<candscore>::const_iterator checker, against;

// First set the total number of voters (voting weight),
// which the abstract matrix class requires.

double total_weight = 0;

for (pri = scores.begin(); pri != scores.end(); ++pri) {
total_weight += pri->get_weight();
}

set_num_voters(total_weight);

// Then set the pairwise contests.

for (pri = scores.begin(); pri != scores.end(); ++pri) {
// Reduce n^2 to n as set iterations are extremely slow.
// KLUDGE.
Expand Down Expand Up @@ -120,4 +133,4 @@ DHwLmatrix::DHwLmatrix(const election_t & scores, const

zeroize(num_candidates);
count_ballots(scores, num_candidates);
}
}

0 comments on commit ecea52b

Please sign in to comment.