99import time
1010import pygad
1111
12- # Hyperparameter
12+ # Hyperparameters
1313
14- # Anzahl der Gene
14+ # number of genes
1515num_genes = 3
16- # Anzahl der Generationen
16+ # number of generations
1717num_generations = 20
18- # Anzahl der Chromosomen
18+ # number of chromosomes
1919sol_per_pop = 10
20- # Anzahl der Eltern
20+ # number of parents
2121num_parents_mating = 10
22- # Wahrscheinlichkeit zur Mutation
22+ # probably of mutation
2323mutation_percent_genes = 34
2424
25- # untere Grenze der Zufallszahl
25+ # lower limit of the random number
2626init_range_low = 0
27- # obere Grenze der Zufallszahl
27+ # upper limit of the random number
2828init_range_high = 100
29- # Datentyp
29+ # data type
3030gene_type = float
3131
3232
@@ -53,13 +53,15 @@ def fitness_func(ga_instance, solution, solution_idx):
5353 pid_control .update_params (p , i , d )
5454 pt2 .reset ()
5555
56+ ww = 0
5657 for w in w_lst :
5758 e = w - x
5859 y = pid_control .get_xa (e )
5960 x = pt2 .get_xa (y )
6061 x_lst .append (x )
62+ ww = w
6163
62- fitness = rating .get_update_rating (x_lst , w )
64+ fitness = rating .get_update_rating (x_lst , ww )
6365
6466 return fitness
6567
@@ -88,9 +90,9 @@ def fitness_func(ga_instance, solution, solution_idx):
8890
8991solution , solution_fitness , solution_idx = ga_instance .best_solution ()
9092
91- print ("Benötigte Zeit :" , tm )
92- print ("Beste Parameter :" , solution )
93- print ("Höchster Fitnesswert :" , solution_fitness )
93+ print ("Required time :" , tm )
94+ print ("Best parameters :" , solution )
95+ print ("Highest fitness value :" , solution_fitness )
9496ga_instance .plot_fitness ()
9597####################################################
9698# plot the fittest control loop
0 commit comments