def _MakeMDFProblem(self):
        """Create a CVXOPT problem for finding the Maximal Thermodynamic
        Driving Force (MDF).

        Does not set the objective function... leaves that to the caller.

        Returns:
            the linear problem object, and the three types of variables as arrays
        """
        A, b, c, y, l = self._GetPrimalVariablesAndConstants()
        B = Variable('mdf')
        x = y + l + [B]
        lp = Model(name="MDF_PRIMAL")

        cnstr_names = ["driving_force_%02d" % j for j in range(self.Nr_active)] + \
                      ["covariance_var_ub_%02d" % j for j in range(self.Nr)] + \
                      ["covariance_var_lb_%02d" % j for j in range(self.Nr)] + \
                      ["log_conc_ub_%02d" % j for j in range(self.Nc)] + \
                      ["log_conc_lb_%02d" % j for j in range(self.Nc)]

        constraints = []
        for j in range(A.shape[0]):
            row = [A[j, i] * x[i] for i in range(A.shape[1])]
            constraints.append(
                Constraint(sum(row), ub=b[j, 0], name=cnstr_names[j]))

        lp.add(constraints)

        row = [c[i, 0] * x[i] for i in range(c.shape[0])]
        lp.objective = Objective(sum(row), direction='max')

        return lp, y, l, B
    def _MakeMDFProblemDual(self):
        """Create a CVXOPT problem for finding the Maximal Thermodynamic
        Driving Force (MDF).

        Does not set the objective function... leaves that to the caller.

        Returns:
            the linear problem object, and the four types of variables as arrays
        """
        A, b, c, w, g, z, u = self._GetDualVariablesAndConstants()
        x = w + g + z + u
        lp = Model(name="MDF_DUAL")

        cnstr_names = ["y_%02d" % j for j in range(self.Nr)] + \
                      ["l_%02d" % j for j in range(self.Nc)] + \
                      ["MDF"]

        constraints = []
        for i in range(A.shape[1]):
            row = [A[j, i] * x[j] for j in range(A.shape[0])]
            constraints.append(
                Constraint(sum(row),
                           lb=c[i, 0],
                           ub=c[i, 0],
                           name=cnstr_names[i]))

        lp.add(constraints)

        row = [b[i, 0] * x[i] for i in range(A.shape[0])]
        lp.objective = Objective(sum(row), direction='min')

        return lp, w, g, z, u
예제 #3
0
    def setUp(self):
        x = Variable("x", lb=0)
        y = Variable("y", lb=0)
        z = Variable("z", lb=0)

        c1 = Constraint(x, ub=10)
        c2 = Constraint(y - 2 * z, lb=0, ub=0)
        c3 = Constraint(x - z, lb=3, ub=15)

        obj = Objective(x + y + z)

        model = Model()
        model.add([c1, c2, c3])
        model.objective = obj
        self.model = model
        self.c1 = c1
    def _GetTotalEnergyProblem(self, min_driving_force=0.0, direction='min'):

        A, b, _c, y, l = self._GetPrimalVariablesAndConstants()
        x = y + l + [min_driving_force]
        lp = Model(name='MDF')

        constraints = []
        for j in range(A.shape[0]):
            row = [A[j, i] * x[i] for i in range(A.shape[1])]
            constraints.append(
                Constraint(sum(row), ub=b[j, 0], name='row_%d' % j))

        total_g0 = float(self.fluxes @ self.dG0_r_prime)
        total_reaction = self.S @ self.fluxes.T
        row = [total_reaction[i, 0] * x[i] for i in range(self.Nc)]
        total_g = total_g0 + sum(row)

        lp.add(constraints)
        lp.objective = Objective(total_g, direction=direction)

        return lp