- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

# /home/coin/SVN-release/Ipopt-3.2.1/Ipopt/src/Common/IpRegOptions.hpp

Go to the documentation of this file.

    00001 // Copyright (C) 2004, 2006 International Business Machines and others.
    00002 // All Rights Reserved.
    00003 // This code is published under the Common Public License.
    00004 //
    00005 // $Id: IpRegOptions.hpp 759 2006-07-07 03:07:08Z andreasw $
    00006 //
    00007 // Authors:  Carl Laird, Andreas Waechter     IBM    2005-06-18
    00008
    00009 #ifndef __IPREGOPTIONS_HPP__
    00010 #define __IPREGOPTIONS_HPP__
    00011
    00012 #include "IpUtils.hpp"
    00013 #include "IpReferenced.hpp"
    00014 #include "IpException.hpp"
    00015 #include "IpSmartPtr.hpp"
    00016
    00017 #include <map>
    00018
    00019 namespace Ipopt
    00020 {
    00021
    00022   enum RegisteredOptionType
    00023   {
    00024     OT_Number,
    00025     OT_Integer,
    00026     OT_String,
    00027     OT_Unknown
    00028   };
    00029
    00033   class RegisteredOption : public ReferencedObject
    00034   {
    00035   public:
    00038     RegisteredOption()
    00039         :
    00040         type_(OT_Unknown),
    00041         has_lower_(false),
    00042         has_upper_(false),
    00043         counter_(0)
    00044     {}
    00045
    00046     RegisteredOption(const std::string& name,
    00047                      const std::string& short_description,
    00048                      const std::string& long_description,
    00049                      const std::string& registering_category)
    00050         :
    00051         name_(name),
    00052         short_description_(short_description),
    00053         long_description_(long_description),
    00054         registering_category_(registering_category),
    00055         type_(OT_Unknown),
    00056         has_lower_(false),
    00057         has_upper_(false),
    00058         counter_(next_counter_++)
    00059     {}
    00060
    00061     RegisteredOption(const RegisteredOption& copy)
    00062         :
    00063         name_(copy.name_),
    00064         short_description_(copy.short_description_),
    00065         long_description_(copy.long_description_),
    00066         registering_category_(copy.registering_category_),
    00067         type_(copy.type_),
    00068         has_lower_(copy.has_lower_),
    00069         lower_(copy.lower_),
    00070         has_upper_(copy.has_upper_),
    00071         upper_(copy.upper_),
    00072         valid_strings_(copy.valid_strings_),
    00073         counter_(copy.counter_)
    00074     {}
    00075
    00076     virtual ~RegisteredOption()
    00077     {}
    00079
    00080     DECLARE_STD_EXCEPTION(ERROR_CONVERTING_STRING_TO_ENUM);
    00081
    00085     const std::string& Name() const
    00086     {
    00087       return name_;
    00088     }
    00090     void SetName(const std::string& name)
    00091     {
    00092       name_ = name;
    00093     }
    00095     const std::string& ShortDescription() const
    00096     {
    00097       return short_description_;
    00098     }
    00100     const std::string& LongDescription() const
    00101     {
    00102       return long_description_;
    00103     }
    00105     void SetShortDescription(const std::string& short_description)
    00106     {
    00107       short_description_ = short_description;
    00108     }
    00110     void SetLongDescription(const std::string& long_description)
    00111     {
    00112       long_description_ = long_description;
    00113     }
    00115     const std::string& RegisteringCategory() const
    00116     {
    00117       return registering_category_;
    00118     }
    00120     void SetRegisteringCategory(const std::string& registering_category)
    00121     {
    00122       registering_category_ = registering_category;
    00123     }
    00125     const RegisteredOptionType& Type() const
    00126     {
    00127       return type_;
    00128     }
    00130     void SetType(const RegisteredOptionType& type)
    00131     {
    00132       type_ = type;
    00133     }
    00135     Index Counter() const
    00136     {
    00137       return counter_;
    00138     }
    00140
    00147     const bool& HasLower() const
    00148     {
    00149       DBG_ASSERT(type_ == OT_Number || type_ == OT_Integer);
    00150       return has_lower_;
    00151     }
    00154     const bool& LowerStrict() const
    00155     {
    00156       DBG_ASSERT(type_ == OT_Number && has_lower_ == true);
    00157       return lower_strict_;
    00158     }
    00161     Number LowerNumber() const
    00162     {
    00163       DBG_ASSERT(has_lower_ == true && type_ == OT_Number);
    00164       return lower_;
    00165     }
    00168     void SetLowerNumber(const Number& lower, const bool& strict)
    00169     {
    00170       DBG_ASSERT(type_ == OT_Number);
    00171       lower_ = lower;
    00172       lower_strict_ = strict, has_lower_ = true;
    00173     }
    00176     Index LowerInteger() const
    00177     {
    00178       DBG_ASSERT(has_lower_ == true && type_ == OT_Integer);
    00179       return (Index)lower_;
    00180     }
    00183     void SetLowerInteger(const Index& lower)
    00184     {
    00185       DBG_ASSERT(type_ == OT_Integer);
    00186       lower_ = (Number)lower;
    00187       has_lower_ = true;
    00188     }
    00191     const bool& HasUpper() const
    00192     {
    00193       DBG_ASSERT(type_ == OT_Number || type_ == OT_Integer);
    00194       return has_upper_;
    00195     }
    00198     const bool& UpperStrict() const
    00199     {
    00200       DBG_ASSERT(type_ == OT_Number && has_upper_ == true);
    00201       return upper_strict_;
    00202     }
    00205     Number UpperNumber()
    00206     {
    00207       DBG_ASSERT(has_upper_ == true && type_ == OT_Number);
    00208       return upper_;
    00209     }
    00212     void SetUpperNumber(const Number& upper, const bool& strict)
    00213     {
    00214       DBG_ASSERT(type_ == OT_Number);
    00215       upper_ = upper;
    00216       upper_strict_ = strict;
    00217       has_upper_ = true;
    00218     }
    00221     Index UpperInteger() const
    00222     {
    00223       DBG_ASSERT(has_upper_ == true && type_ == OT_Integer);
    00224       return (Index)upper_;
    00225     }
    00228     void SetUpperInteger(const Index& upper)
    00229     {
    00230       DBG_ASSERT(type_ == OT_Integer);
    00231       upper_ = (Number)upper;
    00232       has_upper_ = true;
    00233     }
    00236     void AddValidStringSetting(const std::string value,
    00237                                const std::string description)
    00238     {
    00239       DBG_ASSERT(type_ == OT_String);
    00240       valid_strings_.push_back(string_entry(value, description));
    00241     }
    00243     Number DefaultNumber() const
    00244     {
    00245       DBG_ASSERT(type_ == OT_Number);
    00246       return default_number_;
    00247     }
    00249     void SetDefaultNumber(const Number& default_value)
    00250     {
    00251       DBG_ASSERT(type_ == OT_Number);
    00252       default_number_ = default_value;
    00253     }
    00255     Index DefaultInteger() const
    00256     {
    00257       DBG_ASSERT(type_ == OT_Integer);
    00258       return (Index)default_number_;
    00259     }
    00262     void SetDefaultInteger(const Index& default_value)
    00263     {
    00264       DBG_ASSERT(type_ == OT_Integer);
    00265       default_number_ = (Number)default_value;
    00266     }
    00268     std::string DefaultString() const
    00269     {
    00270       DBG_ASSERT(type_ == OT_String);
    00271       return default_string_;
    00272     }
    00276     Index DefaultStringAsEnum() const
    00277     {
    00278       DBG_ASSERT(type_ == OT_String);
    00279       return MapStringSettingToEnum(default_string_);
    00280     }
    00282     void SetDefaultString(const std::string& default_value)
    00283     {
    00284       DBG_ASSERT(type_ == OT_String);
    00285       default_string_ = default_value;
    00286     }
    00289     bool IsValidNumberSetting(const Number& value) const
    00290     {
    00291       DBG_ASSERT(type_ == OT_Number);
    00292       if (has_lower_ && ((lower_strict_ == true && value <= lower_) ||
    00293                          (lower_strict_ == false && value < lower_))) {
    00294         return false;
    00295       }
    00296       if (has_upper_ && ((upper_strict_ == true && value >= upper_) ||
    00297                          (upper_strict_ == false && value > upper_))) {
    00298         return false;
    00299       }
    00300       return true;
    00301     }
    00304     bool IsValidIntegerSetting(const Index& value) const
    00305     {
    00306       DBG_ASSERT(type_ == OT_Integer);
    00307       if (has_lower_ && value < lower_) {
    00308         return false;
    00309       }
    00310       if (has_upper_ && value > upper_) {
    00311         return false;
    00312       }
    00313       return true;
    00314     }
    00317     bool IsValidStringSetting(const std::string& value) const;
    00318
    00322     std::string MapStringSetting(const std::string& value) const;
    00323
    00328     Index MapStringSettingToEnum(const std::string& value) const;
    00330
    00332     void OutputDescription(const Journalist& jnlst) const;
    00334     void OutputShortDescription(const Journalist& jnlst) const;
    00336     void OutputLatexDescription(const Journalist& jnlst) const;
    00337
    00338   private:
    00339     std::string name_;
    00340     std::string short_description_;
    00341     std::string long_description_;
    00342     std::string registering_category_;
    00343     RegisteredOptionType type_;
    00344
    00345     bool has_lower_;
    00346     bool lower_strict_;
    00347     Number lower_;
    00348     bool has_upper_;
    00349     bool upper_strict_;
    00350     Number upper_;
    00351     Number default_number_;
    00352
    00353     void MakeValidLatexString(std::string source, std::string& dest) const;
    00354     std::string MakeValidLatexNumber(Number value) const;
    00355
    00358     bool string_equal_insensitive(const std::string& s1,
    00359                                   const std::string& s2) const;
    00360
    00362     class string_entry
    00363     {
    00364     public:
    00365       string_entry(const std::string& value, const std::string& description)
    00366           : value_(value), description_(description)
    00367       {}
    00368       std::string value_;
    00369       std::string description_;
    00370     };
    00371
    00372     std::vector<string_entry> valid_strings_;
    00373     std::string default_string_;
    00374
    00377     const Index counter_;
    00378
    00379     static Index next_counter_;
    00380   };
    00381
    00385   class RegisteredOptions : public ReferencedObject
    00386   {
    00387   public:
    00391     RegisteredOptions()
    00392         :
    00393         current_registering_category_("Uncategorized")
    00394     {}
    00395
    00397     ~RegisteredOptions()
    00398     {}
    00400
    00401     DECLARE_STD_EXCEPTION(OPTION_ALREADY_REGISTERED);
    00402
    00407     void SetRegisteringCategory(const std::string& registering_category)
    00408     {
    00409       current_registering_category_ = registering_category;
    00410     }
    00411
    00413     std::string RegisteringCategory()
    00414     {
    00415       return current_registering_category_;
    00416     }
    00417
    00419     void AddNumberOption(const std::string& name,
    00420                          const std::string& short_description,
    00421                          Number default_value,
    00422                          const std::string& long_description="");
    00424     void AddLowerBoundedNumberOption(const std::string& name,
    00425                                      const std::string& short_description,
    00426                                      Number lower, bool strict,
    00427                                      Number default_value,
    00428                                      const std::string& long_description="");
    00430     void AddUpperBoundedNumberOption(const std::string& name,
    00431                                      const std::string& short_description,
    00432                                      Number upper, bool strict,
    00433                                      Number default_value,
    00434                                      const std::string& long_description="");
    00436     void AddBoundedNumberOption(const std::string& name,
    00437                                 const std::string& short_description,
    00438                                 Number lower, bool lower_strict,
    00439                                 Number upper, bool upper_strict,
    00440                                 Number default_value,
    00441                                 const std::string& long_description="");
    00443     void AddIntegerOption(const std::string& name,
    00444                           const std::string& short_description,
    00445                           Index default_value,
    00446                           const std::string& long_description="");
    00448     void AddLowerBoundedIntegerOption(const std::string& name,
    00449                                       const std::string& short_description,
    00450                                       Index lower, Index default_value,
    00451                                       const std::string& long_description="");
    00453     void AddUpperBoundedIntegerOption(const std::string& name,
    00454                                       const std::string& short_description,
    00455                                       Index upper, Index default_value,
    00456                                       const std::string& long_description="");
    00458     void AddBoundedIntegerOption(const std::string& name,
    00459                                  const std::string& short_description,
    00460                                  Index lower, Index upper,
    00461                                  Index default_value,
    00462                                  const std::string& long_description="");
    00463
    00465     void AddStringOption(const std::string& name,
    00466                          const std::string& short_description,
    00467                          const std::string& default_value,
    00468                          const std::vector<std::string>& settings,
    00469                          const std::vector<std::string>& descriptions,
    00470                          const std::string& long_description="");
    00473     void AddStringOption1(const std::string& name,
    00474                           const std::string& short_description,
    00475                           const std::string& default_value,
    00476                           const std::string& setting1,
    00477                           const std::string& description1,
    00478                           const std::string& long_description="");
    00479     void AddStringOption2(const std::string& name,
    00480                           const std::string& short_description,
    00481                           const std::string& default_value,
    00482                           const std::string& setting1,
    00483                           const std::string& description1,
    00484                           const std::string& setting2,
    00485                           const std::string& description2,
    00486                           const std::string& long_description="");
    00487     void AddStringOption3(const std::string& name,
    00488                           const std::string& short_description,
    00489                           const std::string& default_value,
    00490                           const std::string& setting1,
    00491                           const std::string& description1,
    00492                           const std::string& setting2,
    00493                           const std::string& description2,
    00494                           const std::string& setting3,
    00495                           const std::string& description3,
    00496                           const std::string& long_description="");
    00497     void AddStringOption4(const std::string& name,
    00498                           const std::string& short_description,
    00499                           const std::string& default_value,
    00500                           const std::string& setting1,
    00501                           const std::string& description1,
    00502                           const std::string& setting2,
    00503                           const std::string& description2,
    00504                           const std::string& setting3,
    00505                           const std::string& description3,
    00506                           const std::string& setting4,
    00507                           const std::string& description4,
    00508                           const std::string& long_description="");
    00509     void AddStringOption5(const std::string& name,
    00510                           const std::string& short_description,
    00511                           const std::string& default_value,
    00512                           const std::string& setting1,
    00513                           const std::string& description1,
    00514                           const std::string& setting2,
    00515                           const std::string& description2,
    00516                           const std::string& setting3,
    00517                           const std::string& description3,
    00518                           const std::string& setting4,
    00519                           const std::string& description4,
    00520                           const std::string& setting5,
    00521                           const std::string& description5,
    00522                           const std::string& long_description="");
    00523     void AddStringOption6(const std::string& name,
    00524                           const std::string& short_description,
    00525                           const std::string& default_value,
    00526                           const std::string& setting1,
    00527                           const std::string& description1,
    00528                           const std::string& setting2,
    00529                           const std::string& description2,
    00530                           const std::string& setting3,
    00531                           const std::string& description3,
    00532                           const std::string& setting4,
    00533                           const std::string& description4,
    00534                           const std::string& setting5,
    00535                           const std::string& description5,
    00536                           const std::string& setting6,
    00537                           const std::string& description6,
    00538                           const std::string& long_description="");
    00539     void AddStringOption7(const std::string& name,
    00540                           const std::string& short_description,
    00541                           const std::string& default_value,
    00542                           const std::string& setting1,
    00543                           const std::string& description1,
    00544                           const std::string& setting2,
    00545                           const std::string& description2,
    00546                           const std::string& setting3,
    00547                           const std::string& description3,
    00548                           const std::string& setting4,
    00549                           const std::string& description4,
    00550                           const std::string& setting5,
    00551                           const std::string& description5,
    00552                           const std::string& setting6,
    00553                           const std::string& description6,
    00554                           const std::string& setting7,
    00555                           const std::string& description7,
    00556                           const std::string& long_description="");
    00557
    00560     SmartPtr<const RegisteredOption> GetOption(const std::string& name);
    00561
    00564     void OutputOptionDocumentation(const Journalist& jnlst, std::list<std::string>& categories);
    00565
    00567     void OutputLatexOptionDocumentation(const Journalist& jnlst, std::list<std::string>& categories);
    00569
    00570   private:
    00571     std::string current_registering_category_;
    00572     std::map<std::string, SmartPtr<RegisteredOption> > registered_options_;
    00573   };
    00574 } // namespace Ipopt
    00575
    00576 #endif