SimplePort
(class from pyomo.network.port
)
- class pyomo.network.port.SimplePort(*args, **kwargs)[source]
Bases:
ScalarPort
- __init__(*args, **kwd)
Methods
Equality
(port, name, index_set)Arc Expansion procedure to generate simple equality constraints
Extensive
(port, name, index_set[, ...])Arc Expansion procedure for extensive variable properties
__init__
(*args, **kwd)add
(var[, name, rule])Add var to this Port, casting it to a Pyomo numeric if necessary
arcs
([active])A list of Arcs in which this Port is a member
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])API definition for constructing components
dests
([active])A list of Arcs in which this Port is a source
dim
()Return the dimension of the index
display
([prefix, ostream])Print component state information
fix
()Fix all variables in the port at their current values.
free
()Unfix all variables in the port.
get_split_fraction
(arc)Returns a tuple (val, fix) for the split fraction of this arc that was set via set_split_fraction if it exists, and otherwise None.
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.
index
()Returns the index of this ComponentData instance relative to the parent component index set.
Return the index set
Return True if all variables in the Port are binary
Return True if this class is a Pyomo component
Return True if this class has been constructed
Return True if all variables in the Port are continuous
is_equality
(name)Return True if the rule for this port member is Port.Equality
is_expression_type
([expression_system])Return True if this numeric value is an expression
is_extensive
(name)Return True if the rule for this port member is Port.Extensive
is_fixed
()Return True if all vars/expressions in the Port are fixed
Return true if this component is indexed
Return True if all variables in the Port are integer
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 as ports may (should!) contain variables
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
iter_vars
([expr_vars, fixed, names])Iterate through every member of the port, going through the indices of indexed members.
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.
Returns the maximum polynomial degree of all port members
pprint
([ostream, verbose, prefix])Print component information
reconstruct
([data])REMOVED: reconstruct() was removed in Pyomo 6.0.
remove
(name)Remove this member from the port
Return self.model()
rule_for
(name)Return the rule associated with the given port member
set_split_fraction
(arc, val[, fix])Set the split fraction value to be used for an arc during arc expansion when using Port.Extensive.
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.
sources
([active])A list of Arcs in which this Port is a destination
TODO
type
()DEPRECATED.
unfix
()Unfix all variables in the port.
Return True if this can be used as a model component.
values
([sort, ordered])Return an iterator of the component data objects
Attributes
vars
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
- static Equality(port, name, index_set)
Arc Expansion procedure to generate simple equality constraints
- static Extensive(port, name, index_set, include_splitfrac=None, write_var_sum=True)
Arc Expansion procedure for extensive variable properties
This procedure is the rule to use when variable quantities should be conserved; that is, split for outlets and combined for inlets.
This will first go through every destination of the port (i.e., arcs whose source is this Port) and create a new variable on the arc’s expanded block of the same index as the current variable being processed to store the amount of the variable that flows over the arc. For ports that have multiple outgoing arcs, this procedure will create a single splitfrac variable on the arc’s expanded block as well. Then it will generate constraints for the new variable that relate it to the port member variable using the split fraction, ensuring that all extensive variables in the Port are split using the same ratio. The generation of the split fraction variable and constraint can be suppressed by setting the include_splitfrac argument to False.
Once all arc-specific variables are created, this procedure will create the “balancing constraint” that ensures that the sum of all the new variables equals the original port member variable. This constraint can be suppressed by setting the write_var_sum argument to False; in which case, a single constraint will be written that states the sum of the split fractions equals 1.
Finally, this procedure will go through every source for this port and create a new arc variable (unless it already exists), before generating the balancing constraint that ensures the sum of all the incoming new arc variables equals the original port variable.
Model simplifications:
If the port has a 1-to-1 connection on either side, it will not create the new variables and instead write a simple equality constraint for that side.
If the outlet side is not 1-to-1 but there is only one outlet, it will not create a splitfrac variable or write the split constraint, but it will still write the outsum constraint which will be a simple equality.
If the port only contains a single Extensive variable, the splitfrac variables and the splitting constraints will be skipped since they will be unnecessary. However, they can be still be included by passing include_splitfrac=True.
Note
If split fractions are skipped, the write_var_sum=False option is not allowed.
- add(var, name=None, rule=None, **kwds)
Add var to this Port, casting it to a Pyomo numeric if necessary
- Parameters:
var – A variable or some NumericValue like an expression
name (str) – Name to associate with this member of the Port
rule (function) – Function implementing the desired expansion procedure for this member. Port.Equality by default, other options include Port.Extensive. Customs are allowed.
kwds – Keyword arguments that will be passed to rule
- arcs(active=None)
A list of Arcs in which this Port is a member
- 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)
API definition for constructing components
- dests(active=None)
A list of Arcs in which this Port is a source
- dim()
Return the dimension of the index
- display(prefix='', ostream=None)
Print component state information
This duplicates logic in Component.pprint()
- fix()
Fix all variables in the port at their current values. For expressions, fix every variable in the expression.
- free()
Unfix all variables in the port. For expressions, unfix every variable in the expression.
- get_split_fraction(arc)
Returns a tuple (val, fix) for the split fraction of this arc that was set via set_split_fraction if it exists, and otherwise None.
- 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()
Returns the index of this ComponentData instance relative to the parent component index set. None is returned if this instance does not have a parent component, or if - for some unknown reason - this instance does not belong to the parent component’s index set.
- index_set()
Return the index set
- is_binary()
Return True if all variables in the Port are binary
- is_component_type()
Return True if this class is a Pyomo component
- is_constructed()
Return True if this class has been constructed
- is_continuous()
Return True if all variables in the Port are continuous
- is_equality(name)
Return True if the rule for this port member is Port.Equality
- is_expression_type(expression_system=None)
Return True if this numeric value is an expression
- is_extensive(name)
Return True if the rule for this port member is Port.Extensive
- is_fixed()
Return True if all vars/expressions in the Port are fixed
- is_indexed()
Return true if this component is indexed
- is_integer()
Return True if all variables in the Port are integer
- 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_potentially_variable()
Return True as ports may (should!) contain variables
- 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().
- iter_vars(expr_vars=False, fixed=None, names=False)
Iterate through every member of the port, going through the indices of indexed members.
- Parameters:
expr_vars (bool) – If True, call identify_variables on expression type members
fixed (bool) – Only include variables/expressions with this type of fixed
names (bool) – If True, yield (name, index, var/expr) tuples
- 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.
- polynomial_degree()
Returns the maximum polynomial degree of all port members
- 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()
- remove(name)
Remove this member from the port
- root_block()
Return self.model()
- rule_for(name)
Return the rule associated with the given port member
- set_split_fraction(arc, val, fix=True)
Set the split fraction value to be used for an arc during arc expansion when using Port.Extensive.
- 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.
- sources(active=None)
A list of Arcs in which this Port is a destination
- 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.
- unfix()
Unfix all variables in the port. For expressions, unfix every variable in the expression.
- 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.