OptObserverVec

Struct OptObserverVec 

Source
pub struct OptObserverVec { /* private fields */ }
Expand description

Collection of observers for optimization monitoring.

This struct manages a vector of observers and provides a convenient notify() method to call all observers at once. Optimizers use this internally to manage their observers.

§Usage

Typically you don’t create this directly - use the add_observer() method on optimizers. However, you can use it for custom optimization algorithms:

use apex_solver::observers::{OptObserver, OptObserverVec};
use apex_solver::core::problem::VariableEnum;
use std::collections::HashMap;

struct MyOptimizer {
    observers: OptObserverVec,
    // ... other fields ...
}

impl MyOptimizer {
    fn step(&mut self, values: &HashMap<String, VariableEnum>, iteration: usize) {
        // ... optimization logic ...

        // Notify all observers
        self.observers.notify(values, iteration);
    }
}

Implementations§

Source§

impl OptObserverVec

Source

pub fn new() -> Self

Create a new empty observer collection.

Source

pub fn add(&mut self, observer: impl OptObserver + 'static)

Add an observer to the collection.

The observer will be called at each optimization iteration in the order it was added.

§Arguments
  • observer - Any type implementing OptObserver
§Examples
use apex_solver::observers::{OptObserver, OptObserverVec};
use apex_solver::core::problem::VariableEnum;
use std::collections::HashMap;

struct MyObserver;
impl OptObserver for MyObserver {
    fn on_step(&self, _values: &HashMap<String, VariableEnum>, _iteration: usize) {
        // Handle optimization step
    }
}

let mut observers = OptObserverVec::new();
observers.add(MyObserver);
Source

pub fn set_iteration_metrics( &self, cost: f64, gradient_norm: f64, damping: Option<f64>, step_norm: f64, step_quality: Option<f64>, )

Set iteration metrics for all observers.

Calls set_iteration_metrics() on each registered observer. This should be called before notify() to provide optimization metrics.

§Arguments
  • cost - Current cost function value
  • gradient_norm - L2 norm of the gradient vector
  • damping - Damping parameter (may be None)
  • step_norm - L2 norm of the parameter update step
  • step_quality - Step quality metric (may be None)
Source

pub fn set_matrix_data( &self, hessian: Option<SparseColMat<usize, f64>>, gradient: Option<Mat<f64>>, )

Set matrix data for all observers.

Calls set_matrix_data() on each registered observer. This should be called before notify() to provide matrix data for visualization.

§Arguments
  • hessian - Sparse Hessian matrix
  • gradient - Gradient vector
Source

pub fn notify(&self, values: &HashMap<String, VariableEnum>, iteration: usize)

Notify all observers with current optimization state.

Calls on_step() on each registered observer in order. If no observers are registered, this is a no-op with zero overhead.

§Arguments
  • values - Current variable values
  • iteration - Current iteration number
§Examples
use apex_solver::observers::OptObserverVec;
use std::collections::HashMap;

let observers = OptObserverVec::new();
let values = HashMap::new();

// Notify all observers (safe even if empty)
observers.notify(&values, 0);
Source

pub fn notify_complete( &self, values: &HashMap<String, VariableEnum>, iterations: usize, )

Notify all observers that optimization is complete.

Calls on_optimization_complete() on each registered observer. This should be called once at the end of optimization, after all iterations are done.

§Arguments
  • values - Final optimized variable values
  • iterations - Total number of iterations performed
§Examples
use apex_solver::observers::OptObserverVec;
use std::collections::HashMap;

let observers = OptObserverVec::new();
let values = HashMap::new();

// Notify all observers that optimization is complete
observers.notify_complete(&values, 50);
Source

pub fn is_empty(&self) -> bool

Check if any observers are registered.

Useful for conditional logic or debugging.

Source

pub fn len(&self) -> usize

Get the number of registered observers.

Trait Implementations§

Source§

impl Default for OptObserverVec

Source§

fn default() -> OptObserverVec

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> ByRef<T> for T

Source§

fn by_ref(&self) -> &T

Source§

impl<T> DistributionExt for T
where T: ?Sized,

Source§

fn rand<T>(&self, rng: &mut (impl Rng + ?Sized)) -> T
where Self: Distribution<T>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more