Skip to content

Commit

Permalink
added limit to local search graph
Browse files Browse the repository at this point in the history
  • Loading branch information
johanneslenfers committed Oct 6, 2022
1 parent 361c68d commit 7bb268f
Showing 1 changed file with 33 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,50 @@ class LocalSearchGraph[P] extends Heuristic[P] {
var old_solution = solution
// var min: Option[Double] = solutionValue

var total = 0

val random = scala.util.Random

// later:
// don't allow duplicates
// save position and action
// save position and action?

do {
//get neighbourhood
val Ns: Seq[Solution[P]] = panel.N(solution)

// evaluate neighborhood and get minimum
old_solution = solution
solution = Ns.reduceLeft((a, b) => min(panel, a, b))
solutionValue = panel.f(solution)
var i = 0
println("start inner loop: " + Ns.size)
while (i < Ns.size && total < samples) {
println("i: " + i)

val candidate = Ns.apply(i)
val candidateValue = panel.f(candidate)

// check for new minimum
val result = candidateValue match {
case Some(candidateValue) => solutionValue match {
case Some(solutionValue) if candidateValue < solutionValue => (candidate, Some(candidateValue))
case Some(solutionValue) => (solution, Some(solutionValue))
case None => (candidate, Some(candidateValue))
}
case None => solutionValue match {
case Some(solutionValue) => (solution, Some(solutionValue))
case None => (solution, None)
}
}
solution = result._1
solutionValue = result._2

// update counter
total += 1
i += 1
}

// solution = Ns.reduceLeft((a, b) => min(panel, a, b))
// solutionValue = panel.f(solution)

// end loop if no new element was found
} while (!old_solution.equals(solution))
Expand Down

0 comments on commit 7bb268f

Please sign in to comment.