class Z3::Optimize

Overview

A solver with objectives. Everything Solver does with assertions it does too, plus #maximize, #minimize and #assert_soft - soft constraints being the ones Z3 is allowed to break, paying their weight when it does, which is MaxSAT.

Z3's objective value readers aren't bound, so read the maximised term out of the model rather than expecting one from #maximize, which answers the objective's index the way Z3 does.

Included Modules

Defined in:

z3/optimize.cr

Constructors

Instance Method Summary

Instance methods inherited from module Z3::Checkable

prove!(claim : BoolExpr, io : IO = STDOUT) : Nil prove!, satisfiable?(*assumptions) : Bool satisfiable?, unsatisfiable?(*assumptions) : Bool unsatisfiable?

Constructor Detail

def self.new #

[View source]

Instance Method Detail

def assert(expr) #

[View source]
def assert_and_track(expr, tracker) #

tracker is a Bool const standing in for expr, and it's what shows up in #unsat_core if the solver blames this assertion


[View source]
def assert_soft(expr, weight : String = "1") #

A constraint Z3 may break, at the cost of weight. The weight is a String because that's Z3's own interface to it.


[View source]
def assertions #

[View source]
def check(*assumptions) : CheckResult #

[View source]
def from_file(path : String) #

[View source]
def from_string(str : String) #

Parses SMT-LIB2 and adds its assertions on top of whatever's already asserted, the same way Solver#from_string does - except that this parser knows (maximize ...), (minimize ...) and (assert-soft ...) too, so a string can bring objectives along with its assertions.


[View source]
def help #

[View source]
def maximize(expr) #

[View source]
def minimize(expr) #

[View source]
def model #

[View source]
def pop #

Z3's optimizer pops one scope at a time, unlike a Solver


[View source]
def push #

[View source]
def reason_unknown #

[View source]
def set_initial_value(var : AnyExpr, value) #

A hint at which value to try for a variable first, the same warm start Solver.simple takes - but Bool and Bitvec only.

Z3's optimizer gets arithmetic ones wrong in both directions: an Int hint is dropped by its elim_01 preprocessing before the search ever sees it, and a Real hint which does arrive comes back out of that preprocessing scaled, so an Optimize with an objective can answer with a model that fails its own assertions. Those two raise here rather than being passed through; Solver.simple honours arithmetic warm starts correctly and is where one belongs until Z3 is fixed.


[View source]
def statistics #

[View source]
def to_s(io) #

[View source]
def to_unsafe : LibZ3::Optimize #

[View source]
def unsat_core #

[View source]