[GIT] ppl/ppl(pip): Improved helper function merge_assign(): add all new rows at once.

Module: ppl/ppl Branch: pip Commit: e10ef6e9a1b924ff1cd14372198a69a1ddc84abf URL: http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=e10ef6e9a1b92...
Author: Enea Zaffanella zaffanella@cs.unipr.it Date: Sat Jan 30 22:22:51 2010 +0100
Improved helper function merge_assign(): add all new rows at once.
---
src/PIP_Problem.cc | 3 +-- src/PIP_Tree.cc | 32 +++++++++++++++++++------------- 2 files changed, 20 insertions(+), 15 deletions(-)
diff --git a/src/PIP_Problem.cc b/src/PIP_Problem.cc index 9f23bb2..0e48871 100644 --- a/src/PIP_Problem.cc +++ b/src/PIP_Problem.cc @@ -282,8 +282,7 @@ PPL::PIP_Problem::ascii_dump(std::ostream& s) const { for (dimension_type i = 0; i < input_cs_size; ++i) input_cs[i].ascii_dump(s);
- s << "\nfirst_pending_constraint: " << first_pending_constraint - << std::endl; + s << "\nfirst_pending_constraint: " << first_pending_constraint << "\n";
s << "\ninitialized: " << (initialized ? "YES" : "NO") << "\n";
diff --git a/src/PIP_Tree.cc b/src/PIP_Tree.cc index 8cf8d29..cb85de7 100644 --- a/src/PIP_Tree.cc +++ b/src/PIP_Tree.cc @@ -60,21 +60,27 @@ sub_assign(Row& x, const Row& y) { void merge_assign(Matrix& x, const Constraint_System& y, - const Variables_Set ¶meters) { - dimension_type width = x.num_columns(); - PPL_ASSERT(parameters.size() == width-1); - Row row(width, Row::Flags()); - Variables_Set::iterator param_begin = parameters.begin(); - Variables_Set::iterator param_end = parameters.end(); - Variables_Set::iterator pi; - dimension_type j; + const Variables_Set& parameters) { + PPL_ASSERT(parameters.size() == x.num_columns() - 1); + const dimension_type new_rows = std::distance(y.begin(), y.end()); + if (new_rows == 0) + return; + const dimension_type old_num_rows = x.num_rows(); + x.add_zero_rows(new_rows, Row::Flags()); + // Compute once for all. + const Variables_Set::const_iterator param_begin = parameters.begin(); + const Variables_Set::const_iterator param_end = parameters.end(); + + dimension_type i = old_num_rows; for (Constraint_System::const_iterator y_i = y.begin(), - y_end = y.end(); y_i != y_end; ++y_i) { + y_end = y.end(); y_i != y_end; ++y_i, ++i) { PPL_ASSERT(y_i->is_nonstrict_inequality()); - row[0] = y_i->inhomogeneous_term(); - for (pi=param_begin, j=1; pi != param_end; ++pi, ++j) - row[j] = y_i->coefficient(Variable(*pi)); - x.add_row(row); + Row& x_i = x[i]; + x_i[0] = y_i->inhomogeneous_term(); + Variables_Set::const_iterator pj; + dimension_type j = 1; + for (pj = param_begin; pj != param_end; ++pj, ++j) + x_i[j] = y_i->coefficient(Variable(*pj)); } }
participants (1)
-
Enea Zaffanella