Ipopt Documentation  
 
Loading...
Searching...
No Matches
Ipopt::AmplTNLP Class Reference

Ampl Interface, implemented as a TNLP. More...

#include <AmplTNLP.hpp>

+ Inheritance diagram for Ipopt::AmplTNLP:

Public Member Functions

 DECLARE_STD_EXCEPTION (NONPOSITIVE_SCALING_FACTOR)
 Exceptions.
 
void set_active_objective (Index obj_no)
 A method for setting the index of the objective function to be considered.
 
SmartPtr< AmplSuffixHandlerget_suffix_handler ()
 Method for returning the suffix handler.
 
Constructors/Destructors
 AmplTNLP (const SmartPtr< const Journalist > &jnlst, const SmartPtr< RegisteredOptions > regoptions, const SmartPtr< OptionsList > options, const char *const *argv, SmartPtr< AmplSuffixHandler > suffix_handler=NULL, bool allow_discrete=false, SmartPtr< AmplOptionsList > ampl_options_list=NULL, const char *ampl_option_string=NULL, const char *ampl_invokation_string=NULL, const char *ampl_banner_string=NULL, std::string *nl_file_content=NULL)
 Constructor.
 
IPOPT_DEPRECATED AmplTNLP (const SmartPtr< const Journalist > &jnlst, const SmartPtr< OptionsList > options, char **&argv, SmartPtr< AmplSuffixHandler > suffix_handler=NULL, bool allow_discrete=false, SmartPtr< AmplOptionsList > ampl_options_list=NULL, const char *ampl_option_string=NULL, const char *ampl_invokation_string=NULL, const char *ampl_banner_string=NULL, std::string *nl_file_content=NULL)
 Constructor without RegisteredOptions.
 
virtual ~AmplTNLP ()
 Default destructor.
 
methods to gather information about the NLP
virtual bool get_nlp_info (Index &n, Index &m, Index &nnz_jac_g, Index &nnz_h_lag, IndexStyleEnum &index_style)
 Method to request the initial information about the problem.
 
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.
 
virtual bool get_bounds_info (Index n, Number *x_l, Number *x_u, Index m, Number *g_l, Number *g_u)
 returns bounds of the nlp.
 
virtual bool get_constraints_linearity (Index m, LinearityType *const_types)
 Method to request the constraints linearity.
 
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)
 Method to request the starting point before iterating.
 
virtual bool eval_f (Index n, const Number *x, bool new_x, Number &obj_value)
 Method to request the value of the objective function.
 
virtual bool eval_grad_f (Index n, const Number *x, bool new_x, Number *grad_f)
 Method to request the gradient of the objective function.
 
virtual bool eval_g (Index n, const Number *x, bool new_x, Index m, Number *g)
 Method to request the constraint values.
 
virtual bool eval_jac_g (Index n, const Number *x, bool new_x, Index m, Index nele_jac, Index *iRow, Index *jCol, Number *values)
 Method to request either the sparsity structure or the values of the Jacobian of the constraints.
 
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.
 
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.
 
Solution Methods
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)
 This method is called when the algorithm has finished (successfully or not) so the TNLP can digest the outcome, e.g., store/write the solution, if any.
 
Method for quasi-Newton approximation information.
virtual Index get_number_of_nonlinear_variables ()
 Return the number of variables that appear nonlinearly in the objective function or in at least one constraint function.
 
virtual bool get_list_of_nonlinear_variables (Index num_nonlin_vars, Index *pos_nonlin_vars)
 Return the indices of all nonlinear variables.
 
Ampl specific methods
ASL_pfghAmplSolverObject ()
 Return the ampl solver object (ASL*)
 
void write_solution_file (const std::string &message) const
 Write the solution file.
 
void get_discrete_info (Index &nlvb_, Index &nlvbi_, Index &nlvc_, Index &nlvci_, Index &nlvo_, Index &nlvoi_, Index &nbv_, Index &niv_) const
 Give the number of binary and integer variables.
 
Methods to set meta data for the variables and constraints.

These values will be passed on to the TNLP in get_var_con_meta_data.

void set_string_metadata_for_var (const std::string &tag, const std::vector< std::string > &meta_data)
 
void set_integer_metadata_for_var (const std::string &tag, const std::vector< Index > &meta_data)
 
void set_numeric_metadata_for_var (const std::string &tag, const std::vector< Number > &meta_data)
 
void set_string_metadata_for_con (const std::string &tag, const std::vector< std::string > &meta_data)
 
void set_integer_metadata_for_con (const std::string &tag, const std::vector< Index > &meta_data)
 
void set_numeric_metadata_for_con (const std::string &tag, const std::vector< Number > &meta_data)
 
- Public Member Functions inherited from Ipopt::TNLP
 DECLARE_STD_EXCEPTION (INVALID_TNLP)
 
 TNLP ()
 
virtual ~TNLP ()
 Default destructor.
 
virtual bool get_variables_linearity (Index n, LinearityType *var_types)
 Method to request the variables linearity.
 
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 internally for warm starts.
 
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.
 
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.
 
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.
 
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.
 
- Public Member Functions inherited from Ipopt::ReferencedObject
 ReferencedObject ()
 
virtual ~ReferencedObject ()
 
Index ReferenceCount () const
 
void AddRef (const Referencer *referencer) const
 
void ReleaseRef (const Referencer *referencer) const
 

Protected Member Functions

bool internal_objval (const Number *x, Number &obj_val)
 Make the objective call to ampl.
 
bool internal_conval (const Number *x, Index m, Number *g=NULL)
 Make the constraint call to ampl.
 
bool apply_new_x (bool new_x, Index n, const Number *x)
 Internal function to update the internal and ampl state if the x value changes.
 
charget_options (const SmartPtr< RegisteredOptions > regoptions, const SmartPtr< OptionsList > &options, SmartPtr< AmplOptionsList > &ampl_options_list, const char *ampl_option_string, const char *ampl_invokation_string, const char *ampl_banner_string, const char *const *argv)
 Method for obtaining the name of the NL file and the options set from AMPL.
 
IPOPT_DEPRECATED charget_options (const SmartPtr< OptionsList > &options, SmartPtr< AmplOptionsList > &ampl_options_list, const char *ampl_option_string, const char *ampl_invokation_string, const char *ampl_banner_string, char **&argv)
 Method for obtaining the name of the NL file and the options set from AMPL.
 
bool nerror_ok (void *nerror)
 whether the ampl nerror code is ok
 
void call_hesset ()
 calls hesset ASL function
 

Protected Attributes

SmartPtr< const Journalistjnlst_
 Journalist.
 
ASL_pfghasl_
 pointer to the main ASL structure
 
Number obj_sign_
 Sign of the objective fn (1 for min, -1 for max)
 
voidOinfo_ptr_
 Pointer to the Oinfo structure.
 
voidnerror_
 nerror flag passed to ampl calls - set to NULL to halt on error
 
SmartPtr< AmplSuffixHandlersuffix_handler_
 Suffix Handler.
 
StringMetaDataMapType var_string_md_
 meta data to pass on to TNLP
 
IntegerMetaDataMapType var_integer_md_
 
NumericMetaDataMapType var_numeric_md_
 
StringMetaDataMapType con_string_md_
 
IntegerMetaDataMapType con_integer_md_
 
NumericMetaDataMapType con_numeric_md_
 
Problem Size Data
Index nz_h_full_
 number of nonzeros in the full_x Hessian
 
Internal copies of solution vectors
Numberx_sol_
 
Numberz_L_sol_
 
Numberz_U_sol_
 
Numberg_sol_
 
Numberlambda_sol_
 
Number obj_sol_
 
Flags to track internal state
bool objval_called_with_current_x_
 whether the objective value has been calculated with the current x
 
bool conval_called_with_current_x_
 whether the constraint values have been calculated with the current x set to false in apply_new_x, and set to true in internal_conval
 
bool hesset_called_
 whether we have called hesset
 
bool set_active_objective_called_
 whether set_active_objective has been called
 

Private Member Functions

void gutsOfConstructor (const SmartPtr< RegisteredOptions > regoptions, const SmartPtr< OptionsList > options, const char *const *argv, bool allow_discrete, SmartPtr< AmplOptionsList > ampl_options_list, const char *ampl_option_string, const char *ampl_invokation_string, const char *ampl_banner_string, std::string *nl_file_content)
 
Default Compiler Generated Methods

(Hidden to avoid implicit creation/calling).

These methods are not implemented and we do not want the compiler to implement them for us, so we declare them private and do not define them. This ensures that they will not be implicitly created/called.

 AmplTNLP ()
 Default Constructor.
 
 AmplTNLP (const AmplTNLP &)
 Copy Constructor.
 
void operator= (const AmplTNLP &)
 Default Assignment Operator.
 

Additional Inherited Members

- Public Types inherited from Ipopt::TNLP
enum  LinearityType { LINEAR , NON_LINEAR }
 Linearity-types of variables and constraints. More...
 
enum  IndexStyleEnum { C_STYLE = 0 , FORTRAN_STYLE = 1 }
 
typedef std::map< std::string, std::vector< std::string > > StringMetaDataMapType
 
typedef std::map< std::string, std::vector< Index > > IntegerMetaDataMapType
 
typedef std::map< std::string, std::vector< Number > > NumericMetaDataMapType
 

Detailed Description

Ampl Interface, implemented as a TNLP.

Definition at line 316 of file AmplTNLP.hpp.

Constructor & Destructor Documentation

◆ AmplTNLP() [1/4]

Ipopt::AmplTNLP::AmplTNLP ( const SmartPtr< const Journalist > &  jnlst,
const SmartPtr< RegisteredOptions regoptions,
const SmartPtr< OptionsList options,
const char *const argv,
SmartPtr< AmplSuffixHandler suffix_handler = NULL,
bool  allow_discrete = false,
SmartPtr< AmplOptionsList ampl_options_list = NULL,
const char ampl_option_string = NULL,
const char ampl_invokation_string = NULL,
const char ampl_banner_string = NULL,
std::string *  nl_file_content = NULL 
)

Constructor.

Since
3.14.0

◆ AmplTNLP() [2/4]

IPOPT_DEPRECATED Ipopt::AmplTNLP::AmplTNLP ( const SmartPtr< const Journalist > &  jnlst,
const SmartPtr< OptionsList options,
char **&  argv,
SmartPtr< AmplSuffixHandler suffix_handler = NULL,
bool  allow_discrete = false,
SmartPtr< AmplOptionsList ampl_options_list = NULL,
const char ampl_option_string = NULL,
const char ampl_invokation_string = NULL,
const char ampl_banner_string = NULL,
std::string *  nl_file_content = NULL 
)

Constructor without RegisteredOptions.

Deprecated:
Use other constructor that also expects regoptions instead.

◆ ~AmplTNLP()

virtual Ipopt::AmplTNLP::~AmplTNLP ( )
virtual

Default destructor.

◆ AmplTNLP() [3/4]

Ipopt::AmplTNLP::AmplTNLP ( )
private

Default Constructor.

◆ AmplTNLP() [4/4]

Ipopt::AmplTNLP::AmplTNLP ( const AmplTNLP )
private

Copy Constructor.

Member Function Documentation

◆ DECLARE_STD_EXCEPTION()

Ipopt::AmplTNLP::DECLARE_STD_EXCEPTION ( NONPOSITIVE_SCALING_FACTOR  )

Exceptions.

◆ get_nlp_info()

virtual bool Ipopt::AmplTNLP::get_nlp_info ( Index n,
Index m,
Index nnz_jac_g,
Index nnz_h_lag,
IndexStyleEnum index_style 
)
virtual

Method to request the initial information about the problem.

Ipopt uses this information when allocating the arrays that it will later ask you to fill with values. Be careful in this method since incorrect values will cause memory bugs which may be very difficult to find.

Parameters
n(out) Storage for the number of variables \(x\)
m(out) Storage for the number of constraints \(g(x)\)
nnz_jac_g(out) Storage for the number of nonzero entries in the Jacobian
nnz_h_lag(out) Storage for the number of nonzero entries in the Hessian
index_style(out) Storage for the index style, the numbering style used for row/col entries in the sparse matrix format (TNLP::C_STYLE: 0-based, TNLP::FORTRAN_STYLE: 1-based; see also Triplet Format for Sparse Matrices)

Implements Ipopt::TNLP.

◆ get_var_con_metadata()

virtual bool Ipopt::AmplTNLP::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 
)
virtual

Method to request meta data for the variables and the constraints.

This method is used to pass meta data about variables or constraints to Ipopt. The data can be either of integer, numeric, or string type. Ipopt passes this data on to its internal problem representation. The meta data type is a std::map with std::string as key type and a std::vector as value type. So far, Ipopt itself makes only use of string meta data under the key idx_names. With this key, variable and constraint names can be passed to Ipopt, which are shown when printing internal vector or matrix data structures if Ipopt is run with a high value for the option. This allows a user to identify the original variables and constraints corresponding to Ipopt's internal problem representation.

If this method is not overloaded, the default implementation does not set any meta data and returns false.

Reimplemented from Ipopt::TNLP.

Reimplemented in Ipopt::SensAmplTNLP.

◆ get_bounds_info()

virtual bool Ipopt::AmplTNLP::get_bounds_info ( Index  n,
Number x_l,
Number x_u,
Index  m,
Number g_l,
Number g_u 
)
virtual

returns bounds of the nlp.

Overloaded from TNLP

Implements Ipopt::TNLP.

Reimplemented in Ipopt::SensAmplTNLP.

◆ get_constraints_linearity()

virtual bool Ipopt::AmplTNLP::get_constraints_linearity ( Index  m,
LinearityType const_types 
)
virtual

Method to request the constraints linearity.

This method is never called by Ipopt, but is used by Bonmin to get information about which constraints are linear. Ipopt passes the array const_types of size m, which should be filled with the appropriate linearity type of the constraints (TNLP::LINEAR or TNLP::NON_LINEAR).

The default implementation just returns false and does not fill the array.

Reimplemented from Ipopt::TNLP.

◆ get_starting_point()

virtual bool Ipopt::AmplTNLP::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 
)
virtual

Method to request the starting point before iterating.

Parameters
n(in) the number of variables \(x\) in the problem; it will have the same value that was specified in TNLP::get_nlp_info
init_x(in) if true, this method must provide an initial value for \(x\)
x(out) the initial values for the primal variables \(x\)
init_z(in) if true, this method must provide an initial value for the bound multipliers \(z^L\) and \(z^U\)
z_L(out) the initial values for the bound multipliers \(z^L\)
z_U(out) the initial values for the bound multipliers \(z^U\)
m(in) the number of constraints \(g(x)\) in the problem; it will have the same value that was specified in TNLP::get_nlp_info
init_lambda(in) if true, this method must provide an initial value for the constraint multipliers \(\lambda\)
lambda(out) the initial values for the constraint multipliers, \(\lambda\)
Returns
true if success, false otherwise.

The boolean variables indicate whether the algorithm requires to have x, z_L/z_u, and lambda initialized, respectively. If, for some reason, the algorithm requires initializations that cannot be provided, false should be returned and Ipopt will stop. The default options only require initial values for the primal variables \(x\).

Note, that the initial values for bound multiplier components for absent bounds ( \(x^L_i=-\infty\) or \(x^U_i=\infty\)) are ignored.

Implements Ipopt::TNLP.

◆ eval_f()

virtual bool Ipopt::AmplTNLP::eval_f ( Index  n,
const Number x,
bool  new_x,
Number obj_value 
)
virtual

Method to request the value of the objective function.

Parameters
n(in) the number of variables \(x\) in the problem; it will have the same value that was specified in TNLP::get_nlp_info
x(in) the values for the primal variables \(x\) at which the objective function \(f(x)\) is to be evaluated
new_x(in) false if any evaluation method (eval_*) was previously called with the same values in x, true otherwise. This can be helpful when users have efficient implementations that calculate multiple outputs at once. Ipopt internally caches results from the TNLP and generally, this flag can be ignored.
obj_value(out) storage for the value of the objective function \(f(x)\)
Returns
true if success, false otherwise.

Implements Ipopt::TNLP.

◆ eval_grad_f()

virtual bool Ipopt::AmplTNLP::eval_grad_f ( Index  n,
const Number x,
bool  new_x,
Number grad_f 
)
virtual

Method to request the gradient of the objective function.

Parameters
n(in) the number of variables \(x\) in the problem; it will have the same value that was specified in TNLP::get_nlp_info
x(in) the values for the primal variables \(x\) at which the gradient \(\nabla f(x)\) is to be evaluated
new_x(in) false if any evaluation method (eval_*) was previously called with the same values in x, true otherwise; see also TNLP::eval_f
grad_f(out) array to store values of the gradient of the objective function \(\nabla f(x)\). The gradient array is in the same order as the \(x\) variables (i.e., the gradient of the objective with respect to x[2] should be put in grad_f[2]).
Returns
true if success, false otherwise.

Implements Ipopt::TNLP.

◆ eval_g()

virtual bool Ipopt::AmplTNLP::eval_g ( Index  n,
const Number x,
bool  new_x,
Index  m,
Number g 
)
virtual

Method to request the constraint values.

Parameters
n(in) the number of variables \(x\) in the problem; it will have the same value that was specified in TNLP::get_nlp_info
x(in) the values for the primal variables \(x\) at which the constraint functions \(g(x)\) are to be evaluated
new_x(in) false if any evaluation method (eval_*) was previously called with the same values in x, true otherwise; see also TNLP::eval_f
m(in) the number of constraints \(g(x)\) in the problem; it will have the same value that was specified in TNLP::get_nlp_info
g(out) array to store constraint function values \(g(x)\), do not add or subtract the bound values \(g^L\) or \(g^U\).
Returns
true if success, false otherwise.

Implements Ipopt::TNLP.

◆ eval_jac_g()

virtual bool Ipopt::AmplTNLP::eval_jac_g ( Index  n,
const Number x,
bool  new_x,
Index  m,
Index  nele_jac,
Index iRow,
Index jCol,
Number values 
)
virtual

Method to request either the sparsity structure or the values of the Jacobian of the constraints.

The Jacobian is the matrix of derivatives where the derivative of constraint function \(g_i\) with respect to variable \(x_j\) is placed in row \(i\) and column \(j\). See Triplet Format for Sparse Matrices for a discussion of the sparse matrix format used in this method.

Parameters
n(in) the number of variables \(x\) in the problem; it will have the same value that was specified in TNLP::get_nlp_info
x(in) first call: NULL; later calls: the values for the primal variables \(x\) at which the constraint Jacobian \(\nabla g(x)^T\) is to be evaluated
new_x(in) false if any evaluation method (eval_*) was previously called with the same values in x, true otherwise; see also TNLP::eval_f
m(in) the number of constraints \(g(x)\) in the problem; it will have the same value that was specified in TNLP::get_nlp_info
nele_jac(in) the number of nonzero elements in the Jacobian; it will have the same value that was specified in TNLP::get_nlp_info
iRow(out) first call: array of length nele_jac to store the row indices of entries in the Jacobian of the constraints; later calls: NULL
jCol(out) first call: array of length nele_jac to store the column indices of entries in the Jacobian of the constraints; later calls: NULL
values(out) first call: NULL; later calls: array of length nele_jac to store the values of the entries in the Jacobian of the constraints
Returns
true if success, false otherwise.
Note
The arrays iRow and jCol only need to be filled once. If the iRow and jCol arguments are not NULL (first call to this function), then Ipopt expects that the sparsity structure of the Jacobian (the row and column indices only) are written into iRow and jCol. At this call, the arguments x and values will be NULL. If the arguments x and values are not NULL, then Ipopt expects that the value of the Jacobian as calculated from array x is stored in array values (using the same order as used when specifying the sparsity structure). At this call, the arguments iRow and jCol will be NULL.

Implements Ipopt::TNLP.

◆ eval_h()

virtual bool Ipopt::AmplTNLP::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 
)
virtual

Method to request either the sparsity structure or the values of the Hessian of the Lagrangian.

The Hessian matrix that Ipopt uses is

\[ \sigma_f \nabla^2 f(x_k) + \sum_{i=1}^m\lambda_i\nabla^2 g_i(x_k) \]

for the given values for \(x\), \(\sigma_f\), and \(\lambda\). See Triplet Format for Sparse Matrices for a discussion of the sparse matrix format used in this method.

Parameters
n(in) the number of variables \(x\) in the problem; it will have the same value that was specified in TNLP::get_nlp_info
x(in) first call: NULL; later calls: the values for the primal variables \(x\) at which the Hessian is to be evaluated
new_x(in) false if any evaluation method (eval_*) was previously called with the same values in x, true otherwise; see also TNLP::eval_f
obj_factor(in) factor \(\sigma_f\) in front of the objective term in the Hessian
m(in) the number of constraints \(g(x)\) in the problem; it will have the same value that was specified in TNLP::get_nlp_info
lambda(in) the values for the constraint multipliers \(\lambda\) at which the Hessian is to be evaluated
new_lambda(in) false if any evaluation method was previously called with the same values in lambda, true otherwise
nele_hess(in) the number of nonzero elements in the Hessian; it will have the same value that was specified in TNLP::get_nlp_info
iRow(out) first call: array of length nele_hess to store the row indices of entries in the Hessian; later calls: NULL
jCol(out) first call: array of length nele_hess to store the column indices of entries in the Hessian; later calls: NULL
values(out) first call: NULL; later calls: array of length nele_hess to store the values of the entries in the Hessian
Returns
true if success, false otherwise.
Note
The arrays iRow and jCol only need to be filled once. If the iRow and jCol arguments are not NULL (first call to this function), then Ipopt expects that the sparsity structure of the Hessian (the row and column indices only) are written into iRow and jCol. At this call, the arguments x, lambda, and values will be NULL. If the arguments x, lambda, and values are not NULL, then Ipopt expects that the value of the Hessian as calculated from arrays x and lambda are stored in array values (using the same order as used when specifying the sparsity structure). At this call, the arguments iRow and jCol will be NULL.
Attention
As this matrix is symmetric, Ipopt expects that only the lower diagonal entries are specified.

A default implementation is provided, in case the user wants to set quasi-Newton approximations to estimate the second derivatives and doesn't not need to implement this method.

Reimplemented from Ipopt::TNLP.

◆ get_scaling_parameters()

virtual bool Ipopt::AmplTNLP::get_scaling_parameters ( Number obj_scaling,
bool use_x_scaling,
Index  n,
Number x_scaling,
bool use_g_scaling,
Index  m,
Number g_scaling 
)
virtual

Method to request scaling parameters.

This is only called if the options are set to retrieve user scaling, that is, if nlp_scaling_method is chosen as "user-scaling". The method should provide scaling factors for the objective function as well as for the optimization variables and/or constraints. The return value should be true, unless an error occurred, and the program is to be aborted.

The value returned in obj_scaling determines, how Ipopt should internally scale the objective function. For example, if this number is chosen to be 10, then Ipopt solves internally an optimization problem that has 10 times the value of the original objective function provided by the TNLP. In particular, if this value is negative, then Ipopt will maximize the objective function instead of minimizing it.

The scaling factors for the variables can be returned in x_scaling, which has the same length as x in the other TNLP methods, and the factors are ordered like x. use_x_scaling needs to be set to true, if Ipopt should scale the variables. If it is false, no internal scaling of the variables is done. Similarly, the scaling factors for the constraints can be returned in g_scaling, and this scaling is activated by setting use_g_scaling to true.

As a guideline, we suggest to scale the optimization problem (either directly in the original formulation, or after using scaling factors) so that all sensitivities, i.e., all non-zero first partial derivatives, are typically of the order 0.1-10.

Reimplemented from Ipopt::TNLP.

◆ finalize_solution()

virtual void Ipopt::AmplTNLP::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 
)
virtual

This method is called when the algorithm has finished (successfully or not) so the TNLP can digest the outcome, e.g., store/write the solution, if any.

Parameters
status(in) gives the status of the algorithm
  • SUCCESS: Algorithm terminated successfully at a locally optimal point, satisfying the convergence tolerances (can be specified by options).
  • MAXITER_EXCEEDED: Maximum number of iterations exceeded (can be specified by an option).
  • CPUTIME_EXCEEDED: Maximum number of CPU seconds exceeded (can be specified by an option).
  • STOP_AT_TINY_STEP: Algorithm proceeds with very little progress.
  • STOP_AT_ACCEPTABLE_POINT: Algorithm stopped at a point that was converged, not to "desired" tolerances, but to "acceptable" tolerances (see the acceptable-... options).
  • LOCAL_INFEASIBILITY: Algorithm converged to a point of local infeasibility. Problem may be infeasible.
  • USER_REQUESTED_STOP: The user call-back function TNLP::intermediate_callback returned false, i.e., the user code requested a premature termination of the optimization.
  • DIVERGING_ITERATES: It seems that the iterates diverge.
  • RESTORATION_FAILURE: Restoration phase failed, algorithm doesn't know how to proceed.
  • ERROR_IN_STEP_COMPUTATION: An unrecoverable error occurred while Ipopt tried to compute the search direction.
  • INVALID_NUMBER_DETECTED: Algorithm received an invalid number (such as NaN or Inf) from the NLP; see also option check_derivatives_for_nan_inf).
  • INTERNAL_ERROR: An unknown internal error occurred.
n(in) the number of variables \(x\) in the problem; it will have the same value that was specified in TNLP::get_nlp_info
x(in) the final values for the primal variables
z_L(in) the final values for the lower bound multipliers
z_U(in) the final values for the upper bound multipliers
m(in) the number of constraints \(g(x)\) in the problem; it will have the same value that was specified in TNLP::get_nlp_info
g(in) the final values of the constraint functions
lambda(in) the final values of the constraint multipliers
obj_value(in) the final value of the objective function
ip_data(in) provided for expert users
ip_cq(in) provided for expert users

Implements Ipopt::TNLP.

Reimplemented in Ipopt::SensAmplTNLP.

◆ get_number_of_nonlinear_variables()

virtual Index Ipopt::AmplTNLP::get_number_of_nonlinear_variables ( )
virtual

Return the number of variables that appear nonlinearly in the objective function or in at least one constraint function.

If -1 is returned as number of nonlinear variables, Ipopt assumes that all variables are nonlinear. Otherwise, it calls get_list_of_nonlinear_variables with an array into which the indices of the nonlinear variables should be written - the array has the length num_nonlin_vars, which is identical with the return value of get_number_of_nonlinear_variables(). It is assumed that the indices are counted starting with 1 in the FORTRAN_STYLE, and 0 for the C_STYLE.

The default implementation returns -1, i.e., all variables are assumed to be nonlinear.

Reimplemented from Ipopt::TNLP.

◆ get_list_of_nonlinear_variables()

virtual bool Ipopt::AmplTNLP::get_list_of_nonlinear_variables ( Index  num_nonlin_vars,
Index pos_nonlin_vars 
)
virtual

Return the indices of all nonlinear variables.

This method is called only if limited-memory quasi-Newton option is used and get_number_of_nonlinear_variables() returned a positive number. This number is provided in parameter num_nonlin_var.

The method must store the indices of all nonlinear variables in pos_nonlin_vars, where the numbering starts with 0 order 1, depending on the numbering style determined in get_nlp_info.

Reimplemented from Ipopt::TNLP.

◆ AmplSolverObject()

ASL_pfgh * Ipopt::AmplTNLP::AmplSolverObject ( )
inline

Return the ampl solver object (ASL*)

Definition at line 498 of file AmplTNLP.hpp.

◆ write_solution_file()

void Ipopt::AmplTNLP::write_solution_file ( const std::string &  message) const

Write the solution file.

This is a wrapper for AMPL's write_sol.

◆ get_discrete_info()

void Ipopt::AmplTNLP::get_discrete_info ( Index nlvb_,
Index nlvbi_,
Index nlvc_,
Index nlvci_,
Index nlvo_,
Index nlvoi_,
Index nbv_,
Index niv_ 
) const

Give the number of binary and integer variables.

AMPL orders the variables like (continuous, binary, integer). For details, see Tables 3 and 4 in "Hooking Your Solver to AMPL"

◆ set_active_objective()

void Ipopt::AmplTNLP::set_active_objective ( Index  obj_no)

A method for setting the index of the objective function to be considered.

This method must be called after the constructor, and before anything else is called. It can only be called once, and if there is more than one objective function in the AMPL model, it MUST be called.

◆ set_string_metadata_for_var()

void Ipopt::AmplTNLP::set_string_metadata_for_var ( const std::string &  tag,
const std::vector< std::string > &  meta_data 
)
inline

Definition at line 546 of file AmplTNLP.hpp.

◆ set_integer_metadata_for_var()

void Ipopt::AmplTNLP::set_integer_metadata_for_var ( const std::string &  tag,
const std::vector< Index > &  meta_data 
)
inline

Definition at line 554 of file AmplTNLP.hpp.

◆ set_numeric_metadata_for_var()

void Ipopt::AmplTNLP::set_numeric_metadata_for_var ( const std::string &  tag,
const std::vector< Number > &  meta_data 
)
inline

Definition at line 562 of file AmplTNLP.hpp.

◆ set_string_metadata_for_con()

void Ipopt::AmplTNLP::set_string_metadata_for_con ( const std::string &  tag,
const std::vector< std::string > &  meta_data 
)
inline

Definition at line 570 of file AmplTNLP.hpp.

◆ set_integer_metadata_for_con()

void Ipopt::AmplTNLP::set_integer_metadata_for_con ( const std::string &  tag,
const std::vector< Index > &  meta_data 
)
inline

Definition at line 578 of file AmplTNLP.hpp.

◆ set_numeric_metadata_for_con()

void Ipopt::AmplTNLP::set_numeric_metadata_for_con ( const std::string &  tag,
const std::vector< Number > &  meta_data 
)
inline

Definition at line 586 of file AmplTNLP.hpp.

◆ get_suffix_handler()

SmartPtr< AmplSuffixHandler > Ipopt::AmplTNLP::get_suffix_handler ( )
inline

Method for returning the suffix handler.

Definition at line 596 of file AmplTNLP.hpp.

◆ operator=()

void Ipopt::AmplTNLP::operator= ( const AmplTNLP )
private

Default Assignment Operator.

◆ gutsOfConstructor()

void Ipopt::AmplTNLP::gutsOfConstructor ( const SmartPtr< RegisteredOptions regoptions,
const SmartPtr< OptionsList options,
const char *const argv,
bool  allow_discrete,
SmartPtr< AmplOptionsList ampl_options_list,
const char ampl_option_string,
const char ampl_invokation_string,
const char ampl_banner_string,
std::string *  nl_file_content 
)
private

◆ internal_objval()

bool Ipopt::AmplTNLP::internal_objval ( const Number x,
Number obj_val 
)
protected

Make the objective call to ampl.

◆ internal_conval()

bool Ipopt::AmplTNLP::internal_conval ( const Number x,
Index  m,
Number g = NULL 
)
protected

Make the constraint call to ampl.

◆ apply_new_x()

bool Ipopt::AmplTNLP::apply_new_x ( bool  new_x,
Index  n,
const Number x 
)
protected

Internal function to update the internal and ampl state if the x value changes.

◆ get_options() [1/2]

char * Ipopt::AmplTNLP::get_options ( const SmartPtr< RegisteredOptions regoptions,
const SmartPtr< OptionsList > &  options,
SmartPtr< AmplOptionsList > &  ampl_options_list,
const char ampl_option_string,
const char ampl_invokation_string,
const char ampl_banner_string,
const char *const argv 
)
protected

Method for obtaining the name of the NL file and the options set from AMPL.

Returns
a pointer to a char* with the name of the stub
Parameters
regoptionsRegistered Ipopt options
Since
3.14.0
Parameters
optionsOptions
ampl_options_listAMPL options list
ampl_option_stringAMPL options string
ampl_invokation_stringAMPL invokation string
ampl_banner_stringAMPL banner string
argvProgram arguments

◆ get_options() [2/2]

IPOPT_DEPRECATED char * Ipopt::AmplTNLP::get_options ( const SmartPtr< OptionsList > &  options,
SmartPtr< AmplOptionsList > &  ampl_options_list,
const char ampl_option_string,
const char ampl_invokation_string,
const char ampl_banner_string,
char **&  argv 
)
inlineprotected

Method for obtaining the name of the NL file and the options set from AMPL.

Returns
a pointer to a char* with the name of the stub
Deprecated:
Use get_options() with RegisteredOptions argument instead.

Definition at line 733 of file AmplTNLP.hpp.

◆ nerror_ok()

bool Ipopt::AmplTNLP::nerror_ok ( void nerror)
protected

whether the ampl nerror code is ok

◆ call_hesset()

void Ipopt::AmplTNLP::call_hesset ( )
protected

calls hesset ASL function

Member Data Documentation

◆ jnlst_

SmartPtr<const Journalist> Ipopt::AmplTNLP::jnlst_
protected

Journalist.

Definition at line 640 of file AmplTNLP.hpp.

◆ asl_

ASL_pfgh* Ipopt::AmplTNLP::asl_
protected

pointer to the main ASL structure

Definition at line 643 of file AmplTNLP.hpp.

◆ obj_sign_

Number Ipopt::AmplTNLP::obj_sign_
protected

Sign of the objective fn (1 for min, -1 for max)

Definition at line 646 of file AmplTNLP.hpp.

◆ nz_h_full_

Index Ipopt::AmplTNLP::nz_h_full_
protected

number of nonzeros in the full_x Hessian

Definition at line 651 of file AmplTNLP.hpp.

◆ x_sol_

Number* Ipopt::AmplTNLP::x_sol_
protected

Definition at line 656 of file AmplTNLP.hpp.

◆ z_L_sol_

Number* Ipopt::AmplTNLP::z_L_sol_
protected

Definition at line 657 of file AmplTNLP.hpp.

◆ z_U_sol_

Number* Ipopt::AmplTNLP::z_U_sol_
protected

Definition at line 658 of file AmplTNLP.hpp.

◆ g_sol_

Number* Ipopt::AmplTNLP::g_sol_
protected

Definition at line 659 of file AmplTNLP.hpp.

◆ lambda_sol_

Number* Ipopt::AmplTNLP::lambda_sol_
protected

Definition at line 660 of file AmplTNLP.hpp.

◆ obj_sol_

Number Ipopt::AmplTNLP::obj_sol_
protected

Definition at line 661 of file AmplTNLP.hpp.

◆ objval_called_with_current_x_

bool Ipopt::AmplTNLP::objval_called_with_current_x_
protected

whether the objective value has been calculated with the current x

set to false in apply_new_x, and set to true in internal_objval

Definition at line 670 of file AmplTNLP.hpp.

◆ conval_called_with_current_x_

bool Ipopt::AmplTNLP::conval_called_with_current_x_
protected

whether the constraint values have been calculated with the current x set to false in apply_new_x, and set to true in internal_conval

Definition at line 674 of file AmplTNLP.hpp.

◆ hesset_called_

bool Ipopt::AmplTNLP::hesset_called_
protected

whether we have called hesset

Definition at line 676 of file AmplTNLP.hpp.

◆ set_active_objective_called_

bool Ipopt::AmplTNLP::set_active_objective_called_
protected

whether set_active_objective has been called

Definition at line 678 of file AmplTNLP.hpp.

◆ Oinfo_ptr_

void* Ipopt::AmplTNLP::Oinfo_ptr_
protected

Pointer to the Oinfo structure.

Definition at line 682 of file AmplTNLP.hpp.

◆ nerror_

void* Ipopt::AmplTNLP::nerror_
protected

nerror flag passed to ampl calls - set to NULL to halt on error

Definition at line 685 of file AmplTNLP.hpp.

◆ suffix_handler_

SmartPtr<AmplSuffixHandler> Ipopt::AmplTNLP::suffix_handler_
protected

Suffix Handler.

Definition at line 688 of file AmplTNLP.hpp.

◆ var_string_md_

StringMetaDataMapType Ipopt::AmplTNLP::var_string_md_
protected

meta data to pass on to TNLP

Definition at line 755 of file AmplTNLP.hpp.

◆ var_integer_md_

IntegerMetaDataMapType Ipopt::AmplTNLP::var_integer_md_
protected

Definition at line 756 of file AmplTNLP.hpp.

◆ var_numeric_md_

NumericMetaDataMapType Ipopt::AmplTNLP::var_numeric_md_
protected

Definition at line 757 of file AmplTNLP.hpp.

◆ con_string_md_

StringMetaDataMapType Ipopt::AmplTNLP::con_string_md_
protected

Definition at line 758 of file AmplTNLP.hpp.

◆ con_integer_md_

IntegerMetaDataMapType Ipopt::AmplTNLP::con_integer_md_
protected

Definition at line 759 of file AmplTNLP.hpp.

◆ con_numeric_md_

NumericMetaDataMapType Ipopt::AmplTNLP::con_numeric_md_
protected

Definition at line 760 of file AmplTNLP.hpp.


The documentation for this class was generated from the following file: