⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 binarytournament.java

📁 关于多目标优化的代码
💻 JAVA
字号:
/**
 * BinaryTournament.java
 * @author Juan J. Durillo
 * @version 1.0
 */
package jmetal.base.operator.selection;


import java.util.Comparator;
import jmetal.base.Solution;
import jmetal.base.Operator;
import jmetal.base.SolutionSet;
import jmetal.base.operator.comparator.*;
import jmetal.util.PseudoRandom;

/**
 * This class implements an opertor for binary selections
 */
public class BinaryTournament extends Operator{

  /**
   * Stores the <code>Comparator</code> used to compare two
   * solutions
   */
  private Comparator comparator_;

  /**
   * Constructor
   * Creates a new Binary tournament operator using a BinaryTournamentComparator
   */
  public BinaryTournament(){
    comparator_ = new BinaryTournamentComparator();
  } // BinaryTournament

  
  /**
  * Constructor
  * Creates a new Binary tournament with a specific <code>Comparator</code>
  * @param comparator The comparator
  */
  public BinaryTournament(Comparator comparator) {
    comparator_ = comparator;
  } // Constructor

  
  /**
  * Performs the operation
  * @param object Object representing a SolutionSet
  * @return the selected solution
  */
  public Object execute(Object object){
    SolutionSet SolutionSet = (SolutionSet)object;
    Solution solution1,solution2;
    solution1 = SolutionSet.get(PseudoRandom.randInt(0,SolutionSet.size()-1));
    solution2 = SolutionSet.get(PseudoRandom.randInt(0,SolutionSet.size()-1));

    int flag = comparator_.compare(solution1,solution2);
    if (flag == -1)
      return solution1;
    else if (flag == 1)
      return solution2;
    else
      if (PseudoRandom.randDouble()<0.5)
        return solution1;
      else
        return solution2;                       
  } // execute
} // BinaryTournament

⌨️ 快捷键说明

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