Add iteration-count accessors to SolvedModel#45
Conversation
| let status = | ||
| unsafe { Highs_getIntInfoValue(self.highs.unsafe_mut_ptr(), name.as_ptr(), value) }; | ||
| try_handle_status(status, "Highs_getIntInfoValue") | ||
| .map(|_| i64::from(*value)) | ||
| .unwrap() | ||
| } |
There was a problem hiding this comment.
can this fail in normal operations ? if yes, then return a Result. Otherwise, use expect instead of unwrap, and explain why this can't fail clearly
There was a problem hiding this comment.
Highs_getIntInfoValue returns kError in only two cases, an unknown info name or a name whose info isn't HighsInt-typed. Both depend only on the name argument. Every caller passes a valid HighsInt key (c"simplex_iteration_count", etc.), so the only way to trigger it is a code change that introduces a bad literal.
I based this accessor based on others in the library, for example mip_gap, primal_solution_status. Should we also switch to an expect there or is it fine as it is?
There was a problem hiding this comment.
If the safety boundary is in the callers, let's put the .expect(...) there. int_info_value can be public, return a Result, and document when it returns an error. The accessor functions can be trusted and not return a Result because the parameter they pass is trusted
There was a problem hiding this comment.
Done, and extended the same to the existing mip_gap()/primal_solution_status().
lovasoa
left a comment
There was a problem hiding this comment.
excellent, great contribution, thanks @GermanHeim !
After a solve, HiGHS exposes per-algorithm iteration counts through its solution-info values (
simplex_iteration_count,ipm_iteration_count, etc.).Right now, there's no safe way to read them: a caller has to reach for
SolvedModel::as_mut_ptr()and call the rawHighs_getIntInfoValueFFI itself.With this PR, we add five new public methods on
SolvedModel, mirroring the existing accessors:simplex_iteration_count(),ipm_iteration_count(),qp_iteration_count(),pdlp_iteration_count(), andcrossover_iteration_count().I also addeda small private
int_info_value(name)helper that wrapsHighs_getIntInfoValue+try_handle_status.