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

hello world! example #4

Open
unnir opened this issue Feb 25, 2017 · 1 comment
Open

hello world! example #4

unnir opened this issue Feb 25, 2017 · 1 comment

Comments

@unnir
Copy link

unnir commented Feb 25, 2017

I have these error messages for the hello world example.

Traceback (most recent call last):
  File "/genetics-master/hello_world.py", line 42, in <module>
    best, best_score, average_score = dna_stats(population)
  File "/genetics-master/hello_world.py", line 32, in dna_stats
    best_dna = max(population)
TypeError: unorderable types: WordDNA() > WordDNA()
@EmbolismSoil
Copy link

EmbolismSoil commented Apr 17, 2017

you should provide the method '__gt__' so that the 'max' function can choice an greater instance of WordDNA when running:

class WordDNA(genetics.arrayed_segment(len(solution), LetterComponent)):
    def score(self):
        return sum(comp.value == letter for comp, letter in zip(self, solution))

    def __str__(self):
        return ''.join(comp.value for comp in self)

    def __gt__(self, other):
        return self.score() > other.score()

liuruoze added a commit to liuruoze/genetics that referenced this issue Jun 24, 2018
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

No branches or pull requests

2 participants