Sets¶
Constraining Order contains DataStructures to represent sets of discrete elements and real numbers.
A DiscreteSet is a wrapper around pythons builtin frozenset. The main difference is that a DiscreteSet can represent a set of all possible elements.
In addition, there are data structures to represent sets of real numbers, in form of connected Intervals and collections of such intervals, called IntervalSet.
DiscreteSet¶
- class constrainingorder.sets.DiscreteSet(elements)[source]¶
A set data structure for hashable elements
This is a wrapper around pythons set type, which additionally provides the possibility to express the set of everything (which only makes sense sometimes).
- __contains__(element)[source]¶
Check membership of the element.
Parameters: element – Element to check membership of Return type: bool
- __init__(elements)[source]¶
Create a new DiscreteSet
Parameters: elements (sequence) – The elements of the newly created set
- difference(other)[source]¶
Return a new DiscreteSet with the difference of the two sets, i.e. all elements that are in self but not in other.
Parameters: other (DiscreteSet) – Set to subtract Return type: DiscreteSet Raises ValueError: if self is a set of everything
- classmethod everything()[source]¶
Create a new set of everything.
One can not iterate over the elements of this set, but many operations are actually well defined and useful.
- intersection(other)[source]¶
Return a new DiscreteSet with the intersection of the two sets, i.e. all elements that are in both self and other.
Parameters: other (DiscreteSet) – Set to intersect with Return type: DiscreteSet
- is_discrete()[source]¶
Check whether the set is discrete, i.e. if iter_members() can be used.
Return type: bool
Interval¶
- class constrainingorder.sets.Interval(bounds, included)[source]¶
An interval on the real axis.
- __contains__(x)[source]¶
Check membership of the element.
Parameters: x (float) – Element to check membership of Return type: bool
- __init__(bounds, included)[source]¶
Create a new Interval with bounds. If the right bound is larger than the left bound, the interval is assumed to be empty.
Parameters: - bounds (sequence) – left and right bounds
- included (sequence) – bools indicating whether the bounds are included in the interval.
- classmethod closed(a, b)[source]¶
Create a new closed Interval.
Parameters: - a (float) – Left bound
- b (float) – Right bound
- classmethod from_value(value)[source]¶
Create a new Interval representing a single real number.
Parameters: value (float) – The member of the Interval
- get_point()[source]¶
Return the number contained in this interval.
Return type: float Raises ValueError: if Interval contains more than exactly one number.
- intersection(other)[source]¶
Return a new Interval with the intersection of the two intervals, i.e. all elements that are in both self and other.
Parameters: other (Interval) – Interval to intersect with Return type: Interval
- is_disjoint(other)[source]¶
Check whether two Intervals are disjoint.
Parameters: other (Interval) – The Interval to check disjointedness with.
- classmethod leftopen(a, b)[source]¶
Create a new halfopen Interval (left bound is excluded, right bound included).
Parameters: - a (float) – Left bound
- b (float) – Right bound
IntervalSet¶
- class constrainingorder.sets.IntervalSet(ints)[source]¶
A set of intervals to represent quite general sets in R
- __contains__(x)[source]¶
Check membership of the element.
Parameters: element – Element to check membership of Return type: bool
- __init__(ints)[source]¶
Create a new IntervalSet.
Parameters: ints (sequence) – Intervals for this IntervalSet
- difference(other)[source]¶
Return a new IntervalSet with the difference of the two sets, i.e. all elements that are in self but not in other.
Parameters: other (IntervalSet) – Set to subtract Return type: IntervalSet
- classmethod from_values(values)[source]¶
Create a new IntervalSet representing a set of isolated real numbers.
Parameters: values (sequence) – The values for this IntervalSet
- intersection(other)[source]¶
Return a new IntervalSet with the intersection of the two sets, i.e. all elements that are both in self and other.
Parameters: other (IntervalSet) – Set to intersect with Return type: IntervalSet
- is_discrete()[source]¶
Check whether this IntervalSet contains only isolated numbers.
Return type: bool