Character match search using Genetic algorihms
In computer science and operations research, a genetic algorithm (GA) is a meta-heuristic inspired by the process of natural selection that belongs to the larger class of evolutionary algorithms (EA). Genetic algorithms are commonly used to generate high-quality solutions to optimization and search problems by relying on bio-inspired operators such as mutation, crossover and selection.[1] John Holland introduced genetic algorithms in 1960 based on the concept of Darwin’s theory of evolution A.K.A Biological life; afterwards, his student Goldberg extended GA in 1989.
One of the most popular application of the genetic algorithm was on the traveling salesman challenge; for some of you unfamiliar to the concept, The travelling salesman problem (TSP) asks the following question: "Given a list of cities and the distances between each pair of cities, what is the shortest possible route that visits each city and returns to the origin city?" It is an NP-hard problem in combinatorial optimization, important in operations research and theoretical computer science.
- Basically; The traveler must reach all destinations while optimizing for the least travel distance.
Leveraging this Algorithm to search for a given text while only provide points for the corresponding letters.
Technical pre-requisite
*Python 3.6 and higher
*Jupyter Notebook
We initialize the Population by;
We proceed to assessing their fitness.
Firstly giving points to individual fitness assessment.
We compare them to get the best.
We select the best.
We infuse tinder in the program Lol. They search for mates; most notably the best to the best, Sorry no Fairy tail! The best part is that we can further develop this part to infuse traditional culture norms found in the human society....wait our society.
Now Here; The virtual creatures go to do the bed job to multiply! A random mutation has the chance to occur on single letter of the new born baby.
Make the entire population do the job! For the sake of the nation :)
Now we ran the program.
Sample output of the last cell:
Generation 0 while the best is "tqh !0I6.IK5grdu5Rhnh4Koc@xZ5oU59i.7H3 cmbGD.2PWzC4Me!AXn6.h251EqSDn4" with 7 after a 9.0 seconds Generation 1 while the best is "RssE6gr.Syih.mAsdTkG2pV!Qjju@uCCeD53p RZpjlW gqqz9PQeVftjdonn tIqibHv" with 9 after a 9.2 seconds Generation 2 while the best is "kgOoiX9qJtUpjl4lQ!amvP@OnlbsiYdtXZORqRPz5HuvMKasikOr0dfbnhgngovlttrrp" with 12 after a 8.8 seconds Generation 3 while the best is "dQ1HsejY8S0On yi s7!e.!QphbeYnQHszvTkS7BmCs7R.@qior2ySp4SYijgMle2feCc" with 17 after a 9.2 seconds Generation 4 while the best is "w!U EGolX.iKnzCgdUbdSd 1PptGvjg0gXv5q nOm!e.qhf 3o4bebbonn9ndSrTEuqgF" with 21 after a 9.8 seconds Generation 5 while the best is "vmPZWSob4liPrUiKv0fs0w onjEeInK 3zq!nGnFmberHokucUOphs QndRnB 2etUegX" with 26 after a 9.5 seconds Generation 6 while the best is "itsJ!0oSu@iwn iR ba@MrJqnBEehng givenTou4bv3TQX!cifrehgbnwitB qettQrT" with 34 after a 9.3 seconds Generation 7 while the best is "its eSTautDonpVsf7aseZ 2n bizdHbgi4!n9nAmbUr QfCcmr3l!p2nwin4olemtn.s" with 36 after a 9.4 seconds Generation 8 while the best is "ptx evol7tionpis ba3.d unIteinY5gDveg Zuvrlr oe coSresE4ndinNyJe@ters" with 44 after a 9.5 seconds Generation 9 while the best is "its8evZou0Moi.ispDased onNbe9nY given nuober ofucorAempondTGgNlZttvrs" with 48 after a 9.6 seconds Generation 10 while the best is "itsXev21uMSon is based on be2ngfjnven nHmb0r of cTrrespSndAng lHtteSs" with 53 after a 9.5 seconds Generation 11 while the best is "its e4olutionEis based on beini givep numbpr oOTcorpHspondiGg lettlrs" with 58 after a 9.5 seconds Generation 12 while the best is "its evolu9ion isybased on being given nupber of corcSs onding lejters" with 62 after a 9.5 seconds Generation 13 while the best is "its evolution is ba6ed onpbeing given numberof carrespon6ing letters" with 65 after a 9.5 seconds Generation 14 while the best is "jts evolution is based on being given numbGr of corresponding letters" with 67 after a 9.7 seconds Generation 15 while the best is "its evolution is based on being given number of corresponding letters" with 69 after a 1e+01 seconds Found Target after 151.35251712799072 Seconds
Notebook code available on Github!
https://github.com/agent87/Character-Guessing-Genetic-Algorithm.git
Comments
Post a Comment