A Java-based Implementation for Genetic Algorithm (GA)
- Encoding
- Binary Solution
- Evolutionary Operators
- Selection
- Tournament Selection
- Crossover
- Single Point Crossover
- Mutation
- Bit Flip Mutation
- Replacement
- Best Solutions Replacement
- Selection
Add a new repository on your Maven project (please refer to https://jitpack.io if you want to add it by using Gradle):
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Then add the dependency.
<dependency>
<groupId>com.github.thiagodnf</groupId>
<artifactId>genetic-algorithm</artifactId>
<version>0.0.3</version>
</dependency>
Now you can import the classes on your project. For instance:
int populationSize = 100;
int maxGenerations = 1000;
Problem problem = new ZeroOneProblem(10);
GeneticAlgorithm ga = new GeneticAlgorithm(problem, populationSize, maxGenerations);
ga.setSelection(new TournamentSelection(2));
ga.setCrossover(new SinglePointCrossover(0.95));
ga.setMutation(new BitFlipMutation(0.005));
ga.setReplacement(new BestSolutionsReplacement());
Solution bestSolution = ga.run();
System.out.println(bestSolution);
This is the output:
#415 [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] = -10.0
Feel free to access the discussions tab as you need
Contributions to the this project are very welcome! We can't do this alone! Feel free to fork this project, work on it and then make a pull request.
Licensed under the MIT license.
I open-source almost everything I can, and I try to reply to everyone needing help using these projects. Obviously, this takes time. You can integrate and use these projects in your applications for free! You can even change the source code and redistribute (even resell it).
However, if you get some profit from this or just want to encourage me to continue creating stuff, reach out to me if you want to do it.
Thanks!
❤️