| 1 |
// (C) Copyright International Business Machines Corporation 2007 |
| 2 |
// |
| 3 |
// All Rights Reserved. |
| 4 |
// This code is published under the Eclipse Public License. |
| 5 |
// |
| 6 |
// Authors : |
| 7 |
// Pierre Bonami, International Business Machines, |
| 8 |
// |
| 9 |
// Date : 27/08/2007 |
| 10 |
|
| 11 |
#include "BonRegisteredOptions.hpp" |
| 12 |
#include <IpSmartPtr.hpp> |
| 13 |
#include <sstream> |
| 14 |
#include <climits> |
| 15 |
#include <cfloat> |
| 16 |
|
| 17 |
namespace Bonmin{ |
| 18 |
struct optionsCmp{ |
| 19 |
bool operator()( Ipopt::RegisteredOption * a, |
| 20 |
Ipopt::RegisteredOption * b){ |
| 21 |
if(a->RegisteringCategory() == b->RegisteringCategory()){ |
| 22 |
return a->Name() < b->Name(); |
| 23 |
} |
| 24 |
return a->RegisteringCategory() < b->RegisteringCategory(); |
| 25 |
} |
| 26 |
}; |
| 27 |
|
| 28 |
|
| 29 |
static std::string makeLatex(const std::string &s){ |
| 30 |
std::string ret_val; |
| 31 |
std::string::const_iterator i = s.begin(); |
| 32 |
for(; i != s.end() ; i++){ |
| 33 |
switch (*i) { |
| 34 |
case '_': |
| 35 |
case '-': |
| 36 |
ret_val +='\\'; |
| 37 |
default: |
| 38 |
ret_val += *i; |
| 39 |
} |
| 40 |
} |
| 41 |
return ret_val; |
| 42 |
} |
| 43 |
|
| 44 |
static std::string makeSpaceLess(const std::string &s){ |
| 45 |
std::string ret_val; |
| 46 |
std::string::const_iterator i = s.begin(); |
| 47 |
for(; i != s.end() ; i++){ |
| 48 |
switch (*i) { |
| 49 |
case ' ': |
| 50 |
case '\t': |
| 51 |
case '_': |
| 52 |
//ret_val +='_'; |
| 53 |
break; |
| 54 |
default: |
| 55 |
ret_val += *i; |
| 56 |
} |
| 57 |
} |
| 58 |
return ret_val; |
| 59 |
} |
| 60 |
|
| 61 |
#if 0 |
| 62 |
static std::string makeLatex(double value){ |
| 63 |
std::string ret_val = "$"; |
| 64 |
std::stringstream s_val; |
| 65 |
s_val<<value; |
| 66 |
|
| 67 |
unsigned int i = s_val.str().find_first_of('e'); |
| 68 |
if(i != s_val.str().size()){ |
| 69 |
ret_val += s_val.str().substr(0,i-1); |
| 70 |
ret_val += " \\cdot 10^{"; |
| 71 |
ret_val += s_val.str().substr(i+1); |
| 72 |
ret_val += '}'; |
| 73 |
} |
| 74 |
else ret_val += s_val.str(); |
| 75 |
ret_val += '$'; |
| 76 |
return ret_val; |
| 77 |
} |
| 78 |
#endif |
| 79 |
|
| 80 |
static std::string makeString(int value){ |
| 81 |
std::string ret_val; |
| 82 |
if(value >= INT_MAX){ |
| 83 |
ret_val="INT_MAX";} |
| 84 |
else if(value <= - INT_MAX){ |
| 85 |
ret_val="-INT_MAX";} |
| 86 |
else{ |
| 87 |
std::stringstream s_val; |
| 88 |
s_val<<value; |
| 89 |
ret_val = s_val.str(); |
| 90 |
} |
| 91 |
return ret_val; |
| 92 |
} |
| 93 |
|
| 94 |
static std::string makeString(double value){ |
| 95 |
std::string ret_val; |
| 96 |
if(value >= DBL_MAX){ |
| 97 |
ret_val="DBL_MAX";} |
| 98 |
else if(value <= - DBL_MAX){ |
| 99 |
ret_val="-DBL_MAX";} |
| 100 |
else{ |
| 101 |
std::stringstream s_val; |
| 102 |
s_val<<value; |
| 103 |
ret_val = s_val.str(); |
| 104 |
} |
| 105 |
return ret_val; |
| 106 |
} |
| 107 |
|
| 108 |
static std::string makeNumber(std::string value){ |
| 109 |
if(value == "DBL_MAX") { |
| 110 |
std::stringstream s_val; |
| 111 |
s_val<<DBL_MAX; |
| 112 |
return s_val.str(); |
| 113 |
} |
| 114 |
if(value == "-DBL_MAX") { |
| 115 |
std::stringstream s_val; |
| 116 |
s_val<<-DBL_MAX; |
| 117 |
return s_val.str(); |
| 118 |
} |
| 119 |
if(value == "INT_MAX") { |
| 120 |
std::stringstream s_val; |
| 121 |
s_val<<INT_MAX; |
| 122 |
return s_val.str(); |
| 123 |
} |
| 124 |
if(value == "-INT_MAX") { |
| 125 |
std::stringstream s_val; |
| 126 |
s_val<<-INT_MAX; |
| 127 |
return s_val.str(); |
| 128 |
} |
| 129 |
return value; |
| 130 |
} |
| 131 |
#if 0 |
| 132 |
static std::string makeLatex(int value){ |
| 133 |
std::string ret_val = "$"; |
| 134 |
std::stringstream s_val; |
| 135 |
s_val<<value; |
| 136 |
ret_val += s_val.str(); |
| 137 |
ret_val += "$"; |
| 138 |
return ret_val; |
| 139 |
} |
| 140 |
#endif |
| 141 |
|
| 142 |
static char OptionType2Char(const Ipopt::RegisteredOptionType &T){ |
| 143 |
switch(T){ |
| 144 |
case Ipopt::OT_Number: return 'F'; |
| 145 |
case Ipopt::OT_Integer: return 'I'; |
| 146 |
case Ipopt::OT_String: return 'S'; |
| 147 |
case Ipopt::OT_Unknown: |
| 148 |
default: return 'U'; |
| 149 |
} |
| 150 |
} |
| 151 |
|
| 152 |
static std::string defaultAsString(Ipopt::SmartPtr< Ipopt::RegisteredOption > opt){ |
| 153 |
Ipopt::RegisteredOptionType T = opt->Type(); |
| 154 |
switch(T){ |
| 155 |
case Ipopt::OT_Number: return makeString(opt->DefaultNumber()); |
| 156 |
case Ipopt::OT_Integer: return makeString(opt->DefaultInteger()); |
| 157 |
case Ipopt::OT_String: return (opt->DefaultString()); |
| 158 |
case Ipopt::OT_Unknown: |
| 159 |
default: |
| 160 |
return "Unknown type of option"; |
| 161 |
} |
| 162 |
} |
| 163 |
/** Output Latex table of options.*/ |
| 164 |
void |
| 165 |
RegisteredOptions::writeLatexOptionsTable(std::ostream &of, ExtraCategoriesInfo which){ |
| 166 |
std::map<std::string, Ipopt::SmartPtr<Ipopt::RegisteredOption> > |
| 167 |
registered_options = RegisteredOptionsList(); |
| 168 |
|
| 169 |
//Print table header |
| 170 |
//of<<"\\begin{threeparttable}"<<std::endl |
| 171 |
of<<"\\topcaption{\\label{tab:options} "<<std::endl |
| 172 |
<<"List of options and compatibility with the different algorithms."<<std::endl |
| 173 |
<<"}"<<std::endl; |
| 174 |
of<<"\\tablehead{\\hline "<<std::endl |
| 175 |
<<"Option & type & "; |
| 176 |
//of<<" default & "; |
| 177 |
of<<"{\\tt B-BB} & {\\tt B-OA} & {\\tt B-QG} & {\\tt B-Hyb} & {\\tt B-Ecp} & {\\tt B-iFP} & {\\tt Cbc\\_Par} \\\\"<<std::endl |
| 178 |
<<"\\hline"<<std::endl |
| 179 |
<<"\\hline}"<<std::endl; |
| 180 |
of<<"\\tabletail{\\hline \\multicolumn{9}{|c|}{continued on next page}\\\\" |
| 181 |
<<"\\hline}"<<std::endl; |
| 182 |
of<<"\\tablelasttail{\\hline}"<<std::endl; |
| 183 |
of<<"{\\footnotesize"<<std::endl; |
| 184 |
of<<"\\begin{xtabular}{@{}|@{\\;}l@{\\;}|@{\\;}r@{\\;}|@{\\;}c@{\\;}|@{\\;}c@{\\;}|@{\\;}c@{\\;}|@{\\;}c@{\\;}|@{\\;}c@{\\;}|@{\\;}c@{\\;}|@{\\;}c@{\\;}|@{}}"<<std::endl; |
| 185 |
|
| 186 |
//sort options by categories and alphabetical order |
| 187 |
std::list< Ipopt::RegisteredOption * > sortedOptions; |
| 188 |
|
| 189 |
for(std::map<std::string, Ipopt::SmartPtr<Ipopt::RegisteredOption > >::iterator i = |
| 190 |
registered_options.begin(); i != registered_options.end() ; i++){ |
| 191 |
if(categoriesInfo(i->second->RegisteringCategory()) == which) |
| 192 |
sortedOptions.push_back(GetRawPtr(i->second)); |
| 193 |
} |
| 194 |
|
| 195 |
sortedOptions.sort(optionsCmp()); |
| 196 |
std::string registeringCategory = ""; |
| 197 |
for(std::list< Ipopt::RegisteredOption * >::iterator i = sortedOptions.begin(); |
| 198 |
i != sortedOptions.end() ; i++) |
| 199 |
{ |
| 200 |
if((*i)->RegisteringCategory() != registeringCategory){ |
| 201 |
registeringCategory = (*i)->RegisteringCategory(); |
| 202 |
of<<"\\hline"<<std::endl |
| 203 |
<<"\\multicolumn{1}{|c}{} & \\multicolumn{8}{l|}{" |
| 204 |
<<registeringCategory<<"}\\\\"<<std::endl |
| 205 |
<<"\\hline"<<std::endl; |
| 206 |
} |
| 207 |
|
| 208 |
of<<makeLatex((*i)->Name())<<"& "<<OptionType2Char((*i)->Type())//<<"& " |
| 209 |
//<<makeLatex(defaultAsString(*i)) |
| 210 |
<<"& "<<( (isValidForBBB((*i)->Name()))? "$\\surd$" : "-" ) |
| 211 |
<<"& "<<( (isValidForBOA((*i)->Name()))? "$\\surd$" : "-" ) |
| 212 |
<<"& "<<( (isValidForBQG((*i)->Name()))? "$\\surd$" : "-" ) |
| 213 |
<<"& "<<( (isValidForHybrid((*i)->Name()))? "$\\surd$" : "-" ) |
| 214 |
<<"& "<<( (isValidForBEcp((*i)->Name()))? "$\\surd$" : "-" ) |
| 215 |
<<"& "<<( (isValidForBiFP((*i)->Name()))? "$\\surd$" : "-" ) |
| 216 |
<<"& "<<( (isValidForCbc((*i)->Name()))? "$\\surd$" : "-" ) |
| 217 |
<<"\\\\"<<std::endl; |
| 218 |
} |
| 219 |
//Print table end |
| 220 |
of<<"\\hline"<<std::endl |
| 221 |
<<"\\end{xtabular}"<<std::endl; |
| 222 |
of<<"}"<<std::endl; |
| 223 |
#if 0 |
| 224 |
of<<"\\begin{tablenotes}"<<std::endl |
| 225 |
<<"\\item $\\strut^*$ option is available"<<std::endl |
| 226 |
<<" for MILP subsolver (it is only passed if the {\\tt milp\\_subsolver} optio"<<std::endl |
| 227 |
<<" see Subsection \\ref{sec:milp_opt})."<<std::endl |
| 228 |
<<" \\item $\\strut^1$ disabled for stability reasons."<<std::endl |
| 229 |
<<"\\end{tablenotes}"<<std::endl |
| 230 |
<<"\\end{threeparttable} "<<std::endl; |
| 231 |
#endif |
| 232 |
} |
| 233 |
|
| 234 |
/** choose options.*/ |
| 235 |
void |
| 236 |
RegisteredOptions::chooseOptions(ExtraCategoriesInfo which, |
| 237 |
std::list< Ipopt::RegisteredOption * >& sortedOptions) |
| 238 |
{ |
| 239 |
std::map<std::string, Ipopt::SmartPtr<Ipopt::RegisteredOption> > |
| 240 |
registered_options = RegisteredOptionsList(); |
| 241 |
|
| 242 |
for(std::map<std::string, Ipopt::SmartPtr<Ipopt::RegisteredOption > >::iterator i = |
| 243 |
registered_options.begin(); i != registered_options.end() ; i++){ |
| 244 |
if(categoriesInfo(i->second->RegisteringCategory()) == which) |
| 245 |
sortedOptions.push_back(GetRawPtr(i->second)); |
| 246 |
} |
| 247 |
sortedOptions.sort(optionsCmp()); |
| 248 |
} |
| 249 |
/** Output html table of options.*/ |
| 250 |
void |
| 251 |
RegisteredOptions::writeHtmlOptionsTable(std::ostream &of, ExtraCategoriesInfo which){ |
| 252 |
|
| 253 |
//Print table header |
| 254 |
of<<"<table border=\"1\">"<<std::endl; |
| 255 |
//sort options by categories and alphabetical order |
| 256 |
std::list< Ipopt::RegisteredOption * > sortedOptions; |
| 257 |
chooseOptions(which, sortedOptions); |
| 258 |
writeHtmlOptionsTable(of, sortedOptions); |
| 259 |
} |
| 260 |
|
| 261 |
|
| 262 |
/** Output html table of options.*/ |
| 263 |
void |
| 264 |
RegisteredOptions::writeHtmlOptionsTable(std::ostream &os, std::list<Ipopt::RegisteredOption *> &options) |
| 265 |
{ |
| 266 |
os<<"<table border=\"1\">"<<std::endl; |
| 267 |
os<<"<tr>"<<std::endl; |
| 268 |
os<<"<td>Option </td>"<<std::endl; |
| 269 |
os<<"<td> type </td>"<<std::endl; |
| 270 |
//os<<"<td> default </td>"<<std::endl; |
| 271 |
os<<"<td> B-BB</td>"<<std::endl; |
| 272 |
os<<"<td> B-OA</td>"<<std::endl; |
| 273 |
os<<"<td> B-QG</td>"<<std::endl; |
| 274 |
os<<"<td> B-Hyb</td>"<<std::endl; |
| 275 |
os<<"</tr>"<<std::endl; |
| 276 |
std::string registeringCategory = ""; |
| 277 |
for(std::list< Ipopt::RegisteredOption * >::iterator i = options.begin(); |
| 278 |
i != options.end() ; i++) |
| 279 |
{ |
| 280 |
if((*i)->RegisteringCategory() != registeringCategory){ |
| 281 |
registeringCategory = (*i)->RegisteringCategory(); |
| 282 |
os<<"<tr>" |
| 283 |
<<" <th colspan=9>" |
| 284 |
<<" <a href=\"#sec:"<<makeSpaceLess(registeringCategory)<<"\">" |
| 285 |
<<registeringCategory<<"</a> </th>"<<std::endl |
| 286 |
<<"</tr>"<<std::endl; |
| 287 |
} |
| 288 |
|
| 289 |
os<<"<tr>"<<std::endl |
| 290 |
<<"<td>"<<((*i)->Name())<<"</td>"<<std::endl |
| 291 |
<<"<td>"<<OptionType2Char((*i)->Type())<<"</td>"<<std::endl |
| 292 |
//<<"<td>"<<defaultAsString(*i)<<"</td>"<<std::endl |
| 293 |
<<"<td> "<<( (isValidForBBB((*i)->Name()))? '+' : '-' )<<"</td>"<<std::endl |
| 294 |
<<"<td>"<<( (isValidForBOA((*i)->Name()))? '+' : '-' )<<"</td>"<<std::endl |
| 295 |
<<"<td>"<<( (isValidForBQG((*i)->Name()))? '+' : '-' )<<"</td>"<<std::endl |
| 296 |
<<"<td>"<<( (isValidForHybrid((*i)->Name()))? '+' : '-' )<<"</td>"<<std::endl |
| 297 |
<<"</tr>"<<std::endl; |
| 298 |
} |
| 299 |
//Print table end |
| 300 |
os<<"</tr>"<<std::endl |
| 301 |
<<"</table>"<<std::endl; |
| 302 |
} |
| 303 |
|
| 304 |
/** Output Latex/Html options documentation.*/ |
| 305 |
void |
| 306 |
RegisteredOptions::writeLatexHtmlDoc(std::ostream &os, ExtraCategoriesInfo which){ |
| 307 |
std::list< Ipopt::RegisteredOption * > options; |
| 308 |
chooseOptions(which, options); |
| 309 |
os<<"\\latexhtml{}{"<<std::endl; |
| 310 |
os<<"\\HCode{"<<std::endl; |
| 311 |
writeHtmlOptionsTable(os, options); |
| 312 |
os<<"}\n}"<<std::endl; |
| 313 |
|
| 314 |
//Create journalist to write to os |
| 315 |
Ipopt::Journalist jnlst; |
| 316 |
Ipopt::SmartPtr<Ipopt::StreamJournal> J = new Ipopt::StreamJournal("options_journal", Ipopt::J_ALL); |
| 317 |
J->SetOutputStream(&os); |
| 318 |
J->SetPrintLevel(Ipopt::J_DOCUMENTATION, Ipopt::J_SUMMARY); |
| 319 |
jnlst.AddJournal(GetRawPtr(J)); |
| 320 |
|
| 321 |
std::string registeringCategory = ""; |
| 322 |
for(std::list< Ipopt::RegisteredOption * >::iterator i = options.begin(); |
| 323 |
i != options.end() ; i++) |
| 324 |
{ |
| 325 |
if((*i)->RegisteringCategory() != registeringCategory){ |
| 326 |
registeringCategory = (*i)->RegisteringCategory(); |
| 327 |
os<<"\\subsection{"<<registeringCategory<<"}"<<std::endl; |
| 328 |
os<<"\\label{sec:"<<makeSpaceLess(registeringCategory)<<"}"<<std::endl; |
| 329 |
os<<"\\htmlanchor{sec:"<<makeSpaceLess(registeringCategory)<<"}"<<std::endl; |
| 330 |
} |
| 331 |
|
| 332 |
(*i)->OutputLatexDescription(jnlst); |
| 333 |
} |
| 334 |
} |
| 335 |
|
| 336 |
/** Ouptut a bonmin.opt file with options default values and short descritpions.*/ |
| 337 |
void |
| 338 |
RegisteredOptions::writeBonminOpt(std::ostream &os, ExtraCategoriesInfo which){ |
| 339 |
std::list< Ipopt::RegisteredOption * > options; |
| 340 |
chooseOptions(which, options); |
| 341 |
|
| 342 |
//Create journalist to write to os |
| 343 |
Ipopt::Journalist jnlst; |
| 344 |
Ipopt::SmartPtr<Ipopt::StreamJournal> J = new Ipopt::StreamJournal("options_journal", Ipopt::J_ALL); |
| 345 |
J->SetOutputStream(&os); |
| 346 |
J->SetPrintLevel(Ipopt::J_DOCUMENTATION, Ipopt::J_SUMMARY); |
| 347 |
jnlst.AddJournal(GetRawPtr(J)); |
| 348 |
|
| 349 |
std::string registeringCategory = ""; |
| 350 |
for(std::list< Ipopt::RegisteredOption * >::iterator i = options.begin(); |
| 351 |
i != options.end() ; i++) |
| 352 |
{ |
| 353 |
if((*i)->RegisteringCategory() != registeringCategory){ |
| 354 |
registeringCategory = (*i)->RegisteringCategory(); |
| 355 |
os<<std::endl<<"# registering category: "<<registeringCategory<<std::endl<<std::endl; |
| 356 |
} |
| 357 |
os<<"bonmin."; |
| 358 |
os.setf(std::ios::left); |
| 359 |
os.width(37); |
| 360 |
os<<(*i)->Name()<<" "; |
| 361 |
os.width(10); |
| 362 |
os<<makeNumber(defaultAsString(*i))<<"\t#"; |
| 363 |
os<<(*i)->ShortDescription(); |
| 364 |
os<<std::endl; |
| 365 |
} |
| 366 |
} |
| 367 |
|
| 368 |
}/*Ends bonmin namespace.*/ |