Esempio n. 1
0
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
bool CTDPartition::initGenRecords( CTDAttribs* pAttribs)
{
	m_genRecords.cleanup();
	int nAttribs = pAttribs->GetSize();

	for (int classInd = 0; classInd < m_nClasses; ++classInd){

		CTDAttrib* pAttrib = NULL;
		CTDValue* pNewValue = NULL;
		CTDRecord* pNewRecord = new CTDRecord(); 
		
		for (int attribID = 0; attribID < nAttribs; ++attribID){
	
			pNewValue = NULL;
			pAttrib = pAttribs->GetAt(attribID);
        
			if (pAttrib->isContinuous())
				pNewValue = new CTDNumericValue(-1.0);
			else
	            pNewValue = new CTDStringValue();

			if (!pNewValue) {
				ASSERT(false);
  				return false;
			}
	
			if (attribID == pAttribs->GetSize() - 1) {
				// Class attribute
				if (!pNewValue->assignGenClassValue(pAttrib, classInd))
					return false;
			}
			else {
				// Ordinary attribute
				// Initialize the current concept to the root concept.                    
				if (!pNewValue->initConceptToRoot(pAttrib))
					return false;
			}

			// Add the value to the record.
			if (!pNewRecord->addValue(pNewValue))
				return false;

		}    

		if (pNewRecord){
			pNewRecord->setRecordID(m_genRecords.Add(pNewRecord));
		}

	}
	if (m_genRecords.GetSize() != m_nClasses) {
            cerr << _T("CTDPartition::initGenRecords: Number of generalized record is not current.") << endl;
            return false;
    }

	return true;
}