Browse Source

sync

master
Tom 6 years ago
parent
commit
1e1b527566
21 changed files with 177 additions and 28 deletions
  1. +4
    -0
      .gitignore
  2. +1
    -1
      collectCmpStatus.py
  3. +4
    -4
      compareMinisatAndWMISresult.py
  4. +2
    -2
      compareRuns.py
  5. +1
    -1
      comparisonStats.py
  6. +2
    -2
      generateRandomKsatDataSet.py
  7. +100
    -0
      generateRandomKsatDataSet_db.py
  8. +32
    -0
      runMinisatOnDataset.py
  9. +4
    -4
      runWMISquboOnSatInstance.py
  10. +1
    -1
      satUnsatConflictsPerVariableStats.py
  11. +2
    -2
      testMinisatResults.py
  12. +2
    -1
      testRandomSat.py
  13. +2
    -2
      testSAT2QUBO.py
  14. +1
    -1
      util/SAT2QUBO.py
  15. +1
    -1
      util/SATquboResult.py
  16. +0
    -0
      util/__init__.py
  17. +14
    -1
      util/kSAT.py
  18. +0
    -0
      util/minisat.py
  19. +1
    -1
      util/randomSAT.py
  20. +1
    -2
      util/script.py
  21. +2
    -2
      verifyWMISresult.py

+ 4
- 0
.gitignore View File

@ -94,3 +94,7 @@ ENV/
# Rope project settings # Rope project settings
.ropeproject .ropeproject
#### config files
#
database.config

+ 1
- 1
collectCmpStatus.py View File

@ -7,7 +7,7 @@ import json
import numpy as np import numpy as np
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import configparser import configparser
import scriptUtils
from util import script as scriptUtils
def main(): def main():
args = __parseArguments() args = __parseArguments()


+ 4
- 4
compareMinisatAndWMISresult.py View File

@ -1,10 +1,10 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import SATquboResult
from util import SATquboResult
import argparse import argparse
from kSAT import kSAT
import minisatUtils as mSatU
import SATquboResult
from util.kSAT import kSAT
from util import minisat as mSatU
from util import SATquboResult
import os import os
import json import json


+ 2
- 2
compareRuns.py View File

@ -1,7 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import scriptUtils
import compare
from util import script as scriptUtils
from util import compare
import glob import glob
import os import os


+ 1
- 1
comparisonStats.py View File

@ -7,7 +7,7 @@ import json
import numpy as np import numpy as np
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import configparser import configparser
import scriptUtils
import util.script as scriptUtils
def main(): def main():
args = __parseArguments() args = __parseArguments()


+ 2
- 2
generateRandomKsatDataSet.py View File

@ -1,7 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import randomSAT
import kSAT
from util import randomSAT
from util import kSAT
import argparse import argparse
import configparser import configparser
import os import os


+ 100
- 0
generateRandomKsatDataSet_db.py View File

@ -0,0 +1,100 @@
#!/usr/bin/env python3
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"]
experimentScope = {}
experimentScope["instances"] = []
description = "This experiment contains %d instances " % args["instances"]
description += "each with %d clauses, %d variables " % (args["clauses"],
args["variables"])
description += ("and %d variables per clause (c/v = %.2f)"
%(args["variablesPerClause"],
float(args["clauses"]) / float(args["variables"])))
experimentScope["description"] = description
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)
dbConf["CONNECTION"]
return pymongo.MongoClient(
"mongodb://%s:%s@%s:%s/%s"
% ( dbConf["CONNECTION"]["user"],
dbConf["CONNECTION"]["pw"],
dbConf["CONNECTION"]["url"],
dbConf["CONNECTION"]["port"],
dbConf["CONNECTION"]["database"]),
ssl=True,
ssl_cert_reqs=ssl.CERT_NONE)
def __parseArguments():
parser = scriptUtils.ArgParser()
parser.addArg(alias="instances", shortFlag="i", longFlag="instances",
help="number of random kSAT instances", type=int,
ignoreDatabaseConfig=True)
parser.addArg(alias="variables", shortFlag="v", longFlag="variables",
help="number of variables in the ksat instances", type=int,
ignoreDatabaseConfig=True)
parser.addArg(alias="clauses", shortFlag="c", longFlag="clauses",
help="number of clauses in the ksat instances", type=int,
ignoreDatabaseConfig=True)
parser.addArg(alias="variablesPerClause", shortFlag="vpc",
longFlag="variables_per_clause",
help="variables per clause in the kSAT instances", type=int,
default=3, ignoreDatabaseConfig=True)
parser.addArg(alias="dbConfigPath", shortFlag="d", longFlag="db_config",
help="path to the database config file", type=str,
default="database.config", ignoreDatabaseConfig=True)
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()

+ 32
- 0
runMinisatOnDataset.py View File

@ -0,0 +1,32 @@
#!/usr/bin/env python3
from util import script as scrUt
import configparser
import os
def main():
args = __parseArgs()
print(args)
def __parseArguments():
parser = scrUt.ArgParser()
parser.addInstanceDirArg()
parser.addArg(alias="instanceDir", shortFlag="i", longFlag="instance_dir",
help="the directory with all instance files", type=str)
parser.addArg(alias="outputDir", shortFlag="o", longFlag="output_dir",
help="the directory to store the minisat results for each instance",
type=str)
parser.addArg(alias="configFile", shortFlag="c", longFlag="config",
help="config file (default: ./satlab.config)",
type=str, default=os.path.join(".", "satlab.config"))
arguments = parser.parse()
if __name__ == "__main__":
main()

+ 4
- 4
runWMISquboOnSatInstance.py View File

@ -1,15 +1,15 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import kSAT
import SAT2QUBO
from SATquboResult import SATquboResult
from util import kSAT
from util import SAT2QUBO
from util.SATquboResult import SATquboResult
import argparse import argparse
from dwave_qbsolv import QBSolv from dwave_qbsolv import QBSolv
import os import os
import collections import collections
import json import json
from tqdm import tqdm from tqdm import tqdm
import scriptUtils
from util import script as scriptUtils
def main(): def main():
arguments = __parseArguments() arguments = __parseArguments()


+ 1
- 1
satUnsatConflictsPerVariableStats.py View File

@ -7,7 +7,7 @@ import json
import numpy as np import numpy as np
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import collections import collections
import scriptUtils
from script import script as scriptUtils
def main(): def main():
args = __parseArguments() args = __parseArguments()


+ 2
- 2
testMinisatResults.py View File

@ -1,7 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import kSAT
import minisatUtils as mSatU
from util import kSAT
from util import minisat as mSatU
import argparse import argparse


+ 2
- 1
testRandomSat.py View File

@ -1,6 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import randomSAT as rdSAT
from util import randomSAT as rdSAT
kSATInstance = rdSAT.generateRandomKSAT(5, 4, 3) kSATInstance = rdSAT.generateRandomKSAT(5, 4, 3)


+ 2
- 2
testSAT2QUBO.py View File

@ -1,7 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import SAT2QUBO as s2q
import randomSAT as rs
from util import SAT2QUBO as s2q
from util import randomSAT as rs
ksatInstance = rs.generateRandomKSAT(2, 4, 3) ksatInstance = rs.generateRandomKSAT(2, 4, 3)


+ 1
- 1
util/SAT2QUBO.py View File

@ -1,7 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import numpy as np import numpy as np
import kSAT
from . import kSAT
from tqdm import tqdm from tqdm import tqdm
import math import math


+ 1
- 1
util/SATquboResult.py View File

@ -1,5 +1,5 @@
import json import json
from kSAT import kSAT
from .kSAT import kSAT
class SATquboResult: class SATquboResult:


+ 0
- 0
util/__init__.py View File


+ 14
- 1
util/kSAT.py View File

@ -150,7 +150,20 @@ class kSAT:
line = inputFile.readline() line = inputFile.readline()
inputFile.close() inputFile.close()
def writeJSONLike(self):
jsonLike = {}
jsonLike["clauses"] = self.__clauses
return jsonLike
def readJSONLike(self, jsonLike):
self.reset()
for clause in jsonLike["clauses"]:
self.addClause(clause)
def reset(self): def reset(self):
self.__clauses = [] self.__clauses = []


util/minisatUtils.py → util/minisat.py View File


+ 1
- 1
util/randomSAT.py View File

@ -2,7 +2,7 @@
import numpy as np import numpy as np
import random import random
import kSAT
from . import kSAT
def generateRandomKSAT(numberOfClauses, def generateRandomKSAT(numberOfClauses,
numberOfVariables, numberOfVariables,


util/scriptUtils.py → util/script.py View File

@ -54,8 +54,7 @@ class ArgParser:
if self.__instanceDirArgSet: if self.__instanceDirArgSet:
self.__config = readConfig(os.path.join(args["dataset_dir"], self.__config = readConfig(os.path.join(args["dataset_dir"],
"dataset.config")) "dataset.config"))
self.__parseDatasetConfig()
self.__parseDatasetConfig()
for alias, flag in self.__flags.items(): for alias, flag in self.__flags.items():
self.__parsedArgs[alias] = self.__processFlag(args, flag) self.__parsedArgs[alias] = self.__processFlag(args, flag)

+ 2
- 2
verifyWMISresult.py View File

@ -1,7 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
from kSAT import kSAT
import SATquboResult
from util.kSAT import kSAT
from util import SATquboResult
import argparse import argparse
def main(): def main():


Loading…
Cancel
Save