[Ipopt] Problems about derivative checker and iteration
Stefan Vigerske
stefan at math.hu-berlin.de
Fri Feb 26 05:01:28 EST 2010
Hi,
you may do something like this:
class MyTNLP : public class TNLP {
private:
double funcvalue;
double* funcgrad;
double* funchess;
void computeFunction(double* x) {
// compute function value, gradient, and hessian
// and store in funcvalue, funcgrad, funchess
}
public:
bool eval_f(bool new_x, double* x, double* objval) {
if (new_x) {
computeFunction(x);
}
*objval = funcvalue;
return true;
}
bool eval_grad_f(bool new_x, double* x, double* grad) {
if (new_x) {
computeFunction(x);
}
memcpy(funcgrad, grad);
return true;
}
bool eval_h(bool new_x, double* x, ..., double* values, ...) {
if (new_x) {
computeFunction(x);
}
// add hessian values from funchess into values array
return true;
}
// and so on for constraint functions...
}
Stefan
lqc234 wrote:
> Hi Stefan,
>
> Thank you for your help! I noticed the new_x flag after your advise.In every eval_* function,the document said about the new_x flag:
>
> The boolean variable new_x will be false if the last call to any of the evaluation methods(eval_*) used
> the same x values.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.
>
> I don't understand the meaning of this section very cleary.I guess the meaning is that we can calculate the value,grandient,and hessian for my function in only one of the eval_* function.If so,how should I write my program? Would you please explain the new_x flag in detail?Thank you very much!
>
>
> 在2010-02-24 17:31:21,"Stefan Vigerske" <stefan at math.hu-berlin.de> 写道:
>> Hi,
>>
>> you may use the new_x flag that Ipopt provides for all the eval_*
>> functions. That is, if new_x is set to true in any of these routines,
>> then you compute value, gradient, and hessian for your function and
>> store these values in your TNLP object. As long as new_x is false, you
>> can use return this evaluated data in all eval_* functions.
>>
>> Stefan
>>
>> lqc234 wrote:
>>> Hi everybody:
>>> I have had a problem during using the Ipopt-3.6.1.And I have no idea about this problem for several days,I think that you might not think of this situation .
>>> Suppose f(x)= x^2+2*x+1/x+3*x+4*x^3. This formula is very simple,however consider this situation: in my application,for example,1/x+3*x+4*x^3 is a very complicated part that I can't write this part of formula directly,in other words I must use some codes to describe this part,for example
>>> a set of "for" cycle codes with complicated processing. Now I thought there are two problem.
>>> First , the direvative checker tools can't deal with this situation because the complicated part 1/x+3*x+4*x^3 is not described directly.
>>> The second problem is not easily to describe somewhat.
>>> The variable x changes in every iteration,while I can't write 1/x+3*x+4*x^3 directly.So in every iteration I have to describe the 1/x+3*x+4*x^3 part using some codes every time .However, I found that the excution sequence is "eval_jac_g,eval_grad_f,eval_g,eval_f,eval_h" sometime,sometimes it is not this sequence.Now I don't know which part I should write these codes in,it should be in the eval_f? or eval_g? or in eval_grad_f?eval_jac?eval_h?.
>>> I don't know the processing procedure during one iteration in Ipopt,those codes should used only once,I can't used those codes in eval_f ,eval_g,eval_grad_f,eval_jac_g,eval_h all.
>>> I don't know if I have described the problem clearly.I hope so.
>>> Anyone can give some suggestion?Thank you very much in advance.
>>>
>>>
>>>
>>>
>>> ------------------------------------------------------------------------
>>>
>>> _______________________________________________
>>> Ipopt mailing list
>>> Ipopt at list.coin-or.org
>>> http://list.coin-or.org/mailman/listinfo/ipopt
>>
>> --
>> Stefan Vigerske
>> Humboldt University Berlin, Numerical Mathematics
>> http://www.math.hu-berlin.de/~stefan
--
Stefan Vigerske
Humboldt University Berlin, Numerical Mathematics
http://www.math.hu-berlin.de/~stefan
More information about the Ipopt
mailing list