Logo
Distributed Genetic Programming Framework
print print

File org.dgpf.search.api.SearchStateBag.java

Here you can find all the information about the file org.dgpf.search.api.SearchStateBag.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 14:21:55
 * Original Filename: org.dgpf.search.api.SearchStateBag.java
 * Version          : 2.0.0
 * Last modification: 2006-05-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.search.api;

import java.io.Serializable;

import org.sfc.math.Mathematics;


/**
 * The search state bag contains the search state. It is the only instance
 * able to access the data of the <code>SearchState</code>. You should
 * place variables like the statistic bags into instances of
 * <code>SearchStateBag</code> while putting the statistic info records
 * into <code>SearchState</code>. This way you prevent them from being
 * serialized/cloned/copied/accessed whenever this is done to a genetic
 * state.
 *
 * @param <Genotype>    The sort of genotype used to represent individuals.
 *                      This must be a serializable type.
 *                    
 * @see SearchState
 * @author Thomas Weise
 */

public class SearchStateBag<Genotype extends    Serializable>
                                     implements Serializable
  {
/**
 * The serial version uid.
 */

  private static final long serialVersionUID = 1;
  
/**
 * The internally hosted search state instance.
 */

                 final SearchState<Genotype> m_state ;
  
  
/**
 * Create a new search state bag.
 * @param p_ff_count  The count of fitness functions evaluated by this
 *                    search.
 */

  protected SearchStateBag  (final int  p_ff_count)
    {
    super();
    this.init(p_ff_count);
    this.m_state = this.create_state(p_ff_count);
    }
  
/**
 * This method allows you to perform additional initialization before
 * the hosted search state will be created.
 * @param p_ff_count  The count of fitness functions evaluated by this
 *                    search.
 */

  protected void  init  (final int  p_ff_count)
    {
    //
    }
  
/**
 * This method is used internally to create a search state instance that
 * can be hosted by this bag.
 * @param p_ff_count  The count of fitness functions evaluated by this
 *                    search.
 * @return  The new search state. 
 */

  protected SearchState<Genotype> create_state(final int  p_ff_count)
    {
    return new SearchState<Genotype>(p_ff_count);
    }
  
/**
 * Check wether the given element is a new supremum considering the given
 * fitness function.
 * @param p_individual    The individual to check.
 * @param p_function      The function regarding to check the individual
 *                        against.
 */

  public final void    check_best(final Individual<Genotype> p_individual,
                                  final int                  p_function)
    { 
    double                l_dist;
    Individual<Genotype>  l_gt;
    SearchState<Genotype> l_s;
        
    l_s    = this.m_state;
    l_gt   = l_s.m_bests[p_function];
    l_dist = (p_individual.get_fitness(p_function) -
                      l_gt.get_fitness(p_function));
    
    if(!(Mathematics.is_number(l_dist))) l_dist = -1.0d;
    
    l_s.m_improvements[p_function] = l_dist;
    
    if(l_dist >= 0.0d)
      {
      l_gt.assign(p_individual);
      }  
    }
  
/**
 * Check wether the given element is a new supremum considering the
 * search's comparator.
 * @param p_individual    The individual to check.
 * @param p_comp          The search's comparator.
 */

  final void check_best(final Individual<Genotype> p_individual,
                        final IndividualComparator p_comp)
    {
    Individual<Genotype>  l_ig;
    int                   l_i;
    SearchState<Genotype> l_s;
        
    l_s  = this.m_state;    
    
    l_ig = l_s.m_best_2;
    l_i  = p_comp.compare(l_ig, p_individual);
    if(l_i >= 0)
      {      
      if(l_i > 0)
        {
        l_ig.assign(p_individual);
        l_s.m_improvement_2 = 1;
        
        l_ig = l_s.m_best;
        l_i  = p_comp.compare(l_ig, p_individual);
        if(l_i >= 0)
          {      
          if(l_i > 0)
            {
            l_ig.assign(p_individual);
            l_s.m_improvement = 1;
            }
          else if(l_s.m_improvement < 0) l_s.m_improvement = 0;
          }
        
        }
      else if(l_s.m_improvement_2 < 0) l_s.m_improvement_2 = 0;
      }
    }
  }

File Information:

file name:SearchStateBag.java
package:org.dgpf.search.api
qualified name:org.dgpf.search.api.SearchStateBag.java
file type:Java Source File
download location:download http://dgpf.sourceforge.net/source/org/dgpf/search/api/SearchStateBag.java
size:5.170 KB (5295 B)
uploaded: 2015-07-22 04:11:00 GMT+0000
last update: 2006-07-14 06:45:31 GMT+0000
last access: 2017-11-24 00:21:51 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-24 00:21:51 GMT+0000.
Valid CSS Valid XHTML 1.1
Valid RSS SourceForge.net Logo