Commit 6575f802 authored by Chuanren Wu's avatar Chuanren Wu

add freedom

parent fc85f71e
......@@ -35,6 +35,7 @@ struct ConstraintExt
int knownLengthMinus;
std::set<int> knownPlus;
std::set<int> knownMinus;
std::vector<int> *freedom;
};
static double totalLength(
......@@ -48,13 +49,15 @@ static double totalLength(
);
}
ConstraintExt::ConstraintExt(const Constraint &c, const std::vector<double> &vl)
: plus(c.plus())
, minus(c.minus())
, totalLengthPlus(totalLength(plus, vl))
, totalLengthMinus(totalLength(minus, vl))
, knownLengthPlus(0)
, knownLengthMinus(0)
ConstraintExt::ConstraintExt(
const Constraint &c,
const std::vector<double> &vl
) : plus(c.plus())
, minus(c.minus())
, totalLengthPlus(totalLength(plus, vl))
, totalLengthMinus(totalLength(minus, vl))
, knownLengthPlus(0)
, knownLengthMinus(0)
{
}
......@@ -65,7 +68,11 @@ struct LengthHelper
double operator()()
// { return isPlus ? c->totalLengthPlus : c->totalLengthMinus; }
// { return isPlus ? c->totalLengthPlus - c->knownLengthPlus : c->totalLengthMinus - c->knownLengthMinus; }
{ return isPlus ? c->plus.size() : c->minus.size(); }
// { return isPlus ? c->plus.size() : c->minus.size(); }
{ return isPlus
? std::accumulate(c->plus.cbegin(), c->plus.cend(), 0, [this](int s, int i) { return s+(*c->freedom)[i]; })
: std::accumulate(c->minus.cbegin(), c->minus.cend(), 0, [this](int s, int i) { return s+(*c->freedom)[i]; });
}
};
static ELIMINATION_ERROR insertNewValues(
......@@ -98,12 +105,14 @@ static ELIMINATION_ERROR insertNewValues(
for (auto &c : vc) {
auto it = c.plus.find(p.first);
if (it != c.plus.cend()) {
--(*vc[0].freedom)[p.first];
c.plus.erase(it);
c.knownPlus.insert(p.first);
c.knownLengthPlus += p.second;
}
it = c.minus.find(p.first);
if (it != c.minus.cend()) {
--(*vc[0].freedom)[p.first];
c.minus.erase(it);
c.knownMinus.insert(p.first);
c.knownLengthMinus += p.second;
......@@ -314,13 +323,25 @@ std::vector<int> discretizeImpl(
)
{
assert(!vl.empty());
assert(!vc.empty());
assert(std::all_of(vl.cbegin(), vl.cend(),
std::bind2nd(std::greater_equal<double>(), 1.0)));
std::vector<int> freedom(vl.size());
std::fill(freedom.begin(), freedom.end(), -1);
std::vector<ConstraintExt> ve;
ve.reserve(vc.size());
for (const auto &c : vc) {
ve.push_back(ConstraintExt(c, vl));
for (const auto &i : c.plus()) {
++freedom[i];
}
for (const auto &i : c.minus()) {
++freedom[i];
}
auto a = ConstraintExt(c, vl);
a.freedom = &freedom;
ve.push_back(a);
}
std::vector<LengthHelper> lh;
......
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