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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
/* pounce.h — C API for the POUNCE nonlinear interior-point solver.
*
* Drop-in replacement for Ipopt 3.14's `IpStdCInterface.h`. Every
* function name, argument list, and return code matches upstream so a
* caller linking against libipopt can swap to libpounce_cinterface
* without source changes.
*
* Quick-start (C):
*
* #include "pounce.h"
*
* IpoptProblem nlp = CreateIpoptProblem(
* n, x_L, x_U, m, g_L, g_U,
* nele_jac, nele_hess, 0,
* eval_f, eval_g, eval_grad_f, eval_jac_g, eval_h);
* AddIpoptNumOption(nlp, "tol", 1e-8);
* AddIpoptIntOption(nlp, "max_iter", 500);
* enum ApplicationReturnStatus status = IpoptSolve(
* nlp, x, NULL, &obj, NULL, NULL, NULL, user_data);
* FreeIpoptProblem(nlp);
*
* Build & link example (macOS):
*
* cargo build --release -p pounce-cinterface
* cc app.c -I crates/pounce-cinterface/include \
* -L target/release -lpounce_cinterface \
* -Wl,-rpath,target/release -o app
*/
/* -----------------------------------------------------------------
* Version
* ----------------------------------------------------------------- */
extern "C" TRUE
/** Opaque handle to a pounce problem. */
;
typedef struct IpoptProblemInfo* IpoptProblem;
/** Pointer for arbitrary caller state passed to every callback. */
typedef void* UserDataPtr;
/* -----------------------------------------------------------------
* Callback signatures (identical to Ipopt C API).
* All callbacks return true on success, false on error.
* `new_x` / `new_lambda` indicate whether x / lambda changed since
* the last call.
*
* Jacobian / Hessian callbacks are dispatched in two modes:
* values == NULL → fill iRow/jCol with the sparsity pattern
* values != NULL → fill values in the same element order
* ----------------------------------------------------------------- */
typedef bool ;
typedef bool ;
typedef bool ;
typedef bool ;
typedef bool ;
typedef bool ;
/* -----------------------------------------------------------------
* Lifecycle
* ----------------------------------------------------------------- */
/** Allocate a new problem handle.
*
* n number of primal variables
* x_L/x_U variable lower/upper bounds (length n; ±1e19 for ±∞)
* m number of constraints
* g_L/g_U constraint lower/upper bounds (length m)
* nele_jac number of nonzeros in the Jacobian
* nele_hess number of nonzeros in the lower-triangular Hessian
* index_style 0 = C (0-based indices), 1 = Fortran (1-based)
* eval_* callback function pointers
*
* Returns NULL on invalid arguments (negative dims, missing required
* callbacks, NULL bound pointers when the corresponding dim > 0). */
IpoptProblem ;
/** Free a problem handle. After this call the pointer is invalid. */
void ;
/* -----------------------------------------------------------------
* Options
* Each Add*Option function returns true on success, false if the
* keyword is unknown or the value violates registered bounds.
* ----------------------------------------------------------------- */
bool ;
bool ;
bool ;
/** Open a file to receive solver output at `print_level`. Equivalent
* to setting the `output_file` and `file_print_level` options and
* attaching a journalist FileJournal. */
bool ;
/** Install user-provided NLP scaling. Pass NULL for `x_scaling` or
* `g_scaling` to leave that axis unscaled. Set option
* `nlp_scaling_method = user-scaling` for the scaling to take
* effect. */
bool ;
/* -----------------------------------------------------------------
* Intermediate callback
* ----------------------------------------------------------------- */
/** Install (or remove, with cb == NULL) a per-iteration callback.
* Returning false from the callback signals
* ApplicationReturnStatus::User_Requested_Stop. */
bool ;
/* -----------------------------------------------------------------
* Solve
*
* problem handle from CreateIpoptProblem()
* x [in/out] initial point (length n) → primal solution
* g [out] constraint values g(x*), or NULL to skip
* obj_val [out] objective f(x*), or NULL to skip
* mult_g [out] constraint multipliers λ (length m), or NULL
* mult_x_L [out] lower-bound multipliers z_L (length n), or NULL
* mult_x_U [out] upper-bound multipliers z_U (length n), or NULL
* user_data forwarded unmodified to every callback
*
* Returns an ApplicationReturnStatus (see IpoptReturnCodes.h).
* ----------------------------------------------------------------- */
enum ApplicationReturnStatus ;
/* -----------------------------------------------------------------
* Inspection (valid only during the intermediate callback)
*
* These mirror Ipopt 3.14's GetIpoptCurrent* functions. Pass NULL for
* any output buffer to skip retrieving it. They return false until
* pounce's algorithm core invokes the intermediate callback per
* iteration (currently a follow-up — the signature is here so callers
* can link against it today).
* ----------------------------------------------------------------- */
bool ;
bool ;
/* -----------------------------------------------------------------
* Library info
* ----------------------------------------------------------------- */
/** Get the pounce version as `major.minor.release`. Any pointer may
* be NULL to skip that component. */
void ;
/* -----------------------------------------------------------------
* Pounce extensions — post-solve statistics
*
* Convenience accessors not present in upstream Ipopt's C API. All are
* valid only after IpoptSolve() has returned; they yield zero before
* the first solve.
* ----------------------------------------------------------------- */
/** Number of IPM iterations in the most recent solve. */
ipindex ;
/** Wall-clock solve time in seconds from the most recent solve. */
ipnumber ;
/** Final primal infeasibility from the most recent solve. */
ipnumber ;
/** Final dual infeasibility from the most recent solve. */
ipnumber ;
/** Final complementarity error from the most recent solve. */
ipnumber ;
} /* extern "C" */
/* POUNCE_H */