Project-Platypus / Platypus

A Free and Open Source Python Library for Multiobjective Optimization
GNU General Public License v3.0
569 stars 153 forks source link

NSGAII ValueError #151

Closed ghost closed 1 year ago

ghost commented 4 years ago

Hi, I'm currently using Platypus' NSGA-II function and have been encountering a ValueError in core.py.

After an inconsistent number of iterations, it throws an error as the self.function(solution.variables) in core.py returns [False] rather than a pair of lists. I've used the same NSGA-II settings on another problem and I had no issues with it.

I've attached my NSGAII settings along with my traceback file and some sample values given by self.function(solution.variables).

Does anyone know what might be causing it to return such a value?

Thanks

problem = Problem(11, 8, 10)
problem.types[:] = [Real(0.01, 1.5), Real(0.05, 0.25), Real(0.01, 0.25), Real(1, 2), Real(0.03, 0.1), Real(1, 5), Real(3,5), Integer(0,12), Integer(0,9), Integer(1,2), Real(0.01,1)]
problem.constraints[:] = "<0"
problem.function = model

algorithm = NSGAII(problem,variator=CompoundOperator(SBX(), HUX(), PM(), BitFlip()))
algorithm.run(10000)
Traceback (most recent call last):

  File "C:\Users\Dennis\Desktop\New folder\model.py", line 606, in <module>
    algorithm.run(10000)

  File "C:\Users\Dennis\anaconda3\lib\site-packages\platypus\core.py", line 410, in run
    self.step()

  File "C:\Users\Dennis\anaconda3\lib\site-packages\platypus\algorithms.py", line 181, in step
    self.initialize()

  File "C:\Users\Dennis\anaconda3\lib\site-packages\platypus\algorithms.py", line 191, in initialize
    super(NSGAII, self).initialize()

  File "C:\Users\Dennis\anaconda3\lib\site-packages\platypus\algorithms.py", line 72, in initialize
    self.evaluate_all(self.population)

  File "C:\Users\Dennis\anaconda3\lib\site-packages\platypus\core.py", line 383, in evaluate_all
    results = self.evaluator.evaluate_all(jobs)

  File "C:\Users\Dennis\anaconda3\lib\site-packages\platypus\evaluator.py", line 88, in evaluate_all
    return list(self.map_func(run_job, jobs))

  File "C:\Users\Dennis\anaconda3\lib\site-packages\platypus\evaluator.py", line 55, in run_job
    job.run()

  File "C:\Users\Dennis\anaconda3\lib\site-packages\platypus\core.py", line 350, in run
    self.solution.evaluate()

  File "C:\Users\Dennis\anaconda3\lib\site-packages\platypus\core.py", line 523, in evaluate
    self.problem(self)

  File "C:\Users\Dennis\anaconda3\lib\site-packages\platypus\core.py", line 165, in __call__
    self.evaluate(solution)

  File "C:\Users\Dennis\anaconda3\lib\site-packages\platypus\core.py", line 191, in evaluate
    (objs, constrs) = self.function(solution.variables)

ValueError: not enough values to unpack (expected 2, got 1)
[[2.50861132238244, 0.3903417051679467, -0.543742035537466, 1.329871101621052, -0.20242039363804123, 6, 5.327322745957215, -0.543742035537466], [10.578699506953527, 2.2, -66.6, -0.06805097093184115, -6.292890004130986, -0.6055867104407471, -0.3944132895592529, 0.543742035537466, -1.329871101621052, -8.16714296906334]]
[[1.0317548868503343, 0.1925439466528248, 0.3021696588989762, 4.938305314218708, 0.763849125186179, 6, 2.669283067563014, 0.3021696588989762], [-20.00189874847675, -19.2, -99.90000000000002, -0.2037189971328583, -9.960316545202902, -0.42301898486518164, -0.5769810151348184, -0.3021696588989762, -4.938305314218708, -8.21550081925964]]
[False]
jetuk commented 4 years ago

This is caused by the function (in this case whatever model is) returning [False], and not a tuple.

ghost commented 4 years ago

Thanks, that appeared to be the case. Managed to solve the issue and everything works fine.

github-actions[bot] commented 1 year ago

This issue is stale and will be closed soon. If you feel this issue is still relevant, please comment to keep it active. Please also consider working on a fix and submitting a PR.