diff --git a/resources/simplex/pivot.py b/resources/simplex/pivot.py index 4fc9be60bfd9523c84e00bb714c9ebbf3fd7433c..bae9f3ea0bea42521dbea5552f73a87878c2c179 100644 --- a/resources/simplex/pivot.py +++ b/resources/simplex/pivot.py @@ -41,6 +41,7 @@ class Pivot(): self._basic_var_indexes = self._parent._basic_var_indexes self._nonbasic_var_indexes = self._parent._nonbasic_var_indexes + # Run pivot function. return self.pivot(old_basic_col, new_basic_col) def pivot(self, old_basic_col, new_basic_col): @@ -80,7 +81,6 @@ class Pivot(): # Compute coefficients of all remaining constraints. matrix_a, vector_b = self._compute_coefficients( n_array, - b_array, matrix_a, vector_b, old_basic, @@ -90,8 +90,6 @@ class Pivot(): # Compute updated objective function. vector_c, obj_const_index = self._update_objective( n_array, - matrix_a, - vector_b, vector_c, obj_const_index, old_basic, @@ -110,13 +108,12 @@ class Pivot(): def _calculate_new_basic(self, n_array, matrix_a, vector_b, old_basic, new_basic): """ - Compute coefficients for the new basic variable x_e. - :param n_array: - :param matrix_a: - :param vector_b: - :param old_basic: - :param new_basic: - :return: + Computes coefficients for the constraint equation with the new basic variable. + :param n_array: Array of all non-basic variable col indexes. + :param matrix_a: Matrix of variable coefficients for constraint equations. + :param vector_b: Vector of constants for constraint equations. + :param old_basic: Tuple of (row, col) index values for old basic variable. + :param new_basic: Tuple of (row, col) index values of the new basic variable. """ # Calculate our new constraint constant. vector_b[new_basic[0]] = self._vector_b[new_basic[0]] / self._matrix_a[old_basic[0]][new_basic[1]] @@ -142,16 +139,14 @@ class Pivot(): return (matrix_a, vector_b) - def _compute_coefficients(self, n_array, b_array, matrix_a, vector_b, old_basic, new_basic): + def _compute_coefficients(self, n_array, matrix_a, vector_b, old_basic, new_basic): """ - Compute coefficients of all remaining constraints. - :param n_array: - :param b_array: - :param matrix_a: - :param vector_b: - :param old_basic: - :param new_basic: - :return: + Computes coefficients for all constraint equations that don't hold the new basic variable. + :param n_array: Array of all non-basic variable col indexes. + :param matrix_a: Matrix of variable coefficients for constraint equations. + :param vector_b: Vector of constants for constraint equations. + :param old_basic: Tuple of (row, col) index values for old basic variable. + :param new_basic: Tuple of (row, col) index values of the new basic variable. """ # Loop through all basic indexes (minus the one we're removing). Adjust coefficients in matrix. for row_index in range(len(vector_b)): @@ -172,17 +167,14 @@ class Pivot(): return (matrix_a, vector_b) - def _update_objective(self, n_array, matrix_a, vector_b, vector_c, obj_const_index, old_basic, new_basic): + def _update_objective(self, n_array, vector_c, obj_const_index, old_basic, new_basic): """ - Compute updated objective function. - :param n_array: - :param matrix_a: - :param vector_b: - :param vector_c: - :param obj_const_index: - :param old_basic: - :param new_basic: - :return: + Computes updated objective function. + :param n_array: Array of all non-basic variable col indexes. + :param vector_c: Vector of objective function coefficients and constant. + :param obj_const_index: Index of constant in vector_c. + :param old_basic: Tuple of (row, col) index values for old basic variable. + :param new_basic: Tuple of (row, col) index values of the new basic variable. """ # Update objective constant. vector_c[self._obj_constant_index] = self._vector_c[self._obj_constant_index] - (self._vector_b[new_basic[0]] * self._vector_c[new_basic[1]]) @@ -199,12 +191,11 @@ class Pivot(): def _compute_basic_sets(self, n_array, b_array, old_basic, new_basic): """ - Compute the new sets of basic and nonbasic variables. - :param n_array: - :param b_array: - :param old_basic: - :param new_basic: - :return: + Computes the new sets of basic and nonbasic variables. + :param n_array: Array of all non-basic variable col indexes. + :param b_array: Array of all basic variable col indexes. + :param old_basic: Tuple of (row, col) index values for old basic variable. + :param new_basic: Tuple of (row, col) index values of the new basic variable. """ # Remove new basic variable from set of nonbasics. n_array.remove(new_basic[1])