예제 #1
0
파일: NodeTest.cs 프로젝트: vadimostanin/GA
 public void TreeHasCorrectStringForm()
 {
     var tree = new Arithmetic.Product<int>(VariableNode.Make<int>(0, "x"),
                                            new Arithmetic.Plus<int>(VariableNode.Make<int>(1, "y"),
                                                                     Constant.Int(3)));
     Assert.AreEqual(tree.ToString(), "(x ∙ (y + 3))");
     var tree2 = new Logic.MultipleOr(new PredicateNode("P", VariableNode.Make<int>(0, "x")),
                                         new PredicateNode("Q", VariableNode.Make<int>(1, "y"), VariableNode.Make<int>(2, "z")),
                                         new PredicateNode("H", new FunctionNode("f", VariableNode.Make<int>(0, "x")), new FunctionNode("c")));
     Assert.AreEqual(tree2.ToString(), "P(x) V Q(y,z) V H(f(x),c)");
 }
예제 #2
0
        public void ComplexUnificationTest()
        {
            // !P(x,b,z,s) V ANS(f(g(z,b,h(x,z,s))))
            var A = new Logic.MultipleOr(
                new SkolemPredicateNode("P", true, VariableNode.Make<bool>(0, "x"), new FunctionNode("b"), VariableNode.Make<bool>(2,"z"), VariableNode.Make<bool>(3, "s")),
                new SkolemPredicateNode("ANS", false,
                    new FunctionNode("f",
                        new FunctionNode("g",VariableNode.Make<bool>(2, "z"),new FunctionNode("b"),
                            new FunctionNode("h", VariableNode.Make<bool>(0, "x"), VariableNode.Make<bool>(2, "z"), VariableNode.Make<bool>(3, "s"))))));

            // P(a,b,c,s0)
            var B = new SkolemPredicateNode("P", false, new FunctionNode("a"), new FunctionNode("b"), new FunctionNode("c"), new FunctionNode("s0"));
            Assert.AreEqual(UnificationService.CanUnificate((SkolemPredicateNode)A.Children[0], B), true);
            var rules = UnificationService.GetUnificationRules((SkolemPredicateNode)A.Children[0], B);
            Assert.AreEqual(rules.Count, 3);
            UnificationService.Unificate(A, rules);
            Assert.AreEqual(A.ToString(), "!P(a,b,c,s0) V ANS(f(g(c,b,h(a,c,s0))))");
        }