diff --git a/resources/simplex/base.py b/resources/simplex/base.py index a0a03bd728447b63d3828ccf6fb766d70ed20e19..2a9583b154eb37da74a81337f515b4bac52d5a6f 100644 --- a/resources/simplex/base.py +++ b/resources/simplex/base.py @@ -488,29 +488,33 @@ class SimplexBase(): logger.info('') # Print objective function. - print_string = ' Max: z= ' + print_string = ' Max: z = ' for index in range(len(self._vector_c)): if index not in self._b_array: + # Check if last index. if index == (len(self._vector_c) - 1): + # Is objective function constant if self._vector_c[index] >= 0: - # Coefficient is negative. + # Constant is negative. print_string += ' {0:>5}'.format('-{0}'.format(self._vector_c[index])) else: - # Coefficient is positive. + # Constant is positive. print_string += ' {0:>5}'.format('+{0}'.format(-self._vector_c[index])) + else: + # Is objective function coefficient. if self._vector_c[index] == 0: # Coefficient is 0. Print nothing. print_string += ' ' elif self._vector_c[index] > 0: - # Coefficient is negative. + # Coefficient is positive. print_string += ' {0:>5} x{1}'.format( '+{0}'.format(self._vector_c[index]), index + 1, ) else: - # Coefficient is positive. + # Coefficient is negative. print_string += ' {0:>5} x{1}'.format( '-{0}'.format(-self._vector_c[index]), index + 1, @@ -562,20 +566,20 @@ class SimplexBase(): #region Child Class Functions - def solve(self): + def solve(self, debug=False): """ Solves simplex. :return: Solution, in format of (max_value, location of max value). """ - return self._run_simplex() + return self._run_simplex(debug=debug) - def initialize(self): + def initialize(self, debug=False): """ Initializes simplex. """ - self._initialize() + self._initialize(debug=debug) - def pivot(self, old_basic_index, new_basic_index): + 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. @@ -586,7 +590,11 @@ class SimplexBase(): 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) + 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