BinarySolution.py 738 B

123456789101112131415161718192021222324252627282930313233
  1. # main imports
  2. import numpy as np
  3. # modules imports
  4. from .Solution import Solution
  5. # Solution which stores solution data as binary array
  6. class BinarySolution(Solution):
  7. def __init__(self, _data, _size):
  8. """
  9. Initialize data of solution using specific data
  10. - `data` field is array of binary values
  11. - `size` field is the size of array binary values
  12. """
  13. self.data = _data
  14. self.size = _size
  15. def random(self):
  16. """
  17. Intialize binary array using size solution data
  18. """
  19. self.data = np.random.randint(2, size=self.size)
  20. return self
  21. def __str__(self):
  22. return "Binary solution %s of size %s" % (self.data, self.size)