Skip to content

Add iteration-count accessors to SolvedModel#45

Merged
lovasoa merged 3 commits into
rust-or:mainfrom
GermanHeim:iterations
Jun 15, 2026
Merged

Add iteration-count accessors to SolvedModel#45
lovasoa merged 3 commits into
rust-or:mainfrom
GermanHeim:iterations

Conversation

@GermanHeim

Copy link
Copy Markdown
Contributor

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 raw Highs_getIntInfoValue FFI 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(), and crossover_iteration_count().

I also addeda small private int_info_value(name) helper that wraps Highs_getIntInfoValue + try_handle_status.

Comment thread src/lib.rs Outdated
Comment thread src/lib.rs
Comment on lines +1026 to +1031
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()
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, and extended the same to the existing mip_gap()/primal_solution_status().

@lovasoa lovasoa left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

excellent, great contribution, thanks @GermanHeim !

@lovasoa lovasoa merged commit b71e097 into rust-or:main Jun 15, 2026
2 checks passed
@GermanHeim GermanHeim deleted the iterations branch June 15, 2026 16:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants