Commit a30591d5 authored by Martin Heistermann's avatar Martin Heistermann

Merge branch 'constrained-solver-save-memory' into cgg3

parents 3f9d8869 77984b11
Pipeline #16441 passed with stages
in 4 minutes and 4 seconds
......@@ -257,6 +257,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 = true;
......@@ -327,6 +338,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 {
......
......@@ -285,6 +285,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_);
......@@ -338,9 +342,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
......@@ -499,9 +505,11 @@ ConstrainedSolver::make_constraints_independent(
_constraints(c_it.index(), elim_j) = 0;
constraints_c(c_it.index(), elim_j) = 0;
// 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()));
}
}
}
}
......@@ -522,11 +530,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
......@@ -716,9 +726,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()));
}
}
}
}
......@@ -732,7 +744,7 @@ ConstrainedSolver::make_constraints_independent_reordering(
RMatrixT c_tmp(gmm::mat_nrows(_constraints), gmm::mat_ncols(_constraints));
gmm::copy(_constraints, c_tmp);
RowMatrix d_tmp(gmm::mat_nrows(rhs_update_table_.D_), gmm::mat_ncols(rhs_update_table_.D_));
gmm::copy(rhs_update_table_.D_, d_tmp);
rhs_update_table_.D_.swap(d_tmp);
// std::vector<int> elim_temp2(_c_elim);
// std::sort(elim_temp2.begin(), elim_temp2.end());
......@@ -744,7 +756,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::copy(gmm::mat_row(d_tmp, row_ordering[i]), 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]];
}
......
......@@ -24,12 +24,14 @@ find_path( GMM_INCLUDE_DIR
/usr/include
/usr/include
/usr/local/include
~/sw/gmm-5.4/include
~/sw/gmm-5.0/include
~/sw/gmm-4.2/include
~/sw/gmm-4.1/include
"c:\\libs\\gmm-4.2\\include"
"c:\\libs\\gmm-4.1\\include"
"c:\\libs\\gmm-3.0\\include"
"${CMAKE_WINDOWS_LIBS_DIR}/general/gmm-5.4/include"
"${CMAKE_WINDOWS_LIBS_DIR}/general/gmm-5.0/include"
"${CMAKE_WINDOWS_LIBS_DIR}/general/gmm-4.2/include"
${PROJECT_SOURCE_DIR}/MacOS/Libs/gmm-3.1/include
......
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