Z3
 
Loading...
Searching...
No Matches
Data Structures | Public Member Functions
Optimize Class Reference
+ Inheritance diagram for Optimize:

Data Structures

class  Handle
 

Public Member Functions

String getHelp ()
 
void setParameters (Params value)
 
ParamDescrs getParameterDescriptions ()
 
void Assert (Expr< BoolSort >... constraints)
 
void Add (Expr< BoolSort >... constraints)
 
void AssertAndTrack (Expr< BoolSort > constraint, Expr< BoolSort > p)
 
Handle<?> AssertSoft (Expr< BoolSort > constraint, int weight, String group)
 
Handle<?> AssertSoft (Expr< BoolSort > constraint, String weight, String group)
 
Status Check (Expr< BoolSort >... assumptions)
 
void Push ()
 
void Pop ()
 
Model getModel ()
 
BoolExpr[] getUnsatCore ()
 
String getReasonUnknown ()
 
String toString ()
 
void fromFile (String file)
 
void fromString (String s)
 
BoolExpr[] getAssertions ()
 
Expr<?>[] getObjectives ()
 
void setInitialValue (Expr<?> var, Expr<?> value)
 
Statistics getStatistics ()
 

Additional Inherited Members

- Static Public Member Functions inherited from Z3Object
static long[] arrayToNative (Z3Object[] a)
 
static int arrayLength (Z3Object[] a)
 

Detailed Description

Object for managing optimization context

Definition at line 30 of file Optimize.java.

Member Function Documentation

◆ Add()

void Add ( Expr< BoolSort >...  constraints)
inline

Alias for Assert.

Definition at line 73 of file Optimize.java.

74 {
75 Assert(constraints);
76 }
void Assert(Expr< BoolSort >... constraints)
Definition Optimize.java:61

◆ Assert()

void Assert ( Expr< BoolSort >...  constraints)
inline

Assert a constraint (or multiple) into the optimize solver.

Definition at line 61 of file Optimize.java.

62 {
63 getContext().checkContextMatch(constraints);
64 for (Expr<BoolSort> a : constraints)
65 {
66 Native.optimizeAssert(getContext().nCtx(), getNativeObject(), a.getNativeObject());
67 }
68 }

◆ AssertAndTrack()

void AssertAndTrack ( Expr< BoolSort >  constraint,
Expr< BoolSort >  p 
)
inline

Assert a constraint into the optimizer, and track it (in the unsat) core using the Boolean constant p.

Remarks: This API is an alternative to Check with assumptions for extracting unsat cores. Both APIs can be used in the same solver. The unsat core will contain a combination of the Boolean variables provided using AssertAndTrack and the Boolean literals provided using Check with assumptions.

See also
Optimize::Check
Optimize::AssertAndTrack

Definition at line 93 of file Optimize.java.

94 {
95 getContext().checkContextMatch(constraint);
96 getContext().checkContextMatch(p);
97
98 Native.optimizeAssertAndTrack(getContext().nCtx(), getNativeObject(),
99 constraint.getNativeObject(), p.getNativeObject());
100 }

◆ AssertSoft() [1/2]

Handle<?> AssertSoft ( Expr< BoolSort >  constraint,
int  weight,
String  group 
)
inline

Assert soft constraint

Return an objective which associates with the group of constraints.

Definition at line 179 of file Optimize.java.

180 {
181 return AssertSoft(constraint, Integer.toString(weight), group);
182 }
Handle<?> AssertSoft(Expr< BoolSort > constraint, int weight, String group)

◆ AssertSoft() [2/2]

Handle<?> AssertSoft ( Expr< BoolSort >  constraint,
String  weight,
String  group 
)
inline

Assert soft constraint

Return an objective which associates with the group of constraints.

Definition at line 190 of file Optimize.java.

191 {
192 getContext().checkContextMatch(constraint);
193 Symbol s = getContext().mkSymbol(group);
194 return new Handle<>(this, Native.optimizeAssertSoft(getContext().nCtx(), getNativeObject(), constraint.getNativeObject(), weight, s.getNativeObject()));
195 }
IntSymbol mkSymbol(int i)
Definition Context.java:94

◆ Check()

Status Check ( Expr< BoolSort >...  assumptions)
inline

Check satisfiability of asserted constraints. Produce a model that (when the objectives are bounded and don't use strict inequalities) is optimal.

Definition at line 202 of file Optimize.java.

203 {
204 Z3_lbool r;
205 if (assumptions == null) {
206 r = Z3_lbool.fromInt(
207 Native.optimizeCheck(
208 getContext().nCtx(),
209 getNativeObject(), 0, null));
210 }
211 else {
212 r = Z3_lbool.fromInt(
213 Native.optimizeCheck(
214 getContext().nCtx(),
215 getNativeObject(),
216 assumptions.length,
217 AST.arrayToNative(assumptions)));
218 }
219 switch (r) {
220 case Z3_L_TRUE:
221 return Status.SATISFIABLE;
222 case Z3_L_FALSE:
223 return Status.UNSATISFIABLE;
224 default:
225 return Status.UNKNOWN;
226 }
227 }
Z3_lbool
Lifted Boolean type: false, undefined, true.
Definition z3_api.h:58
@ Z3_L_TRUE
Definition z3_api.h:61
@ Z3_L_FALSE
Definition z3_api.h:59
Status
Status values.
Definition Status.cs:29

◆ fromFile()

void fromFile ( String  file)
inline

Parse an SMT-LIB2 file with optimization objectives and constraints. The parsed constraints and objectives are added to the optimization context.

Definition at line 371 of file Optimize.java.

372 {
373 Native.optimizeFromFile(getContext().nCtx(), getNativeObject(), file);
374 }

◆ fromString()

void fromString ( String  s)
inline

Similar to FromFile. Instead it takes as argument a string.

Definition at line 379 of file Optimize.java.

380 {
381 Native.optimizeFromString(getContext().nCtx(), getNativeObject(), s);
382 }

◆ getAssertions()

BoolExpr[] getAssertions ( )
inline

The set of asserted formulas.

Definition at line 387 of file Optimize.java.

388 {
389 ASTVector assertions = new ASTVector(getContext(), Native.optimizeGetAssertions(getContext().nCtx(), getNativeObject()));
390 return assertions.ToBoolExprArray();
391 }

◆ getHelp()

String getHelp ( )
inline

A string that describes all available optimize solver parameters.

Definition at line 35 of file Optimize.java.

36 {
37 return Native.optimizeGetHelp(getContext().nCtx(), getNativeObject());
38 }

◆ getModel()

Model getModel ( )
inline

The model of the last Check.

The result is null if Check was not invoked before, if its results was not SATISFIABLE, or if model production is not enabled.

Definition at line 254 of file Optimize.java.

255 {
256 long x = Native.optimizeGetModel(getContext().nCtx(), getNativeObject());
257 if (x == 0) {
258 return null;
259 } else {
260 return new Model(getContext(), x);
261 }
262 }
Model(ctx=None, eval={})
Definition z3py.py:7470

◆ getObjectives()

Expr<?>[] getObjectives ( )
inline

The set of asserted formulas.

Definition at line 396 of file Optimize.java.

397 {
398 ASTVector objectives = new ASTVector(getContext(), Native.optimizeGetObjectives(getContext().nCtx(), getNativeObject()));
399 return objectives.ToExprArray();
400 }

◆ getParameterDescriptions()

ParamDescrs getParameterDescriptions ( )
inline

Retrieves parameter descriptions for Optimize solver.

Definition at line 53 of file Optimize.java.

54 {
55 return new ParamDescrs(getContext(), Native.optimizeGetParamDescrs(getContext().nCtx(), getNativeObject()));
56 }

◆ getReasonUnknown()

String getReasonUnknown ( )
inline

Return a string the describes why the last to check returned unknown

Definition at line 353 of file Optimize.java.

354 {
355 return Native.optimizeGetReasonUnknown(getContext().nCtx(), getNativeObject());
356 }

◆ getStatistics()

Statistics getStatistics ( )
inline

Optimize statistics.

Definition at line 421 of file Optimize.java.

422 {
423 return new Statistics(getContext(), Native.optimizeGetStatistics(getContext().nCtx(), getNativeObject()));
424 }

◆ getUnsatCore()

BoolExpr[] getUnsatCore ( )
inline

The unsat core of the last Check. Remarks: The unsat core is a subset of Assumptions The result is empty if Check was not invoked before, if its results was not UNSATISFIABLE, or if core production is disabled.

Exceptions
Z3Exception

Definition at line 273 of file Optimize.java.

274 {
275 ASTVector core = new ASTVector(getContext(), Native.optimizeGetUnsatCore(getContext().nCtx(), getNativeObject()));
276 return core.ToBoolExprArray();
277 }

◆ Pop()

void Pop ( )
inline

Backtrack one backtracking point.

Note that an exception is thrown if Pop is called without a corresponding Push.

Definition at line 242 of file Optimize.java.

243 {
244 Native.optimizePop(getContext().nCtx(), getNativeObject());
245 }

◆ Push()

void Push ( )
inline

Creates a backtracking point.

Definition at line 232 of file Optimize.java.

233 {
234 Native.optimizePush(getContext().nCtx(), getNativeObject());
235 }

◆ setInitialValue()

void setInitialValue ( Expr<?>  var,
Expr<?>  value 
)
inline

Set an initial value for a variable to guide the optimizer's search heuristics. This can improve performance when a good initial value is known for the variable.

Parameters
varThe variable to set an initial value for
valueThe initial value for the variable
Exceptions
Z3Exception

Definition at line 410 of file Optimize.java.

411 {
412 getContext().checkContextMatch(var);
413 getContext().checkContextMatch(value);
414 Native.optimizeSetInitialValue(getContext().nCtx(), getNativeObject(),
415 var.getNativeObject(), value.getNativeObject());
416 }

◆ setParameters()

void setParameters ( Params  value)
inline

Sets the optimize solver parameters.

Exceptions
Z3Exception

Definition at line 45 of file Optimize.java.

46 {
47 Native.optimizeSetParams(getContext().nCtx(), getNativeObject(), value.getNativeObject());
48 }

◆ toString()

String toString ( )
inline

Print the context to a String (SMT-LIB parseable benchmark).

Definition at line 362 of file Optimize.java.

363 {
364 return Native.optimizeToString(getContext().nCtx(), getNativeObject());
365 }