My Project
OSrLWriter.cpp
Go to the documentation of this file.
1
16
17
18#define DEBUG
19
20
21
22
23#include "OSrLWriter.h"
24#include "OSResult.h"
25
26#include "OSDataStructures.h"
27#include "OSParameters.h"
28#include "OSCommonUtil.h"
29#include "OSMathUtil.h"
30
31
32
33
34#include <sstream>
35#include <iostream>
36
37using std::cout;
38using std::endl;
39using std::ostringstream;
40
42}
43
45}
46
47
48/*char* OSrLWriter::writeOSrLWrap( OSResult *theosresult){
49 std::string sTmp = writeOSrL( theosresult);
50 char *ch;
51 ch = new char[sTmp.size() + 1];
52 strcpy(ch, sTmp.c_str());
53 return ch;
54}
55*/
56
57
58
59
60
61std::string OSrLWriter::writeOSrL( OSResult *theosresult){
62 m_OSResult = theosresult;
63 std::ostringstream outStr;
64 #ifdef WIN_
65 const char dirsep='\\';
66 #else
67 const char dirsep='/';
68 #endif
69 // Set directory containing stylesheet files.
70 std::string xsltDir;
71 xsltDir = dirsep == '/' ? "../stylesheets/" : "..\\stylesheets\\";
72 // always go with '/' -- it is a hypertext reference
73 xsltDir = "../stylesheets/";
74 int i, j;
75#ifdef DEBUG
76 cout << "in OSrLWriter" << endl;
77#endif
78 if(m_OSResult == NULL) return outStr.str();
79 outStr << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" ;
80 outStr << "<?xml-stylesheet type=\"text/xsl\" href=\"";
81 outStr << xsltDir;
82 outStr << "OSrL.xslt\"?>";
83 outStr << endl;
84 outStr << "<osrl xmlns=\"os.optimizationservices.org\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ";
85 outStr << "xsi:schemaLocation=\"os.optimizationservices.org http://www.optimizationservices.org/schemas/";
86 outStr << OS_SCHEMA_VERSION;
87 outStr << "/OSrL.xsd\" >" ;
88 outStr << endl;
89#ifdef DEBUG
90 cout << "output <general>" << endl;
91#endif
92 if(m_OSResult->general != NULL){
93 outStr << "<general>" << endl;
94 if(m_OSResult->general->generalStatus != NULL){
95 outStr << "<generalStatus " ;
96 if(m_OSResult->general->generalStatus->type.length() > 0){
97 outStr << "type=\"";
98 outStr << m_OSResult->general->generalStatus->type ;
99 outStr << "\"";
100 }
101 if(m_OSResult->general->generalStatus->description.length() > 0){
102 outStr << "type=\"";
103 outStr << m_OSResult->general->generalStatus->description ;
104 outStr << "\"";
105 }
106 outStr << "/>" << endl;
107 }
108
109 if(m_OSResult->general->serviceURI.length() > 0){
110 outStr << "<serviceURI>" + m_OSResult->general->serviceURI + "</serviceURI>" << endl;
111 }
112
113 if(m_OSResult->general->serviceName.length() > 0){
114 outStr << "<serviceName>" + m_OSResult->general->serviceName + "</serviceName>" << endl;
115 }
116 if(m_OSResult->general->instanceName.length() > 0){
117 outStr << "<instanceName>" + m_OSResult->general->instanceName + "</instanceName>" << endl;
118 }
119 if(m_OSResult->general->jobID.length() > 0){
120 outStr << "<jobID>" + m_OSResult->general->jobID + "</jobID>" << endl;
121 }
122 if(m_OSResult->general->message.length() > 0){
123 outStr << "<message>" + m_OSResult->general->message + "</message>" << endl;
124 }
125 outStr << "</general>" << endl;
126 }
127#ifdef DEBUG
128 cout << "output <system>" << endl;
129#endif
130 if(m_OSResult->system != NULL){
131 }
132#ifdef DEBUG
133 cout << "output <service>" << endl;
134#endif
135 if(m_OSResult->service != NULL){
136 }
137#ifdef DEBUG
138 cout << "output <job>" << endl;
139#endif
140 if(m_OSResult->job != NULL){
141 outStr << "<job>" << endl;
142 if (m_OSResult->job->timingInformation != NULL)
143 if (m_OSResult->job->timingInformation->numberOfTimes > 0)
144 { outStr << "<timingInformation numberOfTimes=\"";
145 outStr << m_OSResult->job->timingInformation->numberOfTimes << "\">" << endl;
146 for (i=0; i<m_OSResult->job->timingInformation->numberOfTimes; i++)
147 { outStr << "<time ";
148 if (m_OSResult->job->timingInformation->time[i]->type != "")
149 outStr << "type=\"" << m_OSResult->job->timingInformation->time[i]->type << "\" ";
150 if (m_OSResult->job->timingInformation->time[i]->unit != "")
151 outStr << "unit=\"" << m_OSResult->job->timingInformation->time[i]->unit << "\" ";
152 if (m_OSResult->job->timingInformation->time[i]->category != "")
153 outStr << "category=\"" << m_OSResult->job->timingInformation->time[i]->category << "\" ";
154 if (m_OSResult->job->timingInformation->time[i]->description != "")
155 outStr << "description=\"" << m_OSResult->job->timingInformation->time[i]->description << "\" ";
156 outStr << ">" << endl;
157 outStr << os_dtoa_format(m_OSResult->job->timingInformation->time[i]->value);
158 outStr << "</time>" << endl;
159 }
160 outStr << "</timingInformation>" << endl;
161 }
162 outStr << "</job>" << endl;
163 }
164#ifdef DEBUG
165 cout << "output <optimization>" << endl;
166#endif
167 if(m_OSResult->optimization != NULL && m_OSResult->optimization->numberOfSolutions > 0){
168 outStr << "<optimization " ;
169 outStr << "numberOfSolutions=\"";
170 outStr << m_OSResult->optimization->numberOfSolutions ;
171 outStr << "\"";
172 outStr << " numberOfVariables=\"";
173 outStr << m_OSResult->optimization->numberOfVariables ;
174 outStr << "\"";
175 outStr << " numberOfConstraints=\"";
176 outStr << m_OSResult->optimization->numberOfConstraints ;
177 outStr << "\"";
178 outStr << " numberOfObjectives=\"";
179 outStr << m_OSResult->optimization->numberOfObjectives ;
180 outStr << "\"" ;
181 outStr << ">" << endl;
182 // get solution information
183 for(i = 0; i < m_OSResult->optimization->numberOfSolutions; i++){
184 if(m_OSResult->optimization->solution[i] != NULL){
185 outStr << "<solution" ;
186 outStr << " targetObjectiveIdx=\"";
187 outStr << m_OSResult->optimization->solution[i]->targetObjectiveIdx ;
188 outStr << "\"" ;
189 outStr << ">" << endl;
190 if(m_OSResult->optimization->solution[i]->status != NULL){
191 outStr << "<status";
192 if(m_OSResult->optimization->solution[i]->status->type.length() > 0){
193 outStr << " type=\"";
194 outStr << m_OSResult->optimization->solution[i]->status->type;
195 outStr << "\"";
196 }
197 if(m_OSResult->optimization->solution[i]->status->description.length() > 0){
198 outStr << " description=\"";
199 outStr << m_OSResult->optimization->solution[i]->status->description;
200 outStr << "\"" ;
201 }
202 outStr << "/>" << endl;
203 }
204 if(m_OSResult->optimization->solution[i]->message != ""){
205 outStr << "<message>" << endl;
206 outStr << m_OSResult->optimization->solution[i]->message << endl;
207 outStr << "</message>" << endl;
208 }
209 if(m_OSResult->optimization->solution[i]->variables != NULL){
210 outStr << "<variables ";
211 if (m_OSResult->optimization->solution[i]->variables->numberOfOtherVariableResults > 0)
212 outStr << "numberOfOtherVariableResults=\"" << m_OSResult->optimization->solution[i]->variables->numberOfOtherVariableResults << "\"";
213 outStr << ">" << endl;
214 if(m_OSResult->optimization->solution[i]->variables->values != NULL){
215#ifdef DEBUG
216 cout << "output <variables> <values>" << endl;
217#endif
218 outStr << "<values numberOfVar=\"" << m_OSResult->optimization->solution[i]->variables->values->numberOfVar << "\">" << endl;
219 for(j = 0; j < m_OSResult->optimization->solution[i]->variables->values->numberOfVar; j++){
220 if(m_OSResult->optimization->solution[i]->variables->values->var[j] != NULL){
221 outStr << "<var";
222 outStr << " idx=\"";
223 outStr << j ;
224 outStr << "\">";
225 outStr << os_dtoa_format( m_OSResult->optimization->solution[i]->variables->values->var[j]->value );
226 outStr << "</var>" << endl;
227 }
228 }
229 outStr << "</values>" << endl;
230 }
231#ifdef DEBUG
232 cout << "output <variables> <other>" << endl;
233#endif
234 if(m_OSResult->optimization->solution[i]->variables->other != NULL){
235 if(m_OSResult->optimization->solution[i]->variables->numberOfOtherVariableResults > 0){
236 for(int k = 0; k < m_OSResult->optimization->solution[i]->variables->numberOfOtherVariableResults; k++){
237 cout << "<other" ;
238 cout << " numberOfVar=\"";
239 cout << m_OSResult->optimization->solution[i]->variables->other[k]->numberOfVar;
240 cout << "\"" ;
241 cout << " name=\"";
242 cout << m_OSResult->optimization->solution[i]->variables->other[k]->name;
243 cout << "\"" ;
244 cout << " value=\"";
245 cout << m_OSResult->optimization->solution[i]->variables->other[k]->value;
246 cout << "\"" ;
247 cout << " description=\"";
248 cout << m_OSResult->optimization->solution[i]->variables->other[k]->description;
249 cout << "\"" ;
250 cout << ">" << endl;
251
252 outStr << "<other" ;
253 outStr << " numberOfVar=\"";
254 outStr << m_OSResult->optimization->solution[i]->variables->other[k]->numberOfVar;
255 outStr << "\"" ;
256 if (m_OSResult->optimization->solution[i]->variables->other[k]->name != "")
257 {
258 outStr << " name=\"";
259 outStr << m_OSResult->optimization->solution[i]->variables->other[k]->name;
260 outStr << "\"" ;
261 }
262 if (m_OSResult->optimization->solution[i]->variables->other[k]->value != "")
263 {
264 outStr << " value=\"";
265 outStr << m_OSResult->optimization->solution[i]->variables->other[k]->value;
266 outStr << "\"" ;
267 }
268 if (m_OSResult->optimization->solution[i]->variables->other[k]->description != "")
269 {
270 outStr << " description=\"";
271 outStr << m_OSResult->optimization->solution[i]->variables->other[k]->description;
272 outStr << "\"" ;
273 }
274 outStr << ">" << endl;
275 if(m_OSResult->optimization->solution[i]->variables->other[k]->var.size() > 0){
276 for(j = 0; j < m_OSResult->optimization->solution[i]->variables->other[k]->numberOfVar; j++){
277 if(m_OSResult->optimization->solution[i]->variables->other[k]->var.size() > 0){
278 outStr << "<var";
279 outStr << " idx=\"";
280 outStr << j ;
281 outStr << "\">";
282 outStr << m_OSResult->optimization->solution[i]->variables->other[k]->var[j]->value;
283 outStr << "</var>" << endl;
284 }
285 }
286 }
287 outStr << "</other>" << endl;
288 }
289 }
290 } // end of if on other variables
291 outStr << "</variables>" << endl;
292 }
293 //
294 //
295 //
296 if(m_OSResult->optimization->solution[i]->objectives != NULL){
297 outStr << "<objectives ";
298 if (m_OSResult->optimization->solution[i]->objectives->numberOfOtherObjectiveResults > 0)
299 outStr << "numberOfOtherObjectiveResults=\"" << m_OSResult->optimization->solution[i]->objectives->numberOfOtherObjectiveResults << "\"";
300 outStr << ">" << endl;
301#ifdef DEBUG
302 cout << "output <objectives> <values>" << endl;
303#endif
304 if(m_OSResult->optimization->solution[i]->objectives->values != NULL){
305 outStr << "<values numberOfObj=\"" << m_OSResult->optimization->solution[i]->objectives->values->numberOfObj << "\">" << endl;
306 for(j = 0; j < m_OSResult->optimization->solution[i]->objectives->values->numberOfObj; j++){
307 if(m_OSResult->optimization->solution[i]->objectives->values->obj[j] != NULL){
308 outStr << "<obj";
309 outStr << " idx=\"";
310 outStr << -(1 + j) ;
311 outStr << "\">";
312 outStr << os_dtoa_format( m_OSResult->optimization->solution[i]->objectives->values->obj[j]->value);
313 outStr << "</obj>" << endl;
314 }
315 }
316 outStr << "</values>" << endl;
317 }
318#ifdef DEBUG
319 cout << "output <objectives> <other>" << endl;
320#endif
321 if(m_OSResult->optimization->solution[i]->objectives->other != NULL){
322 if(m_OSResult->optimization->solution[i]->objectives->numberOfOtherObjectiveResults > 0){
323 for(int k = 0; k < m_OSResult->optimization->solution[i]->objectives->numberOfOtherObjectiveResults; k++){
324 outStr << "<other" ;
325 outStr << " name=\"";\
326 outStr << m_OSResult->optimization->solution[i]->objectives->other[k]->name;
327 outStr << "\"" ;
328 outStr << " description=\"";
329 outStr << m_OSResult->optimization->solution[i]->objectives->other[k]->description;
330 outStr << "\"" ;
331 outStr << ">" << endl;
332 if(m_OSResult->optimization->solution[i]->objectives->other[k]->obj.size() > 0){
333 for(j = 0; j < m_OSResult->optimization->solution[i]->objectives->other[k]->numberOfObj; j++){
334 if(m_OSResult->optimization->solution[i]->objectives->other[k]->obj.size() > 0){
335 outStr << "<obj";
336 outStr << " idx=\"";
337 outStr << j ;
338 outStr << "\">";
339 outStr << m_OSResult->optimization->solution[i]->objectives->other[k]->obj[j]->value;
340 outStr << "</obj>" << endl;
341 }
342 }
343 }
344 outStr << "</other>" << endl;
345 }
346 }
347 } // end of if on other objectives
348 outStr << "</objectives>" << endl;
349 }
350 if(m_OSResult->optimization->solution[i]->constraints != NULL){
351 outStr << "<constraints ";
352 if (m_OSResult->optimization->solution[i]->constraints->numberOfOtherConstraintResults > 0)
353 outStr << "numberOfOtherConstraintResults=\"" << m_OSResult->optimization->solution[i]->constraints->numberOfOtherConstraintResults << "\"";
354 outStr << ">" << endl;
355#ifdef DEBUG
356 cout << "output <constraints> <dualValues>" << endl;
357#endif
358 if(m_OSResult->optimization->solution[i]->constraints->dualValues != NULL){
359 outStr << "<dualValues numberOfCon=\"" << m_OSResult->optimization->solution[i]->constraints->dualValues->numberOfCon << "\">" << endl;
360 for(j = 0; j < m_OSResult->optimization->solution[i]->constraints->dualValues->numberOfCon; j++){
361 if(m_OSResult->optimization->solution[i]->constraints->dualValues->con[j] != NULL){
362 outStr << "<con";
363 outStr << " idx=\"";
364 outStr << j ;
365 outStr << "\">";
366 outStr << os_dtoa_format( m_OSResult->optimization->solution[i]->constraints->dualValues->con[j]->value);
367 outStr << "</con>" << endl;
368 }
369 }
370 outStr << "</dualValues>" << endl;
371 }
372#ifdef DEBUG
373 cout << "output <constraints> <other>" << endl;
374#endif
375 if(m_OSResult->optimization->solution[i]->constraints->other != NULL){
376 if(m_OSResult->optimization->solution[i]->constraints->numberOfOtherConstraintResults > 0){
377 for(int k = 0; k < m_OSResult->optimization->solution[i]->constraints->numberOfOtherConstraintResults; k++){
378 outStr << "<other" ;
379 outStr << " name=\"";\
380 outStr << m_OSResult->optimization->solution[i]->constraints->other[k]->name;
381 outStr << "\"" ;
382 outStr << " description=\"";
383 outStr << m_OSResult->optimization->solution[i]->constraints->other[k]->description;
384 outStr << "\"" ;
385 outStr << ">" << endl;
386 if(m_OSResult->optimization->solution[i]->constraints->other[k]->con.size() > 0){
387 for(j = 0; j < m_OSResult->optimization->solution[i]->constraints->other[k]->numberOfCon; j++){
388 if(m_OSResult->optimization->solution[i]->constraints->other[k]->con.size() > 0){
389 outStr << "<con";
390 outStr << " idx=\"";
391 outStr << j ;
392 outStr << "\">";
393 outStr << m_OSResult->optimization->solution[i]->constraints->other[k]->con[j]->value;
394 outStr << "</con>" << endl;
395 }
396 }
397 }
398 outStr << "</other>" << endl;
399 }
400 }
401 } // end of if on other constraints
402 outStr << "</constraints>" << endl;
403 }
404 outStr << "</solution>" << endl;
405 }
406 } // end the solution for loop
407 outStr << "</optimization>" << endl;
408 } // end if (optimization != NULL)
409#ifdef DEBUG
410 cout << "done" << endl;
411#endif
412 outStr << "</osrl>" << endl ;
413 return outStr.str();
414}// end writeOSrL
415
416
std::string os_dtoa_format(double x)
The Result Class.
Definition OSResult.h:2549
std::string writeOSrL(OSResult *theosresult)
create an osrl string from an OSResult object
OSResult * m_OSResult
m_OSResult is an object in the class OSResult, the data in m_OSResult are written to a string that va...
Definition OSrLWriter.h:37
~OSrLWriter()
Class destructor.
OSrLWriter()
Default constructor.
#define OS_SCHEMA_VERSION