Ipopt Documentation  
 
Loading...
Searching...
No Matches
IpTNLP.hpp
Go to the documentation of this file.
1// Copyright (C) 2004, 2009 International Business Machines and others.
2// All Rights Reserved.
3// This code is published under the Eclipse Public License.
4//
5// Authors: Carl Laird, Andreas Waechter IBM 2004-08-13
6
7#ifndef __IPTNLP_HPP__
8#define __IPTNLP_HPP__
9
10#include "IpoptConfig.h"
11#include "IpUtils.hpp"
12#include "IpReferenced.hpp"
13#include "IpException.hpp"
14#include "IpAlgTypes.hpp"
15#include "IpReturnCodes.hpp"
16
17#include <map>
18
19namespace Ipopt
20{
21// forward declarations
22class IpoptData;
23class IpoptCalculatedQuantities;
24class IteratesVector;
25
48{
49public:
50
53 {
55 NON_LINEAR
56 };
57
61 { }
62
64 virtual ~TNLP()
65 { }
67
69
70 typedef std::map<std::string, std::vector<std::string> > StringMetaDataMapType;
71 typedef std::map<std::string, std::vector<Index> > IntegerMetaDataMapType;
72 typedef std::map<std::string, std::vector<Number> > NumericMetaDataMapType;
73
75 {
76 C_STYLE = 0,
77 FORTRAN_STYLE = 1
78 };
79
82
98 // [TNLP_get_nlp_info]
99 virtual bool get_nlp_info(
100 Index& n,
101 Index& m,
105 ) = 0;
106 // [TNLP_get_nlp_info]
107
125 // [TNLP_get_var_con_metadata]
148
169 // [TNLP_get_bounds_info]
170 virtual bool get_bounds_info(
171 Index n,
172 Number* x_l,
173 Number* x_u,
174 Index m,
175 Number* g_l,
176 Number* g_u
177 ) = 0;
178 // [TNLP_get_bounds_info]
179
210 // [TNLP_get_scaling_parameters]
213 bool& use_x_scaling,
214 Index n,
216 bool& use_g_scaling,
217 Index m,
219 )
220 // [TNLP_get_scaling_parameters]
221 {
224 (void) n;
225 (void) x_scaling;
227 (void) m;
228 (void) g_scaling;
229 return false;
230 }
231
242 // [TNLP_get_variables_linearity]
244 Index n,
246 )
247 // [TNLP_get_variables_linearity]
248 {
249 (void) n;
250 (void) var_types;
251 return false;
252 }
253
264 // [TNLP_get_constraints_linearity]
266 Index m,
268 )
269 // [TNLP_get_constraints_linearity]
270 {
271 (void) m;
273 return false;
274 }
275
300 // [TNLP_get_starting_point]
301 virtual bool get_starting_point(
302 Index n,
303 bool init_x,
304 Number* x,
305 bool init_z,
306 Number* z_L,
307 Number* z_U,
308 Index m,
309 bool init_lambda,
311 ) = 0;
312 // [TNLP_get_starting_point]
313
321 // [TNLP_get_warm_start_iterate]
324 )
325 {
327 return false;
328 }
329 // [TNLP_get_warm_start_iterate]
330
342 // [TNLP_eval_f]
343 virtual bool eval_f(
344 Index n,
345 const Number* x,
346 bool new_x,
348 ) = 0;
349 // [TNLP_eval_f]
350
362 // [TNLP_eval_grad_f]
363 virtual bool eval_grad_f(
364 Index n,
365 const Number* x,
366 bool new_x,
367 Number* grad_f
368 ) = 0;
369 // [TNLP_eval_grad_f]
370
381 // [TNLP_eval_g]
382 virtual bool eval_g(
383 Index n,
384 const Number* x,
385 bool new_x,
386 Index m,
387 Number* g
388 ) = 0;
389 // [TNLP_eval_g]
390
420 // [TNLP_eval_jac_g]
421 virtual bool eval_jac_g(
422 Index n,
423 const Number* x,
424 bool new_x,
425 Index m,
427 Index* iRow,
428 Index* jCol,
430 ) = 0;
431 // [TNLP_eval_jac_g]
432
471 // [TNLP_eval_h]
472 virtual bool eval_h(
473 Index n,
474 const Number* x,
475 bool new_x,
477 Index m,
478 const Number* lambda,
479 bool new_lambda,
481 Index* iRow,
482 Index* jCol,
484 )
485 // [TNLP_eval_h]
486 {
487 (void) n;
488 (void) x;
489 (void) new_x;
491 (void) m;
492 (void) lambda;
494 (void) nele_hess;
495 (void) iRow;
496 (void) jCol;
497 (void) values;
498 return false;
499 }
500
525 // [TNLP_get_number_of_nonlinear_variables]
527 // [TNLP_get_number_of_nonlinear_variables]
528 {
529 return -1;
530 }
531
542 // [TNLP_get_list_of_nonlinear_variables]
546 )
547 // [TNLP_get_list_of_nonlinear_variables]
548 {
551 return false;
552 }
555
558
587 // [TNLP_finalize_solution]
588 virtual void finalize_solution(
589 SolverReturn status,
590 Index n,
591 const Number* x,
592 const Number* z_L,
593 const Number* z_U,
594 Index m,
595 const Number* g,
596 const Number* lambda,
598 const IpoptData* ip_data,
600 ) = 0;
601 // [TNLP_finalize_solution]
602
618 // [TNLP_finalize_metadata]
640
664 // [TNLP_intermediate_callback]
667 Index iter,
671 Number mu,
677 const IpoptData* ip_data,
679 )
680 // [TNLP_intermediate_callback]
681 {
682 (void) mode;
683 (void) iter;
684 (void) obj_value;
685 (void) inf_pr;
686 (void) inf_du;
687 (void) mu;
688 (void) d_norm;
690 (void) alpha_du;
691 (void) alpha_pr;
692 (void) ls_trials;
693 (void) ip_data;
694 (void) ip_cq;
695 return true;
696 }
698
701
730 // [TNLP_get_curr_iterate]
732 const IpoptData* ip_data,
734 bool scaled,
735 Index n,
736 Number* x,
737 Number* z_L,
738 Number* z_U,
739 Index m,
740 Number* g,
742 ) const;
743 // [TNLP_get_curr_iterate]
744
778 // [TNLP_get_curr_violations]
780 const IpoptData* ip_data,
782 bool scaled,
783 Index n,
789 Index m,
792 ) const;
793 // [TNLP_get_curr_violations]
795
796private:
806
808 const TNLP&
809 );
810
813 const TNLP&
814 );
816};
817
818} // namespace Ipopt
819
820#endif
AlgorithmMode
enum to indicate the mode in which the algorithm is
Templated class which stores one entry for the CachedResult class.
Class for all IPOPT specific calculated quantities.
Class to organize all the data required by the algorithm.
Specialized CompoundVector class specifically for the algorithm iterates.
Storing the reference count of all the smart pointers that currently reference it.
Base class for all NLP's that use standard triplet matrix form and dense vectors.
Definition IpTNLP.hpp:48
virtual Index get_number_of_nonlinear_variables()
Return the number of variables that appear nonlinearly in the objective function or in at least one c...
Definition IpTNLP.hpp:526
virtual ~TNLP()
Default destructor.
Definition IpTNLP.hpp:64
virtual bool get_starting_point(Index n, bool init_x, Number *x, bool init_z, Number *z_L, Number *z_U, Index m, bool init_lambda, Number *lambda)=0
Method to request the starting point before iterating.
DECLARE_STD_EXCEPTION(INVALID_TNLP)
virtual bool eval_h(Index n, const Number *x, bool new_x, Number obj_factor, Index m, const Number *lambda, bool new_lambda, Index nele_hess, Index *iRow, Index *jCol, Number *values)
Method to request either the sparsity structure or the values of the Hessian of the Lagrangian.
Definition IpTNLP.hpp:472
virtual bool get_warm_start_iterate(IteratesVector &warm_start_iterate)
Method to provide an Ipopt warm start iterate which is already in the form Ipopt requires it internal...
Definition IpTNLP.hpp:322
virtual bool intermediate_callback(AlgorithmMode mode, Index iter, Number obj_value, Number inf_pr, Number inf_du, Number mu, Number d_norm, Number regularization_size, Number alpha_du, Number alpha_pr, Index ls_trials, const IpoptData *ip_data, IpoptCalculatedQuantities *ip_cq)
Intermediate Callback method for the user.
Definition IpTNLP.hpp:665
virtual void finalize_solution(SolverReturn status, Index n, const Number *x, const Number *z_L, const Number *z_U, Index m, const Number *g, const Number *lambda, Number obj_value, const IpoptData *ip_data, IpoptCalculatedQuantities *ip_cq)=0
This method is called when the algorithm has finished (successfully or not) so the TNLP can digest th...
virtual bool get_scaling_parameters(Number &obj_scaling, bool &use_x_scaling, Index n, Number *x_scaling, bool &use_g_scaling, Index m, Number *g_scaling)
Method to request scaling parameters.
Definition IpTNLP.hpp:211
virtual bool get_constraints_linearity(Index m, LinearityType *const_types)
Method to request the constraints linearity.
Definition IpTNLP.hpp:265
virtual bool eval_grad_f(Index n, const Number *x, bool new_x, Number *grad_f)=0
Method to request the gradient of the objective function.
virtual bool get_nlp_info(Index &n, Index &m, Index &nnz_jac_g, Index &nnz_h_lag, IndexStyleEnum &index_style)=0
Method to request the initial information about the problem.
virtual bool eval_f(Index n, const Number *x, bool new_x, Number &obj_value)=0
Method to request the value of the objective function.
bool get_curr_violations(const IpoptData *ip_data, IpoptCalculatedQuantities *ip_cq, bool scaled, Index n, Number *x_L_violation, Number *x_U_violation, Number *compl_x_L, Number *compl_x_U, Number *grad_lag_x, Index m, Number *nlp_constraint_violation, Number *compl_g) const
Get primal and dual infeasibility of the current iterate.
virtual void finalize_metadata(Index n, const StringMetaDataMapType &var_string_md, const IntegerMetaDataMapType &var_integer_md, const NumericMetaDataMapType &var_numeric_md, Index m, const StringMetaDataMapType &con_string_md, const IntegerMetaDataMapType &con_integer_md, const NumericMetaDataMapType &con_numeric_md)
This method returns any metadata collected during the run of the algorithm.
Definition IpTNLP.hpp:619
bool get_curr_iterate(const IpoptData *ip_data, IpoptCalculatedQuantities *ip_cq, bool scaled, Index n, Number *x, Number *z_L, Number *z_U, Index m, Number *g, Number *lambda) const
Get primal and dual variable values of the current iterate.
virtual bool get_variables_linearity(Index n, LinearityType *var_types)
Method to request the variables linearity.
Definition IpTNLP.hpp:243
std::map< std::string, std::vector< Index > > IntegerMetaDataMapType
Definition IpTNLP.hpp:71
virtual bool get_list_of_nonlinear_variables(Index num_nonlin_vars, Index *pos_nonlin_vars)
Return the indices of all nonlinear variables.
Definition IpTNLP.hpp:543
std::map< std::string, std::vector< Number > > NumericMetaDataMapType
Definition IpTNLP.hpp:72
virtual bool eval_jac_g(Index n, const Number *x, bool new_x, Index m, Index nele_jac, Index *iRow, Index *jCol, Number *values)=0
Method to request either the sparsity structure or the values of the Jacobian of the constraints.
void operator=(const TNLP &)
Default Assignment Operator.
virtual bool get_bounds_info(Index n, Number *x_l, Number *x_u, Index m, Number *g_l, Number *g_u)=0
Method to request bounds on the variables and constraints.
LinearityType
Linearity-types of variables and constraints.
Definition IpTNLP.hpp:53
@ LINEAR
Constraint/Variable is linear.
Definition IpTNLP.hpp:54
std::map< std::string, std::vector< std::string > > StringMetaDataMapType
Definition IpTNLP.hpp:70
TNLP(const TNLP &)
Copy Constructor.
virtual bool get_var_con_metadata(Index n, StringMetaDataMapType &var_string_md, IntegerMetaDataMapType &var_integer_md, NumericMetaDataMapType &var_numeric_md, Index m, StringMetaDataMapType &con_string_md, IntegerMetaDataMapType &con_integer_md, NumericMetaDataMapType &con_numeric_md)
Method to request meta data for the variables and the constraints.
Definition IpTNLP.hpp:126
virtual bool eval_g(Index n, const Number *x, bool new_x, Index m, Number *g)=0
Method to request the constraint values.
#define IPOPTLIB_EXPORT
This file contains a base class for all exceptions and a set of macros to help with exceptions.
SolverReturn
enum for the return from the optimize algorithm
ipindex Index
Type of all indices of vectors, matrices etc.
Definition IpTypes.hpp:20
ipnumber Number
Type of all numbers.
Definition IpTypes.hpp:17