Example #1
0
    def test(self, f):
        self.case += 1
        self.tested += 1
        print("CASE %d: %s" % (self.case, f.toString()))
        cnf = CnfClause()
        try:
            start = now()
            cnf = f.toCnf()
            duration = now() - start
        except KeyboardInterrupt:
            raise KeyboardInterrupt()
        except:
            printException()
            if stopOnError:
                raise FailedTestException()
            return

        deg = self.formulaDeg(f)
        size = self.cnfSize(cnf)

        print('CNF: time: %12.9f   f.deg: %3d   cnf.size: %3d' %
              (duration, deg, size))

        if not isinstance(cnf, Cnf):
            print('FAILED: not a Cnf: %s' % type(cnf))
            print()
            return

        start = now()
        equiSatisfiable = self.satisfiableFormula(f) == self.satisfiableCnf(
            cnf)
        equivalent = self.formulaVars(f).issubset(self.cnfVars(cnf)) and \
                all(self.formulaEval(f, i) == self.cnfEval(cnf, i) for i in self.interpretations(self.cnfVars(cnf)))
        duration = now() - start

        if equivalent:
            self.equiv += 1

        self.size += size
        self.time += duration

        if equiSatisfiable:
            self.passed += 1
            print('PASSED: testTime: %12.9f    equiSatisfiable %s' %
                  (duration, 'equivalent' if equivalent else ''))
        else:
            if len(cnf) < 20:
                print('FAILED: \n-----CNF-----\n%s%s' %
                      (cnf.toString(), '-' * 13))
            else:
                print('FAILED: \n-----CNF-----\n%s...\n%s' %
                      (Cnf(cnf[:20]).toString(), '-' * 13))
            if stopOnError:
                raise FailedTestException()
        print()
Example #2
0
    def test(self, f):
        self.case += 1
        self.tested += 1
        print("CASE %d: %s" % (self.case, f.toString()))
        cnf = CnfClause()
        try:
            start = now()
            cnf = f.toCnf()
            duration = now() - start
        except KeyboardInterrupt:
            raise KeyboardInterrupt()
        except:
            printException()
            if stopOnError:
                raise FailedTestException()
            return

        deg = self.formulaDeg(f)
        size = self.cnfSize(cnf)

        print('CNF: time: %12.9f   f.deg: %3d   cnf.size: %3d' %
                (duration, deg, size))

        if not isinstance(cnf, Cnf):
            print('FAILED: not a Cnf: %s' % type(cnf))
            print()
            return

        start = now()
        equiSatisfiable = self.satisfiableFormula(f) == self.satisfiableCnf(cnf)
        equivalent = self.formulaVars(f).issubset(self.cnfVars(cnf)) and \
                all(self.formulaEval(f, i) == self.cnfEval(cnf, i) for i in self.interpretations(self.cnfVars(cnf)))
        duration = now() - start

        if equivalent:
            self.equiv += 1

        self.size += size
        self.time += duration

        if equiSatisfiable:
            self.passed += 1
            print('PASSED: testTime: %12.9f    equiSatisfiable %s' %
                    (duration, 'equivalent' if equivalent else ''))
        else:
            if len(cnf) < 20:
                print('FAILED: \n-----CNF-----\n%s%s' % (cnf.toString(), '-'*13))
            else:
                print('FAILED: \n-----CNF-----\n%s...\n%s' % (Cnf(cnf[:20]).toString(), '-'*13))
            if stopOnError:
                raise FailedTestException()
        print()
Example #3
0
 def testCnfClauseRead(self, dimacs, varMap, ecnf):
     iF = io.StringIO(dimacs)
     cnf = CnfClause.readFromFile(iF, varMap)
     self.compare(cnf.toString(), ecnf.toString(),
                  'CnfClause.readFromFile %s' % ecnf.toString())
Example #4
0
        }, True),
        ({
            'a': False
        }, False),
    ])

    t.testCnf(CnfLit.Not('a'), '-a', [
        ({
            'a': True
        }, False),
        ({
            'a': False
        }, True),
    ])

    t.testCnf(CnfClause([CnfLit('a'), CnfLit('a')]), 'a a', [
        ({
            'a': True
        }, True),
        ({
            'a': False
        }, False),
    ])

    t.testCnf(CnfClause([CnfLit('a'), CnfLit.Not('a')]), 'a -a', [
        ({
            'a': True
        }, True),
        ({
            'a': False
        }, True),
Example #5
0
 def testCnfClauseRead(self, dimacs, varMap, ecnf):
     iF = io.StringIO(dimacs)
     cnf = CnfClause.readFromFile(iF, varMap)
     self.compare(cnf.toString(), ecnf.toString(), 'CnfClause.readFromFile %s' % ecnf.toString())