jMetal / jMetalPy

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

Problem when using class RandomSearch #27

Closed moar82 closed 6 years ago

moar82 commented 6 years ago

Hi, I am trying to run an experiment using NSGAII and randomSearch. However my script breaks when it reaches the class RandomSearch with the folloiwng error.

2018-08-30 03:22:29,075 [MainThread  ] [INFO ]  Running experiment: problem <miniaturization.Miniaturization object at 0x7f95bf2c7518>, algorithm <module 'jmetal.algorithm.multiobjective.randomSearch' from '/usr/local/lib/python3.6/site-packages/jmetalpy-0.5.0-py3.6.egg/jmetal/algorithm/multiobjective/randomSearch.py'>
Traceback (most recent call last):
  File "NSGAII-RS for MINIOT.py", line 17, in <module>                         
    results = experiment(algorithm, metric, problem)                           
  File "/usr/local/lib/python3.6/site-packages/jmetalpy-0.5.0-py3.6.egg/jmetal/util/laboratory.py", line 41, in experiment                                     
    pool.submit(algorithm_list[a_index][0].run())                              
AttributeError: module 'jmetal.algorithm.multiobjective.randomSearch' has no attribute 'run'

This the code of my experiment:

from jmetal.algorithm import NSGAII
from jmetal.algorithm.multiobjective import randomSearch
from jmetal.component.comparator import RankingAndCrowdingDistanceComparator
from jmetal.operator import  SP, BitFlip, BinaryTournamentSelection
from miniaturization import Miniaturization
from jmetal.component.quality_indicator import HyperVolume
from jmetal.util.laboratory import experiment, display

algorithm = [
    (    (randomSearch, {'max_evaluations': 250}))
]
metric = [HyperVolume(reference_point=[1, 1, 1, 1])]
problem = [(Miniaturization, {})]

results = experiment(algorithm, metric, problem)
display(results)

Do you have any idea why this happening? NSGAII is working well.

moar82 commented 6 years ago

I think I found the problem in the file /usr/local/lib/python3.6/site-packages/jmetalpy-0.5.0-py3.6.egg/jmetal/algorithm/__init__.py

I submit a pull request.

benhid commented 6 years ago

Fixed in #28, thank you!