CombinatoryIntegerSolution.py 916 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. # main imports
  2. import numpy as np
  3. # modules imports
  4. from .Solution import Solution
  5. # Solution which stores solution data as combinatory integer array
  6. class CombinatoryIntegerSolution(Solution):
  7. def __init__(self, _data, _size):
  8. """
  9. Initialize data of solution using specific data
  10. - `data` field is array of integer values
  11. - `size` field is the size of array integer values
  12. """
  13. self.data = _data
  14. self.size = _size
  15. def random(self, _validator):
  16. """
  17. Intialize combinatory integer array using size solution data
  18. Use of validator to generate valid random solution
  19. """
  20. while not self.isValid(_validator):
  21. self.data = np.random.shuffle(np.arange(self.size))
  22. return self
  23. def __str__(self):
  24. return "Combinatory integer solution %s of size %s" % (self.data, self.size)