Exemple #1
0
def create_lp(polyt, obj_inds):
    """ Creates core LP problem with the Stoichiometric Matrix and list of constraints"""
    # create problem
    p = qsoptex.ExactProblem()
    [Aeq, beq, rids,
     domain] = [polyt["Aeq"], polyt["beq"], polyt["rids"], polyt["domain"]]
    [lbs, ubs] = domain
    # add variables to lp
    for i in range(len(rids)):
        p.add_variable(name=rids[i],
                       objective=Fraction(str(obj_inds[i])),
                       lower=lbs[i],
                       upper=ubs[i])
    # constraints
    # for each row in S (metabolite) = for each constraint
    for i in range(Aeq.shape[0]):
        constr = {}
        # for each column in S = for each reaction
        for j in range(Aeq.shape[1]):
            if Aeq[i, j] != 0:
                constr[rids[j]] = int(Aeq[i, j])
        p.add_linear_constraint(qsoptex.ConstraintSense.EQUAL,
                                constr,
                                rhs=int(beq[i]))
    return p
def l1_equiv_lp(N, constraint_rhs, objective_weight_vector=None, variable_lower_bound=None, variable_upper_bound=None):
    m, n = getSize(N)
    # following part set a default weight vector
    if objective_weight_vector is None:
        objective_weight_vector = np.ones(n)
    if variable_lower_bound is None:
        variable_lower_bound = [None]*n
    if variable_upper_bound is None:
        variable_upper_bound = [None]*n
    p = qsoptex.ExactProblem()
    # In the following part we define the objective of the linear programming
    for i in range(n):
        p.add_variable(name='z' + str(i), objective=objective_weight_vector[i], lower=None, upper=None)
        p.add_variable(name='x' + str(i), objective=0, lower=variable_lower_bound[i], upper=variable_upper_bound[i])
    # In the following part we define constrains of the linear Programming
    for j in range(m):
        p.add_linear_constraint(qsoptex.ConstraintSense.GREATER,
                                {'x' + str(i): N[j][i] for i in range(n)}, rhs=constraint_rhs[j])
    for i in range(n):
        p.add_linear_constraint(qsoptex.ConstraintSense.GREATER,
                                {'z' + str(i): 1, 'x' + str(i): 1}, rhs=0)
        p.add_linear_constraint(qsoptex.ConstraintSense.GREATER,
                                {'z' + str(i): 1, 'x' + str(i): -1}, rhs=0)
    # Following part would solve the LP with qsoptex
    p.set_objective_sense(qsoptex.ObjectiveSense.MINIMIZE)
    p.set_param(qsoptex.Parameter.SIMPLEX_DISPLAY, 1)
    status = p.solve()
    return p, status, n
def minimum_free_lunches(N, constraint_rhs, objective_weight_vector=None, variable_lower_bound=None, variable_upper_bound=None):
    m, n = getSize(N)
    # alpha = Fraction(1, 10)
    # Set default weight vector
    if objective_weight_vector is None:
        objective_weight_vector = np.ones(n)
    if variable_lower_bound is None:
        variable_lower_bound = [None]*n
    if variable_upper_bound is None:
        variable_upper_bound = [None]*n
    p = qsoptex.ExactProblem()
    for i in range(n):
        p.add_variable(name='z' + str(i), objective=objective_weight_vector[i], lower=None, upper=None)
        p.add_variable(name='x' + str(i), objective=0, lower=variable_lower_bound[i], upper=variable_upper_bound[i])
    # The following part will add non-negative slack variable y
    for i in range(m):
        p.add_variable(name='y' + str(i), objective=0, lower=0, upper=None)
    for j in range(m):
        constraints_dict = {'x' + str(i): N[j][i] for i in range(n)}
        constraints_dict.update({'y' + str(j): -1})
        p.add_linear_constraint(qsoptex.ConstraintSense.EQUAL, constraints_dict, rhs=constraint_rhs[j])
        constraints_dict.clear()
    for i in range(n):
        p.add_linear_constraint(qsoptex.ConstraintSense.GREATER,
                                {'z' + str(i): 1, 'x' + str(i): 1}, rhs=0)
        p.add_linear_constraint(qsoptex.ConstraintSense.GREATER,
                                {'z' + str(i): 1, 'x' + str(i): -1}, rhs=0)
    # Adding tolerance to whole system
    p.add_linear_constraint(qsoptex.ConstraintSense.GREATER, {'y' + str(i): 1 for i in range(m)},
                            rhs=1)
    # ------------
    p.set_objective_sense(qsoptex.ObjectiveSense.MINIMIZE)
    p.set_param(qsoptex.Parameter.SIMPLEX_DISPLAY, 1)
    status = p.solve()
    return p, status, n
Exemple #4
0
    def __init__(self, **kwargs):
        self._p = qsoptex.ExactProblem()
        self._p.set_param(qsoptex.Parameter.SIMPLEX_DISPLAY, 1)

        self._variables = {}
        self._var_names = ('x' + str(i) for i in count(1))
        self._constr_names = ('c' + str(i) for i in count(1))

        self._result = None
Exemple #5
0
 def setUp(self):
     self._problem = qsoptex.ExactProblem()
     self._problem.add_variable(name='x',
                                objective=2,
                                lower=3.5,
                                upper=17.5)
     self._problem.add_variable(name='y', objective=-1, lower=None, upper=2)
     self._problem.add_linear_constraint(qsoptex.ConstraintSense.EQUAL, {
         'x': 1,
         'y': 1
     },
                                         rhs=0,
                                         name='c1')
     self._problem.set_objective_sense(qsoptex.ObjectiveSense.MAXIMIZE)
Exemple #6
0
 def test_variable_unicode(self):
     """Test that a variable of unicode type works"""
     self._problem = qsoptex.ExactProblem()
     self._problem.add_variable(name=u('x'))
Exemple #7
0
 def test_variable_str(self):
     """Test that a variable of bytes type works"""
     self._problem = qsoptex.ExactProblem()
     self._problem.add_variable(name=b('x'))