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.

84 lines
2.7 KiB

6 years ago
5 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. #!/usr/bin/env python3
  2. from util import randomSAT
  3. from util import kSAT
  4. import util.script as scriptUtils
  5. import pymongo
  6. import ssl
  7. def main():
  8. args = __parseArguments()
  9. dbContext = scriptUtils.getDBContext(args["dbConfigPath"])
  10. __generateExperiment(args, dbContext)
  11. dbContext["client"].close()
  12. def __generateExperiment(args, dbContext):
  13. experimentScope = __prepareExperimentScope(args)
  14. for i in range(args["instances"]):
  15. sat = randomSAT.generateRandomKSAT(args["clauses"],
  16. args["variables"],
  17. args["variablesPerClause"])
  18. instanceId = dbContext["instances"].insert_one(__packDocument(sat)).inserted_id
  19. experimentScope["instances"].append(instanceId)
  20. dbContext["experimentScopes"].insert_one(experimentScope)
  21. def __packDocument(instance):
  22. doc = instance.writeJSONLike();
  23. return doc
  24. def __prepareExperimentScope(args):
  25. experimentScope = {}
  26. experimentScope["instances"] = []
  27. description = "This experiment contains %d instances " % args["instances"]
  28. description += "each with %d clauses, %d variables " % (args["clauses"],
  29. args["variables"])
  30. description += ("and %d variables per clause (c/v = %.2f)"
  31. %(args["variablesPerClause"],
  32. float(args["clauses"]) / float(args["variables"])))
  33. experimentScope["description"] = description
  34. experimentScope["_id"] = args["experimentId"].strip()
  35. return experimentScope
  36. def __parseArguments():
  37. parser = scriptUtils.ArgParser()
  38. parser.addArg(alias="instances", shortFlag="i", longFlag="instances",
  39. help="number of random kSAT instances", type=int)
  40. parser.addArg(alias="variables", shortFlag="v", longFlag="variables",
  41. help="number of variables in the ksat instances", type=int)
  42. parser.addArg(alias="clauses", shortFlag="c", longFlag="clauses",
  43. help="number of clauses in the ksat instances", type=int)
  44. parser.addArg(alias="variablesPerClause", shortFlag="vpc",
  45. longFlag="variables_per_clause",
  46. help="variables per clause in the kSAT instances", type=int,
  47. default=3)
  48. parser.addArg(alias="dbConfigPath", shortFlag="d", longFlag="db_config",
  49. help="path to the database config file", type=str,
  50. default="database.config")
  51. parser.addArg(alias="experimentId", shortFlag="id", longFlag="experiment_id",
  52. help="the name or id of the experiment", type=str)
  53. return parser.parse()
  54. if __name__ == "__main__":
  55. main()