How to use Pyomo - 10 common examples

To help you get started, we’ve selected a few Pyomo examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cog-imperial / suspect / tests / polynomial / test_rules.py View on Github external
def test_division_rule_with_nonconstant_denominator(visitor, den_degree):
    assume(not den_degree.is_constant())
    child = pe.Var()
    num = 1.0
    expr = DivisionExpression([num, child])
    poly = ComponentMap()
    poly[num] = PolynomialDegree(0)
    poly[child] = den_degree
    matched, result = visitor.visit_expression(expr, poly)
    assert matched
    assert not result.is_polynomial()
github Pyomo / pyomo / pyomo / contrib / satsolver / test_satsolver.py View on Github external
def test_disjunction_unsat(self):
        m = ConcreteModel()
        m.x1 = Var(bounds=(0, 8))
        m.x2 = Var(bounds=(0, 8))
        m.obj = Objective(expr=m.x1 + m.x2, sense=minimize)
        m.y1 = Disjunct()
        m.y2 = Disjunct()
        m.y1.c1 = Constraint(expr=m.x1 >= 9)
        m.y1.c2 = Constraint(expr=m.x2 >= 2)
        m.y2.c1 = Constraint(expr=m.x1 >= 3)
        m.y2.c2 = Constraint(expr=m.x2 >= 9)
        m.djn = Disjunction(expr=[m.y1, m.y2])
        self.assertFalse(satisfiable(m))
github coin-or / rbfopt / tests / test_rbfopt_degree1_models.py View on Github external
def test_create_min_rbf_model(self):
        """Test the create_min_rbf_model function.

        This test simply checks whether the function returns a valid
        pyomo.ConcreteModel object.
        """
        model = d1.create_min_rbf_model(self.settings, self.n, self.k,
                                        self.var_lower, self.var_upper,
                                        self.integer_vars, None, self.node_pos,
                                        self.rbf_lambda, self.rbf_h)
        self.assertIsInstance(model, pyomo.environ.ConcreteModel)
        model = d1.create_min_rbf_model(
            self.settings, 10, 20, np.array([0] * 10),np.array([1] * 10),
            np.array([i for i in range(10)]),
            (np.array([0]), np.array([]),
             [(0, 0, np.array([i for i in range(10)]))]),
            np.random.randint(0, 2, size=(20, 10)),
            np.random.uniform(size=20), np.random.uniform(size=11))
        self.assertIsInstance(model, pyomo.environ.ConcreteModel)
github IDAES / idaes-pse / idaes / core / util / testing.py View on Github external
def build(self):
        super(_PhysicalParameterBlock, self).build()

        self.p1 = Phase()
        self.p2 = Phase()

        self.c1 = Component()
        self.c2 = Component()

        self.phase_equilibrium_idx = Set(initialize=["e1", "e2"])
        self.element_list = Set(initialize=["H", "He", "Li"])
        self.element_comp = {"c1": {"H": 1, "He": 2, "Li": 3},
                             "c2": {"H": 4, "He": 5, "Li": 6}}

        self.phase_equilibrium_list = \
            {"e1": ["c1", ("p1", "p2")],
             "e2": ["c2", ("p1", "p2")]}

        # Attribute to switch flow basis for testing
        self.basis_switch = 1
        self.default_balance_switch = 1

        self._state_block_class = TestStateBlock
github cog-imperial / suspect / tests / polynomial / test_rules.py View on Github external
def test_power_with_non_polynomial_exponent(visitor, base, expo, base_poly):
    poly = ComponentMap()
    poly[base] = base_poly
    poly[expo] = PolynomialDegree(None)
    expr = base ** expo
    matched, result = visitor.visit_expression(expr, poly)
    assert matched
    assert not result.is_polynomial()
github cog-imperial / suspect / tests / convexity / test_rules.py View on Github external
def _rule_result(self, visitor, base, cvx_base, mono_base, bounds_base, expo):
        convexity = ComponentMap()
        convexity[base] = cvx_base
        convexity[expo] = C.Linear
        mono = ComponentMap()
        mono[base] = mono_base
        mono[expo] = M.Constant
        bounds = ComponentMap()
        bounds[base] = bounds_base
        bounds[expo] = I(expo, expo)
        expr = PowExpression([base, expo])
        matched, result = visitor.visit_expression(expr, convexity, mono, bounds)
        assert matched
        return result
github cog-imperial / suspect / tests / convexity / test_rules.py View on Github external
def _rule_result(self, cvx_f, cvx_g, mono_f, mono_g, bounds_f, bounds_g):
        rule = DivisionRule()
        f = PE()
        g = PE()
        convexity = ComponentMap()
        convexity[f] = cvx_f
        convexity[g] = cvx_g
        mono = ComponentMap()
        mono[f] = mono_f
        mono[g] = mono_g
        bounds = ComponentMap()
        bounds[f] = bounds_f
        bounds[g] = bounds_g
        return rule.apply(PE(ET.Division, [f, g]), convexity, mono, bounds)
github cog-imperial / suspect / tests / convexity / test_rules.py View on Github external
def _rule_result(self, visitor, base, expo, cvx_expo, mono_expo, bounds_expo):
        convexity = ComponentMap()
        convexity[expo] = cvx_expo
        convexity[base] = C.Linear
        mono = ComponentMap()
        mono[expo] = mono_expo
        mono[base] = M.Constant
        bounds = ComponentMap()
        bounds[base] = I(base, base)
        bounds[expo] = bounds_expo

        expr = PowExpression([base, expo])
        matched, result = visitor.visit_expression(expr, convexity, mono, bounds)
        assert matched
        return result
github cog-imperial / suspect / tests / monotonicity / test_rules.py View on Github external
def test_division(visitor, g, mono_g, bound_g, expected):
    num = NumericConstant(1.0)
    bounds = ComponentMap()
    bounds[num] = I(1.0, 1.0)
    bounds[g] = bound_g
    mono = ComponentMap()
    mono[num] = M.Constant
    mono[g] = mono_g

    print(mono)
    print(mono[num])
    expr = DivisionExpression([num, g])
    matched, result = visitor.visit_expression(expr, mono, bounds)
    assert matched
    assert result == expected
github cog-imperial / suspect / tests / monotonicity / test_rules.py View on Github external
def _result_with_terms(self, visitor, expr_with_monos):
        children = [c for c, _ in expr_with_monos]
        monos = [m for _, m in expr_with_monos]
        monotonicity = ComponentMap()
        for child, mono in expr_with_monos:
            monotonicity[child] = mono
        expr = SumExpression(children)
        matched, result = visitor.visit_expression(expr, monotonicity, None)
        assert matched
        return result