'Test domain for partial minimization/maximization problems.'

def test_partial_problem(self):

    for obj in [Minimize((self.a ** (-1))), Maximize(log(self.a))]:
        prob = Problem(obj, [((self.x + self.a) >= [5, 8])])
        expr = cvxpy.partial_optimize(prob, dont_opt_vars=[self.x, self.a])
        dom = expr.domain
        constr = [(self.a >= (-100)), (self.x >= 0)]
        prob = Problem(Minimize(sum_entries((self.x + self.a))), (dom + constr))
        prob.solve()
        self.assertAlmostEqual(prob.value, 13)
        assert (self.a.value >= 0)
        assert np.all((((self.x + self.a) - [5, 8]).value >= (-0.001)))
        expr = cvxpy.partial_optimize(prob, opt_vars=[self.x])
        dom = expr.domain
        constr = [(self.a >= (-100)), (self.x >= 0)]
        prob = Problem(Minimize(sum_entries((self.x + self.a))), (dom + constr))
        prob.solve()
        self.assertAlmostEqual(prob.value, 0)
        assert (self.a.value >= 0)
        self.assertItemsAlmostEqual(self.x.value, [0, 0])
        expr = cvxpy.partial_optimize(prob, opt_vars=[self.x, self.a])
        dom = expr.domain
        constr = [(self.a >= (-100)), (self.x >= 0)]
        prob = Problem(Minimize(sum_entries((self.x + self.a))), (dom + constr))
        prob.solve()
        self.assertAlmostEqual(self.a.value, (-100))
        self.assertItemsAlmostEqual(self.x.value, [0, 0])
