[PPL-devel] [GIT] ppl/ppl(master): FIXME resolved. Fixed a bug in Linear_Expression( Variable v, Variable w).
Roberto Bagnara
bagnara at cs.unipr.it
Sun Mar 22 12:23:02 CET 2009
Module: ppl/ppl
Branch: master
Commit: cb448212741bfb74cf3538cef7ffc32ff184cf34
URL: http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=cb448212741bfb74cf3538cef7ffc32ff184cf34
Author: Roberto Bagnara <bagnara at cs.unipr.it>
Date: Sun Mar 22 12:21:32 2009 +0100
FIXME resolved. Fixed a bug in Linear_Expression(Variable v, Variable w).
The bug would cause a wrong result to be computed when v == w.
---
src/Linear_Expression.cc | 17 ++++++++++++++
src/Linear_Expression.defs.hh | 2 +
src/Linear_Expression.inlines.hh | 17 ++++----------
tests/Polyhedron/.gitignore | 2 +-
tests/Polyhedron/Makefile.am | 4 +-
tests/Polyhedron/linearexpression1.cc | 39 ++++++++++++++++++++++-----------
6 files changed, 53 insertions(+), 28 deletions(-)
diff --git a/src/Linear_Expression.cc b/src/Linear_Expression.cc
index 5ba3ccc..aabaad5 100644
--- a/src/Linear_Expression.cc
+++ b/src/Linear_Expression.cc
@@ -119,6 +119,23 @@ PPL::operator+(Coefficient_traits::const_reference n,
return r;
}
+/*! \relates Linear_Expression */
+PPL::Linear_Expression
+PPL::operator+(const Variable v, const Variable w) {
+ const dimension_type v_space_dim = v.space_dimension();
+ const dimension_type w_space_dim = w.space_dimension();
+ const dimension_type space_dim = std::max(v_space_dim, w_space_dim);
+ if (space_dim > Linear_Expression::max_space_dimension())
+ throw std::length_error("Linear_Expression "
+ "PPL::operator+(v, w):\n"
+ "v or w exceed the maximum allowed "
+ "space dimension.");
+ Linear_Expression r(space_dim+1, true);
+ ++r[v_space_dim];
+ ++r[w_space_dim];
+ return r;
+}
+
/*! \relates Parma_Polyhedra_Library::Linear_Expression */
PPL::Linear_Expression
PPL::operator-(const Linear_Expression& e) {
diff --git a/src/Linear_Expression.defs.hh b/src/Linear_Expression.defs.hh
index 9fcc77a..db4af74 100644
--- a/src/Linear_Expression.defs.hh
+++ b/src/Linear_Expression.defs.hh
@@ -408,6 +408,8 @@ private:
operator+(Coefficient_traits::const_reference n, const Linear_Expression& e);
friend Linear_Expression
operator+(const Linear_Expression& e, Coefficient_traits::const_reference n);
+ friend Linear_Expression
+ operator+(Variable v, Variable w);
friend Linear_Expression
operator-(const Linear_Expression& e);
diff --git a/src/Linear_Expression.inlines.hh b/src/Linear_Expression.inlines.hh
index f1fb619..a5da9d2 100644
--- a/src/Linear_Expression.inlines.hh
+++ b/src/Linear_Expression.inlines.hh
@@ -47,14 +47,14 @@ Linear_Expression::Linear_Expression(dimension_type sz, bool)
inline
Linear_Expression::Linear_Expression(const Variable v)
: Linear_Row(v.space_dimension() <= max_space_dimension()
- ? v.id() + 2
+ ? v.space_dimension() + 1
: (throw std::length_error("PPL::Linear_Expression::"
"Linear_Expression(v):\n"
"v exceeds the maximum allowed "
"space dimension."),
- v.id() + 2)
+ v.space_dimension() + 1)
, Linear_Row::Flags()) {
- (*this)[v.id() + 1] = 1;
+ ++((*this)[v.space_dimension()]);
}
inline
@@ -70,8 +70,8 @@ Linear_Expression::Linear_Expression(const Variable v, const Variable w)
"space dimension.");
construct(space_dim+1, Linear_Row::Flags());
if (v_space_dim != w_space_dim) {
- (*this)[v_space_dim] = 1;
- (*this)[w_space_dim] = -1;
+ ++((*this)[v_space_dim]);
+ --((*this)[w_space_dim]);
}
}
@@ -143,13 +143,6 @@ operator+(const Linear_Expression& e, Coefficient_traits::const_reference n) {
/*! \relates Linear_Expression */
inline Linear_Expression
-operator+(const Variable v, const Variable w) {
- // FIXME(0.10.1): provide a better implementation.
- return Linear_Expression(v) + Linear_Expression(w);
-}
-
-/*! \relates Linear_Expression */
-inline Linear_Expression
operator+(const Variable v, const Linear_Expression& e) {
// FIXME(0.10.1): provide a better implementation.
return e + Linear_Expression(v);
diff --git a/tests/Polyhedron/.gitignore b/tests/Polyhedron/.gitignore
index 69b05a3..8fa7846 100644
--- a/tests/Polyhedron/.gitignore
+++ b/tests/Polyhedron/.gitignore
@@ -72,7 +72,7 @@ limitedh79extrapolation1
linearpartition1
linearsystem1
linearsystem1.dat
-linexpression1
+linearexpression1
mapspacedims1
matrix1
matrix1.dat
diff --git a/tests/Polyhedron/Makefile.am b/tests/Polyhedron/Makefile.am
index 9063201..98c0189 100644
--- a/tests/Polyhedron/Makefile.am
+++ b/tests/Polyhedron/Makefile.am
@@ -100,7 +100,7 @@ simplifyusingcontext1 \
limitedbhrz03extrapolation1 \
limitedh79extrapolation1 \
linearpartition1 \
-linexpression1 \
+linearexpression1 \
linearsystem1 \
mapspacedims1 \
matrix1 \
@@ -330,7 +330,7 @@ limitedh79extrapolation1_SOURCES = limitedh79extrapolation1.cc
linearpartition1_SOURCES = linearpartition1.cc
-linexpression1_SOURCES = linexpression1.cc
+linearexpression1_SOURCES = linearexpression1.cc
linearsystem1_SOURCES = linearsystem1.cc
diff --git a/tests/Polyhedron/linearexpression1.cc b/tests/Polyhedron/linearexpression1.cc
index 1de2763..84a7f16 100644
--- a/tests/Polyhedron/linearexpression1.cc
+++ b/tests/Polyhedron/linearexpression1.cc
@@ -52,26 +52,39 @@ test01() {
bool
test02() {
- Variable A(0);
- Variable B(15);
+ Variable A(15);
+ Variable B(0);
Linear_Expression e1 = A;
Linear_Expression e2 = B;
- Linear_Expression known_result = e1 + e2;
+ Linear_Expression known_result1 = e1 + e2;
- bool ok = EQUIVALENT(A + B, known_result)
- && EQUIVALENT(B + A, known_result)
- && EQUIVALENT(Linear_Expression(A) + B, known_result)
- && EQUIVALENT(B + Linear_Expression(A), known_result)
- && EQUIVALENT(A + Linear_Expression(B), known_result)
- && EQUIVALENT(Linear_Expression(B) + A, known_result)
- && EQUIVALENT(Linear_Expression(B) + Linear_Expression(A), known_result);
+ bool ok1 = EQUIVALENT(A + B, known_result1)
+ && EQUIVALENT(B + A, known_result1)
+ && EQUIVALENT(Linear_Expression(A) + B, known_result1)
+ && EQUIVALENT(B + Linear_Expression(A), known_result1)
+ && EQUIVALENT(A + Linear_Expression(B), known_result1)
+ && EQUIVALENT(Linear_Expression(B) + A, known_result1)
+ && EQUIVALENT(Linear_Expression(B) + Linear_Expression(A), known_result1);
- nout << "*** known_result ***" << endl
- << known_result << endl;
+ nout << "*** known_result1 ***" << endl
+ << known_result1 << endl;
- return ok;
+ Linear_Expression known_result2 = e1 + e1;
+
+ bool ok2 = EQUIVALENT(A + A, known_result2)
+ && EQUIVALENT(A + A, known_result2)
+ && EQUIVALENT(Linear_Expression(A) + A, known_result2)
+ && EQUIVALENT(A + Linear_Expression(A), known_result2)
+ && EQUIVALENT(A + Linear_Expression(A), known_result2)
+ && EQUIVALENT(Linear_Expression(A) + A, known_result2)
+ && EQUIVALENT(Linear_Expression(A) + Linear_Expression(A), known_result2);
+
+ nout << "*** known_result2 ***" << endl
+ << known_result2 << endl;
+
+ return ok1 && ok2;
}
} // namespace
More information about the PPL-devel
mailing list