Logo
Distributed Genetic Programming Framework
print print

File org.dgpf.search.api.FitnessAccessor.java

Here you can find all the information about the file org.dgpf.search.api.FitnessAccessor.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-04-10 13:32:35
 * Original Filename: org.dgpf.search.api.FitnessAccessor.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.util.Comparator;

import org.sfc.math.stochastic.statistics.ValueExtractor;

/**
 * This internal class is used to provide statistics on the single fitness
 * functions.
 *
 * @author Thomas Weise
 */

public  final class FitnessAccessor extends    ValueExtractor<Individual<?>[]>
                                    implements Comparator<Individual<?>>
  {
/**
 * The accessor pool.
 */

  static    FitnessAccessor[]  s_pool  ;

  static
    {
    int l_i;

    s_pool = new FitnessAccessor[10];

    for(l_i = (s_pool.length-1); l_i >= 0; l_i--)
      {
      s_pool[l_i] = new FitnessAccessor(l_i);
      }
    }

/**
 * Obtain a fitness accessor for the fitness function at index
 * <code>p_ff_id</code>.
 * @param p_ff_id The index of the fitness function to be used.
 * @return  An instance of <code>FitnessAccessor</code> that can be used to
 *          sort a list of individuals or to access the fitness values.
 */

  public  static  final FitnessAccessor get_accessor  (final int p_ff_id)
    {
    return s_pool[p_ff_id];
    }

/**
 * Ensure that the accessor pool has the right capacity.
 * @param p_count The minimum count of accessors required.
 */

  static synchronized final void ensure_pool_capacity(final int p_count)
    {
    FitnessAccessor[]  l_p;
    int         l_i;

    l_i = s_pool.length;

    if(p_count > l_i)
      {
      l_p = new FitnessAccessor[p_count];

      System.arraycopy(s_pool, 0, l_p, 0, l_i);

      for(; l_i < p_count; l_i++)
        {
        l_p[l_i] = new FitnessAccessor(l_i);
        }
      s_pool = l_p;
      }
    }


/**
 * The index of the fitness function to be processed by this accessor.
 */

  private final int m_index ;

/**
 * Create a new accessor object.
 * @param p_index The index of the fitness function to be processed by this
 *                accessor.
 */

  FitnessAccessor  (final int p_index)
    {
    super();
    this.m_index = p_index;
    }

/**
 * Obtain a double value from the item at position <code>p_index</code> in
 * the collection.
 * @param p_collection  The collection object to obtain the value from.
 * @param p_index       The index of the item to return the value of.
 * @return              The <code>double</code> representation of the item
 *                      at this position.
 */

  @Override
  protected final double  get_value(final Individual<?>[] p_collection,
                                    final int             p_index)
    {
    return p_collection[p_index].get_fitness(this.m_index);
    }

/**
 * Compare two individuals. This method is used to sort them in a descending
 * order.
 * @param p_o1  The first individual.
 * @param p_o2  The second individual.
 * @return  An integer >0 if <code>p_o1&lt;p_o2</code>, ==0 if
 *          <code>p_o1==p_o2</code> and <0 if <code>p_o1&gt;p_o2</code>.
 */

  public  final int compare(final Individual<?> p_o1,
                            final Individual<?> p_o2)
    {
    return Double.compare(p_o2.get_fitness(this.m_index),
                          p_o1.get_fitness(this.m_index));
    }
  }

File Information:

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