Skip to content

Commit 868e336

Browse files
committed
Add LipsBudget.kt from b2e1597f8
1 parent 226eb78 commit 868e336

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

  • core/src/main/kotlin/org/evomaster/core/search/algorithms
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package org.evomaster.core.search.algorithms
2+
3+
import org.evomaster.core.EMConfig
4+
import org.evomaster.core.search.service.SearchTimeController
5+
6+
/**
7+
* Encapsulates per-target budget accounting for LIPS.
8+
* It derives fair-share budgets from the global stopping criterion
9+
* and tracks the remaining budget for the current target.
10+
*/
11+
class LipsBudget(
12+
private val config: EMConfig,
13+
private val time: SearchTimeController
14+
) {
15+
16+
var budgetLeftForCurrentTarget: Int = 0
17+
18+
fun computePerTargetBudget(uncoveredSize: Int): Int {
19+
return when (config.stoppingCriterion) {
20+
EMConfig.StoppingCriterion.ACTION_EVALUATIONS -> {
21+
val remaining = (config.maxEvaluations - time.evaluatedActions).coerceAtLeast(0)
22+
if (uncoveredSize <= 0) remaining else remaining / uncoveredSize
23+
}
24+
EMConfig.StoppingCriterion.TIME -> {
25+
val remaining = (config.timeLimitInSeconds() - time.getElapsedSeconds()).coerceAtLeast(0)
26+
if (uncoveredSize <= 0) remaining else remaining / uncoveredSize
27+
}
28+
else -> Int.MAX_VALUE
29+
}
30+
}
31+
32+
fun usedForCurrentTarget(startActions: Int, startSeconds: Int): Int {
33+
return when (config.stoppingCriterion) {
34+
EMConfig.StoppingCriterion.ACTION_EVALUATIONS -> time.evaluatedActions - startActions
35+
EMConfig.StoppingCriterion.TIME -> time.getElapsedSeconds() - startSeconds
36+
else -> 0
37+
}
38+
}
39+
40+
fun updatePerTargetBudget(actionsAtGenStart: Int, secondsAtGenStart: Int) {
41+
val used = usedForCurrentTarget(actionsAtGenStart, secondsAtGenStart)
42+
budgetLeftForCurrentTarget -= used
43+
}
44+
45+
fun shouldSwitchTarget(coveredNow: Boolean): Boolean {
46+
val outOfBudget = budgetLeftForCurrentTarget <= 0
47+
return coveredNow || outOfBudget
48+
}
49+
}
50+
51+

0 commit comments

Comments
 (0)