Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions python/opengen/constraints/rectangle.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,12 @@ def is_orthant(self):

:rtype: boolean
"""
chk_orthant = True
for x_min_i in self.__xmin:
chk_orthant &= (x_min_i == 0 or x_min_i == float(
'inf') or x_min_i == float('-inf'))
for x_max_i in self.__xmax:
chk_orthant &= (x_max_i == 0 or x_max_i == float(
'inf') or x_max_i == float('-inf'))
return chk_orthant
xmin = ([float('-inf')] * self.dimension()
if self.__xmin is None else self.__xmin)
xmax = ([float('inf')] * self.dimension()
if self.__xmax is None else self.__xmax)
return all(
(lower == 0 and upper == float('inf')) or
(lower == float('-inf') and upper == 0)
for lower, upper in zip(xmin, xmax)
)
13 changes: 13 additions & 0 deletions python/test/test_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,19 @@ def test_rectangle_is_orthant(self):
rect = og.constraints.Rectangle([-1.0, float('-inf')], [10.0, 3.0])
self.assertFalse(rect.is_orthant())

def test_rectangle_is_orthant_one_sided_and_degenerate(self):
cases = [
(None, [0], True),
([0], None, True),
([0], [0], False),
([float('-inf')], [float('inf')], False),
([-1], [1], False),
]
for xmin, xmax, expected in cases:
with self.subTest(xmin=xmin, xmax=xmax):
self.assertEqual(
og.constraints.Rectangle(xmin, xmax).is_orthant(), expected)

def test_rectangle_dimension(self):
rec_only_xmin = og.constraints.Rectangle(xmin=[1])
rec_only_xmax = og.constraints.Rectangle(xmax=[5, 6])
Expand Down