Пример #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 ArgumentException("Sentence is not in CNF: " + s);               //IllegalArgumentException
     }
     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())
            {
                IList <Literal> literals = new List <Literal>(LiteralCollector.getLiterals(s));           //ArrayList
                arg.Add(new Clause(literals));
            }
            else
            {
                throw new ArgumentException("Sentence is not in CNF: " + s);           //IllegalArgumentException
            }

            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;))
                        // Nota: incluso si ambos son sentencias 'and' preferiremos usar s2
                        alpha        = s1;
                        betaAndGamma = s2;
                    }
                    else
                    {
                        // Nota: Hace falta manejar este caso también
                        // ((&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);
        }