Skip to content

Commit 25e7b9f

Browse files
committed
Test lb < ub
1 parent 3740fa8 commit 25e7b9f

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

tests/test_constraint.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,3 +175,28 @@ def constraint_function(a, b):
175175
init_points=2,
176176
n_iter=10,
177177
)
178+
179+
def test_lower_less_than_upper():
180+
def target_function(x, y):
181+
return np.cos(2 * x) * np.cos(y) + np.sin(x)
182+
183+
def constraint_function_2_dim(x, y):
184+
return np.array([
185+
-np.cos(x) * np.cos(y) + np.sin(x) * np.sin(y),
186+
-np.cos(x) * np.cos(-y) + np.sin(x) * np.sin(-y)
187+
])
188+
189+
constraint_limit_lower = np.array([0.6, -np.inf])
190+
constraint_limit_upper = np.array([0.3, 0.6])
191+
192+
conmod = NonlinearConstraint(constraint_function_2_dim, constraint_limit_lower, constraint_limit_upper)
193+
pbounds = {'x': (0, 6), 'y': (0, 6)}
194+
195+
with raises(ValueError):
196+
optimizer = BayesianOptimization(
197+
f=target_function,
198+
constraint=conmod,
199+
pbounds=pbounds,
200+
verbose=0,
201+
random_state=1,
202+
)

0 commit comments

Comments
 (0)