use super::ffi::*;
use super::{cones::Cone, CoreSettings, ScalingStrategy, SettingsError};
use super::{SolverStatus, StepDirection};
use crate::algebra::*;
use crate::timers::*;
pub trait ProblemData<T: FloatT> {
type V: Variables<T>;
type C: Cone<T>;
type SE: Settings<T>;
fn equilibrate(&mut self, cones: &Self::C, settings: &Self::SE);
}
pub trait Variables<T: FloatT> {
type D: ProblemData<T>;
type R: Residuals<T>;
type C: Cone<T>;
type SE: Settings<T>;
fn calc_mu(&mut self, residuals: &Self::R, cones: &Self::C) -> T;
fn affine_step_rhs(&mut self, residuals: &Self::R, variables: &Self, cones: &Self::C);
#[allow(clippy::too_many_arguments)]
fn combined_step_rhs(
&mut self,
residuals: &Self::R,
variables: &Self,
cones: &mut Self::C,
step: &mut Self, σ: T,
μ: T,
m: T,
);
fn calc_step_length(
&self,
step_lhs: &Self,
cones: &mut Self::C,
settings: &Self::SE,
step_direction: StepDirection,
) -> T;
fn add_step(&mut self, step_lhs: &Self, α: T);
fn symmetric_initialization(&mut self, cones: &mut Self::C);
fn unit_initialization(&mut self, cones: &Self::C);
fn copy_from(&mut self, src: &Self);
fn scale_cones(&self, cones: &mut Self::C, μ: T, scaling_strategy: ScalingStrategy) -> bool;
fn barrier(&self, step: &Self, α: T, cones: &mut Self::C) -> T;
fn rescale(&mut self);
}
pub trait Residuals<T: FloatT> {
type D: ProblemData<T>;
type V: Variables<T>;
fn update(&mut self, variables: &Self::V, data: &Self::D);
}
pub trait KKTSystem<T: FloatT> {
type D: ProblemData<T>;
type V: Variables<T>;
type C: Cone<T>;
type SE: Settings<T>;
fn update(&mut self, data: &Self::D, cones: &Self::C, settings: &Self::SE) -> bool;
#[allow(clippy::too_many_arguments)]
fn solve(
&mut self,
step_lhs: &mut Self::V,
step_rhs: &Self::V,
data: &Self::D,
variables: &Self::V,
cones: &mut Self::C,
step_direction: StepDirection,
settings: &Self::SE,
) -> bool;
fn solve_initial_point(
&mut self,
variables: &mut Self::V,
data: &Self::D,
settings: &Self::SE,
) -> bool;
}
pub trait InfoPrint<T>
where
T: FloatT,
{
type D: ProblemData<T>;
type C: Cone<T>;
type SE: Settings<T>;
fn print_target(&mut self) -> &mut dyn std::io::Write;
fn print_configuration(
&mut self,
settings: &Self::SE,
data: &Self::D,
cones: &Self::C,
) -> std::io::Result<()>;
fn print_status_header(&mut self, settings: &Self::SE) -> std::io::Result<()>;
fn print_status(&mut self, settings: &Self::SE) -> std::io::Result<()>;
fn print_footer(&mut self, settings: &Self::SE) -> std::io::Result<()>;
}
pub trait Info<T>: InfoPrint<T> + ClarabelFFI<Self> + Sized + Clone
where
T: FloatT,
{
type V: Variables<T>;
type R: Residuals<T>;
fn reset(&mut self, timers: &mut Timers);
fn post_process(&mut self, residuals: &Self::R, settings: &Self::SE);
fn finalize(&mut self, timers: &mut Timers);
fn update(
&mut self,
data: &mut Self::D,
variables: &Self::V,
residuals: &Self::R,
timers: &Timers,
);
fn check_termination(&mut self, residuals: &Self::R, settings: &Self::SE, iter: u32) -> bool;
fn save_prev_iterate(&mut self, variables: &Self::V, prev_variables: &mut Self::V);
fn reset_to_prev_iterate(&mut self, variables: &mut Self::V, prev_variables: &Self::V);
fn save_scalars(&mut self, μ: T, α: T, σ: T, iter: u32);
fn get_status(&self) -> SolverStatus;
fn set_status(&mut self, status: SolverStatus);
}
pub trait Solution<T: FloatT> {
type D: ProblemData<T>;
type V: Variables<T>;
type I: Info<T>;
type SE: Settings<T>;
fn post_process(
&mut self,
data: &Self::D,
variables: &mut Self::V,
info: &Self::I,
settings: &Self::SE,
);
fn finalize(&mut self, info: &Self::I);
}
pub trait Settings<T: FloatT>: ClarabelFFI<Self> + Sized + Clone {
fn core(&self) -> &CoreSettings<T>;
fn core_mut(&mut self) -> &mut CoreSettings<T>;
fn validate(&self) -> Result<(), SettingsError>;
fn validate_as_update(&self, prev: &Self) -> Result<(), SettingsError>;
}