Commit aab2ebfc authored by Chuanren Wu's avatar Chuanren Wu

fix error

parent 7974065f
......@@ -9,9 +9,9 @@
#include <iterator>
#include <iostream>
template<class T> int clamp1(T x)
template<class T> T atLeast1(T x)
{
return x <= 1 ? static_cast<int>(x) : 1;
return x >= 1 ? x : 1;
}
struct ConstraintExt
......@@ -106,7 +106,7 @@ static std::map<int, int> eliminateSide(
std::max(
/* totalLength already >= number of elements * */
c.totalLengthPlus,
clamp1(c.totalLengthMinus-c.knownLengthMinus)*1.1
atLeast1(c.totalLengthMinus - c.knownLengthMinus)*1.1
) - c.knownLengthPlus;
const int nTotal = c.minus.empty() ? c.knownLengthMinus
: std::ceil(realTotal);
......@@ -127,7 +127,7 @@ static std::map<int, int> eliminateSide(
// need to be sorted before assign?
for (const auto &i : c.plus) {
// since the "realTotal - size()" before several lines, we add 1
m[i] = 1 + clamp1(std::floor(vl[i]*factor));
m[i] = 1 + std::floor(vl[i]*factor);
}
// make sure the sum is nTotal
m[*c.plus.cbegin()] = nTotal - std::accumulate(
......@@ -146,7 +146,7 @@ static std::map<int, int> eliminateSide(
std::max(
/* totalLength already >= number of elements * */
c.totalLengthMinus,
clamp1(c.totalLengthPlus-c.knownLengthPlus)*1.1
atLeast1(c.totalLengthPlus - c.knownLengthPlus)*1.1
) - c.knownLengthMinus;
const int nTotal = c.plus.empty() ? c.knownLengthPlus
: std::ceil(realTotal);
......@@ -167,7 +167,7 @@ static std::map<int, int> eliminateSide(
// need to be sorted before assign?
for (const auto &i : c.minus) {
// since the "realTotal - size()" before several lines, we add 1
m[i] = 1 + clamp1(std::floor(vl[i]*factor));
m[i] = 1 + std::floor(vl[i]*factor);
}
// make sure the sum is nTotal
m[*c.minus.cbegin()] = nTotal - std::accumulate(
......
......@@ -124,7 +124,7 @@ TEST(BC, SingleSegment4)
<< vl[0] << " + " << vl[1] << " = "
<< vl[2] << " + " << vl[3];
for (int i = 0; i < 4; ++i) {
EXPECT_LE(vl[i], v[i])
EXPECT_LE(vl[i]-1, v[i])
<< "With equation " << i << " :"
<< vl[0] << " + " << vl[1] << " = "
<< vl[2] << " + " << vl[3]
......
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