3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-08-01 08:53:18 +00:00

ensure smaller layers are visited first

This commit is contained in:
Jakob Rath 2024-04-03 18:25:18 +02:00
parent 18eeb48b34
commit 2b89767d1f
2 changed files with 44 additions and 20 deletions

View file

@ -96,7 +96,7 @@ namespace polysat {
while (true) { while (true) {
for (auto const& [w, offset] : m_suffixes) { for (auto const& [w, offset] : m_suffixes) {
for (auto& layer : m_units[w].get_layers()) { for (auto& layer : m_units[w].get_layers()) {
entry* e = find_overlap(w, layer, value); entry* e = find_overlap(layer, value);
if (!e) if (!e)
continue; continue;
m_explain.push_back({ e, value }); m_explain.push_back({ e, value });
@ -171,17 +171,42 @@ namespace polysat {
viable::entry* viable::find_overlap(rational& val) { viable::entry* viable::find_overlap(rational& val) {
entry* last = nullptr; entry* last = nullptr;
// TODO: this doesn't always make sure we prefer smaller sizes... different suffixes would have to be interleaved.
next: #if 0
{
verbose_stream() << "\n\n\n\n\nfind_overlap v" << m_var << ", starting val = " << val << "\n";
for (auto const& [w, offset] : m_suffixes) { for (auto const& [w, offset] : m_suffixes) {
for (auto& layer : m_units[w].get_layers()) { for (auto& layer : m_units[w].get_layers()) {
entry* e = find_overlap(w, layer, val); verbose_stream() << " layer width = " << layer.bit_width << "\n";
entry const* e = layer.entries;
if (!e)
continue;
entry const* first = e;
do {
display_one(verbose_stream() << " ", e) << "\n";
e = e->next();
}
while (e != first);
}
}
}
#endif
ptr_vector<layer const> layers;
for (auto const& [w, offset] : m_suffixes)
for (auto const& layer : m_units[w].get_layers())
layers.push_back(&layer);
std::sort(layers.begin(), layers.end(), [](layer const* l1, layer const* l2) { return l1->bit_width < l2->bit_width; });
next:
for (layer const* layer : layers) {
entry* e = find_overlap(*layer, val);
if (!e) if (!e)
continue; continue;
last = e; last = e;
if (e->interval.is_proper()) if (e->interval.is_proper())
update_value_to_high(val, e); update_value_to_high(val, e);
// display_explain(verbose_stream() << "found: ", {e,val}) << "\n"; display_explain(verbose_stream() << "found: ", {e,val}) << "\n";
m_explain.push_back({ e, val }); m_explain.push_back({ e, val });
if (is_conflict()) { if (is_conflict()) {
verbose_stream() << "find_overlap conflict\n"; verbose_stream() << "find_overlap conflict\n";
@ -190,11 +215,10 @@ next:
} }
goto next; goto next;
} }
}
return last; return last;
} }
viable::entry* viable::find_overlap(pvar /* w */, layer& l, rational const& val) { viable::entry* viable::find_overlap(layer const& l, rational const& val) {
if (!l.entries) if (!l.entries)
return nullptr; return nullptr;
unsigned v_width = m_num_bits; unsigned v_width = m_num_bits;

View file

@ -120,7 +120,7 @@ namespace polysat {
// find the first non-fixed entry that overlaps with val, if any. // find the first non-fixed entry that overlaps with val, if any.
entry* find_overlap(rational& val); entry* find_overlap(rational& val);
entry* find_overlap(pvar w, layer& l, rational const& val); entry* find_overlap(layer const& l, rational const& val);
void remove_redundant_explanations(); void remove_redundant_explanations();