Logo
Distributed Genetic Programming Framework
print print

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

Here you can find all the information about the file org.dgpf.gp.vm.instructions.ctrl.PushCHandler.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.arith.PushCHandler.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.NoMemInstr2Handler;
import org.dgpf.gp.vm.mutation.MutationInfo;
import org.dgpf.search.api.utils.IMutator;
import org.dgpf.search.api.utils.WeightedSetBuilder;
import org.sfc.math.stochastic.Randomizer;


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

public final class PushCHandler extends  NoMemInstr2Handler
  {
/**
 * The serial version uid.
 */

  private static final long serialVersionUID = 1;

  

/**
 * The first internal mutator.
 */

  private static  final IMutator<Instruction, VMContext, MutationInfo> M1 =
    new IMutator<Instruction, VMContext, MutationInfo>()
      {
      public  final  Instruction  mutate  (final Instruction  p_source,
                                           final VMContext    p_context,
                                           final MutationInfo p_info)
        {
        int         l_j, l_i;
        double      l_d;
        Randomizer  l_r;
        
        l_j = ((PushC)p_source).get_const();
        l_r = p_context.get_randomizer();
        l_d = Math.max(1.0d, Math.log(l_j));
        
        do
          {
          l_i = ((int)(l_r.normal(l_j, l_d)));
          } while(l_i == l_j);
        
        return PushC.create(l_i);
        }
      };
      
/**
 * The second internal mutator.
 */

  private static  final IMutator<Instruction, VMContext, MutationInfo> M2 =
    new IMutator<Instruction, VMContext, MutationInfo>()
      {
      public  final  Instruction  mutate  (final Instruction  p_source,
                                           final VMContext    p_context,
                                           final MutationInfo p_info)
        {        
        return PushCHandler.INSTANCE.create(p_context, p_info);
        }
      };
      
/**
 * The globally shared instance of the pushc handler.
 */

  public  static  final IInstructionHandler  INSTANCE =
                                        new PushCHandler();
  
/**
 * Create a new pushc handler - you cannot do this, use the shared
 * instance.
 * @see #INSTANCE
 */

  private PushCHandler()
    {
    super(build());
    }
  

/**
 * Build the weighted set internally.
 * @return The weighted set to be used internally.
 */
  
  private static  final WeightedSetBuilder<IMutator
                       <Instruction, VMContext, MutationInfo>> build()
   {
   WeightedSetBuilder<IMutator<Instruction, VMContext, MutationInfo>> l_m;
      
   l_m = new WeightedSetBuilder<IMutator
         <Instruction, VMContext, MutationInfo>>(IMutator.class);
   
   l_m.add(M1, 1.0d);
   l_m.add(M2, 0.1d);
   
   return l_m;
   }
  
/**
 * 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;
    int        l_i;
    
    l_r = p_context.get_randomizer();
    l_i = 0;
    
    while(l_r.nextBoolean())
      {
      l_i = ((3*l_i) + l_r.nextInt(3));
      }
    
    return PushC.create(l_r.nextBoolean() ? l_i : (-l_i));
    }
  }

File Information:

file name:PushCHandler.java
package:org.dgpf.gp.vm.instructions.ctrl
qualified name:org.dgpf.gp.vm.instructions.ctrl.PushCHandler.java
file type:Java Source File
download location:download http://dgpf.sourceforge.net/source/org/dgpf/gp/vm/instructions/ctrl/PushCHandler.java
size:4.633 KB (4745 B)
uploaded: 2015-07-22 04:10:58 GMT+0000
last update: 2006-07-04 02:06:45 GMT+0000
last access: 2017-11-19 03:08:59 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-19 03:08:59 GMT+0000.
Valid CSS Valid XHTML 1.1
Valid RSS SourceForge.net Logo