Logo
Distributed Genetic Programming Framework
print print

File org.dgpf.gp.vm.mutation.ProgramCrossover.java

Here you can find all the information about the file org.dgpf.gp.vm.mutation.ProgramCrossover.java. You may explore it here or download it onto your local disk.
/*
 * Copyright (c) 2006 Thomas Weise
 * 
 * E-Mail           : tweise@gmx.de
 * Creation Date    : 2006-07-03 16:36:27
 * Original Filename: org.dgpf.gp.vm.mutation.ProgramCrossover.java
 * Version          : 1.0.0
 * Last modification: 2006-07-03
 *                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.vm.mutation;

import org.dgpf.gp.vm.base.Instruction;
import org.dgpf.gp.vm.base.VMContext;
import org.dgpf.gp.vm.instructions.ctrl.Call;
import org.sfc.math.stochastic.Randomizer;
import org.sfc.utils.Typesafe;

/**
 * This class is used to perform the crossover operation of two programs.
 *
 * @author Thomas Weise
 */

public final  class ProgramCrossover
  {
  
/**
 * Perform a crossover operation on two programs.
 * @param p_source_1  The first source program.
 * @param p_source_2  The second source program.
 * @param p_context   The context to be used.
 * @return  The new program which is a product of its two elders. 
 */

  public  static  final Instruction[][] crossover
                              (      Instruction[][] p_source_1,
                                     Instruction[][] p_source_2,
                               final VMContext       p_context)
    {
    Randomizer      l_r;
    int             l_s, l_d, l_c, l_l, l_i, l_t;
    Instruction[][] l_dst;
    Instruction[]   l_x;
    Instruction     l_c1;
    Call            l_c2;
    double          l_dx;
    
    
    if(p_source_2.length < 1) return p_source_1;
    if(p_source_1.length < 1) return p_source_2;
    
    l_r   = p_context.get_randomizer();
    l_l   = p_source_1.length;
    
    if(l_l <= 1)
      {
      if((l_l = p_source_2.length) <= 1)
        {
        return p_source_1;
        }
      
      l_dst      = p_source_1;
      p_source_1 = p_source_2;
      p_source_2 = l_dst;      
      }
        
    l_dst = p_source_1.clone();
    
    
    for(l_c = Math.max(1, l_r.nextInt(l_l)); l_c > 0; l_c--)
      {
      l_s = l_r.nextInt(p_source_2.length);
      l_dx = 0.5d;
      do
        {
        l_d   = ((int)(l_r.normal(l_s, l_dx)));
        l_dx += 0.1d;
        } while((l_d < 0) || (l_d >= l_l) ||
                ((l_dst[l_d] != p_source_1[l_d]) && (l_dx < 4.0d)));
      
      l_x = p_source_2[l_s];
      
      for(l_i = (l_x.length-1); l_i >= 0; l_i--)
        {
        l_c1 = l_x[l_i];
        if(l_c1 instanceof Call)
          {
          l_c2 = ((Call)l_c1);
          l_t  = l_c2.get_index();
          
          if((l_t == l_s) && (l_d != l_s))
            {
            l_c2 = Call.create(l_d, l_c2.is_unconditional());
            }
          else
            {
            if(l_t >= l_l)
              {
              l_c2 = Call.create(l_r.nextInt(l_l), l_c2.is_unconditional());
              }
            }
          
          if(l_c2 != l_c1)
            {
            if(l_x == p_source_2[l_s]) l_x = l_x.clone();
            l_x[l_i] = l_c2;
            }
          }
        }
      
      l_dst[l_d] = l_x;
      }
    
    return l_dst;
    }
  
  
/**
 * This class will never be instantiated.
 */

  private ProgramCrossover()
    {
    Typesafe.do_not_call();
    }
  }

File Information:

file name:ProgramCrossover.java
package:org.dgpf.gp.vm.mutation
qualified name:org.dgpf.gp.vm.mutation.ProgramCrossover.java
file type:Java Source File
download location:download http://dgpf.sourceforge.net/source/org/dgpf/gp/vm/mutation/ProgramCrossover.java
size:3.982 KB (4078 B)
uploaded: 2015-07-22 04:10:58 GMT+0000
last update: 2006-08-22 07:01:46 GMT+0000
last access: 2017-11-18 06:38:20 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-18 06:38:20 GMT+0000.
Valid CSS Valid XHTML 1.1
Valid RSS SourceForge.net Logo