Logo
Distributed Genetic Programming Framework
print print

File org.dgpf.search.api.comparators.WeightedComparator.java

Here you can find all the information about the file org.dgpf.search.api.comparators.WeightedComparator.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-06 09:18:34
 * Original Filename: org.dgpf.search.api.comparators.WeightedComparator.java
 * Version          : 2.0.1
 * 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.comparators;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

import org.dgpf.search.api.IndividualComparator;

/**
 * This is the abstract base class for weighted comparators 
 *
 * @author Thomas Weise
 */

abstract class WeightedComparator  extends IndividualComparator
  {  
/**
 * The weights of the dominances of the single fitness functions.
 * The higher a priority is, the bigger the absolute influence of its
 * according fitness function's dominance.
 */

  transient double[]  m_weights  ;

/**
 * Create a new instance of the weighted comparator.
 * @param p_weights  The weights of the single fitness function's
 *                      dominances. The higher a priority is, the bigger
 *                      the absolute influence of its according fitness
 *                      function's dominance.
 */

  WeightedComparator(final  double[]  p_weights)
    {
    super();
    this.m_weights = p_weights.clone();
    }
  


/**
 * Returns a human-readable name of the comparator.
 * @return A human-readable name of the comparator.
 */

  @Override
  public  final  String  toString()
    {
    StringBuilder l_sb;
    double[]      l_p;
    int           l_i;

    l_sb = new StringBuilder(super.toString());
    l_p  = this.m_weights;
    l_sb.append('(');
    for(l_i = 0; l_i < l_p.length; l_i++)
      {
      l_sb.append(l_p[l_i]);
      l_sb.append(',');
      }
    l_sb.setCharAt(l_sb.length()-1, ')');
    return l_sb.toString();
    }
  
/**
 * Copy this comparator object.
 * @return A perfect copy of this individual comparator.
 */

  @Override
  public  Object  clone()
    {
    WeightedComparator l_c;
    
    l_c = ((WeightedComparator)(super.clone()));
    
    l_c.m_weights = l_c.m_weights.clone();
    
    return l_c;
    }
  


/**
 * Stores the <code>SfcEvent</code> into the stream.
 * @param p_s The output stream.
 * @throws  IOException If something io-like went wrong.
 */

  private final void writeObject(final ObjectOutputStream p_s)
        throws IOException
    {
    p_s.defaultWriteObject();
    p_s.writeUnshared(this.m_weights);
    }
  


/**
 * Reconstitute the <code>SfcEvent</code> instance from a stream (that is,
 * deserialize it).
 * @param p_s The input stream.
 * @throws  IOException If something io-like went wrong.
 * @throws  ClassNotFoundException  If a needed class could not be found.
 */

  private final void readObject(final ObjectInputStream p_s)
        throws IOException, ClassNotFoundException
    {
    p_s.defaultReadObject();
    this.m_weights = ((double[])(p_s.readUnshared()));
    }
  

/**
 * Obtain the count of fitness functions evaluated by this search.
 * @return The count of fitness functions evaluated by this search.
 */

  public  final int get_fitness_function_count()
    {
    return this.m_weights.length;
    }
  
/**
 * Obtain the weight at the specified index.
 * @param p_index The index to obtain the weight value at.
 * @return  The weight value at the specified index.
 */

  public  final double  get_weight(final int p_index)
    {
    return this.m_weights[p_index];
    }
  

/**
 * Set the weight at the specified index.
 * @param p_index  The index to set the weight value at.
 * @param p_weight The weight value to be set at the specified index.
 */

  public  final void    set_weight(final int    p_index,
                                   final double p_weight)
    {
    if(p_weight >= 0.0d)
      {
      this.m_weights[p_index] = p_weight;
      }
    }
  

  
/**
 * Check whether this comparator equals another object.
 * @param p_object  The object to compare with.
 * @return <code>true</code> if and only if <code>p_object</code> is also
 *         an individual comparator and will always return the same result
 *         for all possible comparisons to be performed.
 */

  @Override
  public  final boolean equals  (final Object p_object)
    {    
    double[]  l_d1, l_d2;
    int       l_i;
    
    if(p_object == thisreturn true;
    if(p_object == null) return false;
    
    if(this.getClass().equals(p_object.getClass()))
      {
      l_d1 = ((WeightedComparator)p_object).m_weights;
      l_d2 = this.m_weights;
      
      l_i = l_d1.length;
      if(l_d2.length != l_i) return false;
      
      for(--l_i; l_i >= 0; l_i--)
        {
        if(Double.compare(l_d1[l_i], l_d2[l_i]) != 0) return false;
        }
      
      return true;
      }
    
    return false;
    }
  }

File Information:

file name:WeightedComparator.java
package:org.dgpf.search.api.comparators
qualified name:org.dgpf.search.api.comparators.WeightedComparator.java
file type:Java Source File
download location:download http://dgpf.sourceforge.net/source/org/dgpf/search/api/comparators/WeightedComparator.java
size:5.673 KB (5810 B)
uploaded: 2015-07-22 04:11:00 GMT+0000
last update: 2006-05-29 14:14:55 GMT+0000
last access: 2017-11-24 00:23:09 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:23:09 GMT+0000.
Valid CSS Valid XHTML 1.1
Valid RSS SourceForge.net Logo