Logo
Distributed Genetic Programming Framework
print print

File org.dgpf.gp.vm.instructions.ctrl.CallHandler.java

Here you can find all the information about the file org.dgpf.gp.vm.instructions.ctrl.CallHandler.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 09:40:46
 * Original Filename: org.dgpf.gp.vm.instructions.ctrl.CallHandler.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.instructions.ctrl;

import org.dgpf.gp.vm.base.IInstructionHandler;
import org.dgpf.gp.vm.base.Instruction;
import org.dgpf.gp.vm.base.VMContext;
import org.dgpf.gp.vm.instructions.base.NoMemInstrHandler;
import org.dgpf.gp.vm.mutation.MutationInfo;
import org.sfc.math.stochastic.Randomizer;


/**
 * The instruction handler for the call instruction.
 *
 * @author Thomas Weise
 */

public final class CallHandler extends NoMemInstrHandler
  {
/**
 * The globally shared instance of the call handler.
 */

  public  static  final IInstructionHandler  INSTANCE =
                                        new CallHandler();

  
/**
 * Create a new call handler - you cannot do this, use the shared
 * instance.
 * @see #INSTANCE
 */

  private CallHandler()
    {
    super();
    }
  
/**
 * Create a new randomized instance of this instruction.
 * @param p_context The vm context to be used.
 * @param p_info    The information record holding the infos on the
 *                  instruction to be created.
 * @return  The new instruction instance.
 */

  public  final     Instruction create      (final VMContext    p_context,
                                             final MutationInfo p_info)
    {
    Randomizer l_r;
    
    l_r = p_context.get_randomizer();
    
    return Call.create(l_r.nextInt(p_info.get_proc_count()),
                       l_r.nextBoolean());
    }
  

/**
 * Perform the mutation.
 * @param p_source  The source object to create a randomizedly altered
 *                  copy of.
 * @param p_context The context hosting the operation.
 * @param p_info    The information record.
 * @return  The new, randomizedly altered copy of the object
 *          <code>p_source</code> or <code>p_source</code> itself if no
 *          mutation was possible.
 */

  public  final Instruction mutate  (final Instruction    p_source,
                                     final VMContext      p_context,
                                     final MutationInfo   p_info)
    {
    Randomizer  l_r;
    int         l_d, l_i, l_j;
    Call        l_c;
    boolean     l_b;
       
    l_c = ((Call)p_source);    
    l_r = p_context.get_randomizer();
    l_j = l_c.get_index();
    l_b = l_c.is_unconditional();
    
    if(((l_d = p_info.get_proc_count()) <= 1) ||
        (l_r.nextInt(5) > 0))
      {
      return Call.create(l_j, (!l_b));
      }
  
    do
      {
      l_i = l_r.nextInt(l_d);
      } while( (l_i == l_j) || (l_i >= l_d) || (l_i < 0) );
      
    return Call.create(l_i, l_b);
    }
  }

File Information:

file name:CallHandler.java
package:org.dgpf.gp.vm.instructions.ctrl
qualified name:org.dgpf.gp.vm.instructions.ctrl.CallHandler.java
file type:Java Source File
download location:download http://dgpf.sourceforge.net/source/org/dgpf/gp/vm/instructions/ctrl/CallHandler.java
size:3.679 KB (3768 B)
uploaded: 2015-07-22 04:10:58 GMT+0000
last update: 2006-08-22 07:00:53 GMT+0000
last access: 2017-11-24 00:23:04 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-24 00:23:04 GMT+0000.
Valid CSS Valid XHTML 1.1
Valid RSS SourceForge.net Logo