pub struct Optimizer { /* private fields */ }Expand description
Optimizer for SMT formulas with objectives
The optimizer extends the basic SMT solver with optimization capabilities, allowing you to minimize or maximize objectives subject to constraints.
§Examples
§Basic Minimization
use oxiz_solver::{Optimizer, OptimizationResult};
use oxiz_core::ast::TermManager;
use num_bigint::BigInt;
let mut opt = Optimizer::new();
let mut tm = TermManager::new();
opt.set_logic("QF_LIA");
let x = tm.mk_var("x", tm.sorts.int_sort);
let five = tm.mk_int(BigInt::from(5));
opt.assert(tm.mk_ge(x, five));
// Minimize x (should be 5)
opt.minimize(x);
let result = opt.optimize(&mut tm);
match result {
OptimizationResult::Optimal { .. } => println!("Found optimal solution"),
_ => println!("No optimal solution"),
}§Lexicographic Optimization
use oxiz_solver::{Optimizer, OptimizationResult};
use oxiz_core::ast::TermManager;
use num_bigint::BigInt;
let mut opt = Optimizer::new();
let mut tm = TermManager::new();
opt.set_logic("QF_LIA");
let x = tm.mk_var("x", tm.sorts.int_sort);
let y = tm.mk_var("y", tm.sorts.int_sort);
let zero = tm.mk_int(BigInt::from(0));
let ten = tm.mk_int(BigInt::from(10));
opt.assert(tm.mk_ge(x, zero));
let zero_y = tm.mk_int(BigInt::from(0));
opt.assert(tm.mk_ge(y, zero_y));
let sum = tm.mk_add(vec![x, y]);
opt.assert(tm.mk_ge(sum, ten));
// Minimize x first, then y
opt.minimize(x);
opt.minimize(y);
let _result = opt.optimize(&mut tm);Implementations§
Source§impl Optimizer
impl Optimizer
Sourcepub fn optimize(&mut self, term_manager: &mut TermManager) -> OptimizationResult
pub fn optimize(&mut self, term_manager: &mut TermManager) -> OptimizationResult
Check satisfiability and optimize objectives
Uses linear search with binary search refinement for integer objectives. For lexicographic optimization, processes objectives in priority order.
Source§impl Optimizer
impl Optimizer
Sourcepub fn pareto_optimize(
&mut self,
term_manager: &mut TermManager,
) -> Vec<ParetoPoint>
pub fn pareto_optimize( &mut self, term_manager: &mut TermManager, ) -> Vec<ParetoPoint>
Find Pareto-optimal solutions for multi-objective optimization
This implements a simple iterative approach:
- Find an initial solution
- Add constraints to exclude dominated solutions
- Repeat until no more solutions exist
Note: This can be expensive for problems with many Pareto-optimal points
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Optimizer
impl !RefUnwindSafe for Optimizer
impl Send for Optimizer
impl Sync for Optimizer
impl Unpin for Optimizer
impl !UnwindSafe for Optimizer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more