追加无法正常工作 [英] Append not working like expected
问题描述
我有以下问题:
对于遗传算法,我正在创建5个突变并将其存储在准备好的列表中(请参见下面的代码)。
i have the following Problem: For a genetic algorithm i'm creating 5 mutations and store them in a prepared list (see code below).
这是我要附加变异驱动程序的函数:
This is my function where i want to append the mutated drivers:
def startNewRunFromScratch(self):
self.log.logBlue('Starting new run from scratch', 2, 0)
parameterSet = []
parameterSet.append(Parameter('TEST', 0.5, 0, 1))
defaultGDriver = GDriver(parameterSet)
gDriverList = []
gDriverList.append(defaultGDriver)
m = Mutation(self.mutationRate)
for i in range(1, self.populationSize, 1):
g = m.mutate(defaultGDriver)
self.log.log('After mutaion: '+str(g.parameterSet[0].value), 0, 2)
gDriverList.append(g)
self.startSuite(gDriverList)
startSuite原型函数:
And here the the startSuite prototype function:
def startSuite(self, gDriverList):
self.log.logSuccess('Starting suite', 1, 0)
for g in gDriverList:
self.log.log('Inside suite: '+str(g.parameterSet[0].value), 0, 2)
问题是,输出与我的逻辑不符:
The problem is, that the output does not match my logic:
Starting new run from scratch
After mutaion: 0.5
After mutaion: 0.5
After mutaion: 0.5
After mutaion: 0.740296236666
Starting suite
Inside suite: 0.740296236666
Inside suite: 0.740296236666
Inside suite: 0.740296236666
Inside suite: 0.740296236666
Inside suite: 0.740296236666
预期输出:
Inside suite: 0.5
Inside suite: 0.5
Inside suite: 0.5
Inside suite: 0.5
Inside suite: 0.740296236666
有人能解决这个问题吗? Maybee我缺少了一些东西。
Does anyone have an good idea how to solve this problem? Maybee im missing something.
推荐答案
您反复附加相同的 Mutation
,并最终在列表中对其进行多次引用。如果要使用其他突变
,则必须制作新的。 (我认为这就是您认为的问题,因为您从未明确指出输出的问题是什么。)
You repeatedly append the same Mutation
, and end up with multiple references to it in the list. If you want different Mutations
, you have to make new ones. (I assume that's what you think is the "problem", as you never explicitly say what is wrong about the output.)
这篇关于追加无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!