Example #1
0
        public void testEquals()
        {
            Clause clause1 = new Clause();
            Clause clause2 = new Clause();

            Assert.IsTrue(clause1.Equals(clause2));

            clause1 = new Clause(LITERAL_P);
            clause2 = new Clause(LITERAL_P);
            Assert.IsTrue(clause1.Equals(clause2));

            clause1 = new Clause(LITERAL_P, LITERAL_Q);
            clause2 = new Clause(LITERAL_P, LITERAL_Q);
            Assert.IsTrue(clause1.Equals(clause2));

            clause1 = new Clause(LITERAL_R, LITERAL_P, LITERAL_Q);
            clause2 = new Clause(LITERAL_P, LITERAL_Q, LITERAL_R);
            Assert.IsTrue(clause1.Equals(clause2));

            clause1 = new Clause(LITERAL_P);
            clause2 = new Clause(LITERAL_Q);
            Assert.IsFalse(clause1.Equals(clause2));

            clause1 = new Clause(LITERAL_P, LITERAL_Q);
            clause2 = new Clause(LITERAL_P, LITERAL_R);
            Assert.IsFalse(clause1.Equals(clause2));

            clause1 = new Clause(LITERAL_P);
            Assert.IsFalse(clause1.Equals(LITERAL_P));
        }
Example #2
0
        public void testComplexEquals()
        {
            FOLDomain domain = new FOLDomain();

            domain.addConstant("A");
            domain.addConstant("B");
            domain.addConstant("C");
            domain.addConstant("D");
            domain.addPredicate("P");
            domain.addPredicate("Animal");
            domain.addPredicate("Kills");
            domain.addFunction("F");
            domain.addFunction("SF0");

            FOLParser parser = new FOLParser(domain);

            CNFConverter cnfConverter = new CNFConverter(parser);
            Sentence     s1           = parser.parse("((x1 = y1 AND y1 = z1) => x1 = z1)");
            Sentence     s2           = parser.parse("((x2 = y2 AND F(y2) = z2) => F(x2) = z2)");
            CNF          cnf1         = cnfConverter.convertToCNF(s1);
            CNF          cnf2         = cnfConverter.convertToCNF(s2);

            Clause c1 = cnf1.getConjunctionOfClauses().Get(0);
            Clause c2 = cnf2.getConjunctionOfClauses().Get(0);

            Assert.IsFalse(c1.Equals(c2));

            s1   = parser.parse("((x1 = y1 AND y1 = z1) => x1 = z1)");
            s2   = parser.parse("((x2 = y2 AND y2 = z2) => x2 = z2)");
            cnf1 = cnfConverter.convertToCNF(s1);
            cnf2 = cnfConverter.convertToCNF(s2);

            c1 = cnf1.getConjunctionOfClauses().Get(0);
            c2 = cnf2.getConjunctionOfClauses().Get(0);

            Assert.IsTrue(c1.Equals(c2));

            s1   = parser.parse("((x1 = y1 AND y1 = z1) => x1 = z1)");
            s2   = parser.parse("((y2 = z2 AND x2 = y2) => x2 = z2)");
            cnf1 = cnfConverter.convertToCNF(s1);
            cnf2 = cnfConverter.convertToCNF(s2);

            c1 = cnf1.getConjunctionOfClauses().Get(0);
            c2 = cnf2.getConjunctionOfClauses().Get(0);

            Assert.IsTrue(c1.Equals(c2));

            s1   = parser.parse("(((x1 = y1 AND y1 = z1) AND z1 = r1) => x1 = r1)");
            s2   = parser.parse("(((x2 = y2 AND y2 = z2) AND z2 = r2) => x2 = r2)");
            cnf1 = cnfConverter.convertToCNF(s1);
            cnf2 = cnfConverter.convertToCNF(s2);

            c1 = cnf1.getConjunctionOfClauses().Get(0);
            c2 = cnf2.getConjunctionOfClauses().Get(0);

            Assert.IsTrue(c1.Equals(c2));

            s1   = parser.parse("(((x1 = y1 AND y1 = z1) AND z1 = r1) => x1 = r1)");
            s2   = parser.parse("(((z2 = r2 AND y2 = z2) AND x2 = y2) => x2 = r2)");
            cnf1 = cnfConverter.convertToCNF(s1);
            cnf2 = cnfConverter.convertToCNF(s2);

            c1 = cnf1.getConjunctionOfClauses().Get(0);
            c2 = cnf2.getConjunctionOfClauses().Get(0);

            Assert.IsTrue(c1.Equals(c2));

            s1   = parser.parse("(((x1 = y1 AND y1 = z1) AND z1 = r1) => x1 = r1)");
            s2   = parser.parse("(((x2 = y2 AND y2 = z2) AND z2 = y2) => x2 = r2)");
            cnf1 = cnfConverter.convertToCNF(s1);
            cnf2 = cnfConverter.convertToCNF(s2);

            c1 = cnf1.getConjunctionOfClauses().Get(0);
            c2 = cnf2.getConjunctionOfClauses().Get(0);

            Assert.IsFalse(c1.Equals(c2));

            s1 = parser
                 .parse("(((((x1 = y1 AND y1 = z1) AND z1 = r1) AND r1 = q1) AND q1 = s1) => x1 = r1)");
            s2 = parser
                 .parse("(((((x2 = y2 AND y2 = z2) AND z2 = r2) AND r2 = q2) AND q2 = s2) => x2 = r2)");
            cnf1 = cnfConverter.convertToCNF(s1);
            cnf2 = cnfConverter.convertToCNF(s2);

            c1 = cnf1.getConjunctionOfClauses().Get(0);
            c2 = cnf2.getConjunctionOfClauses().Get(0);

            Assert.IsTrue(c1.Equals(c2));

            s1 = parser
                 .parse("((((NOT(Animal(c1920)) OR NOT(Animal(c1921))) OR NOT(Kills(c1922,c1920))) OR NOT(Kills(c1919,c1921))) OR NOT(Kills(SF0(c1922),SF0(c1919))))");
            s2 = parser
                 .parse("((((NOT(Animal(c1929)) OR NOT(Animal(c1928))) OR NOT(Kills(c1927,c1929))) OR NOT(Kills(c1930,c1928))) OR NOT(Kills(SF0(c1930),SF0(c1927))))");
            cnf1 = cnfConverter.convertToCNF(s1);
            cnf2 = cnfConverter.convertToCNF(s2);

            c1 = cnf1.getConjunctionOfClauses().Get(0);
            c2 = cnf2.getConjunctionOfClauses().Get(0);

            Assert.IsTrue(c1.Equals(c2));
        }
Example #3
0
        public void testSimpleEquals()
        {
            Term cons1 = new Constant("C1");
            Term cons2 = new Constant("C2");
            Term var1  = new Variable("v1");
            ICollection <Term> pts1 = CollectionFactory.CreateQueue <Term>();
            ICollection <Term> pts2 = CollectionFactory.CreateQueue <Term>();

            pts1.Add(cons1);
            pts1.Add(cons2);
            pts1.Add(var1);
            pts2.Add(cons2);
            pts2.Add(cons1);
            pts2.Add(var1);

            Clause c1 = new Clause();
            Clause c2 = new Clause();

            Assert.IsTrue(c1.Equals(c1));
            Assert.IsTrue(c2.Equals(c2));
            Assert.IsTrue(c1.Equals(c2));
            Assert.IsTrue(c2.Equals(c1));

            // Check negatives
            c1.addNegativeLiteral(new Predicate("Pred1", pts1));
            Assert.IsFalse(c1.Equals(c2));
            Assert.IsFalse(c2.Equals(c1));
            c2.addNegativeLiteral(new Predicate("Pred1", pts1));
            Assert.IsTrue(c1.Equals(c2));
            Assert.IsTrue(c2.Equals(c1));

            c1.addNegativeLiteral(new Predicate("Pred2", pts2));
            Assert.IsFalse(c1.Equals(c2));
            Assert.IsFalse(c2.Equals(c1));
            c2.addNegativeLiteral(new Predicate("Pred2", pts2));
            Assert.IsTrue(c1.Equals(c2));
            Assert.IsTrue(c2.Equals(c1));
            // Check same but added in different order
            c1.addNegativeLiteral(new Predicate("Pred3", pts1));
            Assert.IsFalse(c1.Equals(c2));
            Assert.IsFalse(c2.Equals(c1));
            c1.addNegativeLiteral(new Predicate("Pred4", pts1));
            Assert.IsFalse(c1.Equals(c2));
            Assert.IsFalse(c2.Equals(c1));
            c2.addNegativeLiteral(new Predicate("Pred4", pts1));
            Assert.IsFalse(c1.Equals(c2));
            Assert.IsFalse(c2.Equals(c1));
            c2.addNegativeLiteral(new Predicate("Pred3", pts1));
            Assert.IsTrue(c1.Equals(c2));
            Assert.IsTrue(c2.Equals(c1));

            // Check positives
            c1.addPositiveLiteral(new Predicate("Pred1", pts1));
            Assert.IsFalse(c1.Equals(c2));
            Assert.IsFalse(c2.Equals(c1));
            c2.addPositiveLiteral(new Predicate("Pred1", pts1));
            Assert.IsTrue(c1.Equals(c2));
            Assert.IsTrue(c2.Equals(c1));

            c1.addPositiveLiteral(new Predicate("Pred2", pts2));
            Assert.IsFalse(c1.Equals(c2));
            Assert.IsFalse(c2.Equals(c1));
            c2.addPositiveLiteral(new Predicate("Pred2", pts2));
            Assert.IsTrue(c1.Equals(c2));
            Assert.IsTrue(c2.Equals(c1));
            // Check same but added in different order
            c1.addPositiveLiteral(new Predicate("Pred3", pts1));
            Assert.IsFalse(c1.Equals(c2));
            Assert.IsFalse(c2.Equals(c1));
            c1.addPositiveLiteral(new Predicate("Pred4", pts1));
            Assert.IsFalse(c1.Equals(c2));
            Assert.IsFalse(c2.Equals(c1));
            c2.addPositiveLiteral(new Predicate("Pred4", pts1));
            Assert.IsFalse(c1.Equals(c2));
            Assert.IsFalse(c2.Equals(c1));
            c2.addPositiveLiteral(new Predicate("Pred3", pts1));
            Assert.IsTrue(c1.Equals(c2));
            Assert.IsTrue(c2.Equals(c1));
        }
Example #4
0
        public void testSimpleEquals()
        {
            Term cons1 = new Constant("C1");
            Term cons2 = new Constant("C2");
            Term var1 = new Variable("v1");
            List<Term> pts1 = new List<Term>();
            List<Term> pts2 = new List<Term>();
            pts1.Add(cons1);
            pts1.Add(cons2);
            pts1.Add(var1);
            pts2.Add(cons2);
            pts2.Add(cons1);
            pts2.Add(var1);

            Clause c1 = new Clause();
            Clause c2 = new Clause();
            Assert.IsTrue(c1.Equals(c1));
            Assert.IsTrue(c2.Equals(c2));
            Assert.IsTrue(c1.Equals(c2));
            Assert.IsTrue(c2.Equals(c1));

            // Check negatives
            c1.addNegativeLiteral(new Predicate("Pred1", pts1));
            Assert.IsFalse(c1.Equals(c2));
            Assert.IsFalse(c2.Equals(c1));
            c2.addNegativeLiteral(new Predicate("Pred1", pts1));
            Assert.IsTrue(c1.Equals(c2));
            Assert.IsTrue(c2.Equals(c1));

            c1.addNegativeLiteral(new Predicate("Pred2", pts2));
            Assert.IsFalse(c1.Equals(c2));
            Assert.IsFalse(c2.Equals(c1));
            c2.addNegativeLiteral(new Predicate("Pred2", pts2));
            Assert.IsTrue(c1.Equals(c2));
            Assert.IsTrue(c2.Equals(c1));
            // Check same but added in different order
            c1.addNegativeLiteral(new Predicate("Pred3", pts1));
            Assert.IsFalse(c1.Equals(c2));
            Assert.IsFalse(c2.Equals(c1));
            c1.addNegativeLiteral(new Predicate("Pred4", pts1));
            Assert.IsFalse(c1.Equals(c2));
            Assert.IsFalse(c2.Equals(c1));
            c2.addNegativeLiteral(new Predicate("Pred4", pts1));
            Assert.IsFalse(c1.Equals(c2));
            Assert.IsFalse(c2.Equals(c1));
            c2.addNegativeLiteral(new Predicate("Pred3", pts1));
            Assert.IsTrue(c1.Equals(c2));
            Assert.IsTrue(c2.Equals(c1));

            // Check positives
            c1.addPositiveLiteral(new Predicate("Pred1", pts1));
            Assert.IsFalse(c1.Equals(c2));
            Assert.IsFalse(c2.Equals(c1));
            c2.addPositiveLiteral(new Predicate("Pred1", pts1));
            Assert.IsTrue(c1.Equals(c2));
            Assert.IsTrue(c2.Equals(c1));

            c1.addPositiveLiteral(new Predicate("Pred2", pts2));
            Assert.IsFalse(c1.Equals(c2));
            Assert.IsFalse(c2.Equals(c1));
            c2.addPositiveLiteral(new Predicate("Pred2", pts2));
            Assert.IsTrue(c1.Equals(c2));
            Assert.IsTrue(c2.Equals(c1));
            // Check same but added in different order
            c1.addPositiveLiteral(new Predicate("Pred3", pts1));
            Assert.IsFalse(c1.Equals(c2));
            Assert.IsFalse(c2.Equals(c1));
            c1.addPositiveLiteral(new Predicate("Pred4", pts1));
            Assert.IsFalse(c1.Equals(c2));
            Assert.IsFalse(c2.Equals(c1));
            c2.addPositiveLiteral(new Predicate("Pred4", pts1));
            Assert.IsFalse(c1.Equals(c2));
            Assert.IsFalse(c2.Equals(c1));
            c2.addPositiveLiteral(new Predicate("Pred3", pts1));
            Assert.IsTrue(c1.Equals(c2));
            Assert.IsTrue(c2.Equals(c1));
        }