We then set each Gene in the array to an IntegerGene that is constructed with appropriate lower and upper bounds for that coin type. In fact, we look at what a QuarterGene might look like in the Creating Custom Genes document that we just mentioned. Ultimately, you’ll need to settle on a value that balances your need for a nice selection of potential solutions against how much time you’re willing to spend waiting for your population to evolve. So to get back to the code, we first create an array of Genes with a length of 4, since we want to represent 4 genes one for each coin type. The evaluate method is a standard method that all fitness functions must implement. If you want, you can construct each Chromosome individually and then pass them all into a new Genotype much like we constructed each Gene and passed them into the sample Chromosome in step 3 , but JGAP provides a much quicker and easier way of creating a random population.
|Date Added:||16 July 2008|
|File Size:||29.97 Mb|
|Operating Systems:||Windows NT/2000/XP/2003/2003/7/8/10 MacOS 10/X|
|Price:||Free* [*Free Regsitration Required]|
Getting Started With JGAP
The first thing the evaluate method does is invoke a couple of helper methods which conveniently return the total amount of change that is represented by the potential solution and the total number of coins represented by the solution. That’s where the fitness function comes in: Please note that this documentation could be correlated to a former JGAP version.
Limiting the solution space this way helps JGAP arrive at better solutions with jgzp evolutions. A population of Chromosomes is called a Kgap, and that is the class we need to construct to create our population.
Since the goal of our small program is to produce an amount of change in American coins equal to a target amount in the fewest possible number of coins, it seems reasonable that the measure of fitness for a ngap solution would be a combination of the relative closeness of the amount of change it represented to the target amount of change, and the total number of coins represented by the solution fewer being better. To view all of the code for this example, see the MinimizingMakeChange.
That provides the most flexibility and convenience. The lower the number 1 being the lowest legal fitness valuethe poorer the solution. The goal of our program will be to produce a user-specified amount of change in the fewest possible American coins quarters, dimes, nickels, and pennies.
As mentioned earlier, the value of each gene in the Chromosome is called an allele.
If the best solution so far is good enough for you, then you’re done. We set the upper bounds to be the largest number of coins of that respective type that would appear in an optimal solution.
The value of a gene is called an allele. In our example, the allele would be the number of a given type of coin for example, 2 pennies.
We’ll actually write the code to setup our Chromosome objects in step jga. And that’s the end of the fitness function. To use JGAP in an application, there are five basic things that you must jgsp In fact, we look at what a QuarterGene might look like in the Creating Custom Genes document that we just mentioned.
Then, if the solution amount happens to equal the target amount, we go to stage two, which adjusts the fitness value based upon the total number of coins represented by the solution. A larger population size means more potential solutions to choose from and more genetic diversity, but it also means more work to evolve that population.
However, it has no knowledge of the specific problem you’re actually trying to solve, and hence has no intrinsic way of deciding if one potential solution is any better than another potential solution for your specific problem.
If you want, you can construct each Chromosome individually jgzp then pass them all into a new Genotype much like we constructed each Gene and passed them into the sample Chromosome in step 3but JGAP provides a much quicker and easier way of creating a random population.
As the comments indicate, we’re going to calculate fitness in two stages.
The final part of this step is setting the population size, which is the number of Chromosomes we want in the population. The interesting part of the whole class is the evaluate method, which is where the work is done.
Getting Started with JGAP
If you’re feeling a little bit overwhelmed, don’t worry about it and take some comfort in the fact that it’s all down hill from here! Our constructor isn’t very exciting: Recall jyap each potential solution is represented by a Chromosome.
A Chromosome is made up of genes, each of which represents a respective part of the solution.
Alternatively, you may just choose to evolve the population a set number of times and then see what the best solution is that was produced at the end or a combination thereof. To start, we define our own class and extend the org.
The next convenience method, getNumberOfCoinsAtGeneis responsible for determining the number of coins represented by a specific gene in the given Chromosome. For most applications, this is all that’s necessary to create your initial population of potential solutions. Let’s look at that bit in a little more detail.