8.3. 更改 OptaPlanner solver 日志记录级别
您可以更改 OptaPlanner solver 中的日志级别来查看 solver 活动。以下列表描述了不同的日志记录级别:
Error: Logs 错误,除了作为
RuntimeException形式丢弃到调用代码中的错误。如果发生错误,OptaPlanner 通常会快速失败。它将引发一系列
RuntimeException,并将详细消息提供给调用代码。为避免重复的日志消息,它不会将其记录为错误。除非调用代码明确捕获并消除RuntimeException,否则线程的默认 'ExceptionHandler会将它作为错误记录。同时,代码会因为执行进一步危害或模糊处理错误而中断。- warn :日志可疑情况
- info :记录每个阶段和解决方案本身
- debug :记录每个阶段的每个步骤
- trace :记录每个阶段每个步骤的每个移动
指定 trace 日志记录会大大降低性能。但是,在开发过程中可以发现瓶颈。
对于 Late Acceptance 和 Simulated Anneing 等快速步骤算法,调试日志记录可能会大大降低性能,但不适用于 Tabu Search 等慢步算法。
trace 和 debug 日志都使用大多数附加器在多线程中解决导致拥塞的问题。
在 Eclipse 中,调试日志记录 到控制台可能会导致拥塞,分数计算速度高于 10000 每秒。IntelliJ 或 Maven 命令行都不会受到此问题。
流程
将日志记录级别设置为 debug 日志记录,以查看阶段何时结束以及执行快速步骤。
以下示例显示了 debug 日志记录的输出:
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。为您的日志记录框架添加依赖项到日志记录适配器。