pub struct LoweringContext<'a> { /* private fields */ }Expand description
One solve’s immutable model metadata and lazy expression decompositions.
Original IDs, expressions, bounds and activity flags are retained. Native ordering, capability checks and generated entities belong to the adapter. Create a fresh preparation after model or parameter changes. Resident solver handles should retain their native state, not this borrowed view.
Implementations§
Source§impl<'a> LoweringContext<'a>
impl<'a> LoweringContext<'a>
Sourcepub fn new(model: &'a Model) -> Result<Self, SolverError>
pub fn new(model: &'a Model) -> Result<Self, SolverError>
Validate the objective declaration and capture the current parameter values.
§Errors
Returns a core error if neither an objective nor feasibility was declared.
pub fn variables(&self) -> &[Variable]
pub fn constraints(&self) -> &ModelConstraints<'a>
pub fn objective(&self) -> Option<&Objective>
pub fn kind(&self) -> ModelKind
pub fn sense(&self) -> ObjectiveSense
Sourcepub fn nonlinear_error(
&self,
expr: ExprId,
location: impl Into<String>,
) -> SolverError
pub fn nonlinear_error( &self, expr: ExprId, location: impl Into<String>, ) -> SolverError
Explain an unsupported expression using original variable names.
Sourcepub fn require_linear(
&self,
expr: ExprId,
location: impl FnOnce() -> String,
) -> Result<AffineTerms<'_>, SolverError>
pub fn require_linear( &self, expr: ExprId, location: impl FnOnce() -> String, ) -> Result<AffineTerms<'_>, SolverError>
Require an affine expression.
§Errors
Returns a named nonlinear-expression error when extraction fails.
Sourcepub fn require_linear_once(
&self,
expr: ExprId,
location: impl FnOnce() -> String,
) -> Result<LinearTerms<'_>, SolverError>
pub fn require_linear_once( &self, expr: ExprId, location: impl FnOnce() -> String, ) -> Result<LinearTerms<'_>, SolverError>
Require an affine expression for a one-use streaming consumer.
This bypasses reuse admission and returns the expression crate’s native
borrowed/owned representation. Prefer Self::require_linear when the
same root is likely to be requested again during this preparation.
§Errors
Returns a lazily named nonlinear-expression error when extraction fails.
Sourcepub fn require_quadratic(
&self,
expr: ExprId,
location: impl FnOnce() -> String,
) -> Result<Extracted<QuadraticTerms>, SolverError>
pub fn require_quadratic( &self, expr: ExprId, location: impl FnOnce() -> String, ) -> Result<Extracted<QuadraticTerms>, SolverError>
Require a polynomial of degree at most two.
§Errors
Returns a named nonlinear-expression error when extraction fails.
Sourcepub fn require_polynomial(
&self,
expr: ExprId,
location: impl FnOnce() -> String,
) -> Result<PolynomialTerms<'_>, SolverError>
pub fn require_polynomial( &self, expr: ExprId, location: impl FnOnce() -> String, ) -> Result<PolynomialTerms<'_>, SolverError>
Require a polynomial while retaining the direct-affine borrowed path. Non-direct nodes are traversed once as quadratics, avoiding a failed affine pass before quadratic/SOC handling.
§Errors
Returns a lazily named nonlinear-expression error when extraction fails.
Sourcepub fn detected_soc(&self, row: &Constraint) -> Option<SocForm>
pub fn detected_soc(&self, row: &Constraint) -> Option<SocForm>
An optional alternative, never a replacement for the original row.
Methods from Deref<Target = PreparedExpressions>§
pub fn arena(&self) -> &ExprArena
Sourcepub fn linear(&self, expr: ExprId) -> Option<AffineTerms<'_>>
pub fn linear(&self, expr: ExprId) -> Option<AffineTerms<'_>>
Direct affine nodes retain their zero-copy path. Reused compound roots may be cached, including failed extractions, within this snapshot’s budget.
§Panics
Panics for an expression outside this arena or a poisoned cache.
Sourcepub fn quadratic(&self, expr: ExprId) -> Option<Extracted<QuadraticTerms>>
pub fn quadratic(&self, expr: ExprId) -> Option<Extracted<QuadraticTerms>>
Extract a quadratic polynomial, sharing terms only after observed reuse.
§Panics
Panics for an expression outside this arena or a poisoned cache.
Sourcepub fn detected_soc(
&self,
variables: &[Variable],
row: &Constraint,
) -> Option<SocForm>
pub fn detected_soc( &self, variables: &[Variable], row: &Constraint, ) -> Option<SocForm>
Detect an optional cone representation using cached polynomial terms.
Sourcepub fn explicit_soc(&self, soc: &SocConstraint) -> Result<SocForm, SolverError>
pub fn explicit_soc(&self, soc: &SocConstraint) -> Result<SocForm, SolverError>
Extract an explicit cone in one streaming pass over its affine members.
§Errors
Returns a backend error for invalid affine cone members.
Methods from Deref<Target = ExprArena>§
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
pub fn get(&self, id: ExprId) -> &ExprNode
pub fn nodes(&self) -> &[ExprNode]
pub fn num_params(&self) -> usize
Sourcepub fn param_value(&self, p: ParamId) -> f64
pub fn param_value(&self, p: ParamId) -> f64
Current value bound to parameter p.
§Panics
Panics if p was not allocated by Self::new_param on this arena.
Sourcepub fn try_param_value(&self, p: ParamId) -> Option<f64>
pub fn try_param_value(&self, p: ParamId) -> Option<f64>
Look up the value of p, returning None if p is out of range.
Trait Implementations§
Source§impl<'a> Debug for LoweringContext<'a>
impl<'a> Debug for LoweringContext<'a>
Auto Trait Implementations§
impl<'a> !Freeze for LoweringContext<'a>
impl<'a> !RefUnwindSafe for LoweringContext<'a>
impl<'a> !Send for LoweringContext<'a>
impl<'a> !Sync for LoweringContext<'a>
impl<'a> !UnwindSafe for LoweringContext<'a>
impl<'a> Unpin for LoweringContext<'a>
impl<'a> UnsafeUnpin for LoweringContext<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more