original_docstring: 
          Function to start the GA run.
  
          Parameters:
  
              popSize (int) - population size to start the GA with.
              genLimit (int) - the stopping criteria; the number iterations till the same front (until converged)
              mutationProbability (float) - the probability of mutating an edge.
              swapProbability (float) - the probability of doing a swap on a mutating edge.
              transferProbability (float) - the probability of doing a transfer on a mutating edge.
              population (list) - Optional. Can pass a population to start GA (Used in experiments)
              k (int) - the value of 'k' in case of K-Point crossover. (Used only for experiments)
  
          Returns:
  
              metricData (dictionary) - dictionary containing all the metric data associated with the GA run.
              front - the non dominated solutions after the GA run (Pareto Optimal Frontier; the first front.)
              
          
docstring: Function to start the GA run.
  Parameters.
  
  popSize (int) - population size to start the GA with.
  genLimit (int) - the stopping criteria; the number iterations till the same front (until converged)
  mutationProbability (float) - the probability of mutating an edge.
  swapProbability (float) - the probability of doing a swap on a mutating edge.
  transferProbability (float) - the probability of doing a transfer on a mutating edge.
  population (list) - Optional. Can pass a population to start GA (Used in experiments)
  k (int) - the value of 'k' in case of K-Point crossover. (Used only for experiments)
  
  
  
  metricData (dictionary) - dictionary containing all the metric data associated with the GA run.
  front - the non dominated solutions after the GA run (Pareto Optimal Frontier; the first front.)
docstring_tokens: Function to start the GA run . Parameters . popSize ( int ) - population size to start the GA with . genLimit ( int ) - the stopping criteria ; the number iterations till the same front ( until converged ) mutationProbability ( float ) - the probability of mutating an edge . swapProbability ( float ) - the probability of doing a swap on a mutating edge . transferProbability ( float ) - the probability of doing a transfer on a mutating edge . population ( list ) - Optional . Can pass a population to start GA ( Used in experiments ) k ( int ) - the value of ' k ' in case of K - Point crossover . ( Used only for experiments ) metricData ( dictionary ) - dictionary containing all the metric data associated with the GA run . front - the non dominated solutions after the GA run ( Pareto Optimal Frontier ; the first front . )
code: def start(self,popSize,genLimit,mutationProbability,swapProbability,transferProbability,population=None,k=None):
          """
          Function to start the GA run.
  
          Parameters:
  
              popSize (int) - population size to start the GA with.
              genLimit (int) - the stopping criteria; the number iterations till the same front (until converged)
              mutationProbability (float) - the probability of mutating an edge.
              swapProbability (float) - the probability of doing a swap on a mutating edge.
              transferProbability (float) - the probability of doing a transfer on a mutating edge.
              population (list) - Optional. Can pass a population to start GA (Used in experiments)
              k (int) - the value of 'k' in case of K-Point crossover. (Used only for experiments)
  
          Returns:
  
              metricData (dictionary) - dictionary containing all the metric data associated with the GA run.
              front - the non dominated solutions after the GA run (Pareto Optimal Frontier; the first front.)
              
          """
          
          #Initialize the population
          
          if not population:
              population = self.initializePopulation(popSize)
  
          tic1 = time.time()
          
          fronts = self.fast_non_dominated_sort(population)
          
          best_hv = float("inf")
          best_front = None
          hv = GeneticAlgorithm.SMetric( [ (x.getFst(),x.getFsup()) for x in  fronts[0] ] )
          no_impr = 0
  
          
          toc1 = time.time() - tic1
          
          offsprings = []
          
          count = 0
          genCount = 0
          prev = set()
  
          metricData = {}
  
          #Metrics Data
          
          initial_maxFst = max(population, key=lambda x: x.getFst()).getFst()
          initial_minFst = min(population, key=lambda x: x.getFst()).getFst()
          initial_maxFsup = max(population, key=lambda x: x.getFsup()).getFsup()
          initial_minFsup = min(population, key=lambda x: x.getFsup()).getFsup()
  
          evolution_front = []
  
          tic1 = time.time()
          
          while ( no_impr <= 20 ):
  
              print("Generation " + str(genCount) + " no improvement in " + str(no_impr))
  
              #Combine parent and offspring population
              
              population.extend(offsprings)
  
  
              #Divide the population into fronts
              
              fronts = self.fast_non_dominated_sort(population)
              hv = GeneticAlgorithm.SMetric( [ (x.getFst(),x.getFsup()) for x in  fronts[0] ] )
              if hv >= best_hv :
                  no_impr = no_impr + 1
              else :
                  no_impr = 0
                  best_hv = hv
                  best_front = fronts[0]
  
              maxFst = max(population, key=lambda x: x.getFst()).getFst()
              minFst = min(population, key=lambda x: x.getFst()).getFst()
  
              maxFsup = max(population, key=lambda x: x.getFsup()).getFsup()
              minFsup = min(population, key=lambda x: x.getFsup()).getFsup()
  
              newPopulation = []
              frontCount = 0
  
              evolution_front.append( sorted([ (x.getFst(),x.getFsup()) for x in fronts[0] ]) )
  
              #Until inclusion possible, calculate the crowding distance and add to new population
              while len(newPopulation) + len(fronts[frontCount]) <= popSize:
                  
                  self.crowding_distance_assignment(fronts[frontCount],maxFst,minFst,maxFsup,minFsup)
                  newPopulation.extend(fronts[frontCount])
                  frontCount+=1
                  if frontCount == len(fronts):
                      break
  
              
              #Select the required amount of solutions from the last non-visted front to fill the population to the specified size
              if len(newPopulation) != popSize:
                  
                  self.crowding_distance_assignment(fronts[frontCount],maxFst,minFst,maxFsup,minFsup)
                  
                  fronts[frontCount] = sorted(fronts[frontCount]) 
                  
                  needed = popSize - len(newPopulation)
                  newPopulation.extend(fronts[frontCount][:needed])
  
              population = newPopulation
  
  
              #Filter population to keep as much unique solutions as possible
  
              filteredPop = self.filterPopulation(population,popSize)
  
              #Make offspring population from the filtered population
              offsprings = self.makeNewPopulation(filteredPop,popSize,mutationProbability,swapProbability,transferProbability,k)
  
              #Checking if solutions in frontier are the same as previous. If the same for 10 times, then the GA run stops.
              
              curr = set([(i._Fst,i._Fsup) for i in fronts[0]])
                 
              
              if len(curr - prev) != 0:
                  count=0
                  prev = copy.deepcopy(curr)
              else:
                  count+=1
              
              genCount+=1
              
  
          toc1 += time.time() - tic1
  
          #Adding Metrics Data
  
          
          final_maxFst = maxFst
          final_maxFsup = maxFsup
          final_minFst = minFst
          final_minFsup = minFsup
  
          metricData['initial_maxFst']=initial_maxFst
          metricData['initial_minFst']=initial_minFst
          metricData['initial_maxFsup']=initial_maxFsup
          metricData['initial_minFsup']=initial_minFsup
  
          metricData['final_maxFst']=final_maxFst
          metricData['final_minFst']=final_minFst
          metricData['final_maxFsup']=final_maxFsup
          metricData['final_minFsup']=final_minFsup
  
          metricData['evolution'] = evolution_front
          metricData['diversity'] = calcSpacing(best_front)
  
          metricData['numberOfGenerations'] = genCount
          metricData['non_dominated_solutions'] = set([(i._Fst,i._Fsup) for i in best_front])
          
          metricData['total_time_generations'] = toc1
          metricData['avg_time_generation'] = toc1/genCount
          
          
          print("GA Run Finished..")
  
          
          return metricData,best_front
code_tokens: def start ( self , popSize , genLimit , mutationProbability , swapProbability , transferProbability , population = None , k = None ) : if not population : population = self . initializePopulation ( popSize ) tic1 = time . time ( ) fronts = self . fast_non_dominated_sort ( population ) best_hv = float ( "inf" ) best_front = None hv = GeneticAlgorithm . SMetric ( [ ( x . getFst ( ) , x . getFsup ( ) ) for x in fronts [ 0 ] ] ) no_impr = 0 toc1 = time . time ( ) - tic1 offsprings = [ ] count = 0 genCount = 0 prev = set ( ) metricData = { } initial_maxFst = max ( population , key = lambda x : x . getFst ( ) ) . getFst ( ) initial_minFst = min ( population , key = lambda x : x . getFst ( ) ) . getFst ( ) initial_maxFsup = max ( population , key = lambda x : x . getFsup ( ) ) . getFsup ( ) initial_minFsup = min ( population , key = lambda x : x . getFsup ( ) ) . getFsup ( ) evolution_front = [ ] tic1 = time . time ( ) while ( no_impr <= 20 ) : print ( "Generation " + str ( genCount ) + " no improvement in " + str ( no_impr ) ) population . extend ( offsprings ) fronts = self . fast_non_dominated_sort ( population ) hv = GeneticAlgorithm . SMetric ( [ ( x . getFst ( ) , x . getFsup ( ) ) for x in fronts [ 0 ] ] ) if hv >= best_hv : no_impr = no_impr + 1 else : no_impr = 0 best_hv = hv best_front = fronts [ 0 ] maxFst = max ( population , key = lambda x : x . getFst ( ) ) . getFst ( ) minFst = min ( population , key = lambda x : x . getFst ( ) ) . getFst ( ) maxFsup = max ( population , key = lambda x : x . getFsup ( ) ) . getFsup ( ) minFsup = min ( population , key = lambda x : x . getFsup ( ) ) . getFsup ( ) newPopulation = [ ] frontCount = 0 evolution_front . append ( sorted ( [ ( x . getFst ( ) , x . getFsup ( ) ) for x in fronts [ 0 ] ] ) ) while len ( newPopulation ) + len ( fronts [ frontCount ] ) <= popSize : self . crowding_distance_assignment ( fronts [ frontCount ] , maxFst , minFst , maxFsup , minFsup ) newPopulation . extend ( fronts [ frontCount ] ) frontCount += 1 if frontCount == len ( fronts ) : break if len ( newPopulation ) != popSize : self . crowding_distance_assignment ( fronts [ frontCount ] , maxFst , minFst , maxFsup , minFsup ) fronts [ frontCount ] = sorted ( fronts [ frontCount ] ) needed = popSize - len ( newPopulation ) newPopulation . extend ( fronts [ frontCount ] [ : needed ] ) population = newPopulation filteredPop = self . filterPopulation ( population , popSize ) offsprings = self . makeNewPopulation ( filteredPop , popSize , mutationProbability , swapProbability , transferProbability , k ) curr = set ( [ ( i . _Fst , i . _Fsup ) for i in fronts [ 0 ] ] ) if len ( curr - prev ) != 0 : count = 0 prev = copy . deepcopy ( curr ) else : count += 1 genCount += 1 toc1 += time . time ( ) - tic1 final_maxFst = maxFst final_maxFsup = maxFsup final_minFst = minFst final_minFsup = minFsup metricData [ 'initial_maxFst' ] = initial_maxFst metricData [ 'initial_minFst' ] = initial_minFst metricData [ 'initial_maxFsup' ] = initial_maxFsup metricData [ 'initial_minFsup' ] = initial_minFsup metricData [ 'final_maxFst' ] = final_maxFst metricData [ 'final_minFst' ] = final_minFst metricData [ 'final_maxFsup' ] = final_maxFsup metricData [ 'final_minFsup' ] = final_minFsup metricData [ 'evolution' ] = evolution_front metricData [ 'diversity' ] = calcSpacing ( best_front ) metricData [ 'numberOfGenerations' ] = genCount metricData [ 'non_dominated_solutions' ] = set ( [ ( i . _Fst , i . _Fsup ) for i in best_front ] ) metricData [ 'total_time_generations' ] = toc1 metricData [ 'avg_time_generation' ] = toc1 / genCount print ( "GA Run Finished.." ) return metricData , best_front
short_docstring: Function to start the GA run.
short_docstring_tokens: Function to start the GA run .
comment: """
          Function to start the GA run.
  
          Parameters:
  
              popSize (int) - population size to start the GA with.
              genLimit (int) - the stopping criteria; the number iterations till the same front (until converged)
              mutationProbability (float) - the probability of mutating an edge.
              swapProbability (float) - the probability of doing a swap on a mutating edge.
              transferProbability (float) - the probability of doing a transfer on a mutating edge.
              population (list) - Optional. Can pass a population to start GA (Used in experiments)
              k (int) - the value of 'k' in case of K-Point crossover. (Used only for experiments)
  
          Returns:
  
              metricData (dictionary) - dictionary containing all the metric data associated with the GA run.
              front - the non dominated solutions after the GA run (Pareto Optimal Frontier; the first front.)
              
          """$SEP$#Initialize the population$SEP$#Metrics Data$SEP$#Combine parent and offspring population$SEP$#Divide the population into fronts$SEP$#Until inclusion possible, calculate the crowding distance and add to new population$SEP$#Select the required amount of solutions from the last non-visted front to fill the population to the specified size$SEP$#Filter population to keep as much unique solutions as possible$SEP$#Make offspring population from the filtered population$SEP$#Checking if solutions in frontier are the same as previous. If the same for 10 times, then the GA run stops.$SEP$#Adding Metrics Data