/* ------------------------------------------------------------- This file is a component of SDPA Copyright (C) 2004-2013 SDPA Project This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ------------------------------------------------------------- */ #include #include #include using namespace sdpa; #define USER_PARAMETER_FILE ((char *)"./param.sdpaC") #define DEFAULT_PARAMETER_FILE ((char *)"/usr/share/sdpa/param.sdpaC") // PARAMETER_FILE is decided by the following priority // 1: The file assigned by '-p' option of 'option type 2'. // For 'option type1', this is skipped. // 2: USER_PARAMETER_FILE // For 'option type2', this is skipped. // 3: DEFAULT_PARAMETER_FILE // 4: Default parameter static void message(char* argv0) { cout << endl; cout << "*** Please assign data file and output file.***" << endl; cout << endl; cout << "---- option type 1 ------------" << endl; cout << argv0 <<" SparseDataFile OutputFile" " [-pt parameters] [-dimacs] [-numThreads numThreads]"<< endl; cout << "parameters = 0 default, 1 fast (unstable)," " 2 slow (stable)" << endl; cout << " -dimacs : printout dimacs information incurring additional computation cost " << endl; cout << " -numThreads: Number of pthreads for internal computation" << endl; cout << "example1-1: " << argv0 << " example1.dat-s example1.result" << endl; cout << "example1-2: " << argv0 << " example1.dat-s example1.result -pt 2" << endl; cout << "example1-3: " << argv0 << " example1.dat-s example1.result -dimacs" << endl; cout << "example1-4: " << argv0 << " example1.dat-s example1.result -numThreads 4" << endl; cout << endl; cout << "---- option type 2 ------------" << endl; cout << argv0 << " [option filename]+ " << endl; cout << " -ds : data sparse " << endl; cout << " -o : output :: -p : parameter " << endl; cout << " -pt : parameters , 0 default, 1 fast (unstable)" << endl; cout << " 2 slow (stable) " << endl; cout << " -dimacs : printout dimacs information incurring additional computation cost " << endl; cout << " -numThreads: Number of pthreads for internal computation" << endl; cout << "example2-1: " << argv0 << " -ds example1.dat-s -o example1.result " << "-p param.sdpaC" << endl; cout << "example2-2: " << argv0 << " -ds example1.dat-s -o example1.result " << "-pt 2" << endl; cout << "example2-3: " << argv0 << " -ds example1.dat-s -o example1.result " << "-dimacs" << endl; cout << "example2-4: " << argv0 << " -ds example1.dat-s -o example1.result " << "-numThreads 4" << endl; cout << endl; cout << "---- option type 3 ------------" << endl; cout << argv0 << " --version " << endl; cout << " to print out version and exit." << endl; cout << endl << endl; cout << "PARAMETER_FILE is decided by the following priority" << endl; cout << " 1: The file assigned by '-p' option of 'option type 2'." << endl; cout << " For 'option type1', this is skipped." << endl; cout << " 2: " << USER_PARAMETER_FILE << endl; cout << " For 'option type2', this is skipped." << endl; cout << " 3: " << DEFAULT_PARAMETER_FILE << endl; cout << " 4: Default parameter" << endl; exit(1); } static void argumentAnalysis(SDPA& Problem1, int argc, char** argv, char*& inputFileName, char*& resultFileName, char*& paramFileName, SDPA::ParameterType& parameterType, bool& isDimacs, int& numThreads) { if (argc == 1) { message(argv[0]); } if (strcmp(argv[1],"--version") == 0) { fprintf(stdout,"====\n"); fprintf(stdout,"SDPA-C (SemiDefinite Programming Algorithm with Completion) %s\n",sdpa_version); fprintf(stdout," %s\n",sdpa_right); fprintf(stdout,"====\n"); exit(0); } if (argv[1][0] == '-') { // rsdpa argument for (int index = 0; index < argc; ++index) { char* target = argv[index]; if (strcmp(target,"-dd")==0 && index+1 < argc) { fprintf(stdout,"*** Dense Data is NOT supported ***\n"); inputFileName = argv[index+1]; inputFileName = NULL; // isInputSparse = SDPA::DENSE; index++; continue; } if (strcmp(target,"-ds")==0 && index+1 < argc) { inputFileName = argv[index+1]; // isInputSparse = SDPA::SPARSE; continue; } if (strcmp(target,"-o")==0 && index+1 < argc) { resultFileName = argv[index+1]; index++; continue; } if (strcmp(target,"-p")==0 && index+1 < argc) { paramFileName = argv[index+1]; index++; continue; } if (strcmp(target,"-dimacs")==0) { isDimacs = true; continue; } if (strcmp(target,"-pt")==0 && index+1 < argc) { int tmp = atoi(argv[index+1]); switch (tmp) { case 0: parameterType = SDPA::PARAMETER_DEFAULT; break; case 1: parameterType = SDPA::PARAMETER_UNSTABLE_BUT_FAST; break; case 2: parameterType = SDPA::PARAMETER_STABLE_BUT_SLOW; break; default: parameterType = SDPA::PARAMETER_DEFAULT; } index++; paramFileName = NULL; continue; } if (strcmp(target,"-numThreads")==0 && index+1 < argc) { numThreads = atoi(argv[index+1]); index++; continue; } } } else { // SDPA argument inputFileName = argv[1]; int len = strlen(inputFileName); if (inputFileName[len-1] == 's' && inputFileName[len-2] == '-') { } else { fprintf(stdout, "File may not be Sparse SDPA format. \n"); fprintf(stdout, "The file extension must be 'dat-s'. \n"); inputFileName = NULL; } resultFileName = argv[2]; paramFileName = USER_PARAMETER_FILE; for (int index=3; index