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.

87 lines
2.4 KiB

5 years ago
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. return self.Random(self.__parameter_range.next())
  10. class Random:
  11. def __init__(self, parameters):
  12. self.__params = parameters
  13. def random(self):
  14. return randomSAT.generateRandomKSAT(self.__params.number_of_clauses,
  15. self.__params.number_of_variables,
  16. self.__params.variables_per_clause)
  17. class Instance_parameters:
  18. def __init__(self,
  19. number_of_clauses,
  20. number_of_variables,
  21. variables_per_clause = 3):
  22. self.number_of_clauses = number_of_clauses
  23. self.number_of_variables = number_of_variables
  24. self.variables_per_clause = variables_per_clause
  25. def __str__(self):
  26. return ("number of clauses: {}\n"
  27. "number of variables: {}\n"
  28. "variables per clause: {}").format(self.number_of_clauses,
  29. self.number_of_variables,
  30. self.variables_per_clause)
  31. class Instance_parameter_variable_range:
  32. def __init__(self, start_parameter, variable_range):
  33. self.start_parameter = start_parameter
  34. self.__variable_range = variable_range
  35. def __iter__(self):
  36. return self
  37. def __next__(self):
  38. self.start_parameter.number_of_variables = self.__variable_range.next()
  39. return self.start_parameter
  40. def next(self):
  41. return self.__next__()
  42. class Manual_range:
  43. def __init__(self, start, stop, step = 1):
  44. self.start = start
  45. self.stop = stop
  46. self.step = step
  47. self.__current = start
  48. def __iter__(self):
  49. return self
  50. def __next__(self):
  51. if self.__current >= self.stop:
  52. raise StopIteration
  53. self.__current += self.step
  54. return self.__current
  55. def next(self):
  56. return self.__next__()