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