|
6 | 6 | """ |
7 | 7 |
|
8 | 8 | import numpy |
9 | | - |
10 | 9 | import pygad |
11 | 10 |
|
12 | | - |
13 | 11 | def fitness_func(ga_instance, solution, solution_idx): |
14 | 12 | return [float(numpy.sum(solution)), |
15 | 13 | -float(numpy.sum(numpy.asarray(solution) ** 2))] |
16 | 14 |
|
17 | | - |
18 | | -def main(): |
19 | | - ga_instance = pygad.GA( |
20 | | - num_generations=30, |
21 | | - num_parents_mating=8, |
22 | | - fitness_func=fitness_func, |
23 | | - sol_per_pop=20, |
24 | | - num_genes=4, |
25 | | - parent_selection_type="nsga2", |
26 | | - save_solutions=True, |
27 | | - random_seed=42, |
28 | | - suppress_warnings=True, |
29 | | - ) |
30 | | - ga_instance.run() |
31 | | - output_path = ga_instance.generate_report( |
32 | | - filename="pygad_report", |
33 | | - title="PyGAD multi-objective demo", |
34 | | - notes="A short two-objective example with 30 generations.", |
35 | | - ) |
36 | | - print(f"Report written to: {output_path}") |
37 | | - |
38 | | - |
39 | | -if __name__ == "__main__": |
40 | | - main() |
| 15 | +ga_instance = pygad.GA(num_generations=30, |
| 16 | + num_parents_mating=8, |
| 17 | + fitness_func=fitness_func, |
| 18 | + sol_per_pop=20, |
| 19 | + num_genes=4, |
| 20 | + parent_selection_type="nsga2", |
| 21 | + save_solutions=True, |
| 22 | + random_seed=42, |
| 23 | + suppress_warnings=True,) |
| 24 | +ga_instance.run() |
| 25 | +output_path = ga_instance.generate_report(filename="pygad_report", |
| 26 | + title="PyGAD multi-objective demo", |
| 27 | + notes="A short two-objective example with 30 generations.",) |
| 28 | +print(f"Report written to: {output_path}") |
0 commit comments