11from collections .abc import Callable , Sequence
2- from typing import Final , Literal , LiteralString , TypeAlias , TypedDict , overload , type_check_only
2+ from typing import Final , Literal , TypeAlias , TypedDict , overload , type_check_only
33from typing_extensions import deprecated
44
55import numpy as np
@@ -15,11 +15,9 @@ __all__ = ["linprog", "linprog_terse_callback", "linprog_verbose_callback"]
1515
1616_Ignored : TypeAlias = object
1717_Max3 : TypeAlias = Literal [0 , 1 , 2 , 3 ]
18- _Max4 : TypeAlias = Literal [_Max3 , 4 ]
1918
2019_Int : TypeAlias = int | np .int32 | np .int64
2120_Float : TypeAlias = float | np .float64
22- _Float1D : TypeAlias = onp .Array1D [np .float64 ]
2321
2422@type_check_only
2523class _OptionsCommon (TypedDict , total = False ):
@@ -79,21 +77,39 @@ class _OptionsSimplex(_OptionsCommonLegacy, TypedDict, total=False):
7977
8078###
8179
80+ class OptimizeResult (_OptimizeResult ):
81+ x : onp .Array1D [np .float64 ] | None
82+ fun : float | None
83+ slack : onp .Array1D [np .float64 ] | None
84+ con : onp .Array1D [np .float64 ] | None
85+ success : bool
86+ status : Literal [0 , 1 , 2 , 3 , 4 ]
87+ message : str
88+ nit : int
89+
90+ @type_check_only
91+ class _OptimizeResultSensitivity (_OptimizeResult ):
92+ residual : onp .Array1D [np .float64 ]
93+ marginals : onp .Array1D [np .float64 ]
94+
95+ @type_check_only
96+ class _OptimizeResultHighs (OptimizeResult ):
97+ crossover_nit : int
98+ lower : _OptimizeResultSensitivity
99+ upper : _OptimizeResultSensitivity
100+ eqlin : _OptimizeResultSensitivity
101+ ineqlin : _OptimizeResultSensitivity
102+ mip_node_count : int # only exists if `success=True`
103+ mip_dual_bound : float # only exists if `success=True`
104+ mip_gap : float # only exists if `success=True`
105+
106+ ###
107+
82108__docformat__ : Final = "restructuredtext en" # undocumented
83109LINPROG_METHODS : Final [Sequence [MethodLinprog | MethodLinprogLegacy ]] = ... # undocumented
84110
85- class OptimizeResult (_OptimizeResult ):
86- x : _Float1D # minimizing decision variables w.r.t. the constraints
87- fun : _Float # optimal objective function value
88- slack : _Float1D # slack values; nominally positive
89- con : _Float1D # residuals of equality constraints; nominally zero
90- status : _Max4
91- message : LiteralString
92- nit : int # >=0
93- success : bool # `success = status == 0`
94-
95- def linprog_verbose_callback (res : _OptimizeResult ) -> None : ...
96- def linprog_terse_callback (res : _OptimizeResult ) -> None : ...
111+ def linprog_verbose_callback (res : OptimizeResult ) -> None : ...
112+ def linprog_terse_callback (res : OptimizeResult ) -> None : ...
97113
98114#
99115@overload # highs (default)
@@ -105,11 +121,11 @@ def linprog(
105121 b_eq : onp .ToFloat1D | None = None ,
106122 bounds : Bound | Sequence [Bound ] = (0 , None ),
107123 method : Literal ["highs" ] = "highs" ,
108- callback : Callable [[_OptimizeResult ], _Ignored ] | None = None ,
124+ callback : Callable [[OptimizeResult ], _Ignored ] | None = None ,
109125 options : _OptionsHighs | None = None ,
110126 x0 : onp .ToFloat1D | None = None ,
111127 integrality : _Max3 | Sequence [_Max3 ] | onp .CanArrayND [npc .integer ] | None = None ,
112- ) -> _OptimizeResult : ...
128+ ) -> _OptimizeResultHighs : ...
113129@overload # highs-ds
114130def linprog (
115131 c : onp .ToFloat1D ,
@@ -120,11 +136,11 @@ def linprog(
120136 bounds : Bound | Sequence [Bound ] = (0 , None ),
121137 * ,
122138 method : Literal ["highs-ds" ],
123- callback : Callable [[_OptimizeResult ], _Ignored ] | None = None ,
139+ callback : Callable [[OptimizeResult ], _Ignored ] | None = None ,
124140 options : _OptionsHighsDS | None = None ,
125141 x0 : onp .ToFloat1D | None = None ,
126142 integrality : _Max3 | Sequence [_Max3 ] | onp .CanArrayND [npc .integer ] | None = None ,
127- ) -> _OptimizeResult : ...
143+ ) -> _OptimizeResultHighs : ...
128144@overload # highs-ipm
129145def linprog (
130146 c : onp .ToFloat1D ,
@@ -135,11 +151,11 @@ def linprog(
135151 bounds : Bound | Sequence [Bound ] = (0 , None ),
136152 * ,
137153 method : Literal ["highs-ipm" ],
138- callback : Callable [[_OptimizeResult ], _Ignored ] | None = None ,
154+ callback : Callable [[OptimizeResult ], _Ignored ] | None = None ,
139155 options : _OptionsHighsIPM | None = None ,
140156 x0 : onp .ToFloat1D | None = None ,
141157 integrality : _Max3 | Sequence [_Max3 ] | onp .CanArrayND [npc .integer ] | None = None ,
142- ) -> _OptimizeResult : ...
158+ ) -> _OptimizeResultHighs : ...
143159@overload # interior-point (legacy, see https://github.com/scipy/scipy/issues/15707)
144160@deprecated ("`method='interior-point'` is deprecated and will be removed in SciPy 1.17. Please use one of the HIGHS solvers." )
145161def linprog (
@@ -151,11 +167,11 @@ def linprog(
151167 bounds : Bound | Sequence [Bound ] = (0 , None ),
152168 * ,
153169 method : Literal ["interior-point" ],
154- callback : Callable [[_OptimizeResult ], _Ignored ] | None = None ,
170+ callback : Callable [[OptimizeResult ], _Ignored ] | None = None ,
155171 options : _OptionsInteriorPoint | None = None ,
156172 x0 : onp .ToFloat1D | None = None ,
157173 integrality : _Max3 | Sequence [_Max3 ] | onp .CanArrayND [npc .integer ] | None = None ,
158- ) -> _OptimizeResult : ...
174+ ) -> OptimizeResult : ...
159175@overload # revised simplex (legacy, see https://github.com/scipy/scipy/issues/15707)
160176@deprecated ("`method='revised simplex'` is deprecated and will be removed in SciPy 1.17. Please use one of the HIGHS solvers." )
161177def linprog (
@@ -167,11 +183,11 @@ def linprog(
167183 bounds : Bound | Sequence [Bound ] = (0 , None ),
168184 * ,
169185 method : Literal ["revised simplex" ],
170- callback : Callable [[_OptimizeResult ], _Ignored ] | None = None ,
186+ callback : Callable [[OptimizeResult ], _Ignored ] | None = None ,
171187 options : _OptionsRevisedSimplex | None = None ,
172188 x0 : onp .ToFloat1D | None = None ,
173189 integrality : _Max3 | Sequence [_Max3 ] | onp .CanArrayND [npc .integer ] | None = None ,
174- ) -> _OptimizeResult : ...
190+ ) -> OptimizeResult : ...
175191@overload # simplex (legacy, see https://github.com/scipy/scipy/issues/15707)
176192@deprecated ("`method='simplex'` is deprecated and will be removed in SciPy 1.17. Please use one of the HIGHS solvers." )
177193def linprog (
@@ -183,11 +199,11 @@ def linprog(
183199 bounds : Bound | Sequence [Bound ] = (0 , None ),
184200 * ,
185201 method : Literal ["simplex" ],
186- callback : Callable [[_OptimizeResult ], _Ignored ] | None = None ,
202+ callback : Callable [[OptimizeResult ], _Ignored ] | None = None ,
187203 options : _OptionsSimplex | None = None ,
188204 x0 : onp .ToFloat1D | None = None ,
189205 integrality : _Max3 | Sequence [_Max3 ] | onp .CanArrayND [npc .integer ] | None = None ,
190- ) -> _OptimizeResult : ...
206+ ) -> OptimizeResult : ...
191207@overload # any "highs"
192208def linprog (
193209 c : onp .ToFloat1D ,
@@ -197,8 +213,8 @@ def linprog(
197213 b_eq : onp .ToFloat1D | None = None ,
198214 bounds : Bound | Sequence [Bound ] = (0 , None ),
199215 method : MethodLinprog = "highs" ,
200- callback : Callable [[_OptimizeResult ], _Ignored ] | None = None ,
216+ callback : Callable [[OptimizeResult ], _Ignored ] | None = None ,
201217 options : _OptionsHighs | None = None ,
202218 x0 : onp .ToFloat1D | None = None ,
203219 integrality : _Max3 | Sequence [_Max3 ] | onp .CanArrayND [npc .integer ] | None = None ,
204- ) -> _OptimizeResult : ...
220+ ) -> _OptimizeResultHighs : ...
0 commit comments