Pivots on value on the intersection of pivot row and column. >>> Tableau(np.array([[-2,-3,0,0,0],[1,3,1,0,4],[3,1,0,1,4.]]), ... 2, 2).pivot(1, 0).tolist() ... # doctest: +NORMALIZE_WHITESPACE [[0.0, 3.0, 2.0, 0.0, 8.0], [1.0, 3.0, 1.0, 0.0, 4.0], [0.
(self, row_idx: int, col_idx: int)
| 147 | return row_idx, col_idx |
| 148 | |
| 149 | def pivot(self, row_idx: int, col_idx: int) -> np.ndarray: |
| 150 | """Pivots on value on the intersection of pivot row and column. |
| 151 | |
| 152 | >>> Tableau(np.array([[-2,-3,0,0,0],[1,3,1,0,4],[3,1,0,1,4.]]), |
| 153 | ... 2, 2).pivot(1, 0).tolist() |
| 154 | ... # doctest: +NORMALIZE_WHITESPACE |
| 155 | [[0.0, 3.0, 2.0, 0.0, 8.0], |
| 156 | [1.0, 3.0, 1.0, 0.0, 4.0], |
| 157 | [0.0, -8.0, -3.0, 1.0, -8.0]] |
| 158 | """ |
| 159 | # Avoid changes to original tableau |
| 160 | piv_row = self.tableau[row_idx].copy() |
| 161 | |
| 162 | piv_val = piv_row[col_idx] |
| 163 | |
| 164 | # Entry becomes 1 |
| 165 | piv_row *= 1 / piv_val |
| 166 | |
| 167 | # Variable in pivot column becomes basic, ie the only non-zero entry |
| 168 | for idx, coeff in enumerate(self.tableau[:, col_idx]): |
| 169 | self.tableau[idx] += -coeff * piv_row |
| 170 | self.tableau[row_idx] = piv_row |
| 171 | return self.tableau |
| 172 | |
| 173 | def change_stage(self) -> np.ndarray: |
| 174 | """Exits first phase of the two-stage method by deleting artificial |