Logo
Distributed Genetic Programming Framework
print print

File org.dgpf.search.api.SearchData2.java

Here you can find all the information about the file org.dgpf.search.api.SearchData2.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 13:30:19
 * Original Filename: org.dgpf.search.api.SearchData2.java
 * Version          : 2.0.2
 * Last modification: 2006-05-29
 *                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.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

import org.dgpf.search.api.comparators.StaggeredComparator;
import org.sfc.meta.MetaInformation;
import org.sfc.meta.Property;
import org.sfc.utils.ICloneable;
import org.sfc.utils.Typesafe;


/**
 * This is an intermediate class, used as root for
 * <code>SearchDefinition</code> and <code>SearchParameters</code>.
 * 
 * @param <Genotype>    The sort of genotype used to represent individuals.
 *                      This must be a serializable type.
 *
 * @author Thomas Weise
 */

public  class SearchData2<Genotype extends Serializable>
                                   extends SearchData
  {
/**
 * The serial version uid.
 */

  private static final long                       serialVersionUID = 1;

/**
 * The meta information for search data 2 records.
 */

  public  static  final MetaInformation SEARCH_DATA2_METAINFO ;
  
  
  
/**
 * The property for the individual comparator.
 */

  public  static  final Property<IndividualComparator> COMPARATOR ;
  
  
  static
    {
    CACHE_SIZE.add_port               (SearchData2.class, true, true, null);
    CHALLENGE_PARENT.add_port         (SearchData2.class, true, true, null);
    MAX_CREATION_TRIALS.add_port      (SearchData2.class, true, true, null);
    MAX_IMPROVEMENT_TRIALS.add_port   (SearchData2.class, true, true, null);
    RETURN_FIRST_IMPROVEMENT.add_port (SearchData2.class, true, true, null);
    SIMULATION_COUNT.add_port         (SearchData2.class, true, true, null);
    STEPS_PER_SIMULATION.add_port     (SearchData2.class, true, true, null);
    
    COMPARATOR = new Property<IndividualComparator>(
                             "comparator",
                             SearchUtils.CONTROL_PROPERTIES,
                             IndividualComparator.class);
    COMPARATOR.add_port(SearchData2.class, true, true, null);
    
    SEARCH_DATA2_METAINFO = new MetaInformation();
    }
  
/**
 * The individual comparator to be used.
 */

  private              IndividualComparator       m_comparator    ;
   
/**
 * Create a new search data 2 instance.
 * @param p_data  The search data to assign to.
 */

  SearchData2(final SearchData p_data)
    {
    super(p_data);
    
    if(this.m_comparator == null)
      {
      this.set_comparator(SearchUtils.DEFAULT_COMPARATOR);
      }
    }
 
/**
 * Create a new search data 2 instance.
 * @param p_ff_count  The count of fitness functions evaluated by this
 *                    search. 
 */

  SearchData2   (final int                  p_ff_count)
    {
    super(p_ff_count);    
    set_comparator(SearchUtils.DEFAULT_COMPARATOR);
    }
  
/**
 * Obtain the comparator used to compare the individual's fitnesses.
 * @return The comparator used to compare the individual's fitnesses.
 */

  public  IndividualComparator  get_comparator  ()
    {
    return this.m_comparator;
    }
   

/**
 * Set the comparator used to compare the individual's fitnesses.
 * @param p_comparator The comparator used to compare the individual's
 *                     fitnesses.
 */

  public final void  set_comparator
                        (final IndividualComparator p_comparator)
    {
    if(p_comparator != null)
      {
      this.m_comparator = p_comparator;
      }
    else
      {
      if(this.m_comparator == null)
        {
        this.m_comparator = StaggeredComparator.INSTANCE;
        }
      }
    }
  

/**
 * 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.
 */

  @Override
  public     void  set_simulation_count  (final int p_simulation_count)
    {
    super.set_simulation_count(p_simulation_count);
    }
  
  
/**
 * Set the count of steps to perform per simulation.
 * @param p_steps_per_simulation  How many steps will be performed
 *                                per simulation.
 */

  @Override
  public     void  set_steps_per_simulation
                                      (final long p_steps_per_simulation)
    {
    super.set_steps_per_simulation(p_steps_per_simulation);
    }
  
  
/**
 * 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.
 */

  @Override
  public     void  set_max_creation_trials
                                  (final int p_max_creation_trials)
    {
    super.set_max_creation_trials(p_max_creation_trials);
    }
  

/**
 * 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.
 */

  @Override
  public     void  set_cache_size  (final int p_size)
    {
    super.set_cache_size(p_size);
    }
  

  
/**
 * 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.
 */

  @Override
  public     void  set_max_improvement_trials  (final int p_trials)
    {
    super.set_max_improvement_trials(p_trials);
    }
  
  
/**
 * 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. 
 */

  @Override
  public     void set_challenge_parent  (final boolean p_challenge)
    {
    super.set_challenge_parent(p_challenge);
    }
  

/**
 * 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. 
 */

  @Override
  public     void  set_return_first_improvement  (final boolean p_ret)
    {
    super.set_return_first_improvement(p_ret);
    }
  
  
/**
 * Assign the internal data of this search data to the data of
 * another one.
 * @param p_data  The simulation data  to assign to.
 */

  @Override
  public void  assign  (final Object p_data)
    {
    SearchData2<Genotype>  l_sd;
      
    if(p_data instanceof SearchData2)
      {
      l_sd = Typesafe.cast(p_data);
      this.set_comparator(l_sd.m_comparator);
      }
    
    super.assign(p_data);
    }
  
/**
 * Creates and returns a copy of this object.  The precise meaning 
 * of "copy" may depend on the class of the object. 
 *
 * @return     A clone of this instance.
 * 
 * @see java.lang.Cloneable
 */

  @Override
  protected Object  clone ()
    {
    SearchData2<Genotype> l_sd2;
    
    try
      {
      l_sd2 = Typesafe.cast(super.clone());
      
      l_sd2.m_comparator = Typesafe.cast(((ICloneable)(l_sd2.m_comparator)).clone());
      
      return l_sd2;
      }
    catch(Throwable l_t)
      {
      return this;
      }
    }
  

/**
 * Stores the <code>SearchData2</code> into the stream.
 * @param p_s The output stream.
 * @throws  IOException If something io-like went wrong.
 */

  private final void writeObject(final ObjectOutputStream p_s)
        throws IOException
    {
    p_s.defaultWriteObject();
    p_s.writeUnshared(this.m_comparator);
    }
  


/**
 * Reconstitute the <code>SearchData2</code> instance from a stream (that is,
 * deserialize it).
 * @param p_s The input stream.
 * @throws  IOException If something io-like went wrong.
 * @throws  ClassNotFoundException  If a needed class could not be found.
 */

  private final void readObject(final ObjectInputStream p_s)
        throws IOException, ClassNotFoundException
    {    
    IndividualComparator  l_c;
    
    p_s.defaultReadObject();
    l_c = ((IndividualComparator)( p_s.readUnshared() ));
    this.set_comparator ( l_c );
    }
  }

File Information:

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