Logo
Distributed Genetic Programming Framework
print print

File org.dgpf.gp.vm.instructions.base.MemInstr3Handler.java

Here you can find all the information about the file org.dgpf.gp.vm.instructions.base.MemInstr3Handler.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 04:10:21
 * Original Filename: org.dgpf.gp.vm.instructions.base.MemInstr3Handler.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.base;

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.arith.Compare;
import org.dgpf.gp.vm.instructions.arith.SetZeroFlag;
import org.dgpf.gp.vm.mutation.MutationInfo;
import org.dgpf.search.api.utils.IMutator;
import org.dgpf.search.api.utils.WeightedSet;
import org.dgpf.search.api.utils.WeightedSetBuilder;


/**
 * The base class for memory 1 instruction handlers.
 *
 * @author Thomas Weise
 */

public abstract class       MemInstr3Handler 
                extends     MemInstr2Handler
  {
///**
// * The first internal mutator.
// */

//  private static  final IMutator<Instruction, VMContext, MutationInfo> M31 =
//    new IMutator<Instruction, VMContext, MutationInfo>()
//      {
//      public  final  Instruction  mutate  (final Instruction  p_source,
//                                           final VMContext    p_context,
//                                           final MutationInfo p_info)
//        {
//        MemInstr3 l_i;
//        
//        if(p_context.can_relative())
//          {
//          l_i = ((MemInstr3)(p_source.clone()));
//          l_i.m_relative_3 = !(l_i.m_relative_3);
//          return l_i;
//          }
//        return p_source;
//        }
//      };
//      
//
///**
// * The second internal mutator.
// */

//  private static  final IMutator<Instruction, VMContext, MutationInfo> M32 =
//    new IMutator<Instruction, VMContext, MutationInfo>()
//      {
//      public  final  Instruction  mutate  (final Instruction  p_source,
//                                           final VMContext    p_context,
//                                           final MutationInfo p_info)
//        {
//        MemInstr3 l_i;
//        
//        l_i = ((MemInstr3)(p_source.clone()));
//        l_i.m_addr_3 = p_context.mutate_address(l_i.m_addr_3, p_info);
//        return l_i;
//        }
//      };
//  


/**
 * The third internal mutator.
 */

  private static  final IMutator<Instruction, VMContext, MutationInfo> M33 =
    new IMutator<Instruction, VMContext, MutationInfo>()
      {
      public  final  Instruction  mutate  (final Instruction  p_source,
                                           final VMContext    p_context,
                                           final MutationInfo p_info)
        {
        MemInstr3                                 l_i, l_i2;
        IInstructionHandler                       l_ii, l_io;
        WeightedSet<IInstructionHandler>.Session  l_s;
      
        l_i  = ((MemInstr3)(p_source));
        l_io = l_i.get_handler();
        l_s  = p_context.get_instruction_set().open_session(
                                               p_context.get_randomizer());
        
        while(l_s.hasNext())
          {
          l_ii = l_s.next();
          if((l_ii != l_io) && (l_ii instanceof MemInstr3Handler))
            {
            l_i2 = ((MemInstr3)(l_ii.create(p_context, p_info)));
            l_i2.m_addr_1     = l_i.m_addr_1;
            l_i2.m_relative_1 = l_i.m_relative_1;
            l_i2.m_addr_2     = l_i.m_addr_2;
            l_i2.m_relative_2 = l_i.m_relative_2;
            l_i2.m_addr_3     = l_i.m_addr_3;
            l_i2.m_relative_3 = l_i.m_relative_3;
            l_s.close();
            return l_i2;
            }
          }
        
        l_s.close();
        return l_i;
        }
      };
      

      
/**
 * The default weighted set builder.
 */

  static  final WeightedSetBuilder<IMutator
                             <Instruction, VMContext, MutationInfo>>
    MI3B = new WeightedSetBuilder<IMutator
                   <Instruction, VMContext, MutationInfo>>(IMutator.class);
  
  static
    {
    MI3B.add(MI2B);
//    MI3B.add(M31, M1_WEIGHT);    
//    MI3B.add(M32, M2_WEIGHT);    
    MI3B.add(M33, M3_WEIGHT);
    }
  
      
/**
 * Create a new mem instr 1 handler. Such handlers use internal mutator
 * lists.
 * @param p_wsb The weighted set builder to use. Leave this
 *              <code>null</code> if no additional mutators are needed.
 */

  protected MemInstr3Handler(final WeightedSetBuilder<IMutator
                             <Instruction, VMContext, MutationInfo>> p_wsb)
    {
    super(build_set(p_wsb));
    }
  
/**
 * The internal set conversion routine.
 * @param p_set The normal mutator set.
 * @return  The modified mutator set.
 */

  private static final WeightedSetBuilder<IMutator
                       <Instruction, VMContext, MutationInfo>> build_set
                       (final WeightedSetBuilder<IMutator
                        <Instruction, VMContext, MutationInfo>> p_set)
    {
    if(p_set == null) return MI3B;
    
//    if(!(p_set.contains(M31))) p_set.add(M31, M1_WEIGHT);    
//    if(!(p_set.contains(M32))) p_set.add(M32, M2_WEIGHT);    
    if(!(p_set.contains(M33))) p_set.add(M33, M3_WEIGHT);
    
    return p_set;
    }
              

/**
 * Replace a memory access address by another one.
 * @param p_instruction The instruction to replace the address.
 * @param p_old         The old address.
 * @param p_new         The new address.
 * @return  The new instruction where the address relacement has been
 *          performed, or the old one if no replacement was needed.  
 */

  @Override
  public Instruction swap_address(final Instruction p_instruction,
                                  final int         p_old,
                                  final int         p_new)
    {
    MemInstr3 l_m2;
    
    l_m2 = ((MemInstr3)(super.swap_address(p_instruction, p_old, p_new)));
    if(l_m2.m_addr_3 == p_old)
      {
      if(p_instruction == l_m2) l_m2 = ((MemInstr3)(l_m2.clone()));
      l_m2.m_addr_3 = p_new;
      return l_m2;
      }
    
    return p_instruction;
    }
  
/**
 * Try to melt two instructions together. The second instruction is of
 * the type this instruction handler handles.
 * @param p_first   The first instruction.
 * @param p_second  The second instruction.
 * @return  An instruction able to replace the sequence of these both
 *          instructions, or <code>null</code> if no valid replacement
 *          coult be found.
 */
  
  @Override
  public  Instruction try_melt  (final Instruction p_first,
                                 final Instruction p_second)
    {  
    if((p_first instanceof SetZeroFlag) || (p_first instanceof Compare))
      {
      return p_second;
      }
    
    return super.try_melt(p_first, p_second);
    }
  }

File Information:

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