OperationPathList::OperationPathList(std::queue<std::wstring> & oArgList) : Operation(oArgList) { // exit if there are not enough arguments to parse std::vector<std::wstring> sSubArgs = ProcessAndCheckArgs(1, oArgList, L"\\0"); // open the file std::wifstream fFile(sSubArgs[0].c_str()); // adapt the stream to read windows unicode files (void) fFile.imbue(std::locale(fFile.getloc(), new std::codecvt_utf8<wchar_t, 0x10ffff, std::consume_header>)); // read the file line-by-line std::wstring sLine; while (std::getline(fFile, sLine)) { // sometimes a carriage return appears in the input stream so adding // it here ensures it is stripped from the very end std::vector<std::wstring> oLineItems = SplitArgs(sLine, L"\r"); if (oLineItems.size() != 1) { wprintf(L"ERROR: Unable to parse string path list file."); exit(-1); } // store off the argument InputOutput::ScanPaths().push_back(oLineItems[0]); } // cleanup fFile.close(); };
void Shader::LoadFragmentShader(const std::string &pFilename){ // Creation des shaders mFShader = glCreateShader(GL_FRAGMENT_SHADER); // Récupération de la source std::string filePath = ResourceManager::Call().FindFile(pFilename, "Shader"); if(filePath == "0") throw Exception(String("Fragment Shader file \"")+pFilename+"\" does not exist. Double check file path!"); File fFile(filePath); std::string fSourceStr = fFile.Read(); const char* fSource = fSourceStr.c_str(); glShaderSource(mFShader, 1, &fSource, NULL); // Compilation glCompileShader(mFShader); // Vérification GLint error; glGetShaderiv(mFShader, GL_COMPILE_STATUS, &error); if(error != GL_TRUE){ char log[1024]; glGetShaderInfoLog(mFShader, 1024, NULL, log); if(mVShader) glDeleteShader(mVShader); glDeleteShader(mFShader); if(mGShader) glDeleteShader(mGShader); throw Exception(String("Fragment Shader Compilation Error (\"")+pFilename+"\") :\n"+log); } }
void Z3DShaderProgram::loadFromSourceFile(const QString &vertFilename, const QString &geomFilename, const QString &fragFilename, const QString &header) { m_vertSrcs.clear(); m_geomSrcs.clear(); m_fragSrcs.clear(); // vert QString vFilename = Z3DApplication::app()->getShaderPath(vertFilename); QFile vFile(vFilename); if (!vFile.open(QIODevice::ReadOnly | QIODevice::Text)) { throw Exception(QString("Can not open vertex shader file: %1. Error String: %2").arg(vFilename).arg(vFile.errorString()).toStdString()); } m_vertSrcs.push_back(QString()); m_vertSrcs[0] = vFile.readAll(); vFile.close(); // geom if (!geomFilename.isEmpty()) { QString gFilename = Z3DApplication::app()->getShaderPath(geomFilename); QFile gFile(gFilename); if (!gFile.open(QIODevice::ReadOnly | QIODevice::Text)) { throw Exception(QString("Can not open geometry shader file: %1. Error String: %2").arg(gFilename).arg(gFile.errorString()).toStdString()); } m_geomSrcs.push_back(QString()); m_geomSrcs[0] = gFile.readAll(); gFile.close(); } // frag QString fFilename = Z3DApplication::app()->getShaderPath(fragFilename); QFile fFile(fFilename); if (!fFile.open(QIODevice::ReadOnly | QIODevice::Text)) { throw Exception(QString("Can not open fragment shader file: %1. Error String: %2").arg(fFilename).arg(fFile.errorString()).toStdString()); } m_fragSrcs.push_back(QString()); m_fragSrcs[0] = fFile.readAll(); fFile.close(); // load loadFromSourceCode(m_vertSrcs, m_geomSrcs, m_fragSrcs, header); }
/******************************************************************************* * MAIN * ******************************************************************************/ int main(int argc, char** argv) { if (argc <= REQUIRED_PARAMS_NUM) { usage(argv[0]); } const char* fileNameE = argv[1]; const char* fileNameF = argv[2]; const char* fileNameA = argv[3]; maxPhraseLength = std::atoi(argv[4]); // read_optional_params(argc, argv, 5); // Init phrase pairs counters (add +1 for dummy zero-length counter). phrasePairsCounters.resize(maxPhraseLength + 1, 0); std::cerr << "Starting phrase pairs counter ..." << std::endl; // open input files std::ifstream eFile(fileNameE); std::ifstream fFile(fileNameF); std::ifstream aFile(fileNameA); // readInput(eFile, fFile, aFile); std::cerr << std::endl; // Leave the progress bar end on previous line. // close input files eFile.close(); fFile.close(); aFile.close(); std::cout << "############################" << std::endl << "# len # phrase pairs count #" << std::endl << "############################" << std::endl; for ( size_t i = 1; i < phrasePairsCounters.size(); ++i ) { std::cout << "# " << std::setw(3) << i << " # " << std::setw(18) << phrasePairsCounters[i] << " #" << std::endl; } std::cout << "############################" << std::endl; }
/******************************************************************************* * MAIN * ******************************************************************************/ int main(int argc, char* argv[]) { // Welcome user with program info! program_info(); if (argc <= REQUIRED_PARAMS_NUM) { usage(argv[0]); } const char* fileNameE = argv[1]; const char* fileNameF = argv[2]; const char* fileNameA = argv[3]; std::string fileNameExtract = std::string(argv[4]); // Init lossy counters. std::string lossyCountersParams; int paramIdx = 5; while ( (argc > paramIdx) && (*argv[paramIdx] != '-') ) { std::string param = std::string(argv[paramIdx]); if ( !parse_lossy_counting_params(param) ) { usage(argv[0]); } lossyCountersParams += (" " + param); ++paramIdx; } if ( paramIdx == REQUIRED_PARAMS_NUM ) { std::cerr << "ERROR: no Lossy Counting parameters specified!" << std::endl; usage(argv[0]); } for ( size_t i = 1; i < lossyCounters.size(); ++i ) { if ( lossyCounters[i] == NULL ) { std::cerr << "ERROR: max phrase length set to " << maxPhraseLength << ", but no Lossy Counting parameters specified for phrase pairs of length " << i << "!" << std::endl; usage(argv[0]); } } if ( (argc > paramIdx) && (strcmp(argv[paramIdx], "--compact") == 0) ) { compactOutputFlag = true; ++paramIdx; } if ( (argc > paramIdx) && (strcmp(argv[paramIdx], "--sort") == 0) ) { sortedOutput = true; ++paramIdx; } // read_optional_params(argc, argv, paramIdx); std::cerr << "Starting epochal phrase table extraction with params:" << lossyCountersParams << std::endl; std::cerr << "Output will be " << (sortedOutput ? "sorted" : "unsorted") << "." << std::endl; // open input files std::ifstream eFile(fileNameE); std::ifstream fFile(fileNameF); std::ifstream aFile(fileNameA); // open output files if (translationFlag) { if (sortedOutput) { extractFile.open((fileNameExtract + ".sorted").c_str()); extractFileInv.open((fileNameExtract + ".inv.sorted").c_str()); } else { extractFile.open(fileNameExtract.c_str()); extractFileInv.open((fileNameExtract + ".inv").c_str()); } } if (orientationFlag) { extractFileOrientation.open((fileNameExtract + ".o").c_str()); } // readInput(eFile, fFile, aFile); std::cerr << std::endl; // Leave the progress bar end on previous line. // close input files eFile.close(); fFile.close(); aFile.close(); FlushingOutputProcessor processor(compactOutputFlag); processOutput(processor); // close output files if (translationFlag) { extractFile.close(); extractFileInv.close(); } if (orientationFlag) { extractFileOrientation.close(); } printStats(); } // end of main()
int main(int argc, char* argv[]) { int run_num = 0; run_num = atoi(argv[1]); //read in the run number of this simulation int seed = 0; seed = atoi(argv[2]); //read in the seed for the random number generator of this simulation srand(seed); int arg = 0; int typeTest = 0; typeTest = atoi(argv[3]); //read the type of test this simulation is doing int tempTTTindex = 0; int temphysindex = 0; std::string folder = ""; //case statement of the different simulation type with TTT and hys values //as well as the folder to output to switch(typeTest) { case 0: folder = "high"; tempTTTindex = 15; temphysindex = 20; arg = 3; break; case 1: folder = "highhys"; tempTTTindex = 3; temphysindex = 15; arg = 3; break; case 2: folder = "low"; tempTTTindex = 0; temphysindex = 0; arg = 3; break; case 3: folder = "mid"; tempTTTindex = 7; temphysindex = 10; arg = 3; break; case 4: folder = "opthigh"; tempTTTindex = 15; temphysindex = 20; arg = 2; break; case 5: folder = "opthighhys"; tempTTTindex = 3; temphysindex = 15; arg = 2; break; case 6: folder = "optlow"; tempTTTindex = 0; temphysindex = 0; arg = 2; break; case 7: folder = "optmid"; tempTTTindex = 7; temphysindex = 10; arg = 2; break; default: // program should not reach here break; } //set the TTTindex array to the correct values for(int j=0; j<NUM_BASESTATION; j++) { TTTindex[j] = tempTTTindex; } //set the hysindex array to the correct values for(int k=0; k<NUM_BASESTATION; k++) { hysindex[k] = temphysindex; } TTTmaxindex = 15; hysmaxindex = 20; TTTArray[0] = 0.0; TTTArray[1] = 0.04; TTTArray[2] = 0.064; TTTArray[3] = 0.08; TTTArray[4] = 0.1; TTTArray[5] = 0.128; TTTArray[6] = 0.16; TTTArray[7] = 0.256; TTTArray[8] = 0.32; TTTArray[9] = 0.48; TTTArray[10] = 0.512; TTTArray[11] = 0.64; TTTArray[12] = 1.024; TTTArray[13] = 1.280; TTTArray[14] = 2.56; TTTArray[15] = 5.12; hysArray[0] = 0.0; hysArray[1] = 0.5; hysArray[2] = 1.0; hysArray[3] = 1.5; hysArray[4] = 2.0; hysArray[5] = 2.5; hysArray[6] = 3.0; hysArray[7] = 3.5; hysArray[8] = 4.0; hysArray[9] = 4.5; hysArray[10] = 5.0; hysArray[11] = 5.5; hysArray[12] = 6.0; hysArray[13] = 6.5; hysArray[14] = 7.0; hysArray[15] = 7.5; hysArray[16] = 8.0; hysArray[17] = 8.5; hysArray[18] = 9.0; hysArray[19] = 9.5; hysArray[20] = 10.0; //set the TTT and hys arrays to the correct values for(int i=0; i<NUM_BASESTATION; i++) { TTT[i] = TTTArray[TTTindex[i]]; hys[i] = hysArray[hysindex[i]]; } // std::cout << "Enter what operation you would like to undertake.\n"; // std::cout << "1 for generating / updating policy\n"; // std::cout << "2 for using the policy\n"; // std::cout << "3 for no learning\n"; // std:: cout << "Please enter:\n"; // // int arg; // std::cin >> arg; //this block set the function variable. //if all the code is commented in and the code above commented out then //the simulation can be run with user given parameters instead of parameters //given by the bash script. if(arg == 1) { // q-learning printf("Q-Learning started...\n"); function = 1; } else if(arg == 2) { // use policy printf("Simulation started...\n"); // printf("Enter index for TTT\n"); // int tempTTTindex; // // std::cin >> tempTTTindex; // tempTTTindex = atoi(argv[4]); // for(int j=0; j<NUM_BASESTATION; j++) { // TTT[j] = TTTArray[tempTTTindex]; // TTTindex[j] = tempTTTindex; // } // // printf("Enter index for hys\n"); // int temphysindex; // // std::cin >> temphysindex; // temphysindex = atoi(argv[5]); // for(int k=0; k<NUM_BASESTATION; k++) { // hys[k] = hysArray[temphysindex]; // hysindex[k] = temphysindex; // } function = 2; } else if(arg == 3) { printf("No learning simulation...\n"); // printf("Enter index for TTT\n"); // int tempTTTindex; // // std::cin >> tempTTTindex; // tempTTTindex = atoi(argv[4]); // for(int j=0; j<NUM_BASESTATION; j++) { // TTT[j] = TTTArray[tempTTTindex]; // TTTindex[j] = tempTTTindex; // } // // printf("Enter index for hys\n"); // int temphysindex; // // std::cin >> temphysindex; // temphysindex = atoi(argv[5]); // for(int k=0; k<NUM_BASESTATION; k++) { // hys[k] = hysArray[temphysindex]; // hysindex[k] = temphysindex; // } function = 4; } //instantiate the q-learning agents for the base stations q[0] = new q_learning(gs,0,TTTindex[0],hysindex[0]); q[1] = new q_learning(gs,1,TTTindex[1],hysindex[1]); q[2] = new q_learning(gs,2,TTTindex[2],hysindex[2]); q[3] = new q_learning(gs,3,TTTindex[3],hysindex[3]); q[4] = new q_learning(gs,4,TTTindex[4],hysindex[4]); q[5] = new q_learning(gs,5,TTTindex[5],hysindex[5]); q[6] = new q_learning(gs,6,TTTindex[6],hysindex[6]); q[7] = new q_learning(gs,7,TTTindex[7],hysindex[7]); q[8] = new q_learning(gs,8,TTTindex[8],hysindex[8]); gs->start(); //start the scheduler //this is where the simulation returns to when the schedulers is stopped by a mobile //print the results for the base stations on screen and save the q-vaules and policy //for the q-learning agents to external files for (int l=0; l<NUM_BASESTATION; l++) { bStations[l]->print(); q[l]->saveQValues(); } //This block of code writes the results out to text files in folders for(int m=0; m<NUM_BASESTATION; m++) { std::stringstream hString; hString << "results/longer/" << folder << run_num << "/basestation" << m << "/handover.txt"; handoverString = hString.str(); std::stringstream dString; dString<< "results/longer/" << folder << run_num << "/basestation" << m << "/drop.txt"; dropString = dString.str(); std::stringstream pString; pString << "results/longer/" << folder << run_num << "/basestation" << m << "/ping.txt"; pingString = pString.str(); std::stringstream fString; fString << "results/longer/" << folder << run_num << "/basestation" << m << "/failure.txt"; failureString = fString.str(); std::stringstream sString; sString << "results/longer/" << folder << run_num << "/basestation" << m << "/state.txt"; stateString = sString.str(); std::ofstream hFile (handoverString); if(hFile.is_open()) { for (std::vector<double>::iterator it=handover_total[m].begin() ; it!=handover_total[m].end(); it++) { hFile << *it << "\n"; } } hFile.close(); std::ofstream dFile (dropString); if(dFile.is_open()) { for (std::vector<double>::iterator it=drop_total[m].begin() ; it!=drop_total[m].end(); it++) { dFile << *it << "\n"; } } dFile.close(); std::ofstream pFile (pingString); if(pFile.is_open()) { for (std::vector<double>::iterator it=pingpong_total[m].begin() ; it!=pingpong_total[m].end(); it++) { pFile << *it << "\n"; } } pFile.close(); std::ofstream fFile (failureString); if(fFile.is_open()) { for (std::vector<double>::iterator it=failure_total[m].begin() ; it!=failure_total[m].end(); it++) { fFile << *it << "\n"; } } fFile.close(); std::ofstream sFile (stateString); if(sFile.is_open()) { for (std::vector<int>::iterator it=stateChanges[m].begin() ; it!=stateChanges[m].end(); it++) { sFile << *it << "\n"; } } sFile.close(); } printf("end...\n"); delete gs; //delete the scheduler to clean up return 0; }