]> gitweb.michael.orlitzky.com - dead/census-tools.git/blob - src/LinearProgramming.py
Remove the inequality constants in favor of those defined by the lp_solve library.
[dead/census-tools.git] / src / LinearProgramming.py
1 """
2 Classes to create, solve, and make dinner for linear programs. Handles
3 integration with lp_solve.
4 """
5
6 import os
7 import site
8 import sys
9
10 # Add LP_SOLVE_PATH to our path. There is no point to this variable
11 # other than to make the site.addsitedir() line fit within 80
12 # characters.
13 LP_SOLVE_PATH = '/../lib/lp_solve'
14 site.addsitedir(os.path.dirname(os.path.abspath(sys.argv[0])) + LP_SOLVE_PATH)
15
16 from lp_solve import *
17
18 MINIMUM = 0
19 MAXIMUM = 1
20
21 class LinearProgram(object):
22 """
23 Represents an instance of an lp_solve linear program.
24 """
25
26 def __init__(self):
27 self.objective_function_coefficients = []
28 self.constraint_matrix = []
29 self.rhs = []
30 self.inequalities = []
31
32
33 def solve(self):
34 [v,x,duals] = lp_solve(self.objective_function_coefficients,
35 self.constraint_matrix,
36 self.rhs,
37 self.inequalities)
38 return [v,x,duals]
39