1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
//! # pounce-rs — solve nonlinear programs with POUNCE from Rust
//!
//! POUNCE's solver lives across several crates (`pounce-nlp` for the
//! [`TNLP`] problem trait, `pounce-algorithm` for the [`IpoptApplication`]
//! driver, `pounce-common` for the scalar types). This crate is a thin
//! **facade**: it re-exports everything needed to define and solve a problem,
//! so a Rust user depends on one crate and writes `use pounce_rs::prelude::*;`
//! — the Rust counterpart to the one-import `import pounce` Python API.
//!
//! It is re-exports only (no logic of its own), and it pins a single curated
//! public surface, so downstream code is insulated from churn in the internal
//! crate layout.
//!
//! ## Example: HS071 (Hock–Schittkowski problem 71)
//!
//! ```text
//! min x1*x4*(x1 + x2 + x3) + x3
//! s.t. x1*x2*x3*x4 >= 25
//! x1^2 + x2^2 + x3^2 + x4^2 == 40
//! 1 <= xi <= 5
//! ```
//!
//! ```
//! use pounce_rs::prelude::*;
//! use std::cell::RefCell;
//! use std::rc::Rc;
//!
//! #[derive(Default)]
//! struct Hs071 {
//! obj: Option<f64>,
//! x: Option<[f64; 4]>,
//! }
//!
//! impl TNLP for Hs071 {
//! fn get_nlp_info(&mut self) -> Option<NlpInfo> {
//! Some(NlpInfo { n: 4, m: 2, nnz_jac_g: 8, nnz_h_lag: 10, index_style: IndexStyle::C })
//! }
//!
//! fn get_bounds_info(&mut self, b: BoundsInfo<'_>) -> bool {
//! b.x_l.copy_from_slice(&[1.0; 4]);
//! b.x_u.copy_from_slice(&[5.0; 4]);
//! b.g_l.copy_from_slice(&[25.0, 40.0]); // g0 >= 25, g1 == 40
//! b.g_u.copy_from_slice(&[2.0e19, 40.0]);
//! true
//! }
//!
//! fn get_starting_point(&mut self, sp: StartingPoint<'_>) -> bool {
//! sp.x.copy_from_slice(&[1.0, 5.0, 5.0, 1.0]);
//! true
//! }
//!
//! fn eval_f(&mut self, x: &[f64], _new_x: bool) -> Option<f64> {
//! Some(x[0] * x[3] * (x[0] + x[1] + x[2]) + x[2])
//! }
//!
//! fn eval_grad_f(&mut self, x: &[f64], _new_x: bool, g: &mut [f64]) -> bool {
//! g[0] = x[3] * (2.0 * x[0] + x[1] + x[2]);
//! g[1] = x[0] * x[3];
//! g[2] = x[0] * x[3] + 1.0;
//! g[3] = x[0] * (x[0] + x[1] + x[2]);
//! true
//! }
//!
//! fn eval_g(&mut self, x: &[f64], _new_x: bool, g: &mut [f64]) -> bool {
//! g[0] = x[0] * x[1] * x[2] * x[3];
//! g[1] = x[0] * x[0] + x[1] * x[1] + x[2] * x[2] + x[3] * x[3];
//! true
//! }
//!
//! fn eval_jac_g(&mut self, x: Option<&[f64]>, _new_x: bool, mode: SparsityRequest<'_>) -> bool {
//! match mode {
//! SparsityRequest::Structure { irow, jcol } => {
//! irow.copy_from_slice(&[0, 0, 0, 0, 1, 1, 1, 1]);
//! jcol.copy_from_slice(&[0, 1, 2, 3, 0, 1, 2, 3]);
//! }
//! SparsityRequest::Values { values } => {
//! let x = x.unwrap();
//! values.copy_from_slice(&[
//! x[1] * x[2] * x[3], x[0] * x[2] * x[3], x[0] * x[1] * x[3], x[0] * x[1] * x[2],
//! 2.0 * x[0], 2.0 * x[1], 2.0 * x[2], 2.0 * x[3],
//! ]);
//! }
//! }
//! true
//! }
//!
//! fn eval_h(&mut self, x: Option<&[f64]>, _new_x: bool, of: f64,
//! lambda: Option<&[f64]>, _new_lambda: bool, mode: SparsityRequest<'_>) -> bool {
//! match mode {
//! SparsityRequest::Structure { irow, jcol } => {
//! irow.copy_from_slice(&[0, 1, 1, 2, 2, 2, 3, 3, 3, 3]);
//! jcol.copy_from_slice(&[0, 0, 1, 0, 1, 2, 0, 1, 2, 3]);
//! }
//! SparsityRequest::Values { values } => {
//! let x = x.unwrap();
//! let l = lambda.unwrap();
//! values.copy_from_slice(&[
//! of * (2.0 * x[3]) + l[1] * 2.0,
//! of * x[3] + l[0] * (x[2] * x[3]),
//! l[1] * 2.0,
//! of * x[3] + l[0] * (x[1] * x[3]),
//! l[0] * (x[0] * x[3]),
//! l[1] * 2.0,
//! of * (2.0 * x[0] + x[1] + x[2]) + l[0] * (x[1] * x[2]),
//! of * x[0] + l[0] * (x[0] * x[2]),
//! of * x[0] + l[0] * (x[0] * x[1]),
//! l[1] * 2.0,
//! ]);
//! }
//! }
//! true
//! }
//!
//! fn finalize_solution(&mut self, sol: Solution<'_>, _d: &IpoptData, _q: &IpoptCq) {
//! self.obj = Some(sol.obj_value);
//! self.x = Some([sol.x[0], sol.x[1], sol.x[2], sol.x[3]]);
//! }
//! }
//!
//! let mut app = IpoptApplication::new();
//! app.initialize().unwrap();
//! let prob = Rc::new(RefCell::new(Hs071::default()));
//! let status = app.optimize_tnlp(Rc::clone(&prob) as Rc<RefCell<dyn TNLP>>);
//!
//! assert_eq!(status, ApplicationReturnStatus::SolveSucceeded);
//! let obj = prob.borrow().obj.unwrap();
//! assert!((obj - 17.014_017).abs() < 1e-4); // known optimum
//! ```
//!
//! ## Solve statistics and the iteration trajectory
//!
//! Every [`builder::Nlp::solve`] fills [`Solution::stats`](builder::Solution)
//! with the solve's [`SolveStatistics`] (wall time, iteration count,
//! evaluation counts, final infeasibilities) and the solution carries the
//! constraint values `g` and bound multipliers `z_l`/`z_u`. Opt in to the
//! per-iteration trajectory with `.capture_iterations()`.
//!
//! ```
//! use pounce_rs::prelude::*;
//!
//! struct Quad; // min (x0-1)^2 + (x1-2)^2 s.t. x0 + x1 == 3
//! impl Problem for Quad {
//! fn objective(&self, x: &[f64]) -> f64 {
//! (x[0] - 1.0).powi(2) + (x[1] - 2.0).powi(2)
//! }
//! fn n_constraints(&self) -> usize {
//! 1
//! }
//! fn constraints(&self, x: &[f64], g: &mut [f64]) {
//! g[0] = x[0] + x[1];
//! }
//! }
//!
//! let sol = Nlp::new(Quad)
//! .var_bounds(&[0.0, 0.0], &[5.0, 5.0])
//! .constraint_bounds(&[3.0], &[3.0])
//! .capture_iterations()
//! .solve();
//! assert!(sol.success);
//! assert!(sol.stats.iteration_count > 0);
//! assert!(sol.stats.total_wallclock_time_secs > 0.0);
//! assert!(!sol.stats.iterations.is_empty()); // one record per iteration
//! ```
//!
//! For solves outside the builder, [`with_iter_capture`] wraps any closure
//! with capture active and returns the recorded [`IterRecord`]s alongside
//! the closure's result. For the [`IpoptApplication`] path, install
//! [`collector_scope`] for the duration of the solve and read the history
//! back from `statistics()`:
//! `let _scope = collector_scope(); app.enable_iter_history(); …`.
// --- scalar types -----------------------------------------------------------
pub use ;
// --- the problem trait and its supporting types -----------------------------
pub use ;
pub use ;
// --- the solver driver ------------------------------------------------------
pub use IpoptApplication;
// --- iteration capture & observability --------------------------------------
// Thread-scoped helpers so an embedding library can record a solve's
// trajectory (and turn on console logs) with no direct `tracing` deps.
pub use ;
pub use ;
// --- the underlying crates, for anything not surfaced above -----------------
pub use pounce_algorithm;
pub use pounce_common;
pub use pounce_nlp;
pub use pounce_observability;
// --- ergonomic builder API (argmin-style small trait + builder; #168) -------
pub use ;
/// The common case in one glob import. Brings in the ergonomic [`Problem`]
/// trait + [`Nlp`] builder, plus the low-level [`TNLP`] surface and the
/// [`IpoptApplication`] driver for full control.
///
/// ```
/// use pounce_rs::prelude::*;
/// ```