Commit 98c565cf authored by Chuanren Wu's avatar Chuanren Wu

fix homogen problem

parent db70438a
......@@ -28,8 +28,17 @@ static void redist(
const double factor = 1/std::accumulate(s.cbegin(), s.cend(), 0.0,
[&vl](double s, int i){ return s+vl[i]; } );
int rest = n;
double rem = 0;
std::for_each(std::next(s.cbegin()), s.cend(), [&](int i){
res[i] = std::max(minRes[i], atLeast1(std::ceil(vl[i]*factor*n)));
const double d = vl[i]*factor*n + rem;
const double x = std::floor(d);
if (x < minRes[i]) {
res[i] = minRes[i];
} else {
res[i] = x;
rem = d-x;
assert(rem < 1);
}
rest -= res[i];
});
const int idFirst = *s.cbegin();
......
......@@ -125,8 +125,8 @@ TEST(BC, HomogeneousLine2)
auto v = discretize(vl, cs);
ASSERT_NE(0, v.size());
for (int i = 1; i <= 10; ++i) {
EXPECT_GE(101, v[i]);
EXPECT_GE(99, v[i]);
EXPECT_GE(101, v[i]) << "at index " << i;
EXPECT_LE(99, v[i]) << "at index " << i;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment