|
|
@ -3,19 +3,35 @@ |
|
|
|
from util import randomSAT |
|
|
|
from util import kSAT |
|
|
|
import util.script as scriptUtils |
|
|
|
import h5py |
|
|
|
import numpy as np |
|
|
|
import pymongo |
|
|
|
import ssl |
|
|
|
|
|
|
|
def main(): |
|
|
|
args = __parseArguments() |
|
|
|
|
|
|
|
dbClient = __getDBClient(args["dbConfigPath"]); |
|
|
|
db = dbClient["experiments"] |
|
|
|
dbInstances = db["instances"] |
|
|
|
dbExperimentScopes = db["experiment_scopes"] |
|
|
|
|
|
|
|
dbContext = __getDBContext(args["dbConfigPath"]) |
|
|
|
|
|
|
|
__generateExperiment(args, dbContext) |
|
|
|
|
|
|
|
dbContext["client"].close() |
|
|
|
|
|
|
|
def __generateExperiment(args, dbContext): |
|
|
|
experimentScope = __prepareExperimentScope(args) |
|
|
|
|
|
|
|
for i in range(args["instances"]): |
|
|
|
sat = randomSAT.generateRandomKSAT(args["clauses"], |
|
|
|
args["variables"], |
|
|
|
args["variablesPerClause"]) |
|
|
|
|
|
|
|
instanceId = dbContext["instances"].insert_one(sat.writeJSONLike()).inserted_id |
|
|
|
|
|
|
|
experimentScope["instances"].append(instanceId) |
|
|
|
|
|
|
|
dbContext["experimentScopes"].insert_one(experimentScope) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def __prepareExperimentScope(args): |
|
|
|
experimentScope = {} |
|
|
|
experimentScope["instances"] = [] |
|
|
|
|
|
|
@ -28,21 +44,8 @@ def main(): |
|
|
|
|
|
|
|
experimentScope["description"] = description |
|
|
|
|
|
|
|
return experimentScope |
|
|
|
|
|
|
|
for i in range(args["instances"]): |
|
|
|
print("loop", i) |
|
|
|
|
|
|
|
sat = randomSAT.generateRandomKSAT(args["clauses"], |
|
|
|
args["variables"], |
|
|
|
args["variablesPerClause"]) |
|
|
|
|
|
|
|
instanceId = dbInstances.insert_one(sat.writeJSONLike()).inserted_id |
|
|
|
|
|
|
|
experimentScope["instances"].append(instanceId) |
|
|
|
|
|
|
|
dbExperimentScopes.insert_one(experimentScope) |
|
|
|
|
|
|
|
dbClient.close() |
|
|
|
|
|
|
|
def __getDBClient(dbConfigPath): |
|
|
|
dbConf = scriptUtils.readConfig(dbConfigPath) |
|
|
@ -58,6 +61,17 @@ def __getDBClient(dbConfigPath): |
|
|
|
ssl=True, |
|
|
|
ssl_cert_reqs=ssl.CERT_NONE) |
|
|
|
|
|
|
|
|
|
|
|
def __getDBContext(dbConfigPath): |
|
|
|
dbContext = {} |
|
|
|
|
|
|
|
dbContext["client"] = __getDBClient(dbConfigPath) |
|
|
|
dbContext["db"] = dbContext["client"]["experiments"] |
|
|
|
dbContext["instances"] = dbContext["db"]["instances"] |
|
|
|
dbContext["experimentScopes"] = dbContext["db"]["experiment_scopes"] |
|
|
|
|
|
|
|
return dbContext |
|
|
|
|
|
|
|
def __parseArguments(): |
|
|
|
parser = scriptUtils.ArgParser() |
|
|
|
|
|
|
@ -84,17 +98,5 @@ def __parseArguments(): |
|
|
|
|
|
|
|
return parser.parse() |
|
|
|
|
|
|
|
def __initFile(args): |
|
|
|
f = h5py.File(args["fileName"], "w") |
|
|
|
|
|
|
|
__SAT_TYPE__ = np.dtype([('bindings', (np.int32, (args["clauses"], |
|
|
|
args["variablesPerClause"])))]) |
|
|
|
|
|
|
|
instances = f.create_dataset(name="instances", |
|
|
|
shape=(args["instances"],), |
|
|
|
dtype=__SAT_TYPE__) |
|
|
|
|
|
|
|
return f, __SAT_TYPE__ |
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
|
main() |