[Ipopt] Extract Objective Function Gradient in finalize_solution(...)

Knut Heidemann heidemannknut at gmail.com
Tue Jan 29 11:23:42 EST 2013


Hi,

I have got some difficulties concerning data extraction from the 
converged solution of my IPOPT problem.
I am extracting the forces on some dofs via (in finalize_solution):

/  SmartPtr<const DenseVector> curr_grad = dynamic_cast<const 
DenseVector*>(GetRawPtr(ip_cq->curr_grad_f()));//
//  const double* grad_values = curr_grad->Values();/

Then I look at some "grad_values[x]".
The problem now is the following: If I write a file with the final 
coordinates and multipliers and start IPOPT again (after loading the 
files as starting point) , I occasionally get different grad_values[x], 
although the program converges in zero iterations and the final 
coordinates (and objective etc.) are exactly the same as before.

This is my main:

/int main(int argc, char** argv)
{
   SystemState system ("vertices.txt", "springs.txt", "constraints.txt", 
"fixed.txt");

   SmartPtr<TNLP> mynlp = new WLCNLP(system);

   // Create a new instance of IpoptApplication
   //  (use a SmartPtr, not raw)
   SmartPtr<IpoptApplication> app = new IpoptApplication();

   // Intialize the IpoptApplication and process the options
   ApplicationReturnStatus status;
   status = app->Initialize();
   if (status != Solve_Succeeded) {
     std::cout << std::endl << std::endl << "*** Error during 
initialization!" << std::endl;
     return (int) status;
   }

   // Ask Ipopt to solve the problem
   status = app->OptimizeTNLP(mynlp);
   system.updateCoordinates("vertices.txt"); // load coordinates from 
preceding simulation
app->Options()->SetStringValue("warm_start_init_point", "yes"); // load 
initial lagrange multipliers from preceding simulation
   mynlp = new WLCNLP(system);
   status = app->OptimizeTNLP(mynlp);

   return 0;
}
/
I cannot come up with a reasoning for this behavior.
Any hint would be tremendously appreciated.

Best,
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/20130129/ab52a9f1/attachment.html>


More information about the Ipopt mailing list