Skip to content

Conversation

@danyoungday
Copy link
Contributor

We modify our evolution to softly handle constraint violation by using it as a pseudo-objective that is prioritized first.

We also create a direct prescriptor class that directly evolves parameters within a given range.

Finally, we combine the two to optimize a multi-objective problem with constraints.

@danyoungday danyoungday requested a review from Copilot April 25, 2025 18:17
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR updates the evolutionary algorithm to incorporate constraint violation as a pseudo‐objective and adds a new direct prescriptor for evolving parameters directly. Key changes include:

  • Modifying evaluator functions to return metrics together with a constraint violation value (cv) across evaluators and tests.
  • Updating CSV output and corresponding test assertions to account for the new cv field.
  • Introducing the DirectPrescriptor and DirectFactory classes for direct parameter evolution.

Reviewed Changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/test_parallel.py Updated test to account for the new tuple output in evaluate_candidate.
tests/test_cv.py Added tests for constraint violation prioritization in domination.
tests/test_cartpole.py Modified CSV reading and assertions to validate new output shape and cv.
tests/dummy_evaluator.py Updated evaluator to return a tuple (metrics, cv).
presp/prescriptor/direct.py Added DirectPrescriptor and DirectFactory for direct parameter evolution.
presp/prescriptor/base.py Introduced the cv attribute in the base prescriptor.
presp/prescriptor/init.py Imported DirectPrescriptor and DirectFactory.
presp/nsga2_utils.py Updated domination logic to account for constraint violations.
presp/evolution.py Updated result recording now including cv and refined CSV output.
presp/evaluator/base.py Adjusted evaluation functions to return (metrics, cv).
examples/cartpole/direct_evaluator.py Evaluator now returns tuple (metrics, cv) for CartPole.
examples/bnh/demo.ipynb Updated demo notebook to reflect changes in CSV output and prescriptor usage.
examples/bnh/config.yml Added configuration for evolution and prescriptor parameters.
examples/bnh/bnh_evaluator.py New evaluator implementation that computes constraint violations.

c6 = self.c6(x2)

g = np.array([c1, c2, c3, c4, c5, c6])
g = np.sum(np.maximum(0, g))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Constraints are handled within the evaluator, evolution just needs to know the final number

for candidate, metrics in zip(pop_subset, pop_results):
for candidate, (metrics, cv) in zip(pop_subset, pop_results):
candidate.metrics = metrics
candidate.cv = cv
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We must set the cv parameter now

if candidate1.cv > candidate2.cv:
return False

# If both candidates are feasible or have the same constraint violation, we compare metrics
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Domination starts with constraint violation. If they are tied, we go into rank and distance.

self.cand_id = ""
self.parents = None
self.metrics = None
self.cv = 0
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default CV is 0

Creates a randomly initialized vector of floats between xl and xu uniformly.
"""
genome = np.random.rand(*self.xl.shape)
genome = genome * (self.xu - self.xl) + self.xl
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Random uniform initialization between xl and xu

@danyoungday danyoungday merged commit d0f3cf0 into main Apr 29, 2025
1 check passed
@danyoungday danyoungday deleted the constraint branch April 29, 2025 20:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants