微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

无法使用抽象属性权重实例化抽象 <class 'deap.creator.Fitnessmin'>

如何解决无法使用抽象属性权重实例化抽象 <class 'deap.creator.Fitnessmin'>

我在上课时遇到了问题,我真的不知道该怎么办,这是代码

来自 deap 导入库,创建者 从深度导入算法 从 deap 导入工具 将 numpy 导入为 np 随机导入

weight=[23,31,29,44,53,38,63,85,89,82]
profit=[92,57,49,68,60,43,67,84,87,72]
maxw=165
i=1000
def fit(x):
    totp= np.sum(np.asarray(x)*np.sdsrray(profit))
    totw=np.sum(np.asarray(x)*np.asarray(weight))
    if totw>max:
        totp=totp+(maxw-totw)*3
    totp=max(totp,0)
    return totp

creator.create("fitnessmin",base.fitness,ws=(1.0,))
creator.create("Individual",list,fitness=creator.fitnessmin)
toolBox= base.ToolBox()
toolBox.register("select",tools.selRoulette)
toolBox.register("mutate",tools.mutFlipBit,indpb=0.1)
toolBox.register("mate",tools.cxOnePoint)
toolBox.register("evaluate",fit)
toolBox.register("attribute",random.randint,a=0,b=1)
toolBox.register("individual",tools.initRepeat,creator.Individual,toolBox.attribute,n=10)
toolBox.register("population",toolBox.individual)
pobl=toolBox.population(n=10)

stats= tools.Statistics(key=lambda ind: ind.fitness.values)
stats.register("max",np.max)
stats.register("min",np.min)
stats.register("avg",np.mean)
stats.register("std",np.std)
hof=tools.HallofFame(3)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。