Esempio n. 1
0
        public override ISet <Clause> visitBinarySentence(ComplexSentence s, ISet <Clause> arg)
        {
            if (s.isAndSentence())
            {
                s.getSimplerSentence(0).accept(this, arg);
                s.getSimplerSentence(1).accept(this, arg);
            }
            else if (s.isOrSentence())
            {
                ICollection <Literal> literals = CollectionFactory.CreateQueue <Literal>(LiteralCollector.getLiterals(s));
                arg.Add(new Clause(literals));
            }
            else
            {
                throw new IllegalArgumentException("Sentence is not in CNF: " + s);
            }

            return(arg);
        }
Esempio n. 2
0
        public override Sentence visitBinarySentence(ComplexSentence s, object arg)
        {
            Sentence result = null;

            if (s.isAndSentence())
            {
                Sentence s1 = s.getSimplerSentence(0).accept(this, arg);
                Sentence s2 = s.getSimplerSentence(1).accept(this, arg);
                if (s1.isOrSentence() || s2.isOrSentence())
                {
                    Sentence alpha, betaAndGamma;
                    if (s2.isOrSentence())
                    {
                        // (&alpha; & (&beta; | &gamma;))
                        // Note: even if both are 'or' sentence
                        // we will prefer to use s2
                        alpha        = s1;
                        betaAndGamma = s2;
                    }
                    else
                    {
                        // Note: Need to handle this case too
                        // ((&beta; | &gamma;) & &alpha;)
                        alpha        = s2;
                        betaAndGamma = s1;
                    }

                    Sentence beta  = betaAndGamma.getSimplerSentence(0);
                    Sentence gamma = betaAndGamma.getSimplerSentence(1);

                    if (s2.isOrSentence())
                    {
                        // ((&alpha; & &beta;) | (&alpha; & &gamma;))
                        Sentence alphaAndBeta = (new ComplexSentence(Connective.AND,
                                                                     alpha, beta)).accept(this, null);
                        Sentence alphaAndGamma = (new ComplexSentence(Connective.AND,
                                                                      alpha, gamma)).accept(this, null);

                        result = new ComplexSentence(Connective.OR, alphaAndBeta,
                                                     alphaAndGamma);
                    }
                    else
                    {
                        // ((&beta; & &alpha;) | (&gamma; & &alpha;))
                        Sentence betaAndAlpha = (new ComplexSentence(Connective.AND,
                                                                     beta, alpha)).accept(this, null);
                        Sentence gammaAndAlpha = (new ComplexSentence(Connective.AND,
                                                                      gamma, alpha)).accept(this, null);

                        result = new ComplexSentence(Connective.OR, betaAndAlpha,
                                                     gammaAndAlpha);
                    }
                }
                else
                {
                    result = new ComplexSentence(Connective.AND, s1, s2);
                }
            }
            else
            {
                result = base.visitBinarySentence(s, arg);
            }

            return(result);
        }