[PPL-devel] [GIT] ppl/ppl(master): Added helper function sub_mul_assign() to Linear_Expression interface.

Enea Zaffanella zaffanella at cs.unipr.it
Thu Mar 25 13:01:38 CET 2010


Module: ppl/ppl
Branch: master
Commit: 6f07d12fc19f7b867a5b43f6f143f2fd202ff928
URL:    http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=6f07d12fc19f7b867a5b43f6f143f2fd202ff928

Author: Enea Zaffanella <zaffanella at cs.unipr.it>
Date:   Thu Mar 25 12:00:22 2010 +0100

Added helper function sub_mul_assign() to Linear_Expression interface.

---

 src/Linear_Expression.cc      |   19 +++++++++++++++++++
 src/Linear_Expression.defs.hh |    9 +++++++++
 2 files changed, 28 insertions(+), 0 deletions(-)

diff --git a/src/Linear_Expression.cc b/src/Linear_Expression.cc
index f7d50a3..cd8ace8 100644
--- a/src/Linear_Expression.cc
+++ b/src/Linear_Expression.cc
@@ -373,6 +373,25 @@ PPL::add_mul_assign(Linear_Expression& e,
   return e;
 }
 
+/*! \relates Parma_Polyhedra_Library::Linear_Expression */
+PPL::Linear_Expression&
+PPL::sub_mul_assign(Linear_Expression& e,
+                    Coefficient_traits::const_reference n,
+                    const Variable v) {
+  const dimension_type v_space_dim = v.space_dimension();
+  if (v_space_dim > Linear_Expression::max_space_dimension())
+    throw std::length_error("Linear_Expression& "
+                            "PPL::sub_mul_assign(e, n, v):\n"
+			    "v exceeds the maximum allowed space dimension.");
+  const dimension_type e_size = e.size();
+  if (e_size <= v_space_dim) {
+    Linear_Expression new_e(e, v_space_dim+1);
+    e.swap(new_e);
+  }
+  e[v_space_dim] -= n;
+  return e;
+}
+
 bool
 PPL::Linear_Expression::OK() const {
   return Linear_Row::OK();
diff --git a/src/Linear_Expression.defs.hh b/src/Linear_Expression.defs.hh
index 5e4c81d..222ba57 100644
--- a/src/Linear_Expression.defs.hh
+++ b/src/Linear_Expression.defs.hh
@@ -172,6 +172,12 @@ Linear_Expression&
 add_mul_assign(Linear_Expression& e,
                Coefficient_traits::const_reference n, Variable v);
 
+//! Returns the linear expression \p e - \p n * \p v and assigns it to \p e.
+/*! \relates Linear_Expression */
+Linear_Expression&
+sub_mul_assign(Linear_Expression& e,
+               Coefficient_traits::const_reference n, Variable v);
+
 namespace IO_Operators {
 
 //! Output operator.
@@ -469,6 +475,9 @@ private:
   friend Linear_Expression&
   add_mul_assign(Linear_Expression& e,
                  Coefficient_traits::const_reference n, Variable v);
+  friend Linear_Expression&
+  sub_mul_assign(Linear_Expression& e,
+                 Coefficient_traits::const_reference n, Variable v);
 
   friend std::ostream&
   Parma_Polyhedra_Library::IO_Operators




More information about the PPL-devel mailing list