Beispiel #1
0
 private bool TT_CHECK_ALL(AdvancedKnowledgeBase kb, string query, List <string> symbols, Dictionary <string, bool> model)
 {
     if (symbols.Count == 0)
     {
         if (IS_TRUE(kb.Expressions, model))
         {
             if (IS_TRUE(query, model))
             {
                 _modelCount++;
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
         else
         {
             return(true);
         }
     }
     else
     {
         string P = symbols[0];
         symbols.RemoveAt(0);
         return(TT_CHECK_ALL(kb, query, new List <string>(symbols), extend(P, true, model)) && TT_CHECK_ALL(kb, query, new List <string>(symbols), extend(P, false, model)));
     }
 }
Beispiel #2
0
        private bool TT_ENTAILS(AdvancedKnowledgeBase kb, string query)
        {
            List <string>             Symbol = createSymbolList(kb.Expressions, query);
            Dictionary <string, bool> model  = new Dictionary <string, bool>();

            return(TT_CHECK_ALL(kb, query, Symbol, model));
        }
Beispiel #3
0
 public ExtendedTruthTable(AdvancedKnowledgeBase kb, string query)
 {
     _kb    = kb;
     _query = query;
 }
Beispiel #4
0
        /*
         * Reads Problem File
         * @Param filename - string that gives name of file to read from
         * @Param solver - string that tells reader what type of engine is being used. Changes
         *      output if more advanced algorithms used.
         */
        public static bool ReadProblem(string filename, string solver)
        {
            List <string> text = new List <string>();

            //tries to read problem file, if it can't returns false
            try
            {
                StreamReader reader = File.OpenText(filename);
                for (int i = 0; i < 4; i++)
                {
                    text.Add(reader.ReadLine());
                }
                reader.Close();
            }
            catch
            {
                Console.WriteLine("Error: Could not read file");
                return(false);
            }
            string[] knowledge = text[1].Split(';');
            knowledge = knowledge.Take(knowledge.Count() - 1).ToArray();
            List <Clause> clauses = new List <Clause>();

            // If basic checking method
            if (solver != "GTT" || solver != "DPLL")
            {
                foreach (string s in knowledge)
                {
                    if (s.Contains("=>"))
                    {
                        List <string> premiseSymbols = new List <string>();
                        int           index          = s.IndexOf("=>");
                        string        premise        = s.Substring(0, index);
                        string        conclusion     = s.Substring(index + 2);
                        conclusion = conclusion.Trim();
                        string[] splitPremise = { "" };
                        if (premise.Contains("&"))
                        {
                            splitPremise = premise.Split('&');
                        }
                        else
                        {
                            splitPremise[0] = premise;
                        }
                        foreach (string symbol in splitPremise)
                        {
                            string trim = symbol.Trim();
                            premiseSymbols.Add(trim);
                        }
                        clauses.Add(new Clause(premiseSymbols, conclusion));
                    }
                    else
                    {
                        string conclusion = s.Trim();
                        clauses.Add(new Clause(conclusion));
                    }
                }
                _query = text[3];
                _kb    = new KnowledgeBase(clauses);


                return(true);
            }
            // if solving method more advanced clauses
            else
            {
                List <LogicalExpression> kb = new List <LogicalExpression>();
                foreach (string s in knowledge)
                {
                    LogicalExpression exp = new LogicalExpression(s);
                    //exp.printInfo();
                    kb.Add(exp);
                }

                _akb   = new AdvancedKnowledgeBase(kb);
                _query = text[3];
                return(true);
            }
        }