00001
00016 #ifndef BONMINSOLVER_H
00017 #define BONMINSOLVER_H
00018
00019 #include "OSConfig.h"
00020 #include "OSDefaultSolver.h"
00021 #include "OSrLWriter.h"
00022 #include "OSInstance.h"
00023 #include "OSParameters.h"
00024 #include "OSnLNode.h"
00025 #include "OSiLReader.h"
00026 #include "OSInstance.h"
00027 #include "OSExpressionTree.h"
00028 #include "OSnLNode.h"
00029 #include "OSDataStructures.h"
00030 #include "OSFileUtil.h"
00031 #include "OSErrorClass.h"
00032
00033 #include "OSResult.h"
00034 #include "OSInstance.h"
00035
00036 # include <cstddef>
00037 # include <cstdlib>
00038 # include <cctype>
00039 # include <cassert>
00040 # include <stack>
00041 #include <string>
00042 # include <cppad/cppad.hpp>
00043 #include<iostream>
00044
00045 #ifdef HAVE_CTIME
00046 # include <ctime>
00047 #else
00048 # ifdef HAVE_TIME_H
00049 # include <time.h>
00050 # else
00051 # error "don't have header file for time"
00052 # endif
00053 #endif
00054
00055
00056 #ifdef HAVE_CMATH
00057 # include <cmath>
00058 #else
00059 # ifdef HAVE_MATH_H
00060 # include <math.h>
00061 # else
00062 # error "don't have header file for math"
00063 # endif
00064 #endif
00065 #include<vector>
00066 #include <map>
00067
00068
00069
00070
00071 #include "BonTMINLP.hpp"
00072 using namespace Ipopt;
00073 using namespace Bonmin;
00074
00075
00076
00077
00078
00079
00080 class BonminProblem : public TMINLP{
00081
00082
00083 public:
00084
00086 BonminProblem(OSInstance *osinstance_ , OSResult *osresult_);
00087
00089 virtual ~BonminProblem();
00090
00091 OSResult *osresult;
00092
00093 OSInstance *osinstance;
00094
00095
00105 virtual bool get_variables_types(Index n, VariableType* var_types);
00106
00108 virtual bool get_variables_linearity(Index n, Ipopt::TNLP::LinearityType* var_types);
00109
00114 virtual bool get_constraints_linearity(Index m, Ipopt::TNLP::LinearityType* const_types);
00116
00129 virtual bool get_nlp_info(Index& n, Index&m, Index& nnz_jac_g,
00130 Index& nnz_h_lag, TNLP::IndexStyleEnum& index_style);
00131
00132
00133
00135
00136
00137
00139 virtual bool get_bounds_info(Index n, Number* x_l, Number* x_u,
00140 Index m, Number* g_l, Number* g_u);
00141
00143 virtual bool get_starting_point(Index n, bool init_x, Number* x,
00144 bool init_z, Number* z_L, Number* z_U,
00145 Index m, bool init_lambda,
00146 Number* lambda);
00147
00149 virtual bool eval_f(Index n, const Number* x, bool new_x, Number& obj_value);
00150
00152 virtual bool eval_grad_f(Index n, const Number* x, bool new_x, Number* grad_f);
00153
00155 virtual bool eval_g(Index n, const Number* x, bool new_x, Index m, Number* g);
00156
00161 virtual bool eval_jac_g(Index n, const Number* x, bool new_x,
00162 Index m, Index nele_jac, Index* iRow, Index *jCol,
00163 Number* values);
00164
00169 virtual bool eval_h(Index n, const Number* x, bool new_x,
00170 Number obj_factor, Index m, const Number* lambda,
00171 bool new_lambda, Index nele_hess, Index* iRow,
00172 Index* jCol, Number* values);
00173
00175
00176
00177 virtual bool get_scaling_parameters(Number& obj_scaling,
00178 bool& use_x_scaling, Index n,
00179 Number* x_scaling,
00180 bool& use_g_scaling, Index m,
00181 Number* g_scaling);
00182
00185 virtual void finalize_solution(TMINLP::SolverReturn status,
00186 Index n, const Number* x, Number obj_value);
00188
00189 virtual const SosInfo * sosConstraints() const{return NULL;}
00190 virtual const BranchingInfo* branchingInfo() const{return NULL;}
00191
00192 void printSolutionAtEndOfAlgorithm(){
00193 printSol_ = true;}
00194
00195
00196
00197
00198
00199 private:
00200 bool printSol_;
00201
00202 private:
00214
00215
00217
00218
00219
00220 std::string bonminErrorMsg;
00221
00222
00223 };
00224
00225
00240 class BonminSolver : public DefaultSolver{
00241 public:
00242
00243
00244
00246 BonminSolver();
00247
00249 ~BonminSolver();
00250
00251
00252
00253
00254
00255
00256 SmartPtr<BonminProblem> tminlp;
00257
00258
00259
00260
00263 virtual void solve() throw (ErrorClass) ;
00264
00269 virtual void buildSolverInstance() throw(ErrorClass);
00270
00276 void dataEchoCheck();
00277
00282 OSiLReader *m_osilreader;
00283
00284
00285 private:
00286 OSrLWriter *osrlwriter;
00287
00288
00289 std::string bonminErrorMsg;
00290 };
00291
00292
00293 #endif