예제 #1
0
 public override ISet <Literal> visitBinarySentence(ComplexSentence s, ISet <Literal> arg)
 {
     if (s.isOrSentence())
     {
         s.getSimplerSentence(0).accept(this, arg);
         s.getSimplerSentence(1).accept(this, arg);
     }
     else
     {
         throw new IllegalArgumentException("Sentence is not in CNF: " + s);
     }
     return(arg);
 }
예제 #2
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);
        }
예제 #3
0
        public override Sentence visitBinarySentence(ComplexSentence s, object arg)
        {
            Sentence result = null;

            if (s.isOrSentence())
            {
                Sentence s1 = s.getSimplerSentence(0).accept(this, arg);
                Sentence s2 = s.getSimplerSentence(1).accept(this, arg);
                if (s1.isAndSentence() || s2.isAndSentence())
                {
                    Sentence alpha, betaAndGamma;
                    if (s2.isAndSentence())
                    {
                        // (&alpha; | (&beta; & &gamma;))
                        // Note: even if both are 'and' 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.isAndSentence())
                    {
                        // ((&alpha; | &beta;) & (&alpha; | &gamma;))
                        Sentence alphaOrBeta = (new ComplexSentence(Connective.OR,
                                                                    alpha, beta)).accept(this, null);
                        Sentence alphaOrGamma = (new ComplexSentence(Connective.OR,
                                                                     alpha, gamma)).accept(this, null);

                        result = new ComplexSentence(Connective.AND, alphaOrBeta,
                                                     alphaOrGamma);
                    }
                    else
                    {
                        // ((&beta; | &alpha;) & (&gamma; | &alpha;))
                        Sentence betaOrAlpha = (new ComplexSentence(Connective.OR,
                                                                    beta, alpha)).accept(this, null);
                        Sentence gammaOrAlpha = (new ComplexSentence(Connective.OR,
                                                                     gamma, alpha)).accept(this, null);

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

            return(result);
        }