[PPL-devel] [GIT] ppl/ppl(products): Bug in frequency() for Octagonal shapes fixed.
Patricia Hill
p.m.hill at leeds.ac.uk
Sun May 24 08:16:12 CEST 2009
Module: ppl/ppl
Branch: products
Commit: 0ef46ef0cbc64d9f9a472d433abf01507fd078fd
URL: http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=0ef46ef0cbc64d9f9a472d433abf01507fd078fd
Author: Patricia Hill <p.m.hill at leeds.ac.uk>
Date: Sat May 23 20:55:47 2009 +0100
Bug in frequency() for Octagonal shapes fixed.
---
src/Octagonal_Shape.templates.hh | 30 +++++++++++++++-----
tests/Octagonal_Shape/frequency1.cc | 50 +++++++++++++++++++++++++++++++++++
2 files changed, 72 insertions(+), 8 deletions(-)
diff --git a/src/Octagonal_Shape.templates.hh b/src/Octagonal_Shape.templates.hh
index 8793f09..b3faa2a 100644
--- a/src/Octagonal_Shape.templates.hh
+++ b/src/Octagonal_Shape.templates.hh
@@ -983,13 +983,8 @@ Octagonal_Shape<T>::frequency(const Linear_Expression& expr,
const dimension_type cj = coherent_index(j);
const dimension_type cjj = coherent_index(j+1);
- // Check if we want the sum or difference constraint.
- // If the coefficients for `v' and `vj' are the same, use
- // the sum constraint, otherwise use the difference constraint.
- bool same_sign = (sgn(coeff) == sgn(coeff_j));
-
- Row_Reference m_j = (same_sign) ? *(m_begin + j + 1) : *(m_begin + j);
- Row_Reference m_cj = (same_sign) ? *(m_begin + cjj) : *(m_begin + cj);
+ Row_Reference m_j = *(m_begin + j);
+ Row_Reference m_cj = *(m_begin + cj);
const N& m_j_i = m_j[i];
const N& m_i_j = m_cj[ci];
if ((!is_plus_infinity(m_i_j) && !is_plus_infinity(m_j_i))
@@ -999,7 +994,26 @@ Octagonal_Shape<T>::frequency(const Linear_Expression& expr,
// So apply this equality to eliminate `v' in `le'.
numer_denom(m_i_j, num, den);
le -= coeff*v;
- le = (same_sign) ? le - coeff*vj : le + coeff*vj;
+ le = le + coeff*vj;
+ le *= den;
+ le = le - num*coeff;
+ val_den *= den;
+ constant_v = true;
+ break;
+ }
+
+ m_j = *(m_begin + j + 1);
+ m_cj = *(m_begin + cjj);
+ const N& m_j_i1 = m_j[i];
+ const N& m_i_j1 = m_cj[ci];
+ if ((!is_plus_infinity(m_i_j1) && !is_plus_infinity(m_j_i1))
+ && (is_additive_inverse(m_i_j1, m_j_i1))) {
+ // The coefficient for `vj' in `le' is not 0
+ // and the constraint with `v' is an equality.
+ // So apply this equality to eliminate `v' in `le'.
+ numer_denom(m_i_j1, num, den);
+ le -= coeff*v;
+ le = le - coeff*vj;
le *= den;
le = le - num*coeff;
val_den *= den;
diff --git a/tests/Octagonal_Shape/frequency1.cc b/tests/Octagonal_Shape/frequency1.cc
index 293cc8b..02a8754 100644
--- a/tests/Octagonal_Shape/frequency1.cc
+++ b/tests/Octagonal_Shape/frequency1.cc
@@ -243,6 +243,54 @@ test10() {
return ok;
}
+bool
+test11() {
+ Variable A(0);
+ Variable B(1);
+ Variable C(2);
+
+ TOctagonal_Shape os(3);
+ os.add_constraint(2*A + 2*B == 1);
+ os.add_constraint(B - C == 1);
+ os.add_constraint(B <= 2);
+
+ Coefficient num;
+ Coefficient den;
+ Coefficient valn;
+ Coefficient vald;
+ bool ok = (os.frequency(Linear_Expression(A - B + 2*C + 1),
+ num, den, valn, vald)
+ && num == 0 && den == 1 && valn == -1 && vald == 2);
+ print_constraints(os, "*** os ***");
+ nout << "valn " << valn << ", vald " << vald << endl;
+
+ return ok;
+}
+
+bool
+test12() {
+ Variable A(0);
+ Variable B(1);
+ Variable C(2);
+
+ TOctagonal_Shape os(3);
+ os.add_constraint(2*A - 2*B == 1);
+ os.add_constraint(B + C == 1);
+ os.add_constraint(B <= 2);
+
+ Coefficient num;
+ Coefficient den;
+ Coefficient valn;
+ Coefficient vald;
+ bool ok = (os.frequency(Linear_Expression(A + B + 2*C + 1),
+ num, den, valn, vald)
+ && num == 0 && den == 1 && valn == 7 && vald == 2);
+ print_constraints(os, "*** os ***");
+ nout << "valn " << valn << ", vald " << vald << endl;
+
+ return ok;
+}
+
} // namespace
BEGIN_MAIN
@@ -256,4 +304,6 @@ BEGIN_MAIN
DO_TEST(test08);
DO_TEST(test09);
DO_TEST(test10);
+ DO_TEST(test11);
+ DO_TEST(test12);
END_MAIN
More information about the PPL-devel
mailing list