""" Classes to create, solve, and make dinner for linear programs. Handles integration with lp_solve. """ import os import site 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' site.addsitedir(os.path.dirname(os.path.abspath(sys.argv[0])) + LP_SOLVE_PATH) from lp_solve import * MINIMUM = 0 MAXIMUM = 1 class LinearProgram(object): """ Represents an instance of an lp_solve linear program. """ def __init__(self): self.objective_function_coefficients = [] self.constraint_matrix = [] self.rhs = [] self.inequalities = [] def solve(self): [v,x,duals] = lp_solve(self.objective_function_coefficients, self.constraint_matrix, self.rhs, self.inequalities) return [v,x,duals]