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>)¶
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.
Check if solution is feasible.
is_goal_satisfied(goal_name[, tolerance])Check if a goal is satisfied within tolerance.
Check if solution is optimal.
summary()Get solution summary.
visualize([model])Create interactive visualization for this solution.
Attributes
- 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:
- 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_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:
- 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:
- Return type:
- 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:
- Returns:
Total deviation, or None if goal not found
Example
>>> total_dev = solution.get_total_deviation("production_target") >>> print(f"Total deviation: {total_dev}")
- 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")
- __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>)¶