gtopt/lp_cache.hpp file

LpCache — post-solve scalar + vector cache for LinearInterface.

LpCache owns the 9 post-solve cache fields that previously lived directly on LinearInterface as m_cached_*_. Extraction is Phase 1 of the LinearInterface split.

Lifecycle:

  • Default-constructed: all empty / zero / nullopt / false.
  • After a successful solve: scalars (obj_value, kappa, numrows, numcols) are set, is_optimal is true, backend_solution_fresh is true, and the three vectors hold the post-solve primal / dual values (compress mode only — under LowMemoryMode::off the live backend is the source of truth and the vectors stay empty).
  • On structural mutation: invalidate_optimal_on_mutation() flips is_optimal to false; the vectors are not touched (callers may still read them via the empty-fallback path used by cut-construction code after backend release).
  • On backend reconstruct: mark_solution_fresh(false) — scalars + vectors stay; only the "live backend has fresh solution" gate is cleared until the next resolve() lands.

Invariants (asserted in debug, see validate_consistency()):

  • C1. is_optimal() ⇒ col_sol().size() == numcols().
  • C2. invalidate_optimal_on_mutation() is idempotent and does NOT clear the col_sol / col_cost / row_dual vectors.
  • C3. drop_solution_caches() clears col_sol + col_cost, leaves row_dual and the scalars intact.
  • C4. set_is_optimal(true) is the only path that flips the optimality flag to true.
  • C5. mark_solution_fresh(true) fires inside timed_solve before the optimality check; mark_solution_fresh(false) fires on every reconstruct_backend().
  • C6. size_bytes() reports the total bytes held by the three vectors.
  • C7. col_sol_buffer(n) / col_cost_buffer(n) / row_dual_buffer(n) resize the underlying vector and return a span over it — the only write entry- point that backends use via SolverBackend::fill_*.
  • C8. Default-constructed LpCache{} reports is_optimal() == false, obj_value() == 0.0, numrows() == 0, numcols() == 0, kappa() == std::nullopt, all spans empty.

Namespaces

namespace gtopt

Classes

class gtopt::LpCache
Post-solve cache for LinearInterface.