This is a Java program, run in the terminal, that generates a target word/phrase using Genetic Algorithms
This program uses ANSI Escape Sequences meaning that Windows Command Prompt (cmd) CANNOT OUTPUT CORRECTLY!
If you are using Windows, there are a number of terminal emulators available that do support ANSI Escape Sequences, the easiest of which to get is:
These are some terms that are necessary to understand in order to use this program:
Target
The word or phrase that the program will try to generate using genetic algorithms
Word
Each
Wordhas the same number of letters as thetargetword/phraseEvery
Wordhas afitnessbased on the letters it contains
Fitness
If a letter in a given
Wordis the same letter and in the same spot as in thetarget, it is worth 1fitness
Fitnessfor eachWordis calculated by summing up each letter'sfitnessExample:
target= cat
Word= cac
Fitness= 2 (1 for the c and 1 for the a and 0 for the second c)
Population
A collection of
Wordsused to generate newWordsA
Populationknows:The highest
fitnesswithin the populationThe word that has the highest
fitnessin the populationThe average
fitnessin the population
Generation
Each
Generationa newPopulationis createdThis new
Populationgets itsWordsby mutating theWordsof the oldPopulationIt does this by picking 2
Wordsfrom the oldPopulationasparentsand creating a newWord(thechild) from thoseparentsEvery
childhas a 50% chance to inherit a letter from eachparent(50% to inherit from parent 1 and 50% to inherit from parent 2)Every
childalso has a user determined percent chance to have each lettermutateA
mutationreplaces that letter with a random letter and no inheritance happens for that letter
java wordGenerator.WordGenerator
If this command does not work, you probably need to define the classpath for the JVM to use.
While in the JavaWordGenerator folder use the command:
java -cp . wordGenerator.WordGenerator or java --classpath . wordGenerator.WordGenerator
It will ask you to input some values:
Population size
The number of words to be mutated in a
Population
Population sizeis anint
Mutation Percentage
The percentage each letter in a given word has to
mutate(randomly change to another letter)
Mutation Percentageis entered as anintwhich is interpreted as a percentageex:
Mutation Percentage= 10 -> 10% chance for a letter to mutate
Target
The word/phrase that this program will try to generate
is a
Stringand can include A-Z, a-z, 0-9, spaces, and symbols
Input: java wordGenerator.WordGenerator
Output: Please enter population size
Input: 100
Output: Please enter the percentage for the mutation to occour
Input: 1
Output: Please enter target word or phrase
Input: Hello World
Output:
Generation: 559
Top Word: Hello World
Fitness: 11
Average Fitness: 9.880000
Elapsed time: 0.8557480000000001 second(s)