Logo
Distributed Genetic Programming Framework
print print

File org.dgpf.search.algorithms.hc.HCState.java

Here you can find all the information about the file org.dgpf.search.algorithms.hc.HCState.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-05-10 08:17:46
 * Original Filename: org.dgpf.search.algorithms.hc.HCState.java
 * Version          : 1.0.2
 * Last modification: 2006-07-21
 *                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.algorithms.hc;

import java.io.Serializable;

import org.dgpf.search.algorithms.ga.GeneticState;
import org.dgpf.search.api.SearchState;
import org.dgpf.search.api.SearchUtils;
import org.sfc.math.stochastic.statistics.StatisticInfo;
import org.sfc.math.stochastic.statistics.StatisticInfoBag;
import org.sfc.meta.BoundedIntProperty;
import org.sfc.meta.MetaInformation;
import org.sfc.meta.Property;
import org.sfc.utils.Typesafe;

/**
 * The state of the hill climbing engine.
 * @param <Genotype> The genotype of the elements to be evolved.
 *
 * @author Thomas Weise
 */

public class HCState<Genotype extends Serializable>
                              extends SearchState<Genotype>
  {
/**
 * The serial version uid.
 */

  private static final long serialVersionUID = 1;
  
/**
 * The meta information of the hill climbing state.
 */

  public  static  final MetaInformation HC_STATE_METAINFO ;
  
  
/**
 * The immutable state property for the population size.
 */

  public  static  final BoundedIntProperty POPULATION_SIZE ;
  

/**
 * The property telling if the best individual of the
 * current iteration or the best individual of the current run should
 * be used.
 */

  public  static  final Property<Boolean> USE_REL_BEST ;

  
/**
 * The property telling the whole population was newly
 * created in a randomized manner.
 */

  public  static  final Property<Boolean> IS_POPULATION_NEW ;
  
  static
    {
    POPULATION_SIZE = new BoundedIntProperty(
             GeneticState.POPULATION_SIZE.get_name(),
             HCUtils.HC_PROPERTIES,
             0, SearchUtils.DEFAULT_MAX_INT);
    POPULATION_SIZE.add_port(HCState.class, true, false, null);
    
    USE_REL_BEST = new Property<Boolean>("use_rel_best",
                             HCUtils.HC_PROPERTIES,
                             boolean.class);
    USE_REL_BEST.add_port(HCState.class, true, false, null);
    
    IS_POPULATION_NEW = new Property<Boolean>("is_population_new",
                             HCUtils.HC_PROPERTIES,
                             boolean.class);
    IS_POPULATION_NEW.add_port(HCState.class, true, false, null);
    
    SearchUtils.ALL_STAT.add_port(HCState.class"get_stat", null,
                                  SearchUtils.FITNESS_FUNCTION_COUNT_FUNC);
    
    HC_STATE_METAINFO = new MetaInformation();
    }
  
/**
 * This parameter is <code>true</code> if we use always the best individual
 * known of this search run, <code>false</code> if we use the best
 * individual of the last update instead.
 */

  private       boolean                 m_use_rel_best  ;
/**
 * The size of the population in hill climbing. This will normally be the
 * number of processors available - or the count of servers in
 * client/server distribution schemes.  
 */

  private       int                     m_population_size ;
/**
 * <code>true</code> if the elements of this update are newly created
 * random individuals, <code>false</code> if they're result of mutation. 
 */

  private       boolean                 m_new ;
/**
 * The statistic info for the current update.
 * @see #get_stat(int)
 */

  private       StatisticInfo[]         m_stat       ;

  
/**
 * Create a new hill climbing state.
 * @param p_ff_count  The count of fitness functions evaluated by this
 *                    search.
 * @param p_bag       The state bag containing this state.
 */

  protected HCState  (final int                  p_ff_count,
                      final HCStateBag<Genotype> p_bag)
    {
    super(p_ff_count);
    
    this.m_use_rel_best    = HCUtils.DEFAULT_USE_REL_BEST;
    this.m_population_size = Math.max(1,
                              Runtime.getRuntime().availableProcessors());
    
    StatisticInfoBag[]  l_asb;
    StatisticInfo[]     l_as;
    int                 l_i;

    l_asb = p_bag.m_stat;
    l_i   = l_asb.length;

    this.m_stat = l_as = new StatisticInfo[l_i];

    for(--l_i; l_i >= 0; l_i--)
      {
      l_as[l_i] = l_asb[l_i].unpack();
      }    
    }
  
/**
 * Obtain whether we use always the best individual known of this search
 * run or if we use the best individual of the last update instead.
 * @return This parameter is <code>true</code> if we use always the best
 *         individual known of this search run, <code>false</code> if we
 *         use the best individual of the last update instead.
 */

  public  final boolean get_use_rel_best()
    {
    return this.m_use_rel_best;
    }
  
/**
 * Set whether we use always the best individual known of this search
 * run or if we use the best individual of the last update instead.
 * @param p_use_rel_best  This parameter is <code>true</code> if we use
 *                        always the best individual known of this search
 *                        run, <code>false</code> if we use the best
 *                        individual of the last update instead.
 */

  private final void  set_use_rel_best(final boolean p_use_rel_best)
    {
    this.m_use_rel_best = p_use_rel_best;
    }
  
/**
 * Obtain the statistics for the specified fitness function for the
 * the whole population of this update. The whole popultion contains
 * the individuals which are created by either new or mutation 
 * tasks. For each fitness function, one statistical record is available.
 * @param p_ff_index  The index of the fitness function to obtain the
 *                    statistics of.
 * @return  The statistics record for the whole population.
 */

  public  final StatisticInfo get_stat (final int p_ff_index)
    {
    return this.m_stat[p_ff_index];
    }
  
/**
 * Obtain the size of the population in hill climbing. This will normally
 * be the number of processors available - or the count of servers in
 * client/server distribution schemes.
 * @return  The current size of the population.  
 */

  public  final int     get_population_size()
    {
    return this.m_population_size;
    }
  
/**
 * Internally set the population size.
 * @param p_population_size The next population size.
 * @return  The new population size.
 */

  final int set_population_size(final int p_population_size)
    {
    if(p_population_size > 0)
      {
      this.m_population_size = p_population_size;
      return p_population_size;
      }
    return this.m_population_size;
    }
  
/**
 * Returns <code>true</code> if the elements of this update are newly
 * created random individuals, <code>false</code> if they're result of 
 * mutation.
 * @return <code>true</code> if the elements of this update are newly
 *         created random individuals, <code>false</code> if they're
 *         result of mutation.  
 */

  public  final boolean get_is_population_new()
    {
    return this.m_new;
    }
  
/**
 * Set whether the elements of this update are results of mutation or
 * newly created individuals.
 * @param p_new <code>true</code> if the elements of this update are newly
 *              created random individuals, <code>false</code> if they're
 *              result of mutation. 
 */

  final void  set_population_is_new (final boolean p_new)
    {
    this.m_new = p_new;
    }
  
/**
 * Assign the internal data of this search data to the data of
 * another one.
 * @param p_data  The simulation data  to assign to.
 */

  @Override
  protected void  assign  (final Object p_data)
    { 
    HCState<Genotype>       l_hcs;
    HCParameters<Genotype>  l_hcp;
    
    super.assign(p_data);
    
    if(p_data instanceof HCState)
      {
      l_hcs                 = Typesafe.cast(p_data);
      this.set_use_rel_best(l_hcs.m_use_rel_best);
      this.set_population_size(l_hcs.m_population_size);
      }
    else
      {
      if(p_data instanceof HCParameters)
        {
        l_hcp = Typesafe.cast(p_data);
        this.set_use_rel_best(l_hcp.get_use_rel_best());
        }
      }
    }
  
/**
 * 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
  public  Object  clone ()
    {
    final HCState<Genotype>  l_ss;
    final StatisticInfo[]    l_n;
          int                l_i;
  
    l_ss = Typesafe.cast(super.clone());      
    l_ss.m_stat        = l_n = l_ss.m_stat.clone();
    
    for(l_i = (l_n.length-1); l_i >= 0; l_i--)
      {
      l_n[l_i] = ((StatisticInfo)(l_n[l_i].clone()));
      }
    
    return l_ss;
    }
  }

File Information:

file name:HCState.java
package:org.dgpf.search.algorithms.hc
qualified name:org.dgpf.search.algorithms.hc.HCState.java
file type:Java Source File
download location:download http://dgpf.sourceforge.net/source/org/dgpf/search/algorithms/hc/HCState.java
size:9.596 KB (9827 B)
uploaded: 2015-07-22 04:10:59 GMT+0000
last update: 2006-07-21 13:11:55 GMT+0000
last access: 2017-11-20 19:06:29 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-20 19:06:29 GMT+0000.
Valid CSS Valid XHTML 1.1
Valid RSS SourceForge.net Logo