File tree Expand file tree Collapse file tree 1 file changed +11
-7
lines changed
src/gradient_free_optimizers/optimizers/core_optimizer Expand file tree Collapse file tree 1 file changed +11
-7
lines changed Original file line number Diff line number Diff line change @@ -429,15 +429,19 @@ def _iterate(self):
429429 -------
430430 New position as numpy array
431431 """
432- # Retry loop for constraint satisfaction
433432 max_retries = 100
434- for _ in range (max_retries ):
435- clipped_pos = self ._generate_position ()
433+ clipped_pos = self ._generate_position ()
436434
437- # Check constraints
438- if self .conv .not_in_constraint (clipped_pos ):
439- break
440- # If max retries exceeded, use the last generated position anyway
435+ if not self .conv .not_in_constraint (clipped_pos ):
436+ for _ in range (max_retries ):
437+ clipped_pos = self ._generate_position ()
438+ if self .conv .not_in_constraint (clipped_pos ):
439+ break
440+ else :
441+ for _ in range (max_retries ):
442+ clipped_pos = self ._clip_position (self .init .move_random_typed ())
443+ if self .conv .not_in_constraint (clipped_pos ):
444+ break
441445
442446 # Track as new position (property setter auto-appends)
443447 self ._pos_new = clipped_pos
You can’t perform that action at this time.
0 commit comments