You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Release Date 29 January 2024
1. Solve bugs when multi-objective optimization is used. #238
2. When the `stop_ciiteria` parameter is used with the `reach` keyword, then multiple numeric values can be passed when solving a multi-objective problem. For example, if a problem has 3 objective functions, then `stop_criteria="reach_10_20_30"` means the GA stops if the fitness of the 3 objectives are at least 10, 20, and 30, respectively. The number values must match the number of objective functions. If a single value found (e.g. `stop_criteria=reach_5`) when solving a multi-objective problem, then it is used across all the objectives. #238
3. The `delay_after_gen` parameter is now deprecated and will be removed in a future release. If it is necessary to have a time delay after each generation, then assign a callback function/method to the `on_generation` parameter to pause the evolution.
4. Parallel processing now supports calculating the fitness during adaptive mutation. #201
5. The population size can be changed during runtime by changing all the parameters that would affect the size of any thing used by the GA. For more information, check the [Change Population Size during Runtime](https://pygad.readthedocs.io/en/latest/pygad_more.html#change-population-size-during-runtime) section. #234
6. When a dictionary exists in the `gene_space` parameter without a step, then mutation occurs by adding a random value to the gene value. The random vaue is generated based on the 2 parameters `random_mutation_min_val` and `random_mutation_max_val`. For more information, check the [How Mutation Works with the gene_space Parameter?](https://pygad.readthedocs.io/en/latest/pygad_more.html#how-mutation-works-with-the-gene-space-parameter) section. #229
7. Add `object` as a supported data type for int (GA.supported_int_types) and float (GA.supported_float_types). #174
8. Use the `raise` clause instead of the `sys.exit(-1)` to terminate the execution. #213
9. Fix a bug when multi-objective optimization is used with batch fitness calculation (e.g. `fitness_batch_size` set to a non-zero number).
10. Fix a bug in the `pygad.py` script when finding the index of the best solution. It does not work properly with multi-objective optimization where `self.best_solutions_fitness` have multiple columns.
Copy file name to clipboardExpand all lines: examples/example_dynamic_population_size.py
+63-24
Original file line number
Diff line number
Diff line change
@@ -3,44 +3,83 @@
3
3
4
4
"""
5
5
This is an example to dynamically change the population size (i.e. number of solutions/chromosomes per population) during runtime.
6
-
The following 2 instance attributes must be changed to meet the new desired population size:
7
-
1) population: This is a NumPy array holding the population.
8
-
2) num_offspring: This represents the number of offspring to produce during crossover.
9
-
For example, if the population initially has 20 solutions and 6 genes. To change it to have 30 solutions, then:
10
-
1)population: Create a new NumPy array with the desired size (30, 6) and assign it to the population instance attribute.
11
-
2)num_offspring: Set the num_offspring attribute accordingly (e.g. 29 assuming that keep_elitism has the default value of 1).
6
+
7
+
The user has to carefully inspect the parameters and instance attributes to select those that must be changed to be consistent with the new population size.
8
+
Check this link for more information: https://pygad.readthedocs.io/en/latest/pygad_more.html#change-population-size-during-runtime
12
9
"""
13
10
11
+
defupdate_GA(ga_i,
12
+
pop_size):
13
+
"""
14
+
Update the parameters and instance attributes to match the new population size.
15
+
16
+
Parameters
17
+
----------
18
+
ga_i : TYPE
19
+
The pygad.GA instance.
20
+
pop_size : TYPE
21
+
The new population size.
22
+
23
+
Returns
24
+
-------
25
+
None.
26
+
"""
27
+
28
+
ga_i.pop_size=pop_size
29
+
ga_i.sol_per_pop=ga_i.pop_size[0]
30
+
ga_i.num_parents_mating=int(ga_i.pop_size[0]/2)
31
+
32
+
# Calculate the new value for the num_offspring parameter.
0 commit comments