def test_include_variable_parameter_in_bound(self):
     aop = AbstractOptimizationProblem()
     p = aop.create_parameter('p')
     self.assertRaises(ValueError,
                       aop.create_variable,
                       name='x',
                       size=3,
                       lb=p,
                       ub=p)
    def test_get_problem_dict(self):
        aop = AbstractOptimizationProblem()
        x = aop.create_variable('x', 3)
        p = aop.create_parameter('p', 3)
        f = sum([x[i]**2 for i in range(x.numel())])
        g = x[0] - x[1] + 2 * x[2]
        aop.set_objective(f)
        aop.include_inequality(g, lb=-10, ub=20)
        d_res = {'x': x, 'p': p, 'f': f, 'g': g}

        d = aop.get_problem_dict()
        for key in set(d_res.keys()).union(set(d.keys())):
            self.assertTrue(is_equal(d_res[key], d[key]))
    def test_get_default_call_dict(self):
        aop = AbstractOptimizationProblem()

        lbx = -DM([2, 3, 10])
        ubx = DM([2, 3, 10])

        x = aop.create_variable('x', 3, lb=lbx, ub=ubx)
        p = aop.create_parameter('p', 3)
        f = sum([x[i]**2 for i in range(x.numel())])
        g = x[0] - x[1] + 2 * x[2]

        aop.set_objective(f)
        aop.include_inequality(g, lb=-10, ub=20)

        expected = {'lbx': lbx, 'ubx': ubx, 'lbg': DM(-10), 'ubg': DM(20)}

        d = aop.get_default_call_dict()
        for key in set(expected.keys()).union(set(d.keys())):
            self.assertTrue(is_equal(expected[key], d[key]))
    def test_create_parameter(self):
        aop = AbstractOptimizationProblem()
        p = aop.create_parameter('p')

        self.assertTrue(is_equal(aop.p, p))