use pounce_common::types::{Index, Number};
use pounce_linalg::{DenseVector, Matrix, SymMatrix, Vector};
use std::rc::Rc;
#[derive(Debug, Clone, Default)]
pub struct SplitNames {
pub x_var: Vec<Option<String>>,
pub eq: Vec<Option<String>>,
pub ineq: Vec<Option<String>>,
}
impl SplitNames {
pub fn any_present(&self) -> bool {
self.x_var
.iter()
.chain(self.eq.iter())
.chain(self.ineq.iter())
.any(Option::is_some)
}
}
pub trait Nlp {
fn n(&self) -> Index;
fn m_eq(&self) -> Index;
fn m_ineq(&self) -> Index;
fn eval_f(&mut self, x: &dyn Vector) -> Number;
fn eval_grad_f(&mut self, x: &dyn Vector, g: &mut dyn Vector);
fn eval_c(&mut self, x: &dyn Vector, c: &mut dyn Vector);
fn eval_d(&mut self, x: &dyn Vector, d: &mut dyn Vector);
fn eval_jac_c(&mut self, x: &dyn Vector) -> Rc<dyn Matrix>;
fn eval_jac_d(&mut self, x: &dyn Vector) -> Rc<dyn Matrix>;
fn eval_h(
&mut self,
x: &dyn Vector,
obj_factor: Number,
y_c: &dyn Vector,
y_d: &dyn Vector,
) -> Rc<dyn SymMatrix>;
}
pub trait IpoptNlp: Nlp {
fn x_l(&self) -> &dyn Vector;
fn x_u(&self) -> &dyn Vector;
fn d_l(&self) -> &dyn Vector;
fn d_u(&self) -> &dyn Vector;
fn px_l(&self) -> Rc<dyn Matrix>;
fn px_u(&self) -> Rc<dyn Matrix>;
fn pd_l(&self) -> Rc<dyn Matrix>;
fn pd_u(&self) -> Rc<dyn Matrix>;
fn adjust_variable_bounds(
&mut self,
_new_x_l: &dyn Vector,
_new_x_u: &dyn Vector,
_new_d_l: &dyn Vector,
_new_d_u: &dyn Vector,
) {
}
fn get_starting_x(&mut self, _x: &mut dyn Vector) -> bool {
true
}
fn get_starting_y(&mut self, _y_c: &mut dyn Vector, _y_d: &mut dyn Vector) -> bool {
true
}
#[allow(clippy::too_many_arguments)]
fn get_starting_z(
&mut self,
_z_l: &mut dyn Vector,
_z_u: &mut dyn Vector,
_v_l: &mut dyn Vector,
_v_u: &mut dyn Vector,
) -> bool {
true
}
fn lift_x_to_full(&self, x: &dyn Vector) -> Vec<Number> {
let dx = x
.as_any()
.downcast_ref::<DenseVector>()
.expect("IpoptNlp::lift_x_to_full expects DenseVector");
dx.expanded_values().to_vec()
}
fn pack_lambda_for_user(&self, _y_c: &dyn Vector, _y_d: &dyn Vector) -> Vec<Number> {
Vec::new()
}
fn pack_g_for_user(&self, _c: &dyn Vector, _d: &dyn Vector) -> Vec<Number> {
Vec::new()
}
fn pack_z_l_for_user(&self, _z_l: &dyn Vector) -> Vec<Number> {
Vec::new()
}
fn pack_z_u_for_user(&self, _z_u: &dyn Vector) -> Vec<Number> {
Vec::new()
}
fn n_full_x(&self) -> Index {
0
}
fn n_full_g(&self) -> Index {
0
}
fn finalize_solution_lambda(&self, _y_c: &dyn Vector, _y_d: &dyn Vector) -> Vec<Number> {
Vec::new()
}
fn finalize_solution_z_l(&self, _z_l: &dyn Vector) -> Vec<Number> {
Vec::new()
}
fn finalize_solution_z_u(&self, _z_u: &dyn Vector) -> Vec<Number> {
Vec::new()
}
fn full_x_to_var_x(&self, full_idx: Index) -> Option<Index> {
Some(full_idx)
}
fn full_g_to_c_block(&self, full_idx: Index) -> Option<Index> {
Some(full_idx)
}
fn var_x_to_full_x(&self, var_idx: Index) -> Index {
var_idx
}
fn obj_scaling_factor(&self) -> Number {
1.0
}
fn split_space_names(&self) -> Option<SplitNames> {
None
}
}