next up previous contents
Next: Method get_nlp_info Up: The C++ Interface Previous: The C++ Interface   Contents


Coding the Problem Representation

We provide the information required in Figure 2 by coding the HS071_NLP class, a specific implementation of the TNLP base class. In the executable, we will create an instance of the HS071_NLP class and give this class to IPOPT so it can evaluate the problem functions through the TNLP interface. If you have any difficulty as the implementation proceeds, have a look at the completed example in the Ipopt/examples/hs071_cpp directory.

Start by creating a new directory under examples, called MyExample and create the files hs071_nlp.hpp and hs071_nlp.cpp. In hs071_nlp.hpp, include IpTNLP.hpp (the base class), tell the compiler that we are using the IPOPT namespace, and create the declaration of the HS071_NLP class, inheriting off of TNLP. Have a look at the TNLP class in IpTNLP.hpp; you will see eight pure virtual methods that we must implement. Declare these methods in the header file. Implement each of the methods in HS071_NLP.cpp using the descriptions given below. In hs071_nlp.cpp, first include the header file for your class and tell the compiler that you are using the IPOPT namespace. A full version of these files can be found in the Ipopt/examples/hs071_cpp directory.

It is very easy to make mistakes in the implementation of the function evaluation methods, in particular regarding the derivatives. IPOPT has a feature that can help you to debug the derivative code, using finite differences, see Section 4.1.

Note that the return value of any bool-valued function should be true, unless an error occurred, for example, because the value of a problem function could not be evaluated at the required point.



Subsections
next up previous contents
Next: Method get_nlp_info Up: The C++ Interface Previous: The C++ Interface   Contents
Andreas Waechter 2008-04-25