TransformedPiecewiseLinearFunction

(class from pyomo.core.kernel.piecewise_library.transforms)

class pyomo.core.kernel.piecewise_library.transforms.TransformedPiecewiseLinearFunction(f, input=None, output=None, bound='eq', validate=True, **kwds)[source]

Bases: block

Base class for transformed piecewise linear functions

A transformed piecewise linear functions is a block of variables and constraints that enforce a piecewise linear relationship between an input variable and an output variable.

Parameters:
  • f (PiecewiseLinearFunction) – The piecewise linear function to transform.

  • input – The variable constrained to be the input of the piecewise linear function.

  • output – The variable constrained to be the output of the piecewise linear function.

  • bound (str) –

    The type of bound to impose on the output expression. Can be one of:

    • ’lb’: y <= f(x)

    • ’eq’: y = f(x)

    • ’ub’: y >= f(x)

  • validate (bool) – Indicates whether or not to perform validation of the input data. The default is True. Validation can be performed manually after the piecewise object is created by calling the validate() method. Validation should be performed any time the inputs are changed (e.g., when using mutable parameters in the breakpoints list or when the input variable changes).

  • **kwds – Additional keywords are passed to the validate() method when the validate keyword is True; otherwise, they are ignored.

__init__(f, input=None, output=None, bound='eq', validate=True, **kwds)[source]

Methods

__init__(f[, input, output, bound, validate])

activate([shallow])

Activate this container.

block_data_objects(**kwds)

child(key)

Get the child object associated with a given storage key for this container.

child_ctypes()

Returns the set of child object category types stored in this container.

children([ctype])

Iterate over the children of this block.

clone()

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

collect_ctypes([active, descend_into])

Returns the set of object category types that can be found under this container.

component_data_objects(*args, **kwds)

component_objects(*args, **kwds)

components([ctype, active, descend_into])

Generates an efficient traversal of all components stored under this container.

deactivate([shallow])

Deactivate this container.

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

Dynamically generates a name for this object.

load_solution(solution[, ...])

Load a solution.

valid_problem_types()

validate([equal_slopes_tolerance, ...])

Validate this piecewise linear function by verifying various properties of the breakpoints, values, and input variable (e.g., that the list of breakpoints is nondecreasing).

write(filename[, format, ...])

Write the model to a file, with a given format.

Attributes

active

The active status of this object.

bound

The bound type assigned to the piecewise relationship ('lb','ub','eq').

breakpoints

The set of breakpoints used to defined this function

ctype

The object's category type.

input

The expression that stores the input to the piecewise function.

local_name

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

name

The object's fully qualified name.

output

The expression that stores the output of the piecewise function.

parent

The object's parent (possibly None).

storage_key

The object's storage key within its parent

values

The set of values used to defined this function

Member Documentation

activate(shallow=True)

Activate this container.

child(key)

Get the child object associated with a given storage key for this container.

Raises:

KeyError – if the argument is not a storage key for any children of this container

child_ctypes()

Returns the set of child object category types stored in this container.

children(ctype=<class 'pyomo.core.kernel.base._no_ctype'>)

Iterate over the children of this block.

Parameters:

ctype – Indicates the category of children to include. The default value indicates that all categories should be included.

Returns:

iterator of child objects

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.

collect_ctypes(active=True, descend_into=True)

Returns the set of object category types that can be found under this container.

Parameters:
  • active (True/None) – Controls whether or not to filter the iteration to include only the active part of the storage tree. The default is True. Setting this keyword to None causes the active status of objects to be ignored.

  • descend_into (bool, function) – Indicates whether or not to descend into a heterogeneous container. Default is True, which is equivalent to lambda x: True, meaning all heterogeneous containers will be descended into.

Returns:

A set of object category types

components(ctype=<class 'pyomo.core.kernel.base._no_ctype'>, active=True, descend_into=True)

Generates an efficient traversal of all components stored under this container. Components are categorized objects that are either (1) not containers, or (2) are heterogeneous containers.

Parameters:
  • ctype – Indicates the category of components to include. The default value indicates that all categories should be included.

  • active (True/None) – Controls whether or not to filter the iteration to include only the active part of the storage tree. The default is True. Setting this keyword to None causes the active status of objects to be ignored.

  • descend_into (bool, function) – Indicates whether or not to descend into a heterogeneous container. Default is True, which is equivalent to lambda x: True, meaning all heterogeneous containers will be descended into.

Returns:

iterator of components in the storage tree

deactivate(shallow=True)

Deactivate this container.

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.

load_solution(solution, allow_consistent_values_for_fixed_vars=False, comparison_tolerance_for_fixed_vars=1e-05)

Load a solution.

Parameters:
  • solution – A pyomo.opt.Solution object with a symbol map. Optionally, the solution can be tagged with a default variable value (e.g., 0) that will be applied to those variables in the symbol map that do not have a value in the solution.

  • allow_consistent_values_for_fixed_vars – Indicates whether a solution can specify consistent values for variables that are fixed.

  • comparison_tolerance_for_fixed_vars – The tolerance used to define whether or not a value in the solution is consistent with the value of a fixed variable.

validate(equal_slopes_tolerance=1e-06, require_bounded_input_variable=True, require_variable_domain_coverage=True)[source]

Validate this piecewise linear function by verifying various properties of the breakpoints, values, and input variable (e.g., that the list of breakpoints is nondecreasing).

Parameters:
  • equal_slopes_tolerance (float) – Tolerance used check if consecutive slopes are nearly equal. If any are found, validation will fail. Default is 1e-6.

  • require_bounded_input_variable (bool) – Indicates if the input variable is required to have finite upper and lower bounds. Default is True. Setting this keyword to False can be used to allow general expressions to be used as the input in place of a variable.

  • require_variable_domain_coverage (bool) – Indicates if the function domain (defined by the endpoints of the breakpoints list) needs to cover the entire domain of the input variable. Default is True. Ignored for any bounds of variables that are not finite, or when the input is not assigned a variable.

Returns:

a function characterization code (see util.characterize_function())

Return type:

int

Raises:

PiecewiseValidationError – if validation fails

write(filename, format=None, _solver_capability=None, _called_by_solver=False, **kwds)

Write the model to a file, with a given format.

Parameters:
  • filename (str) – The name of the file to write.

  • format – The file format to use. If this is not specified, the file format will be inferred from the filename suffix.

  • **kwds – Additional keyword options passed to the model writer.

Returns:

a SymbolMap

property active

The active status of this object.

property bound

The bound type assigned to the piecewise relationship (‘lb’,’ub’,’eq’).

property breakpoints

The set of breakpoints used to defined this function

property ctype

The object’s category type.

property input

The expression that stores the input to the piecewise function. The returned object can be updated by assigning to its expr attribute.

property local_name

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

property name

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

property output

The expression that stores the output of the piecewise function. The returned object can be updated by assigning to its expr attribute.

property parent

The object’s parent (possibly None).

property storage_key

The object’s storage key within its parent

property values

The set of values used to defined this function