def test_solve(self): """Test the complete linear programing solution, using the example from the documentation""" mat = [ [ 1.0, 1.0, 1.0], [10.0, 4.0, 5.0], [ 2.0, 2.0, 6.0], ] lp.load(mat) lp.objective_coefficients([ 10.0, 6.0, 4.0 ]) lp.row_bounds([(None, 100.0), (None, 600.0), (None, 300.0)]) lp.col_bounds([(0, None), (0, None), (0, None)]) status, result = lp.solve() r = "%0.3f" % result self.assertEqual(r, "733.333") self.assertEqual(status, 'opt')
def test_primals(self): """Test getting the primals back as a list""" mat = [ [ 1.0, 1.0, 1.0], [10.0, 4.0, 5.0], [ 2.0, 2.0, 6.0], ] rh = ['a', 'b', 'c'] ch = ['x', 'y', 'z'] lp.load(mat, rh, ch) lp.objective_coefficients([ 10.0, 6.0, 4.0 ]) lp.row_bounds([(None, 100.0), (None, 600.0), (None, 300.0)]) lp.col_bounds([(0, None), (0, None), (0, None)]) status, result = lp.solve() col_pri = [33.333333333333336, 66.66666666666666, 0.0] col_res = lp.col_primals() self.assertEqual(col_pri, col_res)
parser.add_argument('-m', '--media', help="Media input file") parser.add_argument('-o', '--out', help="Output file") parser.add_argument('-v', '--verbose', action="store_true", help="Output status messages") args = parser.parse_args() sbmlf = args.sbml output = args.out if args.out else None mediaf = args.media if args.media else None verbose = args.verbose doc = parse_sbml_file(sbmlf) model = doc.getModel() if mediaf: media = parse_media_file(mediaf) else: media = None compound_ids, reaction_ids, stiochio_m, objFunc = parse_stoichiometry( model) compound_ids, reaction_ids = create_smatrix(compound_ids, reaction_ids, stiochio_m, objFunc) reaction_bounds(model, reaction_ids, media) compound_bounds(compound_ids) status, value = lp.solve() print("Solved the FBA with status: {}".format(status)) print("Objective value: {}".format(value))
if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument("sbml", help='SBML Model file') parser.add_argument('-m', '--media', help="Media input file") parser.add_argument('-o', '--out', help="Output file") parser.add_argument('-v', '--verbose', action="store_true", help="Output status messages") args = parser.parse_args() sbmlf = args.sbml output = args.out if args.out else None mediaf = args.media if args.media else None verbose = args.verbose doc = parse_sbml_file(sbmlf) model = doc.getModel() if mediaf: media = parse_media_file(mediaf) else: media = None cpdIds, rxnIds, sm, objFunc = parse_stoichiometry(model) cpdIds, rxnIds = createSMatrix(cpdIds, rxnIds, sm, objFunc) reaction_bounds(model, rxnIds, media) compound_bounds(cpdIds) status, value = lp.solve() print("Solved the FBA with status: {}".format(status)) print("Objective value: {}".format(value))