lumix.solvers.base.LXOptimizer

class lumix.solvers.base.LXOptimizer(orm=None)[source]

Main optimizer with full generic support.

Provides high-level interface to: - Select solver - Configure rational conversion - Enable sensitivity analysis - Solve models

Examples

optimizer = LXOptimizer[Product](orm_context)

.use_solver(“gurobi”) .enable_sensitivity() .enable_rational_conversion()

solution = optimizer.solve(model)

Parameters:

orm (LXORMContext[TModel] | None)

__init__(orm=None)[source]

Initialize optimizer.

Parameters:

orm (Optional[LXORMContext[TypeVar(TModel)]]) – Optional ORM context for data access

Methods

__init__([orm])

Initialize optimizer.

enable_linearization([big_m, pwl_segments, ...])

Enable automatic linearization for nonlinear terms.

enable_rational_conversion([max_denom])

Enable float-to-rational conversion.

enable_sensitivity()

Enable sensitivity analysis.

solve(model, **solver_params)

Solve with full type safety.

use_solver(name, **kwargs)

Set solver with literal type checking.

__init__(orm=None)[source]

Initialize optimizer.

Parameters:

orm (Optional[LXORMContext[TypeVar(TModel)]]) – Optional ORM context for data access

use_solver(name, **kwargs)[source]

Set solver with literal type checking.

Parameters:

name (Literal['ortools', 'gurobi', 'cplex', 'cpsat', 'glpk']) – Solver name (“ortools”, “gurobi”, “cplex”, “cpsat”, “glpk”)

Return type:

Self

Returns:

Self for chaining

enable_rational_conversion(max_denom=10000)[source]

Enable float-to-rational conversion.

Parameters:

max_denom (int) – Maximum denominator for rational approximation

Return type:

Self

Returns:

Self for chaining

enable_linearization(big_m=1000000.0, pwl_segments=20, pwl_method='sos2', prefer_sos2=True, adaptive_breakpoints=True, mccormick_tighten_bounds=True, **kwargs)[source]

Enable automatic linearization for nonlinear terms.

Mirrors enable_rational_conversion() API pattern for consistency.

When enabled, the optimizer will automatically:

  • Detect nonlinear terms in the model

  • Check if solver lacks native support

  • Apply appropriate linearization techniques:

    • Binary × Binary: AND logic

    • Binary × Continuous: Big-M method

    • Continuous × Continuous: McCormick envelopes

    • Piecewise-linear approximations for exp, log, sin, cos, etc.

Parameters:
  • big_m (float) – Big-M constant for conditional constraints (default: 1e6)

  • pwl_segments (int) – Number of segments for piecewise-linear approximations (default: 20)

  • pwl_method (Literal['sos2', 'incremental', 'logarithmic']) – Method for PWL (“sos2”, “incremental”, “logarithmic”)

  • prefer_sos2 (bool) – Use SOS2 formulation when solver supports it (default: True)

  • adaptive_breakpoints (bool) – Use adaptive breakpoint generation for PWL (default: True)

  • mccormick_tighten_bounds (bool) – Apply bound tightening for McCormick envelopes (default: True)

  • **kwargs (Any) – Additional linearization configuration options

Return type:

Self

Returns:

Self for chaining

Example:

optimizer = (
    LXOptimizer[Product]()
    .use_solver("ortools")
    .enable_linearization(
        big_m=1e5,
        pwl_segments=30,
        adaptive_breakpoints=True
    )
)

solution = optimizer.solve(model)
enable_sensitivity()[source]

Enable sensitivity analysis.

Return type:

Self

Returns:

Self for chaining

solve(model, **solver_params)[source]

Solve with full type safety.

Parameters:
  • model (LXModel[TypeVar(TModel)]) – LXModel to solve

  • **solver_params (Any) – Solver-specific parameters

Return type:

LXSolution[TypeVar(TModel)]

Returns:

Type-safe solution

Raises: