Programming Language: Python

Namespace/Package Name: pyomo.core

Class/Type: Constraint

Examples at hotexamples.com: 33

The pyomo.core.Constraint package library is used to define and apply constraints in mathematical optimization problems.

**Example 1:** Linear constraint

The following code creates a linear constraint in Pyomo where the sum of x and y should be less than or equal to 10:

**Example 2:** Nonlinear constraint

The following code creates a nonlinear constraint in Pyomo where the product of x and y should be at least 1:

**Example 3:** Disjunctive constraint

The following code creates a disjunctive constraint in Pyomo where either x or y should be equal to 1:

The following code creates a linear constraint in Pyomo where the sum of x and y should be less than or equal to 10:

from pyomo.environ import * model = ConcreteModel() model.x = Var(within=NonNegativeReals) model.y = Var(within=NonNegativeReals) model.con1 = Constraint(expr=model.x + model.y <= 10)

The following code creates a nonlinear constraint in Pyomo where the product of x and y should be at least 1:

from pyomo.environ import * model = ConcreteModel() model.x = Var(within=NonNegativeReals) model.y = Var(within=NonNegativeReals) model.con2 = Constraint(expr=model.x*model.y >= 1)

The following code creates a disjunctive constraint in Pyomo where either x or y should be equal to 1:

from pyomo.environ import * model = ConcreteModel() model.x = Var(within=NonNegativeReals) model.y = Var(within=NonNegativeReals) model.con3 = Constraint(expr=model.x + model.y == 1) model.disj_con = Disjunction(expr=[model.x == 1, model.y == 1])In summary, Pyomo's Constraint package library provides a wide range of tools for defining and implementing constraints in mathematical optimization problems, including linear, nonlinear, and disjunctive constraints.

Frequently Used Methods