Changeset 9492


Ignore:
Timestamp:
Dec 14, 2014 10:51:17 PM (4 years ago)
Author:
wehart
Message:

Creating a RealInterval? domain

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pyomo/trunk/pyomo/core/base/set_types.py

    r9247 r9492  
    1414  'NonNegativeReals', 'PercentFraction', 'UnitInterval', 'Integers', 'PositiveIntegers',
    1515  'NonPositiveIntegers', 'NegativeIntegers', 'NonNegativeIntegers', 'Boolean',
    16   'Binary'
     16  'Binary', 'RealInterval'
    1717]
    1818
     
    2929
    3030_virtual_sets = []
     31
    3132
    3233class _VirtualSet(SimpleSet, pyomo.util.plugin.Plugin):
     
    6768        return True
    6869
     70
    6971class _AnySetWithNone(_AnySet):
    7072    """A virtual set that allows any value (including None)"""
     
    7274    def __contains__(self, element):
    7375        return True
     76
    7477
    7578class RealSet(_VirtualSet):
     
    107110        return _VirtualSet.__contains__(self, element) and \
    108111            ( element.__class__ in native_integer_types )
     112
    109113
    110114class BooleanSet(_VirtualSet):
     
    124128               and ( element.__class__ in native_boolean_types ) \
    125129               and ( element in (0, 1, True, False, 'True', 'False', 'T', 'F') )
     130
     131
     132class RealInterval(RealSet):
     133    """A virtual set that represents an interval of real values"""
     134
     135    def __init__(self, *args, **kwds):
     136        """Constructor"""
     137        if not 'bounds' in kwds:
     138            kwds['bounds'] = (None,None)
     139        _bounds = kwds['bounds']
     140        def validate_interval(model,x): return (_bounds[0] is None or x >= _bounds[0]) and (_bounds[1] is None or x <= _bounds[1])
     141        kwds['validate'] = validate_interval
     142        RealSet.__init__(self, *args, **kwds)
     143
    126144
    127145#
Note: See TracChangeset for help on using the changeset viewer.