Skip to content

Commit

Permalink
Code cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
irevich committed Apr 5, 2022
1 parent 4ca78ef commit b662efe
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 14 deletions.
7 changes: 1 addition & 6 deletions TP2/selectionMethods/boltzmannSelection.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,18 @@ def __init__(self , T0 , Tc , k):
self.initialT = T0
self.finalT = Tc
self.k = k
print("Corre Boltzmann")


#Funcion de temperatura dada en clase
def __temperature(self):
return self.finalT + (self.initialT - self.finalT) * np.exp( - self.k * self.generation )

def apply(self,selectionIndividuals,targetPopulationSize,replacement=False):
# print(self.__temperature())
valuedIndividuals = []
total = 0
#Por cada individuo calculo su valor (el dividendo de la probabilidad)
for individual in selectionIndividuals:
value = np.exp(individual.fitness / self.__temperature())
#print("fitness: " + str(individual.fitness) + "value: " + str(value) )
total += value
valuedIndividuals.append((value, individual))

Expand All @@ -34,9 +31,7 @@ def apply(self,selectionIndividuals,targetPopulationSize,replacement=False):
for valuedIndividual in valuedIndividuals:
acumulated+= valuedIndividual[0] / total
promediatedIndividuals.append((acumulated , valuedIndividual[1]))
# print("fitness: " + str(valuedIndividual[1].fitness) + "value: " + str(acumulated) )

#print("total: " + str(valueAcum) )

selectedPopulation = []
#tiro la ruleta
for i in range(0 , targetPopulationSize):
Expand Down
2 changes: 0 additions & 2 deletions TP2/selectionMethods/eliteSelection.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
class EliteSelection:
def __init__(self):
print("Hola TOR")

def apply(self,selectionIndividuals,targetPopulationSize,replacement=False):
#Ordenamos la poblacion por mayor fitness, y retornamos los primeros "targetPopulationSize"
Expand Down
3 changes: 0 additions & 3 deletions TP2/selectionMethods/rankSelection.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

class RankSelection:

def __init__(self):
print("Corre rank")

def apply(self,selectionIndividuals,targetPopulationSize,replacement=False):
#Ordenamos los individuos por fitness
rankedIndividuals = sorted(selectionIndividuals,key=lambda x: x.fitness,reverse=True)
Expand Down
3 changes: 0 additions & 3 deletions TP2/selectionMethods/rouletteSelection.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

class RouletteSelection:

def __init__(self):
print("Corre roulette")

def apply(self,selectionIndividuals,targetPopulationSize,replacement=False):
#Sacamos el fitness total
#return random.choices(selectionIndividuals , weights=[x.fitness for x in selectionIndividuals] , k=targetPopulationSize )
Expand Down

0 comments on commit b662efe

Please sign in to comment.