From 67f5f70d3334fe0b5f56460807fea5c7d2466076 Mon Sep 17 00:00:00 2001
From: Brandon Rodriguez <brodriguez8774@gmail.com>
Date: Thu, 28 Nov 2019 19:57:57 -0500
Subject: [PATCH] Correct objective function output for right aligned display

---
 resources/simplex/base.py | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/resources/simplex/base.py b/resources/simplex/base.py
index 802a7fa..a0a03bd 100644
--- a/resources/simplex/base.py
+++ b/resources/simplex/base.py
@@ -488,26 +488,31 @@ class SimplexBase():
             logger.info('')
 
         # Print objective function.
-        print_string = ' Max: '
+        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):
-                    print_string += ' = {0:>5} '.format(-self._vector_c[index])
+                    if self._vector_c[index] >= 0:
+                        # Coefficient is negative.
+                        print_string += ' {0:>5}'.format('-{0}'.format(self._vector_c[index]))
+                    else:
+                        # Coefficient is positive.
+                        print_string += ' {0:>5}'.format('+{0}'.format(-self._vector_c[index]))
                 else:
                     if self._vector_c[index] == 0:
                         # Coefficient is 0. Print nothing.
                         print_string += '         '
-                    elif self._vector_c[index] < 0:
+                    elif self._vector_c[index] > 0:
                         # Coefficient is negative.
                         print_string += ' {0:>5} x{1}'.format(
-                            '-{0}'.format(-self._vector_c[index]),
+                            '+{0}'.format(self._vector_c[index]),
                             index + 1,
                         )
                     else:
                         # Coefficient is positive.
                         print_string += ' {0:>5} x{1}'.format(
-                            '+{0}'.format(self._vector_c[index]),
+                            '-{0}'.format(-self._vector_c[index]),
                             index + 1,
                         )
         logger.info(print_string)
-- 
GitLab