Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extrapolation fix #27

Merged
merged 2 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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