Logo
Distributed Genetic Programming Framework
print print

File org.dgpf.gp.vm.fitness.CodeSizePressure.java

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

import org.dgpf.gp.vm.base.Program;
import org.dgpf.search.api.FitnessData;
import org.dgpf.search.api.FitnessFunction;
import org.dgpf.search.api.SearchContext;


/**
 * The code size pressure fitness function is used to prevent the code from
 * becomming too big.
 *
 * @author Thomas Weise
 */

public class CodeSizePressure extends FitnessFunction<Program,
                                                      FitnessData<Program>>
  {
/**
 * The globally shared instance of the code size pressure fitness function.
 */

  public  static  final FitnessFunction<Program, FitnessData<Program>>
    DEFAULT_INSTANCE = new CodeSizePressure(-1, 5.0d);

/**
 * The maximum allowed instruction count.
 */

  private final int m_max_instructions  ;


/**
 * Create a new code size pressure fitness function.
 * @param p_max_instructions  The maximum allowed instruction count.
 * @param p_precision   The precision of this fitness function. This is the
 *                      count of levels to be used for the calculation.
 *                      If this parameter is <= 0.0d, the full precision
 *                      available will be used.
 *
 */

  public  CodeSizePressure(final int p_max_instructions,
                           final double p_precision)
    {
    super(-1, p_precision);

    this.m_max_instructions = ((p_max_instructions > 1) ?
                                p_max_instructions      :
                                Integer.MAX_VALUE);
    }

/**
 * This method is called when a simulation has come to an end.
 * You must use this method to store a fitness value into the fitness
 * record <code>p_fitness</code>. Use <code>set_fitness</code> for this.
 * @param p_fitness       The fitness data record that was used in this
 *                        simulation.
 * @param p_context       The context that has driven the simulation.
 * @see FitnessData#set_fitness(double)
 */

  @Override
  protected  final  void end_simulation(
                            final FitnessData<Program>    p_fitness,
                            final SearchContext<Program>  p_context)
    {    
    int l_i;
    
    l_i = p_context.get_current().get_instr_count();
    p_fitness.set_fitness((l_i > 0) ? (1.0d / Math.sqrt(l_i)) : 0); 
    }

/**
 * Returns a human readable name of this fitness function.
 * @return A human readable name of this fitness function.
 */

  @Override
  public  final  String  toString  ()
    {
    return "code size";
    }


/**
 * Perform a sanity check if there is any use in simulating this individual.
 * @param p_individual  The individual to be sanity-checked.
 * @return  <code>true</code> if and only if the individual shall be
 *          evaluated, <code>false</code> to abort evaluation of the
 *          individual because it is wack for some reason.
 */

  @Override
  protected  final  boolean should_simulate (final Program p_individual)
    {
    int l_i;

    l_i = p_individual.get_instr_count();    
    if( (l_i < 2) || (l_i > this.m_max_instructions) ) return false;
    
    return super.should_simulate(p_individual);
    }
  }

File Information:

file name:CodeSizePressure.java
package:org.dgpf.gp.vm.fitness
qualified name:org.dgpf.gp.vm.fitness.CodeSizePressure.java
file type:Java Source File
download location:download http://dgpf.sourceforge.net/source/org/dgpf/gp/vm/fitness/CodeSizePressure.java
size:4.207 KB (4308 B)
uploaded: 2015-07-22 04:10:56 GMT+0000
last update: 2006-08-24 02:36:31 GMT+0000
last access: 2017-11-17 19:03:39 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-17 19:03:39 GMT+0000.
Valid CSS Valid XHTML 1.1
Valid RSS SourceForge.net Logo