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 &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)
 
 object (object const &s)
 
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 2824 of file z3++.h.

Constructor & Destructor Documentation

◆ optimize() [1/3]

optimize ( context c)
inline

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

2834 :object(c) { m_opt = Z3_mk_optimize(c); Z3_optimize_inc_ref(c, m_opt); }

◆ optimize() [2/3]

optimize ( optimize o)
inline

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

2835  :object(o) {
2836  Z3_optimize_inc_ref(o.ctx(), o.m_opt);
2837  m_opt = o.m_opt;
2838  }

◆ optimize() [3/3]

optimize ( context c,
optimize src 
)
inline

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

2839  :object(c) {
2840  m_opt = Z3_mk_optimize(c);
2841  Z3_optimize_inc_ref(c, m_opt);
2842  add(expr_vector(c, src.assertions()));
2843  expr_vector v(c, src.objectives());
2844  for (expr_vector::iterator it = v.begin(); it != v.end(); ++it) minimize(*it);
2845  }

◆ ~optimize()

~optimize ( )
inline

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

2853 { Z3_optimize_dec_ref(ctx(), m_opt); }

Member Function Documentation

◆ add() [1/5]

void add ( expr const &  e)
inline

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

2855  {
2856  assert(e.is_bool());
2857  Z3_optimize_assert(ctx(), m_opt, e);
2858  }

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

◆ add() [2/5]

void add ( expr const &  e,
char const *  p 
)
inline

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

2866  {
2867  assert(e.is_bool());
2868  add(e, ctx().bool_const(p));
2869  }

◆ add() [3/5]

void add ( expr const &  e,
expr const &  t 
)
inline

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

2862  {
2863  assert(e.is_bool());
2864  Z3_optimize_assert_and_track(ctx(), m_opt, e, t);
2865  }

◆ add() [4/5]

handle add ( expr const &  e,
unsigned  weight 
)
inline

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

2879  {
2880  return add_soft(e, weight);
2881  }

◆ add() [5/5]

void add ( expr_vector const &  es)
inline

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

2859  {
2860  for (expr_vector::iterator it = es.begin(); it != es.end(); ++it) add(*it);
2861  }

◆ add_soft() [1/2]

handle add_soft ( expr const &  e,
char const *  weight 
)
inline

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

2875  {
2876  assert(e.is_bool());
2877  return handle(Z3_optimize_assert_soft(ctx(), m_opt, e, weight, 0));
2878  }

◆ add_soft() [2/2]

handle add_soft ( expr const &  e,
unsigned  weight 
)
inline

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

2870  {
2871  assert(e.is_bool());
2872  auto str = std::to_string(weight);
2873  return handle(Z3_optimize_assert_soft(ctx(), m_opt, e, str.c_str(), 0));
2874  }

Referenced by optimize::add().

◆ assertions()

expr_vector assertions ( ) const
inline

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

2919 { Z3_ast_vector r = Z3_optimize_get_assertions(ctx(), m_opt); check_error(); return expr_vector(ctx(), r); }

Referenced by optimize::optimize().

◆ check() [1/2]

check_result check ( )
inline

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

2894 { Z3_lbool r = Z3_optimize_check(ctx(), m_opt, 0, 0); check_error(); return to_check_result(r); }

◆ check() [2/2]

check_result check ( expr_vector const &  asms)
inline

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

2895  {
2896  unsigned n = asms.size();
2897  array<Z3_ast> _asms(n);
2898  for (unsigned i = 0; i < n; i++) {
2899  check_context(*this, asms[i]);
2900  _asms[i] = asms[i];
2901  }
2902  Z3_lbool r = Z3_optimize_check(ctx(), m_opt, n, _asms.ptr());
2903  check_error();
2904  return to_check_result(r);
2905  }

◆ from_file()

void from_file ( char const *  filename)
inline

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

2923 { Z3_optimize_from_file(ctx(), m_opt, filename); check_error(); }

◆ from_string()

void from_string ( char const *  constraints)
inline

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

2924 { Z3_optimize_from_string(ctx(), m_opt, constraints); check_error(); }

◆ get_model()

model get_model ( ) const
inline

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

2906 { Z3_model m = Z3_optimize_get_model(ctx(), m_opt); check_error(); return model(ctx(), m); }

◆ help()

std::string help ( ) const
inline

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

2925 { char const * r = Z3_optimize_get_help(ctx(), m_opt); check_error(); return r; }

◆ lower()

expr lower ( handle const &  h)
inline

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

2909  {
2910  Z3_ast r = Z3_optimize_get_lower(ctx(), m_opt, h.h());
2911  check_error();
2912  return expr(ctx(), r);
2913  }

◆ maximize()

handle maximize ( expr const &  e)
inline

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

2882  {
2883  return handle(Z3_optimize_maximize(ctx(), m_opt, e));
2884  }

◆ minimize()

handle minimize ( expr const &  e)
inline

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

2885  {
2886  return handle(Z3_optimize_minimize(ctx(), m_opt, e));
2887  }

Referenced by optimize::optimize().

◆ objectives()

expr_vector objectives ( ) const
inline

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

2920 { Z3_ast_vector r = Z3_optimize_get_objectives(ctx(), m_opt); check_error(); return expr_vector(ctx(), r); }

Referenced by optimize::optimize().

◆ operator Z3_optimize()

operator Z3_optimize ( ) const
inline

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

2854 { return m_opt; }

◆ operator=()

optimize& operator= ( optimize const &  o)
inline

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

2846  {
2847  Z3_optimize_inc_ref(o.ctx(), o.m_opt);
2848  Z3_optimize_dec_ref(ctx(), m_opt);
2849  m_opt = o.m_opt;
2850  m_ctx = o.m_ctx;
2851  return *this;
2852  }

◆ pop()

void pop ( )
inline

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

2891  {
2892  Z3_optimize_pop(ctx(), m_opt);
2893  }

◆ push()

void push ( )
inline

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

2888  {
2889  Z3_optimize_push(ctx(), m_opt);
2890  }

◆ set()

void set ( params const &  p)
inline

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

2908 { Z3_optimize_set_params(ctx(), m_opt, p); check_error(); }

◆ statistics()

stats statistics ( ) const
inline

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

2921 { Z3_stats r = Z3_optimize_get_statistics(ctx(), m_opt); check_error(); return stats(ctx(), r); }

◆ unsat_core()

expr_vector unsat_core ( ) const
inline

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

2907 { Z3_ast_vector r = Z3_optimize_get_unsat_core(ctx(), m_opt); check_error(); return expr_vector(ctx(), r); }

◆ upper()

expr upper ( handle const &  h)
inline

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

2914  {
2915  Z3_ast r = Z3_optimize_get_upper(ctx(), m_opt, h.h());
2916  check_error();
2917  return expr(ctx(), r);
2918  }

Friends And Related Function Documentation

◆ operator<<

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

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

2927 { out << Z3_optimize_to_string(s.ctx(), s.m_opt); return out; }
Z3_optimize_pop
void Z3_API Z3_optimize_pop(Z3_context c, Z3_optimize d)
Backtrack one level.
Z3_optimize_assert_and_track
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.
Z3_optimize_dec_ref
void Z3_API Z3_optimize_dec_ref(Z3_context c, Z3_optimize d)
Decrement the reference counter of the given optimize context.
Z3_optimize_from_string
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....
Z3_optimize_get_objectives
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_optimize_get_statistics
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.
Z3_optimize_get_assertions
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.
Z3_optimize_assert_soft
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.
Z3_optimize_maximize
unsigned Z3_API Z3_optimize_maximize(Z3_context c, Z3_optimize o, Z3_ast t)
Add a maximization constraint.
Z3_lbool
Z3_lbool
Lifted Boolean type: false, undefined, true.
Definition: z3_api.h:101
Z3_optimize_to_string
Z3_string Z3_API Z3_optimize_to_string(Z3_context c, Z3_optimize o)
Print the current context as a string.
z3::object::object
object(context &c)
Definition: z3++.h:416
z3::object::m_ctx
context * m_ctx
Definition: z3++.h:414
Z3_optimize_get_lower
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.
Z3_optimize_get_upper
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.
Z3_optimize_check
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.
Z3_optimize_assert
void Z3_API Z3_optimize_assert(Z3_context c, Z3_optimize o, Z3_ast a)
Assert hard constraint to the optimization context.
Z3_optimize_from_file
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....
z3::optimize::add
void add(expr const &e)
Definition: z3++.h:2855
Z3_optimize_set_params
void Z3_API Z3_optimize_set_params(Z3_context c, Z3_optimize o, Z3_params p)
Set parameters on optimization context.
z3::expr_vector
ast_vector_tpl< expr > expr_vector
Definition: z3++.h:72
Z3_mk_optimize
Z3_optimize Z3_API Z3_mk_optimize(Z3_context c)
Create a new optimize context.
z3::object::check_context
friend void check_context(object const &a, object const &b)
Definition: z3++.h:422
Z3_optimize_push
void Z3_API Z3_optimize_push(Z3_context c, Z3_optimize d)
Create a backtracking point.
z3::to_check_result
check_result to_check_result(Z3_lbool l)
Definition: z3++.h:143
z3::optimize::minimize
handle minimize(expr const &e)
Definition: z3++.h:2885
z3::object::check_error
Z3_error_code check_error() const
Definition: z3++.h:419
Z3_optimize_get_unsat_core
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 ...
Z3_optimize_get_model
Z3_model Z3_API Z3_optimize_get_model(Z3_context c, Z3_optimize o)
Retrieve the model for the last Z3_optimize_check.
z3::optimize::add_soft
handle add_soft(expr const &e, unsigned weight)
Definition: z3++.h:2870
z3::object::ctx
context & ctx() const
Definition: z3++.h:418
Z3_optimize_get_help
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.
Z3_optimize_minimize
unsigned Z3_API Z3_optimize_minimize(Z3_context c, Z3_optimize o, Z3_ast t)
Add a minimization constraint.
Z3_optimize_inc_ref
void Z3_API Z3_optimize_inc_ref(Z3_context c, Z3_optimize d)
Increment the reference counter of the given optimize context.