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

fix wcnf front-end and unsat case in pd

Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
Nikolaj Bjorner 2015-08-23 14:24:51 -07:00
parent ee458fa601
commit 149549dd52
2 changed files with 34 additions and 11 deletions

View file

@ -239,7 +239,12 @@ public:
break; break;
case l_false: case l_false:
is_sat = process_unsat(); is_sat = process_unsat();
if (is_sat != l_true) return is_sat; if (is_sat == l_false) {
m_lower = m_upper;
}
if (is_sat == l_undef) {
return is_sat;
}
break; break;
case l_undef: case l_undef:
return l_undef; return l_undef;

View file

@ -42,6 +42,11 @@ public:
next(); next();
} }
} }
void skip_space() {
while (ch() != 10 && ((ch() >= 9 && ch() <= 13) || ch() == 32)) {
next();
}
}
void skip_line() { void skip_line() {
while(true) { while(true) {
if (eof()) { if (eof()) {
@ -88,6 +93,19 @@ public:
} }
return neg ? -val : val; return neg ? -val : val;
} }
unsigned parse_unsigned() {
skip_space();
if (ch() == '\n') {
return UINT_MAX;
}
unsigned val = 0;
while (ch() >= '0' && ch() <= '9') {
val = val*10 + (ch() - '0');
next();
}
return val;
}
}; };
class wcnf { class wcnf {
@ -95,11 +113,10 @@ class wcnf {
ast_manager& m; ast_manager& m;
stream_buffer& in; stream_buffer& in;
app_ref read_clause(int& weight) { app_ref read_clause(unsigned& weight) {
int parsed_lit; int parsed_lit;
int var; int var;
parsed_lit = in.parse_int(); weight = in.parse_unsigned();
weight = parsed_lit;
app_ref result(m), p(m); app_ref result(m), p(m);
expr_ref_vector ors(m); expr_ref_vector ors(m);
while (true) { while (true) {
@ -115,11 +132,11 @@ class wcnf {
return result; return result;
} }
void parse_spec(int& num_vars, int& num_clauses, int& max_weight) { void parse_spec(unsigned& num_vars, unsigned& num_clauses, unsigned& max_weight) {
in.parse_token("wcnf"); in.parse_token("wcnf");
num_vars = in.parse_int(); num_vars = in.parse_unsigned();
num_clauses = in.parse_int(); num_clauses = in.parse_unsigned();
max_weight = in.parse_int(); max_weight = in.parse_unsigned();
} }
public: public:
@ -129,7 +146,7 @@ public:
} }
void parse() { void parse() {
int num_vars = 0, num_clauses = 0, max_weight = 0; unsigned num_vars = 0, num_clauses = 0, max_weight = 0;
while (true) { while (true) {
in.skip_whitespace(); in.skip_whitespace();
if (in.eof()) { if (in.eof()) {
@ -141,11 +158,12 @@ public:
else if (*in == 'p') { else if (*in == 'p') {
++in; ++in;
parse_spec(num_vars, num_clauses, max_weight); parse_spec(num_vars, num_clauses, max_weight);
std::cout << "v " << num_vars << " c " << num_clauses << " w " << max_weight << "\n";
} }
else { else {
int weight = 0; unsigned weight = 0;
app_ref cls = read_clause(weight); app_ref cls = read_clause(weight);
if (weight == max_weight) { if (weight >= max_weight) {
opt.add_hard_constraint(cls); opt.add_hard_constraint(cls);
} }
else { else {