Logo
Distributed Genetic Programming Framework
print print

File org.dgpf.gp.automaton.search.ProgramDefinition.java

Here you can find all the information about the file org.dgpf.gp.automaton.search.ProgramDefinition.java. You may explore it here or download it onto your local disk.
/*
 * Copyright (c) 2005 Thomas Weise
 *
 * E-Mail           : tweise@gmx.de
 * Creation Date    : 2005-12-29 07:22:59
 * Original Filename: org.dgpf.automaton.genetics.AutomatonDefinition.java
 * Version          : 2.2.2
 * Last modification: 2006-06-08
 *                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.automaton.search;

import org.dgpf.gp.automaton.base.Program;
import org.dgpf.search.api.FitnessFunction;
import org.dgpf.search.api.SearchContext;
import org.dgpf.search.api.SearchDefinition;
import org.dgpf.search.api.utils.WeightedSet;
import org.dgpf.search.api.utils.WeightedSetBuilder;
import org.sfc.events.IEventListener;

/**
 * The genetic definition object holds all information needed for genetic
 * evolving of automatons.
 *
 * @author Thomas Weise
 */

public class ProgramDefinition extends SearchDefinition<Program>
  {
/**
 * The serial version uid.
 */

  private static  final long                serialVersionUID  = 1;


/**
 * The random set containing the instruction handlers.
 */

  final WeightedSet<InstructionHandler>          m_instructions;

/**
 * The random set containing the expression handlers.
 */

  final WeightedSet<ExpressionHandler>          m_expressions;
  

/**
 * The random set containing the wrapable expression handlers.
 */

  final WeightedSet<WrapableExpressionHandler>  m_wrapables;
/**
 * The random set containing the sequence factories.
 */

  final WeightedSet<SequenceFactory>            m_sequences;

/**
 * The minimum memory size of a program.
 */

  final int                                     m_min_mem_size ;

  
/**
 * Create a new program definition.
 * @param p_definition  The search definition to use as blueprint for the
 *                      internally stored data.
 */

  public  ProgramDefinition(final ProgramDefinition p_definition)
    {
    super(p_definition);
    this.m_min_mem_size   = p_definition.m_min_mem_size;
    this.m_expressions    = p_definition.m_expressions;
    this.m_instructions   = p_definition.m_instructions;
    this.m_sequences      = p_definition.m_sequences;
    this.m_wrapables      = p_definition.m_wrapables;
    }
  
/**
 * Create a new program definition.
 * @param p_functions   The fitness functions to be applied in this
 *                      evolution.
 * @param p_min_mem_size  The minimum memory size of a program. This value
 *                        will at least be 1.
 */

  public ProgramDefinition(final int                          p_min_mem_size,
                           final FitnessFunction<Program,?>[] p_functions)
    {
    this(p_min_mem_size, p_functions, null, null, null);
    }
  
/**
 * Create a new program definition.
 * @param p_functions   The fitness functions to be applied in this
 *                      evolution.
 *
 * @param p_instructions  The instruction handlers provided.
 *                        Set to <code>null</code> to use default values.
 * 
 * @param p_expressions   The expression handlers provided.
 *                        Set to <code>null</code> to use default values.
 * @param p_sequences     The fixed sequence factories.
 *                        Set to <code>null</code> to use default values.
 * @param p_min_mem_size  The minimum memory size of a program. This value
 *                        will at least be 1.
 */

  public ProgramDefinition(
              final int                             p_min_mem_size,
              final FitnessFunction<Program,?>[]    p_functions,
              final WeightedSet<InstructionHandler> p_instructions,
                    WeightedSet<ExpressionHandler>  p_expressions,
              final WeightedSet<SequenceFactory>    p_sequences)
    {
    super(p_functions);
    
    WeightedSetBuilder<WrapableExpressionHandler> l_we;
    int                                           l_i;
    ExpressionHandler                             l_eh;
    
    this.m_min_mem_size = ((p_min_mem_size > 1) ? p_min_mem_size : 1);

    if((p_expressions == null) || (p_expressions.size() <= 0))
      {
      p_expressions     = AutomatonUtils.BASIC_EXPRESSION_SET;
      }
    this.m_expressions  = p_expressions;
    this.m_instructions = (((p_instructions != null) &&
                           (p_instructions.size() > 0)) ? p_instructions :
                            AutomatonUtils.BASIC_INSTRUCTION_SET);
    this.m_sequences    = (((p_sequences != null) &&
                            (p_sequences.size() >0)) ? p_sequences :
                            AutomatonUtils.BASIC_SEQUENCE_FACTORIES);
    
    l_we = new WeightedSetBuilder<WrapableExpressionHandler>(
                            WrapableExpressionHandler.class);
        
    for(l_i = (p_expressions.size()-1); l_i >= 0; l_i--)
      {
      l_eh = p_expressions.get(l_i);
      if(l_eh instanceof WrapableExpressionHandler)
        {
        l_we.add(((WrapableExpressionHandler)l_eh),
                   p_expressions.get_probability(l_i));
        }
      }
    
    
    this.m_wrapables = ((l_we.get_count() > 0) ?
                         new WeightedSet<WrapableExpressionHandler>(l_we) :
                         AutomatonUtils.EMPTY_WRAPABLES);
    }


/**
 * Using this method, a search definition works as factory for search
 * contexts. This implementation returns an <code>AutomatonContext</code>-
 * instance.
 * 
 * @param p_events  The event listener to be used to propagate
 *                      error events to, if needed.
 * 
 * @return A new search context.
 */

  @Override
  public SearchContext<Program> create_context
                                          (final IEventListener p_events)
    {
    return new AutomatonContext(this, p_events);
    }
  }

File Information:

file name:ProgramDefinition.java
package:org.dgpf.gp.automaton.search
qualified name:org.dgpf.gp.automaton.search.ProgramDefinition.java
file type:Java Source File
download location:download http://dgpf.sourceforge.net/source/org/dgpf/gp/automaton/search/ProgramDefinition.java
size:6.480 KB (6636 B)
uploaded: 2015-07-22 04:10:55 GMT+0000
last update: 2006-06-08 12:47:40 GMT+0000
last access: 2017-11-19 03:12:52 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:12:52 GMT+0000.
Valid CSS Valid XHTML 1.1
Valid RSS SourceForge.net Logo