tucoopy.diagnostics.linprog_diagnostics¶
Linear-programming (LP) diagnostics and explanations.¶
This module contains small, serialization-friendly helpers to extract a stable subset of information from LP solver results, plus higher-level helpers used by tucoopy to expose LP-based explanations in analysis outputs.
The low-level extractor linprog_diagnostics is designed to work with:
- SciPy/HiGHS
scipy.optimize.linprogresult objects, and - the fallback :class:
tucoopy.backends.lp.LinprogResultwrapper used by the PuLP backend.
Notes
SciPy is an optional dependency in tucoopy. If SciPy (or the configured LP backend) is unavailable, higher-level helpers may raise an ImportError suggesting installing extra dependencies (e.g. pip install "tucoopy[lp]").
Examples:
>>> from tucoopy.diagnostics.linprog_diagnostics import LinprogDiagnostics, explain_linprog
>>> d = LinprogDiagnostics(0, "Optimal", 1.0, [1.0, 2.0], [0.0], [0.0], [0.0])
>>> explain_linprog(d)
['status=0', 'fun=1', 'Optimal']
LinprogDiagnostics dataclass ¶
Diagnostics extracted from SciPy/HiGHS linear programming results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
status | int | Solver status code. | required |
message | str | Solver message. | required |
fun | float | Objective function value. | required |
x | list of float | Solution vector. | required |
ineqlin_residual | list of float | Inequality constraint residuals. | required |
ineqlin_marginals | list of float | Inequality constraint multipliers. | required |
eqlin_marginals | list of float | Equality constraint multipliers. | required |
Methods:
| Name | Description |
|---|---|
to_dict | Returns diagnostics as a dictionary. |
Examples:
>>> d = LinprogDiagnostics(0, "Optimal", 1.0, [1.0, 2.0], [0.0], [0.0], [0.0])
>>> d.to_dict()
{...}
to_dict ¶
to_dict()
Returns diagnostics as a dictionary.
Returns:
| Type | Description |
|---|---|
dict | Dictionary representation of diagnostics. |
Examples:
>>> d = LinprogDiagnostics(0, "Optimal", 1.0, [1.0, 2.0], [0.0], [0.0], [0.0])
>>> d.to_dict()
{...}
build_lp_explanations ¶
build_lp_explanations(game, *, tol=1e-09, max_list=256)
Compute LP-based explanations for cooperative game analysis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
game | Game | Cooperative game instance. | required |
tol | float | Numerical tolerance (default 1e-9). | 1e-09 |
max_list | int | Maximum number of elements in returned lists. | 256 |
Returns:
| Type | Description |
|---|---|
dict | Dictionary with balancedness and least core explanations. |
Examples:
>>> from tucoopy.base.game import Game
>>> from tucoopy.diagnostics.linprog import build_lp_explanations
>>> g = Game.from_coalitions(n_players=2, values={(): 0, (0,): 1, (1,): 1, (0, 1): 2})
>>> build_lp_explanations(g)
{...}
explain_linprog ¶
explain_linprog(diag)
Generates a readable summary for UI/debug of LP diagnostics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
diag | LinprogDiagnostics | Diagnostics extracted from the solver. | required |
Returns:
| Type | Description |
|---|---|
list of str | Lines of textual summary. |
Examples:
>>> diag = LinprogDiagnostics(0, "Optimal", 1.0, [1.0, 2.0], [0.0], [0.0], [0.0])
>>> explain_linprog(diag)
['status=0', 'fun=1', 'Optimal']
linprog_diagnostics ¶
linprog_diagnostics(res)
Extracts a stable subset of diagnostics from SciPy/HiGHS linprog results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
res | Any | Result object from linprog solver. | required |
Returns:
| Type | Description |
|---|---|
LinprogDiagnostics | Diagnostics extracted from the result. |
Examples:
>>> # res = scipy.optimize.linprog(...)
>>> diag = linprog_diagnostics(res)
>>> diag.status
0