mirror of
https://github.com/Z3Prover/z3
synced 2025-07-01 10:28:46 +00:00
Add search_iterator
This commit is contained in:
parent
8a1a202133
commit
b644fe0f3d
2 changed files with 59 additions and 2 deletions
|
@ -74,4 +74,60 @@ namespace polysat {
|
||||||
|
|
||||||
inline std::ostream& operator<<(std::ostream& out, search_state const& s) { return s.display(out); }
|
inline std::ostream& operator<<(std::ostream& out, search_state const& s) { return s.display(out); }
|
||||||
|
|
||||||
|
|
||||||
|
// Go backwards over the search_state
|
||||||
|
class search_iterator {
|
||||||
|
|
||||||
|
search_state* m_search;
|
||||||
|
|
||||||
|
unsigned current;
|
||||||
|
unsigned first;
|
||||||
|
|
||||||
|
struct idx_range {
|
||||||
|
unsigned current;
|
||||||
|
unsigned first; // highest index + 1
|
||||||
|
};
|
||||||
|
vector<idx_range> m_index_stack;
|
||||||
|
|
||||||
|
public:
|
||||||
|
search_iterator(search_state& search):
|
||||||
|
m_search(&search) {
|
||||||
|
first = m_search->size();
|
||||||
|
current = first; // we start one before the beginning, then it also works for empty m_search
|
||||||
|
}
|
||||||
|
|
||||||
|
search_item const& operator*() const {
|
||||||
|
return (*m_search)[current];
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned last() {
|
||||||
|
return m_index_stack.empty() ? 0 : m_index_stack.back().first;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool next() {
|
||||||
|
if (current > last()) {
|
||||||
|
--current;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
SASSERT(current == last());
|
||||||
|
if (m_index_stack.empty())
|
||||||
|
return false;
|
||||||
|
current = m_index_stack.back().current;
|
||||||
|
first = m_index_stack.back().first;
|
||||||
|
m_index_stack.pop_back();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// to be called after all saturations for a step are done
|
||||||
|
void push_block() {
|
||||||
|
if (first != m_search->size()) {
|
||||||
|
m_index_stack.push_back({current, first});
|
||||||
|
first = m_search->size();
|
||||||
|
current = first - 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -472,9 +472,10 @@ namespace polysat {
|
||||||
set_marks(m_conflict);
|
set_marks(m_conflict);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (unsigned i = m_search.size(); i-- > 0; ) {
|
search_iterator search_it(m_search);
|
||||||
|
while (search_it.next()) {
|
||||||
LOG("Conflict: " << m_conflict);
|
LOG("Conflict: " << m_conflict);
|
||||||
auto const& item = m_search[i];
|
auto const& item = *search_it;
|
||||||
if (item.is_assignment()) {
|
if (item.is_assignment()) {
|
||||||
// Resolve over variable assignment
|
// Resolve over variable assignment
|
||||||
pvar v = item.var();
|
pvar v = item.var();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue