/home/coin/SVN-release/OS-1.0.0/OS/src/OSCommonInterfaces/OSrLWriter.cpp

Go to the documentation of this file.
00001 
00023 #include "OSrLWriter.h"
00024 #include "OSResult.h"
00025 #include "OSParameters.h"
00026 #include "CommonUtil.h"
00027 #include "OSConfig.h"
00028 #include <sstream>   
00029 #include <iostream>  
00030 
00031 using std::cout;
00032 using std::endl;
00033 using std::ostringstream;
00034 
00035 OSrLWriter::OSrLWriter( ) {      
00036 }
00037 
00038 OSrLWriter::~OSrLWriter(){
00039 }
00040 
00041 
00042 /*char* OSrLWriter::writeOSrLWrap( OSResult *theosresult){
00043         std::string sTmp = writeOSrL( theosresult);
00044         char *ch;
00045     ch = new char[sTmp.size() + 1];
00046     strcpy(ch, sTmp.c_str());
00047         return ch;
00048 }
00049 */
00050 
00051 
00052 
00053 
00054  
00055 std::string OSrLWriter::writeOSrL( OSResult *theosresult){
00056         m_OSResult = theosresult;
00057         std::ostringstream outStr;
00058         #ifdef WIN_
00059         const char      dirsep='\\';
00060         #else
00061         const char      dirsep='/';
00062         #endif
00063         // Set directory containing mps data files.
00064         std::string xsltDir;
00065     xsltDir = dirsep == '/' ? "/stylesheets/" : "\\stylesheets\\";
00066         int i, j;
00067         if(m_OSResult == NULL)  return outStr.str(); 
00068         outStr << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" ; 
00069         outStr << "<?xml-stylesheet type = \"text/xsl\" href = \"";
00070         outStr << OSROOT_DIR;
00071         outStr << xsltDir;
00072         outStr << "OSrL.xslt\"?>";
00073         outStr << "<osrl xmlns=\"os.optimizationservices.org\"   xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"os.optimizationservices.org http://www.optimizationservices.org/schemas/OSrL.xsd\" >" ;
00074         outStr << endl;
00075         outStr << "<resultHeader>" << endl;
00076         if(m_OSResult->resultHeader != NULL){
00077                 if(m_OSResult->resultHeader->generalStatus != NULL){
00078                         outStr << "<generalStatus "    ;
00079                         if(m_OSResult->resultHeader->generalStatus->type.length() > 0){
00080                                 outStr << "type=\"";
00081                                 outStr << m_OSResult->resultHeader->generalStatus->type ;
00082                                 outStr << "\"";
00083                         }
00084                         if(m_OSResult->resultHeader->generalStatus->description.length() > 0){
00085                                 outStr << "type=\"";
00086                                 outStr << m_OSResult->resultHeader->generalStatus->description ;
00087                                 outStr << "\"";
00088                         }
00089                         outStr << "/>" << endl;
00090                 }               
00091                 
00092                 if(m_OSResult->resultHeader->serviceURI.length() > 0){
00093                         outStr << "<serviceURI>" + m_OSResult->resultHeader->serviceURI + "</serviceURI>"  << endl;
00094                 }
00095 
00096                 if(m_OSResult->resultHeader->serviceName.length() > 0){
00097                         outStr << "<serviceName>" + m_OSResult->resultHeader->serviceName + "</serviceName>"  << endl;
00098                 }
00099                 if(m_OSResult->resultHeader->instanceName.length() > 0){
00100                         outStr << "<instanceName>" + m_OSResult->resultHeader->instanceName  + "</instanceName>" << endl;
00101                 }
00102                 if(m_OSResult->resultHeader->jobID.length() > 0){
00103                         outStr << "<jobID>" + m_OSResult->resultHeader->jobID  + "</jobID>" << endl;
00104                 }
00105                 if(m_OSResult->resultHeader->time.length() > 0){
00106                         outStr << "<time>" + m_OSResult->resultHeader->time  + "</time>" << endl;
00107                 }
00108                 if(m_OSResult->resultHeader->message.length() > 0){
00109                         outStr << "<message>" + m_OSResult->resultHeader->message  + "</message>" << endl;
00110                 }
00111         }
00112         outStr << "</resultHeader>" << endl;
00113         if(m_OSResult->resultData != NULL){
00114                 outStr << "<resultData>" << endl;
00115                 if(m_OSResult->resultData->optimization != NULL && m_OSResult->resultData->optimization->numberOfSolutions > 0){
00116                         outStr << "<optimization " ;
00117                         outStr << "numberOfSolutions=\"";
00118                         outStr << m_OSResult->resultData->optimization->numberOfSolutions ;
00119                         outStr <<  "\"";
00120                         outStr << " numberOfVariables=\"";
00121                         outStr << m_OSResult->resultData->optimization->numberOfVariables ;
00122                         outStr <<  "\"";
00123                         outStr << " numberOfConstraints=\"";
00124                         outStr << m_OSResult->resultData->optimization->numberOfConstraints ;
00125                         outStr <<  "\"";
00126                         outStr << " numberOfObjectives=\"";
00127                         outStr << m_OSResult->resultData->optimization->numberOfObjectives ;
00128                         outStr << "\"" ;
00129                         outStr << ">" << endl;
00130                         // get solution information
00131                         for(i = 0; i < m_OSResult->resultData->optimization->numberOfSolutions; i++){
00132                                 if(m_OSResult->resultData->optimization->solution[i] != NULL){
00133                                         outStr << "<solution" ;
00134                                         outStr << " objectiveIdx=\"";
00135                                         outStr << m_OSResult->resultData->optimization->solution[i]->objectiveIdx ;
00136                                         outStr << "\"" ;
00137                                         outStr << ">" << endl;
00138                                         if(m_OSResult->resultData->optimization->solution[i]->status != NULL){
00139                                                 outStr << "<status";
00140                                                 if(m_OSResult->resultData->optimization->solution[i]->status->type.length() > 0){
00141                                                         outStr << " type=\"";
00142                                                         outStr << m_OSResult->resultData->optimization->solution[i]->status->type;
00143                                                         outStr <<  "\"";
00144                                                 }
00145                                                 if(m_OSResult->resultData->optimization->solution[i]->status->description.length() > 0){
00146                                                         outStr << " description=\"";
00147                                                         outStr <<  m_OSResult->resultData->optimization->solution[i]->status->description;
00148                                                         outStr << "\"" ;
00149                                                 }
00150                                                 outStr << "/>" << endl;
00151                                         }
00152                                         if(m_OSResult->resultData->optimization->solution[i]->message != ""){
00153                                                 outStr << "<message>" << endl;
00154                                                 outStr << m_OSResult->resultData->optimization->solution[i]->message  << endl;
00155                                                 outStr << "</message>" << endl;
00156                                         }
00157                                         if(m_OSResult->resultData->optimization->solution[i]->variables != NULL){
00158                                                 outStr << "<variables>" << endl;
00159                                                 if(m_OSResult->resultData->optimization->solution[i]->variables->values != NULL){
00160                                                         outStr << "<values>" << endl;
00161                                                         for(j = 0; j < m_OSResult->resultData->optimization->numberOfVariables; j++){
00162                                                                 if(m_OSResult->resultData->optimization->solution[i]->variables->values->var[j] != NULL){
00163                                                                         outStr << "<var";
00164                                                                         outStr << " idx=\"";
00165                                                                         outStr << j ;
00166                                                                         outStr <<  "\">";
00167                                                                         outStr <<  m_OSResult->resultData->optimization->solution[i]->variables->values->var[j]->value;
00168                                                                         outStr << "</var>" << endl;
00169                                                                 }
00170                                                         }
00171                                                         outStr << "</values>" << endl;
00172                                                 }
00173                                                 if(m_OSResult->resultData->optimization->solution[i]->variables->other != NULL){
00174                                                         if(m_OSResult->resultData->optimization->solution[i]->variables->numberOfOtherVariableResult > 0){
00175                                                                 for(int k = 0; k < m_OSResult->resultData->optimization->solution[i]->variables->numberOfOtherVariableResult; k++){
00176                                                                         outStr << "<other" ;
00177                                                                         outStr << " name=\"";\
00178                                                                         outStr << m_OSResult->resultData->optimization->solution[i]->variables->other[k]->name;
00179                                                                         outStr << "\"" ;
00180                                                                         outStr << " description=\"";
00181                                                                         outStr << m_OSResult->resultData->optimization->solution[i]->variables->other[k]->description;
00182                                                                         outStr << "\"" ;
00183                                                                         outStr <<  ">" << endl;
00184                                                                         if(m_OSResult->resultData->optimization->solution[i]->variables->other[k]->var.size() > 0){
00185                                                                                 for(j = 0; j < m_OSResult->resultData->optimization->numberOfVariables; j++){
00186                                                                                         if(m_OSResult->resultData->optimization->solution[i]->variables->other[k]->var.size() > 0){
00187                                                                                                 outStr << "<var";
00188                                                                                                 outStr << " idx=\"";
00189                                                                                                 outStr << j ;
00190                                                                                                 outStr <<  "\">";
00191                                                                                                 outStr <<  m_OSResult->resultData->optimization->solution[i]->variables->other[k]->var[j]->value;
00192                                                                                                 outStr << "</var>" << endl;
00193                                                                                         }
00194                                                                                 }
00195                                                                         }
00196                                                                         outStr << "</other>" << endl;
00197                                                                 }
00198                                                         }
00199                                                 } // end of if on other variables
00200                                                 outStr << "</variables>" << endl;
00201                                         }
00202                                         //
00203                                         //
00204                                         //
00205                                         if(m_OSResult->resultData->optimization->solution[i]->objectives != NULL){
00206                                                 outStr << "<objectives>" << endl;
00207                                                 if(m_OSResult->resultData->optimization->solution[i]->objectives->values != NULL){
00208                                                         outStr << "<values>" << endl;
00209                                                         for(j = 0; j < m_OSResult->resultData->optimization->numberOfObjectives; j++){
00210                                                                 if(m_OSResult->resultData->optimization->solution[i]->objectives->values->obj[j] != NULL){
00211                                                                         outStr << "<obj";
00212                                                                         outStr << " idx=\"";
00213                                                                         outStr << -(1 + j) ;
00214                                                                         outStr <<  "\">";
00215                                                                         outStr <<  m_OSResult->resultData->optimization->solution[i]->objectives->values->obj[j]->value;
00216                                                                         outStr << "</obj>" << endl;
00217                                                                 }
00218                                                         }
00219                                                         outStr << "</values>" << endl;
00220                                                 }
00221                                                 if(m_OSResult->resultData->optimization->solution[i]->objectives->other != NULL){
00222                                                         if(m_OSResult->resultData->optimization->solution[i]->objectives->numberOfOtherObjectiveResult > 0){
00223                                                                 for(int k = 0; k < m_OSResult->resultData->optimization->solution[i]->objectives->numberOfOtherObjectiveResult; k++){
00224                                                                         outStr << "<other" ;
00225                                                                         outStr << " name=\"";\
00226                                                                         outStr << m_OSResult->resultData->optimization->solution[i]->objectives->other[k]->name;
00227                                                                         outStr << "\"" ;
00228                                                                         outStr << " description=\"";
00229                                                                         outStr << m_OSResult->resultData->optimization->solution[i]->objectives->other[k]->description;
00230                                                                         outStr << "\"" ;
00231                                                                         outStr <<  ">" << endl;
00232                                                                         if(m_OSResult->resultData->optimization->solution[i]->objectives->other[k]->obj.size() > 0){
00233                                                                                 for(j = 0; j < m_OSResult->resultData->optimization->numberOfObjectives; j++){
00234                                                                                         if(m_OSResult->resultData->optimization->solution[i]->objectives->other[k]->obj.size() > 0){
00235                                                                                                 outStr << "<obj";
00236                                                                                                 outStr << " idx=\"";
00237                                                                                                 outStr << j ;
00238                                                                                                 outStr <<  "\">";
00239                                                                                                 outStr <<  m_OSResult->resultData->optimization->solution[i]->objectives->other[k]->obj[j]->value;
00240                                                                                                 outStr << "</obj>" << endl;
00241                                                                                         }
00242                                                                                 }
00243                                                                         }
00244                                                                         outStr << "</other>" << endl;
00245                                                                 }
00246                                                         }
00247                                                 } // end of if on other objectives
00248                                                 outStr << "</objectives>" << endl;
00249                                         }
00250                                         if(m_OSResult->resultData->optimization->solution[i]->constraints != NULL){
00251                                                 outStr << "<constraints>" << endl;
00252                                                 if(m_OSResult->resultData->optimization->solution[i]->constraints->values != NULL){
00253                                                         outStr << "<values>" << endl;
00254                                                         for(j = 0; j < m_OSResult->resultData->optimization->numberOfConstraints; j++){
00255                                                                 if(m_OSResult->resultData->optimization->solution[i]->constraints->values->con[j] != NULL){
00256                                                                         outStr << "<con";
00257                                                                         outStr << " idx=\"";
00258                                                                         outStr <<  j ;
00259                                                                         outStr <<  "\">";
00260                                                                         outStr <<  m_OSResult->resultData->optimization->solution[i]->constraints->values->con[j]->value;
00261                                                                         outStr << "</con>" << endl;
00262                                                                 }
00263                                                         }
00264                                                         outStr << "</values>" << endl;
00265                                                 }
00266                                                 if(m_OSResult->resultData->optimization->solution[i]->constraints->dualValues != NULL){
00267                                                         outStr << "<dualValues>" << endl;
00268                                                         for(j = 0; j < m_OSResult->resultData->optimization->numberOfConstraints; j++){
00269                                                                 if(m_OSResult->resultData->optimization->solution[i]->constraints->dualValues->con[j] != NULL){
00270                                                                         outStr << "<con";
00271                                                                         outStr << " idx=\"";
00272                                                                         outStr <<  j ;
00273                                                                         outStr <<  "\">";
00274                                                                         outStr <<  m_OSResult->resultData->optimization->solution[i]->constraints->dualValues->con[j]->value;
00275                                                                         outStr << "</con>" << endl;
00276                                                                 }
00277                                                         }
00278                                                         outStr << "</dualValues>" << endl;
00279                                                 }
00280                                                 if(m_OSResult->resultData->optimization->solution[i]->constraints->other != NULL){
00281                                                         if(m_OSResult->resultData->optimization->solution[i]->constraints->numberOfOtherConstraintResult > 0){
00282                                                                 for(int k = 0; k < m_OSResult->resultData->optimization->solution[i]->constraints->numberOfOtherConstraintResult; k++){
00283                                                                         outStr << "<other" ;
00284                                                                         outStr << " name=\"";\
00285                                                                         outStr << m_OSResult->resultData->optimization->solution[i]->constraints->other[k]->name;
00286                                                                         outStr << "\"" ;
00287                                                                         outStr << " description=\"";
00288                                                                         outStr << m_OSResult->resultData->optimization->solution[i]->constraints->other[k]->description;
00289                                                                         outStr << "\"" ;
00290                                                                         outStr <<  ">" << endl;
00291                                                                         if(m_OSResult->resultData->optimization->solution[i]->constraints->other[k]->con.size() > 0){
00292                                                                                 for(j = 0; j < m_OSResult->resultData->optimization->numberOfConstraints; j++){
00293                                                                                         if(m_OSResult->resultData->optimization->solution[i]->constraints->other[k]->con.size() > 0){
00294                                                                                                 outStr << "<con";
00295                                                                                                 outStr << " idx=\"";
00296                                                                                                 outStr << j ;
00297                                                                                                 outStr <<  "\">";
00298                                                                                                 outStr <<  m_OSResult->resultData->optimization->solution[i]->constraints->other[k]->con[j]->value;
00299                                                                                                 outStr << "</con>" << endl;
00300                                                                                         }
00301                                                                                 }
00302                                                                         }
00303                                                                         outStr << "</other>" << endl;
00304                                                                 }
00305                                                         }
00306                                                 } // end of if on other constraints
00307                                                 outStr << "</constraints>" << endl;
00308                                         }
00309                                         outStr << "</solution>" << endl;
00310                                 }
00311                         } // end the solution for loop
00312                         outStr << "</optimization>" << endl;
00313                 }
00314                 outStr << "</resultData>" << endl ;
00315         } // end instanceData if
00316         outStr << "</osrl>" << endl;
00317         return outStr.str();
00318 }// end writeOSrL
00319 
00320 //the following is copied from CoinHelperFunctions
00321 
00322 

Generated on Thu May 15 22:15:05 2008 by  doxygen 1.4.7