Skip to content

Commit

Permalink
Change rusty code to use vectors instead of VLAs. CFC-Kemeny now works.
Browse files Browse the repository at this point in the history
It is very slow, though, due to its design.

Also fix some finite() invocations in mono_webster and add the MSVC
random() hack, as both of these kept them from compiling on Windows.
  • Loading branch information
kristomu committed Sep 6, 2024
1 parent 35b6f10 commit d6dd52d
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 18 deletions.
13 changes: 6 additions & 7 deletions src/multiwinner/rusty/auxiliary/assignment.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,10 @@ void assignment::initialize(double n, int u, int k,
// Row (constraint #) indices in ia, column indices (var #) in ja,
// multipliers (always 1) in ar.

//int ia[u*k], ja[u*k];
//double ar[u*k];

int ia[u*k*2], ja[u*k*2];
double ar[u*k*2];
// Building these arrays dynamically doesn't work for some
// reason. Find out why later.
std::vector<int> ia(u*k*2, 0), ja(u*k*2, 0);
std::vector<double> ar(u*k*2, 0);

// Now actually link the constraints to the right variables.
// First the ballot power constraints (includes a single row)...
Expand All @@ -143,7 +142,7 @@ void assignment::initialize(double n, int u, int k,
++constraint_num;
}

glp_load_matrix(lp, lincount-1, ia, ja, ar);
glp_load_matrix(lp, ia.size(), ia.data(), ja.data(), ar.data());

// And we're all set to receive the distances.
return;
Expand Down Expand Up @@ -193,4 +192,4 @@ bool assignment::success() const {
double assignment::get_unknown(int index) const {

return (glp_get_col_prim(lp, index+1));
}
}
4 changes: 2 additions & 2 deletions src/multiwinner/rusty/fc_kemeny.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#include <iostream>
#include <iterator>
#include <ext/numeric>
#include <numeric>
#include <vector>

using namespace std;
Expand Down Expand Up @@ -414,4 +414,4 @@ std::list<size_t> fc_kemeny::get_council(size_t council_size,
}

return (toRet);
}
}
8 changes: 5 additions & 3 deletions src/multiwinner/rusty/mono_webst_640.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include "setwise/coalition.h"
#include "tools/tools.h"

#include "hack/msvc_random.h"

using namespace std;

enum margin_type { MM_PLUSONE = 0, MM_PLUSHALF = 1, MM_FABS = 2, MM_INVERTED = 3 };
Expand Down Expand Up @@ -234,7 +236,7 @@ std::set<std::set<int> > mono_webster_640::get_passed_lowest(
}
}

assert(finite(last_true));
assert(isfinite(last_true));

std::set<std::set<int> > passed_sets = get_passed_sets(constraints, in,
last_true);
Expand All @@ -255,7 +257,7 @@ std::set<std::set<int> > mono_webster_640::get_passed_lowest(
}
divisor = last_true;

if (finite(last_true)) {
if (isfinite(last_true)) {
return (passed_sets);
} else {
return (std::set<std::set<int> >()); // Shouldn't happen
Expand Down Expand Up @@ -526,4 +528,4 @@ std::list<size_t> mono_webster_640::get_council(size_t council_size,
copy(council.begin(), council.end(), inserter(toRet, toRet.begin()));

return (toRet);
}
}
8 changes: 5 additions & 3 deletions src/multiwinner/rusty/mono_webst_c37.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include "setwise/coalition.h"
#include "tools/tools.h"

#include "hack/msvc_random.h"

using namespace std;

enum margin_type_c37 { MMC_PLUSONE = 0, MMC_PLUSHALF = 1, MMC_FABS = 2,
Expand Down Expand Up @@ -364,7 +366,7 @@ std::set<std::set<int> > mono_webster_c37::get_passed_lowest(
}
}

assert(finite(last_true));
assert(isfinite(last_true));

std::set<std::set<int> > passed_sets = get_passed_sets(constraints, in,
last_true);
Expand All @@ -385,7 +387,7 @@ std::set<std::set<int> > mono_webster_c37::get_passed_lowest(
}
divisor = last_true;

if (finite(last_true)) {
if (isfinite(last_true)) {
return (passed_sets);
} else {
return (std::set<std::set<int> >()); // Shouldn't happen
Expand Down Expand Up @@ -722,4 +724,4 @@ std::list<size_t> mono_webster_c37::get_council(size_t council_size,
copy(council.begin(), council.end(), inserter(toRet, toRet.begin()));

return (toRet);
}
}
8 changes: 5 additions & 3 deletions src/multiwinner/rusty/mono_webst_f03.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

#include "set_functs.h"

#include "hack/msvc_random.h"

using namespace std;

enum margin_type_f03 { MMF_PLUSONE = 0, MMF_PLUSHALF = 1, MMF_FABS = 2,
Expand Down Expand Up @@ -208,7 +210,7 @@ std::set<std::set<int> > mono_webster_f03::get_passed_lowest(
}
}

assert(finite(last_true));
assert(isfinite(last_true));

std::set<std::set<int> > passed_sets = get_passed_sets(constraints, in,
last_true);
Expand All @@ -229,7 +231,7 @@ std::set<std::set<int> > mono_webster_f03::get_passed_lowest(
}
divisor = last_true;

if (finite(last_true)) {
if (isfinite(last_true)) {
return (passed_sets);
} else {
return (std::set<std::set<int> >()); // Shouldn't happen
Expand Down Expand Up @@ -573,4 +575,4 @@ std::list<size_t> mono_webster_f03::get_council(size_t council_size,
copy(council.begin(), council.end(), inserter(toRet, toRet.begin()));

return (toRet);
}
}

0 comments on commit d6dd52d

Please sign in to comment.