File tree Expand file tree Collapse file tree 1 file changed +16
-2
lines changed
utbot-framework/src/main/kotlin/org/utbot/engine/selectors/nurs Expand file tree Collapse file tree 1 file changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -58,6 +58,13 @@ abstract class NonUniformRandomSearch(
58
58
59
59
private val randomGen: Random ? = seed?.let { Random (seed) }
60
60
61
+ // We use this value to avoid non-deterministic behaviour of the
62
+ // peek method. Without it, we might have different states for
63
+ // a sequence of the `peek` calls.
64
+ // Now we remember it at the first `peek` call and use it
65
+ // until a first `poll` call. The first call should reset it back to null.
66
+ private var lastTakenRandomValue: Double? = null
67
+
61
68
override fun update () {
62
69
executionQueue.updateAll()
63
70
}
@@ -75,15 +82,22 @@ abstract class NonUniformRandomSearch(
75
82
* with probability executionState.asWeight.weight / sumWeights
76
83
*/
77
84
override fun peekImpl (): ExecutionState ? {
78
- val rand = (randomGen?.nextDouble() ? : 1.0 ) * sumWeights
85
+ if (lastTakenRandomValue == null ) {
86
+ lastTakenRandomValue = randomGen?.nextDouble()
87
+ }
88
+
89
+ val rand = (lastTakenRandomValue ? : 1.0 ) * sumWeights
79
90
80
91
return executionQueue.findLeftest(rand)?.first
81
92
}
82
93
83
94
override fun removeImpl (state : ExecutionState ): Boolean = executionQueue.remove(state)
84
95
85
96
override fun pollImpl (): ExecutionState ? =
86
- peekImpl()?.also { remove(it) }
97
+ peekImpl()?.also {
98
+ remove(it)
99
+ lastTakenRandomValue = null
100
+ }
87
101
88
102
override fun isEmpty () =
89
103
executionQueue.isEmpty()
You can’t perform that action at this time.
0 commit comments