Skip to content

Commit ba2f70a

Browse files
angelacorteDanySK
authored andcommitted
docs: add documentation
1 parent 9b886e2 commit ba2f70a

1 file changed

Lines changed: 14 additions & 10 deletions

File tree

alchemist-implementationbase/src/main/kotlin/it/unibo/alchemist/model/terminators/MetricsStableForSteps.kt

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@ import it.unibo.alchemist.model.Environment
44
import it.unibo.alchemist.model.Position
55
import it.unibo.alchemist.model.TerminationPredicate
66

7+
/**
8+
* [stepInterval] for how many steps the [metricsToCheck] should be stable.
9+
* [equalInterval] how many times it should be stable.
10+
*/
711
class MetricsStableForSteps<T>(
812
private val stepInterval: Long,
913
private val equalInterval: Long,
1014
private val metricsToCheck: (Environment<T, Position<*>>) -> Map<String, T>,
11-
): TerminationPredicate<T, Position<*>> {
15+
) : TerminationPredicate<T, Position<*>> {
1216
private var stepsChecked: Long = 0
1317
private var equalSuccess: Long = 0
1418
private var lastUpdatedMetrics: Map<String, T> = emptyMap()
@@ -22,17 +26,17 @@ class MetricsStableForSteps<T>(
2226
require(metrics.isNotEmpty()) {
2327
"There should be at least one metric to check."
2428
}
25-
return if (lastUpdatedMetrics == metrics) {
26-
if (++stepsChecked >= stepInterval){
27-
stepsChecked = 0
29+
return when {
30+
lastUpdatedMetrics == metrics -> {
31+
if (++stepsChecked >= stepInterval) stepsChecked = 0
2832
++equalSuccess >= equalInterval
2933
}
30-
else false
31-
} else {
32-
stepsChecked = 0
33-
equalSuccess = 0
34-
lastUpdatedMetrics = metrics
35-
false
34+
else -> {
35+
stepsChecked = 0
36+
equalSuccess = 0
37+
lastUpdatedMetrics = metrics
38+
false
39+
}
3640
}
3741
}
3842
}

0 commit comments

Comments
 (0)