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

📄 structure.cpp

📁 The subject which is to us propos¨&brvbar is as follows: calculation of the degr¨&brvbar d&iexcl &ma
💻 CPP
字号:
#pragma warning (disable: 4267)

#include "Structure.h"
#include <iterator>


/* CAtomPos class */

CAtomPos::CAtomPos(int nAt, int nDeg)
{
  nAtom = nAt;
  nDegree = nDeg;
}

CAtomPos::~CAtomPos() { }


/* CProgReduct class */

CProgReduct::iterator
CProgReduct::Find(int nValue)
{
  CProgReduct::iterator iter = begin();
  for (; iter != end(); iter++)
  {
      CAtomPos a = *iter;
      if (a.nAtom == nValue)
	return iter;
  }
  return iter;
}


void CProgReduct::UpdateDegree(int nAtom, int nNewDegree, int nTypeCompare)
{
  CProgReduct::iterator iter = Find(nAtom);
  CAtomPos* a = &*iter;
  switch (nTypeCompare)
  {
    case INFERIOR:
    {
	if (a->nDegree > nNewDegree)
	{
	    a->nDegree = nNewDegree;
	}
    }
    break;

    case SUPERIOR:
    {
	if (a->nDegree < nNewDegree)
	{
	    a->nDegree = nNewDegree;
	}
    }
    break;

    case EQUAL:
    {
	if (a->nDegree == nNewDegree)
	{
	    a->nDegree = nNewDegree;
	}
    }
    break;

    default :
      cout << "CProgReduct::UpdateDegree " << "nTypeCompare not referenced : " << nTypeCompare << endl;
  }
}

/* CSetAtom class */

CSetAtom::CSetAtom() {}
CSetAtom::~CSetAtom() {}

/* CRegle class */

CRegle::CRegle() {};

CRegle::~CRegle()
{
    bodyPlus.clear();
    bodyMinus.clear();
}

void CRegle::SetHead(int nNewHead)
{
    this->nHead = nNewHead;
}
        
int CRegle::GetHead()
{
    return this->nHead;
}

void CRegle::AddBodyPlusEntry(int newEntry)
{
    bodyPlus.insert(newEntry);
}
        
void CRegle::AddBodyMinusEntry(int newEntry)
{
    bodyMinus.insert(newEntry);
}

void CRegle::WriteInformation()
{
    cout << "Head : " << nHead << endl;
    cout << "BodyPlus : ";
    copy(bodyPlus.begin(), bodyPlus.end(), ostream_iterator<int>(cout, " - "));
    cout << "BodyMinus : ";
    copy(bodyMinus.begin(), bodyMinus.end(), ostream_iterator<int>(cout, " - "));
    cout << endl;
}


CSetAtom CRegle::GetBodyPlus()
{
	return this->bodyPlus;
}

CSetAtom CRegle::GetBodyMinus()
{
	return this->bodyMinus;
}

void* CRegle::Copy(int nTypeBodyCopy)
{
	CRegle* rReturn = new CRegle();

	rReturn->SetHead(this->GetHead());
	rReturn->SetBody(this, nTypeBodyCopy);

	return rReturn;
}

bool CRegle::IsEmptyBody(int nTypeBody)
{
	bool bReturn = true;

	switch (nTypeBody)
	{
		case BODYMINUS:
		{
			bReturn = (this->bodyMinus.size() == 0);
		}
		break;

		case BODYPLUS:
		{
			bReturn = (this->bodyPlus.size() == 0);
		}
		break;

		default:
			bReturn = ((this->bodyMinus.size() == 0) && (this->bodyPlus.size() == 0));
	}

	return bReturn;
}

void CRegle::SetBody(CRegle* rSource, int nTypeBody)
{
	switch (nTypeBody)
	{
		case BODYMINUS:
		{
			this->bodyMinus = rSource->GetBodyMinus();
		}
		break;

		case BODYPLUS:
		{
			this->bodyPlus = rSource->GetBodyPlus();
		}
		break;

		case ALLBODY:
		{
			this->bodyMinus = rSource->GetBodyMinus();
			this->bodyPlus = rSource->GetBodyPlus();
		}
		break;

		default :
			cout << "Error In CRegle::Copy " << "nTypeCopy not referenced" << endl;
	}
}

bool CRegle::IsContaining(int nAtom, int nTypeBody)
{
	switch (nTypeBody)
	{
		case BODYMINUS:
		{
			return (bodyMinus.find(nAtom) != bodyMinus.end());
		}
		break;

		case BODYPLUS:
		{
			return (bodyPlus.find(nAtom) != bodyPlus.end());
		}
		break;

		case ALLBODY:
		{
			return ((bodyMinus.find(nAtom) != bodyMinus.end()) ||
					(bodyPlus.find(nAtom) != bodyPlus.end()));
		}
		break;

		default :
			cout << "Error In CRegle::IsContaining " << "nTypeCopy not referenced" << endl;
	}

    return false;
}

void CRegle::EraseElement(int nAtom, int nTypeBody)
{
	switch (nTypeBody)
	{
		case BODYMINUS:
		{
			bodyMinus.erase(nAtom);
		}
		break;

		case BODYPLUS:
		{
			bodyPlus.erase(nAtom);
		}
		break;

		case ALLBODY:
		{
			bodyPlus.erase(nAtom);
			bodyMinus.erase(nAtom);
		}
		break;

		default :
			cout << "Error In CRegle::EraseElement " << "nTypeCopy not referenced" << endl;
	}
}

/* CReglePos class methods definition */

CReglePos::CReglePos() : CRegle()
{}

CReglePos::~CReglePos() {};

void CReglePos::SetDegree(int nNewDegree)
{
    this->nDegree = nNewDegree;
}

int CReglePos::GetDegree()
{
    return this->nDegree;
}

void CReglePos::WriteInformationPos()
{
    CRegle : WriteInformation();
    cout << "Degree : " << nDegree << "\n" << endl;
}

void* CReglePos::Copy(int nTypeBodyCopy)
{
	CReglePos* rReturn = new CReglePos();

	rReturn->SetHead(this->GetHead());
	rReturn->SetDegree(this->GetDegree());
	rReturn->SetBody(this, nTypeBodyCopy);

	return rReturn;
}

/* CProgLog class methods definitions */
CProgLog::CProgLog() {}
CProgLog::~CProgLog()
{
    // Destruction of the two lists
    int sizeVector = m_vSetOfRegle.size();
    for (int i = 0; i < sizeVector; i++)
    {
        delete (m_vSetOfRegle[i]);
    }

    sizeVector = m_vDictionnary.size();
    for (int i = 0; i < sizeVector; i++)
    {
        free(m_vDictionnary[i]);
    }

    m_vSetOfRegle.clear();
    m_vDictionnary.clear();
}

void CProgLog::AddRegle(CRegle* pRegle)
{
    m_vSetOfRegle.push_back(pRegle);
}
        
int CProgLog::AddDictionnaryEntry(char* newEntry)
{
    int place = FindPlaceInDictionnary(newEntry);

    if (place == -1)
    {
        char* strCopy;
        strCopy = (char*) malloc(sizeof(char)*strlen(newEntry)+1);
        strcpy(strCopy, newEntry);

        m_vDictionnary.push_back(strCopy);

        return (m_vDictionnary.size()-1);
    }

    return place;
}
        
void CProgLog::WriteInformation()
{
    this->WriteDictionnary();

    cout << "\n\nRULES :\n" << endl;

    int sizeVector = m_vSetOfRegle.size();
    for (int i = 0; i < sizeVector; i++)
    {
        m_vSetOfRegle[i]->WriteInformation();
        cout << "\n" << endl;
    }
}

void CProgLog::WriteDictionnary()
{
    cout << "\n\nDICTIONNARY :\n";

    int sizeVector = m_vDictionnary.size();
    for (int i = 0; i < sizeVector; i++)
    {
        cout << i << " - " << m_vDictionnary[i] << "\n";
    }

    cout << endl;
}

int CProgLog::FindPlaceInDictionnary(char* str)
{
    int sizeVector = m_vDictionnary.size();
    for (int i = 0; i < sizeVector; i++)
    {
        if (strcmp(m_vDictionnary[i], str) == 0)
            return i;
    }

    return -1;
}

vector<CRegle*> CProgLog::GetAllLogicRules()
{
	return this->m_vSetOfRegle;
}

char* CProgLog::GetDictionnaryEntry(int nPlace)
{
	return this->m_vDictionnary[nPlace];
}

/* CProgLogPos class methods definitions */
CProgLogPos::CProgLogPos() : CProgLog()
{}

CProgLogPos::~CProgLogPos()
{
    int sizeVector = m_vSetOfRegle.size();
    for (int i = 0; i < sizeVector; i++)
    {
        delete (m_vSetOfRegle[i]);
    }

    m_vSetOfRegle.clear();
}

void CProgLogPos::AddRegle(CReglePos* pRegle)
{
    m_vSetOfRegle.push_back(pRegle);
}

void CProgLogPos::WriteInformation()
{
    WriteDictionnary();

	cout << "\nRULES :\n" << endl;
        
    int sizeVector = m_vSetOfRegle.size();
    for (int i = 0; i < sizeVector; i++)
    {
        m_vSetOfRegle[i]->WriteInformationPos();
        cout << endl;
    }
}

vector<CRegle*> CProgLogPos::GetAllLogicRules()
{
    vector<CRegle*> vectReturn;
    vector<CReglePos*>::iterator iter = m_vSetOfRegle.begin();

    for (; iter != m_vSetOfRegle.end(); iter++)
    {
	vectReturn.push_back((CRegle*) *iter);
    }

    return vectReturn;
}

vector<CReglePos*> CProgLogPos::GetAllPossibilistRules()
{
  return m_vSetOfRegle;
}

⌨️ 快捷键说明

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