MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / pivot

Method pivot

linear_programming/simplex.py:149–171  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers 1

run_simplexMethod · 0.95

Calls 1

copyMethod · 0.80

Tested by

no test coverage detected