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

Go to the documentation of this file.
00001 // Copyright (C) 2004, 2007 International Business Machines and others.
00002 // All Rights Reserved.
00003 // This code is published under the Common Public License.
00004 //
00005 // $Id: IpRegOptions.hpp 1587 2009-10-27 16:09:21Z 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     virtual const std::string& Name() const
00086     {
00087       return name_;
00088     }
00090     virtual void SetName(const std::string& name)
00091     {
00092       name_ = name;
00093     }
00095     virtual const std::string& ShortDescription() const
00096     {
00097       return short_description_;
00098     }
00100     virtual const std::string& LongDescription() const
00101     {
00102       return long_description_;
00103     }
00105     virtual void SetShortDescription(const std::string& short_description)
00106     {
00107       short_description_ = short_description;
00108     }
00110     virtual void SetLongDescription(const std::string& long_description)
00111     {
00112       long_description_ = long_description;
00113     }
00115     virtual const std::string& RegisteringCategory() const
00116     {
00117       return registering_category_;
00118     }
00120     virtual void SetRegisteringCategory(const std::string& registering_category)
00121     {
00122       registering_category_ = registering_category;
00123     }
00125     virtual const RegisteredOptionType& Type() const
00126     {
00127       return type_;
00128     }
00130     virtual void SetType(const RegisteredOptionType& type)
00131     {
00132       type_ = type;
00133     }
00135     virtual Index Counter() const
00136     {
00137       return counter_;
00138     }
00140 
00147     virtual const bool& HasLower() const
00148     {
00149       DBG_ASSERT(type_ == OT_Number || type_ == OT_Integer);
00150       return has_lower_;
00151     }
00154     virtual const bool& LowerStrict() const
00155     {
00156       DBG_ASSERT(type_ == OT_Number && has_lower_ == true);
00157       return lower_strict_;
00158     }
00161     virtual Number LowerNumber() const
00162     {
00163       DBG_ASSERT(has_lower_ == true && type_ == OT_Number);
00164       return lower_;
00165     }
00168     virtual 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     virtual Index LowerInteger() const
00177     {
00178       DBG_ASSERT(has_lower_ == true && type_ == OT_Integer);
00179       return (Index)lower_;
00180     }
00183     virtual void SetLowerInteger(const Index& lower)
00184     {
00185       DBG_ASSERT(type_ == OT_Integer);
00186       lower_ = (Number)lower;
00187       has_lower_ = true;
00188     }
00191     virtual const bool& HasUpper() const
00192     {
00193       DBG_ASSERT(type_ == OT_Number || type_ == OT_Integer);
00194       return has_upper_;
00195     }
00198     virtual const bool& UpperStrict() const
00199     {
00200       DBG_ASSERT(type_ == OT_Number && has_upper_ == true);
00201       return upper_strict_;
00202     }
00205     virtual Number UpperNumber() const
00206     {
00207       DBG_ASSERT(has_upper_ == true && type_ == OT_Number);
00208       return upper_;
00209     }
00212     virtual 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     virtual Index UpperInteger() const
00222     {
00223       DBG_ASSERT(has_upper_ == true && type_ == OT_Integer);
00224       return (Index)upper_;
00225     }
00228     virtual void SetUpperInteger(const Index& upper)
00229     {
00230       DBG_ASSERT(type_ == OT_Integer);
00231       upper_ = (Number)upper;
00232       has_upper_ = true;
00233     }
00236     virtual 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     virtual Number DefaultNumber() const
00244     {
00245       DBG_ASSERT(type_ == OT_Number);
00246       return default_number_;
00247     }
00249     virtual void SetDefaultNumber(const Number& default_value)
00250     {
00251       DBG_ASSERT(type_ == OT_Number);
00252       default_number_ = default_value;
00253     }
00255     virtual Index DefaultInteger() const
00256     {
00257       DBG_ASSERT(type_ == OT_Integer);
00258       return (Index)default_number_;
00259     }
00262     virtual void SetDefaultInteger(const Index& default_value)
00263     {
00264       DBG_ASSERT(type_ == OT_Integer);
00265       default_number_ = (Number)default_value;
00266     }
00268     virtual std::string DefaultString() const
00269     {
00270       DBG_ASSERT(type_ == OT_String);
00271       return default_string_;
00272     }
00276     virtual Index DefaultStringAsEnum() const
00277     {
00278       DBG_ASSERT(type_ == OT_String);
00279       return MapStringSettingToEnum(default_string_);
00280     }
00282     virtual void SetDefaultString(const std::string& default_value)
00283     {
00284       DBG_ASSERT(type_ == OT_String);
00285       default_string_ = default_value;
00286     }
00289     virtual 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     virtual 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     virtual bool IsValidStringSetting(const std::string& value) const;
00318 
00322     virtual std::string MapStringSetting(const std::string& value) const;
00323 
00328     virtual Index MapStringSettingToEnum(const std::string& value) const;
00330 
00332     virtual void OutputDescription(const Journalist& jnlst) const;
00334     virtual void OutputShortDescription(const Journalist& jnlst) const;
00336     virtual 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     virtual ~RegisteredOptions()
00398     {}
00400 
00401     DECLARE_STD_EXCEPTION(OPTION_ALREADY_REGISTERED);
00402 
00407     virtual void SetRegisteringCategory(const std::string& registering_category)
00408     {
00409       current_registering_category_ = registering_category;
00410     }
00411 
00413     virtual std::string RegisteringCategory()
00414     {
00415       return current_registering_category_;
00416     }
00417 
00419     virtual void AddNumberOption(const std::string& name,
00420                                  const std::string& short_description,
00421                                  Number default_value,
00422                                  const std::string& long_description="");
00424     virtual 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     virtual 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     virtual 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     virtual void AddIntegerOption(const std::string& name,
00444                                   const std::string& short_description,
00445                                   Index default_value,
00446                                   const std::string& long_description="");
00448     virtual 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     virtual 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     virtual 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     virtual 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     virtual 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     virtual 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     virtual 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     virtual 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     virtual 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     virtual 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     virtual 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     virtual void AddStringOption8(const std::string& name,
00558                                   const std::string& short_description,
00559                                   const std::string& default_value,
00560                                   const std::string& setting1,
00561                                   const std::string& description1,
00562                                   const std::string& setting2,
00563                                   const std::string& description2,
00564                                   const std::string& setting3,
00565                                   const std::string& description3,
00566                                   const std::string& setting4,
00567                                   const std::string& description4,
00568                                   const std::string& setting5,
00569                                   const std::string& description5,
00570                                   const std::string& setting6,
00571                                   const std::string& description6,
00572                                   const std::string& setting7,
00573                                   const std::string& description7,
00574                                   const std::string& setting8,
00575                                   const std::string& description8,
00576                                   const std::string& long_description="");
00577     virtual void AddStringOption9(const std::string& name,
00578                                   const std::string& short_description,
00579                                   const std::string& default_value,
00580                                   const std::string& setting1,
00581                                   const std::string& description1,
00582                                   const std::string& setting2,
00583                                   const std::string& description2,
00584                                   const std::string& setting3,
00585                                   const std::string& description3,
00586                                   const std::string& setting4,
00587                                   const std::string& description4,
00588                                   const std::string& setting5,
00589                                   const std::string& description5,
00590                                   const std::string& setting6,
00591                                   const std::string& description6,
00592                                   const std::string& setting7,
00593                                   const std::string& description7,
00594                                   const std::string& setting8,
00595                                   const std::string& description8,
00596                                   const std::string& setting9,
00597                                   const std::string& description9,
00598                                   const std::string& long_description="");
00599     virtual void AddStringOption10(const std::string& name,
00600                                    const std::string& short_description,
00601                                    const std::string& default_value,
00602                                    const std::string& setting1,
00603                                    const std::string& description1,
00604                                    const std::string& setting2,
00605                                    const std::string& description2,
00606                                    const std::string& setting3,
00607                                    const std::string& description3,
00608                                    const std::string& setting4,
00609                                    const std::string& description4,
00610                                    const std::string& setting5,
00611                                    const std::string& description5,
00612                                    const std::string& setting6,
00613                                    const std::string& description6,
00614                                    const std::string& setting7,
00615                                    const std::string& description7,
00616                                    const std::string& setting8,
00617                                    const std::string& description8,
00618                                    const std::string& setting9,
00619                                    const std::string& description9,
00620                                    const std::string& setting10,
00621                                    const std::string& description10,
00622                                    const std::string& long_description="");
00623 
00626     virtual SmartPtr<const RegisteredOption> GetOption(const std::string& name);
00627 
00630     virtual void OutputOptionDocumentation(const Journalist& jnlst, std::list<std::string>& categories);
00631 
00633     virtual void OutputLatexOptionDocumentation(const Journalist& jnlst, std::list<std::string>& categories);
00635 
00636     typedef std::map<std::string, SmartPtr<RegisteredOption> > RegOptionsList;
00637 
00640     virtual const RegOptionsList& RegisteredOptionsList () const
00641     {
00642       return registered_options_;
00643     }
00644 
00645   private:
00646     std::string current_registering_category_;
00647     std::map<std::string, SmartPtr<RegisteredOption> > registered_options_;
00648   };
00649 } // namespace Ipopt
00650 
00651 #endif

Generated on Fri Oct 30 03:00:43 2009 by  doxygen 1.4.7