LoginSignup
2
1

More than 5 years have passed since last update.

jMetal解説 - アルゴリズムの設定と実行

Last updated at Posted at 2018-02-21

元のページ

このページを雑に訳しただけ.

アルゴリズムの設定

アルゴリズムを設定するためにはrunnerと呼ばれるクラスを書くしかない.
(次以降のリリースで,外部のファイルから設定を読み込めるようにしたいらしい)

jMetalに含まれるアルゴリズムには少なくとも1つはrunnerクラスが用意されている.
それらはjmetal-execモジュールのこのフォルダにある.

例として次のNSGA-IIの5つのrunnerクラスを挙げる.
これらはそれぞれ違う用途に使用するように設定されている.

  • NSGAIIRnner: 連続値の問題を解くためのNSGA-IIのスタンダードな設定.
  • NSGAIIInteger: 整数値問題を解くための設定.
  • NSGAIIBinary: 2値問題を解くための設定.
  • NSGAIIMeasures: NSGAIIRunnerと同様だが,measuresの使い方の例が含まれている.
  • ParallelNSGAII: NSGAIIRunnerと同様だが,populationsを評価する際にスレッドを用いて並列に処理を行う.

次にNSGAIIRunnerクラスの詳細を示す.
Javadocに示しているように,第1引数には解くべき問題のクラス名を与える.
第2引数はオプションのパラメータで,最適なパレートフロントの近似を含むファイルのパスを与える.
パレートフロントが与えられた場合,利用可能なすべてのquality indicatorを計算するために用いられる.

public class NSGAIIRunner extends AbstractAlgorithmRunner {
  /**
   * @param args Command line arguments.
   * @throws JMetalException
   * @throws FileNotFoundException
   * Invoking command: java org.uma.jmetal.runner.multiobjetive.NSGAIIRunner problemName [referenceFront]
   */
  public static void main(String[] args) throws JMetalException, FileNotFoundException {

mainメソッドでは最初に,解くべき問題の型と使用するoperatorを宣言する.
(この例では,DoubleSolutionを個体として扱う問題を宣言している.)
referenceParetoFrontは与えらえれた最適なパレ―トフロントのファイルパスを示す.

    Problem<DoubleSolution> problem;
    Algorithm<List<DoubleSolution>> algorithm;
    CrossoverOperator<DoubleSolution> crossover;
    MutationOperator<DoubleSolution> mutation;
    SelectionOperator<List<DoubleSolution>, DoubleSolution> selection;
    String referenceParetoFront = "" ;

次に,プログラムに与えられた引数をパースしていく.
引数が与えられなかった場合はデフォルトでベンチマーク問題を解く.(この例ではZDT1を解く.)

    String problemName ;
    if (args.length == 1) {
      problemName = args[0];
    } else if (args.length == 2) {
      problemName = args[0] ;
      referenceParetoFront = args[1] ;
    } else {
      problemName = "org.uma.jmetal.problem.multiobjective.zdt.ZDT1";
      referenceParetoFront = "jmetal-problem/src/test/resources/pareto_fronts/ZDT1.pf" ;
    }

次に,クラス名からproblemロードする.

    problem = ProblemUtils.<DoubleSolution> loadProblem(problemName);

そして,operatorやalgorithmの設定をする.

    double crossoverProbability = 0.9 ;
    double crossoverDistributionIndex = 20.0 ;
    crossover = new SBXCrossover(crossoverProbability, crossoverDistributionIndex) ;

    double mutationProbability = 1.0 / problem.getNumberOfVariables() ;
    double mutationDistributionIndex = 20.0 ;
    mutation = new PolynomialMutation(mutationProbability, mutationDistributionIndex) ;

    selection = new BinaryTournamentSelection<DoubleSolution>(new RankingAndCrowdingDistanceComparator<DoubleSolution>());

    algorithm = new NSGAIIBuilder<DoubleSolution>(problem, crossover, mutation)
        .setSelectionOperator(selection)
        .setMaxEvaluations(25000)
        .setPopulationSize(100)
        .build() ;

最後に,アルゴリズムを実行し,得られた解を2つのファイルに書き込む.
1つには変数の値を,もう1つには目的関数の値を書きこむ.
また,パレートフロントが引数で与えられていたら,利用可能なすべてのquality indicatorsの計算結果をプリントする.

    AlgorithmRunner algorithmRunner = new AlgorithmRunner.Executor(algorithm)
        .execute() ;

    List<DoubleSolution> population = algorithm.getResult() ;
    long computingTime = algorithmRunner.getComputingTime() ;

    JMetalLogger.logger.info("Total execution time: " + computingTime + "ms");

    printFinalSolutionSet(population);
    if (!referenceParetoFront.equals("")) {
      printQualityIndicators(population, referenceParetoFront) ;
    }
  }
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1