jMetal / jMetalPy

A framework for single/multi-objective optimization with metaheuristics
https://jmetal.github.io/jMetalPy/index.html
MIT License
498 stars 150 forks source link

replicating the use case SubsetSum Binary Problem. with the NSGAII algorithm #112

Closed hdchantre closed 3 years ago

hdchantre commented 3 years ago

Hello Everyone, I am new to this, I am replicating the use case SubsetSum Binary Problem. with the NSGAII algorithm to run but I am having the following error:
File "my_run_myBsubset.py", line 65, in experiment.run() File "C:\Users\AppData\Local\Programs\Python\Python37\lib\site-packages\jmetal\lab\experiment.py", line 69, in run executor.submit(job.execute(output_path)) File "C:\Users\AppData\Local\Programs\Python\Python37\lib\site-packages\jmetal\lab\experiment.py", line 38, in execute self.algorithm.run() File "C:\Users\AppData\Local\Programs\Python\Python37\lib\site-packages\jmetal\core\algorithm.py", line 84, in run self.step() File "C:\Users\AppData\Local\Programs\Python\Python37\lib\site-packages\ jmetal\core\algorithm.py", line 145, in step offspring_population = self.reproduction(mating_population) File "C:\Users\AppData\Local\Programs\Python\Python37\lib\site-packages\ jmetal\algorithm\singleobjective\genetic_algorithm.py", line 86, in reproduction offspring = self.crossover_operator.execute(parents) File "C:\Users\AppData\Local\Programs\Python\Python37\lib\site-packages\jmetal\operator\crossover.py", line 148, in execute Check.that(issubclass(type(parents[0]), FloatSolution), "Solution type invalid: " + str(type(parents[0]))) File "C:\Users\AppData\Local\Programs\Python\Python37\lib\site-packages\jmetal\util\ckecking.py", line 58, in that raise InvalidConditionException(message) jmetal.util.ckecking.InvalidConditionException: Solution type invalid: <class 'j metal.core.solution.BinarySolution'>

Thanks for this amazing project.

hdchantre commented 3 years ago

This was solved by using the following from jmetal.algorithm.multiobjective.nsgaii import NSGAII from jmetal.operator import BitFlipMutation, SPXCrossover and the algorithm = NSGAII( problem=problem, population_size=100, offspring_population_size=1, mutation=BitFlipMutation(probability=1.0 / binary_string_length), crossover=SPXCrossover(probability=1.0), termination_criterion=StoppingByEvaluations(max_evaluations=max_evaluations), dominance_comparator=DominanceComparator() )