Ejemplo n.º 1
0
 def __init__(self,
              n,
              rootName,
              verbose=False,
              includeCorners=False,
              bucketMode=1):
     self.n = n
     variableCount = 2 * n * (n - 1)
     if not includeCorners:
         variableCount -= 4
     self.verbose = verbose
     self.includeCorners = includeCorners
     self.bucketMode = bucketMode
     self.cnfWriter = writer.CnfWriter(variableCount, rootName,
                                       self.verbose)
     self.scheduleWriter = writer.ScheduleWriter(variableCount, rootName,
                                                 self.verbose)
     self.bucketWriter = writer.OrderWriter(variableCount,
                                            rootName,
                                            self.verbose,
                                            suffix="buckets")
     self.orderWriter = writer.OrderWriter(variableCount, rootName,
                                           self.verbose)
     self.idDict = {}
     self.squares = {}
     self.variableCount = 0
     self.idList = []
Ejemplo n.º 2
0
 def __init__(self,
              n,
              rootName,
              verbose=False,
              includeCorners=False,
              m=None,
              fixedPoint=False):
     self.n = n
     self.m = self.n if m is None else m
     self.fixedPoint = fixedPoint
     variableCount = self.m * (self.n - 1) + self.n * (self.m - 1)
     if not includeCorners:
         if self.fixedPoint:
             variableCount -= 2
         else:
             variableCount -= 4
     self.verbose = verbose
     self.includeCorners = includeCorners
     self.cnfWriter = writer.CnfWriter(variableCount, rootName,
                                       self.verbose)
     self.scheduleWriter = writer.ScheduleWriter(variableCount, rootName,
                                                 self.verbose)
     self.orderWriter = writer.OrderWriter(variableCount, rootName,
                                           self.verbose)
     self.idDict = {}
     self.squares = {}
     self.variableCount = 0
Ejemplo n.º 3
0
 def __init__(self, n, rootName, verbose=False):
     self.n = n
     variableCount = (n + 1) * n + n * n
     self.verbose = verbose
     self.cnfWriter = writer.CnfWriter(variableCount, rootName,
                                       self.verbose)
     self.scheduleWriter = writer.ScheduleWriter(variableCount, rootName,
                                                 self.verbose)
     self.orderWriter = writer.OrderWriter(variableCount, rootName,
                                           self.verbose)
     self.idDict = {}
     self.positions = {}
     self.variableCount = 0
Ejemplo n.º 4
0
 def __init__(self, count, rootName, verbose=False):
     self.verbose = verbose
     self.inputCount = count
     # Leaves + 2 binary trees
     fullCount = 3 * count - 2
     self.leafTrees = [Node(v) for v in range(1, count + 1)]
     self.variableCount = count
     self.roots = []
     self.modes = []
     self.cnfWriter = writer.CnfWriter(fullCount, rootName, self.verbose)
     self.scheduleWriter = writer.ScheduleWriter(fullCount, rootName,
                                                 self.verbose)
     self.orderWriter = writer.OrderWriter(fullCount, rootName,
                                           self.verbose)
Ejemplo n.º 5
0
 def __init__(self, n, rootName, verbose = False):
     self.n = n
     if self.n > 2:
         tvarPerHole = int((n-2)/2 if n%2== 0 else (n-1)/2)
     else:
         tvarPerHole = 0
     variableCount = n*(n+1) + tvarPerHole * n
     self.verbose = verbose
     self.cnfWriter = writer.CnfWriter(variableCount, rootName, self.verbose)
     self.scheduleWriter = writer.ScheduleWriter(variableCount, rootName, self.verbose)
     self.orderWriter = writer.OrderWriter(variableCount, rootName, self.verbose)
     self.idDict = {}
     self.positions = {}
     self.pindexList = [p for p in range(self.n) if p % 2 == 0]
     self.variableCount = 0
Ejemplo n.º 6
0
def run(name, args):
    N = 2
    root = None
    verbose = False
    invert = False
    tseitinMode = Manager.tseitinEnd
    optlist, args = getopt.getopt(args, "hvit:n:r:")
    for (opt, val) in optlist:
        if opt == '-h':
            usage(name)
            return
        elif opt == '-v':
            verbose = True
        elif opt == '-i':
            invert = True
        elif opt == '-t':
            if val == 'b':
                tseitinMode = Manager.tseitinBefore
            elif val == 'a':
                tseitinMode = Manager.tseitinAfter
            elif val == 'e':
                tseitinMode = Manager.tseitinEnd
            else:
                print("Unknown Tseitin variable placement mode '%s'" % val)
                usage(name)
                return
        elif opt == '-n':
            N = int(val)
        elif opt == '-r':
            root = val
    if root is None:
        print("Must have output file root name")
        usage(name)
        return
    qwrite = writer.QcnfWriter(root)
    manager = Manager(qwrite, verbose, tseitinMode)
    domino = Domino(manager, N, invert)
    domino.buildQcnf()
    vwrite = writer.OrderWriter(manager.variableCount, root, verbose=verbose)
    domino.listVariables(vwrite)
Ejemplo n.º 7
0
def run(name, args):
    profile = []
    root = None
    verbose = False
    tseitinMode = Manager.tseitinEnd
    encodingMode = Move.encodingUnary
    variableMode = None
    optlist, args = getopt.getopt(args, "hve:t:V:p:r:")
    for (opt, val) in optlist:
        if opt == '-h':
            usage(name)
            return
        elif opt == '-v':
            verbose = True
        elif opt == '-e':
            if val == 'u':
                encodingMode = Move.encodingUnary
            elif val == 'o':
                encodingMode = Move.encodingObject
            else:
                print("Unknown Tseitin bucket encoding mode '%s'" % val)
                usage(name)
                return
        elif opt == '-t':
            if val == 'b':
                tseitinMode = Manager.tseitinBefore
            elif val == 'a':
                tseitinMode = Manager.tseitinAfter
            elif val == 'e':
                tseitinMode = Manager.tseitinEnd
            else:
                print("Unknown Tseitin variable placement mode '%s'" % val)
                usage(name)
                return
        elif opt == '-V':
            if val == 'm':
                variableMode = Nim.moveMajor
            elif val == 'b':
                variableMode = Nim.bucketMajor
            elif val == 'o':
                variableMode = Nim.objectMajor
            else:
                print("Unknown variable ordering strategy '%s'" % val)
                usage(name)
                return
        elif opt == '-p':
            pfields = val.split('+')
            try:
                profile = [int(s) for s in pfields]
            except:
                print("Couldn't parse profile '%s'" % val)
                usage(name)
                return
            if sum(profile) == 0:
                print("invalid profile '%s'" % val)
                return
        elif opt == '-r':
            root = val
    if profile is None:
        print("Must have profile")
        usage(name)
        return
    if root is None:
        print("Must have output file root name")
        usage(name)
        return
    qwrite = writer.QcnfWriter(root)
    manager = Manager(qwrite, verbose, tseitinMode)
    nim = Nim(manager, profile, encodingMode)
    nim.buildQcnf()

    if variableMode is not None:
        vwrite = writer.OrderWriter(manager.variableCount, root, verbose=verbose)
        nim.listVariables(variableMode, vwrite)