Esempio n. 1
0
def _optimise(a_matrix, max_stoich, num_opt_formulae):
    '''Optimise linear program and return result.'''
    bounds = [(1.0, max_stoich)] * (len(a_matrix[0]) -
                                    num_opt_formulae * 2) + \
        [(0.0, max_stoich)] * num_opt_formulae * 2

    return math_utils.linprog([1] * len(a_matrix[0]),
                              a_matrix,
                              [0.0] * (len(a_matrix)),
                              bounds)
    def test_linprog(self):
        '''Tests linprog method.'''
        a_matrix = [[-238, -142, 1, 248, 131, -1, -2, 1, 2],
                    [-144, -86, 0, 150, 80, 0, 0, 0, 0],
                    [-2, 0, 0, 2, 0, 0, 0, 0, 0],
                    [-57, -9, 0, 62, 4, 0, -1, 0, 1],
                    [-2, -1, 0, 2, 1, 0, 0, 0, 0],
                    [2.0, 1.0, 1.0, -2.0, -2.0, -1, 0, 1, 0]]

        bounds = [(1, 8), (1, 8), (1, 8), (1, 8), (1, 8), (0, 8), (0, 8),
                  (0, 8), (0, 8)]

        self.assertTrue(math_utils.linprog([1] * len(a_matrix[0]), a_matrix,
                                           [0] * len(a_matrix), bounds)[0])