@@ -107,8 +107,8 @@ def generate_col_titles(self) -> list[str]:
107
107
108
108
def find_pivot (self ) -> tuple [Any , Any ]:
109
109
"""Finds the pivot row and column.
110
- >>> Tableau(np.array([[-2,1,0,0,0], [3,1,1,0,6], [1,2,0,1,7.]]) ,
111
- ... 2, 0).find_pivot()
110
+ >>> tuple(int(x) for x in Tableau(np.array([[-2,1,0,0,0], [3,1,1,0,6],
111
+ ... [1,2,0,1,7.]]), 2, 0).find_pivot() )
112
112
(1, 0)
113
113
"""
114
114
objective = self .objectives [- 1 ]
@@ -215,56 +215,56 @@ def run_simplex(self) -> dict[Any, Any]:
215
215
Max: x1 + x2
216
216
ST: x1 + 3x2 <= 4
217
217
3x1 + x2 <= 4
218
- >>> Tableau(np.array([[-1,-1,0,0,0],[1,3,1,0,4],[3,1,0,1,4.]]) ,
219
- ... 2, 0).run_simplex()
218
+ >>> {key: float(value) for key, value in Tableau(np.array([[-1,-1,0,0,0],
219
+ ... [1,3,1,0,4],[3,1,0,1,4.]]), 2, 0).run_simplex().items()}
220
220
{'P': 2.0, 'x1': 1.0, 'x2': 1.0}
221
221
222
222
# Standard linear program with 3 variables:
223
223
Max: 3x1 + x2 + 3x3
224
224
ST: 2x1 + x2 + x3 ≤ 2
225
225
x1 + 2x2 + 3x3 ≤ 5
226
226
2x1 + 2x2 + x3 ≤ 6
227
- >>> Tableau(np.array([
227
+ >>> {key: float(value) for key, value in Tableau(np.array([
228
228
... [-3,-1,-3,0,0,0,0],
229
229
... [2,1,1,1,0,0,2],
230
230
... [1,2,3,0,1,0,5],
231
231
... [2,2,1,0,0,1,6.]
232
- ... ]),3,0).run_simplex() # doctest: +ELLIPSIS
232
+ ... ]),3,0).run_simplex().items()} # doctest: +ELLIPSIS
233
233
{'P': 5.4, 'x1': 0.199..., 'x3': 1.6}
234
234
235
235
236
236
# Optimal tableau input:
237
- >>> Tableau(np.array([
237
+ >>> {key: float(value) for key, value in Tableau(np.array([
238
238
... [0, 0, 0.25, 0.25, 2],
239
239
... [0, 1, 0.375, -0.125, 1],
240
240
... [1, 0, -0.125, 0.375, 1]
241
- ... ]), 2, 0).run_simplex()
241
+ ... ]), 2, 0).run_simplex().items()}
242
242
{'P': 2.0, 'x1': 1.0, 'x2': 1.0}
243
243
244
244
# Non-standard: >= constraints
245
245
Max: 2x1 + 3x2 + x3
246
246
ST: x1 + x2 + x3 <= 40
247
247
2x1 + x2 - x3 >= 10
248
248
- x2 + x3 >= 10
249
- >>> Tableau(np.array([
249
+ >>> {key: float(value) for key, value in Tableau(np.array([
250
250
... [2, 0, 0, 0, -1, -1, 0, 0, 20],
251
251
... [-2, -3, -1, 0, 0, 0, 0, 0, 0],
252
252
... [1, 1, 1, 1, 0, 0, 0, 0, 40],
253
253
... [2, 1, -1, 0, -1, 0, 1, 0, 10],
254
254
... [0, -1, 1, 0, 0, -1, 0, 1, 10.]
255
- ... ]), 3, 2).run_simplex()
255
+ ... ]), 3, 2).run_simplex().items()}
256
256
{'P': 70.0, 'x1': 10.0, 'x2': 10.0, 'x3': 20.0}
257
257
258
258
# Non standard: minimisation and equalities
259
259
Min: x1 + x2
260
260
ST: 2x1 + x2 = 12
261
261
6x1 + 5x2 = 40
262
- >>> Tableau(np.array([
262
+ >>> {key: float(value) for key, value in Tableau(np.array([
263
263
... [8, 6, 0, 0, 52],
264
264
... [1, 1, 0, 0, 0],
265
265
... [2, 1, 1, 0, 12],
266
266
... [6, 5, 0, 1, 40.],
267
- ... ]), 2, 2).run_simplex()
267
+ ... ]), 2, 2).run_simplex().items()}
268
268
{'P': 7.0, 'x1': 5.0, 'x2': 2.0}
269
269
270
270
@@ -275,15 +275,15 @@ def run_simplex(self) -> dict[Any, Any]:
275
275
2x1 + 4x2 <= 48
276
276
x1 + x2 >= 10
277
277
x1 >= 2
278
- >>> Tableau(np.array([
278
+ >>> {key: float(value) for key, value in Tableau(np.array([
279
279
... [2, 1, 0, 0, 0, -1, -1, 0, 0, 12.0],
280
280
... [-8, -6, 0, 0, 0, 0, 0, 0, 0, 0.0],
281
281
... [1, 3, 1, 0, 0, 0, 0, 0, 0, 33.0],
282
282
... [4, 2, 0, 1, 0, 0, 0, 0, 0, 60.0],
283
283
... [2, 4, 0, 0, 1, 0, 0, 0, 0, 48.0],
284
284
... [1, 1, 0, 0, 0, -1, 0, 1, 0, 10.0],
285
285
... [1, 0, 0, 0, 0, 0, -1, 0, 1, 2.0]
286
- ... ]), 2, 2).run_simplex() # doctest: +ELLIPSIS
286
+ ... ]), 2, 2).run_simplex().items()} # doctest: +ELLIPSIS
287
287
{'P': 132.0, 'x1': 12.000... 'x2': 5.999...}
288
288
"""
289
289
# Stop simplex algorithm from cycling.
@@ -307,11 +307,11 @@ def run_simplex(self) -> dict[Any, Any]:
307
307
def interpret_tableau (self ) -> dict [str , float ]:
308
308
"""Given the final tableau, add the corresponding values of the basic
309
309
decision variables to the `output_dict`
310
- >>> Tableau(np.array([
310
+ >>> {key: float(value) for key, value in Tableau(np.array([
311
311
... [0,0,0.875,0.375,5],
312
312
... [0,1,0.375,-0.125,1],
313
313
... [1,0,-0.125,0.375,1]
314
- ... ]),2, 0).interpret_tableau()
314
+ ... ]),2, 0).interpret_tableau().items()}
315
315
{'P': 5.0, 'x1': 1.0, 'x2': 1.0}
316
316
"""
317
317
# P = RHS of final tableau
0 commit comments