Skip to content

Commit

Permalink
adjust random sampling
Browse files Browse the repository at this point in the history
  • Loading branch information
johanneslenfers committed Oct 24, 2024
1 parent 3152851 commit 62eb515
Showing 1 changed file with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,12 @@ class RandomGraph[P] extends Heuristic[P] {
val Ns: Seq[Solution[P]] = panel.N(solution)

// choose solution from neighborhood
solution = Ns.size match {
Ns.size match {

case 0 =>
// empty neighborhood
// abort this try and reset
depthCounter = depth
solution

// choose valid solution randomly from neighborhood
case _ =>
Expand All @@ -54,19 +53,19 @@ class RandomGraph[P] extends Heuristic[P] {
} else {
// get next element
sampleCounter += 1
solution = candidates.apply(random.nextInt(candidates.size))
solutionValue = panel.f(solution)

if (solutionValue.equals(None)) {
// add attempt
attempts += solution

} else {
foundValid = true
val candidate = candidates.apply(random.nextInt(candidates.size))
val candidateValue = panel.f(candidate)

candidateValue match {
case None =>
attempts += candidate
case Some(value) =>
foundValid = true
solution = candidate
solutionValue = candidateValue
}
}
}
solution
}
}
}
Expand Down

0 comments on commit 62eb515

Please sign in to comment.