variable

(class from pyomo.core.kernel.variable)

class pyomo.core.kernel.variable.variable(domain_type=None, domain=None, lb=None, ub=None, value=None, fixed=False)[source]

Bases: IVariable

A decision variable

Decision variables are used in objectives and constraints to define an optimization problem.

Parameters:
  • domain_type – Sets the domain type of the variable. Must be one of RealSet or IntegerSet. Can be updated later by assigning to the domain_type property. The default value of None is equivalent to RealSet, unless the domain keyword is used.

  • domain – Sets the domain of the variable. This updates the domain_type, lb, and ub properties of the variable. The default value of None implies that this keyword is ignored. This keyword can not be used in combination with the domain_type keyword.

  • lb – Sets the lower bound of the variable. Can be updated later by assigning to the lb property on the variable. Default is None, which is equivalent to -inf.

  • ub – Sets the upper bound of the variable. Can be updated later by assigning to the ub property on the variable. Default is None, which is equivalent to +inf.

  • value – Sets the value of the variable. Can be updated later by assigning to the value property on the variable. Default is None.

  • fixed (bool) – Sets the fixed status of the variable. Can be updated later by assigning to the fixed property or by calling the fix() method. Default is False.

Examples

>>> import pyomo.kernel as pmo
>>> # A continuous variable with infinite bounds
>>> x = pmo.variable()
>>> # A binary variable
>>> x = pmo.variable(domain=pmo.Binary)
>>> # Also a binary variable
>>> x = pmo.variable(domain_type=pmo.IntegerSet, lb=0, ub=1)
__init__(domain_type=None, domain=None, lb=None, ub=None, value=None, fixed=False)[source]

Methods

__init__([domain_type, domain, lb, ub, ...])

activate()

Activate this object.

clone()

Returns a copy of this object with the parent pointer set to None.

deactivate()

Deactivate this object.

fix([value])

Fix the variable.

free()

Free the variable.

getname([fully_qualified, name_buffer, ...])

Dynamically generates a name for this object.

has_lb()

Returns False when the lower bound is None or negative infinity

has_ub()

Returns False when the upper bound is None or positive infinity

is_binary()

Returns True when the domain type is IntegerSet and the bounds are within [0,1].

is_component_type()

Return True if this class is a Pyomo component

is_constant()

Returns False because this is not a constant in an expression.

is_continuous()

Returns True when the domain type is RealSet.

is_discrete()

Returns True when the domain type is IntegerSet.

is_expression_type([expression_system])

Return True if this numeric value is an expression

is_fixed()

Returns True if this variable is fixed, otherwise returns False.

is_indexed()

Return True if this numeric value is an indexed object

is_integer()

Returns True when the domain type is IntegerSet.

is_logical_type()

Return True if this class is a Pyomo Boolean object.

is_named_expression_type()

Return True if this numeric value is a named expression

is_numeric_type()

Return True if this class is a Pyomo numeric object

is_parameter_type()

Returns False because this is not a parameter object.

is_potentially_variable()

Returns True because this is a variable.

is_reference()

Return True if this object is a reference.

is_relational()

DEPRECATED.

is_variable_type()

Returns True because this is a variable object.

polynomial_degree()

Return the polynomial degree of this expression

set_value(value[, skip_validation])

to_string([verbose, labeler, smap, ...])

Return a string representation of the expression tree.

unfix()

Free the variable.

Attributes

active

The active status of this object.

bounds

Get/Set the bounds as a tuple (lb, ub).

ctype

The object's category type.

domain

Set the domain of the variable.

domain_type

The domain type of the variable (RealSet or IntegerSet)

fixed

The fixed status of the variable

lb

Return the numeric value of the variable lower bound.

local_name

The object's local name within the context of its parent.

lower

The lower bound of the variable

lslack

Lower slack (value - lb).

name

The object's fully qualified name.

parent

The object's parent (possibly None).

slack

min(lslack, uslack).

stale

The stale status of the variable

storage_key

The object's storage key within its parent

ub

Return the numeric value of the variable upper bound.

upper

The upper bound of the variable

uslack

Upper slack (ub - value).

value

The value of the variable

Member Documentation

activate()

Activate this object.

clone()

Returns a copy of this object with the parent pointer set to None.

A clone is almost equivalent to deepcopy except that any categorized objects encountered that are not descendents of this object will reference the same object on the clone.

deactivate()

Deactivate this object.

fix(value=NOTSET)

Fix the variable. Sets the fixed indicator to True. An optional value argument will update the variable’s value before fixing.

free()

Free the variable. Sets the fixed indicator to False.

getname(fully_qualified=False, name_buffer={}, convert=<class 'str'>, relative_to=None)

Dynamically generates a name for this object.

Parameters:
  • fully_qualified (bool) – Generate a full name by iterating through all ancestor containers. Default is False.

  • convert (function) – A function that converts a storage key into a string representation. Default is the built-in function str.

  • relative_to (object) – When generating a fully qualified name, generate the name relative to this block.

Returns:

If a parent exists, this method returns a string representing the name of the object in the context of its parent; otherwise (if no parent exists), this method returns None.

has_lb()

Returns False when the lower bound is None or negative infinity

has_ub()

Returns False when the upper bound is None or positive infinity

is_binary()

Returns True when the domain type is IntegerSet and the bounds are within [0,1].

is_component_type()

Return True if this class is a Pyomo component

is_constant()

Returns False because this is not a constant in an expression.

is_continuous()

Returns True when the domain type is RealSet.

is_discrete()

Returns True when the domain type is IntegerSet.

is_expression_type(expression_system=None)

Return True if this numeric value is an expression

is_fixed()

Returns True if this variable is fixed, otherwise returns False.

is_indexed()

Return True if this numeric value is an indexed object

is_integer()

Returns True when the domain type is IntegerSet.

is_logical_type()

Return True if this class is a Pyomo Boolean object.

Boolean objects include constants, variables, or logical expressions.

is_named_expression_type()

Return True if this numeric value is a named expression

is_numeric_type()

Return True if this class is a Pyomo numeric object

is_parameter_type()

Returns False because this is not a parameter object.

is_potentially_variable()

Returns True because this is a variable.

is_reference()

Return True if this object is a reference.

is_relational()

DEPRECATED.

Return True if this numeric value represents a relational expression.

Deprecated since version 6.4.3: is_relational() is deprecated in favor of is_expression_type(ExpressionType.RELATIONAL)

is_variable_type()

Returns True because this is a variable object.

polynomial_degree()

Return the polynomial degree of this expression

to_string(verbose=None, labeler=None, smap=None, compute_values=False)

Return a string representation of the expression tree.

Parameters:
  • verbose (bool) – If True, then the string representation consists of nested functions. Otherwise, the string representation is an infix algebraic equation. Defaults to False.

  • labeler – An object that generates string labels for non-constant in the expression tree. Defaults to None.

  • smap – A SymbolMap instance that stores string labels for non-constant nodes in the expression tree. Defaults to None.

  • compute_values (bool) – If True, then fixed expressions are evaluated and the string representation of the resulting value is returned.

Returns:

A string representation for the expression tree.

unfix()

Free the variable. Sets the fixed indicator to False.

property active

The active status of this object.

property bounds

Get/Set the bounds as a tuple (lb, ub).

property ctype

The object’s category type.

property domain

Set the domain of the variable. This method updates the domain_type property and overwrites the lb and ub properties with the domain bounds.

property domain_type

The domain type of the variable (RealSet or IntegerSet)

property fixed

The fixed status of the variable

property lb

Return the numeric value of the variable lower bound.

property local_name

The object’s local name within the context of its parent. Alias for obj.getname(fully_qualified=False).

property lower

The lower bound of the variable

property lslack

Lower slack (value - lb). Returns None if the variable value is None.

property name

The object’s fully qualified name. Alias for obj.getname(fully_qualified=True).

property parent

The object’s parent (possibly None).

property slack

min(lslack, uslack). Returns None if the variable value is None.

property stale

The stale status of the variable

property storage_key

The object’s storage key within its parent

property ub

Return the numeric value of the variable upper bound.

property upper

The upper bound of the variable

property uslack

Upper slack (ub - value). Returns None if the variable value is None.

property value

The value of the variable