Skip to content

Commit

Permalink
fix initial proposals in mix-int case issue #2235
Browse files Browse the repository at this point in the history
  • Loading branch information
nikohansen committed Nov 22, 2023
1 parent acb0a36 commit 8bdbe68
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions code-experiments/build/python/src/cocoex/interface.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -656,13 +656,13 @@ cdef class Problem:
return self(x) - self.final_target_fvalue1

def initial_solution_proposal(self, restart_number=None):
"""return feasible initial solution proposals.
"""return initial solution proposals.
For unconstrained problems, the proposal is different for each
consecutive call without argument and for each `restart_number`
and may be different under repeated calls with the same
`restart_number`. ``self.initial_solution_proposal(0)`` is the
same as ``self.initial_solution``.
The proposal is different for each consecutive call without
argument and for each `restart_number` and may be different under
repeated calls with the same `restart_number`.
``self.initial_solution_proposal(0)`` is the same as
``self.initial_solution`` and is always feasible.
Conceptual example::
Expand All @@ -672,13 +672,15 @@ cdef class Problem:
while problem.evaluations < budget and not problem.final_target_hit:
fmin(problem, problem.initial_solution_proposal())
Details: by default, the first proposal is the domain middle or
the (only) known feasible solution.
Subsequent proposals are coordinate-wise sampled as the sum
of two iid random variates uniformly distributed within the
domain boundaries. On the ``'bbob'`` suite their density is
0.2 * (x / 5 + 1) for x in [-5, 0] and
Details: by default, the first proposal is the domain middle or the
(only) known feasible solution. Subsequent proposals are
coordinate-wise sampled uniformly at random for discrete variables
and as the sum of two iid random variates uniformly distributed
within the domain boundaries. On the ``'bbob'`` suite their density
is 0.2 * (x / 5 + 1) for x in [-5, 0] and
0.2 * (1 - x / 5) for x in [0, 5] and zero otherwise.
For constrained problems, the initial solution is varied by
(only) +-1.
"""
if restart_number is None:
Expand All @@ -687,8 +689,16 @@ cdef class Problem:
if restart_number <= 0:
return self.initial_solution
rv_triangular = np.random.rand(self.dimension) + np.random.rand(self.dimension)
for i in range(self.number_of_integer_variables):
rv_triangular[i] = np.random.randint(self.lower_bounds[i], self.upper_bounds[i] + 1)
if self.number_of_constraints > 0:
return self.initial_solution + 1.0 * (rv_triangular - 1)
rv_triangular[self._number_of_integer_variables:] += -1 + self.initial_solution[self._number_of_integer_variables:]
# returns self.initial_solution + rv_triangular - 1
else:
rv_triangular[self._number_of_integer_variables:] *= (self.upper_bounds[self._number_of_integer_variables:] -
self.lower_bounds[self._number_of_integer_variables:]) / 2
rv_triangular[self._number_of_integer_variables:] += self.lower_bounds[self._number_of_integer_variables:]
return rv_triangular
return self.lower_bounds + rv_triangular * (
self.upper_bounds - self.lower_bounds) / 2
@property
Expand Down

0 comments on commit 8bdbe68

Please sign in to comment.