Logo
Distributed Genetic Programming Framework
print print

File org.dgpf.search.algorithms.sa.SAState.java

Here you can find all the information about the file org.dgpf.search.algorithms.sa.SAState.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-06-05 13:27:42
 * Created by       : Stefan Niemczyk, Marc Kirchhoff
 * Original Filename: org.dgpf.search.algorithms.sa.SAState.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.sa;

import java.io.Serializable;

import org.dgpf.search.algorithms.ga.GeneticState;
import org.dgpf.search.algorithms.sa.ta.TemperatureAdaptionStrategy;
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.BoundedDoubleProperty;
import org.sfc.meta.BoundedIntProperty;
import org.sfc.meta.MetaInformation;
import org.sfc.meta.Property;
import org.sfc.utils.Typesafe;

/**
* The state of the simulated annealing engine.
@param <Genotype> The genotype of the elements to be evolved.
*
@author Stefan Niemczyk, Marc Kirchhoff
*/

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

  private static final long serialVersionUID = 1;
  

/**
 * The meta information of the simulated annealing state.
 */

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

  public  static  final BoundedIntProperty POPULATION_SIZE ;
  
  
/**
 * The property telling the whole population was newly
 * created in a randomized manner.
 */

  public  static  final Property<Boolean> IS_POPULATION_NEW ;
/**
 * The property to access the start temperature.
 */

  public  static  final BoundedDoubleProperty START_TEMPERATURE ;
/**
 * The temperature property.
 */

  public  static  final BoundedDoubleProperty TEMPERATURE ;
/**
 * The temperature adaption strategy property.
 */

  public  static  final Property<TemperatureAdaptionStrategy>
        TEMPERATURE_ADAPTION  ;
  
  static
    {
    POPULATION_SIZE = new BoundedIntProperty(
             GeneticState.POPULATION_SIZE.get_name(),
             SAUtils.SA_PROPERTIES,
             0, SearchUtils.DEFAULT_MAX_INT);
    POPULATION_SIZE.add_port(SAState.class, true, false, null);
    
    
    IS_POPULATION_NEW = new Property<Boolean>("is_population_new",
                             SAUtils.SA_PROPERTIES,
                             boolean.class);
    IS_POPULATION_NEW.add_port(SAState.class, true, false, null);
    
    SearchUtils.ALL_STAT.add_port(SAState.class"get_stat", null,
                                  SearchUtils.FITNESS_FUNCTION_COUNT_FUNC);
    
    START_TEMPERATURE = new BoundedDoubleProperty("start_temperature",
                          SAUtils.SA_PROPERTIES, 0.0d,
                          SearchUtils.DEFAULT_MAX_DOUBLE);
    START_TEMPERATURE.add_port(SAState.class, true, false, null);
    
    TEMPERATURE = new BoundedDoubleProperty("temperature",
                          SAUtils.SA_PROPERTIES, 0.0d,
                          SearchUtils.DEFAULT_MAX_DOUBLE);
    TEMPERATURE.add_port(SAState.class, true, false, null);
    
    TEMPERATURE_ADAPTION = new Property<TemperatureAdaptionStrategy>
                              ("temperature_adaption_strategy",
                                        SAUtils.SA_PROPERTIES,
                                      TemperatureAdaptionStrategy.class); 
    TEMPERATURE_ADAPTION.add_port(SAState.class, true, false, null); 
    
    SA_STATE_METAINFO = new MetaInformation();
    }
 
/**
 * The parameter indicates the probability the worst individual will be 
 * used next.
 */

  private double m_temperature;
  
/**
 * The temperature which was set at the beginning.
 */

  private double m_start_temperature;

   
/**
 * The parameter indicates the temperature adaption strategy.
 */

  private String m_temperature_adaption_strategy;
  
/**
 * The size of the population in simulated annealing. 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 simulated annealing state.
 * @param p_ff_count  The count of fitness functions evaluated by this
 *                    search.
 * @param p_bag       The state bag containing this state.
 */

  protected SAState  (final int                  p_ff_count,
                      final SAStateBag<Genotype> p_bag)
    {
    super(p_ff_count);
      
    this.m_temperature    = SAUtils.DEFAULT_TEMPERATURE;
    this.m_temperature_adaption_strategy = 
      SAUtils.DEFAULT_TEMPERATURE_ADAPT_STRATEGY.toString();
    this.m_start_temperature  = SAUtils.DEFAULT_TEMPERATURE;
    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();
      }    
    }
  
/**
 * Get the m_temperature parameter.
 * @return The probability the worst individual will be used next.
 */

  public final double get_temperature()
    {
    return this.m_temperature;
    }
  
/**
 * Set the <code<m_temperature</code> parameter.
 * @param p_temperature  The new temperature value.
 */

  private final void set_temperature(final double p_temperature)
    {
    if(p_temperature >= 0.0d) this.m_temperature = p_temperature;
    }
  
/**
 * Get the m_start_temperature parameter.
 * @return The temperature which was set at the beginning.
 */

  public final double get_start_temperature()
    {
    return this.m_start_temperature;
    }
  
/**
 * Set the <code>m_start_temperature</code> parameter.
 * @param p_start_temperature  The start temperature value.
 */

  private final void set_start_temperature(final double p_start_temperature)
    {
    if(p_start_temperature >= 0.0d)
      {
      this.m_start_temperature = p_start_temperature;
      }
    }
  
/**
 * Get the m_temperature_adaption_strategy parameter.
 * @return The current temperature adaption strategy.
 */

  public final String get_temperature_adaption_strategy()
    {
    return this.m_temperature_adaption_strategy;
    }
  
/**
 * Set the <code<m_alpha</code> parameter.
 * @param p_temperature_adaption_strategy  The new 
 *        m_temperature_adaption_strategy value.
 */

  private final void set_temperature_adaption_strategy(
      final String p_temperature_adaption_strategy)
    {
    if(p_temperature_adaption_strategy != null)
      {
      this.m_temperature_adaption_strategy = 
          p_temperature_adaption_strategy;
      }
    }
  
/**
 * 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 simulated annealing. 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)
    { 
    SAState<Genotype>           l_sas;
    SAParameters<Genotype>      l_sap;
    TemperatureAdaptionStrategy l_tas;
    
    super.assign(p_data);
    
    if(p_data instanceof SAState)
      {
      l_sas                 = Typesafe.cast(p_data);
      this.set_temperature(l_sas.get_temperature());
      this.set_temperature_adaption_strategy(
          l_sas.get_temperature_adaption_strategy());
      this.set_population_size(l_sas.m_population_size);
      this.set_start_temperature(l_sas.get_start_temperature());
      }
    else
      {
      if(p_data instanceof SAParameters)
        {
        l_sap = Typesafe.cast(p_data);
        this.set_temperature(l_sap.get_temperature());
        l_tas = l_sap.get_temperature_adaption_strategy();
        if(l_tas != null)
        this.set_temperature_adaption_strategy(l_tas.toString());
        this.set_start_temperature(l_sap.get_start_temperature());
        }
      }
    }
  
/**
 * 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 SAState<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:SAState.java
package:org.dgpf.search.algorithms.sa
qualified name:org.dgpf.search.algorithms.sa.SAState.java
file type:Java Source File
download location:download http://dgpf.sourceforge.net/source/org/dgpf/search/algorithms/sa/SAState.java
size:11.916 KB (12203 B)
uploaded: 2015-07-22 04:10:59 GMT+0000
last update: 2006-07-21 13:11:55 GMT+0000
last access: 2017-11-17 21:06:46 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 21:06:46 GMT+0000.
Valid CSS Valid XHTML 1.1
Valid RSS SourceForge.net Logo