IpIpoptApplication.hpp 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. // Copyright (C) 2004, 2010 International Business Machines and others.
  2. // All Rights Reserved.
  3. // This code is published under the Eclipse Public License.
  4. //
  5. // $Id: IpIpoptApplication.hpp 2173 2013-03-30 17:25:39Z stefan $
  6. //
  7. // Authors: Carl Laird, Andreas Waechter IBM 2004-08-13
  8. #ifndef __IPIPOPTAPPLICATION_HPP__
  9. #define __IPIPOPTAPPLICATION_HPP__
  10. #ifndef IPOPT_EXPORT
  11. #ifdef _MSC_VER
  12. #ifdef IPOPT_DLL
  13. #define IPOPT_EXPORT(type) __declspec(dllexport) type __cdecl
  14. #else
  15. #define IPOPT_EXPORT(type) type __cdecl
  16. #endif
  17. #else
  18. #define IPOPT_EXPORT(type) type
  19. #endif
  20. #endif
  21. #include <iostream>
  22. #include "IpJournalist.hpp"
  23. #include "IpTNLP.hpp"
  24. #include "IpNLP.hpp"
  25. /* Return codes for the Optimize call for an application */
  26. #include "IpReturnCodes.hpp"
  27. namespace Ipopt
  28. {
  29. DECLARE_STD_EXCEPTION(IPOPT_APPLICATION_ERROR);
  30. /* forward declarations */
  31. class IpoptAlgorithm;
  32. class IpoptNLP;
  33. class IpoptData;
  34. class IpoptCalculatedQuantities;
  35. class AlgorithmBuilder;
  36. class RegisteredOptions;
  37. class OptionsList;
  38. class SolveStatistics;
  39. /** This is the main application class for making calls to Ipopt. */
  40. class IpoptApplication : public ReferencedObject
  41. {
  42. public:
  43. IpoptApplication(bool create_console_out = true,
  44. bool create_empty = false);
  45. /** Another constructor that assumes that the code in the
  46. * (default) constructor has already been executed */
  47. IpoptApplication(SmartPtr<RegisteredOptions> reg_options,
  48. SmartPtr<OptionsList> options,
  49. SmartPtr<Journalist> jnlst);
  50. virtual ~IpoptApplication();
  51. /** Method for creating a new IpoptApplication that uses the same
  52. * journalist and registered options, and a copy of the options
  53. list. */
  54. virtual SmartPtr<IpoptApplication> clone();
  55. /** Initialize method. This method reads the params file and
  56. * initializes the journalists. You should call this method at
  57. * some point before the first optimize call. Note: you can skip
  58. * the processing of a params file by setting params_file to "".
  59. * It returns something other than Solve_Succeeded if there was a
  60. * problem in the initialization (such as an invalid option).
  61. */
  62. virtual ApplicationReturnStatus Initialize(std::string params_file = "ipopt.opt");
  63. virtual ApplicationReturnStatus Initialize(std::istream& is);
  64. /**@name Solve methods */
  65. //@{
  66. /** Solve a problem that inherits from TNLP */
  67. virtual ApplicationReturnStatus OptimizeTNLP(const SmartPtr<TNLP>& tnlp);
  68. /** Solve a problem that inherits from NLP */
  69. virtual ApplicationReturnStatus OptimizeNLP(const SmartPtr<NLP>& nlp);
  70. /** Solve a problem that inherits from NLP */
  71. virtual ApplicationReturnStatus OptimizeNLP(const SmartPtr<NLP>& nlp, SmartPtr<AlgorithmBuilder>& alg_builder);
  72. /** Solve a problem (that inherits from TNLP) for a repeated time.
  73. * The OptimizeTNLP method must have been called before. The
  74. * TNLP must be the same object, and the structure (number of
  75. * variables and constraints and position of nonzeros in Jacobian
  76. * and Hessian must be the same). */
  77. virtual ApplicationReturnStatus ReOptimizeTNLP(const SmartPtr<TNLP>& tnlp);
  78. /** Solve a problem (that inherits from NLP) for a repeated time.
  79. * The OptimizeNLP method must have been called before. The
  80. * NLP must be the same object, and the structure (number of
  81. * variables and constraints and position of nonzeros in Jacobian
  82. * and Hessian must be the same). */
  83. virtual ApplicationReturnStatus ReOptimizeNLP(const SmartPtr<NLP>& nlp);
  84. //@}
  85. /** Method for opening an output file with given print_level.
  86. * Returns false if there was a problem. */
  87. virtual bool OpenOutputFile(std::string file_name, EJournalLevel print_level);
  88. /**@name Accessor methods */
  89. //@{
  90. /** Get the Journalist for printing output */
  91. virtual SmartPtr<Journalist> Jnlst()
  92. {
  93. return jnlst_;
  94. }
  95. /** Get a pointer to RegisteredOptions object to
  96. * add new options */
  97. virtual SmartPtr<RegisteredOptions> RegOptions()
  98. {
  99. return reg_options_;
  100. }
  101. /** Get the options list for setting options */
  102. virtual SmartPtr<OptionsList> Options()
  103. {
  104. return options_;
  105. }
  106. /** Get the options list for setting options (const version) */
  107. virtual SmartPtr<const OptionsList> Options() const
  108. {
  109. return ConstPtr(options_);
  110. }
  111. /** Get the object with the statistics about the most recent
  112. * optimization run. */
  113. virtual SmartPtr<SolveStatistics> Statistics();
  114. /** Get the IpoptNLP Object */
  115. virtual SmartPtr<IpoptNLP> IpoptNLPObject();
  116. /** Get the IpoptData Object */
  117. SmartPtr<IpoptData> IpoptDataObject();
  118. /** Get the IpoptCQ Object */
  119. virtual SmartPtr<IpoptCalculatedQuantities> IpoptCQObject();
  120. /** Get the Algorithm Object */
  121. SmartPtr<IpoptAlgorithm> AlgorithmObject();
  122. //@}
  123. /** Method for printing Ipopt copyright message now instead of
  124. * just before the optimization. If you want to have the copy
  125. * right message printed earlier than by default, call this
  126. * method at the convenient time. */
  127. void PrintCopyrightMessage();
  128. /** @name Methods for IpoptTypeInfo */
  129. //@{
  130. static void RegisterOptions(SmartPtr<RegisteredOptions> roptions);
  131. //@}
  132. /** Method to registering all Ipopt options. */
  133. static void
  134. RegisterAllIpoptOptions(const SmartPtr<RegisteredOptions>& roptions);
  135. private:
  136. /**@name Default Compiler Generated Methods
  137. * (Hidden to avoid implicit creation/calling).
  138. * These methods are not implemented and
  139. * we do not want the compiler to implement
  140. * them for us, so we declare them private
  141. * and do not define them. This ensures that
  142. * they will not be implicitly created/called. */
  143. //@{
  144. /** Default Constructor */
  145. // IpoptApplication();
  146. /** Copy Constructor */
  147. IpoptApplication(const IpoptApplication&);
  148. /** Overloaded Equals Operator */
  149. void operator=(const IpoptApplication&);
  150. //@}
  151. /** Method for the actual optimize call of the Ipopt algorithm.
  152. * This is used both for Optimize and ReOptimize */
  153. ApplicationReturnStatus call_optimize();
  154. /**@name Variables that customize the application behavior */
  155. //@{
  156. /** Decide whether or not the ipopt.opt file should be read */
  157. bool read_params_dat_;
  158. //@}
  159. /** Journalist for reporting output */
  160. SmartPtr<Journalist> jnlst_;
  161. /** RegisteredOptions */
  162. SmartPtr<RegisteredOptions> reg_options_;
  163. /** OptionsList used for the application */
  164. SmartPtr<OptionsList> options_;
  165. /** Object for storing statistics about the most recent
  166. * optimization run. */
  167. SmartPtr<SolveStatistics> statistics_;
  168. /** Object with the algorithm sceleton.
  169. */
  170. SmartPtr<IpoptAlgorithm> alg_;
  171. /** IpoptNLP Object for the NLP. We keep this around for a
  172. * ReOptimize warm start. */
  173. SmartPtr<IpoptNLP> ip_nlp_;
  174. /** IpoptData Object for the NLP. We keep this around for a
  175. * ReOptimize warm start.
  176. */
  177. SmartPtr<IpoptData> ip_data_;
  178. /** IpoptCalculatedQuantities Object for the NLP. We keep this
  179. * around for a ReOptimize warm start.
  180. */
  181. SmartPtr<IpoptCalculatedQuantities> ip_cq_;
  182. /** Pointer to the TNLPAdapter used to convert the TNLP to an NLP.
  183. * We keep this around for the ReOptimizerTNLP call. */
  184. SmartPtr<NLP> nlp_adapter_;
  185. /** @name Algorithmic parameters */
  186. //@{
  187. /** Flag indicating if we are to use the inexact linear solver option */
  188. bool inexact_algorithm_;
  189. /** Flag indicating if all bounds should be replaced by inequality
  190. * constraints. This is necessary for the inexact algorithm. */
  191. bool replace_bounds_;
  192. //@}
  193. };
  194. } // namespace Ipopt
  195. extern "C" IPOPT_EXPORT(class Ipopt::IpoptApplication *) IpoptApplicationFactory();
  196. #endif