00001 /* $Id: template.cpp 3348 2010-03-27 10:53:47Z kmartin $ */ 00017 #include "OSCoinSolver.h" 00018 #include "OSResult.h" 00019 #include "OSiLReader.h" 00020 #include "OSiLWriter.h" 00021 #include "OSoLReader.h" 00022 #include "OSrLReader.h" 00023 #include "OSrLWriter.h" 00024 #include "OSInstance.h" 00025 #include "OSOption.h" 00026 #include "OSoLWriter.h" 00027 #include "OSFileUtil.h" 00028 #include "OSConfig.h" 00029 #include "OSDefaultSolver.h" 00030 #include "OSWSUtil.h" 00031 #include "OSSolverAgent.h" 00032 #include "OShL.h" 00033 #include "OSErrorClass.h" 00034 #include "OSmps2osil.h" 00035 #include "OSBase64.h" 00036 00037 00038 00039 00040 using std::ostringstream; 00041 00042 00043 #ifdef COIN_HAS_KNITRO 00044 #include "OSKnitroSolver.h" 00045 #endif 00046 00047 00048 00049 00050 00051 #ifdef COIN_HAS_LINDO 00052 #include "OSLindoSolver.h" 00053 #endif 00054 00055 /* 00056 #ifdef COIN_HAS_IPOPT 00057 #ifndef COIN_HAS_ASL 00058 #include "OSIpoptSolver.h" 00059 #undef COIN_HAS_ASL 00060 #else 00061 #include "OSIpoptSolver.h" 00062 #endif 00063 #endif 00064 */ 00065 00066 #ifdef COIN_HAS_ASL 00067 #include "OSnl2osil.h" 00068 #endif 00069 00070 #ifdef HAVE_CTIME 00071 # include <ctime> 00072 #else 00073 # ifdef HAVE_TIME_H 00074 # include <time.h> 00075 # else 00076 # error "don't have header file for time" 00077 # endif 00078 #endif 00079 00080 //#ifdef COIN_HAS_IPOPT 00081 //#include "OSIpoptSolver.h" 00082 //#endif 00083 00084 #ifdef COIN_HAS_IPOPT 00085 #ifndef COIN_HAS_ASL 00086 #include "OSIpoptSolver.h" 00087 #undef COIN_HAS_ASL 00088 #else 00089 #include "OSIpoptSolver.h" 00090 #endif 00091 #endif 00092 00093 00094 00095 #ifdef COIN_HAS_BONMIN 00096 #include "OSBonminSolver.h" 00097 #endif 00098 00099 #ifdef COIN_HAS_COUENNE 00100 #include "OSCouenneSolver.h" 00101 #endif 00102 00103 00104 #include "OSOptionsStruc.h" 00105 00106 00107 using std::cout; 00108 using std::endl; 00109 using std::ostringstream; 00110 using std::string; 00111 00112 00113 00114 00115 00116 int main(int argC, char* argV[]){ 00117 00118 // template -- add your code here -- // 00119 00120 // temporary experimentation by Kipp 00121 std::cout << "Hello World" << std::endl; 00122 FileUtil *fileUtil = NULL; 00123 fileUtil = new FileUtil(); 00124 std::cout << std::endl << std::endl; 00125 size_t i; 00126 size_t numberOfNonlinearExpressions; 00127 numberOfNonlinearExpressions = 1000000; 00130 Nl **nlarray; 00131 nlarray = new Nl*[ numberOfNonlinearExpressions ]; 00132 OSnLNodeNumber *nlNodeNumberPoint; 00133 00134 std::vector<Nl*> nlVec; 00135 std::cout << "Start Loop " << std::endl; 00136 for(i = 0; i < numberOfNonlinearExpressions ; i++){ 00137 nlarray[ i] = new Nl(); 00138 nlarray[i]->idx = i; 00139 nlarray[ i]->osExpressionTree = new OSExpressionTree(); 00140 nlNodeNumberPoint = new OSnLNodeNumber(); 00141 nlNodeNumberPoint->value = 77.77; 00142 nlarray[ i]->osExpressionTree->m_treeRoot = nlNodeNumberPoint; 00143 nlVec.push_back( nlarray[ i]) ; 00144 00145 } 00146 00147 std::cout << "End Loop" << std::endl; 00148 00149 /* 00150 OSnLNodeNumber *nlNodeNumberPoint; 00151 std::vector<OSnLNodeNumber*> nlNodeVec; 00152 std::cout << "Start OSnLNumberNode loop" << std::endl; 00153 for(int i = 0; i <10000; i++){ 00154 nlNodeNumberPoint = new OSnLNodeNumber(); 00155 nlNodeNumberPoint->value = 77.77; 00156 new Nl(); 00157 nlNodeVec.push_back( nlNodeNumberPoint); 00158 } 00159 std::cout << "Finish OSnLNumberNode loop" << std::endl; 00160 */ 00161 //garbage collection 00162 00163 for(i = 0; i < numberOfNonlinearExpressions; i++){ 00164 delete nlarray[i]; 00165 nlarray[i] = NULL; 00166 } 00167 delete[] nlarray; 00168 nlarray = NULL; 00169 00170 delete fileUtil; 00171 00172 return 0; 00173 00174 // OSnl2osil *nl2osil = NULL; 00175 // try { 00176 00177 // double cpuTime; 00178 // cpuTime = CoinCpuTime(); 00179 //get the size of the nl string 00180 //std::string nlstring = fileUtil->getFileAsString("../../../../OS/data/amplFiles/blpmpec1.nl"); 00181 // std::string nlstring = fileUtil->getFileAsString("smalltest.nl"); 00182 // std::cout << "nl string size = " << nlstring.size() << std::endl; 00183 // std::cout << "start the process " << std::endl; 00184 // //nl2osil = new OSnl2osil( "../../../../OS/data/amplFiles/BLPMPEC.nl"); 00185 // nl2osil = new OSnl2osil( "smalltest.nl"); 00186 // std::cout << "nl file read " << std::endl; 00187 // cpuTime = CoinCpuTime() - cpuTime; 00188 // std::cout << "Time to read nl file: " << cpuTime << std::endl; 00189 // nl2osil->createOSInstance() ; 00190 // std::cout << "Number Variable = " << nl2osil->osinstance->getVariableNumber() << std::endl; 00191 // std::cout << "Number Constraints = " << nl2osil->osinstance->getConstraintNumber() << std::endl; 00192 // 00193 // 00194 // std::cout << "an osinstance created " << std::endl; 00195 // cpuTime = CoinCpuTime() - cpuTime; 00196 // std::cout << "Time to create osinstance : " << cpuTime << std::endl; 00197 // 00198 // std::cout << "Initialize Nonlinear Structures" << std::endl; 00199 // nl2osil->osinstance->initForAlgDiff( ); 00200 // cpuTime = CoinCpuTime() - cpuTime; 00201 // std::cout << "Time to initialize Nonlinear Structures : " << cpuTime << std::endl; 00202 00203 00204 // std::cout << "Get Sparse Jacobian" << std::endl; 00205 // SparseJacobianMatrix *sparseJac; 00206 // sparseJac = nl2osil->osinstance->getJacobianSparsityPattern(); 00207 // cpuTime = CoinCpuTime() - cpuTime; 00208 // std::cout << "Time to get Sparse Jacobian pattern : " << cpuTime << std::endl; 00209 // 00210 // SparseHessianMatrix *sparseHessian = nl2osil->osinstance->getLagrangianHessianSparsityPattern(); 00211 // cpuTime = CoinCpuTime() - cpuTime; 00212 // std::cout << "Time to get Sparse Hessain pattern : " << cpuTime << std::endl; 00213 // OSiLWriter *osilwriter = NULL; 00214 // osilwriter = new OSiLWriter(); 00215 // std::string osil; 00216 // osil = osilwriter->writeOSiL( nl2osil->osinstance) ; 00217 // std::cout << "osil generated" << std::endl; 00218 // cpuTime = CoinCpuTime() - cpuTime; 00219 // std::cout << "Time to create osil : " << cpuTime << std::endl; 00220 // std::cout << "Size of osil string : " << osil.size() << std::endl; 00221 //fileUtil->writeFileFromString("tmp.osil", osil); 00222 // delete nl2osil; 00223 // std::cout << "nl2osil deleted " << std::endl; 00224 // cpuTime = CoinCpuTime() - cpuTime; 00225 // std::cout << "Time to delete nl2osil : " << cpuTime << std::endl; 00226 // delete fileUtil; 00227 // delete osilwriter; 00228 00229 // } 00230 // catch(const ErrorClass& eclass){ 00231 // std::cout << "THERE WAS AN ERROR" << std::endl; 00232 // delete fileUtil; 00233 // delete nl2osil; 00234 // std::cout << "THERE WAS AN ERROR" << std::endl; 00235 // std::cout << eclass.errormsg << std::endl; 00236 // return 0; 00237 // } 00238 00239 00240 00241 00242 // time_t rawtime; 00243 // struct tm * timeinfo; 00244 // int year, month ,day; 00245 // char * weekday[] = { "Sunday", "Monday", 00246 // "Tuesday", "Wednesday", 00247 // "Thursday", "Friday", "Saturday"}; 00248 // int days_per_month[] = {31, 28, 31, 30, 00249 // 31, 30, 31, 31, 30, 31, 30, 31}; 00250 // 00251 // 00252 // 00253 // /* prompt user for date */ 00254 // printf ("Enter year: "); scanf ("%d",&year); 00255 // printf ("Enter month: "); scanf ("%d",&month); 00256 // 00257 // // adjust for leap year 00258 // if ( ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) { 00259 // days_per_month[ 1] = 29; 00260 // } 00261 // std::cout << "GAIL = " << year % 4 << std::endl; 00262 // /* get current timeinfo and modify it to the user's choice */ 00263 // time ( &rawtime ); 00264 // timeinfo = localtime ( &rawtime ); 00265 // timeinfo->tm_year = year - 1900; 00266 // timeinfo->tm_mon = month - 1; 00267 // timeinfo->tm_mday = 1; 00268 // 00269 // /* call mktime: timeinfo->tm_wday will be set */ 00270 // mktime ( timeinfo ); 00271 // 00272 // printf ("That day is a %s.\n", weekday[timeinfo->tm_wday]); 00273 // std::cout << "Days in this month = " << days_per_month[ month-1] << std::endl; 00274 00275 }// end main 00276