int main(int argc, char ** argv){ //first, read the data in files into an array in order to process it more efficiently. record_item_struct * item_data = (record_item_struct *) _mm_malloc(sizeof(record_item_struct)*RECORD_COUNT,64); memset(item_data, 0, sizeof(record_item_struct)*RECORD_COUNT); get_item_data(item_data, argv[1]); float * item_block_data_i = (float*)_mm_malloc(sizeof(float)*ITEM_BLOCK*USER_COUNT,64); float * item_block_data_j = (float*)_mm_malloc(sizeof(float)*ITEM_BLOCK*USER_COUNT,64); if (item_block_data_i==NULL || item_block_data_j == NULL) { printf(" malloc of base_data failed\n"); exit(1); } double * item_average_matrix = (double*)_mm_malloc(sizeof(double)*ITEM_COUNT,64); memset(item_average_matrix,0,sizeof(double)*ITEM_COUNT); k_similarity_struct * item_index_matrix = (k_similarity_struct *) _mm_malloc (sizeof(k_similarity_struct)*K_SORT*ITEM_COUNT,64); memset (item_index_matrix,-1,sizeof(k_similarity_struct)); int item_start_index_i=0; int item_start_index_j=0; // int i,j; for (int i=0; i <= ITEM_ROUND; i++) { printf("round %d ================== with ITEM_BLOCK %d\n",i,ITEM_BLOCK); //block_data printf("get item_block_data begins\n"); item_start_index_i = get_item_block_data(i, item_block_data_i,item_start_index_i, item_data); printf("get_item_block_data ends\n"); //average matrix printf("get_item_average_matrix begins\n"); get_item_average_matrix(item_block_data_i, item_average_matrix,i*ITEM_BLOCK); printf("get_item_average_matrix ends\n"); item_start_index_j = 0; for(int j=0; j<= i;j++) { if( i==j) { //the index of item after sorting the similarity matrix printf("get k_similarity_begins\n"); get_pearson_similarity(item_block_data_i,item_block_data_i,item_average_matrix,item_index_matrix,i*ITEM_BLOCK,i*ITEM_BLOCK,0); printf("get k_similarity_ends\n"); continue; } //block_data printf("get item_block_data begins\n"); item_start_index_j = get_item_block_data(j, item_block_data_j, item_start_index_j, item_data); printf("get_item_block_data ends\n"); //the index of item after sorting the similarity matrix printf("get k_similarity_begins\n"); get_pearson_similarity(item_block_data_i,item_block_data_j,item_average_matrix,item_index_matrix,i*ITEM_BLOCK,j*ITEM_BLOCK,1); printf("get k_similarity_ends\n"); } } _mm_free(item_block_data_i); _mm_free(item_block_data_j); int *test_data; float *test_rating; test_data = (int*)_mm_malloc (sizeof(int)*2*TEST_COUNT,64); test_rating= (float*)_mm_malloc(sizeof(float)*TEST_COUNT,64); printf("get_test_data begins\n"); get_test_data(test_data,test_rating); printf("get_test_data ends\n"); long user_file_start_index = 0; float * user_block_data = (float*)_mm_malloc(sizeof(float)*USER_BLOCK*ITEM_COUNT,64); if (user_block_data==NULL) { printf(" malloc of base_data failed\n"); exit(1); } int test_start_index = 0; double * item_predict_rating = (double*)_mm_malloc (sizeof(double)*TEST_COUNT,64); for(int i=0;i<=USER_ROUND;i++) { user_file_start_index = get_user_block_data(i,user_block_data, user_file_start_index); printf("get_predict_rating begins\n"); test_start_index=get_predict_rating(item_predict_rating, user_block_data, item_index_matrix, test_data,item_average_matrix,i*USER_BLOCK, test_start_index); printf("get_predict_rating ends\n"); if ( test_start_index == TEST_COUNT) break; } _mm_free (user_block_data); double rmse; printf("get_rmse begins\n"); rmse = get_rmse(test_rating,item_predict_rating); printf("ge_rmse ends\n"); printf("rmse= %f\n", rmse); return 0; }
/* * changed this to take a filename so we can pass config files on the command line * default is config.xml */ sConfigData::sConfigData(const char *a_filename) : fonts() { DirPath dp = DirPath() << a_filename; // `J` moved to root directory DirPath dpold = DirPath() << "Resources" << "Data" << a_filename; string filename = dp.c_str(); string filenameold = dpold.c_str(); l.ss() << "Loading configuration variables from '" << filename << "'"; l.ssend(); /* * make sure we have something playable, * even if the file doesn't load */ set_defaults(); /* * open the file - moan most eloqently in its absence */ TiXmlDocument doc(filename); TiXmlDocument docold(filenameold); if (!doc.LoadFile()) { l.ss() << "Can't load " << filename << " from root directory." << endl << "Error: line " << doc.ErrorRow() << ", col " << doc.ErrorCol() << ": " << doc.ErrorDesc() << endl << "Attempting to load old file " << filenameold << "." << endl; l.ssend(); doc = docold; } if (!doc.LoadFile()) { l.ss() << "can't load " << filename << endl << "Error: line " << doc.ErrorRow() << ", col " << doc.ErrorCol() << ": " << doc.ErrorDesc(); l.ssend(); /* * a bit of narrative for the players: makes it easier to tell * if the config isn't being found */ l.ss() << "*** Game will run with default pricing factors.\n*** This may seem a little easy. To fix this\n*** get a config.xml file from pinkpetal.org\n*** or make one with W***e Master Editor"; l.ssend(); return; } /* * get the docuement root */ TiXmlElement *el, *root_el = doc.RootElement(); /* * loop over the elements attached to the root */ for (el = root_el->FirstChildElement(); el; el = el->NextSiblingElement()) { string tag = el->ValueStr(); // now, depending on the tag name... if (el->ValueStr() == "Folders") { get_folders_data(el); continue; } if (el->ValueStr() == "Resolution") { get_resolution_data(el); continue; } if (el->ValueStr() == "Initial") { get_initial_values(el); continue; } if (el->ValueStr() == "Income") { get_income_factors(el); continue; } if (el->ValueStr() == "Expenses") { get_expense_factors(el); continue; } if (el->ValueStr() == "Gambling") { get_gambling_factors(el); continue; } if (el->ValueStr() == "Prostitution") { get_pros_factors(el); continue; } if (el->ValueStr() == "Catacombs") { get_catacombs_data(el); continue; } if (el->ValueStr() == "SlaveMarket") { get_slave_market_data(el);continue; } if (el->ValueStr() == "Pregnancy") { get_preg_factors(el); continue; } if (el->ValueStr() == "Tax") { get_tax_factors(el); continue; } if (el->ValueStr() == "Gangs") { get_gang_factors(el); continue; } if (el->ValueStr() == "Items") { get_item_data(el); continue; } if (el->ValueStr() == "Fonts") { get_font_data(el); continue; } if (el->ValueStr() == "Debug") { get_debug_flags(el); continue; } l.ss() << "Warning: config.xml: tag: '" << tag << "' unexpected"; l.ssend(); } // check interface for colors DirPath dpi = DirPath() << "Resources" << "Interface" << resolution.resolution << "InterfaceColors.xml"; TiXmlDocument doci(dpi.c_str()); if (doci.LoadFile()) { string m_filename = dpi.c_str(); TiXmlElement *el, *root_el = doci.RootElement(); for (el = root_el->FirstChildElement(); el; el = el->NextSiblingElement()) { string tag = el->ValueStr(); if (tag == "Color") { XmlUtil xu(m_filename); string name; int r, g, b; xu.get_att(el, "Name", name); xu.get_att(el, "R", r); xu.get_att(el, "G", g); xu.get_att(el, "B", b); /* */if (name == "ItemRarity0") ColorConvert.RGBToSDLColor(items.rarity_color[0], r, g, b); else if (name == "ItemRarity1") ColorConvert.RGBToSDLColor(items.rarity_color[1], r, g, b); else if (name == "ItemRarity2") ColorConvert.RGBToSDLColor(items.rarity_color[2], r, g, b); else if (name == "ItemRarity3") ColorConvert.RGBToSDLColor(items.rarity_color[3], r, g, b); else if (name == "ItemRarity4") ColorConvert.RGBToSDLColor(items.rarity_color[4], r, g, b); else if (name == "ItemRarity5") ColorConvert.RGBToSDLColor(items.rarity_color[5], r, g, b); else if (name == "ItemRarity6") ColorConvert.RGBToSDLColor(items.rarity_color[6], r, g, b); else if (name == "ItemRarity7") ColorConvert.RGBToSDLColor(items.rarity_color[7], r, g, b); else if (name == "ItemRarity8") ColorConvert.RGBToSDLColor(items.rarity_color[8], r, g, b); } } } fonts.detailfontsize = 9; // default to 9 then check if it is set in girl_details_screen.xml DirPath dpt = DirPath() << "Resources" << "Interface" << resolution.resolution << "girl_details_screen.xml"; TiXmlDocument doct(dp.c_str()); if (doct.LoadFile()) { string m_filename = dpt.c_str(); TiXmlElement *el, *root_el = doct.RootElement(); for (el = root_el->FirstChildElement(); el; el = el->NextSiblingElement()) { string tag = el->ValueStr(); if (tag == "Text") { XmlUtil xu(m_filename); string name; int f = 9; xu.get_att(el, "Name", name); xu.get_att(el, "FontSize", f, true); if (name == "GirlDescription" && f > 0) { fonts.detailfontsize = f; break; } } } } }