def test_osil_read():
    filename = current_dir / 'osil' / 'example1.xml'
    problem = read_osil(str(filename))
    variables = list(model_variables(problem))
    constraints = list(model_constraints(problem))
    objectives = list(model_objectives(problem))
    assert len(variables) == 35
    assert len(constraints) == 18
    assert len(objectives) == 1

    m = problem

    e9_body_expected = m.x33 - (m.x32*pe.log(m.x22)/(1.0-m.x32))
    e9_body_actual = m.e9.body
    assert sympyify_expression(e9_body_expected - e9_body_actual)[1] == 0

    e11_body_expected = m.x35 - ((m.x33 - m.x34*(m.x32+1.0))/(m.x32+3.0)/(1.0-m.x32)**2/m.x34)
    e11_body_actual = m.e11.body
    assert sympyify_expression(e11_body_expected - e11_body_actual)[1] == 0

    e14_body_expected = m.x26 - m.x22 * m.x28
    e14_body_actual = m.e14.body
    assert sympyify_expression(e14_body_expected - e14_body_actual)[1] == 0

    e15_body_expected = m.x27 - m.x22 * m.x29
    e15_body_actual = m.e15.body
    assert sympyify_expression(e15_body_expected - e15_body_actual)[1] == 0
def test_osil_read():
    filename = current_dir / 'osil' / 'example1.xml'
    problem = read_osil(str(filename))
    variables = list(model_variables(problem))
    constraints = list(model_constraints(problem))
    objectives = list(model_objectives(problem))
    assert len(variables) == 35
    assert len(constraints) == 18
    assert len(objectives) == 1
    def test_binary_variables(self):
        m = aml.ConcreteModel()
        # 10 binary variables
        m.b = aml.Var(range(10), domain=aml.Binary)

        dag = ProblemDag()
        factory = ComponentFactory(dag)
        count = 0
        for omo_var in model_variables(m):
            new_var = factory.variable(omo_var)
            assert new_var.name.startswith('b')
            assert new_var.lb == 0
            assert new_var.ub == 1
            assert new_var.is_binary()
            count += 1
        assert count == 10
    def test_integer_variables(self):
        m = aml.ConcreteModel()
        # 5 integer variables in [-10, 5]
        m.y = aml.Var(range(5), bounds=(-10, 5), domain=aml.Integers)

        dag = ProblemDag()
        factory = ComponentFactory(dag)
        count = 0
        for omo_var in model_variables(m):
            new_var = factory.variable(omo_var)
            assert new_var.name.startswith('y')
            assert new_var.lb == -10
            assert new_var.ub == 5
            assert new_var.is_integer()
            count += 1
        assert count == 5
    def test_continuous_variables(self):
        m = aml.ConcreteModel()
        # 10 continuous variables in [-inf, inf]
        m.x = aml.Var(range(10))

        dag = ProblemDag()
        factory = ComponentFactory(dag)
        count = 0
        for omo_var in model_variables(m):
            new_var = factory.variable(omo_var)
            assert new_var.name.startswith('x')
            assert new_var.name == omo_var.name
            assert new_var.lb is None
            assert new_var.ub is None
            assert not new_var.is_integer()
            assert not new_var.is_binary()
            count += 1
        assert count == 10