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

add colors

Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
Nikolaj Bjorner 2021-07-15 00:03:56 +02:00
commit 4c6e2acd45
56 changed files with 419 additions and 195 deletions

View file

@ -36,7 +36,7 @@ core::core(lp::lar_solver& s, reslimit & lim) :
m_emons(m_evars),
m_reslim(lim),
m_use_nra_model(false),
m_nra(s, lim, *this)
m_nra(s, m_nra_lim, *this)
{
m_nlsat_delay = lp_settings().nlsat_delay();
}
@ -1563,10 +1563,15 @@ bool core::should_run_bounded_nlsat() {
lbool core::bounded_nlsat() {
params_ref p;
lbool ret;
p.set_uint("max_conflicts", 100);
scoped_rlimit sr(m_reslim, 100000);
m_nra.updt_params(p);
lbool ret = m_nra.check();
{
scoped_limits sl(m_reslim);
sl.push_child(&m_nra_lim);
scoped_rlimit sr(m_nra_lim, 100000);
ret = m_nra.check();
}
p.set_uint("max_conflicts", UINT_MAX);
m_nra.updt_params(p);
m_stats.m_nra_calls++;

View file

@ -175,6 +175,7 @@ private:
svector<lpvar> m_add_buffer;
mutable lp::u_set m_active_var_set;
lp::u_set m_rows;
reslimit m_nra_lim;
public:
reslimit& m_reslim;
bool m_use_nra_model;

View file

@ -22,7 +22,7 @@ Notes:
#include "math/polysat/types.h"
namespace polysat {
class clause_builder {
solver& m_solver;
sat::literal_vector m_literals;

View file

@ -1,5 +1,9 @@
#ifndef _MSC_VER
#include <unistd.h> // for isatty
#else
#include <windows.h>
#include <io.h>
#undef min
#endif
#include <utility>
@ -54,11 +58,11 @@ level_color(LogLevel msg_level)
{
switch (msg_level) {
case LogLevel::Heading1:
return "\x1B[31m"; // red
return ""; // red
case LogLevel::Heading2:
return "\x1B[33m"; // yellow
return ""; // yellow
case LogLevel::Heading3:
return "\x1B[34m"; // blue
return ""; // blue
default:
return nullptr;
}
@ -70,16 +74,20 @@ std::pair<std::ostream&, bool>
polysat_log(LogLevel msg_level, std::string fn, std::string /* pretty_fn */)
{
std::ostream& os = std::cerr;
#if 0
int const fd = fileno(stderr);
size_t width = 20;
size_t padding = width - std::min(width, fn.size());
#ifdef _MSC_VER
char const* color = nullptr;
color = level_color(msg_level);
#ifdef _MSC_VER
HANDLE hOut = GetStdHandle(STD_ERROR_HANDLE);
bool ok = hOut != INVALID_HANDLE_VALUE;
DWORD dwMode = 0;
ok = ok && GetConsoleMode(hOut, &dwMode);
dwMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
ok = ok && SetConsoleMode(hOut, dwMode);
#else
char const* color = level_color(msg_level);
int const fd = _fileno(stderr);
if (color && !isatty(fd)) { color = nullptr; }
#endif
@ -87,9 +95,6 @@ polysat_log(LogLevel msg_level, std::string fn, std::string /* pretty_fn */)
os << "[" << fn << "] " << std::string(padding, ' ');
os << std::string(polysat_log_indent_level, ' ');
return {os, (bool)color};
#else
return {os, false};
#endif
}

View file

@ -134,20 +134,29 @@ namespace opt {
}
void model_based_opt::def::normalize() {
if (m_div.is_one()) return;
SASSERT(m_div.is_int());
if (m_div.is_neg()) {
for (var& v : m_vars)
v.m_coeff.neg();
m_coeff.neg();
m_div.neg();
}
if (m_div.is_one())
return;
rational g(m_div);
if (!m_coeff.is_int())
return;
g = gcd(g, m_coeff);
for (var const& v : m_vars) {
if (!v.m_coeff.is_int())
return;
g = gcd(g, abs(v.m_coeff));
if (g.is_one()) break;
}
if (m_div.is_neg()) {
g.neg();
if (g.is_one())
break;
}
if (!g.is_one()) {
for (var& v : m_vars) {
v.m_coeff /= g;
}
for (var& v : m_vars)
v.m_coeff /= g;
m_coeff /= g;
m_div /= g;
}
@ -1130,9 +1139,12 @@ namespace opt {
}
TRACE("opt1", display(tout << "tableau after replace x by y := v" << y << "\n"););
def result = project(y, compute_def);
if (compute_def)
result = (result * D) + u;
SASSERT(!compute_def || eval(result) == eval(x));
if (compute_def) {
result = (result * D) + u;
m_var2value[x] = eval(result);
}
TRACE("opt1", display(tout << "tableau after project y" << y << "\n"););
return result;
}
@ -1181,7 +1193,7 @@ namespace opt {
// 3 | -t & 21 | (-ct + 3s) & a-t <= 3u
model_based_opt::def model_based_opt::solve_for(unsigned row_id1, unsigned x, bool compute_def) {
TRACE("opt", tout << "v" << x << "\n" << m_rows[row_id1] << "\n";);
TRACE("opt", tout << "v" << x << " := " << eval(x) << "\n" << m_rows[row_id1] << "\n";);
rational a = get_coefficient(row_id1, x), b;
ineq_type ty = m_rows[row_id1].m_type;
SASSERT(!a.is_zero());
@ -1231,6 +1243,7 @@ namespace opt {
if (compute_def) {
result = def(m_rows[row_id1], x);
m_var2value[x] = eval(result);
TRACE("opt1", tout << "updated eval " << x << " := " << eval(x) << "\n";);
}
retire_row(row_id1);
return result;