Logo
Distributed Genetic Programming Framework
print print

File org.dgpf.search.api.SearchData.java

Here you can find all the information about the file org.dgpf.search.api.SearchData.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-03-30 11:34:03
 * Original Filename: org.dgpf.search.api.SearchData.java
 * Version          : 1.0.1
 * Last modification: 2006-05-28
 *                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.search.api;

import java.io.Serializable;

import org.sfc.meta.BoundedIntProperty;
import org.sfc.meta.BoundedLongProperty;
import org.sfc.meta.MetaInformation;
import org.sfc.meta.Property;

/**
 * This class stores some basic data that may guide a search.
 *
 * @author Thomas Weise
 */

public abstract class SearchData  implements Serializable
  {
/**
 * The serial version uid.
 */

  private static final long serialVersionUID = 1;
  
/**
 * The search data meta information.
 */

  public  static  final MetaInformation       SEARCH_DATA_METAINFO ;    
/**
 * The property for search cache sizes.
 */

  public  static  final BoundedIntProperty    CACHE_SIZE;
  
/**
 * The property for challenge-parent.
 */

  public  static  final Property<Boolean>     CHALLENGE_PARENT;
/**
 * The property for the fitness function count.
 */

  public  static  final BoundedIntProperty    FITNESS_FUNCTION_COUNT;
/**
 * The property for the maximum creation trials.
 */

  public  static  final BoundedIntProperty    MAX_CREATION_TRIALS;
/**
 * The property for the maximum improvement trials.
 */

  public  static  final BoundedIntProperty    MAX_IMPROVEMENT_TRIALS;
/**
 * The property for return-first-improvement.
 */

  public  static  final Property<Boolean>     RETURN_FIRST_IMPROVEMENT;  
/**
 * The property for the simulation count.
 */

  public  static  final BoundedIntProperty    SIMULATION_COUNT;
/**
 * The property for the steps per simulation.
 */

  public  static  final BoundedLongProperty   STEPS_PER_SIMULATION ;  
  
  static
    {
    CACHE_SIZE  = new BoundedIntProperty("cache_size",
                                         SearchUtils.CONTROL_PROPERTIES,
                                         0, SearchUtils.DEFAULT_MAX_INT);
    CACHE_SIZE.add_port(SearchData.class, true, false, null);
    
    CHALLENGE_PARENT = new Property<Boolean>("challenge_parent",
                                             SearchUtils.CONTROL_PROPERTIES,
                                             boolean.class);
    CHALLENGE_PARENT.add_port(SearchData.class, true, false, null);

    FITNESS_FUNCTION_COUNT = new BoundedIntProperty(
                                  "fitness_function_count",
                                  SearchUtils.FITNESS_PROPERTIES,
                                  0, SearchUtils.DEFAULT_MAX_INT);
    FITNESS_FUNCTION_COUNT.add_port(SearchData.class,true, false, null);

    MAX_CREATION_TRIALS = new BoundedIntProperty(
                            "max_creation_trials",                             
                             SearchUtils.CONTROL_PROPERTIES,                            
                             1, SearchUtils.DEFAULT_MAX_INT);
    MAX_CREATION_TRIALS.add_port(SearchData.class, true, false,  null);
    
    MAX_IMPROVEMENT_TRIALS = new BoundedIntProperty(
                                   "max_improvement_trials",
                                   SearchUtils.CONTROL_PROPERTIES,
                                   1, SearchUtils.DEFAULT_MAX_INT);
    MAX_IMPROVEMENT_TRIALS.add_port(SearchData.class,true, false, null);

    RETURN_FIRST_IMPROVEMENT = new Property<Boolean>(
                                  "return_first_improvement",
                                  SearchUtils.CONTROL_PROPERTIES,
                                  boolean.class);
    RETURN_FIRST_IMPROVEMENT.add_port(SearchData.class, true, false, null);  

    SIMULATION_COUNT =  new BoundedIntProperty(
                                    "simulation_count",
                                    SearchUtils.CONTROL_PROPERTIES,
                                    1, SearchUtils.DEFAULT_MAX_INT);
    SIMULATION_COUNT.add_port(SearchData.class, true, false, null);

    STEPS_PER_SIMULATION = new BoundedLongProperty(
                              "steps_per_simulation",
                              SearchUtils.CONTROL_PROPERTIES,
                              0, SearchUtils.DEFAULT_MAX_LONG);
    STEPS_PER_SIMULATION.add_port(SearchData.class, true, false, null);
    
    SEARCH_DATA_METAINFO = new MetaInformation();    
    }
  
/**
 * How many simulations will be needed per individual.
 * @see #get_simulation_count()
 */

  private           int             m_simulation_count      ;   
 
/**
 * How many steps will be performed per simulation.
 * @see #get_steps_per_simulation()
 */

   private          long            m_steps_per_simulation  ;
/**
 * The maximum count of trials to be used to create <i>unique</i>
 * individuals. (That is, individuals that are not already cached.)
 * @see #get_max_creation_trials()
 */

   private          int             m_max_creation_trials   ;
/**
 * The size of the internal cache preventing individuals from being created
 * twice.
 * @see #get_cache_size()
 */

   private          int             m_cache_size            ;   
/**
 * Defines how often a genetic operation can be performed at max to obtain
 * an improvement.
 * @see #get_max_improvement_trials()
 */
  
  private           int             m_max_improvement_trials  ;
/**
 * Defines if the first improvement found in a genetic operation should be
 * returned or if all <code>get_max_improvement_trials()</code> should be
 * evaluated before determining the individual to be returned.
 * @see #get_return_first_improvement()
 * @see #get_max_improvement_trials()
 */

  private           boolean         m_return_first_improvement  ;
  
/**
 * If this parameter is <code>true</code> a child may only survive if it is
 * better as at least one parent.
 * @see #get_challenge_parent() 
 */

  private           boolean         m_challenge_parent  ;
/**
 * The count of fitness functions.
 * @see #get_fitness_function_count()
 */

  private final     int             m_ff_count  ;
  
/**
 * Create a new search data instance.
 * @param p_data  The search data to assign to.
 */

  SearchData(final SearchData p_data)
    {
    super();
    this.assign(p_data);
    this.m_ff_count = ((p_data != null) ? p_data.m_ff_count : 0);
    }
  
 
/**
 * Create a new search data instance.
 * @param p_ff_count  The count of fitness functions evaluated by this
 *                    search.            
 */

   SearchData  (final int  p_ff_count)
     {
     super();
     
     FitnessAccessor.ensure_pool_capacity(p_ff_count);
     
     this.set_cache_size(SearchUtils.DEFAULT_CACHE_SIZE );
     this.set_max_creation_trials( SearchUtils.DEFAULT_MAX_CREATION_TRIALS);
     this.set_max_improvement_trials(SearchUtils.DEFAULT_MAX_IMPROVEMENT_TRIALS);
     this.set_challenge_parent(SearchUtils.DEFAULT_CHALLENGE_PARENT);
     this.set_return_first_improvement(SearchUtils.DEFAULT_RETURN_FIRST_IMPROVEMENT);
     this.set_simulation_count(SearchUtils.DEFAULT_SIMULATION_COUNT);
     this.set_steps_per_simulation(SearchUtils.DEFAULT_STEPS_PER_SIMULATION);
     
     this.m_ff_count = ((p_ff_count > 0) ? p_ff_count : 0);
     }
   
/**
 * Obtain the count of simulations to be performed for every individual
 * (genotype) to determine a stable fitness value.
 * @return  How many simulations will be needed per individual.
 */

  public  final  int get_simulation_count      ()
    {
    return this.m_simulation_count;
    }

/**
 * Set the count of simulations to be performed for every individual
 * (genotype) to determine a stable fitness value.
 * @param p_simulation_count  How many simulations will be needed
 *                            per individual.
 */

  protected  void  set_simulation_count  (final int p_simulation_count)
    {
    if(p_simulation_count > 0)
      {
      this.m_simulation_count = p_simulation_count;
      }
    }
  
/**
 * Obtain the count of steps to perform per simulation.
 * @return  How many steps will be performed per simulation.
 */

  public  final  long get_steps_per_simulation  ()
    {
    return this.m_steps_per_simulation;
    }
  
/**
 * Set the count of steps to perform per simulation.
 * @param p_steps_per_simulation  How many steps will be performed
 *                                per simulation.
 */

  void  set_steps_per_simulation (final long p_steps_per_simulation)
    {
    if(p_steps_per_simulation >= 0)
      {
      this.m_steps_per_simulation = p_steps_per_simulation;
      }
    }
  
  

/**
 * Obtain the maximum count of trials to be used to create <i>unique</i>
 * individuals. (That is, individuals that are not already cached.)
 * @return  The maximum count of trials to be used to create individuals.
 */

  public  final  int get_max_creation_trials      ()
    {
    return this.m_max_creation_trials;
    }

/**
 * Set the maximum count of trials to be used to create <i>unique</i>
 * individuals. (That is, individuals that are not already cached.)
 * @param p_max_creation_trials  The maximum count of trials to be used to
 *                               create <i>unique</i> individuals.
 */

  protected  void  set_max_creation_trials
                                  (final int p_max_creation_trials)
    {
    if(p_max_creation_trials >= 1)
      {
      this.m_max_creation_trials = p_max_creation_trials;
      }
    }
  
/**
 * Obtain the size of the internal cache preventing individuals from being
 * created twice.
 * @return  The size of the internal cache that holds individuals already
 *          created.
 */

  public  final int get_cache_size  ()
    {
    return this.m_cache_size;
    }

/**
 * Set the size of the internal cache preventing individuals from being
 * created twice.
 * @param p_size  The size of the internal cache that holds individuals
 *                already created.
 */

  protected void  set_cache_size  (final int p_size)
    {
    if(p_size >= 0)
      {
      this.m_cache_size = ((p_size < SearchUtils.MAX_CACHE_SIZE)
                            ? p_size : SearchUtils.MAX_CACHE_SIZE);
      }
    }
  

/**
 * Obtain how often a genetic operation can be performed at max to obtain
 * an improvement.
 * @return  The count of trials to be used to achive an improvement at max
 *          via a genetic operation.
 */
  
  public  final int get_max_improvement_trials()
    {
    return this.m_max_improvement_trials;
    }
  
/**
 * Set how often a genetic operation can be performed at max to obtain
 * an improvement.
 * @param p_trials  The count of trials to be used to achive an improvement
 *                  at max via a genetic operation.
 */

  void  set_max_improvement_trials  (final int p_trials)
    {
    if(p_trials >= 1)
      {
      this.m_max_improvement_trials = p_trials;
      }
    }
  
/**
 * If this parameter is <code>true</code> a child may only survive if it is
 * better as at least one parent.
 * @return  <code>true</code> if the child must win the competition against
 *          its parent in order to survive. 
 */

  public  final boolean get_challenge_parent()
    {
    return this.m_challenge_parent;
    }
  
/**
 * Set to <code>true</code> a child may only survive if it is
 * better as at least one parent, set to <code>false</code> otherwise.
 * @param p_challenge <code>true</code> if the child must win the
 *                    competition against its parent in order to survive. 
 */

  void set_challenge_parent  (final boolean p_challenge)
    {
    this.m_challenge_parent = p_challenge;
    }
  
/**
 * Obtain if the first improvement found in a genetic operation should be
 * returned or if all <code>get_max_improvement_trials()</code> should be
 * evaluated before determining the individual to be returned.
 * @return  <code>true</code> if the first individual better as its parents
 *          found in a genetic operation should be returned.
 *          <code>false</code> if we have to evaluate all
 *          <code>get_max_improvement_trials()</code> before returning
 *          anything. 
 */

  public  final boolean get_return_first_improvement  ()
    {
    return this.m_return_first_improvement;
    }

/**
 * Set if the first improvement found in a genetic operation should be
 * returned or if all <code>get_max_improvement_trials()</code> should be
 * evaluated before determining the individual to be returned.
 * @param p_ret  <code>true</code> if the first individual better as its
 *               parents found in a genetic operation should be returned.
 *               <code>false</code> if we have to evaluate all
 *               <code>get_max_improvement_trials()</code> before returning
 *               anything. 
 */

  void  set_return_first_improvement  (final boolean p_ret)
    {
    this.m_return_first_improvement = p_ret;
    }
  
/**
 * Obtain the count of fitness functions evaluated by this search.
 * @return The count of fitness functions evaluated by this search.
 */

  public  final int get_fitness_function_count()
    {
    return this.m_ff_count;
    }
  
  
/**
 * Assign the internal data of this search data to the data of
 * another one.
 * @param p_data  The simulation data  to assign to.
 */

  protected void  assign  (final Object p_data)
    {
    SearchData      l_sd;
    
    if(p_data instanceof SearchData)
      {
      l_sd = ((SearchData)p_data);
      
      this.set_simulation_count        (l_sd.m_simulation_count   );
      this.set_steps_per_simulation    (l_sd.m_steps_per_simulation );
      this.set_max_creation_trials     (l_sd.m_max_creation_trials );
      this.set_cache_size              (l_sd.m_cache_size        );
      this.set_max_improvement_trials  (l_sd.m_max_improvement_trials);
      this.set_challenge_parent        (l_sd.m_challenge_parent       );
      this.set_return_first_improvement(l_sd.m_return_first_improvement);
      }
    }  
  }

File Information:

file name:SearchData.java
package:org.dgpf.search.api
qualified name:org.dgpf.search.api.SearchData.java
file type:Java Source File
download location:download http://dgpf.sourceforge.net/source/org/dgpf/search/api/SearchData.java
size:14.735 KB (15089 B)
uploaded: 2015-07-22 04:11:00 GMT+0000
last update: 2006-05-28 13:53:17 GMT+0000
last access: 2017-11-22 09:28:22 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-22 09:28:22 GMT+0000.
Valid CSS Valid XHTML 1.1
Valid RSS SourceForge.net Logo