Given the final tableau, add the corresponding values of the basic decision variables to the `output_dict` >>> {key: float(value) for key, value in Tableau(np.array([ ... [0,0,0.875,0.375,5], ... [0,1,0.375,-0.125,1], ... [1,0,-0.125,0.375,1] ... ]),2,
(self)
| 305 | return {} |
| 306 | |
| 307 | def interpret_tableau(self) -> dict[str, float]: |
| 308 | """Given the final tableau, add the corresponding values of the basic |
| 309 | decision variables to the `output_dict` |
| 310 | >>> {key: float(value) for key, value in Tableau(np.array([ |
| 311 | ... [0,0,0.875,0.375,5], |
| 312 | ... [0,1,0.375,-0.125,1], |
| 313 | ... [1,0,-0.125,0.375,1] |
| 314 | ... ]),2, 0).interpret_tableau().items()} |
| 315 | {'P': 5.0, 'x1': 1.0, 'x2': 1.0} |
| 316 | """ |
| 317 | # P = RHS of final tableau |
| 318 | output_dict = {"P": abs(self.tableau[0, -1])} |
| 319 | |
| 320 | for i in range(self.n_vars): |
| 321 | # Gives indices of nonzero entries in the ith column |
| 322 | nonzero = np.nonzero(self.tableau[:, i]) |
| 323 | n_nonzero = len(nonzero[0]) |
| 324 | |
| 325 | # First entry in the nonzero indices |
| 326 | nonzero_rowidx = nonzero[0][0] |
| 327 | nonzero_val = self.tableau[nonzero_rowidx, i] |
| 328 | |
| 329 | # If there is only one nonzero value in column, which is one |
| 330 | if n_nonzero == 1 and nonzero_val == 1: |
| 331 | rhs_val = self.tableau[nonzero_rowidx, -1] |
| 332 | output_dict[self.col_titles[i]] = rhs_val |
| 333 | return output_dict |
| 334 | |
| 335 | |
| 336 | if __name__ == "__main__": |