@@ -9,7 +9,7 @@ This section of the PyGAD's library documentation discusses the
99Using the ``pygad `` module, instances of the genetic algorithm can be
1010created, run, saved, and loaded.
1111
12- .. _header-n3 :
12+ .. _header-n4 :
1313
1414``pygad.GA `` Class
1515==================
@@ -19,7 +19,7 @@ class named ``GA`` for building the genetic algorithm. The constructor,
1919methods, function, and attributes within the class are discussed in this
2020section.
2121
22- .. _header-n5 :
22+ .. _header-n6 :
2323
2424``__init__() ``
2525--------------
@@ -142,7 +142,7 @@ parameter (i.e. ``init_range_low`` is not needed to be lower than
142142The parameters are validated within the constructor. If at least a
143143parameter is not validated, an exception is thrown.
144144
145- .. _header-n48 :
145+ .. _header-n49 :
146146
147147Other Instance Attributes & Methods
148148-----------------------------------
@@ -154,7 +154,7 @@ attributes and methods added to the instances of the **pygad.GA** class:
154154
155155The next 2 subsections list such attributes and methods.
156156
157- .. _header-n51 :
157+ .. _header-n52 :
158158
159159Other Attributes
160160~~~~~~~~~~~~~~~~
@@ -179,7 +179,7 @@ Other Attributes
179179 fitness value is reached. It is only assigned the generation number
180180 after the ``run() `` method completes. Otherwise, its value is -1.
181181
182- .. _header-n67 :
182+ .. _header-n68 :
183183
184184Other Methods
185185~~~~~~~~~~~~~
@@ -203,7 +203,7 @@ Other Methods
203203The next sections discuss the methods available in the **pygad.GA **
204204class.
205205
206- .. _header-n78 :
206+ .. _header-n79 :
207207
208208``initialize_population() ``
209209---------------------------
@@ -230,7 +230,7 @@ This method assigns the values of the following 3 instance attributes:
230230
2312313. ``initial_population ``: Keeping the initial population.
232232
233- .. _header-n94 :
233+ .. _header-n95 :
234234
235235``cal_pop_fitness() ``
236236---------------------
@@ -244,7 +244,7 @@ constructor for each solution.
244244
245245It returns an array of the solutions' fitness values.
246246
247- .. _header-n98 :
247+ .. _header-n99 :
248248
249249``run() ``
250250---------
@@ -288,7 +288,7 @@ After the ``run()`` method completes, the following takes place:
288288
289289- The ``run_completed `` attribute is set to ``True ``.
290290
291- .. _header-n117 :
291+ .. _header-n118 :
292292
293293Parent Selection Methods
294294------------------------
@@ -306,49 +306,49 @@ All of such methods return an array of the selected parents.
306306
307307The next subsections list the supported methods for parent selection.
308308
309- .. _header-n126 :
309+ .. _header-n127 :
310310
311311``steady_state_selection() ``
312312~~~~~~~~~~~~~~~~~~~~~~~~~~~~
313313
314314Selects the parents using the steady-state selection technique.
315315
316- .. _header-n128 :
316+ .. _header-n129 :
317317
318318``rank_selection() ``
319319~~~~~~~~~~~~~~~~~~~~
320320
321321Selects the parents using the rank selection technique.
322322
323- .. _header-n130 :
323+ .. _header-n131 :
324324
325325``random_selection() ``
326326~~~~~~~~~~~~~~~~~~~~~~
327327
328328Selects the parents randomly.
329329
330- .. _header-n132 :
330+ .. _header-n133 :
331331
332332``tournament_selection() ``
333333~~~~~~~~~~~~~~~~~~~~~~~~~~
334334
335335Selects the parents using the tournament selection technique.
336336
337- .. _header-n134 :
337+ .. _header-n135 :
338338
339339``roulette_wheel_selection() ``
340340~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
341341
342342Selects the parents using the roulette wheel selection technique.
343343
344- .. _header-n136 :
344+ .. _header-n137 :
345345
346346``stochastic_universal_selection() ``
347347~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
348348
349349Selects the parents using the stochastic universal selection technique.
350350
351- .. _header-n138 :
351+ .. _header-n139 :
352352
353353Crossover Methods
354354-----------------
@@ -365,31 +365,31 @@ All of such methods return an array of the produced offspring.
365365
366366The next subsections list the supported methods for crossover.
367367
368- .. _header-n147 :
368+ .. _header-n148 :
369369
370370``single_point_crossover() ``
371371~~~~~~~~~~~~~~~~~~~~~~~~~~~~
372372
373373Applies the single-point crossover. It selects a point randomly at which
374374crossover takes place between the pairs of parents.
375375
376- .. _header-n149 :
376+ .. _header-n150 :
377377
378378``two_points_crossover() ``
379379~~~~~~~~~~~~~~~~~~~~~~~~~~
380380
381381Applies the 2 points crossover. It selects the 2 points randomly at
382382which crossover takes place between the pairs of parents.
383383
384- .. _header-n151 :
384+ .. _header-n152 :
385385
386386``uniform_crossover() ``
387387~~~~~~~~~~~~~~~~~~~~~~~
388388
389389Applies the uniform crossover. For each gene, a parent out of the 2
390390mating parents is selected randomly and the gene is copied from it.
391391
392- .. _header-n153 :
392+ .. _header-n154 :
393393
394394Mutation Methods
395395----------------
@@ -403,7 +403,7 @@ All of such methods return an array of the mutated offspring.
403403
404404The next subsections list the supported methods for mutation.
405405
406- .. _header-n160 :
406+ .. _header-n161 :
407407
408408``random_mutation() ``
409409~~~~~~~~~~~~~~~~~~~~~
@@ -417,31 +417,31 @@ specified by the 2 attributes ``random_mutation_min_val`` and
417417``random_mutation_max_val ``. The random value is added to the selected
418418gene.
419419
420- .. _header-n163 :
420+ .. _header-n164 :
421421
422422``swap_mutation() ``
423423~~~~~~~~~~~~~~~~~~~
424424
425425Applies the swap mutation which interchanges the values of 2 randomly
426426selected genes.
427427
428- .. _header-n165 :
428+ .. _header-n166 :
429429
430430``inversion_mutation() ``
431431~~~~~~~~~~~~~~~~~~~~~~~~
432432
433433Applies the inversion mutation which selects a subset of genes and
434434inverts them.
435435
436- .. _header-n167 :
436+ .. _header-n168 :
437437
438438``scramble_mutation() ``
439439~~~~~~~~~~~~~~~~~~~~~~~
440440
441441Applies the scramble mutation which selects a subset of genes and
442442shuffles their order randomly.
443443
444- .. _header-n169 :
444+ .. _header-n170 :
445445
446446``best_solution() ``
447447-------------------
@@ -459,7 +459,7 @@ following is returned:
459459- ``best_match_idx ``: Index of the best solution in the current
460460 population.
461461
462- .. _header-n179 :
462+ .. _header-n180 :
463463
464464``plot_result() ``
465465-----------------
@@ -470,7 +470,7 @@ generation.
470470
471471If no generation is completed (at least 1), an exception is raised.
472472
473- .. _header-n182 :
473+ .. _header-n183 :
474474
475475``save() ``
476476----------
@@ -482,7 +482,7 @@ Accepts the following parameter:
482482- ``filename ``: Name of the file to save the instance. No extension is
483483 needed.
484484
485- .. _header-n188 :
485+ .. _header-n189 :
486486
487487Functions in ``pygad ``
488488======================
@@ -491,7 +491,7 @@ Besides the methods available in the **pygad.GA** class, this section
491491discusses the functions available in pygad. Up to this time, there is
492492only a single function named ``load() ``.
493493
494- .. _header-n190 :
494+ .. _header-n191 :
495495
496496``pygad.load() ``
497497----------------
@@ -508,7 +508,7 @@ Accepts the following parameter:
508508
509509Returns the genetic algorithm instance.
510510
511- .. _header-n197 :
511+ .. _header-n198 :
512512
513513Steps to Use ``pygad ``
514514======================
@@ -533,7 +533,7 @@ To use the ``pygad`` module, here is a summary of the required steps:
533533
534534Let's discuss how to do each of these steps.
535535
536- .. _header-n217 :
536+ .. _header-n218 :
537537
538538Preparing the ``fitness_func `` Parameter
539539-----------------------------------------
@@ -593,7 +593,7 @@ an exception is thrown.
593593By creating this function, you almost did an awesome step towards using
594594PyGAD.
595595
596- .. _header-n233 :
596+ .. _header-n234 :
597597
598598Preparing Other Parameters
599599~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -621,7 +621,7 @@ Here is an example for preparing the other parameters:
621621 mutation_type = " random"
622622 mutation_percent_genes = 10
623623
624- .. _header-n236 :
624+ .. _header-n237 :
625625
626626The ``callback_generation `` Parameter
627627~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -654,7 +654,7 @@ generation.
654654 After the parameters are prepared, we can import PyGAD and build an
655655instance of the **pygad.GA ** class.
656656
657- .. _header-n242 :
657+ .. _header-n243 :
658658
659659Import the ``pygad ``
660660--------------------
@@ -668,7 +668,7 @@ The next step is to import PyGAD as follows:
668668 The **pygad.GA ** class holds the implementation of all methods for
669669running the genetic algorithm.
670670
671- .. _header-n246 :
671+ .. _header-n247 :
672672
673673Create an Instance of the ``pygad.GA `` Class
674674--------------------------------------------
@@ -692,7 +692,7 @@ for creating the initial population.
692692 mutation_type = mutation_type,
693693 mutation_percent_genes = mutation_percent_genes)
694694
695- .. _header-n249 :
695+ .. _header-n250 :
696696
697697Run the Genetic Algorithm
698698-------------------------
@@ -716,7 +716,7 @@ by doing the following tasks:
716716
7177174. Repeat the process for the specified number of generations.
718718
719- .. _header-n262 :
719+ .. _header-n263 :
720720
721721Plotting Results
722722----------------
@@ -732,7 +732,7 @@ generations.
732732 .. figure :: https://user-images.githubusercontent.com/16560492/78830005-93111d00-79e7-11ea-9d8e-a8d8325a6101.png
733733 :alt:
734734
735- .. _header-n266 :
735+ .. _header-n267 :
736736
737737Information about the Best Solution
738738-----------------------------------
@@ -762,7 +762,7 @@ fitness** is reached could be fetched.
762762 if ga_instance.best_solution_generation != - 1 :
763763 print (" Best fitness value reached after {best_solution_generation} generations." .format(best_solution_generation = ga_instance.best_solution_generation))
764764
765- .. _header-n278 :
765+ .. _header-n279 :
766766
767767Saving & Loading the Results
768768----------------------------
@@ -795,7 +795,7 @@ any property.
795795
796796 print (loaded_ga_instance.best_solution())
797797
798- .. _header-n285 :
798+ .. _header-n286 :
799799
800800Crossover, Mutation, and Parent Selection
801801=========================================
@@ -805,7 +805,7 @@ the crossover & mutation operators. More features will be added in the
805805future. To ask for a new feature, please check the **Ask for Feature **
806806section.
807807
808- .. _header-n287 :
808+ .. _header-n288 :
809809
810810Supported Crossover Operations
811811------------------------------
@@ -819,7 +819,7 @@ The supported crossover operations at this time are:
819819
8208203. Uniform: Implemented using the ``uniform_crossover() `` method.
821821
822- .. _header-n296 :
822+ .. _header-n297 :
823823
824824Supported Mutation Operations
825825-----------------------------
@@ -834,7 +834,7 @@ The supported mutation operations at this time are:
834834
8358354. Scramble: Implemented using the ``scramble_mutation() `` method.
836836
837- .. _header-n307 :
837+ .. _header-n308 :
838838
839839Supported Parent Selection Operations
840840-------------------------------------
@@ -856,15 +856,15 @@ The supported parent selection techniques at this time are:
856856
8578576. Tournament: Implemented using the ``tournament_selection() `` method.
858858
859- .. _header-n322 :
859+ .. _header-n323 :
860860
861861Examples
862862========
863863
864864This section gives the complete code of some examples that use
865865``pygad ``. Each subsection builds a different example.
866866
867- .. _header-n324 :
867+ .. _header-n325 :
868868
869869Linear Model Optimization
870870-------------------------
0 commit comments