00001
00023 #include <iostream>
00024 #include "OSrLReader.h"
00025 #include "OSosrl2ampl.h"
00026 #include "OSResult.h"
00027 #include "OSErrorClass.h"
00028 #include "OSMathUtil.h"
00029 #include "OSOutput.h"
00030
00031 #include "CoinHelperFunctions.hpp"
00032
00033
00034 #include "nlp.h"
00035 #include "getstub.h"
00036 #include "r_opn.hd"
00037 #include "opcode.hd"
00038
00039 #ifdef HAVE_CMATH
00040 # include <cmath>
00041 #else
00042 # ifdef HAVE_CMATH_H
00043 # include <cmath.h>
00044 # endif
00045 #endif
00046
00047 #include <sstream>
00048
00049 #include <asl.h>
00050
00051
00052 using std::cerr;
00053 using std::cout;
00054 using std::endl;
00055
00056 #ifdef HAVE_STDINT_H
00057 #include <stdint.h>
00058 #endif
00059
00060 #ifdef HAVE_STDLIB_H
00061 #include <stdlib.h>
00062 #endif
00063
00064
00065 OSosrl2ampl::OSosrl2ampl()
00066 {
00067 }
00068
00069 OSosrl2ampl::~OSosrl2ampl()
00070 {
00071 }
00072
00073 bool OSosrl2ampl::writeSolFile(std::string osrl, ASL *asl, std::string solfile)
00074 {
00075 OSrLReader *osrlreader = NULL;
00076 OSResult *osresult;
00077 std::ostringstream outStr;
00078
00079 if (osrl == "")
00080 {
00081
00082 std::string solMsg = " ";
00083 solve_result_num = 550;
00084 write_sol(const_cast<char*>(solMsg.c_str()), NULL, NULL , NULL);
00085 return true;
00086 }
00087 else
00088 {
00089 std::cout << std::endl << osrl << std::endl << std::endl << std::endl;
00090 #ifndef NDEBUG
00091 outStr.str("");
00092 outStr.clear();
00093 outStr << std::endl << osrl << std::endl << std::endl << std::endl;
00094 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSModelInterfaces, ENUM_OUTPUT_LEVEL_debug, outStr.str());
00095 #endif
00096
00097 double *x = NULL;
00098 double *y = NULL;
00099 std::string *otherVar = NULL;
00100 std::string *otherObj = NULL;
00101 std::string *otherCon = NULL;
00102
00103 double **rData = NULL;
00104 int **iData = NULL;
00105 double* rvalues = NULL;
00106 int* ivalues = NULL;
00107 int nSuffixes = 0;
00108
00109 try
00110 {
00111 osrlreader = new OSrLReader();
00112 osresult = osrlreader->readOSrL( osrl);
00113
00114
00115
00116
00120 int numSols = osresult->getSolutionNumber();
00121
00122 if (numSols == 0)
00123 {
00124
00125 std::string solMsg = " ";
00126 solve_result_num = 550;
00127 write_sol(const_cast<char*>(solMsg.c_str()), NULL, NULL , NULL);
00128 return true;
00129 }
00130
00131
00132 int i;
00133 int vecSize;
00134 int numVars = osresult->getVariableNumber();
00135 int numObjs = osresult->getObjectiveNumber();
00136 int numCons = osresult->getConstraintNumber();
00137
00138 if (numVars > 0)
00139 {
00140 x = new double[ numVars];
00141 otherVar = new std::string[numVars];
00142 }
00143 if (numCons > 0)
00144 {
00145 y = new double[ numCons];
00146 otherCon = new std::string[numCons];
00147 }
00148 if (numObjs > 0)
00149 {
00150 otherObj = new std::string[numObjs];
00151 }
00152
00153 std::vector<IndexValuePair*> primalValPair;
00154 std::vector<IndexValuePair*> dualValPair;
00155 dualValPair = osresult->getOptimalDualVariableValues( 0);
00156 primalValPair = osresult->getOptimalPrimalVariableValues( 0);
00157
00158 for (i = 0; i < numVars; i++)
00159 {
00160 x[i] = 0.0;
00161 }
00162 vecSize = primalValPair.size();
00163 for (i = 0; i < vecSize; i++)
00164 {
00165 x[ primalValPair[i]->idx ] = primalValPair[i]->value;
00166 #ifndef NDEBUG
00167 outStr.str("");
00168 outStr.clear();
00169 outStr << "index = " << primalValPair[i]->idx << std::endl;
00170 outStr << "value = " << primalValPair[i]->value << std::endl;
00171 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSModelInterfaces, ENUM_OUTPUT_LEVEL_debug, outStr.str());
00172 #endif
00173 }
00174
00175 for (i = 0; i < numCons; i++)
00176 {
00177 y[i] = 0.0;
00178 }
00179 vecSize = dualValPair.size();
00180 for (i = 0; i < vecSize; i++)
00181 {
00182 y[ dualValPair[i]->idx ] = dualValPair[i]->value;
00183 #ifndef NDEBUG
00184 outStr.str("");
00185 outStr.clear();
00186 outStr << "index = " << dualValPair[i]->idx << std::endl;
00187 outStr << "value = " << dualValPair[i]->value << std::endl;
00188 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSModelInterfaces, ENUM_OUTPUT_LEVEL_debug, outStr.str());
00189 #endif
00190 }
00191
00192
00193
00194 int n;
00195 bool have_basic_var = false;
00196 bool have_basic_con = false;
00197 SufDecl *suftab = NULL;
00198
00199
00200
00201 n = osresult->getNumberOfOtherVariableResults(0);
00202 if (n > 0) nSuffixes += n;
00203 n = osresult->getNumberOfOtherObjectiveResults(0);
00204 if (n > 0) nSuffixes += n;
00205 n = osresult->getNumberOfOtherConstraintResults(0);
00206 if (n > 0) nSuffixes += n;
00207
00208 if ( (osresult->optimization != NULL)
00209 && (osresult->optimization->solution[0] != NULL)
00210 && (osresult->optimization->solution[0]->variables != NULL)
00211 && (osresult->optimization->solution[0]->variables->basisStatus != NULL) )
00212 {
00213 have_basic_var = true;
00214 nSuffixes++;
00215 }
00216 if ( (osresult->optimization != NULL)
00217 && (osresult->optimization->solution[0] != NULL)
00218 && (osresult->optimization->solution[0]->constraints != NULL)
00219 && (osresult->optimization->solution[0]->constraints->basisStatus != NULL) )
00220 {
00221 have_basic_con = true;
00222 nSuffixes++;
00223 }
00224
00225 if (nSuffixes > 0)
00226 {
00227
00228
00229 int k = 0;
00230 suftab = new SufDecl[nSuffixes];
00231 SufDecl temp;
00232 std::string s;
00233 char* p;
00234
00235 for (i=0; i < osresult->getNumberOfOtherVariableResults(0); i++, k++)
00236 {
00237 s = osresult->getOtherVariableResultName(0, i);
00238 suftab[k].name = new char[s.size()+1];
00239 s.copy(suftab[k].name, s.size(), 0);
00240 suftab[k].name[s.size()] = '\0';
00241
00242 #ifndef NDEBUG
00243 outStr.str("");
00244 outStr.clear();
00245 outStr << s << " has length " << s.size() << " p = " << suftab[k].name << std::endl;
00246 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSModelInterfaces, ENUM_OUTPUT_LEVEL_debug, outStr.str());
00247 #endif
00248
00249 suftab[k].table = NULL;
00250 suftab[k].kind = ASL_Sufkind_var;
00251 suftab[k].nextra = 1;
00252 }
00253 for (i=0; i < osresult->getNumberOfOtherObjectiveResults(0); i++, k++)
00254 {
00255 s = osresult->getOtherObjectiveResultName(0, i);
00256 suftab[k].name = new char[s.size()+1];
00257 s.copy(suftab[k].name, s.size(), 0);
00258 suftab[k].name[s.size()] = '\0';
00259
00260 #ifndef NDEBUG
00261 outStr.str("");
00262 outStr.clear();
00263 outStr << s << " has length " << s.size() << " p = " << suftab[k].name << std::endl;
00264 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSModelInterfaces, ENUM_OUTPUT_LEVEL_debug, outStr.str());
00265 #endif
00266
00267 suftab[k].table = NULL;
00268 suftab[k].kind = ASL_Sufkind_obj;
00269 suftab[k].nextra = 1;
00270 }
00271 for (i=0; i < osresult->getNumberOfOtherConstraintResults(0); i++, k++)
00272 {
00273 s = osresult->getOtherConstraintResultName(0, i);
00274 suftab[k].name = new char[s.size()+1];
00275 s.copy(suftab[k].name, s.size(), 0);
00276 suftab[k].name[s.size()] = '\0';
00277
00278 #ifndef NDEBUG
00279 outStr.str("");
00280 outStr.clear();
00281 outStr << s << " has length " << s.size() << " p = " << suftab[k].name << std::endl;
00282 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSModelInterfaces, ENUM_OUTPUT_LEVEL_debug, outStr.str());
00283 #endif
00284
00285 suftab[k].table = NULL;
00286 suftab[k].kind = ASL_Sufkind_con;
00287 suftab[k].nextra = 1;
00288 }
00289 if (have_basic_var)
00290 {
00291 s = "sstatus";
00292 suftab[k].name = new char[s.size()+1];
00293 s.copy(suftab[k].name, s.size(), 0);
00294 suftab[k].name[s.size()] = '\0';
00295
00296 #ifndef NDEBUG
00297 outStr.str("");
00298 outStr.clear();
00299 outStr << s << " has length " << s.size() << " p = " << suftab[k].name << std::endl;
00300 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSModelInterfaces, ENUM_OUTPUT_LEVEL_debug, outStr.str());
00301 #endif
00302
00303 suftab[k].table = NULL;
00304 suftab[k].kind = ASL_Sufkind_var;
00305 suftab[k].nextra = 1;
00306 k++;
00307 }
00308 if (have_basic_con)
00309 {
00310 s = "sstatus";
00311 suftab[k].name = new char[s.size()+1];
00312 s.copy(suftab[k].name, s.size(), 0);
00313 suftab[k].name[s.size()] = '\0';
00314
00315 #ifndef NDEBUG
00316 outStr.str("");
00317 outStr.clear();
00318 outStr << s << " has length " << s.size() << " p = " << suftab[k].name << std::endl;
00319 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSModelInterfaces, ENUM_OUTPUT_LEVEL_debug, outStr.str());
00320 #endif
00321
00322 suftab[k].table = NULL;
00323 suftab[k].kind = ASL_Sufkind_con;
00324 suftab[k].nextra = 1;
00325 }
00326
00327 #ifndef NDEBUG
00328 outStr.str("");
00329 outStr.clear();
00330 for (i=0; i < nSuffixes; i++)
00331 outStr << i << ": suffix " << suftab[i].name << " of kind " << suftab[i].kind << std::endl;
00332 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSModelInterfaces, ENUM_OUTPUT_LEVEL_debug, outStr.str());
00333 #endif
00334
00335
00336
00337 suf_declare(suftab, nSuffixes);
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347 rData = new double*[nSuffixes];
00348 iData = new int*[nSuffixes];
00349
00350 std::string resultType;
00351 std::string resultName;
00352
00353 for (i=0; i<nSuffixes; i++)
00354 {
00355 rData[i] = NULL;
00356 iData[i] = NULL;
00357 }
00358
00359 int iSuf = 0;
00360
00361 for (i=0; i < osresult->getNumberOfOtherVariableResults(0); i++, iSuf++)
00362 {
00363 if ( (osresult->optimization->solution[0]->variables->other[i]->var != NULL) ||
00364 (osresult->optimization->solution[0]->variables->other[i]->enumeration != NULL) )
00365 {
00366 if (numVars > 0)
00367 n = osresult->getOtherVariableResultArrayDense(0, i, otherVar, numVars);
00368 else
00369 n = 0;
00370 if (n < 0)
00371 throw ErrorClass("unspecified error in routine getOtherVariableResultArrayDense()");
00372 else if (n > 0)
00373 {
00374 resultType = osresult->getOtherVariableResultArrayType(0, i);
00375 resultName = osresult->getOtherVariableResultName(0, i);
00376
00377 #ifndef NDEBUG
00378 outStr.str("");
00379 outStr.clear();
00380 outStr << "found variable suffix " << resultName
00381 << " of type " << resultType << std::endl;
00382 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSModelInterfaces, ENUM_OUTPUT_LEVEL_debug, outStr.str());
00383
00384 outStr.str("");
00385 outStr.clear();
00386 outStr << "retrieved these values:";
00387 for (int m=0; m<n; m++)
00388 outStr << " " << otherVar[m];
00389 outStr << std::endl;
00390 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSModelInterfaces, ENUM_OUTPUT_LEVEL_trace, outStr.str());
00391 #endif
00392
00393 if ( (resultType == "real")
00394 || (resultType == "double")
00395 || (resultType == "numeric")
00396
00397 )
00398 {
00399 rData[iSuf] = new double[n];
00400 for (int m=0; m<n; m++)
00401 rData[iSuf][m] = os_strtod(otherVar[m].c_str(), NULL);
00402 #ifndef NDEBUG
00403 outStr.str("");
00404 outStr.clear();
00405 outStr << "values (real): ";
00406 for (int m=0; m<n; m++)
00407 outStr << rData[iSuf][m] << " ";
00408 outStr << std::endl << std::endl;
00409 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSModelInterfaces, ENUM_OUTPUT_LEVEL_debug, outStr.str());
00410 #endif
00411
00412 suf_rput(resultName.c_str(), ASL_Sufkind_var, rData[iSuf]);
00413 }
00414 else if (resultType == "integer")
00415 {
00416 iData[iSuf] = new int[n];
00417 for (int m=0; m<n; m++)
00418 iData[iSuf][m] = atoi(otherVar[m].c_str());
00419 #ifndef NDEBUG
00420 outStr.str("");
00421 outStr.clear();
00422 outStr << "values (integer): ";
00423 for (int m=0; m<n; m++)
00424 outStr << iData[iSuf][m] << " ";
00425 outStr << std::endl << std::endl;
00426 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSModelInterfaces, ENUM_OUTPUT_LEVEL_debug, outStr.str());
00427 #endif
00428 suf_iput(resultName.c_str(), ASL_Sufkind_var, iData[iSuf]);
00429 }
00430 else
00431 throw ErrorClass("otherVariableResult has unsupported type in OSosrl2ampl()");
00432 }
00433 }
00434 }
00435
00436
00437
00438 for (i=0; i < osresult->getNumberOfOtherObjectiveResults(0); i++, k++)
00439 {
00440 if ( (osresult->optimization->solution[0]->objectives->other[i]->obj != NULL) ||
00441 (osresult->optimization->solution[0]->objectives->other[i]->enumeration != NULL) )
00442 {
00443 n = osresult->getOtherObjectiveResultArrayDense(0, i, otherObj, numObjs);
00444 if (n < 0)
00445 throw ErrorClass("unspecified error in routine getOtherObjectiveResultArrayDense()");
00446 else if (n > 0)
00447 {
00448 resultType = osresult->getOtherObjectiveResultArrayType(0, i);
00449 resultName = osresult->getOtherObjectiveResultName(0, i);
00450 #ifndef NDEBUG
00451 outStr.str("");
00452 outStr.clear();
00453 outStr << "found objective suffix " << resultName
00454 << " of type " << resultType << std::endl;
00455 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSModelInterfaces, ENUM_OUTPUT_LEVEL_debug, outStr.str());
00456
00457 outStr.str("");
00458 outStr.clear();
00459 outStr << "retrieved these values:";
00460 for (int m=0; m<n; m++)
00461 outStr << " " << otherObj[m];
00462 outStr << std::endl;
00463 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSModelInterfaces, ENUM_OUTPUT_LEVEL_trace, outStr.str());
00464 #endif
00465
00466 if ( (resultType == "real")
00467 || (resultType == "double")
00468 || (resultType == "numeric")
00469
00470 )
00471 {
00472 rData[iSuf] = new double[n];
00473 for (int m=0; m<n; m++)
00474 rData[iSuf][m] = os_strtod(otherObj[m].c_str(), NULL);
00475 #ifndef NDEBUG
00476 outStr.str("");
00477 outStr.clear();
00478 outStr << "values (real): ";
00479 for (int m=0; m<n; m++)
00480 outStr << rData[iSuf][m] << " ";
00481 outStr << std::endl << std::endl;
00482 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSModelInterfaces, ENUM_OUTPUT_LEVEL_debug, outStr.str());
00483 #endif
00484 suf_rput(resultName.c_str(), ASL_Sufkind_obj, rData[iSuf]);
00485
00486 }
00487 else if (resultType == "integer")
00488 {
00489 iData[iSuf] = new int[n];
00490 for (int m=0; m<n; m++)
00491 iData[iSuf][m] = atoi(otherObj[m].c_str());
00492 #ifndef NDEBUG
00493 outStr.str("");
00494 outStr.clear();
00495 outStr << "values (integer): ";
00496 for (int m=0; m<n; m++)
00497 outStr << iData[iSuf][m] << " ";
00498 outStr << std::endl << std::endl;
00499 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSModelInterfaces, ENUM_OUTPUT_LEVEL_debug, outStr.str());
00500 #endif
00501 suf_iput(resultName.c_str(), ASL_Sufkind_obj, iData[iSuf]);
00502
00503 }
00504 else
00505 throw ErrorClass("otherObjectiveResult has unsupported type in OSosrl2ampl()");
00506 }
00507 }
00508 }
00509
00510
00511
00512 for (i=0; i < osresult->getNumberOfOtherConstraintResults(0); i++, k++)
00513 {
00514 if ( (osresult->optimization->solution[0]->constraints->other[i]->con != NULL) ||
00515 (osresult->optimization->solution[0]->constraints->other[i]->enumeration != NULL) )
00516 {
00517 if (numCons > 0)
00518 n = osresult->getOtherConstraintResultArrayDense(0, i, otherCon, numCons);
00519 else
00520 n = 0;
00521 if (n < 0)
00522 throw ErrorClass("unspecified error in routine getOtherConstraintResultArrayDense()");
00523 else if (n > 0)
00524 {
00525 resultType = osresult->getOtherConstraintResultArrayType(0, i);
00526 resultName = osresult->getOtherConstraintResultName(0, i);
00527 #ifndef NDEBUG
00528 outStr.str("");
00529 outStr.clear();
00530 outStr << "found constraint suffix " << resultName
00531 << " of type " << resultType << std::endl;
00532 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSModelInterfaces, ENUM_OUTPUT_LEVEL_debug, outStr.str());
00533
00534 outStr.str("");
00535 outStr.clear();
00536 outStr << "retrieved these values:";
00537 for (int m=0; m<n; m++)
00538 outStr << " " << otherCon[m];
00539 outStr << std::endl;
00540 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSModelInterfaces, ENUM_OUTPUT_LEVEL_trace, outStr.str());
00541 #endif
00542
00543 if ( (resultType == "real")
00544 || (resultType == "double")
00545 || (resultType == "numeric")
00546
00547 )
00548 {
00549 rData[iSuf] = new double[n];
00550 for (int m=0; m<n; m++)
00551 rData[iSuf][m] = os_strtod(otherCon[m].c_str(), NULL);
00552 #ifndef NDEBUG
00553 outStr.str("");
00554 outStr.clear();
00555 outStr << "values (real): ";
00556 for (int m=0; m < n; m++)
00557 outStr << rData[iSuf][m] << " ";
00558 outStr << std::endl << std::endl;
00559 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSModelInterfaces, ENUM_OUTPUT_LEVEL_debug, outStr.str());
00560 #endif
00561 suf_rput(resultName.c_str(), ASL_Sufkind_con, rData[iSuf]);
00562
00563 }
00564 else if (resultType == "integer")
00565 {
00566 iData[iSuf] = new int[n];
00567 for (int m=0; m<n; m++)
00568 iData[iSuf][m] = atoi(otherCon[m].c_str());
00569 #ifndef NDEBUG
00570 outStr.str("");
00571 outStr.clear();
00572 outStr << "values (integer): ";
00573 for (int m=0; m < n; m++)
00574 outStr << iData[iSuf][m] << " ";
00575 outStr << std::endl << std::endl;
00576 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSModelInterfaces, ENUM_OUTPUT_LEVEL_debug, outStr.str());
00577 #endif
00578 suf_iput(resultName.c_str(), ASL_Sufkind_con, iData[iSuf]);
00579
00580 }
00581 else
00582 throw ErrorClass("otherConstraintResult has unsupported type in OSosrl2ampl()");
00583 }
00584 }
00585 }
00586
00587
00588
00589
00590
00591
00592
00593
00594
00595
00596
00597
00598
00599 int basCode[ENUM_BASIS_STATUS_NUMBER_OF_STATES] = {1,3,4,5,6,2,0};
00600 if (have_basic_var && numVars > 0)
00601 {
00602 iData[iSuf] = new int[numVars];
00603 n = osresult->getBasisInformationDense(0, ENUM_PROBLEM_COMPONENT_variables, iData[iSuf], numVars);
00604 if (n < 0)
00605 throw ErrorClass("unspecified error in routine getBasisInformationDense()");
00606 else if (n > 0)
00607 {
00608 for (i=0; i<numVars; i++)
00609 iData[iSuf][i] = basCode[iData[iSuf][i]];
00610 #ifndef NDEBUG
00611 outStr.str("");
00612 outStr.clear();
00613 outStr << "primal basic: ";
00614 for (int k=0; k < numVars; k++)
00615 outStr << iData[iSuf][k] << " ";
00616 outStr << std::endl << std::endl;
00617 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSModelInterfaces, ENUM_OUTPUT_LEVEL_debug, outStr.str());
00618 #endif
00619 suf_iput("sstatus", ASL_Sufkind_var, iData[iSuf]);
00620 }
00621 iSuf++;
00622
00623 }
00624 if (have_basic_con && numCons > 0)
00625 {
00626 iData[iSuf] = new int[numCons];
00627 n = osresult->getBasisInformationDense(0, ENUM_PROBLEM_COMPONENT_constraints, iData[iSuf], numCons);
00628 if (n < 0)
00629 throw ErrorClass("unspecified error in routine getBasisInformationDense()");
00630 else if (n > 0)
00631 {
00632 for (i=0; i<numCons; i++)
00633 iData[iSuf][i] = basCode[iData[iSuf][i]];
00634 #ifndef NDEBUG
00635 outStr.str("");
00636 outStr.clear();
00637 outStr << "dual basic: ";
00638 for (int k=0; k < numCons; k++)
00639 outStr << iData[iSuf][k] << " ";
00640 outStr << std::endl << std::endl;
00641 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSModelInterfaces, ENUM_OUTPUT_LEVEL_debug, outStr.str());
00642 #endif
00643 suf_iput("sstatus", ASL_Sufkind_con, iData[iSuf]);
00644 iSuf++;
00645
00646 }
00647 }
00648 }
00649
00650
00651
00652 int OS_solve_result = returnSolutionStatus(osresult->getSolutionStatusType(0));
00653 switch (OS_solve_result)
00654 {
00655 case (ENUM_SOLUTION_STATUS_globallyOptimal):
00656 {
00657 solve_result_num = 90;
00658 break;
00659 }
00660 case (ENUM_SOLUTION_STATUS_locallyOptimal):
00661 {
00662 solve_result_num = 50;
00663 break;
00664 }
00665 case (ENUM_SOLUTION_STATUS_optimal):
00666 {
00667 solve_result_num = 10;
00668 break;
00669 }
00670 case (ENUM_SOLUTION_STATUS_bestSoFar):
00671 {
00672 solve_result_num = 110;
00673 break;
00674 }
00675 case (ENUM_SOLUTION_STATUS_feasible):
00676 {
00677 solve_result_num = 120;
00678 break;
00679 }
00680 case (ENUM_SOLUTION_STATUS_infeasible):
00681 {
00682 solve_result_num = 200;
00683 break;
00684 }
00685 case (ENUM_SOLUTION_STATUS_unbounded):
00686 {
00687 solve_result_num = 300;
00688 break;
00689 }
00690 case (ENUM_SOLUTION_STATUS_error):
00691 {
00692 solve_result_num = 500;
00693 break;
00694 }
00695 case (ENUM_SOLUTION_STATUS_unsure):
00696 {
00697 solve_result_num = 520;
00698 break;
00699 }
00700 case (ENUM_SOLUTION_STATUS_other):
00701 {
00702 solve_result_num = 550;
00703 break;
00704 }
00705 default:
00706 throw ErrorClass("Unknown solution status detected");
00707 }
00708
00709
00710
00711 std::string solMsg;
00712 std::string tmpStr;
00713 tmpStr = osresult->getSolutionMessage(0);
00714 if (tmpStr != "")
00715 solMsg = tmpStr;
00716 else
00717 {
00718 std::ostringstream outStr;
00719 try
00720 {
00721 outStr << "Solution status: " << osresult->getSolutionStatusType(0) << std::endl;
00722 tmpStr = osresult->getSolutionStatusDescription(0);
00723 if (tmpStr != "")
00724 outStr << "Description: " << tmpStr << std::endl;
00725 }
00726 catch (const ErrorClass& eclass)
00727 {
00728 outStr << "Solution status: " << "unknown" << std::endl;
00729 }
00730 try
00731 {
00732 int objIdx = osresult->getSolutionTargetObjectiveIdx(0);
00733 if (objIdx == 0) objIdx = -1;
00734 double objVal = osresult-> getOptimalObjValue(objIdx,0);
00735 outStr << "Objective value: " << objVal << std::endl;
00736 outStr << "Objective index: " << objIdx << std::endl;
00737 }
00738 catch (const ErrorClass& eclass)
00739 {
00740 outStr << "Objective info: " << "not returned" << std::endl;
00741 }
00742 solMsg = outStr.str();
00743 }
00744
00745 amplflag = 1;
00746
00747
00748
00749
00750
00751
00752
00753
00754
00755
00756
00757
00758 try
00759 {
00760 #ifndef NDEBUG
00761 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSModelInterfaces, ENUM_OUTPUT_LEVEL_debug, "Calling ASL");
00762 #endif
00763 write_solf_ASL(asl, const_cast<char*>(solMsg.c_str()), x, y , NULL, solfile.c_str());
00764
00765 #ifndef NDEBUG
00766 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSModelInterfaces, ENUM_OUTPUT_LEVEL_debug, "Returned from ASL");
00767 #endif
00768 }
00769 catch(const ErrorClass& eclass)
00770 {
00771 #ifndef NDEBUG
00772 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSModelInterfaces, ENUM_OUTPUT_LEVEL_debug, "Error in ASL");
00773 #endif
00774 }
00775
00776 if (osrlreader != NULL) delete osrlreader;
00777 osrlreader = NULL;
00778 if (x != NULL)
00779 delete [] x;
00780 x = NULL;
00781 if (y != NULL)
00782 delete [] y;
00783 y = NULL;
00784 if (otherVar != NULL)
00785 delete [] otherVar;
00786 otherVar = NULL;
00787 if (otherObj != NULL)
00788 delete [] otherObj;
00789 otherObj = NULL;
00790 if (otherCon != NULL)
00791 delete [] otherCon;
00792 otherCon = NULL;
00793 if (rData != NULL)
00794 {
00795 for (i=0; i<nSuffixes; i++)
00796 {
00797 if (rData[i] != NULL) delete [] rData[i];
00798 }
00799 delete [] rData;
00800 rData = NULL;
00801 }
00802 if (iData != NULL)
00803 {
00804 for (i=0; i<nSuffixes; i++)
00805 {
00806 if (iData[i] != NULL) delete [] iData[i];
00807 }
00808 delete [] iData;
00809 iData = NULL;
00810 }
00811 return true;
00812 }
00813 catch(const ErrorClass& eclass)
00814 {
00815 outStr.str("");
00816 outStr.clear();
00817 outStr << "There was an error: " + eclass.errormsg << std::endl;
00818 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSModelInterfaces, ENUM_OUTPUT_LEVEL_error, outStr.str());
00819 if (osrlreader != NULL) delete osrlreader;
00820 osrlreader = NULL;
00821 if (x != NULL)
00822 delete [] x;
00823 x = NULL;
00824 if (y != NULL)
00825 delete [] y;
00826 y = NULL;
00827 if (otherVar != NULL)
00828 delete [] otherVar;
00829 otherVar = NULL;
00830 if (otherObj != NULL)
00831 delete [] otherObj;
00832 otherObj = NULL;
00833 if (otherCon != NULL)
00834 delete [] otherCon;
00835 otherCon = NULL;
00836 if (rData != NULL)
00837 {
00838 for (int i=0; i<nSuffixes; i++)
00839 {
00840 if (rData[i] != NULL) delete [] rData[i];
00841 }
00842 delete [] rData;
00843 rData = NULL;
00844 }
00845 if (iData != NULL)
00846 {
00847 for (int i=0; i<nSuffixes; i++)
00848 {
00849 if (iData[i] != NULL) delete [] iData[i];
00850 }
00851 delete [] iData;
00852 iData = NULL;
00853 }
00854 return false;
00855 }
00856 }
00857 }
00858