|
9 | 9 | from pygad import utils |
10 | 10 | from pygad import helper |
11 | 11 | from pygad import visualize |
12 | | -import sys |
13 | 12 |
|
14 | 13 | # Extend all the classes so that they can be referenced by just the `self` object of the `pygad.GA` class. |
15 | 14 | class GA(utils.parent_selection.ParentSelection, |
@@ -446,7 +445,7 @@ def __init__(self, |
446 | 445 | raise TypeError(f"The value assigned to the 'initial_population' parameter is expected to by of type list, tuple, or ndarray but {type(initial_population)} found.") |
447 | 446 | elif numpy.array(initial_population).ndim != 2: |
448 | 447 | self.valid_parameters = False |
449 | | - raise ValueError(f"A 2D list is expected to the initail_population parameter but a ({numpy.array(initial_population).ndim}-D) list found.") |
| 448 | + raise ValueError(f"A 2D list is expected to the initial_population parameter but a ({numpy.array(initial_population).ndim}-D) list found.") |
450 | 449 | else: |
451 | 450 | # Validate the type of each value in the 'initial_population' parameter. |
452 | 451 | for row_idx in range(len(initial_population)): |
@@ -1333,7 +1332,8 @@ def __init__(self, |
1333 | 1332 | self.pareto_fronts = None |
1334 | 1333 | except Exception as e: |
1335 | 1334 | self.logger.exception(e) |
1336 | | - sys.exit(-1) |
| 1335 | + # sys.exit(-1) |
| 1336 | + raise e |
1337 | 1337 |
|
1338 | 1338 | def round_genes(self, solutions): |
1339 | 1339 | for gene_idx in range(self.num_genes): |
@@ -1867,7 +1867,8 @@ def cal_pop_fitness(self): |
1867 | 1867 | pop_fitness = numpy.array(pop_fitness) |
1868 | 1868 | except Exception as ex: |
1869 | 1869 | self.logger.exception(ex) |
1870 | | - sys.exit(-1) |
| 1870 | + # sys.exit(-1) |
| 1871 | + raise ex |
1871 | 1872 | return pop_fitness |
1872 | 1873 |
|
1873 | 1874 | def run(self): |
@@ -2242,7 +2243,8 @@ def run(self): |
2242 | 2243 | # self.solutions = numpy.array(self.solutions) |
2243 | 2244 | except Exception as ex: |
2244 | 2245 | self.logger.exception(ex) |
2245 | | - sys.exit(-1) |
| 2246 | + # sys.exit(-1) |
| 2247 | + raise ex |
2246 | 2248 |
|
2247 | 2249 | def best_solution(self, pop_fitness=None): |
2248 | 2250 | """ |
@@ -2277,7 +2279,8 @@ def best_solution(self, pop_fitness=None): |
2277 | 2279 | best_solution_fitness = pop_fitness[best_match_idx] |
2278 | 2280 | except Exception as ex: |
2279 | 2281 | self.logger.exception(ex) |
2280 | | - sys.exit(-1) |
| 2282 | + # sys.exit(-1) |
| 2283 | + raise ex |
2281 | 2284 |
|
2282 | 2285 | return best_solution, best_solution_fitness, best_match_idx |
2283 | 2286 |
|
|
0 commit comments