Debian Codegraph @

Bonmin/src/Interfaces/BonRegisteredOptions.hpp

raw
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, Carnegie Mellon University,
8 //
9 // Date : 27/08/2007
10
11 #ifndef BonRegisteredOptions_H
12 #define BonRegisteredOptions_H
13
14 #include "IpRegOptions.hpp"
15 #include "IpException.hpp"
16 #include "CoinError.hpp"
17 #include "IpTypes.hpp"
18 #include <iostream>
19
20 /* Forward declaration, the function will be defined in BonAmplTMINLP.cpp, if ASL is available */
21 namespace Ipopt {
22 class AmplOptionsList;
23 }
24
25 namespace Bonmin {
26 /** Class to add a few more information to Ipopt::RegisteredOptions.
27 In particular, it allows to store code to indicate in which algorithm
28 option is available. It also allows to table summing up all the options
29 both in LaTex and html.*/
30 class RegisteredOptions: public Ipopt::RegisteredOptions{
31 public:
32 enum ExtraOptInfosBits{
33 validInHybrid=0/** Say that option is valid in Hybrid method (1).*/,
34 validInQG/** Say that option is valid in Quesada Grossmann method (2).*/,
35 validInOA/**Say that option is valid in outer approximation dec (4).*/,
36 validInBBB/** Say that option is valid in the pure branch-and-bound (8).*/,
37 validInEcp/** Say that option is valid in the Ecp (16).*/,
38 validIniFP/** Say that option is valid in the iFP (32).*/,
39 validInCbc/** Say that option is valid when using Cbc_Par (64).*/
40 };
41
42
43 /* Table of values
44 * only B-Hyb 1
45 * B-Hyb & B-QG 3
46 * B-Hyb & B-OA 5
47 * B-Hyb & B-QG & B-OA & B-ECP 23
48 */
49
50
51
52 enum ExtraCategoriesInfo{
53 BonminCategory = 0/** Option category is for Bonmin.*/,
54 IpoptCategory /** Option category for Ipopt.*/,
55 FilterCategory /** Option category for FilterSqp.*/,
56 BqpdCategory /** Option category for Bqpd.*/,
57 CouenneCategory /** Option category for Couenne.*/,
58 UndocumentedCategory /**For undocumented options.*/
59 };
60 /** Standard constructor.*/
61 RegisteredOptions():
62 Ipopt::RegisteredOptions(){
63 }
64
65 /** Standard destructor.*/
66 ~RegisteredOptions(){
67 }
68
69 //DECLARE_STD_EXCEPTION(OPTION_NOT_REGISTERED);
70 /** Set registering category with extra information.*/
71 void SetRegisteringCategory (const std::string &registering_category,
72 const ExtraCategoriesInfo extra){
73 Ipopt::RegisteredOptions::SetRegisteringCategory(registering_category);
74 categoriesInfos_[registering_category] = extra;}
75
76 /** throw if option does not exists.*/
77 inline void optionExists(const std::string & option){
78 if(!IsValid(GetOption(option))){
79 std::string msg = "Try to access option: "+option;
80 msg += "\n Option is not registered.\n";
81 throw CoinError("Bonmin::RegisteredOption","optionExists",msg);
82 }
83 }
84
85 /**Set extra information for option.*/
86 inline void setOptionExtraInfo(const std::string & option, int code){
87 optionExists(option);
88 bonOptInfos_[option] = code;
89 }
90
91 /** Set that option is valid for hybrid.*/
92 inline void optionValidForHybrid(const std::string &option){
93 optionExists(option);
94 bonOptInfos_[option] |= 1 << validInHybrid;}
95
96 /** Set that option is valid for QuesadaGrossmann.*/
97 inline void optionValidForBQG(const std::string &option){
98 optionExists(option);
99 bonOptInfos_[option] |= 1 << validInQG;}
100
101 /** Set that option is valid for Outer approximation.*/
102 inline void optionValidForBOA(const std::string &option){
103 optionExists(option);
104 bonOptInfos_[option] |= 1 << validInOA;}
105
106 /** Set that option is valid for pure branch-and-bound.*/
107 inline void optionValidForBBB(const std::string &option){
108 optionExists(option);
109 bonOptInfos_[option] |= 1 << validInBBB;}
110
111 /** Set that option is valid for B-Ecp.*/
112 inline void optionValidForBEcp(const std::string &option){
113 optionExists(option);
114 bonOptInfos_[option] |= 1 << validInEcp;}
115
116 /** Set that option is valid for B-iFP.*/
117 inline void optionValidForBiFP(const std::string &option){
118 optionExists(option);
119 bonOptInfos_[option] |= 1 << validIniFP;}
120
121 /** Set that option is valid for Cbc.*/
122 inline void optionValidForCbc(const std::string &option){
123 optionExists(option);
124 bonOptInfos_[option] |= 1 << validInCbc;}
125
126
127 /** Say if option is valid for hybrid.*/
128 inline bool isValidForHybrid(const std::string &option){
129 optionExists(option);
130 std::map<std::string, int>::iterator i = bonOptInfos_.find(option);
131 if(i != bonOptInfos_.end())
132 return (i->second) & (1 << validInHybrid);
133 else return true;}
134
135 /** Say if option is valid for QuesadaGrossmann.*/
136 inline bool isValidForBQG(const std::string &option){
137 optionExists(option);
138 std::map<std::string, int>::iterator i = bonOptInfos_.find(option);
139 if(i != bonOptInfos_.end())
140 return (i->second) & (1 << validInQG);
141 else return true;}
142
143 /** Say if option is valid for Outer approximation.*/
144 inline bool isValidForBOA(const std::string &option){
145 optionExists(option);
146 std::map<std::string, int>::iterator i = bonOptInfos_.find(option);
147 if(i != bonOptInfos_.end())
148 return (i->second) & (1 << validInOA);
149 return true;}
150
151 /** Say if option is valid for pure branch-and-bound.*/
152 inline bool isValidForBBB(const std::string &option){
153 optionExists(option);
154 std::map<std::string, int>::iterator i = bonOptInfos_.find(option);
155 if(i != bonOptInfos_.end())
156 return (i->second) & (1 << validInBBB);
157 return true;}
158
159
160 /** Say if option is valid for B-Ecp.*/
161 inline bool isValidForBEcp(const std::string &option){
162 optionExists(option);
163 std::map<std::string, int>::iterator i = bonOptInfos_.find(option);
164 if(i != bonOptInfos_.end())
165 return (i->second) & (1 << validInEcp);
166 return true;}
167
168
169 /** Say if option is valid for B-iFP.*/
170 inline bool isValidForBiFP(const std::string &option){
171 optionExists(option);
172 std::map<std::string, int>::iterator i = bonOptInfos_.find(option);
173 if(i != bonOptInfos_.end())
174 return (i->second) & (1 << validIniFP);
175 return true;}
176
177
178 /** Say if option is valid for Cbc.*/
179 inline bool isValidForCbc(const std::string &option){
180 optionExists(option);
181 std::map<std::string, int>::iterator i = bonOptInfos_.find(option);
182 if(i != bonOptInfos_.end())
183 return (i->second) & (1 << validInCbc);
184 return true;}
185
186
187 /** Output Latex table of options.*/
188 void writeLatexOptionsTable(std::ostream &of, ExtraCategoriesInfo which);
189
190 /** Output html table of options.*/
191 void writeHtmlOptionsTable(std::ostream &of, ExtraCategoriesInfo which);
192
193
194 /** Output Latex/Html ooptions documentation.*/
195 void writeLatexHtmlDoc(std::ostream &of, ExtraCategoriesInfo which);
196 /** Ouptut a bonmin.opt file with options default values and short descriptions.*/
197 void writeBonminOpt(std::ostream &os, ExtraCategoriesInfo which);
198
199 /** Get info about what a category is taking care of (e.g., Ipopt, Bonmin, FilterSQP,...) .*/
200 ExtraCategoriesInfo categoriesInfo(const std::string &s)
201 {
202 std::map<std::string, ExtraCategoriesInfo>::iterator i = categoriesInfos_.find(s);
203 if(i == categoriesInfos_.end())
204 return IpoptCategory;
205 return i->second;
206 }
207
208 /* Forward declaration, the function will be defined in BonAmplTMINLP.cpp*/
209 void fillAmplOptionList(ExtraCategoriesInfo which, Ipopt::AmplOptionsList * amplOptList);
210
211 private:
212 /** Output Latex table of options.*/
213 void chooseOptions(ExtraCategoriesInfo which, std::list<Ipopt::RegisteredOption *> &options);
214 /** Output html table of options.*/
215 void writeHtmlOptionsTable(std::ostream & os, std::list<Ipopt::RegisteredOption *> &options);
216 /** Store extra Informations on Bonmin options.*/
217 std::map<std::string, int> bonOptInfos_;
218 /** Store extra Informations on Registering categories
219 (is bonmin, filterSqp...).*/
220 std::map<std::string, ExtraCategoriesInfo> categoriesInfos_;
221 };
222
223 }/*Ends namespace Bonmin.*/
224 #endif
225