00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "BonRegisteredOptions.hpp"
00012 #include <IpSmartPtr.hpp>
00013 #include <sstream>
00014 #include <climits>
00015 #include <cfloat>
00016
00017 namespace Bonmin{
00018 struct optionsCmp{
00019 bool operator()( Ipopt::RegisteredOption * a,
00020 Ipopt::RegisteredOption * b){
00021 if(a->RegisteringCategory() == b->RegisteringCategory()){
00022 return a->Name() < b->Name();
00023 }
00024 return a->RegisteringCategory() < b->RegisteringCategory();
00025 }
00026 };
00027
00028
00029 static std::string makeLatex(const std::string &s){
00030 std::string ret_val;
00031 std::string::const_iterator i = s.begin();
00032 for(; i != s.end() ; i++){
00033 switch (*i) {
00034 case '_':
00035 case '-':
00036 ret_val +='\\';
00037 default:
00038 ret_val += *i;
00039 }
00040 }
00041 return ret_val;
00042 }
00043
00044 static std::string makeSpaceLess(const std::string &s){
00045 std::string ret_val;
00046 std::string::const_iterator i = s.begin();
00047 for(; i != s.end() ; i++){
00048 switch (*i) {
00049 case ' ':
00050 case '\t':
00051 ret_val +='_';
00052 break;
00053 default:
00054 ret_val += *i;
00055 }
00056 }
00057 return ret_val;
00058 }
00059
00060 #if 0
00061 static std::string makeLatex(double value){
00062 std::string ret_val = "$";
00063 std::stringstream s_val;
00064 s_val<<value;
00065
00066 unsigned int i = s_val.str().find_first_of('e');
00067 if(i != s_val.str().size()){
00068 ret_val += s_val.str().substr(0,i-1);
00069 ret_val += " \\cdot 10^{";
00070 ret_val += s_val.str().substr(i+1);
00071 ret_val += '}';
00072 }
00073 else ret_val += s_val.str();
00074 ret_val += '$';
00075 return ret_val;
00076 }
00077 #endif
00078
00079 static std::string makeString(int value){
00080 std::string ret_val;
00081 if(value >= INT_MAX){
00082 ret_val="INT_MAX";}
00083 else if(value <= - INT_MAX){
00084 ret_val="-INT_MAX";}
00085 else{
00086 std::stringstream s_val;
00087 s_val<<value;
00088 ret_val = s_val.str();
00089 }
00090 return ret_val;
00091 }
00092
00093 static std::string makeString(double value){
00094 std::string ret_val;
00095 if(value >= DBL_MAX){
00096 ret_val="DBL_MAX";}
00097 else if(value <= - DBL_MAX){
00098 ret_val="-DBL_MAX";}
00099 else{
00100 std::stringstream s_val;
00101 s_val<<value;
00102 ret_val = s_val.str();
00103 }
00104 return ret_val;
00105 }
00106
00107 static std::string makeNumber(std::string value){
00108 if(value == "DBL_MAX") {
00109 std::stringstream s_val;
00110 s_val<<DBL_MAX;
00111 return s_val.str();
00112 }
00113 if(value == "-DBL_MAX") {
00114 std::stringstream s_val;
00115 s_val<<-DBL_MAX;
00116 return s_val.str();
00117 }
00118 if(value == "INT_MAX") {
00119 std::stringstream s_val;
00120 s_val<<INT_MAX;
00121 return s_val.str();
00122 }
00123 if(value == "-INT_MAX") {
00124 std::stringstream s_val;
00125 s_val<<-INT_MAX;
00126 return s_val.str();
00127 }
00128 return value;
00129 }
00130 #if 0
00131 static std::string makeLatex(int value){
00132 std::string ret_val = "$";
00133 std::stringstream s_val;
00134 s_val<<value;
00135 ret_val += s_val.str();
00136 ret_val += "$";
00137 return ret_val;
00138 }
00139 #endif
00140
00141 static char OptionType2Char(const Ipopt::RegisteredOptionType &T){
00142 switch(T){
00143 case Ipopt::OT_Number: return 'F';
00144 case Ipopt::OT_Integer: return 'I';
00145 case Ipopt::OT_String: return 'S';
00146 case Ipopt::OT_Unknown:
00147 default: return 'U';
00148 }
00149 }
00150
00151 static std::string defaultAsString(Ipopt::SmartPtr< Ipopt::RegisteredOption > opt){
00152 Ipopt::RegisteredOptionType T = opt->Type();
00153 switch(T){
00154 case Ipopt::OT_Number: return makeString(opt->DefaultNumber());
00155 case Ipopt::OT_Integer: return makeString(opt->DefaultInteger());
00156 case Ipopt::OT_String: return (opt->DefaultString());
00157 case Ipopt::OT_Unknown:
00158 default:
00159 return "Unknown type of option";
00160 }
00161 }
00163 void
00164 RegisteredOptions::writeLatexOptionsTable(std::ostream &of, ExtraCategoriesInfo which){
00165 std::map<std::string, Ipopt::SmartPtr<Ipopt::RegisteredOption> >
00166 registered_options = RegisteredOptionsList();
00167
00168
00169
00170 of<<"\\topcaption{\\label{tab:options} "<<std::endl
00171 <<"List of options and compatibility with the different algorithms."<<std::endl
00172 <<"}"<<std::endl;
00173 of<<"\\tablehead{\\hline "<<std::endl
00174 <<"Option & type & ";
00175
00176 of<<"{\\tt B-BB} & {\\tt B-OA} & {\\tt B-QG} & {\\tt B-Hyb} & {\\tt B-Ecp} & {\\tt B-iFP} & {\\tt Cbc\\_Par} \\\\"<<std::endl
00177 <<"\\hline"<<std::endl
00178 <<"\\hline}"<<std::endl;
00179 of<<"\\tabletail{\\hline \\multicolumn{9}{|c|}{continued on next page}\\\\"
00180 <<"\\hline}"<<std::endl;
00181 of<<"\\tablelasttail{\\hline}"<<std::endl;
00182 of<<"{\\tiny"<<std::endl;
00183 of<<"\\begin{xtabular}{|l|r|r|r|r|r|r|r|r|}"<<std::endl;
00184
00185
00186 std::list< Ipopt::RegisteredOption * > sortedOptions;
00187
00188 for(std::map<std::string, Ipopt::SmartPtr<Ipopt::RegisteredOption > >::iterator i =
00189 registered_options.begin(); i != registered_options.end() ; i++){
00190 if(categoriesInfo(i->second->RegisteringCategory()) == which)
00191 sortedOptions.push_back(GetRawPtr(i->second));
00192 }
00193
00194 sortedOptions.sort(optionsCmp());
00195 std::string registeringCategory = "";
00196 for(std::list< Ipopt::RegisteredOption * >::iterator i = sortedOptions.begin();
00197 i != sortedOptions.end() ; i++)
00198 {
00199 if((*i)->RegisteringCategory() != registeringCategory){
00200 registeringCategory = (*i)->RegisteringCategory();
00201 of<<"\\hline"<<std::endl
00202 <<"\\multicolumn{1}{|c}{} & \\multicolumn{8}{l|}{"
00203 <<registeringCategory<<"}\\\\"<<std::endl
00204 <<"\\hline"<<std::endl;
00205 }
00206
00207 of<<makeLatex((*i)->Name())<<"& "<<OptionType2Char((*i)->Type())
00208
00209 <<"& "<<( (isValidForBBB((*i)->Name()))? "$\\surd$" : "-" )
00210 <<"& "<<( (isValidForBOA((*i)->Name()))? "$\\surd$" : "-" )
00211 <<"& "<<( (isValidForBQG((*i)->Name()))? "$\\surd$" : "-" )
00212 <<"& "<<( (isValidForHybrid((*i)->Name()))? "$\\surd$" : "-" )
00213 <<"& "<<( (isValidForBEcp((*i)->Name()))? "$\\surd$" : "-" )
00214 <<"& "<<( (isValidForBiFP((*i)->Name()))? "$\\surd$" : "-" )
00215 <<"& "<<( (isValidForCbc((*i)->Name()))? "$\\surd$" : "-" )
00216 <<"\\\\"<<std::endl;
00217 }
00218
00219 of<<"\\hline"<<std::endl
00220 <<"\\end{xtabular}"<<std::endl;
00221 of<<"}"<<std::endl;
00222 #if 0
00223 of<<"\\begin{tablenotes}"<<std::endl
00224 <<"\\item $\\strut^*$ option is available"<<std::endl
00225 <<" for MILP subsolver (it is only passed if the {\\tt milp\\_subsolver} optio"<<std::endl
00226 <<" see Subsection \\ref{sec:milp_opt})."<<std::endl
00227 <<" \\item $\\strut^1$ disabled for stability reasons."<<std::endl
00228 <<"\\end{tablenotes}"<<std::endl
00229 <<"\\end{threeparttable} "<<std::endl;
00230 #endif
00231 }
00232
00234 void
00235 RegisteredOptions::chooseOptions(ExtraCategoriesInfo which,
00236 std::list< Ipopt::RegisteredOption * >& sortedOptions)
00237 {
00238 std::map<std::string, Ipopt::SmartPtr<Ipopt::RegisteredOption> >
00239 registered_options = RegisteredOptionsList();
00240
00241 for(std::map<std::string, Ipopt::SmartPtr<Ipopt::RegisteredOption > >::iterator i =
00242 registered_options.begin(); i != registered_options.end() ; i++){
00243 if(categoriesInfo(i->second->RegisteringCategory()) == which)
00244 sortedOptions.push_back(GetRawPtr(i->second));
00245 }
00246 sortedOptions.sort(optionsCmp());
00247 }
00249 void
00250 RegisteredOptions::writeHtmlOptionsTable(std::ostream &of, ExtraCategoriesInfo which){
00251
00252
00253 of<<"<table border=\"1\">"<<std::endl;
00254
00255 std::list< Ipopt::RegisteredOption * > sortedOptions;
00256 chooseOptions(which, sortedOptions);
00257 writeHtmlOptionsTable(of, sortedOptions);
00258 }
00259
00260
00262 void
00263 RegisteredOptions::writeHtmlOptionsTable(std::ostream &os, std::list<Ipopt::RegisteredOption *> &options)
00264 {
00265 os<<"<table border=\"1\">"<<std::endl;
00266 os<<"<tr>"<<std::endl;
00267 os<<"<td>Option </td>"<<std::endl;
00268 os<<"<td> type </td>"<<std::endl;
00269
00270 os<<"<td> B-BB</td>"<<std::endl;
00271 os<<"<td> B-OA</td>"<<std::endl;
00272 os<<"<td> B-QG</td>"<<std::endl;
00273 os<<"<td> B-Hyb</td>"<<std::endl;
00274 os<<"</tr>"<<std::endl;
00275 std::string registeringCategory = "";
00276 for(std::list< Ipopt::RegisteredOption * >::iterator i = options.begin();
00277 i != options.end() ; i++)
00278 {
00279 if((*i)->RegisteringCategory() != registeringCategory){
00280 registeringCategory = (*i)->RegisteringCategory();
00281 os<<"<tr>"
00282 <<" <th colspan=9>"
00283 <<" <a href=\"#sec:"<<makeSpaceLess(registeringCategory)<<"\">"
00284 <<registeringCategory<<"</a> </th>"<<std::endl
00285 <<"</tr>"<<std::endl;
00286 }
00287
00288 os<<"<tr>"<<std::endl
00289 <<"<td> <a href=\"#sec:"<<makeSpaceLess((*i)->Name())<<"\">"
00290 <<((*i)->Name())<<"</a> </td>"<<std::endl
00291 <<"<td>"<<OptionType2Char((*i)->Type())<<"</td>"<<std::endl
00292
00293 <<"<td> "<<( (isValidForBBB((*i)->Name()))? '+' : '-' )<<"</td>"<<std::endl
00294 <<"<td>"<<( (isValidForBOA((*i)->Name()))? '+' : '-' )<<"</td>"<<std::endl
00295 <<"<td>"<<( (isValidForBQG((*i)->Name()))? '+' : '-' )<<"</td>"<<std::endl
00296 <<"<td>"<<( (isValidForHybrid((*i)->Name()))? '+' : '-' )<<"</td>"<<std::endl
00297 <<"</tr>"<<std::endl;
00298 }
00299
00300 os<<"</tr>"<<std::endl
00301 <<"</table>"<<std::endl;
00302 }
00303
00305 void
00306 RegisteredOptions::writeLatexHtmlDoc(std::ostream &os, ExtraCategoriesInfo which){
00307 std::list< Ipopt::RegisteredOption * > options;
00308 chooseOptions(which, options);
00309 os<<"\\latexhtml{}{"<<std::endl;
00310 os<<"\\HCode{"<<std::endl;
00311 writeHtmlOptionsTable(os, options);
00312 os<<"}\n}"<<std::endl;
00313
00314
00315 Ipopt::Journalist jnlst;
00316 Ipopt::SmartPtr<Ipopt::StreamJournal> J = new Ipopt::StreamJournal("options_journal", Ipopt::J_ALL);
00317 J->SetOutputStream(&os);
00318 J->SetPrintLevel(Ipopt::J_DOCUMENTATION, Ipopt::J_SUMMARY);
00319 jnlst.AddJournal(GetRawPtr(J));
00320
00321 std::string registeringCategory = "";
00322 for(std::list< Ipopt::RegisteredOption * >::iterator i = options.begin();
00323 i != options.end() ; i++)
00324 {
00325 if((*i)->RegisteringCategory() != registeringCategory){
00326 registeringCategory = (*i)->RegisteringCategory();
00327 os<<"\\subsection{"<<registeringCategory<<"}"<<std::endl;
00328 os<<"\\label{sec:"<<makeSpaceLess(registeringCategory)<<"}"<<std::endl;
00329 os<<"\\htmlanchor{sec:"<<makeSpaceLess(registeringCategory)<<"}"<<std::endl;
00330 }
00331
00332 (*i)->OutputLatexDescription(jnlst);
00333 }
00334 }
00335
00337 void
00338 RegisteredOptions::writeBonminOpt(std::ostream &os, ExtraCategoriesInfo which){
00339 std::list< Ipopt::RegisteredOption * > options;
00340 chooseOptions(which, options);
00341
00342
00343 Ipopt::Journalist jnlst;
00344 Ipopt::SmartPtr<Ipopt::StreamJournal> J = new Ipopt::StreamJournal("options_journal", Ipopt::J_ALL);
00345 J->SetOutputStream(&os);
00346 J->SetPrintLevel(Ipopt::J_DOCUMENTATION, Ipopt::J_SUMMARY);
00347 jnlst.AddJournal(GetRawPtr(J));
00348
00349 std::string registeringCategory = "";
00350 for(std::list< Ipopt::RegisteredOption * >::iterator i = options.begin();
00351 i != options.end() ; i++)
00352 {
00353 if((*i)->RegisteringCategory() != registeringCategory){
00354 registeringCategory = (*i)->RegisteringCategory();
00355 os<<std::endl<<"# registering category: "<<registeringCategory<<std::endl<<std::endl;
00356 }
00357 os<<"bonmin.";
00358 os.setf(std::ios::left);
00359 os.width(37);
00360 os<<(*i)->Name()<<" ";
00361 os.width(10);
00362 os<<makeNumber(defaultAsString(*i))<<"\t#";
00363 os<<(*i)->ShortDescription();
00364 os<<std::endl;
00365 }
00366 }
00367
00368 }