Logo
Distributed Genetic Programming Framework
print print

File org.dgpf.gp.regression.expressions.parameterless.ConstantHandler.java

Here you can find all the information about the file org.dgpf.gp.regression.expressions.parameterless.ConstantHandler.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-25 11:41:55
 * Original Filename: org.dgpf.gp.regression.expressions.parameterless.ConstantHandler.java
 * Version          : 1.0.0
 * Last modification: 2006-07-25
 *                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.regression.expressions.parameterless;

import org.dgpf.gp.regression.base.AggregationContext;
import org.dgpf.gp.regression.base.AggregationUtils;
import org.dgpf.gp.regression.base.Expression;
import org.dgpf.gp.regression.base.IExpressionHandler;
import org.dgpf.gp.regression.expressions.DefaultExpressionHandler;
import org.dgpf.gp.regression.search.MutationInfo;
import org.dgpf.search.api.utils.IMutator;
import org.dgpf.search.api.utils.WeightedSetBuilder;

/**
 * This is the handler for constant expressions.
 *
 * @author Thomas Weise
 */

public  final class ConstantHandler extends DefaultExpressionHandler
//implements IExpressionHandler
  {
/**
 * The serial version uid.
 */

  private static  final long  serialVersionUID  = 1;
  
/**
 * The internal mutator which mutates the constant value.
 */

  private static  final IMutator<Expression, AggregationContext,
                                 MutationInfo> MUT_V =
    new IMutator<Expression, AggregationContext, MutationInfo>()
      {
      public  final  Expression  mutate  (final Expression        p_source,
                                          final AggregationContext p_context,
                                          final MutationInfo      p_info)
        {
        return Constant.create(AggregationUtils.mutate_constant(
                       ((Constant)p_source).get_value(),
                       p_context.get_randomizer()));
        }
      };
  
/**
 * The internal mutator which replaces the constant value by a variable.
 */

  private static  final IMutator<Expression, AggregationContext,
                                 MutationInfo> MUT_V2 =
    new IMutator<Expression, AggregationContext, MutationInfo>()
      {
      public  final  Expression  mutate  (final Expression        p_source,
                                          final AggregationContext p_context,
                                          final MutationInfo      p_info)
        {
        return VariableHandler.INSTANCE.create(p_context, p_info);
        }
      };

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

  private static  final WeightedSetBuilder<IMutator
                           <Expression, AggregationContext, MutationInfo>>
    MI1B = new WeightedSetBuilder<IMutator
             <Expression, AggregationContext, MutationInfo>>(IMutator.class);
/**
 * The first mutator weight.
 */

  private static  final double  MUT_V_WEIGHT  = (4.0d * MUT_WRAP_WEIGHT);
/**
 * The second mutator weight.
 */

  private static  final double  MUT_V2_WEIGHT  = (MUT_V_WEIGHT * 0.5d);
  
  static
    {
    MI1B.add(MUT_V,    MUT_V_WEIGHT);  
    MI1B.add(MUT_V2,   MUT_V2_WEIGHT); 
    }
      
/**
 * The shared singleton instance of the constant expression handler.
 */

  public static final IExpressionHandler INSTANCE =
                          new ConstantHandler();
  
/**
 * The hidden constructor. Use the singleton instance instead of trying to
 * create your own instances.
 * @see #INSTANCE
 */

  private ConstantHandler()
    {
    super(MI1B);
    }
  
  
/**
 * Create a new randomized instance of the expression handled by this
 * handler.
 * @param p_context The regression context to be used.
 * @param p_info    The information record holding the infos on the
 *                  expression to be created.
 * @return  The new expression instance.
 */

  public  final Expression  create (final AggregationContext  p_context,
                                    final MutationInfo       p_info)
    {    
    return Constant.create(AggregationUtils.create_constant(
                                  p_context.get_randomizer()));
    }


/**
 * Check whether the expressions created by this handler are terminal
 * expressions or not.
 * @return  <code>true</code> if and only if the expressions created by
 *          this handler are terminal.
 */

  @Override
  public  final  boolean     is_terminal ()
    {
    return true;
    }
  
  }

File Information:

file name:ConstantHandler.java
package:org.dgpf.gp.regression.expressions.parameterless
qualified name:org.dgpf.gp.regression.expressions.parameterless.ConstantHandler.java
file type:Java Source File
download location:download http://dgpf.sourceforge.net/source/org/dgpf/gp/regression/expressions/parameterless/ConstantHandler.java
size:5.098 KB (5221 B)
uploaded: 2015-07-22 04:10:56 GMT+0000
last update: 2006-08-16 02:50:24 GMT+0000
last access: 2017-11-19 04:59:41 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:59:41 GMT+0000.
Valid CSS Valid XHTML 1.1
Valid RSS SourceForge.net Logo