PiecewiseLinearFunction
(class from pyomo.contrib.piecewise.piecewise_linear_function
)
- class pyomo.contrib.piecewise.piecewise_linear_function.PiecewiseLinearFunction(*args, **kwds)[source]
Bases:
Block
A piecewise linear function, which may be defined over an index.
- Can be specified in one of several ways:
List of points and a nonlinear function to approximate. In this case, the points will be used to derive a triangulation of the part of the domain of interest, and a linear function approximating the given function will be calculated for each of the simplices in the triangulation. In this case, scipy is required (for multivariate functions).
List of simplices and a nonlinear function to approximate. In this case, a linear function approximating the given function will be calculated for each simplex. For multivariate functions, numpy is required.
List of simplices and list of functions that return linear function expressions. These are the desired piecewise functions corresponding to each simplex.
Mapping of function values to points of the domain, allowing for the construction of a piecewise linear function from tabular data.
- Parameters:
function – Nonlinear function to approximate: must be callable
function_rule – Function that returns a nonlinear function to approximate for each index in an IndexedPiecewiseLinearFunction
points – List of points in the same dimension as the domain of the function being approximated. Note that if the pieces of the function are specified this way, we require scipy.
simplices – A list of lists of points, where each list specifies the extreme points of a a simplex over which the nonlinear function will be approximated as a linear function.
linear_functions – A list of functions, each of which returns an expression for a linear function of the arguments.
tabular_data – A dictionary mapping values of the nonlinear function to points in the domain
triangulation (optional) – An enum value of type Triangulation specifying how Pyomo should triangulate the function domain, or None. Behavior depends on how this piecewise-linear function is constructed: when constructed using methods (1) or (4) above, valid arguments are the members of Triangulation except Unknown or AssumeValid, and Pyomo will use that method to triangulate the domain and to tag the resulting PWLF. If no argument or None is passed, the default is Triangulation.Delaunay. When constructed using methods (2) or (3) above, valid arguments are only Triangulation.Unknown and Triangulation.AssumeValid. Pyomo will tag the constructed PWLF as specified, trusting the user in the case of AssumeValid. When no argument or None is passed, the default is Triangulation.Unknown
Methods
__init__
(*args, **kwargs)Constructor
activate
()Set the active attribute to True
clear
()Clear the data in this component
clear_suffix_value
(suffix_or_name[, expand])Clear the suffix value for this component data
cname
(*args, **kwds)DEPRECATED.
construct
([data])Initialize the block
Set the active attribute to False
dim
()Return the dimension of the index
display
([filename, ostream, prefix])Display values in the block
get_suffix_value
(suffix_or_name[, default])Get the suffix value for this component data
getname
([fully_qualified, name_buffer, ...])Returns the component name associated with this object.
Return an dictionary id->index for all ComponentData instances.
Return the index set
Return True if this class is a Pyomo component
Return True if this class has been constructed
is_expression_type
([expression_system])Return True if this numeric value is an expression
Return true if this component is indexed
Return True if this class is a Pyomo Boolean object.
Return True if this numeric value is a named expression
Return True if this class is a Pyomo numeric object
Return False unless this class is a parameter object
Return True if this component is a reference, where "reference" is interpreted as any component that does not own its own data.
Return False unless this class is a variable object
items
([sort, ordered])Return an iterator of (index,data) component data tuples
DEPRECATED.
iterkeys
()DEPRECATED.
DEPRECATED.
keys
([sort, ordered])Return an iterator over the component data keys
model
()Returns the model associated with this object.
Returns the parent of this object.
Returns the component associated with this object.
pprint
([ostream, verbose, prefix])Print component information
reconstruct
([data])REMOVED: reconstruct() was removed in Pyomo 6.0.
register_private_data_initializer
(initializer)Return self.model()
set_suffix_value
(suffix_or_name, value[, expand])Set the suffix value for this component data
set_value
(value)Set the value of a scalar component.
TODO
type
()DEPRECATED.
Return True if this can be used as a model component.
values
([sort, ordered])Return an iterator of the component data objects
Attributes
Return the active attribute
Return the class type for this component
Get the component name only within the context of the immediate parent container.
Get the fully qualified component name.
Member Documentation
- activate()
Set the active attribute to True
- clear()
Clear the data in this component
- clear_suffix_value(suffix_or_name, expand=True)
Clear the suffix value for this component data
- cname(*args, **kwds)
DEPRECATED.
Deprecated since version 5.0: The cname() method has been renamed to getname(). The preferred method of obtaining a component name is to use the .name property, which returns the fully qualified component name. The .local_name property will return the component name only within the context of the immediate parent container.
- construct(data=None)
Initialize the block
- deactivate()
Set the active attribute to False
- dim()
Return the dimension of the index
- display(filename=None, ostream=None, prefix='')
Display values in the block
- get_suffix_value(suffix_or_name, default=None)
Get the suffix value for this component data
- getname(fully_qualified=False, name_buffer=None, relative_to=None)
Returns the component name associated with this object.
- id_index_map()
Return an dictionary id->index for all ComponentData instances.
- index_set()
Return the index set
- is_component_type()
Return True if this class is a Pyomo component
- is_constructed()
Return True if this class has been constructed
- is_expression_type(expression_system=None)
Return True if this numeric value is an expression
- is_indexed()
Return true if this component is indexed
- 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()
Return False unless this class is a parameter object
- is_reference()
Return True if this component is a reference, where “reference” is interpreted as any component that does not own its own data.
- is_variable_type()
Return False unless this class is a variable object
- items(sort=<SortComponents.UNSORTED: 0>, ordered=NOTSET)
Return an iterator of (index,data) component data tuples
- Parameters:
sort (bool or SortComponents) – Iterate over the declared component items in a specified sorted order. See
SortComponents
for valid options and descriptions.ordered (bool) – DEPRECATED: Please use sort=SortComponents.ORDERED_INDICES. If True, then the items are returned in a deterministic order (using the underlying set’s ordered_iter().
- iteritems()
DEPRECATED.
Return a list (index,data) tuples from the dictionary
Deprecated since version 6.0: The iteritems method is deprecated. Use dict.items().
- iterkeys()
DEPRECATED.
Return a list of keys in the dictionary
Deprecated since version 6.0: The iterkeys method is deprecated. Use dict.keys().
- itervalues()
DEPRECATED.
Return a list of the component data objects in the dictionary
Deprecated since version 6.0: The itervalues method is deprecated. Use dict.values().
- keys(sort=<SortComponents.UNSORTED: 0>, ordered=NOTSET)
Return an iterator over the component data keys
This method sets the ordering of component data objects within this IndexedComponent container. For consistency,
__init__()
,values()
, anditems()
all leverage this method to ensure consistent ordering.- Parameters:
sort (bool or SortComponents) – Iterate over the declared component keys in a specified sorted order. See
SortComponents
for valid options and descriptions.ordered (bool) – DEPRECATED: Please use sort=SortComponents.ORDERED_INDICES. If True, then the keys are returned in a deterministic order (using the underlying set’s ordered_iter()).
- model()
Returns the model associated with this object.
- parent_block()
Returns the parent of this object.
- parent_component()
Returns the component associated with this object.
- pprint(ostream=None, verbose=False, prefix='')
Print component information
- reconstruct(data=None)
REMOVED: reconstruct() was removed in Pyomo 6.0.
Re-constructing model components was fragile and did not correctly update instances of the component used in other components or contexts (this was particularly problemmatic for Var, Param, and Set). Users who wish to reproduce the old behavior of reconstruct(), are comfortable manipulating non-public interfaces, and who take the time to verify that the correct thing happens to their model can approximate the old behavior of reconstruct with:
component.clear() component._constructed = False component.construct()
- root_block()
Return self.model()
- set_suffix_value(suffix_or_name, value, expand=True)
Set the suffix value for this component data
- set_value(value)
Set the value of a scalar component.
- to_dense_data()
TODO
- type()
DEPRECATED.
Return the class type for this component
Deprecated since version 5.7: Component.type() method has been replaced by the .ctype property.
- valid_model_component()
Return True if this can be used as a model component.
- values(sort=<SortComponents.UNSORTED: 0>, ordered=NOTSET)
Return an iterator of the component data objects
- Parameters:
sort (bool or SortComponents) – Iterate over the declared component values in a specified sorted order. See
SortComponents
for valid options and descriptions.ordered (bool) – DEPRECATED: Please use sort=SortComponents.ORDERED_INDICES. If True, then the values are returned in a deterministic order (using the underlying set’s ordered_iter().
- property active
Return the active attribute
- property ctype
Return the class type for this component
- property local_name
Get the component name only within the context of the immediate parent container.
- property name
Get the fully qualified component name.