diff --git a/resources/simplex/pivot.py b/resources/simplex/pivot.py index bf097bb938da0189a6484d8bb87cc50314894043..37479f51cbcc1df291895edd51ab9fb61c920de6 100644 --- a/resources/simplex/pivot.py +++ b/resources/simplex/pivot.py @@ -8,7 +8,6 @@ Author: Brandon Rodriguez Implementation of the "Pivot" function for Linear Programming Simplex problems. """ - # System Imports. import copy @@ -119,6 +118,10 @@ class Pivot(): # 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]] + # Truncate if can be represented as int. + if vector_b[new_basic[0]] % 1 == 0: + vector_b[new_basic[0]] = int(vector_b[new_basic[0]]) + # Loop through all nonbasic indexes (minus the one we're adding). Adjust coefficients in matrix. for col_index in n_array: @@ -201,13 +204,13 @@ class Pivot(): # Remove new basic variable from set of nonbasics. n_array.remove(new_basic[1]) - # Add new nonbasic variable to set of nonbasics. - n_array.append(old_basic[1]) + # Add new nonbasic variable to set of nonbasics, making sure we put it in the proper equation index. + n_array.insert(old_basic[0], old_basic[1]) # Remove new nonbasic variable from set of basics. b_array.remove(old_basic[1]) - # Add new basic variable to set of basics. - b_array.append(new_basic[1]) + # Add new basic variable to set of basics, making sure we put it in the proper equation index. + b_array.insert(new_basic[0], new_basic[1]) return (n_array, b_array)