22
33from PEPit .function import Function
44
5-
65class ConvexIndicatorFunction (Function ):
76 """
87 The :class:`ConvexIndicatorFunction` class overwrites the `add_class_constraints` method of :class:`Function`,
@@ -11,15 +10,19 @@ class ConvexIndicatorFunction(Function):
1110 Attributes:
1211 D (float): upper bound on the diameter of the feasible set, possibly set to np.inf
1312 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.
1414 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- >>> func = problem.declare_function(function_class=ConvexIndicatorFunction, R=1)
22-
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+
2326 References:
2427
2528 `[1] A. Taylor, J. Hendrickx, F. Glineur (2017).
@@ -32,6 +35,7 @@ class ConvexIndicatorFunction(Function):
3235 def __init__ (self ,
3336 D = np .inf ,
3437 R = np .inf ,
38+ center = None ,
3539 is_leaf = True ,
3640 decomposition_dict = None ,
3741 reuse_gradient = False ,
@@ -41,6 +45,8 @@ def __init__(self,
4145 Args:
4246 D (float): Diameter of the support of self. Default value set to infinity.
4347 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.
4450 is_leaf (bool): True if self is defined from scratch.
4551 False if self is defined as linear combination of leaf.
4652 decomposition_dict (dict): Decomposition of self as linear combination of leaf :class:`Function` objects.
@@ -59,7 +65,10 @@ def __init__(self,
5965
6066 # Store the diameter D in an attribute
6167 self .D = D
68+ # Store the radius R in an attribute
6269 self .R = R
70+ # Store the center in an attribute
71+ self .center = center
6372
6473 @staticmethod
6574 def set_value_constraint_i (xi , gi , fi ):
@@ -94,8 +103,16 @@ def set_diameter_constraint_i_j(self,
94103 """
95104 # Diameter constraint
96105 constraint = ((xi - xj ) ** 2 <= self .D ** 2 )
106+
97107 # Radius constraint
98- constraint = ((xi )** 2 <= self .R ** 2 )
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+
99116 return constraint
100117
101118 def add_class_constraints (self ):
0 commit comments