void electre::calculate_concordance_matrix() { minconcs.resize(get_no_alts()); // for all pairs of alternatives for (int i=0;i<get_no_alts();i++) { double min = 1.0; for (int j=0;j<get_no_alts();j++) { if (i == j) {conc_matrix[matloc(i,j)] = 1.0; continue; } double sum = 0.0; // for all criteria for (int k=0;k<get_no_crit();k++) { double conc = concordance(k, alts[i], alts[j]); sum += crits[k]->get_weight() * conc; } sum /= sum_w; conc_matrix[matloc(i,j)] = sum; if (sum < min) min = sum; } minconcs[i] = min; } }
void electre_tri::analyze() { int i=0; // calc sum_w sum_w = 0.0; for (int j=0;j<get_no_crit();j++) sum_w += crits[j]->get_weight(); // classify alternatives for (int j=0;j<get_no_alts();j++) { // printf ("Classifying alternative %s...\n", alts[j]->get_name().c_str()); if (optimistic_rule) i=0; else // pessimistic i=num_classes-2; while (true) { if (optimistic_rule && i==num_classes-1) break; else if (!optimistic_rule && i==-1) break; double sum = 0.0; double sum2 = 0.0; for (int k=0;k<get_no_crit();k++) { double conc = concordance(k, alts[j], profiles[i]); double conc2 = concordance(k, profiles[i], alts[j]); sum += (crits[k]->get_weight() * conc); sum2 += (crits[k]->get_weight() * conc2); } sum /= sum_w; sum2 /= sum_w; // concordance calc'd, calc discordance double disprod = 1.0; double disprod2 = 1.0; for (int k=0;k<get_no_crit();k++) { if (crits[k]->has_veto()) { double dis = discordance(k, alts[j], profiles[i]); double dis2 = discordance(k, profiles[i], alts[j]); if (dis > sum) disprod *= ((1.0 - dis) / (1.0 - sum)); if (dis2 > sum2) disprod2 *= ((1.0 - dis2) / (1.0 - sum2)); } } sum *= disprod; sum2 *= disprod2; // printf ("disp %f %f sums %f %f\n", disprod, disprod2, sum, sum2); if (!optimistic_rule && sum >= lambda) break; else if (optimistic_rule && sum2 >= lambda & sum < lambda) break; if (optimistic_rule) i++; else i--; } // ok, let's classify, class found if (optimistic_rule) assign_to_class(j, i); else assign_to_class(j,i+1); } // end for }
int main (int argc, const char * argv[]) { char *fn; /* File name */ struct hashMap *hashTable, *hashTable2; FILE *filePtr; fn = "text1.txt";/* the file name and path */ printf("Opening file: %s \n", fn); filePtr = fopen(fn, "r"); hashTable = createMap(40, 1); char *word; while((word = getWord(filePtr)) != '\0') { insertMap(hashTable, word, 1); } printf("--------------- Testing contains --------------- \n"); assertTrue(containsKey(hashTable, "it") == 1, "Search for 'it'"); assertTrue(containsKey(hashTable, "comparison") == 1, "Search for 'comparison'"); assertTrue(containsKey(hashTable, "period") == 1, "Search for 'period'"); assertTrue(containsKey(hashTable, "despair") == 1, "Search for 'despair'"); assertTrue(containsKey(hashTable, "deriop") == 0, "Search for 'deriop'"); assertTrue(containsKey(hashTable, "yuck") == 0, "Search for 'yuck'"); printf("--------------- Testing table stats --------------- \n"); assertTrue(hashTable->tableSize == 40, "Test table size"); assertTrue(fullBuckets(hashTable) == 30, "Test full buckets"); assertTrue(emptyBuckets(hashTable) == 10, "Test empty buckets"); assertTrue(linkCount(hashTable) == 59, "Test link count"); printf("--------------- Testing remove --------------- \n"); removeKey(hashTable, "yuck"); /* Should print some type of 'not found' message */ removeKey(hashTable, "despair"); assertTrue(containsKey(hashTable, "despair") == 0, "Search for 'despair'"); printf("--------------- Printing hash table --------------- \n"); printMap(hashTable); deleteMap(hashTable); printf("--------------- New table - same text file - new hash --------------- \n"); fn = "text1.txt";/* the file name and path */ printf("Opening file: %s \n", fn); filePtr = fopen(fn, "r"); hashTable2 = createMap(40, 2); while((word = getWord(filePtr)) != '\0') { insertMap(hashTable2, word, 1); } printf("--------------- Testing table stats 2 --------------- \n"); assertTrue(hashTable2->tableSize == 80, "Test table size"); assertTrue(fullBuckets(hashTable2) == 38, "Test full buckets"); assertTrue(emptyBuckets(hashTable2) == 42, "Test empty buckets"); assertTrue(linkCount(hashTable2) == 59, "Test link count"); printf("Closing file: %s \n", fn); fclose(filePtr); /* Concordance testing */ struct hashMap * concord; fn = "text2.txt"; printf("Opening file: %s \n", fn); filePtr = fopen(fn, "r"); concord = createMap(10, 2); while((word = getWord(filePtr)) != '\0') { concordance(concord, word); } printf("--------------- Concordance table stats --------------- \n"); printf("table size: %d \n", concord->tableSize); printf("full buckets: %d \n", fullBuckets(concord)); printf("empty buckets: %d \n", emptyBuckets(concord)); printf("link count: %d \n", linkCount(concord)); /*Test further on your own */ return 0; }