ContinuousSet

(class from pyomo.dae.contset)

class pyomo.dae.contset.ContinuousSet(*args, **kwds)[source]

Bases: SortedScalarSet

Represents a bounded continuous domain

Minimally, this set must contain two numeric values defining the bounds of a continuous range. Discrete points of interest may be added to the continuous set. A continuous set is one dimensional and may only contain numerical values.

Parameters:
  • initialize (list) – Default discretization points to be included

  • bounds (tuple) – The bounding points for the continuous domain. The bounds will be included as discrete points in the ContinuousSet and will be used to bound the points added to the ContinuousSet through the ‘initialize’ argument, a data file, or the add() method

_changed

This keeps track of whether or not the ContinuousSet was changed during discretization. If the user specifies all of the needed discretization points before the discretization then there is no need to go back through the model and reconstruct things indexed by the ContinuousSet

Type:

boolean

_fe

This is a sorted list of the finite element points in the ContinuousSet. i.e. this list contains all the discrete points in the ContinuousSet that are not collocation points. Points that are both finite element points and collocation points will be included in this list.

Type:

list

_discretization_info

This is a dictionary which contains information on the discretization transformation which has been applied to the ContinuousSet.

Type:

dict

__init__(*args, **kwds)[source]

Constructor

Methods

__init__(*args, **kwds)

Constructor

add(*values)

at(index)

Return the specified member of the set.

bounds()

card(index)

DEPRECATED.

check_values()

DEPRECATED.

clear()

Clear the data in this component

clear_suffix_value(suffix_or_name[, expand])

Set the suffix value for this component data

cname(*args, **kwds)

DEPRECATED.

construct([values])

Constructs a ContinuousSet component

cross(*args)

Return the cross-product between this set and one or more sets

data()

difference(*args)

Return the difference between this set with one or more sets

dim()

Return the dimension of the index

discard(val)

display([ostream, verbose, prefix])

find_nearest_index(target[, tolerance])

Returns the index of the nearest point in the ContinuousSet.

first()

get(value[, default])

Return True if the set contains a given value.

get_changed()

Returns flag indicating if the ContinuousSet was changed during discretization

get_discretization_info()

Returns a dict with information on the discretization scheme that has been applied to the ContinuousSet.

get_finite_elements()

Returns the finite element points

get_interval()

Return the interval for this Set as (start, end, step)

get_lower_element_boundary(point)

Returns the first finite element point that is less than or equal to 'point'

get_suffix_value(suffix_or_name[, default])

Get the suffix value for this component data

get_upper_element_boundary(point)

Returns the first finite element point that is greater or equal to 'point'

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

Return a string with the component name and index

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.

index_set()

Return the index set

intersection(*args)

Return the intersection of this set with one or more sets

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])

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.

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

isdiscrete()

Returns True if this set admits only discrete members

isdisjoint(other)

Test if this Set is disjoint from other

isfinite()

Returns True if this is a finite discrete (iterable) Set

isordered()

Returns True if this is an ordered finite discrete (iterable) Set

issubset(other)

Test if this Set is a subset of other

issuperset(other)

Test if this Set is a superset of other

items()

Return an iterator of (index,data) tuples from the dictionary

iteritems()

DEPRECATED.

iterkeys()

DEPRECATED.

itervalues()

DEPRECATED.

keys([sort, ordered])

Return an iterator over the component data keys

last()

model()

Return the model of the component that owns this data.

next(item[, step])

Return the next item in the set.

nextw(item[, step])

Return the next item in the set with wrapping if necessary.

ord(item)

Return the position index of the input value.

ordered_data()

ordered_iter()

parent_block()

Return the parent of the component that owns this data.

parent_component()

Returns the component associated with this object.

pop()

pprint([ostream, verbose, prefix])

Print component information

prev(item[, step])

Return the previous item in the set.

prevw(item[, step])

Return the previous item in the set with wrapping if necessary.

ranges()

reconstruct([data])

REMOVED: reconstruct() was removed in Pyomo 6.0.

remove(val)

root_block()

Return self.model()

set_changed(newvalue)

Sets the _changed flag to 'newvalue'

set_suffix_value(suffix_or_name, value[, expand])

Set the suffix value for this component data

set_value(val)

Set the value of a scalar component.

sorted_data()

sorted_iter()

subsets([expand_all_set_operators])

symmetric_difference(other)

Return the symmetric difference of this set with another set

to_dense_data()

TODO

type()

DEPRECATED.

union(*args)

Return the union of this set with one or more sets.

update(values)

valid_model_component()

Return True if this can be used as a model component.

values()

Return an iterator of the component data objects in the dictionary

Attributes

active

Return the active attribute

concrete

DEPRECATED.

ctype

Return the class type for this component

dimen

domain

filter

DEPRECATED.

local_name

Get the component name only within the context of the immediate parent container.

name

Get the fully qualified component name.

ordered

DEPRECATED.

value

DEPRECATED.

value_list

DEPRECATED.

virtual

DEPRECATED.

Member Documentation

at(index)

Return the specified member of the set.

The public Set API is 1-based, even though the internal _lookup and _values are (pythonically) 0-based.

card(index)

DEPRECATED.

Deprecated since version 6.1.2: card() was incorrectly added to the Set API. Please use at() (will be removed in (or after) 6.2)

check_values()

DEPRECATED.

Verify that the values in this set are valid.

Deprecated since version 5.7: check_values() is deprecated: Sets only contain valid members

clear()

Clear the data in this component

clear_suffix_value(suffix_or_name, expand=True)

Set 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(values=None)[source]

Constructs a ContinuousSet component

cross(*args)

Return the cross-product between this set and one or more sets

difference(*args)

Return the difference between this set with one or more sets

dim()

Return the dimension of the index

find_nearest_index(target, tolerance=None)[source]

Returns the index of the nearest point in the ContinuousSet.

If a tolerance is specified, the index will only be returned if the distance between the target and the closest point is less than or equal to that tolerance. If there is a tie for closest point, the index on the left is returned.

Parameters:
  • target (float)

  • tolerance (float or None)

Return type:

float or None

get(value, default=None)

Return True if the set contains a given value.

This method will raise TypeError for unhashable types.

get_changed()[source]

Returns flag indicating if the ContinuousSet was changed during discretization

Returns “True” if additional points were added to the ContinuousSet while applying a discretization scheme

Return type:

boolean

get_discretization_info()[source]

Returns a dict with information on the discretization scheme that has been applied to the ContinuousSet.

Return type:

dict

get_finite_elements()[source]

Returns the finite element points

If the ContinuousSet has been discretizaed using a collocation scheme, this method will return a list of the finite element discretization points but not the collocation points within each finite element. If the ContinuousSet has not been discretized or a finite difference discretization was used, this method returns a list of all the discretization points in the ContinuousSet.

Return type:

list of floats

get_interval()

Return the interval for this Set as (start, end, step)

Returns the effective interval for this Set as a (start, end, step) tuple. Start and End are the same as returned by bounds(). Step is 0 for continuous ranges, a positive value for regular discrete sets (e.g., 1 for Integers), or None for Sets that do not have a regular interval (e.g., semicontinuous sets, mixed type sets, sets with dimen != 1, etc).

get_lower_element_boundary(point)[source]

Returns the first finite element point that is less than or equal to ‘point’

Parameters:

point (float)

Return type:

float

get_suffix_value(suffix_or_name, default=None)

Get the suffix value for this component data

get_upper_element_boundary(point)[source]

Returns the first finite element point that is greater or equal to ‘point’

Parameters:

point (float)

Return type:

float

getname(fully_qualified=False, name_buffer=None, relative_to=None)

Return a string with the component name and index

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

intersection(*args)

Return the intersection of this set with one or more sets

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

isdiscrete()

Returns True if this set admits only discrete members

isdisjoint(other)

Test if this Set is disjoint from other

Parameters:

other (Set or iterable) – The Set or iterable object to compare this Set against

Returns:

bool

Return type:

True if this set is disjoint from other

isfinite()

Returns True if this is a finite discrete (iterable) Set

isordered()

Returns True if this is an ordered finite discrete (iterable) Set

issubset(other)

Test if this Set is a subset of other

Parameters:

other (Set or iterable) – The Set or iterable object to compare this Set against

Returns:

bool

Return type:

True if this set is a subset of other

issuperset(other)

Test if this Set is a superset of other

Parameters:

other (Set or iterable) – The Set or iterable object to compare this Set against

Returns:

bool

Return type:

True if this set is a superset of other

items()

Return an iterator of (index,data) tuples from the dictionary

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(), and items() 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()

Return the model of the component that owns this data.

next(item, step=1)

Return the next item in the set.

The default behavior is to return the very next element. The step option can specify how many steps are taken to get the next element.

If the search item is not in the Set, or the next element is beyond the end of the set, then an IndexError is raised.

nextw(item, step=1)

Return the next item in the set with wrapping if necessary.

The default behavior is to return the very next element. The step option can specify how many steps are taken to get the next element. If the next element is past the end of the Set, the search wraps back to the beginning of the Set.

If the search item is not in the Set an IndexError is raised.

ord(item)

Return the position index of the input value.

Note that Pyomo Set objects have positions starting at 1 (not 0).

If the search item is not in the Set, then an IndexError is raised.

parent_block()

Return the parent of the component that owns this data.

parent_component()

Returns the component associated with this object.

pprint(ostream=None, verbose=False, prefix='')

Print component information

prev(item, step=1)

Return the previous item in the set.

The default behavior is to return the immediately previous element. The step option can specify how many steps are taken to get the previous element.

If the search item is not in the Set, or the previous element is before the beginning of the set, then an IndexError is raised.

prevw(item, step=1)

Return the previous item in the set with wrapping if necessary.

The default behavior is to return the immediately previouselement. The step option can specify how many steps are taken to get the previous element. If the previous element is past the end of the Set, the search wraps back to the end of the Set.

If the search item is not in the Set an IndexError is raised.

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_changed(newvalue)[source]

Sets the _changed flag to ‘newvalue’

Parameters:

newvalue (boolean)

set_suffix_value(suffix_or_name, value, expand=True)

Set the suffix value for this component data

set_value(val)

Set the value of a scalar component.

symmetric_difference(other)

Return the symmetric difference of this set with another set

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.

union(*args)

Return the union of this set with one or more sets.

valid_model_component()

Return True if this can be used as a model component.

values()

Return an iterator of the component data objects in the dictionary

property active

Return the active attribute

property concrete

DEPRECATED.

Deprecated since version 5.7: The ‘concrete’ attribute is no longer supported. Use isdiscrete() or isfinite()

property ctype

Return the class type for this component

property filter

DEPRECATED.

Deprecated since version 5.7: ‘filter’ is no longer a public attribute.

property local_name

Get the component name only within the context of the immediate parent container.

property name

Get the fully qualified component name.

property ordered

DEPRECATED.

Deprecated since version 5.7: The ‘ordered’ attribute is no longer supported. Use isordered()

property value

DEPRECATED.

Deprecated since version 5.7: The ‘value’ attribute is deprecated. Use .data() to retrieve the values in a finite set.

property value_list

DEPRECATED.

Deprecated since version 5.7: The ‘value_list’ attribute is deprecated. Use .ordered_data() to retrieve the values from a finite set in a deterministic order.

property virtual

DEPRECATED.

Deprecated since version 5.7: The ‘virtual’ attribute is no longer supported