Skip to content

严重的性能瓶颈: Decode(J, Processing_time, M_num, ...) #2

@xianzhi-xzw

Description

@xianzhi-xzw

GA.py 的 fitness 函数是这样实现的:

for i in range(len(CHS)):
    d = Decode(J, Processing_time, M_num, ...) # 每次都重新初始化
    Fit.append(d.decode(CHS[i], Len))

每一代中的每一个个体在计算适应度时,都会执行一遍 Decode.init 里的所有预计算循环(包括嵌套循环、对象创建等)。如果有 100 个个体运行 100 代,那么 Decode.init 就会被执行 10,000 次。 @Incalos

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions