IteratedLocalSearch.py 1.1 KB

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