From a0b717e497151c08e7aee91ce7553c420ee680ee Mon Sep 17 00:00:00 2001 From: Johannes Lenfers Date: Thu, 11 Jan 2024 15:44:02 +0100 Subject: [PATCH] added proper limits for random sampling --- .../elevate/heuristic_search/heuristics/RandomGraph.scala | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/scala/elevate/heuristic_search/heuristics/RandomGraph.scala b/src/main/scala/elevate/heuristic_search/heuristics/RandomGraph.scala index 37d28bec..f3ce4c56 100644 --- a/src/main/scala/elevate/heuristic_search/heuristics/RandomGraph.scala +++ b/src/main/scala/elevate/heuristic_search/heuristics/RandomGraph.scala @@ -18,7 +18,10 @@ class RandomGraph[P] extends Heuristic[P] { // reset solution solution = initialSolution - for (_ <- Range(0, depth)) { + var depthCounter: Int = 0 + while (depthCounter < depth && sampleCounter < samples) { + depthCounter += 1 + sampleCounter += 1 //get neighbourhood val Ns: Seq[Solution[P]] = panel.N(solution) @@ -40,7 +43,6 @@ class RandomGraph[P] extends Heuristic[P] { // get next element solution = Ns.apply(random.nextInt(Ns.size)) solutionValue = panel.f(solution) - sampleCounter += 1 solution }