diff --git a/resources/simplex/base.py b/resources/simplex/base.py index d8c1a9502474d521517d23fbdb1cc89320a1d44a..c68301c30e75c586de757e9c888db84cb9d6796a 100644 --- a/resources/simplex/base.py +++ b/resources/simplex/base.py @@ -108,6 +108,10 @@ class SimplexBase(): #region Simplex Read in and Setup def read_data_from_json(self, json_file_location): + """ + Attempts to read in data from provided file location. + :param json_file_location: Location to attempt to read from. + """ logger.info('') logger.info('Attempting to read in simplex from file.') @@ -388,11 +392,17 @@ class SimplexBase(): #region Display Functions def display_all_printouts(self): + """ + Prints out all 3 equation types, one after another, for comparison. + """ self.display_tableau() self.display_equations() self.display_right_aligned_equations() def display_tableau(self): + """ + Prints out current problem values in "Tableau" (aka matrix) format. + """ logger.info('') logger.info('Printing Simplex Tableau.') logger.info('') @@ -448,6 +458,9 @@ class SimplexBase(): logger.info('') def display_equations(self): + """ + Prints out current problem values in "Standard Form" (aka equation) format. + """ logger.info('') logger.info('Printing Simplex Equations.') logger.info('') @@ -516,6 +529,9 @@ class SimplexBase(): logger.info('') def display_right_aligned_equations(self): + """ + Prints out current problem values in "right aligned equation form" format. + """ logger.info('') logger.info('Printing Simplex Equations (Right Aligned).') logger.info('') diff --git a/resources/simplex/initialize.py b/resources/simplex/initialize.py index c6eaf0d7b0d0faa1de1293efe22c278c1d0f5ba3..42e74b6b41733c31fb1921e4f92522aa803788c3 100644 --- a/resources/simplex/initialize.py +++ b/resources/simplex/initialize.py @@ -57,6 +57,10 @@ class Initialize(): return results def initialize_simplex(self): + """ + The start of the "Initialize" function. + :return: Bool indicating if problem is feasible. + """ # Determine smallest constant for constraints. smallest_const_index = 0 for index in range(len(self._vector_b)): @@ -75,6 +79,11 @@ class Initialize(): return self._correct_simplex(smallest_const_index) def _correct_simplex(self, smallest_index): + """ + Logic to attempt to find a solvable starting point, if original values aren't solvable. + :param smallest_index: The row index of the smallest constant found. + :return: True if problem has been formatted into a solvable starting point | False if infeasible. + """ # Get values pulled from parent. We make sure we get a new copy and not a reference. matrix_a = copy.deepcopy(self._matrix_a) vector_b = copy.deepcopy(self._vector_b) @@ -176,5 +185,3 @@ class Initialize(): # No solution exists for original simplex. logger.info('Could not determine solution for simplex problem. Problem is likely infeasible.') return False - - diff --git a/resources/simplex/run_simplex.py b/resources/simplex/run_simplex.py index a8329ebf11f9a2aee9f3394cff0b98c1f2308b95..948d3a15fce8b5ec32c9cf17ab6fc7ce7af4b955 100644 --- a/resources/simplex/run_simplex.py +++ b/resources/simplex/run_simplex.py @@ -49,6 +49,10 @@ class RunSimplex(): return results def _start_simplex(self): + """ + Start of full "Simplex" algorithm. + :return: Solution found for problem | False if problem is infeasible. + """ # Run "Initialize-Simplex" function before we do any work. self._parent.initialize() @@ -56,6 +60,11 @@ class RunSimplex(): return self._run_simplex() def _run_simplex(self): + """ + Attempts to run simplex algorithm. + This should only be called after the simplex has been initialized. + :return: Solution found for problem. + """ # Run optimization loop. self._optimization_loop() @@ -130,6 +139,10 @@ class RunSimplex(): self._optimize_on_index(highest_obj_index) def _optimize_on_index(self, col_index): + """ + The part of loop that optimized on the current column index, using a pivot. + :param col_index: Index to optimize on. + """ # Get parent data, after initialized. matrix_a = self._parent._matrix_a