Quantcast

Question about Mutation Operator

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Question about Mutation Operator

Giuseppe Quartarone

Hi all,


Recently I have been working with genetic algorithms and I would start by saying thank you guys for your work on jgap, it is a very good framework.

I'm writing you because I would like some advice about mutation operator in jgap.

In my implementation I wrote my gene according to the documentation webpage. Basically it is very similar to the IntegerGene, and according to my implementation I override the correct "applyMutation" method. Moreover, I wrote the proper random generator and either the gene and random generator implementations work properly with the rest of my project. Regarding the mutation operator, I'm using the MutationOperator class, which is present in the framewok and I added its instance to the configuration with the "addGeneticOperator" but the mutation is not working.

So I read the MutationOperator.class code present in the package that I downloaded and I found the following piece of code at line 220.


// Process all atomic elements in the gene. For a StringGene this

         // would be as many elements as the string is long , for an

         // IntegerGene, it is always one element.

         // --------------------------------------------------------------

         if (genes[j] instanceof ICompositeGene) {

           ICompositeGene compositeGene = (ICompositeGene) genes[j];

           if (m_monitorActive) {

                 compositeGene.setUniqueIDTemplate(chrom.getGene(j).getUniqueID(), 1);

           }

           for (int k = 0; k < compositeGene.size(); k++) {

             mutateGene(compositeGene.geneAt(k), generator);

             if (m_monitorActive) {

               compositeGene.geneAt(k).setUniqueIDTemplate(

                   ( (ICompositeGene) chrom.getGene(j)).geneAt(k).getUniqueID(),

                   1);

             }

           }

         }

         else {

           mutateGene(genes[j], generator);

           if (m_monitorActive) {

             genes[j].setUniqueIDTemplate(chrom.getGene(j).getUniqueID(), 1);

           }

         }


As you can see the "mutateGene" method is called either by the true branch and the else branch. Below the "mutateGene" implementation:


/**

  * Helper: mutate all atomic elements of a gene.

  *

  * @param a_gene the gene to be mutated

  * @param a_generator the generator delivering the amount of mutation

  *

  * @author Klaus Meffert

  * @since 1.1

  */

 private void mutateGene(final Gene a_gene, final RandomGenerator a_generator) {

    for (int k = 0; k < a_gene.size(); k++) {

     // Retrieve value between 0 and 1 (not included) from generator.

     // Then map this value to range -1 and 1 (-1 included, 1 not).

     // -------------------------------------------------------------

     double percentage = -1 + a_generator.nextDouble() * 2;

     // Mutate atomic element by calculated percentage.

     // -----------------------------------------------

     a_gene.applyMutation(k, percentage);

    }

 }


Thus, when the "mutateGene" is called and the gene is not an instance of "ICompoisteGene" his size is zero and the mutation never take place.
However, this issue doesn’t occur if I call the "applyMutation" in the else branch, so I'm wondering whether this is the main cause or I wrongly set up the framework configuration.

Thanks in advance for your time


Best regards
Giuseppe


------------------------------------------------------------------------------
Minimize network downtime and maximize team effectiveness.
Reduce network management and security costs.Learn how to hire
the most talented Cisco Certified professionals. Visit the
Employer Resources Portal
http://www.cisco.com/web/learning/employer_resources/index.html
_______________________________________________
jgap-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jgap-users
Loading...