optimize.go

Optimization with maximize/minimize objectives

Types

type Context

Context methods (receiver omitted for clarity)

Methods:

NewOptimize

func (c *Context) NewOptimize() *Optimize

NewOptimize creates a new optimization context.

type Optimize

Optimize represents a Z3 optimization context for solving optimization problems. Unlike Solver which only checks satisfiability, Optimize can find optimal solutions with respect to objective functions.

Methods:

Assert

func (o *Optimize) Assert(constraint *Expr)

Assert adds a constraint to the optimizer.

AssertAndTrack

func (o *Optimize) AssertAndTrack(constraint, track *Expr)

AssertAndTrack adds a constraint with a tracking literal for unsat core extraction.

AssertSoft

func (o *Optimize) AssertSoft(constraint *Expr, weight string, group string) uint

AssertSoft adds a soft constraint with a weight. Soft constraints are used for MaxSMT problems. Returns a handle to the objective.

Assertions

func (o *Optimize) Assertions() []*Expr

Assertions returns the assertions in the optimizer.

Check

func (o *Optimize) Check(assumptions ...*Expr) Status

Check checks the satisfiability of the constraints and optimizes objectives.

FromFile

func (o *Optimize) FromFile(filename string)

FromFile parses an SMT-LIB2 file with optimization objectives and constraints.

FromString

func (o *Optimize) FromString(s string)

FromString parses an SMT-LIB2 string with optimization objectives and constraints.

GetHelp

func (o *Optimize) GetHelp() string

GetHelp returns help information for the optimizer.

GetLower

func (o *Optimize) GetLower(index uint) *Expr

GetLower retrieves a lower bound for the objective at the given index.

GetLowerAsVector

func (o *Optimize) GetLowerAsVector(index uint) []*Expr

GetLowerAsVector retrieves a lower bound as a vector (inf, value, eps). The objective value is unbounded if inf is non-zero, otherwise it's represented as value + eps * EPSILON.

GetUpper

func (o *Optimize) GetUpper(index uint) *Expr

GetUpper retrieves an upper bound for the objective at the given index.

GetUpperAsVector

func (o *Optimize) GetUpperAsVector(index uint) []*Expr

GetUpperAsVector retrieves an upper bound as a vector (inf, value, eps). The objective value is unbounded if inf is non-zero, otherwise it's represented as value + eps * EPSILON.

Maximize

func (o *Optimize) Maximize(expr *Expr) uint

Maximize adds a maximization objective. Returns a handle to the objective that can be used to retrieve bounds.

Minimize

func (o *Optimize) Minimize(expr *Expr) uint

Minimize adds a minimization objective. Returns a handle to the objective that can be used to retrieve bounds.

Model

func (o *Optimize) Model() *Model

Model returns the model if the constraints are satisfiable.

Objectives

func (o *Optimize) Objectives() []*Expr

Objectives returns the objectives in the optimizer.

Pop

func (o *Optimize) Pop()

Pop removes a backtracking point.

Push

func (o *Optimize) Push()

Push creates a backtracking point.

ReasonUnknown

func (o *Optimize) ReasonUnknown() string

ReasonUnknown returns the reason why the result is unknown.

SetParams

func (o *Optimize) SetParams(params *Params)

SetParams sets parameters for the optimizer.

String

func (o *Optimize) String() string

String returns the string representation of the optimize context.

UnsatCore

func (o *Optimize) UnsatCore() []*Expr

UnsatCore returns the unsat core if the constraints are unsatisfiable.