def RandomLocal(step): chompvalue = 0 hamming = 3 local = 3 valuelist = list() ary = ['A', 'T', 'C', 'G'] for i in range(step): eDNA = SimpleDNA(randint(0, 50)).getDNA() value = funcDNA2(eDNA) if value > chompvalue: chompDNA = eDNA[:] chompvalue = value N = len(eDNA) for i in range(hamming): eDNA = SimpleDNA(len(eDNA)).getDNA() value = funcDNA2(eDNA) if value > chompvalue: chompDNA = eDNA[:] chompvalue = value for i in range(local): index = randint(0, N - 1) for ele in ary: eDNA[index] = ele value = funcDNA2(eDNA) if value > chompvalue: chompDNA = eDNA[:] chompvalue = value valuelist.append(chompvalue) return [chompDNA, chompvalue,valuelist]
def RandomWalk(step): chompvalue = 0 hamming = 3 valuelist = list() ary = ['A', 'T', 'C', 'G'] for i in range(step): eDNA = SimpleDNA(randint(0, 50)).getDNA() value = funcDNA2(eDNA) if value > chompvalue: chompDNA = eDNA[:] chompvalue = value for i in range(hamming): eDNA = SimpleDNA(len(eDNA)).getDNA() value = funcDNA2(eDNA) if value > chompvalue: chompDNA = eDNA[:] chompvalue = value valuelist.append(chompvalue) return [chompDNA, chompvalue, valuelist]