Exemple #1
0
        public SymbolValuePair FindPureSymbolValuePair(IList <Sentence> clauseList,
                                                       Model model)
        {
            IList <Sentence> clausesWithNonTrueValues = ClausesWithNonTrueValues(clauseList, model);
            Sentence         nonTrueClauses           = LogicUtils.ChainWith("AND", clausesWithNonTrueValues);

            // System.out.println("Unsatisfied clauses = "
            // + clausesWithNonTrueValues.Count);
            ISet <Symbol> symbolsAlreadyAssigned = model.GetAssignedSymbols();

            // debug
            // IList symList = asList(symbolsAlreadyAssigned);
            //
            // System.out.println(" assignedSymbols = " + symList.Count);
            // if (symList.Count == 52) {
            // System.out.println("untrue clauses = " + clausesWithNonTrueValues);
            // System.out.println("model= " + model);
            // }

            // debug
            IList <Symbol> purePositiveSymbols = new SymbolClassifier().GetPurePositiveSymbolsIn(nonTrueClauses)
                                                 .Except(symbolsAlreadyAssigned).ToList();

            IList <Symbol> pureNegativeSymbols =
                new SymbolClassifier().GetPureNegativeSymbolsIn(nonTrueClauses).Except(symbolsAlreadyAssigned).ToList();

            // if none found return "not found
            if ((purePositiveSymbols.Count == 0) &&
                (pureNegativeSymbols.Count == 0))
            {
                return(new SymbolValuePair());// automatically set to null values
            }
            else
            {
                if (purePositiveSymbols.Count > 0)
                {
                    Symbol symbol = new Symbol((purePositiveSymbols[0])
                                               .Value);
                    if (pureNegativeSymbols.Contains(symbol))
                    {
                        throw new ApplicationException("Symbol " + symbol.Value
                                                       + "misclassified");
                    }
                    return(new SymbolValuePair(symbol, true));
                }
                else
                {
                    Symbol symbol = new Symbol((pureNegativeSymbols[0])
                                               .Value);
                    if (purePositiveSymbols.Contains(symbol))
                    {
                        throw new ApplicationException("Symbol " + symbol.Value
                                                       + "misclassified");
                    }
                    return(new SymbolValuePair(symbol, false));
                }
            }
        }
Exemple #2
0
        private Sentence CreateResolventClause(ClauseSymbols cs, Symbol toRemove)
        {
            var positiveSymbols = cs.Clause1PositiveSymbols.Union(cs.Clause2PositiveSymbols).ToList();
            var negativeSymbols = cs.Clause1NegativeSymbols.Union(cs.Clause2NegativeSymbols).ToList();

            if (positiveSymbols.Contains(toRemove))
            {
                positiveSymbols.Remove(toRemove);
            }
            if (negativeSymbols.Contains(toRemove))
            {
                negativeSymbols.Remove(toRemove);
            }

            positiveSymbols.Sort(this.CompareSymbols);
            negativeSymbols.Sort(this.CompareSymbols);

            IList <Sentence> sentences = new List <Sentence>();

            for (int i = 0; i < positiveSymbols.Count; i++)
            {
                sentences.Add(positiveSymbols[i]);
            }
            for (int i = 0; i < negativeSymbols.Count; i++)
            {
                sentences.Add(new UnarySentence(negativeSymbols[i]));
            }
            if (sentences.Count == 0)
            {
                return(new Symbol("EMPTY_CLAUSE")); // == empty clause
            }
            else
            {
                return(LogicUtils.ChainWith("OR", sentences));
            }
        }
 public Sentence AsSentence()
 {
     return(LogicUtils.ChainWith("AND", this.Sentences));
 }