Skip to main content

pounce_algorithm/hess/
exact.rs

1//! Exact Hessian — port of `IpExactHessianUpdater.{hpp,cpp}`.
2//! Pulls `eval_h` from the NLP at every iterate via
3//! `IpoptCalculatedQuantities::curr_exact_hessian` and stashes the
4//! result into `IpoptData::w`.
5
6use crate::hess::r#trait::HessianUpdater;
7use crate::ipopt_cq::IpoptCqHandle;
8use crate::ipopt_data::IpoptDataHandle;
9
10pub struct ExactHessianUpdater;
11
12impl ExactHessianUpdater {
13    pub fn new() -> Self {
14        Self
15    }
16}
17
18impl Default for ExactHessianUpdater {
19    fn default() -> Self {
20        Self::new()
21    }
22}
23
24impl HessianUpdater for ExactHessianUpdater {
25    fn update_hessian(&mut self, data: &IpoptDataHandle, cq: &IpoptCqHandle) -> bool {
26        let w = cq.borrow().curr_exact_hessian();
27        data.borrow_mut().w = Some(w);
28        true
29    }
30
31    fn provides_exact_hessian(&self) -> bool {
32        true
33    }
34
35    /// A pure evaluation at the current iterate; `data.w` is untouched.
36    fn hessian_at_current(
37        &mut self,
38        _data: &IpoptDataHandle,
39        cq: &IpoptCqHandle,
40    ) -> Option<std::rc::Rc<dyn pounce_linalg::SymMatrix>> {
41        Some(cq.borrow().curr_exact_hessian())
42    }
43}