CombinatoryIntegerSolution.py 955 B

12345678910111213141516171819202122232425262728293031323334353637383940
  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. self.data = np.random.shuffle(np.arange(self.size))
  21. while not self.isValid(_validator):
  22. self.data = np.random.shuffle(np.arange(self.size))
  23. return self
  24. def __str__(self):
  25. return "Combinatory integer solution %s" % (self.data)