[Ipopt] Extract Objective Function Gradient in finalize_solution(...)
Knut Heidemann
heidemannknut at gmail.com
Sun Feb 3 13:00:02 EST 2013
Hi,
Thanks for the hint.
I tried the following (which I found here:
http://list.coin-or.org/pipermail/ipopt/2010-July/002078.html):
/ OrigIpoptNLP* orignlp =
dynamic_cast<OrigIpoptNLP*>(GetRawPtr(ip_cq->GetIpoptNLP()));//
// TNLPAdapter* tnlp_adapter =
dynamic_cast<TNLPAdapter*>(GetRawPtr(orignlp->nlp()));//
//
// double *grad_current = new double[n];//
//
//tnlp_adapter->ResortX(*(GetRawPtr(ip_cq->curr_grad_f())), grad_current);//
//
// for (Index i=0;i<n;i++)//
// cout << grad_current[i] << endl;//
//
// delete[] grad_current;//
/
The problem is, that ResortX does the gradient sorting right but adds
the "fixed values in x", not the corresponding gradient values.
So I end up with the fixed coordinates written to grad_current. I cannot
figure out, how to access the gradient values wrt the fixed dofs.
It does not seem like there is a method which does the job (?). I would
be glad to hear that I am wrong ;).
If not, I think I will just try to use the last call of eval_grad_f in
order to get the final gradient values of my NLP, although this would
not be elegant ...
Best,
Knut.
Am 01.02.2013 16:00, schrieb Stefan Vigerske:
> Hi,
>
> note that there are two representations of the same NLP in Ipopt.
>
> In your implementation of eval_grad_f you work on the TNLP that you
> have passed to Ipopt.
>
> Internally, Ipopt works with an NLP in standardform (the one from the
> Ipopt implementation paper: no inequalities, only equations, fixed
> variables removed). The vector you get in IpoptCalculatedQuantities is
> w.r.t. this standardform. That is probably one reason why it's not so
> trivial to actually get these values.
>
> There have been posts on this list on how to translate vectors from
> the internal NLP representation to the TNLP form. You should find
> these in the mailing lists archive, try searching for
> TNLPAdapter site:http://list.coin-or.org/pipermail/ipopt/
> in google.
>
> Stefan
>
>
> On 02/01/2013 03:44 PM, Knut Heidemann wrote:
>> Hi,
>>
>> I access the gradient values of my final objective function via
>>
>> / SmartPtr<const DenseVector> curr_grad = dynamic_cast<const
>> DenseVector*>(GetRawPtr(ip_cq->curr_grad_f()));//
>> // const double* grad_values = curr_grad->Values();/
>>
>> Unfortunately, this does not agree with the values calculated in the
>> last call of "eval_grad_f".
>> The first few entries do agree, but then I get values that are not
>> related to the actual results.
>> Furthermore, the values are not reproducable.
>> For me, this looks like I am accessing values that have not been set?
>>
>> Might there be something wrong with the code above, or even the methods
>> used therein?
>>
>> Kind regards,
>> Knut.
>>
>>
>>
>>
>> Am 18.01.2013 16:29, schrieb Stefan Vigerske:
>>> Hi,
>>>
>>> On 01/18/2013 12:10 PM, Knut Heidemann wrote:
>>>> I tried the code snippet below and get the following error:
>>>>
>>>> /In member function 'virtual void
>>>> WLCNLP::finalize_solution(Ipopt::SolverReturn, Ipopt::Index, const
>>>> Number*, const Number*, const Number*, Ipopt::Index, const Number*,
>>>> const Number*, Ipopt::Number, const Ipopt::IpoptData*,
>>>> Ipopt::IpoptCalculatedQuantities*)'://
>>>> //error: invalid use of incomplete type 'struct
>>>> Ipopt::IpoptCalculatedQuantities'//
>>>> //error: forward declaration of 'struct
>>>> Ipopt::IpoptCalculatedQuantities'/
>>>>
>>>> Can this be due to further missing #includes or what kind of
>>>> problem do
>>>> I face here?
>>>
>>> Yes.
>>> You need to include the header file where the
>>> IpoptCalculatedQuantities class is defined.
>>>
>>> Stefan
>>>
>>>>
>>>> Best,
>>>> Knut.
>>>>
>>>> Am 17.01.2013 19:21, schrieb Hans Pirnay:
>>>>> this should work:
>>>>>
>>>>> SmartPtr<DenseVector> curr_grad = dynamic_cast<const
>>>>> DenseVector*>(GetRawPtr(ip_cq->curr_grad_f()));
>>>>> const double* grad_values = curr_grad->Values();
>>>>>
>>>>> You'll probably have to #include "IpDenseVector.hpp" and maybe some
>>>>> other dependencies.
>>>>>
>>>>> Hans
>>>>>
>>>>> On Thu, Jan 17, 2013 at 6:30 PM, Knut Heidemann
>>>>> <heidemannknut at gmail.com> wrote:
>>>>>> Hi,
>>>>>>
>>>>>> I am trying to access the objective function gradient information
>>>>>> after my
>>>>>> problem has been solved.
>>>>>> I assume that this is done in finalize_solution(...).
>>>>>> Unfortunately, I do not manage to use "ip_cq" for this purpose. Can
>>>>>> anybody
>>>>>> tell me how the appropriate line of code would look like?
>>>>>>
>>>>>> Best regards,
>>>>>> Knut Heidemann.
>>>>>> _______________________________________________
>>>>>> Ipopt mailing list
>>>>>> Ipopt at list.coin-or.org
>>>>>> http://list.coin-or.org/mailman/listinfo/ipopt
>>>>
>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> Ipopt mailing list
>>>> Ipopt at list.coin-or.org
>>>> http://list.coin-or.org/mailman/listinfo/ipopt
>>>>
>>>
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://list.coin-or.org/pipermail/ipopt/attachments/20130203/effd17da/attachment.html>
More information about the Ipopt
mailing list