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 3145 of file z3++.h.

Constructor & Destructor Documentation

◆ optimize() [1/3]

optimize ( context c)
inline

◆ optimize() [2/3]

optimize ( optimize const &  o)
inline

◆ optimize() [3/3]

optimize ( context c,
optimize src 
)
inline

◆ ~optimize()

~optimize ( )
inline

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

3173 { Z3_optimize_dec_ref(ctx(), m_opt); }
context & ctx() const
Definition: z3++.h:463
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

◆ add() [1/5]

void add ( expr const &  e)
inline

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

3175  {
3176  assert(e.is_bool());
3177  Z3_optimize_assert(ctx(), m_opt, e);
3178  }
void Z3_API Z3_optimize_assert(Z3_context c, Z3_optimize o, Z3_ast a)
Assert hard constraint to the optimization context.

Referenced by Solver::__iadd__(), Fixedpoint::__iadd__(), Optimize::__iadd__(), optimize::add(), and optimize::optimize().

◆ add() [2/5]

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

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

3186  {
3187  assert(e.is_bool());
3188  add(e, ctx().bool_const(p));
3189  }

Referenced by Solver::__iadd__(), Fixedpoint::__iadd__(), and Optimize::__iadd__().

◆ add() [3/5]

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

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

3182  {
3183  assert(e.is_bool());
3184  Z3_optimize_assert_and_track(ctx(), m_opt, e, t);
3185  }
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.

Referenced by Solver::__iadd__(), Fixedpoint::__iadd__(), and Optimize::__iadd__().

◆ add() [4/5]

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

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

3199  {
3200  return add_soft(e, weight);
3201  }
handle add_soft(expr const &e, unsigned weight)
Definition: z3++.h:3190

Referenced by Solver::__iadd__(), Fixedpoint::__iadd__(), and Optimize::__iadd__().

◆ add() [5/5]

void add ( expr_vector const &  es)
inline

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

3179  {
3180  for (expr_vector::iterator it = es.begin(); it != es.end(); ++it) add(*it);
3181  }

Referenced by Solver::__iadd__(), Fixedpoint::__iadd__(), and Optimize::__iadd__().

◆ add_soft() [1/2]

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

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

3195  {
3196  assert(e.is_bool());
3197  return handle(Z3_optimize_assert_soft(ctx(), m_opt, e, weight, 0));
3198  }
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.

◆ add_soft() [2/2]

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

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

3190  {
3191  assert(e.is_bool());
3192  auto str = std::to_string(weight);
3193  return handle(Z3_optimize_assert_soft(ctx(), m_opt, e, str.c_str(), 0));
3194  }

Referenced by optimize::add().

◆ assertions()

expr_vector assertions ( ) const
inline

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

3239 { 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:464
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.
System.IntPtr Z3_ast_vector

Referenced by optimize::optimize(), and Solver::to_smt2().

◆ check() [1/2]

check_result check ( )
inline

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

3214 { Z3_lbool r = Z3_optimize_check(ctx(), m_opt, 0, 0); check_error(); return to_check_result(r); }
Z3_lbool
Lifted Boolean type: false, undefined, true.
Definition: z3_api.h:60
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.
check_result to_check_result(Z3_lbool l)
Definition: z3++.h:146

◆ check() [2/2]

check_result check ( expr_vector const &  asms)
inline

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

3215  {
3216  unsigned n = asms.size();
3217  array<Z3_ast> _asms(n);
3218  for (unsigned i = 0; i < n; i++) {
3219  check_context(*this, asms[i]);
3220  _asms[i] = asms[i];
3221  }
3222  Z3_lbool r = Z3_optimize_check(ctx(), m_opt, n, _asms.ptr());
3223  check_error();
3224  return to_check_result(r);
3225  }
friend void check_context(object const &a, object const &b)
Definition: z3++.h:467

◆ from_file()

void from_file ( char const *  filename)
inline

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

3243 { Z3_optimize_from_file(ctx(), m_opt, filename); check_error(); }
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....

◆ from_string()

void from_string ( char const *  constraints)
inline

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

3244 { Z3_optimize_from_string(ctx(), m_opt, constraints); check_error(); }
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....

◆ get_model()

model get_model ( ) const
inline

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

3226 { Z3_model m = Z3_optimize_get_model(ctx(), m_opt); check_error(); return model(ctx(), m); }
Z3_model Z3_API Z3_optimize_get_model(Z3_context c, Z3_optimize o)
Retrieve the model for the last Z3_optimize_check.
System.IntPtr Z3_model

◆ help()

std::string help ( ) const
inline

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

3245 { char const * r = Z3_optimize_get_help(ctx(), m_opt); check_error(); return r; }
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.

◆ lower()

expr lower ( handle const &  h)
inline

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

3229  {
3230  Z3_ast r = Z3_optimize_get_lower(ctx(), m_opt, h.h());
3231  check_error();
3232  return expr(ctx(), r);
3233  }
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.
System.IntPtr Z3_ast

Referenced by OptimizeObjective::value().

◆ maximize()

handle maximize ( expr const &  e)
inline

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

3202  {
3203  return handle(Z3_optimize_maximize(ctx(), m_opt, e));
3204  }
unsigned Z3_API Z3_optimize_maximize(Z3_context c, Z3_optimize o, Z3_ast t)
Add a maximization constraint.

◆ minimize()

handle minimize ( expr const &  e)
inline

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

3205  {
3206  return handle(Z3_optimize_minimize(ctx(), m_opt, e));
3207  }
unsigned Z3_API Z3_optimize_minimize(Z3_context c, Z3_optimize o, Z3_ast t)
Add a minimization constraint.

Referenced by optimize::optimize().

◆ objectives()

expr_vector objectives ( ) const
inline

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

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

Referenced by optimize::optimize().

◆ operator Z3_optimize()

operator Z3_optimize ( ) const
inline

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

3174 { return m_opt; }

◆ operator=()

optimize& operator= ( optimize const &  o)
inline

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

3166  {
3167  Z3_optimize_inc_ref(o.ctx(), o.m_opt);
3168  Z3_optimize_dec_ref(ctx(), m_opt);
3169  m_opt = o.m_opt;
3170  object::operator=(o);
3171  return *this;
3172  }

◆ pop()

void pop ( )
inline

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

3211  {
3212  Z3_optimize_pop(ctx(), m_opt);
3213  }
void Z3_API Z3_optimize_pop(Z3_context c, Z3_optimize d)
Backtrack one level.

◆ push()

void push ( )
inline

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

3208  {
3209  Z3_optimize_push(ctx(), m_opt);
3210  }
void Z3_API Z3_optimize_push(Z3_context c, Z3_optimize d)
Create a backtracking point.

◆ set()

void set ( params const &  p)
inline

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

3228 { Z3_optimize_set_params(ctx(), m_opt, p); check_error(); }
void Z3_API Z3_optimize_set_params(Z3_context c, Z3_optimize o, Z3_params p)
Set parameters on optimization context.

◆ statistics()

stats statistics ( ) const
inline

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

3241 { Z3_stats r = Z3_optimize_get_statistics(ctx(), m_opt); check_error(); return stats(ctx(), r); }
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.
System.IntPtr Z3_stats

◆ unsat_core()

expr_vector unsat_core ( ) const
inline

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

3227 { Z3_ast_vector r = Z3_optimize_get_unsat_core(ctx(), m_opt); check_error(); return expr_vector(ctx(), r); }
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 ...

◆ upper()

expr upper ( handle const &  h)
inline

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

3234  {
3235  Z3_ast r = Z3_optimize_get_upper(ctx(), m_opt, h.h());
3236  check_error();
3237  return expr(ctx(), r);
3238  }
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.

Referenced by OptimizeObjective::value().

Friends And Related Function Documentation

◆ operator<<

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

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

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