mainExample.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. # main imports
  2. import logging
  3. # module imports
  4. # Note: you need to import from folder dependency name
  5. # examples: `from optimization.solutions.BinarySolution import BinarySolution`
  6. from optimization.algorithms.IteratedLocalSearch import IteratedLocalSearch as ILS
  7. from optimization.solutions.BinarySolution import BinarySolution
  8. from optimization.evaluators.EvaluatorExample import evaluatorExample
  9. from optimization.updators.mutators.SimpleMutation import SimpleMutation, SimpleBinaryMutation
  10. from optimization.updators.policies.RandomPolicy import RandomPolicy
  11. # logging configuration
  12. logging.basicConfig(format='%(asctime)s %(message)s', filename='example.log', level=logging.DEBUG)
  13. # default validator
  14. def validator(solution):
  15. return True
  16. # define init random solution
  17. def init():
  18. return BinarySolution([], 30).random(validator)
  19. def main():
  20. updators = [SimpleBinaryMutation, SimpleMutation]
  21. policy = RandomPolicy(updators)
  22. algo = ILS(init, evaluatorExample, updators, policy, validator, True)
  23. bestSol = algo.run(100000)
  24. print("Found ", bestSol)
  25. if __name__ == "__main__":
  26. main()