solutioncomparator.java

来自「这是多目标进化算法包」· Java 代码 · 共 54 行

JAVA
54
字号
/**
 * SolutionComparator.java
 * 
 * @author Juan J. Durillo
 * @version 1.0
 */
package jmetal.base.operator.comparator;

import java.util.Comparator;

import jmetal.base.Configuration;
import jmetal.base.Solution;
import jmetal.util.Distance;
import jmetal.util.JMException;

/**
 * This class implements a <code>Comparator</code> (a method for comparing
 * <code>Solution</code> objects) based on the values of the variables.
 */
public class SolutionComparator implements Comparator {
   
  /**
   * Establishes a value of allowed dissimilarity
   */
  private static final double EPSILON  = 1e-10;    
        
  /**
   * Compares two solutions.
   * @param o1 Object representing the first <code>Solution</code>. 
   * @param o2 Object representing the second <code>Solution</code>.
   * @return 0, if both solutions are equals with a certain dissimilarity, -1
   * otherwise.
   * @throws JMException 
   * @throws JMException 
   */
  public int compare(Object o1, Object o2) {
    Solution solution1, solution2;        
    solution1 = (Solution)o1;
    solution2 = (Solution)o2;
        
    if (solution1.numberOfVariables() != solution2.numberOfVariables())
      return -1;

    try {
      if ((new Distance()).distanceBetweenSolutions(solution1,solution2) < EPSILON)
        return 0;
    } catch (JMException e) {
      Configuration.logger_.severe("SolutionComparator.compare: JMException ") ; 
    }
                
    return -1;
  } // compare
} // SolutionComparator

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?