You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
2.2 KiB

5 years ago
  1. #!/usr/bin/env python3
  2. from . import randomSAT
  3. class Random_instance_pool:
  4. def __init__(self, parameter_range):
  5. self.__parameter_range = parameter_range
  6. def __iter__(self):
  7. return self
  8. def __next__(self):
  9. params = self.__parameter_range.next()
  10. return randomSAT.generateRandomKSAT(params.number_of_clauses,
  11. params.number_of_variables,
  12. params.variables_per_clause)
  13. class Instance_parameters:
  14. def __init__(self,
  15. number_of_clauses,
  16. number_of_variables,
  17. variables_per_clause = 3):
  18. self.number_of_clauses = number_of_clauses
  19. self.number_of_variables = number_of_variables
  20. self.variables_per_clause = variables_per_clause
  21. def __str__(self):
  22. return ("number of clauses: {}\n"
  23. "number of variables: {}\n"
  24. "variables per clause: {}").format(self.number_of_clauses,
  25. self.number_of_variables,
  26. self.variables_per_clause)
  27. class Instance_parameter_variable_range:
  28. def __init__(self, start_parameter, variable_range):
  29. self.start_parameter = start_parameter
  30. self.__variable_range = variable_range
  31. def __iter__(self):
  32. return self
  33. def __next__(self):
  34. self.start_parameter.number_of_variables = self.__variable_range.next()
  35. return self.start_parameter
  36. def next(self):
  37. return self.__next__()
  38. class Manual_range:
  39. def __init__(self, start, stop, step = 1):
  40. self.start = start
  41. self.stop = stop
  42. self.step = step
  43. self.__current = start
  44. def __iter__(self):
  45. return self
  46. def __next__(self):
  47. if self.__current >= self.stop:
  48. raise StopIteration
  49. self.__current += self.step
  50. return self.__current
  51. def next(self):
  52. return self.__next__()