00001
00018 #define DEBUG
00019
00020
00021
00022
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 #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
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 cout << "<other" ;
00238 cout << " numberOfVar=\"";
00239 cout << m_OSResult->optimization->solution[i]->variables->other[k]->numberOfVar;
00240 cout << "\"" ;
00241 cout << " name=\"";
00242 cout << m_OSResult->optimization->solution[i]->variables->other[k]->name;
00243 cout << "\"" ;
00244 cout << " value=\"";
00245 cout << m_OSResult->optimization->solution[i]->variables->other[k]->value;
00246 cout << "\"" ;
00247 cout << " description=\"";
00248 cout << m_OSResult->optimization->solution[i]->variables->other[k]->description;
00249 cout << "\"" ;
00250 cout << ">" << endl;
00251
00252 outStr << "<other" ;
00253 outStr << " numberOfVar=\"";
00254 outStr << m_OSResult->optimization->solution[i]->variables->other[k]->numberOfVar;
00255 outStr << "\"" ;
00256 if (m_OSResult->optimization->solution[i]->variables->other[k]->name != "")
00257 {
00258 outStr << " name=\"";
00259 outStr << m_OSResult->optimization->solution[i]->variables->other[k]->name;
00260 outStr << "\"" ;
00261 }
00262 if (m_OSResult->optimization->solution[i]->variables->other[k]->value != "")
00263 {
00264 outStr << " value=\"";
00265 outStr << m_OSResult->optimization->solution[i]->variables->other[k]->value;
00266 outStr << "\"" ;
00267 }
00268 if (m_OSResult->optimization->solution[i]->variables->other[k]->description != "")
00269 {
00270 outStr << " description=\"";
00271 outStr << m_OSResult->optimization->solution[i]->variables->other[k]->description;
00272 outStr << "\"" ;
00273 }
00274 outStr << ">" << endl;
00275 if(m_OSResult->optimization->solution[i]->variables->other[k]->var.size() > 0){
00276 for(j = 0; j < m_OSResult->optimization->solution[i]->variables->other[k]->numberOfVar; j++){
00277 if(m_OSResult->optimization->solution[i]->variables->other[k]->var.size() > 0){
00278 outStr << "<var";
00279 outStr << " idx=\"";
00280 outStr << j ;
00281 outStr << "\">";
00282 outStr << m_OSResult->optimization->solution[i]->variables->other[k]->var[j]->value;
00283 outStr << "</var>" << endl;
00284 }
00285 }
00286 }
00287 outStr << "</other>" << endl;
00288 }
00289 }
00290 }
00291 outStr << "</variables>" << endl;
00292 }
00293
00294
00295
00296 if(m_OSResult->optimization->solution[i]->objectives != NULL){
00297 outStr << "<objectives ";
00298 if (m_OSResult->optimization->solution[i]->objectives->numberOfOtherObjectiveResults > 0)
00299 outStr << "numberOfOtherObjectiveResults=\"" << m_OSResult->optimization->solution[i]->objectives->numberOfOtherObjectiveResults << "\"";
00300 outStr << ">" << endl;
00301 #ifdef DEBUG
00302 cout << "output <objectives> <values>" << endl;
00303 #endif
00304 if(m_OSResult->optimization->solution[i]->objectives->values != NULL){
00305 outStr << "<values numberOfObj=\"" << m_OSResult->optimization->solution[i]->objectives->values->numberOfObj << "\">" << endl;
00306 for(j = 0; j < m_OSResult->optimization->solution[i]->objectives->values->numberOfObj; j++){
00307 if(m_OSResult->optimization->solution[i]->objectives->values->obj[j] != NULL){
00308 outStr << "<obj";
00309 outStr << " idx=\"";
00310 outStr << -(1 + j) ;
00311 outStr << "\">";
00312 outStr << os_dtoa_format( m_OSResult->optimization->solution[i]->objectives->values->obj[j]->value);
00313 outStr << "</obj>" << endl;
00314 }
00315 }
00316 outStr << "</values>" << endl;
00317 }
00318 #ifdef DEBUG
00319 cout << "output <objectives> <other>" << endl;
00320 #endif
00321 if(m_OSResult->optimization->solution[i]->objectives->other != NULL){
00322 if(m_OSResult->optimization->solution[i]->objectives->numberOfOtherObjectiveResults > 0){
00323 for(int k = 0; k < m_OSResult->optimization->solution[i]->objectives->numberOfOtherObjectiveResults; k++){
00324 outStr << "<other" ;
00325 outStr << " name=\"";\
00326 outStr << m_OSResult->optimization->solution[i]->objectives->other[k]->name;
00327 outStr << "\"" ;
00328 outStr << " description=\"";
00329 outStr << m_OSResult->optimization->solution[i]->objectives->other[k]->description;
00330 outStr << "\"" ;
00331 outStr << ">" << endl;
00332 if(m_OSResult->optimization->solution[i]->objectives->other[k]->obj.size() > 0){
00333 for(j = 0; j < m_OSResult->optimization->solution[i]->objectives->other[k]->numberOfObj; j++){
00334 if(m_OSResult->optimization->solution[i]->objectives->other[k]->obj.size() > 0){
00335 outStr << "<obj";
00336 outStr << " idx=\"";
00337 outStr << j ;
00338 outStr << "\">";
00339 outStr << m_OSResult->optimization->solution[i]->objectives->other[k]->obj[j]->value;
00340 outStr << "</obj>" << endl;
00341 }
00342 }
00343 }
00344 outStr << "</other>" << endl;
00345 }
00346 }
00347 }
00348 outStr << "</objectives>" << endl;
00349 }
00350 if(m_OSResult->optimization->solution[i]->constraints != NULL){
00351 outStr << "<constraints ";
00352 if (m_OSResult->optimization->solution[i]->constraints->numberOfOtherConstraintResults > 0)
00353 outStr << "numberOfOtherConstraintResults=\"" << m_OSResult->optimization->solution[i]->constraints->numberOfOtherConstraintResults << "\"";
00354 outStr << ">" << endl;
00355 #ifdef DEBUG
00356 cout << "output <constraints> <dualValues>" << endl;
00357 #endif
00358 if(m_OSResult->optimization->solution[i]->constraints->dualValues != NULL){
00359 outStr << "<dualValues numberOfCon=\"" << m_OSResult->optimization->solution[i]->constraints->dualValues->numberOfCon << "\">" << endl;
00360 for(j = 0; j < m_OSResult->optimization->solution[i]->constraints->dualValues->numberOfCon; j++){
00361 if(m_OSResult->optimization->solution[i]->constraints->dualValues->con[j] != NULL){
00362 outStr << "<con";
00363 outStr << " idx=\"";
00364 outStr << j ;
00365 outStr << "\">";
00366 outStr << os_dtoa_format( m_OSResult->optimization->solution[i]->constraints->dualValues->con[j]->value);
00367 outStr << "</con>" << endl;
00368 }
00369 }
00370 outStr << "</dualValues>" << endl;
00371 }
00372 #ifdef DEBUG
00373 cout << "output <constraints> <other>" << endl;
00374 #endif
00375 if(m_OSResult->optimization->solution[i]->constraints->other != NULL){
00376 if(m_OSResult->optimization->solution[i]->constraints->numberOfOtherConstraintResults > 0){
00377 for(int k = 0; k < m_OSResult->optimization->solution[i]->constraints->numberOfOtherConstraintResults; k++){
00378 outStr << "<other" ;
00379 outStr << " name=\"";\
00380 outStr << m_OSResult->optimization->solution[i]->constraints->other[k]->name;
00381 outStr << "\"" ;
00382 outStr << " description=\"";
00383 outStr << m_OSResult->optimization->solution[i]->constraints->other[k]->description;
00384 outStr << "\"" ;
00385 outStr << ">" << endl;
00386 if(m_OSResult->optimization->solution[i]->constraints->other[k]->con.size() > 0){
00387 for(j = 0; j < m_OSResult->optimization->solution[i]->constraints->other[k]->numberOfCon; j++){
00388 if(m_OSResult->optimization->solution[i]->constraints->other[k]->con.size() > 0){
00389 outStr << "<con";
00390 outStr << " idx=\"";
00391 outStr << j ;
00392 outStr << "\">";
00393 outStr << m_OSResult->optimization->solution[i]->constraints->other[k]->con[j]->value;
00394 outStr << "</con>" << endl;
00395 }
00396 }
00397 }
00398 outStr << "</other>" << endl;
00399 }
00400 }
00401 }
00402 outStr << "</constraints>" << endl;
00403 }
00404 outStr << "</solution>" << endl;
00405 }
00406 }
00407 outStr << "</optimization>" << endl;
00408 }
00409 #ifdef DEBUG
00410 cout << "done" << endl;
00411 #endif
00412 outStr << "</osrl>" << endl ;
00413 return outStr.str();
00414 }
00415
00416