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