anyoptimization / pymoo

NSGA2, NSGA3, R-NSGA3, MOEAD, Genetic Algorithms (GA), Differential Evolution (DE), CMAES, PSO
https://pymoo.org
Apache License 2.0
2.22k stars 381 forks source link

eliminate_duplicates seems not work for integers? #385

Closed GitLD closed 1 year ago

GitLD commented 1 year ago

I'm solving an optimization problem with n_var=5, where all variable should be unrepeatable integers in range between x_min and x_max, however when I set eliminate_duplicates = True, did't work fine?

Here is my snapshot of code: algorithm = NSGA2( pop_size=6, sampling=IntegerRandomSampling(), crossover=SBX(repair=RoundingRepair()), mutation=PM(repair=RoundingRepair()), eliminate_duplicates=True ) And the Results give out as: Best solution found: [[ 4 2 9 4 30] [13 36 23 5 6] [13 35 22 5 6] [ 4 36 22 14 36] which obviously variable did't meet the requirement of unrepeatable.

It will appreciate if any advice is give.

GitLD commented 1 year ago

It seems that I misunderstood the eliminate_duplicates, maybe I should apply the unrepeatable by adding constains

blankjul commented 1 year ago

Yes, the eliminate_duplicates operators on a population level. Not individual level.

Adding a constraint with a Repair operator is the best fix for what you want to achieve!