OSrLWriter.cpp
Go to the documentation of this file.
1 
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 
37 using std::cout;
38 using std::endl;
39 using 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 
61 std::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=\"";
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)
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 << "\" ";
155  outStr << "description=\"" << m_OSResult->job->timingInformation->time[i]->description << "\" ";
156  outStr << ">" << endl;
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
168  outStr << "<optimization " ;
169  outStr << "numberOfSolutions=\"";
171  outStr << "\"";
172  outStr << " numberOfVariables=\"";
174  outStr << "\"";
175  outStr << " numberOfConstraints=\"";
177  outStr << "\"";
178  outStr << " 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=\"";
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=\"";
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 ";
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 << "\">";
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){
237  cout << "<other" ;
238  cout << " numberOfVar=\"";
240  cout << "\"" ;
241  cout << " name=\"";
243  cout << "\"" ;
244  cout << " value=\"";
246  cout << "\"" ;
247  cout << " description=\"";
249  cout << "\"" ;
250  cout << ">" << endl;
251 
252  outStr << "<other" ;
253  outStr << " 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  }
263  {
264  outStr << " value=\"";
266  outStr << "\"" ;
267  }
269  {
270  outStr << " 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 ";
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 << "\">";
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){
324  outStr << "<other" ;
325  outStr << " name=\"";\
327  outStr << "\"" ;
328  outStr << " 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 ";
353  outStr << "numberOfOtherConstraintResults=\"" << m_OSResult->optimization->solution[i]->constraints->numberOfOtherConstraintResults << "\"";
354  outStr << ">" << endl;
355 #ifdef DEBUG
356  cout << "output <constraints> <dualValues>" << endl;
357 #endif
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 << "\">";
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){
378  outStr << "<other" ;
379  outStr << " name=\"";\
381  outStr << "\"" ;
382  outStr << " 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 << "\">";
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 
OptimizationSolutionStatus * status
status is a pointer to an OptimizationSolutionStatus object associated with this optimization solutio...
Definition: OSResult.h:2283
std::string description
Further description on the timer used.
Definition: OSResult.h:563
OtherConstraintResult ** other
a pointer to an array of other pointer objects for constraint functions
Definition: OSResult.h:1879
int numberOfVar
the number of variable values that are in the solution
Definition: OSResult.h:907
std::string value
value is a value associated with the constraint indexed by idx, for example value might be the value ...
Definition: OSResult.h:1724
int numberOfOtherObjectiveResults
the number of types of objective function results other than the basic objective function values ...
Definition: OSResult.h:1544
TimingInformation * timingInformation
a pointer to the TimingInformation class
Definition: OSResult.h:679
std::string value
this element allows a specific value associated with this particular type of result ...
Definition: OSResult.h:1144
OSrLWriter()
Default constructor.
Definition: OSrLWriter.cpp:34
std::string description
a brief description of the type of result
Definition: OSResult.h:1469
ObjValue ** obj
obj is a pointer to an array of ObjValue objects that give an index and objective function value for ...
Definition: OSResult.h:1344
DualVarValue ** con
con is a vector of DualVarValue objects that give an index and dual variable value for each constrain...
Definition: OSResult.h:1666
DualVariableValues * dualValues
a pointer to an array of DualVariableValues objects
Definition: OSResult.h:1871
std::string message
a message associated with this solution
Definition: OSResult.h:2286
JobResult * job
job holds the fourth child of the OSResult specified by the OSrL Schema.
Definition: OSResult.h:2576
The Result Class.
Definition: OSResult.h:2548
std::string description
a brief description of the type of result
Definition: OSResult.h:1793
GeneralResult * general
general holds the first child of the OSResult specified by the OSrL Schema.
Definition: OSResult.h:2561
ServiceResult * service
service holds the third child of the OSResult specified by the OSrL Schema.
Definition: OSResult.h:2571
double value
the number of units
Definition: OSGeneral.h:932
OptimizationResult * optimization
optimization holds the fifth child of the OSResult specified by the OSrL Schema.
Definition: OSResult.h:2581
SystemResult * system
system holds the second child of the OSResult specified by the OSrL Schema.
Definition: OSResult.h:2566
std::string value
value is a value associated with an objective function indexed by idx
Definition: OSResult.h:1400
std::string description
a brief description of the type of result
Definition: OSResult.h:1150
ObjectiveSolution * objectives
objectives holds the solution information for the objectives
Definition: OSResult.h:2300
std::string writeOSrL(OSResult *theosresult)
create an osrl string from an OSResult object
Definition: OSrLWriter.cpp:45
static char * j
Definition: OSdtoa.cpp:3622
int numberOfVar
the number of variables which have values for this particular type of result
Definition: OSResult.h:1131
OtherConResult ** con
Definition: OSResult.h:1805
std::string message
any general message associated with the optimization
Definition: OSResult.h:276
OtherVarResult ** var
Definition: OSResult.h:1162
int numberOfCon
record the number of constraints for which values are given
Definition: OSResult.h:1660
VarValue ** var
a vector of VarValue objects, there will be one for each variable in the solution ...
Definition: OSResult.h:912
VariableSolution * variables
variables holds the solution information for the variables
Definition: OSResult.h:2291
#define OS_SCHEMA_VERSION
Definition: OSParameters.h:83
int numberOfSolutions
numberOfSolutions is the number of objective functions reported.
Definition: OSResult.h:2480
std::string name
the name of the result the user is defining
Definition: OSResult.h:1139
std::string name
the name of the result the user is defining
Definition: OSResult.h:1458
int numberOfTimes
The number of elements in the time array.
Definition: OSResult.h:612
VariableValues * values
a pointer to a VariableValues object
Definition: OSResult.h:1227
GeneralStatus * generalStatus
a pointer to the GeneralStatus class
Definition: OSResult.h:272
void fint fint * k
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
int numberOfCon
the number of constraints which have values for this particular type of result
Definition: OSResult.h:1774
TimeMeasurement ** time
An array of time measurements.
Definition: OSResult.h:618
std::string type
the type of solution status
Definition: OSResult.h:800
int targetObjectiveIdx
the index of the objective function for which we are reporting solution information ...
Definition: OSResult.h:2270
std::string type
the type of status
Definition: OSResult.h:114
OptimizationSolution ** solution
solution is an array of pointers to OptimizationSolution objects
Definition: OSResult.h:2500
ConstraintSolution * constraints
constraints holds the solution information for the constraints
Definition: OSResult.h:2295
ObjectiveValues * values
a pointer to an array of ObjectiveValues objects
Definition: OSResult.h:1547
std::string instanceName
the name of the instance that was solved
Definition: OSResult.h:290
std::string serviceName
the serviceName is the name of the solver service that did the optimization
Definition: OSResult.h:286
int numberOfConstraints
numberOfConstrants is the number of constraint functions reported in the solution.
Definition: OSResult.h:2495
std::string description
a description of the solution status type
Definition: OSResult.h:803
std::string category
The category of time (total/input/preprocessing/optimization/postprocessing/output/other) ...
Definition: OSResult.h:558
double value
Definition: OSResult.h:860
OtherVariableResult ** other
a pointer to an array of other pointer objects for variables
Definition: OSResult.h:1238
int numberOfObj
record the number of objective rows for which values are given
Definition: OSResult.h:1338
std::string serviceURI
the serviceURI is the URI of the solver service that did the optimization
Definition: OSResult.h:281
std::string os_dtoa_format(double x)
Definition: OSMathUtil.cpp:154
std::string type
The type of timer used (cpuTime/elapsedTime/other)
Definition: OSResult.h:553
OtherObjResult ** obj
Definition: OSResult.h:1481
OtherObjectiveResult ** other
a pointer to an array of other pointer objects for objective functions
Definition: OSResult.h:1555
int numberOfVariables
numberOfVariables is the number of variables reported in the solution.
Definition: OSResult.h:2485
int numberOfOtherConstraintResults
the number of types of constraint function results other than the basic constraint function values ...
Definition: OSResult.h:1868
int numberOfOtherVariableResults
the number of types of variable results other than the value of the variable
Definition: OSResult.h:1224
double value
the value of the objective indexed by idx
Definition: OSResult.h:1292
~OSrLWriter()
Class destructor.
Definition: OSrLWriter.cpp:40
int numberOfObj
the number of objectives which have values for this particular type of result
Definition: OSResult.h:1450
std::string jobID
the jobID is the ID associated with the solution of this instance
Definition: OSResult.h:295
std::string value
value holds a general value associated with a variable, for example, rather than the value of a varia...
Definition: OSResult.h:1081
double value
value of dual variable on the constraint indexed by idx
Definition: OSResult.h:1611
std::string unit
the unit in which time is measured
Definition: OSGeneral.h:929
int numberOfObjectives
numberOfObjectives is the number of objective functions reported in the solution. ...
Definition: OSResult.h:2490
std::string description
the description of the status
Definition: OSResult.h:117
std::string name
the name of the result the user is defining
Definition: OSResult.h:1782