2
2
Contain `linprog_simplex`, a Numba-jitted linear programming solver
3
3
based on the Simplex Method.
4
4
5
- The formulation of linear program `linprog_simplex` assumes is:
5
+ The formulation of linear program that `linprog_simplex` assumes is:
6
6
7
7
maximize::
8
8
16
16
17
17
Examples
18
18
--------
19
- 1. A problem inequality constraints:
19
+ 1. A problem with inequality constraints:
20
20
21
21
.. math::
22
22
49
49
>>> res.lambd
50
50
array([0.45, 0.25, 1.1 ])
51
51
52
- 2. A problem equality constraints:
52
+ 2. A problem with equality constraints:
53
53
54
54
.. math::
55
55
99
99
100
100
.. math::
101
101
102
- \max_{z_0, z_1, z_2}\ \ & z_0 + z_1 - 4z_2 \\
103
- \mbox{such that}\ \ & -3z_0 - 3z_1 + z_2 \leq 9, \\
104
- & z_0 + z_1 + 2z_2 \leq -2 , \\
102
+ \max_{z_0, z_1, z_2}\ \ & z_0 - z_1 - 4z_2 \\
103
+ \mbox{such that}\ \ & -3z_0 + 3z_1 + z_2 \leq 9, \\
104
+ & z_0 - z_1 + 2z_2 \leq 10 , \\
105
105
& z_0, z_1, z_2 \geq 0.
106
106
107
107
Solve the latter problem with `linprog_simplex`:
108
108
109
- >>> c = np.array([1, 1, -4])
110
- >>> A = np.array([[-3, - 3, 1], [1, 1, 2]])
109
+ >>> c = np.array([1, - 1, -4])
110
+ >>> A = np.array([[-3, 3, 1], [1, - 1, 2]])
111
111
>>> b = np.array([9, 10])
112
112
>>> res = linprog_simplex(c, A_ub=A, b_ub=b)
113
113
114
114
The optimal value of the original problem:
115
115
116
- >>> -(res.fun + 12) # -(z_0 + z_1 - 4 (z_2 - 3))
117
- -22.0
116
+ >>> -(res.fun + 12) # -(z_0 - z_1 - 4 (z_2 - 3))
117
+ -21.999999999999996
118
118
119
119
And the solution found:
120
120
121
121
>>> res.x[0] - res.x[1], res.x[2] - 3 # (z_0 - z_1, z_2 - 3)
122
- (10.0, -3.0)
122
+ (np.float64(9.999999999999998), np.float64( -3.0) )
123
123
124
124
"""
125
125
from collections import namedtuple
@@ -192,7 +192,7 @@ def linprog_simplex(c, A_ub=np.empty((0, 0)), b_ub=np.empty((0,)),
192
192
ndarray of shape (k,).
193
193
194
194
max_iter : int, optional(default=10**6)
195
- Maximum number of iteration to perform.
195
+ Maximum number of iterations to perform.
196
196
197
197
piv_options : PivOptions, optional
198
198
PivOptions namedtuple to set the following tolerance values:
@@ -204,7 +204,7 @@ def linprog_simplex(c, A_ub=np.empty((0, 0)), b_ub=np.empty((0,)),
204
204
Pivot tolerance (default={TOL_PIV}).
205
205
206
206
tol_ratio_diff : float
207
- Tolerance used in the the lexicographic pivoting
207
+ Tolerance used in the lexicographic pivoting
208
208
(default={TOL_RATIO_DIFF}).
209
209
210
210
tableau : ndarray(float, ndim=2), optional
0 commit comments