Couenne  0.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CouenneTNLP.hpp
Go to the documentation of this file.
1 /* $Id: CouenneTNLP.hpp 893 2012-08-09 14:48:19Z pbelotti $
2  *
3  * Name: CouenneTNLP.hpp
4  * Authors: Pietro Belotti, Lehigh University
5  * Purpose: Definition of an NLP interface with gradient/Jacobian/etc
6  *
7  * This file is licensed under the Eclipse Public License (EPL)
8  */
9 
10 #ifndef COUENNETNLP_HPP
11 #define COUENNETNLP_HPP
12 
13 #include "IpTNLP.hpp"
14 #include "CouenneExprJac.hpp"
15 #include "CouenneExprHess.hpp"
16 #include "CouenneTypes.hpp"
17 
18 #include <vector>
19 #include <set>
20 
21 namespace Couenne {
22 
23  class CouenneProblem;
24  class CouenneSparseMatrix;
25 
27  class CouenneTNLP: public Ipopt::TNLP {
28 
29  public:
30 
32  CouenneTNLP ();
33 
36 
38  CouenneTNLP (const CouenneTNLP &);
39 
41  CouenneTNLP &operator= (const CouenneTNLP &rhs);
42 
44  CouenneTNLP *clone ();
45 
47  virtual ~CouenneTNLP ();
48 
50  void setInitSol (const double *sol);
51 
54  {return sol_;}
55 
58  {return bestZ_;}
59 
65  virtual bool get_nlp_info (Ipopt::Index& n,
66  Ipopt::Index& m,
67  Ipopt::Index& nnz_jac_g,
68  Ipopt::Index& nnz_h_lag,
69  enum Ipopt::TNLP::IndexStyleEnum& index_style);
70 
76  virtual bool get_bounds_info (Ipopt::Index n, Ipopt::Number* x_l, Ipopt::Number* x_u,
77  Ipopt::Index m, Ipopt::Number* g_l, Ipopt::Number* g_u);
78 
83  virtual bool get_variables_linearity (Ipopt::Index n, Ipopt::TNLP::LinearityType* var_types);
84 
88  virtual bool get_constraints_linearity (Ipopt::Index m, Ipopt::TNLP::LinearityType* const_types);
89 
96  virtual bool get_starting_point (Ipopt::Index n,
97  bool init_x, Ipopt::Number* x,
98  bool init_z, Ipopt::Number* z_L, Ipopt::Number* z_U,
99  Ipopt::Index m,
100  bool init_lambda, Ipopt::Number* lambda);
101 
103  virtual bool eval_f (Ipopt::Index n, const Ipopt::Number* x, bool new_x,
104  Ipopt::Number& obj_value);
105 
107  virtual bool eval_grad_f (Ipopt::Index n, const Ipopt::Number* x,
108  bool new_x,
109  Ipopt::Number* grad_f);
110 
112  virtual bool eval_g (Ipopt::Index n, const Ipopt::Number* x, bool new_x,
113  Ipopt::Index m, Ipopt::Number* g);
114 
120  virtual bool eval_jac_g (Ipopt::Index n, const Ipopt::Number* x, bool new_x,
121  Ipopt::Index m, Ipopt::Index nele_jac, Ipopt::Index* iRow,
122  Ipopt::Index *jCol, Ipopt::Number* values);
123 
133  virtual bool eval_h (Ipopt::Index n, const Ipopt::Number* x, bool new_x,
134  Ipopt::Number obj_factor, Ipopt::Index m, const Ipopt::Number* lambda,
135  bool new_lambda, Ipopt::Index nele_hess,
136  Ipopt::Index* iRow, Ipopt::Index* jCol, Ipopt::Number* values);
137 
139  virtual void finalize_solution (Ipopt::SolverReturn status,
140  Ipopt::Index n, const Ipopt::Number* x, const Ipopt::Number* z_L, const Ipopt::Number* z_U,
141  Ipopt::Index m, const Ipopt::Number* g, const Ipopt::Number* lambda,
142  Ipopt::Number obj_value,
143  const Ipopt::IpoptData* ip_data,
144  Ipopt::IpoptCalculatedQuantities* ip_cq);
145 
149  virtual bool intermediate_callback (Ipopt::AlgorithmMode mode,
150  Ipopt::Index iter, Ipopt::Number obj_value,
151  Ipopt::Number inf_pr, Ipopt::Number inf_du,
152  Ipopt::Number mu, Ipopt::Number d_norm,
153  Ipopt::Number regularization_size,
154  Ipopt::Number alpha_du, Ipopt::Number alpha_pr,
155  Ipopt::Index ls_trials,
156  const Ipopt::IpoptData* ip_data,
157  Ipopt::IpoptCalculatedQuantities* ip_cq);
158 
171  virtual Ipopt::Index get_number_of_nonlinear_variables ();
172 
174  virtual bool get_list_of_nonlinear_variables (Ipopt::Index num_nonlin_vars,
175  Ipopt::Index* pos_nonlin_vars);
176 
179  virtual void setObjective (expression *newObj);
180 
183  {return optHessian_;}
184 
186  inline bool &getSaveOptHessian ()
187  {return saveOptHessian_;}
188 
189  private:
190 
193 
196 
199 
202 
204  std::vector <std::pair <int, expression *> > gradient_;
205 
207  std::set <int> nonLinVars_;
208 
211 
215 
218 
221  };
222 }
223 
224 #endif
CouNumber * sol_
Optimal solution.
Jacobian of the problem (computed through Couenne expression classes).
CouNumber * getSolution()
returns best solution (if it exists)
Definition: CouenneTNLP.hpp:53
expression matrices.
virtual Ipopt::Index get_number_of_nonlinear_variables()
Pointer to the object containing all info.
virtual bool get_variables_linearity(Ipopt::Index n, Ipopt::TNLP::LinearityType *var_types)
return the variables linearity (TNLP::Linear or TNLP::NonLinear).
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)
return the starting point.
ExprHess * HLa_
Hessian — there are 1+m of them, but all are squeezed in a single object.
virtual bool eval_g(Ipopt::Index n, const Ipopt::Number *x, bool new_x, Ipopt::Index m, Ipopt::Number *g)
return the vector of constraint values
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)
return the jacobian of the constraints.
ExprJac Jac_
Jacobian.
virtual bool eval_f(Ipopt::Index n, const Ipopt::Number *x, bool new_x, Ipopt::Number &obj_value)
return the value of the objective function
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)
return the information about the bound on the variables and constraints.
CouenneProblem * problem_
Pointer to the object containing all info.
CouenneSparseMatrix * optHessian_
Stores the values of the Hessian of the Lagrangian at optimum for later use.
Class for sparse Matrixs (used in modifying distances in FP)
virtual bool intermediate_callback(Ipopt::AlgorithmMode mode, Ipopt::Index iter, Ipopt::Number obj_value, Ipopt::Number inf_pr, Ipopt::Number inf_du, Ipopt::Number mu, Ipopt::Number d_norm, Ipopt::Number regularization_size, Ipopt::Number alpha_du, Ipopt::Number alpha_pr, Ipopt::Index ls_trials, const Ipopt::IpoptData *ip_data, Ipopt::IpoptCalculatedQuantities *ip_cq)
Intermediate Callback method for the user.
bool & getSaveOptHessian()
set and get saveOptHessian_
CouNumber * sol0_
Initial solution.
std::vector< std::pair< int, expression * > > gradient_
expression gradient (packed sparse vector)
CouNumber getSolValue()
returns value of the best solution
Definition: CouenneTNLP.hpp:57
CouNumber bestZ_
Value of the optimal solution.
void setInitSol(const double *sol)
set initial solution
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)
return the hessian of the lagrangian.
virtual ~CouenneTNLP()
Destructor.
virtual void setObjective(expression *newObj)
Change objective function and modify gradient expressions accordingly.
Class for MINLP problems with symbolic information.
virtual bool get_list_of_nonlinear_variables(Ipopt::Index num_nonlin_vars, Ipopt::Index *pos_nonlin_vars)
get real list
virtual bool eval_grad_f(Ipopt::Index n, const Ipopt::Number *x, bool new_x, Ipopt::Number *grad_f)
return the vector of the gradient of the objective w.r.t. x
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)
This method is called when the algorithm is complete so the TNLP can store/write the solution...
double CouNumber
main number type in Couenne
CouenneSparseMatrix *& optHessian()
Get methods.
bool saveOptHessian_
Flag to be set to save this solution&#39;s Lagrangian Hessian in above structure.
CouenneTNLP()
Empty constructor.
Expression base class.
Class for handling NLPs using CouenneProblem.
Definition: CouenneTNLP.hpp:27
CouenneTNLP * clone()
Clone.
CouenneTNLP & operator=(const CouenneTNLP &rhs)
Assignment.
std::set< int > nonLinVars_
list of nonlinear variables
virtual bool get_nlp_info(Ipopt::Index &n, Ipopt::Index &m, Ipopt::Index &nnz_jac_g, Ipopt::Index &nnz_h_lag, enum Ipopt::TNLP::IndexStyleEnum &index_style)
return the number of variables and constraints, and the number of non-zeros in the jacobian and the h...
virtual bool get_constraints_linearity(Ipopt::Index m, Ipopt::TNLP::LinearityType *const_types)
return the constraint linearity.