X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2FLinearProgramming.py;h=2e949d252bd65e18e175a9068d73c9cbc97a32e1;hb=d22e45b4d10c354f84e1de5ef92b6725675817f2;hp=71d02ffca6df6baef185d47ecfa62551201c7acb;hpb=ade85ef1d6cea62110e02a426f84042edd6613b9;p=dead%2Fcensus-tools.git diff --git a/src/LinearProgramming.py b/src/LinearProgramming.py index 71d02ff..2e949d2 100644 --- a/src/LinearProgramming.py +++ b/src/LinearProgramming.py @@ -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,10 +11,10 @@ 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 lp_solve import * +from lpsolve55 import * # Constants representing the two types of linear programs. @@ -318,3 +319,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)