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.

61 lines
2.3 KiB

6 years ago
  1. #!/usr/bin/env python3
  2. import randomSAT
  3. import kSAT
  4. import argparse
  5. import configparser
  6. import os
  7. def main():
  8. parser = argparse.ArgumentParser()
  9. parser.add_argument("-d", "--base_directory", help="the base directorey of the new dataset; should contain a dataset.config file", type=str)
  10. parser.add_argument("-i", "--instances", help="number of random kSAT instances", type=int)
  11. parser.add_argument("-v", "--variables", help="number of variables in ksat instances", type=int)
  12. parser.add_argument("-c", "--clauses", help="number of clauses in ksat instances", type=int)
  13. parser.add_argument("--variables_per_clause", help="variables per clause in ksat instances", type=int, default=3)
  14. parser.add_argument("-o", "--output", help="output directory", type=str)
  15. args = parser.parse_args()
  16. baseDir = args.base_directory
  17. if baseDir != None:
  18. config = __readConfig(os.path.join(baseDir, "dataset.config"));
  19. numberOfVariables = args.variables
  20. if numberOfVariables == None:
  21. numberOfVariables = int(input("Number of variables per instance: "))
  22. numberOfClauses = args.clauses
  23. if numberOfClauses == None:
  24. numberOfClauses = int(input("Number of clauses per instance: "))
  25. numberOfInstances = args.instances
  26. if numberOfInstances == None:
  27. numberOfInstances = int(input("Number of instances: "))
  28. instanceDir = None
  29. if "instance_dir" in config["STRUCTURE"]:
  30. instanceDir = os.path.join(baseDir, config["STRUCTURE"]["instance_dir"])
  31. elif args.output != None:
  32. instanceDir = args.output
  33. elif args.output == None:
  34. instanceDir = str(input("output directory: "))
  35. for i in range(numberOfInstances):
  36. ksatInstance = randomSAT.generateRandomKSAT(numberOfClauses,
  37. numberOfVariables,
  38. args.variables_per_clause)
  39. instanceFilePath = os.path.join(instanceDir, "instance_%d.dimacs" % (i))
  40. ksatInstance.writeDIMACS(instanceFilePath)
  41. def __readConfig(configFilePath):
  42. config = configparser.ConfigParser()
  43. if os.path.isfile(configFilePath):
  44. config.read(configFilePath)
  45. return config
  46. if __name__ == "__main__":
  47. main()