]> gitweb.michael.orlitzky.com - dead/census-tools.git/blobdiff - src/LinearProgramming.py
Added a setter for the type property.
[dead/census-tools.git] / src / LinearProgramming.py
index 5f4668a705d1e3972f42433ff045fa27ee427e71..d779dc00aaad47cf1c05a56bf4b7d475b83d4223 100644 (file)
@@ -3,6 +3,7 @@ Classes to create, solve, and make dinner for linear programs. Handles
 integration with lp_solve.
 """
 
+import fractions
 import os
 import site
 import sys
@@ -10,7 +11,7 @@ import sys
 # Add LP_SOLVE_PATH to our path. There is no point to this variable
 # other than to make the site.addsitedir() line fit within 80
 # characters.
-LP_SOLVE_PATH = '/../lib/lp_solve'
+LP_SOLVE_PATH = '/../../lib/lp_solve'
 site.addsitedir(os.path.dirname(os.path.abspath(sys.argv[0])) + LP_SOLVE_PATH)
 
 from lpsolve55 import *
@@ -58,7 +59,7 @@ class LinearProgram(object):
         """
         return self._type
 
-
+    @type.setter
     def type(self, type):
         if type == MINIMIZE:
             self._type = MINIMIZE
@@ -215,6 +216,15 @@ class LinearProgram(object):
 
 
 
+    def print_tableau(self):
+        """
+        Tell lp_solve to print its simplex tableau. Only works after
+        a successful call to solve().
+        """
+        lpsolve('set_outputfile', self._lp, '')
+        lpsolve('print_tableau', self._lp)
+
+
     def __init__(self):
         """
         Initialize the object, setting all of the properties
@@ -318,3 +328,10 @@ class LinearProgram(object):
             [obj, x, duals, ret] = lpsolve('get_solution', self._lp)
 
         return [obj, x, duals]
+
+
+    def objective_coefficient_gcd(self):
+        """
+        Return the GCD of all objective function coefficients.
+        """
+        return reduce(fractions.gcd, self.objective_coefficients)