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.