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

Fix genotype wrapping limit problem #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

xfreib00
Copy link
Contributor

Fix genotype to phenotype wrapping problem creating invalid inividuals
and stopping evolution process by catching wrappingLimitExceeded
exception and assigning worst possible fitness value. Value of individual is
specified by a boolean variable specifing whether to use minimum or
maximum value of fitness class.

Test cases were updated to reflect new changes in SingleThreadDriver constructor.

Fix genotype to phenotype wrapping problem creating invalid inividuals
and stopping evolution process by catching wrappingLimitExceeded
exception and assigning worst possible fitness value. Its value is
specified by a boolean variable specifing whether to use minimum or
maximum value of fitness class.
@jansvoboda11
Copy link
Owner

Thanks for the PR, this would be a good thing to fix.

That said, I think the implementation can be improved.

Gram already provides an interface for expressing whether to look for the maximum or minimum fitness value: {High,Low}FitnessComparer. I think it would be better to reuse it instead of passing a separate argument to SingleThreadDriver. Additionally, using std::numeric_limits<Fitness>::{max,min} for getting the "worst" fitness should work in most cases, but I can imagine applications where the fitness of all individuals must fall into a well defined range (e.g. <0, 1.0>). It would be nice to provide a way to customise this to produce sensible values.

I think we should consider consolidating some of these concepts into a logical interface that groups the properties of Fitness.

I can imagine something akin to:

struct FitnessDomain {
  virtual Fitness evaluate(const Phenotype& phenotype) = 0;
  virtual Fitness worst() = 0;
  virtual bool compare(const Fitness& lhs, const Fitness& rhs) = 0;
};

which could replace FitnessEvaluator, FitnessComparer, isMin and the std::numeric_limits<Fitness> usage.

WDYT?

Adding a test-case that demonstrates the issue would be good, so we can prevent future regressions.

Also, please run clang-format over your code before submitting a PR, it helps to maintain the codebase consistent.

@xfreib00
Copy link
Contributor Author

Hi,
i really like the idea of interface for fitness. My solution was more like "quick easy solution", but I agree in some cases this aproach won't work.

Adding a test-case that demonstrates the issue would be good, so we can prevent future regressions.

This step should be easy, because any grammar with small number of rules which are recursive should give a good demonstration of this issue. Or even set wrappingLimit to zero could do the trick. Of course tests should cover both of these options.

Also, please run clang-format over your code before submitting a PR, it helps to maintain the codebase consistent.

Yes, sorry about that, completely forgot there is .clang-format file.

@jansvoboda11
Copy link
Owner

Cool. Do you plan to try implementing the FitnessDomain interface yourself?

@xfreib00
Copy link
Contributor Author

Well in this case I think it would be better if you could implement this interface, since it's major change in library's functionality / codebase.

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