mirror of
https://github.com/Z3Prover/z3
synced 2025-08-18 17:22:15 +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
|
@ -15,6 +15,7 @@ z3_add_component(ast
|
|||
ast_util.cpp
|
||||
bv_decl_plugin.cpp
|
||||
char_decl_plugin.cpp
|
||||
cost_evaluator.cpp
|
||||
datatype_decl_plugin.cpp
|
||||
decl_collector.cpp
|
||||
display_dimacs.cpp
|
||||
|
|
100
src/ast/cost_evaluator.cpp
Normal file
100
src/ast/cost_evaluator.cpp
Normal file
|
@ -0,0 +1,100 @@
|
|||
/*++
|
||||
Copyright (c) 2006 Microsoft Corporation
|
||||
|
||||
Module Name:
|
||||
|
||||
cost_evaluator.cpp
|
||||
|
||||
Abstract:
|
||||
|
||||
<abstract>
|
||||
|
||||
Author:
|
||||
|
||||
Leonardo de Moura (leonardo) 2008-06-14.
|
||||
|
||||
Revision History:
|
||||
|
||||
--*/
|
||||
#include "ast/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);
|
||||
}
|
||||
|
||||
|
||||
|
41
src/ast/cost_evaluator.h
Normal file
41
src/ast/cost_evaluator.h
Normal file
|
@ -0,0 +1,41 @@
|
|||
/*++
|
||||
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);
|
||||
};
|
||||
|
||||
|
|
@ -295,8 +295,6 @@ namespace euf {
|
|||
enode_vector const& nodes() const { return m_nodes; }
|
||||
|
||||
ast_manager& get_manager() { return m; }
|
||||
bool is_relevant(enode* n) const { return true; } // TODO
|
||||
bool resource_limits_exceeded() const { return false; } // TODO
|
||||
|
||||
void invariant();
|
||||
void copy_from(egraph const& src, std::function<void*(void*)>& copy_justification);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue