00001
00017 #ifndef IPOPTSOLVER_H
00018 #define IPOPTSOLVER_H
00019
00020 #include "OSConfig.h"
00021 #include "OSDefaultSolver.h"
00022 #include "OSrLWriter.h"
00023 #include "OSInstance.h"
00024 #include "OSParameters.h"
00025 #include "OSnLNode.h"
00026 #include "OSiLReader.h"
00027 #include "OSoLReader.h"
00028 #include "OSInstance.h"
00029 #include "OSExpressionTree.h"
00030 #include "OSnLNode.h"
00031 #include "OSGeneral.h"
00032 #include "OSFileUtil.h"
00033 #include "OSErrorClass.h"
00034
00035 #include "OSResult.h"
00036 #include "OSInstance.h"
00037 #include "OSOption.h"
00038
00039 # include <cstddef>
00040 # include <cstdlib>
00041 # include <cctype>
00042 # include <cassert>
00043 # include <stack>
00044 #include <string>
00045 #include<iostream>
00046
00047 #ifdef HAVE_CTIME
00048 # include <ctime>
00049 #else
00050 # ifdef HAVE_TIME_H
00051 # include <time.h>
00052 # else
00053 # error "don't have header file for time"
00054 # endif
00055 #endif
00056
00057
00058 #ifdef HAVE_CMATH
00059 # include <cmath>
00060 #else
00061 # ifdef HAVE_MATH_H
00062 # include <math.h>
00063 # else
00064 # error "don't have header file for math"
00065 # endif
00066 #endif
00067 #include<vector>
00068 #include <map>
00069
00070
00071 #include "IpTNLP.hpp"
00072 #include "IpIpoptApplication.hpp"
00073
00074 using namespace Ipopt;
00075
00076
00077
00078
00079 class IpoptProblem : public TNLP{
00080 public:
00081
00083 IpoptProblem(OSInstance *osinstance_ , OSOption *osoption_, OSResult *osresult_, std::string *ipoptErrorMsg_);
00084
00086 virtual ~IpoptProblem();
00087
00088
00089 OSInstance *osinstance;
00090
00091 OSOption *osoption;
00092
00093 OSResult *osresult;
00094
00095 std::string *ipoptErrorMsg;
00096
00098 virtual bool get_nlp_info(Index& n, Index& m, Index& nnz_jac_g,
00099 Index& nnz_h_lag, IndexStyleEnum& index_style);
00100
00102 virtual bool get_bounds_info(Index n, Number* x_l, Number* x_u,
00103 Index m, Number* g_l, Number* g_u);
00104
00106 virtual bool get_starting_point(Index n, bool init_x, Number* x,
00107 bool init_z, Number* z_L, Number* z_U,
00108 Index m, bool init_lambda,
00109 Number* lambda);
00110
00112 virtual bool eval_f(Index n, const Number* x, bool new_x, Number& obj_value);
00113
00115 virtual bool eval_grad_f(Index n, const Number* x, bool new_x, Number* grad_f);
00116
00118 virtual bool eval_g(Index n, const Number* x, bool new_x, Index m, Number* g);
00119
00124 virtual bool eval_jac_g(Index n, const Number* x, bool new_x,
00125 Index m, Index nele_jac, Index* iRow, Index *jCol,
00126 Number* values);
00127
00132 virtual bool eval_h(Index n, const Number* x, bool new_x,
00133 Number obj_factor, Index m, const Number* lambda,
00134 bool new_lambda, Index nele_hess, Index* iRow,
00135 Index* jCol, Number* values);
00136
00138
00139
00140 virtual bool get_scaling_parameters(Number& obj_scaling,
00141 bool& use_x_scaling, Index n,
00142 Number* x_scaling,
00143 bool& use_g_scaling, Index m,
00144 Number* g_scaling);
00145
00149 virtual void finalize_solution(SolverReturn status,
00150 Index n, const Number* x, const Number* z_L, const Number* z_U,
00151 Index m, const Number* g, const Number* lambda,
00152 Number obj_value,
00153 const IpoptData* ip_data,
00154 IpoptCalculatedQuantities* ip_cq);
00156
00157
00158
00159 private:
00171
00172 IpoptProblem(const IpoptProblem&);
00173 IpoptProblem& operator=(const IpoptProblem&);
00175
00176
00177
00178
00179 };
00180
00181
00194
00195
00196 class IpoptSolver : public DefaultSolver{
00197 public:
00198
00199
00200
00202 IpoptSolver();
00203
00205 ~IpoptSolver();
00206
00207 SmartPtr<TNLP> nlp;
00208
00209 SmartPtr<IpoptApplication> app;
00210
00211
00214 virtual void solve() throw (ErrorClass) ;
00215
00220 virtual void buildSolverInstance() throw(ErrorClass);
00221
00226 virtual void setSolverOptions() throw(ErrorClass);
00227
00233 void dataEchoCheck();
00234
00239 OSiLReader *m_osilreader;
00240
00245 OSoLReader *m_osolreader;
00246
00247
00248 private:
00249 OSrLWriter *osrlwriter;
00250
00262
00263
00264
00266
00267 std::string *ipoptErrorMsg;
00268 };
00269
00270
00271 #endif