//--------------------------------------------------------------------------- // Register this parition from the concept. //--------------------------------------------------------------------------- bool CTDPartition::registerPartition() { CTDRecord* pFirstRec = NULL; if ( getNumRecords()== 0){ // Get the first record of the generalized records. pFirstRec = getGenRecords()->GetAt(0); } else { // Get the first record of the partition. pFirstRec = getRecord(0); if (!pFirstRec) { ASSERT(false); return false; } } int a = 0; CTDPartAttrib* pPartAttrib = NULL; CTDConcept* pCurrentConcept = NULL; for (POSITION pos = m_partAttribs.GetHeadPosition(); pos != NULL; ++a) { // Find the current concept of this attribute. pPartAttrib = m_partAttribs.GetNext(pos); pCurrentConcept = pFirstRec->getValue(a)->getCurrentConcept(); if (!pCurrentConcept) { ASSERT(false); return false; } pPartAttrib->m_relatedPos = pCurrentConcept->registerPartition(this); } return true; }
void database::NPCInfo::select(float level, float epsilon, bool licensed, std::vector<unsigned int>& result) { result.clear(); for( unsigned int i=0; i<getNumRecords(); i++ ) { if( i == getLicensedCharacterId() && !licensed ) continue; if( fabs( level - getRecord( i )->level ) <= fabs( epsilon ) ) { result.push_back( i ); } } }
database::NPCInfo* database::NPCInfo::getRecord(unsigned int id) { assert( id >= 0 && id < getNumRecords() ); buildExNPCs(); return &exNPCs[id]; }
//--------------------------------------------------------------------------- //--------------------------------------------------------------------------- bool CTDPartition::constructSupportMatrix(double epsilon) { CTDRecord* pFirstRec = NULL; if ( getNumRecords()== 0){ // Get the first record of the generalized records. pFirstRec = getGenRecords()->GetAt(0); } else { // Get the first record of the partition. pFirstRec = getRecord(0); if (!pFirstRec) { ASSERT(false); return false; } } int a = 0; CTDPartAttrib* pPartAttrib = NULL; CTDConcept* pCurrentConcept = NULL; for (POSITION pos = m_partAttribs.GetHeadPosition(); pos != NULL; ++a) { pPartAttrib = m_partAttribs.GetNext(pos); if (!pPartAttrib->m_bCandidate) // pPartAttrib->m_bCandidate is true by default. continue; // Find the current concept of this attribute. pCurrentConcept = pFirstRec->getValue(a)->getCurrentConcept(); // Need to find the split point. We also turn it true when we read the configuration file. if (pPartAttrib->getActualAttrib()->m_bVirtualAttrib) { if (!pCurrentConcept->divideConcept(epsilon, m_nClasses)) { ASSERT(false); return false; } } // If this attribute does not have child concepts, this cannot be candidate. if (pCurrentConcept->getNumChildConcepts() == 0) { pCurrentConcept->m_bCutCandidate = false; // "true" by default. pPartAttrib->m_bCandidate = false; continue; } // Construct the support matrix. if (!pPartAttrib->initSupportMatrix(pCurrentConcept, m_nClasses)) { ASSERT(false); return false; } } // initializing the noisy class sum count m_classNoisySums.SetSize(m_nClasses); for (int j = 0; j < m_nClasses; ++j) m_classNoisySums.SetAt(j, 0); // Compute the support matrix CTDConcept* pClassConcept = NULL; CTDConcept* pLowerConcept = NULL; CTDMDIntArray* pSupMatrix = NULL; CTDIntArray* pSupSums = NULL; CTDIntArray* pClassSums = NULL; CTDRecord* pRec = NULL; int nRecs = getNumRecords(); int classIdx = m_partAttribs.GetCount(); for (int r = 0; r < nRecs; ++r) { pRec = getRecord(r); // Get the class concept. pClassConcept = pRec->getValue(classIdx)->getCurrentConcept(); ++m_classNoisySums[pClassConcept->m_childIdx]; // Compute support counts for each attribute int aIdx = 0; for (POSITION pos = m_partAttribs.GetHeadPosition(); pos != NULL; ++aIdx) { // The partition attribute. pPartAttrib = m_partAttribs.GetNext(pos); if (!pPartAttrib->m_bCandidate) continue; // Get the lower concept value pLowerConcept = pRec->getValue(aIdx)->getLowerConcept(); if (!pLowerConcept) { cerr << _T("No more child concepts. This should not be a candidate.") << endl; ASSERT(false); return false; } // Construct the support matrix. pSupMatrix = pPartAttrib->getSupportMatrix(); if (!pSupMatrix) { ASSERT(false); return false; } ++((*pSupMatrix)[pLowerConcept->m_childIdx][pClassConcept->m_childIdx]); // Compute the support sum of this matrix. pSupSums = pPartAttrib->getSupportSums(); if (!pSupSums) { ASSERT(false); return false; } ++((*pSupSums)[pLowerConcept->m_childIdx]); // Compute the class sum of this matrix. pClassSums = pPartAttrib->getClassSums(); if (!pClassSums) { ASSERT(false); return false; } ++((*pClassSums)[pClassConcept->m_childIdx]); } } return true; }
main() { /* Declarations Start */ status_code SC; boolean boolval; FILE *fp; employee_type *emp_ptr,*ptr; employee_type *list1,*list2,*list3; employee_type *duplicate; empname_type *name_ptr,*ptr_name; char dumbo[2]; char emp_name[NAME_LEN]; char proj_name[NAME_LEN]; char c; unsigned int Hrs; unsigned int emp_salary; char emp_address[ADD_LEN]; unsigned long int phone; int option,contnue; int numRecords,maxNumHrs; /* Declarations End */ /* Initialisations Start */ emp_ptr=NULL; name_ptr=NULL; ptr_name=NULL; ptr=NULL; list1=NULL; list2=NULL; list3=NULL; duplicate=NULL; fp=NULL; /* Initialisations End */ /* Start Reading Data from File */ fp=fopen("record.txt","a"); fclose(fp); fp=fopen("record.txt","r"); while((c=getc(fp)) != EOF) { fseek(fp,-sizeof(char),1); fscanf(fp,"%s %s %u %u %s %lu",emp_name,proj_name,&Hrs,&emp_salary,emp_address,&phone); SC=insert(&emp_ptr,emp_name,proj_name,Hrs,emp_salary,emp_address,phone); } fclose(fp); fp=NULL; /* End Reading Data from File */ do { /* Asking for Option */ puts("ENTER the option as per the operation you want to do. ENTER :-\n"); puts("1- insert/update\n2- delete\n3- getNumRecords\n4- isEmpty\n5- List_Unique\n6- getMaxNumHrs\n7- list_union\n8- list_intersection\n9- list_difference\n10- list_symmetric_difference\n"); printf("Your Choice is:- "); scanf("%d",&option); printf("\n\n"); switch (option) { /* INSERT/UPDATE */ case 1: { printf("***********INSERT**********\n\n"); /* Data Entering Start */ printf("Enter Employee Name :-\t"); gets(dumbo); gets(emp_name); remove_space_make_uppercase(emp_name); printf("Enter Employee's Project Name :-\t"); gets(proj_name); remove_space_make_uppercase(proj_name); printf("Enter Number of Hours :-\t"); scanf("%u",&Hrs); printf("Enter Employee's Salary :-\t"); scanf("%u",&emp_salary); printf("Enter Employee's Address :-\t"); gets(dumbo); gets(emp_address); remove_space_make_uppercase(emp_address); printf("Enter Employee's Phone Number :-\t"); scanf("%lu",&phone); /* Data Entering End */ /* Inserting/Updating Data */ SC=insert(&emp_ptr,emp_name,proj_name,Hrs,emp_salary,emp_address,phone); if(SC==SUCCESS) { puts("\n**********Data inserted**********\n"); } else { puts("\n**********Data insertion failed**********\n"); } break; } /* DELETE */ case 2: { printf("***********DELETE**********\n\n"); /* Data Entering Start */ printf("Enter Employee Name :-\t"); gets(dumbo); gets(emp_name); remove_space_make_uppercase(emp_name); printf("Enter Employee's Project Name :-\t"); gets(proj_name); remove_space_make_uppercase(proj_name); /* Data Entering End */ /* Deleting Data */ SC=delete_entry(&emp_ptr,emp_name,proj_name); if(SC==SUCCESS) { puts("\n**********Data deleted**********\n"); } else { puts("\n**********Data deletion failed**********\n"); } break; } /* getNumRecords */ case 3: { printf("***********getNumRecords**********\n\n"); numRecords=getNumRecords(emp_ptr); printf("\n\nNumber of ACTIVE record in the list is :- %d",numRecords); break; } /* isEmpty */ case 4: { printf("***********isEmpty**********\n\n"); boolval=isEmpty(emp_ptr); if(boolval==NO) { puts("The list is NOT EMPTY"); } else { puts("The list is EMPTY"); } break; } /* list_unique */ case 5: { printf("***********list_unique**********\n\n"); /* Creating Duplicate Entries for Testing */ duplicate=create_duplicate(); list_unique(duplicate); printf("\n\n*****LIST MADE UNIQUE*****\n\n"); print(duplicate); freeof_employee(&duplicate); break; } /* getMaxNumHrs */ case 6: { printf("***********getMaxNumHrs**********\n\n"); /* Data Entering Start */ printf("Enter Project Name :-\t"); gets(dumbo); gets(proj_name); remove_space_make_uppercase(proj_name); /* Data Entering End */ maxNumHrs=getMaxNumHrs(emp_ptr,proj_name,&name_ptr); printf("\nMaximum hours spent in the given project is :- %d\n\n",maxNumHrs); if(maxNumHrs!=0) { printf("Employee's spending maximum hours in this project are :-\n"); ptr_name=name_ptr; while(ptr_name!=NULL) { puts(ptr_name->employee_name); ptr_name=ptr_name->next; } } freeof_empname(&name_ptr); ptr_name=NULL; break; } /* list_union */ case 7: { printf("***********list_union**********\n\n"); /* Creating list1 and list2 for Testing */ puts("*****Creating Testing Entries for list1*****"); list1=create_checklist(); puts("*****Creating Testing Entries for list2*****"); list2=create_checklist(); list3=list_union(list1,list2); printf("\n\n*****UNION of the given lists is as follows*****\n\n"); print(list3); freeof_employee(&list1); freeof_employee(&list2); freeof_employee(&list3); break; } /* list_intersection */ case 8: { printf("***********list_intersection**********\n\n"); /* Creating list1 and list2 for Testing */ puts("*****Creating Testing Entries for list1*****"); list1=create_checklist(); puts("*****Creating Testing Entries for list2*****"); list2=create_checklist(); list3=list_intersection(list1,list2); printf("\n\n*****INTERSECTION of the given lists is as follows*****\n\n"); print(list3); freeof_employee(&list1); freeof_employee(&list2); freeof_employee(&list3); break; } /* list_difference */ case 9: { printf("***********list_difference**********\n\n"); /* Creating list1 and list2 for Testing */ puts("*****Creating Testing Entries for list1*****"); list1=create_checklist(); puts("*****Creating Testing Entries for list2*****"); list2=create_checklist(); list3=list_difference(list1,list2); printf("\n\n*****DIFFERENCE of the given lists is as follows*****\n\n"); print(list3); freeof_employee(&list1); freeof_employee(&list2); freeof_employee(&list3); break; } /* list_symmetric_difference */ case 10: { printf("***********list_symmetric_difference**********\n\n"); /* Creating list1 and list2 for Testing */ puts("*****Creating Testing Entries for list1*****"); list1=create_checklist(); puts("*****Creating Testing Entries for list2*****"); list2=create_checklist(); list3=list_symmetric_difference(list1,list2); printf("\n\n*****SYMMETRIC DIFFERENCE of the given lists is as follows*****\n\n"); print(list3); freeof_employee(&list1); freeof_employee(&list2); freeof_employee(&list3); break; } /* Default */ default: { break; } } /* Asking for CHOICE to Continue */ puts("\n\nIf you want to continue... ? Enter 1 if YES or 0 if NO\n"); printf("Your Choice is:- "); scanf("%d",&contnue); printf("\n\n"); }while(contnue==1); /* Start Writing Data from File */ fp=fopen("record.txt","w"); ptr=emp_ptr; while(ptr!=NULL) { fprintf(fp,"%s %s %u %u %s %lu",ptr->employee_name,ptr->project_name,ptr->numHrs,ptr->employee_salary,ptr->employee_address,ptr->phone_number); ptr=ptr->next; } fclose(fp); fp=NULL; /* End Writing Data from File */ if(emp_ptr!=NULL) { print(emp_ptr); freeof_employee(&emp_ptr); } getch(); }