IteratedLocalSearch.py 998 B

123456789101112131415161718192021222324252627282930313233
  1. # module imports
  2. from .Algorithm import Algorithm
  3. from.LocalSearch import LocalSearch
  4. class IteratedLocalSearch(Algorithm):
  5. def run(self, _evaluations):
  6. # by default use of mother method to initialize variables
  7. super().run(_evaluations)
  8. ls = LocalSearch(self.initializer, self.evaluator, self.updators, self.policy, self.validator, self.maximise)
  9. # local search algorithm implementation
  10. while self.numberOfEvaluations < self.maxEvalutations:
  11. # create and search solution from local search
  12. newSolution = ls.run(100)
  13. # if better solution than currently, replace it
  14. if self.isBetter(newSolution):
  15. self.bestSolution = newSolution
  16. # increase number of evaluations
  17. self.numberOfEvaluations += 100
  18. print(self.progress())
  19. print(self.information())
  20. print("End of local search algorithm..")
  21. return self.bestSolution