description.rst.txt 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. Description
  2. =====================================
  3. .. image:: _static/logo_macop.png
  4. :width: 350 px
  5. :align: center
  6. Context
  7. ------------
  8. `macop` is an optimization Python package which not implement the whole available algorithms in the literature but let you the possibility to quickly develop and test your own algorithm and strategies. The main objective of this package is to be the most flexible as possible and hence, to offer a maximum of implementation possibilities.
  9. Installation
  10. ------------
  11. Just install package using `pip` Python package manager:
  12. .. code:: bash
  13. pip install macop
  14. How to use ?
  15. ------------
  16. Load all `macop` implemented features:
  17. .. code:: python
  18. from macop.algorithms.IteratedLocalSearch import IteratedLocalSearch as ILS
  19. from macop.solutions.BinarySolution import BinarySolution
  20. from macop.evaluators.EvaluatorExample import evaluatorExample
  21. from macop.operators.mutators.SimpleMutation import SimpleMutation
  22. from macop.operators.mutators.SimpleBinaryMutation import SimpleBinaryMutation
  23. from macop.operators.crossovers.SimpleCrossover import SimpleCrossover
  24. from macop.operators.crossovers.RandomSplitCrossover import RandomSplitCrossover
  25. from macop.operators.policies.RandomPolicy import RandomPolicy
  26. from macop.checkpoints.BasicCheckpoint import BasicCheckpoint
  27. # logging configuration
  28. logging.basicConfig(format='%(asctime)s %(message)s', filename='example.log', level=logging.DEBUG)
  29. # default validator
  30. def validator(solution):
  31. return True
  32. # define init random solution
  33. def init():
  34. return BinarySolution([], 30).random(validator)
  35. filepath = "checkpoints.csv"
  36. def main():
  37. operators = [SimpleBinaryMutation(), SimpleMutation(), SimpleCrossover(), RandomSplitCrossover()]
  38. policy = RandomPolicy(operators)
  39. algo = ILS(init, evaluatorExample, operators, policy, validator, True)
  40. algo.addCheckpoint(_class=BasicCheckpoint, _every=5, _filepath=filepath)
  41. bestSol = algo.run(425)
  42. print("Found ", bestSol)
  43. if __name__ == "__main__":
  44. main()