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

Fix naming of automatically generated next-state variables #349

Merged
merged 4 commits into from
Sep 10, 2024
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
6 changes: 5 additions & 1 deletion core/ts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ void swap(TransitionSystem & ts1, TransitionSystem & ts2)
std::swap(ts1.no_state_updates_, ts2.no_state_updates_);
std::swap(ts1.next_map_, ts2.next_map_);
std::swap(ts1.curr_map_, ts2.curr_map_);
std::swap(ts1.next_suffix_, ts2.next_suffix_);
std::swap(ts1.functional_, ts2.functional_);
std::swap(ts1.deterministic_, ts2.deterministic_);
std::swap(ts1.constraints_, ts2.constraints_);
Expand Down Expand Up @@ -128,6 +129,8 @@ TransitionSystem::TransitionSystem(const TransitionSystem & other_ts,
for (const auto & e : other_ts.constraints_) {
constraints_.push_back({ transfer_as(e.first, BOOL), e.second });
}

next_suffix_ = other_ts.next_suffix_;
functional_ = other_ts.functional_;
deterministic_ = other_ts.deterministic_;
}
Expand All @@ -146,6 +149,7 @@ bool TransitionSystem::operator==(const TransitionSystem & other) const
no_state_updates_ == other.no_state_updates_ &&
next_map_ == other.next_map_ &&
curr_map_ == other.curr_map_ &&
next_suffix_ == other.next_suffix_ &&
functional_ == other.functional_ &&
deterministic_ == other.deterministic_ &&
constraints_ == other.constraints_);
Expand Down Expand Up @@ -292,7 +296,7 @@ Term TransitionSystem::make_statevar(const string name, const Sort & sort)
deterministic_ = false;

Term state = solver_->make_symbol(name, sort);
Term next_state = solver_->make_symbol(name + ".next", sort);
Term next_state = solver_->make_symbol(name + next_suffix_, sort);
add_statevar(state, next_state);
return state;
}
Expand Down
17 changes: 9 additions & 8 deletions core/ts.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,17 @@ class TransitionSystem
* it supports the most theories and doesn't rewrite-on-the-fly or alias
* sorts
* this makes it a great candidate for representing the TransitionSystem */
TransitionSystem()
: solver_(smt::Cvc5SolverFactory::create(false)),
init_(solver_->make_term(true)),
trans_(solver_->make_term(true)),
functional_(false),
deterministic_(false)
TransitionSystem() : TransitionSystem(smt::Cvc5SolverFactory::create(false))
{
}

TransitionSystem(const smt::SmtSolver & s)
TransitionSystem(
const smt::SmtSolver & s,
const std::string & next_state_suffix = ".pono_generated__next")
: solver_(s),
init_(s->make_term(true)),
trans_(s->make_term(true)),
next_suffix_(next_state_suffix),
functional_(false),
deterministic_(false)
{
Expand All @@ -69,7 +67,7 @@ class TransitionSystem
*/
TransitionSystem(const TransitionSystem & other_ts, smt::TermTranslator & tt);

virtual ~TransitionSystem(){};
virtual ~TransitionSystem() {};

/** Equality comparison between TransitionSystems
* compares each member variable
Expand Down Expand Up @@ -524,6 +522,9 @@ class TransitionSystem
// maps next back to curr
smt::UnorderedTermMap curr_map_;

// Text appended to generate names for next-state variables.
std::string next_suffix_;

// whether the TransitionSystem is functional
bool functional_;
// whether the TransitionSystem is fully deterministic
Expand Down
4 changes: 2 additions & 2 deletions tests/test_ts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ TEST_P(TSUnitTests, FTS_IsFunc)
EXPECT_FALSE(fts.is_deterministic());
EXPECT_EQ(fts.statevars_with_no_update().size(), 0);

Term z = fts.make_statevar("z", bvsort);
EXPECT_EQ(fts.statevars_with_no_update(), UnorderedTermSet({z}));
Term ynext = fts.make_statevar("y.next", bvsort);
EXPECT_EQ(fts.statevars_with_no_update(), UnorderedTermSet({ynext}));

TransitionSystem ts_copy = fts;
EXPECT_EQ(fts.is_functional(), ts_copy.is_functional());
Expand Down
Loading