Commit d3d3bdc6 authored by Martin Heistermann's avatar Martin Heistermann

ConstrainedSolver: allow saving memory by disabling support for constraint-rhs updates in resolve

parent 266a6d1e
Pipeline #12189 failed with stages
in 8 minutes and 14 seconds
......@@ -260,6 +260,17 @@ public:
/// Set noise-level (how much std output is given) 0 basically none, 1 important stuff (warning/timing, is default), 2+ not so important
void set_noisy( int _noisy) { noisy_ = _noisy;}
/// Support changing the RHS of the constraint system in resolve(). Enabled by default.
/// If this is needed, it must be enabled for the initial solve, not just before the resolve!
/// Warning: This can impose substantial memory overhead for large sparse constraint systems.
void set_support_constraint_rhs_resolve( bool _val) {
support_constraint_rhs_resolve_ = _val;
if (!_val) {
// Disabling support means we don't need the content of D_ anymore.
this->rhs_update_table_.D_ = {};
}
}
// Get/Set whether the constraint reordering is used (default true)
bool& use_constraint_reordering() { return miso_.use_constraint_reordering(); }
......@@ -361,6 +372,9 @@ private:
int noisy_;
bool do_gcd_;
// User-configurable, whether to store information for constraint-rhs resolve:
bool support_constraint_rhs_resolve_ = true;
// --------------- Update by Marcel to enable efficient re-solve with changed rhs ----------------------
// Store for symbolic elimination information for rhs
class rhsUpdateTable {
......
......@@ -346,6 +346,10 @@ ConstrainedSolver::resolve(
// apply stored updates and eliminations to exchanged rhs
if (_constraint_rhs)
{
if (!support_constraint_rhs_resolve_) {
std::cerr << "ERROR: ConstrainedSolver::resolve: resolve() with modified constraint_rhs requested, but support is disabled." << std::endl;
return;
}
// apply linear transformation of Gaussian elimination
rhs_update_table_.cur_constraint_rhs_.resize(gmm::mat_nrows(rhs_update_table_.D_));
gmm::mult(rhs_update_table_.D_, *_constraint_rhs, rhs_update_table_.cur_constraint_rhs_);
......@@ -399,9 +403,11 @@ ConstrainedSolver::make_constraints_independent(
DEB_enter_func;
// setup linear transformation for rhs, start with identity
gmm::size_type nr = gmm::mat_nrows(_constraints);
gmm::resize(rhs_update_table_.D_, nr, nr);
gmm::clear(rhs_update_table_.D_);
for (gmm::size_type i = 0; i < nr; ++i) rhs_update_table_.D_(i, i) = 1.0;
if (support_constraint_rhs_resolve_) {
gmm::resize(rhs_update_table_.D_, nr, nr);
gmm::clear(rhs_update_table_.D_);
for (gmm::size_type i = 0; i < nr; ++i) rhs_update_table_.D_(i, i) = 1.0;
}
// Base::StopWatch sw;
// number of variables
......@@ -560,9 +566,11 @@ ConstrainedSolver::make_constraints_independent(
_constraints(c_it.index(), elim_j) = 0;
constraints_c(c_it.index(), elim_j) = 0;
if (support_constraint_rhs_resolve_) {
// update linear transition of rhs
gmm::add(gmm::scaled(gmm::mat_row(rhs_update_table_.D_, i), val),
gmm::mat_row(rhs_update_table_.D_, c_it.index()));
gmm::add(gmm::scaled(gmm::mat_row(rhs_update_table_.D_, i), val),
gmm::mat_row(rhs_update_table_.D_, c_it.index()));
}
}
}
}
......@@ -583,11 +591,13 @@ ConstrainedSolver::make_constraints_independent_reordering(
DEB_enter_func;
// setup linear transformation for rhs, start with identity
gmm::size_type nr = gmm::mat_nrows(_constraints);
gmm::resize(rhs_update_table_.D_, nr, nr);
gmm::clear(rhs_update_table_.D_);
if (support_constraint_rhs_resolve_) {
gmm::resize(rhs_update_table_.D_, nr, nr);
gmm::clear(rhs_update_table_.D_);
for (gmm::size_type i = 0; i < nr; ++i)
rhs_update_table_.D_(i, i) = 1.0;
for (gmm::size_type i = 0; i < nr; ++i)
rhs_update_table_.D_(i, i) = 1.0;
}
// Base::StopWatch sw;
// number of variables
......@@ -777,9 +787,11 @@ ConstrainedSolver::make_constraints_independent_reordering(
queue.update(static_cast<int>(cur_idx),
static_cast<int>(cur_nnz));
// update linear transition of rhs
gmm::add(gmm::scaled(gmm::mat_row(rhs_update_table_.D_, i), val),
gmm::mat_row(rhs_update_table_.D_, c_it.index()));
if (support_constraint_rhs_resolve_) {
// update linear transition of rhs
gmm::add(gmm::scaled(gmm::mat_row(rhs_update_table_.D_, i), val),
gmm::mat_row(rhs_update_table_.D_, c_it.index()));
}
}
}
}
......@@ -805,7 +817,9 @@ ConstrainedSolver::make_constraints_independent_reordering(
for (unsigned int i = 0; i < nr; ++i)
{
gmm::copy(gmm::mat_row(c_tmp, row_ordering[i]), gmm::mat_row(_constraints, i));
gmm::mat_row(d_tmp, row_ordering[i]).swap(gmm::mat_row(rhs_update_table_.D_, i));
if (support_constraint_rhs_resolve_) {
gmm::mat_row(d_tmp, row_ordering[i]).swap(gmm::mat_row(rhs_update_table_.D_, i));
}
_c_elim[i] = elim_temp[row_ordering[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