31 #include "CoinHelperFunctions.hpp"
75 std::ostringstream outStr;
80 std::string solMsg =
" ";
81 solve_result_num = 550;
82 write_sol(const_cast<char*>(solMsg.c_str()), NULL, NULL , NULL);
90 outStr << std::endl << osrl << std::endl << std::endl << std::endl;
96 std::string *otherVar = NULL;
97 std::string *otherObj = NULL;
98 std::string *otherCon = NULL;
100 double **rData = NULL;
102 double* rvalues = NULL;
109 osresult = osrlreader->
readOSrL( osrl);
122 std::string solMsg =
" ";
123 solve_result_num = 550;
124 write_sol(const_cast<char*>(solMsg.c_str()), NULL, NULL , NULL);
137 x =
new double[ numVars];
138 otherVar =
new std::string[numVars];
142 y =
new double[ numCons];
143 otherCon =
new std::string[numCons];
147 otherObj =
new std::string[numObjs];
150 std::vector<IndexValuePair*> primalValPair;
151 std::vector<IndexValuePair*> dualValPair;
155 for (i = 0; i < numVars; i++)
159 vecSize = primalValPair.size();
160 for (i = 0; i < vecSize; i++)
162 x[ primalValPair[i]->idx ] = primalValPair[i]->value;
166 outStr <<
"index = " << primalValPair[i]->idx << std::endl;
167 outStr <<
"value = " << primalValPair[i]->value << std::endl;
172 for (i = 0; i < numCons; i++)
176 vecSize = dualValPair.size();
177 for (i = 0; i < vecSize; i++)
179 y[ dualValPair[i]->idx ] = dualValPair[i]->value;
183 outStr <<
"index = " << dualValPair[i]->idx << std::endl;
184 outStr <<
"value = " << dualValPair[i]->value << std::endl;
192 bool have_basic_var =
false;
193 bool have_basic_con =
false;
194 SufDecl *suftab = NULL;
199 if (n > 0) nSuffixes +=
n;
201 if (n > 0) nSuffixes +=
n;
203 if (n > 0) nSuffixes +=
n;
210 have_basic_var =
true;
218 have_basic_con =
true;
227 suftab =
new SufDecl[nSuffixes];
235 suftab[
k].name =
new char[s.size()+1];
236 s.copy(suftab[k].name, s.size(), 0);
237 suftab[
k].name[s.size()] =
'\0';
242 outStr << s <<
" has length " << s.size() <<
" p = " << suftab[
k].name << std::endl;
246 suftab[
k].table = NULL;
247 suftab[
k].kind = ASL_Sufkind_var;
248 suftab[
k].nextra = 1;
253 suftab[
k].name =
new char[s.size()+1];
254 s.copy(suftab[k].name, s.size(), 0);
255 suftab[
k].name[s.size()] =
'\0';
260 outStr << s <<
" has length " << s.size() <<
" p = " << suftab[
k].name << std::endl;
264 suftab[
k].table = NULL;
265 suftab[
k].kind = ASL_Sufkind_obj;
266 suftab[
k].nextra = 1;
271 suftab[
k].name =
new char[s.size()+1];
272 s.copy(suftab[k].name, s.size(), 0);
273 suftab[
k].name[s.size()] =
'\0';
278 outStr << s <<
" has length " << s.size() <<
" p = " << suftab[
k].name << std::endl;
282 suftab[
k].table = NULL;
283 suftab[
k].kind = ASL_Sufkind_con;
284 suftab[
k].nextra = 1;
289 suftab[
k].name =
new char[s.size()+1];
290 s.copy(suftab[k].name, s.size(), 0);
291 suftab[
k].name[s.size()] =
'\0';
296 outStr << s <<
" has length " << s.size() <<
" p = " << suftab[
k].name << std::endl;
300 suftab[
k].table = NULL;
301 suftab[
k].kind = ASL_Sufkind_var;
302 suftab[
k].nextra = 1;
308 suftab[
k].name =
new char[s.size()+1];
309 s.copy(suftab[k].name, s.size(), 0);
310 suftab[
k].name[s.size()] =
'\0';
315 outStr << s <<
" has length " << s.size() <<
" p = " << suftab[
k].name << std::endl;
319 suftab[
k].table = NULL;
320 suftab[
k].kind = ASL_Sufkind_con;
321 suftab[
k].nextra = 1;
327 for (i=0; i < nSuffixes; i++)
328 outStr << i <<
": suffix " << suftab[i].name <<
" of kind " << suftab[i].kind << std::endl;
334 suf_declare(suftab, nSuffixes);
344 rData =
new double*[nSuffixes];
345 iData =
new int*[nSuffixes];
347 std::string resultType;
348 std::string resultName;
350 for (i=0; i<nSuffixes; i++)
368 throw ErrorClass(
"unspecified error in routine getOtherVariableResultArrayDense()");
377 outStr <<
"found variable suffix " << resultName
378 <<
" of type " << resultType << std::endl;
383 outStr <<
"retrieved these values:";
384 for (
int m=0;
m<
n;
m++)
385 outStr <<
" " << otherVar[
m];
390 if ( (resultType ==
"real")
391 || (resultType ==
"double")
392 || (resultType ==
"numeric")
396 rData[iSuf] =
new double[
n];
397 for (
int m=0;
m<
n;
m++)
398 rData[iSuf][
m] =
os_strtod(otherVar[
m].c_str(), NULL);
402 outStr <<
"values (real): ";
403 for (
int m=0;
m<
n;
m++)
404 outStr << rData[iSuf][
m] <<
" ";
405 outStr << std::endl << std::endl;
409 suf_rput(resultName.c_str(), ASL_Sufkind_var, rData[iSuf]);
411 else if (resultType ==
"integer")
413 iData[iSuf] =
new int[
n];
414 for (
int m=0;
m<
n;
m++)
415 iData[iSuf][
m] = atoi(otherVar[
m].c_str());
419 outStr <<
"values (integer): ";
420 for (
int m=0;
m<
n;
m++)
421 outStr << iData[iSuf][
m] <<
" ";
422 outStr << std::endl << std::endl;
425 suf_iput(resultName.c_str(), ASL_Sufkind_var, iData[iSuf]);
428 throw ErrorClass(
"otherVariableResult has unsupported type in OSosrl2ampl()");
442 throw ErrorClass(
"unspecified error in routine getOtherObjectiveResultArrayDense()");
450 outStr <<
"found objective suffix " << resultName
451 <<
" of type " << resultType << std::endl;
456 outStr <<
"retrieved these values:";
457 for (
int m=0;
m<
n;
m++)
458 outStr <<
" " << otherObj[
m];
463 if ( (resultType ==
"real")
464 || (resultType ==
"double")
465 || (resultType ==
"numeric")
469 rData[iSuf] =
new double[
n];
470 for (
int m=0;
m<
n;
m++)
471 rData[iSuf][
m] =
os_strtod(otherObj[
m].c_str(), NULL);
475 outStr <<
"values (real): ";
476 for (
int m=0;
m<
n;
m++)
477 outStr << rData[iSuf][
m] <<
" ";
478 outStr << std::endl << std::endl;
481 suf_rput(resultName.c_str(), ASL_Sufkind_obj, rData[iSuf]);
484 else if (resultType ==
"integer")
486 iData[iSuf] =
new int[
n];
487 for (
int m=0;
m<
n;
m++)
488 iData[iSuf][
m] = atoi(otherObj[
m].c_str());
492 outStr <<
"values (integer): ";
493 for (
int m=0;
m<
n;
m++)
494 outStr << iData[iSuf][
m] <<
" ";
495 outStr << std::endl << std::endl;
498 suf_iput(resultName.c_str(), ASL_Sufkind_obj, iData[iSuf]);
502 throw ErrorClass(
"otherObjectiveResult has unsupported type in OSosrl2ampl()");
519 throw ErrorClass(
"unspecified error in routine getOtherConstraintResultArrayDense()");
527 outStr <<
"found constraint suffix " << resultName
528 <<
" of type " << resultType << std::endl;
533 outStr <<
"retrieved these values:";
534 for (
int m=0;
m<
n;
m++)
535 outStr <<
" " << otherCon[
m];
540 if ( (resultType ==
"real")
541 || (resultType ==
"double")
542 || (resultType ==
"numeric")
546 rData[iSuf] =
new double[
n];
547 for (
int m=0;
m<
n;
m++)
548 rData[iSuf][
m] =
os_strtod(otherCon[
m].c_str(), NULL);
552 outStr <<
"values (real): ";
553 for (
int m=0;
m <
n;
m++)
554 outStr << rData[iSuf][
m] <<
" ";
555 outStr << std::endl << std::endl;
558 suf_rput(resultName.c_str(), ASL_Sufkind_con, rData[iSuf]);
561 else if (resultType ==
"integer")
563 iData[iSuf] =
new int[
n];
564 for (
int m=0;
m<
n;
m++)
565 iData[iSuf][
m] = atoi(otherCon[
m].c_str());
569 outStr <<
"values (integer): ";
570 for (
int m=0;
m <
n;
m++)
571 outStr << iData[iSuf][
m] <<
" ";
572 outStr << std::endl << std::endl;
575 suf_iput(resultName.c_str(), ASL_Sufkind_con, iData[iSuf]);
579 throw ErrorClass(
"otherConstraintResult has unsupported type in OSosrl2ampl()");
597 if (have_basic_var && numVars > 0)
599 iData[iSuf] =
new int[numVars];
602 throw ErrorClass(
"unspecified error in routine getBasisInformationDense()");
605 for (i=0; i<numVars; i++)
606 iData[iSuf][i] = basCode[iData[iSuf][i]];
610 outStr <<
"primal basic: ";
611 for (
int k=0; k < numVars; k++)
612 outStr << iData[iSuf][k] <<
" ";
613 outStr << std::endl << std::endl;
616 suf_iput(
"sstatus", ASL_Sufkind_var, iData[iSuf]);
621 if (have_basic_con && numCons > 0)
623 iData[iSuf] =
new int[numCons];
626 throw ErrorClass(
"unspecified error in routine getBasisInformationDense()");
629 for (i=0; i<numCons; i++)
630 iData[iSuf][i] = basCode[iData[iSuf][i]];
634 outStr <<
"dual basic: ";
635 for (
int k=0; k < numCons; k++)
636 outStr << iData[iSuf][k] <<
" ";
637 outStr << std::endl << std::endl;
640 suf_iput(
"sstatus", ASL_Sufkind_con, iData[iSuf]);
650 switch (OS_solve_result)
654 solve_result_num = 90;
659 solve_result_num = 50;
664 solve_result_num = 10;
669 solve_result_num = 110;
674 solve_result_num = 120;
679 solve_result_num = 200;
684 solve_result_num = 300;
689 solve_result_num = 500;
694 solve_result_num = 520;
699 solve_result_num = 550;
703 throw ErrorClass(
"Unknown solution status detected");
715 std::ostringstream outStr;
721 outStr <<
"Description: " << tmpStr << std::endl;
725 outStr <<
"Solution status: " <<
"unknown" << std::endl;
730 if (objIdx == 0) objIdx = -1;
731 double objVal = osresult-> getOptimalObjValue(objIdx,0);
732 outStr <<
"Objective value: " << objVal << std::endl;
733 outStr <<
"Objective index: " << objIdx << std::endl;
737 outStr <<
"Objective info: " <<
"not returned" << std::endl;
739 solMsg = outStr.str();
760 write_solf_ASL(asl, const_cast<char*>(solMsg.c_str()), x, y , NULL, solfile.c_str());
773 if (osrlreader != NULL)
delete osrlreader;
781 if (otherVar != NULL)
784 if (otherObj != NULL)
787 if (otherCon != NULL)
792 for (i=0; i<nSuffixes; i++)
794 if (rData[i] != NULL)
delete [] rData[i];
801 for (i=0; i<nSuffixes; i++)
803 if (iData[i] != NULL)
delete [] iData[i];
814 outStr <<
"There was an error: " + eclass.
errormsg << std::endl;
816 if (osrlreader != NULL)
delete osrlreader;
824 if (otherVar != NULL)
827 if (otherObj != NULL)
830 if (otherCon != NULL)
835 for (
int i=0; i<nSuffixes; i++)
837 if (rData[i] != NULL)
delete [] rData[i];
844 for (
int i=0; i<nSuffixes; i++)
846 if (iData[i] != NULL)
delete [] iData[i];
int getObjectiveNumber()
Get objective number.
double os_strtod(const char *s00, char **se)
int getNumberOfOtherObjectiveResults(int solIdx)
OtherConstraintResult ** other
a pointer to an array of other pointer objects for constraint functions
const OSSmartPtr< OSOutput > osoutput
std::string getSolutionStatusType(int solIdx)
Get the [i]th optimization solution status type, where i equals the given solution index...
std::string errormsg
errormsg is the error that is causing the exception to be thrown
OtherOptionOrResultEnumeration ** enumeration
std::vector< IndexValuePair * > getOptimalPrimalVariableValues(int solIdx)
Get one solution of optimal primal variable values.
int getNumberOfOtherConstraintResults(int solIdx)
OSResult * readOSrL(const std::string &posrl)
Get an OSResult object from an OSrL string.
int getBasisInformationDense(int solIdx, int object, int *resultArray, int dim)
Get the basis information associated with the variables, objectives or constraints for some solution...
OptimizationResult * optimization
optimization holds the fifth child of the OSResult specified by the OSrL Schema.
std::vector< IndexValuePair * > getOptimalDualVariableValues(int solIdx)
Get one solution of optimal dual variable values.
std::string getOtherVariableResultName(int solIdx, int otherIdx)
ObjectiveSolution * objectives
objectives holds the solution information for the objectives
std::string getOtherVariableResultArrayType(int solIdx, int otherIdx)
Get the type of values contained in the or <enumeration> array associated with an <other> result for...
std::string getOtherConstraintResultArrayType(int solIdx, int otherIdx)
Get the type of values contained in the <con> or <enumeration> array associated with an <other> resul...
std::string getSolutionMessage(int solIdx)
Get the [i]th optimization solution message, where i equals the given solution index.
std::string getOtherObjectiveResultArrayType(int solIdx, int otherIdx)
Get the type of values contained in the <obj> or <enumeration> array associated with an <other> resul...
VariableSolution * variables
variables holds the solution information for the variables
int getOtherObjectiveResultArrayDense(int solIdx, int otherIdx, std::string *resultArray, int dim)
Get the values of an <obj> array or an <enumeration> associated with an <other> result for some solut...
bool writeSolFile(std::string osrl, ASL *asl, std::string filename)
Convert the solution to AMPL .sol format.
std::string getOtherObjectiveResultName(int solIdx, int otherIdx)
std::string getOtherConstraintResultName(int solIdx, int otherIdx)
void fint fint fint fint fint fint fint fint fint fint real real real real real real real real * s
int getSolutionNumber()
get the number of solutions.
int getSolutionTargetObjectiveIdx(int solIdx)
~OSosrl2ampl()
the OSosrl2ampl class destructor
OptimizationSolution ** solution
solution is an array of pointers to OptimizationSolution objects
int returnSolutionStatus(std::string status)
ConstraintSolution * constraints
constraints holds the solution information for the constraints
std::string getSolutionStatusDescription(int solIdx)
Get the [i]th optimization solution status description, where i equals the given solution index...
BasisStatus * basisStatus
a pointer to a BasisStatus object
OtherVariableResult ** other
a pointer to an array of other pointer objects for variables
OtherOptionOrResultEnumeration ** enumeration
OtherObjectiveResult ** other
a pointer to an array of other pointer objects for objective functions
int getNumberOfOtherVariableResults(int solIdx)
Get numberOfOtherVariableResult.
int getOtherConstraintResultArrayDense(int solIdx, int otherIdx, std::string *resultArray, int dim)
Get the values of a <con> array or an <enumeration> associated with an <other> result for some soluti...
OtherOptionOrResultEnumeration ** enumeration
BasisStatus * basisStatus
a pointer to a BasisStatus object
int getOtherVariableResultArrayDense(int solIdx, int otherIdx, std::string *resultArray, int dim)
Get the values of a array or an <enumeration> associated with an <other> result for some solution...
used for throwing exceptions.
int getVariableNumber()
Get variable number.
OSosrl2ampl()
the OSosrl2ampl class constructor
int getConstraintNumber()
Get constraint number.
void fint fint fint real fint real * x