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;
24class IteratesVector;
25
48{
49public:
50
57
61 { }
62
64 virtual ~TNLP()
65 { }
66
67
68 DECLARE_STD_EXCEPTION(INVALID_TNLP);
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 {
78 };
79
82
98 // [TNLP_get_nlp_info]
99 virtual bool get_nlp_info(
100 Index& n,
101 Index& m,
102 Index& nnz_jac_g,
103 Index& nnz_h_lag,
104 IndexStyleEnum& index_style
105 ) = 0;
106 // [TNLP_get_nlp_info]
107
125 // [TNLP_get_var_con_metadata]
127 Index n,
128 StringMetaDataMapType& var_string_md,
129 IntegerMetaDataMapType& var_integer_md,
130 NumericMetaDataMapType& var_numeric_md,
131 Index m,
132 StringMetaDataMapType& con_string_md,
133 IntegerMetaDataMapType& con_integer_md,
134 NumericMetaDataMapType& con_numeric_md
135 )
136 // [TNLP_get_var_con_metadata]
137 {
138 (void) n;
139 (void) var_string_md;
140 (void) var_integer_md;
141 (void) var_numeric_md;
142 (void) m;
143 (void) con_string_md;
144 (void) con_integer_md;
145 (void) con_numeric_md;
146 return false;
147 }
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]
212 Number& obj_scaling,
213 bool& use_x_scaling,
214 Index n,
215 Number* x_scaling,
216 bool& use_g_scaling,
217 Index m,
218 Number* g_scaling
219 )
220 // [TNLP_get_scaling_parameters]
221 {
222 (void) obj_scaling;
223 (void) use_x_scaling;
224 (void) n;
225 (void) x_scaling;
226 (void) use_g_scaling;
227 (void) m;
228 (void) g_scaling;
229 return false;
230 }
231
242 // [TNLP_get_variables_linearity]
244 Index n,
245 LinearityType* var_types
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,
267 LinearityType* const_types
268 )
269 // [TNLP_get_constraints_linearity]
270 {
271 (void) m;
272 (void) const_types;
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,
310 Number* lambda
311 ) = 0;
312 // [TNLP_get_starting_point]
313
321 // [TNLP_get_warm_start_iterate]
323 IteratesVector& warm_start_iterate
324 )
325 {
326 (void) warm_start_iterate;
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,
347 Number& obj_value
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,
426 Index nele_jac,
427 Index* iRow,
428 Index* jCol,
429 Number* values
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,
476 Number obj_factor,
477 Index m,
478 const Number* lambda,
479 bool new_lambda,
480 Index nele_hess,
481 Index* iRow,
482 Index* jCol,
483 Number* values
484 )
485 // [TNLP_eval_h]
486 {
487 (void) n;
488 (void) x;
489 (void) new_x;
490 (void) obj_factor;
491 (void) m;
492 (void) lambda;
493 (void) new_lambda;
494 (void) nele_hess;
495 (void) iRow;
496 (void) jCol;
497 (void) values;
498 return false;
499 }
500
510
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]
544 Index num_nonlin_vars,
545 Index* pos_nonlin_vars
546 )
547 // [TNLP_get_list_of_nonlinear_variables]
548 {
549 (void) num_nonlin_vars;
550 (void) pos_nonlin_vars;
551 return false;
552 }
553
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,
597 Number obj_value,
598 const IpoptData* ip_data,
600 ) = 0;
601 // [TNLP_finalize_solution]
602
618 // [TNLP_finalize_metadata]
619 virtual void finalize_metadata(
620 Index n,
621 const StringMetaDataMapType& var_string_md,
622 const IntegerMetaDataMapType& var_integer_md,
623 const NumericMetaDataMapType& var_numeric_md,
624 Index m,
625 const StringMetaDataMapType& con_string_md,
626 const IntegerMetaDataMapType& con_integer_md,
627 const NumericMetaDataMapType& con_numeric_md
628 )
629 // [TNLP_finalize_metadata]
630 {
631 (void) n;
632 (void) var_string_md;
633 (void) var_integer_md;
634 (void) var_numeric_md;
635 (void) m;
636 (void) con_string_md;
637 (void) con_integer_md;
638 (void) con_numeric_md;
639 }
640
664 // [TNLP_intermediate_callback]
666 AlgorithmMode mode,
667 Index iter,
668 Number obj_value,
669 Number inf_pr,
670 Number inf_du,
671 Number mu,
672 Number d_norm,
673 Number regularization_size,
674 Number alpha_du,
675 Number alpha_pr,
676 Index ls_trials,
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;
689 (void) regularization_size;
690 (void) alpha_du;
691 (void) alpha_pr;
692 (void) ls_trials;
693 (void) ip_data;
694 (void) ip_cq;
695 return true;
696 }
697
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,
741 Number* lambda
742 ) const;
743 // [TNLP_get_curr_iterate]
744
778 // [TNLP_get_curr_violations]
780 const IpoptData* ip_data,
782 bool scaled,
783 Index n,
784 Number* x_L_violation,
785 Number* x_U_violation,
786 Number* compl_x_L,
787 Number* compl_x_U,
788 Number* grad_lag_x,
789 Index m,
790 Number* nlp_constraint_violation,
791 Number* compl_g
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
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.
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
@ NON_LINEAR
Constraint/Variable is non-linear.
Definition IpTNLP.hpp:55
@ 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
@ FORTRAN_STYLE
Definition IpTNLP.hpp:77
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
Definition config.h:94
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
AlgorithmMode
enum to indicate the mode in which the algorithm is