mirror of
https://github.com/Z3Prover/z3
synced 2025-04-23 09:05:31 +00:00
add priority queue to instantiation
This commit is contained in:
parent
22b0c3aa70
commit
46f754c43d
19 changed files with 1138 additions and 541 deletions
|
@ -3,7 +3,6 @@ z3_add_component(smt
|
|||
arith_eq_adapter.cpp
|
||||
arith_eq_solver.cpp
|
||||
asserted_formulas.cpp
|
||||
cost_evaluator.cpp
|
||||
dyn_ack.cpp
|
||||
expr_context_simplifier.cpp
|
||||
fingerprints.cpp
|
||||
|
|
|
@ -1,100 +0,0 @@
|
|||
/*++
|
||||
Copyright (c) 2006 Microsoft Corporation
|
||||
|
||||
Module Name:
|
||||
|
||||
cost_evaluator.cpp
|
||||
|
||||
Abstract:
|
||||
|
||||
<abstract>
|
||||
|
||||
Author:
|
||||
|
||||
Leonardo de Moura (leonardo) 2008-06-14.
|
||||
|
||||
Revision History:
|
||||
|
||||
--*/
|
||||
#include "smt/cost_evaluator.h"
|
||||
#include "util/warning.h"
|
||||
|
||||
cost_evaluator::cost_evaluator(ast_manager & m):
|
||||
m(m),
|
||||
m_util(m) {
|
||||
}
|
||||
|
||||
float cost_evaluator::eval(expr * f) const {
|
||||
#define E(IDX) eval(to_app(f)->get_arg(IDX))
|
||||
if (is_app(f)) {
|
||||
family_id fid = to_app(f)->get_family_id();
|
||||
if (fid == m.get_basic_family_id()) {
|
||||
switch (to_app(f)->get_decl_kind()) {
|
||||
case OP_TRUE: return 1.0f;
|
||||
case OP_FALSE: return 0.0f;
|
||||
case OP_NOT: return E(0) == 0.0f ? 1.0f : 0.0f;
|
||||
case OP_AND:
|
||||
for (expr* arg : *to_app(f))
|
||||
if (eval(arg) == 0.0f)
|
||||
return 0.0f;
|
||||
return 1.0f;
|
||||
case OP_OR:
|
||||
for (expr* arg : *to_app(f))
|
||||
if (eval(arg) != 0.0f)
|
||||
return 1.0f;
|
||||
return 0.0f;
|
||||
case OP_ITE: return E(0) != 0.0f ? E(1) : E(2);
|
||||
case OP_EQ: return E(0) == E(1) ? 1.0f : 0.0f;
|
||||
case OP_XOR: return E(0) != E(1) ? 1.0f : 0.0f;
|
||||
case OP_IMPLIES:
|
||||
if (E(0) == 0.0f)
|
||||
return 1.0f;
|
||||
return E(1) != 0.0f ? 1.0f : 0.0f;
|
||||
default:
|
||||
;
|
||||
}
|
||||
}
|
||||
else if (fid == m_util.get_family_id()) {
|
||||
switch (to_app(f)->get_decl_kind()) {
|
||||
case OP_NUM: {
|
||||
rational r = to_app(f)->get_decl()->get_parameter(0).get_rational();
|
||||
return static_cast<float>(numerator(r).get_int64())/static_cast<float>(denominator(r).get_int64());
|
||||
}
|
||||
case OP_LE: return E(0) <= E(1) ? 1.0f : 0.0f;
|
||||
case OP_GE: return E(0) >= E(1) ? 1.0f : 0.0f;
|
||||
case OP_LT: return E(0) < E(1) ? 1.0f : 0.0f;
|
||||
case OP_GT: return E(0) > E(1) ? 1.0f : 0.0f;
|
||||
case OP_ADD: return E(0) + E(1);
|
||||
case OP_SUB: return E(0) - E(1);
|
||||
case OP_UMINUS: return - E(0);
|
||||
case OP_MUL: return E(0) * E(1);
|
||||
case OP_DIV: {
|
||||
float q = E(1);
|
||||
if (q == 0.0f) {
|
||||
warning_msg("cost function division by zero");
|
||||
return 1.0f;
|
||||
}
|
||||
return E(0) / q;
|
||||
}
|
||||
default:
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (is_var(f)) {
|
||||
unsigned idx = to_var(f)->get_idx();
|
||||
if (idx < m_num_args)
|
||||
return m_args[m_num_args - idx - 1];
|
||||
}
|
||||
warning_msg("cost function evaluation error");
|
||||
return 1.0f;
|
||||
}
|
||||
|
||||
float cost_evaluator::operator()(expr * f, unsigned num_args, float const * args) {
|
||||
m_num_args = num_args;
|
||||
m_args = args;
|
||||
return eval(f);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -1,41 +0,0 @@
|
|||
/*++
|
||||
Copyright (c) 2006 Microsoft Corporation
|
||||
|
||||
Module Name:
|
||||
|
||||
cost_evaluator.h
|
||||
|
||||
Abstract:
|
||||
|
||||
Simple evaluator for cost function
|
||||
|
||||
Author:
|
||||
|
||||
Leonardo de Moura (leonardo) 2008-06-14.
|
||||
|
||||
Revision History:
|
||||
|
||||
--*/
|
||||
#pragma once
|
||||
|
||||
#include "ast/ast.h"
|
||||
#include "ast/arith_decl_plugin.h"
|
||||
|
||||
class cost_evaluator {
|
||||
ast_manager & m;
|
||||
arith_util m_util;
|
||||
unsigned m_num_args;
|
||||
float const * m_args;
|
||||
float eval(expr * f) const;
|
||||
public:
|
||||
cost_evaluator(ast_manager & m);
|
||||
/**
|
||||
I'm using the same standard used in quantifier instantiation.
|
||||
(VAR 0) is stored in the last position of the array.
|
||||
...
|
||||
(VAR (num_args - 1)) is stored in the first position of the array.
|
||||
*/
|
||||
float operator()(expr * f, unsigned num_args, float const * args);
|
||||
};
|
||||
|
||||
|
|
@ -26,7 +26,7 @@ Revision History:
|
|||
#include "smt/smt_quantifier.h"
|
||||
#include "smt/fingerprints.h"
|
||||
#include "smt/params/qi_params.h"
|
||||
#include "smt/cost_evaluator.h"
|
||||
#include "ast/cost_evaluator.h"
|
||||
#include "util/statistics.h"
|
||||
|
||||
namespace smt {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue