diff --git a/resources/simplex/base.py b/resources/simplex/base.py index 9216b00628f45f8faa5e873abae455dc4bb22451..d8c1a9502474d521517d23fbdb1cc89320a1d44a 100644 --- a/resources/simplex/base.py +++ b/resources/simplex/base.py @@ -63,6 +63,48 @@ class SimplexBase(): self._initialize = Initialize(self, debug=debug) self._pivot = Pivot(self, debug=debug) + # region Child Class Functions + + def solve(self, debug=False): + """ + Solves simplex. + :return: Solution, in format of (max_value, location of max value). + """ + return self._run_simplex(debug=debug) + + def initialize(self, debug=False): + """ + Initializes simplex. + """ + return self._initialize(debug=debug) + + def pivot(self, old_basic_index, new_basic_index, debug=False): + """ + Pivots simplex around provided basic variable indexes. + :param old_basic_index: Index of variable column turning nonbasic. + :param new_basic_index: Index of variable column turning basic. + :return: + """ + if not isinstance(old_basic_index, int) or not isinstance(new_basic_index, int): + raise TypeError('Expected basic variable indexes to be of type int.') + + # Get new values from pivot. + n_array, b_array, matrix_a, vector_b, vector_c, obj_const_index = self._pivot( + old_basic_index, + new_basic_index, + debug=debug, + ) + + # Set new values to class. + self._n_array = n_array + self._b_array = b_array + self._matrix_a = matrix_a + self._vector_b = vector_b + self._vector_c = vector_c + self._obj_constant_index = obj_const_index + + # endregion Child Class Functions + #region Simplex Read in and Setup def read_data_from_json(self, json_file_location): @@ -563,45 +605,3 @@ class SimplexBase(): logger.info('') #endregion Display Functions - - #region Child Class Functions - - def solve(self, debug=False): - """ - Solves simplex. - :return: Solution, in format of (max_value, location of max value). - """ - return self._run_simplex(debug=debug) - - def initialize(self, debug=False): - """ - Initializes simplex. - """ - return self._initialize(debug=debug) - - def pivot(self, old_basic_index, new_basic_index, debug=False): - """ - Pivots simplex around provided basic variable indexes. - :param old_basic_index: Index of variable column turning nonbasic. - :param new_basic_index: Index of variable column turning basic. - :return: - """ - if not isinstance(old_basic_index, int) or not isinstance(new_basic_index, int): - raise TypeError('Expected basic variable indexes to be of type int.') - - # Get new values from pivot. - n_array, b_array, matrix_a, vector_b, vector_c, obj_const_index = self._pivot( - old_basic_index, - new_basic_index, - debug=debug, - ) - - # Set new values to class. - self._n_array = n_array - self._b_array = b_array - self._matrix_a = matrix_a - self._vector_b = vector_b - self._vector_c = vector_c - self._obj_constant_index = obj_const_index - - #endregion Child Class Functions