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(
5858
5959 private val randomGen: Random ? = seed?.let { Random (seed) }
6060
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+
6168 override fun update () {
6269 executionQueue.updateAll()
6370 }
@@ -75,15 +82,22 @@ abstract class NonUniformRandomSearch(
7582 * with probability executionState.asWeight.weight / sumWeights
7683 */
7784 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
7990
8091 return executionQueue.findLeftest(rand)?.first
8192 }
8293
8394 override fun removeImpl (state : ExecutionState ): Boolean = executionQueue.remove(state)
8495
8596 override fun pollImpl (): ExecutionState ? =
86- peekImpl()?.also { remove(it) }
97+ peekImpl()?.also {
98+ remove(it)
99+ lastTakenRandomValue = null
100+ }
87101
88102 override fun isEmpty () =
89103 executionQueue.isEmpty()
You can’t perform that action at this time.
0 commit comments