21using System.Collections.Generic;
22using System.Diagnostics;
39 return Native.Z3_optimize_get_help(
Context.nCtx, NativeObject);
50 Debug.Assert(value !=
null);
51 Context.CheckContextMatch(value);
52 Native.Z3_optimize_set_params(
Context.nCtx, NativeObject, value.NativeObject);
110 AddConstraints(constraints);
116 public void Assert(IEnumerable<BoolExpr> constraints)
118 AddConstraints(constraints);
126 AddConstraints(constraints);
132 public void Add(IEnumerable<BoolExpr> constraints)
134 AddConstraints(constraints);
140 private void AddConstraints(IEnumerable<BoolExpr> constraints)
142 Debug.Assert(constraints !=
null);
143 Debug.Assert(constraints.All(c => c !=
null));
145 Context.CheckContextMatch(constraints);
148 Native.Z3_optimize_assert(
Context.nCtx, NativeObject, a.NativeObject);
165 Debug.Assert(constraint !=
null);
166 Debug.Assert(p !=
null);
167 Context.CheckContextMatch(constraint);
170 Native.Z3_optimize_assert_and_track(
Context.nCtx, NativeObject, constraint.NativeObject, p.NativeObject);
191 get {
return opt.GetLower(handle); }
199 get {
return opt.GetUpper(handle); }
207 get {
return Lower; }
215 get {
return opt.GetLowerAsVector(handle); }
223 get {
return opt.GetUpperAsVector(handle); }
236 Context.CheckContextMatch(constraint);
238 return new Handle(
this, Native.Z3_optimize_assert_soft(
Context.nCtx, NativeObject, constraint.NativeObject, weight.ToString(), s.NativeObject));
250 Z3_lbool r = (
Z3_lbool)Native.Z3_optimize_check(
Context.nCtx, NativeObject, (uint)assumptions.Length,
AST.ArrayToNative(assumptions));
254 return Status.SATISFIABLE;
256 return Status.UNSATISFIABLE;
268 Native.Z3_optimize_push(
Context.nCtx, NativeObject);
278 Native.Z3_optimize_pop(
Context.nCtx, NativeObject);
293 IntPtr x = Native.Z3_optimize_get_model(
Context.nCtx, NativeObject);
294 if (x == IntPtr.Zero)
315 return core.ToBoolExprArray();
327 return new Handle(
this, Native.Z3_optimize_maximize(
Context.nCtx, NativeObject, e.NativeObject));
336 return new Handle(
this, Native.Z3_optimize_minimize(
Context.nCtx, NativeObject, e.NativeObject));
343 private Expr GetLower(uint index)
345 return Expr.Create(
Context, Native.Z3_optimize_get_lower(
Context.nCtx, NativeObject, index));
352 private Expr GetUpper(uint index)
354 return Expr.Create(
Context, Native.Z3_optimize_get_upper(
Context.nCtx, NativeObject, index));
360 private Expr[] GetLowerAsVector(uint index)
362 using ASTVector v =
new ASTVector(
Context, Native.Z3_optimize_get_lower_as_vector(
Context.nCtx, NativeObject, index));
363 return v.ToExprArray();
370 private Expr[] GetUpperAsVector(uint index)
372 using ASTVector v =
new ASTVector(
Context, Native.Z3_optimize_get_upper_as_vector(
Context.nCtx, NativeObject, index));
373 return v.ToExprArray();
383 return Native.Z3_optimize_get_reason_unknown(
Context.nCtx, NativeObject);
393 return Native.Z3_optimize_to_string(
Context.nCtx, NativeObject);
402 Native.Z3_optimize_from_file(
Context.nCtx, NativeObject, file);
410 Native.Z3_optimize_from_string(
Context.nCtx, NativeObject, s);
422 return assertions.ToBoolExprArray();
435 return objectives.ToExprArray();
457 Debug.Assert(ctx !=
null);
462 Debug.Assert(ctx !=
null);
465 internal override void IncRef(IntPtr o)
467 Native.Z3_optimize_inc_ref(
Context.nCtx, o);
470 internal override void DecRef(IntPtr o)
474 if (
Context.nCtx != IntPtr.Zero)
475 Native.Z3_optimize_dec_ref(
Context.nCtx, o);
The abstract syntax tree (AST) class.
The main interaction with Z3 happens via the Context.
Params MkParams()
Creates a new ParameterSet.
IntSymbol MkSymbol(int i)
Creates a new symbol using an integer.
A Model contains interpretations (assignments) of constants and functions.
Handle to objectives returned by objective functions.
Expr[] UpperAsVector
Retrieve an upper bound for the objective handle.
Expr[] LowerAsVector
Retrieve a lower bound for the objective handle.
Expr Upper
Retrieve an upper bound for the objective handle.
Expr Value
Retrieve the value of an objective.
Expr Lower
Retrieve a lower bound for the objective handle.
Object for managing optimization context.
void Set(string name, uint value)
Sets parameter on the optimize solver.
BoolExpr[] Assertions
The set of asserted formulas.
void Set(string name, double value)
Sets parameter on the optimize solver.
Model Model
The model of the last Check.
string Help
A string that describes all available optimize solver parameters.
void Set(string name, string value)
Sets parameter on the optimize solver.
void Add(IEnumerable< BoolExpr > constraints)
Alias for Assert.
void AssertAndTrack(BoolExpr constraint, BoolExpr p)
Assert a constraint into the optimize solver, and track it (in the unsat) core using the Boolean cons...
void Set(Symbol name, Symbol value)
Sets parameter on the optimize solver.
void Push()
Creates a backtracking point.
Handle MkMaximize(Expr e)
Declare an arithmetical maximization objective. Return a handle to the objective. The handle is used ...
void Assert(params BoolExpr[] constraints)
Assert a constraint (or multiple) into the optimize solver.
void FromString(string s)
Similar to FromFile. Instead it takes as argument a string.
Params Parameters
Sets the optimize solver parameters.
Statistics Statistics
Optimize statistics.
void Pop()
Backtrack one backtracking point.
Handle MkMinimize(Expr e)
Declare an arithmetical minimization objective. Similar to MkMaximize.
void Set(Symbol name, string value)
Sets parameter on the optimize solver.
ParamDescrs ParameterDescriptions
Retrieves parameter descriptions for Optimize solver.
Expr[] Objectives
The set of asserted formulas.
Status Check(params Expr[] assumptions)
Check satisfiability of asserted constraints. Produce a model that (when the objectives are bounded a...
BoolExpr[] UnsatCore
The unsat core of the last Check.
void Assert(IEnumerable< BoolExpr > constraints)
Assert a constraint (or multiple) into the optimize solver.
override string ToString()
Print the context to a string (SMT-LIB parseable benchmark).
void FromFile(string file)
Parse an SMT-LIB2 file with optimization objectives and constraints. The parsed constraints and objec...
void Set(string name, bool value)
Sets parameter on the optimize solver.
void Set(Symbol name, double value)
Sets parameter on the optimize solver.
void Set(Symbol name, bool value)
Sets parameter on the optimize solver.
void Add(params BoolExpr[] constraints)
Alias for Assert.
Handle AssertSoft(BoolExpr constraint, uint weight, string group)
Assert soft constraint.
void Set(string name, Symbol value)
Sets parameter on the optimize solver.
void Set(Symbol name, uint value)
Sets parameter on the optimize solver.
String ReasonUnknown
Return a string the describes why the last to check returned unknown.
A ParamDescrs describes a set of parameters.
A Params objects represents a configuration in the form of Symbol/value pairs.
Params Add(Symbol name, bool value)
Adds a parameter setting.
Objects of this class track statistical information about solvers.
Symbols are used to name several term and type constructors.
Internal base class for interfacing with native Z3 objects. Should not be used externally.
Context Context
Access Context object.
Z3_lbool
Lifted Boolean type: false, undefined, true.
Z3_optimize Z3_API Z3_mk_optimize(Z3_context c)
Create a new optimize context.