Skip to content

Commit

Permalink
chore & fix(deap/tools/emo.py:selTournamentDCD): check on value of k …
Browse files Browse the repository at this point in the history
…& throw ValueError for failed input validation

Now, if number of individuals to select(stored in parameter `k`) is not multiple of 4, it will throw. In addition, throw `ValueError` instead of generic `Exception` when input is invalid.
  • Loading branch information
yxliang01 authored Apr 30, 2019
1 parent e1a52b2 commit 64f1334
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions deap/tools/emo.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,12 @@ def selTournamentDCD(individuals, k):
:returns: A list of selected individuals.
"""

if len(individuals)%4 !=0:
raise Exception("selTournamentDCD: individuals length must be a multiple of 4")
if len(individuals) % 4 != 0:
raise ValueError("selTournamentDCD: individuals length must be a multiple of 4")

if k % 4 != 0:
raise ValueError("selTournamentDCD: number of individuals to select must be a multiple of 4")

def tourn(ind1, ind2):
if ind1.fitness.dominates(ind2.fitness):
return ind1
Expand Down

0 comments on commit 64f1334

Please sign in to comment.