⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.cpp

📁 The subject which is to us propos¨&brvbar is as follows: calculation of the degr¨&brvbar d&iexcl &ma
💻 CPP
字号:

#include "Structure.h"
#include "Lecture.h"

// SModels Header
#include "smodels.h"
#include "api.h"
#include "atomrule.h"

void CalculReduit(CProgLogPos* pProg, CSetAtom v_ListeAtomPositif)
{
  // Calcul du r閐uit
  // tu peux recup閞er les valeurs qu'il y a dans le tableau v_ListeAtomPositif comme ceci :
  cout << "\n-- CalculReduit In : --" << endl;

  // Erase all the rules those have not a head in v_ListeAtomPositif
  // And put these rules in another CProgLogPos
  /*  CProgLogPos* pProgUpdating = new CProgLogPos;

  vector<CReglePos*> vSetAllRules = pProg->GetAllPossibilistRules();
  vector<CReglePos*>::iterator iterRule = SetAllRules.begin();

  for (; iterRule != vSetAllRules.end(); iterRule++)
  {
      nHead = *iterRule->GetHead();
  }
  */
  CSetAtom::iterator iter;
  for (iter = v_ListeAtomPositif.begin(); iter != v_ListeAtomPositif.end(); iter++)
  {
      
      int nAtom = *iter;
      int nHead;
      cout << "Atome numero : " << nAtom << endl;





  }
  cout << endl;

  cout << "-- CalculReduit Out --\n" << endl;
}

void ConstructSmodels(CProgLogPos* pProg)
{
	Smodels smodels;
        Api api(&smodels.program);

        Atom *aTmp;

	// Keep track of atom names
	api.remember();

	//	cout << "ConstrucSmodels" << endl;

	vector<CRegle*> m_vSetOfRules = pProg->GetAllLogicRules();
	vector<CRegle*>::iterator iterRule = m_vSetOfRules.begin();

	for (; iterRule != m_vSetOfRules.end(); iterRule++)
	{
	  // cout << "New iteration" << endl;

		// Creation of a new rule in smodels
		api.begin_rule(BASICRULE);
		CRegle* rTmp = *iterRule;
		rTmp->WriteInformation();

		// Head
		char* nameAtom = pProg->GetDictionnaryEntry(rTmp->GetHead());

		if (!(aTmp = api.get_atom(nameAtom))) // Check if the atom doesn't exist
		{
		        cout << "Head / Atom not referenced" << endl;
			// It is not referenced so we create a new atom
			aTmp = api.new_atom();
			api.set_name(aTmp, nameAtom);
		}
		else
		{
		    cout << "Head / Atom already Referenced" << endl;
		}

		api.add_head(aTmp);

		// Definition of the body's rule
		// Body Plus
		CSetAtom bodyPlus = rTmp->GetBodyPlus();
		CSetAtom::iterator iter;
		for (iter = bodyPlus.begin(); iter != bodyPlus.end(); iter++)
		{
			int nAtom = *iter;
			nameAtom = pProg->GetDictionnaryEntry(nAtom);

			if (!(aTmp = api.get_atom(nameAtom)))
			{
				aTmp = api.new_atom();
				api.set_name(aTmp, nameAtom);
			}

			api.add_body(aTmp, true);
		}

		// Body Minus
		CSetAtom bodyMinus = rTmp->GetBodyMinus();
		for (iter = bodyMinus.begin(); iter != bodyMinus.end(); iter++)
		{
			int nAtom = *iter;
			nameAtom = pProg->GetDictionnaryEntry(nAtom);

			if (!(aTmp = api.get_atom(nameAtom)))
			{
				aTmp = api.new_atom();
				api.set_name(aTmp, nameAtom);
			}

			api.add_body(aTmp, false);
		}

		// Definition of the rule finished
		api.end_rule();
	}

	// Definition of the program finished
	api.done();

	cout << "---------- api.done() finished---------------\n" << endl;
	cout << "----------- Program in Smodels --------------\n" << endl;

	// Display the program
	smodels.program.print();

	cout << "\n---------- End of Smodels' program -------------\n" << endl;;
	cout << "---------- Initialisation of Smodels ----------------\n" << endl;

	// Generate the stable models
	smodels.init();

	cout << "---------- Initialisation of Smodels Finished -----------\n" << endl;

	cout << "-------------- Compute all models stable ----------------\n" << endl;

	// Compute all stable models
	while (smodels.model ())  // Returns 0 when there are no more models
	{
	        cout << "New Model : " << endl;

		cout << " -- smodels.printAnswer() : --" << endl;
		// We've got one model more
		smodels.printAnswer ();  // Prints the answer

		CSetAtom vectAtomPositif;

		cout << "-- smodels.printAnswer :: Finished --" << endl;
		Node* nd = smodels.program.atoms.head();
		for (; nd; nd = nd->next)
		{
		    if (nd->atom->Bpos)
		    {
		      vectAtomPositif.insert(pProg->FindPlaceInDictionnary((char*)nd->atom->atom_name()));
		      cout << "The atom " << nd->atom->atom_name() << " is true" << endl;
		    }
		    else if (nd->atom->Bneg)
		    {
		        // Nothing to do ! (The atom is not in the a stable model
		        // cout << "The atom "  << nd->atom->atom_name() << " is false" << endl;
		    }
		}

		CalculReduit(pProg, vectAtomPositif);
	}

	cout << "\n------------- End of Computing models -------------------\n" << endl;
}

int main(int argc, char** argv)
{
    if (argc != 2)
    {
        printf("Il manque le fichier d'entree contenant un programme logique - deterministe\n");
        system("PAUSE");
        return -1;
    }

    printf("argv[1] : %s\n",argv[1]);

    CProgLogPos* pProgLog = ConstructProgLogPos(argv[1]);
    pProgLog->WriteInformation();

    ConstructSmodels(pProgLog);

    delete pProgLog;

    system("PAUSE");
    return 0;
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -