Skip to content

Commit

Permalink
Merge pull request #27 from DEIS-Tools/extrapolation_fix
Browse files Browse the repository at this point in the history
Extrapolation fix
  • Loading branch information
ThomasMG authored Sep 12, 2023
2 parents e300241 + 6475654 commit 60e093f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/pardibaal/DBM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,13 +363,13 @@ namespace pardibaal {
for (dim_t i = 0; i < D.dimension(); ++i) {
for (dim_t j = 0; j < D.dimension(); ++j) {
if (i == j) continue;
if ((D.at(i, j) > bound_t::non_strict(ceiling[i])) ||
(D.at(0, i) < bound_t::non_strict(-ceiling[i])) ||
(D.at(0, j) < bound_t::non_strict(-ceiling[j]) && i != 0)){
if ((D.at(i, j).get_bound() > ceiling[i]) ||
(-D.at(0, i).get_bound() > ceiling[i]) ||
(-D.at(0, j).get_bound() > ceiling[j] && i != 0)){

this->set(i, j, bound_t::inf());
}
else if (D.at(i, j) < bound_t::non_strict(-ceiling[j]) && i == 0)
else if (-D.at(i, j).get_bound() > ceiling[j] && i == 0)
this->set(i, j, bound_t::strict(-ceiling[j]));

// Make sure we don't set 0, j to positive bound or i, 0 to a negative one
Expand Down Expand Up @@ -400,9 +400,9 @@ namespace pardibaal {
for (dim_t i = 0; i < D.dimension(); ++i) {
for (dim_t j = 0; j < D.dimension(); ++j) {
if (i == j) continue;
else if (D.at(i, j) > bound_t::non_strict(lower[i]))
else if (D.at(i, j).get_bound() > lower[i])
this->set(i, j, bound_t::inf());
else if (D.at(i, j) < bound_t::non_strict(-upper[j]))
else if (-D.at(i, j).get_bound() > upper[j])
this->set(i, j, bound_t::strict(-upper[j]));

// Make sure we don't set 0, j to positive bound or i, 0 to a negative one
Expand Down Expand Up @@ -430,11 +430,11 @@ namespace pardibaal {
for (dim_t i = 0; i < D.dimension(); ++i) {
for (dim_t j = 0; j < D.dimension(); ++j) {
if (i == j) continue;
else if (D.at(i, j) > bound_t::non_strict(lower[i]) ||
D.at(0, i) < bound_t::non_strict(-lower[i]) ||
(D.at(0, j) < bound_t::non_strict(-upper[j]) && i != 0))
else if ((D.at(i, j).get_bound() > lower[i]) ||
(-D.at(0, i).get_bound() > -lower[i]) ||
(-D.at(0, j).get_bound() > -upper[j] && i != 0))
this->set(i, j, bound_t::inf());
else if (D.at(0, j) < bound_t::non_strict(-upper[j]) && i == 0)
else if (-D.at(0, j).get_bound() > upper[j] && i == 0)
this->set(i, j, bound_t::strict(-upper[j]));

// Make sure we don't set 0, j to positive bound or i, 0 to a negative one
Expand Down
21 changes: 21 additions & 0 deletions test/DBM_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,27 @@ BOOST_AUTO_TEST_CASE(extrapolate_diagonal_test_5) {
BOOST_CHECK_THROW(D.extrapolate_diagonal(ceiling), base_error);
}

BOOST_AUTO_TEST_CASE(extrapolate_diagonal_test_6) {
DBM dbm = DBM::unconstrained(4);
std::vector ceiling{0, 2, 2, 6};

dbm.set(0, 1, {-2, STRICT});
dbm.set(2, 1, {-2, STRICT});
dbm.set(3, 2, {2, NON_STRICT});
dbm.set(0, 2, bound_t::zero());
dbm.set(0, 3, bound_t::zero());
dbm.set(2, 3, bound_t::zero());
dbm.set(3, 1, {0, STRICT});

BOOST_CHECK(!dbm.is_empty());

auto cpy = dbm;

dbm.extrapolate_diagonal(ceiling);

BOOST_CHECK(dbm.is_equal(cpy));
}

BOOST_AUTO_TEST_CASE(extrapolate_lu_test_1) {
/* LU Extrapolation
* Example from Behrmann, Gerd & Bouyer, Patricia & Larsen, Kim & Pelánek, Radek. (2004).
Expand Down

0 comments on commit 60e093f

Please sign in to comment.