Ipopt  3.12.11
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Public Member Functions | Private Member Functions | Private Attributes | List of all members
Ipopt::AmplTNLP Class Reference

Ampl Interface. More...

#include <AmplTNLP.hpp>

+ Inheritance diagram for Ipopt::AmplTNLP:

Public Member Functions

 DECLARE_STD_EXCEPTION (NONPOSITIVE_SCALING_FACTOR)
 Exceptions. More...
 
void set_active_objective (Index obj_no)
 A method for setting the index of the objective function to be considered. More...
 
SmartPtr< AmplSuffixHandlerget_suffix_handler ()
 Method for returning the suffix handler. More...
 
Constructors/Destructors
 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. More...
 
virtual ~AmplTNLP ()
 Default destructor. More...
 
methods to gather information about the NLP. These

methods are overloaded from TNLP.

See TNLP for their more detailed documentation.

virtual bool get_nlp_info (Index &n, Index &m, Index &nnz_jac_g, Index &nnz_h_lag, IndexStyleEnum &index_style)
 returns dimensions of the nlp. More...
 
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)
 returns names and other meta data for the variables and constraints Overloaded from TNLP More...
 
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. More...
 
virtual bool get_constraints_linearity (Index m, LinearityType *const_types)
 Returns the constraint linearity. More...
 
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)
 provides a starting point for the nlp variables. More...
 
virtual bool eval_f (Index n, const Number *x, bool new_x, Number &obj_value)
 evaluates the objective value for the nlp. More...
 
virtual bool eval_grad_f (Index n, const Number *x, bool new_x, Number *grad_f)
 
evaluates the gradient of the objective for the

nlp. More...

 
virtual bool eval_g (Index n, const Number *x, bool new_x, Index m, Number *g)
 evaluates the constraint residuals for the nlp. More...
 
virtual bool eval_jac_g (Index n, const Number *x, bool new_x, Index m, Index nele_jac, Index *iRow, Index *jCol, Number *values)
 specifies the jacobian structure (if values is NULL) and evaluates the jacobian values (if values is not NULL) for the nlp. More...
 
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)
 specifies the structure of the hessian of the lagrangian (if values is NULL) and evaluates the values (if values is not NULL). More...
 
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)
 retrieve the scaling parameters for the variables, objective function, and constraints. More...
 
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 is complete so the TNLP can store/write the solution. More...
 
Method for quasi-Newton approximation information.
virtual Index get_number_of_nonlinear_variables ()
 
virtual bool get_list_of_nonlinear_variables (Index num_nonlin_vars, Index *pos_nonlin_vars)
 
Ampl specific methods
ASL_pfgh * AmplSolverObject ()
 Return the ampl solver object (ASL*) More...
 
void write_solution_file (const std::string &message) const
 Write the solution file. More...
 
void get_discrete_info (Index &nlvb_, Index &nlvbi_, Index &nlvc_, Index &nlvci_, Index &nlvo_, Index &nlvoi_, Index &nbv_, Index &niv_) const
 ampl orders the variables like (continuous, binary, integer). More...
 
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 (std::string tag, std::vector< std::string > meta_data)
 
void set_integer_metadata_for_var (std::string tag, std::vector< Index > meta_data)
 
void set_numeric_metadata_for_var (std::string tag, std::vector< Number > meta_data)
 
void set_string_metadata_for_con (std::string tag, std::vector< std::string > meta_data)
 
void set_integer_metadata_for_con (std::string tag, std::vector< Index > meta_data)
 
void set_numeric_metadata_for_con (std::string tag, std::vector< Number > meta_data)
 
- Public Member Functions inherited from Ipopt::TNLP
 DECLARE_STD_EXCEPTION (INVALID_TNLP)
 
 TNLP ()
 
virtual ~TNLP ()
 Default destructor. More...
 
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 is called just before finalize_solution. More...
 
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. More...
 
virtual bool get_variables_linearity (Index n, LinearityType *var_types)
 overload this method to return the variables linearity (TNLP::LINEAR or TNLP::NON_LINEAR). More...
 
virtual bool get_warm_start_iterate (IteratesVector &warm_start_iterate)
 overload this method to provide an Ipopt iterate (already in the form Ipopt requires it internally) for a warm start. More...
 
- 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
 

Private Member Functions

bool internal_objval (const Number *x, Number &obj_val)
 Make the objective call to ampl. More...
 
bool internal_conval (const Number *x, Index m, Number *g=NULL)
 Make the constraint call to ampl. More...
 
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. More...
 
char * 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)
 Method for obtaining the name of the NL file and the options set from AMPL. More...
 
bool nerror_ok (void *nerror)
 returns true if the ampl nerror code is ok More...
 
void call_hesset ()
 calls hesset ASL function More...
 
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. More...
 
 AmplTNLP (const AmplTNLP &)
 Copy Constructor. More...
 
void operator= (const AmplTNLP &)
 Overloaded Equals Operator. More...
 

Private Attributes

SmartPtr< const Journalistjnlst_
 Journlist. More...
 
ASL_pfgh * asl_
 pointer to the main ASL structure More...
 
double obj_sign_
 Sign of the objective fn (1 for min, -1 for max) More...
 
void * Oinfo_ptr_
 Pointer to the Oinfo structure. More...
 
void * nerror_
 nerror flag passed to ampl calls - set to NULL to halt on error More...
 
SmartPtr< AmplSuffixHandlersuffix_handler_
 Suffix Handler. More...
 
StringMetaDataMapType var_string_md_
 meta data to pass on to TNLP More...
 
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_
 
Internal copies of data
Numberx_sol_
 Solution Vectors. More...
 
Numberz_L_sol_
 
Numberz_U_sol_
 
Numberg_sol_
 
Numberlambda_sol_
 
Number obj_sol_
 
Flags to track internal state
bool objval_called_with_current_x_
 true when the objective value has been calculated with the current x, set to false in apply_new_x, and set to true in internal_objval More...
 
bool conval_called_with_current_x_
 true when the constraint values have been calculated with the current x, set to false in apply_new_x, and set to true in internal_conval More...
 
bool hesset_called_
 true when we have called hesset More...
 
bool set_active_objective_called_
 true when set_active_objective has been called More...
 

Additional Inherited Members

- Public Types inherited from Ipopt::TNLP
enum  LinearityType { LINEAR, NON_LINEAR }
 Type of the constraints. More...
 
enum  IndexStyleEnum { C_STYLE =0, FORTRAN_STYLE =1 }
 overload this method to return the number of variables and constraints, and the number of non-zeros in the jacobian and the hessian. More...
 
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.

Ampl Interface, implemented as a TNLP.

Definition at line 271 of file AmplTNLP.hpp.

Constructor & Destructor Documentation

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.

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

Default destructor.

Ipopt::AmplTNLP::AmplTNLP ( )
private

Default Constructor.

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

Copy Constructor.

Member Function Documentation

Ipopt::AmplTNLP::DECLARE_STD_EXCEPTION ( NONPOSITIVE_SCALING_FACTOR  )

Exceptions.

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

returns dimensions of the nlp.

Overloaded from TNLP

Implements Ipopt::TNLP.

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

returns names and other meta data for the variables and constraints Overloaded from TNLP

Reimplemented from Ipopt::TNLP.

Reimplemented in Ipopt::SensAmplTNLP.

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.

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

Returns the constraint linearity.

array will be alocated with length n. (default implementation just return false and does not fill the array).

Reimplemented from Ipopt::TNLP.

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

provides a starting point for the nlp variables.

Overloaded from TNLP

Implements Ipopt::TNLP.

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

evaluates the objective value for the nlp.

Overloaded from TNLP

Implements Ipopt::TNLP.

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

evaluates the gradient of the objective for the

nlp.

Overloaded from TNLP

Implements Ipopt::TNLP.

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

evaluates the constraint residuals for the nlp.

Overloaded from TNLP

Implements Ipopt::TNLP.

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

specifies the jacobian structure (if values is NULL) and evaluates the jacobian values (if values is not NULL) for the nlp.

Overloaded from TNLP

Implements Ipopt::TNLP.

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

specifies the structure of the hessian of the lagrangian (if values is NULL) and evaluates the values (if values is not NULL).

Overloaded from TNLP

Reimplemented from Ipopt::TNLP.

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

retrieve the scaling parameters for the variables, objective function, and constraints.

Reimplemented from Ipopt::TNLP.

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 is complete so the TNLP can store/write the solution.

Implements Ipopt::TNLP.

Reimplemented in Ipopt::SensAmplTNLP.

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

Reimplemented from Ipopt::TNLP.

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

Reimplemented from Ipopt::TNLP.

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

Return the ampl solver object (ASL*)

Definition at line 387 of file AmplTNLP.hpp.

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

Write the solution file.

This is a wrapper for AMPL's write_sol. TODO Maybe this should be at a different place, or collect the numbers itself?

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

ampl orders the variables like (continuous, binary, integer).

This method gives the number of binary and integer variables. For details, see Tables 3 and 4 in "Hooking Your Solver to AMPL"

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.

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

Definition at line 424 of file AmplTNLP.hpp.

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

Definition at line 429 of file AmplTNLP.hpp.

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

Definition at line 434 of file AmplTNLP.hpp.

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

Definition at line 439 of file AmplTNLP.hpp.

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

Definition at line 444 of file AmplTNLP.hpp.

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

Definition at line 449 of file AmplTNLP.hpp.

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

Method for returning the suffix handler.

Definition at line 456 of file AmplTNLP.hpp.

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

Overloaded Equals Operator.

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

Make the objective call to ampl.

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

Make the constraint call to ampl.

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

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

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 
)
private

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

bool Ipopt::AmplTNLP::nerror_ok ( void *  nerror)
private

returns true if the ampl nerror code is ok

void Ipopt::AmplTNLP::call_hesset ( )
private

calls hesset ASL function

Member Data Documentation

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

Journlist.

Definition at line 481 of file AmplTNLP.hpp.

ASL_pfgh* Ipopt::AmplTNLP::asl_
private

pointer to the main ASL structure

Definition at line 484 of file AmplTNLP.hpp.

double Ipopt::AmplTNLP::obj_sign_
private

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

Definition at line 487 of file AmplTNLP.hpp.

Index Ipopt::AmplTNLP::nz_h_full_
private

Definition at line 491 of file AmplTNLP.hpp.

Number* Ipopt::AmplTNLP::x_sol_
private

Solution Vectors.

Definition at line 498 of file AmplTNLP.hpp.

Number* Ipopt::AmplTNLP::z_L_sol_
private

Definition at line 499 of file AmplTNLP.hpp.

Number* Ipopt::AmplTNLP::z_U_sol_
private

Definition at line 500 of file AmplTNLP.hpp.

Number* Ipopt::AmplTNLP::g_sol_
private

Definition at line 501 of file AmplTNLP.hpp.

Number* Ipopt::AmplTNLP::lambda_sol_
private

Definition at line 502 of file AmplTNLP.hpp.

Number Ipopt::AmplTNLP::obj_sol_
private

Definition at line 503 of file AmplTNLP.hpp.

bool Ipopt::AmplTNLP::objval_called_with_current_x_
private

true when 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 511 of file AmplTNLP.hpp.

bool Ipopt::AmplTNLP::conval_called_with_current_x_
private

true when 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 515 of file AmplTNLP.hpp.

bool Ipopt::AmplTNLP::hesset_called_
private

true when we have called hesset

Definition at line 517 of file AmplTNLP.hpp.

bool Ipopt::AmplTNLP::set_active_objective_called_
private

true when set_active_objective has been called

Definition at line 519 of file AmplTNLP.hpp.

void* Ipopt::AmplTNLP::Oinfo_ptr_
private

Pointer to the Oinfo structure.

Definition at line 523 of file AmplTNLP.hpp.

void* Ipopt::AmplTNLP::nerror_
private

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

Definition at line 526 of file AmplTNLP.hpp.

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

Suffix Handler.

Definition at line 529 of file AmplTNLP.hpp.

StringMetaDataMapType Ipopt::AmplTNLP::var_string_md_
private

meta data to pass on to TNLP

Definition at line 557 of file AmplTNLP.hpp.

IntegerMetaDataMapType Ipopt::AmplTNLP::var_integer_md_
private

Definition at line 558 of file AmplTNLP.hpp.

NumericMetaDataMapType Ipopt::AmplTNLP::var_numeric_md_
private

Definition at line 559 of file AmplTNLP.hpp.

StringMetaDataMapType Ipopt::AmplTNLP::con_string_md_
private

Definition at line 560 of file AmplTNLP.hpp.

IntegerMetaDataMapType Ipopt::AmplTNLP::con_integer_md_
private

Definition at line 561 of file AmplTNLP.hpp.

NumericMetaDataMapType Ipopt::AmplTNLP::con_numeric_md_
private

Definition at line 562 of file AmplTNLP.hpp.


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