3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-08-07 19:51:22 +00:00

Centralize and document TRACE tags using X-macros (#7657)

* Introduce X-macro-based trace tag definition
- Created trace_tags.def to centralize TRACE tag definitions
- Each tag includes a symbolic name and description
- Set up enum class TraceTag for type-safe usage in TRACE macros

* Add script to generate Markdown documentation from trace_tags.def
- Python script parses trace_tags.def and outputs trace_tags.md

* Refactor TRACE_NEW to prepend TraceTag and pass enum to is_trace_enabled

* trace: improve trace tag handling system with hierarchical tagging

- Introduce hierarchical tag-class structure: enabling a tag class activates all child tags
- Unify TRACE, STRACE, SCTRACE, and CTRACE under enum TraceTag
- Implement initial version of trace_tag.def using X(tag, tag_class, description)
  (class names and descriptions to be refined in a future update)

* trace: replace all string-based TRACE tags with enum TraceTag
- Migrated all TRACE, STRACE, SCTRACE, and CTRACE macros to use enum TraceTag values instead of raw string literals

* trace : add cstring header

* trace : Add Markdown documentation generation from trace_tags.def via mk_api_doc.py

* trace : rename macro parameter 'class' to 'tag_class' and remove Unicode comment in trace_tags.h.

* trace : Add TODO comment for future implementation of tag_class activation

* trace : Disable code related to tag_class until implementation is ready (#7663).
This commit is contained in:
LeeYoungJoon 2025-05-28 22:31:25 +09:00 committed by GitHub
parent d766292dab
commit 0a93ff515d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
583 changed files with 8698 additions and 7299 deletions

View file

@ -193,7 +193,7 @@ public:
}
void add_soft(expr* e, rational const& w) {
TRACE("opt", tout << mk_pp(e, m) << " |-> " << w << "\n";);
TRACE(opt, tout << mk_pp(e, m) << " |-> " << w << "\n";);
expr_ref asum(m), fml(m);
app_ref cls(m);
rational weight(0);
@ -219,7 +219,7 @@ public:
m_asm2weight.insert(e, w);
m_asms.push_back(e);
m_trail.push_back(e);
TRACE("opt", tout << "insert: " << mk_pp(e, m) << " : " << w << "\n";
TRACE(opt, tout << "insert: " << mk_pp(e, m) << " : " << w << "\n";
tout << m_asms << " " << "\n"; );
}
@ -235,7 +235,7 @@ public:
improve_model();
if (is_sat != l_true) return is_sat;
while (m_lower < m_upper) {
TRACE("opt_verbose",
TRACE(opt_verbose,
s().display(tout << m_asms << "\n") << "\n";
display(tout););
is_sat = check_sat_hill_climb(m_asms);
@ -244,7 +244,7 @@ public:
}
switch (is_sat) {
case l_true:
CTRACE("opt", m_model->is_false(m_asms),
CTRACE(opt, m_model->is_false(m_asms),
tout << *m_model << "assumptions: ";
for (expr* a : m_asms) tout << mk_pp(a, m) << " -> " << (*m_model)(a) << " ";
tout << "\n";);
@ -344,7 +344,7 @@ public:
if (r == l_true) {
model_ref mdl;
s().get_model(mdl);
TRACE("opt", tout << *mdl;);
TRACE(opt, tout << *mdl;);
if (mdl.get()) {
update_assignment(mdl);
}
@ -407,7 +407,7 @@ public:
}
if (core.empty()) {
IF_VERBOSE(100, verbose_stream() << "(opt.maxres core is empty)\n";);
TRACE("opt", tout << "empty core\n";);
TRACE(opt, tout << "empty core\n";);
cores.reset();
m_lower = m_upper;
return l_true;
@ -429,7 +429,7 @@ public:
is_sat = check_sat_hill_climb(m_asms);
}
TRACE("opt",
TRACE(opt,
tout << "sat: " << is_sat << " num cores: " << cores.size() << "\n";
for (auto const& c : cores) display_vec(tout, c.m_core);
tout << "num assumptions: " << m_asms.size() << "\n";);
@ -452,7 +452,7 @@ public:
cs.push_back(a);
}
}
TRACE("opt", display_vec(tout << "new correction set: ", cs););
TRACE(opt, display_vec(tout << "new correction set: ", cs););
}
struct compare_asm {
@ -490,7 +490,7 @@ public:
void process_sat(exprs const& corr_set) {
++m_stats.m_num_cs;
expr_ref fml(m), tmp(m);
TRACE("opt", display_vec(tout << "corr_set: ", corr_set););
TRACE(opt, display_vec(tout << "corr_set: ", corr_set););
remove_soft(corr_set, m_asms);
rational w = split_core(corr_set);
cs_max_resolve(corr_set, w);
@ -558,7 +558,7 @@ public:
IF_VERBOSE(3, verbose_stream() << "(maxres cs model valid: " << (m_csmodel.get() != nullptr) << " cs size:" << m_correction_set_size << " core: " << core.size() << ")\n";);
expr_ref fml(m);
SASSERT(!core.empty());
TRACE("opt", display_vec(tout << "minimized core: ", core););
TRACE(opt, display_vec(tout << "minimized core: ", core););
IF_VERBOSE(10, display_vec(verbose_stream() << "core: ", core););
switch (m_st) {
case strategy_t::s_primal_binary:
@ -594,7 +594,7 @@ public:
exprs cs;
get_current_correction_set(m_csmodel.get(), cs);
m_correction_set_size = cs.size();
TRACE("opt", tout << "cs " << m_correction_set_size << " " << core.size() << "\n";);
TRACE(opt, tout << "cs " << m_correction_set_size << " " << core.size() << "\n";);
if (m_correction_set_size >= core.size())
return;
rational w(0);
@ -895,7 +895,7 @@ public:
// cs is a correction set (a complement of a (maximal) satisfying assignment).
void cs_max_resolve(exprs const& cs, rational const& w) {
if (cs.empty()) return;
TRACE("opt", display_vec(tout << "correction set: ", cs););
TRACE(opt, display_vec(tout << "correction set: ", cs););
expr_ref fml(m), asum(m);
app_ref cls(m), d(m), dd(m);
m_B.reset();
@ -991,12 +991,12 @@ public:
m_correction_set_size = correction_set_size;
}
TRACE("opt_verbose", tout << *mdl;);
TRACE(opt_verbose, tout << *mdl;);
rational upper = cost(*mdl);
if (upper > m_upper) {
TRACE("opt", tout << "new upper: " << upper << " vs existing upper: " << m_upper << "\n";);
TRACE(opt, tout << "new upper: " << upper << " vs existing upper: " << m_upper << "\n";);
return;
}
@ -1007,7 +1007,7 @@ public:
m_model = mdl;
m_c.model_updated(mdl.get());
TRACE("opt", tout << "updated upper: " << upper << "\n";);
TRACE(opt, tout << "updated upper: " << upper << "\n";);
for (soft& s : m_soft)
s.set_value(m_model->is_true(s.s));
@ -1033,18 +1033,18 @@ public:
weights.push_back(s.weight);
}
fml = u.mk_lt(nsoft.size(), weights.data(), nsoft.data(), m_upper);
TRACE("opt", tout << "block upper bound " << fml << "\n";);;
TRACE(opt, tout << "block upper bound " << fml << "\n";);;
add(fml);
}
void remove_soft(exprs const& core, expr_ref_vector& asms) {
TRACE("opt", tout << "before remove: " << asms << "\n";);
TRACE(opt, tout << "before remove: " << asms << "\n";);
unsigned j = 0;
for (expr* a : asms)
if (!core.contains(a))
asms[j++] = a;
asms.shrink(j);
TRACE("opt", tout << "after remove: " << asms << "\n";);
TRACE(opt, tout << "after remove: " << asms << "\n";);
}
void updt_params(params_ref& _p) override {
@ -1088,7 +1088,7 @@ public:
if (m_found_feasible_optimum) {
add(m_defs);
add(m_asms);
TRACE("opt", tout << "Committing feasible solution\ndefs:" << m_defs << "\nasms:" << m_asms << "\n");
TRACE(opt, tout << "Committing feasible solution\ndefs:" << m_defs << "\nasms:" << m_asms << "\n");
}
// else: there is only a single assignment to these soft constraints.
}
@ -1101,7 +1101,7 @@ public:
_solver->assert_expr(core);
lbool is_sat = _solver->check_sat(0, nullptr);
IF_VERBOSE(0, verbose_stream() << "core status (l_false:) " << is_sat << " core size " << core.size() << "\n");
CTRACE("opt", is_sat != l_false,
CTRACE(opt, is_sat != l_false,
for (expr* c : core) tout << "core: " << mk_pp(c, m) << "\n";
_solver->display(tout);
tout << "other solver\n";

View file

@ -133,7 +133,7 @@ namespace opt {
model_ref mdl;
s().get_model(mdl);
if (mdl) {
TRACE("opt", tout << *mdl << "\n";);
TRACE(opt, tout << *mdl << "\n";);
for (auto & soft : m_soft) {
if (!mdl->is_true(soft.s)) {
update_bounds();

View file

@ -78,7 +78,7 @@ namespace opt {
}
pb_util pb(m);
tmp = pb.mk_ge(weights.size(), weights.data(), fmls.data(), k);
TRACE("opt", tout << "cost: " << cost << "\n" << tmp << "\n";);
TRACE(opt, tout << "cost: " << cost << "\n" << tmp << "\n";);
s().assert_expr(tmp);
}
@ -100,7 +100,7 @@ namespace opt {
m_c.add_offset(m_index, lower);
m_upper -= lower;
TRACE("opt",
TRACE(opt,
tout << "lower " << lower << " upper: " << m_upper << " assignments: ";
for (soft& s : m_soft) tout << (s.is_true()?"T":"F");
tout << "\n";);
@ -184,7 +184,7 @@ namespace opt {
opt_params optp(m_params);
symbol const& maxsat_engine = m_c.maxsat_engine();
IF_VERBOSE(1, verbose_stream() << "(maxsmt)\n";);
TRACE("opt_verbose", s().display(tout << "maxsmt\n") << "\n";);
TRACE(opt_verbose, s().display(tout << "maxsmt\n") << "\n";);
if (!committed && optp.maxlex_enable() && is_maxlex(m_soft))
m_msolver = mk_maxlex(m_c, m_index, m_soft);
else if (m_soft.empty() || maxsat_engine == symbol("maxres") || maxsat_engine == symbol::null)
@ -293,7 +293,7 @@ namespace opt {
}
void maxsmt::add(expr* f, rational const& w) {
TRACE("opt", tout << mk_pp(f, m) << " weight: " << w << "\n";);
TRACE(opt, tout << mk_pp(f, m) << " weight: " << w << "\n";);
SASSERT(m.is_bool(f));
SASSERT(w.is_pos());
unsigned index = 0;

View file

@ -323,7 +323,7 @@ namespace opt {
lbool is_sat = s.check_sat(asms.size(), asms.data());
TRACE("opt", s.display(tout << "initial search result: " << is_sat << "\n"););
TRACE(opt, s.display(tout << "initial search result: " << is_sat << "\n"););
if (is_sat != l_false) {
s.get_model(m_model);
s.get_labels(m_labels);
@ -333,7 +333,7 @@ namespace opt {
}
}
if (is_sat != l_true) {
TRACE("opt", tout << m_hard_constraints << " " << asms << "\n";);
TRACE(opt, tout << m_hard_constraints << " " << asms << "\n";);
if (!asms.empty()) {
s.get_unsat_core(m_core);
}
@ -341,7 +341,7 @@ namespace opt {
}
s.assert_expr(asms);
IF_VERBOSE(1, verbose_stream() << "(optimize:sat)\n");
TRACE("opt", model_smt2_pp(tout, m, *m_model, 0););
TRACE(opt, model_smt2_pp(tout, m, *m_model, 0););
m_optsmt.setup(*m_opt_solver.get());
update_lower();
@ -389,7 +389,7 @@ namespace opt {
void context::fix_model(model_ref& mdl) {
if (mdl && !m_model_fixed.contains(mdl.get())) {
TRACE("opt", m_fm->display(tout << "fix-model\n");
TRACE(opt, m_fm->display(tout << "fix-model\n");
tout << *mdl << "\n";
if (m_model_converter) m_model_converter->display(tout););
(*m_fm)(mdl);
@ -433,10 +433,10 @@ namespace opt {
void context::get_model_core(model_ref& mdl) {
mdl = m_model;
CTRACE("opt", mdl, tout << *mdl;);
CTRACE(opt, mdl, tout << *mdl;);
fix_model(mdl);
if (mdl) mdl->set_model_completion(true);
CTRACE("opt", mdl, tout << *mdl;);
CTRACE(opt, mdl, tout << *mdl;);
}
void context::get_box_model(model_ref& mdl, unsigned index) {
@ -530,7 +530,7 @@ namespace opt {
lbool context::execute_box() {
if (m_box_index < m_box_models.size()) {
m_model = m_box_models[m_box_index];
CTRACE("opt", m_model, tout << *m_model << "\n";);
CTRACE(opt, m_model, tout << *m_model << "\n";);
++m_box_index;
return l_true;
}
@ -562,7 +562,7 @@ namespace opt {
}
if (r == l_true && !m_box_models.empty()) {
m_model = m_box_models[0];
CTRACE("opt", m_model, tout << *m_model << "\n";);
CTRACE(opt, m_model, tout << *m_model << "\n";);
}
return r;
}
@ -615,7 +615,7 @@ namespace opt {
k += obj.m_weights[i];
}
else {
TRACE("opt", tout << (*mdl)(obj.m_terms[i]) << "\n";);
TRACE(opt, tout << (*mdl)(obj.m_terms[i]) << "\n";);
}
}
if (is_ge) {
@ -627,7 +627,7 @@ namespace opt {
break;
}
}
TRACE("opt",
TRACE(opt,
tout << (is_ge?">= ":"<= ") << k << "\n";
display_objective(tout, obj);
tout << "\n";
@ -651,7 +651,7 @@ namespace opt {
m_pareto->get_model(m_model, m_labels);
update_bound(true);
update_bound(false);
TRACE("opt", model_smt2_pp(tout, m, *m_model.get(), 0););
TRACE(opt, model_smt2_pp(tout, m, *m_model.get(), 0););
}
lbool context::execute_pareto() {
@ -910,12 +910,12 @@ namespace opt {
set_simplify(tac0.get());
}
goal_ref_buffer result;
TRACE("opt", g->display(tout););
TRACE(opt, g->display(tout););
(*m_simplify)(g, result);
SASSERT(result.size() == 1);
goal* r = result[0];
m_model_converter = r->mc();
CTRACE("opt", r->mc(), r->mc()->display(tout););
CTRACE(opt, r->mc(), r->mc()->display(tout););
fmls.reset();
expr_ref tmp(m);
for (unsigned i = 0; i < r->size(); ++i) {
@ -1010,7 +1010,7 @@ namespace opt {
bool is_max = is_maximize(fml, term, orig_term, index);
bool is_min = !is_max && is_minimize(fml, term, orig_term, index);
if (is_min && get_pb_sum(term, terms, weights, offset)) {
TRACE("opt", tout << "try to convert minimization\n" << mk_pp(term, m) << "\n";);
TRACE(opt, tout << "try to convert minimization\n" << mk_pp(term, m) << "\n";);
// minimize 2*x + 3*y
// <=>
// (assert-soft (not x) 2)
@ -1025,7 +1025,7 @@ namespace opt {
terms[i] = mk_not(m, terms[i].get());
}
}
TRACE("opt",
TRACE(opt,
tout << "Convert minimization " << orig_term << "\n";
tout << "to maxsat: " << term << "\n";
for (unsigned i = 0; i < weights.size(); ++i) {
@ -1039,7 +1039,7 @@ namespace opt {
return true;
}
if (is_max && get_pb_sum(term, terms, weights, offset)) {
TRACE("opt", tout << "try to convert maximization " << mk_pp(term, m) << "\n";);
TRACE(opt, tout << "try to convert maximization " << mk_pp(term, m) << "\n";);
// maximize 2*x + 3*y - z
// <=>
// (assert-soft x 2)
@ -1117,7 +1117,7 @@ namespace opt {
}
void context::from_fmls(expr_ref_vector const& fmls) {
TRACE("opt", tout << fmls << "\n";);
TRACE(opt, tout << fmls << "\n";);
m_hard_constraints.reset();
for (expr * fml : fmls) {
app_ref tr(m);
@ -1147,7 +1147,7 @@ namespace opt {
obj.m_weights.append(weights);
obj.m_adjust_value.set_offset(offset);
obj.m_adjust_value.set_negate(neg);
TRACE("opt", tout << "maxsat: " << neg << " " << id << " offset: " << offset << "\n";
TRACE(opt, tout << "maxsat: " << neg << " " << id << " offset: " << offset << "\n";
tout << terms << "\n";);
}
else if (is_maximize(fml, tr, orig_term, index)) {
@ -1206,17 +1206,17 @@ namespace opt {
val = (*mdl)(term);
unsigned bvsz;
if (!m_arith.is_numeral(val, r) && !m_bv.is_numeral(val, r, bvsz)) {
TRACE("opt", tout << "model does not evaluate objective to a value but instead " << val << "\n";
TRACE(opt, tout << "model does not evaluate objective to a value but instead " << val << "\n";
tout << *mdl << "\n";
);
return false;
}
if (r != v) {
TRACE("opt", tout << "Out of bounds: " << term << " " << val << " != " << v << "\n";);
TRACE(opt, tout << "Out of bounds: " << term << " " << val << " != " << v << "\n";);
return false;
}
else {
TRACE("opt", tout << "validated: " << term << " = " << val << "\n";);
TRACE(opt, tout << "validated: " << term << " = " << val << "\n";);
}
return true;
}
@ -1236,7 +1236,7 @@ namespace opt {
term = m_arith.mk_add(args.size(), args.data());
}
else if (m.is_ite(term) || !is_mul_const(term)) {
TRACE("opt", tout << "Purifying " << term << "\n";);
TRACE(opt, tout << "Purifying " << term << "\n";);
term = purify(fm, term);
}
if (fm) {
@ -1309,7 +1309,7 @@ namespace opt {
break;
}
}
TRACE("opt", tout << fmls << "\n";);
TRACE(opt, tout << fmls << "\n";);
}
void context::internalize() {
@ -1346,10 +1346,10 @@ namespace opt {
switch(obj.m_type) {
case O_MINIMIZE: {
val = (*m_model)(obj.m_term);
TRACE("opt", tout << obj.m_term << " " << val << "\n";);
TRACE(opt, tout << obj.m_term << " " << val << "\n";);
if (is_numeral(val, r)) {
inf_eps val = inf_eps(obj.m_adjust_value(r));
TRACE("opt", tout << "adjusted value: " << val << "\n";);
TRACE(opt, tout << "adjusted value: " << val << "\n";);
if (is_lower) {
m_optsmt.update_lower(obj.m_index, val);
}
@ -1361,10 +1361,10 @@ namespace opt {
}
case O_MAXIMIZE: {
val = (*m_model)(obj.m_term);
TRACE("opt", tout << obj.m_term << " " << val << "\n";);
TRACE(opt, tout << obj.m_term << " " << val << "\n";);
if (is_numeral(val, r)) {
inf_eps val = inf_eps(obj.m_adjust_value(r));
TRACE("opt", tout << "adjusted value: " << val << "\n";);
TRACE(opt, tout << "adjusted value: " << val << "\n";);
if (is_lower) {
m_optsmt.update_lower(obj.m_index, val);
}
@ -1377,7 +1377,7 @@ namespace opt {
case O_MAXSMT: {
for (unsigned j = 0; j < obj.m_terms.size(); ++j) {
val = (*m_model)(obj.m_terms[j]);
TRACE("opt", tout << mk_pp(obj.m_terms[j], m) << " " << val << "\n";);
TRACE(opt, tout << mk_pp(obj.m_terms[j], m) << " " << val << "\n";);
if (!m.is_true(val))
r += obj.m_weights[j];
}
@ -1385,11 +1385,11 @@ namespace opt {
maxsmt& ms = *m_maxsmts.find(obj.m_id);
if (is_lower) {
ms.update_upper(r);
TRACE("opt", tout << "update upper from " << r << " to " << ms.get_upper() << "\n";);
TRACE(opt, tout << "update upper from " << r << " to " << ms.get_upper() << "\n";);
}
else {
ms.update_lower(r);
TRACE("opt", tout << "update lower from " << r << " to " << ms.get_lower() << "\n";);
TRACE(opt, tout << "update lower from " << r << " to " << ms.get_lower() << "\n";);
}
break;
}
@ -1737,7 +1737,7 @@ namespace opt {
void context::validate_maxsat(symbol const& id) {
maxsmt& ms = *m_maxsmts.find(id);
TRACE("opt", tout << "Validate: " << id << "\n";);
TRACE(opt, tout << "Validate: " << id << "\n";);
for (objective const& obj : m_objectives) {
if (obj.m_id == id && obj.m_type == O_MAXSMT) {
SASSERT(obj.m_type == O_MAXSMT);
@ -1752,7 +1752,7 @@ namespace opt {
}
value = obj.m_adjust_value(value);
rational value0 = ms.get_lower();
TRACE("opt", tout << "value " << value << " " << value0 << "\n";);
TRACE(opt, tout << "value " << value << " " << value0 << "\n";);
// TBD is this correct? SASSERT(value == value0);
}
}
@ -1778,7 +1778,7 @@ namespace opt {
}
maxsmt& ms = *m_maxsmts.find(obj.m_id);
rational value0 = ms.get_lower();
TRACE("opt", tout << "value " << value << " other " << value0 << "\n";);
TRACE(opt, tout << "value " << value << " other " << value0 << "\n";);
// TBD SASSERT(value0 == value);
break;
}

View file

@ -316,7 +316,7 @@ namespace opt {
add_core(core);
if (core.empty()) {
IF_VERBOSE(100, verbose_stream() << "(opt.maxres :empty-core)\n";);
TRACE("opt", tout << "empty core\n";);
TRACE(opt, tout << "empty core\n";);
break;
}

View file

@ -217,7 +217,7 @@ namespace opt {
case l_undef:
break;
case l_false:
TRACE("opt", tout << "pruned " << mk_bounded_pp(unprocessed(i), m) << "\n";);
TRACE(opt, tout << "pruned " << mk_bounded_pp(unprocessed(i), m) << "\n";);
m_hardened.push_back(m.mk_not(unprocessed(i)));
for (unsigned k = i; k + 1 < m_unprocessed.size(); ++k)
m_unprocessed[k] = unprocessed(k + 1);
@ -231,7 +231,7 @@ namespace opt {
if (j <= i)
++offset;
++m_num_improves;
TRACE("opt", tout << "improved " << mk_bounded_pp(unprocessed(j), m) << "\n";);
TRACE(opt, tout << "improved " << mk_bounded_pp(unprocessed(j), m) << "\n";);
m_hardened.push_back(unprocessed(j));
++num_improved;
}

View file

@ -74,7 +74,7 @@ namespace opt {
fmls.push_back(mk_or(gt));
fml = mk_and(fmls);
IF_VERBOSE(10, verbose_stream() << "dominates: " << fml << "\n";);
TRACE("opt", model_smt2_pp(tout << fml << "\n", m, *m_model, 0););
TRACE(opt, model_smt2_pp(tout << fml << "\n", m, *m_model, 0););
m_solver->assert_expr(fml);
}
@ -87,7 +87,7 @@ namespace opt {
}
fml = m.mk_not(mk_and(le));
IF_VERBOSE(10, verbose_stream() << "not dominated by: " << fml << "\n";);
TRACE("opt", tout << fml << "\n";);
TRACE(opt, tout << fml << "\n";);
m_solver->assert_expr(fml);
}

View file

@ -192,7 +192,7 @@ namespace opt {
};
void preprocess::process_mutex(expr_ref_vector& mutex, obj_map<expr, rational>& new_soft, rational& lower) {
TRACE("opt",
TRACE(opt,
for (expr* e : mutex) {
tout << mk_pp(e, m) << " |-> " << new_soft.find(e) << "\n";
});

View file

@ -173,7 +173,7 @@ namespace opt {
m_pb2bv(m_solver->get_assertion(i), tmp);
g->assert_expr(tmp);
}
TRACE("opt", g->display(tout););
TRACE(opt, g->display(tout););
tactic_ref simplify = mk_nnf_tactic(m);
proof_converter_ref pc;
expr_dependency_ref core(m);
@ -185,7 +185,7 @@ namespace opt {
for (unsigned i = 0; i < r->size(); ++i) {
m_bvsls->assert_expr(r->form(i));
}
TRACE("opt", m_bvsls->display(tout););
TRACE(opt, m_bvsls->display(tout););
}
void pbsls_opt(model_ref& mdl) {
@ -212,7 +212,7 @@ namespace opt {
m_bvsls = alloc(bvsls_opt_engine, m, m_params);
assertions2sls();
expr_ref objective = soft2bv(m_soft, m_weights);
TRACE("opt", tout << objective << "\n";);
TRACE(opt, tout << objective << "\n";);
opt_result res(m);
res.is_sat = l_undef;
try {

View file

@ -160,7 +160,7 @@ namespace opt {
}
lbool opt_solver::check_sat_core2(unsigned num_assumptions, expr * const * assumptions) {
TRACE("opt_verbose", {
TRACE(opt_verbose, {
tout << "context size: " << m_context.size() << "\n";
for (unsigned i = 0; i < m_context.size(); ++i) {
tout << mk_pp(m_context.get_formula(i), m_context.m()) << "\n";
@ -252,12 +252,12 @@ namespace opt {
m_context.get_model(m_last_model);
inf_eps val2;
has_shared = true;
TRACE("opt", tout << (has_shared?"has shared":"non-shared") << " " << val << " " << blocker << "\n";
TRACE(opt, tout << (has_shared?"has shared":"non-shared") << " " << val << " " << blocker << "\n";
if (m_last_model) tout << *m_last_model << "\n";);
if (!m_models[i])
m_models.set(i, m_last_model.get());
TRACE("opt", tout << "maximize " << i << " " << val << " " << m_objective_values[i] << " " << blocker << "\n";);
TRACE(opt, tout << "maximize " << i << " " << val << " " << m_objective_values[i] << " " << blocker << "\n";);
if (val > m_objective_values[i]) {
m_objective_values[i] = val;
}
@ -291,7 +291,7 @@ namespace opt {
// skip model updates
}
else if (m_context.get_context().update_model(has_shared)) {
TRACE("opt", tout << "updated\n";);
TRACE(opt, tout << "updated\n";);
m_last_model = nullptr;
m_context.get_model(m_last_model);
if (!m_last_model)
@ -304,7 +304,7 @@ namespace opt {
else if (!check_bound())
return false;
m_objective_values[i] = val;
TRACE("opt", {
TRACE(opt, {
tout << "objective: " << mk_pp(m_objective_terms.get(i), m) << "\n";
tout << "maximal value: " << val << "\n";
tout << "new condition: " << blocker << "\n";
@ -353,12 +353,12 @@ namespace opt {
for (unsigned i = m_models.size(); i-- > 0; ) {
auto* mdl = m_models[i];
if (mdl) {
TRACE("opt", tout << "get " << i << "\n" << *mdl << "\n";);
TRACE(opt, tout << "get " << i << "\n" << *mdl << "\n";);
m = mdl;
return;
}
}
TRACE("opt", tout << "get last\n";);
TRACE(opt, tout << "get last\n";);
m = m_last_model.get();
}
@ -397,7 +397,7 @@ namespace opt {
smt::theory_var opt_solver::add_objective(app* term) {
smt::theory_var v = get_optimizer().add_objective(term);
TRACE("opt", tout << v << " " << mk_pp(term, m) << "\n";);
TRACE(opt, tout << v << " " << mk_pp(term, m) << "\n";);
m_objective_vars.push_back(v);
m_objective_values.push_back(inf_eps(rational::minus_one(), inf_rational()));
m_objective_terms.push_back(term);
@ -428,7 +428,7 @@ namespace opt {
}
smt::theory_opt& opt = get_optimizer();
smt::theory_var v = m_objective_vars[var];
TRACE("opt", tout << "v" << var << " " << val << "\n";);
TRACE(opt, tout << "v" << var << " " << val << "\n";);
if (typeid(smt::theory_inf_arith) == typeid(opt)) {
smt::theory_inf_arith& th = dynamic_cast<smt::theory_inf_arith&>(opt);

View file

@ -136,7 +136,7 @@ namespace opt {
// only try to improve delta_index.
bound = m_s->mk_ge(delta_index, m_lower[delta_index] + inf_eps(delta_per_step));
}
TRACE("opt", tout << mk_pp(m_objs.get(delta_index), m) << " index: " << delta_index
TRACE(opt, tout << mk_pp(m_objs.get(delta_index), m) << " index: " << delta_index
<< " delta: " << delta_per_step << " bound: " << bound
<< " " << m_lower[delta_index] << " " << m_upper[delta_index] << "\n");
if (bound == last_bound) {
@ -203,7 +203,7 @@ namespace opt {
}
lbool optsmt::geometric_lex(unsigned obj_index, bool is_maximize) {
TRACE("opt", tout << "index: " << obj_index << " is-max: " << is_maximize << "\n";);
TRACE(opt, tout << "index: " << obj_index << " is-max: " << is_maximize << "\n";);
arith_util arith(m);
bool is_int = arith.is_int(m_objs.get(obj_index));
lbool is_sat = l_true;
@ -222,7 +222,7 @@ namespace opt {
SASSERT(delta_per_step.is_int());
SASSERT(delta_per_step.is_pos());
is_sat = m_s->check_sat(0, nullptr);
TRACE("opt", tout << "check " << is_sat << "\n";
TRACE(opt, tout << "check " << is_sat << "\n";
tout << "last bound: " << last_bound << " bound " << bound << "\n";
tout << "lower: " << m_lower[obj_index] << "\n";
tout << "upper: " << m_upper[obj_index] << "\n";
@ -233,7 +233,7 @@ namespace opt {
m_s->get_model(m_model);
SASSERT(m_model);
inf_eps obj = m_s->saved_objective_value(obj_index);
TRACE("opt", tout << "saved objective: " << obj << "\n";);
TRACE(opt, tout << "saved objective: " << obj << "\n";);
update_lower_lex(obj_index, obj, is_maximize);
if (!is_int || !m_lower[obj_index].is_finite()) {
delta_per_step = rational(1);
@ -272,7 +272,7 @@ namespace opt {
}
m_s->pop(num_scopes);
TRACE("opt", tout << is_sat << " " << num_scopes << "\n";);
TRACE(opt, tout << is_sat << " " << num_scopes << "\n";);
if (is_sat == l_false && !m_model) {
return l_false;
@ -328,7 +328,7 @@ namespace opt {
solver::scoped_push _push(*m_s);
while (m.inc()) {
m_s->assert_expr(fml);
TRACE("opt", tout << fml << "\n";);
TRACE(opt, tout << fml << "\n";);
is_sat = m_s->check_sat(1,vars);
if (is_sat == l_true) {
disj.reset();
@ -367,7 +367,7 @@ namespace opt {
}
void optsmt::update_lower_lex(unsigned idx, inf_eps const& v, bool is_maximize) {
TRACE("opt", tout << v << " lower: " << m_lower[idx] << "\n";);
TRACE(opt, tout << v << " lower: " << m_lower[idx] << "\n";);
if (v > m_lower[idx]) {
m_lower[idx] = v;
IF_VERBOSE(1,
@ -379,7 +379,7 @@ namespace opt {
for (unsigned i = idx+1; i < m_vars.size(); ++i) {
m_lower[i] = m_s->saved_objective_value(i);
}
TRACE("opt", tout << "update best model " << *m_model << "\n";);
TRACE(opt, tout << "update best model " << *m_model << "\n";);
m_best_model = m_model;
m_s->get_labels(m_labels);
m_context.set_model(m_model);
@ -387,13 +387,13 @@ namespace opt {
}
void optsmt::update_lower(unsigned idx, inf_eps const& v) {
TRACE("opt", tout << "v" << idx << " >= " << v << "\n";);
TRACE(opt, tout << "v" << idx << " >= " << v << "\n";);
m_lower_fmls[idx] = m_s->mk_ge(idx, v);
m_lower[idx] = v;
}
void optsmt::update_upper(unsigned idx, inf_eps const& v) {
TRACE("opt", tout << "v" << idx << " <= " << v << "\n";);
TRACE(opt, tout << "v" << idx << " <= " << v << "\n";);
m_upper[idx] = v;
}
@ -411,7 +411,7 @@ namespace opt {
if (!m_s->maximize_objectives1(disj))
return expr_ref(m.mk_true(), m);
set_max(m_lower, m_s->get_objective_values(), disj);
TRACE("opt", model_pp(tout << m_lower << "\n", *m_model););
TRACE(opt, model_pp(tout << m_lower << "\n", *m_model););
IF_VERBOSE(2, verbose_stream() << "(optsmt.lower " << m_lower << ")\n";);
return mk_or(disj);
}
@ -506,7 +506,7 @@ namespace opt {
}
lbool optsmt::lex(unsigned obj_index, bool is_maximize) {
TRACE("opt", tout << "optsmt:lex\n";);
TRACE(opt, tout << "optsmt:lex\n";);
m_context.get_base_model(m_best_model);
solver::scoped_push _push(*m_s);
SASSERT(obj_index < m_vars.size());
@ -551,14 +551,14 @@ namespace opt {
void optsmt::get_model(model_ref& mdl, svector<symbol> & labels) {
mdl = m_best_model.get();
TRACE("opt", tout << *mdl << "\n";);
TRACE(opt, tout << *mdl << "\n";);
labels = m_labels;
}
// force lower_bound(i) <= objective_value(i)
void optsmt::commit_assignment(unsigned i) {
inf_eps lo = m_lower[i];
TRACE("opt", tout << "set lower bound of " << mk_pp(m_objs.get(i), m) << " to: " << lo << "\n";
TRACE(opt, tout << "set lower bound of " << mk_pp(m_objs.get(i), m) << " to: " << lo << "\n";
tout << get_lower(i) << ":" << get_upper(i) << "\n";);
// Only assert bounds for bounded objectives
if (lo.is_finite()) {

View file

@ -344,7 +344,7 @@ namespace smt {
}
}
m_best_penalty = m_penalty;
TRACE("opt", display(tout););
TRACE(opt, display(tout););
}
literal flip() {
@ -496,7 +496,7 @@ namespace smt {
}
}
TRACE("opt", tout << "flip: " << l << " num false: " << m_hard_false.num_elems()
TRACE(opt, tout << "flip: " << l << " num false: " << m_hard_false.num_elems()
<< " penalty: " << m_penalty << " break count: " << break_count << "\n";);
return break_count;
}

View file

@ -76,7 +76,7 @@ namespace opt {
trace_bounds("sortmax");
s().assert_expr(out[first]);
is_sat = s().check_sat(0, nullptr);
TRACE("opt", tout << is_sat << "\n"; s().display(tout); tout << "\n";);
TRACE(opt, tout << is_sat << "\n"; s().display(tout); tout << "\n";);
if (!m.inc()) {
is_sat = l_undef;
}
@ -87,7 +87,7 @@ namespace opt {
for (; first < out.size() && is_true(out[first]); ++first) {
s().assert_expr(out[first]);
}
TRACE("opt", model_smt2_pp(tout, m, *m_model.get(), 0););
TRACE(opt, model_smt2_pp(tout, m, *m_model.get(), 0););
m_upper = m_lower + rational(out.size() - first);
(*m_filter)(m_model);
}
@ -96,7 +96,7 @@ namespace opt {
is_sat = l_true;
m_lower = m_upper;
}
TRACE("opt", tout << "min cost: " << m_upper << "\n";);
TRACE(opt, tout << "min cost: " << m_upper << "\n";);
return is_sat;
}

View file

@ -50,7 +50,7 @@ namespace opt {
m_defs(m) {}
lbool operator()() override {
TRACE("opt", tout << "weighted maxsat\n";);
TRACE(opt, tout << "weighted maxsat\n";);
scoped_ensure_theory wth(*this);
reset();
if (!init())
@ -67,7 +67,7 @@ namespace opt {
wth().init_min_cost(m_upper - m_lower);
trace_bounds("wmax");
TRACE("opt",
TRACE(opt,
s().display(tout) << "\n";
tout << "lower: " << m_lower << " upper: " << m_upper << "\n";);
while (m.inc() && m_lower < m_upper) {
@ -79,7 +79,7 @@ namespace opt {
break;
}
if (is_sat == l_false) {
TRACE("opt", tout << "Unsat\n";);
TRACE(opt, tout << "Unsat\n";);
break;
}
if (is_sat == l_true) {
@ -107,7 +107,7 @@ namespace opt {
is_sat = l_true;
m_lower = m_upper;
}
TRACE("opt", tout << "min cost: " << m_upper << "\n";);
TRACE(opt, tout << "min cost: " << m_upper << "\n";);
return is_sat;
}