def compound_bounds(cpdIds): """ This is the zero flux vector. Parameters: cpdIds: List of compound IDs from the model """ cbounds = [(0.0, 0.0) for i in cpdIds] if verbose: print "Number of compound bounds: %d" % len(cbounds) lp.row_bounds(cbounds)
def compound_bounds(cpids): """ This is the zero flux vector. Parameters: cpids: List of compound IDs from the model """ cbounds = [(0.0, 0.0) for i in cpids] if verbose: print(f"Number of compound bounds: {len(cbounds)}") lp.row_bounds(cbounds)
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_bound_rows(self): """Test adding tuples of boundary conditions for rows""" mat = [ [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12] ] lp.load(mat) boundsr = [] # test that we don't have enough values self.assertRaises(ValueError, lp.row_bounds, boundsr) # a boundary of None should be infiniity! boundsr = [(None, 1000), (1000, None), (1000, 1000)] lp.row_bounds(boundsr)
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)
def compound_bounds(cp, lower=0, upper=0): """ Impose constraints on the compounds. These constraints limit what the variation of each compound can be and is essentially 0 for most compounds except those that are in the media or otherwise external. This is the zero flux vector. Parameters: cp: the list of compound ids lower: the default lower value upper: the default upper value """ cbounds = [(lower, upper) for c in cp] cbvals = {c: (lower, upper) for c in cp} lp.row_bounds(cbounds) return cbvals