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

Go to the documentation of this file.
00001 /* $Id: OSrLWriter.cpp 2852 2009-07-29 05:04:05Z kmartin $ */
00019 //#define DEBUG
00020 
00021 
00022 
00023 
00024 #include "OSrLWriter.h"
00025 #include "OSResult.h"
00026 
00027 #include "OSDataStructures.h"
00028 #include "OSParameters.h" 
00029 #include "OSMathUtil.h"
00030 
00031   
00032 
00033 
00034 #include <sstream>   
00035 #include <iostream>  
00036 
00037 using std::cout;
00038 using std::endl;
00039 using std::ostringstream;
00040 
00041 OSrLWriter::OSrLWriter( ) {      
00042 }
00043 
00044 OSrLWriter::~OSrLWriter(){
00045 }
00046 
00047 
00048 /*char* OSrLWriter::writeOSrLWrap( OSResult *theosresult){
00049         std::string sTmp = writeOSrL( theosresult);
00050         char *ch;
00051     ch = new char[sTmp.size() + 1];
00052     strcpy(ch, sTmp.c_str());
00053         return ch;
00054 }
00055 */
00056 
00057 
00058 
00059 
00060  
00061 std::string OSrLWriter::writeOSrL( OSResult *theosresult){
00062         m_OSResult = theosresult;
00063         std::ostringstream outStr;  
00064         #ifdef WIN_
00065         const char      dirsep='\\';
00066         #else
00067         const char      dirsep='/';
00068         #endif
00069         // Set directory containing stylesheet files.
00070         std::string xsltDir;
00071     xsltDir = dirsep == '/' ? "../stylesheets/" : "..\\stylesheets\\";
00072     // always go with '/' -- it is a hypertext reference
00073     xsltDir = "../stylesheets/";
00074         int i, j;
00075 #ifdef DEBUG
00076         cout << "in OSrLWriter" << endl;
00077 #endif
00078         if(m_OSResult == NULL)  return outStr.str(); 
00079         outStr << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" ; 
00080         outStr << "<?xml-stylesheet type=\"text/xsl\" href=\"";
00081         outStr << xsltDir;
00082         outStr << "OSrL.xslt\"?>";
00083         outStr << endl;
00084         outStr << "<osrl xmlns=\"os.optimizationservices.org\"   xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ";
00085         outStr << "xsi:schemaLocation=\"os.optimizationservices.org http://www.optimizationservices.org/schemas/";
00086         outStr << OS_SCHEMA_VERSION;
00087         outStr << "/OSrL.xsd\" >" ;
00088         outStr << endl;
00089 #ifdef DEBUG
00090         cout << "output <general>" << endl;
00091 #endif
00092         if(m_OSResult->general != NULL){
00093                 outStr << "<general>" << endl;
00094                 if(m_OSResult->general->generalStatus != NULL){
00095                         outStr << "<generalStatus "    ;
00096                         if(m_OSResult->general->generalStatus->type.length() > 0){
00097                                 outStr << "type=\"";
00098                                 outStr << m_OSResult->general->generalStatus->type ;
00099                                 outStr << "\"";
00100                         }
00101                         if(m_OSResult->general->generalStatus->description.length() > 0){
00102                                 outStr << "type=\"";
00103                                 outStr << m_OSResult->general->generalStatus->description ;
00104                                 outStr << "\"";
00105                         }
00106                         outStr << "/>" << endl;
00107                 }               
00108                 
00109                 if(m_OSResult->general->serviceURI.length() > 0){
00110                         outStr << "<serviceURI>" + m_OSResult->general->serviceURI + "</serviceURI>"  << endl;
00111                 }
00112 
00113                 if(m_OSResult->general->serviceName.length() > 0){
00114                         outStr << "<serviceName>" + m_OSResult->general->serviceName + "</serviceName>"  << endl;
00115                 }
00116                 if(m_OSResult->general->instanceName.length() > 0){
00117                         outStr << "<instanceName>" + m_OSResult->general->instanceName  + "</instanceName>" << endl;
00118                 }
00119                 if(m_OSResult->general->jobID.length() > 0){
00120                         outStr << "<jobID>" + m_OSResult->general->jobID  + "</jobID>" << endl;
00121                 }
00122                 if(m_OSResult->general->message.length() > 0){
00123                         outStr << "<message>" + m_OSResult->general->message  + "</message>" << endl;
00124                 }
00125                 outStr << "</general>" << endl;
00126         }
00127 #ifdef DEBUG
00128         cout << "output <system>" << endl;
00129 #endif
00130         if(m_OSResult->system != NULL){
00131         }
00132 #ifdef DEBUG
00133         cout << "output <service>" << endl;
00134 #endif
00135         if(m_OSResult->service != NULL){
00136         }
00137 #ifdef DEBUG
00138         cout << "output <job>" << endl;
00139 #endif
00140         if(m_OSResult->job != NULL){
00141                 outStr << "<job>" << endl;
00142                 if (m_OSResult->job->timingInformation != NULL)
00143                         if (m_OSResult->job->timingInformation->numberOfTimes > 0)
00144                         {       outStr << "<timingInformation numberOfTimes=\"";
00145                                 outStr << m_OSResult->job->timingInformation->numberOfTimes << "\">" << endl;
00146                                 for (i=0; i<m_OSResult->job->timingInformation->numberOfTimes; i++)
00147                                 {       outStr << "<time ";
00148                                         if (m_OSResult->job->timingInformation->time[i]->type != "")
00149                                                 outStr << "type=\"" << m_OSResult->job->timingInformation->time[i]->type << "\" ";
00150                                         if (m_OSResult->job->timingInformation->time[i]->unit != "")
00151                                                 outStr << "unit=\"" << m_OSResult->job->timingInformation->time[i]->unit << "\" ";
00152                                         if (m_OSResult->job->timingInformation->time[i]->category != "")
00153                                                 outStr << "category=\"" << m_OSResult->job->timingInformation->time[i]->category << "\" ";
00154                                         if (m_OSResult->job->timingInformation->time[i]->description != "")
00155                                                 outStr << "description=\"" << m_OSResult->job->timingInformation->time[i]->description << "\" ";
00156                                         outStr << ">" << endl;
00157                                         outStr << os_dtoa_format(m_OSResult->job->timingInformation->time[i]->value);
00158                                         outStr << "</time>" << endl; 
00159                                 }
00160                                 outStr << "</timingInformation>" << endl;
00161                         }
00162                 outStr << "</job>" << endl;
00163         }
00164 #ifdef DEBUG
00165         cout << "output <optimization>" << endl;
00166 #endif
00167         if(m_OSResult->optimization != NULL && m_OSResult->optimization->numberOfSolutions > 0){
00168                 outStr << "<optimization " ;
00169                 outStr << "numberOfSolutions=\"";
00170                 outStr << m_OSResult->optimization->numberOfSolutions ;
00171                 outStr <<  "\"";
00172                 outStr << " numberOfVariables=\"";
00173                 outStr << m_OSResult->optimization->numberOfVariables ;
00174                 outStr <<  "\"";
00175                 outStr << " numberOfConstraints=\"";
00176                 outStr << m_OSResult->optimization->numberOfConstraints ;
00177                 outStr <<  "\"";
00178                 outStr << " numberOfObjectives=\"";
00179                 outStr << m_OSResult->optimization->numberOfObjectives ;
00180                 outStr << "\"" ;
00181                 outStr << ">" << endl;
00182                 // get solution information
00183                 for(i = 0; i < m_OSResult->optimization->numberOfSolutions; i++){
00184                         if(m_OSResult->optimization->solution[i] != NULL){
00185                                 outStr << "<solution" ;
00186                                 outStr << " targetObjectiveIdx=\"";
00187                                 outStr << m_OSResult->optimization->solution[i]->targetObjectiveIdx ;
00188                                 outStr << "\"" ;
00189                                 outStr << ">" << endl;
00190                                 if(m_OSResult->optimization->solution[i]->status != NULL){
00191                                         outStr << "<status";
00192                                         if(m_OSResult->optimization->solution[i]->status->type.length() > 0){
00193                                                 outStr << " type=\"";
00194                                                 outStr << m_OSResult->optimization->solution[i]->status->type;
00195                                                 outStr <<  "\"";
00196                                         }
00197                                         if(m_OSResult->optimization->solution[i]->status->description.length() > 0){
00198                                                 outStr << " description=\"";
00199                                                 outStr <<  m_OSResult->optimization->solution[i]->status->description;
00200                                                 outStr << "\"" ;
00201                                         }
00202                                         outStr << "/>" << endl;
00203                                 }
00204                                 if(m_OSResult->optimization->solution[i]->message != ""){
00205                                         outStr << "<message>" << endl;
00206                                         outStr << m_OSResult->optimization->solution[i]->message  << endl;
00207                                         outStr << "</message>" << endl;
00208                                 }
00209                                 if(m_OSResult->optimization->solution[i]->variables != NULL){
00210                                         outStr << "<variables ";
00211                                         if (m_OSResult->optimization->solution[i]->variables->numberOfOtherVariableResults > 0)
00212                                                 outStr << "numberOfOtherVariableResults=\"" << m_OSResult->optimization->solution[i]->variables->numberOfOtherVariableResults << "\""; 
00213                                         outStr << ">" << endl;
00214                                         if(m_OSResult->optimization->solution[i]->variables->values != NULL){
00215 #ifdef DEBUG
00216         cout << "output <variables> <values>" << endl;
00217 #endif
00218                                                 outStr << "<values numberOfVar=\"" << m_OSResult->optimization->solution[i]->variables->values->numberOfVar << "\">" << endl;
00219                                                 for(j = 0; j < m_OSResult->optimization->solution[i]->variables->values->numberOfVar; j++){
00220                                                         if(m_OSResult->optimization->solution[i]->variables->values->var[j] != NULL){
00221                                                                 outStr << "<var";
00222                                                                 outStr << " idx=\"";
00223                                                                 outStr << j ;
00224                                                                 outStr <<  "\">";
00225                                                                 outStr <<  os_dtoa_format( m_OSResult->optimization->solution[i]->variables->values->var[j]->value );
00226                                                                 outStr << "</var>" << endl;
00227                                                         }
00228                                                 }
00229                                                 outStr << "</values>" << endl;
00230                                         }
00231 #ifdef DEBUG
00232         cout << "output <variables> <other>" << endl;
00233 #endif
00234                                         if(m_OSResult->optimization->solution[i]->variables->other != NULL){
00235                                                 if(m_OSResult->optimization->solution[i]->variables->numberOfOtherVariableResults > 0){
00236                                                         for(int k = 0; k < m_OSResult->optimization->solution[i]->variables->numberOfOtherVariableResults; k++){
00237 
00238                                                                 outStr << "<other" ;
00239                                                                 outStr << " numberOfVar=\"";
00240                                                                 outStr << m_OSResult->optimization->solution[i]->variables->other[k]->numberOfVar;
00241                                                                 outStr << "\"" ;
00242                                                                 if (m_OSResult->optimization->solution[i]->variables->other[k]->name != "")
00243                                                                 {
00244                                                                         outStr << " name=\"";
00245                                                                         outStr << m_OSResult->optimization->solution[i]->variables->other[k]->name;
00246                                                                         outStr << "\"" ;
00247                                                                 }
00248                                                                 if (m_OSResult->optimization->solution[i]->variables->other[k]->value != "")
00249                                                                 {
00250                                                                         outStr << " value=\"";
00251                                                                         outStr << m_OSResult->optimization->solution[i]->variables->other[k]->value;
00252                                                                         outStr << "\"" ;
00253                                                                 }
00254                                                                 if (m_OSResult->optimization->solution[i]->variables->other[k]->description != "")
00255                                                                 {
00256                                                                         outStr << " description=\"";
00257                                                                         outStr << m_OSResult->optimization->solution[i]->variables->other[k]->description;
00258                                                                         outStr << "\"" ;
00259                                                                 }
00260                                                                 outStr <<  ">" << endl;
00261                                                                 if(m_OSResult->optimization->solution[i]->variables->other[k]->var.size() > 0){
00262                                                                         for(j = 0; j < m_OSResult->optimization->solution[i]->variables->other[k]->numberOfVar; j++){
00263                                                                                 if(m_OSResult->optimization->solution[i]->variables->other[k]->var.size() > 0){
00264                                                                                         outStr << "<var";
00265                                                                                         outStr << " idx=\"";
00266                                                                                         outStr << m_OSResult->optimization->solution[i]->variables->other[k]->var[j]->idx ;
00267                                                                                         outStr <<  "\">";
00268                                                                                         outStr << m_OSResult->optimization->solution[i]->variables->other[k]->var[j]->value;
00269                                                                                         outStr << "</var>" << endl;
00270                                                                                 }
00271                                                                         }
00272                                                                 }
00273                                                                 outStr << "</other>" << endl;
00274                                                         }
00275                                                 }
00276                                         } // end of if on other variables
00277                                         outStr << "</variables>" << endl;
00278                                 }
00279                                 //
00280                                 //
00281                                 //
00282                                 if(m_OSResult->optimization->solution[i]->objectives != NULL){
00283                                         outStr << "<objectives ";
00284                                         if (m_OSResult->optimization->solution[i]->objectives->numberOfOtherObjectiveResults > 0)
00285                                                 outStr << "numberOfOtherObjectiveResults=\"" << m_OSResult->optimization->solution[i]->objectives->numberOfOtherObjectiveResults << "\""; 
00286                                         outStr << ">" << endl;
00287 #ifdef DEBUG
00288         cout << "output <objectives> <values>" << endl;
00289 #endif
00290                                         if(m_OSResult->optimization->solution[i]->objectives->values != NULL){
00291                                                 outStr << "<values numberOfObj=\"" << m_OSResult->optimization->solution[i]->objectives->values->numberOfObj << "\">" << endl;
00292                                                 for(j = 0; j < m_OSResult->optimization->solution[i]->objectives->values->numberOfObj; j++){
00293                                                         if(m_OSResult->optimization->solution[i]->objectives->values->obj[j] != NULL){
00294                                                                 outStr << "<obj";
00295                                                                 outStr << " idx=\"";
00296                                                                 outStr << m_OSResult->optimization->solution[i]->objectives->values->obj[j]->idx; //-(1 + j) ;
00297                                                                 outStr <<  "\">";
00298                                                                 outStr <<  os_dtoa_format( m_OSResult->optimization->solution[i]->objectives->values->obj[j]->value);
00299                                                                 outStr << "</obj>" << endl;
00300                                                         }
00301                                                 }
00302 
00303                                                 outStr << "</values>" << endl;
00304                                         }
00305 #ifdef DEBUG
00306         cout << "output <objectives> <other>" << endl;
00307 #endif
00308                                         if(m_OSResult->optimization->solution[i]->objectives->other != NULL){
00309                                                 if(m_OSResult->optimization->solution[i]->objectives->numberOfOtherObjectiveResults > 0){
00310                                                         for(int k = 0; k < m_OSResult->optimization->solution[i]->objectives->numberOfOtherObjectiveResults; k++){
00311                                                                 outStr << "<other" ;
00312                                                                 outStr << " name=\"";\
00313                                                                 outStr << m_OSResult->optimization->solution[i]->objectives->other[k]->name;
00314                                                                 outStr << "\"" ;
00315                                                                 outStr << " description=\"";
00316                                                                 outStr << m_OSResult->optimization->solution[i]->objectives->other[k]->description;
00317                                                                 outStr << "\"" ;
00318                                                                 outStr <<  ">" << endl;
00319                                                                 if(m_OSResult->optimization->solution[i]->objectives->other[k]->obj.size() > 0){
00320                                                                         for(j = 0; j < m_OSResult->optimization->solution[i]->objectives->other[k]->numberOfObj; j++){
00321                                                                                 if(m_OSResult->optimization->solution[i]->objectives->other[k]->obj.size() > 0){
00322                                                                                         outStr << "<obj";
00323                                                                                         outStr << " idx=\"";
00324                                                                                         outStr << j ;
00325                                                                                         outStr <<  "\">";
00326                                                                                         outStr <<   m_OSResult->optimization->solution[i]->objectives->other[k]->obj[j]->value;
00327                                                                                         outStr << "</obj>" << endl;
00328                                                                                 }
00329                                                                         }
00330                                                                 }
00331                                                                 outStr << "</other>" << endl;
00332                                                         }
00333                                                 }
00334                                         } // end of if on other objectives
00335                                         outStr << "</objectives>" << endl;
00336                                 }
00337                                 if(m_OSResult->optimization->solution[i]->constraints != NULL){
00338                                         outStr << "<constraints ";
00339                                         if (m_OSResult->optimization->solution[i]->constraints->numberOfOtherConstraintResults > 0)
00340                                                 outStr << "numberOfOtherConstraintResults=\"" << m_OSResult->optimization->solution[i]->constraints->numberOfOtherConstraintResults << "\""; 
00341                                         outStr << ">" << endl;
00342 #ifdef DEBUG
00343         cout << "output <constraints> <dualValues>" << endl;
00344 #endif
00345                                         if(m_OSResult->optimization->solution[i]->constraints->dualValues != NULL){
00346                                                 outStr << "<dualValues numberOfCon=\"" << m_OSResult->optimization->solution[i]->constraints->dualValues->numberOfCon << "\">" << endl;
00347                                                 for(j = 0; j < m_OSResult->optimization->solution[i]->constraints->dualValues->numberOfCon; j++){
00348                                                         if(m_OSResult->optimization->solution[i]->constraints->dualValues->con[j] != NULL){
00349                                                                 outStr << "<con";
00350                                                                 outStr << " idx=\"";
00351                                                                 outStr <<  j ;
00352                                                                 outStr <<  "\">";
00353                                                                 outStr <<  os_dtoa_format( m_OSResult->optimization->solution[i]->constraints->dualValues->con[j]->value);
00354                                                                 outStr << "</con>" << endl;
00355                                                         }
00356                                                 }
00357                                                 outStr << "</dualValues>" << endl;
00358                                         }
00359 #ifdef DEBUG
00360         cout << "output <constraints> <other>" << endl;
00361 #endif
00362                                         if(m_OSResult->optimization->solution[i]->constraints->other != NULL){
00363                                                 if(m_OSResult->optimization->solution[i]->constraints->numberOfOtherConstraintResults > 0){
00364                                                         for(int k = 0; k < m_OSResult->optimization->solution[i]->constraints->numberOfOtherConstraintResults; k++){
00365                                                                 outStr << "<other" ;
00366                                                                 outStr << " name=\"";\
00367                                                                 outStr << m_OSResult->optimization->solution[i]->constraints->other[k]->name;
00368                                                                 outStr << "\"" ;
00369                                                                 outStr << " description=\"";
00370                                                                 outStr << m_OSResult->optimization->solution[i]->constraints->other[k]->description;
00371                                                                 outStr << "\"" ;
00372                                                                 outStr <<  ">" << endl;
00373                                                                 if(m_OSResult->optimization->solution[i]->constraints->other[k]->con.size() > 0){
00374                                                                         for(j = 0; j < m_OSResult->optimization->solution[i]->constraints->other[k]->numberOfCon; j++){
00375                                                                                 if(m_OSResult->optimization->solution[i]->constraints->other[k]->con.size() > 0){
00376                                                                                         outStr << "<con";
00377                                                                                         outStr << " idx=\"";
00378                                                                                         outStr << j ;
00379                                                                                         outStr <<  "\">";
00380                                                                                         outStr <<  m_OSResult->optimization->solution[i]->constraints->other[k]->con[j]->value;
00381                                                                                         outStr << "</con>" << endl;
00382                                                                                 }
00383                                                                         }
00384                                                                 }
00385                                                                 outStr << "</other>" << endl;
00386                                                         }
00387                                                 }
00388                                         } // end of if on other constraints
00389                                         outStr << "</constraints>" << endl;
00390                                 }
00391 #ifdef DEBUG
00392         cout << "output <otherSolutionResults>" << endl;
00393 #endif
00394                         if (m_OSResult->optimization->solution[i]->otherSolutionResults != NULL)
00395                                         if (m_OSResult->optimization->solution[i]->otherSolutionResults->numberOfOtherSolutionResults > 0){
00396                                                 outStr << "<otherSolutionResults numberOfOtherSolutionResults=\"";
00397                                                 outStr << m_OSResult->optimization->solution[i]->otherSolutionResults->numberOfOtherSolutionResults;
00398                                                 outStr << "\">" << std::endl;
00399                                                 for(int k = 0; k < m_OSResult->optimization->solution[i]->otherSolutionResults->numberOfOtherSolutionResults; k++){
00400                                                         outStr << "<otherSolutionResult";
00401                                                         outStr << " name=\"";
00402                                                         outStr << m_OSResult->optimization->solution[i]->otherSolutionResults->otherSolutionResult[k]->name;
00403                                                         outStr << "\"";
00404                                                         if (m_OSResult->optimization->solution[i]->otherSolutionResults->otherSolutionResult[k]->category != "")
00405                                                                 outStr << " category=\"" << m_OSResult->optimization->solution[i]->otherSolutionResults->otherSolutionResult[k]->category << "\"";
00406                                                         if (m_OSResult->optimization->solution[i]->otherSolutionResults->otherSolutionResult[k]->description != "")
00407                                                                 outStr << " description=\"" << m_OSResult->optimization->solution[i]->otherSolutionResults->otherSolutionResult[k]->description << "\"";
00408                                                         if (m_OSResult->optimization->solution[i]->otherSolutionResults->otherSolutionResult[k]->numberOfItems > 0)
00409                                                                 outStr << " numberOfItems=\"" << m_OSResult->optimization->solution[i]->otherSolutionResults->otherSolutionResult[k]->numberOfItems << "\"";
00410                                                         outStr << ">" << std::endl;
00411                                                         for(int j = 0; j < m_OSResult->optimization->solution[i]->otherSolutionResults->otherSolutionResult[k]->numberOfItems; j++){
00412                                                                 outStr << "<item>" << m_OSResult->optimization->solution[i]->otherSolutionResults->otherSolutionResult[k]->item[j] << "</item>" << std::endl;
00413                                                         }
00414                                                         outStr << "</otherSolutionResult>" << std::endl;
00415                                                 }
00416                                                 outStr << "</otherSolutionResults>" << std::endl;
00417                                         }
00418  
00419                                 outStr << "</solution>" << endl;
00420                         }
00421                 } // end the solution for loop
00422                 outStr << "</optimization>" << endl;
00423         } // end if (optimization != NULL)
00424 #ifdef DEBUG 
00425         cout << "done" << endl;
00426 #endif
00427         outStr << "</osrl>" << endl ;
00428         return outStr.str();
00429 }// end writeOSrL
00430 
00431 

Generated on Mon Aug 3 03:02:23 2009 by  doxygen 1.4.7