use crate::core::ExitStatus;
#[derive(Debug)]
pub struct AlmOptimizerStatus {
exit_status: ExitStatus,
num_outer_iterations: usize,
num_inner_iterations: usize,
last_problem_norm_fpr: f64,
lagrange_multipliers: Option<Vec<f64>>,
solve_time: std::time::Duration,
penalty: f64,
delta_y_norm: f64,
f2_norm: f64,
cost: f64,
}
impl AlmOptimizerStatus {
pub(crate) fn new(exit_status: ExitStatus) -> Self {
AlmOptimizerStatus {
exit_status,
num_outer_iterations: 0,
num_inner_iterations: 0,
last_problem_norm_fpr: -1.0,
lagrange_multipliers: None,
solve_time: std::time::Duration::from_nanos(0),
penalty: 0.0,
delta_y_norm: 0.0,
f2_norm: 0.0,
cost: 0.0,
}
}
pub(crate) fn with_solve_time(mut self, duration: std::time::Duration) -> Self {
self.solve_time = duration;
self
}
pub(crate) fn with_outer_iterations(mut self, outer_iters: usize) -> Self {
self.num_outer_iterations = outer_iters;
self
}
pub(crate) fn with_inner_iterations(mut self, inner_iters: usize) -> Self {
self.num_inner_iterations = inner_iters;
self
}
pub(crate) fn with_lagrange_multipliers(mut self, lagrange_multipliers: &[f64]) -> Self {
self.lagrange_multipliers = Some(vec![]);
if let Some(y) = &mut self.lagrange_multipliers {
y.extend_from_slice(lagrange_multipliers);
}
self
}
pub(crate) fn with_penalty(mut self, penalty: f64) -> Self {
assert!(
penalty >= 0.0,
"the penalty parameter should not be negative"
);
self.penalty = penalty;
self
}
pub(crate) fn with_last_problem_norm_fpr(mut self, last_problem_norm_fpr: f64) -> Self {
assert!(
last_problem_norm_fpr >= 0.0,
"last_problem_norm_fpr should not be negative"
);
self.last_problem_norm_fpr = last_problem_norm_fpr;
self
}
pub(crate) fn with_delta_y_norm(mut self, delta_y_norm: f64) -> Self {
assert!(delta_y_norm >= 0.0, "delta_y_norm must be nonnegative");
self.delta_y_norm = delta_y_norm;
self
}
pub(crate) fn with_f2_norm(mut self, f2_norm: f64) -> Self {
assert!(f2_norm >= 0.0, "f2_norm must be nonnegative");
self.f2_norm = f2_norm;
self
}
pub(crate) fn with_cost(mut self, cost: f64) -> Self {
self.cost = cost;
self
}
pub fn exit_status(&self) -> ExitStatus {
self.exit_status
}
pub fn num_outer_iterations(&self) -> usize {
self.num_outer_iterations
}
pub fn num_inner_iterations(&self) -> usize {
self.num_inner_iterations
}
pub fn lagrange_multipliers(&self) -> &Option<Vec<f64>> {
&self.lagrange_multipliers
}
pub fn last_problem_norm_fpr(&self) -> f64 {
self.last_problem_norm_fpr
}
pub fn solve_time(&self) -> std::time::Duration {
self.solve_time
}
pub fn penalty(&self) -> f64 {
self.penalty
}
pub fn delta_y_norm_over_c(&self) -> f64 {
let c = self.penalty();
self.delta_y_norm / if c < 1.0 { 1.0 } else { c }
}
pub fn f2_norm(&self) -> f64 {
self.f2_norm
}
pub fn cost(&self) -> f64 {
self.cost
}
}