Bonmin
1.7
|
00001 // (C) Copyright International Business Machines Corporation 2007 00002 // 00003 // All Rights Reserved. 00004 // This code is published under the Common Public License. 00005 // 00006 // Authors : 00007 // Pierre Bonami, Carnegie Mellon University, 00008 // 00009 // Date : 27/08/2007 00010 00011 #ifndef BonRegisteredOptions_H 00012 #define BonRegisteredOptions_H 00013 00014 #include "IpRegOptions.hpp" 00015 #include "IpException.hpp" 00016 #include "CoinError.hpp" 00017 #include "IpTypes.hpp" 00018 #include <iostream> 00019 00020 /* Forward declaration, the function will be defined in BonAmplTMINLP.cpp, if ASL is available */ 00021 namespace Ipopt { 00022 class AmplOptionsList; 00023 } 00024 00025 namespace Bonmin { 00030 class RegisteredOptions: public Ipopt::RegisteredOptions{ 00031 public: 00032 enum ExtraOptInfosBits{ 00033 validInHybrid=0, 00034 validInQG, 00035 validInOA, 00036 validInBBB, 00037 validInEcp, 00038 validIniFP, 00039 validInCbc 00040 }; 00041 00042 00043 /* Table of values 00044 * only B-Hyb 1 00045 * B-Hyb & B-QG 3 00046 * B-Hyb & B-OA 5 00047 * B-Hyb & B-QG & B-OA & B-ECP 23 00048 */ 00049 00050 00051 00052 enum ExtraCategoriesInfo{ 00053 BonminCategory = 0, 00054 IpoptCategory , 00055 FilterCategory , 00056 BqpdCategory , 00057 CouenneCategory , 00058 UndocumentedCategory 00059 }; 00061 RegisteredOptions(): 00062 Ipopt::RegisteredOptions(){ 00063 } 00064 00066 ~RegisteredOptions(){ 00067 } 00068 00069 //DECLARE_STD_EXCEPTION(OPTION_NOT_REGISTERED); 00071 void SetRegisteringCategory (const std::string ®istering_category, 00072 const ExtraCategoriesInfo extra){ 00073 Ipopt::RegisteredOptions::SetRegisteringCategory(registering_category); 00074 categoriesInfos_[registering_category] = extra;} 00075 00077 inline void optionExists(const std::string & option){ 00078 if(!IsValid(GetOption(option))){ 00079 std::string msg = "Try to access option: "+option; 00080 msg += "\n Option is not registered.\n"; 00081 throw CoinError("Bonmin::RegisteredOption","optionExists",msg); 00082 } 00083 } 00084 00086 inline void setOptionExtraInfo(const std::string & option, int code){ 00087 optionExists(option); 00088 bonOptInfos_[option] = code; 00089 } 00090 00092 inline void optionValidForHybrid(const std::string &option){ 00093 optionExists(option); 00094 bonOptInfos_[option] |= 1 << validInHybrid;} 00095 00097 inline void optionValidForBQG(const std::string &option){ 00098 optionExists(option); 00099 bonOptInfos_[option] |= 1 << validInQG;} 00100 00102 inline void optionValidForBOA(const std::string &option){ 00103 optionExists(option); 00104 bonOptInfos_[option] |= 1 << validInOA;} 00105 00107 inline void optionValidForBBB(const std::string &option){ 00108 optionExists(option); 00109 bonOptInfos_[option] |= 1 << validInBBB;} 00110 00112 inline void optionValidForBEcp(const std::string &option){ 00113 optionExists(option); 00114 bonOptInfos_[option] |= 1 << validInEcp;} 00115 00117 inline void optionValidForBiFP(const std::string &option){ 00118 optionExists(option); 00119 bonOptInfos_[option] |= 1 << validIniFP;} 00120 00122 inline void optionValidForCbc(const std::string &option){ 00123 optionExists(option); 00124 bonOptInfos_[option] |= 1 << validInCbc;} 00125 00126 00128 inline bool isValidForHybrid(const std::string &option){ 00129 optionExists(option); 00130 std::map<std::string, int>::iterator i = bonOptInfos_.find(option); 00131 if(i != bonOptInfos_.end()) 00132 return (i->second) & (1 << validInHybrid); 00133 else return true;} 00134 00136 inline bool isValidForBQG(const std::string &option){ 00137 optionExists(option); 00138 std::map<std::string, int>::iterator i = bonOptInfos_.find(option); 00139 if(i != bonOptInfos_.end()) 00140 return (i->second) & (1 << validInQG); 00141 else return true;} 00142 00144 inline bool isValidForBOA(const std::string &option){ 00145 optionExists(option); 00146 std::map<std::string, int>::iterator i = bonOptInfos_.find(option); 00147 if(i != bonOptInfos_.end()) 00148 return (i->second) & (1 << validInOA); 00149 return true;} 00150 00152 inline bool isValidForBBB(const std::string &option){ 00153 optionExists(option); 00154 std::map<std::string, int>::iterator i = bonOptInfos_.find(option); 00155 if(i != bonOptInfos_.end()) 00156 return (i->second) & (1 << validInBBB); 00157 return true;} 00158 00159 00161 inline bool isValidForBEcp(const std::string &option){ 00162 optionExists(option); 00163 std::map<std::string, int>::iterator i = bonOptInfos_.find(option); 00164 if(i != bonOptInfos_.end()) 00165 return (i->second) & (1 << validInEcp); 00166 return true;} 00167 00168 00170 inline bool isValidForBiFP(const std::string &option){ 00171 optionExists(option); 00172 std::map<std::string, int>::iterator i = bonOptInfos_.find(option); 00173 if(i != bonOptInfos_.end()) 00174 return (i->second) & (1 << validIniFP); 00175 return true;} 00176 00177 00179 inline bool isValidForCbc(const std::string &option){ 00180 optionExists(option); 00181 std::map<std::string, int>::iterator i = bonOptInfos_.find(option); 00182 if(i != bonOptInfos_.end()) 00183 return (i->second) & (1 << validInCbc); 00184 return true;} 00185 00186 00188 void writeLatexOptionsTable(std::ostream &of, ExtraCategoriesInfo which); 00189 00191 void writeHtmlOptionsTable(std::ostream &of, ExtraCategoriesInfo which); 00192 00193 00195 void writeLatexHtmlDoc(std::ostream &of, ExtraCategoriesInfo which); 00197 void writeBonminOpt(std::ostream &os, ExtraCategoriesInfo which); 00198 00200 ExtraCategoriesInfo categoriesInfo(const std::string &s) 00201 { 00202 std::map<std::string, ExtraCategoriesInfo>::iterator i = categoriesInfos_.find(s); 00203 if(i == categoriesInfos_.end()) 00204 return IpoptCategory; 00205 return i->second; 00206 } 00207 00208 /* Forward declaration, the function will be defined in BonAmplTMINLP.cpp*/ 00209 void fillAmplOptionList(ExtraCategoriesInfo which, Ipopt::AmplOptionsList * amplOptList); 00210 00211 private: 00213 void chooseOptions(ExtraCategoriesInfo which, std::list<Ipopt::RegisteredOption *> &options); 00215 void writeHtmlOptionsTable(std::ostream & os, std::list<Ipopt::RegisteredOption *> &options); 00217 std::map<std::string, int> bonOptInfos_; 00220 std::map<std::string, ExtraCategoriesInfo> categoriesInfos_; 00221 }; 00222 00223 }/*Ends namespace Bonmin.*/ 00224 #endif 00225