Z3
Data Structures | Public Member Functions | Friends
optimize Class Reference
+ Inheritance diagram for optimize:

Data Structures

class  handle
 
struct  translate
 

Public Member Functions

 optimize (context &c)
 
 optimize (context &c, optimize const &src, translate)
 
 optimize (optimize const &o)
 
 optimize (context &c, optimize &src)
 
optimizeoperator= (optimize const &o)
 
 ~optimize () override
 
 operator Z3_optimize () const
 
void add (expr const &e)
 
void add (expr_vector const &es)
 
void add (expr const &e, expr const &t)
 
void add (expr const &e, char const *p)
 
handle add_soft (expr const &e, unsigned weight)
 
handle add_soft (expr const &e, char const *weight)
 
handle add (expr const &e, unsigned weight)
 
void set_initial_value (expr const &var, expr const &value)
 
void set_initial_value (expr const &var, int i)
 
void set_initial_value (expr const &var, bool b)
 
handle maximize (expr const &e)
 
handle minimize (expr const &e)
 
void push ()
 
void pop ()
 
check_result check ()
 
check_result check (expr_vector const &asms)
 
model get_model () const
 
expr_vector unsat_core () const
 
void set (params const &p)
 
expr lower (handle const &h)
 
expr upper (handle const &h)
 
expr_vector assertions () const
 
expr_vector objectives () const
 
stats statistics () const
 
void from_file (char const *filename)
 
void from_string (char const *constraints)
 
std::string help () const
 
- Public Member Functions inherited from object
 object (context &c)
 
virtual ~object ()=default
 
contextctx () const
 
Z3_error_code check_error () const
 

Friends

std::ostream & operator<< (std::ostream &out, optimize const &s)
 

Additional Inherited Members

- Protected Attributes inherited from object
contextm_ctx
 

Detailed Description

Definition at line 3457 of file z3++.h.

Constructor & Destructor Documentation

optimize ( context c)
inline

Definition at line 3468 of file z3++.h.

3468 :object(c) { m_opt = Z3_mk_optimize(c); Z3_optimize_inc_ref(c, m_opt); }
Z3_optimize Z3_API Z3_mk_optimize(Z3_context c)
Create a new optimize context.
void Z3_API Z3_optimize_inc_ref(Z3_context c, Z3_optimize d)
Increment the reference counter of the given optimize context.
object(context &c)
Definition: z3++.h:538
optimize ( context c,
optimize const &  src,
translate   
)
inline

Definition at line 3469 of file z3++.h.

3469  : object(c) {
3470  Z3_optimize o = Z3_optimize_translate(src.ctx(), src, c);
3471  check_error();
3472  m_opt = o;
3473  Z3_optimize_inc_ref(c, m_opt);
3474  }
void Z3_API Z3_optimize_inc_ref(Z3_context c, Z3_optimize d)
Increment the reference counter of the given optimize context.
Z3_error_code check_error() const
Definition: z3++.h:541
Z3_optimize Z3_API Z3_optimize_translate(Z3_context c, Z3_optimize o, Z3_context target)
Copy an optimization context from a source to a target context.
object(context &c)
Definition: z3++.h:538
optimize ( optimize const &  o)
inline

Definition at line 3475 of file z3++.h.

3475  :object(o), m_opt(o.m_opt) {
3476  Z3_optimize_inc_ref(o.ctx(), o.m_opt);
3477  }
void Z3_API Z3_optimize_inc_ref(Z3_context c, Z3_optimize d)
Increment the reference counter of the given optimize context.
object(context &c)
Definition: z3++.h:538
optimize ( context c,
optimize src 
)
inline

Definition at line 3478 of file z3++.h.

3478  :object(c) {
3479  m_opt = Z3_mk_optimize(c);
3480  Z3_optimize_inc_ref(c, m_opt);
3481  add(expr_vector(c, src.assertions()));
3482  expr_vector v(c, src.objectives());
3483  for (expr_vector::iterator it = v.begin(); it != v.end(); ++it) minimize(*it);
3484  }
Z3_optimize Z3_API Z3_mk_optimize(Z3_context c)
Create a new optimize context.
void Z3_API Z3_optimize_inc_ref(Z3_context c, Z3_optimize d)
Increment the reference counter of the given optimize context.
void add(expr const &e)
Definition: z3++.h:3494
object(context &c)
Definition: z3++.h:538
handle minimize(expr const &e)
Definition: z3++.h:3535
ast_vector_tpl< expr > expr_vector
Definition: z3++.h:77
~optimize ( )
inlineoverride

Definition at line 3492 of file z3++.h.

3492 { Z3_optimize_dec_ref(ctx(), m_opt); }
context & ctx() const
Definition: z3++.h:540
void Z3_API Z3_optimize_dec_ref(Z3_context c, Z3_optimize d)
Decrement the reference counter of the given optimize context.

Member Function Documentation

void add ( expr const &  e)
inline

Definition at line 3494 of file z3++.h.

Referenced by optimize::add(), and optimize::optimize().

3494  {
3495  assert(e.is_bool());
3496  Z3_optimize_assert(ctx(), m_opt, e);
3497  }
void Z3_API Z3_optimize_assert(Z3_context c, Z3_optimize o, Z3_ast a)
Assert hard constraint to the optimization context.
context & ctx() const
Definition: z3++.h:540
void add ( expr_vector const &  es)
inline

Definition at line 3498 of file z3++.h.

3498  {
3499  for (expr_vector::iterator it = es.begin(); it != es.end(); ++it) add(*it);
3500  }
void add(expr const &e)
Definition: z3++.h:3494
void add ( expr const &  e,
expr const &  t 
)
inline

Definition at line 3501 of file z3++.h.

3501  {
3502  assert(e.is_bool());
3503  Z3_optimize_assert_and_track(ctx(), m_opt, e, t);
3504  }
void Z3_API Z3_optimize_assert_and_track(Z3_context c, Z3_optimize o, Z3_ast a, Z3_ast t)
Assert tracked hard constraint to the optimization context.
context & ctx() const
Definition: z3++.h:540
void add ( expr const &  e,
char const *  p 
)
inline

Definition at line 3505 of file z3++.h.

3505  {
3506  assert(e.is_bool());
3507  add(e, ctx().bool_const(p));
3508  }
context & ctx() const
Definition: z3++.h:540
void add(expr const &e)
Definition: z3++.h:3494
handle add ( expr const &  e,
unsigned  weight 
)
inline

Definition at line 3518 of file z3++.h.

3518  {
3519  return add_soft(e, weight);
3520  }
handle add_soft(expr const &e, unsigned weight)
Definition: z3++.h:3509
handle add_soft ( expr const &  e,
unsigned  weight 
)
inline

Definition at line 3509 of file z3++.h.

Referenced by optimize::add().

3509  {
3510  assert(e.is_bool());
3511  auto str = std::to_string(weight);
3512  return handle(Z3_optimize_assert_soft(ctx(), m_opt, e, str.c_str(), 0));
3513  }
context & ctx() const
Definition: z3++.h:540
unsigned Z3_API Z3_optimize_assert_soft(Z3_context c, Z3_optimize o, Z3_ast a, Z3_string weight, Z3_symbol id)
Assert soft constraint to the optimization context.
handle add_soft ( expr const &  e,
char const *  weight 
)
inline

Definition at line 3514 of file z3++.h.

3514  {
3515  assert(e.is_bool());
3516  return handle(Z3_optimize_assert_soft(ctx(), m_opt, e, weight, 0));
3517  }
context & ctx() const
Definition: z3++.h:540
unsigned Z3_API Z3_optimize_assert_soft(Z3_context c, Z3_optimize o, Z3_ast a, Z3_string weight, Z3_symbol id)
Assert soft constraint to the optimization context.
expr_vector assertions ( ) const
inline

Definition at line 3569 of file z3++.h.

Referenced by optimize::optimize().

3569 { Z3_ast_vector r = Z3_optimize_get_assertions(ctx(), m_opt); check_error(); return expr_vector(ctx(), r); }
Z3_error_code check_error() const
Definition: z3++.h:541
context & ctx() const
Definition: z3++.h:540
Z3_ast_vector Z3_API Z3_optimize_get_assertions(Z3_context c, Z3_optimize o)
Return the set of asserted formulas on the optimization context.
ast_vector_tpl< expr > expr_vector
Definition: z3++.h:77
check_result check ( )
inline

Definition at line 3544 of file z3++.h.

3544 { Z3_lbool r = Z3_optimize_check(ctx(), m_opt, 0, 0); check_error(); return to_check_result(r); }
Z3_error_code check_error() const
Definition: z3++.h:541
Z3_lbool Z3_API Z3_optimize_check(Z3_context c, Z3_optimize o, unsigned num_assumptions, Z3_ast const assumptions[])
Check consistency and produce optimal values.
context & ctx() const
Definition: z3++.h:540
Z3_lbool
Lifted Boolean type: false, undefined, true.
Definition: z3_api.h:57
check_result to_check_result(Z3_lbool l)
Definition: z3++.h:178
check_result check ( expr_vector const &  asms)
inline

Definition at line 3545 of file z3++.h.

3545  {
3546  unsigned n = asms.size();
3547  array<Z3_ast> _asms(n);
3548  for (unsigned i = 0; i < n; ++i) {
3549  check_context(*this, asms[i]);
3550  _asms[i] = asms[i];
3551  }
3552  Z3_lbool r = Z3_optimize_check(ctx(), m_opt, n, _asms.ptr());
3553  check_error();
3554  return to_check_result(r);
3555  }
Z3_error_code check_error() const
Definition: z3++.h:541
Z3_lbool Z3_API Z3_optimize_check(Z3_context c, Z3_optimize o, unsigned num_assumptions, Z3_ast const assumptions[])
Check consistency and produce optimal values.
context & ctx() const
Definition: z3++.h:540
Z3_lbool
Lifted Boolean type: false, undefined, true.
Definition: z3_api.h:57
friend void check_context(object const &a, object const &b)
Definition: z3++.h:544
check_result to_check_result(Z3_lbool l)
Definition: z3++.h:178
void from_file ( char const *  filename)
inline

Definition at line 3573 of file z3++.h.

3573 { Z3_optimize_from_file(ctx(), m_opt, filename); check_error(); }
Z3_error_code check_error() const
Definition: z3++.h:541
context & ctx() const
Definition: z3++.h:540
void Z3_API Z3_optimize_from_file(Z3_context c, Z3_optimize o, Z3_string s)
Parse an SMT-LIB2 file with assertions, soft constraints and optimization objectives. Add the parsed constraints and objectives to the optimization context.
void from_string ( char const *  constraints)
inline

Definition at line 3574 of file z3++.h.

3574 { Z3_optimize_from_string(ctx(), m_opt, constraints); check_error(); }
Z3_error_code check_error() const
Definition: z3++.h:541
context & ctx() const
Definition: z3++.h:540
void Z3_API Z3_optimize_from_string(Z3_context c, Z3_optimize o, Z3_string s)
Parse an SMT-LIB2 string with assertions, soft constraints and optimization objectives. Add the parsed constraints and objectives to the optimization context.
model get_model ( ) const
inline

Definition at line 3556 of file z3++.h.

3556 { Z3_model m = Z3_optimize_get_model(ctx(), m_opt); check_error(); return model(ctx(), m); }
Z3_error_code check_error() const
Definition: z3++.h:541
context & ctx() const
Definition: z3++.h:540
Z3_model Z3_API Z3_optimize_get_model(Z3_context c, Z3_optimize o)
Retrieve the model for the last Z3_optimize_check.
std::string help ( ) const
inline

Definition at line 3575 of file z3++.h.

3575 { char const * r = Z3_optimize_get_help(ctx(), m_opt); check_error(); return r; }
Z3_error_code check_error() const
Definition: z3++.h:541
context & ctx() const
Definition: z3++.h:540
Z3_string Z3_API Z3_optimize_get_help(Z3_context c, Z3_optimize t)
Return a string containing a description of parameters accepted by optimize.
expr lower ( handle const &  h)
inline

Definition at line 3559 of file z3++.h.

3559  {
3560  Z3_ast r = Z3_optimize_get_lower(ctx(), m_opt, h.h());
3561  check_error();
3562  return expr(ctx(), r);
3563  }
Z3_error_code check_error() const
Definition: z3++.h:541
context & ctx() const
Definition: z3++.h:540
Z3_ast Z3_API Z3_optimize_get_lower(Z3_context c, Z3_optimize o, unsigned idx)
Retrieve lower bound value or approximation for the i'th optimization objective.
handle maximize ( expr const &  e)
inline

Definition at line 3532 of file z3++.h.

3532  {
3533  return handle(Z3_optimize_maximize(ctx(), m_opt, e));
3534  }
context & ctx() const
Definition: z3++.h:540
unsigned Z3_API Z3_optimize_maximize(Z3_context c, Z3_optimize o, Z3_ast t)
Add a maximization constraint.
handle minimize ( expr const &  e)
inline

Definition at line 3535 of file z3++.h.

Referenced by optimize::optimize().

3535  {
3536  return handle(Z3_optimize_minimize(ctx(), m_opt, e));
3537  }
context & ctx() const
Definition: z3++.h:540
unsigned Z3_API Z3_optimize_minimize(Z3_context c, Z3_optimize o, Z3_ast t)
Add a minimization constraint.
expr_vector objectives ( ) const
inline

Definition at line 3570 of file z3++.h.

Referenced by optimize::optimize().

3570 { Z3_ast_vector r = Z3_optimize_get_objectives(ctx(), m_opt); check_error(); return expr_vector(ctx(), r); }
Z3_ast_vector Z3_API Z3_optimize_get_objectives(Z3_context c, Z3_optimize o)
Return objectives on the optimization context. If the objective function is a max-sat objective it is...
Z3_error_code check_error() const
Definition: z3++.h:541
context & ctx() const
Definition: z3++.h:540
ast_vector_tpl< expr > expr_vector
Definition: z3++.h:77
operator Z3_optimize ( ) const
inline

Definition at line 3493 of file z3++.h.

3493 { return m_opt; }
optimize& operator= ( optimize const &  o)
inline

Definition at line 3485 of file z3++.h.

3485  {
3486  Z3_optimize_inc_ref(o.ctx(), o.m_opt);
3487  Z3_optimize_dec_ref(ctx(), m_opt);
3488  m_opt = o.m_opt;
3489  object::operator=(o);
3490  return *this;
3491  }
void Z3_API Z3_optimize_inc_ref(Z3_context c, Z3_optimize d)
Increment the reference counter of the given optimize context.
context & ctx() const
Definition: z3++.h:540
void Z3_API Z3_optimize_dec_ref(Z3_context c, Z3_optimize d)
Decrement the reference counter of the given optimize context.
void pop ( )
inline

Definition at line 3541 of file z3++.h.

3541  {
3542  Z3_optimize_pop(ctx(), m_opt);
3543  }
context & ctx() const
Definition: z3++.h:540
void Z3_API Z3_optimize_pop(Z3_context c, Z3_optimize d)
Backtrack one level.
void push ( )
inline

Definition at line 3538 of file z3++.h.

3538  {
3539  Z3_optimize_push(ctx(), m_opt);
3540  }
context & ctx() const
Definition: z3++.h:540
void Z3_API Z3_optimize_push(Z3_context c, Z3_optimize d)
Create a backtracking point.
void set ( params const &  p)
inline

Definition at line 3558 of file z3++.h.

3558 { Z3_optimize_set_params(ctx(), m_opt, p); check_error(); }
Z3_error_code check_error() const
Definition: z3++.h:541
void Z3_API Z3_optimize_set_params(Z3_context c, Z3_optimize o, Z3_params p)
Set parameters on optimization context.
context & ctx() const
Definition: z3++.h:540
void set_initial_value ( expr const &  var,
expr const &  value 
)
inline

Definition at line 3521 of file z3++.h.

Referenced by optimize::set_initial_value().

3521  {
3522  Z3_optimize_set_initial_value(ctx(), m_opt, var, value);
3523  check_error();
3524  }
Z3_error_code check_error() const
Definition: z3++.h:541
context & ctx() const
Definition: z3++.h:540
void Z3_API Z3_optimize_set_initial_value(Z3_context c, Z3_optimize o, Z3_ast v, Z3_ast val)
provide an initialization hint to the solver. The initialization hint is used to calibrate an initial...
void set_initial_value ( expr const &  var,
int  i 
)
inline

Definition at line 3525 of file z3++.h.

3525  {
3526  set_initial_value(var, ctx().num_val(i, var.get_sort()));
3527  }
void set_initial_value(expr const &var, expr const &value)
Definition: z3++.h:3521
context & ctx() const
Definition: z3++.h:540
void set_initial_value ( expr const &  var,
bool  b 
)
inline

Definition at line 3528 of file z3++.h.

3528  {
3529  set_initial_value(var, ctx().bool_val(b));
3530  }
void set_initial_value(expr const &var, expr const &value)
Definition: z3++.h:3521
context & ctx() const
Definition: z3++.h:540
stats statistics ( ) const
inline

Definition at line 3571 of file z3++.h.

3571 { Z3_stats r = Z3_optimize_get_statistics(ctx(), m_opt); check_error(); return stats(ctx(), r); }
Z3_error_code check_error() const
Definition: z3++.h:541
context & ctx() const
Definition: z3++.h:540
Z3_stats Z3_API Z3_optimize_get_statistics(Z3_context c, Z3_optimize d)
Retrieve statistics information from the last call to Z3_optimize_check.
expr_vector unsat_core ( ) const
inline

Definition at line 3557 of file z3++.h.

3557 { Z3_ast_vector r = Z3_optimize_get_unsat_core(ctx(), m_opt); check_error(); return expr_vector(ctx(), r); }
Z3_error_code check_error() const
Definition: z3++.h:541
context & ctx() const
Definition: z3++.h:540
ast_vector_tpl< expr > expr_vector
Definition: z3++.h:77
Z3_ast_vector Z3_API Z3_optimize_get_unsat_core(Z3_context c, Z3_optimize o)
Retrieve the unsat core for the last Z3_optimize_check The unsat core is a subset of the assumptions ...
expr upper ( handle const &  h)
inline

Definition at line 3564 of file z3++.h.

3564  {
3565  Z3_ast r = Z3_optimize_get_upper(ctx(), m_opt, h.h());
3566  check_error();
3567  return expr(ctx(), r);
3568  }
Z3_error_code check_error() const
Definition: z3++.h:541
Z3_ast Z3_API Z3_optimize_get_upper(Z3_context c, Z3_optimize o, unsigned idx)
Retrieve upper bound value or approximation for the i'th optimization objective.
context & ctx() const
Definition: z3++.h:540

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  out,
optimize const &  s 
)
friend

Definition at line 3577 of file z3++.h.

3577 { out << Z3_optimize_to_string(s.ctx(), s.m_opt); return out; }
Z3_string Z3_API Z3_optimize_to_string(Z3_context c, Z3_optimize o)
Print the current context as a string.