Skip to content

Commit

Permalink
EMO changes (bug fixes), Tools change.
Browse files Browse the repository at this point in the history
- Fixed bug in single point binary crossover where the returned
  population size failed when to_mate=None.
- LHS generator: the generator used the len of Problem.variables, which
  causes errors when problems have tensor valued variables. Now uses the
  number of flattened variables.
- Updated deprecated option in CbcOptions.
  • Loading branch information
gialmisi committed Nov 29, 2024
1 parent c85ca73 commit 6b4b9ed
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
5 changes: 4 additions & 1 deletion desdeo/emo/operators/crossover.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ def do(

mating_pop = parent_decision_vars[shuffled_ids]
mating_pop_size = len(shuffled_ids)
original_mating_pop_size = mating_pop_size

if mating_pop_size % 2 != 0:
# if the number of member to mate is of uneven size, copy the first member to the tail
Expand Down Expand Up @@ -317,7 +318,9 @@ def do(
# combine the two offspring populations into one, drop the last member if the number of
# indices (to_mate) is uneven
self.offspring_population = pl.from_numpy(
np.vstack((offspring1, offspring2))[: (len(to_mate) if len(to_mate) % 2 == 0 else -1)],
np.vstack((offspring1, offspring2))[
: (original_mating_pop_size if original_mating_pop_size % 2 == 0 else -1)
],
schema=self.variable_symbols,
).select(pl.all().cast(pl.Float64))
self.notify()
Expand Down
2 changes: 1 addition & 1 deletion desdeo/emo/operators/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def __init__(self, problem: Problem, evaluator: EMOEvaluator, n_points: int, see
At the very least, the publisher argument should be provided.
"""
super().__init__(problem, evaluator, n_points, seed, **kwargs)
self.lhsrng = LatinHypercube(d=len(problem.variables), seed=seed)
self.lhsrng = LatinHypercube(d=len(self.variable_symbols), seed=seed)
self.seed = seed

def do(self) -> tuple[pl.DataFrame, pl.DataFrame]:
Expand Down
2 changes: 1 addition & 1 deletion desdeo/tools/pyomo_solver_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class CbcOptions(BaseModel):
Please add options as they are needed and make a pull request.
"""

model_config = ConfigDict(frozen=True, allow_population_by_field_name=True)
model_config = ConfigDict(frozen=True, populate_by_name=True)

sec: int = Field(
description="The maximum amount of time (in seconds) the solver should run. Defaults to None.", default=None
Expand Down

0 comments on commit 6b4b9ed

Please sign in to comment.