Logo
Distributed Genetic Programming Framework
print print

File org.dgpf.search.api.IndividualComparator.java

Here you can find all the information about the file org.dgpf.search.api.IndividualComparator.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 13:38:15
 * Original Filename: org.dgpf.search.api.comparators.IndividualComparator.java
 * Version          : 2.0.2
 * Last modification: 2006-05-29
 *                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 java.util.Comparator;

import org.sfc.utils.ICloneable;


/**
 * <p>
 * This abstract base class provides the comparator interface used for
 * population sorting and individual comparison.
 * </p><p>
 * Notice that individual comparison is inverse to normal object comparison.
 * A result of -1 indicates that the individual is better than another one,
 * 1 means worse.
 * </p>
 * <p>
 * An individual comparator may use volatile data and/or change its way to
 * compare things. If it does so, it must implement the interface
 * <code>ICloneable</code></p>
 *                   
 * @see ICloneable
 * @author Thomas Weise
 */

public abstract class       IndividualComparator
                extends     SearchAdaptable
                implements  Comparator<Individual<?>>,
                            Serializable
  {
/**
 * The serial version uid.
 */

  private static final long serialVersionUID = 1;
  
/**
 * <p>
 * Compares its two individuals for fitness.  Returns a negative integer,
 * zero, or a positive integer as the first argument is fitter than, equal
 * to, or less fit than the second.
 *</p><p>
 * The implementor must ensure that <tt>sgn(compare(x, y)) ==
 * -sgn(compare(y, x))</tt> for all <tt>x</tt> and <tt>y</tt>.  (This
 * implies that <tt>compare(x, y)</tt> must throw an exception if and only
 * if <tt>compare(y, x)</tt> throws an exception.)<p>
 * </p><p>
 * The implementor must also ensure that the relation is transitive:
 * <tt>((compare(x, y)&gt;0) &amp;&amp; (compare(y, z)&gt;0))</tt> implies
 * <tt>compare(x, z)&gt;0</tt>.<p>
 *</p><p>
 * Finally, the implementer must ensure that <tt>compare(x, y)==0</tt>
 * implies that <tt>sgn(compare(x, z))==sgn(compare(y, z))</tt> for all
 * <tt>z</tt>.<p>
 * </p><p>
 * It is generally the case, but <i>not</i> strictly required that
 * <tt>(compare(x, y)==0) == (x.equals(y))</tt>.  Generally speaking,
 * any comparator that violates this condition should clearly indicate
 * this fact.  The recommended language is "Note: this comparator
 * imposes orderings that are inconsistent with equals."
 * </p>
 * @param p_i1 The first individual to be compared.
 * @param p_i2 The second individual to be compared.
 * @return a negative integer, zero, or a positive integer as the
 *         first individual is fitter than, equal to, or less fit than the
 *         second.
 * @throws ClassCastException if the arguments' types prevent them from
 *         being compared by this Comparator.
 * @see #get_scalar_difference(Individual, Individual)
 */

  public  abstract  int compare(final Individual<?>  p_i1,
                                final Individual<?>  p_i2);

  
/**
 * <p>
 * Obtain the scalar difference of two individuals. This method is
 * compatible with <code>compare</code> by fulfilling the contract that
 * <code>sign(compare(a,b)) == sign(get_scalar_difference(a,b))</code>
 * where <code>sign(x)</code> computes the sign of the number
 * <code>x</code>. <code>get_scalar_difference</code> is used by some
 * search techniques that require a numeric resolution of the comparison
 * of two individuals more precise than <code>compare</code> can deliver.
 * However, <code>compare</code> should be the prefered way to compare
 * two individuals. 
 * </p>
 * @param p_i1 The first individual to be compared.
 * @param p_i2 The second individual to be compared.
 * @return a negative double, zero, or a positive double as the
 *         first individual is fitter than, equal to, or less fit than the
 *         second denoting the difference of the two individuals.
 * @throws ClassCastException if the arguments' types prevent them from
 *         being compared by this Comparator.
 * @see #compare(Individual, Individual)
 */

  public  double get_scalar_difference(final Individual<?>  p_i1,
                                       final Individual<?>  p_i2)
    {
    return this.compare(p_i1, p_i2);
    }

  
/**
 * Check wether an individual is useless or not.
 * @param p_i   The individual to be checked.
 * @return  <code>true</code> if and only if the individual is useless for
 *          the genetic process, <code>false</code> if it might be useful.
 */

  public  boolean is_useless  (final Individual<?>  p_i)
    {
    int     l_i;
    
    for(l_i = (p_i.get_fitness_function_count()-1); l_i >= 0; l_i--)
      {
      if(SearchUtils.format_positive(p_i.get_fitness(l_i)) <= 0.0d)
        {
        return true;
        }
      }
    
    return false;
    }
  }

File Information:

file name:IndividualComparator.java
package:org.dgpf.search.api
qualified name:org.dgpf.search.api.IndividualComparator.java
file type:Java Source File
download location:download http://dgpf.sourceforge.net/source/org/dgpf/search/api/IndividualComparator.java
size:5.663 KB (5799 B)
uploaded: 2015-07-22 04:11:00 GMT+0000
last update: 2006-06-07 06:57:21 GMT+0000
last access: 2017-11-17 21:15:13 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:15:13 GMT+0000.
Valid CSS Valid XHTML 1.1
Valid RSS SourceForge.net Logo