stats: fix rounding issues

Fixes #582.

* spot/twaalgos/stats.cc: Add 0.5 to the result of bdd_satcountset()
before truncating it.
* NEWS: Mention the bug.
This commit is contained in:
Alexandre Duret-Lutz 2024-05-16 12:17:17 +02:00
parent 2bd2abd4c9
commit 913e807d66
2 changed files with 15 additions and 3 deletions

3
NEWS
View file

@ -325,6 +325,9 @@ New in spot 2.11.6.dev (not yet released)
- The configure script failed to detect the include path for Python 3.12.
(Issue #577.)
- Work around many failures caused by incorrect rounding of floating
point values in the counting of transitions. (Issue #582)
- Some incorrectly escaped strings in Python code were causing
warnings with Python 3.12.

View file

@ -35,7 +35,10 @@ namespace spot
unsigned long long tr = 0;
bdd v = g->ap_vars();
for (auto& e: g->edges())
tr += bdd_satcountset(e.cond, v);
// We add 0.5 to work around rounding errors in the computation
// of bdd_satcountset(), as the conversion is done by
// truncation. See issue #582.
tr += 0.5 + bdd_satcountset(e.cond, v);
return tr;
}
@ -79,7 +82,10 @@ namespace spot
const twa_succ_iterator* it) override
{
++s_.edges;
s_.transitions += bdd_satcountset(it->cond(), apvars_);
// We add 0.5 to work around rounding errors in the
// computation of bdd_satcountset(), as the conversion is done
// by truncation. See issue #582.
s_.transitions += 0.5 + bdd_satcountset(it->cond(), apvars_);
}
private:
@ -182,7 +188,10 @@ namespace spot
[&s, &ge](bdd cond)
{
++s.edges;
s.transitions += bdd_satcountset(cond, ge->ap_vars());
// We add 0.5 to work around rounding errors in the
// computation of bdd_satcountset(), as the conversion
// is done by truncation. See issue #582.
s.transitions += 0.5 + bdd_satcountset(cond, ge->ap_vars());
});
}
return s;