geatpy-dev / geatpy

Evolutionary algorithm toolbox and framework with high performance for Python
http://www.geatpy.com
GNU Lesser General Public License v3.0
2.02k stars 727 forks source link

RuntimeError: error in ndsortESS: CV and ObjV disagree #102

Closed jdx0813 closed 4 years ago

jdx0813 commented 4 years ago

请问出现这行错误是因为我设置的约束条件过多吗? 如果是的话,要怎么将我原先的约束条件做调整会比较适当

geatpy-dev commented 4 years ago

@jdx0813 您好!这说明CV和ObjV在格式上不匹配。两者均需要是2维的Numpy ndarray矩阵,并且两者的行数要相等(详见《Geatpy数据结构》文档)。您可以在自定义目标函数末尾print(CV.shape)和print(ObjV.shape)输出两者的规格,进而修改确保两者的行数一致。

jdx0813 commented 4 years ago

好的,感谢我再多尝试一会

jdx0813 commented 4 years ago

print(pop.CV.shape)->(60, 4) print(pop.ObjV.shape)->(780,) Traceback (most recent call last): File "C:\Users\LAB432\Desktop\pytest\Test\Supply\main.py", line 18, in NDSet = myAlgorithm.run() File "C:\Users\LAB432\AppData\Roaming\Python\Python35\site-packages\geatpy\templates\moeas\nsga2\moea_NSGA2_templet.py", line 92, in run [levels, criLevel] = self.ndSort(self.problem.maxormins * population.ObjV, NIND, None, population.CV) # 对NIND个个体进行非支配分层 ValueError: operands could not be broadcast together with shapes (2,) (780,)

jdx0813 commented 4 years ago

请问我这样是目标函式的问题吗?

geatpy-dev commented 4 years ago

是的,CV是60行的时候,ObjV也要有60行。另外最好print(pop.sizes)看一下个体数是不是60,如果不是60,那么CV也有问题。

geatpy-dev commented 4 years ago

如果后续还有问题欢迎继续发issue提问噢!这里就把该问题关闭了。