Skip to content

interval

Interval(feature, left_endpoint, right_endpoint, min_value, max_value)

Represents an interval for a specific feature.

The interval belongs to one equivalence class.

Attributes:

feature: int Index of the feature to which the interval belongs.

IntervalEndpoint

Indicates whether the interval is left-open or left-closed.

IntervalEndpoint

Indicates whether the interval is right-open or right-closed.

int | float

Lower bound of the interval.

int | float

Upper bound of the interval.

Initializes an Interval object.

Parameters:

Name Type Description Default
feature int

Index of the feature to which the interval belongs.

required
left_endpoint IntervalEndpoint

Left endpoint type ('(' for open, '[' for closed).

required
right_endpoint IntervalEndpoint

Right endpoint type (')' for open, ']' for closed).

required
min_value float

Lower bound of the interval.

required
max_value float

Upper bound of the interval.

required
Source code in src/flowcean/testing/generator/ddtig/domain/model_analyser/surrogate/interval.py
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
def __init__(
    self,
    feature: int,
    left_endpoint: IntervalEndpoint,
    right_endpoint: IntervalEndpoint,
    min_value: float,
    max_value: float,
) -> None:
    """Initializes an Interval object.

    Args:
        feature: Index of the feature to which the interval belongs.
        left_endpoint: Left endpoint type ('(' for open, '[' for closed).
        right_endpoint: Right endpoint type
            (')' for open, ']' for closed).
        min_value: Lower bound of the interval.
        max_value: Upper bound of the interval.
    """
    self.feature = feature
    self.left_endpoint = left_endpoint
    self.right_endpoint = right_endpoint
    self.min_value = min_value
    self.max_value = max_value

__str__()

Returns a string representation of the interval.

Source code in src/flowcean/testing/generator/ddtig/domain/model_analyser/surrogate/interval.py
53
54
55
56
57
58
59
60
61
def __str__(self) -> str:
    """Returns a string representation of the interval."""
    return (
        self.left_endpoint.value
        + str(self.min_value)
        + ","
        + str(self.max_value)
        + self.right_endpoint.value
    )

is_closed()

Checks if the interval is fully closed [a, b].

Returns:

Type Description
bool

True if both endpoints are closed.

Source code in src/flowcean/testing/generator/ddtig/domain/model_analyser/surrogate/interval.py
63
64
65
66
67
68
69
70
71
72
def is_closed(self) -> bool:
    """Checks if the interval is fully closed [a, b].

    Returns:
        True if both endpoints are closed.
    """
    return (
        self.left_endpoint == IntervalEndpoint.LEFT_CLOSED
        and self.right_endpoint == IntervalEndpoint.RIGHT_CLOSED
    )

is_open()

Checks if the interval is fully open (a, b).

Returns:

Type Description
bool

True if both endpoints are open.

Source code in src/flowcean/testing/generator/ddtig/domain/model_analyser/surrogate/interval.py
74
75
76
77
78
79
80
81
82
83
def is_open(self) -> bool:
    """Checks if the interval is fully open (a, b).

    Returns:
        True if both endpoints are open.
    """
    return (
        self.left_endpoint == IntervalEndpoint.LEFT_OPEN
        and self.right_endpoint == IntervalEndpoint.RIGHT_OPEN
    )

is_right_open()

Checks if the interval is right-open [a, b).

Returns:

Type Description
bool

True if left is closed and right is open.

Source code in src/flowcean/testing/generator/ddtig/domain/model_analyser/surrogate/interval.py
85
86
87
88
89
90
91
92
93
94
def is_right_open(self) -> bool:
    """Checks if the interval is right-open [a, b).

    Returns:
        True if left is closed and right is open.
    """
    return (
        self.left_endpoint == IntervalEndpoint.LEFT_CLOSED
        and self.right_endpoint == IntervalEndpoint.RIGHT_OPEN
    )

is_left_open()

Checks if the interval is left-open (a, b].

Returns:

Type Description
bool

True if left is open and right is closed.

Source code in src/flowcean/testing/generator/ddtig/domain/model_analyser/surrogate/interval.py
 96
 97
 98
 99
100
101
102
103
104
105
def is_left_open(self) -> bool:
    """Checks if the interval is left-open (a, b].

    Returns:
        True if left is open and right is closed.
    """
    return (
        self.left_endpoint == IntervalEndpoint.RIGHT_CLOSED
        and self.right_endpoint == IntervalEndpoint.LEFT_OPEN
    )

is_subset(interval_a, interval_b) staticmethod

Determines which interval is a subset of the other.

Parameters:

Name Type Description Default
interval_a Interval

First interval to compare.

required
interval_b Interval

Second interval to compare.

required

Returns:

Type Description
Interval | None

The superset interval if one contains the other,

Interval | None

otherwise None.

Source code in src/flowcean/testing/generator/ddtig/domain/model_analyser/surrogate/interval.py
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
@staticmethod
def is_subset(
    interval_a: Interval,
    interval_b: Interval,
) -> Interval | None:
    """Determines which interval is a subset of the other.

    Args:
        interval_a: First interval to compare.
        interval_b: Second interval to compare.

    Returns:
        The superset interval if one contains the other,
        otherwise None.
    """
    ordered = Interval._order_by_bounds(interval_a, interval_b)
    if ordered is None:
        return None

    interval_large, interval_small = ordered

    # Case 1: Strict containment
    if (
        interval_large.min_value < interval_small.min_value
        and interval_large.max_value > interval_small.max_value
    ):
        return interval_large

    # Case 2: Same lower bound, larger upper bound
    if (
        interval_large.min_value == interval_small.min_value
        and interval_large.max_value > interval_small.max_value
    ):
        left_ok = (
            interval_small.left_endpoint == IntervalEndpoint.LEFT_OPEN
            or interval_large.left_endpoint == IntervalEndpoint.LEFT_CLOSED
        )
        return interval_large if left_ok else None

    # Case 3: Smaller lower bound, same upper bound
    if (
        interval_large.min_value < interval_small.min_value
        and interval_large.max_value == interval_small.max_value
    ):
        right_ok = (
            interval_small.right_endpoint == IntervalEndpoint.RIGHT_OPEN
            or interval_large.right_endpoint
            == IntervalEndpoint.RIGHT_CLOSED
        )
        return interval_large if right_ok else None

    # Case 4: Same bounds
    if (
        interval_a.min_value == interval_b.min_value
        and interval_a.max_value == interval_b.max_value
    ):
        return Interval._same_bounds_superset(interval_a, interval_b)
    return None

IntervalEndpoint

Bases: Enum

Enum representing the types of interval endpoints.