Skip to content

Commit 250d0e9

Browse files
authored
Merge pull request #103 from ErwanMeunier/master
Added the support of convex indicator for feasible sets bounded by a radius
2 parents 112d209 + c6bc146 commit 250d0e9

1 file changed

Lines changed: 28 additions & 6 deletions

File tree

PEPit/functions/convex_indicator.py

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,27 @@
22

33
from PEPit.function import Function
44

5-
65
class ConvexIndicatorFunction(Function):
76
"""
87
The :class:`ConvexIndicatorFunction` class overwrites the `add_class_constraints` method of :class:`Function`,
98
implementing interpolation constraints for the class of closed convex indicator functions.
109
1110
Attributes:
1211
D (float): upper bound on the diameter of the feasible set, possibly set to np.inf
13-
14-
Convex indicator functions are characterized by a parameter `D`, hence can be instantiated as
12+
R (float): upper bound on the radius of the feasible set, possibly set to np.inf
13+
center (Point): Center of the feasible set spanned by the radius constraint, possibly set to None.
14+
Convex indicator functions are characterized by a parameter `D` (or `R`), hence can be instantiated as
1515
1616
Example:
1717
>>> from PEPit import PEP
18+
>>> from PEPit import Point
1819
>>> from PEPit.functions import ConvexIndicatorFunction
1920
>>> problem = PEP()
20-
>>> func = problem.declare_function(function_class=ConvexIndicatorFunction, D=1)
21-
21+
>>> func1 = problem.declare_function(function_class=ConvexIndicatorFunction, D=1)
22+
>>> func2 = problem.declare_function(function_class=ConvexIndicatorFunction, R=1)
23+
>>> omega = Point()
24+
>>> func3 = problem.declare_function(function_class=ConvexIndicatorFunction, R=1, center=omega)
25+
2226
References:
2327
2428
`[1] A. Taylor, J. Hendrickx, F. Glineur (2017).
@@ -30,6 +34,8 @@ class ConvexIndicatorFunction(Function):
3034

3135
def __init__(self,
3236
D=np.inf,
37+
R=np.inf,
38+
center=None,
3339
is_leaf=True,
3440
decomposition_dict=None,
3541
reuse_gradient=False,
@@ -38,6 +44,9 @@ def __init__(self,
3844
3945
Args:
4046
D (float): Diameter of the support of self. Default value set to infinity.
47+
R (float): Radius of the support of self. Default value set to infinity.
48+
center: Center of the feasible set spanned by the radius constraint of self. Default value set to None.
49+
If the value is None, the feasible set is centered on the origin.
4150
is_leaf (bool): True if self is defined from scratch.
4251
False if self is defined as linear combination of leaf.
4352
decomposition_dict (dict): Decomposition of self as linear combination of leaf :class:`Function` objects.
@@ -56,6 +65,10 @@ def __init__(self,
5665

5766
# Store the diameter D in an attribute
5867
self.D = D
68+
# Store the radius R in an attribute
69+
self.R = R
70+
# Store the center in an attribute
71+
self.center = center
5972

6073
@staticmethod
6174
def set_value_constraint_i(xi, gi, fi):
@@ -91,6 +104,15 @@ def set_diameter_constraint_i_j(self,
91104
# Diameter constraint
92105
constraint = ((xi - xj) ** 2 <= self.D ** 2)
93106

107+
# Radius constraint
108+
if self.R < np.inf:
109+
# No self.center provided centers the ball on the origin
110+
if self.center is None:
111+
constraint = ((xi)**2 <= self.R ** 2)
112+
# Centering the ball on self.center
113+
else:
114+
constraint = ((self.center - xi)**2 <= self.R ** 2)
115+
94116
return constraint
95117

96118
def add_class_constraints(self):
@@ -108,7 +130,7 @@ def add_class_constraints(self):
108130
constraint_name="convexity",
109131
set_class_constraint_i_j=self.set_convexity_constraint_i_j,
110132
)
111-
if self.D != np.inf:
133+
if (self.D != np.inf) or (self.R != np.inf):
112134
self.add_constraints_from_two_lists_of_points(list_of_points_1=self.list_of_points,
113135
list_of_points_2=self.list_of_points,
114136
constraint_name="diameter",

0 commit comments

Comments
 (0)