Z3
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 ()
 
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.

Definition at line 91 of file Optimize.java.

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

◆ 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 177 of file Optimize.java.

178  {
179  return AssertSoft(constraint, Integer.toString(weight), group);
180  }
Handle<?> AssertSoft(Expr< BoolSort > constraint, int weight, String group)
Definition: Optimize.java:177

◆ 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 188 of file Optimize.java.

189  {
190  getContext().checkContextMatch(constraint);
191  Symbol s = getContext().mkSymbol(group);
192  return new Handle<>(this, Native.optimizeAssertSoft(getContext().nCtx(), getNativeObject(), constraint.getNativeObject(), weight, s.getNativeObject()));
193  }
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 200 of file Optimize.java.

201  {
202  Z3_lbool r;
203  if (assumptions == null) {
204  r = Z3_lbool.fromInt(
205  Native.optimizeCheck(
206  getContext().nCtx(),
207  getNativeObject(), 0, null));
208  }
209  else {
210  r = Z3_lbool.fromInt(
211  Native.optimizeCheck(
212  getContext().nCtx(),
213  getNativeObject(),
214  assumptions.length,
215  AST.arrayToNative(assumptions)));
216  }
217  switch (r) {
218  case Z3_L_TRUE:
219  return Status.SATISFIABLE;
220  case Z3_L_FALSE:
221  return Status.UNSATISFIABLE;
222  default:
223  return Status.UNKNOWN;
224  }
225  }
Z3_lbool
Lifted Boolean type: false, undefined, true.
Definition: z3_api.h:61
@ Z3_L_TRUE
Definition: z3_api.h:64
@ Z3_L_FALSE
Definition: z3_api.h:62
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 369 of file Optimize.java.

370  {
371  Native.optimizeFromFile(getContext().nCtx(), getNativeObject(), file);
372  }

◆ fromString()

void fromString ( String  s)
inline

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

Definition at line 377 of file Optimize.java.

378  {
379  Native.optimizeFromString(getContext().nCtx(), getNativeObject(), s);
380  }

◆ getAssertions()

BoolExpr [] getAssertions ( )
inline

The set of asserted formulas.

Definition at line 385 of file Optimize.java.

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

◆ 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 252 of file Optimize.java.

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

◆ getObjectives()

Expr<?> [] getObjectives ( )
inline

The set of asserted formulas.

Definition at line 394 of file Optimize.java.

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

◆ 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 351 of file Optimize.java.

352  {
353  return Native.optimizeGetReasonUnknown(getContext().nCtx(), getNativeObject());
354  }

◆ getStatistics()

Statistics getStatistics ( )
inline

Optimize statistics.

Definition at line 403 of file Optimize.java.

404  {
405  return new Statistics(getContext(), Native.optimizeGetStatistics(getContext().nCtx(), getNativeObject()));
406  }

◆ getUnsatCore()

BoolExpr [] getUnsatCore ( )
inline

The unsat core of the last

Status Check(Expr< BoolSort >... assumptions)
Definition: Optimize.java:200

. Remarks: The unsat core is a subset of

Assumptions

The result is empty if

was not invoked before, if its results was not

@ UNSATISFIABLE
Used to signify an unsatisfiable status.

, or if core production is disabled.

Exceptions
Z3Exception

Definition at line 271 of file Optimize.java.

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

◆ 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 240 of file Optimize.java.

241  {
242  Native.optimizePop(getContext().nCtx(), getNativeObject());
243  }

◆ Push()

void Push ( )
inline

Creates a backtracking point.

Definition at line 230 of file Optimize.java.

231  {
232  Native.optimizePush(getContext().nCtx(), getNativeObject());
233  }

◆ 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 360 of file Optimize.java.

361  {
362  return Native.optimizeToString(getContext().nCtx(), getNativeObject());
363  }