X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2FLinearProgramming.py;h=7ea144bca77b3d1606a6927f713b542f5d275058;hb=HEAD;hp=ceb2e5fca184f5825720406ef3db6c7a30c6cad4;hpb=9e873928a42a91b468e56bf95217f8504c12dad2;p=dead%2Fcensus-tools.git diff --git a/src/LinearProgramming.py b/src/LinearProgramming.py index ceb2e5f..7ea144b 100644 --- a/src/LinearProgramming.py +++ b/src/LinearProgramming.py @@ -26,6 +26,12 @@ from lpsolve55 import * MINIMIZE = 0 MAXIMIZE = 1 +# "Epsilon levels" +# Used to control rounding thresholds. +EPS_TIGHT = 0 +EPS_MEDIUM = 1 +EPS_LOOSE = 2 +EPS_BAGGY = 3 class LinearProgram(object): """ @@ -116,6 +122,17 @@ class LinearProgram(object): lpsolve('set_rh_vec', self._lp, self._rhs) + @property + def eps_level(self): + return self._eps_level + + @eps_level.setter + def eps_level(self, value): + self._eps_level = value + + if self._lp != None: + lpsolve('set_epslevel', self._lp, value) + @property def inequalities(self): @@ -253,6 +270,7 @@ class LinearProgram(object): self._solution_upper_bounds = [] self._scale_mode = 0 self._type = MINIMIZE + self._eps_level = EPS_MEDIUM def set_all_lp_properties(self): @@ -277,6 +295,7 @@ class LinearProgram(object): self.solution_upper_bounds = self.solution_upper_bounds self.scale_mode = self.scale_mode self.type = self.type + self.eps_level = self.eps_level @@ -382,6 +401,15 @@ class SimplexIteration(object): self._solution_vector = array(value) + @property + def variables(self): + vars = [] + for idx in range(1, len(self.solution_vector)+1): + vars.append("x" + str(idx)) + + return vars + + @property def basic_variables(self): # The current set of basic variables. Constructed from the @@ -461,6 +489,13 @@ class SimplexIteration(object): bm = delete(bm, idxs, axis=1) return bm.tolist() + + def objective_function_value(self): + c = array(self.objective_coefficients) + sv = array(self.solution_vector) + return dot(sv, c) + + def reduced_cost(self, idx): # Find the reduced cost ofthe variable whose column has index # idx.