Checkpoint.py 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. """Abstract Checkpoint class
  2. """
  3. # main imports
  4. import os
  5. import logging
  6. from abc import abstractmethod
  7. class Checkpoint():
  8. """
  9. Local Search used as exploitation optimization algorithm
  10. Attributes:
  11. algo: {Algorithm} -- main algorithm instance reference
  12. every: {int} -- checkpoint frequency used (based on number of evaluations)
  13. filepath: {str} -- file path where checkpoints will be saved
  14. """
  15. def __init__(self, _algo, _every, _filepath):
  16. self.algo = _algo
  17. self.every = _every
  18. self.filepath = _filepath
  19. # build path if not already exists
  20. head, _ = os.path.split(self.filepath)
  21. if not os.path.exists(head):
  22. os.makedirs(head)
  23. @abstractmethod
  24. def run(self):
  25. """
  26. Check if necessary to do backup based on `every` variable
  27. """
  28. pass
  29. @abstractmethod
  30. def load(self):
  31. """
  32. Load last backup line of solution and set algorithm state at this backup
  33. """
  34. pass