Logo
Distributed Genetic Programming Framework
print print

File org.dgpf.search.algorithms.ga.sorting.DominationFitnessSorting.java

Here you can find all the information about the file org.dgpf.search.algorithms.ga.sorting.DominationFitnessSorting.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-12 14:51:13
 * Original Filename: org.dgpf.search.algorithms.ga.sorting.DominationFitnessSorting.java
 * Version          : 1.0.1
 * Last modification: 2006-05-31
 *                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.ga.sorting;

import org.dgpf.search.api.Individual;
import org.dgpf.search.api.IndividualComparator;


/**
 * This sorting algorithm performs the same sorting as the domination based
 * sorting but also computes virtual fitness values for the elements.
 *
 * @author Thomas Weise
 */

public class DominationFitnessSorting  extends DominationBasedSorting
  {
/**
 * The serial version uid.
 */

  private   static  final long    serialVersionUID        = 1;
  
/**
 * Create a new domination based sorting instance.
 * @param p_count_dominated This parameter is <code>true</code> if not only
 *                          the count of individuals one individual is not
 *                          dominated is used for sorting, but also the
 *                          count of individuals it is dominating itself is
 *                          used.
 */

  public  DominationFitnessSorting  (final boolean p_count_dominated)
    {  
    super(p_count_dominated);
    }
  

/**
 * Internally create a new individual holder.
 * @return A new individual holder.
 */

  @Override
  final IndividualHolder  create_holder()
    {
    return new IndividualHolder2();
    }
  
/**
 * Internally create a new individual holder array.
 * @param p_len The length of the wanted array.
 * @return A new individual holder.
 */

  @Override
  final IndividualHolder[]  create_holder_array(final int p_len)
    {
    return new IndividualHolder2[p_len];
    }
  
  
  
  
/**
 * Obtain the fitness group of the element at the specified index.
 * The fitness group is the a set of individuals which were determined to
 * have the same domination characteristics. The higher the fitness group,
 * the better.
 * @param p_index The index of the element to obtain the fitness group
 *                index of.
 * @return The fitness group of the element at the specified index.
 */

  public  final int get_fitness_group (final int p_index)
    {
    return ((IndividualHolder2)(this.m_temp[p_index])).m_group;
    }

/**
 * Sort the individuals so that they can be used by the selection algorithm
 * optimally.
 * @param p_individuals The array with the individuals to be sorted.
 * @param p_count       The count of individuals in that array.
 * @param p_comparator  The comparator to be used.
 * @param p_unsorted    This parameter is <code>false</code>, if and only
 *                      if the population is already sorted according to
 *                      the comparator provided. Otherwise it is
 *                      <code>true</code> indicating that list is not yet
 *                      sorted.
 */

  @Override
  public        void  sort  (final Individual<?>[]      p_individuals,
                             final int                  p_count,
                             final IndividualComparator p_comparator,
                             final boolean              p_unsorted)
    {
    final IndividualHolder2[] l_d;
          IndividualHolder2   l_h;
          int                 l_i, l_k, l_od, l_on, l_ns, l_g;
              
    super.sort(p_individuals, p_count, p_comparator, p_unsorted);
          
    l_d  = ((IndividualHolder2[])(this.m_temp));        
    
    l_k  = (p_count-1);
    l_h  = l_d[l_k];
    l_od = l_h.m_dom;
    l_on = l_h.m_nondom;
    l_g  = 0;
    for(l_i = (l_k-1); l_i >= 0; l_i--)
      {
      l_h = l_d[l_i];
      if((l_h.m_dom != l_od) || (l_h.m_nondom != l_on))
        {
        l_od  = l_h.m_dom;
        l_on  = l_h.m_nondom;        
        l_ns  = (l_k - l_i);      
        l_g++;
        for(; l_k > l_i; l_k--)
          {
          l_h.m_nieche_size = l_ns;
          l_h.m_group       = l_g;
          }
        }      
      }
    
           
    l_ns  = (l_k - l_i);
    l_g++;
    for(; l_k > l_i; l_k--)
      {
      l_h.m_nieche_size = l_ns;
      l_h.m_group       = l_g;
      }
    
    }
  
  
/**
 * Obtain the nieche size of the individual at the given index.
 * @param p_index The index of the individual to obtain the nieche size of.
 * @return The nieche size of the individual at the given index.
 */

  public  final int   get_nieche_size (final int p_index)
    {
    return ((IndividualHolder2)(this.m_temp[p_index])).m_nieche_size;
    }
  

/**
 * Check whether this object equals another one.
 * @param p_object  The object to compare with.
 * @return <code>true</code> if and only if this object equals to the other
 *         one.
 */

  @Override
  public  boolean equals  (final Object p_object)
    {
    if(p_object == thisreturn true;
    
    if(p_object instanceof DominationFitnessSorting)
      {
      return super.equals(p_object);
      }
    
    return false;
    }
  
/**
 * This class is used to hold the reference to an individual.
 *
 * @author Thomas Weise
 */

  static  class IndividualHolder2 extends IndividualHolder
    {
/**
 * The nieche size.
 */

    int           m_nieche_size  ;
/**
 * The fitness group of the individual.
 */

    int           m_group ;
    }
  }

File Information:

file name:DominationFitnessSorting.java
package:org.dgpf.search.algorithms.ga.sorting
qualified name:org.dgpf.search.algorithms.ga.sorting.DominationFitnessSorting.java
file type:Java Source File
download location:download http://dgpf.sourceforge.net/source/org/dgpf/search/algorithms/ga/sorting/DominationFitnessSorting.java
size:6.180 KB (6329 B)
uploaded: 2015-07-22 04:10:59 GMT+0000
last update: 2006-05-31 03:03:49 GMT+0000
last access: 2017-11-24 00:11:35 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:11:35 GMT+0000.
Valid CSS Valid XHTML 1.1
Valid RSS SourceForge.net Logo