mirror of
https://github.com/Z3Prover/z3
synced 2025-04-27 19:05:51 +00:00
Updated user-propagator example (#5879)
This commit is contained in:
parent
a08be497f7
commit
35fb95648b
9 changed files with 893 additions and 242 deletions
|
@ -0,0 +1,30 @@
|
|||
#pragma once
|
||||
|
||||
#include "user_propagator_with_theory.h"
|
||||
|
||||
class user_propagator_internal_maximisation : public user_propagator_with_theory {
|
||||
|
||||
z3::expr manhattanSum;
|
||||
|
||||
public:
|
||||
|
||||
int best = -1;
|
||||
|
||||
user_propagator_internal_maximisation(z3::solver *s, std::unordered_map<z3::expr, unsigned> &idMapping, unsigned board, z3::expr_vector queens)
|
||||
: user_propagator_with_theory(s, idMapping, board),
|
||||
manhattanSum(s->ctx().bv_val(0, queens[0].get_sort().bv_size())) {
|
||||
for (int i = 1; i < queens.size(); i++) {
|
||||
manhattanSum = manhattanSum + z3::ite(z3::uge(queens[i], queens[i - 1]), queens[i] - queens[i - 1], queens[i - 1] - queens[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void final() override {
|
||||
|
||||
int current = 0;
|
||||
for (unsigned i = 1; i < board; i++) {
|
||||
current += abs((signed) currentModel[i] - (signed) currentModel[i - 1]);
|
||||
}
|
||||
best = std::max(current, best);
|
||||
this->propagate(z3::expr_vector(ctx()), z3::ugt(manhattanSum, best));
|
||||
}
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue