Logo
Distributed Genetic Programming Framework
print print

File org.dgpf.gp.automaton.search.MutationDispatcher.java

Here you can find all the information about the file org.dgpf.gp.automaton.search.MutationDispatcher.java. You may explore it here or download it onto your local disk.
/*
 * Copyright (c) 2005 Thomas Weise
 *
 * E-Mail           : tweise@gmx.de
 * Creation Date    : 2005-12-28 11:48:01
 * Original Filename: org.dgpf.automaton.genetics.MutationDispatcher.java
 * Version          : 2.2.1
 * Last modification: 2006-05-08
 *                by: Thomas Weise
 *
 * License          : GNU LESSER GENERAL PUBLIC LICENSE
 *                    Version 2.1, February 1999
 *                    You should have received a copy of this license along
 *                    with this library; if not, write to the Free Software
 *                    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *                    MA 02111-1307, USA or download the license under
 *                    http://www.gnu.org/copyleft/lesser.html.
 *
 * Warranty         : This software is provided "as is" without any
 *                    warranty; without even the implied warranty of
 *                    merchantability or fitness for a particular purpose.
 *                    See the Gnu Lesser General Public License for more
 *                    details.
 */


package org.dgpf.gp.automaton.search;

import org.dgpf.search.api.SearchUtils;
import org.sfc.math.stochastic.Randomizer;




/**
 * This class selects one possibility of many to perform a mutation on a
 * given object.
 *
 * @param <Genotype>  The genotype of the objects to mutate.
 * @param <Return>    The return type of the mutation operation.
 *
 * @author Thomas Weise
 */

class MutationDispatcher<Return, Genotype extends Return>
                                     extends Mutator<Return, Genotype>
  {
/**
 * The maximum count of trials to spend trying to get new and different
 * individuals in the mutation routine, to prevent deadlocks.
 */

  static  final int          MAX_DIFF_TRIALS   = 1000;
/**
 * The internal mutator array.
 */

  private final Mutator<Return, Genotype>[] m_mutators      ;
/**
 * The probabilities.
 */

  private final double[]                    m_probabilities ;

/**
 * Create a new mutation dispatcher.
 * @param p_mutators    The array of mutators to dispatch to.
 * @param p_weight      The array with the relative importance of the
 *                      different mutations. The higher the according
 *                      value, the heigher the probability of the mutation.
 */

  public  MutationDispatcher(final  Mutator<Return, Genotype>[] p_mutators,
                             final  double[]                    p_weight)
    {
    super();

    final double[] l_prob;

    l_prob = p_weight.clone();

    this.m_mutators      = p_mutators;
    SearchUtils.normalize(l_prob);
    this.m_probabilities = l_prob;
    }

/**
 * Mutate an existing instance of the genotype.
 * @param p_source        The source instance.
 * @param p_context       The (calling) context to be used.
 * @param p_info          An additional information integer.
 * @param p_memory_size   The memory size currently available.
 * @return The randomly mutated copy of the source or <code>p_source</code>
 *         itself if it cannot be mutated in any way.
 */

  @Override
  protected final Return mutate(final  Genotype           p_source,
                                final  ProgramContext     p_context,
                                final  int                p_info,
                                final  int                p_memory_size)
    {
    final int                         l_l;
    final Mutator<Return, Genotype>[] l_m;
          int                         l_k, l_i, l_c;
          Return                      l_r;
    final boolean[]                   l_b;
    final double[]                    l_prb;
    final Randomizer                  l_x;

    l_m   = this.m_mutators;
    l_prb = this.m_probabilities;
    l_l   = l_m.length;
    l_c   = MAX_DIFF_TRIALS;
    l_x   = p_context.get_randomizer();
    
    l_i = SearchUtils.random_index(l_prb, l_x.nextDouble());
    
    l_r = l_m[l_i].mutate(p_source, p_context, p_info,
                          p_memory_size);
    if( (l_r != null) && (l_r != p_source) ) return l_r;

    if(l_l <= 1) return p_source;
    
    l_b      = new boolean[l_l];
    l_b[l_i] = true;

    for(l_k = (l_l-2); l_k >= 0; l_k--)
      {
      do
        {
        if((--l_c) <= 0) return p_source; 
        l_i = SearchUtils.random_index(l_prb, l_x.nextDouble());
        } while(l_b[l_i]);

      l_r = l_m[l_i].mutate(p_source, p_context, p_info,
                            p_memory_size);
      if( (l_r != null) && (!(l_r.equals(p_source)))) return l_r;
      l_b[l_i] = true;
      }

    return p_source;
    }
  
/**
 * Returns the count of installed mutators.
 * @return The count of installed mutators.
 */

  final int get_mutator_count ()
    {
    return this.m_mutators.length;
    }
  }

File Information:

file name:MutationDispatcher.java
package:org.dgpf.gp.automaton.search
qualified name:org.dgpf.gp.automaton.search.MutationDispatcher.java
file type:Java Source File
download location:download http://dgpf.sourceforge.net/source/org/dgpf/gp/automaton/search/MutationDispatcher.java
size:4.799 KB (4915 B)
uploaded: 2015-07-22 04:10:55 GMT+0000
last update: 2006-06-08 08:15:49 GMT+0000
last access: 2017-11-20 02:20:57 GMT+0000

statistics online since 2006-01-02.   RSS Feed
Contact us by sending an email to tweise@gmx.de to receive further information, to report errors, or to join our project.
All content on this site (http://dgpf.sourceforge.net/) is LGPL-licensed.
http://dgpf.sourceforge.net/scripts/source/source.php last modified at 2015-07-22 04:10:53 GMT+0000 served at 2017-11-20 02:20:57 GMT+0000.
Valid CSS Valid XHTML 1.1
Valid RSS SourceForge.net Logo