MAiNGO
ipoptProblem.h
Go to the documentation of this file.
1 /**********************************************************************************
2  * Copyright (c) 2019 Process Systems Engineering (AVT.SVT), RWTH Aachen University
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License 2.0 which is available at
6  * http://www.eclipse.org/legal/epl-2.0.
7  *
8  * SPDX-License-Identifier: EPL-2.0
9  *
10  * @file ipoptProblem.h
11  *
12  * @brief File containing declaration of problem class used by Ipopt.
13  * Based on ample file by Carl Laird, Andreas Waechter IBM 2005-08-09
14  *
15  **********************************************************************************/
16 
17 #pragma once
18 
19 #include "ubpStructure.h"
20 
21 // Needed according to Ipopt Dll readme:
22 #define HAVE_CONFIG_H
23 #include "IpTNLP.hpp"
24 
25 #include <memory>
26 #include <vector>
27 
28 
29 namespace maingo {
30 
31 
32 namespace ubp {
33 
34 
35 struct DagObj;
36 
47 class IpoptProblem: public Ipopt::TNLP {
48 
49  public:
53  IpoptProblem();
54 
66  IpoptProblem(unsigned nvarIn, unsigned neqIn, unsigned nineqIn, unsigned nineqSquashIn, UbpStructure* structureIn,
67  std::vector<Constraint>* constraintPropertiesIn, std::shared_ptr<DagObj> dagObj);
68 
70  virtual ~IpoptProblem();
71 
81  virtual bool get_nlp_info(Ipopt::Index& n, Ipopt::Index& m, Ipopt::Index& nnz_jac_g,
82  Ipopt::Index& nnz_h_lag, IndexStyleEnum& Index_style);
83 
93  virtual bool get_bounds_info(Ipopt::Index n, Ipopt::Number* x_l, Ipopt::Number* x_u,
94  Ipopt::Index m, Ipopt::Number* g_l, Ipopt::Number* g_u);
95 
109  virtual bool get_starting_point(Ipopt::Index n, bool init_x, Ipopt::Number* x,
110  bool init_z, Ipopt::Number* z_L, Ipopt::Number* z_U,
111  Ipopt::Index m, bool init_lambda,
112  Ipopt::Number* lambda);
121  virtual bool eval_f(Ipopt::Index n, const Ipopt::Number* x, bool new_x, Ipopt::Number& obj_value);
122 
131  virtual bool eval_grad_f(Ipopt::Index n, const Ipopt::Number* x, bool new_x, Ipopt::Number* grad_f);
132 
142  virtual bool eval_g(Ipopt::Index n, const Ipopt::Number* x, bool new_x, Ipopt::Index m, Ipopt::Number* g);
143 
156  virtual bool eval_jac_g(Ipopt::Index n, const Ipopt::Number* x, bool new_x,
157  Ipopt::Index m, Ipopt::Index nele_jac, Ipopt::Index* iRow, Ipopt::Index* jCol,
158  Ipopt::Number* values);
159 
175  virtual bool eval_h(Ipopt::Index n, const Ipopt::Number* x, bool new_x,
176  Ipopt::Number obj_factor, Ipopt::Index m, const Ipopt::Number* lambda,
177  bool new_lambda, Ipopt::Index nele_hess, Ipopt::Index* iRow,
178  Ipopt::Index* jCol, Ipopt::Number* values);
179 
195  virtual void finalize_solution(Ipopt::SolverReturn status,
196  Ipopt::Index n, const Ipopt::Number* x, const Ipopt::Number* z_L, const Ipopt::Number* z_U,
197  Ipopt::Index m, const Ipopt::Number* g, const Ipopt::Number* lambda,
198  Ipopt::Number obj_value,
199  const Ipopt::IpoptData* ip_data,
200  Ipopt::IpoptCalculatedQuantities* ip_cq);
201 
208  double get_solution(std::vector<double>& sol_x);
209 
217  void set_bounds_and_starting_point(const std::vector<double>& xL, const std::vector<double>& xU, const std::vector<double>& xStart);
218 
219  private:
220  std::shared_ptr<DagObj> _DAGobj;
226  Ipopt::Index _nvar;
227  Ipopt::Index _nineq;
228  Ipopt::Index _nineqSquash;
229  Ipopt::Index _neq;
231  std::vector<Constraint>* _constraintProperties;
232  double _solution_f;
233  std::vector<double> _xL;
234  std::vector<double> _xU;
235  std::vector<double> _xStart;
236  std::vector<double> _solutionX;
239  // Copy constructors made private
240  IpoptProblem(const IpoptProblem&);
242 };
243 
244 
245 } // end namespace ubp
246 
247 
248 } // end namespace maingo
virtual bool eval_g(Ipopt::Index n, const Ipopt::Number *x, bool new_x, Ipopt::Index m, Ipopt::Number *g)
Function called by Ipopt to evaluate the constraints.
Definition: ipoptProblem.cpp:149
std::vector< double > _xL
Definition: ipoptProblem.h:233
virtual bool eval_f(Ipopt::Index n, const Ipopt::Number *x, bool new_x, Ipopt::Number &obj_value)
Function called by Ipopt to evaluate the objective function.
Definition: ipoptProblem.cpp:129
virtual ~IpoptProblem()
Destructor.
Definition: ipoptProblem.cpp:40
virtual bool eval_grad_f(Ipopt::Index n, const Ipopt::Number *x, bool new_x, Ipopt::Number *grad_f)
Function called by Ipopt to evaluate the gradient of the objective function.
Definition: ipoptProblem.cpp:139
virtual bool get_nlp_info(Ipopt::Index &n, Ipopt::Index &m, Ipopt::Index &nnz_jac_g, Ipopt::Index &nnz_h_lag, IndexStyleEnum &Index_style)
Function called by Ipopt to get basic information on the problem.
Definition: ipoptProblem.cpp:48
std::shared_ptr< DagObj > _DAGobj
Definition: ipoptProblem.h:220
IpoptProblem()
Standard constructor.
IpoptProblem & operator=(const IpoptProblem &)
Ipopt::Index _nineqSquash
Definition: ipoptProblem.h:228
double get_solution(std::vector< double > &sol_x)
Function called from the upper bounding wrapper to query the solution.
Definition: ipoptProblem.cpp:253
Ipopt::Index _nvar
Definition: ipoptProblem.h:226
UbpStructure * _structure
Definition: ipoptProblem.h:230
std::vector< double > _xStart
Definition: ipoptProblem.h:235
virtual bool eval_h(Ipopt::Index n, const Ipopt::Number *x, bool new_x, Ipopt::Number obj_factor, Ipopt::Index m, const Ipopt::Number *lambda, bool new_lambda, Ipopt::Index nele_hess, Ipopt::Index *iRow, Ipopt::Index *jCol, Ipopt::Number *values)
Function called by Ipopt to evaluate the Hessian - not implemented, just throws an exception!
Definition: ipoptProblem.cpp:193
namespace holding all essentials of MAiNGO
Definition: aleModel.h:31
virtual bool get_bounds_info(Ipopt::Index n, Ipopt::Number *x_l, Ipopt::Number *x_u, Ipopt::Index m, Ipopt::Number *g_l, Ipopt::Number *g_u)
Function called by Ipopt to get information on variables bounds.
Definition: ipoptProblem.cpp:73
double _solution_f
Definition: ipoptProblem.h:232
std::vector< double > _xU
Definition: ipoptProblem.h:234
void set_bounds_and_starting_point(const std::vector< double > &xL, const std::vector< double > &xU, const std::vector< double > &xStart)
Function called from the upper bounding wrapper to specify the variable bounds and starting point.
Definition: ipoptProblem.cpp:269
virtual bool eval_jac_g(Ipopt::Index n, const Ipopt::Number *x, bool new_x, Ipopt::Index m, Ipopt::Index nele_jac, Ipopt::Index *iRow, Ipopt::Index *jCol, Ipopt::Number *values)
Function called by Ipopt to evaluate the constraints.
Definition: ipoptProblem.cpp:159
Ipopt::Index _nineq
Definition: ipoptProblem.h:227
virtual bool get_starting_point(Ipopt::Index n, bool init_x, Ipopt::Number *x, bool init_z, Ipopt::Number *z_L, Ipopt::Number *z_U, Ipopt::Index m, bool init_lambda, Ipopt::Number *lambda)
Function called by Ipopt to query the starting point for local search.
Definition: ipoptProblem.cpp:107
Class for representing problems to be solved by IpOpt, providing an interface to the problem definiti...
Definition: ipoptProblem.h:47
Struct for storing structure information for the upper bounding solver.
Definition: ubpStructure.h:35
virtual void finalize_solution(Ipopt::SolverReturn status, Ipopt::Index n, const Ipopt::Number *x, const Ipopt::Number *z_L, const Ipopt::Number *z_U, Ipopt::Index m, const Ipopt::Number *g, const Ipopt::Number *lambda, Ipopt::Number obj_value, const Ipopt::IpoptData *ip_data, Ipopt::IpoptCalculatedQuantities *ip_cq)
Function called by Ipopt to communicate the result of the local search.
Definition: ipoptProblem.cpp:234
std::vector< Constraint > * _constraintProperties
Definition: ipoptProblem.h:231
Ipopt::Index _neq
Definition: ipoptProblem.h:229
std::vector< double > _solutionX
Definition: ipoptProblem.h:236