Пример #1
0
def runGeneticAlgorithm():
	popN = 100 # n number of chromos per population
	genesPerCh = 54
	max_iterations = 1000
  	chromos = geneticAlgorithm.generatePop(popN) #generate new population of random chromosomes
  	iterations = 0

  	while True:
  		if (iterations == max_iterations):
	 		rankedPop = geneticAlgorithm.rankPop(chromos) 
	 		#print(len(rankedPop))
	 		#print rankedPop
	  		chromos = []
	  		agent = geneticAlgorithm.iteratePop(rankedPop, popN, True)
	  		listKeys = agent[0]
	  		keyNames = []
	  		for i in range(len(listKeys)):
	  			if (listKeys[i] == 1):
	  				keyNames.append(allKeys[i])
	  		print agent
	  		print keyNames
	  		break
		# take the pop of random chromos and rank them based on their fitness score/proximity to target output
		rankedPop = geneticAlgorithm.rankPop(chromos) 
		#print rankedPop

  		chromos = []
  		chromos = geneticAlgorithm.iteratePop(rankedPop, popN, False)
		
  		iterations += 1
Пример #2
0
def runGeneticAlgorithm():
	

  	while True:
  		if (iterations == max_iterations):
  			#get the new generation, ranked by fitness score
	 		rankedPop = geneticAlgorithm.rankPop(chromos) 
	 		#print(len(rankedPop))
	 		#print rankedPop
	  		chromos = []
	  		#get the best agent from the population
	  		agent = geneticAlgorithm.iteratePop(rankedPop, popN, True)
	  		listKeys = agent[0]
	  		keyNames = []
	  		#find the best keys for this agent
	  		for i in range(len(listKeys)):
	  			if (listKeys[i] == 1):
	  				keyNames.append(allKeys[i])
	  		print agent
	  		print keyNames
	  		break
		# take the population of random chromos and rank them based on their fitness score/proximity to target output
		rankedPop = geneticAlgorithm.rankPop(chromos) 
		#print rankedPop

  		chromos = []
  		#get the new chromosomes
  		chromos = geneticAlgorithm.iteratePop(rankedPop, popN, False)
		
  		iterations += 1