Debian Codegraph @

Bonmin/src/Interfaces/Ipopt/BonIpoptSolver.hpp

raw
1 // (C) Copyright International Business Machines (IBM) 2005, 2007
2 // All Rights Reserved.
3 // This code is published under the Eclipse Public License.
4 //
5 // Authors :
6 // Pierre Bonami, IBM
7 //
8 // Date : 26/09/2006
9
10 #ifndef IpoptSolver_HPP
11 #define IpoptSolver_HPP
12 #include "BonTNLPSolver.hpp"
13 #include "IpIpoptApplication.hpp"
14
15
16 namespace Bonmin
17 {
18 class IpoptSolver: public TNLPSolver
19 {
20 public:
21 class UnsolvedIpoptError: public TNLPSolver::UnsolvedError
22 {
23 public:
24 UnsolvedIpoptError(int errorNum,
25 Ipopt::SmartPtr<TMINLP2TNLP> problem,
26 std::string name):
27 TNLPSolver::UnsolvedError(errorNum, problem, name)
28 {}
29 virtual const std::string& errorName() const;
30
31 virtual const std::string& solverName() const;
32 virtual ~UnsolvedIpoptError()
33 {}
34 private:
35 static std::string errorNames [17];
36 static std::string solverName_;
37 };
38
39 virtual UnsolvedError * newUnsolvedError(int num,
40 Ipopt::SmartPtr<TMINLP2TNLP> problem,
41 std::string name)
42 {
43 return new UnsolvedIpoptError(num, problem, name);
44 }
45
46
47
48 /// Constructor
49 IpoptSolver(bool createEmpty = false);
50
51 /// Constructor with Passed in journalist, registered options, options
52 IpoptSolver(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions,
53 Ipopt::SmartPtr<Ipopt::OptionsList> options,
54 Ipopt::SmartPtr<Ipopt::Journalist> journalist,
55 const std::string & prefix);
56
57 /// Constructor with Passed in journalist, registered options, options
58 IpoptSolver(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions,
59 Ipopt::SmartPtr<Ipopt::OptionsList> options,
60 Ipopt::SmartPtr<Ipopt::Journalist> journalist);
61
62 /// Copy constructor
63 IpoptSolver(const IpoptSolver &other);
64
65 ///virtual copy constructor
66 virtual Ipopt::SmartPtr<TNLPSolver> clone();
67
68 /// Virtual destructor
69 virtual ~IpoptSolver();
70
71 /** Initialize the TNLPSolver (read options from params_file)
72 */
73 virtual bool Initialize(std::string params_file);
74
75 /** Initialize the TNLPSolver (read options from istream is)
76 */
77 virtual bool Initialize(std::istream& is);
78
79 /** @name Solve methods */
80 //@{
81 /// Solves a problem expresses as a TNLP
82 virtual TNLPSolver::ReturnStatus OptimizeTNLP(const Ipopt::SmartPtr<Ipopt::TNLP> & tnlp);
83
84 /// Resolves a problem expresses as a TNLP
85 virtual TNLPSolver::ReturnStatus ReOptimizeTNLP(const Ipopt::SmartPtr<Ipopt::TNLP> & tnlp);
86
87 /// Set the warm start in the solver
88 virtual bool setWarmStart(const CoinWarmStart * warm,
89 Ipopt::SmartPtr<TMINLP2TNLP> tnlp);
90
91 /// Get warm start used in last optimization
92 virtual CoinWarmStart * getUsedWarmStart(Ipopt::SmartPtr<TMINLP2TNLP> tnlp) const;
93
94
95 /// Get the warm start form the solver
96 virtual CoinWarmStart * getWarmStart(Ipopt::SmartPtr<Bonmin::TMINLP2TNLP> tnlp) const;
97
98 virtual CoinWarmStart * getEmptyWarmStart() const;
99
100 /** Check that warm start object is valid.*/
101 virtual bool warmStartIsValid(const CoinWarmStart * ws) const;
102
103 /// Enable the warm start options in the solver
104 virtual void enableWarmStart();
105
106 /// Disable the warm start options in the solver
107 virtual void disableWarmStart();
108
109 //@}
110
111 /// Get the CpuTime of the last optimization.
112 virtual double CPUTime();
113
114 /// Get the iteration count of the last optimization.
115 virtual int IterationCount();
116
117 /// turn off all output from the solver
118 virtual void setOutputToDefault();
119 /// turn on all output from the solver
120 virtual void forceSolverOutput(int log_level);
121
122 /// Get the solver name
123 virtual std::string & solverName()
124 {
125 return solverName_;
126 }
127
128 /// Register this solver options into passed roptions
129 static void RegisterOptions(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions)
130 {
131 Ipopt::IpoptApplication::RegisterAllIpoptOptions(GetRawPtr(roptions));
132 }
133
134
135
136 /// Return status of last optimization
137 Ipopt::ApplicationReturnStatus getOptStatus() const
138 {
139 return optimizationStatus_;
140 }
141
142 Ipopt::IpoptApplication& getIpoptApp()
143 {
144 return *app_;
145 }
146
147 virtual int errorCode() const
148 {
149 return (int) optimizationStatus_;
150 }
151 private:
152 /** Set default Ipopt parameters for use in a MINLP */
153 void setMinlpDefaults(Ipopt::SmartPtr< Ipopt::OptionsList> Options);
154
155 /** get Bonmin return status from Ipopt one. */
156 TNLPSolver::ReturnStatus solverReturnStatus(Ipopt::ApplicationReturnStatus optimization_status) const;
157
158 /** Ipopt application */
159 Ipopt::SmartPtr<Ipopt::IpoptApplication> app_;
160 /** return status of last optimization.*/
161 Ipopt::ApplicationReturnStatus optimizationStatus_;
162 //@}
163
164
165 /** Flag to indicate if last problem solved had 0 dimension. (in this case Ipopt was not called).*/
166 bool problemHadZeroDimension_;
167
168 /** Warm start strategy :
169 <ol>
170 <li> no warm start,</li>
171 <li> simple warm start (optimal point),</li>
172 <li> more elaborate strategies (interior point...).</li>
173 </ol>
174 */
175 int warmStartStrategy_;
176
177 /** flag remembering if we want to use warm start option */
178 bool enable_warm_start_;
179
180 /** flag remembering if we have call the Optimize method of the
181 IpoptInterface before */
182 bool optimized_before_;
183 //name of solver (Ipopt)
184 static std::string solverName_;
185 };
186 }
187 #endif
188