lumix.solution.solution.LXSolution

class lumix.solution.solution.LXSolution(objective_value, status, solve_time, variables=<factory>, mapped=<factory>, shadow_prices=<factory>, reduced_costs=<factory>, gap=None, iterations=None, nodes=None, goal_deviations=<factory>)[source]

Type-safe solution with automatic mapping.

Provides access to:

  • Variable values (by name or LXVariable object)

  • Mapped values (variables mapped by index keys)

  • Shadow prices (dual values for constraints)

  • Reduced costs (for sensitivity analysis)

Examples

Basic usage:

solution = optimizer.solve(model)

# Access by variable name
prod_value = solution.variables["production"]

# Access by LXVariable object
prod_value = solution.get_variable(production)

# Access multi-indexed variables
duty_value = solution.variables["duty"][(driver_id, date)]

# Access mapped values (indexed by keys)
for key, value in solution.get_mapped(duty).items():
    if value > 0.5:
        print(f"Variable {key} = {value}")
Parameters:
__init__(objective_value, status, solve_time, variables=<factory>, mapped=<factory>, shadow_prices=<factory>, reduced_costs=<factory>, gap=None, iterations=None, nodes=None, goal_deviations=<factory>)
Parameters:
Return type:

None

Methods

__init__(objective_value, status, solve_time)

get_goal_deviations(goal_name)

Get deviation values for a goal constraint.

get_mapped(var)

Get values mapped by index keys.

get_reduced_cost(var_name)

Get reduced cost for variable.

get_shadow_price(constraint_name)

Get shadow price (dual value) for constraint.

get_total_deviation(goal_name)

Get total absolute deviation for a goal.

get_variable(var)

Get variable value with full type inference.

is_feasible()

Check if solution is feasible.

is_goal_satisfied(goal_name[, tolerance])

Check if a goal is satisfied within tolerance.

is_optimal()

Check if solution is optimal.

summary()

Get solution summary.

visualize([model])

Create interactive visualization for this solution.

Attributes

objective_value: float
status: str
solve_time: float
variables: Dict[str, Union[float, Dict[Any, float]]]
mapped: Dict[str, Dict[Any, float]]
shadow_prices: Dict[str, float]
reduced_costs: Dict[str, float]
gap: Optional[float] = None
iterations: Optional[int] = None
nodes: Optional[int] = None
goal_deviations: Dict[str, Dict[str, Union[float, Dict[Any, float]]]]
get_variable(var)[source]

Get variable value with full type inference.

Parameters:

var (LXVariable[TypeVar(TModel), TypeVar(TValue, int, float)]) – LXVariable to get value for

Return type:

Union[TypeVar(TValue, int, float), Dict[Any, TypeVar(TValue, int, float)]]

Returns:

Variable value (scalar or dict for indexed variables)

get_mapped(var)[source]

Get values mapped by index keys.

Returns the same structure as variables, indexed by the keys extracted via the variable’s index_func (e.g., product.id).

Note

This returns index keys, not model instances, to avoid hashability issues with non-frozen dataclasses.

Parameters:

var (LXVariable[TypeVar(TModel), TypeVar(TValue, int, float)]) – LXVariable to get mapped values for

Return type:

Dict[Any, TypeVar(TValue, int, float)]

Returns:

Dictionary mapping index keys to values

Examples

For production indexed by product.id:

for product_id, qty in solution.get_mapped(production).items():
    print(f"Product {product_id}: {qty} units")
get_shadow_price(constraint_name)[source]

Get shadow price (dual value) for constraint.

Parameters:

constraint_name (str) – Constraint name

Return type:

Optional[float]

Returns:

Shadow price if available

get_reduced_cost(var_name)[source]

Get reduced cost for variable.

Parameters:

var_name (str) – Variable name

Return type:

Optional[float]

Returns:

Reduced cost if available

get_goal_deviations(goal_name)[source]

Get deviation values for a goal constraint.

Returns both positive and negative deviations for the specified goal.

Parameters:

goal_name (str) – Name of the goal constraint

Return type:

Optional[Dict[str, Union[float, Dict[Any, float]]]]

Returns:

Dictionary with keys ‘pos’ and ‘neg’ containing deviation values, or None if goal not found

Example

>>> deviations = solution.get_goal_deviations("production_target")
>>> pos_dev = deviations["pos"]  # Over-production
>>> neg_dev = deviations["neg"]  # Under-production
is_goal_satisfied(goal_name, tolerance=1e-06)[source]

Check if a goal is satisfied within tolerance.

A goal is satisfied if both positive and negative deviations are within the specified tolerance.

Parameters:
  • goal_name (str) – Name of the goal constraint

  • tolerance (float) – Tolerance for deviation (default: 1e-6)

Return type:

Optional[bool]

Returns:

True if goal is satisfied, False if not, None if goal not found

Example

>>> if solution.is_goal_satisfied("demand_goal", tolerance=0.01):
...     print("Demand goal achieved!")
get_total_deviation(goal_name)[source]

Get total absolute deviation for a goal.

Sum of absolute values of all positive and negative deviations.

Parameters:

goal_name (str) – Name of the goal constraint

Return type:

Optional[float]

Returns:

Total deviation, or None if goal not found

Example

>>> total_dev = solution.get_total_deviation("production_target")
>>> print(f"Total deviation: {total_dev}")
is_optimal()[source]

Check if solution is optimal.

Return type:

bool

is_feasible()[source]

Check if solution is feasible.

Return type:

bool

visualize(model=None)[source]

Create interactive visualization for this solution.

Requires the visualization extra: pip install lumix-opt[viz]

Parameters:

model (Optional[LXModel[TypeVar(TModel)]]) – Optional optimization model (for constraint info)

Return type:

LXSolutionVisualizer[TypeVar(TModel)]

Returns:

LXSolutionVisualizer instance

Examples

Basic usage:

solution.visualize().show()

With model for constraint details:

solution.visualize(model).show()

Export to HTML:

solution.visualize(model).to_html("solution.html")
summary()[source]

Get solution summary.

Return type:

str

Returns:

String summary

__init__(objective_value, status, solve_time, variables=<factory>, mapped=<factory>, shadow_prices=<factory>, reduced_costs=<factory>, gap=None, iterations=None, nodes=None, goal_deviations=<factory>)
Parameters:
Return type:

None