8.3. OptaPlanner ソルバーのログレベルの変更

OptaPlanner ソルバーのログレベルを変更して、ソルバーアクティビティーを確認できます。次のリストは、さまざまなログレベルについて説明しています。

  • error:RuntimeException として呼び出し元のコードに throw されるエラーを除いて、エラーをログに記録します。

    エラーが発生した場合、OptaPlanner は通常は短時間で失敗します。呼び出し元のコードに詳細なメッセージを含む RuntimeException の サブクラスを出力します。ログメッセージの重複を避けるために、エラーとしてログに記録されません。呼び出し元のコードがその RuntimeException を 明示的にキャッチして排除しない限り、スレッドのデフォルトの `ExceptionHandler はとにかくそれをエラーとしてログに記録します。その間、コードはさらに害を及ぼしたり、エラーを難読化したりすることで中断されます。

  • 警告: 疑わしい状況をログに記録します
  • info: すべてのフェーズとソルバー自体をログに記録します
  • デバッグ: すべてのフェーズのすべてのステップをログに記録します
  • トレース: すべてのフェーズのすべてのステップのすべての動きをログに記録します
注記

トレース ログを指定すると、パフォーマンスが大幅に低下します。ただし、トレース ロギングは、ボトルネックを発見するための開発中に非常に重要です。

デバッグ ログでさえ、レイトアクセプタンスやシミュレーテッドアニーリングなどの高速ステッピングアルゴリズムではパフォーマンスが大幅に低下する可能性がありますが、タブーサーチなどの低速ステッピングアルゴリズムでは低下しません。

trace`と デバッグ ロギングの両方が、ほとんどのアペンダーでのマルチスレッド解決で輻輳を引き起こします。

Eclipse では、コンソールへの デバッグ ログにより、スコア計算速度が 1 秒あたり 10000 を超える輻輳が発生する傾向があります。IntelliJ も Maven コマンドラインもこの問題に悩まされていません。

手順

ロギングレベルを デバッグ ロギングに設定して、フェーズがいつ終了し、どのくらいの速さでステップが実行されるかを確認します。

次の例は、デバッグログからの出力を示しています。

INFO  Solving started: time spent (3), best score (-4init/0), random (JDK with seed 0).
DEBUG     CH step (0), time spent (5), score (-3init/0), selected move count (1), picked move (Queen-2 {null -> Row-0}).
DEBUG     CH step (1), time spent (7), score (-2init/0), selected move count (3), picked move (Queen-1 {null -> Row-2}).
DEBUG     CH step (2), time spent (10), score (-1init/0), selected move count (4), picked move (Queen-3 {null -> Row-3}).
DEBUG     CH step (3), time spent (12), score (-1), selected move count (4), picked move (Queen-0 {null -> Row-1}).
INFO  Construction Heuristic phase (0) ended: time spent (12), best score (-1), score calculation speed (9000/sec), step total (4).
DEBUG     LS step (0), time spent (19), score (-1),     best score (-1), accepted/selected move count (12/12), picked move (Queen-1 {Row-2 -> Row-3}).
DEBUG     LS step (1), time spent (24), score (0), new best score (0), accepted/selected move count (9/12), picked move (Queen-3 {Row-3 -> Row-2}).
INFO  Local Search phase (1) ended: time spent (24), best score (0), score calculation speed (4000/sec), step total (2).
INFO  Solving ended: time spent (24), best score (0), score calculation speed (7000/sec), phase total (2), environment mode (REPRODUCIBLE).

費やされた時間の値はすべてミリ秒単位です。

すべてが SLF4J に記録されます。これは、すべてのログメッセージを Logback、Apache Commons Logging、Log4j、または java.util.logging に委任する単純なログファサードです。選択したロギングフレームワークのロギングアダプターに依存関係を追加します。