Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix to rebuild_platypus_population #276

Merged
merged 6 commits into from
Jun 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 28 additions & 3 deletions ema_workbench/em_framework/optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,7 @@ def epsilon_nondominated(results, epsilons, problem):
Returns
-------
DataFrame

Notes
-----
this is a platypus based alternative to pareto.py (https://github.com/matthewjwoodruff/pareto.py)
Expand Down Expand Up @@ -872,13 +873,37 @@ def rebuild_platypus_population(archive, problem):
list of platypus Solutions

"""

expected_columns = problem.nvars + problem.nobjs
actual_columns = len(archive.columns)

if actual_columns != expected_columns:
raise EMAError(
f"The number of columns in the archive ({actual_columns}) does not match the "
f"expected number of decision variables and objectives ({expected_columns})."
)

solutions = []
for row in archive.itertuples():
decision_variables = [getattr(row, attr) for attr in problem.parameter_names]
objectives = [getattr(row, attr) for attr in problem.outcome_names]
try:
decision_variables = [getattr(row, attr) for attr in problem.parameter_names]
except AttributeError:
missing_parameters = [
attr for attr in problem.parameter_names if not hasattr(row, attr)
]
raise EMAError(f"parameter names {missing_parameters} not found in archive")

try:
objectives = [getattr(row, attr) for attr in problem.outcome_names]
except AttributeError:
missing_outcomes = [attr for attr in problem.outcome_names if not hasattr(row, attr)]
raise EMAError(f"outcome names {missing_outcomes} not found in archive'")

solution = Solution(problem)
solution.variables = decision_variables
solution.variables = [
platypus_type.encode(value)
for platypus_type, value in zip(problem.types, decision_variables)
]
solution.objectives = objectives
solutions.append(solution)
return solutions
Expand Down