2

I'm using Ipopt third party library. In order to use it, I've to implement some of virtual functions from one of its classes. Two virtual functions are given below for understanding.

virtual bool get_starting_point   ( double* x);
virtual bool eval_f(const Number* x, Number& obj_value);

here x is array of variable and obj_value is an expression of variables in x. x will change the value in each iteration.

An example implementation:

bool TNLP::get_starting_point   ( double* x)
{
     x[0] =1.5;
     x[1] =0.5;
     return true;
}
bool TNLP::eval_f(const Number* x, Number& obj_value)
{
     obj_value = x[0]*x[0] +x[1]*x[1];
     return true;
}

My problem:

I have a class which contain data and expressions needed for my problem.

class MyProblem: public TNLP
{
public:
    MyProblem();
protected:
    double* m_x= nullptr;   // initial values, i.e, x[0] =1.5; x[1] =0.5;
    double m_obj_value;     // same as x[0]*x[0] +x[1]*x[1];
}

Now, inheriting from TNLP, I can implement the virtual functions. I have to pass m_x and m_obj_value to x and obj_value in the corresponding virtual functions. I cannot just copy the m_x and m_obj_value since m_obj_value is an expression of m_x. How can I efficiently implement the virtual functions with the data m_x and m_obj_value?

user8153630
  • 301
  • 1
  • 8
hisham
  • 215
  • 1
  • 9

0 Answers0