Description
The ga.ssGA package contains the implementation of a steady state genetic algorithm in Java. This EA-(m ,1) algorithm uses binary tournament selection, single point crossover returning one random child out of the two created by the crossover, bit flip mutation, and replacement always of the worst individual in the population in every step. The package is offered to solve two problems: ONEMAX and P-PEAKS, and of course can be modified to solve your problem.
Files in the Package:
- Exe.java
- Algorithm.java
- Problem.java
- ProblemOneMax.java
- ProblemPPeaks.java
- Individual
- Chromosome.java
- Population.java
Compiling and running the program
To compile the program, you can use the following command after having unzipped the ssGA.zip file:
javac ga/ssGA/*.java [-d class_directory]
To run the program, execute the following commmand:
java ga.ssGA.Exe
Configuring the program
The ssGA program can solve two problems, ONEMAX and P-PEAKS. To specify what problem you want to solve, make the following changes in the Exe.java program:
- Set the parameters of the execution (gene number, gene length, population size, etc), located at the beginning of the main() method.
- Choose the problem to be solved, creating a ProblemOneMax or a ProblemPPeaks object, just below the parameters (you have only to uncomment the desired choice)
Extending the program with new problems
You can use the ga.ssGA package to solve new problems, besides ONEMAX and P-PEAKS. The simplest way to add a new problem is to understand how the current ones are implemented. Let us see, for example, the file ProblemOneMax.java. It can be observed that the class ProblemOneMax inherits from the class Problem, and it contains a method named Evaluate() that must be implemented. This method receives an individual as parameter, and returns a double value that represents the fitness of the individual.
So, to add a new problem (eg, NewProblem), follow the next steps:
- Create a file named NewProblem.java
- Include this file into the ga.ssGA package
- Define the class NewProblem, that has to inherit from (extend) the class Problem
- Define the Evaluate() method
- Set the parameters of the problem in the file Exe.java
- In the file Exe.java, create an instance of the new problem, as indicated above (in Configuring the program)
- Compile and run the program with javac and java, respectively