From 7fdd22499845fdbb20f004d564c97172750419b2 Mon Sep 17 00:00:00 2001
From: Brandon Rodriguez <brodriguez8774@gmail.com>
Date: Wed, 27 Nov 2019 00:25:02 -0500
Subject: [PATCH] Fix minor errors in pivot function

---
 resources/simplex/pivot.py | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/resources/simplex/pivot.py b/resources/simplex/pivot.py
index bf097bb..37479f5 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)
-- 
GitLab