Exemple #1
0
void model_test_3_aux(ai::PL::KnowledgeBase &kb,
		      std::vector<ai::PL::Symbol *> &symbols,
		      unsigned int pos)
{
  kb.SetModel(symbols);
  
  ai::PL::Symbol::State rval = kb.Evaluate();

  if(rval == ai::PL::Symbol::KNOWN_TRUE)
    {
      std::cout << kb << std::endl;
      std::cout << "Truth: " << rval << std::endl;
      return;
    }
  else if(rval == ai::PL::Symbol::KNOWN_FALSE)
    {
      return;
    }
  // still unknown
  count ++;
  
  ai::PL::Symbol::State p;
  for(p = ai::PL::Symbol::KNOWN_TRUE; p <= ai::PL::Symbol::KNOWN_FALSE; p++)
    {
      symbols[pos]->SetValue(p);
      model_test_3_aux(kb, symbols, pos + 1);
    }
}
Exemple #2
0
int do_ask(ai::PL::KnowledgeBase &kb, int interactive, char *buf, std::istream &in, std::ostream &out, const char *prompt)
{
    ai::PL::Symbol::State rval;
    ai::PL::KnowledgeBase question;
    char *q = 0;
    unsigned int len = strlen(prompt);

    if(strlen(buf) > len)
    {
        q = &buf[len];
    }
    else
    {
        if(interactive)
        {
            out << prompt << "> " << std::flush;
        }
        in.getline(buf, BUF_SIZE);
        q = buf;
    }
    question.AddSentence(q);
    if(!interactive)
    {
        out << prompt << " " << *(question.GetSentences()[0]) << std::endl;
    }
    if(strcmp(prompt, "dpll") == 0)
    {
        rval = kb.DPLL_Entails(question);
    }
    else if(strcmp(prompt, "ask2") == 0)
    {
        rval = kb.TT_Entails_Pruned(question);
    }
    else if(strcmp(prompt, "ask") == 0)
    {
        rval = kb.TT_Entails(question);
    }
    else
    {
        out << "Unknown ask mode: " << prompt << std::endl;
        rval = ai::PL::Symbol::UNKNOWN;
    }
    if(rval == ai::PL::Symbol::KNOWN_TRUE)
    {
        out << "YES, " << q << " is entailed." << std::endl;
    }
    else
    {
        out << "NO, " << q << " is not entailed." << std::endl;
    }
    out << kb.GetCount() << " evaluations."  << std::endl;
    return 0;
}
Exemple #3
0
int do_list(ai::PL::KnowledgeBase &kb, int interactive, char *buf, std::istream &in, std::ostream &out)
{
    const std::vector<ai::PL::Sentence *>       &sentences = kb.GetSentences();
    std::vector<ai::PL::Sentence *>::const_iterator sen_it = sentences.begin();
    while(sen_it != sentences.end())
    {
        out << *(*sen_it) << std::endl;
        sen_it ++;
    }
    return 0;
}
Exemple #4
0
void tt_entails_test_2_aux(ai::PL::KnowledgeBase &kb,
			   ai::PL::KnowledgeBase &alpha)
{
  ai::PL::Symbol::State rval;

  rval = kb.TT_Entails_Pruned(alpha);
  
  std::cout << "KB" << std::endl << kb 
	    << "alpha" << std::endl << alpha
	    << "result: " << rval
	    << std::endl
	    << std::endl;
}
Exemple #5
0
int do_cnf(ai::PL::KnowledgeBase &kb, int interactive, char *buf, std::istream &in, std::ostream &out)
{
    const std::vector<ai::PL::Sentence *>          &sentences = kb.GetSentences();
    std::vector<ai::PL::Sentence *>::const_iterator sen_it = sentences.begin();
    while(sen_it != sentences.end())
    {
        ai::PL::Sentence *s_tmp = new ai::PL::Sentence(*(*sen_it));
        s_tmp->CNF();
        out << *(s_tmp) << std::endl;
        sen_it ++;
        delete s_tmp;
    }
    return 0;
}
Exemple #6
0
int do_tell(ai::PL::KnowledgeBase &kb, int interactive, char *buf, std::istream &in, std::ostream &out)
{
    char * sentence = 0;
    if(strlen(buf) > 4)
    {
        sentence = &buf[4];
    }
    else
    {
        if(interactive)
        {
            out << "tell> " << std::flush;
        }
        in.getline(buf, BUF_SIZE);
        sentence = buf;
    }
    kb.AddSentence(sentence);
    if(!interactive)
    {
        out << "tell " << sentence << std::endl;
    }
    return 0;
}