|
|
@ -23,13 +23,52 @@ def __generateExperiment(args, dbContext): |
|
|
|
args["variables"], |
|
|
|
args["variablesPerClause"]) |
|
|
|
|
|
|
|
instanceId = dbContext["instances"].insert_one(sat.writeJSONLike()).inserted_id |
|
|
|
|
|
|
|
instanceId = dbContext["instances"].insert_one(__packDocument(sat)).inserted_id |
|
|
|
|
|
|
|
experimentScope["instances"].append(instanceId) |
|
|
|
|
|
|
|
dbContext["experimentScopes"].insert_one(experimentScope) |
|
|
|
|
|
|
|
def __packDocument(instance): |
|
|
|
doc = instance.writeJSONLike(); |
|
|
|
|
|
|
|
doc["degrees_of_variables"] = __packDegreesOfVariables(instance) |
|
|
|
|
|
|
|
doc["conflicts"] = __packConflicts(instance) |
|
|
|
|
|
|
|
return doc |
|
|
|
|
|
|
|
def __packDegreesOfVariables(instance): |
|
|
|
doc = [] |
|
|
|
|
|
|
|
for var, degree in instance.getDegreesOfVariables().items(): |
|
|
|
doc.append({"var": var, "deg": degree}) |
|
|
|
|
|
|
|
return doc |
|
|
|
|
|
|
|
def __packConflicts(instance): |
|
|
|
doc = [{"var": i + 1, |
|
|
|
"clauses": { |
|
|
|
"pos_lit": [], |
|
|
|
"neg_lit": []}} for i in range(instance.getNumberOfVariables())] |
|
|
|
|
|
|
|
for conflict in instance.getConflicts(): |
|
|
|
|
|
|
|
for binding in conflict: |
|
|
|
clause = binding[0] |
|
|
|
lit = binding[1] |
|
|
|
varIndex = abs(lit) - 1 |
|
|
|
|
|
|
|
if lit > 0: |
|
|
|
if clause not in doc[varIndex]["clauses"]["pos_lit"]: |
|
|
|
doc[varIndex]["clauses"]["pos_lit"].append(clause) |
|
|
|
else: |
|
|
|
if clause not in doc[varIndex]["clauses"]["neg_lit"]: |
|
|
|
doc[varIndex]["clauses"]["neg_lit"].append(clause) |
|
|
|
|
|
|
|
|
|
|
|
return doc |
|
|
|
|
|
|
|
def __prepareExperimentScope(args): |
|
|
|
experimentScope = {} |
|
|
|