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

Data Structures

class  handle
 

Public Member Functions

 optimize (context &c)
 
 optimize (optimize const &o)
 
 optimize (context &c, optimize &src)
 
optimizeoperator= (optimize const &o)
 
 ~optimize ()
 
 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)
 
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)
 
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 3081 of file z3++.h.

Constructor & Destructor Documentation

optimize ( context c)
inline

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

3091 :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:427
optimize ( optimize const &  o)
inline

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

3092  :object(o), m_opt(o.m_opt) {
3093  Z3_optimize_inc_ref(o.ctx(), o.m_opt);
3094  }
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:427
optimize ( context c,
optimize src 
)
inline

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

3095  :object(c) {
3096  m_opt = Z3_mk_optimize(c);
3097  Z3_optimize_inc_ref(c, m_opt);
3098  add(expr_vector(c, src.assertions()));
3099  expr_vector v(c, src.objectives());
3100  for (expr_vector::iterator it = v.begin(); it != v.end(); ++it) minimize(*it);
3101  }
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:3111
object(context &c)
Definition: z3++.h:427
handle minimize(expr const &e)
Definition: z3++.h:3141
ast_vector_tpl< expr > expr_vector
Definition: z3++.h:73
~optimize ( )
inline

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

3109 { Z3_optimize_dec_ref(ctx(), m_opt); }
context & ctx() const
Definition: z3++.h:428
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 3111 of file z3++.h.

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

3111  {
3112  assert(e.is_bool());
3113  Z3_optimize_assert(ctx(), m_opt, e);
3114  }
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:428
void add ( expr_vector const &  es)
inline

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

3115  {
3116  for (expr_vector::iterator it = es.begin(); it != es.end(); ++it) add(*it);
3117  }
void add(expr const &e)
Definition: z3++.h:3111
void add ( expr const &  e,
expr const &  t 
)
inline

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

3118  {
3119  assert(e.is_bool());
3120  Z3_optimize_assert_and_track(ctx(), m_opt, e, t);
3121  }
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:428
void add ( expr const &  e,
char const *  p 
)
inline

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

3122  {
3123  assert(e.is_bool());
3124  add(e, ctx().bool_const(p));
3125  }
context & ctx() const
Definition: z3++.h:428
void add(expr const &e)
Definition: z3++.h:3111
handle add ( expr const &  e,
unsigned  weight 
)
inline

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

3135  {
3136  return add_soft(e, weight);
3137  }
handle add_soft(expr const &e, unsigned weight)
Definition: z3++.h:3126
handle add_soft ( expr const &  e,
unsigned  weight 
)
inline

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

Referenced by optimize::add().

3126  {
3127  assert(e.is_bool());
3128  auto str = std::to_string(weight);
3129  return handle(Z3_optimize_assert_soft(ctx(), m_opt, e, str.c_str(), 0));
3130  }
context & ctx() const
Definition: z3++.h:428
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 3131 of file z3++.h.

3131  {
3132  assert(e.is_bool());
3133  return handle(Z3_optimize_assert_soft(ctx(), m_opt, e, weight, 0));
3134  }
context & ctx() const
Definition: z3++.h:428
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 3175 of file z3++.h.

Referenced by optimize::optimize().

3175 { 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:429
context & ctx() const
Definition: z3++.h:428
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:73
check_result check ( )
inline

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

3150 { 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:429
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:428
Z3_lbool
Lifted Boolean type: false, undefined, true.
Definition: z3_api.h:101
check_result to_check_result(Z3_lbool l)
Definition: z3++.h:144
check_result check ( expr_vector const &  asms)
inline

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

3151  {
3152  unsigned n = asms.size();
3153  array<Z3_ast> _asms(n);
3154  for (unsigned i = 0; i < n; i++) {
3155  check_context(*this, asms[i]);
3156  _asms[i] = asms[i];
3157  }
3158  Z3_lbool r = Z3_optimize_check(ctx(), m_opt, n, _asms.ptr());
3159  check_error();
3160  return to_check_result(r);
3161  }
Z3_error_code check_error() const
Definition: z3++.h:429
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:428
Z3_lbool
Lifted Boolean type: false, undefined, true.
Definition: z3_api.h:101
friend void check_context(object const &a, object const &b)
Definition: z3++.h:432
check_result to_check_result(Z3_lbool l)
Definition: z3++.h:144
void from_file ( char const *  filename)
inline

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

3179 { Z3_optimize_from_file(ctx(), m_opt, filename); check_error(); }
Z3_error_code check_error() const
Definition: z3++.h:429
context & ctx() const
Definition: z3++.h:428
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 3180 of file z3++.h.

3180 { Z3_optimize_from_string(ctx(), m_opt, constraints); check_error(); }
Z3_error_code check_error() const
Definition: z3++.h:429
context & ctx() const
Definition: z3++.h:428
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 3162 of file z3++.h.

3162 { 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:429
context & ctx() const
Definition: z3++.h:428
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 3181 of file z3++.h.

3181 { char const * r = Z3_optimize_get_help(ctx(), m_opt); check_error(); return r; }
Z3_error_code check_error() const
Definition: z3++.h:429
context & ctx() const
Definition: z3++.h:428
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 3165 of file z3++.h.

3165  {
3166  Z3_ast r = Z3_optimize_get_lower(ctx(), m_opt, h.h());
3167  check_error();
3168  return expr(ctx(), r);
3169  }
Z3_error_code check_error() const
Definition: z3++.h:429
context & ctx() const
Definition: z3++.h:428
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 3138 of file z3++.h.

3138  {
3139  return handle(Z3_optimize_maximize(ctx(), m_opt, e));
3140  }
context & ctx() const
Definition: z3++.h:428
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 3141 of file z3++.h.

Referenced by optimize::optimize().

3141  {
3142  return handle(Z3_optimize_minimize(ctx(), m_opt, e));
3143  }
context & ctx() const
Definition: z3++.h:428
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 3176 of file z3++.h.

Referenced by optimize::optimize().

3176 { 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:429
context & ctx() const
Definition: z3++.h:428
ast_vector_tpl< expr > expr_vector
Definition: z3++.h:73
operator Z3_optimize ( ) const
inline

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

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

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

3102  {
3103  Z3_optimize_inc_ref(o.ctx(), o.m_opt);
3104  Z3_optimize_dec_ref(ctx(), m_opt);
3105  m_opt = o.m_opt;
3106  object::operator=(o);
3107  return *this;
3108  }
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:428
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 3147 of file z3++.h.

3147  {
3148  Z3_optimize_pop(ctx(), m_opt);
3149  }
context & ctx() const
Definition: z3++.h:428
void Z3_API Z3_optimize_pop(Z3_context c, Z3_optimize d)
Backtrack one level.
void push ( )
inline

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

3144  {
3145  Z3_optimize_push(ctx(), m_opt);
3146  }
context & ctx() const
Definition: z3++.h:428
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 3164 of file z3++.h.

3164 { Z3_optimize_set_params(ctx(), m_opt, p); check_error(); }
Z3_error_code check_error() const
Definition: z3++.h:429
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:428
stats statistics ( ) const
inline

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

3177 { 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:429
context & ctx() const
Definition: z3++.h:428
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 3163 of file z3++.h.

3163 { 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:429
context & ctx() const
Definition: z3++.h:428
ast_vector_tpl< expr > expr_vector
Definition: z3++.h:73
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 3170 of file z3++.h.

3170  {
3171  Z3_ast r = Z3_optimize_get_upper(ctx(), m_opt, h.h());
3172  check_error();
3173  return expr(ctx(), r);
3174  }
Z3_error_code check_error() const
Definition: z3++.h:429
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:428

Friends And Related Function Documentation

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

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

3183 { 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.