00001
00023 #include "OSrLWriter.h"
00024 #include "OSResult.h"
00025
00026 #include "OSDataStructures.h"
00027 #include "OSParameters.h"
00028 #include "OSCommonUtil.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
00049
00050
00051
00052
00053
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
00070 std::string xsltDir;
00071 xsltDir = dirsep == '/' ? "../stylesheets/" : "..\\stylesheets\\";
00072
00073 xsltDir = "../stylesheets/";
00074 int i, j;
00075 if(m_OSResult == NULL) return outStr.str();
00076 outStr << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" ;
00077 outStr << "<?xml-stylesheet type = \"text/xsl\" href = \"";
00078 outStr << xsltDir;
00079 outStr << "OSrL.xslt\"?>";
00080 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\" >" ;
00081 outStr << endl;
00082 outStr << "<resultHeader>" << endl;
00083 if(m_OSResult->resultHeader != NULL){
00084 if(m_OSResult->resultHeader->generalStatus != NULL){
00085 outStr << "<generalStatus " ;
00086 if(m_OSResult->resultHeader->generalStatus->type.length() > 0){
00087 outStr << "type=\"";
00088 outStr << m_OSResult->resultHeader->generalStatus->type ;
00089 outStr << "\"";
00090 }
00091 if(m_OSResult->resultHeader->generalStatus->description.length() > 0){
00092 outStr << "type=\"";
00093 outStr << m_OSResult->resultHeader->generalStatus->description ;
00094 outStr << "\"";
00095 }
00096 outStr << "/>" << endl;
00097 }
00098
00099 if(m_OSResult->resultHeader->serviceURI.length() > 0){
00100 outStr << "<serviceURI>" + m_OSResult->resultHeader->serviceURI + "</serviceURI>" << endl;
00101 }
00102
00103 if(m_OSResult->resultHeader->serviceName.length() > 0){
00104 outStr << "<serviceName>" + m_OSResult->resultHeader->serviceName + "</serviceName>" << endl;
00105 }
00106 if(m_OSResult->resultHeader->instanceName.length() > 0){
00107 outStr << "<instanceName>" + m_OSResult->resultHeader->instanceName + "</instanceName>" << endl;
00108 }
00109 if(m_OSResult->resultHeader->jobID.length() > 0){
00110 outStr << "<jobID>" + m_OSResult->resultHeader->jobID + "</jobID>" << endl;
00111 }
00112 if(m_OSResult->resultHeader->time.length() > 0){
00113 outStr << "<time>" + m_OSResult->resultHeader->time + "</time>" << endl;
00114 }
00115 if(m_OSResult->resultHeader->message.length() > 0){
00116 outStr << "<message>" + m_OSResult->resultHeader->message + "</message>" << endl;
00117 }
00118 }
00119 outStr << "</resultHeader>" << endl;
00120 if(m_OSResult->resultData != NULL){
00121 outStr << "<resultData>" << endl;
00122 if(m_OSResult->resultData->optimization != NULL && m_OSResult->resultData->optimization->numberOfSolutions > 0){
00123 outStr << "<optimization " ;
00124 outStr << "numberOfSolutions=\"";
00125 outStr << m_OSResult->resultData->optimization->numberOfSolutions ;
00126 outStr << "\"";
00127 outStr << " numberOfVariables=\"";
00128 outStr << m_OSResult->resultData->optimization->numberOfVariables ;
00129 outStr << "\"";
00130 outStr << " numberOfConstraints=\"";
00131 outStr << m_OSResult->resultData->optimization->numberOfConstraints ;
00132 outStr << "\"";
00133 outStr << " numberOfObjectives=\"";
00134 outStr << m_OSResult->resultData->optimization->numberOfObjectives ;
00135 outStr << "\"" ;
00136 outStr << ">" << endl;
00137
00138 for(i = 0; i < m_OSResult->resultData->optimization->numberOfSolutions; i++){
00139 if(m_OSResult->resultData->optimization->solution[i] != NULL){
00140 outStr << "<solution" ;
00141 outStr << " objectiveIdx=\"";
00142 outStr << m_OSResult->resultData->optimization->solution[i]->objectiveIdx ;
00143 outStr << "\"" ;
00144 outStr << ">" << endl;
00145 if(m_OSResult->resultData->optimization->solution[i]->status != NULL){
00146 outStr << "<status";
00147 if(m_OSResult->resultData->optimization->solution[i]->status->type.length() > 0){
00148 outStr << " type=\"";
00149 outStr << m_OSResult->resultData->optimization->solution[i]->status->type;
00150 outStr << "\"";
00151 }
00152 if(m_OSResult->resultData->optimization->solution[i]->status->description.length() > 0){
00153 outStr << " description=\"";
00154 outStr << m_OSResult->resultData->optimization->solution[i]->status->description;
00155 outStr << "\"" ;
00156 }
00157 outStr << "/>" << endl;
00158 }
00159 if(m_OSResult->resultData->optimization->solution[i]->message != ""){
00160 outStr << "<message>" << endl;
00161 outStr << m_OSResult->resultData->optimization->solution[i]->message << endl;
00162 outStr << "</message>" << endl;
00163 }
00164 if(m_OSResult->resultData->optimization->solution[i]->variables != NULL){
00165 outStr << "<variables>" << endl;
00166 if(m_OSResult->resultData->optimization->solution[i]->variables->values != NULL){
00167 outStr << "<values>" << endl;
00168 for(j = 0; j < m_OSResult->resultData->optimization->numberOfVariables; j++){
00169 if(m_OSResult->resultData->optimization->solution[i]->variables->values->var[j] != NULL){
00170 outStr << "<var";
00171 outStr << " idx=\"";
00172 outStr << j ;
00173 outStr << "\">";
00174 outStr << os_dtoa_format( m_OSResult->resultData->optimization->solution[i]->variables->values->var[j]->value );
00175 outStr << "</var>" << endl;
00176 }
00177 }
00178 outStr << "</values>" << endl;
00179 }
00180 if(m_OSResult->resultData->optimization->solution[i]->variables->other != NULL){
00181 if(m_OSResult->resultData->optimization->solution[i]->variables->numberOfOtherVariableResult > 0){
00182 for(int k = 0; k < m_OSResult->resultData->optimization->solution[i]->variables->numberOfOtherVariableResult; k++){
00183 outStr << "<other" ;
00184 outStr << " name=\"";
00185 outStr << m_OSResult->resultData->optimization->solution[i]->variables->other[k]->name;
00186 outStr << "\"" ;
00187 outStr << " description=\"";
00188 outStr << m_OSResult->resultData->optimization->solution[i]->variables->other[k]->description;
00189 outStr << "\"" ;
00190 outStr << ">" << endl;
00191 if(m_OSResult->resultData->optimization->solution[i]->variables->other[k]->var.size() > 0){
00192 for(j = 0; j < m_OSResult->resultData->optimization->numberOfVariables; j++){
00193 if(m_OSResult->resultData->optimization->solution[i]->variables->other[k]->var.size() > 0){
00194 outStr << "<var";
00195 outStr << " idx=\"";
00196 outStr << j ;
00197 outStr << "\">";
00198 outStr << m_OSResult->resultData->optimization->solution[i]->variables->other[k]->var[j]->value;
00199 outStr << "</var>" << endl;
00200 }
00201 }
00202 }
00203 outStr << "</other>" << endl;
00204 }
00205 }
00206 }
00207 outStr << "</variables>" << endl;
00208 }
00209
00210
00211
00212 if(m_OSResult->resultData->optimization->solution[i]->objectives != NULL){
00213 outStr << "<objectives>" << endl;
00214 if(m_OSResult->resultData->optimization->solution[i]->objectives->values != NULL){
00215 outStr << "<values>" << endl;
00216 for(j = 0; j < m_OSResult->resultData->optimization->numberOfObjectives; j++){
00217 if(m_OSResult->resultData->optimization->solution[i]->objectives->values->obj[j] != NULL){
00218 outStr << "<obj";
00219 outStr << " idx=\"";
00220 outStr << -(1 + j) ;
00221 outStr << "\">";
00222 outStr << os_dtoa_format( m_OSResult->resultData->optimization->solution[i]->objectives->values->obj[j]->value);
00223 outStr << "</obj>" << endl;
00224 }
00225 }
00226 outStr << "</values>" << endl;
00227 }
00228 if(m_OSResult->resultData->optimization->solution[i]->objectives->other != NULL){
00229 if(m_OSResult->resultData->optimization->solution[i]->objectives->numberOfOtherObjectiveResult > 0){
00230 for(int k = 0; k < m_OSResult->resultData->optimization->solution[i]->objectives->numberOfOtherObjectiveResult; k++){
00231 outStr << "<other" ;
00232 outStr << " name=\"";\
00233 outStr << m_OSResult->resultData->optimization->solution[i]->objectives->other[k]->name;
00234 outStr << "\"" ;
00235 outStr << " description=\"";
00236 outStr << m_OSResult->resultData->optimization->solution[i]->objectives->other[k]->description;
00237 outStr << "\"" ;
00238 outStr << ">" << endl;
00239 if(m_OSResult->resultData->optimization->solution[i]->objectives->other[k]->obj.size() > 0){
00240 for(j = 0; j < m_OSResult->resultData->optimization->numberOfObjectives; j++){
00241 if(m_OSResult->resultData->optimization->solution[i]->objectives->other[k]->obj.size() > 0){
00242 outStr << "<obj";
00243 outStr << " idx=\"";
00244 outStr << j ;
00245 outStr << "\">";
00246 outStr << m_OSResult->resultData->optimization->solution[i]->objectives->other[k]->obj[j]->value;
00247 outStr << "</obj>" << endl;
00248 }
00249 }
00250 }
00251 outStr << "</other>" << endl;
00252 }
00253 }
00254 }
00255 outStr << "</objectives>" << endl;
00256 }
00257 if(m_OSResult->resultData->optimization->solution[i]->constraints != NULL){
00258 outStr << "<constraints>" << endl;
00259 if(m_OSResult->resultData->optimization->solution[i]->constraints->values != NULL){
00260 outStr << "<values>" << endl;
00261 for(j = 0; j < m_OSResult->resultData->optimization->numberOfConstraints; j++){
00262 if(m_OSResult->resultData->optimization->solution[i]->constraints->values->con[j] != NULL){
00263 outStr << "<con";
00264 outStr << " idx=\"";
00265 outStr << j ;
00266 outStr << "\">";
00267 outStr << os_dtoa_format( m_OSResult->resultData->optimization->solution[i]->constraints->values->con[j]->value);
00268 outStr << "</con>" << endl;
00269 }
00270 }
00271 outStr << "</values>" << endl;
00272 }
00273 if(m_OSResult->resultData->optimization->solution[i]->constraints->dualValues != NULL){
00274 outStr << "<dualValues>" << endl;
00275 for(j = 0; j < m_OSResult->resultData->optimization->numberOfConstraints; j++){
00276 if(m_OSResult->resultData->optimization->solution[i]->constraints->dualValues->con[j] != NULL){
00277 outStr << "<con";
00278 outStr << " idx=\"";
00279 outStr << j ;
00280 outStr << "\">";
00281 outStr << os_dtoa_format( m_OSResult->resultData->optimization->solution[i]->constraints->dualValues->con[j]->value );
00282 outStr << "</con>" << endl;
00283 }
00284 }
00285 outStr << "</dualValues>" << endl;
00286 }
00287 if(m_OSResult->resultData->optimization->solution[i]->constraints->other != NULL){
00288 if(m_OSResult->resultData->optimization->solution[i]->constraints->numberOfOtherConstraintResult > 0){
00289 for(int k = 0; k < m_OSResult->resultData->optimization->solution[i]->constraints->numberOfOtherConstraintResult; k++){
00290 outStr << "<other" ;
00291 outStr << " name=\"";\
00292 outStr << m_OSResult->resultData->optimization->solution[i]->constraints->other[k]->name;
00293 outStr << "\"" ;
00294 outStr << " description=\"";
00295 outStr << m_OSResult->resultData->optimization->solution[i]->constraints->other[k]->description;
00296 outStr << "\"" ;
00297 outStr << ">" << endl;
00298 if(m_OSResult->resultData->optimization->solution[i]->constraints->other[k]->con.size() > 0){
00299 for(j = 0; j < m_OSResult->resultData->optimization->numberOfConstraints; j++){
00300 if(m_OSResult->resultData->optimization->solution[i]->constraints->other[k]->con.size() > 0){
00301 outStr << "<con";
00302 outStr << " idx=\"";
00303 outStr << j ;
00304 outStr << "\">";
00305 outStr << m_OSResult->resultData->optimization->solution[i]->constraints->other[k]->con[j]->value;
00306 outStr << "</con>" << endl;
00307 }
00308 }
00309 }
00310 outStr << "</other>" << endl;
00311 }
00312 }
00313 }
00314 outStr << "</constraints>" << endl;
00315 }
00316 outStr << "</solution>" << endl;
00317 }
00318 }
00319 outStr << "</optimization>" << endl;
00320 }
00321 outStr << "</resultData>" << endl ;
00322 }
00323 outStr << "</osrl>" << endl;
00324 return outStr.str();
00325 }
00326
00327
00328
00329