Skip to content

Commit 8056794

Browse files
committed
dimension() implemented in constraints
1 parent 0b0cc6a commit 8056794

File tree

11 files changed

+95
-13
lines changed

11 files changed

+95
-13
lines changed

python/opengen/constraints/ball1.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,6 @@ def is_compact(self):
7575
return True
7676

7777
def dimension(self):
78-
return super().dimension()
78+
if self.center is None:
79+
return None
80+
return len(self.center)

python/opengen/constraints/ball2.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
class Ball2(Constraint):
88
"""A Euclidean ball constraint
99
10-
A constraint of the form :math:`\|u-u_0\| \leq r`, where :math:`u_0` is the center
10+
A constraint of the form :math:`\Vert u-u_0 \Vert \leq r`, where :math:`u_0` is the center
1111
of the ball and `r` is its radius
1212
1313
"""
@@ -93,4 +93,6 @@ def is_compact(self):
9393
return True
9494

9595
def dimension(self):
96-
return super().dimension()
96+
if self.center is None:
97+
return None
98+
return len(self.center)

python/opengen/constraints/ball_inf.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,6 @@ def is_compact(self):
9090
return True
9191

9292
def dimension(self):
93-
return super().dimension()
93+
if self.center is None:
94+
return None
95+
return len(self.center)

python/opengen/constraints/cartesian.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,4 @@ def is_compact(self):
126126
return True
127127

128128
def dimension(self):
129-
return super().dimension()
129+
return self.segments[-1] + 1

python/opengen/constraints/no_constraints.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ def is_compact(self):
2323
return False
2424

2525
def dimension(self):
26-
return super().dimension()
26+
return None

python/opengen/constraints/rectangle.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def __check_xmin_xmax(cls, xmin, xmax):
3131
if xmin_element > xmax_element:
3232
raise Exception("xmin must be <= xmax")
3333

34-
def __init__(self, xmin, xmax):
34+
def __init__(self, xmin=None, xmax=None):
3535
"""Construct a new instance of Rectangle
3636
3737
:param xmin: minimum bounds (can be ``None``)

python/opengen/constraints/simplex.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,4 @@ def is_compact(self):
105105
return True
106106

107107
def dimension(self):
108-
return super().dimension()
108+
return None

python/opengen/constraints/soc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,4 @@ def is_compact(self):
8787
return False
8888

8989
def dimension(self):
90-
return super().dimension()
90+
return None

python/opengen/constraints/sphere2.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,8 @@ def is_convex(self):
7575

7676
def is_compact(self):
7777
return True
78+
79+
def dimension(self):
80+
if self.center is None:
81+
return None
82+
return len(self.center)

python/opengen/constraints/zero.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@
77
class Zero(Constraint):
88
"""A set that contains only the origin
99
10-
The singleton :math:`\{0\}`
10+
The singleton :math:`\\{0\\}`
1111
1212
"""
1313

1414
def __init__(self):
1515
"""
16-
Constructor for set :math:`Z = \{0\}`
16+
Constructor for set :math:`Z = \\{0\\}`
1717
1818
"""
19+
pass
1920

2021
def distance_squared(self, u):
2122
return fn.norm2_squared(u)
@@ -29,3 +30,5 @@ def is_convex(self):
2930
def is_compact(self):
3031
return True
3132

33+
def dimension(self):
34+
return None

0 commit comments

Comments
 (0)